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 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
55 GpCoordinateSpace src_space
, GpMatrix
*matrix
);
57 /* Converts from gdiplus path point type to gdi path point type. */
58 static BYTE
convert_path_point_type(BYTE type
)
62 switch(type
& PathPointTypePathTypeMask
){
63 case PathPointTypeBezier
:
66 case PathPointTypeLine
:
69 case PathPointTypeStart
:
73 ERR("Bad point type\n");
77 if(type
& PathPointTypeCloseSubpath
)
78 ret
|= PT_CLOSEFIGURE
;
83 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
89 case BrushTypeSolidColor
:
91 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
95 case BrushTypeHatchFill
:
97 const GpHatch
*hatch
= (const GpHatch
*)brush
;
98 argb
= hatch
->forecol
;
101 case BrushTypeLinearGradient
:
103 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
104 argb
= line
->startcolor
;
107 case BrushTypePathGradient
:
109 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
110 argb
= grad
->centercolor
;
114 FIXME("unhandled brush type %d\n", brush
->bt
);
118 return ARGB2COLORREF(argb
);
121 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
124 BITMAPINFOHEADER bmih
;
128 bmih
.biSize
= sizeof(bmih
);
132 bmih
.biBitCount
= 32;
133 bmih
.biCompression
= BI_RGB
;
134 bmih
.biSizeImage
= 0;
136 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
139 const char *hatch_data
;
141 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
143 for (y
= 0; y
< 8; y
++)
145 for (x
= 0; x
< 8; x
++)
147 if (hatch_data
[y
] & (0x80 >> x
))
148 bits
[y
* 8 + x
] = hatch
->forecol
;
150 bits
[y
* 8 + x
] = hatch
->backcol
;
156 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
158 for (y
= 0; y
< 64; y
++)
159 bits
[y
] = hatch
->forecol
;
166 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
170 case BrushTypeSolidColor
:
172 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
173 lb
->lbStyle
= BS_SOLID
;
174 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
179 case BrushTypeHatchFill
:
181 const GpHatch
*hatch
= (const GpHatch
*)brush
;
184 hbmp
= create_hatch_bitmap(hatch
);
185 if (!hbmp
) return OutOfMemory
;
187 lb
->lbStyle
= BS_PATTERN
;
189 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
194 FIXME("unhandled brush type %d\n", brush
->bt
);
195 lb
->lbStyle
= BS_SOLID
;
196 lb
->lbColor
= get_gdi_brush_color(brush
);
202 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
207 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
213 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
218 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
220 gdibrush
= CreateBrushIndirect(&lb
);
221 free_gdi_logbrush(&lb
);
226 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
231 INT save_state
, i
, numdashes
;
233 DWORD dash_array
[MAX_DASHLEN
];
235 save_state
= SaveDC(graphics
->hdc
);
237 EndPath(graphics
->hdc
);
239 if(pen
->unit
== UnitPixel
){
243 /* Get an estimate for the amount the pen width is affected by the world
244 * transform. (This is similar to what some of the wine drivers do.) */
249 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
250 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
251 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
253 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
254 width
*= graphics
->scale
;
257 if(pen
->dash
== DashStyleCustom
){
258 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
260 TRACE("dashes are: ");
261 for(i
= 0; i
< numdashes
; i
++){
262 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
263 TRACE("%d, ", dash_array
[i
]);
265 TRACE("\n and the pen style is %x\n", pen
->style
);
267 create_gdi_logbrush(pen
->brush
, &lb
);
268 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
269 numdashes
, dash_array
);
270 free_gdi_logbrush(&lb
);
274 create_gdi_logbrush(pen
->brush
, &lb
);
275 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
276 free_gdi_logbrush(&lb
);
279 SelectObject(graphics
->hdc
, gdipen
);
284 static void restore_dc(GpGraphics
*graphics
, INT state
)
286 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
287 RestoreDC(graphics
->hdc
, state
);
290 /* This helper applies all the changes that the points listed in ptf need in
291 * order to be drawn on the device context. In the end, this should include at
293 * -scaling by page unit
294 * -applying world transformation
295 * -converting from float to int
296 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
297 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
298 * gdi to draw, and these functions would irreparably mess with line widths.
300 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
301 GpPointF
*ptf
, INT count
)
303 REAL scale_x
, scale_y
;
307 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
308 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
310 /* apply page scale */
311 if(graphics
->unit
!= UnitDisplay
)
313 scale_x
*= graphics
->scale
;
314 scale_y
*= graphics
->scale
;
317 matrix
= graphics
->worldtrans
;
318 GdipScaleMatrix(&matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
319 GdipTransformMatrixPoints(&matrix
, ptf
, count
);
321 for(i
= 0; i
< count
; i
++){
322 pti
[i
].x
= gdip_round(ptf
[i
].X
);
323 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
327 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
328 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
330 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
332 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
334 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
335 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
341 bf
.BlendOp
= AC_SRC_OVER
;
343 bf
.SourceConstantAlpha
= 255;
344 bf
.AlphaFormat
= AC_SRC_ALPHA
;
346 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
347 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
351 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
353 /* clipping region is in device coords */
354 return GdipGetRegionHRgn(graphics
->clip
, NULL
, hrgn
);
357 /* Draw ARGB data to the given graphics object */
358 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
359 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, const PixelFormat fmt
)
361 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
364 for (y
=0; y
<src_height
; y
++)
366 for (x
=0; x
<src_width
; x
++)
368 ARGB dst_color
, src_color
;
369 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
371 if (!(src_color
& 0xff000000))
374 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
375 if (fmt
& PixelFormatPAlpha
)
376 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over_fgpremult(dst_color
, src_color
));
378 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
385 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
386 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
390 BITMAPINFOHEADER bih
;
393 hdc
= CreateCompatibleDC(0);
395 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
396 bih
.biWidth
= src_width
;
397 bih
.biHeight
= -src_height
;
400 bih
.biCompression
= BI_RGB
;
402 bih
.biXPelsPerMeter
= 0;
403 bih
.biYPelsPerMeter
= 0;
405 bih
.biClrImportant
= 0;
407 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
408 (void**)&temp_bits
, NULL
, 0);
410 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
||
411 fmt
& PixelFormatPAlpha
)
412 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
414 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
415 4 * src_width
, src
, src_stride
);
417 SelectObject(hdc
, hbitmap
);
418 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
419 hdc
, 0, 0, src_width
, src_height
);
421 DeleteObject(hbitmap
);
426 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
427 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
, PixelFormat fmt
)
431 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
437 HRGN hrgn
, visible_rgn
;
439 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
443 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
452 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
453 DeleteObject(visible_rgn
);
457 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
459 size
= GetRegionData(hrgn
, 0, NULL
);
461 rgndata
= GdipAlloc(size
);
468 GetRegionData(hrgn
, size
, rgndata
);
470 rects
= (RECT
*)rgndata
->Buffer
;
472 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
474 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
475 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
476 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
486 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
488 ERR("This should not be used for metafiles; fix caller\n");
489 return NotImplemented
;
496 stat
= get_clip_hrgn(graphics
, &hrgn
);
501 save
= SaveDC(graphics
->hdc
);
504 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
507 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
509 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
510 src_height
, src_stride
, fmt
);
512 RestoreDC(graphics
->hdc
, save
);
520 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
521 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
523 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
, fmt
);
526 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
528 INT start_a
, end_a
, final_a
;
531 pos
= gdip_round(position
* 0xff);
533 start_a
= ((start
>> 24) & 0xff) * (pos
^ 0xff);
534 end_a
= ((end
>> 24) & 0xff) * pos
;
536 final_a
= start_a
+ end_a
;
538 if (final_a
< 0xff) return 0;
540 return (final_a
/ 0xff) << 24 |
541 ((((start
>> 16) & 0xff) * start_a
+ (((end
>> 16) & 0xff) * end_a
)) / final_a
) << 16 |
542 ((((start
>> 8) & 0xff) * start_a
+ (((end
>> 8) & 0xff) * end_a
)) / final_a
) << 8 |
543 (((start
& 0xff) * start_a
+ ((end
& 0xff) * end_a
)) / final_a
);
546 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
550 /* clamp to between 0.0 and 1.0, using the wrap mode */
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 static 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 static BOOL
brush_can_fill_path(GpBrush
*brush
)
1011 case BrushTypeSolidColor
:
1013 case BrushTypeHatchFill
:
1015 GpHatch
*hatch
= (GpHatch
*)brush
;
1016 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
1017 ((hatch
->backcol
& 0xff000000) == 0xff000000);
1019 case BrushTypeLinearGradient
:
1020 case BrushTypeTextureFill
:
1021 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
1027 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
1031 case BrushTypeSolidColor
:
1033 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1034 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1039 /* partially transparent fill */
1041 SelectClipPath(graphics
->hdc
, RGN_AND
);
1042 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1044 HDC hdc
= CreateCompatibleDC(NULL
);
1048 SelectObject(hdc
, bmp
);
1049 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1057 /* else fall through */
1061 HBRUSH gdibrush
, old_brush
;
1063 gdibrush
= create_gdi_brush(brush
);
1064 if (!gdibrush
) return;
1066 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1067 FillPath(graphics
->hdc
);
1068 SelectObject(graphics
->hdc
, old_brush
);
1069 DeleteObject(gdibrush
);
1075 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1079 case BrushTypeSolidColor
:
1080 case BrushTypeHatchFill
:
1081 case BrushTypeLinearGradient
:
1082 case BrushTypeTextureFill
:
1083 case BrushTypePathGradient
:
1090 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1091 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1095 case BrushTypeSolidColor
:
1098 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1099 for (x
=0; x
<fill_area
->Width
; x
++)
1100 for (y
=0; y
<fill_area
->Height
; y
++)
1101 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1104 case BrushTypeHatchFill
:
1107 GpHatch
*fill
= (GpHatch
*)brush
;
1108 const char *hatch_data
;
1110 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1111 return NotImplemented
;
1113 for (x
=0; x
<fill_area
->Width
; x
++)
1114 for (y
=0; y
<fill_area
->Height
; y
++)
1118 /* FIXME: Account for the rendering origin */
1119 hx
= (x
+ fill_area
->X
) % 8;
1120 hy
= (y
+ fill_area
->Y
) % 8;
1122 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1123 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1125 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1130 case BrushTypeLinearGradient
:
1132 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1133 GpPointF draw_points
[3], line_points
[3];
1135 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1136 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1139 draw_points
[0].X
= fill_area
->X
;
1140 draw_points
[0].Y
= fill_area
->Y
;
1141 draw_points
[1].X
= fill_area
->X
+1;
1142 draw_points
[1].Y
= fill_area
->Y
;
1143 draw_points
[2].X
= fill_area
->X
;
1144 draw_points
[2].Y
= fill_area
->Y
+1;
1146 /* Transform the points to a co-ordinate space where X is the point's
1147 * position in the gradient, 0.0 being the start point and 1.0 the
1149 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1150 CoordinateSpaceDevice
, draw_points
, 3);
1154 line_points
[0] = fill
->startpoint
;
1155 line_points
[1] = fill
->endpoint
;
1156 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1157 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1159 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1164 stat
= GdipInvertMatrix(world_to_gradient
);
1167 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1169 GdipDeleteMatrix(world_to_gradient
);
1174 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1175 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1177 for (y
=0; y
<fill_area
->Height
; y
++)
1179 for (x
=0; x
<fill_area
->Width
; x
++)
1181 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1183 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1190 case BrushTypeTextureFill
:
1192 GpTexture
*fill
= (GpTexture
*)brush
;
1193 GpPointF draw_points
[3];
1200 if (fill
->image
->type
!= ImageTypeBitmap
)
1202 FIXME("metafile texture brushes not implemented\n");
1203 return NotImplemented
;
1206 bitmap
= (GpBitmap
*)fill
->image
;
1207 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1209 src_area
.X
= src_area
.Y
= 0;
1210 src_area
.Width
= bitmap
->width
;
1211 src_area
.Height
= bitmap
->height
;
1213 draw_points
[0].X
= fill_area
->X
;
1214 draw_points
[0].Y
= fill_area
->Y
;
1215 draw_points
[1].X
= fill_area
->X
+1;
1216 draw_points
[1].Y
= fill_area
->Y
;
1217 draw_points
[2].X
= fill_area
->X
;
1218 draw_points
[2].Y
= fill_area
->Y
+1;
1220 /* Transform the points to the co-ordinate space of the bitmap. */
1221 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1222 CoordinateSpaceDevice
, draw_points
, 3);
1226 GpMatrix world_to_texture
= fill
->transform
;
1228 stat
= GdipInvertMatrix(&world_to_texture
);
1230 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1233 if (stat
== Ok
&& !fill
->bitmap_bits
)
1235 BitmapData lockeddata
;
1237 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1238 if (!fill
->bitmap_bits
)
1243 lockeddata
.Width
= bitmap
->width
;
1244 lockeddata
.Height
= bitmap
->height
;
1245 lockeddata
.Stride
= src_stride
;
1246 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1247 lockeddata
.Scan0
= fill
->bitmap_bits
;
1249 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1250 PixelFormat32bppARGB
, &lockeddata
);
1254 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1257 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1258 bitmap
->width
, bitmap
->height
,
1259 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
1263 GdipFree(fill
->bitmap_bits
);
1264 fill
->bitmap_bits
= NULL
;
1270 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1271 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1272 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1273 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1275 for (y
=0; y
<fill_area
->Height
; y
++)
1277 for (x
=0; x
<fill_area
->Width
; x
++)
1280 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1281 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1283 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1284 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1285 &point
, fill
->imageattributes
, graphics
->interpolation
,
1286 graphics
->pixeloffset
);
1293 case BrushTypePathGradient
:
1295 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1297 GpMatrix world_to_device
;
1299 int i
, figure_start
=0;
1300 GpPointF start_point
, end_point
, center_point
;
1302 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1303 INT min_y
, max_y
, min_x
, max_x
;
1306 static BOOL transform_fixme_once
;
1308 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1312 FIXME("path gradient focus not implemented\n");
1319 FIXME("path gradient gamma correction not implemented\n");
1322 if (fill
->blendcount
)
1326 FIXME("path gradient blend not implemented\n");
1329 if (fill
->pblendcount
)
1333 FIXME("path gradient preset blend not implemented\n");
1336 if (!transform_fixme_once
)
1338 BOOL is_identity
=TRUE
;
1339 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1342 FIXME("path gradient transform not implemented\n");
1343 transform_fixme_once
= TRUE
;
1347 stat
= GdipClonePath(fill
->path
, &flat_path
);
1352 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1353 CoordinateSpaceWorld
, &world_to_device
);
1356 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1360 center_point
= fill
->center
;
1361 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1365 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1370 GdipDeletePath(flat_path
);
1374 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1376 int start_center_line
=0, end_center_line
=0;
1377 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1378 REAL center_distance
;
1379 ARGB start_color
, end_color
;
1382 type
= flat_path
->pathdata
.Types
[i
];
1384 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1387 start_point
= flat_path
->pathdata
.Points
[i
];
1389 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1391 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1393 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1394 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1396 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1398 end_point
= flat_path
->pathdata
.Points
[i
+1];
1399 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1404 outer_color
= start_color
;
1406 min_yf
= center_point
.Y
;
1407 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1408 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1410 if (min_yf
< fill_area
->Y
)
1411 min_y
= fill_area
->Y
;
1413 min_y
= (INT
)ceil(min_yf
);
1415 max_yf
= center_point
.Y
;
1416 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1417 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1419 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1420 max_y
= fill_area
->Y
+ fill_area
->Height
;
1422 max_y
= (INT
)ceil(max_yf
);
1424 dy
= end_point
.Y
- start_point
.Y
;
1425 dx
= end_point
.X
- start_point
.X
;
1427 /* This is proportional to the distance from start-end line to center point. */
1428 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1429 dx
* (center_point
.Y
- start_point
.Y
);
1431 for (y
=min_y
; y
<max_y
; y
++)
1435 if (!seen_start
&& yf
>= start_point
.Y
)
1438 start_center_line
^= 1;
1440 if (!seen_end
&& yf
>= end_point
.Y
)
1443 end_center_line
^= 1;
1445 if (!seen_center
&& yf
>= center_point
.Y
)
1448 start_center_line
^= 1;
1449 end_center_line
^= 1;
1452 if (start_center_line
)
1453 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1455 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1457 if (end_center_line
)
1458 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1460 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1462 if (line1_xf
< line2_xf
)
1464 min_x
= (INT
)ceil(line1_xf
);
1465 max_x
= (INT
)ceil(line2_xf
);
1469 min_x
= (INT
)ceil(line2_xf
);
1470 max_x
= (INT
)ceil(line1_xf
);
1473 if (min_x
< fill_area
->X
)
1474 min_x
= fill_area
->X
;
1475 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1476 max_x
= fill_area
->X
+ fill_area
->Width
;
1478 for (x
=min_x
; x
<max_x
; x
++)
1483 if (start_color
!= end_color
)
1485 REAL blend_amount
, pdy
, pdx
;
1486 pdy
= yf
- center_point
.Y
;
1487 pdx
= xf
- center_point
.X
;
1488 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1489 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1492 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1493 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1495 distance
= distance
/ center_distance
;
1497 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1498 blend_colors(outer_color
, fill
->centercolor
, distance
);
1503 GdipDeletePath(flat_path
);
1507 return NotImplemented
;
1511 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1512 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1513 * should not be called on an hdc that has a path you care about. */
1514 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1515 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1517 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1519 HBRUSH brush
= NULL
;
1521 PointF ptf
[4], *custptf
= NULL
;
1522 POINT pt
[4], *custpt
= NULL
;
1524 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1529 if((x1
== x2
) && (y1
== y2
))
1532 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1534 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1536 brush
= CreateSolidBrush(color
);
1537 lb
.lbStyle
= BS_SOLID
;
1540 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1541 PS_JOIN_MITER
, 1, &lb
, 0,
1543 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1544 oldpen
= SelectObject(graphics
->hdc
, pen
);
1551 case LineCapSquareAnchor
:
1552 case LineCapDiamondAnchor
:
1553 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1554 if(cap
== LineCapDiamondAnchor
){
1555 dsmall
= cos(theta
+ M_PI_2
) * size
;
1556 dbig
= sin(theta
+ M_PI_2
) * size
;
1559 dsmall
= cos(theta
+ M_PI_4
) * size
;
1560 dbig
= sin(theta
+ M_PI_4
) * size
;
1563 ptf
[0].X
= x2
- dsmall
;
1564 ptf
[1].X
= x2
+ dbig
;
1566 ptf
[0].Y
= y2
- dbig
;
1567 ptf
[3].Y
= y2
+ dsmall
;
1569 ptf
[1].Y
= y2
- dsmall
;
1570 ptf
[2].Y
= y2
+ dbig
;
1572 ptf
[3].X
= x2
- dbig
;
1573 ptf
[2].X
= x2
+ dsmall
;
1575 transform_and_round_points(graphics
, pt
, ptf
, 4);
1576 Polygon(graphics
->hdc
, pt
, 4);
1579 case LineCapArrowAnchor
:
1580 size
= size
* 4.0 / sqrt(3.0);
1582 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1583 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1588 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1589 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1597 transform_and_round_points(graphics
, pt
, ptf
, 3);
1598 Polygon(graphics
->hdc
, pt
, 3);
1601 case LineCapRoundAnchor
:
1602 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1609 transform_and_round_points(graphics
, pt
, ptf
, 2);
1610 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1613 case LineCapTriangle
:
1615 dx
= cos(M_PI_2
+ theta
) * size
;
1616 dy
= sin(M_PI_2
+ theta
) * size
;
1623 dx
= cos(theta
) * size
;
1624 dy
= sin(theta
) * size
;
1629 transform_and_round_points(graphics
, pt
, ptf
, 3);
1630 Polygon(graphics
->hdc
, pt
, 3);
1634 dx
= dy
= size
/ 2.0;
1641 dx
= -cos(M_PI_2
+ theta
) * size
;
1642 dy
= -sin(M_PI_2
+ theta
) * size
;
1649 transform_and_round_points(graphics
, pt
, ptf
, 4);
1650 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1651 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1658 count
= custom
->pathdata
.Count
;
1659 custptf
= GdipAlloc(count
* sizeof(PointF
));
1660 custpt
= GdipAlloc(count
* sizeof(POINT
));
1661 tp
= GdipAlloc(count
);
1663 if(!custptf
|| !custpt
|| !tp
)
1666 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1668 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1669 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1670 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1672 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1673 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1675 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1677 for(i
= 0; i
< count
; i
++)
1678 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1681 BeginPath(graphics
->hdc
);
1682 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1683 EndPath(graphics
->hdc
);
1684 StrokeAndFillPath(graphics
->hdc
);
1687 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1699 SelectObject(graphics
->hdc
, oldbrush
);
1700 SelectObject(graphics
->hdc
, oldpen
);
1701 DeleteObject(brush
);
1706 /* Shortens the line by the given percent by changing x2, y2.
1707 * If percent is > 1.0 then the line will change direction.
1708 * If percent is negative it can lengthen the line. */
1709 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1711 REAL dist
, theta
, dx
, dy
;
1713 if((y1
== *y2
) && (x1
== *x2
))
1716 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1717 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1718 dx
= cos(theta
) * dist
;
1719 dy
= sin(theta
) * dist
;
1725 /* Shortens the line by the given amount by changing x2, y2.
1726 * If the amount is greater than the distance, the line will become length 0.
1727 * If the amount is negative, it can lengthen the line. */
1728 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1730 REAL dx
, dy
, percent
;
1734 if(dx
== 0 && dy
== 0)
1737 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1744 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1747 /* Conducts a linear search to find the bezier points that will back off
1748 * the endpoint of the curve by a distance of amt. Linear search works
1749 * better than binary in this case because there are multiple solutions,
1750 * and binary searches often find a bad one. I don't think this is what
1751 * Windows does but short of rendering the bezier without GDI's help it's
1752 * the best we can do. If rev then work from the start of the passed points
1753 * instead of the end. */
1754 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1757 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1758 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1767 origx
= pt
[fourth
].X
;
1768 origy
= pt
[fourth
].Y
;
1769 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1771 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1772 /* reset bezier points to original values */
1773 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1774 /* Perform magic on bezier points. Order is important here.*/
1775 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1776 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1777 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1778 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1779 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1780 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1782 dx
= pt
[fourth
].X
- origx
;
1783 dy
= pt
[fourth
].Y
- origy
;
1785 diff
= sqrt(dx
* dx
+ dy
* dy
);
1786 percent
+= 0.0005 * amt
;
1790 /* Draws a combination of bezier curves and lines between points. */
1791 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1792 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1794 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1795 BYTE
*tp
= GdipAlloc(count
);
1796 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1798 GpStatus status
= GenericError
;
1804 if(!pti
|| !tp
|| !ptcopy
){
1805 status
= OutOfMemory
;
1809 for(i
= 1; i
< count
; i
++){
1810 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1811 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1812 || !(types
[i
+ 2] & PathPointTypeBezier
)){
1813 ERR("Bad bezier points\n");
1820 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1822 /* If we are drawing caps, go through the points and adjust them accordingly,
1823 * and draw the caps. */
1825 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1826 case PathPointTypeBezier
:
1827 if(pen
->endcap
== LineCapArrowAnchor
)
1828 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1829 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1830 shorten_bezier_amt(&ptcopy
[count
- 4],
1831 pen
->width
* pen
->customend
->inset
, FALSE
);
1833 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1834 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1835 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1836 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1839 case PathPointTypeLine
:
1840 if(pen
->endcap
== LineCapArrowAnchor
)
1841 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1842 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1844 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1845 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1846 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1847 pen
->customend
->inset
* pen
->width
);
1849 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1850 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1855 ERR("Bad path last point\n");
1859 /* Find start of points */
1860 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1861 == PathPointTypeStart
); j
++);
1863 switch(types
[j
] & PathPointTypePathTypeMask
){
1864 case PathPointTypeBezier
:
1865 if(pen
->startcap
== LineCapArrowAnchor
)
1866 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1867 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1868 shorten_bezier_amt(&ptcopy
[j
- 1],
1869 pen
->width
* pen
->customstart
->inset
, TRUE
);
1871 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1872 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1873 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1874 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1877 case PathPointTypeLine
:
1878 if(pen
->startcap
== LineCapArrowAnchor
)
1879 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1880 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1882 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1883 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1884 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1885 pen
->customstart
->inset
* pen
->width
);
1887 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1888 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1893 ERR("Bad path points\n");
1898 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1900 for(i
= 0; i
< count
; i
++){
1901 tp
[i
] = convert_path_point_type(types
[i
]);
1904 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1916 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1920 BeginPath(graphics
->hdc
);
1921 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1922 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1923 EndPath(graphics
->hdc
);
1927 typedef struct _GraphicsContainerItem
{
1929 GraphicsContainer contid
;
1931 SmoothingMode smoothing
;
1932 CompositingQuality compqual
;
1933 InterpolationMode interpolation
;
1934 CompositingMode compmode
;
1935 TextRenderingHint texthint
;
1938 PixelOffsetMode pixeloffset
;
1940 GpMatrix worldtrans
;
1942 INT origin_x
, origin_y
;
1943 } GraphicsContainerItem
;
1945 static GpStatus
init_container(GraphicsContainerItem
** container
,
1946 GDIPCONST GpGraphics
* graphics
){
1949 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1953 (*container
)->contid
= graphics
->contid
+ 1;
1955 (*container
)->smoothing
= graphics
->smoothing
;
1956 (*container
)->compqual
= graphics
->compqual
;
1957 (*container
)->interpolation
= graphics
->interpolation
;
1958 (*container
)->compmode
= graphics
->compmode
;
1959 (*container
)->texthint
= graphics
->texthint
;
1960 (*container
)->scale
= graphics
->scale
;
1961 (*container
)->unit
= graphics
->unit
;
1962 (*container
)->textcontrast
= graphics
->textcontrast
;
1963 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1964 (*container
)->origin_x
= graphics
->origin_x
;
1965 (*container
)->origin_y
= graphics
->origin_y
;
1966 (*container
)->worldtrans
= graphics
->worldtrans
;
1968 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1970 GdipFree(*container
);
1978 static void delete_container(GraphicsContainerItem
* container
)
1980 GdipDeleteRegion(container
->clip
);
1981 GdipFree(container
);
1984 static GpStatus
restore_container(GpGraphics
* graphics
,
1985 GDIPCONST GraphicsContainerItem
* container
){
1989 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1990 if(sts
!= Ok
) return sts
;
1992 graphics
->worldtrans
= container
->worldtrans
;
1994 GdipDeleteRegion(graphics
->clip
);
1995 graphics
->clip
= newClip
;
1997 graphics
->contid
= container
->contid
- 1;
1999 graphics
->smoothing
= container
->smoothing
;
2000 graphics
->compqual
= container
->compqual
;
2001 graphics
->interpolation
= container
->interpolation
;
2002 graphics
->compmode
= container
->compmode
;
2003 graphics
->texthint
= container
->texthint
;
2004 graphics
->scale
= container
->scale
;
2005 graphics
->unit
= container
->unit
;
2006 graphics
->textcontrast
= container
->textcontrast
;
2007 graphics
->pixeloffset
= container
->pixeloffset
;
2008 graphics
->origin_x
= container
->origin_x
;
2009 graphics
->origin_y
= container
->origin_y
;
2014 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2020 if(graphics
->hwnd
) {
2021 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2022 return GenericError
;
2024 rect
->X
= wnd_rect
.left
;
2025 rect
->Y
= wnd_rect
.top
;
2026 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2027 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2028 }else if (graphics
->image
){
2029 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2030 if (stat
== Ok
&& unit
!= UnitPixel
)
2031 FIXME("need to convert from unit %i\n", unit
);
2032 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2039 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2040 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2042 rect
->Width
= bmp
.bmWidth
;
2043 rect
->Height
= bmp
.bmHeight
;
2054 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2055 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2062 points
[0].x
= rect
->X
;
2063 points
[0].y
= rect
->Y
;
2064 points
[1].x
= rect
->X
+ rect
->Width
;
2065 points
[1].y
= rect
->Y
+ rect
->Height
;
2067 DPtoLP(graphics
->hdc
, points
, sizeof(points
)/sizeof(points
[0]));
2069 rect
->X
= min(points
[0].x
, points
[1].x
);
2070 rect
->Y
= min(points
[0].y
, points
[1].y
);
2071 rect
->Width
= abs(points
[1].x
- points
[0].x
);
2072 rect
->Height
= abs(points
[1].y
- points
[0].y
);
2078 /* on success, rgn will contain the region of the graphics object which
2079 * is visible after clipping has been applied */
2080 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2086 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2089 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2092 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2095 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2098 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2101 GdipDeleteRegion(tmp
);
2105 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2109 if (font
->unit
== UnitPixel
)
2111 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2115 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2116 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2118 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2121 lf
->lfHeight
= -(height
+ 0.5);
2123 lf
->lfEscapement
= 0;
2124 lf
->lfOrientation
= 0;
2125 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2126 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2127 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2128 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2129 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2130 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2131 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2132 lf
->lfQuality
= DEFAULT_QUALITY
;
2133 lf
->lfPitchAndFamily
= 0;
2134 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2137 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2138 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2139 GDIPCONST GpMatrix
*matrix
)
2141 HDC hdc
= CreateCompatibleDC(0);
2143 REAL angle
, rel_width
, rel_height
, font_height
;
2145 HFONT unscaled_font
;
2146 TEXTMETRICW textmet
;
2148 if (font
->unit
== UnitPixel
|| font
->unit
== UnitWorld
)
2149 font_height
= font
->emSize
;
2152 REAL unit_scale
, res
;
2154 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2155 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2157 font_height
= font
->emSize
* unit_scale
;
2168 GpMatrix xform
= *matrix
;
2169 GdipTransformMatrixPoints(&xform
, pt
, 3);
2172 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2173 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2174 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2175 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2176 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2177 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2179 get_log_fontW(font
, graphics
, &lfw
);
2180 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2181 unscaled_font
= CreateFontIndirectW(&lfw
);
2183 SelectObject(hdc
, unscaled_font
);
2184 GetTextMetricsW(hdc
, &textmet
);
2186 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2187 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2189 *hfont
= CreateFontIndirectW(&lfw
);
2192 DeleteObject(unscaled_font
);
2195 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2197 TRACE("(%p, %p)\n", hdc
, graphics
);
2199 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2202 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2208 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2211 FIXME("Don't know how to handle parameter hDevice\n");
2216 if(graphics
== NULL
)
2217 return InvalidParameter
;
2219 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2220 if(!*graphics
) return OutOfMemory
;
2222 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2224 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2225 GdipFree(*graphics
);
2229 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2230 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2231 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2233 (*graphics
)->alpha_hdc
= 1;
2236 (*graphics
)->hdc
= hdc
;
2237 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2238 (*graphics
)->owndc
= FALSE
;
2239 (*graphics
)->smoothing
= SmoothingModeDefault
;
2240 (*graphics
)->compqual
= CompositingQualityDefault
;
2241 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2242 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2243 (*graphics
)->compmode
= CompositingModeSourceOver
;
2244 (*graphics
)->unit
= UnitDisplay
;
2245 (*graphics
)->scale
= 1.0;
2246 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2247 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2248 (*graphics
)->busy
= FALSE
;
2249 (*graphics
)->textcontrast
= 4;
2250 list_init(&(*graphics
)->containers
);
2251 (*graphics
)->contid
= 0;
2253 TRACE("<-- %p\n", *graphics
);
2258 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2262 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2263 if(!*graphics
) return OutOfMemory
;
2265 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2267 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2268 GdipFree(*graphics
);
2272 (*graphics
)->hdc
= NULL
;
2273 (*graphics
)->hwnd
= NULL
;
2274 (*graphics
)->owndc
= FALSE
;
2275 (*graphics
)->image
= image
;
2276 /* We have to store the image type here because the image may be freed
2277 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2278 (*graphics
)->image_type
= image
->type
;
2279 (*graphics
)->smoothing
= SmoothingModeDefault
;
2280 (*graphics
)->compqual
= CompositingQualityDefault
;
2281 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2282 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2283 (*graphics
)->compmode
= CompositingModeSourceOver
;
2284 (*graphics
)->unit
= UnitDisplay
;
2285 (*graphics
)->scale
= 1.0;
2286 (*graphics
)->xres
= image
->xres
;
2287 (*graphics
)->yres
= image
->yres
;
2288 (*graphics
)->busy
= FALSE
;
2289 (*graphics
)->textcontrast
= 4;
2290 list_init(&(*graphics
)->containers
);
2291 (*graphics
)->contid
= 0;
2293 TRACE("<-- %p\n", *graphics
);
2298 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2303 TRACE("(%p, %p)\n", hwnd
, graphics
);
2307 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2309 ReleaseDC(hwnd
, hdc
);
2313 (*graphics
)->hwnd
= hwnd
;
2314 (*graphics
)->owndc
= TRUE
;
2319 /* FIXME: no icm handling */
2320 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2322 TRACE("(%p, %p)\n", hwnd
, graphics
);
2324 return GdipCreateFromHWND(hwnd
, graphics
);
2327 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2328 UINT access
, IStream
**stream
)
2333 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2335 if(!stream
|| !filename
)
2336 return InvalidParameter
;
2338 if(access
& GENERIC_WRITE
)
2339 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2340 else if(access
& GENERIC_READ
)
2341 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2343 return InvalidParameter
;
2345 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2347 return hresult_to_status(ret
);
2350 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2352 GraphicsContainerItem
*cont
, *next
;
2354 TRACE("(%p)\n", graphics
);
2356 if(!graphics
) return InvalidParameter
;
2357 if(graphics
->busy
) return ObjectBusy
;
2359 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2361 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2367 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2369 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2370 list_remove(&cont
->entry
);
2371 delete_container(cont
);
2374 GdipDeleteRegion(graphics
->clip
);
2376 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2377 * do otherwise, but we can't have that in the test suite because it means
2378 * accessing freed memory. */
2379 graphics
->busy
= TRUE
;
2386 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2387 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2392 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2393 width
, height
, startAngle
, sweepAngle
);
2395 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2396 return InvalidParameter
;
2401 status
= GdipCreatePath(FillModeAlternate
, &path
);
2402 if (status
!= Ok
) return status
;
2404 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2406 status
= GdipDrawPath(graphics
, pen
, path
);
2408 GdipDeletePath(path
);
2412 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2413 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2415 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2416 width
, height
, startAngle
, sweepAngle
);
2418 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2421 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2422 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2426 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2427 x2
, y2
, x3
, y3
, x4
, y4
);
2429 if(!graphics
|| !pen
)
2430 return InvalidParameter
;
2443 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2446 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2447 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2449 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2450 x2
, y2
, x3
, y3
, x4
, y4
);
2452 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2455 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2456 GDIPCONST GpPointF
*points
, INT count
)
2461 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2463 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2464 return InvalidParameter
;
2469 status
= GdipCreatePath(FillModeAlternate
, &path
);
2470 if (status
!= Ok
) return status
;
2472 status
= GdipAddPathBeziers(path
, points
, count
);
2474 status
= GdipDrawPath(graphics
, pen
, path
);
2476 GdipDeletePath(path
);
2480 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2481 GDIPCONST GpPoint
*points
, INT count
)
2487 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2489 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2490 return InvalidParameter
;
2495 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2499 for(i
= 0; i
< count
; i
++){
2500 pts
[i
].X
= (REAL
)points
[i
].X
;
2501 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2504 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2511 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2512 GDIPCONST GpPointF
*points
, INT count
)
2514 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2516 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2519 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2520 GDIPCONST GpPoint
*points
, INT count
)
2522 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2524 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2527 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2528 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2533 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2535 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2536 return InvalidParameter
;
2541 status
= GdipCreatePath(FillModeAlternate
, &path
);
2542 if (status
!= Ok
) return status
;
2544 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2546 status
= GdipDrawPath(graphics
, pen
, path
);
2548 GdipDeletePath(path
);
2553 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2554 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2560 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2562 if(!points
|| count
<= 0)
2563 return InvalidParameter
;
2565 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2569 for(i
= 0; i
< count
; i
++){
2570 ptf
[i
].X
= (REAL
)points
[i
].X
;
2571 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2574 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2581 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2582 GDIPCONST GpPointF
*points
, INT count
)
2584 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2586 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2589 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2590 GDIPCONST GpPoint
*points
, INT count
)
2596 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2599 return InvalidParameter
;
2601 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2605 for(i
= 0; i
< count
; i
++){
2606 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2607 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2610 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2616 /* Approximates cardinal spline with Bezier curves. */
2617 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2618 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2623 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2625 if(!graphics
|| !pen
)
2626 return InvalidParameter
;
2632 return InvalidParameter
;
2634 status
= GdipCreatePath(FillModeAlternate
, &path
);
2635 if (status
!= Ok
) return status
;
2637 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2639 status
= GdipDrawPath(graphics
, pen
, path
);
2641 GdipDeletePath(path
);
2645 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2646 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2652 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2655 return InvalidParameter
;
2657 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2661 for(i
= 0; i
< count
; i
++){
2662 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2663 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2666 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2672 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2673 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2676 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2678 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2679 return InvalidParameter
;
2682 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2685 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2686 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2689 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2695 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2696 return InvalidParameter
;
2699 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2702 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2703 REAL y
, REAL width
, REAL height
)
2708 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2710 if(!graphics
|| !pen
)
2711 return InvalidParameter
;
2716 status
= GdipCreatePath(FillModeAlternate
, &path
);
2717 if (status
!= Ok
) return status
;
2719 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2721 status
= GdipDrawPath(graphics
, pen
, path
);
2723 GdipDeletePath(path
);
2727 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2728 INT y
, INT width
, INT height
)
2730 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2732 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2736 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2740 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2742 if(!graphics
|| !image
)
2743 return InvalidParameter
;
2745 GdipGetImageWidth(image
, &width
);
2746 GdipGetImageHeight(image
, &height
);
2748 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2749 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2752 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2755 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2757 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2760 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2761 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2765 REAL scale_x
, scale_y
, width
, height
;
2767 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2769 if (!graphics
|| !image
) return InvalidParameter
;
2771 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2772 scale_x
*= graphics
->xres
/ image
->xres
;
2773 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2774 scale_y
*= graphics
->yres
/ image
->yres
;
2775 width
= srcwidth
* scale_x
;
2776 height
= srcheight
* scale_y
;
2778 points
[0].X
= points
[2].X
= x
;
2779 points
[0].Y
= points
[1].Y
= y
;
2780 points
[1].X
= x
+ width
;
2781 points
[2].Y
= y
+ height
;
2783 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2784 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2787 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2788 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2791 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2794 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2795 GDIPCONST GpPointF
*dstpoints
, INT count
)
2799 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2802 return InvalidParameter
;
2804 GdipGetImageWidth(image
, &width
);
2805 GdipGetImageHeight(image
, &height
);
2807 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2808 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2811 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2812 GDIPCONST GpPoint
*dstpoints
, INT count
)
2816 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2818 if (count
!= 3 || !dstpoints
)
2819 return InvalidParameter
;
2821 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2822 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2823 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2824 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2825 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2826 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2828 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2831 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2832 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2834 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2838 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2839 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2840 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2841 DrawImageAbort callback
, VOID
* callbackData
)
2847 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2848 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2852 return NotImplemented
;
2854 if(!graphics
|| !image
|| !points
|| count
!= 3)
2855 return InvalidParameter
;
2857 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2858 debugstr_pointf(&points
[2]));
2860 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2862 /* Ensure source width/height is positive */
2865 GpPointF tmp
= ptf
[1];
2866 srcx
= srcx
+ srcwidth
;
2867 srcwidth
= -srcwidth
;
2868 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2869 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2876 GpPointF tmp
= ptf
[2];
2877 srcy
= srcy
+ srcheight
;
2878 srcheight
= -srcheight
;
2879 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
2880 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
2885 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2886 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2887 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
2889 transform_and_round_points(graphics
, pti
, ptf
, 4);
2891 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2892 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2894 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2895 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2896 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2897 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2898 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2904 FIXME("graphics object has no HDC\n");
2907 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2908 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2909 srcx
, srcy
, srcwidth
, srcheight
, NULL
) != S_OK
)
2912 callback(callbackData
);
2913 return GenericError
;
2916 else if (image
->type
== ImageTypeBitmap
)
2918 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2919 BOOL do_resampling
= FALSE
;
2920 BOOL use_software
= FALSE
;
2922 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2923 graphics
->xres
, graphics
->yres
,
2924 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2925 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2926 imageAttributes
? imageAttributes
->outside_color
: 0);
2928 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2929 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2930 srcx
< 0 || srcy
< 0 ||
2931 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2932 do_resampling
= TRUE
;
2934 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
2935 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
2936 use_software
= TRUE
;
2941 GpRectF graphics_bounds
;
2943 int i
, x
, y
, src_stride
, dst_stride
;
2944 GpMatrix dst_to_src
;
2945 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2946 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
2947 BitmapData lockeddata
;
2948 InterpolationMode interpolation
= graphics
->interpolation
;
2949 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2950 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2951 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2952 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2954 if (!imageAttributes
)
2955 imageAttributes
= &defaultImageAttributes
;
2957 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2958 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2961 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2962 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2963 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2964 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2967 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
2968 if (stat
!= Ok
) return stat
;
2970 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
2971 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
2972 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
2973 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
2975 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
2977 if (IsRectEmpty(&dst_area
)) return Ok
;
2979 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2980 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2981 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2982 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2983 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2984 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2986 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
2988 stat
= GdipInvertMatrix(&dst_to_src
);
2989 if (stat
!= Ok
) return stat
;
2993 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2994 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2998 /* Make sure src_area is equal in size to dst_area. */
2999 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
3000 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
3001 src_area
.Width
= dst_area
.right
- dst_area
.left
;
3002 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
3005 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3007 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3010 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3012 /* Read the bits we need from the source bitmap into a compatible buffer. */
3013 lockeddata
.Width
= src_area
.Width
;
3014 lockeddata
.Height
= src_area
.Height
;
3015 lockeddata
.Stride
= src_stride
;
3016 lockeddata
.Scan0
= src_data
;
3017 if (!do_resampling
&& bitmap
->format
== PixelFormat32bppPARGB
)
3018 lockeddata
.PixelFormat
= apply_image_attributes(imageAttributes
, NULL
, 0, 0, 0, ColorAdjustTypeBitmap
, bitmap
->format
);
3020 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3022 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3023 lockeddata
.PixelFormat
, &lockeddata
);
3026 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3034 apply_image_attributes(imageAttributes
, src_data
,
3035 src_area
.Width
, src_area
.Height
,
3036 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
3040 /* Transform the bits as needed to the destination. */
3041 dst_data
= dst_dyn_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3048 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3050 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3052 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3053 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3054 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3055 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3057 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3059 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3061 GpPointF src_pointf
;
3064 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3065 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3067 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3069 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3070 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3071 imageAttributes
, interpolation
, offset_mode
);
3079 dst_data
= src_data
;
3080 dst_stride
= src_stride
;
3083 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3084 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
,
3085 lockeddata
.PixelFormat
);
3089 GdipFree(dst_dyn_data
);
3096 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3097 HBITMAP hbitmap
, old_hbm
=NULL
;
3099 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3100 bitmap
->format
== PixelFormat24bppRGB
||
3101 bitmap
->format
== PixelFormat32bppRGB
||
3102 bitmap
->format
== PixelFormat32bppPARGB
))
3104 BITMAPINFOHEADER bih
;
3106 PixelFormat dst_format
;
3108 /* we can't draw a bitmap of this format directly */
3109 hdc
= CreateCompatibleDC(0);
3113 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3114 bih
.biWidth
= bitmap
->width
;
3115 bih
.biHeight
= -bitmap
->height
;
3117 bih
.biBitCount
= 32;
3118 bih
.biCompression
= BI_RGB
;
3119 bih
.biSizeImage
= 0;
3120 bih
.biXPelsPerMeter
= 0;
3121 bih
.biYPelsPerMeter
= 0;
3123 bih
.biClrImportant
= 0;
3125 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3126 (void**)&temp_bits
, NULL
, 0);
3128 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3129 dst_format
= PixelFormat32bppPARGB
;
3131 dst_format
= PixelFormat32bppRGB
;
3133 convert_pixels(bitmap
->width
, bitmap
->height
,
3134 bitmap
->width
*4, temp_bits
, dst_format
,
3135 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3136 bitmap
->image
.palette
);
3140 if (bitmap
->hbitmap
)
3141 hbitmap
= bitmap
->hbitmap
;
3144 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3149 temp_hdc
= (hdc
== 0);
3154 if (!hdc
) hdc
= CreateCompatibleDC(0);
3155 old_hbm
= SelectObject(hdc
, hbitmap
);
3158 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3160 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3161 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3165 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3166 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3171 SelectObject(hdc
, old_hbm
);
3176 DeleteObject(hbitmap
);
3179 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3185 rc
.Width
= srcwidth
;
3186 rc
.Height
= srcheight
;
3188 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3189 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3193 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3194 return InvalidParameter
;
3200 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3201 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3202 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3203 DrawImageAbort callback
, VOID
* callbackData
)
3205 GpPointF pointsF
[3];
3208 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3209 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3212 if(!points
|| count
!=3)
3213 return InvalidParameter
;
3215 for(i
= 0; i
< count
; i
++){
3216 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3217 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3220 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3221 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3222 callback
, callbackData
);
3225 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3226 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3227 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3228 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3229 VOID
* callbackData
)
3233 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3234 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3235 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3239 points
[1].X
= dstx
+ dstwidth
;
3242 points
[2].Y
= dsty
+ dstheight
;
3244 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3245 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3248 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3249 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3250 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3251 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3252 VOID
* callbackData
)
3256 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3257 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3258 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3262 points
[1].X
= dstx
+ dstwidth
;
3265 points
[2].Y
= dsty
+ dstheight
;
3267 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3268 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3271 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3272 REAL x
, REAL y
, REAL width
, REAL height
)
3278 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3280 if(!graphics
|| !image
)
3281 return InvalidParameter
;
3283 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3287 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3288 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3289 unit
, NULL
, NULL
, NULL
);
3292 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3293 INT x
, INT y
, INT width
, INT height
)
3295 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3297 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3300 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3301 REAL y1
, REAL x2
, REAL y2
)
3305 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3311 return GdipDrawLines(graphics
, pen
, pt
, 2);
3314 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3315 INT y1
, INT x2
, INT y2
)
3317 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3319 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3322 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3323 GpPointF
*points
, INT count
)
3328 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3330 if(!pen
|| !graphics
|| (count
< 2))
3331 return InvalidParameter
;
3336 status
= GdipCreatePath(FillModeAlternate
, &path
);
3337 if (status
!= Ok
) return status
;
3339 status
= GdipAddPathLine2(path
, points
, count
);
3341 status
= GdipDrawPath(graphics
, pen
, path
);
3343 GdipDeletePath(path
);
3347 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3348 GpPoint
*points
, INT count
)
3354 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3356 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3357 if(!ptf
) return OutOfMemory
;
3359 for(i
= 0; i
< count
; i
++){
3360 ptf
[i
].X
= (REAL
) points
[i
].X
;
3361 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3364 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3370 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3376 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3378 if(!pen
|| !graphics
)
3379 return InvalidParameter
;
3386 FIXME("graphics object has no HDC\n");
3390 save_state
= prepare_dc(graphics
, pen
);
3392 retval
= get_clip_hrgn(graphics
, &hrgn
);
3398 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3400 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3401 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3404 restore_dc(graphics
, save_state
);
3410 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3411 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3416 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3417 width
, height
, startAngle
, sweepAngle
);
3419 if(!graphics
|| !pen
)
3420 return InvalidParameter
;
3425 status
= GdipCreatePath(FillModeAlternate
, &path
);
3426 if (status
!= Ok
) return status
;
3428 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3430 status
= GdipDrawPath(graphics
, pen
, path
);
3432 GdipDeletePath(path
);
3436 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3437 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3439 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3440 width
, height
, startAngle
, sweepAngle
);
3442 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3445 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3446 REAL y
, REAL width
, REAL height
)
3451 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3453 if(!pen
|| !graphics
)
3454 return InvalidParameter
;
3459 status
= GdipCreatePath(FillModeAlternate
, &path
);
3460 if (status
!= Ok
) return status
;
3462 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3464 status
= GdipDrawPath(graphics
, pen
, path
);
3466 GdipDeletePath(path
);
3470 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3471 INT y
, INT width
, INT height
)
3473 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3475 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3478 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3479 GDIPCONST GpRectF
* rects
, INT count
)
3484 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3486 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3487 return InvalidParameter
;
3492 status
= GdipCreatePath(FillModeAlternate
, &path
);
3493 if (status
!= Ok
) return status
;
3495 status
= GdipAddPathRectangles(path
, rects
, count
);
3497 status
= GdipDrawPath(graphics
, pen
, path
);
3499 GdipDeletePath(path
);
3503 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3504 GDIPCONST GpRect
* rects
, INT count
)
3510 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3512 if(!rects
|| count
<=0)
3513 return InvalidParameter
;
3515 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3519 for(i
= 0;i
< count
;i
++){
3520 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3521 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3522 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3523 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3526 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3532 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3533 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3538 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3539 count
, tension
, fill
);
3541 if(!graphics
|| !brush
|| !points
)
3542 return InvalidParameter
;
3547 if(count
== 1) /* Do nothing */
3550 status
= GdipCreatePath(fill
, &path
);
3551 if (status
!= Ok
) return status
;
3553 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3555 status
= GdipFillPath(graphics
, brush
, path
);
3557 GdipDeletePath(path
);
3561 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3562 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3568 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3569 count
, tension
, fill
);
3571 if(!points
|| count
== 0)
3572 return InvalidParameter
;
3574 if(count
== 1) /* Do nothing */
3577 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3581 for(i
= 0;i
< count
;i
++){
3582 ptf
[i
].X
= (REAL
)points
[i
].X
;
3583 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3586 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3593 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3594 GDIPCONST GpPointF
*points
, INT count
)
3596 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3597 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3598 0.5f
, FillModeAlternate
);
3601 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3602 GDIPCONST GpPoint
*points
, INT count
)
3604 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3605 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3606 0.5f
, FillModeAlternate
);
3609 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3610 REAL y
, REAL width
, REAL height
)
3615 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3617 if(!graphics
|| !brush
)
3618 return InvalidParameter
;
3623 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3627 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3630 stat
= GdipFillPath(graphics
, brush
, path
);
3632 GdipDeletePath(path
);
3638 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3639 INT y
, INT width
, INT height
)
3641 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3643 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3646 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3652 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3653 return NotImplemented
;
3655 save_state
= SaveDC(graphics
->hdc
);
3656 EndPath(graphics
->hdc
);
3657 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3660 retval
= get_clip_hrgn(graphics
, &hrgn
);
3666 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3668 BeginPath(graphics
->hdc
);
3669 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3670 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3675 EndPath(graphics
->hdc
);
3676 brush_fill_path(graphics
, brush
);
3681 RestoreDC(graphics
->hdc
, save_state
);
3687 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3692 if (!brush_can_fill_pixels(brush
))
3693 return NotImplemented
;
3695 /* FIXME: This could probably be done more efficiently without regions. */
3697 stat
= GdipCreateRegionPath(path
, &rgn
);
3701 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3703 GdipDeleteRegion(rgn
);
3709 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3711 GpStatus stat
= NotImplemented
;
3713 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3715 if(!brush
|| !graphics
|| !path
)
3716 return InvalidParameter
;
3721 if (!graphics
->image
&& !graphics
->alpha_hdc
)
3722 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3724 if (stat
== NotImplemented
)
3725 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3727 if (stat
== NotImplemented
)
3729 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3736 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3737 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3742 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3743 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3745 if(!graphics
|| !brush
)
3746 return InvalidParameter
;
3751 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3755 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3758 stat
= GdipFillPath(graphics
, brush
, path
);
3760 GdipDeletePath(path
);
3766 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3767 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3769 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3770 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3772 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3775 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3776 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3781 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3783 if(!graphics
|| !brush
|| !points
|| !count
)
3784 return InvalidParameter
;
3789 stat
= GdipCreatePath(fillMode
, &path
);
3793 stat
= GdipAddPathPolygon(path
, points
, count
);
3796 stat
= GdipFillPath(graphics
, brush
, path
);
3798 GdipDeletePath(path
);
3804 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3805 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3810 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3812 if(!graphics
|| !brush
|| !points
|| !count
)
3813 return InvalidParameter
;
3818 stat
= GdipCreatePath(fillMode
, &path
);
3822 stat
= GdipAddPathPolygonI(path
, points
, count
);
3825 stat
= GdipFillPath(graphics
, brush
, path
);
3827 GdipDeletePath(path
);
3833 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3834 GDIPCONST GpPointF
*points
, INT count
)
3836 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3838 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3841 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3842 GDIPCONST GpPoint
*points
, INT count
)
3844 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3846 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3849 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3850 REAL x
, REAL y
, REAL width
, REAL height
)
3854 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3859 rect
.Height
= height
;
3861 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
3864 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3865 INT x
, INT y
, INT width
, INT height
)
3869 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3873 rect
.Width
= (REAL
)width
;
3874 rect
.Height
= (REAL
)height
;
3876 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
3879 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3885 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3887 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
3888 return InvalidParameter
;
3890 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
3892 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
3893 /* FIXME: Add gdi32 drawing. */
3897 status
= GdipCreatePath(FillModeAlternate
, &path
);
3898 if (status
!= Ok
) return status
;
3900 status
= GdipAddPathRectangles(path
, rects
, count
);
3902 status
= GdipFillPath(graphics
, brush
, path
);
3904 GdipDeletePath(path
);
3908 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3915 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3917 if(!rects
|| count
<= 0)
3918 return InvalidParameter
;
3920 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3924 for(i
= 0; i
< count
; i
++){
3925 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3926 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3927 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3928 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3931 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3937 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3945 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3946 return NotImplemented
;
3948 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3952 save_state
= SaveDC(graphics
->hdc
);
3953 EndPath(graphics
->hdc
);
3955 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3957 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3959 BeginPath(graphics
->hdc
);
3960 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3961 EndPath(graphics
->hdc
);
3963 brush_fill_path(graphics
, brush
);
3966 RestoreDC(graphics
->hdc
, save_state
);
3973 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3977 GpRegion
*temp_region
;
3978 GpMatrix world_to_device
;
3979 GpRectF graphics_bounds
;
3983 GpRect gp_bound_rect
;
3985 if (!brush_can_fill_pixels(brush
))
3986 return NotImplemented
;
3988 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3991 stat
= GdipCloneRegion(region
, &temp_region
);
3995 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3996 CoordinateSpaceWorld
, &world_to_device
);
3999 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4002 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4005 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4007 GdipDeleteRegion(temp_region
);
4010 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4012 DeleteObject(hregion
);
4018 gp_bound_rect
.X
= bound_rect
.left
;
4019 gp_bound_rect
.Y
= bound_rect
.top
;
4020 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4021 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4023 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4029 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4030 &gp_bound_rect
, gp_bound_rect
.Width
);
4033 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4034 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4035 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
,
4036 PixelFormat32bppARGB
);
4038 GdipFree(pixel_data
);
4041 DeleteObject(hregion
);
4047 /*****************************************************************************
4048 * GdipFillRegion [GDIPLUS.@]
4050 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4053 GpStatus stat
= NotImplemented
;
4055 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4057 if (!(graphics
&& brush
&& region
))
4058 return InvalidParameter
;
4063 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4064 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4066 if (stat
== NotImplemented
)
4067 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4069 if (stat
== NotImplemented
)
4071 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4078 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4080 TRACE("(%p,%u)\n", graphics
, intention
);
4083 return InvalidParameter
;
4088 /* We have no internal operation queue, so there's no need to clear it. */
4096 /*****************************************************************************
4097 * GdipGetClipBounds [GDIPLUS.@]
4099 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4104 TRACE("(%p, %p)\n", graphics
, rect
);
4107 return InvalidParameter
;
4112 status
= GdipCreateRegion(&clip
);
4113 if (status
!= Ok
) return status
;
4115 status
= GdipGetClip(graphics
, clip
);
4117 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4119 GdipDeleteRegion(clip
);
4123 /*****************************************************************************
4124 * GdipGetClipBoundsI [GDIPLUS.@]
4126 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4128 TRACE("(%p, %p)\n", graphics
, rect
);
4131 return InvalidParameter
;
4136 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4139 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4140 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4141 CompositingMode
*mode
)
4143 TRACE("(%p, %p)\n", graphics
, mode
);
4145 if(!graphics
|| !mode
)
4146 return InvalidParameter
;
4151 *mode
= graphics
->compmode
;
4156 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4157 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4158 CompositingQuality
*quality
)
4160 TRACE("(%p, %p)\n", graphics
, quality
);
4162 if(!graphics
|| !quality
)
4163 return InvalidParameter
;
4168 *quality
= graphics
->compqual
;
4173 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4174 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4175 InterpolationMode
*mode
)
4177 TRACE("(%p, %p)\n", graphics
, mode
);
4179 if(!graphics
|| !mode
)
4180 return InvalidParameter
;
4185 *mode
= graphics
->interpolation
;
4190 /* FIXME: Need to handle color depths less than 24bpp */
4191 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4193 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4195 if(!graphics
|| !argb
)
4196 return InvalidParameter
;
4204 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4206 TRACE("(%p, %p)\n", graphics
, scale
);
4208 if(!graphics
|| !scale
)
4209 return InvalidParameter
;
4214 *scale
= graphics
->scale
;
4219 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4221 TRACE("(%p, %p)\n", graphics
, unit
);
4223 if(!graphics
|| !unit
)
4224 return InvalidParameter
;
4229 *unit
= graphics
->unit
;
4234 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4235 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4238 TRACE("(%p, %p)\n", graphics
, mode
);
4240 if(!graphics
|| !mode
)
4241 return InvalidParameter
;
4246 *mode
= graphics
->pixeloffset
;
4251 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4252 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4254 TRACE("(%p, %p)\n", graphics
, mode
);
4256 if(!graphics
|| !mode
)
4257 return InvalidParameter
;
4262 *mode
= graphics
->smoothing
;
4267 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4269 TRACE("(%p, %p)\n", graphics
, contrast
);
4271 if(!graphics
|| !contrast
)
4272 return InvalidParameter
;
4274 *contrast
= graphics
->textcontrast
;
4279 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4280 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4281 TextRenderingHint
*hint
)
4283 TRACE("(%p, %p)\n", graphics
, hint
);
4285 if(!graphics
|| !hint
)
4286 return InvalidParameter
;
4291 *hint
= graphics
->texthint
;
4296 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4301 TRACE("(%p, %p)\n", graphics
, rect
);
4303 if(!graphics
|| !rect
)
4304 return InvalidParameter
;
4309 /* intersect window and graphics clipping regions */
4310 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4313 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4316 /* get bounds of the region */
4317 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4320 GdipDeleteRegion(clip_rgn
);
4325 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4330 TRACE("(%p, %p)\n", graphics
, rect
);
4332 if(!graphics
|| !rect
)
4333 return InvalidParameter
;
4335 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4337 rect
->X
= gdip_round(rectf
.X
);
4338 rect
->Y
= gdip_round(rectf
.Y
);
4339 rect
->Width
= gdip_round(rectf
.Width
);
4340 rect
->Height
= gdip_round(rectf
.Height
);
4346 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4348 TRACE("(%p, %p)\n", graphics
, matrix
);
4350 if(!graphics
|| !matrix
)
4351 return InvalidParameter
;
4356 *matrix
= graphics
->worldtrans
;
4360 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4366 TRACE("(%p, %x)\n", graphics
, color
);
4369 return InvalidParameter
;
4374 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4377 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4378 GdipDeleteBrush((GpBrush
*)brush
);
4382 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4383 wnd_rect
.Width
, wnd_rect
.Height
);
4385 GdipDeleteBrush((GpBrush
*)brush
);
4390 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4392 TRACE("(%p, %p)\n", graphics
, res
);
4394 if(!graphics
|| !res
)
4395 return InvalidParameter
;
4397 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4400 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4406 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4408 if(!graphics
|| !result
)
4409 return InvalidParameter
;
4416 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4417 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4420 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4423 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4426 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4429 GdipDeleteRegion(rgn
);
4433 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4435 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4438 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4444 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4446 if(!graphics
|| !result
)
4447 return InvalidParameter
;
4454 pts
[1].X
= x
+ width
;
4455 pts
[1].Y
= y
+ height
;
4457 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4458 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4461 pts
[1].X
-= pts
[0].X
;
4462 pts
[1].Y
-= pts
[0].Y
;
4464 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4467 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4470 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4473 GdipDeleteRegion(rgn
);
4477 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4479 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4482 GpStatus
gdip_format_string(HDC hdc
,
4483 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4484 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4485 gdip_format_string_callback callback
, void *user_data
)
4488 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4489 nheight
, lineend
, lineno
= 0;
4491 StringAlignment halign
;
4494 HotkeyPrefix hkprefix
;
4495 INT
*hotkeyprefix_offsets
=NULL
;
4496 INT hotkeyprefix_count
=0;
4497 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4498 BOOL seen_prefix
= FALSE
;
4499 GpStringFormat
*dyn_format
=NULL
;
4501 if(length
== -1) length
= lstrlenW(string
);
4503 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4504 if(!stringdup
) return OutOfMemory
;
4508 stat
= GdipStringFormatGetGenericDefault(&dyn_format
);
4511 GdipFree(stringdup
);
4514 format
= dyn_format
;
4517 nwidth
= rect
->Width
;
4518 nheight
= rect
->Height
;
4519 if (ignore_empty_clip
)
4521 if (!nwidth
) nwidth
= INT_MAX
;
4522 if (!nheight
) nheight
= INT_MAX
;
4525 hkprefix
= format
->hkprefix
;
4527 if (hkprefix
== HotkeyPrefixShow
)
4529 for (i
=0; i
<length
; i
++)
4531 if (string
[i
] == '&')
4532 hotkeyprefix_count
++;
4536 if (hotkeyprefix_count
)
4537 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4539 hotkeyprefix_count
= 0;
4541 for(i
= 0, j
= 0; i
< length
; i
++){
4542 /* FIXME: This makes the indexes passed to callback inaccurate. */
4543 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4546 /* FIXME: tabs should be handled using tabstops from stringformat */
4547 if (string
[i
] == '\t')
4550 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4551 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4552 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4558 seen_prefix
= FALSE
;
4560 stringdup
[j
] = string
[i
];
4566 halign
= format
->align
;
4568 while(sum
< length
){
4569 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4570 nwidth
, &fit
, NULL
, &size
);
4576 for(lret
= 0; lret
< fit
; lret
++)
4577 if(*(stringdup
+ sum
+ lret
) == '\n')
4580 /* Line break code (may look strange, but it imitates windows). */
4582 lineend
= fit
= lret
; /* this is not an off-by-one error */
4583 else if(fit
< (length
- sum
)){
4584 if(*(stringdup
+ sum
+ fit
) == ' ')
4585 while(*(stringdup
+ sum
+ fit
) == ' ')
4588 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4591 if(*(stringdup
+ sum
+ fit
) == '\t')
4600 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4601 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4607 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4608 nwidth
, &j
, NULL
, &size
);
4610 bounds
.Width
= size
.cx
;
4612 if(height
+ size
.cy
> nheight
)
4614 if (format
->attr
& StringFormatFlagsLineLimit
)
4616 bounds
.Height
= nheight
- (height
+ size
.cy
);
4619 bounds
.Height
= size
.cy
;
4621 bounds
.Y
= rect
->Y
+ height
;
4625 case StringAlignmentNear
:
4629 case StringAlignmentCenter
:
4630 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4632 case StringAlignmentFar
:
4633 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4637 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4638 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4641 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4642 font
, rect
, format
, lineno
, &bounds
,
4643 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4644 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4649 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4653 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4655 if(height
> nheight
)
4658 /* Stop if this was a linewrap (but not if it was a linebreak). */
4659 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
4663 GdipFree(stringdup
);
4664 GdipFree(hotkeyprefix_offsets
);
4665 GdipDeleteStringFormat(dyn_format
);
4670 struct measure_ranges_args
{
4672 REAL rel_width
, rel_height
;
4675 static GpStatus
measure_ranges_callback(HDC hdc
,
4676 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4677 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4678 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4679 INT underlined_index_count
, void *user_data
)
4683 struct measure_ranges_args
*args
= user_data
;
4685 for (i
=0; i
<format
->range_count
; i
++)
4687 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4688 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4689 if (range_start
< range_end
)
4694 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4695 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4697 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4698 INT_MAX
, NULL
, NULL
, &range_size
);
4699 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4701 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4702 INT_MAX
, NULL
, NULL
, &range_size
);
4703 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4705 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4714 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4715 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4716 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4717 INT regionCount
, GpRegion
** regions
)
4721 HFONT gdifont
, oldfont
;
4722 struct measure_ranges_args args
;
4723 HDC hdc
, temp_hdc
=NULL
;
4728 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4729 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4731 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4732 return InvalidParameter
;
4734 if (regionCount
< stringFormat
->range_count
)
4735 return InvalidParameter
;
4739 hdc
= temp_hdc
= CreateCompatibleDC(0);
4740 if (!temp_hdc
) return OutOfMemory
;
4743 hdc
= graphics
->hdc
;
4745 if (stringFormat
->attr
)
4746 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4754 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4755 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4756 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4757 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4758 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4760 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4761 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4763 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4764 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4765 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
4766 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
4768 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4769 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4771 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
4772 oldfont
= SelectObject(hdc
, gdifont
);
4774 for (i
=0; i
<stringFormat
->range_count
; i
++)
4776 stat
= GdipSetEmpty(regions
[i
]);
4781 args
.regions
= regions
;
4783 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
4784 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
4786 SelectObject(hdc
, oldfont
);
4787 DeleteObject(gdifont
);
4795 struct measure_string_args
{
4797 INT
*codepointsfitted
;
4799 REAL rel_width
, rel_height
;
4802 static GpStatus
measure_string_callback(HDC hdc
,
4803 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4804 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4805 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4806 INT underlined_index_count
, void *user_data
)
4808 struct measure_string_args
*args
= user_data
;
4809 REAL new_width
, new_height
;
4811 new_width
= bounds
->Width
/ args
->rel_width
;
4812 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
4814 if (new_width
> args
->bounds
->Width
)
4815 args
->bounds
->Width
= new_width
;
4817 if (new_height
> args
->bounds
->Height
)
4818 args
->bounds
->Height
= new_height
;
4820 if (args
->codepointsfitted
)
4821 *args
->codepointsfitted
= index
+ length
;
4823 if (args
->linesfilled
)
4824 (*args
->linesfilled
)++;
4829 /* Find the smallest rectangle that bounds the text when it is printed in rect
4830 * according to the format options listed in format. If rect has 0 width and
4831 * height, then just find the smallest rectangle that bounds the text when it's
4832 * printed at location (rect->X, rect-Y). */
4833 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4834 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4835 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4836 INT
*codepointsfitted
, INT
*linesfilled
)
4838 HFONT oldfont
, gdifont
;
4839 struct measure_string_args args
;
4840 HDC temp_hdc
=NULL
, hdc
;
4846 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4847 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4848 bounds
, codepointsfitted
, linesfilled
);
4850 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4851 return InvalidParameter
;
4855 hdc
= temp_hdc
= CreateCompatibleDC(0);
4856 if (!temp_hdc
) return OutOfMemory
;
4859 hdc
= graphics
->hdc
;
4861 if(linesfilled
) *linesfilled
= 0;
4862 if(codepointsfitted
) *codepointsfitted
= 0;
4865 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4873 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4874 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4875 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4876 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4877 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4879 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4880 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4882 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
4883 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
4884 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
4885 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
4886 if (scaled_rect
.Width
>= 0.5)
4888 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4889 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4892 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4893 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4895 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
4896 oldfont
= SelectObject(hdc
, gdifont
);
4898 bounds
->X
= rect
->X
;
4899 bounds
->Y
= rect
->Y
;
4900 bounds
->Width
= 0.0;
4901 bounds
->Height
= 0.0;
4903 args
.bounds
= bounds
;
4904 args
.codepointsfitted
= &glyphs
;
4905 args
.linesfilled
= &lines
;
4908 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
4909 measure_string_callback
, &args
);
4911 if (linesfilled
) *linesfilled
= lines
;
4912 if (codepointsfitted
) *codepointsfitted
= glyphs
;
4915 bounds
->Width
+= margin_x
* 2.0;
4917 SelectObject(hdc
, oldfont
);
4918 DeleteObject(gdifont
);
4926 struct draw_string_args
{
4927 GpGraphics
*graphics
;
4928 GDIPCONST GpBrush
*brush
;
4929 REAL x
, y
, rel_width
, rel_height
, ascent
;
4932 static GpStatus
draw_string_callback(HDC hdc
,
4933 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4934 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4935 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4936 INT underlined_index_count
, void *user_data
)
4938 struct draw_string_args
*args
= user_data
;
4942 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4943 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4945 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
4946 args
->brush
, &position
,
4947 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4949 if (stat
== Ok
&& underlined_index_count
)
4951 OUTLINETEXTMETRICW otm
;
4952 REAL underline_y
, underline_height
;
4955 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
4957 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
4958 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
4960 for (i
=0; i
<underlined_index_count
; i
++)
4962 REAL start_x
, end_x
;
4964 INT ofs
= underlined_indexes
[i
] - index
;
4966 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
4967 start_x
= text_size
.cx
/ args
->rel_width
;
4969 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
4970 end_x
= text_size
.cx
/ args
->rel_width
;
4972 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
4979 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4980 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4981 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4985 GpPointF pt
[3], rectcpy
[4];
4987 REAL rel_width
, rel_height
, margin_x
;
4988 INT save_state
, format_flags
= 0;
4990 struct draw_string_args args
;
4992 HDC hdc
, temp_hdc
=NULL
;
4993 TEXTMETRICW textmetric
;
4995 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4996 length
, font
, debugstr_rectf(rect
), format
, brush
);
4998 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4999 return InvalidParameter
;
5003 hdc
= graphics
->hdc
;
5007 hdc
= temp_hdc
= CreateCompatibleDC(0);
5011 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5013 format_flags
= format
->attr
;
5015 /* Should be no need to explicitly test for StringAlignmentNear as
5016 * that is default behavior if no alignment is passed. */
5017 if(format
->vertalign
!= StringAlignmentNear
){
5018 RectF bounds
, in_rect
= *rect
;
5019 in_rect
.Height
= 0.0; /* avoid height clipping */
5020 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5022 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5024 if(format
->vertalign
== StringAlignmentCenter
)
5025 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5026 else if(format
->vertalign
== StringAlignmentFar
)
5027 offsety
= (rect
->Height
- bounds
.Height
);
5029 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
5032 save_state
= SaveDC(hdc
);
5040 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5041 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5042 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5043 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5044 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5046 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5047 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5048 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5049 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5050 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5052 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5053 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5055 scaled_rect
.X
= margin_x
* rel_width
;
5056 scaled_rect
.Y
= 0.0;
5057 scaled_rect
.Width
= rel_width
* rect
->Width
;
5058 scaled_rect
.Height
= rel_height
* rect
->Height
;
5059 if (scaled_rect
.Width
>= 0.5)
5061 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5062 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5065 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5066 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5068 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5069 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5070 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5072 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5073 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5074 SelectClipRgn(hdc
, rgn
);
5077 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5078 SelectObject(hdc
, gdifont
);
5080 args
.graphics
= graphics
;
5084 args
.y
= rect
->Y
+ offsety
;
5086 args
.rel_width
= rel_width
;
5087 args
.rel_height
= rel_height
;
5089 GetTextMetricsW(hdc
, &textmetric
);
5090 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5092 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5093 draw_string_callback
, &args
);
5096 DeleteObject(gdifont
);
5098 RestoreDC(hdc
, save_state
);
5105 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5107 TRACE("(%p)\n", graphics
);
5110 return InvalidParameter
;
5115 return GdipSetInfinite(graphics
->clip
);
5118 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5120 TRACE("(%p)\n", graphics
);
5123 return InvalidParameter
;
5128 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5131 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5133 return GdipEndContainer(graphics
, state
);
5136 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5137 GpMatrixOrder order
)
5139 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5142 return InvalidParameter
;
5147 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5150 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5152 return GdipBeginContainer2(graphics
, state
);
5155 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5156 GraphicsContainer
*state
)
5158 GraphicsContainerItem
*container
;
5161 TRACE("(%p, %p)\n", graphics
, state
);
5163 if(!graphics
|| !state
)
5164 return InvalidParameter
;
5166 sts
= init_container(&container
, graphics
);
5170 list_add_head(&graphics
->containers
, &container
->entry
);
5171 *state
= graphics
->contid
= container
->contid
;
5176 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5178 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5179 return NotImplemented
;
5182 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5184 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5185 return NotImplemented
;
5188 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5190 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5191 return NotImplemented
;
5194 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5197 GraphicsContainerItem
*container
, *container2
;
5199 TRACE("(%p, %x)\n", graphics
, state
);
5202 return InvalidParameter
;
5204 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5205 if(container
->contid
== state
)
5209 /* did not find a matching container */
5210 if(&container
->entry
== &graphics
->containers
)
5213 sts
= restore_container(graphics
, container
);
5217 /* remove all of the containers on top of the found container */
5218 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5219 if(container
->contid
== state
)
5221 list_remove(&container
->entry
);
5222 delete_container(container
);
5225 list_remove(&container
->entry
);
5226 delete_container(container
);
5231 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5232 REAL sy
, GpMatrixOrder order
)
5234 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5237 return InvalidParameter
;
5242 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5245 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5248 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5250 if(!graphics
|| !srcgraphics
)
5251 return InvalidParameter
;
5253 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5256 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5257 CompositingMode mode
)
5259 TRACE("(%p, %d)\n", graphics
, mode
);
5262 return InvalidParameter
;
5267 graphics
->compmode
= mode
;
5272 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5273 CompositingQuality quality
)
5275 TRACE("(%p, %d)\n", graphics
, quality
);
5278 return InvalidParameter
;
5283 graphics
->compqual
= quality
;
5288 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5289 InterpolationMode mode
)
5291 TRACE("(%p, %d)\n", graphics
, mode
);
5293 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5294 return InvalidParameter
;
5299 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5300 mode
= InterpolationModeBilinear
;
5302 if (mode
== InterpolationModeHighQuality
)
5303 mode
= InterpolationModeHighQualityBicubic
;
5305 graphics
->interpolation
= mode
;
5310 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5314 TRACE("(%p, %.2f)\n", graphics
, scale
);
5316 if(!graphics
|| (scale
<= 0.0))
5317 return InvalidParameter
;
5322 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5324 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
5329 graphics
->scale
= scale
;
5334 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5338 TRACE("(%p, %d)\n", graphics
, unit
);
5341 return InvalidParameter
;
5346 if(unit
== UnitWorld
)
5347 return InvalidParameter
;
5349 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5351 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
5356 graphics
->unit
= unit
;
5361 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5364 TRACE("(%p, %d)\n", graphics
, mode
);
5367 return InvalidParameter
;
5372 graphics
->pixeloffset
= mode
;
5377 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5381 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5384 FIXME("value is unused in rendering\n");
5387 return InvalidParameter
;
5389 graphics
->origin_x
= x
;
5390 graphics
->origin_y
= y
;
5395 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5397 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5399 if (!graphics
|| !x
|| !y
)
5400 return InvalidParameter
;
5402 *x
= graphics
->origin_x
;
5403 *y
= graphics
->origin_y
;
5408 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5410 TRACE("(%p, %d)\n", graphics
, mode
);
5413 return InvalidParameter
;
5418 graphics
->smoothing
= mode
;
5423 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5425 TRACE("(%p, %d)\n", graphics
, contrast
);
5428 return InvalidParameter
;
5430 graphics
->textcontrast
= contrast
;
5435 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5436 TextRenderingHint hint
)
5438 TRACE("(%p, %d)\n", graphics
, hint
);
5440 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5441 return InvalidParameter
;
5446 graphics
->texthint
= hint
;
5451 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5453 TRACE("(%p, %p)\n", graphics
, matrix
);
5455 if(!graphics
|| !matrix
)
5456 return InvalidParameter
;
5461 TRACE("%f,%f,%f,%f,%f,%f\n",
5462 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5463 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5465 graphics
->worldtrans
= *matrix
;
5470 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5471 REAL dy
, GpMatrixOrder order
)
5473 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5476 return InvalidParameter
;
5481 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5484 /*****************************************************************************
5485 * GdipSetClipHrgn [GDIPLUS.@]
5487 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5492 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5495 return InvalidParameter
;
5500 /* hrgn is already in device units */
5501 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5505 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5507 GdipDeleteRegion(region
);
5511 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5516 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5519 return InvalidParameter
;
5524 status
= GdipClonePath(path
, &clip_path
);
5527 GpMatrix world_to_device
;
5529 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
5530 CoordinateSpaceWorld
, &world_to_device
);
5531 status
= GdipTransformPath(clip_path
, &world_to_device
);
5533 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
5535 GdipDeletePath(clip_path
);
5540 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5541 REAL width
, REAL height
,
5548 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5551 return InvalidParameter
;
5559 rect
.Height
= height
;
5560 status
= GdipCreateRegionRect(&rect
, ®ion
);
5563 GpMatrix world_to_device
;
5565 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5566 status
= GdipTransformRegion(region
, &world_to_device
);
5568 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5570 GdipDeleteRegion(region
);
5575 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5576 INT width
, INT height
,
5579 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5582 return InvalidParameter
;
5587 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5590 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5596 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5598 if(!graphics
|| !region
)
5599 return InvalidParameter
;
5604 status
= GdipCloneRegion(region
, &clip
);
5607 GpMatrix world_to_device
;
5609 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5610 status
= GdipTransformRegion(clip
, &world_to_device
);
5612 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
5614 GdipDeleteRegion(clip
);
5619 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5625 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5627 if(!graphics
|| !pen
|| count
<=0)
5628 return InvalidParameter
;
5635 FIXME("graphics object has no HDC\n");
5639 pti
= GdipAlloc(sizeof(POINT
) * count
);
5641 save_state
= prepare_dc(graphics
, pen
);
5642 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5644 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5645 Polygon(graphics
->hdc
, pti
, count
);
5647 restore_dc(graphics
, save_state
);
5653 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5660 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5662 if(count
<=0) return InvalidParameter
;
5663 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5665 for(i
= 0;i
< count
; i
++){
5666 ptf
[i
].X
= (REAL
)points
[i
].X
;
5667 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5670 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5676 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5678 TRACE("(%p, %p)\n", graphics
, dpi
);
5680 if(!graphics
|| !dpi
)
5681 return InvalidParameter
;
5686 *dpi
= graphics
->xres
;
5690 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5692 TRACE("(%p, %p)\n", graphics
, dpi
);
5694 if(!graphics
|| !dpi
)
5695 return InvalidParameter
;
5700 *dpi
= graphics
->yres
;
5704 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5705 GpMatrixOrder order
)
5710 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5712 if(!graphics
|| !matrix
)
5713 return InvalidParameter
;
5718 m
= graphics
->worldtrans
;
5720 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5722 graphics
->worldtrans
= m
;
5727 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5728 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5730 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5734 TRACE("(%p, %p)\n", graphics
, hdc
);
5736 if(!graphics
|| !hdc
)
5737 return InvalidParameter
;
5742 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5744 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5746 else if (!graphics
->hdc
||
5747 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5749 /* Create a fake HDC and fill it with a constant color. */
5753 BITMAPINFOHEADER bmih
;
5756 stat
= get_graphics_bounds(graphics
, &bounds
);
5760 graphics
->temp_hbitmap_width
= bounds
.Width
;
5761 graphics
->temp_hbitmap_height
= bounds
.Height
;
5763 bmih
.biSize
= sizeof(bmih
);
5764 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5765 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5767 bmih
.biBitCount
= 32;
5768 bmih
.biCompression
= BI_RGB
;
5769 bmih
.biSizeImage
= 0;
5770 bmih
.biXPelsPerMeter
= 0;
5771 bmih
.biYPelsPerMeter
= 0;
5773 bmih
.biClrImportant
= 0;
5775 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5776 (void**)&graphics
->temp_bits
, NULL
, 0);
5778 return GenericError
;
5780 temp_hdc
= CreateCompatibleDC(0);
5783 DeleteObject(hbitmap
);
5784 return GenericError
;
5787 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5788 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5790 SelectObject(temp_hdc
, hbitmap
);
5792 graphics
->temp_hbitmap
= hbitmap
;
5793 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5797 *hdc
= graphics
->hdc
;
5801 graphics
->busy
= TRUE
;
5806 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5810 TRACE("(%p, %p)\n", graphics
, hdc
);
5812 if(!graphics
|| !hdc
|| !graphics
->busy
)
5813 return InvalidParameter
;
5815 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5817 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5819 else if (graphics
->temp_hdc
== hdc
)
5824 /* Find the pixels that have changed, and mark them as opaque. */
5825 pos
= (DWORD
*)graphics
->temp_bits
;
5826 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5828 if (*pos
!= DC_BACKGROUND_KEY
)
5835 /* Write the changed pixels to the real target. */
5836 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5837 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5838 graphics
->temp_hbitmap_width
* 4, PixelFormat32bppARGB
);
5841 DeleteDC(graphics
->temp_hdc
);
5842 DeleteObject(graphics
->temp_hbitmap
);
5843 graphics
->temp_hdc
= NULL
;
5844 graphics
->temp_hbitmap
= NULL
;
5846 else if (hdc
!= graphics
->hdc
)
5848 stat
= InvalidParameter
;
5852 graphics
->busy
= FALSE
;
5857 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5861 GpMatrix device_to_world
;
5863 TRACE("(%p, %p)\n", graphics
, region
);
5865 if(!graphics
|| !region
)
5866 return InvalidParameter
;
5871 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5874 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
5875 status
= GdipTransformRegion(clip
, &device_to_world
);
5878 GdipDeleteRegion(clip
);
5882 /* free everything except root node and header */
5883 delete_element(®ion
->node
);
5884 memcpy(region
, clip
, sizeof(GpRegion
));
5890 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5891 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
5894 REAL scale_x
, scale_y
;
5896 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5898 if (dst_space
!= src_space
)
5900 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5901 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5903 if(graphics
->unit
!= UnitDisplay
)
5905 scale_x
*= graphics
->scale
;
5906 scale_y
*= graphics
->scale
;
5909 /* transform from src_space to CoordinateSpacePage */
5912 case CoordinateSpaceWorld
:
5913 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
5915 case CoordinateSpacePage
:
5917 case CoordinateSpaceDevice
:
5918 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
5922 /* transform from CoordinateSpacePage to dst_space */
5925 case CoordinateSpaceWorld
:
5927 GpMatrix inverted_transform
= graphics
->worldtrans
;
5928 stat
= GdipInvertMatrix(&inverted_transform
);
5930 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
5933 case CoordinateSpacePage
:
5935 case CoordinateSpaceDevice
:
5936 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
5943 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5944 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5949 if(!graphics
|| !points
|| count
<= 0)
5950 return InvalidParameter
;
5955 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5957 if (src_space
== dst_space
) return Ok
;
5959 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5960 if (stat
!= Ok
) return stat
;
5962 return GdipTransformMatrixPoints(&matrix
, points
, count
);
5965 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5966 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5972 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5975 return InvalidParameter
;
5977 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5981 for(i
= 0; i
< count
; i
++){
5982 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5983 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5986 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5989 for(i
= 0; i
< count
; i
++){
5990 points
[i
].X
= gdip_round(pointsF
[i
].X
);
5991 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
5998 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6010 /*****************************************************************************
6011 * GdipTranslateClip [GDIPLUS.@]
6013 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6015 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6018 return InvalidParameter
;
6023 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6026 /*****************************************************************************
6027 * GdipTranslateClipI [GDIPLUS.@]
6029 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6031 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6034 return InvalidParameter
;
6039 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6043 /*****************************************************************************
6044 * GdipMeasureDriverString [GDIPLUS.@]
6046 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6047 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6048 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6050 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6053 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6055 TEXTMETRICW textmetric
;
6056 const WORD
*glyph_indices
;
6057 WORD
*dynamic_glyph_indices
=NULL
;
6058 REAL rel_width
, rel_height
, ascent
, descent
;
6061 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6063 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6064 return InvalidParameter
;
6067 length
= strlenW(text
);
6071 boundingBox
->X
= 0.0;
6072 boundingBox
->Y
= 0.0;
6073 boundingBox
->Width
= 0.0;
6074 boundingBox
->Height
= 0.0;
6077 if (flags
& unsupported_flags
)
6078 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6080 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6082 hdc
= CreateCompatibleDC(0);
6083 SelectObject(hdc
, hfont
);
6085 GetTextMetricsW(hdc
, &textmetric
);
6095 GpMatrix xform
= *matrix
;
6096 GdipTransformMatrixPoints(&xform
, pt
, 3);
6098 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6099 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6100 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6101 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6102 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6104 if (flags
& DriverStringOptionsCmapLookup
)
6106 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6110 DeleteObject(hfont
);
6114 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6117 glyph_indices
= text
;
6119 min_x
= max_x
= x
= positions
[0].X
;
6120 min_y
= max_y
= y
= positions
[0].Y
;
6122 ascent
= textmetric
.tmAscent
/ rel_height
;
6123 descent
= textmetric
.tmDescent
/ rel_height
;
6125 for (i
=0; i
<length
; i
++)
6130 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6136 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6137 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6139 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6140 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6141 if (min_x
> x
) min_x
= x
;
6143 x
+= char_width
/ rel_width
;
6145 if (max_x
< x
) max_x
= x
;
6148 GdipFree(dynamic_glyph_indices
);
6150 DeleteObject(hfont
);
6152 boundingBox
->X
= min_x
;
6153 boundingBox
->Y
= min_y
;
6154 boundingBox
->Width
= max_x
- min_x
;
6155 boundingBox
->Height
= max_y
- min_y
;
6160 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6161 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6162 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6163 INT flags
, GDIPCONST GpMatrix
*matrix
)
6165 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6171 if (flags
& unsupported_flags
)
6172 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6174 if (!(flags
& DriverStringOptionsCmapLookup
))
6175 eto_flags
|= ETO_GLYPH_INDEX
;
6177 save_state
= SaveDC(graphics
->hdc
);
6178 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6179 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6182 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6184 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6185 SelectObject(graphics
->hdc
, hfont
);
6187 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6189 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6191 RestoreDC(graphics
->hdc
, save_state
);
6193 DeleteObject(hfont
);
6198 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6199 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6200 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6201 INT flags
, GDIPCONST GpMatrix
*matrix
)
6203 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6205 PointF
*real_positions
, real_position
;
6209 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6210 DWORD max_glyphsize
=0;
6211 GLYPHMETRICS glyphmetrics
;
6212 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6215 int text_mask_stride
;
6217 int pixel_data_stride
;
6219 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6224 if (!(flags
& DriverStringOptionsCmapLookup
))
6225 ggo_flags
|= GGO_GLYPH_INDEX
;
6227 if (flags
& unsupported_flags
)
6228 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6230 pti
= GdipAlloc(sizeof(POINT
) * length
);
6234 if (flags
& DriverStringOptionsRealizedAdvance
)
6236 real_position
= positions
[0];
6238 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6242 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6243 if (!real_positions
)
6249 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6251 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6253 GdipFree(real_positions
);
6256 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6258 hdc
= CreateCompatibleDC(0);
6259 SelectObject(hdc
, hfont
);
6261 /* Get the boundaries of the text to be drawn */
6262 for (i
=0; i
<length
; i
++)
6265 int left
, top
, right
, bottom
;
6267 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6268 &glyphmetrics
, 0, NULL
, &identity
);
6270 if (glyphsize
== GDI_ERROR
)
6272 ERR("GetGlyphOutlineW failed\n");
6275 DeleteObject(hfont
);
6276 return GenericError
;
6279 if (glyphsize
> max_glyphsize
)
6280 max_glyphsize
= glyphsize
;
6284 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6285 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6286 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6287 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6289 if (left
< min_x
) min_x
= left
;
6290 if (top
< min_y
) min_y
= top
;
6291 if (right
> max_x
) max_x
= right
;
6292 if (bottom
> max_y
) max_y
= bottom
;
6295 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6297 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6298 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6302 if (max_glyphsize
== 0)
6303 /* Nothing to draw. */
6306 glyph_mask
= GdipAlloc(max_glyphsize
);
6307 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6308 text_mask_stride
= max_x
- min_x
;
6310 if (!(glyph_mask
&& text_mask
))
6312 GdipFree(glyph_mask
);
6313 GdipFree(text_mask
);
6316 DeleteObject(hfont
);
6320 /* Generate a mask for the text */
6321 for (i
=0; i
<length
; i
++)
6324 int left
, top
, stride
;
6326 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6327 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6329 if (ret
== GDI_ERROR
|| ret
== 0)
6330 continue; /* empty glyph */
6332 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6333 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6334 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6336 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6338 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6339 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6340 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6342 *text_val
= min(64, *text_val
+ *glyph_val
);
6351 DeleteObject(hfont
);
6352 GdipFree(glyph_mask
);
6354 /* get the brush data */
6355 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6358 GdipFree(text_mask
);
6362 pixel_area
.X
= min_x
;
6363 pixel_area
.Y
= min_y
;
6364 pixel_area
.Width
= max_x
- min_x
;
6365 pixel_area
.Height
= max_y
- min_y
;
6366 pixel_data_stride
= pixel_area
.Width
* 4;
6368 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6371 GdipFree(text_mask
);
6372 GdipFree(pixel_data
);
6376 /* multiply the brush data by the mask */
6377 for (y
=0; y
<pixel_area
.Height
; y
++)
6379 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6380 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6381 for (x
=0; x
<pixel_area
.Width
; x
++)
6383 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6389 GdipFree(text_mask
);
6391 /* draw the result */
6392 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6393 pixel_area
.Height
, pixel_data_stride
, PixelFormat32bppARGB
);
6395 GdipFree(pixel_data
);
6400 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6401 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6402 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6403 INT flags
, GDIPCONST GpMatrix
*matrix
)
6405 GpStatus stat
= NotImplemented
;
6408 length
= strlenW(text
);
6410 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6411 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6412 brush
->bt
== BrushTypeSolidColor
&&
6413 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6414 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6415 brush
, positions
, flags
, matrix
);
6416 if (stat
== NotImplemented
)
6417 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6418 brush
, positions
, flags
, matrix
);
6422 /*****************************************************************************
6423 * GdipDrawDriverString [GDIPLUS.@]
6425 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6426 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6427 GDIPCONST PointF
*positions
, INT flags
,
6428 GDIPCONST GpMatrix
*matrix
)
6430 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6432 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6433 return InvalidParameter
;
6435 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6436 brush
, positions
, flags
, matrix
);
6439 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6440 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6442 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6443 return NotImplemented
;
6446 /*****************************************************************************
6447 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6449 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6454 TRACE("(%p, %p)\n", graphics
, res
);
6456 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6459 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6462 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6465 GdipDeleteRegion(rgn
);
6469 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6473 TRACE("(%p) stub\n", graphics
);
6476 FIXME("not implemented\n");
6478 return NotImplemented
;