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 ARGB
transform_color(ARGB color
, const ColorMatrix
*matrix
)
600 unsigned char a
, r
, g
, b
;
602 val
[0] = ((color
>> 16) & 0xff) / 255.0; /* red */
603 val
[1] = ((color
>> 8) & 0xff) / 255.0; /* green */
604 val
[2] = (color
& 0xff) / 255.0; /* blue */
605 val
[3] = ((color
>> 24) & 0xff) / 255.0; /* alpha */
606 val
[4] = 1.0; /* translation */
613 res
[i
] += matrix
->m
[j
][i
] * val
[j
];
616 a
= min(max(floorf(res
[3]*255.0), 0.0), 255.0);
617 r
= min(max(floorf(res
[0]*255.0), 0.0), 255.0);
618 g
= min(max(floorf(res
[1]*255.0), 0.0), 255.0);
619 b
= min(max(floorf(res
[2]*255.0), 0.0), 255.0);
621 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
624 static BOOL
color_is_gray(ARGB color
)
626 unsigned char r
, g
, b
;
628 r
= (color
>> 16) & 0xff;
629 g
= (color
>> 8) & 0xff;
632 return (r
== g
) && (g
== b
);
635 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
636 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
641 if (attributes
->colorkeys
[type
].enabled
||
642 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
644 const struct color_key
*key
;
645 BYTE min_blue
, min_green
, min_red
;
646 BYTE max_blue
, max_green
, max_red
;
648 if (attributes
->colorkeys
[type
].enabled
)
649 key
= &attributes
->colorkeys
[type
];
651 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
653 min_blue
= key
->low
&0xff;
654 min_green
= (key
->low
>>8)&0xff;
655 min_red
= (key
->low
>>16)&0xff;
657 max_blue
= key
->high
&0xff;
658 max_green
= (key
->high
>>8)&0xff;
659 max_red
= (key
->high
>>16)&0xff;
661 for (x
=0; x
<width
; x
++)
662 for (y
=0; y
<height
; y
++)
665 BYTE blue
, green
, red
;
666 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
667 blue
= *src_color
&0xff;
668 green
= (*src_color
>>8)&0xff;
669 red
= (*src_color
>>16)&0xff;
670 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
671 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
672 *src_color
= 0x00000000;
676 if (attributes
->colorremaptables
[type
].enabled
||
677 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
679 const struct color_remap_table
*table
;
681 if (attributes
->colorremaptables
[type
].enabled
)
682 table
= &attributes
->colorremaptables
[type
];
684 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
686 for (x
=0; x
<width
; x
++)
687 for (y
=0; y
<height
; y
++)
690 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
691 for (i
=0; i
<table
->mapsize
; i
++)
693 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
695 *src_color
= table
->colormap
[i
].newColor
.Argb
;
702 if (attributes
->colormatrices
[type
].enabled
||
703 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
705 const struct color_matrix
*colormatrices
;
707 if (attributes
->colormatrices
[type
].enabled
)
708 colormatrices
= &attributes
->colormatrices
[type
];
710 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
712 for (x
=0; x
<width
; x
++)
713 for (y
=0; y
<height
; y
++)
716 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
718 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
719 !color_is_gray(*src_color
))
721 *src_color
= transform_color(*src_color
, &colormatrices
->colormatrix
);
723 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
725 *src_color
= transform_color(*src_color
, &colormatrices
->graymatrix
);
730 if (attributes
->gamma_enabled
[type
] ||
731 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
735 if (attributes
->gamma_enabled
[type
])
736 gamma
= attributes
->gamma
[type
];
738 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
740 for (x
=0; x
<width
; x
++)
741 for (y
=0; y
<height
; y
++)
744 BYTE blue
, green
, red
;
745 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
747 blue
= *src_color
&0xff;
748 green
= (*src_color
>>8)&0xff;
749 red
= (*src_color
>>16)&0xff;
751 /* FIXME: We should probably use a table for this. */
752 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
753 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
754 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
756 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
761 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
762 * bitmap that contains all the pixels we may need to draw it. */
763 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
764 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
767 INT left
, top
, right
, bottom
;
769 switch (interpolation
)
771 case InterpolationModeHighQualityBilinear
:
772 case InterpolationModeHighQualityBicubic
:
773 /* FIXME: Include a greater range for the prefilter? */
774 case InterpolationModeBicubic
:
775 case InterpolationModeBilinear
:
776 left
= (INT
)(floorf(srcx
));
777 top
= (INT
)(floorf(srcy
));
778 right
= (INT
)(ceilf(srcx
+srcwidth
));
779 bottom
= (INT
)(ceilf(srcy
+srcheight
));
781 case InterpolationModeNearestNeighbor
:
783 left
= gdip_round(srcx
);
784 top
= gdip_round(srcy
);
785 right
= gdip_round(srcx
+srcwidth
);
786 bottom
= gdip_round(srcy
+srcheight
);
790 if (wrap
== WrapModeClamp
)
796 if (right
>= bitmap
->width
)
797 right
= bitmap
->width
-1;
798 if (bottom
>= bitmap
->height
)
799 bottom
= bitmap
->height
-1;
803 /* In some cases we can make the rectangle smaller here, but the logic
804 * is hard to get right, and tiling suggests we're likely to use the
805 * entire source image. */
806 if (left
< 0 || right
>= bitmap
->width
)
809 right
= bitmap
->width
-1;
812 if (top
< 0 || bottom
>= bitmap
->height
)
815 bottom
= bitmap
->height
-1;
821 rect
->Width
= right
- left
+ 1;
822 rect
->Height
= bottom
- top
+ 1;
825 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
826 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
828 if (attributes
->wrap
== WrapModeClamp
)
830 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
831 return attributes
->outside_color
;
835 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
837 x
= width
*2 + x
% (width
* 2);
839 y
= height
*2 + y
% (height
* 2);
841 if ((attributes
->wrap
& 1) == 1)
844 if ((x
/ width
) % 2 == 0)
847 x
= width
- 1 - x
% width
;
852 if ((attributes
->wrap
& 2) == 2)
855 if ((y
/ height
) % 2 == 0)
858 y
= height
- 1 - y
% height
;
864 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
866 ERR("out of range pixel requested\n");
870 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
873 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
874 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
875 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
879 switch (interpolation
)
883 FIXME("Unimplemented interpolation %i\n", interpolation
);
885 case InterpolationModeBilinear
:
888 INT leftx
, rightx
, topy
, bottomy
;
889 ARGB topleft
, topright
, bottomleft
, bottomright
;
893 leftxf
= floorf(point
->X
);
895 rightx
= (INT
)ceilf(point
->X
);
896 topyf
= floorf(point
->Y
);
898 bottomy
= (INT
)ceilf(point
->Y
);
900 if (leftx
== rightx
&& topy
== bottomy
)
901 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
902 leftx
, topy
, attributes
);
904 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
905 leftx
, topy
, attributes
);
906 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
907 rightx
, topy
, attributes
);
908 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
909 leftx
, bottomy
, attributes
);
910 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
911 rightx
, bottomy
, attributes
);
913 x_offset
= point
->X
- leftxf
;
914 top
= blend_colors(topleft
, topright
, x_offset
);
915 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
917 return blend_colors(top
, bottom
, point
->Y
- topyf
);
919 case InterpolationModeNearestNeighbor
:
925 case PixelOffsetModeNone
:
926 case PixelOffsetModeHighSpeed
:
930 case PixelOffsetModeHalf
:
931 case PixelOffsetModeHighQuality
:
935 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
936 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
942 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
944 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
947 static BOOL
brush_can_fill_path(GpBrush
*brush
)
951 case BrushTypeSolidColor
:
953 case BrushTypeHatchFill
:
955 GpHatch
*hatch
= (GpHatch
*)brush
;
956 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
957 ((hatch
->backcol
& 0xff000000) == 0xff000000);
959 case BrushTypeLinearGradient
:
960 case BrushTypeTextureFill
:
961 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
967 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
971 case BrushTypeSolidColor
:
973 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
974 HBITMAP bmp
= ARGB2BMP(fill
->color
);
979 /* partially transparent fill */
981 SelectClipPath(graphics
->hdc
, RGN_AND
);
982 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
984 HDC hdc
= CreateCompatibleDC(NULL
);
988 SelectObject(hdc
, bmp
);
989 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
997 /* else fall through */
1001 HBRUSH gdibrush
, old_brush
;
1003 gdibrush
= create_gdi_brush(brush
);
1004 if (!gdibrush
) return;
1006 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1007 FillPath(graphics
->hdc
);
1008 SelectObject(graphics
->hdc
, old_brush
);
1009 DeleteObject(gdibrush
);
1015 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1019 case BrushTypeSolidColor
:
1020 case BrushTypeHatchFill
:
1021 case BrushTypeLinearGradient
:
1022 case BrushTypeTextureFill
:
1023 case BrushTypePathGradient
:
1030 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1031 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1035 case BrushTypeSolidColor
:
1038 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1039 for (x
=0; x
<fill_area
->Width
; x
++)
1040 for (y
=0; y
<fill_area
->Height
; y
++)
1041 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1044 case BrushTypeHatchFill
:
1047 GpHatch
*fill
= (GpHatch
*)brush
;
1048 const char *hatch_data
;
1050 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1051 return NotImplemented
;
1053 for (x
=0; x
<fill_area
->Width
; x
++)
1054 for (y
=0; y
<fill_area
->Height
; y
++)
1058 /* FIXME: Account for the rendering origin */
1059 hx
= (x
+ fill_area
->X
) % 8;
1060 hy
= (y
+ fill_area
->Y
) % 8;
1062 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1063 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1065 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1070 case BrushTypeLinearGradient
:
1072 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1073 GpPointF draw_points
[3], line_points
[3];
1075 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1076 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1079 draw_points
[0].X
= fill_area
->X
;
1080 draw_points
[0].Y
= fill_area
->Y
;
1081 draw_points
[1].X
= fill_area
->X
+1;
1082 draw_points
[1].Y
= fill_area
->Y
;
1083 draw_points
[2].X
= fill_area
->X
;
1084 draw_points
[2].Y
= fill_area
->Y
+1;
1086 /* Transform the points to a co-ordinate space where X is the point's
1087 * position in the gradient, 0.0 being the start point and 1.0 the
1089 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1090 CoordinateSpaceDevice
, draw_points
, 3);
1094 line_points
[0] = fill
->startpoint
;
1095 line_points
[1] = fill
->endpoint
;
1096 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1097 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1099 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1104 stat
= GdipInvertMatrix(world_to_gradient
);
1107 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1109 GdipDeleteMatrix(world_to_gradient
);
1114 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1115 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1117 for (y
=0; y
<fill_area
->Height
; y
++)
1119 for (x
=0; x
<fill_area
->Width
; x
++)
1121 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1123 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1130 case BrushTypeTextureFill
:
1132 GpTexture
*fill
= (GpTexture
*)brush
;
1133 GpPointF draw_points
[3];
1140 if (fill
->image
->type
!= ImageTypeBitmap
)
1142 FIXME("metafile texture brushes not implemented\n");
1143 return NotImplemented
;
1146 bitmap
= (GpBitmap
*)fill
->image
;
1147 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1149 src_area
.X
= src_area
.Y
= 0;
1150 src_area
.Width
= bitmap
->width
;
1151 src_area
.Height
= bitmap
->height
;
1153 draw_points
[0].X
= fill_area
->X
;
1154 draw_points
[0].Y
= fill_area
->Y
;
1155 draw_points
[1].X
= fill_area
->X
+1;
1156 draw_points
[1].Y
= fill_area
->Y
;
1157 draw_points
[2].X
= fill_area
->X
;
1158 draw_points
[2].Y
= fill_area
->Y
+1;
1160 /* Transform the points to the co-ordinate space of the bitmap. */
1161 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1162 CoordinateSpaceDevice
, draw_points
, 3);
1166 GpMatrix world_to_texture
= fill
->transform
;
1168 stat
= GdipInvertMatrix(&world_to_texture
);
1170 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1173 if (stat
== Ok
&& !fill
->bitmap_bits
)
1175 BitmapData lockeddata
;
1177 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1178 if (!fill
->bitmap_bits
)
1183 lockeddata
.Width
= bitmap
->width
;
1184 lockeddata
.Height
= bitmap
->height
;
1185 lockeddata
.Stride
= src_stride
;
1186 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1187 lockeddata
.Scan0
= fill
->bitmap_bits
;
1189 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1190 PixelFormat32bppARGB
, &lockeddata
);
1194 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1197 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1198 bitmap
->width
, bitmap
->height
,
1199 src_stride
, ColorAdjustTypeBitmap
);
1203 GdipFree(fill
->bitmap_bits
);
1204 fill
->bitmap_bits
= NULL
;
1210 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1211 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1212 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1213 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1215 for (y
=0; y
<fill_area
->Height
; y
++)
1217 for (x
=0; x
<fill_area
->Width
; x
++)
1220 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1221 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1223 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1224 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1225 &point
, fill
->imageattributes
, graphics
->interpolation
,
1226 graphics
->pixeloffset
);
1233 case BrushTypePathGradient
:
1235 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1237 GpMatrix world_to_device
;
1239 int i
, figure_start
=0;
1240 GpPointF start_point
, end_point
, center_point
;
1242 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1243 INT min_y
, max_y
, min_x
, max_x
;
1246 static int transform_fixme_once
;
1248 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1252 FIXME("path gradient focus not implemented\n");
1259 FIXME("path gradient gamma correction not implemented\n");
1262 if (fill
->blendcount
)
1266 FIXME("path gradient blend not implemented\n");
1269 if (fill
->pblendcount
)
1273 FIXME("path gradient preset blend not implemented\n");
1276 if (!transform_fixme_once
)
1278 BOOL is_identity
=TRUE
;
1279 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1282 FIXME("path gradient transform not implemented\n");
1283 transform_fixme_once
= 1;
1287 stat
= GdipClonePath(fill
->path
, &flat_path
);
1292 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1293 CoordinateSpaceWorld
, &world_to_device
);
1296 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1300 center_point
= fill
->center
;
1301 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1305 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1310 GdipDeletePath(flat_path
);
1314 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1316 int start_center_line
=0, end_center_line
=0;
1317 int seen_start
=0, seen_end
=0, seen_center
=0;
1318 REAL center_distance
;
1319 ARGB start_color
, end_color
;
1322 type
= flat_path
->pathdata
.Types
[i
];
1324 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1327 start_point
= flat_path
->pathdata
.Points
[i
];
1329 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1331 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1333 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1334 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1336 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1338 end_point
= flat_path
->pathdata
.Points
[i
+1];
1339 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1344 outer_color
= start_color
;
1346 min_yf
= center_point
.Y
;
1347 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1348 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1350 if (min_yf
< fill_area
->Y
)
1351 min_y
= fill_area
->Y
;
1353 min_y
= (INT
)ceil(min_yf
);
1355 max_yf
= center_point
.Y
;
1356 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1357 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1359 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1360 max_y
= fill_area
->Y
+ fill_area
->Height
;
1362 max_y
= (INT
)ceil(max_yf
);
1364 dy
= end_point
.Y
- start_point
.Y
;
1365 dx
= end_point
.X
- start_point
.X
;
1367 /* This is proportional to the distance from start-end line to center point. */
1368 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1369 dx
* (center_point
.Y
- start_point
.Y
);
1371 for (y
=min_y
; y
<max_y
; y
++)
1375 if (!seen_start
&& yf
>= start_point
.Y
)
1378 start_center_line
^= 1;
1380 if (!seen_end
&& yf
>= end_point
.Y
)
1383 end_center_line
^= 1;
1385 if (!seen_center
&& yf
>= center_point
.Y
)
1388 start_center_line
^= 1;
1389 end_center_line
^= 1;
1392 if (start_center_line
)
1393 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1395 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1397 if (end_center_line
)
1398 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1400 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1402 if (line1_xf
< line2_xf
)
1404 min_x
= (INT
)ceil(line1_xf
);
1405 max_x
= (INT
)ceil(line2_xf
);
1409 min_x
= (INT
)ceil(line2_xf
);
1410 max_x
= (INT
)ceil(line1_xf
);
1413 if (min_x
< fill_area
->X
)
1414 min_x
= fill_area
->X
;
1415 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1416 max_x
= fill_area
->X
+ fill_area
->Width
;
1418 for (x
=min_x
; x
<max_x
; x
++)
1423 if (start_color
!= end_color
)
1425 REAL blend_amount
, pdy
, pdx
;
1426 pdy
= yf
- center_point
.Y
;
1427 pdx
= xf
- center_point
.X
;
1428 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1429 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1432 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1433 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1435 distance
= distance
/ center_distance
;
1437 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1438 blend_colors(outer_color
, fill
->centercolor
, distance
);
1443 GdipDeletePath(flat_path
);
1447 return NotImplemented
;
1451 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1452 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1453 * should not be called on an hdc that has a path you care about. */
1454 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1455 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1457 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1459 HBRUSH brush
= NULL
;
1461 PointF ptf
[4], *custptf
= NULL
;
1462 POINT pt
[4], *custpt
= NULL
;
1464 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1469 if((x1
== x2
) && (y1
== y2
))
1472 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1474 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1476 brush
= CreateSolidBrush(color
);
1477 lb
.lbStyle
= BS_SOLID
;
1480 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1481 PS_JOIN_MITER
, 1, &lb
, 0,
1483 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1484 oldpen
= SelectObject(graphics
->hdc
, pen
);
1491 case LineCapSquareAnchor
:
1492 case LineCapDiamondAnchor
:
1493 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1494 if(cap
== LineCapDiamondAnchor
){
1495 dsmall
= cos(theta
+ M_PI_2
) * size
;
1496 dbig
= sin(theta
+ M_PI_2
) * size
;
1499 dsmall
= cos(theta
+ M_PI_4
) * size
;
1500 dbig
= sin(theta
+ M_PI_4
) * size
;
1503 ptf
[0].X
= x2
- dsmall
;
1504 ptf
[1].X
= x2
+ dbig
;
1506 ptf
[0].Y
= y2
- dbig
;
1507 ptf
[3].Y
= y2
+ dsmall
;
1509 ptf
[1].Y
= y2
- dsmall
;
1510 ptf
[2].Y
= y2
+ dbig
;
1512 ptf
[3].X
= x2
- dbig
;
1513 ptf
[2].X
= x2
+ dsmall
;
1515 transform_and_round_points(graphics
, pt
, ptf
, 4);
1516 Polygon(graphics
->hdc
, pt
, 4);
1519 case LineCapArrowAnchor
:
1520 size
= size
* 4.0 / sqrt(3.0);
1522 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1523 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1528 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1529 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1537 transform_and_round_points(graphics
, pt
, ptf
, 3);
1538 Polygon(graphics
->hdc
, pt
, 3);
1541 case LineCapRoundAnchor
:
1542 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1549 transform_and_round_points(graphics
, pt
, ptf
, 2);
1550 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1553 case LineCapTriangle
:
1555 dx
= cos(M_PI_2
+ theta
) * size
;
1556 dy
= sin(M_PI_2
+ theta
) * size
;
1563 dx
= cos(theta
) * size
;
1564 dy
= sin(theta
) * size
;
1569 transform_and_round_points(graphics
, pt
, ptf
, 3);
1570 Polygon(graphics
->hdc
, pt
, 3);
1574 dx
= dy
= size
/ 2.0;
1581 dx
= -cos(M_PI_2
+ theta
) * size
;
1582 dy
= -sin(M_PI_2
+ theta
) * size
;
1589 transform_and_round_points(graphics
, pt
, ptf
, 4);
1590 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1591 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1598 count
= custom
->pathdata
.Count
;
1599 custptf
= GdipAlloc(count
* sizeof(PointF
));
1600 custpt
= GdipAlloc(count
* sizeof(POINT
));
1601 tp
= GdipAlloc(count
);
1603 if(!custptf
|| !custpt
|| !tp
)
1606 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1608 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1609 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1610 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1612 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1613 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1615 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1617 for(i
= 0; i
< count
; i
++)
1618 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1621 BeginPath(graphics
->hdc
);
1622 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1623 EndPath(graphics
->hdc
);
1624 StrokeAndFillPath(graphics
->hdc
);
1627 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1639 SelectObject(graphics
->hdc
, oldbrush
);
1640 SelectObject(graphics
->hdc
, oldpen
);
1641 DeleteObject(brush
);
1646 /* Shortens the line by the given percent by changing x2, y2.
1647 * If percent is > 1.0 then the line will change direction.
1648 * If percent is negative it can lengthen the line. */
1649 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1651 REAL dist
, theta
, dx
, dy
;
1653 if((y1
== *y2
) && (x1
== *x2
))
1656 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1657 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1658 dx
= cos(theta
) * dist
;
1659 dy
= sin(theta
) * dist
;
1665 /* Shortens the line by the given amount by changing x2, y2.
1666 * If the amount is greater than the distance, the line will become length 0.
1667 * If the amount is negative, it can lengthen the line. */
1668 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1670 REAL dx
, dy
, percent
;
1674 if(dx
== 0 && dy
== 0)
1677 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1684 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1687 /* Conducts a linear search to find the bezier points that will back off
1688 * the endpoint of the curve by a distance of amt. Linear search works
1689 * better than binary in this case because there are multiple solutions,
1690 * and binary searches often find a bad one. I don't think this is what
1691 * Windows does but short of rendering the bezier without GDI's help it's
1692 * the best we can do. If rev then work from the start of the passed points
1693 * instead of the end. */
1694 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1697 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1698 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1707 origx
= pt
[fourth
].X
;
1708 origy
= pt
[fourth
].Y
;
1709 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1711 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1712 /* reset bezier points to original values */
1713 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1714 /* Perform magic on bezier points. Order is important here.*/
1715 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1716 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1717 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1718 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1719 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1720 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1722 dx
= pt
[fourth
].X
- origx
;
1723 dy
= pt
[fourth
].Y
- origy
;
1725 diff
= sqrt(dx
* dx
+ dy
* dy
);
1726 percent
+= 0.0005 * amt
;
1730 /* Draws a combination of bezier curves and lines between points. */
1731 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1732 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1734 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1735 BYTE
*tp
= GdipAlloc(count
);
1736 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1738 GpStatus status
= GenericError
;
1744 if(!pti
|| !tp
|| !ptcopy
){
1745 status
= OutOfMemory
;
1749 for(i
= 1; i
< count
; i
++){
1750 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1751 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1752 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1753 ERR("Bad bezier points\n");
1760 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1762 /* If we are drawing caps, go through the points and adjust them accordingly,
1763 * and draw the caps. */
1765 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1766 case PathPointTypeBezier
:
1767 if(pen
->endcap
== LineCapArrowAnchor
)
1768 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1769 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1770 shorten_bezier_amt(&ptcopy
[count
- 4],
1771 pen
->width
* pen
->customend
->inset
, FALSE
);
1773 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1774 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1775 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1776 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1779 case PathPointTypeLine
:
1780 if(pen
->endcap
== LineCapArrowAnchor
)
1781 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1782 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1784 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1785 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1786 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1787 pen
->customend
->inset
* pen
->width
);
1789 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1790 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1795 ERR("Bad path last point\n");
1799 /* Find start of points */
1800 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1801 == PathPointTypeStart
); j
++);
1803 switch(types
[j
] & PathPointTypePathTypeMask
){
1804 case PathPointTypeBezier
:
1805 if(pen
->startcap
== LineCapArrowAnchor
)
1806 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1807 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1808 shorten_bezier_amt(&ptcopy
[j
- 1],
1809 pen
->width
* pen
->customstart
->inset
, TRUE
);
1811 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1812 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1813 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1814 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1817 case PathPointTypeLine
:
1818 if(pen
->startcap
== LineCapArrowAnchor
)
1819 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1820 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1822 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1823 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1824 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1825 pen
->customstart
->inset
* pen
->width
);
1827 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1828 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1833 ERR("Bad path points\n");
1838 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1840 for(i
= 0; i
< count
; i
++){
1841 tp
[i
] = convert_path_point_type(types
[i
]);
1844 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1856 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1860 BeginPath(graphics
->hdc
);
1861 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1862 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1863 EndPath(graphics
->hdc
);
1867 typedef struct _GraphicsContainerItem
{
1869 GraphicsContainer contid
;
1871 SmoothingMode smoothing
;
1872 CompositingQuality compqual
;
1873 InterpolationMode interpolation
;
1874 CompositingMode compmode
;
1875 TextRenderingHint texthint
;
1878 PixelOffsetMode pixeloffset
;
1880 GpMatrix worldtrans
;
1882 INT origin_x
, origin_y
;
1883 } GraphicsContainerItem
;
1885 static GpStatus
init_container(GraphicsContainerItem
** container
,
1886 GDIPCONST GpGraphics
* graphics
){
1889 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1893 (*container
)->contid
= graphics
->contid
+ 1;
1895 (*container
)->smoothing
= graphics
->smoothing
;
1896 (*container
)->compqual
= graphics
->compqual
;
1897 (*container
)->interpolation
= graphics
->interpolation
;
1898 (*container
)->compmode
= graphics
->compmode
;
1899 (*container
)->texthint
= graphics
->texthint
;
1900 (*container
)->scale
= graphics
->scale
;
1901 (*container
)->unit
= graphics
->unit
;
1902 (*container
)->textcontrast
= graphics
->textcontrast
;
1903 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1904 (*container
)->origin_x
= graphics
->origin_x
;
1905 (*container
)->origin_y
= graphics
->origin_y
;
1906 (*container
)->worldtrans
= graphics
->worldtrans
;
1908 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1910 GdipFree(*container
);
1918 static void delete_container(GraphicsContainerItem
* container
)
1920 GdipDeleteRegion(container
->clip
);
1921 GdipFree(container
);
1924 static GpStatus
restore_container(GpGraphics
* graphics
,
1925 GDIPCONST GraphicsContainerItem
* container
){
1929 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1930 if(sts
!= Ok
) return sts
;
1932 graphics
->worldtrans
= container
->worldtrans
;
1934 GdipDeleteRegion(graphics
->clip
);
1935 graphics
->clip
= newClip
;
1937 graphics
->contid
= container
->contid
- 1;
1939 graphics
->smoothing
= container
->smoothing
;
1940 graphics
->compqual
= container
->compqual
;
1941 graphics
->interpolation
= container
->interpolation
;
1942 graphics
->compmode
= container
->compmode
;
1943 graphics
->texthint
= container
->texthint
;
1944 graphics
->scale
= container
->scale
;
1945 graphics
->unit
= container
->unit
;
1946 graphics
->textcontrast
= container
->textcontrast
;
1947 graphics
->pixeloffset
= container
->pixeloffset
;
1948 graphics
->origin_x
= container
->origin_x
;
1949 graphics
->origin_y
= container
->origin_y
;
1954 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1960 if(graphics
->hwnd
) {
1961 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1962 return GenericError
;
1964 rect
->X
= wnd_rect
.left
;
1965 rect
->Y
= wnd_rect
.top
;
1966 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1967 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1968 }else if (graphics
->image
){
1969 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1970 if (stat
== Ok
&& unit
!= UnitPixel
)
1971 FIXME("need to convert from unit %i\n", unit
);
1972 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
1979 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
1980 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
1982 rect
->Width
= bmp
.bmWidth
;
1983 rect
->Height
= bmp
.bmHeight
;
1994 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1995 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2001 /* on success, rgn will contain the region of the graphics object which
2002 * is visible after clipping has been applied */
2003 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2009 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2012 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2015 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2018 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2021 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2024 GdipDeleteRegion(tmp
);
2028 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2032 if (font
->unit
== UnitPixel
)
2034 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2038 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2039 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2041 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2044 lf
->lfHeight
= -(height
+ 0.5);
2046 lf
->lfEscapement
= 0;
2047 lf
->lfOrientation
= 0;
2048 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2049 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2050 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2051 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2052 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2053 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2054 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2055 lf
->lfQuality
= DEFAULT_QUALITY
;
2056 lf
->lfPitchAndFamily
= 0;
2057 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2060 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2061 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2062 GDIPCONST GpMatrix
*matrix
)
2064 HDC hdc
= CreateCompatibleDC(0);
2066 REAL angle
, rel_width
, rel_height
, font_height
;
2068 HFONT unscaled_font
;
2069 TEXTMETRICW textmet
;
2071 if (font
->unit
== UnitPixel
)
2072 font_height
= font
->emSize
;
2075 REAL unit_scale
, res
;
2077 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2078 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2080 font_height
= font
->emSize
* unit_scale
;
2091 GpMatrix xform
= *matrix
;
2092 GdipTransformMatrixPoints(&xform
, pt
, 3);
2095 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2096 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2097 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2098 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2099 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2100 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2102 get_log_fontW(font
, graphics
, &lfw
);
2103 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2104 unscaled_font
= CreateFontIndirectW(&lfw
);
2106 SelectObject(hdc
, unscaled_font
);
2107 GetTextMetricsW(hdc
, &textmet
);
2109 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2110 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2112 *hfont
= CreateFontIndirectW(&lfw
);
2115 DeleteObject(unscaled_font
);
2118 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2120 TRACE("(%p, %p)\n", hdc
, graphics
);
2122 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2125 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2131 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2134 FIXME("Don't know how to handle parameter hDevice\n");
2139 if(graphics
== NULL
)
2140 return InvalidParameter
;
2142 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2143 if(!*graphics
) return OutOfMemory
;
2145 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2147 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2148 GdipFree(*graphics
);
2152 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2153 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2154 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2156 (*graphics
)->alpha_hdc
= 1;
2159 (*graphics
)->hdc
= hdc
;
2160 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2161 (*graphics
)->owndc
= FALSE
;
2162 (*graphics
)->smoothing
= SmoothingModeDefault
;
2163 (*graphics
)->compqual
= CompositingQualityDefault
;
2164 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2165 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2166 (*graphics
)->compmode
= CompositingModeSourceOver
;
2167 (*graphics
)->unit
= UnitDisplay
;
2168 (*graphics
)->scale
= 1.0;
2169 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2170 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2171 (*graphics
)->busy
= FALSE
;
2172 (*graphics
)->textcontrast
= 4;
2173 list_init(&(*graphics
)->containers
);
2174 (*graphics
)->contid
= 0;
2176 TRACE("<-- %p\n", *graphics
);
2181 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2185 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2186 if(!*graphics
) return OutOfMemory
;
2188 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2190 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2191 GdipFree(*graphics
);
2195 (*graphics
)->hdc
= NULL
;
2196 (*graphics
)->hwnd
= NULL
;
2197 (*graphics
)->owndc
= FALSE
;
2198 (*graphics
)->image
= image
;
2199 /* We have to store the image type here because the image may be freed
2200 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2201 (*graphics
)->image_type
= image
->type
;
2202 (*graphics
)->smoothing
= SmoothingModeDefault
;
2203 (*graphics
)->compqual
= CompositingQualityDefault
;
2204 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2205 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2206 (*graphics
)->compmode
= CompositingModeSourceOver
;
2207 (*graphics
)->unit
= UnitDisplay
;
2208 (*graphics
)->scale
= 1.0;
2209 (*graphics
)->xres
= image
->xres
;
2210 (*graphics
)->yres
= image
->yres
;
2211 (*graphics
)->busy
= FALSE
;
2212 (*graphics
)->textcontrast
= 4;
2213 list_init(&(*graphics
)->containers
);
2214 (*graphics
)->contid
= 0;
2216 TRACE("<-- %p\n", *graphics
);
2221 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2226 TRACE("(%p, %p)\n", hwnd
, graphics
);
2230 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2232 ReleaseDC(hwnd
, hdc
);
2236 (*graphics
)->hwnd
= hwnd
;
2237 (*graphics
)->owndc
= TRUE
;
2242 /* FIXME: no icm handling */
2243 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2245 TRACE("(%p, %p)\n", hwnd
, graphics
);
2247 return GdipCreateFromHWND(hwnd
, graphics
);
2250 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2251 GpMetafile
**metafile
)
2253 ENHMETAHEADER header
;
2254 MetafileType metafile_type
;
2256 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2258 if(!hemf
|| !metafile
)
2259 return InvalidParameter
;
2261 if (GetEnhMetaFileHeader(hemf
, sizeof(header
), &header
) == 0)
2262 return GenericError
;
2264 metafile_type
= METAFILE_GetEmfType(hemf
);
2266 if (metafile_type
== MetafileTypeInvalid
)
2267 return GenericError
;
2269 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2273 (*metafile
)->image
.type
= ImageTypeMetafile
;
2274 (*metafile
)->image
.format
= ImageFormatEMF
;
2275 (*metafile
)->image
.frame_count
= 1;
2276 (*metafile
)->image
.xres
= (REAL
)header
.szlDevice
.cx
;
2277 (*metafile
)->image
.yres
= (REAL
)header
.szlDevice
.cy
;
2278 (*metafile
)->bounds
.X
= (REAL
)header
.rclBounds
.left
;
2279 (*metafile
)->bounds
.Y
= (REAL
)header
.rclBounds
.top
;
2280 (*metafile
)->bounds
.Width
= (REAL
)(header
.rclBounds
.right
- header
.rclBounds
.left
);
2281 (*metafile
)->bounds
.Height
= (REAL
)(header
.rclBounds
.bottom
- header
.rclBounds
.top
);
2282 (*metafile
)->unit
= UnitPixel
;
2283 (*metafile
)->metafile_type
= metafile_type
;
2284 (*metafile
)->hemf
= hemf
;
2285 (*metafile
)->preserve_hemf
= !delete;
2287 TRACE("<-- %p\n", *metafile
);
2292 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2293 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2298 GpStatus retval
= Ok
;
2300 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2302 if(!hwmf
|| !metafile
|| !placeable
)
2303 return InvalidParameter
;
2306 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2308 return GenericError
;
2309 copy
= GdipAlloc(read
);
2310 GetMetaFileBitsEx(hwmf
, read
, copy
);
2312 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2315 /* FIXME: We should store and use hwmf instead of converting to hemf */
2316 retval
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
2320 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2321 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2322 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2323 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2324 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2325 placeable
->BoundingBox
.Left
);
2326 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2327 placeable
->BoundingBox
.Top
);
2328 (*metafile
)->metafile_type
= MetafileTypeWmfPlaceable
;
2329 (*metafile
)->image
.format
= ImageFormatWMF
;
2331 if (delete) DeleteMetaFile(hwmf
);
2334 DeleteEnhMetaFile(hemf
);
2338 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2339 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2341 HMETAFILE hmf
= GetMetaFileW(file
);
2343 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2345 if(!hmf
) return InvalidParameter
;
2347 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2350 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2351 GpMetafile
**metafile
)
2353 FIXME("(%p, %p): stub\n", file
, metafile
);
2354 return NotImplemented
;
2357 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2358 GpMetafile
**metafile
)
2360 FIXME("(%p, %p): stub\n", stream
, metafile
);
2361 return NotImplemented
;
2364 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2365 UINT access
, IStream
**stream
)
2370 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2372 if(!stream
|| !filename
)
2373 return InvalidParameter
;
2375 if(access
& GENERIC_WRITE
)
2376 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2377 else if(access
& GENERIC_READ
)
2378 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2380 return InvalidParameter
;
2382 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2384 return hresult_to_status(ret
);
2387 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2389 GraphicsContainerItem
*cont
, *next
;
2391 TRACE("(%p)\n", graphics
);
2393 if(!graphics
) return InvalidParameter
;
2394 if(graphics
->busy
) return ObjectBusy
;
2396 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2398 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2404 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2406 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2407 list_remove(&cont
->entry
);
2408 delete_container(cont
);
2411 GdipDeleteRegion(graphics
->clip
);
2413 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2414 * do otherwise, but we can't have that in the test suite because it means
2415 * accessing freed memory. */
2416 graphics
->busy
= TRUE
;
2423 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2424 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2429 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2430 width
, height
, startAngle
, sweepAngle
);
2432 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2433 return InvalidParameter
;
2438 status
= GdipCreatePath(FillModeAlternate
, &path
);
2439 if (status
!= Ok
) return status
;
2441 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2443 status
= GdipDrawPath(graphics
, pen
, path
);
2445 GdipDeletePath(path
);
2449 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2450 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2452 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2453 width
, height
, startAngle
, sweepAngle
);
2455 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2458 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2459 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2463 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2464 x2
, y2
, x3
, y3
, x4
, y4
);
2466 if(!graphics
|| !pen
)
2467 return InvalidParameter
;
2480 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2483 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2484 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2486 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2487 x2
, y2
, x3
, y3
, x4
, y4
);
2489 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2492 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2493 GDIPCONST GpPointF
*points
, INT count
)
2498 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2500 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2501 return InvalidParameter
;
2506 status
= GdipCreatePath(FillModeAlternate
, &path
);
2507 if (status
!= Ok
) return status
;
2509 status
= GdipAddPathBeziers(path
, points
, count
);
2511 status
= GdipDrawPath(graphics
, pen
, path
);
2513 GdipDeletePath(path
);
2517 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2518 GDIPCONST GpPoint
*points
, INT count
)
2524 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2526 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2527 return InvalidParameter
;
2532 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2536 for(i
= 0; i
< count
; i
++){
2537 pts
[i
].X
= (REAL
)points
[i
].X
;
2538 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2541 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2548 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2549 GDIPCONST GpPointF
*points
, INT count
)
2551 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2553 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2556 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2557 GDIPCONST GpPoint
*points
, INT count
)
2559 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2561 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2564 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2565 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2570 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2572 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2573 return InvalidParameter
;
2578 status
= GdipCreatePath(FillModeAlternate
, &path
);
2579 if (status
!= Ok
) return status
;
2581 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2583 status
= GdipDrawPath(graphics
, pen
, path
);
2585 GdipDeletePath(path
);
2590 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2591 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2597 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2599 if(!points
|| count
<= 0)
2600 return InvalidParameter
;
2602 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2606 for(i
= 0; i
< count
; i
++){
2607 ptf
[i
].X
= (REAL
)points
[i
].X
;
2608 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2611 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2618 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2619 GDIPCONST GpPointF
*points
, INT count
)
2621 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2623 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2626 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2627 GDIPCONST GpPoint
*points
, INT count
)
2633 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2636 return InvalidParameter
;
2638 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2642 for(i
= 0; i
< count
; i
++){
2643 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2644 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2647 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2653 /* Approximates cardinal spline with Bezier curves. */
2654 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2655 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2660 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2662 if(!graphics
|| !pen
)
2663 return InvalidParameter
;
2669 return InvalidParameter
;
2671 status
= GdipCreatePath(FillModeAlternate
, &path
);
2672 if (status
!= Ok
) return status
;
2674 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2676 status
= GdipDrawPath(graphics
, pen
, path
);
2678 GdipDeletePath(path
);
2682 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2683 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2689 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2692 return InvalidParameter
;
2694 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2698 for(i
= 0; i
< count
; i
++){
2699 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2700 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2703 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2709 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2710 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2713 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2715 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2716 return InvalidParameter
;
2719 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2722 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2723 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2726 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2732 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2733 return InvalidParameter
;
2736 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2739 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2740 REAL y
, REAL width
, REAL height
)
2745 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2747 if(!graphics
|| !pen
)
2748 return InvalidParameter
;
2753 status
= GdipCreatePath(FillModeAlternate
, &path
);
2754 if (status
!= Ok
) return status
;
2756 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2758 status
= GdipDrawPath(graphics
, pen
, path
);
2760 GdipDeletePath(path
);
2764 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2765 INT y
, INT width
, INT height
)
2767 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2769 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2773 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2777 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2779 if(!graphics
|| !image
)
2780 return InvalidParameter
;
2782 GdipGetImageWidth(image
, &width
);
2783 GdipGetImageHeight(image
, &height
);
2785 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2786 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2789 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2792 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2794 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2797 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2798 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2802 REAL scale_x
, scale_y
, width
, height
;
2804 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2806 if (!graphics
|| !image
) return InvalidParameter
;
2808 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2809 scale_x
*= graphics
->xres
/ image
->xres
;
2810 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2811 scale_y
*= graphics
->yres
/ image
->yres
;
2812 width
= srcwidth
* scale_x
;
2813 height
= srcheight
* scale_y
;
2815 points
[0].X
= points
[2].X
= x
;
2816 points
[0].Y
= points
[1].Y
= y
;
2817 points
[1].X
= x
+ width
;
2818 points
[2].Y
= y
+ height
;
2820 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2821 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2824 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2825 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2828 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2831 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2832 GDIPCONST GpPointF
*dstpoints
, INT count
)
2836 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2839 return InvalidParameter
;
2841 GdipGetImageWidth(image
, &width
);
2842 GdipGetImageHeight(image
, &height
);
2844 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2845 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2848 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2849 GDIPCONST GpPoint
*dstpoints
, INT count
)
2853 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2855 if (count
!= 3 || !dstpoints
)
2856 return InvalidParameter
;
2858 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2859 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2860 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2861 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2862 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2863 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2865 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2868 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2869 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2871 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2875 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2876 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2877 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2878 DrawImageAbort callback
, VOID
* callbackData
)
2884 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2885 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2889 return NotImplemented
;
2891 if(!graphics
|| !image
|| !points
|| count
!= 3)
2892 return InvalidParameter
;
2894 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2895 debugstr_pointf(&points
[2]));
2897 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2898 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2899 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2900 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
2902 transform_and_round_points(graphics
, pti
, ptf
, 4);
2904 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2905 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2907 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2908 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2909 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2910 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2911 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2917 FIXME("graphics object has no HDC\n");
2920 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2921 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2922 srcx
, srcy
, srcwidth
, srcheight
, NULL
) != S_OK
)
2925 callback(callbackData
);
2926 return GenericError
;
2929 else if (image
->type
== ImageTypeBitmap
)
2931 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2934 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2935 graphics
->xres
, graphics
->yres
,
2936 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2937 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2938 imageAttributes
? imageAttributes
->outside_color
: 0);
2940 if (imageAttributes
|| graphics
->alpha_hdc
||
2941 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2942 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2943 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2944 srcx
< 0 || srcy
< 0 ||
2945 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2952 int i
, x
, y
, src_stride
, dst_stride
;
2953 GpMatrix dst_to_src
;
2954 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2955 LPBYTE src_data
, dst_data
;
2956 BitmapData lockeddata
;
2957 InterpolationMode interpolation
= graphics
->interpolation
;
2958 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2959 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2960 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2961 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2963 if (!imageAttributes
)
2964 imageAttributes
= &defaultImageAttributes
;
2966 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2967 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2970 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2971 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2972 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2973 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2976 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
2978 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2979 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2980 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2981 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2982 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2983 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2985 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
2987 stat
= GdipInvertMatrix(&dst_to_src
);
2988 if (stat
!= Ok
) return stat
;
2990 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2991 if (!dst_data
) return OutOfMemory
;
2993 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2995 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2996 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2998 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3000 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3006 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3008 /* Read the bits we need from the source bitmap into an ARGB buffer. */
3009 lockeddata
.Width
= src_area
.Width
;
3010 lockeddata
.Height
= src_area
.Height
;
3011 lockeddata
.Stride
= src_stride
;
3012 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3013 lockeddata
.Scan0
= src_data
;
3015 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3016 PixelFormat32bppARGB
, &lockeddata
);
3019 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3023 if (src_data
!= dst_data
)
3029 apply_image_attributes(imageAttributes
, src_data
,
3030 src_area
.Width
, src_area
.Height
,
3031 src_stride
, ColorAdjustTypeBitmap
);
3033 /* Transform the bits as needed to the destination. */
3034 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3036 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3037 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3038 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3039 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3041 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3043 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3045 GpPointF src_pointf
;
3048 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3049 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3051 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3053 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3054 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3055 imageAttributes
, interpolation
, offset_mode
);
3063 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3064 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3073 int temp_hdc
=0, temp_bitmap
=0;
3074 HBITMAP hbitmap
, old_hbm
=NULL
;
3076 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3077 bitmap
->format
== PixelFormat24bppRGB
||
3078 bitmap
->format
== PixelFormat32bppRGB
||
3079 bitmap
->format
== PixelFormat32bppPARGB
))
3081 BITMAPINFOHEADER bih
;
3083 PixelFormat dst_format
;
3085 /* we can't draw a bitmap of this format directly */
3086 hdc
= CreateCompatibleDC(0);
3090 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3091 bih
.biWidth
= bitmap
->width
;
3092 bih
.biHeight
= -bitmap
->height
;
3094 bih
.biBitCount
= 32;
3095 bih
.biCompression
= BI_RGB
;
3096 bih
.biSizeImage
= 0;
3097 bih
.biXPelsPerMeter
= 0;
3098 bih
.biYPelsPerMeter
= 0;
3100 bih
.biClrImportant
= 0;
3102 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3103 (void**)&temp_bits
, NULL
, 0);
3105 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3106 dst_format
= PixelFormat32bppPARGB
;
3108 dst_format
= PixelFormat32bppRGB
;
3110 convert_pixels(bitmap
->width
, bitmap
->height
,
3111 bitmap
->width
*4, temp_bits
, dst_format
,
3112 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3113 bitmap
->image
.palette
);
3117 if (bitmap
->hbitmap
)
3118 hbitmap
= bitmap
->hbitmap
;
3121 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3126 temp_hdc
= (hdc
== 0);
3131 if (!hdc
) hdc
= CreateCompatibleDC(0);
3132 old_hbm
= SelectObject(hdc
, hbitmap
);
3135 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3137 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3138 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3142 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3143 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3148 SelectObject(hdc
, old_hbm
);
3153 DeleteObject(hbitmap
);
3156 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3162 rc
.Width
= srcwidth
;
3163 rc
.Height
= srcheight
;
3165 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3166 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3170 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3171 return InvalidParameter
;
3177 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3178 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3179 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3180 DrawImageAbort callback
, VOID
* callbackData
)
3182 GpPointF pointsF
[3];
3185 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3186 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3189 if(!points
|| count
!=3)
3190 return InvalidParameter
;
3192 for(i
= 0; i
< count
; i
++){
3193 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3194 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3197 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3198 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3199 callback
, callbackData
);
3202 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3203 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3204 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3205 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3206 VOID
* callbackData
)
3210 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3211 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3212 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3216 points
[1].X
= dstx
+ dstwidth
;
3219 points
[2].Y
= dsty
+ dstheight
;
3221 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3222 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3225 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3226 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3227 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3228 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3229 VOID
* callbackData
)
3233 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3234 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3235 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3239 points
[1].X
= dstx
+ dstwidth
;
3242 points
[2].Y
= dsty
+ dstheight
;
3244 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3245 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3248 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3249 REAL x
, REAL y
, REAL width
, REAL height
)
3255 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3257 if(!graphics
|| !image
)
3258 return InvalidParameter
;
3260 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3264 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3265 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3266 unit
, NULL
, NULL
, NULL
);
3269 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3270 INT x
, INT y
, INT width
, INT height
)
3272 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3274 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3277 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3278 REAL y1
, REAL x2
, REAL y2
)
3282 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3288 return GdipDrawLines(graphics
, pen
, pt
, 2);
3291 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3292 INT y1
, INT x2
, INT y2
)
3294 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3296 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3299 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3300 GpPointF
*points
, INT count
)
3305 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3307 if(!pen
|| !graphics
|| (count
< 2))
3308 return InvalidParameter
;
3313 status
= GdipCreatePath(FillModeAlternate
, &path
);
3314 if (status
!= Ok
) return status
;
3316 status
= GdipAddPathLine2(path
, points
, count
);
3318 status
= GdipDrawPath(graphics
, pen
, path
);
3320 GdipDeletePath(path
);
3324 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3325 GpPoint
*points
, INT count
)
3331 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3333 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3334 if(!ptf
) return OutOfMemory
;
3336 for(i
= 0; i
< count
; i
++){
3337 ptf
[i
].X
= (REAL
) points
[i
].X
;
3338 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3341 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3347 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3353 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3355 if(!pen
|| !graphics
)
3356 return InvalidParameter
;
3363 FIXME("graphics object has no HDC\n");
3367 save_state
= prepare_dc(graphics
, pen
);
3369 retval
= get_clip_hrgn(graphics
, &hrgn
);
3375 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3377 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3378 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3381 restore_dc(graphics
, save_state
);
3387 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3388 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3393 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3394 width
, height
, startAngle
, sweepAngle
);
3396 if(!graphics
|| !pen
)
3397 return InvalidParameter
;
3402 status
= GdipCreatePath(FillModeAlternate
, &path
);
3403 if (status
!= Ok
) return status
;
3405 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3407 status
= GdipDrawPath(graphics
, pen
, path
);
3409 GdipDeletePath(path
);
3413 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3414 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3416 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3417 width
, height
, startAngle
, sweepAngle
);
3419 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3422 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3423 REAL y
, REAL width
, REAL height
)
3428 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3430 if(!pen
|| !graphics
)
3431 return InvalidParameter
;
3436 status
= GdipCreatePath(FillModeAlternate
, &path
);
3437 if (status
!= Ok
) return status
;
3439 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3441 status
= GdipDrawPath(graphics
, pen
, path
);
3443 GdipDeletePath(path
);
3447 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3448 INT y
, INT width
, INT height
)
3450 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3452 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3455 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3456 GDIPCONST GpRectF
* rects
, INT count
)
3461 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3463 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3464 return InvalidParameter
;
3469 status
= GdipCreatePath(FillModeAlternate
, &path
);
3470 if (status
!= Ok
) return status
;
3472 status
= GdipAddPathRectangles(path
, rects
, count
);
3474 status
= GdipDrawPath(graphics
, pen
, path
);
3476 GdipDeletePath(path
);
3480 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3481 GDIPCONST GpRect
* rects
, INT count
)
3487 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3489 if(!rects
|| count
<=0)
3490 return InvalidParameter
;
3492 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3496 for(i
= 0;i
< count
;i
++){
3497 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3498 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3499 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3500 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3503 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3509 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3510 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3515 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3516 count
, tension
, fill
);
3518 if(!graphics
|| !brush
|| !points
)
3519 return InvalidParameter
;
3524 if(count
== 1) /* Do nothing */
3527 status
= GdipCreatePath(fill
, &path
);
3528 if (status
!= Ok
) return status
;
3530 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3532 status
= GdipFillPath(graphics
, brush
, path
);
3534 GdipDeletePath(path
);
3538 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3539 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3545 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3546 count
, tension
, fill
);
3548 if(!points
|| count
== 0)
3549 return InvalidParameter
;
3551 if(count
== 1) /* Do nothing */
3554 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3558 for(i
= 0;i
< count
;i
++){
3559 ptf
[i
].X
= (REAL
)points
[i
].X
;
3560 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3563 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3570 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3571 GDIPCONST GpPointF
*points
, INT count
)
3573 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3574 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3575 0.5f
, FillModeAlternate
);
3578 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3579 GDIPCONST GpPoint
*points
, INT count
)
3581 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3582 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3583 0.5f
, FillModeAlternate
);
3586 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3587 REAL y
, REAL width
, REAL height
)
3592 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3594 if(!graphics
|| !brush
)
3595 return InvalidParameter
;
3600 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3604 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3607 stat
= GdipFillPath(graphics
, brush
, path
);
3609 GdipDeletePath(path
);
3615 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3616 INT y
, INT width
, INT height
)
3618 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3620 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3623 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3629 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3630 return NotImplemented
;
3632 save_state
= SaveDC(graphics
->hdc
);
3633 EndPath(graphics
->hdc
);
3634 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3637 retval
= get_clip_hrgn(graphics
, &hrgn
);
3643 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3645 BeginPath(graphics
->hdc
);
3646 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3647 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3652 EndPath(graphics
->hdc
);
3653 brush_fill_path(graphics
, brush
);
3658 RestoreDC(graphics
->hdc
, save_state
);
3664 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3669 if (!brush_can_fill_pixels(brush
))
3670 return NotImplemented
;
3672 /* FIXME: This could probably be done more efficiently without regions. */
3674 stat
= GdipCreateRegionPath(path
, &rgn
);
3678 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3680 GdipDeleteRegion(rgn
);
3686 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3688 GpStatus stat
= NotImplemented
;
3690 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3692 if(!brush
|| !graphics
|| !path
)
3693 return InvalidParameter
;
3698 if (!graphics
->image
&& !graphics
->alpha_hdc
)
3699 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3701 if (stat
== NotImplemented
)
3702 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3704 if (stat
== NotImplemented
)
3706 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3713 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3714 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3719 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3720 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3722 if(!graphics
|| !brush
)
3723 return InvalidParameter
;
3728 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3732 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3735 stat
= GdipFillPath(graphics
, brush
, path
);
3737 GdipDeletePath(path
);
3743 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3744 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3746 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3747 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3749 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3752 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3753 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3758 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3760 if(!graphics
|| !brush
|| !points
|| !count
)
3761 return InvalidParameter
;
3766 stat
= GdipCreatePath(fillMode
, &path
);
3770 stat
= GdipAddPathPolygon(path
, points
, count
);
3773 stat
= GdipFillPath(graphics
, brush
, path
);
3775 GdipDeletePath(path
);
3781 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3782 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3787 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3789 if(!graphics
|| !brush
|| !points
|| !count
)
3790 return InvalidParameter
;
3795 stat
= GdipCreatePath(fillMode
, &path
);
3799 stat
= GdipAddPathPolygonI(path
, points
, count
);
3802 stat
= GdipFillPath(graphics
, brush
, path
);
3804 GdipDeletePath(path
);
3810 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3811 GDIPCONST GpPointF
*points
, INT count
)
3813 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3815 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3818 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3819 GDIPCONST GpPoint
*points
, INT count
)
3821 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3823 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3826 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3827 REAL x
, REAL y
, REAL width
, REAL height
)
3831 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3836 rect
.Height
= height
;
3838 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
3841 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3842 INT x
, INT y
, INT width
, INT height
)
3846 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3850 rect
.Width
= (REAL
)width
;
3851 rect
.Height
= (REAL
)height
;
3853 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
3856 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3862 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3865 return InvalidParameter
;
3867 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
3869 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
3870 /* FIXME: Add gdi32 drawing. */
3874 status
= GdipCreatePath(FillModeAlternate
, &path
);
3875 if (status
!= Ok
) return status
;
3877 status
= GdipAddPathRectangles(path
, rects
, count
);
3879 status
= GdipFillPath(graphics
, brush
, path
);
3881 GdipDeletePath(path
);
3885 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3892 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3894 if(!rects
|| count
<= 0)
3895 return InvalidParameter
;
3897 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3901 for(i
= 0; i
< count
; i
++){
3902 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3903 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3904 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3905 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3908 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3914 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3922 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3923 return NotImplemented
;
3925 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3929 save_state
= SaveDC(graphics
->hdc
);
3930 EndPath(graphics
->hdc
);
3932 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3934 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3936 BeginPath(graphics
->hdc
);
3937 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3938 EndPath(graphics
->hdc
);
3940 brush_fill_path(graphics
, brush
);
3943 RestoreDC(graphics
->hdc
, save_state
);
3950 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3954 GpRegion
*temp_region
;
3955 GpMatrix world_to_device
;
3956 GpRectF graphics_bounds
;
3960 GpRect gp_bound_rect
;
3962 if (!brush_can_fill_pixels(brush
))
3963 return NotImplemented
;
3965 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3968 stat
= GdipCloneRegion(region
, &temp_region
);
3972 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3973 CoordinateSpaceWorld
, &world_to_device
);
3976 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
3979 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
3982 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
3984 GdipDeleteRegion(temp_region
);
3987 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
3989 DeleteObject(hregion
);
3995 gp_bound_rect
.X
= bound_rect
.left
;
3996 gp_bound_rect
.Y
= bound_rect
.top
;
3997 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
3998 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4000 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4006 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4007 &gp_bound_rect
, gp_bound_rect
.Width
);
4010 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4011 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4012 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4014 GdipFree(pixel_data
);
4017 DeleteObject(hregion
);
4023 /*****************************************************************************
4024 * GdipFillRegion [GDIPLUS.@]
4026 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4029 GpStatus stat
= NotImplemented
;
4031 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4033 if (!(graphics
&& brush
&& region
))
4034 return InvalidParameter
;
4039 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4040 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4042 if (stat
== NotImplemented
)
4043 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4045 if (stat
== NotImplemented
)
4047 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4054 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4056 TRACE("(%p,%u)\n", graphics
, intention
);
4059 return InvalidParameter
;
4064 /* We have no internal operation queue, so there's no need to clear it. */
4072 /*****************************************************************************
4073 * GdipGetClipBounds [GDIPLUS.@]
4075 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4080 TRACE("(%p, %p)\n", graphics
, rect
);
4083 return InvalidParameter
;
4088 status
= GdipCreateRegion(&clip
);
4089 if (status
!= Ok
) return status
;
4091 status
= GdipGetClip(graphics
, clip
);
4093 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4095 GdipDeleteRegion(clip
);
4099 /*****************************************************************************
4100 * GdipGetClipBoundsI [GDIPLUS.@]
4102 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4104 TRACE("(%p, %p)\n", graphics
, rect
);
4107 return InvalidParameter
;
4112 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4115 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4116 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4117 CompositingMode
*mode
)
4119 TRACE("(%p, %p)\n", graphics
, mode
);
4121 if(!graphics
|| !mode
)
4122 return InvalidParameter
;
4127 *mode
= graphics
->compmode
;
4132 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4133 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4134 CompositingQuality
*quality
)
4136 TRACE("(%p, %p)\n", graphics
, quality
);
4138 if(!graphics
|| !quality
)
4139 return InvalidParameter
;
4144 *quality
= graphics
->compqual
;
4149 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4150 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4151 InterpolationMode
*mode
)
4153 TRACE("(%p, %p)\n", graphics
, mode
);
4155 if(!graphics
|| !mode
)
4156 return InvalidParameter
;
4161 *mode
= graphics
->interpolation
;
4166 /* FIXME: Need to handle color depths less than 24bpp */
4167 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4169 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4171 if(!graphics
|| !argb
)
4172 return InvalidParameter
;
4180 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4182 TRACE("(%p, %p)\n", graphics
, scale
);
4184 if(!graphics
|| !scale
)
4185 return InvalidParameter
;
4190 *scale
= graphics
->scale
;
4195 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4197 TRACE("(%p, %p)\n", graphics
, unit
);
4199 if(!graphics
|| !unit
)
4200 return InvalidParameter
;
4205 *unit
= graphics
->unit
;
4210 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4211 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4214 TRACE("(%p, %p)\n", graphics
, mode
);
4216 if(!graphics
|| !mode
)
4217 return InvalidParameter
;
4222 *mode
= graphics
->pixeloffset
;
4227 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4228 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4230 TRACE("(%p, %p)\n", graphics
, mode
);
4232 if(!graphics
|| !mode
)
4233 return InvalidParameter
;
4238 *mode
= graphics
->smoothing
;
4243 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4245 TRACE("(%p, %p)\n", graphics
, contrast
);
4247 if(!graphics
|| !contrast
)
4248 return InvalidParameter
;
4250 *contrast
= graphics
->textcontrast
;
4255 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4256 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4257 TextRenderingHint
*hint
)
4259 TRACE("(%p, %p)\n", graphics
, hint
);
4261 if(!graphics
|| !hint
)
4262 return InvalidParameter
;
4267 *hint
= graphics
->texthint
;
4272 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4277 TRACE("(%p, %p)\n", graphics
, rect
);
4279 if(!graphics
|| !rect
)
4280 return InvalidParameter
;
4285 /* intersect window and graphics clipping regions */
4286 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4289 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4292 /* get bounds of the region */
4293 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4296 GdipDeleteRegion(clip_rgn
);
4301 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4306 TRACE("(%p, %p)\n", graphics
, rect
);
4308 if(!graphics
|| !rect
)
4309 return InvalidParameter
;
4311 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4313 rect
->X
= gdip_round(rectf
.X
);
4314 rect
->Y
= gdip_round(rectf
.Y
);
4315 rect
->Width
= gdip_round(rectf
.Width
);
4316 rect
->Height
= gdip_round(rectf
.Height
);
4322 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4324 TRACE("(%p, %p)\n", graphics
, matrix
);
4326 if(!graphics
|| !matrix
)
4327 return InvalidParameter
;
4332 *matrix
= graphics
->worldtrans
;
4336 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4342 TRACE("(%p, %x)\n", graphics
, color
);
4345 return InvalidParameter
;
4350 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4353 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4354 GdipDeleteBrush((GpBrush
*)brush
);
4358 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4359 wnd_rect
.Width
, wnd_rect
.Height
);
4361 GdipDeleteBrush((GpBrush
*)brush
);
4366 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4368 TRACE("(%p, %p)\n", graphics
, res
);
4370 if(!graphics
|| !res
)
4371 return InvalidParameter
;
4373 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4376 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4382 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4384 if(!graphics
|| !result
)
4385 return InvalidParameter
;
4392 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4393 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4396 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4399 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4402 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4405 GdipDeleteRegion(rgn
);
4409 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4411 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4414 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4420 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4422 if(!graphics
|| !result
)
4423 return InvalidParameter
;
4430 pts
[1].X
= x
+ width
;
4431 pts
[1].Y
= y
+ height
;
4433 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4434 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4437 pts
[1].X
-= pts
[0].X
;
4438 pts
[1].Y
-= pts
[0].Y
;
4440 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4443 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4446 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4449 GdipDeleteRegion(rgn
);
4453 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4455 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4458 GpStatus
gdip_format_string(HDC hdc
,
4459 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4460 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4461 gdip_format_string_callback callback
, void *user_data
)
4464 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4465 nheight
, lineend
, lineno
= 0;
4467 StringAlignment halign
;
4470 HotkeyPrefix hkprefix
;
4471 INT
*hotkeyprefix_offsets
=NULL
;
4472 INT hotkeyprefix_count
=0;
4473 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4476 if(length
== -1) length
= lstrlenW(string
);
4478 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4479 if(!stringdup
) return OutOfMemory
;
4481 nwidth
= rect
->Width
;
4482 nheight
= rect
->Height
;
4483 if (ignore_empty_clip
)
4485 if (!nwidth
) nwidth
= INT_MAX
;
4486 if (!nheight
) nheight
= INT_MAX
;
4490 hkprefix
= format
->hkprefix
;
4492 hkprefix
= HotkeyPrefixNone
;
4494 if (hkprefix
== HotkeyPrefixShow
)
4496 for (i
=0; i
<length
; i
++)
4498 if (string
[i
] == '&')
4499 hotkeyprefix_count
++;
4503 if (hotkeyprefix_count
)
4504 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4506 hotkeyprefix_count
= 0;
4508 for(i
= 0, j
= 0; i
< length
; i
++){
4509 /* FIXME: This makes the indexes passed to callback inaccurate. */
4510 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4513 /* FIXME: tabs should be handled using tabstops from stringformat */
4514 if (string
[i
] == '\t')
4517 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4518 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4519 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4527 stringdup
[j
] = string
[i
];
4533 if (format
) halign
= format
->align
;
4534 else halign
= StringAlignmentNear
;
4536 while(sum
< length
){
4537 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4538 nwidth
, &fit
, NULL
, &size
);
4544 for(lret
= 0; lret
< fit
; lret
++)
4545 if(*(stringdup
+ sum
+ lret
) == '\n')
4548 /* Line break code (may look strange, but it imitates windows). */
4550 lineend
= fit
= lret
; /* this is not an off-by-one error */
4551 else if(fit
< (length
- sum
)){
4552 if(*(stringdup
+ sum
+ fit
) == ' ')
4553 while(*(stringdup
+ sum
+ fit
) == ' ')
4556 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4559 if(*(stringdup
+ sum
+ fit
) == '\t')
4568 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4569 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4575 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4576 nwidth
, &j
, NULL
, &size
);
4578 bounds
.Width
= size
.cx
;
4580 if(height
+ size
.cy
> nheight
)
4582 if (format
->attr
& StringFormatFlagsLineLimit
)
4584 bounds
.Height
= nheight
- (height
+ size
.cy
);
4587 bounds
.Height
= size
.cy
;
4589 bounds
.Y
= rect
->Y
+ height
;
4593 case StringAlignmentNear
:
4597 case StringAlignmentCenter
:
4598 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4600 case StringAlignmentFar
:
4601 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4605 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4606 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4609 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4610 font
, rect
, format
, lineno
, &bounds
,
4611 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4612 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4617 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4621 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4623 if(height
> nheight
)
4626 /* Stop if this was a linewrap (but not if it was a linebreak). */
4627 if ((lret
== fitcpy
) && format
&&
4628 (format
->attr
& StringFormatFlagsNoWrap
))
4632 GdipFree(stringdup
);
4633 GdipFree(hotkeyprefix_offsets
);
4638 struct measure_ranges_args
{
4640 REAL rel_width
, rel_height
;
4643 static GpStatus
measure_ranges_callback(HDC hdc
,
4644 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4645 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4646 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4647 INT underlined_index_count
, void *user_data
)
4651 struct measure_ranges_args
*args
= user_data
;
4653 for (i
=0; i
<format
->range_count
; i
++)
4655 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4656 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4657 if (range_start
< range_end
)
4662 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4663 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4665 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4666 INT_MAX
, NULL
, NULL
, &range_size
);
4667 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4669 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4670 INT_MAX
, NULL
, NULL
, &range_size
);
4671 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4673 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4682 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4683 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4684 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4685 INT regionCount
, GpRegion
** regions
)
4689 HFONT gdifont
, oldfont
;
4690 struct measure_ranges_args args
;
4691 HDC hdc
, temp_hdc
=NULL
;
4696 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4697 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4699 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4700 return InvalidParameter
;
4702 if (regionCount
< stringFormat
->range_count
)
4703 return InvalidParameter
;
4707 hdc
= temp_hdc
= CreateCompatibleDC(0);
4708 if (!temp_hdc
) return OutOfMemory
;
4711 hdc
= graphics
->hdc
;
4713 if (stringFormat
->attr
)
4714 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4722 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4723 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4724 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4725 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4726 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4728 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4729 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4731 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4732 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4733 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
4734 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
4736 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
4737 oldfont
= SelectObject(hdc
, gdifont
);
4739 for (i
=0; i
<stringFormat
->range_count
; i
++)
4741 stat
= GdipSetEmpty(regions
[i
]);
4746 args
.regions
= regions
;
4748 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
4749 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
4751 SelectObject(hdc
, oldfont
);
4752 DeleteObject(gdifont
);
4760 struct measure_string_args
{
4762 INT
*codepointsfitted
;
4764 REAL rel_width
, rel_height
;
4767 static GpStatus
measure_string_callback(HDC hdc
,
4768 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4769 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4770 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4771 INT underlined_index_count
, void *user_data
)
4773 struct measure_string_args
*args
= user_data
;
4774 REAL new_width
, new_height
;
4776 new_width
= bounds
->Width
/ args
->rel_width
;
4777 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
4779 if (new_width
> args
->bounds
->Width
)
4780 args
->bounds
->Width
= new_width
;
4782 if (new_height
> args
->bounds
->Height
)
4783 args
->bounds
->Height
= new_height
;
4785 if (args
->codepointsfitted
)
4786 *args
->codepointsfitted
= index
+ length
;
4788 if (args
->linesfilled
)
4789 (*args
->linesfilled
)++;
4794 /* Find the smallest rectangle that bounds the text when it is printed in rect
4795 * according to the format options listed in format. If rect has 0 width and
4796 * height, then just find the smallest rectangle that bounds the text when it's
4797 * printed at location (rect->X, rect-Y). */
4798 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4799 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4800 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4801 INT
*codepointsfitted
, INT
*linesfilled
)
4803 HFONT oldfont
, gdifont
;
4804 struct measure_string_args args
;
4805 HDC temp_hdc
=NULL
, hdc
;
4811 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4812 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4813 bounds
, codepointsfitted
, linesfilled
);
4815 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4816 return InvalidParameter
;
4820 hdc
= temp_hdc
= CreateCompatibleDC(0);
4821 if (!temp_hdc
) return OutOfMemory
;
4824 hdc
= graphics
->hdc
;
4826 if(linesfilled
) *linesfilled
= 0;
4827 if(codepointsfitted
) *codepointsfitted
= 0;
4830 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4838 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4839 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4840 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4841 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4842 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4844 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4845 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4847 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
4848 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
4849 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
4850 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
4851 if (scaled_rect
.Width
>= 0.5)
4853 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4854 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4857 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4858 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4860 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
4861 oldfont
= SelectObject(hdc
, gdifont
);
4863 bounds
->X
= rect
->X
;
4864 bounds
->Y
= rect
->Y
;
4865 bounds
->Width
= 0.0;
4866 bounds
->Height
= 0.0;
4868 args
.bounds
= bounds
;
4869 args
.codepointsfitted
= &glyphs
;
4870 args
.linesfilled
= &lines
;
4873 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
4874 measure_string_callback
, &args
);
4876 if (linesfilled
) *linesfilled
= lines
;
4877 if (codepointsfitted
) *codepointsfitted
= glyphs
;
4880 bounds
->Width
+= margin_x
* 2.0;
4882 SelectObject(hdc
, oldfont
);
4883 DeleteObject(gdifont
);
4891 struct draw_string_args
{
4892 GpGraphics
*graphics
;
4893 GDIPCONST GpBrush
*brush
;
4894 REAL x
, y
, rel_width
, rel_height
, ascent
;
4897 static GpStatus
draw_string_callback(HDC hdc
,
4898 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4899 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4900 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4901 INT underlined_index_count
, void *user_data
)
4903 struct draw_string_args
*args
= user_data
;
4907 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4908 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4910 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
4911 args
->brush
, &position
,
4912 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4914 if (stat
== Ok
&& underlined_index_count
)
4916 OUTLINETEXTMETRICW otm
;
4917 REAL underline_y
, underline_height
;
4920 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
4922 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
4923 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
4925 for (i
=0; i
<underlined_index_count
; i
++)
4927 REAL start_x
, end_x
;
4929 INT ofs
= underlined_indexes
[i
] - index
;
4931 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
4932 start_x
= text_size
.cx
/ args
->rel_width
;
4934 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
4935 end_x
= text_size
.cx
/ args
->rel_width
;
4937 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
4944 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4945 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4946 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4950 GpPointF pt
[3], rectcpy
[4];
4952 REAL rel_width
, rel_height
, margin_x
;
4953 INT save_state
, format_flags
= 0;
4955 struct draw_string_args args
;
4957 HDC hdc
, temp_hdc
=NULL
;
4958 TEXTMETRICW textmetric
;
4960 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4961 length
, font
, debugstr_rectf(rect
), format
, brush
);
4963 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4964 return InvalidParameter
;
4968 hdc
= graphics
->hdc
;
4972 hdc
= temp_hdc
= CreateCompatibleDC(0);
4976 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4978 format_flags
= format
->attr
;
4980 /* Should be no need to explicitly test for StringAlignmentNear as
4981 * that is default behavior if no alignment is passed. */
4982 if(format
->vertalign
!= StringAlignmentNear
){
4983 RectF bounds
, in_rect
= *rect
;
4984 in_rect
.Height
= 0.0; /* avoid height clipping */
4985 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
4987 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
4989 if(format
->vertalign
== StringAlignmentCenter
)
4990 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4991 else if(format
->vertalign
== StringAlignmentFar
)
4992 offsety
= (rect
->Height
- bounds
.Height
);
4994 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
4997 save_state
= SaveDC(hdc
);
5005 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5006 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5007 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5008 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5009 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5011 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5012 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5013 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5014 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5015 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5017 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5018 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5020 scaled_rect
.X
= margin_x
* rel_width
;
5021 scaled_rect
.Y
= 0.0;
5022 scaled_rect
.Width
= rel_width
* rect
->Width
;
5023 scaled_rect
.Height
= rel_height
* rect
->Height
;
5024 if (scaled_rect
.Width
>= 0.5)
5026 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5027 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5030 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5031 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5033 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5034 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5035 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5037 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5038 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5039 SelectClipRgn(hdc
, rgn
);
5042 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5043 SelectObject(hdc
, gdifont
);
5045 args
.graphics
= graphics
;
5049 args
.y
= rect
->Y
+ offsety
;
5051 args
.rel_width
= rel_width
;
5052 args
.rel_height
= rel_height
;
5054 GetTextMetricsW(hdc
, &textmetric
);
5055 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5057 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5058 draw_string_callback
, &args
);
5061 DeleteObject(gdifont
);
5063 RestoreDC(hdc
, save_state
);
5070 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5072 TRACE("(%p)\n", graphics
);
5075 return InvalidParameter
;
5080 return GdipSetInfinite(graphics
->clip
);
5083 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5085 TRACE("(%p)\n", graphics
);
5088 return InvalidParameter
;
5093 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5096 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5098 return GdipEndContainer(graphics
, state
);
5101 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5102 GpMatrixOrder order
)
5104 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5107 return InvalidParameter
;
5112 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5115 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5117 return GdipBeginContainer2(graphics
, state
);
5120 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5121 GraphicsContainer
*state
)
5123 GraphicsContainerItem
*container
;
5126 TRACE("(%p, %p)\n", graphics
, state
);
5128 if(!graphics
|| !state
)
5129 return InvalidParameter
;
5131 sts
= init_container(&container
, graphics
);
5135 list_add_head(&graphics
->containers
, &container
->entry
);
5136 *state
= graphics
->contid
= container
->contid
;
5141 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5143 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5144 return NotImplemented
;
5147 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5149 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5150 return NotImplemented
;
5153 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5155 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5156 return NotImplemented
;
5159 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5162 GraphicsContainerItem
*container
, *container2
;
5164 TRACE("(%p, %x)\n", graphics
, state
);
5167 return InvalidParameter
;
5169 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5170 if(container
->contid
== state
)
5174 /* did not find a matching container */
5175 if(&container
->entry
== &graphics
->containers
)
5178 sts
= restore_container(graphics
, container
);
5182 /* remove all of the containers on top of the found container */
5183 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5184 if(container
->contid
== state
)
5186 list_remove(&container
->entry
);
5187 delete_container(container
);
5190 list_remove(&container
->entry
);
5191 delete_container(container
);
5196 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5197 REAL sy
, GpMatrixOrder order
)
5199 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5202 return InvalidParameter
;
5207 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5210 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5213 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5215 if(!graphics
|| !srcgraphics
)
5216 return InvalidParameter
;
5218 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5221 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5222 CompositingMode mode
)
5224 TRACE("(%p, %d)\n", graphics
, mode
);
5227 return InvalidParameter
;
5232 graphics
->compmode
= mode
;
5237 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5238 CompositingQuality quality
)
5240 TRACE("(%p, %d)\n", graphics
, quality
);
5243 return InvalidParameter
;
5248 graphics
->compqual
= quality
;
5253 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5254 InterpolationMode mode
)
5256 TRACE("(%p, %d)\n", graphics
, mode
);
5258 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5259 return InvalidParameter
;
5264 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5265 mode
= InterpolationModeBilinear
;
5267 if (mode
== InterpolationModeHighQuality
)
5268 mode
= InterpolationModeHighQualityBicubic
;
5270 graphics
->interpolation
= mode
;
5275 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5279 TRACE("(%p, %.2f)\n", graphics
, scale
);
5281 if(!graphics
|| (scale
<= 0.0))
5282 return InvalidParameter
;
5287 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5289 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
5294 graphics
->scale
= scale
;
5299 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5303 TRACE("(%p, %d)\n", graphics
, unit
);
5306 return InvalidParameter
;
5311 if(unit
== UnitWorld
)
5312 return InvalidParameter
;
5314 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5316 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
5321 graphics
->unit
= unit
;
5326 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5329 TRACE("(%p, %d)\n", graphics
, mode
);
5332 return InvalidParameter
;
5337 graphics
->pixeloffset
= mode
;
5342 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5346 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5349 FIXME("value is unused in rendering\n");
5352 return InvalidParameter
;
5354 graphics
->origin_x
= x
;
5355 graphics
->origin_y
= y
;
5360 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5362 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5364 if (!graphics
|| !x
|| !y
)
5365 return InvalidParameter
;
5367 *x
= graphics
->origin_x
;
5368 *y
= graphics
->origin_y
;
5373 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5375 TRACE("(%p, %d)\n", graphics
, mode
);
5378 return InvalidParameter
;
5383 graphics
->smoothing
= mode
;
5388 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5390 TRACE("(%p, %d)\n", graphics
, contrast
);
5393 return InvalidParameter
;
5395 graphics
->textcontrast
= contrast
;
5400 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5401 TextRenderingHint hint
)
5403 TRACE("(%p, %d)\n", graphics
, hint
);
5405 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5406 return InvalidParameter
;
5411 graphics
->texthint
= hint
;
5416 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5418 TRACE("(%p, %p)\n", graphics
, matrix
);
5420 if(!graphics
|| !matrix
)
5421 return InvalidParameter
;
5426 TRACE("%f,%f,%f,%f,%f,%f\n",
5427 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5428 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5430 graphics
->worldtrans
= *matrix
;
5435 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5436 REAL dy
, GpMatrixOrder order
)
5438 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5441 return InvalidParameter
;
5446 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5449 /*****************************************************************************
5450 * GdipSetClipHrgn [GDIPLUS.@]
5452 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5457 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5460 return InvalidParameter
;
5465 /* hrgn is already in device units */
5466 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5470 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5472 GdipDeleteRegion(region
);
5476 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5481 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5484 return InvalidParameter
;
5489 status
= GdipClonePath(path
, &clip_path
);
5492 GpMatrix world_to_device
;
5494 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
5495 CoordinateSpaceWorld
, &world_to_device
);
5496 status
= GdipTransformPath(clip_path
, &world_to_device
);
5498 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
5500 GdipDeletePath(clip_path
);
5505 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5506 REAL width
, REAL height
,
5513 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5516 return InvalidParameter
;
5524 rect
.Height
= height
;
5525 status
= GdipCreateRegionRect(&rect
, ®ion
);
5528 GpMatrix world_to_device
;
5530 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5531 status
= GdipTransformRegion(region
, &world_to_device
);
5533 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5535 GdipDeleteRegion(region
);
5540 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5541 INT width
, INT height
,
5544 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5547 return InvalidParameter
;
5552 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5555 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5561 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5563 if(!graphics
|| !region
)
5564 return InvalidParameter
;
5569 status
= GdipCloneRegion(region
, &clip
);
5572 GpMatrix world_to_device
;
5574 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5575 status
= GdipTransformRegion(clip
, &world_to_device
);
5577 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
5579 GdipDeleteRegion(clip
);
5584 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5589 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5592 FIXME("not implemented\n");
5594 return NotImplemented
;
5597 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5603 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5605 if(!graphics
|| !pen
|| count
<=0)
5606 return InvalidParameter
;
5613 FIXME("graphics object has no HDC\n");
5617 pti
= GdipAlloc(sizeof(POINT
) * count
);
5619 save_state
= prepare_dc(graphics
, pen
);
5620 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5622 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5623 Polygon(graphics
->hdc
, pti
, count
);
5625 restore_dc(graphics
, save_state
);
5631 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5638 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5640 if(count
<=0) return InvalidParameter
;
5641 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5643 for(i
= 0;i
< count
; i
++){
5644 ptf
[i
].X
= (REAL
)points
[i
].X
;
5645 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5648 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5654 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5656 TRACE("(%p, %p)\n", graphics
, dpi
);
5658 if(!graphics
|| !dpi
)
5659 return InvalidParameter
;
5664 *dpi
= graphics
->xres
;
5668 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5670 TRACE("(%p, %p)\n", graphics
, dpi
);
5672 if(!graphics
|| !dpi
)
5673 return InvalidParameter
;
5678 *dpi
= graphics
->yres
;
5682 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5683 GpMatrixOrder order
)
5688 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5690 if(!graphics
|| !matrix
)
5691 return InvalidParameter
;
5696 m
= graphics
->worldtrans
;
5698 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5700 graphics
->worldtrans
= m
;
5705 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5706 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5708 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5712 TRACE("(%p, %p)\n", graphics
, hdc
);
5714 if(!graphics
|| !hdc
)
5715 return InvalidParameter
;
5720 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5722 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5724 else if (!graphics
->hdc
|| graphics
->alpha_hdc
||
5725 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5727 /* Create a fake HDC and fill it with a constant color. */
5731 BITMAPINFOHEADER bmih
;
5734 stat
= get_graphics_bounds(graphics
, &bounds
);
5738 graphics
->temp_hbitmap_width
= bounds
.Width
;
5739 graphics
->temp_hbitmap_height
= bounds
.Height
;
5741 bmih
.biSize
= sizeof(bmih
);
5742 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5743 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5745 bmih
.biBitCount
= 32;
5746 bmih
.biCompression
= BI_RGB
;
5747 bmih
.biSizeImage
= 0;
5748 bmih
.biXPelsPerMeter
= 0;
5749 bmih
.biYPelsPerMeter
= 0;
5751 bmih
.biClrImportant
= 0;
5753 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5754 (void**)&graphics
->temp_bits
, NULL
, 0);
5756 return GenericError
;
5758 temp_hdc
= CreateCompatibleDC(0);
5761 DeleteObject(hbitmap
);
5762 return GenericError
;
5765 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5766 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5768 SelectObject(temp_hdc
, hbitmap
);
5770 graphics
->temp_hbitmap
= hbitmap
;
5771 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5775 *hdc
= graphics
->hdc
;
5779 graphics
->busy
= TRUE
;
5784 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5788 TRACE("(%p, %p)\n", graphics
, hdc
);
5790 if(!graphics
|| !hdc
|| !graphics
->busy
)
5791 return InvalidParameter
;
5793 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5795 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5797 else if (graphics
->temp_hdc
== hdc
)
5802 /* Find the pixels that have changed, and mark them as opaque. */
5803 pos
= (DWORD
*)graphics
->temp_bits
;
5804 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5806 if (*pos
!= DC_BACKGROUND_KEY
)
5813 /* Write the changed pixels to the real target. */
5814 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5815 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5816 graphics
->temp_hbitmap_width
* 4);
5819 DeleteDC(graphics
->temp_hdc
);
5820 DeleteObject(graphics
->temp_hbitmap
);
5821 graphics
->temp_hdc
= NULL
;
5822 graphics
->temp_hbitmap
= NULL
;
5824 else if (hdc
!= graphics
->hdc
)
5826 stat
= InvalidParameter
;
5830 graphics
->busy
= FALSE
;
5835 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5839 GpMatrix device_to_world
;
5841 TRACE("(%p, %p)\n", graphics
, region
);
5843 if(!graphics
|| !region
)
5844 return InvalidParameter
;
5849 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5852 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
5853 status
= GdipTransformRegion(clip
, &device_to_world
);
5856 GdipDeleteRegion(clip
);
5860 /* free everything except root node and header */
5861 delete_element(®ion
->node
);
5862 memcpy(region
, clip
, sizeof(GpRegion
));
5868 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5869 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
5872 REAL scale_x
, scale_y
;
5874 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5876 if (dst_space
!= src_space
)
5878 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5879 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5881 if(graphics
->unit
!= UnitDisplay
)
5883 scale_x
*= graphics
->scale
;
5884 scale_y
*= graphics
->scale
;
5887 /* transform from src_space to CoordinateSpacePage */
5890 case CoordinateSpaceWorld
:
5891 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
5893 case CoordinateSpacePage
:
5895 case CoordinateSpaceDevice
:
5896 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
5900 /* transform from CoordinateSpacePage to dst_space */
5903 case CoordinateSpaceWorld
:
5905 GpMatrix inverted_transform
= graphics
->worldtrans
;
5906 stat
= GdipInvertMatrix(&inverted_transform
);
5908 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
5911 case CoordinateSpacePage
:
5913 case CoordinateSpaceDevice
:
5914 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
5921 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5922 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5927 if(!graphics
|| !points
|| count
<= 0)
5928 return InvalidParameter
;
5933 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5935 if (src_space
== dst_space
) return Ok
;
5937 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5938 if (stat
!= Ok
) return stat
;
5940 return GdipTransformMatrixPoints(&matrix
, points
, count
);
5943 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5944 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5950 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5953 return InvalidParameter
;
5955 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5959 for(i
= 0; i
< count
; i
++){
5960 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5961 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5964 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5967 for(i
= 0; i
< count
; i
++){
5968 points
[i
].X
= gdip_round(pointsF
[i
].X
);
5969 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
5976 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5988 /*****************************************************************************
5989 * GdipTranslateClip [GDIPLUS.@]
5991 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5993 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5996 return InvalidParameter
;
6001 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6004 /*****************************************************************************
6005 * GdipTranslateClipI [GDIPLUS.@]
6007 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6009 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6012 return InvalidParameter
;
6017 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6021 /*****************************************************************************
6022 * GdipMeasureDriverString [GDIPLUS.@]
6024 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6025 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6026 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6028 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6031 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6033 TEXTMETRICW textmetric
;
6034 const WORD
*glyph_indices
;
6035 WORD
*dynamic_glyph_indices
=NULL
;
6036 REAL rel_width
, rel_height
, ascent
, descent
;
6039 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6041 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6042 return InvalidParameter
;
6045 length
= strlenW(text
);
6049 boundingBox
->X
= 0.0;
6050 boundingBox
->Y
= 0.0;
6051 boundingBox
->Width
= 0.0;
6052 boundingBox
->Height
= 0.0;
6055 if (flags
& unsupported_flags
)
6056 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6058 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6060 hdc
= CreateCompatibleDC(0);
6061 SelectObject(hdc
, hfont
);
6063 GetTextMetricsW(hdc
, &textmetric
);
6073 GpMatrix xform
= *matrix
;
6074 GdipTransformMatrixPoints(&xform
, pt
, 3);
6076 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6077 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6078 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6079 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6080 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6082 if (flags
& DriverStringOptionsCmapLookup
)
6084 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6088 DeleteObject(hfont
);
6092 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6095 glyph_indices
= text
;
6097 min_x
= max_x
= x
= positions
[0].X
;
6098 min_y
= max_y
= y
= positions
[0].Y
;
6100 ascent
= textmetric
.tmAscent
/ rel_height
;
6101 descent
= textmetric
.tmDescent
/ rel_height
;
6103 for (i
=0; i
<length
; i
++)
6108 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6114 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6115 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6117 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6118 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6119 if (min_x
> x
) min_x
= x
;
6121 x
+= char_width
/ rel_width
;
6123 if (max_x
< x
) max_x
= x
;
6126 GdipFree(dynamic_glyph_indices
);
6128 DeleteObject(hfont
);
6130 boundingBox
->X
= min_x
;
6131 boundingBox
->Y
= min_y
;
6132 boundingBox
->Width
= max_x
- min_x
;
6133 boundingBox
->Height
= max_y
- min_y
;
6138 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6139 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6140 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6141 INT flags
, GDIPCONST GpMatrix
*matrix
)
6143 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6149 if (flags
& unsupported_flags
)
6150 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6152 if (!(flags
& DriverStringOptionsCmapLookup
))
6153 eto_flags
|= ETO_GLYPH_INDEX
;
6155 save_state
= SaveDC(graphics
->hdc
);
6156 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6157 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6160 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6162 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6163 SelectObject(graphics
->hdc
, hfont
);
6165 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6167 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6169 RestoreDC(graphics
->hdc
, save_state
);
6171 DeleteObject(hfont
);
6176 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6177 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6178 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6179 INT flags
, GDIPCONST GpMatrix
*matrix
)
6181 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6183 PointF
*real_positions
, real_position
;
6187 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6188 DWORD max_glyphsize
=0;
6189 GLYPHMETRICS glyphmetrics
;
6190 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6193 int text_mask_stride
;
6195 int pixel_data_stride
;
6197 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6202 if (!(flags
& DriverStringOptionsCmapLookup
))
6203 ggo_flags
|= GGO_GLYPH_INDEX
;
6205 if (flags
& unsupported_flags
)
6206 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6208 pti
= GdipAlloc(sizeof(POINT
) * length
);
6212 if (flags
& DriverStringOptionsRealizedAdvance
)
6214 real_position
= positions
[0];
6216 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6220 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6221 if (!real_positions
)
6227 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6229 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6231 GdipFree(real_positions
);
6234 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6236 hdc
= CreateCompatibleDC(0);
6237 SelectObject(hdc
, hfont
);
6239 /* Get the boundaries of the text to be drawn */
6240 for (i
=0; i
<length
; i
++)
6243 int left
, top
, right
, bottom
;
6245 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6246 &glyphmetrics
, 0, NULL
, &identity
);
6248 if (glyphsize
== GDI_ERROR
)
6250 ERR("GetGlyphOutlineW failed\n");
6253 DeleteObject(hfont
);
6254 return GenericError
;
6257 if (glyphsize
> max_glyphsize
)
6258 max_glyphsize
= glyphsize
;
6262 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6263 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6264 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6265 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6267 if (left
< min_x
) min_x
= left
;
6268 if (top
< min_y
) min_y
= top
;
6269 if (right
> max_x
) max_x
= right
;
6270 if (bottom
> max_y
) max_y
= bottom
;
6273 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6275 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6276 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6280 if (max_glyphsize
== 0)
6281 /* Nothing to draw. */
6284 glyph_mask
= GdipAlloc(max_glyphsize
);
6285 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6286 text_mask_stride
= max_x
- min_x
;
6288 if (!(glyph_mask
&& text_mask
))
6290 GdipFree(glyph_mask
);
6291 GdipFree(text_mask
);
6294 DeleteObject(hfont
);
6298 /* Generate a mask for the text */
6299 for (i
=0; i
<length
; i
++)
6302 int left
, top
, stride
;
6304 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6305 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6307 if (ret
== GDI_ERROR
|| ret
== 0)
6308 continue; /* empty glyph */
6310 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6311 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6312 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6314 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6316 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6317 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6318 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6320 *text_val
= min(64, *text_val
+ *glyph_val
);
6329 DeleteObject(hfont
);
6330 GdipFree(glyph_mask
);
6332 /* get the brush data */
6333 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6336 GdipFree(text_mask
);
6340 pixel_area
.X
= min_x
;
6341 pixel_area
.Y
= min_y
;
6342 pixel_area
.Width
= max_x
- min_x
;
6343 pixel_area
.Height
= max_y
- min_y
;
6344 pixel_data_stride
= pixel_area
.Width
* 4;
6346 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6349 GdipFree(text_mask
);
6350 GdipFree(pixel_data
);
6354 /* multiply the brush data by the mask */
6355 for (y
=0; y
<pixel_area
.Height
; y
++)
6357 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6358 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6359 for (x
=0; x
<pixel_area
.Width
; x
++)
6361 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6367 GdipFree(text_mask
);
6369 /* draw the result */
6370 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6371 pixel_area
.Height
, pixel_data_stride
);
6373 GdipFree(pixel_data
);
6378 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6379 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6380 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6381 INT flags
, GDIPCONST GpMatrix
*matrix
)
6383 GpStatus stat
= NotImplemented
;
6386 length
= strlenW(text
);
6388 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6389 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6390 brush
->bt
== BrushTypeSolidColor
&&
6391 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6392 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6393 brush
, positions
, flags
, matrix
);
6394 if (stat
== NotImplemented
)
6395 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6396 brush
, positions
, flags
, matrix
);
6400 /*****************************************************************************
6401 * GdipDrawDriverString [GDIPLUS.@]
6403 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6404 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6405 GDIPCONST PointF
*positions
, INT flags
,
6406 GDIPCONST GpMatrix
*matrix
)
6408 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6410 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6411 return InvalidParameter
;
6413 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6414 brush
, positions
, flags
, matrix
);
6417 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6418 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6420 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6421 return NotImplemented
;
6424 /*****************************************************************************
6425 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6427 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6432 TRACE("(%p, %p)\n", graphics
, res
);
6434 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6437 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6440 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6443 GdipDeleteRegion(rgn
);
6447 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6451 TRACE("(%p) stub\n", graphics
);
6454 FIXME("not implemented\n");
6456 return NotImplemented
;