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
, /* pPolyBezier */
50 NULL
, /* pRealizePalette */
51 MFDRV_Rectangle
, /* pRectangle */
52 NULL
, /* pRestoreDC */
53 MFDRV_RoundRect
, /* pRoundRect */
55 MFDRV_ScaleViewportExt
, /* pScaleViewportExt */
56 MFDRV_ScaleWindowExt
, /* pScaleWindowExt */
57 NULL
, /* pSelectClipRgn */
58 MFDRV_SelectObject
, /* pSelectObject */
59 NULL
, /* pSelectPalette */
60 MFDRV_SetBkColor
, /* pSetBkColor */
61 NULL
, /* pSetBkMode */
62 NULL
, /* pSetDeviceClipping */
63 NULL
, /* pSetDIBitsToDevice */
64 MFDRV_SetMapMode
, /* pSetMapMode */
65 NULL
, /* pSetMapperFlags */
66 MFDRV_SetPixel
, /* pSetPixel */
67 NULL
, /* pSetPolyFillMode */
69 NULL
, /* pSetRelAbs */
70 NULL
, /* pSetStretchBltMode */
71 NULL
, /* pSetTextAlign */
72 NULL
, /* pSetTextCharacterExtra */
73 MFDRV_SetTextColor
, /* pSetTextColor */
74 NULL
, /* pSetTextJustification */
75 MFDRV_SetViewportExt
, /* pSetViewportExt */
76 MFDRV_SetViewportOrg
, /* pSetViewportOrg */
77 MFDRV_SetWindowExt
, /* pSetWindowExt */
78 MFDRV_SetWindowOrg
, /* pSetWindowOrg */
79 MFDRV_StretchBlt
, /* pStretchBlt */
80 NULL
/* pStretchDIBits */
85 /**********************************************************************
88 static DC
*MFDRV_AllocMetaFile(void)
91 METAFILEDRV_PDEVICE
*physDev
;
93 if (!(dc
= DC_AllocDC( &MFDRV_Funcs
))) return NULL
;
94 dc
->header
.wMagic
= METAFILE_DC_MAGIC
;
96 physDev
= (METAFILEDRV_PDEVICE
*)HeapAlloc(SystemHeap
,0,sizeof(*physDev
));
99 GDI_HEAP_FREE( dc
->hSelf
);
102 dc
->physDev
= physDev
;
104 if (!(physDev
->mh
= HeapAlloc( SystemHeap
, 0, sizeof(*physDev
->mh
) )))
106 HeapFree( SystemHeap
, 0, physDev
);
107 GDI_HEAP_FREE( dc
->hSelf
);
111 physDev
->nextHandle
= 0;
113 physDev
->mh
->mtHeaderSize
= sizeof(METAHEADER
) / sizeof(WORD
);
114 physDev
->mh
->mtVersion
= 0x0300;
115 physDev
->mh
->mtSize
= physDev
->mh
->mtHeaderSize
;
116 physDev
->mh
->mtNoObjects
= 0;
117 physDev
->mh
->mtMaxRecord
= 0;
118 physDev
->mh
->mtNoParameters
= 0;
120 /* DC_InitDC( dc ); */
125 /**********************************************************************
128 static BOOL32
MFDRV_DeleteDC( DC
*dc
)
130 METAFILEDRV_PDEVICE
*physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
132 if (physDev
->mh
) HeapFree( SystemHeap
, 0, physDev
->mh
);
133 HeapFree( SystemHeap
, 0, physDev
);
135 GDI_FreeObject(dc
->hSelf
);
140 /**********************************************************************
141 * CreateMetaFile16 (GDI.125)
143 * Create a new DC and associate it with a metafile. Pass a filename
144 * to create a disk-based metafile, NULL to create a memory metafile.
147 * A handle to the metafile DC if successful, NULL on failure.
149 HDC16 WINAPI
CreateMetaFile16(
150 LPCSTR filename
/* Filename of disk metafile */
154 METAFILEDRV_PDEVICE
*physDev
;
157 TRACE(metafile
, "'%s'\n", filename
);
159 if (!(dc
= MFDRV_AllocMetaFile())) return 0;
160 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
162 if (filename
) /* disk based metafile */
164 physDev
->mh
->mtType
= METAFILE_DISK
;
165 if ((hFile
= _lcreat32( filename
, 0 )) == HFILE_ERROR32
)
167 MFDRV_DeleteDC( dc
);
170 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
171 sizeof(*physDev
->mh
)) == HFILE_ERROR32
)
173 MFDRV_DeleteDC( dc
);
176 physDev
->mh
->mtNoParameters
= hFile
; /* store file descriptor here */
177 /* windows probably uses this too*/
179 else /* memory based metafile */
180 physDev
->mh
->mtType
= METAFILE_MEMORY
;
182 TRACE(metafile
, "returning %04x\n", dc
->hSelf
);
186 /**********************************************************************
187 * CreateMetaFile32A (GDI32.51)
189 HDC32 WINAPI
CreateMetaFile32A(
190 LPCSTR filename
/* Filename of disk metafile */
193 return CreateMetaFile16( filename
);
196 static DC
*METAFILE_CloseMetaFile( HDC32 hdc
)
200 METAFILEDRV_PDEVICE
*physDev
;
202 TRACE(metafile
, "(%04x)\n", hdc
);
204 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, METAFILE_DC_MAGIC
))) return 0;
205 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
207 /* Construct the end of metafile record - this is documented
208 * in SDK Knowledgebase Q99334.
211 if (!MF_MetaParam0(dc
, META_EOF
))
213 MFDRV_DeleteDC( dc
);
217 if (physDev
->mh
->mtType
== METAFILE_DISK
) /* disk based metafile */
219 hFile
= physDev
->mh
->mtNoParameters
;
220 physDev
->mh
->mtNoParameters
= 0;
221 if (_llseek32(hFile
, 0L, 0) == HFILE_ERROR32
)
223 MFDRV_DeleteDC( dc
);
226 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
227 sizeof(*physDev
->mh
)) == HFILE_ERROR32
)
229 MFDRV_DeleteDC( dc
);
238 /******************************************************************
239 * CloseMetaFile16 (GDI.126)
241 HMETAFILE16 WINAPI
CloseMetaFile16(
242 HDC16 hdc
/* Metafile DC to close */
246 METAFILEDRV_PDEVICE
*physDev
;
247 DC
*dc
= METAFILE_CloseMetaFile(hdc
);
249 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
251 /* Now allocate a global handle for the metafile */
253 hmf
= GLOBAL_CreateBlock( GMEM_MOVEABLE
, physDev
->mh
,
254 physDev
->mh
->mtSize
* sizeof(WORD
),
255 GetCurrentPDB(), FALSE
, FALSE
, FALSE
, NULL
);
256 physDev
->mh
= NULL
; /* So it won't be deleted */
257 MFDRV_DeleteDC( dc
);
261 /******************************************************************
262 * CloseMetaFile32 (GDI32.17)
264 * Stop recording graphics operations in metafile associated with
265 * hdc and retrieve metafile.
268 * Handle of newly created metafile on success, NULL on failure.
270 HMETAFILE32 WINAPI
CloseMetaFile32(
271 HDC32 hdc
/* Metafile DC to close */
274 return CloseMetaFile16(hdc
);
278 /******************************************************************
279 * DeleteMetaFile16 (GDI.127)
281 BOOL16 WINAPI
DeleteMetaFile16(
283 /* Handle of memory metafile to delete */
286 return !GlobalFree16( hmf
);
289 /******************************************************************
290 * DeleteMetaFile32 (GDI32.69)
292 * Delete a memory-based metafile.
295 BOOL32 WINAPI
DeleteMetaFile32(
298 return !GlobalFree16( hmf
);
301 /********************************************************************
303 Enhanced Metafile driver initializations
305 This possibly should be moved to their own file/directory
308 **********************************************************************/
311 need wide version as well
313 HDC32 WINAPI
CreateEnhMetaFile32A(
314 HDC32 hdc
, /* optional reference DC */
315 LPCSTR filename
, /* optional filename for disk metafiles */
316 const RECT32
*rect
, /* optional bounding rectangle */
317 LPCSTR description
/* optional description */
322 METAFILEDRV_PDEVICE
*physDev
;
325 if (!(dc
= MFDRV_AllocMetaFile())) return 0;
326 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
328 if (filename
) /* disk based metafile */
330 physDev
->mh
->mtType
= METAFILE_DISK
;
331 if ((hFile
= _lcreat32( filename
, 0 )) == HFILE_ERROR32
)
333 MFDRV_DeleteDC( dc
);
336 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
337 sizeof(*physDev
->mh
)) == HFILE_ERROR32
)
339 MFDRV_DeleteDC( dc
);
342 physDev
->mh
->mtNoParameters
= hFile
; /* store file descriptor here */
343 /* windows probably uses this too*/
345 else /* memory based metafile */
346 physDev
->mh
->mtType
= METAFILE_MEMORY
;
348 TRACE(metafile
, "returning %04x\n", dc
->hSelf
);
354 HENHMETAFILE32 WINAPI
CloseEnhMetaFile32(
355 HDC32 hdc
/* metafile DC */
358 /* write EMR_EOF(0x0, 0x10, 0x14) */