Mercurial > projects > dwt-win
annotate dwt/graphics/GlyphMetrics.d @ 212:ab60f3309436
reverted the char[] to String and use the an alias.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:12:38 +0200 |
parents | 06825fa0ae76 |
children | fd9c62a2998e |
rev | line source |
---|---|
12 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2006 IBM Corporation and others. | |
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 | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwt.graphics.GlyphMetrics; | |
14 | |
15 import dwt.DWT; | |
16 import tango.text.convert.Format; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
12
diff
changeset
|
17 import dwt.dwthelper.utils; |
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
12
diff
changeset
|
18 |
12 | 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 | |
35 * | |
36 * @since 3.2 | |
37 */ | |
38 public final class GlyphMetrics { | |
39 | |
40 /** | |
41 * the ascent of the GlyphMetrics | |
42 */ | |
43 public int ascent; | |
44 | |
45 /** | |
46 * the descent of the GlyphMetrics | |
47 */ | |
48 public int descent; | |
49 | |
50 /** | |
51 * the width of the GlyphMetrics | |
52 */ | |
53 public int width; | |
54 | |
55 /** | |
56 * Constructs an instance of this class with the given | |
57 * ascent, descent and width values. | |
58 * | |
59 * @exception IllegalArgumentException <ul> | |
60 * <li>ERROR_INVALID_ARGUMENT - if the ascent, descent or width argument is negative</li> | |
61 * </ul> | |
62 */ | |
63 public this(int ascent, int descent, int width) { | |
64 if (ascent < 0 || descent < 0 || width < 0) { | |
65 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
66 } | |
67 this.ascent = ascent; | |
68 this.descent = descent; | |
69 this.width = width; | |
70 } | |
71 | |
72 /** | |
73 * Compares the argument to the receiver, and returns true | |
74 * if they represent the <em>same</em> object using a class | |
75 * specific comparison. | |
76 * | |
77 * @param object the object to compare with this object | |
78 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
79 * | |
80 * @see #hashCode() | |
81 */ | |
82 public override int opEquals (Object object) { | |
83 if (object is this) return true; | |
84 if (auto metrics = cast(GlyphMetrics)object ){ | |
85 return metrics.ascent == ascent && metrics.descent == descent && metrics.width == width; | |
86 } | |
87 return false; | |
88 } | |
89 | |
90 | |
91 /** | |
92 * Returns an integer hash code for the receiver. Any two | |
93 * objects that return <code>true</code> when passed to | |
94 * <code>equals</code> must return the same value for this | |
95 * method. | |
96 * | |
97 * @return the receiver's hash | |
98 * | |
99 * @see #equals(Object) | |
100 */ | |
101 public override hash_t toHash () { | |
102 return ascent ^ descent ^ width; | |
103 } | |
104 | |
105 /** | |
106 * Returns a string containing a concise, human-readable | |
107 * description of the receiver. | |
108 * | |
109 * @return a string representation of the <code>GlyphMetrics</code> | |
110 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
12
diff
changeset
|
111 public override String toString () { |
12 | 112 return Format( "GlyphMetrics {{{}, {}, {}}", ascent, descent, width ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
113 } | |
114 | |
115 } |