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
21 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
27 #include <wine/test.h>
32 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
33 #define expectf(expected, got) ok(fabs((expected) - (got)) < 0.0001, "Expected %f, got %f\n", (expected), (got))
35 static BOOL save_metafiles
;
37 typedef struct emfplus_record
44 typedef struct emfplus_check_state
48 const struct emfplus_record
*expected
;
50 } emfplus_check_state
;
52 static void check_record(int count
, const char *desc
, const struct emfplus_record
*expected
, const struct emfplus_record
*actual
)
55 todo_wine
ok(expected
->record_type
== actual
->record_type
,
56 "%s.%i: Expected record type 0x%x, got 0x%x\n", desc
, count
,
57 expected
->record_type
, actual
->record_type
);
59 ok(expected
->record_type
== actual
->record_type
,
60 "%s.%i: Expected record type 0x%x, got 0x%x\n", desc
, count
,
61 expected
->record_type
, actual
->record_type
);
64 typedef struct EmfPlusRecordHeader
70 } EmfPlusRecordHeader
;
72 static int CALLBACK
enum_emf_proc(HDC hDC
, HANDLETABLE
*lpHTable
, const ENHMETARECORD
*lpEMFR
,
73 int nObj
, LPARAM lpData
)
75 emfplus_check_state
*state
= (emfplus_check_state
*)lpData
;
76 emfplus_record actual
;
78 if (lpEMFR
->iType
== EMR_GDICOMMENT
)
80 const EMRGDICOMMENT
*comment
= (const EMRGDICOMMENT
*)lpEMFR
;
82 if (comment
->cbData
>= 4 && memcmp(comment
->Data
, "EMF+", 4) == 0)
86 while (offset
+ sizeof(EmfPlusRecordHeader
) <= comment
->cbData
)
88 const EmfPlusRecordHeader
*record
= (const EmfPlusRecordHeader
*)&comment
->Data
[offset
];
90 ok(record
->Size
== record
->DataSize
+ sizeof(EmfPlusRecordHeader
),
91 "%s: EMF+ record datasize %u and size %u mismatch\n", state
->desc
, record
->DataSize
, record
->Size
);
93 ok(offset
+ record
->DataSize
<= comment
->cbData
,
94 "%s: EMF+ record truncated\n", state
->desc
);
96 if (offset
+ record
->DataSize
> comment
->cbData
)
99 if (state
->expected
[state
->count
].record_type
)
102 actual
.record_type
= record
->Type
;
104 check_record(state
->count
, state
->desc
, &state
->expected
[state
->count
], &actual
);
110 ok(0, "%s: Unexpected EMF+ 0x%x record\n", state
->desc
, record
->Type
);
113 offset
+= record
->Size
;
116 ok(offset
== comment
->cbData
, "%s: truncated EMF+ record data?\n", state
->desc
);
122 if (state
->expected
[state
->count
].record_type
)
125 actual
.record_type
= lpEMFR
->iType
;
127 check_record(state
->count
, state
->desc
, &state
->expected
[state
->count
], &actual
);
133 ok(0, "%s: Unexpected EMF 0x%x record\n", state
->desc
, lpEMFR
->iType
);
139 static void check_emfplus(HENHMETAFILE hemf
, const emfplus_record
*expected
, const char *desc
)
141 emfplus_check_state state
;
145 state
.expected
= expected
;
147 EnumEnhMetaFile(0, hemf
, enum_emf_proc
, &state
, NULL
);
149 if (expected
[state
.count
].todo
)
150 todo_wine
ok(expected
[state
.count
].record_type
== 0, "%s: Got %i records, expecting more\n", desc
, state
.count
);
152 ok(expected
[state
.count
].record_type
== 0, "%s: Got %i records, expecting more\n", desc
, state
.count
);
155 static BOOL CALLBACK
enum_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
156 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
158 emfplus_check_state
*state
= (emfplus_check_state
*)userdata
;
159 emfplus_record actual
;
162 actual
.record_type
= record_type
;
165 ok(pStr
== NULL
, "non-NULL pStr\n");
167 if (state
->expected
[state
->count
].record_type
)
169 check_record(state
->count
, state
->desc
, &state
->expected
[state
->count
], &actual
);
175 ok(0, "%s: Unexpected EMF 0x%x record\n", state
->desc
, record_type
);
181 static void check_metafile(GpMetafile
*metafile
, const emfplus_record
*expected
, const char *desc
,
182 const GpPointF
*dst_points
, const GpRectF
*src_rect
, Unit src_unit
)
186 GpGraphics
*graphics
;
187 emfplus_check_state state
;
191 state
.expected
= expected
;
192 state
.metafile
= metafile
;
194 hdc
= CreateCompatibleDC(0);
196 stat
= GdipCreateFromHDC(hdc
, &graphics
);
199 stat
= GdipEnumerateMetafileSrcRectDestPoints(graphics
, metafile
, dst_points
,
200 3, src_rect
, src_unit
, enum_metafile_proc
, &state
, NULL
);
203 if (expected
[state
.count
].todo
)
204 todo_wine
ok(expected
[state
.count
].record_type
== 0, "%s: Got %i records, expecting more\n", desc
, state
.count
);
206 ok(expected
[state
.count
].record_type
== 0, "%s: Got %i records, expecting more\n", desc
, state
.count
);
208 GdipDeleteGraphics(graphics
);
213 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
214 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
216 emfplus_check_state
*state
= (emfplus_check_state
*)userdata
;
219 stat
= GdipPlayMetafileRecord(state
->metafile
, record_type
, flags
, dataSize
, pStr
);
221 if (state
->expected
[state
->count
].record_type
)
223 if (state
->expected
[state
->count
].playback_todo
)
224 todo_wine
ok(stat
== Ok
, "%s.%i: GdipPlayMetafileRecord failed with stat %i\n", state
->desc
, state
->count
, stat
);
226 ok(stat
== Ok
, "%s.%i: GdipPlayMetafileRecord failed with stat %i\n", state
->desc
, state
->count
, stat
);
231 if (state
->expected
[state
->count
].playback_todo
)
232 todo_wine
ok(0, "%s: too many records\n", state
->desc
);
234 ok(0, "%s: too many records\n", state
->desc
);
242 static void play_metafile(GpMetafile
*metafile
, GpGraphics
*graphics
, const emfplus_record
*expected
,
243 const char *desc
, const GpPointF
*dst_points
, const GpRectF
*src_rect
, Unit src_unit
)
246 emfplus_check_state state
;
250 state
.expected
= expected
;
251 state
.metafile
= metafile
;
253 stat
= GdipEnumerateMetafileSrcRectDestPoints(graphics
, metafile
, dst_points
,
254 3, src_rect
, src_unit
, play_metafile_proc
, &state
, NULL
);
258 static void save_metafile(GpMetafile
*metafile
, const char *filename
)
266 stat
= GdipCloneImage((GpImage
*)metafile
, (GpImage
**)&clone
);
269 stat
= GdipGetHemfFromMetafile(clone
, &hemf
);
272 DeleteEnhMetaFile(CopyEnhMetaFileA(hemf
, filename
));
274 DeleteEnhMetaFile(hemf
);
276 stat
= GdipDisposeImage((GpImage
*)clone
);
281 static const emfplus_record empty_records
[] = {
283 {0, EmfPlusRecordTypeHeader
},
284 {0, EmfPlusRecordTypeEndOfFile
},
289 static void test_empty(void)
292 GpMetafile
*metafile
;
293 GpGraphics
*graphics
;
295 HENHMETAFILE hemf
, dummy
;
297 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
298 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
299 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
301 hdc
= CreateCompatibleDC(0);
303 stat
= GdipRecordMetafile(NULL
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
304 expect(InvalidParameter
, stat
);
306 stat
= GdipRecordMetafile(hdc
, MetafileTypeInvalid
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
307 expect(InvalidParameter
, stat
);
309 stat
= GdipRecordMetafile(hdc
, MetafileTypeWmf
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
310 expect(InvalidParameter
, stat
);
312 stat
= GdipRecordMetafile(hdc
, MetafileTypeWmfPlaceable
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
313 expect(InvalidParameter
, stat
);
315 stat
= GdipRecordMetafile(hdc
, MetafileTypeEmfPlusDual
+1, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
316 expect(InvalidParameter
, stat
);
318 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, NULL
);
319 expect(InvalidParameter
, stat
);
321 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
329 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
330 expect(InvalidParameter
, stat
);
332 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
335 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
336 expect(InvalidParameter
, stat
);
338 stat
= GdipDeleteGraphics(graphics
);
341 check_metafile(metafile
, empty_records
, "empty metafile", dst_points
, &frame
, UnitPixel
);
343 save_metafile(metafile
, "empty.emf");
345 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
348 stat
= GdipGetHemfFromMetafile(metafile
, &dummy
);
349 expect(InvalidParameter
, stat
);
351 stat
= GdipDisposeImage((GpImage
*)metafile
);
354 check_emfplus(hemf
, empty_records
, "empty emf");
356 ret
= DeleteEnhMetaFile(hemf
);
357 ok(ret
!= 0, "Failed to delete enhmetafile %p\n", hemf
);
360 static const emfplus_record getdc_records
[] = {
362 {0, EmfPlusRecordTypeHeader
},
363 {0, EmfPlusRecordTypeGetDC
},
364 {0, EMR_CREATEBRUSHINDIRECT
},
365 {0, EMR_SELECTOBJECT
},
367 {0, EMR_SELECTOBJECT
},
368 {0, EMR_DELETEOBJECT
},
369 {0, EmfPlusRecordTypeEndOfFile
},
374 static void test_getdc(void)
377 GpMetafile
*metafile
;
378 GpGraphics
*graphics
;
379 HDC hdc
, metafile_dc
;
382 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
383 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
384 static const GpPointF dst_points_half
[3] = {{0.0,0.0},{50.0,0.0},{0.0,50.0}};
385 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
386 HBRUSH hbrush
, holdbrush
;
390 hdc
= CreateCompatibleDC(0);
392 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
400 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
401 expect(InvalidParameter
, stat
);
403 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
406 stat
= GdipGetDC(graphics
, &metafile_dc
);
411 GdipDeleteGraphics(graphics
);
412 GdipDisposeImage((GpImage
*)metafile
);
416 hbrush
= CreateSolidBrush(0xff0000);
418 holdbrush
= SelectObject(metafile_dc
, hbrush
);
420 Rectangle(metafile_dc
, 25, 25, 75, 75);
422 SelectObject(metafile_dc
, holdbrush
);
424 DeleteObject(hbrush
);
426 stat
= GdipReleaseDC(graphics
, metafile_dc
);
429 stat
= GdipDeleteGraphics(graphics
);
432 check_metafile(metafile
, getdc_records
, "getdc metafile", dst_points
, &frame
, UnitPixel
);
434 save_metafile(metafile
, "getdc.emf");
436 stat
= GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB
, NULL
, &bitmap
);
439 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
442 play_metafile(metafile
, graphics
, getdc_records
, "getdc playback", dst_points
, &frame
, UnitPixel
);
444 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
448 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
450 expect(0xff0000ff, color
);
452 stat
= GdipBitmapSetPixel(bitmap
, 50, 50, 0);
455 play_metafile(metafile
, graphics
, getdc_records
, "getdc playback", dst_points_half
, &frame
, UnitPixel
);
457 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
459 expect(0xff0000ff, color
);
461 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
465 stat
= GdipBitmapSetPixel(bitmap
, 15, 15, 0);
468 stat
= GdipDrawImagePointsRect(graphics
, (GpImage
*)metafile
, dst_points
, 3,
469 0.0, 0.0, 100.0, 100.0, UnitPixel
, NULL
, NULL
, NULL
);
472 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
476 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
478 expect(0xff0000ff, color
);
480 stat
= GdipDeleteGraphics(graphics
);
483 stat
= GdipDisposeImage((GpImage
*)bitmap
);
486 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
489 stat
= GdipDisposeImage((GpImage
*)metafile
);
492 check_emfplus(hemf
, getdc_records
, "getdc emf");
494 ret
= DeleteEnhMetaFile(hemf
);
495 ok(ret
!= 0, "Failed to delete enhmetafile %p\n", hemf
);
498 static const emfplus_record emfonly_records
[] = {
500 {0, EMR_CREATEBRUSHINDIRECT
},
501 {0, EMR_SELECTOBJECT
},
503 {0, EMR_SELECTOBJECT
},
504 {0, EMR_DELETEOBJECT
},
509 static void test_emfonly(void)
512 GpMetafile
*metafile
;
514 GpGraphics
*graphics
;
515 HDC hdc
, metafile_dc
;
518 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
519 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
520 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
521 HBRUSH hbrush
, holdbrush
;
525 hdc
= CreateCompatibleDC(0);
527 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
535 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
536 expect(InvalidParameter
, stat
);
538 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
541 stat
= GdipGetDC(graphics
, &metafile_dc
);
546 GdipDeleteGraphics(graphics
);
547 GdipDisposeImage((GpImage
*)metafile
);
551 hbrush
= CreateSolidBrush(0xff0000);
553 holdbrush
= SelectObject(metafile_dc
, hbrush
);
555 Rectangle(metafile_dc
, 25, 25, 75, 75);
557 SelectObject(metafile_dc
, holdbrush
);
559 DeleteObject(hbrush
);
561 stat
= GdipReleaseDC(graphics
, metafile_dc
);
564 stat
= GdipDeleteGraphics(graphics
);
567 check_metafile(metafile
, emfonly_records
, "emfonly metafile", dst_points
, &frame
, UnitPixel
);
569 save_metafile(metafile
, "emfonly.emf");
571 stat
= GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB
, NULL
, &bitmap
);
574 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
577 play_metafile(metafile
, graphics
, emfonly_records
, "emfonly playback", dst_points
, &frame
, UnitPixel
);
579 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
583 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
585 expect(0xff0000ff, color
);
587 stat
= GdipBitmapSetPixel(bitmap
, 50, 50, 0);
590 stat
= GdipDrawImagePointsRect(graphics
, (GpImage
*)metafile
, dst_points
, 3,
591 0.0, 0.0, 100.0, 100.0, UnitPixel
, NULL
, NULL
, NULL
);
594 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
598 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
600 expect(0xff0000ff, color
);
602 stat
= GdipCloneImage((GpImage
*)metafile
, &clone
);
607 stat
= GdipBitmapSetPixel(bitmap
, 50, 50, 0);
610 stat
= GdipDrawImagePointsRect(graphics
, clone
, dst_points
, 3,
611 0.0, 0.0, 100.0, 100.0, UnitPixel
, NULL
, NULL
, NULL
);
614 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
618 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
620 expect(0xff0000ff, color
);
622 GdipDisposeImage(clone
);
625 stat
= GdipDeleteGraphics(graphics
);
628 stat
= GdipDisposeImage((GpImage
*)bitmap
);
631 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
634 stat
= GdipDisposeImage((GpImage
*)metafile
);
637 check_emfplus(hemf
, emfonly_records
, "emfonly emf");
639 ret
= DeleteEnhMetaFile(hemf
);
640 ok(ret
!= 0, "Failed to delete enhmetafile %p\n", hemf
);
643 static const emfplus_record fillrect_records
[] = {
645 {0, EmfPlusRecordTypeHeader
},
646 {0, EmfPlusRecordTypeFillRects
},
647 {0, EmfPlusRecordTypeEndOfFile
},
652 static void test_fillrect(void)
655 GpMetafile
*metafile
;
656 GpGraphics
*graphics
;
659 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
660 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
661 static const GpPointF dst_points_half
[3] = {{0.0,0.0},{50.0,0.0},{0.0,50.0}};
662 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
667 hdc
= CreateCompatibleDC(0);
669 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
677 stat
= GdipGetHemfFromMetafile(metafile
, &hemf
);
678 expect(InvalidParameter
, stat
);
680 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
683 stat
= GdipCreateSolidFill((ARGB
)0xff0000ff, (GpSolidFill
**)&brush
);
686 stat
= GdipFillRectangleI(graphics
, brush
, 25, 25, 75, 75);
689 stat
= GdipDeleteBrush(brush
);
692 stat
= GdipDeleteGraphics(graphics
);
695 check_metafile(metafile
, fillrect_records
, "fillrect metafile", dst_points
, &frame
, UnitPixel
);
697 save_metafile(metafile
, "fillrect.emf");
699 stat
= GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB
, NULL
, &bitmap
);
702 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
705 play_metafile(metafile
, graphics
, fillrect_records
, "fillrect playback", dst_points
, &frame
, UnitPixel
);
707 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
711 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
713 expect(0xff0000ff, color
);
715 stat
= GdipBitmapSetPixel(bitmap
, 50, 50, 0);
718 play_metafile(metafile
, graphics
, fillrect_records
, "fillrect playback", dst_points_half
, &frame
, UnitPixel
);
720 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
722 expect(0xff0000ff, color
);
724 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
728 stat
= GdipBitmapSetPixel(bitmap
, 15, 15, 0);
731 stat
= GdipDrawImagePointsRect(graphics
, (GpImage
*)metafile
, dst_points
, 3,
732 0.0, 0.0, 100.0, 100.0, UnitPixel
, NULL
, NULL
, NULL
);
735 stat
= GdipBitmapGetPixel(bitmap
, 15, 15, &color
);
739 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
741 expect(0xff0000ff, color
);
743 stat
= GdipDeleteGraphics(graphics
);
746 stat
= GdipDisposeImage((GpImage
*)bitmap
);
749 stat
= GdipDisposeImage((GpImage
*)metafile
);
753 static const emfplus_record pagetransform_records
[] = {
755 {0, EmfPlusRecordTypeHeader
},
756 {0, EmfPlusRecordTypeFillRects
},
757 {0, EmfPlusRecordTypeSetPageTransform
},
758 {0, EmfPlusRecordTypeFillRects
},
759 {0, EmfPlusRecordTypeSetPageTransform
},
760 {0, EmfPlusRecordTypeFillRects
},
761 {0, EmfPlusRecordTypeSetPageTransform
},
762 {0, EmfPlusRecordTypeFillRects
},
763 {0, EmfPlusRecordTypeSetPageTransform
},
764 {0, EmfPlusRecordTypeFillRects
},
765 {0, EmfPlusRecordTypeEndOfFile
},
770 static void test_pagetransform(void)
773 GpMetafile
*metafile
;
774 GpGraphics
*graphics
;
776 static const GpRectF frame
= {0.0, 0.0, 5.0, 5.0};
777 static const GpPointF dst_points
[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}};
778 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
783 REAL scale
, dpix
, dpiy
;
786 hdc
= CreateCompatibleDC(0);
788 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitInch
, description
, &metafile
);
796 stat
= GdipGetImageHorizontalResolution((GpImage
*)metafile
, &dpix
);
797 todo_wine
expect(InvalidParameter
, stat
);
799 stat
= GdipGetImageVerticalResolution((GpImage
*)metafile
, &dpiy
);
800 todo_wine
expect(InvalidParameter
, stat
);
802 stat
= GdipGetImageWidth((GpImage
*)metafile
, &width
);
803 todo_wine
expect(InvalidParameter
, stat
);
805 stat
= GdipGetImageHeight((GpImage
*)metafile
, &height
);
806 todo_wine
expect(InvalidParameter
, stat
);
808 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
812 stat
= GdipGetPageUnit(graphics
, &unit
);
814 expect(UnitDisplay
, unit
);
816 stat
= GdipGetPageScale(graphics
, &scale
);
820 stat
= GdipGetDpiX(graphics
, &dpix
);
824 stat
= GdipGetDpiY(graphics
, &dpiy
);
828 stat
= GdipCreateSolidFill((ARGB
)0xff0000ff, (GpSolidFill
**)&brush
);
831 stat
= GdipFillRectangleI(graphics
, brush
, 1, 2, 1, 1);
834 stat
= GdipDeleteBrush(brush
);
837 /* page unit = pixels */
838 stat
= GdipSetPageUnit(graphics
, UnitPixel
);
841 stat
= GdipGetPageUnit(graphics
, &unit
);
843 expect(UnitPixel
, unit
);
845 stat
= GdipCreateSolidFill((ARGB
)0xff00ff00, (GpSolidFill
**)&brush
);
848 stat
= GdipFillRectangleI(graphics
, brush
, 0, 1, 1, 1);
851 stat
= GdipDeleteBrush(brush
);
854 /* page scale = 3, unit = pixels */
855 stat
= GdipSetPageScale(graphics
, 3.0);
858 stat
= GdipGetPageScale(graphics
, &scale
);
862 stat
= GdipCreateSolidFill((ARGB
)0xff00ffff, (GpSolidFill
**)&brush
);
865 stat
= GdipFillRectangleI(graphics
, brush
, 0, 1, 2, 2);
868 stat
= GdipDeleteBrush(brush
);
871 /* page scale = 3, unit = inches */
872 stat
= GdipSetPageUnit(graphics
, UnitInch
);
875 stat
= GdipGetPageUnit(graphics
, &unit
);
877 expect(UnitInch
, unit
);
879 stat
= GdipCreateSolidFill((ARGB
)0xffff0000, (GpSolidFill
**)&brush
);
882 stat
= GdipFillRectangle(graphics
, brush
, 1.0/96.0, 0, 1, 1);
885 stat
= GdipDeleteBrush(brush
);
888 /* page scale = 3, unit = display */
889 stat
= GdipSetPageUnit(graphics
, UnitDisplay
);
892 stat
= GdipGetPageUnit(graphics
, &unit
);
894 expect(UnitDisplay
, unit
);
896 stat
= GdipCreateSolidFill((ARGB
)0xffff00ff, (GpSolidFill
**)&brush
);
899 stat
= GdipFillRectangle(graphics
, brush
, 3, 3, 2, 2);
902 stat
= GdipDeleteBrush(brush
);
905 stat
= GdipDeleteGraphics(graphics
);
908 check_metafile(metafile
, pagetransform_records
, "pagetransform metafile", dst_points
, &frame
, UnitPixel
);
910 save_metafile(metafile
, "pagetransform.emf");
912 stat
= GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB
, NULL
, &bitmap
);
915 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
918 play_metafile(metafile
, graphics
, pagetransform_records
, "pagetransform playback", dst_points
, &frame
, UnitPixel
);
920 stat
= GdipBitmapGetPixel(bitmap
, 50, 50, &color
);
924 stat
= GdipBitmapGetPixel(bitmap
, 30, 50, &color
);
926 expect(0xff0000ff, color
);
928 stat
= GdipBitmapGetPixel(bitmap
, 10, 30, &color
);
930 expect(0xff00ff00, color
);
932 stat
= GdipBitmapGetPixel(bitmap
, 20, 80, &color
);
934 expect(0xff00ffff, color
);
936 stat
= GdipBitmapGetPixel(bitmap
, 80, 20, &color
);
938 expect(0xffff0000, color
);
940 stat
= GdipBitmapGetPixel(bitmap
, 80, 80, &color
);
942 expect(0xffff00ff, color
);
944 stat
= GdipDeleteGraphics(graphics
);
947 stat
= GdipDisposeImage((GpImage
*)bitmap
);
950 stat
= GdipDisposeImage((GpImage
*)metafile
);
954 static void test_converttoemfplus(void)
956 GpStatus (WINAPI
*pGdipConvertToEmfPlus
)( const GpGraphics
*graphics
, GpMetafile
*metafile
, BOOL
*succ
,
957 EmfType emfType
, const WCHAR
*description
, GpMetafile
**outmetafile
);
958 static const GpRectF frame
= {0.0, 0.0, 100.0, 100.0};
959 static const WCHAR description
[] = {'w','i','n','e','t','e','s','t',0};
961 GpMetafile
*metafile
, *metafile2
= NULL
, *emhmeta
;
962 GpGraphics
*graphics
;
965 HMODULE mod
= GetModuleHandleA("gdiplus.dll");
967 pGdipConvertToEmfPlus
= (void*)GetProcAddress( mod
, "GdipConvertToEmfPlus");
968 if(!pGdipConvertToEmfPlus
)
970 /* GdipConvertToEmfPlus was introduced in Windows Vista. */
971 win_skip("GDIPlus version 1.1 not available\n");
975 hdc
= CreateCompatibleDC(0);
977 stat
= GdipRecordMetafile(hdc
, MetafileTypeEmf
, &frame
, MetafileFrameUnitPixel
, description
, &metafile
);
980 stat
= GdipRecordMetafile(hdc
, EmfTypeEmfPlusOnly
, &frame
, MetafileFrameUnitPixel
, description
, &emhmeta
);
988 stat
= GdipGetImageGraphicsContext((GpImage
*)metafile
, &graphics
);
991 /* Invalid Parameters */
992 stat
= pGdipConvertToEmfPlus(NULL
, metafile
, &succ
, EmfTypeEmfPlusOnly
, description
, &metafile2
);
993 expect(InvalidParameter
, stat
);
995 stat
= pGdipConvertToEmfPlus(graphics
, NULL
, &succ
, EmfTypeEmfPlusOnly
, description
, &metafile2
);
996 expect(InvalidParameter
, stat
);
998 stat
= pGdipConvertToEmfPlus(graphics
, metafile
, &succ
, EmfTypeEmfPlusOnly
, description
, NULL
);
999 expect(InvalidParameter
, stat
);
1001 stat
= pGdipConvertToEmfPlus(graphics
, metafile
, NULL
, MetafileTypeInvalid
, NULL
, &metafile2
);
1002 expect(InvalidParameter
, stat
);
1004 stat
= pGdipConvertToEmfPlus(graphics
, metafile
, NULL
, MetafileTypeEmfPlusDual
+1, NULL
, &metafile2
);
1005 expect(InvalidParameter
, stat
);
1007 /* If we are already an Enhanced Metafile then the conversion fails. */
1008 stat
= pGdipConvertToEmfPlus(graphics
, emhmeta
, NULL
, EmfTypeEmfPlusOnly
, NULL
, &metafile2
);
1009 todo_wine
expect(InvalidParameter
, stat
);
1011 stat
= pGdipConvertToEmfPlus(graphics
, metafile
, NULL
, EmfTypeEmfPlusOnly
, NULL
, &metafile2
);
1012 todo_wine
expect(Ok
, stat
);
1014 GdipDisposeImage((GpImage
*)metafile2
);
1017 stat
= pGdipConvertToEmfPlus(graphics
, metafile
, &succ
, EmfTypeEmfPlusOnly
, NULL
, &metafile2
);
1018 todo_wine
expect(Ok
, stat
);
1020 GdipDisposeImage((GpImage
*)metafile2
);
1022 stat
= GdipDeleteGraphics(graphics
);
1025 stat
= GdipDisposeImage((GpImage
*)metafile
);
1028 stat
= GdipDisposeImage((GpImage
*)emhmeta
);
1032 START_TEST(metafile
)
1034 struct GdiplusStartupInput gdiplusStartupInput
;
1035 ULONG_PTR gdiplusToken
;
1039 gdiplusStartupInput
.GdiplusVersion
= 1;
1040 gdiplusStartupInput
.DebugEventCallback
= NULL
;
1041 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
1042 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
1044 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
1046 myARGC
= winetest_get_mainargs( &myARGV
);
1048 if (myARGC
>= 3 && !strcmp(myARGV
[2], "save"))
1049 save_metafiles
= TRUE
;
1055 test_pagetransform();
1056 test_converttoemfplus();
1058 GdiplusShutdown(gdiplusToken
);