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;
830 if (bottom
< top
|| right
< left
)
831 /* entirely outside image, just sample a pixel so we don't have to
832 * special-case this later */
833 left
= top
= right
= bottom
= 0;
837 /* In some cases we can make the rectangle smaller here, but the logic
838 * is hard to get right, and tiling suggests we're likely to use the
839 * entire source image. */
840 if (left
< 0 || right
>= bitmap
->width
)
843 right
= bitmap
->width
-1;
846 if (top
< 0 || bottom
>= bitmap
->height
)
849 bottom
= bitmap
->height
-1;
855 rect
->Width
= right
- left
+ 1;
856 rect
->Height
= bottom
- top
+ 1;
859 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
860 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
862 if (attributes
->wrap
== WrapModeClamp
)
864 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
865 return attributes
->outside_color
;
869 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
871 x
= width
*2 + x
% (width
* 2);
873 y
= height
*2 + y
% (height
* 2);
875 if ((attributes
->wrap
& 1) == 1)
878 if ((x
/ width
) % 2 == 0)
881 x
= width
- 1 - x
% width
;
886 if ((attributes
->wrap
& 2) == 2)
889 if ((y
/ height
) % 2 == 0)
892 y
= height
- 1 - y
% height
;
898 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
900 ERR("out of range pixel requested\n");
904 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
907 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
908 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
909 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
913 switch (interpolation
)
917 FIXME("Unimplemented interpolation %i\n", interpolation
);
919 case InterpolationModeBilinear
:
922 INT leftx
, rightx
, topy
, bottomy
;
923 ARGB topleft
, topright
, bottomleft
, bottomright
;
927 leftxf
= floorf(point
->X
);
929 rightx
= (INT
)ceilf(point
->X
);
930 topyf
= floorf(point
->Y
);
932 bottomy
= (INT
)ceilf(point
->Y
);
934 if (leftx
== rightx
&& topy
== bottomy
)
935 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
936 leftx
, topy
, attributes
);
938 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
939 leftx
, topy
, attributes
);
940 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
941 rightx
, topy
, attributes
);
942 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
943 leftx
, bottomy
, attributes
);
944 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
945 rightx
, bottomy
, attributes
);
947 x_offset
= point
->X
- leftxf
;
948 top
= blend_colors(topleft
, topright
, x_offset
);
949 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
951 return blend_colors(top
, bottom
, point
->Y
- topyf
);
953 case InterpolationModeNearestNeighbor
:
959 case PixelOffsetModeNone
:
960 case PixelOffsetModeHighSpeed
:
964 case PixelOffsetModeHalf
:
965 case PixelOffsetModeHighQuality
:
969 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
970 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
976 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
978 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
981 static BOOL
brush_can_fill_path(GpBrush
*brush
)
985 case BrushTypeSolidColor
:
987 case BrushTypeHatchFill
:
989 GpHatch
*hatch
= (GpHatch
*)brush
;
990 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
991 ((hatch
->backcol
& 0xff000000) == 0xff000000);
993 case BrushTypeLinearGradient
:
994 case BrushTypeTextureFill
:
995 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
1001 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
1005 case BrushTypeSolidColor
:
1007 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1008 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1013 /* partially transparent fill */
1015 SelectClipPath(graphics
->hdc
, RGN_AND
);
1016 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1018 HDC hdc
= CreateCompatibleDC(NULL
);
1022 SelectObject(hdc
, bmp
);
1023 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1031 /* else fall through */
1035 HBRUSH gdibrush
, old_brush
;
1037 gdibrush
= create_gdi_brush(brush
);
1038 if (!gdibrush
) return;
1040 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1041 FillPath(graphics
->hdc
);
1042 SelectObject(graphics
->hdc
, old_brush
);
1043 DeleteObject(gdibrush
);
1049 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1053 case BrushTypeSolidColor
:
1054 case BrushTypeHatchFill
:
1055 case BrushTypeLinearGradient
:
1056 case BrushTypeTextureFill
:
1057 case BrushTypePathGradient
:
1064 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1065 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1069 case BrushTypeSolidColor
:
1072 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1073 for (x
=0; x
<fill_area
->Width
; x
++)
1074 for (y
=0; y
<fill_area
->Height
; y
++)
1075 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1078 case BrushTypeHatchFill
:
1081 GpHatch
*fill
= (GpHatch
*)brush
;
1082 const char *hatch_data
;
1084 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1085 return NotImplemented
;
1087 for (x
=0; x
<fill_area
->Width
; x
++)
1088 for (y
=0; y
<fill_area
->Height
; y
++)
1092 /* FIXME: Account for the rendering origin */
1093 hx
= (x
+ fill_area
->X
) % 8;
1094 hy
= (y
+ fill_area
->Y
) % 8;
1096 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1097 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1099 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1104 case BrushTypeLinearGradient
:
1106 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1107 GpPointF draw_points
[3], line_points
[3];
1109 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1110 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1113 draw_points
[0].X
= fill_area
->X
;
1114 draw_points
[0].Y
= fill_area
->Y
;
1115 draw_points
[1].X
= fill_area
->X
+1;
1116 draw_points
[1].Y
= fill_area
->Y
;
1117 draw_points
[2].X
= fill_area
->X
;
1118 draw_points
[2].Y
= fill_area
->Y
+1;
1120 /* Transform the points to a co-ordinate space where X is the point's
1121 * position in the gradient, 0.0 being the start point and 1.0 the
1123 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1124 CoordinateSpaceDevice
, draw_points
, 3);
1128 line_points
[0] = fill
->startpoint
;
1129 line_points
[1] = fill
->endpoint
;
1130 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1131 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1133 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1138 stat
= GdipInvertMatrix(world_to_gradient
);
1141 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1143 GdipDeleteMatrix(world_to_gradient
);
1148 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1149 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1151 for (y
=0; y
<fill_area
->Height
; y
++)
1153 for (x
=0; x
<fill_area
->Width
; x
++)
1155 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1157 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1164 case BrushTypeTextureFill
:
1166 GpTexture
*fill
= (GpTexture
*)brush
;
1167 GpPointF draw_points
[3];
1174 if (fill
->image
->type
!= ImageTypeBitmap
)
1176 FIXME("metafile texture brushes not implemented\n");
1177 return NotImplemented
;
1180 bitmap
= (GpBitmap
*)fill
->image
;
1181 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1183 src_area
.X
= src_area
.Y
= 0;
1184 src_area
.Width
= bitmap
->width
;
1185 src_area
.Height
= bitmap
->height
;
1187 draw_points
[0].X
= fill_area
->X
;
1188 draw_points
[0].Y
= fill_area
->Y
;
1189 draw_points
[1].X
= fill_area
->X
+1;
1190 draw_points
[1].Y
= fill_area
->Y
;
1191 draw_points
[2].X
= fill_area
->X
;
1192 draw_points
[2].Y
= fill_area
->Y
+1;
1194 /* Transform the points to the co-ordinate space of the bitmap. */
1195 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1196 CoordinateSpaceDevice
, draw_points
, 3);
1200 GpMatrix world_to_texture
= fill
->transform
;
1202 stat
= GdipInvertMatrix(&world_to_texture
);
1204 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1207 if (stat
== Ok
&& !fill
->bitmap_bits
)
1209 BitmapData lockeddata
;
1211 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1212 if (!fill
->bitmap_bits
)
1217 lockeddata
.Width
= bitmap
->width
;
1218 lockeddata
.Height
= bitmap
->height
;
1219 lockeddata
.Stride
= src_stride
;
1220 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1221 lockeddata
.Scan0
= fill
->bitmap_bits
;
1223 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1224 PixelFormat32bppARGB
, &lockeddata
);
1228 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1231 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1232 bitmap
->width
, bitmap
->height
,
1233 src_stride
, ColorAdjustTypeBitmap
);
1237 GdipFree(fill
->bitmap_bits
);
1238 fill
->bitmap_bits
= NULL
;
1244 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1245 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1246 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1247 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1249 for (y
=0; y
<fill_area
->Height
; y
++)
1251 for (x
=0; x
<fill_area
->Width
; x
++)
1254 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1255 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1257 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1258 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1259 &point
, fill
->imageattributes
, graphics
->interpolation
,
1260 graphics
->pixeloffset
);
1267 case BrushTypePathGradient
:
1269 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1271 GpMatrix world_to_device
;
1273 int i
, figure_start
=0;
1274 GpPointF start_point
, end_point
, center_point
;
1276 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1277 INT min_y
, max_y
, min_x
, max_x
;
1280 static BOOL transform_fixme_once
;
1282 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1286 FIXME("path gradient focus not implemented\n");
1293 FIXME("path gradient gamma correction not implemented\n");
1296 if (fill
->blendcount
)
1300 FIXME("path gradient blend not implemented\n");
1303 if (fill
->pblendcount
)
1307 FIXME("path gradient preset blend not implemented\n");
1310 if (!transform_fixme_once
)
1312 BOOL is_identity
=TRUE
;
1313 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1316 FIXME("path gradient transform not implemented\n");
1317 transform_fixme_once
= TRUE
;
1321 stat
= GdipClonePath(fill
->path
, &flat_path
);
1326 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1327 CoordinateSpaceWorld
, &world_to_device
);
1330 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1334 center_point
= fill
->center
;
1335 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1339 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1344 GdipDeletePath(flat_path
);
1348 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1350 int start_center_line
=0, end_center_line
=0;
1351 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1352 REAL center_distance
;
1353 ARGB start_color
, end_color
;
1356 type
= flat_path
->pathdata
.Types
[i
];
1358 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1361 start_point
= flat_path
->pathdata
.Points
[i
];
1363 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1365 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1367 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1368 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1370 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1372 end_point
= flat_path
->pathdata
.Points
[i
+1];
1373 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1378 outer_color
= start_color
;
1380 min_yf
= center_point
.Y
;
1381 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1382 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1384 if (min_yf
< fill_area
->Y
)
1385 min_y
= fill_area
->Y
;
1387 min_y
= (INT
)ceil(min_yf
);
1389 max_yf
= center_point
.Y
;
1390 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1391 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1393 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1394 max_y
= fill_area
->Y
+ fill_area
->Height
;
1396 max_y
= (INT
)ceil(max_yf
);
1398 dy
= end_point
.Y
- start_point
.Y
;
1399 dx
= end_point
.X
- start_point
.X
;
1401 /* This is proportional to the distance from start-end line to center point. */
1402 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1403 dx
* (center_point
.Y
- start_point
.Y
);
1405 for (y
=min_y
; y
<max_y
; y
++)
1409 if (!seen_start
&& yf
>= start_point
.Y
)
1412 start_center_line
^= 1;
1414 if (!seen_end
&& yf
>= end_point
.Y
)
1417 end_center_line
^= 1;
1419 if (!seen_center
&& yf
>= center_point
.Y
)
1422 start_center_line
^= 1;
1423 end_center_line
^= 1;
1426 if (start_center_line
)
1427 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1429 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1431 if (end_center_line
)
1432 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1434 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1436 if (line1_xf
< line2_xf
)
1438 min_x
= (INT
)ceil(line1_xf
);
1439 max_x
= (INT
)ceil(line2_xf
);
1443 min_x
= (INT
)ceil(line2_xf
);
1444 max_x
= (INT
)ceil(line1_xf
);
1447 if (min_x
< fill_area
->X
)
1448 min_x
= fill_area
->X
;
1449 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1450 max_x
= fill_area
->X
+ fill_area
->Width
;
1452 for (x
=min_x
; x
<max_x
; x
++)
1457 if (start_color
!= end_color
)
1459 REAL blend_amount
, pdy
, pdx
;
1460 pdy
= yf
- center_point
.Y
;
1461 pdx
= xf
- center_point
.X
;
1462 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1463 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1466 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1467 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1469 distance
= distance
/ center_distance
;
1471 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1472 blend_colors(outer_color
, fill
->centercolor
, distance
);
1477 GdipDeletePath(flat_path
);
1481 return NotImplemented
;
1485 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1486 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1487 * should not be called on an hdc that has a path you care about. */
1488 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1489 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1491 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1493 HBRUSH brush
= NULL
;
1495 PointF ptf
[4], *custptf
= NULL
;
1496 POINT pt
[4], *custpt
= NULL
;
1498 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1503 if((x1
== x2
) && (y1
== y2
))
1506 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1508 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1510 brush
= CreateSolidBrush(color
);
1511 lb
.lbStyle
= BS_SOLID
;
1514 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1515 PS_JOIN_MITER
, 1, &lb
, 0,
1517 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1518 oldpen
= SelectObject(graphics
->hdc
, pen
);
1525 case LineCapSquareAnchor
:
1526 case LineCapDiamondAnchor
:
1527 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1528 if(cap
== LineCapDiamondAnchor
){
1529 dsmall
= cos(theta
+ M_PI_2
) * size
;
1530 dbig
= sin(theta
+ M_PI_2
) * size
;
1533 dsmall
= cos(theta
+ M_PI_4
) * size
;
1534 dbig
= sin(theta
+ M_PI_4
) * size
;
1537 ptf
[0].X
= x2
- dsmall
;
1538 ptf
[1].X
= x2
+ dbig
;
1540 ptf
[0].Y
= y2
- dbig
;
1541 ptf
[3].Y
= y2
+ dsmall
;
1543 ptf
[1].Y
= y2
- dsmall
;
1544 ptf
[2].Y
= y2
+ dbig
;
1546 ptf
[3].X
= x2
- dbig
;
1547 ptf
[2].X
= x2
+ dsmall
;
1549 transform_and_round_points(graphics
, pt
, ptf
, 4);
1550 Polygon(graphics
->hdc
, pt
, 4);
1553 case LineCapArrowAnchor
:
1554 size
= size
* 4.0 / sqrt(3.0);
1556 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1557 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1562 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1563 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1571 transform_and_round_points(graphics
, pt
, ptf
, 3);
1572 Polygon(graphics
->hdc
, pt
, 3);
1575 case LineCapRoundAnchor
:
1576 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1583 transform_and_round_points(graphics
, pt
, ptf
, 2);
1584 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1587 case LineCapTriangle
:
1589 dx
= cos(M_PI_2
+ theta
) * size
;
1590 dy
= sin(M_PI_2
+ theta
) * size
;
1597 dx
= cos(theta
) * size
;
1598 dy
= sin(theta
) * size
;
1603 transform_and_round_points(graphics
, pt
, ptf
, 3);
1604 Polygon(graphics
->hdc
, pt
, 3);
1608 dx
= dy
= size
/ 2.0;
1615 dx
= -cos(M_PI_2
+ theta
) * size
;
1616 dy
= -sin(M_PI_2
+ theta
) * size
;
1623 transform_and_round_points(graphics
, pt
, ptf
, 4);
1624 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1625 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1632 count
= custom
->pathdata
.Count
;
1633 custptf
= GdipAlloc(count
* sizeof(PointF
));
1634 custpt
= GdipAlloc(count
* sizeof(POINT
));
1635 tp
= GdipAlloc(count
);
1637 if(!custptf
|| !custpt
|| !tp
)
1640 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1642 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1643 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1644 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1646 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1647 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1649 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1651 for(i
= 0; i
< count
; i
++)
1652 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1655 BeginPath(graphics
->hdc
);
1656 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1657 EndPath(graphics
->hdc
);
1658 StrokeAndFillPath(graphics
->hdc
);
1661 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1673 SelectObject(graphics
->hdc
, oldbrush
);
1674 SelectObject(graphics
->hdc
, oldpen
);
1675 DeleteObject(brush
);
1680 /* Shortens the line by the given percent by changing x2, y2.
1681 * If percent is > 1.0 then the line will change direction.
1682 * If percent is negative it can lengthen the line. */
1683 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1685 REAL dist
, theta
, dx
, dy
;
1687 if((y1
== *y2
) && (x1
== *x2
))
1690 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1691 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1692 dx
= cos(theta
) * dist
;
1693 dy
= sin(theta
) * dist
;
1699 /* Shortens the line by the given amount by changing x2, y2.
1700 * If the amount is greater than the distance, the line will become length 0.
1701 * If the amount is negative, it can lengthen the line. */
1702 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1704 REAL dx
, dy
, percent
;
1708 if(dx
== 0 && dy
== 0)
1711 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1718 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1721 /* Conducts a linear search to find the bezier points that will back off
1722 * the endpoint of the curve by a distance of amt. Linear search works
1723 * better than binary in this case because there are multiple solutions,
1724 * and binary searches often find a bad one. I don't think this is what
1725 * Windows does but short of rendering the bezier without GDI's help it's
1726 * the best we can do. If rev then work from the start of the passed points
1727 * instead of the end. */
1728 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1731 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1732 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1741 origx
= pt
[fourth
].X
;
1742 origy
= pt
[fourth
].Y
;
1743 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1745 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1746 /* reset bezier points to original values */
1747 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1748 /* Perform magic on bezier points. Order is important here.*/
1749 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1750 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1751 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1752 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1753 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1754 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1756 dx
= pt
[fourth
].X
- origx
;
1757 dy
= pt
[fourth
].Y
- origy
;
1759 diff
= sqrt(dx
* dx
+ dy
* dy
);
1760 percent
+= 0.0005 * amt
;
1764 /* Draws a combination of bezier curves and lines between points. */
1765 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1766 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1768 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1769 BYTE
*tp
= GdipAlloc(count
);
1770 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1772 GpStatus status
= GenericError
;
1778 if(!pti
|| !tp
|| !ptcopy
){
1779 status
= OutOfMemory
;
1783 for(i
= 1; i
< count
; i
++){
1784 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1785 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1786 || !(types
[i
+ 2] & PathPointTypeBezier
)){
1787 ERR("Bad bezier points\n");
1794 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1796 /* If we are drawing caps, go through the points and adjust them accordingly,
1797 * and draw the caps. */
1799 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1800 case PathPointTypeBezier
:
1801 if(pen
->endcap
== LineCapArrowAnchor
)
1802 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1803 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1804 shorten_bezier_amt(&ptcopy
[count
- 4],
1805 pen
->width
* pen
->customend
->inset
, FALSE
);
1807 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1808 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1809 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1810 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1813 case PathPointTypeLine
:
1814 if(pen
->endcap
== LineCapArrowAnchor
)
1815 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1816 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1818 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1819 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1820 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1821 pen
->customend
->inset
* pen
->width
);
1823 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1824 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1829 ERR("Bad path last point\n");
1833 /* Find start of points */
1834 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1835 == PathPointTypeStart
); j
++);
1837 switch(types
[j
] & PathPointTypePathTypeMask
){
1838 case PathPointTypeBezier
:
1839 if(pen
->startcap
== LineCapArrowAnchor
)
1840 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1841 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1842 shorten_bezier_amt(&ptcopy
[j
- 1],
1843 pen
->width
* pen
->customstart
->inset
, TRUE
);
1845 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1846 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1847 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1848 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1851 case PathPointTypeLine
:
1852 if(pen
->startcap
== LineCapArrowAnchor
)
1853 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1854 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1856 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1857 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1858 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1859 pen
->customstart
->inset
* pen
->width
);
1861 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1862 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1867 ERR("Bad path points\n");
1872 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1874 for(i
= 0; i
< count
; i
++){
1875 tp
[i
] = convert_path_point_type(types
[i
]);
1878 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1890 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1894 BeginPath(graphics
->hdc
);
1895 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1896 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1897 EndPath(graphics
->hdc
);
1901 typedef struct _GraphicsContainerItem
{
1903 GraphicsContainer contid
;
1905 SmoothingMode smoothing
;
1906 CompositingQuality compqual
;
1907 InterpolationMode interpolation
;
1908 CompositingMode compmode
;
1909 TextRenderingHint texthint
;
1912 PixelOffsetMode pixeloffset
;
1914 GpMatrix worldtrans
;
1916 INT origin_x
, origin_y
;
1917 } GraphicsContainerItem
;
1919 static GpStatus
init_container(GraphicsContainerItem
** container
,
1920 GDIPCONST GpGraphics
* graphics
){
1923 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1927 (*container
)->contid
= graphics
->contid
+ 1;
1929 (*container
)->smoothing
= graphics
->smoothing
;
1930 (*container
)->compqual
= graphics
->compqual
;
1931 (*container
)->interpolation
= graphics
->interpolation
;
1932 (*container
)->compmode
= graphics
->compmode
;
1933 (*container
)->texthint
= graphics
->texthint
;
1934 (*container
)->scale
= graphics
->scale
;
1935 (*container
)->unit
= graphics
->unit
;
1936 (*container
)->textcontrast
= graphics
->textcontrast
;
1937 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1938 (*container
)->origin_x
= graphics
->origin_x
;
1939 (*container
)->origin_y
= graphics
->origin_y
;
1940 (*container
)->worldtrans
= graphics
->worldtrans
;
1942 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1944 GdipFree(*container
);
1952 static void delete_container(GraphicsContainerItem
* container
)
1954 GdipDeleteRegion(container
->clip
);
1955 GdipFree(container
);
1958 static GpStatus
restore_container(GpGraphics
* graphics
,
1959 GDIPCONST GraphicsContainerItem
* container
){
1963 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1964 if(sts
!= Ok
) return sts
;
1966 graphics
->worldtrans
= container
->worldtrans
;
1968 GdipDeleteRegion(graphics
->clip
);
1969 graphics
->clip
= newClip
;
1971 graphics
->contid
= container
->contid
- 1;
1973 graphics
->smoothing
= container
->smoothing
;
1974 graphics
->compqual
= container
->compqual
;
1975 graphics
->interpolation
= container
->interpolation
;
1976 graphics
->compmode
= container
->compmode
;
1977 graphics
->texthint
= container
->texthint
;
1978 graphics
->scale
= container
->scale
;
1979 graphics
->unit
= container
->unit
;
1980 graphics
->textcontrast
= container
->textcontrast
;
1981 graphics
->pixeloffset
= container
->pixeloffset
;
1982 graphics
->origin_x
= container
->origin_x
;
1983 graphics
->origin_y
= container
->origin_y
;
1988 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1994 if(graphics
->hwnd
) {
1995 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1996 return GenericError
;
1998 rect
->X
= wnd_rect
.left
;
1999 rect
->Y
= wnd_rect
.top
;
2000 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2001 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2002 }else if (graphics
->image
){
2003 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2004 if (stat
== Ok
&& unit
!= UnitPixel
)
2005 FIXME("need to convert from unit %i\n", unit
);
2006 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2013 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2014 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2016 rect
->Width
= bmp
.bmWidth
;
2017 rect
->Height
= bmp
.bmHeight
;
2028 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2029 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2032 if (graphics
->hdc
&&
2033 (GetMapMode(graphics
->hdc
) != MM_TEXT
|| GetGraphicsMode(graphics
->hdc
) != GM_COMPATIBLE
))
2037 points
[0].x
= rect
->X
;
2038 points
[0].y
= rect
->Y
;
2039 points
[1].x
= rect
->X
+ rect
->Width
;
2040 points
[1].y
= rect
->Y
+ rect
->Height
;
2042 DPtoLP(graphics
->hdc
, points
, sizeof(points
)/sizeof(points
[0]));
2044 rect
->X
= min(points
[0].x
, points
[1].x
);
2045 rect
->Y
= min(points
[0].y
, points
[1].y
);
2046 rect
->Width
= abs(points
[1].x
- points
[0].x
);
2047 rect
->Height
= abs(points
[1].y
- points
[0].y
);
2053 /* on success, rgn will contain the region of the graphics object which
2054 * is visible after clipping has been applied */
2055 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2061 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2064 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2067 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2070 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2073 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2076 GdipDeleteRegion(tmp
);
2080 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2084 if (font
->unit
== UnitPixel
)
2086 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2090 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2091 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2093 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2096 lf
->lfHeight
= -(height
+ 0.5);
2098 lf
->lfEscapement
= 0;
2099 lf
->lfOrientation
= 0;
2100 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2101 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2102 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2103 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2104 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2105 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2106 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2107 lf
->lfQuality
= DEFAULT_QUALITY
;
2108 lf
->lfPitchAndFamily
= 0;
2109 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2112 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2113 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2114 GDIPCONST GpMatrix
*matrix
)
2116 HDC hdc
= CreateCompatibleDC(0);
2118 REAL angle
, rel_width
, rel_height
, font_height
;
2120 HFONT unscaled_font
;
2121 TEXTMETRICW textmet
;
2123 if (font
->unit
== UnitPixel
)
2124 font_height
= font
->emSize
;
2127 REAL unit_scale
, res
;
2129 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2130 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2132 font_height
= font
->emSize
* unit_scale
;
2143 GpMatrix xform
= *matrix
;
2144 GdipTransformMatrixPoints(&xform
, pt
, 3);
2147 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2148 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2149 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2150 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2151 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2152 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2154 get_log_fontW(font
, graphics
, &lfw
);
2155 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2156 unscaled_font
= CreateFontIndirectW(&lfw
);
2158 SelectObject(hdc
, unscaled_font
);
2159 GetTextMetricsW(hdc
, &textmet
);
2161 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2162 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2164 *hfont
= CreateFontIndirectW(&lfw
);
2167 DeleteObject(unscaled_font
);
2170 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2172 TRACE("(%p, %p)\n", hdc
, graphics
);
2174 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2177 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2183 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2186 FIXME("Don't know how to handle parameter hDevice\n");
2191 if(graphics
== NULL
)
2192 return InvalidParameter
;
2194 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2195 if(!*graphics
) return OutOfMemory
;
2197 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2199 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2200 GdipFree(*graphics
);
2204 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2205 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2206 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2208 (*graphics
)->alpha_hdc
= 1;
2211 (*graphics
)->hdc
= hdc
;
2212 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2213 (*graphics
)->owndc
= FALSE
;
2214 (*graphics
)->smoothing
= SmoothingModeDefault
;
2215 (*graphics
)->compqual
= CompositingQualityDefault
;
2216 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2217 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2218 (*graphics
)->compmode
= CompositingModeSourceOver
;
2219 (*graphics
)->unit
= UnitDisplay
;
2220 (*graphics
)->scale
= 1.0;
2221 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2222 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2223 (*graphics
)->busy
= FALSE
;
2224 (*graphics
)->textcontrast
= 4;
2225 list_init(&(*graphics
)->containers
);
2226 (*graphics
)->contid
= 0;
2228 TRACE("<-- %p\n", *graphics
);
2233 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2237 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2238 if(!*graphics
) return OutOfMemory
;
2240 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2242 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2243 GdipFree(*graphics
);
2247 (*graphics
)->hdc
= NULL
;
2248 (*graphics
)->hwnd
= NULL
;
2249 (*graphics
)->owndc
= FALSE
;
2250 (*graphics
)->image
= image
;
2251 /* We have to store the image type here because the image may be freed
2252 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2253 (*graphics
)->image_type
= image
->type
;
2254 (*graphics
)->smoothing
= SmoothingModeDefault
;
2255 (*graphics
)->compqual
= CompositingQualityDefault
;
2256 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2257 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2258 (*graphics
)->compmode
= CompositingModeSourceOver
;
2259 (*graphics
)->unit
= UnitDisplay
;
2260 (*graphics
)->scale
= 1.0;
2261 (*graphics
)->xres
= image
->xres
;
2262 (*graphics
)->yres
= image
->yres
;
2263 (*graphics
)->busy
= FALSE
;
2264 (*graphics
)->textcontrast
= 4;
2265 list_init(&(*graphics
)->containers
);
2266 (*graphics
)->contid
= 0;
2268 TRACE("<-- %p\n", *graphics
);
2273 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2278 TRACE("(%p, %p)\n", hwnd
, graphics
);
2282 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2284 ReleaseDC(hwnd
, hdc
);
2288 (*graphics
)->hwnd
= hwnd
;
2289 (*graphics
)->owndc
= TRUE
;
2294 /* FIXME: no icm handling */
2295 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2297 TRACE("(%p, %p)\n", hwnd
, graphics
);
2299 return GdipCreateFromHWND(hwnd
, graphics
);
2302 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2303 UINT access
, IStream
**stream
)
2308 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2310 if(!stream
|| !filename
)
2311 return InvalidParameter
;
2313 if(access
& GENERIC_WRITE
)
2314 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2315 else if(access
& GENERIC_READ
)
2316 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2318 return InvalidParameter
;
2320 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2322 return hresult_to_status(ret
);
2325 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2327 GraphicsContainerItem
*cont
, *next
;
2329 TRACE("(%p)\n", graphics
);
2331 if(!graphics
) return InvalidParameter
;
2332 if(graphics
->busy
) return ObjectBusy
;
2334 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2336 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2342 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2344 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2345 list_remove(&cont
->entry
);
2346 delete_container(cont
);
2349 GdipDeleteRegion(graphics
->clip
);
2351 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2352 * do otherwise, but we can't have that in the test suite because it means
2353 * accessing freed memory. */
2354 graphics
->busy
= TRUE
;
2361 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2362 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2367 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2368 width
, height
, startAngle
, sweepAngle
);
2370 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2371 return InvalidParameter
;
2376 status
= GdipCreatePath(FillModeAlternate
, &path
);
2377 if (status
!= Ok
) return status
;
2379 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2381 status
= GdipDrawPath(graphics
, pen
, path
);
2383 GdipDeletePath(path
);
2387 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2388 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2390 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2391 width
, height
, startAngle
, sweepAngle
);
2393 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2396 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2397 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2401 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2402 x2
, y2
, x3
, y3
, x4
, y4
);
2404 if(!graphics
|| !pen
)
2405 return InvalidParameter
;
2418 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2421 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2422 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2424 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2425 x2
, y2
, x3
, y3
, x4
, y4
);
2427 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2430 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2431 GDIPCONST GpPointF
*points
, INT count
)
2436 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2438 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2439 return InvalidParameter
;
2444 status
= GdipCreatePath(FillModeAlternate
, &path
);
2445 if (status
!= Ok
) return status
;
2447 status
= GdipAddPathBeziers(path
, points
, count
);
2449 status
= GdipDrawPath(graphics
, pen
, path
);
2451 GdipDeletePath(path
);
2455 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2456 GDIPCONST GpPoint
*points
, INT count
)
2462 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2464 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2465 return InvalidParameter
;
2470 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2474 for(i
= 0; i
< count
; i
++){
2475 pts
[i
].X
= (REAL
)points
[i
].X
;
2476 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2479 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2486 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2487 GDIPCONST GpPointF
*points
, INT count
)
2489 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2491 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2494 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2495 GDIPCONST GpPoint
*points
, INT count
)
2497 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2499 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2502 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2503 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2508 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2510 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2511 return InvalidParameter
;
2516 status
= GdipCreatePath(FillModeAlternate
, &path
);
2517 if (status
!= Ok
) return status
;
2519 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2521 status
= GdipDrawPath(graphics
, pen
, path
);
2523 GdipDeletePath(path
);
2528 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2529 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2535 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2537 if(!points
|| count
<= 0)
2538 return InvalidParameter
;
2540 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2544 for(i
= 0; i
< count
; i
++){
2545 ptf
[i
].X
= (REAL
)points
[i
].X
;
2546 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2549 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2556 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2557 GDIPCONST GpPointF
*points
, INT count
)
2559 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2561 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2564 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2565 GDIPCONST GpPoint
*points
, INT count
)
2571 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2574 return InvalidParameter
;
2576 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2580 for(i
= 0; i
< count
; i
++){
2581 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2582 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2585 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2591 /* Approximates cardinal spline with Bezier curves. */
2592 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2593 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2598 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2600 if(!graphics
|| !pen
)
2601 return InvalidParameter
;
2607 return InvalidParameter
;
2609 status
= GdipCreatePath(FillModeAlternate
, &path
);
2610 if (status
!= Ok
) return status
;
2612 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2614 status
= GdipDrawPath(graphics
, pen
, path
);
2616 GdipDeletePath(path
);
2620 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2621 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2627 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2630 return InvalidParameter
;
2632 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2636 for(i
= 0; i
< count
; i
++){
2637 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2638 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2641 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2647 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2648 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2651 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2653 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2654 return InvalidParameter
;
2657 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2660 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2661 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2664 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2670 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2671 return InvalidParameter
;
2674 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2677 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2678 REAL y
, REAL width
, REAL height
)
2683 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2685 if(!graphics
|| !pen
)
2686 return InvalidParameter
;
2691 status
= GdipCreatePath(FillModeAlternate
, &path
);
2692 if (status
!= Ok
) return status
;
2694 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2696 status
= GdipDrawPath(graphics
, pen
, path
);
2698 GdipDeletePath(path
);
2702 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2703 INT y
, INT width
, INT height
)
2705 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2707 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2711 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2715 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2717 if(!graphics
|| !image
)
2718 return InvalidParameter
;
2720 GdipGetImageWidth(image
, &width
);
2721 GdipGetImageHeight(image
, &height
);
2723 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2724 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2727 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2730 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2732 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2735 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2736 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2740 REAL scale_x
, scale_y
, width
, height
;
2742 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2744 if (!graphics
|| !image
) return InvalidParameter
;
2746 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2747 scale_x
*= graphics
->xres
/ image
->xres
;
2748 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2749 scale_y
*= graphics
->yres
/ image
->yres
;
2750 width
= srcwidth
* scale_x
;
2751 height
= srcheight
* scale_y
;
2753 points
[0].X
= points
[2].X
= x
;
2754 points
[0].Y
= points
[1].Y
= y
;
2755 points
[1].X
= x
+ width
;
2756 points
[2].Y
= y
+ height
;
2758 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2759 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2762 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2763 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2766 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2769 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2770 GDIPCONST GpPointF
*dstpoints
, INT count
)
2774 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2777 return InvalidParameter
;
2779 GdipGetImageWidth(image
, &width
);
2780 GdipGetImageHeight(image
, &height
);
2782 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2783 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2786 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2787 GDIPCONST GpPoint
*dstpoints
, INT count
)
2791 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2793 if (count
!= 3 || !dstpoints
)
2794 return InvalidParameter
;
2796 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2797 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2798 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2799 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2800 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2801 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2803 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2806 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2807 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2809 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2813 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2814 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2815 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2816 DrawImageAbort callback
, VOID
* callbackData
)
2822 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2823 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2827 return NotImplemented
;
2829 if(!graphics
|| !image
|| !points
|| count
!= 3)
2830 return InvalidParameter
;
2832 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2833 debugstr_pointf(&points
[2]));
2835 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2837 /* Ensure source width/height is positive */
2840 GpPointF tmp
= ptf
[1];
2841 srcx
= srcx
+ srcwidth
;
2842 srcwidth
= -srcwidth
;
2843 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2844 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2851 GpPointF tmp
= ptf
[2];
2852 srcy
= srcy
+ srcheight
;
2853 srcheight
= -srcheight
;
2854 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
2855 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
2860 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2861 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2862 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
2864 transform_and_round_points(graphics
, pti
, ptf
, 4);
2866 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2867 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2869 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2870 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2871 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2872 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2873 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2879 FIXME("graphics object has no HDC\n");
2882 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2883 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2884 srcx
, srcy
, srcwidth
, srcheight
, NULL
) != S_OK
)
2887 callback(callbackData
);
2888 return GenericError
;
2891 else if (image
->type
== ImageTypeBitmap
)
2893 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2894 BOOL do_resampling
= FALSE
;
2895 BOOL use_software
= FALSE
;
2897 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2898 graphics
->xres
, graphics
->yres
,
2899 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2900 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2901 imageAttributes
? imageAttributes
->outside_color
: 0);
2903 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2904 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2905 srcx
< 0 || srcy
< 0 ||
2906 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2907 do_resampling
= TRUE
;
2909 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
2910 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
2911 use_software
= TRUE
;
2916 GpRectF graphics_bounds
;
2918 int i
, x
, y
, src_stride
, dst_stride
;
2919 GpMatrix dst_to_src
;
2920 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2921 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
2922 BitmapData lockeddata
;
2923 InterpolationMode interpolation
= graphics
->interpolation
;
2924 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2925 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2926 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2927 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2929 if (!imageAttributes
)
2930 imageAttributes
= &defaultImageAttributes
;
2932 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2933 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2936 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2937 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2938 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2939 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2942 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
2943 if (stat
!= Ok
) return stat
;
2945 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
2946 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
2947 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
2948 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
2950 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
2952 if (IsRectEmpty(&dst_area
)) return Ok
;
2954 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2955 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2956 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2957 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2958 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2959 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2961 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
2963 stat
= GdipInvertMatrix(&dst_to_src
);
2964 if (stat
!= Ok
) return stat
;
2968 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2969 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2973 /* Make sure src_area is equal in size to dst_area. */
2974 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
2975 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
2976 src_area
.Width
= dst_area
.right
- dst_area
.left
;
2977 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
2980 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
2982 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
2985 src_stride
= sizeof(ARGB
) * src_area
.Width
;
2987 /* Read the bits we need from the source bitmap into an ARGB buffer. */
2988 lockeddata
.Width
= src_area
.Width
;
2989 lockeddata
.Height
= src_area
.Height
;
2990 lockeddata
.Stride
= src_stride
;
2991 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
2992 lockeddata
.Scan0
= src_data
;
2994 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
2995 PixelFormat32bppARGB
, &lockeddata
);
2998 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3006 apply_image_attributes(imageAttributes
, src_data
,
3007 src_area
.Width
, src_area
.Height
,
3008 src_stride
, ColorAdjustTypeBitmap
);
3012 /* Transform the bits as needed to the destination. */
3013 dst_data
= dst_dyn_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3020 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3022 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3024 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3025 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3026 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3027 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3029 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3031 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3033 GpPointF src_pointf
;
3036 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3037 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3039 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3041 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3042 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3043 imageAttributes
, interpolation
, offset_mode
);
3051 dst_data
= src_data
;
3052 dst_stride
= src_stride
;
3055 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3056 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3060 GdipFree(dst_dyn_data
);
3067 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3068 HBITMAP hbitmap
, old_hbm
=NULL
;
3070 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3071 bitmap
->format
== PixelFormat24bppRGB
||
3072 bitmap
->format
== PixelFormat32bppRGB
||
3073 bitmap
->format
== PixelFormat32bppPARGB
))
3075 BITMAPINFOHEADER bih
;
3077 PixelFormat dst_format
;
3079 /* we can't draw a bitmap of this format directly */
3080 hdc
= CreateCompatibleDC(0);
3084 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3085 bih
.biWidth
= bitmap
->width
;
3086 bih
.biHeight
= -bitmap
->height
;
3088 bih
.biBitCount
= 32;
3089 bih
.biCompression
= BI_RGB
;
3090 bih
.biSizeImage
= 0;
3091 bih
.biXPelsPerMeter
= 0;
3092 bih
.biYPelsPerMeter
= 0;
3094 bih
.biClrImportant
= 0;
3096 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3097 (void**)&temp_bits
, NULL
, 0);
3099 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3100 dst_format
= PixelFormat32bppPARGB
;
3102 dst_format
= PixelFormat32bppRGB
;
3104 convert_pixels(bitmap
->width
, bitmap
->height
,
3105 bitmap
->width
*4, temp_bits
, dst_format
,
3106 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3107 bitmap
->image
.palette
);
3111 if (bitmap
->hbitmap
)
3112 hbitmap
= bitmap
->hbitmap
;
3115 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3120 temp_hdc
= (hdc
== 0);
3125 if (!hdc
) hdc
= CreateCompatibleDC(0);
3126 old_hbm
= SelectObject(hdc
, hbitmap
);
3129 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3131 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3132 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3136 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3137 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3142 SelectObject(hdc
, old_hbm
);
3147 DeleteObject(hbitmap
);
3150 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3156 rc
.Width
= srcwidth
;
3157 rc
.Height
= srcheight
;
3159 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3160 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3164 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3165 return InvalidParameter
;
3171 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3172 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3173 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3174 DrawImageAbort callback
, VOID
* callbackData
)
3176 GpPointF pointsF
[3];
3179 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3180 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3183 if(!points
|| count
!=3)
3184 return InvalidParameter
;
3186 for(i
= 0; i
< count
; i
++){
3187 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3188 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3191 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3192 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3193 callback
, callbackData
);
3196 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3197 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3198 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3199 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3200 VOID
* callbackData
)
3204 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3205 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3206 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3210 points
[1].X
= dstx
+ dstwidth
;
3213 points
[2].Y
= dsty
+ dstheight
;
3215 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3216 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3219 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3220 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3221 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3222 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3223 VOID
* callbackData
)
3227 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3228 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3229 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3233 points
[1].X
= dstx
+ dstwidth
;
3236 points
[2].Y
= dsty
+ dstheight
;
3238 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3239 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3242 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3243 REAL x
, REAL y
, REAL width
, REAL height
)
3249 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3251 if(!graphics
|| !image
)
3252 return InvalidParameter
;
3254 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3258 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3259 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3260 unit
, NULL
, NULL
, NULL
);
3263 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3264 INT x
, INT y
, INT width
, INT height
)
3266 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3268 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3271 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3272 REAL y1
, REAL x2
, REAL y2
)
3276 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3282 return GdipDrawLines(graphics
, pen
, pt
, 2);
3285 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3286 INT y1
, INT x2
, INT y2
)
3288 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3290 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3293 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3294 GpPointF
*points
, INT count
)
3299 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3301 if(!pen
|| !graphics
|| (count
< 2))
3302 return InvalidParameter
;
3307 status
= GdipCreatePath(FillModeAlternate
, &path
);
3308 if (status
!= Ok
) return status
;
3310 status
= GdipAddPathLine2(path
, points
, count
);
3312 status
= GdipDrawPath(graphics
, pen
, path
);
3314 GdipDeletePath(path
);
3318 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3319 GpPoint
*points
, INT count
)
3325 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3327 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3328 if(!ptf
) return OutOfMemory
;
3330 for(i
= 0; i
< count
; i
++){
3331 ptf
[i
].X
= (REAL
) points
[i
].X
;
3332 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3335 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3341 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3347 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3349 if(!pen
|| !graphics
)
3350 return InvalidParameter
;
3357 FIXME("graphics object has no HDC\n");
3361 save_state
= prepare_dc(graphics
, pen
);
3363 retval
= get_clip_hrgn(graphics
, &hrgn
);
3369 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3371 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3372 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3375 restore_dc(graphics
, save_state
);
3381 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3382 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3387 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3388 width
, height
, startAngle
, sweepAngle
);
3390 if(!graphics
|| !pen
)
3391 return InvalidParameter
;
3396 status
= GdipCreatePath(FillModeAlternate
, &path
);
3397 if (status
!= Ok
) return status
;
3399 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3401 status
= GdipDrawPath(graphics
, pen
, path
);
3403 GdipDeletePath(path
);
3407 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3408 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3410 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3411 width
, height
, startAngle
, sweepAngle
);
3413 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3416 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3417 REAL y
, REAL width
, REAL height
)
3422 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3424 if(!pen
|| !graphics
)
3425 return InvalidParameter
;
3430 status
= GdipCreatePath(FillModeAlternate
, &path
);
3431 if (status
!= Ok
) return status
;
3433 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3435 status
= GdipDrawPath(graphics
, pen
, path
);
3437 GdipDeletePath(path
);
3441 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3442 INT y
, INT width
, INT height
)
3444 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3446 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3449 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3450 GDIPCONST GpRectF
* rects
, INT count
)
3455 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3457 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3458 return InvalidParameter
;
3463 status
= GdipCreatePath(FillModeAlternate
, &path
);
3464 if (status
!= Ok
) return status
;
3466 status
= GdipAddPathRectangles(path
, rects
, count
);
3468 status
= GdipDrawPath(graphics
, pen
, path
);
3470 GdipDeletePath(path
);
3474 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3475 GDIPCONST GpRect
* rects
, INT count
)
3481 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3483 if(!rects
|| count
<=0)
3484 return InvalidParameter
;
3486 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3490 for(i
= 0;i
< count
;i
++){
3491 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3492 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3493 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3494 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3497 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3503 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3504 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3509 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3510 count
, tension
, fill
);
3512 if(!graphics
|| !brush
|| !points
)
3513 return InvalidParameter
;
3518 if(count
== 1) /* Do nothing */
3521 status
= GdipCreatePath(fill
, &path
);
3522 if (status
!= Ok
) return status
;
3524 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3526 status
= GdipFillPath(graphics
, brush
, path
);
3528 GdipDeletePath(path
);
3532 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3533 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3539 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3540 count
, tension
, fill
);
3542 if(!points
|| count
== 0)
3543 return InvalidParameter
;
3545 if(count
== 1) /* Do nothing */
3548 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3552 for(i
= 0;i
< count
;i
++){
3553 ptf
[i
].X
= (REAL
)points
[i
].X
;
3554 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3557 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3564 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3565 GDIPCONST GpPointF
*points
, INT count
)
3567 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3568 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3569 0.5f
, FillModeAlternate
);
3572 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3573 GDIPCONST GpPoint
*points
, INT count
)
3575 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3576 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3577 0.5f
, FillModeAlternate
);
3580 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3581 REAL y
, REAL width
, REAL height
)
3586 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3588 if(!graphics
|| !brush
)
3589 return InvalidParameter
;
3594 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3598 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3601 stat
= GdipFillPath(graphics
, brush
, path
);
3603 GdipDeletePath(path
);
3609 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3610 INT y
, INT width
, INT height
)
3612 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3614 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3617 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3623 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3624 return NotImplemented
;
3626 save_state
= SaveDC(graphics
->hdc
);
3627 EndPath(graphics
->hdc
);
3628 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3631 retval
= get_clip_hrgn(graphics
, &hrgn
);
3637 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3639 BeginPath(graphics
->hdc
);
3640 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3641 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3646 EndPath(graphics
->hdc
);
3647 brush_fill_path(graphics
, brush
);
3652 RestoreDC(graphics
->hdc
, save_state
);
3658 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3663 if (!brush_can_fill_pixels(brush
))
3664 return NotImplemented
;
3666 /* FIXME: This could probably be done more efficiently without regions. */
3668 stat
= GdipCreateRegionPath(path
, &rgn
);
3672 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3674 GdipDeleteRegion(rgn
);
3680 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3682 GpStatus stat
= NotImplemented
;
3684 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3686 if(!brush
|| !graphics
|| !path
)
3687 return InvalidParameter
;
3692 if (!graphics
->image
&& !graphics
->alpha_hdc
)
3693 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3695 if (stat
== NotImplemented
)
3696 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3698 if (stat
== NotImplemented
)
3700 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3707 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3708 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3713 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3714 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3716 if(!graphics
|| !brush
)
3717 return InvalidParameter
;
3722 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3726 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3729 stat
= GdipFillPath(graphics
, brush
, path
);
3731 GdipDeletePath(path
);
3737 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3738 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3740 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3741 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3743 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3746 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3747 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3752 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3754 if(!graphics
|| !brush
|| !points
|| !count
)
3755 return InvalidParameter
;
3760 stat
= GdipCreatePath(fillMode
, &path
);
3764 stat
= GdipAddPathPolygon(path
, points
, count
);
3767 stat
= GdipFillPath(graphics
, brush
, path
);
3769 GdipDeletePath(path
);
3775 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3776 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3781 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3783 if(!graphics
|| !brush
|| !points
|| !count
)
3784 return InvalidParameter
;
3789 stat
= GdipCreatePath(fillMode
, &path
);
3793 stat
= GdipAddPathPolygonI(path
, points
, count
);
3796 stat
= GdipFillPath(graphics
, brush
, path
);
3798 GdipDeletePath(path
);
3804 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3805 GDIPCONST GpPointF
*points
, INT count
)
3807 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3809 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3812 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3813 GDIPCONST GpPoint
*points
, INT count
)
3815 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3817 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3820 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3821 REAL x
, REAL y
, REAL width
, REAL height
)
3825 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3830 rect
.Height
= height
;
3832 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
3835 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3836 INT x
, INT y
, INT width
, INT height
)
3840 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3844 rect
.Width
= (REAL
)width
;
3845 rect
.Height
= (REAL
)height
;
3847 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
3850 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3856 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3858 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
3859 return InvalidParameter
;
3861 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
3863 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
3864 /* FIXME: Add gdi32 drawing. */
3868 status
= GdipCreatePath(FillModeAlternate
, &path
);
3869 if (status
!= Ok
) return status
;
3871 status
= GdipAddPathRectangles(path
, rects
, count
);
3873 status
= GdipFillPath(graphics
, brush
, path
);
3875 GdipDeletePath(path
);
3879 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3886 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3888 if(!rects
|| count
<= 0)
3889 return InvalidParameter
;
3891 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3895 for(i
= 0; i
< count
; i
++){
3896 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3897 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3898 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3899 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3902 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3908 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3916 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3917 return NotImplemented
;
3919 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3923 save_state
= SaveDC(graphics
->hdc
);
3924 EndPath(graphics
->hdc
);
3926 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3928 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3930 BeginPath(graphics
->hdc
);
3931 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3932 EndPath(graphics
->hdc
);
3934 brush_fill_path(graphics
, brush
);
3937 RestoreDC(graphics
->hdc
, save_state
);
3944 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3948 GpRegion
*temp_region
;
3949 GpMatrix world_to_device
;
3950 GpRectF graphics_bounds
;
3954 GpRect gp_bound_rect
;
3956 if (!brush_can_fill_pixels(brush
))
3957 return NotImplemented
;
3959 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3962 stat
= GdipCloneRegion(region
, &temp_region
);
3966 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3967 CoordinateSpaceWorld
, &world_to_device
);
3970 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
3973 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
3976 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
3978 GdipDeleteRegion(temp_region
);
3981 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
3983 DeleteObject(hregion
);
3989 gp_bound_rect
.X
= bound_rect
.left
;
3990 gp_bound_rect
.Y
= bound_rect
.top
;
3991 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
3992 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
3994 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4000 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4001 &gp_bound_rect
, gp_bound_rect
.Width
);
4004 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4005 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4006 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4008 GdipFree(pixel_data
);
4011 DeleteObject(hregion
);
4017 /*****************************************************************************
4018 * GdipFillRegion [GDIPLUS.@]
4020 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4023 GpStatus stat
= NotImplemented
;
4025 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4027 if (!(graphics
&& brush
&& region
))
4028 return InvalidParameter
;
4033 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4034 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4036 if (stat
== NotImplemented
)
4037 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4039 if (stat
== NotImplemented
)
4041 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4048 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4050 TRACE("(%p,%u)\n", graphics
, intention
);
4053 return InvalidParameter
;
4058 /* We have no internal operation queue, so there's no need to clear it. */
4066 /*****************************************************************************
4067 * GdipGetClipBounds [GDIPLUS.@]
4069 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4074 TRACE("(%p, %p)\n", graphics
, rect
);
4077 return InvalidParameter
;
4082 status
= GdipCreateRegion(&clip
);
4083 if (status
!= Ok
) return status
;
4085 status
= GdipGetClip(graphics
, clip
);
4087 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4089 GdipDeleteRegion(clip
);
4093 /*****************************************************************************
4094 * GdipGetClipBoundsI [GDIPLUS.@]
4096 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4098 TRACE("(%p, %p)\n", graphics
, rect
);
4101 return InvalidParameter
;
4106 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4109 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4110 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4111 CompositingMode
*mode
)
4113 TRACE("(%p, %p)\n", graphics
, mode
);
4115 if(!graphics
|| !mode
)
4116 return InvalidParameter
;
4121 *mode
= graphics
->compmode
;
4126 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4127 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4128 CompositingQuality
*quality
)
4130 TRACE("(%p, %p)\n", graphics
, quality
);
4132 if(!graphics
|| !quality
)
4133 return InvalidParameter
;
4138 *quality
= graphics
->compqual
;
4143 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4144 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4145 InterpolationMode
*mode
)
4147 TRACE("(%p, %p)\n", graphics
, mode
);
4149 if(!graphics
|| !mode
)
4150 return InvalidParameter
;
4155 *mode
= graphics
->interpolation
;
4160 /* FIXME: Need to handle color depths less than 24bpp */
4161 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4163 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4165 if(!graphics
|| !argb
)
4166 return InvalidParameter
;
4174 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4176 TRACE("(%p, %p)\n", graphics
, scale
);
4178 if(!graphics
|| !scale
)
4179 return InvalidParameter
;
4184 *scale
= graphics
->scale
;
4189 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4191 TRACE("(%p, %p)\n", graphics
, unit
);
4193 if(!graphics
|| !unit
)
4194 return InvalidParameter
;
4199 *unit
= graphics
->unit
;
4204 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4205 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4208 TRACE("(%p, %p)\n", graphics
, mode
);
4210 if(!graphics
|| !mode
)
4211 return InvalidParameter
;
4216 *mode
= graphics
->pixeloffset
;
4221 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4222 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4224 TRACE("(%p, %p)\n", graphics
, mode
);
4226 if(!graphics
|| !mode
)
4227 return InvalidParameter
;
4232 *mode
= graphics
->smoothing
;
4237 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4239 TRACE("(%p, %p)\n", graphics
, contrast
);
4241 if(!graphics
|| !contrast
)
4242 return InvalidParameter
;
4244 *contrast
= graphics
->textcontrast
;
4249 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4250 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4251 TextRenderingHint
*hint
)
4253 TRACE("(%p, %p)\n", graphics
, hint
);
4255 if(!graphics
|| !hint
)
4256 return InvalidParameter
;
4261 *hint
= graphics
->texthint
;
4266 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4271 TRACE("(%p, %p)\n", graphics
, rect
);
4273 if(!graphics
|| !rect
)
4274 return InvalidParameter
;
4279 /* intersect window and graphics clipping regions */
4280 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4283 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4286 /* get bounds of the region */
4287 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4290 GdipDeleteRegion(clip_rgn
);
4295 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4300 TRACE("(%p, %p)\n", graphics
, rect
);
4302 if(!graphics
|| !rect
)
4303 return InvalidParameter
;
4305 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4307 rect
->X
= gdip_round(rectf
.X
);
4308 rect
->Y
= gdip_round(rectf
.Y
);
4309 rect
->Width
= gdip_round(rectf
.Width
);
4310 rect
->Height
= gdip_round(rectf
.Height
);
4316 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4318 TRACE("(%p, %p)\n", graphics
, matrix
);
4320 if(!graphics
|| !matrix
)
4321 return InvalidParameter
;
4326 *matrix
= graphics
->worldtrans
;
4330 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4336 TRACE("(%p, %x)\n", graphics
, color
);
4339 return InvalidParameter
;
4344 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4347 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4348 GdipDeleteBrush((GpBrush
*)brush
);
4352 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4353 wnd_rect
.Width
, wnd_rect
.Height
);
4355 GdipDeleteBrush((GpBrush
*)brush
);
4360 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4362 TRACE("(%p, %p)\n", graphics
, res
);
4364 if(!graphics
|| !res
)
4365 return InvalidParameter
;
4367 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4370 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4376 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4378 if(!graphics
|| !result
)
4379 return InvalidParameter
;
4386 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4387 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4390 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4393 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4396 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4399 GdipDeleteRegion(rgn
);
4403 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4405 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4408 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4414 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4416 if(!graphics
|| !result
)
4417 return InvalidParameter
;
4424 pts
[1].X
= x
+ width
;
4425 pts
[1].Y
= y
+ height
;
4427 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4428 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4431 pts
[1].X
-= pts
[0].X
;
4432 pts
[1].Y
-= pts
[0].Y
;
4434 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4437 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4440 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4443 GdipDeleteRegion(rgn
);
4447 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4449 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4452 GpStatus
gdip_format_string(HDC hdc
,
4453 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4454 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4455 gdip_format_string_callback callback
, void *user_data
)
4458 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4459 nheight
, lineend
, lineno
= 0;
4461 StringAlignment halign
;
4464 HotkeyPrefix hkprefix
;
4465 INT
*hotkeyprefix_offsets
=NULL
;
4466 INT hotkeyprefix_count
=0;
4467 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4468 BOOL seen_prefix
= FALSE
;
4469 GpStringFormat
*dyn_format
=NULL
;
4471 if(length
== -1) length
= lstrlenW(string
);
4473 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4474 if(!stringdup
) return OutOfMemory
;
4478 stat
= GdipStringFormatGetGenericDefault(&dyn_format
);
4481 GdipFree(stringdup
);
4484 format
= dyn_format
;
4487 nwidth
= rect
->Width
;
4488 nheight
= rect
->Height
;
4489 if (ignore_empty_clip
)
4491 if (!nwidth
) nwidth
= INT_MAX
;
4492 if (!nheight
) nheight
= INT_MAX
;
4495 hkprefix
= format
->hkprefix
;
4497 if (hkprefix
== HotkeyPrefixShow
)
4499 for (i
=0; i
<length
; i
++)
4501 if (string
[i
] == '&')
4502 hotkeyprefix_count
++;
4506 if (hotkeyprefix_count
)
4507 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4509 hotkeyprefix_count
= 0;
4511 for(i
= 0, j
= 0; i
< length
; i
++){
4512 /* FIXME: This makes the indexes passed to callback inaccurate. */
4513 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4516 /* FIXME: tabs should be handled using tabstops from stringformat */
4517 if (string
[i
] == '\t')
4520 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4521 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4522 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4528 seen_prefix
= FALSE
;
4530 stringdup
[j
] = string
[i
];
4536 halign
= format
->align
;
4538 while(sum
< length
){
4539 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4540 nwidth
, &fit
, NULL
, &size
);
4546 for(lret
= 0; lret
< fit
; lret
++)
4547 if(*(stringdup
+ sum
+ lret
) == '\n')
4550 /* Line break code (may look strange, but it imitates windows). */
4552 lineend
= fit
= lret
; /* this is not an off-by-one error */
4553 else if(fit
< (length
- sum
)){
4554 if(*(stringdup
+ sum
+ fit
) == ' ')
4555 while(*(stringdup
+ sum
+ fit
) == ' ')
4558 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4561 if(*(stringdup
+ sum
+ fit
) == '\t')
4570 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4571 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4577 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4578 nwidth
, &j
, NULL
, &size
);
4580 bounds
.Width
= size
.cx
;
4582 if(height
+ size
.cy
> nheight
)
4584 if (format
->attr
& StringFormatFlagsLineLimit
)
4586 bounds
.Height
= nheight
- (height
+ size
.cy
);
4589 bounds
.Height
= size
.cy
;
4591 bounds
.Y
= rect
->Y
+ height
;
4595 case StringAlignmentNear
:
4599 case StringAlignmentCenter
:
4600 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4602 case StringAlignmentFar
:
4603 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4607 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4608 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4611 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4612 font
, rect
, format
, lineno
, &bounds
,
4613 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4614 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4619 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4623 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4625 if(height
> nheight
)
4628 /* Stop if this was a linewrap (but not if it was a linebreak). */
4629 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
4633 GdipFree(stringdup
);
4634 GdipFree(hotkeyprefix_offsets
);
4635 GdipDeleteStringFormat(dyn_format
);
4640 struct measure_ranges_args
{
4642 REAL rel_width
, rel_height
;
4645 static GpStatus
measure_ranges_callback(HDC hdc
,
4646 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4647 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4648 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4649 INT underlined_index_count
, void *user_data
)
4653 struct measure_ranges_args
*args
= user_data
;
4655 for (i
=0; i
<format
->range_count
; i
++)
4657 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4658 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4659 if (range_start
< range_end
)
4664 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4665 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4667 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4668 INT_MAX
, NULL
, NULL
, &range_size
);
4669 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4671 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4672 INT_MAX
, NULL
, NULL
, &range_size
);
4673 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4675 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4684 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4685 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4686 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4687 INT regionCount
, GpRegion
** regions
)
4691 HFONT gdifont
, oldfont
;
4692 struct measure_ranges_args args
;
4693 HDC hdc
, temp_hdc
=NULL
;
4698 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4699 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4701 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4702 return InvalidParameter
;
4704 if (regionCount
< stringFormat
->range_count
)
4705 return InvalidParameter
;
4709 hdc
= temp_hdc
= CreateCompatibleDC(0);
4710 if (!temp_hdc
) return OutOfMemory
;
4713 hdc
= graphics
->hdc
;
4715 if (stringFormat
->attr
)
4716 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4724 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4725 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4726 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4727 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4728 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4730 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4731 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4733 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4734 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4735 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
4736 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
4738 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
4739 oldfont
= SelectObject(hdc
, gdifont
);
4741 for (i
=0; i
<stringFormat
->range_count
; i
++)
4743 stat
= GdipSetEmpty(regions
[i
]);
4748 args
.regions
= regions
;
4750 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
4751 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
4753 SelectObject(hdc
, oldfont
);
4754 DeleteObject(gdifont
);
4762 struct measure_string_args
{
4764 INT
*codepointsfitted
;
4766 REAL rel_width
, rel_height
;
4769 static GpStatus
measure_string_callback(HDC hdc
,
4770 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4771 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4772 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4773 INT underlined_index_count
, void *user_data
)
4775 struct measure_string_args
*args
= user_data
;
4776 REAL new_width
, new_height
;
4778 new_width
= bounds
->Width
/ args
->rel_width
;
4779 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
4781 if (new_width
> args
->bounds
->Width
)
4782 args
->bounds
->Width
= new_width
;
4784 if (new_height
> args
->bounds
->Height
)
4785 args
->bounds
->Height
= new_height
;
4787 if (args
->codepointsfitted
)
4788 *args
->codepointsfitted
= index
+ length
;
4790 if (args
->linesfilled
)
4791 (*args
->linesfilled
)++;
4796 /* Find the smallest rectangle that bounds the text when it is printed in rect
4797 * according to the format options listed in format. If rect has 0 width and
4798 * height, then just find the smallest rectangle that bounds the text when it's
4799 * printed at location (rect->X, rect-Y). */
4800 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4801 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4802 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4803 INT
*codepointsfitted
, INT
*linesfilled
)
4805 HFONT oldfont
, gdifont
;
4806 struct measure_string_args args
;
4807 HDC temp_hdc
=NULL
, hdc
;
4813 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4814 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4815 bounds
, codepointsfitted
, linesfilled
);
4817 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4818 return InvalidParameter
;
4822 hdc
= temp_hdc
= CreateCompatibleDC(0);
4823 if (!temp_hdc
) return OutOfMemory
;
4826 hdc
= graphics
->hdc
;
4828 if(linesfilled
) *linesfilled
= 0;
4829 if(codepointsfitted
) *codepointsfitted
= 0;
4832 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4840 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4841 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4842 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4843 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4844 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4846 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4847 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4849 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
4850 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
4851 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
4852 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
4853 if (scaled_rect
.Width
>= 0.5)
4855 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4856 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4859 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4860 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4862 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
4863 oldfont
= SelectObject(hdc
, gdifont
);
4865 bounds
->X
= rect
->X
;
4866 bounds
->Y
= rect
->Y
;
4867 bounds
->Width
= 0.0;
4868 bounds
->Height
= 0.0;
4870 args
.bounds
= bounds
;
4871 args
.codepointsfitted
= &glyphs
;
4872 args
.linesfilled
= &lines
;
4875 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
4876 measure_string_callback
, &args
);
4878 if (linesfilled
) *linesfilled
= lines
;
4879 if (codepointsfitted
) *codepointsfitted
= glyphs
;
4882 bounds
->Width
+= margin_x
* 2.0;
4884 SelectObject(hdc
, oldfont
);
4885 DeleteObject(gdifont
);
4893 struct draw_string_args
{
4894 GpGraphics
*graphics
;
4895 GDIPCONST GpBrush
*brush
;
4896 REAL x
, y
, rel_width
, rel_height
, ascent
;
4899 static GpStatus
draw_string_callback(HDC hdc
,
4900 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4901 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4902 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4903 INT underlined_index_count
, void *user_data
)
4905 struct draw_string_args
*args
= user_data
;
4909 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4910 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4912 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
4913 args
->brush
, &position
,
4914 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4916 if (stat
== Ok
&& underlined_index_count
)
4918 OUTLINETEXTMETRICW otm
;
4919 REAL underline_y
, underline_height
;
4922 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
4924 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
4925 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
4927 for (i
=0; i
<underlined_index_count
; i
++)
4929 REAL start_x
, end_x
;
4931 INT ofs
= underlined_indexes
[i
] - index
;
4933 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
4934 start_x
= text_size
.cx
/ args
->rel_width
;
4936 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
4937 end_x
= text_size
.cx
/ args
->rel_width
;
4939 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
4946 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4947 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4948 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4952 GpPointF pt
[3], rectcpy
[4];
4954 REAL rel_width
, rel_height
, margin_x
;
4955 INT save_state
, format_flags
= 0;
4957 struct draw_string_args args
;
4959 HDC hdc
, temp_hdc
=NULL
;
4960 TEXTMETRICW textmetric
;
4962 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4963 length
, font
, debugstr_rectf(rect
), format
, brush
);
4965 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4966 return InvalidParameter
;
4970 hdc
= graphics
->hdc
;
4974 hdc
= temp_hdc
= CreateCompatibleDC(0);
4978 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4980 format_flags
= format
->attr
;
4982 /* Should be no need to explicitly test for StringAlignmentNear as
4983 * that is default behavior if no alignment is passed. */
4984 if(format
->vertalign
!= StringAlignmentNear
){
4985 RectF bounds
, in_rect
= *rect
;
4986 in_rect
.Height
= 0.0; /* avoid height clipping */
4987 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
4989 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
4991 if(format
->vertalign
== StringAlignmentCenter
)
4992 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4993 else if(format
->vertalign
== StringAlignmentFar
)
4994 offsety
= (rect
->Height
- bounds
.Height
);
4996 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
4999 save_state
= SaveDC(hdc
);
5007 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5008 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5009 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5010 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5011 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5013 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5014 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5015 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5016 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5017 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5019 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5020 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5022 scaled_rect
.X
= margin_x
* rel_width
;
5023 scaled_rect
.Y
= 0.0;
5024 scaled_rect
.Width
= rel_width
* rect
->Width
;
5025 scaled_rect
.Height
= rel_height
* rect
->Height
;
5026 if (scaled_rect
.Width
>= 0.5)
5028 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5029 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5032 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5033 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5035 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5036 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5037 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5039 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5040 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5041 SelectClipRgn(hdc
, rgn
);
5044 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5045 SelectObject(hdc
, gdifont
);
5047 args
.graphics
= graphics
;
5051 args
.y
= rect
->Y
+ offsety
;
5053 args
.rel_width
= rel_width
;
5054 args
.rel_height
= rel_height
;
5056 GetTextMetricsW(hdc
, &textmetric
);
5057 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5059 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5060 draw_string_callback
, &args
);
5063 DeleteObject(gdifont
);
5065 RestoreDC(hdc
, save_state
);
5072 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5074 TRACE("(%p)\n", graphics
);
5077 return InvalidParameter
;
5082 return GdipSetInfinite(graphics
->clip
);
5085 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5087 TRACE("(%p)\n", graphics
);
5090 return InvalidParameter
;
5095 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5098 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5100 return GdipEndContainer(graphics
, state
);
5103 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5104 GpMatrixOrder order
)
5106 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5109 return InvalidParameter
;
5114 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5117 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5119 return GdipBeginContainer2(graphics
, state
);
5122 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5123 GraphicsContainer
*state
)
5125 GraphicsContainerItem
*container
;
5128 TRACE("(%p, %p)\n", graphics
, state
);
5130 if(!graphics
|| !state
)
5131 return InvalidParameter
;
5133 sts
= init_container(&container
, graphics
);
5137 list_add_head(&graphics
->containers
, &container
->entry
);
5138 *state
= graphics
->contid
= container
->contid
;
5143 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5145 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5146 return NotImplemented
;
5149 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5151 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5152 return NotImplemented
;
5155 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5157 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5158 return NotImplemented
;
5161 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5164 GraphicsContainerItem
*container
, *container2
;
5166 TRACE("(%p, %x)\n", graphics
, state
);
5169 return InvalidParameter
;
5171 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5172 if(container
->contid
== state
)
5176 /* did not find a matching container */
5177 if(&container
->entry
== &graphics
->containers
)
5180 sts
= restore_container(graphics
, container
);
5184 /* remove all of the containers on top of the found container */
5185 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5186 if(container
->contid
== state
)
5188 list_remove(&container
->entry
);
5189 delete_container(container
);
5192 list_remove(&container
->entry
);
5193 delete_container(container
);
5198 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5199 REAL sy
, GpMatrixOrder order
)
5201 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5204 return InvalidParameter
;
5209 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5212 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5215 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5217 if(!graphics
|| !srcgraphics
)
5218 return InvalidParameter
;
5220 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5223 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5224 CompositingMode mode
)
5226 TRACE("(%p, %d)\n", graphics
, mode
);
5229 return InvalidParameter
;
5234 graphics
->compmode
= mode
;
5239 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5240 CompositingQuality quality
)
5242 TRACE("(%p, %d)\n", graphics
, quality
);
5245 return InvalidParameter
;
5250 graphics
->compqual
= quality
;
5255 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5256 InterpolationMode mode
)
5258 TRACE("(%p, %d)\n", graphics
, mode
);
5260 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5261 return InvalidParameter
;
5266 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5267 mode
= InterpolationModeBilinear
;
5269 if (mode
== InterpolationModeHighQuality
)
5270 mode
= InterpolationModeHighQualityBicubic
;
5272 graphics
->interpolation
= mode
;
5277 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5281 TRACE("(%p, %.2f)\n", graphics
, scale
);
5283 if(!graphics
|| (scale
<= 0.0))
5284 return InvalidParameter
;
5289 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5291 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
5296 graphics
->scale
= scale
;
5301 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5305 TRACE("(%p, %d)\n", graphics
, unit
);
5308 return InvalidParameter
;
5313 if(unit
== UnitWorld
)
5314 return InvalidParameter
;
5316 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5318 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
5323 graphics
->unit
= unit
;
5328 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5331 TRACE("(%p, %d)\n", graphics
, mode
);
5334 return InvalidParameter
;
5339 graphics
->pixeloffset
= mode
;
5344 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5348 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5351 FIXME("value is unused in rendering\n");
5354 return InvalidParameter
;
5356 graphics
->origin_x
= x
;
5357 graphics
->origin_y
= y
;
5362 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5364 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5366 if (!graphics
|| !x
|| !y
)
5367 return InvalidParameter
;
5369 *x
= graphics
->origin_x
;
5370 *y
= graphics
->origin_y
;
5375 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5377 TRACE("(%p, %d)\n", graphics
, mode
);
5380 return InvalidParameter
;
5385 graphics
->smoothing
= mode
;
5390 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5392 TRACE("(%p, %d)\n", graphics
, contrast
);
5395 return InvalidParameter
;
5397 graphics
->textcontrast
= contrast
;
5402 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5403 TextRenderingHint hint
)
5405 TRACE("(%p, %d)\n", graphics
, hint
);
5407 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5408 return InvalidParameter
;
5413 graphics
->texthint
= hint
;
5418 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5420 TRACE("(%p, %p)\n", graphics
, matrix
);
5422 if(!graphics
|| !matrix
)
5423 return InvalidParameter
;
5428 TRACE("%f,%f,%f,%f,%f,%f\n",
5429 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5430 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5432 graphics
->worldtrans
= *matrix
;
5437 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5438 REAL dy
, GpMatrixOrder order
)
5440 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5443 return InvalidParameter
;
5448 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5451 /*****************************************************************************
5452 * GdipSetClipHrgn [GDIPLUS.@]
5454 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5459 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5462 return InvalidParameter
;
5467 /* hrgn is already in device units */
5468 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5472 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5474 GdipDeleteRegion(region
);
5478 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5483 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5486 return InvalidParameter
;
5491 status
= GdipClonePath(path
, &clip_path
);
5494 GpMatrix world_to_device
;
5496 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
5497 CoordinateSpaceWorld
, &world_to_device
);
5498 status
= GdipTransformPath(clip_path
, &world_to_device
);
5500 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
5502 GdipDeletePath(clip_path
);
5507 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5508 REAL width
, REAL height
,
5515 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5518 return InvalidParameter
;
5526 rect
.Height
= height
;
5527 status
= GdipCreateRegionRect(&rect
, ®ion
);
5530 GpMatrix world_to_device
;
5532 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5533 status
= GdipTransformRegion(region
, &world_to_device
);
5535 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5537 GdipDeleteRegion(region
);
5542 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5543 INT width
, INT height
,
5546 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5549 return InvalidParameter
;
5554 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5557 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5563 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5565 if(!graphics
|| !region
)
5566 return InvalidParameter
;
5571 status
= GdipCloneRegion(region
, &clip
);
5574 GpMatrix world_to_device
;
5576 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5577 status
= GdipTransformRegion(clip
, &world_to_device
);
5579 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
5581 GdipDeleteRegion(clip
);
5586 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5592 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5594 if(!graphics
|| !pen
|| count
<=0)
5595 return InvalidParameter
;
5602 FIXME("graphics object has no HDC\n");
5606 pti
= GdipAlloc(sizeof(POINT
) * count
);
5608 save_state
= prepare_dc(graphics
, pen
);
5609 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5611 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5612 Polygon(graphics
->hdc
, pti
, count
);
5614 restore_dc(graphics
, save_state
);
5620 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5627 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5629 if(count
<=0) return InvalidParameter
;
5630 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5632 for(i
= 0;i
< count
; i
++){
5633 ptf
[i
].X
= (REAL
)points
[i
].X
;
5634 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5637 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5643 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5645 TRACE("(%p, %p)\n", graphics
, dpi
);
5647 if(!graphics
|| !dpi
)
5648 return InvalidParameter
;
5653 *dpi
= graphics
->xres
;
5657 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5659 TRACE("(%p, %p)\n", graphics
, dpi
);
5661 if(!graphics
|| !dpi
)
5662 return InvalidParameter
;
5667 *dpi
= graphics
->yres
;
5671 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5672 GpMatrixOrder order
)
5677 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5679 if(!graphics
|| !matrix
)
5680 return InvalidParameter
;
5685 m
= graphics
->worldtrans
;
5687 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5689 graphics
->worldtrans
= m
;
5694 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5695 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5697 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5701 TRACE("(%p, %p)\n", graphics
, hdc
);
5703 if(!graphics
|| !hdc
)
5704 return InvalidParameter
;
5709 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5711 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5713 else if (!graphics
->hdc
|| graphics
->alpha_hdc
||
5714 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5716 /* Create a fake HDC and fill it with a constant color. */
5720 BITMAPINFOHEADER bmih
;
5723 stat
= get_graphics_bounds(graphics
, &bounds
);
5727 graphics
->temp_hbitmap_width
= bounds
.Width
;
5728 graphics
->temp_hbitmap_height
= bounds
.Height
;
5730 bmih
.biSize
= sizeof(bmih
);
5731 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5732 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5734 bmih
.biBitCount
= 32;
5735 bmih
.biCompression
= BI_RGB
;
5736 bmih
.biSizeImage
= 0;
5737 bmih
.biXPelsPerMeter
= 0;
5738 bmih
.biYPelsPerMeter
= 0;
5740 bmih
.biClrImportant
= 0;
5742 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5743 (void**)&graphics
->temp_bits
, NULL
, 0);
5745 return GenericError
;
5747 temp_hdc
= CreateCompatibleDC(0);
5750 DeleteObject(hbitmap
);
5751 return GenericError
;
5754 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5755 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5757 SelectObject(temp_hdc
, hbitmap
);
5759 graphics
->temp_hbitmap
= hbitmap
;
5760 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5764 *hdc
= graphics
->hdc
;
5768 graphics
->busy
= TRUE
;
5773 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5777 TRACE("(%p, %p)\n", graphics
, hdc
);
5779 if(!graphics
|| !hdc
|| !graphics
->busy
)
5780 return InvalidParameter
;
5782 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5784 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5786 else if (graphics
->temp_hdc
== hdc
)
5791 /* Find the pixels that have changed, and mark them as opaque. */
5792 pos
= (DWORD
*)graphics
->temp_bits
;
5793 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5795 if (*pos
!= DC_BACKGROUND_KEY
)
5802 /* Write the changed pixels to the real target. */
5803 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5804 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5805 graphics
->temp_hbitmap_width
* 4);
5808 DeleteDC(graphics
->temp_hdc
);
5809 DeleteObject(graphics
->temp_hbitmap
);
5810 graphics
->temp_hdc
= NULL
;
5811 graphics
->temp_hbitmap
= NULL
;
5813 else if (hdc
!= graphics
->hdc
)
5815 stat
= InvalidParameter
;
5819 graphics
->busy
= FALSE
;
5824 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5828 GpMatrix device_to_world
;
5830 TRACE("(%p, %p)\n", graphics
, region
);
5832 if(!graphics
|| !region
)
5833 return InvalidParameter
;
5838 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5841 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
5842 status
= GdipTransformRegion(clip
, &device_to_world
);
5845 GdipDeleteRegion(clip
);
5849 /* free everything except root node and header */
5850 delete_element(®ion
->node
);
5851 memcpy(region
, clip
, sizeof(GpRegion
));
5857 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5858 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
5861 REAL scale_x
, scale_y
;
5863 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5865 if (dst_space
!= src_space
)
5867 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5868 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5870 if(graphics
->unit
!= UnitDisplay
)
5872 scale_x
*= graphics
->scale
;
5873 scale_y
*= graphics
->scale
;
5876 /* transform from src_space to CoordinateSpacePage */
5879 case CoordinateSpaceWorld
:
5880 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
5882 case CoordinateSpacePage
:
5884 case CoordinateSpaceDevice
:
5885 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
5889 /* transform from CoordinateSpacePage to dst_space */
5892 case CoordinateSpaceWorld
:
5894 GpMatrix inverted_transform
= graphics
->worldtrans
;
5895 stat
= GdipInvertMatrix(&inverted_transform
);
5897 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
5900 case CoordinateSpacePage
:
5902 case CoordinateSpaceDevice
:
5903 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
5910 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5911 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5916 if(!graphics
|| !points
|| count
<= 0)
5917 return InvalidParameter
;
5922 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5924 if (src_space
== dst_space
) return Ok
;
5926 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5927 if (stat
!= Ok
) return stat
;
5929 return GdipTransformMatrixPoints(&matrix
, points
, count
);
5932 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5933 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5939 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5942 return InvalidParameter
;
5944 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5948 for(i
= 0; i
< count
; i
++){
5949 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5950 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5953 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5956 for(i
= 0; i
< count
; i
++){
5957 points
[i
].X
= gdip_round(pointsF
[i
].X
);
5958 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
5965 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5977 /*****************************************************************************
5978 * GdipTranslateClip [GDIPLUS.@]
5980 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5982 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5985 return InvalidParameter
;
5990 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5993 /*****************************************************************************
5994 * GdipTranslateClipI [GDIPLUS.@]
5996 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5998 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6001 return InvalidParameter
;
6006 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6010 /*****************************************************************************
6011 * GdipMeasureDriverString [GDIPLUS.@]
6013 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6014 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6015 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6017 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6020 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6022 TEXTMETRICW textmetric
;
6023 const WORD
*glyph_indices
;
6024 WORD
*dynamic_glyph_indices
=NULL
;
6025 REAL rel_width
, rel_height
, ascent
, descent
;
6028 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6030 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6031 return InvalidParameter
;
6034 length
= strlenW(text
);
6038 boundingBox
->X
= 0.0;
6039 boundingBox
->Y
= 0.0;
6040 boundingBox
->Width
= 0.0;
6041 boundingBox
->Height
= 0.0;
6044 if (flags
& unsupported_flags
)
6045 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6047 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6049 hdc
= CreateCompatibleDC(0);
6050 SelectObject(hdc
, hfont
);
6052 GetTextMetricsW(hdc
, &textmetric
);
6062 GpMatrix xform
= *matrix
;
6063 GdipTransformMatrixPoints(&xform
, pt
, 3);
6065 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6066 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6067 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6068 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6069 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6071 if (flags
& DriverStringOptionsCmapLookup
)
6073 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6077 DeleteObject(hfont
);
6081 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6084 glyph_indices
= text
;
6086 min_x
= max_x
= x
= positions
[0].X
;
6087 min_y
= max_y
= y
= positions
[0].Y
;
6089 ascent
= textmetric
.tmAscent
/ rel_height
;
6090 descent
= textmetric
.tmDescent
/ rel_height
;
6092 for (i
=0; i
<length
; i
++)
6097 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6103 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6104 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6106 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6107 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6108 if (min_x
> x
) min_x
= x
;
6110 x
+= char_width
/ rel_width
;
6112 if (max_x
< x
) max_x
= x
;
6115 GdipFree(dynamic_glyph_indices
);
6117 DeleteObject(hfont
);
6119 boundingBox
->X
= min_x
;
6120 boundingBox
->Y
= min_y
;
6121 boundingBox
->Width
= max_x
- min_x
;
6122 boundingBox
->Height
= max_y
- min_y
;
6127 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6128 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6129 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6130 INT flags
, GDIPCONST GpMatrix
*matrix
)
6132 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6138 if (flags
& unsupported_flags
)
6139 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6141 if (!(flags
& DriverStringOptionsCmapLookup
))
6142 eto_flags
|= ETO_GLYPH_INDEX
;
6144 save_state
= SaveDC(graphics
->hdc
);
6145 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6146 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6149 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6151 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6152 SelectObject(graphics
->hdc
, hfont
);
6154 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6156 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6158 RestoreDC(graphics
->hdc
, save_state
);
6160 DeleteObject(hfont
);
6165 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6166 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6167 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6168 INT flags
, GDIPCONST GpMatrix
*matrix
)
6170 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6172 PointF
*real_positions
, real_position
;
6176 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6177 DWORD max_glyphsize
=0;
6178 GLYPHMETRICS glyphmetrics
;
6179 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6182 int text_mask_stride
;
6184 int pixel_data_stride
;
6186 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6191 if (!(flags
& DriverStringOptionsCmapLookup
))
6192 ggo_flags
|= GGO_GLYPH_INDEX
;
6194 if (flags
& unsupported_flags
)
6195 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6197 pti
= GdipAlloc(sizeof(POINT
) * length
);
6201 if (flags
& DriverStringOptionsRealizedAdvance
)
6203 real_position
= positions
[0];
6205 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6209 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6210 if (!real_positions
)
6216 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6218 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6220 GdipFree(real_positions
);
6223 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6225 hdc
= CreateCompatibleDC(0);
6226 SelectObject(hdc
, hfont
);
6228 /* Get the boundaries of the text to be drawn */
6229 for (i
=0; i
<length
; i
++)
6232 int left
, top
, right
, bottom
;
6234 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6235 &glyphmetrics
, 0, NULL
, &identity
);
6237 if (glyphsize
== GDI_ERROR
)
6239 ERR("GetGlyphOutlineW failed\n");
6242 DeleteObject(hfont
);
6243 return GenericError
;
6246 if (glyphsize
> max_glyphsize
)
6247 max_glyphsize
= glyphsize
;
6251 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6252 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6253 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6254 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6256 if (left
< min_x
) min_x
= left
;
6257 if (top
< min_y
) min_y
= top
;
6258 if (right
> max_x
) max_x
= right
;
6259 if (bottom
> max_y
) max_y
= bottom
;
6262 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6264 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6265 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6269 if (max_glyphsize
== 0)
6270 /* Nothing to draw. */
6273 glyph_mask
= GdipAlloc(max_glyphsize
);
6274 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6275 text_mask_stride
= max_x
- min_x
;
6277 if (!(glyph_mask
&& text_mask
))
6279 GdipFree(glyph_mask
);
6280 GdipFree(text_mask
);
6283 DeleteObject(hfont
);
6287 /* Generate a mask for the text */
6288 for (i
=0; i
<length
; i
++)
6291 int left
, top
, stride
;
6293 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6294 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6296 if (ret
== GDI_ERROR
|| ret
== 0)
6297 continue; /* empty glyph */
6299 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6300 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6301 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6303 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6305 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6306 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6307 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6309 *text_val
= min(64, *text_val
+ *glyph_val
);
6318 DeleteObject(hfont
);
6319 GdipFree(glyph_mask
);
6321 /* get the brush data */
6322 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6325 GdipFree(text_mask
);
6329 pixel_area
.X
= min_x
;
6330 pixel_area
.Y
= min_y
;
6331 pixel_area
.Width
= max_x
- min_x
;
6332 pixel_area
.Height
= max_y
- min_y
;
6333 pixel_data_stride
= pixel_area
.Width
* 4;
6335 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6338 GdipFree(text_mask
);
6339 GdipFree(pixel_data
);
6343 /* multiply the brush data by the mask */
6344 for (y
=0; y
<pixel_area
.Height
; y
++)
6346 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6347 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6348 for (x
=0; x
<pixel_area
.Width
; x
++)
6350 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6356 GdipFree(text_mask
);
6358 /* draw the result */
6359 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6360 pixel_area
.Height
, pixel_data_stride
);
6362 GdipFree(pixel_data
);
6367 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6368 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6369 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6370 INT flags
, GDIPCONST GpMatrix
*matrix
)
6372 GpStatus stat
= NotImplemented
;
6375 length
= strlenW(text
);
6377 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6378 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6379 brush
->bt
== BrushTypeSolidColor
&&
6380 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6381 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6382 brush
, positions
, flags
, matrix
);
6383 if (stat
== NotImplemented
)
6384 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6385 brush
, positions
, flags
, matrix
);
6389 /*****************************************************************************
6390 * GdipDrawDriverString [GDIPLUS.@]
6392 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6393 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6394 GDIPCONST PointF
*positions
, INT flags
,
6395 GDIPCONST GpMatrix
*matrix
)
6397 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6399 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6400 return InvalidParameter
;
6402 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6403 brush
, positions
, flags
, matrix
);
6406 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6407 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6409 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6410 return NotImplemented
;
6413 /*****************************************************************************
6414 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6416 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6421 TRACE("(%p, %p)\n", graphics
, res
);
6423 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6426 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6429 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6432 GdipDeleteRegion(rgn
);
6436 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6440 TRACE("(%p) stub\n", graphics
);
6443 FIXME("not implemented\n");
6445 return NotImplemented
;