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 */
73 static void get_points_bounds( RECTL
*bounds
, const POINT
*pts
, UINT count
, HDC hdc
)
75 static void get_points_bounds( RECTL
*bounds
, const POINT
*pts
, UINT count
, DC
*dc
)
83 GetCurrentPositionEx( hdc
, &cur_pt
);
84 bounds
->left
= bounds
->right
= cur_pt
.x
;
85 bounds
->top
= bounds
->bottom
= cur_pt
.y
;
90 bounds
->left
= bounds
->right
= dc
->cur_pos
.x
;
91 bounds
->top
= bounds
->bottom
= dc
->cur_pos
.y
;
96 bounds
->left
= bounds
->right
= pts
[0].x
;
97 bounds
->top
= bounds
->bottom
= pts
[0].y
;
99 else *bounds
= empty_bounds
;
101 for (i
= 0; i
< count
; i
++)
103 bounds
->left
= min( bounds
->left
, pts
[i
].x
);
104 bounds
->right
= max( bounds
->right
, pts
[i
].x
);
105 bounds
->top
= min( bounds
->top
, pts
[i
].y
);
106 bounds
->bottom
= max( bounds
->bottom
, pts
[i
].y
);
110 /* helper for path stroke and fill functions */
112 static BOOL
emfdrv_stroke_and_fill_path( PHYSDEV dev
, INT type
)
114 EMRSTROKEANDFILLPATH emr
;
119 emr
.emr
.iType
= type
;
120 emr
.emr
.nSize
= sizeof(emr
);
122 nSize
= GetPath(dev
->hdc
, NULL
, NULL
, 0);
125 Points
= HeapAlloc( GetProcessHeap(), 0, nSize
*sizeof(POINT
) );
126 Types
= HeapAlloc( GetProcessHeap(), 0, nSize
*sizeof(BYTE
) );
128 GetPath(dev
->hdc
, Points
, Types
, nSize
);
129 get_points_bounds( &emr
.rclBounds
, Points
, nSize
, 0 );
131 HeapFree( GetProcessHeap(), 0, Points
);
132 HeapFree( GetProcessHeap(), 0, Types
);
134 TRACE("GetBounds l %d t %d r %d b %d\n",emr
.rclBounds
.left
, emr
.rclBounds
.top
, emr
.rclBounds
.right
, emr
.rclBounds
.bottom
);
136 else emr
.rclBounds
= empty_bounds
;
138 if (!EMFDRV_WriteRecord( dev
, &emr
.emr
)) return FALSE
;
139 if (nSize
== -1 ) return FALSE
;
140 EMFDRV_UpdateBBox( dev
, &emr
.rclBounds
);
144 static BOOL
emfdrv_stroke_and_fill_path( PHYSDEV dev
, INT type
)
146 DC
*dc
= get_physdev_dc( dev
);
147 EMRSTROKEANDFILLPATH emr
;
148 struct gdi_path
*path
;
152 emr
.emr
.iType
= type
;
153 emr
.emr
.nSize
= sizeof(emr
);
155 if ((path
= get_gdi_flat_path( dc
, NULL
)))
157 int count
= get_gdi_path_data( path
, &points
, &flags
);
158 get_points_bounds( &emr
.rclBounds
, points
, count
, 0 );
159 free_gdi_path( path
);
161 else emr
.rclBounds
= empty_bounds
;
163 if (!EMFDRV_WriteRecord( dev
, &emr
.emr
)) return FALSE
;
164 if (!path
) return FALSE
;
165 EMFDRV_UpdateBBox( dev
, &emr
.rclBounds
);
170 /**********************************************************************
173 BOOL
EMFDRV_MoveTo(PHYSDEV dev
, INT x
, INT y
)
177 emr
.emr
.iType
= EMR_MOVETOEX
;
178 emr
.emr
.nSize
= sizeof(emr
);
182 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
185 /***********************************************************************
188 BOOL
EMFDRV_LineTo( PHYSDEV dev
, INT x
, INT y
)
190 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
192 DC
*dc
= get_physdev_dc( dev
);
198 emr
.emr
.iType
= EMR_LINETO
;
199 emr
.emr
.nSize
= sizeof(emr
);
203 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
206 GetCurrentPositionEx( dev
->hdc
, &pt
);
210 bounds
.left
= min(x
, pt
.x
);
211 bounds
.top
= min(y
, pt
.y
);
212 bounds
.right
= max(x
, pt
.x
);
213 bounds
.bottom
= max(y
, pt
.y
);
216 EMFDRV_UpdateBBox( dev
, &bounds
);
222 /***********************************************************************
226 EMFDRV_ArcChordPie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
227 INT xstart
, INT ystart
, INT xend
, INT yend
, DWORD iType
)
229 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
231 DC
*dc
= get_physdev_dc( dev
);
233 INT temp
, xCentre
, yCentre
, i
;
234 double angleStart
, angleEnd
;
235 double xinterStart
, yinterStart
, xinterEnd
, yinterEnd
;
239 if(left
== right
|| top
== bottom
) return FALSE
;
241 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
242 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
244 if(GetGraphicsMode(dev
->hdc
) == GM_COMPATIBLE
) {
246 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
252 emr
.emr
.iType
= iType
;
253 emr
.emr
.nSize
= sizeof(emr
);
254 emr
.rclBox
.left
= left
;
255 emr
.rclBox
.top
= top
;
256 emr
.rclBox
.right
= right
;
257 emr
.rclBox
.bottom
= bottom
;
258 emr
.ptlStart
.x
= xstart
;
259 emr
.ptlStart
.y
= ystart
;
264 /* Now calculate the BBox */
265 xCentre
= (left
+ right
+ 1) / 2;
266 yCentre
= (top
+ bottom
+ 1) / 2;
273 /* invert y co-ords to get angle anti-clockwise from x-axis */
274 angleStart
= atan2( -(double)ystart
, (double)xstart
);
275 angleEnd
= atan2( -(double)yend
, (double)xend
);
277 /* These are the intercepts of the start/end lines with the arc */
279 xinterStart
= (right
- left
+ 1)/2 * cos(angleStart
) + xCentre
;
280 yinterStart
= -(bottom
- top
+ 1)/2 * sin(angleStart
) + yCentre
;
281 xinterEnd
= (right
- left
+ 1)/2 * cos(angleEnd
) + xCentre
;
282 yinterEnd
= -(bottom
- top
+ 1)/2 * sin(angleEnd
) + yCentre
;
284 if(angleStart
< 0) angleStart
+= 2 * M_PI
;
285 if(angleEnd
< 0) angleEnd
+= 2 * M_PI
;
286 if(angleEnd
< angleStart
) angleEnd
+= 2 * M_PI
;
288 bounds
.left
= min(xinterStart
, xinterEnd
);
289 bounds
.top
= min(yinterStart
, yinterEnd
);
290 bounds
.right
= max(xinterStart
, xinterEnd
);
291 bounds
.bottom
= max(yinterStart
, yinterEnd
);
293 for(i
= 0; i
<= 8; i
++) {
294 if(i
* M_PI
/ 2 < angleStart
) /* loop until we're past start */
296 if(i
* M_PI
/ 2 > angleEnd
) /* if we're past end we're finished */
299 /* the arc touches the rectangle at the start of quadrant i, so adjust
300 BBox to reflect this. */
304 bounds
.right
= right
;
313 bounds
.bottom
= bottom
;
318 /* If we're drawing a pie then make sure we include the centre */
319 if(iType
== EMR_PIE
) {
320 if(bounds
.left
> xCentre
) bounds
.left
= xCentre
;
321 else if(bounds
.right
< xCentre
) bounds
.right
= xCentre
;
322 if(bounds
.top
> yCentre
) bounds
.top
= yCentre
;
323 else if(bounds
.bottom
< yCentre
) bounds
.bottom
= yCentre
;
325 if (iType
== EMR_ARCTO
)
329 GetCurrentPositionEx( dev
->hdc
, &pt
);
333 bounds
.left
= min( bounds
.left
, pt
.x
);
334 bounds
.top
= min( bounds
.top
, pt
.y
);
335 bounds
.right
= max( bounds
.right
, pt
.x
);
336 bounds
.bottom
= max( bounds
.bottom
, pt
.y
);
338 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
341 EMFDRV_UpdateBBox( dev
, &bounds
);
346 /***********************************************************************
349 BOOL
EMFDRV_Arc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
350 INT xstart
, INT ystart
, INT xend
, INT yend
)
352 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
353 xend
, yend
, EMR_ARC
);
356 /***********************************************************************
359 BOOL
EMFDRV_ArcTo( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
360 INT xstart
, INT ystart
, INT xend
, INT yend
)
362 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
363 xend
, yend
, EMR_ARCTO
);
366 /***********************************************************************
369 BOOL
EMFDRV_Pie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
370 INT xstart
, INT ystart
, INT xend
, INT yend
)
372 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
373 xend
, yend
, EMR_PIE
);
377 /***********************************************************************
380 BOOL
EMFDRV_Chord( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
381 INT xstart
, INT ystart
, INT xend
, INT yend
)
383 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
384 xend
, yend
, EMR_CHORD
);
387 /***********************************************************************
390 BOOL
EMFDRV_AngleArc( PHYSDEV dev
, INT x
, INT y
, DWORD radius
, FLOAT start
, FLOAT sweep
)
394 emr
.emr
.iType
= EMR_ANGLEARC
;
395 emr
.emr
.nSize
= sizeof( emr
);
398 emr
.nRadius
= radius
;
399 emr
.eStartAngle
= start
;
400 emr
.eSweepAngle
= sweep
;
402 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
405 /***********************************************************************
408 BOOL
EMFDRV_Ellipse( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
410 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
412 DC
*dc
= get_physdev_dc( dev
);
417 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
419 if(left
== right
|| top
== bottom
) return FALSE
;
421 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
422 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
424 if(GetGraphicsMode(dev
->hdc
) == GM_COMPATIBLE
) {
426 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
432 emr
.emr
.iType
= EMR_ELLIPSE
;
433 emr
.emr
.nSize
= sizeof(emr
);
434 emr
.rclBox
.left
= left
;
435 emr
.rclBox
.top
= top
;
436 emr
.rclBox
.right
= right
;
437 emr
.rclBox
.bottom
= bottom
;
440 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
441 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
444 /***********************************************************************
447 BOOL
EMFDRV_Rectangle(PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
449 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
451 DC
*dc
= get_physdev_dc( dev
);
456 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
458 if(left
== right
|| top
== bottom
) return FALSE
;
460 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
461 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
463 if(GetGraphicsMode(dev
->hdc
) == GM_COMPATIBLE
) {
465 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
471 emr
.emr
.iType
= EMR_RECTANGLE
;
472 emr
.emr
.nSize
= sizeof(emr
);
473 emr
.rclBox
.left
= left
;
474 emr
.rclBox
.top
= top
;
475 emr
.rclBox
.right
= right
;
476 emr
.rclBox
.bottom
= bottom
;
479 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
480 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
483 /***********************************************************************
486 BOOL
EMFDRV_RoundRect( PHYSDEV dev
, INT left
, INT top
, INT right
,
487 INT bottom
, INT ell_width
, INT ell_height
)
489 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
491 DC
*dc
= get_physdev_dc( dev
);
496 if(left
== right
|| top
== bottom
) return FALSE
;
498 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
499 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
501 if(GetGraphicsMode(dev
->hdc
) == GM_COMPATIBLE
) {
503 if(dc
->GraphicsMode
== GM_COMPATIBLE
) {
509 emr
.emr
.iType
= EMR_ROUNDRECT
;
510 emr
.emr
.nSize
= sizeof(emr
);
511 emr
.rclBox
.left
= left
;
512 emr
.rclBox
.top
= top
;
513 emr
.rclBox
.right
= right
;
514 emr
.rclBox
.bottom
= bottom
;
515 emr
.szlCorner
.cx
= ell_width
;
516 emr
.szlCorner
.cy
= ell_height
;
519 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
520 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
523 /***********************************************************************
526 COLORREF
EMFDRV_SetPixel( PHYSDEV dev
, INT x
, INT y
, COLORREF color
)
530 emr
.emr
.iType
= EMR_SETPIXELV
;
531 emr
.emr
.nSize
= sizeof(emr
);
536 if (EMFDRV_WriteRecord( dev
, &emr
.emr
)) {
538 bounds
.left
= bounds
.right
= x
;
539 bounds
.top
= bounds
.bottom
= y
;
540 EMFDRV_UpdateBBox( dev
, &bounds
);
546 /**********************************************************************
549 * Helper for EMFDRV_Poly{line|gon}
552 EMFDRV_Polylinegon( PHYSDEV dev
, const POINT
* pt
, INT count
, DWORD iType
)
554 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
556 DC
*dc
= get_physdev_dc( dev
);
560 BOOL ret
, use_small_emr
= can_use_short_points( pt
, count
);
562 size
= use_small_emr
? offsetof( EMRPOLYLINE16
, apts
[count
] ) : offsetof( EMRPOLYLINE
, aptl
[count
] );
564 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
565 emr
->emr
.iType
= use_small_emr
? iType
+ EMR_POLYLINE16
- EMR_POLYLINE
: iType
;
566 emr
->emr
.nSize
= size
;
569 store_points( emr
->aptl
, pt
, count
, use_small_emr
);
572 get_points_bounds( &emr
->rclBounds
, pt
, count
,
574 (iType
== EMR_POLYBEZIERTO
|| iType
== EMR_POLYLINETO
) ? dev
->hdc
: 0 );
576 (iType
== EMR_POLYBEZIERTO
|| iType
== EMR_POLYLINETO
) ? dc
: 0 );
579 emr
->rclBounds
= empty_bounds
;
581 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
582 if (ret
&& !physDev
->path
)
583 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
584 HeapFree( GetProcessHeap(), 0, emr
);
589 /**********************************************************************
592 BOOL
EMFDRV_Polyline( PHYSDEV dev
, const POINT
* pt
, INT count
)
594 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYLINE
);
597 /**********************************************************************
600 BOOL
EMFDRV_PolylineTo( PHYSDEV dev
, const POINT
* pt
, INT count
)
602 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYLINETO
);
605 /**********************************************************************
608 BOOL
EMFDRV_Polygon( PHYSDEV dev
, const POINT
* pt
, INT count
)
610 if(count
< 2) return FALSE
;
611 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYGON
);
614 /**********************************************************************
617 BOOL
EMFDRV_PolyBezier( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
619 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIER
);
622 /**********************************************************************
623 * EMFDRV_PolyBezierTo
625 BOOL
EMFDRV_PolyBezierTo( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
627 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIERTO
);
631 /**********************************************************************
632 * EMFDRV_PolyPolylinegon
634 * Helper for EMFDRV_PolyPoly{line|gon}
637 EMFDRV_PolyPolylinegon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
,
640 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
641 EMRPOLYPOLYLINE
*emr
;
642 DWORD cptl
= 0, poly
, size
;
643 BOOL ret
, use_small_emr
, bounds_valid
= TRUE
;
645 for(poly
= 0; poly
< polys
; poly
++) {
646 cptl
+= counts
[poly
];
647 if(counts
[poly
] < 2) bounds_valid
= FALSE
;
649 if(!cptl
) bounds_valid
= FALSE
;
650 use_small_emr
= can_use_short_points( pt
, cptl
);
652 size
= FIELD_OFFSET(EMRPOLYPOLYLINE
, aPolyCounts
[polys
]);
654 size
+= cptl
* sizeof(POINTS
);
656 size
+= cptl
* sizeof(POINTL
);
658 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
660 emr
->emr
.iType
= iType
;
661 if(use_small_emr
) emr
->emr
.iType
+= EMR_POLYPOLYLINE16
- EMR_POLYPOLYLINE
;
663 emr
->emr
.nSize
= size
;
664 if(bounds_valid
&& !physDev
->path
)
665 get_points_bounds( &emr
->rclBounds
, pt
, cptl
, 0 );
667 emr
->rclBounds
= empty_bounds
;
673 memcpy( emr
->aPolyCounts
, counts
, polys
* sizeof(DWORD
) );
674 store_points( (POINTL
*)(emr
->aPolyCounts
+ polys
), pt
, cptl
, use_small_emr
);
677 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
678 if(ret
&& !bounds_valid
)
681 SetLastError( ERROR_INVALID_PARAMETER
);
683 if(ret
&& !physDev
->path
)
684 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
685 HeapFree( GetProcessHeap(), 0, emr
);
689 /**********************************************************************
690 * EMFDRV_PolyPolyline
692 BOOL
EMFDRV_PolyPolyline(PHYSDEV dev
, const POINT
* pt
, const DWORD
* counts
, DWORD polys
)
694 return EMFDRV_PolyPolylinegon( dev
, pt
, (const INT
*)counts
, polys
,
698 /**********************************************************************
701 BOOL
EMFDRV_PolyPolygon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
)
703 return EMFDRV_PolyPolylinegon( dev
, pt
, counts
, polys
, EMR_POLYPOLYGON
);
707 /**********************************************************************
710 BOOL
EMFDRV_PolyDraw( PHYSDEV dev
, const POINT
*pts
, const BYTE
*types
, DWORD count
)
712 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
716 BOOL use_small_emr
= can_use_short_points( pts
, count
);
719 size
= use_small_emr
? offsetof( EMRPOLYDRAW16
, apts
[count
] ) : offsetof( EMRPOLYDRAW
, aptl
[count
] );
720 size
+= (count
+ 3) & ~3;
722 if (!(emr
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
724 emr
->emr
.iType
= use_small_emr
? EMR_POLYDRAW16
: EMR_POLYDRAW
;
725 emr
->emr
.nSize
= size
;
728 types_dest
= store_points( emr
->aptl
, pts
, count
, use_small_emr
);
729 memcpy( types_dest
, types
, count
);
730 if (count
& 3) memset( types_dest
+ count
, 0, 4 - (count
& 3) );
733 get_points_bounds( &emr
->rclBounds
, pts
, count
, 0 );
735 emr
->rclBounds
= empty_bounds
;
737 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
738 if (ret
&& !physDev
->path
) EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
739 HeapFree( GetProcessHeap(), 0, emr
);
744 /**********************************************************************
745 * EMFDRV_ExtFloodFill
747 BOOL
EMFDRV_ExtFloodFill( PHYSDEV dev
, INT x
, INT y
, COLORREF color
, UINT fillType
)
751 emr
.emr
.iType
= EMR_EXTFLOODFILL
;
752 emr
.emr
.nSize
= sizeof(emr
);
756 emr
.iMode
= fillType
;
758 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
762 /*********************************************************************
765 BOOL
EMFDRV_FillRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
)
768 DWORD size
, rgnsize
, index
;
771 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
772 if(!index
) return FALSE
;
774 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
775 size
= rgnsize
+ offsetof(EMRFILLRGN
,RgnData
);
776 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
778 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
780 emr
->emr
.iType
= EMR_FILLRGN
;
781 emr
->emr
.nSize
= size
;
782 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
783 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
784 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
785 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
786 emr
->cbRgnData
= rgnsize
;
787 emr
->ihBrush
= index
;
789 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
791 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
792 HeapFree( GetProcessHeap(), 0, emr
);
795 /*********************************************************************
798 BOOL
EMFDRV_FrameRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
, INT width
, INT height
)
801 DWORD size
, rgnsize
, index
;
804 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
805 if(!index
) return FALSE
;
807 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
808 size
= rgnsize
+ offsetof(EMRFRAMERGN
,RgnData
);
809 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
811 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
813 emr
->emr
.iType
= EMR_FRAMERGN
;
814 emr
->emr
.nSize
= size
;
815 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
816 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
817 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
818 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
819 emr
->cbRgnData
= rgnsize
;
820 emr
->ihBrush
= index
;
821 emr
->szlStroke
.cx
= width
;
822 emr
->szlStroke
.cy
= height
;
824 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
826 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
827 HeapFree( GetProcessHeap(), 0, emr
);
831 /*********************************************************************
832 * EMFDRV_PaintInvertRgn
834 * Helper for EMFDRV_{Paint|Invert}Rgn
836 static BOOL
EMFDRV_PaintInvertRgn( PHYSDEV dev
, HRGN hrgn
, DWORD iType
)
843 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
844 size
= rgnsize
+ offsetof(EMRINVERTRGN
,RgnData
);
845 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
847 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
849 emr
->emr
.iType
= iType
;
850 emr
->emr
.nSize
= size
;
851 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
852 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
853 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
854 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
855 emr
->cbRgnData
= rgnsize
;
857 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
859 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
860 HeapFree( GetProcessHeap(), 0, emr
);
864 /**********************************************************************
867 BOOL
EMFDRV_PaintRgn( PHYSDEV dev
, HRGN hrgn
)
869 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_PAINTRGN
);
872 /**********************************************************************
875 BOOL
EMFDRV_InvertRgn( PHYSDEV dev
, HRGN hrgn
)
877 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_INVERTRGN
);
880 /**********************************************************************
883 BOOL
EMFDRV_ExtTextOut( PHYSDEV dev
, INT x
, INT y
, UINT flags
, const RECT
*lprect
,
884 LPCWSTR str
, UINT count
, const INT
*lpDx
)
886 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
888 DC
*dc
= get_physdev_dc( dev
);
890 EMREXTTEXTOUTW
*pemr
;
896 const UINT textAlign
= GetTextAlign( dev
->hdc
);
897 const INT graphicsMode
= GetGraphicsMode( dev
->hdc
);
899 const UINT textAlign
= dc
->textAlign
;
900 const INT graphicsMode
= dc
->GraphicsMode
;
902 FLOAT exScale
, eyScale
;
904 nSize
= sizeof(*pemr
) + ((count
+1) & ~1) * sizeof(WCHAR
) + count
* sizeof(INT
);
906 TRACE("%s %s count %d nSize = %d\n", debugstr_wn(str
, count
),
907 wine_dbgstr_rect(lprect
), count
, nSize
);
908 pemr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nSize
);
910 if (graphicsMode
== GM_COMPATIBLE
)
912 const INT horzSize
= GetDeviceCaps( dev
->hdc
, HORZSIZE
);
913 const INT horzRes
= GetDeviceCaps( dev
->hdc
, HORZRES
);
914 const INT vertSize
= GetDeviceCaps( dev
->hdc
, VERTSIZE
);
915 const INT vertRes
= GetDeviceCaps( dev
->hdc
, VERTRES
);
916 SIZE wndext
, vportext
;
918 GetViewportExtEx( dev
->hdc
, &vportext
);
919 GetWindowExtEx( dev
->hdc
, &wndext
);
920 exScale
= 100.0 * ((FLOAT
)horzSize
/ (FLOAT
)horzRes
) /
921 ((FLOAT
)wndext
.cx
/ (FLOAT
)vportext
.cx
);
922 eyScale
= 100.0 * ((FLOAT
)vertSize
/ (FLOAT
)vertRes
) /
923 ((FLOAT
)wndext
.cy
/ (FLOAT
)vportext
.cy
);
931 pemr
->emr
.iType
= EMR_EXTTEXTOUTW
;
932 pemr
->emr
.nSize
= nSize
;
933 pemr
->iGraphicsMode
= graphicsMode
;
934 pemr
->exScale
= exScale
;
935 pemr
->eyScale
= eyScale
;
936 pemr
->emrtext
.ptlReference
.x
= x
;
937 pemr
->emrtext
.ptlReference
.y
= y
;
938 pemr
->emrtext
.nChars
= count
;
939 pemr
->emrtext
.offString
= sizeof(*pemr
);
940 memcpy((char*)pemr
+ pemr
->emrtext
.offString
, str
, count
* sizeof(WCHAR
));
941 pemr
->emrtext
.fOptions
= flags
;
943 pemr
->emrtext
.rcl
.left
= pemr
->emrtext
.rcl
.top
= 0;
944 pemr
->emrtext
.rcl
.right
= pemr
->emrtext
.rcl
.bottom
= -1;
946 pemr
->emrtext
.rcl
.left
= lprect
->left
;
947 pemr
->emrtext
.rcl
.top
= lprect
->top
;
948 pemr
->emrtext
.rcl
.right
= lprect
->right
;
949 pemr
->emrtext
.rcl
.bottom
= lprect
->bottom
;
952 pemr
->emrtext
.offDx
= pemr
->emrtext
.offString
+ ((count
+1) & ~1) * sizeof(WCHAR
);
956 memcpy((char*)pemr
+ pemr
->emrtext
.offDx
, lpDx
, count
* sizeof(INT
));
957 for (i
= 0; i
< count
; i
++) {
958 textWidth
+= lpDx
[i
];
960 if (GetTextExtentPoint32W( dev
->hdc
, str
, count
, &strSize
))
961 textHeight
= strSize
.cy
;
965 INT
*dx
= (INT
*)((char*)pemr
+ pemr
->emrtext
.offDx
);
967 for (i
= 0; i
< count
; i
++) {
968 if (GetTextExtentPoint32W( dev
->hdc
, str
+ i
, 1, &charSize
)) {
970 textWidth
+= charSize
.cx
;
971 textHeight
= max(textHeight
, charSize
.cy
);
978 pemr
->rclBounds
.left
= pemr
->rclBounds
.top
= 0;
979 pemr
->rclBounds
.right
= pemr
->rclBounds
.bottom
= -1;
983 /* FIXME: handle font escapement */
984 switch (textAlign
& (TA_LEFT
| TA_RIGHT
| TA_CENTER
)) {
986 pemr
->rclBounds
.left
= x
- (textWidth
/ 2) - 1;
987 pemr
->rclBounds
.right
= x
+ (textWidth
/ 2) + 1;
991 pemr
->rclBounds
.left
= x
- textWidth
- 1;
992 pemr
->rclBounds
.right
= x
;
995 default: { /* TA_LEFT */
996 pemr
->rclBounds
.left
= x
;
997 pemr
->rclBounds
.right
= x
+ textWidth
+ 1;
1001 switch (textAlign
& (TA_TOP
| TA_BOTTOM
| TA_BASELINE
)) {
1004 if (!GetTextMetricsW( dev
->hdc
, &tm
))
1006 /* Play safe here... it's better to have a bounding box */
1007 /* that is too big than too small. */
1008 pemr
->rclBounds
.top
= y
- textHeight
- 1;
1009 pemr
->rclBounds
.bottom
= y
+ tm
.tmDescent
+ 1;
1013 pemr
->rclBounds
.top
= y
- textHeight
- 1;
1014 pemr
->rclBounds
.bottom
= y
;
1017 default: { /* TA_TOP */
1018 pemr
->rclBounds
.top
= y
;
1019 pemr
->rclBounds
.bottom
= y
+ textHeight
+ 1;
1022 EMFDRV_UpdateBBox( dev
, &pemr
->rclBounds
);
1025 ret
= EMFDRV_WriteRecord( dev
, &pemr
->emr
);
1026 HeapFree( GetProcessHeap(), 0, pemr
);
1030 /**********************************************************************
1031 * EMFDRV_GradientFill
1033 BOOL
EMFDRV_GradientFill( PHYSDEV dev
, TRIVERTEX
*vert_array
, ULONG nvert
,
1034 void *grad_array
, ULONG ngrad
, ULONG mode
)
1036 EMRGRADIENTFILL
*emr
;
1037 ULONG i
, pt
, size
, num_pts
= ngrad
* (mode
== GRADIENT_FILL_TRIANGLE
? 3 : 2);
1038 const ULONG
*pts
= (const ULONG
*)grad_array
;
1041 size
= FIELD_OFFSET(EMRGRADIENTFILL
, Ver
[nvert
]) + num_pts
* sizeof(pts
[0]);
1043 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
1044 if (!emr
) return FALSE
;
1046 for (i
= 0; i
< num_pts
; i
++)
1052 emr
->rclBounds
.left
= emr
->rclBounds
.right
= vert_array
[pt
].x
;
1053 emr
->rclBounds
.top
= emr
->rclBounds
.bottom
= vert_array
[pt
].y
;
1057 if (vert_array
[pt
].x
< emr
->rclBounds
.left
)
1058 emr
->rclBounds
.left
= vert_array
[pt
].x
;
1059 else if (vert_array
[pt
].x
> emr
->rclBounds
.right
)
1060 emr
->rclBounds
.right
= vert_array
[pt
].x
;
1061 if (vert_array
[pt
].y
< emr
->rclBounds
.top
)
1062 emr
->rclBounds
.top
= vert_array
[pt
].y
;
1063 else if (vert_array
[pt
].y
> emr
->rclBounds
.bottom
)
1064 emr
->rclBounds
.bottom
= vert_array
[pt
].y
;
1067 emr
->rclBounds
.right
--;
1068 emr
->rclBounds
.bottom
--;
1070 emr
->emr
.iType
= EMR_GRADIENTFILL
;
1071 emr
->emr
.nSize
= size
;
1075 memcpy( emr
->Ver
, vert_array
, nvert
* sizeof(vert_array
[0]) );
1076 memcpy( emr
->Ver
+ nvert
, pts
, num_pts
* sizeof(pts
[0]) );
1078 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
1079 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
1080 HeapFree( GetProcessHeap(), 0, emr
);
1084 /**********************************************************************
1087 BOOL
EMFDRV_FillPath( PHYSDEV dev
)
1089 return emfdrv_stroke_and_fill_path( dev
, EMR_FILLPATH
);
1092 /**********************************************************************
1093 * EMFDRV_StrokeAndFillPath
1095 BOOL
EMFDRV_StrokeAndFillPath( PHYSDEV dev
)
1097 return emfdrv_stroke_and_fill_path( dev
, EMR_STROKEANDFILLPATH
);
1100 /**********************************************************************
1103 BOOL
EMFDRV_StrokePath( PHYSDEV dev
)
1105 return emfdrv_stroke_and_fill_path( dev
, EMR_STROKEPATH
);