2 * Enhanced MetaFile driver graphics functions
4 * Copyright 1999 Huw D M Davies
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 "enhmfdrv/enhmetafiledrv.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile
);
33 static const RECTL empty_bounds
= { 0, 0, -1, -1 };
35 /* determine if we can use 16-bit points to store all the input points */
36 static BOOL
can_use_short_points( const POINT
*pts
, UINT count
)
40 for (i
= 0; i
< count
; i
++)
41 if (((pts
[i
].x
+ 0x8000) & ~0xffff) || ((pts
[i
].y
+ 0x8000) & ~0xffff))
46 /* store points in either long or short format; return a pointer to the end of the stored data */
47 static void *store_points( POINTL
*dest
, const POINT
*pts
, UINT count
, BOOL short_points
)
52 POINTS
*dest_short
= (POINTS
*)dest
;
54 for (i
= 0; i
< count
; i
++)
56 dest_short
[i
].x
= pts
[i
].x
;
57 dest_short
[i
].y
= pts
[i
].y
;
59 return dest_short
+ count
;
63 memcpy( dest
, pts
, count
* sizeof(*dest
) );
68 /* compute the bounds of an array of points, optionally including the current position */
69 static void get_points_bounds( RECTL
*bounds
, const POINT
*pts
, UINT count
, DC
*dc
)
75 bounds
->left
= bounds
->right
= dc
->cur_pos
.x
;
76 bounds
->top
= bounds
->bottom
= dc
->cur_pos
.y
;
80 bounds
->left
= bounds
->right
= pts
[0].x
;
81 bounds
->top
= bounds
->bottom
= pts
[0].y
;
83 else *bounds
= empty_bounds
;
85 for (i
= 0; i
< count
; i
++)
87 bounds
->left
= min( bounds
->left
, pts
[i
].x
);
88 bounds
->right
= max( bounds
->right
, pts
[i
].x
);
89 bounds
->top
= min( bounds
->top
, pts
[i
].y
);
90 bounds
->bottom
= max( bounds
->bottom
, pts
[i
].y
);
94 /* helper for path stroke and fill functions */
95 static BOOL
emfdrv_stroke_and_fill_path( PHYSDEV dev
, INT type
)
97 DC
*dc
= get_physdev_dc( dev
);
98 EMRSTROKEANDFILLPATH emr
;
99 struct gdi_path
*path
;
103 emr
.emr
.iType
= type
;
104 emr
.emr
.nSize
= sizeof(emr
);
106 if ((path
= get_gdi_flat_path( dc
, NULL
)))
108 int count
= get_gdi_path_data( path
, &points
, &flags
);
109 get_points_bounds( &emr
.rclBounds
, points
, count
, 0 );
110 free_gdi_path( path
);
112 else emr
.rclBounds
= empty_bounds
;
114 if (!EMFDRV_WriteRecord( dev
, &emr
.emr
)) return FALSE
;
115 if (!path
) return FALSE
;
116 EMFDRV_UpdateBBox( dev
, &emr
.rclBounds
);
120 /**********************************************************************
123 BOOL CDECL
EMFDRV_MoveTo(PHYSDEV dev
, INT x
, INT y
)
127 emr
.emr
.iType
= EMR_MOVETOEX
;
128 emr
.emr
.nSize
= sizeof(emr
);
132 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
135 /***********************************************************************
138 BOOL CDECL
EMFDRV_LineTo( PHYSDEV dev
, INT x
, INT y
)
140 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
141 DC
*dc
= get_physdev_dc( dev
);
146 emr
.emr
.iType
= EMR_LINETO
;
147 emr
.emr
.nSize
= sizeof(emr
);
151 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
156 bounds
.left
= min(x
, pt
.x
);
157 bounds
.top
= min(y
, pt
.y
);
158 bounds
.right
= max(x
, pt
.x
);
159 bounds
.bottom
= max(y
, pt
.y
);
162 EMFDRV_UpdateBBox( dev
, &bounds
);
168 /***********************************************************************
172 EMFDRV_ArcChordPie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
173 INT xstart
, INT ystart
, INT xend
, INT yend
, DWORD iType
)
175 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
176 DC
*dc
= get_physdev_dc( dev
);
177 INT temp
, xCentre
, yCentre
, i
;
178 double angleStart
, angleEnd
;
179 double xinterStart
, yinterStart
, xinterEnd
, yinterEnd
;
183 if(left
== right
|| top
== bottom
) return FALSE
;
185 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
186 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
188 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
193 emr
.emr
.iType
= iType
;
194 emr
.emr
.nSize
= sizeof(emr
);
195 emr
.rclBox
.left
= left
;
196 emr
.rclBox
.top
= top
;
197 emr
.rclBox
.right
= right
;
198 emr
.rclBox
.bottom
= bottom
;
199 emr
.ptlStart
.x
= xstart
;
200 emr
.ptlStart
.y
= ystart
;
205 /* Now calculate the BBox */
206 xCentre
= (left
+ right
+ 1) / 2;
207 yCentre
= (top
+ bottom
+ 1) / 2;
214 /* invert y co-ords to get angle anti-clockwise from x-axis */
215 angleStart
= atan2( -(double)ystart
, (double)xstart
);
216 angleEnd
= atan2( -(double)yend
, (double)xend
);
218 /* These are the intercepts of the start/end lines with the arc */
220 xinterStart
= (right
- left
+ 1)/2 * cos(angleStart
) + xCentre
;
221 yinterStart
= -(bottom
- top
+ 1)/2 * sin(angleStart
) + yCentre
;
222 xinterEnd
= (right
- left
+ 1)/2 * cos(angleEnd
) + xCentre
;
223 yinterEnd
= -(bottom
- top
+ 1)/2 * sin(angleEnd
) + yCentre
;
225 if(angleStart
< 0) angleStart
+= 2 * M_PI
;
226 if(angleEnd
< 0) angleEnd
+= 2 * M_PI
;
227 if(angleEnd
< angleStart
) angleEnd
+= 2 * M_PI
;
229 bounds
.left
= min(xinterStart
, xinterEnd
);
230 bounds
.top
= min(yinterStart
, yinterEnd
);
231 bounds
.right
= max(xinterStart
, xinterEnd
);
232 bounds
.bottom
= max(yinterStart
, yinterEnd
);
234 for(i
= 0; i
<= 8; i
++) {
235 if(i
* M_PI
/ 2 < angleStart
) /* loop until we're past start */
237 if(i
* M_PI
/ 2 > angleEnd
) /* if we're past end we're finished */
240 /* the arc touches the rectangle at the start of quadrant i, so adjust
241 BBox to reflect this. */
245 bounds
.right
= right
;
254 bounds
.bottom
= bottom
;
259 /* If we're drawing a pie then make sure we include the centre */
260 if(iType
== EMR_PIE
) {
261 if(bounds
.left
> xCentre
) bounds
.left
= xCentre
;
262 else if(bounds
.right
< xCentre
) bounds
.right
= xCentre
;
263 if(bounds
.top
> yCentre
) bounds
.top
= yCentre
;
264 else if(bounds
.bottom
< yCentre
) bounds
.bottom
= yCentre
;
266 if (iType
== EMR_ARCTO
)
270 bounds
.left
= min( bounds
.left
, pt
.x
);
271 bounds
.top
= min( bounds
.top
, pt
.y
);
272 bounds
.right
= max( bounds
.right
, pt
.x
);
273 bounds
.bottom
= max( bounds
.bottom
, pt
.y
);
275 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
278 EMFDRV_UpdateBBox( dev
, &bounds
);
283 /***********************************************************************
286 BOOL CDECL
EMFDRV_Arc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
287 INT xstart
, INT ystart
, INT xend
, INT yend
)
289 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
290 xend
, yend
, EMR_ARC
);
293 /***********************************************************************
296 BOOL CDECL
EMFDRV_ArcTo( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
297 INT xstart
, INT ystart
, INT xend
, INT yend
)
299 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
300 xend
, yend
, EMR_ARCTO
);
303 /***********************************************************************
306 BOOL CDECL
EMFDRV_Pie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
307 INT xstart
, INT ystart
, INT xend
, INT yend
)
309 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
310 xend
, yend
, EMR_PIE
);
314 /***********************************************************************
317 BOOL CDECL
EMFDRV_Chord( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
318 INT xstart
, INT ystart
, INT xend
, INT yend
)
320 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
321 xend
, yend
, EMR_CHORD
);
324 /***********************************************************************
327 BOOL CDECL
EMFDRV_AngleArc( PHYSDEV dev
, INT x
, INT y
, DWORD radius
, FLOAT start
, FLOAT sweep
)
331 emr
.emr
.iType
= EMR_ANGLEARC
;
332 emr
.emr
.nSize
= sizeof( emr
);
335 emr
.nRadius
= radius
;
336 emr
.eStartAngle
= start
;
337 emr
.eSweepAngle
= sweep
;
339 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
342 /***********************************************************************
345 BOOL CDECL
EMFDRV_Ellipse( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
347 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
348 DC
*dc
= get_physdev_dc( dev
);
352 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
354 if(left
== right
|| top
== bottom
) return FALSE
;
356 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
357 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
359 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
364 emr
.emr
.iType
= EMR_ELLIPSE
;
365 emr
.emr
.nSize
= sizeof(emr
);
366 emr
.rclBox
.left
= left
;
367 emr
.rclBox
.top
= top
;
368 emr
.rclBox
.right
= right
;
369 emr
.rclBox
.bottom
= bottom
;
372 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
373 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
376 /***********************************************************************
379 BOOL CDECL
EMFDRV_Rectangle(PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
381 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
382 DC
*dc
= get_physdev_dc( dev
);
386 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
388 if(left
== right
|| top
== bottom
) return FALSE
;
390 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
391 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
393 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
398 emr
.emr
.iType
= EMR_RECTANGLE
;
399 emr
.emr
.nSize
= sizeof(emr
);
400 emr
.rclBox
.left
= left
;
401 emr
.rclBox
.top
= top
;
402 emr
.rclBox
.right
= right
;
403 emr
.rclBox
.bottom
= bottom
;
406 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
407 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
410 /***********************************************************************
413 BOOL CDECL
EMFDRV_RoundRect( PHYSDEV dev
, INT left
, INT top
, INT right
,
414 INT bottom
, INT ell_width
, INT ell_height
)
416 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
417 DC
*dc
= get_physdev_dc( dev
);
421 if(left
== right
|| top
== bottom
) return FALSE
;
423 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
424 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
426 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
431 emr
.emr
.iType
= EMR_ROUNDRECT
;
432 emr
.emr
.nSize
= sizeof(emr
);
433 emr
.rclBox
.left
= left
;
434 emr
.rclBox
.top
= top
;
435 emr
.rclBox
.right
= right
;
436 emr
.rclBox
.bottom
= bottom
;
437 emr
.szlCorner
.cx
= ell_width
;
438 emr
.szlCorner
.cy
= ell_height
;
441 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
442 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
445 /***********************************************************************
448 COLORREF CDECL
EMFDRV_SetPixel( PHYSDEV dev
, INT x
, INT y
, COLORREF color
)
452 emr
.emr
.iType
= EMR_SETPIXELV
;
453 emr
.emr
.nSize
= sizeof(emr
);
458 if (EMFDRV_WriteRecord( dev
, &emr
.emr
)) {
460 bounds
.left
= bounds
.right
= x
;
461 bounds
.top
= bounds
.bottom
= y
;
462 EMFDRV_UpdateBBox( dev
, &bounds
);
468 /**********************************************************************
471 * Helper for EMFDRV_Poly{line|gon}
474 EMFDRV_Polylinegon( PHYSDEV dev
, const POINT
* pt
, INT count
, DWORD iType
)
476 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
477 DC
*dc
= get_physdev_dc( dev
);
480 BOOL ret
, use_small_emr
= can_use_short_points( pt
, count
);
482 size
= use_small_emr
? offsetof( EMRPOLYLINE16
, apts
[count
] ) : offsetof( EMRPOLYLINE
, aptl
[count
] );
484 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
485 emr
->emr
.iType
= use_small_emr
? iType
+ EMR_POLYLINE16
- EMR_POLYLINE
: iType
;
486 emr
->emr
.nSize
= size
;
489 store_points( emr
->aptl
, pt
, count
, use_small_emr
);
492 get_points_bounds( &emr
->rclBounds
, pt
, count
,
493 (iType
== EMR_POLYBEZIERTO
|| iType
== EMR_POLYLINETO
) ? dc
: 0 );
495 emr
->rclBounds
= empty_bounds
;
497 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
498 if (ret
&& !physDev
->path
)
499 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
500 HeapFree( GetProcessHeap(), 0, emr
);
505 /**********************************************************************
508 BOOL CDECL
EMFDRV_Polyline( PHYSDEV dev
, const POINT
* pt
, INT count
)
510 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYLINE
);
513 /**********************************************************************
516 BOOL CDECL
EMFDRV_PolylineTo( PHYSDEV dev
, const POINT
* pt
, INT count
)
518 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYLINETO
);
521 /**********************************************************************
524 BOOL CDECL
EMFDRV_Polygon( PHYSDEV dev
, const POINT
* pt
, INT count
)
526 if(count
< 2) return FALSE
;
527 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYGON
);
530 /**********************************************************************
533 BOOL CDECL
EMFDRV_PolyBezier( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
535 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIER
);
538 /**********************************************************************
539 * EMFDRV_PolyBezierTo
541 BOOL CDECL
EMFDRV_PolyBezierTo( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
543 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIERTO
);
547 /**********************************************************************
548 * EMFDRV_PolyPolylinegon
550 * Helper for EMFDRV_PolyPoly{line|gon}
553 EMFDRV_PolyPolylinegon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
,
556 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
557 EMRPOLYPOLYLINE
*emr
;
558 DWORD cptl
= 0, poly
, size
;
559 BOOL ret
, use_small_emr
, bounds_valid
= TRUE
;
561 for(poly
= 0; poly
< polys
; poly
++) {
562 cptl
+= counts
[poly
];
563 if(counts
[poly
] < 2) bounds_valid
= FALSE
;
565 if(!cptl
) bounds_valid
= FALSE
;
566 use_small_emr
= can_use_short_points( pt
, cptl
);
568 size
= FIELD_OFFSET(EMRPOLYPOLYLINE
, aPolyCounts
[polys
]);
570 size
+= cptl
* sizeof(POINTS
);
572 size
+= cptl
* sizeof(POINTL
);
574 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
576 emr
->emr
.iType
= iType
;
577 if(use_small_emr
) emr
->emr
.iType
+= EMR_POLYPOLYLINE16
- EMR_POLYPOLYLINE
;
579 emr
->emr
.nSize
= size
;
580 if(bounds_valid
&& !physDev
->path
)
581 get_points_bounds( &emr
->rclBounds
, pt
, cptl
, 0 );
583 emr
->rclBounds
= empty_bounds
;
589 memcpy( emr
->aPolyCounts
, counts
, polys
* sizeof(DWORD
) );
590 store_points( (POINTL
*)(emr
->aPolyCounts
+ polys
), pt
, cptl
, use_small_emr
);
593 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
594 if(ret
&& !bounds_valid
)
597 SetLastError( ERROR_INVALID_PARAMETER
);
599 if(ret
&& !physDev
->path
)
600 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
601 HeapFree( GetProcessHeap(), 0, emr
);
605 /**********************************************************************
606 * EMFDRV_PolyPolyline
608 BOOL CDECL
EMFDRV_PolyPolyline(PHYSDEV dev
, const POINT
* pt
, const DWORD
* counts
, DWORD polys
)
610 return EMFDRV_PolyPolylinegon( dev
, pt
, (const INT
*)counts
, polys
,
614 /**********************************************************************
617 BOOL CDECL
EMFDRV_PolyPolygon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
)
619 return EMFDRV_PolyPolylinegon( dev
, pt
, counts
, polys
, EMR_POLYPOLYGON
);
623 /**********************************************************************
626 BOOL CDECL
EMFDRV_PolyDraw( PHYSDEV dev
, const POINT
*pts
, const BYTE
*types
, DWORD count
)
628 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
632 BOOL use_small_emr
= can_use_short_points( pts
, count
);
635 size
= use_small_emr
? offsetof( EMRPOLYDRAW16
, apts
[count
] ) : offsetof( EMRPOLYDRAW
, aptl
[count
] );
636 size
+= (count
+ 3) & ~3;
638 if (!(emr
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
640 emr
->emr
.iType
= use_small_emr
? EMR_POLYDRAW16
: EMR_POLYDRAW
;
641 emr
->emr
.nSize
= size
;
644 types_dest
= store_points( emr
->aptl
, pts
, count
, use_small_emr
);
645 memcpy( types_dest
, types
, count
);
646 if (count
& 3) memset( types_dest
+ count
, 0, 4 - (count
& 3) );
649 get_points_bounds( &emr
->rclBounds
, pts
, count
, 0 );
651 emr
->rclBounds
= empty_bounds
;
653 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
654 if (ret
&& !physDev
->path
) EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
655 HeapFree( GetProcessHeap(), 0, emr
);
660 /**********************************************************************
661 * EMFDRV_ExtFloodFill
663 BOOL CDECL
EMFDRV_ExtFloodFill( PHYSDEV dev
, INT x
, INT y
, COLORREF color
, UINT fillType
)
667 emr
.emr
.iType
= EMR_EXTFLOODFILL
;
668 emr
.emr
.nSize
= sizeof(emr
);
672 emr
.iMode
= fillType
;
674 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
678 /*********************************************************************
681 BOOL CDECL
EMFDRV_FillRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
)
684 DWORD size
, rgnsize
, index
;
687 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
688 if(!index
) return FALSE
;
690 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
691 size
= rgnsize
+ offsetof(EMRFILLRGN
,RgnData
);
692 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
694 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
696 emr
->emr
.iType
= EMR_FILLRGN
;
697 emr
->emr
.nSize
= size
;
698 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
699 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
700 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
701 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
702 emr
->cbRgnData
= rgnsize
;
703 emr
->ihBrush
= index
;
705 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
707 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
708 HeapFree( GetProcessHeap(), 0, emr
);
711 /*********************************************************************
714 BOOL CDECL
EMFDRV_FrameRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
, INT width
, INT height
)
717 DWORD size
, rgnsize
, index
;
720 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
721 if(!index
) return FALSE
;
723 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
724 size
= rgnsize
+ offsetof(EMRFRAMERGN
,RgnData
);
725 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
727 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
729 emr
->emr
.iType
= EMR_FRAMERGN
;
730 emr
->emr
.nSize
= size
;
731 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
732 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
733 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
734 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
735 emr
->cbRgnData
= rgnsize
;
736 emr
->ihBrush
= index
;
737 emr
->szlStroke
.cx
= width
;
738 emr
->szlStroke
.cy
= height
;
740 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
742 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
743 HeapFree( GetProcessHeap(), 0, emr
);
747 /*********************************************************************
748 * EMFDRV_PaintInvertRgn
750 * Helper for EMFDRV_{Paint|Invert}Rgn
752 static BOOL
EMFDRV_PaintInvertRgn( PHYSDEV dev
, HRGN hrgn
, DWORD iType
)
759 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
760 size
= rgnsize
+ offsetof(EMRINVERTRGN
,RgnData
);
761 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
763 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
765 emr
->emr
.iType
= iType
;
766 emr
->emr
.nSize
= size
;
767 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
768 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
769 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
770 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
771 emr
->cbRgnData
= rgnsize
;
773 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
775 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
776 HeapFree( GetProcessHeap(), 0, emr
);
780 /**********************************************************************
783 BOOL CDECL
EMFDRV_PaintRgn( PHYSDEV dev
, HRGN hrgn
)
785 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_PAINTRGN
);
788 /**********************************************************************
791 BOOL CDECL
EMFDRV_InvertRgn( PHYSDEV dev
, HRGN hrgn
)
793 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_INVERTRGN
);
796 /**********************************************************************
799 BOOL CDECL
EMFDRV_ExtTextOut( PHYSDEV dev
, INT x
, INT y
, UINT flags
, const RECT
*lprect
,
800 LPCWSTR str
, UINT count
, const INT
*lpDx
)
802 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
803 DC
*dc
= get_physdev_dc( dev
);
804 EMREXTTEXTOUTW
*pemr
;
809 const UINT textAlign
= dc
->textAlign
;
810 const INT graphicsMode
= dc
->GraphicsMode
;
811 FLOAT exScale
, eyScale
;
813 nSize
= sizeof(*pemr
) + ((count
+1) & ~1) * sizeof(WCHAR
) + count
* sizeof(INT
);
815 TRACE("%s %s count %d nSize = %d\n", debugstr_wn(str
, count
),
816 wine_dbgstr_rect(lprect
), count
, nSize
);
817 pemr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nSize
);
819 if (graphicsMode
== GM_COMPATIBLE
)
821 const INT horzSize
= GetDeviceCaps( dev
->hdc
, HORZSIZE
);
822 const INT horzRes
= GetDeviceCaps( dev
->hdc
, HORZRES
);
823 const INT vertSize
= GetDeviceCaps( dev
->hdc
, VERTSIZE
);
824 const INT vertRes
= GetDeviceCaps( dev
->hdc
, VERTRES
);
825 SIZE wndext
, vportext
;
827 GetViewportExtEx( dev
->hdc
, &vportext
);
828 GetWindowExtEx( dev
->hdc
, &wndext
);
829 exScale
= 100.0 * ((FLOAT
)horzSize
/ (FLOAT
)horzRes
) /
830 ((FLOAT
)wndext
.cx
/ (FLOAT
)vportext
.cx
);
831 eyScale
= 100.0 * ((FLOAT
)vertSize
/ (FLOAT
)vertRes
) /
832 ((FLOAT
)wndext
.cy
/ (FLOAT
)vportext
.cy
);
840 pemr
->emr
.iType
= EMR_EXTTEXTOUTW
;
841 pemr
->emr
.nSize
= nSize
;
842 pemr
->iGraphicsMode
= graphicsMode
;
843 pemr
->exScale
= exScale
;
844 pemr
->eyScale
= eyScale
;
845 pemr
->emrtext
.ptlReference
.x
= x
;
846 pemr
->emrtext
.ptlReference
.y
= y
;
847 pemr
->emrtext
.nChars
= count
;
848 pemr
->emrtext
.offString
= sizeof(*pemr
);
849 memcpy((char*)pemr
+ pemr
->emrtext
.offString
, str
, count
* sizeof(WCHAR
));
850 pemr
->emrtext
.fOptions
= flags
;
852 pemr
->emrtext
.rcl
.left
= pemr
->emrtext
.rcl
.top
= 0;
853 pemr
->emrtext
.rcl
.right
= pemr
->emrtext
.rcl
.bottom
= -1;
855 pemr
->emrtext
.rcl
.left
= lprect
->left
;
856 pemr
->emrtext
.rcl
.top
= lprect
->top
;
857 pemr
->emrtext
.rcl
.right
= lprect
->right
;
858 pemr
->emrtext
.rcl
.bottom
= lprect
->bottom
;
861 pemr
->emrtext
.offDx
= pemr
->emrtext
.offString
+ ((count
+1) & ~1) * sizeof(WCHAR
);
865 memcpy((char*)pemr
+ pemr
->emrtext
.offDx
, lpDx
, count
* sizeof(INT
));
866 for (i
= 0; i
< count
; i
++) {
867 textWidth
+= lpDx
[i
];
869 if (GetTextExtentPoint32W( dev
->hdc
, str
, count
, &strSize
))
870 textHeight
= strSize
.cy
;
874 INT
*dx
= (INT
*)((char*)pemr
+ pemr
->emrtext
.offDx
);
876 for (i
= 0; i
< count
; i
++) {
877 if (GetTextExtentPoint32W( dev
->hdc
, str
+ i
, 1, &charSize
)) {
879 textWidth
+= charSize
.cx
;
880 textHeight
= max(textHeight
, charSize
.cy
);
887 pemr
->rclBounds
.left
= pemr
->rclBounds
.top
= 0;
888 pemr
->rclBounds
.right
= pemr
->rclBounds
.bottom
= -1;
892 /* FIXME: handle font escapement */
893 switch (textAlign
& (TA_LEFT
| TA_RIGHT
| TA_CENTER
)) {
895 pemr
->rclBounds
.left
= x
- (textWidth
/ 2) - 1;
896 pemr
->rclBounds
.right
= x
+ (textWidth
/ 2) + 1;
900 pemr
->rclBounds
.left
= x
- textWidth
- 1;
901 pemr
->rclBounds
.right
= x
;
904 default: { /* TA_LEFT */
905 pemr
->rclBounds
.left
= x
;
906 pemr
->rclBounds
.right
= x
+ textWidth
+ 1;
910 switch (textAlign
& (TA_TOP
| TA_BOTTOM
| TA_BASELINE
)) {
913 if (!GetTextMetricsW( dev
->hdc
, &tm
))
915 /* Play safe here... it's better to have a bounding box */
916 /* that is too big than too small. */
917 pemr
->rclBounds
.top
= y
- textHeight
- 1;
918 pemr
->rclBounds
.bottom
= y
+ tm
.tmDescent
+ 1;
922 pemr
->rclBounds
.top
= y
- textHeight
- 1;
923 pemr
->rclBounds
.bottom
= y
;
926 default: { /* TA_TOP */
927 pemr
->rclBounds
.top
= y
;
928 pemr
->rclBounds
.bottom
= y
+ textHeight
+ 1;
931 EMFDRV_UpdateBBox( dev
, &pemr
->rclBounds
);
934 ret
= EMFDRV_WriteRecord( dev
, &pemr
->emr
);
935 HeapFree( GetProcessHeap(), 0, pemr
);
939 /**********************************************************************
940 * EMFDRV_GradientFill
942 BOOL CDECL
EMFDRV_GradientFill( PHYSDEV dev
, TRIVERTEX
*vert_array
, ULONG nvert
,
943 void *grad_array
, ULONG ngrad
, ULONG mode
)
945 EMRGRADIENTFILL
*emr
;
946 ULONG i
, pt
, size
, num_pts
= ngrad
* (mode
== GRADIENT_FILL_TRIANGLE
? 3 : 2);
947 const ULONG
*pts
= (const ULONG
*)grad_array
;
950 size
= FIELD_OFFSET(EMRGRADIENTFILL
, Ver
[nvert
]) + num_pts
* sizeof(pts
[0]);
952 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
953 if (!emr
) return FALSE
;
955 for (i
= 0; i
< num_pts
; i
++)
961 emr
->rclBounds
.left
= emr
->rclBounds
.right
= vert_array
[pt
].x
;
962 emr
->rclBounds
.top
= emr
->rclBounds
.bottom
= vert_array
[pt
].y
;
966 if (vert_array
[pt
].x
< emr
->rclBounds
.left
)
967 emr
->rclBounds
.left
= vert_array
[pt
].x
;
968 else if (vert_array
[pt
].x
> emr
->rclBounds
.right
)
969 emr
->rclBounds
.right
= vert_array
[pt
].x
;
970 if (vert_array
[pt
].y
< emr
->rclBounds
.top
)
971 emr
->rclBounds
.top
= vert_array
[pt
].y
;
972 else if (vert_array
[pt
].y
> emr
->rclBounds
.bottom
)
973 emr
->rclBounds
.bottom
= vert_array
[pt
].y
;
976 emr
->rclBounds
.right
--;
977 emr
->rclBounds
.bottom
--;
979 emr
->emr
.iType
= EMR_GRADIENTFILL
;
980 emr
->emr
.nSize
= size
;
984 memcpy( emr
->Ver
, vert_array
, nvert
* sizeof(vert_array
[0]) );
985 memcpy( emr
->Ver
+ nvert
, pts
, num_pts
* sizeof(pts
[0]) );
987 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
988 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
989 HeapFree( GetProcessHeap(), 0, emr
);
993 /**********************************************************************
996 BOOL CDECL
EMFDRV_FillPath( PHYSDEV dev
)
998 return emfdrv_stroke_and_fill_path( dev
, EMR_FILLPATH
);
1001 /**********************************************************************
1002 * EMFDRV_StrokeAndFillPath
1004 BOOL CDECL
EMFDRV_StrokeAndFillPath( PHYSDEV dev
)
1006 return emfdrv_stroke_and_fill_path( dev
, EMR_STROKEANDFILLPATH
);
1009 /**********************************************************************
1012 BOOL CDECL
EMFDRV_StrokePath( PHYSDEV dev
)
1014 return emfdrv_stroke_and_fill_path( dev
, EMR_STROKEPATH
);