Changeset 11
- Timestamp:
- 05/02/04 12:49:53 (4 years ago)
- Files:
-
- branches/0.1/src/dwt/graphics/all.d (modified) (2 diffs)
- branches/0.1/src/dwt/graphics/color.d (modified) (13 diffs)
- branches/0.1/src/dwt/graphics/device.d (modified) (27 diffs)
- branches/0.1/src/dwt/graphics/drawable.d (modified) (5 diffs)
- branches/0.1/src/dwt/graphics/font.d (modified) (14 diffs)
- branches/0.1/src/dwt/graphics/fontdata.d (modified) (26 diffs)
- branches/0.1/src/dwt/graphics/fontmetrics.d (modified) (8 diffs)
- branches/0.1/src/dwt/graphics/forward.d (added)
- branches/0.1/src/dwt/graphics/gc.d (modified) (136 diffs)
- branches/0.1/src/dwt/graphics/gcdata.d (modified) (2 diffs)
- branches/0.1/src/dwt/graphics/image.d (modified) (104 diffs)
- branches/0.1/src/dwt/graphics/imagedata.d (modified) (137 diffs)
- branches/0.1/src/dwt/graphics/imageloader.d (added)
- branches/0.1/src/dwt/graphics/palettedata.d (added)
- branches/0.1/src/dwt/graphics/region.d (modified) (21 diffs)
- branches/0.1/src/dwt/graphics/rgb.d (modified) (5 diffs)
- branches/0.1/src/dwt/internal/callback.d (added)
- branches/0.1/src/dwt/internal/compatibility.d (modified) (13 diffs)
- branches/0.1/src/dwt/internal/library.d (modified) (4 diffs)
- branches/0.1/src/dwt/internal/make_callback.d.py (added)
- branches/0.1/src/dwt/internal/platform.d (modified) (1 diff)
- branches/0.1/src/dwt/internal/win32/all.d (modified) (1 diff)
- branches/0.1/src/dwt/internal/win32/bitmap.d (deleted)
- branches/0.1/src/dwt/internal/win32/forward.d (deleted)
- branches/0.1/src/dwt/internal/win32/os.d (modified) (37 diffs)
- branches/0.1/src/dwt/internal/win32/rect.d (modified) (1 diff)
- branches/0.1/src/dwt/internal/win32/tchar.d (modified) (2 diffs)
- branches/0.1/src/dwt/internal/win32/textmetric.d (modified) (6 diffs)
- branches/0.1/src/dwt/internal/win32/types.d (modified) (3 diffs)
- branches/0.1/src/dwt/util/runnable.d (modified) (1 diff)
- branches/0.1/src/dwt/util/string.d (modified) (114 diffs)
- branches/0.1/src/dwt/util/util.d (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/0.1/src/dwt/graphics/all.d
r3 r11 3 3 module dwt.graphics.all; 4 4 5 5 /* 6 6 import dwt.graphics.device; 7 7 import dwt.graphics.devicedata; … … 10 10 import dwt.graphics.rectangle; 11 11 12 */ branches/0.1/src/dwt/graphics/color.d
r3 r11 12 12 private import dwt.graphics.device; 13 13 private import dwt.internal.win32.os; 14 private import std.string; 14 15 15 16 … … 17 18 * Instances of this class manage the operating system resources that 18 19 * implement DWT's RGB color model. To create a color you can either 19 * specify the individual color components as integers in the range 20 * 0 to 255 or provide an instance of an <code>RGB</code>. 21 * <p> 22 * Application code must explicitly invoke the <code>Color.dispose()</code> 20 * specify the individual color components as integers in the range 21 * 0 to 255 or provide an instance of an <code>RGB</code>. 22 * <p> 23 * Application code must explicitly invoke the <code>Color.dispose()</code> 23 24 * method to release the operating system resources managed by each instance 24 25 * when those instances are no longer required. … … 30 31 31 32 public final class Color { 32 33 33 34 /** 34 * the handle to the OS color resource 35 * the handle to the OS color resource 35 36 * (Warning: This field is platform dependent) 36 37 */ 37 38 public int handle; 38 39 39 40 /** 40 41 * the device where this color was created … … 47 48 this(){} 48 49 49 /** 50 /** 50 51 * Constructs a new instance of this class given a device and the 51 52 * desired red, green and blue values expressed as ints in the range … … 53 54 * color devices, the color instance created by this call may not have 54 55 * the same RGB values as the ones specified by the arguments. The 55 * RGB values on the returned instance will be the color values of 56 * RGB values on the returned instance will be the color values of 56 57 * the operating system color. 57 58 * <p> 58 * You must dispose the color when it is no longer required. 59 * You must dispose the color when it is no longer required. 59 60 * </p> 60 61 * … … 78 79 } 79 80 80 /** 81 /** 81 82 * Constructs a new instance of this class given a device and an 82 83 * <code>RGB</code> describing the desired red, green and blue values. … … 86 87 * values of the operating system color. 87 88 * <p> 88 * You must dispose the color when it is no longer required. 89 * You must dispose the color when it is no longer required. 89 90 * </p> 90 91 * … … 103 104 if (device == null) device = Device.getDevice(); 104 105 if (device == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 105 if (rgb == null) DWT.error(DWT.ERROR_NULL_ARGUMENT);106 106 init(device, rgb.red, rgb.green, rgb.blue); 107 107 if (device.tracking) device.new_Object(this); … … 204 204 public RGB getRGB () { 205 205 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 206 return newRGB(handle & 0xFF, (handle & 0xFF00) >> 8, (handle & 0xFF0000) >> 16);207 } 208 209 /** 210 * Returns an integer hash code for the receiver. Any two 211 * objects which return <code>true</code> when passed to 206 return RGB(handle & 0xFF, (handle & 0xFF00) >> 8, (handle & 0xFF0000) >> 16); 207 } 208 209 /** 210 * Returns an integer hash code for the receiver. Any two 211 * objects which return <code>true</code> when passed to 212 212 * <code>equals</code> must return the same value for this 213 213 * method. … … 222 222 223 223 /** 224 * Allocates the operating system resources associated 224 * Allocates the operating system resources associated 225 225 * with the receiver. 226 226 * … … 242 242 this.device = device; 243 243 handle = 0x02000000 | (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16); 244 244 245 245 /* If this is not a palette-based device, return */ 246 246 int hPal = device.hPalette; 247 247 if (hPal == 0) return; 248 248 249 249 int[] colorRefCount = device.colorRefCount; 250 250 /* Add this color to the default palette now */ … … 276 276 } else { 277 277 /* Found a free entry */ 278 entry = new byte[] [ cast(byte)(red & 0xFF), cast(byte)(green & 0xFF), cast(byte)(blue & 0xFF), 0 ]; 278 entry = new byte[3];// [ cast(byte)(red & 0xFF), cast(byte)(green & 0xFF), cast(byte)(blue & 0xFF), 0 ]; 279 entry[0] = red & 0xff; 280 entry[1] = green & 0xff; 281 entry[2] = blue & 0xff; 279 282 OS.SetPaletteEntries(hPal, index, 1, entry); 280 283 } … … 304 307 public char[] toString () { 305 308 if (isDisposed()) return "Color {*DISPOSED*}"; //$NON-NLS-1$ 306 return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() +"}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$307 } 308 309 /** 309 return "Color {" ~ .toString(getRed()) ~ ", " ~ .toString(getGreen()) ~ ", " ~ .toString(getBlue()) ~ "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 310 } 311 312 /** 310 313 * Invokes platform specific functionality to allocate a new color. 311 314 * <p> branches/0.1/src/dwt/graphics/device.d
r3 r11 9 9 +/ 10 10 11 private import dwt.dwt; 12 13 private import dwt.graphics.color; 14 private import dwt.graphics.drawable; 15 private import dwt.graphics.devicedata; 16 private import dwt.graphics.font; 17 private import dwt.graphics.fontdata; 18 private import dwt.graphics.gcdata; 19 private import dwt.graphics.rectangle; 20 private import dwt.graphics.point; 21 22 private import dwt.internal.compatibility; 23 24 private import dwt.internal.win32.os; 25 private import dwt.internal.win32.logfont; 26 private import dwt.internal.win32.logfonta; 27 private import dwt.internal.win32.logfontw; 28 private import dwt.internal.win32.textmetric; 29 private import dwt.internal.win32.textmetrica; 30 private import dwt.internal.win32.textmetricw; 31 32 private import dwt.util.runnable; 33 11 private 12 { 13 import dwt.dwt; 14 15 import dwt.graphics.color; 16 import dwt.graphics.drawable; 17 import dwt.graphics.devicedata; 18 import dwt.graphics.font; 19 import dwt.graphics.fontdata; 20 import dwt.graphics.forward; 21 import dwt.graphics.rectangle; 22 import dwt.graphics.point; 23 24 import dwt.internal.compatibility; 25 26 import dwt.internal.win32.os; 27 import dwt.internal.win32.logfont; 28 import dwt.internal.win32.textmetric; 29 import dwt.internal.win32.tchar; 30 31 import dwt.util.runnable; 32 } 34 33 35 34 /** … … 42 41 /+ TODO: this was an abstract class, but I was having difficulties 43 42 with no implementations allowed +/ 44 45 public class Device : D rawable {46 47 43 44 public class Device : DeviceBase { 45 46 48 47 /* Debugging */ 49 48 // debug { 50 public static bit DBUG;49 public const bit DBUG = true; 51 50 bit dbug = DBUG; 52 51 bit tracking = DBUG; … … 54 53 Object[] objects; 55 54 // } 56 57 58 /* Palette 55 56 57 /* Palette 59 58 * (Warning: This field is platform dependent) 60 59 */ 61 public int hPalette = 0; 60 /* 61 // Moved into DeviceBase for the time being. 62 public int hPalette = 0; 62 63 int[] colorRefCount; 63 64 / * System Font */64 65 // System Font 65 66 int systemFont; 66 67 67 / * Font Enumeration */68 // Font Enumeration 68 69 int nFonts = 256; 69 LOGFONT [] logFonts;70 LOGFONT*[] logFonts; 70 71 71 72 bit disposed; 72 73 /+ 73 */ 74 75 74 76 /* 75 77 * TEMPORARY CODE. When a graphics object is … … 86 88 protected static Device CurrentDevice; 87 89 protected static Runnable DeviceFinder; 90 /+ 88 91 static { 89 92 try { 90 93 Class.forName ("org.eclipse.swt.widgets.Display"); 91 94 } catch (Throwable e) {} 92 93 94 95 } 95 } 96 +/ 96 97 97 98 /* … … 105 106 } 106 107 107 +/ 108 108 109 109 /** 110 110 * Constructs a new instance of this class. 111 111 * <p> 112 * You must dispose the device when it is no longer required. 112 * You must dispose the device when it is no longer required. 113 113 * </p> 114 114 * … … 120 120 */ 121 121 122 this() {} 123 122 this() {} 123 124 124 125 125 // TODO: not working when class was abstract due to no implementations … … 138 138 /* Initialize the system font slot */ 139 139 systemFont = getSystemFont().handle; 140 140 141 141 } 142 142 … … 195 195 } 196 196 197 int computePoints(LOGFONT logFont) {197 int computePoints(LOGFONT* logFont) { 198 198 int hDC = internal_new_GC (null); 199 199 int logPixelsY = OS.GetDeviceCaps(hDC, OS.LOGPIXELSY); 200 int pixels = 0; 200 int pixels = 0; 201 201 if (logFont.lfHeight > 0) { 202 202 /* … … 210 210 int hFont = OS.CreateFontIndirect(logFont); 211 211 int oldFont = OS.SelectObject(hDC, hFont); 212 TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA(); 212 TEXTMETRIC* lptm = OS.IsUnicode 213 ? cast(TEXTMETRIC*)new TEXTMETRICW() 214 : cast(TEXTMETRIC*)new TEXTMETRICA(); 213 215 OS.GetTextMetrics(hDC, lptm); 214 216 OS.SelectObject(hDC, oldFont); … … 281 283 bit scalable = lParam == 1; 282 284 if (isScalable == scalable) { 285 // DWT's Java heritage is responsible for this particular weirdness. 286 283 287 /* Add the log font to the list of log fonts */ 284 if (nFonts == logFonts.length) { 285 LOGFONT[] newLogFonts = new LOGFONT[logFonts.length + 128]; 286 // System.arraycopy (logFonts, 0, newLogFonts, 0, nFonts); 287 newLogFonts = logFonts.dup; 288 logFonts = newLogFonts; 289 } 290 LOGFONT logFont = logFonts[nFonts]; 291 if (logFont == null) logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW () : new LOGFONTA (); 292 OS.MoveMemory (logFont, lpelfe, LOGFONT.sizeof); 293 logFonts [nFonts++] = logFont; 288 if (nFonts == logFonts.length) 289 logFonts.length = logFonts.length + 128; 290 291 LOGFONT* logFont = logFonts[nFonts]; 292 if (logFont === null) 293 logFont = OS.IsUnicode 294 ? cast(LOGFONT*)new LOGFONTW () 295 : cast(LOGFONT*)new LOGFONTA (); 296 297 // FIXME? LOGFONT is smaller than LOGFONTW and LOGFONTA 298 // the string at the end isn't copied! 299 *logFont = *cast(LOGFONT*)lpelfe; 300 301 logFonts ~= logFont; 302 nFonts++; 294 303 } 295 304 return 1; … … 353 362 * Returns a rectangle which describes the area of the 354 363 * receiver which is capable of displaying data. 355 * 364 * 356 365 * @return the client area 357 366 * … … 369 378 * Returns the bit depth of the screen, which is the number of 370 379 * bits it takes to represent the number of unique colors that 371 * the screen is currently capable of displaying. This number 380 * the screen is currently capable of displaying. This number 372 381 * will typically be one of 1, 8, 15, 16, 24 or 32. 373 382 * … … 420 429 * </ul> 421 430 */ 422 public FontData[] getFontList( char[] faceName, bit scalable) {431 public FontData[] getFontList(wchar[] faceName, bit scalable) { 423 432 checkDevice (); 424 433 425 434 /+ 426 435 /* Create the callback */ … … 428 437 int lpEnumFontFamProc = callback.getAddress (); 429 438 +/ 430 439 431 440 /* Initialize the instance variables */ 432 logFonts = new LOGFONT [nFonts];441 logFonts = new LOGFONT*[nFonts]; 433 442 for (int i=0; i<logFonts.length; i++) { 434 logFonts [i] = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA (); 443 logFonts [i] = OS.IsUnicode 444 ? cast(LOGFONT*) new LOGFONTW () 445 : cast(LOGFONT*) new LOGFONTA (); 435 446 } 436 447 nFonts = 0; … … 439 450 int offset = 0; 440 451 int hDC = internal_new_GC (null); 441 if (faceName == null) { 452 if (faceName == null) { 442 453 /* The user did not specify a face name, so they want all versions of all available face names */ 443 454 444 455 // TODO: in D - this involves dwt.internal.callback above, if we're going to use that. 445 456 // OS.EnumFontFamilies (hDC, null, lpEnumFontFamProc, scalable ? 1 : 0); 446 457 447 458 /** 448 459 * For bitmapped fonts, EnumFontFamilies only enumerates once for each font, regardless … … 452 463 offset = nFonts; 453 464 for (int i=0; i<offset; i++) { 454 LOGFONT lf = logFonts [i];455 465 LOGFONT* lf = logFonts [i]; 466 456 467 /+ TODO: in D 457 468 /** … … 487 498 FontData[] result = new FontData[count]; 488 499 for (int i=0; i<count; i++) { 489 LOGFONT logFont = logFonts [i+offset];500 LOGFONT* logFont = logFonts [i+offset]; 490 501 result [i] = FontData.win32_new (logFont, computePoints(logFont)); 491 502 } 492 503 493 504 /* Clean up */ 494 505 // TODO: using this? callback.dispose (); … … 591 602 * call the <code>super</code> implementation. 592 603 * </p> 593 * 604 * 594 605 * @see #create 595 606 */ … … 606 617 int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL); 607 618 int planes = OS.GetDeviceCaps (hDC, OS.PLANES); 608 619 609 620 bits *= planes; 610 621 if ((rc & OS.RC_PALETTE) == 0 || bits != 8) { … … 612 623 return; 613 624 } 614 625 615 626 int numReserved = OS.GetDeviceCaps (hDC, OS.NUMRESERVED); 616 627 int numEntries = OS.GetDeviceCaps (hDC, OS.SIZEPALETTE); … … 632 643 /* 4 bytes header + 4 bytes per entry * numEntries entries */ 633 644 byte [] logPalette = new byte [4 + 4 * numEntries]; 634 645 635 646 /* 2 bytes = special header */ 636 647 logPalette [0] = 0x00; 637 648 logPalette [1] = 0x03; 638 649 639 650 /* 2 bytes = number of colors, LSB first */ 640 651 logPalette [2] = 0; 641 652 logPalette [3] = 1; 642 653 643 /* 654 /* 644 655 * Create a palette which contains the system entries 645 656 * as they are located in the system palette. The … … 653 664 /* Copy all entries from the system palette */ 654 665 // System.arraycopy (lppe, 0, logPalette, 4, 4 * numEntries); 655 666 656 667 /* Lock the indices corresponding to the system entries */ 657 668 for (int i = 0; i < numReserved / 2; i++) { … … 668 679 669 680 670 /** 681 /** 671 682 * Invokes platform specific functionality to allocate a new GC handle. 672 683 * <p> … … 678 689 * </p> 679 690 * 680 * @param data the platform specific GC data 691 * @param data the platform specific GC data 681 692 * @return the platform specific GC handle 682 693 */ 683 public int internal_new_GC (GCData data) { }684 685 /** 694 public int internal_new_GC (GCData data) { return 0; } 695 696 /** 686 697 * Invokes platform specific functionality to dispose a GC handle. 687 698 * <p> … … 694 705 * 695 706 * @param handle the platform specific GC handle 696 * @param data the platform specific GC data 707 * @param data the platform specific GC data 697 708 */ 698 709 public void internal_dispose_GC (int hDC, GCData data) {} … … 718 729 if (objects [i] == null) { 719 730 objects [i] = object; 720 errors [i] = new Error ( );731 errors [i] = new Error ("Java doesn't require a string here but D does -- andy"); 721 732 return; 722 733 } … … 728 739 Error [] newErrors = new Error [errors.length + 128]; 729 740 // TODO: System.arraycopy (errors, 0, newErrors, 0, errors.length); 730 newErrors [errors.length] = new Error ( );741 newErrors [errors.length] = new Error ("Same here"); 731 742 errors = newErrors; 732 743 } branches/0.1/src/dwt/graphics/drawable.d
r3 r11 1 1 /+ 2 2 3 3 module dwt.graphics.drawable; … … 8 8 public interface Drawable { 9 9 10 /** 10 /** 11 11 * Invokes platform specific functionality to allocate a new GC handle. 12 12 * <p> … … 18 18 * </p> 19 19 * 20 * @param data the platform specific GC data 20 * @param data the platform specific GC data 21 21 * @return the platform specific GC handle 22 22 */ … … 25 25 26 26 27 /** 27 /** 28 28 * Invokes platform specific functionality to dispose a GC handle. 29 29 * <p> … … 36 36 * 37 37 * @param handle the platform specific GC handle 38 * @param data the platform specific GC data 38 * @param data the platform specific GC data 39 39 */ 40 40 41 41 public void internal_dispose_GC (int handle, GCData data); 42 42 } 43 +/ branches/0.1/src/dwt/graphics/font.d
r3 r11 13 13 private import dwt.internal.win32.os; 14 14 private import dwt.internal.win32.logfont; 15 15 private import std.string; 16 16 17 17 … … 22 22 * or a <code>FontData</code> object which encapsulates this data. 23 23 * <p> 24 * Application code must explicitly invoke the <code>Font.dispose()</code> 24 * Application code must explicitly invoke the <code>Font.dispose()</code> 25 25 * method to release the operating system resources managed by each instance 26 26 * when those instances are no longer required. … … 31 31 32 32 public final class Font { 33 33 34 34 /** 35 35 * the handle to the OS font resource … … 37 37 */ 38 38 public int handle; 39 39 40 40 /** 41 41 * the device where this font was created 42 42 */ 43 43 Device device; 44 44 45 45 /** 46 46 * Prevents uninitialized instances from being created outside the package. … … 48 48 this() {} 49 49 50 /** 50 /** 51 51 * Constructs a new font given a device and font data 52 52 * which describes the desired font's appearance. 53 53 * <p> 54 * You must dispose the font when it is no longer required. 54 * You must dispose the font when it is no longer required. 55 55 * </p> 56 56 * 57 57 * @param device the device to create the font on 58 58 * @param fd the FontData that describes the desired font (must not be null) 59 * 59 * 60 60 * @exception IllegalArgumentException <ul> 61 61 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> … … 70 70 if (device == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 71 71 init(device, fd); 72 if (device.tracking) device.new_Object(this); 73 } 74 75 /** 72 if (device.tracking) device.new_Object(this); 73 } 74 75 /** 76 76 * Constructs a new font given a device and an array 77 77 * of font data which describes the desired font's 78 78 * appearance. 79 79 * <p> 80 * You must dispose the font when it is no longer required. 80 * You must dispose the font when it is no longer required. 81 81 * </p> 82 82 * 83 83 * @param device the device to create the font on 84 84 * @param fds the array of FontData that describes the desired font (must not be null) 85 * 85 * 86 86 * @exception IllegalArgumentException <ul> 87 87 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> … … 93 93 * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li> 94 94 * </ul> 95 * 95 * 96 96 * @since 2.1 97 97 */ … … 102 102 if (fds.length == 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 103 103 init(device, fds[0]); 104 if (device.tracking) device.new_Object(this); 105 } 106 107 /** 104 if (device.tracking) device.new_Object(this); 105 } 106 107 /** 108 108 * Constructs a new font given a device, a font name, 109 109 * the height of the desired font in points, and a font 110 110 * style. 111 111 * <p> 112 * You must dispose the font when it is no longer required. 112 * You must dispose the font when it is no longer required. 113 113 * </p> 114 114 * … … 117 117 * @param height the font height in points 118 118 * @param style a bit or combination of NORMAL, BOLD, ITALIC 119 * 119 * 120 120 * @exception IllegalArgumentException <ul> 121 121 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> … … 127 127 * </ul> 128 128 */ 129 public this(Device device, char[] name, int height, int style) {129 public this(Device device, wchar[] name, int height, int style) { 130 130 if (device == null) device = Device.getDevice(); 131 131 if (device == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 132 132 if (name == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 133 133 init(device, new FontData (name, height, style)); 134 if (device.tracking) device.new_Object(this); 134 if (device.tracking) device.new_Object(this); 135 135 } 136 136 … … 168 168 /** 169 169 * Returns an array of <code>FontData</code>s representing the receiver. 170 * On Windows, only one FontData will be returned per font. On X however, 171 * a <code>Font</code> object <em>may</em> be composed of multiple X 170 * On Windows, only one FontData will be returned per font. On X however, 171 * a <code>Font</code> object <em>may</em> be composed of multiple X 172 172 * fonts. To support this case, we return an array of font data objects. 173 173 * … … 180 180 public FontData[] getFontData() { 181 181 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 182 LOGFONT logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); 182 LOGFONT* logFont = OS.IsUnicode 183 ? cast(LOGFONT*)new LOGFONTW() 184 : cast(LOGFONT*)new LOGFONTA(); 183 185 OS.GetObject(handle, LOGFONT.sizeof, logFont); 184 return new FontData[] [FontData.win32_new(logFont, device.computePoints(logFont))]; 185 } 186 187 /** 188 * Returns an integer hash code for the receiver. Any two 189 * objects which return <code>true</code> when passed to 186 187 FontData[] result; 188 result ~= FontData.win32_new(logFont, device.computePoints(logFont)); 189 return result; 190 } 191 192 /** 193 * Returns an integer hash code for the receiver. Any two 194 * objects which return <code>true</code> when passed to 190 195 * <code>equals</code> must return the same value for this 191 196 * method. … … 202 207 if (fd == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 203 208 this.device = device; 204 LOGFONT logFont = fd.data;209 LOGFONT* logFont = fd.data; 205 210 int lfHeight = logFont.lfHeight; 206 211 logFont.lfHeight = device.computePixels(fd.height); … … 232 237 public char[] toString () { 233 238 if (isDisposed()) return "Font {*DISPOSED*}"; 234 return "Font {" + handle +"}";235 } 236 237 /** 239 return "Font {" ~ .toString(handle) ~ "}"; 240 } 241 242 /** 238 243 * Invokes platform specific functionality to allocate a new font. 239 244 * <p> branches/0.1/src/dwt/graphics/fontdata.d
r3 r11 3 3 module dwt.graphics.fontdata; 4 4 5 /+ 5 /+ 6 6 import org.eclipse.swt.internal.*; 7 7 import org.eclipse.swt.internal.win32.*; … … 12 12 13 13 private import dwt.internal.win32.logfont; 14 private import dwt.internal.win32.logfonta;15 private import dwt.internal.win32.logfontw;16 14 private import dwt.internal.win32.os; 17 15 private import dwt.internal.win32.tchar; 16 private import dwt.internal.callback; 17 private import dwt.util.string; 18 private import std.string; 18 19 19 20 … … 45 46 46 47 public final class FontData { 47 48 48 49 /** 49 50 * A Win32 LOGFONT struct 50 51 * (Warning: This field is platform dependent) 51 52 */ 52 public LOGFONT data;53 53 public LOGFONT* data; 54 54 55 /** 55 56 * The height of the font data in points … … 57 58 */ 58 59 public int height; 59 60 60 61 /** 61 62 * The locales of the font 62 63 * (Warning: These fields are platform dependent) 63 64 */ 64 char[] lang, country, variant;65 66 /** 65 wchar[] lang, country, variant; 66 67 /** 67 68 * Constructs a new un-initialized font data. 68 69 */ 69 70 public this() { 70 data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); 71 data = OS.IsUnicode 72 ? cast(LOGFONT*)new LOGFONTW() 73 : cast(LOGFONT*)new LOGFONTA(); 71 74 // We set the charset field so that 72 75 // wildcard searching will work properly … … 79 82 * Constructs a new font data given the Windows <code>LOGFONT</code> 80 83 * that it should represent. 81 * 84 * 82 85 * @param data the <code>LOGFONT</code> for the result 83 86 */ 84 this(LOGFONT data, int height) {87 this(LOGFONT* data, int height) { 85 88 this.data = data; 86 89 this.height = height; … … 93 96 * <p> 94 97 * Note that the representation varies between platforms, 95 * and a FontData can only be created from a string that was 98 * and a FontData can only be created from a string that was 96 99 * generated on the same platform. 97 100 * </p> … … 106 109 * @see #toString 107 110 */ 108 public this(char[] string) { 109 if (string == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 110 int start = 0; 111 int end = string.indexOf('|'); 112 if (end == -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 113 char[] version1 = string.substring(start, end); 114 try { 115 if (Integer.parseInt(version1) != 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 116 } catch (NumberFormatException e) { 117 DWT.error(DWT.ERROR_INVALID_ARGUMENT); 118 } 119 120 start = end + 1; 121 end = string.indexOf('|', start); 122 if (end == -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 123 char[] name = string.substring(start, end); 124 125 start = end + 1; 126 end = string.indexOf('|', start); 127 if (end == -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 111 public this(wchar[] string) { 112 wchar[][] str = Strings!(wchar).split(string, "|"); 113 114 if (string === null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 115 int pos = 0; 116 if (pos >= str.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 117 wchar[] version1 = str[pos++]; 118 //try { 119 if (Strings!(wchar).toInt(version1) != 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 120 //} catch (NumberFormatException e) { 121 // DWT.error(DWT.ERROR_INVALID_ARGUMENT); 122 //} 123 124 if (pos >= str.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 125 wchar[] name = str[pos++]; 126 127 if (pos >= str.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 128 128 int height = 0; 129 try { 130 height = Integer.parseInt(string.substring(start, end)); 131 } catch (NumberFormatException e) { 132 DWT.error(DWT.ERROR_INVALID_ARGUMENT); 133 } 134 135 start = end + 1; 136 end = string.indexOf('|', start); 137 if (end == -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 129 //try { 130 height = Strings!(wchar).toInt(str[pos++]); 131 //} catch (NumberFormatException e) { 132 // DWT.error(DWT.ERROR_INVALID_ARGUMENT); 133 //} 134 135 if (pos >= str.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 138 136 int style = 0; 139 try {140 style = Integer.parseInt(string.substring(start, end));141 } catch (NumberFormatException e) {142 DWT.error(DWT.ERROR_INVALID_ARGUMENT);143 }144 145 start = end + 1;146 end = string.indexOf('|', start);147 data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() :new LOGFONTA();137 //try { 138 style = Strings!(wchar).toInt(str[pos++]); 139 //} catch (NumberFormatException e) { 140 // DWT.error(DWT.ERROR_INVALID_ARGUMENT); 141 //} 142 143 data = OS.IsUnicode 144 ? cast(LOGFONT*)new LOGFONTW() 145 : cast(LOGFONT*)new LOGFONTA(); 148 146 data.lfCharSet = OS.DEFAULT_CHARSET; 149 147 setName(name); 150 148 setHeight(height); 151 149 setStyle(style); 152 if (end == -1) return; 153 char[] platform = string.substring(start, end); 154 155 start = end + 1; 156 end = string.indexOf('|', start); 157 if (end == -1) return; 158 char[] version2 = string.substring(start, end); 159 160 if (platform.equals("WINDOWS") && version2.equals("1")) { 161 LOGFONT newData = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); 162 try { 163 start = end + 1; 164 end = string.indexOf('|', start); 165 if (end == -1) return; 166 newData.lfHeight = Integer.parseInt(string.substring(start, end)); 167 start = end + 1; 168 end = string.indexOf('|', start); 169 if (end == -1) return; 170 newData.lfWidth = Integer.parseInt(string.substring(start, end)); 171 start = end + 1; 172 end = string.indexOf('|', start); 173 if (end == -1) return; 174 newData.lfEscapement = Integer.parseInt(string.substring(start, end)); 175 start = end + 1; 176 end = string.indexOf('|', start); 177 if (end == -1) return; 178 newData.lfOrientation = Integer.parseInt(string.substring(start, end)); 179 start = end + 1; 180 end = string.indexOf('|', start); 181 if (end == -1) return; 182 newData.lfWeight = Integer.parseInt(string.substring(start, end)); 183 start = end + 1; 184 end = string.indexOf('|', start); 185 if (end == -1) return; 186 newData.lfItalic = Byte.parseByte(string.substring(start, end)); 187 start = end + 1; 188 end = string.indexOf('|', start); 189 if (end == -1) return; 190 newData.lfUnderline = Byte.parseByte(string.substring(start, end)); 191 start = end + 1; 192 end = string.indexOf('|', start); 193 if (end == -1) return; 194 newData.lfStrikeOut = Byte.parseByte(string.substring(start, end)); 195 start = end + 1; 196 end = string.indexOf('|', start); 197 if (end == -1) return; 198 newData.lfCharSet = Byte.parseByte(string.substring(start, end)); 199 start = end + 1; 200 end = string.indexOf('|', start); 201 if (end == -1) return; 202 newData.lfOutPrecision = Byte.parseByte(string.substring(start, end)); 203 start = end + 1; 204 end = string.indexOf('|', start); 205 if (end == -1) return; 206 newData.lfClipPrecision = Byte.parseByte(string.substring(start, end)); 207 start = end + 1; 208 end = string.indexOf('|', start); 209 if (end == -1) return; 210 newData.lfQuality = Byte.parseByte(string.substring(start, end)); 211 start = end + 1; 212 end = string.indexOf('|', start); 213 if (end == -1) return; 214 newData.lfPitchAndFamily = Byte.parseByte(string.substring(start, end)); 215 start = end + 1; 216 } catch (NumberFormatException e) { 150 if (pos >= str.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 151 wchar[] platform = str[pos++]; 152 153 if (pos >= str.length) return; 154 wchar[] version2 = str[pos++]; 155 156 if (platform == "WINDOWS" && version2 == "1") { 157 LOGFONT* newData = OS.IsUnicode 158 ? cast(LOGFONT*)new LOGFONTW() 159 : cast(LOGFONT*)new LOGFONTA(); 160 //try { 161 if (pos >= str.length) return; 162 newData.lfHeight = Strings!(wchar).toInt(str[pos++]); 163 164 if (pos >= str.length) return; 165 newData.lfWidth = Strings!(wchar).toInt(str[pos++]); 166 167 if (pos >= str.length) return; 168 newData.lfEscapement = Strings!(wchar).toInt(str[pos++]); 169 170 if (pos >= str.length) return; 171 &
