Mercurial > projects > dwt-mac
comparison dwt/graphics/TextStyle.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | 642f460a0908 |
children | 535243e6d16a |
comparison
equal
deleted
inserted
replaced
44:ca5e494f2bbf | 45:d8635bb48c7c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | 10 * |
11 * Port to the D programming language: | 11 * Port to the D programming language: |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | 12 * Jacob Carlborg <doob@me.com> |
13 *******************************************************************************/ | 13 *******************************************************************************/ |
14 module dwt.graphics.TextStyle; | 14 module dwt.graphics.TextStyle; |
15 | 15 |
16 import dwt.DWT; | 16 import dwt.DWT; |
17 | 17 |
36 * </p> | 36 * </p> |
37 * | 37 * |
38 * @see TextLayout | 38 * @see TextLayout |
39 * @see Font | 39 * @see Font |
40 * @see Color | 40 * @see Color |
41 * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a> | |
42 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
41 * | 43 * |
42 * @since 3.0 | 44 * @since 3.0 |
43 */ | 45 */ |
44 public class TextStyle { | 46 public class TextStyle { |
45 | 47 |
161 * @param background the background color of the style, <code>null</code> if none | 163 * @param background the background color of the style, <code>null</code> if none |
162 */ | 164 */ |
163 public this (Font font, Color foreground, Color background) { | 165 public this (Font font, Color foreground, Color background) { |
164 if (font !is null && font.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 166 if (font !is null && font.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
165 if (foreground !is null && foreground.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 167 if (foreground !is null && foreground.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
166 if (background !is null && background.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 168 if (background !is null && background.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
167 this.font = font; | 169 this.font = font; |
168 this.foreground = foreground; | 170 this.foreground = foreground; |
169 this.background = background; | 171 this.background = background; |
170 } | 172 } |
171 | 173 |
172 | 174 |
173 /** | 175 /** |
174 * Create a new text style from an existing text style. | 176 * Create a new text style from an existing text style. |
175 * | 177 * |
176 *@param style the style to copy | 178 * @param style the style to copy |
177 * | 179 * |
178 * @since 3.4 | 180 * @since 3.4 |
179 */ | 181 */ |
180 public this (TextStyle style) { | 182 public this (TextStyle style) { |
181 if (style is null) DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 183 if (style is null) DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
249 * @see #equals(Object) | 251 * @see #equals(Object) |
250 */ | 252 */ |
251 public hash_t toHash() { | 253 public hash_t toHash() { |
252 hash_t hash = 0; | 254 hash_t hash = 0; |
253 if (foreground !is null) hash ^= foreground.hashCode(); | 255 if (foreground !is null) hash ^= foreground.hashCode(); |
254 if (background !is null) hash ^= background.hashCode(); | 256 if (background !is null) hash ^= background.hashCode(); |
255 if (font !is null) hash ^= font.hashCode(); | 257 if (font !is null) hash ^= font.hashCode(); |
256 if (metrics !is null) hash ^= metrics.hashCode(); | 258 if (metrics !is null) hash ^= metrics.hashCode(); |
257 if (underline) hash ^= hash; | 259 if (underline) hash ^= hash; |
258 if (strikeout) hash ^= hash; | 260 if (strikeout) hash ^= hash; |
259 hash ^= rise; | 261 hash ^= rise; |
270 if (this is style) return true; | 272 if (this is style) return true; |
271 if (style is null) return false; | 273 if (style is null) return false; |
272 if (borderStyle !is style.borderStyle) return false; | 274 if (borderStyle !is style.borderStyle) return false; |
273 if (borderColor !is null) { | 275 if (borderColor !is null) { |
274 if (!borderColor.equals(style.borderColor)) return false; | 276 if (!borderColor.equals(style.borderColor)) return false; |
275 } else if (style.borderColor !is null) return false; | 277 } else { |
278 if (style.borderColor !is null) return false; | |
279 if (foreground !is null) { | |
280 if (!foreground.equals(style.foreground)) return false; | |
281 } else if (style.foreground !is null) return false; | |
282 } | |
276 return true; | 283 return true; |
277 } | 284 } |
278 | 285 |
279 bool isAdherentUnderline(TextStyle style) { | 286 bool isAdherentUnderline(TextStyle style) { |
280 if (this is style) return true; | 287 if (this is style) return true; |
281 if (style is null) return false; | 288 if (style is null) return false; |
282 if (underline !is style.underline) return false; | 289 if (underline !is style.underline) return false; |
283 if (underlineStyle !is style.underlineStyle) return false; | 290 if (underlineStyle !is style.underlineStyle) return false; |
284 if (underlineColor !is null) { | 291 if (underlineColor !is null) { |
285 if (!underlineColor.equals(style.underlineColor)) return false; | 292 if (!underlineColor.equals(style.underlineColor)) return false; |
286 } else if (style.underlineColor !is null) return false; | 293 } else { |
294 if (style.underlineColor !is null) return false; | |
295 if (foreground !is null) { | |
296 if (!foreground.equals(style.foreground)) return false; | |
297 } else if (style.foreground !is null) return false; | |
298 } | |
287 return true; | 299 return true; |
288 } | 300 } |
289 | 301 |
290 bool isAdherentStrikeout(TextStyle style) { | 302 bool isAdherentStrikeout(TextStyle style) { |
291 if (this is style) return true; | 303 if (this is style) return true; |
292 if (style is null) return false; | 304 if (style is null) return false; |
293 if (strikeout !is style.strikeout) return false; | 305 if (strikeout !is style.strikeout) return false; |
294 if (strikeoutColor !is null) { | 306 if (strikeoutColor !is null) { |
295 if (!strikeoutColor.equals(style.strikeoutColor)) return false; | 307 if (!strikeoutColor.equals(style.strikeoutColor)) return false; |
296 } else if (style.strikeoutColor !is null) return false; | 308 } else { |
309 if (style.strikeoutColor !is null) return false; | |
310 if (foreground !is null) { | |
311 if (!foreground.equals(style.foreground)) return false; | |
312 } else if (style.foreground !is null) return false; | |
313 } | |
297 return true; | 314 return true; |
298 } | 315 } |
299 | 316 |
300 /** | 317 /** |
301 * Returns a string containing a concise, human-readable | 318 * Returns a string containing a concise, human-readable |