Mercurial > projects > dwt-linux
annotate dwt/graphics/FontMetrics.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 | b6bee07cfc0b |
children |
rev | line source |
---|---|
72 | 1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
4 | 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> | |
4 | 12 *******************************************************************************/ |
10
63c023465156
moved from org.eclipse.swt to dwt
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
13 module dwt.graphics.FontMetrics; |
4 | 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 | |
259 | 24 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
4 | 25 */ |
26 public final class FontMetrics { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
27 int ascent, descent, averageCharWidth, leading, height; |
4 | 28 |
29 package this() { | |
30 } | |
31 | |
32 /** | |
33 * Compares the argument to the receiver, and returns true | |
34 * if they represent the <em>same</em> object using a class | |
35 * specific comparison. | |
36 * | |
37 * @param object the object to compare with this object | |
38 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
39 * | |
40 * @see #hashCode | |
41 */ | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
42 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:
10
diff
changeset
|
43 if (object is this) return true; |
4 | 44 if( auto metrics = cast(FontMetrics)object ){ |
194 | 45 return ascent is metrics.ascent && descent is metrics.descent && |
46 averageCharWidth is metrics.averageCharWidth && leading is metrics.leading && | |
47 height is metrics.height; | |
4 | 48 } |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
49 return false; |
4 | 50 } |
51 | |
52 /** | |
53 * Returns the ascent of the font described by the receiver. A | |
54 * font's <em>ascent</em> is the distance from the baseline to the | |
55 * top of actual characters, not including any of the leading area, | |
56 * measured in pixels. | |
57 * | |
58 * @return the ascent of the font | |
59 */ | |
60 public int getAscent() { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
61 return ascent; |
4 | 62 } |
63 | |
64 /** | |
65 * Returns the average character width, measured in pixels, | |
66 * of the font described by the receiver. | |
67 * | |
68 * @return the average character width of the font | |
69 */ | |
70 public int getAverageCharWidth() { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
71 return averageCharWidth; |
4 | 72 } |
73 | |
74 /** | |
75 * Returns the descent of the font described by the receiver. A | |
76 * font's <em>descent</em> is the distance from the baseline to the | |
77 * bottom of actual characters, not including any of the leading area, | |
78 * measured in pixels. | |
79 * | |
80 * @return the descent of the font | |
81 */ | |
82 public int getDescent() { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
83 return descent; |
4 | 84 } |
85 | |
86 /** | |
87 * Returns the height of the font described by the receiver, | |
88 * measured in pixels. A font's <em>height</em> is the sum of | |
89 * its ascent, descent and leading area. | |
90 * | |
91 * @return the height of the font | |
92 * | |
93 * @see #getAscent | |
94 * @see #getDescent | |
95 * @see #getLeading | |
96 */ | |
97 public int getHeight() { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
98 return height; |
4 | 99 } |
100 | |
101 /** | |
102 * Returns the leading area of the font described by the | |
103 * receiver. A font's <em>leading area</em> is the space | |
104 * above its ascent which may include accents or other marks. | |
105 * | |
106 * @return the leading space of the font | |
107 */ | |
108 public int getLeading() { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
109 return leading; |
4 | 110 } |
111 | |
112 public static FontMetrics gtk_new(int ascent, int descent, int averageCharWidth, int leading, int height) { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
113 FontMetrics fontMetrics = new FontMetrics(); |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
114 fontMetrics.ascent = ascent; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
115 fontMetrics.descent = descent; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
116 fontMetrics.averageCharWidth = averageCharWidth; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
117 fontMetrics.leading = leading; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
118 fontMetrics.height = height; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
119 return fontMetrics; |
4 | 120 } |
121 | |
122 /** | |
123 * Returns an integer hash code for the receiver. Any two | |
124 * objects that return <code>true</code> when passed to | |
125 * <code>equals</code> must return the same value for this | |
126 * method. | |
127 * | |
128 * @return the receiver's hash | |
129 * | |
130 * @see #equals | |
131 */ | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
132 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:
10
diff
changeset
|
133 return ascent ^ descent ^ averageCharWidth ^ leading ^ height; |
4 | 134 } |
135 | |
136 } |