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
19 #include "gdiplus_private.h"
24 /* Mike "tamlin" Nordell 2012-09-14 for ReactOS:
25 * NOTE: Wine uses per-GpGraphics id's ('contid' starting from zero in
26 * every GpGraphics). Windows seems to use process-global id's, or at
27 * least more unique id's.
28 * This have the following implications. It:
29 * 1. fails the current gdiplus test case.
30 * 2. is not what Windows does.
32 * We therefore "obfuscate" the 'contid' a little to more match Windows'
33 * behaviour. The observable behviour should still remain the same,
34 * except for handing out more "unique" id's.
36 #define GDIP_CONTID_STEP 64
37 static volatile LONG g_priv_contid
= GDIP_CONTID_STEP
;
38 #define GDIP_GET_NEW_CONTID_FOR(pGpGraphics) \
39 (UINT)(InterlockedExchangeAdd(&g_priv_contid,GDIP_CONTID_STEP))
41 /* looks-right constants */
42 #define ANCHOR_WIDTH (2.0)
43 #define MAX_ITERS (50)
45 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
46 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
47 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
48 INT flags
, GDIPCONST GpMatrix
*matrix
);
50 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
51 GpCoordinateSpace src_space
, GpMatrix
*matrix
);
53 /* Converts from gdiplus path point type to gdi path point type. */
54 static BYTE
convert_path_point_type(BYTE type
)
58 switch(type
& PathPointTypePathTypeMask
){
59 case PathPointTypeBezier
:
62 case PathPointTypeLine
:
65 case PathPointTypeStart
:
69 ERR("Bad point type\n");
73 if(type
& PathPointTypeCloseSubpath
)
74 ret
|= PT_CLOSEFIGURE
;
79 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
85 case BrushTypeSolidColor
:
87 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
91 case BrushTypeHatchFill
:
93 const GpHatch
*hatch
= (const GpHatch
*)brush
;
94 argb
= hatch
->forecol
;
97 case BrushTypeLinearGradient
:
99 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
100 argb
= line
->startcolor
;
103 case BrushTypePathGradient
:
105 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
106 argb
= grad
->centercolor
;
110 FIXME("unhandled brush type %d\n", brush
->bt
);
114 return ARGB2COLORREF(argb
);
117 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
120 BITMAPINFOHEADER bmih
;
124 bmih
.biSize
= sizeof(bmih
);
128 bmih
.biBitCount
= 32;
129 bmih
.biCompression
= BI_RGB
;
130 bmih
.biSizeImage
= 0;
132 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
135 const char *hatch_data
;
137 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
139 for (y
= 0; y
< 8; y
++)
141 for (x
= 0; x
< 8; x
++)
143 if (hatch_data
[y
] & (0x80 >> x
))
144 bits
[y
* 8 + x
] = hatch
->forecol
;
146 bits
[y
* 8 + x
] = hatch
->backcol
;
152 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
154 for (y
= 0; y
< 64; y
++)
155 bits
[y
] = hatch
->forecol
;
162 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
166 case BrushTypeSolidColor
:
168 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
169 lb
->lbStyle
= BS_SOLID
;
170 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
175 case BrushTypeHatchFill
:
177 const GpHatch
*hatch
= (const GpHatch
*)brush
;
180 hbmp
= create_hatch_bitmap(hatch
);
181 if (!hbmp
) return OutOfMemory
;
183 lb
->lbStyle
= BS_PATTERN
;
185 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
190 FIXME("unhandled brush type %d\n", brush
->bt
);
191 lb
->lbStyle
= BS_SOLID
;
192 lb
->lbColor
= get_gdi_brush_color(brush
);
198 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
203 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
209 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
214 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
216 gdibrush
= CreateBrushIndirect(&lb
);
217 free_gdi_logbrush(&lb
);
222 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
227 INT save_state
, i
, numdashes
;
229 DWORD dash_array
[MAX_DASHLEN
];
231 save_state
= SaveDC(graphics
->hdc
);
233 EndPath(graphics
->hdc
);
235 if(pen
->unit
== UnitPixel
){
239 /* Get an estimate for the amount the pen width is affected by the world
240 * transform. (This is similar to what some of the wine drivers do.) */
245 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
246 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
247 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
249 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
250 width
*= graphics
->scale
;
253 if(pen
->dash
== DashStyleCustom
){
254 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
256 TRACE("dashes are: ");
257 for(i
= 0; i
< numdashes
; i
++){
258 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
259 TRACE("%d, ", dash_array
[i
]);
261 TRACE("\n and the pen style is %x\n", pen
->style
);
263 create_gdi_logbrush(pen
->brush
, &lb
);
264 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
265 numdashes
, dash_array
);
266 free_gdi_logbrush(&lb
);
270 create_gdi_logbrush(pen
->brush
, &lb
);
271 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
272 free_gdi_logbrush(&lb
);
275 SelectObject(graphics
->hdc
, gdipen
);
280 static void restore_dc(GpGraphics
*graphics
, INT state
)
282 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
283 RestoreDC(graphics
->hdc
, state
);
286 /* This helper applies all the changes that the points listed in ptf need in
287 * order to be drawn on the device context. In the end, this should include at
289 * -scaling by page unit
290 * -applying world transformation
291 * -converting from float to int
292 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
293 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
294 * gdi to draw, and these functions would irreparably mess with line widths.
296 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
297 GpPointF
*ptf
, INT count
)
299 REAL scale_x
, scale_y
;
303 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
304 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
306 /* apply page scale */
307 if(graphics
->unit
!= UnitDisplay
)
309 scale_x
*= graphics
->scale
;
310 scale_y
*= graphics
->scale
;
313 matrix
= graphics
->worldtrans
;
314 GdipScaleMatrix(&matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
315 GdipTransformMatrixPoints(&matrix
, ptf
, count
);
317 for(i
= 0; i
< count
; i
++){
318 pti
[i
].x
= gdip_round(ptf
[i
].X
);
319 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
323 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
324 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
326 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
328 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
330 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
331 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
337 bf
.BlendOp
= AC_SRC_OVER
;
339 bf
.SourceConstantAlpha
= 255;
340 bf
.AlphaFormat
= AC_SRC_ALPHA
;
342 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
343 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
347 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
349 /* clipping region is in device coords */
350 return GdipGetRegionHRgn(graphics
->clip
, NULL
, hrgn
);
353 /* Draw ARGB data to the given graphics object */
354 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
355 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, const PixelFormat fmt
)
357 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
360 for (y
=0; y
<src_height
; y
++)
362 for (x
=0; x
<src_width
; x
++)
364 ARGB dst_color
, src_color
;
365 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
367 if (!(src_color
& 0xff000000))
370 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
371 if (fmt
& PixelFormatPAlpha
)
372 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over_fgpremult(dst_color
, src_color
));
374 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
381 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
382 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
386 BITMAPINFOHEADER bih
;
389 hdc
= CreateCompatibleDC(0);
391 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
392 bih
.biWidth
= src_width
;
393 bih
.biHeight
= -src_height
;
396 bih
.biCompression
= BI_RGB
;
398 bih
.biXPelsPerMeter
= 0;
399 bih
.biYPelsPerMeter
= 0;
401 bih
.biClrImportant
= 0;
403 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
404 (void**)&temp_bits
, NULL
, 0);
406 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
||
407 fmt
& PixelFormatPAlpha
)
408 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
410 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
411 4 * src_width
, src
, src_stride
);
413 SelectObject(hdc
, hbitmap
);
414 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
415 hdc
, 0, 0, src_width
, src_height
);
417 DeleteObject(hbitmap
);
422 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
423 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
, PixelFormat fmt
)
427 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
433 HRGN hrgn
, visible_rgn
;
435 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
439 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
448 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
449 DeleteObject(visible_rgn
);
453 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
455 size
= GetRegionData(hrgn
, 0, NULL
);
457 rgndata
= heap_alloc_zero(size
);
464 GetRegionData(hrgn
, size
, rgndata
);
466 rects
= (RECT
*)rgndata
->Buffer
;
468 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
470 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
471 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
472 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
482 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
484 ERR("This should not be used for metafiles; fix caller\n");
485 return NotImplemented
;
492 stat
= get_clip_hrgn(graphics
, &hrgn
);
497 save
= SaveDC(graphics
->hdc
);
500 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
503 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
505 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
506 src_height
, src_stride
, fmt
);
508 RestoreDC(graphics
->hdc
, save
);
516 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
517 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
519 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
, fmt
);
522 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
524 INT start_a
, end_a
, final_a
;
527 pos
= gdip_round(position
* 0xff);
529 start_a
= ((start
>> 24) & 0xff) * (pos
^ 0xff);
530 end_a
= ((end
>> 24) & 0xff) * pos
;
532 final_a
= start_a
+ end_a
;
534 if (final_a
< 0xff) return 0;
536 return (final_a
/ 0xff) << 24 |
537 ((((start
>> 16) & 0xff) * start_a
+ (((end
>> 16) & 0xff) * end_a
)) / final_a
) << 16 |
538 ((((start
>> 8) & 0xff) * start_a
+ (((end
>> 8) & 0xff) * end_a
)) / final_a
) << 8 |
539 (((start
& 0xff) * start_a
+ ((end
& 0xff) * end_a
)) / final_a
);
542 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
546 /* clamp to between 0.0 and 1.0, using the wrap mode */
547 if (brush
->wrap
== WrapModeTile
)
549 position
= fmodf(position
, 1.0f
);
550 if (position
< 0.0f
) position
+= 1.0f
;
552 else /* WrapModeFlip* */
554 position
= fmodf(position
, 2.0f
);
555 if (position
< 0.0f
) position
+= 2.0f
;
556 if (position
> 1.0f
) position
= 2.0f
- position
;
559 if (brush
->blendcount
== 1)
564 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
567 /* locate the blend positions surrounding this position */
568 while (position
> brush
->blendpos
[i
])
571 /* interpolate between the blend positions */
572 left_blendpos
= brush
->blendpos
[i
-1];
573 left_blendfac
= brush
->blendfac
[i
-1];
574 right_blendpos
= brush
->blendpos
[i
];
575 right_blendfac
= brush
->blendfac
[i
];
576 range
= right_blendpos
- left_blendpos
;
577 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
578 right_blendfac
* (position
- left_blendpos
)) / range
;
581 if (brush
->pblendcount
== 0)
582 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
586 ARGB left_blendcolor
, right_blendcolor
;
587 REAL left_blendpos
, right_blendpos
;
589 /* locate the blend colors surrounding this position */
590 while (blendfac
> brush
->pblendpos
[i
])
593 /* interpolate between the blend colors */
594 left_blendpos
= brush
->pblendpos
[i
-1];
595 left_blendcolor
= brush
->pblendcolor
[i
-1];
596 right_blendpos
= brush
->pblendpos
[i
];
597 right_blendcolor
= brush
->pblendcolor
[i
];
598 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
599 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
603 static BOOL
round_color_matrix(const ColorMatrix
*matrix
, int values
[5][5])
605 /* Convert floating point color matrix to int[5][5], return TRUE if it's an identity */
606 BOOL identity
= TRUE
;
612 if (matrix
->m
[j
][i
] != (i
== j
? 1.0 : 0.0))
614 values
[j
][i
] = gdip_round(matrix
->m
[j
][i
] * 256.0);
620 static ARGB
transform_color(ARGB color
, int matrix
[5][5])
624 unsigned char a
, r
, g
, b
;
626 val
[0] = ((color
>> 16) & 0xff); /* red */
627 val
[1] = ((color
>> 8) & 0xff); /* green */
628 val
[2] = (color
& 0xff); /* blue */
629 val
[3] = ((color
>> 24) & 0xff); /* alpha */
630 val
[4] = 255; /* translation */
637 res
[i
] += matrix
[j
][i
] * val
[j
];
640 a
= min(max(res
[3] / 256, 0), 255);
641 r
= min(max(res
[0] / 256, 0), 255);
642 g
= min(max(res
[1] / 256, 0), 255);
643 b
= min(max(res
[2] / 256, 0), 255);
645 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
648 static BOOL
color_is_gray(ARGB color
)
650 unsigned char r
, g
, b
;
652 r
= (color
>> 16) & 0xff;
653 g
= (color
>> 8) & 0xff;
656 return (r
== g
) && (g
== b
);
659 /* returns preferred pixel format for the applied attributes */
660 static PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
661 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
)
666 if (attributes
->colorkeys
[type
].enabled
||
667 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
669 const struct color_key
*key
;
670 BYTE min_blue
, min_green
, min_red
;
671 BYTE max_blue
, max_green
, max_red
;
673 if (!data
|| fmt
!= PixelFormat32bppARGB
)
674 return PixelFormat32bppARGB
;
676 if (attributes
->colorkeys
[type
].enabled
)
677 key
= &attributes
->colorkeys
[type
];
679 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
681 min_blue
= key
->low
&0xff;
682 min_green
= (key
->low
>>8)&0xff;
683 min_red
= (key
->low
>>16)&0xff;
685 max_blue
= key
->high
&0xff;
686 max_green
= (key
->high
>>8)&0xff;
687 max_red
= (key
->high
>>16)&0xff;
689 for (x
=0; x
<width
; x
++)
690 for (y
=0; y
<height
; y
++)
693 BYTE blue
, green
, red
;
694 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
695 blue
= *src_color
&0xff;
696 green
= (*src_color
>>8)&0xff;
697 red
= (*src_color
>>16)&0xff;
698 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
699 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
700 *src_color
= 0x00000000;
704 if (attributes
->colorremaptables
[type
].enabled
||
705 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
707 const struct color_remap_table
*table
;
709 if (!data
|| fmt
!= PixelFormat32bppARGB
)
710 return PixelFormat32bppARGB
;
712 if (attributes
->colorremaptables
[type
].enabled
)
713 table
= &attributes
->colorremaptables
[type
];
715 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
717 for (x
=0; x
<width
; x
++)
718 for (y
=0; y
<height
; y
++)
721 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
722 for (i
=0; i
<table
->mapsize
; i
++)
724 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
726 *src_color
= table
->colormap
[i
].newColor
.Argb
;
733 if (attributes
->colormatrices
[type
].enabled
||
734 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
736 const struct color_matrix
*colormatrices
;
737 int color_matrix
[5][5];
738 int gray_matrix
[5][5];
741 if (!data
|| fmt
!= PixelFormat32bppARGB
)
742 return PixelFormat32bppARGB
;
744 if (attributes
->colormatrices
[type
].enabled
)
745 colormatrices
= &attributes
->colormatrices
[type
];
747 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
749 identity
= round_color_matrix(&colormatrices
->colormatrix
, color_matrix
);
751 if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
752 identity
= (round_color_matrix(&colormatrices
->graymatrix
, gray_matrix
) && identity
);
756 for (x
=0; x
<width
; x
++)
758 for (y
=0; y
<height
; y
++)
761 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
763 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
764 !color_is_gray(*src_color
))
766 *src_color
= transform_color(*src_color
, color_matrix
);
768 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
770 *src_color
= transform_color(*src_color
, gray_matrix
);
777 if (attributes
->gamma_enabled
[type
] ||
778 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
782 if (!data
|| fmt
!= PixelFormat32bppARGB
)
783 return PixelFormat32bppARGB
;
785 if (attributes
->gamma_enabled
[type
])
786 gamma
= attributes
->gamma
[type
];
788 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
790 for (x
=0; x
<width
; x
++)
791 for (y
=0; y
<height
; y
++)
794 BYTE blue
, green
, red
;
795 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
797 blue
= *src_color
&0xff;
798 green
= (*src_color
>>8)&0xff;
799 red
= (*src_color
>>16)&0xff;
801 /* FIXME: We should probably use a table for this. */
802 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
803 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
804 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
806 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
813 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
814 * bitmap that contains all the pixels we may need to draw it. */
815 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
816 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
819 INT left
, top
, right
, bottom
;
821 switch (interpolation
)
823 case InterpolationModeHighQualityBilinear
:
824 case InterpolationModeHighQualityBicubic
:
825 /* FIXME: Include a greater range for the prefilter? */
826 case InterpolationModeBicubic
:
827 case InterpolationModeBilinear
:
828 left
= (INT
)(floorf(srcx
));
829 top
= (INT
)(floorf(srcy
));
830 right
= (INT
)(ceilf(srcx
+srcwidth
));
831 bottom
= (INT
)(ceilf(srcy
+srcheight
));
833 case InterpolationModeNearestNeighbor
:
835 left
= gdip_round(srcx
);
836 top
= gdip_round(srcy
);
837 right
= gdip_round(srcx
+srcwidth
);
838 bottom
= gdip_round(srcy
+srcheight
);
842 if (wrap
== WrapModeClamp
)
848 if (right
>= bitmap
->width
)
849 right
= bitmap
->width
-1;
850 if (bottom
>= bitmap
->height
)
851 bottom
= bitmap
->height
-1;
852 if (bottom
< top
|| right
< left
)
853 /* entirely outside image, just sample a pixel so we don't have to
854 * special-case this later */
855 left
= top
= right
= bottom
= 0;
859 /* In some cases we can make the rectangle smaller here, but the logic
860 * is hard to get right, and tiling suggests we're likely to use the
861 * entire source image. */
862 if (left
< 0 || right
>= bitmap
->width
)
865 right
= bitmap
->width
-1;
868 if (top
< 0 || bottom
>= bitmap
->height
)
871 bottom
= bitmap
->height
-1;
877 rect
->Width
= right
- left
+ 1;
878 rect
->Height
= bottom
- top
+ 1;
881 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
882 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
884 if (attributes
->wrap
== WrapModeClamp
)
886 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
887 return attributes
->outside_color
;
891 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
893 x
= width
*2 + x
% (width
* 2);
895 y
= height
*2 + y
% (height
* 2);
897 if ((attributes
->wrap
& 1) == 1)
900 if ((x
/ width
) % 2 == 0)
903 x
= width
- 1 - x
% width
;
908 if ((attributes
->wrap
& 2) == 2)
911 if ((y
/ height
) % 2 == 0)
914 y
= height
- 1 - y
% height
;
920 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
922 ERR("out of range pixel requested\n");
926 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
929 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
930 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
931 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
935 switch (interpolation
)
939 FIXME("Unimplemented interpolation %i\n", interpolation
);
941 case InterpolationModeBilinear
:
944 INT leftx
, rightx
, topy
, bottomy
;
945 ARGB topleft
, topright
, bottomleft
, bottomright
;
949 leftxf
= floorf(point
->X
);
951 rightx
= (INT
)ceilf(point
->X
);
952 topyf
= floorf(point
->Y
);
954 bottomy
= (INT
)ceilf(point
->Y
);
956 if (leftx
== rightx
&& topy
== bottomy
)
957 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
958 leftx
, topy
, attributes
);
960 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
961 leftx
, topy
, attributes
);
962 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
963 rightx
, topy
, attributes
);
964 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
965 leftx
, bottomy
, attributes
);
966 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
967 rightx
, bottomy
, attributes
);
969 x_offset
= point
->X
- leftxf
;
970 top
= blend_colors(topleft
, topright
, x_offset
);
971 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
973 return blend_colors(top
, bottom
, point
->Y
- topyf
);
975 case InterpolationModeNearestNeighbor
:
981 case PixelOffsetModeNone
:
982 case PixelOffsetModeHighSpeed
:
986 case PixelOffsetModeHalf
:
987 case PixelOffsetModeHighQuality
:
991 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
992 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
998 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
1000 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
1003 static BOOL
brush_can_fill_path(GpBrush
*brush
)
1007 case BrushTypeSolidColor
:
1009 case BrushTypeHatchFill
:
1011 GpHatch
*hatch
= (GpHatch
*)brush
;
1012 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
1013 ((hatch
->backcol
& 0xff000000) == 0xff000000);
1015 case BrushTypeLinearGradient
:
1016 case BrushTypeTextureFill
:
1017 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
1023 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
1027 case BrushTypeSolidColor
:
1029 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1030 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1035 /* partially transparent fill */
1037 SelectClipPath(graphics
->hdc
, RGN_AND
);
1038 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1040 HDC hdc
= CreateCompatibleDC(NULL
);
1044 SelectObject(hdc
, bmp
);
1045 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1053 /* else fall through */
1057 HBRUSH gdibrush
, old_brush
;
1059 gdibrush
= create_gdi_brush(brush
);
1060 if (!gdibrush
) return;
1062 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1063 FillPath(graphics
->hdc
);
1064 SelectObject(graphics
->hdc
, old_brush
);
1065 DeleteObject(gdibrush
);
1071 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1075 case BrushTypeSolidColor
:
1076 case BrushTypeHatchFill
:
1077 case BrushTypeLinearGradient
:
1078 case BrushTypeTextureFill
:
1079 case BrushTypePathGradient
:
1086 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1087 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1091 case BrushTypeSolidColor
:
1094 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1095 for (x
=0; x
<fill_area
->Width
; x
++)
1096 for (y
=0; y
<fill_area
->Height
; y
++)
1097 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1100 case BrushTypeHatchFill
:
1103 GpHatch
*fill
= (GpHatch
*)brush
;
1104 const char *hatch_data
;
1106 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1107 return NotImplemented
;
1109 for (x
=0; x
<fill_area
->Width
; x
++)
1110 for (y
=0; y
<fill_area
->Height
; y
++)
1114 /* FIXME: Account for the rendering origin */
1115 hx
= (x
+ fill_area
->X
) % 8;
1116 hy
= (y
+ fill_area
->Y
) % 8;
1118 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1119 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1121 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1126 case BrushTypeLinearGradient
:
1128 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1129 GpPointF draw_points
[3], line_points
[3];
1131 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1132 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1135 draw_points
[0].X
= fill_area
->X
;
1136 draw_points
[0].Y
= fill_area
->Y
;
1137 draw_points
[1].X
= fill_area
->X
+1;
1138 draw_points
[1].Y
= fill_area
->Y
;
1139 draw_points
[2].X
= fill_area
->X
;
1140 draw_points
[2].Y
= fill_area
->Y
+1;
1142 /* Transform the points to a co-ordinate space where X is the point's
1143 * position in the gradient, 0.0 being the start point and 1.0 the
1145 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1146 CoordinateSpaceDevice
, draw_points
, 3);
1150 line_points
[0] = fill
->startpoint
;
1151 line_points
[1] = fill
->endpoint
;
1152 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1153 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1155 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1160 stat
= GdipInvertMatrix(world_to_gradient
);
1163 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1165 GdipDeleteMatrix(world_to_gradient
);
1170 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1171 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1173 for (y
=0; y
<fill_area
->Height
; y
++)
1175 for (x
=0; x
<fill_area
->Width
; x
++)
1177 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1179 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1186 case BrushTypeTextureFill
:
1188 GpTexture
*fill
= (GpTexture
*)brush
;
1189 GpPointF draw_points
[3];
1196 if (fill
->image
->type
!= ImageTypeBitmap
)
1198 FIXME("metafile texture brushes not implemented\n");
1199 return NotImplemented
;
1202 bitmap
= (GpBitmap
*)fill
->image
;
1203 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1205 src_area
.X
= src_area
.Y
= 0;
1206 src_area
.Width
= bitmap
->width
;
1207 src_area
.Height
= bitmap
->height
;
1209 draw_points
[0].X
= fill_area
->X
;
1210 draw_points
[0].Y
= fill_area
->Y
;
1211 draw_points
[1].X
= fill_area
->X
+1;
1212 draw_points
[1].Y
= fill_area
->Y
;
1213 draw_points
[2].X
= fill_area
->X
;
1214 draw_points
[2].Y
= fill_area
->Y
+1;
1216 /* Transform the points to the co-ordinate space of the bitmap. */
1217 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1218 CoordinateSpaceDevice
, draw_points
, 3);
1222 GpMatrix world_to_texture
= fill
->transform
;
1224 stat
= GdipInvertMatrix(&world_to_texture
);
1226 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1229 if (stat
== Ok
&& !fill
->bitmap_bits
)
1231 BitmapData lockeddata
;
1233 fill
->bitmap_bits
= heap_alloc_zero(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1234 if (!fill
->bitmap_bits
)
1239 lockeddata
.Width
= bitmap
->width
;
1240 lockeddata
.Height
= bitmap
->height
;
1241 lockeddata
.Stride
= src_stride
;
1242 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1243 lockeddata
.Scan0
= fill
->bitmap_bits
;
1245 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1246 PixelFormat32bppARGB
, &lockeddata
);
1250 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1253 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1254 bitmap
->width
, bitmap
->height
,
1255 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
1259 heap_free(fill
->bitmap_bits
);
1260 fill
->bitmap_bits
= NULL
;
1266 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1267 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1268 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1269 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1271 for (y
=0; y
<fill_area
->Height
; y
++)
1273 for (x
=0; x
<fill_area
->Width
; x
++)
1276 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1277 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1279 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1280 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1281 &point
, fill
->imageattributes
, graphics
->interpolation
,
1282 graphics
->pixeloffset
);
1289 case BrushTypePathGradient
:
1291 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1293 GpMatrix world_to_device
;
1295 int i
, figure_start
=0;
1296 GpPointF start_point
, end_point
, center_point
;
1298 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1299 INT min_y
, max_y
, min_x
, max_x
;
1302 static BOOL transform_fixme_once
;
1304 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1308 FIXME("path gradient focus not implemented\n");
1315 FIXME("path gradient gamma correction not implemented\n");
1318 if (fill
->blendcount
)
1322 FIXME("path gradient blend not implemented\n");
1325 if (fill
->pblendcount
)
1329 FIXME("path gradient preset blend not implemented\n");
1332 if (!transform_fixme_once
)
1334 BOOL is_identity
=TRUE
;
1335 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1338 FIXME("path gradient transform not implemented\n");
1339 transform_fixme_once
= TRUE
;
1343 stat
= GdipClonePath(fill
->path
, &flat_path
);
1348 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1349 CoordinateSpaceWorld
, &world_to_device
);
1352 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1356 center_point
= fill
->center
;
1357 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1361 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1366 GdipDeletePath(flat_path
);
1370 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1372 int start_center_line
=0, end_center_line
=0;
1373 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1374 REAL center_distance
;
1375 ARGB start_color
, end_color
;
1378 type
= flat_path
->pathdata
.Types
[i
];
1380 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1383 start_point
= flat_path
->pathdata
.Points
[i
];
1385 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1387 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1389 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1390 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1392 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1394 end_point
= flat_path
->pathdata
.Points
[i
+1];
1395 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1400 outer_color
= start_color
;
1402 min_yf
= center_point
.Y
;
1403 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1404 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1406 if (min_yf
< fill_area
->Y
)
1407 min_y
= fill_area
->Y
;
1409 min_y
= (INT
)ceil(min_yf
);
1411 max_yf
= center_point
.Y
;
1412 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1413 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1415 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1416 max_y
= fill_area
->Y
+ fill_area
->Height
;
1418 max_y
= (INT
)ceil(max_yf
);
1420 dy
= end_point
.Y
- start_point
.Y
;
1421 dx
= end_point
.X
- start_point
.X
;
1423 /* This is proportional to the distance from start-end line to center point. */
1424 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1425 dx
* (center_point
.Y
- start_point
.Y
);
1427 for (y
=min_y
; y
<max_y
; y
++)
1431 if (!seen_start
&& yf
>= start_point
.Y
)
1434 start_center_line
^= 1;
1436 if (!seen_end
&& yf
>= end_point
.Y
)
1439 end_center_line
^= 1;
1441 if (!seen_center
&& yf
>= center_point
.Y
)
1444 start_center_line
^= 1;
1445 end_center_line
^= 1;
1448 if (start_center_line
)
1449 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1451 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1453 if (end_center_line
)
1454 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1456 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1458 if (line1_xf
< line2_xf
)
1460 min_x
= (INT
)ceil(line1_xf
);
1461 max_x
= (INT
)ceil(line2_xf
);
1465 min_x
= (INT
)ceil(line2_xf
);
1466 max_x
= (INT
)ceil(line1_xf
);
1469 if (min_x
< fill_area
->X
)
1470 min_x
= fill_area
->X
;
1471 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1472 max_x
= fill_area
->X
+ fill_area
->Width
;
1474 for (x
=min_x
; x
<max_x
; x
++)
1479 if (start_color
!= end_color
)
1481 REAL blend_amount
, pdy
, pdx
;
1482 pdy
= yf
- center_point
.Y
;
1483 pdx
= xf
- center_point
.X
;
1484 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1485 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1488 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1489 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1491 distance
= distance
/ center_distance
;
1493 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1494 blend_colors(outer_color
, fill
->centercolor
, distance
);
1499 GdipDeletePath(flat_path
);
1503 return NotImplemented
;
1507 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1508 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1509 * should not be called on an hdc that has a path you care about. */
1510 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1511 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1513 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1515 HBRUSH brush
= NULL
;
1517 PointF ptf
[4], *custptf
= NULL
;
1518 POINT pt
[4], *custpt
= NULL
;
1520 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1525 if((x1
== x2
) && (y1
== y2
))
1528 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1530 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1532 brush
= CreateSolidBrush(color
);
1533 lb
.lbStyle
= BS_SOLID
;
1536 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1537 PS_JOIN_MITER
, 1, &lb
, 0,
1539 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1540 oldpen
= SelectObject(graphics
->hdc
, pen
);
1547 case LineCapSquareAnchor
:
1548 case LineCapDiamondAnchor
:
1549 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1550 if(cap
== LineCapDiamondAnchor
){
1551 dsmall
= cos(theta
+ M_PI_2
) * size
;
1552 dbig
= sin(theta
+ M_PI_2
) * size
;
1555 dsmall
= cos(theta
+ M_PI_4
) * size
;
1556 dbig
= sin(theta
+ M_PI_4
) * size
;
1559 ptf
[0].X
= x2
- dsmall
;
1560 ptf
[1].X
= x2
+ dbig
;
1562 ptf
[0].Y
= y2
- dbig
;
1563 ptf
[3].Y
= y2
+ dsmall
;
1565 ptf
[1].Y
= y2
- dsmall
;
1566 ptf
[2].Y
= y2
+ dbig
;
1568 ptf
[3].X
= x2
- dbig
;
1569 ptf
[2].X
= x2
+ dsmall
;
1571 transform_and_round_points(graphics
, pt
, ptf
, 4);
1572 Polygon(graphics
->hdc
, pt
, 4);
1575 case LineCapArrowAnchor
:
1576 size
= size
* 4.0 / sqrt(3.0);
1578 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1579 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1584 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1585 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1593 transform_and_round_points(graphics
, pt
, ptf
, 3);
1594 Polygon(graphics
->hdc
, pt
, 3);
1597 case LineCapRoundAnchor
:
1598 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1605 transform_and_round_points(graphics
, pt
, ptf
, 2);
1606 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1609 case LineCapTriangle
:
1611 dx
= cos(M_PI_2
+ theta
) * size
;
1612 dy
= sin(M_PI_2
+ theta
) * size
;
1619 dx
= cos(theta
) * size
;
1620 dy
= sin(theta
) * size
;
1625 transform_and_round_points(graphics
, pt
, ptf
, 3);
1626 Polygon(graphics
->hdc
, pt
, 3);
1630 dx
= dy
= size
/ 2.0;
1637 dx
= -cos(M_PI_2
+ theta
) * size
;
1638 dy
= -sin(M_PI_2
+ theta
) * size
;
1645 transform_and_round_points(graphics
, pt
, ptf
, 4);
1646 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1647 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1654 count
= custom
->pathdata
.Count
;
1655 custptf
= heap_alloc_zero(count
* sizeof(PointF
));
1656 custpt
= heap_alloc_zero(count
* sizeof(POINT
));
1657 tp
= heap_alloc_zero(count
);
1659 if(!custptf
|| !custpt
|| !tp
)
1662 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1664 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1665 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1666 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1668 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1669 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1671 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1673 for(i
= 0; i
< count
; i
++)
1674 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1677 BeginPath(graphics
->hdc
);
1678 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1679 EndPath(graphics
->hdc
);
1680 StrokeAndFillPath(graphics
->hdc
);
1683 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1695 SelectObject(graphics
->hdc
, oldbrush
);
1696 SelectObject(graphics
->hdc
, oldpen
);
1697 DeleteObject(brush
);
1702 /* Shortens the line by the given percent by changing x2, y2.
1703 * If percent is > 1.0 then the line will change direction.
1704 * If percent is negative it can lengthen the line. */
1705 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1707 REAL dist
, theta
, dx
, dy
;
1709 if((y1
== *y2
) && (x1
== *x2
))
1712 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1713 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1714 dx
= cos(theta
) * dist
;
1715 dy
= sin(theta
) * dist
;
1721 /* Shortens the line by the given amount by changing x2, y2.
1722 * If the amount is greater than the distance, the line will become length 0.
1723 * If the amount is negative, it can lengthen the line. */
1724 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1726 REAL dx
, dy
, percent
;
1730 if(dx
== 0 && dy
== 0)
1733 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1740 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1743 /* Conducts a linear search to find the bezier points that will back off
1744 * the endpoint of the curve by a distance of amt. Linear search works
1745 * better than binary in this case because there are multiple solutions,
1746 * and binary searches often find a bad one. I don't think this is what
1747 * Windows does but short of rendering the bezier without GDI's help it's
1748 * the best we can do. If rev then work from the start of the passed points
1749 * instead of the end. */
1750 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1753 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1754 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1763 origx
= pt
[fourth
].X
;
1764 origy
= pt
[fourth
].Y
;
1765 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1767 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1768 /* reset bezier points to original values */
1769 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1770 /* Perform magic on bezier points. Order is important here.*/
1771 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1772 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1773 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1774 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1775 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1776 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1778 dx
= pt
[fourth
].X
- origx
;
1779 dy
= pt
[fourth
].Y
- origy
;
1781 diff
= sqrt(dx
* dx
+ dy
* dy
);
1782 percent
+= 0.0005 * amt
;
1786 /* Draws a combination of bezier curves and lines between points. */
1787 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1788 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1790 POINT
*pti
= heap_alloc_zero(count
* sizeof(POINT
));
1791 BYTE
*tp
= heap_alloc_zero(count
);
1792 GpPointF
*ptcopy
= heap_alloc_zero(count
* sizeof(GpPointF
));
1794 GpStatus status
= GenericError
;
1800 if(!pti
|| !tp
|| !ptcopy
){
1801 status
= OutOfMemory
;
1805 for(i
= 1; i
< count
; i
++){
1806 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1807 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1808 || !(types
[i
+ 2] & PathPointTypeBezier
)){
1809 ERR("Bad bezier points\n");
1816 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1818 /* If we are drawing caps, go through the points and adjust them accordingly,
1819 * and draw the caps. */
1821 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1822 case PathPointTypeBezier
:
1823 if(pen
->endcap
== LineCapArrowAnchor
)
1824 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1825 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1826 shorten_bezier_amt(&ptcopy
[count
- 4],
1827 pen
->width
* pen
->customend
->inset
, FALSE
);
1829 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1830 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1831 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1832 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1835 case PathPointTypeLine
:
1836 if(pen
->endcap
== LineCapArrowAnchor
)
1837 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1838 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1840 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1841 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1842 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1843 pen
->customend
->inset
* pen
->width
);
1845 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1846 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1851 ERR("Bad path last point\n");
1855 /* Find start of points */
1856 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1857 == PathPointTypeStart
); j
++);
1859 switch(types
[j
] & PathPointTypePathTypeMask
){
1860 case PathPointTypeBezier
:
1861 if(pen
->startcap
== LineCapArrowAnchor
)
1862 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1863 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1864 shorten_bezier_amt(&ptcopy
[j
- 1],
1865 pen
->width
* pen
->customstart
->inset
, TRUE
);
1867 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1868 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1869 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1870 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1873 case PathPointTypeLine
:
1874 if(pen
->startcap
== LineCapArrowAnchor
)
1875 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1876 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1878 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1879 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1880 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1881 pen
->customstart
->inset
* pen
->width
);
1883 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1884 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1889 ERR("Bad path points\n");
1894 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1896 for(i
= 0; i
< count
; i
++){
1897 tp
[i
] = convert_path_point_type(types
[i
]);
1900 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1912 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1916 BeginPath(graphics
->hdc
);
1917 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1918 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1919 EndPath(graphics
->hdc
);
1923 typedef struct _GraphicsContainerItem
{
1925 GraphicsContainer contid
;
1927 SmoothingMode smoothing
;
1928 CompositingQuality compqual
;
1929 InterpolationMode interpolation
;
1930 CompositingMode compmode
;
1931 TextRenderingHint texthint
;
1934 PixelOffsetMode pixeloffset
;
1936 GpMatrix worldtrans
;
1938 INT origin_x
, origin_y
;
1939 } GraphicsContainerItem
;
1941 static GpStatus
init_container(GraphicsContainerItem
** container
,
1942 GDIPCONST GpGraphics
* graphics
){
1945 *container
= heap_alloc_zero(sizeof(GraphicsContainerItem
));
1949 (*container
)->contid
= graphics
->contid
+ 1;
1951 (*container
)->smoothing
= graphics
->smoothing
;
1952 (*container
)->compqual
= graphics
->compqual
;
1953 (*container
)->interpolation
= graphics
->interpolation
;
1954 (*container
)->compmode
= graphics
->compmode
;
1955 (*container
)->texthint
= graphics
->texthint
;
1956 (*container
)->scale
= graphics
->scale
;
1957 (*container
)->unit
= graphics
->unit
;
1958 (*container
)->textcontrast
= graphics
->textcontrast
;
1959 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1960 (*container
)->origin_x
= graphics
->origin_x
;
1961 (*container
)->origin_y
= graphics
->origin_y
;
1962 (*container
)->worldtrans
= graphics
->worldtrans
;
1964 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1966 heap_free(*container
);
1974 static void delete_container(GraphicsContainerItem
* container
)
1976 GdipDeleteRegion(container
->clip
);
1977 heap_free(container
);
1980 static GpStatus
restore_container(GpGraphics
* graphics
,
1981 GDIPCONST GraphicsContainerItem
* container
){
1985 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1986 if(sts
!= Ok
) return sts
;
1988 graphics
->worldtrans
= container
->worldtrans
;
1990 GdipDeleteRegion(graphics
->clip
);
1991 graphics
->clip
= newClip
;
1993 graphics
->contid
= container
->contid
- 1;
1995 graphics
->smoothing
= container
->smoothing
;
1996 graphics
->compqual
= container
->compqual
;
1997 graphics
->interpolation
= container
->interpolation
;
1998 graphics
->compmode
= container
->compmode
;
1999 graphics
->texthint
= container
->texthint
;
2000 graphics
->scale
= container
->scale
;
2001 graphics
->unit
= container
->unit
;
2002 graphics
->textcontrast
= container
->textcontrast
;
2003 graphics
->pixeloffset
= container
->pixeloffset
;
2004 graphics
->origin_x
= container
->origin_x
;
2005 graphics
->origin_y
= container
->origin_y
;
2010 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2016 if(graphics
->hwnd
) {
2017 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2018 return GenericError
;
2020 rect
->X
= wnd_rect
.left
;
2021 rect
->Y
= wnd_rect
.top
;
2022 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2023 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2024 }else if (graphics
->image
){
2025 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2026 if (stat
== Ok
&& unit
!= UnitPixel
)
2027 FIXME("need to convert from unit %i\n", unit
);
2028 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2035 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2036 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2038 rect
->Width
= bmp
.bmWidth
;
2039 rect
->Height
= bmp
.bmHeight
;
2050 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2051 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2058 points
[0].x
= rect
->X
;
2059 points
[0].y
= rect
->Y
;
2060 points
[1].x
= rect
->X
+ rect
->Width
;
2061 points
[1].y
= rect
->Y
+ rect
->Height
;
2063 DPtoLP(graphics
->hdc
, points
, sizeof(points
)/sizeof(points
[0]));
2065 rect
->X
= min(points
[0].x
, points
[1].x
);
2066 rect
->Y
= min(points
[0].y
, points
[1].y
);
2067 rect
->Width
= abs(points
[1].x
- points
[0].x
);
2068 rect
->Height
= abs(points
[1].y
- points
[0].y
);
2074 /* on success, rgn will contain the region of the graphics object which
2075 * is visible after clipping has been applied */
2076 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2082 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2085 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2088 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2091 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2094 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2097 GdipDeleteRegion(tmp
);
2101 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2105 if (font
->unit
== UnitPixel
)
2107 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2111 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2112 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2114 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2117 lf
->lfHeight
= -(height
+ 0.5);
2119 lf
->lfEscapement
= 0;
2120 lf
->lfOrientation
= 0;
2121 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2122 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2123 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2124 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2125 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2126 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2127 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2128 lf
->lfQuality
= DEFAULT_QUALITY
;
2129 lf
->lfPitchAndFamily
= 0;
2130 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2133 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2134 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2135 GDIPCONST GpMatrix
*matrix
)
2137 HDC hdc
= CreateCompatibleDC(0);
2139 REAL angle
, rel_width
, rel_height
, font_height
;
2141 HFONT unscaled_font
;
2142 TEXTMETRICW textmet
;
2144 if (font
->unit
== UnitPixel
|| font
->unit
== UnitWorld
)
2145 font_height
= font
->emSize
;
2148 REAL unit_scale
, res
;
2150 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2151 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2153 font_height
= font
->emSize
* unit_scale
;
2164 GpMatrix xform
= *matrix
;
2165 GdipTransformMatrixPoints(&xform
, pt
, 3);
2168 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2169 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2170 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2171 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2172 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2173 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2175 get_log_fontW(font
, graphics
, &lfw
);
2176 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2177 unscaled_font
= CreateFontIndirectW(&lfw
);
2179 SelectObject(hdc
, unscaled_font
);
2180 GetTextMetricsW(hdc
, &textmet
);
2182 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2183 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2185 *hfont
= CreateFontIndirectW(&lfw
);
2188 DeleteObject(unscaled_font
);
2191 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2193 TRACE("(%p, %p)\n", hdc
, graphics
);
2195 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2198 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2204 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2207 FIXME("Don't know how to handle parameter hDevice\n");
2212 if(graphics
== NULL
)
2213 return InvalidParameter
;
2215 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2216 if(!*graphics
) return OutOfMemory
;
2218 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2220 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2221 heap_free(*graphics
);
2225 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2226 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2227 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2229 (*graphics
)->alpha_hdc
= 1;
2232 (*graphics
)->hdc
= hdc
;
2233 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2234 (*graphics
)->owndc
= FALSE
;
2235 (*graphics
)->smoothing
= SmoothingModeDefault
;
2236 (*graphics
)->compqual
= CompositingQualityDefault
;
2237 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2238 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2239 (*graphics
)->compmode
= CompositingModeSourceOver
;
2240 (*graphics
)->unit
= UnitDisplay
;
2241 (*graphics
)->scale
= 1.0;
2242 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2243 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2244 (*graphics
)->busy
= FALSE
;
2245 (*graphics
)->textcontrast
= 4;
2246 list_init(&(*graphics
)->containers
);
2247 (*graphics
)->contid
= GDIP_GET_NEW_CONTID_FOR(*graphics
);
2249 TRACE("<-- %p\n", *graphics
);
2254 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2258 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2259 if(!*graphics
) return OutOfMemory
;
2261 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2263 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2264 heap_free(*graphics
);
2268 (*graphics
)->hdc
= NULL
;
2269 (*graphics
)->hwnd
= NULL
;
2270 (*graphics
)->owndc
= FALSE
;
2271 (*graphics
)->image
= image
;
2272 /* We have to store the image type here because the image may be freed
2273 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2274 (*graphics
)->image_type
= image
->type
;
2275 (*graphics
)->smoothing
= SmoothingModeDefault
;
2276 (*graphics
)->compqual
= CompositingQualityDefault
;
2277 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2278 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2279 (*graphics
)->compmode
= CompositingModeSourceOver
;
2280 (*graphics
)->unit
= UnitDisplay
;
2281 (*graphics
)->scale
= 1.0;
2282 (*graphics
)->xres
= image
->xres
;
2283 (*graphics
)->yres
= image
->yres
;
2284 (*graphics
)->busy
= FALSE
;
2285 (*graphics
)->textcontrast
= 4;
2286 list_init(&(*graphics
)->containers
);
2287 (*graphics
)->contid
= GDIP_GET_NEW_CONTID_FOR(*graphics
);
2289 TRACE("<-- %p\n", *graphics
);
2294 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2299 TRACE("(%p, %p)\n", hwnd
, graphics
);
2303 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2305 ReleaseDC(hwnd
, hdc
);
2309 (*graphics
)->hwnd
= hwnd
;
2310 (*graphics
)->owndc
= TRUE
;
2315 /* FIXME: no icm handling */
2316 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2318 TRACE("(%p, %p)\n", hwnd
, graphics
);
2320 return GdipCreateFromHWND(hwnd
, graphics
);
2323 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2324 UINT access
, IStream
**stream
)
2329 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2331 if(!stream
|| !filename
)
2332 return InvalidParameter
;
2334 if(access
& GENERIC_WRITE
)
2335 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2336 else if(access
& GENERIC_READ
)
2337 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2339 return InvalidParameter
;
2341 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2343 return hresult_to_status(ret
);
2346 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2348 GraphicsContainerItem
*cont
, *next
;
2350 TRACE("(%p)\n", graphics
);
2352 if(!graphics
) return InvalidParameter
;
2353 if(graphics
->busy
) return ObjectBusy
;
2355 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2357 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2363 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2365 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2366 list_remove(&cont
->entry
);
2367 delete_container(cont
);
2370 GdipDeleteRegion(graphics
->clip
);
2372 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2373 * do otherwise, but we can't have that in the test suite because it means
2374 * accessing freed memory. */
2375 graphics
->busy
= TRUE
;
2377 heap_free(graphics
);
2382 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2383 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2388 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2389 width
, height
, startAngle
, sweepAngle
);
2391 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2392 return InvalidParameter
;
2397 status
= GdipCreatePath(FillModeAlternate
, &path
);
2398 if (status
!= Ok
) return status
;
2400 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2402 status
= GdipDrawPath(graphics
, pen
, path
);
2404 GdipDeletePath(path
);
2408 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2409 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2411 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2412 width
, height
, startAngle
, sweepAngle
);
2414 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2417 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2418 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2422 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2423 x2
, y2
, x3
, y3
, x4
, y4
);
2425 if(!graphics
|| !pen
)
2426 return InvalidParameter
;
2439 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2442 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2443 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2445 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2446 x2
, y2
, x3
, y3
, x4
, y4
);
2448 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2451 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2452 GDIPCONST GpPointF
*points
, INT count
)
2457 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2459 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2460 return InvalidParameter
;
2465 status
= GdipCreatePath(FillModeAlternate
, &path
);
2466 if (status
!= Ok
) return status
;
2468 status
= GdipAddPathBeziers(path
, points
, count
);
2470 status
= GdipDrawPath(graphics
, pen
, path
);
2472 GdipDeletePath(path
);
2476 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2477 GDIPCONST GpPoint
*points
, INT count
)
2483 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2485 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2486 return InvalidParameter
;
2491 pts
= heap_alloc_zero(sizeof(GpPointF
) * count
);
2495 for(i
= 0; i
< count
; i
++){
2496 pts
[i
].X
= (REAL
)points
[i
].X
;
2497 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2500 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2507 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2508 GDIPCONST GpPointF
*points
, INT count
)
2510 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2512 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2515 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2516 GDIPCONST GpPoint
*points
, INT count
)
2518 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2520 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2523 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2524 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2529 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2531 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2532 return InvalidParameter
;
2537 status
= GdipCreatePath(FillModeAlternate
, &path
);
2538 if (status
!= Ok
) return status
;
2540 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2542 status
= GdipDrawPath(graphics
, pen
, path
);
2544 GdipDeletePath(path
);
2549 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2550 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2556 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2558 if(!points
|| count
<= 0)
2559 return InvalidParameter
;
2561 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2565 for(i
= 0; i
< count
; i
++){
2566 ptf
[i
].X
= (REAL
)points
[i
].X
;
2567 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2570 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2577 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2578 GDIPCONST GpPointF
*points
, INT count
)
2580 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2582 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2585 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2586 GDIPCONST GpPoint
*points
, INT count
)
2592 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2595 return InvalidParameter
;
2597 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2601 for(i
= 0; i
< count
; i
++){
2602 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2603 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2606 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2612 /* Approximates cardinal spline with Bezier curves. */
2613 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2614 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2619 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2621 if(!graphics
|| !pen
)
2622 return InvalidParameter
;
2628 return InvalidParameter
;
2630 status
= GdipCreatePath(FillModeAlternate
, &path
);
2631 if (status
!= Ok
) return status
;
2633 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2635 status
= GdipDrawPath(graphics
, pen
, path
);
2637 GdipDeletePath(path
);
2641 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2642 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2648 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2651 return InvalidParameter
;
2653 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2657 for(i
= 0; i
< count
; i
++){
2658 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2659 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2662 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2668 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2669 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2672 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2674 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2675 return InvalidParameter
;
2678 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2681 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2682 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2685 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2691 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2692 return InvalidParameter
;
2695 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2698 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2699 REAL y
, REAL width
, REAL height
)
2704 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2706 if(!graphics
|| !pen
)
2707 return InvalidParameter
;
2712 status
= GdipCreatePath(FillModeAlternate
, &path
);
2713 if (status
!= Ok
) return status
;
2715 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2717 status
= GdipDrawPath(graphics
, pen
, path
);
2719 GdipDeletePath(path
);
2723 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2724 INT y
, INT width
, INT height
)
2726 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2728 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2732 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2736 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2738 if(!graphics
|| !image
)
2739 return InvalidParameter
;
2741 GdipGetImageWidth(image
, &width
);
2742 GdipGetImageHeight(image
, &height
);
2744 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2745 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2748 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2751 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2753 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2756 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2757 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2761 REAL scale_x
, scale_y
, width
, height
;
2763 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2765 if (!graphics
|| !image
) return InvalidParameter
;
2767 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2768 scale_x
*= graphics
->xres
/ image
->xres
;
2769 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2770 scale_y
*= graphics
->yres
/ image
->yres
;
2771 width
= srcwidth
* scale_x
;
2772 height
= srcheight
* scale_y
;
2774 points
[0].X
= points
[2].X
= x
;
2775 points
[0].Y
= points
[1].Y
= y
;
2776 points
[1].X
= x
+ width
;
2777 points
[2].Y
= y
+ height
;
2779 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2780 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2783 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2784 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2787 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2790 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2791 GDIPCONST GpPointF
*dstpoints
, INT count
)
2795 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2798 return InvalidParameter
;
2800 GdipGetImageWidth(image
, &width
);
2801 GdipGetImageHeight(image
, &height
);
2803 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2804 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2807 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2808 GDIPCONST GpPoint
*dstpoints
, INT count
)
2812 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2814 if (count
!= 3 || !dstpoints
)
2815 return InvalidParameter
;
2817 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2818 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2819 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2820 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2821 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2822 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2824 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2827 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2828 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2830 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2834 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2835 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2836 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2837 DrawImageAbort callback
, VOID
* callbackData
)
2843 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2844 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2848 return NotImplemented
;
2850 if(!graphics
|| !image
|| !points
|| count
!= 3)
2851 return InvalidParameter
;
2853 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2854 debugstr_pointf(&points
[2]));
2856 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2858 /* Ensure source width/height is positive */
2861 GpPointF tmp
= ptf
[1];
2862 srcx
= srcx
+ srcwidth
;
2863 srcwidth
= -srcwidth
;
2864 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2865 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2872 GpPointF tmp
= ptf
[2];
2873 srcy
= srcy
+ srcheight
;
2874 srcheight
= -srcheight
;
2875 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
2876 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
2881 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2882 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2883 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
2885 transform_and_round_points(graphics
, pti
, ptf
, 4);
2887 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2888 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2890 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2891 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2892 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2893 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2894 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2896 if (image
->type
== ImageTypeBitmap
)
2898 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2899 BOOL do_resampling
= FALSE
;
2900 BOOL use_software
= FALSE
;
2902 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2903 graphics
->xres
, graphics
->yres
,
2904 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2905 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2906 imageAttributes
? imageAttributes
->outside_color
: 0);
2908 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2909 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2910 srcx
< 0 || srcy
< 0 ||
2911 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2912 do_resampling
= TRUE
;
2914 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
2915 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
2916 use_software
= TRUE
;
2921 GpRectF graphics_bounds
;
2923 int i
, x
, y
, src_stride
, dst_stride
;
2924 GpMatrix dst_to_src
;
2925 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2926 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
2927 BitmapData lockeddata
;
2928 InterpolationMode interpolation
= graphics
->interpolation
;
2929 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2930 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2931 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2932 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2934 if (!imageAttributes
)
2935 imageAttributes
= &defaultImageAttributes
;
2937 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2938 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2941 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2942 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2943 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2944 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2947 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
2948 if (stat
!= Ok
) return stat
;
2950 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
2951 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
2952 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
2953 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
2955 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
2957 if (IsRectEmpty(&dst_area
)) return Ok
;
2959 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2960 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2961 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2962 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2963 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2964 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2966 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
2968 stat
= GdipInvertMatrix(&dst_to_src
);
2969 if (stat
!= Ok
) return stat
;
2973 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2974 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2978 /* Make sure src_area is equal in size to dst_area. */
2979 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
2980 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
2981 src_area
.Width
= dst_area
.right
- dst_area
.left
;
2982 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
2985 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
2987 src_data
= heap_alloc_zero(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
2990 src_stride
= sizeof(ARGB
) * src_area
.Width
;
2992 /* Read the bits we need from the source bitmap into a compatible buffer. */
2993 lockeddata
.Width
= src_area
.Width
;
2994 lockeddata
.Height
= src_area
.Height
;
2995 lockeddata
.Stride
= src_stride
;
2996 lockeddata
.Scan0
= src_data
;
2997 if (!do_resampling
&& bitmap
->format
== PixelFormat32bppPARGB
)
2998 lockeddata
.PixelFormat
= apply_image_attributes(imageAttributes
, NULL
, 0, 0, 0, ColorAdjustTypeBitmap
, bitmap
->format
);
3000 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3002 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3003 lockeddata
.PixelFormat
, &lockeddata
);
3006 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3010 heap_free(src_data
);
3014 apply_image_attributes(imageAttributes
, src_data
,
3015 src_area
.Width
, src_area
.Height
,
3016 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
3020 /* Transform the bits as needed to the destination. */
3021 dst_data
= dst_dyn_data
= heap_alloc_zero(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3024 heap_free(src_data
);
3028 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3030 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3032 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3033 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3034 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3035 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3037 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3039 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3041 GpPointF src_pointf
;
3044 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3045 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3047 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3049 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3050 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3051 imageAttributes
, interpolation
, offset_mode
);
3059 dst_data
= src_data
;
3060 dst_stride
= src_stride
;
3063 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3064 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
,
3065 lockeddata
.PixelFormat
);
3067 heap_free(src_data
);
3069 heap_free(dst_dyn_data
);
3076 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3077 HBITMAP hbitmap
, old_hbm
=NULL
;
3079 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3080 bitmap
->format
== PixelFormat24bppRGB
||
3081 bitmap
->format
== PixelFormat32bppRGB
||
3082 bitmap
->format
== PixelFormat32bppPARGB
))
3084 BITMAPINFOHEADER bih
;
3086 PixelFormat dst_format
;
3088 /* we can't draw a bitmap of this format directly */
3089 hdc
= CreateCompatibleDC(0);
3093 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3094 bih
.biWidth
= bitmap
->width
;
3095 bih
.biHeight
= -bitmap
->height
;
3097 bih
.biBitCount
= 32;
3098 bih
.biCompression
= BI_RGB
;
3099 bih
.biSizeImage
= 0;
3100 bih
.biXPelsPerMeter
= 0;
3101 bih
.biYPelsPerMeter
= 0;
3103 bih
.biClrImportant
= 0;
3105 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3106 (void**)&temp_bits
, NULL
, 0);
3108 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3109 dst_format
= PixelFormat32bppPARGB
;
3111 dst_format
= PixelFormat32bppRGB
;
3113 convert_pixels(bitmap
->width
, bitmap
->height
,
3114 bitmap
->width
*4, temp_bits
, dst_format
,
3115 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3116 bitmap
->image
.palette
);
3120 if (bitmap
->hbitmap
)
3121 hbitmap
= bitmap
->hbitmap
;
3124 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3129 temp_hdc
= (hdc
== 0);
3134 if (!hdc
) hdc
= CreateCompatibleDC(0);
3135 old_hbm
= SelectObject(hdc
, hbitmap
);
3138 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3140 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3141 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3145 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3146 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3151 SelectObject(hdc
, old_hbm
);
3156 DeleteObject(hbitmap
);
3159 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3165 rc
.Width
= srcwidth
;
3166 rc
.Height
= srcheight
;
3168 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3169 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3173 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3174 return InvalidParameter
;
3180 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3181 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3182 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3183 DrawImageAbort callback
, VOID
* callbackData
)
3185 GpPointF pointsF
[3];
3188 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3189 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3192 if(!points
|| count
!=3)
3193 return InvalidParameter
;
3195 for(i
= 0; i
< count
; i
++){
3196 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3197 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3200 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3201 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3202 callback
, callbackData
);
3205 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3206 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3207 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3208 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3209 VOID
* callbackData
)
3213 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3214 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3215 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3219 points
[1].X
= dstx
+ dstwidth
;
3222 points
[2].Y
= dsty
+ dstheight
;
3224 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3225 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3228 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3229 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3230 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3231 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3232 VOID
* callbackData
)
3236 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3237 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3238 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3242 points
[1].X
= dstx
+ dstwidth
;
3245 points
[2].Y
= dsty
+ dstheight
;
3247 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3248 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3251 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3252 REAL x
, REAL y
, REAL width
, REAL height
)
3258 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3260 if(!graphics
|| !image
)
3261 return InvalidParameter
;
3263 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3267 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3268 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3269 unit
, NULL
, NULL
, NULL
);
3272 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3273 INT x
, INT y
, INT width
, INT height
)
3275 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3277 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3280 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3281 REAL y1
, REAL x2
, REAL y2
)
3285 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3291 return GdipDrawLines(graphics
, pen
, pt
, 2);
3294 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3295 INT y1
, INT x2
, INT y2
)
3297 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3299 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3302 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3303 GpPointF
*points
, INT count
)
3308 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3310 if(!pen
|| !graphics
|| (count
< 2))
3311 return InvalidParameter
;
3316 status
= GdipCreatePath(FillModeAlternate
, &path
);
3317 if (status
!= Ok
) return status
;
3319 status
= GdipAddPathLine2(path
, points
, count
);
3321 status
= GdipDrawPath(graphics
, pen
, path
);
3323 GdipDeletePath(path
);
3327 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3328 GpPoint
*points
, INT count
)
3334 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3336 ptf
= heap_alloc_zero(count
* sizeof(GpPointF
));
3337 if(!ptf
) return OutOfMemory
;
3339 for(i
= 0; i
< count
; i
++){
3340 ptf
[i
].X
= (REAL
) points
[i
].X
;
3341 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3344 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3350 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3356 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3358 if(!pen
|| !graphics
)
3359 return InvalidParameter
;
3366 FIXME("graphics object has no HDC\n");
3370 save_state
= prepare_dc(graphics
, pen
);
3372 retval
= get_clip_hrgn(graphics
, &hrgn
);
3378 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3380 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3381 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3384 restore_dc(graphics
, save_state
);
3390 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3391 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3396 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3397 width
, height
, startAngle
, sweepAngle
);
3399 if(!graphics
|| !pen
)
3400 return InvalidParameter
;
3405 status
= GdipCreatePath(FillModeAlternate
, &path
);
3406 if (status
!= Ok
) return status
;
3408 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3410 status
= GdipDrawPath(graphics
, pen
, path
);
3412 GdipDeletePath(path
);
3416 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3417 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3419 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3420 width
, height
, startAngle
, sweepAngle
);
3422 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3425 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3426 REAL y
, REAL width
, REAL height
)
3431 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3433 if(!pen
|| !graphics
)
3434 return InvalidParameter
;
3439 status
= GdipCreatePath(FillModeAlternate
, &path
);
3440 if (status
!= Ok
) return status
;
3442 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3444 status
= GdipDrawPath(graphics
, pen
, path
);
3446 GdipDeletePath(path
);
3450 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3451 INT y
, INT width
, INT height
)
3453 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3455 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3458 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3459 GDIPCONST GpRectF
* rects
, INT count
)
3464 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3466 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3467 return InvalidParameter
;
3472 status
= GdipCreatePath(FillModeAlternate
, &path
);
3473 if (status
!= Ok
) return status
;
3475 status
= GdipAddPathRectangles(path
, rects
, count
);
3477 status
= GdipDrawPath(graphics
, pen
, path
);
3479 GdipDeletePath(path
);
3483 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3484 GDIPCONST GpRect
* rects
, INT count
)
3490 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3492 if(!rects
|| count
<=0)
3493 return InvalidParameter
;
3495 rectsF
= heap_alloc_zero(sizeof(GpRectF
) * count
);
3499 for(i
= 0;i
< count
;i
++){
3500 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3501 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3502 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3503 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3506 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3512 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3513 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3518 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3519 count
, tension
, fill
);
3521 if(!graphics
|| !brush
|| !points
)
3522 return InvalidParameter
;
3527 if(count
== 1) /* Do nothing */
3530 status
= GdipCreatePath(fill
, &path
);
3531 if (status
!= Ok
) return status
;
3533 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3535 status
= GdipFillPath(graphics
, brush
, path
);
3537 GdipDeletePath(path
);
3541 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3542 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3548 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3549 count
, tension
, fill
);
3551 if(!points
|| count
== 0)
3552 return InvalidParameter
;
3554 if(count
== 1) /* Do nothing */
3557 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
3561 for(i
= 0;i
< count
;i
++){
3562 ptf
[i
].X
= (REAL
)points
[i
].X
;
3563 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3566 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3573 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3574 GDIPCONST GpPointF
*points
, INT count
)
3576 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3577 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3578 0.5f
, FillModeAlternate
);
3581 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3582 GDIPCONST GpPoint
*points
, INT count
)
3584 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3585 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3586 0.5f
, FillModeAlternate
);
3589 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3590 REAL y
, REAL width
, REAL height
)
3595 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3597 if(!graphics
|| !brush
)
3598 return InvalidParameter
;
3603 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3607 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3610 stat
= GdipFillPath(graphics
, brush
, path
);
3612 GdipDeletePath(path
);
3618 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3619 INT y
, INT width
, INT height
)
3621 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3623 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3626 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3632 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3633 return NotImplemented
;
3635 save_state
= SaveDC(graphics
->hdc
);
3636 EndPath(graphics
->hdc
);
3637 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3640 retval
= get_clip_hrgn(graphics
, &hrgn
);
3646 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3648 BeginPath(graphics
->hdc
);
3649 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3650 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3655 EndPath(graphics
->hdc
);
3656 brush_fill_path(graphics
, brush
);
3661 RestoreDC(graphics
->hdc
, save_state
);
3667 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3672 if (!brush_can_fill_pixels(brush
))
3673 return NotImplemented
;
3675 /* FIXME: This could probably be done more efficiently without regions. */
3677 stat
= GdipCreateRegionPath(path
, &rgn
);
3681 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3683 GdipDeleteRegion(rgn
);
3689 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3691 GpStatus stat
= NotImplemented
;
3693 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3695 if(!brush
|| !graphics
|| !path
)
3696 return InvalidParameter
;
3701 if (!graphics
->image
&& !graphics
->alpha_hdc
)
3702 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3704 if (stat
== NotImplemented
)
3705 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3707 if (stat
== NotImplemented
)
3709 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3716 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3717 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3722 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3723 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3725 if(!graphics
|| !brush
)
3726 return InvalidParameter
;
3731 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3735 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3738 stat
= GdipFillPath(graphics
, brush
, path
);
3740 GdipDeletePath(path
);
3746 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3747 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3749 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3750 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3752 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3755 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3756 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3761 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3763 if(!graphics
|| !brush
|| !points
|| !count
)
3764 return InvalidParameter
;
3769 stat
= GdipCreatePath(fillMode
, &path
);
3773 stat
= GdipAddPathPolygon(path
, points
, count
);
3776 stat
= GdipFillPath(graphics
, brush
, path
);
3778 GdipDeletePath(path
);
3784 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3785 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3790 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3792 if(!graphics
|| !brush
|| !points
|| !count
)
3793 return InvalidParameter
;
3798 stat
= GdipCreatePath(fillMode
, &path
);
3802 stat
= GdipAddPathPolygonI(path
, points
, count
);
3805 stat
= GdipFillPath(graphics
, brush
, path
);
3807 GdipDeletePath(path
);
3813 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3814 GDIPCONST GpPointF
*points
, INT count
)
3816 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3818 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3821 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3822 GDIPCONST GpPoint
*points
, INT count
)
3824 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3826 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3829 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3830 REAL x
, REAL y
, REAL width
, REAL height
)
3834 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3839 rect
.Height
= height
;
3841 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
3844 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3845 INT x
, INT y
, INT width
, INT height
)
3849 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3853 rect
.Width
= (REAL
)width
;
3854 rect
.Height
= (REAL
)height
;
3856 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
3859 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3865 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3867 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
3868 return InvalidParameter
;
3870 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
3872 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
3873 /* FIXME: Add gdi32 drawing. */
3877 status
= GdipCreatePath(FillModeAlternate
, &path
);
3878 if (status
!= Ok
) return status
;
3880 status
= GdipAddPathRectangles(path
, rects
, count
);
3882 status
= GdipFillPath(graphics
, brush
, path
);
3884 GdipDeletePath(path
);
3888 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3895 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3897 if(!rects
|| count
<= 0)
3898 return InvalidParameter
;
3900 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
3904 for(i
= 0; i
< count
; i
++){
3905 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3906 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3907 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3908 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3911 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3917 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3925 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3926 return NotImplemented
;
3928 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3932 save_state
= SaveDC(graphics
->hdc
);
3933 EndPath(graphics
->hdc
);
3935 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3937 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3939 BeginPath(graphics
->hdc
);
3940 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3941 EndPath(graphics
->hdc
);
3943 brush_fill_path(graphics
, brush
);
3946 RestoreDC(graphics
->hdc
, save_state
);
3953 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3957 GpRegion
*temp_region
;
3958 GpMatrix world_to_device
;
3959 GpRectF graphics_bounds
;
3963 GpRect gp_bound_rect
;
3965 if (!brush_can_fill_pixels(brush
))
3966 return NotImplemented
;
3968 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3971 stat
= GdipCloneRegion(region
, &temp_region
);
3975 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3976 CoordinateSpaceWorld
, &world_to_device
);
3979 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
3982 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
3985 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
3987 GdipDeleteRegion(temp_region
);
3990 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
3992 DeleteObject(hregion
);
3998 gp_bound_rect
.X
= bound_rect
.left
;
3999 gp_bound_rect
.Y
= bound_rect
.top
;
4000 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4001 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4003 pixel_data
= heap_alloc_zero(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4009 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4010 &gp_bound_rect
, gp_bound_rect
.Width
);
4013 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4014 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4015 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
,
4016 PixelFormat32bppARGB
);
4018 heap_free(pixel_data
);
4021 DeleteObject(hregion
);
4027 /*****************************************************************************
4028 * GdipFillRegion [GDIPLUS.@]
4030 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4033 GpStatus stat
= NotImplemented
;
4035 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4037 if (!(graphics
&& brush
&& region
))
4038 return InvalidParameter
;
4043 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4044 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4046 if (stat
== NotImplemented
)
4047 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4049 if (stat
== NotImplemented
)
4051 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4058 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4060 TRACE("(%p,%u)\n", graphics
, intention
);
4063 return InvalidParameter
;
4068 /* We have no internal operation queue, so there's no need to clear it. */
4076 /*****************************************************************************
4077 * GdipGetClipBounds [GDIPLUS.@]
4079 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4084 TRACE("(%p, %p)\n", graphics
, rect
);
4087 return InvalidParameter
;
4092 status
= GdipCreateRegion(&clip
);
4093 if (status
!= Ok
) return status
;
4095 status
= GdipGetClip(graphics
, clip
);
4097 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4099 GdipDeleteRegion(clip
);
4103 /*****************************************************************************
4104 * GdipGetClipBoundsI [GDIPLUS.@]
4106 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4108 TRACE("(%p, %p)\n", graphics
, rect
);
4111 return InvalidParameter
;
4116 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4119 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4120 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4121 CompositingMode
*mode
)
4123 TRACE("(%p, %p)\n", graphics
, mode
);
4125 if(!graphics
|| !mode
)
4126 return InvalidParameter
;
4131 *mode
= graphics
->compmode
;
4136 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4137 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4138 CompositingQuality
*quality
)
4140 TRACE("(%p, %p)\n", graphics
, quality
);
4142 if(!graphics
|| !quality
)
4143 return InvalidParameter
;
4148 *quality
= graphics
->compqual
;
4153 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4154 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4155 InterpolationMode
*mode
)
4157 TRACE("(%p, %p)\n", graphics
, mode
);
4159 if(!graphics
|| !mode
)
4160 return InvalidParameter
;
4165 *mode
= graphics
->interpolation
;
4170 /* FIXME: Need to handle color depths less than 24bpp */
4171 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4173 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4175 if(!graphics
|| !argb
)
4176 return InvalidParameter
;
4184 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4186 TRACE("(%p, %p)\n", graphics
, scale
);
4188 if(!graphics
|| !scale
)
4189 return InvalidParameter
;
4194 *scale
= graphics
->scale
;
4199 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4201 TRACE("(%p, %p)\n", graphics
, unit
);
4203 if(!graphics
|| !unit
)
4204 return InvalidParameter
;
4209 *unit
= graphics
->unit
;
4214 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4215 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4218 TRACE("(%p, %p)\n", graphics
, mode
);
4220 if(!graphics
|| !mode
)
4221 return InvalidParameter
;
4226 *mode
= graphics
->pixeloffset
;
4231 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4232 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4234 TRACE("(%p, %p)\n", graphics
, mode
);
4236 if(!graphics
|| !mode
)
4237 return InvalidParameter
;
4242 *mode
= graphics
->smoothing
;
4247 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4249 TRACE("(%p, %p)\n", graphics
, contrast
);
4251 if(!graphics
|| !contrast
)
4252 return InvalidParameter
;
4254 *contrast
= graphics
->textcontrast
;
4259 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4260 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4261 TextRenderingHint
*hint
)
4263 TRACE("(%p, %p)\n", graphics
, hint
);
4265 if(!graphics
|| !hint
)
4266 return InvalidParameter
;
4271 *hint
= graphics
->texthint
;
4276 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4281 TRACE("(%p, %p)\n", graphics
, rect
);
4283 if(!graphics
|| !rect
)
4284 return InvalidParameter
;
4289 /* intersect window and graphics clipping regions */
4290 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4293 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4296 /* get bounds of the region */
4297 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4300 GdipDeleteRegion(clip_rgn
);
4305 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4310 TRACE("(%p, %p)\n", graphics
, rect
);
4312 if(!graphics
|| !rect
)
4313 return InvalidParameter
;
4315 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4317 rect
->X
= gdip_round(rectf
.X
);
4318 rect
->Y
= gdip_round(rectf
.Y
);
4319 rect
->Width
= gdip_round(rectf
.Width
);
4320 rect
->Height
= gdip_round(rectf
.Height
);
4326 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4328 TRACE("(%p, %p)\n", graphics
, matrix
);
4330 if(!graphics
|| !matrix
)
4331 return InvalidParameter
;
4336 *matrix
= graphics
->worldtrans
;
4340 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4346 TRACE("(%p, %x)\n", graphics
, color
);
4349 return InvalidParameter
;
4354 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4357 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4358 GdipDeleteBrush((GpBrush
*)brush
);
4362 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4363 wnd_rect
.Width
, wnd_rect
.Height
);
4365 GdipDeleteBrush((GpBrush
*)brush
);
4370 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4372 TRACE("(%p, %p)\n", graphics
, res
);
4374 if(!graphics
|| !res
)
4375 return InvalidParameter
;
4377 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4380 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4386 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4388 if(!graphics
|| !result
)
4389 return InvalidParameter
;
4396 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4397 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4400 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4403 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4406 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4409 GdipDeleteRegion(rgn
);
4413 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4415 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4418 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4424 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4426 if(!graphics
|| !result
)
4427 return InvalidParameter
;
4434 pts
[1].X
= x
+ width
;
4435 pts
[1].Y
= y
+ height
;
4437 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4438 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4441 pts
[1].X
-= pts
[0].X
;
4442 pts
[1].Y
-= pts
[0].Y
;
4444 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4447 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4450 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4453 GdipDeleteRegion(rgn
);
4457 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4459 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4462 GpStatus
gdip_format_string(HDC hdc
,
4463 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4464 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4465 gdip_format_string_callback callback
, void *user_data
)
4468 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4469 nheight
, lineend
, lineno
= 0;
4471 StringAlignment halign
;
4474 HotkeyPrefix hkprefix
;
4475 INT
*hotkeyprefix_offsets
=NULL
;
4476 INT hotkeyprefix_count
=0;
4477 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4478 BOOL seen_prefix
= FALSE
;
4479 GpStringFormat
*dyn_format
=NULL
;
4481 if(length
== -1) length
= lstrlenW(string
);
4483 stringdup
= heap_alloc_zero((length
+ 1) * sizeof(WCHAR
));
4484 if(!stringdup
) return OutOfMemory
;
4488 stat
= GdipStringFormatGetGenericDefault(&dyn_format
);
4491 heap_free(stringdup
);
4494 format
= dyn_format
;
4497 nwidth
= rect
->Width
;
4498 nheight
= rect
->Height
;
4499 if (ignore_empty_clip
)
4501 if (!nwidth
) nwidth
= INT_MAX
;
4502 if (!nheight
) nheight
= INT_MAX
;
4505 hkprefix
= format
->hkprefix
;
4507 if (hkprefix
== HotkeyPrefixShow
)
4509 for (i
=0; i
<length
; i
++)
4511 if (string
[i
] == '&')
4512 hotkeyprefix_count
++;
4516 if (hotkeyprefix_count
)
4517 hotkeyprefix_offsets
= heap_alloc_zero(sizeof(INT
) * hotkeyprefix_count
);
4519 hotkeyprefix_count
= 0;
4521 for(i
= 0, j
= 0; i
< length
; i
++){
4522 /* FIXME: This makes the indexes passed to callback inaccurate. */
4523 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4526 /* FIXME: tabs should be handled using tabstops from stringformat */
4527 if (string
[i
] == '\t')
4530 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4531 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4532 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4538 seen_prefix
= FALSE
;
4540 stringdup
[j
] = string
[i
];
4546 halign
= format
->align
;
4548 while(sum
< length
){
4549 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4550 nwidth
, &fit
, NULL
, &size
);
4556 for(lret
= 0; lret
< fit
; lret
++)
4557 if(*(stringdup
+ sum
+ lret
) == '\n')
4560 /* Line break code (may look strange, but it imitates windows). */
4562 lineend
= fit
= lret
; /* this is not an off-by-one error */
4563 else if(fit
< (length
- sum
)){
4564 if(*(stringdup
+ sum
+ fit
) == ' ')
4565 while(*(stringdup
+ sum
+ fit
) == ' ')
4568 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4571 if(*(stringdup
+ sum
+ fit
) == '\t')
4580 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4581 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4587 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4588 nwidth
, &j
, NULL
, &size
);
4590 bounds
.Width
= size
.cx
;
4592 if(height
+ size
.cy
> nheight
)
4594 if (format
->attr
& StringFormatFlagsLineLimit
)
4596 bounds
.Height
= nheight
- (height
+ size
.cy
);
4599 bounds
.Height
= size
.cy
;
4601 bounds
.Y
= rect
->Y
+ height
;
4605 case StringAlignmentNear
:
4609 case StringAlignmentCenter
:
4610 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4612 case StringAlignmentFar
:
4613 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4617 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4618 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4621 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4622 font
, rect
, format
, lineno
, &bounds
,
4623 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4624 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4629 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4633 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4635 if(height
> nheight
)
4638 /* Stop if this was a linewrap (but not if it was a linebreak). */
4639 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
4643 heap_free(stringdup
);
4644 heap_free(hotkeyprefix_offsets
);
4645 GdipDeleteStringFormat(dyn_format
);
4650 struct measure_ranges_args
{
4652 REAL rel_width
, rel_height
;
4655 static GpStatus
measure_ranges_callback(HDC hdc
,
4656 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4657 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4658 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4659 INT underlined_index_count
, void *user_data
)
4663 struct measure_ranges_args
*args
= user_data
;
4665 for (i
=0; i
<format
->range_count
; i
++)
4667 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4668 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4669 if (range_start
< range_end
)
4674 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4675 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4677 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4678 INT_MAX
, NULL
, NULL
, &range_size
);
4679 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4681 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4682 INT_MAX
, NULL
, NULL
, &range_size
);
4683 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4685 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4694 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4695 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4696 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4697 INT regionCount
, GpRegion
** regions
)
4701 HFONT gdifont
, oldfont
;
4702 struct measure_ranges_args args
;
4703 HDC hdc
, temp_hdc
=NULL
;
4708 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4709 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4711 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4712 return InvalidParameter
;
4714 if (regionCount
< stringFormat
->range_count
)
4715 return InvalidParameter
;
4719 hdc
= temp_hdc
= CreateCompatibleDC(0);
4720 if (!temp_hdc
) return OutOfMemory
;
4723 hdc
= graphics
->hdc
;
4725 if (stringFormat
->attr
)
4726 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4734 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4735 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4736 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4737 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4738 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4740 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4741 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4743 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4744 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4745 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
4746 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
4748 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4749 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4751 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
4752 oldfont
= SelectObject(hdc
, gdifont
);
4754 for (i
=0; i
<stringFormat
->range_count
; i
++)
4756 stat
= GdipSetEmpty(regions
[i
]);
4761 args
.regions
= regions
;
4763 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
4764 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
4766 SelectObject(hdc
, oldfont
);
4767 DeleteObject(gdifont
);
4775 struct measure_string_args
{
4777 INT
*codepointsfitted
;
4779 REAL rel_width
, rel_height
;
4782 static GpStatus
measure_string_callback(HDC hdc
,
4783 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4784 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4785 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4786 INT underlined_index_count
, void *user_data
)
4788 struct measure_string_args
*args
= user_data
;
4789 REAL new_width
, new_height
;
4791 new_width
= bounds
->Width
/ args
->rel_width
;
4792 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
4794 if (new_width
> args
->bounds
->Width
)
4795 args
->bounds
->Width
= new_width
;
4797 if (new_height
> args
->bounds
->Height
)
4798 args
->bounds
->Height
= new_height
;
4800 if (args
->codepointsfitted
)
4801 *args
->codepointsfitted
= index
+ length
;
4803 if (args
->linesfilled
)
4804 (*args
->linesfilled
)++;
4809 /* Find the smallest rectangle that bounds the text when it is printed in rect
4810 * according to the format options listed in format. If rect has 0 width and
4811 * height, then just find the smallest rectangle that bounds the text when it's
4812 * printed at location (rect->X, rect-Y). */
4813 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4814 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4815 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4816 INT
*codepointsfitted
, INT
*linesfilled
)
4818 HFONT oldfont
, gdifont
;
4819 struct measure_string_args args
;
4820 HDC temp_hdc
=NULL
, hdc
;
4826 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4827 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4828 bounds
, codepointsfitted
, linesfilled
);
4830 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4831 return InvalidParameter
;
4835 hdc
= temp_hdc
= CreateCompatibleDC(0);
4836 if (!temp_hdc
) return OutOfMemory
;
4839 hdc
= graphics
->hdc
;
4841 if(linesfilled
) *linesfilled
= 0;
4842 if(codepointsfitted
) *codepointsfitted
= 0;
4845 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4853 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4854 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4855 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4856 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4857 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4859 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4860 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4862 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
4863 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
4864 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
4865 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
4866 if (scaled_rect
.Width
>= 0.5)
4868 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4869 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4872 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4873 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4875 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
4876 oldfont
= SelectObject(hdc
, gdifont
);
4878 bounds
->X
= rect
->X
;
4879 bounds
->Y
= rect
->Y
;
4880 bounds
->Width
= 0.0;
4881 bounds
->Height
= 0.0;
4883 args
.bounds
= bounds
;
4884 args
.codepointsfitted
= &glyphs
;
4885 args
.linesfilled
= &lines
;
4888 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
4889 measure_string_callback
, &args
);
4891 if (linesfilled
) *linesfilled
= lines
;
4892 if (codepointsfitted
) *codepointsfitted
= glyphs
;
4895 bounds
->Width
+= margin_x
* 2.0;
4897 SelectObject(hdc
, oldfont
);
4898 DeleteObject(gdifont
);
4906 struct draw_string_args
{
4907 GpGraphics
*graphics
;
4908 GDIPCONST GpBrush
*brush
;
4909 REAL x
, y
, rel_width
, rel_height
, ascent
;
4912 static GpStatus
draw_string_callback(HDC hdc
,
4913 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4914 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4915 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4916 INT underlined_index_count
, void *user_data
)
4918 struct draw_string_args
*args
= user_data
;
4922 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4923 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4925 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
4926 args
->brush
, &position
,
4927 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4929 if (stat
== Ok
&& underlined_index_count
)
4931 OUTLINETEXTMETRICW otm
;
4932 REAL underline_y
, underline_height
;
4935 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
4937 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
4938 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
4940 for (i
=0; i
<underlined_index_count
; i
++)
4942 REAL start_x
, end_x
;
4944 INT ofs
= underlined_indexes
[i
] - index
;
4946 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
4947 start_x
= text_size
.cx
/ args
->rel_width
;
4949 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
4950 end_x
= text_size
.cx
/ args
->rel_width
;
4952 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
4959 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4960 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4961 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4965 GpPointF pt
[3], rectcpy
[4];
4967 REAL rel_width
, rel_height
, margin_x
;
4968 INT save_state
, format_flags
= 0;
4970 struct draw_string_args args
;
4972 HDC hdc
, temp_hdc
=NULL
;
4973 TEXTMETRICW textmetric
;
4975 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4976 length
, font
, debugstr_rectf(rect
), format
, brush
);
4978 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4979 return InvalidParameter
;
4983 hdc
= graphics
->hdc
;
4987 hdc
= temp_hdc
= CreateCompatibleDC(0);
4991 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4993 format_flags
= format
->attr
;
4995 /* Should be no need to explicitly test for StringAlignmentNear as
4996 * that is default behavior if no alignment is passed. */
4997 if(format
->vertalign
!= StringAlignmentNear
){
4998 RectF bounds
, in_rect
= *rect
;
4999 in_rect
.Height
= 0.0; /* avoid height clipping */
5000 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5002 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5004 if(format
->vertalign
== StringAlignmentCenter
)
5005 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5006 else if(format
->vertalign
== StringAlignmentFar
)
5007 offsety
= (rect
->Height
- bounds
.Height
);
5009 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
5012 save_state
= SaveDC(hdc
);
5020 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5021 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5022 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5023 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5024 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5026 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5027 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5028 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5029 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5030 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5032 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5033 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5035 scaled_rect
.X
= margin_x
* rel_width
;
5036 scaled_rect
.Y
= 0.0;
5037 scaled_rect
.Width
= rel_width
* rect
->Width
;
5038 scaled_rect
.Height
= rel_height
* rect
->Height
;
5039 if (scaled_rect
.Width
>= 0.5)
5041 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5042 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5045 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5046 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5048 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5049 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5050 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5052 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5053 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5054 SelectClipRgn(hdc
, rgn
);
5057 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5058 SelectObject(hdc
, gdifont
);
5060 args
.graphics
= graphics
;
5064 args
.y
= rect
->Y
+ offsety
;
5066 args
.rel_width
= rel_width
;
5067 args
.rel_height
= rel_height
;
5069 GetTextMetricsW(hdc
, &textmetric
);
5070 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5072 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5073 draw_string_callback
, &args
);
5076 DeleteObject(gdifont
);
5078 RestoreDC(hdc
, save_state
);
5085 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5087 TRACE("(%p)\n", graphics
);
5090 return InvalidParameter
;
5095 return GdipSetInfinite(graphics
->clip
);
5098 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5100 TRACE("(%p)\n", graphics
);
5103 return InvalidParameter
;
5108 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5111 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5113 return GdipEndContainer(graphics
, state
);
5116 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5117 GpMatrixOrder order
)
5119 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5122 return InvalidParameter
;
5127 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5130 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5132 return GdipBeginContainer2(graphics
, state
);
5135 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5136 GraphicsContainer
*state
)
5138 GraphicsContainerItem
*container
;
5141 TRACE("(%p, %p)\n", graphics
, state
);
5143 if(!graphics
|| !state
)
5144 return InvalidParameter
;
5146 sts
= init_container(&container
, graphics
);
5150 list_add_head(&graphics
->containers
, &container
->entry
);
5151 *state
= graphics
->contid
= container
->contid
;
5156 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5158 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5159 return NotImplemented
;
5162 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5164 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5165 return NotImplemented
;
5168 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5170 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5171 return NotImplemented
;
5174 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5177 GraphicsContainerItem
*container
, *container2
;
5179 TRACE("(%p, %x)\n", graphics
, state
);
5182 return InvalidParameter
;
5184 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5185 if(container
->contid
== state
)
5189 /* did not find a matching container */
5190 if(&container
->entry
== &graphics
->containers
)
5193 sts
= restore_container(graphics
, container
);
5197 /* remove all of the containers on top of the found container */
5198 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5199 if(container
->contid
== state
)
5201 list_remove(&container
->entry
);
5202 delete_container(container
);
5205 list_remove(&container
->entry
);
5206 delete_container(container
);
5211 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5212 REAL sy
, GpMatrixOrder order
)
5214 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5217 return InvalidParameter
;
5222 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5225 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5228 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5230 if(!graphics
|| !srcgraphics
)
5231 return InvalidParameter
;
5233 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5236 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5237 CompositingMode mode
)
5239 TRACE("(%p, %d)\n", graphics
, mode
);
5242 return InvalidParameter
;
5247 graphics
->compmode
= mode
;
5252 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5253 CompositingQuality quality
)
5255 TRACE("(%p, %d)\n", graphics
, quality
);
5258 return InvalidParameter
;
5263 graphics
->compqual
= quality
;
5268 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5269 InterpolationMode mode
)
5271 TRACE("(%p, %d)\n", graphics
, mode
);
5273 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5274 return InvalidParameter
;
5279 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5280 mode
= InterpolationModeBilinear
;
5282 if (mode
== InterpolationModeHighQuality
)
5283 mode
= InterpolationModeHighQualityBicubic
;
5285 graphics
->interpolation
= mode
;
5290 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5294 TRACE("(%p, %.2f)\n", graphics
, scale
);
5296 if(!graphics
|| (scale
<= 0.0))
5297 return InvalidParameter
;
5302 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5304 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
5309 graphics
->scale
= scale
;
5314 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5318 TRACE("(%p, %d)\n", graphics
, unit
);
5321 return InvalidParameter
;
5326 if(unit
== UnitWorld
)
5327 return InvalidParameter
;
5329 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5331 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
5336 graphics
->unit
= unit
;
5341 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5344 TRACE("(%p, %d)\n", graphics
, mode
);
5347 return InvalidParameter
;
5352 graphics
->pixeloffset
= mode
;
5357 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5361 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5364 FIXME("value is unused in rendering\n");
5367 return InvalidParameter
;
5369 graphics
->origin_x
= x
;
5370 graphics
->origin_y
= y
;
5375 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5377 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5379 if (!graphics
|| !x
|| !y
)
5380 return InvalidParameter
;
5382 *x
= graphics
->origin_x
;
5383 *y
= graphics
->origin_y
;
5388 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5390 TRACE("(%p, %d)\n", graphics
, mode
);
5393 return InvalidParameter
;
5398 graphics
->smoothing
= mode
;
5403 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5405 TRACE("(%p, %d)\n", graphics
, contrast
);
5408 return InvalidParameter
;
5410 graphics
->textcontrast
= contrast
;
5415 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5416 TextRenderingHint hint
)
5418 TRACE("(%p, %d)\n", graphics
, hint
);
5420 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5421 return InvalidParameter
;
5426 graphics
->texthint
= hint
;
5431 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5433 TRACE("(%p, %p)\n", graphics
, matrix
);
5435 if(!graphics
|| !matrix
)
5436 return InvalidParameter
;
5441 TRACE("%f,%f,%f,%f,%f,%f\n",
5442 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5443 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5445 graphics
->worldtrans
= *matrix
;
5450 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5451 REAL dy
, GpMatrixOrder order
)
5453 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5456 return InvalidParameter
;
5461 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5464 /*****************************************************************************
5465 * GdipSetClipHrgn [GDIPLUS.@]
5467 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5472 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5475 return InvalidParameter
;
5480 /* hrgn is already in device units */
5481 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5485 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5487 GdipDeleteRegion(region
);
5491 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5496 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5499 return InvalidParameter
;
5504 status
= GdipClonePath(path
, &clip_path
);
5507 GpMatrix world_to_device
;
5509 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
5510 CoordinateSpaceWorld
, &world_to_device
);
5511 status
= GdipTransformPath(clip_path
, &world_to_device
);
5513 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
5515 GdipDeletePath(clip_path
);
5520 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5521 REAL width
, REAL height
,
5528 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5531 return InvalidParameter
;
5539 rect
.Height
= height
;
5540 status
= GdipCreateRegionRect(&rect
, ®ion
);
5543 GpMatrix world_to_device
;
5545 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5546 status
= GdipTransformRegion(region
, &world_to_device
);
5548 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5550 GdipDeleteRegion(region
);
5555 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5556 INT width
, INT height
,
5559 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5562 return InvalidParameter
;
5567 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5570 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5576 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5578 if(!graphics
|| !region
)
5579 return InvalidParameter
;
5584 status
= GdipCloneRegion(region
, &clip
);
5587 GpMatrix world_to_device
;
5589 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5590 status
= GdipTransformRegion(clip
, &world_to_device
);
5592 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
5594 GdipDeleteRegion(clip
);
5599 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5605 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5607 if(!graphics
|| !pen
|| count
<=0)
5608 return InvalidParameter
;
5615 FIXME("graphics object has no HDC\n");
5619 pti
= heap_alloc_zero(sizeof(POINT
) * count
);
5621 save_state
= prepare_dc(graphics
, pen
);
5622 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5624 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5625 Polygon(graphics
->hdc
, pti
, count
);
5627 restore_dc(graphics
, save_state
);
5633 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5640 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5642 if(count
<=0) return InvalidParameter
;
5643 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
5645 for(i
= 0;i
< count
; i
++){
5646 ptf
[i
].X
= (REAL
)points
[i
].X
;
5647 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5650 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5656 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5658 TRACE("(%p, %p)\n", graphics
, dpi
);
5660 if(!graphics
|| !dpi
)
5661 return InvalidParameter
;
5666 *dpi
= graphics
->xres
;
5670 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5672 TRACE("(%p, %p)\n", graphics
, dpi
);
5674 if(!graphics
|| !dpi
)
5675 return InvalidParameter
;
5680 *dpi
= graphics
->yres
;
5684 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5685 GpMatrixOrder order
)
5690 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5692 if(!graphics
|| !matrix
)
5693 return InvalidParameter
;
5698 m
= graphics
->worldtrans
;
5700 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5702 graphics
->worldtrans
= m
;
5707 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5708 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5710 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5714 TRACE("(%p, %p)\n", graphics
, hdc
);
5716 if(!graphics
|| !hdc
)
5717 return InvalidParameter
;
5722 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5724 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5726 else if (!graphics
->hdc
||
5727 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5729 /* Create a fake HDC and fill it with a constant color. */
5733 BITMAPINFOHEADER bmih
;
5736 stat
= get_graphics_bounds(graphics
, &bounds
);
5740 graphics
->temp_hbitmap_width
= bounds
.Width
;
5741 graphics
->temp_hbitmap_height
= bounds
.Height
;
5743 bmih
.biSize
= sizeof(bmih
);
5744 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5745 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5747 bmih
.biBitCount
= 32;
5748 bmih
.biCompression
= BI_RGB
;
5749 bmih
.biSizeImage
= 0;
5750 bmih
.biXPelsPerMeter
= 0;
5751 bmih
.biYPelsPerMeter
= 0;
5753 bmih
.biClrImportant
= 0;
5755 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5756 (void**)&graphics
->temp_bits
, NULL
, 0);
5758 return GenericError
;
5760 temp_hdc
= CreateCompatibleDC(0);
5763 DeleteObject(hbitmap
);
5764 return GenericError
;
5767 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5768 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5770 SelectObject(temp_hdc
, hbitmap
);
5772 graphics
->temp_hbitmap
= hbitmap
;
5773 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5777 *hdc
= graphics
->hdc
;
5781 graphics
->busy
= TRUE
;
5786 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5790 TRACE("(%p, %p)\n", graphics
, hdc
);
5792 if(!graphics
|| !hdc
|| !graphics
->busy
)
5793 return InvalidParameter
;
5795 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5797 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5799 else if (graphics
->temp_hdc
== hdc
)
5804 /* Find the pixels that have changed, and mark them as opaque. */
5805 pos
= (DWORD
*)graphics
->temp_bits
;
5806 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5808 if (*pos
!= DC_BACKGROUND_KEY
)
5815 /* Write the changed pixels to the real target. */
5816 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5817 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5818 graphics
->temp_hbitmap_width
* 4, PixelFormat32bppARGB
);
5821 DeleteDC(graphics
->temp_hdc
);
5822 DeleteObject(graphics
->temp_hbitmap
);
5823 graphics
->temp_hdc
= NULL
;
5824 graphics
->temp_hbitmap
= NULL
;
5826 else if (hdc
!= graphics
->hdc
)
5828 stat
= InvalidParameter
;
5832 graphics
->busy
= FALSE
;
5837 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5841 GpMatrix device_to_world
;
5843 TRACE("(%p, %p)\n", graphics
, region
);
5845 if(!graphics
|| !region
)
5846 return InvalidParameter
;
5851 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5854 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
5855 status
= GdipTransformRegion(clip
, &device_to_world
);
5858 GdipDeleteRegion(clip
);
5862 /* free everything except root node and header */
5863 delete_element(®ion
->node
);
5864 memcpy(region
, clip
, sizeof(GpRegion
));
5870 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5871 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
5874 REAL scale_x
, scale_y
;
5876 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5878 if (dst_space
!= src_space
)
5880 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5881 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5883 if(graphics
->unit
!= UnitDisplay
)
5885 scale_x
*= graphics
->scale
;
5886 scale_y
*= graphics
->scale
;
5889 /* transform from src_space to CoordinateSpacePage */
5892 case CoordinateSpaceWorld
:
5893 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
5895 case CoordinateSpacePage
:
5897 case CoordinateSpaceDevice
:
5898 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
5902 /* transform from CoordinateSpacePage to dst_space */
5905 case CoordinateSpaceWorld
:
5907 GpMatrix inverted_transform
= graphics
->worldtrans
;
5908 stat
= GdipInvertMatrix(&inverted_transform
);
5910 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
5913 case CoordinateSpacePage
:
5915 case CoordinateSpaceDevice
:
5916 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
5923 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5924 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5929 if(!graphics
|| !points
|| count
<= 0)
5930 return InvalidParameter
;
5935 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5937 if (src_space
== dst_space
) return Ok
;
5939 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5940 if (stat
!= Ok
) return stat
;
5942 return GdipTransformMatrixPoints(&matrix
, points
, count
);
5945 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5946 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5952 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5955 return InvalidParameter
;
5957 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
5961 for(i
= 0; i
< count
; i
++){
5962 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5963 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5966 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5969 for(i
= 0; i
< count
; i
++){
5970 points
[i
].X
= gdip_round(pointsF
[i
].X
);
5971 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
5978 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5990 /*****************************************************************************
5991 * GdipTranslateClip [GDIPLUS.@]
5993 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5995 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5998 return InvalidParameter
;
6003 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6006 /*****************************************************************************
6007 * GdipTranslateClipI [GDIPLUS.@]
6009 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6011 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6014 return InvalidParameter
;
6019 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6023 /*****************************************************************************
6024 * GdipMeasureDriverString [GDIPLUS.@]
6026 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6027 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6028 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6030 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6033 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6035 TEXTMETRICW textmetric
;
6036 const WORD
*glyph_indices
;
6037 WORD
*dynamic_glyph_indices
=NULL
;
6038 REAL rel_width
, rel_height
, ascent
, descent
;
6041 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6043 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6044 return InvalidParameter
;
6047 length
= strlenW(text
);
6051 boundingBox
->X
= 0.0;
6052 boundingBox
->Y
= 0.0;
6053 boundingBox
->Width
= 0.0;
6054 boundingBox
->Height
= 0.0;
6057 if (flags
& unsupported_flags
)
6058 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6060 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6062 hdc
= CreateCompatibleDC(0);
6063 SelectObject(hdc
, hfont
);
6065 GetTextMetricsW(hdc
, &textmetric
);
6075 GpMatrix xform
= *matrix
;
6076 GdipTransformMatrixPoints(&xform
, pt
, 3);
6078 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6079 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6080 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6081 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6082 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6084 if (flags
& DriverStringOptionsCmapLookup
)
6086 glyph_indices
= dynamic_glyph_indices
= heap_alloc_zero(sizeof(WORD
) * length
);
6090 DeleteObject(hfont
);
6094 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6097 glyph_indices
= text
;
6099 min_x
= max_x
= x
= positions
[0].X
;
6100 min_y
= max_y
= y
= positions
[0].Y
;
6102 ascent
= textmetric
.tmAscent
/ rel_height
;
6103 descent
= textmetric
.tmDescent
/ rel_height
;
6105 for (i
=0; i
<length
; i
++)
6110 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6116 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6117 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6119 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6120 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6121 if (min_x
> x
) min_x
= x
;
6123 x
+= char_width
/ rel_width
;
6125 if (max_x
< x
) max_x
= x
;
6128 heap_free(dynamic_glyph_indices
);
6130 DeleteObject(hfont
);
6132 boundingBox
->X
= min_x
;
6133 boundingBox
->Y
= min_y
;
6134 boundingBox
->Width
= max_x
- min_x
;
6135 boundingBox
->Height
= max_y
- min_y
;
6140 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6141 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6142 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6143 INT flags
, GDIPCONST GpMatrix
*matrix
)
6145 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6151 if (flags
& unsupported_flags
)
6152 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6154 if (!(flags
& DriverStringOptionsCmapLookup
))
6155 eto_flags
|= ETO_GLYPH_INDEX
;
6157 save_state
= SaveDC(graphics
->hdc
);
6158 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6159 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6162 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6164 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6165 SelectObject(graphics
->hdc
, hfont
);
6167 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6169 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6171 RestoreDC(graphics
->hdc
, save_state
);
6173 DeleteObject(hfont
);
6178 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6179 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6180 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6181 INT flags
, GDIPCONST GpMatrix
*matrix
)
6183 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6185 PointF
*real_positions
, real_position
;
6189 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6190 DWORD max_glyphsize
=0;
6191 GLYPHMETRICS glyphmetrics
;
6192 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6195 int text_mask_stride
;
6197 int pixel_data_stride
;
6199 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6204 if (!(flags
& DriverStringOptionsCmapLookup
))
6205 ggo_flags
|= GGO_GLYPH_INDEX
;
6207 if (flags
& unsupported_flags
)
6208 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6210 pti
= heap_alloc_zero(sizeof(POINT
) * length
);
6214 if (flags
& DriverStringOptionsRealizedAdvance
)
6216 real_position
= positions
[0];
6218 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6222 real_positions
= heap_alloc_zero(sizeof(PointF
) * length
);
6223 if (!real_positions
)
6229 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6231 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6233 heap_free(real_positions
);
6236 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6238 hdc
= CreateCompatibleDC(0);
6239 SelectObject(hdc
, hfont
);
6241 /* Get the boundaries of the text to be drawn */
6242 for (i
=0; i
<length
; i
++)
6245 int left
, top
, right
, bottom
;
6247 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6248 &glyphmetrics
, 0, NULL
, &identity
);
6250 if (glyphsize
== GDI_ERROR
)
6252 ERR("GetGlyphOutlineW failed\n");
6255 DeleteObject(hfont
);
6256 return GenericError
;
6259 if (glyphsize
> max_glyphsize
)
6260 max_glyphsize
= glyphsize
;
6264 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6265 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6266 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6267 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6269 if (left
< min_x
) min_x
= left
;
6270 if (top
< min_y
) min_y
= top
;
6271 if (right
> max_x
) max_x
= right
;
6272 if (bottom
> max_y
) max_y
= bottom
;
6275 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6277 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6278 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6282 if (max_glyphsize
== 0)
6283 /* Nothing to draw. */
6286 glyph_mask
= heap_alloc_zero(max_glyphsize
);
6287 text_mask
= heap_alloc_zero((max_x
- min_x
) * (max_y
- min_y
));
6288 text_mask_stride
= max_x
- min_x
;
6290 if (!(glyph_mask
&& text_mask
))
6292 heap_free(glyph_mask
);
6293 heap_free(text_mask
);
6296 DeleteObject(hfont
);
6300 /* Generate a mask for the text */
6301 for (i
=0; i
<length
; i
++)
6304 int left
, top
, stride
;
6306 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6307 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6309 if (ret
== GDI_ERROR
|| ret
== 0)
6310 continue; /* empty glyph */
6312 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6313 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6314 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6316 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6318 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6319 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6320 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6322 *text_val
= min(64, *text_val
+ *glyph_val
);
6331 DeleteObject(hfont
);
6332 heap_free(glyph_mask
);
6334 /* get the brush data */
6335 pixel_data
= heap_alloc_zero(4 * (max_x
- min_x
) * (max_y
- min_y
));
6338 heap_free(text_mask
);
6342 pixel_area
.X
= min_x
;
6343 pixel_area
.Y
= min_y
;
6344 pixel_area
.Width
= max_x
- min_x
;
6345 pixel_area
.Height
= max_y
- min_y
;
6346 pixel_data_stride
= pixel_area
.Width
* 4;
6348 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6351 heap_free(text_mask
);
6352 heap_free(pixel_data
);
6356 /* multiply the brush data by the mask */
6357 for (y
=0; y
<pixel_area
.Height
; y
++)
6359 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6360 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6361 for (x
=0; x
<pixel_area
.Width
; x
++)
6363 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6369 heap_free(text_mask
);
6371 /* draw the result */
6372 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6373 pixel_area
.Height
, pixel_data_stride
, PixelFormat32bppARGB
);
6375 heap_free(pixel_data
);
6380 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6381 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6382 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6383 INT flags
, GDIPCONST GpMatrix
*matrix
)
6385 GpStatus stat
= NotImplemented
;
6388 length
= strlenW(text
);
6390 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6391 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6392 brush
->bt
== BrushTypeSolidColor
&&
6393 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6394 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6395 brush
, positions
, flags
, matrix
);
6396 if (stat
== NotImplemented
)
6397 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6398 brush
, positions
, flags
, matrix
);
6402 /*****************************************************************************
6403 * GdipDrawDriverString [GDIPLUS.@]
6405 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6406 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6407 GDIPCONST PointF
*positions
, INT flags
,
6408 GDIPCONST GpMatrix
*matrix
)
6410 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6412 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6413 return InvalidParameter
;
6415 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6416 brush
, positions
, flags
, matrix
);
6419 /*****************************************************************************
6420 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6422 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6427 TRACE("(%p, %p)\n", graphics
, res
);
6429 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6432 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6435 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6438 GdipDeleteRegion(rgn
);
6442 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6446 TRACE("(%p) stub\n", graphics
);
6449 FIXME("not implemented\n");
6451 return NotImplemented
;