2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/unicode.h"
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
45 /* looks-right constants */
46 #define ANCHOR_WIDTH (2.0)
47 #define MAX_ITERS (50)
49 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
50 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
51 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
52 INT flags
, GDIPCONST GpMatrix
*matrix
);
54 /* Converts from gdiplus path point type to gdi path point type. */
55 static BYTE
convert_path_point_type(BYTE type
)
59 switch(type
& PathPointTypePathTypeMask
){
60 case PathPointTypeBezier
:
63 case PathPointTypeLine
:
66 case PathPointTypeStart
:
70 ERR("Bad point type\n");
74 if(type
& PathPointTypeCloseSubpath
)
75 ret
|= PT_CLOSEFIGURE
;
80 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
86 case BrushTypeSolidColor
:
88 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
92 case BrushTypeHatchFill
:
94 const GpHatch
*hatch
= (const GpHatch
*)brush
;
95 argb
= hatch
->forecol
;
98 case BrushTypeLinearGradient
:
100 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
101 argb
= line
->startcolor
;
104 case BrushTypePathGradient
:
106 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
107 argb
= grad
->centercolor
;
111 FIXME("unhandled brush type %d\n", brush
->bt
);
115 return ARGB2COLORREF(argb
);
118 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
121 BITMAPINFOHEADER bmih
;
125 bmih
.biSize
= sizeof(bmih
);
129 bmih
.biBitCount
= 32;
130 bmih
.biCompression
= BI_RGB
;
131 bmih
.biSizeImage
= 0;
133 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
136 const char *hatch_data
;
138 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
140 for (y
= 0; y
< 8; y
++)
142 for (x
= 0; x
< 8; x
++)
144 if (hatch_data
[y
] & (0x80 >> x
))
145 bits
[y
* 8 + x
] = hatch
->forecol
;
147 bits
[y
* 8 + x
] = hatch
->backcol
;
153 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
155 for (y
= 0; y
< 64; y
++)
156 bits
[y
] = hatch
->forecol
;
163 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
167 case BrushTypeSolidColor
:
169 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
170 lb
->lbStyle
= BS_SOLID
;
171 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
176 case BrushTypeHatchFill
:
178 const GpHatch
*hatch
= (const GpHatch
*)brush
;
181 hbmp
= create_hatch_bitmap(hatch
);
182 if (!hbmp
) return OutOfMemory
;
184 lb
->lbStyle
= BS_PATTERN
;
186 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
191 FIXME("unhandled brush type %d\n", brush
->bt
);
192 lb
->lbStyle
= BS_SOLID
;
193 lb
->lbColor
= get_gdi_brush_color(brush
);
199 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
204 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
210 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
215 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
217 gdibrush
= CreateBrushIndirect(&lb
);
218 free_gdi_logbrush(&lb
);
223 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
228 INT save_state
, i
, numdashes
;
230 DWORD dash_array
[MAX_DASHLEN
];
232 save_state
= SaveDC(graphics
->hdc
);
234 EndPath(graphics
->hdc
);
236 if(pen
->unit
== UnitPixel
){
240 /* Get an estimate for the amount the pen width is affected by the world
241 * transform. (This is similar to what some of the wine drivers do.) */
246 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
247 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
248 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
250 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
251 width
*= graphics
->scale
;
257 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceDevice
, pt
, 2);
258 width
*= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
259 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
262 if(pen
->dash
== DashStyleCustom
){
263 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
265 TRACE("dashes are: ");
266 for(i
= 0; i
< numdashes
; i
++){
267 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
268 TRACE("%d, ", dash_array
[i
]);
270 TRACE("\n and the pen style is %x\n", pen
->style
);
272 create_gdi_logbrush(pen
->brush
, &lb
);
273 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
274 numdashes
, dash_array
);
275 free_gdi_logbrush(&lb
);
279 create_gdi_logbrush(pen
->brush
, &lb
);
280 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
281 free_gdi_logbrush(&lb
);
284 SelectObject(graphics
->hdc
, gdipen
);
289 static void restore_dc(GpGraphics
*graphics
, INT state
)
291 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
292 RestoreDC(graphics
->hdc
, state
);
295 static void round_points(POINT
*pti
, GpPointF
*ptf
, INT count
)
299 for(i
= 0; i
< count
; i
++){
300 pti
[i
].x
= gdip_round(ptf
[i
].X
);
301 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
305 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
306 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
308 if (GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
) == DT_RASPRINTER
&&
309 GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
311 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
313 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
314 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
320 bf
.BlendOp
= AC_SRC_OVER
;
322 bf
.SourceConstantAlpha
= 255;
323 bf
.AlphaFormat
= AC_SRC_ALPHA
;
325 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
326 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
330 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
336 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceDevice
, &transform
);
339 stat
= GdipCloneRegion(graphics
->clip
, &rgn
);
343 stat
= GdipTransformRegion(rgn
, &transform
);
346 stat
= GdipGetRegionHRgn(rgn
, NULL
, hrgn
);
348 GdipDeleteRegion(rgn
);
354 /* Draw ARGB data to the given graphics object */
355 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
356 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, const PixelFormat fmt
)
358 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
361 for (y
=0; y
<src_height
; y
++)
363 for (x
=0; x
<src_width
; x
++)
365 ARGB dst_color
, src_color
;
366 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
368 if (!(src_color
& 0xff000000))
371 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
372 if (fmt
& PixelFormatPAlpha
)
373 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over_fgpremult(dst_color
, src_color
));
375 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
382 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
383 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
387 BITMAPINFOHEADER bih
;
390 hdc
= CreateCompatibleDC(0);
392 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
393 bih
.biWidth
= src_width
;
394 bih
.biHeight
= -src_height
;
397 bih
.biCompression
= BI_RGB
;
399 bih
.biXPelsPerMeter
= 0;
400 bih
.biYPelsPerMeter
= 0;
402 bih
.biClrImportant
= 0;
404 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
405 (void**)&temp_bits
, NULL
, 0);
407 if ((GetDeviceCaps(graphics
->hdc
, TECHNOLOGY
) == DT_RASPRINTER
&&
408 GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
) ||
409 fmt
& PixelFormatPAlpha
)
410 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
412 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
413 4 * src_width
, src
, src_stride
);
415 SelectObject(hdc
, hbitmap
);
416 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
417 hdc
, 0, 0, src_width
, src_height
);
419 DeleteObject(hbitmap
);
424 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
425 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
, PixelFormat fmt
)
429 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
435 HRGN hrgn
, visible_rgn
;
437 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
441 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
450 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
451 DeleteObject(visible_rgn
);
455 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
457 size
= GetRegionData(hrgn
, 0, NULL
);
459 rgndata
= heap_alloc_zero(size
);
466 GetRegionData(hrgn
, size
, rgndata
);
468 rects
= (RECT
*)rgndata
->Buffer
;
470 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
472 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
473 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
474 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
484 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
486 ERR("This should not be used for metafiles; fix caller\n");
487 return NotImplemented
;
494 stat
= get_clip_hrgn(graphics
, &hrgn
);
499 save
= SaveDC(graphics
->hdc
);
502 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
505 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
507 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
508 src_height
, src_stride
, fmt
);
510 RestoreDC(graphics
->hdc
, save
);
518 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
519 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
521 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
, fmt
);
524 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
526 INT start_a
, end_a
, final_a
;
529 pos
= gdip_round(position
* 0xff);
531 start_a
= ((start
>> 24) & 0xff) * (pos
^ 0xff);
532 end_a
= ((end
>> 24) & 0xff) * pos
;
534 final_a
= start_a
+ end_a
;
536 if (final_a
< 0xff) return 0;
538 return (final_a
/ 0xff) << 24 |
539 ((((start
>> 16) & 0xff) * start_a
+ (((end
>> 16) & 0xff) * end_a
)) / final_a
) << 16 |
540 ((((start
>> 8) & 0xff) * start_a
+ (((end
>> 8) & 0xff) * end_a
)) / final_a
) << 8 |
541 (((start
& 0xff) * start_a
+ ((end
& 0xff) * end_a
)) / final_a
);
544 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
548 /* clamp to between 0.0 and 1.0, using the wrap mode */
549 position
= (position
- brush
->rect
.X
) / brush
->rect
.Width
;
550 if (brush
->wrap
== WrapModeTile
)
552 position
= fmodf(position
, 1.0f
);
553 if (position
< 0.0f
) position
+= 1.0f
;
555 else /* WrapModeFlip* */
557 position
= fmodf(position
, 2.0f
);
558 if (position
< 0.0f
) position
+= 2.0f
;
559 if (position
> 1.0f
) position
= 2.0f
- position
;
562 if (brush
->blendcount
== 1)
567 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
570 /* locate the blend positions surrounding this position */
571 while (position
> brush
->blendpos
[i
])
574 /* interpolate between the blend positions */
575 left_blendpos
= brush
->blendpos
[i
-1];
576 left_blendfac
= brush
->blendfac
[i
-1];
577 right_blendpos
= brush
->blendpos
[i
];
578 right_blendfac
= brush
->blendfac
[i
];
579 range
= right_blendpos
- left_blendpos
;
580 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
581 right_blendfac
* (position
- left_blendpos
)) / range
;
584 if (brush
->pblendcount
== 0)
585 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
589 ARGB left_blendcolor
, right_blendcolor
;
590 REAL left_blendpos
, right_blendpos
;
592 /* locate the blend colors surrounding this position */
593 while (blendfac
> brush
->pblendpos
[i
])
596 /* interpolate between the blend colors */
597 left_blendpos
= brush
->pblendpos
[i
-1];
598 left_blendcolor
= brush
->pblendcolor
[i
-1];
599 right_blendpos
= brush
->pblendpos
[i
];
600 right_blendcolor
= brush
->pblendcolor
[i
];
601 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
602 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
606 static BOOL
round_color_matrix(const ColorMatrix
*matrix
, int values
[5][5])
608 /* Convert floating point color matrix to int[5][5], return TRUE if it's an identity */
609 BOOL identity
= TRUE
;
615 if (matrix
->m
[j
][i
] != (i
== j
? 1.0 : 0.0))
617 values
[j
][i
] = gdip_round(matrix
->m
[j
][i
] * 256.0);
623 static ARGB
transform_color(ARGB color
, int matrix
[5][5])
627 unsigned char a
, r
, g
, b
;
629 val
[0] = ((color
>> 16) & 0xff); /* red */
630 val
[1] = ((color
>> 8) & 0xff); /* green */
631 val
[2] = (color
& 0xff); /* blue */
632 val
[3] = ((color
>> 24) & 0xff); /* alpha */
633 val
[4] = 255; /* translation */
640 res
[i
] += matrix
[j
][i
] * val
[j
];
643 a
= min(max(res
[3] / 256, 0), 255);
644 r
= min(max(res
[0] / 256, 0), 255);
645 g
= min(max(res
[1] / 256, 0), 255);
646 b
= min(max(res
[2] / 256, 0), 255);
648 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
651 static BOOL
color_is_gray(ARGB color
)
653 unsigned char r
, g
, b
;
655 r
= (color
>> 16) & 0xff;
656 g
= (color
>> 8) & 0xff;
659 return (r
== g
) && (g
== b
);
662 /* returns preferred pixel format for the applied attributes */
663 PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
664 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
)
669 if (attributes
->colorkeys
[type
].enabled
||
670 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
672 const struct color_key
*key
;
673 BYTE min_blue
, min_green
, min_red
;
674 BYTE max_blue
, max_green
, max_red
;
676 if (!data
|| fmt
!= PixelFormat32bppARGB
)
677 return PixelFormat32bppARGB
;
679 if (attributes
->colorkeys
[type
].enabled
)
680 key
= &attributes
->colorkeys
[type
];
682 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
684 min_blue
= key
->low
&0xff;
685 min_green
= (key
->low
>>8)&0xff;
686 min_red
= (key
->low
>>16)&0xff;
688 max_blue
= key
->high
&0xff;
689 max_green
= (key
->high
>>8)&0xff;
690 max_red
= (key
->high
>>16)&0xff;
692 for (x
=0; x
<width
; x
++)
693 for (y
=0; y
<height
; y
++)
696 BYTE blue
, green
, red
;
697 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
698 blue
= *src_color
&0xff;
699 green
= (*src_color
>>8)&0xff;
700 red
= (*src_color
>>16)&0xff;
701 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
702 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
703 *src_color
= 0x00000000;
707 if (attributes
->colorremaptables
[type
].enabled
||
708 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
710 const struct color_remap_table
*table
;
712 if (!data
|| fmt
!= PixelFormat32bppARGB
)
713 return PixelFormat32bppARGB
;
715 if (attributes
->colorremaptables
[type
].enabled
)
716 table
= &attributes
->colorremaptables
[type
];
718 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
720 for (x
=0; x
<width
; x
++)
721 for (y
=0; y
<height
; y
++)
724 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
725 for (i
=0; i
<table
->mapsize
; i
++)
727 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
729 *src_color
= table
->colormap
[i
].newColor
.Argb
;
736 if (attributes
->colormatrices
[type
].enabled
||
737 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
739 const struct color_matrix
*colormatrices
;
740 int color_matrix
[5][5];
741 int gray_matrix
[5][5];
744 if (!data
|| fmt
!= PixelFormat32bppARGB
)
745 return PixelFormat32bppARGB
;
747 if (attributes
->colormatrices
[type
].enabled
)
748 colormatrices
= &attributes
->colormatrices
[type
];
750 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
752 identity
= round_color_matrix(&colormatrices
->colormatrix
, color_matrix
);
754 if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
755 identity
= (round_color_matrix(&colormatrices
->graymatrix
, gray_matrix
) && identity
);
759 for (x
=0; x
<width
; x
++)
761 for (y
=0; y
<height
; y
++)
764 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
766 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
767 !color_is_gray(*src_color
))
769 *src_color
= transform_color(*src_color
, color_matrix
);
771 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
773 *src_color
= transform_color(*src_color
, gray_matrix
);
780 if (attributes
->gamma_enabled
[type
] ||
781 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
785 if (!data
|| fmt
!= PixelFormat32bppARGB
)
786 return PixelFormat32bppARGB
;
788 if (attributes
->gamma_enabled
[type
])
789 gamma
= attributes
->gamma
[type
];
791 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
793 for (x
=0; x
<width
; x
++)
794 for (y
=0; y
<height
; y
++)
797 BYTE blue
, green
, red
;
798 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
800 blue
= *src_color
&0xff;
801 green
= (*src_color
>>8)&0xff;
802 red
= (*src_color
>>16)&0xff;
804 /* FIXME: We should probably use a table for this. */
805 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
806 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
807 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
809 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
816 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
817 * bitmap that contains all the pixels we may need to draw it. */
818 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
819 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
822 INT left
, top
, right
, bottom
;
824 switch (interpolation
)
826 case InterpolationModeHighQualityBilinear
:
827 case InterpolationModeHighQualityBicubic
:
828 /* FIXME: Include a greater range for the prefilter? */
829 case InterpolationModeBicubic
:
830 case InterpolationModeBilinear
:
831 left
= (INT
)(floorf(srcx
));
832 top
= (INT
)(floorf(srcy
));
833 right
= (INT
)(ceilf(srcx
+srcwidth
));
834 bottom
= (INT
)(ceilf(srcy
+srcheight
));
836 case InterpolationModeNearestNeighbor
:
838 left
= gdip_round(srcx
);
839 top
= gdip_round(srcy
);
840 right
= gdip_round(srcx
+srcwidth
);
841 bottom
= gdip_round(srcy
+srcheight
);
845 if (wrap
== WrapModeClamp
)
851 if (right
>= bitmap
->width
)
852 right
= bitmap
->width
-1;
853 if (bottom
>= bitmap
->height
)
854 bottom
= bitmap
->height
-1;
855 if (bottom
< top
|| right
< left
)
856 /* entirely outside image, just sample a pixel so we don't have to
857 * special-case this later */
858 left
= top
= right
= bottom
= 0;
862 /* In some cases we can make the rectangle smaller here, but the logic
863 * is hard to get right, and tiling suggests we're likely to use the
864 * entire source image. */
865 if (left
< 0 || right
>= bitmap
->width
)
868 right
= bitmap
->width
-1;
871 if (top
< 0 || bottom
>= bitmap
->height
)
874 bottom
= bitmap
->height
-1;
880 rect
->Width
= right
- left
+ 1;
881 rect
->Height
= bottom
- top
+ 1;
884 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
885 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
887 if (attributes
->wrap
== WrapModeClamp
)
889 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
890 return attributes
->outside_color
;
894 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
896 x
= width
*2 + x
% (width
* 2);
898 y
= height
*2 + y
% (height
* 2);
900 if (attributes
->wrap
& WrapModeTileFlipX
)
902 if ((x
/ width
) % 2 == 0)
905 x
= width
- 1 - x
% width
;
910 if (attributes
->wrap
& WrapModeTileFlipY
)
912 if ((y
/ height
) % 2 == 0)
915 y
= height
- 1 - y
% height
;
921 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
923 ERR("out of range pixel requested\n");
927 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
930 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
931 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
932 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
936 switch (interpolation
)
940 FIXME("Unimplemented interpolation %i\n", interpolation
);
942 case InterpolationModeBilinear
:
945 INT leftx
, rightx
, topy
, bottomy
;
946 ARGB topleft
, topright
, bottomleft
, bottomright
;
950 leftxf
= floorf(point
->X
);
952 rightx
= (INT
)ceilf(point
->X
);
953 topyf
= floorf(point
->Y
);
955 bottomy
= (INT
)ceilf(point
->Y
);
957 if (leftx
== rightx
&& topy
== bottomy
)
958 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
959 leftx
, topy
, attributes
);
961 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
962 leftx
, topy
, attributes
);
963 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
964 rightx
, topy
, attributes
);
965 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
966 leftx
, bottomy
, attributes
);
967 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
968 rightx
, bottomy
, attributes
);
970 x_offset
= point
->X
- leftxf
;
971 top
= blend_colors(topleft
, topright
, x_offset
);
972 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
974 return blend_colors(top
, bottom
, point
->Y
- topyf
);
976 case InterpolationModeNearestNeighbor
:
982 case PixelOffsetModeNone
:
983 case PixelOffsetModeHighSpeed
:
987 case PixelOffsetModeHalf
:
988 case PixelOffsetModeHighQuality
:
992 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
993 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
999 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
1001 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
1004 /* is_fill is TRUE if filling regions, FALSE for drawing primitives */
1005 static BOOL
brush_can_fill_path(GpBrush
*brush
, BOOL is_fill
)
1009 case BrushTypeSolidColor
:
1015 /* cannot draw semi-transparent colors */
1016 return (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000;
1019 case BrushTypeHatchFill
:
1021 GpHatch
*hatch
= (GpHatch
*)brush
;
1022 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
1023 ((hatch
->backcol
& 0xff000000) == 0xff000000);
1025 case BrushTypeLinearGradient
:
1026 case BrushTypeTextureFill
:
1027 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
1033 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
1037 case BrushTypeSolidColor
:
1039 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1040 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1045 /* partially transparent fill */
1047 SelectClipPath(graphics
->hdc
, RGN_AND
);
1048 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1050 HDC hdc
= CreateCompatibleDC(NULL
);
1054 SelectObject(hdc
, bmp
);
1055 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1063 /* else fall through */
1067 HBRUSH gdibrush
, old_brush
;
1069 gdibrush
= create_gdi_brush(brush
);
1070 if (!gdibrush
) return;
1072 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1073 FillPath(graphics
->hdc
);
1074 SelectObject(graphics
->hdc
, old_brush
);
1075 DeleteObject(gdibrush
);
1081 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1085 case BrushTypeSolidColor
:
1086 case BrushTypeHatchFill
:
1087 case BrushTypeLinearGradient
:
1088 case BrushTypeTextureFill
:
1089 case BrushTypePathGradient
:
1096 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1097 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1101 case BrushTypeSolidColor
:
1104 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1105 for (x
=0; x
<fill_area
->Width
; x
++)
1106 for (y
=0; y
<fill_area
->Height
; y
++)
1107 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1110 case BrushTypeHatchFill
:
1113 GpHatch
*fill
= (GpHatch
*)brush
;
1114 const char *hatch_data
;
1116 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1117 return NotImplemented
;
1119 for (x
=0; x
<fill_area
->Width
; x
++)
1120 for (y
=0; y
<fill_area
->Height
; y
++)
1124 /* FIXME: Account for the rendering origin */
1125 hx
= (x
+ fill_area
->X
) % 8;
1126 hy
= (y
+ fill_area
->Y
) % 8;
1128 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1129 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1131 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1136 case BrushTypeLinearGradient
:
1138 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1139 GpPointF draw_points
[3];
1143 draw_points
[0].X
= fill_area
->X
;
1144 draw_points
[0].Y
= fill_area
->Y
;
1145 draw_points
[1].X
= fill_area
->X
+1;
1146 draw_points
[1].Y
= fill_area
->Y
;
1147 draw_points
[2].X
= fill_area
->X
;
1148 draw_points
[2].Y
= fill_area
->Y
+1;
1150 /* Transform the points to a co-ordinate space where X is the point's
1151 * position in the gradient, 0.0 being the start point and 1.0 the
1153 stat
= gdip_transform_points(graphics
, CoordinateSpaceWorld
,
1154 WineCoordinateSpaceGdiDevice
, draw_points
, 3);
1158 GpMatrix world_to_gradient
= fill
->transform
;
1160 stat
= GdipInvertMatrix(&world_to_gradient
);
1162 stat
= GdipTransformMatrixPoints(&world_to_gradient
, draw_points
, 3);
1167 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1168 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1170 for (y
=0; y
<fill_area
->Height
; y
++)
1172 for (x
=0; x
<fill_area
->Width
; x
++)
1174 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1176 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1183 case BrushTypeTextureFill
:
1185 GpTexture
*fill
= (GpTexture
*)brush
;
1186 GpPointF draw_points
[3];
1193 if (fill
->image
->type
!= ImageTypeBitmap
)
1195 FIXME("metafile texture brushes not implemented\n");
1196 return NotImplemented
;
1199 bitmap
= (GpBitmap
*)fill
->image
;
1200 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1202 src_area
.X
= src_area
.Y
= 0;
1203 src_area
.Width
= bitmap
->width
;
1204 src_area
.Height
= bitmap
->height
;
1206 draw_points
[0].X
= fill_area
->X
;
1207 draw_points
[0].Y
= fill_area
->Y
;
1208 draw_points
[1].X
= fill_area
->X
+1;
1209 draw_points
[1].Y
= fill_area
->Y
;
1210 draw_points
[2].X
= fill_area
->X
;
1211 draw_points
[2].Y
= fill_area
->Y
+1;
1213 /* Transform the points to the co-ordinate space of the bitmap. */
1214 stat
= gdip_transform_points(graphics
, CoordinateSpaceWorld
,
1215 WineCoordinateSpaceGdiDevice
, draw_points
, 3);
1219 GpMatrix world_to_texture
= fill
->transform
;
1221 stat
= GdipInvertMatrix(&world_to_texture
);
1223 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1226 if (stat
== Ok
&& !fill
->bitmap_bits
)
1228 BitmapData lockeddata
;
1230 fill
->bitmap_bits
= heap_alloc_zero(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1231 if (!fill
->bitmap_bits
)
1236 lockeddata
.Width
= bitmap
->width
;
1237 lockeddata
.Height
= bitmap
->height
;
1238 lockeddata
.Stride
= src_stride
;
1239 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1240 lockeddata
.Scan0
= fill
->bitmap_bits
;
1242 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1243 PixelFormat32bppARGB
, &lockeddata
);
1247 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1250 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1251 bitmap
->width
, bitmap
->height
,
1252 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
1256 heap_free(fill
->bitmap_bits
);
1257 fill
->bitmap_bits
= NULL
;
1263 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1264 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1265 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1266 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1268 for (y
=0; y
<fill_area
->Height
; y
++)
1270 for (x
=0; x
<fill_area
->Width
; x
++)
1273 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1274 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1276 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1277 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1278 &point
, fill
->imageattributes
, graphics
->interpolation
,
1279 graphics
->pixeloffset
);
1286 case BrushTypePathGradient
:
1288 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1290 GpMatrix world_to_device
;
1292 int i
, figure_start
=0;
1293 GpPointF start_point
, end_point
, center_point
;
1295 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1296 INT min_y
, max_y
, min_x
, max_x
;
1299 static BOOL transform_fixme_once
;
1301 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1305 FIXME("path gradient focus not implemented\n");
1312 FIXME("path gradient gamma correction not implemented\n");
1315 if (fill
->blendcount
)
1319 FIXME("path gradient blend not implemented\n");
1322 if (fill
->pblendcount
)
1326 FIXME("path gradient preset blend not implemented\n");
1329 if (!transform_fixme_once
)
1331 BOOL is_identity
=TRUE
;
1332 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1335 FIXME("path gradient transform not implemented\n");
1336 transform_fixme_once
= TRUE
;
1340 stat
= GdipClonePath(fill
->path
, &flat_path
);
1345 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
1346 CoordinateSpaceWorld
, &world_to_device
);
1349 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1353 center_point
= fill
->center
;
1354 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1358 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1363 GdipDeletePath(flat_path
);
1367 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1369 int start_center_line
=0, end_center_line
=0;
1370 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1371 REAL center_distance
;
1372 ARGB start_color
, end_color
;
1375 type
= flat_path
->pathdata
.Types
[i
];
1377 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1380 start_point
= flat_path
->pathdata
.Points
[i
];
1382 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1384 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1386 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1387 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1389 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1391 end_point
= flat_path
->pathdata
.Points
[i
+1];
1392 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1397 outer_color
= start_color
;
1399 min_yf
= center_point
.Y
;
1400 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1401 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1403 if (min_yf
< fill_area
->Y
)
1404 min_y
= fill_area
->Y
;
1406 min_y
= (INT
)ceil(min_yf
);
1408 max_yf
= center_point
.Y
;
1409 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1410 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1412 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1413 max_y
= fill_area
->Y
+ fill_area
->Height
;
1415 max_y
= (INT
)ceil(max_yf
);
1417 dy
= end_point
.Y
- start_point
.Y
;
1418 dx
= end_point
.X
- start_point
.X
;
1420 /* This is proportional to the distance from start-end line to center point. */
1421 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1422 dx
* (center_point
.Y
- start_point
.Y
);
1424 for (y
=min_y
; y
<max_y
; y
++)
1428 if (!seen_start
&& yf
>= start_point
.Y
)
1431 start_center_line
^= 1;
1433 if (!seen_end
&& yf
>= end_point
.Y
)
1436 end_center_line
^= 1;
1438 if (!seen_center
&& yf
>= center_point
.Y
)
1441 start_center_line
^= 1;
1442 end_center_line
^= 1;
1445 if (start_center_line
)
1446 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1448 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1450 if (end_center_line
)
1451 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1453 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1455 if (line1_xf
< line2_xf
)
1457 min_x
= (INT
)ceil(line1_xf
);
1458 max_x
= (INT
)ceil(line2_xf
);
1462 min_x
= (INT
)ceil(line2_xf
);
1463 max_x
= (INT
)ceil(line1_xf
);
1466 if (min_x
< fill_area
->X
)
1467 min_x
= fill_area
->X
;
1468 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1469 max_x
= fill_area
->X
+ fill_area
->Width
;
1471 for (x
=min_x
; x
<max_x
; x
++)
1476 if (start_color
!= end_color
)
1478 REAL blend_amount
, pdy
, pdx
;
1479 pdy
= yf
- center_point
.Y
;
1480 pdx
= xf
- center_point
.X
;
1482 if (fabs(pdx
) <= 0.001 && fabs(pdy
) <= 0.001)
1484 /* Too close to center point, don't try to calculate outer color */
1485 outer_color
= start_color
;
1489 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1490 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1494 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1495 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1497 distance
= distance
/ center_distance
;
1499 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1500 blend_colors(outer_color
, fill
->centercolor
, distance
);
1505 GdipDeletePath(flat_path
);
1509 return NotImplemented
;
1513 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1514 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1515 * should not be called on an hdc that has a path you care about. */
1516 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1517 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1519 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1521 HBRUSH brush
= NULL
;
1523 PointF ptf
[4], *custptf
= NULL
;
1524 POINT pt
[4], *custpt
= NULL
;
1526 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1531 if((x1
== x2
) && (y1
== y2
))
1534 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1536 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1538 brush
= CreateSolidBrush(color
);
1539 lb
.lbStyle
= BS_SOLID
;
1542 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1543 PS_JOIN_MITER
, 1, &lb
, 0,
1545 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1546 oldpen
= SelectObject(graphics
->hdc
, pen
);
1553 case LineCapSquareAnchor
:
1554 case LineCapDiamondAnchor
:
1555 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1556 if(cap
== LineCapDiamondAnchor
){
1557 dsmall
= cos(theta
+ M_PI_2
) * size
;
1558 dbig
= sin(theta
+ M_PI_2
) * size
;
1561 dsmall
= cos(theta
+ M_PI_4
) * size
;
1562 dbig
= sin(theta
+ M_PI_4
) * size
;
1565 ptf
[0].X
= x2
- dsmall
;
1566 ptf
[1].X
= x2
+ dbig
;
1568 ptf
[0].Y
= y2
- dbig
;
1569 ptf
[3].Y
= y2
+ dsmall
;
1571 ptf
[1].Y
= y2
- dsmall
;
1572 ptf
[2].Y
= y2
+ dbig
;
1574 ptf
[3].X
= x2
- dbig
;
1575 ptf
[2].X
= x2
+ dsmall
;
1577 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1579 round_points(pt
, ptf
, 3);
1581 Polygon(graphics
->hdc
, pt
, 4);
1584 case LineCapArrowAnchor
:
1585 size
= size
* 4.0 / sqrt(3.0);
1587 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1588 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1593 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1594 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1602 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1604 round_points(pt
, ptf
, 3);
1606 Polygon(graphics
->hdc
, pt
, 3);
1609 case LineCapRoundAnchor
:
1610 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1617 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1619 round_points(pt
, ptf
, 3);
1621 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1624 case LineCapTriangle
:
1626 dx
= cos(M_PI_2
+ theta
) * size
;
1627 dy
= sin(M_PI_2
+ theta
) * size
;
1634 dx
= cos(theta
) * size
;
1635 dy
= sin(theta
) * size
;
1640 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1642 round_points(pt
, ptf
, 3);
1644 Polygon(graphics
->hdc
, pt
, 3);
1648 dx
= dy
= size
/ 2.0;
1655 dx
= -cos(M_PI_2
+ theta
) * size
;
1656 dy
= -sin(M_PI_2
+ theta
) * size
;
1663 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1665 round_points(pt
, ptf
, 3);
1667 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1668 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1675 count
= custom
->pathdata
.Count
;
1676 custptf
= heap_alloc_zero(count
* sizeof(PointF
));
1677 custpt
= heap_alloc_zero(count
* sizeof(POINT
));
1678 tp
= heap_alloc_zero(count
);
1680 if(!custptf
|| !custpt
|| !tp
)
1683 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1685 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1686 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1687 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1689 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1690 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1692 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 3);
1694 round_points(pt
, ptf
, 3);
1696 for(i
= 0; i
< count
; i
++)
1697 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1700 BeginPath(graphics
->hdc
);
1701 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1702 EndPath(graphics
->hdc
);
1703 StrokeAndFillPath(graphics
->hdc
);
1706 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1718 SelectObject(graphics
->hdc
, oldbrush
);
1719 SelectObject(graphics
->hdc
, oldpen
);
1720 DeleteObject(brush
);
1725 /* Shortens the line by the given percent by changing x2, y2.
1726 * If percent is > 1.0 then the line will change direction.
1727 * If percent is negative it can lengthen the line. */
1728 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1730 REAL dist
, theta
, dx
, dy
;
1732 if((y1
== *y2
) && (x1
== *x2
))
1735 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1736 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1737 dx
= cos(theta
) * dist
;
1738 dy
= sin(theta
) * dist
;
1744 /* Shortens the line by the given amount by changing x2, y2.
1745 * If the amount is greater than the distance, the line will become length 0.
1746 * If the amount is negative, it can lengthen the line. */
1747 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1749 REAL dx
, dy
, percent
;
1753 if(dx
== 0 && dy
== 0)
1756 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1763 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1766 /* Conducts a linear search to find the bezier points that will back off
1767 * the endpoint of the curve by a distance of amt. Linear search works
1768 * better than binary in this case because there are multiple solutions,
1769 * and binary searches often find a bad one. I don't think this is what
1770 * Windows does but short of rendering the bezier without GDI's help it's
1771 * the best we can do. If rev then work from the start of the passed points
1772 * instead of the end. */
1773 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1776 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1777 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1786 origx
= pt
[fourth
].X
;
1787 origy
= pt
[fourth
].Y
;
1788 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1790 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1791 /* reset bezier points to original values */
1792 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1793 /* Perform magic on bezier points. Order is important here.*/
1794 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1795 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1796 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1797 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1798 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1799 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1801 dx
= pt
[fourth
].X
- origx
;
1802 dy
= pt
[fourth
].Y
- origy
;
1804 diff
= sqrt(dx
* dx
+ dy
* dy
);
1805 percent
+= 0.0005 * amt
;
1809 /* Draws a combination of bezier curves and lines between points. */
1810 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1811 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1813 POINT
*pti
= heap_alloc_zero(count
* sizeof(POINT
));
1814 BYTE
*tp
= heap_alloc_zero(count
);
1815 GpPointF
*ptcopy
= heap_alloc_zero(count
* sizeof(GpPointF
));
1817 GpStatus status
= GenericError
;
1823 if(!pti
|| !tp
|| !ptcopy
){
1824 status
= OutOfMemory
;
1828 for(i
= 1; i
< count
; i
++){
1829 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1830 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1831 || !(types
[i
+ 2] & PathPointTypeBezier
)){
1832 ERR("Bad bezier points\n");
1839 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1841 /* If we are drawing caps, go through the points and adjust them accordingly,
1842 * and draw the caps. */
1844 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1845 case PathPointTypeBezier
:
1846 if(pen
->endcap
== LineCapArrowAnchor
)
1847 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1848 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1849 shorten_bezier_amt(&ptcopy
[count
- 4],
1850 pen
->width
* pen
->customend
->inset
, FALSE
);
1852 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1853 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1854 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1855 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1858 case PathPointTypeLine
:
1859 if(pen
->endcap
== LineCapArrowAnchor
)
1860 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1861 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1863 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1864 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1865 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1866 pen
->customend
->inset
* pen
->width
);
1868 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1869 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1874 ERR("Bad path last point\n");
1878 /* Find start of points */
1879 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1880 == PathPointTypeStart
); j
++);
1882 switch(types
[j
] & PathPointTypePathTypeMask
){
1883 case PathPointTypeBezier
:
1884 if(pen
->startcap
== LineCapArrowAnchor
)
1885 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1886 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1887 shorten_bezier_amt(&ptcopy
[j
- 1],
1888 pen
->width
* pen
->customstart
->inset
, TRUE
);
1890 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1891 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1892 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1893 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1896 case PathPointTypeLine
:
1897 if(pen
->startcap
== LineCapArrowAnchor
)
1898 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1899 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1901 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1902 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1903 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1904 pen
->customstart
->inset
* pen
->width
);
1906 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1907 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1912 ERR("Bad path points\n");
1917 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptcopy
, count
);
1919 round_points(pti
, ptcopy
, count
);
1921 for(i
= 0; i
< count
; i
++){
1922 tp
[i
] = convert_path_point_type(types
[i
]);
1925 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1937 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1941 BeginPath(graphics
->hdc
);
1942 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1943 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1944 EndPath(graphics
->hdc
);
1948 typedef enum GraphicsContainerType
{
1951 } GraphicsContainerType
;
1953 typedef struct _GraphicsContainerItem
{
1955 GraphicsContainer contid
;
1956 GraphicsContainerType type
;
1958 SmoothingMode smoothing
;
1959 CompositingQuality compqual
;
1960 InterpolationMode interpolation
;
1961 CompositingMode compmode
;
1962 TextRenderingHint texthint
;
1965 PixelOffsetMode pixeloffset
;
1967 GpMatrix worldtrans
;
1969 INT origin_x
, origin_y
;
1970 } GraphicsContainerItem
;
1972 static GpStatus
init_container(GraphicsContainerItem
** container
,
1973 GDIPCONST GpGraphics
* graphics
, GraphicsContainerType type
){
1976 *container
= heap_alloc_zero(sizeof(GraphicsContainerItem
));
1980 (*container
)->contid
= graphics
->contid
+ 1;
1981 (*container
)->type
= type
;
1983 (*container
)->smoothing
= graphics
->smoothing
;
1984 (*container
)->compqual
= graphics
->compqual
;
1985 (*container
)->interpolation
= graphics
->interpolation
;
1986 (*container
)->compmode
= graphics
->compmode
;
1987 (*container
)->texthint
= graphics
->texthint
;
1988 (*container
)->scale
= graphics
->scale
;
1989 (*container
)->unit
= graphics
->unit
;
1990 (*container
)->textcontrast
= graphics
->textcontrast
;
1991 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1992 (*container
)->origin_x
= graphics
->origin_x
;
1993 (*container
)->origin_y
= graphics
->origin_y
;
1994 (*container
)->worldtrans
= graphics
->worldtrans
;
1996 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1998 heap_free(*container
);
2006 static void delete_container(GraphicsContainerItem
* container
)
2008 GdipDeleteRegion(container
->clip
);
2009 heap_free(container
);
2012 static GpStatus
restore_container(GpGraphics
* graphics
,
2013 GDIPCONST GraphicsContainerItem
* container
){
2017 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2018 if(sts
!= Ok
) return sts
;
2020 graphics
->worldtrans
= container
->worldtrans
;
2022 GdipDeleteRegion(graphics
->clip
);
2023 graphics
->clip
= newClip
;
2025 graphics
->contid
= container
->contid
- 1;
2027 graphics
->smoothing
= container
->smoothing
;
2028 graphics
->compqual
= container
->compqual
;
2029 graphics
->interpolation
= container
->interpolation
;
2030 graphics
->compmode
= container
->compmode
;
2031 graphics
->texthint
= container
->texthint
;
2032 graphics
->scale
= container
->scale
;
2033 graphics
->unit
= container
->unit
;
2034 graphics
->textcontrast
= container
->textcontrast
;
2035 graphics
->pixeloffset
= container
->pixeloffset
;
2036 graphics
->origin_x
= container
->origin_x
;
2037 graphics
->origin_y
= container
->origin_y
;
2042 static GpStatus
get_graphics_device_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2048 if(graphics
->hwnd
) {
2049 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2050 return GenericError
;
2052 rect
->X
= wnd_rect
.left
;
2053 rect
->Y
= wnd_rect
.top
;
2054 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2055 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2056 }else if (graphics
->image
){
2057 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2058 if (stat
== Ok
&& unit
!= UnitPixel
)
2059 FIXME("need to convert from unit %i\n", unit
);
2060 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2067 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2068 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2070 rect
->Width
= bmp
.bmWidth
;
2071 rect
->Height
= bmp
.bmHeight
;
2082 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2083 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2089 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2091 GpStatus stat
= get_graphics_device_bounds(graphics
, rect
);
2093 if (stat
== Ok
&& graphics
->hdc
)
2095 GpPointF points
[4], min_point
, max_point
;
2098 points
[0].X
= points
[2].X
= rect
->X
;
2099 points
[0].Y
= points
[1].Y
= rect
->Y
;
2100 points
[1].X
= points
[3].X
= rect
->X
+ rect
->Width
;
2101 points
[2].Y
= points
[3].Y
= rect
->Y
+ rect
->Height
;
2103 gdip_transform_points(graphics
, CoordinateSpaceDevice
, WineCoordinateSpaceGdiDevice
, points
, 4);
2105 min_point
= max_point
= points
[0];
2109 if (points
[i
].X
< min_point
.X
) min_point
.X
= points
[i
].X
;
2110 if (points
[i
].Y
< min_point
.Y
) min_point
.Y
= points
[i
].Y
;
2111 if (points
[i
].X
> max_point
.X
) max_point
.X
= points
[i
].X
;
2112 if (points
[i
].Y
> max_point
.Y
) max_point
.Y
= points
[i
].Y
;
2115 rect
->X
= min_point
.X
;
2116 rect
->Y
= min_point
.Y
;
2117 rect
->Width
= max_point
.X
- min_point
.X
;
2118 rect
->Height
= max_point
.Y
- min_point
.Y
;
2124 /* on success, rgn will contain the region of the graphics object which
2125 * is visible after clipping has been applied */
2126 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2132 /* Ignore graphics image bounds for metafiles */
2133 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2134 return GdipCombineRegionRegion(rgn
, graphics
->clip
, CombineModeReplace
);
2136 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2139 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2142 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2145 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2148 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2151 GdipDeleteRegion(tmp
);
2155 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2159 if (font
->unit
== UnitPixel
)
2161 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2165 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2166 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2168 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2171 lf
->lfHeight
= -(height
+ 0.5);
2173 lf
->lfEscapement
= 0;
2174 lf
->lfOrientation
= 0;
2175 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2176 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2177 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2178 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2179 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2180 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2181 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2182 lf
->lfQuality
= DEFAULT_QUALITY
;
2183 lf
->lfPitchAndFamily
= 0;
2184 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2187 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2188 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2189 GDIPCONST GpMatrix
*matrix
)
2191 HDC hdc
= CreateCompatibleDC(0);
2193 REAL angle
, rel_width
, rel_height
, font_height
;
2195 HFONT unscaled_font
;
2196 TEXTMETRICW textmet
;
2198 if (font
->unit
== UnitPixel
|| font
->unit
== UnitWorld
)
2199 font_height
= font
->emSize
;
2202 REAL unit_scale
, res
;
2204 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2205 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2207 font_height
= font
->emSize
* unit_scale
;
2218 GpMatrix xform
= *matrix
;
2219 GdipTransformMatrixPoints(&xform
, pt
, 3);
2222 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
2223 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2224 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2225 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2226 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2227 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2229 get_log_fontW(font
, graphics
, &lfw
);
2230 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2231 unscaled_font
= CreateFontIndirectW(&lfw
);
2233 SelectObject(hdc
, unscaled_font
);
2234 GetTextMetricsW(hdc
, &textmet
);
2236 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2237 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2239 *hfont
= CreateFontIndirectW(&lfw
);
2242 DeleteObject(unscaled_font
);
2245 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2247 TRACE("(%p, %p)\n", hdc
, graphics
);
2249 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2252 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2258 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2261 FIXME("Don't know how to handle parameter hDevice\n");
2266 if(graphics
== NULL
)
2267 return InvalidParameter
;
2269 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2270 if(!*graphics
) return OutOfMemory
;
2272 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2274 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2275 heap_free(*graphics
);
2279 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2280 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2281 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2283 (*graphics
)->alpha_hdc
= 1;
2286 (*graphics
)->hdc
= hdc
;
2287 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2288 (*graphics
)->owndc
= FALSE
;
2289 (*graphics
)->smoothing
= SmoothingModeDefault
;
2290 (*graphics
)->compqual
= CompositingQualityDefault
;
2291 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2292 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2293 (*graphics
)->compmode
= CompositingModeSourceOver
;
2294 (*graphics
)->unit
= UnitDisplay
;
2295 (*graphics
)->scale
= 1.0;
2296 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2297 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2298 (*graphics
)->busy
= FALSE
;
2299 (*graphics
)->textcontrast
= 4;
2300 list_init(&(*graphics
)->containers
);
2301 (*graphics
)->contid
= 0;
2303 TRACE("<-- %p\n", *graphics
);
2308 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2312 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2313 if(!*graphics
) return OutOfMemory
;
2315 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2317 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2318 heap_free(*graphics
);
2322 (*graphics
)->hdc
= NULL
;
2323 (*graphics
)->hwnd
= NULL
;
2324 (*graphics
)->owndc
= FALSE
;
2325 (*graphics
)->image
= image
;
2326 /* We have to store the image type here because the image may be freed
2327 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2328 (*graphics
)->image_type
= image
->type
;
2329 (*graphics
)->smoothing
= SmoothingModeDefault
;
2330 (*graphics
)->compqual
= CompositingQualityDefault
;
2331 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2332 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2333 (*graphics
)->compmode
= CompositingModeSourceOver
;
2334 (*graphics
)->unit
= UnitDisplay
;
2335 (*graphics
)->scale
= 1.0;
2336 (*graphics
)->xres
= image
->xres
;
2337 (*graphics
)->yres
= image
->yres
;
2338 (*graphics
)->busy
= FALSE
;
2339 (*graphics
)->textcontrast
= 4;
2340 list_init(&(*graphics
)->containers
);
2341 (*graphics
)->contid
= 0;
2343 TRACE("<-- %p\n", *graphics
);
2348 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2353 TRACE("(%p, %p)\n", hwnd
, graphics
);
2357 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2359 ReleaseDC(hwnd
, hdc
);
2363 (*graphics
)->hwnd
= hwnd
;
2364 (*graphics
)->owndc
= TRUE
;
2369 /* FIXME: no icm handling */
2370 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2372 TRACE("(%p, %p)\n", hwnd
, graphics
);
2374 return GdipCreateFromHWND(hwnd
, graphics
);
2377 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2378 UINT access
, IStream
**stream
)
2383 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2385 if(!stream
|| !filename
)
2386 return InvalidParameter
;
2388 if(access
& GENERIC_WRITE
)
2389 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2390 else if(access
& GENERIC_READ
)
2391 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2393 return InvalidParameter
;
2395 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2397 return hresult_to_status(ret
);
2400 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2402 GraphicsContainerItem
*cont
, *next
;
2404 TRACE("(%p)\n", graphics
);
2406 if(!graphics
) return InvalidParameter
;
2407 if(graphics
->busy
) return ObjectBusy
;
2409 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2411 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2417 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2419 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2420 list_remove(&cont
->entry
);
2421 delete_container(cont
);
2424 GdipDeleteRegion(graphics
->clip
);
2426 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2427 * do otherwise, but we can't have that in the test suite because it means
2428 * accessing freed memory. */
2429 graphics
->busy
= TRUE
;
2431 heap_free(graphics
);
2436 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2437 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2442 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2443 width
, height
, startAngle
, sweepAngle
);
2445 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2446 return InvalidParameter
;
2451 status
= GdipCreatePath(FillModeAlternate
, &path
);
2452 if (status
!= Ok
) return status
;
2454 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2456 status
= GdipDrawPath(graphics
, pen
, path
);
2458 GdipDeletePath(path
);
2462 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2463 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2465 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2466 width
, height
, startAngle
, sweepAngle
);
2468 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2471 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2472 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2476 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2477 x2
, y2
, x3
, y3
, x4
, y4
);
2479 if(!graphics
|| !pen
)
2480 return InvalidParameter
;
2493 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2496 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2497 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2499 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2500 x2
, y2
, x3
, y3
, x4
, y4
);
2502 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2505 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2506 GDIPCONST GpPointF
*points
, INT count
)
2511 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2513 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2514 return InvalidParameter
;
2519 status
= GdipCreatePath(FillModeAlternate
, &path
);
2520 if (status
!= Ok
) return status
;
2522 status
= GdipAddPathBeziers(path
, points
, count
);
2524 status
= GdipDrawPath(graphics
, pen
, path
);
2526 GdipDeletePath(path
);
2530 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2531 GDIPCONST GpPoint
*points
, INT count
)
2537 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2539 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2540 return InvalidParameter
;
2545 pts
= heap_alloc_zero(sizeof(GpPointF
) * count
);
2549 for(i
= 0; i
< count
; i
++){
2550 pts
[i
].X
= (REAL
)points
[i
].X
;
2551 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2554 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2561 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2562 GDIPCONST GpPointF
*points
, INT count
)
2564 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2566 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2569 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2570 GDIPCONST GpPoint
*points
, INT count
)
2572 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2574 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2577 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2578 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2583 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2585 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2586 return InvalidParameter
;
2591 status
= GdipCreatePath(FillModeAlternate
, &path
);
2592 if (status
!= Ok
) return status
;
2594 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2596 status
= GdipDrawPath(graphics
, pen
, path
);
2598 GdipDeletePath(path
);
2603 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2604 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2610 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2612 if(!points
|| count
<= 0)
2613 return InvalidParameter
;
2615 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2619 for(i
= 0; i
< count
; i
++){
2620 ptf
[i
].X
= (REAL
)points
[i
].X
;
2621 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2624 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2631 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2632 GDIPCONST GpPointF
*points
, INT count
)
2634 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2636 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2639 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2640 GDIPCONST GpPoint
*points
, INT count
)
2646 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2649 return InvalidParameter
;
2651 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2655 for(i
= 0; i
< count
; i
++){
2656 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2657 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2660 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2666 /* Approximates cardinal spline with Bezier curves. */
2667 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2668 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2673 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2675 if(!graphics
|| !pen
)
2676 return InvalidParameter
;
2682 return InvalidParameter
;
2684 status
= GdipCreatePath(FillModeAlternate
, &path
);
2685 if (status
!= Ok
) return status
;
2687 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2689 status
= GdipDrawPath(graphics
, pen
, path
);
2691 GdipDeletePath(path
);
2695 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2696 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2702 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2705 return InvalidParameter
;
2707 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2711 for(i
= 0; i
< count
; i
++){
2712 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2713 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2716 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2722 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2723 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2726 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2728 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2729 return InvalidParameter
;
2732 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2735 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2736 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2739 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2745 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2746 return InvalidParameter
;
2749 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2752 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2753 REAL y
, REAL width
, REAL height
)
2758 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2760 if(!graphics
|| !pen
)
2761 return InvalidParameter
;
2766 status
= GdipCreatePath(FillModeAlternate
, &path
);
2767 if (status
!= Ok
) return status
;
2769 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2771 status
= GdipDrawPath(graphics
, pen
, path
);
2773 GdipDeletePath(path
);
2777 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2778 INT y
, INT width
, INT height
)
2780 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2782 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2786 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2790 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2792 if(!graphics
|| !image
)
2793 return InvalidParameter
;
2795 GdipGetImageWidth(image
, &width
);
2796 GdipGetImageHeight(image
, &height
);
2798 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2799 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2802 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2805 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2807 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2810 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2811 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2815 REAL scale_x
, scale_y
, width
, height
;
2817 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2819 if (!graphics
|| !image
) return InvalidParameter
;
2821 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2822 scale_x
*= graphics
->xres
/ image
->xres
;
2823 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2824 scale_y
*= graphics
->yres
/ image
->yres
;
2825 width
= srcwidth
* scale_x
;
2826 height
= srcheight
* scale_y
;
2828 points
[0].X
= points
[2].X
= x
;
2829 points
[0].Y
= points
[1].Y
= y
;
2830 points
[1].X
= x
+ width
;
2831 points
[2].Y
= y
+ height
;
2833 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2834 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2837 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2838 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2841 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2844 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2845 GDIPCONST GpPointF
*dstpoints
, INT count
)
2849 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2852 return InvalidParameter
;
2854 GdipGetImageWidth(image
, &width
);
2855 GdipGetImageHeight(image
, &height
);
2857 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2858 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2861 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2862 GDIPCONST GpPoint
*dstpoints
, INT count
)
2866 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2868 if (count
!= 3 || !dstpoints
)
2869 return InvalidParameter
;
2871 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2872 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2873 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2874 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2875 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2876 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2878 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2881 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2882 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2884 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2888 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2889 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2890 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2891 DrawImageAbort callback
, VOID
* callbackData
)
2897 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2898 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2902 return NotImplemented
;
2904 if(!graphics
|| !image
|| !points
|| count
!= 3)
2905 return InvalidParameter
;
2907 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2908 debugstr_pointf(&points
[2]));
2910 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2912 return METAFILE_DrawImagePointsRect((GpMetafile
*)graphics
->image
,
2913 image
, points
, count
, srcx
, srcy
, srcwidth
, srcheight
,
2914 srcUnit
, imageAttributes
, callback
, callbackData
);
2917 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2919 /* Ensure source width/height is positive */
2922 GpPointF tmp
= ptf
[1];
2923 srcx
= srcx
+ srcwidth
;
2924 srcwidth
= -srcwidth
;
2925 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2926 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2933 GpPointF tmp
= ptf
[2];
2934 srcy
= srcy
+ srcheight
;
2935 srcheight
= -srcheight
;
2936 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
2937 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
2942 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2943 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2944 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
2946 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, ptf
, 4);
2947 round_points(pti
, ptf
, 4);
2949 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2950 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2952 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2953 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2954 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2955 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2956 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2958 if (image
->type
== ImageTypeBitmap
)
2960 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2961 BOOL do_resampling
= FALSE
;
2962 BOOL use_software
= FALSE
;
2964 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2965 graphics
->xres
, graphics
->yres
,
2966 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2967 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2968 imageAttributes
? imageAttributes
->outside_color
: 0);
2970 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2971 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2972 srcx
< 0 || srcy
< 0 ||
2973 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2974 do_resampling
= TRUE
;
2976 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
2977 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
2978 use_software
= TRUE
;
2983 GpRectF graphics_bounds
;
2985 int i
, x
, y
, src_stride
, dst_stride
;
2986 GpMatrix dst_to_src
;
2987 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2988 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
2989 BitmapData lockeddata
;
2990 InterpolationMode interpolation
= graphics
->interpolation
;
2991 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2992 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2993 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2994 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2996 if (!imageAttributes
)
2997 imageAttributes
= &defaultImageAttributes
;
2999 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3000 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3003 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3004 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3005 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3006 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3009 stat
= get_graphics_device_bounds(graphics
, &graphics_bounds
);
3010 if (stat
!= Ok
) return stat
;
3012 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
3013 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
3014 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
3015 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
3017 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
3019 if (IsRectEmpty(&dst_area
)) return Ok
;
3021 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3022 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3023 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3024 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3025 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3026 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3028 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
3030 stat
= GdipInvertMatrix(&dst_to_src
);
3031 if (stat
!= Ok
) return stat
;
3035 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3036 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3040 /* Make sure src_area is equal in size to dst_area. */
3041 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
3042 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
3043 src_area
.Width
= dst_area
.right
- dst_area
.left
;
3044 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
3047 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3049 src_data
= heap_alloc_zero(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3052 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3054 /* Read the bits we need from the source bitmap into a compatible buffer. */
3055 lockeddata
.Width
= src_area
.Width
;
3056 lockeddata
.Height
= src_area
.Height
;
3057 lockeddata
.Stride
= src_stride
;
3058 lockeddata
.Scan0
= src_data
;
3059 if (!do_resampling
&& bitmap
->format
== PixelFormat32bppPARGB
)
3060 lockeddata
.PixelFormat
= apply_image_attributes(imageAttributes
, NULL
, 0, 0, 0, ColorAdjustTypeBitmap
, bitmap
->format
);
3062 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3064 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3065 lockeddata
.PixelFormat
, &lockeddata
);
3068 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3072 heap_free(src_data
);
3076 apply_image_attributes(imageAttributes
, src_data
,
3077 src_area
.Width
, src_area
.Height
,
3078 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
3082 /* Transform the bits as needed to the destination. */
3083 dst_data
= dst_dyn_data
= heap_alloc_zero(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3086 heap_free(src_data
);
3090 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3092 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3094 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3095 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3096 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3097 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3099 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3101 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3103 GpPointF src_pointf
;
3106 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3107 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3109 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3111 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3112 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3113 imageAttributes
, interpolation
, offset_mode
);
3121 dst_data
= src_data
;
3122 dst_stride
= src_stride
;
3125 gdi_transform_acquire(graphics
);
3127 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3128 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
,
3129 lockeddata
.PixelFormat
);
3131 gdi_transform_release(graphics
);
3133 heap_free(src_data
);
3135 heap_free(dst_dyn_data
);
3142 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3143 HBITMAP hbitmap
, old_hbm
=NULL
;
3147 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3148 bitmap
->format
== PixelFormat24bppRGB
||
3149 bitmap
->format
== PixelFormat32bppRGB
||
3150 bitmap
->format
== PixelFormat32bppPARGB
))
3152 BITMAPINFOHEADER bih
;
3154 PixelFormat dst_format
;
3156 /* we can't draw a bitmap of this format directly */
3157 hdc
= CreateCompatibleDC(0);
3161 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3162 bih
.biWidth
= bitmap
->width
;
3163 bih
.biHeight
= -bitmap
->height
;
3165 bih
.biBitCount
= 32;
3166 bih
.biCompression
= BI_RGB
;
3167 bih
.biSizeImage
= 0;
3168 bih
.biXPelsPerMeter
= 0;
3169 bih
.biYPelsPerMeter
= 0;
3171 bih
.biClrImportant
= 0;
3173 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3174 (void**)&temp_bits
, NULL
, 0);
3176 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3177 dst_format
= PixelFormat32bppPARGB
;
3179 dst_format
= PixelFormat32bppRGB
;
3181 convert_pixels(bitmap
->width
, bitmap
->height
,
3182 bitmap
->width
*4, temp_bits
, dst_format
,
3183 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3184 bitmap
->image
.palette
);
3188 if (bitmap
->hbitmap
)
3189 hbitmap
= bitmap
->hbitmap
;
3192 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3197 temp_hdc
= (hdc
== 0);
3202 if (!hdc
) hdc
= CreateCompatibleDC(0);
3203 old_hbm
= SelectObject(hdc
, hbitmap
);
3206 save_state
= SaveDC(graphics
->hdc
);
3208 stat
= get_clip_hrgn(graphics
, &hrgn
);
3210 if (stat
== Ok
&& hrgn
)
3212 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3216 gdi_transform_acquire(graphics
);
3218 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3220 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3221 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3225 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3226 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3229 gdi_transform_release(graphics
);
3231 RestoreDC(graphics
->hdc
, save_state
);
3235 SelectObject(hdc
, old_hbm
);
3240 DeleteObject(hbitmap
);
3243 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3249 rc
.Width
= srcwidth
;
3250 rc
.Height
= srcheight
;
3252 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3253 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3257 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3258 return InvalidParameter
;
3264 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3265 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3266 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3267 DrawImageAbort callback
, VOID
* callbackData
)
3269 GpPointF pointsF
[3];
3272 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3273 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3276 if(!points
|| count
!=3)
3277 return InvalidParameter
;
3279 for(i
= 0; i
< count
; i
++){
3280 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3281 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3284 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3285 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3286 callback
, callbackData
);
3289 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3290 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3291 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3292 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3293 VOID
* callbackData
)
3297 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3298 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3299 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3303 points
[1].X
= dstx
+ dstwidth
;
3306 points
[2].Y
= dsty
+ dstheight
;
3308 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3309 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3312 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3313 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3314 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3315 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3316 VOID
* callbackData
)
3320 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3321 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3322 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3326 points
[1].X
= dstx
+ dstwidth
;
3329 points
[2].Y
= dsty
+ dstheight
;
3331 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3332 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3335 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3336 REAL x
, REAL y
, REAL width
, REAL height
)
3342 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3344 if(!graphics
|| !image
)
3345 return InvalidParameter
;
3347 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3351 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3352 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3353 unit
, NULL
, NULL
, NULL
);
3356 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3357 INT x
, INT y
, INT width
, INT height
)
3359 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3361 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3364 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3365 REAL y1
, REAL x2
, REAL y2
)
3369 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3372 return InvalidParameter
;
3374 if (pen
->unit
== UnitPixel
&& pen
->width
<= 0.0)
3381 return GdipDrawLines(graphics
, pen
, pt
, 2);
3384 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3385 INT y1
, INT x2
, INT y2
)
3387 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3389 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3392 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3393 GpPointF
*points
, INT count
)
3398 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3400 if(!pen
|| !graphics
|| (count
< 2))
3401 return InvalidParameter
;
3406 status
= GdipCreatePath(FillModeAlternate
, &path
);
3407 if (status
!= Ok
) return status
;
3409 status
= GdipAddPathLine2(path
, points
, count
);
3411 status
= GdipDrawPath(graphics
, pen
, path
);
3413 GdipDeletePath(path
);
3417 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3418 GpPoint
*points
, INT count
)
3424 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3426 ptf
= heap_alloc_zero(count
* sizeof(GpPointF
));
3427 if(!ptf
) return OutOfMemory
;
3429 for(i
= 0; i
< count
; i
++){
3430 ptf
[i
].X
= (REAL
) points
[i
].X
;
3431 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3434 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3440 static GpStatus
GDI32_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3446 save_state
= prepare_dc(graphics
, pen
);
3448 retval
= get_clip_hrgn(graphics
, &hrgn
);
3454 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3456 gdi_transform_acquire(graphics
);
3458 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3459 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3461 gdi_transform_release(graphics
);
3464 restore_dc(graphics
, save_state
);
3470 static GpStatus
SOFTWARE_GdipDrawThinPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3474 GpMatrix
* transform
;
3475 GpRectF gp_bound_rect
;
3476 GpRect gp_output_area
;
3478 INT output_height
, output_width
;
3479 DWORD
*output_bits
, *brush_bits
=NULL
;
3481 static const BYTE static_dash_pattern
[] = {1,1,1,0,1,0,1,0};
3482 const BYTE
*dash_pattern
;
3483 INT dash_pattern_size
;
3484 BYTE
*dyn_dash_pattern
= NULL
;
3486 stat
= GdipClonePath(path
, &flat_path
);
3491 stat
= GdipCreateMatrix(&transform
);
3495 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3496 CoordinateSpaceWorld
, transform
);
3499 stat
= GdipFlattenPath(flat_path
, transform
, 1.0);
3501 GdipDeleteMatrix(transform
);
3504 /* estimate the output size in pixels, can be larger than necessary */
3507 output_area
.left
= floorf(flat_path
->pathdata
.Points
[0].X
);
3508 output_area
.right
= ceilf(flat_path
->pathdata
.Points
[0].X
);
3509 output_area
.top
= floorf(flat_path
->pathdata
.Points
[0].Y
);
3510 output_area
.bottom
= ceilf(flat_path
->pathdata
.Points
[0].Y
);
3512 for (i
=1; i
<flat_path
->pathdata
.Count
; i
++)
3515 x
= flat_path
->pathdata
.Points
[i
].X
;
3516 y
= flat_path
->pathdata
.Points
[i
].Y
;
3518 if (floorf(x
) < output_area
.left
) output_area
.left
= floorf(x
);
3519 if (floorf(y
) < output_area
.top
) output_area
.top
= floorf(y
);
3520 if (ceilf(x
) > output_area
.right
) output_area
.right
= ceilf(x
);
3521 if (ceilf(y
) > output_area
.bottom
) output_area
.bottom
= ceilf(y
);
3524 stat
= get_graphics_device_bounds(graphics
, &gp_bound_rect
);
3529 output_area
.left
= max(output_area
.left
, floorf(gp_bound_rect
.X
));
3530 output_area
.top
= max(output_area
.top
, floorf(gp_bound_rect
.Y
));
3531 output_area
.right
= min(output_area
.right
, ceilf(gp_bound_rect
.X
+ gp_bound_rect
.Width
));
3532 output_area
.bottom
= min(output_area
.bottom
, ceilf(gp_bound_rect
.Y
+ gp_bound_rect
.Height
));
3534 output_width
= output_area
.right
- output_area
.left
+ 1;
3535 output_height
= output_area
.bottom
- output_area
.top
+ 1;
3537 if (output_width
<= 0 || output_height
<= 0)
3539 GdipDeletePath(flat_path
);
3543 gp_output_area
.X
= output_area
.left
;
3544 gp_output_area
.Y
= output_area
.top
;
3545 gp_output_area
.Width
= output_width
;
3546 gp_output_area
.Height
= output_height
;
3548 output_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3555 if (pen
->brush
->bt
!= BrushTypeSolidColor
)
3557 /* allocate and draw brush output */
3558 brush_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3562 stat
= brush_fill_pixels(graphics
, pen
->brush
, brush_bits
,
3563 &gp_output_area
, output_width
);
3571 /* convert dash pattern to bool array */
3574 case DashStyleCustom
:
3576 dash_pattern_size
= 0;
3578 for (i
=0; i
< pen
->numdashes
; i
++)
3579 dash_pattern_size
+= gdip_round(pen
->dashes
[i
]);
3581 if (dash_pattern_size
!= 0)
3583 dash_pattern
= dyn_dash_pattern
= heap_alloc(dash_pattern_size
);
3585 if (dyn_dash_pattern
)
3588 for (i
=0; i
< pen
->numdashes
; i
++)
3591 for (k
=0; k
< gdip_round(pen
->dashes
[i
]); k
++)
3592 dyn_dash_pattern
[j
++] = (i
&1)^1;
3600 /* else fall through */
3602 case DashStyleSolid
:
3604 dash_pattern
= static_dash_pattern
;
3605 dash_pattern_size
= 1;
3608 dash_pattern
= static_dash_pattern
;
3609 dash_pattern_size
= 4;
3612 dash_pattern
= &static_dash_pattern
[4];
3613 dash_pattern_size
= 2;
3615 case DashStyleDashDot
:
3616 dash_pattern
= static_dash_pattern
;
3617 dash_pattern_size
= 6;
3619 case DashStyleDashDotDot
:
3620 dash_pattern
= static_dash_pattern
;
3621 dash_pattern_size
= 8;
3629 GpPointF subpath_start
= flat_path
->pathdata
.Points
[0];
3630 INT prev_x
= INT_MAX
, prev_y
= INT_MAX
;
3631 int dash_pos
= dash_pattern_size
- 1;
3633 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
3636 GpPointF start_point
, end_point
;
3637 GpPoint start_pointi
, end_pointi
;
3639 type
= flat_path
->pathdata
.Types
[i
];
3640 if (i
+1 < flat_path
->pathdata
.Count
)
3641 type2
= flat_path
->pathdata
.Types
[i
+1];
3643 type2
= PathPointTypeStart
;
3645 start_point
= flat_path
->pathdata
.Points
[i
];
3647 if ((type
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3648 subpath_start
= start_point
;
3650 if ((type
& PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
3651 end_point
= subpath_start
;
3652 else if ((type2
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3655 end_point
= flat_path
->pathdata
.Points
[i
+1];
3657 start_pointi
.X
= floorf(start_point
.X
);
3658 start_pointi
.Y
= floorf(start_point
.Y
);
3659 end_pointi
.X
= floorf(end_point
.X
);
3660 end_pointi
.Y
= floorf(end_point
.Y
);
3662 if(start_pointi
.X
== end_pointi
.X
&& start_pointi
.Y
== end_pointi
.Y
)
3665 /* draw line segment */
3666 if (abs(start_pointi
.Y
- end_pointi
.Y
) > abs(start_pointi
.X
- end_pointi
.X
))
3668 INT x
, y
, start_y
, end_y
, step
;
3670 if (start_pointi
.Y
< end_pointi
.Y
)
3673 start_y
= ceilf(start_point
.Y
) - output_area
.top
;
3674 end_y
= end_pointi
.Y
- output_area
.top
;
3679 start_y
= start_point
.Y
- output_area
.top
;
3680 end_y
= ceilf(end_point
.Y
) - output_area
.top
;
3683 for (y
=start_y
; y
!= (end_y
+step
); y
+=step
)
3685 x
= gdip_round( start_point
.X
+
3686 (end_point
.X
- start_point
.X
) * (y
+ output_area
.top
- start_point
.Y
) / (end_point
.Y
- start_point
.Y
) )
3689 if (x
== prev_x
&& y
== prev_y
)
3694 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3696 if (!dash_pattern
[dash_pos
])
3699 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3703 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3705 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3710 INT x
, y
, start_x
, end_x
, step
;
3712 if (start_pointi
.X
< end_pointi
.X
)
3715 start_x
= ceilf(start_point
.X
) - output_area
.left
;
3716 end_x
= end_pointi
.X
- output_area
.left
;
3721 start_x
= start_point
.X
- output_area
.left
;
3722 end_x
= ceilf(end_point
.X
) - output_area
.left
;
3725 for (x
=start_x
; x
!= (end_x
+step
); x
+=step
)
3727 y
= gdip_round( start_point
.Y
+
3728 (end_point
.Y
- start_point
.Y
) * (x
+ output_area
.left
- start_point
.X
) / (end_point
.X
- start_point
.X
) )
3731 if (x
== prev_x
&& y
== prev_y
)
3736 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3738 if (!dash_pattern
[dash_pos
])
3741 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3745 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3747 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3753 /* draw output image */
3756 gdi_transform_acquire(graphics
);
3758 stat
= alpha_blend_pixels(graphics
, output_area
.left
, output_area
.top
,
3759 (BYTE
*)output_bits
, output_width
, output_height
, output_width
* 4,
3760 PixelFormat32bppARGB
);
3762 gdi_transform_release(graphics
);
3765 heap_free(brush_bits
);
3766 heap_free(dyn_dash_pattern
);
3767 heap_free(output_bits
);
3770 GdipDeletePath(flat_path
);
3775 static GpStatus
SOFTWARE_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3779 GpMatrix
*transform
=NULL
;
3782 /* Check if the final pen thickness in pixels is too thin. */
3783 if (pen
->unit
== UnitPixel
)
3785 if (pen
->width
< 1.415)
3786 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3790 GpPointF points
[3] = {{0,0}, {1,0}, {0,1}};
3792 points
[1].X
= pen
->width
;
3793 points
[2].Y
= pen
->width
;
3795 stat
= gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
,
3796 CoordinateSpaceWorld
, points
, 3);
3801 if (((points
[1].X
-points
[0].X
)*(points
[1].X
-points
[0].X
) +
3802 (points
[1].Y
-points
[0].Y
)*(points
[1].Y
-points
[0].Y
) < 2.0001) &&
3803 ((points
[2].X
-points
[0].X
)*(points
[2].X
-points
[0].X
) +
3804 (points
[2].Y
-points
[0].Y
)*(points
[2].Y
-points
[0].Y
) < 2.0001))
3805 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3808 stat
= GdipClonePath(path
, &wide_path
);
3813 if (pen
->unit
== UnitPixel
)
3815 /* We have to transform this to device coordinates to get the widths right. */
3816 stat
= GdipCreateMatrix(&transform
);
3819 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3820 CoordinateSpaceWorld
, transform
);
3824 /* Set flatness based on the final coordinate space */
3827 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
3828 CoordinateSpaceWorld
, &t
);
3833 flatness
= 1.0/sqrt(fmax(
3834 t
.matrix
[0] * t
.matrix
[0] + t
.matrix
[1] * t
.matrix
[1],
3835 t
.matrix
[2] * t
.matrix
[2] + t
.matrix
[3] * t
.matrix
[3]));
3839 stat
= GdipWidenPath(wide_path
, pen
, transform
, flatness
);
3841 if (pen
->unit
== UnitPixel
)
3843 /* Transform the path back to world coordinates */
3845 stat
= GdipInvertMatrix(transform
);
3848 stat
= GdipTransformPath(wide_path
, transform
);
3851 /* Actually draw the path */
3853 stat
= GdipFillPath(graphics
, pen
->brush
, wide_path
);
3855 GdipDeleteMatrix(transform
);
3857 GdipDeletePath(wide_path
);
3862 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3866 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3868 if(!pen
|| !graphics
)
3869 return InvalidParameter
;
3874 if (path
->pathdata
.Count
== 0)
3877 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
3878 retval
= METAFILE_DrawPath((GpMetafile
*)graphics
->image
, pen
, path
);
3879 else if (!graphics
->hdc
|| graphics
->alpha_hdc
|| !brush_can_fill_path(pen
->brush
, FALSE
))
3880 retval
= SOFTWARE_GdipDrawPath(graphics
, pen
, path
);
3882 retval
= GDI32_GdipDrawPath(graphics
, pen
, path
);
3887 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3888 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3893 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3894 width
, height
, startAngle
, sweepAngle
);
3896 if(!graphics
|| !pen
)
3897 return InvalidParameter
;
3902 status
= GdipCreatePath(FillModeAlternate
, &path
);
3903 if (status
!= Ok
) return status
;
3905 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3907 status
= GdipDrawPath(graphics
, pen
, path
);
3909 GdipDeletePath(path
);
3913 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3914 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3916 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3917 width
, height
, startAngle
, sweepAngle
);
3919 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3922 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3923 REAL y
, REAL width
, REAL height
)
3928 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3930 if(!pen
|| !graphics
)
3931 return InvalidParameter
;
3936 status
= GdipCreatePath(FillModeAlternate
, &path
);
3937 if (status
!= Ok
) return status
;
3939 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3941 status
= GdipDrawPath(graphics
, pen
, path
);
3943 GdipDeletePath(path
);
3947 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3948 INT y
, INT width
, INT height
)
3950 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3952 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3955 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3956 GDIPCONST GpRectF
* rects
, INT count
)
3961 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3963 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3964 return InvalidParameter
;
3969 status
= GdipCreatePath(FillModeAlternate
, &path
);
3970 if (status
!= Ok
) return status
;
3972 status
= GdipAddPathRectangles(path
, rects
, count
);
3974 status
= GdipDrawPath(graphics
, pen
, path
);
3976 GdipDeletePath(path
);
3980 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3981 GDIPCONST GpRect
* rects
, INT count
)
3987 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3989 if(!rects
|| count
<=0)
3990 return InvalidParameter
;
3992 rectsF
= heap_alloc_zero(sizeof(GpRectF
) * count
);
3996 for(i
= 0;i
< count
;i
++){
3997 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3998 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3999 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
4000 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4003 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
4009 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
4010 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
4015 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
4016 count
, tension
, fill
);
4018 if(!graphics
|| !brush
|| !points
)
4019 return InvalidParameter
;
4024 if(count
== 1) /* Do nothing */
4027 status
= GdipCreatePath(fill
, &path
);
4028 if (status
!= Ok
) return status
;
4030 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
4032 status
= GdipFillPath(graphics
, brush
, path
);
4034 GdipDeletePath(path
);
4038 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
4039 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
4045 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
4046 count
, tension
, fill
);
4048 if(!points
|| count
== 0)
4049 return InvalidParameter
;
4051 if(count
== 1) /* Do nothing */
4054 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
4058 for(i
= 0;i
< count
;i
++){
4059 ptf
[i
].X
= (REAL
)points
[i
].X
;
4060 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4063 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
4070 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
4071 GDIPCONST GpPointF
*points
, INT count
)
4073 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4074 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
4075 0.5f
, FillModeAlternate
);
4078 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
4079 GDIPCONST GpPoint
*points
, INT count
)
4081 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4082 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
4083 0.5f
, FillModeAlternate
);
4086 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4087 REAL y
, REAL width
, REAL height
)
4092 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4094 if(!graphics
|| !brush
)
4095 return InvalidParameter
;
4100 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4104 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
4107 stat
= GdipFillPath(graphics
, brush
, path
);
4109 GdipDeletePath(path
);
4115 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4116 INT y
, INT width
, INT height
)
4118 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4120 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
4123 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4129 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4130 return NotImplemented
;
4132 save_state
= SaveDC(graphics
->hdc
);
4133 EndPath(graphics
->hdc
);
4134 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
4137 retval
= get_clip_hrgn(graphics
, &hrgn
);
4143 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4145 gdi_transform_acquire(graphics
);
4147 BeginPath(graphics
->hdc
);
4148 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
4149 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
4153 EndPath(graphics
->hdc
);
4154 brush_fill_path(graphics
, brush
);
4157 gdi_transform_release(graphics
);
4160 RestoreDC(graphics
->hdc
, save_state
);
4166 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4171 if (!brush_can_fill_pixels(brush
))
4172 return NotImplemented
;
4174 /* FIXME: This could probably be done more efficiently without regions. */
4176 stat
= GdipCreateRegionPath(path
, &rgn
);
4180 stat
= GdipFillRegion(graphics
, brush
, rgn
);
4182 GdipDeleteRegion(rgn
);
4188 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4190 GpStatus stat
= NotImplemented
;
4192 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
4194 if(!brush
|| !graphics
|| !path
)
4195 return InvalidParameter
;
4200 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4201 return METAFILE_FillPath((GpMetafile
*)graphics
->image
, brush
, path
);
4203 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4204 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
4206 if (stat
== NotImplemented
)
4207 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
4209 if (stat
== NotImplemented
)
4211 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
4218 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4219 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4224 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
4225 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4227 if(!graphics
|| !brush
)
4228 return InvalidParameter
;
4233 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4237 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4240 stat
= GdipFillPath(graphics
, brush
, path
);
4242 GdipDeletePath(path
);
4248 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4249 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4251 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
4252 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4254 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4257 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
4258 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
4263 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4265 if(!graphics
|| !brush
|| !points
|| !count
)
4266 return InvalidParameter
;
4271 stat
= GdipCreatePath(fillMode
, &path
);
4275 stat
= GdipAddPathPolygon(path
, points
, count
);
4278 stat
= GdipFillPath(graphics
, brush
, path
);
4280 GdipDeletePath(path
);
4286 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4287 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4292 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4294 if(!graphics
|| !brush
|| !points
|| !count
)
4295 return InvalidParameter
;
4300 stat
= GdipCreatePath(fillMode
, &path
);
4304 stat
= GdipAddPathPolygonI(path
, points
, count
);
4307 stat
= GdipFillPath(graphics
, brush
, path
);
4309 GdipDeletePath(path
);
4315 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4316 GDIPCONST GpPointF
*points
, INT count
)
4318 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4320 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4323 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4324 GDIPCONST GpPoint
*points
, INT count
)
4326 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4328 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4331 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4332 REAL x
, REAL y
, REAL width
, REAL height
)
4336 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4341 rect
.Height
= height
;
4343 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4346 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4347 INT x
, INT y
, INT width
, INT height
)
4351 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4355 rect
.Width
= (REAL
)width
;
4356 rect
.Height
= (REAL
)height
;
4358 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4361 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4367 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4369 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
4370 return InvalidParameter
;
4372 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4374 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
4375 /* FIXME: Add gdi32 drawing. */
4379 status
= GdipCreatePath(FillModeAlternate
, &path
);
4380 if (status
!= Ok
) return status
;
4382 status
= GdipAddPathRectangles(path
, rects
, count
);
4384 status
= GdipFillPath(graphics
, brush
, path
);
4386 GdipDeletePath(path
);
4390 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4397 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4399 if(!rects
|| count
<= 0)
4400 return InvalidParameter
;
4402 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
4406 for(i
= 0; i
< count
; i
++){
4407 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4408 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4409 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
4410 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4413 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4419 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4427 if(!graphics
->hdc
|| !brush_can_fill_path(brush
, TRUE
))
4428 return NotImplemented
;
4430 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4434 save_state
= SaveDC(graphics
->hdc
);
4435 EndPath(graphics
->hdc
);
4437 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4442 status
= get_clip_hrgn(graphics
, &hrgn
);
4446 RestoreDC(graphics
->hdc
, save_state
);
4452 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4456 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4458 BeginPath(graphics
->hdc
);
4459 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4460 EndPath(graphics
->hdc
);
4462 brush_fill_path(graphics
, brush
);
4465 RestoreDC(graphics
->hdc
, save_state
);
4471 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4475 GpRegion
*temp_region
;
4476 GpMatrix world_to_device
;
4477 GpRectF graphics_bounds
;
4481 GpRect gp_bound_rect
;
4483 if (!brush_can_fill_pixels(brush
))
4484 return NotImplemented
;
4486 stat
= gdi_transform_acquire(graphics
);
4489 stat
= get_graphics_device_bounds(graphics
, &graphics_bounds
);
4492 stat
= GdipCloneRegion(region
, &temp_region
);
4496 stat
= get_graphics_transform(graphics
, WineCoordinateSpaceGdiDevice
,
4497 CoordinateSpaceWorld
, &world_to_device
);
4500 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4503 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4506 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4508 GdipDeleteRegion(temp_region
);
4511 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4513 DeleteObject(hregion
);
4514 gdi_transform_release(graphics
);
4520 gp_bound_rect
.X
= bound_rect
.left
;
4521 gp_bound_rect
.Y
= bound_rect
.top
;
4522 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4523 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4525 pixel_data
= heap_alloc_zero(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4531 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4532 &gp_bound_rect
, gp_bound_rect
.Width
);
4535 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4536 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4537 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
,
4538 PixelFormat32bppARGB
);
4540 heap_free(pixel_data
);
4543 DeleteObject(hregion
);
4546 gdi_transform_release(graphics
);
4551 /*****************************************************************************
4552 * GdipFillRegion [GDIPLUS.@]
4554 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4557 GpStatus stat
= NotImplemented
;
4559 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4561 if (!(graphics
&& brush
&& region
))
4562 return InvalidParameter
;
4567 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4568 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4570 if (stat
== NotImplemented
)
4571 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4573 if (stat
== NotImplemented
)
4575 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4582 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4584 TRACE("(%p,%u)\n", graphics
, intention
);
4587 return InvalidParameter
;
4592 /* We have no internal operation queue, so there's no need to clear it. */
4600 /*****************************************************************************
4601 * GdipGetClipBounds [GDIPLUS.@]
4603 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4608 TRACE("(%p, %p)\n", graphics
, rect
);
4611 return InvalidParameter
;
4616 status
= GdipCreateRegion(&clip
);
4617 if (status
!= Ok
) return status
;
4619 status
= GdipGetClip(graphics
, clip
);
4621 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4623 GdipDeleteRegion(clip
);
4627 /*****************************************************************************
4628 * GdipGetClipBoundsI [GDIPLUS.@]
4630 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4632 TRACE("(%p, %p)\n", graphics
, rect
);
4635 return InvalidParameter
;
4640 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4643 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4644 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4645 CompositingMode
*mode
)
4647 TRACE("(%p, %p)\n", graphics
, mode
);
4649 if(!graphics
|| !mode
)
4650 return InvalidParameter
;
4655 *mode
= graphics
->compmode
;
4660 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4661 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4662 CompositingQuality
*quality
)
4664 TRACE("(%p, %p)\n", graphics
, quality
);
4666 if(!graphics
|| !quality
)
4667 return InvalidParameter
;
4672 *quality
= graphics
->compqual
;
4677 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4678 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4679 InterpolationMode
*mode
)
4681 TRACE("(%p, %p)\n", graphics
, mode
);
4683 if(!graphics
|| !mode
)
4684 return InvalidParameter
;
4689 *mode
= graphics
->interpolation
;
4694 /* FIXME: Need to handle color depths less than 24bpp */
4695 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4697 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4699 if(!graphics
|| !argb
)
4700 return InvalidParameter
;
4708 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4710 TRACE("(%p, %p)\n", graphics
, scale
);
4712 if(!graphics
|| !scale
)
4713 return InvalidParameter
;
4718 *scale
= graphics
->scale
;
4723 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4725 TRACE("(%p, %p)\n", graphics
, unit
);
4727 if(!graphics
|| !unit
)
4728 return InvalidParameter
;
4733 *unit
= graphics
->unit
;
4738 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4739 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4742 TRACE("(%p, %p)\n", graphics
, mode
);
4744 if(!graphics
|| !mode
)
4745 return InvalidParameter
;
4750 *mode
= graphics
->pixeloffset
;
4755 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4756 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4758 TRACE("(%p, %p)\n", graphics
, mode
);
4760 if(!graphics
|| !mode
)
4761 return InvalidParameter
;
4766 *mode
= graphics
->smoothing
;
4771 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4773 TRACE("(%p, %p)\n", graphics
, contrast
);
4775 if(!graphics
|| !contrast
)
4776 return InvalidParameter
;
4778 *contrast
= graphics
->textcontrast
;
4783 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4784 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4785 TextRenderingHint
*hint
)
4787 TRACE("(%p, %p)\n", graphics
, hint
);
4789 if(!graphics
|| !hint
)
4790 return InvalidParameter
;
4795 *hint
= graphics
->texthint
;
4800 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4804 GpMatrix device_to_world
;
4806 TRACE("(%p, %p)\n", graphics
, rect
);
4808 if(!graphics
|| !rect
)
4809 return InvalidParameter
;
4814 /* intersect window and graphics clipping regions */
4815 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4818 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4821 /* transform to world coordinates */
4822 if((stat
= get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
)) != Ok
)
4825 if((stat
= GdipTransformRegion(clip_rgn
, &device_to_world
)) != Ok
)
4828 /* get bounds of the region */
4829 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4832 GdipDeleteRegion(clip_rgn
);
4837 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4842 TRACE("(%p, %p)\n", graphics
, rect
);
4844 if(!graphics
|| !rect
)
4845 return InvalidParameter
;
4847 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4849 rect
->X
= gdip_round(rectf
.X
);
4850 rect
->Y
= gdip_round(rectf
.Y
);
4851 rect
->Width
= gdip_round(rectf
.Width
);
4852 rect
->Height
= gdip_round(rectf
.Height
);
4858 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4860 TRACE("(%p, %p)\n", graphics
, matrix
);
4862 if(!graphics
|| !matrix
)
4863 return InvalidParameter
;
4868 *matrix
= graphics
->worldtrans
;
4872 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4878 TRACE("(%p, %x)\n", graphics
, color
);
4881 return InvalidParameter
;
4886 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4887 return METAFILE_GraphicsClear((GpMetafile
*)graphics
->image
, color
);
4889 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4892 if((stat
= GdipGetVisibleClipBounds(graphics
, &wnd_rect
)) != Ok
){
4893 GdipDeleteBrush((GpBrush
*)brush
);
4897 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4898 wnd_rect
.Width
, wnd_rect
.Height
);
4900 GdipDeleteBrush((GpBrush
*)brush
);
4905 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4907 TRACE("(%p, %p)\n", graphics
, res
);
4909 if(!graphics
|| !res
)
4910 return InvalidParameter
;
4912 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4915 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4921 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4923 if(!graphics
|| !result
)
4924 return InvalidParameter
;
4931 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4932 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4935 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4938 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4941 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4944 GdipDeleteRegion(rgn
);
4948 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4950 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4953 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4959 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4961 if(!graphics
|| !result
)
4962 return InvalidParameter
;
4969 pts
[1].X
= x
+ width
;
4970 pts
[1].Y
= y
+ height
;
4972 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4973 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4976 pts
[1].X
-= pts
[0].X
;
4977 pts
[1].Y
-= pts
[0].Y
;
4979 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4982 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4985 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4988 GdipDeleteRegion(rgn
);
4992 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4994 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4997 GpStatus
gdip_format_string(HDC hdc
,
4998 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4999 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
5000 gdip_format_string_callback callback
, void *user_data
)
5003 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
5004 nheight
, lineend
, lineno
= 0;
5006 StringAlignment halign
;
5009 HotkeyPrefix hkprefix
;
5010 INT
*hotkeyprefix_offsets
=NULL
;
5011 INT hotkeyprefix_count
=0;
5012 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
5013 BOOL seen_prefix
= FALSE
;
5015 if(length
== -1) length
= lstrlenW(string
);
5017 stringdup
= heap_alloc_zero((length
+ 1) * sizeof(WCHAR
));
5018 if(!stringdup
) return OutOfMemory
;
5021 format
= &default_drawstring_format
;
5023 nwidth
= rect
->Width
;
5024 nheight
= rect
->Height
;
5025 if (ignore_empty_clip
)
5027 if (!nwidth
) nwidth
= INT_MAX
;
5028 if (!nheight
) nheight
= INT_MAX
;
5031 hkprefix
= format
->hkprefix
;
5033 if (hkprefix
== HotkeyPrefixShow
)
5035 for (i
=0; i
<length
; i
++)
5037 if (string
[i
] == '&')
5038 hotkeyprefix_count
++;
5042 if (hotkeyprefix_count
)
5043 hotkeyprefix_offsets
= heap_alloc_zero(sizeof(INT
) * hotkeyprefix_count
);
5045 hotkeyprefix_count
= 0;
5047 for(i
= 0, j
= 0; i
< length
; i
++){
5048 /* FIXME: This makes the indexes passed to callback inaccurate. */
5049 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
5052 /* FIXME: tabs should be handled using tabstops from stringformat */
5053 if (string
[i
] == '\t')
5056 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
5057 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
5058 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
5064 seen_prefix
= FALSE
;
5066 stringdup
[j
] = string
[i
];
5072 halign
= format
->align
;
5074 while(sum
< length
){
5075 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
5076 nwidth
, &fit
, NULL
, &size
);
5082 for(lret
= 0; lret
< fit
; lret
++)
5083 if(*(stringdup
+ sum
+ lret
) == '\n')
5086 /* Line break code (may look strange, but it imitates windows). */
5088 lineend
= fit
= lret
; /* this is not an off-by-one error */
5089 else if(fit
< (length
- sum
)){
5090 if(*(stringdup
+ sum
+ fit
) == ' ')
5091 while(*(stringdup
+ sum
+ fit
) == ' ')
5094 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
5097 if(*(stringdup
+ sum
+ fit
) == '\t')
5106 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
5107 *(stringdup
+ sum
+ lineend
- 1) == '\t')
5113 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
5114 nwidth
, &j
, NULL
, &size
);
5116 bounds
.Width
= size
.cx
;
5118 if(height
+ size
.cy
> nheight
)
5120 if (format
->attr
& StringFormatFlagsLineLimit
)
5122 bounds
.Height
= nheight
- (height
+ size
.cy
);
5125 bounds
.Height
= size
.cy
;
5127 bounds
.Y
= rect
->Y
+ height
;
5131 case StringAlignmentNear
:
5135 case StringAlignmentCenter
:
5136 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
5138 case StringAlignmentFar
:
5139 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
5143 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
5144 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
5147 stat
= callback(hdc
, stringdup
, sum
, lineend
,
5148 font
, rect
, format
, lineno
, &bounds
,
5149 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
5150 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
5155 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
5159 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
5161 if(height
> nheight
)
5164 /* Stop if this was a linewrap (but not if it was a linebreak). */
5165 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
5169 heap_free(stringdup
);
5170 heap_free(hotkeyprefix_offsets
);
5175 struct measure_ranges_args
{
5177 REAL rel_width
, rel_height
;
5180 static GpStatus
measure_ranges_callback(HDC hdc
,
5181 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5182 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5183 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5184 INT underlined_index_count
, void *user_data
)
5188 struct measure_ranges_args
*args
= user_data
;
5190 for (i
=0; i
<format
->range_count
; i
++)
5192 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
5193 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
5194 if (range_start
< range_end
)
5199 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
5200 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
5202 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
5203 INT_MAX
, NULL
, NULL
, &range_size
);
5204 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
5206 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
5207 INT_MAX
, NULL
, NULL
, &range_size
);
5208 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
5210 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
5219 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
5220 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
5221 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
5222 INT regionCount
, GpRegion
** regions
)
5226 HFONT gdifont
, oldfont
;
5227 struct measure_ranges_args args
;
5228 HDC hdc
, temp_hdc
=NULL
;
5233 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
5234 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
5236 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
5237 return InvalidParameter
;
5239 if (regionCount
< stringFormat
->range_count
)
5240 return InvalidParameter
;
5244 hdc
= temp_hdc
= CreateCompatibleDC(0);
5245 if (!temp_hdc
) return OutOfMemory
;
5248 hdc
= graphics
->hdc
;
5250 if (stringFormat
->attr
)
5251 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
5259 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5260 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5261 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5262 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5263 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5265 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
5266 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5268 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
5269 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
5270 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
5271 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
5273 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5274 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5276 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
5277 oldfont
= SelectObject(hdc
, gdifont
);
5279 for (i
=0; i
<stringFormat
->range_count
; i
++)
5281 stat
= GdipSetEmpty(regions
[i
]);
5286 args
.regions
= regions
;
5288 gdi_transform_acquire(graphics
);
5290 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
5291 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
5293 gdi_transform_release(graphics
);
5295 SelectObject(hdc
, oldfont
);
5296 DeleteObject(gdifont
);
5304 struct measure_string_args
{
5306 INT
*codepointsfitted
;
5308 REAL rel_width
, rel_height
;
5311 static GpStatus
measure_string_callback(HDC hdc
,
5312 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5313 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5314 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5315 INT underlined_index_count
, void *user_data
)
5317 struct measure_string_args
*args
= user_data
;
5318 REAL new_width
, new_height
;
5320 new_width
= bounds
->Width
/ args
->rel_width
;
5321 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
5323 if (new_width
> args
->bounds
->Width
)
5324 args
->bounds
->Width
= new_width
;
5326 if (new_height
> args
->bounds
->Height
)
5327 args
->bounds
->Height
= new_height
;
5329 if (args
->codepointsfitted
)
5330 *args
->codepointsfitted
= index
+ length
;
5332 if (args
->linesfilled
)
5333 (*args
->linesfilled
)++;
5338 /* Find the smallest rectangle that bounds the text when it is printed in rect
5339 * according to the format options listed in format. If rect has 0 width and
5340 * height, then just find the smallest rectangle that bounds the text when it's
5341 * printed at location (rect->X, rect-Y). */
5342 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
5343 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5344 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
5345 INT
*codepointsfitted
, INT
*linesfilled
)
5347 HFONT oldfont
, gdifont
;
5348 struct measure_string_args args
;
5349 HDC temp_hdc
=NULL
, hdc
;
5355 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
5356 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
5357 bounds
, codepointsfitted
, linesfilled
);
5359 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
5360 return InvalidParameter
;
5364 hdc
= temp_hdc
= CreateCompatibleDC(0);
5365 if (!temp_hdc
) return OutOfMemory
;
5368 hdc
= graphics
->hdc
;
5370 if(linesfilled
) *linesfilled
= 0;
5371 if(codepointsfitted
) *codepointsfitted
= 0;
5374 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5382 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5383 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5384 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5385 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5386 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5388 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5389 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5391 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
5392 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
5393 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
5394 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
5395 if (scaled_rect
.Width
>= 0.5)
5397 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5398 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5401 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5402 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5404 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5405 oldfont
= SelectObject(hdc
, gdifont
);
5407 bounds
->X
= rect
->X
;
5408 bounds
->Y
= rect
->Y
;
5409 bounds
->Width
= 0.0;
5410 bounds
->Height
= 0.0;
5412 args
.bounds
= bounds
;
5413 args
.codepointsfitted
= &glyphs
;
5414 args
.linesfilled
= &lines
;
5417 gdi_transform_acquire(graphics
);
5419 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5420 measure_string_callback
, &args
);
5422 gdi_transform_release(graphics
);
5424 if (linesfilled
) *linesfilled
= lines
;
5425 if (codepointsfitted
) *codepointsfitted
= glyphs
;
5428 bounds
->Width
+= margin_x
* 2.0;
5430 SelectObject(hdc
, oldfont
);
5431 DeleteObject(gdifont
);
5439 struct draw_string_args
{
5440 GpGraphics
*graphics
;
5441 GDIPCONST GpBrush
*brush
;
5442 REAL x
, y
, rel_width
, rel_height
, ascent
;
5445 static GpStatus
draw_string_callback(HDC hdc
,
5446 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5447 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5448 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5449 INT underlined_index_count
, void *user_data
)
5451 struct draw_string_args
*args
= user_data
;
5455 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5456 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5458 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
5459 args
->brush
, &position
,
5460 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5462 if (stat
== Ok
&& underlined_index_count
)
5464 OUTLINETEXTMETRICW otm
;
5465 REAL underline_y
, underline_height
;
5468 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5470 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5471 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5473 for (i
=0; i
<underlined_index_count
; i
++)
5475 REAL start_x
, end_x
;
5477 INT ofs
= underlined_indexes
[i
] - index
;
5479 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5480 start_x
= text_size
.cx
/ args
->rel_width
;
5482 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5483 end_x
= text_size
.cx
/ args
->rel_width
;
5485 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5492 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5493 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5494 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5498 GpPointF pt
[3], rectcpy
[4];
5500 REAL rel_width
, rel_height
, margin_x
;
5501 INT save_state
, format_flags
= 0;
5503 struct draw_string_args args
;
5505 HDC hdc
, temp_hdc
=NULL
;
5506 TEXTMETRICW textmetric
;
5508 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5509 length
, font
, debugstr_rectf(rect
), format
, brush
);
5511 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5512 return InvalidParameter
;
5516 hdc
= graphics
->hdc
;
5520 hdc
= temp_hdc
= CreateCompatibleDC(0);
5524 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5526 format_flags
= format
->attr
;
5528 /* Should be no need to explicitly test for StringAlignmentNear as
5529 * that is default behavior if no alignment is passed. */
5530 if(format
->line_align
!= StringAlignmentNear
){
5531 RectF bounds
, in_rect
= *rect
;
5532 in_rect
.Height
= 0.0; /* avoid height clipping */
5533 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5535 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5537 if(format
->line_align
== StringAlignmentCenter
)
5538 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5539 else if(format
->line_align
== StringAlignmentFar
)
5540 offsety
= (rect
->Height
- bounds
.Height
);
5542 TRACE("line align %d, offsety %f\n", format
->line_align
, offsety
);
5545 save_state
= SaveDC(hdc
);
5553 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
5554 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5555 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5556 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5557 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5559 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5560 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5561 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5562 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5563 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, rectcpy
, 4);
5564 round_points(corners
, rectcpy
, 4);
5566 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5567 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5569 scaled_rect
.X
= margin_x
* rel_width
;
5570 scaled_rect
.Y
= 0.0;
5571 scaled_rect
.Width
= rel_width
* rect
->Width
;
5572 scaled_rect
.Height
= rel_height
* rect
->Height
;
5573 if (scaled_rect
.Width
>= 0.5)
5575 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5576 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5579 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5580 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5582 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5583 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5584 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5586 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5587 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5588 SelectClipRgn(hdc
, rgn
);
5591 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5592 SelectObject(hdc
, gdifont
);
5594 args
.graphics
= graphics
;
5598 args
.y
= rect
->Y
+ offsety
;
5600 args
.rel_width
= rel_width
;
5601 args
.rel_height
= rel_height
;
5603 gdi_transform_acquire(graphics
);
5605 GetTextMetricsW(hdc
, &textmetric
);
5606 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5608 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5609 draw_string_callback
, &args
);
5611 gdi_transform_release(graphics
);
5614 DeleteObject(gdifont
);
5616 RestoreDC(hdc
, save_state
);
5623 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5625 TRACE("(%p)\n", graphics
);
5628 return InvalidParameter
;
5633 return GdipSetInfinite(graphics
->clip
);
5636 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5640 TRACE("(%p)\n", graphics
);
5643 return InvalidParameter
;
5648 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5649 stat
= METAFILE_ResetWorldTransform((GpMetafile
*)graphics
->image
);
5655 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5658 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5659 GpMatrixOrder order
)
5663 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5666 return InvalidParameter
;
5671 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5672 stat
= METAFILE_RotateWorldTransform((GpMetafile
*)graphics
->image
, angle
, order
);
5678 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5681 static GpStatus
begin_container(GpGraphics
*graphics
,
5682 GraphicsContainerType type
, GraphicsContainer
*state
)
5684 GraphicsContainerItem
*container
;
5687 if(!graphics
|| !state
)
5688 return InvalidParameter
;
5690 sts
= init_container(&container
, graphics
, type
);
5694 list_add_head(&graphics
->containers
, &container
->entry
);
5695 *state
= graphics
->contid
= container
->contid
;
5697 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5698 if (type
== BEGIN_CONTAINER
)
5699 METAFILE_BeginContainerNoParams((GpMetafile
*)graphics
->image
, container
->contid
);
5701 METAFILE_SaveGraphics((GpMetafile
*)graphics
->image
, container
->contid
);
5707 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5709 TRACE("(%p, %p)\n", graphics
, state
);
5710 return begin_container(graphics
, SAVE_GRAPHICS
, state
);
5713 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5714 GraphicsContainer
*state
)
5716 TRACE("(%p, %p)\n", graphics
, state
);
5717 return begin_container(graphics
, BEGIN_CONTAINER
, state
);
5720 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5722 GraphicsContainerItem
*container
;
5725 GpRectF scaled_srcrect
;
5726 REAL scale_x
, scale_y
;
5728 TRACE("(%p, %s, %s, %d, %p)\n", graphics
, debugstr_rectf(dstrect
), debugstr_rectf(srcrect
), unit
, state
);
5730 if(!graphics
|| !dstrect
|| !srcrect
|| unit
< UnitPixel
|| unit
> UnitMillimeter
|| !state
)
5731 return InvalidParameter
;
5733 stat
= init_container(&container
, graphics
, BEGIN_CONTAINER
);
5737 list_add_head(&graphics
->containers
, &container
->entry
);
5738 *state
= graphics
->contid
= container
->contid
;
5740 scale_x
= units_to_pixels(1.0, unit
, graphics
->xres
);
5741 scale_y
= units_to_pixels(1.0, unit
, graphics
->yres
);
5743 scaled_srcrect
.X
= scale_x
* srcrect
->X
;
5744 scaled_srcrect
.Y
= scale_y
* srcrect
->Y
;
5745 scaled_srcrect
.Width
= scale_x
* srcrect
->Width
;
5746 scaled_srcrect
.Height
= scale_y
* srcrect
->Height
;
5748 transform
.matrix
[0] = dstrect
->Width
/ scaled_srcrect
.Width
;
5749 transform
.matrix
[1] = 0.0;
5750 transform
.matrix
[2] = 0.0;
5751 transform
.matrix
[3] = dstrect
->Height
/ scaled_srcrect
.Height
;
5752 transform
.matrix
[4] = dstrect
->X
- scaled_srcrect
.X
;
5753 transform
.matrix
[5] = dstrect
->Y
- scaled_srcrect
.Y
;
5755 GdipMultiplyMatrix(&graphics
->worldtrans
, &transform
, MatrixOrderPrepend
);
5757 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5758 METAFILE_BeginContainer((GpMetafile
*)graphics
->image
, dstrect
, srcrect
, unit
, container
->contid
);
5764 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5766 GpRectF dstrectf
, srcrectf
;
5768 TRACE("(%p, %p, %p, %d, %p)\n", graphics
, dstrect
, srcrect
, unit
, state
);
5770 if (!dstrect
|| !srcrect
)
5771 return InvalidParameter
;
5773 dstrectf
.X
= dstrect
->X
;
5774 dstrectf
.Y
= dstrect
->Y
;
5775 dstrectf
.Width
= dstrect
->Width
;
5776 dstrectf
.Height
= dstrect
->Height
;
5778 srcrectf
.X
= srcrect
->X
;
5779 srcrectf
.Y
= srcrect
->Y
;
5780 srcrectf
.Width
= srcrect
->Width
;
5781 srcrectf
.Height
= srcrect
->Height
;
5783 return GdipBeginContainer(graphics
, &dstrectf
, &srcrectf
, unit
, state
);
5786 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5788 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5789 return NotImplemented
;
5792 static GpStatus
end_container(GpGraphics
*graphics
, GraphicsContainerType type
,
5793 GraphicsContainer state
)
5796 GraphicsContainerItem
*container
, *container2
;
5799 return InvalidParameter
;
5801 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5802 if(container
->contid
== state
&& container
->type
== type
)
5806 /* did not find a matching container */
5807 if(&container
->entry
== &graphics
->containers
)
5810 sts
= restore_container(graphics
, container
);
5814 /* remove all of the containers on top of the found container */
5815 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5816 if(container
->contid
== state
)
5818 list_remove(&container
->entry
);
5819 delete_container(container
);
5822 list_remove(&container
->entry
);
5823 delete_container(container
);
5825 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5826 if (type
== BEGIN_CONTAINER
)
5827 METAFILE_EndContainer((GpMetafile
*)graphics
->image
, state
);
5829 METAFILE_RestoreGraphics((GpMetafile
*)graphics
->image
, state
);
5835 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5837 TRACE("(%p, %x)\n", graphics
, state
);
5838 return end_container(graphics
, BEGIN_CONTAINER
, state
);
5841 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5843 TRACE("(%p, %x)\n", graphics
, state
);
5844 return end_container(graphics
, SAVE_GRAPHICS
, state
);
5847 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5848 REAL sy
, GpMatrixOrder order
)
5852 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5855 return InvalidParameter
;
5860 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5861 stat
= METAFILE_ScaleWorldTransform((GpMetafile
*)graphics
->image
, sx
, sy
, order
);
5867 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5870 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5873 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5875 if(!graphics
|| !srcgraphics
)
5876 return InvalidParameter
;
5878 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5881 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5882 CompositingMode mode
)
5884 TRACE("(%p, %d)\n", graphics
, mode
);
5887 return InvalidParameter
;
5892 if(graphics
->compmode
== mode
)
5895 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5899 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5900 EmfPlusRecordTypeSetCompositingMode
, mode
);
5905 graphics
->compmode
= mode
;
5910 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5911 CompositingQuality quality
)
5913 TRACE("(%p, %d)\n", graphics
, quality
);
5916 return InvalidParameter
;
5921 if(graphics
->compqual
== quality
)
5924 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5928 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5929 EmfPlusRecordTypeSetCompositingQuality
, quality
);
5934 graphics
->compqual
= quality
;
5939 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5940 InterpolationMode mode
)
5942 TRACE("(%p, %d)\n", graphics
, mode
);
5944 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5945 return InvalidParameter
;
5950 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5951 mode
= InterpolationModeBilinear
;
5953 if (mode
== InterpolationModeHighQuality
)
5954 mode
= InterpolationModeHighQualityBicubic
;
5956 if (mode
== graphics
->interpolation
)
5959 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5963 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
5964 EmfPlusRecordTypeSetInterpolationMode
, mode
);
5969 graphics
->interpolation
= mode
;
5974 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5978 TRACE("(%p, %.2f)\n", graphics
, scale
);
5980 if(!graphics
|| (scale
<= 0.0))
5981 return InvalidParameter
;
5986 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5988 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
5993 graphics
->scale
= scale
;
5998 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
6002 TRACE("(%p, %d)\n", graphics
, unit
);
6005 return InvalidParameter
;
6010 if(unit
== UnitWorld
)
6011 return InvalidParameter
;
6013 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6015 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
6020 graphics
->unit
= unit
;
6025 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
6028 TRACE("(%p, %d)\n", graphics
, mode
);
6031 return InvalidParameter
;
6036 if(graphics
->pixeloffset
== mode
)
6039 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6043 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6044 EmfPlusRecordTypeSetPixelOffsetMode
, mode
);
6049 graphics
->pixeloffset
= mode
;
6054 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
6058 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
6061 FIXME("value is unused in rendering\n");
6064 return InvalidParameter
;
6066 graphics
->origin_x
= x
;
6067 graphics
->origin_y
= y
;
6072 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
6074 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
6076 if (!graphics
|| !x
|| !y
)
6077 return InvalidParameter
;
6079 *x
= graphics
->origin_x
;
6080 *y
= graphics
->origin_y
;
6085 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
6087 TRACE("(%p, %d)\n", graphics
, mode
);
6090 return InvalidParameter
;
6095 if(graphics
->smoothing
== mode
)
6098 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6100 BOOL antialias
= (mode
!= SmoothingModeDefault
&&
6101 mode
!= SmoothingModeNone
&& mode
!= SmoothingModeHighSpeed
);
6103 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6104 EmfPlusRecordTypeSetAntiAliasMode
, (mode
<< 1) + antialias
);
6109 graphics
->smoothing
= mode
;
6114 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
6116 TRACE("(%p, %d)\n", graphics
, contrast
);
6119 return InvalidParameter
;
6121 graphics
->textcontrast
= contrast
;
6126 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
6127 TextRenderingHint hint
)
6129 TRACE("(%p, %d)\n", graphics
, hint
);
6131 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
6132 return InvalidParameter
;
6137 if(graphics
->texthint
== hint
)
6140 if(graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6143 stat
= METAFILE_AddSimpleProperty((GpMetafile
*)graphics
->image
,
6144 EmfPlusRecordTypeSetTextRenderingHint
, hint
);
6149 graphics
->texthint
= hint
;
6154 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
6158 TRACE("(%p, %p)\n", graphics
, matrix
);
6160 if(!graphics
|| !matrix
)
6161 return InvalidParameter
;
6166 TRACE("%f,%f,%f,%f,%f,%f\n",
6167 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
6168 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
6170 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6171 stat
= METAFILE_SetWorldTransform((GpMetafile
*)graphics
->image
, matrix
);
6177 graphics
->worldtrans
= *matrix
;
6182 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
6183 REAL dy
, GpMatrixOrder order
)
6187 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
6190 return InvalidParameter
;
6195 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6196 stat
= METAFILE_TranslateWorldTransform((GpMetafile
*)graphics
->image
, dx
, dy
, order
);
6202 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
6205 /*****************************************************************************
6206 * GdipSetClipHrgn [GDIPLUS.@]
6208 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
6214 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
6217 return InvalidParameter
;
6222 /* hrgn is in gdi32 device units */
6223 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
6227 status
= get_graphics_transform(graphics
, CoordinateSpaceDevice
, WineCoordinateSpaceGdiDevice
, &transform
);
6230 status
= GdipTransformRegion(region
, &transform
);
6233 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6235 GdipDeleteRegion(region
);
6240 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
6245 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
6248 return InvalidParameter
;
6253 status
= GdipClonePath(path
, &clip_path
);
6256 GpMatrix world_to_device
;
6258 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
6259 CoordinateSpaceWorld
, &world_to_device
);
6260 status
= GdipTransformPath(clip_path
, &world_to_device
);
6262 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
6264 GdipDeletePath(clip_path
);
6269 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
6270 REAL width
, REAL height
,
6277 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6280 return InvalidParameter
;
6285 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6287 status
= METAFILE_SetClipRect((GpMetafile
*)graphics
->image
, x
, y
, width
, height
, mode
);
6295 rect
.Height
= height
;
6296 status
= GdipCreateRegionRect(&rect
, ®ion
);
6299 GpMatrix world_to_device
;
6301 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6302 status
= GdipTransformRegion(region
, &world_to_device
);
6304 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6306 GdipDeleteRegion(region
);
6311 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
6312 INT width
, INT height
,
6315 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6318 return InvalidParameter
;
6323 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
6326 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
6332 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
6334 if(!graphics
|| !region
)
6335 return InvalidParameter
;
6340 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6342 status
= METAFILE_SetClipRegion((GpMetafile
*)graphics
->image
, region
, mode
);
6347 status
= GdipCloneRegion(region
, &clip
);
6350 GpMatrix world_to_device
;
6352 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6353 status
= GdipTransformRegion(clip
, &world_to_device
);
6355 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
6357 GdipDeleteRegion(clip
);
6362 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
6368 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
6370 if(!graphics
|| !pen
|| count
<=0)
6371 return InvalidParameter
;
6376 status
= GdipCreatePath(FillModeAlternate
, &path
);
6377 if (status
!= Ok
) return status
;
6379 status
= GdipAddPathPolygon(path
, points
, count
);
6381 status
= GdipDrawPath(graphics
, pen
, path
);
6383 GdipDeletePath(path
);
6388 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
6395 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
6397 if(count
<=0) return InvalidParameter
;
6398 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6400 for(i
= 0;i
< count
; i
++){
6401 ptf
[i
].X
= (REAL
)points
[i
].X
;
6402 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
6405 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
6411 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
6413 TRACE("(%p, %p)\n", graphics
, dpi
);
6415 if(!graphics
|| !dpi
)
6416 return InvalidParameter
;
6421 *dpi
= graphics
->xres
;
6425 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
6427 TRACE("(%p, %p)\n", graphics
, dpi
);
6429 if(!graphics
|| !dpi
)
6430 return InvalidParameter
;
6435 *dpi
= graphics
->yres
;
6439 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
6440 GpMatrixOrder order
)
6445 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
6447 if(!graphics
|| !matrix
)
6448 return InvalidParameter
;
6453 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6454 ret
= METAFILE_MultiplyWorldTransform((GpMetafile
*)graphics
->image
, matrix
, order
);
6460 m
= graphics
->worldtrans
;
6462 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
6464 graphics
->worldtrans
= m
;
6469 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
6470 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
6472 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
6476 TRACE("(%p, %p)\n", graphics
, hdc
);
6478 if(!graphics
|| !hdc
)
6479 return InvalidParameter
;
6484 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6486 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
6488 else if (!graphics
->hdc
||
6489 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
6491 /* Create a fake HDC and fill it with a constant color. */
6495 BITMAPINFOHEADER bmih
;
6498 stat
= get_graphics_bounds(graphics
, &bounds
);
6502 graphics
->temp_hbitmap_width
= bounds
.Width
;
6503 graphics
->temp_hbitmap_height
= bounds
.Height
;
6505 bmih
.biSize
= sizeof(bmih
);
6506 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
6507 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
6509 bmih
.biBitCount
= 32;
6510 bmih
.biCompression
= BI_RGB
;
6511 bmih
.biSizeImage
= 0;
6512 bmih
.biXPelsPerMeter
= 0;
6513 bmih
.biYPelsPerMeter
= 0;
6515 bmih
.biClrImportant
= 0;
6517 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
6518 (void**)&graphics
->temp_bits
, NULL
, 0);
6520 return GenericError
;
6522 temp_hdc
= CreateCompatibleDC(0);
6525 DeleteObject(hbitmap
);
6526 return GenericError
;
6529 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6530 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
6532 SelectObject(temp_hdc
, hbitmap
);
6534 graphics
->temp_hbitmap
= hbitmap
;
6535 *hdc
= graphics
->temp_hdc
= temp_hdc
;
6539 *hdc
= graphics
->hdc
;
6543 graphics
->busy
= TRUE
;
6548 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
6552 TRACE("(%p, %p)\n", graphics
, hdc
);
6554 if(!graphics
|| !hdc
|| !graphics
->busy
)
6555 return InvalidParameter
;
6557 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6559 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
6561 else if (graphics
->temp_hdc
== hdc
)
6566 /* Find the pixels that have changed, and mark them as opaque. */
6567 pos
= (DWORD
*)graphics
->temp_bits
;
6568 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6570 if (*pos
!= DC_BACKGROUND_KEY
)
6577 /* Write the changed pixels to the real target. */
6578 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
6579 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
6580 graphics
->temp_hbitmap_width
* 4, PixelFormat32bppARGB
);
6583 DeleteDC(graphics
->temp_hdc
);
6584 DeleteObject(graphics
->temp_hbitmap
);
6585 graphics
->temp_hdc
= NULL
;
6586 graphics
->temp_hbitmap
= NULL
;
6588 else if (hdc
!= graphics
->hdc
)
6590 stat
= InvalidParameter
;
6594 graphics
->busy
= FALSE
;
6599 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
6603 GpMatrix device_to_world
;
6605 TRACE("(%p, %p)\n", graphics
, region
);
6607 if(!graphics
|| !region
)
6608 return InvalidParameter
;
6613 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
6616 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
6617 status
= GdipTransformRegion(clip
, &device_to_world
);
6620 GdipDeleteRegion(clip
);
6624 /* free everything except root node and header */
6625 delete_element(®ion
->node
);
6626 memcpy(region
, clip
, sizeof(GpRegion
));
6632 static void get_gdi_transform(GpGraphics
*graphics
, GpMatrix
*matrix
)
6636 if (graphics
->hdc
== NULL
)
6638 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
6642 if (graphics
->gdi_transform_acquire_count
)
6644 *matrix
= graphics
->gdi_transform
;
6648 GetTransform(graphics
->hdc
, 0x204, &xform
);
6649 GdipSetMatrixElements(matrix
, xform
.eM11
, xform
.eM12
, xform
.eM21
, xform
.eM22
, xform
.eDx
, xform
.eDy
);
6652 GpStatus
gdi_transform_acquire(GpGraphics
*graphics
)
6654 if (graphics
->gdi_transform_acquire_count
== 0 && graphics
->hdc
)
6656 get_gdi_transform(graphics
, &graphics
->gdi_transform
);
6657 graphics
->gdi_transform_save
= SaveDC(graphics
->hdc
);
6658 SetGraphicsMode(graphics
->hdc
, GM_COMPATIBLE
);
6659 SetMapMode(graphics
->hdc
, MM_TEXT
);
6660 SetWindowOrgEx(graphics
->hdc
, 0, 0, NULL
);
6661 SetViewportOrgEx(graphics
->hdc
, 0, 0, NULL
);
6663 graphics
->gdi_transform_acquire_count
++;
6667 GpStatus
gdi_transform_release(GpGraphics
*graphics
)
6669 if (graphics
->gdi_transform_acquire_count
<= 0)
6671 ERR("called without matching gdi_transform_acquire");
6672 return GenericError
;
6674 if (graphics
->gdi_transform_acquire_count
== 1 && graphics
->hdc
)
6676 RestoreDC(graphics
->hdc
, graphics
->gdi_transform_save
);
6678 graphics
->gdi_transform_acquire_count
--;
6682 GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6683 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
6686 REAL scale_x
, scale_y
;
6688 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
6690 if (dst_space
!= src_space
)
6692 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
6693 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
6695 if(graphics
->unit
!= UnitDisplay
)
6697 scale_x
*= graphics
->scale
;
6698 scale_y
*= graphics
->scale
;
6701 if (dst_space
< src_space
)
6703 /* transform towards world space */
6704 switch ((int)src_space
)
6706 case WineCoordinateSpaceGdiDevice
:
6709 get_gdi_transform(graphics
, &gdixform
);
6710 stat
= GdipInvertMatrix(&gdixform
);
6713 GdipMultiplyMatrix(matrix
, &gdixform
, MatrixOrderAppend
);
6714 if (dst_space
== CoordinateSpaceDevice
)
6716 /* else fall-through */
6718 case CoordinateSpaceDevice
:
6719 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
6720 if (dst_space
== CoordinateSpacePage
)
6722 /* else fall-through */
6723 case CoordinateSpacePage
:
6725 GpMatrix inverted_transform
= graphics
->worldtrans
;
6726 stat
= GdipInvertMatrix(&inverted_transform
);
6728 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
6735 /* transform towards device space */
6736 switch ((int)src_space
)
6738 case CoordinateSpaceWorld
:
6739 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
6740 if (dst_space
== CoordinateSpacePage
)
6742 /* else fall-through */
6743 case CoordinateSpacePage
:
6744 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
6745 if (dst_space
== CoordinateSpaceDevice
)
6747 /* else fall-through */
6748 case CoordinateSpaceDevice
:
6751 get_gdi_transform(graphics
, &gdixform
);
6752 GdipMultiplyMatrix(matrix
, &gdixform
, MatrixOrderAppend
);
6761 GpStatus
gdip_transform_points(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6762 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6767 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6768 if (stat
!= Ok
) return stat
;
6770 return GdipTransformMatrixPoints(&matrix
, points
, count
);
6773 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6774 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6776 if(!graphics
|| !points
|| count
<= 0 ||
6777 dst_space
< 0 || dst_space
> CoordinateSpaceDevice
||
6778 src_space
< 0 || src_space
> CoordinateSpaceDevice
)
6779 return InvalidParameter
;
6784 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6786 if (src_space
== dst_space
) return Ok
;
6788 return gdip_transform_points(graphics
, dst_space
, src_space
, points
, count
);
6791 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6792 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6798 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6801 return InvalidParameter
;
6803 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6807 for(i
= 0; i
< count
; i
++){
6808 pointsF
[i
].X
= (REAL
)points
[i
].X
;
6809 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
6812 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6815 for(i
= 0; i
< count
; i
++){
6816 points
[i
].X
= gdip_round(pointsF
[i
].X
);
6817 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
6824 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6836 /*****************************************************************************
6837 * GdipTranslateClip [GDIPLUS.@]
6839 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6841 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6844 return InvalidParameter
;
6849 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6852 /*****************************************************************************
6853 * GdipTranslateClipI [GDIPLUS.@]
6855 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6857 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6860 return InvalidParameter
;
6865 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6869 /*****************************************************************************
6870 * GdipMeasureDriverString [GDIPLUS.@]
6872 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6873 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6874 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6876 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6879 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6881 TEXTMETRICW textmetric
;
6882 const WORD
*glyph_indices
;
6883 WORD
*dynamic_glyph_indices
=NULL
;
6884 REAL rel_width
, rel_height
, ascent
, descent
;
6887 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6889 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6890 return InvalidParameter
;
6893 length
= strlenW(text
);
6897 boundingBox
->X
= 0.0;
6898 boundingBox
->Y
= 0.0;
6899 boundingBox
->Width
= 0.0;
6900 boundingBox
->Height
= 0.0;
6903 if (flags
& unsupported_flags
)
6904 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6906 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6908 hdc
= CreateCompatibleDC(0);
6909 SelectObject(hdc
, hfont
);
6911 GetTextMetricsW(hdc
, &textmetric
);
6921 GpMatrix xform
= *matrix
;
6922 GdipTransformMatrixPoints(&xform
, pt
, 3);
6924 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, pt
, 3);
6925 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6926 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6927 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6928 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6930 if (flags
& DriverStringOptionsCmapLookup
)
6932 glyph_indices
= dynamic_glyph_indices
= heap_alloc_zero(sizeof(WORD
) * length
);
6936 DeleteObject(hfont
);
6940 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6943 glyph_indices
= text
;
6945 min_x
= max_x
= x
= positions
[0].X
;
6946 min_y
= max_y
= y
= positions
[0].Y
;
6948 ascent
= textmetric
.tmAscent
/ rel_height
;
6949 descent
= textmetric
.tmDescent
/ rel_height
;
6951 for (i
=0; i
<length
; i
++)
6956 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6962 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6963 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6965 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6966 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6967 if (min_x
> x
) min_x
= x
;
6969 x
+= char_width
/ rel_width
;
6971 if (max_x
< x
) max_x
= x
;
6974 heap_free(dynamic_glyph_indices
);
6976 DeleteObject(hfont
);
6978 boundingBox
->X
= min_x
;
6979 boundingBox
->Y
= min_y
;
6980 boundingBox
->Width
= max_x
- min_x
;
6981 boundingBox
->Height
= max_y
- min_y
;
6986 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6987 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6988 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6989 INT flags
, GDIPCONST GpMatrix
*matrix
)
6991 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6999 if (flags
& unsupported_flags
)
7000 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
7002 if (!(flags
& DriverStringOptionsCmapLookup
))
7003 eto_flags
|= ETO_GLYPH_INDEX
;
7005 save_state
= SaveDC(graphics
->hdc
);
7006 SetBkMode(graphics
->hdc
, TRANSPARENT
);
7007 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
7009 status
= get_clip_hrgn(graphics
, &hrgn
);
7011 if (status
== Ok
&& hrgn
)
7013 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
7018 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, &pt
, 1);
7020 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
7021 SelectObject(graphics
->hdc
, hfont
);
7023 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
7025 gdi_transform_acquire(graphics
);
7027 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
7029 gdi_transform_release(graphics
);
7031 RestoreDC(graphics
->hdc
, save_state
);
7033 DeleteObject(hfont
);
7038 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7039 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7040 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7041 INT flags
, GDIPCONST GpMatrix
*matrix
)
7043 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
7045 PointF
*real_positions
, real_position
;
7049 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
7050 DWORD max_glyphsize
=0;
7051 GLYPHMETRICS glyphmetrics
;
7052 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
7055 int text_mask_stride
;
7057 int pixel_data_stride
;
7059 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
7064 if (!(flags
& DriverStringOptionsCmapLookup
))
7065 ggo_flags
|= GGO_GLYPH_INDEX
;
7067 if (flags
& unsupported_flags
)
7068 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
7070 pti
= heap_alloc_zero(sizeof(POINT
) * length
);
7074 if (flags
& DriverStringOptionsRealizedAdvance
)
7076 real_position
= positions
[0];
7078 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, &real_position
, 1);
7079 round_points(pti
, &real_position
, 1);
7083 real_positions
= heap_alloc_zero(sizeof(PointF
) * length
);
7084 if (!real_positions
)
7090 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
7092 gdip_transform_points(graphics
, WineCoordinateSpaceGdiDevice
, CoordinateSpaceWorld
, real_positions
, length
);
7093 round_points(pti
, real_positions
, length
);
7095 heap_free(real_positions
);
7098 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
7100 hdc
= CreateCompatibleDC(0);
7101 SelectObject(hdc
, hfont
);
7103 /* Get the boundaries of the text to be drawn */
7104 for (i
=0; i
<length
; i
++)
7107 int left
, top
, right
, bottom
;
7109 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
7110 &glyphmetrics
, 0, NULL
, &identity
);
7112 if (glyphsize
== GDI_ERROR
)
7114 ERR("GetGlyphOutlineW failed\n");
7117 DeleteObject(hfont
);
7118 return GenericError
;
7121 if (glyphsize
> max_glyphsize
)
7122 max_glyphsize
= glyphsize
;
7126 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7127 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7128 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
7129 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
7131 if (left
< min_x
) min_x
= left
;
7132 if (top
< min_y
) min_y
= top
;
7133 if (right
> max_x
) max_x
= right
;
7134 if (bottom
> max_y
) max_y
= bottom
;
7137 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
7139 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
7140 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
7144 if (max_glyphsize
== 0)
7145 /* Nothing to draw. */
7148 glyph_mask
= heap_alloc_zero(max_glyphsize
);
7149 text_mask
= heap_alloc_zero((max_x
- min_x
) * (max_y
- min_y
));
7150 text_mask_stride
= max_x
- min_x
;
7152 if (!(glyph_mask
&& text_mask
))
7154 heap_free(glyph_mask
);
7155 heap_free(text_mask
);
7158 DeleteObject(hfont
);
7162 /* Generate a mask for the text */
7163 for (i
=0; i
<length
; i
++)
7166 int left
, top
, stride
;
7168 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
7169 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
7171 if (ret
== GDI_ERROR
|| ret
== 0)
7172 continue; /* empty glyph */
7174 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
7175 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
7176 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
7178 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
7180 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
7181 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
7182 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
7184 *text_val
= min(64, *text_val
+ *glyph_val
);
7193 DeleteObject(hfont
);
7194 heap_free(glyph_mask
);
7196 /* get the brush data */
7197 pixel_data
= heap_alloc_zero(4 * (max_x
- min_x
) * (max_y
- min_y
));
7200 heap_free(text_mask
);
7204 pixel_area
.X
= min_x
;
7205 pixel_area
.Y
= min_y
;
7206 pixel_area
.Width
= max_x
- min_x
;
7207 pixel_area
.Height
= max_y
- min_y
;
7208 pixel_data_stride
= pixel_area
.Width
* 4;
7210 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
7213 heap_free(text_mask
);
7214 heap_free(pixel_data
);
7218 /* multiply the brush data by the mask */
7219 for (y
=0; y
<pixel_area
.Height
; y
++)
7221 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
7222 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
7223 for (x
=0; x
<pixel_area
.Width
; x
++)
7225 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
7231 heap_free(text_mask
);
7233 gdi_transform_acquire(graphics
);
7235 /* draw the result */
7236 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
7237 pixel_area
.Height
, pixel_data_stride
, PixelFormat32bppARGB
);
7239 gdi_transform_release(graphics
);
7241 heap_free(pixel_data
);
7246 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7247 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
7248 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
7249 INT flags
, GDIPCONST GpMatrix
*matrix
)
7251 GpStatus stat
= NotImplemented
;
7254 length
= strlenW(text
);
7256 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
7257 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
7258 brush
->bt
== BrushTypeSolidColor
&&
7259 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
7260 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7261 brush
, positions
, flags
, matrix
);
7262 if (stat
== NotImplemented
)
7263 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
7264 brush
, positions
, flags
, matrix
);
7268 /*****************************************************************************
7269 * GdipDrawDriverString [GDIPLUS.@]
7271 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
7272 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
7273 GDIPCONST PointF
*positions
, INT flags
,
7274 GDIPCONST GpMatrix
*matrix
)
7276 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
7278 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
7279 return InvalidParameter
;
7281 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
7282 brush
, positions
, flags
, matrix
);
7285 /*****************************************************************************
7286 * GdipIsVisibleClipEmpty [GDIPLUS.@]
7288 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
7293 TRACE("(%p, %p)\n", graphics
, res
);
7295 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
7298 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
7301 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
7304 GdipDeleteRegion(rgn
);
7308 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
7312 TRACE("(%p) stub\n", graphics
);
7315 FIXME("not implemented\n");
7317 return NotImplemented
;
7320 GpStatus WINGDIPAPI
GdipGraphicsSetAbort(GpGraphics
*graphics
, GdiplusAbort
*pabort
)
7322 TRACE("(%p, %p)\n", graphics
, pabort
);
7325 return InvalidParameter
;
7328 FIXME("Abort callback is not supported.\n");