comparison dwt/graphics/FontMetrics.d @ 0:380af2bdd8e5

Upload of whole dwt tree
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sat, 09 Aug 2008 17:00:02 +0200
parents
children 1a8b3cb347e0
comparison
equal deleted inserted replaced
-1:000000000000 0:380af2bdd8e5
1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 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 *******************************************************************************/
11 module dwt.graphics.FontMetrics;
12
13 import dwt.dwthelper.utils;
14
15
16 /**
17 * Instances of this class provide measurement information
18 * about fonts including ascent, descent, height, leading
19 * space between rows, and average character width.
20 * <code>FontMetrics</code> are obtained from <code>GC</code>s
21 * using the <code>getFontMetrics()</code> method.
22 *
23 * @see GC#getFontMetrics
24 */
25 public final class FontMetrics {
26 int ascent, descent, averageCharWidth, leading, height;
27
28 FontMetrics() {
29 }
30
31 public static FontMetrics cocoa_new(int ascent, int descent, int averageCharWidth, int leading, int height) {
32 FontMetrics fontMetrics = new FontMetrics();
33 fontMetrics.ascent = ascent;
34 fontMetrics.descent = descent;
35 fontMetrics.averageCharWidth = averageCharWidth;
36 fontMetrics.leading = leading;
37 fontMetrics.height = height;
38 return fontMetrics;
39 }
40
41 /**
42 * Compares the argument to the receiver, and returns true
43 * if they represent the <em>same</em> object using a class
44 * specific comparison.
45 *
46 * @param object the object to compare with this object
47 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
48 *
49 * @see #hashCode
50 */
51 public bool equals (Object object) {
52 if (object is this) return true;
53 if (!(object instanceof FontMetrics)) return false;
54 FontMetrics metrics = (FontMetrics)object;
55 return ascent is metrics.ascent && descent is metrics.descent &&
56 averageCharWidth is metrics.averageCharWidth && leading is metrics.leading &&
57 height is metrics.height;
58 }
59
60 /**
61 * Returns the ascent of the font described by the receiver. A
62 * font's <em>ascent</em> is the distance from the baseline to the
63 * top of actual characters, not including any of the leading area,
64 * measured in pixels.
65 *
66 * @return the ascent of the font
67 */
68 public int getAscent() {
69 return ascent;
70 }
71
72 /**
73 * Returns the average character width, measured in pixels,
74 * of the font described by the receiver.
75 *
76 * @return the average character width of the font
77 */
78 public int getAverageCharWidth() {
79 return averageCharWidth;
80 }
81
82 /**
83 * Returns the descent of the font described by the receiver. A
84 * font's <em>descent</em> is the distance from the baseline to the
85 * bottom of actual characters, not including any of the leading area,
86 * measured in pixels.
87 *
88 * @return the descent of the font
89 */
90 public int getDescent() {
91 return descent;
92 }
93
94 /**
95 * Returns the height of the font described by the receiver,
96 * measured in pixels. A font's <em>height</em> is the sum of
97 * its ascent, descent and leading area.
98 *
99 * @return the height of the font
100 *
101 * @see #getAscent
102 * @see #getDescent
103 * @see #getLeading
104 */
105 public int getHeight() {
106 return height;
107 }
108
109 /**
110 * Returns the leading area of the font described by the
111 * receiver. A font's <em>leading area</em> is the space
112 * above its ascent which may include accents or other marks.
113 *
114 * @return the leading space of the font
115 */
116 public int getLeading() {
117 return leading;
118 }
119
120 /**
121 * Returns an integer hash code for the receiver. Any two
122 * objects that return <code>true</code> when passed to
123 * <code>equals</code> must return the same value for this
124 * method.
125 *
126 * @return the receiver's hash
127 *
128 * @see #equals
129 */
130 public int hashCode() {
131 return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
132 }
133
134 }