Mercurial > projects > dwt-mac
diff dwt/graphics/Font.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 | db5a898b2119 |
line wrap: on
line diff
--- a/dwt/graphics/Font.d Wed Sep 10 23:18:26 2008 +0200 +++ b/dwt/graphics/Font.d Thu Sep 11 23:16:53 2008 +0200 @@ -7,11 +7,12 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg <jacob.carlborg@gmail.com> *******************************************************************************/ module dwt.graphics.Font; -import dwt.dwthelper.utils; - import dwt.DWT; import dwt.DWTError; @@ -19,6 +20,15 @@ import dwt.internal.cocoa.NSFont; import dwt.internal.cocoa.NSString; +import tango.stdc.stringz; +import tango.text.convert.Utf; + +import dwt.dwthelper.utils; +import dwt.graphics.Device; +import dwt.graphics.FontData; +import dwt.graphics.Resource; +import dwt.internal.cocoa.CGFloat; + /** * Instances of this class manage operating system resources that * define how text looks when it is displayed. Fonts may be constructed @@ -138,7 +148,7 @@ init(); } -/*public*/ Font(Device device, String name, float height, int style) { +/*public*/ this(Device device, String name, float height, int style) { super(device); init(name, height, style, null); init(); @@ -159,13 +169,15 @@ * * @see #hashCode */ -public bool equals(Object object) { +public bool opEquals(Object object) { if (object is this) return true; if (!( null !is cast(Font)object )) return false; Font font = cast(Font)object; return handle is font.handle; } +alias opEquals equals; + /** * Returns an array of <code>FontData</code>s representing the receiver. * On Windows, only one FontData will be returned per font. On X however, @@ -181,19 +193,19 @@ public FontData[] getFontData() { if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); NSString family = handle.familyName(); - char[] buffer1 = new char[family.length()]; + wchar[] buffer1 = new wchar[family.length()]; family.getCharacters_(buffer1); - String name = new String(buffer1); + String name = buffer1.toString().dup; NSString str = handle.fontName(); - char[] buffer = new char[str.length()]; + wchar[] buffer = new wchar[str.length()]; str.getCharacters_(buffer); - String nsName = new String(buffer); + String nsName = buffer.toString().dup; int style = DWT.NORMAL; if (nsName.indexOf("Italic") !is -1) style |= DWT.ITALIC; if (nsName.indexOf("Bold") !is -1) style |= DWT.BOLD; FontData data = new FontData(name, handle.pointSize(), style); data.nsName = nsName; - return new FontData[]{data}; + return new FontData[][data]; } /** @@ -229,28 +241,30 @@ * * @see #equals */ -public int hashCode() { +public hash_t toHash() { return handle !is null ? handle.id : 0; } +alias toHash hashCode; + void init(String name, float height, int style, String nsName) { - if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); + //if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); if (height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); if (nsName !is null) { - handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), height); + handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height); } else { nsName = name; if ((style & DWT.BOLD) !is 0) nsName += " Bold"; if ((style & DWT.ITALIC) !is 0) nsName += " Italic"; - handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), height); + handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height); if (handle is null && (style & DWT.ITALIC) !is 0) { nsName = name; if ((style & DWT.BOLD) !is 0) nsName += " Bold"; - handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), height); + handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height); } if (handle is null && (style & DWT.BOLD) !is 0) { nsName = name; - handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), height); + handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height); } } if (handle is null) { @@ -281,7 +295,7 @@ */ public String toString () { if (isDisposed()) return "Font {*DISPOSED*}"; - return "Font {" + handle + "}"; + return "Font {" ~ handle ~ "}"; } }