comparison dwt/graphics/Font.d @ 36:db5a898b2119

Fixed a lot of compile errors
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Tue, 07 Oct 2008 12:56:18 +0200
parents 93b13b15f0b1
children 642f460a0908
comparison
equal deleted inserted replaced
35:7d135fe0caf2 36:db5a898b2119
19 import dwt.DWTException; 19 import dwt.DWTException;
20 import dwt.internal.cocoa.NSFont; 20 import dwt.internal.cocoa.NSFont;
21 import dwt.internal.cocoa.NSString; 21 import dwt.internal.cocoa.NSString;
22 22
23 import tango.stdc.stringz; 23 import tango.stdc.stringz;
24 import tango.text.convert.Utf; 24 import tango.text.convert.Format;
25 static import tango.text.convert.Utf;
25 26
26 import dwt.dwthelper.utils; 27 import dwt.dwthelper.utils;
27 import dwt.graphics.Device; 28 import dwt.graphics.Device;
28 import dwt.graphics.FontData; 29 import dwt.graphics.FontData;
29 import dwt.graphics.Resource; 30 import dwt.graphics.Resource;
42 * 43 *
43 * @see FontData 44 * @see FontData
44 */ 45 */
45 public final class Font : Resource { 46 public final class Font : Resource {
46 47
48 alias Resource.init_ init_;
49
47 /** 50 /**
48 * the handle to the OS font resource 51 * the handle to the OS font resource
49 * (Warning: This field is platform dependent) 52 * (Warning: This field is platform dependent)
50 * <p> 53 * <p>
51 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT 54 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT
79 * </ul> 82 * </ul>
80 */ 83 */
81 public this(Device device, FontData fd) { 84 public this(Device device, FontData fd) {
82 super(device); 85 super(device);
83 if (fd is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 86 if (fd is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
84 init(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.nsName); 87 init_(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.nsName);
85 init(); 88 init_();
86 } 89 }
87 90
88 /** 91 /**
89 * Constructs a new font given a device and an array 92 * Constructs a new font given a device and an array
90 * of font data which describes the desired font's 93 * of font data which describes the desired font's
114 if (fds.length is 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 117 if (fds.length is 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
115 for (int i=0; i<fds.length; i++) { 118 for (int i=0; i<fds.length; i++) {
116 if (fds[i] is null) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 119 if (fds[i] is null) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
117 } 120 }
118 FontData fd = fds[0]; 121 FontData fd = fds[0];
119 init(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.nsName); 122 init_(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.nsName);
120 init(); 123 init_();
121 } 124 }
122 125
123 /** 126 /**
124 * Constructs a new font given a device, a font name, 127 * Constructs a new font given a device, a font name,
125 * the height of the desired font in points, and a font 128 * the height of the desired font in points, and a font
142 * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li> 145 * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li>
143 * </ul> 146 * </ul>
144 */ 147 */
145 public this(Device device, String name, int height, int style) { 148 public this(Device device, String name, int height, int style) {
146 super(device); 149 super(device);
147 init(name, height, style, null); 150 init_(name, height, style, null);
148 init(); 151 init_();
149 } 152 }
150 153
151 /*public*/ this(Device device, String name, float height, int style) { 154 /*public*/ this(Device device, String name, float height, int style) {
152 super(device); 155 super(device);
153 init(name, height, style, null); 156 init_(name, height, style, null);
154 init(); 157 init_();
155 } 158 }
156 159
157 void destroy() { 160 void destroy() {
158 handle.release(); 161 handle.release();
159 handle = null; 162 handle = null;
167 * @param object the object to compare with this object 170 * @param object the object to compare with this object
168 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise 171 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
169 * 172 *
170 * @see #hashCode 173 * @see #hashCode
171 */ 174 */
172 public bool opEquals(Object object) { 175 public int opEquals(Object object) {
173 if (object is this) return true; 176 if (object is this) return true;
174 if (!( null !is cast(Font)object )) return false; 177 if (!( null !is cast(Font)object )) return false;
175 Font font = cast(Font)object; 178 Font font = cast(Font)object;
176 return handle is font.handle; 179 return handle is font.handle;
177 } 180 }
192 */ 195 */
193 public FontData[] getFontData() { 196 public FontData[] getFontData() {
194 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 197 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
195 NSString family = handle.familyName(); 198 NSString family = handle.familyName();
196 wchar[] buffer1 = new wchar[family.length()]; 199 wchar[] buffer1 = new wchar[family.length()];
197 family.getCharacters_(buffer1); 200 family.getCharacters_(buffer1.ptr);
198 String name = buffer1.toString().dup; 201 String name = tango.text.convert.Utf.toString(buffer1).dup;
199 NSString str = handle.fontName(); 202 NSString str = handle.fontName();
200 wchar[] buffer = new wchar[str.length()]; 203 wchar[] buffer = new wchar[str.length()];
201 str.getCharacters_(buffer); 204 str.getCharacters_(buffer.ptr);
202 String nsName = buffer.toString().dup; 205 String nsName = tango.text.convert.Utf.toString(buffer).dup;
203 int style = DWT.NORMAL; 206 int style = DWT.NORMAL;
204 if (nsName.indexOf("Italic") !is -1) style |= DWT.ITALIC; 207 if (nsName.indexOf("Italic") !is -1) style |= DWT.ITALIC;
205 if (nsName.indexOf("Bold") !is -1) style |= DWT.BOLD; 208 if (nsName.indexOf("Bold") !is -1) style |= DWT.BOLD;
206 FontData data = new FontData(name, handle.pointSize(), style); 209 FontData data = new FontData(name, handle.pointSize(), style);
207 data.nsName = nsName; 210 data.nsName = nsName;
208 return new FontData[][data]; 211 return [data];
209 } 212 }
210 213
211 /** 214 /**
212 * Invokes platform specific functionality to allocate a new font. 215 * Invokes platform specific functionality to allocate a new font.
213 * <p> 216 * <p>
240 * @return the receiver's hash 243 * @return the receiver's hash
241 * 244 *
242 * @see #equals 245 * @see #equals
243 */ 246 */
244 public hash_t toHash() { 247 public hash_t toHash() {
245 return handle !is null ? handle.id : 0; 248 return handle !is null ? cast(hash_t) handle.id_ : 0;
246 } 249 }
247 250
248 alias toHash hashCode; 251 alias toHash hashCode;
249 252
250 void init(String name, float height, int style, String nsName) { 253 void init_(String name, float height, int style, String nsName) {
251 //if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 254 //if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
252 if (height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 255 if (height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
253 if (nsName !is null) { 256 if (nsName !is null) {
254 handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height); 257 handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height);
255 } else { 258 } else {
256 nsName = name; 259 nsName = name;
257 if ((style & DWT.BOLD) !is 0) nsName += " Bold"; 260 if ((style & DWT.BOLD) !is 0) nsName ~= " Bold";
258 if ((style & DWT.ITALIC) !is 0) nsName += " Italic"; 261 if ((style & DWT.ITALIC) !is 0) nsName ~= " Italic";
259 handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height); 262 handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height);
260 if (handle is null && (style & DWT.ITALIC) !is 0) { 263 if (handle is null && (style & DWT.ITALIC) !is 0) {
261 nsName = name; 264 nsName = name;
262 if ((style & DWT.BOLD) !is 0) nsName += " Bold"; 265 if ((style & DWT.BOLD) !is 0) nsName ~= " Bold";
263 handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height); 266 handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height);
264 } 267 }
265 if (handle is null && (style & DWT.BOLD) !is 0) { 268 if (handle is null && (style & DWT.BOLD) !is 0) {
266 nsName = name; 269 nsName = name;
267 handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height); 270 handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height);
293 * 296 *
294 * @return a string representation of the receiver 297 * @return a string representation of the receiver
295 */ 298 */
296 public String toString () { 299 public String toString () {
297 if (isDisposed()) return "Font {*DISPOSED*}"; 300 if (isDisposed()) return "Font {*DISPOSED*}";
298 return "Font {" ~ handle ~ "}"; 301 return Format("Font {{}{}" , handle , "}");
299 } 302 }
300 303
301 } 304 }