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 */
27 NULL
, /* pExcludeClipRect */
28 NULL
, /* pExcludeVisRect */
29 MFDRV_ExtFloodFill
, /* pExtFloodFill */
30 MFDRV_ExtTextOut
, /* pExtTextOut */
31 NULL
/* no implementation */, /* pGetPixel */
32 NULL
, /* pGetTextExtentPoint */
33 NULL
, /* pGetTextMetrics */
34 NULL
, /* pIntersectClipRect */
35 NULL
, /* pIntersectVisRect */
36 MFDRV_LineTo
, /* pLineTo */
37 MFDRV_MoveToEx
, /* pMoveToEx */
38 NULL
, /* pOffsetClipRgn */
39 MFDRV_OffsetViewportOrg
, /* pOffsetViewportOrg */
40 MFDRV_OffsetWindowOrg
, /* pOffsetWindowOrg */
42 MFDRV_PatBlt
, /* pPatBlt */
44 MFDRV_PolyPolygon
, /* pPolyPolygon */
45 MFDRV_Polygon
, /* pPolygon */
46 MFDRV_Polyline
, /* pPolyline */
47 NULL
, /* pRealizePalette */
48 MFDRV_Rectangle
, /* pRectangle */
49 NULL
, /* pRestoreDC */
50 MFDRV_RoundRect
, /* pRoundRect */
52 MFDRV_ScaleViewportExt
, /* pScaleViewportExt */
53 MFDRV_ScaleWindowExt
, /* pScaleWindowExt */
54 NULL
, /* pSelectClipRgn */
55 NULL
, /* pSelectObject */
56 NULL
, /* pSelectPalette */
57 NULL
, /* pSetBkColor */
58 NULL
, /* pSetBkMode */
59 NULL
, /* pSetDeviceClipping */
60 NULL
, /* pSetDIBitsToDevice */
61 MFDRV_SetMapMode
, /* pSetMapMode */
62 NULL
, /* pSetMapperFlags */
63 MFDRV_SetPixel
, /* pSetPixel */
64 NULL
, /* pSetPolyFillMode */
66 NULL
, /* pSetRelAbs */
67 NULL
, /* pSetStretchBltMode */
68 NULL
, /* pSetTextAlign */
69 NULL
, /* pSetTextCharacterExtra */
70 NULL
, /* pSetTextColor */
71 NULL
, /* pSetTextJustification */
72 MFDRV_SetViewportExt
, /* pSetViewportExt */
73 MFDRV_SetViewportOrg
, /* pSetViewportOrg */
74 MFDRV_SetWindowExt
, /* pSetWindowExt */
75 MFDRV_SetWindowOrg
, /* pSetWindowOrg */
76 MFDRV_StretchBlt
, /* pStretchBlt */
77 NULL
/* pStretchDIBits */
82 /**********************************************************************
85 static DC
*MFDRV_AllocMetaFile(void)
88 METAFILEDRV_PDEVICE
*physDev
;
90 if (!(dc
= DC_AllocDC( &MFDRV_Funcs
))) return NULL
;
91 dc
->header
.wMagic
= METAFILE_DC_MAGIC
;
93 physDev
= (METAFILEDRV_PDEVICE
*)HeapAlloc(SystemHeap
,0,sizeof(*physDev
));
96 GDI_HEAP_FREE( dc
->hSelf
);
99 dc
->physDev
= physDev
;
101 if (!(physDev
->mh
= HeapAlloc( SystemHeap
, 0, sizeof(*physDev
->mh
) )))
103 HeapFree( SystemHeap
, 0, physDev
);
104 GDI_HEAP_FREE( dc
->hSelf
);
108 physDev
->nextHandle
= 0;
110 physDev
->mh
->mtHeaderSize
= sizeof(METAHEADER
) / sizeof(WORD
);
111 physDev
->mh
->mtVersion
= 0x0300;
112 physDev
->mh
->mtSize
= physDev
->mh
->mtHeaderSize
;
113 physDev
->mh
->mtNoObjects
= 0;
114 physDev
->mh
->mtMaxRecord
= 0;
115 physDev
->mh
->mtNoParameters
= 0;
117 /* DC_InitDC( dc ); */
122 /**********************************************************************
125 static BOOL32
MFDRV_DeleteDC( DC
*dc
)
127 METAFILEDRV_PDEVICE
*physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
129 if (physDev
->mh
) HeapFree( SystemHeap
, 0, physDev
->mh
);
130 HeapFree( SystemHeap
, 0, physDev
);
136 /**********************************************************************
137 * CreateMetafile16 (GDI.125)
139 HDC16
CreateMetaFile16( LPCSTR filename
)
142 METAFILEDRV_PDEVICE
*physDev
;
145 dprintf_metafile( stddeb
, "CreateMetaFile16: '%s'\n", filename
);
147 if (!(dc
= MFDRV_AllocMetaFile())) return 0;
148 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
150 if (filename
) /* disk based metafile */
152 physDev
->mh
->mtType
= METAFILE_DISK
;
153 if ((hFile
= _lcreat32( filename
, 0 )) == HFILE_ERROR32
)
155 DeleteDC32( dc
->hSelf
);
158 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
159 sizeof(*physDev
->mh
)) == HFILE_ERROR32
)
161 DeleteDC32( dc
->hSelf
);
164 physDev
->mh
->mtNoParameters
= hFile
; /* store file descriptor here */
165 /* windows probably uses this too*/
167 else /* memory based metafile */
168 physDev
->mh
->mtType
= METAFILE_MEMORY
;
170 dprintf_metafile( stddeb
, "CreateMetaFile16: returning %04x\n", dc
->hSelf
);
175 /******************************************************************
176 * CloseMetafile16 (GDI.126)
178 HMETAFILE16
CloseMetaFile16( HDC16 hdc
)
183 METAFILEDRV_PDEVICE
*physDev
;
185 dprintf_metafile( stddeb
, "CloseMetaFile(%04x)\n", hdc
);
187 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
188 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
190 /* Construct the end of metafile record - this is documented
191 * in SDK Knowledgebase Q99334.
194 if (!MF_MetaParam0(dc
, META_EOF
))
200 if (physDev
->mh
->mtType
== METAFILE_DISK
) /* disk based metafile */
202 hFile
= physDev
->mh
->mtNoParameters
;
203 physDev
->mh
->mtNoParameters
= 0;
204 if (_llseek32(hFile
, 0L, 0) == HFILE_ERROR32
)
209 if (_lwrite32( hFile
, (LPSTR
)physDev
->mh
,
210 sizeof(*physDev
->mh
)) == HFILE_ERROR32
)
218 /* Now allocate a global handle for the metafile */
220 hmf
= GLOBAL_CreateBlock( GMEM_MOVEABLE
, physDev
->mh
,
221 physDev
->mh
->mtSize
* sizeof(WORD
),
222 GetCurrentPDB(), FALSE
, FALSE
, FALSE
, NULL
);
223 physDev
->mh
= NULL
; /* So it won't be deleted */
229 /******************************************************************
230 * DeleteMetafile16 (GDI.127)
232 BOOL16
DeleteMetaFile16( HMETAFILE16 hmf
)
234 return !GlobalFree16( hmf
);