changeset 8:4287bcee9960

Correct match to win version
author Frank Benoit <benoit@tionex.de>
date Fri, 25 Jan 2008 14:02:07 +0100
parents ac97aa23bcb7
children 9f69ba7a0546
files dwt/graphics/FontMetrics.d
diffstat 1 files changed, 79 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/graphics/FontMetrics.d	Fri Jan 25 13:56:20 2008 +0100
+++ b/dwt/graphics/FontMetrics.d	Fri Jan 25 14:02:07 2008 +0100
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * 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
@@ -7,12 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
- * Port to the D programming language:
- *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.graphics.FontMetrics;
 
 
+import dwt.internal.win32.WINTYPES;
+
 /**
  * Instances of this class provide measurement information
  * about fonts including ascent, descent, height, leading
@@ -22,10 +22,26 @@
  *
  * @see GC#getFontMetrics
  */
+ 
 public final class FontMetrics {
-    int ascent, descent, averageCharWidth, leading, height;
-
-package this() {
+    
+    /**
+     * On Windows, handle is a Win32 TEXTMETRIC struct
+     * On Photon, handle is a Photon FontQueryInfo struct
+     * (Warning: This field is platform dependent)
+     * <p>
+     * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT
+     * public API. It is marked public only so that it can be shared
+     * within the packages provided by DWT. It is not available on all
+     * platforms and should never be accessed from application code.
+     * </p>
+     */
+    public TEXTMETRIC handle;
+    
+/**
+ * Prevents instances from being created outside the package.
+ */
+this() {
 }
 
 /**
@@ -40,24 +56,42 @@
  */
 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;
+    if( auto metricObj = cast(FontMetrics)object ){
+        TEXTMETRIC metric = metricObj.handle;
+        return handle.tmHeight is metric.tmHeight &&
+            handle.tmAscent is metric.tmAscent &&
+            handle.tmDescent is metric.tmDescent &&
+            handle.tmInternalLeading is metric.tmInternalLeading &&
+            handle.tmExternalLeading is metric.tmExternalLeading &&
+            handle.tmAveCharWidth is metric.tmAveCharWidth &&
+            handle.tmMaxCharWidth is metric.tmMaxCharWidth &&
+            handle.tmWeight is metric.tmWeight &&
+            handle.tmOverhang is metric.tmOverhang &&
+            handle.tmDigitizedAspectX is metric.tmDigitizedAspectX &&
+            handle.tmDigitizedAspectY is metric.tmDigitizedAspectY &&
+    //      handle.tmFirstChar is metric.tmFirstChar &&
+    //      handle.tmLastChar is metric.tmLastChar &&
+    //      handle.tmDefaultChar is metric.tmDefaultChar &&
+    //      handle.tmBreakChar is metric.tmBreakChar &&
+            handle.tmItalic is metric.tmItalic &&
+            handle.tmUnderlined is metric.tmUnderlined &&
+            handle.tmStruckOut is metric.tmStruckOut &&
+            handle.tmPitchAndFamily is metric.tmPitchAndFamily &&
+            handle.tmCharSet is metric.tmCharSet;
     }
     return false;
 }
 
 /**
  * Returns the ascent of the font described by the receiver. A
- * font's <em>ascent</em> is the distance from the baseline to the
+ * font's <em>ascent</em> 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;
+    return handle.tmAscent - handle.tmInternalLeading;
 }
 
 /**
@@ -67,7 +101,7 @@
  * @return the average character width of the font
  */
 public int getAverageCharWidth() {
-    return averageCharWidth;
+    return handle.tmAveCharWidth;
 }
 
 /**
@@ -79,11 +113,11 @@
  * @return the descent of the font
  */
 public int getDescent() {
-    return descent;
+    return handle.tmDescent;
 }
 
 /**
- * Returns the height of the font described by the receiver,
+ * Returns the height of the font described by the receiver, 
  * measured in pixels. A font's <em>height</em> is the sum of
  * its ascent, descent and leading area.
  *
@@ -94,7 +128,7 @@
  * @see #getLeading
  */
 public int getHeight() {
-    return height;
+    return handle.tmHeight;
 }
 
 /**
@@ -105,22 +139,12 @@
  * @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;
+    return handle.tmInternalLeading;
 }
 
 /**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
+ * Returns an integer hash code for the receiver. Any two 
+ * objects that return <code>true</code> when passed to 
  * <code>equals</code> must return the same value for this
  * method.
  *
@@ -129,7 +153,32 @@
  * @see #equals
  */
 public hash_t toHash() {
-    return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
+    return handle.tmHeight ^ handle.tmAscent ^ handle.tmDescent ^
+        handle.tmInternalLeading ^ handle.tmExternalLeading ^
+        handle.tmAveCharWidth ^ handle.tmMaxCharWidth ^ handle.tmWeight ^
+        handle.tmOverhang ^ handle.tmDigitizedAspectX ^ handle.tmDigitizedAspectY ^
+//      handle.tmFirstChar ^ handle.tmLastChar ^ handle.tmDefaultChar ^ handle.tmBreakChar ^
+        handle.tmItalic ^ handle.tmUnderlined ^ handle.tmStruckOut ^
+        handle.tmPitchAndFamily ^ handle.tmCharSet;
+}
+
+/**  
+ * Invokes platform specific functionality to allocate a new font metrics.
+ * <p>
+ * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
+ * API for <code>FontMetrics</code>. It is marked public only so that
+ * it can be shared within the packages provided by DWT. It is not
+ * available on all platforms, and should never be called from
+ * application code.
+ * </p>
+ *
+ * @param handle the <code>TEXTMETRIC</code> containing information about a font
+ * @return a new font metrics object containing the specified <code>TEXTMETRIC</code>
+ */
+public static FontMetrics win32_new(TEXTMETRIC handle) {
+    FontMetrics fontMetrics = new FontMetrics();
+    fontMetrics.handle = handle;
+    return fontMetrics;
 }
 
 }