2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/unicode.h"
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
45 /* looks-right constants */
46 #define ANCHOR_WIDTH (2.0)
47 #define MAX_ITERS (50)
49 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
50 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
51 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
52 INT flags
, GDIPCONST GpMatrix
*matrix
);
54 /* Converts from gdiplus path point type to gdi path point type. */
55 static BYTE
convert_path_point_type(BYTE type
)
59 switch(type
& PathPointTypePathTypeMask
){
60 case PathPointTypeBezier
:
63 case PathPointTypeLine
:
66 case PathPointTypeStart
:
70 ERR("Bad point type\n");
74 if(type
& PathPointTypeCloseSubpath
)
75 ret
|= PT_CLOSEFIGURE
;
80 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
86 case BrushTypeSolidColor
:
88 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
92 case BrushTypeHatchFill
:
94 const GpHatch
*hatch
= (const GpHatch
*)brush
;
95 argb
= hatch
->forecol
;
98 case BrushTypeLinearGradient
:
100 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
101 argb
= line
->startcolor
;
104 case BrushTypePathGradient
:
106 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
107 argb
= grad
->centercolor
;
111 FIXME("unhandled brush type %d\n", brush
->bt
);
115 return ARGB2COLORREF(argb
);
118 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
121 BITMAPINFOHEADER bmih
;
125 bmih
.biSize
= sizeof(bmih
);
129 bmih
.biBitCount
= 32;
130 bmih
.biCompression
= BI_RGB
;
131 bmih
.biSizeImage
= 0;
133 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
136 const char *hatch_data
;
138 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
140 for (y
= 0; y
< 8; y
++)
142 for (x
= 0; x
< 8; x
++)
144 if (hatch_data
[y
] & (0x80 >> x
))
145 bits
[y
* 8 + x
] = hatch
->forecol
;
147 bits
[y
* 8 + x
] = hatch
->backcol
;
153 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
155 for (y
= 0; y
< 64; y
++)
156 bits
[y
] = hatch
->forecol
;
163 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
167 case BrushTypeSolidColor
:
169 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
170 lb
->lbStyle
= BS_SOLID
;
171 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
176 case BrushTypeHatchFill
:
178 const GpHatch
*hatch
= (const GpHatch
*)brush
;
181 hbmp
= create_hatch_bitmap(hatch
);
182 if (!hbmp
) return OutOfMemory
;
184 lb
->lbStyle
= BS_PATTERN
;
186 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
191 FIXME("unhandled brush type %d\n", brush
->bt
);
192 lb
->lbStyle
= BS_SOLID
;
193 lb
->lbColor
= get_gdi_brush_color(brush
);
199 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
204 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
210 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
215 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
217 gdibrush
= CreateBrushIndirect(&lb
);
218 free_gdi_logbrush(&lb
);
223 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
228 INT save_state
, i
, numdashes
;
230 DWORD dash_array
[MAX_DASHLEN
];
232 save_state
= SaveDC(graphics
->hdc
);
234 EndPath(graphics
->hdc
);
236 if(pen
->unit
== UnitPixel
){
240 /* Get an estimate for the amount the pen width is affected by the world
241 * transform. (This is similar to what some of the wine drivers do.) */
246 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
247 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
248 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
250 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
251 width
*= graphics
->scale
;
257 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceDevice
, pt
, 2);
258 width
*= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
259 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
262 if(pen
->dash
== DashStyleCustom
){
263 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
265 TRACE("dashes are: ");
266 for(i
= 0; i
< numdashes
; i
++){
267 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
268 TRACE("%d, ", dash_array
[i
]);
270 TRACE("\n and the pen style is %x\n", pen
->style
);
272 create_gdi_logbrush(pen
->brush
, &lb
);
273 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
274 numdashes
, dash_array
);
275 free_gdi_logbrush(&lb
);
279 create_gdi_logbrush(pen
->brush
, &lb
);
280 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
281 free_gdi_logbrush(&lb
);
284 SelectObject(graphics
->hdc
, gdipen
);
289 static void restore_dc(GpGraphics
*graphics
, INT state
)
291 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
292 RestoreDC(graphics
->hdc
, state
);
295 static void round_points(POINT
*pti
, GpPointF
*ptf
, INT count
)
299 for(i
= 0; i
< count
; i
++){
300 pti
[i
].x
= gdip_round(ptf
[i
].X
);
301 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
305 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
306 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
308 if (GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
) == DT_RASPRINTER
&&
309 GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
311 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
313 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
314 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
320 bf
.BlendOp
= AC_SRC_OVER
;
322 bf
.SourceConstantAlpha
= 255;
323 bf
.AlphaFormat
= AC_SRC_ALPHA
;
325 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
326 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
330 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
337 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceDevice
, &transform
);
340 stat
= GdipIsMatrixIdentity(&transform
, &identity
);
343 stat
= GdipCloneRegion(graphics
->clip
, &rgn
);
348 stat
= GdipTransformRegion(rgn
, &transform
);
351 stat
= GdipGetRegionHRgn(rgn
, NULL
, hrgn
);
353 GdipDeleteRegion(rgn
);
356 if (stat
== Ok
&& graphics
->gdi_clip
)
359 CombineRgn(*hrgn
, *hrgn
, graphics
->gdi_clip
, RGN_AND
);
362 *hrgn
= CreateRectRgn(0,0,0,0);
363 CombineRgn(*hrgn
, graphics
->gdi_clip
, graphics
->gdi_clip
, RGN_COPY
);
370 /* Draw ARGB data to the given graphics object */
371 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
372 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, const PixelFormat fmt
)
374 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
377 for (y
=0; y
<src_height
; y
++)
379 for (x
=0; x
<src_width
; x
++)
381 ARGB dst_color
, src_color
;
382 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
384 if (!(src_color
& 0xff000000))
387 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
388 if (fmt
& PixelFormatPAlpha
)
389 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over_fgpremult(dst_color
, src_color
));
391 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
398 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
399 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
403 BITMAPINFOHEADER bih
;
406 hdc
= CreateCompatibleDC(0);
408 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
409 bih
.biWidth
= src_width
;
410 bih
.biHeight
= -src_height
;
413 bih
.biCompression
= BI_RGB
;
415 bih
.biXPelsPerMeter
= 0;
416 bih
.biYPelsPerMeter
= 0;
418 bih
.biClrImportant
= 0;
420 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
421 (void**)&temp_bits
, NULL
, 0);
423 if ((GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
) == DT_RASPRINTER
&&
424 GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
) ||
425 fmt
& PixelFormatPAlpha
)
426 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
428 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
429 4 * src_width
, src
, src_stride
);
431 SelectObject(hdc
, hbitmap
);
432 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
433 hdc
, 0, 0, src_width
, src_height
);
435 DeleteObject(hbitmap
);
440 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
441 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
, PixelFormat fmt
)
445 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
451 HRGN hrgn
, visible_rgn
;
453 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
457 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
466 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
467 DeleteObject(visible_rgn
);
471 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
473 size
= GetRegionData(hrgn
, 0, NULL
);
475 rgndata
= heap_alloc_zero(size
);
482 GetRegionData(hrgn
, size
, rgndata
);
484 rects
= (RECT
*)rgndata
->Buffer
;
486 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
488 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
489 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
490 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
500 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
502 ERR("This should not be used for metafiles; fix caller\n");
503 return NotImplemented
;
510 stat
= get_clip_hrgn(graphics
, &hrgn
);
515 save
= SaveDC(graphics
->hdc
);
517 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
520 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
522 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
523 src_height
, src_stride
, fmt
);
525 RestoreDC(graphics
->hdc
, save
);
533 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
534 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
536 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
, fmt
);
539 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
541 INT start_a
, end_a
, final_a
;
544 pos
= gdip_round(position
* 0xff);
546 start_a
= ((start
>> 24) & 0xff) * (pos
^ 0xff);
547 end_a
= ((end
>> 24) & 0xff) * pos
;
549 final_a
= start_a
+ end_a
;
551 if (final_a
< 0xff) return 0;
553 return (final_a
/ 0xff) << 24 |
554 ((((start
>> 16) & 0xff) * start_a
+ (((end
>> 16) & 0xff) * end_a
)) / final_a
) << 16 |
555 ((((start
>> 8) & 0xff) * start_a
+ (((end
>> 8) & 0xff) * end_a
)) / final_a
) << 8 |
556 (((start
& 0xff) * start_a
+ ((end
& 0xff) * end_a
)) / final_a
);
559 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
563 /* clamp to between 0.0 and 1.0, using the wrap mode */
564 position
= (position
- brush
->rect
.X
) / brush
->rect
.Width
;
565 if (brush
->wrap
== WrapModeTile
)
567 position
= fmodf(position
, 1.0f
);
568 if (position
< 0.0f
) position
+= 1.0f
;
570 else /* WrapModeFlip* */
572 position
= fmodf(position
, 2.0f
);
573 if (position
< 0.0f
) position
+= 2.0f
;
574 if (position
> 1.0f
) position
= 2.0f
- position
;
577 if (brush
->blendcount
== 1)
582 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
585 /* locate the blend positions surrounding this position */
586 while (position
> brush
->blendpos
[i
])
589 /* interpolate between the blend positions */
590 left_blendpos
= brush
->blendpos
[i
-1];
591 left_blendfac
= brush
->blendfac
[i
-1];
592 right_blendpos
= brush
->blendpos
[i
];
593 right_blendfac
= brush
->blendfac
[i
];
594 range
= right_blendpos
- left_blendpos
;
595 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
596 right_blendfac
* (position
- left_blendpos
)) / range
;
599 if (brush
->pblendcount
== 0)
600 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
604 ARGB left_blendcolor
, right_blendcolor
;
605 REAL left_blendpos
, right_blendpos
;
607 /* locate the blend colors surrounding this position */
608 while (blendfac
> brush
->pblendpos
[i
])
611 /* interpolate between the blend colors */
612 left_blendpos
= brush
->pblendpos
[i
-1];
613 left_blendcolor
= brush
->pblendcolor
[i
-1];
614 right_blendpos
= brush
->pblendpos
[i
];
615 right_blendcolor
= brush
->pblendcolor
[i
];
616 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
617 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
621 static BOOL
round_color_matrix(const ColorMatrix
*matrix
, int values
[5][5])
623 /* Convert floating point color matrix to int[5][5], return TRUE if it's an identity */
624 BOOL identity
= TRUE
;
630 if (matrix
->m
[j
][i
] != (i
== j
? 1.0 : 0.0))
632 values
[j
][i
] = gdip_round(matrix
->m
[j
][i
] * 256.0);
638 static ARGB
transform_color(ARGB color
, int matrix
[5][5])
642 unsigned char a
, r
, g
, b
;
644 val
[0] = ((color
>> 16) & 0xff); /* red */
645 val
[1] = ((color
>> 8) & 0xff); /* green */
646 val
[2] = (color
& 0xff); /* blue */
647 val
[3] = ((color
>> 24) & 0xff); /* alpha */
648 val
[4] = 255; /* translation */
655 res
[i
] += matrix
[j
][i
] * val
[j
];
658 a
= min(max(res
[3] / 256, 0), 255);
659 r
= min(max(res
[0] / 256, 0), 255);
660 g
= min(max(res
[1] / 256, 0), 255);
661 b
= min(max(res
[2] / 256, 0), 255);
663 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
666 static BOOL
color_is_gray(ARGB color
)
668 unsigned char r
, g
, b
;
670 r
= (color
>> 16) & 0xff;
671 g
= (color
>> 8) & 0xff;
674 return (r
== g
) && (g
== b
);
677 /* returns preferred pixel format for the applied attributes */
678 PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
679 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
)
684 if ((attributes
->noop
[type
] == IMAGEATTR_NOOP_UNDEFINED
&&
685 attributes
->noop
[ColorAdjustTypeDefault
] == IMAGEATTR_NOOP_SET
) ||
686 (attributes
->noop
[type
] == IMAGEATTR_NOOP_SET
))
689 if (attributes
->colorkeys
[type
].enabled
||
690 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
692 const struct color_key
*key
;
693 BYTE min_blue
, min_green
, min_red
;
694 BYTE max_blue
, max_green
, max_red
;
696 if (!data
|| fmt
!= PixelFormat32bppARGB
)
697 return PixelFormat32bppARGB
;
699 if (attributes
->colorkeys
[type
].enabled
)
700 key
= &attributes
->colorkeys
[type
];
702 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
704 min_blue
= key
->low
&0xff;
705 min_green
= (key
->low
>>8)&0xff;
706 min_red
= (key
->low
>>16)&0xff;
708 max_blue
= key
->high
&0xff;
709 max_green
= (key
->high
>>8)&0xff;
710 max_red
= (key
->high
>>16)&0xff;
712 for (x
=0; x
<width
; x
++)
713 for (y
=0; y
<height
; y
++)
716 BYTE blue
, green
, red
;
717 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
718 blue
= *src_color
&0xff;
719 green
= (*src_color
>>8)&0xff;
720 red
= (*src_color
>>16)&0xff;
721 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
722 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
723 *src_color
= 0x00000000;
727 if (attributes
->colorremaptables
[type
].enabled
||
728 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
730 const struct color_remap_table
*table
;
732 if (!data
|| fmt
!= PixelFormat32bppARGB
)
733 return PixelFormat32bppARGB
;
735 if (attributes
->colorremaptables
[type
].enabled
)
736 table
= &attributes
->colorremaptables
[type
];
738 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
740 for (x
=0; x
<width
; x
++)
741 for (y
=0; y
<height
; y
++)
744 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
745 for (i
=0; i
<table
->mapsize
; i
++)
747 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
749 *src_color
= table
->colormap
[i
].newColor
.Argb
;
756 if (attributes
->colormatrices
[type
].enabled
||
757 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
759 const struct color_matrix
*colormatrices
;
760 int color_matrix
[5][5];
761 int gray_matrix
[5][5];
764 if (!data
|| fmt
!= PixelFormat32bppARGB
)
765 return PixelFormat32bppARGB
;
767 if (attributes
->colormatrices
[type
].enabled
)
768 colormatrices
= &attributes
->colormatrices
[type
];
770 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
772 identity
= round_color_matrix(&colormatrices
->colormatrix
, color_matrix
);
774 if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
775 identity
= (round_color_matrix(&colormatrices
->graymatrix
, gray_matrix
) && identity
);
779 for (x
=0; x
<width
; x
++)
781 for (y
=0; y
<height
; y
++)
784 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
786 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
787 !color_is_gray(*src_color
))
789 *src_color
= transform_color(*src_color
, color_matrix
);
791 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
793 *src_color
= transform_color(*src_color
, gray_matrix
);
800 if (attributes
->gamma_enabled
[type
] ||
801 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
805 if (!data
|| fmt
!= PixelFormat32bppARGB
)
806 return PixelFormat32bppARGB
;
808 if (attributes
->gamma_enabled
[type
])
809 gamma
= attributes
->gamma
[type
];
811 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
813 for (x
=0; x
<width
; x
++)
814 for (y
=0; y
<height
; y
++)
817 BYTE blue
, green
, red
;
818 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
820 blue
= *src_color
&0xff;
821 green
= (*src_color
>>8)&0xff;
822 red
= (*src_color
>>16)&0xff;
824 /* FIXME: We should probably use a table for this. */
825 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
826 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
827 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
829 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
836 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
837 * bitmap that contains all the pixels we may need to draw it. */
838 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
839 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
842 INT left
, top
, right
, bottom
;
844 switch (interpolation
)
846 case InterpolationModeHighQualityBilinear
:
847 case InterpolationModeHighQualityBicubic
:
848 /* FIXME: Include a greater range for the prefilter? */
849 case InterpolationModeBicubic
:
850 case InterpolationModeBilinear
:
851 left
= (INT
)(floorf(srcx
));
852 top
= (INT
)(floorf(srcy
));
853 right
= (INT
)(ceilf(srcx
+srcwidth
));
854 bottom
= (INT
)(ceilf(srcy
+srcheight
));
856 case InterpolationModeNearestNeighbor
:
858 left
= gdip_round(srcx
);
859 top
= gdip_round(srcy
);
860 right
= gdip_round(srcx
+srcwidth
);
861 bottom
= gdip_round(srcy
+srcheight
);
865 if (wrap
== WrapModeClamp
)
871 if (right
>= bitmap
->width
)
872 right
= bitmap
->width
-1;
873 if (bottom
>= bitmap
->height
)
874 bottom
= bitmap
->height
-1;
875 if (bottom
< top
|| right
< left
)
876 /* entirely outside image, just sample a pixel so we don't have to
877 * special-case this later */
878 left
= top
= right
= bottom
= 0;
882 /* In some cases we can make the rectangle smaller here, but the logic
883 * is hard to get right, and tiling suggests we're likely to use the
884 * entire source image. */
885 if (left
< 0 || right
>= bitmap
->width
)
888 right
= bitmap
->width
-1;
891 if (top
< 0 || bottom
>= bitmap
->height
)
894 bottom
= bitmap
->height
-1;
900 rect
->Width
= right
- left
+ 1;
901 rect
->Height
= bottom
- top
+ 1;
904 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
905 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
907 if (attributes
->wrap
== WrapModeClamp
)
909 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
910 return attributes
->outside_color
;
914 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
916 x
= width
*2 + x
% (width
* 2);
918 y
= height
*2 + y
% (height
* 2);
920 if (attributes
->wrap
& WrapModeTileFlipX
)
922 if ((x
/ width
) % 2 == 0)
925 x
= width
- 1 - x
% width
;
930 if (attributes
->wrap
& WrapModeTileFlipY
)
932 if ((y
/ height
) % 2 == 0)
935 y
= height
- 1 - y
% height
;
941 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
943 ERR("out of range pixel requested\n");
947 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
950 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
951 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
952 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
956 switch (interpolation
)
960 FIXME("Unimplemented interpolation %i\n", interpolation
);
962 case InterpolationModeBilinear
:
965 INT leftx
, rightx
, topy
, bottomy
;
966 ARGB topleft
, topright
, bottomleft
, bottomright
;
970 leftxf
= floorf(point
->X
);
972 rightx
= (INT
)ceilf(point
->X
);
973 topyf
= floorf(point
->Y
);
975 bottomy
= (INT
)ceilf(point
->Y
);
977 if (leftx
== rightx
&& topy
== bottomy
)
978 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
979 leftx
, topy
, attributes
);
981 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
982 leftx
, topy
, attributes
);
983 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
984 rightx
, topy
, attributes
);
985 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
986 leftx
, bottomy
, attributes
);
987 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
988 rightx
, bottomy
, attributes
);
990 x_offset
= point
->X
- leftxf
;
991 top
= blend_colors(topleft
, topright
, x_offset
);
992 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
994 return blend_colors(top
, bottom
, point
->Y
- topyf
);
996 case InterpolationModeNearestNeighbor
:
1002 case PixelOffsetModeNone
:
1003 case PixelOffsetModeHighSpeed
:
1007 case PixelOffsetModeHalf
:
1008 case PixelOffsetModeHighQuality
:
1012 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1013 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
1019 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
1021 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
1024 /* is_fill is TRUE if filling regions, FALSE for drawing primitives */
1025 static BOOL
brush_can_fill_path(GpBrush
*brush
, BOOL is_fill
)
1029 case BrushTypeSolidColor
:
1035 /* cannot draw semi-transparent colors */
1036 return (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000;
1039 case BrushTypeHatchFill
:
1041 GpHatch
*hatch
= (GpHatch
*)brush
;
1042 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
1043 ((hatch
->backcol
& 0xff000000) == 0xff000000);
1045 case BrushTypeLinearGradient
:
1046 case BrushTypeTextureFill
:
1047 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
1053 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
1057 case BrushTypeSolidColor
:
1059 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1060 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1065 /* partially transparent fill */
1067 SelectClipPath(graphics
->hdc
, RGN_AND
);
1068 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1070 HDC hdc
= CreateCompatibleDC(NULL
);
1074 SelectObject(hdc
, bmp
);
1075 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1083 /* else fall through */
1087 HBRUSH gdibrush
, old_brush
;
1089 gdibrush
= create_gdi_brush(brush
);
1090 if (!gdibrush
) return;
1092 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1093 FillPath(graphics
->hdc
);
1094 SelectObject(graphics
->hdc
, old_brush
);
1095 DeleteObject(gdibrush
);
1101 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1105 case BrushTypeSolidColor
:
1106 case BrushTypeHatchFill
:
1107 case BrushTypeLinearGradient
:
1108 case BrushTypeTextureFill
:
1109 case BrushTypePathGradient
:
1116 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1117 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1121 case BrushTypeSolidColor
:
1124 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1125 for (x
=0; x
<fill_area
->Width
; x
++)
1126 for (y
=0; y
<fill_area
->Height
; y
++)
1127 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1130 case BrushTypeHatchFill
:
1133 GpHatch
*fill
= (GpHatch
*)brush
;
1134 const char *hatch_data
;
1136 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1137 return NotImplemented
;
1139 for (x
=0; x
<fill_area
->Width
; x
++)
1140 for (y
=0; y
<fill_area
->Height
; y
++)
1144 /* FIXME: Account for the rendering origin */
1145 hx
= (x
+ fill_area
->X
) % 8;
1146 hy
= (y
+ fill_area
->Y
) % 8;
1148 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1149 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1151 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1156 case BrushTypeLinearGradient
:
1158 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1159 GpPointF draw_points
[3];
1163 draw_points
[0].X
= fill_area
->X
;
1164 draw_points
[0].Y
= fill_area
->Y
;
1165 draw_points
[1].X
= fill_area
->X
+1;
1166 draw_points
[1].Y
= fill_area
->Y
;
1167 draw_points
[2].X
= fill_area
->X
;
1168 draw_points
[2].Y
= fill_area
->Y
+1;
1170 /* Transform the points to a co-ordinate space where X is the point's
1171 * position in the gradient, 0.0 being the start point and 1.0 the
1173 stat
= gdip_transform_points(graphics
, CoordinateSpaceWorld
,
1174 WineCoordinateSpaceGdiDevice
, draw_points
, 3);
1178 GpMatrix world_to_gradient
= fill
->transform
;
1180 stat
= GdipInvertMatrix(&world_to_gradient
);
1182 stat
= GdipTransformMatrixPoints(&world_to_gradient
, draw_points
, 3);
1187 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1188 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1190 for (y
=0; y
<fill_area
->Height
; y
++)
1192 for (x
=0; x
<fill_area
->Width
; x
++)
1194 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1196 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1203 case BrushTypeTextureFill
:
1205 GpTexture
*fill
= (GpTexture
*)brush
;
1206 GpPointF draw_points
[3];
1213 if (fill
->image
->type
!= ImageTypeBitmap
)
1215 FIXME("metafile texture brushes not implemented\n");
1216 return NotImplemented
;
1219 bitmap
= (GpBitmap
*)fill
->image
;
1220 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1222 src_area
.X
= src_area
.Y
= 0;
1223 src_area
.Width
= bitmap
->width
;
1224 src_area
.Height
= bitmap
->height
;
1226 draw_points
[0].X
= fill_area
->X
;
1227 draw_points
[0].Y
= fill_area
->Y
;
1228 draw_points
[1].X
= fill_area
->X
+1;
1229 draw_points
[1].Y
= fill_area
->Y
;
1230 draw_points
[2].X
= fill_area
->X
;
1231 draw_points
[2].Y
= fill_area
->Y
+1;
1233 /* Transform the points to the co-ordinate space of the bitmap. */
1234 stat
= gdip_transform_points(graphics
, CoordinateSpaceWorld
,
1235 WineCoordinateSpaceGdiDevice
, draw_points
, 3);
1239 GpMatrix world_to_texture
= fill
->transform
;
1241 stat
= GdipInvertMatrix(&world_to_texture
);
1243 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1246 if (stat
== Ok
&& !fill
->bitmap_bits
)
1248 BitmapData lockeddata
;
1250 fill
->bitmap_bits
= heap_alloc_zero(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1251 if (!fill
->bitmap_bits
)
1256 lockeddata
.Width
= bitmap
->width
;
1257 lockeddata
.Height
= bitmap
->height
;
1258 lockeddata
.Stride
= src_stride
;
1259 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1260 lockeddata
.Scan0
= fill
->bitmap_bits
;
1262 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1263 PixelFormat32bppARGB
, &lockeddata
);
1267 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1270 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1271 bitmap
->width
, bitmap
->height
,
1272 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
1276 heap_free(fill
->bitmap_bits
);
1277 fill
->bitmap_bits
= NULL
;
1283 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1284 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1285 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1286 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1288 for (y
=0; y
<fill_area
->Height
; y
++)
1290 for (x
=0; x
<fill_area
->Width
; x
++)
1293 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1294 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1296 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1297 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1298 &point
, fill
->imageattributes
, graphics
->interpolation
,
1299 graphics
->pixeloffset
);
1306 case BrushTypePathGradient
:
1308 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1310 GpMatrix world_to_device
;
1312 int i
, figure_start
=0;
1313 GpPointF start_point
, end_point
, center_point
;
1315 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1316 INT min_y
, max_y
, min_x
, max_x
;
1319 static BOOL transform_fixme_once
;
1321 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1325 FIXME("path gradient focus not implemented\n");
1332 FIXME("path gradient gamma correction not implemented\n");
1335 if (fill
->blendcount
)
1339 FIXME("path gradient blend not implemented\n");
1342 if (fill
->pblendcount
)
1346 FIXME("path gradient preset blend not implemented\n");
1349 if (!transform_fixme_once
)
1351 BOOL is_identity
=TRUE
;
1352 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1355 FIXME("path gradient transform not implemented\n");
1356 transform_fixme_once
= TRUE
;
1360 stat
= GdipClonePath(fill
->path
, &flat_path
);
1365 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
1366 CoordinateSpaceWorld
, &world_to_device
);
1369 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1373 center_point
= fill
->center
;
1374 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1378 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1383 GdipDeletePath(flat_path
);
1387 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1389 int start_center_line
=0, end_center_line
=0;
1390 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1391 REAL center_distance
;
1392 ARGB start_color
, end_color
;
1395 type
= flat_path
->pathdata
.Types
[i
];
1397 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1400 start_point
= flat_path
->pathdata
.Points
[i
];
1402 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1404 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1406 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1407 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1409 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1411 end_point
= flat_path
->pathdata
.Points
[i
+1];
1412 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1417 outer_color
= start_color
;
1419 min_yf
= center_point
.Y
;
1420 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1421 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1423 if (min_yf
< fill_area
->Y
)
1424 min_y
= fill_area
->Y
;
1426 min_y
= (INT
)ceil(min_yf
);
1428 max_yf
= center_point
.Y
;
1429 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1430 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1432 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1433 max_y
= fill_area
->Y
+ fill_area
->Height
;
1435 max_y
= (INT
)ceil(max_yf
);
1437 dy
= end_point
.Y
- start_point
.Y
;
1438 dx
= end_point
.X
- start_point
.X
;
1440 /* This is proportional to the distance from start-end line to center point. */
1441 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1442 dx
* (center_point
.Y
- start_point
.Y
);
1444 for (y
=min_y
; y
<max_y
; y
++)
1448 if (!seen_start
&& yf
>= start_point
.Y
)
1451 start_center_line
^= 1;
1453 if (!seen_end
&& yf
>= end_point
.Y
)
1456 end_center_line
^= 1;
1458 if (!seen_center
&& yf
>= center_point
.Y
)
1461 start_center_line
^= 1;
1462 end_center_line
^= 1;
1465 if (start_center_line
)
1466 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1468 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1470 if (end_center_line
)
1471 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1473 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1475 if (line1_xf
< line2_xf
)
1477 min_x
= (INT
)ceil(line1_xf
);
1478 max_x
= (INT
)ceil(line2_xf
);
1482 min_x
= (INT
)ceil(line2_xf
);
1483 max_x
= (INT
)ceil(line1_xf
);
1486 if (min_x
< fill_area
->X
)
1487 min_x
= fill_area
->X
;
1488 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1489 max_x
= fill_area
->X
+ fill_area
->Width
;
1491 for (x
=min_x
; x
<max_x
; x
++)
1496 if (start_color
!= end_color
)
1498 REAL blend_amount
, pdy
, pdx
;
1499 pdy
= yf
- center_point
.Y
;
1500 pdx
= xf
- center_point
.X
;
1502 if (fabs(pdx
) <= 0.001 && fabs(pdy
) <= 0.001)
1504 /* Too close to center point, don't try to calculate outer color */
1505 outer_color
= start_color
;
1509 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1510 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1514 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1515 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1517 distance
= distance
/ center_distance
;
1519 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1520 blend_colors(outer_color
, fill
->centercolor
, distance
);
1525 GdipDeletePath(flat_path
);
1529 return NotImplemented
;
1533 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1534 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1535 * should not be called on an hdc that has a path you care about. */
1536 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1537 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1539 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1541 HBRUSH brush
= NULL
;
1543 PointF ptf
[4], *custptf
= NULL
;
1544 POINT pt
[4], *custpt
= NULL
;
1546 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1551 if((x1
== x2
) && (y1
== y2
))
1554 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1556 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1558 brush
= CreateSolidBrush(color
);
1559 lb
.lbStyle
= BS_SOLID
;
1562 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1563 PS_JOIN_MITER
, 1, &lb
, 0,
1565 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1566 oldpen
= SelectObject(graphics
->hdc
, pen
);
1573 case LineCapSquareAnchor
:
1574 case LineCapDiamondAnchor
:
1575 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1576 if(cap
== LineCapDiamondAnchor
){
1577 dsmall
= cos(theta
+ M_PI_2
) * size
;
1578 dbig
= sin(theta
+ M_PI_2
) * size
;
1581 dsmall
= cos(theta
+ M_PI_4
) * size
;
1582 dbig
= sin(theta
+ M_PI_4
) * size
;
1585 ptf
[0].X
= x2
- dsmall
;
1586 ptf
[1].X
= x2
+ dbig
;
1588 ptf
[0].Y
= y2
- dbig
;
1589 ptf
[3].Y
= y2
+ dsmall
;
1591 ptf
[1].Y
= y2
- dsmall
;
1592 ptf
[2].Y
= y2
+ dbig
;
1594 ptf
[3].X
= x2
- dbig
;
1595 ptf
[2].X
= x2
+ dsmall
;
1597 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1599 round_points(pt
, ptf
, 3);
1601 Polygon(graphics
->hdc
, pt
, 4);
1604 case LineCapArrowAnchor
:
1605 size
= size
* 4.0 / sqrt(3.0);
1607 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1608 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1613 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1614 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1622 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1624 round_points(pt
, ptf
, 3);
1626 Polygon(graphics
->hdc
, pt
, 3);
1629 case LineCapRoundAnchor
:
1630 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1637 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1639 round_points(pt
, ptf
, 3);
1641 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1644 case LineCapTriangle
:
1646 dx
= cos(M_PI_2
+ theta
) * size
;
1647 dy
= sin(M_PI_2
+ theta
) * size
;
1654 dx
= cos(theta
) * size
;
1655 dy
= sin(theta
) * size
;
1660 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1662 round_points(pt
, ptf
, 3);
1664 Polygon(graphics
->hdc
, pt
, 3);
1668 dx
= dy
= size
/ 2.0;
1675 dx
= -cos(M_PI_2
+ theta
) * size
;
1676 dy
= -sin(M_PI_2
+ theta
) * size
;
1683 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1685 round_points(pt
, ptf
, 3);
1687 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1688 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1695 count
= custom
->pathdata
.Count
;
1696 custptf
= heap_alloc_zero(count
* sizeof(PointF
));
1697 custpt
= heap_alloc_zero(count
* sizeof(POINT
));
1698 tp
= heap_alloc_zero(count
);
1700 if(!custptf
|| !custpt
|| !tp
)
1703 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1705 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1706 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1707 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1709 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1710 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1712 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1714 round_points(pt
, ptf
, 3);
1716 for(i
= 0; i
< count
; i
++)
1717 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1720 BeginPath(graphics
->hdc
);
1721 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1722 EndPath(graphics
->hdc
);
1723 StrokeAndFillPath(graphics
->hdc
);
1726 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1738 SelectObject(graphics
->hdc
, oldbrush
);
1739 SelectObject(graphics
->hdc
, oldpen
);
1740 DeleteObject(brush
);
1745 /* Shortens the line by the given percent by changing x2, y2.
1746 * If percent is > 1.0 then the line will change direction.
1747 * If percent is negative it can lengthen the line. */
1748 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1750 REAL dist
, theta
, dx
, dy
;
1752 if((y1
== *y2
) && (x1
== *x2
))
1755 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1756 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1757 dx
= cos(theta
) * dist
;
1758 dy
= sin(theta
) * dist
;
1764 /* Shortens the line by the given amount by changing x2, y2.
1765 * If the amount is greater than the distance, the line will become length 0.
1766 * If the amount is negative, it can lengthen the line. */
1767 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1769 REAL dx
, dy
, percent
;
1773 if(dx
== 0 && dy
== 0)
1776 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1783 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1786 /* Conducts a linear search to find the bezier points that will back off
1787 * the endpoint of the curve by a distance of amt. Linear search works
1788 * better than binary in this case because there are multiple solutions,
1789 * and binary searches often find a bad one. I don't think this is what
1790 * Windows does but short of rendering the bezier without GDI's help it's
1791 * the best we can do. If rev then work from the start of the passed points
1792 * instead of the end. */
1793 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1796 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1797 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1806 origx
= pt
[fourth
].X
;
1807 origy
= pt
[fourth
].Y
;
1808 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1810 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1811 /* reset bezier points to original values */
1812 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1813 /* Perform magic on bezier points. Order is important here.*/
1814 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1815 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1816 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1817 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1818 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1819 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1821 dx
= pt
[fourth
].X
- origx
;
1822 dy
= pt
[fourth
].Y
- origy
;
1824 diff
= sqrt(dx
* dx
+ dy
* dy
);
1825 percent
+= 0.0005 * amt
;
1829 /* Draws a combination of bezier curves and lines between points. */
1830 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1831 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1833 POINT
*pti
= heap_alloc_zero(count
* sizeof(POINT
));
1834 BYTE
*tp
= heap_alloc_zero(count
);
1835 GpPointF
*ptcopy
= heap_alloc_zero(count
* sizeof(GpPointF
));
1837 GpStatus status
= GenericError
;
1843 if(!pti
|| !tp
|| !ptcopy
){
1844 status
= OutOfMemory
;
1848 for(i
= 1; i
< count
; i
++){
1849 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1850 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1851 || !(types
[i
+ 2] & PathPointTypeBezier
)){
1852 ERR("Bad bezier points\n");
1859 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1861 /* If we are drawing caps, go through the points and adjust them accordingly,
1862 * and draw the caps. */
1864 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1865 case PathPointTypeBezier
:
1866 if(pen
->endcap
== LineCapArrowAnchor
)
1867 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1868 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1869 shorten_bezier_amt(&ptcopy
[count
- 4],
1870 pen
->width
* pen
->customend
->inset
, FALSE
);
1872 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1873 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1874 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1875 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1878 case PathPointTypeLine
:
1879 if(pen
->endcap
== LineCapArrowAnchor
)
1880 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1881 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1883 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1884 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1885 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1886 pen
->customend
->inset
* pen
->width
);
1888 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1889 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1894 ERR("Bad path last point\n");
1898 /* Find start of points */
1899 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1900 == PathPointTypeStart
); j
++);
1902 switch(types
[j
] & PathPointTypePathTypeMask
){
1903 case PathPointTypeBezier
:
1904 if(pen
->startcap
== LineCapArrowAnchor
)
1905 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1906 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1907 shorten_bezier_amt(&ptcopy
[j
- 1],
1908 pen
->width
* pen
->customstart
->inset
, TRUE
);
1910 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1911 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1912 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1913 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1916 case PathPointTypeLine
:
1917 if(pen
->startcap
== LineCapArrowAnchor
)
1918 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1919 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1921 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1922 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1923 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1924 pen
->customstart
->inset
* pen
->width
);
1926 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1927 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1932 ERR("Bad path points\n");
1937 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptcopy
, count
);
1939 round_points(pti
, ptcopy
, count
);
1941 for(i
= 0; i
< count
; i
++){
1942 tp
[i
] = convert_path_point_type(types
[i
]);
1945 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1957 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1961 BeginPath(graphics
->hdc
);
1962 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1963 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1964 EndPath(graphics
->hdc
);
1968 typedef enum GraphicsContainerType
{
1971 } GraphicsContainerType
;
1973 typedef struct _GraphicsContainerItem
{
1975 GraphicsContainer contid
;
1976 GraphicsContainerType type
;
1978 SmoothingMode smoothing
;
1979 CompositingQuality compqual
;
1980 InterpolationMode interpolation
;
1981 CompositingMode compmode
;
1982 TextRenderingHint texthint
;
1985 PixelOffsetMode pixeloffset
;
1987 GpMatrix worldtrans
;
1989 INT origin_x
, origin_y
;
1990 } GraphicsContainerItem
;
1992 static GpStatus
init_container(GraphicsContainerItem
** container
,
1993 GDIPCONST GpGraphics
* graphics
, GraphicsContainerType type
){
1996 *container
= heap_alloc_zero(sizeof(GraphicsContainerItem
));
2000 (*container
)->contid
= graphics
->contid
+ 1;
2001 (*container
)->type
= type
;
2003 (*container
)->smoothing
= graphics
->smoothing
;
2004 (*container
)->compqual
= graphics
->compqual
;
2005 (*container
)->interpolation
= graphics
->interpolation
;
2006 (*container
)->compmode
= graphics
->compmode
;
2007 (*container
)->texthint
= graphics
->texthint
;
2008 (*container
)->scale
= graphics
->scale
;
2009 (*container
)->unit
= graphics
->unit
;
2010 (*container
)->textcontrast
= graphics
->textcontrast
;
2011 (*container
)->pixeloffset
= graphics
->pixeloffset
;
2012 (*container
)->origin_x
= graphics
->origin_x
;
2013 (*container
)->origin_y
= graphics
->origin_y
;
2014 (*container
)->worldtrans
= graphics
->worldtrans
;
2016 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
2018 heap_free(*container
);
2026 static void delete_container(GraphicsContainerItem
* container
)
2028 GdipDeleteRegion(container
->clip
);
2029 heap_free(container
);
2032 static GpStatus
restore_container(GpGraphics
* graphics
,
2033 GDIPCONST GraphicsContainerItem
* container
){
2037 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2038 if(sts
!= Ok
) return sts
;
2040 graphics
->worldtrans
= container
->worldtrans
;
2042 GdipDeleteRegion(graphics
->clip
);
2043 graphics
->clip
= newClip
;
2045 graphics
->contid
= container
->contid
- 1;
2047 graphics
->smoothing
= container
->smoothing
;
2048 graphics
->compqual
= container
->compqual
;
2049 graphics
->interpolation
= container
->interpolation
;
2050 graphics
->compmode
= container
->compmode
;
2051 graphics
->texthint
= container
->texthint
;
2052 graphics
->scale
= container
->scale
;
2053 graphics
->unit
= container
->unit
;
2054 graphics
->textcontrast
= container
->textcontrast
;
2055 graphics
->pixeloffset
= container
->pixeloffset
;
2056 graphics
->origin_x
= container
->origin_x
;
2057 graphics
->origin_y
= container
->origin_y
;
2062 static GpStatus
get_graphics_device_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2068 if(graphics
->hwnd
) {
2069 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2070 return GenericError
;
2072 rect
->X
= wnd_rect
.left
;
2073 rect
->Y
= wnd_rect
.top
;
2074 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2075 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2076 }else if (graphics
->image
){
2077 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2078 if (stat
== Ok
&& unit
!= UnitPixel
)
2079 FIXME("need to convert from unit %i\n", unit
);
2080 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2087 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2088 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2090 rect
->Width
= bmp
.bmWidth
;
2091 rect
->Height
= bmp
.bmHeight
;
2102 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2103 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2109 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2111 GpStatus stat
= get_graphics_device_bounds(graphics
, rect
);
2113 if (stat
== Ok
&& graphics
->hdc
)
2115 GpPointF points
[4], min_point
, max_point
;
2118 points
[0].X
= points
[2].X
= rect
->X
;
2119 points
[0].Y
= points
[1].Y
= rect
->Y
;
2120 points
[1].X
= points
[3].X
= rect
->X
+ rect
->Width
;
2121 points
[2].Y
= points
[3].Y
= rect
->Y
+ rect
->Height
;
2123 gdip_transform_points(graphics
, CoordinateSpaceDevice
, WineCoordinateSpaceGdiDevice
, points
, 4);
2125 min_point
= max_point
= points
[0];
2129 if (points
[i
].X
< min_point
.X
) min_point
.X
= points
[i
].X
;
2130 if (points
[i
].Y
< min_point
.Y
) min_point
.Y
= points
[i
].Y
;
2131 if (points
[i
].X
> max_point
.X
) max_point
.X
= points
[i
].X
;
2132 if (points
[i
].Y
> max_point
.Y
) max_point
.Y
= points
[i
].Y
;
2135 rect
->X
= min_point
.X
;
2136 rect
->Y
= min_point
.Y
;
2137 rect
->Width
= max_point
.X
- min_point
.X
;
2138 rect
->Height
= max_point
.Y
- min_point
.Y
;
2144 /* on success, rgn will contain the region of the graphics object which
2145 * is visible after clipping has been applied */
2146 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2152 /* Ignore graphics image bounds for metafiles */
2153 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2154 return GdipCombineRegionRegion(rgn
, graphics
->clip
, CombineModeReplace
);
2156 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2159 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2162 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2165 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2168 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2171 GdipDeleteRegion(tmp
);
2175 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2179 if (font
->unit
== UnitPixel
)
2181 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2185 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2186 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2188 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2191 lf
->lfHeight
= -(height
+ 0.5);
2193 lf
->lfEscapement
= 0;
2194 lf
->lfOrientation
= 0;
2195 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2196 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2197 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2198 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2199 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2200 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2201 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2202 lf
->lfQuality
= DEFAULT_QUALITY
;
2203 lf
->lfPitchAndFamily
= 0;
2204 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2207 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2208 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2209 GDIPCONST GpMatrix
*matrix
)
2211 HDC hdc
= CreateCompatibleDC(0);
2213 REAL angle
, rel_width
, rel_height
, font_height
;
2215 HFONT unscaled_font
;
2216 TEXTMETRICW textmet
;
2218 if (font
->unit
== UnitPixel
|| font
->unit
== UnitWorld
)
2219 font_height
= font
->emSize
;
2222 REAL unit_scale
, res
;
2224 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2225 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2227 font_height
= font
->emSize
* unit_scale
;
2238 GpMatrix xform
= *matrix
;
2239 GdipTransformMatrixPoints(&xform
, pt
, 3);
2242 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
2243 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2244 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2245 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2246 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2247 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2249 get_log_fontW(font
, graphics
, &lfw
);
2250 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2251 unscaled_font
= CreateFontIndirectW(&lfw
);
2253 SelectObject(hdc
, unscaled_font
);
2254 GetTextMetricsW(hdc
, &textmet
);
2256 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2257 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2259 *hfont
= CreateFontIndirectW(&lfw
);
2262 DeleteObject(unscaled_font
);
2265 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2267 TRACE("(%p, %p)\n", hdc
, graphics
);
2269 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2272 static void get_gdi_transform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2276 if (graphics
->hdc
== NULL
)
2278 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2282 GetTransform(graphics
->hdc
, 0x204, &xform
);
2283 GdipSetMatrixElements(matrix
, xform
.eM11
, xform
.eM12
, xform
.eM21
, xform
.eM22
, xform
.eDx
, xform
.eDy
);
2286 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2292 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2295 FIXME("Don't know how to handle parameter hDevice\n");
2300 if(graphics
== NULL
)
2301 return InvalidParameter
;
2303 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2304 if(!*graphics
) return OutOfMemory
;
2306 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2308 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2309 heap_free(*graphics
);
2313 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2314 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2315 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2317 (*graphics
)->alpha_hdc
= 1;
2320 (*graphics
)->hdc
= hdc
;
2321 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2322 (*graphics
)->owndc
= FALSE
;
2323 (*graphics
)->smoothing
= SmoothingModeDefault
;
2324 (*graphics
)->compqual
= CompositingQualityDefault
;
2325 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2326 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2327 (*graphics
)->compmode
= CompositingModeSourceOver
;
2328 (*graphics
)->unit
= UnitDisplay
;
2329 (*graphics
)->scale
= 1.0;
2330 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2331 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2332 (*graphics
)->busy
= FALSE
;
2333 (*graphics
)->textcontrast
= 4;
2334 list_init(&(*graphics
)->containers
);
2335 (*graphics
)->contid
= 0;
2336 get_gdi_transform(*graphics
, &(*graphics
)->gdi_transform
);
2338 (*graphics
)->gdi_clip
= CreateRectRgn(0,0,0,0);
2339 if (!GetClipRgn(hdc
, (*graphics
)->gdi_clip
))
2341 DeleteObject((*graphics
)->gdi_clip
);
2342 (*graphics
)->gdi_clip
= NULL
;
2345 TRACE("<-- %p\n", *graphics
);
2350 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2354 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2355 if(!*graphics
) return OutOfMemory
;
2357 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2358 GdipSetMatrixElements(&(*graphics
)->gdi_transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2360 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2361 heap_free(*graphics
);
2365 (*graphics
)->hdc
= NULL
;
2366 (*graphics
)->hwnd
= NULL
;
2367 (*graphics
)->owndc
= FALSE
;
2368 (*graphics
)->image
= image
;
2369 /* We have to store the image type here because the image may be freed
2370 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2371 (*graphics
)->image_type
= image
->type
;
2372 (*graphics
)->smoothing
= SmoothingModeDefault
;
2373 (*graphics
)->compqual
= CompositingQualityDefault
;
2374 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2375 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2376 (*graphics
)->compmode
= CompositingModeSourceOver
;
2377 (*graphics
)->unit
= UnitDisplay
;
2378 (*graphics
)->scale
= 1.0;
2379 (*graphics
)->xres
= image
->xres
;
2380 (*graphics
)->yres
= image
->yres
;
2381 (*graphics
)->busy
= FALSE
;
2382 (*graphics
)->textcontrast
= 4;
2383 list_init(&(*graphics
)->containers
);
2384 (*graphics
)->contid
= 0;
2386 TRACE("<-- %p\n", *graphics
);
2391 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2396 TRACE("(%p, %p)\n", hwnd
, graphics
);
2400 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2402 ReleaseDC(hwnd
, hdc
);
2406 (*graphics
)->hwnd
= hwnd
;
2407 (*graphics
)->owndc
= TRUE
;
2412 /* FIXME: no icm handling */
2413 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2415 TRACE("(%p, %p)\n", hwnd
, graphics
);
2417 return GdipCreateFromHWND(hwnd
, graphics
);
2420 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2421 UINT access
, IStream
**stream
)
2426 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2428 if(!stream
|| !filename
)
2429 return InvalidParameter
;
2431 if(access
& GENERIC_WRITE
)
2432 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2433 else if(access
& GENERIC_READ
)
2434 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2436 return InvalidParameter
;
2438 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2440 return hresult_to_status(ret
);
2443 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2445 GraphicsContainerItem
*cont
, *next
;
2447 TRACE("(%p)\n", graphics
);
2449 if(!graphics
) return InvalidParameter
;
2450 if(graphics
->busy
) return ObjectBusy
;
2452 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2454 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2460 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2462 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2463 list_remove(&cont
->entry
);
2464 delete_container(cont
);
2467 GdipDeleteRegion(graphics
->clip
);
2469 DeleteObject(graphics
->gdi_clip
);
2471 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2472 * do otherwise, but we can't have that in the test suite because it means
2473 * accessing freed memory. */
2474 graphics
->busy
= TRUE
;
2476 heap_free(graphics
);
2481 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2482 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2487 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2488 width
, height
, startAngle
, sweepAngle
);
2490 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2491 return InvalidParameter
;
2496 status
= GdipCreatePath(FillModeAlternate
, &path
);
2497 if (status
!= Ok
) return status
;
2499 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2501 status
= GdipDrawPath(graphics
, pen
, path
);
2503 GdipDeletePath(path
);
2507 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2508 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2510 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2511 width
, height
, startAngle
, sweepAngle
);
2513 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2516 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2517 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2521 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2522 x2
, y2
, x3
, y3
, x4
, y4
);
2524 if(!graphics
|| !pen
)
2525 return InvalidParameter
;
2538 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2541 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2542 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2544 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2545 x2
, y2
, x3
, y3
, x4
, y4
);
2547 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2550 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2551 GDIPCONST GpPointF
*points
, INT count
)
2556 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2558 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2559 return InvalidParameter
;
2564 status
= GdipCreatePath(FillModeAlternate
, &path
);
2565 if (status
!= Ok
) return status
;
2567 status
= GdipAddPathBeziers(path
, points
, count
);
2569 status
= GdipDrawPath(graphics
, pen
, path
);
2571 GdipDeletePath(path
);
2575 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2576 GDIPCONST GpPoint
*points
, INT count
)
2582 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2584 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2585 return InvalidParameter
;
2590 pts
= heap_alloc_zero(sizeof(GpPointF
) * count
);
2594 for(i
= 0; i
< count
; i
++){
2595 pts
[i
].X
= (REAL
)points
[i
].X
;
2596 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2599 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2606 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2607 GDIPCONST GpPointF
*points
, INT count
)
2609 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2611 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2614 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2615 GDIPCONST GpPoint
*points
, INT count
)
2617 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2619 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2622 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2623 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2628 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2630 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2631 return InvalidParameter
;
2636 status
= GdipCreatePath(FillModeAlternate
, &path
);
2637 if (status
!= Ok
) return status
;
2639 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2641 status
= GdipDrawPath(graphics
, pen
, path
);
2643 GdipDeletePath(path
);
2648 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2649 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2655 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2657 if(!points
|| count
<= 0)
2658 return InvalidParameter
;
2660 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2664 for(i
= 0; i
< count
; i
++){
2665 ptf
[i
].X
= (REAL
)points
[i
].X
;
2666 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2669 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2676 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2677 GDIPCONST GpPointF
*points
, INT count
)
2679 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2681 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2684 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2685 GDIPCONST GpPoint
*points
, INT count
)
2691 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2694 return InvalidParameter
;
2696 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2700 for(i
= 0; i
< count
; i
++){
2701 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2702 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2705 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2711 /* Approximates cardinal spline with Bezier curves. */
2712 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2713 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2718 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2720 if(!graphics
|| !pen
)
2721 return InvalidParameter
;
2727 return InvalidParameter
;
2729 status
= GdipCreatePath(FillModeAlternate
, &path
);
2730 if (status
!= Ok
) return status
;
2732 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2734 status
= GdipDrawPath(graphics
, pen
, path
);
2736 GdipDeletePath(path
);
2740 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2741 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2747 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2750 return InvalidParameter
;
2752 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2756 for(i
= 0; i
< count
; i
++){
2757 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2758 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2761 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2767 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2768 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2771 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2773 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2774 return InvalidParameter
;
2777 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2780 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2781 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2784 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2790 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2791 return InvalidParameter
;
2794 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2797 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2798 REAL y
, REAL width
, REAL height
)
2803 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2805 if(!graphics
|| !pen
)
2806 return InvalidParameter
;
2811 status
= GdipCreatePath(FillModeAlternate
, &path
);
2812 if (status
!= Ok
) return status
;
2814 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2816 status
= GdipDrawPath(graphics
, pen
, path
);
2818 GdipDeletePath(path
);
2822 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2823 INT y
, INT width
, INT height
)
2825 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2827 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2831 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2835 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2837 if(!graphics
|| !image
)
2838 return InvalidParameter
;
2840 GdipGetImageWidth(image
, &width
);
2841 GdipGetImageHeight(image
, &height
);
2843 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2844 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2847 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2850 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2852 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2855 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2856 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2860 REAL scale_x
, scale_y
, width
, height
;
2862 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2864 if (!graphics
|| !image
) return InvalidParameter
;
2866 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2867 scale_x
*= graphics
->xres
/ image
->xres
;
2868 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2869 scale_y
*= graphics
->yres
/ image
->yres
;
2870 width
= srcwidth
* scale_x
;
2871 height
= srcheight
* scale_y
;
2873 points
[0].X
= points
[2].X
= x
;
2874 points
[0].Y
= points
[1].Y
= y
;
2875 points
[1].X
= x
+ width
;
2876 points
[2].Y
= y
+ height
;
2878 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2879 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2882 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2883 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2886 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2889 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2890 GDIPCONST GpPointF
*dstpoints
, INT count
)
2894 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2897 return InvalidParameter
;
2899 GdipGetImageWidth(image
, &width
);
2900 GdipGetImageHeight(image
, &height
);
2902 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2903 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2906 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2907 GDIPCONST GpPoint
*dstpoints
, INT count
)
2911 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2913 if (count
!= 3 || !dstpoints
)
2914 return InvalidParameter
;
2916 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2917 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2918 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2919 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2920 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2921 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2923 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2926 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2927 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2929 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2933 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2934 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2935 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2936 DrawImageAbort callback
, VOID
* callbackData
)
2942 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2943 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2947 return NotImplemented
;
2949 if(!graphics
|| !image
|| !points
|| count
!= 3)
2950 return InvalidParameter
;
2952 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2953 debugstr_pointf(&points
[2]));
2955 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2957 return METAFILE_DrawImagePointsRect((GpMetafile
*)graphics
->image
,
2958 image
, points
, count
, srcx
, srcy
, srcwidth
, srcheight
,
2959 srcUnit
, imageAttributes
, callback
, callbackData
);
2962 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2964 /* Ensure source width/height is positive */
2967 GpPointF tmp
= ptf
[1];
2968 srcx
= srcx
+ srcwidth
;
2969 srcwidth
= -srcwidth
;
2970 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2971 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2978 GpPointF tmp
= ptf
[2];
2979 srcy
= srcy
+ srcheight
;
2980 srcheight
= -srcheight
;
2981 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
2982 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
2987 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2988 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2989 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
2991 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 4);
2992 round_points(pti
, ptf
, 4);
2994 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2995 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2997 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2998 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2999 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
3000 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
3001 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
3003 if (image
->type
== ImageTypeBitmap
)
3005 GpBitmap
* bitmap
= (GpBitmap
*)image
;
3006 BOOL do_resampling
= FALSE
;
3007 BOOL use_software
= FALSE
;
3009 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
3010 graphics
->xres
, graphics
->yres
,
3011 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
3012 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
3013 imageAttributes
? imageAttributes
->outside_color
: 0);
3015 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
3016 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
3017 srcx
< 0 || srcy
< 0 ||
3018 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
3019 do_resampling
= TRUE
;
3021 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
3022 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
3023 use_software
= TRUE
;
3028 GpRectF graphics_bounds
;
3030 int i
, x
, y
, src_stride
, dst_stride
;
3031 GpMatrix dst_to_src
;
3032 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
3033 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
3034 BitmapData lockeddata
;
3035 InterpolationMode interpolation
= graphics
->interpolation
;
3036 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
3037 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3038 REAL x_dx
, x_dy
, y_dx
, y_dy
;
3039 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
3041 if (!imageAttributes
)
3042 imageAttributes
= &defaultImageAttributes
;
3044 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3045 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3048 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3049 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3050 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3051 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3054 stat
= get_graphics_device_bounds(graphics
, &graphics_bounds
);
3055 if (stat
!= Ok
) return stat
;
3057 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
3058 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
3059 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
3060 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
3062 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
3064 if (IsRectEmpty(&dst_area
)) return Ok
;
3066 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3067 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3068 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3069 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3070 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3071 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3073 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
3075 stat
= GdipInvertMatrix(&dst_to_src
);
3076 if (stat
!= Ok
) return stat
;
3080 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3081 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3085 /* Make sure src_area is equal in size to dst_area. */
3086 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
3087 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
3088 src_area
.Width
= dst_area
.right
- dst_area
.left
;
3089 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
3092 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3094 src_data
= heap_alloc_zero(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3097 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3099 /* Read the bits we need from the source bitmap into a compatible buffer. */
3100 lockeddata
.Width
= src_area
.Width
;
3101 lockeddata
.Height
= src_area
.Height
;
3102 lockeddata
.Stride
= src_stride
;
3103 lockeddata
.Scan0
= src_data
;
3104 if (!do_resampling
&& bitmap
->format
== PixelFormat32bppPARGB
)
3105 lockeddata
.PixelFormat
= apply_image_attributes(imageAttributes
, NULL
, 0, 0, 0, ColorAdjustTypeBitmap
, bitmap
->format
);
3107 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3109 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3110 lockeddata
.PixelFormat
, &lockeddata
);
3113 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3117 heap_free(src_data
);
3121 apply_image_attributes(imageAttributes
, src_data
,
3122 src_area
.Width
, src_area
.Height
,
3123 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
3127 /* Transform the bits as needed to the destination. */
3128 dst_data
= dst_dyn_data
= heap_alloc_zero(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3131 heap_free(src_data
);
3135 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3137 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3139 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3140 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3141 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3142 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3144 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3146 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3148 GpPointF src_pointf
;
3151 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3152 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3154 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3156 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3157 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3158 imageAttributes
, interpolation
, offset_mode
);
3166 dst_data
= src_data
;
3167 dst_stride
= src_stride
;
3170 gdi_transform_acquire(graphics
);
3172 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3173 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
,
3174 lockeddata
.PixelFormat
);
3176 gdi_transform_release(graphics
);
3178 heap_free(src_data
);
3180 heap_free(dst_dyn_data
);
3187 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3188 HBITMAP hbitmap
, old_hbm
=NULL
;
3192 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3193 bitmap
->format
== PixelFormat24bppRGB
||
3194 bitmap
->format
== PixelFormat32bppRGB
||
3195 bitmap
->format
== PixelFormat32bppPARGB
))
3197 BITMAPINFOHEADER bih
;
3199 PixelFormat dst_format
;
3201 /* we can't draw a bitmap of this format directly */
3202 hdc
= CreateCompatibleDC(0);
3206 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3207 bih
.biWidth
= bitmap
->width
;
3208 bih
.biHeight
= -bitmap
->height
;
3210 bih
.biBitCount
= 32;
3211 bih
.biCompression
= BI_RGB
;
3212 bih
.biSizeImage
= 0;
3213 bih
.biXPelsPerMeter
= 0;
3214 bih
.biYPelsPerMeter
= 0;
3216 bih
.biClrImportant
= 0;
3218 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3219 (void**)&temp_bits
, NULL
, 0);
3221 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3222 dst_format
= PixelFormat32bppPARGB
;
3224 dst_format
= PixelFormat32bppRGB
;
3226 convert_pixels(bitmap
->width
, bitmap
->height
,
3227 bitmap
->width
*4, temp_bits
, dst_format
,
3228 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3229 bitmap
->image
.palette
);
3233 if (bitmap
->hbitmap
)
3234 hbitmap
= bitmap
->hbitmap
;
3237 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3242 temp_hdc
= (hdc
== 0);
3247 if (!hdc
) hdc
= CreateCompatibleDC(0);
3248 old_hbm
= SelectObject(hdc
, hbitmap
);
3251 save_state
= SaveDC(graphics
->hdc
);
3253 stat
= get_clip_hrgn(graphics
, &hrgn
);
3257 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
3261 gdi_transform_acquire(graphics
);
3263 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3265 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3266 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3270 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3271 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3274 gdi_transform_release(graphics
);
3276 RestoreDC(graphics
->hdc
, save_state
);
3280 SelectObject(hdc
, old_hbm
);
3285 DeleteObject(hbitmap
);
3288 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3294 rc
.Width
= srcwidth
;
3295 rc
.Height
= srcheight
;
3297 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3298 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3302 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3303 return InvalidParameter
;
3309 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3310 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3311 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3312 DrawImageAbort callback
, VOID
* callbackData
)
3314 GpPointF pointsF
[3];
3317 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3318 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3321 if(!points
|| count
!=3)
3322 return InvalidParameter
;
3324 for(i
= 0; i
< count
; i
++){
3325 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3326 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3329 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3330 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3331 callback
, callbackData
);
3334 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3335 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3336 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3337 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3338 VOID
* callbackData
)
3342 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3343 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3344 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3348 points
[1].X
= dstx
+ dstwidth
;
3351 points
[2].Y
= dsty
+ dstheight
;
3353 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3354 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3357 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3358 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3359 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3360 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3361 VOID
* callbackData
)
3365 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3366 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3367 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3371 points
[1].X
= dstx
+ dstwidth
;
3374 points
[2].Y
= dsty
+ dstheight
;
3376 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3377 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3380 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3381 REAL x
, REAL y
, REAL width
, REAL height
)
3387 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3389 if(!graphics
|| !image
)
3390 return InvalidParameter
;
3392 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3396 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3397 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3398 unit
, NULL
, NULL
, NULL
);
3401 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3402 INT x
, INT y
, INT width
, INT height
)
3404 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3406 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3409 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3410 REAL y1
, REAL x2
, REAL y2
)
3414 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3417 return InvalidParameter
;
3419 if (pen
->unit
== UnitPixel
&& pen
->width
<= 0.0)
3426 return GdipDrawLines(graphics
, pen
, pt
, 2);
3429 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3430 INT y1
, INT x2
, INT y2
)
3432 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3434 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3437 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3438 GpPointF
*points
, INT count
)
3443 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3445 if(!pen
|| !graphics
|| (count
< 2))
3446 return InvalidParameter
;
3451 status
= GdipCreatePath(FillModeAlternate
, &path
);
3452 if (status
!= Ok
) return status
;
3454 status
= GdipAddPathLine2(path
, points
, count
);
3456 status
= GdipDrawPath(graphics
, pen
, path
);
3458 GdipDeletePath(path
);
3462 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3463 GpPoint
*points
, INT count
)
3469 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3471 ptf
= heap_alloc_zero(count
* sizeof(GpPointF
));
3472 if(!ptf
) return OutOfMemory
;
3474 for(i
= 0; i
< count
; i
++){
3475 ptf
[i
].X
= (REAL
) points
[i
].X
;
3476 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3479 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3485 static GpStatus
GDI32_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3491 save_state
= prepare_dc(graphics
, pen
);
3493 retval
= get_clip_hrgn(graphics
, &hrgn
);
3498 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
3500 gdi_transform_acquire(graphics
);
3502 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3503 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3505 gdi_transform_release(graphics
);
3508 restore_dc(graphics
, save_state
);
3514 static GpStatus
SOFTWARE_GdipDrawThinPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3518 GpMatrix
* transform
;
3519 GpRectF gp_bound_rect
;
3520 GpRect gp_output_area
;
3522 INT output_height
, output_width
;
3523 DWORD
*output_bits
, *brush_bits
=NULL
;
3525 static const BYTE static_dash_pattern
[] = {1,1,1,0,1,0,1,0};
3526 const BYTE
*dash_pattern
;
3527 INT dash_pattern_size
;
3528 BYTE
*dyn_dash_pattern
= NULL
;
3530 stat
= GdipClonePath(path
, &flat_path
);
3535 stat
= GdipCreateMatrix(&transform
);
3539 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3540 CoordinateSpaceWorld
, transform
);
3543 stat
= GdipFlattenPath(flat_path
, transform
, 1.0);
3545 GdipDeleteMatrix(transform
);
3548 /* estimate the output size in pixels, can be larger than necessary */
3551 output_area
.left
= floorf(flat_path
->pathdata
.Points
[0].X
);
3552 output_area
.right
= ceilf(flat_path
->pathdata
.Points
[0].X
);
3553 output_area
.top
= floorf(flat_path
->pathdata
.Points
[0].Y
);
3554 output_area
.bottom
= ceilf(flat_path
->pathdata
.Points
[0].Y
);
3556 for (i
=1; i
<flat_path
->pathdata
.Count
; i
++)
3559 x
= flat_path
->pathdata
.Points
[i
].X
;
3560 y
= flat_path
->pathdata
.Points
[i
].Y
;
3562 if (floorf(x
) < output_area
.left
) output_area
.left
= floorf(x
);
3563 if (floorf(y
) < output_area
.top
) output_area
.top
= floorf(y
);
3564 if (ceilf(x
) > output_area
.right
) output_area
.right
= ceilf(x
);
3565 if (ceilf(y
) > output_area
.bottom
) output_area
.bottom
= ceilf(y
);
3568 stat
= get_graphics_device_bounds(graphics
, &gp_bound_rect
);
3573 output_area
.left
= max(output_area
.left
, floorf(gp_bound_rect
.X
));
3574 output_area
.top
= max(output_area
.top
, floorf(gp_bound_rect
.Y
));
3575 output_area
.right
= min(output_area
.right
, ceilf(gp_bound_rect
.X
+ gp_bound_rect
.Width
));
3576 output_area
.bottom
= min(output_area
.bottom
, ceilf(gp_bound_rect
.Y
+ gp_bound_rect
.Height
));
3578 output_width
= output_area
.right
- output_area
.left
+ 1;
3579 output_height
= output_area
.bottom
- output_area
.top
+ 1;
3581 if (output_width
<= 0 || output_height
<= 0)
3583 GdipDeletePath(flat_path
);
3587 gp_output_area
.X
= output_area
.left
;
3588 gp_output_area
.Y
= output_area
.top
;
3589 gp_output_area
.Width
= output_width
;
3590 gp_output_area
.Height
= output_height
;
3592 output_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3599 if (pen
->brush
->bt
!= BrushTypeSolidColor
)
3601 /* allocate and draw brush output */
3602 brush_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3606 stat
= brush_fill_pixels(graphics
, pen
->brush
, brush_bits
,
3607 &gp_output_area
, output_width
);
3615 /* convert dash pattern to bool array */
3618 case DashStyleCustom
:
3620 dash_pattern_size
= 0;
3622 for (i
=0; i
< pen
->numdashes
; i
++)
3623 dash_pattern_size
+= gdip_round(pen
->dashes
[i
]);
3625 if (dash_pattern_size
!= 0)
3627 dash_pattern
= dyn_dash_pattern
= heap_alloc(dash_pattern_size
);
3629 if (dyn_dash_pattern
)
3632 for (i
=0; i
< pen
->numdashes
; i
++)
3635 for (k
=0; k
< gdip_round(pen
->dashes
[i
]); k
++)
3636 dyn_dash_pattern
[j
++] = (i
&1)^1;
3644 /* else fall through */
3646 case DashStyleSolid
:
3648 dash_pattern
= static_dash_pattern
;
3649 dash_pattern_size
= 1;
3652 dash_pattern
= static_dash_pattern
;
3653 dash_pattern_size
= 4;
3656 dash_pattern
= &static_dash_pattern
[4];
3657 dash_pattern_size
= 2;
3659 case DashStyleDashDot
:
3660 dash_pattern
= static_dash_pattern
;
3661 dash_pattern_size
= 6;
3663 case DashStyleDashDotDot
:
3664 dash_pattern
= static_dash_pattern
;
3665 dash_pattern_size
= 8;
3673 GpPointF subpath_start
= flat_path
->pathdata
.Points
[0];
3674 INT prev_x
= INT_MAX
, prev_y
= INT_MAX
;
3675 int dash_pos
= dash_pattern_size
- 1;
3677 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
3680 GpPointF start_point
, end_point
;
3681 GpPoint start_pointi
, end_pointi
;
3683 type
= flat_path
->pathdata
.Types
[i
];
3684 if (i
+1 < flat_path
->pathdata
.Count
)
3685 type2
= flat_path
->pathdata
.Types
[i
+1];
3687 type2
= PathPointTypeStart
;
3689 start_point
= flat_path
->pathdata
.Points
[i
];
3691 if ((type
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3692 subpath_start
= start_point
;
3694 if ((type
& PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
3695 end_point
= subpath_start
;
3696 else if ((type2
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3699 end_point
= flat_path
->pathdata
.Points
[i
+1];
3701 start_pointi
.X
= floorf(start_point
.X
);
3702 start_pointi
.Y
= floorf(start_point
.Y
);
3703 end_pointi
.X
= floorf(end_point
.X
);
3704 end_pointi
.Y
= floorf(end_point
.Y
);
3706 if(start_pointi
.X
== end_pointi
.X
&& start_pointi
.Y
== end_pointi
.Y
)
3709 /* draw line segment */
3710 if (abs(start_pointi
.Y
- end_pointi
.Y
) > abs(start_pointi
.X
- end_pointi
.X
))
3712 INT x
, y
, start_y
, end_y
, step
;
3714 if (start_pointi
.Y
< end_pointi
.Y
)
3717 start_y
= ceilf(start_point
.Y
) - output_area
.top
;
3718 end_y
= end_pointi
.Y
- output_area
.top
;
3723 start_y
= start_point
.Y
- output_area
.top
;
3724 end_y
= ceilf(end_point
.Y
) - output_area
.top
;
3727 for (y
=start_y
; y
!= (end_y
+step
); y
+=step
)
3729 x
= gdip_round( start_point
.X
+
3730 (end_point
.X
- start_point
.X
) * (y
+ output_area
.top
- start_point
.Y
) / (end_point
.Y
- start_point
.Y
) )
3733 if (x
== prev_x
&& y
== prev_y
)
3738 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3740 if (!dash_pattern
[dash_pos
])
3743 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3747 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3749 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3754 INT x
, y
, start_x
, end_x
, step
;
3756 if (start_pointi
.X
< end_pointi
.X
)
3759 start_x
= ceilf(start_point
.X
) - output_area
.left
;
3760 end_x
= end_pointi
.X
- output_area
.left
;
3765 start_x
= start_point
.X
- output_area
.left
;
3766 end_x
= ceilf(end_point
.X
) - output_area
.left
;
3769 for (x
=start_x
; x
!= (end_x
+step
); x
+=step
)
3771 y
= gdip_round( start_point
.Y
+
3772 (end_point
.Y
- start_point
.Y
) * (x
+ output_area
.left
- start_point
.X
) / (end_point
.X
- start_point
.X
) )
3775 if (x
== prev_x
&& y
== prev_y
)
3780 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3782 if (!dash_pattern
[dash_pos
])
3785 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3789 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3791 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3797 /* draw output image */
3800 gdi_transform_acquire(graphics
);
3802 stat
= alpha_blend_pixels(graphics
, output_area
.left
, output_area
.top
,
3803 (BYTE
*)output_bits
, output_width
, output_height
, output_width
* 4,
3804 PixelFormat32bppARGB
);
3806 gdi_transform_release(graphics
);
3809 heap_free(brush_bits
);
3810 heap_free(dyn_dash_pattern
);
3811 heap_free(output_bits
);
3814 GdipDeletePath(flat_path
);
3819 static GpStatus
SOFTWARE_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3823 GpMatrix
*transform
=NULL
;
3826 /* Check if the final pen thickness in pixels is too thin. */
3827 if (pen
->unit
== UnitPixel
)
3829 if (pen
->width
< 1.415)
3830 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3834 GpPointF points
[3] = {{0,0}, {1,0}, {0,1}};
3836 points
[1].X
= pen
->width
;
3837 points
[2].Y
= pen
->width
;
3839 stat
= gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
,
3840 CoordinateSpaceWorld
, points
, 3);
3845 if (((points
[1].X
-points
[0].X
)*(points
[1].X
-points
[0].X
) +
3846 (points
[1].Y
-points
[0].Y
)*(points
[1].Y
-points
[0].Y
) < 2.0001) &&
3847 ((points
[2].X
-points
[0].X
)*(points
[2].X
-points
[0].X
) +
3848 (points
[2].Y
-points
[0].Y
)*(points
[2].Y
-points
[0].Y
) < 2.0001))
3849 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3852 stat
= GdipClonePath(path
, &wide_path
);
3857 if (pen
->unit
== UnitPixel
)
3859 /* We have to transform this to device coordinates to get the widths right. */
3860 stat
= GdipCreateMatrix(&transform
);
3863 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3864 CoordinateSpaceWorld
, transform
);
3868 /* Set flatness based on the final coordinate space */
3871 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3872 CoordinateSpaceWorld
, &t
);
3877 flatness
= 1.0/sqrt(fmax(
3878 t
.matrix
[0] * t
.matrix
[0] + t
.matrix
[1] * t
.matrix
[1],
3879 t
.matrix
[2] * t
.matrix
[2] + t
.matrix
[3] * t
.matrix
[3]));
3883 stat
= GdipWidenPath(wide_path
, pen
, transform
, flatness
);
3885 if (pen
->unit
== UnitPixel
)
3887 /* Transform the path back to world coordinates */
3889 stat
= GdipInvertMatrix(transform
);
3892 stat
= GdipTransformPath(wide_path
, transform
);
3895 /* Actually draw the path */
3897 stat
= GdipFillPath(graphics
, pen
->brush
, wide_path
);
3899 GdipDeleteMatrix(transform
);
3901 GdipDeletePath(wide_path
);
3906 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3910 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3912 if(!pen
|| !graphics
)
3913 return InvalidParameter
;
3918 if (path
->pathdata
.Count
== 0)
3921 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
3922 retval
= METAFILE_DrawPath((GpMetafile
*)graphics
->image
, pen
, path
);
3923 else if (!graphics
->hdc
|| graphics
->alpha_hdc
|| !brush_can_fill_path(pen
->brush
, FALSE
))
3924 retval
= SOFTWARE_GdipDrawPath(graphics
, pen
, path
);
3926 retval
= GDI32_GdipDrawPath(graphics
, pen
, path
);
3931 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3932 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3937 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3938 width
, height
, startAngle
, sweepAngle
);
3940 if(!graphics
|| !pen
)
3941 return InvalidParameter
;
3946 status
= GdipCreatePath(FillModeAlternate
, &path
);
3947 if (status
!= Ok
) return status
;
3949 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3951 status
= GdipDrawPath(graphics
, pen
, path
);
3953 GdipDeletePath(path
);
3957 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3958 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3960 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3961 width
, height
, startAngle
, sweepAngle
);
3963 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3966 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3967 REAL y
, REAL width
, REAL height
)
3972 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3974 if(!pen
|| !graphics
)
3975 return InvalidParameter
;
3980 status
= GdipCreatePath(FillModeAlternate
, &path
);
3981 if (status
!= Ok
) return status
;
3983 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3985 status
= GdipDrawPath(graphics
, pen
, path
);
3987 GdipDeletePath(path
);
3991 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3992 INT y
, INT width
, INT height
)
3994 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3996 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3999 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
4000 GDIPCONST GpRectF
* rects
, INT count
)
4005 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
4007 if(!graphics
|| !pen
|| !rects
|| count
< 1)
4008 return InvalidParameter
;
4013 status
= GdipCreatePath(FillModeAlternate
, &path
);
4014 if (status
!= Ok
) return status
;
4016 status
= GdipAddPathRectangles(path
, rects
, count
);
4018 status
= GdipDrawPath(graphics
, pen
, path
);
4020 GdipDeletePath(path
);
4024 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
4025 GDIPCONST GpRect
* rects
, INT count
)
4031 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
4033 if(!rects
|| count
<=0)
4034 return InvalidParameter
;
4036 rectsF
= heap_alloc_zero(sizeof(GpRectF
) * count
);
4040 for(i
= 0;i
< count
;i
++){
4041 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4042 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4043 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
4044 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4047 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
4053 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
4054 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
4059 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
4060 count
, tension
, fill
);
4062 if(!graphics
|| !brush
|| !points
)
4063 return InvalidParameter
;
4068 if(count
== 1) /* Do nothing */
4071 status
= GdipCreatePath(fill
, &path
);
4072 if (status
!= Ok
) return status
;
4074 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
4076 status
= GdipFillPath(graphics
, brush
, path
);
4078 GdipDeletePath(path
);
4082 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
4083 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
4089 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
4090 count
, tension
, fill
);
4092 if(!points
|| count
== 0)
4093 return InvalidParameter
;
4095 if(count
== 1) /* Do nothing */
4098 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
4102 for(i
= 0;i
< count
;i
++){
4103 ptf
[i
].X
= (REAL
)points
[i
].X
;
4104 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4107 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
4114 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
4115 GDIPCONST GpPointF
*points
, INT count
)
4117 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4118 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
4119 0.5f
, FillModeAlternate
);
4122 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
4123 GDIPCONST GpPoint
*points
, INT count
)
4125 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4126 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
4127 0.5f
, FillModeAlternate
);
4130 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4131 REAL y
, REAL width
, REAL height
)
4136 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4138 if(!graphics
|| !brush
)
4139 return InvalidParameter
;
4144 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4148 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
4151 stat
= GdipFillPath(graphics
, brush
, path
);
4153 GdipDeletePath(path
);
4159 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4160 INT y
, INT width
, INT height
)
4162 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4164 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
4167 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4173 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4174 return NotImplemented
;
4176 save_state
= SaveDC(graphics
->hdc
);
4177 EndPath(graphics
->hdc
);
4178 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
4181 retval
= get_clip_hrgn(graphics
, &hrgn
);
4186 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
4188 gdi_transform_acquire(graphics
);
4190 BeginPath(graphics
->hdc
);
4191 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
4192 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
4196 EndPath(graphics
->hdc
);
4197 brush_fill_path(graphics
, brush
);
4200 gdi_transform_release(graphics
);
4203 RestoreDC(graphics
->hdc
, save_state
);
4209 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4214 if (!brush_can_fill_pixels(brush
))
4215 return NotImplemented
;
4217 /* FIXME: This could probably be done more efficiently without regions. */
4219 stat
= GdipCreateRegionPath(path
, &rgn
);
4223 stat
= GdipFillRegion(graphics
, brush
, rgn
);
4225 GdipDeleteRegion(rgn
);
4231 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4233 GpStatus stat
= NotImplemented
;
4235 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
4237 if(!brush
|| !graphics
|| !path
)
4238 return InvalidParameter
;
4243 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4244 return METAFILE_FillPath((GpMetafile
*)graphics
->image
, brush
, path
);
4246 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4247 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
4249 if (stat
== NotImplemented
)
4250 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
4252 if (stat
== NotImplemented
)
4254 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
4261 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4262 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4267 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
4268 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4270 if(!graphics
|| !brush
)
4271 return InvalidParameter
;
4276 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4280 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4283 stat
= GdipFillPath(graphics
, brush
, path
);
4285 GdipDeletePath(path
);
4291 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4292 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4294 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
4295 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4297 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4300 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
4301 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
4306 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4308 if(!graphics
|| !brush
|| !points
|| !count
)
4309 return InvalidParameter
;
4314 stat
= GdipCreatePath(fillMode
, &path
);
4318 stat
= GdipAddPathPolygon(path
, points
, count
);
4321 stat
= GdipFillPath(graphics
, brush
, path
);
4323 GdipDeletePath(path
);
4329 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4330 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4335 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4337 if(!graphics
|| !brush
|| !points
|| !count
)
4338 return InvalidParameter
;
4343 stat
= GdipCreatePath(fillMode
, &path
);
4347 stat
= GdipAddPathPolygonI(path
, points
, count
);
4350 stat
= GdipFillPath(graphics
, brush
, path
);
4352 GdipDeletePath(path
);
4358 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4359 GDIPCONST GpPointF
*points
, INT count
)
4361 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4363 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4366 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4367 GDIPCONST GpPoint
*points
, INT count
)
4369 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4371 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4374 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4375 REAL x
, REAL y
, REAL width
, REAL height
)
4379 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4384 rect
.Height
= height
;
4386 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4389 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4390 INT x
, INT y
, INT width
, INT height
)
4394 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4398 rect
.Width
= (REAL
)width
;
4399 rect
.Height
= (REAL
)height
;
4401 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4404 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4410 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4412 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
4413 return InvalidParameter
;
4415 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4417 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
4418 /* FIXME: Add gdi32 drawing. */
4422 status
= GdipCreatePath(FillModeAlternate
, &path
);
4423 if (status
!= Ok
) return status
;
4425 status
= GdipAddPathRectangles(path
, rects
, count
);
4427 status
= GdipFillPath(graphics
, brush
, path
);
4429 GdipDeletePath(path
);
4433 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4440 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4442 if(!rects
|| count
<= 0)
4443 return InvalidParameter
;
4445 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
4449 for(i
= 0; i
< count
; i
++){
4450 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4451 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4452 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
4453 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4456 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4462 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4470 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4471 return NotImplemented
;
4473 save_state
= SaveDC(graphics
->hdc
);
4474 EndPath(graphics
->hdc
);
4477 status
= get_clip_hrgn(graphics
, &hrgn
);
4480 RestoreDC(graphics
->hdc
, save_state
);
4484 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
4487 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4490 RestoreDC(graphics
->hdc
, save_state
);
4494 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4497 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4499 BeginPath(graphics
->hdc
);
4500 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4501 EndPath(graphics
->hdc
);
4503 brush_fill_path(graphics
, brush
);
4506 RestoreDC(graphics
->hdc
, save_state
);
4512 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4516 GpRegion
*temp_region
;
4517 GpMatrix world_to_device
;
4518 GpRectF graphics_bounds
;
4522 GpRect gp_bound_rect
;
4524 if (!brush_can_fill_pixels(brush
))
4525 return NotImplemented
;
4527 stat
= gdi_transform_acquire(graphics
);
4530 stat
= get_graphics_device_bounds(graphics
, &graphics_bounds
);
4533 stat
= GdipCloneRegion(region
, &temp_region
);
4537 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
4538 CoordinateSpaceWorld
, &world_to_device
);
4541 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4544 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4547 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4549 GdipDeleteRegion(temp_region
);
4552 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4554 DeleteObject(hregion
);
4555 gdi_transform_release(graphics
);
4561 gp_bound_rect
.X
= bound_rect
.left
;
4562 gp_bound_rect
.Y
= bound_rect
.top
;
4563 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4564 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4566 pixel_data
= heap_alloc_zero(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4572 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4573 &gp_bound_rect
, gp_bound_rect
.Width
);
4576 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4577 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4578 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
,
4579 PixelFormat32bppARGB
);
4581 heap_free(pixel_data
);
4584 DeleteObject(hregion
);
4587 gdi_transform_release(graphics
);
4592 /*****************************************************************************
4593 * GdipFillRegion [GDIPLUS.@]
4595 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4598 GpStatus stat
= NotImplemented
;
4600 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4602 if (!(graphics
&& brush
&& region
))
4603 return InvalidParameter
;
4608 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4609 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4611 if (stat
== NotImplemented
)
4612 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4614 if (stat
== NotImplemented
)
4616 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4623 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4625 TRACE("(%p,%u)\n", graphics
, intention
);
4628 return InvalidParameter
;
4633 /* We have no internal operation queue, so there's no need to clear it. */
4641 /*****************************************************************************
4642 * GdipGetClipBounds [GDIPLUS.@]
4644 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4649 TRACE("(%p, %p)\n", graphics
, rect
);
4652 return InvalidParameter
;
4657 status
= GdipCreateRegion(&clip
);
4658 if (status
!= Ok
) return status
;
4660 status
= GdipGetClip(graphics
, clip
);
4662 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4664 GdipDeleteRegion(clip
);
4668 /*****************************************************************************
4669 * GdipGetClipBoundsI [GDIPLUS.@]
4671 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4673 TRACE("(%p, %p)\n", graphics
, rect
);
4676 return InvalidParameter
;
4681 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4684 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4685 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4686 CompositingMode
*mode
)
4688 TRACE("(%p, %p)\n", graphics
, mode
);
4690 if(!graphics
|| !mode
)
4691 return InvalidParameter
;
4696 *mode
= graphics
->compmode
;
4701 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4702 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4703 CompositingQuality
*quality
)
4705 TRACE("(%p, %p)\n", graphics
, quality
);
4707 if(!graphics
|| !quality
)
4708 return InvalidParameter
;
4713 *quality
= graphics
->compqual
;
4718 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4719 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4720 InterpolationMode
*mode
)
4722 TRACE("(%p, %p)\n", graphics
, mode
);
4724 if(!graphics
|| !mode
)
4725 return InvalidParameter
;
4730 *mode
= graphics
->interpolation
;
4735 /* FIXME: Need to handle color depths less than 24bpp */
4736 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4738 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4740 if(!graphics
|| !argb
)
4741 return InvalidParameter
;
4749 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4751 TRACE("(%p, %p)\n", graphics
, scale
);
4753 if(!graphics
|| !scale
)
4754 return InvalidParameter
;
4759 *scale
= graphics
->scale
;
4764 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4766 TRACE("(%p, %p)\n", graphics
, unit
);
4768 if(!graphics
|| !unit
)
4769 return InvalidParameter
;
4774 *unit
= graphics
->unit
;
4779 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4780 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4783 TRACE("(%p, %p)\n", graphics
, mode
);
4785 if(!graphics
|| !mode
)
4786 return InvalidParameter
;
4791 *mode
= graphics
->pixeloffset
;
4796 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4797 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4799 TRACE("(%p, %p)\n", graphics
, mode
);
4801 if(!graphics
|| !mode
)
4802 return InvalidParameter
;
4807 *mode
= graphics
->smoothing
;
4812 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4814 TRACE("(%p, %p)\n", graphics
, contrast
);
4816 if(!graphics
|| !contrast
)
4817 return InvalidParameter
;
4819 *contrast
= graphics
->textcontrast
;
4824 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4825 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4826 TextRenderingHint
*hint
)
4828 TRACE("(%p, %p)\n", graphics
, hint
);
4830 if(!graphics
|| !hint
)
4831 return InvalidParameter
;
4836 *hint
= graphics
->texthint
;
4841 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4845 GpMatrix device_to_world
;
4847 TRACE("(%p, %p)\n", graphics
, rect
);
4849 if(!graphics
|| !rect
)
4850 return InvalidParameter
;
4855 /* intersect window and graphics clipping regions */
4856 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4859 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4862 /* transform to world coordinates */
4863 if((stat
= get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
)) != Ok
)
4866 if((stat
= GdipTransformRegion(clip_rgn
, &device_to_world
)) != Ok
)
4869 /* get bounds of the region */
4870 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4873 GdipDeleteRegion(clip_rgn
);
4878 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4883 TRACE("(%p, %p)\n", graphics
, rect
);
4885 if(!graphics
|| !rect
)
4886 return InvalidParameter
;
4888 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4890 rect
->X
= gdip_round(rectf
.X
);
4891 rect
->Y
= gdip_round(rectf
.Y
);
4892 rect
->Width
= gdip_round(rectf
.Width
);
4893 rect
->Height
= gdip_round(rectf
.Height
);
4899 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4901 TRACE("(%p, %p)\n", graphics
, matrix
);
4903 if(!graphics
|| !matrix
)
4904 return InvalidParameter
;
4909 *matrix
= graphics
->worldtrans
;
4913 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4919 TRACE("(%p, %x)\n", graphics
, color
);
4922 return InvalidParameter
;
4927 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4928 return METAFILE_GraphicsClear((GpMetafile
*)graphics
->image
, color
);
4930 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4933 if((stat
= GdipGetVisibleClipBounds(graphics
, &wnd_rect
)) != Ok
){
4934 GdipDeleteBrush((GpBrush
*)brush
);
4938 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4939 wnd_rect
.Width
, wnd_rect
.Height
);
4941 GdipDeleteBrush((GpBrush
*)brush
);
4946 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4948 TRACE("(%p, %p)\n", graphics
, res
);
4950 if(!graphics
|| !res
)
4951 return InvalidParameter
;
4953 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4956 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4962 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4964 if(!graphics
|| !result
)
4965 return InvalidParameter
;
4972 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4973 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4976 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4979 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4982 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4985 GdipDeleteRegion(rgn
);
4989 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4991 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4994 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
5000 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
5002 if(!graphics
|| !result
)
5003 return InvalidParameter
;
5010 pts
[1].X
= x
+ width
;
5011 pts
[1].Y
= y
+ height
;
5013 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
5014 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
5017 pts
[1].X
-= pts
[0].X
;
5018 pts
[1].Y
-= pts
[0].Y
;
5020 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5023 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5026 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
5029 GdipDeleteRegion(rgn
);
5033 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
5035 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
5038 GpStatus
gdip_format_string(HDC hdc
,
5039 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5040 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
5041 gdip_format_string_callback callback
, void *user_data
)
5044 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
5045 nheight
, lineend
, lineno
= 0;
5047 StringAlignment halign
;
5050 HotkeyPrefix hkprefix
;
5051 INT
*hotkeyprefix_offsets
=NULL
;
5052 INT hotkeyprefix_count
=0;
5053 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
5054 BOOL seen_prefix
= FALSE
;
5056 if(length
== -1) length
= lstrlenW(string
);
5058 stringdup
= heap_alloc_zero((length
+ 1) * sizeof(WCHAR
));
5059 if(!stringdup
) return OutOfMemory
;
5062 format
= &default_drawstring_format
;
5064 nwidth
= rect
->Width
;
5065 nheight
= rect
->Height
;
5066 if (ignore_empty_clip
)
5068 if (!nwidth
) nwidth
= INT_MAX
;
5069 if (!nheight
) nheight
= INT_MAX
;
5072 hkprefix
= format
->hkprefix
;
5074 if (hkprefix
== HotkeyPrefixShow
)
5076 for (i
=0; i
<length
; i
++)
5078 if (string
[i
] == '&')
5079 hotkeyprefix_count
++;
5083 if (hotkeyprefix_count
)
5084 hotkeyprefix_offsets
= heap_alloc_zero(sizeof(INT
) * hotkeyprefix_count
);
5086 hotkeyprefix_count
= 0;
5088 for(i
= 0, j
= 0; i
< length
; i
++){
5089 /* FIXME: This makes the indexes passed to callback inaccurate. */
5090 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
5093 /* FIXME: tabs should be handled using tabstops from stringformat */
5094 if (string
[i
] == '\t')
5097 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
5098 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
5099 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
5105 seen_prefix
= FALSE
;
5107 stringdup
[j
] = string
[i
];
5113 halign
= format
->align
;
5115 while(sum
< length
){
5116 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
5117 nwidth
, &fit
, NULL
, &size
);
5123 for(lret
= 0; lret
< fit
; lret
++)
5124 if(*(stringdup
+ sum
+ lret
) == '\n')
5127 /* Line break code (may look strange, but it imitates windows). */
5129 lineend
= fit
= lret
; /* this is not an off-by-one error */
5130 else if(fit
< (length
- sum
)){
5131 if(*(stringdup
+ sum
+ fit
) == ' ')
5132 while(*(stringdup
+ sum
+ fit
) == ' ')
5135 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
5138 if(*(stringdup
+ sum
+ fit
) == '\t')
5147 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
5148 *(stringdup
+ sum
+ lineend
- 1) == '\t')
5154 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
5155 nwidth
, &j
, NULL
, &size
);
5157 bounds
.Width
= size
.cx
;
5159 if(height
+ size
.cy
> nheight
)
5161 if (format
->attr
& StringFormatFlagsLineLimit
)
5163 bounds
.Height
= nheight
- (height
+ size
.cy
);
5166 bounds
.Height
= size
.cy
;
5168 bounds
.Y
= rect
->Y
+ height
;
5172 case StringAlignmentNear
:
5176 case StringAlignmentCenter
:
5177 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
5179 case StringAlignmentFar
:
5180 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
5184 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
5185 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
5188 stat
= callback(hdc
, stringdup
, sum
, lineend
,
5189 font
, rect
, format
, lineno
, &bounds
,
5190 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
5191 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
5196 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
5200 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
5202 if(height
> nheight
)
5205 /* Stop if this was a linewrap (but not if it was a linebreak). */
5206 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
5210 heap_free(stringdup
);
5211 heap_free(hotkeyprefix_offsets
);
5216 struct measure_ranges_args
{
5218 REAL rel_width
, rel_height
;
5221 static GpStatus
measure_ranges_callback(HDC hdc
,
5222 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5223 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5224 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5225 INT underlined_index_count
, void *user_data
)
5229 struct measure_ranges_args
*args
= user_data
;
5231 for (i
=0; i
<format
->range_count
; i
++)
5233 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
5234 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
5235 if (range_start
< range_end
)
5240 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
5241 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
5243 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
5244 INT_MAX
, NULL
, NULL
, &range_size
);
5245 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
5247 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
5248 INT_MAX
, NULL
, NULL
, &range_size
);
5249 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
5251 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
5260 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
5261 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
5262 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
5263 INT regionCount
, GpRegion
** regions
)
5267 HFONT gdifont
, oldfont
;
5268 struct measure_ranges_args args
;
5269 HDC hdc
, temp_hdc
=NULL
;
5274 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
5275 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
5277 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
5278 return InvalidParameter
;
5280 if (regionCount
< stringFormat
->range_count
)
5281 return InvalidParameter
;
5285 hdc
= temp_hdc
= CreateCompatibleDC(0);
5286 if (!temp_hdc
) return OutOfMemory
;
5289 hdc
= graphics
->hdc
;
5291 if (stringFormat
->attr
)
5292 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
5300 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5301 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5302 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5303 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5304 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5306 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
5307 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5309 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
5310 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
5311 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
5312 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
5314 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5315 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5317 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
5318 oldfont
= SelectObject(hdc
, gdifont
);
5320 for (i
=0; i
<stringFormat
->range_count
; i
++)
5322 stat
= GdipSetEmpty(regions
[i
]);
5327 args
.regions
= regions
;
5329 gdi_transform_acquire(graphics
);
5331 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
5332 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
5334 gdi_transform_release(graphics
);
5336 SelectObject(hdc
, oldfont
);
5337 DeleteObject(gdifont
);
5345 struct measure_string_args
{
5347 INT
*codepointsfitted
;
5349 REAL rel_width
, rel_height
;
5352 static GpStatus
measure_string_callback(HDC hdc
,
5353 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5354 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5355 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5356 INT underlined_index_count
, void *user_data
)
5358 struct measure_string_args
*args
= user_data
;
5359 REAL new_width
, new_height
;
5361 new_width
= bounds
->Width
/ args
->rel_width
;
5362 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
5364 if (new_width
> args
->bounds
->Width
)
5365 args
->bounds
->Width
= new_width
;
5367 if (new_height
> args
->bounds
->Height
)
5368 args
->bounds
->Height
= new_height
;
5370 if (args
->codepointsfitted
)
5371 *args
->codepointsfitted
= index
+ length
;
5373 if (args
->linesfilled
)
5374 (*args
->linesfilled
)++;
5379 /* Find the smallest rectangle that bounds the text when it is printed in rect
5380 * according to the format options listed in format. If rect has 0 width and
5381 * height, then just find the smallest rectangle that bounds the text when it's
5382 * printed at location (rect->X, rect-Y). */
5383 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
5384 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5385 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
5386 INT
*codepointsfitted
, INT
*linesfilled
)
5388 HFONT oldfont
, gdifont
;
5389 struct measure_string_args args
;
5390 HDC temp_hdc
=NULL
, hdc
;
5396 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
5397 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
5398 bounds
, codepointsfitted
, linesfilled
);
5400 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
5401 return InvalidParameter
;
5405 hdc
= temp_hdc
= CreateCompatibleDC(0);
5406 if (!temp_hdc
) return OutOfMemory
;
5409 hdc
= graphics
->hdc
;
5411 if(linesfilled
) *linesfilled
= 0;
5412 if(codepointsfitted
) *codepointsfitted
= 0;
5415 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5423 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5424 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5425 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5426 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5427 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5429 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5430 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5432 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
5433 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
5434 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
5435 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
5436 if (scaled_rect
.Width
>= 0.5)
5438 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5439 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5442 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5443 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5445 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5446 oldfont
= SelectObject(hdc
, gdifont
);
5448 bounds
->X
= rect
->X
;
5449 bounds
->Y
= rect
->Y
;
5450 bounds
->Width
= 0.0;
5451 bounds
->Height
= 0.0;
5453 args
.bounds
= bounds
;
5454 args
.codepointsfitted
= &glyphs
;
5455 args
.linesfilled
= &lines
;
5458 gdi_transform_acquire(graphics
);
5460 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5461 measure_string_callback
, &args
);
5463 gdi_transform_release(graphics
);
5465 if (linesfilled
) *linesfilled
= lines
;
5466 if (codepointsfitted
) *codepointsfitted
= glyphs
;
5469 bounds
->Width
+= margin_x
* 2.0;
5471 SelectObject(hdc
, oldfont
);
5472 DeleteObject(gdifont
);
5480 struct draw_string_args
{
5481 GpGraphics
*graphics
;
5482 GDIPCONST GpBrush
*brush
;
5483 REAL x
, y
, rel_width
, rel_height
, ascent
;
5486 static GpStatus
draw_string_callback(HDC hdc
,
5487 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5488 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5489 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5490 INT underlined_index_count
, void *user_data
)
5492 struct draw_string_args
*args
= user_data
;
5496 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5497 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5499 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
5500 args
->brush
, &position
,
5501 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5503 if (stat
== Ok
&& underlined_index_count
)
5505 OUTLINETEXTMETRICW otm
;
5506 REAL underline_y
, underline_height
;
5509 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5511 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5512 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5514 for (i
=0; i
<underlined_index_count
; i
++)
5516 REAL start_x
, end_x
;
5518 INT ofs
= underlined_indexes
[i
] - index
;
5520 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5521 start_x
= text_size
.cx
/ args
->rel_width
;
5523 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5524 end_x
= text_size
.cx
/ args
->rel_width
;
5526 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5533 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5534 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5535 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5539 GpPointF pt
[3], rectcpy
[4];
5541 REAL rel_width
, rel_height
, margin_x
;
5542 INT save_state
, format_flags
= 0;
5544 struct draw_string_args args
;
5546 HDC hdc
, temp_hdc
=NULL
;
5547 TEXTMETRICW textmetric
;
5549 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5550 length
, font
, debugstr_rectf(rect
), format
, brush
);
5552 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5553 return InvalidParameter
;
5557 hdc
= graphics
->hdc
;
5561 hdc
= temp_hdc
= CreateCompatibleDC(0);
5565 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5567 format_flags
= format
->attr
;
5569 /* Should be no need to explicitly test for StringAlignmentNear as
5570 * that is default behavior if no alignment is passed. */
5571 if(format
->line_align
!= StringAlignmentNear
){
5572 RectF bounds
, in_rect
= *rect
;
5573 in_rect
.Height
= 0.0; /* avoid height clipping */
5574 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5576 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5578 if(format
->line_align
== StringAlignmentCenter
)
5579 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5580 else if(format
->line_align
== StringAlignmentFar
)
5581 offsety
= (rect
->Height
- bounds
.Height
);
5583 TRACE("line align %d, offsety %f\n", format
->line_align
, offsety
);
5586 save_state
= SaveDC(hdc
);
5594 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5595 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5596 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5597 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5598 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5600 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5601 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5602 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5603 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5604 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, rectcpy
, 4);
5605 round_points(corners
, rectcpy
, 4);
5607 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5608 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5610 scaled_rect
.X
= margin_x
* rel_width
;
5611 scaled_rect
.Y
= 0.0;
5612 scaled_rect
.Width
= rel_width
* rect
->Width
;
5613 scaled_rect
.Height
= rel_height
* rect
->Height
;
5614 if (scaled_rect
.Width
>= 0.5)
5616 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5617 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5620 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5621 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5623 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5624 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5625 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5627 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5628 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5629 SelectClipRgn(hdc
, rgn
);
5632 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5633 SelectObject(hdc
, gdifont
);
5635 args
.graphics
= graphics
;
5639 args
.y
= rect
->Y
+ offsety
;
5641 args
.rel_width
= rel_width
;
5642 args
.rel_height
= rel_height
;
5644 gdi_transform_acquire(graphics
);
5646 GetTextMetricsW(hdc
, &textmetric
);
5647 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5649 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5650 draw_string_callback
, &args
);
5652 gdi_transform_release(graphics
);
5655 DeleteObject(gdifont
);
5657 RestoreDC(hdc
, save_state
);
5664 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5666 TRACE("(%p)\n", graphics
);
5669 return InvalidParameter
;
5674 return GdipSetInfinite(graphics
->clip
);
5677 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5681 TRACE("(%p)\n", graphics
);
5684 return InvalidParameter
;
5689 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5690 stat
= METAFILE_ResetWorldTransform((GpMetafile
*)graphics
->image
);
5696 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5699 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5700 GpMatrixOrder order
)
5704 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5707 return InvalidParameter
;
5712 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5713 stat
= METAFILE_RotateWorldTransform((GpMetafile
*)graphics
->image
, angle
, order
);
5719 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5722 static GpStatus
begin_container(GpGraphics
*graphics
,
5723 GraphicsContainerType type
, GraphicsContainer
*state
)
5725 GraphicsContainerItem
*container
;
5728 if(!graphics
|| !state
)
5729 return InvalidParameter
;
5731 sts
= init_container(&container
, graphics
, type
);
5735 list_add_head(&graphics
->containers
, &container
->entry
);
5736 *state
= graphics
->contid
= container
->contid
;
5738 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5739 if (type
== BEGIN_CONTAINER
)
5740 METAFILE_BeginContainerNoParams((GpMetafile
*)graphics
->image
, container
->contid
);
5742 METAFILE_SaveGraphics((GpMetafile
*)graphics
->image
, container
->contid
);
5748 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5750 TRACE("(%p, %p)\n", graphics
, state
);
5751 return begin_container(graphics
, SAVE_GRAPHICS
, state
);
5754 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5755 GraphicsContainer
*state
)
5757 TRACE("(%p, %p)\n", graphics
, state
);
5758 return begin_container(graphics
, BEGIN_CONTAINER
, state
);
5761 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5763 GraphicsContainerItem
*container
;
5766 GpRectF scaled_srcrect
;
5767 REAL scale_x
, scale_y
;
5769 TRACE("(%p, %s, %s, %d, %p)\n", graphics
, debugstr_rectf(dstrect
), debugstr_rectf(srcrect
), unit
, state
);
5771 if(!graphics
|| !dstrect
|| !srcrect
|| unit
< UnitPixel
|| unit
> UnitMillimeter
|| !state
)
5772 return InvalidParameter
;
5774 stat
= init_container(&container
, graphics
, BEGIN_CONTAINER
);
5778 list_add_head(&graphics
->containers
, &container
->entry
);
5779 *state
= graphics
->contid
= container
->contid
;
5781 scale_x
= units_to_pixels(1.0, unit
, graphics
->xres
);
5782 scale_y
= units_to_pixels(1.0, unit
, graphics
->yres
);
5784 scaled_srcrect
.X
= scale_x
* srcrect
->X
;
5785 scaled_srcrect
.Y
= scale_y
* srcrect
->Y
;
5786 scaled_srcrect
.Width
= scale_x
* srcrect
->Width
;
5787 scaled_srcrect
.Height
= scale_y
* srcrect
->Height
;
5789 transform
.matrix
[0] = dstrect
->Width
/ scaled_srcrect
.Width
;
5790 transform
.matrix
[1] = 0.0;
5791 transform
.matrix
[2] = 0.0;
5792 transform
.matrix
[3] = dstrect
->Height
/ scaled_srcrect
.Height
;
5793 transform
.matrix
[4] = dstrect
->X
- scaled_srcrect
.X
;
5794 transform
.matrix
[5] = dstrect
->Y
- scaled_srcrect
.Y
;
5796 GdipMultiplyMatrix(&graphics
->worldtrans
, &transform
, MatrixOrderPrepend
);
5798 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5799 METAFILE_BeginContainer((GpMetafile
*)graphics
->image
, dstrect
, srcrect
, unit
, container
->contid
);
5805 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5807 GpRectF dstrectf
, srcrectf
;
5809 TRACE("(%p, %p, %p, %d, %p)\n", graphics
, dstrect
, srcrect
, unit
, state
);
5811 if (!dstrect
|| !srcrect
)
5812 return InvalidParameter
;
5814 dstrectf
.X
= dstrect
->X
;
5815 dstrectf
.Y
= dstrect
->Y
;
5816 dstrectf
.Width
= dstrect
->Width
;
5817 dstrectf
.Height
= dstrect
->Height
;
5819 srcrectf
.X
= srcrect
->X
;
5820 srcrectf
.Y
= srcrect
->Y
;
5821 srcrectf
.Width
= srcrect
->Width
;
5822 srcrectf
.Height
= srcrect
->Height
;
5824 return GdipBeginContainer(graphics
, &dstrectf
, &srcrectf
, unit
, state
);
5827 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5829 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5830 return NotImplemented
;
5833 static GpStatus
end_container(GpGraphics
*graphics
, GraphicsContainerType type
,
5834 GraphicsContainer state
)
5837 GraphicsContainerItem
*container
, *container2
;
5840 return InvalidParameter
;
5842 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5843 if(container
->contid
== state
&& container
->type
== type
)
5847 /* did not find a matching container */
5848 if(&container
->entry
== &graphics
->containers
)
5851 sts
= restore_container(graphics
, container
);
5855 /* remove all of the containers on top of the found container */
5856 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5857 if(container
->contid
== state
)
5859 list_remove(&container
->entry
);
5860 delete_container(container
);
5863 list_remove(&container
->entry
);
5864 delete_container(container
);
5866 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5867 if (type
== BEGIN_CONTAINER
)
5868 METAFILE_EndContainer((GpMetafile
*)graphics
->image
, state
);
5870 METAFILE_RestoreGraphics((GpMetafile
*)graphics
->image
, state
);
5876 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5878 TRACE("(%p, %x)\n", graphics
, state
);
5879 return end_container(graphics
, BEGIN_CONTAINER
, state
);
5882 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5884 TRACE("(%p, %x)\n", graphics
, state
);
5885 return end_container(graphics
, SAVE_GRAPHICS
, state
);
5888 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5889 REAL sy
, GpMatrixOrder order
)
5893 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5896 return InvalidParameter
;
5901 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5902 stat
= METAFILE_ScaleWorldTransform((GpMetafile
*)graphics
->image
, sx
, sy
, order
);
5908 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5911 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5914 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5916 if(!graphics
|| !srcgraphics
)
5917 return InvalidParameter
;
5919 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5922 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5923 CompositingMode mode
)
5925 TRACE("(%p, %d)\n", graphics
, mode
);
5928 return InvalidParameter
;
5933 if(graphics
->compmode
== mode
)
5936 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5940 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5941 EmfPlusRecordTypeSetCompositingMode
, mode
);
5946 graphics
->compmode
= mode
;
5951 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5952 CompositingQuality quality
)
5954 TRACE("(%p, %d)\n", graphics
, quality
);
5957 return InvalidParameter
;
5962 if(graphics
->compqual
== quality
)
5965 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5969 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5970 EmfPlusRecordTypeSetCompositingQuality
, quality
);
5975 graphics
->compqual
= quality
;
5980 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5981 InterpolationMode mode
)
5983 TRACE("(%p, %d)\n", graphics
, mode
);
5985 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5986 return InvalidParameter
;
5991 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5992 mode
= InterpolationModeBilinear
;
5994 if (mode
== InterpolationModeHighQuality
)
5995 mode
= InterpolationModeHighQualityBicubic
;
5997 if (mode
== graphics
->interpolation
)
6000 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6004 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6005 EmfPlusRecordTypeSetInterpolationMode
, mode
);
6010 graphics
->interpolation
= mode
;
6015 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
6019 TRACE("(%p, %.2f)\n", graphics
, scale
);
6021 if(!graphics
|| (scale
<= 0.0))
6022 return InvalidParameter
;
6027 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6029 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
6034 graphics
->scale
= scale
;
6039 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
6043 TRACE("(%p, %d)\n", graphics
, unit
);
6046 return InvalidParameter
;
6051 if(unit
== UnitWorld
)
6052 return InvalidParameter
;
6054 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6056 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
6061 graphics
->unit
= unit
;
6066 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
6069 TRACE("(%p, %d)\n", graphics
, mode
);
6072 return InvalidParameter
;
6077 if(graphics
->pixeloffset
== mode
)
6080 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6084 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6085 EmfPlusRecordTypeSetPixelOffsetMode
, mode
);
6090 graphics
->pixeloffset
= mode
;
6095 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
6099 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
6102 FIXME("value is unused in rendering\n");
6105 return InvalidParameter
;
6107 graphics
->origin_x
= x
;
6108 graphics
->origin_y
= y
;
6113 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
6115 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
6117 if (!graphics
|| !x
|| !y
)
6118 return InvalidParameter
;
6120 *x
= graphics
->origin_x
;
6121 *y
= graphics
->origin_y
;
6126 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
6128 TRACE("(%p, %d)\n", graphics
, mode
);
6131 return InvalidParameter
;
6136 if(graphics
->smoothing
== mode
)
6139 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6141 BOOL antialias
= (mode
!= SmoothingModeDefault
&&
6142 mode
!= SmoothingModeNone
&& mode
!= SmoothingModeHighSpeed
);
6144 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6145 EmfPlusRecordTypeSetAntiAliasMode
, (mode
<< 1) + antialias
);
6150 graphics
->smoothing
= mode
;
6155 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
6157 TRACE("(%p, %d)\n", graphics
, contrast
);
6160 return InvalidParameter
;
6162 graphics
->textcontrast
= contrast
;
6167 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
6168 TextRenderingHint hint
)
6170 TRACE("(%p, %d)\n", graphics
, hint
);
6172 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
6173 return InvalidParameter
;
6178 if(graphics
->texthint
== hint
)
6181 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6184 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6185 EmfPlusRecordTypeSetTextRenderingHint
, hint
);
6190 graphics
->texthint
= hint
;
6195 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
6199 TRACE("(%p, %p)\n", graphics
, matrix
);
6201 if(!graphics
|| !matrix
)
6202 return InvalidParameter
;
6207 TRACE("%f,%f,%f,%f,%f,%f\n",
6208 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
6209 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
6211 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6212 stat
= METAFILE_SetWorldTransform((GpMetafile
*)graphics
->image
, matrix
);
6218 graphics
->worldtrans
= *matrix
;
6223 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
6224 REAL dy
, GpMatrixOrder order
)
6228 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
6231 return InvalidParameter
;
6236 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6237 stat
= METAFILE_TranslateWorldTransform((GpMetafile
*)graphics
->image
, dx
, dy
, order
);
6243 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
6246 /*****************************************************************************
6247 * GdipSetClipHrgn [GDIPLUS.@]
6249 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
6255 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
6258 return InvalidParameter
;
6263 /* hrgn is in gdi32 device units */
6264 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
6268 status
= get_graphics_transform(graphics
, CoordinateSpaceDevice
, WineCoordinateSpaceGdiDevice
, &transform
);
6271 status
= GdipTransformRegion(region
, &transform
);
6274 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6276 GdipDeleteRegion(region
);
6281 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
6286 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
6289 return InvalidParameter
;
6294 status
= GdipClonePath(path
, &clip_path
);
6297 GpMatrix world_to_device
;
6299 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
6300 CoordinateSpaceWorld
, &world_to_device
);
6301 status
= GdipTransformPath(clip_path
, &world_to_device
);
6303 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
6305 GdipDeletePath(clip_path
);
6310 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
6311 REAL width
, REAL height
,
6318 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6321 return InvalidParameter
;
6326 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6328 status
= METAFILE_SetClipRect((GpMetafile
*)graphics
->image
, x
, y
, width
, height
, mode
);
6336 rect
.Height
= height
;
6337 status
= GdipCreateRegionRect(&rect
, ®ion
);
6340 GpMatrix world_to_device
;
6343 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6344 status
= GdipIsMatrixIdentity(&world_to_device
, &identity
);
6345 if (status
== Ok
&& !identity
)
6346 status
= GdipTransformRegion(region
, &world_to_device
);
6348 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6350 GdipDeleteRegion(region
);
6355 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
6356 INT width
, INT height
,
6359 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6362 return InvalidParameter
;
6367 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
6370 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
6376 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
6378 if(!graphics
|| !region
)
6379 return InvalidParameter
;
6384 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6386 status
= METAFILE_SetClipRegion((GpMetafile
*)graphics
->image
, region
, mode
);
6391 status
= GdipCloneRegion(region
, &clip
);
6394 GpMatrix world_to_device
;
6397 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6398 status
= GdipIsMatrixIdentity(&world_to_device
, &identity
);
6399 if (status
== Ok
&& !identity
)
6400 status
= GdipTransformRegion(clip
, &world_to_device
);
6402 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
6404 GdipDeleteRegion(clip
);
6409 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
6415 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
6417 if(!graphics
|| !pen
|| count
<=0)
6418 return InvalidParameter
;
6423 status
= GdipCreatePath(FillModeAlternate
, &path
);
6424 if (status
!= Ok
) return status
;
6426 status
= GdipAddPathPolygon(path
, points
, count
);
6428 status
= GdipDrawPath(graphics
, pen
, path
);
6430 GdipDeletePath(path
);
6435 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
6442 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
6444 if(count
<=0) return InvalidParameter
;
6445 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6447 for(i
= 0;i
< count
; i
++){
6448 ptf
[i
].X
= (REAL
)points
[i
].X
;
6449 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
6452 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
6458 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
6460 TRACE("(%p, %p)\n", graphics
, dpi
);
6462 if(!graphics
|| !dpi
)
6463 return InvalidParameter
;
6468 *dpi
= graphics
->xres
;
6472 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
6474 TRACE("(%p, %p)\n", graphics
, dpi
);
6476 if(!graphics
|| !dpi
)
6477 return InvalidParameter
;
6482 *dpi
= graphics
->yres
;
6486 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
6487 GpMatrixOrder order
)
6492 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
6494 if(!graphics
|| !matrix
)
6495 return InvalidParameter
;
6500 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6501 ret
= METAFILE_MultiplyWorldTransform((GpMetafile
*)graphics
->image
, matrix
, order
);
6507 m
= graphics
->worldtrans
;
6509 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
6511 graphics
->worldtrans
= m
;
6516 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
6517 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
6519 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
6523 TRACE("(%p, %p)\n", graphics
, hdc
);
6525 if(!graphics
|| !hdc
)
6526 return InvalidParameter
;
6531 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6533 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
6535 else if (!graphics
->hdc
||
6536 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
6538 /* Create a fake HDC and fill it with a constant color. */
6542 BITMAPINFOHEADER bmih
;
6545 stat
= get_graphics_bounds(graphics
, &bounds
);
6549 graphics
->temp_hbitmap_width
= bounds
.Width
;
6550 graphics
->temp_hbitmap_height
= bounds
.Height
;
6552 bmih
.biSize
= sizeof(bmih
);
6553 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
6554 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
6556 bmih
.biBitCount
= 32;
6557 bmih
.biCompression
= BI_RGB
;
6558 bmih
.biSizeImage
= 0;
6559 bmih
.biXPelsPerMeter
= 0;
6560 bmih
.biYPelsPerMeter
= 0;
6562 bmih
.biClrImportant
= 0;
6564 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
6565 (void**)&graphics
->temp_bits
, NULL
, 0);
6567 return GenericError
;
6569 temp_hdc
= CreateCompatibleDC(0);
6572 DeleteObject(hbitmap
);
6573 return GenericError
;
6576 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6577 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
6579 SelectObject(temp_hdc
, hbitmap
);
6581 graphics
->temp_hbitmap
= hbitmap
;
6582 *hdc
= graphics
->temp_hdc
= temp_hdc
;
6586 *hdc
= graphics
->hdc
;
6590 graphics
->busy
= TRUE
;
6595 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
6599 TRACE("(%p, %p)\n", graphics
, hdc
);
6601 if(!graphics
|| !hdc
|| !graphics
->busy
)
6602 return InvalidParameter
;
6604 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6606 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
6608 else if (graphics
->temp_hdc
== hdc
)
6613 /* Find the pixels that have changed, and mark them as opaque. */
6614 pos
= (DWORD
*)graphics
->temp_bits
;
6615 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6617 if (*pos
!= DC_BACKGROUND_KEY
)
6624 /* Write the changed pixels to the real target. */
6625 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
6626 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
6627 graphics
->temp_hbitmap_width
* 4, PixelFormat32bppARGB
);
6630 DeleteDC(graphics
->temp_hdc
);
6631 DeleteObject(graphics
->temp_hbitmap
);
6632 graphics
->temp_hdc
= NULL
;
6633 graphics
->temp_hbitmap
= NULL
;
6635 else if (hdc
!= graphics
->hdc
)
6637 stat
= InvalidParameter
;
6641 graphics
->busy
= FALSE
;
6646 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
6650 GpMatrix device_to_world
;
6652 TRACE("(%p, %p)\n", graphics
, region
);
6654 if(!graphics
|| !region
)
6655 return InvalidParameter
;
6660 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
6663 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
6664 status
= GdipTransformRegion(clip
, &device_to_world
);
6667 GdipDeleteRegion(clip
);
6671 /* free everything except root node and header */
6672 delete_element(®ion
->node
);
6673 memcpy(region
, clip
, sizeof(GpRegion
));
6679 GpStatus
gdi_transform_acquire(GpGraphics
*graphics
)
6681 if (graphics
->gdi_transform_acquire_count
== 0 && graphics
->hdc
)
6683 graphics
->gdi_transform_save
= SaveDC(graphics
->hdc
);
6684 SetGraphicsMode(graphics
->hdc
, GM_COMPATIBLE
);
6685 SetMapMode(graphics
->hdc
, MM_TEXT
);
6686 SetWindowOrgEx(graphics
->hdc
, 0, 0, NULL
);
6687 SetViewportOrgEx(graphics
->hdc
, 0, 0, NULL
);
6689 graphics
->gdi_transform_acquire_count
++;
6693 GpStatus
gdi_transform_release(GpGraphics
*graphics
)
6695 if (graphics
->gdi_transform_acquire_count
<= 0)
6697 ERR("called without matching gdi_transform_acquire\n");
6698 return GenericError
;
6700 if (graphics
->gdi_transform_acquire_count
== 1 && graphics
->hdc
)
6702 RestoreDC(graphics
->hdc
, graphics
->gdi_transform_save
);
6704 graphics
->gdi_transform_acquire_count
--;
6708 GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6709 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
6712 REAL scale_x
, scale_y
;
6714 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
6716 if (dst_space
!= src_space
)
6718 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
6719 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
6721 if(graphics
->unit
!= UnitDisplay
)
6723 scale_x
*= graphics
->scale
;
6724 scale_y
*= graphics
->scale
;
6727 if (dst_space
< src_space
)
6729 /* transform towards world space */
6730 switch ((int)src_space
)
6732 case WineCoordinateSpaceGdiDevice
:
6735 gdixform
= graphics
->gdi_transform
;
6736 stat
= GdipInvertMatrix(&gdixform
);
6739 GdipMultiplyMatrix(matrix
, &gdixform
, MatrixOrderAppend
);
6740 if (dst_space
== CoordinateSpaceDevice
)
6742 /* else fall-through */
6744 case CoordinateSpaceDevice
:
6745 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
6746 if (dst_space
== CoordinateSpacePage
)
6748 /* else fall-through */
6749 case CoordinateSpacePage
:
6751 GpMatrix inverted_transform
= graphics
->worldtrans
;
6752 stat
= GdipInvertMatrix(&inverted_transform
);
6754 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
6761 /* transform towards device space */
6762 switch ((int)src_space
)
6764 case CoordinateSpaceWorld
:
6765 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
6766 if (dst_space
== CoordinateSpacePage
)
6768 /* else fall-through */
6769 case CoordinateSpacePage
:
6770 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
6771 if (dst_space
== CoordinateSpaceDevice
)
6773 /* else fall-through */
6774 case CoordinateSpaceDevice
:
6776 GdipMultiplyMatrix(matrix
, &graphics
->gdi_transform
, MatrixOrderAppend
);
6785 GpStatus
gdip_transform_points(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6786 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6791 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6792 if (stat
!= Ok
) return stat
;
6794 return GdipTransformMatrixPoints(&matrix
, points
, count
);
6797 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6798 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6800 if(!graphics
|| !points
|| count
<= 0 ||
6801 dst_space
< 0 || dst_space
> CoordinateSpaceDevice
||
6802 src_space
< 0 || src_space
> CoordinateSpaceDevice
)
6803 return InvalidParameter
;
6808 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6810 if (src_space
== dst_space
) return Ok
;
6812 return gdip_transform_points(graphics
, dst_space
, src_space
, points
, count
);
6815 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6816 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6822 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6825 return InvalidParameter
;
6827 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6831 for(i
= 0; i
< count
; i
++){
6832 pointsF
[i
].X
= (REAL
)points
[i
].X
;
6833 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
6836 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6839 for(i
= 0; i
< count
; i
++){
6840 points
[i
].X
= gdip_round(pointsF
[i
].X
);
6841 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
6848 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6860 /*****************************************************************************
6861 * GdipTranslateClip [GDIPLUS.@]
6863 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6865 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6868 return InvalidParameter
;
6873 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6876 /*****************************************************************************
6877 * GdipTranslateClipI [GDIPLUS.@]
6879 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6881 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6884 return InvalidParameter
;
6889 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6893 /*****************************************************************************
6894 * GdipMeasureDriverString [GDIPLUS.@]
6896 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6897 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6898 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6900 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6903 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6905 TEXTMETRICW textmetric
;
6906 const WORD
*glyph_indices
;
6907 WORD
*dynamic_glyph_indices
=NULL
;
6908 REAL rel_width
, rel_height
, ascent
, descent
;
6911 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6913 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6914 return InvalidParameter
;
6917 length
= strlenW(text
);
6921 boundingBox
->X
= 0.0;
6922 boundingBox
->Y
= 0.0;
6923 boundingBox
->Width
= 0.0;
6924 boundingBox
->Height
= 0.0;
6927 if (flags
& unsupported_flags
)
6928 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6930 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6932 hdc
= CreateCompatibleDC(0);
6933 SelectObject(hdc
, hfont
);
6935 GetTextMetricsW(hdc
, &textmetric
);
6945 GpMatrix xform
= *matrix
;
6946 GdipTransformMatrixPoints(&xform
, pt
, 3);
6948 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
6949 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6950 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6951 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6952 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6954 if (flags
& DriverStringOptionsCmapLookup
)
6956 glyph_indices
= dynamic_glyph_indices
= heap_alloc_zero(sizeof(WORD
) * length
);
6960 DeleteObject(hfont
);
6964 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6967 glyph_indices
= text
;
6969 min_x
= max_x
= x
= positions
[0].X
;
6970 min_y
= max_y
= y
= positions
[0].Y
;
6972 ascent
= textmetric
.tmAscent
/ rel_height
;
6973 descent
= textmetric
.tmDescent
/ rel_height
;
6975 for (i
=0; i
<length
; i
++)
6980 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6986 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6987 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6989 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6990 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6991 if (min_x
> x
) min_x
= x
;
6993 x
+= char_width
/ rel_width
;
6995 if (max_x
< x
) max_x
= x
;
6998 heap_free(dynamic_glyph_indices
);
7000 DeleteObject(hfont
);
7002 boundingBox
->X
= min_x
;
7003 boundingBox
->Y
= min_y
;
7004 boundingBox
->Width
= max_x
- min_x
;
7005 boundingBox
->Height
= max_y
- min_y
;
7010 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7011 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7012 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7013 INT flags
, GDIPCONST GpMatrix
*matrix
)
7015 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
7023 if (flags
& unsupported_flags
)
7024 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
7026 if (!(flags
& DriverStringOptionsCmapLookup
))
7027 eto_flags
|= ETO_GLYPH_INDEX
;
7029 save_state
= SaveDC(graphics
->hdc
);
7030 SetBkMode(graphics
->hdc
, TRANSPARENT
);
7031 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
7033 status
= get_clip_hrgn(graphics
, &hrgn
);
7037 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
7042 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, &pt
, 1);
7044 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
7045 SelectObject(graphics
->hdc
, hfont
);
7047 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
7049 gdi_transform_acquire(graphics
);
7051 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
7053 gdi_transform_release(graphics
);
7055 RestoreDC(graphics
->hdc
, save_state
);
7057 DeleteObject(hfont
);
7062 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7063 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7064 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7065 INT flags
, GDIPCONST GpMatrix
*matrix
)
7067 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
7069 PointF
*real_positions
, real_position
;
7073 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
7074 DWORD max_glyphsize
=0;
7075 GLYPHMETRICS glyphmetrics
;
7076 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
7079 int text_mask_stride
;
7081 int pixel_data_stride
;
7083 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
7088 if (!(flags
& DriverStringOptionsCmapLookup
))
7089 ggo_flags
|= GGO_GLYPH_INDEX
;
7091 if (flags
& unsupported_flags
)
7092 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
7094 pti
= heap_alloc_zero(sizeof(POINT
) * length
);
7098 if (flags
& DriverStringOptionsRealizedAdvance
)
7100 real_position
= positions
[0];
7102 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, &real_position
, 1);
7103 round_points(pti
, &real_position
, 1);
7107 real_positions
= heap_alloc_zero(sizeof(PointF
) * length
);
7108 if (!real_positions
)
7114 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
7116 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, real_positions
, length
);
7117 round_points(pti
, real_positions
, length
);
7119 heap_free(real_positions
);
7122 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
7124 hdc
= CreateCompatibleDC(0);
7125 SelectObject(hdc
, hfont
);
7127 /* Get the boundaries of the text to be drawn */
7128 for (i
=0; i
<length
; i
++)
7131 int left
, top
, right
, bottom
;
7133 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
7134 &glyphmetrics
, 0, NULL
, &identity
);
7136 if (glyphsize
== GDI_ERROR
)
7138 ERR("GetGlyphOutlineW failed\n");
7141 DeleteObject(hfont
);
7142 return GenericError
;
7145 if (glyphsize
> max_glyphsize
)
7146 max_glyphsize
= glyphsize
;
7150 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7151 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7152 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
7153 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
7155 if (left
< min_x
) min_x
= left
;
7156 if (top
< min_y
) min_y
= top
;
7157 if (right
> max_x
) max_x
= right
;
7158 if (bottom
> max_y
) max_y
= bottom
;
7161 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
7163 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
7164 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
7168 if (max_glyphsize
== 0)
7169 /* Nothing to draw. */
7172 glyph_mask
= heap_alloc_zero(max_glyphsize
);
7173 text_mask
= heap_alloc_zero((max_x
- min_x
) * (max_y
- min_y
));
7174 text_mask_stride
= max_x
- min_x
;
7176 if (!(glyph_mask
&& text_mask
))
7178 heap_free(glyph_mask
);
7179 heap_free(text_mask
);
7182 DeleteObject(hfont
);
7186 /* Generate a mask for the text */
7187 for (i
=0; i
<length
; i
++)
7190 int left
, top
, stride
;
7192 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
7193 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
7195 if (ret
== GDI_ERROR
|| ret
== 0)
7196 continue; /* empty glyph */
7198 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7199 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7200 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
7202 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
7204 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
7205 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
7206 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
7208 *text_val
= min(64, *text_val
+ *glyph_val
);
7217 DeleteObject(hfont
);
7218 heap_free(glyph_mask
);
7220 /* get the brush data */
7221 pixel_data
= heap_alloc_zero(4 * (max_x
- min_x
) * (max_y
- min_y
));
7224 heap_free(text_mask
);
7228 pixel_area
.X
= min_x
;
7229 pixel_area
.Y
= min_y
;
7230 pixel_area
.Width
= max_x
- min_x
;
7231 pixel_area
.Height
= max_y
- min_y
;
7232 pixel_data_stride
= pixel_area
.Width
* 4;
7234 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
7237 heap_free(text_mask
);
7238 heap_free(pixel_data
);
7242 /* multiply the brush data by the mask */
7243 for (y
=0; y
<pixel_area
.Height
; y
++)
7245 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
7246 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
7247 for (x
=0; x
<pixel_area
.Width
; x
++)
7249 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
7255 heap_free(text_mask
);
7257 gdi_transform_acquire(graphics
);
7259 /* draw the result */
7260 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
7261 pixel_area
.Height
, pixel_data_stride
, PixelFormat32bppARGB
);
7263 gdi_transform_release(graphics
);
7265 heap_free(pixel_data
);
7270 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7271 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7272 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7273 INT flags
, GDIPCONST GpMatrix
*matrix
)
7275 GpStatus stat
= NotImplemented
;
7278 length
= strlenW(text
);
7280 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
7281 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
7282 brush
->bt
== BrushTypeSolidColor
&&
7283 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
7284 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7285 brush
, positions
, flags
, matrix
);
7286 if (stat
== NotImplemented
)
7287 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7288 brush
, positions
, flags
, matrix
);
7292 /*****************************************************************************
7293 * GdipDrawDriverString [GDIPLUS.@]
7295 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7296 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
7297 GDIPCONST PointF
*positions
, INT flags
,
7298 GDIPCONST GpMatrix
*matrix
)
7300 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
7302 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
7303 return InvalidParameter
;
7305 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
7306 brush
, positions
, flags
, matrix
);
7309 /*****************************************************************************
7310 * GdipIsVisibleClipEmpty [GDIPLUS.@]
7312 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
7317 TRACE("(%p, %p)\n", graphics
, res
);
7319 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
7322 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
7325 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
7328 GdipDeleteRegion(rgn
);
7332 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
7336 TRACE("(%p) stub\n", graphics
);
7339 FIXME("not implemented\n");
7341 return NotImplemented
;
7344 GpStatus WINGDIPAPI
GdipGraphicsSetAbort(GpGraphics
*graphics
, GdiplusAbort
*pabort
)
7346 TRACE("(%p, %p)\n", graphics
, pabort
);
7349 return InvalidParameter
;
7352 FIXME("Abort callback is not supported.\n");