2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/unicode.h"
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
45 /* looks-right constants */
46 #define ANCHOR_WIDTH (2.0)
47 #define MAX_ITERS (50)
49 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
50 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
51 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
52 INT flags
, GDIPCONST GpMatrix
*matrix
);
54 /* Converts from gdiplus path point type to gdi path point type. */
55 static BYTE
convert_path_point_type(BYTE type
)
59 switch(type
& PathPointTypePathTypeMask
){
60 case PathPointTypeBezier
:
63 case PathPointTypeLine
:
66 case PathPointTypeStart
:
70 ERR("Bad point type\n");
74 if(type
& PathPointTypeCloseSubpath
)
75 ret
|= PT_CLOSEFIGURE
;
80 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
86 case BrushTypeSolidColor
:
88 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
92 case BrushTypeHatchFill
:
94 const GpHatch
*hatch
= (const GpHatch
*)brush
;
95 argb
= hatch
->forecol
;
98 case BrushTypeLinearGradient
:
100 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
101 argb
= line
->startcolor
;
104 case BrushTypePathGradient
:
106 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
107 argb
= grad
->centercolor
;
111 FIXME("unhandled brush type %d\n", brush
->bt
);
115 return ARGB2COLORREF(argb
);
118 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
121 BITMAPINFOHEADER bmih
;
125 bmih
.biSize
= sizeof(bmih
);
129 bmih
.biBitCount
= 32;
130 bmih
.biCompression
= BI_RGB
;
131 bmih
.biSizeImage
= 0;
133 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
136 const char *hatch_data
;
138 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
140 for (y
= 0; y
< 8; y
++)
142 for (x
= 0; x
< 8; x
++)
144 if (hatch_data
[y
] & (0x80 >> x
))
145 bits
[y
* 8 + x
] = hatch
->forecol
;
147 bits
[y
* 8 + x
] = hatch
->backcol
;
153 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
155 for (y
= 0; y
< 64; y
++)
156 bits
[y
] = hatch
->forecol
;
163 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
167 case BrushTypeSolidColor
:
169 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
170 lb
->lbStyle
= BS_SOLID
;
171 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
176 case BrushTypeHatchFill
:
178 const GpHatch
*hatch
= (const GpHatch
*)brush
;
181 hbmp
= create_hatch_bitmap(hatch
);
182 if (!hbmp
) return OutOfMemory
;
184 lb
->lbStyle
= BS_PATTERN
;
186 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
191 FIXME("unhandled brush type %d\n", brush
->bt
);
192 lb
->lbStyle
= BS_SOLID
;
193 lb
->lbColor
= get_gdi_brush_color(brush
);
199 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
204 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
210 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
215 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
217 gdibrush
= CreateBrushIndirect(&lb
);
218 free_gdi_logbrush(&lb
);
223 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
228 INT save_state
, i
, numdashes
;
230 DWORD dash_array
[MAX_DASHLEN
];
232 save_state
= SaveDC(graphics
->hdc
);
234 EndPath(graphics
->hdc
);
236 if(pen
->unit
== UnitPixel
){
240 /* Get an estimate for the amount the pen width is affected by the world
241 * transform. (This is similar to what some of the wine drivers do.) */
246 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
247 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
248 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
250 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
251 width
*= graphics
->scale
;
257 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceDevice
, pt
, 2);
258 width
*= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
259 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
262 if(pen
->dash
== DashStyleCustom
){
263 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
265 TRACE("dashes are: ");
266 for(i
= 0; i
< numdashes
; i
++){
267 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
268 TRACE("%d, ", dash_array
[i
]);
270 TRACE("\n and the pen style is %x\n", pen
->style
);
272 create_gdi_logbrush(pen
->brush
, &lb
);
273 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
274 numdashes
, dash_array
);
275 free_gdi_logbrush(&lb
);
279 create_gdi_logbrush(pen
->brush
, &lb
);
280 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
281 free_gdi_logbrush(&lb
);
284 SelectObject(graphics
->hdc
, gdipen
);
289 static void restore_dc(GpGraphics
*graphics
, INT state
)
291 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
292 RestoreDC(graphics
->hdc
, state
);
295 static void round_points(POINT
*pti
, GpPointF
*ptf
, INT count
)
299 for(i
= 0; i
< count
; i
++){
300 pti
[i
].x
= gdip_round(ptf
[i
].X
);
301 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
305 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
306 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
308 if (GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
) == DT_RASPRINTER
&&
309 GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
311 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
313 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
314 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
320 bf
.BlendOp
= AC_SRC_OVER
;
322 bf
.SourceConstantAlpha
= 255;
323 bf
.AlphaFormat
= AC_SRC_ALPHA
;
325 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
326 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
330 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
336 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceDevice
, &transform
);
339 stat
= GdipCloneRegion(graphics
->clip
, &rgn
);
343 stat
= GdipTransformRegion(rgn
, &transform
);
346 stat
= GdipGetRegionHRgn(rgn
, NULL
, hrgn
);
348 GdipDeleteRegion(rgn
);
351 if (stat
== Ok
&& graphics
->gdi_clip
)
354 CombineRgn(*hrgn
, *hrgn
, graphics
->gdi_clip
, RGN_AND
);
357 *hrgn
= CreateRectRgn(0,0,0,0);
358 CombineRgn(*hrgn
, graphics
->gdi_clip
, graphics
->gdi_clip
, RGN_COPY
);
365 /* Draw ARGB data to the given graphics object */
366 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
367 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, const PixelFormat fmt
)
369 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
372 for (y
=0; y
<src_height
; y
++)
374 for (x
=0; x
<src_width
; x
++)
376 ARGB dst_color
, src_color
;
377 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
379 if (!(src_color
& 0xff000000))
382 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
383 if (fmt
& PixelFormatPAlpha
)
384 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over_fgpremult(dst_color
, src_color
));
386 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
393 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
394 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
398 BITMAPINFOHEADER bih
;
401 hdc
= CreateCompatibleDC(0);
403 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
404 bih
.biWidth
= src_width
;
405 bih
.biHeight
= -src_height
;
408 bih
.biCompression
= BI_RGB
;
410 bih
.biXPelsPerMeter
= 0;
411 bih
.biYPelsPerMeter
= 0;
413 bih
.biClrImportant
= 0;
415 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
416 (void**)&temp_bits
, NULL
, 0);
418 if ((GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
) == DT_RASPRINTER
&&
419 GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
) ||
420 fmt
& PixelFormatPAlpha
)
421 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
423 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
424 4 * src_width
, src
, src_stride
);
426 SelectObject(hdc
, hbitmap
);
427 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
428 hdc
, 0, 0, src_width
, src_height
);
430 DeleteObject(hbitmap
);
435 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
436 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
, PixelFormat fmt
)
440 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
446 HRGN hrgn
, visible_rgn
;
448 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
452 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
461 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
462 DeleteObject(visible_rgn
);
466 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
468 size
= GetRegionData(hrgn
, 0, NULL
);
470 rgndata
= heap_alloc_zero(size
);
477 GetRegionData(hrgn
, size
, rgndata
);
479 rects
= (RECT
*)rgndata
->Buffer
;
481 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
483 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
484 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
485 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
495 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
497 ERR("This should not be used for metafiles; fix caller\n");
498 return NotImplemented
;
505 stat
= get_clip_hrgn(graphics
, &hrgn
);
510 save
= SaveDC(graphics
->hdc
);
512 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
515 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
517 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
518 src_height
, src_stride
, fmt
);
520 RestoreDC(graphics
->hdc
, save
);
528 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
529 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
531 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
, fmt
);
534 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
536 INT start_a
, end_a
, final_a
;
539 pos
= gdip_round(position
* 0xff);
541 start_a
= ((start
>> 24) & 0xff) * (pos
^ 0xff);
542 end_a
= ((end
>> 24) & 0xff) * pos
;
544 final_a
= start_a
+ end_a
;
546 if (final_a
< 0xff) return 0;
548 return (final_a
/ 0xff) << 24 |
549 ((((start
>> 16) & 0xff) * start_a
+ (((end
>> 16) & 0xff) * end_a
)) / final_a
) << 16 |
550 ((((start
>> 8) & 0xff) * start_a
+ (((end
>> 8) & 0xff) * end_a
)) / final_a
) << 8 |
551 (((start
& 0xff) * start_a
+ ((end
& 0xff) * end_a
)) / final_a
);
554 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
558 /* clamp to between 0.0 and 1.0, using the wrap mode */
559 position
= (position
- brush
->rect
.X
) / brush
->rect
.Width
;
560 if (brush
->wrap
== WrapModeTile
)
562 position
= fmodf(position
, 1.0f
);
563 if (position
< 0.0f
) position
+= 1.0f
;
565 else /* WrapModeFlip* */
567 position
= fmodf(position
, 2.0f
);
568 if (position
< 0.0f
) position
+= 2.0f
;
569 if (position
> 1.0f
) position
= 2.0f
- position
;
572 if (brush
->blendcount
== 1)
577 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
580 /* locate the blend positions surrounding this position */
581 while (position
> brush
->blendpos
[i
])
584 /* interpolate between the blend positions */
585 left_blendpos
= brush
->blendpos
[i
-1];
586 left_blendfac
= brush
->blendfac
[i
-1];
587 right_blendpos
= brush
->blendpos
[i
];
588 right_blendfac
= brush
->blendfac
[i
];
589 range
= right_blendpos
- left_blendpos
;
590 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
591 right_blendfac
* (position
- left_blendpos
)) / range
;
594 if (brush
->pblendcount
== 0)
595 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
599 ARGB left_blendcolor
, right_blendcolor
;
600 REAL left_blendpos
, right_blendpos
;
602 /* locate the blend colors surrounding this position */
603 while (blendfac
> brush
->pblendpos
[i
])
606 /* interpolate between the blend colors */
607 left_blendpos
= brush
->pblendpos
[i
-1];
608 left_blendcolor
= brush
->pblendcolor
[i
-1];
609 right_blendpos
= brush
->pblendpos
[i
];
610 right_blendcolor
= brush
->pblendcolor
[i
];
611 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
612 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
616 static BOOL
round_color_matrix(const ColorMatrix
*matrix
, int values
[5][5])
618 /* Convert floating point color matrix to int[5][5], return TRUE if it's an identity */
619 BOOL identity
= TRUE
;
625 if (matrix
->m
[j
][i
] != (i
== j
? 1.0 : 0.0))
627 values
[j
][i
] = gdip_round(matrix
->m
[j
][i
] * 256.0);
633 static ARGB
transform_color(ARGB color
, int matrix
[5][5])
637 unsigned char a
, r
, g
, b
;
639 val
[0] = ((color
>> 16) & 0xff); /* red */
640 val
[1] = ((color
>> 8) & 0xff); /* green */
641 val
[2] = (color
& 0xff); /* blue */
642 val
[3] = ((color
>> 24) & 0xff); /* alpha */
643 val
[4] = 255; /* translation */
650 res
[i
] += matrix
[j
][i
] * val
[j
];
653 a
= min(max(res
[3] / 256, 0), 255);
654 r
= min(max(res
[0] / 256, 0), 255);
655 g
= min(max(res
[1] / 256, 0), 255);
656 b
= min(max(res
[2] / 256, 0), 255);
658 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
661 static BOOL
color_is_gray(ARGB color
)
663 unsigned char r
, g
, b
;
665 r
= (color
>> 16) & 0xff;
666 g
= (color
>> 8) & 0xff;
669 return (r
== g
) && (g
== b
);
672 /* returns preferred pixel format for the applied attributes */
673 PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
674 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
)
679 if ((attributes
->noop
[type
] == IMAGEATTR_NOOP_UNDEFINED
&&
680 attributes
->noop
[ColorAdjustTypeDefault
] == IMAGEATTR_NOOP_SET
) ||
681 (attributes
->noop
[type
] == IMAGEATTR_NOOP_SET
))
684 if (attributes
->colorkeys
[type
].enabled
||
685 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
687 const struct color_key
*key
;
688 BYTE min_blue
, min_green
, min_red
;
689 BYTE max_blue
, max_green
, max_red
;
691 if (!data
|| fmt
!= PixelFormat32bppARGB
)
692 return PixelFormat32bppARGB
;
694 if (attributes
->colorkeys
[type
].enabled
)
695 key
= &attributes
->colorkeys
[type
];
697 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
699 min_blue
= key
->low
&0xff;
700 min_green
= (key
->low
>>8)&0xff;
701 min_red
= (key
->low
>>16)&0xff;
703 max_blue
= key
->high
&0xff;
704 max_green
= (key
->high
>>8)&0xff;
705 max_red
= (key
->high
>>16)&0xff;
707 for (x
=0; x
<width
; x
++)
708 for (y
=0; y
<height
; y
++)
711 BYTE blue
, green
, red
;
712 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
713 blue
= *src_color
&0xff;
714 green
= (*src_color
>>8)&0xff;
715 red
= (*src_color
>>16)&0xff;
716 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
717 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
718 *src_color
= 0x00000000;
722 if (attributes
->colorremaptables
[type
].enabled
||
723 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
725 const struct color_remap_table
*table
;
727 if (!data
|| fmt
!= PixelFormat32bppARGB
)
728 return PixelFormat32bppARGB
;
730 if (attributes
->colorremaptables
[type
].enabled
)
731 table
= &attributes
->colorremaptables
[type
];
733 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
735 for (x
=0; x
<width
; x
++)
736 for (y
=0; y
<height
; y
++)
739 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
740 for (i
=0; i
<table
->mapsize
; i
++)
742 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
744 *src_color
= table
->colormap
[i
].newColor
.Argb
;
751 if (attributes
->colormatrices
[type
].enabled
||
752 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
754 const struct color_matrix
*colormatrices
;
755 int color_matrix
[5][5];
756 int gray_matrix
[5][5];
759 if (!data
|| fmt
!= PixelFormat32bppARGB
)
760 return PixelFormat32bppARGB
;
762 if (attributes
->colormatrices
[type
].enabled
)
763 colormatrices
= &attributes
->colormatrices
[type
];
765 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
767 identity
= round_color_matrix(&colormatrices
->colormatrix
, color_matrix
);
769 if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
770 identity
= (round_color_matrix(&colormatrices
->graymatrix
, gray_matrix
) && identity
);
774 for (x
=0; x
<width
; x
++)
776 for (y
=0; y
<height
; y
++)
779 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
781 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
782 !color_is_gray(*src_color
))
784 *src_color
= transform_color(*src_color
, color_matrix
);
786 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
788 *src_color
= transform_color(*src_color
, gray_matrix
);
795 if (attributes
->gamma_enabled
[type
] ||
796 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
800 if (!data
|| fmt
!= PixelFormat32bppARGB
)
801 return PixelFormat32bppARGB
;
803 if (attributes
->gamma_enabled
[type
])
804 gamma
= attributes
->gamma
[type
];
806 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
808 for (x
=0; x
<width
; x
++)
809 for (y
=0; y
<height
; y
++)
812 BYTE blue
, green
, red
;
813 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
815 blue
= *src_color
&0xff;
816 green
= (*src_color
>>8)&0xff;
817 red
= (*src_color
>>16)&0xff;
819 /* FIXME: We should probably use a table for this. */
820 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
821 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
822 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
824 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
831 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
832 * bitmap that contains all the pixels we may need to draw it. */
833 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
834 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
837 INT left
, top
, right
, bottom
;
839 switch (interpolation
)
841 case InterpolationModeHighQualityBilinear
:
842 case InterpolationModeHighQualityBicubic
:
843 /* FIXME: Include a greater range for the prefilter? */
844 case InterpolationModeBicubic
:
845 case InterpolationModeBilinear
:
846 left
= (INT
)(floorf(srcx
));
847 top
= (INT
)(floorf(srcy
));
848 right
= (INT
)(ceilf(srcx
+srcwidth
));
849 bottom
= (INT
)(ceilf(srcy
+srcheight
));
851 case InterpolationModeNearestNeighbor
:
853 left
= gdip_round(srcx
);
854 top
= gdip_round(srcy
);
855 right
= gdip_round(srcx
+srcwidth
);
856 bottom
= gdip_round(srcy
+srcheight
);
860 if (wrap
== WrapModeClamp
)
866 if (right
>= bitmap
->width
)
867 right
= bitmap
->width
-1;
868 if (bottom
>= bitmap
->height
)
869 bottom
= bitmap
->height
-1;
870 if (bottom
< top
|| right
< left
)
871 /* entirely outside image, just sample a pixel so we don't have to
872 * special-case this later */
873 left
= top
= right
= bottom
= 0;
877 /* In some cases we can make the rectangle smaller here, but the logic
878 * is hard to get right, and tiling suggests we're likely to use the
879 * entire source image. */
880 if (left
< 0 || right
>= bitmap
->width
)
883 right
= bitmap
->width
-1;
886 if (top
< 0 || bottom
>= bitmap
->height
)
889 bottom
= bitmap
->height
-1;
895 rect
->Width
= right
- left
+ 1;
896 rect
->Height
= bottom
- top
+ 1;
899 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
900 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
902 if (attributes
->wrap
== WrapModeClamp
)
904 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
905 return attributes
->outside_color
;
909 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
911 x
= width
*2 + x
% (width
* 2);
913 y
= height
*2 + y
% (height
* 2);
915 if (attributes
->wrap
& WrapModeTileFlipX
)
917 if ((x
/ width
) % 2 == 0)
920 x
= width
- 1 - x
% width
;
925 if (attributes
->wrap
& WrapModeTileFlipY
)
927 if ((y
/ height
) % 2 == 0)
930 y
= height
- 1 - y
% height
;
936 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
938 ERR("out of range pixel requested\n");
942 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
945 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
946 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
947 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
951 switch (interpolation
)
955 FIXME("Unimplemented interpolation %i\n", interpolation
);
957 case InterpolationModeBilinear
:
960 INT leftx
, rightx
, topy
, bottomy
;
961 ARGB topleft
, topright
, bottomleft
, bottomright
;
965 leftxf
= floorf(point
->X
);
967 rightx
= (INT
)ceilf(point
->X
);
968 topyf
= floorf(point
->Y
);
970 bottomy
= (INT
)ceilf(point
->Y
);
972 if (leftx
== rightx
&& topy
== bottomy
)
973 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
974 leftx
, topy
, attributes
);
976 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
977 leftx
, topy
, attributes
);
978 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
979 rightx
, topy
, attributes
);
980 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
981 leftx
, bottomy
, attributes
);
982 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
983 rightx
, bottomy
, attributes
);
985 x_offset
= point
->X
- leftxf
;
986 top
= blend_colors(topleft
, topright
, x_offset
);
987 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
989 return blend_colors(top
, bottom
, point
->Y
- topyf
);
991 case InterpolationModeNearestNeighbor
:
997 case PixelOffsetModeNone
:
998 case PixelOffsetModeHighSpeed
:
1002 case PixelOffsetModeHalf
:
1003 case PixelOffsetModeHighQuality
:
1007 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
1008 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
1014 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
1016 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
1019 /* is_fill is TRUE if filling regions, FALSE for drawing primitives */
1020 static BOOL
brush_can_fill_path(GpBrush
*brush
, BOOL is_fill
)
1024 case BrushTypeSolidColor
:
1030 /* cannot draw semi-transparent colors */
1031 return (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000;
1034 case BrushTypeHatchFill
:
1036 GpHatch
*hatch
= (GpHatch
*)brush
;
1037 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
1038 ((hatch
->backcol
& 0xff000000) == 0xff000000);
1040 case BrushTypeLinearGradient
:
1041 case BrushTypeTextureFill
:
1042 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
1048 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
1052 case BrushTypeSolidColor
:
1054 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1055 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1060 /* partially transparent fill */
1062 SelectClipPath(graphics
->hdc
, RGN_AND
);
1063 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1065 HDC hdc
= CreateCompatibleDC(NULL
);
1069 SelectObject(hdc
, bmp
);
1070 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1078 /* else fall through */
1082 HBRUSH gdibrush
, old_brush
;
1084 gdibrush
= create_gdi_brush(brush
);
1085 if (!gdibrush
) return;
1087 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1088 FillPath(graphics
->hdc
);
1089 SelectObject(graphics
->hdc
, old_brush
);
1090 DeleteObject(gdibrush
);
1096 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1100 case BrushTypeSolidColor
:
1101 case BrushTypeHatchFill
:
1102 case BrushTypeLinearGradient
:
1103 case BrushTypeTextureFill
:
1104 case BrushTypePathGradient
:
1111 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1112 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1116 case BrushTypeSolidColor
:
1119 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1120 for (x
=0; x
<fill_area
->Width
; x
++)
1121 for (y
=0; y
<fill_area
->Height
; y
++)
1122 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1125 case BrushTypeHatchFill
:
1128 GpHatch
*fill
= (GpHatch
*)brush
;
1129 const char *hatch_data
;
1131 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1132 return NotImplemented
;
1134 for (x
=0; x
<fill_area
->Width
; x
++)
1135 for (y
=0; y
<fill_area
->Height
; y
++)
1139 /* FIXME: Account for the rendering origin */
1140 hx
= (x
+ fill_area
->X
) % 8;
1141 hy
= (y
+ fill_area
->Y
) % 8;
1143 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1144 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1146 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1151 case BrushTypeLinearGradient
:
1153 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1154 GpPointF draw_points
[3];
1158 draw_points
[0].X
= fill_area
->X
;
1159 draw_points
[0].Y
= fill_area
->Y
;
1160 draw_points
[1].X
= fill_area
->X
+1;
1161 draw_points
[1].Y
= fill_area
->Y
;
1162 draw_points
[2].X
= fill_area
->X
;
1163 draw_points
[2].Y
= fill_area
->Y
+1;
1165 /* Transform the points to a co-ordinate space where X is the point's
1166 * position in the gradient, 0.0 being the start point and 1.0 the
1168 stat
= gdip_transform_points(graphics
, CoordinateSpaceWorld
,
1169 WineCoordinateSpaceGdiDevice
, draw_points
, 3);
1173 GpMatrix world_to_gradient
= fill
->transform
;
1175 stat
= GdipInvertMatrix(&world_to_gradient
);
1177 stat
= GdipTransformMatrixPoints(&world_to_gradient
, draw_points
, 3);
1182 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1183 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1185 for (y
=0; y
<fill_area
->Height
; y
++)
1187 for (x
=0; x
<fill_area
->Width
; x
++)
1189 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1191 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1198 case BrushTypeTextureFill
:
1200 GpTexture
*fill
= (GpTexture
*)brush
;
1201 GpPointF draw_points
[3];
1208 if (fill
->image
->type
!= ImageTypeBitmap
)
1210 FIXME("metafile texture brushes not implemented\n");
1211 return NotImplemented
;
1214 bitmap
= (GpBitmap
*)fill
->image
;
1215 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1217 src_area
.X
= src_area
.Y
= 0;
1218 src_area
.Width
= bitmap
->width
;
1219 src_area
.Height
= bitmap
->height
;
1221 draw_points
[0].X
= fill_area
->X
;
1222 draw_points
[0].Y
= fill_area
->Y
;
1223 draw_points
[1].X
= fill_area
->X
+1;
1224 draw_points
[1].Y
= fill_area
->Y
;
1225 draw_points
[2].X
= fill_area
->X
;
1226 draw_points
[2].Y
= fill_area
->Y
+1;
1228 /* Transform the points to the co-ordinate space of the bitmap. */
1229 stat
= gdip_transform_points(graphics
, CoordinateSpaceWorld
,
1230 WineCoordinateSpaceGdiDevice
, draw_points
, 3);
1234 GpMatrix world_to_texture
= fill
->transform
;
1236 stat
= GdipInvertMatrix(&world_to_texture
);
1238 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1241 if (stat
== Ok
&& !fill
->bitmap_bits
)
1243 BitmapData lockeddata
;
1245 fill
->bitmap_bits
= heap_alloc_zero(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1246 if (!fill
->bitmap_bits
)
1251 lockeddata
.Width
= bitmap
->width
;
1252 lockeddata
.Height
= bitmap
->height
;
1253 lockeddata
.Stride
= src_stride
;
1254 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1255 lockeddata
.Scan0
= fill
->bitmap_bits
;
1257 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1258 PixelFormat32bppARGB
, &lockeddata
);
1262 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1265 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1266 bitmap
->width
, bitmap
->height
,
1267 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
1271 heap_free(fill
->bitmap_bits
);
1272 fill
->bitmap_bits
= NULL
;
1278 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1279 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1280 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1281 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1283 for (y
=0; y
<fill_area
->Height
; y
++)
1285 for (x
=0; x
<fill_area
->Width
; x
++)
1288 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1289 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1291 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1292 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1293 &point
, fill
->imageattributes
, graphics
->interpolation
,
1294 graphics
->pixeloffset
);
1301 case BrushTypePathGradient
:
1303 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1305 GpMatrix world_to_device
;
1307 int i
, figure_start
=0;
1308 GpPointF start_point
, end_point
, center_point
;
1310 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1311 INT min_y
, max_y
, min_x
, max_x
;
1314 static BOOL transform_fixme_once
;
1316 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1320 FIXME("path gradient focus not implemented\n");
1327 FIXME("path gradient gamma correction not implemented\n");
1330 if (fill
->blendcount
)
1334 FIXME("path gradient blend not implemented\n");
1337 if (fill
->pblendcount
)
1341 FIXME("path gradient preset blend not implemented\n");
1344 if (!transform_fixme_once
)
1346 BOOL is_identity
=TRUE
;
1347 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1350 FIXME("path gradient transform not implemented\n");
1351 transform_fixme_once
= TRUE
;
1355 stat
= GdipClonePath(fill
->path
, &flat_path
);
1360 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
1361 CoordinateSpaceWorld
, &world_to_device
);
1364 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1368 center_point
= fill
->center
;
1369 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1373 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1378 GdipDeletePath(flat_path
);
1382 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1384 int start_center_line
=0, end_center_line
=0;
1385 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1386 REAL center_distance
;
1387 ARGB start_color
, end_color
;
1390 type
= flat_path
->pathdata
.Types
[i
];
1392 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1395 start_point
= flat_path
->pathdata
.Points
[i
];
1397 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1399 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1401 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1402 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1404 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1406 end_point
= flat_path
->pathdata
.Points
[i
+1];
1407 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1412 outer_color
= start_color
;
1414 min_yf
= center_point
.Y
;
1415 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1416 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1418 if (min_yf
< fill_area
->Y
)
1419 min_y
= fill_area
->Y
;
1421 min_y
= (INT
)ceil(min_yf
);
1423 max_yf
= center_point
.Y
;
1424 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1425 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1427 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1428 max_y
= fill_area
->Y
+ fill_area
->Height
;
1430 max_y
= (INT
)ceil(max_yf
);
1432 dy
= end_point
.Y
- start_point
.Y
;
1433 dx
= end_point
.X
- start_point
.X
;
1435 /* This is proportional to the distance from start-end line to center point. */
1436 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1437 dx
* (center_point
.Y
- start_point
.Y
);
1439 for (y
=min_y
; y
<max_y
; y
++)
1443 if (!seen_start
&& yf
>= start_point
.Y
)
1446 start_center_line
^= 1;
1448 if (!seen_end
&& yf
>= end_point
.Y
)
1451 end_center_line
^= 1;
1453 if (!seen_center
&& yf
>= center_point
.Y
)
1456 start_center_line
^= 1;
1457 end_center_line
^= 1;
1460 if (start_center_line
)
1461 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1463 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1465 if (end_center_line
)
1466 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1468 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1470 if (line1_xf
< line2_xf
)
1472 min_x
= (INT
)ceil(line1_xf
);
1473 max_x
= (INT
)ceil(line2_xf
);
1477 min_x
= (INT
)ceil(line2_xf
);
1478 max_x
= (INT
)ceil(line1_xf
);
1481 if (min_x
< fill_area
->X
)
1482 min_x
= fill_area
->X
;
1483 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1484 max_x
= fill_area
->X
+ fill_area
->Width
;
1486 for (x
=min_x
; x
<max_x
; x
++)
1491 if (start_color
!= end_color
)
1493 REAL blend_amount
, pdy
, pdx
;
1494 pdy
= yf
- center_point
.Y
;
1495 pdx
= xf
- center_point
.X
;
1497 if (fabs(pdx
) <= 0.001 && fabs(pdy
) <= 0.001)
1499 /* Too close to center point, don't try to calculate outer color */
1500 outer_color
= start_color
;
1504 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1505 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1509 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1510 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1512 distance
= distance
/ center_distance
;
1514 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1515 blend_colors(outer_color
, fill
->centercolor
, distance
);
1520 GdipDeletePath(flat_path
);
1524 return NotImplemented
;
1528 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1529 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1530 * should not be called on an hdc that has a path you care about. */
1531 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1532 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1534 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1536 HBRUSH brush
= NULL
;
1538 PointF ptf
[4], *custptf
= NULL
;
1539 POINT pt
[4], *custpt
= NULL
;
1541 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1546 if((x1
== x2
) && (y1
== y2
))
1549 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1551 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1553 brush
= CreateSolidBrush(color
);
1554 lb
.lbStyle
= BS_SOLID
;
1557 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1558 PS_JOIN_MITER
, 1, &lb
, 0,
1560 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1561 oldpen
= SelectObject(graphics
->hdc
, pen
);
1568 case LineCapSquareAnchor
:
1569 case LineCapDiamondAnchor
:
1570 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1571 if(cap
== LineCapDiamondAnchor
){
1572 dsmall
= cos(theta
+ M_PI_2
) * size
;
1573 dbig
= sin(theta
+ M_PI_2
) * size
;
1576 dsmall
= cos(theta
+ M_PI_4
) * size
;
1577 dbig
= sin(theta
+ M_PI_4
) * size
;
1580 ptf
[0].X
= x2
- dsmall
;
1581 ptf
[1].X
= x2
+ dbig
;
1583 ptf
[0].Y
= y2
- dbig
;
1584 ptf
[3].Y
= y2
+ dsmall
;
1586 ptf
[1].Y
= y2
- dsmall
;
1587 ptf
[2].Y
= y2
+ dbig
;
1589 ptf
[3].X
= x2
- dbig
;
1590 ptf
[2].X
= x2
+ dsmall
;
1592 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1594 round_points(pt
, ptf
, 3);
1596 Polygon(graphics
->hdc
, pt
, 4);
1599 case LineCapArrowAnchor
:
1600 size
= size
* 4.0 / sqrt(3.0);
1602 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1603 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1608 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1609 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1617 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1619 round_points(pt
, ptf
, 3);
1621 Polygon(graphics
->hdc
, pt
, 3);
1624 case LineCapRoundAnchor
:
1625 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1632 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1634 round_points(pt
, ptf
, 3);
1636 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1639 case LineCapTriangle
:
1641 dx
= cos(M_PI_2
+ theta
) * size
;
1642 dy
= sin(M_PI_2
+ theta
) * size
;
1649 dx
= cos(theta
) * size
;
1650 dy
= sin(theta
) * size
;
1655 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1657 round_points(pt
, ptf
, 3);
1659 Polygon(graphics
->hdc
, pt
, 3);
1663 dx
= dy
= size
/ 2.0;
1670 dx
= -cos(M_PI_2
+ theta
) * size
;
1671 dy
= -sin(M_PI_2
+ theta
) * size
;
1678 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1680 round_points(pt
, ptf
, 3);
1682 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1683 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1690 count
= custom
->pathdata
.Count
;
1691 custptf
= heap_alloc_zero(count
* sizeof(PointF
));
1692 custpt
= heap_alloc_zero(count
* sizeof(POINT
));
1693 tp
= heap_alloc_zero(count
);
1695 if(!custptf
|| !custpt
|| !tp
)
1698 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1700 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1701 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1702 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1704 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1705 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1707 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1709 round_points(pt
, ptf
, 3);
1711 for(i
= 0; i
< count
; i
++)
1712 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1715 BeginPath(graphics
->hdc
);
1716 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1717 EndPath(graphics
->hdc
);
1718 StrokeAndFillPath(graphics
->hdc
);
1721 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1733 SelectObject(graphics
->hdc
, oldbrush
);
1734 SelectObject(graphics
->hdc
, oldpen
);
1735 DeleteObject(brush
);
1740 /* Shortens the line by the given percent by changing x2, y2.
1741 * If percent is > 1.0 then the line will change direction.
1742 * If percent is negative it can lengthen the line. */
1743 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1745 REAL dist
, theta
, dx
, dy
;
1747 if((y1
== *y2
) && (x1
== *x2
))
1750 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1751 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1752 dx
= cos(theta
) * dist
;
1753 dy
= sin(theta
) * dist
;
1759 /* Shortens the line by the given amount by changing x2, y2.
1760 * If the amount is greater than the distance, the line will become length 0.
1761 * If the amount is negative, it can lengthen the line. */
1762 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1764 REAL dx
, dy
, percent
;
1768 if(dx
== 0 && dy
== 0)
1771 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1778 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1781 /* Conducts a linear search to find the bezier points that will back off
1782 * the endpoint of the curve by a distance of amt. Linear search works
1783 * better than binary in this case because there are multiple solutions,
1784 * and binary searches often find a bad one. I don't think this is what
1785 * Windows does but short of rendering the bezier without GDI's help it's
1786 * the best we can do. If rev then work from the start of the passed points
1787 * instead of the end. */
1788 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1791 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1792 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1801 origx
= pt
[fourth
].X
;
1802 origy
= pt
[fourth
].Y
;
1803 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1805 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1806 /* reset bezier points to original values */
1807 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1808 /* Perform magic on bezier points. Order is important here.*/
1809 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1810 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1811 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1812 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1813 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1814 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1816 dx
= pt
[fourth
].X
- origx
;
1817 dy
= pt
[fourth
].Y
- origy
;
1819 diff
= sqrt(dx
* dx
+ dy
* dy
);
1820 percent
+= 0.0005 * amt
;
1824 /* Draws a combination of bezier curves and lines between points. */
1825 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1826 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1828 POINT
*pti
= heap_alloc_zero(count
* sizeof(POINT
));
1829 BYTE
*tp
= heap_alloc_zero(count
);
1830 GpPointF
*ptcopy
= heap_alloc_zero(count
* sizeof(GpPointF
));
1832 GpStatus status
= GenericError
;
1838 if(!pti
|| !tp
|| !ptcopy
){
1839 status
= OutOfMemory
;
1843 for(i
= 1; i
< count
; i
++){
1844 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1845 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1846 || !(types
[i
+ 2] & PathPointTypeBezier
)){
1847 ERR("Bad bezier points\n");
1854 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1856 /* If we are drawing caps, go through the points and adjust them accordingly,
1857 * and draw the caps. */
1859 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1860 case PathPointTypeBezier
:
1861 if(pen
->endcap
== LineCapArrowAnchor
)
1862 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1863 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1864 shorten_bezier_amt(&ptcopy
[count
- 4],
1865 pen
->width
* pen
->customend
->inset
, FALSE
);
1867 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1868 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1869 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1870 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1873 case PathPointTypeLine
:
1874 if(pen
->endcap
== LineCapArrowAnchor
)
1875 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1876 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1878 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1879 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1880 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1881 pen
->customend
->inset
* pen
->width
);
1883 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1884 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1889 ERR("Bad path last point\n");
1893 /* Find start of points */
1894 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1895 == PathPointTypeStart
); j
++);
1897 switch(types
[j
] & PathPointTypePathTypeMask
){
1898 case PathPointTypeBezier
:
1899 if(pen
->startcap
== LineCapArrowAnchor
)
1900 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1901 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1902 shorten_bezier_amt(&ptcopy
[j
- 1],
1903 pen
->width
* pen
->customstart
->inset
, TRUE
);
1905 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1906 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1907 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1908 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1911 case PathPointTypeLine
:
1912 if(pen
->startcap
== LineCapArrowAnchor
)
1913 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1914 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1916 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1917 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1918 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1919 pen
->customstart
->inset
* pen
->width
);
1921 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1922 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1927 ERR("Bad path points\n");
1932 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptcopy
, count
);
1934 round_points(pti
, ptcopy
, count
);
1936 for(i
= 0; i
< count
; i
++){
1937 tp
[i
] = convert_path_point_type(types
[i
]);
1940 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1952 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1956 BeginPath(graphics
->hdc
);
1957 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1958 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1959 EndPath(graphics
->hdc
);
1963 typedef enum GraphicsContainerType
{
1966 } GraphicsContainerType
;
1968 typedef struct _GraphicsContainerItem
{
1970 GraphicsContainer contid
;
1971 GraphicsContainerType type
;
1973 SmoothingMode smoothing
;
1974 CompositingQuality compqual
;
1975 InterpolationMode interpolation
;
1976 CompositingMode compmode
;
1977 TextRenderingHint texthint
;
1980 PixelOffsetMode pixeloffset
;
1982 GpMatrix worldtrans
;
1984 INT origin_x
, origin_y
;
1985 } GraphicsContainerItem
;
1987 static GpStatus
init_container(GraphicsContainerItem
** container
,
1988 GDIPCONST GpGraphics
* graphics
, GraphicsContainerType type
){
1991 *container
= heap_alloc_zero(sizeof(GraphicsContainerItem
));
1995 (*container
)->contid
= graphics
->contid
+ 1;
1996 (*container
)->type
= type
;
1998 (*container
)->smoothing
= graphics
->smoothing
;
1999 (*container
)->compqual
= graphics
->compqual
;
2000 (*container
)->interpolation
= graphics
->interpolation
;
2001 (*container
)->compmode
= graphics
->compmode
;
2002 (*container
)->texthint
= graphics
->texthint
;
2003 (*container
)->scale
= graphics
->scale
;
2004 (*container
)->unit
= graphics
->unit
;
2005 (*container
)->textcontrast
= graphics
->textcontrast
;
2006 (*container
)->pixeloffset
= graphics
->pixeloffset
;
2007 (*container
)->origin_x
= graphics
->origin_x
;
2008 (*container
)->origin_y
= graphics
->origin_y
;
2009 (*container
)->worldtrans
= graphics
->worldtrans
;
2011 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
2013 heap_free(*container
);
2021 static void delete_container(GraphicsContainerItem
* container
)
2023 GdipDeleteRegion(container
->clip
);
2024 heap_free(container
);
2027 static GpStatus
restore_container(GpGraphics
* graphics
,
2028 GDIPCONST GraphicsContainerItem
* container
){
2032 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2033 if(sts
!= Ok
) return sts
;
2035 graphics
->worldtrans
= container
->worldtrans
;
2037 GdipDeleteRegion(graphics
->clip
);
2038 graphics
->clip
= newClip
;
2040 graphics
->contid
= container
->contid
- 1;
2042 graphics
->smoothing
= container
->smoothing
;
2043 graphics
->compqual
= container
->compqual
;
2044 graphics
->interpolation
= container
->interpolation
;
2045 graphics
->compmode
= container
->compmode
;
2046 graphics
->texthint
= container
->texthint
;
2047 graphics
->scale
= container
->scale
;
2048 graphics
->unit
= container
->unit
;
2049 graphics
->textcontrast
= container
->textcontrast
;
2050 graphics
->pixeloffset
= container
->pixeloffset
;
2051 graphics
->origin_x
= container
->origin_x
;
2052 graphics
->origin_y
= container
->origin_y
;
2057 static GpStatus
get_graphics_device_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2063 if(graphics
->hwnd
) {
2064 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2065 return GenericError
;
2067 rect
->X
= wnd_rect
.left
;
2068 rect
->Y
= wnd_rect
.top
;
2069 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2070 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2071 }else if (graphics
->image
){
2072 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2073 if (stat
== Ok
&& unit
!= UnitPixel
)
2074 FIXME("need to convert from unit %i\n", unit
);
2075 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2082 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2083 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2085 rect
->Width
= bmp
.bmWidth
;
2086 rect
->Height
= bmp
.bmHeight
;
2097 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2098 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2104 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2106 GpStatus stat
= get_graphics_device_bounds(graphics
, rect
);
2108 if (stat
== Ok
&& graphics
->hdc
)
2110 GpPointF points
[4], min_point
, max_point
;
2113 points
[0].X
= points
[2].X
= rect
->X
;
2114 points
[0].Y
= points
[1].Y
= rect
->Y
;
2115 points
[1].X
= points
[3].X
= rect
->X
+ rect
->Width
;
2116 points
[2].Y
= points
[3].Y
= rect
->Y
+ rect
->Height
;
2118 gdip_transform_points(graphics
, CoordinateSpaceDevice
, WineCoordinateSpaceGdiDevice
, points
, 4);
2120 min_point
= max_point
= points
[0];
2124 if (points
[i
].X
< min_point
.X
) min_point
.X
= points
[i
].X
;
2125 if (points
[i
].Y
< min_point
.Y
) min_point
.Y
= points
[i
].Y
;
2126 if (points
[i
].X
> max_point
.X
) max_point
.X
= points
[i
].X
;
2127 if (points
[i
].Y
> max_point
.Y
) max_point
.Y
= points
[i
].Y
;
2130 rect
->X
= min_point
.X
;
2131 rect
->Y
= min_point
.Y
;
2132 rect
->Width
= max_point
.X
- min_point
.X
;
2133 rect
->Height
= max_point
.Y
- min_point
.Y
;
2139 /* on success, rgn will contain the region of the graphics object which
2140 * is visible after clipping has been applied */
2141 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2147 /* Ignore graphics image bounds for metafiles */
2148 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2149 return GdipCombineRegionRegion(rgn
, graphics
->clip
, CombineModeReplace
);
2151 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2154 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2157 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2160 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2163 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2166 GdipDeleteRegion(tmp
);
2170 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2174 if (font
->unit
== UnitPixel
)
2176 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2180 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2181 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2183 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2186 lf
->lfHeight
= -(height
+ 0.5);
2188 lf
->lfEscapement
= 0;
2189 lf
->lfOrientation
= 0;
2190 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2191 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2192 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2193 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2194 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2195 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2196 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2197 lf
->lfQuality
= DEFAULT_QUALITY
;
2198 lf
->lfPitchAndFamily
= 0;
2199 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2202 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2203 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2204 GDIPCONST GpMatrix
*matrix
)
2206 HDC hdc
= CreateCompatibleDC(0);
2208 REAL angle
, rel_width
, rel_height
, font_height
;
2210 HFONT unscaled_font
;
2211 TEXTMETRICW textmet
;
2213 if (font
->unit
== UnitPixel
|| font
->unit
== UnitWorld
)
2214 font_height
= font
->emSize
;
2217 REAL unit_scale
, res
;
2219 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2220 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2222 font_height
= font
->emSize
* unit_scale
;
2233 GpMatrix xform
= *matrix
;
2234 GdipTransformMatrixPoints(&xform
, pt
, 3);
2237 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
2238 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2239 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2240 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2241 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2242 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2244 get_log_fontW(font
, graphics
, &lfw
);
2245 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2246 unscaled_font
= CreateFontIndirectW(&lfw
);
2248 SelectObject(hdc
, unscaled_font
);
2249 GetTextMetricsW(hdc
, &textmet
);
2251 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2252 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2254 *hfont
= CreateFontIndirectW(&lfw
);
2257 DeleteObject(unscaled_font
);
2260 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2262 TRACE("(%p, %p)\n", hdc
, graphics
);
2264 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2267 static void get_gdi_transform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2271 if (graphics
->hdc
== NULL
)
2273 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2277 GetTransform(graphics
->hdc
, 0x204, &xform
);
2278 GdipSetMatrixElements(matrix
, xform
.eM11
, xform
.eM12
, xform
.eM21
, xform
.eM22
, xform
.eDx
, xform
.eDy
);
2281 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2287 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2290 FIXME("Don't know how to handle parameter hDevice\n");
2295 if(graphics
== NULL
)
2296 return InvalidParameter
;
2298 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2299 if(!*graphics
) return OutOfMemory
;
2301 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2303 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2304 heap_free(*graphics
);
2308 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2309 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2310 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2312 (*graphics
)->alpha_hdc
= 1;
2315 (*graphics
)->hdc
= hdc
;
2316 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2317 (*graphics
)->owndc
= FALSE
;
2318 (*graphics
)->smoothing
= SmoothingModeDefault
;
2319 (*graphics
)->compqual
= CompositingQualityDefault
;
2320 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2321 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2322 (*graphics
)->compmode
= CompositingModeSourceOver
;
2323 (*graphics
)->unit
= UnitDisplay
;
2324 (*graphics
)->scale
= 1.0;
2325 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2326 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2327 (*graphics
)->busy
= FALSE
;
2328 (*graphics
)->textcontrast
= 4;
2329 list_init(&(*graphics
)->containers
);
2330 (*graphics
)->contid
= 0;
2331 get_gdi_transform(*graphics
, &(*graphics
)->gdi_transform
);
2333 (*graphics
)->gdi_clip
= CreateRectRgn(0,0,0,0);
2334 if (!GetClipRgn(hdc
, (*graphics
)->gdi_clip
))
2336 DeleteObject((*graphics
)->gdi_clip
);
2337 (*graphics
)->gdi_clip
= NULL
;
2340 TRACE("<-- %p\n", *graphics
);
2345 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2349 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2350 if(!*graphics
) return OutOfMemory
;
2352 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2353 GdipSetMatrixElements(&(*graphics
)->gdi_transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2355 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2356 heap_free(*graphics
);
2360 (*graphics
)->hdc
= NULL
;
2361 (*graphics
)->hwnd
= NULL
;
2362 (*graphics
)->owndc
= FALSE
;
2363 (*graphics
)->image
= image
;
2364 /* We have to store the image type here because the image may be freed
2365 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2366 (*graphics
)->image_type
= image
->type
;
2367 (*graphics
)->smoothing
= SmoothingModeDefault
;
2368 (*graphics
)->compqual
= CompositingQualityDefault
;
2369 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2370 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2371 (*graphics
)->compmode
= CompositingModeSourceOver
;
2372 (*graphics
)->unit
= UnitDisplay
;
2373 (*graphics
)->scale
= 1.0;
2374 (*graphics
)->xres
= image
->xres
;
2375 (*graphics
)->yres
= image
->yres
;
2376 (*graphics
)->busy
= FALSE
;
2377 (*graphics
)->textcontrast
= 4;
2378 list_init(&(*graphics
)->containers
);
2379 (*graphics
)->contid
= 0;
2381 TRACE("<-- %p\n", *graphics
);
2386 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2391 TRACE("(%p, %p)\n", hwnd
, graphics
);
2395 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2397 ReleaseDC(hwnd
, hdc
);
2401 (*graphics
)->hwnd
= hwnd
;
2402 (*graphics
)->owndc
= TRUE
;
2407 /* FIXME: no icm handling */
2408 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2410 TRACE("(%p, %p)\n", hwnd
, graphics
);
2412 return GdipCreateFromHWND(hwnd
, graphics
);
2415 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2416 UINT access
, IStream
**stream
)
2421 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2423 if(!stream
|| !filename
)
2424 return InvalidParameter
;
2426 if(access
& GENERIC_WRITE
)
2427 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2428 else if(access
& GENERIC_READ
)
2429 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2431 return InvalidParameter
;
2433 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2435 return hresult_to_status(ret
);
2438 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2440 GraphicsContainerItem
*cont
, *next
;
2442 TRACE("(%p)\n", graphics
);
2444 if(!graphics
) return InvalidParameter
;
2445 if(graphics
->busy
) return ObjectBusy
;
2447 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2449 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2455 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2457 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2458 list_remove(&cont
->entry
);
2459 delete_container(cont
);
2462 GdipDeleteRegion(graphics
->clip
);
2464 DeleteObject(graphics
->gdi_clip
);
2466 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2467 * do otherwise, but we can't have that in the test suite because it means
2468 * accessing freed memory. */
2469 graphics
->busy
= TRUE
;
2471 heap_free(graphics
);
2476 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2477 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2482 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2483 width
, height
, startAngle
, sweepAngle
);
2485 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2486 return InvalidParameter
;
2491 status
= GdipCreatePath(FillModeAlternate
, &path
);
2492 if (status
!= Ok
) return status
;
2494 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2496 status
= GdipDrawPath(graphics
, pen
, path
);
2498 GdipDeletePath(path
);
2502 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2503 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2505 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2506 width
, height
, startAngle
, sweepAngle
);
2508 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2511 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2512 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2516 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2517 x2
, y2
, x3
, y3
, x4
, y4
);
2519 if(!graphics
|| !pen
)
2520 return InvalidParameter
;
2533 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2536 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2537 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2539 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2540 x2
, y2
, x3
, y3
, x4
, y4
);
2542 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2545 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2546 GDIPCONST GpPointF
*points
, INT count
)
2551 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2553 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2554 return InvalidParameter
;
2559 status
= GdipCreatePath(FillModeAlternate
, &path
);
2560 if (status
!= Ok
) return status
;
2562 status
= GdipAddPathBeziers(path
, points
, count
);
2564 status
= GdipDrawPath(graphics
, pen
, path
);
2566 GdipDeletePath(path
);
2570 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2571 GDIPCONST GpPoint
*points
, INT count
)
2577 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2579 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2580 return InvalidParameter
;
2585 pts
= heap_alloc_zero(sizeof(GpPointF
) * count
);
2589 for(i
= 0; i
< count
; i
++){
2590 pts
[i
].X
= (REAL
)points
[i
].X
;
2591 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2594 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2601 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2602 GDIPCONST GpPointF
*points
, INT count
)
2604 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2606 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2609 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2610 GDIPCONST GpPoint
*points
, INT count
)
2612 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2614 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2617 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2618 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2623 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2625 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2626 return InvalidParameter
;
2631 status
= GdipCreatePath(FillModeAlternate
, &path
);
2632 if (status
!= Ok
) return status
;
2634 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2636 status
= GdipDrawPath(graphics
, pen
, path
);
2638 GdipDeletePath(path
);
2643 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2644 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2650 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2652 if(!points
|| count
<= 0)
2653 return InvalidParameter
;
2655 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2659 for(i
= 0; i
< count
; i
++){
2660 ptf
[i
].X
= (REAL
)points
[i
].X
;
2661 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2664 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2671 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2672 GDIPCONST GpPointF
*points
, INT count
)
2674 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2676 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2679 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2680 GDIPCONST GpPoint
*points
, INT count
)
2686 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2689 return InvalidParameter
;
2691 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2695 for(i
= 0; i
< count
; i
++){
2696 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2697 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2700 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2706 /* Approximates cardinal spline with Bezier curves. */
2707 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2708 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2713 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2715 if(!graphics
|| !pen
)
2716 return InvalidParameter
;
2722 return InvalidParameter
;
2724 status
= GdipCreatePath(FillModeAlternate
, &path
);
2725 if (status
!= Ok
) return status
;
2727 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2729 status
= GdipDrawPath(graphics
, pen
, path
);
2731 GdipDeletePath(path
);
2735 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2736 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2742 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2745 return InvalidParameter
;
2747 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2751 for(i
= 0; i
< count
; i
++){
2752 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2753 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2756 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2762 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2763 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2766 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2768 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2769 return InvalidParameter
;
2772 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2775 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2776 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2779 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2785 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2786 return InvalidParameter
;
2789 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2792 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2793 REAL y
, REAL width
, REAL height
)
2798 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2800 if(!graphics
|| !pen
)
2801 return InvalidParameter
;
2806 status
= GdipCreatePath(FillModeAlternate
, &path
);
2807 if (status
!= Ok
) return status
;
2809 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2811 status
= GdipDrawPath(graphics
, pen
, path
);
2813 GdipDeletePath(path
);
2817 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2818 INT y
, INT width
, INT height
)
2820 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2822 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2826 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2830 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2832 if(!graphics
|| !image
)
2833 return InvalidParameter
;
2835 GdipGetImageWidth(image
, &width
);
2836 GdipGetImageHeight(image
, &height
);
2838 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2839 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2842 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2845 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2847 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2850 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2851 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2855 REAL scale_x
, scale_y
, width
, height
;
2857 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2859 if (!graphics
|| !image
) return InvalidParameter
;
2861 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2862 scale_x
*= graphics
->xres
/ image
->xres
;
2863 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2864 scale_y
*= graphics
->yres
/ image
->yres
;
2865 width
= srcwidth
* scale_x
;
2866 height
= srcheight
* scale_y
;
2868 points
[0].X
= points
[2].X
= x
;
2869 points
[0].Y
= points
[1].Y
= y
;
2870 points
[1].X
= x
+ width
;
2871 points
[2].Y
= y
+ height
;
2873 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2874 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2877 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2878 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2881 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2884 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2885 GDIPCONST GpPointF
*dstpoints
, INT count
)
2889 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2892 return InvalidParameter
;
2894 GdipGetImageWidth(image
, &width
);
2895 GdipGetImageHeight(image
, &height
);
2897 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2898 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2901 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2902 GDIPCONST GpPoint
*dstpoints
, INT count
)
2906 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2908 if (count
!= 3 || !dstpoints
)
2909 return InvalidParameter
;
2911 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2912 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2913 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2914 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2915 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2916 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2918 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2921 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2922 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2924 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2928 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2929 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2930 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2931 DrawImageAbort callback
, VOID
* callbackData
)
2937 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2938 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2942 return NotImplemented
;
2944 if(!graphics
|| !image
|| !points
|| count
!= 3)
2945 return InvalidParameter
;
2947 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2948 debugstr_pointf(&points
[2]));
2950 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2952 return METAFILE_DrawImagePointsRect((GpMetafile
*)graphics
->image
,
2953 image
, points
, count
, srcx
, srcy
, srcwidth
, srcheight
,
2954 srcUnit
, imageAttributes
, callback
, callbackData
);
2957 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2959 /* Ensure source width/height is positive */
2962 GpPointF tmp
= ptf
[1];
2963 srcx
= srcx
+ srcwidth
;
2964 srcwidth
= -srcwidth
;
2965 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2966 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2973 GpPointF tmp
= ptf
[2];
2974 srcy
= srcy
+ srcheight
;
2975 srcheight
= -srcheight
;
2976 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
2977 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
2982 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2983 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2984 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
2986 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 4);
2987 round_points(pti
, ptf
, 4);
2989 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2990 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2992 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2993 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2994 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2995 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2996 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2998 if (image
->type
== ImageTypeBitmap
)
3000 GpBitmap
* bitmap
= (GpBitmap
*)image
;
3001 BOOL do_resampling
= FALSE
;
3002 BOOL use_software
= FALSE
;
3004 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
3005 graphics
->xres
, graphics
->yres
,
3006 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
3007 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
3008 imageAttributes
? imageAttributes
->outside_color
: 0);
3010 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
3011 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
3012 srcx
< 0 || srcy
< 0 ||
3013 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
3014 do_resampling
= TRUE
;
3016 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
3017 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
3018 use_software
= TRUE
;
3023 GpRectF graphics_bounds
;
3025 int i
, x
, y
, src_stride
, dst_stride
;
3026 GpMatrix dst_to_src
;
3027 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
3028 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
3029 BitmapData lockeddata
;
3030 InterpolationMode interpolation
= graphics
->interpolation
;
3031 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
3032 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3033 REAL x_dx
, x_dy
, y_dx
, y_dy
;
3034 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
3036 if (!imageAttributes
)
3037 imageAttributes
= &defaultImageAttributes
;
3039 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3040 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3043 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3044 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3045 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3046 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3049 stat
= get_graphics_device_bounds(graphics
, &graphics_bounds
);
3050 if (stat
!= Ok
) return stat
;
3052 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
3053 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
3054 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
3055 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
3057 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
3059 if (IsRectEmpty(&dst_area
)) return Ok
;
3061 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3062 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3063 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3064 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3065 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3066 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3068 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
3070 stat
= GdipInvertMatrix(&dst_to_src
);
3071 if (stat
!= Ok
) return stat
;
3075 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3076 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3080 /* Make sure src_area is equal in size to dst_area. */
3081 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
3082 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
3083 src_area
.Width
= dst_area
.right
- dst_area
.left
;
3084 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
3087 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3089 src_data
= heap_alloc_zero(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3092 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3094 /* Read the bits we need from the source bitmap into a compatible buffer. */
3095 lockeddata
.Width
= src_area
.Width
;
3096 lockeddata
.Height
= src_area
.Height
;
3097 lockeddata
.Stride
= src_stride
;
3098 lockeddata
.Scan0
= src_data
;
3099 if (!do_resampling
&& bitmap
->format
== PixelFormat32bppPARGB
)
3100 lockeddata
.PixelFormat
= apply_image_attributes(imageAttributes
, NULL
, 0, 0, 0, ColorAdjustTypeBitmap
, bitmap
->format
);
3102 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3104 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3105 lockeddata
.PixelFormat
, &lockeddata
);
3108 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3112 heap_free(src_data
);
3116 apply_image_attributes(imageAttributes
, src_data
,
3117 src_area
.Width
, src_area
.Height
,
3118 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
3122 /* Transform the bits as needed to the destination. */
3123 dst_data
= dst_dyn_data
= heap_alloc_zero(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3126 heap_free(src_data
);
3130 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3132 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3134 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3135 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3136 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3137 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3139 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3141 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3143 GpPointF src_pointf
;
3146 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3147 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3149 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3151 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3152 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3153 imageAttributes
, interpolation
, offset_mode
);
3161 dst_data
= src_data
;
3162 dst_stride
= src_stride
;
3165 gdi_transform_acquire(graphics
);
3167 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3168 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
,
3169 lockeddata
.PixelFormat
);
3171 gdi_transform_release(graphics
);
3173 heap_free(src_data
);
3175 heap_free(dst_dyn_data
);
3182 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3183 HBITMAP hbitmap
, old_hbm
=NULL
;
3187 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3188 bitmap
->format
== PixelFormat24bppRGB
||
3189 bitmap
->format
== PixelFormat32bppRGB
||
3190 bitmap
->format
== PixelFormat32bppPARGB
))
3192 BITMAPINFOHEADER bih
;
3194 PixelFormat dst_format
;
3196 /* we can't draw a bitmap of this format directly */
3197 hdc
= CreateCompatibleDC(0);
3201 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3202 bih
.biWidth
= bitmap
->width
;
3203 bih
.biHeight
= -bitmap
->height
;
3205 bih
.biBitCount
= 32;
3206 bih
.biCompression
= BI_RGB
;
3207 bih
.biSizeImage
= 0;
3208 bih
.biXPelsPerMeter
= 0;
3209 bih
.biYPelsPerMeter
= 0;
3211 bih
.biClrImportant
= 0;
3213 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3214 (void**)&temp_bits
, NULL
, 0);
3216 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3217 dst_format
= PixelFormat32bppPARGB
;
3219 dst_format
= PixelFormat32bppRGB
;
3221 convert_pixels(bitmap
->width
, bitmap
->height
,
3222 bitmap
->width
*4, temp_bits
, dst_format
,
3223 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3224 bitmap
->image
.palette
);
3228 if (bitmap
->hbitmap
)
3229 hbitmap
= bitmap
->hbitmap
;
3232 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3237 temp_hdc
= (hdc
== 0);
3242 if (!hdc
) hdc
= CreateCompatibleDC(0);
3243 old_hbm
= SelectObject(hdc
, hbitmap
);
3246 save_state
= SaveDC(graphics
->hdc
);
3248 stat
= get_clip_hrgn(graphics
, &hrgn
);
3252 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
3256 gdi_transform_acquire(graphics
);
3258 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3260 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3261 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3265 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3266 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3269 gdi_transform_release(graphics
);
3271 RestoreDC(graphics
->hdc
, save_state
);
3275 SelectObject(hdc
, old_hbm
);
3280 DeleteObject(hbitmap
);
3283 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3289 rc
.Width
= srcwidth
;
3290 rc
.Height
= srcheight
;
3292 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3293 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3297 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3298 return InvalidParameter
;
3304 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3305 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3306 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3307 DrawImageAbort callback
, VOID
* callbackData
)
3309 GpPointF pointsF
[3];
3312 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3313 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3316 if(!points
|| count
!=3)
3317 return InvalidParameter
;
3319 for(i
= 0; i
< count
; i
++){
3320 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3321 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3324 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3325 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3326 callback
, callbackData
);
3329 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3330 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3331 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3332 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3333 VOID
* callbackData
)
3337 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3338 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3339 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3343 points
[1].X
= dstx
+ dstwidth
;
3346 points
[2].Y
= dsty
+ dstheight
;
3348 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3349 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3352 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3353 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3354 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3355 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3356 VOID
* callbackData
)
3360 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3361 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3362 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3366 points
[1].X
= dstx
+ dstwidth
;
3369 points
[2].Y
= dsty
+ dstheight
;
3371 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3372 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3375 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3376 REAL x
, REAL y
, REAL width
, REAL height
)
3382 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3384 if(!graphics
|| !image
)
3385 return InvalidParameter
;
3387 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3391 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3392 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3393 unit
, NULL
, NULL
, NULL
);
3396 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3397 INT x
, INT y
, INT width
, INT height
)
3399 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3401 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3404 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3405 REAL y1
, REAL x2
, REAL y2
)
3409 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3412 return InvalidParameter
;
3414 if (pen
->unit
== UnitPixel
&& pen
->width
<= 0.0)
3421 return GdipDrawLines(graphics
, pen
, pt
, 2);
3424 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3425 INT y1
, INT x2
, INT y2
)
3427 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3429 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3432 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3433 GpPointF
*points
, INT count
)
3438 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3440 if(!pen
|| !graphics
|| (count
< 2))
3441 return InvalidParameter
;
3446 status
= GdipCreatePath(FillModeAlternate
, &path
);
3447 if (status
!= Ok
) return status
;
3449 status
= GdipAddPathLine2(path
, points
, count
);
3451 status
= GdipDrawPath(graphics
, pen
, path
);
3453 GdipDeletePath(path
);
3457 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3458 GpPoint
*points
, INT count
)
3464 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3466 ptf
= heap_alloc_zero(count
* sizeof(GpPointF
));
3467 if(!ptf
) return OutOfMemory
;
3469 for(i
= 0; i
< count
; i
++){
3470 ptf
[i
].X
= (REAL
) points
[i
].X
;
3471 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3474 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3480 static GpStatus
GDI32_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3486 save_state
= prepare_dc(graphics
, pen
);
3488 retval
= get_clip_hrgn(graphics
, &hrgn
);
3493 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
3495 gdi_transform_acquire(graphics
);
3497 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3498 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3500 gdi_transform_release(graphics
);
3503 restore_dc(graphics
, save_state
);
3509 static GpStatus
SOFTWARE_GdipDrawThinPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3513 GpMatrix
* transform
;
3514 GpRectF gp_bound_rect
;
3515 GpRect gp_output_area
;
3517 INT output_height
, output_width
;
3518 DWORD
*output_bits
, *brush_bits
=NULL
;
3520 static const BYTE static_dash_pattern
[] = {1,1,1,0,1,0,1,0};
3521 const BYTE
*dash_pattern
;
3522 INT dash_pattern_size
;
3523 BYTE
*dyn_dash_pattern
= NULL
;
3525 stat
= GdipClonePath(path
, &flat_path
);
3530 stat
= GdipCreateMatrix(&transform
);
3534 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3535 CoordinateSpaceWorld
, transform
);
3538 stat
= GdipFlattenPath(flat_path
, transform
, 1.0);
3540 GdipDeleteMatrix(transform
);
3543 /* estimate the output size in pixels, can be larger than necessary */
3546 output_area
.left
= floorf(flat_path
->pathdata
.Points
[0].X
);
3547 output_area
.right
= ceilf(flat_path
->pathdata
.Points
[0].X
);
3548 output_area
.top
= floorf(flat_path
->pathdata
.Points
[0].Y
);
3549 output_area
.bottom
= ceilf(flat_path
->pathdata
.Points
[0].Y
);
3551 for (i
=1; i
<flat_path
->pathdata
.Count
; i
++)
3554 x
= flat_path
->pathdata
.Points
[i
].X
;
3555 y
= flat_path
->pathdata
.Points
[i
].Y
;
3557 if (floorf(x
) < output_area
.left
) output_area
.left
= floorf(x
);
3558 if (floorf(y
) < output_area
.top
) output_area
.top
= floorf(y
);
3559 if (ceilf(x
) > output_area
.right
) output_area
.right
= ceilf(x
);
3560 if (ceilf(y
) > output_area
.bottom
) output_area
.bottom
= ceilf(y
);
3563 stat
= get_graphics_device_bounds(graphics
, &gp_bound_rect
);
3568 output_area
.left
= max(output_area
.left
, floorf(gp_bound_rect
.X
));
3569 output_area
.top
= max(output_area
.top
, floorf(gp_bound_rect
.Y
));
3570 output_area
.right
= min(output_area
.right
, ceilf(gp_bound_rect
.X
+ gp_bound_rect
.Width
));
3571 output_area
.bottom
= min(output_area
.bottom
, ceilf(gp_bound_rect
.Y
+ gp_bound_rect
.Height
));
3573 output_width
= output_area
.right
- output_area
.left
+ 1;
3574 output_height
= output_area
.bottom
- output_area
.top
+ 1;
3576 if (output_width
<= 0 || output_height
<= 0)
3578 GdipDeletePath(flat_path
);
3582 gp_output_area
.X
= output_area
.left
;
3583 gp_output_area
.Y
= output_area
.top
;
3584 gp_output_area
.Width
= output_width
;
3585 gp_output_area
.Height
= output_height
;
3587 output_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3594 if (pen
->brush
->bt
!= BrushTypeSolidColor
)
3596 /* allocate and draw brush output */
3597 brush_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3601 stat
= brush_fill_pixels(graphics
, pen
->brush
, brush_bits
,
3602 &gp_output_area
, output_width
);
3610 /* convert dash pattern to bool array */
3613 case DashStyleCustom
:
3615 dash_pattern_size
= 0;
3617 for (i
=0; i
< pen
->numdashes
; i
++)
3618 dash_pattern_size
+= gdip_round(pen
->dashes
[i
]);
3620 if (dash_pattern_size
!= 0)
3622 dash_pattern
= dyn_dash_pattern
= heap_alloc(dash_pattern_size
);
3624 if (dyn_dash_pattern
)
3627 for (i
=0; i
< pen
->numdashes
; i
++)
3630 for (k
=0; k
< gdip_round(pen
->dashes
[i
]); k
++)
3631 dyn_dash_pattern
[j
++] = (i
&1)^1;
3639 /* else fall through */
3641 case DashStyleSolid
:
3643 dash_pattern
= static_dash_pattern
;
3644 dash_pattern_size
= 1;
3647 dash_pattern
= static_dash_pattern
;
3648 dash_pattern_size
= 4;
3651 dash_pattern
= &static_dash_pattern
[4];
3652 dash_pattern_size
= 2;
3654 case DashStyleDashDot
:
3655 dash_pattern
= static_dash_pattern
;
3656 dash_pattern_size
= 6;
3658 case DashStyleDashDotDot
:
3659 dash_pattern
= static_dash_pattern
;
3660 dash_pattern_size
= 8;
3668 GpPointF subpath_start
= flat_path
->pathdata
.Points
[0];
3669 INT prev_x
= INT_MAX
, prev_y
= INT_MAX
;
3670 int dash_pos
= dash_pattern_size
- 1;
3672 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
3675 GpPointF start_point
, end_point
;
3676 GpPoint start_pointi
, end_pointi
;
3678 type
= flat_path
->pathdata
.Types
[i
];
3679 if (i
+1 < flat_path
->pathdata
.Count
)
3680 type2
= flat_path
->pathdata
.Types
[i
+1];
3682 type2
= PathPointTypeStart
;
3684 start_point
= flat_path
->pathdata
.Points
[i
];
3686 if ((type
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3687 subpath_start
= start_point
;
3689 if ((type
& PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
3690 end_point
= subpath_start
;
3691 else if ((type2
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3694 end_point
= flat_path
->pathdata
.Points
[i
+1];
3696 start_pointi
.X
= floorf(start_point
.X
);
3697 start_pointi
.Y
= floorf(start_point
.Y
);
3698 end_pointi
.X
= floorf(end_point
.X
);
3699 end_pointi
.Y
= floorf(end_point
.Y
);
3701 if(start_pointi
.X
== end_pointi
.X
&& start_pointi
.Y
== end_pointi
.Y
)
3704 /* draw line segment */
3705 if (abs(start_pointi
.Y
- end_pointi
.Y
) > abs(start_pointi
.X
- end_pointi
.X
))
3707 INT x
, y
, start_y
, end_y
, step
;
3709 if (start_pointi
.Y
< end_pointi
.Y
)
3712 start_y
= ceilf(start_point
.Y
) - output_area
.top
;
3713 end_y
= end_pointi
.Y
- output_area
.top
;
3718 start_y
= start_point
.Y
- output_area
.top
;
3719 end_y
= ceilf(end_point
.Y
) - output_area
.top
;
3722 for (y
=start_y
; y
!= (end_y
+step
); y
+=step
)
3724 x
= gdip_round( start_point
.X
+
3725 (end_point
.X
- start_point
.X
) * (y
+ output_area
.top
- start_point
.Y
) / (end_point
.Y
- start_point
.Y
) )
3728 if (x
== prev_x
&& y
== prev_y
)
3733 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3735 if (!dash_pattern
[dash_pos
])
3738 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3742 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3744 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3749 INT x
, y
, start_x
, end_x
, step
;
3751 if (start_pointi
.X
< end_pointi
.X
)
3754 start_x
= ceilf(start_point
.X
) - output_area
.left
;
3755 end_x
= end_pointi
.X
- output_area
.left
;
3760 start_x
= start_point
.X
- output_area
.left
;
3761 end_x
= ceilf(end_point
.X
) - output_area
.left
;
3764 for (x
=start_x
; x
!= (end_x
+step
); x
+=step
)
3766 y
= gdip_round( start_point
.Y
+
3767 (end_point
.Y
- start_point
.Y
) * (x
+ output_area
.left
- start_point
.X
) / (end_point
.X
- start_point
.X
) )
3770 if (x
== prev_x
&& y
== prev_y
)
3775 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3777 if (!dash_pattern
[dash_pos
])
3780 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3784 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3786 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3792 /* draw output image */
3795 gdi_transform_acquire(graphics
);
3797 stat
= alpha_blend_pixels(graphics
, output_area
.left
, output_area
.top
,
3798 (BYTE
*)output_bits
, output_width
, output_height
, output_width
* 4,
3799 PixelFormat32bppARGB
);
3801 gdi_transform_release(graphics
);
3804 heap_free(brush_bits
);
3805 heap_free(dyn_dash_pattern
);
3806 heap_free(output_bits
);
3809 GdipDeletePath(flat_path
);
3814 static GpStatus
SOFTWARE_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3818 GpMatrix
*transform
=NULL
;
3821 /* Check if the final pen thickness in pixels is too thin. */
3822 if (pen
->unit
== UnitPixel
)
3824 if (pen
->width
< 1.415)
3825 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3829 GpPointF points
[3] = {{0,0}, {1,0}, {0,1}};
3831 points
[1].X
= pen
->width
;
3832 points
[2].Y
= pen
->width
;
3834 stat
= gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
,
3835 CoordinateSpaceWorld
, points
, 3);
3840 if (((points
[1].X
-points
[0].X
)*(points
[1].X
-points
[0].X
) +
3841 (points
[1].Y
-points
[0].Y
)*(points
[1].Y
-points
[0].Y
) < 2.0001) &&
3842 ((points
[2].X
-points
[0].X
)*(points
[2].X
-points
[0].X
) +
3843 (points
[2].Y
-points
[0].Y
)*(points
[2].Y
-points
[0].Y
) < 2.0001))
3844 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3847 stat
= GdipClonePath(path
, &wide_path
);
3852 if (pen
->unit
== UnitPixel
)
3854 /* We have to transform this to device coordinates to get the widths right. */
3855 stat
= GdipCreateMatrix(&transform
);
3858 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3859 CoordinateSpaceWorld
, transform
);
3863 /* Set flatness based on the final coordinate space */
3866 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3867 CoordinateSpaceWorld
, &t
);
3872 flatness
= 1.0/sqrt(fmax(
3873 t
.matrix
[0] * t
.matrix
[0] + t
.matrix
[1] * t
.matrix
[1],
3874 t
.matrix
[2] * t
.matrix
[2] + t
.matrix
[3] * t
.matrix
[3]));
3878 stat
= GdipWidenPath(wide_path
, pen
, transform
, flatness
);
3880 if (pen
->unit
== UnitPixel
)
3882 /* Transform the path back to world coordinates */
3884 stat
= GdipInvertMatrix(transform
);
3887 stat
= GdipTransformPath(wide_path
, transform
);
3890 /* Actually draw the path */
3892 stat
= GdipFillPath(graphics
, pen
->brush
, wide_path
);
3894 GdipDeleteMatrix(transform
);
3896 GdipDeletePath(wide_path
);
3901 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3905 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3907 if(!pen
|| !graphics
)
3908 return InvalidParameter
;
3913 if (path
->pathdata
.Count
== 0)
3916 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
3917 retval
= METAFILE_DrawPath((GpMetafile
*)graphics
->image
, pen
, path
);
3918 else if (!graphics
->hdc
|| graphics
->alpha_hdc
|| !brush_can_fill_path(pen
->brush
, FALSE
))
3919 retval
= SOFTWARE_GdipDrawPath(graphics
, pen
, path
);
3921 retval
= GDI32_GdipDrawPath(graphics
, pen
, path
);
3926 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3927 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3932 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3933 width
, height
, startAngle
, sweepAngle
);
3935 if(!graphics
|| !pen
)
3936 return InvalidParameter
;
3941 status
= GdipCreatePath(FillModeAlternate
, &path
);
3942 if (status
!= Ok
) return status
;
3944 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3946 status
= GdipDrawPath(graphics
, pen
, path
);
3948 GdipDeletePath(path
);
3952 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3953 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3955 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3956 width
, height
, startAngle
, sweepAngle
);
3958 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3961 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3962 REAL y
, REAL width
, REAL height
)
3967 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3969 if(!pen
|| !graphics
)
3970 return InvalidParameter
;
3975 status
= GdipCreatePath(FillModeAlternate
, &path
);
3976 if (status
!= Ok
) return status
;
3978 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3980 status
= GdipDrawPath(graphics
, pen
, path
);
3982 GdipDeletePath(path
);
3986 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3987 INT y
, INT width
, INT height
)
3989 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3991 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3994 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3995 GDIPCONST GpRectF
* rects
, INT count
)
4000 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
4002 if(!graphics
|| !pen
|| !rects
|| count
< 1)
4003 return InvalidParameter
;
4008 status
= GdipCreatePath(FillModeAlternate
, &path
);
4009 if (status
!= Ok
) return status
;
4011 status
= GdipAddPathRectangles(path
, rects
, count
);
4013 status
= GdipDrawPath(graphics
, pen
, path
);
4015 GdipDeletePath(path
);
4019 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
4020 GDIPCONST GpRect
* rects
, INT count
)
4026 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
4028 if(!rects
|| count
<=0)
4029 return InvalidParameter
;
4031 rectsF
= heap_alloc_zero(sizeof(GpRectF
) * count
);
4035 for(i
= 0;i
< count
;i
++){
4036 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4037 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4038 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
4039 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4042 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
4048 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
4049 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
4054 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
4055 count
, tension
, fill
);
4057 if(!graphics
|| !brush
|| !points
)
4058 return InvalidParameter
;
4063 if(count
== 1) /* Do nothing */
4066 status
= GdipCreatePath(fill
, &path
);
4067 if (status
!= Ok
) return status
;
4069 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
4071 status
= GdipFillPath(graphics
, brush
, path
);
4073 GdipDeletePath(path
);
4077 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
4078 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
4084 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
4085 count
, tension
, fill
);
4087 if(!points
|| count
== 0)
4088 return InvalidParameter
;
4090 if(count
== 1) /* Do nothing */
4093 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
4097 for(i
= 0;i
< count
;i
++){
4098 ptf
[i
].X
= (REAL
)points
[i
].X
;
4099 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4102 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
4109 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
4110 GDIPCONST GpPointF
*points
, INT count
)
4112 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4113 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
4114 0.5f
, FillModeAlternate
);
4117 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
4118 GDIPCONST GpPoint
*points
, INT count
)
4120 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4121 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
4122 0.5f
, FillModeAlternate
);
4125 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4126 REAL y
, REAL width
, REAL height
)
4131 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4133 if(!graphics
|| !brush
)
4134 return InvalidParameter
;
4139 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4143 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
4146 stat
= GdipFillPath(graphics
, brush
, path
);
4148 GdipDeletePath(path
);
4154 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4155 INT y
, INT width
, INT height
)
4157 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4159 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
4162 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4168 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4169 return NotImplemented
;
4171 save_state
= SaveDC(graphics
->hdc
);
4172 EndPath(graphics
->hdc
);
4173 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
4176 retval
= get_clip_hrgn(graphics
, &hrgn
);
4181 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
4183 gdi_transform_acquire(graphics
);
4185 BeginPath(graphics
->hdc
);
4186 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
4187 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
4191 EndPath(graphics
->hdc
);
4192 brush_fill_path(graphics
, brush
);
4195 gdi_transform_release(graphics
);
4198 RestoreDC(graphics
->hdc
, save_state
);
4204 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4209 if (!brush_can_fill_pixels(brush
))
4210 return NotImplemented
;
4212 /* FIXME: This could probably be done more efficiently without regions. */
4214 stat
= GdipCreateRegionPath(path
, &rgn
);
4218 stat
= GdipFillRegion(graphics
, brush
, rgn
);
4220 GdipDeleteRegion(rgn
);
4226 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4228 GpStatus stat
= NotImplemented
;
4230 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
4232 if(!brush
|| !graphics
|| !path
)
4233 return InvalidParameter
;
4238 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4239 return METAFILE_FillPath((GpMetafile
*)graphics
->image
, brush
, path
);
4241 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4242 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
4244 if (stat
== NotImplemented
)
4245 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
4247 if (stat
== NotImplemented
)
4249 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
4256 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4257 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4262 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
4263 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4265 if(!graphics
|| !brush
)
4266 return InvalidParameter
;
4271 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4275 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4278 stat
= GdipFillPath(graphics
, brush
, path
);
4280 GdipDeletePath(path
);
4286 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4287 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4289 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
4290 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4292 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4295 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
4296 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
4301 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4303 if(!graphics
|| !brush
|| !points
|| !count
)
4304 return InvalidParameter
;
4309 stat
= GdipCreatePath(fillMode
, &path
);
4313 stat
= GdipAddPathPolygon(path
, points
, count
);
4316 stat
= GdipFillPath(graphics
, brush
, path
);
4318 GdipDeletePath(path
);
4324 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4325 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4330 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4332 if(!graphics
|| !brush
|| !points
|| !count
)
4333 return InvalidParameter
;
4338 stat
= GdipCreatePath(fillMode
, &path
);
4342 stat
= GdipAddPathPolygonI(path
, points
, count
);
4345 stat
= GdipFillPath(graphics
, brush
, path
);
4347 GdipDeletePath(path
);
4353 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4354 GDIPCONST GpPointF
*points
, INT count
)
4356 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4358 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4361 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4362 GDIPCONST GpPoint
*points
, INT count
)
4364 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4366 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4369 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4370 REAL x
, REAL y
, REAL width
, REAL height
)
4374 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4379 rect
.Height
= height
;
4381 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4384 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4385 INT x
, INT y
, INT width
, INT height
)
4389 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4393 rect
.Width
= (REAL
)width
;
4394 rect
.Height
= (REAL
)height
;
4396 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4399 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4405 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4407 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
4408 return InvalidParameter
;
4410 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4412 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
4413 /* FIXME: Add gdi32 drawing. */
4417 status
= GdipCreatePath(FillModeAlternate
, &path
);
4418 if (status
!= Ok
) return status
;
4420 status
= GdipAddPathRectangles(path
, rects
, count
);
4422 status
= GdipFillPath(graphics
, brush
, path
);
4424 GdipDeletePath(path
);
4428 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4435 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4437 if(!rects
|| count
<= 0)
4438 return InvalidParameter
;
4440 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
4444 for(i
= 0; i
< count
; i
++){
4445 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4446 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4447 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
4448 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4451 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4457 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4465 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4466 return NotImplemented
;
4468 save_state
= SaveDC(graphics
->hdc
);
4469 EndPath(graphics
->hdc
);
4472 status
= get_clip_hrgn(graphics
, &hrgn
);
4475 RestoreDC(graphics
->hdc
, save_state
);
4479 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
4482 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4485 RestoreDC(graphics
->hdc
, save_state
);
4489 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4492 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4494 BeginPath(graphics
->hdc
);
4495 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4496 EndPath(graphics
->hdc
);
4498 brush_fill_path(graphics
, brush
);
4501 RestoreDC(graphics
->hdc
, save_state
);
4507 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4511 GpRegion
*temp_region
;
4512 GpMatrix world_to_device
;
4513 GpRectF graphics_bounds
;
4517 GpRect gp_bound_rect
;
4519 if (!brush_can_fill_pixels(brush
))
4520 return NotImplemented
;
4522 stat
= gdi_transform_acquire(graphics
);
4525 stat
= get_graphics_device_bounds(graphics
, &graphics_bounds
);
4528 stat
= GdipCloneRegion(region
, &temp_region
);
4532 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
4533 CoordinateSpaceWorld
, &world_to_device
);
4536 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4539 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4542 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4544 GdipDeleteRegion(temp_region
);
4547 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4549 DeleteObject(hregion
);
4550 gdi_transform_release(graphics
);
4556 gp_bound_rect
.X
= bound_rect
.left
;
4557 gp_bound_rect
.Y
= bound_rect
.top
;
4558 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4559 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4561 pixel_data
= heap_alloc_zero(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4567 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4568 &gp_bound_rect
, gp_bound_rect
.Width
);
4571 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4572 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4573 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
,
4574 PixelFormat32bppARGB
);
4576 heap_free(pixel_data
);
4579 DeleteObject(hregion
);
4582 gdi_transform_release(graphics
);
4587 /*****************************************************************************
4588 * GdipFillRegion [GDIPLUS.@]
4590 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4593 GpStatus stat
= NotImplemented
;
4595 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4597 if (!(graphics
&& brush
&& region
))
4598 return InvalidParameter
;
4603 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4604 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4606 if (stat
== NotImplemented
)
4607 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4609 if (stat
== NotImplemented
)
4611 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4618 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4620 TRACE("(%p,%u)\n", graphics
, intention
);
4623 return InvalidParameter
;
4628 /* We have no internal operation queue, so there's no need to clear it. */
4636 /*****************************************************************************
4637 * GdipGetClipBounds [GDIPLUS.@]
4639 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4644 TRACE("(%p, %p)\n", graphics
, rect
);
4647 return InvalidParameter
;
4652 status
= GdipCreateRegion(&clip
);
4653 if (status
!= Ok
) return status
;
4655 status
= GdipGetClip(graphics
, clip
);
4657 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4659 GdipDeleteRegion(clip
);
4663 /*****************************************************************************
4664 * GdipGetClipBoundsI [GDIPLUS.@]
4666 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4668 TRACE("(%p, %p)\n", graphics
, rect
);
4671 return InvalidParameter
;
4676 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4679 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4680 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4681 CompositingMode
*mode
)
4683 TRACE("(%p, %p)\n", graphics
, mode
);
4685 if(!graphics
|| !mode
)
4686 return InvalidParameter
;
4691 *mode
= graphics
->compmode
;
4696 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4697 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4698 CompositingQuality
*quality
)
4700 TRACE("(%p, %p)\n", graphics
, quality
);
4702 if(!graphics
|| !quality
)
4703 return InvalidParameter
;
4708 *quality
= graphics
->compqual
;
4713 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4714 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4715 InterpolationMode
*mode
)
4717 TRACE("(%p, %p)\n", graphics
, mode
);
4719 if(!graphics
|| !mode
)
4720 return InvalidParameter
;
4725 *mode
= graphics
->interpolation
;
4730 /* FIXME: Need to handle color depths less than 24bpp */
4731 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4733 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4735 if(!graphics
|| !argb
)
4736 return InvalidParameter
;
4744 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4746 TRACE("(%p, %p)\n", graphics
, scale
);
4748 if(!graphics
|| !scale
)
4749 return InvalidParameter
;
4754 *scale
= graphics
->scale
;
4759 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4761 TRACE("(%p, %p)\n", graphics
, unit
);
4763 if(!graphics
|| !unit
)
4764 return InvalidParameter
;
4769 *unit
= graphics
->unit
;
4774 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4775 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4778 TRACE("(%p, %p)\n", graphics
, mode
);
4780 if(!graphics
|| !mode
)
4781 return InvalidParameter
;
4786 *mode
= graphics
->pixeloffset
;
4791 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4792 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4794 TRACE("(%p, %p)\n", graphics
, mode
);
4796 if(!graphics
|| !mode
)
4797 return InvalidParameter
;
4802 *mode
= graphics
->smoothing
;
4807 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4809 TRACE("(%p, %p)\n", graphics
, contrast
);
4811 if(!graphics
|| !contrast
)
4812 return InvalidParameter
;
4814 *contrast
= graphics
->textcontrast
;
4819 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4820 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4821 TextRenderingHint
*hint
)
4823 TRACE("(%p, %p)\n", graphics
, hint
);
4825 if(!graphics
|| !hint
)
4826 return InvalidParameter
;
4831 *hint
= graphics
->texthint
;
4836 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4840 GpMatrix device_to_world
;
4842 TRACE("(%p, %p)\n", graphics
, rect
);
4844 if(!graphics
|| !rect
)
4845 return InvalidParameter
;
4850 /* intersect window and graphics clipping regions */
4851 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4854 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4857 /* transform to world coordinates */
4858 if((stat
= get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
)) != Ok
)
4861 if((stat
= GdipTransformRegion(clip_rgn
, &device_to_world
)) != Ok
)
4864 /* get bounds of the region */
4865 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4868 GdipDeleteRegion(clip_rgn
);
4873 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4878 TRACE("(%p, %p)\n", graphics
, rect
);
4880 if(!graphics
|| !rect
)
4881 return InvalidParameter
;
4883 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4885 rect
->X
= gdip_round(rectf
.X
);
4886 rect
->Y
= gdip_round(rectf
.Y
);
4887 rect
->Width
= gdip_round(rectf
.Width
);
4888 rect
->Height
= gdip_round(rectf
.Height
);
4894 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4896 TRACE("(%p, %p)\n", graphics
, matrix
);
4898 if(!graphics
|| !matrix
)
4899 return InvalidParameter
;
4904 *matrix
= graphics
->worldtrans
;
4908 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4914 TRACE("(%p, %x)\n", graphics
, color
);
4917 return InvalidParameter
;
4922 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4923 return METAFILE_GraphicsClear((GpMetafile
*)graphics
->image
, color
);
4925 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4928 if((stat
= GdipGetVisibleClipBounds(graphics
, &wnd_rect
)) != Ok
){
4929 GdipDeleteBrush((GpBrush
*)brush
);
4933 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4934 wnd_rect
.Width
, wnd_rect
.Height
);
4936 GdipDeleteBrush((GpBrush
*)brush
);
4941 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4943 TRACE("(%p, %p)\n", graphics
, res
);
4945 if(!graphics
|| !res
)
4946 return InvalidParameter
;
4948 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4951 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4957 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4959 if(!graphics
|| !result
)
4960 return InvalidParameter
;
4967 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4968 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4971 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4974 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4977 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4980 GdipDeleteRegion(rgn
);
4984 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4986 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4989 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4995 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4997 if(!graphics
|| !result
)
4998 return InvalidParameter
;
5005 pts
[1].X
= x
+ width
;
5006 pts
[1].Y
= y
+ height
;
5008 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
5009 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
5012 pts
[1].X
-= pts
[0].X
;
5013 pts
[1].Y
-= pts
[0].Y
;
5015 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5018 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5021 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
5024 GdipDeleteRegion(rgn
);
5028 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
5030 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
5033 GpStatus
gdip_format_string(HDC hdc
,
5034 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5035 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
5036 gdip_format_string_callback callback
, void *user_data
)
5039 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
5040 nheight
, lineend
, lineno
= 0;
5042 StringAlignment halign
;
5045 HotkeyPrefix hkprefix
;
5046 INT
*hotkeyprefix_offsets
=NULL
;
5047 INT hotkeyprefix_count
=0;
5048 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
5049 BOOL seen_prefix
= FALSE
;
5051 if(length
== -1) length
= lstrlenW(string
);
5053 stringdup
= heap_alloc_zero((length
+ 1) * sizeof(WCHAR
));
5054 if(!stringdup
) return OutOfMemory
;
5057 format
= &default_drawstring_format
;
5059 nwidth
= rect
->Width
;
5060 nheight
= rect
->Height
;
5061 if (ignore_empty_clip
)
5063 if (!nwidth
) nwidth
= INT_MAX
;
5064 if (!nheight
) nheight
= INT_MAX
;
5067 hkprefix
= format
->hkprefix
;
5069 if (hkprefix
== HotkeyPrefixShow
)
5071 for (i
=0; i
<length
; i
++)
5073 if (string
[i
] == '&')
5074 hotkeyprefix_count
++;
5078 if (hotkeyprefix_count
)
5079 hotkeyprefix_offsets
= heap_alloc_zero(sizeof(INT
) * hotkeyprefix_count
);
5081 hotkeyprefix_count
= 0;
5083 for(i
= 0, j
= 0; i
< length
; i
++){
5084 /* FIXME: This makes the indexes passed to callback inaccurate. */
5085 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
5088 /* FIXME: tabs should be handled using tabstops from stringformat */
5089 if (string
[i
] == '\t')
5092 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
5093 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
5094 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
5100 seen_prefix
= FALSE
;
5102 stringdup
[j
] = string
[i
];
5108 halign
= format
->align
;
5110 while(sum
< length
){
5111 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
5112 nwidth
, &fit
, NULL
, &size
);
5118 for(lret
= 0; lret
< fit
; lret
++)
5119 if(*(stringdup
+ sum
+ lret
) == '\n')
5122 /* Line break code (may look strange, but it imitates windows). */
5124 lineend
= fit
= lret
; /* this is not an off-by-one error */
5125 else if(fit
< (length
- sum
)){
5126 if(*(stringdup
+ sum
+ fit
) == ' ')
5127 while(*(stringdup
+ sum
+ fit
) == ' ')
5130 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
5133 if(*(stringdup
+ sum
+ fit
) == '\t')
5142 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
5143 *(stringdup
+ sum
+ lineend
- 1) == '\t')
5149 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
5150 nwidth
, &j
, NULL
, &size
);
5152 bounds
.Width
= size
.cx
;
5154 if(height
+ size
.cy
> nheight
)
5156 if (format
->attr
& StringFormatFlagsLineLimit
)
5158 bounds
.Height
= nheight
- (height
+ size
.cy
);
5161 bounds
.Height
= size
.cy
;
5163 bounds
.Y
= rect
->Y
+ height
;
5167 case StringAlignmentNear
:
5171 case StringAlignmentCenter
:
5172 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
5174 case StringAlignmentFar
:
5175 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
5179 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
5180 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
5183 stat
= callback(hdc
, stringdup
, sum
, lineend
,
5184 font
, rect
, format
, lineno
, &bounds
,
5185 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
5186 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
5191 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
5195 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
5197 if(height
> nheight
)
5200 /* Stop if this was a linewrap (but not if it was a linebreak). */
5201 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
5205 heap_free(stringdup
);
5206 heap_free(hotkeyprefix_offsets
);
5211 struct measure_ranges_args
{
5213 REAL rel_width
, rel_height
;
5216 static GpStatus
measure_ranges_callback(HDC hdc
,
5217 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5218 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5219 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5220 INT underlined_index_count
, void *user_data
)
5224 struct measure_ranges_args
*args
= user_data
;
5226 for (i
=0; i
<format
->range_count
; i
++)
5228 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
5229 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
5230 if (range_start
< range_end
)
5235 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
5236 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
5238 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
5239 INT_MAX
, NULL
, NULL
, &range_size
);
5240 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
5242 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
5243 INT_MAX
, NULL
, NULL
, &range_size
);
5244 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
5246 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
5255 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
5256 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
5257 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
5258 INT regionCount
, GpRegion
** regions
)
5262 HFONT gdifont
, oldfont
;
5263 struct measure_ranges_args args
;
5264 HDC hdc
, temp_hdc
=NULL
;
5269 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
5270 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
5272 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
5273 return InvalidParameter
;
5275 if (regionCount
< stringFormat
->range_count
)
5276 return InvalidParameter
;
5280 hdc
= temp_hdc
= CreateCompatibleDC(0);
5281 if (!temp_hdc
) return OutOfMemory
;
5284 hdc
= graphics
->hdc
;
5286 if (stringFormat
->attr
)
5287 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
5295 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5296 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5297 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5298 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5299 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5301 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
5302 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5304 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
5305 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
5306 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
5307 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
5309 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5310 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5312 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
5313 oldfont
= SelectObject(hdc
, gdifont
);
5315 for (i
=0; i
<stringFormat
->range_count
; i
++)
5317 stat
= GdipSetEmpty(regions
[i
]);
5322 args
.regions
= regions
;
5324 gdi_transform_acquire(graphics
);
5326 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
5327 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
5329 gdi_transform_release(graphics
);
5331 SelectObject(hdc
, oldfont
);
5332 DeleteObject(gdifont
);
5340 struct measure_string_args
{
5342 INT
*codepointsfitted
;
5344 REAL rel_width
, rel_height
;
5347 static GpStatus
measure_string_callback(HDC hdc
,
5348 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5349 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5350 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5351 INT underlined_index_count
, void *user_data
)
5353 struct measure_string_args
*args
= user_data
;
5354 REAL new_width
, new_height
;
5356 new_width
= bounds
->Width
/ args
->rel_width
;
5357 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
5359 if (new_width
> args
->bounds
->Width
)
5360 args
->bounds
->Width
= new_width
;
5362 if (new_height
> args
->bounds
->Height
)
5363 args
->bounds
->Height
= new_height
;
5365 if (args
->codepointsfitted
)
5366 *args
->codepointsfitted
= index
+ length
;
5368 if (args
->linesfilled
)
5369 (*args
->linesfilled
)++;
5374 /* Find the smallest rectangle that bounds the text when it is printed in rect
5375 * according to the format options listed in format. If rect has 0 width and
5376 * height, then just find the smallest rectangle that bounds the text when it's
5377 * printed at location (rect->X, rect-Y). */
5378 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
5379 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5380 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
5381 INT
*codepointsfitted
, INT
*linesfilled
)
5383 HFONT oldfont
, gdifont
;
5384 struct measure_string_args args
;
5385 HDC temp_hdc
=NULL
, hdc
;
5391 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
5392 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
5393 bounds
, codepointsfitted
, linesfilled
);
5395 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
5396 return InvalidParameter
;
5400 hdc
= temp_hdc
= CreateCompatibleDC(0);
5401 if (!temp_hdc
) return OutOfMemory
;
5404 hdc
= graphics
->hdc
;
5406 if(linesfilled
) *linesfilled
= 0;
5407 if(codepointsfitted
) *codepointsfitted
= 0;
5410 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5418 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5419 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5420 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5421 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5422 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5424 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5425 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5427 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
5428 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
5429 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
5430 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
5431 if (scaled_rect
.Width
>= 0.5)
5433 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5434 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5437 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5438 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5440 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5441 oldfont
= SelectObject(hdc
, gdifont
);
5443 bounds
->X
= rect
->X
;
5444 bounds
->Y
= rect
->Y
;
5445 bounds
->Width
= 0.0;
5446 bounds
->Height
= 0.0;
5448 args
.bounds
= bounds
;
5449 args
.codepointsfitted
= &glyphs
;
5450 args
.linesfilled
= &lines
;
5453 gdi_transform_acquire(graphics
);
5455 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5456 measure_string_callback
, &args
);
5458 gdi_transform_release(graphics
);
5460 if (linesfilled
) *linesfilled
= lines
;
5461 if (codepointsfitted
) *codepointsfitted
= glyphs
;
5464 bounds
->Width
+= margin_x
* 2.0;
5466 SelectObject(hdc
, oldfont
);
5467 DeleteObject(gdifont
);
5475 struct draw_string_args
{
5476 GpGraphics
*graphics
;
5477 GDIPCONST GpBrush
*brush
;
5478 REAL x
, y
, rel_width
, rel_height
, ascent
;
5481 static GpStatus
draw_string_callback(HDC hdc
,
5482 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5483 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5484 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5485 INT underlined_index_count
, void *user_data
)
5487 struct draw_string_args
*args
= user_data
;
5491 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5492 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5494 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
5495 args
->brush
, &position
,
5496 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5498 if (stat
== Ok
&& underlined_index_count
)
5500 OUTLINETEXTMETRICW otm
;
5501 REAL underline_y
, underline_height
;
5504 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5506 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5507 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5509 for (i
=0; i
<underlined_index_count
; i
++)
5511 REAL start_x
, end_x
;
5513 INT ofs
= underlined_indexes
[i
] - index
;
5515 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5516 start_x
= text_size
.cx
/ args
->rel_width
;
5518 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5519 end_x
= text_size
.cx
/ args
->rel_width
;
5521 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5528 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5529 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5530 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5534 GpPointF pt
[3], rectcpy
[4];
5536 REAL rel_width
, rel_height
, margin_x
;
5537 INT save_state
, format_flags
= 0;
5539 struct draw_string_args args
;
5541 HDC hdc
, temp_hdc
=NULL
;
5542 TEXTMETRICW textmetric
;
5544 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5545 length
, font
, debugstr_rectf(rect
), format
, brush
);
5547 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5548 return InvalidParameter
;
5552 hdc
= graphics
->hdc
;
5556 hdc
= temp_hdc
= CreateCompatibleDC(0);
5560 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5562 format_flags
= format
->attr
;
5564 /* Should be no need to explicitly test for StringAlignmentNear as
5565 * that is default behavior if no alignment is passed. */
5566 if(format
->line_align
!= StringAlignmentNear
){
5567 RectF bounds
, in_rect
= *rect
;
5568 in_rect
.Height
= 0.0; /* avoid height clipping */
5569 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5571 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5573 if(format
->line_align
== StringAlignmentCenter
)
5574 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5575 else if(format
->line_align
== StringAlignmentFar
)
5576 offsety
= (rect
->Height
- bounds
.Height
);
5578 TRACE("line align %d, offsety %f\n", format
->line_align
, offsety
);
5581 save_state
= SaveDC(hdc
);
5589 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5590 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5591 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5592 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5593 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5595 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5596 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5597 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5598 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5599 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, rectcpy
, 4);
5600 round_points(corners
, rectcpy
, 4);
5602 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5603 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5605 scaled_rect
.X
= margin_x
* rel_width
;
5606 scaled_rect
.Y
= 0.0;
5607 scaled_rect
.Width
= rel_width
* rect
->Width
;
5608 scaled_rect
.Height
= rel_height
* rect
->Height
;
5609 if (scaled_rect
.Width
>= 0.5)
5611 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5612 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5615 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5616 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5618 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5619 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5620 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5622 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5623 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5624 SelectClipRgn(hdc
, rgn
);
5627 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5628 SelectObject(hdc
, gdifont
);
5630 args
.graphics
= graphics
;
5634 args
.y
= rect
->Y
+ offsety
;
5636 args
.rel_width
= rel_width
;
5637 args
.rel_height
= rel_height
;
5639 gdi_transform_acquire(graphics
);
5641 GetTextMetricsW(hdc
, &textmetric
);
5642 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5644 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5645 draw_string_callback
, &args
);
5647 gdi_transform_release(graphics
);
5650 DeleteObject(gdifont
);
5652 RestoreDC(hdc
, save_state
);
5659 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5661 TRACE("(%p)\n", graphics
);
5664 return InvalidParameter
;
5669 return GdipSetInfinite(graphics
->clip
);
5672 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5676 TRACE("(%p)\n", graphics
);
5679 return InvalidParameter
;
5684 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5685 stat
= METAFILE_ResetWorldTransform((GpMetafile
*)graphics
->image
);
5691 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5694 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5695 GpMatrixOrder order
)
5699 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5702 return InvalidParameter
;
5707 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5708 stat
= METAFILE_RotateWorldTransform((GpMetafile
*)graphics
->image
, angle
, order
);
5714 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5717 static GpStatus
begin_container(GpGraphics
*graphics
,
5718 GraphicsContainerType type
, GraphicsContainer
*state
)
5720 GraphicsContainerItem
*container
;
5723 if(!graphics
|| !state
)
5724 return InvalidParameter
;
5726 sts
= init_container(&container
, graphics
, type
);
5730 list_add_head(&graphics
->containers
, &container
->entry
);
5731 *state
= graphics
->contid
= container
->contid
;
5733 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5734 if (type
== BEGIN_CONTAINER
)
5735 METAFILE_BeginContainerNoParams((GpMetafile
*)graphics
->image
, container
->contid
);
5737 METAFILE_SaveGraphics((GpMetafile
*)graphics
->image
, container
->contid
);
5743 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5745 TRACE("(%p, %p)\n", graphics
, state
);
5746 return begin_container(graphics
, SAVE_GRAPHICS
, state
);
5749 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5750 GraphicsContainer
*state
)
5752 TRACE("(%p, %p)\n", graphics
, state
);
5753 return begin_container(graphics
, BEGIN_CONTAINER
, state
);
5756 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5758 GraphicsContainerItem
*container
;
5761 GpRectF scaled_srcrect
;
5762 REAL scale_x
, scale_y
;
5764 TRACE("(%p, %s, %s, %d, %p)\n", graphics
, debugstr_rectf(dstrect
), debugstr_rectf(srcrect
), unit
, state
);
5766 if(!graphics
|| !dstrect
|| !srcrect
|| unit
< UnitPixel
|| unit
> UnitMillimeter
|| !state
)
5767 return InvalidParameter
;
5769 stat
= init_container(&container
, graphics
, BEGIN_CONTAINER
);
5773 list_add_head(&graphics
->containers
, &container
->entry
);
5774 *state
= graphics
->contid
= container
->contid
;
5776 scale_x
= units_to_pixels(1.0, unit
, graphics
->xres
);
5777 scale_y
= units_to_pixels(1.0, unit
, graphics
->yres
);
5779 scaled_srcrect
.X
= scale_x
* srcrect
->X
;
5780 scaled_srcrect
.Y
= scale_y
* srcrect
->Y
;
5781 scaled_srcrect
.Width
= scale_x
* srcrect
->Width
;
5782 scaled_srcrect
.Height
= scale_y
* srcrect
->Height
;
5784 transform
.matrix
[0] = dstrect
->Width
/ scaled_srcrect
.Width
;
5785 transform
.matrix
[1] = 0.0;
5786 transform
.matrix
[2] = 0.0;
5787 transform
.matrix
[3] = dstrect
->Height
/ scaled_srcrect
.Height
;
5788 transform
.matrix
[4] = dstrect
->X
- scaled_srcrect
.X
;
5789 transform
.matrix
[5] = dstrect
->Y
- scaled_srcrect
.Y
;
5791 GdipMultiplyMatrix(&graphics
->worldtrans
, &transform
, MatrixOrderPrepend
);
5793 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5794 METAFILE_BeginContainer((GpMetafile
*)graphics
->image
, dstrect
, srcrect
, unit
, container
->contid
);
5800 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5802 GpRectF dstrectf
, srcrectf
;
5804 TRACE("(%p, %p, %p, %d, %p)\n", graphics
, dstrect
, srcrect
, unit
, state
);
5806 if (!dstrect
|| !srcrect
)
5807 return InvalidParameter
;
5809 dstrectf
.X
= dstrect
->X
;
5810 dstrectf
.Y
= dstrect
->Y
;
5811 dstrectf
.Width
= dstrect
->Width
;
5812 dstrectf
.Height
= dstrect
->Height
;
5814 srcrectf
.X
= srcrect
->X
;
5815 srcrectf
.Y
= srcrect
->Y
;
5816 srcrectf
.Width
= srcrect
->Width
;
5817 srcrectf
.Height
= srcrect
->Height
;
5819 return GdipBeginContainer(graphics
, &dstrectf
, &srcrectf
, unit
, state
);
5822 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5824 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5825 return NotImplemented
;
5828 static GpStatus
end_container(GpGraphics
*graphics
, GraphicsContainerType type
,
5829 GraphicsContainer state
)
5832 GraphicsContainerItem
*container
, *container2
;
5835 return InvalidParameter
;
5837 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5838 if(container
->contid
== state
&& container
->type
== type
)
5842 /* did not find a matching container */
5843 if(&container
->entry
== &graphics
->containers
)
5846 sts
= restore_container(graphics
, container
);
5850 /* remove all of the containers on top of the found container */
5851 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5852 if(container
->contid
== state
)
5854 list_remove(&container
->entry
);
5855 delete_container(container
);
5858 list_remove(&container
->entry
);
5859 delete_container(container
);
5861 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5862 if (type
== BEGIN_CONTAINER
)
5863 METAFILE_EndContainer((GpMetafile
*)graphics
->image
, state
);
5865 METAFILE_RestoreGraphics((GpMetafile
*)graphics
->image
, state
);
5871 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5873 TRACE("(%p, %x)\n", graphics
, state
);
5874 return end_container(graphics
, BEGIN_CONTAINER
, state
);
5877 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5879 TRACE("(%p, %x)\n", graphics
, state
);
5880 return end_container(graphics
, SAVE_GRAPHICS
, state
);
5883 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5884 REAL sy
, GpMatrixOrder order
)
5888 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5891 return InvalidParameter
;
5896 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5897 stat
= METAFILE_ScaleWorldTransform((GpMetafile
*)graphics
->image
, sx
, sy
, order
);
5903 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5906 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5909 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5911 if(!graphics
|| !srcgraphics
)
5912 return InvalidParameter
;
5914 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5917 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5918 CompositingMode mode
)
5920 TRACE("(%p, %d)\n", graphics
, mode
);
5923 return InvalidParameter
;
5928 if(graphics
->compmode
== mode
)
5931 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5935 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5936 EmfPlusRecordTypeSetCompositingMode
, mode
);
5941 graphics
->compmode
= mode
;
5946 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5947 CompositingQuality quality
)
5949 TRACE("(%p, %d)\n", graphics
, quality
);
5952 return InvalidParameter
;
5957 if(graphics
->compqual
== quality
)
5960 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5964 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5965 EmfPlusRecordTypeSetCompositingQuality
, quality
);
5970 graphics
->compqual
= quality
;
5975 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5976 InterpolationMode mode
)
5978 TRACE("(%p, %d)\n", graphics
, mode
);
5980 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5981 return InvalidParameter
;
5986 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5987 mode
= InterpolationModeBilinear
;
5989 if (mode
== InterpolationModeHighQuality
)
5990 mode
= InterpolationModeHighQualityBicubic
;
5992 if (mode
== graphics
->interpolation
)
5995 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5999 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6000 EmfPlusRecordTypeSetInterpolationMode
, mode
);
6005 graphics
->interpolation
= mode
;
6010 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
6014 TRACE("(%p, %.2f)\n", graphics
, scale
);
6016 if(!graphics
|| (scale
<= 0.0))
6017 return InvalidParameter
;
6022 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6024 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
6029 graphics
->scale
= scale
;
6034 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
6038 TRACE("(%p, %d)\n", graphics
, unit
);
6041 return InvalidParameter
;
6046 if(unit
== UnitWorld
)
6047 return InvalidParameter
;
6049 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6051 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
6056 graphics
->unit
= unit
;
6061 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
6064 TRACE("(%p, %d)\n", graphics
, mode
);
6067 return InvalidParameter
;
6072 if(graphics
->pixeloffset
== mode
)
6075 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6079 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6080 EmfPlusRecordTypeSetPixelOffsetMode
, mode
);
6085 graphics
->pixeloffset
= mode
;
6090 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
6094 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
6097 FIXME("value is unused in rendering\n");
6100 return InvalidParameter
;
6102 graphics
->origin_x
= x
;
6103 graphics
->origin_y
= y
;
6108 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
6110 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
6112 if (!graphics
|| !x
|| !y
)
6113 return InvalidParameter
;
6115 *x
= graphics
->origin_x
;
6116 *y
= graphics
->origin_y
;
6121 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
6123 TRACE("(%p, %d)\n", graphics
, mode
);
6126 return InvalidParameter
;
6131 if(graphics
->smoothing
== mode
)
6134 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6136 BOOL antialias
= (mode
!= SmoothingModeDefault
&&
6137 mode
!= SmoothingModeNone
&& mode
!= SmoothingModeHighSpeed
);
6139 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6140 EmfPlusRecordTypeSetAntiAliasMode
, (mode
<< 1) + antialias
);
6145 graphics
->smoothing
= mode
;
6150 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
6152 TRACE("(%p, %d)\n", graphics
, contrast
);
6155 return InvalidParameter
;
6157 graphics
->textcontrast
= contrast
;
6162 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
6163 TextRenderingHint hint
)
6165 TRACE("(%p, %d)\n", graphics
, hint
);
6167 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
6168 return InvalidParameter
;
6173 if(graphics
->texthint
== hint
)
6176 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6179 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6180 EmfPlusRecordTypeSetTextRenderingHint
, hint
);
6185 graphics
->texthint
= hint
;
6190 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
6194 TRACE("(%p, %p)\n", graphics
, matrix
);
6196 if(!graphics
|| !matrix
)
6197 return InvalidParameter
;
6202 TRACE("%f,%f,%f,%f,%f,%f\n",
6203 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
6204 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
6206 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6207 stat
= METAFILE_SetWorldTransform((GpMetafile
*)graphics
->image
, matrix
);
6213 graphics
->worldtrans
= *matrix
;
6218 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
6219 REAL dy
, GpMatrixOrder order
)
6223 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
6226 return InvalidParameter
;
6231 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6232 stat
= METAFILE_TranslateWorldTransform((GpMetafile
*)graphics
->image
, dx
, dy
, order
);
6238 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
6241 /*****************************************************************************
6242 * GdipSetClipHrgn [GDIPLUS.@]
6244 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
6250 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
6253 return InvalidParameter
;
6258 /* hrgn is in gdi32 device units */
6259 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
6263 status
= get_graphics_transform(graphics
, CoordinateSpaceDevice
, WineCoordinateSpaceGdiDevice
, &transform
);
6266 status
= GdipTransformRegion(region
, &transform
);
6269 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6271 GdipDeleteRegion(region
);
6276 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
6281 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
6284 return InvalidParameter
;
6289 status
= GdipClonePath(path
, &clip_path
);
6292 GpMatrix world_to_device
;
6294 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
6295 CoordinateSpaceWorld
, &world_to_device
);
6296 status
= GdipTransformPath(clip_path
, &world_to_device
);
6298 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
6300 GdipDeletePath(clip_path
);
6305 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
6306 REAL width
, REAL height
,
6313 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6316 return InvalidParameter
;
6321 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6323 status
= METAFILE_SetClipRect((GpMetafile
*)graphics
->image
, x
, y
, width
, height
, mode
);
6331 rect
.Height
= height
;
6332 status
= GdipCreateRegionRect(&rect
, ®ion
);
6335 GpMatrix world_to_device
;
6337 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6338 status
= GdipTransformRegion(region
, &world_to_device
);
6340 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6342 GdipDeleteRegion(region
);
6347 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
6348 INT width
, INT height
,
6351 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6354 return InvalidParameter
;
6359 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
6362 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
6368 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
6370 if(!graphics
|| !region
)
6371 return InvalidParameter
;
6376 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6378 status
= METAFILE_SetClipRegion((GpMetafile
*)graphics
->image
, region
, mode
);
6383 status
= GdipCloneRegion(region
, &clip
);
6386 GpMatrix world_to_device
;
6388 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6389 status
= GdipTransformRegion(clip
, &world_to_device
);
6391 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
6393 GdipDeleteRegion(clip
);
6398 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
6404 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
6406 if(!graphics
|| !pen
|| count
<=0)
6407 return InvalidParameter
;
6412 status
= GdipCreatePath(FillModeAlternate
, &path
);
6413 if (status
!= Ok
) return status
;
6415 status
= GdipAddPathPolygon(path
, points
, count
);
6417 status
= GdipDrawPath(graphics
, pen
, path
);
6419 GdipDeletePath(path
);
6424 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
6431 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
6433 if(count
<=0) return InvalidParameter
;
6434 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6436 for(i
= 0;i
< count
; i
++){
6437 ptf
[i
].X
= (REAL
)points
[i
].X
;
6438 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
6441 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
6447 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
6449 TRACE("(%p, %p)\n", graphics
, dpi
);
6451 if(!graphics
|| !dpi
)
6452 return InvalidParameter
;
6457 *dpi
= graphics
->xres
;
6461 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
6463 TRACE("(%p, %p)\n", graphics
, dpi
);
6465 if(!graphics
|| !dpi
)
6466 return InvalidParameter
;
6471 *dpi
= graphics
->yres
;
6475 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
6476 GpMatrixOrder order
)
6481 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
6483 if(!graphics
|| !matrix
)
6484 return InvalidParameter
;
6489 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6490 ret
= METAFILE_MultiplyWorldTransform((GpMetafile
*)graphics
->image
, matrix
, order
);
6496 m
= graphics
->worldtrans
;
6498 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
6500 graphics
->worldtrans
= m
;
6505 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
6506 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
6508 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
6512 TRACE("(%p, %p)\n", graphics
, hdc
);
6514 if(!graphics
|| !hdc
)
6515 return InvalidParameter
;
6520 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6522 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
6524 else if (!graphics
->hdc
||
6525 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
6527 /* Create a fake HDC and fill it with a constant color. */
6531 BITMAPINFOHEADER bmih
;
6534 stat
= get_graphics_bounds(graphics
, &bounds
);
6538 graphics
->temp_hbitmap_width
= bounds
.Width
;
6539 graphics
->temp_hbitmap_height
= bounds
.Height
;
6541 bmih
.biSize
= sizeof(bmih
);
6542 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
6543 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
6545 bmih
.biBitCount
= 32;
6546 bmih
.biCompression
= BI_RGB
;
6547 bmih
.biSizeImage
= 0;
6548 bmih
.biXPelsPerMeter
= 0;
6549 bmih
.biYPelsPerMeter
= 0;
6551 bmih
.biClrImportant
= 0;
6553 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
6554 (void**)&graphics
->temp_bits
, NULL
, 0);
6556 return GenericError
;
6558 temp_hdc
= CreateCompatibleDC(0);
6561 DeleteObject(hbitmap
);
6562 return GenericError
;
6565 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6566 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
6568 SelectObject(temp_hdc
, hbitmap
);
6570 graphics
->temp_hbitmap
= hbitmap
;
6571 *hdc
= graphics
->temp_hdc
= temp_hdc
;
6575 *hdc
= graphics
->hdc
;
6579 graphics
->busy
= TRUE
;
6584 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
6588 TRACE("(%p, %p)\n", graphics
, hdc
);
6590 if(!graphics
|| !hdc
|| !graphics
->busy
)
6591 return InvalidParameter
;
6593 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6595 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
6597 else if (graphics
->temp_hdc
== hdc
)
6602 /* Find the pixels that have changed, and mark them as opaque. */
6603 pos
= (DWORD
*)graphics
->temp_bits
;
6604 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6606 if (*pos
!= DC_BACKGROUND_KEY
)
6613 /* Write the changed pixels to the real target. */
6614 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
6615 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
6616 graphics
->temp_hbitmap_width
* 4, PixelFormat32bppARGB
);
6619 DeleteDC(graphics
->temp_hdc
);
6620 DeleteObject(graphics
->temp_hbitmap
);
6621 graphics
->temp_hdc
= NULL
;
6622 graphics
->temp_hbitmap
= NULL
;
6624 else if (hdc
!= graphics
->hdc
)
6626 stat
= InvalidParameter
;
6630 graphics
->busy
= FALSE
;
6635 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
6639 GpMatrix device_to_world
;
6641 TRACE("(%p, %p)\n", graphics
, region
);
6643 if(!graphics
|| !region
)
6644 return InvalidParameter
;
6649 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
6652 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
6653 status
= GdipTransformRegion(clip
, &device_to_world
);
6656 GdipDeleteRegion(clip
);
6660 /* free everything except root node and header */
6661 delete_element(®ion
->node
);
6662 memcpy(region
, clip
, sizeof(GpRegion
));
6668 GpStatus
gdi_transform_acquire(GpGraphics
*graphics
)
6670 if (graphics
->gdi_transform_acquire_count
== 0 && graphics
->hdc
)
6672 graphics
->gdi_transform_save
= SaveDC(graphics
->hdc
);
6673 SetGraphicsMode(graphics
->hdc
, GM_COMPATIBLE
);
6674 SetMapMode(graphics
->hdc
, MM_TEXT
);
6675 SetWindowOrgEx(graphics
->hdc
, 0, 0, NULL
);
6676 SetViewportOrgEx(graphics
->hdc
, 0, 0, NULL
);
6678 graphics
->gdi_transform_acquire_count
++;
6682 GpStatus
gdi_transform_release(GpGraphics
*graphics
)
6684 if (graphics
->gdi_transform_acquire_count
<= 0)
6686 ERR("called without matching gdi_transform_acquire\n");
6687 return GenericError
;
6689 if (graphics
->gdi_transform_acquire_count
== 1 && graphics
->hdc
)
6691 RestoreDC(graphics
->hdc
, graphics
->gdi_transform_save
);
6693 graphics
->gdi_transform_acquire_count
--;
6697 GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6698 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
6701 REAL scale_x
, scale_y
;
6703 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
6705 if (dst_space
!= src_space
)
6707 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
6708 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
6710 if(graphics
->unit
!= UnitDisplay
)
6712 scale_x
*= graphics
->scale
;
6713 scale_y
*= graphics
->scale
;
6716 if (dst_space
< src_space
)
6718 /* transform towards world space */
6719 switch ((int)src_space
)
6721 case WineCoordinateSpaceGdiDevice
:
6724 gdixform
= graphics
->gdi_transform
;
6725 stat
= GdipInvertMatrix(&gdixform
);
6728 GdipMultiplyMatrix(matrix
, &gdixform
, MatrixOrderAppend
);
6729 if (dst_space
== CoordinateSpaceDevice
)
6731 /* else fall-through */
6733 case CoordinateSpaceDevice
:
6734 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
6735 if (dst_space
== CoordinateSpacePage
)
6737 /* else fall-through */
6738 case CoordinateSpacePage
:
6740 GpMatrix inverted_transform
= graphics
->worldtrans
;
6741 stat
= GdipInvertMatrix(&inverted_transform
);
6743 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
6750 /* transform towards device space */
6751 switch ((int)src_space
)
6753 case CoordinateSpaceWorld
:
6754 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
6755 if (dst_space
== CoordinateSpacePage
)
6757 /* else fall-through */
6758 case CoordinateSpacePage
:
6759 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
6760 if (dst_space
== CoordinateSpaceDevice
)
6762 /* else fall-through */
6763 case CoordinateSpaceDevice
:
6765 GdipMultiplyMatrix(matrix
, &graphics
->gdi_transform
, MatrixOrderAppend
);
6774 GpStatus
gdip_transform_points(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6775 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6780 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6781 if (stat
!= Ok
) return stat
;
6783 return GdipTransformMatrixPoints(&matrix
, points
, count
);
6786 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6787 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6789 if(!graphics
|| !points
|| count
<= 0 ||
6790 dst_space
< 0 || dst_space
> CoordinateSpaceDevice
||
6791 src_space
< 0 || src_space
> CoordinateSpaceDevice
)
6792 return InvalidParameter
;
6797 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6799 if (src_space
== dst_space
) return Ok
;
6801 return gdip_transform_points(graphics
, dst_space
, src_space
, points
, count
);
6804 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6805 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6811 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6814 return InvalidParameter
;
6816 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6820 for(i
= 0; i
< count
; i
++){
6821 pointsF
[i
].X
= (REAL
)points
[i
].X
;
6822 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
6825 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6828 for(i
= 0; i
< count
; i
++){
6829 points
[i
].X
= gdip_round(pointsF
[i
].X
);
6830 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
6837 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6849 /*****************************************************************************
6850 * GdipTranslateClip [GDIPLUS.@]
6852 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6854 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6857 return InvalidParameter
;
6862 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6865 /*****************************************************************************
6866 * GdipTranslateClipI [GDIPLUS.@]
6868 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6870 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6873 return InvalidParameter
;
6878 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6882 /*****************************************************************************
6883 * GdipMeasureDriverString [GDIPLUS.@]
6885 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6886 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6887 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6889 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6892 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6894 TEXTMETRICW textmetric
;
6895 const WORD
*glyph_indices
;
6896 WORD
*dynamic_glyph_indices
=NULL
;
6897 REAL rel_width
, rel_height
, ascent
, descent
;
6900 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6902 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6903 return InvalidParameter
;
6906 length
= strlenW(text
);
6910 boundingBox
->X
= 0.0;
6911 boundingBox
->Y
= 0.0;
6912 boundingBox
->Width
= 0.0;
6913 boundingBox
->Height
= 0.0;
6916 if (flags
& unsupported_flags
)
6917 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6919 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6921 hdc
= CreateCompatibleDC(0);
6922 SelectObject(hdc
, hfont
);
6924 GetTextMetricsW(hdc
, &textmetric
);
6934 GpMatrix xform
= *matrix
;
6935 GdipTransformMatrixPoints(&xform
, pt
, 3);
6937 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
6938 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6939 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6940 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6941 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6943 if (flags
& DriverStringOptionsCmapLookup
)
6945 glyph_indices
= dynamic_glyph_indices
= heap_alloc_zero(sizeof(WORD
) * length
);
6949 DeleteObject(hfont
);
6953 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6956 glyph_indices
= text
;
6958 min_x
= max_x
= x
= positions
[0].X
;
6959 min_y
= max_y
= y
= positions
[0].Y
;
6961 ascent
= textmetric
.tmAscent
/ rel_height
;
6962 descent
= textmetric
.tmDescent
/ rel_height
;
6964 for (i
=0; i
<length
; i
++)
6969 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6975 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6976 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6978 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6979 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6980 if (min_x
> x
) min_x
= x
;
6982 x
+= char_width
/ rel_width
;
6984 if (max_x
< x
) max_x
= x
;
6987 heap_free(dynamic_glyph_indices
);
6989 DeleteObject(hfont
);
6991 boundingBox
->X
= min_x
;
6992 boundingBox
->Y
= min_y
;
6993 boundingBox
->Width
= max_x
- min_x
;
6994 boundingBox
->Height
= max_y
- min_y
;
6999 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7000 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7001 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7002 INT flags
, GDIPCONST GpMatrix
*matrix
)
7004 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
7012 if (flags
& unsupported_flags
)
7013 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
7015 if (!(flags
& DriverStringOptionsCmapLookup
))
7016 eto_flags
|= ETO_GLYPH_INDEX
;
7018 save_state
= SaveDC(graphics
->hdc
);
7019 SetBkMode(graphics
->hdc
, TRANSPARENT
);
7020 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
7022 status
= get_clip_hrgn(graphics
, &hrgn
);
7026 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_COPY
);
7031 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, &pt
, 1);
7033 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
7034 SelectObject(graphics
->hdc
, hfont
);
7036 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
7038 gdi_transform_acquire(graphics
);
7040 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
7042 gdi_transform_release(graphics
);
7044 RestoreDC(graphics
->hdc
, save_state
);
7046 DeleteObject(hfont
);
7051 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7052 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7053 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7054 INT flags
, GDIPCONST GpMatrix
*matrix
)
7056 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
7058 PointF
*real_positions
, real_position
;
7062 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
7063 DWORD max_glyphsize
=0;
7064 GLYPHMETRICS glyphmetrics
;
7065 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
7068 int text_mask_stride
;
7070 int pixel_data_stride
;
7072 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
7077 if (!(flags
& DriverStringOptionsCmapLookup
))
7078 ggo_flags
|= GGO_GLYPH_INDEX
;
7080 if (flags
& unsupported_flags
)
7081 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
7083 pti
= heap_alloc_zero(sizeof(POINT
) * length
);
7087 if (flags
& DriverStringOptionsRealizedAdvance
)
7089 real_position
= positions
[0];
7091 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, &real_position
, 1);
7092 round_points(pti
, &real_position
, 1);
7096 real_positions
= heap_alloc_zero(sizeof(PointF
) * length
);
7097 if (!real_positions
)
7103 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
7105 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, real_positions
, length
);
7106 round_points(pti
, real_positions
, length
);
7108 heap_free(real_positions
);
7111 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
7113 hdc
= CreateCompatibleDC(0);
7114 SelectObject(hdc
, hfont
);
7116 /* Get the boundaries of the text to be drawn */
7117 for (i
=0; i
<length
; i
++)
7120 int left
, top
, right
, bottom
;
7122 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
7123 &glyphmetrics
, 0, NULL
, &identity
);
7125 if (glyphsize
== GDI_ERROR
)
7127 ERR("GetGlyphOutlineW failed\n");
7130 DeleteObject(hfont
);
7131 return GenericError
;
7134 if (glyphsize
> max_glyphsize
)
7135 max_glyphsize
= glyphsize
;
7139 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7140 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7141 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
7142 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
7144 if (left
< min_x
) min_x
= left
;
7145 if (top
< min_y
) min_y
= top
;
7146 if (right
> max_x
) max_x
= right
;
7147 if (bottom
> max_y
) max_y
= bottom
;
7150 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
7152 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
7153 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
7157 if (max_glyphsize
== 0)
7158 /* Nothing to draw. */
7161 glyph_mask
= heap_alloc_zero(max_glyphsize
);
7162 text_mask
= heap_alloc_zero((max_x
- min_x
) * (max_y
- min_y
));
7163 text_mask_stride
= max_x
- min_x
;
7165 if (!(glyph_mask
&& text_mask
))
7167 heap_free(glyph_mask
);
7168 heap_free(text_mask
);
7171 DeleteObject(hfont
);
7175 /* Generate a mask for the text */
7176 for (i
=0; i
<length
; i
++)
7179 int left
, top
, stride
;
7181 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
7182 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
7184 if (ret
== GDI_ERROR
|| ret
== 0)
7185 continue; /* empty glyph */
7187 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7188 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7189 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
7191 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
7193 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
7194 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
7195 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
7197 *text_val
= min(64, *text_val
+ *glyph_val
);
7206 DeleteObject(hfont
);
7207 heap_free(glyph_mask
);
7209 /* get the brush data */
7210 pixel_data
= heap_alloc_zero(4 * (max_x
- min_x
) * (max_y
- min_y
));
7213 heap_free(text_mask
);
7217 pixel_area
.X
= min_x
;
7218 pixel_area
.Y
= min_y
;
7219 pixel_area
.Width
= max_x
- min_x
;
7220 pixel_area
.Height
= max_y
- min_y
;
7221 pixel_data_stride
= pixel_area
.Width
* 4;
7223 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
7226 heap_free(text_mask
);
7227 heap_free(pixel_data
);
7231 /* multiply the brush data by the mask */
7232 for (y
=0; y
<pixel_area
.Height
; y
++)
7234 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
7235 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
7236 for (x
=0; x
<pixel_area
.Width
; x
++)
7238 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
7244 heap_free(text_mask
);
7246 gdi_transform_acquire(graphics
);
7248 /* draw the result */
7249 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
7250 pixel_area
.Height
, pixel_data_stride
, PixelFormat32bppARGB
);
7252 gdi_transform_release(graphics
);
7254 heap_free(pixel_data
);
7259 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7260 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7261 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7262 INT flags
, GDIPCONST GpMatrix
*matrix
)
7264 GpStatus stat
= NotImplemented
;
7267 length
= strlenW(text
);
7269 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
7270 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
7271 brush
->bt
== BrushTypeSolidColor
&&
7272 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
7273 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7274 brush
, positions
, flags
, matrix
);
7275 if (stat
== NotImplemented
)
7276 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7277 brush
, positions
, flags
, matrix
);
7281 /*****************************************************************************
7282 * GdipDrawDriverString [GDIPLUS.@]
7284 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7285 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
7286 GDIPCONST PointF
*positions
, INT flags
,
7287 GDIPCONST GpMatrix
*matrix
)
7289 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
7291 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
7292 return InvalidParameter
;
7294 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
7295 brush
, positions
, flags
, matrix
);
7298 /*****************************************************************************
7299 * GdipIsVisibleClipEmpty [GDIPLUS.@]
7301 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
7306 TRACE("(%p, %p)\n", graphics
, res
);
7308 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
7311 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
7314 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
7317 GdipDeleteRegion(rgn
);
7321 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
7325 TRACE("(%p) stub\n", graphics
);
7328 FIXME("not implemented\n");
7330 return NotImplemented
;
7333 GpStatus WINGDIPAPI
GdipGraphicsSetAbort(GpGraphics
*graphics
, GdiplusAbort
*pabort
)
7335 TRACE("(%p, %p)\n", graphics
, pabort
);
7338 return InvalidParameter
;
7341 FIXME("Abort callback is not supported.\n");