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
23 #define NONAMELESSUNION
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
45 HRESULT WINAPI
WICCreateImagingFactory_Proxy(UINT
, IWICImagingFactory
**);
47 typedef ARGB EmfPlusARGB
;
49 typedef struct EmfPlusRecordHeader
55 } EmfPlusRecordHeader
;
57 typedef struct EmfPlusHeader
59 EmfPlusRecordHeader Header
;
66 typedef struct EmfPlusClear
68 EmfPlusRecordHeader Header
;
72 typedef struct EmfPlusFillRects
74 EmfPlusRecordHeader Header
;
79 typedef struct EmfPlusSetClipRect
81 EmfPlusRecordHeader Header
;
85 typedef struct EmfPlusSetPageTransform
87 EmfPlusRecordHeader Header
;
89 } EmfPlusSetPageTransform
;
91 typedef struct EmfPlusRect
99 typedef struct EmfPlusSetWorldTransform
101 EmfPlusRecordHeader Header
;
103 } EmfPlusSetWorldTransform
;
105 typedef struct EmfPlusScaleWorldTransform
107 EmfPlusRecordHeader Header
;
110 } EmfPlusScaleWorldTransform
;
112 typedef struct EmfPlusMultiplyWorldTransform
114 EmfPlusRecordHeader Header
;
116 } EmfPlusMultiplyWorldTransform
;
118 typedef struct EmfPlusRotateWorldTransform
120 EmfPlusRecordHeader Header
;
122 } EmfPlusRotateWorldTransform
;
124 typedef struct EmfPlusTranslateWorldTransform
126 EmfPlusRecordHeader Header
;
129 } EmfPlusTranslateWorldTransform
;
131 typedef struct EmfPlusBeginContainer
133 EmfPlusRecordHeader Header
;
137 } EmfPlusBeginContainer
;
139 typedef struct EmfPlusContainerRecord
141 EmfPlusRecordHeader Header
;
143 } EmfPlusContainerRecord
;
151 typedef struct container
155 enum container_type type
;
156 GraphicsContainer state
;
157 GpMatrix world_transform
;
165 PenDataTransform
= 0x0001,
166 PenDataStartCap
= 0x0002,
167 PenDataEndCap
= 0x0004,
168 PenDataJoin
= 0x0008,
169 PenDataMiterLimit
= 0x0010,
170 PenDataLineStyle
= 0x0020,
171 PenDataDashedLineCap
= 0x0040,
172 PenDataDashedLineOffset
= 0x0080,
173 PenDataDashedLine
= 0x0100,
174 PenDataNonCenter
= 0x0200,
175 PenDataCompoundLine
= 0x0400,
176 PenDataCustomStartCap
= 0x0800,
177 PenDataCustomEndCap
= 0x1000
180 typedef struct EmfPlusTransformMatrix
182 REAL TransformMatrix
[6];
183 } EmfPlusTransformMatrix
;
195 typedef struct EmfPlusDashedLineData
197 DWORD DashedLineDataSize
;
199 } EmfPlusDashedLineData
;
201 typedef struct EmfPlusCompoundLineData
203 DWORD CompoundLineDataSize
;
205 } EmfPlusCompoundLineData
;
207 typedef struct EmfPlusCustomStartCapData
209 DWORD CustomStartCapSize
;
211 } EmfPlusCustomStartCapData
;
213 typedef struct EmfPlusCustomEndCapData
215 DWORD CustomEndCapSize
;
217 } EmfPlusCustomEndCapData
;
219 typedef struct EmfPlusPenData
224 BYTE OptionalData
[1];
229 BrushDataPath
= 1 << 0,
230 BrushDataTransform
= 1 << 1,
231 BrushDataPresetColors
= 1 << 2,
232 BrushDataBlendFactorsH
= 1 << 3,
233 BrushDataBlendFactorsV
= 1 << 4,
234 BrushDataFocusScales
= 1 << 6,
235 BrushDataIsGammaCorrected
= 1 << 7,
236 BrushDataDoNotTransform
= 1 << 8,
239 typedef struct EmfPlusSolidBrushData
241 EmfPlusARGB SolidColor
;
242 } EmfPlusSolidBrushData
;
244 typedef struct EmfPlusHatchBrushData
247 EmfPlusARGB ForeColor
;
248 EmfPlusARGB BackColor
;
249 } EmfPlusHatchBrushData
;
251 typedef struct EmfPlusTextureBrushData
253 DWORD BrushDataFlags
;
255 BYTE OptionalData
[1];
256 } EmfPlusTextureBrushData
;
258 typedef struct EmfPlusRectF
266 typedef struct EmfPlusLinearGradientBrushData
268 DWORD BrushDataFlags
;
271 EmfPlusARGB StartColor
;
272 EmfPlusARGB EndColor
;
275 BYTE OptionalData
[1];
276 } EmfPlusLinearGradientBrushData
;
278 typedef struct EmfPlusBrush
283 EmfPlusSolidBrushData solid
;
284 EmfPlusHatchBrushData hatch
;
285 EmfPlusTextureBrushData texture
;
286 EmfPlusLinearGradientBrushData lineargradient
;
290 typedef struct EmfPlusPen
299 typedef struct EmfPlusPath
302 DWORD PathPointCount
;
303 DWORD PathPointFlags
;
305 /* PathPointTypes[] */
306 /* AlignmentPadding */
310 typedef struct EmfPlusRegionNodePath
312 DWORD RegionNodePathLength
;
313 EmfPlusPath RegionNodePath
;
314 } EmfPlusRegionNodePath
;
316 typedef struct EmfPlusRegion
319 DWORD RegionNodeCount
;
323 typedef struct EmfPlusPalette
325 DWORD PaletteStyleFlags
;
327 BYTE PaletteEntries
[1];
333 BitmapDataTypeCompressed
,
336 typedef struct EmfPlusBitmap
346 typedef struct EmfPlusMetafile
349 DWORD MetafileDataSize
;
350 BYTE MetafileData
[1];
353 typedef enum ImageDataType
355 ImageDataTypeUnknown
,
357 ImageDataTypeMetafile
,
360 typedef struct EmfPlusImage
366 EmfPlusBitmap bitmap
;
367 EmfPlusMetafile metafile
;
371 typedef struct EmfPlusImageAttributes
376 EmfPlusARGB ClampColor
;
379 } EmfPlusImageAttributes
;
381 typedef struct EmfPlusFont
386 DWORD FontStyleFlags
;
392 typedef struct EmfPlusObject
394 EmfPlusRecordHeader Header
;
400 EmfPlusRegion region
;
402 EmfPlusImageAttributes image_attributes
;
407 typedef struct EmfPlusPointR7
413 typedef struct EmfPlusPoint
419 typedef struct EmfPlusPointF
425 typedef struct EmfPlusDrawImage
427 EmfPlusRecordHeader Header
;
428 DWORD ImageAttributesID
;
430 EmfPlusRectF SrcRect
;
438 typedef struct EmfPlusDrawImagePoints
440 EmfPlusRecordHeader Header
;
441 DWORD ImageAttributesID
;
443 EmfPlusRectF SrcRect
;
447 EmfPlusPointR7 pointsR
[3];
448 EmfPlusPoint points
[3];
449 EmfPlusPointF pointsF
[3];
451 } EmfPlusDrawImagePoints
;
453 typedef struct EmfPlusDrawPath
455 EmfPlusRecordHeader Header
;
459 typedef struct EmfPlusDrawArc
461 EmfPlusRecordHeader Header
;
471 typedef struct EmfPlusDrawEllipse
473 EmfPlusRecordHeader Header
;
479 } EmfPlusDrawEllipse
;
481 typedef struct EmfPlusDrawPie
483 EmfPlusRecordHeader Header
;
493 typedef struct EmfPlusDrawRects
495 EmfPlusRecordHeader Header
;
500 EmfPlusRectF rectF
[1];
504 typedef struct EmfPlusFillPath
506 EmfPlusRecordHeader Header
;
514 typedef struct EmfPlusFillClosedCurve
516 EmfPlusRecordHeader Header
;
522 EmfPlusPointR7 pointsR
[1];
523 EmfPlusPoint points
[1];
524 EmfPlusPointF pointsF
[1];
526 } EmfPlusFillClosedCurve
;
528 typedef struct EmfPlusFillEllipse
530 EmfPlusRecordHeader Header
;
537 } EmfPlusFillEllipse
;
539 typedef struct EmfPlusFillPie
541 EmfPlusRecordHeader Header
;
552 typedef struct EmfPlusDrawDriverString
554 EmfPlusRecordHeader Header
;
560 DWORD DriverStringOptionsFlags
;
563 BYTE VariableData
[1];
564 } EmfPlusDrawDriverString
;
566 typedef struct EmfPlusFillRegion
568 EmfPlusRecordHeader Header
;
576 static void metafile_free_object_table_entry(GpMetafile
*metafile
, BYTE id
)
578 struct emfplus_object
*object
= &metafile
->objtable
[id
];
580 switch (object
->type
)
582 case ObjectTypeInvalid
:
584 case ObjectTypeBrush
:
585 GdipDeleteBrush(object
->u
.brush
);
588 GdipDeletePen(object
->u
.pen
);
591 GdipDeletePath(object
->u
.path
);
593 case ObjectTypeRegion
:
594 GdipDeleteRegion(object
->u
.region
);
596 case ObjectTypeImage
:
597 GdipDisposeImage(object
->u
.image
);
600 GdipDeleteFont(object
->u
.font
);
602 case ObjectTypeImageAttributes
:
603 GdipDisposeImageAttributes(object
->u
.image_attributes
);
606 FIXME("not implemented for object type %u.\n", object
->type
);
610 object
->type
= ObjectTypeInvalid
;
611 object
->u
.object
= NULL
;
614 void METAFILE_Free(GpMetafile
*metafile
)
618 heap_free(metafile
->comment_data
);
619 DeleteEnhMetaFile(CloseEnhMetaFile(metafile
->record_dc
));
620 if (!metafile
->preserve_hemf
)
621 DeleteEnhMetaFile(metafile
->hemf
);
622 if (metafile
->record_graphics
)
624 WARN("metafile closed while recording\n");
625 /* not sure what to do here; for now just prevent the graphics from functioning or using this object */
626 metafile
->record_graphics
->image
= NULL
;
627 metafile
->record_graphics
->busy
= TRUE
;
630 if (metafile
->record_stream
)
631 IStream_Release(metafile
->record_stream
);
633 for (i
= 0; i
< ARRAY_SIZE(metafile
->objtable
); i
++)
634 metafile_free_object_table_entry(metafile
, i
);
637 static DWORD
METAFILE_AddObjectId(GpMetafile
*metafile
)
639 return (metafile
->next_object_id
++) % EmfPlusObjectTableSize
;
642 static GpStatus
METAFILE_AllocateRecord(GpMetafile
*metafile
, DWORD size
, void **result
)
645 EmfPlusRecordHeader
*record
;
647 if (!metafile
->comment_data_size
)
649 DWORD data_size
= max(256, size
* 2 + 4);
650 metafile
->comment_data
= heap_alloc_zero(data_size
);
652 if (!metafile
->comment_data
)
655 memcpy(metafile
->comment_data
, "EMF+", 4);
657 metafile
->comment_data_size
= data_size
;
658 metafile
->comment_data_length
= 4;
661 size_needed
= size
+ metafile
->comment_data_length
;
663 if (size_needed
> metafile
->comment_data_size
)
665 DWORD data_size
= size_needed
* 2;
666 BYTE
*new_data
= heap_alloc_zero(data_size
);
671 memcpy(new_data
, metafile
->comment_data
, metafile
->comment_data_length
);
673 metafile
->comment_data_size
= data_size
;
674 heap_free(metafile
->comment_data
);
675 metafile
->comment_data
= new_data
;
678 *result
= metafile
->comment_data
+ metafile
->comment_data_length
;
679 metafile
->comment_data_length
+= size
;
681 record
= (EmfPlusRecordHeader
*)*result
;
683 record
->DataSize
= size
- sizeof(EmfPlusRecordHeader
);
688 static void METAFILE_RemoveLastRecord(GpMetafile
*metafile
, EmfPlusRecordHeader
*record
)
690 assert(metafile
->comment_data
+ metafile
->comment_data_length
== (BYTE
*)record
+ record
->Size
);
691 metafile
->comment_data_length
-= record
->Size
;
694 static void METAFILE_WriteRecords(GpMetafile
*metafile
)
696 if (metafile
->comment_data_length
> 4)
698 GdiComment(metafile
->record_dc
, metafile
->comment_data_length
, metafile
->comment_data
);
699 metafile
->comment_data_length
= 4;
703 static GpStatus
METAFILE_WriteHeader(GpMetafile
*metafile
, HDC hdc
)
707 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
709 EmfPlusHeader
*header
;
711 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusHeader
), (void**)&header
);
715 header
->Header
.Type
= EmfPlusRecordTypeHeader
;
717 if (metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
718 header
->Header
.Flags
= 1;
720 header
->Header
.Flags
= 0;
722 header
->Version
= VERSION_MAGIC2
;
724 if (GetDeviceCaps(hdc
, TECHNOLOGY
) == DT_RASDISPLAY
)
725 header
->EmfPlusFlags
= 1;
727 header
->EmfPlusFlags
= 0;
729 header
->LogicalDpiX
= GetDeviceCaps(hdc
, LOGPIXELSX
);
730 header
->LogicalDpiY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
732 METAFILE_WriteRecords(metafile
);
738 static GpStatus
METAFILE_WriteEndOfFile(GpMetafile
*metafile
)
742 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
744 EmfPlusRecordHeader
*record
;
746 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusRecordHeader
), (void**)&record
);
750 record
->Type
= EmfPlusRecordTypeEndOfFile
;
753 METAFILE_WriteRecords(metafile
);
759 GpStatus WINGDIPAPI
GdipRecordMetafile(HDC hdc
, EmfType type
, GDIPCONST GpRectF
*frameRect
,
760 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
763 TRACE("(%p %d %s %d %p %p)\n", hdc
, type
, debugstr_rectf(frameRect
), frameUnit
, desc
, metafile
);
765 return GdipRecordMetafileFileName(NULL
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
768 /*****************************************************************************
769 * GdipRecordMetafileI [GDIPLUS.@]
771 GpStatus WINGDIPAPI
GdipRecordMetafileI(HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
772 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
774 GpRectF frameRectF
, *pFrameRectF
;
776 TRACE("(%p %d %p %d %p %p)\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
780 set_rect(&frameRectF
, frameRect
->X
, frameRect
->Y
, frameRect
->Width
, frameRect
->Height
);
781 pFrameRectF
= &frameRectF
;
786 return GdipRecordMetafile(hdc
, type
, pFrameRectF
, frameUnit
, desc
, metafile
);
789 GpStatus WINGDIPAPI
GdipRecordMetafileStreamI(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
790 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
792 GpRectF frameRectF
, *pFrameRectF
;
794 TRACE("(%p %p %d %p %d %p %p)\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
798 set_rect(&frameRectF
, frameRect
->X
, frameRect
->Y
, frameRect
->Width
, frameRect
->Height
);
799 pFrameRectF
= &frameRectF
;
804 return GdipRecordMetafileStream(stream
, hdc
, type
, pFrameRectF
, frameUnit
, desc
, metafile
);
807 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRectF
*frameRect
,
808 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
812 TRACE("(%p %p %d %s %d %p %p)\n", stream
, hdc
, type
, debugstr_rectf(frameRect
), frameUnit
, desc
, metafile
);
815 return InvalidParameter
;
817 stat
= GdipRecordMetafile(hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
821 (*metafile
)->record_stream
= stream
;
822 IStream_AddRef(stream
);
828 static void METAFILE_AdjustFrame(GpMetafile
* metafile
, const GpPointF
*points
,
833 if (!metafile
->auto_frame
|| !num_points
)
836 if (metafile
->auto_frame_max
.X
< metafile
->auto_frame_min
.X
)
837 metafile
->auto_frame_max
= metafile
->auto_frame_min
= points
[0];
839 for (i
=0; i
<num_points
; i
++)
841 if (points
[i
].X
< metafile
->auto_frame_min
.X
)
842 metafile
->auto_frame_min
.X
= points
[i
].X
;
843 if (points
[i
].X
> metafile
->auto_frame_max
.X
)
844 metafile
->auto_frame_max
.X
= points
[i
].X
;
845 if (points
[i
].Y
< metafile
->auto_frame_min
.Y
)
846 metafile
->auto_frame_min
.Y
= points
[i
].Y
;
847 if (points
[i
].Y
> metafile
->auto_frame_max
.Y
)
848 metafile
->auto_frame_max
.Y
= points
[i
].Y
;
852 GpStatus
METAFILE_GetGraphicsContext(GpMetafile
* metafile
, GpGraphics
**result
)
856 if (!metafile
->record_dc
|| metafile
->record_graphics
)
857 return InvalidParameter
;
859 stat
= graphics_from_image((GpImage
*)metafile
, &metafile
->record_graphics
);
863 *result
= metafile
->record_graphics
;
864 metafile
->record_graphics
->xres
= metafile
->logical_dpix
;
865 metafile
->record_graphics
->yres
= metafile
->logical_dpiy
;
866 metafile
->record_graphics
->printer_display
= metafile
->printer_display
;
872 GpStatus
METAFILE_GetDC(GpMetafile
* metafile
, HDC
*hdc
)
874 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
876 EmfPlusRecordHeader
*record
;
879 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusRecordHeader
), (void**)&record
);
883 record
->Type
= EmfPlusRecordTypeGetDC
;
886 METAFILE_WriteRecords(metafile
);
889 *hdc
= metafile
->record_dc
;
894 GpStatus
METAFILE_GraphicsClear(GpMetafile
* metafile
, ARGB color
)
896 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
898 EmfPlusClear
*record
;
901 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusClear
), (void**)&record
);
905 record
->Header
.Type
= EmfPlusRecordTypeClear
;
906 record
->Header
.Flags
= 0;
907 record
->Color
= color
;
909 METAFILE_WriteRecords(metafile
);
915 static BOOL
is_integer_rect(const GpRectF
*rect
)
917 SHORT x
, y
, width
, height
;
921 height
= rect
->Height
;
922 if (rect
->X
!= (REAL
)x
|| rect
->Y
!= (REAL
)y
||
923 rect
->Width
!= (REAL
)width
|| rect
->Height
!= (REAL
)height
)
928 static GpStatus
METAFILE_PrepareBrushData(GDIPCONST GpBrush
*brush
, DWORD
*size
)
932 case BrushTypeSolidColor
:
933 *size
= FIELD_OFFSET(EmfPlusBrush
, BrushData
) + sizeof(EmfPlusSolidBrushData
);
935 case BrushTypeHatchFill
:
936 *size
= FIELD_OFFSET(EmfPlusBrush
, BrushData
) + sizeof(EmfPlusHatchBrushData
);
938 case BrushTypeLinearGradient
:
941 GpLineGradient
*gradient
= (GpLineGradient
*)brush
;
943 *size
= FIELD_OFFSET(EmfPlusBrush
, BrushData
.lineargradient
.OptionalData
);
945 GdipIsMatrixIdentity(&gradient
->transform
, &ignore_xform
);
947 *size
+= sizeof(gradient
->transform
);
949 if (gradient
->pblendcount
> 1 && gradient
->pblendcolor
&& gradient
->pblendpos
)
950 *size
+= sizeof(DWORD
) + gradient
->pblendcount
*
951 (sizeof(*gradient
->pblendcolor
) + sizeof(*gradient
->pblendpos
));
952 else if (gradient
->blendcount
> 1 && gradient
->blendfac
&& gradient
->blendpos
)
953 *size
+= sizeof(DWORD
) + gradient
->blendcount
*
954 (sizeof(*gradient
->blendfac
) + sizeof(*gradient
->blendpos
));
959 FIXME("unsupported brush type: %d\n", brush
->bt
);
960 return NotImplemented
;
966 static void METAFILE_FillBrushData(GDIPCONST GpBrush
*brush
, EmfPlusBrush
*data
)
968 data
->Version
= VERSION_MAGIC2
;
969 data
->Type
= brush
->bt
;
973 case BrushTypeSolidColor
:
975 GpSolidFill
*solid
= (GpSolidFill
*)brush
;
976 data
->BrushData
.solid
.SolidColor
= solid
->color
;
979 case BrushTypeHatchFill
:
981 GpHatch
*hatch
= (GpHatch
*)brush
;
982 data
->BrushData
.hatch
.HatchStyle
= hatch
->hatchstyle
;
983 data
->BrushData
.hatch
.ForeColor
= hatch
->forecol
;
984 data
->BrushData
.hatch
.BackColor
= hatch
->backcol
;
987 case BrushTypeLinearGradient
:
991 GpLineGradient
*gradient
= (GpLineGradient
*)brush
;
993 data
->BrushData
.lineargradient
.BrushDataFlags
= 0;
994 data
->BrushData
.lineargradient
.WrapMode
= gradient
->wrap
;
995 data
->BrushData
.lineargradient
.RectF
.X
= gradient
->rect
.X
;
996 data
->BrushData
.lineargradient
.RectF
.Y
= gradient
->rect
.Y
;
997 data
->BrushData
.lineargradient
.RectF
.Width
= gradient
->rect
.Width
;
998 data
->BrushData
.lineargradient
.RectF
.Height
= gradient
->rect
.Height
;
999 data
->BrushData
.lineargradient
.StartColor
= gradient
->startcolor
;
1000 data
->BrushData
.lineargradient
.EndColor
= gradient
->endcolor
;
1001 data
->BrushData
.lineargradient
.Reserved1
= gradient
->startcolor
;
1002 data
->BrushData
.lineargradient
.Reserved2
= gradient
->endcolor
;
1004 if (gradient
->gamma
)
1005 data
->BrushData
.lineargradient
.BrushDataFlags
|= BrushDataIsGammaCorrected
;
1007 cursor
= &data
->BrushData
.lineargradient
.OptionalData
[0];
1009 GdipIsMatrixIdentity(&gradient
->transform
, &ignore_xform
);
1012 data
->BrushData
.lineargradient
.BrushDataFlags
|= BrushDataTransform
;
1013 memcpy(cursor
, &gradient
->transform
, sizeof(gradient
->transform
));
1014 cursor
+= sizeof(gradient
->transform
);
1017 if (gradient
->pblendcount
> 1 && gradient
->pblendcolor
&& gradient
->pblendpos
)
1019 const DWORD count
= gradient
->pblendcount
;
1021 data
->BrushData
.lineargradient
.BrushDataFlags
|= BrushDataPresetColors
;
1023 memcpy(cursor
, &count
, sizeof(count
));
1024 cursor
+= sizeof(count
);
1026 memcpy(cursor
, gradient
->pblendpos
, count
* sizeof(*gradient
->pblendpos
));
1027 cursor
+= count
* sizeof(*gradient
->pblendpos
);
1029 memcpy(cursor
, gradient
->pblendcolor
, count
* sizeof(*gradient
->pblendcolor
));
1031 else if (gradient
->blendcount
> 1 && gradient
->blendfac
&& gradient
->blendpos
)
1033 const DWORD count
= gradient
->blendcount
;
1035 data
->BrushData
.lineargradient
.BrushDataFlags
|= BrushDataBlendFactorsH
;
1037 memcpy(cursor
, &count
, sizeof(count
));
1038 cursor
+= sizeof(count
);
1040 memcpy(cursor
, gradient
->blendpos
, count
* sizeof(*gradient
->blendpos
));
1041 cursor
+= count
* sizeof(*gradient
->blendpos
);
1043 memcpy(cursor
, gradient
->blendfac
, count
* sizeof(*gradient
->blendfac
));
1049 FIXME("unsupported brush type: %d\n", brush
->bt
);
1053 static GpStatus
METAFILE_AddBrushObject(GpMetafile
*metafile
, GDIPCONST GpBrush
*brush
, DWORD
*id
)
1055 EmfPlusObject
*object_record
;
1060 if (metafile
->metafile_type
!= MetafileTypeEmfPlusOnly
&& metafile
->metafile_type
!= MetafileTypeEmfPlusDual
)
1063 stat
= METAFILE_PrepareBrushData(brush
, &size
);
1064 if (stat
!= Ok
) return stat
;
1066 stat
= METAFILE_AllocateRecord(metafile
,
1067 FIELD_OFFSET(EmfPlusObject
, ObjectData
) + size
, (void**)&object_record
);
1068 if (stat
!= Ok
) return stat
;
1070 *id
= METAFILE_AddObjectId(metafile
);
1071 object_record
->Header
.Type
= EmfPlusRecordTypeObject
;
1072 object_record
->Header
.Flags
= *id
| ObjectTypeBrush
<< 8;
1073 METAFILE_FillBrushData(brush
, &object_record
->ObjectData
.brush
);
1077 GpStatus
METAFILE_FillRectangles(GpMetafile
* metafile
, GpBrush
* brush
,
1078 GDIPCONST GpRectF
* rects
, INT count
)
1080 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1082 EmfPlusFillRects
*record
;
1084 BOOL integer_rects
= TRUE
;
1089 if (brush
->bt
== BrushTypeSolidColor
)
1092 brushid
= ((GpSolidFill
*)brush
)->color
;
1096 stat
= METAFILE_AddBrushObject(metafile
, brush
, &brushid
);
1101 for (i
=0; i
<count
; i
++)
1103 if (!is_integer_rect(&rects
[i
]))
1105 integer_rects
= FALSE
;
1113 stat
= METAFILE_AllocateRecord(metafile
,
1114 sizeof(EmfPlusFillRects
) + count
* (integer_rects
? sizeof(EmfPlusRect
) : sizeof(GpRectF
)),
1119 record
->Header
.Type
= EmfPlusRecordTypeFillRects
;
1120 record
->Header
.Flags
= flags
;
1121 record
->BrushID
= brushid
;
1122 record
->Count
= count
;
1126 EmfPlusRect
*record_rects
= (EmfPlusRect
*)(record
+1);
1127 for (i
=0; i
<count
; i
++)
1129 record_rects
[i
].X
= (SHORT
)rects
[i
].X
;
1130 record_rects
[i
].Y
= (SHORT
)rects
[i
].Y
;
1131 record_rects
[i
].Width
= (SHORT
)rects
[i
].Width
;
1132 record_rects
[i
].Height
= (SHORT
)rects
[i
].Height
;
1136 memcpy(record
+1, rects
, sizeof(GpRectF
) * count
);
1138 METAFILE_WriteRecords(metafile
);
1141 if (metafile
->auto_frame
)
1143 GpPointF corners
[4];
1146 for (i
=0; i
<count
; i
++)
1148 corners
[0].X
= rects
[i
].X
;
1149 corners
[0].Y
= rects
[i
].Y
;
1150 corners
[1].X
= rects
[i
].X
+ rects
[i
].Width
;
1151 corners
[1].Y
= rects
[i
].Y
;
1152 corners
[2].X
= rects
[i
].X
;
1153 corners
[2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
1154 corners
[3].X
= rects
[i
].X
+ rects
[i
].Width
;
1155 corners
[3].Y
= rects
[i
].Y
+ rects
[i
].Height
;
1157 GdipTransformPoints(metafile
->record_graphics
, CoordinateSpaceDevice
,
1158 CoordinateSpaceWorld
, corners
, 4);
1160 METAFILE_AdjustFrame(metafile
, corners
, 4);
1167 GpStatus
METAFILE_SetClipRect(GpMetafile
* metafile
, REAL x
, REAL y
, REAL width
, REAL height
, CombineMode mode
)
1169 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1171 EmfPlusSetClipRect
*record
;
1174 stat
= METAFILE_AllocateRecord(metafile
,
1175 sizeof(EmfPlusSetClipRect
),
1180 record
->Header
.Type
= EmfPlusRecordTypeSetClipRect
;
1181 record
->Header
.Flags
= (mode
& 0xf) << 8;
1182 record
->ClipRect
.X
= x
;
1183 record
->ClipRect
.Y
= y
;
1184 record
->ClipRect
.Width
= width
;
1185 record
->ClipRect
.Height
= height
;
1187 METAFILE_WriteRecords(metafile
);
1193 static GpStatus
METAFILE_AddRegionObject(GpMetafile
*metafile
, GpRegion
*region
, DWORD
*id
)
1195 EmfPlusObject
*object_record
;
1200 if (metafile
->metafile_type
!= MetafileTypeEmfPlusOnly
&& metafile
->metafile_type
!= MetafileTypeEmfPlusDual
)
1203 size
= write_region_data(region
, NULL
);
1204 stat
= METAFILE_AllocateRecord(metafile
,
1205 FIELD_OFFSET(EmfPlusObject
, ObjectData
.region
) + size
, (void**)&object_record
);
1206 if (stat
!= Ok
) return stat
;
1208 *id
= METAFILE_AddObjectId(metafile
);
1209 object_record
->Header
.Type
= EmfPlusRecordTypeObject
;
1210 object_record
->Header
.Flags
= *id
| ObjectTypeRegion
<< 8;
1211 write_region_data(region
, &object_record
->ObjectData
.region
);
1215 GpStatus
METAFILE_SetClipRegion(GpMetafile
* metafile
, GpRegion
* region
, CombineMode mode
)
1217 EmfPlusRecordHeader
*record
;
1221 if (metafile
->metafile_type
== MetafileTypeEmf
)
1224 return NotImplemented
;
1227 stat
= METAFILE_AddRegionObject(metafile
, region
, ®ion_id
);
1228 if (stat
!= Ok
) return stat
;
1230 stat
= METAFILE_AllocateRecord(metafile
, sizeof(*record
), (void**)&record
);
1231 if (stat
!= Ok
) return stat
;
1233 record
->Type
= EmfPlusRecordTypeSetClipRegion
;
1234 record
->Flags
= region_id
| mode
<< 8;
1236 METAFILE_WriteRecords(metafile
);
1240 GpStatus
METAFILE_SetPageTransform(GpMetafile
* metafile
, GpUnit unit
, REAL scale
)
1242 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1244 EmfPlusSetPageTransform
*record
;
1247 stat
= METAFILE_AllocateRecord(metafile
,
1248 sizeof(EmfPlusSetPageTransform
),
1253 record
->Header
.Type
= EmfPlusRecordTypeSetPageTransform
;
1254 record
->Header
.Flags
= unit
;
1255 record
->PageScale
= scale
;
1257 METAFILE_WriteRecords(metafile
);
1263 GpStatus
METAFILE_SetWorldTransform(GpMetafile
* metafile
, GDIPCONST GpMatrix
* transform
)
1265 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1267 EmfPlusSetWorldTransform
*record
;
1270 stat
= METAFILE_AllocateRecord(metafile
,
1271 sizeof(EmfPlusSetWorldTransform
),
1276 record
->Header
.Type
= EmfPlusRecordTypeSetWorldTransform
;
1277 record
->Header
.Flags
= 0;
1278 memcpy(record
->MatrixData
, transform
->matrix
, sizeof(record
->MatrixData
));
1280 METAFILE_WriteRecords(metafile
);
1286 GpStatus
METAFILE_ScaleWorldTransform(GpMetafile
* metafile
, REAL sx
, REAL sy
, MatrixOrder order
)
1288 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1290 EmfPlusScaleWorldTransform
*record
;
1293 stat
= METAFILE_AllocateRecord(metafile
,
1294 sizeof(EmfPlusScaleWorldTransform
),
1299 record
->Header
.Type
= EmfPlusRecordTypeScaleWorldTransform
;
1300 record
->Header
.Flags
= (order
== MatrixOrderAppend
? 0x2000 : 0);
1304 METAFILE_WriteRecords(metafile
);
1310 GpStatus
METAFILE_MultiplyWorldTransform(GpMetafile
* metafile
, GDIPCONST GpMatrix
* matrix
, MatrixOrder order
)
1312 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1314 EmfPlusMultiplyWorldTransform
*record
;
1317 stat
= METAFILE_AllocateRecord(metafile
,
1318 sizeof(EmfPlusMultiplyWorldTransform
),
1323 record
->Header
.Type
= EmfPlusRecordTypeMultiplyWorldTransform
;
1324 record
->Header
.Flags
= (order
== MatrixOrderAppend
? 0x2000 : 0);
1325 memcpy(record
->MatrixData
, matrix
->matrix
, sizeof(record
->MatrixData
));
1327 METAFILE_WriteRecords(metafile
);
1333 GpStatus
METAFILE_RotateWorldTransform(GpMetafile
* metafile
, REAL angle
, MatrixOrder order
)
1335 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1337 EmfPlusRotateWorldTransform
*record
;
1340 stat
= METAFILE_AllocateRecord(metafile
,
1341 sizeof(EmfPlusRotateWorldTransform
),
1346 record
->Header
.Type
= EmfPlusRecordTypeRotateWorldTransform
;
1347 record
->Header
.Flags
= (order
== MatrixOrderAppend
? 0x2000 : 0);
1348 record
->Angle
= angle
;
1350 METAFILE_WriteRecords(metafile
);
1356 GpStatus
METAFILE_TranslateWorldTransform(GpMetafile
* metafile
, REAL dx
, REAL dy
, MatrixOrder order
)
1358 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1360 EmfPlusTranslateWorldTransform
*record
;
1363 stat
= METAFILE_AllocateRecord(metafile
,
1364 sizeof(EmfPlusTranslateWorldTransform
),
1369 record
->Header
.Type
= EmfPlusRecordTypeTranslateWorldTransform
;
1370 record
->Header
.Flags
= (order
== MatrixOrderAppend
? 0x2000 : 0);
1374 METAFILE_WriteRecords(metafile
);
1380 GpStatus
METAFILE_ResetWorldTransform(GpMetafile
* metafile
)
1382 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1384 EmfPlusRecordHeader
*record
;
1387 stat
= METAFILE_AllocateRecord(metafile
,
1388 sizeof(EmfPlusRecordHeader
),
1393 record
->Type
= EmfPlusRecordTypeResetWorldTransform
;
1396 METAFILE_WriteRecords(metafile
);
1402 GpStatus
METAFILE_BeginContainer(GpMetafile
* metafile
, GDIPCONST GpRectF
*dstrect
,
1403 GDIPCONST GpRectF
*srcrect
, GpUnit unit
, DWORD StackIndex
)
1405 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1407 EmfPlusBeginContainer
*record
;
1410 stat
= METAFILE_AllocateRecord(metafile
, sizeof(*record
), (void**)&record
);
1414 record
->Header
.Type
= EmfPlusRecordTypeBeginContainer
;
1415 record
->Header
.Flags
= unit
& 0xff;
1416 record
->DestRect
= *dstrect
;
1417 record
->SrcRect
= *srcrect
;
1418 record
->StackIndex
= StackIndex
;
1420 METAFILE_WriteRecords(metafile
);
1426 GpStatus
METAFILE_BeginContainerNoParams(GpMetafile
* metafile
, DWORD StackIndex
)
1428 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1430 EmfPlusContainerRecord
*record
;
1433 stat
= METAFILE_AllocateRecord(metafile
,
1434 sizeof(EmfPlusContainerRecord
),
1439 record
->Header
.Type
= EmfPlusRecordTypeBeginContainerNoParams
;
1440 record
->Header
.Flags
= 0;
1441 record
->StackIndex
= StackIndex
;
1443 METAFILE_WriteRecords(metafile
);
1449 GpStatus
METAFILE_EndContainer(GpMetafile
* metafile
, DWORD StackIndex
)
1451 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1453 EmfPlusContainerRecord
*record
;
1456 stat
= METAFILE_AllocateRecord(metafile
,
1457 sizeof(EmfPlusContainerRecord
),
1462 record
->Header
.Type
= EmfPlusRecordTypeEndContainer
;
1463 record
->Header
.Flags
= 0;
1464 record
->StackIndex
= StackIndex
;
1466 METAFILE_WriteRecords(metafile
);
1472 GpStatus
METAFILE_SaveGraphics(GpMetafile
* metafile
, DWORD StackIndex
)
1474 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1476 EmfPlusContainerRecord
*record
;
1479 stat
= METAFILE_AllocateRecord(metafile
,
1480 sizeof(EmfPlusContainerRecord
),
1485 record
->Header
.Type
= EmfPlusRecordTypeSave
;
1486 record
->Header
.Flags
= 0;
1487 record
->StackIndex
= StackIndex
;
1489 METAFILE_WriteRecords(metafile
);
1495 GpStatus
METAFILE_RestoreGraphics(GpMetafile
* metafile
, DWORD StackIndex
)
1497 if (metafile
->metafile_type
== MetafileTypeEmfPlusOnly
|| metafile
->metafile_type
== MetafileTypeEmfPlusDual
)
1499 EmfPlusContainerRecord
*record
;
1502 stat
= METAFILE_AllocateRecord(metafile
,
1503 sizeof(EmfPlusContainerRecord
),
1508 record
->Header
.Type
= EmfPlusRecordTypeRestore
;
1509 record
->Header
.Flags
= 0;
1510 record
->StackIndex
= StackIndex
;
1512 METAFILE_WriteRecords(metafile
);
1518 GpStatus
METAFILE_ReleaseDC(GpMetafile
* metafile
, HDC hdc
)
1520 if (hdc
!= metafile
->record_dc
)
1521 return InvalidParameter
;
1526 GpStatus
METAFILE_GraphicsDeleted(GpMetafile
* metafile
)
1530 stat
= METAFILE_WriteEndOfFile(metafile
);
1531 metafile
->record_graphics
= NULL
;
1533 metafile
->hemf
= CloseEnhMetaFile(metafile
->record_dc
);
1534 metafile
->record_dc
= NULL
;
1536 heap_free(metafile
->comment_data
);
1537 metafile
->comment_data
= NULL
;
1538 metafile
->comment_data_size
= 0;
1542 MetafileHeader header
;
1544 stat
= GdipGetMetafileHeaderFromEmf(metafile
->hemf
, &header
);
1545 if (stat
== Ok
&& metafile
->auto_frame
&&
1546 metafile
->auto_frame_max
.X
>= metafile
->auto_frame_min
.X
)
1548 RECTL bounds_rc
, gdi_bounds_rc
;
1549 REAL x_scale
= 2540.0 / header
.DpiX
;
1550 REAL y_scale
= 2540.0 / header
.DpiY
;
1554 gdi_bounds_rc
= header
.u
.EmfHeader
.rclBounds
;
1555 if (gdi_bounds_rc
.right
> gdi_bounds_rc
.left
&&
1556 gdi_bounds_rc
.bottom
> gdi_bounds_rc
.top
)
1558 GpPointF
*af_min
= &metafile
->auto_frame_min
;
1559 GpPointF
*af_max
= &metafile
->auto_frame_max
;
1561 af_min
->X
= fmin(af_min
->X
, gdi_bounds_rc
.left
);
1562 af_min
->Y
= fmin(af_min
->Y
, gdi_bounds_rc
.top
);
1563 af_max
->X
= fmax(af_max
->X
, gdi_bounds_rc
.right
);
1564 af_max
->Y
= fmax(af_max
->Y
, gdi_bounds_rc
.bottom
);
1567 bounds_rc
.left
= floorf(metafile
->auto_frame_min
.X
* x_scale
);
1568 bounds_rc
.top
= floorf(metafile
->auto_frame_min
.Y
* y_scale
);
1569 bounds_rc
.right
= ceilf(metafile
->auto_frame_max
.X
* x_scale
);
1570 bounds_rc
.bottom
= ceilf(metafile
->auto_frame_max
.Y
* y_scale
);
1572 buffer_size
= GetEnhMetaFileBits(metafile
->hemf
, 0, NULL
);
1573 buffer
= heap_alloc(buffer_size
);
1576 HENHMETAFILE new_hemf
;
1578 GetEnhMetaFileBits(metafile
->hemf
, buffer_size
, buffer
);
1580 ((ENHMETAHEADER
*)buffer
)->rclFrame
= bounds_rc
;
1582 new_hemf
= SetEnhMetaFileBits(buffer_size
, buffer
);
1586 DeleteEnhMetaFile(metafile
->hemf
);
1587 metafile
->hemf
= new_hemf
;
1598 stat
= GdipGetMetafileHeaderFromEmf(metafile
->hemf
, &header
);
1602 metafile
->bounds
.X
= header
.X
;
1603 metafile
->bounds
.Y
= header
.Y
;
1604 metafile
->bounds
.Width
= header
.Width
;
1605 metafile
->bounds
.Height
= header
.Height
;
1609 if (stat
== Ok
&& metafile
->record_stream
)
1614 buffer_size
= GetEnhMetaFileBits(metafile
->hemf
, 0, NULL
);
1616 buffer
= heap_alloc(buffer_size
);
1621 GetEnhMetaFileBits(metafile
->hemf
, buffer_size
, buffer
);
1623 hr
= IStream_Write(metafile
->record_stream
, buffer
, buffer_size
, NULL
);
1626 stat
= hresult_to_status(hr
);
1634 if (metafile
->record_stream
)
1636 IStream_Release(metafile
->record_stream
);
1637 metafile
->record_stream
= NULL
;
1643 GpStatus WINGDIPAPI
GdipGetHemfFromMetafile(GpMetafile
*metafile
, HENHMETAFILE
*hEmf
)
1645 TRACE("(%p,%p)\n", metafile
, hEmf
);
1647 if (!metafile
|| !hEmf
|| !metafile
->hemf
)
1648 return InvalidParameter
;
1650 *hEmf
= metafile
->hemf
;
1651 metafile
->hemf
= NULL
;
1656 static GpStatus
METAFILE_PlaybackGetDC(GpMetafile
*metafile
)
1660 stat
= GdipGetDC(metafile
->playback_graphics
, &metafile
->playback_dc
);
1665 static void METAFILE_PlaybackReleaseDC(GpMetafile
*metafile
)
1667 if (metafile
->playback_dc
)
1669 GdipReleaseDC(metafile
->playback_graphics
, metafile
->playback_dc
);
1670 metafile
->playback_dc
= NULL
;
1674 static GpStatus
METAFILE_PlaybackUpdateClip(GpMetafile
*metafile
)
1677 stat
= GdipCombineRegionRegion(metafile
->playback_graphics
->clip
, metafile
->base_clip
, CombineModeReplace
);
1679 stat
= GdipCombineRegionRegion(metafile
->playback_graphics
->clip
, metafile
->clip
, CombineModeIntersect
);
1683 static GpStatus
METAFILE_PlaybackUpdateWorldTransform(GpMetafile
*metafile
)
1685 GpMatrix
*real_transform
;
1688 stat
= GdipCreateMatrix3(&metafile
->src_rect
, metafile
->playback_points
, &real_transform
);
1692 REAL scale_x
= units_to_pixels(1.0, metafile
->page_unit
, metafile
->logical_dpix
, metafile
->printer_display
);
1693 REAL scale_y
= units_to_pixels(1.0, metafile
->page_unit
, metafile
->logical_dpiy
, metafile
->printer_display
);
1695 if (metafile
->page_unit
!= UnitDisplay
)
1697 scale_x
*= metafile
->page_scale
;
1698 scale_y
*= metafile
->page_scale
;
1701 stat
= GdipScaleMatrix(real_transform
, scale_x
, scale_y
, MatrixOrderPrepend
);
1704 stat
= GdipMultiplyMatrix(real_transform
, metafile
->world_transform
, MatrixOrderPrepend
);
1707 stat
= GdipSetWorldTransform(metafile
->playback_graphics
, real_transform
);
1709 GdipDeleteMatrix(real_transform
);
1715 static void metafile_set_object_table_entry(GpMetafile
*metafile
, BYTE id
, BYTE type
, void *object
)
1717 metafile_free_object_table_entry(metafile
, id
);
1718 metafile
->objtable
[id
].type
= type
;
1719 metafile
->objtable
[id
].u
.object
= object
;
1722 static GpStatus
metafile_deserialize_image(const BYTE
*record_data
, UINT data_size
, GpImage
**image
)
1724 EmfPlusImage
*data
= (EmfPlusImage
*)record_data
;
1729 if (data_size
< FIELD_OFFSET(EmfPlusImage
, ImageData
))
1730 return InvalidParameter
;
1731 data_size
-= FIELD_OFFSET(EmfPlusImage
, ImageData
);
1735 case ImageDataTypeBitmap
:
1737 EmfPlusBitmap
*bitmapdata
= &data
->ImageData
.bitmap
;
1739 if (data_size
<= FIELD_OFFSET(EmfPlusBitmap
, BitmapData
))
1740 return InvalidParameter
;
1741 data_size
-= FIELD_OFFSET(EmfPlusBitmap
, BitmapData
);
1743 switch (bitmapdata
->Type
)
1745 case BitmapDataTypePixel
:
1747 ColorPalette
*palette
;
1750 if (bitmapdata
->PixelFormat
& PixelFormatIndexed
)
1752 EmfPlusPalette
*palette_obj
= (EmfPlusPalette
*)bitmapdata
->BitmapData
;
1753 UINT palette_size
= FIELD_OFFSET(EmfPlusPalette
, PaletteEntries
);
1755 if (data_size
<= palette_size
)
1756 return InvalidParameter
;
1757 palette_size
+= palette_obj
->PaletteCount
* sizeof(EmfPlusARGB
);
1759 if (data_size
< palette_size
)
1760 return InvalidParameter
;
1761 data_size
-= palette_size
;
1763 palette
= (ColorPalette
*)bitmapdata
->BitmapData
;
1764 scan0
= (BYTE
*)bitmapdata
->BitmapData
+ palette_size
;
1769 scan0
= bitmapdata
->BitmapData
;
1772 if (data_size
< bitmapdata
->Height
* bitmapdata
->Stride
)
1773 return InvalidParameter
;
1775 status
= GdipCreateBitmapFromScan0(bitmapdata
->Width
, bitmapdata
->Height
, bitmapdata
->Stride
,
1776 bitmapdata
->PixelFormat
, scan0
, (GpBitmap
**)image
);
1777 if (status
== Ok
&& palette
)
1779 status
= GdipSetImagePalette(*image
, palette
);
1782 GdipDisposeImage(*image
);
1788 case BitmapDataTypeCompressed
:
1790 IWICImagingFactory
*factory
;
1794 if (WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
) != S_OK
)
1795 return GenericError
;
1797 hr
= IWICImagingFactory_CreateStream(factory
, &stream
);
1798 IWICImagingFactory_Release(factory
);
1800 return GenericError
;
1802 if (IWICStream_InitializeFromMemory(stream
, bitmapdata
->BitmapData
, data_size
) == S_OK
)
1803 status
= GdipCreateBitmapFromStream((IStream
*)stream
, (GpBitmap
**)image
);
1805 status
= GenericError
;
1807 IWICStream_Release(stream
);
1811 WARN("Invalid bitmap type %d.\n", bitmapdata
->Type
);
1812 return InvalidParameter
;
1816 case ImageDataTypeMetafile
:
1818 EmfPlusMetafile
*metafiledata
= &data
->ImageData
.metafile
;
1820 if (data_size
<= FIELD_OFFSET(EmfPlusMetafile
, MetafileData
))
1821 return InvalidParameter
;
1822 data_size
-= FIELD_OFFSET(EmfPlusMetafile
, MetafileData
);
1824 switch (metafiledata
->Type
) {
1825 case MetafileTypeEmf
:
1826 case MetafileTypeEmfPlusOnly
:
1827 case MetafileTypeEmfPlusDual
:
1831 hemf
= SetEnhMetaFileBits(data_size
, metafiledata
->MetafileData
);
1834 return GenericError
;
1836 status
= GdipCreateMetafileFromEmf(hemf
, TRUE
, (GpMetafile
**)image
);
1839 DeleteEnhMetaFile(hemf
);
1844 FIXME("metafile type %d not supported.\n", metafiledata
->Type
);
1845 return NotImplemented
;
1850 FIXME("image type %d not supported.\n", data
->Type
);
1851 return NotImplemented
;
1857 static GpStatus
metafile_deserialize_path(const BYTE
*record_data
, UINT data_size
, GpPath
**path
)
1859 EmfPlusPath
*data
= (EmfPlusPath
*)record_data
;
1867 if (data_size
<= FIELD_OFFSET(EmfPlusPath
, data
))
1868 return InvalidParameter
;
1869 data_size
-= FIELD_OFFSET(EmfPlusPath
, data
);
1871 if (data
->PathPointFlags
& 0x800) /* R */
1873 FIXME("RLE encoded path data is not supported.\n");
1874 return NotImplemented
;
1878 if (data
->PathPointFlags
& 0x4000) /* C */
1879 size
= sizeof(EmfPlusPoint
);
1881 size
= sizeof(EmfPlusPointF
);
1882 size
+= sizeof(BYTE
); /* EmfPlusPathPointType */
1883 size
*= data
->PathPointCount
;
1886 if (data_size
< size
)
1887 return InvalidParameter
;
1889 status
= GdipCreatePath(FillModeAlternate
, path
);
1893 (*path
)->pathdata
.Count
= data
->PathPointCount
;
1894 (*path
)->pathdata
.Points
= GdipAlloc(data
->PathPointCount
* sizeof(*(*path
)->pathdata
.Points
));
1895 (*path
)->pathdata
.Types
= GdipAlloc(data
->PathPointCount
* sizeof(*(*path
)->pathdata
.Types
));
1896 (*path
)->datalen
= (*path
)->pathdata
.Count
;
1898 if (!(*path
)->pathdata
.Points
|| !(*path
)->pathdata
.Types
)
1900 GdipDeletePath(*path
);
1904 if (data
->PathPointFlags
& 0x4000) /* C */
1906 EmfPlusPoint
*points
= (EmfPlusPoint
*)data
->data
;
1907 for (i
= 0; i
< data
->PathPointCount
; i
++)
1909 (*path
)->pathdata
.Points
[i
].X
= points
[i
].X
;
1910 (*path
)->pathdata
.Points
[i
].Y
= points
[i
].Y
;
1912 types
= (BYTE
*)(points
+ i
);
1916 EmfPlusPointF
*points
= (EmfPlusPointF
*)data
->data
;
1917 memcpy((*path
)->pathdata
.Points
, points
, sizeof(*points
) * data
->PathPointCount
);
1918 types
= (BYTE
*)(points
+ data
->PathPointCount
);
1921 memcpy((*path
)->pathdata
.Types
, types
, sizeof(*types
) * data
->PathPointCount
);
1926 static GpStatus
metafile_read_region_node(struct memory_buffer
*mbuf
, GpRegion
*region
, region_element
*node
, UINT
*count
)
1931 type
= buffer_read(mbuf
, sizeof(*type
));
1932 if (!type
) return Ok
;
1938 case CombineModeReplace
:
1939 case CombineModeIntersect
:
1940 case CombineModeUnion
:
1941 case CombineModeXor
:
1942 case CombineModeExclude
:
1943 case CombineModeComplement
:
1945 region_element
*left
, *right
;
1947 left
= heap_alloc_zero(sizeof(*left
));
1951 right
= heap_alloc_zero(sizeof(*right
));
1958 status
= metafile_read_region_node(mbuf
, region
, left
, count
);
1961 status
= metafile_read_region_node(mbuf
, region
, right
, count
);
1964 node
->elementdata
.combine
.left
= left
;
1965 node
->elementdata
.combine
.right
= right
;
1966 region
->num_children
+= 2;
1975 case RegionDataRect
:
1977 const EmfPlusRectF
*rect
;
1979 rect
= buffer_read(mbuf
, sizeof(*rect
));
1981 return InvalidParameter
;
1983 memcpy(&node
->elementdata
.rect
, rect
, sizeof(*rect
));
1987 case RegionDataPath
:
1989 const BYTE
*path_data
;
1990 const UINT
*data_size
;
1993 data_size
= buffer_read(mbuf
, FIELD_OFFSET(EmfPlusRegionNodePath
, RegionNodePath
));
1995 return InvalidParameter
;
1997 path_data
= buffer_read(mbuf
, *data_size
);
1999 return InvalidParameter
;
2001 status
= metafile_deserialize_path(path_data
, *data_size
, &path
);
2004 node
->elementdata
.path
= path
;
2009 case RegionDataEmptyRect
:
2010 case RegionDataInfiniteRect
:
2014 FIXME("element type %#x is not supported\n", *type
);
2018 return InvalidParameter
;
2021 static GpStatus
metafile_deserialize_region(const BYTE
*record_data
, UINT data_size
, GpRegion
**region
)
2023 struct memory_buffer mbuf
;
2029 init_memory_buffer(&mbuf
, record_data
, data_size
);
2031 if (!buffer_read(&mbuf
, FIELD_OFFSET(EmfPlusRegion
, RegionNode
)))
2032 return InvalidParameter
;
2034 status
= GdipCreateRegion(region
);
2039 status
= metafile_read_region_node(&mbuf
, *region
, &(*region
)->node
, &count
);
2040 if (status
== Ok
&& !count
)
2041 status
= InvalidParameter
;
2045 GdipDeleteRegion(*region
);
2052 static GpStatus
metafile_deserialize_brush(const BYTE
*record_data
, UINT data_size
, GpBrush
**brush
)
2054 static const UINT header_size
= FIELD_OFFSET(EmfPlusBrush
, BrushData
);
2055 EmfPlusBrush
*data
= (EmfPlusBrush
*)record_data
;
2056 EmfPlusTransformMatrix
*transform
= NULL
;
2063 if (data_size
< header_size
)
2064 return InvalidParameter
;
2068 case BrushTypeSolidColor
:
2069 if (data_size
!= header_size
+ sizeof(EmfPlusSolidBrushData
))
2070 return InvalidParameter
;
2072 status
= GdipCreateSolidFill(data
->BrushData
.solid
.SolidColor
, (GpSolidFill
**)brush
);
2074 case BrushTypeHatchFill
:
2075 if (data_size
!= header_size
+ sizeof(EmfPlusHatchBrushData
))
2076 return InvalidParameter
;
2078 status
= GdipCreateHatchBrush(data
->BrushData
.hatch
.HatchStyle
, data
->BrushData
.hatch
.ForeColor
,
2079 data
->BrushData
.hatch
.BackColor
, (GpHatch
**)brush
);
2081 case BrushTypeTextureFill
:
2085 offset
= header_size
+ FIELD_OFFSET(EmfPlusTextureBrushData
, OptionalData
);
2086 if (data_size
<= offset
)
2087 return InvalidParameter
;
2089 brushflags
= data
->BrushData
.texture
.BrushDataFlags
;
2090 if (brushflags
& BrushDataTransform
)
2092 if (data_size
<= offset
+ sizeof(EmfPlusTransformMatrix
))
2093 return InvalidParameter
;
2094 transform
= (EmfPlusTransformMatrix
*)(record_data
+ offset
);
2095 offset
+= sizeof(EmfPlusTransformMatrix
);
2098 status
= metafile_deserialize_image(record_data
+ offset
, data_size
- offset
, &image
);
2102 status
= GdipCreateTexture(image
, data
->BrushData
.texture
.WrapMode
, (GpTexture
**)brush
);
2103 if (status
== Ok
&& transform
&& !(brushflags
& BrushDataDoNotTransform
))
2104 GdipSetTextureTransform((GpTexture
*)*brush
, (const GpMatrix
*)transform
);
2106 GdipDisposeImage(image
);
2109 case BrushTypeLinearGradient
:
2111 GpLineGradient
*gradient
= NULL
;
2113 UINT position_count
= 0;
2115 offset
= header_size
+ FIELD_OFFSET(EmfPlusLinearGradientBrushData
, OptionalData
);
2116 if (data_size
< offset
)
2117 return InvalidParameter
;
2119 brushflags
= data
->BrushData
.lineargradient
.BrushDataFlags
;
2120 if ((brushflags
& BrushDataPresetColors
) && (brushflags
& (BrushDataBlendFactorsH
| BrushDataBlendFactorsV
)))
2121 return InvalidParameter
;
2123 if (brushflags
& BrushDataTransform
)
2125 if (data_size
< offset
+ sizeof(EmfPlusTransformMatrix
))
2126 return InvalidParameter
;
2127 transform
= (EmfPlusTransformMatrix
*)(record_data
+ offset
);
2128 offset
+= sizeof(EmfPlusTransformMatrix
);
2131 if (brushflags
& (BrushDataPresetColors
| BrushDataBlendFactorsH
| BrushDataBlendFactorsV
))
2133 if (data_size
<= offset
+ sizeof(DWORD
)) /* Number of factors/preset colors. */
2134 return InvalidParameter
;
2135 position_count
= *(DWORD
*)(record_data
+ offset
);
2136 offset
+= sizeof(DWORD
);
2139 if (brushflags
& BrushDataPresetColors
)
2141 if (data_size
!= offset
+ position_count
* (sizeof(float) + sizeof(EmfPlusARGB
)))
2142 return InvalidParameter
;
2144 else if (brushflags
& BrushDataBlendFactorsH
)
2146 if (data_size
!= offset
+ position_count
* 2 * sizeof(float))
2147 return InvalidParameter
;
2150 rect
.X
= data
->BrushData
.lineargradient
.RectF
.X
;
2151 rect
.Y
= data
->BrushData
.lineargradient
.RectF
.Y
;
2152 rect
.Width
= data
->BrushData
.lineargradient
.RectF
.Width
;
2153 rect
.Height
= data
->BrushData
.lineargradient
.RectF
.Height
;
2155 status
= GdipCreateLineBrushFromRect(&rect
, data
->BrushData
.lineargradient
.StartColor
,
2156 data
->BrushData
.lineargradient
.EndColor
, LinearGradientModeHorizontal
,
2157 data
->BrushData
.lineargradient
.WrapMode
, &gradient
);
2161 status
= GdipSetLineTransform(gradient
, (const GpMatrix
*)transform
);
2165 if (brushflags
& BrushDataPresetColors
)
2166 status
= GdipSetLinePresetBlend(gradient
, (ARGB
*)(record_data
+ offset
+
2167 position_count
* sizeof(REAL
)), (REAL
*)(record_data
+ offset
), position_count
);
2168 else if (brushflags
& BrushDataBlendFactorsH
)
2169 status
= GdipSetLineBlend(gradient
, (REAL
*)(record_data
+ offset
+ position_count
* sizeof(REAL
)),
2170 (REAL
*)(record_data
+ offset
), position_count
);
2172 if (brushflags
& BrushDataIsGammaCorrected
)
2173 FIXME("BrushDataIsGammaCorrected is not handled.\n");
2178 *brush
= (GpBrush
*)gradient
;
2180 GdipDeleteBrush((GpBrush
*)gradient
);
2185 FIXME("brush type %u is not supported.\n", data
->Type
);
2186 return NotImplemented
;
2192 static GpStatus
metafile_get_pen_brush_data_offset(EmfPlusPen
*data
, UINT data_size
, DWORD
*ret
)
2194 EmfPlusPenData
*pendata
= (EmfPlusPenData
*)data
->data
;
2195 DWORD offset
= FIELD_OFFSET(EmfPlusPen
, data
);
2197 if (data_size
<= offset
)
2198 return InvalidParameter
;
2200 offset
+= FIELD_OFFSET(EmfPlusPenData
, OptionalData
);
2201 if (data_size
<= offset
)
2202 return InvalidParameter
;
2204 if (pendata
->PenDataFlags
& PenDataTransform
)
2205 offset
+= sizeof(EmfPlusTransformMatrix
);
2207 if (pendata
->PenDataFlags
& PenDataStartCap
)
2208 offset
+= sizeof(DWORD
);
2210 if (pendata
->PenDataFlags
& PenDataEndCap
)
2211 offset
+= sizeof(DWORD
);
2213 if (pendata
->PenDataFlags
& PenDataJoin
)
2214 offset
+= sizeof(DWORD
);
2216 if (pendata
->PenDataFlags
& PenDataMiterLimit
)
2217 offset
+= sizeof(REAL
);
2219 if (pendata
->PenDataFlags
& PenDataLineStyle
)
2220 offset
+= sizeof(DWORD
);
2222 if (pendata
->PenDataFlags
& PenDataDashedLineCap
)
2223 offset
+= sizeof(DWORD
);
2225 if (pendata
->PenDataFlags
& PenDataDashedLineOffset
)
2226 offset
+= sizeof(REAL
);
2228 if (pendata
->PenDataFlags
& PenDataDashedLine
)
2230 EmfPlusDashedLineData
*dashedline
= (EmfPlusDashedLineData
*)((BYTE
*)data
+ offset
);
2232 offset
+= FIELD_OFFSET(EmfPlusDashedLineData
, data
);
2233 if (data_size
<= offset
)
2234 return InvalidParameter
;
2236 offset
+= dashedline
->DashedLineDataSize
* sizeof(float);
2239 if (pendata
->PenDataFlags
& PenDataNonCenter
)
2240 offset
+= sizeof(DWORD
);
2242 if (pendata
->PenDataFlags
& PenDataCompoundLine
)
2244 EmfPlusCompoundLineData
*compoundline
= (EmfPlusCompoundLineData
*)((BYTE
*)data
+ offset
);
2246 offset
+= FIELD_OFFSET(EmfPlusCompoundLineData
, data
);
2247 if (data_size
<= offset
)
2248 return InvalidParameter
;
2250 offset
+= compoundline
->CompoundLineDataSize
* sizeof(float);
2253 if (pendata
->PenDataFlags
& PenDataCustomStartCap
)
2255 EmfPlusCustomStartCapData
*startcap
= (EmfPlusCustomStartCapData
*)((BYTE
*)data
+ offset
);
2257 offset
+= FIELD_OFFSET(EmfPlusCustomStartCapData
, data
);
2258 if (data_size
<= offset
)
2259 return InvalidParameter
;
2261 offset
+= startcap
->CustomStartCapSize
;
2264 if (pendata
->PenDataFlags
& PenDataCustomEndCap
)
2266 EmfPlusCustomEndCapData
*endcap
= (EmfPlusCustomEndCapData
*)((BYTE
*)data
+ offset
);
2268 offset
+= FIELD_OFFSET(EmfPlusCustomEndCapData
, data
);
2269 if (data_size
<= offset
)
2270 return InvalidParameter
;
2272 offset
+= endcap
->CustomEndCapSize
;
2279 static GpStatus
METAFILE_PlaybackObject(GpMetafile
*metafile
, UINT flags
, UINT data_size
, const BYTE
*record_data
)
2281 BYTE type
= (flags
>> 8) & 0xff;
2282 BYTE id
= flags
& 0xff;
2283 void *object
= NULL
;
2286 if (type
> ObjectTypeMax
|| id
>= EmfPlusObjectTableSize
)
2287 return InvalidParameter
;
2291 case ObjectTypeBrush
:
2292 status
= metafile_deserialize_brush(record_data
, data_size
, (GpBrush
**)&object
);
2296 EmfPlusPen
*data
= (EmfPlusPen
*)record_data
;
2297 EmfPlusPenData
*pendata
= (EmfPlusPenData
*)data
->data
;
2302 status
= metafile_get_pen_brush_data_offset(data
, data_size
, &offset
);
2306 status
= metafile_deserialize_brush(record_data
+ offset
, data_size
- offset
, &brush
);
2310 status
= GdipCreatePen2(brush
, pendata
->PenWidth
, pendata
->PenUnit
, &pen
);
2311 GdipDeleteBrush(brush
);
2315 offset
= FIELD_OFFSET(EmfPlusPenData
, OptionalData
);
2317 if (pendata
->PenDataFlags
& PenDataTransform
)
2319 FIXME("PenDataTransform is not supported.\n");
2320 offset
+= sizeof(EmfPlusTransformMatrix
);
2323 if (pendata
->PenDataFlags
& PenDataStartCap
)
2325 if ((status
= GdipSetPenStartCap(pen
, *(DWORD
*)((BYTE
*)pendata
+ offset
))) != Ok
)
2327 offset
+= sizeof(DWORD
);
2330 if (pendata
->PenDataFlags
& PenDataEndCap
)
2332 if ((status
= GdipSetPenEndCap(pen
, *(DWORD
*)((BYTE
*)pendata
+ offset
))) != Ok
)
2334 offset
+= sizeof(DWORD
);
2337 if (pendata
->PenDataFlags
& PenDataJoin
)
2339 if ((status
= GdipSetPenLineJoin(pen
, *(DWORD
*)((BYTE
*)pendata
+ offset
))) != Ok
)
2341 offset
+= sizeof(DWORD
);
2344 if (pendata
->PenDataFlags
& PenDataMiterLimit
)
2346 if ((status
= GdipSetPenMiterLimit(pen
, *(REAL
*)((BYTE
*)pendata
+ offset
))) != Ok
)
2348 offset
+= sizeof(REAL
);
2351 if (pendata
->PenDataFlags
& PenDataLineStyle
)
2353 if ((status
= GdipSetPenDashStyle(pen
, *(DWORD
*)((BYTE
*)pendata
+ offset
))) != Ok
)
2355 offset
+= sizeof(DWORD
);
2358 if (pendata
->PenDataFlags
& PenDataDashedLineCap
)
2360 FIXME("PenDataDashedLineCap is not supported.\n");
2361 offset
+= sizeof(DWORD
);
2364 if (pendata
->PenDataFlags
& PenDataDashedLineOffset
)
2366 if ((status
= GdipSetPenDashOffset(pen
, *(REAL
*)((BYTE
*)pendata
+ offset
))) != Ok
)
2368 offset
+= sizeof(REAL
);
2371 if (pendata
->PenDataFlags
& PenDataDashedLine
)
2373 EmfPlusDashedLineData
*dashedline
= (EmfPlusDashedLineData
*)((BYTE
*)pendata
+ offset
);
2374 FIXME("PenDataDashedLine is not supported.\n");
2375 offset
+= FIELD_OFFSET(EmfPlusDashedLineData
, data
) + dashedline
->DashedLineDataSize
* sizeof(float);
2378 if (pendata
->PenDataFlags
& PenDataNonCenter
)
2380 FIXME("PenDataNonCenter is not supported.\n");
2381 offset
+= sizeof(DWORD
);
2384 if (pendata
->PenDataFlags
& PenDataCompoundLine
)
2386 EmfPlusCompoundLineData
*compoundline
= (EmfPlusCompoundLineData
*)((BYTE
*)pendata
+ offset
);
2387 FIXME("PenDataCompoundLine is not supported.\n");
2388 offset
+= FIELD_OFFSET(EmfPlusCompoundLineData
, data
) + compoundline
->CompoundLineDataSize
* sizeof(float);
2391 if (pendata
->PenDataFlags
& PenDataCustomStartCap
)
2393 EmfPlusCustomStartCapData
*startcap
= (EmfPlusCustomStartCapData
*)((BYTE
*)pendata
+ offset
);
2394 FIXME("PenDataCustomStartCap is not supported.\n");
2395 offset
+= FIELD_OFFSET(EmfPlusCustomStartCapData
, data
) + startcap
->CustomStartCapSize
;
2398 if (pendata
->PenDataFlags
& PenDataCustomEndCap
)
2400 EmfPlusCustomEndCapData
*endcap
= (EmfPlusCustomEndCapData
*)((BYTE
*)pendata
+ offset
);
2401 FIXME("PenDataCustomEndCap is not supported.\n");
2402 offset
+= FIELD_OFFSET(EmfPlusCustomEndCapData
, data
) + endcap
->CustomEndCapSize
;
2412 case ObjectTypePath
:
2413 status
= metafile_deserialize_path(record_data
, data_size
, (GpPath
**)&object
);
2415 case ObjectTypeRegion
:
2416 status
= metafile_deserialize_region(record_data
, data_size
, (GpRegion
**)&object
);
2418 case ObjectTypeImage
:
2419 status
= metafile_deserialize_image(record_data
, data_size
, (GpImage
**)&object
);
2421 case ObjectTypeFont
:
2423 EmfPlusFont
*data
= (EmfPlusFont
*)record_data
;
2424 GpFontFamily
*family
;
2427 if (data_size
<= FIELD_OFFSET(EmfPlusFont
, FamilyName
))
2428 return InvalidParameter
;
2429 data_size
-= FIELD_OFFSET(EmfPlusFont
, FamilyName
);
2431 if (data_size
< data
->Length
* sizeof(WCHAR
))
2432 return InvalidParameter
;
2434 if (!(familyname
= GdipAlloc((data
->Length
+ 1) * sizeof(*familyname
))))
2437 memcpy(familyname
, data
->FamilyName
, data
->Length
* sizeof(*familyname
));
2438 familyname
[data
->Length
] = 0;
2440 status
= GdipCreateFontFamilyFromName(familyname
, NULL
, &family
);
2441 GdipFree(familyname
);
2443 /* If a font family cannot be created from family name, native
2444 falls back to a sans serif font. */
2446 status
= GdipGetGenericFontFamilySansSerif(&family
);
2450 status
= GdipCreateFont(family
, data
->EmSize
, data
->FontStyleFlags
, data
->SizeUnit
, (GpFont
**)&object
);
2451 GdipDeleteFontFamily(family
);
2454 case ObjectTypeImageAttributes
:
2456 EmfPlusImageAttributes
*data
= (EmfPlusImageAttributes
*)record_data
;
2457 GpImageAttributes
*attributes
= NULL
;
2459 if (data_size
!= sizeof(*data
))
2460 return InvalidParameter
;
2462 if ((status
= GdipCreateImageAttributes(&attributes
)) != Ok
)
2465 status
= GdipSetImageAttributesWrapMode(attributes
, data
->WrapMode
, *(DWORD
*)&data
->ClampColor
,
2466 !!data
->ObjectClamp
);
2468 object
= attributes
;
2470 GdipDisposeImageAttributes(attributes
);
2474 FIXME("not implemented for object type %d.\n", type
);
2475 return NotImplemented
;
2479 metafile_set_object_table_entry(metafile
, id
, type
, object
);
2484 static GpStatus
metafile_set_clip_region(GpMetafile
*metafile
, GpRegion
*region
, CombineMode mode
)
2486 GpMatrix world_to_device
;
2488 get_graphics_transform(metafile
->playback_graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
2490 GdipTransformRegion(region
, &world_to_device
);
2491 GdipCombineRegionRegion(metafile
->clip
, region
, mode
);
2493 return METAFILE_PlaybackUpdateClip(metafile
);
2496 GpStatus WINGDIPAPI
GdipPlayMetafileRecord(GDIPCONST GpMetafile
*metafile
,
2497 EmfPlusRecordType recordType
, UINT flags
, UINT dataSize
, GDIPCONST BYTE
*data
)
2500 GpMetafile
*real_metafile
= (GpMetafile
*)metafile
;
2502 TRACE("(%p,%x,%x,%d,%p)\n", metafile
, recordType
, flags
, dataSize
, data
);
2504 if (!metafile
|| (dataSize
&& !data
) || !metafile
->playback_graphics
)
2505 return InvalidParameter
;
2507 if (recordType
>= 1 && recordType
<= 0x7a)
2509 /* regular EMF record */
2510 if (metafile
->playback_dc
)
2512 ENHMETARECORD
*record
= heap_alloc_zero(dataSize
+ 8);
2516 record
->iType
= recordType
;
2517 record
->nSize
= dataSize
+ 8;
2518 memcpy(record
->dParm
, data
, dataSize
);
2520 if(PlayEnhMetaFileRecord(metafile
->playback_dc
, metafile
->handle_table
,
2521 record
, metafile
->handle_count
) == 0)
2522 ERR("PlayEnhMetaFileRecord failed\n");
2532 EmfPlusRecordHeader
*header
= (EmfPlusRecordHeader
*)(data
)-1;
2534 METAFILE_PlaybackReleaseDC((GpMetafile
*)metafile
);
2538 case EmfPlusRecordTypeHeader
:
2539 case EmfPlusRecordTypeEndOfFile
:
2541 case EmfPlusRecordTypeGetDC
:
2542 METAFILE_PlaybackGetDC((GpMetafile
*)metafile
);
2544 case EmfPlusRecordTypeClear
:
2546 EmfPlusClear
*record
= (EmfPlusClear
*)header
;
2548 if (dataSize
!= sizeof(record
->Color
))
2549 return InvalidParameter
;
2551 return GdipGraphicsClear(metafile
->playback_graphics
, record
->Color
);
2553 case EmfPlusRecordTypeFillRects
:
2555 EmfPlusFillRects
*record
= (EmfPlusFillRects
*)header
;
2556 GpBrush
*brush
, *temp_brush
=NULL
;
2557 GpRectF
*rects
, *temp_rects
=NULL
;
2559 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusFillRects
))
2560 return InvalidParameter
;
2564 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusFillRects
) + sizeof(EmfPlusRect
) * record
->Count
)
2565 return InvalidParameter
;
2569 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusFillRects
) + sizeof(GpRectF
) * record
->Count
)
2570 return InvalidParameter
;
2575 stat
= GdipCreateSolidFill(record
->BrushID
, (GpSolidFill
**)&temp_brush
);
2580 if (record
->BrushID
>= EmfPlusObjectTableSize
||
2581 real_metafile
->objtable
[record
->BrushID
].type
!= ObjectTypeBrush
)
2582 return InvalidParameter
;
2584 brush
= real_metafile
->objtable
[record
->BrushID
].u
.brush
;
2592 EmfPlusRect
*int_rects
= (EmfPlusRect
*)(record
+1);
2595 rects
= temp_rects
= heap_alloc_zero(sizeof(GpRectF
) * record
->Count
);
2598 for (i
=0; i
<record
->Count
; i
++)
2600 rects
[i
].X
= int_rects
[i
].X
;
2601 rects
[i
].Y
= int_rects
[i
].Y
;
2602 rects
[i
].Width
= int_rects
[i
].Width
;
2603 rects
[i
].Height
= int_rects
[i
].Height
;
2610 rects
= (GpRectF
*)(record
+1);
2615 stat
= GdipFillRectangles(metafile
->playback_graphics
, brush
, rects
, record
->Count
);
2618 GdipDeleteBrush(temp_brush
);
2619 heap_free(temp_rects
);
2623 case EmfPlusRecordTypeSetClipRect
:
2625 EmfPlusSetClipRect
*record
= (EmfPlusSetClipRect
*)header
;
2626 CombineMode mode
= (CombineMode
)((flags
>> 8) & 0xf);
2629 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(*record
))
2630 return InvalidParameter
;
2632 stat
= GdipCreateRegionRect(&record
->ClipRect
, ®ion
);
2636 stat
= metafile_set_clip_region(real_metafile
, region
, mode
);
2637 GdipDeleteRegion(region
);
2642 case EmfPlusRecordTypeSetClipRegion
:
2644 CombineMode mode
= (flags
>> 8) & 0xf;
2645 BYTE regionid
= flags
& 0xff;
2649 return InvalidParameter
;
2651 if (regionid
>= EmfPlusObjectTableSize
|| real_metafile
->objtable
[regionid
].type
!= ObjectTypeRegion
)
2652 return InvalidParameter
;
2654 stat
= GdipCloneRegion(real_metafile
->objtable
[regionid
].u
.region
, ®ion
);
2657 stat
= metafile_set_clip_region(real_metafile
, region
, mode
);
2658 GdipDeleteRegion(region
);
2663 case EmfPlusRecordTypeSetClipPath
:
2665 CombineMode mode
= (flags
>> 8) & 0xf;
2666 BYTE pathid
= flags
& 0xff;
2670 return InvalidParameter
;
2672 if (pathid
>= EmfPlusObjectTableSize
|| real_metafile
->objtable
[pathid
].type
!= ObjectTypePath
)
2673 return InvalidParameter
;
2675 stat
= GdipCreateRegionPath(real_metafile
->objtable
[pathid
].u
.path
, ®ion
);
2678 stat
= metafile_set_clip_region(real_metafile
, region
, mode
);
2679 GdipDeleteRegion(region
);
2684 case EmfPlusRecordTypeSetPageTransform
:
2686 EmfPlusSetPageTransform
*record
= (EmfPlusSetPageTransform
*)header
;
2687 GpUnit unit
= (GpUnit
)flags
;
2689 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusSetPageTransform
))
2690 return InvalidParameter
;
2692 real_metafile
->page_unit
= unit
;
2693 real_metafile
->page_scale
= record
->PageScale
;
2695 return METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
2697 case EmfPlusRecordTypeSetWorldTransform
:
2699 EmfPlusSetWorldTransform
*record
= (EmfPlusSetWorldTransform
*)header
;
2701 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusSetWorldTransform
))
2702 return InvalidParameter
;
2704 memcpy(real_metafile
->world_transform
->matrix
, record
->MatrixData
, sizeof(record
->MatrixData
));
2706 return METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
2708 case EmfPlusRecordTypeScaleWorldTransform
:
2710 EmfPlusScaleWorldTransform
*record
= (EmfPlusScaleWorldTransform
*)header
;
2711 MatrixOrder order
= (flags
& 0x2000) ? MatrixOrderAppend
: MatrixOrderPrepend
;
2713 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusScaleWorldTransform
))
2714 return InvalidParameter
;
2716 GdipScaleMatrix(real_metafile
->world_transform
, record
->Sx
, record
->Sy
, order
);
2718 return METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
2720 case EmfPlusRecordTypeMultiplyWorldTransform
:
2722 EmfPlusMultiplyWorldTransform
*record
= (EmfPlusMultiplyWorldTransform
*)header
;
2723 MatrixOrder order
= (flags
& 0x2000) ? MatrixOrderAppend
: MatrixOrderPrepend
;
2726 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusMultiplyWorldTransform
))
2727 return InvalidParameter
;
2729 memcpy(matrix
.matrix
, record
->MatrixData
, sizeof(matrix
.matrix
));
2731 GdipMultiplyMatrix(real_metafile
->world_transform
, &matrix
, order
);
2733 return METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
2735 case EmfPlusRecordTypeRotateWorldTransform
:
2737 EmfPlusRotateWorldTransform
*record
= (EmfPlusRotateWorldTransform
*)header
;
2738 MatrixOrder order
= (flags
& 0x2000) ? MatrixOrderAppend
: MatrixOrderPrepend
;
2740 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusRotateWorldTransform
))
2741 return InvalidParameter
;
2743 GdipRotateMatrix(real_metafile
->world_transform
, record
->Angle
, order
);
2745 return METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
2747 case EmfPlusRecordTypeTranslateWorldTransform
:
2749 EmfPlusTranslateWorldTransform
*record
= (EmfPlusTranslateWorldTransform
*)header
;
2750 MatrixOrder order
= (flags
& 0x2000) ? MatrixOrderAppend
: MatrixOrderPrepend
;
2752 if (dataSize
+ sizeof(EmfPlusRecordHeader
) < sizeof(EmfPlusTranslateWorldTransform
))
2753 return InvalidParameter
;
2755 GdipTranslateMatrix(real_metafile
->world_transform
, record
->dx
, record
->dy
, order
);
2757 return METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
2759 case EmfPlusRecordTypeResetWorldTransform
:
2761 GdipSetMatrixElements(real_metafile
->world_transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2763 return METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
2765 case EmfPlusRecordTypeBeginContainer
:
2767 EmfPlusBeginContainer
*record
= (EmfPlusBeginContainer
*)header
;
2770 REAL scale_x
, scale_y
;
2771 GpRectF scaled_srcrect
;
2774 cont
= heap_alloc_zero(sizeof(*cont
));
2778 stat
= GdipCloneRegion(metafile
->clip
, &cont
->clip
);
2785 stat
= GdipBeginContainer2(metafile
->playback_graphics
, &cont
->state
);
2789 GdipDeleteRegion(cont
->clip
);
2794 cont
->id
= record
->StackIndex
;
2795 cont
->type
= BEGIN_CONTAINER
;
2796 cont
->world_transform
= *metafile
->world_transform
;
2797 cont
->page_unit
= metafile
->page_unit
;
2798 cont
->page_scale
= metafile
->page_scale
;
2799 list_add_head(&real_metafile
->containers
, &cont
->entry
);
2801 unit
= record
->Header
.Flags
& 0xff;
2803 scale_x
= units_to_pixels(1.0, unit
, metafile
->image
.xres
, metafile
->printer_display
);
2804 scale_y
= units_to_pixels(1.0, unit
, metafile
->image
.yres
, metafile
->printer_display
);
2806 scaled_srcrect
.X
= scale_x
* record
->SrcRect
.X
;
2807 scaled_srcrect
.Y
= scale_y
* record
->SrcRect
.Y
;
2808 scaled_srcrect
.Width
= scale_x
* record
->SrcRect
.Width
;
2809 scaled_srcrect
.Height
= scale_y
* record
->SrcRect
.Height
;
2811 transform
.matrix
[0] = record
->DestRect
.Width
/ scaled_srcrect
.Width
;
2812 transform
.matrix
[1] = 0.0;
2813 transform
.matrix
[2] = 0.0;
2814 transform
.matrix
[3] = record
->DestRect
.Height
/ scaled_srcrect
.Height
;
2815 transform
.matrix
[4] = record
->DestRect
.X
- scaled_srcrect
.X
;
2816 transform
.matrix
[5] = record
->DestRect
.Y
- scaled_srcrect
.Y
;
2818 GdipMultiplyMatrix(real_metafile
->world_transform
, &transform
, MatrixOrderPrepend
);
2820 return METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
2822 case EmfPlusRecordTypeBeginContainerNoParams
:
2823 case EmfPlusRecordTypeSave
:
2825 EmfPlusContainerRecord
*record
= (EmfPlusContainerRecord
*)header
;
2828 cont
= heap_alloc_zero(sizeof(*cont
));
2832 stat
= GdipCloneRegion(metafile
->clip
, &cont
->clip
);
2839 if (recordType
== EmfPlusRecordTypeBeginContainerNoParams
)
2840 stat
= GdipBeginContainer2(metafile
->playback_graphics
, &cont
->state
);
2842 stat
= GdipSaveGraphics(metafile
->playback_graphics
, &cont
->state
);
2846 GdipDeleteRegion(cont
->clip
);
2851 cont
->id
= record
->StackIndex
;
2852 if (recordType
== EmfPlusRecordTypeBeginContainerNoParams
)
2853 cont
->type
= BEGIN_CONTAINER
;
2855 cont
->type
= SAVE_GRAPHICS
;
2856 cont
->world_transform
= *metafile
->world_transform
;
2857 cont
->page_unit
= metafile
->page_unit
;
2858 cont
->page_scale
= metafile
->page_scale
;
2859 list_add_head(&real_metafile
->containers
, &cont
->entry
);
2863 case EmfPlusRecordTypeEndContainer
:
2864 case EmfPlusRecordTypeRestore
:
2866 EmfPlusContainerRecord
*record
= (EmfPlusContainerRecord
*)header
;
2868 enum container_type type
;
2871 if (recordType
== EmfPlusRecordTypeEndContainer
)
2872 type
= BEGIN_CONTAINER
;
2874 type
= SAVE_GRAPHICS
;
2876 LIST_FOR_EACH_ENTRY(cont
, &real_metafile
->containers
, container
, entry
)
2878 if (cont
->id
== record
->StackIndex
&& cont
->type
== type
)
2889 /* pop any newer items on the stack */
2890 while ((cont2
= LIST_ENTRY(list_head(&real_metafile
->containers
), container
, entry
)) != cont
)
2892 list_remove(&cont2
->entry
);
2893 GdipDeleteRegion(cont2
->clip
);
2897 if (type
== BEGIN_CONTAINER
)
2898 GdipEndContainer(real_metafile
->playback_graphics
, cont
->state
);
2900 GdipRestoreGraphics(real_metafile
->playback_graphics
, cont
->state
);
2902 *real_metafile
->world_transform
= cont
->world_transform
;
2903 real_metafile
->page_unit
= cont
->page_unit
;
2904 real_metafile
->page_scale
= cont
->page_scale
;
2905 GdipCombineRegionRegion(real_metafile
->clip
, cont
->clip
, CombineModeReplace
);
2907 list_remove(&cont
->entry
);
2908 GdipDeleteRegion(cont
->clip
);
2914 case EmfPlusRecordTypeSetPixelOffsetMode
:
2916 return GdipSetPixelOffsetMode(real_metafile
->playback_graphics
, flags
& 0xff);
2918 case EmfPlusRecordTypeSetCompositingQuality
:
2920 return GdipSetCompositingQuality(real_metafile
->playback_graphics
, flags
& 0xff);
2922 case EmfPlusRecordTypeSetInterpolationMode
:
2924 return GdipSetInterpolationMode(real_metafile
->playback_graphics
, flags
& 0xff);
2926 case EmfPlusRecordTypeSetTextRenderingHint
:
2928 return GdipSetTextRenderingHint(real_metafile
->playback_graphics
, flags
& 0xff);
2930 case EmfPlusRecordTypeSetAntiAliasMode
:
2932 return GdipSetSmoothingMode(real_metafile
->playback_graphics
, (flags
>> 1) & 0xff);
2934 case EmfPlusRecordTypeSetCompositingMode
:
2936 return GdipSetCompositingMode(real_metafile
->playback_graphics
, flags
& 0xff);
2938 case EmfPlusRecordTypeObject
:
2940 return METAFILE_PlaybackObject(real_metafile
, flags
, dataSize
, data
);
2942 case EmfPlusRecordTypeDrawImage
:
2944 EmfPlusDrawImage
*draw
= (EmfPlusDrawImage
*)header
;
2945 BYTE image
= flags
& 0xff;
2948 if (image
>= EmfPlusObjectTableSize
|| real_metafile
->objtable
[image
].type
!= ObjectTypeImage
)
2949 return InvalidParameter
;
2951 if (dataSize
!= FIELD_OFFSET(EmfPlusDrawImage
, RectData
) - sizeof(EmfPlusRecordHeader
) +
2952 (flags
& 0x4000 ? sizeof(EmfPlusRect
) : sizeof(EmfPlusRectF
)))
2953 return InvalidParameter
;
2955 if (draw
->ImageAttributesID
>= EmfPlusObjectTableSize
||
2956 real_metafile
->objtable
[draw
->ImageAttributesID
].type
!= ObjectTypeImageAttributes
)
2957 return InvalidParameter
;
2959 if (flags
& 0x4000) /* C */
2961 points
[0].X
= draw
->RectData
.rect
.X
;
2962 points
[0].Y
= draw
->RectData
.rect
.Y
;
2963 points
[1].X
= points
[0].X
+ draw
->RectData
.rect
.Width
;
2964 points
[1].Y
= points
[0].Y
;
2965 points
[2].X
= points
[1].X
;
2966 points
[2].Y
= points
[1].Y
+ draw
->RectData
.rect
.Height
;
2970 points
[0].X
= draw
->RectData
.rectF
.X
;
2971 points
[0].Y
= draw
->RectData
.rectF
.Y
;
2972 points
[1].X
= points
[0].X
+ draw
->RectData
.rectF
.Width
;
2973 points
[1].Y
= points
[0].Y
;
2974 points
[2].X
= points
[1].X
;
2975 points
[2].Y
= points
[1].Y
+ draw
->RectData
.rectF
.Height
;
2978 return GdipDrawImagePointsRect(real_metafile
->playback_graphics
, real_metafile
->objtable
[image
].u
.image
,
2979 points
, 3, draw
->SrcRect
.X
, draw
->SrcRect
.Y
, draw
->SrcRect
.Width
, draw
->SrcRect
.Height
, draw
->SrcUnit
,
2980 real_metafile
->objtable
[draw
->ImageAttributesID
].u
.image_attributes
, NULL
, NULL
);
2982 case EmfPlusRecordTypeDrawImagePoints
:
2984 EmfPlusDrawImagePoints
*draw
= (EmfPlusDrawImagePoints
*)header
;
2985 static const UINT fixed_part_size
= FIELD_OFFSET(EmfPlusDrawImagePoints
, PointData
) -
2986 FIELD_OFFSET(EmfPlusDrawImagePoints
, ImageAttributesID
);
2987 BYTE image
= flags
& 0xff;
2992 if (image
>= EmfPlusObjectTableSize
|| real_metafile
->objtable
[image
].type
!= ObjectTypeImage
)
2993 return InvalidParameter
;
2995 if (dataSize
<= fixed_part_size
)
2996 return InvalidParameter
;
2997 dataSize
-= fixed_part_size
;
2999 if (draw
->ImageAttributesID
>= EmfPlusObjectTableSize
||
3000 real_metafile
->objtable
[draw
->ImageAttributesID
].type
!= ObjectTypeImageAttributes
)
3001 return InvalidParameter
;
3003 if (draw
->count
!= 3)
3004 return InvalidParameter
;
3006 if ((flags
>> 13) & 1) /* E */
3007 FIXME("image effects are not supported.\n");
3009 if ((flags
>> 11) & 1) /* P */
3010 size
= sizeof(EmfPlusPointR7
) * draw
->count
;
3011 else if ((flags
>> 14) & 1) /* C */
3012 size
= sizeof(EmfPlusPoint
) * draw
->count
;
3014 size
= sizeof(EmfPlusPointF
) * draw
->count
;
3016 if (dataSize
!= size
)
3017 return InvalidParameter
;
3019 if ((flags
>> 11) & 1) /* P */
3021 points
[0].X
= draw
->PointData
.pointsR
[0].X
;
3022 points
[0].Y
= draw
->PointData
.pointsR
[0].Y
;
3023 for (i
= 1; i
< 3; i
++)
3025 points
[i
].X
= points
[i
-1].X
+ draw
->PointData
.pointsR
[i
].X
;
3026 points
[i
].Y
= points
[i
-1].Y
+ draw
->PointData
.pointsR
[i
].Y
;
3029 else if ((flags
>> 14) & 1) /* C */
3031 for (i
= 0; i
< 3; i
++)
3033 points
[i
].X
= draw
->PointData
.points
[i
].X
;
3034 points
[i
].Y
= draw
->PointData
.points
[i
].Y
;
3038 memcpy(points
, draw
->PointData
.pointsF
, sizeof(points
));
3040 return GdipDrawImagePointsRect(real_metafile
->playback_graphics
, real_metafile
->objtable
[image
].u
.image
,
3041 points
, 3, draw
->SrcRect
.X
, draw
->SrcRect
.Y
, draw
->SrcRect
.Width
, draw
->SrcRect
.Height
, draw
->SrcUnit
,
3042 real_metafile
->objtable
[draw
->ImageAttributesID
].u
.image_attributes
, NULL
, NULL
);
3044 case EmfPlusRecordTypeFillPath
:
3046 EmfPlusFillPath
*fill
= (EmfPlusFillPath
*)header
;
3047 GpSolidFill
*solidfill
= NULL
;
3048 BYTE path
= flags
& 0xff;
3051 if (path
>= EmfPlusObjectTableSize
|| real_metafile
->objtable
[path
].type
!= ObjectTypePath
)
3052 return InvalidParameter
;
3054 if (dataSize
!= sizeof(fill
->data
.BrushId
))
3055 return InvalidParameter
;
3059 stat
= GdipCreateSolidFill(fill
->data
.Color
, &solidfill
);
3062 brush
= (GpBrush
*)solidfill
;
3066 if (fill
->data
.BrushId
>= EmfPlusObjectTableSize
||
3067 real_metafile
->objtable
[fill
->data
.BrushId
].type
!= ObjectTypeBrush
)
3068 return InvalidParameter
;
3070 brush
= real_metafile
->objtable
[fill
->data
.BrushId
].u
.brush
;
3073 stat
= GdipFillPath(real_metafile
->playback_graphics
, brush
, real_metafile
->objtable
[path
].u
.path
);
3074 GdipDeleteBrush((GpBrush
*)solidfill
);
3077 case EmfPlusRecordTypeFillClosedCurve
:
3079 static const UINT fixed_part_size
= FIELD_OFFSET(EmfPlusFillClosedCurve
, PointData
) -
3080 sizeof(EmfPlusRecordHeader
);
3081 EmfPlusFillClosedCurve
*fill
= (EmfPlusFillClosedCurve
*)header
;
3082 GpSolidFill
*solidfill
= NULL
;
3087 if (dataSize
<= fixed_part_size
)
3088 return InvalidParameter
;
3090 if (fill
->Count
== 0)
3091 return InvalidParameter
;
3093 if (flags
& 0x800) /* P */
3094 size
= (fixed_part_size
+ sizeof(EmfPlusPointR7
) * fill
->Count
+ 3) & ~3;
3095 else if (flags
& 0x4000) /* C */
3096 size
= fixed_part_size
+ sizeof(EmfPlusPoint
) * fill
->Count
;
3098 size
= fixed_part_size
+ sizeof(EmfPlusPointF
) * fill
->Count
;
3100 if (dataSize
!= size
)
3101 return InvalidParameter
;
3103 mode
= flags
& 0x200 ? FillModeWinding
: FillModeAlternate
; /* W */
3105 if (flags
& 0x8000) /* S */
3107 stat
= GdipCreateSolidFill(fill
->BrushId
, &solidfill
);
3110 brush
= (GpBrush
*)solidfill
;
3114 if (fill
->BrushId
>= EmfPlusObjectTableSize
||
3115 real_metafile
->objtable
[fill
->BrushId
].type
!= ObjectTypeBrush
)
3116 return InvalidParameter
;
3118 brush
= real_metafile
->objtable
[fill
->BrushId
].u
.brush
;
3121 if (flags
& (0x800 | 0x4000))
3123 GpPointF
*points
= GdipAlloc(fill
->Count
* sizeof(*points
));
3126 if (flags
& 0x800) /* P */
3128 for (i
= 1; i
< fill
->Count
; i
++)
3130 points
[i
].X
= points
[i
- 1].X
+ fill
->PointData
.pointsR
[i
].X
;
3131 points
[i
].Y
= points
[i
- 1].Y
+ fill
->PointData
.pointsR
[i
].Y
;
3136 for (i
= 0; i
< fill
->Count
; i
++)
3138 points
[i
].X
= fill
->PointData
.points
[i
].X
;
3139 points
[i
].Y
= fill
->PointData
.points
[i
].Y
;
3143 stat
= GdipFillClosedCurve2(real_metafile
->playback_graphics
, brush
,
3144 points
, fill
->Count
, fill
->Tension
, mode
);
3151 stat
= GdipFillClosedCurve2(real_metafile
->playback_graphics
, brush
,
3152 (const GpPointF
*)fill
->PointData
.pointsF
, fill
->Count
, fill
->Tension
, mode
);
3154 GdipDeleteBrush((GpBrush
*)solidfill
);
3157 case EmfPlusRecordTypeFillEllipse
:
3159 EmfPlusFillEllipse
*fill
= (EmfPlusFillEllipse
*)header
;
3160 GpSolidFill
*solidfill
= NULL
;
3163 if (dataSize
<= FIELD_OFFSET(EmfPlusFillEllipse
, RectData
) - sizeof(EmfPlusRecordHeader
))
3164 return InvalidParameter
;
3165 dataSize
-= FIELD_OFFSET(EmfPlusFillEllipse
, RectData
) - sizeof(EmfPlusRecordHeader
);
3167 if (dataSize
!= (flags
& 0x4000 ? sizeof(EmfPlusRect
) : sizeof(EmfPlusRectF
)))
3168 return InvalidParameter
;
3172 stat
= GdipCreateSolidFill(fill
->BrushId
, &solidfill
);
3175 brush
= (GpBrush
*)solidfill
;
3179 if (fill
->BrushId
>= EmfPlusObjectTableSize
||
3180 real_metafile
->objtable
[fill
->BrushId
].type
!= ObjectTypeBrush
)
3181 return InvalidParameter
;
3183 brush
= real_metafile
->objtable
[fill
->BrushId
].u
.brush
;
3187 stat
= GdipFillEllipseI(real_metafile
->playback_graphics
, brush
, fill
->RectData
.rect
.X
,
3188 fill
->RectData
.rect
.Y
, fill
->RectData
.rect
.Width
, fill
->RectData
.rect
.Height
);
3190 stat
= GdipFillEllipse(real_metafile
->playback_graphics
, brush
, fill
->RectData
.rectF
.X
,
3191 fill
->RectData
.rectF
.Y
, fill
->RectData
.rectF
.Width
, fill
->RectData
.rectF
.Height
);
3193 GdipDeleteBrush((GpBrush
*)solidfill
);
3196 case EmfPlusRecordTypeFillPie
:
3198 EmfPlusFillPie
*fill
= (EmfPlusFillPie
*)header
;
3199 GpSolidFill
*solidfill
= NULL
;
3202 if (dataSize
<= FIELD_OFFSET(EmfPlusFillPie
, RectData
) - sizeof(EmfPlusRecordHeader
))
3203 return InvalidParameter
;
3204 dataSize
-= FIELD_OFFSET(EmfPlusFillPie
, RectData
) - sizeof(EmfPlusRecordHeader
);
3206 if (dataSize
!= (flags
& 0x4000 ? sizeof(EmfPlusRect
) : sizeof(EmfPlusRectF
)))
3207 return InvalidParameter
;
3209 if (flags
& 0x8000) /* S */
3211 stat
= GdipCreateSolidFill(fill
->BrushId
, &solidfill
);
3214 brush
= (GpBrush
*)solidfill
;
3218 if (fill
->BrushId
>= EmfPlusObjectTableSize
||
3219 real_metafile
->objtable
[fill
->BrushId
].type
!= ObjectTypeBrush
)
3220 return InvalidParameter
;
3222 brush
= real_metafile
->objtable
[fill
->BrushId
].u
.brush
;
3225 if (flags
& 0x4000) /* C */
3226 stat
= GdipFillPieI(real_metafile
->playback_graphics
, brush
, fill
->RectData
.rect
.X
,
3227 fill
->RectData
.rect
.Y
, fill
->RectData
.rect
.Width
, fill
->RectData
.rect
.Height
,
3228 fill
->StartAngle
, fill
->SweepAngle
);
3230 stat
= GdipFillPie(real_metafile
->playback_graphics
, brush
, fill
->RectData
.rectF
.X
,
3231 fill
->RectData
.rectF
.Y
, fill
->RectData
.rectF
.Width
, fill
->RectData
.rectF
.Height
,
3232 fill
->StartAngle
, fill
->SweepAngle
);
3234 GdipDeleteBrush((GpBrush
*)solidfill
);
3237 case EmfPlusRecordTypeDrawPath
:
3239 EmfPlusDrawPath
*draw
= (EmfPlusDrawPath
*)header
;
3240 BYTE path
= flags
& 0xff;
3242 if (dataSize
!= sizeof(draw
->PenId
))
3243 return InvalidParameter
;
3245 if (path
>= EmfPlusObjectTableSize
|| draw
->PenId
>= EmfPlusObjectTableSize
)
3246 return InvalidParameter
;
3248 if (real_metafile
->objtable
[path
].type
!= ObjectTypePath
||
3249 real_metafile
->objtable
[draw
->PenId
].type
!= ObjectTypePen
)
3250 return InvalidParameter
;
3252 return GdipDrawPath(real_metafile
->playback_graphics
, real_metafile
->objtable
[draw
->PenId
].u
.pen
,
3253 real_metafile
->objtable
[path
].u
.path
);
3255 case EmfPlusRecordTypeDrawArc
:
3257 EmfPlusDrawArc
*draw
= (EmfPlusDrawArc
*)header
;
3258 BYTE pen
= flags
& 0xff;
3260 if (pen
>= EmfPlusObjectTableSize
|| real_metafile
->objtable
[pen
].type
!= ObjectTypePen
)
3261 return InvalidParameter
;
3263 if (dataSize
!= FIELD_OFFSET(EmfPlusDrawArc
, RectData
) - sizeof(EmfPlusRecordHeader
) +
3264 (flags
& 0x4000 ? sizeof(EmfPlusRect
) : sizeof(EmfPlusRectF
)))
3265 return InvalidParameter
;
3267 if (flags
& 0x4000) /* C */
3268 return GdipDrawArcI(real_metafile
->playback_graphics
, real_metafile
->objtable
[pen
].u
.pen
,
3269 draw
->RectData
.rect
.X
, draw
->RectData
.rect
.Y
, draw
->RectData
.rect
.Width
,
3270 draw
->RectData
.rect
.Height
, draw
->StartAngle
, draw
->SweepAngle
);
3272 return GdipDrawArc(real_metafile
->playback_graphics
, real_metafile
->objtable
[pen
].u
.pen
,
3273 draw
->RectData
.rectF
.X
, draw
->RectData
.rectF
.Y
, draw
->RectData
.rectF
.Width
,
3274 draw
->RectData
.rectF
.Height
, draw
->StartAngle
, draw
->SweepAngle
);
3276 case EmfPlusRecordTypeDrawEllipse
:
3278 EmfPlusDrawEllipse
*draw
= (EmfPlusDrawEllipse
*)header
;
3279 BYTE pen
= flags
& 0xff;
3281 if (pen
>= EmfPlusObjectTableSize
|| real_metafile
->objtable
[pen
].type
!= ObjectTypePen
)
3282 return InvalidParameter
;
3284 if (dataSize
!= (flags
& 0x4000 ? sizeof(EmfPlusRect
) : sizeof(EmfPlusRectF
)))
3285 return InvalidParameter
;
3287 if (flags
& 0x4000) /* C */
3288 return GdipDrawEllipseI(real_metafile
->playback_graphics
, real_metafile
->objtable
[pen
].u
.pen
,
3289 draw
->RectData
.rect
.X
, draw
->RectData
.rect
.Y
, draw
->RectData
.rect
.Width
,
3290 draw
->RectData
.rect
.Height
);
3292 return GdipDrawEllipse(real_metafile
->playback_graphics
, real_metafile
->objtable
[pen
].u
.pen
,
3293 draw
->RectData
.rectF
.X
, draw
->RectData
.rectF
.Y
, draw
->RectData
.rectF
.Width
,
3294 draw
->RectData
.rectF
.Height
);
3296 case EmfPlusRecordTypeDrawPie
:
3298 EmfPlusDrawPie
*draw
= (EmfPlusDrawPie
*)header
;
3299 BYTE pen
= flags
& 0xff;
3301 if (pen
>= EmfPlusObjectTableSize
|| real_metafile
->objtable
[pen
].type
!= ObjectTypePen
)
3302 return InvalidParameter
;
3304 if (dataSize
!= FIELD_OFFSET(EmfPlusDrawPie
, RectData
) - sizeof(EmfPlusRecordHeader
) +
3305 (flags
& 0x4000 ? sizeof(EmfPlusRect
) : sizeof(EmfPlusRectF
)))
3306 return InvalidParameter
;
3308 if (flags
& 0x4000) /* C */
3309 return GdipDrawPieI(real_metafile
->playback_graphics
, real_metafile
->objtable
[pen
].u
.pen
,
3310 draw
->RectData
.rect
.X
, draw
->RectData
.rect
.Y
, draw
->RectData
.rect
.Width
,
3311 draw
->RectData
.rect
.Height
, draw
->StartAngle
, draw
->SweepAngle
);
3313 return GdipDrawPie(real_metafile
->playback_graphics
, real_metafile
->objtable
[pen
].u
.pen
,
3314 draw
->RectData
.rectF
.X
, draw
->RectData
.rectF
.Y
, draw
->RectData
.rectF
.Width
,
3315 draw
->RectData
.rectF
.Height
, draw
->StartAngle
, draw
->SweepAngle
);
3317 case EmfPlusRecordTypeDrawRects
:
3319 EmfPlusDrawRects
*draw
= (EmfPlusDrawRects
*)header
;
3320 BYTE pen
= flags
& 0xff;
3321 GpRectF
*rects
= NULL
;
3323 if (pen
>= EmfPlusObjectTableSize
|| real_metafile
->objtable
[pen
].type
!= ObjectTypePen
)
3324 return InvalidParameter
;
3326 if (dataSize
<= FIELD_OFFSET(EmfPlusDrawRects
, RectData
) - sizeof(EmfPlusRecordHeader
))
3327 return InvalidParameter
;
3328 dataSize
-= FIELD_OFFSET(EmfPlusDrawRects
, RectData
) - sizeof(EmfPlusRecordHeader
);
3330 if (dataSize
!= draw
->Count
* (flags
& 0x4000 ? sizeof(EmfPlusRect
) : sizeof(EmfPlusRectF
)))
3331 return InvalidParameter
;
3337 rects
= GdipAlloc(draw
->Count
* sizeof(*rects
));
3341 for (i
= 0; i
< draw
->Count
; i
++)
3343 rects
[i
].X
= draw
->RectData
.rect
[i
].X
;
3344 rects
[i
].Y
= draw
->RectData
.rect
[i
].Y
;
3345 rects
[i
].Width
= draw
->RectData
.rect
[i
].Width
;
3346 rects
[i
].Height
= draw
->RectData
.rect
[i
].Height
;
3350 stat
= GdipDrawRectangles(real_metafile
->playback_graphics
, real_metafile
->objtable
[pen
].u
.pen
,
3351 rects
? rects
: (GpRectF
*)draw
->RectData
.rectF
, draw
->Count
);
3355 case EmfPlusRecordTypeDrawDriverString
:
3358 DWORD expected_size
;
3361 GpSolidFill
*solidfill
= NULL
;
3362 void* alignedmem
= NULL
;
3363 GpMatrix
*matrix
= NULL
;
3364 BYTE font
= flags
& 0xff;
3365 EmfPlusDrawDriverString
*draw
= (EmfPlusDrawDriverString
*)header
;
3367 if (font
>= EmfPlusObjectTableSize
||
3368 real_metafile
->objtable
[font
].type
!= ObjectTypeFont
)
3369 return InvalidParameter
;
3371 expected_size
= FIELD_OFFSET(EmfPlusDrawDriverString
, VariableData
) -
3372 sizeof(EmfPlusRecordHeader
);
3373 if (dataSize
< expected_size
|| draw
->GlyphCount
<= 0)
3374 return InvalidParameter
;
3376 expected_size
+= draw
->GlyphCount
* (sizeof(*text
) + sizeof(*positions
));
3377 if (draw
->MatrixPresent
)
3378 expected_size
+= sizeof(*matrix
);
3380 /* Pad expected size to DWORD alignment. */
3381 expected_size
= (expected_size
+ 3) & ~3;
3383 if (dataSize
!= expected_size
)
3384 return InvalidParameter
;
3388 stat
= GdipCreateSolidFill(draw
->brush
.Color
, &solidfill
);
3391 return InvalidParameter
;
3393 brush
= (GpBrush
*)solidfill
;
3397 if (draw
->brush
.BrushId
>= EmfPlusObjectTableSize
||
3398 real_metafile
->objtable
[draw
->brush
.BrushId
].type
!= ObjectTypeBrush
)
3399 return InvalidParameter
;
3401 brush
= real_metafile
->objtable
[draw
->brush
.BrushId
].u
.brush
;
3404 text
= (UINT16
*)&draw
->VariableData
[0];
3406 /* If GlyphCount is odd, all subsequent fields will be 2-byte
3407 aligned rather than 4-byte aligned, which may lead to access
3408 issues. Handle this case by making our own copy of positions. */
3409 if (draw
->GlyphCount
% 2)
3411 SIZE_T alloc_size
= draw
->GlyphCount
* sizeof(*positions
);
3413 if (draw
->MatrixPresent
)
3414 alloc_size
+= sizeof(*matrix
);
3416 positions
= alignedmem
= heap_alloc(alloc_size
);
3419 GdipDeleteBrush((GpBrush
*)solidfill
);
3423 memcpy(positions
, &text
[draw
->GlyphCount
], alloc_size
);
3426 positions
= (PointF
*)&text
[draw
->GlyphCount
];
3428 if (draw
->MatrixPresent
)
3429 matrix
= (GpMatrix
*)&positions
[draw
->GlyphCount
];
3431 stat
= GdipDrawDriverString(real_metafile
->playback_graphics
, text
, draw
->GlyphCount
,
3432 real_metafile
->objtable
[font
].u
.font
, brush
, positions
,
3433 draw
->DriverStringOptionsFlags
, matrix
);
3435 GdipDeleteBrush((GpBrush
*)solidfill
);
3436 heap_free(alignedmem
);
3440 case EmfPlusRecordTypeFillRegion
:
3442 EmfPlusFillRegion
* const fill
= (EmfPlusFillRegion
*)header
;
3443 GpSolidFill
*solidfill
= NULL
;
3445 BYTE region
= flags
& 0xff;
3447 if (dataSize
!= sizeof(EmfPlusFillRegion
) - sizeof(EmfPlusRecordHeader
))
3448 return InvalidParameter
;
3450 if (region
>= EmfPlusObjectTableSize
||
3451 real_metafile
->objtable
[region
].type
!= ObjectTypeRegion
)
3452 return InvalidParameter
;
3456 stat
= GdipCreateSolidFill(fill
->data
.Color
, &solidfill
);
3459 brush
= (GpBrush
*)solidfill
;
3463 if (fill
->data
.BrushId
>= EmfPlusObjectTableSize
||
3464 real_metafile
->objtable
[fill
->data
.BrushId
].type
!= ObjectTypeBrush
)
3465 return InvalidParameter
;
3467 brush
= real_metafile
->objtable
[fill
->data
.BrushId
].u
.brush
;
3470 stat
= GdipFillRegion(real_metafile
->playback_graphics
, brush
,
3471 real_metafile
->objtable
[region
].u
.region
);
3472 GdipDeleteBrush((GpBrush
*)solidfill
);
3477 FIXME("Not implemented for record type %x\n", recordType
);
3478 return NotImplemented
;
3485 struct enum_metafile_data
3487 EnumerateMetafileProc callback
;
3488 void *callback_data
;
3489 GpMetafile
*metafile
;
3492 static int CALLBACK
enum_metafile_proc(HDC hDC
, HANDLETABLE
*lpHTable
, const ENHMETARECORD
*lpEMFR
,
3493 int nObj
, LPARAM lpData
)
3496 struct enum_metafile_data
*data
= (struct enum_metafile_data
*)lpData
;
3499 data
->metafile
->handle_table
= lpHTable
;
3500 data
->metafile
->handle_count
= nObj
;
3502 /* First check for an EMF+ record. */
3503 if (lpEMFR
->iType
== EMR_GDICOMMENT
)
3505 const EMRGDICOMMENT
*comment
= (const EMRGDICOMMENT
*)lpEMFR
;
3507 if (comment
->cbData
>= 4 && memcmp(comment
->Data
, "EMF+", 4) == 0)
3511 while (offset
+ sizeof(EmfPlusRecordHeader
) <= comment
->cbData
)
3513 const EmfPlusRecordHeader
*record
= (const EmfPlusRecordHeader
*)&comment
->Data
[offset
];
3515 if (record
->DataSize
)
3516 pStr
= (const BYTE
*)(record
+1);
3520 ret
= data
->callback(record
->Type
, record
->Flags
, record
->DataSize
,
3521 pStr
, data
->callback_data
);
3526 offset
+= record
->Size
;
3533 if (lpEMFR
->nSize
!= 8)
3534 pStr
= (const BYTE
*)lpEMFR
->dParm
;
3538 return data
->callback(lpEMFR
->iType
, 0, lpEMFR
->nSize
-8,
3539 pStr
, data
->callback_data
);
3542 GpStatus WINGDIPAPI
GdipEnumerateMetafileSrcRectDestPoints(GpGraphics
*graphics
,
3543 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpPointF
*destPoints
, INT count
,
3544 GDIPCONST GpRectF
*srcRect
, Unit srcUnit
, EnumerateMetafileProc callback
,
3545 VOID
*callbackData
, GDIPCONST GpImageAttributes
*imageAttributes
)
3547 struct enum_metafile_data data
;
3549 GpMetafile
*real_metafile
= (GpMetafile
*)metafile
; /* whoever made this const was joking */
3550 GraphicsContainer state
;
3554 TRACE("(%p,%p,%p,%i,%p,%i,%p,%p,%p)\n", graphics
, metafile
,
3555 destPoints
, count
, srcRect
, srcUnit
, callback
, callbackData
,
3558 if (!graphics
|| !metafile
|| !destPoints
|| count
!= 3 || !srcRect
)
3559 return InvalidParameter
;
3561 if (!metafile
->hemf
)
3562 return InvalidParameter
;
3564 if (metafile
->playback_graphics
)
3567 TRACE("%s %i -> %s %s %s\n", debugstr_rectf(srcRect
), srcUnit
,
3568 debugstr_pointf(&destPoints
[0]), debugstr_pointf(&destPoints
[1]),
3569 debugstr_pointf(&destPoints
[2]));
3571 data
.callback
= callback
;
3572 data
.callback_data
= callbackData
;
3573 data
.metafile
= real_metafile
;
3575 real_metafile
->playback_graphics
= graphics
;
3576 real_metafile
->playback_dc
= NULL
;
3577 real_metafile
->src_rect
= *srcRect
;
3579 memcpy(real_metafile
->playback_points
, destPoints
, sizeof(PointF
) * 3);
3580 stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, real_metafile
->playback_points
, 3);
3583 stat
= GdipBeginContainer2(graphics
, &state
);
3587 stat
= GdipSetPageScale(graphics
, 1.0);
3590 stat
= GdipSetPageUnit(graphics
, UnitPixel
);
3593 stat
= GdipResetWorldTransform(graphics
);
3596 stat
= GdipCreateRegion(&real_metafile
->base_clip
);
3599 stat
= GdipGetClip(graphics
, real_metafile
->base_clip
);
3602 stat
= GdipCreateRegion(&real_metafile
->clip
);
3605 stat
= GdipCreatePath(FillModeAlternate
, &dst_path
);
3609 GpPointF clip_points
[4];
3611 clip_points
[0] = real_metafile
->playback_points
[0];
3612 clip_points
[1] = real_metafile
->playback_points
[1];
3613 clip_points
[2].X
= real_metafile
->playback_points
[1].X
+ real_metafile
->playback_points
[2].X
3614 - real_metafile
->playback_points
[0].X
;
3615 clip_points
[2].Y
= real_metafile
->playback_points
[1].Y
+ real_metafile
->playback_points
[2].Y
3616 - real_metafile
->playback_points
[0].Y
;
3617 clip_points
[3] = real_metafile
->playback_points
[2];
3619 stat
= GdipAddPathPolygon(dst_path
, clip_points
, 4);
3622 stat
= GdipCombineRegionPath(real_metafile
->base_clip
, dst_path
, CombineModeIntersect
);
3624 GdipDeletePath(dst_path
);
3628 stat
= GdipCreateMatrix(&real_metafile
->world_transform
);
3632 real_metafile
->page_unit
= UnitDisplay
;
3633 real_metafile
->page_scale
= 1.0;
3634 stat
= METAFILE_PlaybackUpdateWorldTransform(real_metafile
);
3639 stat
= METAFILE_PlaybackUpdateClip(real_metafile
);
3644 stat
= METAFILE_PlaybackGetDC(real_metafile
);
3646 dst_bounds
.left
= real_metafile
->playback_points
[0].X
;
3647 dst_bounds
.right
= real_metafile
->playback_points
[1].X
;
3648 dst_bounds
.top
= real_metafile
->playback_points
[0].Y
;
3649 dst_bounds
.bottom
= real_metafile
->playback_points
[2].Y
;
3653 EnumEnhMetaFile(real_metafile
->playback_dc
, metafile
->hemf
, enum_metafile_proc
,
3654 &data
, &dst_bounds
);
3656 METAFILE_PlaybackReleaseDC(real_metafile
);
3658 GdipDeleteMatrix(real_metafile
->world_transform
);
3659 real_metafile
->world_transform
= NULL
;
3661 GdipDeleteRegion(real_metafile
->base_clip
);
3662 real_metafile
->base_clip
= NULL
;
3664 GdipDeleteRegion(real_metafile
->clip
);
3665 real_metafile
->clip
= NULL
;
3667 while (list_head(&real_metafile
->containers
))
3669 container
* cont
= LIST_ENTRY(list_head(&real_metafile
->containers
), container
, entry
);
3670 list_remove(&cont
->entry
);
3671 GdipDeleteRegion(cont
->clip
);
3675 GdipEndContainer(graphics
, state
);
3678 real_metafile
->playback_graphics
= NULL
;
3683 GpStatus WINGDIPAPI
GdipEnumerateMetafileSrcRectDestRect( GpGraphics
*graphics
,
3684 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpRectF
*dest
,
3685 GDIPCONST GpRectF
*src
, Unit srcUnit
, EnumerateMetafileProc callback
,
3686 VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
3690 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
3692 points
[0].X
= points
[2].X
= dest
->X
;
3693 points
[0].Y
= points
[1].Y
= dest
->Y
;
3694 points
[1].X
= dest
->X
+ dest
->Width
;
3695 points
[2].Y
= dest
->Y
+ dest
->Height
;
3697 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, metafile
, points
, 3,
3698 src
, srcUnit
, callback
, cb_data
, attrs
);
3701 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestRect(GpGraphics
*graphics
,
3702 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpRectF
*dest
,
3703 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
3707 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
3709 points
[0].X
= points
[2].X
= dest
->X
;
3710 points
[0].Y
= points
[1].Y
= dest
->Y
;
3711 points
[1].X
= dest
->X
+ dest
->Width
;
3712 points
[2].Y
= dest
->Y
+ dest
->Height
;
3714 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, metafile
, points
, 3,
3715 &metafile
->bounds
, metafile
->unit
, callback
, cb_data
, attrs
);
3718 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestRectI(GpGraphics
*graphics
,
3719 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpRect
*dest
,
3720 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
3724 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
3728 destf
.Width
= dest
->Width
;
3729 destf
.Height
= dest
->Height
;
3731 return GdipEnumerateMetafileDestRect(graphics
, metafile
, &destf
, callback
, cb_data
, attrs
);
3734 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestPoint(GpGraphics
*graphics
,
3735 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpPointF
*dest
,
3736 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
3740 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
3744 destf
.Width
= units_to_pixels(metafile
->bounds
.Width
, metafile
->unit
,
3745 metafile
->image
.xres
, metafile
->printer_display
);
3746 destf
.Height
= units_to_pixels(metafile
->bounds
.Height
, metafile
->unit
,
3747 metafile
->image
.yres
, metafile
->printer_display
);
3749 return GdipEnumerateMetafileDestRect(graphics
, metafile
, &destf
, callback
, cb_data
, attrs
);
3752 GpStatus WINGDIPAPI
GdipEnumerateMetafileDestPointI(GpGraphics
*graphics
,
3753 GDIPCONST GpMetafile
*metafile
, GDIPCONST GpPoint
*dest
,
3754 EnumerateMetafileProc callback
, VOID
*cb_data
, GDIPCONST GpImageAttributes
*attrs
)
3758 if (!graphics
|| !metafile
|| !dest
) return InvalidParameter
;
3763 return GdipEnumerateMetafileDestPoint(graphics
, metafile
, &ptf
, callback
, cb_data
, attrs
);
3766 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromMetafile(GpMetafile
* metafile
,
3767 MetafileHeader
* header
)
3771 TRACE("(%p, %p)\n", metafile
, header
);
3773 if(!metafile
|| !header
)
3774 return InvalidParameter
;
3778 status
= GdipGetMetafileHeaderFromEmf(metafile
->hemf
, header
);
3779 if (status
!= Ok
) return status
;
3783 memset(header
, 0, sizeof(*header
));
3784 header
->Version
= VERSION_MAGIC2
;
3787 header
->Type
= metafile
->metafile_type
;
3788 header
->DpiX
= metafile
->image
.xres
;
3789 header
->DpiY
= metafile
->image
.yres
;
3790 header
->Width
= gdip_round(metafile
->bounds
.Width
);
3791 header
->Height
= gdip_round(metafile
->bounds
.Height
);
3796 static int CALLBACK
get_emfplus_header_proc(HDC hDC
, HANDLETABLE
*lpHTable
, const ENHMETARECORD
*lpEMFR
,
3797 int nObj
, LPARAM lpData
)
3799 EmfPlusHeader
*dst_header
= (EmfPlusHeader
*)lpData
;
3801 if (lpEMFR
->iType
== EMR_GDICOMMENT
)
3803 const EMRGDICOMMENT
*comment
= (const EMRGDICOMMENT
*)lpEMFR
;
3805 if (comment
->cbData
>= 4 && memcmp(comment
->Data
, "EMF+", 4) == 0)
3807 const EmfPlusRecordHeader
*header
= (const EmfPlusRecordHeader
*)&comment
->Data
[4];
3809 if (4 + sizeof(EmfPlusHeader
) <= comment
->cbData
&&
3810 header
->Type
== EmfPlusRecordTypeHeader
)
3812 memcpy(dst_header
, header
, sizeof(*dst_header
));
3816 else if (lpEMFR
->iType
== EMR_HEADER
)
3822 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromEmf(HENHMETAFILE hemf
,
3823 MetafileHeader
*header
)
3825 ENHMETAHEADER3 emfheader
;
3826 EmfPlusHeader emfplusheader
;
3827 MetafileType metafile_type
;
3829 TRACE("(%p,%p)\n", hemf
, header
);
3831 if(!hemf
|| !header
)
3832 return InvalidParameter
;
3834 if (GetEnhMetaFileHeader(hemf
, sizeof(emfheader
), (ENHMETAHEADER
*)&emfheader
) == 0)
3835 return GenericError
;
3837 emfplusheader
.Header
.Type
= 0;
3839 EnumEnhMetaFile(NULL
, hemf
, get_emfplus_header_proc
, &emfplusheader
, NULL
);
3841 if (emfplusheader
.Header
.Type
== EmfPlusRecordTypeHeader
)
3843 if ((emfplusheader
.Header
.Flags
& 1) == 1)
3844 metafile_type
= MetafileTypeEmfPlusDual
;
3846 metafile_type
= MetafileTypeEmfPlusOnly
;
3849 metafile_type
= MetafileTypeEmf
;
3851 header
->Type
= metafile_type
;
3852 header
->Size
= emfheader
.nBytes
;
3853 header
->DpiX
= (REAL
)emfheader
.szlDevice
.cx
* 25.4 / emfheader
.szlMillimeters
.cx
;
3854 header
->DpiY
= (REAL
)emfheader
.szlDevice
.cy
* 25.4 / emfheader
.szlMillimeters
.cy
;
3855 header
->X
= gdip_round((REAL
)emfheader
.rclFrame
.left
/ 2540.0 * header
->DpiX
);
3856 header
->Y
= gdip_round((REAL
)emfheader
.rclFrame
.top
/ 2540.0 * header
->DpiY
);
3857 header
->Width
= gdip_round((REAL
)(emfheader
.rclFrame
.right
- emfheader
.rclFrame
.left
) / 2540.0 * header
->DpiX
);
3858 header
->Height
= gdip_round((REAL
)(emfheader
.rclFrame
.bottom
- emfheader
.rclFrame
.top
) / 2540.0 * header
->DpiY
);
3859 header
->u
.EmfHeader
= emfheader
;
3861 if (metafile_type
== MetafileTypeEmfPlusDual
|| metafile_type
== MetafileTypeEmfPlusOnly
)
3863 header
->Version
= emfplusheader
.Version
;
3864 header
->EmfPlusFlags
= emfplusheader
.EmfPlusFlags
;
3865 header
->EmfPlusHeaderSize
= emfplusheader
.Header
.Size
;
3866 header
->LogicalDpiX
= emfplusheader
.LogicalDpiX
;
3867 header
->LogicalDpiY
= emfplusheader
.LogicalDpiY
;
3871 header
->Version
= emfheader
.nVersion
;
3872 header
->EmfPlusFlags
= 0;
3873 header
->EmfPlusHeaderSize
= 0;
3874 header
->LogicalDpiX
= 0;
3875 header
->LogicalDpiY
= 0;
3881 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromWmf(HMETAFILE hwmf
,
3882 GDIPCONST WmfPlaceableFileHeader
*placeable
, MetafileHeader
*header
)
3885 GpMetafile
*metafile
;
3887 TRACE("(%p,%p,%p)\n", hwmf
, placeable
, header
);
3889 status
= GdipCreateMetafileFromWmf(hwmf
, FALSE
, placeable
, &metafile
);
3892 status
= GdipGetMetafileHeaderFromMetafile(metafile
, header
);
3893 GdipDisposeImage(&metafile
->image
);
3898 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromFile(GDIPCONST WCHAR
*filename
,
3899 MetafileHeader
*header
)
3902 GpMetafile
*metafile
;
3904 TRACE("(%s,%p)\n", debugstr_w(filename
), header
);
3906 if (!filename
|| !header
)
3907 return InvalidParameter
;
3909 status
= GdipCreateMetafileFromFile(filename
, &metafile
);
3912 status
= GdipGetMetafileHeaderFromMetafile(metafile
, header
);
3913 GdipDisposeImage(&metafile
->image
);
3918 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromStream(IStream
*stream
,
3919 MetafileHeader
*header
)
3922 GpMetafile
*metafile
;
3924 TRACE("(%p,%p)\n", stream
, header
);
3926 if (!stream
|| !header
)
3927 return InvalidParameter
;
3929 status
= GdipCreateMetafileFromStream(stream
, &metafile
);
3932 status
= GdipGetMetafileHeaderFromMetafile(metafile
, header
);
3933 GdipDisposeImage(&metafile
->image
);
3938 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
3939 GpMetafile
**metafile
)
3942 MetafileHeader header
;
3944 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
3946 if(!hemf
|| !metafile
)
3947 return InvalidParameter
;
3949 stat
= GdipGetMetafileHeaderFromEmf(hemf
, &header
);
3953 *metafile
= heap_alloc_zero(sizeof(GpMetafile
));
3957 (*metafile
)->image
.type
= ImageTypeMetafile
;
3958 (*metafile
)->image
.format
= ImageFormatEMF
;
3959 (*metafile
)->image
.frame_count
= 1;
3960 (*metafile
)->image
.xres
= header
.DpiX
;
3961 (*metafile
)->image
.yres
= header
.DpiY
;
3962 (*metafile
)->bounds
.X
= (REAL
)header
.u
.EmfHeader
.rclFrame
.left
/ 2540.0 * header
.DpiX
;
3963 (*metafile
)->bounds
.Y
= (REAL
)header
.u
.EmfHeader
.rclFrame
.top
/ 2540.0 * header
.DpiY
;
3964 (*metafile
)->bounds
.Width
= (REAL
)(header
.u
.EmfHeader
.rclFrame
.right
- header
.u
.EmfHeader
.rclFrame
.left
)
3965 / 2540.0 * header
.DpiX
;
3966 (*metafile
)->bounds
.Height
= (REAL
)(header
.u
.EmfHeader
.rclFrame
.bottom
- header
.u
.EmfHeader
.rclFrame
.top
)
3967 / 2540.0 * header
.DpiY
;
3968 (*metafile
)->unit
= UnitPixel
;
3969 (*metafile
)->metafile_type
= header
.Type
;
3970 (*metafile
)->hemf
= hemf
;
3971 (*metafile
)->preserve_hemf
= !delete;
3972 /* If the 31th bit of EmfPlusFlags was set, metafile was recorded with a DC for a video display.
3973 * If clear, metafile was recorded with a DC for a printer */
3974 (*metafile
)->printer_display
= !(header
.EmfPlusFlags
& (1u << 31));
3975 (*metafile
)->logical_dpix
= header
.LogicalDpiX
;
3976 (*metafile
)->logical_dpiy
= header
.LogicalDpiY
;
3977 list_init(&(*metafile
)->containers
);
3979 TRACE("<-- %p\n", *metafile
);
3984 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
3985 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
3990 GpStatus retval
= Ok
;
3992 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
3994 if(!hwmf
|| !metafile
)
3995 return InvalidParameter
;
3998 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
4000 return GenericError
;
4001 copy
= heap_alloc_zero(read
);
4002 GetMetaFileBitsEx(hwmf
, read
, copy
);
4004 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
4007 /* FIXME: We should store and use hwmf instead of converting to hemf */
4008 retval
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
4014 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
4015 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
4016 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
4017 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
4018 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
4019 placeable
->BoundingBox
.Left
);
4020 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
4021 placeable
->BoundingBox
.Top
);
4022 (*metafile
)->metafile_type
= MetafileTypeWmfPlaceable
;
4025 (*metafile
)->metafile_type
= MetafileTypeWmf
;
4026 (*metafile
)->image
.format
= ImageFormatWMF
;
4028 if (delete) DeleteMetaFile(hwmf
);
4031 DeleteEnhMetaFile(hemf
);
4035 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
4036 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
4041 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
4043 hmf
= GetMetaFileW(file
);
4045 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
4047 emf
= GetEnhMetaFileW(file
);
4049 return GdipCreateMetafileFromEmf(emf
, TRUE
, metafile
);
4051 return GenericError
;
4054 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
4055 GpMetafile
**metafile
)
4060 TRACE("(%p, %p)\n", file
, metafile
);
4062 if (!file
|| !metafile
) return InvalidParameter
;
4066 status
= GdipCreateStreamOnFile(file
, GENERIC_READ
, &stream
);
4069 status
= GdipCreateMetafileFromStream(stream
, metafile
);
4070 IStream_Release(stream
);
4075 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
4076 GpMetafile
**metafile
)
4080 TRACE("%p %p\n", stream
, metafile
);
4082 stat
= GdipLoadImageFromStream(stream
, (GpImage
**)metafile
);
4083 if (stat
!= Ok
) return stat
;
4085 if ((*metafile
)->image
.type
!= ImageTypeMetafile
)
4087 GdipDisposeImage(&(*metafile
)->image
);
4089 return GenericError
;
4095 GpStatus WINGDIPAPI
GdipGetMetafileDownLevelRasterizationLimit(GDIPCONST GpMetafile
*metafile
,
4098 TRACE("(%p,%p)\n", metafile
, limitDpi
);
4100 if (!metafile
|| !limitDpi
)
4101 return InvalidParameter
;
4103 if (!metafile
->record_dc
)
4106 *limitDpi
= metafile
->limit_dpi
;
4111 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
4114 TRACE("(%p,%u)\n", metafile
, limitDpi
);
4119 if (!metafile
|| limitDpi
< 10)
4120 return InvalidParameter
;
4122 if (!metafile
->record_dc
)
4125 metafile
->limit_dpi
= limitDpi
;
4130 GpStatus WINGDIPAPI
GdipConvertToEmfPlus(const GpGraphics
* ref
,
4131 GpMetafile
* metafile
, BOOL
* succ
, EmfType emfType
,
4132 const WCHAR
* description
, GpMetafile
** out_metafile
)
4136 TRACE("(%p,%p,%p,%u,%s,%p)\n", ref
, metafile
, succ
, emfType
,
4137 debugstr_w(description
), out_metafile
);
4139 if(!ref
|| !metafile
|| !out_metafile
|| emfType
< EmfTypeEmfOnly
|| emfType
> EmfTypeEmfPlusDual
)
4140 return InvalidParameter
;
4144 *out_metafile
= NULL
;
4147 FIXME("not implemented\n");
4149 return NotImplemented
;
4152 GpStatus WINGDIPAPI
GdipEmfToWmfBits(HENHMETAFILE hemf
, UINT cbData16
,
4153 LPBYTE pData16
, INT iMapMode
, INT eFlags
)
4155 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf
, cbData16
, pData16
, iMapMode
, eFlags
);
4156 return NotImplemented
;
4159 GpStatus WINGDIPAPI
GdipRecordMetafileFileName(GDIPCONST WCHAR
* fileName
,
4160 HDC hdc
, EmfType type
, GDIPCONST GpRectF
*pFrameRect
,
4161 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
,
4162 GpMetafile
**metafile
)
4166 REAL framerect_factor_x
, framerect_factor_y
;
4170 TRACE("%s %p %d %s %d %s %p\n", debugstr_w(fileName
), hdc
, type
, debugstr_rectf(pFrameRect
),
4171 frameUnit
, debugstr_w(desc
), metafile
);
4173 if (!hdc
|| type
< EmfTypeEmfOnly
|| type
> EmfTypeEmfPlusDual
|| !metafile
)
4174 return InvalidParameter
;
4176 dpix
= (REAL
)GetDeviceCaps(hdc
, HORZRES
) / GetDeviceCaps(hdc
, HORZSIZE
) * 25.4;
4177 dpiy
= (REAL
)GetDeviceCaps(hdc
, VERTRES
) / GetDeviceCaps(hdc
, VERTSIZE
) * 25.4;
4183 case MetafileFrameUnitPixel
:
4184 framerect_factor_x
= 2540.0 / dpix
;
4185 framerect_factor_y
= 2540.0 / dpiy
;
4187 case MetafileFrameUnitPoint
:
4188 framerect_factor_x
= framerect_factor_y
= 2540.0 / 72.0;
4190 case MetafileFrameUnitInch
:
4191 framerect_factor_x
= framerect_factor_y
= 2540.0;
4193 case MetafileFrameUnitDocument
:
4194 framerect_factor_x
= framerect_factor_y
= 2540.0 / 300.0;
4196 case MetafileFrameUnitMillimeter
:
4197 framerect_factor_x
= framerect_factor_y
= 100.0;
4199 case MetafileFrameUnitGdi
:
4200 framerect_factor_x
= framerect_factor_y
= 1.0;
4203 return InvalidParameter
;
4206 rc
.left
= framerect_factor_x
* pFrameRect
->X
;
4207 rc
.top
= framerect_factor_y
* pFrameRect
->Y
;
4208 rc
.right
= rc
.left
+ framerect_factor_x
* pFrameRect
->Width
;
4209 rc
.bottom
= rc
.top
+ framerect_factor_y
* pFrameRect
->Height
;
4216 record_dc
= CreateEnhMetaFileW(hdc
, fileName
, lprc
, desc
);
4219 return GenericError
;
4221 *metafile
= heap_alloc_zero(sizeof(GpMetafile
));
4224 DeleteEnhMetaFile(CloseEnhMetaFile(record_dc
));
4228 (*metafile
)->image
.type
= ImageTypeMetafile
;
4229 (*metafile
)->image
.flags
= ImageFlagsNone
;
4230 (*metafile
)->image
.palette
= NULL
;
4231 (*metafile
)->image
.xres
= dpix
;
4232 (*metafile
)->image
.yres
= dpiy
;
4233 (*metafile
)->bounds
.X
= (*metafile
)->bounds
.Y
= 0.0;
4234 (*metafile
)->bounds
.Width
= (*metafile
)->bounds
.Height
= 1.0;
4235 (*metafile
)->unit
= UnitPixel
;
4236 (*metafile
)->metafile_type
= type
;
4237 (*metafile
)->record_dc
= record_dc
;
4238 (*metafile
)->comment_data
= NULL
;
4239 (*metafile
)->comment_data_size
= 0;
4240 (*metafile
)->comment_data_length
= 0;
4241 (*metafile
)->limit_dpi
= 96;
4242 (*metafile
)->hemf
= NULL
;
4243 (*metafile
)->printer_display
= (GetDeviceCaps(record_dc
, TECHNOLOGY
) == DT_RASPRINTER
);
4244 (*metafile
)->logical_dpix
= (REAL
)GetDeviceCaps(record_dc
, LOGPIXELSX
);
4245 (*metafile
)->logical_dpiy
= (REAL
)GetDeviceCaps(record_dc
, LOGPIXELSY
);
4246 list_init(&(*metafile
)->containers
);
4250 (*metafile
)->auto_frame
= TRUE
;
4251 (*metafile
)->auto_frame_min
.X
= 0;
4252 (*metafile
)->auto_frame_min
.Y
= 0;
4253 (*metafile
)->auto_frame_max
.X
= -1;
4254 (*metafile
)->auto_frame_max
.Y
= -1;
4257 stat
= METAFILE_WriteHeader(*metafile
, hdc
);
4261 DeleteEnhMetaFile(CloseEnhMetaFile(record_dc
));
4262 heap_free(*metafile
);
4270 GpStatus WINGDIPAPI
GdipRecordMetafileFileNameI(GDIPCONST WCHAR
* fileName
, HDC hdc
, EmfType type
,
4271 GDIPCONST GpRect
*pFrameRect
, MetafileFrameUnit frameUnit
,
4272 GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
4274 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
4275 frameUnit
, debugstr_w(desc
), metafile
);
4277 return NotImplemented
;
4280 /*****************************************************************************
4281 * GdipConvertToEmfPlusToFile [GDIPLUS.@]
4284 GpStatus WINGDIPAPI
GdipConvertToEmfPlusToFile(const GpGraphics
* refGraphics
,
4285 GpMetafile
* metafile
, BOOL
* conversionSuccess
,
4286 const WCHAR
* filename
, EmfType emfType
,
4287 const WCHAR
* description
, GpMetafile
** out_metafile
)
4289 FIXME("stub: %p, %p, %p, %p, %u, %p, %p\n", refGraphics
, metafile
, conversionSuccess
, filename
, emfType
, description
, out_metafile
);
4290 return NotImplemented
;
4293 static GpStatus
METAFILE_CreateCompressedImageStream(GpImage
*image
, IStream
**stream
, DWORD
*size
)
4302 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, stream
);
4303 if (FAILED(hr
)) return hresult_to_status(hr
);
4305 stat
= encode_image_png(image
, *stream
, NULL
);
4308 IStream_Release(*stream
);
4312 hr
= IStream_Stat(*stream
, &statstg
, 1);
4315 IStream_Release(*stream
);
4316 return hresult_to_status(hr
);
4318 *size
= statstg
.cbSize
.u
.LowPart
;
4321 hr
= IStream_Seek(*stream
, zero
, STREAM_SEEK_SET
, NULL
);
4324 IStream_Release(*stream
);
4325 return hresult_to_status(hr
);
4331 static GpStatus
METAFILE_FillEmfPlusBitmap(EmfPlusBitmap
*record
, IStream
*stream
, DWORD size
)
4338 record
->PixelFormat
= 0;
4339 record
->Type
= BitmapDataTypeCompressed
;
4341 hr
= IStream_Read(stream
, record
->BitmapData
, size
, NULL
);
4342 if (FAILED(hr
)) return hresult_to_status(hr
);
4346 static GpStatus
METAFILE_AddImageObject(GpMetafile
*metafile
, GpImage
*image
, DWORD
*id
)
4348 EmfPlusObject
*object_record
;
4354 if (metafile
->metafile_type
!= MetafileTypeEmfPlusOnly
&& metafile
->metafile_type
!= MetafileTypeEmfPlusDual
)
4357 if (image
->type
== ImageTypeBitmap
)
4362 stat
= METAFILE_CreateCompressedImageStream(image
, &stream
, &size
);
4363 if (stat
!= Ok
) return stat
;
4364 aligned_size
= (size
+ 3) & ~3;
4366 stat
= METAFILE_AllocateRecord(metafile
,
4367 FIELD_OFFSET(EmfPlusObject
, ObjectData
.image
.ImageData
.bitmap
.BitmapData
[aligned_size
]),
4368 (void**)&object_record
);
4371 IStream_Release(stream
);
4374 memset(object_record
->ObjectData
.image
.ImageData
.bitmap
.BitmapData
+ size
, 0, aligned_size
- size
);
4376 *id
= METAFILE_AddObjectId(metafile
);
4377 object_record
->Header
.Type
= EmfPlusRecordTypeObject
;
4378 object_record
->Header
.Flags
= *id
| ObjectTypeImage
<< 8;
4379 object_record
->ObjectData
.image
.Version
= VERSION_MAGIC2
;
4380 object_record
->ObjectData
.image
.Type
= ImageDataTypeBitmap
;
4382 stat
= METAFILE_FillEmfPlusBitmap(&object_record
->ObjectData
.image
.ImageData
.bitmap
, stream
, size
);
4383 IStream_Release(stream
);
4384 if (stat
!= Ok
) METAFILE_RemoveLastRecord(metafile
, &object_record
->Header
);
4387 else if (image
->type
== ImageTypeMetafile
)
4389 HENHMETAFILE hemf
= ((GpMetafile
*)image
)->hemf
;
4390 EmfPlusMetafile
*metafile_record
;
4392 if (!hemf
) return InvalidParameter
;
4394 size
= GetEnhMetaFileBits(hemf
, 0, NULL
);
4395 if (!size
) return GenericError
;
4397 stat
= METAFILE_AllocateRecord(metafile
,
4398 FIELD_OFFSET(EmfPlusObject
, ObjectData
.image
.ImageData
.metafile
.MetafileData
[size
]),
4399 (void**)&object_record
);
4400 if (stat
!= Ok
) return stat
;
4402 *id
= METAFILE_AddObjectId(metafile
);
4403 object_record
->Header
.Type
= EmfPlusRecordTypeObject
;
4404 object_record
->Header
.Flags
= *id
| ObjectTypeImage
<< 8;
4405 object_record
->ObjectData
.image
.Version
= VERSION_MAGIC2
;
4406 object_record
->ObjectData
.image
.Type
= ImageDataTypeMetafile
;
4407 metafile_record
= &object_record
->ObjectData
.image
.ImageData
.metafile
;
4408 metafile_record
->Type
= ((GpMetafile
*)image
)->metafile_type
;
4409 metafile_record
->MetafileDataSize
= size
;
4410 if (GetEnhMetaFileBits(hemf
, size
, metafile_record
->MetafileData
) != size
)
4412 METAFILE_RemoveLastRecord(metafile
, &object_record
->Header
);
4413 return GenericError
;
4419 FIXME("not supported image type (%d)\n", image
->type
);
4420 return NotImplemented
;
4424 static GpStatus
METAFILE_AddImageAttributesObject(GpMetafile
*metafile
, const GpImageAttributes
*attrs
, DWORD
*id
)
4426 EmfPlusObject
*object_record
;
4427 EmfPlusImageAttributes
*attrs_record
;
4432 if (metafile
->metafile_type
!= MetafileTypeEmfPlusOnly
&& metafile
->metafile_type
!= MetafileTypeEmfPlusDual
)
4438 stat
= METAFILE_AllocateRecord(metafile
,
4439 FIELD_OFFSET(EmfPlusObject
, ObjectData
.image_attributes
) + sizeof(EmfPlusImageAttributes
),
4440 (void**)&object_record
);
4441 if (stat
!= Ok
) return stat
;
4443 *id
= METAFILE_AddObjectId(metafile
);
4444 object_record
->Header
.Type
= EmfPlusRecordTypeObject
;
4445 object_record
->Header
.Flags
= *id
| (ObjectTypeImageAttributes
<< 8);
4446 attrs_record
= &object_record
->ObjectData
.image_attributes
;
4447 attrs_record
->Version
= VERSION_MAGIC2
;
4448 attrs_record
->Reserved1
= 0;
4449 attrs_record
->WrapMode
= attrs
->wrap
;
4450 attrs_record
->ClampColor
= attrs
->outside_color
;
4451 attrs_record
->ObjectClamp
= attrs
->clamp
;
4452 attrs_record
->Reserved2
= 0;
4456 GpStatus
METAFILE_DrawImagePointsRect(GpMetafile
*metafile
, GpImage
*image
,
4457 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
4458 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
4459 DrawImageAbort callback
, VOID
*callbackData
)
4461 EmfPlusDrawImagePoints
*draw_image_record
;
4462 DWORD image_id
, attributes_id
;
4465 if (count
!= 3) return InvalidParameter
;
4467 if (metafile
->metafile_type
== MetafileTypeEmf
)
4469 FIXME("MetafileTypeEmf metafiles not supported\n");
4470 return NotImplemented
;
4473 FIXME("semi-stub\n");
4475 if (!imageAttributes
)
4477 stat
= METAFILE_AddImageObject(metafile
, image
, &image_id
);
4479 else if (image
->type
== ImageTypeBitmap
)
4481 INT width
= ((GpBitmap
*)image
)->width
;
4482 INT height
= ((GpBitmap
*)image
)->height
;
4483 GpGraphics
*graphics
;
4486 stat
= GdipCreateBitmapFromScan0(width
, height
,
4487 0, PixelFormat32bppARGB
, NULL
, &bitmap
);
4488 if (stat
!= Ok
) return stat
;
4490 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
4493 GdipDisposeImage((GpImage
*)bitmap
);
4497 stat
= GdipDrawImageRectRectI(graphics
, image
, 0, 0, width
, height
,
4498 0, 0, width
, height
, UnitPixel
, imageAttributes
, NULL
, NULL
);
4499 GdipDeleteGraphics(graphics
);
4502 GdipDisposeImage((GpImage
*)bitmap
);
4506 stat
= METAFILE_AddImageObject(metafile
, (GpImage
*)bitmap
, &image_id
);
4507 GdipDisposeImage((GpImage
*)bitmap
);
4511 FIXME("imageAttributes not supported (image type %d)\n", image
->type
);
4512 return NotImplemented
;
4514 if (stat
!= Ok
) return stat
;
4516 stat
= METAFILE_AddImageAttributesObject(metafile
, imageAttributes
, &attributes_id
);
4517 if (stat
!= Ok
) return stat
;
4519 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusDrawImagePoints
), (void**)&draw_image_record
);
4520 if (stat
!= Ok
) return stat
;
4521 draw_image_record
->Header
.Type
= EmfPlusRecordTypeDrawImagePoints
;
4522 draw_image_record
->Header
.Flags
= image_id
;
4523 draw_image_record
->ImageAttributesID
= attributes_id
;
4524 draw_image_record
->SrcUnit
= UnitPixel
;
4525 draw_image_record
->SrcRect
.X
= units_to_pixels(srcx
, srcUnit
, metafile
->image
.xres
, metafile
->printer_display
);
4526 draw_image_record
->SrcRect
.Y
= units_to_pixels(srcy
, srcUnit
, metafile
->image
.yres
, metafile
->printer_display
);
4527 draw_image_record
->SrcRect
.Width
= units_to_pixels(srcwidth
, srcUnit
, metafile
->image
.xres
, metafile
->printer_display
);
4528 draw_image_record
->SrcRect
.Height
= units_to_pixels(srcheight
, srcUnit
, metafile
->image
.yres
, metafile
->printer_display
);
4529 draw_image_record
->count
= 3;
4530 memcpy(draw_image_record
->PointData
.pointsF
, points
, 3 * sizeof(*points
));
4531 METAFILE_WriteRecords(metafile
);
4535 GpStatus
METAFILE_AddSimpleProperty(GpMetafile
*metafile
, SHORT prop
, SHORT val
)
4537 EmfPlusRecordHeader
*record
;
4540 if (metafile
->metafile_type
!= MetafileTypeEmfPlusOnly
&& metafile
->metafile_type
!= MetafileTypeEmfPlusDual
)
4543 stat
= METAFILE_AllocateRecord(metafile
, sizeof(*record
), (void**)&record
);
4544 if (stat
!= Ok
) return stat
;
4546 record
->Type
= prop
;
4547 record
->Flags
= val
;
4549 METAFILE_WriteRecords(metafile
);
4553 static GpStatus
METAFILE_AddPathObject(GpMetafile
*metafile
, GpPath
*path
, DWORD
*id
)
4555 EmfPlusObject
*object_record
;
4560 if (metafile
->metafile_type
!= MetafileTypeEmfPlusOnly
&& metafile
->metafile_type
!= MetafileTypeEmfPlusDual
)
4563 size
= write_path_data(path
, NULL
);
4564 stat
= METAFILE_AllocateRecord(metafile
,
4565 FIELD_OFFSET(EmfPlusObject
, ObjectData
.path
) + size
,
4566 (void**)&object_record
);
4567 if (stat
!= Ok
) return stat
;
4569 *id
= METAFILE_AddObjectId(metafile
);
4570 object_record
->Header
.Type
= EmfPlusRecordTypeObject
;
4571 object_record
->Header
.Flags
= *id
| ObjectTypePath
<< 8;
4572 write_path_data(path
, &object_record
->ObjectData
.path
);
4576 static GpStatus
METAFILE_AddPenObject(GpMetafile
*metafile
, GpPen
*pen
, DWORD
*id
)
4578 DWORD i
, data_flags
, pen_data_size
, brush_size
;
4579 EmfPlusObject
*object_record
;
4580 EmfPlusPenData
*pen_data
;
4585 if (metafile
->metafile_type
!= MetafileTypeEmfPlusOnly
&& metafile
->metafile_type
!= MetafileTypeEmfPlusDual
)
4589 pen_data_size
= FIELD_OFFSET(EmfPlusPenData
, OptionalData
);
4591 GdipIsMatrixIdentity(&pen
->transform
, &result
);
4594 data_flags
|= PenDataTransform
;
4595 pen_data_size
+= sizeof(EmfPlusTransformMatrix
);
4597 if (pen
->startcap
!= LineCapFlat
)
4599 data_flags
|= PenDataStartCap
;
4600 pen_data_size
+= sizeof(DWORD
);
4602 if (pen
->endcap
!= LineCapFlat
)
4604 data_flags
|= PenDataEndCap
;
4605 pen_data_size
+= sizeof(DWORD
);
4607 if (pen
->join
!= LineJoinMiter
)
4609 data_flags
|= PenDataJoin
;
4610 pen_data_size
+= sizeof(DWORD
);
4612 if (pen
->miterlimit
!= 10.0)
4614 data_flags
|= PenDataMiterLimit
;
4615 pen_data_size
+= sizeof(REAL
);
4617 if (pen
->style
!= GP_DEFAULT_PENSTYLE
)
4619 data_flags
|= PenDataLineStyle
;
4620 pen_data_size
+= sizeof(DWORD
);
4622 if (pen
->dashcap
!= DashCapFlat
)
4624 data_flags
|= PenDataDashedLineCap
;
4625 pen_data_size
+= sizeof(DWORD
);
4627 data_flags
|= PenDataDashedLineOffset
;
4628 pen_data_size
+= sizeof(REAL
);
4631 data_flags
|= PenDataDashedLine
;
4632 pen_data_size
+= sizeof(DWORD
) + pen
->numdashes
*sizeof(REAL
);
4634 if (pen
->align
!= PenAlignmentCenter
)
4636 data_flags
|= PenDataNonCenter
;
4637 pen_data_size
+= sizeof(DWORD
);
4639 /* TODO: Add support for PenDataCompoundLine */
4640 if (pen
->customstart
)
4642 FIXME("ignoring custom start cup\n");
4646 FIXME("ignoring custom end cup\n");
4649 stat
= METAFILE_PrepareBrushData(pen
->brush
, &brush_size
);
4650 if (stat
!= Ok
) return stat
;
4652 stat
= METAFILE_AllocateRecord(metafile
,
4653 FIELD_OFFSET(EmfPlusObject
, ObjectData
.pen
.data
) + pen_data_size
+ brush_size
,
4654 (void**)&object_record
);
4655 if (stat
!= Ok
) return stat
;
4657 *id
= METAFILE_AddObjectId(metafile
);
4658 object_record
->Header
.Type
= EmfPlusRecordTypeObject
;
4659 object_record
->Header
.Flags
= *id
| ObjectTypePen
<< 8;
4660 object_record
->ObjectData
.pen
.Version
= VERSION_MAGIC2
;
4661 object_record
->ObjectData
.pen
.Type
= 0;
4663 pen_data
= (EmfPlusPenData
*)object_record
->ObjectData
.pen
.data
;
4664 pen_data
->PenDataFlags
= data_flags
;
4665 pen_data
->PenUnit
= pen
->unit
;
4666 pen_data
->PenWidth
= pen
->width
;
4669 if (data_flags
& PenDataTransform
)
4671 EmfPlusTransformMatrix
*m
= (EmfPlusTransformMatrix
*)(pen_data
->OptionalData
+ i
);
4672 memcpy(m
, &pen
->transform
, sizeof(*m
));
4673 i
+= sizeof(EmfPlusTransformMatrix
);
4675 if (data_flags
& PenDataStartCap
)
4677 *(DWORD
*)(pen_data
->OptionalData
+ i
) = pen
->startcap
;
4680 if (data_flags
& PenDataEndCap
)
4682 *(DWORD
*)(pen_data
->OptionalData
+ i
) = pen
->endcap
;
4685 if (data_flags
& PenDataJoin
)
4687 *(DWORD
*)(pen_data
->OptionalData
+ i
) = pen
->join
;
4690 if (data_flags
& PenDataMiterLimit
)
4692 *(REAL
*)(pen_data
->OptionalData
+ i
) = pen
->miterlimit
;
4695 if (data_flags
& PenDataLineStyle
)
4697 switch (pen
->style
& PS_STYLE_MASK
)
4699 case PS_SOLID
: *(DWORD
*)(pen_data
->OptionalData
+ i
) = LineStyleSolid
; break;
4700 case PS_DASH
: *(DWORD
*)(pen_data
->OptionalData
+ i
) = LineStyleDash
; break;
4701 case PS_DOT
: *(DWORD
*)(pen_data
->OptionalData
+ i
) = LineStyleDot
; break;
4702 case PS_DASHDOT
: *(DWORD
*)(pen_data
->OptionalData
+ i
) = LineStyleDashDot
; break;
4703 case PS_DASHDOTDOT
: *(DWORD
*)(pen_data
->OptionalData
+ i
) = LineStyleDashDotDot
; break;
4704 default: *(DWORD
*)(pen_data
->OptionalData
+ i
) = LineStyleCustom
; break;
4708 if (data_flags
& PenDataDashedLineCap
)
4710 *(DWORD
*)(pen_data
->OptionalData
+ i
) = pen
->dashcap
;
4713 if (data_flags
& PenDataDashedLineOffset
)
4715 *(REAL
*)(pen_data
->OptionalData
+ i
) = pen
->offset
;
4718 if (data_flags
& PenDataDashedLine
)
4722 *(DWORD
*)(pen_data
->OptionalData
+ i
) = pen
->numdashes
;
4725 for (j
=0; j
<pen
->numdashes
; j
++)
4727 *(REAL
*)(pen_data
->OptionalData
+ i
) = pen
->dashes
[j
];
4731 if (data_flags
& PenDataNonCenter
)
4733 *(REAL
*)(pen_data
->OptionalData
+ i
) = pen
->align
;
4737 METAFILE_FillBrushData(pen
->brush
,
4738 (EmfPlusBrush
*)(object_record
->ObjectData
.pen
.data
+ pen_data_size
));
4742 GpStatus
METAFILE_DrawPath(GpMetafile
*metafile
, GpPen
*pen
, GpPath
*path
)
4744 EmfPlusDrawPath
*draw_path_record
;
4749 if (metafile
->metafile_type
== MetafileTypeEmf
)
4752 return NotImplemented
;
4755 stat
= METAFILE_AddPenObject(metafile
, pen
, &pen_id
);
4756 if (stat
!= Ok
) return stat
;
4758 stat
= METAFILE_AddPathObject(metafile
, path
, &path_id
);
4759 if (stat
!= Ok
) return stat
;
4761 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusDrawPath
), (void**)&draw_path_record
);
4762 if (stat
!= Ok
) return stat
;
4763 draw_path_record
->Header
.Type
= EmfPlusRecordTypeDrawPath
;
4764 draw_path_record
->Header
.Flags
= path_id
;
4765 draw_path_record
->PenId
= pen_id
;
4767 METAFILE_WriteRecords(metafile
);
4771 GpStatus
METAFILE_DrawEllipse(GpMetafile
*metafile
, GpPen
*pen
, GpRectF
*rect
)
4773 EmfPlusDrawEllipse
*record
;
4777 if (metafile
->metafile_type
== MetafileTypeEmf
)
4780 return NotImplemented
;
4783 stat
= METAFILE_AddPenObject(metafile
, pen
, &pen_id
);
4784 if (stat
!= Ok
) return stat
;
4786 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusDrawEllipse
), (void **)&record
);
4787 if (stat
!= Ok
) return stat
;
4788 record
->Header
.Type
= EmfPlusRecordTypeDrawEllipse
;
4789 record
->Header
.Flags
= pen_id
;
4790 if (is_integer_rect(rect
))
4792 record
->Header
.Flags
|= 0x4000;
4793 record
->RectData
.rect
.X
= (SHORT
)rect
->X
;
4794 record
->RectData
.rect
.Y
= (SHORT
)rect
->Y
;
4795 record
->RectData
.rect
.Width
= (SHORT
)rect
->Width
;
4796 record
->RectData
.rect
.Height
= (SHORT
)rect
->Height
;
4799 memcpy(&record
->RectData
.rectF
, rect
, sizeof(*rect
));
4801 METAFILE_WriteRecords(metafile
);
4805 GpStatus
METAFILE_FillPath(GpMetafile
*metafile
, GpBrush
*brush
, GpPath
*path
)
4807 EmfPlusFillPath
*fill_path_record
;
4808 DWORD brush_id
= -1, path_id
;
4812 if (metafile
->metafile_type
== MetafileTypeEmf
)
4815 return NotImplemented
;
4818 inline_color
= brush
->bt
== BrushTypeSolidColor
;
4821 stat
= METAFILE_AddBrushObject(metafile
, brush
, &brush_id
);
4822 if (stat
!= Ok
) return stat
;
4825 stat
= METAFILE_AddPathObject(metafile
, path
, &path_id
);
4826 if (stat
!= Ok
) return stat
;
4828 stat
= METAFILE_AllocateRecord(metafile
,
4829 sizeof(EmfPlusFillPath
), (void**)&fill_path_record
);
4830 if (stat
!= Ok
) return stat
;
4831 fill_path_record
->Header
.Type
= EmfPlusRecordTypeFillPath
;
4834 fill_path_record
->Header
.Flags
= 0x8000 | path_id
;
4835 fill_path_record
->data
.Color
= ((GpSolidFill
*)brush
)->color
;
4839 fill_path_record
->Header
.Flags
= path_id
;
4840 fill_path_record
->data
.BrushId
= brush_id
;
4843 METAFILE_WriteRecords(metafile
);
4847 GpStatus
METAFILE_FillEllipse(GpMetafile
*metafile
, GpBrush
*brush
, GpRectF
*rect
)
4849 EmfPlusFillEllipse
*record
;
4850 DWORD brush_id
= -1;
4854 if (metafile
->metafile_type
== MetafileTypeEmf
)
4857 return NotImplemented
;
4860 inline_color
= brush
->bt
== BrushTypeSolidColor
;
4863 stat
= METAFILE_AddBrushObject(metafile
, brush
, &brush_id
);
4864 if (stat
!= Ok
) return stat
;
4867 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusFillEllipse
), (void **)&record
);
4868 if (stat
!= Ok
) return stat
;
4869 record
->Header
.Type
= EmfPlusRecordTypeFillEllipse
;
4872 record
->Header
.Flags
= 0x8000;
4873 record
->BrushId
= ((GpSolidFill
*)brush
)->color
;
4876 record
->BrushId
= brush_id
;
4878 if (is_integer_rect(rect
))
4880 record
->Header
.Flags
|= 0x4000;
4881 record
->RectData
.rect
.X
= (SHORT
)rect
->X
;
4882 record
->RectData
.rect
.Y
= (SHORT
)rect
->Y
;
4883 record
->RectData
.rect
.Width
= (SHORT
)rect
->Width
;
4884 record
->RectData
.rect
.Height
= (SHORT
)rect
->Height
;
4887 memcpy(&record
->RectData
.rectF
, rect
, sizeof(*rect
));
4889 METAFILE_WriteRecords(metafile
);
4893 GpStatus
METAFILE_FillPie(GpMetafile
*metafile
, GpBrush
*brush
, const GpRectF
*rect
,
4894 REAL startAngle
, REAL sweepAngle
)
4896 BOOL is_int_rect
, inline_color
;
4897 EmfPlusFillPie
*record
;
4898 DWORD brush_id
= -1;
4901 if (metafile
->metafile_type
== MetafileTypeEmf
)
4904 return NotImplemented
;
4907 inline_color
= brush
->bt
== BrushTypeSolidColor
;
4910 stat
= METAFILE_AddBrushObject(metafile
, brush
, &brush_id
);
4911 if (stat
!= Ok
) return stat
;
4914 is_int_rect
= is_integer_rect(rect
);
4916 stat
= METAFILE_AllocateRecord(metafile
, FIELD_OFFSET(EmfPlusFillPie
, RectData
) +
4917 is_int_rect
? sizeof(EmfPlusRect
) : sizeof(EmfPlusRectF
), (void **)&record
);
4918 if (stat
!= Ok
) return stat
;
4919 record
->Header
.Type
= EmfPlusRecordTypeFillPie
;
4922 record
->Header
.Flags
= 0x8000;
4923 record
->BrushId
= ((GpSolidFill
*)brush
)->color
;
4926 record
->BrushId
= brush_id
;
4928 record
->StartAngle
= startAngle
;
4929 record
->SweepAngle
= sweepAngle
;
4933 record
->Header
.Flags
|= 0x4000;
4934 record
->RectData
.rect
.X
= (SHORT
)rect
->X
;
4935 record
->RectData
.rect
.Y
= (SHORT
)rect
->Y
;
4936 record
->RectData
.rect
.Width
= (SHORT
)rect
->Width
;
4937 record
->RectData
.rect
.Height
= (SHORT
)rect
->Height
;
4940 memcpy(&record
->RectData
.rectF
, rect
, sizeof(*rect
));
4942 METAFILE_WriteRecords(metafile
);
4946 static GpStatus
METAFILE_AddFontObject(GpMetafile
*metafile
, GDIPCONST GpFont
*font
, DWORD
*id
)
4948 EmfPlusObject
*object_record
;
4949 EmfPlusFont
*font_record
;
4956 if (metafile
->metafile_type
!= MetafileTypeEmfPlusOnly
&&
4957 metafile
->metafile_type
!= MetafileTypeEmfPlusDual
)
4960 /* The following cast is ugly, but GdipGetFontStyle does treat
4961 its first parameter as const. */
4962 stat
= GdipGetFontStyle((GpFont
*)font
, &style
);
4966 fn_len
= lstrlenW(font
->family
->FamilyName
);
4967 stat
= METAFILE_AllocateRecord(metafile
,
4968 FIELD_OFFSET(EmfPlusObject
, ObjectData
.font
.FamilyName
[(fn_len
+ 1) & ~1]),
4969 (void**)&object_record
);
4973 *id
= METAFILE_AddObjectId(metafile
);
4975 object_record
->Header
.Type
= EmfPlusRecordTypeObject
;
4976 object_record
->Header
.Flags
= *id
| ObjectTypeFont
<< 8;
4978 font_record
= &object_record
->ObjectData
.font
;
4979 font_record
->Version
= VERSION_MAGIC2
;
4980 font_record
->EmSize
= font
->emSize
;
4981 font_record
->SizeUnit
= font
->unit
;
4982 font_record
->FontStyleFlags
= style
;
4983 font_record
->Reserved
= 0;
4984 font_record
->Length
= fn_len
;
4986 memcpy(font_record
->FamilyName
, font
->family
->FamilyName
,
4987 fn_len
* sizeof(*font
->family
->FamilyName
));
4992 GpStatus
METAFILE_DrawDriverString(GpMetafile
*metafile
, GDIPCONST UINT16
*text
, INT length
,
4993 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
,
4994 GDIPCONST PointF
*positions
, INT flags
, GDIPCONST GpMatrix
*matrix
)
5000 EmfPlusDrawDriverString
*draw_string_record
;
5003 BOOL include_matrix
= FALSE
;
5006 return InvalidParameter
;
5008 if (metafile
->metafile_type
!= MetafileTypeEmfPlusOnly
&&
5009 metafile
->metafile_type
!= MetafileTypeEmfPlusDual
)
5011 FIXME("metafile type not supported: %i\n", metafile
->metafile_type
);
5012 return NotImplemented
;
5015 stat
= METAFILE_AddFontObject(metafile
, font
, &font_id
);
5019 inline_color
= (brush
->bt
== BrushTypeSolidColor
);
5022 stat
= METAFILE_AddBrushObject(metafile
, brush
, &brush_id
);
5031 stat
= GdipIsMatrixIdentity(matrix
, &identity
);
5035 include_matrix
= !identity
;
5038 alloc_size
= FIELD_OFFSET(EmfPlusDrawDriverString
, VariableData
) +
5039 length
* (sizeof(*text
) + sizeof(*positions
));
5042 alloc_size
+= sizeof(*matrix
);
5044 /* Pad record to DWORD alignment. */
5045 alloc_size
= (alloc_size
+ 3) & ~3;
5047 stat
= METAFILE_AllocateRecord(metafile
, alloc_size
, (void**)&draw_string_record
);
5051 draw_string_record
->Header
.Type
= EmfPlusRecordTypeDrawDriverString
;
5052 draw_string_record
->Header
.Flags
= font_id
;
5053 draw_string_record
->DriverStringOptionsFlags
= flags
;
5054 draw_string_record
->MatrixPresent
= include_matrix
;
5055 draw_string_record
->GlyphCount
= length
;
5059 draw_string_record
->Header
.Flags
|= 0x8000;
5060 draw_string_record
->brush
.Color
= ((GpSolidFill
*)brush
)->color
;
5063 draw_string_record
->brush
.BrushId
= brush_id
;
5065 cursor
= &draw_string_record
->VariableData
[0];
5067 memcpy(cursor
, text
, length
* sizeof(*text
));
5068 cursor
+= length
* sizeof(*text
);
5070 if (flags
& DriverStringOptionsRealizedAdvance
)
5072 static BOOL fixme_written
= FALSE
;
5074 /* Native never writes DriverStringOptionsRealizedAdvance. Instead,
5075 in the case of RealizedAdvance, each glyph position is computed
5078 While native GDI+ is capable of playing back metafiles with this
5079 flag set, it is possible that some application might rely on
5080 metafiles produced from GDI+ not setting this flag. Ideally we
5081 would also compute the position of each glyph here, serialize those
5082 values, and not set DriverStringOptionsRealizedAdvance. */
5085 fixme_written
= TRUE
;
5086 FIXME("serializing RealizedAdvance flag and single GlyphPos with padding\n");
5089 *((PointF
*)cursor
) = *positions
;
5092 memcpy(cursor
, positions
, length
* sizeof(*positions
));
5096 cursor
+= length
* sizeof(*positions
);
5097 memcpy(cursor
, matrix
, sizeof(*matrix
));
5100 METAFILE_WriteRecords(metafile
);
5105 GpStatus
METAFILE_FillRegion(GpMetafile
* metafile
, GpBrush
* brush
, GpRegion
* region
)
5110 EmfPlusFillRegion
*fill_region_record
;
5113 if (metafile
->metafile_type
!= MetafileTypeEmfPlusOnly
&&
5114 metafile
->metafile_type
!= MetafileTypeEmfPlusDual
)
5116 FIXME("metafile type not supported: %i\n", metafile
->metafile_type
);
5117 return NotImplemented
;
5120 inline_color
= (brush
->bt
== BrushTypeSolidColor
);
5123 stat
= METAFILE_AddBrushObject(metafile
, brush
, &brush_id
);
5128 stat
= METAFILE_AddRegionObject(metafile
, region
, ®ion_id
);
5132 stat
= METAFILE_AllocateRecord(metafile
, sizeof(EmfPlusFillRegion
),
5133 (void**)&fill_region_record
);
5137 fill_region_record
->Header
.Type
= EmfPlusRecordTypeFillRegion
;
5138 fill_region_record
->Header
.Flags
= region_id
;
5142 fill_region_record
->Header
.Flags
|= 0x8000;
5143 fill_region_record
->data
.Color
= ((GpSolidFill
*)brush
)->color
;
5146 fill_region_record
->data
.BrushId
= brush_id
;
5148 METAFILE_WriteRecords(metafile
);
5153 GpStatus
METAFILE_DrawRectangles(GpMetafile
*metafile
, GpPen
*pen
, const GpRectF
*rects
, INT count
)
5155 EmfPlusDrawRects
*record
;
5157 BOOL integer_rects
= TRUE
;
5161 if (metafile
->metafile_type
== MetafileTypeEmf
)
5164 return NotImplemented
;
5167 stat
= METAFILE_AddPenObject(metafile
, pen
, &pen_id
);
5168 if (stat
!= Ok
) return stat
;
5170 for (i
= 0; i
< count
; i
++)
5172 if (!is_integer_rect(&rects
[i
]))
5174 integer_rects
= FALSE
;
5179 stat
= METAFILE_AllocateRecord(metafile
, FIELD_OFFSET(EmfPlusDrawRects
, RectData
) +
5180 count
* (integer_rects
? sizeof(record
->RectData
.rect
) : sizeof(record
->RectData
.rectF
)),
5185 record
->Header
.Type
= EmfPlusRecordTypeDrawRects
;
5186 record
->Header
.Flags
= pen_id
;
5188 record
->Header
.Flags
|= 0x4000;
5189 record
->Count
= count
;
5193 for (i
= 0; i
< count
; i
++)
5195 record
->RectData
.rect
[i
].X
= (SHORT
)rects
[i
].X
;
5196 record
->RectData
.rect
[i
].Y
= (SHORT
)rects
[i
].Y
;
5197 record
->RectData
.rect
[i
].Width
= (SHORT
)rects
[i
].Width
;
5198 record
->RectData
.rect
[i
].Height
= (SHORT
)rects
[i
].Height
;
5202 memcpy(record
->RectData
.rectF
, rects
, sizeof(*rects
) * count
);
5204 METAFILE_WriteRecords(metafile
);
5209 GpStatus
METAFILE_DrawArc(GpMetafile
*metafile
, GpPen
*pen
, const GpRectF
*rect
, REAL startAngle
, REAL sweepAngle
)
5211 EmfPlusDrawArc
*record
;
5216 if (metafile
->metafile_type
== MetafileTypeEmf
)
5219 return NotImplemented
;
5222 stat
= METAFILE_AddPenObject(metafile
, pen
, &pen_id
);
5223 if (stat
!= Ok
) return stat
;
5225 integer_rect
= is_integer_rect(rect
);
5227 stat
= METAFILE_AllocateRecord(metafile
, FIELD_OFFSET(EmfPlusDrawArc
, RectData
) +
5228 integer_rect
? sizeof(record
->RectData
.rect
) : sizeof(record
->RectData
.rectF
),
5233 record
->Header
.Type
= EmfPlusRecordTypeDrawArc
;
5234 record
->Header
.Flags
= pen_id
;
5236 record
->Header
.Flags
|= 0x4000;
5237 record
->StartAngle
= startAngle
;
5238 record
->SweepAngle
= sweepAngle
;
5242 record
->RectData
.rect
.X
= (SHORT
)rect
->X
;
5243 record
->RectData
.rect
.Y
= (SHORT
)rect
->Y
;
5244 record
->RectData
.rect
.Width
= (SHORT
)rect
->Width
;
5245 record
->RectData
.rect
.Height
= (SHORT
)rect
->Height
;
5248 memcpy(&record
->RectData
.rectF
, rect
, sizeof(*rect
));
5250 METAFILE_WriteRecords(metafile
);