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
38 #include "gdiplus_private.h"
39 #include "wine/debug.h"
40 #include "wine/list.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
44 /* looks-right constants */
45 #define ANCHOR_WIDTH (2.0)
46 #define MAX_ITERS (50)
48 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
49 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
50 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
51 INT flags
, GDIPCONST GpMatrix
*matrix
);
53 /* Converts from gdiplus path point type to gdi path point type. */
54 static BYTE
convert_path_point_type(BYTE type
)
58 switch(type
& PathPointTypePathTypeMask
){
59 case PathPointTypeBezier
:
62 case PathPointTypeLine
:
65 case PathPointTypeStart
:
69 ERR("Bad point type\n");
73 if(type
& PathPointTypeCloseSubpath
)
74 ret
|= PT_CLOSEFIGURE
;
79 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
85 case BrushTypeSolidColor
:
87 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
91 case BrushTypeHatchFill
:
93 const GpHatch
*hatch
= (const GpHatch
*)brush
;
94 argb
= hatch
->forecol
;
97 case BrushTypeLinearGradient
:
99 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
100 argb
= line
->startcolor
;
103 case BrushTypePathGradient
:
105 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
106 argb
= grad
->centercolor
;
110 FIXME("unhandled brush type %d\n", brush
->bt
);
114 return ARGB2COLORREF(argb
);
117 static BOOL
is_metafile_graphics(const GpGraphics
*graphics
)
119 return graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
;
122 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
);
124 static void init_hatch_palette(ARGB
*hatch_palette
, ARGB fore_color
, ARGB back_color
)
126 /* Pass the center of a 45-degree diagonal line with width of one unit through the
127 * center of a unit square, and the portion of the square that will be covered will
128 * equal sqrt(2) - 1/2. The covered portion for adjacent squares will be 1/4. */
129 hatch_palette
[0] = back_color
;
130 hatch_palette
[1] = blend_colors(back_color
, fore_color
, 0.25);
131 hatch_palette
[2] = blend_colors(back_color
, fore_color
, sqrt(2.0) - 0.5);
132 hatch_palette
[3] = fore_color
;
135 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
, INT origin_x
, INT origin_y
)
138 BITMAPINFOHEADER bmih
;
142 bmih
.biSize
= sizeof(bmih
);
146 bmih
.biBitCount
= 32;
147 bmih
.biCompression
= BI_RGB
;
148 bmih
.biSizeImage
= 0;
150 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
153 const unsigned char *hatch_data
;
155 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
157 ARGB hatch_palette
[4];
158 init_hatch_palette(hatch_palette
, hatch
->forecol
, hatch
->backcol
);
160 /* Anti-aliasing is only specified for diagonal hatch patterns.
161 * This implementation repeats the pattern, shifts as needed,
162 * then uses bitmask 1 to check the pixel value, and the 0x82
163 * bitmask to check the adjacent pixel values, to determine the
164 * degree of shading needed. */
165 for (y
= 0; y
< 8; y
++)
167 const int hy
= (y
+ origin_y
) & 7;
168 const int hx
= origin_x
& 7;
169 unsigned int row
= (0x10101 * hatch_data
[hy
]) >> hx
;
171 for (x
= 0; x
< 8; x
++, row
>>= 1)
175 index
= (row
& 1) ? 2 : (row
& 0x82) ? 1 : 0;
177 index
= (row
& 1) ? 3 : 0;
178 bits
[y
* 8 + 7 - x
] = hatch_palette
[index
];
184 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
186 for (y
= 0; y
< 64; y
++)
187 bits
[y
] = hatch
->forecol
;
194 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
, INT origin_x
, INT origin_y
)
198 case BrushTypeSolidColor
:
200 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
201 lb
->lbStyle
= BS_SOLID
;
202 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
207 case BrushTypeHatchFill
:
209 const GpHatch
*hatch
= (const GpHatch
*)brush
;
212 hbmp
= create_hatch_bitmap(hatch
, origin_x
, origin_y
);
213 if (!hbmp
) return OutOfMemory
;
215 lb
->lbStyle
= BS_PATTERN
;
217 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
222 FIXME("unhandled brush type %d\n", brush
->bt
);
223 lb
->lbStyle
= BS_SOLID
;
224 lb
->lbColor
= get_gdi_brush_color(brush
);
230 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
235 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
241 static HBRUSH
create_gdi_brush(const GpBrush
*brush
, INT origin_x
, INT origin_y
)
246 if (create_gdi_logbrush(brush
, &lb
, origin_x
, origin_y
) != Ok
) return 0;
248 gdibrush
= CreateBrushIndirect(&lb
);
249 free_gdi_logbrush(&lb
);
254 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
259 INT save_state
, i
, numdashes
;
261 DWORD dash_array
[MAX_DASHLEN
];
263 save_state
= SaveDC(graphics
->hdc
);
265 EndPath(graphics
->hdc
);
267 if(pen
->unit
== UnitPixel
){
271 /* Get an estimate for the amount the pen width is affected by the world
272 * transform. (This is similar to what some of the wine drivers do.) */
277 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
278 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
279 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
281 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
,
282 graphics
->xres
, graphics
->printer_display
);
283 width
*= graphics
->scale
;
289 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceDevice
, pt
, 2);
290 width
*= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
291 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
294 if(pen
->dash
== DashStyleCustom
){
295 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
297 TRACE("dashes are: ");
298 for(i
= 0; i
< numdashes
; i
++){
299 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
300 TRACE("%ld, ", dash_array
[i
]);
302 TRACE("\n and the pen style is %x\n", pen
->style
);
304 create_gdi_logbrush(pen
->brush
, &lb
, graphics
->origin_x
, graphics
->origin_y
);
305 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
306 numdashes
, dash_array
);
307 free_gdi_logbrush(&lb
);
311 create_gdi_logbrush(pen
->brush
, &lb
, graphics
->origin_x
, graphics
->origin_y
);
312 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
313 free_gdi_logbrush(&lb
);
316 SelectObject(graphics
->hdc
, gdipen
);
321 static void restore_dc(GpGraphics
*graphics
, INT state
)
323 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
324 RestoreDC(graphics
->hdc
, state
);
327 static void round_points(POINT
*pti
, GpPointF
*ptf
, INT count
)
331 for(i
= 0; i
< count
; i
++){
335 pti
[i
].x
= gdip_round(ptf
[i
].X
);
340 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
344 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
345 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
347 CompositingMode comp_mode
;
348 INT technology
= GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
);
349 INT shadeblendcaps
= GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
);
351 GdipGetCompositingMode(graphics
, &comp_mode
);
353 if ((technology
== DT_RASPRINTER
&& shadeblendcaps
== SB_NONE
)
354 || comp_mode
== CompositingModeSourceCopy
)
356 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
358 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
359 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
365 bf
.BlendOp
= AC_SRC_OVER
;
367 bf
.SourceConstantAlpha
= 255;
368 bf
.AlphaFormat
= AC_SRC_ALPHA
;
370 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
371 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
375 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
382 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceDevice
, &transform
);
385 stat
= GdipIsMatrixIdentity(&transform
, &identity
);
388 stat
= GdipCloneRegion(graphics
->clip
, &rgn
);
393 stat
= GdipTransformRegion(rgn
, &transform
);
396 stat
= GdipGetRegionHRgn(rgn
, NULL
, hrgn
);
398 GdipDeleteRegion(rgn
);
401 if (stat
== Ok
&& graphics
->gdi_clip
)
404 CombineRgn(*hrgn
, *hrgn
, graphics
->gdi_clip
, RGN_AND
);
407 *hrgn
= CreateRectRgn(0,0,0,0);
408 CombineRgn(*hrgn
, graphics
->gdi_clip
, graphics
->gdi_clip
, RGN_COPY
);
415 /* Draw ARGB data to the given graphics object */
416 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
417 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, const PixelFormat fmt
)
419 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
421 CompositingMode comp_mode
= graphics
->compmode
;
423 for (y
=0; y
<src_height
; y
++)
425 for (x
=0; x
<src_width
; x
++)
427 ARGB dst_color
, src_color
;
428 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
430 if (comp_mode
== CompositingModeSourceCopy
)
432 if (!(src_color
& 0xff000000))
433 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, 0);
435 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, src_color
);
439 if (!(src_color
& 0xff000000))
442 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
443 if (fmt
& PixelFormatPAlpha
)
444 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over_fgpremult(dst_color
, src_color
));
446 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
454 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
455 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
459 BITMAPINFOHEADER bih
;
462 hdc
= CreateCompatibleDC(0);
464 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
465 bih
.biWidth
= src_width
;
466 bih
.biHeight
= -src_height
;
469 bih
.biCompression
= BI_RGB
;
471 bih
.biXPelsPerMeter
= 0;
472 bih
.biYPelsPerMeter
= 0;
474 bih
.biClrImportant
= 0;
476 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
477 (void**)&temp_bits
, NULL
, 0);
479 if(!hbitmap
|| !temp_bits
)
482 if ((GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
) == DT_RASPRINTER
&&
483 GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
) ||
484 fmt
& PixelFormatPAlpha
)
485 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
487 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
488 4 * src_width
, src
, src_stride
);
490 SelectObject(hdc
, hbitmap
);
491 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
492 hdc
, 0, 0, src_width
, src_height
);
494 DeleteObject(hbitmap
);
502 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
503 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
, PixelFormat fmt
)
507 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
513 HRGN hrgn
, visible_rgn
;
515 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
519 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
528 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
529 DeleteObject(visible_rgn
);
533 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
535 size
= GetRegionData(hrgn
, 0, NULL
);
537 rgndata
= heap_alloc_zero(size
);
544 GetRegionData(hrgn
, size
, rgndata
);
546 rects
= (RECT
*)rgndata
->Buffer
;
548 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
550 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
551 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
552 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
562 else if (is_metafile_graphics(graphics
))
564 ERR("This should not be used for metafiles; fix caller\n");
565 return NotImplemented
;
572 stat
= get_clip_hrgn(graphics
, &hrgn
);
577 save
= SaveDC(graphics
->hdc
);
579 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
582 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
584 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
585 src_height
, src_stride
, fmt
);
587 RestoreDC(graphics
->hdc
, save
);
595 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
596 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
598 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
, fmt
);
601 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
603 INT start_a
, end_a
, final_a
;
606 pos
= gdip_round(position
* 0xff);
608 start_a
= ((start
>> 24) & 0xff) * (pos
^ 0xff);
609 end_a
= ((end
>> 24) & 0xff) * pos
;
611 final_a
= start_a
+ end_a
;
613 if (final_a
< 0xff) return 0;
615 return (final_a
/ 0xff) << 24 |
616 ((((start
>> 16) & 0xff) * start_a
+ (((end
>> 16) & 0xff) * end_a
)) / final_a
) << 16 |
617 ((((start
>> 8) & 0xff) * start_a
+ (((end
>> 8) & 0xff) * end_a
)) / final_a
) << 8 |
618 (((start
& 0xff) * start_a
+ ((end
& 0xff) * end_a
)) / final_a
);
621 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
625 /* clamp to between 0.0 and 1.0, using the wrap mode */
626 position
= (position
- brush
->rect
.X
) / brush
->rect
.Width
;
627 if (brush
->wrap
== WrapModeTile
)
629 position
= fmodf(position
, 1.0f
);
630 if (position
< 0.0f
) position
+= 1.0f
;
632 else /* WrapModeFlip* */
634 position
= fmodf(position
, 2.0f
);
635 if (position
< 0.0f
) position
+= 2.0f
;
636 if (position
> 1.0f
) position
= 2.0f
- position
;
639 if (brush
->blendcount
== 1)
644 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
647 /* locate the blend positions surrounding this position */
648 while (position
> brush
->blendpos
[i
])
651 /* interpolate between the blend positions */
652 left_blendpos
= brush
->blendpos
[i
-1];
653 left_blendfac
= brush
->blendfac
[i
-1];
654 right_blendpos
= brush
->blendpos
[i
];
655 right_blendfac
= brush
->blendfac
[i
];
656 range
= right_blendpos
- left_blendpos
;
657 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
658 right_blendfac
* (position
- left_blendpos
)) / range
;
661 if (brush
->pblendcount
== 0)
662 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
666 ARGB left_blendcolor
, right_blendcolor
;
667 REAL left_blendpos
, right_blendpos
;
669 /* locate the blend colors surrounding this position */
670 while (blendfac
> brush
->pblendpos
[i
])
673 /* interpolate between the blend colors */
674 left_blendpos
= brush
->pblendpos
[i
-1];
675 left_blendcolor
= brush
->pblendcolor
[i
-1];
676 right_blendpos
= brush
->pblendpos
[i
];
677 right_blendcolor
= brush
->pblendcolor
[i
];
678 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
679 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
683 static BOOL
round_color_matrix(const ColorMatrix
*matrix
, int values
[5][5])
685 /* Convert floating point color matrix to int[5][5], return TRUE if it's an identity */
686 BOOL identity
= TRUE
;
692 if (matrix
->m
[j
][i
] != (i
== j
? 1.0 : 0.0))
694 values
[j
][i
] = gdip_round(matrix
->m
[j
][i
] * 256.0);
700 static ARGB
transform_color(ARGB color
, int matrix
[5][5])
704 unsigned char a
, r
, g
, b
;
706 val
[0] = ((color
>> 16) & 0xff); /* red */
707 val
[1] = ((color
>> 8) & 0xff); /* green */
708 val
[2] = (color
& 0xff); /* blue */
709 val
[3] = ((color
>> 24) & 0xff); /* alpha */
710 val
[4] = 255; /* translation */
717 res
[i
] += matrix
[j
][i
] * val
[j
];
720 a
= min(max(res
[3] / 256, 0), 255);
721 r
= min(max(res
[0] / 256, 0), 255);
722 g
= min(max(res
[1] / 256, 0), 255);
723 b
= min(max(res
[2] / 256, 0), 255);
725 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
728 static BOOL
color_is_gray(ARGB color
)
730 unsigned char r
, g
, b
;
732 r
= (color
>> 16) & 0xff;
733 g
= (color
>> 8) & 0xff;
736 return (r
== g
) && (g
== b
);
739 /* returns preferred pixel format for the applied attributes */
740 PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
741 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
)
746 if ((attributes
->noop
[type
] == IMAGEATTR_NOOP_UNDEFINED
&&
747 attributes
->noop
[ColorAdjustTypeDefault
] == IMAGEATTR_NOOP_SET
) ||
748 (attributes
->noop
[type
] == IMAGEATTR_NOOP_SET
))
751 if (attributes
->colorkeys
[type
].enabled
||
752 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
754 const struct color_key
*key
;
755 BYTE min_blue
, min_green
, min_red
;
756 BYTE max_blue
, max_green
, max_red
;
758 if (!data
|| fmt
!= PixelFormat32bppARGB
)
759 return PixelFormat32bppARGB
;
761 if (attributes
->colorkeys
[type
].enabled
)
762 key
= &attributes
->colorkeys
[type
];
764 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
766 min_blue
= key
->low
&0xff;
767 min_green
= (key
->low
>>8)&0xff;
768 min_red
= (key
->low
>>16)&0xff;
770 max_blue
= key
->high
&0xff;
771 max_green
= (key
->high
>>8)&0xff;
772 max_red
= (key
->high
>>16)&0xff;
774 for (x
=0; x
<width
; x
++)
775 for (y
=0; y
<height
; y
++)
778 BYTE blue
, green
, red
;
779 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
780 blue
= *src_color
&0xff;
781 green
= (*src_color
>>8)&0xff;
782 red
= (*src_color
>>16)&0xff;
783 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
784 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
785 *src_color
= 0x00000000;
789 if (attributes
->colorremaptables
[type
].enabled
||
790 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
792 const struct color_remap_table
*table
;
794 if (!data
|| fmt
!= PixelFormat32bppARGB
)
795 return PixelFormat32bppARGB
;
797 if (attributes
->colorremaptables
[type
].enabled
)
798 table
= &attributes
->colorremaptables
[type
];
800 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
802 for (x
=0; x
<width
; x
++)
803 for (y
=0; y
<height
; y
++)
806 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
807 for (i
=0; i
<table
->mapsize
; i
++)
809 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
811 *src_color
= table
->colormap
[i
].newColor
.Argb
;
818 if (attributes
->colormatrices
[type
].enabled
||
819 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
821 const struct color_matrix
*colormatrices
;
822 int color_matrix
[5][5];
823 int gray_matrix
[5][5];
826 if (!data
|| fmt
!= PixelFormat32bppARGB
)
827 return PixelFormat32bppARGB
;
829 if (attributes
->colormatrices
[type
].enabled
)
830 colormatrices
= &attributes
->colormatrices
[type
];
832 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
834 identity
= round_color_matrix(&colormatrices
->colormatrix
, color_matrix
);
836 if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
837 identity
= (round_color_matrix(&colormatrices
->graymatrix
, gray_matrix
) && identity
);
841 for (x
=0; x
<width
; x
++)
843 for (y
=0; y
<height
; y
++)
846 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
848 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
849 !color_is_gray(*src_color
))
851 *src_color
= transform_color(*src_color
, color_matrix
);
853 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
855 *src_color
= transform_color(*src_color
, gray_matrix
);
862 if (attributes
->gamma_enabled
[type
] ||
863 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
867 if (!data
|| fmt
!= PixelFormat32bppARGB
)
868 return PixelFormat32bppARGB
;
870 if (attributes
->gamma_enabled
[type
])
871 gamma
= attributes
->gamma
[type
];
873 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
875 for (x
=0; x
<width
; x
++)
876 for (y
=0; y
<height
; y
++)
879 BYTE blue
, green
, red
;
880 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
882 blue
= *src_color
&0xff;
883 green
= (*src_color
>>8)&0xff;
884 red
= (*src_color
>>16)&0xff;
886 /* FIXME: We should probably use a table for this. */
887 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
888 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
889 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
891 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
898 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
899 * bitmap that contains all the pixels we may need to draw it. */
900 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
901 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
904 INT left
, top
, right
, bottom
;
906 switch (interpolation
)
908 case InterpolationModeHighQualityBilinear
:
909 case InterpolationModeHighQualityBicubic
:
910 /* FIXME: Include a greater range for the prefilter? */
911 case InterpolationModeBicubic
:
912 case InterpolationModeBilinear
:
913 left
= (INT
)(floorf(srcx
));
914 top
= (INT
)(floorf(srcy
));
915 right
= (INT
)(ceilf(srcx
+srcwidth
));
916 bottom
= (INT
)(ceilf(srcy
+srcheight
));
918 case InterpolationModeNearestNeighbor
:
920 left
= gdip_round(srcx
);
921 top
= gdip_round(srcy
);
922 right
= gdip_round(srcx
+srcwidth
);
923 bottom
= gdip_round(srcy
+srcheight
);
927 if (wrap
== WrapModeClamp
)
933 if (right
>= bitmap
->width
)
934 right
= bitmap
->width
-1;
935 if (bottom
>= bitmap
->height
)
936 bottom
= bitmap
->height
-1;
937 if (bottom
< top
|| right
< left
)
938 /* entirely outside image, just sample a pixel so we don't have to
939 * special-case this later */
940 left
= top
= right
= bottom
= 0;
944 /* In some cases we can make the rectangle smaller here, but the logic
945 * is hard to get right, and tiling suggests we're likely to use the
946 * entire source image. */
947 if (left
< 0 || right
>= bitmap
->width
)
950 right
= bitmap
->width
-1;
953 if (top
< 0 || bottom
>= bitmap
->height
)
956 bottom
= bitmap
->height
-1;
962 rect
->Width
= right
- left
+ 1;
963 rect
->Height
= bottom
- top
+ 1;
966 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
967 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
969 if (attributes
->wrap
== WrapModeClamp
)
971 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
972 return attributes
->outside_color
;
976 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
978 x
= width
*2 + x
% (INT
)(width
* 2);
980 y
= height
*2 + y
% (INT
)(height
* 2);
982 if (attributes
->wrap
& WrapModeTileFlipX
)
984 if ((x
/ width
) % 2 == 0)
987 x
= width
- 1 - x
% width
;
992 if (attributes
->wrap
& WrapModeTileFlipY
)
994 if ((y
/ height
) % 2 == 0)
997 y
= height
- 1 - y
% height
;
1003 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
1005 ERR("out of range pixel requested\n");
1009 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
1012 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
1013 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
1014 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
1018 switch (interpolation
)
1022 FIXME("Unimplemented interpolation %i\n", interpolation
);
1024 case InterpolationModeBilinear
:
1027 INT leftx
, rightx
, topy
, bottomy
;
1028 ARGB topleft
, topright
, bottomleft
, bottomright
;
1032 leftxf
= floorf(point
->X
);
1033 leftx
= (INT
)leftxf
;
1034 rightx
= (INT
)ceilf(point
->X
);
1035 topyf
= floorf(point
->Y
);
1037 bottomy
= (INT
)ceilf(point
->Y
);
1039 if (leftx
== rightx
&& topy
== bottomy
)
1040 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1041 leftx
, topy
, attributes
);
1043 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1044 leftx
, topy
, attributes
);
1045 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1046 rightx
, topy
, attributes
);
1047 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1048 leftx
, bottomy
, attributes
);
1049 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1050 rightx
, bottomy
, attributes
);
1052 x_offset
= point
->X
- leftxf
;
1053 top
= blend_colors(topleft
, topright
, x_offset
);
1054 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
1056 return blend_colors(top
, bottom
, point
->Y
- topyf
);
1058 case InterpolationModeNearestNeighbor
:
1061 switch (offset_mode
)
1064 case PixelOffsetModeNone
:
1065 case PixelOffsetModeHighSpeed
:
1069 case PixelOffsetModeHalf
:
1070 case PixelOffsetModeHighQuality
:
1074 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1075 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
1081 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
1083 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
1086 /* is_fill is TRUE if filling regions, FALSE for drawing primitives */
1087 static BOOL
brush_can_fill_path(GpBrush
*brush
, BOOL is_fill
)
1091 case BrushTypeSolidColor
:
1097 /* cannot draw semi-transparent colors */
1098 return (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000;
1101 case BrushTypeHatchFill
:
1103 GpHatch
*hatch
= (GpHatch
*)brush
;
1104 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
1105 ((hatch
->backcol
& 0xff000000) == 0xff000000);
1107 case BrushTypeLinearGradient
:
1108 case BrushTypeTextureFill
:
1109 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
1115 static GpStatus
brush_fill_path(GpGraphics
*graphics
, GpBrush
*brush
)
1117 GpStatus status
= Ok
;
1120 case BrushTypeSolidColor
:
1122 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1123 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1128 /* partially transparent fill */
1130 if (!SelectClipPath(graphics
->hdc
, RGN_AND
))
1132 status
= GenericError
;
1136 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1138 HDC hdc
= CreateCompatibleDC(NULL
);
1142 status
= OutOfMemory
;
1147 SelectObject(hdc
, bmp
);
1148 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1156 /* else fall through */
1160 HBRUSH gdibrush
, old_brush
;
1162 gdibrush
= create_gdi_brush(brush
, graphics
->origin_x
, graphics
->origin_y
);
1165 status
= OutOfMemory
;
1169 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1170 FillPath(graphics
->hdc
);
1171 SelectObject(graphics
->hdc
, old_brush
);
1172 DeleteObject(gdibrush
);
1180 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1184 case BrushTypeSolidColor
:
1185 case BrushTypeHatchFill
:
1186 case BrushTypeLinearGradient
:
1187 case BrushTypeTextureFill
:
1188 case BrushTypePathGradient
:
1195 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1196 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1200 case BrushTypeSolidColor
:
1203 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1204 for (x
=0; x
<fill_area
->Width
; x
++)
1205 for (y
=0; y
<fill_area
->Height
; y
++)
1206 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1209 case BrushTypeHatchFill
:
1212 GpHatch
*fill
= (GpHatch
*)brush
;
1213 const unsigned char *hatch_data
;
1214 ARGB hatch_palette
[4];
1216 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1217 return NotImplemented
;
1219 init_hatch_palette(hatch_palette
, fill
->forecol
, fill
->backcol
);
1221 /* See create_hatch_bitmap for an explanation of how index is derived. */
1222 for (y
= 0; y
< fill_area
->Height
; y
++, argb_pixels
+= cdwStride
)
1224 const int hy
= ~(y
+ fill_area
->Y
- graphics
->origin_y
) & 7;
1225 const int hx
= graphics
->origin_x
& 7;
1226 const unsigned int row
= (0x10101 * hatch_data
[hy
]) >> hx
;
1228 for (x
= 0; x
< fill_area
->Width
; x
++)
1230 const unsigned int srow
= row
>> (~(x
+ fill_area
->X
) & 7);
1233 index
= (srow
& 1) ? 2 : (srow
& 0x82) ? 1 : 0;
1235 index
= (srow
& 1) ? 3 : 0;
1237 argb_pixels
[x
] = hatch_palette
[index
];
1243 case BrushTypeLinearGradient
:
1245 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1246 GpPointF draw_points
[3];
1250 draw_points
[0].X
= fill_area
->X
;
1251 draw_points
[0].Y
= fill_area
->Y
;
1252 draw_points
[1].X
= fill_area
->X
+1;
1253 draw_points
[1].Y
= fill_area
->Y
;
1254 draw_points
[2].X
= fill_area
->X
;
1255 draw_points
[2].Y
= fill_area
->Y
+1;
1257 /* Transform the points to a co-ordinate space where X is the point's
1258 * position in the gradient, 0.0 being the start point and 1.0 the
1260 stat
= gdip_transform_points(graphics
, CoordinateSpaceWorld
,
1261 WineCoordinateSpaceGdiDevice
, draw_points
, 3);
1265 GpMatrix world_to_gradient
= fill
->transform
;
1267 stat
= GdipInvertMatrix(&world_to_gradient
);
1269 stat
= GdipTransformMatrixPoints(&world_to_gradient
, draw_points
, 3);
1274 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1275 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1277 for (y
=0; y
<fill_area
->Height
; y
++)
1279 for (x
=0; x
<fill_area
->Width
; x
++)
1281 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1283 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1290 case BrushTypeTextureFill
:
1292 GpTexture
*fill
= (GpTexture
*)brush
;
1293 GpPointF draw_points
[3];
1300 if (fill
->image
->type
!= ImageTypeBitmap
)
1302 FIXME("metafile texture brushes not implemented\n");
1303 return NotImplemented
;
1306 bitmap
= (GpBitmap
*)fill
->image
;
1307 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1309 src_area
.X
= src_area
.Y
= 0;
1310 src_area
.Width
= bitmap
->width
;
1311 src_area
.Height
= bitmap
->height
;
1313 draw_points
[0].X
= fill_area
->X
;
1314 draw_points
[0].Y
= fill_area
->Y
;
1315 draw_points
[1].X
= fill_area
->X
+1;
1316 draw_points
[1].Y
= fill_area
->Y
;
1317 draw_points
[2].X
= fill_area
->X
;
1318 draw_points
[2].Y
= fill_area
->Y
+1;
1320 /* Transform the points to the co-ordinate space of the bitmap. */
1321 stat
= gdip_transform_points(graphics
, CoordinateSpaceWorld
,
1322 WineCoordinateSpaceGdiDevice
, draw_points
, 3);
1326 GpMatrix world_to_texture
= fill
->transform
;
1328 stat
= GdipInvertMatrix(&world_to_texture
);
1330 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1333 if (stat
== Ok
&& !fill
->bitmap_bits
)
1335 BitmapData lockeddata
;
1337 fill
->bitmap_bits
= heap_alloc_zero(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1338 if (!fill
->bitmap_bits
)
1343 lockeddata
.Width
= bitmap
->width
;
1344 lockeddata
.Height
= bitmap
->height
;
1345 lockeddata
.Stride
= src_stride
;
1346 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1347 lockeddata
.Scan0
= fill
->bitmap_bits
;
1349 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1350 PixelFormat32bppARGB
, &lockeddata
);
1354 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1357 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1358 bitmap
->width
, bitmap
->height
,
1359 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
1363 heap_free(fill
->bitmap_bits
);
1364 fill
->bitmap_bits
= NULL
;
1370 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1371 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1372 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1373 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1375 for (y
=0; y
<fill_area
->Height
; y
++)
1377 for (x
=0; x
<fill_area
->Width
; x
++)
1380 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1381 point
.Y
= draw_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
1383 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1384 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1385 &point
, fill
->imageattributes
, graphics
->interpolation
,
1386 graphics
->pixeloffset
);
1393 case BrushTypePathGradient
:
1395 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1397 GpMatrix world_to_device
;
1399 int i
, figure_start
=0;
1400 GpPointF start_point
, end_point
, center_point
;
1402 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1403 INT min_y
, max_y
, min_x
, max_x
;
1406 static BOOL transform_fixme_once
;
1408 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1412 FIXME("path gradient focus not implemented\n");
1419 FIXME("path gradient gamma correction not implemented\n");
1422 if (fill
->blendcount
)
1426 FIXME("path gradient blend not implemented\n");
1429 if (fill
->pblendcount
)
1433 FIXME("path gradient preset blend not implemented\n");
1436 if (!transform_fixme_once
)
1438 BOOL is_identity
=TRUE
;
1439 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1442 FIXME("path gradient transform not implemented\n");
1443 transform_fixme_once
= TRUE
;
1447 stat
= GdipClonePath(fill
->path
, &flat_path
);
1452 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
1453 CoordinateSpaceWorld
, &world_to_device
);
1456 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1460 center_point
= fill
->center
;
1461 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1465 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1470 GdipDeletePath(flat_path
);
1474 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1476 int start_center_line
=0, end_center_line
=0;
1477 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1478 REAL center_distance
;
1479 ARGB start_color
, end_color
;
1482 type
= flat_path
->pathdata
.Types
[i
];
1484 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1487 start_point
= flat_path
->pathdata
.Points
[i
];
1489 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1491 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1493 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1494 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1496 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1498 end_point
= flat_path
->pathdata
.Points
[i
+1];
1499 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1504 outer_color
= start_color
;
1506 min_yf
= center_point
.Y
;
1507 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1508 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1510 if (min_yf
< fill_area
->Y
)
1511 min_y
= fill_area
->Y
;
1513 min_y
= (INT
)ceil(min_yf
);
1515 max_yf
= center_point
.Y
;
1516 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1517 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1519 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1520 max_y
= fill_area
->Y
+ fill_area
->Height
;
1522 max_y
= (INT
)ceil(max_yf
);
1524 dy
= end_point
.Y
- start_point
.Y
;
1525 dx
= end_point
.X
- start_point
.X
;
1527 /* This is proportional to the distance from start-end line to center point. */
1528 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1529 dx
* (center_point
.Y
- start_point
.Y
);
1531 for (y
=min_y
; y
<max_y
; y
++)
1535 if (!seen_start
&& yf
>= start_point
.Y
)
1538 start_center_line
^= 1;
1540 if (!seen_end
&& yf
>= end_point
.Y
)
1543 end_center_line
^= 1;
1545 if (!seen_center
&& yf
>= center_point
.Y
)
1548 start_center_line
^= 1;
1549 end_center_line
^= 1;
1552 if (start_center_line
)
1553 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1555 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1557 if (end_center_line
)
1558 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1560 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1562 if (line1_xf
< line2_xf
)
1564 min_x
= (INT
)ceil(line1_xf
);
1565 max_x
= (INT
)ceil(line2_xf
);
1569 min_x
= (INT
)ceil(line2_xf
);
1570 max_x
= (INT
)ceil(line1_xf
);
1573 if (min_x
< fill_area
->X
)
1574 min_x
= fill_area
->X
;
1575 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1576 max_x
= fill_area
->X
+ fill_area
->Width
;
1578 for (x
=min_x
; x
<max_x
; x
++)
1583 if (start_color
!= end_color
)
1585 REAL blend_amount
, pdy
, pdx
;
1586 pdy
= yf
- center_point
.Y
;
1587 pdx
= xf
- center_point
.X
;
1589 if (fabs(pdx
) <= 0.001 && fabs(pdy
) <= 0.001)
1591 /* Too close to center point, don't try to calculate outer color */
1592 outer_color
= start_color
;
1596 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1597 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1601 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1602 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1604 distance
= distance
/ center_distance
;
1606 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1607 blend_colors(outer_color
, fill
->centercolor
, distance
);
1612 GdipDeletePath(flat_path
);
1616 return NotImplemented
;
1620 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1621 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1622 * should not be called on an hdc that has a path you care about. */
1623 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1624 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1626 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1628 HBRUSH brush
= NULL
;
1630 PointF ptf
[4], *custptf
= NULL
;
1631 POINT pt
[4], *custpt
= NULL
;
1633 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1638 if((x1
== x2
) && (y1
== y2
))
1641 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1643 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1645 brush
= CreateSolidBrush(color
);
1646 lb
.lbStyle
= BS_SOLID
;
1649 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1650 PS_JOIN_MITER
, 1, &lb
, 0,
1652 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1653 oldpen
= SelectObject(graphics
->hdc
, pen
);
1660 case LineCapSquareAnchor
:
1661 case LineCapDiamondAnchor
:
1662 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1663 if(cap
== LineCapDiamondAnchor
){
1664 dsmall
= cos(theta
+ M_PI_2
) * size
;
1665 dbig
= sin(theta
+ M_PI_2
) * size
;
1668 dsmall
= cos(theta
+ M_PI_4
) * size
;
1669 dbig
= sin(theta
+ M_PI_4
) * size
;
1672 ptf
[0].X
= x2
- dsmall
;
1673 ptf
[1].X
= x2
+ dbig
;
1675 ptf
[0].Y
= y2
- dbig
;
1676 ptf
[3].Y
= y2
+ dsmall
;
1678 ptf
[1].Y
= y2
- dsmall
;
1679 ptf
[2].Y
= y2
+ dbig
;
1681 ptf
[3].X
= x2
- dbig
;
1682 ptf
[2].X
= x2
+ dsmall
;
1684 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 4);
1686 round_points(pt
, ptf
, 4);
1688 Polygon(graphics
->hdc
, pt
, 4);
1691 case LineCapArrowAnchor
:
1692 size
= size
* 4.0 / sqrt(3.0);
1694 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1695 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1700 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1701 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1709 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1711 round_points(pt
, ptf
, 3);
1713 Polygon(graphics
->hdc
, pt
, 3);
1716 case LineCapRoundAnchor
:
1717 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1724 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 2);
1726 round_points(pt
, ptf
, 2);
1728 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1731 case LineCapTriangle
:
1733 dx
= cos(M_PI_2
+ theta
) * size
;
1734 dy
= sin(M_PI_2
+ theta
) * size
;
1741 dx
= cos(theta
) * size
;
1742 dy
= sin(theta
) * size
;
1747 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1749 round_points(pt
, ptf
, 3);
1751 Polygon(graphics
->hdc
, pt
, 3);
1755 dx
= dy
= size
/ 2.0;
1762 dx
= -cos(M_PI_2
+ theta
) * size
;
1763 dy
= -sin(M_PI_2
+ theta
) * size
;
1770 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 4);
1772 round_points(pt
, ptf
, 4);
1774 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1775 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1782 if (custom
->type
== CustomLineCapTypeAdjustableArrow
)
1784 GpAdjustableArrowCap
*arrow
= (GpAdjustableArrowCap
*)custom
;
1785 if (arrow
->cap
.fill
&& arrow
->height
<= 0.0)
1789 count
= custom
->pathdata
.Count
;
1790 custptf
= heap_alloc_zero(count
* sizeof(PointF
));
1791 custpt
= heap_alloc_zero(count
* sizeof(POINT
));
1792 tp
= heap_alloc_zero(count
);
1794 if(!custptf
|| !custpt
|| !tp
)
1797 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1799 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1800 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1801 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1803 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1804 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1806 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, custptf
, count
);
1808 round_points(custpt
, custptf
, count
);
1810 for(i
= 0; i
< count
; i
++)
1811 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1814 BeginPath(graphics
->hdc
);
1815 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1816 EndPath(graphics
->hdc
);
1817 StrokeAndFillPath(graphics
->hdc
);
1820 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1832 SelectObject(graphics
->hdc
, oldbrush
);
1833 SelectObject(graphics
->hdc
, oldpen
);
1834 DeleteObject(brush
);
1839 /* Shortens the line by the given percent by changing x2, y2.
1840 * If percent is > 1.0 then the line will change direction.
1841 * If percent is negative it can lengthen the line. */
1842 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1844 REAL dist
, theta
, dx
, dy
;
1846 if((y1
== *y2
) && (x1
== *x2
))
1849 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1850 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1851 dx
= cos(theta
) * dist
;
1852 dy
= sin(theta
) * dist
;
1858 /* Shortens the line by the given amount by changing x2, y2.
1859 * If the amount is greater than the distance, the line will become length 0.
1860 * If the amount is negative, it can lengthen the line. */
1861 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1863 REAL dx
, dy
, percent
;
1867 if(dx
== 0 && dy
== 0)
1870 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1877 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1880 /* Conducts a linear search to find the bezier points that will back off
1881 * the endpoint of the curve by a distance of amt. Linear search works
1882 * better than binary in this case because there are multiple solutions,
1883 * and binary searches often find a bad one. I don't think this is what
1884 * Windows does but short of rendering the bezier without GDI's help it's
1885 * the best we can do. If rev then work from the start of the passed points
1886 * instead of the end. */
1887 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1890 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1891 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1900 origx
= pt
[fourth
].X
;
1901 origy
= pt
[fourth
].Y
;
1902 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1904 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1905 /* reset bezier points to original values */
1906 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1907 /* Perform magic on bezier points. Order is important here.*/
1908 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1909 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1910 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1911 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1912 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1913 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1915 dx
= pt
[fourth
].X
- origx
;
1916 dy
= pt
[fourth
].Y
- origy
;
1918 diff
= sqrt(dx
* dx
+ dy
* dy
);
1919 percent
+= 0.0005 * amt
;
1923 /* Draws a combination of bezier curves and lines between points. */
1924 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1925 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1927 POINT
*pti
= heap_alloc_zero(count
* sizeof(POINT
));
1928 BYTE
*tp
= heap_alloc_zero(count
);
1929 GpPointF
*ptcopy
= heap_alloc_zero(count
* sizeof(GpPointF
));
1931 GpStatus status
= GenericError
;
1937 if(!pti
|| !tp
|| !ptcopy
){
1938 status
= OutOfMemory
;
1942 for(i
= 1; i
< count
; i
++){
1943 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1944 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1945 || !(types
[i
+ 2] & PathPointTypeBezier
)){
1946 ERR("Bad bezier points\n");
1953 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1955 /* If we are drawing caps, go through the points and adjust them accordingly,
1956 * and draw the caps. */
1958 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1959 case PathPointTypeBezier
:
1960 if(pen
->endcap
== LineCapArrowAnchor
)
1961 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1962 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1963 shorten_bezier_amt(&ptcopy
[count
- 4],
1964 pen
->width
* pen
->customend
->inset
, FALSE
);
1966 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1967 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1968 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1969 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1972 case PathPointTypeLine
:
1973 if(pen
->endcap
== LineCapArrowAnchor
)
1974 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1975 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1977 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1978 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1979 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1980 pen
->customend
->inset
* pen
->width
);
1982 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1983 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1988 ERR("Bad path last point\n");
1992 /* Find start of points */
1993 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1994 == PathPointTypeStart
); j
++);
1996 switch(types
[j
] & PathPointTypePathTypeMask
){
1997 case PathPointTypeBezier
:
1998 if(pen
->startcap
== LineCapArrowAnchor
)
1999 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
2000 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
2001 shorten_bezier_amt(&ptcopy
[j
- 1],
2002 pen
->width
* pen
->customstart
->inset
, TRUE
);
2004 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
2005 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
2006 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
2007 pt
[j
- 1].X
, pt
[j
- 1].Y
);
2010 case PathPointTypeLine
:
2011 if(pen
->startcap
== LineCapArrowAnchor
)
2012 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
2013 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
2015 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
2016 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
2017 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
2018 pen
->customstart
->inset
* pen
->width
);
2020 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
2021 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
2026 ERR("Bad path points\n");
2031 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptcopy
, count
);
2033 round_points(pti
, ptcopy
, count
);
2035 for(i
= 0; i
< count
; i
++){
2036 tp
[i
] = convert_path_point_type(types
[i
]);
2039 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
2051 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
2055 BeginPath(graphics
->hdc
);
2056 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2057 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2058 EndPath(graphics
->hdc
);
2062 typedef enum GraphicsContainerType
{
2065 } GraphicsContainerType
;
2067 typedef struct _GraphicsContainerItem
{
2069 GraphicsContainer contid
;
2070 GraphicsContainerType type
;
2072 SmoothingMode smoothing
;
2073 CompositingQuality compqual
;
2074 InterpolationMode interpolation
;
2075 CompositingMode compmode
;
2076 TextRenderingHint texthint
;
2079 PixelOffsetMode pixeloffset
;
2081 GpMatrix worldtrans
;
2083 INT origin_x
, origin_y
;
2084 } GraphicsContainerItem
;
2086 static GpStatus
init_container(GraphicsContainerItem
** container
,
2087 GDIPCONST GpGraphics
* graphics
, GraphicsContainerType type
){
2090 *container
= heap_alloc_zero(sizeof(GraphicsContainerItem
));
2094 (*container
)->contid
= graphics
->contid
+ 1;
2095 (*container
)->type
= type
;
2097 (*container
)->smoothing
= graphics
->smoothing
;
2098 (*container
)->compqual
= graphics
->compqual
;
2099 (*container
)->interpolation
= graphics
->interpolation
;
2100 (*container
)->compmode
= graphics
->compmode
;
2101 (*container
)->texthint
= graphics
->texthint
;
2102 (*container
)->scale
= graphics
->scale
;
2103 (*container
)->unit
= graphics
->unit
;
2104 (*container
)->textcontrast
= graphics
->textcontrast
;
2105 (*container
)->pixeloffset
= graphics
->pixeloffset
;
2106 (*container
)->origin_x
= graphics
->origin_x
;
2107 (*container
)->origin_y
= graphics
->origin_y
;
2108 (*container
)->worldtrans
= graphics
->worldtrans
;
2110 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
2112 heap_free(*container
);
2120 static void delete_container(GraphicsContainerItem
* container
)
2122 GdipDeleteRegion(container
->clip
);
2123 heap_free(container
);
2126 static GpStatus
restore_container(GpGraphics
* graphics
,
2127 GDIPCONST GraphicsContainerItem
* container
){
2131 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2132 if(sts
!= Ok
) return sts
;
2134 graphics
->worldtrans
= container
->worldtrans
;
2136 GdipDeleteRegion(graphics
->clip
);
2137 graphics
->clip
= newClip
;
2139 graphics
->contid
= container
->contid
- 1;
2141 graphics
->smoothing
= container
->smoothing
;
2142 graphics
->compqual
= container
->compqual
;
2143 graphics
->interpolation
= container
->interpolation
;
2144 graphics
->compmode
= container
->compmode
;
2145 graphics
->texthint
= container
->texthint
;
2146 graphics
->scale
= container
->scale
;
2147 graphics
->unit
= container
->unit
;
2148 graphics
->textcontrast
= container
->textcontrast
;
2149 graphics
->pixeloffset
= container
->pixeloffset
;
2150 graphics
->origin_x
= container
->origin_x
;
2151 graphics
->origin_y
= container
->origin_y
;
2156 static GpStatus
get_graphics_device_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2162 if(graphics
->hwnd
) {
2163 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2164 return GenericError
;
2166 rect
->X
= wnd_rect
.left
;
2167 rect
->Y
= wnd_rect
.top
;
2168 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2169 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2170 }else if (graphics
->image
){
2171 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2172 if (stat
== Ok
&& unit
!= UnitPixel
)
2173 FIXME("need to convert from unit %i\n", unit
);
2174 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2181 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2182 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2184 rect
->Width
= bmp
.bmWidth
;
2185 rect
->Height
= bmp
.bmHeight
;
2196 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2197 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2203 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2205 GpStatus stat
= get_graphics_device_bounds(graphics
, rect
);
2207 if (stat
== Ok
&& graphics
->hdc
)
2209 GpPointF points
[4], min_point
, max_point
;
2212 points
[0].X
= points
[2].X
= rect
->X
;
2213 points
[0].Y
= points
[1].Y
= rect
->Y
;
2214 points
[1].X
= points
[3].X
= rect
->X
+ rect
->Width
;
2215 points
[2].Y
= points
[3].Y
= rect
->Y
+ rect
->Height
;
2217 gdip_transform_points(graphics
, CoordinateSpaceDevice
, WineCoordinateSpaceGdiDevice
, points
, 4);
2219 min_point
= max_point
= points
[0];
2223 if (points
[i
].X
< min_point
.X
) min_point
.X
= points
[i
].X
;
2224 if (points
[i
].Y
< min_point
.Y
) min_point
.Y
= points
[i
].Y
;
2225 if (points
[i
].X
> max_point
.X
) max_point
.X
= points
[i
].X
;
2226 if (points
[i
].Y
> max_point
.Y
) max_point
.Y
= points
[i
].Y
;
2229 rect
->X
= min_point
.X
;
2230 rect
->Y
= min_point
.Y
;
2231 rect
->Width
= max_point
.X
- min_point
.X
;
2232 rect
->Height
= max_point
.Y
- min_point
.Y
;
2238 /* on success, rgn will contain the region of the graphics object which
2239 * is visible after clipping has been applied */
2240 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2246 /* Ignore graphics image bounds for metafiles */
2247 if (is_metafile_graphics(graphics
))
2248 return GdipCombineRegionRegion(rgn
, graphics
->clip
, CombineModeReplace
);
2250 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2253 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2256 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2259 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2262 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2265 GdipDeleteRegion(tmp
);
2269 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2273 if (font
->unit
== UnitPixel
)
2275 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
, graphics
->printer_display
);
2279 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2280 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
, graphics
->printer_display
);
2282 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
, graphics
->printer_display
);
2285 lf
->lfHeight
= -(height
+ 0.5);
2287 lf
->lfEscapement
= 0;
2288 lf
->lfOrientation
= 0;
2289 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2290 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2291 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2292 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2293 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2294 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2295 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2296 lf
->lfQuality
= DEFAULT_QUALITY
;
2297 lf
->lfPitchAndFamily
= 0;
2298 lstrcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2301 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2302 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2303 LOGFONTW
*lfw_return
, GDIPCONST GpMatrix
*matrix
)
2305 HDC hdc
= CreateCompatibleDC(0);
2307 REAL angle
, rel_width
, rel_height
, font_height
;
2309 HFONT unscaled_font
;
2310 TEXTMETRICW textmet
;
2312 if (font
->unit
== UnitPixel
|| font
->unit
== UnitWorld
)
2313 font_height
= font
->emSize
;
2316 REAL unit_scale
, res
;
2318 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2319 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
, graphics
->printer_display
);
2321 font_height
= font
->emSize
* unit_scale
;
2332 GpMatrix xform
= *matrix
;
2333 GdipTransformMatrixPoints(&xform
, pt
, 3);
2336 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
2337 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2338 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2339 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2340 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2341 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2342 /* If the font unit is not pixels scaling should not be applied */
2343 if (font
->unit
!= UnitPixel
&& font
->unit
!= UnitWorld
)
2345 rel_width
/= graphics
->scale
;
2346 rel_height
/= graphics
->scale
;
2349 get_log_fontW(font
, graphics
, &lfw
);
2350 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2351 unscaled_font
= CreateFontIndirectW(&lfw
);
2353 SelectObject(hdc
, unscaled_font
);
2354 GetTextMetricsW(hdc
, &textmet
);
2356 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2357 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2359 *hfont
= CreateFontIndirectW(&lfw
);
2365 DeleteObject(unscaled_font
);
2368 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2370 TRACE("(%p, %p)\n", hdc
, graphics
);
2372 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2375 static void get_gdi_transform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2379 if (graphics
->hdc
== NULL
)
2381 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2385 GetTransform(graphics
->hdc
, 0x204, &xform
);
2386 GdipSetMatrixElements(matrix
, xform
.eM11
, xform
.eM12
, xform
.eM21
, xform
.eM22
, xform
.eDx
, xform
.eDy
);
2389 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2395 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2398 FIXME("Don't know how to handle parameter hDevice\n");
2403 if(graphics
== NULL
)
2404 return InvalidParameter
;
2406 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2407 if(!*graphics
) return OutOfMemory
;
2409 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2411 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2412 heap_free(*graphics
);
2416 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2417 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2418 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2420 (*graphics
)->alpha_hdc
= 1;
2423 (*graphics
)->hdc
= hdc
;
2424 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2425 (*graphics
)->owndc
= FALSE
;
2426 (*graphics
)->smoothing
= SmoothingModeDefault
;
2427 (*graphics
)->compqual
= CompositingQualityDefault
;
2428 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2429 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2430 (*graphics
)->compmode
= CompositingModeSourceOver
;
2431 (*graphics
)->unit
= UnitDisplay
;
2432 (*graphics
)->scale
= 1.0;
2433 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2434 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2435 (*graphics
)->busy
= FALSE
;
2436 (*graphics
)->textcontrast
= 4;
2437 list_init(&(*graphics
)->containers
);
2438 (*graphics
)->contid
= 0;
2439 (*graphics
)->printer_display
= (GetDeviceCaps(hdc
, TECHNOLOGY
) == DT_RASPRINTER
);
2440 get_gdi_transform(*graphics
, &(*graphics
)->gdi_transform
);
2442 (*graphics
)->gdi_clip
= CreateRectRgn(0,0,0,0);
2443 if (!GetClipRgn(hdc
, (*graphics
)->gdi_clip
))
2445 DeleteObject((*graphics
)->gdi_clip
);
2446 (*graphics
)->gdi_clip
= NULL
;
2449 TRACE("<-- %p\n", *graphics
);
2454 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2458 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2459 if(!*graphics
) return OutOfMemory
;
2461 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2462 GdipSetMatrixElements(&(*graphics
)->gdi_transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2464 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2465 heap_free(*graphics
);
2469 (*graphics
)->hdc
= NULL
;
2470 (*graphics
)->hwnd
= NULL
;
2471 (*graphics
)->owndc
= FALSE
;
2472 (*graphics
)->image
= image
;
2473 /* We have to store the image type here because the image may be freed
2474 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2475 (*graphics
)->image_type
= image
->type
;
2476 (*graphics
)->smoothing
= SmoothingModeDefault
;
2477 (*graphics
)->compqual
= CompositingQualityDefault
;
2478 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2479 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2480 (*graphics
)->compmode
= CompositingModeSourceOver
;
2481 (*graphics
)->unit
= UnitDisplay
;
2482 (*graphics
)->scale
= 1.0;
2483 (*graphics
)->xres
= image
->xres
;
2484 (*graphics
)->yres
= image
->yres
;
2485 (*graphics
)->busy
= FALSE
;
2486 (*graphics
)->textcontrast
= 4;
2487 list_init(&(*graphics
)->containers
);
2488 (*graphics
)->contid
= 0;
2490 TRACE("<-- %p\n", *graphics
);
2495 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2500 TRACE("(%p, %p)\n", hwnd
, graphics
);
2504 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2506 ReleaseDC(hwnd
, hdc
);
2510 (*graphics
)->hwnd
= hwnd
;
2511 (*graphics
)->owndc
= TRUE
;
2516 /* FIXME: no icm handling */
2517 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2519 TRACE("(%p, %p)\n", hwnd
, graphics
);
2521 return GdipCreateFromHWND(hwnd
, graphics
);
2524 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2525 UINT access
, IStream
**stream
)
2530 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2532 if(!stream
|| !filename
)
2533 return InvalidParameter
;
2535 if(access
& GENERIC_WRITE
)
2536 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2537 else if(access
& GENERIC_READ
)
2538 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2540 return InvalidParameter
;
2542 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2544 return hresult_to_status(ret
);
2547 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2549 GraphicsContainerItem
*cont
, *next
;
2551 TRACE("(%p)\n", graphics
);
2553 if(!graphics
) return InvalidParameter
;
2554 if(graphics
->busy
) return ObjectBusy
;
2556 if (is_metafile_graphics(graphics
))
2558 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2563 if (graphics
->temp_hdc
)
2565 DeleteDC(graphics
->temp_hdc
);
2566 graphics
->temp_hdc
= NULL
;
2570 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2572 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2573 list_remove(&cont
->entry
);
2574 delete_container(cont
);
2577 GdipDeleteRegion(graphics
->clip
);
2579 DeleteObject(graphics
->gdi_clip
);
2581 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2582 * do otherwise, but we can't have that in the test suite because it means
2583 * accessing freed memory. */
2584 graphics
->busy
= TRUE
;
2586 heap_free(graphics
);
2591 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2592 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2598 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2599 width
, height
, startAngle
, sweepAngle
);
2601 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2602 return InvalidParameter
;
2607 if (is_metafile_graphics(graphics
))
2609 set_rect(&rect
, x
, y
, width
, height
);
2610 return METAFILE_DrawArc((GpMetafile
*)graphics
->image
, pen
, &rect
, startAngle
, sweepAngle
);
2613 status
= GdipCreatePath(FillModeAlternate
, &path
);
2614 if (status
!= Ok
) return status
;
2616 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2618 status
= GdipDrawPath(graphics
, pen
, path
);
2620 GdipDeletePath(path
);
2624 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2625 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2627 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2628 width
, height
, startAngle
, sweepAngle
);
2630 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2633 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2634 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2638 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2639 x2
, y2
, x3
, y3
, x4
, y4
);
2641 if(!graphics
|| !pen
)
2642 return InvalidParameter
;
2655 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2658 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2659 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2661 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2662 x2
, y2
, x3
, y3
, x4
, y4
);
2664 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2667 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2668 GDIPCONST GpPointF
*points
, INT count
)
2673 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2675 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2676 return InvalidParameter
;
2681 status
= GdipCreatePath(FillModeAlternate
, &path
);
2682 if (status
!= Ok
) return status
;
2684 status
= GdipAddPathBeziers(path
, points
, count
);
2686 status
= GdipDrawPath(graphics
, pen
, path
);
2688 GdipDeletePath(path
);
2692 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2693 GDIPCONST GpPoint
*points
, INT count
)
2699 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2701 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2702 return InvalidParameter
;
2707 pts
= heap_alloc_zero(sizeof(GpPointF
) * count
);
2711 for(i
= 0; i
< count
; i
++){
2712 pts
[i
].X
= (REAL
)points
[i
].X
;
2713 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2716 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2723 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2724 GDIPCONST GpPointF
*points
, INT count
)
2726 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2728 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2731 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2732 GDIPCONST GpPoint
*points
, INT count
)
2734 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2736 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2739 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2740 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2745 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2747 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2748 return InvalidParameter
;
2753 status
= GdipCreatePath(FillModeAlternate
, &path
);
2754 if (status
!= Ok
) return status
;
2756 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2758 status
= GdipDrawPath(graphics
, pen
, path
);
2760 GdipDeletePath(path
);
2765 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2766 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2772 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2774 if(!points
|| count
<= 0)
2775 return InvalidParameter
;
2777 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2781 for(i
= 0; i
< count
; i
++){
2782 ptf
[i
].X
= (REAL
)points
[i
].X
;
2783 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2786 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2793 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2794 GDIPCONST GpPointF
*points
, INT count
)
2796 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2798 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2801 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2802 GDIPCONST GpPoint
*points
, INT count
)
2808 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2811 return InvalidParameter
;
2813 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2817 for(i
= 0; i
< count
; i
++){
2818 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2819 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2822 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2828 /* Approximates cardinal spline with Bezier curves. */
2829 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2830 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2835 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2837 if(!graphics
|| !pen
)
2838 return InvalidParameter
;
2844 return InvalidParameter
;
2846 status
= GdipCreatePath(FillModeAlternate
, &path
);
2847 if (status
!= Ok
) return status
;
2849 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2851 status
= GdipDrawPath(graphics
, pen
, path
);
2853 GdipDeletePath(path
);
2857 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2858 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2864 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2867 return InvalidParameter
;
2869 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2873 for(i
= 0; i
< count
; i
++){
2874 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2875 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2878 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2884 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2885 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2888 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2890 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2891 return InvalidParameter
;
2894 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2897 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2898 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2901 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2907 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2908 return InvalidParameter
;
2911 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2914 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2915 REAL y
, REAL width
, REAL height
)
2921 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2923 if(!graphics
|| !pen
)
2924 return InvalidParameter
;
2929 if (is_metafile_graphics(graphics
))
2931 set_rect(&rect
, x
, y
, width
, height
);
2932 return METAFILE_DrawEllipse((GpMetafile
*)graphics
->image
, pen
, &rect
);
2935 status
= GdipCreatePath(FillModeAlternate
, &path
);
2936 if (status
!= Ok
) return status
;
2938 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2940 status
= GdipDrawPath(graphics
, pen
, path
);
2942 GdipDeletePath(path
);
2946 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2947 INT y
, INT width
, INT height
)
2949 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2951 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2955 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2959 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2961 if(!graphics
|| !image
)
2962 return InvalidParameter
;
2964 GdipGetImageWidth(image
, &width
);
2965 GdipGetImageHeight(image
, &height
);
2967 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2968 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2971 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2974 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2976 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2979 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2980 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2984 REAL scale_x
, scale_y
, width
, height
;
2986 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2988 if (!graphics
|| !image
) return InvalidParameter
;
2990 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
, graphics
->printer_display
);
2991 scale_x
*= graphics
->xres
/ image
->xres
;
2992 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
, graphics
->printer_display
);
2993 scale_y
*= graphics
->yres
/ image
->yres
;
2994 width
= srcwidth
* scale_x
;
2995 height
= srcheight
* scale_y
;
2997 points
[0].X
= points
[2].X
= x
;
2998 points
[0].Y
= points
[1].Y
= y
;
2999 points
[1].X
= x
+ width
;
3000 points
[2].Y
= y
+ height
;
3002 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3003 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
3006 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
3007 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
3010 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
3013 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
3014 GDIPCONST GpPointF
*dstpoints
, INT count
)
3018 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
3021 return InvalidParameter
;
3023 GdipGetImageWidth(image
, &width
);
3024 GdipGetImageHeight(image
, &height
);
3026 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
3027 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
3030 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
3031 GDIPCONST GpPoint
*dstpoints
, INT count
)
3035 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
3037 if (count
!= 3 || !dstpoints
)
3038 return InvalidParameter
;
3040 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
3041 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
3042 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
3043 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
3044 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
3045 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
3047 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
3050 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
3051 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
3053 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
3057 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
3058 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
3059 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3060 DrawImageAbort callback
, VOID
* callbackData
)
3066 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
3067 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3071 return NotImplemented
;
3073 if(!graphics
|| !image
|| !points
|| count
!= 3)
3074 return InvalidParameter
;
3076 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
3077 debugstr_pointf(&points
[2]));
3079 if (is_metafile_graphics(graphics
))
3081 return METAFILE_DrawImagePointsRect((GpMetafile
*)graphics
->image
,
3082 image
, points
, count
, srcx
, srcy
, srcwidth
, srcheight
,
3083 srcUnit
, imageAttributes
, callback
, callbackData
);
3086 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
3088 /* Ensure source width/height is positive */
3091 GpPointF tmp
= ptf
[1];
3092 srcx
= srcx
+ srcwidth
;
3093 srcwidth
= -srcwidth
;
3094 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
3095 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
3102 GpPointF tmp
= ptf
[2];
3103 srcy
= srcy
+ srcheight
;
3104 srcheight
= -srcheight
;
3105 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
3106 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
3111 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
3112 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
3113 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
3115 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 4);
3116 round_points(pti
, ptf
, 4);
3118 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
3119 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
3121 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
, graphics
->printer_display
);
3122 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
, graphics
->printer_display
);
3123 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
, graphics
->printer_display
);
3124 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
, graphics
->printer_display
);
3125 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
3127 if (image
->type
== ImageTypeBitmap
)
3129 GpBitmap
* bitmap
= (GpBitmap
*)image
;
3130 BOOL do_resampling
= FALSE
;
3131 BOOL use_software
= FALSE
;
3133 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08lx\n",
3134 graphics
->xres
, graphics
->yres
,
3135 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
3136 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
3137 imageAttributes
? imageAttributes
->outside_color
: 0);
3139 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
3140 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
3141 srcx
< 0 || srcy
< 0 ||
3142 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
3143 do_resampling
= TRUE
;
3145 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
3146 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
3147 use_software
= TRUE
;
3152 GpRectF graphics_bounds
;
3154 int i
, x
, y
, src_stride
, dst_stride
;
3155 GpMatrix dst_to_src
;
3156 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
3157 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
3158 BitmapData lockeddata
;
3159 InterpolationMode interpolation
= graphics
->interpolation
;
3160 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
3161 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3162 REAL x_dx
, x_dy
, y_dx
, y_dy
;
3163 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
3165 if (!imageAttributes
)
3166 imageAttributes
= &defaultImageAttributes
;
3168 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3169 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3172 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3173 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3174 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3175 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3178 stat
= get_graphics_device_bounds(graphics
, &graphics_bounds
);
3179 if (stat
!= Ok
) return stat
;
3181 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
3182 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
3183 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
3184 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
3186 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
3188 if (IsRectEmpty(&dst_area
)) return Ok
;
3190 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3191 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3192 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3193 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3194 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3195 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3197 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
3199 stat
= GdipInvertMatrix(&dst_to_src
);
3200 if (stat
!= Ok
) return stat
;
3204 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3205 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3209 /* Make sure src_area is equal in size to dst_area. */
3210 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
3211 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
3212 src_area
.Width
= dst_area
.right
- dst_area
.left
;
3213 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
3216 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3218 src_data
= heap_alloc_zero(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3221 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3223 /* Read the bits we need from the source bitmap into a compatible buffer. */
3224 lockeddata
.Width
= src_area
.Width
;
3225 lockeddata
.Height
= src_area
.Height
;
3226 lockeddata
.Stride
= src_stride
;
3227 lockeddata
.Scan0
= src_data
;
3228 if (!do_resampling
&& bitmap
->format
== PixelFormat32bppPARGB
)
3229 lockeddata
.PixelFormat
= apply_image_attributes(imageAttributes
, NULL
, 0, 0, 0, ColorAdjustTypeBitmap
, bitmap
->format
);
3231 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3233 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3234 lockeddata
.PixelFormat
, &lockeddata
);
3237 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3241 heap_free(src_data
);
3245 apply_image_attributes(imageAttributes
, src_data
,
3246 src_area
.Width
, src_area
.Height
,
3247 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
3251 /* Transform the bits as needed to the destination. */
3252 dst_data
= dst_dyn_data
= heap_alloc_zero(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3255 heap_free(src_data
);
3259 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3261 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3263 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3264 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3265 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3266 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3268 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3270 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3272 GpPointF src_pointf
;
3275 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3276 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3278 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3280 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3281 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3282 imageAttributes
, interpolation
, offset_mode
);
3290 dst_data
= src_data
;
3291 dst_stride
= src_stride
;
3294 gdi_transform_acquire(graphics
);
3296 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3297 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
,
3298 lockeddata
.PixelFormat
);
3300 gdi_transform_release(graphics
);
3302 heap_free(src_data
);
3304 heap_free(dst_dyn_data
);
3311 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3312 HBITMAP hbitmap
, old_hbm
=NULL
;
3316 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3317 bitmap
->format
== PixelFormat24bppRGB
||
3318 bitmap
->format
== PixelFormat32bppRGB
||
3319 bitmap
->format
== PixelFormat32bppPARGB
))
3321 BITMAPINFOHEADER bih
;
3323 PixelFormat dst_format
;
3325 /* we can't draw a bitmap of this format directly */
3326 hdc
= CreateCompatibleDC(0);
3330 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3331 bih
.biWidth
= bitmap
->width
;
3332 bih
.biHeight
= -bitmap
->height
;
3334 bih
.biBitCount
= 32;
3335 bih
.biCompression
= BI_RGB
;
3336 bih
.biSizeImage
= 0;
3337 bih
.biXPelsPerMeter
= 0;
3338 bih
.biYPelsPerMeter
= 0;
3340 bih
.biClrImportant
= 0;
3342 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3343 (void**)&temp_bits
, NULL
, 0);
3345 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3346 dst_format
= PixelFormat32bppPARGB
;
3348 dst_format
= PixelFormat32bppRGB
;
3350 convert_pixels(bitmap
->width
, bitmap
->height
,
3351 bitmap
->width
*4, temp_bits
, dst_format
, bitmap
->image
.palette
,
3352 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3353 bitmap
->image
.palette
);
3357 if (bitmap
->hbitmap
)
3358 hbitmap
= bitmap
->hbitmap
;
3361 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3366 temp_hdc
= (hdc
== 0);
3371 if (!hdc
) hdc
= CreateCompatibleDC(0);
3372 old_hbm
= SelectObject(hdc
, hbitmap
);
3375 save_state
= SaveDC(graphics
->hdc
);
3377 stat
= get_clip_hrgn(graphics
, &hrgn
);
3381 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
3385 gdi_transform_acquire(graphics
);
3387 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3389 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3390 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3394 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3395 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3398 gdi_transform_release(graphics
);
3400 RestoreDC(graphics
->hdc
, save_state
);
3404 SelectObject(hdc
, old_hbm
);
3409 DeleteObject(hbitmap
);
3412 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3416 set_rect(&rc
, srcx
, srcy
, srcwidth
, srcheight
);
3417 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3418 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3422 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3423 return InvalidParameter
;
3429 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3430 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3431 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3432 DrawImageAbort callback
, VOID
* callbackData
)
3434 GpPointF pointsF
[3];
3437 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3438 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3441 if(!points
|| count
!=3)
3442 return InvalidParameter
;
3444 for(i
= 0; i
< count
; i
++){
3445 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3446 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3449 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3450 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3451 callback
, callbackData
);
3454 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3455 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3456 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3457 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3458 VOID
* callbackData
)
3462 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3463 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3464 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3468 points
[1].X
= dstx
+ dstwidth
;
3471 points
[2].Y
= dsty
+ dstheight
;
3473 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3474 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3477 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3478 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3479 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3480 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3481 VOID
* callbackData
)
3485 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3486 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3487 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3491 points
[1].X
= dstx
+ dstwidth
;
3494 points
[2].Y
= dsty
+ dstheight
;
3496 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3497 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3500 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3501 REAL x
, REAL y
, REAL width
, REAL height
)
3507 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3509 if(!graphics
|| !image
)
3510 return InvalidParameter
;
3512 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3516 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3517 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3518 unit
, NULL
, NULL
, NULL
);
3521 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3522 INT x
, INT y
, INT width
, INT height
)
3524 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3526 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3529 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3530 REAL y1
, REAL x2
, REAL y2
)
3534 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3537 return InvalidParameter
;
3539 if (pen
->unit
== UnitPixel
&& pen
->width
<= 0.0)
3546 return GdipDrawLines(graphics
, pen
, pt
, 2);
3549 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3550 INT y1
, INT x2
, INT y2
)
3552 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3554 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3557 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3558 GpPointF
*points
, INT count
)
3563 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3565 if(!pen
|| !graphics
|| (count
< 2))
3566 return InvalidParameter
;
3571 status
= GdipCreatePath(FillModeAlternate
, &path
);
3572 if (status
!= Ok
) return status
;
3574 status
= GdipAddPathLine2(path
, points
, count
);
3576 status
= GdipDrawPath(graphics
, pen
, path
);
3578 GdipDeletePath(path
);
3582 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3583 GpPoint
*points
, INT count
)
3589 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3591 ptf
= heap_alloc_zero(count
* sizeof(GpPointF
));
3592 if(!ptf
) return OutOfMemory
;
3594 for(i
= 0; i
< count
; i
++){
3595 ptf
[i
].X
= (REAL
) points
[i
].X
;
3596 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3599 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3605 static GpStatus
GDI32_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3611 save_state
= prepare_dc(graphics
, pen
);
3613 retval
= get_clip_hrgn(graphics
, &hrgn
);
3618 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
3620 gdi_transform_acquire(graphics
);
3622 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3623 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3625 gdi_transform_release(graphics
);
3628 restore_dc(graphics
, save_state
);
3634 static GpStatus
SOFTWARE_GdipDrawThinPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3638 GpMatrix
* transform
;
3639 GpRectF gp_bound_rect
;
3640 GpRect gp_output_area
;
3642 INT output_height
, output_width
;
3643 DWORD
*output_bits
, *brush_bits
=NULL
;
3645 static const BYTE static_dash_pattern
[] = {1,1,1,0,1,0,1,0};
3646 const BYTE
*dash_pattern
;
3647 INT dash_pattern_size
;
3648 BYTE
*dyn_dash_pattern
= NULL
;
3650 stat
= GdipClonePath(path
, &flat_path
);
3655 stat
= GdipCreateMatrix(&transform
);
3659 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3660 CoordinateSpaceWorld
, transform
);
3663 stat
= GdipFlattenPath(flat_path
, transform
, 1.0);
3665 GdipDeleteMatrix(transform
);
3668 /* estimate the output size in pixels, can be larger than necessary */
3671 output_area
.left
= floorf(flat_path
->pathdata
.Points
[0].X
);
3672 output_area
.right
= ceilf(flat_path
->pathdata
.Points
[0].X
);
3673 output_area
.top
= floorf(flat_path
->pathdata
.Points
[0].Y
);
3674 output_area
.bottom
= ceilf(flat_path
->pathdata
.Points
[0].Y
);
3676 for (i
=1; i
<flat_path
->pathdata
.Count
; i
++)
3679 x
= flat_path
->pathdata
.Points
[i
].X
;
3680 y
= flat_path
->pathdata
.Points
[i
].Y
;
3682 if (floorf(x
) < output_area
.left
) output_area
.left
= floorf(x
);
3683 if (floorf(y
) < output_area
.top
) output_area
.top
= floorf(y
);
3684 if (ceilf(x
) > output_area
.right
) output_area
.right
= ceilf(x
);
3685 if (ceilf(y
) > output_area
.bottom
) output_area
.bottom
= ceilf(y
);
3688 stat
= get_graphics_device_bounds(graphics
, &gp_bound_rect
);
3693 output_area
.left
= max(output_area
.left
, floorf(gp_bound_rect
.X
));
3694 output_area
.top
= max(output_area
.top
, floorf(gp_bound_rect
.Y
));
3695 output_area
.right
= min(output_area
.right
, ceilf(gp_bound_rect
.X
+ gp_bound_rect
.Width
));
3696 output_area
.bottom
= min(output_area
.bottom
, ceilf(gp_bound_rect
.Y
+ gp_bound_rect
.Height
));
3698 output_width
= output_area
.right
- output_area
.left
+ 1;
3699 output_height
= output_area
.bottom
- output_area
.top
+ 1;
3701 if (output_width
<= 0 || output_height
<= 0)
3703 GdipDeletePath(flat_path
);
3707 gp_output_area
.X
= output_area
.left
;
3708 gp_output_area
.Y
= output_area
.top
;
3709 gp_output_area
.Width
= output_width
;
3710 gp_output_area
.Height
= output_height
;
3712 output_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3719 if (pen
->brush
->bt
!= BrushTypeSolidColor
)
3721 /* allocate and draw brush output */
3722 brush_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3726 stat
= brush_fill_pixels(graphics
, pen
->brush
, brush_bits
,
3727 &gp_output_area
, output_width
);
3735 /* convert dash pattern to bool array */
3738 case DashStyleCustom
:
3740 dash_pattern_size
= 0;
3742 for (i
=0; i
< pen
->numdashes
; i
++)
3743 dash_pattern_size
+= gdip_round(pen
->dashes
[i
]);
3745 if (dash_pattern_size
!= 0)
3747 dash_pattern
= dyn_dash_pattern
= heap_alloc(dash_pattern_size
);
3749 if (dyn_dash_pattern
)
3752 for (i
=0; i
< pen
->numdashes
; i
++)
3755 for (k
=0; k
< gdip_round(pen
->dashes
[i
]); k
++)
3756 dyn_dash_pattern
[j
++] = (i
&1)^1;
3764 /* else fall through */
3766 case DashStyleSolid
:
3768 dash_pattern
= static_dash_pattern
;
3769 dash_pattern_size
= 1;
3772 dash_pattern
= static_dash_pattern
;
3773 dash_pattern_size
= 4;
3776 dash_pattern
= &static_dash_pattern
[4];
3777 dash_pattern_size
= 2;
3779 case DashStyleDashDot
:
3780 dash_pattern
= static_dash_pattern
;
3781 dash_pattern_size
= 6;
3783 case DashStyleDashDotDot
:
3784 dash_pattern
= static_dash_pattern
;
3785 dash_pattern_size
= 8;
3793 GpPointF subpath_start
= flat_path
->pathdata
.Points
[0];
3794 INT prev_x
= INT_MAX
, prev_y
= INT_MAX
;
3795 int dash_pos
= dash_pattern_size
- 1;
3797 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
3800 GpPointF start_point
, end_point
;
3801 GpPoint start_pointi
, end_pointi
;
3803 type
= flat_path
->pathdata
.Types
[i
];
3804 if (i
+1 < flat_path
->pathdata
.Count
)
3805 type2
= flat_path
->pathdata
.Types
[i
+1];
3807 type2
= PathPointTypeStart
;
3809 start_point
= flat_path
->pathdata
.Points
[i
];
3811 if ((type
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3812 subpath_start
= start_point
;
3814 if ((type
& PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
3815 end_point
= subpath_start
;
3816 else if ((type2
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3819 end_point
= flat_path
->pathdata
.Points
[i
+1];
3821 start_pointi
.X
= floorf(start_point
.X
);
3822 start_pointi
.Y
= floorf(start_point
.Y
);
3823 end_pointi
.X
= floorf(end_point
.X
);
3824 end_pointi
.Y
= floorf(end_point
.Y
);
3826 if(start_pointi
.X
== end_pointi
.X
&& start_pointi
.Y
== end_pointi
.Y
)
3829 /* draw line segment */
3830 if (abs(start_pointi
.Y
- end_pointi
.Y
) > abs(start_pointi
.X
- end_pointi
.X
))
3832 INT x
, y
, start_y
, end_y
, step
;
3834 if (start_pointi
.Y
< end_pointi
.Y
)
3837 start_y
= ceilf(start_point
.Y
) - output_area
.top
;
3838 end_y
= end_pointi
.Y
- output_area
.top
;
3843 start_y
= start_point
.Y
- output_area
.top
;
3844 end_y
= ceilf(end_point
.Y
) - output_area
.top
;
3847 for (y
=start_y
; y
!= (end_y
+step
); y
+=step
)
3849 x
= gdip_round( start_point
.X
+
3850 (end_point
.X
- start_point
.X
) * (y
+ output_area
.top
- start_point
.Y
) / (end_point
.Y
- start_point
.Y
) )
3853 if (x
== prev_x
&& y
== prev_y
)
3858 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3860 if (!dash_pattern
[dash_pos
])
3863 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3867 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3869 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3874 INT x
, y
, start_x
, end_x
, step
;
3876 if (start_pointi
.X
< end_pointi
.X
)
3879 start_x
= ceilf(start_point
.X
) - output_area
.left
;
3880 end_x
= end_pointi
.X
- output_area
.left
;
3885 start_x
= start_point
.X
- output_area
.left
;
3886 end_x
= ceilf(end_point
.X
) - output_area
.left
;
3889 for (x
=start_x
; x
!= (end_x
+step
); x
+=step
)
3891 y
= gdip_round( start_point
.Y
+
3892 (end_point
.Y
- start_point
.Y
) * (x
+ output_area
.left
- start_point
.X
) / (end_point
.X
- start_point
.X
) )
3895 if (x
== prev_x
&& y
== prev_y
)
3900 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3902 if (!dash_pattern
[dash_pos
])
3905 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3909 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3911 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3917 /* draw output image */
3920 gdi_transform_acquire(graphics
);
3922 stat
= alpha_blend_pixels(graphics
, output_area
.left
, output_area
.top
,
3923 (BYTE
*)output_bits
, output_width
, output_height
, output_width
* 4,
3924 PixelFormat32bppARGB
);
3926 gdi_transform_release(graphics
);
3929 heap_free(brush_bits
);
3930 heap_free(dyn_dash_pattern
);
3931 heap_free(output_bits
);
3934 GdipDeletePath(flat_path
);
3939 static GpStatus
SOFTWARE_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3943 GpMatrix
*transform
=NULL
;
3946 /* Check if the final pen thickness in pixels is too thin. */
3947 if (pen
->unit
== UnitPixel
)
3949 if (pen
->width
< 1.415)
3950 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3954 GpPointF points
[3] = {{0,0}, {1,0}, {0,1}};
3956 points
[1].X
= pen
->width
;
3957 points
[2].Y
= pen
->width
;
3959 stat
= gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
,
3960 CoordinateSpaceWorld
, points
, 3);
3965 if (((points
[1].X
-points
[0].X
)*(points
[1].X
-points
[0].X
) +
3966 (points
[1].Y
-points
[0].Y
)*(points
[1].Y
-points
[0].Y
) < 2.0001) &&
3967 ((points
[2].X
-points
[0].X
)*(points
[2].X
-points
[0].X
) +
3968 (points
[2].Y
-points
[0].Y
)*(points
[2].Y
-points
[0].Y
) < 2.0001))
3969 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3972 stat
= GdipClonePath(path
, &wide_path
);
3977 if (pen
->unit
== UnitPixel
)
3979 /* We have to transform this to device coordinates to get the widths right. */
3980 stat
= GdipCreateMatrix(&transform
);
3983 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3984 CoordinateSpaceWorld
, transform
);
3988 /* Set flatness based on the final coordinate space */
3991 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3992 CoordinateSpaceWorld
, &t
);
3997 flatness
= 1.0/sqrt(fmax(
3998 t
.matrix
[0] * t
.matrix
[0] + t
.matrix
[1] * t
.matrix
[1],
3999 t
.matrix
[2] * t
.matrix
[2] + t
.matrix
[3] * t
.matrix
[3]));
4003 stat
= GdipWidenPath(wide_path
, pen
, transform
, flatness
);
4005 if (pen
->unit
== UnitPixel
)
4007 /* Transform the path back to world coordinates */
4009 stat
= GdipInvertMatrix(transform
);
4012 stat
= GdipTransformPath(wide_path
, transform
);
4015 /* Actually draw the path */
4017 stat
= GdipFillPath(graphics
, pen
->brush
, wide_path
);
4019 GdipDeleteMatrix(transform
);
4021 GdipDeletePath(wide_path
);
4026 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
4030 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
4032 if(!pen
|| !graphics
)
4033 return InvalidParameter
;
4038 if (path
->pathdata
.Count
== 0)
4041 if (is_metafile_graphics(graphics
))
4042 retval
= METAFILE_DrawPath((GpMetafile
*)graphics
->image
, pen
, path
);
4043 else if (!graphics
->hdc
|| graphics
->alpha_hdc
|| !brush_can_fill_path(pen
->brush
, FALSE
))
4044 retval
= SOFTWARE_GdipDrawPath(graphics
, pen
, path
);
4046 retval
= GDI32_GdipDrawPath(graphics
, pen
, path
);
4051 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
4052 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4057 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
4058 width
, height
, startAngle
, sweepAngle
);
4060 if(!graphics
|| !pen
)
4061 return InvalidParameter
;
4066 status
= GdipCreatePath(FillModeAlternate
, &path
);
4067 if (status
!= Ok
) return status
;
4069 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4071 status
= GdipDrawPath(graphics
, pen
, path
);
4073 GdipDeletePath(path
);
4077 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
4078 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4080 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
4081 width
, height
, startAngle
, sweepAngle
);
4083 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4086 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
4087 REAL y
, REAL width
, REAL height
)
4091 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
4093 set_rect(&rect
, x
, y
, width
, height
);
4094 return GdipDrawRectangles(graphics
, pen
, &rect
, 1);
4097 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
4098 INT y
, INT width
, INT height
)
4100 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
4102 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
4105 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
4106 GDIPCONST GpRectF
* rects
, INT count
)
4111 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
4113 if(!graphics
|| !pen
|| !rects
|| count
< 1)
4114 return InvalidParameter
;
4119 if (is_metafile_graphics(graphics
))
4120 return METAFILE_DrawRectangles((GpMetafile
*)graphics
->image
, pen
, rects
, count
);
4122 status
= GdipCreatePath(FillModeAlternate
, &path
);
4123 if (status
!= Ok
) return status
;
4125 status
= GdipAddPathRectangles(path
, rects
, count
);
4127 status
= GdipDrawPath(graphics
, pen
, path
);
4129 GdipDeletePath(path
);
4133 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
4134 GDIPCONST GpRect
* rects
, INT count
)
4140 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
4142 if(!rects
|| count
<=0)
4143 return InvalidParameter
;
4145 rectsF
= heap_alloc_zero(sizeof(GpRectF
) * count
);
4149 for(i
= 0;i
< count
;i
++)
4150 set_rect(&rectsF
[i
], rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
4152 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
4158 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
4159 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
4164 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
4165 count
, tension
, fill
);
4167 if(!graphics
|| !brush
|| !points
)
4168 return InvalidParameter
;
4173 if(count
== 1) /* Do nothing */
4176 status
= GdipCreatePath(fill
, &path
);
4177 if (status
!= Ok
) return status
;
4179 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
4181 status
= GdipFillPath(graphics
, brush
, path
);
4183 GdipDeletePath(path
);
4187 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
4188 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
4194 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
4195 count
, tension
, fill
);
4197 if(!points
|| count
== 0)
4198 return InvalidParameter
;
4200 if(count
== 1) /* Do nothing */
4203 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
4207 for(i
= 0;i
< count
;i
++){
4208 ptf
[i
].X
= (REAL
)points
[i
].X
;
4209 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4212 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
4219 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
4220 GDIPCONST GpPointF
*points
, INT count
)
4222 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4223 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
4224 0.5f
, FillModeAlternate
);
4227 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
4228 GDIPCONST GpPoint
*points
, INT count
)
4230 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4231 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
4232 0.5f
, FillModeAlternate
);
4235 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4236 REAL y
, REAL width
, REAL height
)
4242 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4244 if(!graphics
|| !brush
)
4245 return InvalidParameter
;
4250 if (is_metafile_graphics(graphics
))
4252 set_rect(&rect
, x
, y
, width
, height
);
4253 return METAFILE_FillEllipse((GpMetafile
*)graphics
->image
, brush
, &rect
);
4256 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4260 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
4263 stat
= GdipFillPath(graphics
, brush
, path
);
4265 GdipDeletePath(path
);
4271 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4272 INT y
, INT width
, INT height
)
4274 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4276 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
4279 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4285 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4286 return NotImplemented
;
4288 save_state
= SaveDC(graphics
->hdc
);
4289 EndPath(graphics
->hdc
);
4290 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
4293 retval
= get_clip_hrgn(graphics
, &hrgn
);
4298 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
4300 gdi_transform_acquire(graphics
);
4302 BeginPath(graphics
->hdc
);
4303 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
4304 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
4308 EndPath(graphics
->hdc
);
4309 retval
= brush_fill_path(graphics
, brush
);
4312 gdi_transform_release(graphics
);
4315 RestoreDC(graphics
->hdc
, save_state
);
4321 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4326 if (!brush_can_fill_pixels(brush
))
4327 return NotImplemented
;
4329 /* FIXME: This could probably be done more efficiently without regions. */
4331 stat
= GdipCreateRegionPath(path
, &rgn
);
4335 stat
= GdipFillRegion(graphics
, brush
, rgn
);
4337 GdipDeleteRegion(rgn
);
4343 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4345 GpStatus stat
= NotImplemented
;
4347 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
4349 if(!brush
|| !graphics
|| !path
)
4350 return InvalidParameter
;
4355 if (!path
->pathdata
.Count
)
4358 if (is_metafile_graphics(graphics
))
4359 return METAFILE_FillPath((GpMetafile
*)graphics
->image
, brush
, path
);
4361 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4362 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
4364 if (stat
== NotImplemented
)
4365 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
4367 if (stat
== NotImplemented
)
4369 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
4376 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4377 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4383 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
4384 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4386 if(!graphics
|| !brush
)
4387 return InvalidParameter
;
4392 if (is_metafile_graphics(graphics
))
4394 set_rect(&rect
, x
, y
, width
, height
);
4395 return METAFILE_FillPie((GpMetafile
*)graphics
->image
, brush
, &rect
, startAngle
, sweepAngle
);
4398 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4402 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4405 stat
= GdipFillPath(graphics
, brush
, path
);
4407 GdipDeletePath(path
);
4413 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4414 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4416 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
4417 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4419 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4422 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
4423 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
4428 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4430 if(!graphics
|| !brush
|| !points
|| !count
)
4431 return InvalidParameter
;
4436 stat
= GdipCreatePath(fillMode
, &path
);
4440 stat
= GdipAddPathPolygon(path
, points
, count
);
4443 stat
= GdipFillPath(graphics
, brush
, path
);
4445 GdipDeletePath(path
);
4451 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4452 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4457 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4459 if(!graphics
|| !brush
|| !points
|| !count
)
4460 return InvalidParameter
;
4465 stat
= GdipCreatePath(fillMode
, &path
);
4469 stat
= GdipAddPathPolygonI(path
, points
, count
);
4472 stat
= GdipFillPath(graphics
, brush
, path
);
4474 GdipDeletePath(path
);
4480 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4481 GDIPCONST GpPointF
*points
, INT count
)
4483 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4485 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4488 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4489 GDIPCONST GpPoint
*points
, INT count
)
4491 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4493 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4496 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4497 REAL x
, REAL y
, REAL width
, REAL height
)
4501 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4503 set_rect(&rect
, x
, y
, width
, height
);
4504 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4507 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4508 INT x
, INT y
, INT width
, INT height
)
4512 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4514 set_rect(&rect
, x
, y
, width
, height
);
4515 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4518 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4524 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4526 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
4527 return InvalidParameter
;
4529 if (is_metafile_graphics(graphics
))
4531 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
4532 /* FIXME: Add gdi32 drawing. */
4536 status
= GdipCreatePath(FillModeAlternate
, &path
);
4537 if (status
!= Ok
) return status
;
4539 status
= GdipAddPathRectangles(path
, rects
, count
);
4541 status
= GdipFillPath(graphics
, brush
, path
);
4543 GdipDeletePath(path
);
4547 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4554 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4556 if(!rects
|| count
<= 0)
4557 return InvalidParameter
;
4559 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
4563 for(i
= 0; i
< count
; i
++)
4564 set_rect(&rectsF
[i
], rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
4566 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4572 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4580 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4581 return NotImplemented
;
4583 save_state
= SaveDC(graphics
->hdc
);
4584 EndPath(graphics
->hdc
);
4587 status
= get_clip_hrgn(graphics
, &hrgn
);
4590 RestoreDC(graphics
->hdc
, save_state
);
4594 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
4597 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4600 RestoreDC(graphics
->hdc
, save_state
);
4604 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4607 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4609 BeginPath(graphics
->hdc
);
4610 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4611 EndPath(graphics
->hdc
);
4613 status
= brush_fill_path(graphics
, brush
);
4616 RestoreDC(graphics
->hdc
, save_state
);
4622 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4626 GpRegion
*temp_region
;
4627 GpMatrix world_to_device
;
4628 GpRectF graphics_bounds
;
4632 GpRect gp_bound_rect
;
4634 if (!brush_can_fill_pixels(brush
))
4635 return NotImplemented
;
4637 stat
= gdi_transform_acquire(graphics
);
4640 stat
= get_graphics_device_bounds(graphics
, &graphics_bounds
);
4643 stat
= GdipCloneRegion(region
, &temp_region
);
4647 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
4648 CoordinateSpaceWorld
, &world_to_device
);
4651 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4654 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4657 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4659 GdipDeleteRegion(temp_region
);
4662 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4664 DeleteObject(hregion
);
4665 gdi_transform_release(graphics
);
4671 gp_bound_rect
.X
= bound_rect
.left
;
4672 gp_bound_rect
.Y
= bound_rect
.top
;
4673 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4674 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4676 pixel_data
= heap_alloc_zero(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4682 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4683 &gp_bound_rect
, gp_bound_rect
.Width
);
4686 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4687 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4688 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
,
4689 PixelFormat32bppARGB
);
4691 heap_free(pixel_data
);
4694 DeleteObject(hregion
);
4697 gdi_transform_release(graphics
);
4702 /*****************************************************************************
4703 * GdipFillRegion [GDIPLUS.@]
4705 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4708 GpStatus stat
= NotImplemented
;
4710 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4712 if (!(graphics
&& brush
&& region
))
4713 return InvalidParameter
;
4718 if (is_metafile_graphics(graphics
))
4719 stat
= METAFILE_FillRegion((GpMetafile
*)graphics
->image
, brush
, region
);
4722 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4723 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4725 if (stat
== NotImplemented
)
4726 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4729 if (stat
== NotImplemented
)
4731 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4738 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4740 TRACE("(%p,%u)\n", graphics
, intention
);
4743 return InvalidParameter
;
4748 /* We have no internal operation queue, so there's no need to clear it. */
4756 /*****************************************************************************
4757 * GdipGetClipBounds [GDIPLUS.@]
4759 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4764 TRACE("(%p, %p)\n", graphics
, rect
);
4767 return InvalidParameter
;
4772 status
= GdipCreateRegion(&clip
);
4773 if (status
!= Ok
) return status
;
4775 status
= GdipGetClip(graphics
, clip
);
4777 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4779 GdipDeleteRegion(clip
);
4783 /*****************************************************************************
4784 * GdipGetClipBoundsI [GDIPLUS.@]
4786 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4791 TRACE("(%p, %p)\n", graphics
, rect
);
4794 return InvalidParameter
;
4796 if ((stat
= GdipGetClipBounds(graphics
, &rectf
)) == Ok
)
4798 rect
->X
= gdip_round(rectf
.X
);
4799 rect
->Y
= gdip_round(rectf
.Y
);
4800 rect
->Width
= gdip_round(rectf
.Width
);
4801 rect
->Height
= gdip_round(rectf
.Height
);
4807 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4808 CompositingMode
*mode
)
4810 TRACE("(%p, %p)\n", graphics
, mode
);
4812 if(!graphics
|| !mode
)
4813 return InvalidParameter
;
4818 *mode
= graphics
->compmode
;
4823 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4824 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4825 CompositingQuality
*quality
)
4827 TRACE("(%p, %p)\n", graphics
, quality
);
4829 if(!graphics
|| !quality
)
4830 return InvalidParameter
;
4835 *quality
= graphics
->compqual
;
4840 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4841 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4842 InterpolationMode
*mode
)
4844 TRACE("(%p, %p)\n", graphics
, mode
);
4846 if(!graphics
|| !mode
)
4847 return InvalidParameter
;
4852 *mode
= graphics
->interpolation
;
4857 /* FIXME: Need to handle color depths less than 24bpp */
4858 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4860 TRACE("(%p, %p)\n", graphics
, argb
);
4862 if(!graphics
|| !argb
)
4863 return InvalidParameter
;
4868 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
4871 GpBitmap
*bitmap
= (GpBitmap
*)graphics
->image
;
4872 if (IsIndexedPixelFormat(bitmap
->format
) && !once
++)
4873 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4879 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4881 TRACE("(%p, %p)\n", graphics
, scale
);
4883 if(!graphics
|| !scale
)
4884 return InvalidParameter
;
4889 *scale
= graphics
->scale
;
4894 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4896 TRACE("(%p, %p)\n", graphics
, unit
);
4898 if(!graphics
|| !unit
)
4899 return InvalidParameter
;
4904 *unit
= graphics
->unit
;
4909 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4910 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4913 TRACE("(%p, %p)\n", graphics
, mode
);
4915 if(!graphics
|| !mode
)
4916 return InvalidParameter
;
4921 *mode
= graphics
->pixeloffset
;
4926 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4927 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4929 TRACE("(%p, %p)\n", graphics
, mode
);
4931 if(!graphics
|| !mode
)
4932 return InvalidParameter
;
4937 *mode
= graphics
->smoothing
;
4942 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4944 TRACE("(%p, %p)\n", graphics
, contrast
);
4946 if(!graphics
|| !contrast
)
4947 return InvalidParameter
;
4949 *contrast
= graphics
->textcontrast
;
4954 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4955 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4956 TextRenderingHint
*hint
)
4958 TRACE("(%p, %p)\n", graphics
, hint
);
4960 if(!graphics
|| !hint
)
4961 return InvalidParameter
;
4966 *hint
= graphics
->texthint
;
4971 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4975 GpMatrix device_to_world
;
4977 TRACE("(%p, %p)\n", graphics
, rect
);
4979 if(!graphics
|| !rect
)
4980 return InvalidParameter
;
4985 /* intersect window and graphics clipping regions */
4986 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4989 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4992 /* transform to world coordinates */
4993 if((stat
= get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
)) != Ok
)
4996 if((stat
= GdipTransformRegion(clip_rgn
, &device_to_world
)) != Ok
)
4999 /* get bounds of the region */
5000 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
5003 GdipDeleteRegion(clip_rgn
);
5008 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
5013 TRACE("(%p, %p)\n", graphics
, rect
);
5015 if(!graphics
|| !rect
)
5016 return InvalidParameter
;
5018 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
5020 rect
->X
= gdip_round(rectf
.X
);
5021 rect
->Y
= gdip_round(rectf
.Y
);
5022 rect
->Width
= gdip_round(rectf
.Width
);
5023 rect
->Height
= gdip_round(rectf
.Height
);
5029 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5031 TRACE("(%p, %p)\n", graphics
, matrix
);
5033 if(!graphics
|| !matrix
)
5034 return InvalidParameter
;
5039 *matrix
= graphics
->worldtrans
;
5043 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
5048 CompositingMode prev_comp_mode
;
5050 TRACE("(%p, %lx)\n", graphics
, color
);
5053 return InvalidParameter
;
5058 if (is_metafile_graphics(graphics
))
5059 return METAFILE_GraphicsClear((GpMetafile
*)graphics
->image
, color
);
5061 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
5064 if((stat
= GdipGetVisibleClipBounds(graphics
, &wnd_rect
)) != Ok
){
5065 GdipDeleteBrush((GpBrush
*)brush
);
5069 GdipGetCompositingMode(graphics
, &prev_comp_mode
);
5070 GdipSetCompositingMode(graphics
, CompositingModeSourceCopy
);
5071 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
5072 wnd_rect
.Width
, wnd_rect
.Height
);
5073 GdipSetCompositingMode(graphics
, prev_comp_mode
);
5075 GdipDeleteBrush((GpBrush
*)brush
);
5080 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
5082 TRACE("(%p, %p)\n", graphics
, res
);
5084 if(!graphics
|| !res
)
5085 return InvalidParameter
;
5087 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
5090 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
5096 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
5098 if(!graphics
|| !result
)
5099 return InvalidParameter
;
5106 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
5107 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
5110 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5113 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5116 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
5119 GdipDeleteRegion(rgn
);
5123 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
5125 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
5128 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
5134 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
5136 if(!graphics
|| !result
)
5137 return InvalidParameter
;
5144 pts
[1].X
= x
+ width
;
5145 pts
[1].Y
= y
+ height
;
5147 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
5148 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
5151 pts
[1].X
-= pts
[0].X
;
5152 pts
[1].Y
-= pts
[0].Y
;
5154 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5157 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5160 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
5163 GdipDeleteRegion(rgn
);
5167 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
5169 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
5172 GpStatus
gdip_format_string(HDC hdc
,
5173 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5174 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
5175 gdip_format_string_callback callback
, void *user_data
)
5178 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
5179 nheight
, lineend
, lineno
= 0;
5181 StringAlignment halign
;
5184 HotkeyPrefix hkprefix
;
5185 INT
*hotkeyprefix_offsets
=NULL
;
5186 INT hotkeyprefix_count
=0;
5187 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
5188 BOOL seen_prefix
= FALSE
;
5190 if(length
== -1) length
= lstrlenW(string
);
5192 stringdup
= heap_alloc_zero((length
+ 1) * sizeof(WCHAR
));
5193 if(!stringdup
) return OutOfMemory
;
5196 format
= &default_drawstring_format
;
5198 nwidth
= rect
->Width
;
5199 nheight
= rect
->Height
;
5200 if (ignore_empty_clip
)
5202 if (!nwidth
) nwidth
= INT_MAX
;
5203 if (!nheight
) nheight
= INT_MAX
;
5206 hkprefix
= format
->hkprefix
;
5208 if (hkprefix
== HotkeyPrefixShow
)
5210 for (i
=0; i
<length
; i
++)
5212 if (string
[i
] == '&')
5213 hotkeyprefix_count
++;
5217 if (hotkeyprefix_count
)
5219 hotkeyprefix_offsets
= heap_alloc_zero(sizeof(INT
) * hotkeyprefix_count
);
5220 if (!hotkeyprefix_offsets
)
5222 heap_free(stringdup
);
5227 hotkeyprefix_count
= 0;
5229 for(i
= 0, j
= 0; i
< length
; i
++){
5231 /* FIXME: tabs should be handled using tabstops from stringformat */
5232 if (string
[i
] == '\t')
5235 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
5236 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
5237 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
5243 seen_prefix
= FALSE
;
5245 stringdup
[j
] = string
[i
];
5251 halign
= format
->align
;
5253 while(sum
< length
){
5254 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
5255 nwidth
, &fit
, NULL
, &size
);
5261 for(lret
= 0; lret
< fit
; lret
++)
5262 if(*(stringdup
+ sum
+ lret
) == '\n')
5265 /* Line break code (may look strange, but it imitates windows). */
5267 lineend
= fit
= lret
; /* this is not an off-by-one error */
5268 else if(fit
< (length
- sum
)){
5269 if(*(stringdup
+ sum
+ fit
) == ' ')
5270 while(*(stringdup
+ sum
+ fit
) == ' ')
5272 else if (!(format
->attr
& StringFormatFlagsNoWrap
))
5273 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
5276 if(*(stringdup
+ sum
+ fit
) == '\t')
5285 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
5286 *(stringdup
+ sum
+ lineend
- 1) == '\t')
5292 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
5293 nwidth
, &j
, NULL
, &size
);
5295 bounds
.Width
= size
.cx
;
5297 if(height
+ size
.cy
> nheight
)
5299 if (format
->attr
& StringFormatFlagsLineLimit
)
5301 bounds
.Height
= nheight
- (height
+ size
.cy
);
5304 bounds
.Height
= size
.cy
;
5306 bounds
.Y
= rect
->Y
+ height
;
5310 case StringAlignmentNear
:
5314 case StringAlignmentCenter
:
5315 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
5317 case StringAlignmentFar
:
5318 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
5322 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
5323 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
5326 stat
= callback(hdc
, stringdup
, sum
, lineend
,
5327 font
, rect
, format
, lineno
, &bounds
,
5328 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
5329 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
5334 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
5338 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
5340 if(height
> nheight
)
5343 /* Stop if this was a linewrap (but not if it was a linebreak). */
5344 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
5348 heap_free(stringdup
);
5349 heap_free(hotkeyprefix_offsets
);
5354 struct measure_ranges_args
{
5356 REAL rel_width
, rel_height
;
5359 static GpStatus
measure_ranges_callback(HDC hdc
,
5360 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5361 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5362 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5363 INT underlined_index_count
, void *user_data
)
5367 struct measure_ranges_args
*args
= user_data
;
5369 for (i
=0; i
<format
->range_count
; i
++)
5371 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
5372 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
5373 if (range_start
< range_end
)
5378 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
5379 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
5381 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
5382 INT_MAX
, NULL
, NULL
, &range_size
);
5383 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
5385 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
5386 INT_MAX
, NULL
, NULL
, &range_size
);
5387 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
5389 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
5398 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
5399 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
5400 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
5401 INT regionCount
, GpRegion
** regions
)
5405 HFONT gdifont
, oldfont
;
5406 struct measure_ranges_args args
;
5407 HDC hdc
, temp_hdc
=NULL
;
5412 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_wn(string
, length
),
5413 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
5415 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
5416 return InvalidParameter
;
5418 if (regionCount
< stringFormat
->range_count
)
5419 return InvalidParameter
;
5423 hdc
= temp_hdc
= CreateCompatibleDC(0);
5424 if (!temp_hdc
) return OutOfMemory
;
5427 hdc
= graphics
->hdc
;
5429 if (stringFormat
->attr
)
5430 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
5438 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5439 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5440 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5441 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5442 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5444 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
5445 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
, graphics
->printer_display
);
5447 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
5448 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
5449 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
5450 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
5452 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5453 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5455 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
, NULL
);
5456 oldfont
= SelectObject(hdc
, gdifont
);
5458 for (i
=0; i
<stringFormat
->range_count
; i
++)
5460 stat
= GdipSetEmpty(regions
[i
]);
5463 SelectObject(hdc
, oldfont
);
5464 DeleteObject(gdifont
);
5471 args
.regions
= regions
;
5473 gdi_transform_acquire(graphics
);
5475 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
5476 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
5478 gdi_transform_release(graphics
);
5480 SelectObject(hdc
, oldfont
);
5481 DeleteObject(gdifont
);
5489 struct measure_string_args
{
5491 INT
*codepointsfitted
;
5493 REAL rel_width
, rel_height
;
5496 static GpStatus
measure_string_callback(HDC hdc
,
5497 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5498 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5499 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5500 INT underlined_index_count
, void *user_data
)
5502 struct measure_string_args
*args
= user_data
;
5503 REAL new_width
, new_height
;
5505 new_width
= bounds
->Width
/ args
->rel_width
;
5506 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
5508 if (new_width
> args
->bounds
->Width
)
5509 args
->bounds
->Width
= new_width
;
5511 if (new_height
> args
->bounds
->Height
)
5512 args
->bounds
->Height
= new_height
;
5514 if (args
->codepointsfitted
)
5515 *args
->codepointsfitted
= index
+ length
;
5517 if (args
->linesfilled
)
5518 (*args
->linesfilled
)++;
5523 /* Find the smallest rectangle that bounds the text when it is printed in rect
5524 * according to the format options listed in format. If rect has 0 width and
5525 * height, then just find the smallest rectangle that bounds the text when it's
5526 * printed at location (rect->X, rect-Y). */
5527 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
5528 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5529 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
5530 INT
*codepointsfitted
, INT
*linesfilled
)
5532 HFONT oldfont
, gdifont
;
5533 struct measure_string_args args
;
5534 HDC temp_hdc
=NULL
, hdc
;
5540 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
5541 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
5542 bounds
, codepointsfitted
, linesfilled
);
5544 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
5545 return InvalidParameter
;
5549 hdc
= temp_hdc
= CreateCompatibleDC(0);
5550 if (!temp_hdc
) return OutOfMemory
;
5553 hdc
= graphics
->hdc
;
5555 if(linesfilled
) *linesfilled
= 0;
5556 if(codepointsfitted
) *codepointsfitted
= 0;
5559 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5567 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5568 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5569 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5570 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5571 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5573 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5574 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
, graphics
->printer_display
);
5576 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
5577 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
5578 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
5579 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
5580 if (scaled_rect
.Width
>= 0.5)
5582 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5583 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5586 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5587 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5589 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
, NULL
);
5590 oldfont
= SelectObject(hdc
, gdifont
);
5592 set_rect(bounds
, rect
->X
, rect
->Y
, 0.0f
, 0.0f
);
5594 args
.bounds
= bounds
;
5595 args
.codepointsfitted
= &glyphs
;
5596 args
.linesfilled
= &lines
;
5599 gdi_transform_acquire(graphics
);
5601 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5602 measure_string_callback
, &args
);
5604 gdi_transform_release(graphics
);
5606 if (linesfilled
) *linesfilled
= lines
;
5607 if (codepointsfitted
) *codepointsfitted
= glyphs
;
5610 bounds
->Width
+= margin_x
* 2.0;
5612 SelectObject(hdc
, oldfont
);
5613 DeleteObject(gdifont
);
5621 struct draw_string_args
{
5622 GpGraphics
*graphics
;
5623 GDIPCONST GpBrush
*brush
;
5624 REAL x
, y
, rel_width
, rel_height
, ascent
;
5627 static GpStatus
draw_string_callback(HDC hdc
,
5628 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5629 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5630 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5631 INT underlined_index_count
, void *user_data
)
5633 struct draw_string_args
*args
= user_data
;
5637 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5638 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5640 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
5641 args
->brush
, &position
,
5642 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5644 if (stat
== Ok
&& underlined_index_count
)
5646 OUTLINETEXTMETRICW otm
;
5647 REAL underline_y
, underline_height
;
5650 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5652 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5653 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5655 for (i
=0; i
<underlined_index_count
; i
++)
5657 REAL start_x
, end_x
;
5659 INT ofs
= underlined_indexes
[i
] - index
;
5661 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5662 start_x
= text_size
.cx
/ args
->rel_width
;
5664 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5665 end_x
= text_size
.cx
/ args
->rel_width
;
5667 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5674 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5675 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5676 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5680 GpPointF pt
[3], rectcpy
[4];
5682 REAL rel_width
, rel_height
, margin_x
;
5683 INT save_state
, format_flags
= 0;
5685 struct draw_string_args args
;
5687 HDC hdc
, temp_hdc
=NULL
;
5688 TEXTMETRICW textmetric
;
5690 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5691 length
, font
, debugstr_rectf(rect
), format
, brush
);
5693 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5694 return InvalidParameter
;
5698 hdc
= graphics
->hdc
;
5702 hdc
= temp_hdc
= CreateCompatibleDC(0);
5706 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5708 format_flags
= format
->attr
;
5710 /* Should be no need to explicitly test for StringAlignmentNear as
5711 * that is default behavior if no alignment is passed. */
5712 if(format
->line_align
!= StringAlignmentNear
){
5713 RectF bounds
, in_rect
= *rect
;
5714 in_rect
.Height
= 0.0; /* avoid height clipping */
5715 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5717 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5719 if(format
->line_align
== StringAlignmentCenter
)
5720 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5721 else if(format
->line_align
== StringAlignmentFar
)
5722 offsety
= (rect
->Height
- bounds
.Height
);
5724 TRACE("line align %d, offsety %f\n", format
->line_align
, offsety
);
5727 save_state
= SaveDC(hdc
);
5735 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5736 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5737 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5738 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5739 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5741 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5742 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5743 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5744 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5745 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, rectcpy
, 4);
5746 round_points(corners
, rectcpy
, 4);
5748 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5749 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
, graphics
->printer_display
);
5751 scaled_rect
.X
= margin_x
* rel_width
;
5752 scaled_rect
.Y
= 0.0;
5753 scaled_rect
.Width
= rel_width
* rect
->Width
;
5754 scaled_rect
.Height
= rel_height
* rect
->Height
;
5755 if (scaled_rect
.Width
>= 0.5)
5757 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5758 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5761 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5762 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5764 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5765 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5766 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5768 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5769 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5770 SelectClipRgn(hdc
, rgn
);
5773 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
, NULL
);
5774 SelectObject(hdc
, gdifont
);
5776 args
.graphics
= graphics
;
5780 args
.y
= rect
->Y
+ offsety
;
5782 args
.rel_width
= rel_width
;
5783 args
.rel_height
= rel_height
;
5785 gdi_transform_acquire(graphics
);
5787 GetTextMetricsW(hdc
, &textmetric
);
5788 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5790 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5791 draw_string_callback
, &args
);
5793 gdi_transform_release(graphics
);
5796 DeleteObject(gdifont
);
5798 RestoreDC(hdc
, save_state
);
5805 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5809 TRACE("(%p)\n", graphics
);
5812 return InvalidParameter
;
5817 if (is_metafile_graphics(graphics
))
5819 stat
= METAFILE_ResetClip((GpMetafile
*)graphics
->image
);
5824 return GdipSetInfinite(graphics
->clip
);
5827 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5831 TRACE("(%p)\n", graphics
);
5834 return InvalidParameter
;
5839 if (is_metafile_graphics(graphics
))
5841 stat
= METAFILE_ResetWorldTransform((GpMetafile
*)graphics
->image
);
5847 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5850 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5851 GpMatrixOrder order
)
5855 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5858 return InvalidParameter
;
5863 if (is_metafile_graphics(graphics
))
5865 stat
= METAFILE_RotateWorldTransform((GpMetafile
*)graphics
->image
, angle
, order
);
5871 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5874 static GpStatus
begin_container(GpGraphics
*graphics
,
5875 GraphicsContainerType type
, GraphicsContainer
*state
)
5877 GraphicsContainerItem
*container
;
5880 if(!graphics
|| !state
)
5881 return InvalidParameter
;
5883 sts
= init_container(&container
, graphics
, type
);
5887 list_add_head(&graphics
->containers
, &container
->entry
);
5888 *state
= graphics
->contid
= container
->contid
;
5890 if (is_metafile_graphics(graphics
)) {
5891 if (type
== BEGIN_CONTAINER
)
5892 METAFILE_BeginContainerNoParams((GpMetafile
*)graphics
->image
, container
->contid
);
5894 METAFILE_SaveGraphics((GpMetafile
*)graphics
->image
, container
->contid
);
5900 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5902 TRACE("(%p, %p)\n", graphics
, state
);
5903 return begin_container(graphics
, SAVE_GRAPHICS
, state
);
5906 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5907 GraphicsContainer
*state
)
5909 TRACE("(%p, %p)\n", graphics
, state
);
5910 return begin_container(graphics
, BEGIN_CONTAINER
, state
);
5913 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5915 GraphicsContainerItem
*container
;
5918 GpRectF scaled_srcrect
;
5919 REAL scale_x
, scale_y
;
5921 TRACE("(%p, %s, %s, %d, %p)\n", graphics
, debugstr_rectf(dstrect
), debugstr_rectf(srcrect
), unit
, state
);
5923 if(!graphics
|| !dstrect
|| !srcrect
|| unit
< UnitPixel
|| unit
> UnitMillimeter
|| !state
)
5924 return InvalidParameter
;
5926 stat
= init_container(&container
, graphics
, BEGIN_CONTAINER
);
5930 list_add_head(&graphics
->containers
, &container
->entry
);
5931 *state
= graphics
->contid
= container
->contid
;
5933 scale_x
= units_to_pixels(1.0, unit
, graphics
->xres
, graphics
->printer_display
);
5934 scale_y
= units_to_pixels(1.0, unit
, graphics
->yres
, graphics
->printer_display
);
5936 scaled_srcrect
.X
= scale_x
* srcrect
->X
;
5937 scaled_srcrect
.Y
= scale_y
* srcrect
->Y
;
5938 scaled_srcrect
.Width
= scale_x
* srcrect
->Width
;
5939 scaled_srcrect
.Height
= scale_y
* srcrect
->Height
;
5941 transform
.matrix
[0] = dstrect
->Width
/ scaled_srcrect
.Width
;
5942 transform
.matrix
[1] = 0.0;
5943 transform
.matrix
[2] = 0.0;
5944 transform
.matrix
[3] = dstrect
->Height
/ scaled_srcrect
.Height
;
5945 transform
.matrix
[4] = dstrect
->X
- scaled_srcrect
.X
;
5946 transform
.matrix
[5] = dstrect
->Y
- scaled_srcrect
.Y
;
5948 GdipMultiplyMatrix(&graphics
->worldtrans
, &transform
, MatrixOrderPrepend
);
5950 if (is_metafile_graphics(graphics
))
5951 METAFILE_BeginContainer((GpMetafile
*)graphics
->image
, dstrect
, srcrect
, unit
, container
->contid
);
5956 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5958 GpRectF dstrectf
, srcrectf
;
5960 TRACE("(%p, %p, %p, %d, %p)\n", graphics
, dstrect
, srcrect
, unit
, state
);
5962 if (!dstrect
|| !srcrect
)
5963 return InvalidParameter
;
5965 dstrectf
.X
= dstrect
->X
;
5966 dstrectf
.Y
= dstrect
->Y
;
5967 dstrectf
.Width
= dstrect
->Width
;
5968 dstrectf
.Height
= dstrect
->Height
;
5970 srcrectf
.X
= srcrect
->X
;
5971 srcrectf
.Y
= srcrect
->Y
;
5972 srcrectf
.Width
= srcrect
->Width
;
5973 srcrectf
.Height
= srcrect
->Height
;
5975 return GdipBeginContainer(graphics
, &dstrectf
, &srcrectf
, unit
, state
);
5978 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5980 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5981 return NotImplemented
;
5984 static GpStatus
end_container(GpGraphics
*graphics
, GraphicsContainerType type
,
5985 GraphicsContainer state
)
5988 GraphicsContainerItem
*container
, *container2
;
5991 return InvalidParameter
;
5993 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5994 if(container
->contid
== state
&& container
->type
== type
)
5998 /* did not find a matching container */
5999 if(&container
->entry
== &graphics
->containers
)
6002 sts
= restore_container(graphics
, container
);
6006 /* remove all of the containers on top of the found container */
6007 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
6008 if(container
->contid
== state
)
6010 list_remove(&container
->entry
);
6011 delete_container(container
);
6014 list_remove(&container
->entry
);
6015 delete_container(container
);
6017 if (is_metafile_graphics(graphics
)) {
6018 if (type
== BEGIN_CONTAINER
)
6019 METAFILE_EndContainer((GpMetafile
*)graphics
->image
, state
);
6021 METAFILE_RestoreGraphics((GpMetafile
*)graphics
->image
, state
);
6027 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
6029 TRACE("(%p, %x)\n", graphics
, state
);
6030 return end_container(graphics
, BEGIN_CONTAINER
, state
);
6033 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
6035 TRACE("(%p, %x)\n", graphics
, state
);
6036 return end_container(graphics
, SAVE_GRAPHICS
, state
);
6039 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
6040 REAL sy
, GpMatrixOrder order
)
6044 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
6047 return InvalidParameter
;
6052 if (is_metafile_graphics(graphics
)) {
6053 stat
= METAFILE_ScaleWorldTransform((GpMetafile
*)graphics
->image
, sx
, sy
, order
);
6059 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
6062 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
6065 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
6067 if(!graphics
|| !srcgraphics
)
6068 return InvalidParameter
;
6070 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
6073 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
6074 CompositingMode mode
)
6076 TRACE("(%p, %d)\n", graphics
, mode
);
6079 return InvalidParameter
;
6084 if(graphics
->compmode
== mode
)
6087 if (is_metafile_graphics(graphics
))
6091 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6092 EmfPlusRecordTypeSetCompositingMode
, mode
);
6097 graphics
->compmode
= mode
;
6102 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
6103 CompositingQuality quality
)
6105 TRACE("(%p, %d)\n", graphics
, quality
);
6108 return InvalidParameter
;
6113 if(graphics
->compqual
== quality
)
6116 if (is_metafile_graphics(graphics
))
6120 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6121 EmfPlusRecordTypeSetCompositingQuality
, quality
);
6126 graphics
->compqual
= quality
;
6131 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
6132 InterpolationMode mode
)
6134 TRACE("(%p, %d)\n", graphics
, mode
);
6136 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
6137 return InvalidParameter
;
6142 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
6143 mode
= InterpolationModeBilinear
;
6145 if (mode
== InterpolationModeHighQuality
)
6146 mode
= InterpolationModeHighQualityBicubic
;
6148 if (mode
== graphics
->interpolation
)
6151 if (is_metafile_graphics(graphics
))
6155 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6156 EmfPlusRecordTypeSetInterpolationMode
, mode
);
6161 graphics
->interpolation
= mode
;
6166 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
6170 TRACE("(%p, %.2f)\n", graphics
, scale
);
6172 if(!graphics
|| (scale
<= 0.0))
6173 return InvalidParameter
;
6178 if (is_metafile_graphics(graphics
))
6180 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
6185 graphics
->scale
= scale
;
6190 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
6194 TRACE("(%p, %d)\n", graphics
, unit
);
6197 return InvalidParameter
;
6202 if(unit
== UnitWorld
)
6203 return InvalidParameter
;
6205 if (is_metafile_graphics(graphics
))
6207 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
6212 graphics
->unit
= unit
;
6217 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
6220 TRACE("(%p, %d)\n", graphics
, mode
);
6223 return InvalidParameter
;
6228 if(graphics
->pixeloffset
== mode
)
6231 if (is_metafile_graphics(graphics
))
6235 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6236 EmfPlusRecordTypeSetPixelOffsetMode
, mode
);
6241 graphics
->pixeloffset
= mode
;
6246 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
6250 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
6253 return InvalidParameter
;
6255 if (graphics
->origin_x
== x
&& graphics
->origin_y
== y
)
6258 if (is_metafile_graphics(graphics
))
6260 stat
= METAFILE_SetRenderingOrigin((GpMetafile
*)graphics
->image
, x
, y
);
6265 graphics
->origin_x
= x
;
6266 graphics
->origin_y
= y
;
6271 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
6273 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
6275 if (!graphics
|| !x
|| !y
)
6276 return InvalidParameter
;
6278 *x
= graphics
->origin_x
;
6279 *y
= graphics
->origin_y
;
6284 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
6286 TRACE("(%p, %d)\n", graphics
, mode
);
6289 return InvalidParameter
;
6294 if(graphics
->smoothing
== mode
)
6297 if (is_metafile_graphics(graphics
))
6300 BOOL antialias
= (mode
!= SmoothingModeDefault
&&
6301 mode
!= SmoothingModeNone
&& mode
!= SmoothingModeHighSpeed
);
6303 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6304 EmfPlusRecordTypeSetAntiAliasMode
, (mode
<< 1) + antialias
);
6309 graphics
->smoothing
= mode
;
6314 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
6316 TRACE("(%p, %d)\n", graphics
, contrast
);
6319 return InvalidParameter
;
6321 graphics
->textcontrast
= contrast
;
6326 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
6327 TextRenderingHint hint
)
6329 TRACE("(%p, %d)\n", graphics
, hint
);
6331 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
6332 return InvalidParameter
;
6337 if(graphics
->texthint
== hint
)
6340 if (is_metafile_graphics(graphics
)) {
6343 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6344 EmfPlusRecordTypeSetTextRenderingHint
, hint
);
6349 graphics
->texthint
= hint
;
6354 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
6358 TRACE("(%p, %p)\n", graphics
, matrix
);
6360 if(!graphics
|| !matrix
)
6361 return InvalidParameter
;
6366 TRACE("%f,%f,%f,%f,%f,%f\n",
6367 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
6368 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
6370 if (is_metafile_graphics(graphics
)) {
6371 stat
= METAFILE_SetWorldTransform((GpMetafile
*)graphics
->image
, matrix
);
6377 graphics
->worldtrans
= *matrix
;
6382 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
6383 REAL dy
, GpMatrixOrder order
)
6387 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
6390 return InvalidParameter
;
6395 if (is_metafile_graphics(graphics
)) {
6396 stat
= METAFILE_TranslateWorldTransform((GpMetafile
*)graphics
->image
, dx
, dy
, order
);
6402 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
6405 /*****************************************************************************
6406 * GdipSetClipHrgn [GDIPLUS.@]
6408 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
6414 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
6417 return InvalidParameter
;
6422 /* hrgn is in gdi32 device units */
6423 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
6427 status
= get_graphics_transform(graphics
, CoordinateSpaceDevice
, WineCoordinateSpaceGdiDevice
, &transform
);
6430 status
= GdipTransformRegion(region
, &transform
);
6433 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6435 GdipDeleteRegion(region
);
6440 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
6445 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
6448 return InvalidParameter
;
6453 if (is_metafile_graphics(graphics
))
6455 status
= METAFILE_SetClipPath((GpMetafile
*)graphics
->image
, path
, mode
);
6460 status
= GdipClonePath(path
, &clip_path
);
6463 GpMatrix world_to_device
;
6465 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
6466 CoordinateSpaceWorld
, &world_to_device
);
6467 status
= GdipTransformPath(clip_path
, &world_to_device
);
6469 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
6471 GdipDeletePath(clip_path
);
6476 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
6477 REAL width
, REAL height
,
6484 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6487 return InvalidParameter
;
6492 if (is_metafile_graphics(graphics
))
6494 status
= METAFILE_SetClipRect((GpMetafile
*)graphics
->image
, x
, y
, width
, height
, mode
);
6499 set_rect(&rect
, x
, y
, width
, height
);
6500 status
= GdipCreateRegionRect(&rect
, ®ion
);
6503 GpMatrix world_to_device
;
6506 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6507 status
= GdipIsMatrixIdentity(&world_to_device
, &identity
);
6508 if (status
== Ok
&& !identity
)
6509 status
= GdipTransformRegion(region
, &world_to_device
);
6511 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6513 GdipDeleteRegion(region
);
6518 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
6519 INT width
, INT height
,
6522 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6525 return InvalidParameter
;
6530 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
6533 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
6539 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
6541 if(!graphics
|| !region
)
6542 return InvalidParameter
;
6547 if (is_metafile_graphics(graphics
))
6549 status
= METAFILE_SetClipRegion((GpMetafile
*)graphics
->image
, region
, mode
);
6554 status
= GdipCloneRegion(region
, &clip
);
6557 GpMatrix world_to_device
;
6560 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6561 status
= GdipIsMatrixIdentity(&world_to_device
, &identity
);
6562 if (status
== Ok
&& !identity
)
6563 status
= GdipTransformRegion(clip
, &world_to_device
);
6565 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
6567 GdipDeleteRegion(clip
);
6572 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
6578 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
6580 if(!graphics
|| !pen
|| count
<=0)
6581 return InvalidParameter
;
6586 status
= GdipCreatePath(FillModeAlternate
, &path
);
6587 if (status
!= Ok
) return status
;
6589 status
= GdipAddPathPolygon(path
, points
, count
);
6591 status
= GdipDrawPath(graphics
, pen
, path
);
6593 GdipDeletePath(path
);
6598 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
6605 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
6607 if(count
<=0) return InvalidParameter
;
6608 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6609 if (!ptf
) return OutOfMemory
;
6611 for(i
= 0;i
< count
; i
++){
6612 ptf
[i
].X
= (REAL
)points
[i
].X
;
6613 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
6616 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
6622 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
6624 TRACE("(%p, %p)\n", graphics
, dpi
);
6626 if(!graphics
|| !dpi
)
6627 return InvalidParameter
;
6632 *dpi
= graphics
->xres
;
6636 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
6638 TRACE("(%p, %p)\n", graphics
, dpi
);
6640 if(!graphics
|| !dpi
)
6641 return InvalidParameter
;
6646 *dpi
= graphics
->yres
;
6650 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
6651 GpMatrixOrder order
)
6656 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
6658 if(!graphics
|| !matrix
)
6659 return InvalidParameter
;
6664 if (is_metafile_graphics(graphics
))
6666 ret
= METAFILE_MultiplyWorldTransform((GpMetafile
*)graphics
->image
, matrix
, order
);
6672 m
= graphics
->worldtrans
;
6674 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
6676 graphics
->worldtrans
= m
;
6681 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
6682 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
6684 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
6688 TRACE("(%p, %p)\n", graphics
, hdc
);
6690 if(!graphics
|| !hdc
)
6691 return InvalidParameter
;
6696 if (is_metafile_graphics(graphics
))
6698 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
6700 else if (!graphics
->hdc
||
6701 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
6703 /* Create a fake HDC and fill it with a constant color. */
6707 BITMAPINFOHEADER bmih
;
6710 stat
= get_graphics_bounds(graphics
, &bounds
);
6714 graphics
->temp_hbitmap_width
= bounds
.Width
;
6715 graphics
->temp_hbitmap_height
= bounds
.Height
;
6717 bmih
.biSize
= sizeof(bmih
);
6718 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
6719 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
6721 bmih
.biBitCount
= 32;
6722 bmih
.biCompression
= BI_RGB
;
6723 bmih
.biSizeImage
= 0;
6724 bmih
.biXPelsPerMeter
= 0;
6725 bmih
.biYPelsPerMeter
= 0;
6727 bmih
.biClrImportant
= 0;
6729 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
6730 (void**)&graphics
->temp_bits
, NULL
, 0);
6732 return GenericError
;
6734 if (!graphics
->temp_hdc
)
6736 temp_hdc
= CreateCompatibleDC(0);
6740 temp_hdc
= graphics
->temp_hdc
;
6745 DeleteObject(hbitmap
);
6746 return GenericError
;
6749 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6750 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
6752 SelectObject(temp_hdc
, hbitmap
);
6754 graphics
->temp_hbitmap
= hbitmap
;
6755 *hdc
= graphics
->temp_hdc
= temp_hdc
;
6759 *hdc
= graphics
->hdc
;
6763 graphics
->busy
= TRUE
;
6768 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
6772 TRACE("(%p, %p)\n", graphics
, hdc
);
6774 if(!graphics
|| !hdc
|| !graphics
->busy
)
6775 return InvalidParameter
;
6777 if (is_metafile_graphics(graphics
))
6779 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
6781 else if (graphics
->temp_hdc
== hdc
)
6786 /* Find the pixels that have changed, and mark them as opaque. */
6787 pos
= (DWORD
*)graphics
->temp_bits
;
6788 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6790 if (*pos
!= DC_BACKGROUND_KEY
)
6797 /* Write the changed pixels to the real target. */
6798 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
6799 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
6800 graphics
->temp_hbitmap_width
* 4, PixelFormat32bppARGB
);
6803 DeleteObject(graphics
->temp_hbitmap
);
6804 graphics
->temp_hbitmap
= NULL
;
6806 else if (hdc
!= graphics
->hdc
)
6808 stat
= InvalidParameter
;
6812 graphics
->busy
= FALSE
;
6817 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
6821 GpMatrix device_to_world
;
6823 TRACE("(%p, %p)\n", graphics
, region
);
6825 if(!graphics
|| !region
)
6826 return InvalidParameter
;
6831 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
6834 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
6835 status
= GdipTransformRegion(clip
, &device_to_world
);
6838 GdipDeleteRegion(clip
);
6842 /* free everything except root node and header */
6843 delete_element(®ion
->node
);
6844 memcpy(region
, clip
, sizeof(GpRegion
));
6850 GpStatus
gdi_transform_acquire(GpGraphics
*graphics
)
6852 if (graphics
->gdi_transform_acquire_count
== 0 && graphics
->hdc
)
6854 graphics
->gdi_transform_save
= SaveDC(graphics
->hdc
);
6855 ModifyWorldTransform(graphics
->hdc
, NULL
, MWT_IDENTITY
);
6856 SetGraphicsMode(graphics
->hdc
, GM_COMPATIBLE
);
6857 SetMapMode(graphics
->hdc
, MM_TEXT
);
6858 SetWindowOrgEx(graphics
->hdc
, 0, 0, NULL
);
6859 SetViewportOrgEx(graphics
->hdc
, 0, 0, NULL
);
6861 graphics
->gdi_transform_acquire_count
++;
6865 GpStatus
gdi_transform_release(GpGraphics
*graphics
)
6867 if (graphics
->gdi_transform_acquire_count
<= 0)
6869 ERR("called without matching gdi_transform_acquire\n");
6870 return GenericError
;
6872 if (graphics
->gdi_transform_acquire_count
== 1 && graphics
->hdc
)
6874 RestoreDC(graphics
->hdc
, graphics
->gdi_transform_save
);
6876 graphics
->gdi_transform_acquire_count
--;
6880 GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6881 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
6884 REAL scale_x
, scale_y
;
6886 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
6888 if (dst_space
!= src_space
)
6890 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
, graphics
->printer_display
);
6891 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
, graphics
->printer_display
);
6893 if(graphics
->unit
!= UnitDisplay
)
6895 scale_x
*= graphics
->scale
;
6896 scale_y
*= graphics
->scale
;
6899 if (dst_space
< src_space
)
6901 /* transform towards world space */
6902 switch ((int)src_space
)
6904 case WineCoordinateSpaceGdiDevice
:
6907 gdixform
= graphics
->gdi_transform
;
6908 stat
= GdipInvertMatrix(&gdixform
);
6911 GdipMultiplyMatrix(matrix
, &gdixform
, MatrixOrderAppend
);
6912 if (dst_space
== CoordinateSpaceDevice
)
6914 /* else fall-through */
6916 case CoordinateSpaceDevice
:
6917 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
6918 if (dst_space
== CoordinateSpacePage
)
6920 /* else fall-through */
6921 case CoordinateSpacePage
:
6923 GpMatrix inverted_transform
= graphics
->worldtrans
;
6924 stat
= GdipInvertMatrix(&inverted_transform
);
6926 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
6933 /* transform towards device space */
6934 switch ((int)src_space
)
6936 case CoordinateSpaceWorld
:
6937 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
6938 if (dst_space
== CoordinateSpacePage
)
6940 /* else fall-through */
6941 case CoordinateSpacePage
:
6942 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
6943 if (dst_space
== CoordinateSpaceDevice
)
6945 /* else fall-through */
6946 case CoordinateSpaceDevice
:
6948 GdipMultiplyMatrix(matrix
, &graphics
->gdi_transform
, MatrixOrderAppend
);
6957 GpStatus
gdip_transform_points(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6958 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6963 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6964 if (stat
!= Ok
) return stat
;
6966 return GdipTransformMatrixPoints(&matrix
, points
, count
);
6969 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6970 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6972 if(!graphics
|| !points
|| count
<= 0 ||
6973 dst_space
< 0 || dst_space
> CoordinateSpaceDevice
||
6974 src_space
< 0 || src_space
> CoordinateSpaceDevice
)
6975 return InvalidParameter
;
6980 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6982 if (src_space
== dst_space
) return Ok
;
6984 return gdip_transform_points(graphics
, dst_space
, src_space
, points
, count
);
6987 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6988 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6994 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6997 return InvalidParameter
;
6999 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
7003 for(i
= 0; i
< count
; i
++){
7004 pointsF
[i
].X
= (REAL
)points
[i
].X
;
7005 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
7008 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
7011 for(i
= 0; i
< count
; i
++){
7012 points
[i
].X
= gdip_round(pointsF
[i
].X
);
7013 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
7020 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
7032 /*****************************************************************************
7033 * GdipTranslateClip [GDIPLUS.@]
7035 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
7039 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
7042 return InvalidParameter
;
7047 if (is_metafile_graphics(graphics
))
7049 stat
= METAFILE_OffsetClip((GpMetafile
*)graphics
->image
, dx
, dy
);
7054 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
7057 /*****************************************************************************
7058 * GdipTranslateClipI [GDIPLUS.@]
7060 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
7062 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
7064 return GdipTranslateClip(graphics
, dx
, dy
);
7067 /*****************************************************************************
7068 * GdipMeasureDriverString [GDIPLUS.@]
7070 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7071 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
7072 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
7074 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
7077 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
7079 TEXTMETRICW textmetric
;
7080 const WORD
*glyph_indices
;
7081 WORD
*dynamic_glyph_indices
=NULL
;
7082 REAL rel_width
, rel_height
, ascent
, descent
;
7085 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
7087 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
7088 return InvalidParameter
;
7091 length
= lstrlenW(text
);
7094 set_rect(boundingBox
, 0.0f
, 0.0f
, 0.0f
, 0.0f
);
7096 if (flags
& unsupported_flags
)
7097 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
7099 get_font_hfont(graphics
, font
, NULL
, &hfont
, NULL
, matrix
);
7101 hdc
= CreateCompatibleDC(0);
7102 SelectObject(hdc
, hfont
);
7104 GetTextMetricsW(hdc
, &textmetric
);
7114 GpMatrix xform
= *matrix
;
7115 GdipTransformMatrixPoints(&xform
, pt
, 3);
7117 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
7118 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
7119 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
7120 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
7121 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
7123 if (flags
& DriverStringOptionsCmapLookup
)
7125 glyph_indices
= dynamic_glyph_indices
= heap_alloc_zero(sizeof(WORD
) * length
);
7129 DeleteObject(hfont
);
7133 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
7136 glyph_indices
= text
;
7138 min_x
= max_x
= x
= positions
[0].X
;
7139 min_y
= max_y
= y
= positions
[0].Y
;
7141 ascent
= textmetric
.tmAscent
/ rel_height
;
7142 descent
= textmetric
.tmDescent
/ rel_height
;
7144 for (i
=0; i
<length
; i
++)
7149 if (!(flags
& DriverStringOptionsRealizedAdvance
))
7155 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
7156 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
7158 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
7159 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
7160 if (min_x
> x
) min_x
= x
;
7162 x
+= char_width
/ rel_width
;
7164 if (max_x
< x
) max_x
= x
;
7167 heap_free(dynamic_glyph_indices
);
7169 DeleteObject(hfont
);
7171 boundingBox
->X
= min_x
;
7172 boundingBox
->Y
= min_y
;
7173 boundingBox
->Width
= max_x
- min_x
;
7174 boundingBox
->Height
= max_y
- min_y
;
7179 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7180 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7181 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7182 INT flags
, GDIPCONST GpMatrix
*matrix
)
7185 GpPointF pt
, *real_positions
=NULL
;
7186 INT
*eto_positions
=NULL
;
7193 if (!(flags
& DriverStringOptionsCmapLookup
))
7194 eto_flags
|= ETO_GLYPH_INDEX
;
7196 if (!(flags
& DriverStringOptionsRealizedAdvance
) && length
> 1)
7198 real_positions
= heap_alloc(sizeof(*real_positions
) * length
);
7199 eto_positions
= heap_alloc(sizeof(*eto_positions
) * 2 * (length
- 1));
7200 if (!real_positions
|| !eto_positions
)
7202 heap_free(real_positions
);
7203 heap_free(eto_positions
);
7208 save_state
= SaveDC(graphics
->hdc
);
7209 SetBkMode(graphics
->hdc
, TRANSPARENT
);
7210 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
7212 status
= get_clip_hrgn(graphics
, &hrgn
);
7216 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
7221 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, &pt
, 1);
7223 get_font_hfont(graphics
, font
, format
, &hfont
, &lfw
, matrix
);
7225 if (!(flags
& DriverStringOptionsRealizedAdvance
) && length
> 1)
7230 eto_flags
|= ETO_PDY
;
7232 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
7234 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, real_positions
, length
);
7236 GdipSetMatrixElements(&rotation
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
7237 GdipRotateMatrix(&rotation
, lfw
.lfEscapement
/ 10.0, MatrixOrderAppend
);
7238 GdipTransformMatrixPoints(&rotation
, real_positions
, length
);
7240 for (i
= 0; i
< (length
- 1); i
++)
7242 eto_positions
[i
*2] = gdip_round(real_positions
[i
+1].X
) - gdip_round(real_positions
[i
].X
);
7243 eto_positions
[i
*2+1] = gdip_round(real_positions
[i
].Y
) - gdip_round(real_positions
[i
+1].Y
);
7247 SelectObject(graphics
->hdc
, hfont
);
7249 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
7251 gdi_transform_acquire(graphics
);
7253 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, eto_positions
);
7255 gdi_transform_release(graphics
);
7257 RestoreDC(graphics
->hdc
, save_state
);
7259 DeleteObject(hfont
);
7261 heap_free(real_positions
);
7262 heap_free(eto_positions
);
7267 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7268 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7269 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7270 INT flags
, GDIPCONST GpMatrix
*matrix
)
7272 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
7274 PointF
*real_positions
, real_position
;
7278 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
7279 DWORD max_glyphsize
=0;
7280 GLYPHMETRICS glyphmetrics
;
7281 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
7284 int text_mask_stride
;
7286 int pixel_data_stride
;
7288 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
7293 if (!(flags
& DriverStringOptionsCmapLookup
))
7294 ggo_flags
|= GGO_GLYPH_INDEX
;
7296 if (flags
& unsupported_flags
)
7297 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
7299 pti
= heap_alloc_zero(sizeof(POINT
) * length
);
7303 if (flags
& DriverStringOptionsRealizedAdvance
)
7305 real_position
= positions
[0];
7307 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, &real_position
, 1);
7308 round_points(pti
, &real_position
, 1);
7312 real_positions
= heap_alloc_zero(sizeof(PointF
) * length
);
7313 if (!real_positions
)
7319 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
7321 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, real_positions
, length
);
7322 round_points(pti
, real_positions
, length
);
7324 heap_free(real_positions
);
7327 get_font_hfont(graphics
, font
, format
, &hfont
, NULL
, matrix
);
7329 hdc
= CreateCompatibleDC(0);
7330 SelectObject(hdc
, hfont
);
7332 /* Get the boundaries of the text to be drawn */
7333 for (i
=0; i
<length
; i
++)
7336 int left
, top
, right
, bottom
;
7338 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
7339 &glyphmetrics
, 0, NULL
, &identity
);
7341 if (glyphsize
== GDI_ERROR
)
7343 ERR("GetGlyphOutlineW failed\n");
7346 DeleteObject(hfont
);
7347 return GenericError
;
7350 if (glyphsize
> max_glyphsize
)
7351 max_glyphsize
= glyphsize
;
7355 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7356 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7357 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
7358 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
7360 if (left
< min_x
) min_x
= left
;
7361 if (top
< min_y
) min_y
= top
;
7362 if (right
> max_x
) max_x
= right
;
7363 if (bottom
> max_y
) max_y
= bottom
;
7366 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
7368 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
7369 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
7373 if (max_glyphsize
== 0)
7375 /* Nothing to draw. */
7378 DeleteObject(hfont
);
7382 glyph_mask
= heap_alloc_zero(max_glyphsize
);
7383 text_mask
= heap_alloc_zero((max_x
- min_x
) * (max_y
- min_y
));
7384 text_mask_stride
= max_x
- min_x
;
7386 if (!(glyph_mask
&& text_mask
))
7388 heap_free(glyph_mask
);
7389 heap_free(text_mask
);
7392 DeleteObject(hfont
);
7396 /* Generate a mask for the text */
7397 for (i
=0; i
<length
; i
++)
7400 int left
, top
, stride
;
7402 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
7403 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
7405 if (ret
== GDI_ERROR
|| ret
== 0)
7406 continue; /* empty glyph */
7408 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7409 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7410 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
7412 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
7414 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
7415 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
7416 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
7418 *text_val
= min(64, *text_val
+ *glyph_val
);
7427 DeleteObject(hfont
);
7428 heap_free(glyph_mask
);
7430 /* get the brush data */
7431 pixel_data
= heap_alloc_zero(4 * (max_x
- min_x
) * (max_y
- min_y
));
7434 heap_free(text_mask
);
7438 pixel_area
.X
= min_x
;
7439 pixel_area
.Y
= min_y
;
7440 pixel_area
.Width
= max_x
- min_x
;
7441 pixel_area
.Height
= max_y
- min_y
;
7442 pixel_data_stride
= pixel_area
.Width
* 4;
7444 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
7447 heap_free(text_mask
);
7448 heap_free(pixel_data
);
7452 /* multiply the brush data by the mask */
7453 for (y
=0; y
<pixel_area
.Height
; y
++)
7455 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
7456 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
7457 for (x
=0; x
<pixel_area
.Width
; x
++)
7459 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
7465 heap_free(text_mask
);
7467 gdi_transform_acquire(graphics
);
7469 /* draw the result */
7470 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
7471 pixel_area
.Height
, pixel_data_stride
, PixelFormat32bppARGB
);
7473 gdi_transform_release(graphics
);
7475 heap_free(pixel_data
);
7480 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7481 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7482 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7483 INT flags
, GDIPCONST GpMatrix
*matrix
)
7485 GpStatus stat
= NotImplemented
;
7488 length
= lstrlenW(text
);
7490 if (is_metafile_graphics(graphics
))
7491 return METAFILE_DrawDriverString((GpMetafile
*)graphics
->image
, text
, length
, font
,
7492 format
, brush
, positions
, flags
, matrix
);
7494 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
7495 brush
->bt
== BrushTypeSolidColor
&&
7496 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
7497 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7498 brush
, positions
, flags
, matrix
);
7499 if (stat
== NotImplemented
)
7500 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7501 brush
, positions
, flags
, matrix
);
7505 /*****************************************************************************
7506 * GdipDrawDriverString [GDIPLUS.@]
7508 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7509 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
7510 GDIPCONST PointF
*positions
, INT flags
,
7511 GDIPCONST GpMatrix
*matrix
)
7513 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
7515 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
7516 return InvalidParameter
;
7518 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
7519 brush
, positions
, flags
, matrix
);
7522 /*****************************************************************************
7523 * GdipIsVisibleClipEmpty [GDIPLUS.@]
7525 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
7530 TRACE("(%p, %p)\n", graphics
, res
);
7532 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
7535 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
7538 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
7541 GdipDeleteRegion(rgn
);
7545 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
7549 TRACE("(%p) stub\n", graphics
);
7552 FIXME("not implemented\n");
7554 return NotImplemented
;
7557 GpStatus WINGDIPAPI
GdipGraphicsSetAbort(GpGraphics
*graphics
, GdiplusAbort
*pabort
)
7559 TRACE("(%p, %p)\n", graphics
, pabort
);
7562 return InvalidParameter
;
7565 FIXME("Abort callback is not supported.\n");