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 */
23 MFDRV_DeleteDC
, /* pDeleteDC */
24 NULL
, /* pDeleteObject */
27 NULL
, /* pExcludeClipRect */
28 NULL
, /* pExcludeVisRect */
29 NULL
, /* pExtFloodFill */
30 NULL
, /* pExtTextOut */
32 NULL
, /* pFloodFill */
34 NULL
, /* pGetTextExtentPoint */
35 NULL
, /* pGetTextMetrics */
36 NULL
, /* pIntersectClipRect */
37 NULL
, /* pIntersectVisRect */
38 NULL
, /* pInvertRgn */
41 NULL
, /* pOffsetClipRgn */
42 MFDRV_OffsetViewportOrg
, /* pOffsetViewportOrg */
43 MFDRV_OffsetWindowOrg
, /* pOffsetWindowOrg */
45 MFDRV_PatBlt
, /* pPatBlt */
47 NULL
, /* pPolyPolygon */
50 NULL
, /* pRealizePalette */
51 NULL
, /* pRectangle */
52 NULL
, /* pRestoreDC */
53 NULL
, /* pRoundRect */
55 MFDRV_ScaleViewportExt
, /* pScaleViewportExt */
56 MFDRV_ScaleWindowExt
, /* pScaleWindowExt */
57 NULL
, /* pSelectClipRgn */
58 NULL
, /* pSelectObject */
59 NULL
, /* pSelectPalette */
60 NULL
, /* pSetBkColor */
61 NULL
, /* pSetBkMode */
62 NULL
, /* pSetDeviceClipping */
63 NULL
, /* pSetDIBitsToDevice */
64 MFDRV_SetMapMode
, /* pSetMapMode */
65 NULL
, /* pSetMapperFlags */
67 NULL
, /* pSetPolyFillMode */
69 NULL
, /* pSetRelAbs */
70 NULL
, /* pSetStretchBltMode */
71 NULL
, /* pSetTextAlign */
72 NULL
, /* pSetTextCharacterExtra */
73 NULL
, /* 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 */
86 /**********************************************************************
89 static DC
*MFDRV_AllocMetaFile(void)
92 METAFILEDRV_PDEVICE
*physDev
;
94 if (!(dc
= DC_AllocDC( &MFDRV_Funcs
))) return NULL
;
95 dc
->header
.wMagic
= METAFILE_DC_MAGIC
;
97 physDev
= (METAFILEDRV_PDEVICE
*)HeapAlloc(SystemHeap
,0,sizeof(*physDev
));
100 GDI_HEAP_FREE( dc
->hSelf
);
103 dc
->physDev
= physDev
;
105 if (!(physDev
->mh
= HeapAlloc( SystemHeap
, 0, sizeof(*physDev
->mh
) )))
107 HeapFree( SystemHeap
, 0, physDev
);
108 GDI_HEAP_FREE( dc
->hSelf
);
112 physDev
->nextHandle
= 0;
114 physDev
->mh
->mtHeaderSize
= sizeof(METAHEADER
) / sizeof(WORD
);
115 physDev
->mh
->mtVersion
= 0x0300;
116 physDev
->mh
->mtSize
= physDev
->mh
->mtHeaderSize
;
117 physDev
->mh
->mtNoObjects
= 0;
118 physDev
->mh
->mtMaxRecord
= 0;
119 physDev
->mh
->mtNoParameters
= 0;
121 /* DC_InitDC( dc ); */
126 /**********************************************************************
129 static BOOL32
MFDRV_DeleteDC( DC
*dc
)
131 METAFILEDRV_PDEVICE
*physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
133 if (physDev
->mh
) HeapFree( SystemHeap
, 0, physDev
->mh
);
134 HeapFree( SystemHeap
, 0, physDev
);
140 /**********************************************************************
141 * CreateMetafile16 (GDI.125)
143 HDC16
CreateMetaFile16( LPCSTR filename
)
146 METAFILEDRV_PDEVICE
*physDev
;
149 dprintf_metafile( stddeb
, "CreateMetaFile16: '%s'\n", filename
);
151 if (!(dc
= MFDRV_AllocMetaFile())) return 0;
152 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
154 if (filename
) /* disk based metafile */
156 physDev
->mh
->mtType
= METAFILE_DISK
;
157 if ((hFile
= _lcreat( filename
, 0 )) == HFILE_ERROR
)
159 DeleteDC32( dc
->hSelf
);
162 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
163 sizeof(*physDev
->mh
)) == HFILE_ERROR
)
165 DeleteDC32( dc
->hSelf
);
168 physDev
->mh
->mtNoParameters
= hFile
; /* store file descriptor here */
169 /* windows probably uses this too*/
171 else /* memory based metafile */
172 physDev
->mh
->mtType
= METAFILE_MEMORY
;
174 dprintf_metafile( stddeb
, "CreateMetaFile16: returning %04x\n", dc
->hSelf
);
179 /******************************************************************
180 * CloseMetafile16 (GDI.126)
182 HMETAFILE16
CloseMetaFile16( HDC16 hdc
)
187 METAFILEDRV_PDEVICE
*physDev
;
189 dprintf_metafile( stddeb
, "CloseMetaFile(%04x)\n", hdc
);
191 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
192 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
194 /* Construct the end of metafile record - this is documented
195 * in SDK Knowledgebase Q99334.
198 if (!MF_MetaParam0(dc
, META_EOF
))
204 if (physDev
->mh
->mtType
== METAFILE_DISK
) /* disk based metafile */
206 hFile
= physDev
->mh
->mtNoParameters
;
207 physDev
->mh
->mtNoParameters
= 0;
208 if (_llseek(hFile
, 0L, 0) == HFILE_ERROR
)
213 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
214 sizeof(*physDev
->mh
)) == HFILE_ERROR
)
222 /* Now allocate a global handle for the metafile */
224 hmf
= GLOBAL_CreateBlock( GMEM_MOVEABLE
, physDev
->mh
,
225 physDev
->mh
->mtSize
* sizeof(WORD
),
226 GetCurrentPDB(), FALSE
, FALSE
, FALSE
, NULL
);
227 physDev
->mh
= NULL
; /* So it won't be deleted */
233 /******************************************************************
234 * DeleteMetafile16 (GDI.127)
236 BOOL16
DeleteMetaFile16( HMETAFILE16 hmf
)
238 return !GlobalFree16( hmf
);