4 * Copyright David W. Metcalfe, 1994
6 static char Copyright[] = "Copyright David W. Metcalfe, 1994";
13 #include "prototypes.h"
15 /* #define DEBUG_METAFILE */
18 #define HTINCR 10 /* handle table allocation size increment */
20 static HANDLE hHT
; /* handle of the handle table */
21 static int HTLen
; /* allocated length of handle table */
23 /******************************************************************
24 * GetMetafile GDI.124 By Kenny MacDonald 30 Nov 94
26 HMETAFILE
GetMetaFile(LPSTR lpFilename
)
34 dprintf_metafile(stddeb
,"GetMetaFile: %s\n", lpFilename
);
39 hmf
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(METAFILE
));
40 mf
= (METAFILE
*)GlobalLock(hmf
);
46 mf
->hMetaHdr
= GlobalAlloc(GMEM_MOVEABLE
, MFHEADERSIZE
);
47 mh
= (METAHEADER
*)GlobalLock(mf
->hMetaHdr
);
49 GlobalFree(mf
->hMetaHdr
);
53 strcpy(mf
->Filename
, lpFilename
);
54 mf
->wMagic
= METAFILE_MAGIC
;
55 if ((mf
->hFile
= _lopen(lpFilename
, OF_READ
)) == HFILE_ERROR
) {
59 if (_lread(mf
->hFile
, (char *)mh
, MFHEADERSIZE
) == HFILE_ERROR
) {
60 GlobalFree(mf
->hMetaHdr
);
67 GlobalUnlock(mf
->hMetaHdr
);
75 /******************************************************************
76 * CreateMetafile GDI.125
78 HANDLE
CreateMetaFile(LPSTR lpFilename
)
86 dprintf_metafile(stddeb
,"CreateMetaFile: %s\n", lpFilename
);
88 handle
= GDI_AllocObject(sizeof(DC
), METAFILE_DC_MAGIC
);
89 if (!handle
) return 0;
90 dc
= (DC
*)GDI_HEAP_ADDR(handle
);
92 if (!(dc
->w
.hMetaFile
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(METAFILE
))))
94 mf
= (METAFILE
*)GlobalLock(dc
->w
.hMetaFile
);
95 if (!(mf
->hMetaHdr
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(METAHEADER
))))
97 GlobalFree(dc
->w
.hMetaFile
);
100 mh
= (METAHEADER
*)GlobalLock(mf
->hMetaHdr
);
102 mf
->wMagic
= METAFILE_MAGIC
;
103 mh
->mtHeaderSize
= MFHEADERSIZE
/ 2;
104 mh
->mtVersion
= MFVERSION
;
105 mh
->mtSize
= MFHEADERSIZE
/ 2;
108 mh
->mtNoParameters
= 0;
110 if (lpFilename
) /* disk based metafile */
113 strcpy(mf
->Filename
, lpFilename
);
114 mf
->hFile
= _lcreat(lpFilename
, 0);
115 if (_lwrite(mf
->hFile
, (char *)mh
, MFHEADERSIZE
) == -1)
117 GlobalFree(mf
->hMetaHdr
);
118 GlobalFree(dc
->w
.hMetaFile
);
122 else /* memory based metafile */
125 /* create the handle table */
127 hHT
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
128 sizeof(HANDLETABLE
) * HTLen
);
129 ht
= (HANDLETABLE
*)GlobalLock(hHT
);
131 GlobalUnlock(mf
->hMetaHdr
);
132 GlobalUnlock(dc
->w
.hMetaFile
);
137 /******************************************************************
138 * CloseMetafile GDI.126
140 HMETAFILE
CloseMetaFile(HDC hdc
)
147 /* METARECORD *mr = (METARECORD *)&buffer;*/
149 dprintf_metafile(stddeb
,"CloseMetaFile\n");
151 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
153 mf
= (METAFILE
*)GlobalLock(dc
->w
.hMetaFile
);
154 mh
= (METAHEADER
*)GlobalLock(mf
->hMetaHdr
);
156 /* Construct the end of metafile record - this is documented
157 * in SDK Knowledgebase Q99334.
159 if (!MF_MetaParam0(dc
, META_EOF
))
161 GlobalFree(mf
->hMetaHdr
);
162 GlobalFree(dc
->w
.hMetaFile
);
166 if (mh
->mtType
== 1) /* disk based metafile */
168 if (_llseek(mf
->hFile
, 0L, 0) == -1)
170 GlobalFree(mf
->hMetaHdr
);
171 GlobalFree(dc
->w
.hMetaFile
);
174 if (_lwrite(mf
->hFile
, (char *)mh
, MFHEADERSIZE
) == -1)
176 GlobalFree(mf
->hMetaHdr
);
177 GlobalFree(dc
->w
.hMetaFile
);
183 /* delete the handle table */
186 GlobalUnlock(mf
->hMetaHdr
);
187 hmf
= dc
->w
.hMetaFile
;
194 /******************************************************************
195 * DeleteMetafile GDI.127
197 BOOL
DeleteMetaFile(HMETAFILE hmf
)
199 METAFILE
*mf
= (METAFILE
*)GlobalLock(hmf
);
201 if (mf
->wMagic
!= METAFILE_MAGIC
)
204 GlobalFree(mf
->hMetaHdr
);
210 /******************************************************************
211 * PlayMetafile GDI.123
213 BOOL
PlayMetaFile(HDC hdc
, HMETAFILE hmf
)
215 METAFILE
*mf
= (METAFILE
*)GlobalLock(hmf
);
221 if (mf
->wMagic
!= METAFILE_MAGIC
)
224 mh
= (METAHEADER
*)GlobalLock(mf
->hMetaHdr
);
225 if (mh
->mtType
== 1) /* disk based metafile */
227 mf
->hFile
= _lopen(mf
->Filename
, OF_READ
);
228 mf
->hBuffer
= GlobalAlloc(GMEM_MOVEABLE
, mh
->mtMaxRecord
* 2);
229 buffer
= (char *)GlobalLock(mf
->hBuffer
);
230 _llseek(mf
->hFile
, mh
->mtHeaderSize
* 2, 0);
231 mf
->MetaOffset
= mh
->mtHeaderSize
* 2;
233 else if (mh
->mtType
== 0) /* memory based metafile */
234 mf
->MetaOffset
= mh
->mtHeaderSize
* 2;
235 else /* not a valid metafile type */
238 /* create the handle table */
239 hHT
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(HANDLETABLE
) * mh
->mtNoObjects
);
240 ht
= (HANDLETABLE
*)GlobalLock(hHT
);
242 /* loop through metafile playing records */
243 while (mf
->MetaOffset
< mh
->mtSize
* 2)
245 if (mh
->mtType
== 1) /* disk based metafile */
247 _lread(mf
->hFile
, buffer
, sizeof(METARECORD
));
248 mr
= (METARECORD
*)buffer
;
249 _lread(mf
->hFile
, (char *)(mr
->rdParam
+ 1), (mr
->rdSize
* 2) -
251 mf
->MetaOffset
+= mr
->rdSize
* 2;
253 else /* memory based metafile */
255 mr
= (METARECORD
*)((char *)mh
+ mf
->MetaOffset
);
256 mf
->MetaOffset
+= mr
->rdSize
* 2;
258 PlayMetaFileRecord(hdc
, ht
, mr
, mh
->mtNoObjects
);
261 /* close disk based metafile and free buffer */
264 GlobalFree(mf
->hBuffer
);
268 /* free handle table */
275 /******************************************************************
276 * PlayMetaFileRecord GDI.176
278 void PlayMetaFileRecord(HDC hdc
, HANDLETABLE
*ht
, METARECORD
*mr
,
284 BITMAPINFOHEADER
*infohdr
;
286 switch (mr
->rdFunction
)
291 case META_DELETEOBJECT
:
292 DeleteObject(*(ht
->objectHandle
+ *(mr
->rdParam
)));
295 case META_SETBKCOLOR
:
296 SetBkColor(hdc
, *(mr
->rdParam
));
300 SetBkMode(hdc
, *(mr
->rdParam
));
303 case META_SETMAPMODE
:
304 SetMapMode(hdc
, *(mr
->rdParam
));
308 SetROP2(hdc
, *(mr
->rdParam
));
312 SetRelAbs(hdc
, *(mr
->rdParam
));
315 case META_SETPOLYFILLMODE
:
316 SetPolyFillMode(hdc
, *(mr
->rdParam
));
319 case META_SETSTRETCHBLTMODE
:
320 SetStretchBltMode(hdc
, *(mr
->rdParam
));
323 case META_SETTEXTCOLOR
:
324 SetTextColor(hdc
, MAKELONG(*(mr
->rdParam
), *(mr
->rdParam
+ 1)));
327 case META_SETWINDOWORG
:
328 SetWindowOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
331 case META_SETWINDOWEXT
:
332 SetWindowExt(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
335 case META_SETVIEWPORTORG
:
336 SetViewportOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
339 case META_SETVIEWPORTEXT
:
340 SetViewportExt(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
343 case META_OFFSETWINDOWORG
:
344 OffsetWindowOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
347 case META_SCALEWINDOWEXT
:
348 ScaleWindowExt(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
349 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
352 case META_OFFSETVIEWPORTORG
:
353 OffsetViewportOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
356 case META_SCALEVIEWPORTEXT
:
357 ScaleViewportExt(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
358 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
362 LineTo(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
366 MoveTo(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
369 case META_EXCLUDECLIPRECT
:
370 ExcludeClipRect(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
371 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
374 case META_INTERSECTCLIPRECT
:
375 IntersectClipRect(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
376 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
380 Arc(hdc
, *(mr
->rdParam
+ 7), *(mr
->rdParam
+ 6), *(mr
->rdParam
+ 5),
381 *(mr
->rdParam
+ 4), *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
382 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
386 Ellipse(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
387 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
391 FloodFill(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
392 MAKELONG(*(mr
->rdParam
+ 1), *(mr
->rdParam
)));
396 Pie(hdc
, *(mr
->rdParam
+ 7), *(mr
->rdParam
+ 6), *(mr
->rdParam
+ 5),
397 *(mr
->rdParam
+ 4), *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
398 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
402 Ellipse(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
403 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
407 RoundRect(hdc
, *(mr
->rdParam
+ 5), *(mr
->rdParam
+ 4),
408 *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
409 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
413 PatBlt(hdc
, *(mr
->rdParam
+ 5), *(mr
->rdParam
+ 4),
414 *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
415 MAKELONG(*(mr
->rdParam
), *(mr
->rdParam
+ 1)));
423 SetPixel(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
424 MAKELONG(*(mr
->rdParam
+ 1), *(mr
->rdParam
)));
427 case META_OFFSETCLIPRGN
:
428 OffsetClipRgn(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
433 TextOut(hdc
, *(mr
->rdParam
+ ((s1
+ 1) >> 1) + 2),
434 *(mr
->rdParam
+ ((s1
+ 1) >> 1) + 1),
435 (char *)(mr
->rdParam
+ 1), s1
);
439 Polygon(hdc
, (LPPOINT
)(mr
->rdParam
+ 1), *(mr
->rdParam
));
442 case META_POLYPOLYGON
:
443 PolyPolygon(hdc
, (LPPOINT
)(mr
->rdParam
+ *(mr
->rdParam
) + 1),
444 (mr
->rdParam
+ 1), *(mr
->rdParam
));
448 Polyline(hdc
, (LPPOINT
)(mr
->rdParam
+ 1), *(mr
->rdParam
));
452 RestoreDC(hdc
, *(mr
->rdParam
));
455 case META_SELECTOBJECT
:
456 SelectObject(hdc
, *(ht
->objectHandle
+ *(mr
->rdParam
)));
460 Chord(hdc
, *(mr
->rdParam
+ 7), *(mr
->rdParam
+ 6), *(mr
->rdParam
+ 5),
461 *(mr
->rdParam
+ 4), *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
462 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
465 case META_CREATEPATTERNBRUSH
:
466 switch (*(mr
->rdParam
))
469 infohdr
= (BITMAPINFOHEADER
*)(mr
->rdParam
+ 2);
470 MF_AddHandle(ht
, nHandles
,
471 CreatePatternBrush(CreateBitmap(infohdr
->biWidth
,
475 (LPSTR
)(mr
->rdParam
+
476 (sizeof(BITMAPINFOHEADER
) / 2) + 4))));
480 s1
= mr
->rdSize
* 2 - sizeof(METARECORD
) - 2;
481 hndl
= GlobalAlloc(GMEM_MOVEABLE
, s1
);
482 ptr
= GlobalLock(hndl
);
483 memcpy(ptr
, mr
->rdParam
+ 2, s1
);
485 MF_AddHandle(ht
, nHandles
,
486 CreateDIBPatternBrush(hndl
, *(mr
->rdParam
+ 1)));
491 case META_CREATEPENINDIRECT
:
492 MF_AddHandle(ht
, nHandles
,
493 CreatePenIndirect((LOGPEN
*)(&(mr
->rdParam
))));
496 case META_CREATEFONTINDIRECT
:
497 MF_AddHandle(ht
, nHandles
,
498 CreateFontIndirect((LOGFONT
*)(&(mr
->rdParam
))));
501 case META_CREATEBRUSHINDIRECT
:
502 MF_AddHandle(ht
, nHandles
,
503 CreateBrushIndirect((LOGBRUSH
*)(&(mr
->rdParam
))));
507 fprintf(stderr
,"PlayMetaFileRecord: Unknown record type %x\n",
513 /******************************************************************
516 BOOL
MF_WriteRecord(HMETAFILE hmf
, METARECORD
*mr
, WORD rlen
)
519 METAFILE
*mf
= (METAFILE
*)GlobalLock(hmf
);
520 METAHEADER
*mh
= (METAHEADER
*)GlobalLock(mf
->hMetaHdr
);
522 if (mh
->mtType
== 0) /* memory based metafile */
524 len
= mh
->mtSize
* 2 + rlen
;
525 GlobalUnlock(mf
->hMetaHdr
);
526 mf
->hMetaHdr
= GlobalReAlloc(mf
->hMetaHdr
, len
, GMEM_MOVEABLE
);
527 mh
= (METAHEADER
*)GlobalLock(mf
->hMetaHdr
);
528 memcpy(mh
+ mh
->mtSize
* 2, mr
, rlen
);
530 else if (mh
->mtType
== 1) /* disk based metafile */
532 if (_lwrite(mf
->hFile
, (char *)mr
, rlen
) == -1)
534 GlobalUnlock(mf
->hMetaHdr
);
540 GlobalUnlock(mf
->hMetaHdr
);
544 mh
->mtSize
+= rlen
/ 2;
545 mh
->mtMaxRecord
= max(mh
->mtMaxRecord
, rlen
/ 2);
546 GlobalUnlock(mf
->hMetaHdr
);
551 /******************************************************************
554 * Add a handle to an external handle table and return the index
556 int MF_AddHandle(HANDLETABLE
*ht
, WORD htlen
, HANDLE hobj
)
560 for (i
= 0; i
< htlen
; i
++)
562 if (*(ht
->objectHandle
+ i
) == 0)
564 *(ht
->objectHandle
+ i
) = hobj
;
572 /******************************************************************
573 * MF_AddHandleInternal
575 * Add a handle to the internal handle table and return the index
577 int MF_AddHandleInternal(HANDLE hobj
)
580 HANDLETABLE
*ht
= (HANDLETABLE
*)GlobalLock(hHT
);
582 for (i
= 0; i
< HTLen
; i
++)
584 if (*(ht
->objectHandle
+ i
) == 0)
586 *(ht
->objectHandle
+ i
) = hobj
;
592 if (!(hHT
= GlobalReAlloc(hHT
, HTINCR
, GMEM_MOVEABLE
| GMEM_ZEROINIT
)))
595 ht
= (HANDLETABLE
*)GlobalLock(hHT
);
596 *(ht
->objectHandle
+ i
) = hobj
;
602 /******************************************************************
605 BOOL
MF_MetaParam0(DC
*dc
, short func
)
608 METARECORD
*mr
= (METARECORD
*)&buffer
;
611 mr
->rdFunction
= func
;
612 return MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
616 /******************************************************************
619 BOOL
MF_MetaParam1(DC
*dc
, short func
, short param1
)
622 METARECORD
*mr
= (METARECORD
*)&buffer
;
625 mr
->rdFunction
= func
;
626 *(mr
->rdParam
) = param1
;
627 return MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
631 /******************************************************************
634 BOOL
MF_MetaParam2(DC
*dc
, short func
, short param1
, short param2
)
637 METARECORD
*mr
= (METARECORD
*)&buffer
;
640 mr
->rdFunction
= func
;
641 *(mr
->rdParam
) = param2
;
642 *(mr
->rdParam
+ 1) = param1
;
643 return MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
647 /******************************************************************
650 BOOL
MF_MetaParam4(DC
*dc
, short func
, short param1
, short param2
,
651 short param3
, short param4
)
654 METARECORD
*mr
= (METARECORD
*)&buffer
;
657 mr
->rdFunction
= func
;
658 *(mr
->rdParam
) = param4
;
659 *(mr
->rdParam
+ 1) = param3
;
660 *(mr
->rdParam
+ 2) = param2
;
661 *(mr
->rdParam
+ 3) = param1
;
662 return MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
666 /******************************************************************
669 BOOL
MF_MetaParam6(DC
*dc
, short func
, short param1
, short param2
,
670 short param3
, short param4
, short param5
, short param6
)
673 METARECORD
*mr
= (METARECORD
*)&buffer
;
676 mr
->rdFunction
= func
;
677 *(mr
->rdParam
) = param6
;
678 *(mr
->rdParam
+ 1) = param5
;
679 *(mr
->rdParam
+ 2) = param4
;
680 *(mr
->rdParam
+ 3) = param3
;
681 *(mr
->rdParam
+ 4) = param2
;
682 *(mr
->rdParam
+ 5) = param1
;
683 return MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
687 /******************************************************************
690 BOOL
MF_MetaParam8(DC
*dc
, short func
, short param1
, short param2
,
691 short param3
, short param4
, short param5
,
692 short param6
, short param7
, short param8
)
695 METARECORD
*mr
= (METARECORD
*)&buffer
;
698 mr
->rdFunction
= func
;
699 *(mr
->rdParam
) = param8
;
700 *(mr
->rdParam
+ 1) = param7
;
701 *(mr
->rdParam
+ 2) = param6
;
702 *(mr
->rdParam
+ 3) = param5
;
703 *(mr
->rdParam
+ 4) = param4
;
704 *(mr
->rdParam
+ 5) = param3
;
705 *(mr
->rdParam
+ 6) = param2
;
706 *(mr
->rdParam
+ 7) = param1
;
707 return MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
711 /******************************************************************
712 * MF_CreateBrushIndirect
714 BOOL
MF_CreateBrushIndirect(DC
*dc
, HBRUSH hBrush
, LOGBRUSH
*logbrush
)
718 char buffer
[sizeof(METARECORD
) - 2 + sizeof(LOGBRUSH
)];
719 METARECORD
*mr
= (METARECORD
*)&buffer
;
723 mr
->rdSize
= (sizeof(METARECORD
) + sizeof(LOGBRUSH
) - 2) / 2;
724 mr
->rdFunction
= META_CREATEBRUSHINDIRECT
;
725 memcpy(&(mr
->rdParam
), logbrush
, sizeof(LOGBRUSH
));
726 if (!MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2))
729 mr
->rdSize
= sizeof(METARECORD
) / 2;
730 mr
->rdFunction
= META_SELECTOBJECT
;
731 if ((index
= MF_AddHandleInternal(hBrush
)) == -1)
734 mf
= (METAFILE
*)GlobalLock(dc
->w
.hMetaFile
);
735 mh
= (METAHEADER
*)GlobalLock(mf
->hMetaHdr
);
736 *(mr
->rdParam
) = index
;
737 if (index
>= mh
->mtNoObjects
)
739 rc
= MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
740 GlobalUnlock(mf
->hMetaHdr
);
741 GlobalUnlock(dc
->w
.hMetaFile
);
746 /******************************************************************
747 * MF_CreatePatternBrush
749 BOOL
MF_CreatePatternBrush(DC
*dc
, HBRUSH hBrush
, LOGBRUSH
*logbrush
)
751 DWORD len
, bmSize
, biSize
;
756 BITMAPINFOHEADER
*infohdr
;
759 char buffer
[sizeof(METARECORD
)];
763 switch (logbrush
->lbStyle
)
766 bmp
= (BITMAPOBJ
*)GDI_GetObjPtr(logbrush
->lbHatch
, BITMAP_MAGIC
);
767 if (!bmp
) return FALSE
;
768 len
= sizeof(METARECORD
) + sizeof(BITMAPINFOHEADER
) +
769 (bmp
->bitmap
.bmHeight
* bmp
->bitmap
.bmWidthBytes
) + 6;
770 if (!(hmr
= GlobalAlloc(GMEM_MOVEABLE
, len
)))
772 mr
= (METARECORD
*)GlobalLock(hmr
);
774 mr
->rdFunction
= META_DIBCREATEPATTERNBRUSH
;
775 mr
->rdSize
= len
/ 2;
776 *(mr
->rdParam
) = logbrush
->lbStyle
;
777 *(mr
->rdParam
+ 1) = DIB_RGB_COLORS
;
778 infohdr
= (BITMAPINFOHEADER
*)(mr
->rdParam
+ 2);
779 infohdr
->biSize
= sizeof(BITMAPINFOHEADER
);
780 infohdr
->biWidth
= bmp
->bitmap
.bmWidth
;
781 infohdr
->biHeight
= bmp
->bitmap
.bmHeight
;
782 infohdr
->biPlanes
= bmp
->bitmap
.bmPlanes
;
783 infohdr
->biBitCount
= bmp
->bitmap
.bmBitsPixel
;
784 memcpy(mr
->rdParam
+ (sizeof(BITMAPINFOHEADER
) / 2) + 4,
786 bmp
->bitmap
.bmHeight
* bmp
->bitmap
.bmWidthBytes
);
790 info
= (BITMAPINFO
*)GlobalLock(logbrush
->lbHatch
);
791 bmSize
= info
->bmiHeader
.biSizeImage
;
793 bmSize
= (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
794 + 31) / 32 * 8 * info
->bmiHeader
.biHeight
;
795 biSize
= DIB_BitmapInfoSize(info
, LOWORD(logbrush
->lbColor
));
796 len
= sizeof(METARECORD
) + biSize
+ bmSize
+ 2;
797 if (!(hmr
= GlobalAlloc(GMEM_MOVEABLE
, len
)))
799 mr
= (METARECORD
*)GlobalLock(hmr
);
801 mr
->rdFunction
= META_DIBCREATEPATTERNBRUSH
;
802 mr
->rdSize
= len
/ 2;
803 *(mr
->rdParam
) = logbrush
->lbStyle
;
804 *(mr
->rdParam
+ 1) = LOWORD(logbrush
->lbColor
);
805 memcpy(mr
->rdParam
+ 2, info
, biSize
+ bmSize
);
808 if (!MF_WriteRecord(dc
->w
.hMetaFile
, mr
, len
))
815 mr
= (METARECORD
*)&buffer
;
816 mr
->rdSize
= sizeof(METARECORD
) / 2;
817 mr
->rdFunction
= META_SELECTOBJECT
;
818 if ((index
= MF_AddHandleInternal(hBrush
)) == -1)
821 mf
= (METAFILE
*)GlobalLock(dc
->w
.hMetaFile
);
822 mh
= (METAHEADER
*)GlobalLock(mf
->hMetaHdr
);
823 *(mr
->rdParam
) = index
;
824 if (index
>= mh
->mtNoObjects
)
826 rc
= MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
827 GlobalUnlock(mf
->hMetaHdr
);
828 GlobalUnlock(dc
->w
.hMetaFile
);
833 /******************************************************************
834 * MF_CreatePenIndirect
836 BOOL
MF_CreatePenIndirect(DC
*dc
, HPEN hPen
, LOGPEN
*logpen
)
840 char buffer
[sizeof(METARECORD
) - 2 + sizeof(LOGPEN
)];
841 METARECORD
*mr
= (METARECORD
*)&buffer
;
845 mr
->rdSize
= (sizeof(METARECORD
) + sizeof(LOGPEN
) - 2) / 2;
846 mr
->rdFunction
= META_CREATEPENINDIRECT
;
847 memcpy(&(mr
->rdParam
), logpen
, sizeof(LOGPEN
));
848 if (!MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2))
851 mr
->rdSize
= sizeof(METARECORD
) / 2;
852 mr
->rdFunction
= META_SELECTOBJECT
;
853 if ((index
= MF_AddHandleInternal(hPen
)) == -1)
856 mf
= (METAFILE
*)GlobalLock(dc
->w
.hMetaFile
);
857 mh
= (METAHEADER
*)GlobalLock(mf
->hMetaHdr
);
858 *(mr
->rdParam
) = index
;
859 if (index
>= mh
->mtNoObjects
)
861 rc
= MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
862 GlobalUnlock(mf
->hMetaHdr
);
863 GlobalUnlock(dc
->w
.hMetaFile
);
868 /******************************************************************
869 * MF_CreateFontIndirect
871 BOOL
MF_CreateFontIndirect(DC
*dc
, HFONT hFont
, LOGFONT
*logfont
)
875 char buffer
[sizeof(METARECORD
) - 2 + sizeof(LOGFONT
)];
876 METARECORD
*mr
= (METARECORD
*)&buffer
;
880 mr
->rdSize
= (sizeof(METARECORD
) + sizeof(LOGFONT
) - 2) / 2;
881 mr
->rdFunction
= META_CREATEFONTINDIRECT
;
882 memcpy(&(mr
->rdParam
), logfont
, sizeof(LOGFONT
));
883 if (!MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2))
886 mr
->rdSize
= sizeof(METARECORD
) / 2;
887 mr
->rdFunction
= META_SELECTOBJECT
;
888 if ((index
= MF_AddHandleInternal(hFont
)) == -1)
891 mf
= (METAFILE
*)GlobalLock(dc
->w
.hMetaFile
);
892 mh
= (METAHEADER
*)GlobalLock(mf
->hMetaHdr
);
893 *(mr
->rdParam
) = index
;
894 if (index
>= mh
->mtNoObjects
)
896 rc
= MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
897 GlobalUnlock(mf
->hMetaHdr
);
898 GlobalUnlock(dc
->w
.hMetaFile
);
903 /******************************************************************
906 BOOL
MF_TextOut(DC
*dc
, short x
, short y
, LPSTR str
, short count
)
913 len
= sizeof(METARECORD
) + (((count
+ 1) >> 1) * 2) + 4;
914 if (!(hmr
= GlobalAlloc(GMEM_MOVEABLE
, len
)))
916 mr
= (METARECORD
*)GlobalLock(hmr
);
919 mr
->rdSize
= len
/ 2;
920 mr
->rdFunction
= META_TEXTOUT
;
921 *(mr
->rdParam
) = count
;
922 memcpy(mr
->rdParam
+ 1, str
, count
);
923 *(mr
->rdParam
+ ((count
+ 1) >> 1) + 1) = y
;
924 *(mr
->rdParam
+ ((count
+ 1) >> 1) + 2) = x
;
925 rc
= MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
931 /******************************************************************
932 * MF_MetaPoly - implements Polygon and Polyline
934 BOOL
MF_MetaPoly(DC
*dc
, short func
, LPPOINT pt
, short count
)
941 len
= sizeof(METARECORD
) + (count
* 4);
942 if (!(hmr
= GlobalAlloc(GMEM_MOVEABLE
, len
)))
944 mr
= (METARECORD
*)GlobalLock(hmr
);
947 mr
->rdSize
= len
/ 2;
948 mr
->rdFunction
= func
;
949 *(mr
->rdParam
) = count
;
950 memcpy(mr
->rdParam
+ 1, pt
, count
* 4);
951 rc
= MF_WriteRecord(dc
->w
.hMetaFile
, mr
, mr
->rdSize
* 2);
957 /******************************************************************
960 BOOL
MF_BitBlt(DC
*dcDest
, short xDest
, short yDest
, short width
,
961 short height
, HDC hdcSrc
, short xSrc
, short ySrc
, DWORD rop
)
963 fprintf(stdnimp
,"MF_BitBlt: not implemented yet\n");
967 /******************************************************************
970 BOOL
MF_StretchBlt(DC
*dcDest
, short xDest
, short yDest
, short widthDest
,
971 short heightDest
, HDC hdcSrc
, short xSrc
, short ySrc
,
972 short widthSrc
, short heightSrc
, DWORD rop
)
974 fprintf(stdnimp
,"MF_StretchBlt: not implemented yet\n");