# HG changeset patch # User Frank Benoit # Date 1201265780 -3600 # Node ID ac97aa23bcb743d152fa885305b3e5ca725eb1fb # Parent 6696f884b8a65f7ac3a9d5bce7c57894435e650b FontMetrics diff -r 6696f884b8a6 -r ac97aa23bcb7 dwt/graphics/FontMetrics.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/graphics/FontMetrics.d Fri Jan 25 13:56:20 2008 +0100 @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ +module dwt.graphics.FontMetrics; + + +/** + * Instances of this class provide measurement information + * about fonts including ascent, descent, height, leading + * space between rows, and average character width. + * FontMetrics are obtained from GCs + * using the getFontMetrics() method. + * + * @see GC#getFontMetrics + */ +public final class FontMetrics { + int ascent, descent, averageCharWidth, leading, height; + +package this() { +} + +/** + * Compares the argument to the receiver, and returns true + * if they represent the same object using a class + * specific comparison. + * + * @param object the object to compare with this object + * @return true if the object is the same as this object and false otherwise + * + * @see #hashCode + */ +public int opEquals (Object object) { + if (object is this) return true; + if( auto metrics = cast(FontMetrics)object ){ + return ascent == metrics.ascent && descent == metrics.descent && + averageCharWidth == metrics.averageCharWidth && leading == metrics.leading && + height == metrics.height; + } + return false; +} + +/** + * Returns the ascent of the font described by the receiver. A + * font's ascent is the distance from the baseline to the + * top of actual characters, not including any of the leading area, + * measured in pixels. + * + * @return the ascent of the font + */ +public int getAscent() { + return ascent; +} + +/** + * Returns the average character width, measured in pixels, + * of the font described by the receiver. + * + * @return the average character width of the font + */ +public int getAverageCharWidth() { + return averageCharWidth; +} + +/** + * Returns the descent of the font described by the receiver. A + * font's descent is the distance from the baseline to the + * bottom of actual characters, not including any of the leading area, + * measured in pixels. + * + * @return the descent of the font + */ +public int getDescent() { + return descent; +} + +/** + * Returns the height of the font described by the receiver, + * measured in pixels. A font's height is the sum of + * its ascent, descent and leading area. + * + * @return the height of the font + * + * @see #getAscent + * @see #getDescent + * @see #getLeading + */ +public int getHeight() { + return height; +} + +/** + * Returns the leading area of the font described by the + * receiver. A font's leading area is the space + * above its ascent which may include accents or other marks. + * + * @return the leading space of the font + */ +public int getLeading() { + return leading; +} + +public static FontMetrics gtk_new(int ascent, int descent, int averageCharWidth, int leading, int height) { + FontMetrics fontMetrics = new FontMetrics(); + fontMetrics.ascent = ascent; + fontMetrics.descent = descent; + fontMetrics.averageCharWidth = averageCharWidth; + fontMetrics.leading = leading; + fontMetrics.height = height; + return fontMetrics; +} + +/** + * Returns an integer hash code for the receiver. Any two + * objects that return true when passed to + * equals must return the same value for this + * method. + * + * @return the receiver's hash + * + * @see #equals + */ +public hash_t toHash() { + return ascent ^ descent ^ averageCharWidth ^ leading ^ height; +} + +}