Mercurial > projects > dwt-linux
annotate dwt/graphics/GlyphMetrics.d @ 259:c0d810de7093
Update SWT 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 29 Jun 2008 14:33:38 +0200 |
parents | 380bad9f6852 |
children |
rev | line source |
---|---|
72 | 1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
21 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
72 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
21 | 12 *******************************************************************************/ |
13 module dwt.graphics.GlyphMetrics; | |
14 | |
238 | 15 import dwt.dwthelper.utils; |
16 | |
71 | 17 import dwt.DWT; |
21 | 18 import tango.text.convert.Format; |
19 /** | |
20 * Instances of this class represent glyph metrics. | |
21 * <p> | |
22 * The hashCode() method in this class uses the values of the public | |
23 * fields to compute the hash value. When storing instances of the | |
24 * class in hashed collections, do not modify these fields after the | |
25 * object has been inserted. | |
26 * </p> | |
27 * <p> | |
28 * Application code does <em>not</em> need to explicitly release the | |
29 * resources managed by each instance when those instances are no longer | |
30 * required, and thus no <code>dispose()</code> method is provided. | |
31 * </p> | |
32 * | |
33 * @see TextStyle | |
34 * @see TextLayout | |
259 | 35 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
21 | 36 * |
37 * @since 3.2 | |
38 */ | |
39 public final class GlyphMetrics { | |
40 | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
41 /** |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
42 * the ascent of the GlyphMetrics |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
43 */ |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
44 public int ascent; |
21 | 45 |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
46 /** |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
47 * the descent of the GlyphMetrics |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
48 */ |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
49 public int descent; |
21 | 50 |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
51 /** |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
52 * the width of the GlyphMetrics |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
53 */ |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
54 public int width; |
21 | 55 |
56 /** | |
57 * Constructs an instance of this class with the given | |
58 * ascent, descent and width values. | |
59 * | |
259 | 60 * @param ascent the GlyphMetrics ascent |
61 * @param descent the GlyphMetrics descent | |
62 * @param width the GlyphMetrics width | |
63 * | |
21 | 64 * @exception IllegalArgumentException <ul> |
65 * <li>ERROR_INVALID_ARGUMENT - if the ascent, descent or width argument is negative</li> | |
66 * </ul> | |
67 */ | |
68 public this(int ascent, int descent, int width) { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
69 if (ascent < 0 || descent < 0 || width < 0) { |
259 | 70 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
71 } |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
72 this.ascent = ascent; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
73 this.descent = descent; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
74 this.width = width; |
21 | 75 } |
76 | |
77 /** | |
78 * Compares the argument to the receiver, and returns true | |
79 * if they represent the <em>same</em> object using a class | |
80 * specific comparison. | |
81 * | |
82 * @param object the object to compare with this object | |
83 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
84 * | |
85 * @see #hashCode() | |
86 */ | |
87 public override int opEquals (Object object) { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
88 if (object is this) return true; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
89 if (auto metrics = cast(GlyphMetrics)object ){ |
194 | 90 return metrics.ascent is ascent && metrics.descent is descent && metrics.width is width; |
21 | 91 } |
92 return false; | |
93 } | |
94 | |
95 | |
96 /** | |
97 * Returns an integer hash code for the receiver. Any two | |
98 * objects that return <code>true</code> when passed to | |
99 * <code>equals</code> must return the same value for this | |
100 * method. | |
101 * | |
102 * @return the receiver's hash | |
103 * | |
104 * @see #equals(Object) | |
105 */ | |
106 public override hash_t toHash () { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
107 return ascent ^ descent ^ width; |
21 | 108 } |
109 | |
110 /** | |
111 * Returns a string containing a concise, human-readable | |
112 * description of the receiver. | |
113 * | |
114 * @return a string representation of the <code>GlyphMetrics</code> | |
115 */ | |
238 | 116 public override String toString () { |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
117 return Format( "GlyphMetrics {{{}, {}, {}}", ascent, descent, width ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
21 | 118 } |
119 | |
120 } |