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 /**********************************************************************
39 BOOL
EMFDRV_MoveTo(PHYSDEV dev
, INT x
, INT y
)
43 emr
.emr
.iType
= EMR_MOVETOEX
;
44 emr
.emr
.nSize
= sizeof(emr
);
48 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
51 /***********************************************************************
54 BOOL
EMFDRV_LineTo( PHYSDEV dev
, INT x
, INT y
)
60 emr
.emr
.iType
= EMR_LINETO
;
61 emr
.emr
.nSize
= sizeof(emr
);
65 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
68 GetCurrentPositionEx( dev
->hdc
, &pt
);
70 bounds
.left
= min(x
, pt
.x
);
71 bounds
.top
= min(y
, pt
.y
);
72 bounds
.right
= max(x
, pt
.x
);
73 bounds
.bottom
= max(y
, pt
.y
);
75 EMFDRV_UpdateBBox( dev
, &bounds
);
81 /***********************************************************************
85 EMFDRV_ArcChordPie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
86 INT xstart
, INT ystart
, INT xend
, INT yend
, DWORD iType
)
88 INT temp
, xCentre
, yCentre
, i
;
89 double angleStart
, angleEnd
;
90 double xinterStart
, yinterStart
, xinterEnd
, yinterEnd
;
94 if(left
== right
|| top
== bottom
) return FALSE
;
96 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
97 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
99 if(GetGraphicsMode(dev
->hdc
) == GM_COMPATIBLE
) {
104 emr
.emr
.iType
= iType
;
105 emr
.emr
.nSize
= sizeof(emr
);
106 emr
.rclBox
.left
= left
;
107 emr
.rclBox
.top
= top
;
108 emr
.rclBox
.right
= right
;
109 emr
.rclBox
.bottom
= bottom
;
110 emr
.ptlStart
.x
= xstart
;
111 emr
.ptlStart
.y
= ystart
;
116 /* Now calculate the BBox */
117 xCentre
= (left
+ right
+ 1) / 2;
118 yCentre
= (top
+ bottom
+ 1) / 2;
125 /* invert y co-ords to get angle anti-clockwise from x-axis */
126 angleStart
= atan2( -(double)ystart
, (double)xstart
);
127 angleEnd
= atan2( -(double)yend
, (double)xend
);
129 /* These are the intercepts of the start/end lines with the arc */
131 xinterStart
= (right
- left
+ 1)/2 * cos(angleStart
) + xCentre
;
132 yinterStart
= -(bottom
- top
+ 1)/2 * sin(angleStart
) + yCentre
;
133 xinterEnd
= (right
- left
+ 1)/2 * cos(angleEnd
) + xCentre
;
134 yinterEnd
= -(bottom
- top
+ 1)/2 * sin(angleEnd
) + yCentre
;
136 if(angleStart
< 0) angleStart
+= 2 * M_PI
;
137 if(angleEnd
< 0) angleEnd
+= 2 * M_PI
;
138 if(angleEnd
< angleStart
) angleEnd
+= 2 * M_PI
;
140 bounds
.left
= min(xinterStart
, xinterEnd
);
141 bounds
.top
= min(yinterStart
, yinterEnd
);
142 bounds
.right
= max(xinterStart
, xinterEnd
);
143 bounds
.bottom
= max(yinterStart
, yinterEnd
);
145 for(i
= 0; i
<= 8; i
++) {
146 if(i
* M_PI
/ 2 < angleStart
) /* loop until we're past start */
148 if(i
* M_PI
/ 2 > angleEnd
) /* if we're past end we're finished */
151 /* the arc touches the rectangle at the start of quadrant i, so adjust
152 BBox to reflect this. */
156 bounds
.right
= right
;
165 bounds
.bottom
= bottom
;
170 /* If we're drawing a pie then make sure we include the centre */
171 if(iType
== EMR_PIE
) {
172 if(bounds
.left
> xCentre
) bounds
.left
= xCentre
;
173 else if(bounds
.right
< xCentre
) bounds
.right
= xCentre
;
174 if(bounds
.top
> yCentre
) bounds
.top
= yCentre
;
175 else if(bounds
.bottom
< yCentre
) bounds
.bottom
= yCentre
;
177 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
179 EMFDRV_UpdateBBox( dev
, &bounds
);
184 /***********************************************************************
187 BOOL
EMFDRV_Arc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
188 INT xstart
, INT ystart
, INT xend
, INT yend
)
190 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
191 xend
, yend
, EMR_ARC
);
194 /***********************************************************************
197 BOOL
EMFDRV_Pie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
198 INT xstart
, INT ystart
, INT xend
, INT yend
)
200 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
201 xend
, yend
, EMR_PIE
);
205 /***********************************************************************
208 BOOL
EMFDRV_Chord( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
209 INT xstart
, INT ystart
, INT xend
, INT yend
)
211 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
212 xend
, yend
, EMR_CHORD
);
215 /***********************************************************************
218 BOOL
EMFDRV_Ellipse( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
223 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
225 if(left
== right
|| top
== bottom
) return FALSE
;
227 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
228 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
230 if(GetGraphicsMode( dev
->hdc
) == GM_COMPATIBLE
) {
235 emr
.emr
.iType
= EMR_ELLIPSE
;
236 emr
.emr
.nSize
= sizeof(emr
);
237 emr
.rclBox
.left
= left
;
238 emr
.rclBox
.top
= top
;
239 emr
.rclBox
.right
= right
;
240 emr
.rclBox
.bottom
= bottom
;
242 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
243 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
246 /***********************************************************************
249 BOOL
EMFDRV_Rectangle(PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
254 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
256 if(left
== right
|| top
== bottom
) return FALSE
;
258 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
259 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
261 if(GetGraphicsMode( dev
->hdc
) == GM_COMPATIBLE
) {
266 emr
.emr
.iType
= EMR_RECTANGLE
;
267 emr
.emr
.nSize
= sizeof(emr
);
268 emr
.rclBox
.left
= left
;
269 emr
.rclBox
.top
= top
;
270 emr
.rclBox
.right
= right
;
271 emr
.rclBox
.bottom
= bottom
;
273 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
274 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
277 /***********************************************************************
280 BOOL
EMFDRV_RoundRect( PHYSDEV dev
, INT left
, INT top
, INT right
,
281 INT bottom
, INT ell_width
, INT ell_height
)
286 if(left
== right
|| top
== bottom
) return FALSE
;
288 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
289 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
291 if(GetGraphicsMode( dev
->hdc
) == GM_COMPATIBLE
) {
296 emr
.emr
.iType
= EMR_ROUNDRECT
;
297 emr
.emr
.nSize
= sizeof(emr
);
298 emr
.rclBox
.left
= left
;
299 emr
.rclBox
.top
= top
;
300 emr
.rclBox
.right
= right
;
301 emr
.rclBox
.bottom
= bottom
;
302 emr
.szlCorner
.cx
= ell_width
;
303 emr
.szlCorner
.cy
= ell_height
;
305 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
306 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
309 /***********************************************************************
312 COLORREF
EMFDRV_SetPixel( PHYSDEV dev
, INT x
, INT y
, COLORREF color
)
316 emr
.emr
.iType
= EMR_SETPIXELV
;
317 emr
.emr
.nSize
= sizeof(emr
);
322 if (EMFDRV_WriteRecord( dev
, &emr
.emr
)) {
324 bounds
.left
= bounds
.right
= x
;
325 bounds
.top
= bounds
.bottom
= y
;
326 EMFDRV_UpdateBBox( dev
, &bounds
);
332 /**********************************************************************
335 * Helper for EMFDRV_Poly{line|gon}
338 EMFDRV_Polylinegon( PHYSDEV dev
, const POINT
* pt
, INT count
, DWORD iType
)
345 size
= sizeof(EMRPOLYLINE
) + sizeof(POINTL
) * (count
- 1);
347 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
348 emr
->emr
.iType
= iType
;
349 emr
->emr
.nSize
= size
;
351 emr
->rclBounds
.left
= emr
->rclBounds
.right
= pt
[0].x
;
352 emr
->rclBounds
.top
= emr
->rclBounds
.bottom
= pt
[0].y
;
354 for(i
= 1; i
< count
; i
++) {
355 if(pt
[i
].x
< emr
->rclBounds
.left
)
356 emr
->rclBounds
.left
= pt
[i
].x
;
357 else if(pt
[i
].x
> emr
->rclBounds
.right
)
358 emr
->rclBounds
.right
= pt
[i
].x
;
359 if(pt
[i
].y
< emr
->rclBounds
.top
)
360 emr
->rclBounds
.top
= pt
[i
].y
;
361 else if(pt
[i
].y
> emr
->rclBounds
.bottom
)
362 emr
->rclBounds
.bottom
= pt
[i
].y
;
366 memcpy(emr
->aptl
, pt
, count
* sizeof(POINTL
));
368 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
370 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
371 HeapFree( GetProcessHeap(), 0, emr
);
376 /**********************************************************************
377 * EMFDRV_Polylinegon16
379 * Helper for EMFDRV_Poly{line|gon}
381 * This is not a legacy function!
382 * We are using SHORT integers to save space.
385 EMFDRV_Polylinegon16( PHYSDEV dev
, const POINT
* pt
, INT count
, DWORD iType
)
392 /* check whether all points fit in the SHORT int POINT structure */
393 for(i
= 0; i
< count
; i
++) {
394 if( ((pt
[i
].x
+0x8000) & ~0xffff ) ||
395 ((pt
[i
].y
+0x8000) & ~0xffff ) )
399 size
= sizeof(EMRPOLYLINE16
) + sizeof(POINTS
) * (count
- 1);
401 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
402 emr
->emr
.iType
= iType
;
403 emr
->emr
.nSize
= size
;
405 emr
->rclBounds
.left
= emr
->rclBounds
.right
= pt
[0].x
;
406 emr
->rclBounds
.top
= emr
->rclBounds
.bottom
= pt
[0].y
;
408 for(i
= 1; i
< count
; i
++) {
409 if(pt
[i
].x
< emr
->rclBounds
.left
)
410 emr
->rclBounds
.left
= pt
[i
].x
;
411 else if(pt
[i
].x
> emr
->rclBounds
.right
)
412 emr
->rclBounds
.right
= pt
[i
].x
;
413 if(pt
[i
].y
< emr
->rclBounds
.top
)
414 emr
->rclBounds
.top
= pt
[i
].y
;
415 else if(pt
[i
].y
> emr
->rclBounds
.bottom
)
416 emr
->rclBounds
.bottom
= pt
[i
].y
;
420 for(i
= 0; i
< count
; i
++ ) {
421 emr
->apts
[i
].x
= pt
[i
].x
;
422 emr
->apts
[i
].y
= pt
[i
].y
;
425 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
427 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
428 HeapFree( GetProcessHeap(), 0, emr
);
433 /**********************************************************************
436 BOOL
EMFDRV_Polyline( PHYSDEV dev
, const POINT
* pt
, INT count
)
438 if( EMFDRV_Polylinegon16( dev
, pt
, count
, EMR_POLYLINE16
) )
440 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYLINE
);
443 /**********************************************************************
446 BOOL
EMFDRV_Polygon( PHYSDEV dev
, const POINT
* pt
, INT count
)
448 if(count
< 2) return FALSE
;
449 if( EMFDRV_Polylinegon16( dev
, pt
, count
, EMR_POLYGON16
) )
451 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYGON
);
454 /**********************************************************************
457 BOOL
EMFDRV_PolyBezier( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
459 if(EMFDRV_Polylinegon16( dev
, pts
, count
, EMR_POLYBEZIER16
))
461 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIER
);
464 /**********************************************************************
465 * EMFDRV_PolyBezierTo
467 BOOL
EMFDRV_PolyBezierTo( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
469 if(EMFDRV_Polylinegon16( dev
, pts
, count
, EMR_POLYBEZIERTO16
))
471 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIERTO
);
475 /**********************************************************************
476 * EMFDRV_PolyPolylinegon
478 * Helper for EMFDRV_PolyPoly{line|gon}
481 EMFDRV_PolyPolylinegon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
,
484 EMRPOLYPOLYLINE
*emr
;
485 DWORD cptl
= 0, poly
, size
, i
;
487 const RECTL empty
= {0, 0, -1, -1};
488 RECTL bounds
= empty
;
490 BOOL ret
, use_small_emr
= TRUE
, bounds_valid
= TRUE
;
493 for(poly
= 0; poly
< polys
; poly
++) {
494 cptl
+= counts
[poly
];
495 if(counts
[poly
] < 2) bounds_valid
= FALSE
;
496 for(point
= 0; point
< counts
[poly
]; point
++) {
497 /* check whether all points fit in the SHORT int POINT structure */
498 if( ((pts
->x
+0x8000) & ~0xffff ) ||
499 ((pts
->y
+0x8000) & ~0xffff ) )
500 use_small_emr
= FALSE
;
502 bounds
.left
= bounds
.right
= pts
->x
;
503 bounds
.top
= bounds
.bottom
= pts
->y
;
505 if(bounds
.left
> pts
->x
) bounds
.left
= pts
->x
;
506 else if(bounds
.right
< pts
->x
) bounds
.right
= pts
->x
;
507 if(bounds
.top
> pts
->y
) bounds
.top
= pts
->y
;
508 else if(bounds
.bottom
< pts
->y
) bounds
.bottom
= pts
->y
;
513 if(!cptl
) bounds_valid
= FALSE
;
515 size
= FIELD_OFFSET(EMRPOLYPOLYLINE
, aPolyCounts
[polys
]);
517 size
+= cptl
* sizeof(POINTS
);
519 size
+= cptl
* sizeof(POINTL
);
521 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
523 emr
->emr
.iType
= iType
;
524 if(use_small_emr
) emr
->emr
.iType
+= EMR_POLYPOLYLINE16
- EMR_POLYPOLYLINE
;
526 emr
->emr
.nSize
= size
;
528 emr
->rclBounds
= bounds
;
530 emr
->rclBounds
= empty
;
536 memcpy( emr
->aPolyCounts
, counts
, polys
* sizeof(DWORD
) );
541 POINTS
*out_pts
= (POINTS
*)(emr
->aPolyCounts
+ polys
);
542 for(i
= 0; i
< cptl
; i
++ )
544 out_pts
[i
].x
= pt
[i
].x
;
545 out_pts
[i
].y
= pt
[i
].y
;
549 memcpy( emr
->aPolyCounts
+ polys
, pt
, cptl
* sizeof(POINTL
) );
553 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
554 if(ret
&& !bounds_valid
)
557 SetLastError( ERROR_INVALID_PARAMETER
);
560 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
561 HeapFree( GetProcessHeap(), 0, emr
);
565 /**********************************************************************
566 * EMFDRV_PolyPolyline
568 BOOL
EMFDRV_PolyPolyline(PHYSDEV dev
, const POINT
* pt
, const DWORD
* counts
, DWORD polys
)
570 return EMFDRV_PolyPolylinegon( dev
, pt
, (const INT
*)counts
, polys
,
574 /**********************************************************************
577 BOOL
EMFDRV_PolyPolygon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
)
579 return EMFDRV_PolyPolylinegon( dev
, pt
, counts
, polys
, EMR_POLYPOLYGON
);
583 /**********************************************************************
584 * EMFDRV_ExtFloodFill
586 BOOL
EMFDRV_ExtFloodFill( PHYSDEV dev
, INT x
, INT y
, COLORREF color
, UINT fillType
)
590 emr
.emr
.iType
= EMR_EXTFLOODFILL
;
591 emr
.emr
.nSize
= sizeof(emr
);
595 emr
.iMode
= fillType
;
597 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
601 /*********************************************************************
604 BOOL
EMFDRV_FillRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
)
607 DWORD size
, rgnsize
, index
;
610 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
611 if(!index
) return FALSE
;
613 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
614 size
= rgnsize
+ offsetof(EMRFILLRGN
,RgnData
);
615 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
617 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
619 emr
->emr
.iType
= EMR_FILLRGN
;
620 emr
->emr
.nSize
= size
;
621 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
622 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
623 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
624 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
625 emr
->cbRgnData
= rgnsize
;
626 emr
->ihBrush
= index
;
628 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
630 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
631 HeapFree( GetProcessHeap(), 0, emr
);
634 /*********************************************************************
637 BOOL
EMFDRV_FrameRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
, INT width
, INT height
)
640 DWORD size
, rgnsize
, index
;
643 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
644 if(!index
) return FALSE
;
646 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
647 size
= rgnsize
+ offsetof(EMRFRAMERGN
,RgnData
);
648 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
650 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
652 emr
->emr
.iType
= EMR_FRAMERGN
;
653 emr
->emr
.nSize
= size
;
654 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
655 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
656 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
657 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
658 emr
->cbRgnData
= rgnsize
;
659 emr
->ihBrush
= index
;
660 emr
->szlStroke
.cx
= width
;
661 emr
->szlStroke
.cy
= height
;
663 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
665 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
666 HeapFree( GetProcessHeap(), 0, emr
);
670 /*********************************************************************
671 * EMFDRV_PaintInvertRgn
673 * Helper for EMFDRV_{Paint|Invert}Rgn
675 static BOOL
EMFDRV_PaintInvertRgn( PHYSDEV dev
, HRGN hrgn
, DWORD iType
)
682 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
683 size
= rgnsize
+ offsetof(EMRINVERTRGN
,RgnData
);
684 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
686 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
688 emr
->emr
.iType
= iType
;
689 emr
->emr
.nSize
= size
;
690 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
691 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
692 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
693 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
694 emr
->cbRgnData
= rgnsize
;
696 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
698 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
699 HeapFree( GetProcessHeap(), 0, emr
);
703 /**********************************************************************
706 BOOL
EMFDRV_PaintRgn( PHYSDEV dev
, HRGN hrgn
)
708 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_PAINTRGN
);
711 /**********************************************************************
714 BOOL
EMFDRV_InvertRgn( PHYSDEV dev
, HRGN hrgn
)
716 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_INVERTRGN
);
719 /**********************************************************************
722 BOOL
EMFDRV_ExtTextOut( PHYSDEV dev
, INT x
, INT y
, UINT flags
, const RECT
*lprect
,
723 LPCWSTR str
, UINT count
, const INT
*lpDx
)
725 EMREXTTEXTOUTW
*pemr
;
730 const UINT textAlign
= GetTextAlign( dev
->hdc
);
731 const INT graphicsMode
= GetGraphicsMode( dev
->hdc
);
732 FLOAT exScale
, eyScale
;
734 nSize
= sizeof(*pemr
) + ((count
+1) & ~1) * sizeof(WCHAR
) + count
* sizeof(INT
);
736 TRACE("%s %s count %d nSize = %d\n", debugstr_wn(str
, count
),
737 wine_dbgstr_rect(lprect
), count
, nSize
);
738 pemr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nSize
);
740 if (graphicsMode
== GM_COMPATIBLE
)
742 const INT horzSize
= GetDeviceCaps( dev
->hdc
, HORZSIZE
);
743 const INT horzRes
= GetDeviceCaps( dev
->hdc
, HORZRES
);
744 const INT vertSize
= GetDeviceCaps( dev
->hdc
, VERTSIZE
);
745 const INT vertRes
= GetDeviceCaps( dev
->hdc
, VERTRES
);
746 SIZE wndext
, vportext
;
748 GetViewportExtEx( dev
->hdc
, &vportext
);
749 GetWindowExtEx( dev
->hdc
, &wndext
);
750 exScale
= 100.0 * ((FLOAT
)horzSize
/ (FLOAT
)horzRes
) /
751 ((FLOAT
)wndext
.cx
/ (FLOAT
)vportext
.cx
);
752 eyScale
= 100.0 * ((FLOAT
)vertSize
/ (FLOAT
)vertRes
) /
753 ((FLOAT
)wndext
.cy
/ (FLOAT
)vportext
.cy
);
761 pemr
->emr
.iType
= EMR_EXTTEXTOUTW
;
762 pemr
->emr
.nSize
= nSize
;
763 pemr
->iGraphicsMode
= graphicsMode
;
764 pemr
->exScale
= exScale
;
765 pemr
->eyScale
= eyScale
;
766 pemr
->emrtext
.ptlReference
.x
= x
;
767 pemr
->emrtext
.ptlReference
.y
= y
;
768 pemr
->emrtext
.nChars
= count
;
769 pemr
->emrtext
.offString
= sizeof(*pemr
);
770 memcpy((char*)pemr
+ pemr
->emrtext
.offString
, str
, count
* sizeof(WCHAR
));
771 pemr
->emrtext
.fOptions
= flags
;
773 pemr
->emrtext
.rcl
.left
= pemr
->emrtext
.rcl
.top
= 0;
774 pemr
->emrtext
.rcl
.right
= pemr
->emrtext
.rcl
.bottom
= -1;
776 pemr
->emrtext
.rcl
.left
= lprect
->left
;
777 pemr
->emrtext
.rcl
.top
= lprect
->top
;
778 pemr
->emrtext
.rcl
.right
= lprect
->right
;
779 pemr
->emrtext
.rcl
.bottom
= lprect
->bottom
;
782 pemr
->emrtext
.offDx
= pemr
->emrtext
.offString
+ ((count
+1) & ~1) * sizeof(WCHAR
);
786 memcpy((char*)pemr
+ pemr
->emrtext
.offDx
, lpDx
, count
* sizeof(INT
));
787 for (i
= 0; i
< count
; i
++) {
788 textWidth
+= lpDx
[i
];
790 if (GetTextExtentPoint32W( dev
->hdc
, str
, count
, &strSize
))
791 textHeight
= strSize
.cy
;
795 INT
*dx
= (INT
*)((char*)pemr
+ pemr
->emrtext
.offDx
);
797 for (i
= 0; i
< count
; i
++) {
798 if (GetTextExtentPoint32W( dev
->hdc
, str
+ i
, 1, &charSize
)) {
800 textWidth
+= charSize
.cx
;
801 textHeight
= max(textHeight
, charSize
.cy
);
808 pemr
->rclBounds
.left
= pemr
->rclBounds
.top
= 0;
809 pemr
->rclBounds
.right
= pemr
->rclBounds
.bottom
= -1;
813 switch (textAlign
& (TA_LEFT
| TA_RIGHT
| TA_CENTER
)) {
815 pemr
->rclBounds
.left
= x
- (textWidth
/ 2) - 1;
816 pemr
->rclBounds
.right
= x
+ (textWidth
/ 2) + 1;
820 pemr
->rclBounds
.left
= x
- textWidth
- 1;
821 pemr
->rclBounds
.right
= x
;
824 default: { /* TA_LEFT */
825 pemr
->rclBounds
.left
= x
;
826 pemr
->rclBounds
.right
= x
+ textWidth
+ 1;
830 switch (textAlign
& (TA_TOP
| TA_BOTTOM
| TA_BASELINE
)) {
833 if (!GetTextMetricsW( dev
->hdc
, &tm
))
835 /* Play safe here... it's better to have a bounding box */
836 /* that is too big than too small. */
837 pemr
->rclBounds
.top
= y
- textHeight
- 1;
838 pemr
->rclBounds
.bottom
= y
+ tm
.tmDescent
+ 1;
842 pemr
->rclBounds
.top
= y
- textHeight
- 1;
843 pemr
->rclBounds
.bottom
= y
;
846 default: { /* TA_TOP */
847 pemr
->rclBounds
.top
= y
;
848 pemr
->rclBounds
.bottom
= y
+ textHeight
+ 1;
851 EMFDRV_UpdateBBox( dev
, &pemr
->rclBounds
);
854 ret
= EMFDRV_WriteRecord( dev
, &pemr
->emr
);
855 HeapFree( GetProcessHeap(), 0, pemr
);