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
;
254 if(pen
->dash
== DashStyleCustom
){
255 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
257 TRACE("dashes are: ");
258 for(i
= 0; i
< numdashes
; i
++){
259 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
260 TRACE("%d, ", dash_array
[i
]);
262 TRACE("\n and the pen style is %x\n", pen
->style
);
264 create_gdi_logbrush(pen
->brush
, &lb
);
265 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
266 numdashes
, dash_array
);
267 free_gdi_logbrush(&lb
);
271 create_gdi_logbrush(pen
->brush
, &lb
);
272 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
273 free_gdi_logbrush(&lb
);
276 SelectObject(graphics
->hdc
, gdipen
);
281 static void restore_dc(GpGraphics
*graphics
, INT state
)
283 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
284 RestoreDC(graphics
->hdc
, state
);
287 /* This helper applies all the changes that the points listed in ptf need in
288 * order to be drawn on the device context. In the end, this should include at
290 * -scaling by page unit
291 * -applying world transformation
292 * -converting from float to int
293 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
294 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
295 * gdi to draw, and these functions would irreparably mess with line widths.
297 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
298 GpPointF
*ptf
, INT count
)
300 REAL scale_x
, scale_y
;
304 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
305 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
307 /* apply page scale */
308 if(graphics
->unit
!= UnitDisplay
)
310 scale_x
*= graphics
->scale
;
311 scale_y
*= graphics
->scale
;
314 matrix
= graphics
->worldtrans
;
315 GdipScaleMatrix(&matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
316 GdipTransformMatrixPoints(&matrix
, ptf
, count
);
318 for(i
= 0; i
< count
; i
++){
319 pti
[i
].x
= gdip_round(ptf
[i
].X
);
320 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
324 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
325 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
327 if (GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
) == DT_RASPRINTER
&&
328 GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
330 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
332 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
333 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
339 bf
.BlendOp
= AC_SRC_OVER
;
341 bf
.SourceConstantAlpha
= 255;
342 bf
.AlphaFormat
= AC_SRC_ALPHA
;
344 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
345 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
349 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
351 /* clipping region is in device coords */
352 return GdipGetRegionHRgn(graphics
->clip
, NULL
, hrgn
);
355 /* Draw ARGB data to the given graphics object */
356 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
357 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, const PixelFormat fmt
)
359 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
362 for (y
=0; y
<src_height
; y
++)
364 for (x
=0; x
<src_width
; x
++)
366 ARGB dst_color
, src_color
;
367 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
369 if (!(src_color
& 0xff000000))
372 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
373 if (fmt
& PixelFormatPAlpha
)
374 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over_fgpremult(dst_color
, src_color
));
376 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
383 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
384 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
388 BITMAPINFOHEADER bih
;
391 hdc
= CreateCompatibleDC(0);
393 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
394 bih
.biWidth
= src_width
;
395 bih
.biHeight
= -src_height
;
398 bih
.biCompression
= BI_RGB
;
400 bih
.biXPelsPerMeter
= 0;
401 bih
.biYPelsPerMeter
= 0;
403 bih
.biClrImportant
= 0;
405 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
406 (void**)&temp_bits
, NULL
, 0);
408 if ((GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
) == DT_RASPRINTER
&&
409 GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
) ||
410 fmt
& PixelFormatPAlpha
)
411 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
413 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
414 4 * src_width
, src
, src_stride
);
416 SelectObject(hdc
, hbitmap
);
417 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
418 hdc
, 0, 0, src_width
, src_height
);
420 DeleteObject(hbitmap
);
425 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
426 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
, PixelFormat fmt
)
430 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
436 HRGN hrgn
, visible_rgn
;
438 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
442 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
451 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
452 DeleteObject(visible_rgn
);
456 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
458 size
= GetRegionData(hrgn
, 0, NULL
);
460 rgndata
= heap_alloc_zero(size
);
467 GetRegionData(hrgn
, size
, rgndata
);
469 rects
= (RECT
*)rgndata
->Buffer
;
471 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
473 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
474 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
475 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
485 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
487 ERR("This should not be used for metafiles; fix caller\n");
488 return NotImplemented
;
495 stat
= get_clip_hrgn(graphics
, &hrgn
);
500 save
= SaveDC(graphics
->hdc
);
503 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
506 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
508 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
509 src_height
, src_stride
, fmt
);
511 RestoreDC(graphics
->hdc
, save
);
519 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
520 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
522 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
, fmt
);
525 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
527 INT start_a
, end_a
, final_a
;
530 pos
= gdip_round(position
* 0xff);
532 start_a
= ((start
>> 24) & 0xff) * (pos
^ 0xff);
533 end_a
= ((end
>> 24) & 0xff) * pos
;
535 final_a
= start_a
+ end_a
;
537 if (final_a
< 0xff) return 0;
539 return (final_a
/ 0xff) << 24 |
540 ((((start
>> 16) & 0xff) * start_a
+ (((end
>> 16) & 0xff) * end_a
)) / final_a
) << 16 |
541 ((((start
>> 8) & 0xff) * start_a
+ (((end
>> 8) & 0xff) * end_a
)) / final_a
) << 8 |
542 (((start
& 0xff) * start_a
+ ((end
& 0xff) * end_a
)) / final_a
);
545 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
549 /* clamp to between 0.0 and 1.0, using the wrap mode */
550 position
= (position
- brush
->rect
.X
) / brush
->rect
.Width
;
551 if (brush
->wrap
== WrapModeTile
)
553 position
= fmodf(position
, 1.0f
);
554 if (position
< 0.0f
) position
+= 1.0f
;
556 else /* WrapModeFlip* */
558 position
= fmodf(position
, 2.0f
);
559 if (position
< 0.0f
) position
+= 2.0f
;
560 if (position
> 1.0f
) position
= 2.0f
- position
;
563 if (brush
->blendcount
== 1)
568 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
571 /* locate the blend positions surrounding this position */
572 while (position
> brush
->blendpos
[i
])
575 /* interpolate between the blend positions */
576 left_blendpos
= brush
->blendpos
[i
-1];
577 left_blendfac
= brush
->blendfac
[i
-1];
578 right_blendpos
= brush
->blendpos
[i
];
579 right_blendfac
= brush
->blendfac
[i
];
580 range
= right_blendpos
- left_blendpos
;
581 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
582 right_blendfac
* (position
- left_blendpos
)) / range
;
585 if (brush
->pblendcount
== 0)
586 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
590 ARGB left_blendcolor
, right_blendcolor
;
591 REAL left_blendpos
, right_blendpos
;
593 /* locate the blend colors surrounding this position */
594 while (blendfac
> brush
->pblendpos
[i
])
597 /* interpolate between the blend colors */
598 left_blendpos
= brush
->pblendpos
[i
-1];
599 left_blendcolor
= brush
->pblendcolor
[i
-1];
600 right_blendpos
= brush
->pblendpos
[i
];
601 right_blendcolor
= brush
->pblendcolor
[i
];
602 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
603 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
607 static BOOL
round_color_matrix(const ColorMatrix
*matrix
, int values
[5][5])
609 /* Convert floating point color matrix to int[5][5], return TRUE if it's an identity */
610 BOOL identity
= TRUE
;
616 if (matrix
->m
[j
][i
] != (i
== j
? 1.0 : 0.0))
618 values
[j
][i
] = gdip_round(matrix
->m
[j
][i
] * 256.0);
624 static ARGB
transform_color(ARGB color
, int matrix
[5][5])
628 unsigned char a
, r
, g
, b
;
630 val
[0] = ((color
>> 16) & 0xff); /* red */
631 val
[1] = ((color
>> 8) & 0xff); /* green */
632 val
[2] = (color
& 0xff); /* blue */
633 val
[3] = ((color
>> 24) & 0xff); /* alpha */
634 val
[4] = 255; /* translation */
641 res
[i
] += matrix
[j
][i
] * val
[j
];
644 a
= min(max(res
[3] / 256, 0), 255);
645 r
= min(max(res
[0] / 256, 0), 255);
646 g
= min(max(res
[1] / 256, 0), 255);
647 b
= min(max(res
[2] / 256, 0), 255);
649 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
652 static BOOL
color_is_gray(ARGB color
)
654 unsigned char r
, g
, b
;
656 r
= (color
>> 16) & 0xff;
657 g
= (color
>> 8) & 0xff;
660 return (r
== g
) && (g
== b
);
663 /* returns preferred pixel format for the applied attributes */
664 PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
665 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
)
670 if (attributes
->colorkeys
[type
].enabled
||
671 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
673 const struct color_key
*key
;
674 BYTE min_blue
, min_green
, min_red
;
675 BYTE max_blue
, max_green
, max_red
;
677 if (!data
|| fmt
!= PixelFormat32bppARGB
)
678 return PixelFormat32bppARGB
;
680 if (attributes
->colorkeys
[type
].enabled
)
681 key
= &attributes
->colorkeys
[type
];
683 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
685 min_blue
= key
->low
&0xff;
686 min_green
= (key
->low
>>8)&0xff;
687 min_red
= (key
->low
>>16)&0xff;
689 max_blue
= key
->high
&0xff;
690 max_green
= (key
->high
>>8)&0xff;
691 max_red
= (key
->high
>>16)&0xff;
693 for (x
=0; x
<width
; x
++)
694 for (y
=0; y
<height
; y
++)
697 BYTE blue
, green
, red
;
698 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
699 blue
= *src_color
&0xff;
700 green
= (*src_color
>>8)&0xff;
701 red
= (*src_color
>>16)&0xff;
702 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
703 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
704 *src_color
= 0x00000000;
708 if (attributes
->colorremaptables
[type
].enabled
||
709 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
711 const struct color_remap_table
*table
;
713 if (!data
|| fmt
!= PixelFormat32bppARGB
)
714 return PixelFormat32bppARGB
;
716 if (attributes
->colorremaptables
[type
].enabled
)
717 table
= &attributes
->colorremaptables
[type
];
719 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
721 for (x
=0; x
<width
; x
++)
722 for (y
=0; y
<height
; y
++)
725 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
726 for (i
=0; i
<table
->mapsize
; i
++)
728 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
730 *src_color
= table
->colormap
[i
].newColor
.Argb
;
737 if (attributes
->colormatrices
[type
].enabled
||
738 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
740 const struct color_matrix
*colormatrices
;
741 int color_matrix
[5][5];
742 int gray_matrix
[5][5];
745 if (!data
|| fmt
!= PixelFormat32bppARGB
)
746 return PixelFormat32bppARGB
;
748 if (attributes
->colormatrices
[type
].enabled
)
749 colormatrices
= &attributes
->colormatrices
[type
];
751 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
753 identity
= round_color_matrix(&colormatrices
->colormatrix
, color_matrix
);
755 if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
756 identity
= (round_color_matrix(&colormatrices
->graymatrix
, gray_matrix
) && identity
);
760 for (x
=0; x
<width
; x
++)
762 for (y
=0; y
<height
; y
++)
765 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
767 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
768 !color_is_gray(*src_color
))
770 *src_color
= transform_color(*src_color
, color_matrix
);
772 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
774 *src_color
= transform_color(*src_color
, gray_matrix
);
781 if (attributes
->gamma_enabled
[type
] ||
782 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
786 if (!data
|| fmt
!= PixelFormat32bppARGB
)
787 return PixelFormat32bppARGB
;
789 if (attributes
->gamma_enabled
[type
])
790 gamma
= attributes
->gamma
[type
];
792 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
794 for (x
=0; x
<width
; x
++)
795 for (y
=0; y
<height
; y
++)
798 BYTE blue
, green
, red
;
799 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
801 blue
= *src_color
&0xff;
802 green
= (*src_color
>>8)&0xff;
803 red
= (*src_color
>>16)&0xff;
805 /* FIXME: We should probably use a table for this. */
806 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
807 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
808 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
810 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
817 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
818 * bitmap that contains all the pixels we may need to draw it. */
819 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
820 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
823 INT left
, top
, right
, bottom
;
825 switch (interpolation
)
827 case InterpolationModeHighQualityBilinear
:
828 case InterpolationModeHighQualityBicubic
:
829 /* FIXME: Include a greater range for the prefilter? */
830 case InterpolationModeBicubic
:
831 case InterpolationModeBilinear
:
832 left
= (INT
)(floorf(srcx
));
833 top
= (INT
)(floorf(srcy
));
834 right
= (INT
)(ceilf(srcx
+srcwidth
));
835 bottom
= (INT
)(ceilf(srcy
+srcheight
));
837 case InterpolationModeNearestNeighbor
:
839 left
= gdip_round(srcx
);
840 top
= gdip_round(srcy
);
841 right
= gdip_round(srcx
+srcwidth
);
842 bottom
= gdip_round(srcy
+srcheight
);
846 if (wrap
== WrapModeClamp
)
852 if (right
>= bitmap
->width
)
853 right
= bitmap
->width
-1;
854 if (bottom
>= bitmap
->height
)
855 bottom
= bitmap
->height
-1;
856 if (bottom
< top
|| right
< left
)
857 /* entirely outside image, just sample a pixel so we don't have to
858 * special-case this later */
859 left
= top
= right
= bottom
= 0;
863 /* In some cases we can make the rectangle smaller here, but the logic
864 * is hard to get right, and tiling suggests we're likely to use the
865 * entire source image. */
866 if (left
< 0 || right
>= bitmap
->width
)
869 right
= bitmap
->width
-1;
872 if (top
< 0 || bottom
>= bitmap
->height
)
875 bottom
= bitmap
->height
-1;
881 rect
->Width
= right
- left
+ 1;
882 rect
->Height
= bottom
- top
+ 1;
885 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
886 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
888 if (attributes
->wrap
== WrapModeClamp
)
890 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
891 return attributes
->outside_color
;
895 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
897 x
= width
*2 + x
% (width
* 2);
899 y
= height
*2 + y
% (height
* 2);
901 if ((attributes
->wrap
& 1) == 1)
904 if ((x
/ width
) % 2 == 0)
907 x
= width
- 1 - x
% width
;
912 if ((attributes
->wrap
& 2) == 2)
915 if ((y
/ height
) % 2 == 0)
918 y
= height
- 1 - y
% height
;
924 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
926 ERR("out of range pixel requested\n");
930 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
933 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
934 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
935 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
939 switch (interpolation
)
943 FIXME("Unimplemented interpolation %i\n", interpolation
);
945 case InterpolationModeBilinear
:
948 INT leftx
, rightx
, topy
, bottomy
;
949 ARGB topleft
, topright
, bottomleft
, bottomright
;
953 leftxf
= floorf(point
->X
);
955 rightx
= (INT
)ceilf(point
->X
);
956 topyf
= floorf(point
->Y
);
958 bottomy
= (INT
)ceilf(point
->Y
);
960 if (leftx
== rightx
&& topy
== bottomy
)
961 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
962 leftx
, topy
, attributes
);
964 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
965 leftx
, topy
, attributes
);
966 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
967 rightx
, topy
, attributes
);
968 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
969 leftx
, bottomy
, attributes
);
970 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
971 rightx
, bottomy
, attributes
);
973 x_offset
= point
->X
- leftxf
;
974 top
= blend_colors(topleft
, topright
, x_offset
);
975 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
977 return blend_colors(top
, bottom
, point
->Y
- topyf
);
979 case InterpolationModeNearestNeighbor
:
985 case PixelOffsetModeNone
:
986 case PixelOffsetModeHighSpeed
:
990 case PixelOffsetModeHalf
:
991 case PixelOffsetModeHighQuality
:
995 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
996 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
1002 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
1004 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
1007 /* is_fill is TRUE if filling regions, FALSE for drawing primitives */
1008 static BOOL
brush_can_fill_path(GpBrush
*brush
, BOOL is_fill
)
1012 case BrushTypeSolidColor
:
1018 /* cannot draw semi-transparent colors */
1019 return (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000;
1022 case BrushTypeHatchFill
:
1024 GpHatch
*hatch
= (GpHatch
*)brush
;
1025 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
1026 ((hatch
->backcol
& 0xff000000) == 0xff000000);
1028 case BrushTypeLinearGradient
:
1029 case BrushTypeTextureFill
:
1030 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
1036 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
1040 case BrushTypeSolidColor
:
1042 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1043 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1048 /* partially transparent fill */
1050 SelectClipPath(graphics
->hdc
, RGN_AND
);
1051 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1053 HDC hdc
= CreateCompatibleDC(NULL
);
1057 SelectObject(hdc
, bmp
);
1058 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1066 /* else fall through */
1070 HBRUSH gdibrush
, old_brush
;
1072 gdibrush
= create_gdi_brush(brush
);
1073 if (!gdibrush
) return;
1075 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1076 FillPath(graphics
->hdc
);
1077 SelectObject(graphics
->hdc
, old_brush
);
1078 DeleteObject(gdibrush
);
1084 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1088 case BrushTypeSolidColor
:
1089 case BrushTypeHatchFill
:
1090 case BrushTypeLinearGradient
:
1091 case BrushTypeTextureFill
:
1092 case BrushTypePathGradient
:
1099 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1100 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1104 case BrushTypeSolidColor
:
1107 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1108 for (x
=0; x
<fill_area
->Width
; x
++)
1109 for (y
=0; y
<fill_area
->Height
; y
++)
1110 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1113 case BrushTypeHatchFill
:
1116 GpHatch
*fill
= (GpHatch
*)brush
;
1117 const char *hatch_data
;
1119 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1120 return NotImplemented
;
1122 for (x
=0; x
<fill_area
->Width
; x
++)
1123 for (y
=0; y
<fill_area
->Height
; y
++)
1127 /* FIXME: Account for the rendering origin */
1128 hx
= (x
+ fill_area
->X
) % 8;
1129 hy
= (y
+ fill_area
->Y
) % 8;
1131 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1132 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1134 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1139 case BrushTypeLinearGradient
:
1141 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1142 GpPointF draw_points
[3];
1146 draw_points
[0].X
= fill_area
->X
;
1147 draw_points
[0].Y
= fill_area
->Y
;
1148 draw_points
[1].X
= fill_area
->X
+1;
1149 draw_points
[1].Y
= fill_area
->Y
;
1150 draw_points
[2].X
= fill_area
->X
;
1151 draw_points
[2].Y
= fill_area
->Y
+1;
1153 /* Transform the points to a co-ordinate space where X is the point's
1154 * position in the gradient, 0.0 being the start point and 1.0 the
1156 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1157 CoordinateSpaceDevice
, draw_points
, 3);
1161 GpMatrix world_to_gradient
= fill
->transform
;
1163 stat
= GdipInvertMatrix(&world_to_gradient
);
1165 stat
= GdipTransformMatrixPoints(&world_to_gradient
, draw_points
, 3);
1170 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1171 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1173 for (y
=0; y
<fill_area
->Height
; y
++)
1175 for (x
=0; x
<fill_area
->Width
; x
++)
1177 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1179 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1186 case BrushTypeTextureFill
:
1188 GpTexture
*fill
= (GpTexture
*)brush
;
1189 GpPointF draw_points
[3];
1196 if (fill
->image
->type
!= ImageTypeBitmap
)
1198 FIXME("metafile texture brushes not implemented\n");
1199 return NotImplemented
;
1202 bitmap
= (GpBitmap
*)fill
->image
;
1203 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1205 src_area
.X
= src_area
.Y
= 0;
1206 src_area
.Width
= bitmap
->width
;
1207 src_area
.Height
= bitmap
->height
;
1209 draw_points
[0].X
= fill_area
->X
;
1210 draw_points
[0].Y
= fill_area
->Y
;
1211 draw_points
[1].X
= fill_area
->X
+1;
1212 draw_points
[1].Y
= fill_area
->Y
;
1213 draw_points
[2].X
= fill_area
->X
;
1214 draw_points
[2].Y
= fill_area
->Y
+1;
1216 /* Transform the points to the co-ordinate space of the bitmap. */
1217 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1218 CoordinateSpaceDevice
, draw_points
, 3);
1222 GpMatrix world_to_texture
= fill
->transform
;
1224 stat
= GdipInvertMatrix(&world_to_texture
);
1226 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1229 if (stat
== Ok
&& !fill
->bitmap_bits
)
1231 BitmapData lockeddata
;
1233 fill
->bitmap_bits
= heap_alloc_zero(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1234 if (!fill
->bitmap_bits
)
1239 lockeddata
.Width
= bitmap
->width
;
1240 lockeddata
.Height
= bitmap
->height
;
1241 lockeddata
.Stride
= src_stride
;
1242 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1243 lockeddata
.Scan0
= fill
->bitmap_bits
;
1245 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1246 PixelFormat32bppARGB
, &lockeddata
);
1250 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1253 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1254 bitmap
->width
, bitmap
->height
,
1255 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
1259 heap_free(fill
->bitmap_bits
);
1260 fill
->bitmap_bits
= NULL
;
1266 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1267 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1268 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1269 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1271 for (y
=0; y
<fill_area
->Height
; y
++)
1273 for (x
=0; x
<fill_area
->Width
; x
++)
1276 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1277 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1279 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1280 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1281 &point
, fill
->imageattributes
, graphics
->interpolation
,
1282 graphics
->pixeloffset
);
1289 case BrushTypePathGradient
:
1291 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1293 GpMatrix world_to_device
;
1295 int i
, figure_start
=0;
1296 GpPointF start_point
, end_point
, center_point
;
1298 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1299 INT min_y
, max_y
, min_x
, max_x
;
1302 static BOOL transform_fixme_once
;
1304 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1308 FIXME("path gradient focus not implemented\n");
1315 FIXME("path gradient gamma correction not implemented\n");
1318 if (fill
->blendcount
)
1322 FIXME("path gradient blend not implemented\n");
1325 if (fill
->pblendcount
)
1329 FIXME("path gradient preset blend not implemented\n");
1332 if (!transform_fixme_once
)
1334 BOOL is_identity
=TRUE
;
1335 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1338 FIXME("path gradient transform not implemented\n");
1339 transform_fixme_once
= TRUE
;
1343 stat
= GdipClonePath(fill
->path
, &flat_path
);
1348 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1349 CoordinateSpaceWorld
, &world_to_device
);
1352 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1356 center_point
= fill
->center
;
1357 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1361 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1366 GdipDeletePath(flat_path
);
1370 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1372 int start_center_line
=0, end_center_line
=0;
1373 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1374 REAL center_distance
;
1375 ARGB start_color
, end_color
;
1378 type
= flat_path
->pathdata
.Types
[i
];
1380 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1383 start_point
= flat_path
->pathdata
.Points
[i
];
1385 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1387 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1389 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1390 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1392 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1394 end_point
= flat_path
->pathdata
.Points
[i
+1];
1395 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1400 outer_color
= start_color
;
1402 min_yf
= center_point
.Y
;
1403 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1404 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1406 if (min_yf
< fill_area
->Y
)
1407 min_y
= fill_area
->Y
;
1409 min_y
= (INT
)ceil(min_yf
);
1411 max_yf
= center_point
.Y
;
1412 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1413 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1415 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1416 max_y
= fill_area
->Y
+ fill_area
->Height
;
1418 max_y
= (INT
)ceil(max_yf
);
1420 dy
= end_point
.Y
- start_point
.Y
;
1421 dx
= end_point
.X
- start_point
.X
;
1423 /* This is proportional to the distance from start-end line to center point. */
1424 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1425 dx
* (center_point
.Y
- start_point
.Y
);
1427 for (y
=min_y
; y
<max_y
; y
++)
1431 if (!seen_start
&& yf
>= start_point
.Y
)
1434 start_center_line
^= 1;
1436 if (!seen_end
&& yf
>= end_point
.Y
)
1439 end_center_line
^= 1;
1441 if (!seen_center
&& yf
>= center_point
.Y
)
1444 start_center_line
^= 1;
1445 end_center_line
^= 1;
1448 if (start_center_line
)
1449 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1451 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1453 if (end_center_line
)
1454 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1456 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1458 if (line1_xf
< line2_xf
)
1460 min_x
= (INT
)ceil(line1_xf
);
1461 max_x
= (INT
)ceil(line2_xf
);
1465 min_x
= (INT
)ceil(line2_xf
);
1466 max_x
= (INT
)ceil(line1_xf
);
1469 if (min_x
< fill_area
->X
)
1470 min_x
= fill_area
->X
;
1471 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1472 max_x
= fill_area
->X
+ fill_area
->Width
;
1474 for (x
=min_x
; x
<max_x
; x
++)
1479 if (start_color
!= end_color
)
1481 REAL blend_amount
, pdy
, pdx
;
1482 pdy
= yf
- center_point
.Y
;
1483 pdx
= xf
- center_point
.X
;
1485 if (fabs(pdx
) <= 0.001 && fabs(pdy
) <= 0.001)
1487 /* Too close to center point, don't try to calculate outer color */
1488 outer_color
= start_color
;
1492 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1493 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1497 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1498 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1500 distance
= distance
/ center_distance
;
1502 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1503 blend_colors(outer_color
, fill
->centercolor
, distance
);
1508 GdipDeletePath(flat_path
);
1512 return NotImplemented
;
1516 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1517 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1518 * should not be called on an hdc that has a path you care about. */
1519 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1520 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1522 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1524 HBRUSH brush
= NULL
;
1526 PointF ptf
[4], *custptf
= NULL
;
1527 POINT pt
[4], *custpt
= NULL
;
1529 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1534 if((x1
== x2
) && (y1
== y2
))
1537 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1539 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1541 brush
= CreateSolidBrush(color
);
1542 lb
.lbStyle
= BS_SOLID
;
1545 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1546 PS_JOIN_MITER
, 1, &lb
, 0,
1548 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1549 oldpen
= SelectObject(graphics
->hdc
, pen
);
1556 case LineCapSquareAnchor
:
1557 case LineCapDiamondAnchor
:
1558 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1559 if(cap
== LineCapDiamondAnchor
){
1560 dsmall
= cos(theta
+ M_PI_2
) * size
;
1561 dbig
= sin(theta
+ M_PI_2
) * size
;
1564 dsmall
= cos(theta
+ M_PI_4
) * size
;
1565 dbig
= sin(theta
+ M_PI_4
) * size
;
1568 ptf
[0].X
= x2
- dsmall
;
1569 ptf
[1].X
= x2
+ dbig
;
1571 ptf
[0].Y
= y2
- dbig
;
1572 ptf
[3].Y
= y2
+ dsmall
;
1574 ptf
[1].Y
= y2
- dsmall
;
1575 ptf
[2].Y
= y2
+ dbig
;
1577 ptf
[3].X
= x2
- dbig
;
1578 ptf
[2].X
= x2
+ dsmall
;
1580 transform_and_round_points(graphics
, pt
, ptf
, 4);
1581 Polygon(graphics
->hdc
, pt
, 4);
1584 case LineCapArrowAnchor
:
1585 size
= size
* 4.0 / sqrt(3.0);
1587 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1588 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1593 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1594 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1602 transform_and_round_points(graphics
, pt
, ptf
, 3);
1603 Polygon(graphics
->hdc
, pt
, 3);
1606 case LineCapRoundAnchor
:
1607 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1614 transform_and_round_points(graphics
, pt
, ptf
, 2);
1615 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1618 case LineCapTriangle
:
1620 dx
= cos(M_PI_2
+ theta
) * size
;
1621 dy
= sin(M_PI_2
+ theta
) * size
;
1628 dx
= cos(theta
) * size
;
1629 dy
= sin(theta
) * size
;
1634 transform_and_round_points(graphics
, pt
, ptf
, 3);
1635 Polygon(graphics
->hdc
, pt
, 3);
1639 dx
= dy
= size
/ 2.0;
1646 dx
= -cos(M_PI_2
+ theta
) * size
;
1647 dy
= -sin(M_PI_2
+ theta
) * size
;
1654 transform_and_round_points(graphics
, pt
, ptf
, 4);
1655 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1656 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1663 count
= custom
->pathdata
.Count
;
1664 custptf
= heap_alloc_zero(count
* sizeof(PointF
));
1665 custpt
= heap_alloc_zero(count
* sizeof(POINT
));
1666 tp
= heap_alloc_zero(count
);
1668 if(!custptf
|| !custpt
|| !tp
)
1671 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1673 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1674 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1675 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1677 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1678 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1680 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1682 for(i
= 0; i
< count
; i
++)
1683 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1686 BeginPath(graphics
->hdc
);
1687 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1688 EndPath(graphics
->hdc
);
1689 StrokeAndFillPath(graphics
->hdc
);
1692 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1704 SelectObject(graphics
->hdc
, oldbrush
);
1705 SelectObject(graphics
->hdc
, oldpen
);
1706 DeleteObject(brush
);
1711 /* Shortens the line by the given percent by changing x2, y2.
1712 * If percent is > 1.0 then the line will change direction.
1713 * If percent is negative it can lengthen the line. */
1714 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1716 REAL dist
, theta
, dx
, dy
;
1718 if((y1
== *y2
) && (x1
== *x2
))
1721 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1722 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1723 dx
= cos(theta
) * dist
;
1724 dy
= sin(theta
) * dist
;
1730 /* Shortens the line by the given amount by changing x2, y2.
1731 * If the amount is greater than the distance, the line will become length 0.
1732 * If the amount is negative, it can lengthen the line. */
1733 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1735 REAL dx
, dy
, percent
;
1739 if(dx
== 0 && dy
== 0)
1742 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1749 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1752 /* Conducts a linear search to find the bezier points that will back off
1753 * the endpoint of the curve by a distance of amt. Linear search works
1754 * better than binary in this case because there are multiple solutions,
1755 * and binary searches often find a bad one. I don't think this is what
1756 * Windows does but short of rendering the bezier without GDI's help it's
1757 * the best we can do. If rev then work from the start of the passed points
1758 * instead of the end. */
1759 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1762 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1763 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1772 origx
= pt
[fourth
].X
;
1773 origy
= pt
[fourth
].Y
;
1774 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1776 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1777 /* reset bezier points to original values */
1778 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1779 /* Perform magic on bezier points. Order is important here.*/
1780 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1781 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1782 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1783 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1784 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1785 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1787 dx
= pt
[fourth
].X
- origx
;
1788 dy
= pt
[fourth
].Y
- origy
;
1790 diff
= sqrt(dx
* dx
+ dy
* dy
);
1791 percent
+= 0.0005 * amt
;
1795 /* Draws a combination of bezier curves and lines between points. */
1796 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1797 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1799 POINT
*pti
= heap_alloc_zero(count
* sizeof(POINT
));
1800 BYTE
*tp
= heap_alloc_zero(count
);
1801 GpPointF
*ptcopy
= heap_alloc_zero(count
* sizeof(GpPointF
));
1803 GpStatus status
= GenericError
;
1809 if(!pti
|| !tp
|| !ptcopy
){
1810 status
= OutOfMemory
;
1814 for(i
= 1; i
< count
; i
++){
1815 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1816 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1817 || !(types
[i
+ 2] & PathPointTypeBezier
)){
1818 ERR("Bad bezier points\n");
1825 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1827 /* If we are drawing caps, go through the points and adjust them accordingly,
1828 * and draw the caps. */
1830 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1831 case PathPointTypeBezier
:
1832 if(pen
->endcap
== LineCapArrowAnchor
)
1833 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1834 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1835 shorten_bezier_amt(&ptcopy
[count
- 4],
1836 pen
->width
* pen
->customend
->inset
, FALSE
);
1838 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1839 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1840 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1841 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1844 case PathPointTypeLine
:
1845 if(pen
->endcap
== LineCapArrowAnchor
)
1846 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1847 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1849 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1850 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1851 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1852 pen
->customend
->inset
* pen
->width
);
1854 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1855 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1860 ERR("Bad path last point\n");
1864 /* Find start of points */
1865 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1866 == PathPointTypeStart
); j
++);
1868 switch(types
[j
] & PathPointTypePathTypeMask
){
1869 case PathPointTypeBezier
:
1870 if(pen
->startcap
== LineCapArrowAnchor
)
1871 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1872 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1873 shorten_bezier_amt(&ptcopy
[j
- 1],
1874 pen
->width
* pen
->customstart
->inset
, TRUE
);
1876 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1877 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1878 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1879 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1882 case PathPointTypeLine
:
1883 if(pen
->startcap
== LineCapArrowAnchor
)
1884 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1885 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1887 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1888 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1889 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1890 pen
->customstart
->inset
* pen
->width
);
1892 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1893 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1898 ERR("Bad path points\n");
1903 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1905 for(i
= 0; i
< count
; i
++){
1906 tp
[i
] = convert_path_point_type(types
[i
]);
1909 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1921 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1925 BeginPath(graphics
->hdc
);
1926 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1927 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1928 EndPath(graphics
->hdc
);
1932 typedef enum GraphicsContainerType
{
1935 } GraphicsContainerType
;
1937 typedef struct _GraphicsContainerItem
{
1939 GraphicsContainer contid
;
1940 GraphicsContainerType type
;
1942 SmoothingMode smoothing
;
1943 CompositingQuality compqual
;
1944 InterpolationMode interpolation
;
1945 CompositingMode compmode
;
1946 TextRenderingHint texthint
;
1949 PixelOffsetMode pixeloffset
;
1951 GpMatrix worldtrans
;
1953 INT origin_x
, origin_y
;
1954 } GraphicsContainerItem
;
1956 static GpStatus
init_container(GraphicsContainerItem
** container
,
1957 GDIPCONST GpGraphics
* graphics
, GraphicsContainerType type
){
1960 *container
= heap_alloc_zero(sizeof(GraphicsContainerItem
));
1964 (*container
)->contid
= graphics
->contid
+ 1;
1965 (*container
)->type
= type
;
1967 (*container
)->smoothing
= graphics
->smoothing
;
1968 (*container
)->compqual
= graphics
->compqual
;
1969 (*container
)->interpolation
= graphics
->interpolation
;
1970 (*container
)->compmode
= graphics
->compmode
;
1971 (*container
)->texthint
= graphics
->texthint
;
1972 (*container
)->scale
= graphics
->scale
;
1973 (*container
)->unit
= graphics
->unit
;
1974 (*container
)->textcontrast
= graphics
->textcontrast
;
1975 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1976 (*container
)->origin_x
= graphics
->origin_x
;
1977 (*container
)->origin_y
= graphics
->origin_y
;
1978 (*container
)->worldtrans
= graphics
->worldtrans
;
1980 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1982 heap_free(*container
);
1990 static void delete_container(GraphicsContainerItem
* container
)
1992 GdipDeleteRegion(container
->clip
);
1993 heap_free(container
);
1996 static GpStatus
restore_container(GpGraphics
* graphics
,
1997 GDIPCONST GraphicsContainerItem
* container
){
2001 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2002 if(sts
!= Ok
) return sts
;
2004 graphics
->worldtrans
= container
->worldtrans
;
2006 GdipDeleteRegion(graphics
->clip
);
2007 graphics
->clip
= newClip
;
2009 graphics
->contid
= container
->contid
- 1;
2011 graphics
->smoothing
= container
->smoothing
;
2012 graphics
->compqual
= container
->compqual
;
2013 graphics
->interpolation
= container
->interpolation
;
2014 graphics
->compmode
= container
->compmode
;
2015 graphics
->texthint
= container
->texthint
;
2016 graphics
->scale
= container
->scale
;
2017 graphics
->unit
= container
->unit
;
2018 graphics
->textcontrast
= container
->textcontrast
;
2019 graphics
->pixeloffset
= container
->pixeloffset
;
2020 graphics
->origin_x
= container
->origin_x
;
2021 graphics
->origin_y
= container
->origin_y
;
2026 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2032 if(graphics
->hwnd
) {
2033 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2034 return GenericError
;
2036 rect
->X
= wnd_rect
.left
;
2037 rect
->Y
= wnd_rect
.top
;
2038 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2039 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2040 }else if (graphics
->image
){
2041 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2042 if (stat
== Ok
&& unit
!= UnitPixel
)
2043 FIXME("need to convert from unit %i\n", unit
);
2044 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2051 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2052 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2054 rect
->Width
= bmp
.bmWidth
;
2055 rect
->Height
= bmp
.bmHeight
;
2066 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2067 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2074 points
[0].x
= rect
->X
;
2075 points
[0].y
= rect
->Y
;
2076 points
[1].x
= rect
->X
+ rect
->Width
;
2077 points
[1].y
= rect
->Y
+ rect
->Height
;
2079 DPtoLP(graphics
->hdc
, points
, sizeof(points
)/sizeof(points
[0]));
2081 rect
->X
= min(points
[0].x
, points
[1].x
);
2082 rect
->Y
= min(points
[0].y
, points
[1].y
);
2083 rect
->Width
= abs(points
[1].x
- points
[0].x
);
2084 rect
->Height
= abs(points
[1].y
- points
[0].y
);
2090 /* on success, rgn will contain the region of the graphics object which
2091 * is visible after clipping has been applied */
2092 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2098 /* Ignore graphics image bounds for metafiles */
2099 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2100 return GdipCombineRegionRegion(rgn
, graphics
->clip
, CombineModeReplace
);
2102 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2105 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2108 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2111 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2114 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2117 GdipDeleteRegion(tmp
);
2121 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2125 if (font
->unit
== UnitPixel
)
2127 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2131 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2132 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2134 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2137 lf
->lfHeight
= -(height
+ 0.5);
2139 lf
->lfEscapement
= 0;
2140 lf
->lfOrientation
= 0;
2141 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2142 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2143 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2144 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2145 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2146 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2147 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2148 lf
->lfQuality
= DEFAULT_QUALITY
;
2149 lf
->lfPitchAndFamily
= 0;
2150 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2153 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2154 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2155 GDIPCONST GpMatrix
*matrix
)
2157 HDC hdc
= CreateCompatibleDC(0);
2159 REAL angle
, rel_width
, rel_height
, font_height
;
2161 HFONT unscaled_font
;
2162 TEXTMETRICW textmet
;
2164 if (font
->unit
== UnitPixel
|| font
->unit
== UnitWorld
)
2165 font_height
= font
->emSize
;
2168 REAL unit_scale
, res
;
2170 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2171 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2173 font_height
= font
->emSize
* unit_scale
;
2184 GpMatrix xform
= *matrix
;
2185 GdipTransformMatrixPoints(&xform
, pt
, 3);
2188 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2189 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2190 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2191 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2192 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2193 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2195 get_log_fontW(font
, graphics
, &lfw
);
2196 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2197 unscaled_font
= CreateFontIndirectW(&lfw
);
2199 SelectObject(hdc
, unscaled_font
);
2200 GetTextMetricsW(hdc
, &textmet
);
2202 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2203 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2205 *hfont
= CreateFontIndirectW(&lfw
);
2208 DeleteObject(unscaled_font
);
2211 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2213 TRACE("(%p, %p)\n", hdc
, graphics
);
2215 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2218 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2224 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2227 FIXME("Don't know how to handle parameter hDevice\n");
2232 if(graphics
== NULL
)
2233 return InvalidParameter
;
2235 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2236 if(!*graphics
) return OutOfMemory
;
2238 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2240 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2241 heap_free(*graphics
);
2245 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2246 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2247 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2249 (*graphics
)->alpha_hdc
= 1;
2252 (*graphics
)->hdc
= hdc
;
2253 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2254 (*graphics
)->owndc
= FALSE
;
2255 (*graphics
)->smoothing
= SmoothingModeDefault
;
2256 (*graphics
)->compqual
= CompositingQualityDefault
;
2257 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2258 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2259 (*graphics
)->compmode
= CompositingModeSourceOver
;
2260 (*graphics
)->unit
= UnitDisplay
;
2261 (*graphics
)->scale
= 1.0;
2262 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2263 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2264 (*graphics
)->busy
= FALSE
;
2265 (*graphics
)->textcontrast
= 4;
2266 list_init(&(*graphics
)->containers
);
2267 (*graphics
)->contid
= 0;
2269 TRACE("<-- %p\n", *graphics
);
2274 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2278 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2279 if(!*graphics
) return OutOfMemory
;
2281 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2283 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2284 heap_free(*graphics
);
2288 (*graphics
)->hdc
= NULL
;
2289 (*graphics
)->hwnd
= NULL
;
2290 (*graphics
)->owndc
= FALSE
;
2291 (*graphics
)->image
= image
;
2292 /* We have to store the image type here because the image may be freed
2293 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2294 (*graphics
)->image_type
= image
->type
;
2295 (*graphics
)->smoothing
= SmoothingModeDefault
;
2296 (*graphics
)->compqual
= CompositingQualityDefault
;
2297 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2298 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2299 (*graphics
)->compmode
= CompositingModeSourceOver
;
2300 (*graphics
)->unit
= UnitDisplay
;
2301 (*graphics
)->scale
= 1.0;
2302 (*graphics
)->xres
= image
->xres
;
2303 (*graphics
)->yres
= image
->yres
;
2304 (*graphics
)->busy
= FALSE
;
2305 (*graphics
)->textcontrast
= 4;
2306 list_init(&(*graphics
)->containers
);
2307 (*graphics
)->contid
= 0;
2309 TRACE("<-- %p\n", *graphics
);
2314 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2319 TRACE("(%p, %p)\n", hwnd
, graphics
);
2323 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2325 ReleaseDC(hwnd
, hdc
);
2329 (*graphics
)->hwnd
= hwnd
;
2330 (*graphics
)->owndc
= TRUE
;
2335 /* FIXME: no icm handling */
2336 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2338 TRACE("(%p, %p)\n", hwnd
, graphics
);
2340 return GdipCreateFromHWND(hwnd
, graphics
);
2343 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2344 UINT access
, IStream
**stream
)
2349 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2351 if(!stream
|| !filename
)
2352 return InvalidParameter
;
2354 if(access
& GENERIC_WRITE
)
2355 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2356 else if(access
& GENERIC_READ
)
2357 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2359 return InvalidParameter
;
2361 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2363 return hresult_to_status(ret
);
2366 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2368 GraphicsContainerItem
*cont
, *next
;
2370 TRACE("(%p)\n", graphics
);
2372 if(!graphics
) return InvalidParameter
;
2373 if(graphics
->busy
) return ObjectBusy
;
2375 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2377 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2383 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2385 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2386 list_remove(&cont
->entry
);
2387 delete_container(cont
);
2390 GdipDeleteRegion(graphics
->clip
);
2392 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2393 * do otherwise, but we can't have that in the test suite because it means
2394 * accessing freed memory. */
2395 graphics
->busy
= TRUE
;
2397 heap_free(graphics
);
2402 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2403 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2408 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2409 width
, height
, startAngle
, sweepAngle
);
2411 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2412 return InvalidParameter
;
2417 status
= GdipCreatePath(FillModeAlternate
, &path
);
2418 if (status
!= Ok
) return status
;
2420 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2422 status
= GdipDrawPath(graphics
, pen
, path
);
2424 GdipDeletePath(path
);
2428 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2429 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2431 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2432 width
, height
, startAngle
, sweepAngle
);
2434 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2437 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2438 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2442 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2443 x2
, y2
, x3
, y3
, x4
, y4
);
2445 if(!graphics
|| !pen
)
2446 return InvalidParameter
;
2459 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2462 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2463 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2465 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2466 x2
, y2
, x3
, y3
, x4
, y4
);
2468 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2471 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2472 GDIPCONST GpPointF
*points
, INT count
)
2477 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2479 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2480 return InvalidParameter
;
2485 status
= GdipCreatePath(FillModeAlternate
, &path
);
2486 if (status
!= Ok
) return status
;
2488 status
= GdipAddPathBeziers(path
, points
, count
);
2490 status
= GdipDrawPath(graphics
, pen
, path
);
2492 GdipDeletePath(path
);
2496 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2497 GDIPCONST GpPoint
*points
, INT count
)
2503 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2505 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2506 return InvalidParameter
;
2511 pts
= heap_alloc_zero(sizeof(GpPointF
) * count
);
2515 for(i
= 0; i
< count
; i
++){
2516 pts
[i
].X
= (REAL
)points
[i
].X
;
2517 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2520 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2527 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2528 GDIPCONST GpPointF
*points
, INT count
)
2530 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2532 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2535 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2536 GDIPCONST GpPoint
*points
, INT count
)
2538 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2540 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2543 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2544 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2549 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2551 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2552 return InvalidParameter
;
2557 status
= GdipCreatePath(FillModeAlternate
, &path
);
2558 if (status
!= Ok
) return status
;
2560 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2562 status
= GdipDrawPath(graphics
, pen
, path
);
2564 GdipDeletePath(path
);
2569 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2570 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2576 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2578 if(!points
|| count
<= 0)
2579 return InvalidParameter
;
2581 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2585 for(i
= 0; i
< count
; i
++){
2586 ptf
[i
].X
= (REAL
)points
[i
].X
;
2587 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2590 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2597 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2598 GDIPCONST GpPointF
*points
, INT count
)
2600 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2602 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2605 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2606 GDIPCONST GpPoint
*points
, INT count
)
2612 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2615 return InvalidParameter
;
2617 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2621 for(i
= 0; i
< count
; i
++){
2622 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2623 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2626 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2632 /* Approximates cardinal spline with Bezier curves. */
2633 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2634 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2639 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2641 if(!graphics
|| !pen
)
2642 return InvalidParameter
;
2648 return InvalidParameter
;
2650 status
= GdipCreatePath(FillModeAlternate
, &path
);
2651 if (status
!= Ok
) return status
;
2653 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2655 status
= GdipDrawPath(graphics
, pen
, path
);
2657 GdipDeletePath(path
);
2661 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2662 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2668 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2671 return InvalidParameter
;
2673 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2677 for(i
= 0; i
< count
; i
++){
2678 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2679 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2682 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2688 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2689 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2692 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2694 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2695 return InvalidParameter
;
2698 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2701 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2702 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2705 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2711 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2712 return InvalidParameter
;
2715 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2718 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2719 REAL y
, REAL width
, REAL height
)
2724 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2726 if(!graphics
|| !pen
)
2727 return InvalidParameter
;
2732 status
= GdipCreatePath(FillModeAlternate
, &path
);
2733 if (status
!= Ok
) return status
;
2735 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2737 status
= GdipDrawPath(graphics
, pen
, path
);
2739 GdipDeletePath(path
);
2743 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2744 INT y
, INT width
, INT height
)
2746 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2748 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2752 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2756 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2758 if(!graphics
|| !image
)
2759 return InvalidParameter
;
2761 GdipGetImageWidth(image
, &width
);
2762 GdipGetImageHeight(image
, &height
);
2764 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2765 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2768 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2771 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2773 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2776 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2777 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2781 REAL scale_x
, scale_y
, width
, height
;
2783 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2785 if (!graphics
|| !image
) return InvalidParameter
;
2787 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2788 scale_x
*= graphics
->xres
/ image
->xres
;
2789 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2790 scale_y
*= graphics
->yres
/ image
->yres
;
2791 width
= srcwidth
* scale_x
;
2792 height
= srcheight
* scale_y
;
2794 points
[0].X
= points
[2].X
= x
;
2795 points
[0].Y
= points
[1].Y
= y
;
2796 points
[1].X
= x
+ width
;
2797 points
[2].Y
= y
+ height
;
2799 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2800 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2803 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2804 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2807 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2810 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2811 GDIPCONST GpPointF
*dstpoints
, INT count
)
2815 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2818 return InvalidParameter
;
2820 GdipGetImageWidth(image
, &width
);
2821 GdipGetImageHeight(image
, &height
);
2823 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2824 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2827 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2828 GDIPCONST GpPoint
*dstpoints
, INT count
)
2832 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2834 if (count
!= 3 || !dstpoints
)
2835 return InvalidParameter
;
2837 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2838 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2839 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2840 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2841 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2842 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2844 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2847 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2848 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2850 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2854 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2855 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2856 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2857 DrawImageAbort callback
, VOID
* callbackData
)
2863 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2864 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2868 return NotImplemented
;
2870 if(!graphics
|| !image
|| !points
|| count
!= 3)
2871 return InvalidParameter
;
2873 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2874 debugstr_pointf(&points
[2]));
2876 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2878 return METAFILE_DrawImagePointsRect((GpMetafile
*)graphics
->image
,
2879 image
, points
, count
, srcx
, srcy
, srcwidth
, srcheight
,
2880 srcUnit
, imageAttributes
, callback
, callbackData
);
2883 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2885 /* Ensure source width/height is positive */
2888 GpPointF tmp
= ptf
[1];
2889 srcx
= srcx
+ srcwidth
;
2890 srcwidth
= -srcwidth
;
2891 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2892 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2899 GpPointF tmp
= ptf
[2];
2900 srcy
= srcy
+ srcheight
;
2901 srcheight
= -srcheight
;
2902 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
2903 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
2908 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2909 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2910 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
2912 transform_and_round_points(graphics
, pti
, ptf
, 4);
2914 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2915 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2917 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2918 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2919 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2920 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2921 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2923 if (image
->type
== ImageTypeBitmap
)
2925 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2926 BOOL do_resampling
= FALSE
;
2927 BOOL use_software
= FALSE
;
2929 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2930 graphics
->xres
, graphics
->yres
,
2931 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2932 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2933 imageAttributes
? imageAttributes
->outside_color
: 0);
2935 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2936 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2937 srcx
< 0 || srcy
< 0 ||
2938 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2939 do_resampling
= TRUE
;
2941 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
2942 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
2943 use_software
= TRUE
;
2948 GpRectF graphics_bounds
;
2950 int i
, x
, y
, src_stride
, dst_stride
;
2951 GpMatrix dst_to_src
;
2952 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2953 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
2954 BitmapData lockeddata
;
2955 InterpolationMode interpolation
= graphics
->interpolation
;
2956 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2957 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2958 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2959 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2961 if (!imageAttributes
)
2962 imageAttributes
= &defaultImageAttributes
;
2964 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2965 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2968 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2969 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2970 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2971 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2974 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
2975 if (stat
!= Ok
) return stat
;
2977 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
2978 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
2979 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
2980 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
2982 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
2984 if (IsRectEmpty(&dst_area
)) return Ok
;
2986 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2987 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2988 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2989 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2990 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2991 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2993 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
2995 stat
= GdipInvertMatrix(&dst_to_src
);
2996 if (stat
!= Ok
) return stat
;
3000 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3001 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3005 /* Make sure src_area is equal in size to dst_area. */
3006 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
3007 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
3008 src_area
.Width
= dst_area
.right
- dst_area
.left
;
3009 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
3012 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3014 src_data
= heap_alloc_zero(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3017 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3019 /* Read the bits we need from the source bitmap into a compatible buffer. */
3020 lockeddata
.Width
= src_area
.Width
;
3021 lockeddata
.Height
= src_area
.Height
;
3022 lockeddata
.Stride
= src_stride
;
3023 lockeddata
.Scan0
= src_data
;
3024 if (!do_resampling
&& bitmap
->format
== PixelFormat32bppPARGB
)
3025 lockeddata
.PixelFormat
= apply_image_attributes(imageAttributes
, NULL
, 0, 0, 0, ColorAdjustTypeBitmap
, bitmap
->format
);
3027 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3029 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3030 lockeddata
.PixelFormat
, &lockeddata
);
3033 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3037 heap_free(src_data
);
3041 apply_image_attributes(imageAttributes
, src_data
,
3042 src_area
.Width
, src_area
.Height
,
3043 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
3047 /* Transform the bits as needed to the destination. */
3048 dst_data
= dst_dyn_data
= heap_alloc_zero(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3051 heap_free(src_data
);
3055 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3057 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3059 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3060 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3061 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3062 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3064 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3066 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3068 GpPointF src_pointf
;
3071 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3072 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3074 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3076 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3077 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3078 imageAttributes
, interpolation
, offset_mode
);
3086 dst_data
= src_data
;
3087 dst_stride
= src_stride
;
3090 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3091 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
,
3092 lockeddata
.PixelFormat
);
3094 heap_free(src_data
);
3096 heap_free(dst_dyn_data
);
3103 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3104 HBITMAP hbitmap
, old_hbm
=NULL
;
3108 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3109 bitmap
->format
== PixelFormat24bppRGB
||
3110 bitmap
->format
== PixelFormat32bppRGB
||
3111 bitmap
->format
== PixelFormat32bppPARGB
))
3113 BITMAPINFOHEADER bih
;
3115 PixelFormat dst_format
;
3117 /* we can't draw a bitmap of this format directly */
3118 hdc
= CreateCompatibleDC(0);
3122 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3123 bih
.biWidth
= bitmap
->width
;
3124 bih
.biHeight
= -bitmap
->height
;
3126 bih
.biBitCount
= 32;
3127 bih
.biCompression
= BI_RGB
;
3128 bih
.biSizeImage
= 0;
3129 bih
.biXPelsPerMeter
= 0;
3130 bih
.biYPelsPerMeter
= 0;
3132 bih
.biClrImportant
= 0;
3134 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3135 (void**)&temp_bits
, NULL
, 0);
3137 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3138 dst_format
= PixelFormat32bppPARGB
;
3140 dst_format
= PixelFormat32bppRGB
;
3142 convert_pixels(bitmap
->width
, bitmap
->height
,
3143 bitmap
->width
*4, temp_bits
, dst_format
,
3144 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3145 bitmap
->image
.palette
);
3149 if (bitmap
->hbitmap
)
3150 hbitmap
= bitmap
->hbitmap
;
3153 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3158 temp_hdc
= (hdc
== 0);
3163 if (!hdc
) hdc
= CreateCompatibleDC(0);
3164 old_hbm
= SelectObject(hdc
, hbitmap
);
3167 save_state
= SaveDC(graphics
->hdc
);
3169 stat
= get_clip_hrgn(graphics
, &hrgn
);
3171 if (stat
== Ok
&& hrgn
)
3173 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3177 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3179 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3180 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3184 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3185 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3188 RestoreDC(graphics
->hdc
, save_state
);
3192 SelectObject(hdc
, old_hbm
);
3197 DeleteObject(hbitmap
);
3200 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3206 rc
.Width
= srcwidth
;
3207 rc
.Height
= srcheight
;
3209 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3210 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3214 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3215 return InvalidParameter
;
3221 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3222 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3223 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3224 DrawImageAbort callback
, VOID
* callbackData
)
3226 GpPointF pointsF
[3];
3229 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3230 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3233 if(!points
|| count
!=3)
3234 return InvalidParameter
;
3236 for(i
= 0; i
< count
; i
++){
3237 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3238 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3241 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3242 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3243 callback
, callbackData
);
3246 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3247 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3248 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3249 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3250 VOID
* callbackData
)
3254 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3255 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3256 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3260 points
[1].X
= dstx
+ dstwidth
;
3263 points
[2].Y
= dsty
+ dstheight
;
3265 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3266 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3269 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3270 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3271 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3272 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3273 VOID
* callbackData
)
3277 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3278 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3279 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3283 points
[1].X
= dstx
+ dstwidth
;
3286 points
[2].Y
= dsty
+ dstheight
;
3288 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3289 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3292 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3293 REAL x
, REAL y
, REAL width
, REAL height
)
3299 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3301 if(!graphics
|| !image
)
3302 return InvalidParameter
;
3304 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3308 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3309 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3310 unit
, NULL
, NULL
, NULL
);
3313 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3314 INT x
, INT y
, INT width
, INT height
)
3316 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3318 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3321 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3322 REAL y1
, REAL x2
, REAL y2
)
3326 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3329 return InvalidParameter
;
3331 if (pen
->unit
== UnitPixel
&& pen
->width
<= 0.0)
3338 return GdipDrawLines(graphics
, pen
, pt
, 2);
3341 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3342 INT y1
, INT x2
, INT y2
)
3344 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3346 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3349 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3350 GpPointF
*points
, INT count
)
3355 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3357 if(!pen
|| !graphics
|| (count
< 2))
3358 return InvalidParameter
;
3363 status
= GdipCreatePath(FillModeAlternate
, &path
);
3364 if (status
!= Ok
) return status
;
3366 status
= GdipAddPathLine2(path
, points
, count
);
3368 status
= GdipDrawPath(graphics
, pen
, path
);
3370 GdipDeletePath(path
);
3374 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3375 GpPoint
*points
, INT count
)
3381 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3383 ptf
= heap_alloc_zero(count
* sizeof(GpPointF
));
3384 if(!ptf
) return OutOfMemory
;
3386 for(i
= 0; i
< count
; i
++){
3387 ptf
[i
].X
= (REAL
) points
[i
].X
;
3388 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3391 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3397 static GpStatus
GDI32_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3403 save_state
= prepare_dc(graphics
, pen
);
3405 retval
= get_clip_hrgn(graphics
, &hrgn
);
3411 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3413 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3414 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3417 restore_dc(graphics
, save_state
);
3423 static GpStatus
SOFTWARE_GdipDrawThinPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3427 GpMatrix
* transform
;
3428 GpRectF gp_bound_rect
;
3429 GpRect gp_output_area
;
3431 INT output_height
, output_width
;
3432 DWORD
*output_bits
, *brush_bits
=NULL
;
3434 static const BYTE static_dash_pattern
[] = {1,1,1,0,1,0,1,0};
3435 const BYTE
*dash_pattern
;
3436 INT dash_pattern_size
;
3437 BYTE
*dyn_dash_pattern
= NULL
;
3439 stat
= GdipClonePath(path
, &flat_path
);
3444 stat
= GdipCreateMatrix(&transform
);
3448 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3449 CoordinateSpaceWorld
, transform
);
3452 stat
= GdipFlattenPath(flat_path
, transform
, 1.0);
3454 GdipDeleteMatrix(transform
);
3457 /* estimate the output size in pixels, can be larger than necessary */
3460 output_area
.left
= floorf(flat_path
->pathdata
.Points
[0].X
);
3461 output_area
.right
= ceilf(flat_path
->pathdata
.Points
[0].X
);
3462 output_area
.top
= floorf(flat_path
->pathdata
.Points
[0].Y
);
3463 output_area
.bottom
= ceilf(flat_path
->pathdata
.Points
[0].Y
);
3465 for (i
=1; i
<flat_path
->pathdata
.Count
; i
++)
3468 x
= flat_path
->pathdata
.Points
[i
].X
;
3469 y
= flat_path
->pathdata
.Points
[i
].Y
;
3471 if (floorf(x
) < output_area
.left
) output_area
.left
= floorf(x
);
3472 if (floorf(y
) < output_area
.top
) output_area
.top
= floorf(y
);
3473 if (ceilf(x
) > output_area
.right
) output_area
.right
= ceilf(x
);
3474 if (ceilf(y
) > output_area
.bottom
) output_area
.bottom
= ceilf(y
);
3477 stat
= get_graphics_bounds(graphics
, &gp_bound_rect
);
3482 output_area
.left
= max(output_area
.left
, floorf(gp_bound_rect
.X
));
3483 output_area
.top
= max(output_area
.top
, floorf(gp_bound_rect
.Y
));
3484 output_area
.right
= min(output_area
.right
, ceilf(gp_bound_rect
.X
+ gp_bound_rect
.Width
));
3485 output_area
.bottom
= min(output_area
.bottom
, ceilf(gp_bound_rect
.Y
+ gp_bound_rect
.Height
));
3487 output_width
= output_area
.right
- output_area
.left
+ 1;
3488 output_height
= output_area
.bottom
- output_area
.top
+ 1;
3490 if (output_width
<= 0 || output_height
<= 0)
3492 GdipDeletePath(flat_path
);
3496 gp_output_area
.X
= output_area
.left
;
3497 gp_output_area
.Y
= output_area
.top
;
3498 gp_output_area
.Width
= output_width
;
3499 gp_output_area
.Height
= output_height
;
3501 output_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3508 if (pen
->brush
->bt
!= BrushTypeSolidColor
)
3510 /* allocate and draw brush output */
3511 brush_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3515 stat
= brush_fill_pixels(graphics
, pen
->brush
, brush_bits
,
3516 &gp_output_area
, output_width
);
3524 /* convert dash pattern to bool array */
3527 case DashStyleCustom
:
3529 dash_pattern_size
= 0;
3531 for (i
=0; i
< pen
->numdashes
; i
++)
3532 dash_pattern_size
+= gdip_round(pen
->dashes
[i
]);
3534 if (dash_pattern_size
!= 0)
3536 dash_pattern
= dyn_dash_pattern
= heap_alloc(dash_pattern_size
);
3538 if (dyn_dash_pattern
)
3541 for (i
=0; i
< pen
->numdashes
; i
++)
3544 for (k
=0; k
< gdip_round(pen
->dashes
[i
]); k
++)
3545 dyn_dash_pattern
[j
++] = (i
&1)^1;
3553 /* else fall through */
3555 case DashStyleSolid
:
3557 dash_pattern
= static_dash_pattern
;
3558 dash_pattern_size
= 1;
3561 dash_pattern
= static_dash_pattern
;
3562 dash_pattern_size
= 4;
3565 dash_pattern
= &static_dash_pattern
[4];
3566 dash_pattern_size
= 2;
3568 case DashStyleDashDot
:
3569 dash_pattern
= static_dash_pattern
;
3570 dash_pattern_size
= 6;
3572 case DashStyleDashDotDot
:
3573 dash_pattern
= static_dash_pattern
;
3574 dash_pattern_size
= 8;
3582 GpPointF subpath_start
= flat_path
->pathdata
.Points
[0];
3583 INT prev_x
= INT_MAX
, prev_y
= INT_MAX
;
3584 int dash_pos
= dash_pattern_size
- 1;
3586 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
3589 GpPointF start_point
, end_point
;
3590 GpPoint start_pointi
, end_pointi
;
3592 type
= flat_path
->pathdata
.Types
[i
];
3593 if (i
+1 < flat_path
->pathdata
.Count
)
3594 type2
= flat_path
->pathdata
.Types
[i
+1];
3596 type2
= PathPointTypeStart
;
3598 start_point
= flat_path
->pathdata
.Points
[i
];
3600 if ((type
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3601 subpath_start
= start_point
;
3603 if ((type
& PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
3604 end_point
= subpath_start
;
3605 else if ((type2
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3608 end_point
= flat_path
->pathdata
.Points
[i
+1];
3610 start_pointi
.X
= floorf(start_point
.X
);
3611 start_pointi
.Y
= floorf(start_point
.Y
);
3612 end_pointi
.X
= floorf(end_point
.X
);
3613 end_pointi
.Y
= floorf(end_point
.Y
);
3615 if(start_pointi
.X
== end_pointi
.X
&& start_pointi
.Y
== end_pointi
.Y
)
3618 /* draw line segment */
3619 if (abs(start_pointi
.Y
- end_pointi
.Y
) > abs(start_pointi
.X
- end_pointi
.X
))
3621 INT x
, y
, start_y
, end_y
, step
;
3623 if (start_pointi
.Y
< end_pointi
.Y
)
3626 start_y
= ceilf(start_point
.Y
) - output_area
.top
;
3627 end_y
= end_pointi
.Y
- output_area
.top
;
3632 start_y
= start_point
.Y
- output_area
.top
;
3633 end_y
= ceilf(end_point
.Y
) - output_area
.top
;
3636 for (y
=start_y
; y
!= (end_y
+step
); y
+=step
)
3638 x
= gdip_round( start_point
.X
+
3639 (end_point
.X
- start_point
.X
) * (y
+ output_area
.top
- start_point
.Y
) / (end_point
.Y
- start_point
.Y
) )
3642 if (x
== prev_x
&& y
== prev_y
)
3647 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3649 if (!dash_pattern
[dash_pos
])
3652 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3656 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3658 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3663 INT x
, y
, start_x
, end_x
, step
;
3665 if (start_pointi
.X
< end_pointi
.X
)
3668 start_x
= ceilf(start_point
.X
) - output_area
.left
;
3669 end_x
= end_pointi
.X
- output_area
.left
;
3674 start_x
= start_point
.X
- output_area
.left
;
3675 end_x
= ceilf(end_point
.X
) - output_area
.left
;
3678 for (x
=start_x
; x
!= (end_x
+step
); x
+=step
)
3680 y
= gdip_round( start_point
.Y
+
3681 (end_point
.Y
- start_point
.Y
) * (x
+ output_area
.left
- start_point
.X
) / (end_point
.X
- start_point
.X
) )
3684 if (x
== prev_x
&& y
== prev_y
)
3689 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3691 if (!dash_pattern
[dash_pos
])
3694 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3698 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3700 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3706 /* draw output image */
3709 stat
= alpha_blend_pixels(graphics
, output_area
.left
, output_area
.top
,
3710 (BYTE
*)output_bits
, output_width
, output_height
, output_width
* 4,
3711 PixelFormat32bppARGB
);
3714 heap_free(brush_bits
);
3715 heap_free(dyn_dash_pattern
);
3716 heap_free(output_bits
);
3719 GdipDeletePath(flat_path
);
3724 static GpStatus
SOFTWARE_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3728 GpMatrix
*transform
=NULL
;
3731 /* Check if the final pen thickness in pixels is too thin. */
3732 if (pen
->unit
== UnitPixel
)
3734 if (pen
->width
< 1.415)
3735 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3739 GpPointF points
[3] = {{0,0}, {1,0}, {0,1}};
3741 points
[1].X
= pen
->width
;
3742 points
[2].Y
= pen
->width
;
3744 stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3745 CoordinateSpaceWorld
, points
, 3);
3750 if (((points
[1].X
-points
[0].X
)*(points
[1].X
-points
[0].X
) +
3751 (points
[1].Y
-points
[0].Y
)*(points
[1].Y
-points
[0].Y
) < 2.0001) &&
3752 ((points
[2].X
-points
[0].X
)*(points
[2].X
-points
[0].X
) +
3753 (points
[2].Y
-points
[0].Y
)*(points
[2].Y
-points
[0].Y
) < 2.0001))
3754 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3757 stat
= GdipClonePath(path
, &wide_path
);
3762 if (pen
->unit
== UnitPixel
)
3764 /* We have to transform this to device coordinates to get the widths right. */
3765 stat
= GdipCreateMatrix(&transform
);
3768 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3769 CoordinateSpaceWorld
, transform
);
3773 /* Set flatness based on the final coordinate space */
3776 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3777 CoordinateSpaceWorld
, &t
);
3782 flatness
= 1.0/sqrt(fmax(
3783 t
.matrix
[0] * t
.matrix
[0] + t
.matrix
[1] * t
.matrix
[1],
3784 t
.matrix
[2] * t
.matrix
[2] + t
.matrix
[3] * t
.matrix
[3]));
3788 stat
= GdipWidenPath(wide_path
, pen
, transform
, flatness
);
3790 if (pen
->unit
== UnitPixel
)
3792 /* Transform the path back to world coordinates */
3794 stat
= GdipInvertMatrix(transform
);
3797 stat
= GdipTransformPath(wide_path
, transform
);
3800 /* Actually draw the path */
3802 stat
= GdipFillPath(graphics
, pen
->brush
, wide_path
);
3804 GdipDeleteMatrix(transform
);
3806 GdipDeletePath(wide_path
);
3811 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3815 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3817 if(!pen
|| !graphics
)
3818 return InvalidParameter
;
3823 if (path
->pathdata
.Count
== 0)
3826 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
3827 retval
= METAFILE_DrawPath((GpMetafile
*)graphics
->image
, pen
, path
);
3828 else if (!graphics
->hdc
|| !brush_can_fill_path(pen
->brush
, FALSE
))
3829 retval
= SOFTWARE_GdipDrawPath(graphics
, pen
, path
);
3831 retval
= GDI32_GdipDrawPath(graphics
, pen
, path
);
3836 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3837 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3842 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3843 width
, height
, startAngle
, sweepAngle
);
3845 if(!graphics
|| !pen
)
3846 return InvalidParameter
;
3851 status
= GdipCreatePath(FillModeAlternate
, &path
);
3852 if (status
!= Ok
) return status
;
3854 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3856 status
= GdipDrawPath(graphics
, pen
, path
);
3858 GdipDeletePath(path
);
3862 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3863 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3865 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3866 width
, height
, startAngle
, sweepAngle
);
3868 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3871 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3872 REAL y
, REAL width
, REAL height
)
3877 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3879 if(!pen
|| !graphics
)
3880 return InvalidParameter
;
3885 status
= GdipCreatePath(FillModeAlternate
, &path
);
3886 if (status
!= Ok
) return status
;
3888 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3890 status
= GdipDrawPath(graphics
, pen
, path
);
3892 GdipDeletePath(path
);
3896 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3897 INT y
, INT width
, INT height
)
3899 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3901 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3904 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3905 GDIPCONST GpRectF
* rects
, INT count
)
3910 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3912 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3913 return InvalidParameter
;
3918 status
= GdipCreatePath(FillModeAlternate
, &path
);
3919 if (status
!= Ok
) return status
;
3921 status
= GdipAddPathRectangles(path
, rects
, count
);
3923 status
= GdipDrawPath(graphics
, pen
, path
);
3925 GdipDeletePath(path
);
3929 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3930 GDIPCONST GpRect
* rects
, INT count
)
3936 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3938 if(!rects
|| count
<=0)
3939 return InvalidParameter
;
3941 rectsF
= heap_alloc_zero(sizeof(GpRectF
) * count
);
3945 for(i
= 0;i
< count
;i
++){
3946 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3947 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3948 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3949 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3952 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3958 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3959 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3964 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3965 count
, tension
, fill
);
3967 if(!graphics
|| !brush
|| !points
)
3968 return InvalidParameter
;
3973 if(count
== 1) /* Do nothing */
3976 status
= GdipCreatePath(fill
, &path
);
3977 if (status
!= Ok
) return status
;
3979 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3981 status
= GdipFillPath(graphics
, brush
, path
);
3983 GdipDeletePath(path
);
3987 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3988 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3994 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3995 count
, tension
, fill
);
3997 if(!points
|| count
== 0)
3998 return InvalidParameter
;
4000 if(count
== 1) /* Do nothing */
4003 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
4007 for(i
= 0;i
< count
;i
++){
4008 ptf
[i
].X
= (REAL
)points
[i
].X
;
4009 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4012 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
4019 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
4020 GDIPCONST GpPointF
*points
, INT count
)
4022 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4023 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
4024 0.5f
, FillModeAlternate
);
4027 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
4028 GDIPCONST GpPoint
*points
, INT count
)
4030 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4031 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
4032 0.5f
, FillModeAlternate
);
4035 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4036 REAL y
, REAL width
, REAL height
)
4041 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4043 if(!graphics
|| !brush
)
4044 return InvalidParameter
;
4049 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4053 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
4056 stat
= GdipFillPath(graphics
, brush
, path
);
4058 GdipDeletePath(path
);
4064 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4065 INT y
, INT width
, INT height
)
4067 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4069 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
4072 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4078 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4079 return NotImplemented
;
4081 save_state
= SaveDC(graphics
->hdc
);
4082 EndPath(graphics
->hdc
);
4083 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
4086 retval
= get_clip_hrgn(graphics
, &hrgn
);
4092 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4094 BeginPath(graphics
->hdc
);
4095 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
4096 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
4101 EndPath(graphics
->hdc
);
4102 brush_fill_path(graphics
, brush
);
4107 RestoreDC(graphics
->hdc
, save_state
);
4113 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4118 if (!brush_can_fill_pixels(brush
))
4119 return NotImplemented
;
4121 /* FIXME: This could probably be done more efficiently without regions. */
4123 stat
= GdipCreateRegionPath(path
, &rgn
);
4127 stat
= GdipFillRegion(graphics
, brush
, rgn
);
4129 GdipDeleteRegion(rgn
);
4135 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4137 GpStatus stat
= NotImplemented
;
4139 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
4141 if(!brush
|| !graphics
|| !path
)
4142 return InvalidParameter
;
4147 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4148 return METAFILE_FillPath((GpMetafile
*)graphics
->image
, brush
, path
);
4150 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4151 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
4153 if (stat
== NotImplemented
)
4154 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
4156 if (stat
== NotImplemented
)
4158 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
4165 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4166 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4171 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
4172 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4174 if(!graphics
|| !brush
)
4175 return InvalidParameter
;
4180 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4184 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4187 stat
= GdipFillPath(graphics
, brush
, path
);
4189 GdipDeletePath(path
);
4195 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4196 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4198 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
4199 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4201 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4204 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
4205 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
4210 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4212 if(!graphics
|| !brush
|| !points
|| !count
)
4213 return InvalidParameter
;
4218 stat
= GdipCreatePath(fillMode
, &path
);
4222 stat
= GdipAddPathPolygon(path
, points
, count
);
4225 stat
= GdipFillPath(graphics
, brush
, path
);
4227 GdipDeletePath(path
);
4233 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4234 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4239 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4241 if(!graphics
|| !brush
|| !points
|| !count
)
4242 return InvalidParameter
;
4247 stat
= GdipCreatePath(fillMode
, &path
);
4251 stat
= GdipAddPathPolygonI(path
, points
, count
);
4254 stat
= GdipFillPath(graphics
, brush
, path
);
4256 GdipDeletePath(path
);
4262 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4263 GDIPCONST GpPointF
*points
, INT count
)
4265 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4267 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4270 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4271 GDIPCONST GpPoint
*points
, INT count
)
4273 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4275 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4278 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4279 REAL x
, REAL y
, REAL width
, REAL height
)
4283 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4288 rect
.Height
= height
;
4290 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4293 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4294 INT x
, INT y
, INT width
, INT height
)
4298 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4302 rect
.Width
= (REAL
)width
;
4303 rect
.Height
= (REAL
)height
;
4305 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4308 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4314 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4316 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
4317 return InvalidParameter
;
4319 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4321 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
4322 /* FIXME: Add gdi32 drawing. */
4326 status
= GdipCreatePath(FillModeAlternate
, &path
);
4327 if (status
!= Ok
) return status
;
4329 status
= GdipAddPathRectangles(path
, rects
, count
);
4331 status
= GdipFillPath(graphics
, brush
, path
);
4333 GdipDeletePath(path
);
4337 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4344 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4346 if(!rects
|| count
<= 0)
4347 return InvalidParameter
;
4349 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
4353 for(i
= 0; i
< count
; i
++){
4354 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4355 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4356 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
4357 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4360 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4366 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4374 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4375 return NotImplemented
;
4377 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4381 save_state
= SaveDC(graphics
->hdc
);
4382 EndPath(graphics
->hdc
);
4384 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4389 status
= get_clip_hrgn(graphics
, &hrgn
);
4393 RestoreDC(graphics
->hdc
, save_state
);
4399 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4403 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4405 BeginPath(graphics
->hdc
);
4406 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4407 EndPath(graphics
->hdc
);
4409 brush_fill_path(graphics
, brush
);
4412 RestoreDC(graphics
->hdc
, save_state
);
4418 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4422 GpRegion
*temp_region
;
4423 GpMatrix world_to_device
;
4424 GpRectF graphics_bounds
;
4428 GpRect gp_bound_rect
;
4430 if (!brush_can_fill_pixels(brush
))
4431 return NotImplemented
;
4433 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
4436 stat
= GdipCloneRegion(region
, &temp_region
);
4440 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
4441 CoordinateSpaceWorld
, &world_to_device
);
4444 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4447 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4450 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4452 GdipDeleteRegion(temp_region
);
4455 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4457 DeleteObject(hregion
);
4463 gp_bound_rect
.X
= bound_rect
.left
;
4464 gp_bound_rect
.Y
= bound_rect
.top
;
4465 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4466 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4468 pixel_data
= heap_alloc_zero(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4474 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4475 &gp_bound_rect
, gp_bound_rect
.Width
);
4478 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4479 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4480 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
,
4481 PixelFormat32bppARGB
);
4483 heap_free(pixel_data
);
4486 DeleteObject(hregion
);
4492 /*****************************************************************************
4493 * GdipFillRegion [GDIPLUS.@]
4495 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4498 GpStatus stat
= NotImplemented
;
4500 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4502 if (!(graphics
&& brush
&& region
))
4503 return InvalidParameter
;
4508 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4509 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4511 if (stat
== NotImplemented
)
4512 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4514 if (stat
== NotImplemented
)
4516 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4523 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4525 TRACE("(%p,%u)\n", graphics
, intention
);
4528 return InvalidParameter
;
4533 /* We have no internal operation queue, so there's no need to clear it. */
4541 /*****************************************************************************
4542 * GdipGetClipBounds [GDIPLUS.@]
4544 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4549 TRACE("(%p, %p)\n", graphics
, rect
);
4552 return InvalidParameter
;
4557 status
= GdipCreateRegion(&clip
);
4558 if (status
!= Ok
) return status
;
4560 status
= GdipGetClip(graphics
, clip
);
4562 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4564 GdipDeleteRegion(clip
);
4568 /*****************************************************************************
4569 * GdipGetClipBoundsI [GDIPLUS.@]
4571 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4573 TRACE("(%p, %p)\n", graphics
, rect
);
4576 return InvalidParameter
;
4581 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4584 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4585 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4586 CompositingMode
*mode
)
4588 TRACE("(%p, %p)\n", graphics
, mode
);
4590 if(!graphics
|| !mode
)
4591 return InvalidParameter
;
4596 *mode
= graphics
->compmode
;
4601 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4602 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4603 CompositingQuality
*quality
)
4605 TRACE("(%p, %p)\n", graphics
, quality
);
4607 if(!graphics
|| !quality
)
4608 return InvalidParameter
;
4613 *quality
= graphics
->compqual
;
4618 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4619 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4620 InterpolationMode
*mode
)
4622 TRACE("(%p, %p)\n", graphics
, mode
);
4624 if(!graphics
|| !mode
)
4625 return InvalidParameter
;
4630 *mode
= graphics
->interpolation
;
4635 /* FIXME: Need to handle color depths less than 24bpp */
4636 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4638 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4640 if(!graphics
|| !argb
)
4641 return InvalidParameter
;
4649 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4651 TRACE("(%p, %p)\n", graphics
, scale
);
4653 if(!graphics
|| !scale
)
4654 return InvalidParameter
;
4659 *scale
= graphics
->scale
;
4664 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4666 TRACE("(%p, %p)\n", graphics
, unit
);
4668 if(!graphics
|| !unit
)
4669 return InvalidParameter
;
4674 *unit
= graphics
->unit
;
4679 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4680 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4683 TRACE("(%p, %p)\n", graphics
, mode
);
4685 if(!graphics
|| !mode
)
4686 return InvalidParameter
;
4691 *mode
= graphics
->pixeloffset
;
4696 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4697 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4699 TRACE("(%p, %p)\n", graphics
, mode
);
4701 if(!graphics
|| !mode
)
4702 return InvalidParameter
;
4707 *mode
= graphics
->smoothing
;
4712 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4714 TRACE("(%p, %p)\n", graphics
, contrast
);
4716 if(!graphics
|| !contrast
)
4717 return InvalidParameter
;
4719 *contrast
= graphics
->textcontrast
;
4724 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4725 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4726 TextRenderingHint
*hint
)
4728 TRACE("(%p, %p)\n", graphics
, hint
);
4730 if(!graphics
|| !hint
)
4731 return InvalidParameter
;
4736 *hint
= graphics
->texthint
;
4741 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4745 GpMatrix device_to_world
;
4747 TRACE("(%p, %p)\n", graphics
, rect
);
4749 if(!graphics
|| !rect
)
4750 return InvalidParameter
;
4755 /* intersect window and graphics clipping regions */
4756 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4759 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4762 /* transform to world coordinates */
4763 if((stat
= get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
)) != Ok
)
4766 if((stat
= GdipTransformRegion(clip_rgn
, &device_to_world
)) != Ok
)
4769 /* get bounds of the region */
4770 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4773 GdipDeleteRegion(clip_rgn
);
4778 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4783 TRACE("(%p, %p)\n", graphics
, rect
);
4785 if(!graphics
|| !rect
)
4786 return InvalidParameter
;
4788 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4790 rect
->X
= gdip_round(rectf
.X
);
4791 rect
->Y
= gdip_round(rectf
.Y
);
4792 rect
->Width
= gdip_round(rectf
.Width
);
4793 rect
->Height
= gdip_round(rectf
.Height
);
4799 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4801 TRACE("(%p, %p)\n", graphics
, matrix
);
4803 if(!graphics
|| !matrix
)
4804 return InvalidParameter
;
4809 *matrix
= graphics
->worldtrans
;
4813 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4819 TRACE("(%p, %x)\n", graphics
, color
);
4822 return InvalidParameter
;
4827 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4828 return METAFILE_GraphicsClear((GpMetafile
*)graphics
->image
, color
);
4830 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4833 if((stat
= GdipGetVisibleClipBounds(graphics
, &wnd_rect
)) != Ok
){
4834 GdipDeleteBrush((GpBrush
*)brush
);
4838 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4839 wnd_rect
.Width
, wnd_rect
.Height
);
4841 GdipDeleteBrush((GpBrush
*)brush
);
4846 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4848 TRACE("(%p, %p)\n", graphics
, res
);
4850 if(!graphics
|| !res
)
4851 return InvalidParameter
;
4853 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4856 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4862 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4864 if(!graphics
|| !result
)
4865 return InvalidParameter
;
4872 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4873 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4876 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4879 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4882 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4885 GdipDeleteRegion(rgn
);
4889 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4891 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4894 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4900 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4902 if(!graphics
|| !result
)
4903 return InvalidParameter
;
4910 pts
[1].X
= x
+ width
;
4911 pts
[1].Y
= y
+ height
;
4913 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4914 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4917 pts
[1].X
-= pts
[0].X
;
4918 pts
[1].Y
-= pts
[0].Y
;
4920 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4923 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4926 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4929 GdipDeleteRegion(rgn
);
4933 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4935 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4938 GpStatus
gdip_format_string(HDC hdc
,
4939 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4940 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4941 gdip_format_string_callback callback
, void *user_data
)
4944 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4945 nheight
, lineend
, lineno
= 0;
4947 StringAlignment halign
;
4950 HotkeyPrefix hkprefix
;
4951 INT
*hotkeyprefix_offsets
=NULL
;
4952 INT hotkeyprefix_count
=0;
4953 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4954 BOOL seen_prefix
= FALSE
;
4956 if(length
== -1) length
= lstrlenW(string
);
4958 stringdup
= heap_alloc_zero((length
+ 1) * sizeof(WCHAR
));
4959 if(!stringdup
) return OutOfMemory
;
4962 format
= &default_drawstring_format
;
4964 nwidth
= rect
->Width
;
4965 nheight
= rect
->Height
;
4966 if (ignore_empty_clip
)
4968 if (!nwidth
) nwidth
= INT_MAX
;
4969 if (!nheight
) nheight
= INT_MAX
;
4972 hkprefix
= format
->hkprefix
;
4974 if (hkprefix
== HotkeyPrefixShow
)
4976 for (i
=0; i
<length
; i
++)
4978 if (string
[i
] == '&')
4979 hotkeyprefix_count
++;
4983 if (hotkeyprefix_count
)
4984 hotkeyprefix_offsets
= heap_alloc_zero(sizeof(INT
) * hotkeyprefix_count
);
4986 hotkeyprefix_count
= 0;
4988 for(i
= 0, j
= 0; i
< length
; i
++){
4989 /* FIXME: This makes the indexes passed to callback inaccurate. */
4990 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4993 /* FIXME: tabs should be handled using tabstops from stringformat */
4994 if (string
[i
] == '\t')
4997 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4998 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4999 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
5005 seen_prefix
= FALSE
;
5007 stringdup
[j
] = string
[i
];
5013 halign
= format
->align
;
5015 while(sum
< length
){
5016 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
5017 nwidth
, &fit
, NULL
, &size
);
5023 for(lret
= 0; lret
< fit
; lret
++)
5024 if(*(stringdup
+ sum
+ lret
) == '\n')
5027 /* Line break code (may look strange, but it imitates windows). */
5029 lineend
= fit
= lret
; /* this is not an off-by-one error */
5030 else if(fit
< (length
- sum
)){
5031 if(*(stringdup
+ sum
+ fit
) == ' ')
5032 while(*(stringdup
+ sum
+ fit
) == ' ')
5035 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
5038 if(*(stringdup
+ sum
+ fit
) == '\t')
5047 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
5048 *(stringdup
+ sum
+ lineend
- 1) == '\t')
5054 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
5055 nwidth
, &j
, NULL
, &size
);
5057 bounds
.Width
= size
.cx
;
5059 if(height
+ size
.cy
> nheight
)
5061 if (format
->attr
& StringFormatFlagsLineLimit
)
5063 bounds
.Height
= nheight
- (height
+ size
.cy
);
5066 bounds
.Height
= size
.cy
;
5068 bounds
.Y
= rect
->Y
+ height
;
5072 case StringAlignmentNear
:
5076 case StringAlignmentCenter
:
5077 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
5079 case StringAlignmentFar
:
5080 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
5084 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
5085 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
5088 stat
= callback(hdc
, stringdup
, sum
, lineend
,
5089 font
, rect
, format
, lineno
, &bounds
,
5090 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
5091 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
5096 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
5100 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
5102 if(height
> nheight
)
5105 /* Stop if this was a linewrap (but not if it was a linebreak). */
5106 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
5110 heap_free(stringdup
);
5111 heap_free(hotkeyprefix_offsets
);
5116 struct measure_ranges_args
{
5118 REAL rel_width
, rel_height
;
5121 static GpStatus
measure_ranges_callback(HDC hdc
,
5122 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5123 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5124 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5125 INT underlined_index_count
, void *user_data
)
5129 struct measure_ranges_args
*args
= user_data
;
5131 for (i
=0; i
<format
->range_count
; i
++)
5133 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
5134 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
5135 if (range_start
< range_end
)
5140 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
5141 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
5143 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
5144 INT_MAX
, NULL
, NULL
, &range_size
);
5145 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
5147 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
5148 INT_MAX
, NULL
, NULL
, &range_size
);
5149 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
5151 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
5160 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
5161 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
5162 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
5163 INT regionCount
, GpRegion
** regions
)
5167 HFONT gdifont
, oldfont
;
5168 struct measure_ranges_args args
;
5169 HDC hdc
, temp_hdc
=NULL
;
5174 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
5175 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
5177 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
5178 return InvalidParameter
;
5180 if (regionCount
< stringFormat
->range_count
)
5181 return InvalidParameter
;
5185 hdc
= temp_hdc
= CreateCompatibleDC(0);
5186 if (!temp_hdc
) return OutOfMemory
;
5189 hdc
= graphics
->hdc
;
5191 if (stringFormat
->attr
)
5192 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
5200 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5201 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5202 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5203 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5204 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5206 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
5207 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5209 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
5210 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
5211 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
5212 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
5214 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5215 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5217 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
5218 oldfont
= SelectObject(hdc
, gdifont
);
5220 for (i
=0; i
<stringFormat
->range_count
; i
++)
5222 stat
= GdipSetEmpty(regions
[i
]);
5227 args
.regions
= regions
;
5229 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
5230 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
5232 SelectObject(hdc
, oldfont
);
5233 DeleteObject(gdifont
);
5241 struct measure_string_args
{
5243 INT
*codepointsfitted
;
5245 REAL rel_width
, rel_height
;
5248 static GpStatus
measure_string_callback(HDC hdc
,
5249 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5250 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5251 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5252 INT underlined_index_count
, void *user_data
)
5254 struct measure_string_args
*args
= user_data
;
5255 REAL new_width
, new_height
;
5257 new_width
= bounds
->Width
/ args
->rel_width
;
5258 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
5260 if (new_width
> args
->bounds
->Width
)
5261 args
->bounds
->Width
= new_width
;
5263 if (new_height
> args
->bounds
->Height
)
5264 args
->bounds
->Height
= new_height
;
5266 if (args
->codepointsfitted
)
5267 *args
->codepointsfitted
= index
+ length
;
5269 if (args
->linesfilled
)
5270 (*args
->linesfilled
)++;
5275 /* Find the smallest rectangle that bounds the text when it is printed in rect
5276 * according to the format options listed in format. If rect has 0 width and
5277 * height, then just find the smallest rectangle that bounds the text when it's
5278 * printed at location (rect->X, rect-Y). */
5279 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
5280 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5281 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
5282 INT
*codepointsfitted
, INT
*linesfilled
)
5284 HFONT oldfont
, gdifont
;
5285 struct measure_string_args args
;
5286 HDC temp_hdc
=NULL
, hdc
;
5292 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
5293 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
5294 bounds
, codepointsfitted
, linesfilled
);
5296 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
5297 return InvalidParameter
;
5301 hdc
= temp_hdc
= CreateCompatibleDC(0);
5302 if (!temp_hdc
) return OutOfMemory
;
5305 hdc
= graphics
->hdc
;
5307 if(linesfilled
) *linesfilled
= 0;
5308 if(codepointsfitted
) *codepointsfitted
= 0;
5311 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5319 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5320 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5321 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5322 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5323 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5325 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5326 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5328 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
5329 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
5330 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
5331 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
5332 if (scaled_rect
.Width
>= 0.5)
5334 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5335 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5338 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5339 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5341 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5342 oldfont
= SelectObject(hdc
, gdifont
);
5344 bounds
->X
= rect
->X
;
5345 bounds
->Y
= rect
->Y
;
5346 bounds
->Width
= 0.0;
5347 bounds
->Height
= 0.0;
5349 args
.bounds
= bounds
;
5350 args
.codepointsfitted
= &glyphs
;
5351 args
.linesfilled
= &lines
;
5354 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5355 measure_string_callback
, &args
);
5357 if (linesfilled
) *linesfilled
= lines
;
5358 if (codepointsfitted
) *codepointsfitted
= glyphs
;
5361 bounds
->Width
+= margin_x
* 2.0;
5363 SelectObject(hdc
, oldfont
);
5364 DeleteObject(gdifont
);
5372 struct draw_string_args
{
5373 GpGraphics
*graphics
;
5374 GDIPCONST GpBrush
*brush
;
5375 REAL x
, y
, rel_width
, rel_height
, ascent
;
5378 static GpStatus
draw_string_callback(HDC hdc
,
5379 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5380 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5381 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5382 INT underlined_index_count
, void *user_data
)
5384 struct draw_string_args
*args
= user_data
;
5388 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5389 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5391 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
5392 args
->brush
, &position
,
5393 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5395 if (stat
== Ok
&& underlined_index_count
)
5397 OUTLINETEXTMETRICW otm
;
5398 REAL underline_y
, underline_height
;
5401 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5403 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5404 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5406 for (i
=0; i
<underlined_index_count
; i
++)
5408 REAL start_x
, end_x
;
5410 INT ofs
= underlined_indexes
[i
] - index
;
5412 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5413 start_x
= text_size
.cx
/ args
->rel_width
;
5415 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5416 end_x
= text_size
.cx
/ args
->rel_width
;
5418 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5425 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5426 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5427 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5431 GpPointF pt
[3], rectcpy
[4];
5433 REAL rel_width
, rel_height
, margin_x
;
5434 INT save_state
, format_flags
= 0;
5436 struct draw_string_args args
;
5438 HDC hdc
, temp_hdc
=NULL
;
5439 TEXTMETRICW textmetric
;
5441 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5442 length
, font
, debugstr_rectf(rect
), format
, brush
);
5444 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5445 return InvalidParameter
;
5449 hdc
= graphics
->hdc
;
5453 hdc
= temp_hdc
= CreateCompatibleDC(0);
5457 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5459 format_flags
= format
->attr
;
5461 /* Should be no need to explicitly test for StringAlignmentNear as
5462 * that is default behavior if no alignment is passed. */
5463 if(format
->line_align
!= StringAlignmentNear
){
5464 RectF bounds
, in_rect
= *rect
;
5465 in_rect
.Height
= 0.0; /* avoid height clipping */
5466 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5468 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5470 if(format
->line_align
== StringAlignmentCenter
)
5471 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5472 else if(format
->line_align
== StringAlignmentFar
)
5473 offsety
= (rect
->Height
- bounds
.Height
);
5475 TRACE("line align %d, offsety %f\n", format
->line_align
, offsety
);
5478 save_state
= SaveDC(hdc
);
5486 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5487 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5488 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5489 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5490 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5492 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5493 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5494 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5495 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5496 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5498 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5499 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5501 scaled_rect
.X
= margin_x
* rel_width
;
5502 scaled_rect
.Y
= 0.0;
5503 scaled_rect
.Width
= rel_width
* rect
->Width
;
5504 scaled_rect
.Height
= rel_height
* rect
->Height
;
5505 if (scaled_rect
.Width
>= 0.5)
5507 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5508 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5511 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5512 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5514 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5515 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5516 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5518 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5519 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5520 SelectClipRgn(hdc
, rgn
);
5523 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5524 SelectObject(hdc
, gdifont
);
5526 args
.graphics
= graphics
;
5530 args
.y
= rect
->Y
+ offsety
;
5532 args
.rel_width
= rel_width
;
5533 args
.rel_height
= rel_height
;
5535 GetTextMetricsW(hdc
, &textmetric
);
5536 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5538 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5539 draw_string_callback
, &args
);
5542 DeleteObject(gdifont
);
5544 RestoreDC(hdc
, save_state
);
5551 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5553 TRACE("(%p)\n", graphics
);
5556 return InvalidParameter
;
5561 return GdipSetInfinite(graphics
->clip
);
5564 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5568 TRACE("(%p)\n", graphics
);
5571 return InvalidParameter
;
5576 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5577 stat
= METAFILE_ResetWorldTransform((GpMetafile
*)graphics
->image
);
5583 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5586 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5587 GpMatrixOrder order
)
5591 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5594 return InvalidParameter
;
5599 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5600 stat
= METAFILE_RotateWorldTransform((GpMetafile
*)graphics
->image
, angle
, order
);
5606 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5609 static GpStatus
begin_container(GpGraphics
*graphics
,
5610 GraphicsContainerType type
, GraphicsContainer
*state
)
5612 GraphicsContainerItem
*container
;
5615 if(!graphics
|| !state
)
5616 return InvalidParameter
;
5618 sts
= init_container(&container
, graphics
, type
);
5622 list_add_head(&graphics
->containers
, &container
->entry
);
5623 *state
= graphics
->contid
= container
->contid
;
5625 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5626 if (type
== BEGIN_CONTAINER
)
5627 METAFILE_BeginContainerNoParams((GpMetafile
*)graphics
->image
, container
->contid
);
5629 METAFILE_SaveGraphics((GpMetafile
*)graphics
->image
, container
->contid
);
5635 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5637 TRACE("(%p, %p)\n", graphics
, state
);
5638 return begin_container(graphics
, SAVE_GRAPHICS
, state
);
5641 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5642 GraphicsContainer
*state
)
5644 TRACE("(%p, %p)\n", graphics
, state
);
5645 return begin_container(graphics
, BEGIN_CONTAINER
, state
);
5648 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5650 GraphicsContainerItem
*container
;
5653 GpRectF scaled_srcrect
;
5654 REAL scale_x
, scale_y
;
5656 TRACE("(%p, %s, %s, %d, %p)\n", graphics
, debugstr_rectf(dstrect
), debugstr_rectf(srcrect
), unit
, state
);
5658 if(!graphics
|| !dstrect
|| !srcrect
|| unit
< UnitPixel
|| unit
> UnitMillimeter
|| !state
)
5659 return InvalidParameter
;
5661 stat
= init_container(&container
, graphics
, BEGIN_CONTAINER
);
5665 list_add_head(&graphics
->containers
, &container
->entry
);
5666 *state
= graphics
->contid
= container
->contid
;
5668 scale_x
= units_to_pixels(1.0, unit
, graphics
->xres
);
5669 scale_y
= units_to_pixels(1.0, unit
, graphics
->yres
);
5671 scaled_srcrect
.X
= scale_x
* srcrect
->X
;
5672 scaled_srcrect
.Y
= scale_y
* srcrect
->Y
;
5673 scaled_srcrect
.Width
= scale_x
* srcrect
->Width
;
5674 scaled_srcrect
.Height
= scale_y
* srcrect
->Height
;
5676 transform
.matrix
[0] = dstrect
->Width
/ scaled_srcrect
.Width
;
5677 transform
.matrix
[1] = 0.0;
5678 transform
.matrix
[2] = 0.0;
5679 transform
.matrix
[3] = dstrect
->Height
/ scaled_srcrect
.Height
;
5680 transform
.matrix
[4] = dstrect
->X
- scaled_srcrect
.X
;
5681 transform
.matrix
[5] = dstrect
->Y
- scaled_srcrect
.Y
;
5683 GdipMultiplyMatrix(&graphics
->worldtrans
, &transform
, MatrixOrderPrepend
);
5685 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5686 METAFILE_BeginContainer((GpMetafile
*)graphics
->image
, dstrect
, srcrect
, unit
, container
->contid
);
5692 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5694 GpRectF dstrectf
, srcrectf
;
5696 TRACE("(%p, %p, %p, %d, %p)\n", graphics
, dstrect
, srcrect
, unit
, state
);
5698 if (!dstrect
|| !srcrect
)
5699 return InvalidParameter
;
5701 dstrectf
.X
= dstrect
->X
;
5702 dstrectf
.Y
= dstrect
->Y
;
5703 dstrectf
.Width
= dstrect
->Width
;
5704 dstrectf
.Height
= dstrect
->Height
;
5706 srcrectf
.X
= srcrect
->X
;
5707 srcrectf
.Y
= srcrect
->Y
;
5708 srcrectf
.Width
= srcrect
->Width
;
5709 srcrectf
.Height
= srcrect
->Height
;
5711 return GdipBeginContainer(graphics
, &dstrectf
, &srcrectf
, unit
, state
);
5714 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5716 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5717 return NotImplemented
;
5720 static GpStatus
end_container(GpGraphics
*graphics
, GraphicsContainerType type
,
5721 GraphicsContainer state
)
5724 GraphicsContainerItem
*container
, *container2
;
5727 return InvalidParameter
;
5729 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5730 if(container
->contid
== state
&& container
->type
== type
)
5734 /* did not find a matching container */
5735 if(&container
->entry
== &graphics
->containers
)
5738 sts
= restore_container(graphics
, container
);
5742 /* remove all of the containers on top of the found container */
5743 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5744 if(container
->contid
== state
)
5746 list_remove(&container
->entry
);
5747 delete_container(container
);
5750 list_remove(&container
->entry
);
5751 delete_container(container
);
5753 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5754 if (type
== BEGIN_CONTAINER
)
5755 METAFILE_EndContainer((GpMetafile
*)graphics
->image
, state
);
5757 METAFILE_RestoreGraphics((GpMetafile
*)graphics
->image
, state
);
5763 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5765 TRACE("(%p, %x)\n", graphics
, state
);
5766 return end_container(graphics
, BEGIN_CONTAINER
, state
);
5769 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5771 TRACE("(%p, %x)\n", graphics
, state
);
5772 return end_container(graphics
, SAVE_GRAPHICS
, state
);
5775 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5776 REAL sy
, GpMatrixOrder order
)
5780 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5783 return InvalidParameter
;
5788 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5789 stat
= METAFILE_ScaleWorldTransform((GpMetafile
*)graphics
->image
, sx
, sy
, order
);
5795 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5798 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5801 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5803 if(!graphics
|| !srcgraphics
)
5804 return InvalidParameter
;
5806 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5809 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5810 CompositingMode mode
)
5812 TRACE("(%p, %d)\n", graphics
, mode
);
5815 return InvalidParameter
;
5820 if(graphics
->compmode
== mode
)
5823 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5827 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5828 EmfPlusRecordTypeSetCompositingMode
, mode
);
5833 graphics
->compmode
= mode
;
5838 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5839 CompositingQuality quality
)
5841 TRACE("(%p, %d)\n", graphics
, quality
);
5844 return InvalidParameter
;
5849 if(graphics
->compqual
== quality
)
5852 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5856 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5857 EmfPlusRecordTypeSetCompositingQuality
, quality
);
5862 graphics
->compqual
= quality
;
5867 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5868 InterpolationMode mode
)
5870 TRACE("(%p, %d)\n", graphics
, mode
);
5872 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5873 return InvalidParameter
;
5878 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5879 mode
= InterpolationModeBilinear
;
5881 if (mode
== InterpolationModeHighQuality
)
5882 mode
= InterpolationModeHighQualityBicubic
;
5884 if (mode
== graphics
->interpolation
)
5887 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5891 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5892 EmfPlusRecordTypeSetInterpolationMode
, mode
);
5897 graphics
->interpolation
= mode
;
5902 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5906 TRACE("(%p, %.2f)\n", graphics
, scale
);
5908 if(!graphics
|| (scale
<= 0.0))
5909 return InvalidParameter
;
5914 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5916 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
5921 graphics
->scale
= scale
;
5926 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5930 TRACE("(%p, %d)\n", graphics
, unit
);
5933 return InvalidParameter
;
5938 if(unit
== UnitWorld
)
5939 return InvalidParameter
;
5941 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5943 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
5948 graphics
->unit
= unit
;
5953 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5956 TRACE("(%p, %d)\n", graphics
, mode
);
5959 return InvalidParameter
;
5964 if(graphics
->pixeloffset
== mode
)
5967 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5971 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5972 EmfPlusRecordTypeSetPixelOffsetMode
, mode
);
5977 graphics
->pixeloffset
= mode
;
5982 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5986 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5989 FIXME("value is unused in rendering\n");
5992 return InvalidParameter
;
5994 graphics
->origin_x
= x
;
5995 graphics
->origin_y
= y
;
6000 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
6002 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
6004 if (!graphics
|| !x
|| !y
)
6005 return InvalidParameter
;
6007 *x
= graphics
->origin_x
;
6008 *y
= graphics
->origin_y
;
6013 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
6015 TRACE("(%p, %d)\n", graphics
, mode
);
6018 return InvalidParameter
;
6023 if(graphics
->smoothing
== mode
)
6026 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6028 BOOL antialias
= (mode
!= SmoothingModeDefault
&&
6029 mode
!= SmoothingModeNone
&& mode
!= SmoothingModeHighSpeed
);
6031 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6032 EmfPlusRecordTypeSetAntiAliasMode
, (mode
<< 1) + antialias
);
6037 graphics
->smoothing
= mode
;
6042 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
6044 TRACE("(%p, %d)\n", graphics
, contrast
);
6047 return InvalidParameter
;
6049 graphics
->textcontrast
= contrast
;
6054 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
6055 TextRenderingHint hint
)
6057 TRACE("(%p, %d)\n", graphics
, hint
);
6059 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
6060 return InvalidParameter
;
6065 if(graphics
->texthint
== hint
)
6068 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6071 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6072 EmfPlusRecordTypeSetTextRenderingHint
, hint
);
6077 graphics
->texthint
= hint
;
6082 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
6086 TRACE("(%p, %p)\n", graphics
, matrix
);
6088 if(!graphics
|| !matrix
)
6089 return InvalidParameter
;
6094 TRACE("%f,%f,%f,%f,%f,%f\n",
6095 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
6096 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
6098 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6099 stat
= METAFILE_SetWorldTransform((GpMetafile
*)graphics
->image
, matrix
);
6105 graphics
->worldtrans
= *matrix
;
6110 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
6111 REAL dy
, GpMatrixOrder order
)
6115 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
6118 return InvalidParameter
;
6123 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6124 stat
= METAFILE_TranslateWorldTransform((GpMetafile
*)graphics
->image
, dx
, dy
, order
);
6130 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
6133 /*****************************************************************************
6134 * GdipSetClipHrgn [GDIPLUS.@]
6136 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
6141 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
6144 return InvalidParameter
;
6149 /* hrgn is already in device units */
6150 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
6154 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6156 GdipDeleteRegion(region
);
6160 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
6165 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
6168 return InvalidParameter
;
6173 status
= GdipClonePath(path
, &clip_path
);
6176 GpMatrix world_to_device
;
6178 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
6179 CoordinateSpaceWorld
, &world_to_device
);
6180 status
= GdipTransformPath(clip_path
, &world_to_device
);
6182 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
6184 GdipDeletePath(clip_path
);
6189 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
6190 REAL width
, REAL height
,
6197 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6200 return InvalidParameter
;
6205 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6207 status
= METAFILE_SetClipRect((GpMetafile
*)graphics
->image
, x
, y
, width
, height
, mode
);
6215 rect
.Height
= height
;
6216 status
= GdipCreateRegionRect(&rect
, ®ion
);
6219 GpMatrix world_to_device
;
6221 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6222 status
= GdipTransformRegion(region
, &world_to_device
);
6224 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6226 GdipDeleteRegion(region
);
6231 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
6232 INT width
, INT height
,
6235 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6238 return InvalidParameter
;
6243 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
6246 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
6252 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
6254 if(!graphics
|| !region
)
6255 return InvalidParameter
;
6260 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6262 status
= METAFILE_SetClipRegion((GpMetafile
*)graphics
->image
, region
, mode
);
6267 status
= GdipCloneRegion(region
, &clip
);
6270 GpMatrix world_to_device
;
6272 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6273 status
= GdipTransformRegion(clip
, &world_to_device
);
6275 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
6277 GdipDeleteRegion(clip
);
6282 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
6288 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
6290 if(!graphics
|| !pen
|| count
<=0)
6291 return InvalidParameter
;
6296 status
= GdipCreatePath(FillModeAlternate
, &path
);
6297 if (status
!= Ok
) return status
;
6299 status
= GdipAddPathPolygon(path
, points
, count
);
6301 status
= GdipDrawPath(graphics
, pen
, path
);
6303 GdipDeletePath(path
);
6308 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
6315 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
6317 if(count
<=0) return InvalidParameter
;
6318 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6320 for(i
= 0;i
< count
; i
++){
6321 ptf
[i
].X
= (REAL
)points
[i
].X
;
6322 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
6325 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
6331 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
6333 TRACE("(%p, %p)\n", graphics
, dpi
);
6335 if(!graphics
|| !dpi
)
6336 return InvalidParameter
;
6341 *dpi
= graphics
->xres
;
6345 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
6347 TRACE("(%p, %p)\n", graphics
, dpi
);
6349 if(!graphics
|| !dpi
)
6350 return InvalidParameter
;
6355 *dpi
= graphics
->yres
;
6359 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
6360 GpMatrixOrder order
)
6365 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
6367 if(!graphics
|| !matrix
)
6368 return InvalidParameter
;
6373 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6374 ret
= METAFILE_MultiplyWorldTransform((GpMetafile
*)graphics
->image
, matrix
, order
);
6380 m
= graphics
->worldtrans
;
6382 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
6384 graphics
->worldtrans
= m
;
6389 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
6390 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
6392 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
6396 TRACE("(%p, %p)\n", graphics
, hdc
);
6398 if(!graphics
|| !hdc
)
6399 return InvalidParameter
;
6404 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6406 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
6408 else if (!graphics
->hdc
||
6409 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
6411 /* Create a fake HDC and fill it with a constant color. */
6415 BITMAPINFOHEADER bmih
;
6418 stat
= get_graphics_bounds(graphics
, &bounds
);
6422 graphics
->temp_hbitmap_width
= bounds
.Width
;
6423 graphics
->temp_hbitmap_height
= bounds
.Height
;
6425 bmih
.biSize
= sizeof(bmih
);
6426 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
6427 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
6429 bmih
.biBitCount
= 32;
6430 bmih
.biCompression
= BI_RGB
;
6431 bmih
.biSizeImage
= 0;
6432 bmih
.biXPelsPerMeter
= 0;
6433 bmih
.biYPelsPerMeter
= 0;
6435 bmih
.biClrImportant
= 0;
6437 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
6438 (void**)&graphics
->temp_bits
, NULL
, 0);
6440 return GenericError
;
6442 temp_hdc
= CreateCompatibleDC(0);
6445 DeleteObject(hbitmap
);
6446 return GenericError
;
6449 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6450 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
6452 SelectObject(temp_hdc
, hbitmap
);
6454 graphics
->temp_hbitmap
= hbitmap
;
6455 *hdc
= graphics
->temp_hdc
= temp_hdc
;
6459 *hdc
= graphics
->hdc
;
6463 graphics
->busy
= TRUE
;
6468 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
6472 TRACE("(%p, %p)\n", graphics
, hdc
);
6474 if(!graphics
|| !hdc
|| !graphics
->busy
)
6475 return InvalidParameter
;
6477 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6479 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
6481 else if (graphics
->temp_hdc
== hdc
)
6486 /* Find the pixels that have changed, and mark them as opaque. */
6487 pos
= (DWORD
*)graphics
->temp_bits
;
6488 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6490 if (*pos
!= DC_BACKGROUND_KEY
)
6497 /* Write the changed pixels to the real target. */
6498 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
6499 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
6500 graphics
->temp_hbitmap_width
* 4, PixelFormat32bppARGB
);
6503 DeleteDC(graphics
->temp_hdc
);
6504 DeleteObject(graphics
->temp_hbitmap
);
6505 graphics
->temp_hdc
= NULL
;
6506 graphics
->temp_hbitmap
= NULL
;
6508 else if (hdc
!= graphics
->hdc
)
6510 stat
= InvalidParameter
;
6514 graphics
->busy
= FALSE
;
6519 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
6523 GpMatrix device_to_world
;
6525 TRACE("(%p, %p)\n", graphics
, region
);
6527 if(!graphics
|| !region
)
6528 return InvalidParameter
;
6533 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
6536 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
6537 status
= GdipTransformRegion(clip
, &device_to_world
);
6540 GdipDeleteRegion(clip
);
6544 /* free everything except root node and header */
6545 delete_element(®ion
->node
);
6546 memcpy(region
, clip
, sizeof(GpRegion
));
6552 GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6553 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
6556 REAL scale_x
, scale_y
;
6558 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
6560 if (dst_space
!= src_space
)
6562 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
6563 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
6565 if(graphics
->unit
!= UnitDisplay
)
6567 scale_x
*= graphics
->scale
;
6568 scale_y
*= graphics
->scale
;
6571 /* transform from src_space to CoordinateSpacePage */
6574 case CoordinateSpaceWorld
:
6575 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
6577 case CoordinateSpacePage
:
6579 case CoordinateSpaceDevice
:
6580 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
6584 /* transform from CoordinateSpacePage to dst_space */
6587 case CoordinateSpaceWorld
:
6589 GpMatrix inverted_transform
= graphics
->worldtrans
;
6590 stat
= GdipInvertMatrix(&inverted_transform
);
6592 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
6595 case CoordinateSpacePage
:
6597 case CoordinateSpaceDevice
:
6598 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
6605 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6606 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6611 if(!graphics
|| !points
|| count
<= 0)
6612 return InvalidParameter
;
6617 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6619 if (src_space
== dst_space
) return Ok
;
6621 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6622 if (stat
!= Ok
) return stat
;
6624 return GdipTransformMatrixPoints(&matrix
, points
, count
);
6627 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6628 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6634 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6637 return InvalidParameter
;
6639 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6643 for(i
= 0; i
< count
; i
++){
6644 pointsF
[i
].X
= (REAL
)points
[i
].X
;
6645 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
6648 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6651 for(i
= 0; i
< count
; i
++){
6652 points
[i
].X
= gdip_round(pointsF
[i
].X
);
6653 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
6660 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6672 /*****************************************************************************
6673 * GdipTranslateClip [GDIPLUS.@]
6675 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6677 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6680 return InvalidParameter
;
6685 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6688 /*****************************************************************************
6689 * GdipTranslateClipI [GDIPLUS.@]
6691 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6693 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6696 return InvalidParameter
;
6701 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6705 /*****************************************************************************
6706 * GdipMeasureDriverString [GDIPLUS.@]
6708 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6709 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6710 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6712 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6715 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6717 TEXTMETRICW textmetric
;
6718 const WORD
*glyph_indices
;
6719 WORD
*dynamic_glyph_indices
=NULL
;
6720 REAL rel_width
, rel_height
, ascent
, descent
;
6723 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6725 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6726 return InvalidParameter
;
6729 length
= strlenW(text
);
6733 boundingBox
->X
= 0.0;
6734 boundingBox
->Y
= 0.0;
6735 boundingBox
->Width
= 0.0;
6736 boundingBox
->Height
= 0.0;
6739 if (flags
& unsupported_flags
)
6740 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6742 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6744 hdc
= CreateCompatibleDC(0);
6745 SelectObject(hdc
, hfont
);
6747 GetTextMetricsW(hdc
, &textmetric
);
6757 GpMatrix xform
= *matrix
;
6758 GdipTransformMatrixPoints(&xform
, pt
, 3);
6760 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6761 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6762 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6763 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6764 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6766 if (flags
& DriverStringOptionsCmapLookup
)
6768 glyph_indices
= dynamic_glyph_indices
= heap_alloc_zero(sizeof(WORD
) * length
);
6772 DeleteObject(hfont
);
6776 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6779 glyph_indices
= text
;
6781 min_x
= max_x
= x
= positions
[0].X
;
6782 min_y
= max_y
= y
= positions
[0].Y
;
6784 ascent
= textmetric
.tmAscent
/ rel_height
;
6785 descent
= textmetric
.tmDescent
/ rel_height
;
6787 for (i
=0; i
<length
; i
++)
6792 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6798 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6799 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6801 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6802 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6803 if (min_x
> x
) min_x
= x
;
6805 x
+= char_width
/ rel_width
;
6807 if (max_x
< x
) max_x
= x
;
6810 heap_free(dynamic_glyph_indices
);
6812 DeleteObject(hfont
);
6814 boundingBox
->X
= min_x
;
6815 boundingBox
->Y
= min_y
;
6816 boundingBox
->Width
= max_x
- min_x
;
6817 boundingBox
->Height
= max_y
- min_y
;
6822 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6823 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6824 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6825 INT flags
, GDIPCONST GpMatrix
*matrix
)
6827 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6835 if (flags
& unsupported_flags
)
6836 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6838 if (!(flags
& DriverStringOptionsCmapLookup
))
6839 eto_flags
|= ETO_GLYPH_INDEX
;
6841 save_state
= SaveDC(graphics
->hdc
);
6842 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6843 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6845 status
= get_clip_hrgn(graphics
, &hrgn
);
6847 if (status
== Ok
&& hrgn
)
6849 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
6854 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6856 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6857 SelectObject(graphics
->hdc
, hfont
);
6859 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6861 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6863 RestoreDC(graphics
->hdc
, save_state
);
6865 DeleteObject(hfont
);
6870 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6871 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6872 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6873 INT flags
, GDIPCONST GpMatrix
*matrix
)
6875 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6877 PointF
*real_positions
, real_position
;
6881 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6882 DWORD max_glyphsize
=0;
6883 GLYPHMETRICS glyphmetrics
;
6884 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6887 int text_mask_stride
;
6889 int pixel_data_stride
;
6891 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6896 if (!(flags
& DriverStringOptionsCmapLookup
))
6897 ggo_flags
|= GGO_GLYPH_INDEX
;
6899 if (flags
& unsupported_flags
)
6900 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6902 pti
= heap_alloc_zero(sizeof(POINT
) * length
);
6906 if (flags
& DriverStringOptionsRealizedAdvance
)
6908 real_position
= positions
[0];
6910 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6914 real_positions
= heap_alloc_zero(sizeof(PointF
) * length
);
6915 if (!real_positions
)
6921 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6923 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6925 heap_free(real_positions
);
6928 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6930 hdc
= CreateCompatibleDC(0);
6931 SelectObject(hdc
, hfont
);
6933 /* Get the boundaries of the text to be drawn */
6934 for (i
=0; i
<length
; i
++)
6937 int left
, top
, right
, bottom
;
6939 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6940 &glyphmetrics
, 0, NULL
, &identity
);
6942 if (glyphsize
== GDI_ERROR
)
6944 ERR("GetGlyphOutlineW failed\n");
6947 DeleteObject(hfont
);
6948 return GenericError
;
6951 if (glyphsize
> max_glyphsize
)
6952 max_glyphsize
= glyphsize
;
6956 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6957 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6958 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6959 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6961 if (left
< min_x
) min_x
= left
;
6962 if (top
< min_y
) min_y
= top
;
6963 if (right
> max_x
) max_x
= right
;
6964 if (bottom
> max_y
) max_y
= bottom
;
6967 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6969 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6970 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6974 if (max_glyphsize
== 0)
6975 /* Nothing to draw. */
6978 glyph_mask
= heap_alloc_zero(max_glyphsize
);
6979 text_mask
= heap_alloc_zero((max_x
- min_x
) * (max_y
- min_y
));
6980 text_mask_stride
= max_x
- min_x
;
6982 if (!(glyph_mask
&& text_mask
))
6984 heap_free(glyph_mask
);
6985 heap_free(text_mask
);
6988 DeleteObject(hfont
);
6992 /* Generate a mask for the text */
6993 for (i
=0; i
<length
; i
++)
6996 int left
, top
, stride
;
6998 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6999 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
7001 if (ret
== GDI_ERROR
|| ret
== 0)
7002 continue; /* empty glyph */
7004 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7005 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7006 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
7008 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
7010 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
7011 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
7012 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
7014 *text_val
= min(64, *text_val
+ *glyph_val
);
7023 DeleteObject(hfont
);
7024 heap_free(glyph_mask
);
7026 /* get the brush data */
7027 pixel_data
= heap_alloc_zero(4 * (max_x
- min_x
) * (max_y
- min_y
));
7030 heap_free(text_mask
);
7034 pixel_area
.X
= min_x
;
7035 pixel_area
.Y
= min_y
;
7036 pixel_area
.Width
= max_x
- min_x
;
7037 pixel_area
.Height
= max_y
- min_y
;
7038 pixel_data_stride
= pixel_area
.Width
* 4;
7040 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
7043 heap_free(text_mask
);
7044 heap_free(pixel_data
);
7048 /* multiply the brush data by the mask */
7049 for (y
=0; y
<pixel_area
.Height
; y
++)
7051 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
7052 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
7053 for (x
=0; x
<pixel_area
.Width
; x
++)
7055 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
7061 heap_free(text_mask
);
7063 /* draw the result */
7064 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
7065 pixel_area
.Height
, pixel_data_stride
, PixelFormat32bppARGB
);
7067 heap_free(pixel_data
);
7072 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7073 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7074 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7075 INT flags
, GDIPCONST GpMatrix
*matrix
)
7077 GpStatus stat
= NotImplemented
;
7080 length
= strlenW(text
);
7082 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
7083 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
7084 brush
->bt
== BrushTypeSolidColor
&&
7085 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
7086 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7087 brush
, positions
, flags
, matrix
);
7088 if (stat
== NotImplemented
)
7089 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7090 brush
, positions
, flags
, matrix
);
7094 /*****************************************************************************
7095 * GdipDrawDriverString [GDIPLUS.@]
7097 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7098 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
7099 GDIPCONST PointF
*positions
, INT flags
,
7100 GDIPCONST GpMatrix
*matrix
)
7102 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
7104 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
7105 return InvalidParameter
;
7107 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
7108 brush
, positions
, flags
, matrix
);
7111 /*****************************************************************************
7112 * GdipIsVisibleClipEmpty [GDIPLUS.@]
7114 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
7119 TRACE("(%p, %p)\n", graphics
, res
);
7121 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
7124 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
7127 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
7130 GdipDeleteRegion(rgn
);
7134 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
7138 TRACE("(%p) stub\n", graphics
);
7141 FIXME("not implemented\n");
7143 return NotImplemented
;
7146 GpStatus WINGDIPAPI
GdipGraphicsSetAbort(GpGraphics
*graphics
, GdiplusAbort
*pabort
)
7148 TRACE("(%p, %p)\n", graphics
, pabort
);
7151 return InvalidParameter
;
7154 FIXME("Abort callback is not supported.\n");