2 * Metafile driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "ntgdi_private.h"
28 #include "mfdrv/metafiledrv.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(metafile
);
33 static BOOL CDECL
MFDRV_CreateCompatibleDC( PHYSDEV orig
, PHYSDEV
*pdev
);
34 static BOOL CDECL
MFDRV_DeleteDC( PHYSDEV dev
);
37 /**********************************************************************
40 static INT CDECL
MFDRV_ExtEscape( PHYSDEV dev
, INT nEscape
, INT cbInput
, LPCVOID in_data
,
41 INT cbOutput
, LPVOID out_data
)
47 if (cbOutput
) return 0; /* escapes that require output cannot work in metafiles */
49 len
= sizeof(*mr
) + sizeof(WORD
) + ((cbInput
+ 1) & ~1);
50 mr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
52 mr
->rdFunction
= META_ESCAPE
;
53 mr
->rdParm
[0] = nEscape
;
54 mr
->rdParm
[1] = cbInput
;
55 memcpy(&(mr
->rdParm
[2]), in_data
, cbInput
);
56 ret
= MFDRV_WriteRecord( dev
, mr
, len
);
57 HeapFree(GetProcessHeap(), 0, mr
);
62 /******************************************************************
65 static UINT CDECL
MFDRV_GetBoundsRect( PHYSDEV dev
, RECT
*rect
, UINT flags
)
71 /******************************************************************
74 static UINT CDECL
MFDRV_SetBoundsRect( PHYSDEV dev
, RECT
*rect
, UINT flags
)
80 /******************************************************************
81 * METADC_GetDeviceCaps
83 *A very simple implementation that returns DT_METAFILE
85 INT
METADC_GetDeviceCaps( HDC hdc
, INT cap
)
87 if (!get_metadc_ptr( hdc
)) return 0;
96 TRACE(" unsupported capability %d, will return 0\n", cap
);
102 static const struct gdi_dc_funcs MFDRV_Funcs
=
104 NULL
, /* pAbortDoc */
105 MFDRV_AbortPath
, /* pAbortPath */
106 NULL
, /* pAlphaBlend */
107 NULL
, /* pAngleArc */
109 MFDRV_ArcTo
, /* pArcTo */
110 MFDRV_BeginPath
, /* pBeginPath */
111 NULL
, /* pBlendImage */
113 MFDRV_CloseFigure
, /* pCloseFigure */
114 MFDRV_CreateCompatibleDC
, /* pCreateCompatibleDC */
115 NULL
, /* pCreateDC */
116 MFDRV_DeleteDC
, /* pDeleteDC */
117 MFDRV_DeleteObject
, /* pDeleteObject */
118 NULL
, /* pDeviceCapabilities */
122 MFDRV_EndPath
, /* pEndPath */
123 NULL
, /* pEnumFonts */
124 NULL
, /* pEnumICMProfiles */
125 MFDRV_ExcludeClipRect
, /* pExcludeClipRect */
126 NULL
, /* pExtDeviceMode */
127 MFDRV_ExtEscape
, /* pExtEscape */
128 NULL
, /* pExtFloodFill */
129 MFDRV_ExtSelectClipRgn
, /* pExtSelectClipRgn */
130 NULL
, /* pExtTextOut */
131 MFDRV_FillPath
, /* pFillPath */
132 MFDRV_FillRgn
, /* pFillRgn */
133 MFDRV_FlattenPath
, /* pFlattenPath */
134 NULL
, /* pFontIsLinked */
135 NULL
, /* pFrameRgn */
136 NULL
, /* pGdiComment */
137 MFDRV_GetBoundsRect
, /* pGetBoundsRect */
138 NULL
, /* pGetCharABCWidths */
139 NULL
, /* pGetCharABCWidthsI */
140 NULL
, /* pGetCharWidth */
141 NULL
, /* pGetCharWidthInfo */
142 NULL
, /* pGetDeviceCaps */
143 NULL
, /* pGetDeviceGammaRamp */
144 NULL
, /* pGetFontData */
145 NULL
, /* pGetFontRealizationInfo */
146 NULL
, /* pGetFontUnicodeRanges */
147 NULL
, /* pGetGlyphIndices */
148 NULL
, /* pGetGlyphOutline */
149 NULL
, /* pGetICMProfile */
150 NULL
, /* pGetImage */
151 NULL
, /* pGetKerningPairs */
152 NULL
, /* pGetNearestColor */
153 NULL
, /* pGetOutlineTextMetrics */
154 NULL
, /* pGetPixel */
155 NULL
, /* pGetSystemPaletteEntries */
156 NULL
, /* pGetTextCharsetInfo */
157 NULL
, /* pGetTextExtentExPoint */
158 NULL
, /* pGetTextExtentExPointI */
159 NULL
, /* pGetTextFace */
160 NULL
, /* pGetTextMetrics */
161 NULL
, /* pGradientFill */
162 NULL
, /* pIntersectClipRect */
163 NULL
, /* pInvertRgn */
165 NULL
, /* pModifyWorldTransform */
167 NULL
, /* pOffsetClipRgn */
168 MFDRV_OffsetViewportOrgEx
, /* pOffsetViewportOrgEx */
169 MFDRV_OffsetWindowOrgEx
, /* pOffsetWindowOrgEx */
170 NULL
, /* pPaintRgn */
173 MFDRV_PolyBezier
, /* pPolyBezier */
174 MFDRV_PolyBezierTo
, /* pPolyBezierTo */
175 NULL
, /* pPolyDraw */
176 NULL
, /* pPolyPolygon */
177 NULL
, /* pPolyPolyline */
178 NULL
, /* pPolylineTo */
179 NULL
, /* pPutImage */
180 NULL
, /* pRealizeDefaultPalette */
181 MFDRV_RealizePalette
, /* pRealizePalette */
182 NULL
, /* pRectangle */
184 MFDRV_RestoreDC
, /* pRestoreDC */
185 NULL
, /* pRoundRect */
186 MFDRV_ScaleViewportExtEx
, /* pScaleViewportExtEx */
187 MFDRV_ScaleWindowExtEx
, /* pScaleWindowExtEx */
188 MFDRV_SelectBitmap
, /* pSelectBitmap */
189 MFDRV_SelectBrush
, /* pSelectBrush */
190 MFDRV_SelectClipPath
, /* pSelectClipPath */
191 MFDRV_SelectFont
, /* pSelectFont */
192 MFDRV_SelectPalette
, /* pSelectPalette */
193 MFDRV_SelectPen
, /* pSelectPen */
194 MFDRV_SetBkColor
, /* pSetBkColor */
195 MFDRV_SetBoundsRect
, /* pSetBoundsRect */
196 MFDRV_SetDCBrushColor
, /* pSetDCBrushColor*/
197 MFDRV_SetDCPenColor
, /* pSetDCPenColor*/
198 MFDRV_SetDIBitsToDevice
, /* pSetDIBitsToDevice */
199 NULL
, /* pSetDeviceClipping */
200 NULL
, /* pSetDeviceGammaRamp */
201 MFDRV_SetLayout
, /* pSetLayout */
202 MFDRV_SetMapMode
, /* pSetMapMode */
203 MFDRV_SetMapperFlags
, /* pSetMapperFlags */
204 NULL
, /* pSetPixel */
205 MFDRV_SetTextCharacterExtra
, /* pSetTextCharacterExtra */
206 MFDRV_SetTextColor
, /* pSetTextColor */
207 MFDRV_SetTextJustification
, /* pSetTextJustification */
208 MFDRV_SetViewportExtEx
, /* pSetViewportExtEx */
209 MFDRV_SetViewportOrgEx
, /* pSetViewportOrgEx */
210 MFDRV_SetWindowExtEx
, /* pSetWindowExtEx */
211 MFDRV_SetWindowOrgEx
, /* pSetWindowOrgEx */
212 NULL
, /* pSetWorldTransform */
213 NULL
, /* pStartDoc */
214 NULL
, /* pStartPage */
215 MFDRV_StretchBlt
, /* pStretchBlt */
216 MFDRV_StretchDIBits
, /* pStretchDIBits */
217 MFDRV_StrokeAndFillPath
, /* pStrokeAndFillPath */
218 MFDRV_StrokePath
, /* pStrokePath */
219 NULL
, /* pUnrealizePalette */
220 MFDRV_WidenPath
, /* pWidenPath */
221 NULL
, /* pD3DKMTCheckVidPnExclusiveOwnership */
222 NULL
, /* pD3DKMTSetVidPnSourceOwner */
223 NULL
, /* wine_get_wgl_driver */
224 NULL
, /* wine_get_vulkan_driver */
225 GDI_PRIORITY_GRAPHICS_DRV
/* priority */
230 /**********************************************************************
231 * MFDRV_AllocMetaFile
233 static DC
*MFDRV_AllocMetaFile(void)
236 METAFILEDRV_PDEVICE
*physDev
;
238 if (!(dc
= alloc_dc_ptr( NTGDI_OBJ_METADC
))) return NULL
;
240 physDev
= HeapAlloc(GetProcessHeap(),0,sizeof(*physDev
));
246 if (!(physDev
->mh
= HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev
->mh
) )))
248 HeapFree( GetProcessHeap(), 0, physDev
);
253 push_dc_driver( &dc
->physDev
, &physDev
->dev
, &MFDRV_Funcs
);
254 set_gdi_client_ptr( dc
->hSelf
, physDev
);
256 physDev
->handles
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, HANDLE_LIST_INC
* sizeof(physDev
->handles
[0]));
257 physDev
->handles_size
= HANDLE_LIST_INC
;
258 physDev
->cur_handles
= 0;
262 physDev
->mh
->mtHeaderSize
= sizeof(METAHEADER
) / sizeof(WORD
);
263 physDev
->mh
->mtVersion
= 0x0300;
264 physDev
->mh
->mtSize
= physDev
->mh
->mtHeaderSize
;
265 physDev
->mh
->mtNoObjects
= 0;
266 physDev
->mh
->mtMaxRecord
= 0;
267 physDev
->mh
->mtNoParameters
= 0;
269 SetVirtualResolution( physDev
->dev
.hdc
, 0, 0, 0, 0);
275 /**********************************************************************
276 * MFDRV_CreateCompatibleDC
278 static BOOL CDECL
MFDRV_CreateCompatibleDC( PHYSDEV orig
, PHYSDEV
*pdev
)
280 /* not supported on metafile DCs */
285 /**********************************************************************
288 static BOOL CDECL
MFDRV_DeleteDC( PHYSDEV dev
)
290 METAFILEDRV_PDEVICE
*physDev
= (METAFILEDRV_PDEVICE
*)dev
;
293 HeapFree( GetProcessHeap(), 0, physDev
->mh
);
294 for(index
= 0; index
< physDev
->handles_size
; index
++)
295 if(physDev
->handles
[index
])
296 GDI_hdc_not_using_object(physDev
->handles
[index
], dev
->hdc
);
297 HeapFree( GetProcessHeap(), 0, physDev
->handles
);
298 HeapFree( GetProcessHeap(), 0, physDev
);
303 /**********************************************************************
304 * CreateMetaFileW (GDI32.@)
306 * Create a new DC and associate it with a metafile. Pass a filename
307 * to create a disk-based metafile, NULL to create a memory metafile.
310 * filename [I] Filename of disk metafile
313 * A handle to the metafile DC if successful, NULL on failure.
315 HDC WINAPI
CreateMetaFileW( LPCWSTR filename
)
319 METAFILEDRV_PDEVICE
*physDev
;
322 TRACE("%s\n", debugstr_w(filename
) );
324 if (!(dc
= MFDRV_AllocMetaFile())) return 0;
325 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
326 physDev
->mh
->mtType
= METAFILE_MEMORY
;
328 if (filename
) /* disk based metafile */
330 if ((hFile
= CreateFileW(filename
, GENERIC_WRITE
, 0, NULL
,
331 CREATE_ALWAYS
, 0, 0)) == INVALID_HANDLE_VALUE
) {
335 physDev
->hFile
= hFile
;
338 TRACE("returning %p\n", physDev
->dev
.hdc
);
339 ret
= physDev
->dev
.hdc
;
340 release_dc_ptr( dc
);
344 /**********************************************************************
345 * CreateMetaFileA (GDI32.@)
347 * See CreateMetaFileW.
349 HDC WINAPI
CreateMetaFileA(LPCSTR filename
)
355 if (!filename
) return CreateMetaFileW(NULL
);
357 len
= MultiByteToWideChar( CP_ACP
, 0, filename
, -1, NULL
, 0 );
358 filenameW
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
359 MultiByteToWideChar( CP_ACP
, 0, filename
, -1, filenameW
, len
);
361 hReturnDC
= CreateMetaFileW(filenameW
);
363 HeapFree( GetProcessHeap(), 0, filenameW
);
369 /**********************************************************************
370 * MFDRV_CloseMetaFile
372 static DC
*MFDRV_CloseMetaFile( HDC hdc
)
375 METAFILEDRV_PDEVICE
*physDev
;
378 TRACE("(%p)\n", hdc
);
380 if (!(dc
= get_dc_ptr( hdc
))) return NULL
;
381 if (GetObjectType( hdc
) != OBJ_METADC
)
383 release_dc_ptr( dc
);
386 if (dc
->refcount
!= 1)
388 FIXME( "not deleting busy DC %p refcount %u\n", hdc
, dc
->refcount
);
389 release_dc_ptr( dc
);
392 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
394 /* Construct the end of metafile record - this is documented
395 * in SDK Knowledgebase Q99334.
398 if (!MFDRV_MetaParam0(dc
->physDev
, META_EOF
))
404 if (physDev
->hFile
) /* disk based metafile */
406 if (!WriteFile(physDev
->hFile
, physDev
->mh
, physDev
->mh
->mtSize
* 2,
407 &bytes_written
, NULL
)) {
411 CloseHandle(physDev
->hFile
);
417 /******************************************************************
418 * CloseMetaFile (GDI32.@)
420 * Stop recording graphics operations in metafile associated with
421 * hdc and retrieve metafile.
424 * hdc [I] Metafile DC to close
427 * Handle of newly created metafile on success, NULL on failure.
429 HMETAFILE WINAPI
CloseMetaFile(HDC hdc
)
432 METAFILEDRV_PDEVICE
*physDev
;
433 DC
*dc
= MFDRV_CloseMetaFile(hdc
);
435 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
437 /* Now allocate a global handle for the metafile */
439 hmf
= MF_Create_HMETAFILE( physDev
->mh
);
441 physDev
->mh
= NULL
; /* So it won't be deleted */
447 /******************************************************************
450 * Warning: this function can change the pointer to the metafile header.
452 BOOL
MFDRV_WriteRecord( PHYSDEV dev
, METARECORD
*mr
, DWORD rlen
)
456 METAFILEDRV_PDEVICE
*physDev
= (METAFILEDRV_PDEVICE
*)dev
;
458 len
= physDev
->mh
->mtSize
* 2 + rlen
;
459 /* reallocate memory if needed */
460 size
= HeapSize( GetProcessHeap(), 0, physDev
->mh
);
464 size
+= size
/ 2 + rlen
;
465 mh
= HeapReAlloc( GetProcessHeap(), 0, physDev
->mh
, size
);
466 if (!mh
) return FALSE
;
468 TRACE("Reallocated metafile: new size is %d\n",size
);
470 memcpy((WORD
*)physDev
->mh
+ physDev
->mh
->mtSize
, mr
, rlen
);
472 physDev
->mh
->mtSize
+= rlen
/ 2;
473 physDev
->mh
->mtMaxRecord
= max(physDev
->mh
->mtMaxRecord
, rlen
/ 2);
478 /******************************************************************
482 BOOL
MFDRV_MetaParam0(PHYSDEV dev
, short func
)
485 METARECORD
*mr
= (METARECORD
*)&buffer
;
488 mr
->rdFunction
= func
;
489 return MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2);
493 /******************************************************************
496 BOOL
MFDRV_MetaParam1(PHYSDEV dev
, short func
, short param1
)
499 METARECORD
*mr
= (METARECORD
*)&buffer
;
500 WORD
*params
= mr
->rdParm
;
503 mr
->rdFunction
= func
;
505 return MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2);
509 /******************************************************************
512 BOOL
MFDRV_MetaParam2(PHYSDEV dev
, short func
, short param1
, short param2
)
515 METARECORD
*mr
= (METARECORD
*)&buffer
;
516 WORD
*params
= mr
->rdParm
;
519 mr
->rdFunction
= func
;
522 return MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2);
526 /******************************************************************
530 BOOL
MFDRV_MetaParam4(PHYSDEV dev
, short func
, short param1
, short param2
,
531 short param3
, short param4
)
534 METARECORD
*mr
= (METARECORD
*)&buffer
;
535 WORD
*params
= mr
->rdParm
;
538 mr
->rdFunction
= func
;
543 return MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2);
547 /******************************************************************
551 BOOL
MFDRV_MetaParam6(PHYSDEV dev
, short func
, short param1
, short param2
,
552 short param3
, short param4
, short param5
, short param6
)
555 METARECORD
*mr
= (METARECORD
*)&buffer
;
556 WORD
*params
= mr
->rdParm
;
559 mr
->rdFunction
= func
;
566 return MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2);
570 /******************************************************************
573 BOOL
MFDRV_MetaParam8(PHYSDEV dev
, short func
, short param1
, short param2
,
574 short param3
, short param4
, short param5
,
575 short param6
, short param7
, short param8
)
578 METARECORD
*mr
= (METARECORD
*)&buffer
;
579 WORD
*params
= mr
->rdParm
;
582 mr
->rdFunction
= func
;
591 return MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2);
594 METAFILEDRV_PDEVICE
*get_metadc_ptr( HDC hdc
)
596 METAFILEDRV_PDEVICE
*metafile
= get_gdi_client_ptr( hdc
, NTGDI_OBJ_METADC
);
597 if (!metafile
) SetLastError( ERROR_INVALID_HANDLE
);
601 BOOL
metadc_record( HDC hdc
, METARECORD
*mr
, DWORD rlen
)
603 METAFILEDRV_PDEVICE
*dev
;
605 if (!(dev
= get_metadc_ptr( hdc
))) return FALSE
;
606 return MFDRV_WriteRecord( &dev
->dev
, mr
, rlen
);
609 BOOL
metadc_param1( HDC hdc
, short func
, short param
)
611 METAFILEDRV_PDEVICE
*dev
;
613 if (!(dev
= get_metadc_ptr( hdc
))) return FALSE
;
614 return MFDRV_MetaParam1( &dev
->dev
, func
, param
);
617 BOOL
metadc_param0( HDC hdc
, short func
)
619 METAFILEDRV_PDEVICE
*dev
;
621 if (!(dev
= get_metadc_ptr( hdc
))) return FALSE
;
622 return MFDRV_MetaParam0( &dev
->dev
, func
);
625 BOOL
metadc_param2( HDC hdc
, short func
, short param1
, short param2
)
627 METAFILEDRV_PDEVICE
*dev
;
629 if (!(dev
= get_metadc_ptr( hdc
))) return FALSE
;
630 return MFDRV_MetaParam2( &dev
->dev
, func
, param1
, param2
);
633 BOOL
metadc_param4( HDC hdc
, short func
, short param1
, short param2
,
634 short param3
, short param4
)
636 METAFILEDRV_PDEVICE
*dev
;
638 if (!(dev
= get_metadc_ptr( hdc
))) return FALSE
;
639 return MFDRV_MetaParam4( &dev
->dev
, func
, param1
, param2
, param3
, param4
);
642 BOOL
metadc_param5( HDC hdc
, short func
, short param1
, short param2
,
643 short param3
, short param4
, short param5
)
645 char buffer
[FIELD_OFFSET(METARECORD
, rdParm
[5])];
646 METARECORD
*mr
= (METARECORD
*)&buffer
;
648 mr
->rdSize
= sizeof(buffer
) / sizeof(WORD
);
649 mr
->rdFunction
= func
;
650 mr
->rdParm
[0] = param5
;
651 mr
->rdParm
[1] = param4
;
652 mr
->rdParm
[2] = param3
;
653 mr
->rdParm
[3] = param2
;
654 mr
->rdParm
[4] = param1
;
655 return metadc_record( hdc
, mr
, sizeof(buffer
) );
658 BOOL
metadc_param6( HDC hdc
, short func
, short param1
, short param2
,
659 short param3
, short param4
, short param5
,
662 METAFILEDRV_PDEVICE
*dev
;
664 if (!(dev
= get_metadc_ptr( hdc
))) return FALSE
;
665 return MFDRV_MetaParam6( &dev
->dev
, func
, param1
, param2
, param3
,
666 param4
, param5
, param6
);
669 BOOL
metadc_param8( HDC hdc
, short func
, short param1
, short param2
,
670 short param3
, short param4
, short param5
,
671 short param6
, short param7
, short param8
)
673 METAFILEDRV_PDEVICE
*dev
;
675 if (!(dev
= get_metadc_ptr( hdc
))) return FALSE
;
676 return MFDRV_MetaParam8( &dev
->dev
, func
, param1
, param2
, param3
,
677 param4
, param5
, param6
, param7
, param8
);