4 * Copyright David W. Metcalfe, 1994
5 * Niels de Carpentier, Albrecht Kleine, Huw Davies 1996
16 #include "metafiledrv.h"
20 /******************************************************************
23 * Add a handle to an external handle table and return the index
26 static int MF_AddHandle(HANDLETABLE16
*ht
, WORD htlen
, HGDIOBJ16 hobj
)
30 for (i
= 0; i
< htlen
; i
++)
32 if (*(ht
->objectHandle
+ i
) == 0)
34 *(ht
->objectHandle
+ i
) = hobj
;
42 /******************************************************************
45 * Note: this function assumes that we never delete objects.
46 * If we do someday, we'll need to maintain a table to re-use deleted
49 static int MF_AddHandleDC( DC
*dc
)
51 METAFILEDRV_PDEVICE
*physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
52 physDev
->mh
->mtNoObjects
++;
53 return physDev
->nextHandle
++;
57 /******************************************************************
58 * GetMetafile GDI.124 By Kenny MacDonald 30 Nov 94
61 HMETAFILE16
GetMetaFile(LPSTR lpFilename
)
68 dprintf_metafile(stddeb
,"GetMetaFile: %s\n", lpFilename
);
73 hmf
= GlobalAlloc16(GMEM_MOVEABLE
, MFHEADERSIZE
);
74 mh
= (METAHEADER
*)GlobalLock16(hmf
);
81 if ((hFile
= _lopen(lpFilename
, OF_READ
)) == HFILE_ERROR
) {
86 if (_lread32(hFile
, (char *)mh
, MFHEADERSIZE
) == HFILE_ERROR
) {
91 size
= mh
->mtSize
* 2; /* alloc memory for whole metafile */
93 hmf
= GlobalReAlloc16(hmf
,size
,GMEM_MOVEABLE
);
94 mh
= (METAHEADER
*)GlobalLock16(hmf
);
101 if (_lread32(hFile
, (char*)mh
+ mh
->mtHeaderSize
* 2,
102 size
- mh
->mtHeaderSize
* 2) == HFILE_ERROR
) {
109 if (mh
->mtType
!= 1) {
120 /******************************************************************
121 * CopyMetafile GDI.151 Niels de Carpentier, April 1996
124 HMETAFILE16
CopyMetaFile(HMETAFILE16 hSrcMetaFile
, LPCSTR lpFilename
)
126 HMETAFILE16 handle
= 0;
131 dprintf_metafile(stddeb
,"CopyMetaFile: %s\n", lpFilename
);
133 mh
= (METAHEADER
*)GlobalLock16(hSrcMetaFile
);
138 if (lpFilename
) /* disk based metafile */
141 hFile
= _lcreat(lpFilename
, 0);
143 mh
->mtType
=1; /* disk file version stores 1 here */
144 i
=_lwrite32(hFile
, (char *)mh
, mh
->mtSize
* 2) ;
145 mh
->mtType
=j
; /* restore old value [0 or 1] */
150 else /* memory based metafile */
152 handle
= GlobalAlloc16(GMEM_MOVEABLE
,mh
->mtSize
* 2);
153 mh2
= (METAHEADER
*)GlobalLock16(handle
);
154 memcpy(mh2
,mh
, mh
->mtSize
* 2);
155 GlobalUnlock16(handle
);
161 /******************************************************************
162 * IsValidMetaFile (GDI.410)
163 * (This is not exactly what windows does, see "Undoc Win")
166 BOOL
IsValidMetaFile(HMETAFILE16 hmf
)
169 METAHEADER
*mh
= (METAHEADER
*)GlobalLock16(hmf
);
171 if (mh
->mtType
== 1 || mh
->mtType
== 0)
172 if (mh
->mtHeaderSize
== MFHEADERSIZE
/sizeof(INT16
))
173 if (mh
->mtVersion
== MFVERSION
)
177 dprintf_metafile(stddeb
,"IsValidMetaFile %x => %d\n",hmf
,resu
);
183 /******************************************************************
184 * CloseMetafile GDI.126
187 HMETAFILE16
CloseMetaFile(HDC16 hdc
)
193 METAFILEDRV_PDEVICE
*physDev
;
195 dprintf_metafile(stddeb
,"CloseMetaFile\n");
197 if (!(dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
))) return 0;
199 physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
200 mh
= (METAHEADER
*)GlobalLock16( physDev
->hMetafile
);
202 /* Construct the end of metafile record - this is documented
203 * in SDK Knowledgebase Q99334.
206 if (!MF_MetaParam0(dc
, META_EOF
))
212 if (mh
->mtType
== 1) /* disk based metafile */
214 hFile
= mh
->mtNoParameters
;
215 mh
->mtNoParameters
= 0;
216 if (_llseek(hFile
, 0L, 0) == -1)
221 if (_lwrite32(hFile
, (char *)mh
, MFHEADERSIZE
) == -1)
229 hmf
= physDev
->hMetafile
;
230 GlobalUnlock16( hmf
);
231 physDev
->hMetafile
= 0; /* So it won't be deleted */
237 /******************************************************************
238 * DeleteMetafile GDI.127
241 BOOL
DeleteMetaFile(HMETAFILE16 hmf
)
243 METAHEADER
*mh
= (METAHEADER
*)GlobalLock16(hmf
);
253 /******************************************************************
254 * PlayMetafile GDI.123
257 BOOL
PlayMetaFile(HDC16 hdc
, HMETAFILE16 hmf
)
259 METAHEADER
*mh
= (METAHEADER
*)GlobalLock16(hmf
);
266 dprintf_metafile(stddeb
,"PlayMetaFile(%04x %04x)\n",hdc
,hmf
);
268 /* create the handle table */
269 hHT
= GlobalAlloc16(GMEM_MOVEABLE
|GMEM_ZEROINIT
,
270 sizeof(HANDLETABLE16
) * mh
->mtNoObjects
);
271 ht
= (HANDLETABLE16
*)GlobalLock16(hHT
);
273 /* loop through metafile playing records */
274 offset
= mh
->mtHeaderSize
* 2;
275 while (offset
< mh
->mtSize
* 2)
277 mr
= (METARECORD
*)((char *)mh
+ offset
);
278 dprintf_metafile(stddeb
,"offset = %04x size = %08lx function = %04x\n",
279 offset
,mr
->rdSize
,mr
->rdFunction
);
280 offset
+= mr
->rdSize
* 2;
281 PlayMetaFileRecord(hdc
, ht
, mr
, mh
->mtNoObjects
);
284 /* free objects in handle table */
285 for(i
= 0; i
< mh
->mtNoObjects
; i
++)
286 if(*(ht
->objectHandle
+ i
) != 0)
287 DeleteObject32(*(ht
->objectHandle
+ i
));
289 /* free handle table */
296 /******************************************************************
297 * EnumMetafile GDI.175
298 * Niels de carpentier, april 1996
301 BOOL
EnumMetaFile(HDC16 hdc
, HMETAFILE16 hmf
, MFENUMPROC16 lpEnumFunc
,LPARAM lpData
)
303 METAHEADER
*mh
= (METAHEADER
*)GlobalLock16(hmf
);
309 dprintf_metafile(stddeb
,"EnumMetaFile(%04x, %04x, %08lx, %08lx)\n",
310 hdc
, hmf
, (DWORD
)lpEnumFunc
, lpData
);
312 /* create the handle table */
314 hHT
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
315 sizeof(HANDLETABLE16
) * mh
->mtNoObjects
);
316 ht
= WIN16_GlobalLock16(hHT
);
318 offset
= mh
->mtHeaderSize
* 2;
320 /* loop through metafile records */
322 spRecord
= WIN16_GlobalLock16(hmf
);
323 while (offset
< (mh
->mtSize
* 2))
325 mr
= (METARECORD
*)((char *)mh
+ offset
);
326 if (!lpEnumFunc( hdc
, (HANDLETABLE16
*)ht
,
327 (METARECORD
*)((UINT32
)spRecord
+ offset
),
328 mh
->mtNoObjects
, (LONG
)lpData
))
331 offset
+= (mr
->rdSize
* 2);
334 /* free handle table */
340 /*******************************************************************
341 * MF_GetDIBitsPointer [internal helper for e.g. PlayMetaFileRecord]
343 * Returns offset to DIB bits or 0 if error
344 * (perhaps should be moved to (objects/dib.c ?)
346 static LPSTR
MF_GetDIBitsPointer(LPBITMAPINFO info
)
349 if (info
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
351 if (info
->bmiHeader
.biClrUsed
)
353 if (info
->bmiHeader
.biClrUsed
< (1 << info
->bmiHeader
.biBitCount
))
354 offset
= info
->bmiHeader
.biClrUsed
* 4;
356 offset
= (1 << info
->bmiHeader
.biBitCount
) * 4;
359 offset
= (1 << info
->bmiHeader
.biBitCount
) * 4;
361 else if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
363 if (info
->bmiHeader
.biClrUsed
)
365 if (info
->bmiHeader
.biClrUsed
< (1 << info
->bmiHeader
.biBitCount
))
366 offset
= info
->bmiHeader
.biClrUsed
* 3;
368 offset
= (1 << info
->bmiHeader
.biBitCount
) * 3;
371 offset
= (1 << info
->bmiHeader
.biBitCount
) * 3;
375 fprintf(stderr
,"Unknown size for BITMAPHEADER in MetaFile!\n");
378 return (LPSTR
)info
+ info
->bmiHeader
.biSize
+ offset
;
382 /******************************************************************
383 * PlayMetaFileRecord GDI.176
386 void PlayMetaFileRecord(HDC16 hdc
, HANDLETABLE16
*ht
, METARECORD
*mr
,
392 BITMAPINFOHEADER
*infohdr
;
394 dprintf_metafile(stddeb
,"PlayMetaFileRecord(%04x %08lx %08lx %04x)\n",
395 hdc
,(LONG
)ht
, (LONG
)mr
, nHandles
);
397 switch (mr
->rdFunction
)
402 case META_DELETEOBJECT
:
403 DeleteObject32(*(ht
->objectHandle
+ *(mr
->rdParam
)));
404 *(ht
->objectHandle
+ *(mr
->rdParam
)) = 0;
407 case META_SETBKCOLOR
:
408 SetBkColor(hdc
, *(mr
->rdParam
));
412 SetBkMode16(hdc
, *(mr
->rdParam
));
415 case META_SETMAPMODE
:
416 SetMapMode16(hdc
, *(mr
->rdParam
));
420 SetROP216(hdc
, *(mr
->rdParam
));
424 SetRelAbs16(hdc
, *(mr
->rdParam
));
427 case META_SETPOLYFILLMODE
:
428 SetPolyFillMode16(hdc
, *(mr
->rdParam
));
431 case META_SETSTRETCHBLTMODE
:
432 SetStretchBltMode16(hdc
, *(mr
->rdParam
));
435 case META_SETTEXTCOLOR
:
436 SetTextColor(hdc
, MAKELONG(*(mr
->rdParam
), *(mr
->rdParam
+ 1)));
439 case META_SETWINDOWORG
:
440 SetWindowOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
443 case META_SETWINDOWEXT
:
444 SetWindowExt(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
447 case META_SETVIEWPORTORG
:
448 SetViewportOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
451 case META_SETVIEWPORTEXT
:
452 SetViewportExt(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
455 case META_OFFSETWINDOWORG
:
456 OffsetWindowOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
459 case META_SCALEWINDOWEXT
:
460 ScaleWindowExt(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
461 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
464 case META_OFFSETVIEWPORTORG
:
465 OffsetViewportOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
468 case META_SCALEVIEWPORTEXT
:
469 ScaleViewportExt(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
470 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
474 LineTo32(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
478 MoveTo(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
481 case META_EXCLUDECLIPRECT
:
482 ExcludeClipRect16( hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
483 *(mr
->rdParam
+ 1), *(mr
->rdParam
) );
486 case META_INTERSECTCLIPRECT
:
487 IntersectClipRect16( hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
488 *(mr
->rdParam
+ 1), *(mr
->rdParam
) );
492 Arc32(hdc
, *(mr
->rdParam
+ 7), *(mr
->rdParam
+ 6), *(mr
->rdParam
+ 5),
493 *(mr
->rdParam
+ 4), *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
494 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
498 Ellipse32(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
499 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
503 FloodFill32(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
504 MAKELONG(*(mr
->rdParam
+ 1), *(mr
->rdParam
)));
508 Pie32(hdc
, *(mr
->rdParam
+ 7), *(mr
->rdParam
+ 6), *(mr
->rdParam
+ 5),
509 *(mr
->rdParam
+ 4), *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
510 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
514 Rectangle32(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
515 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
519 RoundRect32(hdc
, *(mr
->rdParam
+ 5), *(mr
->rdParam
+ 4),
520 *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
521 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
525 PatBlt16(hdc
, *(mr
->rdParam
+ 5), *(mr
->rdParam
+ 4),
526 *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
527 MAKELONG(*(mr
->rdParam
), *(mr
->rdParam
+ 1)));
535 SetPixel32(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
536 MAKELONG(*(mr
->rdParam
+ 1), *(mr
->rdParam
)));
539 case META_OFFSETCLIPRGN
:
540 OffsetClipRgn16( hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
) );
545 TextOut16(hdc
, *(mr
->rdParam
+ ((s1
+ 1) >> 1) + 2),
546 *(mr
->rdParam
+ ((s1
+ 1) >> 1) + 1),
547 (char *)(mr
->rdParam
+ 1), s1
);
551 Polygon16(hdc
, (LPPOINT16
)(mr
->rdParam
+ 1), *(mr
->rdParam
));
554 case META_POLYPOLYGON
:
555 PolyPolygon16(hdc
, (LPPOINT16
)(mr
->rdParam
+ *(mr
->rdParam
) + 1),
556 (LPINT16
)(mr
->rdParam
+ 1), *(mr
->rdParam
));
560 Polyline16(hdc
, (LPPOINT16
)(mr
->rdParam
+ 1), *(mr
->rdParam
));
564 RestoreDC32(hdc
, *(mr
->rdParam
));
567 case META_SELECTOBJECT
:
568 SelectObject32(hdc
, *(ht
->objectHandle
+ *(mr
->rdParam
)));
572 Chord32(hdc
, *(mr
->rdParam
+ 7), *(mr
->rdParam
+ 6), *(mr
->rdParam
+5),
573 *(mr
->rdParam
+ 4), *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
574 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
577 case META_CREATEPATTERNBRUSH
:
578 switch (*(mr
->rdParam
))
581 infohdr
= (BITMAPINFOHEADER
*)(mr
->rdParam
+ 2);
582 MF_AddHandle(ht
, nHandles
,
583 CreatePatternBrush32(CreateBitmap(infohdr
->biWidth
,
587 (LPSTR
)(mr
->rdParam
+
588 (sizeof(BITMAPINFOHEADER
) / 2) + 4))));
592 s1
= mr
->rdSize
* 2 - sizeof(METARECORD
) - 2;
593 hndl
= GlobalAlloc16(GMEM_MOVEABLE
, s1
);
594 ptr
= GlobalLock16(hndl
);
595 memcpy(ptr
, mr
->rdParam
+ 2, s1
);
596 GlobalUnlock16(hndl
);
597 MF_AddHandle(ht
, nHandles
,
598 CreateDIBPatternBrush32(hndl
, *(mr
->rdParam
+ 1)));
603 case META_CREATEPENINDIRECT
:
604 MF_AddHandle(ht
, nHandles
,
605 CreatePenIndirect16((LOGPEN16
*)(&(mr
->rdParam
))));
608 case META_CREATEFONTINDIRECT
:
609 MF_AddHandle(ht
, nHandles
,
610 CreateFontIndirect16((LOGFONT16
*)(&(mr
->rdParam
))));
613 case META_CREATEBRUSHINDIRECT
:
614 MF_AddHandle(ht
, nHandles
,
615 CreateBrushIndirect16((LOGBRUSH16
*)(&(mr
->rdParam
))));
618 /* W. Magro: Some new metafile operations. Not all debugged. */
619 case META_CREATEPALETTE
:
620 MF_AddHandle(ht
, nHandles
,
621 CreatePalette((LPLOGPALETTE
)mr
->rdParam
));
624 case META_SETTEXTALIGN
:
625 SetTextAlign16(hdc
, *(mr
->rdParam
));
628 case META_SELECTPALETTE
:
629 SelectPalette(hdc
, *(ht
->objectHandle
+ *(mr
->rdParam
+1)),*(mr
->rdParam
));
632 case META_SETMAPPERFLAGS
:
633 SetMapperFlags(hdc
, *(mr
->rdParam
));
636 case META_REALIZEPALETTE
:
641 dprintf_metafile(stddeb
,"PlayMetaFileRecord: META_ESCAPE unimplemented.\n");
644 /* --- Begin of fixed or new metafile operations. July 1996 ----*/
645 case META_EXTTEXTOUT
:
650 s1
= mr
->rdParam
[2]; /* String length */
651 len
= sizeof(METARECORD
) + (((s1
+ 1) >> 1) * 2) + 2 * sizeof(short)
652 + sizeof(UINT16
) + sizeof(RECT16
);
653 if (mr
->rdSize
== len
/ 2)
654 dxx
= NULL
; /* No array present */
655 else if (mr
->rdSize
== (len
+ s1
* sizeof(INT16
)) / 2)
656 dxx
= &mr
->rdParam
[8+(s1
+1)/2]; /* start of array */
659 "PlayMetaFileRecord ExtTextOut mr->rdSize = %08lx, count = %x\n",
663 ExtTextOut16( hdc
, mr
->rdParam
[1], /* X position */
664 mr
->rdParam
[0], /* Y position */
665 mr
->rdParam
[3], /* options */
666 (LPRECT16
) &mr
->rdParam
[4], /* rectangle */
667 (char *)(mr
->rdParam
+ 8), /* string */
668 s1
, dxx
); /* length, dx array */
670 dprintf_metafile(stddeb
,"EXTTEXTOUT len: %ld (%hd %hd) [%s].\n",
671 mr
->rdSize
,dxx
[0],dxx
[1],(char*) &(mr
->rdParam
[8]) );
675 case META_STRETCHDIB
:
677 LPBITMAPINFO info
= (LPBITMAPINFO
) &(mr
->rdParam
[11]);
678 LPSTR bits
= MF_GetDIBitsPointer(info
);
680 StretchDIBits16(hdc
,mr
->rdParam
[10],mr
->rdParam
[9],mr
->rdParam
[8],
681 mr
->rdParam
[7],mr
->rdParam
[6],mr
->rdParam
[5],
682 mr
->rdParam
[4],mr
->rdParam
[3],bits
,info
,
683 mr
->rdParam
[2],MAKELONG(mr
->rdParam
[0],mr
->rdParam
[1]));
687 case META_DIBSTRETCHBLT
:
689 LPBITMAPINFO info
= (LPBITMAPINFO
) &(mr
->rdParam
[10]);
690 LPSTR bits
= MF_GetDIBitsPointer(info
);
692 StretchDIBits16(hdc
,mr
->rdParam
[9],mr
->rdParam
[8],mr
->rdParam
[7],
693 mr
->rdParam
[6],mr
->rdParam
[5],mr
->rdParam
[4],
694 mr
->rdParam
[3],mr
->rdParam
[2],bits
,info
,
695 DIB_RGB_COLORS
,MAKELONG(mr
->rdParam
[0],mr
->rdParam
[1]));
699 case META_STRETCHBLT
:
701 HDC16 hdcSrc
=CreateCompatibleDC16(hdc
);
702 HBITMAP16 hbitmap
=CreateBitmap(mr
->rdParam
[10], /*Width */
703 mr
->rdParam
[11], /*Height*/
704 mr
->rdParam
[13], /*Planes*/
705 mr
->rdParam
[14], /*BitsPixel*/
706 (LPSTR
)&mr
->rdParam
[15]); /*bits*/
707 SelectObject32(hdcSrc
,hbitmap
);
708 StretchBlt16(hdc
,mr
->rdParam
[9],mr
->rdParam
[8],
709 mr
->rdParam
[7],mr
->rdParam
[6],
710 hdcSrc
,mr
->rdParam
[5],mr
->rdParam
[4],
711 mr
->rdParam
[3],mr
->rdParam
[2],
712 MAKELONG(mr
->rdParam
[0],mr
->rdParam
[1]));
717 case META_BITBLT
: /* <-- not yet debugged */
719 HDC16 hdcSrc
=CreateCompatibleDC16(hdc
);
720 HBITMAP16 hbitmap
=CreateBitmap(mr
->rdParam
[7]/*Width */,mr
->rdParam
[8]/*Height*/,
721 mr
->rdParam
[10]/*Planes*/,mr
->rdParam
[11]/*BitsPixel*/,
722 (LPSTR
)&mr
->rdParam
[12]/*bits*/);
723 SelectObject32(hdcSrc
,hbitmap
);
724 BitBlt32(hdc
,mr
->rdParam
[6],mr
->rdParam
[5],
725 mr
->rdParam
[4],mr
->rdParam
[3],
726 hdcSrc
, mr
->rdParam
[2],mr
->rdParam
[1],
727 MAKELONG(0,mr
->rdParam
[0]));
733 fprintf(stddeb
,"PlayMetaFileRecord: Unknown record type %x\n",
739 /******************************************************************
740 * GetMetaFileBits by William Magro, 19 Sep 1995
742 * Trade in a meta file object handle for a handle to the meta file memory
745 HGLOBAL16
GetMetaFileBits(HMETAFILE16 hmf
)
747 dprintf_metafile(stddeb
,"GetMetaFileBits: hMem out: %04x\n", hmf
);
752 /******************************************************************
753 * SetMetaFileBits by William Magro, 19 Sep 1995
755 * Trade in a meta file memory handle for a handle to a meta file object
758 HMETAFILE16
SetMetaFileBits( HGLOBAL16 hMem
)
760 dprintf_metafile(stddeb
,"SetMetaFileBits: hmf out: %04x\n", hMem
);
765 /******************************************************************
768 * Warning: this function can change the metafile handle.
771 static BOOL32
MF_WriteRecord( DC
*dc
, METARECORD
*mr
, WORD rlen
)
775 METAFILEDRV_PDEVICE
*physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
777 switch(physDev
->mh
->mtType
)
779 case METAFILE_MEMORY
:
780 len
= physDev
->mh
->mtSize
* 2 + rlen
;
781 mh
= HeapReAlloc( SystemHeap
, 0, physDev
->mh
, len
);
782 if (!mh
) return FALSE
;
784 memcpy((WORD
*)physDev
->mh
+ physDev
->mh
->mtSize
, mr
, rlen
);
787 dprintf_metafile(stddeb
,"Writing record to disk\n");
788 if (_lwrite32(physDev
->mh
->mtNoParameters
, (char *)mr
, rlen
) == -1)
792 fprintf( stderr
, "Uknown metafile type %d\n", physDev
->mh
->mtType
);
796 physDev
->mh
->mtSize
+= rlen
/ 2;
797 physDev
->mh
->mtMaxRecord
= MAX(physDev
->mh
->mtMaxRecord
, rlen
/ 2);
802 /******************************************************************
806 BOOL32
MF_MetaParam0(DC
*dc
, short func
)
809 METARECORD
*mr
= (METARECORD
*)&buffer
;
812 mr
->rdFunction
= func
;
813 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
817 /******************************************************************
820 BOOL32
MF_MetaParam1(DC
*dc
, short func
, short param1
)
823 METARECORD
*mr
= (METARECORD
*)&buffer
;
826 mr
->rdFunction
= func
;
827 *(mr
->rdParam
) = param1
;
828 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
832 /******************************************************************
835 BOOL32
MF_MetaParam2(DC
*dc
, short func
, short param1
, short param2
)
838 METARECORD
*mr
= (METARECORD
*)&buffer
;
841 mr
->rdFunction
= func
;
842 *(mr
->rdParam
) = param2
;
843 *(mr
->rdParam
+ 1) = param1
;
844 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
848 /******************************************************************
852 BOOL32
MF_MetaParam4(DC
*dc
, short func
, short param1
, short param2
,
853 short param3
, short param4
)
856 METARECORD
*mr
= (METARECORD
*)&buffer
;
859 mr
->rdFunction
= func
;
860 *(mr
->rdParam
) = param4
;
861 *(mr
->rdParam
+ 1) = param3
;
862 *(mr
->rdParam
+ 2) = param2
;
863 *(mr
->rdParam
+ 3) = param1
;
864 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
868 /******************************************************************
872 BOOL32
MF_MetaParam6(DC
*dc
, short func
, short param1
, short param2
,
873 short param3
, short param4
, short param5
, short param6
)
876 METARECORD
*mr
= (METARECORD
*)&buffer
;
879 mr
->rdFunction
= func
;
880 *(mr
->rdParam
) = param6
;
881 *(mr
->rdParam
+ 1) = param5
;
882 *(mr
->rdParam
+ 2) = param4
;
883 *(mr
->rdParam
+ 3) = param3
;
884 *(mr
->rdParam
+ 4) = param2
;
885 *(mr
->rdParam
+ 5) = param1
;
886 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
890 /******************************************************************
893 BOOL32
MF_MetaParam8(DC
*dc
, short func
, short param1
, short param2
,
894 short param3
, short param4
, short param5
,
895 short param6
, short param7
, short param8
)
898 METARECORD
*mr
= (METARECORD
*)&buffer
;
901 mr
->rdFunction
= func
;
902 *(mr
->rdParam
) = param8
;
903 *(mr
->rdParam
+ 1) = param7
;
904 *(mr
->rdParam
+ 2) = param6
;
905 *(mr
->rdParam
+ 3) = param5
;
906 *(mr
->rdParam
+ 4) = param4
;
907 *(mr
->rdParam
+ 5) = param3
;
908 *(mr
->rdParam
+ 6) = param2
;
909 *(mr
->rdParam
+ 7) = param1
;
910 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
914 /******************************************************************
915 * MF_CreateBrushIndirect
918 BOOL32
MF_CreateBrushIndirect(DC
*dc
, HBRUSH16 hBrush
, LOGBRUSH16
*logbrush
)
921 char buffer
[sizeof(METARECORD
) - 2 + sizeof(*logbrush
)];
922 METARECORD
*mr
= (METARECORD
*)&buffer
;
924 mr
->rdSize
= (sizeof(METARECORD
) + sizeof(*logbrush
) - 2) / 2;
925 mr
->rdFunction
= META_CREATEBRUSHINDIRECT
;
926 memcpy(&(mr
->rdParam
), logbrush
, sizeof(*logbrush
));
927 if (!(MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2))) return FALSE
;
929 mr
->rdSize
= sizeof(METARECORD
) / 2;
930 mr
->rdFunction
= META_SELECTOBJECT
;
932 if ((index
= MF_AddHandleDC( dc
)) == -1) return FALSE
;
933 *(mr
->rdParam
) = index
;
934 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
938 /******************************************************************
939 * MF_CreatePatternBrush
942 BOOL32
MF_CreatePatternBrush(DC
*dc
, HBRUSH16 hBrush
, LOGBRUSH16
*logbrush
)
944 DWORD len
, bmSize
, biSize
;
949 BITMAPINFOHEADER
*infohdr
;
951 char buffer
[sizeof(METARECORD
)];
953 switch (logbrush
->lbStyle
)
956 bmp
= (BITMAPOBJ
*)GDI_GetObjPtr((HGDIOBJ16
)logbrush
->lbHatch
, BITMAP_MAGIC
);
957 if (!bmp
) return FALSE
;
958 len
= sizeof(METARECORD
) + sizeof(BITMAPINFOHEADER
) +
959 (bmp
->bitmap
.bmHeight
* bmp
->bitmap
.bmWidthBytes
) + 6;
960 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
962 mr
= (METARECORD
*)GlobalLock16(hmr
);
964 mr
->rdFunction
= META_DIBCREATEPATTERNBRUSH
;
965 mr
->rdSize
= len
/ 2;
966 *(mr
->rdParam
) = logbrush
->lbStyle
;
967 *(mr
->rdParam
+ 1) = DIB_RGB_COLORS
;
968 infohdr
= (BITMAPINFOHEADER
*)(mr
->rdParam
+ 2);
969 infohdr
->biSize
= sizeof(BITMAPINFOHEADER
);
970 infohdr
->biWidth
= bmp
->bitmap
.bmWidth
;
971 infohdr
->biHeight
= bmp
->bitmap
.bmHeight
;
972 infohdr
->biPlanes
= bmp
->bitmap
.bmPlanes
;
973 infohdr
->biBitCount
= bmp
->bitmap
.bmBitsPixel
;
974 memcpy(mr
->rdParam
+ (sizeof(BITMAPINFOHEADER
) / 2) + 4,
975 PTR_SEG_TO_LIN(bmp
->bitmap
.bmBits
),
976 bmp
->bitmap
.bmHeight
* bmp
->bitmap
.bmWidthBytes
);
980 info
= (BITMAPINFO
*)GlobalLock16((HGLOBAL16
)logbrush
->lbHatch
);
981 if (info
->bmiHeader
.biCompression
)
982 bmSize
= info
->bmiHeader
.biSizeImage
;
984 bmSize
= (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
985 + 31) / 32 * 8 * info
->bmiHeader
.biHeight
;
986 biSize
= DIB_BitmapInfoSize(info
, LOWORD(logbrush
->lbColor
));
987 len
= sizeof(METARECORD
) + biSize
+ bmSize
+ 2;
988 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
990 mr
= (METARECORD
*)GlobalLock16(hmr
);
992 mr
->rdFunction
= META_DIBCREATEPATTERNBRUSH
;
993 mr
->rdSize
= len
/ 2;
994 *(mr
->rdParam
) = logbrush
->lbStyle
;
995 *(mr
->rdParam
+ 1) = LOWORD(logbrush
->lbColor
);
996 memcpy(mr
->rdParam
+ 2, info
, biSize
+ bmSize
);
1001 if (!(MF_WriteRecord(dc
, mr
, len
)))
1009 mr
= (METARECORD
*)&buffer
;
1010 mr
->rdSize
= sizeof(METARECORD
) / 2;
1011 mr
->rdFunction
= META_SELECTOBJECT
;
1013 if ((index
= MF_AddHandleDC( dc
)) == -1) return FALSE
;
1014 *(mr
->rdParam
) = index
;
1015 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1019 /******************************************************************
1020 * MF_CreatePenIndirect
1023 BOOL32
MF_CreatePenIndirect(DC
*dc
, HPEN16 hPen
, LOGPEN16
*logpen
)
1026 char buffer
[sizeof(METARECORD
) - 2 + sizeof(*logpen
)];
1027 METARECORD
*mr
= (METARECORD
*)&buffer
;
1029 mr
->rdSize
= (sizeof(METARECORD
) + sizeof(*logpen
) - 2) / 2;
1030 mr
->rdFunction
= META_CREATEPENINDIRECT
;
1031 memcpy(&(mr
->rdParam
), logpen
, sizeof(*logpen
));
1032 if (!(MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2))) return FALSE
;
1034 mr
->rdSize
= sizeof(METARECORD
) / 2;
1035 mr
->rdFunction
= META_SELECTOBJECT
;
1037 if ((index
= MF_AddHandleDC( dc
)) == -1) return FALSE
;
1038 *(mr
->rdParam
) = index
;
1039 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1043 /******************************************************************
1044 * MF_CreateFontIndirect
1047 BOOL32
MF_CreateFontIndirect(DC
*dc
, HFONT16 hFont
, LOGFONT16
*logfont
)
1050 char buffer
[sizeof(METARECORD
) - 2 + sizeof(LOGFONT16
)];
1051 METARECORD
*mr
= (METARECORD
*)&buffer
;
1053 mr
->rdSize
= (sizeof(METARECORD
) + sizeof(LOGFONT16
) - 2) / 2;
1054 mr
->rdFunction
= META_CREATEFONTINDIRECT
;
1055 memcpy(&(mr
->rdParam
), logfont
, sizeof(LOGFONT16
));
1056 if (!(MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2))) return FALSE
;
1058 mr
->rdSize
= sizeof(METARECORD
) / 2;
1059 mr
->rdFunction
= META_SELECTOBJECT
;
1061 if ((index
= MF_AddHandleDC( dc
)) == -1) return FALSE
;
1062 *(mr
->rdParam
) = index
;
1063 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1067 /******************************************************************
1070 BOOL32
MF_TextOut(DC
*dc
, short x
, short y
, LPCSTR str
, short count
)
1077 len
= sizeof(METARECORD
) + (((count
+ 1) >> 1) * 2) + 4;
1078 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1080 mr
= (METARECORD
*)GlobalLock16(hmr
);
1083 mr
->rdSize
= len
/ 2;
1084 mr
->rdFunction
= META_TEXTOUT
;
1085 *(mr
->rdParam
) = count
;
1086 memcpy(mr
->rdParam
+ 1, str
, count
);
1087 *(mr
->rdParam
+ ((count
+ 1) >> 1) + 1) = y
;
1088 *(mr
->rdParam
+ ((count
+ 1) >> 1) + 2) = x
;
1089 ret
= MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1094 /******************************************************************
1097 BOOL32
MF_ExtTextOut(DC
*dc
, short x
, short y
, UINT16 flags
, const RECT16
*rect
,
1098 LPCSTR str
, short count
, const INT16
*lpDx
)
1105 len
= sizeof(METARECORD
) + (((count
+ 1) >> 1) * 2) + 2 * sizeof(short)
1106 + sizeof(UINT16
) + sizeof(RECT16
);
1108 len
+=count
*sizeof(INT16
);
1109 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1111 mr
= (METARECORD
*)GlobalLock16(hmr
);
1114 mr
->rdSize
= len
/ 2;
1115 mr
->rdFunction
= META_EXTTEXTOUT
;
1117 *(mr
->rdParam
+ 1) = x
;
1118 *(mr
->rdParam
+ 2) = count
;
1119 *(mr
->rdParam
+ 3) = flags
;
1120 if (rect
) memcpy(mr
->rdParam
+ 4, rect
, sizeof(RECT16
));
1121 memcpy(mr
->rdParam
+ 8, str
, count
);
1123 memcpy(mr
->rdParam
+ 8+ ((count
+ 1) >> 1),lpDx
,count
*sizeof(INT16
));
1124 ret
= MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1129 /******************************************************************
1130 * MF_MetaPoly - implements Polygon and Polyline
1132 BOOL32
MF_MetaPoly(DC
*dc
, short func
, LPPOINT16 pt
, short count
)
1139 len
= sizeof(METARECORD
) + (count
* 4);
1140 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1142 mr
= (METARECORD
*)GlobalLock16(hmr
);
1145 mr
->rdSize
= len
/ 2;
1146 mr
->rdFunction
= func
;
1147 *(mr
->rdParam
) = count
;
1148 memcpy(mr
->rdParam
+ 1, pt
, count
* 4);
1149 ret
= MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1155 /******************************************************************
1158 BOOL32
MF_BitBlt(DC
*dcDest
, short xDest
, short yDest
, short width
,
1159 short height
, DC
*dcSrc
, short xSrc
, short ySrc
, DWORD rop
)
1167 GetObject16(dcSrc
->w
.hBitmap
, sizeof(BITMAP16
), &BM
);
1168 len
= sizeof(METARECORD
) + 12 * sizeof(INT16
) + BM
.bmWidthBytes
* BM
.bmHeight
;
1169 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1171 mr
= (METARECORD
*)GlobalLock16(hmr
);
1172 mr
->rdFunction
= META_BITBLT
;
1173 *(mr
->rdParam
+ 7) = BM
.bmWidth
;
1174 *(mr
->rdParam
+ 8) = BM
.bmHeight
;
1175 *(mr
->rdParam
+ 9) = BM
.bmWidthBytes
;
1176 *(mr
->rdParam
+10) = BM
.bmPlanes
;
1177 *(mr
->rdParam
+11) = BM
.bmBitsPixel
;
1178 dprintf_metafile(stddeb
,"MF_StretchBlt->len = %ld rop=%lx \n",len
,rop
);
1179 if (GetBitmapBits(dcSrc
->w
.hBitmap
,BM
.bmWidthBytes
* BM
.bmHeight
,mr
->rdParam
+12))
1181 mr
->rdSize
= len
/ sizeof(INT16
);
1182 *(mr
->rdParam
) = HIWORD(rop
);
1183 *(mr
->rdParam
+ 1) = ySrc
;
1184 *(mr
->rdParam
+ 2) = xSrc
;
1185 *(mr
->rdParam
+ 3) = height
;
1186 *(mr
->rdParam
+ 4) = width
;
1187 *(mr
->rdParam
+ 5) = yDest
;
1188 *(mr
->rdParam
+ 6) = xDest
;
1189 ret
= MF_WriteRecord( dcDest
, mr
, mr
->rdSize
* 2);
1198 /**********************************************************************
1200 * this function contains TWO ways for procesing StretchBlt in metafiles,
1201 * decide between rdFunction values META_STRETCHBLT or META_DIBSTRETCHBLT
1202 * via #define STRETCH_VIA_DIB
1204 #define STRETCH_VIA_DIB
1205 #undef STRETCH_VIA_DIB
1206 BOOL32
MF_StretchBlt(DC
*dcDest
, short xDest
, short yDest
, short widthDest
,
1207 short heightDest
, DC
*dcSrc
, short xSrc
, short ySrc
,
1208 short widthSrc
, short heightSrc
, DWORD rop
)
1215 #ifdef STRETCH_VIA_DIB
1216 LPBITMAPINFOHEADER lpBMI
;
1219 GetObject16(dcSrc
->w
.hBitmap
, sizeof(BITMAP16
), &BM
);
1220 #ifdef STRETCH_VIA_DIB
1221 nBPP
= BM
.bmPlanes
* BM
.bmBitsPixel
;
1222 len
= sizeof(METARECORD
) + 10 * sizeof(INT16
)
1223 + sizeof(BITMAPINFOHEADER
) + (nBPP
!= 24 ? 1 << nBPP
: 0) * sizeof(RGBQUAD
)
1224 + ((BM
.bmWidth
* nBPP
+ 31) / 32) * 4 * BM
.bmHeight
;
1225 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1227 mr
= (METARECORD
*)GlobalLock16(hmr
);
1228 mr
->rdFunction
= META_DIBSTRETCHBLT
;
1229 lpBMI
=(LPBITMAPINFOHEADER
)(mr
->rdParam
+10);
1230 lpBMI
->biSize
= sizeof(BITMAPINFOHEADER
);
1231 lpBMI
->biWidth
= BM
.bmWidth
;
1232 lpBMI
->biHeight
= BM
.bmHeight
;
1233 lpBMI
->biPlanes
= 1;
1234 lpBMI
->biBitCount
= nBPP
; /* 1,4,8 or 24 */
1235 lpBMI
->biClrUsed
= nBPP
!= 24 ? 1 << nBPP
: 0;
1236 lpBMI
->biSizeImage
= ((lpBMI
->biWidth
* nBPP
+ 31) / 32) * 4 * lpBMI
->biHeight
;
1237 lpBMI
->biCompression
= BI_RGB
;
1238 lpBMI
->biXPelsPerMeter
= MulDiv32(GetDeviceCaps(dcSrc
->hSelf
,LOGPIXELSX
),3937,100);
1239 lpBMI
->biYPelsPerMeter
= MulDiv32(GetDeviceCaps(dcSrc
->hSelf
,LOGPIXELSY
),3937,100);
1240 lpBMI
->biClrImportant
= 0; /* 1 meter = 39.37 inch */
1242 dprintf_metafile(stddeb
,"MF_StretchBltViaDIB->len = %ld rop=%lx PixYPM=%ld Caps=%d\n",
1243 len
,rop
,lpBMI
->biYPelsPerMeter
,GetDeviceCaps(hdcSrc
,LOGPIXELSY
));
1244 if (GetDIBits(hdcSrc
,dcSrc
->w
.hBitmap
,0,(UINT
)lpBMI
->biHeight
,
1245 MF_GetDIBitsPointer((LPBITMAPINFO
)lpBMI
), /* DIB bits */
1246 (LPBITMAPINFO
)lpBMI
,DIB_RGB_COLORS
)) /* DIB info structure */
1248 len
= sizeof(METARECORD
) + 15 * sizeof(INT16
) + BM
.bmWidthBytes
* BM
.bmHeight
;
1249 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1251 mr
= (METARECORD
*)GlobalLock16(hmr
);
1252 mr
->rdFunction
= META_STRETCHBLT
;
1253 *(mr
->rdParam
+10) = BM
.bmWidth
;
1254 *(mr
->rdParam
+11) = BM
.bmHeight
;
1255 *(mr
->rdParam
+12) = BM
.bmWidthBytes
;
1256 *(mr
->rdParam
+13) = BM
.bmPlanes
;
1257 *(mr
->rdParam
+14) = BM
.bmBitsPixel
;
1258 dprintf_metafile(stddeb
,"MF_StretchBlt->len = %ld rop=%lx \n",len
,rop
);
1259 if (GetBitmapBits(dcSrc
->w
.hBitmap
,BM
.bmWidthBytes
* BM
.bmHeight
,mr
->rdParam
+15))
1262 mr
->rdSize
= len
/ sizeof(INT16
);
1263 *(mr
->rdParam
) = LOWORD(rop
);
1264 *(mr
->rdParam
+ 1) = HIWORD(rop
);
1265 *(mr
->rdParam
+ 2) = heightSrc
;
1266 *(mr
->rdParam
+ 3) = widthSrc
;
1267 *(mr
->rdParam
+ 4) = ySrc
;
1268 *(mr
->rdParam
+ 5) = xSrc
;
1269 *(mr
->rdParam
+ 6) = heightDest
;
1270 *(mr
->rdParam
+ 7) = widthDest
;
1271 *(mr
->rdParam
+ 8) = yDest
;
1272 *(mr
->rdParam
+ 9) = xDest
;
1273 ret
= MF_WriteRecord( dcDest
, mr
, mr
->rdSize
* 2);