009f69f8b6be22262f70513f8d9997524811e77a
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 /**********************************************************************
102 BOOL
EMFDRV_MoveTo(PHYSDEV dev
, INT x
, INT y
)
106 emr
.emr
.iType
= EMR_MOVETOEX
;
107 emr
.emr
.nSize
= sizeof(emr
);
111 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
114 /***********************************************************************
117 BOOL
EMFDRV_LineTo( PHYSDEV dev
, INT x
, INT y
)
123 emr
.emr
.iType
= EMR_LINETO
;
124 emr
.emr
.nSize
= sizeof(emr
);
128 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
131 GetCurrentPositionEx( dev
->hdc
, &pt
);
133 bounds
.left
= min(x
, pt
.x
);
134 bounds
.top
= min(y
, pt
.y
);
135 bounds
.right
= max(x
, pt
.x
);
136 bounds
.bottom
= max(y
, pt
.y
);
138 EMFDRV_UpdateBBox( dev
, &bounds
);
144 /***********************************************************************
148 EMFDRV_ArcChordPie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
149 INT xstart
, INT ystart
, INT xend
, INT yend
, DWORD iType
)
151 INT temp
, xCentre
, yCentre
, i
;
152 double angleStart
, angleEnd
;
153 double xinterStart
, yinterStart
, xinterEnd
, yinterEnd
;
157 if(left
== right
|| top
== bottom
) return FALSE
;
159 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
160 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
162 if(GetGraphicsMode(dev
->hdc
) == GM_COMPATIBLE
) {
167 emr
.emr
.iType
= iType
;
168 emr
.emr
.nSize
= sizeof(emr
);
169 emr
.rclBox
.left
= left
;
170 emr
.rclBox
.top
= top
;
171 emr
.rclBox
.right
= right
;
172 emr
.rclBox
.bottom
= bottom
;
173 emr
.ptlStart
.x
= xstart
;
174 emr
.ptlStart
.y
= ystart
;
179 /* Now calculate the BBox */
180 xCentre
= (left
+ right
+ 1) / 2;
181 yCentre
= (top
+ bottom
+ 1) / 2;
188 /* invert y co-ords to get angle anti-clockwise from x-axis */
189 angleStart
= atan2( -(double)ystart
, (double)xstart
);
190 angleEnd
= atan2( -(double)yend
, (double)xend
);
192 /* These are the intercepts of the start/end lines with the arc */
194 xinterStart
= (right
- left
+ 1)/2 * cos(angleStart
) + xCentre
;
195 yinterStart
= -(bottom
- top
+ 1)/2 * sin(angleStart
) + yCentre
;
196 xinterEnd
= (right
- left
+ 1)/2 * cos(angleEnd
) + xCentre
;
197 yinterEnd
= -(bottom
- top
+ 1)/2 * sin(angleEnd
) + yCentre
;
199 if(angleStart
< 0) angleStart
+= 2 * M_PI
;
200 if(angleEnd
< 0) angleEnd
+= 2 * M_PI
;
201 if(angleEnd
< angleStart
) angleEnd
+= 2 * M_PI
;
203 bounds
.left
= min(xinterStart
, xinterEnd
);
204 bounds
.top
= min(yinterStart
, yinterEnd
);
205 bounds
.right
= max(xinterStart
, xinterEnd
);
206 bounds
.bottom
= max(yinterStart
, yinterEnd
);
208 for(i
= 0; i
<= 8; i
++) {
209 if(i
* M_PI
/ 2 < angleStart
) /* loop until we're past start */
211 if(i
* M_PI
/ 2 > angleEnd
) /* if we're past end we're finished */
214 /* the arc touches the rectangle at the start of quadrant i, so adjust
215 BBox to reflect this. */
219 bounds
.right
= right
;
228 bounds
.bottom
= bottom
;
233 /* If we're drawing a pie then make sure we include the centre */
234 if(iType
== EMR_PIE
) {
235 if(bounds
.left
> xCentre
) bounds
.left
= xCentre
;
236 else if(bounds
.right
< xCentre
) bounds
.right
= xCentre
;
237 if(bounds
.top
> yCentre
) bounds
.top
= yCentre
;
238 else if(bounds
.bottom
< yCentre
) bounds
.bottom
= yCentre
;
240 if(!EMFDRV_WriteRecord( dev
, &emr
.emr
))
242 EMFDRV_UpdateBBox( dev
, &bounds
);
247 /***********************************************************************
250 BOOL
EMFDRV_Arc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
251 INT xstart
, INT ystart
, INT xend
, INT yend
)
253 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
254 xend
, yend
, EMR_ARC
);
257 /***********************************************************************
260 BOOL
EMFDRV_Pie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
261 INT xstart
, INT ystart
, INT xend
, INT yend
)
263 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
264 xend
, yend
, EMR_PIE
);
268 /***********************************************************************
271 BOOL
EMFDRV_Chord( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
272 INT xstart
, INT ystart
, INT xend
, INT yend
)
274 return EMFDRV_ArcChordPie( dev
, left
, top
, right
, bottom
, xstart
, ystart
,
275 xend
, yend
, EMR_CHORD
);
278 /***********************************************************************
281 BOOL
EMFDRV_Ellipse( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
286 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
288 if(left
== right
|| top
== bottom
) return FALSE
;
290 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
291 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
293 if(GetGraphicsMode( dev
->hdc
) == GM_COMPATIBLE
) {
298 emr
.emr
.iType
= EMR_ELLIPSE
;
299 emr
.emr
.nSize
= sizeof(emr
);
300 emr
.rclBox
.left
= left
;
301 emr
.rclBox
.top
= top
;
302 emr
.rclBox
.right
= right
;
303 emr
.rclBox
.bottom
= bottom
;
305 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
306 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
309 /***********************************************************************
312 BOOL
EMFDRV_Rectangle(PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
317 TRACE("%d,%d - %d,%d\n", left
, top
, right
, bottom
);
319 if(left
== right
|| top
== bottom
) return FALSE
;
321 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
322 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
324 if(GetGraphicsMode( dev
->hdc
) == GM_COMPATIBLE
) {
329 emr
.emr
.iType
= EMR_RECTANGLE
;
330 emr
.emr
.nSize
= sizeof(emr
);
331 emr
.rclBox
.left
= left
;
332 emr
.rclBox
.top
= top
;
333 emr
.rclBox
.right
= right
;
334 emr
.rclBox
.bottom
= bottom
;
336 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
337 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
340 /***********************************************************************
343 BOOL
EMFDRV_RoundRect( PHYSDEV dev
, INT left
, INT top
, INT right
,
344 INT bottom
, INT ell_width
, INT ell_height
)
349 if(left
== right
|| top
== bottom
) return FALSE
;
351 if(left
> right
) {temp
= left
; left
= right
; right
= temp
;}
352 if(top
> bottom
) {temp
= top
; top
= bottom
; bottom
= temp
;}
354 if(GetGraphicsMode( dev
->hdc
) == GM_COMPATIBLE
) {
359 emr
.emr
.iType
= EMR_ROUNDRECT
;
360 emr
.emr
.nSize
= sizeof(emr
);
361 emr
.rclBox
.left
= left
;
362 emr
.rclBox
.top
= top
;
363 emr
.rclBox
.right
= right
;
364 emr
.rclBox
.bottom
= bottom
;
365 emr
.szlCorner
.cx
= ell_width
;
366 emr
.szlCorner
.cy
= ell_height
;
368 EMFDRV_UpdateBBox( dev
, &emr
.rclBox
);
369 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
372 /***********************************************************************
375 COLORREF
EMFDRV_SetPixel( PHYSDEV dev
, INT x
, INT y
, COLORREF color
)
379 emr
.emr
.iType
= EMR_SETPIXELV
;
380 emr
.emr
.nSize
= sizeof(emr
);
385 if (EMFDRV_WriteRecord( dev
, &emr
.emr
)) {
387 bounds
.left
= bounds
.right
= x
;
388 bounds
.top
= bounds
.bottom
= y
;
389 EMFDRV_UpdateBBox( dev
, &bounds
);
395 /**********************************************************************
398 * Helper for EMFDRV_Poly{line|gon}
401 EMFDRV_Polylinegon( PHYSDEV dev
, const POINT
* pt
, INT count
, DWORD iType
)
408 size
= sizeof(EMRPOLYLINE
) + sizeof(POINTL
) * (count
- 1);
410 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
411 emr
->emr
.iType
= iType
;
412 emr
->emr
.nSize
= size
;
414 emr
->rclBounds
.left
= emr
->rclBounds
.right
= pt
[0].x
;
415 emr
->rclBounds
.top
= emr
->rclBounds
.bottom
= pt
[0].y
;
417 for(i
= 1; i
< count
; i
++) {
418 if(pt
[i
].x
< emr
->rclBounds
.left
)
419 emr
->rclBounds
.left
= pt
[i
].x
;
420 else if(pt
[i
].x
> emr
->rclBounds
.right
)
421 emr
->rclBounds
.right
= pt
[i
].x
;
422 if(pt
[i
].y
< emr
->rclBounds
.top
)
423 emr
->rclBounds
.top
= pt
[i
].y
;
424 else if(pt
[i
].y
> emr
->rclBounds
.bottom
)
425 emr
->rclBounds
.bottom
= pt
[i
].y
;
429 memcpy(emr
->aptl
, pt
, count
* sizeof(POINTL
));
431 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
433 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
434 HeapFree( GetProcessHeap(), 0, emr
);
439 /**********************************************************************
440 * EMFDRV_Polylinegon16
442 * Helper for EMFDRV_Poly{line|gon}
444 * This is not a legacy function!
445 * We are using SHORT integers to save space.
448 EMFDRV_Polylinegon16( PHYSDEV dev
, const POINT
* pt
, INT count
, DWORD iType
)
455 /* check whether all points fit in the SHORT int POINT structure */
456 for(i
= 0; i
< count
; i
++) {
457 if( ((pt
[i
].x
+0x8000) & ~0xffff ) ||
458 ((pt
[i
].y
+0x8000) & ~0xffff ) )
462 size
= sizeof(EMRPOLYLINE16
) + sizeof(POINTS
) * (count
- 1);
464 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
465 emr
->emr
.iType
= iType
;
466 emr
->emr
.nSize
= size
;
468 emr
->rclBounds
.left
= emr
->rclBounds
.right
= pt
[0].x
;
469 emr
->rclBounds
.top
= emr
->rclBounds
.bottom
= pt
[0].y
;
471 for(i
= 1; i
< count
; i
++) {
472 if(pt
[i
].x
< emr
->rclBounds
.left
)
473 emr
->rclBounds
.left
= pt
[i
].x
;
474 else if(pt
[i
].x
> emr
->rclBounds
.right
)
475 emr
->rclBounds
.right
= pt
[i
].x
;
476 if(pt
[i
].y
< emr
->rclBounds
.top
)
477 emr
->rclBounds
.top
= pt
[i
].y
;
478 else if(pt
[i
].y
> emr
->rclBounds
.bottom
)
479 emr
->rclBounds
.bottom
= pt
[i
].y
;
483 for(i
= 0; i
< count
; i
++ ) {
484 emr
->apts
[i
].x
= pt
[i
].x
;
485 emr
->apts
[i
].y
= pt
[i
].y
;
488 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
490 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
491 HeapFree( GetProcessHeap(), 0, emr
);
496 /**********************************************************************
499 BOOL
EMFDRV_Polyline( PHYSDEV dev
, const POINT
* pt
, INT count
)
501 if( EMFDRV_Polylinegon16( dev
, pt
, count
, EMR_POLYLINE16
) )
503 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYLINE
);
506 /**********************************************************************
509 BOOL
EMFDRV_Polygon( PHYSDEV dev
, const POINT
* pt
, INT count
)
511 if(count
< 2) return FALSE
;
512 if( EMFDRV_Polylinegon16( dev
, pt
, count
, EMR_POLYGON16
) )
514 return EMFDRV_Polylinegon( dev
, pt
, count
, EMR_POLYGON
);
517 /**********************************************************************
520 BOOL
EMFDRV_PolyBezier( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
522 if(EMFDRV_Polylinegon16( dev
, pts
, count
, EMR_POLYBEZIER16
))
524 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIER
);
527 /**********************************************************************
528 * EMFDRV_PolyBezierTo
530 BOOL
EMFDRV_PolyBezierTo( PHYSDEV dev
, const POINT
*pts
, DWORD count
)
532 if(EMFDRV_Polylinegon16( dev
, pts
, count
, EMR_POLYBEZIERTO16
))
534 return EMFDRV_Polylinegon( dev
, pts
, count
, EMR_POLYBEZIERTO
);
538 /**********************************************************************
539 * EMFDRV_PolyPolylinegon
541 * Helper for EMFDRV_PolyPoly{line|gon}
544 EMFDRV_PolyPolylinegon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
,
547 EMFDRV_PDEVICE
*physDev
= get_emf_physdev( dev
);
548 EMRPOLYPOLYLINE
*emr
;
549 DWORD cptl
= 0, poly
, size
;
550 BOOL ret
, use_small_emr
, bounds_valid
= TRUE
;
552 for(poly
= 0; poly
< polys
; poly
++) {
553 cptl
+= counts
[poly
];
554 if(counts
[poly
] < 2) bounds_valid
= FALSE
;
556 if(!cptl
) bounds_valid
= FALSE
;
557 use_small_emr
= can_use_short_points( pt
, cptl
);
559 size
= FIELD_OFFSET(EMRPOLYPOLYLINE
, aPolyCounts
[polys
]);
561 size
+= cptl
* sizeof(POINTS
);
563 size
+= cptl
* sizeof(POINTL
);
565 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
567 emr
->emr
.iType
= iType
;
568 if(use_small_emr
) emr
->emr
.iType
+= EMR_POLYPOLYLINE16
- EMR_POLYPOLYLINE
;
570 emr
->emr
.nSize
= size
;
571 if(bounds_valid
&& !physDev
->path
)
572 get_points_bounds( &emr
->rclBounds
, pt
, cptl
, 0 );
574 emr
->rclBounds
= empty_bounds
;
580 memcpy( emr
->aPolyCounts
, counts
, polys
* sizeof(DWORD
) );
581 store_points( (POINTL
*)(emr
->aPolyCounts
+ polys
), pt
, cptl
, use_small_emr
);
584 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
585 if(ret
&& !bounds_valid
)
588 SetLastError( ERROR_INVALID_PARAMETER
);
590 if(ret
&& !physDev
->path
)
591 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
592 HeapFree( GetProcessHeap(), 0, emr
);
596 /**********************************************************************
597 * EMFDRV_PolyPolyline
599 BOOL
EMFDRV_PolyPolyline(PHYSDEV dev
, const POINT
* pt
, const DWORD
* counts
, DWORD polys
)
601 return EMFDRV_PolyPolylinegon( dev
, pt
, (const INT
*)counts
, polys
,
605 /**********************************************************************
608 BOOL
EMFDRV_PolyPolygon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polys
)
610 return EMFDRV_PolyPolylinegon( dev
, pt
, counts
, polys
, EMR_POLYPOLYGON
);
614 /**********************************************************************
615 * EMFDRV_ExtFloodFill
617 BOOL
EMFDRV_ExtFloodFill( PHYSDEV dev
, INT x
, INT y
, COLORREF color
, UINT fillType
)
621 emr
.emr
.iType
= EMR_EXTFLOODFILL
;
622 emr
.emr
.nSize
= sizeof(emr
);
626 emr
.iMode
= fillType
;
628 return EMFDRV_WriteRecord( dev
, &emr
.emr
);
632 /*********************************************************************
635 BOOL
EMFDRV_FillRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
)
638 DWORD size
, rgnsize
, index
;
641 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
642 if(!index
) return FALSE
;
644 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
645 size
= rgnsize
+ offsetof(EMRFILLRGN
,RgnData
);
646 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
648 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
650 emr
->emr
.iType
= EMR_FILLRGN
;
651 emr
->emr
.nSize
= size
;
652 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
653 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
654 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
655 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
656 emr
->cbRgnData
= rgnsize
;
657 emr
->ihBrush
= index
;
659 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
661 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
662 HeapFree( GetProcessHeap(), 0, emr
);
665 /*********************************************************************
668 BOOL
EMFDRV_FrameRgn( PHYSDEV dev
, HRGN hrgn
, HBRUSH hbrush
, INT width
, INT height
)
671 DWORD size
, rgnsize
, index
;
674 index
= EMFDRV_CreateBrushIndirect( dev
, hbrush
);
675 if(!index
) return FALSE
;
677 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
678 size
= rgnsize
+ offsetof(EMRFRAMERGN
,RgnData
);
679 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
681 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
683 emr
->emr
.iType
= EMR_FRAMERGN
;
684 emr
->emr
.nSize
= size
;
685 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
686 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
687 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
688 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
689 emr
->cbRgnData
= rgnsize
;
690 emr
->ihBrush
= index
;
691 emr
->szlStroke
.cx
= width
;
692 emr
->szlStroke
.cy
= height
;
694 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
696 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
697 HeapFree( GetProcessHeap(), 0, emr
);
701 /*********************************************************************
702 * EMFDRV_PaintInvertRgn
704 * Helper for EMFDRV_{Paint|Invert}Rgn
706 static BOOL
EMFDRV_PaintInvertRgn( PHYSDEV dev
, HRGN hrgn
, DWORD iType
)
713 rgnsize
= GetRegionData( hrgn
, 0, NULL
);
714 size
= rgnsize
+ offsetof(EMRINVERTRGN
,RgnData
);
715 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
717 GetRegionData( hrgn
, rgnsize
, (RGNDATA
*)&emr
->RgnData
);
719 emr
->emr
.iType
= iType
;
720 emr
->emr
.nSize
= size
;
721 emr
->rclBounds
.left
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.left
;
722 emr
->rclBounds
.top
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.top
;
723 emr
->rclBounds
.right
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.right
- 1;
724 emr
->rclBounds
.bottom
= ((RGNDATA
*)&emr
->RgnData
)->rdh
.rcBound
.bottom
- 1;
725 emr
->cbRgnData
= rgnsize
;
727 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
729 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
730 HeapFree( GetProcessHeap(), 0, emr
);
734 /**********************************************************************
737 BOOL
EMFDRV_PaintRgn( PHYSDEV dev
, HRGN hrgn
)
739 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_PAINTRGN
);
742 /**********************************************************************
745 BOOL
EMFDRV_InvertRgn( PHYSDEV dev
, HRGN hrgn
)
747 return EMFDRV_PaintInvertRgn( dev
, hrgn
, EMR_INVERTRGN
);
750 /**********************************************************************
753 BOOL
EMFDRV_ExtTextOut( PHYSDEV dev
, INT x
, INT y
, UINT flags
, const RECT
*lprect
,
754 LPCWSTR str
, UINT count
, const INT
*lpDx
)
756 EMREXTTEXTOUTW
*pemr
;
761 const UINT textAlign
= GetTextAlign( dev
->hdc
);
762 const INT graphicsMode
= GetGraphicsMode( dev
->hdc
);
763 FLOAT exScale
, eyScale
;
765 nSize
= sizeof(*pemr
) + ((count
+1) & ~1) * sizeof(WCHAR
) + count
* sizeof(INT
);
767 TRACE("%s %s count %d nSize = %d\n", debugstr_wn(str
, count
),
768 wine_dbgstr_rect(lprect
), count
, nSize
);
769 pemr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nSize
);
771 if (graphicsMode
== GM_COMPATIBLE
)
773 const INT horzSize
= GetDeviceCaps( dev
->hdc
, HORZSIZE
);
774 const INT horzRes
= GetDeviceCaps( dev
->hdc
, HORZRES
);
775 const INT vertSize
= GetDeviceCaps( dev
->hdc
, VERTSIZE
);
776 const INT vertRes
= GetDeviceCaps( dev
->hdc
, VERTRES
);
777 SIZE wndext
, vportext
;
779 GetViewportExtEx( dev
->hdc
, &vportext
);
780 GetWindowExtEx( dev
->hdc
, &wndext
);
781 exScale
= 100.0 * ((FLOAT
)horzSize
/ (FLOAT
)horzRes
) /
782 ((FLOAT
)wndext
.cx
/ (FLOAT
)vportext
.cx
);
783 eyScale
= 100.0 * ((FLOAT
)vertSize
/ (FLOAT
)vertRes
) /
784 ((FLOAT
)wndext
.cy
/ (FLOAT
)vportext
.cy
);
792 pemr
->emr
.iType
= EMR_EXTTEXTOUTW
;
793 pemr
->emr
.nSize
= nSize
;
794 pemr
->iGraphicsMode
= graphicsMode
;
795 pemr
->exScale
= exScale
;
796 pemr
->eyScale
= eyScale
;
797 pemr
->emrtext
.ptlReference
.x
= x
;
798 pemr
->emrtext
.ptlReference
.y
= y
;
799 pemr
->emrtext
.nChars
= count
;
800 pemr
->emrtext
.offString
= sizeof(*pemr
);
801 memcpy((char*)pemr
+ pemr
->emrtext
.offString
, str
, count
* sizeof(WCHAR
));
802 pemr
->emrtext
.fOptions
= flags
;
804 pemr
->emrtext
.rcl
.left
= pemr
->emrtext
.rcl
.top
= 0;
805 pemr
->emrtext
.rcl
.right
= pemr
->emrtext
.rcl
.bottom
= -1;
807 pemr
->emrtext
.rcl
.left
= lprect
->left
;
808 pemr
->emrtext
.rcl
.top
= lprect
->top
;
809 pemr
->emrtext
.rcl
.right
= lprect
->right
;
810 pemr
->emrtext
.rcl
.bottom
= lprect
->bottom
;
813 pemr
->emrtext
.offDx
= pemr
->emrtext
.offString
+ ((count
+1) & ~1) * sizeof(WCHAR
);
817 memcpy((char*)pemr
+ pemr
->emrtext
.offDx
, lpDx
, count
* sizeof(INT
));
818 for (i
= 0; i
< count
; i
++) {
819 textWidth
+= lpDx
[i
];
821 if (GetTextExtentPoint32W( dev
->hdc
, str
, count
, &strSize
))
822 textHeight
= strSize
.cy
;
826 INT
*dx
= (INT
*)((char*)pemr
+ pemr
->emrtext
.offDx
);
828 for (i
= 0; i
< count
; i
++) {
829 if (GetTextExtentPoint32W( dev
->hdc
, str
+ i
, 1, &charSize
)) {
831 textWidth
+= charSize
.cx
;
832 textHeight
= max(textHeight
, charSize
.cy
);
839 pemr
->rclBounds
.left
= pemr
->rclBounds
.top
= 0;
840 pemr
->rclBounds
.right
= pemr
->rclBounds
.bottom
= -1;
844 switch (textAlign
& (TA_LEFT
| TA_RIGHT
| TA_CENTER
)) {
846 pemr
->rclBounds
.left
= x
- (textWidth
/ 2) - 1;
847 pemr
->rclBounds
.right
= x
+ (textWidth
/ 2) + 1;
851 pemr
->rclBounds
.left
= x
- textWidth
- 1;
852 pemr
->rclBounds
.right
= x
;
855 default: { /* TA_LEFT */
856 pemr
->rclBounds
.left
= x
;
857 pemr
->rclBounds
.right
= x
+ textWidth
+ 1;
861 switch (textAlign
& (TA_TOP
| TA_BOTTOM
| TA_BASELINE
)) {
864 if (!GetTextMetricsW( dev
->hdc
, &tm
))
866 /* Play safe here... it's better to have a bounding box */
867 /* that is too big than too small. */
868 pemr
->rclBounds
.top
= y
- textHeight
- 1;
869 pemr
->rclBounds
.bottom
= y
+ tm
.tmDescent
+ 1;
873 pemr
->rclBounds
.top
= y
- textHeight
- 1;
874 pemr
->rclBounds
.bottom
= y
;
877 default: { /* TA_TOP */
878 pemr
->rclBounds
.top
= y
;
879 pemr
->rclBounds
.bottom
= y
+ textHeight
+ 1;
882 EMFDRV_UpdateBBox( dev
, &pemr
->rclBounds
);
885 ret
= EMFDRV_WriteRecord( dev
, &pemr
->emr
);
886 HeapFree( GetProcessHeap(), 0, pemr
);