static GpStatus METAFILE_PlaybackGetDC(GpMetafile *metafile) { GpStatus stat = Ok; stat = GdipGetDC(metafile->playback_graphics, &metafile->playback_dc); if (stat == Ok) { /* The result of GdipGetDC always expects device co-ordinates, but the * device co-ordinates of the source metafile do not correspond to * device co-ordinates of the destination. Therefore, we set up the DC * so that the metafile's bounds map to the destination points where we * are drawing this metafile. */ SetMapMode(metafile->playback_dc, MM_ANISOTROPIC); SetWindowOrgEx(metafile->playback_dc, metafile->bounds.X, metafile->bounds.Y, NULL); SetWindowExtEx(metafile->playback_dc, metafile->bounds.Width, metafile->bounds.Height, NULL); SetViewportOrgEx(metafile->playback_dc, metafile->playback_points[0].X, metafile->playback_points[0].Y, NULL); SetViewportExtEx(metafile->playback_dc, metafile->playback_points[1].X - metafile->playback_points[0].X, metafile->playback_points[2].Y - metafile->playback_points[0].Y, NULL); } return stat; }
static void test_emfonly(void) { GpStatus stat; GpMetafile *metafile; GpGraphics *graphics; HDC hdc, metafile_dc; HENHMETAFILE hemf; BOOL ret; static const GpRectF frame = {0.0, 0.0, 100.0, 100.0}; static const GpPointF dst_points[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}}; static const WCHAR description[] = {'w','i','n','e','t','e','s','t',0}; HBRUSH hbrush, holdbrush; GpBitmap *bitmap; ARGB color; hdc = CreateCompatibleDC(0); stat = GdipRecordMetafile(hdc, EmfTypeEmfOnly, &frame, MetafileFrameUnitPixel, description, &metafile); expect(Ok, stat); DeleteDC(hdc); if (stat != Ok) return; stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(InvalidParameter, stat); stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics); expect(Ok, stat); stat = GdipGetDC(graphics, &metafile_dc); expect(Ok, stat); if (stat != Ok) { GdipDeleteGraphics(graphics); GdipDisposeImage((GpImage*)metafile); return; } hbrush = CreateSolidBrush(0xff0000); holdbrush = SelectObject(metafile_dc, hbrush); Rectangle(metafile_dc, 25, 25, 75, 75); SelectObject(metafile_dc, holdbrush); DeleteObject(hbrush); stat = GdipReleaseDC(graphics, metafile_dc); expect(Ok, stat); stat = GdipDeleteGraphics(graphics); expect(Ok, stat); check_metafile(metafile, emfonly_records, "emfonly metafile", dst_points, &frame, UnitPixel); stat = GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB, NULL, &bitmap); expect(Ok, stat); stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics); expect(Ok, stat); play_metafile(metafile, graphics, emfonly_records, "emfonly playback", dst_points, &frame, UnitPixel); stat = GdipBitmapGetPixel(bitmap, 15, 15, &color); expect(Ok, stat); expect(0, color); stat = GdipBitmapGetPixel(bitmap, 50, 50, &color); expect(Ok, stat); expect(0xff0000ff, color); stat = GdipDeleteGraphics(graphics); expect(Ok, stat); stat = GdipDisposeImage((GpImage*)bitmap); expect(Ok, stat); stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(Ok, stat); stat = GdipDisposeImage((GpImage*)metafile); expect(Ok, stat); check_emfplus(hemf, emfonly_records, "emfonly emf"); ret = DeleteEnhMetaFile(hemf); ok(ret != 0, "Failed to delete enhmetafile %p\n", hemf); }
static void test_getdc(void) { GpStatus stat; GpMetafile *metafile; GpGraphics *graphics; HDC hdc, metafile_dc; HENHMETAFILE hemf; BOOL ret; static const GpRectF frame = {0.0, 0.0, 100.0, 100.0}; static const GpPointF dst_points[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}}; static const WCHAR description[] = {'w','i','n','e','t','e','s','t',0}; HBRUSH hbrush, holdbrush; hdc = CreateCompatibleDC(0); stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, &frame, MetafileFrameUnitPixel, description, &metafile); expect(Ok, stat); DeleteDC(hdc); if (stat != Ok) return; stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(InvalidParameter, stat); stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics); expect(Ok, stat); stat = GdipGetDC(graphics, &metafile_dc); expect(Ok, stat); if (stat != Ok) { GdipDeleteGraphics(graphics); GdipDisposeImage((GpImage*)metafile); return; } hbrush = CreateSolidBrush(0xff0000); holdbrush = SelectObject(metafile_dc, hbrush); Rectangle(metafile_dc, 25, 25, 75, 75); SelectObject(metafile_dc, holdbrush); DeleteObject(hbrush); stat = GdipReleaseDC(graphics, metafile_dc); expect(Ok, stat); stat = GdipDeleteGraphics(graphics); expect(Ok, stat); check_metafile(metafile, getdc_records, "getdc metafile", dst_points, &frame, UnitPixel); stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(Ok, stat); stat = GdipDisposeImage((GpImage*)metafile); expect(Ok, stat); check_emfplus(hemf, getdc_records, "getdc emf"); ret = DeleteEnhMetaFile(hemf); ok(ret != 0, "Failed to delete enhmetafile %p\n", hemf); }