diff dwt/graphics/FontData.d @ 30:93b13b15f0b1

Ported a couple of modules in dwt.graphics
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Thu, 11 Sep 2008 23:16:53 +0200
parents a9ab4c738ed8
children 7d135fe0caf2
line wrap: on
line diff
--- a/dwt/graphics/FontData.d	Wed Sep 10 23:18:26 2008 +0200
+++ b/dwt/graphics/FontData.d	Thu Sep 11 23:16:53 2008 +0200
@@ -7,14 +7,17 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.FontData;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.DWT;
 
+import dwt.dwthelper.utils;
+
 /**
  * Instances of this class describe operating system fonts.
  * <p>
@@ -110,7 +113,7 @@
  * generated on the same platform.
  * </p>
  *
- * @param string the string representation of a <code>FontData</code> (must not be null)
+ * @param str the string representation of a <code>FontData</code> (must not be null)
  *
  * @exception IllegalArgumentException <ul>
  *    <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
@@ -119,12 +122,12 @@
  *
  * @see #toString
  */
-public this(String string) {
-    if (string is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
+public this(String str) {
+    //if (str is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     int start = 0;
-    int end = string.indexOf('|');
+    int end = str.indexOf('|');
     if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    String version1 = string.substring(start, end);
+    String version1 = str.substring(start, end);
     try {
         if (Integer.parseInt(version1) !is 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     } catch (NumberFormatException e) {
@@ -132,47 +135,47 @@
     }
     
     start = end + 1;
-    end = string.indexOf('|', start);
+    end = str.indexOf('|', start);
     if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    String name = string.substring(start, end);
+    String name = str.substring(start, end);
     
     start = end + 1;
-    end = string.indexOf('|', start);
+    end = str.indexOf('|', start);
     if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     float height = 0;
     try {
-        height = Float.parseFloat(string.substring(start, end));
+        height = Float.parseFloat(str.substring(start, end));
     } catch (NumberFormatException e) {
         DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     }
     
     start = end + 1;
-    end = string.indexOf('|', start);
+    end = str.indexOf('|', start);
     if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     int style = 0;
     try {
-        style = Integer.parseInt(string.substring(start, end));
+        style = Integer.parseInt(str.substring(start, end));
     } catch (NumberFormatException e) {
         DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     }
 
     start = end + 1;
-    end = string.indexOf('|', start);
+    end = str.indexOf('|', start);
     setName(name);
     setHeight(height);
     setStyle(style);
     if (end is -1) return;
-    String platform = string.substring(start, end);
+    String platform = str.substring(start, end);
 
     start = end + 1;
-    end = string.indexOf('|', start);
+    end = str.indexOf('|', start);
     if (end is -1) return;
-    String version2 = string.substring(start, end);
+    String version2 = str.substring(start, end);
 
     if (platform.equals("COCOA") && version2.equals("1")) {
         start = end + 1;
-        end = string.length();
-        if (start < end) nsName = string.substring(start, end);
+        end = str.length();
+        if (start < end) nsName = str.substring(start, end);
     }
 }
 
@@ -196,7 +199,7 @@
     setStyle(style);
 }
 
-/*public*/ FontData(String name, float height, int style) {
+/*public*/ this(String name, float height, int style) {
     setName(name);
     setHeight(height);
     setStyle(style);
@@ -212,13 +215,15 @@
  *
  * @see #hashCode
  */
-public bool equals (Object object) {
+public bool opEquals (Object object) {
     if (object is this) return true;
     if (!( null !is cast(FontData)object )) return false;
     FontData data = cast(FontData)object;
     return name.equals(data.name) && height is data.height && style is data.style;
 }
 
+alias opEquals equals;
+
 /**
  * Returns the height of the receiver in points.
  *
@@ -312,10 +317,12 @@
  *
  * @see #equals
  */
-public int hashCode () {
+public hast_t toHash () {
     return name.hashCode() ^ getHeight() ^ style;
 }
 
+alias toHash hashCode;
+
 /**
  * Sets the height of the receiver. The parameter is
  * specified in terms of points, where a point is one
@@ -402,7 +409,7 @@
  * @see #getName
  */
 public void setName(String name) {
-    if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
+    //if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     this.name = name;
     nsName = null;
 }