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.GlyphMetrics; 14 15 import java.lang.all; 16 17 import org.eclipse.swt.SWT; 18 /** 19 * Instances of this class represent glyph metrics. 20 * <p> 21 * The hashCode() method in this class uses the values of the public 22 * fields to compute the hash value. When storing instances of the 23 * class in hashed collections, do not modify these fields after the 24 * object has been inserted. 25 * </p> 26 * <p> 27 * Application code does <em>not</em> need to explicitly release the 28 * resources managed by each instance when those instances are no longer 29 * required, and thus no <code>dispose()</code> method is provided. 30 * </p> 31 * 32 * @see TextStyle 33 * @see TextLayout 34 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> 35 * 36 * @since 3.2 37 */ 38 public final class GlyphMetrics { 39 40 /** 41 * the ascent of the GlyphMetrics 42 */ 43 public int ascent; 44 45 /** 46 * the descent of the GlyphMetrics 47 */ 48 public int descent; 49 50 /** 51 * the width of the GlyphMetrics 52 */ 53 public int width; 54 55 /** 56 * Constructs an instance of this class with the given 57 * ascent, descent and width values. 58 * 59 * @param ascent the GlyphMetrics ascent 60 * @param descent the GlyphMetrics descent 61 * @param width the GlyphMetrics width 62 * 63 * @exception IllegalArgumentException <ul> 64 * <li>ERROR_INVALID_ARGUMENT - if the ascent, descent or width argument is negative</li> 65 * </ul> 66 */ 67 public this(int ascent, int descent, int width) { 68 if (ascent < 0 || descent < 0 || width < 0) { 69 SWT.error(SWT.ERROR_INVALID_ARGUMENT); 70 } 71 this.ascent = ascent; 72 this.descent = descent; 73 this.width = width; 74 } 75 76 /** 77 * Compares the argument to the receiver, and returns true 78 * if they represent the <em>same</em> object using a class 79 * specific comparison. 80 * 81 * @param object the object to compare with this object 82 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise 83 * 84 * @see #hashCode() 85 */ 86 public override equals_t opEquals (Object object) { 87 if (object is this) return true; 88 if (auto metrics = cast(GlyphMetrics)object ){ 89 return metrics.ascent is ascent && metrics.descent is descent && metrics.width is width; 90 } 91 return false; 92 } 93 94 95 /** 96 * Returns an integer hash code for the receiver. Any two 97 * objects that return <code>true</code> when passed to 98 * <code>equals</code> must return the same value for this 99 * method. 100 * 101 * @return the receiver's hash 102 * 103 * @see #equals(Object) 104 */ 105 public override hash_t toHash () { 106 return ascent ^ descent ^ width; 107 } 108 109 /** 110 * Returns a string containing a concise, human-readable 111 * description of the receiver. 112 * 113 * @return a string representation of the <code>GlyphMetrics</code> 114 */ 115 public override String toString () { 116 return Format( "GlyphMetrics {{{}, {}, {}}", ascent, descent, width ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 117 } 118 119 }