2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/unicode.h"
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
45 /* looks-right constants */
46 #define ANCHOR_WIDTH (2.0)
47 #define MAX_ITERS (50)
49 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
50 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
51 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
52 INT flags
, GDIPCONST GpMatrix
*matrix
);
54 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
55 GpCoordinateSpace src_space
, GpMatrix
*matrix
);
57 /* Converts from gdiplus path point type to gdi path point type. */
58 static BYTE
convert_path_point_type(BYTE type
)
62 switch(type
& PathPointTypePathTypeMask
){
63 case PathPointTypeBezier
:
66 case PathPointTypeLine
:
69 case PathPointTypeStart
:
73 ERR("Bad point type\n");
77 if(type
& PathPointTypeCloseSubpath
)
78 ret
|= PT_CLOSEFIGURE
;
83 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
89 case BrushTypeSolidColor
:
91 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
95 case BrushTypeHatchFill
:
97 const GpHatch
*hatch
= (const GpHatch
*)brush
;
98 argb
= hatch
->forecol
;
101 case BrushTypeLinearGradient
:
103 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
104 argb
= line
->startcolor
;
107 case BrushTypePathGradient
:
109 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
110 argb
= grad
->centercolor
;
114 FIXME("unhandled brush type %d\n", brush
->bt
);
118 return ARGB2COLORREF(argb
);
121 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
124 BITMAPINFOHEADER bmih
;
128 bmih
.biSize
= sizeof(bmih
);
132 bmih
.biBitCount
= 32;
133 bmih
.biCompression
= BI_RGB
;
134 bmih
.biSizeImage
= 0;
136 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
139 const char *hatch_data
;
141 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
143 for (y
= 0; y
< 8; y
++)
145 for (x
= 0; x
< 8; x
++)
147 if (hatch_data
[y
] & (0x80 >> x
))
148 bits
[y
* 8 + x
] = hatch
->forecol
;
150 bits
[y
* 8 + x
] = hatch
->backcol
;
156 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
158 for (y
= 0; y
< 64; y
++)
159 bits
[y
] = hatch
->forecol
;
166 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
170 case BrushTypeSolidColor
:
172 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
173 lb
->lbStyle
= BS_SOLID
;
174 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
179 case BrushTypeHatchFill
:
181 const GpHatch
*hatch
= (const GpHatch
*)brush
;
184 hbmp
= create_hatch_bitmap(hatch
);
185 if (!hbmp
) return OutOfMemory
;
187 lb
->lbStyle
= BS_PATTERN
;
189 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
194 FIXME("unhandled brush type %d\n", brush
->bt
);
195 lb
->lbStyle
= BS_SOLID
;
196 lb
->lbColor
= get_gdi_brush_color(brush
);
202 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
207 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
213 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
218 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
220 gdibrush
= CreateBrushIndirect(&lb
);
221 free_gdi_logbrush(&lb
);
226 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
231 INT save_state
, i
, numdashes
;
233 DWORD dash_array
[MAX_DASHLEN
];
235 save_state
= SaveDC(graphics
->hdc
);
237 EndPath(graphics
->hdc
);
239 if(pen
->unit
== UnitPixel
){
243 /* Get an estimate for the amount the pen width is affected by the world
244 * transform. (This is similar to what some of the wine drivers do.) */
249 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
250 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
251 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
253 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
256 if(pen
->dash
== DashStyleCustom
){
257 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
259 TRACE("dashes are: ");
260 for(i
= 0; i
< numdashes
; i
++){
261 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
262 TRACE("%d, ", dash_array
[i
]);
264 TRACE("\n and the pen style is %x\n", pen
->style
);
266 create_gdi_logbrush(pen
->brush
, &lb
);
267 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
268 numdashes
, dash_array
);
269 free_gdi_logbrush(&lb
);
273 create_gdi_logbrush(pen
->brush
, &lb
);
274 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
275 free_gdi_logbrush(&lb
);
278 SelectObject(graphics
->hdc
, gdipen
);
283 static void restore_dc(GpGraphics
*graphics
, INT state
)
285 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
286 RestoreDC(graphics
->hdc
, state
);
289 /* This helper applies all the changes that the points listed in ptf need in
290 * order to be drawn on the device context. In the end, this should include at
292 * -scaling by page unit
293 * -applying world transformation
294 * -converting from float to int
295 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
296 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
297 * gdi to draw, and these functions would irreparably mess with line widths.
299 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
300 GpPointF
*ptf
, INT count
)
302 REAL scale_x
, scale_y
;
306 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
307 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
309 /* apply page scale */
310 if(graphics
->unit
!= UnitDisplay
)
312 scale_x
*= graphics
->scale
;
313 scale_y
*= graphics
->scale
;
316 matrix
= graphics
->worldtrans
;
317 GdipScaleMatrix(&matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
318 GdipTransformMatrixPoints(&matrix
, ptf
, count
);
320 for(i
= 0; i
< count
; i
++){
321 pti
[i
].x
= gdip_round(ptf
[i
].X
);
322 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
326 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
327 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
329 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
331 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
333 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
334 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
340 bf
.BlendOp
= AC_SRC_OVER
;
342 bf
.SourceConstantAlpha
= 255;
343 bf
.AlphaFormat
= AC_SRC_ALPHA
;
345 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
346 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
350 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
352 /* clipping region is in device coords */
353 return GdipGetRegionHRgn(graphics
->clip
, NULL
, hrgn
);
356 /* Draw non-premultiplied ARGB data to the given graphics object */
357 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
358 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
360 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
363 for (x
=0; x
<src_width
; x
++)
365 for (y
=0; y
<src_height
; y
++)
367 ARGB dst_color
, src_color
;
368 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
369 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
370 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
377 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
378 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
382 BITMAPINFOHEADER bih
;
385 hdc
= CreateCompatibleDC(0);
387 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
388 bih
.biWidth
= src_width
;
389 bih
.biHeight
= -src_height
;
392 bih
.biCompression
= BI_RGB
;
394 bih
.biXPelsPerMeter
= 0;
395 bih
.biYPelsPerMeter
= 0;
397 bih
.biClrImportant
= 0;
399 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
400 (void**)&temp_bits
, NULL
, 0);
402 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
403 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
405 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
406 4 * src_width
, src
, src_stride
);
408 SelectObject(hdc
, hbitmap
);
409 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
410 hdc
, 0, 0, src_width
, src_height
);
412 DeleteObject(hbitmap
);
417 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
418 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
)
422 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
428 HRGN hrgn
, visible_rgn
;
430 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
434 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
443 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
444 DeleteObject(visible_rgn
);
448 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
450 size
= GetRegionData(hrgn
, 0, NULL
);
452 rgndata
= GdipAlloc(size
);
459 GetRegionData(hrgn
, size
, rgndata
);
461 rects
= (RECT
*)rgndata
->Buffer
;
463 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
465 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
466 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
467 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
477 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
479 ERR("This should not be used for metafiles; fix caller\n");
480 return NotImplemented
;
487 stat
= get_clip_hrgn(graphics
, &hrgn
);
492 save
= SaveDC(graphics
->hdc
);
495 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
498 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
500 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
501 src_height
, src_stride
);
503 RestoreDC(graphics
->hdc
, save
);
511 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
512 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
514 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
);
517 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
523 a1
= (start
>> 24) & 0xff;
524 a2
= (end
>> 24) & 0xff;
526 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
530 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
531 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
535 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
539 /* clamp to between 0.0 and 1.0, using the wrap mode */
540 if (brush
->wrap
== WrapModeTile
)
542 position
= fmodf(position
, 1.0f
);
543 if (position
< 0.0f
) position
+= 1.0f
;
545 else /* WrapModeFlip* */
547 position
= fmodf(position
, 2.0f
);
548 if (position
< 0.0f
) position
+= 2.0f
;
549 if (position
> 1.0f
) position
= 2.0f
- position
;
552 if (brush
->blendcount
== 1)
557 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
560 /* locate the blend positions surrounding this position */
561 while (position
> brush
->blendpos
[i
])
564 /* interpolate between the blend positions */
565 left_blendpos
= brush
->blendpos
[i
-1];
566 left_blendfac
= brush
->blendfac
[i
-1];
567 right_blendpos
= brush
->blendpos
[i
];
568 right_blendfac
= brush
->blendfac
[i
];
569 range
= right_blendpos
- left_blendpos
;
570 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
571 right_blendfac
* (position
- left_blendpos
)) / range
;
574 if (brush
->pblendcount
== 0)
575 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
579 ARGB left_blendcolor
, right_blendcolor
;
580 REAL left_blendpos
, right_blendpos
;
582 /* locate the blend colors surrounding this position */
583 while (blendfac
> brush
->pblendpos
[i
])
586 /* interpolate between the blend colors */
587 left_blendpos
= brush
->pblendpos
[i
-1];
588 left_blendcolor
= brush
->pblendcolor
[i
-1];
589 right_blendpos
= brush
->pblendpos
[i
];
590 right_blendcolor
= brush
->pblendcolor
[i
];
591 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
592 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
596 static BOOL
round_color_matrix(const ColorMatrix
*matrix
, int values
[5][5])
598 /* Convert floating point color matrix to int[5][5], return TRUE if it's an identity */
599 BOOL identity
= TRUE
;
605 if (matrix
->m
[j
][i
] != (i
== j
? 1.0 : 0.0))
607 values
[j
][i
] = gdip_round(matrix
->m
[j
][i
] * 256.0);
613 static ARGB
transform_color(ARGB color
, int matrix
[5][5])
617 unsigned char a
, r
, g
, b
;
619 val
[0] = ((color
>> 16) & 0xff); /* red */
620 val
[1] = ((color
>> 8) & 0xff); /* green */
621 val
[2] = (color
& 0xff); /* blue */
622 val
[3] = ((color
>> 24) & 0xff); /* alpha */
623 val
[4] = 255; /* translation */
630 res
[i
] += matrix
[j
][i
] * val
[j
];
633 a
= min(max(res
[3] / 256, 0), 255);
634 r
= min(max(res
[0] / 256, 0), 255);
635 g
= min(max(res
[1] / 256, 0), 255);
636 b
= min(max(res
[2] / 256, 0), 255);
638 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
641 static BOOL
color_is_gray(ARGB color
)
643 unsigned char r
, g
, b
;
645 r
= (color
>> 16) & 0xff;
646 g
= (color
>> 8) & 0xff;
649 return (r
== g
) && (g
== b
);
652 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
653 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
658 if (attributes
->colorkeys
[type
].enabled
||
659 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
661 const struct color_key
*key
;
662 BYTE min_blue
, min_green
, min_red
;
663 BYTE max_blue
, max_green
, max_red
;
665 if (attributes
->colorkeys
[type
].enabled
)
666 key
= &attributes
->colorkeys
[type
];
668 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
670 min_blue
= key
->low
&0xff;
671 min_green
= (key
->low
>>8)&0xff;
672 min_red
= (key
->low
>>16)&0xff;
674 max_blue
= key
->high
&0xff;
675 max_green
= (key
->high
>>8)&0xff;
676 max_red
= (key
->high
>>16)&0xff;
678 for (x
=0; x
<width
; x
++)
679 for (y
=0; y
<height
; y
++)
682 BYTE blue
, green
, red
;
683 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
684 blue
= *src_color
&0xff;
685 green
= (*src_color
>>8)&0xff;
686 red
= (*src_color
>>16)&0xff;
687 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
688 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
689 *src_color
= 0x00000000;
693 if (attributes
->colorremaptables
[type
].enabled
||
694 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
696 const struct color_remap_table
*table
;
698 if (attributes
->colorremaptables
[type
].enabled
)
699 table
= &attributes
->colorremaptables
[type
];
701 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
703 for (x
=0; x
<width
; x
++)
704 for (y
=0; y
<height
; y
++)
707 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
708 for (i
=0; i
<table
->mapsize
; i
++)
710 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
712 *src_color
= table
->colormap
[i
].newColor
.Argb
;
719 if (attributes
->colormatrices
[type
].enabled
||
720 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
722 const struct color_matrix
*colormatrices
;
723 int color_matrix
[5][5];
724 int gray_matrix
[5][5];
727 if (attributes
->colormatrices
[type
].enabled
)
728 colormatrices
= &attributes
->colormatrices
[type
];
730 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
732 identity
= round_color_matrix(&colormatrices
->colormatrix
, color_matrix
);
734 if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
735 identity
= (round_color_matrix(&colormatrices
->graymatrix
, gray_matrix
) && identity
);
739 for (x
=0; x
<width
; x
++)
741 for (y
=0; y
<height
; y
++)
744 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
746 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
747 !color_is_gray(*src_color
))
749 *src_color
= transform_color(*src_color
, color_matrix
);
751 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
753 *src_color
= transform_color(*src_color
, gray_matrix
);
760 if (attributes
->gamma_enabled
[type
] ||
761 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
765 if (attributes
->gamma_enabled
[type
])
766 gamma
= attributes
->gamma
[type
];
768 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
770 for (x
=0; x
<width
; x
++)
771 for (y
=0; y
<height
; y
++)
774 BYTE blue
, green
, red
;
775 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
777 blue
= *src_color
&0xff;
778 green
= (*src_color
>>8)&0xff;
779 red
= (*src_color
>>16)&0xff;
781 /* FIXME: We should probably use a table for this. */
782 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
783 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
784 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
786 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
791 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
792 * bitmap that contains all the pixels we may need to draw it. */
793 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
794 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
797 INT left
, top
, right
, bottom
;
799 switch (interpolation
)
801 case InterpolationModeHighQualityBilinear
:
802 case InterpolationModeHighQualityBicubic
:
803 /* FIXME: Include a greater range for the prefilter? */
804 case InterpolationModeBicubic
:
805 case InterpolationModeBilinear
:
806 left
= (INT
)(floorf(srcx
));
807 top
= (INT
)(floorf(srcy
));
808 right
= (INT
)(ceilf(srcx
+srcwidth
));
809 bottom
= (INT
)(ceilf(srcy
+srcheight
));
811 case InterpolationModeNearestNeighbor
:
813 left
= gdip_round(srcx
);
814 top
= gdip_round(srcy
);
815 right
= gdip_round(srcx
+srcwidth
);
816 bottom
= gdip_round(srcy
+srcheight
);
820 if (wrap
== WrapModeClamp
)
826 if (right
>= bitmap
->width
)
827 right
= bitmap
->width
-1;
828 if (bottom
>= bitmap
->height
)
829 bottom
= bitmap
->height
-1;
833 /* In some cases we can make the rectangle smaller here, but the logic
834 * is hard to get right, and tiling suggests we're likely to use the
835 * entire source image. */
836 if (left
< 0 || right
>= bitmap
->width
)
839 right
= bitmap
->width
-1;
842 if (top
< 0 || bottom
>= bitmap
->height
)
845 bottom
= bitmap
->height
-1;
851 rect
->Width
= right
- left
+ 1;
852 rect
->Height
= bottom
- top
+ 1;
855 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
856 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
858 if (attributes
->wrap
== WrapModeClamp
)
860 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
861 return attributes
->outside_color
;
865 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
867 x
= width
*2 + x
% (width
* 2);
869 y
= height
*2 + y
% (height
* 2);
871 if ((attributes
->wrap
& 1) == 1)
874 if ((x
/ width
) % 2 == 0)
877 x
= width
- 1 - x
% width
;
882 if ((attributes
->wrap
& 2) == 2)
885 if ((y
/ height
) % 2 == 0)
888 y
= height
- 1 - y
% height
;
894 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
896 ERR("out of range pixel requested\n");
900 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
903 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
904 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
905 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
909 switch (interpolation
)
913 FIXME("Unimplemented interpolation %i\n", interpolation
);
915 case InterpolationModeBilinear
:
918 INT leftx
, rightx
, topy
, bottomy
;
919 ARGB topleft
, topright
, bottomleft
, bottomright
;
923 leftxf
= floorf(point
->X
);
925 rightx
= (INT
)ceilf(point
->X
);
926 topyf
= floorf(point
->Y
);
928 bottomy
= (INT
)ceilf(point
->Y
);
930 if (leftx
== rightx
&& topy
== bottomy
)
931 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
932 leftx
, topy
, attributes
);
934 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
935 leftx
, topy
, attributes
);
936 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
937 rightx
, topy
, attributes
);
938 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
939 leftx
, bottomy
, attributes
);
940 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
941 rightx
, bottomy
, attributes
);
943 x_offset
= point
->X
- leftxf
;
944 top
= blend_colors(topleft
, topright
, x_offset
);
945 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
947 return blend_colors(top
, bottom
, point
->Y
- topyf
);
949 case InterpolationModeNearestNeighbor
:
955 case PixelOffsetModeNone
:
956 case PixelOffsetModeHighSpeed
:
960 case PixelOffsetModeHalf
:
961 case PixelOffsetModeHighQuality
:
965 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
966 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
972 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
974 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
977 static BOOL
brush_can_fill_path(GpBrush
*brush
)
981 case BrushTypeSolidColor
:
983 case BrushTypeHatchFill
:
985 GpHatch
*hatch
= (GpHatch
*)brush
;
986 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
987 ((hatch
->backcol
& 0xff000000) == 0xff000000);
989 case BrushTypeLinearGradient
:
990 case BrushTypeTextureFill
:
991 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
997 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
1001 case BrushTypeSolidColor
:
1003 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1004 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1009 /* partially transparent fill */
1011 SelectClipPath(graphics
->hdc
, RGN_AND
);
1012 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1014 HDC hdc
= CreateCompatibleDC(NULL
);
1018 SelectObject(hdc
, bmp
);
1019 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1027 /* else fall through */
1031 HBRUSH gdibrush
, old_brush
;
1033 gdibrush
= create_gdi_brush(brush
);
1034 if (!gdibrush
) return;
1036 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1037 FillPath(graphics
->hdc
);
1038 SelectObject(graphics
->hdc
, old_brush
);
1039 DeleteObject(gdibrush
);
1045 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1049 case BrushTypeSolidColor
:
1050 case BrushTypeHatchFill
:
1051 case BrushTypeLinearGradient
:
1052 case BrushTypeTextureFill
:
1053 case BrushTypePathGradient
:
1060 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1061 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1065 case BrushTypeSolidColor
:
1068 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1069 for (x
=0; x
<fill_area
->Width
; x
++)
1070 for (y
=0; y
<fill_area
->Height
; y
++)
1071 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1074 case BrushTypeHatchFill
:
1077 GpHatch
*fill
= (GpHatch
*)brush
;
1078 const char *hatch_data
;
1080 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1081 return NotImplemented
;
1083 for (x
=0; x
<fill_area
->Width
; x
++)
1084 for (y
=0; y
<fill_area
->Height
; y
++)
1088 /* FIXME: Account for the rendering origin */
1089 hx
= (x
+ fill_area
->X
) % 8;
1090 hy
= (y
+ fill_area
->Y
) % 8;
1092 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1093 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1095 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1100 case BrushTypeLinearGradient
:
1102 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1103 GpPointF draw_points
[3], line_points
[3];
1105 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1106 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1109 draw_points
[0].X
= fill_area
->X
;
1110 draw_points
[0].Y
= fill_area
->Y
;
1111 draw_points
[1].X
= fill_area
->X
+1;
1112 draw_points
[1].Y
= fill_area
->Y
;
1113 draw_points
[2].X
= fill_area
->X
;
1114 draw_points
[2].Y
= fill_area
->Y
+1;
1116 /* Transform the points to a co-ordinate space where X is the point's
1117 * position in the gradient, 0.0 being the start point and 1.0 the
1119 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1120 CoordinateSpaceDevice
, draw_points
, 3);
1124 line_points
[0] = fill
->startpoint
;
1125 line_points
[1] = fill
->endpoint
;
1126 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1127 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1129 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1134 stat
= GdipInvertMatrix(world_to_gradient
);
1137 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1139 GdipDeleteMatrix(world_to_gradient
);
1144 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1145 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1147 for (y
=0; y
<fill_area
->Height
; y
++)
1149 for (x
=0; x
<fill_area
->Width
; x
++)
1151 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1153 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1160 case BrushTypeTextureFill
:
1162 GpTexture
*fill
= (GpTexture
*)brush
;
1163 GpPointF draw_points
[3];
1170 if (fill
->image
->type
!= ImageTypeBitmap
)
1172 FIXME("metafile texture brushes not implemented\n");
1173 return NotImplemented
;
1176 bitmap
= (GpBitmap
*)fill
->image
;
1177 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1179 src_area
.X
= src_area
.Y
= 0;
1180 src_area
.Width
= bitmap
->width
;
1181 src_area
.Height
= bitmap
->height
;
1183 draw_points
[0].X
= fill_area
->X
;
1184 draw_points
[0].Y
= fill_area
->Y
;
1185 draw_points
[1].X
= fill_area
->X
+1;
1186 draw_points
[1].Y
= fill_area
->Y
;
1187 draw_points
[2].X
= fill_area
->X
;
1188 draw_points
[2].Y
= fill_area
->Y
+1;
1190 /* Transform the points to the co-ordinate space of the bitmap. */
1191 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1192 CoordinateSpaceDevice
, draw_points
, 3);
1196 GpMatrix world_to_texture
= fill
->transform
;
1198 stat
= GdipInvertMatrix(&world_to_texture
);
1200 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1203 if (stat
== Ok
&& !fill
->bitmap_bits
)
1205 BitmapData lockeddata
;
1207 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1208 if (!fill
->bitmap_bits
)
1213 lockeddata
.Width
= bitmap
->width
;
1214 lockeddata
.Height
= bitmap
->height
;
1215 lockeddata
.Stride
= src_stride
;
1216 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1217 lockeddata
.Scan0
= fill
->bitmap_bits
;
1219 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1220 PixelFormat32bppARGB
, &lockeddata
);
1224 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1227 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1228 bitmap
->width
, bitmap
->height
,
1229 src_stride
, ColorAdjustTypeBitmap
);
1233 GdipFree(fill
->bitmap_bits
);
1234 fill
->bitmap_bits
= NULL
;
1240 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1241 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1242 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1243 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1245 for (y
=0; y
<fill_area
->Height
; y
++)
1247 for (x
=0; x
<fill_area
->Width
; x
++)
1250 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1251 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1253 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1254 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1255 &point
, fill
->imageattributes
, graphics
->interpolation
,
1256 graphics
->pixeloffset
);
1263 case BrushTypePathGradient
:
1265 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1267 GpMatrix world_to_device
;
1269 int i
, figure_start
=0;
1270 GpPointF start_point
, end_point
, center_point
;
1272 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1273 INT min_y
, max_y
, min_x
, max_x
;
1276 static BOOL transform_fixme_once
;
1278 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1282 FIXME("path gradient focus not implemented\n");
1289 FIXME("path gradient gamma correction not implemented\n");
1292 if (fill
->blendcount
)
1296 FIXME("path gradient blend not implemented\n");
1299 if (fill
->pblendcount
)
1303 FIXME("path gradient preset blend not implemented\n");
1306 if (!transform_fixme_once
)
1308 BOOL is_identity
=TRUE
;
1309 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1312 FIXME("path gradient transform not implemented\n");
1313 transform_fixme_once
= TRUE
;
1317 stat
= GdipClonePath(fill
->path
, &flat_path
);
1322 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1323 CoordinateSpaceWorld
, &world_to_device
);
1326 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1330 center_point
= fill
->center
;
1331 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1335 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1340 GdipDeletePath(flat_path
);
1344 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1346 int start_center_line
=0, end_center_line
=0;
1347 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1348 REAL center_distance
;
1349 ARGB start_color
, end_color
;
1352 type
= flat_path
->pathdata
.Types
[i
];
1354 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1357 start_point
= flat_path
->pathdata
.Points
[i
];
1359 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1361 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1363 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1364 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1366 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1368 end_point
= flat_path
->pathdata
.Points
[i
+1];
1369 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1374 outer_color
= start_color
;
1376 min_yf
= center_point
.Y
;
1377 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1378 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1380 if (min_yf
< fill_area
->Y
)
1381 min_y
= fill_area
->Y
;
1383 min_y
= (INT
)ceil(min_yf
);
1385 max_yf
= center_point
.Y
;
1386 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1387 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1389 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1390 max_y
= fill_area
->Y
+ fill_area
->Height
;
1392 max_y
= (INT
)ceil(max_yf
);
1394 dy
= end_point
.Y
- start_point
.Y
;
1395 dx
= end_point
.X
- start_point
.X
;
1397 /* This is proportional to the distance from start-end line to center point. */
1398 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1399 dx
* (center_point
.Y
- start_point
.Y
);
1401 for (y
=min_y
; y
<max_y
; y
++)
1405 if (!seen_start
&& yf
>= start_point
.Y
)
1408 start_center_line
^= 1;
1410 if (!seen_end
&& yf
>= end_point
.Y
)
1413 end_center_line
^= 1;
1415 if (!seen_center
&& yf
>= center_point
.Y
)
1418 start_center_line
^= 1;
1419 end_center_line
^= 1;
1422 if (start_center_line
)
1423 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1425 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1427 if (end_center_line
)
1428 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1430 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1432 if (line1_xf
< line2_xf
)
1434 min_x
= (INT
)ceil(line1_xf
);
1435 max_x
= (INT
)ceil(line2_xf
);
1439 min_x
= (INT
)ceil(line2_xf
);
1440 max_x
= (INT
)ceil(line1_xf
);
1443 if (min_x
< fill_area
->X
)
1444 min_x
= fill_area
->X
;
1445 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1446 max_x
= fill_area
->X
+ fill_area
->Width
;
1448 for (x
=min_x
; x
<max_x
; x
++)
1453 if (start_color
!= end_color
)
1455 REAL blend_amount
, pdy
, pdx
;
1456 pdy
= yf
- center_point
.Y
;
1457 pdx
= xf
- center_point
.X
;
1458 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1459 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1462 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1463 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1465 distance
= distance
/ center_distance
;
1467 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1468 blend_colors(outer_color
, fill
->centercolor
, distance
);
1473 GdipDeletePath(flat_path
);
1477 return NotImplemented
;
1481 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1482 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1483 * should not be called on an hdc that has a path you care about. */
1484 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1485 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1487 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1489 HBRUSH brush
= NULL
;
1491 PointF ptf
[4], *custptf
= NULL
;
1492 POINT pt
[4], *custpt
= NULL
;
1494 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1499 if((x1
== x2
) && (y1
== y2
))
1502 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1504 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1506 brush
= CreateSolidBrush(color
);
1507 lb
.lbStyle
= BS_SOLID
;
1510 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1511 PS_JOIN_MITER
, 1, &lb
, 0,
1513 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1514 oldpen
= SelectObject(graphics
->hdc
, pen
);
1521 case LineCapSquareAnchor
:
1522 case LineCapDiamondAnchor
:
1523 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1524 if(cap
== LineCapDiamondAnchor
){
1525 dsmall
= cos(theta
+ M_PI_2
) * size
;
1526 dbig
= sin(theta
+ M_PI_2
) * size
;
1529 dsmall
= cos(theta
+ M_PI_4
) * size
;
1530 dbig
= sin(theta
+ M_PI_4
) * size
;
1533 ptf
[0].X
= x2
- dsmall
;
1534 ptf
[1].X
= x2
+ dbig
;
1536 ptf
[0].Y
= y2
- dbig
;
1537 ptf
[3].Y
= y2
+ dsmall
;
1539 ptf
[1].Y
= y2
- dsmall
;
1540 ptf
[2].Y
= y2
+ dbig
;
1542 ptf
[3].X
= x2
- dbig
;
1543 ptf
[2].X
= x2
+ dsmall
;
1545 transform_and_round_points(graphics
, pt
, ptf
, 4);
1546 Polygon(graphics
->hdc
, pt
, 4);
1549 case LineCapArrowAnchor
:
1550 size
= size
* 4.0 / sqrt(3.0);
1552 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1553 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1558 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1559 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1567 transform_and_round_points(graphics
, pt
, ptf
, 3);
1568 Polygon(graphics
->hdc
, pt
, 3);
1571 case LineCapRoundAnchor
:
1572 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1579 transform_and_round_points(graphics
, pt
, ptf
, 2);
1580 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1583 case LineCapTriangle
:
1585 dx
= cos(M_PI_2
+ theta
) * size
;
1586 dy
= sin(M_PI_2
+ theta
) * size
;
1593 dx
= cos(theta
) * size
;
1594 dy
= sin(theta
) * size
;
1599 transform_and_round_points(graphics
, pt
, ptf
, 3);
1600 Polygon(graphics
->hdc
, pt
, 3);
1604 dx
= dy
= size
/ 2.0;
1611 dx
= -cos(M_PI_2
+ theta
) * size
;
1612 dy
= -sin(M_PI_2
+ theta
) * size
;
1619 transform_and_round_points(graphics
, pt
, ptf
, 4);
1620 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1621 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1628 count
= custom
->pathdata
.Count
;
1629 custptf
= GdipAlloc(count
* sizeof(PointF
));
1630 custpt
= GdipAlloc(count
* sizeof(POINT
));
1631 tp
= GdipAlloc(count
);
1633 if(!custptf
|| !custpt
|| !tp
)
1636 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1638 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1639 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1640 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1642 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1643 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1645 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1647 for(i
= 0; i
< count
; i
++)
1648 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1651 BeginPath(graphics
->hdc
);
1652 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1653 EndPath(graphics
->hdc
);
1654 StrokeAndFillPath(graphics
->hdc
);
1657 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1669 SelectObject(graphics
->hdc
, oldbrush
);
1670 SelectObject(graphics
->hdc
, oldpen
);
1671 DeleteObject(brush
);
1676 /* Shortens the line by the given percent by changing x2, y2.
1677 * If percent is > 1.0 then the line will change direction.
1678 * If percent is negative it can lengthen the line. */
1679 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1681 REAL dist
, theta
, dx
, dy
;
1683 if((y1
== *y2
) && (x1
== *x2
))
1686 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1687 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1688 dx
= cos(theta
) * dist
;
1689 dy
= sin(theta
) * dist
;
1695 /* Shortens the line by the given amount by changing x2, y2.
1696 * If the amount is greater than the distance, the line will become length 0.
1697 * If the amount is negative, it can lengthen the line. */
1698 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1700 REAL dx
, dy
, percent
;
1704 if(dx
== 0 && dy
== 0)
1707 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1714 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1717 /* Conducts a linear search to find the bezier points that will back off
1718 * the endpoint of the curve by a distance of amt. Linear search works
1719 * better than binary in this case because there are multiple solutions,
1720 * and binary searches often find a bad one. I don't think this is what
1721 * Windows does but short of rendering the bezier without GDI's help it's
1722 * the best we can do. If rev then work from the start of the passed points
1723 * instead of the end. */
1724 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1727 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1728 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1737 origx
= pt
[fourth
].X
;
1738 origy
= pt
[fourth
].Y
;
1739 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1741 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1742 /* reset bezier points to original values */
1743 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1744 /* Perform magic on bezier points. Order is important here.*/
1745 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1746 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1747 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1748 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1749 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1750 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1752 dx
= pt
[fourth
].X
- origx
;
1753 dy
= pt
[fourth
].Y
- origy
;
1755 diff
= sqrt(dx
* dx
+ dy
* dy
);
1756 percent
+= 0.0005 * amt
;
1760 /* Draws a combination of bezier curves and lines between points. */
1761 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1762 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1764 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1765 BYTE
*tp
= GdipAlloc(count
);
1766 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1768 GpStatus status
= GenericError
;
1774 if(!pti
|| !tp
|| !ptcopy
){
1775 status
= OutOfMemory
;
1779 for(i
= 1; i
< count
; i
++){
1780 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1781 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1782 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1783 ERR("Bad bezier points\n");
1790 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1792 /* If we are drawing caps, go through the points and adjust them accordingly,
1793 * and draw the caps. */
1795 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1796 case PathPointTypeBezier
:
1797 if(pen
->endcap
== LineCapArrowAnchor
)
1798 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1799 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1800 shorten_bezier_amt(&ptcopy
[count
- 4],
1801 pen
->width
* pen
->customend
->inset
, FALSE
);
1803 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1804 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1805 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1806 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1809 case PathPointTypeLine
:
1810 if(pen
->endcap
== LineCapArrowAnchor
)
1811 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1812 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1814 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1815 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1816 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1817 pen
->customend
->inset
* pen
->width
);
1819 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1820 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1825 ERR("Bad path last point\n");
1829 /* Find start of points */
1830 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1831 == PathPointTypeStart
); j
++);
1833 switch(types
[j
] & PathPointTypePathTypeMask
){
1834 case PathPointTypeBezier
:
1835 if(pen
->startcap
== LineCapArrowAnchor
)
1836 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1837 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1838 shorten_bezier_amt(&ptcopy
[j
- 1],
1839 pen
->width
* pen
->customstart
->inset
, TRUE
);
1841 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1842 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1843 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1844 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1847 case PathPointTypeLine
:
1848 if(pen
->startcap
== LineCapArrowAnchor
)
1849 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1850 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1852 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1853 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1854 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1855 pen
->customstart
->inset
* pen
->width
);
1857 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1858 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1863 ERR("Bad path points\n");
1868 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1870 for(i
= 0; i
< count
; i
++){
1871 tp
[i
] = convert_path_point_type(types
[i
]);
1874 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1886 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1890 BeginPath(graphics
->hdc
);
1891 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1892 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1893 EndPath(graphics
->hdc
);
1897 typedef struct _GraphicsContainerItem
{
1899 GraphicsContainer contid
;
1901 SmoothingMode smoothing
;
1902 CompositingQuality compqual
;
1903 InterpolationMode interpolation
;
1904 CompositingMode compmode
;
1905 TextRenderingHint texthint
;
1908 PixelOffsetMode pixeloffset
;
1910 GpMatrix worldtrans
;
1912 INT origin_x
, origin_y
;
1913 } GraphicsContainerItem
;
1915 static GpStatus
init_container(GraphicsContainerItem
** container
,
1916 GDIPCONST GpGraphics
* graphics
){
1919 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1923 (*container
)->contid
= graphics
->contid
+ 1;
1925 (*container
)->smoothing
= graphics
->smoothing
;
1926 (*container
)->compqual
= graphics
->compqual
;
1927 (*container
)->interpolation
= graphics
->interpolation
;
1928 (*container
)->compmode
= graphics
->compmode
;
1929 (*container
)->texthint
= graphics
->texthint
;
1930 (*container
)->scale
= graphics
->scale
;
1931 (*container
)->unit
= graphics
->unit
;
1932 (*container
)->textcontrast
= graphics
->textcontrast
;
1933 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1934 (*container
)->origin_x
= graphics
->origin_x
;
1935 (*container
)->origin_y
= graphics
->origin_y
;
1936 (*container
)->worldtrans
= graphics
->worldtrans
;
1938 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1940 GdipFree(*container
);
1948 static void delete_container(GraphicsContainerItem
* container
)
1950 GdipDeleteRegion(container
->clip
);
1951 GdipFree(container
);
1954 static GpStatus
restore_container(GpGraphics
* graphics
,
1955 GDIPCONST GraphicsContainerItem
* container
){
1959 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1960 if(sts
!= Ok
) return sts
;
1962 graphics
->worldtrans
= container
->worldtrans
;
1964 GdipDeleteRegion(graphics
->clip
);
1965 graphics
->clip
= newClip
;
1967 graphics
->contid
= container
->contid
- 1;
1969 graphics
->smoothing
= container
->smoothing
;
1970 graphics
->compqual
= container
->compqual
;
1971 graphics
->interpolation
= container
->interpolation
;
1972 graphics
->compmode
= container
->compmode
;
1973 graphics
->texthint
= container
->texthint
;
1974 graphics
->scale
= container
->scale
;
1975 graphics
->unit
= container
->unit
;
1976 graphics
->textcontrast
= container
->textcontrast
;
1977 graphics
->pixeloffset
= container
->pixeloffset
;
1978 graphics
->origin_x
= container
->origin_x
;
1979 graphics
->origin_y
= container
->origin_y
;
1984 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1990 if(graphics
->hwnd
) {
1991 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1992 return GenericError
;
1994 rect
->X
= wnd_rect
.left
;
1995 rect
->Y
= wnd_rect
.top
;
1996 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1997 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1998 }else if (graphics
->image
){
1999 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2000 if (stat
== Ok
&& unit
!= UnitPixel
)
2001 FIXME("need to convert from unit %i\n", unit
);
2002 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2009 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2010 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2012 rect
->Width
= bmp
.bmWidth
;
2013 rect
->Height
= bmp
.bmHeight
;
2024 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2025 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2028 if (graphics
->hdc
&&
2029 (GetMapMode(graphics
->hdc
) != MM_TEXT
|| GetGraphicsMode(graphics
->hdc
) != GM_COMPATIBLE
))
2033 points
[0].x
= rect
->X
;
2034 points
[0].y
= rect
->Y
;
2035 points
[1].x
= rect
->X
+ rect
->Width
;
2036 points
[1].y
= rect
->Y
+ rect
->Height
;
2038 DPtoLP(graphics
->hdc
, points
, sizeof(points
)/sizeof(points
[0]));
2040 rect
->X
= min(points
[0].x
, points
[1].x
);
2041 rect
->Y
= min(points
[0].y
, points
[1].y
);
2042 rect
->Width
= abs(points
[1].x
- points
[0].x
);
2043 rect
->Height
= abs(points
[1].y
- points
[0].y
);
2049 /* on success, rgn will contain the region of the graphics object which
2050 * is visible after clipping has been applied */
2051 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2057 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2060 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2063 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2066 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2069 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2072 GdipDeleteRegion(tmp
);
2076 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2080 if (font
->unit
== UnitPixel
)
2082 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2086 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2087 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2089 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2092 lf
->lfHeight
= -(height
+ 0.5);
2094 lf
->lfEscapement
= 0;
2095 lf
->lfOrientation
= 0;
2096 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2097 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2098 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2099 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2100 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2101 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2102 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2103 lf
->lfQuality
= DEFAULT_QUALITY
;
2104 lf
->lfPitchAndFamily
= 0;
2105 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2108 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2109 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2110 GDIPCONST GpMatrix
*matrix
)
2112 HDC hdc
= CreateCompatibleDC(0);
2114 REAL angle
, rel_width
, rel_height
, font_height
;
2116 HFONT unscaled_font
;
2117 TEXTMETRICW textmet
;
2119 if (font
->unit
== UnitPixel
)
2120 font_height
= font
->emSize
;
2123 REAL unit_scale
, res
;
2125 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2126 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2128 font_height
= font
->emSize
* unit_scale
;
2139 GpMatrix xform
= *matrix
;
2140 GdipTransformMatrixPoints(&xform
, pt
, 3);
2143 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2144 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2145 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2146 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2147 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2148 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2150 get_log_fontW(font
, graphics
, &lfw
);
2151 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2152 unscaled_font
= CreateFontIndirectW(&lfw
);
2154 SelectObject(hdc
, unscaled_font
);
2155 GetTextMetricsW(hdc
, &textmet
);
2157 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2158 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2160 *hfont
= CreateFontIndirectW(&lfw
);
2163 DeleteObject(unscaled_font
);
2166 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2168 TRACE("(%p, %p)\n", hdc
, graphics
);
2170 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2173 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2179 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2182 FIXME("Don't know how to handle parameter hDevice\n");
2187 if(graphics
== NULL
)
2188 return InvalidParameter
;
2190 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2191 if(!*graphics
) return OutOfMemory
;
2193 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2195 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2196 GdipFree(*graphics
);
2200 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2201 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2202 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2204 (*graphics
)->alpha_hdc
= 1;
2207 (*graphics
)->hdc
= hdc
;
2208 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2209 (*graphics
)->owndc
= FALSE
;
2210 (*graphics
)->smoothing
= SmoothingModeDefault
;
2211 (*graphics
)->compqual
= CompositingQualityDefault
;
2212 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2213 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2214 (*graphics
)->compmode
= CompositingModeSourceOver
;
2215 (*graphics
)->unit
= UnitDisplay
;
2216 (*graphics
)->scale
= 1.0;
2217 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2218 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2219 (*graphics
)->busy
= FALSE
;
2220 (*graphics
)->textcontrast
= 4;
2221 list_init(&(*graphics
)->containers
);
2222 (*graphics
)->contid
= 0;
2224 TRACE("<-- %p\n", *graphics
);
2229 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2233 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2234 if(!*graphics
) return OutOfMemory
;
2236 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2238 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2239 GdipFree(*graphics
);
2243 (*graphics
)->hdc
= NULL
;
2244 (*graphics
)->hwnd
= NULL
;
2245 (*graphics
)->owndc
= FALSE
;
2246 (*graphics
)->image
= image
;
2247 /* We have to store the image type here because the image may be freed
2248 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2249 (*graphics
)->image_type
= image
->type
;
2250 (*graphics
)->smoothing
= SmoothingModeDefault
;
2251 (*graphics
)->compqual
= CompositingQualityDefault
;
2252 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2253 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2254 (*graphics
)->compmode
= CompositingModeSourceOver
;
2255 (*graphics
)->unit
= UnitDisplay
;
2256 (*graphics
)->scale
= 1.0;
2257 (*graphics
)->xres
= image
->xres
;
2258 (*graphics
)->yres
= image
->yres
;
2259 (*graphics
)->busy
= FALSE
;
2260 (*graphics
)->textcontrast
= 4;
2261 list_init(&(*graphics
)->containers
);
2262 (*graphics
)->contid
= 0;
2264 TRACE("<-- %p\n", *graphics
);
2269 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2274 TRACE("(%p, %p)\n", hwnd
, graphics
);
2278 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2280 ReleaseDC(hwnd
, hdc
);
2284 (*graphics
)->hwnd
= hwnd
;
2285 (*graphics
)->owndc
= TRUE
;
2290 /* FIXME: no icm handling */
2291 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2293 TRACE("(%p, %p)\n", hwnd
, graphics
);
2295 return GdipCreateFromHWND(hwnd
, graphics
);
2298 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2299 UINT access
, IStream
**stream
)
2304 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2306 if(!stream
|| !filename
)
2307 return InvalidParameter
;
2309 if(access
& GENERIC_WRITE
)
2310 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2311 else if(access
& GENERIC_READ
)
2312 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2314 return InvalidParameter
;
2316 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2318 return hresult_to_status(ret
);
2321 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2323 GraphicsContainerItem
*cont
, *next
;
2325 TRACE("(%p)\n", graphics
);
2327 if(!graphics
) return InvalidParameter
;
2328 if(graphics
->busy
) return ObjectBusy
;
2330 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2332 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2338 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2340 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2341 list_remove(&cont
->entry
);
2342 delete_container(cont
);
2345 GdipDeleteRegion(graphics
->clip
);
2347 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2348 * do otherwise, but we can't have that in the test suite because it means
2349 * accessing freed memory. */
2350 graphics
->busy
= TRUE
;
2357 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2358 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2363 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2364 width
, height
, startAngle
, sweepAngle
);
2366 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2367 return InvalidParameter
;
2372 status
= GdipCreatePath(FillModeAlternate
, &path
);
2373 if (status
!= Ok
) return status
;
2375 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2377 status
= GdipDrawPath(graphics
, pen
, path
);
2379 GdipDeletePath(path
);
2383 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2384 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2386 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2387 width
, height
, startAngle
, sweepAngle
);
2389 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2392 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2393 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2397 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2398 x2
, y2
, x3
, y3
, x4
, y4
);
2400 if(!graphics
|| !pen
)
2401 return InvalidParameter
;
2414 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2417 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2418 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2420 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2421 x2
, y2
, x3
, y3
, x4
, y4
);
2423 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2426 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2427 GDIPCONST GpPointF
*points
, INT count
)
2432 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2434 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2435 return InvalidParameter
;
2440 status
= GdipCreatePath(FillModeAlternate
, &path
);
2441 if (status
!= Ok
) return status
;
2443 status
= GdipAddPathBeziers(path
, points
, count
);
2445 status
= GdipDrawPath(graphics
, pen
, path
);
2447 GdipDeletePath(path
);
2451 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2452 GDIPCONST GpPoint
*points
, INT count
)
2458 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2460 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2461 return InvalidParameter
;
2466 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2470 for(i
= 0; i
< count
; i
++){
2471 pts
[i
].X
= (REAL
)points
[i
].X
;
2472 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2475 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2482 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2483 GDIPCONST GpPointF
*points
, INT count
)
2485 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2487 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2490 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2491 GDIPCONST GpPoint
*points
, INT count
)
2493 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2495 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2498 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2499 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2504 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2506 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2507 return InvalidParameter
;
2512 status
= GdipCreatePath(FillModeAlternate
, &path
);
2513 if (status
!= Ok
) return status
;
2515 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2517 status
= GdipDrawPath(graphics
, pen
, path
);
2519 GdipDeletePath(path
);
2524 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2525 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2531 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2533 if(!points
|| count
<= 0)
2534 return InvalidParameter
;
2536 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2540 for(i
= 0; i
< count
; i
++){
2541 ptf
[i
].X
= (REAL
)points
[i
].X
;
2542 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2545 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2552 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2553 GDIPCONST GpPointF
*points
, INT count
)
2555 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2557 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2560 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2561 GDIPCONST GpPoint
*points
, INT count
)
2567 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2570 return InvalidParameter
;
2572 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2576 for(i
= 0; i
< count
; i
++){
2577 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2578 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2581 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2587 /* Approximates cardinal spline with Bezier curves. */
2588 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2589 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2594 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2596 if(!graphics
|| !pen
)
2597 return InvalidParameter
;
2603 return InvalidParameter
;
2605 status
= GdipCreatePath(FillModeAlternate
, &path
);
2606 if (status
!= Ok
) return status
;
2608 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2610 status
= GdipDrawPath(graphics
, pen
, path
);
2612 GdipDeletePath(path
);
2616 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2617 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2623 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2626 return InvalidParameter
;
2628 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2632 for(i
= 0; i
< count
; i
++){
2633 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2634 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2637 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2643 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2644 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2647 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2649 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2650 return InvalidParameter
;
2653 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2656 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2657 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2660 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2666 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2667 return InvalidParameter
;
2670 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2673 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2674 REAL y
, REAL width
, REAL height
)
2679 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2681 if(!graphics
|| !pen
)
2682 return InvalidParameter
;
2687 status
= GdipCreatePath(FillModeAlternate
, &path
);
2688 if (status
!= Ok
) return status
;
2690 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2692 status
= GdipDrawPath(graphics
, pen
, path
);
2694 GdipDeletePath(path
);
2698 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2699 INT y
, INT width
, INT height
)
2701 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2703 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2707 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2711 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2713 if(!graphics
|| !image
)
2714 return InvalidParameter
;
2716 GdipGetImageWidth(image
, &width
);
2717 GdipGetImageHeight(image
, &height
);
2719 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2720 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2723 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2726 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2728 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2731 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2732 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2736 REAL scale_x
, scale_y
, width
, height
;
2738 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2740 if (!graphics
|| !image
) return InvalidParameter
;
2742 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2743 scale_x
*= graphics
->xres
/ image
->xres
;
2744 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2745 scale_y
*= graphics
->yres
/ image
->yres
;
2746 width
= srcwidth
* scale_x
;
2747 height
= srcheight
* scale_y
;
2749 points
[0].X
= points
[2].X
= x
;
2750 points
[0].Y
= points
[1].Y
= y
;
2751 points
[1].X
= x
+ width
;
2752 points
[2].Y
= y
+ height
;
2754 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2755 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2758 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2759 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2762 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2765 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2766 GDIPCONST GpPointF
*dstpoints
, INT count
)
2770 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2773 return InvalidParameter
;
2775 GdipGetImageWidth(image
, &width
);
2776 GdipGetImageHeight(image
, &height
);
2778 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2779 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2782 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2783 GDIPCONST GpPoint
*dstpoints
, INT count
)
2787 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2789 if (count
!= 3 || !dstpoints
)
2790 return InvalidParameter
;
2792 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2793 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2794 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2795 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2796 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2797 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2799 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2802 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2803 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2805 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2809 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2810 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2811 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2812 DrawImageAbort callback
, VOID
* callbackData
)
2818 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2819 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2823 return NotImplemented
;
2825 if(!graphics
|| !image
|| !points
|| count
!= 3)
2826 return InvalidParameter
;
2828 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2829 debugstr_pointf(&points
[2]));
2831 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2833 /* Ensure source width/height is positive */
2836 GpPointF tmp
= ptf
[1];
2837 srcx
= srcx
+ srcwidth
;
2838 srcwidth
= -srcwidth
;
2839 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2840 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2847 GpPointF tmp
= ptf
[2];
2848 srcy
= srcy
+ srcheight
;
2849 srcheight
= -srcheight
;
2850 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
2851 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
2856 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2857 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2858 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
2860 transform_and_round_points(graphics
, pti
, ptf
, 4);
2862 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2863 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2865 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2866 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2867 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2868 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2869 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2875 FIXME("graphics object has no HDC\n");
2878 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2879 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2880 srcx
, srcy
, srcwidth
, srcheight
, NULL
) != S_OK
)
2883 callback(callbackData
);
2884 return GenericError
;
2887 else if (image
->type
== ImageTypeBitmap
)
2889 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2890 BOOL do_resampling
= FALSE
;
2891 BOOL use_software
= FALSE
;
2893 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2894 graphics
->xres
, graphics
->yres
,
2895 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2896 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2897 imageAttributes
? imageAttributes
->outside_color
: 0);
2899 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2900 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2901 srcx
< 0 || srcy
< 0 ||
2902 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2903 do_resampling
= TRUE
;
2905 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
2906 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
2907 use_software
= TRUE
;
2912 GpRectF graphics_bounds
;
2914 int i
, x
, y
, src_stride
, dst_stride
;
2915 GpMatrix dst_to_src
;
2916 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2917 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
2918 BitmapData lockeddata
;
2919 InterpolationMode interpolation
= graphics
->interpolation
;
2920 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2921 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2922 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2923 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2925 if (!imageAttributes
)
2926 imageAttributes
= &defaultImageAttributes
;
2928 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2929 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2932 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2933 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2934 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2935 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2938 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
2939 if (stat
!= Ok
) return stat
;
2941 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
2942 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
2943 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
2944 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
2946 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
2948 if (IsRectEmpty(&dst_area
)) return Ok
;
2950 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2951 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2952 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2953 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2954 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2955 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2957 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
2959 stat
= GdipInvertMatrix(&dst_to_src
);
2960 if (stat
!= Ok
) return stat
;
2964 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2965 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2969 /* Make sure src_area is equal in size to dst_area. */
2970 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
2971 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
2972 src_area
.Width
= dst_area
.right
- dst_area
.left
;
2973 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
2976 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
2978 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
2981 src_stride
= sizeof(ARGB
) * src_area
.Width
;
2983 /* Read the bits we need from the source bitmap into an ARGB buffer. */
2984 lockeddata
.Width
= src_area
.Width
;
2985 lockeddata
.Height
= src_area
.Height
;
2986 lockeddata
.Stride
= src_stride
;
2987 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
2988 lockeddata
.Scan0
= src_data
;
2990 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
2991 PixelFormat32bppARGB
, &lockeddata
);
2994 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3002 apply_image_attributes(imageAttributes
, src_data
,
3003 src_area
.Width
, src_area
.Height
,
3004 src_stride
, ColorAdjustTypeBitmap
);
3008 /* Transform the bits as needed to the destination. */
3009 dst_data
= dst_dyn_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3016 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3018 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3020 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3021 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3022 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3023 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3025 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3027 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3029 GpPointF src_pointf
;
3032 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3033 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3035 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3037 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3038 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3039 imageAttributes
, interpolation
, offset_mode
);
3047 dst_data
= src_data
;
3048 dst_stride
= src_stride
;
3051 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3052 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3056 GdipFree(dst_dyn_data
);
3063 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3064 HBITMAP hbitmap
, old_hbm
=NULL
;
3066 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3067 bitmap
->format
== PixelFormat24bppRGB
||
3068 bitmap
->format
== PixelFormat32bppRGB
||
3069 bitmap
->format
== PixelFormat32bppPARGB
))
3071 BITMAPINFOHEADER bih
;
3073 PixelFormat dst_format
;
3075 /* we can't draw a bitmap of this format directly */
3076 hdc
= CreateCompatibleDC(0);
3080 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3081 bih
.biWidth
= bitmap
->width
;
3082 bih
.biHeight
= -bitmap
->height
;
3084 bih
.biBitCount
= 32;
3085 bih
.biCompression
= BI_RGB
;
3086 bih
.biSizeImage
= 0;
3087 bih
.biXPelsPerMeter
= 0;
3088 bih
.biYPelsPerMeter
= 0;
3090 bih
.biClrImportant
= 0;
3092 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3093 (void**)&temp_bits
, NULL
, 0);
3095 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3096 dst_format
= PixelFormat32bppPARGB
;
3098 dst_format
= PixelFormat32bppRGB
;
3100 convert_pixels(bitmap
->width
, bitmap
->height
,
3101 bitmap
->width
*4, temp_bits
, dst_format
,
3102 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3103 bitmap
->image
.palette
);
3107 if (bitmap
->hbitmap
)
3108 hbitmap
= bitmap
->hbitmap
;
3111 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3116 temp_hdc
= (hdc
== 0);
3121 if (!hdc
) hdc
= CreateCompatibleDC(0);
3122 old_hbm
= SelectObject(hdc
, hbitmap
);
3125 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3127 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3128 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3132 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3133 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3138 SelectObject(hdc
, old_hbm
);
3143 DeleteObject(hbitmap
);
3146 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3152 rc
.Width
= srcwidth
;
3153 rc
.Height
= srcheight
;
3155 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3156 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3160 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3161 return InvalidParameter
;
3167 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3168 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3169 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3170 DrawImageAbort callback
, VOID
* callbackData
)
3172 GpPointF pointsF
[3];
3175 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3176 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3179 if(!points
|| count
!=3)
3180 return InvalidParameter
;
3182 for(i
= 0; i
< count
; i
++){
3183 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3184 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3187 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3188 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3189 callback
, callbackData
);
3192 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3193 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3194 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3195 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3196 VOID
* callbackData
)
3200 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3201 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3202 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3206 points
[1].X
= dstx
+ dstwidth
;
3209 points
[2].Y
= dsty
+ dstheight
;
3211 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3212 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3215 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3216 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3217 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3218 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3219 VOID
* callbackData
)
3223 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3224 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3225 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3229 points
[1].X
= dstx
+ dstwidth
;
3232 points
[2].Y
= dsty
+ dstheight
;
3234 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3235 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3238 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3239 REAL x
, REAL y
, REAL width
, REAL height
)
3245 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3247 if(!graphics
|| !image
)
3248 return InvalidParameter
;
3250 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3254 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3255 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3256 unit
, NULL
, NULL
, NULL
);
3259 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3260 INT x
, INT y
, INT width
, INT height
)
3262 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3264 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3267 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3268 REAL y1
, REAL x2
, REAL y2
)
3272 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3278 return GdipDrawLines(graphics
, pen
, pt
, 2);
3281 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3282 INT y1
, INT x2
, INT y2
)
3284 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3286 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3289 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3290 GpPointF
*points
, INT count
)
3295 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3297 if(!pen
|| !graphics
|| (count
< 2))
3298 return InvalidParameter
;
3303 status
= GdipCreatePath(FillModeAlternate
, &path
);
3304 if (status
!= Ok
) return status
;
3306 status
= GdipAddPathLine2(path
, points
, count
);
3308 status
= GdipDrawPath(graphics
, pen
, path
);
3310 GdipDeletePath(path
);
3314 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3315 GpPoint
*points
, INT count
)
3321 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3323 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3324 if(!ptf
) return OutOfMemory
;
3326 for(i
= 0; i
< count
; i
++){
3327 ptf
[i
].X
= (REAL
) points
[i
].X
;
3328 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3331 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3337 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3343 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3345 if(!pen
|| !graphics
)
3346 return InvalidParameter
;
3353 FIXME("graphics object has no HDC\n");
3357 save_state
= prepare_dc(graphics
, pen
);
3359 retval
= get_clip_hrgn(graphics
, &hrgn
);
3365 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3367 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3368 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3371 restore_dc(graphics
, save_state
);
3377 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3378 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3383 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3384 width
, height
, startAngle
, sweepAngle
);
3386 if(!graphics
|| !pen
)
3387 return InvalidParameter
;
3392 status
= GdipCreatePath(FillModeAlternate
, &path
);
3393 if (status
!= Ok
) return status
;
3395 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3397 status
= GdipDrawPath(graphics
, pen
, path
);
3399 GdipDeletePath(path
);
3403 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3404 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3406 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3407 width
, height
, startAngle
, sweepAngle
);
3409 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3412 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3413 REAL y
, REAL width
, REAL height
)
3418 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3420 if(!pen
|| !graphics
)
3421 return InvalidParameter
;
3426 status
= GdipCreatePath(FillModeAlternate
, &path
);
3427 if (status
!= Ok
) return status
;
3429 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3431 status
= GdipDrawPath(graphics
, pen
, path
);
3433 GdipDeletePath(path
);
3437 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3438 INT y
, INT width
, INT height
)
3440 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3442 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3445 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3446 GDIPCONST GpRectF
* rects
, INT count
)
3451 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3453 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3454 return InvalidParameter
;
3459 status
= GdipCreatePath(FillModeAlternate
, &path
);
3460 if (status
!= Ok
) return status
;
3462 status
= GdipAddPathRectangles(path
, rects
, count
);
3464 status
= GdipDrawPath(graphics
, pen
, path
);
3466 GdipDeletePath(path
);
3470 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3471 GDIPCONST GpRect
* rects
, INT count
)
3477 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3479 if(!rects
|| count
<=0)
3480 return InvalidParameter
;
3482 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3486 for(i
= 0;i
< count
;i
++){
3487 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3488 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3489 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3490 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3493 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3499 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3500 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3505 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3506 count
, tension
, fill
);
3508 if(!graphics
|| !brush
|| !points
)
3509 return InvalidParameter
;
3514 if(count
== 1) /* Do nothing */
3517 status
= GdipCreatePath(fill
, &path
);
3518 if (status
!= Ok
) return status
;
3520 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3522 status
= GdipFillPath(graphics
, brush
, path
);
3524 GdipDeletePath(path
);
3528 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3529 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3535 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3536 count
, tension
, fill
);
3538 if(!points
|| count
== 0)
3539 return InvalidParameter
;
3541 if(count
== 1) /* Do nothing */
3544 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3548 for(i
= 0;i
< count
;i
++){
3549 ptf
[i
].X
= (REAL
)points
[i
].X
;
3550 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3553 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3560 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3561 GDIPCONST GpPointF
*points
, INT count
)
3563 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3564 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3565 0.5f
, FillModeAlternate
);
3568 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3569 GDIPCONST GpPoint
*points
, INT count
)
3571 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3572 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3573 0.5f
, FillModeAlternate
);
3576 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3577 REAL y
, REAL width
, REAL height
)
3582 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3584 if(!graphics
|| !brush
)
3585 return InvalidParameter
;
3590 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3594 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3597 stat
= GdipFillPath(graphics
, brush
, path
);
3599 GdipDeletePath(path
);
3605 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3606 INT y
, INT width
, INT height
)
3608 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3610 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3613 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3619 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3620 return NotImplemented
;
3622 save_state
= SaveDC(graphics
->hdc
);
3623 EndPath(graphics
->hdc
);
3624 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3627 retval
= get_clip_hrgn(graphics
, &hrgn
);
3633 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3635 BeginPath(graphics
->hdc
);
3636 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3637 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3642 EndPath(graphics
->hdc
);
3643 brush_fill_path(graphics
, brush
);
3648 RestoreDC(graphics
->hdc
, save_state
);
3654 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3659 if (!brush_can_fill_pixels(brush
))
3660 return NotImplemented
;
3662 /* FIXME: This could probably be done more efficiently without regions. */
3664 stat
= GdipCreateRegionPath(path
, &rgn
);
3668 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3670 GdipDeleteRegion(rgn
);
3676 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3678 GpStatus stat
= NotImplemented
;
3680 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3682 if(!brush
|| !graphics
|| !path
)
3683 return InvalidParameter
;
3688 if (!graphics
->image
&& !graphics
->alpha_hdc
)
3689 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3691 if (stat
== NotImplemented
)
3692 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3694 if (stat
== NotImplemented
)
3696 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3703 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3704 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3709 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3710 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3712 if(!graphics
|| !brush
)
3713 return InvalidParameter
;
3718 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3722 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3725 stat
= GdipFillPath(graphics
, brush
, path
);
3727 GdipDeletePath(path
);
3733 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3734 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3736 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3737 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3739 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3742 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3743 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3748 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3750 if(!graphics
|| !brush
|| !points
|| !count
)
3751 return InvalidParameter
;
3756 stat
= GdipCreatePath(fillMode
, &path
);
3760 stat
= GdipAddPathPolygon(path
, points
, count
);
3763 stat
= GdipFillPath(graphics
, brush
, path
);
3765 GdipDeletePath(path
);
3771 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3772 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3777 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3779 if(!graphics
|| !brush
|| !points
|| !count
)
3780 return InvalidParameter
;
3785 stat
= GdipCreatePath(fillMode
, &path
);
3789 stat
= GdipAddPathPolygonI(path
, points
, count
);
3792 stat
= GdipFillPath(graphics
, brush
, path
);
3794 GdipDeletePath(path
);
3800 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3801 GDIPCONST GpPointF
*points
, INT count
)
3803 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3805 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3808 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3809 GDIPCONST GpPoint
*points
, INT count
)
3811 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3813 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3816 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3817 REAL x
, REAL y
, REAL width
, REAL height
)
3821 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3826 rect
.Height
= height
;
3828 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
3831 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3832 INT x
, INT y
, INT width
, INT height
)
3836 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3840 rect
.Width
= (REAL
)width
;
3841 rect
.Height
= (REAL
)height
;
3843 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
3846 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3852 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3854 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
3855 return InvalidParameter
;
3857 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
3859 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
3860 /* FIXME: Add gdi32 drawing. */
3864 status
= GdipCreatePath(FillModeAlternate
, &path
);
3865 if (status
!= Ok
) return status
;
3867 status
= GdipAddPathRectangles(path
, rects
, count
);
3869 status
= GdipFillPath(graphics
, brush
, path
);
3871 GdipDeletePath(path
);
3875 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3882 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3884 if(!rects
|| count
<= 0)
3885 return InvalidParameter
;
3887 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3891 for(i
= 0; i
< count
; i
++){
3892 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3893 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3894 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3895 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3898 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3904 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3912 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3913 return NotImplemented
;
3915 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3919 save_state
= SaveDC(graphics
->hdc
);
3920 EndPath(graphics
->hdc
);
3922 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3924 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3926 BeginPath(graphics
->hdc
);
3927 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3928 EndPath(graphics
->hdc
);
3930 brush_fill_path(graphics
, brush
);
3933 RestoreDC(graphics
->hdc
, save_state
);
3940 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3944 GpRegion
*temp_region
;
3945 GpMatrix world_to_device
;
3946 GpRectF graphics_bounds
;
3950 GpRect gp_bound_rect
;
3952 if (!brush_can_fill_pixels(brush
))
3953 return NotImplemented
;
3955 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3958 stat
= GdipCloneRegion(region
, &temp_region
);
3962 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3963 CoordinateSpaceWorld
, &world_to_device
);
3966 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
3969 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
3972 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
3974 GdipDeleteRegion(temp_region
);
3977 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
3979 DeleteObject(hregion
);
3985 gp_bound_rect
.X
= bound_rect
.left
;
3986 gp_bound_rect
.Y
= bound_rect
.top
;
3987 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
3988 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
3990 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
3996 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
3997 &gp_bound_rect
, gp_bound_rect
.Width
);
4000 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4001 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4002 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4004 GdipFree(pixel_data
);
4007 DeleteObject(hregion
);
4013 /*****************************************************************************
4014 * GdipFillRegion [GDIPLUS.@]
4016 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4019 GpStatus stat
= NotImplemented
;
4021 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4023 if (!(graphics
&& brush
&& region
))
4024 return InvalidParameter
;
4029 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4030 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4032 if (stat
== NotImplemented
)
4033 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4035 if (stat
== NotImplemented
)
4037 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4044 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4046 TRACE("(%p,%u)\n", graphics
, intention
);
4049 return InvalidParameter
;
4054 /* We have no internal operation queue, so there's no need to clear it. */
4062 /*****************************************************************************
4063 * GdipGetClipBounds [GDIPLUS.@]
4065 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4070 TRACE("(%p, %p)\n", graphics
, rect
);
4073 return InvalidParameter
;
4078 status
= GdipCreateRegion(&clip
);
4079 if (status
!= Ok
) return status
;
4081 status
= GdipGetClip(graphics
, clip
);
4083 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4085 GdipDeleteRegion(clip
);
4089 /*****************************************************************************
4090 * GdipGetClipBoundsI [GDIPLUS.@]
4092 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4094 TRACE("(%p, %p)\n", graphics
, rect
);
4097 return InvalidParameter
;
4102 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4105 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4106 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4107 CompositingMode
*mode
)
4109 TRACE("(%p, %p)\n", graphics
, mode
);
4111 if(!graphics
|| !mode
)
4112 return InvalidParameter
;
4117 *mode
= graphics
->compmode
;
4122 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4123 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4124 CompositingQuality
*quality
)
4126 TRACE("(%p, %p)\n", graphics
, quality
);
4128 if(!graphics
|| !quality
)
4129 return InvalidParameter
;
4134 *quality
= graphics
->compqual
;
4139 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4140 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4141 InterpolationMode
*mode
)
4143 TRACE("(%p, %p)\n", graphics
, mode
);
4145 if(!graphics
|| !mode
)
4146 return InvalidParameter
;
4151 *mode
= graphics
->interpolation
;
4156 /* FIXME: Need to handle color depths less than 24bpp */
4157 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4159 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4161 if(!graphics
|| !argb
)
4162 return InvalidParameter
;
4170 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4172 TRACE("(%p, %p)\n", graphics
, scale
);
4174 if(!graphics
|| !scale
)
4175 return InvalidParameter
;
4180 *scale
= graphics
->scale
;
4185 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4187 TRACE("(%p, %p)\n", graphics
, unit
);
4189 if(!graphics
|| !unit
)
4190 return InvalidParameter
;
4195 *unit
= graphics
->unit
;
4200 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4201 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4204 TRACE("(%p, %p)\n", graphics
, mode
);
4206 if(!graphics
|| !mode
)
4207 return InvalidParameter
;
4212 *mode
= graphics
->pixeloffset
;
4217 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4218 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4220 TRACE("(%p, %p)\n", graphics
, mode
);
4222 if(!graphics
|| !mode
)
4223 return InvalidParameter
;
4228 *mode
= graphics
->smoothing
;
4233 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4235 TRACE("(%p, %p)\n", graphics
, contrast
);
4237 if(!graphics
|| !contrast
)
4238 return InvalidParameter
;
4240 *contrast
= graphics
->textcontrast
;
4245 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4246 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4247 TextRenderingHint
*hint
)
4249 TRACE("(%p, %p)\n", graphics
, hint
);
4251 if(!graphics
|| !hint
)
4252 return InvalidParameter
;
4257 *hint
= graphics
->texthint
;
4262 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4267 TRACE("(%p, %p)\n", graphics
, rect
);
4269 if(!graphics
|| !rect
)
4270 return InvalidParameter
;
4275 /* intersect window and graphics clipping regions */
4276 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4279 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4282 /* get bounds of the region */
4283 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4286 GdipDeleteRegion(clip_rgn
);
4291 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4296 TRACE("(%p, %p)\n", graphics
, rect
);
4298 if(!graphics
|| !rect
)
4299 return InvalidParameter
;
4301 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4303 rect
->X
= gdip_round(rectf
.X
);
4304 rect
->Y
= gdip_round(rectf
.Y
);
4305 rect
->Width
= gdip_round(rectf
.Width
);
4306 rect
->Height
= gdip_round(rectf
.Height
);
4312 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4314 TRACE("(%p, %p)\n", graphics
, matrix
);
4316 if(!graphics
|| !matrix
)
4317 return InvalidParameter
;
4322 *matrix
= graphics
->worldtrans
;
4326 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4332 TRACE("(%p, %x)\n", graphics
, color
);
4335 return InvalidParameter
;
4340 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4343 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4344 GdipDeleteBrush((GpBrush
*)brush
);
4348 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4349 wnd_rect
.Width
, wnd_rect
.Height
);
4351 GdipDeleteBrush((GpBrush
*)brush
);
4356 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4358 TRACE("(%p, %p)\n", graphics
, res
);
4360 if(!graphics
|| !res
)
4361 return InvalidParameter
;
4363 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4366 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4372 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4374 if(!graphics
|| !result
)
4375 return InvalidParameter
;
4382 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4383 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4386 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4389 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4392 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4395 GdipDeleteRegion(rgn
);
4399 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4401 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4404 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4410 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4412 if(!graphics
|| !result
)
4413 return InvalidParameter
;
4420 pts
[1].X
= x
+ width
;
4421 pts
[1].Y
= y
+ height
;
4423 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4424 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4427 pts
[1].X
-= pts
[0].X
;
4428 pts
[1].Y
-= pts
[0].Y
;
4430 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4433 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4436 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4439 GdipDeleteRegion(rgn
);
4443 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4445 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4448 GpStatus
gdip_format_string(HDC hdc
,
4449 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4450 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4451 gdip_format_string_callback callback
, void *user_data
)
4454 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4455 nheight
, lineend
, lineno
= 0;
4457 StringAlignment halign
;
4460 HotkeyPrefix hkprefix
;
4461 INT
*hotkeyprefix_offsets
=NULL
;
4462 INT hotkeyprefix_count
=0;
4463 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4464 BOOL seen_prefix
= FALSE
;
4465 GpStringFormat
*dyn_format
=NULL
;
4467 if(length
== -1) length
= lstrlenW(string
);
4469 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4470 if(!stringdup
) return OutOfMemory
;
4474 stat
= GdipStringFormatGetGenericDefault(&dyn_format
);
4477 GdipFree(stringdup
);
4480 format
= dyn_format
;
4483 nwidth
= rect
->Width
;
4484 nheight
= rect
->Height
;
4485 if (ignore_empty_clip
)
4487 if (!nwidth
) nwidth
= INT_MAX
;
4488 if (!nheight
) nheight
= INT_MAX
;
4491 hkprefix
= format
->hkprefix
;
4493 if (hkprefix
== HotkeyPrefixShow
)
4495 for (i
=0; i
<length
; i
++)
4497 if (string
[i
] == '&')
4498 hotkeyprefix_count
++;
4502 if (hotkeyprefix_count
)
4503 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4505 hotkeyprefix_count
= 0;
4507 for(i
= 0, j
= 0; i
< length
; i
++){
4508 /* FIXME: This makes the indexes passed to callback inaccurate. */
4509 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4512 /* FIXME: tabs should be handled using tabstops from stringformat */
4513 if (string
[i
] == '\t')
4516 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4517 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4518 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4524 seen_prefix
= FALSE
;
4526 stringdup
[j
] = string
[i
];
4532 halign
= format
->align
;
4534 while(sum
< length
){
4535 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4536 nwidth
, &fit
, NULL
, &size
);
4542 for(lret
= 0; lret
< fit
; lret
++)
4543 if(*(stringdup
+ sum
+ lret
) == '\n')
4546 /* Line break code (may look strange, but it imitates windows). */
4548 lineend
= fit
= lret
; /* this is not an off-by-one error */
4549 else if(fit
< (length
- sum
)){
4550 if(*(stringdup
+ sum
+ fit
) == ' ')
4551 while(*(stringdup
+ sum
+ fit
) == ' ')
4554 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4557 if(*(stringdup
+ sum
+ fit
) == '\t')
4566 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4567 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4573 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4574 nwidth
, &j
, NULL
, &size
);
4576 bounds
.Width
= size
.cx
;
4578 if(height
+ size
.cy
> nheight
)
4580 if (format
->attr
& StringFormatFlagsLineLimit
)
4582 bounds
.Height
= nheight
- (height
+ size
.cy
);
4585 bounds
.Height
= size
.cy
;
4587 bounds
.Y
= rect
->Y
+ height
;
4591 case StringAlignmentNear
:
4595 case StringAlignmentCenter
:
4596 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4598 case StringAlignmentFar
:
4599 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4603 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4604 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4607 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4608 font
, rect
, format
, lineno
, &bounds
,
4609 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4610 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4615 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4619 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4621 if(height
> nheight
)
4624 /* Stop if this was a linewrap (but not if it was a linebreak). */
4625 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
4629 GdipFree(stringdup
);
4630 GdipFree(hotkeyprefix_offsets
);
4631 GdipDeleteStringFormat(dyn_format
);
4636 struct measure_ranges_args
{
4638 REAL rel_width
, rel_height
;
4641 static GpStatus
measure_ranges_callback(HDC hdc
,
4642 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4643 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4644 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4645 INT underlined_index_count
, void *user_data
)
4649 struct measure_ranges_args
*args
= user_data
;
4651 for (i
=0; i
<format
->range_count
; i
++)
4653 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4654 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4655 if (range_start
< range_end
)
4660 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4661 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4663 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4664 INT_MAX
, NULL
, NULL
, &range_size
);
4665 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4667 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4668 INT_MAX
, NULL
, NULL
, &range_size
);
4669 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4671 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4680 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4681 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4682 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4683 INT regionCount
, GpRegion
** regions
)
4687 HFONT gdifont
, oldfont
;
4688 struct measure_ranges_args args
;
4689 HDC hdc
, temp_hdc
=NULL
;
4694 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4695 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4697 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4698 return InvalidParameter
;
4700 if (regionCount
< stringFormat
->range_count
)
4701 return InvalidParameter
;
4705 hdc
= temp_hdc
= CreateCompatibleDC(0);
4706 if (!temp_hdc
) return OutOfMemory
;
4709 hdc
= graphics
->hdc
;
4711 if (stringFormat
->attr
)
4712 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4720 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4721 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4722 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4723 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4724 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4726 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4727 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4729 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4730 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4731 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
4732 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
4734 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
4735 oldfont
= SelectObject(hdc
, gdifont
);
4737 for (i
=0; i
<stringFormat
->range_count
; i
++)
4739 stat
= GdipSetEmpty(regions
[i
]);
4744 args
.regions
= regions
;
4746 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
4747 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
4749 SelectObject(hdc
, oldfont
);
4750 DeleteObject(gdifont
);
4758 struct measure_string_args
{
4760 INT
*codepointsfitted
;
4762 REAL rel_width
, rel_height
;
4765 static GpStatus
measure_string_callback(HDC hdc
,
4766 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4767 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4768 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4769 INT underlined_index_count
, void *user_data
)
4771 struct measure_string_args
*args
= user_data
;
4772 REAL new_width
, new_height
;
4774 new_width
= bounds
->Width
/ args
->rel_width
;
4775 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
4777 if (new_width
> args
->bounds
->Width
)
4778 args
->bounds
->Width
= new_width
;
4780 if (new_height
> args
->bounds
->Height
)
4781 args
->bounds
->Height
= new_height
;
4783 if (args
->codepointsfitted
)
4784 *args
->codepointsfitted
= index
+ length
;
4786 if (args
->linesfilled
)
4787 (*args
->linesfilled
)++;
4792 /* Find the smallest rectangle that bounds the text when it is printed in rect
4793 * according to the format options listed in format. If rect has 0 width and
4794 * height, then just find the smallest rectangle that bounds the text when it's
4795 * printed at location (rect->X, rect-Y). */
4796 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4797 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4798 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4799 INT
*codepointsfitted
, INT
*linesfilled
)
4801 HFONT oldfont
, gdifont
;
4802 struct measure_string_args args
;
4803 HDC temp_hdc
=NULL
, hdc
;
4809 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4810 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4811 bounds
, codepointsfitted
, linesfilled
);
4813 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4814 return InvalidParameter
;
4818 hdc
= temp_hdc
= CreateCompatibleDC(0);
4819 if (!temp_hdc
) return OutOfMemory
;
4822 hdc
= graphics
->hdc
;
4824 if(linesfilled
) *linesfilled
= 0;
4825 if(codepointsfitted
) *codepointsfitted
= 0;
4828 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4836 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4837 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4838 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4839 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4840 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4842 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4843 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4845 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
4846 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
4847 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
4848 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
4849 if (scaled_rect
.Width
>= 0.5)
4851 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4852 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4855 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4856 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4858 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
4859 oldfont
= SelectObject(hdc
, gdifont
);
4861 bounds
->X
= rect
->X
;
4862 bounds
->Y
= rect
->Y
;
4863 bounds
->Width
= 0.0;
4864 bounds
->Height
= 0.0;
4866 args
.bounds
= bounds
;
4867 args
.codepointsfitted
= &glyphs
;
4868 args
.linesfilled
= &lines
;
4871 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
4872 measure_string_callback
, &args
);
4874 if (linesfilled
) *linesfilled
= lines
;
4875 if (codepointsfitted
) *codepointsfitted
= glyphs
;
4878 bounds
->Width
+= margin_x
* 2.0;
4880 SelectObject(hdc
, oldfont
);
4881 DeleteObject(gdifont
);
4889 struct draw_string_args
{
4890 GpGraphics
*graphics
;
4891 GDIPCONST GpBrush
*brush
;
4892 REAL x
, y
, rel_width
, rel_height
, ascent
;
4895 static GpStatus
draw_string_callback(HDC hdc
,
4896 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4897 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4898 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4899 INT underlined_index_count
, void *user_data
)
4901 struct draw_string_args
*args
= user_data
;
4905 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4906 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4908 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
4909 args
->brush
, &position
,
4910 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4912 if (stat
== Ok
&& underlined_index_count
)
4914 OUTLINETEXTMETRICW otm
;
4915 REAL underline_y
, underline_height
;
4918 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
4920 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
4921 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
4923 for (i
=0; i
<underlined_index_count
; i
++)
4925 REAL start_x
, end_x
;
4927 INT ofs
= underlined_indexes
[i
] - index
;
4929 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
4930 start_x
= text_size
.cx
/ args
->rel_width
;
4932 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
4933 end_x
= text_size
.cx
/ args
->rel_width
;
4935 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
4942 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4943 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4944 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4948 GpPointF pt
[3], rectcpy
[4];
4950 REAL rel_width
, rel_height
, margin_x
;
4951 INT save_state
, format_flags
= 0;
4953 struct draw_string_args args
;
4955 HDC hdc
, temp_hdc
=NULL
;
4956 TEXTMETRICW textmetric
;
4958 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4959 length
, font
, debugstr_rectf(rect
), format
, brush
);
4961 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4962 return InvalidParameter
;
4966 hdc
= graphics
->hdc
;
4970 hdc
= temp_hdc
= CreateCompatibleDC(0);
4974 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4976 format_flags
= format
->attr
;
4978 /* Should be no need to explicitly test for StringAlignmentNear as
4979 * that is default behavior if no alignment is passed. */
4980 if(format
->vertalign
!= StringAlignmentNear
){
4981 RectF bounds
, in_rect
= *rect
;
4982 in_rect
.Height
= 0.0; /* avoid height clipping */
4983 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
4985 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
4987 if(format
->vertalign
== StringAlignmentCenter
)
4988 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4989 else if(format
->vertalign
== StringAlignmentFar
)
4990 offsety
= (rect
->Height
- bounds
.Height
);
4992 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
4995 save_state
= SaveDC(hdc
);
5003 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5004 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5005 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5006 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5007 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5009 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5010 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5011 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5012 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5013 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5015 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5016 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5018 scaled_rect
.X
= margin_x
* rel_width
;
5019 scaled_rect
.Y
= 0.0;
5020 scaled_rect
.Width
= rel_width
* rect
->Width
;
5021 scaled_rect
.Height
= rel_height
* rect
->Height
;
5022 if (scaled_rect
.Width
>= 0.5)
5024 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5025 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5028 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5029 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5031 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5032 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5033 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5035 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5036 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5037 SelectClipRgn(hdc
, rgn
);
5040 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5041 SelectObject(hdc
, gdifont
);
5043 args
.graphics
= graphics
;
5047 args
.y
= rect
->Y
+ offsety
;
5049 args
.rel_width
= rel_width
;
5050 args
.rel_height
= rel_height
;
5052 GetTextMetricsW(hdc
, &textmetric
);
5053 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5055 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5056 draw_string_callback
, &args
);
5059 DeleteObject(gdifont
);
5061 RestoreDC(hdc
, save_state
);
5068 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5070 TRACE("(%p)\n", graphics
);
5073 return InvalidParameter
;
5078 return GdipSetInfinite(graphics
->clip
);
5081 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5083 TRACE("(%p)\n", graphics
);
5086 return InvalidParameter
;
5091 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5094 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5096 return GdipEndContainer(graphics
, state
);
5099 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5100 GpMatrixOrder order
)
5102 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5105 return InvalidParameter
;
5110 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5113 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5115 return GdipBeginContainer2(graphics
, state
);
5118 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5119 GraphicsContainer
*state
)
5121 GraphicsContainerItem
*container
;
5124 TRACE("(%p, %p)\n", graphics
, state
);
5126 if(!graphics
|| !state
)
5127 return InvalidParameter
;
5129 sts
= init_container(&container
, graphics
);
5133 list_add_head(&graphics
->containers
, &container
->entry
);
5134 *state
= graphics
->contid
= container
->contid
;
5139 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5141 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5142 return NotImplemented
;
5145 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5147 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5148 return NotImplemented
;
5151 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5153 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5154 return NotImplemented
;
5157 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5160 GraphicsContainerItem
*container
, *container2
;
5162 TRACE("(%p, %x)\n", graphics
, state
);
5165 return InvalidParameter
;
5167 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5168 if(container
->contid
== state
)
5172 /* did not find a matching container */
5173 if(&container
->entry
== &graphics
->containers
)
5176 sts
= restore_container(graphics
, container
);
5180 /* remove all of the containers on top of the found container */
5181 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5182 if(container
->contid
== state
)
5184 list_remove(&container
->entry
);
5185 delete_container(container
);
5188 list_remove(&container
->entry
);
5189 delete_container(container
);
5194 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5195 REAL sy
, GpMatrixOrder order
)
5197 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5200 return InvalidParameter
;
5205 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5208 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5211 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5213 if(!graphics
|| !srcgraphics
)
5214 return InvalidParameter
;
5216 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5219 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5220 CompositingMode mode
)
5222 TRACE("(%p, %d)\n", graphics
, mode
);
5225 return InvalidParameter
;
5230 graphics
->compmode
= mode
;
5235 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5236 CompositingQuality quality
)
5238 TRACE("(%p, %d)\n", graphics
, quality
);
5241 return InvalidParameter
;
5246 graphics
->compqual
= quality
;
5251 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5252 InterpolationMode mode
)
5254 TRACE("(%p, %d)\n", graphics
, mode
);
5256 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5257 return InvalidParameter
;
5262 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5263 mode
= InterpolationModeBilinear
;
5265 if (mode
== InterpolationModeHighQuality
)
5266 mode
= InterpolationModeHighQualityBicubic
;
5268 graphics
->interpolation
= mode
;
5273 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5277 TRACE("(%p, %.2f)\n", graphics
, scale
);
5279 if(!graphics
|| (scale
<= 0.0))
5280 return InvalidParameter
;
5285 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5287 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
5292 graphics
->scale
= scale
;
5297 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5301 TRACE("(%p, %d)\n", graphics
, unit
);
5304 return InvalidParameter
;
5309 if(unit
== UnitWorld
)
5310 return InvalidParameter
;
5312 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5314 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
5319 graphics
->unit
= unit
;
5324 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5327 TRACE("(%p, %d)\n", graphics
, mode
);
5330 return InvalidParameter
;
5335 graphics
->pixeloffset
= mode
;
5340 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5344 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5347 FIXME("value is unused in rendering\n");
5350 return InvalidParameter
;
5352 graphics
->origin_x
= x
;
5353 graphics
->origin_y
= y
;
5358 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5360 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5362 if (!graphics
|| !x
|| !y
)
5363 return InvalidParameter
;
5365 *x
= graphics
->origin_x
;
5366 *y
= graphics
->origin_y
;
5371 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5373 TRACE("(%p, %d)\n", graphics
, mode
);
5376 return InvalidParameter
;
5381 graphics
->smoothing
= mode
;
5386 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5388 TRACE("(%p, %d)\n", graphics
, contrast
);
5391 return InvalidParameter
;
5393 graphics
->textcontrast
= contrast
;
5398 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5399 TextRenderingHint hint
)
5401 TRACE("(%p, %d)\n", graphics
, hint
);
5403 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5404 return InvalidParameter
;
5409 graphics
->texthint
= hint
;
5414 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5416 TRACE("(%p, %p)\n", graphics
, matrix
);
5418 if(!graphics
|| !matrix
)
5419 return InvalidParameter
;
5424 TRACE("%f,%f,%f,%f,%f,%f\n",
5425 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5426 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5428 graphics
->worldtrans
= *matrix
;
5433 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5434 REAL dy
, GpMatrixOrder order
)
5436 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5439 return InvalidParameter
;
5444 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5447 /*****************************************************************************
5448 * GdipSetClipHrgn [GDIPLUS.@]
5450 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5455 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5458 return InvalidParameter
;
5463 /* hrgn is already in device units */
5464 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5468 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5470 GdipDeleteRegion(region
);
5474 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5479 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5482 return InvalidParameter
;
5487 status
= GdipClonePath(path
, &clip_path
);
5490 GpMatrix world_to_device
;
5492 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
5493 CoordinateSpaceWorld
, &world_to_device
);
5494 status
= GdipTransformPath(clip_path
, &world_to_device
);
5496 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
5498 GdipDeletePath(clip_path
);
5503 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5504 REAL width
, REAL height
,
5511 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5514 return InvalidParameter
;
5522 rect
.Height
= height
;
5523 status
= GdipCreateRegionRect(&rect
, ®ion
);
5526 GpMatrix world_to_device
;
5528 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5529 status
= GdipTransformRegion(region
, &world_to_device
);
5531 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5533 GdipDeleteRegion(region
);
5538 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5539 INT width
, INT height
,
5542 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5545 return InvalidParameter
;
5550 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5553 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5559 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5561 if(!graphics
|| !region
)
5562 return InvalidParameter
;
5567 status
= GdipCloneRegion(region
, &clip
);
5570 GpMatrix world_to_device
;
5572 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5573 status
= GdipTransformRegion(clip
, &world_to_device
);
5575 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
5577 GdipDeleteRegion(clip
);
5582 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5588 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5590 if(!graphics
|| !pen
|| count
<=0)
5591 return InvalidParameter
;
5598 FIXME("graphics object has no HDC\n");
5602 pti
= GdipAlloc(sizeof(POINT
) * count
);
5604 save_state
= prepare_dc(graphics
, pen
);
5605 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5607 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5608 Polygon(graphics
->hdc
, pti
, count
);
5610 restore_dc(graphics
, save_state
);
5616 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5623 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5625 if(count
<=0) return InvalidParameter
;
5626 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5628 for(i
= 0;i
< count
; i
++){
5629 ptf
[i
].X
= (REAL
)points
[i
].X
;
5630 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5633 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5639 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5641 TRACE("(%p, %p)\n", graphics
, dpi
);
5643 if(!graphics
|| !dpi
)
5644 return InvalidParameter
;
5649 *dpi
= graphics
->xres
;
5653 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5655 TRACE("(%p, %p)\n", graphics
, dpi
);
5657 if(!graphics
|| !dpi
)
5658 return InvalidParameter
;
5663 *dpi
= graphics
->yres
;
5667 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5668 GpMatrixOrder order
)
5673 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5675 if(!graphics
|| !matrix
)
5676 return InvalidParameter
;
5681 m
= graphics
->worldtrans
;
5683 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5685 graphics
->worldtrans
= m
;
5690 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5691 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5693 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5697 TRACE("(%p, %p)\n", graphics
, hdc
);
5699 if(!graphics
|| !hdc
)
5700 return InvalidParameter
;
5705 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5707 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5709 else if (!graphics
->hdc
|| graphics
->alpha_hdc
||
5710 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5712 /* Create a fake HDC and fill it with a constant color. */
5716 BITMAPINFOHEADER bmih
;
5719 stat
= get_graphics_bounds(graphics
, &bounds
);
5723 graphics
->temp_hbitmap_width
= bounds
.Width
;
5724 graphics
->temp_hbitmap_height
= bounds
.Height
;
5726 bmih
.biSize
= sizeof(bmih
);
5727 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5728 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5730 bmih
.biBitCount
= 32;
5731 bmih
.biCompression
= BI_RGB
;
5732 bmih
.biSizeImage
= 0;
5733 bmih
.biXPelsPerMeter
= 0;
5734 bmih
.biYPelsPerMeter
= 0;
5736 bmih
.biClrImportant
= 0;
5738 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5739 (void**)&graphics
->temp_bits
, NULL
, 0);
5741 return GenericError
;
5743 temp_hdc
= CreateCompatibleDC(0);
5746 DeleteObject(hbitmap
);
5747 return GenericError
;
5750 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5751 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5753 SelectObject(temp_hdc
, hbitmap
);
5755 graphics
->temp_hbitmap
= hbitmap
;
5756 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5760 *hdc
= graphics
->hdc
;
5764 graphics
->busy
= TRUE
;
5769 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5773 TRACE("(%p, %p)\n", graphics
, hdc
);
5775 if(!graphics
|| !hdc
|| !graphics
->busy
)
5776 return InvalidParameter
;
5778 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5780 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5782 else if (graphics
->temp_hdc
== hdc
)
5787 /* Find the pixels that have changed, and mark them as opaque. */
5788 pos
= (DWORD
*)graphics
->temp_bits
;
5789 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5791 if (*pos
!= DC_BACKGROUND_KEY
)
5798 /* Write the changed pixels to the real target. */
5799 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5800 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5801 graphics
->temp_hbitmap_width
* 4);
5804 DeleteDC(graphics
->temp_hdc
);
5805 DeleteObject(graphics
->temp_hbitmap
);
5806 graphics
->temp_hdc
= NULL
;
5807 graphics
->temp_hbitmap
= NULL
;
5809 else if (hdc
!= graphics
->hdc
)
5811 stat
= InvalidParameter
;
5815 graphics
->busy
= FALSE
;
5820 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5824 GpMatrix device_to_world
;
5826 TRACE("(%p, %p)\n", graphics
, region
);
5828 if(!graphics
|| !region
)
5829 return InvalidParameter
;
5834 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5837 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
5838 status
= GdipTransformRegion(clip
, &device_to_world
);
5841 GdipDeleteRegion(clip
);
5845 /* free everything except root node and header */
5846 delete_element(®ion
->node
);
5847 memcpy(region
, clip
, sizeof(GpRegion
));
5853 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5854 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
5857 REAL scale_x
, scale_y
;
5859 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5861 if (dst_space
!= src_space
)
5863 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5864 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5866 if(graphics
->unit
!= UnitDisplay
)
5868 scale_x
*= graphics
->scale
;
5869 scale_y
*= graphics
->scale
;
5872 /* transform from src_space to CoordinateSpacePage */
5875 case CoordinateSpaceWorld
:
5876 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
5878 case CoordinateSpacePage
:
5880 case CoordinateSpaceDevice
:
5881 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
5885 /* transform from CoordinateSpacePage to dst_space */
5888 case CoordinateSpaceWorld
:
5890 GpMatrix inverted_transform
= graphics
->worldtrans
;
5891 stat
= GdipInvertMatrix(&inverted_transform
);
5893 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
5896 case CoordinateSpacePage
:
5898 case CoordinateSpaceDevice
:
5899 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
5906 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5907 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5912 if(!graphics
|| !points
|| count
<= 0)
5913 return InvalidParameter
;
5918 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5920 if (src_space
== dst_space
) return Ok
;
5922 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5923 if (stat
!= Ok
) return stat
;
5925 return GdipTransformMatrixPoints(&matrix
, points
, count
);
5928 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5929 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5935 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5938 return InvalidParameter
;
5940 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5944 for(i
= 0; i
< count
; i
++){
5945 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5946 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5949 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5952 for(i
= 0; i
< count
; i
++){
5953 points
[i
].X
= gdip_round(pointsF
[i
].X
);
5954 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
5961 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5973 /*****************************************************************************
5974 * GdipTranslateClip [GDIPLUS.@]
5976 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5978 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5981 return InvalidParameter
;
5986 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5989 /*****************************************************************************
5990 * GdipTranslateClipI [GDIPLUS.@]
5992 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5994 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5997 return InvalidParameter
;
6002 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6006 /*****************************************************************************
6007 * GdipMeasureDriverString [GDIPLUS.@]
6009 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6010 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6011 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6013 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6016 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6018 TEXTMETRICW textmetric
;
6019 const WORD
*glyph_indices
;
6020 WORD
*dynamic_glyph_indices
=NULL
;
6021 REAL rel_width
, rel_height
, ascent
, descent
;
6024 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6026 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6027 return InvalidParameter
;
6030 length
= strlenW(text
);
6034 boundingBox
->X
= 0.0;
6035 boundingBox
->Y
= 0.0;
6036 boundingBox
->Width
= 0.0;
6037 boundingBox
->Height
= 0.0;
6040 if (flags
& unsupported_flags
)
6041 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6043 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6045 hdc
= CreateCompatibleDC(0);
6046 SelectObject(hdc
, hfont
);
6048 GetTextMetricsW(hdc
, &textmetric
);
6058 GpMatrix xform
= *matrix
;
6059 GdipTransformMatrixPoints(&xform
, pt
, 3);
6061 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6062 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6063 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6064 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6065 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6067 if (flags
& DriverStringOptionsCmapLookup
)
6069 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6073 DeleteObject(hfont
);
6077 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6080 glyph_indices
= text
;
6082 min_x
= max_x
= x
= positions
[0].X
;
6083 min_y
= max_y
= y
= positions
[0].Y
;
6085 ascent
= textmetric
.tmAscent
/ rel_height
;
6086 descent
= textmetric
.tmDescent
/ rel_height
;
6088 for (i
=0; i
<length
; i
++)
6093 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6099 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6100 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6102 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6103 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6104 if (min_x
> x
) min_x
= x
;
6106 x
+= char_width
/ rel_width
;
6108 if (max_x
< x
) max_x
= x
;
6111 GdipFree(dynamic_glyph_indices
);
6113 DeleteObject(hfont
);
6115 boundingBox
->X
= min_x
;
6116 boundingBox
->Y
= min_y
;
6117 boundingBox
->Width
= max_x
- min_x
;
6118 boundingBox
->Height
= max_y
- min_y
;
6123 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6124 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6125 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6126 INT flags
, GDIPCONST GpMatrix
*matrix
)
6128 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6134 if (flags
& unsupported_flags
)
6135 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6137 if (!(flags
& DriverStringOptionsCmapLookup
))
6138 eto_flags
|= ETO_GLYPH_INDEX
;
6140 save_state
= SaveDC(graphics
->hdc
);
6141 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6142 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6145 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6147 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6148 SelectObject(graphics
->hdc
, hfont
);
6150 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6152 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6154 RestoreDC(graphics
->hdc
, save_state
);
6156 DeleteObject(hfont
);
6161 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6162 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6163 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6164 INT flags
, GDIPCONST GpMatrix
*matrix
)
6166 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6168 PointF
*real_positions
, real_position
;
6172 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6173 DWORD max_glyphsize
=0;
6174 GLYPHMETRICS glyphmetrics
;
6175 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6178 int text_mask_stride
;
6180 int pixel_data_stride
;
6182 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6187 if (!(flags
& DriverStringOptionsCmapLookup
))
6188 ggo_flags
|= GGO_GLYPH_INDEX
;
6190 if (flags
& unsupported_flags
)
6191 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6193 pti
= GdipAlloc(sizeof(POINT
) * length
);
6197 if (flags
& DriverStringOptionsRealizedAdvance
)
6199 real_position
= positions
[0];
6201 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6205 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6206 if (!real_positions
)
6212 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6214 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6216 GdipFree(real_positions
);
6219 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6221 hdc
= CreateCompatibleDC(0);
6222 SelectObject(hdc
, hfont
);
6224 /* Get the boundaries of the text to be drawn */
6225 for (i
=0; i
<length
; i
++)
6228 int left
, top
, right
, bottom
;
6230 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6231 &glyphmetrics
, 0, NULL
, &identity
);
6233 if (glyphsize
== GDI_ERROR
)
6235 ERR("GetGlyphOutlineW failed\n");
6238 DeleteObject(hfont
);
6239 return GenericError
;
6242 if (glyphsize
> max_glyphsize
)
6243 max_glyphsize
= glyphsize
;
6247 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6248 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6249 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6250 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6252 if (left
< min_x
) min_x
= left
;
6253 if (top
< min_y
) min_y
= top
;
6254 if (right
> max_x
) max_x
= right
;
6255 if (bottom
> max_y
) max_y
= bottom
;
6258 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6260 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6261 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6265 if (max_glyphsize
== 0)
6266 /* Nothing to draw. */
6269 glyph_mask
= GdipAlloc(max_glyphsize
);
6270 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6271 text_mask_stride
= max_x
- min_x
;
6273 if (!(glyph_mask
&& text_mask
))
6275 GdipFree(glyph_mask
);
6276 GdipFree(text_mask
);
6279 DeleteObject(hfont
);
6283 /* Generate a mask for the text */
6284 for (i
=0; i
<length
; i
++)
6287 int left
, top
, stride
;
6289 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6290 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6292 if (ret
== GDI_ERROR
|| ret
== 0)
6293 continue; /* empty glyph */
6295 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6296 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6297 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6299 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6301 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6302 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6303 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6305 *text_val
= min(64, *text_val
+ *glyph_val
);
6314 DeleteObject(hfont
);
6315 GdipFree(glyph_mask
);
6317 /* get the brush data */
6318 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6321 GdipFree(text_mask
);
6325 pixel_area
.X
= min_x
;
6326 pixel_area
.Y
= min_y
;
6327 pixel_area
.Width
= max_x
- min_x
;
6328 pixel_area
.Height
= max_y
- min_y
;
6329 pixel_data_stride
= pixel_area
.Width
* 4;
6331 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6334 GdipFree(text_mask
);
6335 GdipFree(pixel_data
);
6339 /* multiply the brush data by the mask */
6340 for (y
=0; y
<pixel_area
.Height
; y
++)
6342 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6343 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6344 for (x
=0; x
<pixel_area
.Width
; x
++)
6346 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6352 GdipFree(text_mask
);
6354 /* draw the result */
6355 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6356 pixel_area
.Height
, pixel_data_stride
);
6358 GdipFree(pixel_data
);
6363 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6364 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6365 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6366 INT flags
, GDIPCONST GpMatrix
*matrix
)
6368 GpStatus stat
= NotImplemented
;
6371 length
= strlenW(text
);
6373 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6374 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6375 brush
->bt
== BrushTypeSolidColor
&&
6376 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6377 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6378 brush
, positions
, flags
, matrix
);
6379 if (stat
== NotImplemented
)
6380 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6381 brush
, positions
, flags
, matrix
);
6385 /*****************************************************************************
6386 * GdipDrawDriverString [GDIPLUS.@]
6388 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6389 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6390 GDIPCONST PointF
*positions
, INT flags
,
6391 GDIPCONST GpMatrix
*matrix
)
6393 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6395 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6396 return InvalidParameter
;
6398 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6399 brush
, positions
, flags
, matrix
);
6402 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6403 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6405 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6406 return NotImplemented
;
6409 /*****************************************************************************
6410 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6412 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6417 TRACE("(%p, %p)\n", graphics
, res
);
6419 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6422 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6425 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6428 GdipDeleteRegion(rgn
);
6432 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6436 TRACE("(%p) stub\n", graphics
);
6439 FIXME("not implemented\n");
6441 return NotImplemented
;