gdiplus: Implement recording/playback for RotateWorldTransform.
[wine.git] / dlls / gdiplus / tests / metafile.c
blob67e2b9d8cdc5446a910bb5c135f50d943125b133
1 /*
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 #include <math.h>
23 #include "objbase.h"
24 #include "gdiplus.h"
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
36 BOOL todo;
37 ULONG record_type;
38 BOOL playback_todo;
39 } emfplus_record;
41 typedef struct emfplus_check_state
43 const char *desc;
44 int count;
45 const struct emfplus_record *expected;
46 GpMetafile *metafile;
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
59 WORD Type;
60 WORD Flags;
61 DWORD Size;
62 DWORD DataSize;
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)
77 int offset = 4;
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)
90 return 0;
92 if (state->expected[state->count].record_type)
94 actual.todo = FALSE;
95 actual.record_type = record->Type;
97 check_record(state->count, state->desc, &state->expected[state->count], &actual);
99 state->count++;
101 else
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);
111 return 1;
115 if (state->expected[state->count].record_type)
117 actual.todo = FALSE;
118 actual.record_type = lpEMFR->iType;
120 check_record(state->count, state->desc, &state->expected[state->count], &actual);
122 state->count++;
124 else
126 ok(0, "%s: Unexpected EMF 0x%x record\n", state->desc, lpEMFR->iType);
129 return 1;
132 static void check_emfplus(HENHMETAFILE hemf, const emfplus_record *expected, const char *desc)
134 emfplus_check_state state;
136 state.desc = desc;
137 state.count = 0;
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;
152 actual.todo = FALSE;
153 actual.record_type = record_type;
155 if (dataSize == 0)
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);
162 state->count++;
164 else
166 ok(0, "%s: Unexpected EMF 0x%x record\n", state->desc, record_type);
169 return TRUE;
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)
175 GpStatus stat;
176 HDC hdc;
177 GpGraphics *graphics;
178 emfplus_check_state state;
180 state.desc = desc;
181 state.count = 0;
182 state.expected = expected;
183 state.metafile = metafile;
185 hdc = CreateCompatibleDC(0);
187 stat = GdipCreateFromHDC(hdc, &graphics);
188 expect(Ok, stat);
190 stat = GdipEnumerateMetafileSrcRectDestPoints(graphics, metafile, dst_points,
191 3, src_rect, src_unit, enum_metafile_proc, &state, NULL);
192 expect(Ok, stat);
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);
199 DeleteDC(hdc);
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;
206 GpStatus stat;
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);
214 state->count++;
216 else
218 todo_wine_if (state->expected[state->count].playback_todo)
219 ok(0, "%s: too many records\n", state->desc);
221 return FALSE;
224 return TRUE;
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)
230 GpStatus stat;
231 emfplus_check_state state;
233 state.desc = desc;
234 state.count = 0;
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);
240 expect(Ok, stat);
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)
247 GpStatus stat;
248 if (save_metafiles)
250 GpMetafile *clone;
251 HENHMETAFILE hemf;
253 stat = GdipCloneImage((GpImage*)*metafile, (GpImage**)&clone);
254 expect(Ok, stat);
256 stat = GdipGetHemfFromMetafile(clone, &hemf);
257 expect(Ok, stat);
259 DeleteEnhMetaFile(CopyEnhMetaFileA(hemf, filename));
261 DeleteEnhMetaFile(hemf);
263 stat = GdipDisposeImage((GpImage*)clone);
264 expect(Ok, stat);
266 else if (load_metafiles)
268 HENHMETAFILE hemf;
270 stat = GdipDisposeImage((GpImage*)*metafile);
271 expect(Ok, stat);
272 *metafile = NULL;
274 hemf = GetEnhMetaFileA(filename);
275 ok(hemf != NULL, "%s could not be opened\n", filename);
277 stat = GdipCreateMetafileFromEmf(hemf, TRUE, metafile);
278 expect(Ok, stat);
282 static const emfplus_record empty_records[] = {
283 {0, EMR_HEADER},
284 {0, EmfPlusRecordTypeHeader},
285 {0, EmfPlusRecordTypeEndOfFile},
286 {0, EMR_EOF},
290 static void test_empty(void)
292 GpStatus stat;
293 GpMetafile *metafile;
294 GpGraphics *graphics;
295 HDC hdc;
296 GpRectF bounds;
297 GpUnit unit;
298 REAL xres, yres;
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);
326 expect(Ok, stat);
328 DeleteDC(hdc);
330 if (stat != Ok)
331 return;
333 stat = GdipGetHemfFromMetafile(metafile, &hemf);
334 expect(InvalidParameter, stat);
336 stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics);
337 expect(Ok, stat);
339 stat = GdipGetHemfFromMetafile(metafile, &hemf);
340 expect(InvalidParameter, stat);
342 stat = GdipDeleteGraphics(graphics);
343 expect(Ok, stat);
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);
350 expect(Ok, stat);
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);
358 expect(Ok, stat);
360 stat = GdipGetImageVerticalResolution((GpImage*)metafile, &yres);
361 expect(Ok, stat);
363 stat = GdipGetHemfFromMetafile(metafile, &hemf);
364 expect(Ok, stat);
366 stat = GdipGetHemfFromMetafile(metafile, &dummy);
367 expect(InvalidParameter, stat);
369 stat = GdipDisposeImage((GpImage*)metafile);
370 expect(Ok, stat);
372 check_emfplus(hemf, empty_records, "empty emf");
374 memset(&header, 0xaa, sizeof(header));
375 stat = GdipGetMetafileHeaderFromEmf(hemf, &header);
376 expect(Ok, stat);
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);
385 expect(0, header.X);
386 expect(0, header.Y);
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);
403 expect(Ok, stat);
405 stat = GdipGetImageBounds((GpImage*)metafile, &bounds, &unit);
406 expect(Ok, stat);
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);
414 expect(Ok, stat);
415 expectf(header.DpiX, xres);
417 stat = GdipGetImageVerticalResolution((GpImage*)metafile, &yres);
418 expect(Ok, stat);
419 expectf(header.DpiY, yres);
421 stat = GdipDisposeImage((GpImage*)metafile);
422 expect(Ok, stat);
425 static const emfplus_record getdc_records[] = {
426 {0, EMR_HEADER},
427 {0, EmfPlusRecordTypeHeader},
428 {0, EmfPlusRecordTypeGetDC},
429 {0, EMR_CREATEBRUSHINDIRECT},
430 {0, EMR_SELECTOBJECT},
431 {0, EMR_RECTANGLE},
432 {0, EMR_SELECTOBJECT},
433 {0, EMR_DELETEOBJECT},
434 {0, EmfPlusRecordTypeEndOfFile},
435 {0, EMR_EOF},
439 static void test_getdc(void)
441 GpStatus stat;
442 GpMetafile *metafile;
443 GpGraphics *graphics;
444 HDC hdc, metafile_dc;
445 HENHMETAFILE hemf;
446 BOOL ret;
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;
452 GpBitmap *bitmap;
453 ARGB color;
455 hdc = CreateCompatibleDC(0);
457 stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, &frame, MetafileFrameUnitPixel, description, &metafile);
458 expect(Ok, stat);
460 DeleteDC(hdc);
462 if (stat != Ok)
463 return;
465 stat = GdipGetHemfFromMetafile(metafile, &hemf);
466 expect(InvalidParameter, stat);
468 stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics);
469 expect(Ok, stat);
471 stat = GdipGetDC(graphics, &metafile_dc);
472 expect(Ok, stat);
474 if (stat != Ok)
476 GdipDeleteGraphics(graphics);
477 GdipDisposeImage((GpImage*)metafile);
478 return;
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);
492 expect(Ok, stat);
494 stat = GdipDeleteGraphics(graphics);
495 expect(Ok, stat);
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);
502 expect(Ok, stat);
504 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
505 expect(Ok, stat);
507 play_metafile(metafile, graphics, getdc_records, "getdc playback", dst_points, &frame, UnitPixel);
509 stat = GdipBitmapGetPixel(bitmap, 15, 15, &color);
510 expect(Ok, stat);
511 expect(0, color);
513 stat = GdipBitmapGetPixel(bitmap, 50, 50, &color);
514 expect(Ok, stat);
515 expect(0xff0000ff, color);
517 stat = GdipBitmapSetPixel(bitmap, 50, 50, 0);
518 expect(Ok, stat);
520 play_metafile(metafile, graphics, getdc_records, "getdc playback", dst_points_half, &frame, UnitPixel);
522 stat = GdipBitmapGetPixel(bitmap, 15, 15, &color);
523 expect(Ok, stat);
524 expect(0xff0000ff, color);
526 stat = GdipBitmapGetPixel(bitmap, 50, 50, &color);
527 expect(Ok, stat);
528 expect(0, color);
530 stat = GdipBitmapSetPixel(bitmap, 15, 15, 0);
531 expect(Ok, stat);
533 stat = GdipDrawImagePointsRect(graphics, (GpImage*)metafile, dst_points, 3,
534 0.0, 0.0, 100.0, 100.0, UnitPixel, NULL, NULL, NULL);
535 expect(Ok, stat);
537 stat = GdipBitmapGetPixel(bitmap, 15, 15, &color);
538 expect(Ok, stat);
539 expect(0, color);
541 stat = GdipBitmapGetPixel(bitmap, 50, 50, &color);
542 expect(Ok, stat);
543 expect(0xff0000ff, color);
545 stat = GdipDeleteGraphics(graphics);
546 expect(Ok, stat);
548 stat = GdipDisposeImage((GpImage*)bitmap);
549 expect(Ok, stat);
551 stat = GdipGetHemfFromMetafile(metafile, &hemf);
552 expect(Ok, stat);
554 stat = GdipDisposeImage((GpImage*)metafile);
555 expect(Ok, stat);
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[] = {
564 {0, EMR_HEADER},
565 {0, EMR_CREATEBRUSHINDIRECT},
566 {0, EMR_SELECTOBJECT},
567 {0, EMR_RECTANGLE},
568 {0, EMR_SELECTOBJECT},
569 {0, EMR_DELETEOBJECT},
570 {0, EMR_EOF},
574 static void test_emfonly(void)
576 GpStatus stat;
577 GpMetafile *metafile;
578 GpImage *clone;
579 GpGraphics *graphics;
580 HDC hdc, metafile_dc;
581 GpRectF bounds;
582 GpUnit unit;
583 REAL xres, yres;
584 HENHMETAFILE hemf;
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;
590 GpBitmap *bitmap;
591 ARGB color;
593 hdc = CreateCompatibleDC(0);
595 stat = GdipRecordMetafile(hdc, EmfTypeEmfOnly, &frame, MetafileFrameUnitPixel, description, &metafile);
596 expect(Ok, stat);
598 DeleteDC(hdc);
600 if (stat != Ok)
601 return;
603 stat = GdipGetHemfFromMetafile(metafile, &hemf);
604 expect(InvalidParameter, stat);
606 stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics);
607 expect(Ok, stat);
609 stat = GdipGetDC(graphics, &metafile_dc);
610 expect(Ok, stat);
612 if (stat != Ok)
614 GdipDeleteGraphics(graphics);
615 GdipDisposeImage((GpImage*)metafile);
616 return;
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);
630 expect(Ok, stat);
632 stat = GdipDeleteGraphics(graphics);
633 expect(Ok, stat);
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);
640 expect(Ok, stat);
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);
648 expect(Ok, stat);
650 stat = GdipGetImageVerticalResolution((GpImage*)metafile, &yres);
651 expect(Ok, stat);
653 stat = GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB, NULL, &bitmap);
654 expect(Ok, stat);
656 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
657 expect(Ok, stat);
659 play_metafile(metafile, graphics, emfonly_records, "emfonly playback", dst_points, &frame, UnitPixel);
661 stat = GdipBitmapGetPixel(bitmap, 15, 15, &color);
662 expect(Ok, stat);
663 expect(0, color);
665 stat = GdipBitmapGetPixel(bitmap, 50, 50, &color);
666 expect(Ok, stat);
667 expect(0xff0000ff, color);
669 stat = GdipBitmapSetPixel(bitmap, 50, 50, 0);
670 expect(Ok, stat);
672 stat = GdipDrawImagePointsRect(graphics, (GpImage*)metafile, dst_points, 3,
673 0.0, 0.0, 100.0, 100.0, UnitPixel, NULL, NULL, NULL);
674 expect(Ok, stat);
676 stat = GdipBitmapGetPixel(bitmap, 15, 15, &color);
677 expect(Ok, stat);
678 expect(0, color);
680 stat = GdipBitmapGetPixel(bitmap, 50, 50, &color);
681 expect(Ok, stat);
682 expect(0xff0000ff, color);
684 stat = GdipCloneImage((GpImage*)metafile, &clone);
685 expect(Ok, stat);
687 if (stat == Ok)
689 stat = GdipBitmapSetPixel(bitmap, 50, 50, 0);
690 expect(Ok, stat);
692 stat = GdipDrawImagePointsRect(graphics, clone, dst_points, 3,
693 0.0, 0.0, 100.0, 100.0, UnitPixel, NULL, NULL, NULL);
694 expect(Ok, stat);
696 stat = GdipBitmapGetPixel(bitmap, 15, 15, &color);
697 expect(Ok, stat);
698 expect(0, color);
700 stat = GdipBitmapGetPixel(bitmap, 50, 50, &color);
701 expect(Ok, stat);
702 expect(0xff0000ff, color);
704 GdipDisposeImage(clone);
707 stat = GdipDeleteGraphics(graphics);
708 expect(Ok, stat);
710 stat = GdipDisposeImage((GpImage*)bitmap);
711 expect(Ok, stat);
713 stat = GdipGetHemfFromMetafile(metafile, &hemf);
714 expect(Ok, stat);
716 stat = GdipDisposeImage((GpImage*)metafile);
717 expect(Ok, stat);
719 check_emfplus(hemf, emfonly_records, "emfonly emf");
721 memset(&header, 0xaa, sizeof(header));
722 stat = GdipGetMetafileHeaderFromEmf(hemf, &header);
723 expect(Ok, stat);
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);
732 expect(0, header.X);
733 expect(0, header.Y);
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);
750 expect(Ok, stat);
752 stat = GdipGetImageBounds((GpImage*)metafile, &bounds, &unit);
753 expect(Ok, stat);
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);
761 expect(Ok, stat);
762 expectf(header.DpiX, xres);
764 stat = GdipGetImageVerticalResolution((GpImage*)metafile, &yres);
765 expect(Ok, stat);
766 expectf(header.DpiY, yres);
768 stat = GdipDisposeImage((GpImage*)metafile);
769 expect(Ok, stat);
772 static const emfplus_record fillrect_records[] = {
773 {0, EMR_HEADER},
774 {0, EmfPlusRecordTypeHeader},
775 {0, EmfPlusRecordTypeFillRects},
776 {0, EmfPlusRecordTypeEndOfFile},
777 {0, EMR_EOF},
781 static void test_fillrect(void)
783 GpStatus stat;
784 GpMetafile *metafile;
785 GpGraphics *graphics;
786 HDC hdc;
787 HENHMETAFILE hemf;
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};
792 GpBitmap *bitmap;
793 ARGB color;
794 GpBrush *brush;
796 hdc = CreateCompatibleDC(0);
798 stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, &frame, MetafileFrameUnitPixel, description, &metafile);
799 expect(Ok, stat);
801 DeleteDC(hdc);
803 if (stat != Ok)
804 return;
806 stat = GdipGetHemfFromMetafile(metafile, &hemf);
807 expect(InvalidParameter, stat);
809 stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics);
810 expect(Ok, stat);
812 stat = GdipCreateSolidFill((ARGB)0xff0000ff, (GpSolidFill**)&brush);
813 expect(Ok, stat);
815 stat = GdipFillRectangleI(graphics, brush, 25, 25, 75, 75);
816 expect(Ok, stat);
818 stat = GdipDeleteBrush(brush);
819 expect(Ok, stat);
821 stat = GdipDeleteGraphics(graphics);
822 expect(Ok, stat);
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);
829 expect(Ok, stat);
831 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
832 expect(Ok, stat);
834 play_metafile(metafile, graphics, fillrect_records, "fillrect playback", dst_points, &frame, UnitPixel);
836 stat = GdipBitmapGetPixel(bitmap, 15, 15, &color);
837 expect(Ok, stat);
838 expect(0, color);
840 stat = GdipBitmapGetPixel(bitmap, 50, 50, &color);
841 expect(Ok, stat);
842 expect(0xff0000ff, color);
844 stat = GdipBitmapSetPixel(bitmap, 50, 50, 0);
845 expect(Ok, stat);
847 play_metafile(metafile, graphics, fillrect_records, "fillrect playback", dst_points_half, &frame, UnitPixel);
849 stat = GdipBitmapGetPixel(bitmap, 15, 15, &color);
850 expect(Ok, stat);
851 expect(0xff0000ff, color);
853 stat = GdipBitmapGetPixel(bitmap, 50, 50, &color);
854 expect(Ok, stat);
855 expect(0, color);
857 stat = GdipBitmapSetPixel(bitmap, 15, 15, 0);
858 expect(Ok, stat);
860 stat = GdipDrawImagePointsRect(graphics, (GpImage*)metafile, dst_points, 3,
861 0.0, 0.0, 100.0, 100.0, UnitPixel, NULL, NULL, NULL);
862 expect(Ok, stat);
864 stat = GdipBitmapGetPixel(bitmap, 15, 15, &color);
865 expect(Ok, stat);
866 expect(0, color);
868 stat = GdipBitmapGetPixel(bitmap, 50, 50, &color);
869 expect(Ok, stat);
870 expect(0xff0000ff, color);
872 stat = GdipDeleteGraphics(graphics);
873 expect(Ok, stat);
875 stat = GdipDisposeImage((GpImage*)bitmap);
876 expect(Ok, stat);
878 stat = GdipDisposeImage((GpImage*)metafile);
879 expect(Ok, stat);
882 static const emfplus_record clear_emf_records[] = {
883 {0, EMR_HEADER},
884 {0, EmfPlusRecordTypeHeader},
885 {0, EmfPlusRecordTypeClear},
886 {1, EMR_SAVEDC},
887 {1, EMR_SETICMMODE},
888 {1, EMR_BITBLT},
889 {1, EMR_RESTOREDC},
890 {0, EmfPlusRecordTypeEndOfFile},
891 {0, EMR_EOF},
895 static void test_clear(void)
897 GpStatus stat;
898 GpMetafile *metafile;
899 GpGraphics *graphics;
900 HDC hdc;
901 HENHMETAFILE hemf;
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};
905 GpBitmap *bitmap;
906 ARGB color;
908 hdc = CreateCompatibleDC(0);
910 stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, &frame, MetafileFrameUnitPixel, description, &metafile);
911 expect(Ok, stat);
913 DeleteDC(hdc);
915 if (stat != Ok)
916 return;
918 stat = GdipGetHemfFromMetafile(metafile, &hemf);
919 expect(InvalidParameter, stat);
921 stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics);
922 expect(Ok, stat);
924 stat = GdipGraphicsClear(graphics, 0xffffff00);
925 expect(Ok, stat);
927 stat = GdipDeleteGraphics(graphics);
928 expect(Ok, stat);
930 sync_metafile(&metafile, "clear.emf");
932 stat = GdipCreateBitmapFromScan0(30, 30, 0, PixelFormat32bppRGB, NULL, &bitmap);
933 expect(Ok, stat);
935 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
936 expect(Ok, stat);
938 stat = GdipDrawImagePointsRect(graphics, (GpImage*)metafile, dst_points, 3,
939 0.0, 0.0, 100.0, 100.0, UnitPixel, NULL, NULL, NULL);
940 expect(Ok, stat);
942 stat = GdipBitmapGetPixel(bitmap, 5, 5, &color);
943 expect(Ok, stat);
944 expect(0xff000000, color);
946 stat = GdipBitmapGetPixel(bitmap, 15, 15, &color);
947 expect(Ok, stat);
948 expect(0xffffff00, color);
950 stat = GdipBitmapGetPixel(bitmap, 25, 25, &color);
951 expect(Ok, stat);
952 expect(0xff000000, color);
954 stat = GdipDeleteGraphics(graphics);
955 expect(Ok, stat);
957 stat = GdipDisposeImage((GpImage*)bitmap);
958 expect(Ok, stat);
960 stat = GdipGetHemfFromMetafile(metafile, &hemf);
961 expect(Ok, stat);
963 stat = GdipDisposeImage((GpImage*)metafile);
964 expect(Ok, stat);
966 check_emfplus(hemf, clear_emf_records, "clear emf");
968 DeleteEnhMetaFile(hemf);
971 static void test_nullframerect(void) {
972 GpStatus stat;
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};
977 GpBrush *brush;
978 HBRUSH hbrush, holdbrush;
979 GpRectF bounds;
980 GpUnit unit;
982 hdc = CreateCompatibleDC(0);
984 stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, NULL, MetafileFrameUnitPixel, description, &metafile);
985 expect(Ok, stat);
987 DeleteDC(hdc);
989 if (stat != Ok)
990 return;
992 stat = GdipGetImageBounds((GpImage*)metafile, &bounds, &unit);
993 expect(Ok, stat);
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);
1003 expect(Ok, stat);
1005 stat = GdipCreateSolidFill((ARGB)0xff0000ff, (GpSolidFill**)&brush);
1006 expect(Ok, stat);
1008 stat = GdipFillRectangleI(graphics, brush, 25, 25, 75, 75);
1009 expect(Ok, stat);
1011 stat = GdipDeleteBrush(brush);
1012 expect(Ok, stat);
1014 stat = GdipGetImageBounds((GpImage*)metafile, &bounds, &unit);
1015 expect(Ok, stat);
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);
1025 expect(Ok, stat);
1027 stat = GdipGetImageBounds((GpImage*)metafile, &bounds, &unit);
1028 expect(Ok, stat);
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);
1036 expect(Ok, stat);
1038 hdc = CreateCompatibleDC(0);
1040 stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, NULL, MetafileFrameUnitMillimeter, description, &metafile);
1041 expect(Ok, stat);
1043 DeleteDC(hdc);
1045 stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics);
1046 expect(Ok, stat);
1048 stat = GdipGetDC(graphics, &metafile_dc);
1049 expect(Ok, stat);
1051 if (stat != Ok)
1053 GdipDeleteGraphics(graphics);
1054 GdipDisposeImage((GpImage*)metafile);
1055 return;
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);
1069 expect(Ok, stat);
1071 stat = GdipDeleteGraphics(graphics);
1072 expect(Ok, stat);
1074 stat = GdipGetImageBounds((GpImage*)metafile, &bounds, &unit);
1075 expect(Ok, stat);
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);
1083 expect(Ok, stat);
1086 static const emfplus_record pagetransform_records[] = {
1087 {0, EMR_HEADER},
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},
1099 {0, EMR_EOF},
1103 static void test_pagetransform(void)
1105 GpStatus stat;
1106 GpMetafile *metafile;
1107 GpGraphics *graphics;
1108 HDC hdc;
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};
1112 GpBitmap *bitmap;
1113 ARGB color;
1114 GpBrush *brush;
1115 GpUnit unit;
1116 REAL scale, dpix, dpiy;
1117 UINT width, height;
1119 hdc = CreateCompatibleDC(0);
1121 stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, &frame, MetafileFrameUnitInch, description, &metafile);
1122 expect(Ok, stat);
1124 DeleteDC(hdc);
1126 if (stat != Ok)
1127 return;
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);
1142 expect(Ok, stat);
1144 /* initial scale */
1145 stat = GdipGetPageUnit(graphics, &unit);
1146 expect(Ok, stat);
1147 expect(UnitDisplay, unit);
1149 stat = GdipGetPageScale(graphics, &scale);
1150 expect(Ok, stat);
1151 expectf(1.0, scale);
1153 stat = GdipGetDpiX(graphics, &dpix);
1154 expect(Ok, stat);
1155 expectf(96.0, dpix);
1157 stat = GdipGetDpiY(graphics, &dpiy);
1158 expect(Ok, stat);
1159 expectf(96.0, dpiy);
1161 stat = GdipCreateSolidFill((ARGB)0xff0000ff, (GpSolidFill**)&brush);
1162 expect(Ok, stat);
1164 stat = GdipFillRectangleI(graphics, brush, 1, 2, 1, 1);
1165 expect(Ok, stat);
1167 stat = GdipDeleteBrush(brush);
1168 expect(Ok, stat);
1170 /* page unit = pixels */
1171 stat = GdipSetPageUnit(graphics, UnitPixel);
1172 expect(Ok, stat);
1174 stat = GdipGetPageUnit(graphics, &unit);
1175 expect(Ok, stat);
1176 expect(UnitPixel, unit);
1178 stat = GdipCreateSolidFill((ARGB)0xff00ff00, (GpSolidFill**)&brush);
1179 expect(Ok, stat);
1181 stat = GdipFillRectangleI(graphics, brush, 0, 1, 1, 1);
1182 expect(Ok, stat);
1184 stat = GdipDeleteBrush(brush);
1185 expect(Ok, stat);
1187 /* page scale = 3, unit = pixels */
1188 stat = GdipSetPageScale(graphics, 3.0);
1189 expect(Ok, stat);
1191 stat = GdipGetPageScale(graphics, &scale);
1192 expect(Ok, stat);
1193 expectf(3.0, scale);
1195 stat = GdipCreateSolidFill((ARGB)0xff00ffff, (GpSolidFill**)&brush);
1196 expect(Ok, stat);
1198 stat = GdipFillRectangleI(graphics, brush, 0, 1, 2, 2);
1199 expect(Ok, stat);
1201 stat = GdipDeleteBrush(brush);
1202 expect(Ok, stat);
1204 /* page scale = 3, unit = inches */
1205 stat = GdipSetPageUnit(graphics, UnitInch);
1206 expect(Ok, stat);
1208 stat = GdipGetPageUnit(graphics, &unit);
1209 expect(Ok, stat);
1210 expect(UnitInch, unit);
1212 stat = GdipCreateSolidFill((ARGB)0xffff0000, (GpSolidFill**)&brush);
1213 expect(Ok, stat);
1215 stat = GdipFillRectangle(graphics, brush, 1.0/96.0, 0, 1, 1);
1216 expect(Ok, stat);
1218 stat = GdipDeleteBrush(brush);
1219 expect(Ok, stat);
1221 /* page scale = 3, unit = display */
1222 stat = GdipSetPageUnit(graphics, UnitDisplay);
1223 expect(Ok, stat);
1225 stat = GdipGetPageUnit(graphics, &unit);
1226 expect(Ok, stat);
1227 expect(UnitDisplay, unit);
1229 stat = GdipCreateSolidFill((ARGB)0xffff00ff, (GpSolidFill**)&brush);
1230 expect(Ok, stat);
1232 stat = GdipFillRectangle(graphics, brush, 3, 3, 2, 2);
1233 expect(Ok, stat);
1235 stat = GdipDeleteBrush(brush);
1236 expect(Ok, stat);
1238 stat = GdipDeleteGraphics(graphics);
1239 expect(Ok, stat);
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);
1246 expect(Ok, stat);
1248 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
1249 expect(Ok, stat);
1251 play_metafile(metafile, graphics, pagetransform_records, "pagetransform playback", dst_points, &frame, UnitPixel);
1253 stat = GdipBitmapGetPixel(bitmap, 50, 50, &color);
1254 expect(Ok, stat);
1255 expect(0, color);
1257 stat = GdipBitmapGetPixel(bitmap, 30, 50, &color);
1258 expect(Ok, stat);
1259 expect(0xff0000ff, color);
1261 stat = GdipBitmapGetPixel(bitmap, 10, 30, &color);
1262 expect(Ok, stat);
1263 expect(0xff00ff00, color);
1265 stat = GdipBitmapGetPixel(bitmap, 20, 80, &color);
1266 expect(Ok, stat);
1267 expect(0xff00ffff, color);
1269 stat = GdipBitmapGetPixel(bitmap, 80, 20, &color);
1270 expect(Ok, stat);
1271 expect(0xffff0000, color);
1273 stat = GdipBitmapGetPixel(bitmap, 80, 80, &color);
1274 expect(Ok, stat);
1275 expect(0xffff00ff, color);
1277 stat = GdipDeleteGraphics(graphics);
1278 expect(Ok, stat);
1280 stat = GdipDisposeImage((GpImage*)bitmap);
1281 expect(Ok, stat);
1283 stat = GdipDisposeImage((GpImage*)metafile);
1284 expect(Ok, stat);
1287 static const emfplus_record worldtransform_records[] = {
1288 {0, EMR_HEADER},
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},
1300 {0, EMR_EOF},
1304 static void test_worldtransform(void)
1306 GpStatus stat;
1307 GpMetafile *metafile;
1308 GpGraphics *graphics;
1309 HDC hdc;
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};
1313 GpBitmap *bitmap;
1314 ARGB color;
1315 GpBrush *brush;
1316 GpMatrix *transform;
1317 BOOL identity;
1318 REAL elements[6];
1320 hdc = CreateCompatibleDC(0);
1322 stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, &frame, MetafileFrameUnitPixel, description, &metafile);
1323 expect(Ok, stat);
1325 DeleteDC(hdc);
1327 if (stat != Ok)
1328 return;
1330 stat = GdipCreateMatrix(&transform);
1331 expect(Ok, stat);
1333 stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics);
1334 expect(Ok, stat);
1336 /* initial transform */
1337 stat = GdipGetWorldTransform(graphics, transform);
1338 expect(Ok, stat);
1340 stat = GdipIsMatrixIdentity(transform, &identity);
1341 expect(Ok, stat);
1342 expect(TRUE, identity);
1344 stat = GdipCreateSolidFill((ARGB)0xff0000ff, (GpSolidFill**)&brush);
1345 expect(Ok, stat);
1347 stat = GdipFillRectangleI(graphics, brush, 0, 0, 1, 1);
1348 expect(Ok, stat);
1350 stat = GdipDeleteBrush(brush);
1351 expect(Ok, stat);
1353 /* scale transform */
1354 stat = GdipScaleWorldTransform(graphics, 2.0, 4.0, MatrixOrderPrepend);
1355 expect(Ok, stat);
1357 stat = GdipGetWorldTransform(graphics, transform);
1358 expect(Ok, stat);
1360 stat = GdipGetMatrixElements(transform, elements);
1361 expect(Ok, stat);
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);
1370 expect(Ok, stat);
1372 stat = GdipFillRectangle(graphics, brush, 0.5, 0.5, 0.5, 0.25);
1373 expect(Ok, stat);
1375 stat = GdipDeleteBrush(brush);
1376 expect(Ok, stat);
1378 /* reset transform */
1379 stat = GdipResetWorldTransform(graphics);
1380 expect(Ok, stat);
1382 stat = GdipGetWorldTransform(graphics, transform);
1383 expect(Ok, stat);
1385 stat = GdipIsMatrixIdentity(transform, &identity);
1386 expect(Ok, stat);
1387 expect(TRUE, identity);
1389 stat = GdipCreateSolidFill((ARGB)0xff00ffff, (GpSolidFill**)&brush);
1390 expect(Ok, stat);
1392 stat = GdipFillRectangle(graphics, brush, 1.0, 0.0, 1.0, 1.0);
1393 expect(Ok, stat);
1395 stat = GdipDeleteBrush(brush);
1396 expect(Ok, stat);
1398 /* multiply transform */
1399 stat = GdipSetMatrixElements(transform, 2.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1400 expect(Ok, stat);
1402 stat = GdipMultiplyWorldTransform(graphics, transform, MatrixOrderPrepend);
1403 expect(Ok, stat);
1405 stat = GdipGetWorldTransform(graphics, transform);
1406 expect(Ok, stat);
1408 stat = GdipGetMatrixElements(transform, elements);
1409 expect(Ok, stat);
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);
1418 expect(Ok, stat);
1420 stat = GdipFillRectangle(graphics, brush, 1.0, 1.0, 0.5, 1.0);
1421 expect(Ok, stat);
1423 stat = GdipDeleteBrush(brush);
1424 expect(Ok, stat);
1426 /* rotate transform */
1427 stat = GdipRotateWorldTransform(graphics, 90.0, MatrixOrderAppend);
1428 expect(Ok, stat);
1430 stat = GdipGetWorldTransform(graphics, transform);
1431 expect(Ok, stat);
1433 stat = GdipGetMatrixElements(transform, elements);
1434 expect(Ok, stat);
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);
1443 expect(Ok, stat);
1445 stat = GdipFillRectangle(graphics, brush, 1.0, -1.0, 0.5, 1.0);
1446 expect(Ok, stat);
1448 stat = GdipDeleteBrush(brush);
1449 expect(Ok, stat);
1451 stat = GdipDeleteMatrix(transform);
1452 expect(Ok, stat);
1454 stat = GdipDeleteGraphics(graphics);
1455 expect(Ok, stat);
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);
1462 expect(Ok, stat);
1464 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
1465 expect(Ok, stat);
1467 play_metafile(metafile, graphics, worldtransform_records, "worldtransform playback", dst_points, &frame, UnitPixel);
1469 stat = GdipBitmapGetPixel(bitmap, 80, 80, &color);
1470 expect(Ok, stat);
1471 expect(0, color);
1473 stat = GdipBitmapGetPixel(bitmap, 10, 10, &color);
1474 expect(Ok, stat);
1475 expect(0xff0000ff, color);
1477 stat = GdipBitmapGetPixel(bitmap, 30, 50, &color);
1478 expect(Ok, stat);
1479 expect(0xff00ff00, color);
1481 stat = GdipBitmapGetPixel(bitmap, 30, 10, &color);
1482 expect(Ok, stat);
1483 expect(0xff00ffff, color);
1485 stat = GdipBitmapGetPixel(bitmap, 50, 30, &color);
1486 expect(Ok, stat);
1487 expect(0xffff0000, color);
1489 stat = GdipBitmapGetPixel(bitmap, 10, 50, &color);
1490 expect(Ok, stat);
1491 expect(0xffff00ff, color);
1493 stat = GdipDeleteGraphics(graphics);
1494 expect(Ok, stat);
1496 stat = GdipDisposeImage((GpImage*)bitmap);
1497 expect(Ok, stat);
1499 stat = GdipDisposeImage((GpImage*)metafile);
1500 expect(Ok, stat);
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};
1509 GpStatus stat;
1510 GpMetafile *metafile, *metafile2 = NULL, *emhmeta;
1511 GpGraphics *graphics;
1512 HDC hdc;
1513 BOOL succ;
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");
1521 return;
1524 hdc = CreateCompatibleDC(0);
1526 stat = GdipRecordMetafile(hdc, MetafileTypeEmf, &frame, MetafileFrameUnitPixel, description, &metafile);
1527 expect(Ok, stat);
1529 stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, &frame, MetafileFrameUnitPixel, description, &emhmeta);
1530 expect(Ok, stat);
1532 DeleteDC(hdc);
1534 if (stat != Ok)
1535 return;
1537 stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics);
1538 expect(Ok, stat);
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);
1562 if(metafile2)
1563 GdipDisposeImage((GpImage*)metafile2);
1565 succ = FALSE;
1566 stat = pGdipConvertToEmfPlus(graphics, metafile, &succ, EmfTypeEmfPlusOnly, NULL, &metafile2);
1567 todo_wine expect(Ok, stat);
1568 if(metafile2)
1569 GdipDisposeImage((GpImage*)metafile2);
1571 stat = GdipDeleteGraphics(graphics);
1572 expect(Ok, stat);
1574 stat = GdipDisposeImage((GpImage*)metafile);
1575 expect(Ok, stat);
1577 stat = GdipDisposeImage((GpImage*)emhmeta);
1578 expect(Ok, stat);
1581 static void test_frameunit(void)
1583 GpStatus stat;
1584 GpMetafile *metafile;
1585 GpGraphics *graphics;
1586 HDC hdc;
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};
1589 GpUnit unit;
1590 REAL dpix, dpiy;
1591 GpRectF bounds;
1593 hdc = CreateCompatibleDC(0);
1595 stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, &frame, MetafileFrameUnitInch, description, &metafile);
1596 expect(Ok, stat);
1598 DeleteDC(hdc);
1600 if (stat != Ok)
1601 return;
1603 stat = GdipGetImageBounds((GpImage*)metafile, &bounds, &unit);
1604 expect(Ok, stat);
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);
1614 expect(Ok, stat);
1616 stat = GdipGetImageBounds((GpImage*)metafile, &bounds, &unit);
1617 expect(Ok, stat);
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);
1627 expect(Ok, stat);
1629 stat = GdipGetImageHorizontalResolution((GpImage*)metafile, &dpix);
1630 expect(Ok, stat);
1632 stat = GdipGetImageVerticalResolution((GpImage*)metafile, &dpiy);
1633 expect(Ok, stat);
1635 stat = GdipGetImageBounds((GpImage*)metafile, &bounds, &unit);
1636 expect(Ok, stat);
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);
1644 expect(Ok, stat);
1647 START_TEST(metafile)
1649 struct GdiplusStartupInput gdiplusStartupInput;
1650 ULONG_PTR gdiplusToken;
1651 int myARGC;
1652 char **myARGV;
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 );
1663 if (myARGC >= 3)
1665 if (!strcmp(myARGV[2], "save"))
1666 save_metafiles = TRUE;
1667 else if (!strcmp(myARGV[2], "load"))
1668 load_metafiles = TRUE;
1671 test_empty();
1672 test_getdc();
1673 test_emfonly();
1674 test_fillrect();
1675 test_clear();
1676 test_nullframerect();
1677 test_pagetransform();
1678 test_worldtransform();
1679 test_converttoemfplus();
1680 test_frameunit();
1682 GdiplusShutdown(gdiplusToken);