2 * Unit test suite for metafiles
4 * Copyright (C) 2011 Vincent Povirk for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
28 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
29 #define expectf(expected, got) expectf_((expected), (got), 0.001)
31 static BOOL save_metafiles
;
32 static BOOL load_metafiles
;
34 typedef struct emfplus_record
41 typedef struct emfplus_check_state
45 const struct emfplus_record
*expected
;
47 } emfplus_check_state
;
49 static void check_record(int count
, const char *desc
, const struct emfplus_record
*expected
, const struct emfplus_record
*actual
)
51 todo_wine_if (expected
->todo
)
52 ok(expected
->record_type
== actual
->record_type
,
53 "%s.%i: Expected record type 0x%x, got 0x%x\n", desc
, count
,
54 expected
->record_type
, actual
->record_type
);
57 typedef struct EmfPlusRecordHeader
63 } EmfPlusRecordHeader
;
65 static int CALLBACK
enum_emf_proc(HDC hDC
, HANDLETABLE
*lpHTable
, const ENHMETARECORD
*lpEMFR
,
66 int nObj
, LPARAM lpData
)
68 emfplus_check_state
*state
= (emfplus_check_state
*)lpData
;
69 emfplus_record actual
;
71 if (lpEMFR
->iType
== EMR_GDICOMMENT
)
73 const EMRGDICOMMENT
*comment
= (const EMRGDICOMMENT
*)lpEMFR
;
75 if (comment
->cbData
>= 4 && memcmp(comment
->Data
, "EMF+", 4) == 0)
79 while (offset
+ sizeof(EmfPlusRecordHeader
) <= comment
->cbData
)
81 const EmfPlusRecordHeader
*record
= (const EmfPlusRecordHeader
*)&comment
->Data
[offset
];
83 ok(record
->Size
== record
->DataSize
+ sizeof(EmfPlusRecordHeader
),
84 "%s: EMF+ record datasize %u and size %u mismatch\n", state
->desc
, record
->DataSize
, record
->Size
);
86 ok(offset
+ record
->DataSize
<= comment
->cbData
,
87 "%s: EMF+ record truncated\n", state
->desc
);
89 if (offset
+ record
->DataSize
> comment
->cbData
)
92 if (state
->expected
[state
->count
].record_type
)
95 actual
.record_type
= record
->Type
;
97 check_record(state
->count
, state
->desc
, &state
->expected
[state
->count
], &actual
);
103 ok(0, "%s: Unexpected EMF+ 0x%x record\n", state
->desc
, record
->Type
);
106 offset
+= record
->Size
;
109 ok(offset
== comment
->cbData
, "%s: truncated EMF+ record data?\n", state
->desc
);
115 if (state
->expected
[state
->count
].record_type
)
118 actual
.record_type
= lpEMFR
->iType
;
120 check_record(state
->count
, state
->desc
, &state
->expected
[state
->count
], &actual
);
126 ok(0, "%s: Unexpected EMF 0x%x record\n", state
->desc
, lpEMFR
->iType
);
132 static void check_emfplus(HENHMETAFILE hemf
, const emfplus_record
*expected
, const char *desc
)
134 emfplus_check_state state
;
138 state
.expected
= expected
;
140 EnumEnhMetaFile(0, hemf
, enum_emf_proc
, &state
, NULL
);
142 todo_wine_if (expected
[state
.count
].todo
)
143 ok(expected
[state
.count
].record_type
== 0, "%s: Got %i records, expecting more\n", desc
, state
.count
);
146 static BOOL CALLBACK
enum_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
147 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
149 emfplus_check_state
*state
= (emfplus_check_state
*)userdata
;
150 emfplus_record actual
;
153 actual
.record_type
= record_type
;
156 ok(pStr
== NULL
, "non-NULL pStr\n");
158 if (state
->expected
[state
->count
].record_type
)
160 check_record(state
->count
, state
->desc
, &state
->expected
[state
->count
], &actual
);
166 ok(0, "%s: Unexpected EMF 0x%x record\n", state
->desc
, record_type
);
172 static void check_metafile(GpMetafile
*metafile
, const emfplus_record
*expected
, const char *desc
,
173 const GpPointF
*dst_points
, const GpRectF
*src_rect
, Unit src_unit
)
177 GpGraphics
*graphics
;
178 emfplus_check_state state
;
182 state
.expected
= expected
;
183 state
.metafile
= metafile
;
185 hdc
= CreateCompatibleDC(0);
187 stat
= GdipCreateFromHDC(hdc
, &graphics
);
190 stat
= GdipEnumerateMetafileSrcRectDestPoints(graphics
, metafile
, dst_points
,
191 3, src_rect
, src_unit
, enum_metafile_proc
, &state
, NULL
);
194 todo_wine_if (expected
[state
.count
].todo
)
195 ok(expected
[state
.count
].record_type
== 0, "%s: Got %i records, expecting more\n", desc
, state
.count
);
197 GdipDeleteGraphics(graphics
);
202 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
203 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
205 emfplus_check_state
*state
= (emfplus_check_state
*)userdata
;
208 stat
= GdipPlayMetafileRecord(state
->metafile
, record_type
, flags
, dataSize
, pStr
);
210 if (state
->expected
[state
->count
].record_type
)
212 todo_wine_if (state
->expected
[state
->count
].playback_todo
)
213 ok(stat
== Ok
, "%s.%i: GdipPlayMetafileRecord failed with stat %i\n", state
->desc
, state
->count
, stat
);
218 todo_wine_if (state
->expected
[state
->count
].playback_todo
)
219 ok(0, "%s: too many records\n", state
->desc
);
227 static void play_metafile(GpMetafile
*metafile
, GpGraphics
*graphics
, const emfplus_record
*expected
,
228 const char *desc
, const GpPointF
*dst_points
, const GpRectF
*src_rect
, Unit src_unit
)
231 emfplus_check_state state
;
235 state
.expected
= expected
;
236 state
.metafile
= metafile
;
238 stat
= GdipEnumerateMetafileSrcRectDestPoints(graphics
, metafile
, dst_points
,
239 3, src_rect
, src_unit
, play_metafile_proc
, &state
, NULL
);
243 /* When 'save' or 'load' is specified on the command line, save or
244 * load the specified filename. */
245 static void sync_metafile(GpMetafile
**metafile
, const char *filename
)
253 stat
= GdipCloneImage((GpImage
*)*metafile
, (GpImage
**)&clone
);
256 stat
= GdipGetHemfFromMetafile(clone
, &hemf
);
259 DeleteEnhMetaFile(CopyEnhMetaFileA(hemf
, filename
));
261 DeleteEnhMetaFile(hemf
);
263 stat
= GdipDisposeImage((GpImage
*)clone
);
266 else if (load_metafiles
)
270 stat
= GdipDisposeImage((GpImage
*)*metafile
);
274 hemf
= GetEnhMetaFileA(filename
);
275 ok(hemf
!= NULL
, "%s could not be opened\n", filename
);
277 stat
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
282 static const emfplus_record empty_records
[] = {
284 {0, EmfPlusRecordTypeHeader
},
285 {0, EmfPlusRecordTypeEndOfFile
},
290 static void test_empty(void)
293 GpMetafile
*metafile
;
294 GpGraphics
*graphics
;
299 HENHMETAFILE hemf
, dummy
;
300 MetafileHeader header
;
301 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
302 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
303 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
305 hdc
= CreateCompatibleDC(0);
307 stat
= GdipRecordMetafile(NULL
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
308 expect(InvalidParameter
, stat
);
310 stat
= GdipRecordMetafile(hdc
, MetafileTypeInvalid
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
311 expect(InvalidParameter
, stat
);
313 stat
= GdipRecordMetafile(hdc
, MetafileTypeWmf
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
314 expect(InvalidParameter
, stat
);
316 stat
= GdipRecordMetafile(hdc
, MetafileTypeWmfPlaceable
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
317 expect(InvalidParameter
, stat
);
319 stat
= GdipRecordMetafile(hdc
, MetafileTypeEmfPlusDual
+1, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
320 expect(InvalidParameter
, stat
);
322 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, NULL
);
323 expect(InvalidParameter
, stat
);
325 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
333 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
334 expect(InvalidParameter
, stat
);
336 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
339 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
340 expect(InvalidParameter
, stat
);
342 stat
= GdipDeleteGraphics(graphics
);
345 check_metafile(metafile
, empty_records
, "empty metafile", dst_points
, &frame
, UnitPixel
);
347 sync_metafile(&metafile
, "empty.emf");
349 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
351 expectf(0.0, bounds
.X
);
352 expectf(0.0, bounds
.Y
);
353 expectf_(100.0, bounds
.Width
, 0.05);
354 expectf_(100.0, bounds
.Height
, 0.05);
355 expect(UnitPixel
, unit
);
357 stat
= GdipGetImageHorizontalResolution((GpImage
*)metafile
, &xres
);
360 stat
= GdipGetImageVerticalResolution((GpImage
*)metafile
, &yres
);
363 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
366 stat
= GdipGetHemfFromMetafile(metafile
, &dummy
);
367 expect(InvalidParameter
, stat
);
369 stat
= GdipDisposeImage((GpImage
*)metafile
);
372 check_emfplus(hemf
, empty_records
, "empty emf");
374 memset(&header
, 0xaa, sizeof(header
));
375 stat
= GdipGetMetafileHeaderFromEmf(hemf
, &header
);
377 expect(MetafileTypeEmfPlusOnly
, header
.Type
);
378 expect(U(header
).EmfHeader
.nBytes
, header
.Size
);
379 ok(header
.Version
== 0xdbc01001 || header
.Version
== 0xdbc01002, "Unexpected version %x\n", header
.Version
);
380 expect(1, header
.EmfPlusFlags
); /* reference device was display, not printer */
381 expectf(xres
, header
.DpiX
);
382 expectf(xres
, U(header
).EmfHeader
.szlDevice
.cx
/ (REAL
)U(header
).EmfHeader
.szlMillimeters
.cx
* 25.4);
383 expectf(yres
, header
.DpiY
);
384 expectf(yres
, U(header
).EmfHeader
.szlDevice
.cy
/ (REAL
)U(header
).EmfHeader
.szlMillimeters
.cy
* 25.4);
387 expect(100, header
.Width
);
388 expect(100, header
.Height
);
389 expect(28, header
.EmfPlusHeaderSize
);
390 expect(96, header
.LogicalDpiX
);
391 expect(96, header
.LogicalDpiX
);
392 expect(EMR_HEADER
, U(header
).EmfHeader
.iType
);
393 expect(0, U(header
).EmfHeader
.rclBounds
.left
);
394 expect(0, U(header
).EmfHeader
.rclBounds
.top
);
395 expect(-1, U(header
).EmfHeader
.rclBounds
.right
);
396 expect(-1, U(header
).EmfHeader
.rclBounds
.bottom
);
397 expect(0, U(header
).EmfHeader
.rclFrame
.left
);
398 expect(0, U(header
).EmfHeader
.rclFrame
.top
);
399 expectf_(100.0, U(header
).EmfHeader
.rclFrame
.right
* xres
/ 2540.0, 2.0);
400 expectf_(100.0, U(header
).EmfHeader
.rclFrame
.bottom
* yres
/ 2540.0, 2.0);
402 stat
= GdipCreateMetafileFromEmf(hemf
, TRUE
, &metafile
);
405 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
407 expectf(0.0, bounds
.X
);
408 expectf(0.0, bounds
.Y
);
409 expectf_(100.0, bounds
.Width
, 0.05);
410 expectf_(100.0, bounds
.Height
, 0.05);
411 expect(UnitPixel
, unit
);
413 stat
= GdipGetImageHorizontalResolution((GpImage
*)metafile
, &xres
);
415 expectf(header
.DpiX
, xres
);
417 stat
= GdipGetImageVerticalResolution((GpImage
*)metafile
, &yres
);
419 expectf(header
.DpiY
, yres
);
421 stat
= GdipDisposeImage((GpImage
*)metafile
);
425 static const emfplus_record getdc_records
[] = {
427 {0, EmfPlusRecordTypeHeader
},
428 {0, EmfPlusRecordTypeGetDC
},
429 {0, EMR_CREATEBRUSHINDIRECT
},
430 {0, EMR_SELECTOBJECT
},
432 {0, EMR_SELECTOBJECT
},
433 {0, EMR_DELETEOBJECT
},
434 {0, EmfPlusRecordTypeEndOfFile
},
439 static void test_getdc(void)
442 GpMetafile
*metafile
;
443 GpGraphics
*graphics
;
444 HDC hdc
, metafile_dc
;
447 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
448 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
449 static const GpPointF dst_points_half
[3] = {{0.0,0.0},{50.0,0.0},{0.0,50.0}};
450 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
451 HBRUSH hbrush
, holdbrush
;
455 hdc
= CreateCompatibleDC(0);
457 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
465 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
466 expect(InvalidParameter
, stat
);
468 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
471 stat
= GdipGetDC(graphics
, &metafile_dc
);
476 GdipDeleteGraphics(graphics
);
477 GdipDisposeImage((GpImage
*)metafile
);
481 hbrush
= CreateSolidBrush(0xff0000);
483 holdbrush
= SelectObject(metafile_dc
, hbrush
);
485 Rectangle(metafile_dc
, 25, 25, 75, 75);
487 SelectObject(metafile_dc
, holdbrush
);
489 DeleteObject(hbrush
);
491 stat
= GdipReleaseDC(graphics
, metafile_dc
);
494 stat
= GdipDeleteGraphics(graphics
);
497 check_metafile(metafile
, getdc_records
, "getdc metafile", dst_points
, &frame
, UnitPixel
);
499 sync_metafile(&metafile
, "getdc.emf");
501 stat
= GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB
, NULL
, &bitmap
);
504 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
507 play_metafile(metafile
, graphics
, getdc_records
, "getdc playback", dst_points
, &frame
, UnitPixel
);
509 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
513 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
515 expect(0xff0000ff, color
);
517 stat
= GdipBitmapSetPixel(bitmap
, 50, 50, 0);
520 play_metafile(metafile
, graphics
, getdc_records
, "getdc playback", dst_points_half
, &frame
, UnitPixel
);
522 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
524 expect(0xff0000ff, color
);
526 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
530 stat
= GdipBitmapSetPixel(bitmap
, 15, 15, 0);
533 stat
= GdipDrawImagePointsRect(graphics
, (GpImage
*)metafile
, dst_points
, 3,
534 0.0, 0.0, 100.0, 100.0, UnitPixel
, NULL
, NULL
, NULL
);
537 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
541 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
543 expect(0xff0000ff, color
);
545 stat
= GdipDeleteGraphics(graphics
);
548 stat
= GdipDisposeImage((GpImage
*)bitmap
);
551 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
554 stat
= GdipDisposeImage((GpImage
*)metafile
);
557 check_emfplus(hemf
, getdc_records
, "getdc emf");
559 ret
= DeleteEnhMetaFile(hemf
);
560 ok(ret
!= 0, "Failed to delete enhmetafile %p\n", hemf
);
563 static const emfplus_record emfonly_records
[] = {
565 {0, EMR_CREATEBRUSHINDIRECT
},
566 {0, EMR_SELECTOBJECT
},
568 {0, EMR_SELECTOBJECT
},
569 {0, EMR_DELETEOBJECT
},
574 static void test_emfonly(void)
577 GpMetafile
*metafile
;
579 GpGraphics
*graphics
;
580 HDC hdc
, metafile_dc
;
585 MetafileHeader header
;
586 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
587 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
588 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
589 HBRUSH hbrush
, holdbrush
;
593 hdc
= CreateCompatibleDC(0);
595 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
603 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
604 expect(InvalidParameter
, stat
);
606 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
609 stat
= GdipGetDC(graphics
, &metafile_dc
);
614 GdipDeleteGraphics(graphics
);
615 GdipDisposeImage((GpImage
*)metafile
);
619 hbrush
= CreateSolidBrush(0xff0000);
621 holdbrush
= SelectObject(metafile_dc
, hbrush
);
623 Rectangle(metafile_dc
, 25, 25, 75, 75);
625 SelectObject(metafile_dc
, holdbrush
);
627 DeleteObject(hbrush
);
629 stat
= GdipReleaseDC(graphics
, metafile_dc
);
632 stat
= GdipDeleteGraphics(graphics
);
635 check_metafile(metafile
, emfonly_records
, "emfonly metafile", dst_points
, &frame
, UnitPixel
);
637 sync_metafile(&metafile
, "emfonly.emf");
639 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
641 expectf(0.0, bounds
.X
);
642 expectf(0.0, bounds
.Y
);
643 expectf_(100.0, bounds
.Width
, 0.05);
644 expectf_(100.0, bounds
.Height
, 0.05);
645 expect(UnitPixel
, unit
);
647 stat
= GdipGetImageHorizontalResolution((GpImage
*)metafile
, &xres
);
650 stat
= GdipGetImageVerticalResolution((GpImage
*)metafile
, &yres
);
653 stat
= GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB
, NULL
, &bitmap
);
656 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
659 play_metafile(metafile
, graphics
, emfonly_records
, "emfonly playback", dst_points
, &frame
, UnitPixel
);
661 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
665 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
667 expect(0xff0000ff, color
);
669 stat
= GdipBitmapSetPixel(bitmap
, 50, 50, 0);
672 stat
= GdipDrawImagePointsRect(graphics
, (GpImage
*)metafile
, dst_points
, 3,
673 0.0, 0.0, 100.0, 100.0, UnitPixel
, NULL
, NULL
, NULL
);
676 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
680 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
682 expect(0xff0000ff, color
);
684 stat
= GdipCloneImage((GpImage
*)metafile
, &clone
);
689 stat
= GdipBitmapSetPixel(bitmap
, 50, 50, 0);
692 stat
= GdipDrawImagePointsRect(graphics
, clone
, dst_points
, 3,
693 0.0, 0.0, 100.0, 100.0, UnitPixel
, NULL
, NULL
, NULL
);
696 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
700 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
702 expect(0xff0000ff, color
);
704 GdipDisposeImage(clone
);
707 stat
= GdipDeleteGraphics(graphics
);
710 stat
= GdipDisposeImage((GpImage
*)bitmap
);
713 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
716 stat
= GdipDisposeImage((GpImage
*)metafile
);
719 check_emfplus(hemf
, emfonly_records
, "emfonly emf");
721 memset(&header
, 0xaa, sizeof(header
));
722 stat
= GdipGetMetafileHeaderFromEmf(hemf
, &header
);
724 expect(MetafileTypeEmf
, header
.Type
);
725 expect(U(header
).EmfHeader
.nBytes
, header
.Size
);
726 expect(0x10000, header
.Version
);
727 expect(0, header
.EmfPlusFlags
);
728 expectf(xres
, header
.DpiX
);
729 expectf(xres
, U(header
).EmfHeader
.szlDevice
.cx
/ (REAL
)U(header
).EmfHeader
.szlMillimeters
.cx
* 25.4);
730 expectf(yres
, header
.DpiY
);
731 expectf(yres
, U(header
).EmfHeader
.szlDevice
.cy
/ (REAL
)U(header
).EmfHeader
.szlMillimeters
.cy
* 25.4);
734 expect(100, header
.Width
);
735 expect(100, header
.Height
);
736 expect(0, header
.EmfPlusHeaderSize
);
737 expect(0, header
.LogicalDpiX
);
738 expect(0, header
.LogicalDpiX
);
739 expect(EMR_HEADER
, U(header
).EmfHeader
.iType
);
740 expect(25, U(header
).EmfHeader
.rclBounds
.left
);
741 expect(25, U(header
).EmfHeader
.rclBounds
.top
);
742 expect(74, U(header
).EmfHeader
.rclBounds
.right
);
743 expect(74, U(header
).EmfHeader
.rclBounds
.bottom
);
744 expect(0, U(header
).EmfHeader
.rclFrame
.left
);
745 expect(0, U(header
).EmfHeader
.rclFrame
.top
);
746 expectf_(100.0, U(header
).EmfHeader
.rclFrame
.right
* xres
/ 2540.0, 2.0);
747 expectf_(100.0, U(header
).EmfHeader
.rclFrame
.bottom
* yres
/ 2540.0, 2.0);
749 stat
= GdipCreateMetafileFromEmf(hemf
, TRUE
, &metafile
);
752 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
754 expectf(0.0, bounds
.X
);
755 expectf(0.0, bounds
.Y
);
756 expectf_(100.0, bounds
.Width
, 0.05);
757 expectf_(100.0, bounds
.Height
, 0.05);
758 expect(UnitPixel
, unit
);
760 stat
= GdipGetImageHorizontalResolution((GpImage
*)metafile
, &xres
);
762 expectf(header
.DpiX
, xres
);
764 stat
= GdipGetImageVerticalResolution((GpImage
*)metafile
, &yres
);
766 expectf(header
.DpiY
, yres
);
768 stat
= GdipDisposeImage((GpImage
*)metafile
);
772 static const emfplus_record fillrect_records
[] = {
774 {0, EmfPlusRecordTypeHeader
},
775 {0, EmfPlusRecordTypeFillRects
},
776 {0, EmfPlusRecordTypeEndOfFile
},
781 static void test_fillrect(void)
784 GpMetafile
*metafile
;
785 GpGraphics
*graphics
;
788 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
789 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
790 static const GpPointF dst_points_half
[3] = {{0.0,0.0},{50.0,0.0},{0.0,50.0}};
791 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
796 hdc
= CreateCompatibleDC(0);
798 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
806 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
807 expect(InvalidParameter
, stat
);
809 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
812 stat
= GdipCreateSolidFill((ARGB
)0xff0000ff, (GpSolidFill
**)&brush
);
815 stat
= GdipFillRectangleI(graphics
, brush
, 25, 25, 75, 75);
818 stat
= GdipDeleteBrush(brush
);
821 stat
= GdipDeleteGraphics(graphics
);
824 check_metafile(metafile
, fillrect_records
, "fillrect metafile", dst_points
, &frame
, UnitPixel
);
826 sync_metafile(&metafile
, "fillrect.emf");
828 stat
= GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB
, NULL
, &bitmap
);
831 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
834 play_metafile(metafile
, graphics
, fillrect_records
, "fillrect playback", dst_points
, &frame
, UnitPixel
);
836 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
840 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
842 expect(0xff0000ff, color
);
844 stat
= GdipBitmapSetPixel(bitmap
, 50, 50, 0);
847 play_metafile(metafile
, graphics
, fillrect_records
, "fillrect playback", dst_points_half
, &frame
, UnitPixel
);
849 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
851 expect(0xff0000ff, color
);
853 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
857 stat
= GdipBitmapSetPixel(bitmap
, 15, 15, 0);
860 stat
= GdipDrawImagePointsRect(graphics
, (GpImage
*)metafile
, dst_points
, 3,
861 0.0, 0.0, 100.0, 100.0, UnitPixel
, NULL
, NULL
, NULL
);
864 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
868 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
870 expect(0xff0000ff, color
);
872 stat
= GdipDeleteGraphics(graphics
);
875 stat
= GdipDisposeImage((GpImage
*)bitmap
);
878 stat
= GdipDisposeImage((GpImage
*)metafile
);
882 static const emfplus_record clear_emf_records
[] = {
884 {0, EmfPlusRecordTypeHeader
},
885 {0, EmfPlusRecordTypeClear
},
890 {0, EmfPlusRecordTypeEndOfFile
},
895 static void test_clear(void)
898 GpMetafile
*metafile
;
899 GpGraphics
*graphics
;
902 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
903 static const GpPointF dst_points
[3] = {{10.0,10.0},{20.0,10.0},{10.0,20.0}};
904 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
908 hdc
= CreateCompatibleDC(0);
910 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
918 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
919 expect(InvalidParameter
, stat
);
921 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
924 stat
= GdipGraphicsClear(graphics
, 0xffffff00);
927 stat
= GdipDeleteGraphics(graphics
);
930 sync_metafile(&metafile
, "clear.emf");
932 stat
= GdipCreateBitmapFromScan0(30, 30, 0, PixelFormat32bppRGB
, NULL
, &bitmap
);
935 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
938 stat
= GdipDrawImagePointsRect(graphics
, (GpImage
*)metafile
, dst_points
, 3,
939 0.0, 0.0, 100.0, 100.0, UnitPixel
, NULL
, NULL
, NULL
);
942 stat
= GdipBitmapGetPixel(bitmap
, 5, 5, &color
);
944 expect(0xff000000, color
);
946 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
948 expect(0xffffff00, color
);
950 stat
= GdipBitmapGetPixel(bitmap
, 25, 25, &color
);
952 expect(0xff000000, color
);
954 stat
= GdipDeleteGraphics(graphics
);
957 stat
= GdipDisposeImage((GpImage
*)bitmap
);
960 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
963 stat
= GdipDisposeImage((GpImage
*)metafile
);
966 check_emfplus(hemf
, clear_emf_records
, "clear emf");
968 DeleteEnhMetaFile(hemf
);
971 static void test_nullframerect(void) {
973 GpMetafile
*metafile
;
974 GpGraphics
*graphics
;
975 HDC hdc
, metafile_dc
;
976 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
978 HBRUSH hbrush
, holdbrush
;
982 hdc
= CreateCompatibleDC(0);
984 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, NULL
, MetafileFrameUnitPixel
, description
, &metafile
);
992 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
994 expect(UnitPixel
, unit
);
995 expectf(0.0, bounds
.X
);
996 expectf(0.0, bounds
.Y
);
997 ok(bounds
.Width
== 1.0 || broken(bounds
.Width
== 0.0) /* xp sp1 */,
998 "expected 1.0, got %f\n", bounds
.Width
);
999 ok(bounds
.Height
== 1.0 || broken(bounds
.Height
== 0.0) /* xp sp1 */,
1000 "expected 1.0, got %f\n", bounds
.Height
);
1002 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
1005 stat
= GdipCreateSolidFill((ARGB
)0xff0000ff, (GpSolidFill
**)&brush
);
1008 stat
= GdipFillRectangleI(graphics
, brush
, 25, 25, 75, 75);
1011 stat
= GdipDeleteBrush(brush
);
1014 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
1016 expect(UnitPixel
, unit
);
1017 expectf(0.0, bounds
.X
);
1018 expectf(0.0, bounds
.Y
);
1019 ok(bounds
.Width
== 1.0 || broken(bounds
.Width
== 0.0) /* xp sp1 */,
1020 "expected 1.0, got %f\n", bounds
.Width
);
1021 ok(bounds
.Height
== 1.0 || broken(bounds
.Height
== 0.0) /* xp sp1 */,
1022 "expected 1.0, got %f\n", bounds
.Height
);
1024 stat
= GdipDeleteGraphics(graphics
);
1027 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
1029 expect(UnitPixel
, unit
);
1030 expectf_(25.0, bounds
.X
, 0.05);
1031 expectf_(25.0, bounds
.Y
, 0.05);
1032 expectf_(75.0, bounds
.Width
, 0.05);
1033 expectf_(75.0, bounds
.Height
, 0.05);
1035 stat
= GdipDisposeImage((GpImage
*)metafile
);
1038 hdc
= CreateCompatibleDC(0);
1040 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, NULL
, MetafileFrameUnitMillimeter
, description
, &metafile
);
1045 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
1048 stat
= GdipGetDC(graphics
, &metafile_dc
);
1053 GdipDeleteGraphics(graphics
);
1054 GdipDisposeImage((GpImage
*)metafile
);
1058 hbrush
= CreateSolidBrush(0xff0000);
1060 holdbrush
= SelectObject(metafile_dc
, hbrush
);
1062 Rectangle(metafile_dc
, 25, 25, 75, 75);
1064 SelectObject(metafile_dc
, holdbrush
);
1066 DeleteObject(hbrush
);
1068 stat
= GdipReleaseDC(graphics
, metafile_dc
);
1071 stat
= GdipDeleteGraphics(graphics
);
1074 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
1076 expect(UnitPixel
, unit
);
1077 expectf_(25.0, bounds
.X
, 0.05);
1078 expectf_(25.0, bounds
.Y
, 0.05);
1079 todo_wine
expectf_(50.0, bounds
.Width
, 0.05);
1080 todo_wine
expectf_(50.0, bounds
.Height
, 0.05);
1082 stat
= GdipDisposeImage((GpImage
*)metafile
);
1086 static const emfplus_record pagetransform_records
[] = {
1088 {0, EmfPlusRecordTypeHeader
},
1089 {0, EmfPlusRecordTypeFillRects
},
1090 {0, EmfPlusRecordTypeSetPageTransform
},
1091 {0, EmfPlusRecordTypeFillRects
},
1092 {0, EmfPlusRecordTypeSetPageTransform
},
1093 {0, EmfPlusRecordTypeFillRects
},
1094 {0, EmfPlusRecordTypeSetPageTransform
},
1095 {0, EmfPlusRecordTypeFillRects
},
1096 {0, EmfPlusRecordTypeSetPageTransform
},
1097 {0, EmfPlusRecordTypeFillRects
},
1098 {0, EmfPlusRecordTypeEndOfFile
},
1103 static void test_pagetransform(void)
1106 GpMetafile
*metafile
;
1107 GpGraphics
*graphics
;
1109 static const GpRectF frame
= {0.0, 0.0, 5.0, 5.0};
1110 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
1111 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
1116 REAL scale
, dpix
, dpiy
;
1119 hdc
= CreateCompatibleDC(0);
1121 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitInch
, description
, &metafile
);
1129 stat
= GdipGetImageHorizontalResolution((GpImage
*)metafile
, &dpix
);
1130 todo_wine
expect(InvalidParameter
, stat
);
1132 stat
= GdipGetImageVerticalResolution((GpImage
*)metafile
, &dpiy
);
1133 todo_wine
expect(InvalidParameter
, stat
);
1135 stat
= GdipGetImageWidth((GpImage
*)metafile
, &width
);
1136 todo_wine
expect(InvalidParameter
, stat
);
1138 stat
= GdipGetImageHeight((GpImage
*)metafile
, &height
);
1139 todo_wine
expect(InvalidParameter
, stat
);
1141 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
1145 stat
= GdipGetPageUnit(graphics
, &unit
);
1147 expect(UnitDisplay
, unit
);
1149 stat
= GdipGetPageScale(graphics
, &scale
);
1151 expectf(1.0, scale
);
1153 stat
= GdipGetDpiX(graphics
, &dpix
);
1155 expectf(96.0, dpix
);
1157 stat
= GdipGetDpiY(graphics
, &dpiy
);
1159 expectf(96.0, dpiy
);
1161 stat
= GdipCreateSolidFill((ARGB
)0xff0000ff, (GpSolidFill
**)&brush
);
1164 stat
= GdipFillRectangleI(graphics
, brush
, 1, 2, 1, 1);
1167 stat
= GdipDeleteBrush(brush
);
1170 /* page unit = pixels */
1171 stat
= GdipSetPageUnit(graphics
, UnitPixel
);
1174 stat
= GdipGetPageUnit(graphics
, &unit
);
1176 expect(UnitPixel
, unit
);
1178 stat
= GdipCreateSolidFill((ARGB
)0xff00ff00, (GpSolidFill
**)&brush
);
1181 stat
= GdipFillRectangleI(graphics
, brush
, 0, 1, 1, 1);
1184 stat
= GdipDeleteBrush(brush
);
1187 /* page scale = 3, unit = pixels */
1188 stat
= GdipSetPageScale(graphics
, 3.0);
1191 stat
= GdipGetPageScale(graphics
, &scale
);
1193 expectf(3.0, scale
);
1195 stat
= GdipCreateSolidFill((ARGB
)0xff00ffff, (GpSolidFill
**)&brush
);
1198 stat
= GdipFillRectangleI(graphics
, brush
, 0, 1, 2, 2);
1201 stat
= GdipDeleteBrush(brush
);
1204 /* page scale = 3, unit = inches */
1205 stat
= GdipSetPageUnit(graphics
, UnitInch
);
1208 stat
= GdipGetPageUnit(graphics
, &unit
);
1210 expect(UnitInch
, unit
);
1212 stat
= GdipCreateSolidFill((ARGB
)0xffff0000, (GpSolidFill
**)&brush
);
1215 stat
= GdipFillRectangle(graphics
, brush
, 1.0/96.0, 0, 1, 1);
1218 stat
= GdipDeleteBrush(brush
);
1221 /* page scale = 3, unit = display */
1222 stat
= GdipSetPageUnit(graphics
, UnitDisplay
);
1225 stat
= GdipGetPageUnit(graphics
, &unit
);
1227 expect(UnitDisplay
, unit
);
1229 stat
= GdipCreateSolidFill((ARGB
)0xffff00ff, (GpSolidFill
**)&brush
);
1232 stat
= GdipFillRectangle(graphics
, brush
, 3, 3, 2, 2);
1235 stat
= GdipDeleteBrush(brush
);
1238 stat
= GdipDeleteGraphics(graphics
);
1241 check_metafile(metafile
, pagetransform_records
, "pagetransform metafile", dst_points
, &frame
, UnitPixel
);
1243 sync_metafile(&metafile
, "pagetransform.emf");
1245 stat
= GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB
, NULL
, &bitmap
);
1248 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
1251 play_metafile(metafile
, graphics
, pagetransform_records
, "pagetransform playback", dst_points
, &frame
, UnitPixel
);
1253 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
1257 stat
= GdipBitmapGetPixel(bitmap
, 30, 50, &color
);
1259 expect(0xff0000ff, color
);
1261 stat
= GdipBitmapGetPixel(bitmap
, 10, 30, &color
);
1263 expect(0xff00ff00, color
);
1265 stat
= GdipBitmapGetPixel(bitmap
, 20, 80, &color
);
1267 expect(0xff00ffff, color
);
1269 stat
= GdipBitmapGetPixel(bitmap
, 80, 20, &color
);
1271 expect(0xffff0000, color
);
1273 stat
= GdipBitmapGetPixel(bitmap
, 80, 80, &color
);
1275 expect(0xffff00ff, color
);
1277 stat
= GdipDeleteGraphics(graphics
);
1280 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1283 stat
= GdipDisposeImage((GpImage
*)metafile
);
1287 static const emfplus_record worldtransform_records
[] = {
1289 {0, EmfPlusRecordTypeHeader
},
1290 {0, EmfPlusRecordTypeFillRects
},
1291 {0, EmfPlusRecordTypeScaleWorldTransform
},
1292 {0, EmfPlusRecordTypeFillRects
},
1293 {0, EmfPlusRecordTypeResetWorldTransform
},
1294 {0, EmfPlusRecordTypeFillRects
},
1295 {0, EmfPlusRecordTypeMultiplyWorldTransform
},
1296 {0, EmfPlusRecordTypeFillRects
},
1297 {0, EmfPlusRecordTypeRotateWorldTransform
},
1298 {0, EmfPlusRecordTypeFillRects
},
1299 {0, EmfPlusRecordTypeEndOfFile
},
1304 static void test_worldtransform(void)
1307 GpMetafile
*metafile
;
1308 GpGraphics
*graphics
;
1310 static const GpRectF frame
= {0.0, 0.0, 5.0, 5.0};
1311 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
1312 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
1316 GpMatrix
*transform
;
1320 hdc
= CreateCompatibleDC(0);
1322 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
1330 stat
= GdipCreateMatrix(&transform
);
1333 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
1336 /* initial transform */
1337 stat
= GdipGetWorldTransform(graphics
, transform
);
1340 stat
= GdipIsMatrixIdentity(transform
, &identity
);
1342 expect(TRUE
, identity
);
1344 stat
= GdipCreateSolidFill((ARGB
)0xff0000ff, (GpSolidFill
**)&brush
);
1347 stat
= GdipFillRectangleI(graphics
, brush
, 0, 0, 1, 1);
1350 stat
= GdipDeleteBrush(brush
);
1353 /* scale transform */
1354 stat
= GdipScaleWorldTransform(graphics
, 2.0, 4.0, MatrixOrderPrepend
);
1357 stat
= GdipGetWorldTransform(graphics
, transform
);
1360 stat
= GdipGetMatrixElements(transform
, elements
);
1362 expectf(2.0, elements
[0]);
1363 expectf(0.0, elements
[1]);
1364 expectf(0.0, elements
[2]);
1365 expectf(4.0, elements
[3]);
1366 expectf(0.0, elements
[4]);
1367 expectf(0.0, elements
[5]);
1369 stat
= GdipCreateSolidFill((ARGB
)0xff00ff00, (GpSolidFill
**)&brush
);
1372 stat
= GdipFillRectangle(graphics
, brush
, 0.5, 0.5, 0.5, 0.25);
1375 stat
= GdipDeleteBrush(brush
);
1378 /* reset transform */
1379 stat
= GdipResetWorldTransform(graphics
);
1382 stat
= GdipGetWorldTransform(graphics
, transform
);
1385 stat
= GdipIsMatrixIdentity(transform
, &identity
);
1387 expect(TRUE
, identity
);
1389 stat
= GdipCreateSolidFill((ARGB
)0xff00ffff, (GpSolidFill
**)&brush
);
1392 stat
= GdipFillRectangle(graphics
, brush
, 1.0, 0.0, 1.0, 1.0);
1395 stat
= GdipDeleteBrush(brush
);
1398 /* multiply transform */
1399 stat
= GdipSetMatrixElements(transform
, 2.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1402 stat
= GdipMultiplyWorldTransform(graphics
, transform
, MatrixOrderPrepend
);
1405 stat
= GdipGetWorldTransform(graphics
, transform
);
1408 stat
= GdipGetMatrixElements(transform
, elements
);
1410 expectf(2.0, elements
[0]);
1411 expectf(0.0, elements
[1]);
1412 expectf(0.0, elements
[2]);
1413 expectf(1.0, elements
[3]);
1414 expectf(0.0, elements
[4]);
1415 expectf(0.0, elements
[5]);
1417 stat
= GdipCreateSolidFill((ARGB
)0xffff0000, (GpSolidFill
**)&brush
);
1420 stat
= GdipFillRectangle(graphics
, brush
, 1.0, 1.0, 0.5, 1.0);
1423 stat
= GdipDeleteBrush(brush
);
1426 /* rotate transform */
1427 stat
= GdipRotateWorldTransform(graphics
, 90.0, MatrixOrderAppend
);
1430 stat
= GdipGetWorldTransform(graphics
, transform
);
1433 stat
= GdipGetMatrixElements(transform
, elements
);
1435 expectf(0.0, elements
[0]);
1436 expectf(2.0, elements
[1]);
1437 expectf(-1.0, elements
[2]);
1438 expectf(0.0, elements
[3]);
1439 expectf(0.0, elements
[4]);
1440 expectf(0.0, elements
[5]);
1442 stat
= GdipCreateSolidFill((ARGB
)0xffff00ff, (GpSolidFill
**)&brush
);
1445 stat
= GdipFillRectangle(graphics
, brush
, 1.0, -1.0, 0.5, 1.0);
1448 stat
= GdipDeleteBrush(brush
);
1451 stat
= GdipDeleteMatrix(transform
);
1454 stat
= GdipDeleteGraphics(graphics
);
1457 check_metafile(metafile
, worldtransform_records
, "worldtransform metafile", dst_points
, &frame
, UnitPixel
);
1459 sync_metafile(&metafile
, "worldtransform.emf");
1461 stat
= GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB
, NULL
, &bitmap
);
1464 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
1467 play_metafile(metafile
, graphics
, worldtransform_records
, "worldtransform playback", dst_points
, &frame
, UnitPixel
);
1469 stat
= GdipBitmapGetPixel(bitmap
, 80, 80, &color
);
1473 stat
= GdipBitmapGetPixel(bitmap
, 10, 10, &color
);
1475 expect(0xff0000ff, color
);
1477 stat
= GdipBitmapGetPixel(bitmap
, 30, 50, &color
);
1479 expect(0xff00ff00, color
);
1481 stat
= GdipBitmapGetPixel(bitmap
, 30, 10, &color
);
1483 expect(0xff00ffff, color
);
1485 stat
= GdipBitmapGetPixel(bitmap
, 50, 30, &color
);
1487 expect(0xffff0000, color
);
1489 stat
= GdipBitmapGetPixel(bitmap
, 10, 50, &color
);
1491 expect(0xffff00ff, color
);
1493 stat
= GdipDeleteGraphics(graphics
);
1496 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1499 stat
= GdipDisposeImage((GpImage
*)metafile
);
1503 static void test_converttoemfplus(void)
1505 GpStatus (WINAPI
*pGdipConvertToEmfPlus
)( const GpGraphics
*graphics
, GpMetafile
*metafile
, BOOL
*succ
,
1506 EmfType emfType
, const WCHAR
*description
, GpMetafile
**outmetafile
);
1507 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
1508 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
1510 GpMetafile
*metafile
, *metafile2
= NULL
, *emhmeta
;
1511 GpGraphics
*graphics
;
1514 HMODULE mod
= GetModuleHandleA("gdiplus.dll");
1516 pGdipConvertToEmfPlus
= (void*)GetProcAddress( mod
, "GdipConvertToEmfPlus");
1517 if(!pGdipConvertToEmfPlus
)
1519 /* GdipConvertToEmfPlus was introduced in Windows Vista. */
1520 win_skip("GDIPlus version 1.1 not available\n");
1524 hdc
= CreateCompatibleDC(0);
1526 stat
= GdipRecordMetafile(hdc
, MetafileTypeEmf
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
1529 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &emhmeta
);
1537 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
1540 /* Invalid Parameters */
1541 stat
= pGdipConvertToEmfPlus(NULL
, metafile
, &succ
, EmfTypeEmfPlusOnly
, description
, &metafile2
);
1542 expect(InvalidParameter
, stat
);
1544 stat
= pGdipConvertToEmfPlus(graphics
, NULL
, &succ
, EmfTypeEmfPlusOnly
, description
, &metafile2
);
1545 expect(InvalidParameter
, stat
);
1547 stat
= pGdipConvertToEmfPlus(graphics
, metafile
, &succ
, EmfTypeEmfPlusOnly
, description
, NULL
);
1548 expect(InvalidParameter
, stat
);
1550 stat
= pGdipConvertToEmfPlus(graphics
, metafile
, NULL
, MetafileTypeInvalid
, NULL
, &metafile2
);
1551 expect(InvalidParameter
, stat
);
1553 stat
= pGdipConvertToEmfPlus(graphics
, metafile
, NULL
, MetafileTypeEmfPlusDual
+1, NULL
, &metafile2
);
1554 expect(InvalidParameter
, stat
);
1556 /* If we are already an Enhanced Metafile then the conversion fails. */
1557 stat
= pGdipConvertToEmfPlus(graphics
, emhmeta
, NULL
, EmfTypeEmfPlusOnly
, NULL
, &metafile2
);
1558 todo_wine
expect(InvalidParameter
, stat
);
1560 stat
= pGdipConvertToEmfPlus(graphics
, metafile
, NULL
, EmfTypeEmfPlusOnly
, NULL
, &metafile2
);
1561 todo_wine
expect(Ok
, stat
);
1563 GdipDisposeImage((GpImage
*)metafile2
);
1566 stat
= pGdipConvertToEmfPlus(graphics
, metafile
, &succ
, EmfTypeEmfPlusOnly
, NULL
, &metafile2
);
1567 todo_wine
expect(Ok
, stat
);
1569 GdipDisposeImage((GpImage
*)metafile2
);
1571 stat
= GdipDeleteGraphics(graphics
);
1574 stat
= GdipDisposeImage((GpImage
*)metafile
);
1577 stat
= GdipDisposeImage((GpImage
*)emhmeta
);
1581 static void test_frameunit(void)
1584 GpMetafile
*metafile
;
1585 GpGraphics
*graphics
;
1587 static const GpRectF frame
= {0.0, 0.0, 5.0, 5.0};
1588 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
1593 hdc
= CreateCompatibleDC(0);
1595 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitInch
, description
, &metafile
);
1603 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
1605 expect(UnitPixel
, unit
);
1606 expectf(0.0, bounds
.X
);
1607 expectf(0.0, bounds
.Y
);
1608 ok(bounds
.Width
== 1.0 || broken(bounds
.Width
== 0.0) /* xp sp1 */,
1609 "expected 1.0, got %f\n", bounds
.Width
);
1610 ok(bounds
.Height
== 1.0 || broken(bounds
.Height
== 0.0) /* xp sp1 */,
1611 "expected 1.0, got %f\n", bounds
.Height
);
1613 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
1616 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
1618 expect(UnitPixel
, unit
);
1619 expectf(0.0, bounds
.X
);
1620 expectf(0.0, bounds
.Y
);
1621 ok(bounds
.Width
== 1.0 || broken(bounds
.Width
== 0.0) /* xp sp1 */,
1622 "expected 1.0, got %f\n", bounds
.Width
);
1623 ok(bounds
.Height
== 1.0 || broken(bounds
.Height
== 0.0) /* xp sp1 */,
1624 "expected 1.0, got %f\n", bounds
.Height
);
1626 stat
= GdipDeleteGraphics(graphics
);
1629 stat
= GdipGetImageHorizontalResolution((GpImage
*)metafile
, &dpix
);
1632 stat
= GdipGetImageVerticalResolution((GpImage
*)metafile
, &dpiy
);
1635 stat
= GdipGetImageBounds((GpImage
*)metafile
, &bounds
, &unit
);
1637 expect(UnitPixel
, unit
);
1638 expectf(0.0, bounds
.X
);
1639 expectf(0.0, bounds
.Y
);
1640 expectf_(5.0 * dpix
, bounds
.Width
, 1.0);
1641 expectf_(5.0 * dpiy
, bounds
.Height
, 1.0);
1643 stat
= GdipDisposeImage((GpImage
*)metafile
);
1647 START_TEST(metafile
)
1649 struct GdiplusStartupInput gdiplusStartupInput
;
1650 ULONG_PTR gdiplusToken
;
1654 gdiplusStartupInput
.GdiplusVersion
= 1;
1655 gdiplusStartupInput
.DebugEventCallback
= NULL
;
1656 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
1657 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
1659 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
1661 myARGC
= winetest_get_mainargs( &myARGV
);
1665 if (!strcmp(myARGV
[2], "save"))
1666 save_metafiles
= TRUE
;
1667 else if (!strcmp(myARGV
[2], "load"))
1668 load_metafiles
= TRUE
;
1676 test_nullframerect();
1677 test_pagetransform();
1678 test_worldtransform();
1679 test_converttoemfplus();
1682 GdiplusShutdown(gdiplusToken
);