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
= heap_alloc_zero(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 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
= heap_alloc_zero(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 heap_free(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
= heap_alloc_zero(count
* sizeof(PointF
));
1660 custpt
= heap_alloc_zero(count
* sizeof(POINT
));
1661 tp
= heap_alloc_zero(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
= heap_alloc_zero(count
* sizeof(POINT
));
1795 BYTE
*tp
= heap_alloc_zero(count
);
1796 GpPointF
*ptcopy
= heap_alloc_zero(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
= heap_alloc_zero(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 heap_free(*container
);
1978 static void delete_container(GraphicsContainerItem
* container
)
1980 GdipDeleteRegion(container
->clip
);
1981 heap_free(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
= heap_alloc_zero(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 heap_free(*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
= heap_alloc_zero(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 heap_free(*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
;
2381 heap_free(graphics
);
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
= heap_alloc_zero(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
= heap_alloc_zero(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
= heap_alloc_zero(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
= heap_alloc_zero(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
= heap_alloc_zero(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
);
3030 heap_free(src_data
);
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
= heap_alloc_zero(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3044 heap_free(src_data
);
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
);
3087 heap_free(src_data
);
3089 heap_free(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
= heap_alloc_zero(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
= heap_alloc_zero(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
= heap_alloc_zero(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
= heap_alloc_zero(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
= heap_alloc_zero(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 heap_free(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
)
4300 GpMatrix device_to_world
;
4302 TRACE("(%p, %p)\n", graphics
, rect
);
4304 if(!graphics
|| !rect
)
4305 return InvalidParameter
;
4310 /* intersect window and graphics clipping regions */
4311 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4314 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4317 /* transform to world coordinates */
4318 if((stat
= get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
)) != Ok
)
4321 if((stat
= GdipTransformRegion(clip_rgn
, &device_to_world
)) != Ok
)
4324 /* get bounds of the region */
4325 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4328 GdipDeleteRegion(clip_rgn
);
4333 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4338 TRACE("(%p, %p)\n", graphics
, rect
);
4340 if(!graphics
|| !rect
)
4341 return InvalidParameter
;
4343 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4345 rect
->X
= gdip_round(rectf
.X
);
4346 rect
->Y
= gdip_round(rectf
.Y
);
4347 rect
->Width
= gdip_round(rectf
.Width
);
4348 rect
->Height
= gdip_round(rectf
.Height
);
4354 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4356 TRACE("(%p, %p)\n", graphics
, matrix
);
4358 if(!graphics
|| !matrix
)
4359 return InvalidParameter
;
4364 *matrix
= graphics
->worldtrans
;
4368 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4374 TRACE("(%p, %x)\n", graphics
, color
);
4377 return InvalidParameter
;
4382 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4383 return METAFILE_GraphicsClear((GpMetafile
*)graphics
->image
, color
);
4385 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4388 if((stat
= GdipGetVisibleClipBounds(graphics
, &wnd_rect
)) != Ok
){
4389 GdipDeleteBrush((GpBrush
*)brush
);
4393 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4394 wnd_rect
.Width
, wnd_rect
.Height
);
4396 GdipDeleteBrush((GpBrush
*)brush
);
4401 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4403 TRACE("(%p, %p)\n", graphics
, res
);
4405 if(!graphics
|| !res
)
4406 return InvalidParameter
;
4408 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4411 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4417 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4419 if(!graphics
|| !result
)
4420 return InvalidParameter
;
4427 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4428 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4431 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4434 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4437 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4440 GdipDeleteRegion(rgn
);
4444 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4446 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4449 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4455 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4457 if(!graphics
|| !result
)
4458 return InvalidParameter
;
4465 pts
[1].X
= x
+ width
;
4466 pts
[1].Y
= y
+ height
;
4468 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4469 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4472 pts
[1].X
-= pts
[0].X
;
4473 pts
[1].Y
-= pts
[0].Y
;
4475 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4478 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4481 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4484 GdipDeleteRegion(rgn
);
4488 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4490 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4493 GpStatus
gdip_format_string(HDC hdc
,
4494 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4495 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4496 gdip_format_string_callback callback
, void *user_data
)
4499 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4500 nheight
, lineend
, lineno
= 0;
4502 StringAlignment halign
;
4505 HotkeyPrefix hkprefix
;
4506 INT
*hotkeyprefix_offsets
=NULL
;
4507 INT hotkeyprefix_count
=0;
4508 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4509 BOOL seen_prefix
= FALSE
;
4510 GpStringFormat
*dyn_format
=NULL
;
4512 if(length
== -1) length
= lstrlenW(string
);
4514 stringdup
= heap_alloc_zero((length
+ 1) * sizeof(WCHAR
));
4515 if(!stringdup
) return OutOfMemory
;
4519 stat
= GdipStringFormatGetGenericDefault(&dyn_format
);
4522 heap_free(stringdup
);
4525 format
= dyn_format
;
4528 nwidth
= rect
->Width
;
4529 nheight
= rect
->Height
;
4530 if (ignore_empty_clip
)
4532 if (!nwidth
) nwidth
= INT_MAX
;
4533 if (!nheight
) nheight
= INT_MAX
;
4536 hkprefix
= format
->hkprefix
;
4538 if (hkprefix
== HotkeyPrefixShow
)
4540 for (i
=0; i
<length
; i
++)
4542 if (string
[i
] == '&')
4543 hotkeyprefix_count
++;
4547 if (hotkeyprefix_count
)
4548 hotkeyprefix_offsets
= heap_alloc_zero(sizeof(INT
) * hotkeyprefix_count
);
4550 hotkeyprefix_count
= 0;
4552 for(i
= 0, j
= 0; i
< length
; i
++){
4553 /* FIXME: This makes the indexes passed to callback inaccurate. */
4554 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4557 /* FIXME: tabs should be handled using tabstops from stringformat */
4558 if (string
[i
] == '\t')
4561 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4562 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4563 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4569 seen_prefix
= FALSE
;
4571 stringdup
[j
] = string
[i
];
4577 halign
= format
->align
;
4579 while(sum
< length
){
4580 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4581 nwidth
, &fit
, NULL
, &size
);
4587 for(lret
= 0; lret
< fit
; lret
++)
4588 if(*(stringdup
+ sum
+ lret
) == '\n')
4591 /* Line break code (may look strange, but it imitates windows). */
4593 lineend
= fit
= lret
; /* this is not an off-by-one error */
4594 else if(fit
< (length
- sum
)){
4595 if(*(stringdup
+ sum
+ fit
) == ' ')
4596 while(*(stringdup
+ sum
+ fit
) == ' ')
4599 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4602 if(*(stringdup
+ sum
+ fit
) == '\t')
4611 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4612 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4618 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4619 nwidth
, &j
, NULL
, &size
);
4621 bounds
.Width
= size
.cx
;
4623 if(height
+ size
.cy
> nheight
)
4625 if (format
->attr
& StringFormatFlagsLineLimit
)
4627 bounds
.Height
= nheight
- (height
+ size
.cy
);
4630 bounds
.Height
= size
.cy
;
4632 bounds
.Y
= rect
->Y
+ height
;
4636 case StringAlignmentNear
:
4640 case StringAlignmentCenter
:
4641 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4643 case StringAlignmentFar
:
4644 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4648 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4649 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4652 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4653 font
, rect
, format
, lineno
, &bounds
,
4654 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4655 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4660 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4664 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4666 if(height
> nheight
)
4669 /* Stop if this was a linewrap (but not if it was a linebreak). */
4670 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
4674 heap_free(stringdup
);
4675 heap_free(hotkeyprefix_offsets
);
4676 GdipDeleteStringFormat(dyn_format
);
4681 struct measure_ranges_args
{
4683 REAL rel_width
, rel_height
;
4686 static GpStatus
measure_ranges_callback(HDC hdc
,
4687 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4688 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4689 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4690 INT underlined_index_count
, void *user_data
)
4694 struct measure_ranges_args
*args
= user_data
;
4696 for (i
=0; i
<format
->range_count
; i
++)
4698 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4699 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4700 if (range_start
< range_end
)
4705 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4706 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4708 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4709 INT_MAX
, NULL
, NULL
, &range_size
);
4710 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4712 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4713 INT_MAX
, NULL
, NULL
, &range_size
);
4714 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4716 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4725 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4726 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4727 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4728 INT regionCount
, GpRegion
** regions
)
4732 HFONT gdifont
, oldfont
;
4733 struct measure_ranges_args args
;
4734 HDC hdc
, temp_hdc
=NULL
;
4739 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4740 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4742 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4743 return InvalidParameter
;
4745 if (regionCount
< stringFormat
->range_count
)
4746 return InvalidParameter
;
4750 hdc
= temp_hdc
= CreateCompatibleDC(0);
4751 if (!temp_hdc
) return OutOfMemory
;
4754 hdc
= graphics
->hdc
;
4756 if (stringFormat
->attr
)
4757 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4765 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4766 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4767 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4768 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4769 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4771 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4772 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4774 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4775 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4776 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
4777 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
4779 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4780 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4782 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
4783 oldfont
= SelectObject(hdc
, gdifont
);
4785 for (i
=0; i
<stringFormat
->range_count
; i
++)
4787 stat
= GdipSetEmpty(regions
[i
]);
4792 args
.regions
= regions
;
4794 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
4795 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
4797 SelectObject(hdc
, oldfont
);
4798 DeleteObject(gdifont
);
4806 struct measure_string_args
{
4808 INT
*codepointsfitted
;
4810 REAL rel_width
, rel_height
;
4813 static GpStatus
measure_string_callback(HDC hdc
,
4814 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4815 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4816 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4817 INT underlined_index_count
, void *user_data
)
4819 struct measure_string_args
*args
= user_data
;
4820 REAL new_width
, new_height
;
4822 new_width
= bounds
->Width
/ args
->rel_width
;
4823 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
4825 if (new_width
> args
->bounds
->Width
)
4826 args
->bounds
->Width
= new_width
;
4828 if (new_height
> args
->bounds
->Height
)
4829 args
->bounds
->Height
= new_height
;
4831 if (args
->codepointsfitted
)
4832 *args
->codepointsfitted
= index
+ length
;
4834 if (args
->linesfilled
)
4835 (*args
->linesfilled
)++;
4840 /* Find the smallest rectangle that bounds the text when it is printed in rect
4841 * according to the format options listed in format. If rect has 0 width and
4842 * height, then just find the smallest rectangle that bounds the text when it's
4843 * printed at location (rect->X, rect-Y). */
4844 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4845 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4846 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4847 INT
*codepointsfitted
, INT
*linesfilled
)
4849 HFONT oldfont
, gdifont
;
4850 struct measure_string_args args
;
4851 HDC temp_hdc
=NULL
, hdc
;
4857 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4858 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4859 bounds
, codepointsfitted
, linesfilled
);
4861 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4862 return InvalidParameter
;
4866 hdc
= temp_hdc
= CreateCompatibleDC(0);
4867 if (!temp_hdc
) return OutOfMemory
;
4870 hdc
= graphics
->hdc
;
4872 if(linesfilled
) *linesfilled
= 0;
4873 if(codepointsfitted
) *codepointsfitted
= 0;
4876 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4884 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4885 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4886 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4887 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4888 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4890 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4891 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4893 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
4894 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
4895 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
4896 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
4897 if (scaled_rect
.Width
>= 0.5)
4899 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4900 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4903 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4904 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4906 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
4907 oldfont
= SelectObject(hdc
, gdifont
);
4909 bounds
->X
= rect
->X
;
4910 bounds
->Y
= rect
->Y
;
4911 bounds
->Width
= 0.0;
4912 bounds
->Height
= 0.0;
4914 args
.bounds
= bounds
;
4915 args
.codepointsfitted
= &glyphs
;
4916 args
.linesfilled
= &lines
;
4919 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
4920 measure_string_callback
, &args
);
4922 if (linesfilled
) *linesfilled
= lines
;
4923 if (codepointsfitted
) *codepointsfitted
= glyphs
;
4926 bounds
->Width
+= margin_x
* 2.0;
4928 SelectObject(hdc
, oldfont
);
4929 DeleteObject(gdifont
);
4937 struct draw_string_args
{
4938 GpGraphics
*graphics
;
4939 GDIPCONST GpBrush
*brush
;
4940 REAL x
, y
, rel_width
, rel_height
, ascent
;
4943 static GpStatus
draw_string_callback(HDC hdc
,
4944 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4945 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4946 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4947 INT underlined_index_count
, void *user_data
)
4949 struct draw_string_args
*args
= user_data
;
4953 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4954 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4956 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
4957 args
->brush
, &position
,
4958 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4960 if (stat
== Ok
&& underlined_index_count
)
4962 OUTLINETEXTMETRICW otm
;
4963 REAL underline_y
, underline_height
;
4966 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
4968 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
4969 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
4971 for (i
=0; i
<underlined_index_count
; i
++)
4973 REAL start_x
, end_x
;
4975 INT ofs
= underlined_indexes
[i
] - index
;
4977 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
4978 start_x
= text_size
.cx
/ args
->rel_width
;
4980 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
4981 end_x
= text_size
.cx
/ args
->rel_width
;
4983 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
4990 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4991 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4992 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4996 GpPointF pt
[3], rectcpy
[4];
4998 REAL rel_width
, rel_height
, margin_x
;
4999 INT save_state
, format_flags
= 0;
5001 struct draw_string_args args
;
5003 HDC hdc
, temp_hdc
=NULL
;
5004 TEXTMETRICW textmetric
;
5006 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5007 length
, font
, debugstr_rectf(rect
), format
, brush
);
5009 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5010 return InvalidParameter
;
5014 hdc
= graphics
->hdc
;
5018 hdc
= temp_hdc
= CreateCompatibleDC(0);
5022 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5024 format_flags
= format
->attr
;
5026 /* Should be no need to explicitly test for StringAlignmentNear as
5027 * that is default behavior if no alignment is passed. */
5028 if(format
->vertalign
!= StringAlignmentNear
){
5029 RectF bounds
, in_rect
= *rect
;
5030 in_rect
.Height
= 0.0; /* avoid height clipping */
5031 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5033 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5035 if(format
->vertalign
== StringAlignmentCenter
)
5036 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5037 else if(format
->vertalign
== StringAlignmentFar
)
5038 offsety
= (rect
->Height
- bounds
.Height
);
5040 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
5043 save_state
= SaveDC(hdc
);
5051 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5052 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5053 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5054 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5055 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5057 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5058 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5059 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5060 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5061 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5063 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5064 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5066 scaled_rect
.X
= margin_x
* rel_width
;
5067 scaled_rect
.Y
= 0.0;
5068 scaled_rect
.Width
= rel_width
* rect
->Width
;
5069 scaled_rect
.Height
= rel_height
* rect
->Height
;
5070 if (scaled_rect
.Width
>= 0.5)
5072 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5073 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5076 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5077 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5079 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5080 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5081 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5083 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5084 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5085 SelectClipRgn(hdc
, rgn
);
5088 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5089 SelectObject(hdc
, gdifont
);
5091 args
.graphics
= graphics
;
5095 args
.y
= rect
->Y
+ offsety
;
5097 args
.rel_width
= rel_width
;
5098 args
.rel_height
= rel_height
;
5100 GetTextMetricsW(hdc
, &textmetric
);
5101 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5103 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5104 draw_string_callback
, &args
);
5107 DeleteObject(gdifont
);
5109 RestoreDC(hdc
, save_state
);
5116 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5118 TRACE("(%p)\n", graphics
);
5121 return InvalidParameter
;
5126 return GdipSetInfinite(graphics
->clip
);
5129 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5131 TRACE("(%p)\n", graphics
);
5134 return InvalidParameter
;
5139 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5142 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5144 return GdipEndContainer(graphics
, state
);
5147 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5148 GpMatrixOrder order
)
5150 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5153 return InvalidParameter
;
5158 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5161 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5163 return GdipBeginContainer2(graphics
, state
);
5166 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5167 GraphicsContainer
*state
)
5169 GraphicsContainerItem
*container
;
5172 TRACE("(%p, %p)\n", graphics
, state
);
5174 if(!graphics
|| !state
)
5175 return InvalidParameter
;
5177 sts
= init_container(&container
, graphics
);
5181 list_add_head(&graphics
->containers
, &container
->entry
);
5182 *state
= graphics
->contid
= container
->contid
;
5187 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5189 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5190 return NotImplemented
;
5193 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5195 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5196 return NotImplemented
;
5199 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5201 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5202 return NotImplemented
;
5205 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5208 GraphicsContainerItem
*container
, *container2
;
5210 TRACE("(%p, %x)\n", graphics
, state
);
5213 return InvalidParameter
;
5215 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5216 if(container
->contid
== state
)
5220 /* did not find a matching container */
5221 if(&container
->entry
== &graphics
->containers
)
5224 sts
= restore_container(graphics
, container
);
5228 /* remove all of the containers on top of the found container */
5229 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5230 if(container
->contid
== state
)
5232 list_remove(&container
->entry
);
5233 delete_container(container
);
5236 list_remove(&container
->entry
);
5237 delete_container(container
);
5242 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5243 REAL sy
, GpMatrixOrder order
)
5245 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5248 return InvalidParameter
;
5253 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5256 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5259 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5261 if(!graphics
|| !srcgraphics
)
5262 return InvalidParameter
;
5264 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5267 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5268 CompositingMode mode
)
5270 TRACE("(%p, %d)\n", graphics
, mode
);
5273 return InvalidParameter
;
5278 graphics
->compmode
= mode
;
5283 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5284 CompositingQuality quality
)
5286 TRACE("(%p, %d)\n", graphics
, quality
);
5289 return InvalidParameter
;
5294 graphics
->compqual
= quality
;
5299 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5300 InterpolationMode mode
)
5302 TRACE("(%p, %d)\n", graphics
, mode
);
5304 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5305 return InvalidParameter
;
5310 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5311 mode
= InterpolationModeBilinear
;
5313 if (mode
== InterpolationModeHighQuality
)
5314 mode
= InterpolationModeHighQualityBicubic
;
5316 graphics
->interpolation
= mode
;
5321 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5325 TRACE("(%p, %.2f)\n", graphics
, scale
);
5327 if(!graphics
|| (scale
<= 0.0))
5328 return InvalidParameter
;
5333 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5335 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
5340 graphics
->scale
= scale
;
5345 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5349 TRACE("(%p, %d)\n", graphics
, unit
);
5352 return InvalidParameter
;
5357 if(unit
== UnitWorld
)
5358 return InvalidParameter
;
5360 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5362 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
5367 graphics
->unit
= unit
;
5372 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5375 TRACE("(%p, %d)\n", graphics
, mode
);
5378 return InvalidParameter
;
5383 graphics
->pixeloffset
= mode
;
5388 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5392 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5395 FIXME("value is unused in rendering\n");
5398 return InvalidParameter
;
5400 graphics
->origin_x
= x
;
5401 graphics
->origin_y
= y
;
5406 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5408 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5410 if (!graphics
|| !x
|| !y
)
5411 return InvalidParameter
;
5413 *x
= graphics
->origin_x
;
5414 *y
= graphics
->origin_y
;
5419 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5421 TRACE("(%p, %d)\n", graphics
, mode
);
5424 return InvalidParameter
;
5429 graphics
->smoothing
= mode
;
5434 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5436 TRACE("(%p, %d)\n", graphics
, contrast
);
5439 return InvalidParameter
;
5441 graphics
->textcontrast
= contrast
;
5446 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5447 TextRenderingHint hint
)
5449 TRACE("(%p, %d)\n", graphics
, hint
);
5451 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5452 return InvalidParameter
;
5457 graphics
->texthint
= hint
;
5462 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5464 TRACE("(%p, %p)\n", graphics
, matrix
);
5466 if(!graphics
|| !matrix
)
5467 return InvalidParameter
;
5472 TRACE("%f,%f,%f,%f,%f,%f\n",
5473 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5474 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5476 graphics
->worldtrans
= *matrix
;
5481 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5482 REAL dy
, GpMatrixOrder order
)
5484 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5487 return InvalidParameter
;
5492 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5495 /*****************************************************************************
5496 * GdipSetClipHrgn [GDIPLUS.@]
5498 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5503 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5506 return InvalidParameter
;
5511 /* hrgn is already in device units */
5512 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5516 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5518 GdipDeleteRegion(region
);
5522 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5527 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5530 return InvalidParameter
;
5535 status
= GdipClonePath(path
, &clip_path
);
5538 GpMatrix world_to_device
;
5540 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
5541 CoordinateSpaceWorld
, &world_to_device
);
5542 status
= GdipTransformPath(clip_path
, &world_to_device
);
5544 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
5546 GdipDeletePath(clip_path
);
5551 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5552 REAL width
, REAL height
,
5559 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5562 return InvalidParameter
;
5570 rect
.Height
= height
;
5571 status
= GdipCreateRegionRect(&rect
, ®ion
);
5574 GpMatrix world_to_device
;
5576 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5577 status
= GdipTransformRegion(region
, &world_to_device
);
5579 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5581 GdipDeleteRegion(region
);
5586 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5587 INT width
, INT height
,
5590 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5593 return InvalidParameter
;
5598 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5601 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5607 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5609 if(!graphics
|| !region
)
5610 return InvalidParameter
;
5615 status
= GdipCloneRegion(region
, &clip
);
5618 GpMatrix world_to_device
;
5620 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5621 status
= GdipTransformRegion(clip
, &world_to_device
);
5623 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
5625 GdipDeleteRegion(clip
);
5630 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5636 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5638 if(!graphics
|| !pen
|| count
<=0)
5639 return InvalidParameter
;
5646 FIXME("graphics object has no HDC\n");
5650 pti
= heap_alloc_zero(sizeof(POINT
) * count
);
5652 save_state
= prepare_dc(graphics
, pen
);
5653 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5655 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5656 Polygon(graphics
->hdc
, pti
, count
);
5658 restore_dc(graphics
, save_state
);
5664 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5671 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5673 if(count
<=0) return InvalidParameter
;
5674 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
5676 for(i
= 0;i
< count
; i
++){
5677 ptf
[i
].X
= (REAL
)points
[i
].X
;
5678 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5681 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5687 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5689 TRACE("(%p, %p)\n", graphics
, dpi
);
5691 if(!graphics
|| !dpi
)
5692 return InvalidParameter
;
5697 *dpi
= graphics
->xres
;
5701 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5703 TRACE("(%p, %p)\n", graphics
, dpi
);
5705 if(!graphics
|| !dpi
)
5706 return InvalidParameter
;
5711 *dpi
= graphics
->yres
;
5715 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5716 GpMatrixOrder order
)
5721 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5723 if(!graphics
|| !matrix
)
5724 return InvalidParameter
;
5729 m
= graphics
->worldtrans
;
5731 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5733 graphics
->worldtrans
= m
;
5738 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5739 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5741 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5745 TRACE("(%p, %p)\n", graphics
, hdc
);
5747 if(!graphics
|| !hdc
)
5748 return InvalidParameter
;
5753 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5755 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5757 else if (!graphics
->hdc
||
5758 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5760 /* Create a fake HDC and fill it with a constant color. */
5764 BITMAPINFOHEADER bmih
;
5767 stat
= get_graphics_bounds(graphics
, &bounds
);
5771 graphics
->temp_hbitmap_width
= bounds
.Width
;
5772 graphics
->temp_hbitmap_height
= bounds
.Height
;
5774 bmih
.biSize
= sizeof(bmih
);
5775 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5776 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5778 bmih
.biBitCount
= 32;
5779 bmih
.biCompression
= BI_RGB
;
5780 bmih
.biSizeImage
= 0;
5781 bmih
.biXPelsPerMeter
= 0;
5782 bmih
.biYPelsPerMeter
= 0;
5784 bmih
.biClrImportant
= 0;
5786 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5787 (void**)&graphics
->temp_bits
, NULL
, 0);
5789 return GenericError
;
5791 temp_hdc
= CreateCompatibleDC(0);
5794 DeleteObject(hbitmap
);
5795 return GenericError
;
5798 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5799 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5801 SelectObject(temp_hdc
, hbitmap
);
5803 graphics
->temp_hbitmap
= hbitmap
;
5804 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5808 *hdc
= graphics
->hdc
;
5812 graphics
->busy
= TRUE
;
5817 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5821 TRACE("(%p, %p)\n", graphics
, hdc
);
5823 if(!graphics
|| !hdc
|| !graphics
->busy
)
5824 return InvalidParameter
;
5826 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5828 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5830 else if (graphics
->temp_hdc
== hdc
)
5835 /* Find the pixels that have changed, and mark them as opaque. */
5836 pos
= (DWORD
*)graphics
->temp_bits
;
5837 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5839 if (*pos
!= DC_BACKGROUND_KEY
)
5846 /* Write the changed pixels to the real target. */
5847 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5848 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5849 graphics
->temp_hbitmap_width
* 4, PixelFormat32bppARGB
);
5852 DeleteDC(graphics
->temp_hdc
);
5853 DeleteObject(graphics
->temp_hbitmap
);
5854 graphics
->temp_hdc
= NULL
;
5855 graphics
->temp_hbitmap
= NULL
;
5857 else if (hdc
!= graphics
->hdc
)
5859 stat
= InvalidParameter
;
5863 graphics
->busy
= FALSE
;
5868 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5872 GpMatrix device_to_world
;
5874 TRACE("(%p, %p)\n", graphics
, region
);
5876 if(!graphics
|| !region
)
5877 return InvalidParameter
;
5882 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5885 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
5886 status
= GdipTransformRegion(clip
, &device_to_world
);
5889 GdipDeleteRegion(clip
);
5893 /* free everything except root node and header */
5894 delete_element(®ion
->node
);
5895 memcpy(region
, clip
, sizeof(GpRegion
));
5901 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5902 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
5905 REAL scale_x
, scale_y
;
5907 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5909 if (dst_space
!= src_space
)
5911 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5912 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5914 if(graphics
->unit
!= UnitDisplay
)
5916 scale_x
*= graphics
->scale
;
5917 scale_y
*= graphics
->scale
;
5920 /* transform from src_space to CoordinateSpacePage */
5923 case CoordinateSpaceWorld
:
5924 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
5926 case CoordinateSpacePage
:
5928 case CoordinateSpaceDevice
:
5929 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
5933 /* transform from CoordinateSpacePage to dst_space */
5936 case CoordinateSpaceWorld
:
5938 GpMatrix inverted_transform
= graphics
->worldtrans
;
5939 stat
= GdipInvertMatrix(&inverted_transform
);
5941 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
5944 case CoordinateSpacePage
:
5946 case CoordinateSpaceDevice
:
5947 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
5954 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5955 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5960 if(!graphics
|| !points
|| count
<= 0)
5961 return InvalidParameter
;
5966 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5968 if (src_space
== dst_space
) return Ok
;
5970 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5971 if (stat
!= Ok
) return stat
;
5973 return GdipTransformMatrixPoints(&matrix
, points
, count
);
5976 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5977 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5983 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5986 return InvalidParameter
;
5988 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
5992 for(i
= 0; i
< count
; i
++){
5993 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5994 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5997 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6000 for(i
= 0; i
< count
; i
++){
6001 points
[i
].X
= gdip_round(pointsF
[i
].X
);
6002 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
6009 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6021 /*****************************************************************************
6022 * GdipTranslateClip [GDIPLUS.@]
6024 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6026 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6029 return InvalidParameter
;
6034 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6037 /*****************************************************************************
6038 * GdipTranslateClipI [GDIPLUS.@]
6040 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6042 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6045 return InvalidParameter
;
6050 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6054 /*****************************************************************************
6055 * GdipMeasureDriverString [GDIPLUS.@]
6057 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6058 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6059 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6061 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6064 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6066 TEXTMETRICW textmetric
;
6067 const WORD
*glyph_indices
;
6068 WORD
*dynamic_glyph_indices
=NULL
;
6069 REAL rel_width
, rel_height
, ascent
, descent
;
6072 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6074 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6075 return InvalidParameter
;
6078 length
= strlenW(text
);
6082 boundingBox
->X
= 0.0;
6083 boundingBox
->Y
= 0.0;
6084 boundingBox
->Width
= 0.0;
6085 boundingBox
->Height
= 0.0;
6088 if (flags
& unsupported_flags
)
6089 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6091 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6093 hdc
= CreateCompatibleDC(0);
6094 SelectObject(hdc
, hfont
);
6096 GetTextMetricsW(hdc
, &textmetric
);
6106 GpMatrix xform
= *matrix
;
6107 GdipTransformMatrixPoints(&xform
, pt
, 3);
6109 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6110 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6111 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6112 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6113 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6115 if (flags
& DriverStringOptionsCmapLookup
)
6117 glyph_indices
= dynamic_glyph_indices
= heap_alloc_zero(sizeof(WORD
) * length
);
6121 DeleteObject(hfont
);
6125 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6128 glyph_indices
= text
;
6130 min_x
= max_x
= x
= positions
[0].X
;
6131 min_y
= max_y
= y
= positions
[0].Y
;
6133 ascent
= textmetric
.tmAscent
/ rel_height
;
6134 descent
= textmetric
.tmDescent
/ rel_height
;
6136 for (i
=0; i
<length
; i
++)
6141 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6147 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6148 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6150 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6151 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6152 if (min_x
> x
) min_x
= x
;
6154 x
+= char_width
/ rel_width
;
6156 if (max_x
< x
) max_x
= x
;
6159 heap_free(dynamic_glyph_indices
);
6161 DeleteObject(hfont
);
6163 boundingBox
->X
= min_x
;
6164 boundingBox
->Y
= min_y
;
6165 boundingBox
->Width
= max_x
- min_x
;
6166 boundingBox
->Height
= max_y
- min_y
;
6171 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6172 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6173 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6174 INT flags
, GDIPCONST GpMatrix
*matrix
)
6176 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6182 if (flags
& unsupported_flags
)
6183 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6185 if (!(flags
& DriverStringOptionsCmapLookup
))
6186 eto_flags
|= ETO_GLYPH_INDEX
;
6188 save_state
= SaveDC(graphics
->hdc
);
6189 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6190 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6193 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6195 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6196 SelectObject(graphics
->hdc
, hfont
);
6198 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6200 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6202 RestoreDC(graphics
->hdc
, save_state
);
6204 DeleteObject(hfont
);
6209 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6210 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6211 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6212 INT flags
, GDIPCONST GpMatrix
*matrix
)
6214 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6216 PointF
*real_positions
, real_position
;
6220 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6221 DWORD max_glyphsize
=0;
6222 GLYPHMETRICS glyphmetrics
;
6223 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6226 int text_mask_stride
;
6228 int pixel_data_stride
;
6230 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6235 if (!(flags
& DriverStringOptionsCmapLookup
))
6236 ggo_flags
|= GGO_GLYPH_INDEX
;
6238 if (flags
& unsupported_flags
)
6239 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6241 pti
= heap_alloc_zero(sizeof(POINT
) * length
);
6245 if (flags
& DriverStringOptionsRealizedAdvance
)
6247 real_position
= positions
[0];
6249 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6253 real_positions
= heap_alloc_zero(sizeof(PointF
) * length
);
6254 if (!real_positions
)
6260 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6262 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6264 heap_free(real_positions
);
6267 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6269 hdc
= CreateCompatibleDC(0);
6270 SelectObject(hdc
, hfont
);
6272 /* Get the boundaries of the text to be drawn */
6273 for (i
=0; i
<length
; i
++)
6276 int left
, top
, right
, bottom
;
6278 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6279 &glyphmetrics
, 0, NULL
, &identity
);
6281 if (glyphsize
== GDI_ERROR
)
6283 ERR("GetGlyphOutlineW failed\n");
6286 DeleteObject(hfont
);
6287 return GenericError
;
6290 if (glyphsize
> max_glyphsize
)
6291 max_glyphsize
= glyphsize
;
6295 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6296 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6297 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6298 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6300 if (left
< min_x
) min_x
= left
;
6301 if (top
< min_y
) min_y
= top
;
6302 if (right
> max_x
) max_x
= right
;
6303 if (bottom
> max_y
) max_y
= bottom
;
6306 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6308 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6309 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6313 if (max_glyphsize
== 0)
6314 /* Nothing to draw. */
6317 glyph_mask
= heap_alloc_zero(max_glyphsize
);
6318 text_mask
= heap_alloc_zero((max_x
- min_x
) * (max_y
- min_y
));
6319 text_mask_stride
= max_x
- min_x
;
6321 if (!(glyph_mask
&& text_mask
))
6323 heap_free(glyph_mask
);
6324 heap_free(text_mask
);
6327 DeleteObject(hfont
);
6331 /* Generate a mask for the text */
6332 for (i
=0; i
<length
; i
++)
6335 int left
, top
, stride
;
6337 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6338 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6340 if (ret
== GDI_ERROR
|| ret
== 0)
6341 continue; /* empty glyph */
6343 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6344 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6345 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6347 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6349 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6350 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6351 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6353 *text_val
= min(64, *text_val
+ *glyph_val
);
6362 DeleteObject(hfont
);
6363 heap_free(glyph_mask
);
6365 /* get the brush data */
6366 pixel_data
= heap_alloc_zero(4 * (max_x
- min_x
) * (max_y
- min_y
));
6369 heap_free(text_mask
);
6373 pixel_area
.X
= min_x
;
6374 pixel_area
.Y
= min_y
;
6375 pixel_area
.Width
= max_x
- min_x
;
6376 pixel_area
.Height
= max_y
- min_y
;
6377 pixel_data_stride
= pixel_area
.Width
* 4;
6379 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6382 heap_free(text_mask
);
6383 heap_free(pixel_data
);
6387 /* multiply the brush data by the mask */
6388 for (y
=0; y
<pixel_area
.Height
; y
++)
6390 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6391 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6392 for (x
=0; x
<pixel_area
.Width
; x
++)
6394 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6400 heap_free(text_mask
);
6402 /* draw the result */
6403 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6404 pixel_area
.Height
, pixel_data_stride
, PixelFormat32bppARGB
);
6406 heap_free(pixel_data
);
6411 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6412 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6413 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6414 INT flags
, GDIPCONST GpMatrix
*matrix
)
6416 GpStatus stat
= NotImplemented
;
6419 length
= strlenW(text
);
6421 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6422 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6423 brush
->bt
== BrushTypeSolidColor
&&
6424 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6425 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6426 brush
, positions
, flags
, matrix
);
6427 if (stat
== NotImplemented
)
6428 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6429 brush
, positions
, flags
, matrix
);
6433 /*****************************************************************************
6434 * GdipDrawDriverString [GDIPLUS.@]
6436 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6437 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6438 GDIPCONST PointF
*positions
, INT flags
,
6439 GDIPCONST GpMatrix
*matrix
)
6441 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6443 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6444 return InvalidParameter
;
6446 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6447 brush
, positions
, flags
, matrix
);
6450 /*****************************************************************************
6451 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6453 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6458 TRACE("(%p, %p)\n", graphics
, res
);
6460 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6463 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6466 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6469 GdipDeleteRegion(rgn
);
6473 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6477 TRACE("(%p) stub\n", graphics
);
6480 FIXME("not implemented\n");
6482 return NotImplemented
;