1 /*
2 * Metafile driver initialisation functions
3 *
4 * Copyright 1996 Alexandre Julliard
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <stdarg.h>
22 #include <string.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winnls.h"
27 #include "gdi_private.h"
28 #include "mfdrv/metafiledrv.h"
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(metafile);
32
33 static const DC_FUNCTIONS MFDRV_Funcs =
34 {
35 NULL, /* pAbortDoc */
36 MFDRV_AbortPath, /* pAbortPath */
37 NULL, /* pAlphaBlend */
38 NULL, /* pAngleArc */
39 MFDRV_Arc, /* pArc */
40 NULL, /* pArcTo */
41 MFDRV_BeginPath, /* pBeginPath */
42 NULL, /* pBitBlt */
43 NULL, /* pChoosePixelFormat */
44 MFDRV_Chord, /* pChord */
45 MFDRV_CloseFigure, /* pCloseFigure */
46 NULL, /* pCreateBitmap */
47 NULL, /* pCreateDC */
48 NULL, /* pCreateDIBSection */
49 NULL, /* pDeleteBitmap */
50 NULL, /* pDeleteDC */
51 MFDRV_DeleteObject, /* pDeleteObject */
52 NULL, /* pDescribePixelFormat */
53 NULL, /* pDeviceCapabilities */
54 MFDRV_Ellipse, /* pEllipse */
55 NULL, /* pEndDoc */
56 NULL, /* pEndPage */
57 MFDRV_EndPath, /* pEndPath */
58 NULL, /* pEnumDeviceFonts */
59 MFDRV_ExcludeClipRect, /* pExcludeClipRect */
60 NULL, /* pExtDeviceMode */
61 MFDRV_ExtEscape, /* pExtEscape */
62 MFDRV_ExtFloodFill, /* pExtFloodFill */
63 MFDRV_ExtSelectClipRgn, /* pExtSelectClipRgn */
64 MFDRV_ExtTextOut, /* pExtTextOut */
65 MFDRV_FillPath, /* pFillPath */
66 MFDRV_FillRgn, /* pFillRgn */
67 MFDRV_FlattenPath, /* pFlattenPath */
68 MFDRV_FrameRgn, /* pFrameRgn */
69 NULL, /* pGdiComment */
70 NULL, /* pGetBitmapBits */
71 NULL, /* pGetCharWidth */
72 NULL, /* pGetDCOrgEx */
73 NULL, /* pGetDIBColorTable */
74 NULL, /* pGetDIBits */
75 MFDRV_GetDeviceCaps, /* pGetDeviceCaps */
76 NULL, /* pGetDeviceGammaRamp */
77 NULL, /* pGetICMProfile */
78 NULL, /* pGetNearestColor */
79 NULL, /* pGetPixel */
80 NULL, /* pGetPixelFormat */
81 NULL, /* pGetSystemPaletteEntries */
82 NULL, /* pGetTextExtentExPoint */
83 NULL, /* pGetTextMetrics */
84 MFDRV_IntersectClipRect, /* pIntersectClipRect */
85 MFDRV_InvertRgn, /* pInvertRgn */
86 MFDRV_LineTo, /* pLineTo */
87 NULL, /* pModifyWorldTransform */
88 MFDRV_MoveTo, /* pMoveTo */
89 MFDRV_OffsetClipRgn, /* pOffsetClipRgn */
90 MFDRV_OffsetViewportOrg, /* pOffsetViewportOrg */
91 MFDRV_OffsetWindowOrg, /* pOffsetWindowOrg */
92 MFDRV_PaintRgn, /* pPaintRgn */
93 MFDRV_PatBlt, /* pPatBlt */
94 MFDRV_Pie, /* pPie */
95 MFDRV_PolyBezier, /* pPolyBezier */
96 MFDRV_PolyBezierTo, /* pPolyBezierTo */
97 NULL, /* pPolyDraw */
98 MFDRV_PolyPolygon, /* pPolyPolygon */
99 NULL, /* pPolyPolyline */
100 MFDRV_Polygon, /* pPolygon */
101 MFDRV_Polyline, /* pPolyline */
102 NULL, /* pPolylineTo */
103 NULL, /* pRealizeDefaultPalette */
104 MFDRV_RealizePalette, /* pRealizePalette */
105 MFDRV_Rectangle, /* pRectangle */
106 NULL, /* pResetDC */
107 MFDRV_RestoreDC, /* pRestoreDC */
108 MFDRV_RoundRect, /* pRoundRect */
109 MFDRV_SaveDC, /* pSaveDC */
110 MFDRV_ScaleViewportExt, /* pScaleViewportExt */
111 MFDRV_ScaleWindowExt, /* pScaleWindowExt */
112 MFDRV_SelectBitmap, /* pSelectBitmap */
113 MFDRV_SelectBrush, /* pSelectBrush */
114 MFDRV_SelectClipPath, /* pSelectClipPath */
115 MFDRV_SelectFont, /* pSelectFont */
116 MFDRV_SelectPalette, /* pSelectPalette */
117 MFDRV_SelectPen, /* pSelectPen */
118 NULL, /* pSetArcDirection */
119 NULL, /* pSetBitmapBits */
120 MFDRV_SetBkColor, /* pSetBkColor */
121 MFDRV_SetBkMode, /* pSetBkMode */
122 NULL, /* pSetDCBrushColor*/
123 NULL, /* pSetDCPenColor*/
124 NULL, /* pSetDIBColorTable */
125 NULL, /* pSetDIBits */
126 MFDRV_SetDIBitsToDevice, /* pSetDIBitsToDevice */
127 NULL, /* pSetDeviceClipping */
128 NULL, /* pSetDeviceGammaRamp */
129 MFDRV_SetMapMode, /* pSetMapMode */
130 MFDRV_SetMapperFlags, /* pSetMapperFlags */
131 MFDRV_SetPixel, /* pSetPixel */
132 NULL, /* pSetPixelFormat */
133 MFDRV_SetPolyFillMode, /* pSetPolyFillMode */
134 MFDRV_SetROP2, /* pSetROP2 */
135 MFDRV_SetRelAbs, /* pSetRelAbs */
136 MFDRV_SetStretchBltMode, /* pSetStretchBltMode */
137 MFDRV_SetTextAlign, /* pSetTextAlign */
138 MFDRV_SetTextCharacterExtra, /* pSetTextCharacterExtra */
139 MFDRV_SetTextColor, /* pSetTextColor */
140 MFDRV_SetTextJustification, /* pSetTextJustification */
141 MFDRV_SetViewportExt, /* pSetViewportExt */
142 MFDRV_SetViewportOrg, /* pSetViewportOrg */
143 MFDRV_SetWindowExt, /* pSetWindowExt */
144 MFDRV_SetWindowOrg, /* pSetWindowOrg */
145 NULL, /* pSetWorldTransform */
146 NULL, /* pStartDoc */
147 NULL, /* pStartPage */
148 MFDRV_StretchBlt, /* pStretchBlt */
149 MFDRV_StretchDIBits, /* pStretchDIBits */
150 MFDRV_StrokeAndFillPath, /* pStrokeAndFillPath */
151 MFDRV_StrokePath, /* pStrokePath */
152 NULL, /* pSwapBuffers */
153 NULL, /* pUnrealizePalette */
154 MFDRV_WidenPath /* pWidenPath */
155 };
156
157
158
159 /**********************************************************************
160 * MFDRV_AllocMetaFile
161 */
162 static DC *MFDRV_AllocMetaFile(void)
163 {
164 DC *dc;
165 METAFILEDRV_PDEVICE *physDev;
166
167 if (!(dc = alloc_dc_ptr( &MFDRV_Funcs, OBJ_METADC ))) return NULL;
168
169 physDev = HeapAlloc(GetProcessHeap(),0,sizeof(*physDev));
170 if (!physDev)
171 {
172 free_dc_ptr( dc );
173 return NULL;
174 }
175 dc->physDev = (PHYSDEV)physDev;
176 physDev->hdc = dc->hSelf;
177
178 if (!(physDev->mh = HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev->mh) )))
179 {
180 HeapFree( GetProcessHeap(), 0, physDev );
181 free_dc_ptr( dc );
182 return NULL;
183 }
184
185 physDev->handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, HANDLE_LIST_INC * sizeof(physDev->handles[0]));
186 physDev->handles_size = HANDLE_LIST_INC;
187 physDev->cur_handles = 0;
188
189 physDev->hFile = 0;
190
191 physDev->mh->mtHeaderSize = sizeof(METAHEADER) / sizeof(WORD);
192 physDev->mh->mtVersion = 0x0300;
193 physDev->mh->mtSize = physDev->mh->mtHeaderSize;
194 physDev->mh->mtNoObjects = 0;
195 physDev->mh->mtMaxRecord = 0;
196 physDev->mh->mtNoParameters = 0;
197
198 SetVirtualResolution(dc->hSelf, 0, 0, 0, 0);
199
200 return dc;
201 }
202
203
204 /**********************************************************************
205 * MFDRV_DeleteDC
206 */
207 static BOOL MFDRV_DeleteDC( DC *dc )
208 {
209 METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
210 DWORD index;
211
212 HeapFree( GetProcessHeap(), 0, physDev->mh );
213 for(index = 0; index < physDev->handles_size; index++)
214 if(physDev->handles[index])
215 GDI_hdc_not_using_object(physDev->handles[index], physDev->hdc);
216 HeapFree( GetProcessHeap(), 0, physDev->handles );
217 HeapFree( GetProcessHeap(), 0, physDev );
218 dc->physDev = NULL;
219 free_dc_ptr( dc );
220 return TRUE;
221 }
222
223
224 /**********************************************************************
225 * CreateMetaFileW (GDI32.@)
226 *
227 * Create a new DC and associate it with a metafile. Pass a filename
228 * to create a disk-based metafile, NULL to create a memory metafile.
229 *
230 * PARAMS
231 * filename [I] Filename of disk metafile
232 *
233 * RETURNS
234 * A handle to the metafile DC if successful, NULL on failure.
235 */
236 HDC WINAPI CreateMetaFileW( LPCWSTR filename )
237 {
238 HDC ret;
239 DC *dc;
240 METAFILEDRV_PDEVICE *physDev;
241 HANDLE hFile;
242
243 TRACE("%s\n", debugstr_w(filename) );
244
245 if (!(dc = MFDRV_AllocMetaFile())) return 0;
246 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
247
248 if (filename) /* disk based metafile */
249 {
250 physDev->mh->mtType = METAFILE_DISK;
251 if ((hFile = CreateFileW(filename, GENERIC_WRITE, 0, NULL,
252 CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) {
253 MFDRV_DeleteDC( dc );
254 return 0;
255 }
256 if (!WriteFile( hFile, physDev->mh, sizeof(*physDev->mh), NULL,
257 NULL )) {
258 MFDRV_DeleteDC( dc );
259 return 0;
260 }
261 physDev->hFile = hFile;
262
263 /* Grow METAHEADER to include filename */
264 physDev->mh = MF_CreateMetaHeaderDisk(physDev->mh, filename, TRUE);
265 }
266 else /* memory based metafile */
267 physDev->mh->mtType = METAFILE_MEMORY;
268
269 TRACE("returning %p\n", dc->hSelf);
270 ret = dc->hSelf;
271 release_dc_ptr( dc );
272 return ret;
273 }
274
275 /**********************************************************************
276 * CreateMetaFileA (GDI32.@)
277 *
278 * See CreateMetaFileW.
279 */
280 HDC WINAPI CreateMetaFileA(LPCSTR filename)
281 {
282 LPWSTR filenameW;
283 DWORD len;
284 HDC hReturnDC;
285
286 if (!filename) return CreateMetaFileW(NULL);
287
288 len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
289 filenameW = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
290 MultiByteToWideChar( CP_ACP, 0, filename, -1, filenameW, len );
291
292 hReturnDC = CreateMetaFileW(filenameW);
293
294 HeapFree( GetProcessHeap(), 0, filenameW );
295
296 return hReturnDC;
297 }
298
299
300 /**********************************************************************
301 * MFDRV_CloseMetaFile
302 */
303 static DC *MFDRV_CloseMetaFile( HDC hdc )
304 {
305 DC *dc;
306 METAFILEDRV_PDEVICE *physDev;
307
308 TRACE("(%p)\n", hdc );
309
310 if (!(dc = get_dc_ptr( hdc ))) return NULL;
311 if (dc->header.type != OBJ_METADC)
312 {
313 release_dc_ptr( dc );
314 return NULL;
315 }
316 if (dc->refcount != 1)
317 {
318 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
319 release_dc_ptr( dc );
320 return NULL;
321 }
322 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
323
324 /* Construct the end of metafile record - this is documented
325 * in SDK Knowledgebase Q99334.
326 */
327
328 if (!MFDRV_MetaParam0(dc->physDev, META_EOF))
329 {
330 MFDRV_DeleteDC( dc );
331 return 0;
332 }
333
334 if (physDev->mh->mtType == METAFILE_DISK) /* disk based metafile */
335 {
336 if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0) {
337 MFDRV_DeleteDC( dc );
338 return 0;
339 }
340
341 physDev->mh->mtType = METAFILE_MEMORY; /* This is what windows does */
342 if (!WriteFile(physDev->hFile, physDev->mh, sizeof(*physDev->mh),
343 NULL, NULL)) {
344 MFDRV_DeleteDC( dc );
345 return 0;
346 }
347 CloseHandle(physDev->hFile);
348 physDev->mh->mtType = METAFILE_DISK;
349 }
350
351 return dc;
352 }
353
354 /******************************************************************
355 * CloseMetaFile (GDI32.@)
356 *
357 * Stop recording graphics operations in metafile associated with
358 * hdc and retrieve metafile.
359 *
360 * PARAMS
361 * hdc [I] Metafile DC to close
362 *
363 * RETURNS
364 * Handle of newly created metafile on success, NULL on failure.
365 */
366 HMETAFILE WINAPI CloseMetaFile(HDC hdc)
367 {
368 HMETAFILE hmf;
369 METAFILEDRV_PDEVICE *physDev;
370 DC *dc = MFDRV_CloseMetaFile(hdc);
371 if (!dc) return 0;
372 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
373
374 /* Now allocate a global handle for the metafile */
375
376 hmf = MF_Create_HMETAFILE( physDev->mh );
377
378 physDev->mh = NULL; /* So it won't be deleted */
379 MFDRV_DeleteDC( dc );
380 return hmf;
381 }
382
383
384 /******************************************************************
385 * MFDRV_WriteRecord
386 *
387 * Warning: this function can change the pointer to the metafile header.
388 */
389 BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen)
390 {
391 DWORD len, size;
392 METAHEADER *mh;
393 METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
394
395 switch(physDev->mh->mtType)
396 {
397 case METAFILE_MEMORY:
398 len = physDev->mh->mtSize * 2 + rlen;
399 /* reallocate memory if needed */
400 size = HeapSize( GetProcessHeap(), 0, physDev->mh );
401 if (len > size)
402 {
403 /*expand size*/
404 size += size / 2 + rlen;
405 mh = HeapReAlloc( GetProcessHeap(), 0, physDev->mh, size);
406 if (!mh) return FALSE;
407 physDev->mh = mh;
408 TRACE("Reallocated metafile: new size is %d\n",size);
409 }
410 memcpy((WORD *)physDev->mh + physDev->mh->mtSize, mr, rlen);
411 break;
412 case METAFILE_DISK:
413 TRACE("Writing record to disk\n");
414 if (!WriteFile(physDev->hFile, mr, rlen, NULL, NULL))
415 return FALSE;
416 break;
417 default:
418 ERR("Unknown metafile type %d\n", physDev->mh->mtType );
419 return FALSE;
420 }
421
422 physDev->mh->mtSize += rlen / 2;
423 physDev->mh->mtMaxRecord = max(physDev->mh->mtMaxRecord, rlen / 2);
424 return TRUE;
425 }
426
427
428 /******************************************************************
429 * MFDRV_MetaParam0
430 */
431
432 BOOL MFDRV_MetaParam0(PHYSDEV dev, short func)
433 {
434 char buffer[8];
435 METARECORD *mr = (METARECORD *)&buffer;
436
437 mr->rdSize = 3;
438 mr->rdFunction = func;
439 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
440 }
441
442
443 /******************************************************************
444 * MFDRV_MetaParam1
445 */
446 BOOL MFDRV_MetaParam1(PHYSDEV dev, short func, short param1)
447 {
448 char buffer[8];
449 METARECORD *mr = (METARECORD *)&buffer;
450
451 mr->rdSize = 4;
452 mr->rdFunction = func;
453 *(mr->rdParm) = param1;
454 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
455 }
456
457
458 /******************************************************************
459 * MFDRV_MetaParam2
460 */
461 BOOL MFDRV_MetaParam2(PHYSDEV dev, short func, short param1, short param2)
462 {
463 char buffer[10];
464 METARECORD *mr = (METARECORD *)&buffer;
465
466 mr->rdSize = 5;
467 mr->rdFunction = func;
468 *(mr->rdParm) = param2;
469 *(mr->rdParm + 1) = param1;
470 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
471 }
472
473
474 /******************************************************************
475 * MFDRV_MetaParam4
476 */
477
478 BOOL MFDRV_MetaParam4(PHYSDEV dev, short func, short param1, short param2,
479 short param3, short param4)
480 {
481 char buffer[14];
482 METARECORD *mr = (METARECORD *)&buffer;
483
484 mr->rdSize = 7;
485 mr->rdFunction = func;
486 *(mr->rdParm) = param4;
487 *(mr->rdParm + 1) = param3;
488 *(mr->rdParm + 2) = param2;
489 *(mr->rdParm + 3) = param1;
490 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
491 }
492
493
494 /******************************************************************
495 * MFDRV_MetaParam6
496 */
497
498 BOOL MFDRV_MetaParam6(PHYSDEV dev, short func, short param1, short param2,
499 short param3, short param4, short param5, short param6)
500 {
501 char buffer[18];
502 METARECORD *mr = (METARECORD *)&buffer;
503
504 mr->rdSize = 9;
505 mr->rdFunction = func;
506 *(mr->rdParm) = param6;
507 *(mr->rdParm + 1) = param5;
508 *(mr->rdParm + 2) = param4;
509 *(mr->rdParm + 3) = param3;
510 *(mr->rdParm + 4) = param2;
511 *(mr->rdParm + 5) = param1;
512 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
513 }
514
515
516 /******************************************************************
517 * MFDRV_MetaParam8
518 */
519 BOOL MFDRV_MetaParam8(PHYSDEV dev, short func, short param1, short param2,
520 short param3, short param4, short param5,
521 short param6, short param7, short param8)
522 {
523 char buffer[22];
524 METARECORD *mr = (METARECORD *)&buffer;
525
526 mr->rdSize = 11;
527 mr->rdFunction = func;
528 *(mr->rdParm) = param8;
529 *(mr->rdParm + 1) = param7;
530 *(mr->rdParm + 2) = param6;
531 *(mr->rdParm + 3) = param5;
532 *(mr->rdParm + 4) = param4;
533 *(mr->rdParm + 5) = param3;
534 *(mr->rdParm + 6) = param2;
535 *(mr->rdParm + 7) = param1;
536 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
537 }
538
539
540 /**********************************************************************
541 * MFDRV_ExtEscape
542 */
543 INT CDECL MFDRV_ExtEscape( PHYSDEV dev, INT nEscape, INT cbInput, LPCVOID in_data,
544 INT cbOutput, LPVOID out_data )
545 {
546 METARECORD *mr;
547 DWORD len;
548 INT ret;
549
550 if (cbOutput) return 0; /* escapes that require output cannot work in metafiles */
551
552 len = sizeof(*mr) + sizeof(WORD) + ((cbInput + 1) & ~1);
553 mr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
554 mr->rdSize = len / 2;
555 mr->rdFunction = META_ESCAPE;
556 mr->rdParm[0] = nEscape;
557 mr->rdParm[1] = cbInput;
558 memcpy(&(mr->rdParm[2]), in_data, cbInput);
559 ret = MFDRV_WriteRecord( dev, mr, len);
560 HeapFree(GetProcessHeap(), 0, mr);
561 return ret;
562 }
563
564
565 /******************************************************************
566 * MFDRV_GetDeviceCaps
567 *
568 *A very simple implementation that returns DT_METAFILE
569 */
570 INT CDECL MFDRV_GetDeviceCaps(PHYSDEV dev, INT cap)
571 {
572 switch(cap)
573 {
574 case TECHNOLOGY:
575 return DT_METAFILE;
576 case TEXTCAPS:
577 return 0;
578 default:
579 TRACE(" unsupported capability %d, will return 0\n", cap );
580 }
581 return 0;
582 }
583
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.