2 * Metafile driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
7 #include "metafiledrv.h"
16 static const DC_FUNCTIONS MFDRV_Funcs
=
19 MFDRV_BitBlt
, /* pBitBlt */
20 MFDRV_Chord
, /* pChord */
21 NULL
, /* no implementation */ /* pCreateDC */
22 NULL
, /* no implementation */ /* pDeleteDC */
23 NULL
, /* pDeleteObject */
24 MFDRV_Ellipse
, /* pEllipse */
25 NULL
, /* pEnumDeviceFonts */
27 NULL
, /* pExcludeClipRect */
28 NULL
, /* pExcludeVisRect */
29 MFDRV_ExtFloodFill
, /* pExtFloodFill */
30 MFDRV_ExtTextOut
, /* pExtTextOut */
31 NULL
, /* pGetCharWidth */
32 NULL
, /* no implementation */ /* pGetPixel */
33 NULL
, /* pGetTextExtentPoint */
34 NULL
, /* pGetTextMetrics */
35 NULL
, /* pIntersectClipRect */
36 NULL
, /* pIntersectVisRect */
37 MFDRV_LineTo
, /* pLineTo */
38 MFDRV_MoveToEx
, /* pMoveToEx */
39 NULL
, /* pOffsetClipRgn */
40 MFDRV_OffsetViewportOrg
, /* pOffsetViewportOrg */
41 MFDRV_OffsetWindowOrg
, /* pOffsetWindowOrg */
42 MFDRV_PaintRgn
, /* pPaintRgn */
43 MFDRV_PatBlt
, /* pPatBlt */
45 MFDRV_PolyPolygon
, /* pPolyPolygon */
46 NULL
, /* pPolyPolyline */
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
);
134 GDI_FreeObject(dc
->hSelf
);
139 /**********************************************************************
140 * CreateMetaFile16 (GDI.125)
142 * Create a new DC and associate it with a metafile. Pass a filename
143 * to create a disk-based metafile, NULL to create a memory metafile.
146 * A handle to the metafile DC if successful, NULL on failure.
148 HDC16 WINAPI
CreateMetaFile16(
149 LPCSTR filename
/* Filename of disk metafile */
153 METAFILEDRV_PDEVICE
*physDev
;
156 TRACE(metafile
, "'%s'\n", filename
);
158 if (!(dc
= MFDRV_AllocMetaFile())) return 0;
159 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
161 if (filename
) /* disk based metafile */
163 physDev
->mh
->mtType
= METAFILE_DISK
;
164 if ((hFile
= _lcreat32( filename
, 0 )) == HFILE_ERROR32
)
166 MFDRV_DeleteDC( dc
);
169 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
170 sizeof(*physDev
->mh
)) == HFILE_ERROR32
)
172 MFDRV_DeleteDC( dc
);
175 physDev
->mh
->mtNoParameters
= hFile
; /* store file descriptor here */
176 /* windows probably uses this too*/
178 else /* memory based metafile */
179 physDev
->mh
->mtType
= METAFILE_MEMORY
;
181 TRACE(metafile
, "returning %04x\n", dc
->hSelf
);
185 /**********************************************************************
186 * CreateMetaFile32A (GDI32.51)
188 HDC32 WINAPI
CreateMetaFile32A(
189 LPCSTR filename
/* Filename of disk metafile */
192 return CreateMetaFile16( filename
);
195 static DC
*METAFILE_CloseMetaFile( HDC32 hdc
)
199 METAFILEDRV_PDEVICE
*physDev
;
201 TRACE(metafile
, "(%04x)\n", hdc
);
203 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, METAFILE_DC_MAGIC
))) return 0;
204 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
206 /* Construct the end of metafile record - this is documented
207 * in SDK Knowledgebase Q99334.
210 if (!MF_MetaParam0(dc
, META_EOF
))
212 MFDRV_DeleteDC( dc
);
216 if (physDev
->mh
->mtType
== METAFILE_DISK
) /* disk based metafile */
218 hFile
= physDev
->mh
->mtNoParameters
;
219 physDev
->mh
->mtNoParameters
= 0;
220 if (_llseek32(hFile
, 0L, 0) == HFILE_ERROR32
)
222 MFDRV_DeleteDC( dc
);
225 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
226 sizeof(*physDev
->mh
)) == HFILE_ERROR32
)
228 MFDRV_DeleteDC( dc
);
237 /******************************************************************
238 * CloseMetaFile16 (GDI.126)
240 HMETAFILE16 WINAPI
CloseMetaFile16(
241 HDC16 hdc
/* Metafile DC to close */
245 METAFILEDRV_PDEVICE
*physDev
;
246 DC
*dc
= METAFILE_CloseMetaFile(hdc
);
248 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
250 /* Now allocate a global handle for the metafile */
252 hmf
= GLOBAL_CreateBlock( GMEM_MOVEABLE
, physDev
->mh
,
253 physDev
->mh
->mtSize
* sizeof(WORD
),
254 GetCurrentPDB(), FALSE
, FALSE
, FALSE
, NULL
);
255 physDev
->mh
= NULL
; /* So it won't be deleted */
256 MFDRV_DeleteDC( dc
);
260 /******************************************************************
261 * CloseMetaFile32 (GDI32.17)
263 * Stop recording graphics operations in metafile associated with
264 * hdc and retrieve metafile.
267 * Handle of newly created metafile on success, NULL on failure.
269 HMETAFILE32 WINAPI
CloseMetaFile32(
270 HDC32 hdc
/* Metafile DC to close */
273 return CloseMetaFile32(hdc
);
277 /******************************************************************
278 * DeleteMetaFile16 (GDI.127)
280 BOOL16 WINAPI
DeleteMetaFile16(
282 /* Handle of memory metafile to delete */
285 return !GlobalFree16( hmf
);
288 /******************************************************************
289 * DeleteMetaFile32 (GDI32.69)
291 * Delete a memory-based metafile.
294 BOOL32 WINAPI
DeleteMetaFile32(
297 return !GlobalFree16( hmf
);
300 /********************************************************************
302 Enhanced Metafile driver initializations
304 This possibly should be moved to their own file/directory
307 **********************************************************************/
310 need wide version as well
312 HDC32
CreateEnhMetaFile32A(
313 HDC32 hdc
, /* optional reference DC */
314 LPCSTR filename
, /* optional filename for disk metafiles */
315 const RECT32
*rect
, /* optional bounding rectangle */
316 LPCSTR description
/* optional description */
321 METAFILEDRV_PDEVICE
*physDev
;
324 if (!(dc
= MFDRV_AllocMetaFile())) return 0;
325 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
327 if (filename
) /* disk based metafile */
329 physDev
->mh
->mtType
= METAFILE_DISK
;
330 if ((hFile
= _lcreat32( filename
, 0 )) == HFILE_ERROR32
)
332 MFDRV_DeleteDC( dc
);
335 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
336 sizeof(*physDev
->mh
)) == HFILE_ERROR32
)
338 MFDRV_DeleteDC( dc
);
341 physDev
->mh
->mtNoParameters
= hFile
; /* store file descriptor here */
342 /* windows probably uses this too*/
344 else /* memory based metafile */
345 physDev
->mh
->mtType
= METAFILE_MEMORY
;
347 TRACE(metafile
, "returning %04x\n", dc
->hSelf
);
353 HENHMETAFILE32
CloseEnhMetaFile32(
354 HDC32 hdc
/* metafile DC */
357 /* write EMR_EOF(0x0, 0x10, 0x14) */