Changeset 23:f5482da87ed8
- Timestamp:
- 01/27/08 11:43:55
(1 year ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
Image, ImageData?
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r0 |
r23 |
|
| 1 | | /** |
|---|
| | 1 | /** |
|---|
| 2 | 2 | * Authors: Frank Benoit <keinfarbton@googlemail.com> |
|---|
| 3 | 3 | */ |
|---|
| … | … | |
| 10 | 10 | static void validCheck(uint SrcLen, uint DestLen, uint copyLen){ |
|---|
| 11 | 11 | if(SrcLen < copyLen || DestLen < copyLen|| SrcLen < 0 || DestLen < 0){ |
|---|
| 12 | | Util.trace("Error : SimpleType.arraycopy(), out of bounds."); |
|---|
| | 12 | //Util.trace("Error : SimpleType.arraycopy(), out of bounds."); |
|---|
| 13 | 13 | assert(0); |
|---|
| 14 | 14 | } |
|---|
| r22 |
r23 |
|
| 90 | 90 | |
|---|
| 91 | 91 | public void getChars( char[] src, int srcBegin, int srcEnd, char[] dst, int dstBegin){ |
|---|
| 92 | | dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = str[ srcBegin .. srcEnd ]; |
|---|
| | 92 | dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = src[ srcBegin .. srcEnd ]; |
|---|
| 93 | 93 | } |
|---|
| 94 | 94 | |
|---|
| r18 |
r23 |
|
| 8 | 8 | * Contributors: |
|---|
| 9 | 9 | * IBM Corporation - initial API and implementation |
|---|
| | 10 | * Port to the D programming language: |
|---|
| | 11 | * Frank Benoit <benoit@tionex.de> |
|---|
| 10 | 12 | *******************************************************************************/ |
|---|
| 11 | 13 | module dwt.graphics.Color; |
|---|
| r19 |
r23 |
|
| 8 | 8 | * Contributors: |
|---|
| 9 | 9 | * IBM Corporation - initial API and implementation |
|---|
| | 10 | * Port to the D programming language: |
|---|
| | 11 | * Frank Benoit <benoit@tionex.de> |
|---|
| 10 | 12 | *******************************************************************************/ |
|---|
| 11 | 13 | module dwt.graphics.Device; |
|---|
| r15 |
r23 |
|
| 1 | | /******************************************************************************* |
|---|
| | 1 | /******************************************************************************* |
|---|
| 2 | 2 | * Copyright (c) 2000, 2006 IBM Corporation and others. |
|---|
| 3 | 3 | * All rights reserved. This program and the accompanying materials |
|---|
| … | … | |
| 8 | 8 | * Contributors: |
|---|
| 9 | 9 | * IBM Corporation - initial API and implementation |
|---|
| | 10 | * Port to the D programming language: |
|---|
| | 11 | * Frank Benoit <benoit@tionex.de> |
|---|
| 10 | 12 | *******************************************************************************/ |
|---|
| 11 | 13 | module dwt.graphics.Font; |
|---|
| … | … | |
| 19 | 21 | import dwt.graphics.Resource; |
|---|
| 20 | 22 | import dwt.graphics.FontData; |
|---|
| 21 | | import dwt.graphics.Device; |
|---|
| | 23 | import dwt.graphics.Device; |
|---|
| 22 | 24 | |
|---|
| 23 | 25 | import tango.text.convert.Format; |
|---|
| 24 | | //import tango.stdc.stringz; |
|---|
| | 26 | //import tango.stdc.stringz; |
|---|
| 25 | 27 | |
|---|
| 26 | 28 | /** |
|---|
| … | … | |
| 30 | 32 | * or a <code>FontData</code> object which encapsulates this data. |
|---|
| 31 | 33 | * <p> |
|---|
| 32 | | * Application code must explicitly invoke the <code>Font.dispose()</code> |
|---|
| | 34 | * Application code must explicitly invoke the <code>Font.dispose()</code> |
|---|
| 33 | 35 | * method to release the operating system resources managed by each instance |
|---|
| 34 | 36 | * when those instances are no longer required. |
|---|
| … | … | |
| 39 | 41 | |
|---|
| 40 | 42 | public final class Font : Resource { |
|---|
| 41 | | |
|---|
| | 43 | |
|---|
| 42 | 44 | /** |
|---|
| 43 | 45 | * the handle to the OS font resource |
|---|
| … | … | |
| 51 | 53 | */ |
|---|
| 52 | 54 | public HFONT handle; |
|---|
| 53 | | |
|---|
| | 55 | |
|---|
| 54 | 56 | /** |
|---|
| 55 | 57 | * Prevents uninitialized instances from being created outside the package. |
|---|
| … | … | |
| 58 | 60 | } |
|---|
| 59 | 61 | |
|---|
| 60 | | /** |
|---|
| | 62 | /** |
|---|
| 61 | 63 | * Constructs a new font given a device and font data |
|---|
| 62 | 64 | * which describes the desired font's appearance. |
|---|
| 63 | 65 | * <p> |
|---|
| 64 | | * You must dispose the font when it is no longer required. |
|---|
| | 66 | * You must dispose the font when it is no longer required. |
|---|
| 65 | 67 | * </p> |
|---|
| 66 | 68 | * |
|---|
| 67 | 69 | * @param device the device to create the font on |
|---|
| 68 | 70 | * @param fd the FontData that describes the desired font (must not be null) |
|---|
| 69 | | * |
|---|
| | 71 | * |
|---|
| 70 | 72 | * @exception IllegalArgumentException <ul> |
|---|
| 71 | 73 | * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> |
|---|
| … | … | |
| 80 | 82 | if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
|---|
| 81 | 83 | init(device, fd); |
|---|
| 82 | | if (device.tracking) device.new_Object(this); |
|---|
| 83 | | } |
|---|
| 84 | | |
|---|
| 85 | | /** |
|---|
| | 84 | if (device.tracking) device.new_Object(this); |
|---|
| | 85 | } |
|---|
| | 86 | |
|---|
| | 87 | /** |
|---|
| 86 | 88 | * Constructs a new font given a device and an array |
|---|
| 87 | 89 | * of font data which describes the desired font's |
|---|
| 88 | 90 | * appearance. |
|---|
| 89 | 91 | * <p> |
|---|
| 90 | | * You must dispose the font when it is no longer required. |
|---|
| | 92 | * You must dispose the font when it is no longer required. |
|---|
| 91 | 93 | * </p> |
|---|
| 92 | 94 | * |
|---|
| 93 | 95 | * @param device the device to create the font on |
|---|
| 94 | 96 | * @param fds the array of FontData that describes the desired font (must not be null) |
|---|
| 95 | | * |
|---|
| | 97 | * |
|---|
| 96 | 98 | * @exception IllegalArgumentException <ul> |
|---|
| 97 | 99 | * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> |
|---|
| … | … | |
| 103 | 105 | * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li> |
|---|
| 104 | 106 | * </ul> |
|---|
| 105 | | * |
|---|
| | 107 | * |
|---|
| 106 | 108 | * @since 2.1 |
|---|
| 107 | 109 | */ |
|---|
| … | … | |
| 115 | 117 | } |
|---|
| 116 | 118 | init(device, fds[0]); |
|---|
| 117 | | if (device.tracking) device.new_Object(this); |
|---|
| 118 | | } |
|---|
| 119 | | |
|---|
| 120 | | /** |
|---|
| | 119 | if (device.tracking) device.new_Object(this); |
|---|
| | 120 | } |
|---|
| | 121 | |
|---|
| | 122 | /** |
|---|
| 121 | 123 | * Constructs a new font given a device, a font name, |
|---|
| 122 | 124 | * the height of the desired font in points, and a font |
|---|
| 123 | 125 | * style. |
|---|
| 124 | 126 | * <p> |
|---|
| 125 | | * You must dispose the font when it is no longer required. |
|---|
| | 127 | * You must dispose the font when it is no longer required. |
|---|
| 126 | 128 | * </p> |
|---|
| 127 | 129 | * |
|---|
| … | … | |
| 130 | 132 | * @param height the font height in points |
|---|
| 131 | 133 | * @param style a bit or combination of NORMAL, BOLD, ITALIC |
|---|
| 132 | | * |
|---|
| | 134 | * |
|---|
| 133 | 135 | * @exception IllegalArgumentException <ul> |
|---|
| 134 | 136 | * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> |
|---|
| … | … | |
| 145 | 147 | if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
|---|
| 146 | 148 | init(device, new FontData (name, height, style)); |
|---|
| 147 | | if (device.tracking) device.new_Object(this); |
|---|
| | 149 | if (device.tracking) device.new_Object(this); |
|---|
| 148 | 150 | } |
|---|
| 149 | 151 | |
|---|
| … | … | |
| 153 | 155 | if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
|---|
| 154 | 156 | init(device, new FontData (name, height, style)); |
|---|
| 155 | | if (device.tracking) device.new_Object(this); |
|---|
| | 157 | if (device.tracking) device.new_Object(this); |
|---|
| 156 | 158 | } |
|---|
| 157 | 159 | |
|---|
| … | … | |
| 190 | 192 | /** |
|---|
| 191 | 193 | * Returns an array of <code>FontData</code>s representing the receiver. |
|---|
| 192 | | * On Windows, only one FontData will be returned per font. On X however, |
|---|
| 193 | | * a <code>Font</code> object <em>may</em> be composed of multiple X |
|---|
| | 194 | * On Windows, only one FontData will be returned per font. On X however, |
|---|
| | 195 | * a <code>Font</code> object <em>may</em> be composed of multiple X |
|---|
| 194 | 196 | * fonts. To support this case, we return an array of font data objects. |
|---|
| 195 | 197 | * |
|---|
| … | … | |
| 208 | 210 | |
|---|
| 209 | 211 | /** |
|---|
| 210 | | * Returns an integer hash code for the receiver. Any two |
|---|
| 211 | | * objects that return <code>true</code> when passed to |
|---|
| | 212 | * Returns an integer hash code for the receiver. Any two |
|---|
| | 213 | * objects that return <code>true</code> when passed to |
|---|
| 212 | 214 | * <code>equals</code> must return the same value for this |
|---|
| 213 | 215 | * method. |
|---|
| … | … | |
| 257 | 259 | } |
|---|
| 258 | 260 | |
|---|
| 259 | | /** |
|---|
| | 261 | /** |
|---|
| 260 | 262 | * Invokes platform specific functionality to allocate a new font. |
|---|
| 261 | 263 | * <p> |
|---|
| r17 |
r23 |
|
| 1 | | /******************************************************************************* |
|---|
| | 1 | /******************************************************************************* |
|---|
| 2 | 2 | * Copyright (c) 2000, 2007 IBM Corporation and others. |
|---|
| 3 | 3 | * All rights reserved. This program and the accompanying materials |
|---|
| … | … | |
| 8 | 8 | * Contributors: |
|---|
| 9 | 9 | * IBM Corporation - initial API and implementation |
|---|
| | 10 | * Port to the D programming language: |
|---|
| | 11 | * Frank Benoit <benoit@tionex.de> |
|---|
| 10 | 12 | *******************************************************************************/ |
|---|
| 11 | 13 | module dwt.graphics.FontData; |
|---|
| … | … | |
| 53 | 55 | |
|---|
| 54 | 56 | public final class FontData { |
|---|
| 55 | | |
|---|
| | 57 | |
|---|
| 56 | 58 | /** |
|---|
| 57 | 59 | * A Win32 LOGFONT struct |
|---|
| … | … | |
| 65 | 67 | */ |
|---|
| 66 | 68 | public LOGFONT data; |
|---|
| 67 | | |
|---|
| | 69 | |
|---|
| 68 | 70 | /** |
|---|
| 69 | 71 | * The height of the font data in points |
|---|
| … | … | |
| 85 | 87 | private static FontData s_this; |
|---|
| 86 | 88 | |
|---|
| 87 | | /** |
|---|
| | 89 | /** |
|---|
| 88 | 90 | * Constructs a new uninitialized font data. |
|---|
| 89 | 91 | */ |
|---|
| … | … | |
| 99 | 101 | * Constructs a new font data given the Windows <code>LOGFONT</code> |
|---|
| 100 | 102 | * that it should represent. |
|---|
| 101 | | * |
|---|
| | 103 | * |
|---|
| 102 | 104 | * @param data the <code>LOGFONT</code> for the result |
|---|
| 103 | 105 | */ |
|---|
| … | … | |
| 113 | 115 | * <p> |
|---|
| 114 | 116 | * Note that the representation varies between platforms, |
|---|
| 115 | | * and a FontData can only be created from a string that was |
|---|
| | 117 | * and a FontData can only be created from a string that was |
|---|
| 116 | 118 | * generated on the same platform. |
|---|
| 117 | 119 | * </p> |
|---|
| … | … | |
| 133 | 135 | char[] version1 = string.substring(start, end); |
|---|
| 134 | 136 | try { |
|---|
| 135 | | if (Integer.parseInt(version1) !is 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
|---|
| | 137 | if (Integer.parseInt(version1) !is 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
|---|
| 136 | 138 | } catch (NumberFormatException e) { |
|---|
| 137 | 139 | DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
|---|
| 138 | 140 | } |
|---|
| 139 | | |
|---|
| | 141 | |
|---|
| 140 | 142 | start = end + 1; |
|---|
| 141 | 143 | end = string.indexOf('|', start); |
|---|
| 142 | 144 | if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
|---|
| 143 | 145 | char[] name = string.substring(start, end); |
|---|
| 144 | | |
|---|
| | 146 | |
|---|
| 145 | 147 | start = end + 1; |
|---|
| 146 | 148 | end = string.indexOf('|', start); |
|---|
| … | … | |
| 152 | 154 | DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
|---|
| 153 | 155 | } |
|---|
| 154 | | |
|---|
| | 156 | |
|---|
| 155 | 157 | start = end + 1; |
|---|
| 156 | 158 | end = string.indexOf('|', start); |
|---|
| … | … | |
| 247 | 249 | } |
|---|
| 248 | 250 | |
|---|
| 249 | | /** |
|---|
| | 251 | /** |
|---|
| 250 | 252 | * Constructs a new font data given a font name, |
|---|
| 251 | | * the height of the desired font in points, |
|---|
| | 253 | * the height of the desired font in points, |
|---|
| 252 | 254 | * and a font style. |
|---|
| 253 | 255 | * |
|---|
| … | … | |
| 302 | 304 | * a FontData, lfHeight is not necessarily set. Instead |
|---|
| 303 | 305 | * we check the height field which is always set. |
|---|
| 304 | | */ |
|---|
| | 306 | */ |
|---|
| 305 | 307 | // data.lfHeight is lf.lfHeight && |
|---|
| 306 | 308 | height is fd.height && |
|---|
| … | … | |
| 383 | 385 | * locale will determine the character set. |
|---|
| 384 | 386 | * </p> |
|---|
| 385 | | * |
|---|
| | 387 | * |
|---|
| 386 | 388 | * @return the <code>String</code> representing a Locale object |
|---|
| 387 | 389 | * @since 3.0 |
|---|
| … | … | |
| 401 | 403 | buffer.append (variant); |
|---|
| 402 | 404 | } |
|---|
| 403 | | |
|---|
| | 405 | |
|---|
| 404 | 406 | char[] result = buffer.toString (); |
|---|
| 405 | 407 | int length_ = result.length; |
|---|
| … | … | |
| 408 | 410 | result = result.substring (0, length_ - 1); |
|---|
| 409 | 411 | } |
|---|
| 410 | | } |
|---|
| | 412 | } |
|---|
| 411 | 413 | return result; |
|---|
| 412 | 414 | } |
|---|
| … | … | |
| 426 | 428 | |
|---|
| 427 | 429 | /** |
|---|
| 428 | | * Returns the style of the receiver which is a bitwise OR of |
|---|
| | 430 | * Returns the style of the receiver which is a bitwise OR of |
|---|
| 429 | 431 | * one or more of the <code>DWT</code> constants NORMAL, BOLD |
|---|
| 430 | 432 | * and ITALIC. |
|---|
| 431 | 433 | * |
|---|
| 432 | 434 | * @return the style of this <code>FontData</code> |
|---|
| 433 | | * |
|---|
| | 435 | * |
|---|
| 434 | 436 | * @see #setStyle |
|---|
| 435 | 437 | */ |
|---|
| … | … | |
| 442 | 444 | |
|---|
| 443 | 445 | /** |
|---|
| 444 | | * Returns an integer hash code for the receiver. Any two |
|---|
| 445 | | * objects that return <code>true</code> when passed to |
|---|
| | 446 | * Returns an integer hash code for the receiver. Any two |
|---|
| | 447 | * objects that return <code>true</code> when passed to |
|---|
| 446 | 448 | * <code>equals</code> must return the same value for this |
|---|
| 447 | 449 | * method. |
|---|
| … | … | |
| 470 | 472 | * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> |
|---|
| 471 | 473 | * </ul> |
|---|
| 472 | | * |
|---|
| | 474 | * |
|---|
| 473 | 475 | * @see #getHeight |
|---|
| 474 | 476 | */ |
|---|
| … | … | |
| 496 | 498 | * locale will determine the character set. |
|---|
| 497 | 499 | * </p> |
|---|
| 498 | | * |
|---|
| | 500 | * |
|---|
| 499 | 501 | * @param locale the <code>String</code> representing a Locale object |
|---|
| 500 | 502 | * @see java.util.Locale#toString |
|---|
| 501 | 503 | */ |
|---|
| 502 | | public void setLocale(char[] locale) { |
|---|
| | 504 | public void setLocale(char[] locale) { |
|---|
| 503 | 505 | lang = country = variant = null; |
|---|
| 504 | 506 | if (locale !is null) { |
|---|
| … | … | |
| 506 | 508 | int length_ = locale.length; |
|---|
| 507 | 509 | int firstSep, secondSep; |
|---|
| 508 | | |
|---|
| | 510 | |
|---|
| 509 | 511 | firstSep = locale.indexOf(sep); |
|---|
| 510 | 512 | if (firstSep is -1) { |
|---|
| … | … | |
| 543 | 545 | * <p> |
|---|
| 544 | 546 | * On platforms that do not support font foundries, only the face name |
|---|
| 545 | | * (for example, "courier") is used in <code>setName()</code> and |
|---|
| | 547 | * (for example, "courier") is used in <code>setName()</code> and |
|---|
| 546 | 548 | * <code>getName()</code>. |
|---|
| 547 | 549 | * </p> |
|---|
| … | … | |
| 566 | 568 | /** |
|---|
| 567 | 569 | * Sets the style of the receiver to the argument which must |
|---|
| 568 | | * be a bitwise OR of one or more of the <code>DWT</code> |
|---|
| | 570 | * be a bitwise OR of one or more of the <code>DWT</code> |
|---|
| 569 | 571 | * constants NORMAL, BOLD and ITALIC. All other style bits are |
|---|
| 570 | 572 | * ignored. |
|---|
| … | … | |
| 589 | 591 | /** |
|---|
| 590 | 592 | * Returns a string representation of the receiver which is suitable |
|---|
| 591 | | * for constructing an equivalent instance using the |
|---|
| | 593 | * for constructing an equivalent instance using the |
|---|
| 592 | 594 | * <code>FontData(String)</code> constructor. |
|---|
| 593 | 595 | * |
|---|
| … | … | |
| 605 | 607 | buffer.append(to!(char[])(getStyle())); |
|---|
| 606 | 608 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| 607 | | buffer.append("WINDOWS|1|"); //$NON-NLS-1$ |
|---|
| | 609 | buffer.append("WINDOWS|1|"); //$NON-NLS-1$ |
|---|
| 608 | 610 | buffer.append(to!(char[])(data.lfHeight)); |
|---|
| 609 | 611 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| … | … | |
| 612 | 614 | buffer.append(to!(char[])(data.lfEscapement)); |
|---|
| 613 | 615 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| 614 | | buffer.append(to!(char[])(data.lfOrientation)); |
|---|
| 615 | | buffer.append("|"); //$NON-NLS-1$ |
|---|
| 616 | | buffer.append(to!(char[])(data.lfWeight)); |
|---|
| | 616 | buffer.append(to!(char[])(data.lfOrientation)); |
|---|
| | 617 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| | 618 | buffer.append(to!(char[])(data.lfWeight)); |
|---|
| 617 | 619 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| 618 | 620 | buffer.append(to!(char[])(data.lfItalic)); |
|---|
| … | … | |
| 620 | 622 | buffer.append(to!(char[])(data.lfUnderline)); |
|---|
| 621 | 623 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| 622 | | buffer.append(to!(char[])(data.lfStrikeOut)); |
|---|
| 623 | | buffer.append("|"); //$NON-NLS-1$ |
|---|
| 624 | | buffer.append(to!(char[])(data.lfCharSet)); |
|---|
| | 624 | buffer.append(to!(char[])(data.lfStrikeOut)); |
|---|
| | 625 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| | 626 | buffer.append(to!(char[])(data.lfCharSet)); |
|---|
| 625 | 627 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| 626 | 628 | buffer.append(to!(char[])(data.lfOutPrecision)); |
|---|
| 627 | 629 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| 628 | | buffer.append(to!(char[])(data.lfClipPrecision)); |
|---|
| 629 | | buffer.append("|"); //$NON-NLS-1$ |
|---|
| 630 | | buffer.append(to!(char[])(data.lfQuality)); |
|---|
| | 630 | buffer.append(to!(char[])(data.lfClipPrecision)); |
|---|
| | 631 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| | 632 | buffer.append(to!(char[])(data.lfQuality)); |
|---|
| 631 | 633 | buffer.append("|"); //$NON-NLS-1$ |
|---|
| 632 | 634 | buffer.append(to!(char[])(data.lfPitchAndFamily)); |
|---|
| … | … | |
| 636 | 638 | } |
|---|
| 637 | 639 | |
|---|
| 638 | | /** |
|---|
| | 640 | /** |
|---|
| 639 | 641 | * Invokes platform specific functionality to allocate a new font data. |
|---|
| 640 | 642 | * <p> |
|---|
| r16 |
r23 |
|
| 1 | | /******************************************************************************* |
|---|
| | 1 | /******************************************************************************* |
|---|
| 2 | 2 | * Copyright (c) 2000, 2005 IBM Corporation and others. |
|---|
| 3 | 3 | * All rights reserved. This program and the accompanying materials |
|---|
| … | … | |
| 8 | 8 | * Contributors: |
|---|
| 9 | 9 | * IBM Corporation - initial API and implementation |
|---|
| | 10 | * Port to the D programming language: |
|---|
| | 11 | * Frank Benoit <benoit@tionex.de> |
|---|
| 10 | 12 | *******************************************************************************/ |
|---|
| 11 | 13 | module dwt.graphics.FontMetrics; |
|---|
| … | … | |
| 23 | 25 | * @see GC#getFontMetrics |
|---|
| 24 | 26 | */ |
|---|
| 25 | | |
|---|
| | 27 | |
|---|
| 26 | 28 | public final class FontMetrics { |
|---|
| 27 | | |
|---|
| | 29 | |
|---|
| 28 | 30 | /** |
|---|
| 29 | 31 | * On Windows, handle is a Win32 TEXTMETRIC struct |
|---|
| … | … | |
| 38 | 40 | */ |
|---|
| 39 | 41 | public TEXTMETRIC* handle; |
|---|
| 40 | | |
|---|
| | 42 | |
|---|
| 41 | 43 | /** |
|---|
| 42 | 44 | * Prevents instances from being created outside the package. |
|---|
| … | … | |
| 85 | 87 | /** |
|---|
| 86 | 88 | * Returns the ascent of the font described by the receiver. A |
|---|
| 87 | | * font's <em>ascent</em> is the distance from the baseline to the |
|---|
| | 89 | * font's <em>ascent</em> is the distance from the baseline to the |
|---|
| 88 | 90 | * top of actual characters, not including any of the leading area, |
|---|
| 89 | 91 | * measured in pixels. |
|---|
| … | … | |
| 118 | 120 | |
|---|
| 119 | 121 | /** |
|---|
| 120 | | * Returns the height of the font described by the receiver, |
|---|
| | 122 | * Returns the height of the font described by the receiver, |
|---|
| 121 | 123 | * measured in pixels. A font's <em>height</em> is the sum of |
|---|
| 122 | 124 | * its ascent, descent and leading area. |
|---|
| … | … | |
| 144 | 146 | |
|---|
| 145 | 147 | /** |
|---|
| 146 | | * Returns an integer hash code for the receiver. Any two |
|---|
| 147 | | * objects that return <code>true</code> when passed to |
|---|
| | 148 | * Returns an integer hash code for the receiver. Any two |
|---|
| | 149 | * objects that return <code>true</code> when passed to |
|---|
| 148 | 150 | * <code>equals</code> must return the same value for this |
|---|
| 149 | 151 | * method. |
|---|
| … | … | |
| 163 | 165 | } |
|---|
| 164 | 166 | |
|---|
| 165 | | /** |
|---|
| | 167 | /** |
|---|
| 166 | 168 | * Invokes platform specific functionality to allocate a new font metrics. |
|---|
| 167 | 169 | * <p> |
|---|
| r22 |
r23 |
|
| 8 | 8 | * Contributors: |
|---|
| 9 | 9 | * IBM Corporation - initial API and implementation |
|---|
| | 10 | * Port to the D programming language: |
|---|
| | 11 | * Frank Benoit <benoit@tionex.de> |
|---|
| 10 | 12 | *******************************************************************************/ |
|---|
| 11 | 13 | module dwt.graphics.GC; |
|---|
| 12 | 14 | |
|---|
| | 15 | import dwt.graphics.GCData; |
|---|
| | 16 | import dwt.graphics.Image; |
|---|
| | 17 | import dwt.internal.win32.WINTYPES; |
|---|
| | 18 | |
|---|
| 13 | 19 | //PORTING_TYPE |
|---|
| 14 | 20 | class GC{ |
|---|
| | 21 | void dispose(); |
|---|
| | 22 | bool isDisposed(); |
|---|
| | 23 | void flush (); |
|---|
| | 24 | GCData data; |
|---|
| | 25 | HDC handle; |
|---|
| | 26 | public void drawImage(Image image, int x, int y) ; |
|---|
| | 27 | public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) ; |
|---|
| | 28 | void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, bool simple) ; |
|---|
| 15 | 29 | } |
|---|
| 16 | 30 | |
|---|
| r11 |
r23 |
|
| 1 | | /******************************************************************************* |
|---|
| | 1 | /******************************************************************************* |
|---|
| 2 | 2 | * Copyright (c) 2000, 2007 IBM Corporation and others. |
|---|
| 3 | 3 | * All rights reserved. This program and the accompanying materials |
|---|
| … | … | |
| 13 | 13 | module dwt.graphics.GCData; |
|---|
| 14 | 14 | |
|---|
| 15 | | |
|---|
| | 15 | |
|---|
| 16 | 16 | import dwt.DWT; |
|---|
| 17 | 17 | import dwt.internal.win32.WINTYPES; |
|---|
| | 18 | import dwt.graphics.Image; |
|---|
| | 19 | import dwt.graphics.Device; |
|---|
| 18 | 20 | |
|---|
| 19 | 21 | //PORTING_TYPE |
|---|
| 20 | 22 | class GCData { |
|---|
| | 23 | HBITMAP hNullBitmap; |
|---|
| | 24 | int style; |
|---|
| | 25 | int layout; |
|---|
| | 26 | Device device; |
|---|
| | 27 | Image image; |
|---|
| | 28 | HFONT hFont; |
|---|
| 21 | 29 | } |
|---|
| 22 | 30 | /+++ |
|---|
| r22 |
r23 |
|
| 8 | 8 | * Contributors: |
|---|
| 9 | 9 | * IBM Corporation - initial API and implementation |
|---|
| | 10 | * Port to the D programming language: |
|---|
| | 11 | * Frank Benoit <benoit@tionex.de> |
|---|
| 10 | 12 | *******************************************************************************/ |
|---|
| 11 | 13 | module dwt.graphics.Image; |
|---|
| … | … | |
| 786 | 788 | if (isDirect) bmi = new byte[BITMAPINFOHEADER.sizeof + (useBitfields ? 12 : 0)]; |
|---|
| 787 | 789 | else bmi = new byte[BITMAPINFOHEADER.sizeof + rgbs.length * 4]; |
|---|
| 788 | | bmi[ 0 .. BITMAPINFOHEADER.sizeof ] = (cast(byte*)&bmiHeader)[ 0 .. BITMAPINFOHEADER.sizeof ]; |
|---|
| 789 | | //OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof); |
|---|
| | 790 | *cast(BITMAPINFOHEADER*)bmi.ptr = bmiHeader; |
|---|
| 790 | 791 | |
|---|
| 791 | 792 | /* Set the rgb colors into the bitmap info */ |
|---|
| … | … | |
| 979 | 980 | int imgWidth = bm.bmWidth; |
|---|
| 980 | 981 | int imgHeight = hBitmap is iconInfo.hbmMask ? bm.bmHeight / 2 : bm.bmHeight; |
|---|
| 981 | | int img = 0, pixels = 0; |
|---|
| | 982 | Gdip.Bitmap* img; |
|---|
| | 983 | byte* pixels; |
|---|
| 982 | 984 | if (imgWidth > imgHeight) { |
|---|
| 983 | 985 | auto hDC = device.internal_new_GC(null); |
|---|
| … | … | |
| 993 | 995 | OS.SelectObject(memHdc, oldMemBitmap); |
|---|
| 994 | 996 | OS.DeleteObject(memHdc); |
|---|
| 995 | | byte[] srcData = new byte[dibBM.bmWidthBytes * dibBM.bmHeight]; |
|---|
| 996 | | OS.MoveMemory(srcData, dibBM.bmBits, srcData.length); |
|---|
| | 997 | byte[] srcData = (cast(byte*)dibBM.bmBits)[ 0 .. dibBM.bmWidthBytes * dibBM.bmHeight].dup; |
|---|
| 997 | 998 | OS.DeleteObject(memDib); |
|---|
| 998 | 999 | OS.SelectObject(srcHdc, iconInfo.hbmMask); |
|---|
| … | … | |
| 1010 | 1011 | OS.DeleteObject(srcHdc); |
|---|
| 1011 | 1012 | device.internal_dispose_GC(hDC, null); |
|---|
| 1012 | | int hHeap = OS.GetProcessHeap(); |
|---|
| 1013 | | pixels = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, srcData.length); |
|---|
| 1014 | | if (pixels is 0) DWT.error(DWT.ERROR_NO_HANDLES); |
|---|
| 1015 | | OS.MoveMemory(pixels, srcData, srcData.length); |
|---|
| | 1013 | auto hHeap = OS.GetProcessHeap(); |
|---|
| | 1014 | pixels = cast(byte*) OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, srcData.length); |
|---|
| | 1015 | if (pixels is null) DWT.error(DWT.ERROR_NO_HANDLES); |
|---|
| | 1016 | pixels[ 0 .. srcData.length ] = srcData[]; |
|---|
| 1016 | 1017 | img = Gdip.Bitmap_new(imgWidth, imgHeight, dibBM.bmWidthBytes, Gdip.PixelFormat32bppARGB, pixels); |
|---|
| 1017 | 1018 | } else { |
|---|
| 1018 | 1019 | img = Gdip.Bitmap_new(handle); |
|---|
| 1019 | 1020 | } |
|---|
| 1020 | | if (iconInfo.hbmColor !is 0) OS.DeleteObject(iconInfo.hbmColor); |
|---|
| 1021 | | if (iconInfo.hbmMask !is 0) OS.DeleteObject(iconInfo.hbmMask); |
|---|
| 1022 | | return [img, pixels]; |
|---|
| | 1021 | if (iconInfo.hbmColor !is null) OS.DeleteObject(iconInfo.hbmColor); |
|---|
| | 1022 | if (iconInfo.hbmMask !is null) OS.DeleteObject(iconInfo.hbmMask); |
|---|
| | 1023 | return [ cast(int)img, cast(int) pixels ]; |
|---|
| 1023 | 1024 | } |
|---|
| 1024 | 1025 | default: DWT.error(DWT.ERROR_INVALID_IMAGE); |
|---|
| … | … | |
| 1091 | 1092 | |
|---|
| 1092 | 1093 | /* Compute the background color */ |
|---|
| 1093 | | BITMAP bm = new BITMAP(); |
|---|
| 1094 | | OS.GetObject(handle, BITMAP.sizeof, bm); |
|---|
| | 1094 | BITMAP bm; |
|---|
| | 1095 | OS.GetObject(handle, BITMAP.sizeof, &bm); |
|---|
| 1095 | 1096 | auto hdcMem = OS.CreateCompatibleDC(hDC); |
|---|
| 1096 | 1097 | auto hOldObject = OS.SelectObject(hdcMem, handle); |
|---|
| … | … | |
| 1098 | 1099 | if (bm.bmBitsPixel <= 8) { |
|---|
| 1099 | 1100 | if (OS.IsWinCE) { |
|---|
| 1100 | | byte[] pBits = new byte[1]; |
|---|
| 1101 | | OS.MoveMemory(pBits, bm.bmBits, 1); |
|---|
| | 1101 | byte* pBits = cast(byte*)bm.bmBits; |
|---|
| | 1102 | //OS.MoveMemory(pBits, bm.bmBits, 1); |
|---|
| 1102 | 1103 | byte oldValue = pBits[0]; |
|---|
| 1103 | 1104 | int mask = (0xFF << (8 - bm.bmBitsPixel)) & 0x00FF; |
|---|
| 1104 | 1105 | pBits[0] = cast(byte)((transparentPixel << (8 - bm.bmBitsPixel)) | (pBits[0] & ~mask)); |
|---|
| 1105 | | OS.MoveMemory(bm.bmBits, pBits, 1); |
|---|
| | 1106 | //OS.MoveMemory(bm.bmBits, bm.bmBits, 1); |
|---|
| 1106 | 1107 | int color = OS.GetPixel(hdcMem, 0, 0); |
|---|
| 1107 | 1108 | pBits[0] = oldValue; |
|---|
| 1108 | | OS.MoveMemory(bm.bmBits, pBits, 1); |
|---|
| | 1109 | //OS.MoveMemory(bm.bmBits, bm.bmBits, 1); |
|---|
| 1109 | 1110 | blue = (color & 0xFF0000) >> 16; |
|---|
| 1110 | 1111 | green = (color & 0xFF00) >> 8; |
|---|
| 1111 | 1112 | red = color & 0xFF; |
|---|
| 1112 | 1113 | } else { |
|---|
| 1113 | | byte[] color = new byte[4]; |
|---|
| 1114 | | OS.GetDIBColorTable(hdcMem, transparentPixel, 1, color); |
|---|
| 1115 | | blue = color[0] & 0xFF; |
|---|
| 1116 | | green = color[1] & 0xFF; |
|---|
| 1117 | | red = color[2] & 0xFF; |
|---|
| | 1114 | RGBQUAD color; |
|---|
| | 1115 | OS.GetDIBColorTable(hdcMem, transparentPixel, 1, &color); |
|---|
| | 1116 | blue = color.rgbBlue; |
|---|
| | 1117 | green = color.rgbGreen; |
|---|
| | 1118 | red = color.rgbRed; |
|---|
| 1118 | 1119 | } |
|---|
| 1119 | 1120 | } else { |
|---|
| … | … | |
| 1165 | 1166 | switch (type) { |
|---|
| 1166 | 1167 | case DWT.BITMAP: |
|---|
| 1167 | | BITMAP bm = new BITMAP(); |
|---|
| 1168 | | OS.GetObject(handle, BITMAP.sizeof, bm); |
|---|
| | 1168 | BITMAP bm; |
|---|
| | 1169 | OS.GetObject(handle, BITMAP.sizeof, &bm); |
|---|
| 1169 | 1170 | return new Rectangle(0, 0, width = bm.bmWidth, height = bm.bmHeight); |
|---|
| 1170 | 1171 | case DWT.ICON: |
|---|
| … | … | |
| 1172 | 1173 | return new Rectangle(0, 0, width = data.width, height = data.height); |
|---|
| 1173 | 1174 | } else { |
|---|
| 1174 | | ICONINFO info = new ICONINFO(); |
|---|
| 1175 | | OS.GetIconInfo(handle, info); |
|---|
| 1176 | | int hBitmap = info.hbmColor; |
|---|
| 1177 | | if (hBitmap is 0) hBitmap = info.hbmMask; |
|---|
| 1178 | | bm = new BITMAP(); |
|---|
| 1179 | | OS.GetObject(hBitmap, BITMAP.sizeof, bm); |
|---|
| | 1175 | ICONINFO info; |
|---|
| | 1176 | OS.GetIconInfo(handle, &info); |
|---|
| | 1177 | auto hBitmap = info.hbmColor; |
|---|
| | 1178 | if (hBitmap is null) hBitmap = info.hbmMask; |
|---|
| | 1179 | BITMAP bm; |
|---|
| | 1180 | OS.GetObject(hBitmap, BITMAP.sizeof, &bm); |
|---|
| 1180 | 1181 | if (hBitmap is info.hbmMask) bm.bmHeight /= 2; |
|---|
| 1181 | | if (info.hbmColor !is 0) OS.DeleteObject(info.hbmColor); |
|---|
| 1182 | | if (info.hbmMask !is 0) OS.DeleteObject(info.hbmMask); |
|---|
| | 1182 | if (info.hbmColor !is null) OS.DeleteObject(info.hbmColor); |
|---|
| | 1183 | if (info.hbmMask !is null) OS.DeleteObject(info.hbmMask); |
|---|
| 1183 | 1184 | return new Rectangle(0, 0, width = bm.bmWidth, height = bm.bmHeight); |
|---|
| 1184 | 1185 | } |
|---|
| … | … | |
| 1210 | 1211 | case DWT.ICON: { |
|---|
| 1211 | 1212 | if (OS.IsWinCE) return data; |
|---|
| 1212 | | ICONINFO info = new ICONINFO(); |
|---|
| | 1213 | ICONINFO info; |
|---|
| 1213 | 1214 | if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); |
|---|
| 1214 | | OS.GetIconInfo(handle, info); |
|---|
| | 1215 | OS.GetIconInfo(handle, &info); |
|---|
| 1215 | 1216 | /* Get the basic BITMAP information */ |
|---|
| 1216 | | int hBitmap = info.hbmColor; |
|---|
| 1217 | | if (hBitmap is 0) hBitmap = info.hbmMask; |
|---|
| 1218 | | bm = new BITMAP(); |
|---|
| 1219 | | OS.GetObject(hBitmap, BITMAP.sizeof, bm); |
|---|
| | 1217 | auto hBitmap = info.hbmColor; |
|---|
| | 1218 | if (hBitmap is null) hBitmap = info.hbmMask; |
|---|
| | 1219 | OS.GetObject(hBitmap, BITMAP.sizeof, &bm); |
|---|
| 1220 | 1220 | depth = bm.bmPlanes * bm.bmBitsPixel; |
|---|
| 1221 | 1221 | width = bm.bmWidth; |
|---|
| … | … | |
| 1225 | 1225 | if (depth <= 8) numColors = 1 << depth; |
|---|
| 1226 | 1226 | /* Create the BITMAPINFO */ |
|---|
| 1227 | | BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER(); |
|---|
| | 1227 | BITMAPINFOHEADER bmiHeader; |
|---|
| 1228 | 1228 | bmiHeader.biSize = BITMAPINFOHEADER.sizeof; |
|---|
| 1229 | 1229 | bmiHeader.biWidth = width; |
|---|
| … | … | |
| 1233 | 1233 | bmiHeader.biCompression = OS.BI_RGB; |
|---|
| 1234 | 1234 | byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + numColors * 4]; |
|---|
| 1235 | | OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof); |
|---|
| | 1235 | *cast(BITMAPINFOHEADER*)bmi.ptr = bmiHeader; |
|---|
| 1236 | 1236 | |
|---|
| 1237 | 1237 | /* Get the HDC for the device */ |
|---|
| … | … | |
| 1242 | 1242 | auto hOldBitmap = OS.SelectObject(hBitmapDC, hBitmap); |
|---|
| 1243 | 1243 | /* Select the palette if necessary */ |
|---|
| 1244 | | int oldPalette = 0; |
|---|
| | 1244 | HPALETTE oldPalette; |
|---|
| 1245 | 1245 | if (depth <= 8) { |
|---|
| 1246 | | int hPalette = device.hPalette; |
|---|
| 1247 | | if (hPalette !is 0) { |
|---|
| | 1246 | auto hPalette = device.hPalette; |
|---|
| | 1247 | if (hPalette !is null) { |
|---|
| 1248 | 1248 | oldPalette = OS.SelectPalette(hBitmapDC, hPalette, false); |
|---|
| 1249 | 1249 | OS.RealizePalette(hBitmapDC); |
|---|
| … | … | |
| 1254 | 1254 | /* Call with null lpBits to get the image size */ |
|---|
| 1255 | 1255 | if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); |
|---|
| 1256 | | OS.GetDIBits(hBitmapDC, hBitmap, 0, height, 0, bmi, OS.DIB_RGB_COLORS); |
|---|
| 1257 | | OS.MoveMemory(bmiHeader, bmi, BITMAPINFOHEADER.sizeof); |
|---|
| | 1256 | OS.GetDIBits(hBitmapDC, hBitmap, 0, height, null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS); |
|---|
| | 1257 | bmiHeader = *cast(BITMAPINFOHEADER*)bmi.ptr; |
|---|
| 1258 | 1258 | imageSize = bmiHeader.biSizeImage; |
|---|
| 1259 | | byte[] data = new byte[imageSize]; |
|---|
| 1260 | 1259 | /* Get the bitmap data */ |
|---|
| 1261 | | int hHeap = OS.GetProcessHeap(); |
|---|
| 1262 | | int lpvBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, imageSize); |
|---|
| 1263 | | if (lpvBits is 0) DWT.error(DWT.ERROR_NO_HANDLES); |
|---|
| | 1260 | auto hHeap = OS.GetProcessHeap(); |
|---|
| | 1261 | auto lpvBits = cast(byte*) OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, imageSize); |
|---|
| | 1262 | if (lpvBits is null) DWT.error(DWT.ERROR_NO_HANDLES); |
|---|
| 1264 | 1263 | if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); |
|---|
| 1265 | | OS.GetDIBits(hBitmapDC, hBitmap, 0, height, lpvBits, bmi, OS.DIB_RGB_COLORS); |
|---|
| 1266 | | OS.MoveMemory(data, lpvBits, imageSize); |
|---|
| | 1264 | OS.GetDIBits(hBitmapDC, hBitmap, 0, height, lpvBits, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS); |
|---|
| | 1265 | byte[] data = lpvBits[ 0 .. imageSize].dup; /*PORTING_OPTIMIZE?*/ |
|---|
| 1267 | 1266 | /* Calculate the palette */ |
|---|
| 1268 | 1267 | PaletteData palette = null; |
|---|
| … | … | |
| 1287 | 1286 | /* Do the mask */ |
|---|
| 1288 | 1287 | byte [] maskData = null; |
|---|
| 1289 | | if (info.hbmColor is 0) { |
|---|
| | 1288 | if (info.hbmColor is null) { |
|---|
| 1290 | 1289 | /* Do the bottom half of the mask */ |
|---|
| 1291 | | maskData = new byte[imageSize]; |
|---|
| 1292 | 1290 | if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); |
|---|
| 1293 | | OS.GetDIBits(hBitmapDC, hBitmap, height, height, lpvBits, bmi, OS.DIB_RGB_COLORS); |
|---|
| 1294 | | OS.MoveMemory(maskData, lpvBits, imageSize); |
|---|
| | 1291 | OS.GetDIBits(hBitmapDC, hBitmap, height, height, lpvBits, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS); |
|---|
| | 1292 | maskData = lpvBits[ 0 .. imageSize].dup; |
|---|
| 1295 | 1293 | } else { |
|---|
| 1296 | 1294 | /* Do the entire mask */ |
|---|
| 1297 | 1295 | /* Create the BITMAPINFO */ |
|---|
| 1298 | | bmiHeader = new BITMAPINFOHEADER(); |
|---|
| | 1296 | bmiHeader = BITMAPINFOHEADER.init; |
|---|
| 1299 | 1297 | bmiHeader.biSize = BITMAPINFOHEADER.sizeof; |
|---|
| 1300 | 1298 | bmiHeader.biWidth = width; |
|---|
| … | … | |
| 1304 | 1302 | bmiHeader.biCompression = OS.BI_RGB; |
|---|
| 1305 | 1303 | bmi = new byte[BITMAPINFOHEADER.sizeof + 8]; |
|---|
| 1306 | | OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof); |
|---|
| | 1304 | *cast(BITMAPINFOHEADER*)bmi.ptr = bmiHeader; |
|---|
| 1307 | 1305 | |
|---|
| 1308 | 1306 | /* First color black, second color white */ |
|---|
| … | … | |
| 1313 | 1311 | /* Call with null lpBits to get the image size */ |
|---|
| 1314 | 1312 | if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); |
|---|
| 1315 | | OS.GetDIBits(hBitmapDC, info.hbmMask, 0, height, 0, bmi, OS.DIB_RGB_COLORS); |
|---|
| 1316 | | OS.MoveMemory(bmiHeader, bmi, BITMAPINFOHEADER.sizeof); |
|---|
| | 1313 | OS.GetDIBits(hBitmapDC, info.hbmMask, 0, height, null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS); |
|---|
| | 1314 | bmiHeader = *cast(BITMAPINFOHEADER*)bmi.ptr; |
|---|
| 1317 | 1315 | imageSize = bmiHeader.biSizeImage; |
|---|
| 1318 | 1316 | maskData = new byte[imageSize]; |
|---|
| 1319 | | int lpvMaskBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, imageSize); |
|---|
| 1320 | | if (lpvMaskBits is 0) DWT.error(DWT.ERROR_NO_HANDLES); |
|---|
| | 1317 | auto lpvMaskBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, imageSize); |
|---|
| | 1318 | if (lpvMaskBits is null) DWT.error(DWT.ERROR_NO_HANDLES); |
|---|
| 1321 | 1319 | if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); |
|---|
| 1322 | | OS.GetDIBits(hBitmapDC, info.hbmMask, 0, height, lpvMaskBits, bmi, OS.DIB_RGB_COLORS); |
|---|
| 1323 | | OS.MoveMemory(maskData, lpvMaskBits, imageSize); |
|---|
| | 1320 | OS.GetDIBits(hBitmapDC, info.hbmMask, 0, height, lpvMaskBits, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS); |
|---|
| | 1321 | maskData[] = (cast(byte*)lpvMaskBits)[ 0 .. imageSize ]; |
|---|
| 1324 | 1322 | OS.HeapFree(hHeap, 0, lpvMaskBits); |
|---|
| 1325 | 1323 | /* Loop to invert the mask */ |
|---|
| … | … | |
| 1339 | 1337 | OS.HeapFree(hHeap, 0, lpvBits); |
|---|
| 1340 | 1338 | OS.SelectObject(hBitmapDC, hOldBitmap); |
|---|
| 1341 | | if (oldPalette !is 0) { |
|---|
| | 1339 | if (oldPalette !is null) { |
|---|
| 1342 | 1340 | OS.SelectPalette(hBitmapDC, oldPalette, false); |
|---|
| 1343 | 1341 | OS.RealizePalette(hBitmapDC); |
|---|
| … | … | |
| 1348 | 1346 | device.internal_dispose_GC(hDC, null); |
|---|
| 1349 | 1347 | |
|---|
| 1350 | | if (info.hbmColor !is 0) OS.DeleteObject(info.hbmColor); |
|---|
| 1351 | | if (info.hbmMask !is 0) OS.DeleteObject(info.hbmMask); |
|---|
| | 1348 | if (info.hbmColor !is null) OS.DeleteObject(info.hbmColor); |
|---|
| | 1349 | if (info.hbmMask !is null) OS.DeleteObject(info.hbmMask); |
|---|
| 1352 | 1350 | /* Construct and return the ImageData */ |
|---|
| 1353 | 1351 | ImageData imageData = new ImageData(width, height, depth, palette, 4, data); |
|---|
| … | … | |
| 1358 | 1356 | case DWT.BITMAP: { |
|---|
| 1359 | 1357 | /* Get the basic BITMAP information */ |
|---|
| 1360 | | bm = new BITMAP(); |
|---|
| 1361 | | OS.GetObject(handle, BITMAP.sizeof, bm); |
|---|
| | 1358 | bm = BITMAP.init; |
|---|
| | 1359 | OS.GetObject(handle, BITMAP.sizeof, &bm); |
|---|
| 1362 | 1360 | depth = bm.bmPlanes * bm.bmBitsPixel; |
|---|
| 1363 | 1361 | width = bm.bmWidth; |
|---|
| 1364 | 1362 | height = bm.bmHeight; |
|---|
| 1365 | 1363 | /* Find out whether this is a DIB or a DDB. */ |
|---|
| 1366 | | bool isDib = (bm.bmBits !is 0); |
|---|
| | 1364 | bool isDib = (bm.bmBits !is null); |
|---|
| 1367 | 1365 | /* Get the HDC for the device */ |
|---|
| 1368 | 1366 | auto hDC = device.internal_new_GC(null); |
|---|
| … | … | |
| 1373 | 1371 | * the bmBits field of DIBSECTION to retrieve the image data. |
|---|
| 1374 | 1372 | */ |
|---|
| 1375 | | int handle = this.handle; |
|---|
| | 1373 | auto handle = this.handle; |
|---|
| 1376 | 1374 | if (OS.IsWinCE) { |
|---|
| 1377 | 1375 | if (!isDib) { |
|---|
| … | … | |
| 1381 | 1379 | mustRestore = true; |
|---|
| 1382 | 1380 | GCData data = memGC.data; |
|---|
| 1383 | | if (data.hNullBitmap !is 0) { |
|---|
| | 1381 | if (data.hNullBitmap !is null) { |
|---|
| 1384 | 1382 | OS.SelectObject(memGC.handle, data.hNullBitmap); |
|---|
| 1385 | | data.hNullBitmap = 0; |
|---|
| | 1383 | data.hNullBitmap = null; |
|---|
| 1386 | 1384 | } |
|---|
| 1387 | 1385 | } |
|---|
| … | … | |
| 1394 | 1392 | } |
|---|
| 1395 | 1393 | } |
|---|
| 1396 | | DIBSECTION dib = null; |
|---|
| | 1394 | DIBSECTION dib; |
|---|
| 1397 | 1395 | if (isDib) { |
|---|
| 1398 | | dib = new DIBSECTION(); |
|---|
| 1399 | | OS.GetObject(handle, DIBSECTION.sizeof, dib); |
|---|
| | 1396 | OS.GetObject(handle, DIBSECTION.sizeof, &dib); |
|---|
| 1400 | 1397 | } |
|---|
| 1401 | 1398 | /* Calculate number of colors */ |
|---|
| … | … | |
| 1410 | 1407 | /* Create the BITMAPINFO */ |
|---|
| 1411 | 1408 | byte[] bmi = null; |
|---|
| 1412 | | BITMAPINFOHEADER bmiHeader = null; |
|---|
| | 1409 | BITMAPINFOHEADER bmiHeader; |
|---|
| 1413 | 1410 | if (!isDib) { |
|---|
| 1414 | | bmiHeader = new BITMAPINFOHEADER(); |
|---|
| 1415 | 1411 | bmiHeader.biSize = BITMAPINFOHEADER.sizeof; |
|---|
| 1416 | |
|---|