2 * Copyright (C) 2011 Vincent Povirk for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/unicode.h"
37 #include "gdiplus_private.h"
38 #include "wine/debug.h"
39 #include "wine/list.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
43 typedef struct EmfPlusRecordHeader
49 } EmfPlusRecordHeader
;
51 typedef struct EmfPlusHeader
53 EmfPlusRecordHeader Header
;
60 typedef struct EmfPlusFillRects
62 EmfPlusRecordHeader Header
;
67 typedef struct EmfPlusSetPageTransform
69 EmfPlusRecordHeader Header
;
71 } EmfPlusSetPageTransform
;
73 typedef struct EmfPlusRect
81 static GpStatus
METAFILE_AllocateRecord(GpMetafile
*metafile
, DWORD size
, void **result
)
84 EmfPlusRecordHeader
*record
;
86 if (!metafile
->comment_data_size
)
88 DWORD data_size
= max(256, size
* 2 + 4);
89 metafile
->comment_data
= GdipAlloc(data_size
);
91 if (!metafile
->comment_data
)
94 memcpy(metafile
->comment_data
, "EMF+", 4);
96 metafile
->comment_data_size
= data_size
;
97 metafile
->comment_data_length
= 4;
100 size_needed
= size
+ metafile
->comment_data_length
;
102 if (size_needed
> metafile
->comment_data_size
)
104 DWORD data_size
= size_needed
* 2;
105 BYTE
*new_data
= GdipAlloc(data_size
);
110 memcpy(new_data
, metafile
->comment_data
, metafile
->comment_data_length
);
112 metafile
->comment_data_size
= data_size
;
113 GdipFree(metafile
->comment_data
);
114 metafile
->comment_data
= new_data
;
117 *result
= metafile
->comment_data
+ metafile
->comment_data_length
;
118 metafile
->comment_data_length
+= size
;
120 record
= (EmfPlusRecordHeader
*)*result
;
122 record
->DataSize
= size
- sizeof(EmfPlusRecordHeader
);
127 static void METAFILE_WriteRecords(GpMetafile
*metafile
)
129 if (metafile
->comment_data_length
> 4)
131 GdiComment(metafile
->record_dc
, metafile
->comment_data_length
, metafile
->comment_data
);
132 metafile
->comment_data_length
= 4;
136 static GpStatus
METAFILE_WriteHeader(GpMetafile
*metafile
, HDC hdc
)
140 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
142 EmfPlusHeader
*header
;
144 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusHeader
), (void**)&header
);
148 header
->Header
.Type
= EmfPlusRecordTypeHeader
;
150 if (metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
151 header
->Header
.Flags
= 1;
153 header
->Header
.Flags
= 0;
155 header
->Version
= 0xDBC01002;
157 if (GetDeviceCaps(hdc
, TECHNOLOGY
) == DT_RASDISPLAY
)
158 header
->EmfPlusFlags
= 1;
160 header
->EmfPlusFlags
= 0;
162 header
->LogicalDpiX
= GetDeviceCaps(hdc
, LOGPIXELSX
);
163 header
->LogicalDpiY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
165 METAFILE_WriteRecords(metafile
);
171 static GpStatus
METAFILE_WriteEndOfFile(GpMetafile
*metafile
)
175 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
177 EmfPlusRecordHeader
*record
;
179 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusRecordHeader
), (void**)&record
);
183 record
->Type
= EmfPlusRecordTypeEndOfFile
;
186 METAFILE_WriteRecords(metafile
);
192 GpStatus WINGDIPAPI
GdipRecordMetafile(HDC hdc
, EmfType type
, GDIPCONST GpRectF
*frameRect
,
193 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
196 REAL framerect_factor_x
, framerect_factor_y
;
200 TRACE("(%p %d %p %d %p %p)\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
202 if (!hdc
|| type
< EmfTypeEmfOnly
|| type
> EmfTypeEmfPlusDual
|| !metafile
)
203 return InvalidParameter
;
207 FIXME("not implemented for NULL rect\n");
208 return NotImplemented
;
213 case MetafileFrameUnitPixel
:
214 framerect_factor_x
= 2540.0 / GetDeviceCaps(hdc
, LOGPIXELSX
);
215 framerect_factor_y
= 2540.0 / GetDeviceCaps(hdc
, LOGPIXELSY
);
217 case MetafileFrameUnitPoint
:
218 framerect_factor_x
= framerect_factor_y
= 2540.0 / 72.0;
220 case MetafileFrameUnitInch
:
221 framerect_factor_x
= framerect_factor_y
= 2540.0;
223 case MetafileFrameUnitDocument
:
224 framerect_factor_x
= framerect_factor_y
= 2540.0 / 300.0;
226 case MetafileFrameUnitMillimeter
:
227 framerect_factor_x
= framerect_factor_y
= 100.0;
229 case MetafileFrameUnitGdi
:
230 framerect_factor_x
= framerect_factor_y
= 1.0;
233 return InvalidParameter
;
236 rc
.left
= framerect_factor_x
* frameRect
->X
;
237 rc
.top
= framerect_factor_y
* frameRect
->Y
;
238 rc
.right
= rc
.left
+ framerect_factor_x
* frameRect
->Width
;
239 rc
.bottom
= rc
.top
+ framerect_factor_y
* frameRect
->Height
;
241 record_dc
= CreateEnhMetaFileW(hdc
, NULL
, &rc
, desc
);
246 *metafile
= GdipAlloc(sizeof(GpMetafile
));
249 DeleteEnhMetaFile(CloseEnhMetaFile(record_dc
));
253 (*metafile
)->image
.type
= ImageTypeMetafile
;
254 (*metafile
)->image
.picture
= NULL
;
255 (*metafile
)->image
.flags
= ImageFlagsNone
;
256 (*metafile
)->image
.palette
= NULL
;
257 (*metafile
)->image
.xres
= 72.0;
258 (*metafile
)->image
.yres
= 72.0;
259 (*metafile
)->bounds
= *frameRect
;
260 (*metafile
)->unit
= frameUnit
;
261 (*metafile
)->metafile_type
= type
;
262 (*metafile
)->record_dc
= record_dc
;
263 (*metafile
)->comment_data
= NULL
;
264 (*metafile
)->comment_data_size
= 0;
265 (*metafile
)->comment_data_length
= 0;
266 (*metafile
)->hemf
= NULL
;
268 stat
= METAFILE_WriteHeader(*metafile
, hdc
);
272 DeleteEnhMetaFile(CloseEnhMetaFile(record_dc
));
281 /*****************************************************************************
282 * GdipRecordMetafileI [GDIPLUS.@]
284 GpStatus WINGDIPAPI
GdipRecordMetafileI(HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
285 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
287 GpRectF frameRectF
, *pFrameRectF
;
289 TRACE("(%p %d %p %d %p %p)\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
293 frameRectF
.X
= frameRect
->X
;
294 frameRectF
.Y
= frameRect
->Y
;
295 frameRectF
.Width
= frameRect
->Width
;
296 frameRectF
.Height
= frameRect
->Height
;
297 pFrameRectF
= &frameRectF
;
302 return GdipRecordMetafile(hdc
, type
, pFrameRectF
, frameUnit
, desc
, metafile
);
305 GpStatus
METAFILE_GetGraphicsContext(GpMetafile
* metafile
, GpGraphics
**result
)
309 if (!metafile
->record_dc
|| metafile
->record_graphics
)
310 return InvalidParameter
;
312 stat
= graphics_from_image((GpImage
*)metafile
, &metafile
->record_graphics
);
316 *result
= metafile
->record_graphics
;
317 metafile
->record_graphics
->xres
= 96.0;
318 metafile
->record_graphics
->yres
= 96.0;
324 GpStatus
METAFILE_GetDC(GpMetafile
* metafile
, HDC
*hdc
)
326 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
328 EmfPlusRecordHeader
*record
;
331 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusRecordHeader
), (void**)&record
);
335 record
->Type
= EmfPlusRecordTypeGetDC
;
338 METAFILE_WriteRecords(metafile
);
341 *hdc
= metafile
->record_dc
;
346 static BOOL
is_integer_rect(const GpRectF
*rect
)
348 SHORT x
, y
, width
, height
;
352 height
= rect
->Height
;
353 if (rect
->X
!= (REAL
)x
|| rect
->Y
!= (REAL
)y
||
354 rect
->Width
!= (REAL
)width
|| rect
->Height
!= (REAL
)height
)
359 GpStatus
METAFILE_FillRectangles(GpMetafile
* metafile
, GpBrush
* brush
,
360 GDIPCONST GpRectF
* rects
, INT count
)
362 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
364 EmfPlusFillRects
*record
;
366 BOOL integer_rects
=1;
371 if (brush
->bt
== BrushTypeSolidColor
)
374 brushid
= ((GpSolidFill
*)brush
)->color
;
378 FIXME("brush serialization not implemented\n");
379 return NotImplemented
;
382 for (i
=0; i
<count
; i
++)
384 if (!is_integer_rect(&rects
[i
]))
394 stat
= METAFILE_AllocateRecord(metafile
,
395 sizeof(EmfPlusFillRects
) + count
* (integer_rects
? sizeof(EmfPlusRect
) : sizeof(GpRectF
)),
400 record
->Header
.Type
= EmfPlusRecordTypeFillRects
;
401 record
->Header
.Flags
= flags
;
402 record
->BrushID
= brushid
;
403 record
->Count
= count
;
407 EmfPlusRect
*record_rects
= (EmfPlusRect
*)(record
+1);
408 for (i
=0; i
<count
; i
++)
410 record_rects
[i
].X
= (SHORT
)rects
[i
].X
;
411 record_rects
[i
].Y
= (SHORT
)rects
[i
].Y
;
412 record_rects
[i
].Width
= (SHORT
)rects
[i
].Width
;
413 record_rects
[i
].Height
= (SHORT
)rects
[i
].Height
;
417 memcpy(record
+1, rects
, sizeof(GpRectF
) * count
);
419 METAFILE_WriteRecords(metafile
);
425 GpStatus
METAFILE_SetPageTransform(GpMetafile
* metafile
, GpUnit unit
, REAL scale
)
427 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
429 EmfPlusSetPageTransform
*record
;
432 stat
= METAFILE_AllocateRecord(metafile
,
433 sizeof(EmfPlusSetPageTransform
),
438 record
->Header
.Type
= EmfPlusRecordTypeSetPageTransform
;
439 record
->Header
.Flags
= unit
;
440 record
->PageScale
= scale
;
442 METAFILE_WriteRecords(metafile
);
448 GpStatus
METAFILE_ReleaseDC(GpMetafile
* metafile
, HDC hdc
)
450 if (hdc
!= metafile
->record_dc
)
451 return InvalidParameter
;
456 GpStatus
METAFILE_GraphicsDeleted(GpMetafile
* metafile
)
460 stat
= METAFILE_WriteEndOfFile(metafile
);
461 metafile
->record_graphics
= NULL
;
463 metafile
->hemf
= CloseEnhMetaFile(metafile
->record_dc
);
464 metafile
->record_dc
= NULL
;
466 GdipFree(metafile
->comment_data
);
467 metafile
->comment_data
= NULL
;
468 metafile
->comment_data_size
= 0;
473 GpStatus WINGDIPAPI
GdipGetHemfFromMetafile(GpMetafile
*metafile
, HENHMETAFILE
*hEmf
)
475 TRACE("(%p,%p)\n", metafile
, hEmf
);
477 if (!metafile
|| !hEmf
|| !metafile
->hemf
)
478 return InvalidParameter
;
480 *hEmf
= metafile
->hemf
;
481 metafile
->hemf
= NULL
;
486 static GpStatus
METAFILE_PlaybackGetDC(GpMetafile
*metafile
)
490 stat
= GdipGetDC(metafile
->playback_graphics
, &metafile
->playback_dc
);
494 /* The result of GdipGetDC always expects device co-ordinates, but the
495 * device co-ordinates of the source metafile do not correspond to
496 * device co-ordinates of the destination. Therefore, we set up the DC
497 * so that the metafile's bounds map to the destination points where we
498 * are drawing this metafile. */
499 SetMapMode(metafile
->playback_dc
, MM_ANISOTROPIC
);
501 SetWindowOrgEx(metafile
->playback_dc
, metafile
->bounds
.X
, metafile
->bounds
.Y
, NULL
);
502 SetWindowExtEx(metafile
->playback_dc
, metafile
->bounds
.Width
, metafile
->bounds
.Height
, NULL
);
504 SetViewportOrgEx(metafile
->playback_dc
, metafile
->playback_points
[0].X
, metafile
->playback_points
[0].Y
, NULL
);
505 SetViewportExtEx(metafile
->playback_dc
,
506 metafile
->playback_points
[1].X
- metafile
->playback_points
[0].X
,
507 metafile
->playback_points
[2].Y
- metafile
->playback_points
[0].Y
, NULL
);
513 static void METAFILE_PlaybackReleaseDC(GpMetafile
*metafile
)
515 if (metafile
->playback_dc
)
517 GdipReleaseDC(metafile
->playback_graphics
, metafile
->playback_dc
);
518 metafile
->playback_dc
= NULL
;
522 static GpStatus
METAFILE_PlaybackUpdateWorldTransform(GpMetafile
*metafile
)
524 GpMatrix
*real_transform
;
527 stat
= GdipCreateMatrix3(&metafile
->src_rect
, metafile
->playback_points
, &real_transform
);
531 /* FIXME: Prepend page transform. */
533 stat
= GdipMultiplyMatrix(real_transform
, metafile
->world_transform
, MatrixOrderPrepend
);
536 stat
= GdipSetWorldTransform(metafile
->playback_graphics
, real_transform
);
538 GdipDeleteMatrix(real_transform
);
544 GpStatus WINGDIPAPI
GdipPlayMetafileRecord(GDIPCONST GpMetafile
*metafile
,
545 EmfPlusRecordType recordType
, UINT flags
, UINT dataSize
, GDIPCONST BYTE
*data
)
549 TRACE("(%p,%x,%x,%d,%p)\n", metafile
, recordType
, flags
, dataSize
, data
);
551 if (!metafile
|| (dataSize
&& !data
) || !metafile
->playback_graphics
)
552 return InvalidParameter
;
554 if (recordType
>= 1 && recordType
<= 0x7a)
556 /* regular EMF record */
557 if (metafile
->playback_dc
)
559 ENHMETARECORD
*record
;
561 record
= GdipAlloc(dataSize
+ 8);
565 record
->iType
= recordType
;
566 record
->nSize
= dataSize
+ 8;
567 memcpy(record
->dParm
, data
, dataSize
);
569 PlayEnhMetaFileRecord(metafile
->playback_dc
, metafile
->handle_table
,
570 record
, metafile
->handle_count
);
580 EmfPlusRecordHeader
*header
= (EmfPlusRecordHeader
*)(data
)-1;
582 METAFILE_PlaybackReleaseDC((GpMetafile
*)metafile
);
586 case EmfPlusRecordTypeHeader
:
587 case EmfPlusRecordTypeEndOfFile
:
589 case EmfPlusRecordTypeGetDC
:
590 METAFILE_PlaybackGetDC((GpMetafile
*)metafile
);
592 case EmfPlusRecordTypeFillRects
:
594 EmfPlusFillRects
*record
= (EmfPlusFillRects
*)header
;
595 GpBrush
*brush
, *temp_brush
=NULL
;
596 GpRectF
*rects
, *temp_rects
=NULL
;
598 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusFillRects
))
599 return InvalidParameter
;
603 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusFillRects
) + sizeof(EmfPlusRect
) * record
->Count
)
604 return InvalidParameter
;
608 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusFillRects
) + sizeof(GpRectF
) * record
->Count
)
609 return InvalidParameter
;
614 stat
= GdipCreateSolidFill((ARGB
)record
->BrushID
, (GpSolidFill
**)&temp_brush
);
619 FIXME("brush deserialization not implemented\n");
620 return NotImplemented
;
627 EmfPlusRect
*int_rects
= (EmfPlusRect
*)(record
+1);
630 rects
= temp_rects
= GdipAlloc(sizeof(GpRectF
) * record
->Count
);
633 for (i
=0; i
<record
->Count
; i
++)
635 rects
[i
].X
= int_rects
[i
].X
;
636 rects
[i
].Y
= int_rects
[i
].Y
;
637 rects
[i
].Width
= int_rects
[i
].Width
;
638 rects
[i
].Height
= int_rects
[i
].Height
;
645 rects
= (GpRectF
*)(record
+1);
650 stat
= GdipFillRectangles(metafile
->playback_graphics
, brush
, rects
, record
->Count
);
653 GdipDeleteBrush(temp_brush
);
654 GdipFree(temp_rects
);
659 FIXME("Not implemented for record type %x\n", recordType
);
660 return NotImplemented
;
667 struct enum_metafile_data
669 EnumerateMetafileProc callback
;
671 GpMetafile
*metafile
;
674 static int CALLBACK
enum_metafile_proc(HDC hDC
, HANDLETABLE
*lpHTable
, const ENHMETARECORD
*lpEMFR
,
675 int nObj
, LPARAM lpData
)
678 struct enum_metafile_data
*data
= (struct enum_metafile_data
*)lpData
;
681 data
->metafile
->handle_table
= lpHTable
;
682 data
->metafile
->handle_count
= nObj
;
684 /* First check for an EMF+ record. */
685 if (lpEMFR
->iType
== EMR_GDICOMMENT
)
687 const EMRGDICOMMENT
*comment
= (const EMRGDICOMMENT
*)lpEMFR
;
689 if (comment
->cbData
>= 4 && memcmp(comment
->Data
, "EMF+", 4) == 0)
693 while (offset
+ sizeof(EmfPlusRecordHeader
) <= comment
->cbData
)
695 const EmfPlusRecordHeader
*record
= (const EmfPlusRecordHeader
*)&comment
->Data
[offset
];
697 if (record
->DataSize
)
698 pStr
= (const BYTE
*)(record
+1);
702 ret
= data
->callback(record
->Type
, record
->Flags
, record
->DataSize
,
703 pStr
, data
->callback_data
);
708 offset
+= record
->Size
;
715 if (lpEMFR
->nSize
!= 8)
716 pStr
= (const BYTE
*)lpEMFR
->dParm
;
720 return data
->callback(lpEMFR
->iType
, 0, lpEMFR
->nSize
-8,
721 pStr
, data
->callback_data
);
724 GpStatus WINGDIPAPI
GdipEnumerateMetafileSrcRectDestPoints(GpGraphics
*graphics
,
725 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpPointF
*destPoints
, INT count
,
726 GDIPCONST GpRectF
*srcRect
, Unit srcUnit
, EnumerateMetafileProc callback
,
727 VOID
*callbackData
, GDIPCONST GpImageAttributes
*imageAttributes
)
729 struct enum_metafile_data data
;
731 GpMetafile
*real_metafile
= (GpMetafile
*)metafile
; /* whoever made this const was joking */
732 GraphicsContainer state
;
734 TRACE("(%p,%p,%p,%i,%p,%i,%p,%p,%p)\n", graphics
, metafile
,
735 destPoints
, count
, srcRect
, srcUnit
, callback
, callbackData
,
738 if (!graphics
|| !metafile
|| !destPoints
|| count
!= 3 || !srcRect
)
739 return InvalidParameter
;
742 return InvalidParameter
;
744 if (metafile
->playback_graphics
)
747 TRACE("%s %i -> %s %s %s\n", debugstr_rectf(srcRect
), srcUnit
,
748 debugstr_pointf(&destPoints
[0]), debugstr_pointf(&destPoints
[1]),
749 debugstr_pointf(&destPoints
[2]));
751 data
.callback
= callback
;
752 data
.callback_data
= callbackData
;
753 data
.metafile
= real_metafile
;
755 real_metafile
->playback_graphics
= graphics
;
756 real_metafile
->playback_dc
= NULL
;
757 real_metafile
->src_rect
= *srcRect
;
759 memcpy(real_metafile
->playback_points
, destPoints
, sizeof(PointF
) * 3);
760 stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, real_metafile
->playback_points
, 3);
763 stat
= GdipBeginContainer2(graphics
, &state
);
767 stat
= GdipSetPageScale(graphics
, 1.0);
770 stat
= GdipSetPageUnit(graphics
, UnitPixel
);
773 stat
= GdipCreateMatrix(&real_metafile
->world_transform
);
777 real_metafile
->page_unit
= UnitPixel
; /* FIXME: Use frame unit here? */
778 real_metafile
->page_scale
= 1.0;
779 stat
= METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
782 if (stat
== Ok
&& (metafile
->metafile_type
== MetafileTypeEmf
||
783 metafile
->metafile_type
== MetafileTypeWmfPlaceable
||
784 metafile
->metafile_type
== MetafileTypeWmf
))
785 stat
= METAFILE_PlaybackGetDC(real_metafile
);
788 EnumEnhMetaFile(0, metafile
->hemf
, enum_metafile_proc
, &data
, NULL
);
790 METAFILE_PlaybackReleaseDC(real_metafile
);
792 GdipDeleteMatrix(real_metafile
->world_transform
);
793 real_metafile
->world_transform
= NULL
;
795 GdipEndContainer(graphics
, state
);
798 real_metafile
->playback_graphics
= NULL
;
803 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestRect(GpGraphics
*graphics
,
804 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpRectF
*dest
,
805 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
809 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
811 points
[0].X
= points
[2].X
= dest
->X
;
812 points
[0].Y
= points
[1].Y
= dest
->Y
;
813 points
[1].X
= dest
->X
+ dest
->Width
;
814 points
[2].Y
= dest
->Y
+ dest
->Height
;
816 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, metafile
, points
, 3,
817 &metafile
->bounds
, metafile
->unit
, callback
, cb_data
, attrs
);
820 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestRectI(GpGraphics
*graphics
,
821 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpRect
*dest
,
822 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
826 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
830 destf
.Width
= dest
->Width
;
831 destf
.Height
= dest
->Height
;
833 return GdipEnumerateMetafileDestRect(graphics
, metafile
, &destf
, callback
, cb_data
, attrs
);
836 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestPoint(GpGraphics
*graphics
,
837 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpPointF
*dest
,
838 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
842 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
846 destf
.Width
= units_to_pixels(metafile
->bounds
.Width
, metafile
->unit
, metafile
->image
.xres
);
847 destf
.Height
= units_to_pixels(metafile
->bounds
.Height
, metafile
->unit
, metafile
->image
.yres
);
849 return GdipEnumerateMetafileDestRect(graphics
, metafile
, &destf
, callback
, cb_data
, attrs
);
852 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestPointI(GpGraphics
*graphics
,
853 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpPoint
*dest
,
854 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
858 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
863 return GdipEnumerateMetafileDestPoint(graphics
, metafile
, &ptf
, callback
, cb_data
, attrs
);
866 static int CALLBACK
get_metafile_type_proc(HDC hDC
, HANDLETABLE
*lpHTable
, const ENHMETARECORD
*lpEMFR
,
867 int nObj
, LPARAM lpData
)
869 MetafileType
*result
= (MetafileType
*)lpData
;
871 if (lpEMFR
->iType
== EMR_GDICOMMENT
)
873 const EMRGDICOMMENT
*comment
= (const EMRGDICOMMENT
*)lpEMFR
;
875 if (comment
->cbData
>= 4 && memcmp(comment
->Data
, "EMF+", 4) == 0)
877 const EmfPlusRecordHeader
*header
= (const EmfPlusRecordHeader
*)&comment
->Data
[4];
879 if (4 + sizeof(EmfPlusRecordHeader
) <= comment
->cbData
&&
880 header
->Type
== EmfPlusRecordTypeHeader
)
882 if ((header
->Flags
& 1) == 1)
883 *result
= MetafileTypeEmfPlusDual
;
885 *result
= MetafileTypeEmfPlusOnly
;
889 *result
= MetafileTypeEmf
;
892 *result
= MetafileTypeEmf
;
897 MetafileType
METAFILE_GetEmfType(HENHMETAFILE hemf
)
899 MetafileType result
= MetafileTypeInvalid
;
900 EnumEnhMetaFile(NULL
, hemf
, get_metafile_type_proc
, &result
, NULL
);