Mercurial > projects > dwt-win
comparison dwt/graphics/FontData.d @ 212:ab60f3309436
reverted the char[] to String and use the an alias.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:12:38 +0200 |
parents | 108ba7ff5a0b |
children | fd9c62a2998e |
comparison
equal
deleted
inserted
replaced
211:ff59aeb96cac | 212:ab60f3309436 |
---|---|
73 public float height; | 73 public float height; |
74 | 74 |
75 /** | 75 /** |
76 * The locales of the font | 76 * The locales of the font |
77 */ | 77 */ |
78 char[] lang, country, variant; | 78 String lang, country, variant; |
79 | 79 |
80 private static FontData s_this; | 80 private static FontData s_this; |
81 | 81 |
82 /** | 82 /** |
83 * Constructs a new uninitialized font data. | 83 * Constructs a new uninitialized font data. |
118 * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li> | 118 * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li> |
119 * </ul> | 119 * </ul> |
120 * | 120 * |
121 * @see #toString | 121 * @see #toString |
122 */ | 122 */ |
123 public this(char[] string) { | 123 public this(String string) { |
124 if (string is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 124 if (string is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
125 int start = 0; | 125 int start = 0; |
126 int end = string.indexOf('|'); | 126 int end = string.indexOf('|'); |
127 if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 127 if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
128 char[] version1 = string.substring(start, end); | 128 String version1 = string.substring(start, end); |
129 try { | 129 try { |
130 if (Integer.parseInt(version1) !is 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 130 if (Integer.parseInt(version1) !is 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
131 } catch (NumberFormatException e) { | 131 } catch (NumberFormatException e) { |
132 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 132 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
133 } | 133 } |
134 | 134 |
135 start = end + 1; | 135 start = end + 1; |
136 end = string.indexOf('|', start); | 136 end = string.indexOf('|', start); |
137 if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 137 if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
138 char[] name = string.substring(start, end); | 138 String name = string.substring(start, end); |
139 | 139 |
140 start = end + 1; | 140 start = end + 1; |
141 end = string.indexOf('|', start); | 141 end = string.indexOf('|', start); |
142 if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 142 if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
143 float height = 0; | 143 float height = 0; |
163 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; | 163 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; |
164 setName(name); | 164 setName(name); |
165 setHeight(height); | 165 setHeight(height); |
166 setStyle(style); | 166 setStyle(style); |
167 if (end is -1) return; | 167 if (end is -1) return; |
168 char[] platform = string.substring(start, end); | 168 String platform = string.substring(start, end); |
169 | 169 |
170 start = end + 1; | 170 start = end + 1; |
171 end = string.indexOf('|', start); | 171 end = string.indexOf('|', start); |
172 if (end is -1) return; | 172 if (end is -1) return; |
173 char[] version2 = string.substring(start, end); | 173 String version2 = string.substring(start, end); |
174 | 174 |
175 if (platform ==/*eq*/ "WINDOWS" && version2 ==/*eq*/ "1") { //$NON-NLS-1$//$NON-NLS-2$ | 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(); | 176 LOGFONT newData;// = OS.IsUnicode ? cast(LOGFONT)new LOGFONTW() : new LOGFONTA(); |
177 try { | 177 try { |
178 start = end + 1; | 178 start = end + 1; |
232 setName(name); | 232 setName(name); |
233 setHeight(height); | 233 setHeight(height); |
234 setStyle(style); | 234 setStyle(style); |
235 return; | 235 return; |
236 } | 236 } |
237 char[] buffer = string.substring(start); | 237 String buffer = string.substring(start); |
238 auto wname = StrToTCHARs(buffer); | 238 auto wname = StrToTCHARs(buffer); |
239 int len = Math.min(OS.LF_FACESIZE - 1, wname.length); | 239 int len = Math.min(OS.LF_FACESIZE - 1, wname.length); |
240 newData.lfFaceName[ 0 .. len ] = wname[ 0 .. len ]; | 240 newData.lfFaceName[ 0 .. len ] = wname[ 0 .. len ]; |
241 newData.lfFaceName[ len .. $ ] = 0; | 241 newData.lfFaceName[ len .. $ ] = 0; |
242 data = newData; | 242 data = newData; |
255 * @exception IllegalArgumentException <ul> | 255 * @exception IllegalArgumentException <ul> |
256 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> | 256 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> |
257 * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> | 257 * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> |
258 * </ul> | 258 * </ul> |
259 */ | 259 */ |
260 public this(char[] name, int height, int style) { | 260 public this(String name, int height, int style) { |
261 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 261 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
262 setName(name); | 262 setName(name); |
263 setHeight(height); | 263 setHeight(height); |
264 setStyle(style); | 264 setStyle(style); |
265 // We set the charset field so that | 265 // We set the charset field so that |
266 // wildcard searching will work properly | 266 // wildcard searching will work properly |
267 // out of the box | 267 // out of the box |
268 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; | 268 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; |
269 } | 269 } |
270 | 270 |
271 /*public*/ this(char[] name, float height, int style) { | 271 /*public*/ this(String name, float height, int style) { |
272 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 272 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
273 setName(name); | 273 setName(name); |
274 setHeight(height); | 274 setHeight(height); |
275 setStyle(style); | 275 setStyle(style); |
276 // We set the charset field so that | 276 // We set the charset field so that |
320 | 320 |
321 extern (Windows) static int EnumLocalesProc(TCHAR* lpLocaleString) { | 321 extern (Windows) static int EnumLocalesProc(TCHAR* lpLocaleString) { |
322 | 322 |
323 /* Get the locale ID */ | 323 /* Get the locale ID */ |
324 int length_ = 8; | 324 int length_ = 8; |
325 char[] str = .TCHARzToStr( cast(TCHAR*)lpLocaleString, length_); | 325 String str = .TCHARzToStr( cast(TCHAR*)lpLocaleString, length_); |
326 int lcid = Integer.parseInt(str, 16); | 326 int lcid = Integer.parseInt(str, 16); |
327 | 327 |
328 TCHAR[] buffer = new TCHAR[length_]; | 328 TCHAR[] buffer = new TCHAR[length_]; |
329 | 329 |
330 /* Check the language */ | 330 /* Check the language */ |
378 * </p> | 378 * </p> |
379 * | 379 * |
380 * @return the <code>String</code> representing a Locale object | 380 * @return the <code>String</code> representing a Locale object |
381 * @since 3.0 | 381 * @since 3.0 |
382 */ | 382 */ |
383 public char[] getLocale () { | 383 public String getLocale () { |
384 StringBuffer buffer = new StringBuffer (); | 384 StringBuffer buffer = new StringBuffer (); |
385 char sep = '_'; | 385 char sep = '_'; |
386 if (lang !is null) { | 386 if (lang !is null) { |
387 buffer.append (lang); | 387 buffer.append (lang); |
388 buffer.append (sep); | 388 buffer.append (sep); |
393 } | 393 } |
394 if (variant !is null) { | 394 if (variant !is null) { |
395 buffer.append (variant); | 395 buffer.append (variant); |
396 } | 396 } |
397 | 397 |
398 char[] result = buffer.toString (); | 398 String result = buffer.toString (); |
399 int length_ = result.length; | 399 int length_ = result.length; |
400 if (length_ > 0) { | 400 if (length_ > 0) { |
401 if (result.charAt (length_ - 1) is sep) { | 401 if (result.charAt (length_ - 1) is sep) { |
402 result = result.substring (0, length_ - 1); | 402 result = result.substring (0, length_ - 1); |
403 } | 403 } |
412 * | 412 * |
413 * @return the name of this <code>FontData</code> | 413 * @return the name of this <code>FontData</code> |
414 * | 414 * |
415 * @see #setName | 415 * @see #setName |
416 */ | 416 */ |
417 public char[] getName() { | 417 public String getName() { |
418 return .TCHARzToStr( data.lfFaceName.ptr, -1 ); | 418 return .TCHARzToStr( data.lfFaceName.ptr, -1 ); |
419 } | 419 } |
420 | 420 |
421 /** | 421 /** |
422 * Returns the style of the receiver which is a bitwise OR of | 422 * Returns the style of the receiver which is a bitwise OR of |
443 * @return the receiver's hash | 443 * @return the receiver's hash |
444 * | 444 * |
445 * @see #equals | 445 * @see #equals |
446 */ | 446 */ |
447 override public hash_t toHash () { | 447 override public hash_t toHash () { |
448 char[] name = getName(); | 448 String name = getName(); |
449 return data.lfCharSet ^ getHeight() ^ data.lfWidth ^ data.lfEscapement ^ | 449 return data.lfCharSet ^ getHeight() ^ data.lfWidth ^ data.lfEscapement ^ |
450 data.lfOrientation ^ data.lfWeight ^ data.lfItalic ^data.lfUnderline ^ | 450 data.lfOrientation ^ data.lfWeight ^ data.lfItalic ^data.lfUnderline ^ |
451 data.lfStrikeOut ^ data.lfCharSet ^ data.lfOutPrecision ^ | 451 data.lfStrikeOut ^ data.lfCharSet ^ data.lfOutPrecision ^ |
452 data.lfClipPrecision ^ data.lfQuality ^ data.lfPitchAndFamily ^ | 452 data.lfClipPrecision ^ data.lfQuality ^ data.lfPitchAndFamily ^ |
453 typeid(char[]).getHash(&name); | 453 typeid(String).getHash(&name); |
454 } | 454 } |
455 | 455 |
456 /** | 456 /** |
457 * Sets the height of the receiver. The parameter is | 457 * Sets the height of the receiver. The parameter is |
458 * specified in terms of points, where a point is one | 458 * specified in terms of points, where a point is one |
491 * </p> | 491 * </p> |
492 * | 492 * |
493 * @param locale the <code>String</code> representing a Locale object | 493 * @param locale the <code>String</code> representing a Locale object |
494 * @see java.util.Locale#toString | 494 * @see java.util.Locale#toString |
495 */ | 495 */ |
496 public void setLocale(char[] locale) { | 496 public void setLocale(String locale) { |
497 lang = country = variant = null; | 497 lang = country = variant = null; |
498 if (locale !is null) { | 498 if (locale !is null) { |
499 char sep = '_'; | 499 char sep = '_'; |
500 int length_ = locale.length; | 500 int length_ = locale.length; |
501 int firstSep, secondSep; | 501 int firstSep, secondSep; |
545 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> | 545 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> |
546 * </ul> | 546 * </ul> |
547 * | 547 * |
548 * @see #getName | 548 * @see #getName |
549 */ | 549 */ |
550 public void setName(char[] name) { | 550 public void setName(String name) { |
551 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 551 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
552 | 552 |
553 /* The field lfFaceName must be NULL terminated */ | 553 /* The field lfFaceName must be NULL terminated */ |
554 auto wname = StrToTCHARs(name); | 554 auto wname = StrToTCHARs(name); |
555 int len = Math.min(OS.LF_FACESIZE - 1, wname.length); | 555 int len = Math.min(OS.LF_FACESIZE - 1, wname.length); |
587 * | 587 * |
588 * @return a string representation of the FontData | 588 * @return a string representation of the FontData |
589 * | 589 * |
590 * @see FontData | 590 * @see FontData |
591 */ | 591 */ |
592 override public char[] toString() { | 592 override public String toString() { |
593 StringBuffer buffer = new StringBuffer(); | 593 StringBuffer buffer = new StringBuffer(); |
594 buffer.append("1|"); //$NON-NLS-1$ | 594 buffer.append("1|"); //$NON-NLS-1$ |
595 buffer.append(getName()); | 595 buffer.append(getName()); |
596 buffer.append("|"); //$NON-NLS-1$ | 596 buffer.append("|"); //$NON-NLS-1$ |
597 buffer.append(to!(char[])(getHeightF())); | 597 buffer.append(to!(String)(getHeightF())); |
598 buffer.append("|"); //$NON-NLS-1$ | 598 buffer.append("|"); //$NON-NLS-1$ |
599 buffer.append(to!(char[])(getStyle())); | 599 buffer.append(to!(String)(getStyle())); |
600 buffer.append("|"); //$NON-NLS-1$ | 600 buffer.append("|"); //$NON-NLS-1$ |
601 buffer.append("WINDOWS|1|"); //$NON-NLS-1$ | 601 buffer.append("WINDOWS|1|"); //$NON-NLS-1$ |
602 buffer.append(to!(char[])(data.lfHeight)); | 602 buffer.append(to!(String)(data.lfHeight)); |
603 buffer.append("|"); //$NON-NLS-1$ | 603 buffer.append("|"); //$NON-NLS-1$ |
604 buffer.append(to!(char[])(data.lfWidth)); | 604 buffer.append(to!(String)(data.lfWidth)); |
605 buffer.append("|"); //$NON-NLS-1$ | 605 buffer.append("|"); //$NON-NLS-1$ |
606 buffer.append(to!(char[])(data.lfEscapement)); | 606 buffer.append(to!(String)(data.lfEscapement)); |
607 buffer.append("|"); //$NON-NLS-1$ | 607 buffer.append("|"); //$NON-NLS-1$ |
608 buffer.append(to!(char[])(data.lfOrientation)); | 608 buffer.append(to!(String)(data.lfOrientation)); |
609 buffer.append("|"); //$NON-NLS-1$ | 609 buffer.append("|"); //$NON-NLS-1$ |
610 buffer.append(to!(char[])(data.lfWeight)); | 610 buffer.append(to!(String)(data.lfWeight)); |
611 buffer.append("|"); //$NON-NLS-1$ | 611 buffer.append("|"); //$NON-NLS-1$ |
612 buffer.append(to!(char[])(data.lfItalic)); | 612 buffer.append(to!(String)(data.lfItalic)); |
613 buffer.append("|"); //$NON-NLS-1$ | 613 buffer.append("|"); //$NON-NLS-1$ |
614 buffer.append(to!(char[])(data.lfUnderline)); | 614 buffer.append(to!(String)(data.lfUnderline)); |
615 buffer.append("|"); //$NON-NLS-1$ | 615 buffer.append("|"); //$NON-NLS-1$ |
616 buffer.append(to!(char[])(data.lfStrikeOut)); | 616 buffer.append(to!(String)(data.lfStrikeOut)); |
617 buffer.append("|"); //$NON-NLS-1$ | 617 buffer.append("|"); //$NON-NLS-1$ |
618 buffer.append(to!(char[])(data.lfCharSet)); | 618 buffer.append(to!(String)(data.lfCharSet)); |
619 buffer.append("|"); //$NON-NLS-1$ | 619 buffer.append("|"); //$NON-NLS-1$ |
620 buffer.append(to!(char[])(data.lfOutPrecision)); | 620 buffer.append(to!(String)(data.lfOutPrecision)); |
621 buffer.append("|"); //$NON-NLS-1$ | 621 buffer.append("|"); //$NON-NLS-1$ |
622 buffer.append(to!(char[])(data.lfClipPrecision)); | 622 buffer.append(to!(String)(data.lfClipPrecision)); |
623 buffer.append("|"); //$NON-NLS-1$ | 623 buffer.append("|"); //$NON-NLS-1$ |
624 buffer.append(to!(char[])(data.lfQuality)); | 624 buffer.append(to!(String)(data.lfQuality)); |
625 buffer.append("|"); //$NON-NLS-1$ | 625 buffer.append("|"); //$NON-NLS-1$ |
626 buffer.append(to!(char[])(data.lfPitchAndFamily)); | 626 buffer.append(to!(String)(data.lfPitchAndFamily)); |
627 buffer.append("|"); //$NON-NLS-1$ | 627 buffer.append("|"); //$NON-NLS-1$ |
628 buffer.append(getName()); | 628 buffer.append(getName()); |
629 return buffer.toString(); | 629 return buffer.toString(); |
630 } | 630 } |
631 | 631 |