4 * Copyright David W. Metcalfe, 1994
5 * Niels de Carpentier, Albrecht Kleine, Huw Davies 1996
17 #include "metafiledrv.h"
21 /******************************************************************
24 * Add a handle to an external handle table and return the index
27 static int MF_AddHandle(HANDLETABLE16
*ht
, WORD htlen
, HGDIOBJ16 hobj
)
31 for (i
= 0; i
< htlen
; i
++)
33 if (*(ht
->objectHandle
+ i
) == 0)
35 *(ht
->objectHandle
+ i
) = hobj
;
43 /******************************************************************
46 * Note: this function assumes that we never delete objects.
47 * If we do someday, we'll need to maintain a table to re-use deleted
50 static int MF_AddHandleDC( DC
*dc
)
52 METAFILEDRV_PDEVICE
*physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
53 physDev
->mh
->mtNoObjects
++;
54 return physDev
->nextHandle
++;
58 /******************************************************************
59 * GetMetaFile16 (GDI.124)
61 HMETAFILE16 WINAPI
GetMetaFile16( LPCSTR lpFilename
)
63 return GetMetaFile32A( lpFilename
);
67 /******************************************************************
68 * GetMetaFile32A (GDI32.197)
70 * Read a metafile from a file. Returns handle to a disk-based metafile.
72 HMETAFILE32 WINAPI
GetMetaFile32A(
74 /* pointer to string containing filename to read */
82 TRACE(metafile
,"%s\n", lpFilename
);
87 hmf
= GlobalAlloc16(GMEM_MOVEABLE
, MFHEADERSIZE
);
88 mh
= (METAHEADER
*)GlobalLock16(hmf
);
96 if ((hFile
= _lopen32(lpFilename
, OF_READ
)) == HFILE_ERROR32
)
102 if (_lread32(hFile
, (char *)mh
, MFHEADERSIZE
) == HFILE_ERROR32
)
109 size
= mh
->mtSize
* 2; /* alloc memory for whole metafile */
111 hmf
= GlobalReAlloc16(hmf
,size
,GMEM_MOVEABLE
);
112 mh
= (METAHEADER
*)GlobalLock16(hmf
);
121 if (_lread32(hFile
, (char*)mh
+ mh
->mtHeaderSize
* 2,
122 size
- mh
->mtHeaderSize
* 2) == HFILE_ERROR32
)
143 /******************************************************************
144 * GetMetaFile32W (GDI32.199)
146 HMETAFILE32 WINAPI
GetMetaFile32W( LPCWSTR lpFilename
)
148 LPSTR p
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpFilename
);
149 HMETAFILE32 ret
= GetMetaFile32A( p
);
150 HeapFree( GetProcessHeap(), 0, p
);
155 /******************************************************************
156 * CopyMetaFile16 (GDI.151)
159 HMETAFILE16 WINAPI
CopyMetaFile16( HMETAFILE16 hSrcMetaFile
, LPCSTR lpFilename
)
161 return CopyMetaFile32A( hSrcMetaFile
, lpFilename
);
165 /******************************************************************
166 * CopyMetaFile32A (GDI32.23)
168 * Copies the metafile corresponding to hSrcMetaFile to either
169 * a disk file, if a filename is given, or to a new memory based
170 * metafile, if lpFileName is NULL.
174 * Handle to metafile copy on success, NULL on failure.
178 * Copying to disk returns NULL even if successful.
180 HMETAFILE32 WINAPI
CopyMetaFile32A(
181 HMETAFILE32 hSrcMetaFile
, /* handle of metafile to copy */
182 LPCSTR lpFilename
/* filename if copying to a file */
184 HMETAFILE16 handle
= 0;
189 TRACE(metafile
,"(%08x,%s)\n", hSrcMetaFile
, lpFilename
);
191 mh
= (METAHEADER
*)GlobalLock16(hSrcMetaFile
);
196 if (lpFilename
) /* disk based metafile */
199 hFile
= _lcreat32(lpFilename
, 0);
201 mh
->mtType
=1; /* disk file version stores 1 here */
202 i
=_lwrite32(hFile
, (char *)mh
, mh
->mtSize
* 2) ;
203 mh
->mtType
=j
; /* restore old value [0 or 1] */
207 /* FIXME: return value */
209 else /* memory based metafile */
211 handle
= GlobalAlloc16(GMEM_MOVEABLE
,mh
->mtSize
* 2);
212 mh2
= (METAHEADER
*)GlobalLock16(handle
);
213 memcpy(mh2
,mh
, mh
->mtSize
* 2);
214 GlobalUnlock16(handle
);
217 GlobalUnlock16(hSrcMetaFile
);
222 /******************************************************************
223 * CopyMetaFile32W (GDI32.24)
225 HMETAFILE32 WINAPI
CopyMetaFile32W( HMETAFILE32 hSrcMetaFile
,
228 LPSTR p
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpFilename
);
229 HMETAFILE32 ret
= CopyMetaFile32A( hSrcMetaFile
, p
);
230 HeapFree( GetProcessHeap(), 0, p
);
235 /******************************************************************
236 * IsValidMetaFile (GDI.410)
238 * Attempts to check if a given metafile is correctly formatted.
239 * Currently, the only things verified are several properties of the
243 * TRUE if hmf passes some tests for being a valid metafile, FALSE otherwise.
246 * This is not exactly what windows does, see _Undocumented_Windows_
250 BOOL16 WINAPI
IsValidMetaFile(HMETAFILE16 hmf
)
253 METAHEADER
*mh
= (METAHEADER
*)GlobalLock16(hmf
);
255 if (mh
->mtType
== 1 || mh
->mtType
== 0)
256 if (mh
->mtHeaderSize
== MFHEADERSIZE
/sizeof(INT16
))
257 if (mh
->mtVersion
== MFVERSION
)
261 TRACE(metafile
,"IsValidMetaFile %x => %d\n",hmf
,resu
);
266 /******************************************************************
267 * PlayMetaFile16 (GDI.123)
270 BOOL16 WINAPI
PlayMetaFile16( HDC16 hdc
, HMETAFILE16 hmf
)
272 return PlayMetaFile32( hdc
, hmf
);
275 /******************************************************************
276 * PlayMetaFile32 (GDI32.265)
278 * Renders the metafile specified by hmf in the DC specified by
279 * hdc. Returns FALSE on failure, TRUE on success.
281 BOOL32 WINAPI
PlayMetaFile32(
282 HDC32 hdc
, /* handle of DC to render in */
283 HMETAFILE32 hmf
/* handle of metafile to render */
286 METAHEADER
*mh
= (METAHEADER
*)GlobalLock16(hmf
);
297 TRACE(metafile
,"(%04x %04x)\n",hdc
,hmf
);
298 if (!mh
) return FALSE
;
300 /* save the current pen, brush and font */
301 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
303 hBrush
= dc
->w
.hBrush
;
305 GDI_HEAP_UNLOCK(hdc
);
306 /* create the handle table */
307 hHT
= GlobalAlloc16(GMEM_MOVEABLE
|GMEM_ZEROINIT
,
308 sizeof(HANDLETABLE16
) * mh
->mtNoObjects
);
309 ht
= (HANDLETABLE16
*)GlobalLock16(hHT
);
312 /* loop through metafile playing records */
313 offset
= mh
->mtHeaderSize
* 2;
314 while (offset
< mh
->mtSize
* 2)
316 mr
= (METARECORD
*)((char *)mh
+ offset
);
317 TRACE(metafile
,"offset=%04x,size=%08lx\n",
320 TRACE(metafile
,"Entry got size 0 at offset %d, total mf length is %ld\n",
321 offset
,mh
->mtSize
*2);
322 break; /* would loop endlessly otherwise */
324 offset
+= mr
->rdSize
* 2;
325 PlayMetaFileRecord16( hdc
, ht
, mr
, mh
->mtNoObjects
);
328 SelectObject32(hdc
, hBrush
);
329 SelectObject32(hdc
, hPen
);
330 SelectObject32(hdc
, hFont
);
332 /* free objects in handle table */
333 for(i
= 0; i
< mh
->mtNoObjects
; i
++)
334 if(*(ht
->objectHandle
+ i
) != 0)
335 DeleteObject32(*(ht
->objectHandle
+ i
));
337 /* free handle table */
344 /******************************************************************
345 * EnumMetaFile16 (GDI.175)
347 * Loop through the metafile records in hmf, calling the user-specified
348 * function for each one, stopping when the user's function returns FALSE
349 * (which is considered to be failure)
350 * or when no records are left (which is considered to be success).
353 * TRUE on success, FALSE on failure.
356 * Niels de carpentier, april 1996
358 BOOL16 WINAPI
EnumMetaFile16(
361 MFENUMPROC16 lpEnumFunc
,
365 METAHEADER
*mh
= (METAHEADER
*)GlobalLock16(hmf
);
376 BOOL16 result
= TRUE
;
378 TRACE(metafile
,"(%04x, %04x, %08lx, %08lx)\n",
379 hdc
, hmf
, (DWORD
)lpEnumFunc
, lpData
);
381 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
383 hBrush
= dc
->w
.hBrush
;
385 GDI_HEAP_UNLOCK(hdc
);
387 /* create the handle table */
389 hHT
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
390 sizeof(HANDLETABLE16
) * mh
->mtNoObjects
);
391 spht
= WIN16_GlobalLock16(hHT
);
393 seg
= GlobalHandleToSel(hmf
);
394 offset
= mh
->mtHeaderSize
* 2;
396 /* loop through metafile records */
398 while (offset
< (mh
->mtSize
* 2))
400 mr
= (METARECORD
*)((char *)mh
+ offset
);
401 if (!lpEnumFunc( hdc
, (HANDLETABLE16
*)spht
,
402 (METARECORD
*) PTR_SEG_OFF_TO_HUGEPTR(seg
, offset
),
403 mh
->mtNoObjects
, (LONG
)lpData
))
410 offset
+= (mr
->rdSize
* 2);
413 SelectObject32(hdc
, hBrush
);
414 SelectObject32(hdc
, hPen
);
415 SelectObject32(hdc
, hFont
);
417 ht
= (HANDLETABLE16
*)GlobalLock16(hHT
);
419 /* free objects in handle table */
420 for(i
= 0; i
< mh
->mtNoObjects
; i
++)
421 if(*(ht
->objectHandle
+ i
) != 0)
422 DeleteObject32(*(ht
->objectHandle
+ i
));
424 /* free handle table */
430 BOOL32 WINAPI
EnumMetaFile32(
433 MFENUMPROC32 lpEnumFunc
,
436 METAHEADER
*mh
= (METAHEADER
*)GlobalLock16(hmf
);
439 BOOL32 result
= TRUE
;
441 DC
*dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
446 TRACE(metafile
,"(%08x,%08x,%p,%p)\n",
447 hdc
, hmf
, lpEnumFunc
, (void*)lpData
);
450 /* save the current pen, brush and font */
453 hBrush
= dc
->w
.hBrush
;
455 GDI_HEAP_UNLOCK(hdc
);
458 ht
= (HANDLETABLE32
*) GlobalAlloc32(GPTR
,
459 sizeof(HANDLETABLE32
) * mh
->mtNoObjects
);
461 /* loop through metafile records */
462 offset
= mh
->mtHeaderSize
* 2;
464 while (offset
< (mh
->mtSize
* 2))
466 mr
= (METARECORD
*)((char *)mh
+ offset
);
467 if (!lpEnumFunc( hdc
, ht
, mr
, mh
->mtNoObjects
, (LONG
)lpData
))
473 offset
+= (mr
->rdSize
* 2);
476 /* restore pen, brush and font */
477 SelectObject32(hdc
, hBrush
);
478 SelectObject32(hdc
, hPen
);
479 SelectObject32(hdc
, hFont
);
481 /* free objects in handle table */
482 for(i
= 0; i
< mh
->mtNoObjects
; i
++)
483 if(*(ht
->objectHandle
+ i
) != 0)
484 DeleteObject32(*(ht
->objectHandle
+ i
));
486 /* free handle table */
487 GlobalFree32((HGLOBAL32
)ht
);
492 static BOOL32
MF_Meta_CreateRegion( METARECORD
*mr
, HRGN32 hrgn
);
494 /******************************************************************
495 * PlayMetaFileRecord16 (GDI.176)
497 * Render a single metafile record specified by *mr in the DC hdc, while
498 * using the handle table *ht, of length nHandles,
499 * to store metafile objects.
502 * The following metafile records are unimplemented:
504 * FRAMEREGION, DRAWTEXT, SETDIBTODEV, ANIMATEPALETTE, SETPALENTRIES,
505 * RESIZEPALETTE, EXTFLOODFILL, RESETDC, STARTDOC, STARTPAGE, ENDPAGE,
506 * ABORTDOC, ENDDOC, CREATEBRUSH, CREATEBITMAPINDIRECT, and CREATEBITMAP.
509 void WINAPI
PlayMetaFileRecord16(
510 HDC16 hdc
, /* DC to render metafile into */
511 HANDLETABLE16
*ht
, /* pointer to handle table for metafile objects */
512 METARECORD
*mr
, /* pointer to metafile record to render */
513 UINT16 nHandles
/* size of handle table */
518 BITMAPINFOHEADER
*infohdr
;
520 TRACE(metafile
,"(%04x %08lx %08lx %04x) function %04x\n",
521 hdc
,(LONG
)ht
, (LONG
)mr
, nHandles
, mr
->rdFunction
);
523 switch (mr
->rdFunction
)
528 case META_DELETEOBJECT
:
529 DeleteObject32(*(ht
->objectHandle
+ *(mr
->rdParam
)));
530 *(ht
->objectHandle
+ *(mr
->rdParam
)) = 0;
533 case META_SETBKCOLOR
:
534 SetBkColor16(hdc
, MAKELONG(*(mr
->rdParam
), *(mr
->rdParam
+ 1)));
538 SetBkMode16(hdc
, *(mr
->rdParam
));
541 case META_SETMAPMODE
:
542 SetMapMode16(hdc
, *(mr
->rdParam
));
546 SetROP216(hdc
, *(mr
->rdParam
));
550 SetRelAbs16(hdc
, *(mr
->rdParam
));
553 case META_SETPOLYFILLMODE
:
554 SetPolyFillMode16(hdc
, *(mr
->rdParam
));
557 case META_SETSTRETCHBLTMODE
:
558 SetStretchBltMode16(hdc
, *(mr
->rdParam
));
561 case META_SETTEXTCOLOR
:
562 SetTextColor16(hdc
, MAKELONG(*(mr
->rdParam
), *(mr
->rdParam
+ 1)));
565 case META_SETWINDOWORG
:
566 SetWindowOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
569 case META_SETWINDOWEXT
:
570 SetWindowExt(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
573 case META_SETVIEWPORTORG
:
574 SetViewportOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
577 case META_SETVIEWPORTEXT
:
578 SetViewportExt(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
581 case META_OFFSETWINDOWORG
:
582 OffsetWindowOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
585 case META_SCALEWINDOWEXT
:
586 ScaleWindowExt(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
587 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
590 case META_OFFSETVIEWPORTORG
:
591 OffsetViewportOrg(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
594 case META_SCALEVIEWPORTEXT
:
595 ScaleViewportExt(hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
596 *(mr
->rdParam
+ 1), *(mr
->rdParam
));
600 LineTo32(hdc
, (INT16
)*(mr
->rdParam
+ 1), (INT16
)*(mr
->rdParam
));
604 MoveTo(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
607 case META_EXCLUDECLIPRECT
:
608 ExcludeClipRect16( hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
609 *(mr
->rdParam
+ 1), *(mr
->rdParam
) );
612 case META_INTERSECTCLIPRECT
:
613 IntersectClipRect16( hdc
, *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
614 *(mr
->rdParam
+ 1), *(mr
->rdParam
) );
618 Arc32(hdc
, (INT16
)*(mr
->rdParam
+ 7), (INT16
)*(mr
->rdParam
+ 6),
619 (INT16
)*(mr
->rdParam
+ 5), (INT16
)*(mr
->rdParam
+ 4),
620 (INT16
)*(mr
->rdParam
+ 3), (INT16
)*(mr
->rdParam
+ 2),
621 (INT16
)*(mr
->rdParam
+ 1), (INT16
)*(mr
->rdParam
));
625 Ellipse32(hdc
, (INT16
)*(mr
->rdParam
+ 3), (INT16
)*(mr
->rdParam
+ 2),
626 (INT16
)*(mr
->rdParam
+ 1), (INT16
)*(mr
->rdParam
));
630 FloodFill32(hdc
, (INT16
)*(mr
->rdParam
+ 3), (INT16
)*(mr
->rdParam
+ 2),
631 MAKELONG(*(mr
->rdParam
), *(mr
->rdParam
+ 1)));
635 Pie32(hdc
, (INT16
)*(mr
->rdParam
+ 7), (INT16
)*(mr
->rdParam
+ 6),
636 (INT16
)*(mr
->rdParam
+ 5), (INT16
)*(mr
->rdParam
+ 4),
637 (INT16
)*(mr
->rdParam
+ 3), (INT16
)*(mr
->rdParam
+ 2),
638 (INT16
)*(mr
->rdParam
+ 1), (INT16
)*(mr
->rdParam
));
642 Rectangle32(hdc
, (INT16
)*(mr
->rdParam
+ 3), (INT16
)*(mr
->rdParam
+ 2),
643 (INT16
)*(mr
->rdParam
+ 1), (INT16
)*(mr
->rdParam
));
647 RoundRect32(hdc
, (INT16
)*(mr
->rdParam
+ 5), (INT16
)*(mr
->rdParam
+ 4),
648 (INT16
)*(mr
->rdParam
+ 3), (INT16
)*(mr
->rdParam
+ 2),
649 (INT16
)*(mr
->rdParam
+ 1), (INT16
)*(mr
->rdParam
));
653 PatBlt16(hdc
, *(mr
->rdParam
+ 5), *(mr
->rdParam
+ 4),
654 *(mr
->rdParam
+ 3), *(mr
->rdParam
+ 2),
655 MAKELONG(*(mr
->rdParam
), *(mr
->rdParam
+ 1)));
663 SetPixel32(hdc
, (INT16
)*(mr
->rdParam
+ 3), (INT16
)*(mr
->rdParam
+ 2),
664 MAKELONG(*(mr
->rdParam
), *(mr
->rdParam
+ 1)));
667 case META_OFFSETCLIPRGN
:
668 OffsetClipRgn16( hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
) );
673 TextOut16(hdc
, *(mr
->rdParam
+ ((s1
+ 1) >> 1) + 2),
674 *(mr
->rdParam
+ ((s1
+ 1) >> 1) + 1),
675 (char *)(mr
->rdParam
+ 1), s1
);
679 Polygon16(hdc
, (LPPOINT16
)(mr
->rdParam
+ 1), *(mr
->rdParam
));
682 case META_POLYPOLYGON
:
683 PolyPolygon16(hdc
, (LPPOINT16
)(mr
->rdParam
+ *(mr
->rdParam
) + 1),
684 (LPINT16
)(mr
->rdParam
+ 1), *(mr
->rdParam
));
688 Polyline16(hdc
, (LPPOINT16
)(mr
->rdParam
+ 1), *(mr
->rdParam
));
692 RestoreDC32(hdc
, (INT16
)*(mr
->rdParam
));
695 case META_SELECTOBJECT
:
696 SelectObject32(hdc
, *(ht
->objectHandle
+ *(mr
->rdParam
)));
700 Chord32(hdc
, (INT16
)*(mr
->rdParam
+ 7), (INT16
)*(mr
->rdParam
+ 6),
701 (INT16
)*(mr
->rdParam
+5), (INT16
)*(mr
->rdParam
+ 4),
702 (INT16
)*(mr
->rdParam
+ 3), (INT16
)*(mr
->rdParam
+ 2),
703 (INT16
)*(mr
->rdParam
+ 1), (INT16
)*(mr
->rdParam
));
706 case META_CREATEPATTERNBRUSH
:
707 switch (*(mr
->rdParam
))
710 infohdr
= (BITMAPINFOHEADER
*)(mr
->rdParam
+ 2);
711 MF_AddHandle(ht
, nHandles
,
712 CreatePatternBrush32(CreateBitmap32(infohdr
->biWidth
,
716 (LPSTR
)(mr
->rdParam
+
717 (sizeof(BITMAPINFOHEADER
) / 2) + 4))));
721 s1
= mr
->rdSize
* 2 - sizeof(METARECORD
) - 2;
722 hndl
= GlobalAlloc16(GMEM_MOVEABLE
, s1
);
723 ptr
= GlobalLock16(hndl
);
724 memcpy(ptr
, mr
->rdParam
+ 2, s1
);
725 GlobalUnlock16(hndl
);
726 MF_AddHandle(ht
, nHandles
,
727 CreateDIBPatternBrush32(hndl
, *(mr
->rdParam
+ 1)));
732 case META_CREATEPENINDIRECT
:
733 MF_AddHandle(ht
, nHandles
,
734 CreatePenIndirect16((LOGPEN16
*)(&(mr
->rdParam
))));
737 case META_CREATEFONTINDIRECT
:
738 MF_AddHandle(ht
, nHandles
,
739 CreateFontIndirect16((LOGFONT16
*)(&(mr
->rdParam
))));
742 case META_CREATEBRUSHINDIRECT
:
743 MF_AddHandle(ht
, nHandles
,
744 CreateBrushIndirect16((LOGBRUSH16
*)(&(mr
->rdParam
))));
747 /* W. Magro: Some new metafile operations. Not all debugged. */
748 case META_CREATEPALETTE
:
749 MF_AddHandle(ht
, nHandles
,
750 CreatePalette16((LPLOGPALETTE
)mr
->rdParam
));
753 case META_SETTEXTALIGN
:
754 SetTextAlign16(hdc
, *(mr
->rdParam
));
757 case META_SELECTPALETTE
:
758 SelectPalette16(hdc
, *(ht
->objectHandle
+ *(mr
->rdParam
+1)),*(mr
->rdParam
));
761 case META_SETMAPPERFLAGS
:
762 SetMapperFlags16(hdc
, *(mr
->rdParam
));
765 case META_REALIZEPALETTE
:
766 RealizePalette16(hdc
);
770 FIXME(metafile
, "META_ESCAPE unimplemented.\n");
773 /* --- Begin of fixed or new metafile operations. July 1996 ----*/
774 case META_EXTTEXTOUT
:
780 s1
= mr
->rdParam
[2]; /* String length */
781 len
= sizeof(METARECORD
) + (((s1
+ 1) >> 1) * 2) + 2 * sizeof(short)
782 + sizeof(UINT16
) + (mr
->rdParam
[3] ? sizeof(RECT16
) : 0); /* rec len without dx array */
784 sot
= (LPSTR
)&mr
->rdParam
[4]; /* start_of_text */
786 sot
+=sizeof(RECT16
); /* there is a rectangle, so add offset */
788 if (mr
->rdSize
== len
/ 2)
789 dxx
= NULL
; /* determine if array present */
791 if (mr
->rdSize
== (len
+ s1
* sizeof(INT16
)) / 2)
792 dxx
= (LPINT16
)(sot
+(((s1
+1)>>1)*2));
795 TRACE(metafile
,"%s len: %ld\n",
798 "Please report: PlayMetaFile/ExtTextOut len=%ld slen=%d rdSize=%ld opt=%04x\n",
799 len
,s1
,mr
->rdSize
,mr
->rdParam
[3]);
800 dxx
= NULL
; /* should't happen -- but if, we continue with NULL [for workaround] */
802 ExtTextOut16( hdc
, mr
->rdParam
[1], /* X position */
803 mr
->rdParam
[0], /* Y position */
804 mr
->rdParam
[3], /* options */
805 mr
->rdParam
[3] ? (LPRECT16
) &mr
->rdParam
[4]:NULL
, /* rectangle */
807 s1
, dxx
); /* length, dx array */
809 TRACE(metafile
,"%s len: %ld dx0: %d\n",
810 sot
,mr
->rdSize
,dxx
[0]);
814 case META_STRETCHDIB
:
816 LPBITMAPINFO info
= (LPBITMAPINFO
) &(mr
->rdParam
[11]);
817 LPSTR bits
= (LPSTR
)info
+ DIB_BitmapInfoSize( info
, mr
->rdParam
[2] );
818 StretchDIBits16(hdc
,mr
->rdParam
[10],mr
->rdParam
[9],mr
->rdParam
[8],
819 mr
->rdParam
[7],mr
->rdParam
[6],mr
->rdParam
[5],
820 mr
->rdParam
[4],mr
->rdParam
[3],bits
,info
,
821 mr
->rdParam
[2],MAKELONG(mr
->rdParam
[0],mr
->rdParam
[1]));
825 case META_DIBSTRETCHBLT
:
827 LPBITMAPINFO info
= (LPBITMAPINFO
) &(mr
->rdParam
[10]);
828 LPSTR bits
= (LPSTR
)info
+ DIB_BitmapInfoSize( info
, mr
->rdParam
[2] );
829 StretchDIBits16(hdc
,mr
->rdParam
[9],mr
->rdParam
[8],mr
->rdParam
[7],
830 mr
->rdParam
[6],mr
->rdParam
[5],mr
->rdParam
[4],
831 mr
->rdParam
[3],mr
->rdParam
[2],bits
,info
,
832 DIB_RGB_COLORS
,MAKELONG(mr
->rdParam
[0],mr
->rdParam
[1]));
836 case META_STRETCHBLT
:
838 HDC16 hdcSrc
=CreateCompatibleDC16(hdc
);
839 HBITMAP32 hbitmap
=CreateBitmap32(mr
->rdParam
[10], /*Width */
840 mr
->rdParam
[11], /*Height*/
841 mr
->rdParam
[13], /*Planes*/
842 mr
->rdParam
[14], /*BitsPixel*/
843 (LPSTR
)&mr
->rdParam
[15]); /*bits*/
844 SelectObject32(hdcSrc
,hbitmap
);
845 StretchBlt16(hdc
,mr
->rdParam
[9],mr
->rdParam
[8],
846 mr
->rdParam
[7],mr
->rdParam
[6],
847 hdcSrc
,mr
->rdParam
[5],mr
->rdParam
[4],
848 mr
->rdParam
[3],mr
->rdParam
[2],
849 MAKELONG(mr
->rdParam
[0],mr
->rdParam
[1]));
854 case META_BITBLT
: /* <-- not yet debugged */
856 HDC16 hdcSrc
=CreateCompatibleDC16(hdc
);
857 HBITMAP32 hbitmap
=CreateBitmap32(mr
->rdParam
[7]/*Width */,
858 mr
->rdParam
[8]/*Height*/,
859 mr
->rdParam
[10]/*Planes*/,
860 mr
->rdParam
[11]/*BitsPixel*/,
861 (LPSTR
)&mr
->rdParam
[12]/*bits*/);
862 SelectObject32(hdcSrc
,hbitmap
);
863 BitBlt32(hdc
,(INT16
)mr
->rdParam
[6],(INT16
)mr
->rdParam
[5],
864 (INT16
)mr
->rdParam
[4],(INT16
)mr
->rdParam
[3],
865 hdcSrc
, (INT16
)mr
->rdParam
[2],(INT16
)mr
->rdParam
[1],
866 MAKELONG(0,mr
->rdParam
[0]));
871 /* --- Begin of new metafile operations. April, 1997 (ak) ----*/
872 case META_CREATEREGION
:
874 HRGN32 hrgn
= CreateRectRgn32(0,0,0,0);
876 MF_Meta_CreateRegion(mr
, hrgn
);
877 MF_AddHandle(ht
, nHandles
, hrgn
);
881 case META_FILLREGION
:
882 FillRgn16(hdc
, *(ht
->objectHandle
+ *(mr
->rdParam
)),
883 *(ht
->objectHandle
+ *(mr
->rdParam
+1)));
886 case META_INVERTREGION
:
887 InvertRgn16(hdc
, *(ht
->objectHandle
+ *(mr
->rdParam
)));
890 case META_PAINTREGION
:
891 PaintRgn16(hdc
, *(ht
->objectHandle
+ *(mr
->rdParam
)));
894 case META_SELECTCLIPREGION
:
895 SelectClipRgn32(hdc
, *(ht
->objectHandle
+ *(mr
->rdParam
)));
898 case META_DIBCREATEPATTERNBRUSH
:
899 /* *(mr->rdParam) may be BS_PATTERN or BS_DIBPATTERN: but there's no difference */
900 TRACE(metafile
,"%d\n",*(mr
->rdParam
));
901 s1
= mr
->rdSize
* 2 - sizeof(METARECORD
) - 2;
902 hndl
= GlobalAlloc16(GMEM_MOVEABLE
, s1
);
903 ptr
= GlobalLock16(hndl
);
904 memcpy(ptr
, mr
->rdParam
+ 2, s1
);
905 GlobalUnlock16(hndl
);
906 MF_AddHandle(ht
, nHandles
,CreateDIBPatternBrush16(hndl
, *(mr
->rdParam
+ 1)));
912 LPBITMAPINFO info
= (LPBITMAPINFO
) &(mr
->rdParam
[8]);
913 LPSTR bits
= (LPSTR
)info
+ DIB_BitmapInfoSize( info
, mr
->rdParam
[0] );
914 StretchDIBits16(hdc
,mr
->rdParam
[7],mr
->rdParam
[6],mr
->rdParam
[5],
915 mr
->rdParam
[4],mr
->rdParam
[3],mr
->rdParam
[2],
916 mr
->rdParam
[5],mr
->rdParam
[4],bits
,info
,
917 DIB_RGB_COLORS
,MAKELONG(mr
->rdParam
[0],mr
->rdParam
[1]));
921 case META_SETTEXTCHAREXTRA
:
922 SetTextCharacterExtra16(hdc
, (INT16
)*(mr
->rdParam
));
925 case META_SETTEXTJUSTIFICATION
:
926 SetTextJustification32(hdc
, *(mr
->rdParam
+ 1), *(mr
->rdParam
));
929 #define META_UNIMP(x) case x: FIXME(metafile, "PlayMetaFileRecord:record type "#x" not implemented.\n");break;
930 META_UNIMP(META_FRAMEREGION
)
931 META_UNIMP(META_DRAWTEXT
)
932 META_UNIMP(META_SETDIBTODEV
)
933 META_UNIMP(META_ANIMATEPALETTE
)
934 META_UNIMP(META_SETPALENTRIES
)
935 META_UNIMP(META_RESIZEPALETTE
)
936 META_UNIMP(META_EXTFLOODFILL
)
937 META_UNIMP(META_RESETDC
)
938 META_UNIMP(META_STARTDOC
)
939 META_UNIMP(META_STARTPAGE
)
940 META_UNIMP(META_ENDPAGE
)
941 META_UNIMP(META_ABORTDOC
)
942 META_UNIMP(META_ENDDOC
)
943 META_UNIMP(META_CREATEBRUSH
)
944 META_UNIMP(META_CREATEBITMAPINDIRECT
)
945 META_UNIMP(META_CREATEBITMAP
)
949 WARN(metafile
, "PlayMetaFileRecord: Unknown record type %x\n",
955 BOOL32 WINAPI
PlayMetaFileRecord32(
957 HANDLETABLE32
*handletable
,
958 METARECORD
*metarecord
,
962 HANDLETABLE16
* ht
= (void *)GlobalAlloc32(GPTR
,
963 handles
*sizeof(HANDLETABLE16
));
965 TRACE(metafile
, "(%08x,%p,%p,%d)\n", hdc
, handletable
, metarecord
, handles
);
966 for (i
=0; i
<handles
; i
++)
967 ht
->objectHandle
[i
] = handletable
->objectHandle
[i
];
968 PlayMetaFileRecord16(hdc
, ht
, metarecord
, handles
);
969 for (i
=0; i
<handles
; i
++)
970 handletable
->objectHandle
[i
] = ht
->objectHandle
[i
];
971 GlobalFree32((HGLOBAL32
)ht
);
975 /******************************************************************
976 * GetMetaFileBits (GDI.159)
978 * Trade in a metafile object handle for a handle to the metafile memory.
982 HGLOBAL16 WINAPI
GetMetaFileBits(
983 HMETAFILE16 hmf
/* metafile handle */
986 TRACE(metafile
,"hMem out: %04x\n", hmf
);
990 /******************************************************************
991 * SetMetaFileBits (GDI.160)
993 * Trade in a metafile memory handle for a handle to a metafile object.
994 * The memory region should hold a proper metafile, otherwise
995 * problems will occur when it is used. Validity of the memory is not
996 * checked. The function is essentially just the identity function.
998 HMETAFILE16 WINAPI
SetMetaFileBits(
1000 /* handle to a memory region holding a metafile */
1003 TRACE(metafile
,"hmf out: %04x\n", hMem
);
1008 /******************************************************************
1009 * SetMetaFileBitsBetter (GDI.196)
1011 * Trade in a metafile memory handle for a handle to a metafile object,
1012 * making a cursory check (using IsValidMetaFile()) that the memory
1013 * handle points to a valid metafile.
1016 * Handle to a metafile on success, NULL on failure..
1018 HMETAFILE16 WINAPI
SetMetaFileBitsBetter( HMETAFILE16 hMeta
)
1020 if( IsValidMetaFile( hMeta
) )
1021 return (HMETAFILE16
)GlobalReAlloc16( hMeta
, 0,
1022 GMEM_SHARE
| GMEM_NODISCARD
| GMEM_MODIFY
);
1023 return (HMETAFILE16
)0;
1026 /******************************************************************
1027 * SetMetaFileBitsEx (GDI32.323)
1029 * Create a metafile from raw data. No checking of the data is performed.
1030 * Use _GetMetaFileBitsEx_ to get raw data from a metafile.
1032 HMETAFILE32 WINAPI
SetMetaFileBitsEx(
1033 UINT32 size
, /* size of metafile, in bytes */
1034 const BYTE
*lpData
/* pointer to metafile data */
1037 HMETAFILE32 hmf
= GlobalAlloc16(GHND
, size
);
1038 BYTE
*p
= GlobalLock16(hmf
) ;
1039 TRACE(metafile
, "(%d,%p) returning %08x\n", size
, lpData
, hmf
);
1040 if (!hmf
|| !p
) return 0;
1041 memcpy(p
, lpData
, size
);
1042 GlobalUnlock16(hmf
);
1046 /*****************************************************************
1047 * GetMetaFileBitsEx (GDI32.198) Get raw metafile data
1049 * Copies the data from metafile _hmf_ into the buffer _buf_.
1050 * If _buf_ is zero, returns size of buffer required. Otherwise,
1051 * returns number of bytes copied.
1053 UINT32 WINAPI
GetMetaFileBitsEx(
1054 HMETAFILE32 hmf
, /* metafile */
1055 UINT32 nSize
, /* size of buf */
1056 LPVOID buf
/* buffer to receive raw metafile data */
1058 METAHEADER
*h
= GlobalLock16(hmf
);
1059 TRACE(metafile
, "(%08x,%d,%p)\n", hmf
, nSize
, buf
);
1060 if (!h
) return 0; /* FIXME: error code */
1062 GlobalUnlock16(hmf
);
1063 TRACE(metafile
,"returning size %ld\n", h
->mtSize
);
1066 memmove(buf
, h
, MIN(nSize
, h
->mtSize
));
1067 GlobalUnlock16(hmf
);
1068 return MIN(nSize
, h
->mtSize
);
1072 /******************************************************************
1073 * MF_Meta_CreateRegion
1075 * Handles META_CREATEREGION for PlayMetaFileRecord().
1079 * The layout of the record looks something like this:
1084 * 2 Looks like a handle? - not constant
1086 * 4 Total number of bytes
1087 * 5 No. of seperate bands = n [see below]
1088 * 6 Largest number of x co-ords in a band
1089 * 7-10 Bounding box x1 y1 x2 y2
1092 * Regions are divided into bands that are uniform in the
1093 * y-direction. Each band consists of pairs of on/off x-coords and is
1095 * m y0 y1 x1 x2 x3 ... xm m
1096 * into successive rdParam[]s.
1098 * This is probably just a dump of the internal RGNOBJ?
1104 static BOOL32
MF_Meta_CreateRegion( METARECORD
*mr
, HRGN32 hrgn
)
1109 HRGN32 hrgn2
= CreateRectRgn32( 0, 0, 0, 0 );
1111 for(band
= 0, start
= &(mr
->rdParam
[11]); band
< mr
->rdParam
[5];
1112 band
++, start
= end
+ 1) {
1113 if(*start
/ 2 != (*start
+ 1) / 2) {
1114 WARN(metafile
, "Delimiter not even.\n");
1115 DeleteObject32( hrgn2
);
1119 end
= start
+ *start
+ 3;
1120 if(end
> (WORD
*)mr
+ mr
->rdSize
) {
1121 WARN(metafile
, "End points outside record.\n");
1122 DeleteObject32( hrgn2
);
1126 if(*start
!= *end
) {
1127 WARN(metafile
, "Mismatched delimiters.\n");
1128 DeleteObject32( hrgn2
);
1132 y0
= *(INT16
*)(start
+ 1);
1133 y1
= *(INT16
*)(start
+ 2);
1134 for(pair
= 0; pair
< *start
/ 2; pair
++) {
1135 SetRectRgn32( hrgn2
, *(INT16
*)(start
+ 3 + 2*pair
), y0
,
1136 *(INT16
*)(start
+ 4 + 2*pair
), y1
);
1137 CombineRgn32(hrgn
, hrgn
, hrgn2
, RGN_OR
);
1140 DeleteObject32( hrgn2
);
1145 /******************************************************************
1148 * Warning: this function can change the metafile handle.
1151 static BOOL32
MF_WriteRecord( DC
*dc
, METARECORD
*mr
, DWORD rlen
)
1155 METAFILEDRV_PDEVICE
*physDev
= (METAFILEDRV_PDEVICE
*)dc
->physDev
;
1157 switch(physDev
->mh
->mtType
)
1159 case METAFILE_MEMORY
:
1160 len
= physDev
->mh
->mtSize
* 2 + rlen
;
1161 mh
= HeapReAlloc( SystemHeap
, 0, physDev
->mh
, len
);
1162 if (!mh
) return FALSE
;
1164 memcpy((WORD
*)physDev
->mh
+ physDev
->mh
->mtSize
, mr
, rlen
);
1167 TRACE(metafile
,"Writing record to disk\n");
1168 if (_lwrite32(physDev
->mh
->mtNoParameters
, (char *)mr
, rlen
) == -1)
1172 ERR(metafile
, "Unknown metafile type %d\n", physDev
->mh
->mtType
);
1176 physDev
->mh
->mtSize
+= rlen
/ 2;
1177 physDev
->mh
->mtMaxRecord
= MAX(physDev
->mh
->mtMaxRecord
, rlen
/ 2);
1182 /******************************************************************
1186 BOOL32
MF_MetaParam0(DC
*dc
, short func
)
1189 METARECORD
*mr
= (METARECORD
*)&buffer
;
1192 mr
->rdFunction
= func
;
1193 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1197 /******************************************************************
1200 BOOL32
MF_MetaParam1(DC
*dc
, short func
, short param1
)
1203 METARECORD
*mr
= (METARECORD
*)&buffer
;
1206 mr
->rdFunction
= func
;
1207 *(mr
->rdParam
) = param1
;
1208 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1212 /******************************************************************
1215 BOOL32
MF_MetaParam2(DC
*dc
, short func
, short param1
, short param2
)
1218 METARECORD
*mr
= (METARECORD
*)&buffer
;
1221 mr
->rdFunction
= func
;
1222 *(mr
->rdParam
) = param2
;
1223 *(mr
->rdParam
+ 1) = param1
;
1224 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1228 /******************************************************************
1232 BOOL32
MF_MetaParam4(DC
*dc
, short func
, short param1
, short param2
,
1233 short param3
, short param4
)
1236 METARECORD
*mr
= (METARECORD
*)&buffer
;
1239 mr
->rdFunction
= func
;
1240 *(mr
->rdParam
) = param4
;
1241 *(mr
->rdParam
+ 1) = param3
;
1242 *(mr
->rdParam
+ 2) = param2
;
1243 *(mr
->rdParam
+ 3) = param1
;
1244 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1248 /******************************************************************
1252 BOOL32
MF_MetaParam6(DC
*dc
, short func
, short param1
, short param2
,
1253 short param3
, short param4
, short param5
, short param6
)
1256 METARECORD
*mr
= (METARECORD
*)&buffer
;
1259 mr
->rdFunction
= func
;
1260 *(mr
->rdParam
) = param6
;
1261 *(mr
->rdParam
+ 1) = param5
;
1262 *(mr
->rdParam
+ 2) = param4
;
1263 *(mr
->rdParam
+ 3) = param3
;
1264 *(mr
->rdParam
+ 4) = param2
;
1265 *(mr
->rdParam
+ 5) = param1
;
1266 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1270 /******************************************************************
1273 BOOL32
MF_MetaParam8(DC
*dc
, short func
, short param1
, short param2
,
1274 short param3
, short param4
, short param5
,
1275 short param6
, short param7
, short param8
)
1278 METARECORD
*mr
= (METARECORD
*)&buffer
;
1281 mr
->rdFunction
= func
;
1282 *(mr
->rdParam
) = param8
;
1283 *(mr
->rdParam
+ 1) = param7
;
1284 *(mr
->rdParam
+ 2) = param6
;
1285 *(mr
->rdParam
+ 3) = param5
;
1286 *(mr
->rdParam
+ 4) = param4
;
1287 *(mr
->rdParam
+ 5) = param3
;
1288 *(mr
->rdParam
+ 6) = param2
;
1289 *(mr
->rdParam
+ 7) = param1
;
1290 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1294 /******************************************************************
1295 * MF_CreateBrushIndirect
1298 BOOL32
MF_CreateBrushIndirect(DC
*dc
, HBRUSH16 hBrush
, LOGBRUSH16
*logbrush
)
1301 char buffer
[sizeof(METARECORD
) - 2 + sizeof(*logbrush
)];
1302 METARECORD
*mr
= (METARECORD
*)&buffer
;
1304 mr
->rdSize
= (sizeof(METARECORD
) + sizeof(*logbrush
) - 2) / 2;
1305 mr
->rdFunction
= META_CREATEBRUSHINDIRECT
;
1306 memcpy(&(mr
->rdParam
), logbrush
, sizeof(*logbrush
));
1307 if (!(MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2))) return FALSE
;
1309 mr
->rdSize
= sizeof(METARECORD
) / 2;
1310 mr
->rdFunction
= META_SELECTOBJECT
;
1312 if ((index
= MF_AddHandleDC( dc
)) == -1) return FALSE
;
1313 *(mr
->rdParam
) = index
;
1314 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1318 /******************************************************************
1319 * MF_CreatePatternBrush
1322 BOOL32
MF_CreatePatternBrush(DC
*dc
, HBRUSH16 hBrush
, LOGBRUSH16
*logbrush
)
1324 DWORD len
, bmSize
, biSize
;
1329 BITMAPINFOHEADER
*infohdr
;
1331 char buffer
[sizeof(METARECORD
)];
1333 switch (logbrush
->lbStyle
)
1336 bmp
= (BITMAPOBJ
*)GDI_GetObjPtr((HGDIOBJ16
)logbrush
->lbHatch
, BITMAP_MAGIC
);
1337 if (!bmp
) return FALSE
;
1338 len
= sizeof(METARECORD
) + sizeof(BITMAPINFOHEADER
) +
1339 (bmp
->bitmap
.bmHeight
* bmp
->bitmap
.bmWidthBytes
) + 6;
1340 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1342 GDI_HEAP_UNLOCK((HGDIOBJ16
)logbrush
->lbHatch
);
1345 mr
= (METARECORD
*)GlobalLock16(hmr
);
1347 mr
->rdFunction
= META_DIBCREATEPATTERNBRUSH
;
1348 mr
->rdSize
= len
/ 2;
1349 *(mr
->rdParam
) = logbrush
->lbStyle
;
1350 *(mr
->rdParam
+ 1) = DIB_RGB_COLORS
;
1351 infohdr
= (BITMAPINFOHEADER
*)(mr
->rdParam
+ 2);
1352 infohdr
->biSize
= sizeof(BITMAPINFOHEADER
);
1353 infohdr
->biWidth
= bmp
->bitmap
.bmWidth
;
1354 infohdr
->biHeight
= bmp
->bitmap
.bmHeight
;
1355 infohdr
->biPlanes
= bmp
->bitmap
.bmPlanes
;
1356 infohdr
->biBitCount
= bmp
->bitmap
.bmBitsPixel
;
1357 memcpy(mr
->rdParam
+ (sizeof(BITMAPINFOHEADER
) / 2) + 4,
1358 PTR_SEG_TO_LIN(bmp
->bitmap
.bmBits
),
1359 bmp
->bitmap
.bmHeight
* bmp
->bitmap
.bmWidthBytes
);
1360 GDI_HEAP_UNLOCK(logbrush
->lbHatch
);
1364 info
= (BITMAPINFO
*)GlobalLock16((HGLOBAL16
)logbrush
->lbHatch
);
1365 if (info
->bmiHeader
.biCompression
)
1366 bmSize
= info
->bmiHeader
.biSizeImage
;
1368 bmSize
= (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
1369 + 31) / 32 * 8 * info
->bmiHeader
.biHeight
;
1370 biSize
= DIB_BitmapInfoSize(info
, LOWORD(logbrush
->lbColor
));
1371 len
= sizeof(METARECORD
) + biSize
+ bmSize
+ 2;
1372 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1374 mr
= (METARECORD
*)GlobalLock16(hmr
);
1376 mr
->rdFunction
= META_DIBCREATEPATTERNBRUSH
;
1377 mr
->rdSize
= len
/ 2;
1378 *(mr
->rdParam
) = logbrush
->lbStyle
;
1379 *(mr
->rdParam
+ 1) = LOWORD(logbrush
->lbColor
);
1380 memcpy(mr
->rdParam
+ 2, info
, biSize
+ bmSize
);
1385 if (!(MF_WriteRecord(dc
, mr
, len
)))
1393 mr
= (METARECORD
*)&buffer
;
1394 mr
->rdSize
= sizeof(METARECORD
) / 2;
1395 mr
->rdFunction
= META_SELECTOBJECT
;
1397 if ((index
= MF_AddHandleDC( dc
)) == -1) return FALSE
;
1398 *(mr
->rdParam
) = index
;
1399 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1403 /******************************************************************
1404 * MF_CreatePenIndirect
1407 BOOL32
MF_CreatePenIndirect(DC
*dc
, HPEN16 hPen
, LOGPEN16
*logpen
)
1410 char buffer
[sizeof(METARECORD
) - 2 + sizeof(*logpen
)];
1411 METARECORD
*mr
= (METARECORD
*)&buffer
;
1413 mr
->rdSize
= (sizeof(METARECORD
) + sizeof(*logpen
) - 2) / 2;
1414 mr
->rdFunction
= META_CREATEPENINDIRECT
;
1415 memcpy(&(mr
->rdParam
), logpen
, sizeof(*logpen
));
1416 if (!(MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2))) return FALSE
;
1418 mr
->rdSize
= sizeof(METARECORD
) / 2;
1419 mr
->rdFunction
= META_SELECTOBJECT
;
1421 if ((index
= MF_AddHandleDC( dc
)) == -1) return FALSE
;
1422 *(mr
->rdParam
) = index
;
1423 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1427 /******************************************************************
1428 * MF_CreateFontIndirect
1431 BOOL32
MF_CreateFontIndirect(DC
*dc
, HFONT16 hFont
, LOGFONT16
*logfont
)
1434 char buffer
[sizeof(METARECORD
) - 2 + sizeof(LOGFONT16
)];
1435 METARECORD
*mr
= (METARECORD
*)&buffer
;
1437 mr
->rdSize
= (sizeof(METARECORD
) + sizeof(LOGFONT16
) - 2) / 2;
1438 mr
->rdFunction
= META_CREATEFONTINDIRECT
;
1439 memcpy(&(mr
->rdParam
), logfont
, sizeof(LOGFONT16
));
1440 if (!(MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2))) return FALSE
;
1442 mr
->rdSize
= sizeof(METARECORD
) / 2;
1443 mr
->rdFunction
= META_SELECTOBJECT
;
1445 if ((index
= MF_AddHandleDC( dc
)) == -1) return FALSE
;
1446 *(mr
->rdParam
) = index
;
1447 return MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1451 /******************************************************************
1454 BOOL32
MF_TextOut(DC
*dc
, short x
, short y
, LPCSTR str
, short count
)
1461 len
= sizeof(METARECORD
) + (((count
+ 1) >> 1) * 2) + 4;
1462 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1464 mr
= (METARECORD
*)GlobalLock16(hmr
);
1467 mr
->rdSize
= len
/ 2;
1468 mr
->rdFunction
= META_TEXTOUT
;
1469 *(mr
->rdParam
) = count
;
1470 memcpy(mr
->rdParam
+ 1, str
, count
);
1471 *(mr
->rdParam
+ ((count
+ 1) >> 1) + 1) = y
;
1472 *(mr
->rdParam
+ ((count
+ 1) >> 1) + 2) = x
;
1473 ret
= MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1478 /******************************************************************
1481 BOOL32
MF_ExtTextOut(DC
*dc
, short x
, short y
, UINT16 flags
, const RECT16
*rect
,
1482 LPCSTR str
, short count
, const INT16
*lpDx
)
1489 if((!flags
&& rect
) || (flags
&& !rect
))
1490 WARN(metafile
, "Inconsistent flags and rect\n");
1491 len
= sizeof(METARECORD
) + (((count
+ 1) >> 1) * 2) + 2 * sizeof(short)
1494 len
+= sizeof(RECT16
);
1496 len
+=count
*sizeof(INT16
);
1497 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1499 mr
= (METARECORD
*)GlobalLock16(hmr
);
1502 mr
->rdSize
= len
/ 2;
1503 mr
->rdFunction
= META_EXTTEXTOUT
;
1505 *(mr
->rdParam
+ 1) = x
;
1506 *(mr
->rdParam
+ 2) = count
;
1507 *(mr
->rdParam
+ 3) = flags
;
1508 if (rect
) memcpy(mr
->rdParam
+ 4, rect
, sizeof(RECT16
));
1509 memcpy(mr
->rdParam
+ (rect
? 8 : 4), str
, count
);
1511 memcpy(mr
->rdParam
+ (rect
? 8 : 4) + ((count
+ 1) >> 1),lpDx
,
1512 count
*sizeof(INT16
));
1513 ret
= MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1518 /******************************************************************
1519 * MF_MetaPoly - implements Polygon and Polyline
1521 BOOL32
MF_MetaPoly(DC
*dc
, short func
, LPPOINT16 pt
, short count
)
1528 len
= sizeof(METARECORD
) + (count
* 4);
1529 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1531 mr
= (METARECORD
*)GlobalLock16(hmr
);
1534 mr
->rdSize
= len
/ 2;
1535 mr
->rdFunction
= func
;
1536 *(mr
->rdParam
) = count
;
1537 memcpy(mr
->rdParam
+ 1, pt
, count
* 4);
1538 ret
= MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2);
1544 /******************************************************************
1547 BOOL32
MF_BitBlt(DC
*dcDest
, short xDest
, short yDest
, short width
,
1548 short height
, DC
*dcSrc
, short xSrc
, short ySrc
, DWORD rop
)
1556 GetObject16(dcSrc
->w
.hBitmap
, sizeof(BITMAP16
), &BM
);
1557 len
= sizeof(METARECORD
) + 12 * sizeof(INT16
) + BM
.bmWidthBytes
* BM
.bmHeight
;
1558 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1560 mr
= (METARECORD
*)GlobalLock16(hmr
);
1561 mr
->rdFunction
= META_BITBLT
;
1562 *(mr
->rdParam
+ 7) = BM
.bmWidth
;
1563 *(mr
->rdParam
+ 8) = BM
.bmHeight
;
1564 *(mr
->rdParam
+ 9) = BM
.bmWidthBytes
;
1565 *(mr
->rdParam
+10) = BM
.bmPlanes
;
1566 *(mr
->rdParam
+11) = BM
.bmBitsPixel
;
1567 TRACE(metafile
,"MF_StretchBlt->len = %ld rop=%lx \n",len
,rop
);
1568 if (GetBitmapBits32(dcSrc
->w
.hBitmap
,BM
.bmWidthBytes
* BM
.bmHeight
,
1571 mr
->rdSize
= len
/ sizeof(INT16
);
1572 *(mr
->rdParam
) = HIWORD(rop
);
1573 *(mr
->rdParam
+ 1) = ySrc
;
1574 *(mr
->rdParam
+ 2) = xSrc
;
1575 *(mr
->rdParam
+ 3) = height
;
1576 *(mr
->rdParam
+ 4) = width
;
1577 *(mr
->rdParam
+ 5) = yDest
;
1578 *(mr
->rdParam
+ 6) = xDest
;
1579 ret
= MF_WriteRecord( dcDest
, mr
, mr
->rdSize
* 2);
1588 /**********************************************************************
1590 * this function contains TWO ways for procesing StretchBlt in metafiles,
1591 * decide between rdFunction values META_STRETCHBLT or META_DIBSTRETCHBLT
1592 * via #define STRETCH_VIA_DIB
1594 #define STRETCH_VIA_DIB
1595 #undef STRETCH_VIA_DIB
1596 BOOL32
MF_StretchBlt(DC
*dcDest
, short xDest
, short yDest
, short widthDest
,
1597 short heightDest
, DC
*dcSrc
, short xSrc
, short ySrc
,
1598 short widthSrc
, short heightSrc
, DWORD rop
)
1605 #ifdef STRETCH_VIA_DIB
1606 LPBITMAPINFOHEADER lpBMI
;
1609 GetObject16(dcSrc
->w
.hBitmap
, sizeof(BITMAP16
), &BM
);
1610 #ifdef STRETCH_VIA_DIB
1611 nBPP
= BM
.bmPlanes
* BM
.bmBitsPixel
;
1612 len
= sizeof(METARECORD
) + 10 * sizeof(INT16
)
1613 + sizeof(BITMAPINFOHEADER
) + (nBPP
!= 24 ? 1 << nBPP
: 0) * sizeof(RGBQUAD
)
1614 + ((BM
.bmWidth
* nBPP
+ 31) / 32) * 4 * BM
.bmHeight
;
1615 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1617 mr
= (METARECORD
*)GlobalLock16(hmr
);
1618 mr
->rdFunction
= META_DIBSTRETCHBLT
;
1619 lpBMI
=(LPBITMAPINFOHEADER
)(mr
->rdParam
+10);
1620 lpBMI
->biSize
= sizeof(BITMAPINFOHEADER
);
1621 lpBMI
->biWidth
= BM
.bmWidth
;
1622 lpBMI
->biHeight
= BM
.bmHeight
;
1623 lpBMI
->biPlanes
= 1;
1624 lpBMI
->biBitCount
= nBPP
; /* 1,4,8 or 24 */
1625 lpBMI
->biClrUsed
= nBPP
!= 24 ? 1 << nBPP
: 0;
1626 lpBMI
->biSizeImage
= ((lpBMI
->biWidth
* nBPP
+ 31) / 32) * 4 * lpBMI
->biHeight
;
1627 lpBMI
->biCompression
= BI_RGB
;
1628 lpBMI
->biXPelsPerMeter
= MulDiv32(GetDeviceCaps(dcSrc
->hSelf
,LOGPIXELSX
),3937,100);
1629 lpBMI
->biYPelsPerMeter
= MulDiv32(GetDeviceCaps(dcSrc
->hSelf
,LOGPIXELSY
),3937,100);
1630 lpBMI
->biClrImportant
= 0; /* 1 meter = 39.37 inch */
1632 TRACE(metafile
,"MF_StretchBltViaDIB->len = %ld rop=%lx PixYPM=%ld Caps=%d\n",
1633 len
,rop
,lpBMI
->biYPelsPerMeter
,GetDeviceCaps(hdcSrc
,LOGPIXELSY
));
1634 if (GetDIBits(hdcSrc
,dcSrc
->w
.hBitmap
,0,(UINT32
)lpBMI
->biHeight
,
1635 (LPSTR
)lpBMI
+ DIB_BitmapInfoSize( (BITMAPINFO
*)lpBMI
,
1637 (LPBITMAPINFO
)lpBMI
, DIB_RGB_COLORS
))
1639 len
= sizeof(METARECORD
) + 15 * sizeof(INT16
) + BM
.bmWidthBytes
* BM
.bmHeight
;
1640 if (!(hmr
= GlobalAlloc16(GMEM_MOVEABLE
, len
)))
1642 mr
= (METARECORD
*)GlobalLock16(hmr
);
1643 mr
->rdFunction
= META_STRETCHBLT
;
1644 *(mr
->rdParam
+10) = BM
.bmWidth
;
1645 *(mr
->rdParam
+11) = BM
.bmHeight
;
1646 *(mr
->rdParam
+12) = BM
.bmWidthBytes
;
1647 *(mr
->rdParam
+13) = BM
.bmPlanes
;
1648 *(mr
->rdParam
+14) = BM
.bmBitsPixel
;
1649 TRACE(metafile
,"MF_StretchBlt->len = %ld rop=%lx \n",len
,rop
);
1650 if (GetBitmapBits32( dcSrc
->w
.hBitmap
, BM
.bmWidthBytes
* BM
.bmHeight
,
1654 mr
->rdSize
= len
/ sizeof(INT16
);
1655 *(mr
->rdParam
) = LOWORD(rop
);
1656 *(mr
->rdParam
+ 1) = HIWORD(rop
);
1657 *(mr
->rdParam
+ 2) = heightSrc
;
1658 *(mr
->rdParam
+ 3) = widthSrc
;
1659 *(mr
->rdParam
+ 4) = ySrc
;
1660 *(mr
->rdParam
+ 5) = xSrc
;
1661 *(mr
->rdParam
+ 6) = heightDest
;
1662 *(mr
->rdParam
+ 7) = widthDest
;
1663 *(mr
->rdParam
+ 8) = yDest
;
1664 *(mr
->rdParam
+ 9) = xDest
;
1665 ret
= MF_WriteRecord( dcDest
, mr
, mr
->rdSize
* 2);
1674 /******************************************************************
1677 INT16
MF_CreateRegion(DC
*dc
, HRGN32 hrgn
)
1682 RECT32
*pCurRect
, *pEndRect
;
1683 WORD Bands
= 0, MaxBands
= 0;
1684 WORD
*Param
, *StartBand
;
1687 len
= GetRegionData( hrgn
, 0, NULL
);
1688 if( !(rgndata
= HeapAlloc( SystemHeap
, 0, len
)) ) {
1689 WARN(metafile
, "MF_CreateRegion: can't alloc rgndata buffer\n");
1692 GetRegionData( hrgn
, len
, rgndata
);
1694 /* Overestimate of length:
1695 * Assume every rect is a separate band -> 6 WORDs per rect
1697 len
= sizeof(METARECORD
) + 20 + (rgndata
->rdh
.nCount
* 12);
1698 if( !(mr
= HeapAlloc( SystemHeap
, 0, len
)) ) {
1699 WARN(metafile
, "MF_CreateRegion: can't alloc METARECORD buffer\n");
1700 HeapFree( SystemHeap
, 0, rgndata
);
1706 Param
= mr
->rdParam
+ 11;
1709 pEndRect
= (RECT32
*)rgndata
->Buffer
+ rgndata
->rdh
.nCount
;
1710 for(pCurRect
= (RECT32
*)rgndata
->Buffer
; pCurRect
< pEndRect
; pCurRect
++)
1712 if( StartBand
&& pCurRect
->top
== *(StartBand
+ 1) )
1714 *Param
++ = pCurRect
->left
;
1715 *Param
++ = pCurRect
->right
;
1721 *StartBand
= Param
- StartBand
- 3;
1722 *Param
++ = *StartBand
;
1723 if(*StartBand
> MaxBands
)
1724 MaxBands
= *StartBand
;
1727 StartBand
= Param
++;
1728 *Param
++ = pCurRect
->top
;
1729 *Param
++ = pCurRect
->bottom
;
1730 *Param
++ = pCurRect
->left
;
1731 *Param
++ = pCurRect
->right
;
1734 len
= Param
- (WORD
*)mr
;
1738 mr
->rdParam
[2] = 0x1234;
1740 mr
->rdParam
[4] = len
* 2;
1741 mr
->rdParam
[5] = Bands
;
1742 mr
->rdParam
[6] = MaxBands
;
1743 mr
->rdParam
[7] = rgndata
->rdh
.rcBound
.left
;
1744 mr
->rdParam
[8] = rgndata
->rdh
.rcBound
.top
;
1745 mr
->rdParam
[9] = rgndata
->rdh
.rcBound
.right
;
1746 mr
->rdParam
[10] = rgndata
->rdh
.rcBound
.bottom
;
1747 mr
->rdFunction
= META_CREATEREGION
;
1748 mr
->rdSize
= len
/ 2;
1749 ret
= MF_WriteRecord( dc
, mr
, mr
->rdSize
* 2 );
1750 HeapFree( SystemHeap
, 0, mr
);
1751 HeapFree( SystemHeap
, 0, rgndata
);
1754 WARN(metafile
, "MF_CreateRegion: MF_WriteRecord failed\n");
1757 return MF_AddHandleDC( dc
);