Mercurial > projects > dwt-linux
comparison dwt/graphics/FontData.d @ 238:380bad9f6852
reverted char[] to String
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:42:55 +0200 |
parents | 08789b28bdf3 |
children | c0d810de7093 |
comparison
equal
deleted
inserted
replaced
237:98b80b00af79 | 238:380bad9f6852 |
---|---|
17 | 17 |
18 import tango.text.convert.Format; | 18 import tango.text.convert.Format; |
19 import tango.text.Util : locate; | 19 import tango.text.Util : locate; |
20 import tango.util.Convert; | 20 import tango.util.Convert; |
21 import dwt.dwthelper.utils; | 21 import dwt.dwthelper.utils; |
22 import tango.util.log.Trace; | |
22 | 23 |
23 /** | 24 /** |
24 * Instances of this class describe operating system fonts. | 25 * Instances of this class describe operating system fonts. |
25 * <p> | 26 * <p> |
26 * For platform-independent behaviour, use the get and set methods | 27 * For platform-independent behaviour, use the get and set methods |
53 * public API. It is marked public only so that it can be shared | 54 * public API. It is marked public only so that it can be shared |
54 * within the packages provided by DWT. It is not available on all | 55 * within the packages provided by DWT. It is not available on all |
55 * platforms and should never be accessed from application code. | 56 * platforms and should never be accessed from application code. |
56 * </p> | 57 * </p> |
57 */ | 58 */ |
58 public char[] name; | 59 public String name; |
59 | 60 |
60 /** | 61 /** |
61 * The height of the font data in points | 62 * The height of the font data in points |
62 * (Warning: This field is platform dependent) | 63 * (Warning: This field is platform dependent) |
63 * <p> | 64 * <p> |
89 * public API. It is marked public only so that it can be shared | 90 * public API. It is marked public only so that it can be shared |
90 * within the packages provided by DWT. It is not available on all | 91 * within the packages provided by DWT. It is not available on all |
91 * platforms and should never be accessed from application code. | 92 * platforms and should never be accessed from application code. |
92 * </p> | 93 * </p> |
93 */ | 94 */ |
94 public char[] str; | 95 public String str; |
95 | 96 |
96 /** | 97 /** |
97 * The locales of the font | 98 * The locales of the font |
98 */ | 99 */ |
99 char[] lang, country, variant; | 100 String lang, country, variant; |
100 | 101 |
101 /** | 102 /** |
102 * Constructs a new uninitialized font data. | 103 * Constructs a new uninitialized font data. |
103 */ | 104 */ |
104 public this () { | 105 public this () { |
122 * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li> | 123 * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li> |
123 * </ul> | 124 * </ul> |
124 * | 125 * |
125 * @see #toString | 126 * @see #toString |
126 */ | 127 */ |
127 public this(char[] str) { | 128 public this(String str) { |
128 if (str is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 129 if (str is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
129 int start = 0; | 130 int start = 0; |
130 int end = locate( str, '|' ); | 131 int end = locate( str, '|' ); |
131 if (end is str.length ) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 132 if (end is str.length ) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
132 char[] version1 = str[ start .. end ]; | 133 String version1 = str[ start .. end ]; |
133 try { | 134 try { |
134 if (to!(int)(version1) !is 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 135 if (to!(int)(version1) !is 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
135 } catch (ConversionException e) { | 136 } catch (ConversionException e) { |
136 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 137 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
137 } | 138 } |
138 | 139 |
139 start = end + 1; | 140 start = end + 1; |
140 end = locate( str, '|', start ); | 141 end = locate( str, '|', start ); |
141 if (end is str.length ) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 142 if (end is str.length ) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
142 char[] name = str[start .. end ]; | 143 String name = str[start .. end ]; |
143 | 144 |
144 start = end + 1; | 145 start = end + 1; |
145 end = locate( str, '|', start ); | 146 end = locate( str, '|', start ); |
146 if (end is str.length ) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 147 if (end is str.length ) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
147 float height = 0; | 148 float height = 0; |
165 end = locate( str, '|', start ); | 166 end = locate( str, '|', start ); |
166 setName(name); | 167 setName(name); |
167 setHeight(height); | 168 setHeight(height); |
168 setStyle(style); | 169 setStyle(style); |
169 if (end is str.length) return; | 170 if (end is str.length) return; |
170 char[] platform = str[ start .. end ]; | 171 String platform = str[ start .. end ]; |
171 | 172 |
172 start = end + 1; | 173 start = end + 1; |
173 end = locate( str, '|', start ); | 174 end = locate( str, '|', start ); |
174 if (end is str.length) return; | 175 if (end is str.length) return; |
175 char[] version2 = str[ start .. end ]; | 176 String version2 = str[ start .. end ]; |
176 | 177 |
177 if (platform.equals("GTK") && version2.equals("1")) { | 178 if (platform.equals("GTK") && version2.equals("1")) { |
178 return; | 179 return; |
179 } | 180 } |
180 } | 181 } |
191 * @exception IllegalArgumentException <ul> | 192 * @exception IllegalArgumentException <ul> |
192 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> | 193 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> |
193 * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> | 194 * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> |
194 * </ul> | 195 * </ul> |
195 */ | 196 */ |
196 public this(char[] name, int height, int style) { | 197 public this(String name, int height, int style) { |
197 setName(name); | 198 setName(name); |
198 setHeight(height); | 199 setHeight(height); |
199 setStyle(style); | 200 setStyle(style); |
200 } | 201 } |
201 | 202 |
202 /*public*/ this(char[] name, float height, int style) { | 203 /*public*/ this(String name, float height, int style) { |
203 setName(name); | 204 setName(name); |
204 setHeight(height); | 205 setHeight(height); |
205 setStyle(style); | 206 setStyle(style); |
206 } | 207 } |
207 | 208 |
253 * </p> | 254 * </p> |
254 * | 255 * |
255 * @return the <code>String</code> representing a Locale object | 256 * @return the <code>String</code> representing a Locale object |
256 * @since 3.0 | 257 * @since 3.0 |
257 */ | 258 */ |
258 public char[] getLocale () { | 259 public String getLocale () { |
259 char[] result; | 260 String result; |
260 const char sep = '_'; | 261 const char sep = '_'; |
261 if (lang !is null) { | 262 if (lang !is null) { |
262 result ~= lang; | 263 result ~= lang; |
263 result ~= sep; | 264 result ~= sep; |
264 } | 265 } |
273 if (result) { | 274 if (result) { |
274 if (result[$-1] is sep) { | 275 if (result[$-1] is sep) { |
275 result = result[0 .. $ - 1]; | 276 result = result[0 .. $ - 1]; |
276 } | 277 } |
277 } | 278 } |
279 Trace.formatln( "getLocal {}", result ); | |
278 return result; | 280 return result; |
279 } | 281 } |
280 | 282 |
281 /** | 283 /** |
282 * Returns the name of the receiver. | 284 * Returns the name of the receiver. |
285 * | 287 * |
286 * @return the name of this <code>FontData</code> | 288 * @return the name of this <code>FontData</code> |
287 * | 289 * |
288 * @see #setName | 290 * @see #setName |
289 */ | 291 */ |
290 public char[] getName() { | 292 public String getName() { |
291 return name; | 293 return name; |
292 } | 294 } |
293 | 295 |
294 /** | 296 /** |
295 * Returns the style of the receiver which is a bitwise OR of | 297 * Returns the style of the receiver which is a bitwise OR of |
313 * @return the receiver's hash | 315 * @return the receiver's hash |
314 * | 316 * |
315 * @see #equals | 317 * @see #equals |
316 */ | 318 */ |
317 public override hash_t toHash () { | 319 public override hash_t toHash () { |
318 return typeid(char[]).getHash(&name) ^ getHeight() ^ style; | 320 return typeid(String).getHash(&name) ^ getHeight() ^ style; |
319 } | 321 } |
320 | 322 |
321 /** | 323 /** |
322 * Sets the height of the receiver. The parameter is | 324 * Sets the height of the receiver. The parameter is |
323 * specified in terms of points, where a point is one | 325 * specified in terms of points, where a point is one |
358 * </p> | 360 * </p> |
359 * | 361 * |
360 * @param locale the <code>String</code> representing a Locale object | 362 * @param locale the <code>String</code> representing a Locale object |
361 * @see java.util.Locale#toString | 363 * @see java.util.Locale#toString |
362 */ | 364 */ |
363 public void setLocale(char[] locale) { | 365 public void setLocale(String locale) { |
366 Trace.formatln( "setLocal {}", locale ); | |
364 lang = country = variant = null; | 367 lang = country = variant = null; |
365 if (locale !is null) { | 368 if (locale !is null) { |
366 char sep = '_'; | 369 char sep = '_'; |
367 int length = locale.length; | 370 int length = locale.length; |
368 int firstSep, secondSep; | 371 int firstSep, secondSep; |
403 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> | 406 * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> |
404 * </ul> | 407 * </ul> |
405 * | 408 * |
406 * @see #getName | 409 * @see #getName |
407 */ | 410 */ |
408 public void setName(char[] name) { | 411 public void setName(String name) { |
409 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 412 if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
410 this.name = name; | 413 this.name = name; |
411 this.str = null; | 414 this.str = null; |
412 } | 415 } |
413 | 416 |
433 * | 436 * |
434 * @return a string representation of the FontData | 437 * @return a string representation of the FontData |
435 * | 438 * |
436 * @see FontData | 439 * @see FontData |
437 */ | 440 */ |
438 public override char[] toString() { | 441 public override String toString() { |
439 return Format( "1|{}|{}|{}|GTK|1|", getName, getHeightF, getStyle ); | 442 return Format( "1|{}|{}|{}|GTK|1|", getName, getHeightF, getStyle ); |
440 } | 443 } |
441 | 444 |
442 } | 445 } |