Mercurial > projects > dwt-win
annotate dwt/graphics/FontData.d @ 84:00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 06 Feb 2008 18:46:23 +0100 |
parents | 9a64a7781bab |
children | 0a96e5a30470 |
rev | line source |
---|---|
23 | 1 /******************************************************************************* |
15 | 2 * Copyright (c) 2000, 2007 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
23 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
15 | 12 *******************************************************************************/ |
13 module dwt.graphics.FontData; | |
14 | |
15 | |
16 import dwt.DWT; | |
17 //import dwt.internal.Callback; | |
18 //import dwt.internal.win32.LOGFONT; | |
19 //import dwt.internal.win32.LOGFONTA; | |
20 //import dwt.internal.win32.LOGFONTW; | |
21 import dwt.internal.win32.OS; | |
22 //import dwt.internal.win32.TCHAR; | |
23 | |
24 import dwt.dwthelper.utils; | |
25 import dwt.dwthelper.Float; | |
26 import dwt.dwthelper.Integer; | |
27 static import tango.text.Text; | |
28 import tango.util.Convert; | |
29 alias tango.text.Text.Text!(char) StringBuffer; | |
30 | |
31 /** | |
32 * Instances of this class describe operating system fonts. | |
33 * <p> | |
34 * For platform-independent behaviour, use the get and set methods | |
35 * corresponding to the following properties: | |
36 * <dl> | |
37 * <dt>height</dt><dd>the height of the font in points</dd> | |
38 * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd> | |
39 * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd> | |
40 * </dl> | |
41 * If extra, platform-dependent functionality is required: | |
42 * <ul> | |
43 * <li>On <em>Windows</em>, the data member of the <code>FontData</code> | |
44 * corresponds to a Windows <code>LOGFONT</code> structure whose fields | |
45 * may be retrieved and modified.</li> | |
46 * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond | |
47 * to the entries in the font's XLFD name and may be retrieved and modified. | |
48 * </ul> | |
49 * Application code does <em>not</em> need to explicitly release the | |
50 * resources managed by each instance when those instances are no longer | |
51 * required, and thus no <code>dispose()</code> method is provided. | |
52 * | |
53 * @see Font | |
54 */ | |
55 | |
56 public final class FontData { | |
23 | 57 |
15 | 58 /** |
59 * A Win32 LOGFONT struct | |
60 * (Warning: This field is platform dependent) | |
61 * <p> | |
62 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT | |
63 * public API. It is marked public only so that it can be shared | |
64 * within the packages provided by DWT. It is not available on all | |
65 * platforms and should never be accessed from application code. | |
66 * </p> | |
67 */ | |
68 public LOGFONT data; | |
23 | 69 |
15 | 70 /** |
71 * The height of the font data in points | |
72 * (Warning: This field is platform dependent) | |
73 * <p> | |
74 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT | |
75 * public API. It is marked public only so that it can be shared | |
76 * within the packages provided by DWT. It is not available on all | |
77 * platforms and should never be accessed from application code. | |
78 * </p> | |
79 */ | |
80 public float height; | |
81 | |
82 /** | |
83 * The locales of the font | |
84 */ | |
85 char[] lang, country, variant; | |
86 | |
87 private static FontData s_this; | |
88 | |
23 | 89 /** |
15 | 90 * Constructs a new uninitialized font data. |
91 */ | |
92 public this() { | |
93 // We set the charset field so that | |
94 // wildcard searching will work properly | |
95 // out of the box | |
96 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; | |
97 height = 12; | |
98 } | |
99 | |
100 /** | |
101 * Constructs a new font data given the Windows <code>LOGFONT</code> | |
102 * that it should represent. | |
23 | 103 * |
15 | 104 * @param data the <code>LOGFONT</code> for the result |
105 */ | |
106 this(LOGFONT* data, float height) { | |
107 this.data = *data; | |
108 this.height = height; | |
109 } | |
110 | |
111 /** | |
112 * Constructs a new FontData given a string representation | |
113 * in the form generated by the <code>FontData.toString</code> | |
114 * method. | |
115 * <p> | |
116 * Note that the representation varies between platforms, | |
23 | 117 * and a FontData can only be created from a string that was |
15 | 118 * generated on the same platform. |
119 * </p> | |
120 * | |
121 * @param string the string representation of a <code>FontData</code> (must not be null) | |
122 * | |
123 * @exception IllegalArgumentException <ul> | |
124 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
125 * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li> | |
126 * </ul> | |
127 * | |
128 * @see #toString | |
129 */ | |
130 public this(char[] string) { | |
131 if (string is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
132 int start = 0; | |
133 int end = string.indexOf('|'); | |
134 if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
135 char[] version1 = string.substring(start, end); | |
136 try { | |
23 | 137 if (Integer.parseInt(version1) !is 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
15 | 138 } catch (NumberFormatException e) { |
139 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
140 } | |
23 | 141 |
15 | 142 start = end + 1; |
143 end = string.indexOf('|', start); | |
144 if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
145 char[] name = string.substring(start, end); | |
23 | 146 |
15 | 147 start = end + 1; |
148 end = string.indexOf('|', start); | |
149 if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
150 float height = 0; | |
151 try { | |
152 height = Float.parseFloat(string.substring(start, end)); | |
153 } catch (NumberFormatException e) { | |
154 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
155 } | |
23 | 156 |
15 | 157 start = end + 1; |
158 end = string.indexOf('|', start); | |
159 if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
160 int style = 0; | |
161 try { | |
162 style = Integer.parseInt(string.substring(start, end)); | |
163 } catch (NumberFormatException e) { | |
164 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
165 } | |
166 | |
167 start = end + 1; | |
168 end = string.indexOf('|', start); | |
169 //data = OS.IsUnicode ? cast(LOGFONT)new LOGFONTW() : new LOGFONTA(); | |
170 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; | |
171 setName(name); | |
172 setHeight(height); | |
173 setStyle(style); | |
174 if (end is -1) return; | |
175 char[] platform = string.substring(start, end); | |
176 | |
177 start = end + 1; | |
178 end = string.indexOf('|', start); | |
179 if (end is -1) return; | |
180 char[] version2 = string.substring(start, end); | |
181 | |
182 if (platform ==/*eq*/ "WINDOWS" && version2 ==/*eq*/ "1") { //$NON-NLS-1$//$NON-NLS-2$ | |
183 LOGFONT newData;// = OS.IsUnicode ? cast(LOGFONT)new LOGFONTW() : new LOGFONTA(); | |
184 try { | |
185 start = end + 1; | |
186 end = string.indexOf('|', start); | |
187 if (end is -1) return; | |
188 newData.lfHeight = Integer.parseInt(string.substring(start, end)); | |
189 start = end + 1; | |
190 end = string.indexOf('|', start); | |
191 if (end is -1) return; | |
192 newData.lfWidth = Integer.parseInt(string.substring(start, end)); | |
193 start = end + 1; | |
194 end = string.indexOf('|', start); | |
195 if (end is -1) return; | |
196 newData.lfEscapement = Integer.parseInt(string.substring(start, end)); | |
197 start = end + 1; | |
198 end = string.indexOf('|', start); | |
199 if (end is -1) return; | |
200 newData.lfOrientation = Integer.parseInt(string.substring(start, end)); | |
201 start = end + 1; | |
202 end = string.indexOf('|', start); | |
203 if (end is -1) return; | |
204 newData.lfWeight = Integer.parseInt(string.substring(start, end)); | |
205 start = end + 1; | |
206 end = string.indexOf('|', start); | |
207 if (end is -1) return; | |
208 newData.lfItalic = Byte.parseByte(string.substring(start, end)); | |
209 start = end + 1; | |
210 end = string.indexOf('|', start); | |
211 if (end is -1) return; | |
212 newData.lfUnderline = Byte.parseByte(string.substring(start, end)); | |
213 start = end + 1; | |
214 end = string.indexOf('|', start); | |
215 if (end is -1) return; | |
216 newData.lfStrikeOut = Byte.parseByte(string.substring(start, end)); | |
217 start = end + 1; | |
218 end = string.indexOf('|', start); | |
219 if (end is -1) return; | |
220 newData.lfCharSet = Byte.parseByte(string.substring(start, end)); | |
221 start = end + 1; | |
222 end = string.indexOf('|', start); | |
223 if (end is -1) return; | |
224 newData.lfOutPrecision = Byte.parseByte(string.substring(start, end)); | |
225 start = end + 1; | |
226 end = string.indexOf('|', start); | |
227 if (end is -1) return; | |
228 newData.lfClipPrecision = Byte.parseByte(string.substring(start, end)); | |
229 start = end + 1; | |
230 end = string.indexOf('|', start); | |
231 if (end is -1) return; | |
232 newData.lfQuality = Byte.parseByte(string.substring(start, end)); | |
233 start = end + 1; | |
234 end = string.indexOf('|', start); | |
235 if (end is -1) return; | |
236 newData.lfPitchAndFamily = Byte.parseByte(string.substring(start, end)); | |
237 start = end + 1; | |
238 } catch (NumberFormatException e) { | |
239 setName(name); | |
240 setHeight(height); | |
241 setStyle(style); | |
242 return; | |
243 } | |
244 char[] buffer = string.substring(start); | |
245 int len = Math.min(OS.LF_FACESIZE - 1, buffer.length); | |
246 newData.lfFaceName[ 0 .. len ] = .StrToTCHARs(buffer)[ 0 .. len ]; | |
247 data = newData; | |
248 } | |
249 } | |
250 | |
23 | 251 /** |
15 | 252 * Constructs a new font data given a font name, |
23 | 253 * the height of the desired font in points, |
15 | 254 * and a font style. |
255 * | |
256 * @param name the name of the font (must not be null) | |
257 * @param height the font height in points | |
258 * @param style a bit or combination of NORMAL, BOLD, ITALIC | |
259 * | |
260 * @exception IllegalArgumentException <ul> | |
261 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> | |
262 * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> | |
263 * </ul> | |
264 */ | |
265 public this(char[] name, int height, int style) { | |
266 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
267 setName(name); | |
268 setHeight(height); | |
269 setStyle(style); | |
270 // We set the charset field so that | |
271 // wildcard searching will work properly | |
272 // out of the box | |
273 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; | |
274 } | |
275 | |
276 /*public*/ this(char[] name, float height, int style) { | |
277 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
278 setName(name); | |
279 setHeight(height); | |
280 setStyle(style); | |
281 // We set the charset field so that | |
282 // wildcard searching will work properly | |
283 // out of the box | |
284 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; | |
285 } | |
286 | |
287 /** | |
288 * Compares the argument to the receiver, and returns true | |
289 * if they represent the <em>same</em> object using a class | |
290 * specific comparison. | |
291 * | |
292 * @param object the object to compare with this object | |
293 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
294 * | |
295 * @see #hashCode | |
296 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
297 override public int opEquals (Object object) { |
15 | 298 if (object is this) return true; |
299 if( auto fd = cast(FontData)object ){ | |
17 | 300 LOGFONT* lf = &fd.data; |
15 | 301 return data.lfCharSet is lf.lfCharSet && |
302 /* | |
303 * This code is intentionally commented. When creating | |
304 * a FontData, lfHeight is not necessarily set. Instead | |
305 * we check the height field which is always set. | |
23 | 306 */ |
15 | 307 // data.lfHeight is lf.lfHeight && |
308 height is fd.height && | |
309 data.lfWidth is lf.lfWidth && | |
310 data.lfEscapement is lf.lfEscapement && | |
311 data.lfOrientation is lf.lfOrientation && | |
312 data.lfWeight is lf.lfWeight && | |
313 data.lfItalic is lf.lfItalic && | |
314 data.lfUnderline is lf.lfUnderline && | |
315 data.lfStrikeOut is lf.lfStrikeOut && | |
316 data.lfCharSet is lf.lfCharSet && | |
317 data.lfOutPrecision is lf.lfOutPrecision && | |
318 data.lfClipPrecision is lf.lfClipPrecision && | |
319 data.lfQuality is lf.lfQuality && | |
320 data.lfPitchAndFamily is lf.lfPitchAndFamily && | |
321 getName() ==/*eq*/ fd.getName(); | |
322 } | |
323 return false; | |
324 } | |
325 | |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
326 extern (Windows) static int EnumLocalesProc(TCHAR* lpLocaleString) { |
15 | 327 |
328 /* Get the locale ID */ | |
329 int length_ = 8; | |
330 char[] str = .TCHARzToStr( cast(TCHAR*)lpLocaleString, length_); | |
331 int lcid = Integer.parseInt(str, 16); | |
332 | |
333 TCHAR[] buffer = new TCHAR[length_]; | |
334 | |
335 /* Check the language */ | |
336 int size = OS.GetLocaleInfo(lcid, OS.LOCALE_SISO639LANGNAME, buffer.ptr, length_); | |
337 if (size <= 0 || s_this.lang !=/*eq*/ .TCHARzToStr( buffer.ptr ).substring(0, size - 1)) return 1; | |
338 | |
339 /* Check the country */ | |
340 if (s_this.country !is null) { | |
341 size = OS.GetLocaleInfo(lcid, OS.LOCALE_SISO3166CTRYNAME, buffer.ptr, length_); | |
342 if (size <= 0 || s_this.country !=/*eq*/ .TCHARzToStr( buffer.ptr ).substring(0, size - 1)) return 1; | |
343 } | |
344 | |
345 /* Get the charset */ | |
346 size = OS.GetLocaleInfo(lcid, OS.LOCALE_IDEFAULTANSICODEPAGE, buffer.ptr, length_); | |
347 if (size <= 0) return 1; | |
348 int cp = Integer.parseInt(.TCHARzToStr(buffer.ptr).substring(0, size - 1)); | |
349 CHARSETINFO lpCs; | |
350 OS.TranslateCharsetInfo(cast(DWORD*)cp, &lpCs, OS.TCI_SRCCODEPAGE); | |
351 s_this.data.lfCharSet = cast(BYTE)lpCs.ciCharset; | |
352 | |
353 return 0; | |
354 } | |
355 | |
356 /** | |
357 * Returns the height of the receiver in points. | |
358 * | |
359 * @return the height of this FontData | |
360 * | |
361 * @see #setHeight(int) | |
362 */ | |
363 public int getHeight() { | |
364 return cast(int)(0.5f + height); | |
365 } | |
366 | |
367 /*public*/ float getHeightF() { | |
368 return height; | |
369 } | |
370 | |
371 /** | |
372 * Returns the locale of the receiver. | |
373 * <p> | |
374 * The locale determines which platform character set this | |
375 * font is going to use. Widgets and graphics operations that | |
376 * use this font will convert UNICODE strings to the platform | |
377 * character set of the specified locale. | |
378 * </p> | |
379 * <p> | |
380 * On platforms where there are multiple character sets for a | |
381 * given language/country locale, the variant portion of the | |
382 * locale will determine the character set. | |
383 * </p> | |
23 | 384 * |
15 | 385 * @return the <code>String</code> representing a Locale object |
386 * @since 3.0 | |
387 */ | |
388 public char[] getLocale () { | |
389 StringBuffer buffer = new StringBuffer (); | |
390 char sep = '_'; | |
391 if (lang !is null) { | |
392 buffer.append (lang); | |
393 buffer.append (sep); | |
394 } | |
395 if (country !is null) { | |
396 buffer.append (country); | |
397 buffer.append (sep); | |
398 } | |
399 if (variant !is null) { | |
400 buffer.append (variant); | |
401 } | |
23 | 402 |
15 | 403 char[] result = buffer.toString (); |
404 int length_ = result.length; | |
405 if (length_ > 0) { | |
406 if (result.charAt (length_ - 1) is sep) { | |
407 result = result.substring (0, length_ - 1); | |
408 } | |
23 | 409 } |
15 | 410 return result; |
411 } | |
412 | |
413 /** | |
414 * Returns the name of the receiver. | |
415 * On platforms that support font foundries, the return value will | |
416 * be the foundry followed by a dash ("-") followed by the face name. | |
417 * | |
418 * @return the name of this <code>FontData</code> | |
419 * | |
420 * @see #setName | |
421 */ | |
422 public char[] getName() { | |
423 return .TCHARzToStr( data.lfFaceName.ptr, -1 ); | |
424 } | |
425 | |
426 /** | |
23 | 427 * Returns the style of the receiver which is a bitwise OR of |
15 | 428 * one or more of the <code>DWT</code> constants NORMAL, BOLD |
429 * and ITALIC. | |
430 * | |
431 * @return the style of this <code>FontData</code> | |
23 | 432 * |
15 | 433 * @see #setStyle |
434 */ | |
435 public int getStyle() { | |
436 int style = DWT.NORMAL; | |
437 if (data.lfWeight is 700) style |= DWT.BOLD; | |
438 if (data.lfItalic !is 0) style |= DWT.ITALIC; | |
439 return style; | |
440 } | |
441 | |
442 /** | |
23 | 443 * Returns an integer hash code for the receiver. Any two |
444 * objects that return <code>true</code> when passed to | |
15 | 445 * <code>equals</code> must return the same value for this |
446 * method. | |
447 * | |
448 * @return the receiver's hash | |
449 * | |
450 * @see #equals | |
451 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
452 override public hash_t toHash () { |
15 | 453 char[] name = getName(); |
454 return data.lfCharSet ^ getHeight() ^ data.lfWidth ^ data.lfEscapement ^ | |
455 data.lfOrientation ^ data.lfWeight ^ data.lfItalic ^data.lfUnderline ^ | |
456 data.lfStrikeOut ^ data.lfCharSet ^ data.lfOutPrecision ^ | |
457 data.lfClipPrecision ^ data.lfQuality ^ data.lfPitchAndFamily ^ | |
458 typeid(char[]).getHash(&name); | |
459 } | |
460 | |
461 /** | |
462 * Sets the height of the receiver. The parameter is | |
463 * specified in terms of points, where a point is one | |
464 * seventy-second of an inch. | |
465 * | |
466 * @param height the height of the <code>FontData</code> | |
467 * | |
468 * @exception IllegalArgumentException <ul> | |
469 * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> | |
470 * </ul> | |
23 | 471 * |
15 | 472 * @see #getHeight |
473 */ | |
474 public void setHeight(int height) { | |
475 if (height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
476 this.height = height; | |
477 } | |
478 | |
479 /*public*/ void setHeight(float height) { | |
480 if (height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
481 this.height = height; | |
482 } | |
483 | |
484 /** | |
485 * Sets the locale of the receiver. | |
486 * <p> | |
487 * The locale determines which platform character set this | |
488 * font is going to use. Widgets and graphics operations that | |
489 * use this font will convert UNICODE strings to the platform | |
490 * character set of the specified locale. | |
491 * </p> | |
492 * <p> | |
493 * On platforms where there are multiple character sets for a | |
494 * given language/country locale, the variant portion of the | |
495 * locale will determine the character set. | |
496 * </p> | |
23 | 497 * |
15 | 498 * @param locale the <code>String</code> representing a Locale object |
499 * @see java.util.Locale#toString | |
500 */ | |
23 | 501 public void setLocale(char[] locale) { |
15 | 502 lang = country = variant = null; |
503 if (locale !is null) { | |
504 char sep = '_'; | |
505 int length_ = locale.length; | |
506 int firstSep, secondSep; | |
23 | 507 |
15 | 508 firstSep = locale.indexOf(sep); |
509 if (firstSep is -1) { | |
510 firstSep = secondSep = length_; | |
511 } else { | |
512 secondSep = locale.indexOf(sep, firstSep + 1); | |
513 if (secondSep is -1) secondSep = length_; | |
514 } | |
515 if (firstSep > 0) lang = locale.substring(0, firstSep); | |
516 if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep); | |
517 if (length_ > secondSep + 1) variant = locale.substring(secondSep + 1); | |
518 } | |
519 if (lang is null) { | |
520 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; | |
521 } else { | |
522 synchronized(this.classinfo){ | |
523 s_this = this; | |
524 OS.EnumSystemLocales(&EnumLocalesProc, OS.LCID_SUPPORTED); | |
525 s_this = null; | |
526 } | |
527 } | |
528 } | |
529 | |
530 /** | |
531 * Sets the name of the receiver. | |
532 * <p> | |
533 * Some platforms support font foundries. On these platforms, the name | |
534 * of the font specified in setName() may have one of the following forms: | |
535 * <ol> | |
536 * <li>a face name (for example, "courier")</li> | |
537 * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li> | |
538 * </ol> | |
539 * In either case, the name returned from getName() will include the | |
540 * foundry. | |
541 * </p> | |
542 * <p> | |
543 * On platforms that do not support font foundries, only the face name | |
23 | 544 * (for example, "courier") is used in <code>setName()</code> and |
15 | 545 * <code>getName()</code>. |
546 * </p> | |
547 * | |
548 * @param name the name of the font data (must not be null) | |
549 * @exception IllegalArgumentException <ul> | |
550 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> | |
551 * </ul> | |
552 * | |
553 * @see #getName | |
554 */ | |
555 public void setName(char[] name) { | |
556 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
557 | |
558 /* The field lfFaceName must be NULL terminated */ | |
559 int len = Math.min(OS.LF_FACESIZE - 1, name.length); | |
560 | |
561 data.lfFaceName[0 .. len] = .StrToTCHARs(name)[0 .. len]; | |
562 data.lfFaceName[len] = 0; | |
563 } | |
564 | |
565 /** | |
566 * Sets the style of the receiver to the argument which must | |
23 | 567 * be a bitwise OR of one or more of the <code>DWT</code> |
15 | 568 * constants NORMAL, BOLD and ITALIC. All other style bits are |
569 * ignored. | |
570 * | |
571 * @param style the new style for this <code>FontData</code> | |
572 * | |
573 * @see #getStyle | |
574 */ | |
575 public void setStyle(int style) { | |
576 if ((style & DWT.BOLD) is DWT.BOLD) { | |
577 data.lfWeight = 700; | |
578 } else { | |
579 data.lfWeight = 0; | |
580 } | |
581 if ((style & DWT.ITALIC) is DWT.ITALIC) { | |
582 data.lfItalic = 1; | |
583 } else { | |
584 data.lfItalic = 0; | |
585 } | |
586 } | |
587 | |
588 /** | |
589 * Returns a string representation of the receiver which is suitable | |
23 | 590 * for constructing an equivalent instance using the |
15 | 591 * <code>FontData(String)</code> constructor. |
592 * | |
593 * @return a string representation of the FontData | |
594 * | |
595 * @see FontData | |
596 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
597 override public char[] toString() { |
15 | 598 StringBuffer buffer = new StringBuffer(); |
599 buffer.append("1|"); //$NON-NLS-1$ | |
600 buffer.append(getName()); | |
601 buffer.append("|"); //$NON-NLS-1$ | |
602 buffer.append(to!(char[])(getHeightF())); | |
603 buffer.append("|"); //$NON-NLS-1$ | |
604 buffer.append(to!(char[])(getStyle())); | |
605 buffer.append("|"); //$NON-NLS-1$ | |
23 | 606 buffer.append("WINDOWS|1|"); //$NON-NLS-1$ |
15 | 607 buffer.append(to!(char[])(data.lfHeight)); |
608 buffer.append("|"); //$NON-NLS-1$ | |
609 buffer.append(to!(char[])(data.lfWidth)); | |
610 buffer.append("|"); //$NON-NLS-1$ | |
611 buffer.append(to!(char[])(data.lfEscapement)); | |
612 buffer.append("|"); //$NON-NLS-1$ | |
23 | 613 buffer.append(to!(char[])(data.lfOrientation)); |
15 | 614 buffer.append("|"); //$NON-NLS-1$ |
23 | 615 buffer.append(to!(char[])(data.lfWeight)); |
15 | 616 buffer.append("|"); //$NON-NLS-1$ |
617 buffer.append(to!(char[])(data.lfItalic)); | |
618 buffer.append("|"); //$NON-NLS-1$ | |
619 buffer.append(to!(char[])(data.lfUnderline)); | |
620 buffer.append("|"); //$NON-NLS-1$ | |
23 | 621 buffer.append(to!(char[])(data.lfStrikeOut)); |
15 | 622 buffer.append("|"); //$NON-NLS-1$ |
23 | 623 buffer.append(to!(char[])(data.lfCharSet)); |
15 | 624 buffer.append("|"); //$NON-NLS-1$ |
625 buffer.append(to!(char[])(data.lfOutPrecision)); | |
626 buffer.append("|"); //$NON-NLS-1$ | |
23 | 627 buffer.append(to!(char[])(data.lfClipPrecision)); |
15 | 628 buffer.append("|"); //$NON-NLS-1$ |
23 | 629 buffer.append(to!(char[])(data.lfQuality)); |
15 | 630 buffer.append("|"); //$NON-NLS-1$ |
631 buffer.append(to!(char[])(data.lfPitchAndFamily)); | |
632 buffer.append("|"); //$NON-NLS-1$ | |
633 buffer.append(getName()); | |
634 return buffer.toString(); | |
635 } | |
636 | |
23 | 637 /** |
15 | 638 * Invokes platform specific functionality to allocate a new font data. |
639 * <p> | |
640 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
641 * API for <code>FontData</code>. It is marked public only so that | |
642 * it can be shared within the packages provided by DWT. It is not | |
643 * available on all platforms, and should never be called from | |
644 * application code. | |
645 * </p> | |
646 * | |
647 * @param data the <code>LOGFONT</code> for the font data | |
648 * @param height the height of the font data | |
649 * @return a new font data object containing the specified <code>LOGFONT</code> and height | |
650 */ | |
651 public static FontData win32_new(LOGFONT* data, float height) { | |
652 return new FontData(data, height); | |
653 } | |
654 | |
655 } |