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