Mercurial > projects > dwt-win
annotate 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 |
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 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
78 String lang, country, variant; |
15 | 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 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
123 public this(String string) { |
15 | 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); | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
128 String version1 = string.substring(start, end); |
15 | 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); | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
138 String 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; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
168 String platform = string.substring(start, end); |
15 | 169 |
170 start = end + 1; | |
171 end = string.indexOf('|', start); | |
172 if (end is -1) return; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
173 String version2 = string.substring(start, end); |
15 | 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 } | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
237 String buffer = string.substring(start); |
204
108ba7ff5a0b
Fix null termination in FonData(char[])
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
238 auto wname = StrToTCHARs(buffer); |
108ba7ff5a0b
Fix null termination in FonData(char[])
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
239 int len = Math.min(OS.LF_FACESIZE - 1, wname.length); |
108ba7ff5a0b
Fix null termination in FonData(char[])
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
240 newData.lfFaceName[ 0 .. len ] = wname[ 0 .. len ]; |
108ba7ff5a0b
Fix null termination in FonData(char[])
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
241 newData.lfFaceName[ len .. $ ] = 0; |
15 | 242 data = newData; |
243 } | |
244 } | |
245 | |
23 | 246 /** |
15 | 247 * Constructs a new font data given a font name, |
23 | 248 * the height of the desired font in points, |
15 | 249 * and a font style. |
250 * | |
251 * @param name the name of the font (must not be null) | |
252 * @param height the font height in points | |
253 * @param style a bit or combination of NORMAL, BOLD, ITALIC | |
254 * | |
255 * @exception IllegalArgumentException <ul> | |
256 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> | |
257 * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> | |
258 * </ul> | |
259 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
260 public this(String name, int height, int style) { |
15 | 261 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
262 setName(name); | |
263 setHeight(height); | |
264 setStyle(style); | |
265 // We set the charset field so that | |
266 // wildcard searching will work properly | |
267 // out of the box | |
268 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; | |
269 } | |
270 | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
271 /*public*/ this(String name, float height, int style) { |
15 | 272 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
273 setName(name); | |
274 setHeight(height); | |
275 setStyle(style); | |
276 // We set the charset field so that | |
277 // wildcard searching will work properly | |
278 // out of the box | |
279 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; | |
280 } | |
281 | |
282 /** | |
283 * Compares the argument to the receiver, and returns true | |
284 * if they represent the <em>same</em> object using a class | |
285 * specific comparison. | |
286 * | |
287 * @param object the object to compare with this object | |
288 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
289 * | |
290 * @see #hashCode | |
291 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
292 override public int opEquals (Object object) { |
15 | 293 if (object is this) return true; |
294 if( auto fd = cast(FontData)object ){ | |
17 | 295 LOGFONT* lf = &fd.data; |
15 | 296 return data.lfCharSet is lf.lfCharSet && |
297 /* | |
298 * This code is intentionally commented. When creating | |
299 * a FontData, lfHeight is not necessarily set. Instead | |
300 * we check the height field which is always set. | |
23 | 301 */ |
15 | 302 // data.lfHeight is lf.lfHeight && |
303 height is fd.height && | |
304 data.lfWidth is lf.lfWidth && | |
305 data.lfEscapement is lf.lfEscapement && | |
306 data.lfOrientation is lf.lfOrientation && | |
307 data.lfWeight is lf.lfWeight && | |
308 data.lfItalic is lf.lfItalic && | |
309 data.lfUnderline is lf.lfUnderline && | |
310 data.lfStrikeOut is lf.lfStrikeOut && | |
311 data.lfCharSet is lf.lfCharSet && | |
312 data.lfOutPrecision is lf.lfOutPrecision && | |
313 data.lfClipPrecision is lf.lfClipPrecision && | |
314 data.lfQuality is lf.lfQuality && | |
315 data.lfPitchAndFamily is lf.lfPitchAndFamily && | |
316 getName() ==/*eq*/ fd.getName(); | |
317 } | |
318 return false; | |
319 } | |
320 | |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
321 extern (Windows) static int EnumLocalesProc(TCHAR* lpLocaleString) { |
15 | 322 |
323 /* Get the locale ID */ | |
324 int length_ = 8; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
325 String str = .TCHARzToStr( cast(TCHAR*)lpLocaleString, length_); |
15 | 326 int lcid = Integer.parseInt(str, 16); |
327 | |
328 TCHAR[] buffer = new TCHAR[length_]; | |
329 | |
330 /* Check the language */ | |
331 int size = OS.GetLocaleInfo(lcid, OS.LOCALE_SISO639LANGNAME, buffer.ptr, length_); | |
332 if (size <= 0 || s_this.lang !=/*eq*/ .TCHARzToStr( buffer.ptr ).substring(0, size - 1)) return 1; | |
333 | |
334 /* Check the country */ | |
335 if (s_this.country !is null) { | |
336 size = OS.GetLocaleInfo(lcid, OS.LOCALE_SISO3166CTRYNAME, buffer.ptr, length_); | |
337 if (size <= 0 || s_this.country !=/*eq*/ .TCHARzToStr( buffer.ptr ).substring(0, size - 1)) return 1; | |
338 } | |
339 | |
340 /* Get the charset */ | |
341 size = OS.GetLocaleInfo(lcid, OS.LOCALE_IDEFAULTANSICODEPAGE, buffer.ptr, length_); | |
342 if (size <= 0) return 1; | |
343 int cp = Integer.parseInt(.TCHARzToStr(buffer.ptr).substring(0, size - 1)); | |
344 CHARSETINFO lpCs; | |
345 OS.TranslateCharsetInfo(cast(DWORD*)cp, &lpCs, OS.TCI_SRCCODEPAGE); | |
346 s_this.data.lfCharSet = cast(BYTE)lpCs.ciCharset; | |
347 | |
348 return 0; | |
349 } | |
350 | |
351 /** | |
352 * Returns the height of the receiver in points. | |
353 * | |
354 * @return the height of this FontData | |
355 * | |
356 * @see #setHeight(int) | |
357 */ | |
358 public int getHeight() { | |
359 return cast(int)(0.5f + height); | |
360 } | |
361 | |
362 /*public*/ float getHeightF() { | |
363 return height; | |
364 } | |
365 | |
366 /** | |
367 * Returns the locale of the receiver. | |
368 * <p> | |
369 * The locale determines which platform character set this | |
370 * font is going to use. Widgets and graphics operations that | |
371 * use this font will convert UNICODE strings to the platform | |
372 * character set of the specified locale. | |
373 * </p> | |
374 * <p> | |
375 * On platforms where there are multiple character sets for a | |
376 * given language/country locale, the variant portion of the | |
377 * locale will determine the character set. | |
378 * </p> | |
23 | 379 * |
15 | 380 * @return the <code>String</code> representing a Locale object |
381 * @since 3.0 | |
382 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
383 public String getLocale () { |
15 | 384 StringBuffer buffer = new StringBuffer (); |
385 char sep = '_'; | |
386 if (lang !is null) { | |
387 buffer.append (lang); | |
388 buffer.append (sep); | |
389 } | |
390 if (country !is null) { | |
391 buffer.append (country); | |
392 buffer.append (sep); | |
393 } | |
394 if (variant !is null) { | |
395 buffer.append (variant); | |
396 } | |
23 | 397 |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
398 String result = buffer.toString (); |
15 | 399 int length_ = result.length; |
400 if (length_ > 0) { | |
401 if (result.charAt (length_ - 1) is sep) { | |
402 result = result.substring (0, length_ - 1); | |
403 } | |
23 | 404 } |
15 | 405 return result; |
406 } | |
407 | |
408 /** | |
409 * Returns the name of the receiver. | |
410 * On platforms that support font foundries, the return value will | |
411 * be the foundry followed by a dash ("-") followed by the face name. | |
412 * | |
413 * @return the name of this <code>FontData</code> | |
414 * | |
415 * @see #setName | |
416 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
417 public String getName() { |
15 | 418 return .TCHARzToStr( data.lfFaceName.ptr, -1 ); |
419 } | |
420 | |
421 /** | |
23 | 422 * Returns the style of the receiver which is a bitwise OR of |
15 | 423 * one or more of the <code>DWT</code> constants NORMAL, BOLD |
424 * and ITALIC. | |
425 * | |
426 * @return the style of this <code>FontData</code> | |
23 | 427 * |
15 | 428 * @see #setStyle |
429 */ | |
430 public int getStyle() { | |
431 int style = DWT.NORMAL; | |
432 if (data.lfWeight is 700) style |= DWT.BOLD; | |
433 if (data.lfItalic !is 0) style |= DWT.ITALIC; | |
434 return style; | |
435 } | |
436 | |
437 /** | |
23 | 438 * Returns an integer hash code for the receiver. Any two |
439 * objects that return <code>true</code> when passed to | |
15 | 440 * <code>equals</code> must return the same value for this |
441 * method. | |
442 * | |
443 * @return the receiver's hash | |
444 * | |
445 * @see #equals | |
446 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
447 override public hash_t toHash () { |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
448 String name = getName(); |
15 | 449 return data.lfCharSet ^ getHeight() ^ data.lfWidth ^ data.lfEscapement ^ |
450 data.lfOrientation ^ data.lfWeight ^ data.lfItalic ^data.lfUnderline ^ | |
451 data.lfStrikeOut ^ data.lfCharSet ^ data.lfOutPrecision ^ | |
452 data.lfClipPrecision ^ data.lfQuality ^ data.lfPitchAndFamily ^ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
453 typeid(String).getHash(&name); |
15 | 454 } |
455 | |
456 /** | |
457 * Sets the height of the receiver. The parameter is | |
458 * specified in terms of points, where a point is one | |
459 * seventy-second of an inch. | |
460 * | |
461 * @param height the height of the <code>FontData</code> | |
462 * | |
463 * @exception IllegalArgumentException <ul> | |
464 * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> | |
465 * </ul> | |
23 | 466 * |
15 | 467 * @see #getHeight |
468 */ | |
469 public void setHeight(int height) { | |
470 if (height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
471 this.height = height; | |
472 } | |
473 | |
474 /*public*/ void setHeight(float height) { | |
475 if (height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
476 this.height = height; | |
477 } | |
478 | |
479 /** | |
480 * Sets the locale of the receiver. | |
481 * <p> | |
482 * The locale determines which platform character set this | |
483 * font is going to use. Widgets and graphics operations that | |
484 * use this font will convert UNICODE strings to the platform | |
485 * character set of the specified locale. | |
486 * </p> | |
487 * <p> | |
488 * On platforms where there are multiple character sets for a | |
489 * given language/country locale, the variant portion of the | |
490 * locale will determine the character set. | |
491 * </p> | |
23 | 492 * |
15 | 493 * @param locale the <code>String</code> representing a Locale object |
494 * @see java.util.Locale#toString | |
495 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
496 public void setLocale(String locale) { |
15 | 497 lang = country = variant = null; |
498 if (locale !is null) { | |
499 char sep = '_'; | |
500 int length_ = locale.length; | |
501 int firstSep, secondSep; | |
23 | 502 |
15 | 503 firstSep = locale.indexOf(sep); |
504 if (firstSep is -1) { | |
505 firstSep = secondSep = length_; | |
506 } else { | |
507 secondSep = locale.indexOf(sep, firstSep + 1); | |
508 if (secondSep is -1) secondSep = length_; | |
509 } | |
510 if (firstSep > 0) lang = locale.substring(0, firstSep); | |
511 if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep); | |
512 if (length_ > secondSep + 1) variant = locale.substring(secondSep + 1); | |
513 } | |
514 if (lang is null) { | |
515 data.lfCharSet = cast(byte)OS.DEFAULT_CHARSET; | |
516 } else { | |
517 synchronized(this.classinfo){ | |
518 s_this = this; | |
519 OS.EnumSystemLocales(&EnumLocalesProc, OS.LCID_SUPPORTED); | |
520 s_this = null; | |
521 } | |
522 } | |
523 } | |
524 | |
525 /** | |
526 * Sets the name of the receiver. | |
527 * <p> | |
528 * Some platforms support font foundries. On these platforms, the name | |
529 * of the font specified in setName() may have one of the following forms: | |
530 * <ol> | |
531 * <li>a face name (for example, "courier")</li> | |
532 * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li> | |
533 * </ol> | |
534 * In either case, the name returned from getName() will include the | |
535 * foundry. | |
536 * </p> | |
537 * <p> | |
538 * On platforms that do not support font foundries, only the face name | |
23 | 539 * (for example, "courier") is used in <code>setName()</code> and |
15 | 540 * <code>getName()</code>. |
541 * </p> | |
542 * | |
543 * @param name the name of the font data (must not be null) | |
544 * @exception IllegalArgumentException <ul> | |
545 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> | |
546 * </ul> | |
547 * | |
548 * @see #getName | |
549 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
550 public void setName(String name) { |
15 | 551 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
552 | |
553 /* The field lfFaceName must be NULL terminated */ | |
204
108ba7ff5a0b
Fix null termination in FonData(char[])
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
554 auto wname = StrToTCHARs(name); |
108ba7ff5a0b
Fix null termination in FonData(char[])
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
555 int len = Math.min(OS.LF_FACESIZE - 1, wname.length); |
108ba7ff5a0b
Fix null termination in FonData(char[])
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
556 data.lfFaceName[0 .. len] = wname[ 0 .. len ]; |
108ba7ff5a0b
Fix null termination in FonData(char[])
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
557 data.lfFaceName[len .. $] = 0; |
15 | 558 } |
559 | |
560 /** | |
561 * Sets the style of the receiver to the argument which must | |
23 | 562 * be a bitwise OR of one or more of the <code>DWT</code> |
15 | 563 * constants NORMAL, BOLD and ITALIC. All other style bits are |
564 * ignored. | |
565 * | |
566 * @param style the new style for this <code>FontData</code> | |
567 * | |
568 * @see #getStyle | |
569 */ | |
570 public void setStyle(int style) { | |
571 if ((style & DWT.BOLD) is DWT.BOLD) { | |
572 data.lfWeight = 700; | |
573 } else { | |
574 data.lfWeight = 0; | |
575 } | |
576 if ((style & DWT.ITALIC) is DWT.ITALIC) { | |
577 data.lfItalic = 1; | |
578 } else { | |
579 data.lfItalic = 0; | |
580 } | |
581 } | |
582 | |
583 /** | |
584 * Returns a string representation of the receiver which is suitable | |
23 | 585 * for constructing an equivalent instance using the |
15 | 586 * <code>FontData(String)</code> constructor. |
587 * | |
588 * @return a string representation of the FontData | |
589 * | |
590 * @see FontData | |
591 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
592 override public String toString() { |
15 | 593 StringBuffer buffer = new StringBuffer(); |
594 buffer.append("1|"); //$NON-NLS-1$ | |
595 buffer.append(getName()); | |
596 buffer.append("|"); //$NON-NLS-1$ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
597 buffer.append(to!(String)(getHeightF())); |
15 | 598 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
599 buffer.append(to!(String)(getStyle())); |
15 | 600 buffer.append("|"); //$NON-NLS-1$ |
23 | 601 buffer.append("WINDOWS|1|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
602 buffer.append(to!(String)(data.lfHeight)); |
15 | 603 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
604 buffer.append(to!(String)(data.lfWidth)); |
15 | 605 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
606 buffer.append(to!(String)(data.lfEscapement)); |
15 | 607 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
608 buffer.append(to!(String)(data.lfOrientation)); |
15 | 609 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
610 buffer.append(to!(String)(data.lfWeight)); |
15 | 611 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
612 buffer.append(to!(String)(data.lfItalic)); |
15 | 613 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
614 buffer.append(to!(String)(data.lfUnderline)); |
15 | 615 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
616 buffer.append(to!(String)(data.lfStrikeOut)); |
15 | 617 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
618 buffer.append(to!(String)(data.lfCharSet)); |
15 | 619 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
620 buffer.append(to!(String)(data.lfOutPrecision)); |
15 | 621 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
622 buffer.append(to!(String)(data.lfClipPrecision)); |
15 | 623 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
624 buffer.append(to!(String)(data.lfQuality)); |
15 | 625 buffer.append("|"); //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
204
diff
changeset
|
626 buffer.append(to!(String)(data.lfPitchAndFamily)); |
15 | 627 buffer.append("|"); //$NON-NLS-1$ |
628 buffer.append(getName()); | |
629 return buffer.toString(); | |
630 } | |
631 | |
23 | 632 /** |
15 | 633 * Invokes platform specific functionality to allocate a new font data. |
634 * <p> | |
635 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
636 * API for <code>FontData</code>. It is marked public only so that | |
637 * it can be shared within the packages provided by DWT. It is not | |
638 * available on all platforms, and should never be called from | |
639 * application code. | |
640 * </p> | |
641 * | |
642 * @param data the <code>LOGFONT</code> for the font data | |
643 * @param height the height of the font data | |
644 * @return a new font data object containing the specified <code>LOGFONT</code> and height | |
645 */ | |
646 public static FontData win32_new(LOGFONT* data, float height) { | |
647 return new FontData(data, height); | |
648 } | |
649 | |
650 } |