1 /******************************************************************************* 2 * Copyright (c) 2000, 2008 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 org.eclipse.swt.graphics.FontMetrics; 14 15 import java.lang.all; 16 17 18 /** 19 * Instances of this class provide measurement information 20 * about fonts including ascent, descent, height, leading 21 * space between rows, and average character width. 22 * <code>FontMetrics</code> are obtained from <code>GC</code>s 23 * using the <code>getFontMetrics()</code> method. 24 * 25 * @see GC#getFontMetrics 26 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> 27 */ 28 public final class FontMetrics { 29 int ascent, descent, averageCharWidth, leading, height; 30 31 package this() { 32 } 33 34 /** 35 * Compares the argument to the receiver, and returns true 36 * if they represent the <em>same</em> object using a class 37 * specific comparison. 38 * 39 * @param object the object to compare with this object 40 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise 41 * 42 * @see #hashCode 43 */ 44 public override equals_t opEquals (Object object) { 45 if (object is this) return true; 46 if( auto metrics = cast(FontMetrics)object ){ 47 return ascent is metrics.ascent && descent is metrics.descent && 48 averageCharWidth is metrics.averageCharWidth && leading is metrics.leading && 49 height is metrics.height; 50 } 51 return false; 52 } 53 54 /** 55 * Returns the ascent of the font described by the receiver. A 56 * font's <em>ascent</em> is the distance from the baseline to the 57 * top of actual characters, not including any of the leading area, 58 * measured in pixels. 59 * 60 * @return the ascent of the font 61 */ 62 public int getAscent() { 63 return ascent; 64 } 65 66 /** 67 * Returns the average character width, measured in pixels, 68 * of the font described by the receiver. 69 * 70 * @return the average character width of the font 71 */ 72 public int getAverageCharWidth() { 73 return averageCharWidth; 74 } 75 76 /** 77 * Returns the descent of the font described by the receiver. A 78 * font's <em>descent</em> is the distance from the baseline to the 79 * bottom of actual characters, not including any of the leading area, 80 * measured in pixels. 81 * 82 * @return the descent of the font 83 */ 84 public int getDescent() { 85 return descent; 86 } 87 88 /** 89 * Returns the height of the font described by the receiver, 90 * measured in pixels. A font's <em>height</em> is the sum of 91 * its ascent, descent and leading area. 92 * 93 * @return the height of the font 94 * 95 * @see #getAscent 96 * @see #getDescent 97 * @see #getLeading 98 */ 99 public int getHeight() { 100 return height; 101 } 102 103 /** 104 * Returns the leading area of the font described by the 105 * receiver. A font's <em>leading area</em> is the space 106 * above its ascent which may include accents or other marks. 107 * 108 * @return the leading space of the font 109 */ 110 public int getLeading() { 111 return leading; 112 } 113 114 public static FontMetrics gtk_new(int ascent, int descent, int averageCharWidth, int leading, int height) { 115 FontMetrics fontMetrics = new FontMetrics(); 116 fontMetrics.ascent = ascent; 117 fontMetrics.descent = descent; 118 fontMetrics.averageCharWidth = averageCharWidth; 119 fontMetrics.leading = leading; 120 fontMetrics.height = height; 121 return fontMetrics; 122 } 123 124 /** 125 * Returns an integer hash code for the receiver. Any two 126 * objects that return <code>true</code> when passed to 127 * <code>equals</code> must return the same value for this 128 * method. 129 * 130 * @return the receiver's hash 131 * 132 * @see #equals 133 */ 134 public override hash_t toHash() { 135 return ascent ^ descent ^ averageCharWidth ^ leading ^ height; 136 } 137 138 }