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 /**********************************************************************
36 BOOL
MFDRV_MoveTo(PHYSDEV dev
, INT x
, INT y
)
38 return MFDRV_MetaParam2(dev
,META_MOVETO
,x
,y
);
41 /***********************************************************************
44 BOOL
MFDRV_LineTo( PHYSDEV dev
, INT x
, INT y
)
46 return MFDRV_MetaParam2(dev
, META_LINETO
, x
, y
);
50 /***********************************************************************
53 BOOL
MFDRV_Arc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
54 INT xstart
, INT ystart
, INT xend
, INT yend
)
56 return MFDRV_MetaParam8(dev
, META_ARC
, left
, top
, right
, bottom
,
57 xstart
, ystart
, xend
, yend
);
61 /***********************************************************************
64 BOOL
MFDRV_Pie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
65 INT xstart
, INT ystart
, INT xend
, INT yend
)
67 return MFDRV_MetaParam8(dev
, META_PIE
, left
, top
, right
, bottom
,
68 xstart
, ystart
, xend
, yend
);
72 /***********************************************************************
75 BOOL
MFDRV_Chord( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
76 INT xstart
, INT ystart
, INT xend
, INT yend
)
78 return MFDRV_MetaParam8(dev
, META_CHORD
, left
, top
, right
, bottom
,
79 xstart
, ystart
, xend
, yend
);
82 /***********************************************************************
85 BOOL
MFDRV_Ellipse( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
87 return MFDRV_MetaParam4(dev
, META_ELLIPSE
, left
, top
, right
, bottom
);
90 /***********************************************************************
93 BOOL
MFDRV_Rectangle(PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
95 return MFDRV_MetaParam4(dev
, META_RECTANGLE
, left
, top
, right
, bottom
);
98 /***********************************************************************
101 BOOL
MFDRV_RoundRect( PHYSDEV dev
, INT left
, INT top
, INT right
,
102 INT bottom
, INT ell_width
, INT ell_height
)
104 return MFDRV_MetaParam6(dev
, META_ROUNDRECT
, left
, top
, right
, bottom
,
105 ell_width
, ell_height
);
108 /***********************************************************************
111 COLORREF
MFDRV_SetPixel( PHYSDEV dev
, INT x
, INT y
, COLORREF color
)
113 return MFDRV_MetaParam4(dev
, META_SETPIXEL
, x
, y
,HIWORD(color
),
118 /******************************************************************
119 * MFDRV_MetaPoly - implements Polygon and Polyline
121 static BOOL
MFDRV_MetaPoly(PHYSDEV dev
, short func
, POINTS
*pt
, short count
)
127 len
= sizeof(METARECORD
) + (count
* 4);
128 if (!(mr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
)))
131 mr
->rdSize
= len
/ 2;
132 mr
->rdFunction
= func
;
133 *(mr
->rdParm
) = count
;
134 memcpy(mr
->rdParm
+ 1, pt
, count
* 4);
135 ret
= MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2);
136 HeapFree( GetProcessHeap(), 0, mr
);
141 /**********************************************************************
144 BOOL
MFDRV_Polyline( PHYSDEV dev
, const POINT
* pt
, INT count
)
150 pts
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINTS
)*count
);
151 if(!pts
) return FALSE
;
157 ret
= MFDRV_MetaPoly(dev
, META_POLYLINE
, pts
, count
);
159 HeapFree( GetProcessHeap(), 0, pts
);
164 /**********************************************************************
167 BOOL
MFDRV_Polygon( PHYSDEV dev
, const POINT
* pt
, INT count
)
173 pts
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINTS
)*count
);
174 if(!pts
) return FALSE
;
180 ret
= MFDRV_MetaPoly(dev
, META_POLYGON
, pts
, count
);
182 HeapFree( GetProcessHeap(), 0, pts
);
187 /**********************************************************************
190 BOOL
MFDRV_PolyPolygon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polygons
)
197 INT16 totalpoint16
= 0;
200 for (i
=0;i
<polygons
;i
++) {
201 totalpoint16
+= counts
[i
];
204 /* allocate space for all points */
205 pts
=HeapAlloc( GetProcessHeap(), 0, sizeof(POINTS
) * totalpoint16
);
206 pointcounts
= HeapAlloc( GetProcessHeap(), 0, sizeof(INT16
) * totalpoint16
);
208 /* copy point counts */
209 for (i
=0;i
<polygons
;i
++) {
210 pointcounts
[i
] = counts
[i
];
213 /* convert all points */
214 for (j
= totalpoint16
; j
--;){
219 len
= sizeof(METARECORD
) + sizeof(WORD
) + polygons
*sizeof(INT16
) + totalpoint16
*sizeof(*pts
);
221 if (!(mr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
))) {
222 HeapFree( GetProcessHeap(), 0, pts
);
223 HeapFree( GetProcessHeap(), 0, pointcounts
);
228 mr
->rdFunction
= META_POLYPOLYGON
;
229 *(mr
->rdParm
) = polygons
;
230 memcpy(mr
->rdParm
+ 1, pointcounts
, polygons
*sizeof(INT16
));
231 memcpy(mr
->rdParm
+ 1+polygons
, pts
, totalpoint16
*sizeof(*pts
));
232 ret
= MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2);
234 HeapFree( GetProcessHeap(), 0, pts
);
235 HeapFree( GetProcessHeap(), 0, pointcounts
);
236 HeapFree( GetProcessHeap(), 0, mr
);
241 /**********************************************************************
244 BOOL
MFDRV_ExtFloodFill( PHYSDEV dev
, INT x
, INT y
, COLORREF color
, UINT fillType
)
246 return MFDRV_MetaParam4(dev
,META_FLOODFILL
,x
,y
,HIWORD(color
),
251 /******************************************************************
254 * For explanation of the format of the record see MF_Play_MetaCreateRegion in
257 static INT16
MFDRV_CreateRegion(PHYSDEV dev
, HRGN hrgn
)
262 RECT
*pCurRect
, *pEndRect
;
263 WORD Bands
= 0, MaxBands
= 0;
264 WORD
*Param
, *StartBand
;
267 if (!(len
= GetRegionData( hrgn
, 0, NULL
))) return -1;
268 if( !(rgndata
= HeapAlloc( GetProcessHeap(), 0, len
)) ) {
269 WARN("Can't alloc rgndata buffer\n");
272 GetRegionData( hrgn
, len
, rgndata
);
274 /* Overestimate of length:
275 * Assume every rect is a separate band -> 6 WORDs per rect
277 len
= sizeof(METARECORD
) + 20 + (rgndata
->rdh
.nCount
* 12);
278 if( !(mr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
)) ) {
279 WARN("Can't alloc METARECORD buffer\n");
280 HeapFree( GetProcessHeap(), 0, rgndata
);
284 Param
= mr
->rdParm
+ 11;
287 pEndRect
= (RECT
*)rgndata
->Buffer
+ rgndata
->rdh
.nCount
;
288 for(pCurRect
= (RECT
*)rgndata
->Buffer
; pCurRect
< pEndRect
; pCurRect
++)
290 if( StartBand
&& pCurRect
->top
== *(StartBand
+ 1) )
292 *Param
++ = pCurRect
->left
;
293 *Param
++ = pCurRect
->right
;
299 *StartBand
= Param
- StartBand
- 3;
300 *Param
++ = *StartBand
;
301 if(*StartBand
> MaxBands
)
302 MaxBands
= *StartBand
;
306 *Param
++ = pCurRect
->top
;
307 *Param
++ = pCurRect
->bottom
;
308 *Param
++ = pCurRect
->left
;
309 *Param
++ = pCurRect
->right
;
315 *StartBand
= Param
- StartBand
- 3;
316 *Param
++ = *StartBand
;
317 if(*StartBand
> MaxBands
)
318 MaxBands
= *StartBand
;
324 mr
->rdParm
[2] = 0x2f6;
326 mr
->rdParm
[4] = (Param
- &mr
->rdFunction
) * sizeof(WORD
);
327 mr
->rdParm
[5] = Bands
;
328 mr
->rdParm
[6] = MaxBands
;
329 mr
->rdParm
[7] = rgndata
->rdh
.rcBound
.left
;
330 mr
->rdParm
[8] = rgndata
->rdh
.rcBound
.top
;
331 mr
->rdParm
[9] = rgndata
->rdh
.rcBound
.right
;
332 mr
->rdParm
[10] = rgndata
->rdh
.rcBound
.bottom
;
333 mr
->rdFunction
= META_CREATEREGION
;
334 mr
->rdSize
= Param
- (WORD
*)mr
;
335 ret
= MFDRV_WriteRecord( dev
, mr
, mr
->rdSize
* 2 );
336 HeapFree( GetProcessHeap(), 0, mr
);
337 HeapFree( GetProcessHeap(), 0, rgndata
);
340 WARN("MFDRV_WriteRecord failed\n");
343 return MFDRV_AddHandle( dev
, hrgn
);
347 /**********************************************************************
350 BOOL
MFDRV_PaintRgn( PHYSDEV dev
, HRGN hrgn
)
353 index
= MFDRV_CreateRegion( dev
, hrgn
);
356 return MFDRV_MetaParam1( dev
, META_PAINTREGION
, index
);
360 /**********************************************************************
363 BOOL
MFDRV_InvertRgn( PHYSDEV dev
, HRGN hrgn
)
366 index
= MFDRV_CreateRegion( dev
, hrgn
);
369 return MFDRV_MetaParam1( dev
, META_INVERTREGION
, index
);
373 /**********************************************************************
376 BOOL
MFDRV_FillRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
)
379 iRgn
= MFDRV_CreateRegion( dev
, hrgn
);
382 iBrush
= MFDRV_CreateBrushIndirect( dev
, hbrush
);
385 return MFDRV_MetaParam2( dev
, META_FILLREGION
, iRgn
, iBrush
);
388 /**********************************************************************
391 BOOL
MFDRV_FrameRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
, INT x
, INT y
)
394 iRgn
= MFDRV_CreateRegion( dev
, hrgn
);
397 iBrush
= MFDRV_CreateBrushIndirect( dev
, hbrush
);
400 return MFDRV_MetaParam4( dev
, META_FRAMEREGION
, iRgn
, iBrush
, x
, y
);
404 /**********************************************************************
405 * MFDRV_ExtSelectClipRgn
407 INT
MFDRV_ExtSelectClipRgn( PHYSDEV dev
, HRGN hrgn
, INT mode
)
412 if (mode
!= RGN_COPY
) return ERROR
;
413 if (!hrgn
) return NULLREGION
;
414 iRgn
= MFDRV_CreateRegion( dev
, hrgn
);
415 if(iRgn
== -1) return ERROR
;
416 ret
= MFDRV_MetaParam1( dev
, META_SELECTOBJECT
, iRgn
) ? NULLREGION
: ERROR
;
417 MFDRV_MetaParam1( dev
, META_DELETEOBJECT
, iRgn
);
418 MFDRV_RemoveHandle( dev
, iRgn
);
423 /**********************************************************************
425 * Since MetaFiles don't record Beziers and they don't even record
426 * approximations to them using lines, we need this stub function.
428 BOOL
MFDRV_PolyBezier( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
433 /**********************************************************************
435 * Since MetaFiles don't record Beziers and they don't even record
436 * approximations to them using lines, we need this stub function.
438 BOOL
MFDRV_PolyBezierTo( PHYSDEV dev
, const POINT
*pts
, DWORD count
)