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
22 #include "wine/port.h"
31 #include "enhmfdrv/enhmetafiledrv.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile
);
36 static const RECTL empty_bounds
= { 0, 0, -1, -1 };
38 /* determine if we can use 16-bit points to store all the input points */
39 static BOOL
can_use_short_points( const POINT
*pts
, UINT count
)
43 for (i
= 0; i
< count
; i
++)
44 if (((pts
[i
].x
+ 0x8000) & ~0xffff) || ((pts
[i
].y
+ 0x8000) & ~0xffff))
49 /* store points in either long or short format; return a pointer to the end of the stored data */
50 static void *store_points( POINTL
*dest
, const POINT
*pts
, UINT count
, BOOL short_points
)
55 POINTS
*dest_short
= (POINTS
*)dest
;
57 for (i
= 0; i
< count
; i
++)
59 dest_short
[i
].x
= pts
[i
].x
;
60 dest_short
[i
].y
= pts
[i
].y
;
62 return dest_short
+ count
;
66 memcpy( dest
, pts
, count
* sizeof(*dest
) );
71 /* compute the bounds of an array of points, optionally including the current position */
72 static void get_points_bounds( RECTL
*bounds
, const POINT
*pts
, UINT count
, HDC hdc
)
79 GetCurrentPositionEx( hdc
, &cur_pt
);
80 bounds
->left
= bounds
->right
= cur_pt
.x
;
81 bounds
->top
= bounds
->bottom
= cur_pt
.y
;
85 bounds
->left
= bounds
->right
= pts
[0].x
;
86 bounds
->top
= bounds
->bottom
= pts
[0].y
;
88 else *bounds
= empty_bounds
;
90 for (i
= 0; i
< count
; i
++)
92 bounds
->left
= min( bounds
->left
, pts
[i
].x
);
93 bounds
->right
= max( bounds
->right
, pts
[i
].x
);
94 bounds
->top
= min( bounds
->top
, pts
[i
].y
);
95 bounds
->bottom
= max( bounds
->bottom
, pts
[i
].y
);
99 /* helper for path stroke and fill functions */
100 static BOOL
emfdrv_stroke_and_fill_path( PHYSDEV dev
, INT type
)
102 EMRSTROKEANDFILLPATH emr
;
103 struct gdi_path
*path
;
107 emr
.emr
.iType
= type
;
108 emr
.emr
.nSize
= sizeof(emr
);
110 if ((path
= get_gdi_flat_path( dev
->hdc
, NULL
)))
112 int count
= get_gdi_path_data( path
, &points
, &flags
);
113 get_points_bounds( &emr
.rclBounds
, points
, count
, 0 );
114 free_gdi_path( path
);
116 else emr
.rclBounds
= empty_bounds
;
118 if (!EMFDRV_WriteRecord( dev
, &emr
.emr
)) return FALSE
;
119 if (!path
) return FALSE
;
120 EMFDRV_UpdateBBox( dev
, &emr
.rclBounds
);
124 /**********************************************************************
127 BOOL
EMFDRV_MoveTo(PHYSDEV dev
, INT x
, INT y
)
131 emr
.emr
.iType
= EMR_MOVETOEX
;
132 emr
.emr
.nSize
= sizeof(emr
);
136 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
139 /***********************************************************************
142 BOOL
EMFDRV_LineTo( PHYSDEV dev
, INT x
, INT y
)
144 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
149 emr
.emr
.iType
= EMR_LINETO
;
150 emr
.emr
.nSize
= sizeof(emr
);
154 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
157 GetCurrentPositionEx( dev
->hdc
, &pt
);
159 bounds
.left
= min(x
, pt
.x
);
160 bounds
.top
= min(y
, pt
.y
);
161 bounds
.right
= max(x
, pt
.x
);
162 bounds
.bottom
= max(y
, pt
.y
);
165 EMFDRV_UpdateBBox( dev
, &bounds
);
171 /***********************************************************************
175 EMFDRV_ArcChordPie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
176 INT xstart
, INT ystart
, INT xend
, INT yend
, DWORD iType
)
178 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
179 INT temp
, xCentre
, yCentre
, i
;
180 double angleStart
, angleEnd
;
181 double xinterStart
, yinterStart
, xinterEnd
, yinterEnd
;
185 if(left
== right
|| top
== bottom
) return FALSE
;
187 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
188 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
190 if(GetGraphicsMode(dev
->hdc
) == GM_COMPATIBLE
) {
195 emr
.emr
.iType
= iType
;
196 emr
.emr
.nSize
= sizeof(emr
);
197 emr
.rclBox
.left
= left
;
198 emr
.rclBox
.top
= top
;
199 emr
.rclBox
.right
= right
;
200 emr
.rclBox
.bottom
= bottom
;
201 emr
.ptlStart
.x
= xstart
;
202 emr
.ptlStart
.y
= ystart
;
207 /* Now calculate the BBox */
208 xCentre
= (left
+ right
+ 1) / 2;
209 yCentre
= (top
+ bottom
+ 1) / 2;
216 /* invert y co-ords to get angle anti-clockwise from x-axis */
217 angleStart
= atan2( -(double)ystart
, (double)xstart
);
218 angleEnd
= atan2( -(double)yend
, (double)xend
);
220 /* These are the intercepts of the start/end lines with the arc */
222 xinterStart
= (right
- left
+ 1)/2 * cos(angleStart
) + xCentre
;
223 yinterStart
= -(bottom
- top
+ 1)/2 * sin(angleStart
) + yCentre
;
224 xinterEnd
= (right
- left
+ 1)/2 * cos(angleEnd
) + xCentre
;
225 yinterEnd
= -(bottom
- top
+ 1)/2 * sin(angleEnd
) + yCentre
;
227 if(angleStart
< 0) angleStart
+= 2 * M_PI
;
228 if(angleEnd
< 0) angleEnd
+= 2 * M_PI
;
229 if(angleEnd
< angleStart
) angleEnd
+= 2 * M_PI
;
231 bounds
.left
= min(xinterStart
, xinterEnd
);
232 bounds
.top
= min(yinterStart
, yinterEnd
);
233 bounds
.right
= max(xinterStart
, xinterEnd
);
234 bounds
.bottom
= max(yinterStart
, yinterEnd
);
236 for(i
= 0; i
<= 8; i
++) {
237 if(i
* M_PI
/ 2 < angleStart
) /* loop until we're past start */
239 if(i
* M_PI
/ 2 > angleEnd
) /* if we're past end we're finished */
242 /* the arc touches the rectangle at the start of quadrant i, so adjust
243 BBox to reflect this. */
247 bounds
.right
= right
;
256 bounds
.bottom
= bottom
;
261 /* If we're drawing a pie then make sure we include the centre */
262 if(iType
== EMR_PIE
) {
263 if(bounds
.left
> xCentre
) bounds
.left
= xCentre
;
264 else if(bounds
.right
< xCentre
) bounds
.right
= xCentre
;
265 if(bounds
.top
> yCentre
) bounds
.top
= yCentre
;
266 else if(bounds
.bottom
< yCentre
) bounds
.bottom
= yCentre
;
268 if (iType
== EMR_ARCTO
)
271 GetCurrentPositionEx( dev
->hdc
, &pt
);
272 bounds
.left
= min( bounds
.left
, pt
.x
);
273 bounds
.top
= min( bounds
.top
, pt
.y
);
274 bounds
.right
= max( bounds
.right
, pt
.x
);
275 bounds
.bottom
= max( bounds
.bottom
, pt
.y
);
277 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
280 EMFDRV_UpdateBBox( dev
, &bounds
);
285 /***********************************************************************
288 BOOL
EMFDRV_Arc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
289 INT xstart
, INT ystart
, INT xend
, INT yend
)
291 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
292 xend
, yend
, EMR_ARC
);
295 /***********************************************************************
298 BOOL
EMFDRV_ArcTo( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
299 INT xstart
, INT ystart
, INT xend
, INT yend
)
301 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
302 xend
, yend
, EMR_ARCTO
);
305 /***********************************************************************
308 BOOL
EMFDRV_Pie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
309 INT xstart
, INT ystart
, INT xend
, INT yend
)
311 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
312 xend
, yend
, EMR_PIE
);
316 /***********************************************************************
319 BOOL
EMFDRV_Chord( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
320 INT xstart
, INT ystart
, INT xend
, INT yend
)
322 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
323 xend
, yend
, EMR_CHORD
);
326 /***********************************************************************
329 BOOL
EMFDRV_AngleArc( PHYSDEV dev
, INT x
, INT y
, DWORD radius
, FLOAT start
, FLOAT sweep
)
333 emr
.emr
.iType
= EMR_ANGLEARC
;
334 emr
.emr
.nSize
= sizeof( emr
);
337 emr
.nRadius
= radius
;
338 emr
.eStartAngle
= start
;
339 emr
.eSweepAngle
= sweep
;
341 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
344 /***********************************************************************
347 BOOL
EMFDRV_Ellipse( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
349 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
353 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
355 if(left
== right
|| top
== bottom
) return FALSE
;
357 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
358 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
360 if(GetGraphicsMode( dev
->hdc
) == GM_COMPATIBLE
) {
365 emr
.emr
.iType
= EMR_ELLIPSE
;
366 emr
.emr
.nSize
= sizeof(emr
);
367 emr
.rclBox
.left
= left
;
368 emr
.rclBox
.top
= top
;
369 emr
.rclBox
.right
= right
;
370 emr
.rclBox
.bottom
= bottom
;
373 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
374 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
377 /***********************************************************************
380 BOOL
EMFDRV_Rectangle(PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
382 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( 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(GetGraphicsMode( dev
->hdc
) == 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
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
);
420 if(left
== right
|| top
== bottom
) return FALSE
;
422 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
423 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
425 if(GetGraphicsMode( dev
->hdc
) == GM_COMPATIBLE
) {
430 emr
.emr
.iType
= EMR_ROUNDRECT
;
431 emr
.emr
.nSize
= sizeof(emr
);
432 emr
.rclBox
.left
= left
;
433 emr
.rclBox
.top
= top
;
434 emr
.rclBox
.right
= right
;
435 emr
.rclBox
.bottom
= bottom
;
436 emr
.szlCorner
.cx
= ell_width
;
437 emr
.szlCorner
.cy
= ell_height
;
440 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
441 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
444 /***********************************************************************
447 COLORREF
EMFDRV_SetPixel( PHYSDEV dev
, INT x
, INT y
, COLORREF color
)
451 emr
.emr
.iType
= EMR_SETPIXELV
;
452 emr
.emr
.nSize
= sizeof(emr
);
457 if (EMFDRV_WriteRecord( dev
, &emr
.emr
)) {
459 bounds
.left
= bounds
.right
= x
;
460 bounds
.top
= bounds
.bottom
= y
;
461 EMFDRV_UpdateBBox( dev
, &bounds
);
467 /**********************************************************************
470 * Helper for EMFDRV_Poly{line|gon}
473 EMFDRV_Polylinegon( PHYSDEV dev
, const POINT
* pt
, INT count
, DWORD iType
)
475 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
478 BOOL ret
, use_small_emr
= can_use_short_points( pt
, count
);
480 size
= use_small_emr
? offsetof( EMRPOLYLINE16
, apts
[count
] ) : offsetof( EMRPOLYLINE
, aptl
[count
] );
482 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
483 emr
->emr
.iType
= use_small_emr
? iType
+ EMR_POLYLINE16
- EMR_POLYLINE
: iType
;
484 emr
->emr
.nSize
= size
;
487 store_points( emr
->aptl
, pt
, count
, use_small_emr
);
490 get_points_bounds( &emr
->rclBounds
, pt
, count
,
491 (iType
== EMR_POLYBEZIERTO
|| iType
== EMR_POLYLINETO
) ? dev
->hdc
: 0 );
493 emr
->rclBounds
= empty_bounds
;
495 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
496 if (ret
&& !physDev
->path
)
497 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
498 HeapFree( GetProcessHeap(), 0, emr
);
503 /**********************************************************************
506 BOOL
EMFDRV_Polyline( PHYSDEV dev
, const POINT
* pt
, INT count
)
508 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYLINE
);
511 /**********************************************************************
514 BOOL
EMFDRV_PolylineTo( PHYSDEV dev
, const POINT
* pt
, INT count
)
516 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYLINETO
);
519 /**********************************************************************
522 BOOL
EMFDRV_Polygon( PHYSDEV dev
, const POINT
* pt
, INT count
)
524 if(count
< 2) return FALSE
;
525 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYGON
);
528 /**********************************************************************
531 BOOL
EMFDRV_PolyBezier( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
533 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIER
);
536 /**********************************************************************
537 * EMFDRV_PolyBezierTo
539 BOOL
EMFDRV_PolyBezierTo( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
541 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIERTO
);
545 /**********************************************************************
546 * EMFDRV_PolyPolylinegon
548 * Helper for EMFDRV_PolyPoly{line|gon}
551 EMFDRV_PolyPolylinegon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
,
554 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
555 EMRPOLYPOLYLINE
*emr
;
556 DWORD cptl
= 0, poly
, size
;
557 BOOL ret
, use_small_emr
, bounds_valid
= TRUE
;
559 for(poly
= 0; poly
< polys
; poly
++) {
560 cptl
+= counts
[poly
];
561 if(counts
[poly
] < 2) bounds_valid
= FALSE
;
563 if(!cptl
) bounds_valid
= FALSE
;
564 use_small_emr
= can_use_short_points( pt
, cptl
);
566 size
= FIELD_OFFSET(EMRPOLYPOLYLINE
, aPolyCounts
[polys
]);
568 size
+= cptl
* sizeof(POINTS
);
570 size
+= cptl
* sizeof(POINTL
);
572 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
574 emr
->emr
.iType
= iType
;
575 if(use_small_emr
) emr
->emr
.iType
+= EMR_POLYPOLYLINE16
- EMR_POLYPOLYLINE
;
577 emr
->emr
.nSize
= size
;
578 if(bounds_valid
&& !physDev
->path
)
579 get_points_bounds( &emr
->rclBounds
, pt
, cptl
, 0 );
581 emr
->rclBounds
= empty_bounds
;
587 memcpy( emr
->aPolyCounts
, counts
, polys
* sizeof(DWORD
) );
588 store_points( (POINTL
*)(emr
->aPolyCounts
+ polys
), pt
, cptl
, use_small_emr
);
591 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
592 if(ret
&& !bounds_valid
)
595 SetLastError( ERROR_INVALID_PARAMETER
);
597 if(ret
&& !physDev
->path
)
598 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
599 HeapFree( GetProcessHeap(), 0, emr
);
603 /**********************************************************************
604 * EMFDRV_PolyPolyline
606 BOOL
EMFDRV_PolyPolyline(PHYSDEV dev
, const POINT
* pt
, const DWORD
* counts
, DWORD polys
)
608 return EMFDRV_PolyPolylinegon( dev
, pt
, (const INT
*)counts
, polys
,
612 /**********************************************************************
615 BOOL
EMFDRV_PolyPolygon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
)
617 return EMFDRV_PolyPolylinegon( dev
, pt
, counts
, polys
, EMR_POLYPOLYGON
);
621 /**********************************************************************
624 BOOL
EMFDRV_PolyDraw( PHYSDEV dev
, const POINT
*pts
, const BYTE
*types
, DWORD count
)
626 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
630 BOOL use_small_emr
= can_use_short_points( pts
, count
);
633 size
= use_small_emr
? offsetof( EMRPOLYDRAW16
, apts
[count
] ) : offsetof( EMRPOLYDRAW
, aptl
[count
] );
634 size
+= (count
+ 3) & ~3;
636 if (!(emr
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
638 emr
->emr
.iType
= use_small_emr
? EMR_POLYDRAW16
: EMR_POLYDRAW
;
639 emr
->emr
.nSize
= size
;
642 types_dest
= store_points( emr
->aptl
, pts
, count
, use_small_emr
);
643 memcpy( types_dest
, types
, count
);
644 if (count
& 3) memset( types_dest
+ count
, 0, 4 - (count
& 3) );
647 get_points_bounds( &emr
->rclBounds
, pts
, count
, 0 );
649 emr
->rclBounds
= empty_bounds
;
651 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
652 if (ret
&& !physDev
->path
) EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
653 HeapFree( GetProcessHeap(), 0, emr
);
658 /**********************************************************************
659 * EMFDRV_ExtFloodFill
661 BOOL
EMFDRV_ExtFloodFill( PHYSDEV dev
, INT x
, INT y
, COLORREF color
, UINT fillType
)
665 emr
.emr
.iType
= EMR_EXTFLOODFILL
;
666 emr
.emr
.nSize
= sizeof(emr
);
670 emr
.iMode
= fillType
;
672 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
676 /*********************************************************************
679 BOOL
EMFDRV_FillRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
)
682 DWORD size
, rgnsize
, index
;
685 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
686 if(!index
) return FALSE
;
688 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
689 size
= rgnsize
+ offsetof(EMRFILLRGN
,RgnData
);
690 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
692 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
694 emr
->emr
.iType
= EMR_FILLRGN
;
695 emr
->emr
.nSize
= size
;
696 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
697 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
698 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
699 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
700 emr
->cbRgnData
= rgnsize
;
701 emr
->ihBrush
= index
;
703 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
705 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
706 HeapFree( GetProcessHeap(), 0, emr
);
709 /*********************************************************************
712 BOOL
EMFDRV_FrameRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
, INT width
, INT height
)
715 DWORD size
, rgnsize
, index
;
718 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
719 if(!index
) return FALSE
;
721 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
722 size
= rgnsize
+ offsetof(EMRFRAMERGN
,RgnData
);
723 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
725 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
727 emr
->emr
.iType
= EMR_FRAMERGN
;
728 emr
->emr
.nSize
= size
;
729 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
730 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
731 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
732 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
733 emr
->cbRgnData
= rgnsize
;
734 emr
->ihBrush
= index
;
735 emr
->szlStroke
.cx
= width
;
736 emr
->szlStroke
.cy
= height
;
738 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
740 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
741 HeapFree( GetProcessHeap(), 0, emr
);
745 /*********************************************************************
746 * EMFDRV_PaintInvertRgn
748 * Helper for EMFDRV_{Paint|Invert}Rgn
750 static BOOL
EMFDRV_PaintInvertRgn( PHYSDEV dev
, HRGN hrgn
, DWORD iType
)
757 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
758 size
= rgnsize
+ offsetof(EMRINVERTRGN
,RgnData
);
759 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
761 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
763 emr
->emr
.iType
= iType
;
764 emr
->emr
.nSize
= size
;
765 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
766 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
767 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
768 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
769 emr
->cbRgnData
= rgnsize
;
771 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
773 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
774 HeapFree( GetProcessHeap(), 0, emr
);
778 /**********************************************************************
781 BOOL
EMFDRV_PaintRgn( PHYSDEV dev
, HRGN hrgn
)
783 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_PAINTRGN
);
786 /**********************************************************************
789 BOOL
EMFDRV_InvertRgn( PHYSDEV dev
, HRGN hrgn
)
791 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_INVERTRGN
);
794 /**********************************************************************
797 BOOL
EMFDRV_ExtTextOut( PHYSDEV dev
, INT x
, INT y
, UINT flags
, const RECT
*lprect
,
798 LPCWSTR str
, UINT count
, const INT
*lpDx
)
800 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
801 EMREXTTEXTOUTW
*pemr
;
806 const UINT textAlign
= GetTextAlign( dev
->hdc
);
807 const INT graphicsMode
= GetGraphicsMode( dev
->hdc
);
808 FLOAT exScale
, eyScale
;
810 nSize
= sizeof(*pemr
) + ((count
+1) & ~1) * sizeof(WCHAR
) + count
* sizeof(INT
);
812 TRACE("%s %s count %d nSize = %d\n", debugstr_wn(str
, count
),
813 wine_dbgstr_rect(lprect
), count
, nSize
);
814 pemr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nSize
);
816 if (graphicsMode
== GM_COMPATIBLE
)
818 const INT horzSize
= GetDeviceCaps( dev
->hdc
, HORZSIZE
);
819 const INT horzRes
= GetDeviceCaps( dev
->hdc
, HORZRES
);
820 const INT vertSize
= GetDeviceCaps( dev
->hdc
, VERTSIZE
);
821 const INT vertRes
= GetDeviceCaps( dev
->hdc
, VERTRES
);
822 SIZE wndext
, vportext
;
824 GetViewportExtEx( dev
->hdc
, &vportext
);
825 GetWindowExtEx( dev
->hdc
, &wndext
);
826 exScale
= 100.0 * ((FLOAT
)horzSize
/ (FLOAT
)horzRes
) /
827 ((FLOAT
)wndext
.cx
/ (FLOAT
)vportext
.cx
);
828 eyScale
= 100.0 * ((FLOAT
)vertSize
/ (FLOAT
)vertRes
) /
829 ((FLOAT
)wndext
.cy
/ (FLOAT
)vportext
.cy
);
837 pemr
->emr
.iType
= EMR_EXTTEXTOUTW
;
838 pemr
->emr
.nSize
= nSize
;
839 pemr
->iGraphicsMode
= graphicsMode
;
840 pemr
->exScale
= exScale
;
841 pemr
->eyScale
= eyScale
;
842 pemr
->emrtext
.ptlReference
.x
= x
;
843 pemr
->emrtext
.ptlReference
.y
= y
;
844 pemr
->emrtext
.nChars
= count
;
845 pemr
->emrtext
.offString
= sizeof(*pemr
);
846 memcpy((char*)pemr
+ pemr
->emrtext
.offString
, str
, count
* sizeof(WCHAR
));
847 pemr
->emrtext
.fOptions
= flags
;
849 pemr
->emrtext
.rcl
.left
= pemr
->emrtext
.rcl
.top
= 0;
850 pemr
->emrtext
.rcl
.right
= pemr
->emrtext
.rcl
.bottom
= -1;
852 pemr
->emrtext
.rcl
.left
= lprect
->left
;
853 pemr
->emrtext
.rcl
.top
= lprect
->top
;
854 pemr
->emrtext
.rcl
.right
= lprect
->right
;
855 pemr
->emrtext
.rcl
.bottom
= lprect
->bottom
;
858 pemr
->emrtext
.offDx
= pemr
->emrtext
.offString
+ ((count
+1) & ~1) * sizeof(WCHAR
);
862 memcpy((char*)pemr
+ pemr
->emrtext
.offDx
, lpDx
, count
* sizeof(INT
));
863 for (i
= 0; i
< count
; i
++) {
864 textWidth
+= lpDx
[i
];
866 if (GetTextExtentPoint32W( dev
->hdc
, str
, count
, &strSize
))
867 textHeight
= strSize
.cy
;
871 INT
*dx
= (INT
*)((char*)pemr
+ pemr
->emrtext
.offDx
);
873 for (i
= 0; i
< count
; i
++) {
874 if (GetTextExtentPoint32W( dev
->hdc
, str
+ i
, 1, &charSize
)) {
876 textWidth
+= charSize
.cx
;
877 textHeight
= max(textHeight
, charSize
.cy
);
884 pemr
->rclBounds
.left
= pemr
->rclBounds
.top
= 0;
885 pemr
->rclBounds
.right
= pemr
->rclBounds
.bottom
= -1;
889 /* FIXME: handle font escapement */
890 switch (textAlign
& (TA_LEFT
| TA_RIGHT
| TA_CENTER
)) {
892 pemr
->rclBounds
.left
= x
- (textWidth
/ 2) - 1;
893 pemr
->rclBounds
.right
= x
+ (textWidth
/ 2) + 1;
897 pemr
->rclBounds
.left
= x
- textWidth
- 1;
898 pemr
->rclBounds
.right
= x
;
901 default: { /* TA_LEFT */
902 pemr
->rclBounds
.left
= x
;
903 pemr
->rclBounds
.right
= x
+ textWidth
+ 1;
907 switch (textAlign
& (TA_TOP
| TA_BOTTOM
| TA_BASELINE
)) {
910 if (!GetTextMetricsW( dev
->hdc
, &tm
))
912 /* Play safe here... it's better to have a bounding box */
913 /* that is too big than too small. */
914 pemr
->rclBounds
.top
= y
- textHeight
- 1;
915 pemr
->rclBounds
.bottom
= y
+ tm
.tmDescent
+ 1;
919 pemr
->rclBounds
.top
= y
- textHeight
- 1;
920 pemr
->rclBounds
.bottom
= y
;
923 default: { /* TA_TOP */
924 pemr
->rclBounds
.top
= y
;
925 pemr
->rclBounds
.bottom
= y
+ textHeight
+ 1;
928 EMFDRV_UpdateBBox( dev
, &pemr
->rclBounds
);
931 ret
= EMFDRV_WriteRecord( dev
, &pemr
->emr
);
932 HeapFree( GetProcessHeap(), 0, pemr
);
936 /**********************************************************************
937 * EMFDRV_GradientFill
939 BOOL
EMFDRV_GradientFill( PHYSDEV dev
, TRIVERTEX
*vert_array
, ULONG nvert
,
940 void *grad_array
, ULONG ngrad
, ULONG mode
)
942 EMRGRADIENTFILL
*emr
;
943 ULONG i
, pt
, size
, num_pts
= ngrad
* (mode
== GRADIENT_FILL_TRIANGLE
? 3 : 2);
944 const ULONG
*pts
= (const ULONG
*)grad_array
;
947 size
= FIELD_OFFSET(EMRGRADIENTFILL
, Ver
[nvert
]) + num_pts
* sizeof(pts
[0]);
949 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
950 if (!emr
) return FALSE
;
952 for (i
= 0; i
< num_pts
; i
++)
958 emr
->rclBounds
.left
= emr
->rclBounds
.right
= vert_array
[pt
].x
;
959 emr
->rclBounds
.top
= emr
->rclBounds
.bottom
= vert_array
[pt
].y
;
963 if (vert_array
[pt
].x
< emr
->rclBounds
.left
)
964 emr
->rclBounds
.left
= vert_array
[pt
].x
;
965 else if (vert_array
[pt
].x
> emr
->rclBounds
.right
)
966 emr
->rclBounds
.right
= vert_array
[pt
].x
;
967 if (vert_array
[pt
].y
< emr
->rclBounds
.top
)
968 emr
->rclBounds
.top
= vert_array
[pt
].y
;
969 else if (vert_array
[pt
].y
> emr
->rclBounds
.bottom
)
970 emr
->rclBounds
.bottom
= vert_array
[pt
].y
;
973 emr
->rclBounds
.right
--;
974 emr
->rclBounds
.bottom
--;
976 emr
->emr
.iType
= EMR_GRADIENTFILL
;
977 emr
->emr
.nSize
= size
;
981 memcpy( emr
->Ver
, vert_array
, nvert
* sizeof(vert_array
[0]) );
982 memcpy( emr
->Ver
+ nvert
, pts
, num_pts
* sizeof(pts
[0]) );
984 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
985 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
986 HeapFree( GetProcessHeap(), 0, emr
);
990 /**********************************************************************
993 BOOL
EMFDRV_FillPath( PHYSDEV dev
)
995 return emfdrv_stroke_and_fill_path( dev
, EMR_FILLPATH
);
998 /**********************************************************************
999 * EMFDRV_StrokeAndFillPath
1001 BOOL
EMFDRV_StrokeAndFillPath( PHYSDEV dev
)
1003 return emfdrv_stroke_and_fill_path( dev
, EMR_STROKEANDFILLPATH
);
1006 /**********************************************************************
1009 BOOL
EMFDRV_StrokePath( PHYSDEV dev
)
1011 return emfdrv_stroke_and_fill_path( dev
, EMR_STROKEPATH
);