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
= heap_alloc_zero(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
= heap_alloc_zero(data_size
);
110 memcpy(new_data
, metafile
->comment_data
, metafile
->comment_data_length
);
112 metafile
->comment_data_size
= data_size
;
113 heap_free(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
= heap_alloc_zero(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
));
273 heap_free(*metafile
);
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
= TRUE
;
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
]))
386 integer_rects
= FALSE
;
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 heap_free(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 REAL scale
= units_to_pixels(1.0, metafile
->page_unit
, 96.0);
533 if (metafile
->page_unit
!= UnitDisplay
)
534 scale
*= metafile
->page_scale
;
536 stat
= GdipScaleMatrix(real_transform
, scale
, scale
, MatrixOrderPrepend
);
539 stat
= GdipMultiplyMatrix(real_transform
, metafile
->world_transform
, MatrixOrderPrepend
);
542 stat
= GdipSetWorldTransform(metafile
->playback_graphics
, real_transform
);
544 GdipDeleteMatrix(real_transform
);
550 GpStatus WINGDIPAPI
GdipPlayMetafileRecord(GDIPCONST GpMetafile
*metafile
,
551 EmfPlusRecordType recordType
, UINT flags
, UINT dataSize
, GDIPCONST BYTE
*data
)
554 GpMetafile
*real_metafile
= (GpMetafile
*)metafile
;
556 TRACE("(%p,%x,%x,%d,%p)\n", metafile
, recordType
, flags
, dataSize
, data
);
558 if (!metafile
|| (dataSize
&& !data
) || !metafile
->playback_graphics
)
559 return InvalidParameter
;
561 if (recordType
>= 1 && recordType
<= 0x7a)
563 /* regular EMF record */
564 if (metafile
->playback_dc
)
566 ENHMETARECORD
*record
;
568 record
= heap_alloc_zero(dataSize
+ 8);
572 record
->iType
= recordType
;
573 record
->nSize
= dataSize
+ 8;
574 memcpy(record
->dParm
, data
, dataSize
);
576 PlayEnhMetaFileRecord(metafile
->playback_dc
, metafile
->handle_table
,
577 record
, metafile
->handle_count
);
587 EmfPlusRecordHeader
*header
= (EmfPlusRecordHeader
*)(data
)-1;
589 METAFILE_PlaybackReleaseDC((GpMetafile
*)metafile
);
593 case EmfPlusRecordTypeHeader
:
594 case EmfPlusRecordTypeEndOfFile
:
596 case EmfPlusRecordTypeGetDC
:
597 METAFILE_PlaybackGetDC((GpMetafile
*)metafile
);
599 case EmfPlusRecordTypeFillRects
:
601 EmfPlusFillRects
*record
= (EmfPlusFillRects
*)header
;
602 GpBrush
*brush
, *temp_brush
=NULL
;
603 GpRectF
*rects
, *temp_rects
=NULL
;
605 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusFillRects
))
606 return InvalidParameter
;
610 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusFillRects
) + sizeof(EmfPlusRect
) * record
->Count
)
611 return InvalidParameter
;
615 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusFillRects
) + sizeof(GpRectF
) * record
->Count
)
616 return InvalidParameter
;
621 stat
= GdipCreateSolidFill((ARGB
)record
->BrushID
, (GpSolidFill
**)&temp_brush
);
626 FIXME("brush deserialization not implemented\n");
627 return NotImplemented
;
634 EmfPlusRect
*int_rects
= (EmfPlusRect
*)(record
+1);
637 rects
= temp_rects
= heap_alloc_zero(sizeof(GpRectF
) * record
->Count
);
640 for (i
=0; i
<record
->Count
; i
++)
642 rects
[i
].X
= int_rects
[i
].X
;
643 rects
[i
].Y
= int_rects
[i
].Y
;
644 rects
[i
].Width
= int_rects
[i
].Width
;
645 rects
[i
].Height
= int_rects
[i
].Height
;
652 rects
= (GpRectF
*)(record
+1);
657 stat
= GdipFillRectangles(metafile
->playback_graphics
, brush
, rects
, record
->Count
);
660 GdipDeleteBrush(temp_brush
);
661 heap_free(temp_rects
);
665 case EmfPlusRecordTypeSetPageTransform
:
667 EmfPlusSetPageTransform
*record
= (EmfPlusSetPageTransform
*)header
;
668 GpUnit unit
= (GpUnit
)flags
;
670 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusSetPageTransform
))
671 return InvalidParameter
;
673 real_metafile
->page_unit
= unit
;
674 real_metafile
->page_scale
= record
->PageScale
;
676 return METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
679 FIXME("Not implemented for record type %x\n", recordType
);
680 return NotImplemented
;
687 struct enum_metafile_data
689 EnumerateMetafileProc callback
;
691 GpMetafile
*metafile
;
694 static int CALLBACK
enum_metafile_proc(HDC hDC
, HANDLETABLE
*lpHTable
, const ENHMETARECORD
*lpEMFR
,
695 int nObj
, LPARAM lpData
)
698 struct enum_metafile_data
*data
= (struct enum_metafile_data
*)lpData
;
701 data
->metafile
->handle_table
= lpHTable
;
702 data
->metafile
->handle_count
= nObj
;
704 /* First check for an EMF+ record. */
705 if (lpEMFR
->iType
== EMR_GDICOMMENT
)
707 const EMRGDICOMMENT
*comment
= (const EMRGDICOMMENT
*)lpEMFR
;
709 if (comment
->cbData
>= 4 && memcmp(comment
->Data
, "EMF+", 4) == 0)
713 while (offset
+ sizeof(EmfPlusRecordHeader
) <= comment
->cbData
)
715 const EmfPlusRecordHeader
*record
= (const EmfPlusRecordHeader
*)&comment
->Data
[offset
];
717 if (record
->DataSize
)
718 pStr
= (const BYTE
*)(record
+1);
722 ret
= data
->callback(record
->Type
, record
->Flags
, record
->DataSize
,
723 pStr
, data
->callback_data
);
728 offset
+= record
->Size
;
735 if (lpEMFR
->nSize
!= 8)
736 pStr
= (const BYTE
*)lpEMFR
->dParm
;
740 return data
->callback(lpEMFR
->iType
, 0, lpEMFR
->nSize
-8,
741 pStr
, data
->callback_data
);
744 GpStatus WINGDIPAPI
GdipEnumerateMetafileSrcRectDestPoints(GpGraphics
*graphics
,
745 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpPointF
*destPoints
, INT count
,
746 GDIPCONST GpRectF
*srcRect
, Unit srcUnit
, EnumerateMetafileProc callback
,
747 VOID
*callbackData
, GDIPCONST GpImageAttributes
*imageAttributes
)
749 struct enum_metafile_data data
;
751 GpMetafile
*real_metafile
= (GpMetafile
*)metafile
; /* whoever made this const was joking */
752 GraphicsContainer state
;
754 TRACE("(%p,%p,%p,%i,%p,%i,%p,%p,%p)\n", graphics
, metafile
,
755 destPoints
, count
, srcRect
, srcUnit
, callback
, callbackData
,
758 if (!graphics
|| !metafile
|| !destPoints
|| count
!= 3 || !srcRect
)
759 return InvalidParameter
;
762 return InvalidParameter
;
764 if (metafile
->playback_graphics
)
767 TRACE("%s %i -> %s %s %s\n", debugstr_rectf(srcRect
), srcUnit
,
768 debugstr_pointf(&destPoints
[0]), debugstr_pointf(&destPoints
[1]),
769 debugstr_pointf(&destPoints
[2]));
771 data
.callback
= callback
;
772 data
.callback_data
= callbackData
;
773 data
.metafile
= real_metafile
;
775 real_metafile
->playback_graphics
= graphics
;
776 real_metafile
->playback_dc
= NULL
;
777 real_metafile
->src_rect
= *srcRect
;
779 memcpy(real_metafile
->playback_points
, destPoints
, sizeof(PointF
) * 3);
780 stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, real_metafile
->playback_points
, 3);
783 stat
= GdipBeginContainer2(graphics
, &state
);
787 stat
= GdipSetPageScale(graphics
, 1.0);
790 stat
= GdipSetPageUnit(graphics
, UnitPixel
);
793 stat
= GdipCreateMatrix(&real_metafile
->world_transform
);
797 real_metafile
->page_unit
= UnitDisplay
;
798 real_metafile
->page_scale
= 1.0;
799 stat
= METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
802 if (stat
== Ok
&& (metafile
->metafile_type
== MetafileTypeEmf
||
803 metafile
->metafile_type
== MetafileTypeWmfPlaceable
||
804 metafile
->metafile_type
== MetafileTypeWmf
))
805 stat
= METAFILE_PlaybackGetDC(real_metafile
);
808 EnumEnhMetaFile(0, metafile
->hemf
, enum_metafile_proc
, &data
, NULL
);
810 METAFILE_PlaybackReleaseDC(real_metafile
);
812 GdipDeleteMatrix(real_metafile
->world_transform
);
813 real_metafile
->world_transform
= NULL
;
815 GdipEndContainer(graphics
, state
);
818 real_metafile
->playback_graphics
= NULL
;
823 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestRect(GpGraphics
*graphics
,
824 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpRectF
*dest
,
825 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
829 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
831 points
[0].X
= points
[2].X
= dest
->X
;
832 points
[0].Y
= points
[1].Y
= dest
->Y
;
833 points
[1].X
= dest
->X
+ dest
->Width
;
834 points
[2].Y
= dest
->Y
+ dest
->Height
;
836 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, metafile
, points
, 3,
837 &metafile
->bounds
, metafile
->unit
, callback
, cb_data
, attrs
);
840 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestRectI(GpGraphics
*graphics
,
841 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpRect
*dest
,
842 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
846 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
850 destf
.Width
= dest
->Width
;
851 destf
.Height
= dest
->Height
;
853 return GdipEnumerateMetafileDestRect(graphics
, metafile
, &destf
, callback
, cb_data
, attrs
);
856 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestPoint(GpGraphics
*graphics
,
857 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpPointF
*dest
,
858 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
862 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
866 destf
.Width
= units_to_pixels(metafile
->bounds
.Width
, metafile
->unit
, metafile
->image
.xres
);
867 destf
.Height
= units_to_pixels(metafile
->bounds
.Height
, metafile
->unit
, metafile
->image
.yres
);
869 return GdipEnumerateMetafileDestRect(graphics
, metafile
, &destf
, callback
, cb_data
, attrs
);
872 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestPointI(GpGraphics
*graphics
,
873 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpPoint
*dest
,
874 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
878 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
883 return GdipEnumerateMetafileDestPoint(graphics
, metafile
, &ptf
, callback
, cb_data
, attrs
);
886 static int CALLBACK
get_metafile_type_proc(HDC hDC
, HANDLETABLE
*lpHTable
, const ENHMETARECORD
*lpEMFR
,
887 int nObj
, LPARAM lpData
)
889 MetafileType
*result
= (MetafileType
*)lpData
;
891 if (lpEMFR
->iType
== EMR_GDICOMMENT
)
893 const EMRGDICOMMENT
*comment
= (const EMRGDICOMMENT
*)lpEMFR
;
895 if (comment
->cbData
>= 4 && memcmp(comment
->Data
, "EMF+", 4) == 0)
897 const EmfPlusRecordHeader
*header
= (const EmfPlusRecordHeader
*)&comment
->Data
[4];
899 if (4 + sizeof(EmfPlusRecordHeader
) <= comment
->cbData
&&
900 header
->Type
== EmfPlusRecordTypeHeader
)
902 if ((header
->Flags
& 1) == 1)
903 *result
= MetafileTypeEmfPlusDual
;
905 *result
= MetafileTypeEmfPlusOnly
;
909 *result
= MetafileTypeEmf
;
912 *result
= MetafileTypeEmf
;
917 static MetafileType
METAFILE_GetEmfType(HENHMETAFILE hemf
)
919 MetafileType result
= MetafileTypeInvalid
;
920 EnumEnhMetaFile(NULL
, hemf
, get_metafile_type_proc
, &result
, NULL
);
924 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromMetafile(GpMetafile
* metafile
,
925 MetafileHeader
* header
)
929 TRACE("(%p, %p)\n", metafile
, header
);
931 if(!metafile
|| !header
)
932 return InvalidParameter
;
935 FIXME("not implemented\n");
937 memset(header
, 0, sizeof(MetafileHeader
));
942 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromEmf(HENHMETAFILE hEmf
,
943 MetafileHeader
*header
)
948 return InvalidParameter
;
951 FIXME("not implemented\n");
953 memset(header
, 0, sizeof(MetafileHeader
));
958 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromFile(GDIPCONST WCHAR
*filename
,
959 MetafileHeader
*header
)
963 TRACE("(%s,%p)\n", debugstr_w(filename
), header
);
965 if(!filename
|| !header
)
966 return InvalidParameter
;
969 FIXME("not implemented\n");
971 memset(header
, 0, sizeof(MetafileHeader
));
976 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromStream(IStream
*stream
,
977 MetafileHeader
*header
)
981 TRACE("(%p,%p)\n", stream
, header
);
983 if(!stream
|| !header
)
984 return InvalidParameter
;
987 FIXME("not implemented\n");
989 memset(header
, 0, sizeof(MetafileHeader
));
994 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
995 GpMetafile
**metafile
)
997 ENHMETAHEADER header
;
998 MetafileType metafile_type
;
1000 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
1002 if(!hemf
|| !metafile
)
1003 return InvalidParameter
;
1005 if (GetEnhMetaFileHeader(hemf
, sizeof(header
), &header
) == 0)
1006 return GenericError
;
1008 metafile_type
= METAFILE_GetEmfType(hemf
);
1010 if (metafile_type
== MetafileTypeInvalid
)
1011 return GenericError
;
1013 *metafile
= heap_alloc_zero(sizeof(GpMetafile
));
1017 (*metafile
)->image
.type
= ImageTypeMetafile
;
1018 (*metafile
)->image
.format
= ImageFormatEMF
;
1019 (*metafile
)->image
.frame_count
= 1;
1020 (*metafile
)->image
.xres
= (REAL
)header
.szlDevice
.cx
;
1021 (*metafile
)->image
.yres
= (REAL
)header
.szlDevice
.cy
;
1022 (*metafile
)->bounds
.X
= (REAL
)header
.rclBounds
.left
;
1023 (*metafile
)->bounds
.Y
= (REAL
)header
.rclBounds
.top
;
1024 (*metafile
)->bounds
.Width
= (REAL
)(header
.rclBounds
.right
- header
.rclBounds
.left
);
1025 (*metafile
)->bounds
.Height
= (REAL
)(header
.rclBounds
.bottom
- header
.rclBounds
.top
);
1026 (*metafile
)->unit
= UnitPixel
;
1027 (*metafile
)->metafile_type
= metafile_type
;
1028 (*metafile
)->hemf
= hemf
;
1029 (*metafile
)->preserve_hemf
= !delete;
1031 TRACE("<-- %p\n", *metafile
);
1036 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1037 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1042 GpStatus retval
= Ok
;
1044 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1046 if(!hwmf
|| !metafile
|| !placeable
)
1047 return InvalidParameter
;
1050 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1052 return GenericError
;
1053 copy
= heap_alloc_zero(read
);
1054 GetMetaFileBitsEx(hwmf
, read
, copy
);
1056 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1059 /* FIXME: We should store and use hwmf instead of converting to hemf */
1060 retval
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
1064 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
1065 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
1066 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
1067 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
1068 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
1069 placeable
->BoundingBox
.Left
);
1070 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
1071 placeable
->BoundingBox
.Top
);
1072 (*metafile
)->metafile_type
= MetafileTypeWmfPlaceable
;
1073 (*metafile
)->image
.format
= ImageFormatWMF
;
1075 if (delete) DeleteMetaFile(hwmf
);
1078 DeleteEnhMetaFile(hemf
);
1082 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1083 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1085 HMETAFILE hmf
= GetMetaFileW(file
);
1087 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1089 if(!hmf
) return InvalidParameter
;
1091 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1094 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
1095 GpMetafile
**metafile
)
1097 FIXME("(%p, %p): stub\n", file
, metafile
);
1098 return NotImplemented
;
1101 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
1102 GpMetafile
**metafile
)
1104 FIXME("(%p, %p): stub\n", stream
, metafile
);
1105 return NotImplemented
;
1108 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
1113 TRACE("(%p,%u)\n", metafile
, limitDpi
);
1116 FIXME("not implemented\n");
1118 return NotImplemented
;
1121 GpStatus WINGDIPAPI
GdipConvertToEmfPlus(const GpGraphics
* ref
,
1122 GpMetafile
* metafile
, BOOL
* succ
, EmfType emfType
,
1123 const WCHAR
* description
, GpMetafile
** out_metafile
)
1127 TRACE("(%p,%p,%p,%u,%s,%p)\n", ref
, metafile
, succ
, emfType
,
1128 debugstr_w(description
), out_metafile
);
1130 if(!ref
|| !metafile
|| !out_metafile
|| emfType
< EmfTypeEmfOnly
|| emfType
> EmfTypeEmfPlusDual
)
1131 return InvalidParameter
;
1135 *out_metafile
= NULL
;
1138 FIXME("not implemented\n");
1140 return NotImplemented
;
1143 GpStatus WINGDIPAPI
GdipEmfToWmfBits(HENHMETAFILE hemf
, UINT cbData16
,
1144 LPBYTE pData16
, INT iMapMode
, INT eFlags
)
1146 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf
, cbData16
, pData16
, iMapMode
, eFlags
);
1147 return NotImplemented
;
1150 GpStatus WINGDIPAPI
GdipRecordMetafileFileName(GDIPCONST WCHAR
* fileName
,
1151 HDC hdc
, EmfType type
, GDIPCONST GpRectF
*pFrameRect
,
1152 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
,
1153 GpMetafile
**metafile
)
1155 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
1156 frameUnit
, debugstr_w(desc
), metafile
);
1158 return NotImplemented
;
1161 GpStatus WINGDIPAPI
GdipRecordMetafileFileNameI(GDIPCONST WCHAR
* fileName
, HDC hdc
, EmfType type
,
1162 GDIPCONST GpRect
*pFrameRect
, MetafileFrameUnit frameUnit
,
1163 GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
1165 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
1166 frameUnit
, debugstr_w(desc
), metafile
);
1168 return NotImplemented
;
1171 /*****************************************************************************
1172 * GdipConvertToEmfPlusToFile [GDIPLUS.@]
1175 GpStatus WINGDIPAPI
GdipConvertToEmfPlusToFile(const GpGraphics
* refGraphics
,
1176 GpMetafile
* metafile
, BOOL
* conversionSuccess
,
1177 const WCHAR
* filename
, EmfType emfType
,
1178 const WCHAR
* description
, GpMetafile
** out_metafile
)
1180 FIXME("stub: %p, %p, %p, %p, %u, %p, %p\n", refGraphics
, metafile
, conversionSuccess
, filename
, emfType
, description
, out_metafile
);
1181 return NotImplemented
;