2 * Metafile driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
7 #include "metafiledrv.h"
15 static BOOL32
MFDRV_DeleteDC( DC
*dc
);
17 static const DC_FUNCTIONS MFDRV_Funcs
=
20 MFDRV_BitBlt
, /* pBitBlt */
21 MFDRV_Chord
, /* pChord */
23 MFDRV_DeleteDC
, /* pDeleteDC */
24 NULL
, /* pDeleteObject */
25 MFDRV_Ellipse
, /* pEllipse */
26 NULL
, /* pEnumDeviceFonts */
28 NULL
, /* pExcludeClipRect */
29 NULL
, /* pExcludeVisRect */
30 MFDRV_ExtFloodFill
, /* pExtFloodFill */
31 MFDRV_ExtTextOut
, /* pExtTextOut */
32 NULL
, /* pGetCharWidth */
33 NULL
/* no implementation */, /* pGetPixel */
34 NULL
, /* pGetTextExtentPoint */
35 NULL
, /* pGetTextMetrics */
36 NULL
, /* pIntersectClipRect */
37 NULL
, /* pIntersectVisRect */
38 MFDRV_LineTo
, /* pLineTo */
39 MFDRV_MoveToEx
, /* pMoveToEx */
40 NULL
, /* pOffsetClipRgn */
41 MFDRV_OffsetViewportOrg
, /* pOffsetViewportOrg */
42 MFDRV_OffsetWindowOrg
, /* pOffsetWindowOrg */
44 MFDRV_PatBlt
, /* pPatBlt */
46 MFDRV_PolyPolygon
, /* pPolyPolygon */
47 MFDRV_Polygon
, /* pPolygon */
48 MFDRV_Polyline
, /* pPolyline */
49 NULL
, /* pRealizePalette */
50 MFDRV_Rectangle
, /* pRectangle */
51 NULL
, /* pRestoreDC */
52 MFDRV_RoundRect
, /* pRoundRect */
54 MFDRV_ScaleViewportExt
, /* pScaleViewportExt */
55 MFDRV_ScaleWindowExt
, /* pScaleWindowExt */
56 NULL
, /* pSelectClipRgn */
57 MFDRV_SelectObject
, /* pSelectObject */
58 NULL
, /* pSelectPalette */
59 NULL
, /* pSetBkColor */
60 NULL
, /* pSetBkMode */
61 NULL
, /* pSetDeviceClipping */
62 NULL
, /* pSetDIBitsToDevice */
63 MFDRV_SetMapMode
, /* pSetMapMode */
64 NULL
, /* pSetMapperFlags */
65 MFDRV_SetPixel
, /* pSetPixel */
66 NULL
, /* pSetPolyFillMode */
68 NULL
, /* pSetRelAbs */
69 NULL
, /* pSetStretchBltMode */
70 NULL
, /* pSetTextAlign */
71 NULL
, /* pSetTextCharacterExtra */
72 NULL
, /* pSetTextColor */
73 NULL
, /* pSetTextJustification */
74 MFDRV_SetViewportExt
, /* pSetViewportExt */
75 MFDRV_SetViewportOrg
, /* pSetViewportOrg */
76 MFDRV_SetWindowExt
, /* pSetWindowExt */
77 MFDRV_SetWindowOrg
, /* pSetWindowOrg */
78 MFDRV_StretchBlt
, /* pStretchBlt */
79 NULL
/* pStretchDIBits */
84 /**********************************************************************
87 static DC
*MFDRV_AllocMetaFile(void)
90 METAFILEDRV_PDEVICE
*physDev
;
92 if (!(dc
= DC_AllocDC( &MFDRV_Funcs
))) return NULL
;
93 dc
->header
.wMagic
= METAFILE_DC_MAGIC
;
95 physDev
= (METAFILEDRV_PDEVICE
*)HeapAlloc(SystemHeap
,0,sizeof(*physDev
));
98 GDI_HEAP_FREE( dc
->hSelf
);
101 dc
->physDev
= physDev
;
103 if (!(physDev
->mh
= HeapAlloc( SystemHeap
, 0, sizeof(*physDev
->mh
) )))
105 HeapFree( SystemHeap
, 0, physDev
);
106 GDI_HEAP_FREE( dc
->hSelf
);
110 physDev
->nextHandle
= 0;
112 physDev
->mh
->mtHeaderSize
= sizeof(METAHEADER
) / sizeof(WORD
);
113 physDev
->mh
->mtVersion
= 0x0300;
114 physDev
->mh
->mtSize
= physDev
->mh
->mtHeaderSize
;
115 physDev
->mh
->mtNoObjects
= 0;
116 physDev
->mh
->mtMaxRecord
= 0;
117 physDev
->mh
->mtNoParameters
= 0;
119 /* DC_InitDC( dc ); */
124 /**********************************************************************
127 static BOOL32
MFDRV_DeleteDC( DC
*dc
)
129 METAFILEDRV_PDEVICE
*physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
131 if (physDev
->mh
) HeapFree( SystemHeap
, 0, physDev
->mh
);
132 HeapFree( SystemHeap
, 0, physDev
);
138 /**********************************************************************
139 * CreateMetafile16 (GDI.125)
141 HDC16
CreateMetaFile16( LPCSTR filename
)
144 METAFILEDRV_PDEVICE
*physDev
;
147 dprintf_metafile( stddeb
, "CreateMetaFile16: '%s'\n", filename
);
149 if (!(dc
= MFDRV_AllocMetaFile())) return 0;
150 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
152 if (filename
) /* disk based metafile */
154 physDev
->mh
->mtType
= METAFILE_DISK
;
155 if ((hFile
= _lcreat32( filename
, 0 )) == HFILE_ERROR32
)
157 DeleteDC32( dc
->hSelf
);
160 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
161 sizeof(*physDev
->mh
)) == HFILE_ERROR32
)
163 DeleteDC32( dc
->hSelf
);
166 physDev
->mh
->mtNoParameters
= hFile
; /* store file descriptor here */
167 /* windows probably uses this too*/
169 else /* memory based metafile */
170 physDev
->mh
->mtType
= METAFILE_MEMORY
;
172 dprintf_metafile( stddeb
, "CreateMetaFile16: returning %04x\n", dc
->hSelf
);
177 /******************************************************************
178 * CloseMetafile16 (GDI.126)
180 HMETAFILE16
CloseMetaFile16( HDC16 hdc
)
185 METAFILEDRV_PDEVICE
*physDev
;
187 dprintf_metafile( stddeb
, "CloseMetaFile(%04x)\n", hdc
);
189 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
190 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
192 /* Construct the end of metafile record - this is documented
193 * in SDK Knowledgebase Q99334.
196 if (!MF_MetaParam0(dc
, META_EOF
))
202 if (physDev
->mh
->mtType
== METAFILE_DISK
) /* disk based metafile */
204 hFile
= physDev
->mh
->mtNoParameters
;
205 physDev
->mh
->mtNoParameters
= 0;
206 if (_llseek32(hFile
, 0L, 0) == HFILE_ERROR32
)
211 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
212 sizeof(*physDev
->mh
)) == HFILE_ERROR32
)
220 /* Now allocate a global handle for the metafile */
222 hmf
= GLOBAL_CreateBlock( GMEM_MOVEABLE
, physDev
->mh
,
223 physDev
->mh
->mtSize
* sizeof(WORD
),
224 GetCurrentPDB(), FALSE
, FALSE
, FALSE
, NULL
);
225 physDev
->mh
= NULL
; /* So it won't be deleted */
231 /******************************************************************
232 * DeleteMetafile16 (GDI.127)
234 BOOL16
DeleteMetaFile16( HMETAFILE16 hmf
)
236 return !GlobalFree16( hmf
);