2 * Metafile driver graphics functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "mfdrv/metafiledrv.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(metafile
);
33 /**********************************************************************
37 MFDRV_MoveTo(PHYSDEV dev
, INT x
, INT y
)
39 return MFDRV_MetaParam2(dev
,META_MOVETO
,x
,y
);
42 /***********************************************************************
46 MFDRV_LineTo( PHYSDEV dev
, INT x
, INT y
)
48 return MFDRV_MetaParam2(dev
, META_LINETO
, x
, y
);
52 /***********************************************************************
56 MFDRV_Arc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
57 INT xstart
, INT ystart
, INT xend
, INT yend
)
59 return MFDRV_MetaParam8(dev
, META_ARC
, left
, top
, right
, bottom
,
60 xstart
, ystart
, xend
, yend
);
64 /***********************************************************************
68 MFDRV_Pie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
69 INT xstart
, INT ystart
, INT xend
, INT yend
)
71 return MFDRV_MetaParam8(dev
, META_PIE
, left
, top
, right
, bottom
,
72 xstart
, ystart
, xend
, yend
);
76 /***********************************************************************
80 MFDRV_Chord( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
81 INT xstart
, INT ystart
, INT xend
, INT yend
)
83 return MFDRV_MetaParam8(dev
, META_CHORD
, left
, top
, right
, bottom
,
84 xstart
, ystart
, xend
, yend
);
87 /***********************************************************************
91 MFDRV_Ellipse( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
93 return MFDRV_MetaParam4(dev
, META_ELLIPSE
, left
, top
, right
, bottom
);
96 /***********************************************************************
100 MFDRV_Rectangle(PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
102 return MFDRV_MetaParam4(dev
, META_RECTANGLE
, left
, top
, right
, bottom
);
105 /***********************************************************************
109 MFDRV_RoundRect( PHYSDEV dev
, INT left
, INT top
, INT right
,
110 INT bottom
, INT ell_width
, INT ell_height
)
112 return MFDRV_MetaParam6(dev
, META_ROUNDRECT
, left
, top
, right
, bottom
,
113 ell_width
, ell_height
);
116 /***********************************************************************
120 MFDRV_SetPixel( PHYSDEV dev
, INT x
, INT y
, COLORREF color
)
122 return MFDRV_MetaParam4(dev
, META_SETPIXEL
, x
, y
,HIWORD(color
),
127 /******************************************************************
128 * MFDRV_MetaPoly - implements Polygon and Polyline
130 static BOOL
MFDRV_MetaPoly(PHYSDEV dev
, short func
, POINTS
*pt
, short count
)
136 len
= sizeof(METARECORD
) + (count
* 4);
137 if (!(mr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
)))
140 mr
->rdSize
= len
/ 2;
141 mr
->rdFunction
= func
;
142 *(mr
->rdParm
) = count
;
143 memcpy(mr
->rdParm
+ 1, pt
, count
* 4);
144 ret
= MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2);
145 HeapFree( GetProcessHeap(), 0, mr
);
150 /**********************************************************************
154 MFDRV_Polyline( PHYSDEV dev
, const POINT
* pt
, INT count
)
160 pts
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINTS
)*count
);
161 if(!pts
) return FALSE
;
167 ret
= MFDRV_MetaPoly(dev
, META_POLYLINE
, pts
, count
);
169 HeapFree( GetProcessHeap(), 0, pts
);
174 /**********************************************************************
178 MFDRV_Polygon( PHYSDEV dev
, const POINT
* pt
, INT count
)
184 pts
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINTS
)*count
);
185 if(!pts
) return FALSE
;
191 ret
= MFDRV_MetaPoly(dev
, META_POLYGON
, pts
, count
);
193 HeapFree( GetProcessHeap(), 0, pts
);
198 /**********************************************************************
202 MFDRV_PolyPolygon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polygons
)
209 INT16 totalpoint16
= 0;
212 for (i
=0;i
<polygons
;i
++) {
213 totalpoint16
+= counts
[i
];
216 /* allocate space for all points */
217 pts
=HeapAlloc( GetProcessHeap(), 0, sizeof(POINTS
) * totalpoint16
);
218 pointcounts
= HeapAlloc( GetProcessHeap(), 0, sizeof(INT16
) * totalpoint16
);
220 /* copy point counts */
221 for (i
=0;i
<polygons
;i
++) {
222 pointcounts
[i
] = counts
[i
];
225 /* convert all points */
226 for (j
= totalpoint16
; j
--;){
231 len
= sizeof(METARECORD
) + sizeof(WORD
) + polygons
*sizeof(INT16
) + totalpoint16
*sizeof(*pts
);
233 if (!(mr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
))) {
234 HeapFree( GetProcessHeap(), 0, pts
);
235 HeapFree( GetProcessHeap(), 0, pointcounts
);
240 mr
->rdFunction
= META_POLYPOLYGON
;
241 *(mr
->rdParm
) = polygons
;
242 memcpy(mr
->rdParm
+ 1, pointcounts
, polygons
*sizeof(INT16
));
243 memcpy(mr
->rdParm
+ 1+polygons
, pts
, totalpoint16
*sizeof(*pts
));
244 ret
= MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2);
246 HeapFree( GetProcessHeap(), 0, pts
);
247 HeapFree( GetProcessHeap(), 0, pointcounts
);
248 HeapFree( GetProcessHeap(), 0, mr
);
253 /**********************************************************************
257 MFDRV_ExtFloodFill( PHYSDEV dev
, INT x
, INT y
, COLORREF color
, UINT fillType
)
259 return MFDRV_MetaParam4(dev
,META_FLOODFILL
,x
,y
,HIWORD(color
),
264 /******************************************************************
267 * For explanation of the format of the record see MF_Play_MetaCreateRegion in
270 static INT16
MFDRV_CreateRegion(PHYSDEV dev
, HRGN hrgn
)
275 RECT
*pCurRect
, *pEndRect
;
276 WORD Bands
= 0, MaxBands
= 0;
277 WORD
*Param
, *StartBand
;
280 if (!(len
= GetRegionData( hrgn
, 0, NULL
))) return -1;
281 if( !(rgndata
= HeapAlloc( GetProcessHeap(), 0, len
)) ) {
282 WARN("Can't alloc rgndata buffer\n");
285 GetRegionData( hrgn
, len
, rgndata
);
287 /* Overestimate of length:
288 * Assume every rect is a separate band -> 6 WORDs per rect
290 len
= sizeof(METARECORD
) + 20 + (rgndata
->rdh
.nCount
* 12);
291 if( !(mr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
)) ) {
292 WARN("Can't alloc METARECORD buffer\n");
293 HeapFree( GetProcessHeap(), 0, rgndata
);
297 Param
= mr
->rdParm
+ 11;
300 pEndRect
= (RECT
*)rgndata
->Buffer
+ rgndata
->rdh
.nCount
;
301 for(pCurRect
= (RECT
*)rgndata
->Buffer
; pCurRect
< pEndRect
; pCurRect
++)
303 if( StartBand
&& pCurRect
->top
== *(StartBand
+ 1) )
305 *Param
++ = pCurRect
->left
;
306 *Param
++ = pCurRect
->right
;
312 *StartBand
= Param
- StartBand
- 3;
313 *Param
++ = *StartBand
;
314 if(*StartBand
> MaxBands
)
315 MaxBands
= *StartBand
;
319 *Param
++ = pCurRect
->top
;
320 *Param
++ = pCurRect
->bottom
;
321 *Param
++ = pCurRect
->left
;
322 *Param
++ = pCurRect
->right
;
325 len
= Param
- (WORD
*)mr
;
329 mr
->rdParm
[2] = 0x1234;
331 mr
->rdParm
[4] = len
* 2;
332 mr
->rdParm
[5] = Bands
;
333 mr
->rdParm
[6] = MaxBands
;
334 mr
->rdParm
[7] = rgndata
->rdh
.rcBound
.left
;
335 mr
->rdParm
[8] = rgndata
->rdh
.rcBound
.top
;
336 mr
->rdParm
[9] = rgndata
->rdh
.rcBound
.right
;
337 mr
->rdParm
[10] = rgndata
->rdh
.rcBound
.bottom
;
338 mr
->rdFunction
= META_CREATEREGION
;
339 mr
->rdSize
= len
/ 2;
340 ret
= MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2 );
341 HeapFree( GetProcessHeap(), 0, mr
);
342 HeapFree( GetProcessHeap(), 0, rgndata
);
345 WARN("MFDRV_WriteRecord failed\n");
348 return MFDRV_AddHandle( dev
, hrgn
);
352 /**********************************************************************
356 MFDRV_PaintRgn( PHYSDEV dev
, HRGN hrgn
)
359 index
= MFDRV_CreateRegion( dev
, hrgn
);
362 return MFDRV_MetaParam1( dev
, META_PAINTREGION
, index
);
366 /**********************************************************************
370 MFDRV_InvertRgn( PHYSDEV dev
, HRGN hrgn
)
373 index
= MFDRV_CreateRegion( dev
, hrgn
);
376 return MFDRV_MetaParam1( dev
, META_INVERTREGION
, index
);
380 /**********************************************************************
384 MFDRV_FillRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
)
387 iRgn
= MFDRV_CreateRegion( dev
, hrgn
);
390 iBrush
= MFDRV_CreateBrushIndirect( dev
, hbrush
);
393 return MFDRV_MetaParam2( dev
, META_FILLREGION
, iRgn
, iBrush
);
396 /**********************************************************************
400 MFDRV_FrameRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
, INT x
, INT y
)
403 iRgn
= MFDRV_CreateRegion( dev
, hrgn
);
406 iBrush
= MFDRV_CreateBrushIndirect( dev
, hbrush
);
409 return MFDRV_MetaParam4( dev
, META_FRAMEREGION
, iRgn
, iBrush
, x
, y
);
413 /**********************************************************************
414 * MFDRV_ExtSelectClipRgn
416 INT CDECL
MFDRV_ExtSelectClipRgn( PHYSDEV dev
, HRGN hrgn
, INT mode
)
421 if (mode
!= RGN_COPY
) return ERROR
;
422 if (!hrgn
) return NULLREGION
;
423 iRgn
= MFDRV_CreateRegion( dev
, hrgn
);
424 if(iRgn
== -1) return ERROR
;
425 ret
= MFDRV_MetaParam1( dev
, META_SELECTCLIPREGION
, iRgn
) ? NULLREGION
: ERROR
;
426 MFDRV_MetaParam1( dev
, META_DELETEOBJECT
, iRgn
);
427 MFDRV_RemoveHandle( dev
, iRgn
);
432 /**********************************************************************
436 MFDRV_SetBkColor( PHYSDEV dev
, COLORREF color
)
438 return MFDRV_MetaParam2(dev
, META_SETBKCOLOR
, HIWORD(color
),
439 LOWORD(color
)) ? color
: CLR_INVALID
;
443 /**********************************************************************
447 MFDRV_SetTextColor( PHYSDEV dev
, COLORREF color
)
449 return MFDRV_MetaParam2(dev
, META_SETTEXTCOLOR
, HIWORD(color
),
450 LOWORD(color
)) ? color
: CLR_INVALID
;
454 /**********************************************************************
456 * Since MetaFiles don't record Beziers and they don't even record
457 * approximations to them using lines, we need this stub function.
460 MFDRV_PolyBezier( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
465 /**********************************************************************
467 * Since MetaFiles don't record Beziers and they don't even record
468 * approximations to them using lines, we need this stub function.
471 MFDRV_PolyBezierTo( PHYSDEV dev
, const POINT
*pts
, DWORD count
)