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 static void transform_rectf(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
58 GpCoordinateSpace src_space
, GpRectF
*rect
)
64 pt
[1].X
= rect
->X
+ rect
->Width
;
67 pt
[2].Y
= rect
->Y
+ rect
->Height
;
68 GdipTransformPoints(graphics
, dst_space
, src_space
, pt
, 3);
71 rect
->Width
= sqrt((pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
) +
72 (pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
));
73 rect
->Height
= sqrt((pt
[2].Y
- pt
[0].Y
) * (pt
[2].Y
- pt
[0].Y
) +
74 (pt
[2].X
- pt
[0].X
) * (pt
[2].X
- pt
[0].X
));
77 /* Converts from gdiplus path point type to gdi path point type. */
78 static BYTE
convert_path_point_type(BYTE type
)
82 switch(type
& PathPointTypePathTypeMask
){
83 case PathPointTypeBezier
:
86 case PathPointTypeLine
:
89 case PathPointTypeStart
:
93 ERR("Bad point type\n");
97 if(type
& PathPointTypeCloseSubpath
)
98 ret
|= PT_CLOSEFIGURE
;
103 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
109 case BrushTypeSolidColor
:
111 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
115 case BrushTypeHatchFill
:
117 const GpHatch
*hatch
= (const GpHatch
*)brush
;
118 argb
= hatch
->forecol
;
121 case BrushTypeLinearGradient
:
123 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
124 argb
= line
->startcolor
;
127 case BrushTypePathGradient
:
129 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
130 argb
= grad
->centercolor
;
134 FIXME("unhandled brush type %d\n", brush
->bt
);
138 return ARGB2COLORREF(argb
);
141 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
144 BITMAPINFOHEADER bmih
;
148 bmih
.biSize
= sizeof(bmih
);
152 bmih
.biBitCount
= 32;
153 bmih
.biCompression
= BI_RGB
;
154 bmih
.biSizeImage
= 0;
156 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
159 const char *hatch_data
;
161 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
163 for (y
= 0; y
< 8; y
++)
165 for (x
= 0; x
< 8; x
++)
167 if (hatch_data
[y
] & (0x80 >> x
))
168 bits
[y
* 8 + x
] = hatch
->forecol
;
170 bits
[y
* 8 + x
] = hatch
->backcol
;
176 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
178 for (y
= 0; y
< 64; y
++)
179 bits
[y
] = hatch
->forecol
;
186 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
190 case BrushTypeSolidColor
:
192 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
193 lb
->lbStyle
= BS_SOLID
;
194 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
199 case BrushTypeHatchFill
:
201 const GpHatch
*hatch
= (const GpHatch
*)brush
;
204 hbmp
= create_hatch_bitmap(hatch
);
205 if (!hbmp
) return OutOfMemory
;
207 lb
->lbStyle
= BS_PATTERN
;
209 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
214 FIXME("unhandled brush type %d\n", brush
->bt
);
215 lb
->lbStyle
= BS_SOLID
;
216 lb
->lbColor
= get_gdi_brush_color(brush
);
222 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
227 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
233 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
238 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
240 gdibrush
= CreateBrushIndirect(&lb
);
241 free_gdi_logbrush(&lb
);
246 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
251 INT save_state
, i
, numdashes
;
253 DWORD dash_array
[MAX_DASHLEN
];
255 save_state
= SaveDC(graphics
->hdc
);
257 EndPath(graphics
->hdc
);
259 if(pen
->unit
== UnitPixel
){
263 /* Get an estimate for the amount the pen width is affected by the world
264 * transform. (This is similar to what some of the wine drivers do.) */
269 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
270 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
271 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
273 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
276 if(pen
->dash
== DashStyleCustom
){
277 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
279 TRACE("dashes are: ");
280 for(i
= 0; i
< numdashes
; i
++){
281 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
282 TRACE("%d, ", dash_array
[i
]);
284 TRACE("\n and the pen style is %x\n", pen
->style
);
286 create_gdi_logbrush(pen
->brush
, &lb
);
287 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
288 numdashes
, dash_array
);
289 free_gdi_logbrush(&lb
);
293 create_gdi_logbrush(pen
->brush
, &lb
);
294 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
295 free_gdi_logbrush(&lb
);
298 SelectObject(graphics
->hdc
, gdipen
);
303 static void restore_dc(GpGraphics
*graphics
, INT state
)
305 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
306 RestoreDC(graphics
->hdc
, state
);
309 /* This helper applies all the changes that the points listed in ptf need in
310 * order to be drawn on the device context. In the end, this should include at
312 * -scaling by page unit
313 * -applying world transformation
314 * -converting from float to int
315 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
316 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
317 * gdi to draw, and these functions would irreparably mess with line widths.
319 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
320 GpPointF
*ptf
, INT count
)
322 REAL scale_x
, scale_y
;
326 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
327 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
329 /* apply page scale */
330 if(graphics
->unit
!= UnitDisplay
)
332 scale_x
*= graphics
->scale
;
333 scale_y
*= graphics
->scale
;
336 matrix
= graphics
->worldtrans
;
337 GdipScaleMatrix(&matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
338 GdipTransformMatrixPoints(&matrix
, ptf
, count
);
340 for(i
= 0; i
< count
; i
++){
341 pti
[i
].x
= gdip_round(ptf
[i
].X
);
342 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
346 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
347 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
349 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
351 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
353 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
354 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
360 bf
.BlendOp
= AC_SRC_OVER
;
362 bf
.SourceConstantAlpha
= 255;
363 bf
.AlphaFormat
= AC_SRC_ALPHA
;
365 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
366 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
370 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
372 /* clipping region is in device coords */
373 return GdipGetRegionHRgn(graphics
->clip
, NULL
, hrgn
);
376 /* Draw non-premultiplied ARGB data to the given graphics object */
377 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
378 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
380 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
383 for (x
=0; x
<src_width
; x
++)
385 for (y
=0; y
<src_height
; y
++)
387 ARGB dst_color
, src_color
;
388 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
389 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
390 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
397 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
398 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
402 BITMAPINFOHEADER bih
;
405 hdc
= CreateCompatibleDC(0);
407 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
408 bih
.biWidth
= src_width
;
409 bih
.biHeight
= -src_height
;
412 bih
.biCompression
= BI_RGB
;
414 bih
.biXPelsPerMeter
= 0;
415 bih
.biYPelsPerMeter
= 0;
417 bih
.biClrImportant
= 0;
419 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
420 (void**)&temp_bits
, NULL
, 0);
422 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
423 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
425 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
426 4 * src_width
, src
, src_stride
);
428 SelectObject(hdc
, hbitmap
);
429 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
430 hdc
, 0, 0, src_width
, src_height
);
432 DeleteObject(hbitmap
);
437 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
438 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
)
442 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
448 HRGN hrgn
, visible_rgn
;
450 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
454 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
463 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
464 DeleteObject(visible_rgn
);
468 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
470 size
= GetRegionData(hrgn
, 0, NULL
);
472 rgndata
= GdipAlloc(size
);
479 GetRegionData(hrgn
, size
, rgndata
);
481 rects
= (RECT
*)rgndata
->Buffer
;
483 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
485 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
486 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
487 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
497 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
499 ERR("This should not be used for metafiles; fix caller\n");
500 return NotImplemented
;
507 stat
= get_clip_hrgn(graphics
, &hrgn
);
512 save
= SaveDC(graphics
->hdc
);
515 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
518 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
520 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
521 src_height
, src_stride
);
523 RestoreDC(graphics
->hdc
, save
);
531 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
532 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
534 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
);
537 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
543 a1
= (start
>> 24) & 0xff;
544 a2
= (end
>> 24) & 0xff;
546 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
550 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
551 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
555 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
559 /* clamp to between 0.0 and 1.0, using the wrap mode */
560 if (brush
->wrap
== WrapModeTile
)
562 position
= fmodf(position
, 1.0f
);
563 if (position
< 0.0f
) position
+= 1.0f
;
565 else /* WrapModeFlip* */
567 position
= fmodf(position
, 2.0f
);
568 if (position
< 0.0f
) position
+= 2.0f
;
569 if (position
> 1.0f
) position
= 2.0f
- position
;
572 if (brush
->blendcount
== 1)
577 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
580 /* locate the blend positions surrounding this position */
581 while (position
> brush
->blendpos
[i
])
584 /* interpolate between the blend positions */
585 left_blendpos
= brush
->blendpos
[i
-1];
586 left_blendfac
= brush
->blendfac
[i
-1];
587 right_blendpos
= brush
->blendpos
[i
];
588 right_blendfac
= brush
->blendfac
[i
];
589 range
= right_blendpos
- left_blendpos
;
590 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
591 right_blendfac
* (position
- left_blendpos
)) / range
;
594 if (brush
->pblendcount
== 0)
595 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
599 ARGB left_blendcolor
, right_blendcolor
;
600 REAL left_blendpos
, right_blendpos
;
602 /* locate the blend colors surrounding this position */
603 while (blendfac
> brush
->pblendpos
[i
])
606 /* interpolate between the blend colors */
607 left_blendpos
= brush
->pblendpos
[i
-1];
608 left_blendcolor
= brush
->pblendcolor
[i
-1];
609 right_blendpos
= brush
->pblendpos
[i
];
610 right_blendcolor
= brush
->pblendcolor
[i
];
611 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
612 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
616 static ARGB
transform_color(ARGB color
, const ColorMatrix
*matrix
)
620 unsigned char a
, r
, g
, b
;
622 val
[0] = ((color
>> 16) & 0xff) / 255.0; /* red */
623 val
[1] = ((color
>> 8) & 0xff) / 255.0; /* green */
624 val
[2] = (color
& 0xff) / 255.0; /* blue */
625 val
[3] = ((color
>> 24) & 0xff) / 255.0; /* alpha */
626 val
[4] = 1.0; /* translation */
633 res
[i
] += matrix
->m
[j
][i
] * val
[j
];
636 a
= min(max(floorf(res
[3]*255.0), 0.0), 255.0);
637 r
= min(max(floorf(res
[0]*255.0), 0.0), 255.0);
638 g
= min(max(floorf(res
[1]*255.0), 0.0), 255.0);
639 b
= min(max(floorf(res
[2]*255.0), 0.0), 255.0);
641 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
644 static int color_is_gray(ARGB color
)
646 unsigned char r
, g
, b
;
648 r
= (color
>> 16) & 0xff;
649 g
= (color
>> 8) & 0xff;
652 return (r
== g
) && (g
== b
);
655 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
656 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
661 if (attributes
->colorkeys
[type
].enabled
||
662 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
664 const struct color_key
*key
;
665 BYTE min_blue
, min_green
, min_red
;
666 BYTE max_blue
, max_green
, max_red
;
668 if (attributes
->colorkeys
[type
].enabled
)
669 key
= &attributes
->colorkeys
[type
];
671 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
673 min_blue
= key
->low
&0xff;
674 min_green
= (key
->low
>>8)&0xff;
675 min_red
= (key
->low
>>16)&0xff;
677 max_blue
= key
->high
&0xff;
678 max_green
= (key
->high
>>8)&0xff;
679 max_red
= (key
->high
>>16)&0xff;
681 for (x
=0; x
<width
; x
++)
682 for (y
=0; y
<height
; y
++)
685 BYTE blue
, green
, red
;
686 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
687 blue
= *src_color
&0xff;
688 green
= (*src_color
>>8)&0xff;
689 red
= (*src_color
>>16)&0xff;
690 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
691 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
692 *src_color
= 0x00000000;
696 if (attributes
->colorremaptables
[type
].enabled
||
697 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
699 const struct color_remap_table
*table
;
701 if (attributes
->colorremaptables
[type
].enabled
)
702 table
= &attributes
->colorremaptables
[type
];
704 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
706 for (x
=0; x
<width
; x
++)
707 for (y
=0; y
<height
; y
++)
710 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
711 for (i
=0; i
<table
->mapsize
; i
++)
713 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
715 *src_color
= table
->colormap
[i
].newColor
.Argb
;
722 if (attributes
->colormatrices
[type
].enabled
||
723 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
725 const struct color_matrix
*colormatrices
;
727 if (attributes
->colormatrices
[type
].enabled
)
728 colormatrices
= &attributes
->colormatrices
[type
];
730 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
732 for (x
=0; x
<width
; x
++)
733 for (y
=0; y
<height
; y
++)
736 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
738 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
739 !color_is_gray(*src_color
))
741 *src_color
= transform_color(*src_color
, &colormatrices
->colormatrix
);
743 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
745 *src_color
= transform_color(*src_color
, &colormatrices
->graymatrix
);
750 if (attributes
->gamma_enabled
[type
] ||
751 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
755 if (attributes
->gamma_enabled
[type
])
756 gamma
= attributes
->gamma
[type
];
758 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
760 for (x
=0; x
<width
; x
++)
761 for (y
=0; y
<height
; y
++)
764 BYTE blue
, green
, red
;
765 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
767 blue
= *src_color
&0xff;
768 green
= (*src_color
>>8)&0xff;
769 red
= (*src_color
>>16)&0xff;
771 /* FIXME: We should probably use a table for this. */
772 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
773 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
774 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
776 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
781 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
782 * bitmap that contains all the pixels we may need to draw it. */
783 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
784 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
787 INT left
, top
, right
, bottom
;
789 switch (interpolation
)
791 case InterpolationModeHighQualityBilinear
:
792 case InterpolationModeHighQualityBicubic
:
793 /* FIXME: Include a greater range for the prefilter? */
794 case InterpolationModeBicubic
:
795 case InterpolationModeBilinear
:
796 left
= (INT
)(floorf(srcx
));
797 top
= (INT
)(floorf(srcy
));
798 right
= (INT
)(ceilf(srcx
+srcwidth
));
799 bottom
= (INT
)(ceilf(srcy
+srcheight
));
801 case InterpolationModeNearestNeighbor
:
803 left
= gdip_round(srcx
);
804 top
= gdip_round(srcy
);
805 right
= gdip_round(srcx
+srcwidth
);
806 bottom
= gdip_round(srcy
+srcheight
);
810 if (wrap
== WrapModeClamp
)
816 if (right
>= bitmap
->width
)
817 right
= bitmap
->width
-1;
818 if (bottom
>= bitmap
->height
)
819 bottom
= bitmap
->height
-1;
823 /* In some cases we can make the rectangle smaller here, but the logic
824 * is hard to get right, and tiling suggests we're likely to use the
825 * entire source image. */
826 if (left
< 0 || right
>= bitmap
->width
)
829 right
= bitmap
->width
-1;
832 if (top
< 0 || bottom
>= bitmap
->height
)
835 bottom
= bitmap
->height
-1;
841 rect
->Width
= right
- left
+ 1;
842 rect
->Height
= bottom
- top
+ 1;
845 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
846 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
848 if (attributes
->wrap
== WrapModeClamp
)
850 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
851 return attributes
->outside_color
;
855 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
857 x
= width
*2 + x
% (width
* 2);
859 y
= height
*2 + y
% (height
* 2);
861 if ((attributes
->wrap
& 1) == 1)
864 if ((x
/ width
) % 2 == 0)
867 x
= width
- 1 - x
% width
;
872 if ((attributes
->wrap
& 2) == 2)
875 if ((y
/ height
) % 2 == 0)
878 y
= height
- 1 - y
% height
;
884 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
886 ERR("out of range pixel requested\n");
890 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
893 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
894 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
895 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
899 switch (interpolation
)
903 FIXME("Unimplemented interpolation %i\n", interpolation
);
905 case InterpolationModeBilinear
:
908 INT leftx
, rightx
, topy
, bottomy
;
909 ARGB topleft
, topright
, bottomleft
, bottomright
;
913 leftxf
= floorf(point
->X
);
915 rightx
= (INT
)ceilf(point
->X
);
916 topyf
= floorf(point
->Y
);
918 bottomy
= (INT
)ceilf(point
->Y
);
920 if (leftx
== rightx
&& topy
== bottomy
)
921 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
922 leftx
, topy
, attributes
);
924 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
925 leftx
, topy
, attributes
);
926 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
927 rightx
, topy
, attributes
);
928 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
929 leftx
, bottomy
, attributes
);
930 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
931 rightx
, bottomy
, attributes
);
933 x_offset
= point
->X
- leftxf
;
934 top
= blend_colors(topleft
, topright
, x_offset
);
935 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
937 return blend_colors(top
, bottom
, point
->Y
- topyf
);
939 case InterpolationModeNearestNeighbor
:
945 case PixelOffsetModeNone
:
946 case PixelOffsetModeHighSpeed
:
950 case PixelOffsetModeHalf
:
951 case PixelOffsetModeHighQuality
:
955 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
956 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
962 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
964 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
967 static INT
brush_can_fill_path(GpBrush
*brush
)
971 case BrushTypeSolidColor
:
973 case BrushTypeHatchFill
:
975 GpHatch
*hatch
= (GpHatch
*)brush
;
976 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
977 ((hatch
->backcol
& 0xff000000) == 0xff000000);
979 case BrushTypeLinearGradient
:
980 case BrushTypeTextureFill
:
981 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
987 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
991 case BrushTypeSolidColor
:
993 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
994 HBITMAP bmp
= ARGB2BMP(fill
->color
);
999 /* partially transparent fill */
1001 SelectClipPath(graphics
->hdc
, RGN_AND
);
1002 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1004 HDC hdc
= CreateCompatibleDC(NULL
);
1008 SelectObject(hdc
, bmp
);
1009 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1017 /* else fall through */
1021 HBRUSH gdibrush
, old_brush
;
1023 gdibrush
= create_gdi_brush(brush
);
1024 if (!gdibrush
) return;
1026 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1027 FillPath(graphics
->hdc
);
1028 SelectObject(graphics
->hdc
, old_brush
);
1029 DeleteObject(gdibrush
);
1035 static INT
brush_can_fill_pixels(GpBrush
*brush
)
1039 case BrushTypeSolidColor
:
1040 case BrushTypeHatchFill
:
1041 case BrushTypeLinearGradient
:
1042 case BrushTypeTextureFill
:
1043 case BrushTypePathGradient
:
1050 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1051 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1055 case BrushTypeSolidColor
:
1058 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1059 for (x
=0; x
<fill_area
->Width
; x
++)
1060 for (y
=0; y
<fill_area
->Height
; y
++)
1061 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1064 case BrushTypeHatchFill
:
1067 GpHatch
*fill
= (GpHatch
*)brush
;
1068 const char *hatch_data
;
1070 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1071 return NotImplemented
;
1073 for (x
=0; x
<fill_area
->Width
; x
++)
1074 for (y
=0; y
<fill_area
->Height
; y
++)
1078 /* FIXME: Account for the rendering origin */
1079 hx
= (x
+ fill_area
->X
) % 8;
1080 hy
= (y
+ fill_area
->Y
) % 8;
1082 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1083 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1085 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1090 case BrushTypeLinearGradient
:
1092 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1093 GpPointF draw_points
[3], line_points
[3];
1095 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1096 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1099 draw_points
[0].X
= fill_area
->X
;
1100 draw_points
[0].Y
= fill_area
->Y
;
1101 draw_points
[1].X
= fill_area
->X
+1;
1102 draw_points
[1].Y
= fill_area
->Y
;
1103 draw_points
[2].X
= fill_area
->X
;
1104 draw_points
[2].Y
= fill_area
->Y
+1;
1106 /* Transform the points to a co-ordinate space where X is the point's
1107 * position in the gradient, 0.0 being the start point and 1.0 the
1109 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1110 CoordinateSpaceDevice
, draw_points
, 3);
1114 line_points
[0] = fill
->startpoint
;
1115 line_points
[1] = fill
->endpoint
;
1116 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1117 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1119 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1124 stat
= GdipInvertMatrix(world_to_gradient
);
1127 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1129 GdipDeleteMatrix(world_to_gradient
);
1134 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1135 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1137 for (y
=0; y
<fill_area
->Height
; y
++)
1139 for (x
=0; x
<fill_area
->Width
; x
++)
1141 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1143 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1150 case BrushTypeTextureFill
:
1152 GpTexture
*fill
= (GpTexture
*)brush
;
1153 GpPointF draw_points
[3];
1160 if (fill
->image
->type
!= ImageTypeBitmap
)
1162 FIXME("metafile texture brushes not implemented\n");
1163 return NotImplemented
;
1166 bitmap
= (GpBitmap
*)fill
->image
;
1167 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1169 src_area
.X
= src_area
.Y
= 0;
1170 src_area
.Width
= bitmap
->width
;
1171 src_area
.Height
= bitmap
->height
;
1173 draw_points
[0].X
= fill_area
->X
;
1174 draw_points
[0].Y
= fill_area
->Y
;
1175 draw_points
[1].X
= fill_area
->X
+1;
1176 draw_points
[1].Y
= fill_area
->Y
;
1177 draw_points
[2].X
= fill_area
->X
;
1178 draw_points
[2].Y
= fill_area
->Y
+1;
1180 /* Transform the points to the co-ordinate space of the bitmap. */
1181 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1182 CoordinateSpaceDevice
, draw_points
, 3);
1186 GpMatrix world_to_texture
= fill
->transform
;
1188 stat
= GdipInvertMatrix(&world_to_texture
);
1190 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1193 if (stat
== Ok
&& !fill
->bitmap_bits
)
1195 BitmapData lockeddata
;
1197 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1198 if (!fill
->bitmap_bits
)
1203 lockeddata
.Width
= bitmap
->width
;
1204 lockeddata
.Height
= bitmap
->height
;
1205 lockeddata
.Stride
= src_stride
;
1206 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1207 lockeddata
.Scan0
= fill
->bitmap_bits
;
1209 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1210 PixelFormat32bppARGB
, &lockeddata
);
1214 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1217 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1218 bitmap
->width
, bitmap
->height
,
1219 src_stride
, ColorAdjustTypeBitmap
);
1223 GdipFree(fill
->bitmap_bits
);
1224 fill
->bitmap_bits
= NULL
;
1230 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1231 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1232 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1233 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1235 for (y
=0; y
<fill_area
->Height
; y
++)
1237 for (x
=0; x
<fill_area
->Width
; x
++)
1240 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1241 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1243 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1244 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1245 &point
, fill
->imageattributes
, graphics
->interpolation
,
1246 graphics
->pixeloffset
);
1253 case BrushTypePathGradient
:
1255 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1257 GpMatrix world_to_device
;
1259 int i
, figure_start
=0;
1260 GpPointF start_point
, end_point
, center_point
;
1262 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1263 INT min_y
, max_y
, min_x
, max_x
;
1266 static int transform_fixme_once
;
1268 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1272 FIXME("path gradient focus not implemented\n");
1279 FIXME("path gradient gamma correction not implemented\n");
1282 if (fill
->blendcount
)
1286 FIXME("path gradient blend not implemented\n");
1289 if (fill
->pblendcount
)
1293 FIXME("path gradient preset blend not implemented\n");
1296 if (!transform_fixme_once
)
1298 BOOL is_identity
=TRUE
;
1299 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1302 FIXME("path gradient transform not implemented\n");
1303 transform_fixme_once
= 1;
1307 stat
= GdipClonePath(fill
->path
, &flat_path
);
1312 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1313 CoordinateSpaceWorld
, &world_to_device
);
1316 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1320 center_point
= fill
->center
;
1321 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1325 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1330 GdipDeletePath(flat_path
);
1334 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1336 int start_center_line
=0, end_center_line
=0;
1337 int seen_start
=0, seen_end
=0, seen_center
=0;
1338 REAL center_distance
;
1339 ARGB start_color
, end_color
;
1342 type
= flat_path
->pathdata
.Types
[i
];
1344 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1347 start_point
= flat_path
->pathdata
.Points
[i
];
1349 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1351 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1353 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1354 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1356 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1358 end_point
= flat_path
->pathdata
.Points
[i
+1];
1359 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1364 outer_color
= start_color
;
1366 min_yf
= center_point
.Y
;
1367 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1368 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1370 if (min_yf
< fill_area
->Y
)
1371 min_y
= fill_area
->Y
;
1373 min_y
= (INT
)ceil(min_yf
);
1375 max_yf
= center_point
.Y
;
1376 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1377 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1379 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1380 max_y
= fill_area
->Y
+ fill_area
->Height
;
1382 max_y
= (INT
)ceil(max_yf
);
1384 dy
= end_point
.Y
- start_point
.Y
;
1385 dx
= end_point
.X
- start_point
.X
;
1387 /* This is proportional to the distance from start-end line to center point. */
1388 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1389 dx
* (center_point
.Y
- start_point
.Y
);
1391 for (y
=min_y
; y
<max_y
; y
++)
1395 if (!seen_start
&& yf
>= start_point
.Y
)
1398 start_center_line
^= 1;
1400 if (!seen_end
&& yf
>= end_point
.Y
)
1403 end_center_line
^= 1;
1405 if (!seen_center
&& yf
>= center_point
.Y
)
1408 start_center_line
^= 1;
1409 end_center_line
^= 1;
1412 if (start_center_line
)
1413 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1415 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1417 if (end_center_line
)
1418 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1420 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1422 if (line1_xf
< line2_xf
)
1424 min_x
= (INT
)ceil(line1_xf
);
1425 max_x
= (INT
)ceil(line2_xf
);
1429 min_x
= (INT
)ceil(line2_xf
);
1430 max_x
= (INT
)ceil(line1_xf
);
1433 if (min_x
< fill_area
->X
)
1434 min_x
= fill_area
->X
;
1435 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1436 max_x
= fill_area
->X
+ fill_area
->Width
;
1438 for (x
=min_x
; x
<max_x
; x
++)
1443 if (start_color
!= end_color
)
1445 REAL blend_amount
, pdy
, pdx
;
1446 pdy
= yf
- center_point
.Y
;
1447 pdx
= xf
- center_point
.X
;
1448 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1449 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1452 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1453 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1455 distance
= distance
/ center_distance
;
1457 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1458 blend_colors(outer_color
, fill
->centercolor
, distance
);
1463 GdipDeletePath(flat_path
);
1467 return NotImplemented
;
1471 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1472 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1473 * should not be called on an hdc that has a path you care about. */
1474 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1475 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1477 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1479 HBRUSH brush
= NULL
;
1481 PointF ptf
[4], *custptf
= NULL
;
1482 POINT pt
[4], *custpt
= NULL
;
1484 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1489 if((x1
== x2
) && (y1
== y2
))
1492 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1494 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1496 brush
= CreateSolidBrush(color
);
1497 lb
.lbStyle
= BS_SOLID
;
1500 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1501 PS_JOIN_MITER
, 1, &lb
, 0,
1503 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1504 oldpen
= SelectObject(graphics
->hdc
, pen
);
1511 case LineCapSquareAnchor
:
1512 case LineCapDiamondAnchor
:
1513 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1514 if(cap
== LineCapDiamondAnchor
){
1515 dsmall
= cos(theta
+ M_PI_2
) * size
;
1516 dbig
= sin(theta
+ M_PI_2
) * size
;
1519 dsmall
= cos(theta
+ M_PI_4
) * size
;
1520 dbig
= sin(theta
+ M_PI_4
) * size
;
1523 ptf
[0].X
= x2
- dsmall
;
1524 ptf
[1].X
= x2
+ dbig
;
1526 ptf
[0].Y
= y2
- dbig
;
1527 ptf
[3].Y
= y2
+ dsmall
;
1529 ptf
[1].Y
= y2
- dsmall
;
1530 ptf
[2].Y
= y2
+ dbig
;
1532 ptf
[3].X
= x2
- dbig
;
1533 ptf
[2].X
= x2
+ dsmall
;
1535 transform_and_round_points(graphics
, pt
, ptf
, 4);
1536 Polygon(graphics
->hdc
, pt
, 4);
1539 case LineCapArrowAnchor
:
1540 size
= size
* 4.0 / sqrt(3.0);
1542 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1543 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1548 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1549 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1557 transform_and_round_points(graphics
, pt
, ptf
, 3);
1558 Polygon(graphics
->hdc
, pt
, 3);
1561 case LineCapRoundAnchor
:
1562 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1569 transform_and_round_points(graphics
, pt
, ptf
, 2);
1570 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1573 case LineCapTriangle
:
1575 dx
= cos(M_PI_2
+ theta
) * size
;
1576 dy
= sin(M_PI_2
+ theta
) * size
;
1583 dx
= cos(theta
) * size
;
1584 dy
= sin(theta
) * size
;
1589 transform_and_round_points(graphics
, pt
, ptf
, 3);
1590 Polygon(graphics
->hdc
, pt
, 3);
1594 dx
= dy
= size
/ 2.0;
1601 dx
= -cos(M_PI_2
+ theta
) * size
;
1602 dy
= -sin(M_PI_2
+ theta
) * size
;
1609 transform_and_round_points(graphics
, pt
, ptf
, 4);
1610 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1611 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1618 count
= custom
->pathdata
.Count
;
1619 custptf
= GdipAlloc(count
* sizeof(PointF
));
1620 custpt
= GdipAlloc(count
* sizeof(POINT
));
1621 tp
= GdipAlloc(count
);
1623 if(!custptf
|| !custpt
|| !tp
)
1626 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1628 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1629 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1630 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1632 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1633 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1635 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1637 for(i
= 0; i
< count
; i
++)
1638 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1641 BeginPath(graphics
->hdc
);
1642 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1643 EndPath(graphics
->hdc
);
1644 StrokeAndFillPath(graphics
->hdc
);
1647 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1659 SelectObject(graphics
->hdc
, oldbrush
);
1660 SelectObject(graphics
->hdc
, oldpen
);
1661 DeleteObject(brush
);
1666 /* Shortens the line by the given percent by changing x2, y2.
1667 * If percent is > 1.0 then the line will change direction.
1668 * If percent is negative it can lengthen the line. */
1669 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1671 REAL dist
, theta
, dx
, dy
;
1673 if((y1
== *y2
) && (x1
== *x2
))
1676 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1677 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1678 dx
= cos(theta
) * dist
;
1679 dy
= sin(theta
) * dist
;
1685 /* Shortens the line by the given amount by changing x2, y2.
1686 * If the amount is greater than the distance, the line will become length 0.
1687 * If the amount is negative, it can lengthen the line. */
1688 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1690 REAL dx
, dy
, percent
;
1694 if(dx
== 0 && dy
== 0)
1697 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1704 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1707 /* Conducts a linear search to find the bezier points that will back off
1708 * the endpoint of the curve by a distance of amt. Linear search works
1709 * better than binary in this case because there are multiple solutions,
1710 * and binary searches often find a bad one. I don't think this is what
1711 * Windows does but short of rendering the bezier without GDI's help it's
1712 * the best we can do. If rev then work from the start of the passed points
1713 * instead of the end. */
1714 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1717 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1718 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1727 origx
= pt
[fourth
].X
;
1728 origy
= pt
[fourth
].Y
;
1729 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1731 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1732 /* reset bezier points to original values */
1733 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1734 /* Perform magic on bezier points. Order is important here.*/
1735 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1736 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1737 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1738 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1739 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1740 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1742 dx
= pt
[fourth
].X
- origx
;
1743 dy
= pt
[fourth
].Y
- origy
;
1745 diff
= sqrt(dx
* dx
+ dy
* dy
);
1746 percent
+= 0.0005 * amt
;
1750 /* Draws a combination of bezier curves and lines between points. */
1751 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1752 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1754 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1755 BYTE
*tp
= GdipAlloc(count
);
1756 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1758 GpStatus status
= GenericError
;
1764 if(!pti
|| !tp
|| !ptcopy
){
1765 status
= OutOfMemory
;
1769 for(i
= 1; i
< count
; i
++){
1770 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1771 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1772 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1773 ERR("Bad bezier points\n");
1780 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1782 /* If we are drawing caps, go through the points and adjust them accordingly,
1783 * and draw the caps. */
1785 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1786 case PathPointTypeBezier
:
1787 if(pen
->endcap
== LineCapArrowAnchor
)
1788 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1789 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1790 shorten_bezier_amt(&ptcopy
[count
- 4],
1791 pen
->width
* pen
->customend
->inset
, FALSE
);
1793 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1794 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1795 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1796 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1799 case PathPointTypeLine
:
1800 if(pen
->endcap
== LineCapArrowAnchor
)
1801 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1802 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1804 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1805 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1806 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1807 pen
->customend
->inset
* pen
->width
);
1809 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1810 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1815 ERR("Bad path last point\n");
1819 /* Find start of points */
1820 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1821 == PathPointTypeStart
); j
++);
1823 switch(types
[j
] & PathPointTypePathTypeMask
){
1824 case PathPointTypeBezier
:
1825 if(pen
->startcap
== LineCapArrowAnchor
)
1826 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1827 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1828 shorten_bezier_amt(&ptcopy
[j
- 1],
1829 pen
->width
* pen
->customstart
->inset
, TRUE
);
1831 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1832 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1833 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1834 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1837 case PathPointTypeLine
:
1838 if(pen
->startcap
== LineCapArrowAnchor
)
1839 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1840 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1842 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1843 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1844 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1845 pen
->customstart
->inset
* pen
->width
);
1847 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1848 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1853 ERR("Bad path points\n");
1858 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1860 for(i
= 0; i
< count
; i
++){
1861 tp
[i
] = convert_path_point_type(types
[i
]);
1864 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1876 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1880 BeginPath(graphics
->hdc
);
1881 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1882 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1883 EndPath(graphics
->hdc
);
1887 typedef struct _GraphicsContainerItem
{
1889 GraphicsContainer contid
;
1891 SmoothingMode smoothing
;
1892 CompositingQuality compqual
;
1893 InterpolationMode interpolation
;
1894 CompositingMode compmode
;
1895 TextRenderingHint texthint
;
1898 PixelOffsetMode pixeloffset
;
1900 GpMatrix worldtrans
;
1902 INT origin_x
, origin_y
;
1903 } GraphicsContainerItem
;
1905 static GpStatus
init_container(GraphicsContainerItem
** container
,
1906 GDIPCONST GpGraphics
* graphics
){
1909 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1913 (*container
)->contid
= graphics
->contid
+ 1;
1915 (*container
)->smoothing
= graphics
->smoothing
;
1916 (*container
)->compqual
= graphics
->compqual
;
1917 (*container
)->interpolation
= graphics
->interpolation
;
1918 (*container
)->compmode
= graphics
->compmode
;
1919 (*container
)->texthint
= graphics
->texthint
;
1920 (*container
)->scale
= graphics
->scale
;
1921 (*container
)->unit
= graphics
->unit
;
1922 (*container
)->textcontrast
= graphics
->textcontrast
;
1923 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1924 (*container
)->origin_x
= graphics
->origin_x
;
1925 (*container
)->origin_y
= graphics
->origin_y
;
1926 (*container
)->worldtrans
= graphics
->worldtrans
;
1928 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1930 GdipFree(*container
);
1938 static void delete_container(GraphicsContainerItem
* container
)
1940 GdipDeleteRegion(container
->clip
);
1941 GdipFree(container
);
1944 static GpStatus
restore_container(GpGraphics
* graphics
,
1945 GDIPCONST GraphicsContainerItem
* container
){
1949 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1950 if(sts
!= Ok
) return sts
;
1952 graphics
->worldtrans
= container
->worldtrans
;
1954 GdipDeleteRegion(graphics
->clip
);
1955 graphics
->clip
= newClip
;
1957 graphics
->contid
= container
->contid
- 1;
1959 graphics
->smoothing
= container
->smoothing
;
1960 graphics
->compqual
= container
->compqual
;
1961 graphics
->interpolation
= container
->interpolation
;
1962 graphics
->compmode
= container
->compmode
;
1963 graphics
->texthint
= container
->texthint
;
1964 graphics
->scale
= container
->scale
;
1965 graphics
->unit
= container
->unit
;
1966 graphics
->textcontrast
= container
->textcontrast
;
1967 graphics
->pixeloffset
= container
->pixeloffset
;
1968 graphics
->origin_x
= container
->origin_x
;
1969 graphics
->origin_y
= container
->origin_y
;
1974 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1980 if(graphics
->hwnd
) {
1981 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1982 return GenericError
;
1984 rect
->X
= wnd_rect
.left
;
1985 rect
->Y
= wnd_rect
.top
;
1986 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1987 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1988 }else if (graphics
->image
){
1989 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1990 if (stat
== Ok
&& unit
!= UnitPixel
)
1991 FIXME("need to convert from unit %i\n", unit
);
1992 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
1999 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2000 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2002 rect
->Width
= bmp
.bmWidth
;
2003 rect
->Height
= bmp
.bmHeight
;
2014 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2015 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2021 /* on success, rgn will contain the region of the graphics object which
2022 * is visible after clipping has been applied */
2023 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2029 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2032 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2035 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2038 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2041 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2044 GdipDeleteRegion(tmp
);
2048 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2052 if (font
->unit
== UnitPixel
)
2054 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2058 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2059 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2061 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2064 lf
->lfHeight
= -(height
+ 0.5);
2066 lf
->lfEscapement
= 0;
2067 lf
->lfOrientation
= 0;
2068 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2069 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2070 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2071 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2072 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2073 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2074 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2075 lf
->lfQuality
= DEFAULT_QUALITY
;
2076 lf
->lfPitchAndFamily
= 0;
2077 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2080 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2081 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2082 GDIPCONST GpMatrix
*matrix
)
2084 HDC hdc
= CreateCompatibleDC(0);
2086 REAL angle
, rel_width
, rel_height
, font_height
;
2088 HFONT unscaled_font
;
2089 TEXTMETRICW textmet
;
2091 if (font
->unit
== UnitPixel
)
2092 font_height
= font
->emSize
;
2095 REAL unit_scale
, res
;
2097 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2098 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2100 font_height
= font
->emSize
* unit_scale
;
2111 GpMatrix xform
= *matrix
;
2112 GdipTransformMatrixPoints(&xform
, pt
, 3);
2115 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2116 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2117 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2118 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2119 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2120 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2122 get_log_fontW(font
, graphics
, &lfw
);
2123 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2124 unscaled_font
= CreateFontIndirectW(&lfw
);
2126 SelectObject(hdc
, unscaled_font
);
2127 GetTextMetricsW(hdc
, &textmet
);
2129 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2130 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2132 *hfont
= CreateFontIndirectW(&lfw
);
2135 DeleteObject(unscaled_font
);
2138 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2140 TRACE("(%p, %p)\n", hdc
, graphics
);
2142 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2145 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2151 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2154 FIXME("Don't know how to handle parameter hDevice\n");
2159 if(graphics
== NULL
)
2160 return InvalidParameter
;
2162 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2163 if(!*graphics
) return OutOfMemory
;
2165 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2167 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2168 GdipFree(*graphics
);
2172 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2173 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2174 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2176 (*graphics
)->alpha_hdc
= 1;
2179 (*graphics
)->hdc
= hdc
;
2180 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2181 (*graphics
)->owndc
= FALSE
;
2182 (*graphics
)->smoothing
= SmoothingModeDefault
;
2183 (*graphics
)->compqual
= CompositingQualityDefault
;
2184 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2185 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2186 (*graphics
)->compmode
= CompositingModeSourceOver
;
2187 (*graphics
)->unit
= UnitDisplay
;
2188 (*graphics
)->scale
= 1.0;
2189 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2190 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2191 (*graphics
)->busy
= FALSE
;
2192 (*graphics
)->textcontrast
= 4;
2193 list_init(&(*graphics
)->containers
);
2194 (*graphics
)->contid
= 0;
2196 TRACE("<-- %p\n", *graphics
);
2201 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2205 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2206 if(!*graphics
) return OutOfMemory
;
2208 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2210 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2211 GdipFree(*graphics
);
2215 (*graphics
)->hdc
= NULL
;
2216 (*graphics
)->hwnd
= NULL
;
2217 (*graphics
)->owndc
= FALSE
;
2218 (*graphics
)->image
= image
;
2219 /* We have to store the image type here because the image may be freed
2220 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2221 (*graphics
)->image_type
= image
->type
;
2222 (*graphics
)->smoothing
= SmoothingModeDefault
;
2223 (*graphics
)->compqual
= CompositingQualityDefault
;
2224 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2225 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2226 (*graphics
)->compmode
= CompositingModeSourceOver
;
2227 (*graphics
)->unit
= UnitDisplay
;
2228 (*graphics
)->scale
= 1.0;
2229 (*graphics
)->xres
= image
->xres
;
2230 (*graphics
)->yres
= image
->yres
;
2231 (*graphics
)->busy
= FALSE
;
2232 (*graphics
)->textcontrast
= 4;
2233 list_init(&(*graphics
)->containers
);
2234 (*graphics
)->contid
= 0;
2236 TRACE("<-- %p\n", *graphics
);
2241 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2246 TRACE("(%p, %p)\n", hwnd
, graphics
);
2250 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2252 ReleaseDC(hwnd
, hdc
);
2256 (*graphics
)->hwnd
= hwnd
;
2257 (*graphics
)->owndc
= TRUE
;
2262 /* FIXME: no icm handling */
2263 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2265 TRACE("(%p, %p)\n", hwnd
, graphics
);
2267 return GdipCreateFromHWND(hwnd
, graphics
);
2270 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2271 GpMetafile
**metafile
)
2273 ENHMETAHEADER header
;
2274 MetafileType metafile_type
;
2276 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2278 if(!hemf
|| !metafile
)
2279 return InvalidParameter
;
2281 if (GetEnhMetaFileHeader(hemf
, sizeof(header
), &header
) == 0)
2282 return GenericError
;
2284 metafile_type
= METAFILE_GetEmfType(hemf
);
2286 if (metafile_type
== MetafileTypeInvalid
)
2287 return GenericError
;
2289 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2293 (*metafile
)->image
.type
= ImageTypeMetafile
;
2294 (*metafile
)->image
.format
= ImageFormatEMF
;
2295 (*metafile
)->image
.frame_count
= 1;
2296 (*metafile
)->image
.xres
= (REAL
)header
.szlDevice
.cx
;
2297 (*metafile
)->image
.yres
= (REAL
)header
.szlDevice
.cy
;
2298 (*metafile
)->bounds
.X
= (REAL
)header
.rclBounds
.left
;
2299 (*metafile
)->bounds
.Y
= (REAL
)header
.rclBounds
.top
;
2300 (*metafile
)->bounds
.Width
= (REAL
)(header
.rclBounds
.right
- header
.rclBounds
.left
);
2301 (*metafile
)->bounds
.Height
= (REAL
)(header
.rclBounds
.bottom
- header
.rclBounds
.top
);
2302 (*metafile
)->unit
= UnitPixel
;
2303 (*metafile
)->metafile_type
= metafile_type
;
2304 (*metafile
)->hemf
= hemf
;
2305 (*metafile
)->preserve_hemf
= !delete;
2307 TRACE("<-- %p\n", *metafile
);
2312 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2313 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2318 GpStatus retval
= Ok
;
2320 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2322 if(!hwmf
|| !metafile
|| !placeable
)
2323 return InvalidParameter
;
2326 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2328 return GenericError
;
2329 copy
= GdipAlloc(read
);
2330 GetMetaFileBitsEx(hwmf
, read
, copy
);
2332 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2335 /* FIXME: We should store and use hwmf instead of converting to hemf */
2336 retval
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
2340 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2341 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2342 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2343 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2344 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2345 placeable
->BoundingBox
.Left
);
2346 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2347 placeable
->BoundingBox
.Top
);
2348 (*metafile
)->metafile_type
= MetafileTypeWmfPlaceable
;
2349 (*metafile
)->image
.format
= ImageFormatWMF
;
2351 if (delete) DeleteMetaFile(hwmf
);
2354 DeleteEnhMetaFile(hemf
);
2358 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2359 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2361 HMETAFILE hmf
= GetMetaFileW(file
);
2363 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2365 if(!hmf
) return InvalidParameter
;
2367 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2370 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2371 GpMetafile
**metafile
)
2373 FIXME("(%p, %p): stub\n", file
, metafile
);
2374 return NotImplemented
;
2377 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2378 GpMetafile
**metafile
)
2380 FIXME("(%p, %p): stub\n", stream
, metafile
);
2381 return NotImplemented
;
2384 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2385 UINT access
, IStream
**stream
)
2390 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2392 if(!stream
|| !filename
)
2393 return InvalidParameter
;
2395 if(access
& GENERIC_WRITE
)
2396 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2397 else if(access
& GENERIC_READ
)
2398 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2400 return InvalidParameter
;
2402 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2404 return hresult_to_status(ret
);
2407 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2409 GraphicsContainerItem
*cont
, *next
;
2411 TRACE("(%p)\n", graphics
);
2413 if(!graphics
) return InvalidParameter
;
2414 if(graphics
->busy
) return ObjectBusy
;
2416 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2418 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2424 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2426 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2427 list_remove(&cont
->entry
);
2428 delete_container(cont
);
2431 GdipDeleteRegion(graphics
->clip
);
2437 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2438 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2443 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2444 width
, height
, startAngle
, sweepAngle
);
2446 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2447 return InvalidParameter
;
2452 status
= GdipCreatePath(FillModeAlternate
, &path
);
2453 if (status
!= Ok
) return status
;
2455 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2457 status
= GdipDrawPath(graphics
, pen
, path
);
2459 GdipDeletePath(path
);
2463 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2464 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2466 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2467 width
, height
, startAngle
, sweepAngle
);
2469 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2472 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2473 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2477 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2478 x2
, y2
, x3
, y3
, x4
, y4
);
2480 if(!graphics
|| !pen
)
2481 return InvalidParameter
;
2494 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2497 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2498 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2500 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2501 x2
, y2
, x3
, y3
, x4
, y4
);
2503 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2506 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2507 GDIPCONST GpPointF
*points
, INT count
)
2512 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2514 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2515 return InvalidParameter
;
2520 status
= GdipCreatePath(FillModeAlternate
, &path
);
2521 if (status
!= Ok
) return status
;
2523 status
= GdipAddPathBeziers(path
, points
, count
);
2525 status
= GdipDrawPath(graphics
, pen
, path
);
2527 GdipDeletePath(path
);
2531 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2532 GDIPCONST GpPoint
*points
, INT count
)
2538 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2540 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2541 return InvalidParameter
;
2546 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2550 for(i
= 0; i
< count
; i
++){
2551 pts
[i
].X
= (REAL
)points
[i
].X
;
2552 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2555 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2562 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2563 GDIPCONST GpPointF
*points
, INT count
)
2565 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2567 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2570 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2571 GDIPCONST GpPoint
*points
, INT count
)
2573 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2575 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2578 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2579 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2584 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2586 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2587 return InvalidParameter
;
2592 status
= GdipCreatePath(FillModeAlternate
, &path
);
2593 if (status
!= Ok
) return status
;
2595 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2597 status
= GdipDrawPath(graphics
, pen
, path
);
2599 GdipDeletePath(path
);
2604 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2605 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2611 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2613 if(!points
|| count
<= 0)
2614 return InvalidParameter
;
2616 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2620 for(i
= 0; i
< count
; i
++){
2621 ptf
[i
].X
= (REAL
)points
[i
].X
;
2622 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2625 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2632 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2633 GDIPCONST GpPointF
*points
, INT count
)
2635 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2637 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2640 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2641 GDIPCONST GpPoint
*points
, INT count
)
2647 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2650 return InvalidParameter
;
2652 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2656 for(i
= 0; i
< count
; i
++){
2657 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2658 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2661 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2667 /* Approximates cardinal spline with Bezier curves. */
2668 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2669 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2674 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2676 if(!graphics
|| !pen
)
2677 return InvalidParameter
;
2683 return InvalidParameter
;
2685 status
= GdipCreatePath(FillModeAlternate
, &path
);
2686 if (status
!= Ok
) return status
;
2688 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2690 status
= GdipDrawPath(graphics
, pen
, path
);
2692 GdipDeletePath(path
);
2696 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2697 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2703 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2706 return InvalidParameter
;
2708 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2712 for(i
= 0; i
< count
; i
++){
2713 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2714 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2717 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2723 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2724 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2727 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2729 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2730 return InvalidParameter
;
2733 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2736 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2737 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2740 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2746 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2747 return InvalidParameter
;
2750 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2753 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2754 REAL y
, REAL width
, REAL height
)
2759 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2761 if(!graphics
|| !pen
)
2762 return InvalidParameter
;
2767 status
= GdipCreatePath(FillModeAlternate
, &path
);
2768 if (status
!= Ok
) return status
;
2770 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2772 status
= GdipDrawPath(graphics
, pen
, path
);
2774 GdipDeletePath(path
);
2778 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2779 INT y
, INT width
, INT height
)
2781 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2783 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2787 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2791 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2793 if(!graphics
|| !image
)
2794 return InvalidParameter
;
2796 GdipGetImageWidth(image
, &width
);
2797 GdipGetImageHeight(image
, &height
);
2799 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2800 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2803 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2806 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2808 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2811 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2812 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2816 REAL scale_x
, scale_y
, width
, height
;
2818 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2820 if (!graphics
|| !image
) return InvalidParameter
;
2822 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2823 scale_x
*= graphics
->xres
/ image
->xres
;
2824 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2825 scale_y
*= graphics
->yres
/ image
->yres
;
2826 width
= srcwidth
* scale_x
;
2827 height
= srcheight
* scale_y
;
2829 points
[0].X
= points
[2].X
= x
;
2830 points
[0].Y
= points
[1].Y
= y
;
2831 points
[1].X
= x
+ width
;
2832 points
[2].Y
= y
+ height
;
2834 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2835 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2838 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2839 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2842 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2845 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2846 GDIPCONST GpPointF
*dstpoints
, INT count
)
2850 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2853 return InvalidParameter
;
2855 GdipGetImageWidth(image
, &width
);
2856 GdipGetImageHeight(image
, &height
);
2858 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2859 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2862 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2863 GDIPCONST GpPoint
*dstpoints
, INT count
)
2867 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2869 if (count
!= 3 || !dstpoints
)
2870 return InvalidParameter
;
2872 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2873 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2874 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2875 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2876 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2877 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2879 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2882 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2883 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2885 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2889 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2890 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2891 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2892 DrawImageAbort callback
, VOID
* callbackData
)
2898 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2899 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2903 return NotImplemented
;
2905 if(!graphics
|| !image
|| !points
|| count
!= 3)
2906 return InvalidParameter
;
2908 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2909 debugstr_pointf(&points
[2]));
2911 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2912 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2913 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2914 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
2916 transform_and_round_points(graphics
, pti
, ptf
, 4);
2918 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2919 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2921 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2922 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2923 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2924 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2925 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2931 FIXME("graphics object has no HDC\n");
2934 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2935 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2936 srcx
, srcy
, srcwidth
, srcheight
, NULL
) != S_OK
)
2939 callback(callbackData
);
2940 return GenericError
;
2943 else if (image
->type
== ImageTypeBitmap
)
2945 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2948 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2949 graphics
->xres
, graphics
->yres
,
2950 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2951 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2952 imageAttributes
? imageAttributes
->outside_color
: 0);
2954 if (imageAttributes
|| graphics
->alpha_hdc
||
2955 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2956 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2957 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2958 srcx
< 0 || srcy
< 0 ||
2959 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2966 int i
, x
, y
, src_stride
, dst_stride
;
2967 GpMatrix dst_to_src
;
2968 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2969 LPBYTE src_data
, dst_data
;
2970 BitmapData lockeddata
;
2971 InterpolationMode interpolation
= graphics
->interpolation
;
2972 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2973 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2974 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2975 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2977 if (!imageAttributes
)
2978 imageAttributes
= &defaultImageAttributes
;
2980 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2981 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2984 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2985 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2986 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2987 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2990 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
2992 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2993 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2994 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2995 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2996 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2997 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2999 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
3001 stat
= GdipInvertMatrix(&dst_to_src
);
3002 if (stat
!= Ok
) return stat
;
3004 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3005 if (!dst_data
) return OutOfMemory
;
3007 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3009 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3010 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3012 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3014 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3020 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3022 /* Read the bits we need from the source bitmap into an ARGB buffer. */
3023 lockeddata
.Width
= src_area
.Width
;
3024 lockeddata
.Height
= src_area
.Height
;
3025 lockeddata
.Stride
= src_stride
;
3026 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3027 lockeddata
.Scan0
= src_data
;
3029 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3030 PixelFormat32bppARGB
, &lockeddata
);
3033 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3037 if (src_data
!= dst_data
)
3043 apply_image_attributes(imageAttributes
, src_data
,
3044 src_area
.Width
, src_area
.Height
,
3045 src_stride
, ColorAdjustTypeBitmap
);
3047 /* Transform the bits as needed to the destination. */
3048 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3050 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3051 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3052 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3053 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3055 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3057 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3059 GpPointF src_pointf
;
3062 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3063 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3065 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3067 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3068 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3069 imageAttributes
, interpolation
, offset_mode
);
3077 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3078 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3087 int temp_hdc
=0, temp_bitmap
=0;
3088 HBITMAP hbitmap
, old_hbm
=NULL
;
3090 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3091 bitmap
->format
== PixelFormat24bppRGB
||
3092 bitmap
->format
== PixelFormat32bppRGB
||
3093 bitmap
->format
== PixelFormat32bppPARGB
))
3095 BITMAPINFOHEADER bih
;
3097 PixelFormat dst_format
;
3099 /* we can't draw a bitmap of this format directly */
3100 hdc
= CreateCompatibleDC(0);
3104 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3105 bih
.biWidth
= bitmap
->width
;
3106 bih
.biHeight
= -bitmap
->height
;
3108 bih
.biBitCount
= 32;
3109 bih
.biCompression
= BI_RGB
;
3110 bih
.biSizeImage
= 0;
3111 bih
.biXPelsPerMeter
= 0;
3112 bih
.biYPelsPerMeter
= 0;
3114 bih
.biClrImportant
= 0;
3116 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3117 (void**)&temp_bits
, NULL
, 0);
3119 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3120 dst_format
= PixelFormat32bppPARGB
;
3122 dst_format
= PixelFormat32bppRGB
;
3124 convert_pixels(bitmap
->width
, bitmap
->height
,
3125 bitmap
->width
*4, temp_bits
, dst_format
,
3126 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3127 bitmap
->image
.palette
);
3131 if (bitmap
->hbitmap
)
3132 hbitmap
= bitmap
->hbitmap
;
3135 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3140 temp_hdc
= (hdc
== 0);
3145 if (!hdc
) hdc
= CreateCompatibleDC(0);
3146 old_hbm
= SelectObject(hdc
, hbitmap
);
3149 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3151 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3152 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3156 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3157 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3162 SelectObject(hdc
, old_hbm
);
3167 DeleteObject(hbitmap
);
3170 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3176 rc
.Width
= srcwidth
;
3177 rc
.Height
= srcheight
;
3179 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3180 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3184 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3185 return InvalidParameter
;
3191 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3192 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3193 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3194 DrawImageAbort callback
, VOID
* callbackData
)
3196 GpPointF pointsF
[3];
3199 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3200 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3203 if(!points
|| count
!=3)
3204 return InvalidParameter
;
3206 for(i
= 0; i
< count
; i
++){
3207 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3208 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3211 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3212 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3213 callback
, callbackData
);
3216 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3217 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3218 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3219 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3220 VOID
* callbackData
)
3224 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3225 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3226 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3230 points
[1].X
= dstx
+ dstwidth
;
3233 points
[2].Y
= dsty
+ dstheight
;
3235 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3236 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3239 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3240 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3241 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3242 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3243 VOID
* callbackData
)
3247 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3248 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3249 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3253 points
[1].X
= dstx
+ dstwidth
;
3256 points
[2].Y
= dsty
+ dstheight
;
3258 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3259 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3262 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3263 REAL x
, REAL y
, REAL width
, REAL height
)
3269 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3271 if(!graphics
|| !image
)
3272 return InvalidParameter
;
3274 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3278 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3279 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3280 unit
, NULL
, NULL
, NULL
);
3283 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3284 INT x
, INT y
, INT width
, INT height
)
3286 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3288 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3291 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3292 REAL y1
, REAL x2
, REAL y2
)
3296 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3302 return GdipDrawLines(graphics
, pen
, pt
, 2);
3305 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3306 INT y1
, INT x2
, INT y2
)
3308 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3310 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3313 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3314 GpPointF
*points
, INT count
)
3319 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3321 if(!pen
|| !graphics
|| (count
< 2))
3322 return InvalidParameter
;
3327 status
= GdipCreatePath(FillModeAlternate
, &path
);
3328 if (status
!= Ok
) return status
;
3330 status
= GdipAddPathLine2(path
, points
, count
);
3332 status
= GdipDrawPath(graphics
, pen
, path
);
3334 GdipDeletePath(path
);
3338 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3339 GpPoint
*points
, INT count
)
3345 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3347 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3348 if(!ptf
) return OutOfMemory
;
3350 for(i
= 0; i
< count
; i
++){
3351 ptf
[i
].X
= (REAL
) points
[i
].X
;
3352 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3355 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3361 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3366 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3368 if(!pen
|| !graphics
)
3369 return InvalidParameter
;
3376 FIXME("graphics object has no HDC\n");
3380 save_state
= prepare_dc(graphics
, pen
);
3382 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3383 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3385 restore_dc(graphics
, save_state
);
3390 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3391 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3396 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3397 width
, height
, startAngle
, sweepAngle
);
3399 if(!graphics
|| !pen
)
3400 return InvalidParameter
;
3405 status
= GdipCreatePath(FillModeAlternate
, &path
);
3406 if (status
!= Ok
) return status
;
3408 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3410 status
= GdipDrawPath(graphics
, pen
, path
);
3412 GdipDeletePath(path
);
3416 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3417 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3419 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3420 width
, height
, startAngle
, sweepAngle
);
3422 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3425 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3426 REAL y
, REAL width
, REAL height
)
3431 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3433 if(!pen
|| !graphics
)
3434 return InvalidParameter
;
3439 status
= GdipCreatePath(FillModeAlternate
, &path
);
3440 if (status
!= Ok
) return status
;
3442 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3444 status
= GdipDrawPath(graphics
, pen
, path
);
3446 GdipDeletePath(path
);
3450 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3451 INT y
, INT width
, INT height
)
3453 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3455 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3458 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3459 GDIPCONST GpRectF
* rects
, INT count
)
3464 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3466 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3467 return InvalidParameter
;
3472 status
= GdipCreatePath(FillModeAlternate
, &path
);
3473 if (status
!= Ok
) return status
;
3475 status
= GdipAddPathRectangles(path
, rects
, count
);
3477 status
= GdipDrawPath(graphics
, pen
, path
);
3479 GdipDeletePath(path
);
3483 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3484 GDIPCONST GpRect
* rects
, INT count
)
3490 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3492 if(!rects
|| count
<=0)
3493 return InvalidParameter
;
3495 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3499 for(i
= 0;i
< count
;i
++){
3500 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3501 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3502 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3503 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3506 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3512 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3513 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3518 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3519 count
, tension
, fill
);
3521 if(!graphics
|| !brush
|| !points
)
3522 return InvalidParameter
;
3527 if(count
== 1) /* Do nothing */
3530 status
= GdipCreatePath(fill
, &path
);
3531 if (status
!= Ok
) return status
;
3533 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3535 status
= GdipFillPath(graphics
, brush
, path
);
3537 GdipDeletePath(path
);
3541 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3542 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3548 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3549 count
, tension
, fill
);
3551 if(!points
|| count
== 0)
3552 return InvalidParameter
;
3554 if(count
== 1) /* Do nothing */
3557 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3561 for(i
= 0;i
< count
;i
++){
3562 ptf
[i
].X
= (REAL
)points
[i
].X
;
3563 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3566 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3573 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3574 GDIPCONST GpPointF
*points
, INT count
)
3576 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3577 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3578 0.5f
, FillModeAlternate
);
3581 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3582 GDIPCONST GpPoint
*points
, INT count
)
3584 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3585 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3586 0.5f
, FillModeAlternate
);
3589 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3590 REAL y
, REAL width
, REAL height
)
3595 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3597 if(!graphics
|| !brush
)
3598 return InvalidParameter
;
3603 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3607 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3610 stat
= GdipFillPath(graphics
, brush
, path
);
3612 GdipDeletePath(path
);
3618 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3619 INT y
, INT width
, INT height
)
3621 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3623 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3626 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3631 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3632 return NotImplemented
;
3634 save_state
= SaveDC(graphics
->hdc
);
3635 EndPath(graphics
->hdc
);
3636 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3639 BeginPath(graphics
->hdc
);
3640 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3641 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3646 EndPath(graphics
->hdc
);
3647 brush_fill_path(graphics
, brush
);
3652 RestoreDC(graphics
->hdc
, save_state
);
3657 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3662 if (!brush_can_fill_pixels(brush
))
3663 return NotImplemented
;
3665 /* FIXME: This could probably be done more efficiently without regions. */
3667 stat
= GdipCreateRegionPath(path
, &rgn
);
3671 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3673 GdipDeleteRegion(rgn
);
3679 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3681 GpStatus stat
= NotImplemented
;
3683 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3685 if(!brush
|| !graphics
|| !path
)
3686 return InvalidParameter
;
3691 if (!graphics
->image
&& !graphics
->alpha_hdc
)
3692 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3694 if (stat
== NotImplemented
)
3695 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3697 if (stat
== NotImplemented
)
3699 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3706 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3707 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3712 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3713 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3715 if(!graphics
|| !brush
)
3716 return InvalidParameter
;
3721 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3725 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3728 stat
= GdipFillPath(graphics
, brush
, path
);
3730 GdipDeletePath(path
);
3736 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3737 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3739 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3740 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3742 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3745 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3746 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3751 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3753 if(!graphics
|| !brush
|| !points
|| !count
)
3754 return InvalidParameter
;
3759 stat
= GdipCreatePath(fillMode
, &path
);
3763 stat
= GdipAddPathPolygon(path
, points
, count
);
3766 stat
= GdipFillPath(graphics
, brush
, path
);
3768 GdipDeletePath(path
);
3774 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3775 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3780 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3782 if(!graphics
|| !brush
|| !points
|| !count
)
3783 return InvalidParameter
;
3788 stat
= GdipCreatePath(fillMode
, &path
);
3792 stat
= GdipAddPathPolygonI(path
, points
, count
);
3795 stat
= GdipFillPath(graphics
, brush
, path
);
3797 GdipDeletePath(path
);
3803 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3804 GDIPCONST GpPointF
*points
, INT count
)
3806 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3808 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3811 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3812 GDIPCONST GpPoint
*points
, INT count
)
3814 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3816 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3819 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3820 REAL x
, REAL y
, REAL width
, REAL height
)
3825 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3827 if(!graphics
|| !brush
)
3828 return InvalidParameter
;
3833 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3837 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3840 stat
= GdipFillPath(graphics
, brush
, path
);
3842 GdipDeletePath(path
);
3848 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3849 INT x
, INT y
, INT width
, INT height
)
3851 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3853 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
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 status
= GdipCreatePath(FillModeAlternate
, &path
);
3868 if (status
!= Ok
) return status
;
3870 status
= GdipAddPathRectangles(path
, rects
, count
);
3872 status
= GdipFillPath(graphics
, brush
, path
);
3874 GdipDeletePath(path
);
3878 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3885 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3887 if(!rects
|| count
<= 0)
3888 return InvalidParameter
;
3890 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3894 for(i
= 0; i
< count
; i
++){
3895 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3896 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3897 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3898 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3901 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3907 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3915 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3916 return NotImplemented
;
3918 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3922 save_state
= SaveDC(graphics
->hdc
);
3923 EndPath(graphics
->hdc
);
3925 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3927 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3929 BeginPath(graphics
->hdc
);
3930 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3931 EndPath(graphics
->hdc
);
3933 brush_fill_path(graphics
, brush
);
3936 RestoreDC(graphics
->hdc
, save_state
);
3943 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3947 GpRegion
*temp_region
;
3948 GpMatrix world_to_device
;
3949 GpRectF graphics_bounds
;
3953 GpRect gp_bound_rect
;
3955 if (!brush_can_fill_pixels(brush
))
3956 return NotImplemented
;
3958 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3961 stat
= GdipCloneRegion(region
, &temp_region
);
3965 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3966 CoordinateSpaceWorld
, &world_to_device
);
3969 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
3972 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
3975 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
3977 GdipDeleteRegion(temp_region
);
3980 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
3982 DeleteObject(hregion
);
3988 gp_bound_rect
.X
= bound_rect
.left
;
3989 gp_bound_rect
.Y
= bound_rect
.top
;
3990 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
3991 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
3993 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
3999 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4000 &gp_bound_rect
, gp_bound_rect
.Width
);
4003 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4004 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4005 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4007 GdipFree(pixel_data
);
4010 DeleteObject(hregion
);
4016 /*****************************************************************************
4017 * GdipFillRegion [GDIPLUS.@]
4019 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4022 GpStatus stat
= NotImplemented
;
4024 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4026 if (!(graphics
&& brush
&& region
))
4027 return InvalidParameter
;
4032 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4033 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4035 if (stat
== NotImplemented
)
4036 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4038 if (stat
== NotImplemented
)
4040 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4047 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4049 TRACE("(%p,%u)\n", graphics
, intention
);
4052 return InvalidParameter
;
4057 /* We have no internal operation queue, so there's no need to clear it. */
4065 /*****************************************************************************
4066 * GdipGetClipBounds [GDIPLUS.@]
4068 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4072 TRACE("(%p, %p)\n", graphics
, rect
);
4075 return InvalidParameter
;
4080 status
= GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4082 transform_rectf(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, rect
);
4087 /*****************************************************************************
4088 * GdipGetClipBoundsI [GDIPLUS.@]
4090 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4092 TRACE("(%p, %p)\n", graphics
, rect
);
4095 return InvalidParameter
;
4100 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4103 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4104 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4105 CompositingMode
*mode
)
4107 TRACE("(%p, %p)\n", graphics
, mode
);
4109 if(!graphics
|| !mode
)
4110 return InvalidParameter
;
4115 *mode
= graphics
->compmode
;
4120 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4121 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4122 CompositingQuality
*quality
)
4124 TRACE("(%p, %p)\n", graphics
, quality
);
4126 if(!graphics
|| !quality
)
4127 return InvalidParameter
;
4132 *quality
= graphics
->compqual
;
4137 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4138 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4139 InterpolationMode
*mode
)
4141 TRACE("(%p, %p)\n", graphics
, mode
);
4143 if(!graphics
|| !mode
)
4144 return InvalidParameter
;
4149 *mode
= graphics
->interpolation
;
4154 /* FIXME: Need to handle color depths less than 24bpp */
4155 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4157 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4159 if(!graphics
|| !argb
)
4160 return InvalidParameter
;
4168 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4170 TRACE("(%p, %p)\n", graphics
, scale
);
4172 if(!graphics
|| !scale
)
4173 return InvalidParameter
;
4178 *scale
= graphics
->scale
;
4183 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4185 TRACE("(%p, %p)\n", graphics
, unit
);
4187 if(!graphics
|| !unit
)
4188 return InvalidParameter
;
4193 *unit
= graphics
->unit
;
4198 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4199 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4202 TRACE("(%p, %p)\n", graphics
, mode
);
4204 if(!graphics
|| !mode
)
4205 return InvalidParameter
;
4210 *mode
= graphics
->pixeloffset
;
4215 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4216 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4218 TRACE("(%p, %p)\n", graphics
, mode
);
4220 if(!graphics
|| !mode
)
4221 return InvalidParameter
;
4226 *mode
= graphics
->smoothing
;
4231 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4233 TRACE("(%p, %p)\n", graphics
, contrast
);
4235 if(!graphics
|| !contrast
)
4236 return InvalidParameter
;
4238 *contrast
= graphics
->textcontrast
;
4243 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4244 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4245 TextRenderingHint
*hint
)
4247 TRACE("(%p, %p)\n", graphics
, hint
);
4249 if(!graphics
|| !hint
)
4250 return InvalidParameter
;
4255 *hint
= graphics
->texthint
;
4260 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4265 TRACE("(%p, %p)\n", graphics
, rect
);
4267 if(!graphics
|| !rect
)
4268 return InvalidParameter
;
4273 /* intersect window and graphics clipping regions */
4274 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4277 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4280 /* get bounds of the region */
4281 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4284 GdipDeleteRegion(clip_rgn
);
4289 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4294 TRACE("(%p, %p)\n", graphics
, rect
);
4296 if(!graphics
|| !rect
)
4297 return InvalidParameter
;
4299 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4301 rect
->X
= gdip_round(rectf
.X
);
4302 rect
->Y
= gdip_round(rectf
.Y
);
4303 rect
->Width
= gdip_round(rectf
.Width
);
4304 rect
->Height
= gdip_round(rectf
.Height
);
4310 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4312 TRACE("(%p, %p)\n", graphics
, matrix
);
4314 if(!graphics
|| !matrix
)
4315 return InvalidParameter
;
4320 *matrix
= graphics
->worldtrans
;
4324 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4330 TRACE("(%p, %x)\n", graphics
, color
);
4333 return InvalidParameter
;
4338 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4341 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4342 GdipDeleteBrush((GpBrush
*)brush
);
4346 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4347 wnd_rect
.Width
, wnd_rect
.Height
);
4349 GdipDeleteBrush((GpBrush
*)brush
);
4354 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4356 TRACE("(%p, %p)\n", graphics
, res
);
4358 if(!graphics
|| !res
)
4359 return InvalidParameter
;
4361 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4364 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4370 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4372 if(!graphics
|| !result
)
4373 return InvalidParameter
;
4380 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4381 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4384 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4387 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4390 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4393 GdipDeleteRegion(rgn
);
4397 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4399 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4402 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4408 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4410 if(!graphics
|| !result
)
4411 return InvalidParameter
;
4418 pts
[1].X
= x
+ width
;
4419 pts
[1].Y
= y
+ height
;
4421 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4422 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4425 pts
[1].X
-= pts
[0].X
;
4426 pts
[1].Y
-= pts
[0].Y
;
4428 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4431 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4434 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4437 GdipDeleteRegion(rgn
);
4441 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4443 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4446 GpStatus
gdip_format_string(HDC hdc
,
4447 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4448 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4449 gdip_format_string_callback callback
, void *user_data
)
4452 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4453 nheight
, lineend
, lineno
= 0;
4455 StringAlignment halign
;
4458 HotkeyPrefix hkprefix
;
4459 INT
*hotkeyprefix_offsets
=NULL
;
4460 INT hotkeyprefix_count
=0;
4461 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4464 if(length
== -1) length
= lstrlenW(string
);
4466 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4467 if(!stringdup
) return OutOfMemory
;
4469 nwidth
= rect
->Width
;
4470 nheight
= rect
->Height
;
4471 if (ignore_empty_clip
)
4473 if (!nwidth
) nwidth
= INT_MAX
;
4474 if (!nheight
) nheight
= INT_MAX
;
4478 hkprefix
= format
->hkprefix
;
4480 hkprefix
= HotkeyPrefixNone
;
4482 if (hkprefix
== HotkeyPrefixShow
)
4484 for (i
=0; i
<length
; i
++)
4486 if (string
[i
] == '&')
4487 hotkeyprefix_count
++;
4491 if (hotkeyprefix_count
)
4492 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4494 hotkeyprefix_count
= 0;
4496 for(i
= 0, j
= 0; i
< length
; i
++){
4497 /* FIXME: This makes the indexes passed to callback inaccurate. */
4498 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4501 /* FIXME: tabs should be handled using tabstops from stringformat */
4502 if (string
[i
] == '\t')
4505 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4506 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4507 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4515 stringdup
[j
] = string
[i
];
4521 if (format
) halign
= format
->align
;
4522 else halign
= StringAlignmentNear
;
4524 while(sum
< length
){
4525 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4526 nwidth
, &fit
, NULL
, &size
);
4532 for(lret
= 0; lret
< fit
; lret
++)
4533 if(*(stringdup
+ sum
+ lret
) == '\n')
4536 /* Line break code (may look strange, but it imitates windows). */
4538 lineend
= fit
= lret
; /* this is not an off-by-one error */
4539 else if(fit
< (length
- sum
)){
4540 if(*(stringdup
+ sum
+ fit
) == ' ')
4541 while(*(stringdup
+ sum
+ fit
) == ' ')
4544 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4547 if(*(stringdup
+ sum
+ fit
) == '\t')
4556 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4557 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4563 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4564 nwidth
, &j
, NULL
, &size
);
4566 bounds
.Width
= size
.cx
;
4568 if(height
+ size
.cy
> nheight
)
4569 bounds
.Height
= nheight
- (height
+ size
.cy
);
4571 bounds
.Height
= size
.cy
;
4573 bounds
.Y
= rect
->Y
+ height
;
4577 case StringAlignmentNear
:
4581 case StringAlignmentCenter
:
4582 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4584 case StringAlignmentFar
:
4585 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4589 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4590 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4593 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4594 font
, rect
, format
, lineno
, &bounds
,
4595 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4596 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4601 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4605 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4607 if(height
> nheight
)
4610 /* Stop if this was a linewrap (but not if it was a linebreak). */
4611 if ((lret
== fitcpy
) && format
&&
4612 (format
->attr
& (StringFormatFlagsNoWrap
| StringFormatFlagsLineLimit
)))
4616 GdipFree(stringdup
);
4617 GdipFree(hotkeyprefix_offsets
);
4622 struct measure_ranges_args
{
4624 REAL rel_width
, rel_height
;
4627 static GpStatus
measure_ranges_callback(HDC hdc
,
4628 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4629 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4630 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4631 INT underlined_index_count
, void *user_data
)
4635 struct measure_ranges_args
*args
= user_data
;
4637 for (i
=0; i
<format
->range_count
; i
++)
4639 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4640 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4641 if (range_start
< range_end
)
4646 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4647 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4649 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4650 INT_MAX
, NULL
, NULL
, &range_size
);
4651 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4653 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4654 INT_MAX
, NULL
, NULL
, &range_size
);
4655 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4657 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4666 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4667 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4668 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4669 INT regionCount
, GpRegion
** regions
)
4673 HFONT gdifont
, oldfont
;
4674 struct measure_ranges_args args
;
4675 HDC hdc
, temp_hdc
=NULL
;
4680 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4681 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4683 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4684 return InvalidParameter
;
4686 if (regionCount
< stringFormat
->range_count
)
4687 return InvalidParameter
;
4691 hdc
= temp_hdc
= CreateCompatibleDC(0);
4692 if (!temp_hdc
) return OutOfMemory
;
4695 hdc
= graphics
->hdc
;
4697 if (stringFormat
->attr
)
4698 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4706 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4707 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4708 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4709 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4710 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4712 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4713 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4715 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4716 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4717 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
4718 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
4720 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
4721 oldfont
= SelectObject(hdc
, gdifont
);
4723 for (i
=0; i
<stringFormat
->range_count
; i
++)
4725 stat
= GdipSetEmpty(regions
[i
]);
4730 args
.regions
= regions
;
4732 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
4733 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
4735 SelectObject(hdc
, oldfont
);
4736 DeleteObject(gdifont
);
4744 struct measure_string_args
{
4746 INT
*codepointsfitted
;
4748 REAL rel_width
, rel_height
;
4751 static GpStatus
measure_string_callback(HDC hdc
,
4752 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4753 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4754 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4755 INT underlined_index_count
, void *user_data
)
4757 struct measure_string_args
*args
= user_data
;
4758 REAL new_width
, new_height
;
4760 new_width
= bounds
->Width
/ args
->rel_width
;
4761 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
4763 if (new_width
> args
->bounds
->Width
)
4764 args
->bounds
->Width
= new_width
;
4766 if (new_height
> args
->bounds
->Height
)
4767 args
->bounds
->Height
= new_height
;
4769 if (args
->codepointsfitted
)
4770 *args
->codepointsfitted
= index
+ length
;
4772 if (args
->linesfilled
)
4773 (*args
->linesfilled
)++;
4778 /* Find the smallest rectangle that bounds the text when it is printed in rect
4779 * according to the format options listed in format. If rect has 0 width and
4780 * height, then just find the smallest rectangle that bounds the text when it's
4781 * printed at location (rect->X, rect-Y). */
4782 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4783 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4784 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4785 INT
*codepointsfitted
, INT
*linesfilled
)
4787 HFONT oldfont
, gdifont
;
4788 struct measure_string_args args
;
4789 HDC temp_hdc
=NULL
, hdc
;
4795 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4796 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4797 bounds
, codepointsfitted
, linesfilled
);
4799 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4800 return InvalidParameter
;
4804 hdc
= temp_hdc
= CreateCompatibleDC(0);
4805 if (!temp_hdc
) return OutOfMemory
;
4808 hdc
= graphics
->hdc
;
4810 if(linesfilled
) *linesfilled
= 0;
4811 if(codepointsfitted
) *codepointsfitted
= 0;
4814 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4822 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4823 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4824 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4825 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4826 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4828 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4829 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4831 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
4832 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
4833 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
4834 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
4835 if (scaled_rect
.Width
>= 0.5)
4837 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4838 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4841 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4842 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4844 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
4845 oldfont
= SelectObject(hdc
, gdifont
);
4847 bounds
->X
= rect
->X
;
4848 bounds
->Y
= rect
->Y
;
4849 bounds
->Width
= 0.0;
4850 bounds
->Height
= 0.0;
4852 args
.bounds
= bounds
;
4853 args
.codepointsfitted
= &glyphs
;
4854 args
.linesfilled
= &lines
;
4857 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
4858 measure_string_callback
, &args
);
4860 if (linesfilled
) *linesfilled
= lines
;
4861 if (codepointsfitted
) *codepointsfitted
= glyphs
;
4864 bounds
->Width
+= margin_x
* 2.0;
4866 SelectObject(hdc
, oldfont
);
4867 DeleteObject(gdifont
);
4875 struct draw_string_args
{
4876 GpGraphics
*graphics
;
4877 GDIPCONST GpBrush
*brush
;
4878 REAL x
, y
, rel_width
, rel_height
, ascent
;
4881 static GpStatus
draw_string_callback(HDC hdc
,
4882 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4883 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4884 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4885 INT underlined_index_count
, void *user_data
)
4887 struct draw_string_args
*args
= user_data
;
4891 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4892 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4894 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
4895 args
->brush
, &position
,
4896 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4898 if (stat
== Ok
&& underlined_index_count
)
4900 OUTLINETEXTMETRICW otm
;
4901 REAL underline_y
, underline_height
;
4904 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
4906 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
4907 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
4909 for (i
=0; i
<underlined_index_count
; i
++)
4911 REAL start_x
, end_x
;
4913 INT ofs
= underlined_indexes
[i
] - index
;
4915 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
4916 start_x
= text_size
.cx
/ args
->rel_width
;
4918 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
4919 end_x
= text_size
.cx
/ args
->rel_width
;
4921 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
4928 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4929 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4930 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4934 GpPointF pt
[3], rectcpy
[4];
4936 REAL rel_width
, rel_height
, margin_x
;
4937 INT save_state
, format_flags
= 0;
4939 struct draw_string_args args
;
4941 HDC hdc
, temp_hdc
=NULL
;
4942 TEXTMETRICW textmetric
;
4944 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4945 length
, font
, debugstr_rectf(rect
), format
, brush
);
4947 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4948 return InvalidParameter
;
4952 hdc
= graphics
->hdc
;
4956 hdc
= temp_hdc
= CreateCompatibleDC(0);
4960 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4962 format_flags
= format
->attr
;
4964 /* Should be no need to explicitly test for StringAlignmentNear as
4965 * that is default behavior if no alignment is passed. */
4966 if(format
->vertalign
!= StringAlignmentNear
){
4967 RectF bounds
, in_rect
= *rect
;
4968 in_rect
.Height
= 0.0; /* avoid height clipping */
4969 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
4971 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
4973 if(format
->vertalign
== StringAlignmentCenter
)
4974 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4975 else if(format
->vertalign
== StringAlignmentFar
)
4976 offsety
= (rect
->Height
- bounds
.Height
);
4978 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
4981 save_state
= SaveDC(hdc
);
4989 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4990 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4991 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4992 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4993 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4995 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
4996 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
4997 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
4998 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
4999 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5001 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5002 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5004 scaled_rect
.X
= margin_x
* rel_width
;
5005 scaled_rect
.Y
= 0.0;
5006 scaled_rect
.Width
= rel_width
* rect
->Width
;
5007 scaled_rect
.Height
= rel_height
* rect
->Height
;
5008 if (scaled_rect
.Width
>= 0.5)
5010 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5011 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5014 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5015 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5017 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5018 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23)
5020 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5021 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5022 SelectClipRgn(hdc
, rgn
);
5025 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5026 SelectObject(hdc
, gdifont
);
5028 args
.graphics
= graphics
;
5032 args
.y
= rect
->Y
+ offsety
;
5034 args
.rel_width
= rel_width
;
5035 args
.rel_height
= rel_height
;
5037 GetTextMetricsW(hdc
, &textmetric
);
5038 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5040 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5041 draw_string_callback
, &args
);
5044 DeleteObject(gdifont
);
5046 RestoreDC(hdc
, save_state
);
5053 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5055 TRACE("(%p)\n", graphics
);
5058 return InvalidParameter
;
5063 return GdipSetInfinite(graphics
->clip
);
5066 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5068 TRACE("(%p)\n", graphics
);
5071 return InvalidParameter
;
5076 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5079 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5081 return GdipEndContainer(graphics
, state
);
5084 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5085 GpMatrixOrder order
)
5087 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5090 return InvalidParameter
;
5095 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5098 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5100 return GdipBeginContainer2(graphics
, state
);
5103 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5104 GraphicsContainer
*state
)
5106 GraphicsContainerItem
*container
;
5109 TRACE("(%p, %p)\n", graphics
, state
);
5111 if(!graphics
|| !state
)
5112 return InvalidParameter
;
5114 sts
= init_container(&container
, graphics
);
5118 list_add_head(&graphics
->containers
, &container
->entry
);
5119 *state
= graphics
->contid
= container
->contid
;
5124 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5126 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5127 return NotImplemented
;
5130 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5132 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5133 return NotImplemented
;
5136 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5138 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5139 return NotImplemented
;
5142 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5145 GraphicsContainerItem
*container
, *container2
;
5147 TRACE("(%p, %x)\n", graphics
, state
);
5150 return InvalidParameter
;
5152 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5153 if(container
->contid
== state
)
5157 /* did not find a matching container */
5158 if(&container
->entry
== &graphics
->containers
)
5161 sts
= restore_container(graphics
, container
);
5165 /* remove all of the containers on top of the found container */
5166 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5167 if(container
->contid
== state
)
5169 list_remove(&container
->entry
);
5170 delete_container(container
);
5173 list_remove(&container
->entry
);
5174 delete_container(container
);
5179 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5180 REAL sy
, GpMatrixOrder order
)
5182 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5185 return InvalidParameter
;
5190 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5193 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5196 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5198 if(!graphics
|| !srcgraphics
)
5199 return InvalidParameter
;
5201 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5204 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5205 CompositingMode mode
)
5207 TRACE("(%p, %d)\n", graphics
, mode
);
5210 return InvalidParameter
;
5215 graphics
->compmode
= mode
;
5220 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5221 CompositingQuality quality
)
5223 TRACE("(%p, %d)\n", graphics
, quality
);
5226 return InvalidParameter
;
5231 graphics
->compqual
= quality
;
5236 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5237 InterpolationMode mode
)
5239 TRACE("(%p, %d)\n", graphics
, mode
);
5241 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5242 return InvalidParameter
;
5247 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5248 mode
= InterpolationModeBilinear
;
5250 if (mode
== InterpolationModeHighQuality
)
5251 mode
= InterpolationModeHighQualityBicubic
;
5253 graphics
->interpolation
= mode
;
5258 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5260 TRACE("(%p, %.2f)\n", graphics
, scale
);
5262 if(!graphics
|| (scale
<= 0.0))
5263 return InvalidParameter
;
5268 graphics
->scale
= scale
;
5273 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5275 TRACE("(%p, %d)\n", graphics
, unit
);
5278 return InvalidParameter
;
5283 if(unit
== UnitWorld
)
5284 return InvalidParameter
;
5286 graphics
->unit
= unit
;
5291 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5294 TRACE("(%p, %d)\n", graphics
, mode
);
5297 return InvalidParameter
;
5302 graphics
->pixeloffset
= mode
;
5307 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5311 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5314 FIXME("value is unused in rendering\n");
5317 return InvalidParameter
;
5319 graphics
->origin_x
= x
;
5320 graphics
->origin_y
= y
;
5325 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5327 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5329 if (!graphics
|| !x
|| !y
)
5330 return InvalidParameter
;
5332 *x
= graphics
->origin_x
;
5333 *y
= graphics
->origin_y
;
5338 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5340 TRACE("(%p, %d)\n", graphics
, mode
);
5343 return InvalidParameter
;
5348 graphics
->smoothing
= mode
;
5353 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5355 TRACE("(%p, %d)\n", graphics
, contrast
);
5358 return InvalidParameter
;
5360 graphics
->textcontrast
= contrast
;
5365 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5366 TextRenderingHint hint
)
5368 TRACE("(%p, %d)\n", graphics
, hint
);
5370 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5371 return InvalidParameter
;
5376 graphics
->texthint
= hint
;
5381 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5383 TRACE("(%p, %p)\n", graphics
, matrix
);
5385 if(!graphics
|| !matrix
)
5386 return InvalidParameter
;
5391 TRACE("%f,%f,%f,%f,%f,%f\n",
5392 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5393 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5395 graphics
->worldtrans
= *matrix
;
5400 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5401 REAL dy
, GpMatrixOrder order
)
5403 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5406 return InvalidParameter
;
5411 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5414 /*****************************************************************************
5415 * GdipSetClipHrgn [GDIPLUS.@]
5417 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5422 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5425 return InvalidParameter
;
5430 /* hrgn is already in device units */
5431 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5435 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5437 GdipDeleteRegion(region
);
5441 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5446 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5449 return InvalidParameter
;
5454 status
= GdipClonePath(path
, &clip_path
);
5457 GpMatrix world_to_device
;
5459 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
5460 CoordinateSpaceWorld
, &world_to_device
);
5461 status
= GdipTransformPath(clip_path
, &world_to_device
);
5463 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
5465 GdipDeletePath(clip_path
);
5470 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5471 REAL width
, REAL height
,
5476 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5479 return InvalidParameter
;
5487 rect
.Height
= height
;
5488 transform_rectf(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &rect
);
5490 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5493 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5494 INT width
, INT height
,
5497 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5500 return InvalidParameter
;
5505 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5508 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5514 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5516 if(!graphics
|| !region
)
5517 return InvalidParameter
;
5522 status
= GdipCloneRegion(region
, &clip
);
5525 GpMatrix world_to_device
;
5527 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5528 status
= GdipTransformRegion(clip
, &world_to_device
);
5530 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
5532 GdipDeleteRegion(clip
);
5537 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5542 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5545 FIXME("not implemented\n");
5547 return NotImplemented
;
5550 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5556 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5558 if(!graphics
|| !pen
|| count
<=0)
5559 return InvalidParameter
;
5566 FIXME("graphics object has no HDC\n");
5570 pti
= GdipAlloc(sizeof(POINT
) * count
);
5572 save_state
= prepare_dc(graphics
, pen
);
5573 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5575 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5576 Polygon(graphics
->hdc
, pti
, count
);
5578 restore_dc(graphics
, save_state
);
5584 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5591 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5593 if(count
<=0) return InvalidParameter
;
5594 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5596 for(i
= 0;i
< count
; i
++){
5597 ptf
[i
].X
= (REAL
)points
[i
].X
;
5598 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5601 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5607 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5609 TRACE("(%p, %p)\n", graphics
, dpi
);
5611 if(!graphics
|| !dpi
)
5612 return InvalidParameter
;
5617 *dpi
= graphics
->xres
;
5621 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5623 TRACE("(%p, %p)\n", graphics
, dpi
);
5625 if(!graphics
|| !dpi
)
5626 return InvalidParameter
;
5631 *dpi
= graphics
->yres
;
5635 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5636 GpMatrixOrder order
)
5641 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5643 if(!graphics
|| !matrix
)
5644 return InvalidParameter
;
5649 m
= graphics
->worldtrans
;
5651 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5653 graphics
->worldtrans
= m
;
5658 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5659 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5661 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5665 TRACE("(%p, %p)\n", graphics
, hdc
);
5667 if(!graphics
|| !hdc
)
5668 return InvalidParameter
;
5673 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5675 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5677 else if (!graphics
->hdc
|| graphics
->alpha_hdc
||
5678 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5680 /* Create a fake HDC and fill it with a constant color. */
5684 BITMAPINFOHEADER bmih
;
5687 stat
= get_graphics_bounds(graphics
, &bounds
);
5691 graphics
->temp_hbitmap_width
= bounds
.Width
;
5692 graphics
->temp_hbitmap_height
= bounds
.Height
;
5694 bmih
.biSize
= sizeof(bmih
);
5695 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5696 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5698 bmih
.biBitCount
= 32;
5699 bmih
.biCompression
= BI_RGB
;
5700 bmih
.biSizeImage
= 0;
5701 bmih
.biXPelsPerMeter
= 0;
5702 bmih
.biYPelsPerMeter
= 0;
5704 bmih
.biClrImportant
= 0;
5706 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5707 (void**)&graphics
->temp_bits
, NULL
, 0);
5709 return GenericError
;
5711 temp_hdc
= CreateCompatibleDC(0);
5714 DeleteObject(hbitmap
);
5715 return GenericError
;
5718 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5719 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5721 SelectObject(temp_hdc
, hbitmap
);
5723 graphics
->temp_hbitmap
= hbitmap
;
5724 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5728 *hdc
= graphics
->hdc
;
5732 graphics
->busy
= TRUE
;
5737 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5741 TRACE("(%p, %p)\n", graphics
, hdc
);
5743 if(!graphics
|| !hdc
|| !graphics
->busy
)
5744 return InvalidParameter
;
5746 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5748 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5750 else if (graphics
->temp_hdc
== hdc
)
5755 /* Find the pixels that have changed, and mark them as opaque. */
5756 pos
= (DWORD
*)graphics
->temp_bits
;
5757 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5759 if (*pos
!= DC_BACKGROUND_KEY
)
5766 /* Write the changed pixels to the real target. */
5767 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5768 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5769 graphics
->temp_hbitmap_width
* 4);
5772 DeleteDC(graphics
->temp_hdc
);
5773 DeleteObject(graphics
->temp_hbitmap
);
5774 graphics
->temp_hdc
= NULL
;
5775 graphics
->temp_hbitmap
= NULL
;
5777 else if (hdc
!= graphics
->hdc
)
5779 stat
= InvalidParameter
;
5783 graphics
->busy
= FALSE
;
5788 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5792 GpMatrix device_to_world
;
5794 TRACE("(%p, %p)\n", graphics
, region
);
5796 if(!graphics
|| !region
)
5797 return InvalidParameter
;
5802 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5805 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
5806 status
= GdipTransformRegion(clip
, &device_to_world
);
5809 GdipDeleteRegion(clip
);
5813 /* free everything except root node and header */
5814 delete_element(®ion
->node
);
5815 memcpy(region
, clip
, sizeof(GpRegion
));
5821 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5822 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
5825 REAL scale_x
, scale_y
;
5827 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5829 if (dst_space
!= src_space
)
5831 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5832 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5834 if(graphics
->unit
!= UnitDisplay
)
5836 scale_x
*= graphics
->scale
;
5837 scale_y
*= graphics
->scale
;
5840 /* transform from src_space to CoordinateSpacePage */
5843 case CoordinateSpaceWorld
:
5844 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
5846 case CoordinateSpacePage
:
5848 case CoordinateSpaceDevice
:
5849 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
5853 /* transform from CoordinateSpacePage to dst_space */
5856 case CoordinateSpaceWorld
:
5858 GpMatrix inverted_transform
= graphics
->worldtrans
;
5859 stat
= GdipInvertMatrix(&inverted_transform
);
5861 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
5864 case CoordinateSpacePage
:
5866 case CoordinateSpaceDevice
:
5867 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
5874 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5875 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5880 if(!graphics
|| !points
|| count
<= 0)
5881 return InvalidParameter
;
5886 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5888 if (src_space
== dst_space
) return Ok
;
5890 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5891 if (stat
!= Ok
) return stat
;
5893 return GdipTransformMatrixPoints(&matrix
, points
, count
);
5896 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5897 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5903 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5906 return InvalidParameter
;
5908 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5912 for(i
= 0; i
< count
; i
++){
5913 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5914 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5917 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5920 for(i
= 0; i
< count
; i
++){
5921 points
[i
].X
= gdip_round(pointsF
[i
].X
);
5922 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
5929 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5941 /*****************************************************************************
5942 * GdipTranslateClip [GDIPLUS.@]
5944 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5946 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5949 return InvalidParameter
;
5954 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5957 /*****************************************************************************
5958 * GdipTranslateClipI [GDIPLUS.@]
5960 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5962 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5965 return InvalidParameter
;
5970 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
5974 /*****************************************************************************
5975 * GdipMeasureDriverString [GDIPLUS.@]
5977 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5978 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
5979 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
5981 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
5984 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
5986 TEXTMETRICW textmetric
;
5987 const WORD
*glyph_indices
;
5988 WORD
*dynamic_glyph_indices
=NULL
;
5989 REAL rel_width
, rel_height
, ascent
, descent
;
5992 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
5994 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
5995 return InvalidParameter
;
5998 length
= strlenW(text
);
6002 boundingBox
->X
= 0.0;
6003 boundingBox
->Y
= 0.0;
6004 boundingBox
->Width
= 0.0;
6005 boundingBox
->Height
= 0.0;
6008 if (flags
& unsupported_flags
)
6009 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6011 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6013 hdc
= CreateCompatibleDC(0);
6014 SelectObject(hdc
, hfont
);
6016 GetTextMetricsW(hdc
, &textmetric
);
6026 GpMatrix xform
= *matrix
;
6027 GdipTransformMatrixPoints(&xform
, pt
, 3);
6029 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6030 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6031 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6032 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6033 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6035 if (flags
& DriverStringOptionsCmapLookup
)
6037 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6041 DeleteObject(hfont
);
6045 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6048 glyph_indices
= text
;
6050 min_x
= max_x
= x
= positions
[0].X
;
6051 min_y
= max_y
= y
= positions
[0].Y
;
6053 ascent
= textmetric
.tmAscent
/ rel_height
;
6054 descent
= textmetric
.tmDescent
/ rel_height
;
6056 for (i
=0; i
<length
; i
++)
6061 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6067 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6068 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6070 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6071 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6072 if (min_x
> x
) min_x
= x
;
6074 x
+= char_width
/ rel_width
;
6076 if (max_x
< x
) max_x
= x
;
6079 GdipFree(dynamic_glyph_indices
);
6081 DeleteObject(hfont
);
6083 boundingBox
->X
= min_x
;
6084 boundingBox
->Y
= min_y
;
6085 boundingBox
->Width
= max_x
- min_x
;
6086 boundingBox
->Height
= max_y
- min_y
;
6091 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6092 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6093 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6094 INT flags
, GDIPCONST GpMatrix
*matrix
)
6096 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6102 if (flags
& unsupported_flags
)
6103 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6105 if (!(flags
& DriverStringOptionsCmapLookup
))
6106 eto_flags
|= ETO_GLYPH_INDEX
;
6108 save_state
= SaveDC(graphics
->hdc
);
6109 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6110 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6113 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6115 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6116 SelectObject(graphics
->hdc
, hfont
);
6118 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6120 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6122 RestoreDC(graphics
->hdc
, save_state
);
6124 DeleteObject(hfont
);
6129 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6130 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6131 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6132 INT flags
, GDIPCONST GpMatrix
*matrix
)
6134 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6136 PointF
*real_positions
, real_position
;
6140 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6141 DWORD max_glyphsize
=0;
6142 GLYPHMETRICS glyphmetrics
;
6143 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6146 int text_mask_stride
;
6148 int pixel_data_stride
;
6150 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6155 if (!(flags
& DriverStringOptionsCmapLookup
))
6156 ggo_flags
|= GGO_GLYPH_INDEX
;
6158 if (flags
& unsupported_flags
)
6159 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6161 pti
= GdipAlloc(sizeof(POINT
) * length
);
6165 if (flags
& DriverStringOptionsRealizedAdvance
)
6167 real_position
= positions
[0];
6169 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6173 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6174 if (!real_positions
)
6180 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6182 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6184 GdipFree(real_positions
);
6187 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6189 hdc
= CreateCompatibleDC(0);
6190 SelectObject(hdc
, hfont
);
6192 /* Get the boundaries of the text to be drawn */
6193 for (i
=0; i
<length
; i
++)
6196 int left
, top
, right
, bottom
;
6198 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6199 &glyphmetrics
, 0, NULL
, &identity
);
6201 if (glyphsize
== GDI_ERROR
)
6203 ERR("GetGlyphOutlineW failed\n");
6206 DeleteObject(hfont
);
6207 return GenericError
;
6210 if (glyphsize
> max_glyphsize
)
6211 max_glyphsize
= glyphsize
;
6213 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6214 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6215 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6216 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6218 if (left
< min_x
) min_x
= left
;
6219 if (top
< min_y
) min_y
= top
;
6220 if (right
> max_x
) max_x
= right
;
6221 if (bottom
> max_y
) max_y
= bottom
;
6223 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6225 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6226 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6230 glyph_mask
= GdipAlloc(max_glyphsize
);
6231 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6232 text_mask_stride
= max_x
- min_x
;
6234 if (!(glyph_mask
&& text_mask
))
6236 GdipFree(glyph_mask
);
6237 GdipFree(text_mask
);
6240 DeleteObject(hfont
);
6244 /* Generate a mask for the text */
6245 for (i
=0; i
<length
; i
++)
6247 int left
, top
, stride
;
6249 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6250 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6252 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6253 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6254 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6256 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6258 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6259 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6260 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6262 *text_val
= min(64, *text_val
+ *glyph_val
);
6271 DeleteObject(hfont
);
6272 GdipFree(glyph_mask
);
6274 /* get the brush data */
6275 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6278 GdipFree(text_mask
);
6282 pixel_area
.X
= min_x
;
6283 pixel_area
.Y
= min_y
;
6284 pixel_area
.Width
= max_x
- min_x
;
6285 pixel_area
.Height
= max_y
- min_y
;
6286 pixel_data_stride
= pixel_area
.Width
* 4;
6288 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6291 GdipFree(text_mask
);
6292 GdipFree(pixel_data
);
6296 /* multiply the brush data by the mask */
6297 for (y
=0; y
<pixel_area
.Height
; y
++)
6299 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6300 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6301 for (x
=0; x
<pixel_area
.Width
; x
++)
6303 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6309 GdipFree(text_mask
);
6311 /* draw the result */
6312 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6313 pixel_area
.Height
, pixel_data_stride
);
6315 GdipFree(pixel_data
);
6320 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6321 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6322 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6323 INT flags
, GDIPCONST GpMatrix
*matrix
)
6325 GpStatus stat
= NotImplemented
;
6328 length
= strlenW(text
);
6330 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6331 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6332 brush
->bt
== BrushTypeSolidColor
&&
6333 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6334 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6335 brush
, positions
, flags
, matrix
);
6336 if (stat
== NotImplemented
)
6337 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6338 brush
, positions
, flags
, matrix
);
6342 /*****************************************************************************
6343 * GdipDrawDriverString [GDIPLUS.@]
6345 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6346 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6347 GDIPCONST PointF
*positions
, INT flags
,
6348 GDIPCONST GpMatrix
*matrix
)
6350 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6352 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6353 return InvalidParameter
;
6355 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6356 brush
, positions
, flags
, matrix
);
6359 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6360 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6362 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6363 return NotImplemented
;
6366 /*****************************************************************************
6367 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6369 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6374 TRACE("(%p, %p)\n", graphics
, res
);
6376 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6379 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6382 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6385 GdipDeleteRegion(rgn
);
6389 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6393 TRACE("(%p) stub\n", graphics
);
6396 FIXME("not implemented\n");
6398 return NotImplemented
;