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("%d, ", 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
;
423 GdipGetCompositingMode(graphics
, &comp_mode
);
425 for (y
=0; y
<src_height
; y
++)
427 for (x
=0; x
<src_width
; x
++)
429 ARGB dst_color
, src_color
;
430 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
432 if (comp_mode
== CompositingModeSourceCopy
)
434 if (!(src_color
& 0xff000000))
435 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, 0);
437 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, src_color
);
441 if (!(src_color
& 0xff000000))
444 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
445 if (fmt
& PixelFormatPAlpha
)
446 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over_fgpremult(dst_color
, src_color
));
448 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
456 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
457 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
461 BITMAPINFOHEADER bih
;
464 hdc
= CreateCompatibleDC(0);
466 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
467 bih
.biWidth
= src_width
;
468 bih
.biHeight
= -src_height
;
471 bih
.biCompression
= BI_RGB
;
473 bih
.biXPelsPerMeter
= 0;
474 bih
.biYPelsPerMeter
= 0;
476 bih
.biClrImportant
= 0;
478 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
479 (void**)&temp_bits
, NULL
, 0);
481 if(!hbitmap
|| !temp_bits
)
484 if ((GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
) == DT_RASPRINTER
&&
485 GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
) ||
486 fmt
& PixelFormatPAlpha
)
487 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
489 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
490 4 * src_width
, src
, src_stride
);
492 SelectObject(hdc
, hbitmap
);
493 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
494 hdc
, 0, 0, src_width
, src_height
);
496 DeleteObject(hbitmap
);
504 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
505 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
, PixelFormat fmt
)
509 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
515 HRGN hrgn
, visible_rgn
;
517 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
521 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
530 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
531 DeleteObject(visible_rgn
);
535 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
537 size
= GetRegionData(hrgn
, 0, NULL
);
539 rgndata
= heap_alloc_zero(size
);
546 GetRegionData(hrgn
, size
, rgndata
);
548 rects
= (RECT
*)rgndata
->Buffer
;
550 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
552 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
553 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
554 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
564 else if (is_metafile_graphics(graphics
))
566 ERR("This should not be used for metafiles; fix caller\n");
567 return NotImplemented
;
574 stat
= get_clip_hrgn(graphics
, &hrgn
);
579 save
= SaveDC(graphics
->hdc
);
581 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
584 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
586 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
587 src_height
, src_stride
, fmt
);
589 RestoreDC(graphics
->hdc
, save
);
597 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
598 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
600 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
, fmt
);
603 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
605 INT start_a
, end_a
, final_a
;
608 pos
= gdip_round(position
* 0xff);
610 start_a
= ((start
>> 24) & 0xff) * (pos
^ 0xff);
611 end_a
= ((end
>> 24) & 0xff) * pos
;
613 final_a
= start_a
+ end_a
;
615 if (final_a
< 0xff) return 0;
617 return (final_a
/ 0xff) << 24 |
618 ((((start
>> 16) & 0xff) * start_a
+ (((end
>> 16) & 0xff) * end_a
)) / final_a
) << 16 |
619 ((((start
>> 8) & 0xff) * start_a
+ (((end
>> 8) & 0xff) * end_a
)) / final_a
) << 8 |
620 (((start
& 0xff) * start_a
+ ((end
& 0xff) * end_a
)) / final_a
);
623 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
627 /* clamp to between 0.0 and 1.0, using the wrap mode */
628 position
= (position
- brush
->rect
.X
) / brush
->rect
.Width
;
629 if (brush
->wrap
== WrapModeTile
)
631 position
= fmodf(position
, 1.0f
);
632 if (position
< 0.0f
) position
+= 1.0f
;
634 else /* WrapModeFlip* */
636 position
= fmodf(position
, 2.0f
);
637 if (position
< 0.0f
) position
+= 2.0f
;
638 if (position
> 1.0f
) position
= 2.0f
- position
;
641 if (brush
->blendcount
== 1)
646 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
649 /* locate the blend positions surrounding this position */
650 while (position
> brush
->blendpos
[i
])
653 /* interpolate between the blend positions */
654 left_blendpos
= brush
->blendpos
[i
-1];
655 left_blendfac
= brush
->blendfac
[i
-1];
656 right_blendpos
= brush
->blendpos
[i
];
657 right_blendfac
= brush
->blendfac
[i
];
658 range
= right_blendpos
- left_blendpos
;
659 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
660 right_blendfac
* (position
- left_blendpos
)) / range
;
663 if (brush
->pblendcount
== 0)
664 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
668 ARGB left_blendcolor
, right_blendcolor
;
669 REAL left_blendpos
, right_blendpos
;
671 /* locate the blend colors surrounding this position */
672 while (blendfac
> brush
->pblendpos
[i
])
675 /* interpolate between the blend colors */
676 left_blendpos
= brush
->pblendpos
[i
-1];
677 left_blendcolor
= brush
->pblendcolor
[i
-1];
678 right_blendpos
= brush
->pblendpos
[i
];
679 right_blendcolor
= brush
->pblendcolor
[i
];
680 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
681 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
685 static BOOL
round_color_matrix(const ColorMatrix
*matrix
, int values
[5][5])
687 /* Convert floating point color matrix to int[5][5], return TRUE if it's an identity */
688 BOOL identity
= TRUE
;
694 if (matrix
->m
[j
][i
] != (i
== j
? 1.0 : 0.0))
696 values
[j
][i
] = gdip_round(matrix
->m
[j
][i
] * 256.0);
702 static ARGB
transform_color(ARGB color
, int matrix
[5][5])
706 unsigned char a
, r
, g
, b
;
708 val
[0] = ((color
>> 16) & 0xff); /* red */
709 val
[1] = ((color
>> 8) & 0xff); /* green */
710 val
[2] = (color
& 0xff); /* blue */
711 val
[3] = ((color
>> 24) & 0xff); /* alpha */
712 val
[4] = 255; /* translation */
719 res
[i
] += matrix
[j
][i
] * val
[j
];
722 a
= min(max(res
[3] / 256, 0), 255);
723 r
= min(max(res
[0] / 256, 0), 255);
724 g
= min(max(res
[1] / 256, 0), 255);
725 b
= min(max(res
[2] / 256, 0), 255);
727 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
730 static BOOL
color_is_gray(ARGB color
)
732 unsigned char r
, g
, b
;
734 r
= (color
>> 16) & 0xff;
735 g
= (color
>> 8) & 0xff;
738 return (r
== g
) && (g
== b
);
741 /* returns preferred pixel format for the applied attributes */
742 PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
743 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
)
748 if ((attributes
->noop
[type
] == IMAGEATTR_NOOP_UNDEFINED
&&
749 attributes
->noop
[ColorAdjustTypeDefault
] == IMAGEATTR_NOOP_SET
) ||
750 (attributes
->noop
[type
] == IMAGEATTR_NOOP_SET
))
753 if (attributes
->colorkeys
[type
].enabled
||
754 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
756 const struct color_key
*key
;
757 BYTE min_blue
, min_green
, min_red
;
758 BYTE max_blue
, max_green
, max_red
;
760 if (!data
|| fmt
!= PixelFormat32bppARGB
)
761 return PixelFormat32bppARGB
;
763 if (attributes
->colorkeys
[type
].enabled
)
764 key
= &attributes
->colorkeys
[type
];
766 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
768 min_blue
= key
->low
&0xff;
769 min_green
= (key
->low
>>8)&0xff;
770 min_red
= (key
->low
>>16)&0xff;
772 max_blue
= key
->high
&0xff;
773 max_green
= (key
->high
>>8)&0xff;
774 max_red
= (key
->high
>>16)&0xff;
776 for (x
=0; x
<width
; x
++)
777 for (y
=0; y
<height
; y
++)
780 BYTE blue
, green
, red
;
781 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
782 blue
= *src_color
&0xff;
783 green
= (*src_color
>>8)&0xff;
784 red
= (*src_color
>>16)&0xff;
785 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
786 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
787 *src_color
= 0x00000000;
791 if (attributes
->colorremaptables
[type
].enabled
||
792 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
794 const struct color_remap_table
*table
;
796 if (!data
|| fmt
!= PixelFormat32bppARGB
)
797 return PixelFormat32bppARGB
;
799 if (attributes
->colorremaptables
[type
].enabled
)
800 table
= &attributes
->colorremaptables
[type
];
802 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
804 for (x
=0; x
<width
; x
++)
805 for (y
=0; y
<height
; y
++)
808 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
809 for (i
=0; i
<table
->mapsize
; i
++)
811 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
813 *src_color
= table
->colormap
[i
].newColor
.Argb
;
820 if (attributes
->colormatrices
[type
].enabled
||
821 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
823 const struct color_matrix
*colormatrices
;
824 int color_matrix
[5][5];
825 int gray_matrix
[5][5];
828 if (!data
|| fmt
!= PixelFormat32bppARGB
)
829 return PixelFormat32bppARGB
;
831 if (attributes
->colormatrices
[type
].enabled
)
832 colormatrices
= &attributes
->colormatrices
[type
];
834 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
836 identity
= round_color_matrix(&colormatrices
->colormatrix
, color_matrix
);
838 if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
839 identity
= (round_color_matrix(&colormatrices
->graymatrix
, gray_matrix
) && identity
);
843 for (x
=0; x
<width
; x
++)
845 for (y
=0; y
<height
; y
++)
848 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
850 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
851 !color_is_gray(*src_color
))
853 *src_color
= transform_color(*src_color
, color_matrix
);
855 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
857 *src_color
= transform_color(*src_color
, gray_matrix
);
864 if (attributes
->gamma_enabled
[type
] ||
865 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
869 if (!data
|| fmt
!= PixelFormat32bppARGB
)
870 return PixelFormat32bppARGB
;
872 if (attributes
->gamma_enabled
[type
])
873 gamma
= attributes
->gamma
[type
];
875 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
877 for (x
=0; x
<width
; x
++)
878 for (y
=0; y
<height
; y
++)
881 BYTE blue
, green
, red
;
882 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
884 blue
= *src_color
&0xff;
885 green
= (*src_color
>>8)&0xff;
886 red
= (*src_color
>>16)&0xff;
888 /* FIXME: We should probably use a table for this. */
889 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
890 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
891 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
893 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
900 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
901 * bitmap that contains all the pixels we may need to draw it. */
902 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
903 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
906 INT left
, top
, right
, bottom
;
908 switch (interpolation
)
910 case InterpolationModeHighQualityBilinear
:
911 case InterpolationModeHighQualityBicubic
:
912 /* FIXME: Include a greater range for the prefilter? */
913 case InterpolationModeBicubic
:
914 case InterpolationModeBilinear
:
915 left
= (INT
)(floorf(srcx
));
916 top
= (INT
)(floorf(srcy
));
917 right
= (INT
)(ceilf(srcx
+srcwidth
));
918 bottom
= (INT
)(ceilf(srcy
+srcheight
));
920 case InterpolationModeNearestNeighbor
:
922 left
= gdip_round(srcx
);
923 top
= gdip_round(srcy
);
924 right
= gdip_round(srcx
+srcwidth
);
925 bottom
= gdip_round(srcy
+srcheight
);
929 if (wrap
== WrapModeClamp
)
935 if (right
>= bitmap
->width
)
936 right
= bitmap
->width
-1;
937 if (bottom
>= bitmap
->height
)
938 bottom
= bitmap
->height
-1;
939 if (bottom
< top
|| right
< left
)
940 /* entirely outside image, just sample a pixel so we don't have to
941 * special-case this later */
942 left
= top
= right
= bottom
= 0;
946 /* In some cases we can make the rectangle smaller here, but the logic
947 * is hard to get right, and tiling suggests we're likely to use the
948 * entire source image. */
949 if (left
< 0 || right
>= bitmap
->width
)
952 right
= bitmap
->width
-1;
955 if (top
< 0 || bottom
>= bitmap
->height
)
958 bottom
= bitmap
->height
-1;
964 rect
->Width
= right
- left
+ 1;
965 rect
->Height
= bottom
- top
+ 1;
968 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
969 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
971 if (attributes
->wrap
== WrapModeClamp
)
973 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
974 return attributes
->outside_color
;
978 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
980 x
= width
*2 + x
% (INT
)(width
* 2);
982 y
= height
*2 + y
% (INT
)(height
* 2);
984 if (attributes
->wrap
& WrapModeTileFlipX
)
986 if ((x
/ width
) % 2 == 0)
989 x
= width
- 1 - x
% width
;
994 if (attributes
->wrap
& WrapModeTileFlipY
)
996 if ((y
/ height
) % 2 == 0)
999 y
= height
- 1 - y
% height
;
1005 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
1007 ERR("out of range pixel requested\n");
1011 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
1014 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
1015 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
1016 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
1020 switch (interpolation
)
1024 FIXME("Unimplemented interpolation %i\n", interpolation
);
1026 case InterpolationModeBilinear
:
1029 INT leftx
, rightx
, topy
, bottomy
;
1030 ARGB topleft
, topright
, bottomleft
, bottomright
;
1034 leftxf
= floorf(point
->X
);
1035 leftx
= (INT
)leftxf
;
1036 rightx
= (INT
)ceilf(point
->X
);
1037 topyf
= floorf(point
->Y
);
1039 bottomy
= (INT
)ceilf(point
->Y
);
1041 if (leftx
== rightx
&& topy
== bottomy
)
1042 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1043 leftx
, topy
, attributes
);
1045 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1046 leftx
, topy
, attributes
);
1047 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1048 rightx
, topy
, attributes
);
1049 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1050 leftx
, bottomy
, attributes
);
1051 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1052 rightx
, bottomy
, attributes
);
1054 x_offset
= point
->X
- leftxf
;
1055 top
= blend_colors(topleft
, topright
, x_offset
);
1056 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
1058 return blend_colors(top
, bottom
, point
->Y
- topyf
);
1060 case InterpolationModeNearestNeighbor
:
1063 switch (offset_mode
)
1066 case PixelOffsetModeNone
:
1067 case PixelOffsetModeHighSpeed
:
1071 case PixelOffsetModeHalf
:
1072 case PixelOffsetModeHighQuality
:
1076 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1077 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
1083 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
1085 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
1088 /* is_fill is TRUE if filling regions, FALSE for drawing primitives */
1089 static BOOL
brush_can_fill_path(GpBrush
*brush
, BOOL is_fill
)
1093 case BrushTypeSolidColor
:
1099 /* cannot draw semi-transparent colors */
1100 return (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000;
1103 case BrushTypeHatchFill
:
1105 GpHatch
*hatch
= (GpHatch
*)brush
;
1106 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
1107 ((hatch
->backcol
& 0xff000000) == 0xff000000);
1109 case BrushTypeLinearGradient
:
1110 case BrushTypeTextureFill
:
1111 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
1117 static GpStatus
brush_fill_path(GpGraphics
*graphics
, GpBrush
*brush
)
1119 GpStatus status
= Ok
;
1122 case BrushTypeSolidColor
:
1124 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1125 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1130 /* partially transparent fill */
1132 if (!SelectClipPath(graphics
->hdc
, RGN_AND
))
1134 status
= GenericError
;
1138 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1140 HDC hdc
= CreateCompatibleDC(NULL
);
1144 status
= OutOfMemory
;
1149 SelectObject(hdc
, bmp
);
1150 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1158 /* else fall through */
1162 HBRUSH gdibrush
, old_brush
;
1164 gdibrush
= create_gdi_brush(brush
, graphics
->origin_x
, graphics
->origin_y
);
1167 status
= OutOfMemory
;
1171 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1172 FillPath(graphics
->hdc
);
1173 SelectObject(graphics
->hdc
, old_brush
);
1174 DeleteObject(gdibrush
);
1182 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1186 case BrushTypeSolidColor
:
1187 case BrushTypeHatchFill
:
1188 case BrushTypeLinearGradient
:
1189 case BrushTypeTextureFill
:
1190 case BrushTypePathGradient
:
1197 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1198 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1202 case BrushTypeSolidColor
:
1205 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1206 for (x
=0; x
<fill_area
->Width
; x
++)
1207 for (y
=0; y
<fill_area
->Height
; y
++)
1208 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1211 case BrushTypeHatchFill
:
1214 GpHatch
*fill
= (GpHatch
*)brush
;
1215 const unsigned char *hatch_data
;
1216 ARGB hatch_palette
[4];
1218 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1219 return NotImplemented
;
1221 init_hatch_palette(hatch_palette
, fill
->forecol
, fill
->backcol
);
1223 /* See create_hatch_bitmap for an explanation of how index is derived. */
1224 for (y
= 0; y
< fill_area
->Height
; y
++, argb_pixels
+= cdwStride
)
1226 const int hy
= ~(y
+ fill_area
->Y
- graphics
->origin_y
) & 7;
1227 const int hx
= graphics
->origin_x
& 7;
1228 const unsigned int row
= (0x10101 * hatch_data
[hy
]) >> hx
;
1230 for (x
= 0; x
< fill_area
->Width
; x
++)
1232 const unsigned int srow
= row
>> (~(x
+ fill_area
->X
) & 7);
1235 index
= (srow
& 1) ? 2 : (srow
& 0x82) ? 1 : 0;
1237 index
= (srow
& 1) ? 3 : 0;
1239 argb_pixels
[x
] = hatch_palette
[index
];
1245 case BrushTypeLinearGradient
:
1247 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1248 GpPointF draw_points
[3];
1252 draw_points
[0].X
= fill_area
->X
;
1253 draw_points
[0].Y
= fill_area
->Y
;
1254 draw_points
[1].X
= fill_area
->X
+1;
1255 draw_points
[1].Y
= fill_area
->Y
;
1256 draw_points
[2].X
= fill_area
->X
;
1257 draw_points
[2].Y
= fill_area
->Y
+1;
1259 /* Transform the points to a co-ordinate space where X is the point's
1260 * position in the gradient, 0.0 being the start point and 1.0 the
1262 stat
= gdip_transform_points(graphics
, CoordinateSpaceWorld
,
1263 WineCoordinateSpaceGdiDevice
, draw_points
, 3);
1267 GpMatrix world_to_gradient
= fill
->transform
;
1269 stat
= GdipInvertMatrix(&world_to_gradient
);
1271 stat
= GdipTransformMatrixPoints(&world_to_gradient
, draw_points
, 3);
1276 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1277 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1279 for (y
=0; y
<fill_area
->Height
; y
++)
1281 for (x
=0; x
<fill_area
->Width
; x
++)
1283 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1285 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1292 case BrushTypeTextureFill
:
1294 GpTexture
*fill
= (GpTexture
*)brush
;
1295 GpPointF draw_points
[3];
1302 if (fill
->image
->type
!= ImageTypeBitmap
)
1304 FIXME("metafile texture brushes not implemented\n");
1305 return NotImplemented
;
1308 bitmap
= (GpBitmap
*)fill
->image
;
1309 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1311 src_area
.X
= src_area
.Y
= 0;
1312 src_area
.Width
= bitmap
->width
;
1313 src_area
.Height
= bitmap
->height
;
1315 draw_points
[0].X
= fill_area
->X
;
1316 draw_points
[0].Y
= fill_area
->Y
;
1317 draw_points
[1].X
= fill_area
->X
+1;
1318 draw_points
[1].Y
= fill_area
->Y
;
1319 draw_points
[2].X
= fill_area
->X
;
1320 draw_points
[2].Y
= fill_area
->Y
+1;
1322 /* Transform the points to the co-ordinate space of the bitmap. */
1323 stat
= gdip_transform_points(graphics
, CoordinateSpaceWorld
,
1324 WineCoordinateSpaceGdiDevice
, draw_points
, 3);
1328 GpMatrix world_to_texture
= fill
->transform
;
1330 stat
= GdipInvertMatrix(&world_to_texture
);
1332 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1335 if (stat
== Ok
&& !fill
->bitmap_bits
)
1337 BitmapData lockeddata
;
1339 fill
->bitmap_bits
= heap_alloc_zero(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1340 if (!fill
->bitmap_bits
)
1345 lockeddata
.Width
= bitmap
->width
;
1346 lockeddata
.Height
= bitmap
->height
;
1347 lockeddata
.Stride
= src_stride
;
1348 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1349 lockeddata
.Scan0
= fill
->bitmap_bits
;
1351 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1352 PixelFormat32bppARGB
, &lockeddata
);
1356 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1359 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1360 bitmap
->width
, bitmap
->height
,
1361 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
1365 heap_free(fill
->bitmap_bits
);
1366 fill
->bitmap_bits
= NULL
;
1372 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1373 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1374 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1375 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1377 for (y
=0; y
<fill_area
->Height
; y
++)
1379 for (x
=0; x
<fill_area
->Width
; x
++)
1382 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1383 point
.Y
= draw_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
1385 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1386 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1387 &point
, fill
->imageattributes
, graphics
->interpolation
,
1388 graphics
->pixeloffset
);
1395 case BrushTypePathGradient
:
1397 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1399 GpMatrix world_to_device
;
1401 int i
, figure_start
=0;
1402 GpPointF start_point
, end_point
, center_point
;
1404 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1405 INT min_y
, max_y
, min_x
, max_x
;
1408 static BOOL transform_fixme_once
;
1410 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1414 FIXME("path gradient focus not implemented\n");
1421 FIXME("path gradient gamma correction not implemented\n");
1424 if (fill
->blendcount
)
1428 FIXME("path gradient blend not implemented\n");
1431 if (fill
->pblendcount
)
1435 FIXME("path gradient preset blend not implemented\n");
1438 if (!transform_fixme_once
)
1440 BOOL is_identity
=TRUE
;
1441 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1444 FIXME("path gradient transform not implemented\n");
1445 transform_fixme_once
= TRUE
;
1449 stat
= GdipClonePath(fill
->path
, &flat_path
);
1454 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
1455 CoordinateSpaceWorld
, &world_to_device
);
1458 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1462 center_point
= fill
->center
;
1463 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1467 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1472 GdipDeletePath(flat_path
);
1476 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1478 int start_center_line
=0, end_center_line
=0;
1479 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1480 REAL center_distance
;
1481 ARGB start_color
, end_color
;
1484 type
= flat_path
->pathdata
.Types
[i
];
1486 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1489 start_point
= flat_path
->pathdata
.Points
[i
];
1491 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1493 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1495 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1496 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1498 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1500 end_point
= flat_path
->pathdata
.Points
[i
+1];
1501 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1506 outer_color
= start_color
;
1508 min_yf
= center_point
.Y
;
1509 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1510 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1512 if (min_yf
< fill_area
->Y
)
1513 min_y
= fill_area
->Y
;
1515 min_y
= (INT
)ceil(min_yf
);
1517 max_yf
= center_point
.Y
;
1518 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1519 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1521 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1522 max_y
= fill_area
->Y
+ fill_area
->Height
;
1524 max_y
= (INT
)ceil(max_yf
);
1526 dy
= end_point
.Y
- start_point
.Y
;
1527 dx
= end_point
.X
- start_point
.X
;
1529 /* This is proportional to the distance from start-end line to center point. */
1530 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1531 dx
* (center_point
.Y
- start_point
.Y
);
1533 for (y
=min_y
; y
<max_y
; y
++)
1537 if (!seen_start
&& yf
>= start_point
.Y
)
1540 start_center_line
^= 1;
1542 if (!seen_end
&& yf
>= end_point
.Y
)
1545 end_center_line
^= 1;
1547 if (!seen_center
&& yf
>= center_point
.Y
)
1550 start_center_line
^= 1;
1551 end_center_line
^= 1;
1554 if (start_center_line
)
1555 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1557 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1559 if (end_center_line
)
1560 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1562 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1564 if (line1_xf
< line2_xf
)
1566 min_x
= (INT
)ceil(line1_xf
);
1567 max_x
= (INT
)ceil(line2_xf
);
1571 min_x
= (INT
)ceil(line2_xf
);
1572 max_x
= (INT
)ceil(line1_xf
);
1575 if (min_x
< fill_area
->X
)
1576 min_x
= fill_area
->X
;
1577 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1578 max_x
= fill_area
->X
+ fill_area
->Width
;
1580 for (x
=min_x
; x
<max_x
; x
++)
1585 if (start_color
!= end_color
)
1587 REAL blend_amount
, pdy
, pdx
;
1588 pdy
= yf
- center_point
.Y
;
1589 pdx
= xf
- center_point
.X
;
1591 if (fabs(pdx
) <= 0.001 && fabs(pdy
) <= 0.001)
1593 /* Too close to center point, don't try to calculate outer color */
1594 outer_color
= start_color
;
1598 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1599 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1603 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1604 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1606 distance
= distance
/ center_distance
;
1608 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1609 blend_colors(outer_color
, fill
->centercolor
, distance
);
1614 GdipDeletePath(flat_path
);
1618 return NotImplemented
;
1622 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1623 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1624 * should not be called on an hdc that has a path you care about. */
1625 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1626 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1628 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1630 HBRUSH brush
= NULL
;
1632 PointF ptf
[4], *custptf
= NULL
;
1633 POINT pt
[4], *custpt
= NULL
;
1635 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1640 if((x1
== x2
) && (y1
== y2
))
1643 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1645 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1647 brush
= CreateSolidBrush(color
);
1648 lb
.lbStyle
= BS_SOLID
;
1651 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1652 PS_JOIN_MITER
, 1, &lb
, 0,
1654 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1655 oldpen
= SelectObject(graphics
->hdc
, pen
);
1662 case LineCapSquareAnchor
:
1663 case LineCapDiamondAnchor
:
1664 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1665 if(cap
== LineCapDiamondAnchor
){
1666 dsmall
= cos(theta
+ M_PI_2
) * size
;
1667 dbig
= sin(theta
+ M_PI_2
) * size
;
1670 dsmall
= cos(theta
+ M_PI_4
) * size
;
1671 dbig
= sin(theta
+ M_PI_4
) * size
;
1674 ptf
[0].X
= x2
- dsmall
;
1675 ptf
[1].X
= x2
+ dbig
;
1677 ptf
[0].Y
= y2
- dbig
;
1678 ptf
[3].Y
= y2
+ dsmall
;
1680 ptf
[1].Y
= y2
- dsmall
;
1681 ptf
[2].Y
= y2
+ dbig
;
1683 ptf
[3].X
= x2
- dbig
;
1684 ptf
[2].X
= x2
+ dsmall
;
1686 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 4);
1688 round_points(pt
, ptf
, 4);
1690 Polygon(graphics
->hdc
, pt
, 4);
1693 case LineCapArrowAnchor
:
1694 size
= size
* 4.0 / sqrt(3.0);
1696 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1697 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1702 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1703 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1711 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1713 round_points(pt
, ptf
, 3);
1715 Polygon(graphics
->hdc
, pt
, 3);
1718 case LineCapRoundAnchor
:
1719 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1726 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 2);
1728 round_points(pt
, ptf
, 2);
1730 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1733 case LineCapTriangle
:
1735 dx
= cos(M_PI_2
+ theta
) * size
;
1736 dy
= sin(M_PI_2
+ theta
) * size
;
1743 dx
= cos(theta
) * size
;
1744 dy
= sin(theta
) * size
;
1749 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1751 round_points(pt
, ptf
, 3);
1753 Polygon(graphics
->hdc
, pt
, 3);
1757 dx
= dy
= size
/ 2.0;
1764 dx
= -cos(M_PI_2
+ theta
) * size
;
1765 dy
= -sin(M_PI_2
+ theta
) * size
;
1772 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 4);
1774 round_points(pt
, ptf
, 4);
1776 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1777 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1784 if (custom
->type
== CustomLineCapTypeAdjustableArrow
)
1786 GpAdjustableArrowCap
*arrow
= (GpAdjustableArrowCap
*)custom
;
1787 if (arrow
->cap
.fill
&& arrow
->height
<= 0.0)
1791 count
= custom
->pathdata
.Count
;
1792 custptf
= heap_alloc_zero(count
* sizeof(PointF
));
1793 custpt
= heap_alloc_zero(count
* sizeof(POINT
));
1794 tp
= heap_alloc_zero(count
);
1796 if(!custptf
|| !custpt
|| !tp
)
1799 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1801 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1802 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1803 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1805 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1806 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1808 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, custptf
, count
);
1810 round_points(custpt
, custptf
, count
);
1812 for(i
= 0; i
< count
; i
++)
1813 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1816 BeginPath(graphics
->hdc
);
1817 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1818 EndPath(graphics
->hdc
);
1819 StrokeAndFillPath(graphics
->hdc
);
1822 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1834 SelectObject(graphics
->hdc
, oldbrush
);
1835 SelectObject(graphics
->hdc
, oldpen
);
1836 DeleteObject(brush
);
1841 /* Shortens the line by the given percent by changing x2, y2.
1842 * If percent is > 1.0 then the line will change direction.
1843 * If percent is negative it can lengthen the line. */
1844 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1846 REAL dist
, theta
, dx
, dy
;
1848 if((y1
== *y2
) && (x1
== *x2
))
1851 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1852 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1853 dx
= cos(theta
) * dist
;
1854 dy
= sin(theta
) * dist
;
1860 /* Shortens the line by the given amount by changing x2, y2.
1861 * If the amount is greater than the distance, the line will become length 0.
1862 * If the amount is negative, it can lengthen the line. */
1863 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1865 REAL dx
, dy
, percent
;
1869 if(dx
== 0 && dy
== 0)
1872 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1879 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1882 /* Conducts a linear search to find the bezier points that will back off
1883 * the endpoint of the curve by a distance of amt. Linear search works
1884 * better than binary in this case because there are multiple solutions,
1885 * and binary searches often find a bad one. I don't think this is what
1886 * Windows does but short of rendering the bezier without GDI's help it's
1887 * the best we can do. If rev then work from the start of the passed points
1888 * instead of the end. */
1889 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1892 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1893 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1902 origx
= pt
[fourth
].X
;
1903 origy
= pt
[fourth
].Y
;
1904 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1906 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1907 /* reset bezier points to original values */
1908 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1909 /* Perform magic on bezier points. Order is important here.*/
1910 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1911 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1912 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1913 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1914 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1915 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1917 dx
= pt
[fourth
].X
- origx
;
1918 dy
= pt
[fourth
].Y
- origy
;
1920 diff
= sqrt(dx
* dx
+ dy
* dy
);
1921 percent
+= 0.0005 * amt
;
1925 /* Draws a combination of bezier curves and lines between points. */
1926 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1927 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1929 POINT
*pti
= heap_alloc_zero(count
* sizeof(POINT
));
1930 BYTE
*tp
= heap_alloc_zero(count
);
1931 GpPointF
*ptcopy
= heap_alloc_zero(count
* sizeof(GpPointF
));
1933 GpStatus status
= GenericError
;
1939 if(!pti
|| !tp
|| !ptcopy
){
1940 status
= OutOfMemory
;
1944 for(i
= 1; i
< count
; i
++){
1945 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1946 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1947 || !(types
[i
+ 2] & PathPointTypeBezier
)){
1948 ERR("Bad bezier points\n");
1955 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1957 /* If we are drawing caps, go through the points and adjust them accordingly,
1958 * and draw the caps. */
1960 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1961 case PathPointTypeBezier
:
1962 if(pen
->endcap
== LineCapArrowAnchor
)
1963 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1964 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1965 shorten_bezier_amt(&ptcopy
[count
- 4],
1966 pen
->width
* pen
->customend
->inset
, FALSE
);
1968 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1969 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1970 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1971 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1974 case PathPointTypeLine
:
1975 if(pen
->endcap
== LineCapArrowAnchor
)
1976 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1977 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1979 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1980 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1981 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1982 pen
->customend
->inset
* pen
->width
);
1984 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1985 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1990 ERR("Bad path last point\n");
1994 /* Find start of points */
1995 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1996 == PathPointTypeStart
); j
++);
1998 switch(types
[j
] & PathPointTypePathTypeMask
){
1999 case PathPointTypeBezier
:
2000 if(pen
->startcap
== LineCapArrowAnchor
)
2001 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
2002 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
2003 shorten_bezier_amt(&ptcopy
[j
- 1],
2004 pen
->width
* pen
->customstart
->inset
, TRUE
);
2006 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
2007 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
2008 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
2009 pt
[j
- 1].X
, pt
[j
- 1].Y
);
2012 case PathPointTypeLine
:
2013 if(pen
->startcap
== LineCapArrowAnchor
)
2014 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
2015 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
2017 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
2018 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
2019 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
2020 pen
->customstart
->inset
* pen
->width
);
2022 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
2023 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
2028 ERR("Bad path points\n");
2033 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptcopy
, count
);
2035 round_points(pti
, ptcopy
, count
);
2037 for(i
= 0; i
< count
; i
++){
2038 tp
[i
] = convert_path_point_type(types
[i
]);
2041 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
2053 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
2057 BeginPath(graphics
->hdc
);
2058 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2059 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2060 EndPath(graphics
->hdc
);
2064 typedef enum GraphicsContainerType
{
2067 } GraphicsContainerType
;
2069 typedef struct _GraphicsContainerItem
{
2071 GraphicsContainer contid
;
2072 GraphicsContainerType type
;
2074 SmoothingMode smoothing
;
2075 CompositingQuality compqual
;
2076 InterpolationMode interpolation
;
2077 CompositingMode compmode
;
2078 TextRenderingHint texthint
;
2081 PixelOffsetMode pixeloffset
;
2083 GpMatrix worldtrans
;
2085 INT origin_x
, origin_y
;
2086 } GraphicsContainerItem
;
2088 static GpStatus
init_container(GraphicsContainerItem
** container
,
2089 GDIPCONST GpGraphics
* graphics
, GraphicsContainerType type
){
2092 *container
= heap_alloc_zero(sizeof(GraphicsContainerItem
));
2096 (*container
)->contid
= graphics
->contid
+ 1;
2097 (*container
)->type
= type
;
2099 (*container
)->smoothing
= graphics
->smoothing
;
2100 (*container
)->compqual
= graphics
->compqual
;
2101 (*container
)->interpolation
= graphics
->interpolation
;
2102 (*container
)->compmode
= graphics
->compmode
;
2103 (*container
)->texthint
= graphics
->texthint
;
2104 (*container
)->scale
= graphics
->scale
;
2105 (*container
)->unit
= graphics
->unit
;
2106 (*container
)->textcontrast
= graphics
->textcontrast
;
2107 (*container
)->pixeloffset
= graphics
->pixeloffset
;
2108 (*container
)->origin_x
= graphics
->origin_x
;
2109 (*container
)->origin_y
= graphics
->origin_y
;
2110 (*container
)->worldtrans
= graphics
->worldtrans
;
2112 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
2114 heap_free(*container
);
2122 static void delete_container(GraphicsContainerItem
* container
)
2124 GdipDeleteRegion(container
->clip
);
2125 heap_free(container
);
2128 static GpStatus
restore_container(GpGraphics
* graphics
,
2129 GDIPCONST GraphicsContainerItem
* container
){
2133 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2134 if(sts
!= Ok
) return sts
;
2136 graphics
->worldtrans
= container
->worldtrans
;
2138 GdipDeleteRegion(graphics
->clip
);
2139 graphics
->clip
= newClip
;
2141 graphics
->contid
= container
->contid
- 1;
2143 graphics
->smoothing
= container
->smoothing
;
2144 graphics
->compqual
= container
->compqual
;
2145 graphics
->interpolation
= container
->interpolation
;
2146 graphics
->compmode
= container
->compmode
;
2147 graphics
->texthint
= container
->texthint
;
2148 graphics
->scale
= container
->scale
;
2149 graphics
->unit
= container
->unit
;
2150 graphics
->textcontrast
= container
->textcontrast
;
2151 graphics
->pixeloffset
= container
->pixeloffset
;
2152 graphics
->origin_x
= container
->origin_x
;
2153 graphics
->origin_y
= container
->origin_y
;
2158 static GpStatus
get_graphics_device_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2164 if(graphics
->hwnd
) {
2165 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2166 return GenericError
;
2168 rect
->X
= wnd_rect
.left
;
2169 rect
->Y
= wnd_rect
.top
;
2170 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2171 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2172 }else if (graphics
->image
){
2173 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2174 if (stat
== Ok
&& unit
!= UnitPixel
)
2175 FIXME("need to convert from unit %i\n", unit
);
2176 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2183 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2184 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2186 rect
->Width
= bmp
.bmWidth
;
2187 rect
->Height
= bmp
.bmHeight
;
2198 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2199 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2205 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2207 GpStatus stat
= get_graphics_device_bounds(graphics
, rect
);
2209 if (stat
== Ok
&& graphics
->hdc
)
2211 GpPointF points
[4], min_point
, max_point
;
2214 points
[0].X
= points
[2].X
= rect
->X
;
2215 points
[0].Y
= points
[1].Y
= rect
->Y
;
2216 points
[1].X
= points
[3].X
= rect
->X
+ rect
->Width
;
2217 points
[2].Y
= points
[3].Y
= rect
->Y
+ rect
->Height
;
2219 gdip_transform_points(graphics
, CoordinateSpaceDevice
, WineCoordinateSpaceGdiDevice
, points
, 4);
2221 min_point
= max_point
= points
[0];
2225 if (points
[i
].X
< min_point
.X
) min_point
.X
= points
[i
].X
;
2226 if (points
[i
].Y
< min_point
.Y
) min_point
.Y
= points
[i
].Y
;
2227 if (points
[i
].X
> max_point
.X
) max_point
.X
= points
[i
].X
;
2228 if (points
[i
].Y
> max_point
.Y
) max_point
.Y
= points
[i
].Y
;
2231 rect
->X
= min_point
.X
;
2232 rect
->Y
= min_point
.Y
;
2233 rect
->Width
= max_point
.X
- min_point
.X
;
2234 rect
->Height
= max_point
.Y
- min_point
.Y
;
2240 /* on success, rgn will contain the region of the graphics object which
2241 * is visible after clipping has been applied */
2242 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2248 /* Ignore graphics image bounds for metafiles */
2249 if (is_metafile_graphics(graphics
))
2250 return GdipCombineRegionRegion(rgn
, graphics
->clip
, CombineModeReplace
);
2252 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2255 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2258 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2261 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2264 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2267 GdipDeleteRegion(tmp
);
2271 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2275 if (font
->unit
== UnitPixel
)
2277 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
, graphics
->printer_display
);
2281 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2282 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
, graphics
->printer_display
);
2284 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
, graphics
->printer_display
);
2287 lf
->lfHeight
= -(height
+ 0.5);
2289 lf
->lfEscapement
= 0;
2290 lf
->lfOrientation
= 0;
2291 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2292 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2293 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2294 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2295 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2296 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2297 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2298 lf
->lfQuality
= DEFAULT_QUALITY
;
2299 lf
->lfPitchAndFamily
= 0;
2300 lstrcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2303 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2304 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2305 LOGFONTW
*lfw_return
, GDIPCONST GpMatrix
*matrix
)
2307 HDC hdc
= CreateCompatibleDC(0);
2309 REAL angle
, rel_width
, rel_height
, font_height
;
2311 HFONT unscaled_font
;
2312 TEXTMETRICW textmet
;
2314 if (font
->unit
== UnitPixel
|| font
->unit
== UnitWorld
)
2315 font_height
= font
->emSize
;
2318 REAL unit_scale
, res
;
2320 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2321 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
, graphics
->printer_display
);
2323 font_height
= font
->emSize
* unit_scale
;
2334 GpMatrix xform
= *matrix
;
2335 GdipTransformMatrixPoints(&xform
, pt
, 3);
2338 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
2339 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2340 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2341 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2342 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2343 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2344 /* If the font unit is not pixels scaling should not be applied */
2345 if (font
->unit
!= UnitPixel
&& font
->unit
!= UnitWorld
)
2347 rel_width
/= graphics
->scale
;
2348 rel_height
/= graphics
->scale
;
2351 get_log_fontW(font
, graphics
, &lfw
);
2352 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2353 unscaled_font
= CreateFontIndirectW(&lfw
);
2355 SelectObject(hdc
, unscaled_font
);
2356 GetTextMetricsW(hdc
, &textmet
);
2358 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2359 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2361 *hfont
= CreateFontIndirectW(&lfw
);
2367 DeleteObject(unscaled_font
);
2370 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2372 TRACE("(%p, %p)\n", hdc
, graphics
);
2374 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2377 static void get_gdi_transform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2381 if (graphics
->hdc
== NULL
)
2383 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2387 GetTransform(graphics
->hdc
, 0x204, &xform
);
2388 GdipSetMatrixElements(matrix
, xform
.eM11
, xform
.eM12
, xform
.eM21
, xform
.eM22
, xform
.eDx
, xform
.eDy
);
2391 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2397 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2400 FIXME("Don't know how to handle parameter hDevice\n");
2405 if(graphics
== NULL
)
2406 return InvalidParameter
;
2408 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2409 if(!*graphics
) return OutOfMemory
;
2411 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2413 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2414 heap_free(*graphics
);
2418 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2419 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2420 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2422 (*graphics
)->alpha_hdc
= 1;
2425 (*graphics
)->hdc
= hdc
;
2426 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2427 (*graphics
)->owndc
= FALSE
;
2428 (*graphics
)->smoothing
= SmoothingModeDefault
;
2429 (*graphics
)->compqual
= CompositingQualityDefault
;
2430 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2431 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2432 (*graphics
)->compmode
= CompositingModeSourceOver
;
2433 (*graphics
)->unit
= UnitDisplay
;
2434 (*graphics
)->scale
= 1.0;
2435 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2436 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2437 (*graphics
)->busy
= FALSE
;
2438 (*graphics
)->textcontrast
= 4;
2439 list_init(&(*graphics
)->containers
);
2440 (*graphics
)->contid
= 0;
2441 (*graphics
)->printer_display
= (GetDeviceCaps(hdc
, TECHNOLOGY
) == DT_RASPRINTER
);
2442 get_gdi_transform(*graphics
, &(*graphics
)->gdi_transform
);
2444 (*graphics
)->gdi_clip
= CreateRectRgn(0,0,0,0);
2445 if (!GetClipRgn(hdc
, (*graphics
)->gdi_clip
))
2447 DeleteObject((*graphics
)->gdi_clip
);
2448 (*graphics
)->gdi_clip
= NULL
;
2451 TRACE("<-- %p\n", *graphics
);
2456 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2460 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2461 if(!*graphics
) return OutOfMemory
;
2463 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2464 GdipSetMatrixElements(&(*graphics
)->gdi_transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2466 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2467 heap_free(*graphics
);
2471 (*graphics
)->hdc
= NULL
;
2472 (*graphics
)->hwnd
= NULL
;
2473 (*graphics
)->owndc
= FALSE
;
2474 (*graphics
)->image
= image
;
2475 /* We have to store the image type here because the image may be freed
2476 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2477 (*graphics
)->image_type
= image
->type
;
2478 (*graphics
)->smoothing
= SmoothingModeDefault
;
2479 (*graphics
)->compqual
= CompositingQualityDefault
;
2480 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2481 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2482 (*graphics
)->compmode
= CompositingModeSourceOver
;
2483 (*graphics
)->unit
= UnitDisplay
;
2484 (*graphics
)->scale
= 1.0;
2485 (*graphics
)->xres
= image
->xres
;
2486 (*graphics
)->yres
= image
->yres
;
2487 (*graphics
)->busy
= FALSE
;
2488 (*graphics
)->textcontrast
= 4;
2489 list_init(&(*graphics
)->containers
);
2490 (*graphics
)->contid
= 0;
2492 TRACE("<-- %p\n", *graphics
);
2497 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2502 TRACE("(%p, %p)\n", hwnd
, graphics
);
2506 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2508 ReleaseDC(hwnd
, hdc
);
2512 (*graphics
)->hwnd
= hwnd
;
2513 (*graphics
)->owndc
= TRUE
;
2518 /* FIXME: no icm handling */
2519 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2521 TRACE("(%p, %p)\n", hwnd
, graphics
);
2523 return GdipCreateFromHWND(hwnd
, graphics
);
2526 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2527 UINT access
, IStream
**stream
)
2532 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2534 if(!stream
|| !filename
)
2535 return InvalidParameter
;
2537 if(access
& GENERIC_WRITE
)
2538 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2539 else if(access
& GENERIC_READ
)
2540 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2542 return InvalidParameter
;
2544 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2546 return hresult_to_status(ret
);
2549 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2551 GraphicsContainerItem
*cont
, *next
;
2553 TRACE("(%p)\n", graphics
);
2555 if(!graphics
) return InvalidParameter
;
2556 if(graphics
->busy
) return ObjectBusy
;
2558 if (is_metafile_graphics(graphics
))
2560 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2565 if (graphics
->temp_hdc
)
2567 DeleteDC(graphics
->temp_hdc
);
2568 graphics
->temp_hdc
= NULL
;
2572 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2574 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2575 list_remove(&cont
->entry
);
2576 delete_container(cont
);
2579 GdipDeleteRegion(graphics
->clip
);
2581 DeleteObject(graphics
->gdi_clip
);
2583 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2584 * do otherwise, but we can't have that in the test suite because it means
2585 * accessing freed memory. */
2586 graphics
->busy
= TRUE
;
2588 heap_free(graphics
);
2593 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2594 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2599 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2600 width
, height
, startAngle
, sweepAngle
);
2602 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2603 return InvalidParameter
;
2608 status
= GdipCreatePath(FillModeAlternate
, &path
);
2609 if (status
!= Ok
) return status
;
2611 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2613 status
= GdipDrawPath(graphics
, pen
, path
);
2615 GdipDeletePath(path
);
2619 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2620 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2622 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2623 width
, height
, startAngle
, sweepAngle
);
2625 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2628 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2629 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2633 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2634 x2
, y2
, x3
, y3
, x4
, y4
);
2636 if(!graphics
|| !pen
)
2637 return InvalidParameter
;
2650 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2653 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2654 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2656 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2657 x2
, y2
, x3
, y3
, x4
, y4
);
2659 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2662 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2663 GDIPCONST GpPointF
*points
, INT count
)
2668 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2670 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2671 return InvalidParameter
;
2676 status
= GdipCreatePath(FillModeAlternate
, &path
);
2677 if (status
!= Ok
) return status
;
2679 status
= GdipAddPathBeziers(path
, points
, count
);
2681 status
= GdipDrawPath(graphics
, pen
, path
);
2683 GdipDeletePath(path
);
2687 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2688 GDIPCONST GpPoint
*points
, INT count
)
2694 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2696 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2697 return InvalidParameter
;
2702 pts
= heap_alloc_zero(sizeof(GpPointF
) * count
);
2706 for(i
= 0; i
< count
; i
++){
2707 pts
[i
].X
= (REAL
)points
[i
].X
;
2708 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2711 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2718 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2719 GDIPCONST GpPointF
*points
, INT count
)
2721 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2723 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2726 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2727 GDIPCONST GpPoint
*points
, INT count
)
2729 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2731 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2734 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2735 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2740 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2742 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2743 return InvalidParameter
;
2748 status
= GdipCreatePath(FillModeAlternate
, &path
);
2749 if (status
!= Ok
) return status
;
2751 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2753 status
= GdipDrawPath(graphics
, pen
, path
);
2755 GdipDeletePath(path
);
2760 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2761 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2767 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2769 if(!points
|| count
<= 0)
2770 return InvalidParameter
;
2772 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2776 for(i
= 0; i
< count
; i
++){
2777 ptf
[i
].X
= (REAL
)points
[i
].X
;
2778 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2781 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2788 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2789 GDIPCONST GpPointF
*points
, INT count
)
2791 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2793 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2796 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2797 GDIPCONST GpPoint
*points
, INT count
)
2803 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2806 return InvalidParameter
;
2808 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2812 for(i
= 0; i
< count
; i
++){
2813 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2814 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2817 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2823 /* Approximates cardinal spline with Bezier curves. */
2824 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2825 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2830 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2832 if(!graphics
|| !pen
)
2833 return InvalidParameter
;
2839 return InvalidParameter
;
2841 status
= GdipCreatePath(FillModeAlternate
, &path
);
2842 if (status
!= Ok
) return status
;
2844 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2846 status
= GdipDrawPath(graphics
, pen
, path
);
2848 GdipDeletePath(path
);
2852 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2853 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2859 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2862 return InvalidParameter
;
2864 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2868 for(i
= 0; i
< count
; i
++){
2869 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2870 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2873 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2879 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2880 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2883 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2885 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2886 return InvalidParameter
;
2889 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2892 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2893 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2896 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2902 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2903 return InvalidParameter
;
2906 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2909 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2910 REAL y
, REAL width
, REAL height
)
2916 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2918 if(!graphics
|| !pen
)
2919 return InvalidParameter
;
2924 if (is_metafile_graphics(graphics
))
2929 rect
.Height
= height
;
2930 return METAFILE_DrawEllipse((GpMetafile
*)graphics
->image
, pen
, &rect
);
2933 status
= GdipCreatePath(FillModeAlternate
, &path
);
2934 if (status
!= Ok
) return status
;
2936 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2938 status
= GdipDrawPath(graphics
, pen
, path
);
2940 GdipDeletePath(path
);
2944 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2945 INT y
, INT width
, INT height
)
2947 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2949 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2953 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2957 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2959 if(!graphics
|| !image
)
2960 return InvalidParameter
;
2962 GdipGetImageWidth(image
, &width
);
2963 GdipGetImageHeight(image
, &height
);
2965 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2966 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2969 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2972 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2974 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2977 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2978 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2982 REAL scale_x
, scale_y
, width
, height
;
2984 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2986 if (!graphics
|| !image
) return InvalidParameter
;
2988 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
, graphics
->printer_display
);
2989 scale_x
*= graphics
->xres
/ image
->xres
;
2990 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
, graphics
->printer_display
);
2991 scale_y
*= graphics
->yres
/ image
->yres
;
2992 width
= srcwidth
* scale_x
;
2993 height
= srcheight
* scale_y
;
2995 points
[0].X
= points
[2].X
= x
;
2996 points
[0].Y
= points
[1].Y
= y
;
2997 points
[1].X
= x
+ width
;
2998 points
[2].Y
= y
+ height
;
3000 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3001 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
3004 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
3005 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
3008 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
3011 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
3012 GDIPCONST GpPointF
*dstpoints
, INT count
)
3016 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
3019 return InvalidParameter
;
3021 GdipGetImageWidth(image
, &width
);
3022 GdipGetImageHeight(image
, &height
);
3024 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
3025 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
3028 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
3029 GDIPCONST GpPoint
*dstpoints
, INT count
)
3033 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
3035 if (count
!= 3 || !dstpoints
)
3036 return InvalidParameter
;
3038 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
3039 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
3040 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
3041 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
3042 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
3043 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
3045 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
3048 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
3049 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
3051 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
3055 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
3056 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
3057 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3058 DrawImageAbort callback
, VOID
* callbackData
)
3064 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
3065 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3069 return NotImplemented
;
3071 if(!graphics
|| !image
|| !points
|| count
!= 3)
3072 return InvalidParameter
;
3074 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
3075 debugstr_pointf(&points
[2]));
3077 if (is_metafile_graphics(graphics
))
3079 return METAFILE_DrawImagePointsRect((GpMetafile
*)graphics
->image
,
3080 image
, points
, count
, srcx
, srcy
, srcwidth
, srcheight
,
3081 srcUnit
, imageAttributes
, callback
, callbackData
);
3084 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
3086 /* Ensure source width/height is positive */
3089 GpPointF tmp
= ptf
[1];
3090 srcx
= srcx
+ srcwidth
;
3091 srcwidth
= -srcwidth
;
3092 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
3093 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
3100 GpPointF tmp
= ptf
[2];
3101 srcy
= srcy
+ srcheight
;
3102 srcheight
= -srcheight
;
3103 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
3104 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
3109 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
3110 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
3111 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
3113 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 4);
3114 round_points(pti
, ptf
, 4);
3116 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
3117 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
3119 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
, graphics
->printer_display
);
3120 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
, graphics
->printer_display
);
3121 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
, graphics
->printer_display
);
3122 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
, graphics
->printer_display
);
3123 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
3125 if (image
->type
== ImageTypeBitmap
)
3127 GpBitmap
* bitmap
= (GpBitmap
*)image
;
3128 BOOL do_resampling
= FALSE
;
3129 BOOL use_software
= FALSE
;
3131 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
3132 graphics
->xres
, graphics
->yres
,
3133 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
3134 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
3135 imageAttributes
? imageAttributes
->outside_color
: 0);
3137 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
3138 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
3139 srcx
< 0 || srcy
< 0 ||
3140 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
3141 do_resampling
= TRUE
;
3143 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
3144 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
3145 use_software
= TRUE
;
3150 GpRectF graphics_bounds
;
3152 int i
, x
, y
, src_stride
, dst_stride
;
3153 GpMatrix dst_to_src
;
3154 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
3155 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
3156 BitmapData lockeddata
;
3157 InterpolationMode interpolation
= graphics
->interpolation
;
3158 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
3159 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3160 REAL x_dx
, x_dy
, y_dx
, y_dy
;
3161 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
3163 if (!imageAttributes
)
3164 imageAttributes
= &defaultImageAttributes
;
3166 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3167 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3170 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3171 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3172 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3173 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3176 stat
= get_graphics_device_bounds(graphics
, &graphics_bounds
);
3177 if (stat
!= Ok
) return stat
;
3179 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
3180 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
3181 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
3182 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
3184 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
3186 if (IsRectEmpty(&dst_area
)) return Ok
;
3188 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3189 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3190 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3191 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3192 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3193 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3195 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
3197 stat
= GdipInvertMatrix(&dst_to_src
);
3198 if (stat
!= Ok
) return stat
;
3202 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3203 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3207 /* Make sure src_area is equal in size to dst_area. */
3208 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
3209 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
3210 src_area
.Width
= dst_area
.right
- dst_area
.left
;
3211 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
3214 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3216 src_data
= heap_alloc_zero(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3219 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3221 /* Read the bits we need from the source bitmap into a compatible buffer. */
3222 lockeddata
.Width
= src_area
.Width
;
3223 lockeddata
.Height
= src_area
.Height
;
3224 lockeddata
.Stride
= src_stride
;
3225 lockeddata
.Scan0
= src_data
;
3226 if (!do_resampling
&& bitmap
->format
== PixelFormat32bppPARGB
)
3227 lockeddata
.PixelFormat
= apply_image_attributes(imageAttributes
, NULL
, 0, 0, 0, ColorAdjustTypeBitmap
, bitmap
->format
);
3229 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3231 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3232 lockeddata
.PixelFormat
, &lockeddata
);
3235 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3239 heap_free(src_data
);
3243 apply_image_attributes(imageAttributes
, src_data
,
3244 src_area
.Width
, src_area
.Height
,
3245 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
3249 /* Transform the bits as needed to the destination. */
3250 dst_data
= dst_dyn_data
= heap_alloc_zero(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3253 heap_free(src_data
);
3257 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3259 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3261 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3262 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3263 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3264 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3266 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3268 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3270 GpPointF src_pointf
;
3273 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3274 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3276 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3278 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3279 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3280 imageAttributes
, interpolation
, offset_mode
);
3288 dst_data
= src_data
;
3289 dst_stride
= src_stride
;
3292 gdi_transform_acquire(graphics
);
3294 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3295 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
,
3296 lockeddata
.PixelFormat
);
3298 gdi_transform_release(graphics
);
3300 heap_free(src_data
);
3302 heap_free(dst_dyn_data
);
3309 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3310 HBITMAP hbitmap
, old_hbm
=NULL
;
3314 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3315 bitmap
->format
== PixelFormat24bppRGB
||
3316 bitmap
->format
== PixelFormat32bppRGB
||
3317 bitmap
->format
== PixelFormat32bppPARGB
))
3319 BITMAPINFOHEADER bih
;
3321 PixelFormat dst_format
;
3323 /* we can't draw a bitmap of this format directly */
3324 hdc
= CreateCompatibleDC(0);
3328 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3329 bih
.biWidth
= bitmap
->width
;
3330 bih
.biHeight
= -bitmap
->height
;
3332 bih
.biBitCount
= 32;
3333 bih
.biCompression
= BI_RGB
;
3334 bih
.biSizeImage
= 0;
3335 bih
.biXPelsPerMeter
= 0;
3336 bih
.biYPelsPerMeter
= 0;
3338 bih
.biClrImportant
= 0;
3340 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3341 (void**)&temp_bits
, NULL
, 0);
3343 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3344 dst_format
= PixelFormat32bppPARGB
;
3346 dst_format
= PixelFormat32bppRGB
;
3348 convert_pixels(bitmap
->width
, bitmap
->height
,
3349 bitmap
->width
*4, temp_bits
, dst_format
,
3350 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3351 bitmap
->image
.palette
);
3355 if (bitmap
->hbitmap
)
3356 hbitmap
= bitmap
->hbitmap
;
3359 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3364 temp_hdc
= (hdc
== 0);
3369 if (!hdc
) hdc
= CreateCompatibleDC(0);
3370 old_hbm
= SelectObject(hdc
, hbitmap
);
3373 save_state
= SaveDC(graphics
->hdc
);
3375 stat
= get_clip_hrgn(graphics
, &hrgn
);
3379 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
3383 gdi_transform_acquire(graphics
);
3385 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3387 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3388 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3392 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3393 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3396 gdi_transform_release(graphics
);
3398 RestoreDC(graphics
->hdc
, save_state
);
3402 SelectObject(hdc
, old_hbm
);
3407 DeleteObject(hbitmap
);
3410 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3416 rc
.Width
= srcwidth
;
3417 rc
.Height
= srcheight
;
3419 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3420 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3424 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3425 return InvalidParameter
;
3431 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3432 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3433 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3434 DrawImageAbort callback
, VOID
* callbackData
)
3436 GpPointF pointsF
[3];
3439 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3440 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3443 if(!points
|| count
!=3)
3444 return InvalidParameter
;
3446 for(i
= 0; i
< count
; i
++){
3447 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3448 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3451 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3452 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3453 callback
, callbackData
);
3456 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3457 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3458 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3459 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3460 VOID
* callbackData
)
3464 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3465 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3466 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3470 points
[1].X
= dstx
+ dstwidth
;
3473 points
[2].Y
= dsty
+ dstheight
;
3475 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3476 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3479 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3480 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3481 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3482 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3483 VOID
* callbackData
)
3487 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3488 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3489 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3493 points
[1].X
= dstx
+ dstwidth
;
3496 points
[2].Y
= dsty
+ dstheight
;
3498 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3499 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3502 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3503 REAL x
, REAL y
, REAL width
, REAL height
)
3509 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3511 if(!graphics
|| !image
)
3512 return InvalidParameter
;
3514 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3518 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3519 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3520 unit
, NULL
, NULL
, NULL
);
3523 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3524 INT x
, INT y
, INT width
, INT height
)
3526 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3528 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3531 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3532 REAL y1
, REAL x2
, REAL y2
)
3536 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3539 return InvalidParameter
;
3541 if (pen
->unit
== UnitPixel
&& pen
->width
<= 0.0)
3548 return GdipDrawLines(graphics
, pen
, pt
, 2);
3551 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3552 INT y1
, INT x2
, INT y2
)
3554 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3556 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3559 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3560 GpPointF
*points
, INT count
)
3565 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3567 if(!pen
|| !graphics
|| (count
< 2))
3568 return InvalidParameter
;
3573 status
= GdipCreatePath(FillModeAlternate
, &path
);
3574 if (status
!= Ok
) return status
;
3576 status
= GdipAddPathLine2(path
, points
, count
);
3578 status
= GdipDrawPath(graphics
, pen
, path
);
3580 GdipDeletePath(path
);
3584 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3585 GpPoint
*points
, INT count
)
3591 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3593 ptf
= heap_alloc_zero(count
* sizeof(GpPointF
));
3594 if(!ptf
) return OutOfMemory
;
3596 for(i
= 0; i
< count
; i
++){
3597 ptf
[i
].X
= (REAL
) points
[i
].X
;
3598 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3601 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3607 static GpStatus
GDI32_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3613 save_state
= prepare_dc(graphics
, pen
);
3615 retval
= get_clip_hrgn(graphics
, &hrgn
);
3620 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
3622 gdi_transform_acquire(graphics
);
3624 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3625 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3627 gdi_transform_release(graphics
);
3630 restore_dc(graphics
, save_state
);
3636 static GpStatus
SOFTWARE_GdipDrawThinPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3640 GpMatrix
* transform
;
3641 GpRectF gp_bound_rect
;
3642 GpRect gp_output_area
;
3644 INT output_height
, output_width
;
3645 DWORD
*output_bits
, *brush_bits
=NULL
;
3647 static const BYTE static_dash_pattern
[] = {1,1,1,0,1,0,1,0};
3648 const BYTE
*dash_pattern
;
3649 INT dash_pattern_size
;
3650 BYTE
*dyn_dash_pattern
= NULL
;
3652 stat
= GdipClonePath(path
, &flat_path
);
3657 stat
= GdipCreateMatrix(&transform
);
3661 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3662 CoordinateSpaceWorld
, transform
);
3665 stat
= GdipFlattenPath(flat_path
, transform
, 1.0);
3667 GdipDeleteMatrix(transform
);
3670 /* estimate the output size in pixels, can be larger than necessary */
3673 output_area
.left
= floorf(flat_path
->pathdata
.Points
[0].X
);
3674 output_area
.right
= ceilf(flat_path
->pathdata
.Points
[0].X
);
3675 output_area
.top
= floorf(flat_path
->pathdata
.Points
[0].Y
);
3676 output_area
.bottom
= ceilf(flat_path
->pathdata
.Points
[0].Y
);
3678 for (i
=1; i
<flat_path
->pathdata
.Count
; i
++)
3681 x
= flat_path
->pathdata
.Points
[i
].X
;
3682 y
= flat_path
->pathdata
.Points
[i
].Y
;
3684 if (floorf(x
) < output_area
.left
) output_area
.left
= floorf(x
);
3685 if (floorf(y
) < output_area
.top
) output_area
.top
= floorf(y
);
3686 if (ceilf(x
) > output_area
.right
) output_area
.right
= ceilf(x
);
3687 if (ceilf(y
) > output_area
.bottom
) output_area
.bottom
= ceilf(y
);
3690 stat
= get_graphics_device_bounds(graphics
, &gp_bound_rect
);
3695 output_area
.left
= max(output_area
.left
, floorf(gp_bound_rect
.X
));
3696 output_area
.top
= max(output_area
.top
, floorf(gp_bound_rect
.Y
));
3697 output_area
.right
= min(output_area
.right
, ceilf(gp_bound_rect
.X
+ gp_bound_rect
.Width
));
3698 output_area
.bottom
= min(output_area
.bottom
, ceilf(gp_bound_rect
.Y
+ gp_bound_rect
.Height
));
3700 output_width
= output_area
.right
- output_area
.left
+ 1;
3701 output_height
= output_area
.bottom
- output_area
.top
+ 1;
3703 if (output_width
<= 0 || output_height
<= 0)
3705 GdipDeletePath(flat_path
);
3709 gp_output_area
.X
= output_area
.left
;
3710 gp_output_area
.Y
= output_area
.top
;
3711 gp_output_area
.Width
= output_width
;
3712 gp_output_area
.Height
= output_height
;
3714 output_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3721 if (pen
->brush
->bt
!= BrushTypeSolidColor
)
3723 /* allocate and draw brush output */
3724 brush_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3728 stat
= brush_fill_pixels(graphics
, pen
->brush
, brush_bits
,
3729 &gp_output_area
, output_width
);
3737 /* convert dash pattern to bool array */
3740 case DashStyleCustom
:
3742 dash_pattern_size
= 0;
3744 for (i
=0; i
< pen
->numdashes
; i
++)
3745 dash_pattern_size
+= gdip_round(pen
->dashes
[i
]);
3747 if (dash_pattern_size
!= 0)
3749 dash_pattern
= dyn_dash_pattern
= heap_alloc(dash_pattern_size
);
3751 if (dyn_dash_pattern
)
3754 for (i
=0; i
< pen
->numdashes
; i
++)
3757 for (k
=0; k
< gdip_round(pen
->dashes
[i
]); k
++)
3758 dyn_dash_pattern
[j
++] = (i
&1)^1;
3766 /* else fall through */
3768 case DashStyleSolid
:
3770 dash_pattern
= static_dash_pattern
;
3771 dash_pattern_size
= 1;
3774 dash_pattern
= static_dash_pattern
;
3775 dash_pattern_size
= 4;
3778 dash_pattern
= &static_dash_pattern
[4];
3779 dash_pattern_size
= 2;
3781 case DashStyleDashDot
:
3782 dash_pattern
= static_dash_pattern
;
3783 dash_pattern_size
= 6;
3785 case DashStyleDashDotDot
:
3786 dash_pattern
= static_dash_pattern
;
3787 dash_pattern_size
= 8;
3795 GpPointF subpath_start
= flat_path
->pathdata
.Points
[0];
3796 INT prev_x
= INT_MAX
, prev_y
= INT_MAX
;
3797 int dash_pos
= dash_pattern_size
- 1;
3799 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
3802 GpPointF start_point
, end_point
;
3803 GpPoint start_pointi
, end_pointi
;
3805 type
= flat_path
->pathdata
.Types
[i
];
3806 if (i
+1 < flat_path
->pathdata
.Count
)
3807 type2
= flat_path
->pathdata
.Types
[i
+1];
3809 type2
= PathPointTypeStart
;
3811 start_point
= flat_path
->pathdata
.Points
[i
];
3813 if ((type
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3814 subpath_start
= start_point
;
3816 if ((type
& PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
3817 end_point
= subpath_start
;
3818 else if ((type2
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3821 end_point
= flat_path
->pathdata
.Points
[i
+1];
3823 start_pointi
.X
= floorf(start_point
.X
);
3824 start_pointi
.Y
= floorf(start_point
.Y
);
3825 end_pointi
.X
= floorf(end_point
.X
);
3826 end_pointi
.Y
= floorf(end_point
.Y
);
3828 if(start_pointi
.X
== end_pointi
.X
&& start_pointi
.Y
== end_pointi
.Y
)
3831 /* draw line segment */
3832 if (abs(start_pointi
.Y
- end_pointi
.Y
) > abs(start_pointi
.X
- end_pointi
.X
))
3834 INT x
, y
, start_y
, end_y
, step
;
3836 if (start_pointi
.Y
< end_pointi
.Y
)
3839 start_y
= ceilf(start_point
.Y
) - output_area
.top
;
3840 end_y
= end_pointi
.Y
- output_area
.top
;
3845 start_y
= start_point
.Y
- output_area
.top
;
3846 end_y
= ceilf(end_point
.Y
) - output_area
.top
;
3849 for (y
=start_y
; y
!= (end_y
+step
); y
+=step
)
3851 x
= gdip_round( start_point
.X
+
3852 (end_point
.X
- start_point
.X
) * (y
+ output_area
.top
- start_point
.Y
) / (end_point
.Y
- start_point
.Y
) )
3855 if (x
== prev_x
&& y
== prev_y
)
3860 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3862 if (!dash_pattern
[dash_pos
])
3865 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3869 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3871 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3876 INT x
, y
, start_x
, end_x
, step
;
3878 if (start_pointi
.X
< end_pointi
.X
)
3881 start_x
= ceilf(start_point
.X
) - output_area
.left
;
3882 end_x
= end_pointi
.X
- output_area
.left
;
3887 start_x
= start_point
.X
- output_area
.left
;
3888 end_x
= ceilf(end_point
.X
) - output_area
.left
;
3891 for (x
=start_x
; x
!= (end_x
+step
); x
+=step
)
3893 y
= gdip_round( start_point
.Y
+
3894 (end_point
.Y
- start_point
.Y
) * (x
+ output_area
.left
- start_point
.X
) / (end_point
.X
- start_point
.X
) )
3897 if (x
== prev_x
&& y
== prev_y
)
3902 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3904 if (!dash_pattern
[dash_pos
])
3907 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3911 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3913 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3919 /* draw output image */
3922 gdi_transform_acquire(graphics
);
3924 stat
= alpha_blend_pixels(graphics
, output_area
.left
, output_area
.top
,
3925 (BYTE
*)output_bits
, output_width
, output_height
, output_width
* 4,
3926 PixelFormat32bppARGB
);
3928 gdi_transform_release(graphics
);
3931 heap_free(brush_bits
);
3932 heap_free(dyn_dash_pattern
);
3933 heap_free(output_bits
);
3936 GdipDeletePath(flat_path
);
3941 static GpStatus
SOFTWARE_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3945 GpMatrix
*transform
=NULL
;
3948 /* Check if the final pen thickness in pixels is too thin. */
3949 if (pen
->unit
== UnitPixel
)
3951 if (pen
->width
< 1.415)
3952 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3956 GpPointF points
[3] = {{0,0}, {1,0}, {0,1}};
3958 points
[1].X
= pen
->width
;
3959 points
[2].Y
= pen
->width
;
3961 stat
= gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
,
3962 CoordinateSpaceWorld
, points
, 3);
3967 if (((points
[1].X
-points
[0].X
)*(points
[1].X
-points
[0].X
) +
3968 (points
[1].Y
-points
[0].Y
)*(points
[1].Y
-points
[0].Y
) < 2.0001) &&
3969 ((points
[2].X
-points
[0].X
)*(points
[2].X
-points
[0].X
) +
3970 (points
[2].Y
-points
[0].Y
)*(points
[2].Y
-points
[0].Y
) < 2.0001))
3971 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3974 stat
= GdipClonePath(path
, &wide_path
);
3979 if (pen
->unit
== UnitPixel
)
3981 /* We have to transform this to device coordinates to get the widths right. */
3982 stat
= GdipCreateMatrix(&transform
);
3985 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3986 CoordinateSpaceWorld
, transform
);
3990 /* Set flatness based on the final coordinate space */
3993 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3994 CoordinateSpaceWorld
, &t
);
3999 flatness
= 1.0/sqrt(fmax(
4000 t
.matrix
[0] * t
.matrix
[0] + t
.matrix
[1] * t
.matrix
[1],
4001 t
.matrix
[2] * t
.matrix
[2] + t
.matrix
[3] * t
.matrix
[3]));
4005 stat
= GdipWidenPath(wide_path
, pen
, transform
, flatness
);
4007 if (pen
->unit
== UnitPixel
)
4009 /* Transform the path back to world coordinates */
4011 stat
= GdipInvertMatrix(transform
);
4014 stat
= GdipTransformPath(wide_path
, transform
);
4017 /* Actually draw the path */
4019 stat
= GdipFillPath(graphics
, pen
->brush
, wide_path
);
4021 GdipDeleteMatrix(transform
);
4023 GdipDeletePath(wide_path
);
4028 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
4032 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
4034 if(!pen
|| !graphics
)
4035 return InvalidParameter
;
4040 if (path
->pathdata
.Count
== 0)
4043 if (is_metafile_graphics(graphics
))
4044 retval
= METAFILE_DrawPath((GpMetafile
*)graphics
->image
, pen
, path
);
4045 else if (!graphics
->hdc
|| graphics
->alpha_hdc
|| !brush_can_fill_path(pen
->brush
, FALSE
))
4046 retval
= SOFTWARE_GdipDrawPath(graphics
, pen
, path
);
4048 retval
= GDI32_GdipDrawPath(graphics
, pen
, path
);
4053 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
4054 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4059 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
4060 width
, height
, startAngle
, sweepAngle
);
4062 if(!graphics
|| !pen
)
4063 return InvalidParameter
;
4068 status
= GdipCreatePath(FillModeAlternate
, &path
);
4069 if (status
!= Ok
) return status
;
4071 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4073 status
= GdipDrawPath(graphics
, pen
, path
);
4075 GdipDeletePath(path
);
4079 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
4080 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4082 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
4083 width
, height
, startAngle
, sweepAngle
);
4085 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4088 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
4089 REAL y
, REAL width
, REAL height
)
4094 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
4096 if(!pen
|| !graphics
)
4097 return InvalidParameter
;
4102 status
= GdipCreatePath(FillModeAlternate
, &path
);
4103 if (status
!= Ok
) return status
;
4105 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
4107 status
= GdipDrawPath(graphics
, pen
, path
);
4109 GdipDeletePath(path
);
4113 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
4114 INT y
, INT width
, INT height
)
4116 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
4118 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
4121 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
4122 GDIPCONST GpRectF
* rects
, INT count
)
4127 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
4129 if(!graphics
|| !pen
|| !rects
|| count
< 1)
4130 return InvalidParameter
;
4135 if (is_metafile_graphics(graphics
))
4136 return METAFILE_DrawRectangles((GpMetafile
*)graphics
->image
, pen
, rects
, count
);
4138 status
= GdipCreatePath(FillModeAlternate
, &path
);
4139 if (status
!= Ok
) return status
;
4141 status
= GdipAddPathRectangles(path
, rects
, count
);
4143 status
= GdipDrawPath(graphics
, pen
, path
);
4145 GdipDeletePath(path
);
4149 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
4150 GDIPCONST GpRect
* rects
, INT count
)
4156 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
4158 if(!rects
|| count
<=0)
4159 return InvalidParameter
;
4161 rectsF
= heap_alloc_zero(sizeof(GpRectF
) * count
);
4165 for(i
= 0;i
< count
;i
++){
4166 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4167 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4168 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
4169 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4172 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
4178 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
4179 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
4184 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
4185 count
, tension
, fill
);
4187 if(!graphics
|| !brush
|| !points
)
4188 return InvalidParameter
;
4193 if(count
== 1) /* Do nothing */
4196 status
= GdipCreatePath(fill
, &path
);
4197 if (status
!= Ok
) return status
;
4199 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
4201 status
= GdipFillPath(graphics
, brush
, path
);
4203 GdipDeletePath(path
);
4207 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
4208 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
4214 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
4215 count
, tension
, fill
);
4217 if(!points
|| count
== 0)
4218 return InvalidParameter
;
4220 if(count
== 1) /* Do nothing */
4223 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
4227 for(i
= 0;i
< count
;i
++){
4228 ptf
[i
].X
= (REAL
)points
[i
].X
;
4229 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4232 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
4239 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
4240 GDIPCONST GpPointF
*points
, INT count
)
4242 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4243 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
4244 0.5f
, FillModeAlternate
);
4247 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
4248 GDIPCONST GpPoint
*points
, INT count
)
4250 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4251 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
4252 0.5f
, FillModeAlternate
);
4255 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4256 REAL y
, REAL width
, REAL height
)
4261 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4263 if(!graphics
|| !brush
)
4264 return InvalidParameter
;
4269 if (is_metafile_graphics(graphics
))
4276 rect
.Height
= height
;
4277 return METAFILE_FillEllipse((GpMetafile
*)graphics
->image
, brush
, &rect
);
4280 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4284 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
4287 stat
= GdipFillPath(graphics
, brush
, path
);
4289 GdipDeletePath(path
);
4295 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4296 INT y
, INT width
, INT height
)
4298 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4300 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
4303 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4309 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4310 return NotImplemented
;
4312 save_state
= SaveDC(graphics
->hdc
);
4313 EndPath(graphics
->hdc
);
4314 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
4317 retval
= get_clip_hrgn(graphics
, &hrgn
);
4322 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
4324 gdi_transform_acquire(graphics
);
4326 BeginPath(graphics
->hdc
);
4327 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
4328 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
4332 EndPath(graphics
->hdc
);
4333 retval
= brush_fill_path(graphics
, brush
);
4336 gdi_transform_release(graphics
);
4339 RestoreDC(graphics
->hdc
, save_state
);
4345 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4350 if (!brush_can_fill_pixels(brush
))
4351 return NotImplemented
;
4353 /* FIXME: This could probably be done more efficiently without regions. */
4355 stat
= GdipCreateRegionPath(path
, &rgn
);
4359 stat
= GdipFillRegion(graphics
, brush
, rgn
);
4361 GdipDeleteRegion(rgn
);
4367 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4369 GpStatus stat
= NotImplemented
;
4371 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
4373 if(!brush
|| !graphics
|| !path
)
4374 return InvalidParameter
;
4379 if (!path
->pathdata
.Count
)
4382 if (is_metafile_graphics(graphics
))
4383 return METAFILE_FillPath((GpMetafile
*)graphics
->image
, brush
, path
);
4385 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4386 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
4388 if (stat
== NotImplemented
)
4389 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
4391 if (stat
== NotImplemented
)
4393 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
4400 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4401 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4406 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
4407 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4409 if(!graphics
|| !brush
)
4410 return InvalidParameter
;
4415 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4419 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4422 stat
= GdipFillPath(graphics
, brush
, path
);
4424 GdipDeletePath(path
);
4430 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4431 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4433 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
4434 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4436 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4439 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
4440 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
4445 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4447 if(!graphics
|| !brush
|| !points
|| !count
)
4448 return InvalidParameter
;
4453 stat
= GdipCreatePath(fillMode
, &path
);
4457 stat
= GdipAddPathPolygon(path
, points
, count
);
4460 stat
= GdipFillPath(graphics
, brush
, path
);
4462 GdipDeletePath(path
);
4468 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4469 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4474 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4476 if(!graphics
|| !brush
|| !points
|| !count
)
4477 return InvalidParameter
;
4482 stat
= GdipCreatePath(fillMode
, &path
);
4486 stat
= GdipAddPathPolygonI(path
, points
, count
);
4489 stat
= GdipFillPath(graphics
, brush
, path
);
4491 GdipDeletePath(path
);
4497 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4498 GDIPCONST GpPointF
*points
, INT count
)
4500 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4502 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4505 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4506 GDIPCONST GpPoint
*points
, INT count
)
4508 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4510 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4513 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4514 REAL x
, REAL y
, REAL width
, REAL height
)
4518 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4523 rect
.Height
= height
;
4525 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4528 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4529 INT x
, INT y
, INT width
, INT height
)
4533 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4537 rect
.Width
= (REAL
)width
;
4538 rect
.Height
= (REAL
)height
;
4540 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4543 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4549 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4551 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
4552 return InvalidParameter
;
4554 if (is_metafile_graphics(graphics
))
4556 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
4557 /* FIXME: Add gdi32 drawing. */
4561 status
= GdipCreatePath(FillModeAlternate
, &path
);
4562 if (status
!= Ok
) return status
;
4564 status
= GdipAddPathRectangles(path
, rects
, count
);
4566 status
= GdipFillPath(graphics
, brush
, path
);
4568 GdipDeletePath(path
);
4572 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4579 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4581 if(!rects
|| count
<= 0)
4582 return InvalidParameter
;
4584 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
4588 for(i
= 0; i
< count
; i
++){
4589 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4590 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4591 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
4592 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4595 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4601 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4609 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4610 return NotImplemented
;
4612 save_state
= SaveDC(graphics
->hdc
);
4613 EndPath(graphics
->hdc
);
4616 status
= get_clip_hrgn(graphics
, &hrgn
);
4619 RestoreDC(graphics
->hdc
, save_state
);
4623 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
4626 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4629 RestoreDC(graphics
->hdc
, save_state
);
4633 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4636 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4638 BeginPath(graphics
->hdc
);
4639 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4640 EndPath(graphics
->hdc
);
4642 status
= brush_fill_path(graphics
, brush
);
4645 RestoreDC(graphics
->hdc
, save_state
);
4651 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4655 GpRegion
*temp_region
;
4656 GpMatrix world_to_device
;
4657 GpRectF graphics_bounds
;
4661 GpRect gp_bound_rect
;
4663 if (!brush_can_fill_pixels(brush
))
4664 return NotImplemented
;
4666 stat
= gdi_transform_acquire(graphics
);
4669 stat
= get_graphics_device_bounds(graphics
, &graphics_bounds
);
4672 stat
= GdipCloneRegion(region
, &temp_region
);
4676 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
4677 CoordinateSpaceWorld
, &world_to_device
);
4680 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4683 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4686 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4688 GdipDeleteRegion(temp_region
);
4691 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4693 DeleteObject(hregion
);
4694 gdi_transform_release(graphics
);
4700 gp_bound_rect
.X
= bound_rect
.left
;
4701 gp_bound_rect
.Y
= bound_rect
.top
;
4702 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4703 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4705 pixel_data
= heap_alloc_zero(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4711 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4712 &gp_bound_rect
, gp_bound_rect
.Width
);
4715 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4716 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4717 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
,
4718 PixelFormat32bppARGB
);
4720 heap_free(pixel_data
);
4723 DeleteObject(hregion
);
4726 gdi_transform_release(graphics
);
4731 /*****************************************************************************
4732 * GdipFillRegion [GDIPLUS.@]
4734 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4737 GpStatus stat
= NotImplemented
;
4739 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4741 if (!(graphics
&& brush
&& region
))
4742 return InvalidParameter
;
4747 if (is_metafile_graphics(graphics
))
4748 stat
= METAFILE_FillRegion((GpMetafile
*)graphics
->image
, brush
, region
);
4751 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4752 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4754 if (stat
== NotImplemented
)
4755 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4758 if (stat
== NotImplemented
)
4760 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4767 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4769 TRACE("(%p,%u)\n", graphics
, intention
);
4772 return InvalidParameter
;
4777 /* We have no internal operation queue, so there's no need to clear it. */
4785 /*****************************************************************************
4786 * GdipGetClipBounds [GDIPLUS.@]
4788 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4793 TRACE("(%p, %p)\n", graphics
, rect
);
4796 return InvalidParameter
;
4801 status
= GdipCreateRegion(&clip
);
4802 if (status
!= Ok
) return status
;
4804 status
= GdipGetClip(graphics
, clip
);
4806 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4808 GdipDeleteRegion(clip
);
4812 /*****************************************************************************
4813 * GdipGetClipBoundsI [GDIPLUS.@]
4815 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4820 TRACE("(%p, %p)\n", graphics
, rect
);
4823 return InvalidParameter
;
4825 if ((stat
= GdipGetClipBounds(graphics
, &rectf
)) == Ok
)
4827 rect
->X
= gdip_round(rectf
.X
);
4828 rect
->Y
= gdip_round(rectf
.Y
);
4829 rect
->Width
= gdip_round(rectf
.Width
);
4830 rect
->Height
= gdip_round(rectf
.Height
);
4836 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4837 CompositingMode
*mode
)
4839 TRACE("(%p, %p)\n", graphics
, mode
);
4841 if(!graphics
|| !mode
)
4842 return InvalidParameter
;
4847 *mode
= graphics
->compmode
;
4852 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4853 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4854 CompositingQuality
*quality
)
4856 TRACE("(%p, %p)\n", graphics
, quality
);
4858 if(!graphics
|| !quality
)
4859 return InvalidParameter
;
4864 *quality
= graphics
->compqual
;
4869 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4870 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4871 InterpolationMode
*mode
)
4873 TRACE("(%p, %p)\n", graphics
, mode
);
4875 if(!graphics
|| !mode
)
4876 return InvalidParameter
;
4881 *mode
= graphics
->interpolation
;
4886 /* FIXME: Need to handle color depths less than 24bpp */
4887 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4889 TRACE("(%p, %p)\n", graphics
, argb
);
4891 if(!graphics
|| !argb
)
4892 return InvalidParameter
;
4897 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
4900 GpBitmap
*bitmap
= (GpBitmap
*)graphics
->image
;
4901 if (IsIndexedPixelFormat(bitmap
->format
) && !once
++)
4902 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4908 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4910 TRACE("(%p, %p)\n", graphics
, scale
);
4912 if(!graphics
|| !scale
)
4913 return InvalidParameter
;
4918 *scale
= graphics
->scale
;
4923 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4925 TRACE("(%p, %p)\n", graphics
, unit
);
4927 if(!graphics
|| !unit
)
4928 return InvalidParameter
;
4933 *unit
= graphics
->unit
;
4938 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4939 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4942 TRACE("(%p, %p)\n", graphics
, mode
);
4944 if(!graphics
|| !mode
)
4945 return InvalidParameter
;
4950 *mode
= graphics
->pixeloffset
;
4955 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4956 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4958 TRACE("(%p, %p)\n", graphics
, mode
);
4960 if(!graphics
|| !mode
)
4961 return InvalidParameter
;
4966 *mode
= graphics
->smoothing
;
4971 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4973 TRACE("(%p, %p)\n", graphics
, contrast
);
4975 if(!graphics
|| !contrast
)
4976 return InvalidParameter
;
4978 *contrast
= graphics
->textcontrast
;
4983 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4984 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4985 TextRenderingHint
*hint
)
4987 TRACE("(%p, %p)\n", graphics
, hint
);
4989 if(!graphics
|| !hint
)
4990 return InvalidParameter
;
4995 *hint
= graphics
->texthint
;
5000 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
5004 GpMatrix device_to_world
;
5006 TRACE("(%p, %p)\n", graphics
, rect
);
5008 if(!graphics
|| !rect
)
5009 return InvalidParameter
;
5014 /* intersect window and graphics clipping regions */
5015 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
5018 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
5021 /* transform to world coordinates */
5022 if((stat
= get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
)) != Ok
)
5025 if((stat
= GdipTransformRegion(clip_rgn
, &device_to_world
)) != Ok
)
5028 /* get bounds of the region */
5029 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
5032 GdipDeleteRegion(clip_rgn
);
5037 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
5042 TRACE("(%p, %p)\n", graphics
, rect
);
5044 if(!graphics
|| !rect
)
5045 return InvalidParameter
;
5047 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
5049 rect
->X
= gdip_round(rectf
.X
);
5050 rect
->Y
= gdip_round(rectf
.Y
);
5051 rect
->Width
= gdip_round(rectf
.Width
);
5052 rect
->Height
= gdip_round(rectf
.Height
);
5058 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5060 TRACE("(%p, %p)\n", graphics
, matrix
);
5062 if(!graphics
|| !matrix
)
5063 return InvalidParameter
;
5068 *matrix
= graphics
->worldtrans
;
5072 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
5077 CompositingMode prev_comp_mode
;
5079 TRACE("(%p, %x)\n", graphics
, color
);
5082 return InvalidParameter
;
5087 if (is_metafile_graphics(graphics
))
5088 return METAFILE_GraphicsClear((GpMetafile
*)graphics
->image
, color
);
5090 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
5093 if((stat
= GdipGetVisibleClipBounds(graphics
, &wnd_rect
)) != Ok
){
5094 GdipDeleteBrush((GpBrush
*)brush
);
5098 GdipGetCompositingMode(graphics
, &prev_comp_mode
);
5099 GdipSetCompositingMode(graphics
, CompositingModeSourceCopy
);
5100 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
5101 wnd_rect
.Width
, wnd_rect
.Height
);
5102 GdipSetCompositingMode(graphics
, prev_comp_mode
);
5104 GdipDeleteBrush((GpBrush
*)brush
);
5109 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
5111 TRACE("(%p, %p)\n", graphics
, res
);
5113 if(!graphics
|| !res
)
5114 return InvalidParameter
;
5116 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
5119 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
5125 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
5127 if(!graphics
|| !result
)
5128 return InvalidParameter
;
5135 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
5136 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
5139 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5142 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5145 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
5148 GdipDeleteRegion(rgn
);
5152 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
5154 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
5157 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
5163 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
5165 if(!graphics
|| !result
)
5166 return InvalidParameter
;
5173 pts
[1].X
= x
+ width
;
5174 pts
[1].Y
= y
+ height
;
5176 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
5177 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
5180 pts
[1].X
-= pts
[0].X
;
5181 pts
[1].Y
-= pts
[0].Y
;
5183 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5186 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5189 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
5192 GdipDeleteRegion(rgn
);
5196 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
5198 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
5201 GpStatus
gdip_format_string(HDC hdc
,
5202 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5203 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
5204 gdip_format_string_callback callback
, void *user_data
)
5207 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
5208 nheight
, lineend
, lineno
= 0;
5210 StringAlignment halign
;
5213 HotkeyPrefix hkprefix
;
5214 INT
*hotkeyprefix_offsets
=NULL
;
5215 INT hotkeyprefix_count
=0;
5216 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
5217 BOOL seen_prefix
= FALSE
;
5219 if(length
== -1) length
= lstrlenW(string
);
5221 stringdup
= heap_alloc_zero((length
+ 1) * sizeof(WCHAR
));
5222 if(!stringdup
) return OutOfMemory
;
5225 format
= &default_drawstring_format
;
5227 nwidth
= rect
->Width
;
5228 nheight
= rect
->Height
;
5229 if (ignore_empty_clip
)
5231 if (!nwidth
) nwidth
= INT_MAX
;
5232 if (!nheight
) nheight
= INT_MAX
;
5235 hkprefix
= format
->hkprefix
;
5237 if (hkprefix
== HotkeyPrefixShow
)
5239 for (i
=0; i
<length
; i
++)
5241 if (string
[i
] == '&')
5242 hotkeyprefix_count
++;
5246 if (hotkeyprefix_count
)
5248 hotkeyprefix_offsets
= heap_alloc_zero(sizeof(INT
) * hotkeyprefix_count
);
5249 if (!hotkeyprefix_offsets
)
5251 heap_free(stringdup
);
5256 hotkeyprefix_count
= 0;
5258 for(i
= 0, j
= 0; i
< length
; i
++){
5259 /* FIXME: This makes the indexes passed to callback inaccurate. */
5260 if(!iswprint(string
[i
]) && (string
[i
] != '\n'))
5263 /* FIXME: tabs should be handled using tabstops from stringformat */
5264 if (string
[i
] == '\t')
5267 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
5268 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
5269 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
5275 seen_prefix
= FALSE
;
5277 stringdup
[j
] = string
[i
];
5283 halign
= format
->align
;
5285 while(sum
< length
){
5286 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
5287 nwidth
, &fit
, NULL
, &size
);
5293 for(lret
= 0; lret
< fit
; lret
++)
5294 if(*(stringdup
+ sum
+ lret
) == '\n')
5297 /* Line break code (may look strange, but it imitates windows). */
5299 lineend
= fit
= lret
; /* this is not an off-by-one error */
5300 else if(fit
< (length
- sum
)){
5301 if(*(stringdup
+ sum
+ fit
) == ' ')
5302 while(*(stringdup
+ sum
+ fit
) == ' ')
5304 else if (!(format
->attr
& StringFormatFlagsNoWrap
))
5305 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
5308 if(*(stringdup
+ sum
+ fit
) == '\t')
5317 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
5318 *(stringdup
+ sum
+ lineend
- 1) == '\t')
5324 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
5325 nwidth
, &j
, NULL
, &size
);
5327 bounds
.Width
= size
.cx
;
5329 if(height
+ size
.cy
> nheight
)
5331 if (format
->attr
& StringFormatFlagsLineLimit
)
5333 bounds
.Height
= nheight
- (height
+ size
.cy
);
5336 bounds
.Height
= size
.cy
;
5338 bounds
.Y
= rect
->Y
+ height
;
5342 case StringAlignmentNear
:
5346 case StringAlignmentCenter
:
5347 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
5349 case StringAlignmentFar
:
5350 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
5354 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
5355 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
5358 stat
= callback(hdc
, stringdup
, sum
, lineend
,
5359 font
, rect
, format
, lineno
, &bounds
,
5360 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
5361 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
5366 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
5370 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
5372 if(height
> nheight
)
5375 /* Stop if this was a linewrap (but not if it was a linebreak). */
5376 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
5380 heap_free(stringdup
);
5381 heap_free(hotkeyprefix_offsets
);
5386 struct measure_ranges_args
{
5388 REAL rel_width
, rel_height
;
5391 static GpStatus
measure_ranges_callback(HDC hdc
,
5392 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5393 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5394 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5395 INT underlined_index_count
, void *user_data
)
5399 struct measure_ranges_args
*args
= user_data
;
5401 for (i
=0; i
<format
->range_count
; i
++)
5403 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
5404 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
5405 if (range_start
< range_end
)
5410 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
5411 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
5413 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
5414 INT_MAX
, NULL
, NULL
, &range_size
);
5415 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
5417 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
5418 INT_MAX
, NULL
, NULL
, &range_size
);
5419 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
5421 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
5430 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
5431 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
5432 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
5433 INT regionCount
, GpRegion
** regions
)
5437 HFONT gdifont
, oldfont
;
5438 struct measure_ranges_args args
;
5439 HDC hdc
, temp_hdc
=NULL
;
5444 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_wn(string
, length
),
5445 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
5447 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
5448 return InvalidParameter
;
5450 if (regionCount
< stringFormat
->range_count
)
5451 return InvalidParameter
;
5455 hdc
= temp_hdc
= CreateCompatibleDC(0);
5456 if (!temp_hdc
) return OutOfMemory
;
5459 hdc
= graphics
->hdc
;
5461 if (stringFormat
->attr
)
5462 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
5470 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5471 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5472 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5473 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5474 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5476 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
5477 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
, graphics
->printer_display
);
5479 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
5480 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
5481 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
5482 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
5484 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5485 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5487 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
, NULL
);
5488 oldfont
= SelectObject(hdc
, gdifont
);
5490 for (i
=0; i
<stringFormat
->range_count
; i
++)
5492 stat
= GdipSetEmpty(regions
[i
]);
5495 SelectObject(hdc
, oldfont
);
5496 DeleteObject(gdifont
);
5503 args
.regions
= regions
;
5505 gdi_transform_acquire(graphics
);
5507 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
5508 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
5510 gdi_transform_release(graphics
);
5512 SelectObject(hdc
, oldfont
);
5513 DeleteObject(gdifont
);
5521 struct measure_string_args
{
5523 INT
*codepointsfitted
;
5525 REAL rel_width
, rel_height
;
5528 static GpStatus
measure_string_callback(HDC hdc
,
5529 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5530 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5531 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5532 INT underlined_index_count
, void *user_data
)
5534 struct measure_string_args
*args
= user_data
;
5535 REAL new_width
, new_height
;
5537 new_width
= bounds
->Width
/ args
->rel_width
;
5538 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
5540 if (new_width
> args
->bounds
->Width
)
5541 args
->bounds
->Width
= new_width
;
5543 if (new_height
> args
->bounds
->Height
)
5544 args
->bounds
->Height
= new_height
;
5546 if (args
->codepointsfitted
)
5547 *args
->codepointsfitted
= index
+ length
;
5549 if (args
->linesfilled
)
5550 (*args
->linesfilled
)++;
5555 /* Find the smallest rectangle that bounds the text when it is printed in rect
5556 * according to the format options listed in format. If rect has 0 width and
5557 * height, then just find the smallest rectangle that bounds the text when it's
5558 * printed at location (rect->X, rect-Y). */
5559 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
5560 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5561 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
5562 INT
*codepointsfitted
, INT
*linesfilled
)
5564 HFONT oldfont
, gdifont
;
5565 struct measure_string_args args
;
5566 HDC temp_hdc
=NULL
, hdc
;
5572 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
5573 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
5574 bounds
, codepointsfitted
, linesfilled
);
5576 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
5577 return InvalidParameter
;
5581 hdc
= temp_hdc
= CreateCompatibleDC(0);
5582 if (!temp_hdc
) return OutOfMemory
;
5585 hdc
= graphics
->hdc
;
5587 if(linesfilled
) *linesfilled
= 0;
5588 if(codepointsfitted
) *codepointsfitted
= 0;
5591 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5599 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5600 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5601 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5602 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5603 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5605 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5606 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
, graphics
->printer_display
);
5608 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
5609 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
5610 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
5611 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
5612 if (scaled_rect
.Width
>= 0.5)
5614 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5615 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5618 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5619 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5621 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
, NULL
);
5622 oldfont
= SelectObject(hdc
, gdifont
);
5624 bounds
->X
= rect
->X
;
5625 bounds
->Y
= rect
->Y
;
5626 bounds
->Width
= 0.0;
5627 bounds
->Height
= 0.0;
5629 args
.bounds
= bounds
;
5630 args
.codepointsfitted
= &glyphs
;
5631 args
.linesfilled
= &lines
;
5634 gdi_transform_acquire(graphics
);
5636 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5637 measure_string_callback
, &args
);
5639 gdi_transform_release(graphics
);
5641 if (linesfilled
) *linesfilled
= lines
;
5642 if (codepointsfitted
) *codepointsfitted
= glyphs
;
5645 bounds
->Width
+= margin_x
* 2.0;
5647 SelectObject(hdc
, oldfont
);
5648 DeleteObject(gdifont
);
5656 struct draw_string_args
{
5657 GpGraphics
*graphics
;
5658 GDIPCONST GpBrush
*brush
;
5659 REAL x
, y
, rel_width
, rel_height
, ascent
;
5662 static GpStatus
draw_string_callback(HDC hdc
,
5663 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5664 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5665 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5666 INT underlined_index_count
, void *user_data
)
5668 struct draw_string_args
*args
= user_data
;
5672 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5673 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5675 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
5676 args
->brush
, &position
,
5677 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5679 if (stat
== Ok
&& underlined_index_count
)
5681 OUTLINETEXTMETRICW otm
;
5682 REAL underline_y
, underline_height
;
5685 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5687 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5688 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5690 for (i
=0; i
<underlined_index_count
; i
++)
5692 REAL start_x
, end_x
;
5694 INT ofs
= underlined_indexes
[i
] - index
;
5696 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5697 start_x
= text_size
.cx
/ args
->rel_width
;
5699 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5700 end_x
= text_size
.cx
/ args
->rel_width
;
5702 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5709 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5710 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5711 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5715 GpPointF pt
[3], rectcpy
[4];
5717 REAL rel_width
, rel_height
, margin_x
;
5718 INT save_state
, format_flags
= 0;
5720 struct draw_string_args args
;
5722 HDC hdc
, temp_hdc
=NULL
;
5723 TEXTMETRICW textmetric
;
5725 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5726 length
, font
, debugstr_rectf(rect
), format
, brush
);
5728 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5729 return InvalidParameter
;
5733 hdc
= graphics
->hdc
;
5737 hdc
= temp_hdc
= CreateCompatibleDC(0);
5741 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5743 format_flags
= format
->attr
;
5745 /* Should be no need to explicitly test for StringAlignmentNear as
5746 * that is default behavior if no alignment is passed. */
5747 if(format
->line_align
!= StringAlignmentNear
){
5748 RectF bounds
, in_rect
= *rect
;
5749 in_rect
.Height
= 0.0; /* avoid height clipping */
5750 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5752 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5754 if(format
->line_align
== StringAlignmentCenter
)
5755 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5756 else if(format
->line_align
== StringAlignmentFar
)
5757 offsety
= (rect
->Height
- bounds
.Height
);
5759 TRACE("line align %d, offsety %f\n", format
->line_align
, offsety
);
5762 save_state
= SaveDC(hdc
);
5770 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5771 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5772 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5773 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5774 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5776 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5777 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5778 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5779 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5780 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, rectcpy
, 4);
5781 round_points(corners
, rectcpy
, 4);
5783 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5784 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
, graphics
->printer_display
);
5786 scaled_rect
.X
= margin_x
* rel_width
;
5787 scaled_rect
.Y
= 0.0;
5788 scaled_rect
.Width
= rel_width
* rect
->Width
;
5789 scaled_rect
.Height
= rel_height
* rect
->Height
;
5790 if (scaled_rect
.Width
>= 0.5)
5792 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5793 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5796 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5797 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5799 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5800 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5801 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5803 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5804 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5805 SelectClipRgn(hdc
, rgn
);
5808 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
, NULL
);
5809 SelectObject(hdc
, gdifont
);
5811 args
.graphics
= graphics
;
5815 args
.y
= rect
->Y
+ offsety
;
5817 args
.rel_width
= rel_width
;
5818 args
.rel_height
= rel_height
;
5820 gdi_transform_acquire(graphics
);
5822 GetTextMetricsW(hdc
, &textmetric
);
5823 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5825 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5826 draw_string_callback
, &args
);
5828 gdi_transform_release(graphics
);
5831 DeleteObject(gdifont
);
5833 RestoreDC(hdc
, save_state
);
5840 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5842 TRACE("(%p)\n", graphics
);
5845 return InvalidParameter
;
5850 return GdipSetInfinite(graphics
->clip
);
5853 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5857 TRACE("(%p)\n", graphics
);
5860 return InvalidParameter
;
5865 if (is_metafile_graphics(graphics
))
5867 stat
= METAFILE_ResetWorldTransform((GpMetafile
*)graphics
->image
);
5873 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5876 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5877 GpMatrixOrder order
)
5881 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5884 return InvalidParameter
;
5889 if (is_metafile_graphics(graphics
))
5891 stat
= METAFILE_RotateWorldTransform((GpMetafile
*)graphics
->image
, angle
, order
);
5897 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5900 static GpStatus
begin_container(GpGraphics
*graphics
,
5901 GraphicsContainerType type
, GraphicsContainer
*state
)
5903 GraphicsContainerItem
*container
;
5906 if(!graphics
|| !state
)
5907 return InvalidParameter
;
5909 sts
= init_container(&container
, graphics
, type
);
5913 list_add_head(&graphics
->containers
, &container
->entry
);
5914 *state
= graphics
->contid
= container
->contid
;
5916 if (is_metafile_graphics(graphics
)) {
5917 if (type
== BEGIN_CONTAINER
)
5918 METAFILE_BeginContainerNoParams((GpMetafile
*)graphics
->image
, container
->contid
);
5920 METAFILE_SaveGraphics((GpMetafile
*)graphics
->image
, container
->contid
);
5926 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5928 TRACE("(%p, %p)\n", graphics
, state
);
5929 return begin_container(graphics
, SAVE_GRAPHICS
, state
);
5932 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5933 GraphicsContainer
*state
)
5935 TRACE("(%p, %p)\n", graphics
, state
);
5936 return begin_container(graphics
, BEGIN_CONTAINER
, state
);
5939 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5941 GraphicsContainerItem
*container
;
5944 GpRectF scaled_srcrect
;
5945 REAL scale_x
, scale_y
;
5947 TRACE("(%p, %s, %s, %d, %p)\n", graphics
, debugstr_rectf(dstrect
), debugstr_rectf(srcrect
), unit
, state
);
5949 if(!graphics
|| !dstrect
|| !srcrect
|| unit
< UnitPixel
|| unit
> UnitMillimeter
|| !state
)
5950 return InvalidParameter
;
5952 stat
= init_container(&container
, graphics
, BEGIN_CONTAINER
);
5956 list_add_head(&graphics
->containers
, &container
->entry
);
5957 *state
= graphics
->contid
= container
->contid
;
5959 scale_x
= units_to_pixels(1.0, unit
, graphics
->xres
, graphics
->printer_display
);
5960 scale_y
= units_to_pixels(1.0, unit
, graphics
->yres
, graphics
->printer_display
);
5962 scaled_srcrect
.X
= scale_x
* srcrect
->X
;
5963 scaled_srcrect
.Y
= scale_y
* srcrect
->Y
;
5964 scaled_srcrect
.Width
= scale_x
* srcrect
->Width
;
5965 scaled_srcrect
.Height
= scale_y
* srcrect
->Height
;
5967 transform
.matrix
[0] = dstrect
->Width
/ scaled_srcrect
.Width
;
5968 transform
.matrix
[1] = 0.0;
5969 transform
.matrix
[2] = 0.0;
5970 transform
.matrix
[3] = dstrect
->Height
/ scaled_srcrect
.Height
;
5971 transform
.matrix
[4] = dstrect
->X
- scaled_srcrect
.X
;
5972 transform
.matrix
[5] = dstrect
->Y
- scaled_srcrect
.Y
;
5974 GdipMultiplyMatrix(&graphics
->worldtrans
, &transform
, MatrixOrderPrepend
);
5976 if (is_metafile_graphics(graphics
))
5977 METAFILE_BeginContainer((GpMetafile
*)graphics
->image
, dstrect
, srcrect
, unit
, container
->contid
);
5982 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5984 GpRectF dstrectf
, srcrectf
;
5986 TRACE("(%p, %p, %p, %d, %p)\n", graphics
, dstrect
, srcrect
, unit
, state
);
5988 if (!dstrect
|| !srcrect
)
5989 return InvalidParameter
;
5991 dstrectf
.X
= dstrect
->X
;
5992 dstrectf
.Y
= dstrect
->Y
;
5993 dstrectf
.Width
= dstrect
->Width
;
5994 dstrectf
.Height
= dstrect
->Height
;
5996 srcrectf
.X
= srcrect
->X
;
5997 srcrectf
.Y
= srcrect
->Y
;
5998 srcrectf
.Width
= srcrect
->Width
;
5999 srcrectf
.Height
= srcrect
->Height
;
6001 return GdipBeginContainer(graphics
, &dstrectf
, &srcrectf
, unit
, state
);
6004 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
6006 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
6007 return NotImplemented
;
6010 static GpStatus
end_container(GpGraphics
*graphics
, GraphicsContainerType type
,
6011 GraphicsContainer state
)
6014 GraphicsContainerItem
*container
, *container2
;
6017 return InvalidParameter
;
6019 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
6020 if(container
->contid
== state
&& container
->type
== type
)
6024 /* did not find a matching container */
6025 if(&container
->entry
== &graphics
->containers
)
6028 sts
= restore_container(graphics
, container
);
6032 /* remove all of the containers on top of the found container */
6033 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
6034 if(container
->contid
== state
)
6036 list_remove(&container
->entry
);
6037 delete_container(container
);
6040 list_remove(&container
->entry
);
6041 delete_container(container
);
6043 if (is_metafile_graphics(graphics
)) {
6044 if (type
== BEGIN_CONTAINER
)
6045 METAFILE_EndContainer((GpMetafile
*)graphics
->image
, state
);
6047 METAFILE_RestoreGraphics((GpMetafile
*)graphics
->image
, state
);
6053 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
6055 TRACE("(%p, %x)\n", graphics
, state
);
6056 return end_container(graphics
, BEGIN_CONTAINER
, state
);
6059 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
6061 TRACE("(%p, %x)\n", graphics
, state
);
6062 return end_container(graphics
, SAVE_GRAPHICS
, state
);
6065 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
6066 REAL sy
, GpMatrixOrder order
)
6070 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
6073 return InvalidParameter
;
6078 if (is_metafile_graphics(graphics
)) {
6079 stat
= METAFILE_ScaleWorldTransform((GpMetafile
*)graphics
->image
, sx
, sy
, order
);
6085 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
6088 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
6091 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
6093 if(!graphics
|| !srcgraphics
)
6094 return InvalidParameter
;
6096 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
6099 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
6100 CompositingMode mode
)
6102 TRACE("(%p, %d)\n", graphics
, mode
);
6105 return InvalidParameter
;
6110 if(graphics
->compmode
== mode
)
6113 if (is_metafile_graphics(graphics
))
6117 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6118 EmfPlusRecordTypeSetCompositingMode
, mode
);
6123 graphics
->compmode
= mode
;
6128 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
6129 CompositingQuality quality
)
6131 TRACE("(%p, %d)\n", graphics
, quality
);
6134 return InvalidParameter
;
6139 if(graphics
->compqual
== quality
)
6142 if (is_metafile_graphics(graphics
))
6146 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6147 EmfPlusRecordTypeSetCompositingQuality
, quality
);
6152 graphics
->compqual
= quality
;
6157 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
6158 InterpolationMode mode
)
6160 TRACE("(%p, %d)\n", graphics
, mode
);
6162 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
6163 return InvalidParameter
;
6168 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
6169 mode
= InterpolationModeBilinear
;
6171 if (mode
== InterpolationModeHighQuality
)
6172 mode
= InterpolationModeHighQualityBicubic
;
6174 if (mode
== graphics
->interpolation
)
6177 if (is_metafile_graphics(graphics
))
6181 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6182 EmfPlusRecordTypeSetInterpolationMode
, mode
);
6187 graphics
->interpolation
= mode
;
6192 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
6196 TRACE("(%p, %.2f)\n", graphics
, scale
);
6198 if(!graphics
|| (scale
<= 0.0))
6199 return InvalidParameter
;
6204 if (is_metafile_graphics(graphics
))
6206 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
6211 graphics
->scale
= scale
;
6216 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
6220 TRACE("(%p, %d)\n", graphics
, unit
);
6223 return InvalidParameter
;
6228 if(unit
== UnitWorld
)
6229 return InvalidParameter
;
6231 if (is_metafile_graphics(graphics
))
6233 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
6238 graphics
->unit
= unit
;
6243 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
6246 TRACE("(%p, %d)\n", graphics
, mode
);
6249 return InvalidParameter
;
6254 if(graphics
->pixeloffset
== mode
)
6257 if (is_metafile_graphics(graphics
))
6261 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6262 EmfPlusRecordTypeSetPixelOffsetMode
, mode
);
6267 graphics
->pixeloffset
= mode
;
6272 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
6274 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
6277 return InvalidParameter
;
6279 graphics
->origin_x
= x
;
6280 graphics
->origin_y
= y
;
6285 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
6287 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
6289 if (!graphics
|| !x
|| !y
)
6290 return InvalidParameter
;
6292 *x
= graphics
->origin_x
;
6293 *y
= graphics
->origin_y
;
6298 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
6300 TRACE("(%p, %d)\n", graphics
, mode
);
6303 return InvalidParameter
;
6308 if(graphics
->smoothing
== mode
)
6311 if (is_metafile_graphics(graphics
))
6314 BOOL antialias
= (mode
!= SmoothingModeDefault
&&
6315 mode
!= SmoothingModeNone
&& mode
!= SmoothingModeHighSpeed
);
6317 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6318 EmfPlusRecordTypeSetAntiAliasMode
, (mode
<< 1) + antialias
);
6323 graphics
->smoothing
= mode
;
6328 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
6330 TRACE("(%p, %d)\n", graphics
, contrast
);
6333 return InvalidParameter
;
6335 graphics
->textcontrast
= contrast
;
6340 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
6341 TextRenderingHint hint
)
6343 TRACE("(%p, %d)\n", graphics
, hint
);
6345 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
6346 return InvalidParameter
;
6351 if(graphics
->texthint
== hint
)
6354 if (is_metafile_graphics(graphics
)) {
6357 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6358 EmfPlusRecordTypeSetTextRenderingHint
, hint
);
6363 graphics
->texthint
= hint
;
6368 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
6372 TRACE("(%p, %p)\n", graphics
, matrix
);
6374 if(!graphics
|| !matrix
)
6375 return InvalidParameter
;
6380 TRACE("%f,%f,%f,%f,%f,%f\n",
6381 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
6382 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
6384 if (is_metafile_graphics(graphics
)) {
6385 stat
= METAFILE_SetWorldTransform((GpMetafile
*)graphics
->image
, matrix
);
6391 graphics
->worldtrans
= *matrix
;
6396 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
6397 REAL dy
, GpMatrixOrder order
)
6401 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
6404 return InvalidParameter
;
6409 if (is_metafile_graphics(graphics
)) {
6410 stat
= METAFILE_TranslateWorldTransform((GpMetafile
*)graphics
->image
, dx
, dy
, order
);
6416 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
6419 /*****************************************************************************
6420 * GdipSetClipHrgn [GDIPLUS.@]
6422 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
6428 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
6431 return InvalidParameter
;
6436 /* hrgn is in gdi32 device units */
6437 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
6441 status
= get_graphics_transform(graphics
, CoordinateSpaceDevice
, WineCoordinateSpaceGdiDevice
, &transform
);
6444 status
= GdipTransformRegion(region
, &transform
);
6447 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6449 GdipDeleteRegion(region
);
6454 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
6459 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
6462 return InvalidParameter
;
6467 status
= GdipClonePath(path
, &clip_path
);
6470 GpMatrix world_to_device
;
6472 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
6473 CoordinateSpaceWorld
, &world_to_device
);
6474 status
= GdipTransformPath(clip_path
, &world_to_device
);
6476 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
6478 GdipDeletePath(clip_path
);
6483 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
6484 REAL width
, REAL height
,
6491 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6494 return InvalidParameter
;
6499 if (is_metafile_graphics(graphics
))
6501 status
= METAFILE_SetClipRect((GpMetafile
*)graphics
->image
, x
, y
, width
, height
, mode
);
6509 rect
.Height
= height
;
6510 status
= GdipCreateRegionRect(&rect
, ®ion
);
6513 GpMatrix world_to_device
;
6516 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6517 status
= GdipIsMatrixIdentity(&world_to_device
, &identity
);
6518 if (status
== Ok
&& !identity
)
6519 status
= GdipTransformRegion(region
, &world_to_device
);
6521 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6523 GdipDeleteRegion(region
);
6528 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
6529 INT width
, INT height
,
6532 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6535 return InvalidParameter
;
6540 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
6543 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
6549 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
6551 if(!graphics
|| !region
)
6552 return InvalidParameter
;
6557 if (is_metafile_graphics(graphics
))
6559 status
= METAFILE_SetClipRegion((GpMetafile
*)graphics
->image
, region
, mode
);
6564 status
= GdipCloneRegion(region
, &clip
);
6567 GpMatrix world_to_device
;
6570 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6571 status
= GdipIsMatrixIdentity(&world_to_device
, &identity
);
6572 if (status
== Ok
&& !identity
)
6573 status
= GdipTransformRegion(clip
, &world_to_device
);
6575 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
6577 GdipDeleteRegion(clip
);
6582 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
6588 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
6590 if(!graphics
|| !pen
|| count
<=0)
6591 return InvalidParameter
;
6596 status
= GdipCreatePath(FillModeAlternate
, &path
);
6597 if (status
!= Ok
) return status
;
6599 status
= GdipAddPathPolygon(path
, points
, count
);
6601 status
= GdipDrawPath(graphics
, pen
, path
);
6603 GdipDeletePath(path
);
6608 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
6615 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
6617 if(count
<=0) return InvalidParameter
;
6618 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6619 if (!ptf
) return OutOfMemory
;
6621 for(i
= 0;i
< count
; i
++){
6622 ptf
[i
].X
= (REAL
)points
[i
].X
;
6623 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
6626 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
6632 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
6634 TRACE("(%p, %p)\n", graphics
, dpi
);
6636 if(!graphics
|| !dpi
)
6637 return InvalidParameter
;
6642 *dpi
= graphics
->xres
;
6646 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
6648 TRACE("(%p, %p)\n", graphics
, dpi
);
6650 if(!graphics
|| !dpi
)
6651 return InvalidParameter
;
6656 *dpi
= graphics
->yres
;
6660 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
6661 GpMatrixOrder order
)
6666 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
6668 if(!graphics
|| !matrix
)
6669 return InvalidParameter
;
6674 if (is_metafile_graphics(graphics
))
6676 ret
= METAFILE_MultiplyWorldTransform((GpMetafile
*)graphics
->image
, matrix
, order
);
6682 m
= graphics
->worldtrans
;
6684 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
6686 graphics
->worldtrans
= m
;
6691 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
6692 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
6694 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
6698 TRACE("(%p, %p)\n", graphics
, hdc
);
6700 if(!graphics
|| !hdc
)
6701 return InvalidParameter
;
6706 if (is_metafile_graphics(graphics
))
6708 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
6710 else if (!graphics
->hdc
||
6711 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
6713 /* Create a fake HDC and fill it with a constant color. */
6717 BITMAPINFOHEADER bmih
;
6720 stat
= get_graphics_bounds(graphics
, &bounds
);
6724 graphics
->temp_hbitmap_width
= bounds
.Width
;
6725 graphics
->temp_hbitmap_height
= bounds
.Height
;
6727 bmih
.biSize
= sizeof(bmih
);
6728 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
6729 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
6731 bmih
.biBitCount
= 32;
6732 bmih
.biCompression
= BI_RGB
;
6733 bmih
.biSizeImage
= 0;
6734 bmih
.biXPelsPerMeter
= 0;
6735 bmih
.biYPelsPerMeter
= 0;
6737 bmih
.biClrImportant
= 0;
6739 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
6740 (void**)&graphics
->temp_bits
, NULL
, 0);
6742 return GenericError
;
6744 if (!graphics
->temp_hdc
)
6746 temp_hdc
= CreateCompatibleDC(0);
6750 temp_hdc
= graphics
->temp_hdc
;
6755 DeleteObject(hbitmap
);
6756 return GenericError
;
6759 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6760 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
6762 SelectObject(temp_hdc
, hbitmap
);
6764 graphics
->temp_hbitmap
= hbitmap
;
6765 *hdc
= graphics
->temp_hdc
= temp_hdc
;
6769 *hdc
= graphics
->hdc
;
6773 graphics
->busy
= TRUE
;
6778 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
6782 TRACE("(%p, %p)\n", graphics
, hdc
);
6784 if(!graphics
|| !hdc
|| !graphics
->busy
)
6785 return InvalidParameter
;
6787 if (is_metafile_graphics(graphics
))
6789 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
6791 else if (graphics
->temp_hdc
== hdc
)
6796 /* Find the pixels that have changed, and mark them as opaque. */
6797 pos
= (DWORD
*)graphics
->temp_bits
;
6798 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6800 if (*pos
!= DC_BACKGROUND_KEY
)
6807 /* Write the changed pixels to the real target. */
6808 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
6809 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
6810 graphics
->temp_hbitmap_width
* 4, PixelFormat32bppARGB
);
6813 DeleteObject(graphics
->temp_hbitmap
);
6814 graphics
->temp_hbitmap
= NULL
;
6816 else if (hdc
!= graphics
->hdc
)
6818 stat
= InvalidParameter
;
6822 graphics
->busy
= FALSE
;
6827 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
6831 GpMatrix device_to_world
;
6833 TRACE("(%p, %p)\n", graphics
, region
);
6835 if(!graphics
|| !region
)
6836 return InvalidParameter
;
6841 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
6844 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
6845 status
= GdipTransformRegion(clip
, &device_to_world
);
6848 GdipDeleteRegion(clip
);
6852 /* free everything except root node and header */
6853 delete_element(®ion
->node
);
6854 memcpy(region
, clip
, sizeof(GpRegion
));
6860 GpStatus
gdi_transform_acquire(GpGraphics
*graphics
)
6862 if (graphics
->gdi_transform_acquire_count
== 0 && graphics
->hdc
)
6864 graphics
->gdi_transform_save
= SaveDC(graphics
->hdc
);
6865 ModifyWorldTransform(graphics
->hdc
, NULL
, MWT_IDENTITY
);
6866 SetGraphicsMode(graphics
->hdc
, GM_COMPATIBLE
);
6867 SetMapMode(graphics
->hdc
, MM_TEXT
);
6868 SetWindowOrgEx(graphics
->hdc
, 0, 0, NULL
);
6869 SetViewportOrgEx(graphics
->hdc
, 0, 0, NULL
);
6871 graphics
->gdi_transform_acquire_count
++;
6875 GpStatus
gdi_transform_release(GpGraphics
*graphics
)
6877 if (graphics
->gdi_transform_acquire_count
<= 0)
6879 ERR("called without matching gdi_transform_acquire\n");
6880 return GenericError
;
6882 if (graphics
->gdi_transform_acquire_count
== 1 && graphics
->hdc
)
6884 RestoreDC(graphics
->hdc
, graphics
->gdi_transform_save
);
6886 graphics
->gdi_transform_acquire_count
--;
6890 GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6891 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
6894 REAL scale_x
, scale_y
;
6896 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
6898 if (dst_space
!= src_space
)
6900 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
, graphics
->printer_display
);
6901 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
, graphics
->printer_display
);
6903 if(graphics
->unit
!= UnitDisplay
)
6905 scale_x
*= graphics
->scale
;
6906 scale_y
*= graphics
->scale
;
6909 if (dst_space
< src_space
)
6911 /* transform towards world space */
6912 switch ((int)src_space
)
6914 case WineCoordinateSpaceGdiDevice
:
6917 gdixform
= graphics
->gdi_transform
;
6918 stat
= GdipInvertMatrix(&gdixform
);
6921 GdipMultiplyMatrix(matrix
, &gdixform
, MatrixOrderAppend
);
6922 if (dst_space
== CoordinateSpaceDevice
)
6924 /* else fall-through */
6926 case CoordinateSpaceDevice
:
6927 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
6928 if (dst_space
== CoordinateSpacePage
)
6930 /* else fall-through */
6931 case CoordinateSpacePage
:
6933 GpMatrix inverted_transform
= graphics
->worldtrans
;
6934 stat
= GdipInvertMatrix(&inverted_transform
);
6936 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
6943 /* transform towards device space */
6944 switch ((int)src_space
)
6946 case CoordinateSpaceWorld
:
6947 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
6948 if (dst_space
== CoordinateSpacePage
)
6950 /* else fall-through */
6951 case CoordinateSpacePage
:
6952 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
6953 if (dst_space
== CoordinateSpaceDevice
)
6955 /* else fall-through */
6956 case CoordinateSpaceDevice
:
6958 GdipMultiplyMatrix(matrix
, &graphics
->gdi_transform
, MatrixOrderAppend
);
6967 GpStatus
gdip_transform_points(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6968 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6973 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6974 if (stat
!= Ok
) return stat
;
6976 return GdipTransformMatrixPoints(&matrix
, points
, count
);
6979 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6980 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6982 if(!graphics
|| !points
|| count
<= 0 ||
6983 dst_space
< 0 || dst_space
> CoordinateSpaceDevice
||
6984 src_space
< 0 || src_space
> CoordinateSpaceDevice
)
6985 return InvalidParameter
;
6990 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6992 if (src_space
== dst_space
) return Ok
;
6994 return gdip_transform_points(graphics
, dst_space
, src_space
, points
, count
);
6997 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6998 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
7004 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
7007 return InvalidParameter
;
7009 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
7013 for(i
= 0; i
< count
; i
++){
7014 pointsF
[i
].X
= (REAL
)points
[i
].X
;
7015 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
7018 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
7021 for(i
= 0; i
< count
; i
++){
7022 points
[i
].X
= gdip_round(pointsF
[i
].X
);
7023 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
7030 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
7042 /*****************************************************************************
7043 * GdipTranslateClip [GDIPLUS.@]
7045 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
7047 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
7050 return InvalidParameter
;
7055 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
7058 /*****************************************************************************
7059 * GdipTranslateClipI [GDIPLUS.@]
7061 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
7063 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
7066 return InvalidParameter
;
7071 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
7075 /*****************************************************************************
7076 * GdipMeasureDriverString [GDIPLUS.@]
7078 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7079 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
7080 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
7082 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
7085 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
7087 TEXTMETRICW textmetric
;
7088 const WORD
*glyph_indices
;
7089 WORD
*dynamic_glyph_indices
=NULL
;
7090 REAL rel_width
, rel_height
, ascent
, descent
;
7093 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
7095 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
7096 return InvalidParameter
;
7099 length
= lstrlenW(text
);
7103 boundingBox
->X
= 0.0;
7104 boundingBox
->Y
= 0.0;
7105 boundingBox
->Width
= 0.0;
7106 boundingBox
->Height
= 0.0;
7109 if (flags
& unsupported_flags
)
7110 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
7112 get_font_hfont(graphics
, font
, NULL
, &hfont
, NULL
, matrix
);
7114 hdc
= CreateCompatibleDC(0);
7115 SelectObject(hdc
, hfont
);
7117 GetTextMetricsW(hdc
, &textmetric
);
7127 GpMatrix xform
= *matrix
;
7128 GdipTransformMatrixPoints(&xform
, pt
, 3);
7130 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
7131 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
7132 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
7133 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
7134 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
7136 if (flags
& DriverStringOptionsCmapLookup
)
7138 glyph_indices
= dynamic_glyph_indices
= heap_alloc_zero(sizeof(WORD
) * length
);
7142 DeleteObject(hfont
);
7146 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
7149 glyph_indices
= text
;
7151 min_x
= max_x
= x
= positions
[0].X
;
7152 min_y
= max_y
= y
= positions
[0].Y
;
7154 ascent
= textmetric
.tmAscent
/ rel_height
;
7155 descent
= textmetric
.tmDescent
/ rel_height
;
7157 for (i
=0; i
<length
; i
++)
7162 if (!(flags
& DriverStringOptionsRealizedAdvance
))
7168 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
7169 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
7171 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
7172 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
7173 if (min_x
> x
) min_x
= x
;
7175 x
+= char_width
/ rel_width
;
7177 if (max_x
< x
) max_x
= x
;
7180 heap_free(dynamic_glyph_indices
);
7182 DeleteObject(hfont
);
7184 boundingBox
->X
= min_x
;
7185 boundingBox
->Y
= min_y
;
7186 boundingBox
->Width
= max_x
- min_x
;
7187 boundingBox
->Height
= max_y
- min_y
;
7192 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7193 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7194 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7195 INT flags
, GDIPCONST GpMatrix
*matrix
)
7198 GpPointF pt
, *real_positions
=NULL
;
7199 INT
*eto_positions
=NULL
;
7206 if (!(flags
& DriverStringOptionsCmapLookup
))
7207 eto_flags
|= ETO_GLYPH_INDEX
;
7209 if (!(flags
& DriverStringOptionsRealizedAdvance
) && length
> 1)
7211 real_positions
= heap_alloc(sizeof(*real_positions
) * length
);
7212 eto_positions
= heap_alloc(sizeof(*eto_positions
) * 2 * (length
- 1));
7213 if (!real_positions
|| !eto_positions
)
7215 heap_free(real_positions
);
7216 heap_free(eto_positions
);
7221 save_state
= SaveDC(graphics
->hdc
);
7222 SetBkMode(graphics
->hdc
, TRANSPARENT
);
7223 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
7225 status
= get_clip_hrgn(graphics
, &hrgn
);
7229 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
7234 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, &pt
, 1);
7236 get_font_hfont(graphics
, font
, format
, &hfont
, &lfw
, matrix
);
7238 if (!(flags
& DriverStringOptionsRealizedAdvance
) && length
> 1)
7243 eto_flags
|= ETO_PDY
;
7245 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
7247 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, real_positions
, length
);
7249 GdipSetMatrixElements(&rotation
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
7250 GdipRotateMatrix(&rotation
, lfw
.lfEscapement
/ 10.0, MatrixOrderAppend
);
7251 GdipTransformMatrixPoints(&rotation
, real_positions
, length
);
7253 for (i
= 0; i
< (length
- 1); i
++)
7255 eto_positions
[i
*2] = gdip_round(real_positions
[i
+1].X
) - gdip_round(real_positions
[i
].X
);
7256 eto_positions
[i
*2+1] = gdip_round(real_positions
[i
].Y
) - gdip_round(real_positions
[i
+1].Y
);
7260 SelectObject(graphics
->hdc
, hfont
);
7262 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
7264 gdi_transform_acquire(graphics
);
7266 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, eto_positions
);
7268 gdi_transform_release(graphics
);
7270 RestoreDC(graphics
->hdc
, save_state
);
7272 DeleteObject(hfont
);
7274 heap_free(real_positions
);
7275 heap_free(eto_positions
);
7280 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7281 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7282 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7283 INT flags
, GDIPCONST GpMatrix
*matrix
)
7285 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
7287 PointF
*real_positions
, real_position
;
7291 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
7292 DWORD max_glyphsize
=0;
7293 GLYPHMETRICS glyphmetrics
;
7294 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
7297 int text_mask_stride
;
7299 int pixel_data_stride
;
7301 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
7306 if (!(flags
& DriverStringOptionsCmapLookup
))
7307 ggo_flags
|= GGO_GLYPH_INDEX
;
7309 if (flags
& unsupported_flags
)
7310 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
7312 pti
= heap_alloc_zero(sizeof(POINT
) * length
);
7316 if (flags
& DriverStringOptionsRealizedAdvance
)
7318 real_position
= positions
[0];
7320 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, &real_position
, 1);
7321 round_points(pti
, &real_position
, 1);
7325 real_positions
= heap_alloc_zero(sizeof(PointF
) * length
);
7326 if (!real_positions
)
7332 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
7334 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, real_positions
, length
);
7335 round_points(pti
, real_positions
, length
);
7337 heap_free(real_positions
);
7340 get_font_hfont(graphics
, font
, format
, &hfont
, NULL
, matrix
);
7342 hdc
= CreateCompatibleDC(0);
7343 SelectObject(hdc
, hfont
);
7345 /* Get the boundaries of the text to be drawn */
7346 for (i
=0; i
<length
; i
++)
7349 int left
, top
, right
, bottom
;
7351 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
7352 &glyphmetrics
, 0, NULL
, &identity
);
7354 if (glyphsize
== GDI_ERROR
)
7356 ERR("GetGlyphOutlineW failed\n");
7359 DeleteObject(hfont
);
7360 return GenericError
;
7363 if (glyphsize
> max_glyphsize
)
7364 max_glyphsize
= glyphsize
;
7368 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7369 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7370 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
7371 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
7373 if (left
< min_x
) min_x
= left
;
7374 if (top
< min_y
) min_y
= top
;
7375 if (right
> max_x
) max_x
= right
;
7376 if (bottom
> max_y
) max_y
= bottom
;
7379 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
7381 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
7382 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
7386 if (max_glyphsize
== 0)
7388 /* Nothing to draw. */
7391 DeleteObject(hfont
);
7395 glyph_mask
= heap_alloc_zero(max_glyphsize
);
7396 text_mask
= heap_alloc_zero((max_x
- min_x
) * (max_y
- min_y
));
7397 text_mask_stride
= max_x
- min_x
;
7399 if (!(glyph_mask
&& text_mask
))
7401 heap_free(glyph_mask
);
7402 heap_free(text_mask
);
7405 DeleteObject(hfont
);
7409 /* Generate a mask for the text */
7410 for (i
=0; i
<length
; i
++)
7413 int left
, top
, stride
;
7415 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
7416 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
7418 if (ret
== GDI_ERROR
|| ret
== 0)
7419 continue; /* empty glyph */
7421 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7422 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7423 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
7425 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
7427 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
7428 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
7429 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
7431 *text_val
= min(64, *text_val
+ *glyph_val
);
7440 DeleteObject(hfont
);
7441 heap_free(glyph_mask
);
7443 /* get the brush data */
7444 pixel_data
= heap_alloc_zero(4 * (max_x
- min_x
) * (max_y
- min_y
));
7447 heap_free(text_mask
);
7451 pixel_area
.X
= min_x
;
7452 pixel_area
.Y
= min_y
;
7453 pixel_area
.Width
= max_x
- min_x
;
7454 pixel_area
.Height
= max_y
- min_y
;
7455 pixel_data_stride
= pixel_area
.Width
* 4;
7457 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
7460 heap_free(text_mask
);
7461 heap_free(pixel_data
);
7465 /* multiply the brush data by the mask */
7466 for (y
=0; y
<pixel_area
.Height
; y
++)
7468 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
7469 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
7470 for (x
=0; x
<pixel_area
.Width
; x
++)
7472 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
7478 heap_free(text_mask
);
7480 gdi_transform_acquire(graphics
);
7482 /* draw the result */
7483 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
7484 pixel_area
.Height
, pixel_data_stride
, PixelFormat32bppARGB
);
7486 gdi_transform_release(graphics
);
7488 heap_free(pixel_data
);
7493 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7494 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7495 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7496 INT flags
, GDIPCONST GpMatrix
*matrix
)
7498 GpStatus stat
= NotImplemented
;
7501 length
= lstrlenW(text
);
7503 if (is_metafile_graphics(graphics
))
7504 return METAFILE_DrawDriverString((GpMetafile
*)graphics
->image
, text
, length
, font
,
7505 format
, brush
, positions
, flags
, matrix
);
7507 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
7508 brush
->bt
== BrushTypeSolidColor
&&
7509 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
7510 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7511 brush
, positions
, flags
, matrix
);
7512 if (stat
== NotImplemented
)
7513 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7514 brush
, positions
, flags
, matrix
);
7518 /*****************************************************************************
7519 * GdipDrawDriverString [GDIPLUS.@]
7521 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7522 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
7523 GDIPCONST PointF
*positions
, INT flags
,
7524 GDIPCONST GpMatrix
*matrix
)
7526 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
7528 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
7529 return InvalidParameter
;
7531 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
7532 brush
, positions
, flags
, matrix
);
7535 /*****************************************************************************
7536 * GdipIsVisibleClipEmpty [GDIPLUS.@]
7538 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
7543 TRACE("(%p, %p)\n", graphics
, res
);
7545 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
7548 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
7551 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
7554 GdipDeleteRegion(rgn
);
7558 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
7562 TRACE("(%p) stub\n", graphics
);
7565 FIXME("not implemented\n");
7567 return NotImplemented
;
7570 GpStatus WINGDIPAPI
GdipGraphicsSetAbort(GpGraphics
*graphics
, GdiplusAbort
*pabort
)
7572 TRACE("(%p, %p)\n", graphics
, pabort
);
7575 return InvalidParameter
;
7578 FIXME("Abort callback is not supported.\n");