KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > graphics > FontMetrics


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 package org.eclipse.swt.graphics;
12
13
14 /**
15  * Instances of this class provide measurement information
16  * about fonts including ascent, descent, height, leading
17  * space between rows, and average character width.
18  * <code>FontMetrics</code> are obtained from <code>GC</code>s
19  * using the <code>getFontMetrics()</code> method.
20  *
21  * @see GC#getFontMetrics
22  */

23 public final class FontMetrics {
24     int ascent, descent, averageCharWidth, leading, height;
25
26 FontMetrics() {
27 }
28
29 public static FontMetrics carbon_new(int ascent, int descent, int averageCharWidth, int leading, int height) {
30     FontMetrics fontMetrics = new FontMetrics();
31     fontMetrics.ascent = ascent;
32     fontMetrics.descent = descent;
33     fontMetrics.averageCharWidth = averageCharWidth;
34     fontMetrics.leading = leading;
35     fontMetrics.height = height;
36     return fontMetrics;
37 }
38
39 /**
40  * Compares the argument to the receiver, and returns true
41  * if they represent the <em>same</em> object using a class
42  * specific comparison.
43  *
44  * @param object the object to compare with this object
45  * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
46  *
47  * @see #hashCode
48  */

49 public boolean equals (Object JavaDoc object) {
50     if (object == this) return true;
51     if (!(object instanceof FontMetrics)) return false;
52     FontMetrics metrics = (FontMetrics)object;
53     return ascent == metrics.ascent && descent == metrics.descent &&
54         averageCharWidth == metrics.averageCharWidth && leading == metrics.leading &&
55         height == metrics.height;
56 }
57
58 /**
59  * Returns the ascent of the font described by the receiver. A
60  * font's <em>ascent</em> is the distance from the baseline to the
61  * top of actual characters, not including any of the leading area,
62  * measured in pixels.
63  *
64  * @return the ascent of the font
65  */

66 public int getAscent() {
67     return ascent;
68 }
69
70 /**
71  * Returns the average character width, measured in pixels,
72  * of the font described by the receiver.
73  *
74  * @return the average character width of the font
75  */

76 public int getAverageCharWidth() {
77     return averageCharWidth;
78 }
79
80 /**
81  * Returns the descent of the font described by the receiver. A
82  * font's <em>descent</em> is the distance from the baseline to the
83  * bottom of actual characters, not including any of the leading area,
84  * measured in pixels.
85  *
86  * @return the descent of the font
87  */

88 public int getDescent() {
89     return descent;
90 }
91
92 /**
93  * Returns the height of the font described by the receiver,
94  * measured in pixels. A font's <em>height</em> is the sum of
95  * its ascent, descent and leading area.
96  *
97  * @return the height of the font
98  *
99  * @see #getAscent
100  * @see #getDescent
101  * @see #getLeading
102  */

103 public int getHeight() {
104     return height;
105 }
106
107 /**
108  * Returns the leading area of the font described by the
109  * receiver. A font's <em>leading area</em> is the space
110  * above its ascent which may include accents or other marks.
111  *
112  * @return the leading space of the font
113  */

114 public int getLeading() {
115     return leading;
116 }
117
118 /**
119  * Returns an integer hash code for the receiver. Any two
120  * objects that return <code>true</code> when passed to
121  * <code>equals</code> must return the same value for this
122  * method.
123  *
124  * @return the receiver's hash
125  *
126  * @see #equals
127  */

128 public int hashCode() {
129     return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
130 }
131
132 }
133
Popular Tags