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
, DC
*dc
)
78 bounds
->left
= bounds
->right
= dc
->cur_pos
.x
;
79 bounds
->top
= bounds
->bottom
= dc
->cur_pos
.y
;
83 bounds
->left
= bounds
->right
= pts
[0].x
;
84 bounds
->top
= bounds
->bottom
= pts
[0].y
;
86 else *bounds
= empty_bounds
;
88 for (i
= 0; i
< count
; i
++)
90 bounds
->left
= min( bounds
->left
, pts
[i
].x
);
91 bounds
->right
= max( bounds
->right
, pts
[i
].x
);
92 bounds
->top
= min( bounds
->top
, pts
[i
].y
);
93 bounds
->bottom
= max( bounds
->bottom
, pts
[i
].y
);
97 /* helper for path stroke and fill functions */
98 static BOOL
emfdrv_stroke_and_fill_path( PHYSDEV dev
, INT type
)
100 DC
*dc
= get_physdev_dc( dev
);
101 EMRSTROKEANDFILLPATH emr
;
102 struct gdi_path
*path
;
106 emr
.emr
.iType
= type
;
107 emr
.emr
.nSize
= sizeof(emr
);
109 if ((path
= get_gdi_flat_path( dc
, NULL
)))
111 int count
= get_gdi_path_data( path
, &points
, &flags
);
112 get_points_bounds( &emr
.rclBounds
, points
, count
, 0 );
113 free_gdi_path( path
);
115 else emr
.rclBounds
= empty_bounds
;
117 if (!EMFDRV_WriteRecord( dev
, &emr
.emr
)) return FALSE
;
118 if (!path
) return FALSE
;
119 EMFDRV_UpdateBBox( dev
, &emr
.rclBounds
);
123 /**********************************************************************
126 BOOL
EMFDRV_MoveTo(PHYSDEV dev
, INT x
, INT y
)
130 emr
.emr
.iType
= EMR_MOVETOEX
;
131 emr
.emr
.nSize
= sizeof(emr
);
135 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
138 /***********************************************************************
141 BOOL
EMFDRV_LineTo( PHYSDEV dev
, INT x
, INT y
)
143 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
144 DC
*dc
= get_physdev_dc( dev
);
149 emr
.emr
.iType
= EMR_LINETO
;
150 emr
.emr
.nSize
= sizeof(emr
);
154 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
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 DC
*dc
= get_physdev_dc( dev
);
180 INT temp
, xCentre
, yCentre
, i
;
181 double angleStart
, angleEnd
;
182 double xinterStart
, yinterStart
, xinterEnd
, yinterEnd
;
186 if(left
== right
|| top
== bottom
) return FALSE
;
188 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
189 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
191 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
196 emr
.emr
.iType
= iType
;
197 emr
.emr
.nSize
= sizeof(emr
);
198 emr
.rclBox
.left
= left
;
199 emr
.rclBox
.top
= top
;
200 emr
.rclBox
.right
= right
;
201 emr
.rclBox
.bottom
= bottom
;
202 emr
.ptlStart
.x
= xstart
;
203 emr
.ptlStart
.y
= ystart
;
208 /* Now calculate the BBox */
209 xCentre
= (left
+ right
+ 1) / 2;
210 yCentre
= (top
+ bottom
+ 1) / 2;
217 /* invert y co-ords to get angle anti-clockwise from x-axis */
218 angleStart
= atan2( -(double)ystart
, (double)xstart
);
219 angleEnd
= atan2( -(double)yend
, (double)xend
);
221 /* These are the intercepts of the start/end lines with the arc */
223 xinterStart
= (right
- left
+ 1)/2 * cos(angleStart
) + xCentre
;
224 yinterStart
= -(bottom
- top
+ 1)/2 * sin(angleStart
) + yCentre
;
225 xinterEnd
= (right
- left
+ 1)/2 * cos(angleEnd
) + xCentre
;
226 yinterEnd
= -(bottom
- top
+ 1)/2 * sin(angleEnd
) + yCentre
;
228 if(angleStart
< 0) angleStart
+= 2 * M_PI
;
229 if(angleEnd
< 0) angleEnd
+= 2 * M_PI
;
230 if(angleEnd
< angleStart
) angleEnd
+= 2 * M_PI
;
232 bounds
.left
= min(xinterStart
, xinterEnd
);
233 bounds
.top
= min(yinterStart
, yinterEnd
);
234 bounds
.right
= max(xinterStart
, xinterEnd
);
235 bounds
.bottom
= max(yinterStart
, yinterEnd
);
237 for(i
= 0; i
<= 8; i
++) {
238 if(i
* M_PI
/ 2 < angleStart
) /* loop until we're past start */
240 if(i
* M_PI
/ 2 > angleEnd
) /* if we're past end we're finished */
243 /* the arc touches the rectangle at the start of quadrant i, so adjust
244 BBox to reflect this. */
248 bounds
.right
= right
;
257 bounds
.bottom
= bottom
;
262 /* If we're drawing a pie then make sure we include the centre */
263 if(iType
== EMR_PIE
) {
264 if(bounds
.left
> xCentre
) bounds
.left
= xCentre
;
265 else if(bounds
.right
< xCentre
) bounds
.right
= xCentre
;
266 if(bounds
.top
> yCentre
) bounds
.top
= yCentre
;
267 else if(bounds
.bottom
< yCentre
) bounds
.bottom
= yCentre
;
269 if (iType
== EMR_ARCTO
)
273 bounds
.left
= min( bounds
.left
, pt
.x
);
274 bounds
.top
= min( bounds
.top
, pt
.y
);
275 bounds
.right
= max( bounds
.right
, pt
.x
);
276 bounds
.bottom
= max( bounds
.bottom
, pt
.y
);
278 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
281 EMFDRV_UpdateBBox( dev
, &bounds
);
286 /***********************************************************************
289 BOOL
EMFDRV_Arc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
290 INT xstart
, INT ystart
, INT xend
, INT yend
)
292 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
293 xend
, yend
, EMR_ARC
);
296 /***********************************************************************
299 BOOL
EMFDRV_ArcTo( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
300 INT xstart
, INT ystart
, INT xend
, INT yend
)
302 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
303 xend
, yend
, EMR_ARCTO
);
306 /***********************************************************************
309 BOOL
EMFDRV_Pie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
310 INT xstart
, INT ystart
, INT xend
, INT yend
)
312 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
313 xend
, yend
, EMR_PIE
);
317 /***********************************************************************
320 BOOL
EMFDRV_Chord( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
321 INT xstart
, INT ystart
, INT xend
, INT yend
)
323 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
324 xend
, yend
, EMR_CHORD
);
327 /***********************************************************************
330 BOOL
EMFDRV_AngleArc( PHYSDEV dev
, INT x
, INT y
, DWORD radius
, FLOAT start
, FLOAT sweep
)
334 emr
.emr
.iType
= EMR_ANGLEARC
;
335 emr
.emr
.nSize
= sizeof( emr
);
338 emr
.nRadius
= radius
;
339 emr
.eStartAngle
= start
;
340 emr
.eSweepAngle
= sweep
;
342 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
345 /***********************************************************************
348 BOOL
EMFDRV_Ellipse( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
350 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
351 DC
*dc
= get_physdev_dc( dev
);
355 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
357 if(left
== right
|| top
== bottom
) return FALSE
;
359 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
360 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
362 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
367 emr
.emr
.iType
= EMR_ELLIPSE
;
368 emr
.emr
.nSize
= sizeof(emr
);
369 emr
.rclBox
.left
= left
;
370 emr
.rclBox
.top
= top
;
371 emr
.rclBox
.right
= right
;
372 emr
.rclBox
.bottom
= bottom
;
375 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
376 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
379 /***********************************************************************
382 BOOL
EMFDRV_Rectangle(PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
384 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
385 DC
*dc
= get_physdev_dc( dev
);
389 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
391 if(left
== right
|| top
== bottom
) return FALSE
;
393 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
394 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
396 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
401 emr
.emr
.iType
= EMR_RECTANGLE
;
402 emr
.emr
.nSize
= sizeof(emr
);
403 emr
.rclBox
.left
= left
;
404 emr
.rclBox
.top
= top
;
405 emr
.rclBox
.right
= right
;
406 emr
.rclBox
.bottom
= bottom
;
409 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
410 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
413 /***********************************************************************
416 BOOL
EMFDRV_RoundRect( PHYSDEV dev
, INT left
, INT top
, INT right
,
417 INT bottom
, INT ell_width
, INT ell_height
)
419 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
420 DC
*dc
= get_physdev_dc( dev
);
424 if(left
== right
|| top
== bottom
) return FALSE
;
426 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
427 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
429 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
434 emr
.emr
.iType
= EMR_ROUNDRECT
;
435 emr
.emr
.nSize
= sizeof(emr
);
436 emr
.rclBox
.left
= left
;
437 emr
.rclBox
.top
= top
;
438 emr
.rclBox
.right
= right
;
439 emr
.rclBox
.bottom
= bottom
;
440 emr
.szlCorner
.cx
= ell_width
;
441 emr
.szlCorner
.cy
= ell_height
;
444 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
445 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
448 /***********************************************************************
451 COLORREF
EMFDRV_SetPixel( PHYSDEV dev
, INT x
, INT y
, COLORREF color
)
455 emr
.emr
.iType
= EMR_SETPIXELV
;
456 emr
.emr
.nSize
= sizeof(emr
);
461 if (EMFDRV_WriteRecord( dev
, &emr
.emr
)) {
463 bounds
.left
= bounds
.right
= x
;
464 bounds
.top
= bounds
.bottom
= y
;
465 EMFDRV_UpdateBBox( dev
, &bounds
);
471 /**********************************************************************
474 * Helper for EMFDRV_Poly{line|gon}
477 EMFDRV_Polylinegon( PHYSDEV dev
, const POINT
* pt
, INT count
, DWORD iType
)
479 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
480 DC
*dc
= get_physdev_dc( dev
);
483 BOOL ret
, use_small_emr
= can_use_short_points( pt
, count
);
485 size
= use_small_emr
? offsetof( EMRPOLYLINE16
, apts
[count
] ) : offsetof( EMRPOLYLINE
, aptl
[count
] );
487 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
488 emr
->emr
.iType
= use_small_emr
? iType
+ EMR_POLYLINE16
- EMR_POLYLINE
: iType
;
489 emr
->emr
.nSize
= size
;
492 store_points( emr
->aptl
, pt
, count
, use_small_emr
);
495 get_points_bounds( &emr
->rclBounds
, pt
, count
,
496 (iType
== EMR_POLYBEZIERTO
|| iType
== EMR_POLYLINETO
) ? dc
: 0 );
498 emr
->rclBounds
= empty_bounds
;
500 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
501 if (ret
&& !physDev
->path
)
502 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
503 HeapFree( GetProcessHeap(), 0, emr
);
508 /**********************************************************************
511 BOOL
EMFDRV_Polyline( PHYSDEV dev
, const POINT
* pt
, INT count
)
513 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYLINE
);
516 /**********************************************************************
519 BOOL
EMFDRV_PolylineTo( PHYSDEV dev
, const POINT
* pt
, INT count
)
521 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYLINETO
);
524 /**********************************************************************
527 BOOL
EMFDRV_Polygon( PHYSDEV dev
, const POINT
* pt
, INT count
)
529 if(count
< 2) return FALSE
;
530 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYGON
);
533 /**********************************************************************
536 BOOL
EMFDRV_PolyBezier( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
538 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIER
);
541 /**********************************************************************
542 * EMFDRV_PolyBezierTo
544 BOOL
EMFDRV_PolyBezierTo( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
546 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIERTO
);
550 /**********************************************************************
551 * EMFDRV_PolyPolylinegon
553 * Helper for EMFDRV_PolyPoly{line|gon}
556 EMFDRV_PolyPolylinegon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
,
559 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
560 EMRPOLYPOLYLINE
*emr
;
561 DWORD cptl
= 0, poly
, size
;
562 BOOL ret
, use_small_emr
, bounds_valid
= TRUE
;
564 for(poly
= 0; poly
< polys
; poly
++) {
565 cptl
+= counts
[poly
];
566 if(counts
[poly
] < 2) bounds_valid
= FALSE
;
568 if(!cptl
) bounds_valid
= FALSE
;
569 use_small_emr
= can_use_short_points( pt
, cptl
);
571 size
= FIELD_OFFSET(EMRPOLYPOLYLINE
, aPolyCounts
[polys
]);
573 size
+= cptl
* sizeof(POINTS
);
575 size
+= cptl
* sizeof(POINTL
);
577 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
579 emr
->emr
.iType
= iType
;
580 if(use_small_emr
) emr
->emr
.iType
+= EMR_POLYPOLYLINE16
- EMR_POLYPOLYLINE
;
582 emr
->emr
.nSize
= size
;
583 if(bounds_valid
&& !physDev
->path
)
584 get_points_bounds( &emr
->rclBounds
, pt
, cptl
, 0 );
586 emr
->rclBounds
= empty_bounds
;
592 memcpy( emr
->aPolyCounts
, counts
, polys
* sizeof(DWORD
) );
593 store_points( (POINTL
*)(emr
->aPolyCounts
+ polys
), pt
, cptl
, use_small_emr
);
596 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
597 if(ret
&& !bounds_valid
)
600 SetLastError( ERROR_INVALID_PARAMETER
);
602 if(ret
&& !physDev
->path
)
603 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
604 HeapFree( GetProcessHeap(), 0, emr
);
608 /**********************************************************************
609 * EMFDRV_PolyPolyline
611 BOOL
EMFDRV_PolyPolyline(PHYSDEV dev
, const POINT
* pt
, const DWORD
* counts
, DWORD polys
)
613 return EMFDRV_PolyPolylinegon( dev
, pt
, (const INT
*)counts
, polys
,
617 /**********************************************************************
620 BOOL
EMFDRV_PolyPolygon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
)
622 return EMFDRV_PolyPolylinegon( dev
, pt
, counts
, polys
, EMR_POLYPOLYGON
);
626 /**********************************************************************
629 BOOL
EMFDRV_PolyDraw( PHYSDEV dev
, const POINT
*pts
, const BYTE
*types
, DWORD count
)
631 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
635 BOOL use_small_emr
= can_use_short_points( pts
, count
);
638 size
= use_small_emr
? offsetof( EMRPOLYDRAW16
, apts
[count
] ) : offsetof( EMRPOLYDRAW
, aptl
[count
] );
639 size
+= (count
+ 3) & ~3;
641 if (!(emr
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
643 emr
->emr
.iType
= use_small_emr
? EMR_POLYDRAW16
: EMR_POLYDRAW
;
644 emr
->emr
.nSize
= size
;
647 types_dest
= store_points( emr
->aptl
, pts
, count
, use_small_emr
);
648 memcpy( types_dest
, types
, count
);
649 if (count
& 3) memset( types_dest
+ count
, 0, 4 - (count
& 3) );
652 get_points_bounds( &emr
->rclBounds
, pts
, count
, 0 );
654 emr
->rclBounds
= empty_bounds
;
656 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
657 if (ret
&& !physDev
->path
) EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
658 HeapFree( GetProcessHeap(), 0, emr
);
663 /**********************************************************************
664 * EMFDRV_ExtFloodFill
666 BOOL
EMFDRV_ExtFloodFill( PHYSDEV dev
, INT x
, INT y
, COLORREF color
, UINT fillType
)
670 emr
.emr
.iType
= EMR_EXTFLOODFILL
;
671 emr
.emr
.nSize
= sizeof(emr
);
675 emr
.iMode
= fillType
;
677 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
681 /*********************************************************************
684 BOOL
EMFDRV_FillRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
)
687 DWORD size
, rgnsize
, index
;
690 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
691 if(!index
) return FALSE
;
693 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
694 size
= rgnsize
+ offsetof(EMRFILLRGN
,RgnData
);
695 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
697 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
699 emr
->emr
.iType
= EMR_FILLRGN
;
700 emr
->emr
.nSize
= size
;
701 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
702 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
703 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
704 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
705 emr
->cbRgnData
= rgnsize
;
706 emr
->ihBrush
= index
;
708 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
710 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
711 HeapFree( GetProcessHeap(), 0, emr
);
714 /*********************************************************************
717 BOOL
EMFDRV_FrameRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
, INT width
, INT height
)
720 DWORD size
, rgnsize
, index
;
723 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
724 if(!index
) return FALSE
;
726 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
727 size
= rgnsize
+ offsetof(EMRFRAMERGN
,RgnData
);
728 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
730 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
732 emr
->emr
.iType
= EMR_FRAMERGN
;
733 emr
->emr
.nSize
= size
;
734 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
735 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
736 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
737 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
738 emr
->cbRgnData
= rgnsize
;
739 emr
->ihBrush
= index
;
740 emr
->szlStroke
.cx
= width
;
741 emr
->szlStroke
.cy
= height
;
743 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
745 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
746 HeapFree( GetProcessHeap(), 0, emr
);
750 /*********************************************************************
751 * EMFDRV_PaintInvertRgn
753 * Helper for EMFDRV_{Paint|Invert}Rgn
755 static BOOL
EMFDRV_PaintInvertRgn( PHYSDEV dev
, HRGN hrgn
, DWORD iType
)
762 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
763 size
= rgnsize
+ offsetof(EMRINVERTRGN
,RgnData
);
764 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
766 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
768 emr
->emr
.iType
= iType
;
769 emr
->emr
.nSize
= size
;
770 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
771 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
772 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
773 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
774 emr
->cbRgnData
= rgnsize
;
776 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
778 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
779 HeapFree( GetProcessHeap(), 0, emr
);
783 /**********************************************************************
786 BOOL
EMFDRV_PaintRgn( PHYSDEV dev
, HRGN hrgn
)
788 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_PAINTRGN
);
791 /**********************************************************************
794 BOOL
EMFDRV_InvertRgn( PHYSDEV dev
, HRGN hrgn
)
796 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_INVERTRGN
);
799 /**********************************************************************
802 BOOL
EMFDRV_ExtTextOut( PHYSDEV dev
, INT x
, INT y
, UINT flags
, const RECT
*lprect
,
803 LPCWSTR str
, UINT count
, const INT
*lpDx
)
805 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
806 DC
*dc
= get_physdev_dc( dev
);
807 EMREXTTEXTOUTW
*pemr
;
812 const UINT textAlign
= dc
->textAlign
;
813 const INT graphicsMode
= dc
->GraphicsMode
;
814 FLOAT exScale
, eyScale
;
816 nSize
= sizeof(*pemr
) + ((count
+1) & ~1) * sizeof(WCHAR
) + count
* sizeof(INT
);
818 TRACE("%s %s count %d nSize = %d\n", debugstr_wn(str
, count
),
819 wine_dbgstr_rect(lprect
), count
, nSize
);
820 pemr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nSize
);
822 if (graphicsMode
== GM_COMPATIBLE
)
824 const INT horzSize
= GetDeviceCaps( dev
->hdc
, HORZSIZE
);
825 const INT horzRes
= GetDeviceCaps( dev
->hdc
, HORZRES
);
826 const INT vertSize
= GetDeviceCaps( dev
->hdc
, VERTSIZE
);
827 const INT vertRes
= GetDeviceCaps( dev
->hdc
, VERTRES
);
828 SIZE wndext
, vportext
;
830 GetViewportExtEx( dev
->hdc
, &vportext
);
831 GetWindowExtEx( dev
->hdc
, &wndext
);
832 exScale
= 100.0 * ((FLOAT
)horzSize
/ (FLOAT
)horzRes
) /
833 ((FLOAT
)wndext
.cx
/ (FLOAT
)vportext
.cx
);
834 eyScale
= 100.0 * ((FLOAT
)vertSize
/ (FLOAT
)vertRes
) /
835 ((FLOAT
)wndext
.cy
/ (FLOAT
)vportext
.cy
);
843 pemr
->emr
.iType
= EMR_EXTTEXTOUTW
;
844 pemr
->emr
.nSize
= nSize
;
845 pemr
->iGraphicsMode
= graphicsMode
;
846 pemr
->exScale
= exScale
;
847 pemr
->eyScale
= eyScale
;
848 pemr
->emrtext
.ptlReference
.x
= x
;
849 pemr
->emrtext
.ptlReference
.y
= y
;
850 pemr
->emrtext
.nChars
= count
;
851 pemr
->emrtext
.offString
= sizeof(*pemr
);
852 memcpy((char*)pemr
+ pemr
->emrtext
.offString
, str
, count
* sizeof(WCHAR
));
853 pemr
->emrtext
.fOptions
= flags
;
855 pemr
->emrtext
.rcl
.left
= pemr
->emrtext
.rcl
.top
= 0;
856 pemr
->emrtext
.rcl
.right
= pemr
->emrtext
.rcl
.bottom
= -1;
858 pemr
->emrtext
.rcl
.left
= lprect
->left
;
859 pemr
->emrtext
.rcl
.top
= lprect
->top
;
860 pemr
->emrtext
.rcl
.right
= lprect
->right
;
861 pemr
->emrtext
.rcl
.bottom
= lprect
->bottom
;
864 pemr
->emrtext
.offDx
= pemr
->emrtext
.offString
+ ((count
+1) & ~1) * sizeof(WCHAR
);
868 memcpy((char*)pemr
+ pemr
->emrtext
.offDx
, lpDx
, count
* sizeof(INT
));
869 for (i
= 0; i
< count
; i
++) {
870 textWidth
+= lpDx
[i
];
872 if (GetTextExtentPoint32W( dev
->hdc
, str
, count
, &strSize
))
873 textHeight
= strSize
.cy
;
877 INT
*dx
= (INT
*)((char*)pemr
+ pemr
->emrtext
.offDx
);
879 for (i
= 0; i
< count
; i
++) {
880 if (GetTextExtentPoint32W( dev
->hdc
, str
+ i
, 1, &charSize
)) {
882 textWidth
+= charSize
.cx
;
883 textHeight
= max(textHeight
, charSize
.cy
);
890 pemr
->rclBounds
.left
= pemr
->rclBounds
.top
= 0;
891 pemr
->rclBounds
.right
= pemr
->rclBounds
.bottom
= -1;
895 /* FIXME: handle font escapement */
896 switch (textAlign
& (TA_LEFT
| TA_RIGHT
| TA_CENTER
)) {
898 pemr
->rclBounds
.left
= x
- (textWidth
/ 2) - 1;
899 pemr
->rclBounds
.right
= x
+ (textWidth
/ 2) + 1;
903 pemr
->rclBounds
.left
= x
- textWidth
- 1;
904 pemr
->rclBounds
.right
= x
;
907 default: { /* TA_LEFT */
908 pemr
->rclBounds
.left
= x
;
909 pemr
->rclBounds
.right
= x
+ textWidth
+ 1;
913 switch (textAlign
& (TA_TOP
| TA_BOTTOM
| TA_BASELINE
)) {
916 if (!GetTextMetricsW( dev
->hdc
, &tm
))
918 /* Play safe here... it's better to have a bounding box */
919 /* that is too big than too small. */
920 pemr
->rclBounds
.top
= y
- textHeight
- 1;
921 pemr
->rclBounds
.bottom
= y
+ tm
.tmDescent
+ 1;
925 pemr
->rclBounds
.top
= y
- textHeight
- 1;
926 pemr
->rclBounds
.bottom
= y
;
929 default: { /* TA_TOP */
930 pemr
->rclBounds
.top
= y
;
931 pemr
->rclBounds
.bottom
= y
+ textHeight
+ 1;
934 EMFDRV_UpdateBBox( dev
, &pemr
->rclBounds
);
937 ret
= EMFDRV_WriteRecord( dev
, &pemr
->emr
);
938 HeapFree( GetProcessHeap(), 0, pemr
);
942 /**********************************************************************
943 * EMFDRV_GradientFill
945 BOOL
EMFDRV_GradientFill( PHYSDEV dev
, TRIVERTEX
*vert_array
, ULONG nvert
,
946 void *grad_array
, ULONG ngrad
, ULONG mode
)
948 EMRGRADIENTFILL
*emr
;
949 ULONG i
, pt
, size
, num_pts
= ngrad
* (mode
== GRADIENT_FILL_TRIANGLE
? 3 : 2);
950 const ULONG
*pts
= (const ULONG
*)grad_array
;
953 size
= FIELD_OFFSET(EMRGRADIENTFILL
, Ver
[nvert
]) + num_pts
* sizeof(pts
[0]);
955 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
956 if (!emr
) return FALSE
;
958 for (i
= 0; i
< num_pts
; i
++)
964 emr
->rclBounds
.left
= emr
->rclBounds
.right
= vert_array
[pt
].x
;
965 emr
->rclBounds
.top
= emr
->rclBounds
.bottom
= vert_array
[pt
].y
;
969 if (vert_array
[pt
].x
< emr
->rclBounds
.left
)
970 emr
->rclBounds
.left
= vert_array
[pt
].x
;
971 else if (vert_array
[pt
].x
> emr
->rclBounds
.right
)
972 emr
->rclBounds
.right
= vert_array
[pt
].x
;
973 if (vert_array
[pt
].y
< emr
->rclBounds
.top
)
974 emr
->rclBounds
.top
= vert_array
[pt
].y
;
975 else if (vert_array
[pt
].y
> emr
->rclBounds
.bottom
)
976 emr
->rclBounds
.bottom
= vert_array
[pt
].y
;
979 emr
->rclBounds
.right
--;
980 emr
->rclBounds
.bottom
--;
982 emr
->emr
.iType
= EMR_GRADIENTFILL
;
983 emr
->emr
.nSize
= size
;
987 memcpy( emr
->Ver
, vert_array
, nvert
* sizeof(vert_array
[0]) );
988 memcpy( emr
->Ver
+ nvert
, pts
, num_pts
* sizeof(pts
[0]) );
990 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
991 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
992 HeapFree( GetProcessHeap(), 0, emr
);
996 /**********************************************************************
999 BOOL
EMFDRV_FillPath( PHYSDEV dev
)
1001 return emfdrv_stroke_and_fill_path( dev
, EMR_FILLPATH
);
1004 /**********************************************************************
1005 * EMFDRV_StrokeAndFillPath
1007 BOOL
EMFDRV_StrokeAndFillPath( PHYSDEV dev
)
1009 return emfdrv_stroke_and_fill_path( dev
, EMR_STROKEANDFILLPATH
);
1012 /**********************************************************************
1015 BOOL
EMFDRV_StrokePath( PHYSDEV dev
)
1017 return emfdrv_stroke_and_fill_path( dev
, EMR_STROKEPATH
);