comparison dwt/graphics/Font.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children fd9c62a2998e
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
40 * @see FontData 40 * @see FontData
41 */ 41 */
42 42
43 public final class Font : Resource { 43 public final class Font : Resource {
44 44
45 alias Resource.init_ init_;
45 /** 46 /**
46 * the handle to the OS font resource 47 * the handle to the OS font resource
47 * (Warning: This field is platform dependent) 48 * (Warning: This field is platform dependent)
48 * <p> 49 * <p>
49 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT 50 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT
55 public HFONT handle; 56 public HFONT handle;
56 57
57 /** 58 /**
58 * Prevents uninitialized instances from being created outside the package. 59 * Prevents uninitialized instances from being created outside the package.
59 */ 60 */
60 this() { 61 this(Device device) {
62 super(device);
61 } 63 }
62 64
63 /** 65 /**
64 * Constructs a new font given a device and font data 66 * Constructs a new font given a device and font data
65 * which describes the desired font's appearance. 67 * which describes the desired font's appearance.
77 * @exception DWTError <ul> 79 * @exception DWTError <ul>
78 * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li> 80 * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
79 * </ul> 81 * </ul>
80 */ 82 */
81 public this(Device device, FontData fd) { 83 public this(Device device, FontData fd) {
82 if (device is null) device = Device.getDevice(); 84 super(device);
83 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 85 init_(fd);
84 init_(device, fd); 86 init_();
85 if (device.tracking) device.new_Object(this);
86 } 87 }
87 88
88 /** 89 /**
89 * Constructs a new font given a device and an array 90 * Constructs a new font given a device and an array
90 * of font data which describes the desired font's 91 * of font data which describes the desired font's
107 * </ul> 108 * </ul>
108 * 109 *
109 * @since 2.1 110 * @since 2.1
110 */ 111 */
111 public this(Device device, FontData[] fds) { 112 public this(Device device, FontData[] fds) {
112 if (device is null) device = Device.getDevice(); 113 super(device);
113 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
114 if (fds is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 114 if (fds is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
115 if (fds.length is 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 115 if (fds.length is 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
116 for (int i=0; i<fds.length; i++) { 116 for (int i=0; i<fds.length; i++) {
117 if (fds[i] is null) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 117 if (fds[i] is null) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
118 } 118 }
119 init_(device, fds[0]); 119 init_(fds[0]);
120 if (device.tracking) device.new_Object(this); 120 init_();
121 } 121 }
122 122
123 /** 123 /**
124 * Constructs a new font given a device, a font name, 124 * Constructs a new font given a device, a font name,
125 * the height of the desired font in points, and a font 125 * the height of the desired font in points, and a font
141 * @exception DWTError <ul> 141 * @exception DWTError <ul>
142 * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li> 142 * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li>
143 * </ul> 143 * </ul>
144 */ 144 */
145 public this(Device device, String name, int height, int style) { 145 public this(Device device, String name, int height, int style) {
146 if (device is null) device = Device.getDevice(); 146 super(device);
147 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
148 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 147 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
149 init_(device, new FontData (name, height, style)); 148 init_(new FontData (name, height, style));
150 if (device.tracking) device.new_Object(this); 149 init_();
151 } 150 }
152 151
153 /*public*/ this(Device device, String name, float height, int style) { 152 /*public*/ this(Device device, String name, float height, int style) {
154 if (device is null) device = Device.getDevice(); 153 super(device);
155 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
156 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 154 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
157 init_(device, new FontData (name, height, style)); 155 init_(new FontData (name, height, style));
158 if (device.tracking) device.new_Object(this); 156 init_();
159 } 157 }
160 158 void destroy() {
161 /**
162 * Disposes of the operating system resources associated with
163 * the font. Applications must dispose of all fonts which
164 * they allocate.
165 */
166 override public void dispose() {
167 if (handle is null) return;
168 if (device.isDisposed()) return;
169 OS.DeleteObject(handle); 159 OS.DeleteObject(handle);
170 handle = null; 160 handle = null;
171 if (device.tracking) device.dispose_Object(this);
172 device = null;
173 } 161 }
174 162
175 /** 163 /**
176 * Compares the argument to the receiver, and returns true 164 * Compares the argument to the receiver, and returns true
177 * if they represent the <em>same</em> object using a class 165 * if they represent the <em>same</em> object using a class
221 */ 209 */
222 override public hash_t toHash () { 210 override public hash_t toHash () {
223 return cast(hash_t)handle; 211 return cast(hash_t)handle;
224 } 212 }
225 213
226 void init_ (Device device, FontData fd) { 214 void init_ (FontData fd) {
227 if (fd is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 215 if (fd is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
228 this.device = device;
229 LOGFONT* logFont = &fd.data; 216 LOGFONT* logFont = &fd.data;
230 int lfHeight = logFont.lfHeight; 217 int lfHeight = logFont.lfHeight;
231 logFont.lfHeight = device.computePixels(fd.height); 218 logFont.lfHeight = device.computePixels(fd.height);
232 handle = OS.CreateFontIndirect(logFont); 219 handle = OS.CreateFontIndirect(logFont);
233 logFont.lfHeight = lfHeight; 220 logFont.lfHeight = lfHeight;
272 * @param device the device on which to allocate the color 259 * @param device the device on which to allocate the color
273 * @param handle the handle for the font 260 * @param handle the handle for the font
274 * @return a new font object containing the specified device and handle 261 * @return a new font object containing the specified device and handle
275 */ 262 */
276 public static Font win32_new(Device device, HFONT handle) { 263 public static Font win32_new(Device device, HFONT handle) {
277 if (device is null) device = Device.getDevice(); 264 Font font = new Font(device);
278 Font font = new Font();
279 font.handle = handle; 265 font.handle = handle;
280 font.device = device;
281 return font; 266 return font;
282 } 267 }
283 268
284 } 269 }