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
19 #include "gdiplus_private.h"
24 /* Mike "tamlin" Nordell 2012-09-14 for ReactOS:
25 * NOTE: Wine uses per-GpGraphics id's ('contid' starting from zero in
26 * every GpGraphics). Windows seems to use process-global id's, or at
27 * least more unique id's.
28 * This have the following implications. It:
29 * 1. fails the current gdiplus test case.
30 * 2. is not what Windows does.
32 * We therefore "obfuscate" the 'contid' a little to more match Windows'
33 * behaviour. The observable behviour should still remain the same,
34 * except for handing out more "unique" id's.
36 #define GDIP_CONTID_STEP 64
37 static volatile LONG g_priv_contid
= GDIP_CONTID_STEP
;
38 #define GDIP_GET_NEW_CONTID_FOR(pGpGraphics) \
39 (UINT)(InterlockedExchangeAdd(&g_priv_contid,GDIP_CONTID_STEP))
41 /* looks-right constants */
42 #define ANCHOR_WIDTH (2.0)
43 #define MAX_ITERS (50)
45 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
46 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
47 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
48 INT flags
, GDIPCONST GpMatrix
*matrix
);
50 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
51 GpCoordinateSpace src_space
, GpMatrix
*matrix
);
53 /* Converts from gdiplus path point type to gdi path point type. */
54 static BYTE
convert_path_point_type(BYTE type
)
58 switch(type
& PathPointTypePathTypeMask
){
59 case PathPointTypeBezier
:
62 case PathPointTypeLine
:
65 case PathPointTypeStart
:
69 ERR("Bad point type\n");
73 if(type
& PathPointTypeCloseSubpath
)
74 ret
|= PT_CLOSEFIGURE
;
79 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
85 case BrushTypeSolidColor
:
87 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
91 case BrushTypeHatchFill
:
93 const GpHatch
*hatch
= (const GpHatch
*)brush
;
94 argb
= hatch
->forecol
;
97 case BrushTypeLinearGradient
:
99 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
100 argb
= line
->startcolor
;
103 case BrushTypePathGradient
:
105 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
106 argb
= grad
->centercolor
;
110 FIXME("unhandled brush type %d\n", brush
->bt
);
114 return ARGB2COLORREF(argb
);
117 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
120 BITMAPINFOHEADER bmih
;
124 bmih
.biSize
= sizeof(bmih
);
128 bmih
.biBitCount
= 32;
129 bmih
.biCompression
= BI_RGB
;
130 bmih
.biSizeImage
= 0;
132 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
135 const char *hatch_data
;
137 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
139 for (y
= 0; y
< 8; y
++)
141 for (x
= 0; x
< 8; x
++)
143 if (hatch_data
[y
] & (0x80 >> x
))
144 bits
[y
* 8 + x
] = hatch
->forecol
;
146 bits
[y
* 8 + x
] = hatch
->backcol
;
152 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
154 for (y
= 0; y
< 64; y
++)
155 bits
[y
] = hatch
->forecol
;
162 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
166 case BrushTypeSolidColor
:
168 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
169 lb
->lbStyle
= BS_SOLID
;
170 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
175 case BrushTypeHatchFill
:
177 const GpHatch
*hatch
= (const GpHatch
*)brush
;
180 hbmp
= create_hatch_bitmap(hatch
);
181 if (!hbmp
) return OutOfMemory
;
183 lb
->lbStyle
= BS_PATTERN
;
185 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
190 FIXME("unhandled brush type %d\n", brush
->bt
);
191 lb
->lbStyle
= BS_SOLID
;
192 lb
->lbColor
= get_gdi_brush_color(brush
);
198 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
203 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
209 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
214 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
216 gdibrush
= CreateBrushIndirect(&lb
);
217 free_gdi_logbrush(&lb
);
222 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
227 INT save_state
, i
, numdashes
;
229 DWORD dash_array
[MAX_DASHLEN
];
231 save_state
= SaveDC(graphics
->hdc
);
233 EndPath(graphics
->hdc
);
235 if(pen
->unit
== UnitPixel
){
239 /* Get an estimate for the amount the pen width is affected by the world
240 * transform. (This is similar to what some of the wine drivers do.) */
245 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
246 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
247 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
249 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
252 if(pen
->dash
== DashStyleCustom
){
253 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
255 TRACE("dashes are: ");
256 for(i
= 0; i
< numdashes
; i
++){
257 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
258 TRACE("%d, ", dash_array
[i
]);
260 TRACE("\n and the pen style is %x\n", pen
->style
);
262 create_gdi_logbrush(pen
->brush
, &lb
);
263 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
264 numdashes
, dash_array
);
265 free_gdi_logbrush(&lb
);
269 create_gdi_logbrush(pen
->brush
, &lb
);
270 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
271 free_gdi_logbrush(&lb
);
274 SelectObject(graphics
->hdc
, gdipen
);
279 static void restore_dc(GpGraphics
*graphics
, INT state
)
281 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
282 RestoreDC(graphics
->hdc
, state
);
285 /* This helper applies all the changes that the points listed in ptf need in
286 * order to be drawn on the device context. In the end, this should include at
288 * -scaling by page unit
289 * -applying world transformation
290 * -converting from float to int
291 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
292 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
293 * gdi to draw, and these functions would irreparably mess with line widths.
295 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
296 GpPointF
*ptf
, INT count
)
298 REAL scale_x
, scale_y
;
302 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
303 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
305 /* apply page scale */
306 if(graphics
->unit
!= UnitDisplay
)
308 scale_x
*= graphics
->scale
;
309 scale_y
*= graphics
->scale
;
312 matrix
= graphics
->worldtrans
;
313 GdipScaleMatrix(&matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
314 GdipTransformMatrixPoints(&matrix
, ptf
, count
);
316 for(i
= 0; i
< count
; i
++){
317 pti
[i
].x
= gdip_round(ptf
[i
].X
);
318 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
322 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
323 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
325 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
327 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
329 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
330 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
336 bf
.BlendOp
= AC_SRC_OVER
;
338 bf
.SourceConstantAlpha
= 255;
339 bf
.AlphaFormat
= AC_SRC_ALPHA
;
341 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
342 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
346 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
348 /* clipping region is in device coords */
349 return GdipGetRegionHRgn(graphics
->clip
, NULL
, hrgn
);
352 /* Draw non-premultiplied ARGB data to the given graphics object */
353 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
354 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
356 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
359 for (x
=0; x
<src_width
; x
++)
361 for (y
=0; y
<src_height
; y
++)
363 ARGB dst_color
, src_color
;
364 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
365 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
366 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
373 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
374 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
378 BITMAPINFOHEADER bih
;
381 hdc
= CreateCompatibleDC(0);
383 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
384 bih
.biWidth
= src_width
;
385 bih
.biHeight
= -src_height
;
388 bih
.biCompression
= BI_RGB
;
390 bih
.biXPelsPerMeter
= 0;
391 bih
.biYPelsPerMeter
= 0;
393 bih
.biClrImportant
= 0;
395 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
396 (void**)&temp_bits
, NULL
, 0);
398 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
399 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
401 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
402 4 * src_width
, src
, src_stride
);
404 SelectObject(hdc
, hbitmap
);
405 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
406 hdc
, 0, 0, src_width
, src_height
);
408 DeleteObject(hbitmap
);
413 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
414 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
)
418 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
424 HRGN hrgn
, visible_rgn
;
426 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
430 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
439 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
440 DeleteObject(visible_rgn
);
444 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
446 size
= GetRegionData(hrgn
, 0, NULL
);
448 rgndata
= GdipAlloc(size
);
455 GetRegionData(hrgn
, size
, rgndata
);
457 rects
= (RECT
*)rgndata
->Buffer
;
459 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
461 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
462 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
463 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
473 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
475 ERR("This should not be used for metafiles; fix caller\n");
476 return NotImplemented
;
483 stat
= get_clip_hrgn(graphics
, &hrgn
);
488 save
= SaveDC(graphics
->hdc
);
491 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
494 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
496 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
497 src_height
, src_stride
);
499 RestoreDC(graphics
->hdc
, save
);
507 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
508 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
510 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
);
513 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
519 a1
= (start
>> 24) & 0xff;
520 a2
= (end
>> 24) & 0xff;
522 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
526 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
527 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
531 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
535 /* clamp to between 0.0 and 1.0, using the wrap mode */
536 if (brush
->wrap
== WrapModeTile
)
538 position
= fmodf(position
, 1.0f
);
539 if (position
< 0.0f
) position
+= 1.0f
;
541 else /* WrapModeFlip* */
543 position
= fmodf(position
, 2.0f
);
544 if (position
< 0.0f
) position
+= 2.0f
;
545 if (position
> 1.0f
) position
= 2.0f
- position
;
548 if (brush
->blendcount
== 1)
553 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
556 /* locate the blend positions surrounding this position */
557 while (position
> brush
->blendpos
[i
])
560 /* interpolate between the blend positions */
561 left_blendpos
= brush
->blendpos
[i
-1];
562 left_blendfac
= brush
->blendfac
[i
-1];
563 right_blendpos
= brush
->blendpos
[i
];
564 right_blendfac
= brush
->blendfac
[i
];
565 range
= right_blendpos
- left_blendpos
;
566 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
567 right_blendfac
* (position
- left_blendpos
)) / range
;
570 if (brush
->pblendcount
== 0)
571 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
575 ARGB left_blendcolor
, right_blendcolor
;
576 REAL left_blendpos
, right_blendpos
;
578 /* locate the blend colors surrounding this position */
579 while (blendfac
> brush
->pblendpos
[i
])
582 /* interpolate between the blend colors */
583 left_blendpos
= brush
->pblendpos
[i
-1];
584 left_blendcolor
= brush
->pblendcolor
[i
-1];
585 right_blendpos
= brush
->pblendpos
[i
];
586 right_blendcolor
= brush
->pblendcolor
[i
];
587 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
588 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
592 static ARGB
transform_color(ARGB color
, const ColorMatrix
*matrix
)
596 unsigned char a
, r
, g
, b
;
598 val
[0] = ((color
>> 16) & 0xff) / 255.0; /* red */
599 val
[1] = ((color
>> 8) & 0xff) / 255.0; /* green */
600 val
[2] = (color
& 0xff) / 255.0; /* blue */
601 val
[3] = ((color
>> 24) & 0xff) / 255.0; /* alpha */
602 val
[4] = 1.0; /* translation */
609 res
[i
] += matrix
->m
[j
][i
] * val
[j
];
612 a
= min(max(floorf(res
[3]*255.0), 0.0), 255.0);
613 r
= min(max(floorf(res
[0]*255.0), 0.0), 255.0);
614 g
= min(max(floorf(res
[1]*255.0), 0.0), 255.0);
615 b
= min(max(floorf(res
[2]*255.0), 0.0), 255.0);
617 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
620 static int color_is_gray(ARGB color
)
622 unsigned char r
, g
, b
;
624 r
= (color
>> 16) & 0xff;
625 g
= (color
>> 8) & 0xff;
628 return (r
== g
) && (g
== b
);
631 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
632 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
637 if (attributes
->colorkeys
[type
].enabled
||
638 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
640 const struct color_key
*key
;
641 BYTE min_blue
, min_green
, min_red
;
642 BYTE max_blue
, max_green
, max_red
;
644 if (attributes
->colorkeys
[type
].enabled
)
645 key
= &attributes
->colorkeys
[type
];
647 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
649 min_blue
= key
->low
&0xff;
650 min_green
= (key
->low
>>8)&0xff;
651 min_red
= (key
->low
>>16)&0xff;
653 max_blue
= key
->high
&0xff;
654 max_green
= (key
->high
>>8)&0xff;
655 max_red
= (key
->high
>>16)&0xff;
657 for (x
=0; x
<width
; x
++)
658 for (y
=0; y
<height
; y
++)
661 BYTE blue
, green
, red
;
662 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
663 blue
= *src_color
&0xff;
664 green
= (*src_color
>>8)&0xff;
665 red
= (*src_color
>>16)&0xff;
666 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
667 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
668 *src_color
= 0x00000000;
672 if (attributes
->colorremaptables
[type
].enabled
||
673 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
675 const struct color_remap_table
*table
;
677 if (attributes
->colorremaptables
[type
].enabled
)
678 table
= &attributes
->colorremaptables
[type
];
680 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
682 for (x
=0; x
<width
; x
++)
683 for (y
=0; y
<height
; y
++)
686 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
687 for (i
=0; i
<table
->mapsize
; i
++)
689 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
691 *src_color
= table
->colormap
[i
].newColor
.Argb
;
698 if (attributes
->colormatrices
[type
].enabled
||
699 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
701 const struct color_matrix
*colormatrices
;
703 if (attributes
->colormatrices
[type
].enabled
)
704 colormatrices
= &attributes
->colormatrices
[type
];
706 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
708 for (x
=0; x
<width
; x
++)
709 for (y
=0; y
<height
; y
++)
712 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
714 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
715 !color_is_gray(*src_color
))
717 *src_color
= transform_color(*src_color
, &colormatrices
->colormatrix
);
719 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
721 *src_color
= transform_color(*src_color
, &colormatrices
->graymatrix
);
726 if (attributes
->gamma_enabled
[type
] ||
727 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
731 if (attributes
->gamma_enabled
[type
])
732 gamma
= attributes
->gamma
[type
];
734 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
736 for (x
=0; x
<width
; x
++)
737 for (y
=0; y
<height
; y
++)
740 BYTE blue
, green
, red
;
741 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
743 blue
= *src_color
&0xff;
744 green
= (*src_color
>>8)&0xff;
745 red
= (*src_color
>>16)&0xff;
747 /* FIXME: We should probably use a table for this. */
748 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
749 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
750 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
752 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
757 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
758 * bitmap that contains all the pixels we may need to draw it. */
759 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
760 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
763 INT left
, top
, right
, bottom
;
765 switch (interpolation
)
767 case InterpolationModeHighQualityBilinear
:
768 case InterpolationModeHighQualityBicubic
:
769 /* FIXME: Include a greater range for the prefilter? */
770 case InterpolationModeBicubic
:
771 case InterpolationModeBilinear
:
772 left
= (INT
)(floorf(srcx
));
773 top
= (INT
)(floorf(srcy
));
774 right
= (INT
)(ceilf(srcx
+srcwidth
));
775 bottom
= (INT
)(ceilf(srcy
+srcheight
));
777 case InterpolationModeNearestNeighbor
:
779 left
= gdip_round(srcx
);
780 top
= gdip_round(srcy
);
781 right
= gdip_round(srcx
+srcwidth
);
782 bottom
= gdip_round(srcy
+srcheight
);
786 if (wrap
== WrapModeClamp
)
792 if (right
>= bitmap
->width
)
793 right
= bitmap
->width
-1;
794 if (bottom
>= bitmap
->height
)
795 bottom
= bitmap
->height
-1;
799 /* In some cases we can make the rectangle smaller here, but the logic
800 * is hard to get right, and tiling suggests we're likely to use the
801 * entire source image. */
802 if (left
< 0 || right
>= bitmap
->width
)
805 right
= bitmap
->width
-1;
808 if (top
< 0 || bottom
>= bitmap
->height
)
811 bottom
= bitmap
->height
-1;
817 rect
->Width
= right
- left
+ 1;
818 rect
->Height
= bottom
- top
+ 1;
821 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
822 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
824 if (attributes
->wrap
== WrapModeClamp
)
826 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
827 return attributes
->outside_color
;
831 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
833 x
= width
*2 + x
% (width
* 2);
835 y
= height
*2 + y
% (height
* 2);
837 if ((attributes
->wrap
& 1) == 1)
840 if ((x
/ width
) % 2 == 0)
843 x
= width
- 1 - x
% width
;
848 if ((attributes
->wrap
& 2) == 2)
851 if ((y
/ height
) % 2 == 0)
854 y
= height
- 1 - y
% height
;
860 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
862 ERR("out of range pixel requested\n");
866 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
869 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
870 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
871 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
875 switch (interpolation
)
879 FIXME("Unimplemented interpolation %i\n", interpolation
);
881 case InterpolationModeBilinear
:
884 INT leftx
, rightx
, topy
, bottomy
;
885 ARGB topleft
, topright
, bottomleft
, bottomright
;
889 leftxf
= floorf(point
->X
);
891 rightx
= (INT
)ceilf(point
->X
);
892 topyf
= floorf(point
->Y
);
894 bottomy
= (INT
)ceilf(point
->Y
);
896 if (leftx
== rightx
&& topy
== bottomy
)
897 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
898 leftx
, topy
, attributes
);
900 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
901 leftx
, topy
, attributes
);
902 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
903 rightx
, topy
, attributes
);
904 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
905 leftx
, bottomy
, attributes
);
906 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
907 rightx
, bottomy
, attributes
);
909 x_offset
= point
->X
- leftxf
;
910 top
= blend_colors(topleft
, topright
, x_offset
);
911 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
913 return blend_colors(top
, bottom
, point
->Y
- topyf
);
915 case InterpolationModeNearestNeighbor
:
921 case PixelOffsetModeNone
:
922 case PixelOffsetModeHighSpeed
:
926 case PixelOffsetModeHalf
:
927 case PixelOffsetModeHighQuality
:
931 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
932 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
938 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
940 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
943 static INT
brush_can_fill_path(GpBrush
*brush
)
947 case BrushTypeSolidColor
:
949 case BrushTypeHatchFill
:
951 GpHatch
*hatch
= (GpHatch
*)brush
;
952 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
953 ((hatch
->backcol
& 0xff000000) == 0xff000000);
955 case BrushTypeLinearGradient
:
956 case BrushTypeTextureFill
:
957 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
963 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
967 case BrushTypeSolidColor
:
969 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
970 HBITMAP bmp
= ARGB2BMP(fill
->color
);
975 /* partially transparent fill */
977 SelectClipPath(graphics
->hdc
, RGN_AND
);
978 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
980 HDC hdc
= CreateCompatibleDC(NULL
);
984 SelectObject(hdc
, bmp
);
985 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
993 /* else fall through */
997 HBRUSH gdibrush
, old_brush
;
999 gdibrush
= create_gdi_brush(brush
);
1000 if (!gdibrush
) return;
1002 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1003 FillPath(graphics
->hdc
);
1004 SelectObject(graphics
->hdc
, old_brush
);
1005 DeleteObject(gdibrush
);
1011 static INT
brush_can_fill_pixels(GpBrush
*brush
)
1015 case BrushTypeSolidColor
:
1016 case BrushTypeHatchFill
:
1017 case BrushTypeLinearGradient
:
1018 case BrushTypeTextureFill
:
1019 case BrushTypePathGradient
:
1026 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1027 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1031 case BrushTypeSolidColor
:
1034 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1035 for (x
=0; x
<fill_area
->Width
; x
++)
1036 for (y
=0; y
<fill_area
->Height
; y
++)
1037 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1040 case BrushTypeHatchFill
:
1043 GpHatch
*fill
= (GpHatch
*)brush
;
1044 const char *hatch_data
;
1046 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1047 return NotImplemented
;
1049 for (x
=0; x
<fill_area
->Width
; x
++)
1050 for (y
=0; y
<fill_area
->Height
; y
++)
1054 /* FIXME: Account for the rendering origin */
1055 hx
= (x
+ fill_area
->X
) % 8;
1056 hy
= (y
+ fill_area
->Y
) % 8;
1058 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1059 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1061 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1066 case BrushTypeLinearGradient
:
1068 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1069 GpPointF draw_points
[3], line_points
[3];
1071 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1072 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1075 draw_points
[0].X
= fill_area
->X
;
1076 draw_points
[0].Y
= fill_area
->Y
;
1077 draw_points
[1].X
= fill_area
->X
+1;
1078 draw_points
[1].Y
= fill_area
->Y
;
1079 draw_points
[2].X
= fill_area
->X
;
1080 draw_points
[2].Y
= fill_area
->Y
+1;
1082 /* Transform the points to a co-ordinate space where X is the point's
1083 * position in the gradient, 0.0 being the start point and 1.0 the
1085 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1086 CoordinateSpaceDevice
, draw_points
, 3);
1090 line_points
[0] = fill
->startpoint
;
1091 line_points
[1] = fill
->endpoint
;
1092 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1093 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1095 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1100 stat
= GdipInvertMatrix(world_to_gradient
);
1103 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1105 GdipDeleteMatrix(world_to_gradient
);
1110 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1111 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1113 for (y
=0; y
<fill_area
->Height
; y
++)
1115 for (x
=0; x
<fill_area
->Width
; x
++)
1117 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1119 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1126 case BrushTypeTextureFill
:
1128 GpTexture
*fill
= (GpTexture
*)brush
;
1129 GpPointF draw_points
[3];
1136 if (fill
->image
->type
!= ImageTypeBitmap
)
1138 FIXME("metafile texture brushes not implemented\n");
1139 return NotImplemented
;
1142 bitmap
= (GpBitmap
*)fill
->image
;
1143 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1145 src_area
.X
= src_area
.Y
= 0;
1146 src_area
.Width
= bitmap
->width
;
1147 src_area
.Height
= bitmap
->height
;
1149 draw_points
[0].X
= fill_area
->X
;
1150 draw_points
[0].Y
= fill_area
->Y
;
1151 draw_points
[1].X
= fill_area
->X
+1;
1152 draw_points
[1].Y
= fill_area
->Y
;
1153 draw_points
[2].X
= fill_area
->X
;
1154 draw_points
[2].Y
= fill_area
->Y
+1;
1156 /* Transform the points to the co-ordinate space of the bitmap. */
1157 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1158 CoordinateSpaceDevice
, draw_points
, 3);
1162 GpMatrix world_to_texture
= fill
->transform
;
1164 stat
= GdipInvertMatrix(&world_to_texture
);
1166 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1169 if (stat
== Ok
&& !fill
->bitmap_bits
)
1171 BitmapData lockeddata
;
1173 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1174 if (!fill
->bitmap_bits
)
1179 lockeddata
.Width
= bitmap
->width
;
1180 lockeddata
.Height
= bitmap
->height
;
1181 lockeddata
.Stride
= src_stride
;
1182 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1183 lockeddata
.Scan0
= fill
->bitmap_bits
;
1185 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1186 PixelFormat32bppARGB
, &lockeddata
);
1190 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1193 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1194 bitmap
->width
, bitmap
->height
,
1195 src_stride
, ColorAdjustTypeBitmap
);
1199 GdipFree(fill
->bitmap_bits
);
1200 fill
->bitmap_bits
= NULL
;
1206 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1207 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1208 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1209 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1211 for (y
=0; y
<fill_area
->Height
; y
++)
1213 for (x
=0; x
<fill_area
->Width
; x
++)
1216 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1217 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1219 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1220 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1221 &point
, fill
->imageattributes
, graphics
->interpolation
,
1222 graphics
->pixeloffset
);
1229 case BrushTypePathGradient
:
1231 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1233 GpMatrix world_to_device
;
1235 int i
, figure_start
=0;
1236 GpPointF start_point
, end_point
, center_point
;
1238 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1239 INT min_y
, max_y
, min_x
, max_x
;
1242 static int transform_fixme_once
;
1244 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1248 FIXME("path gradient focus not implemented\n");
1255 FIXME("path gradient gamma correction not implemented\n");
1258 if (fill
->blendcount
)
1262 FIXME("path gradient blend not implemented\n");
1265 if (fill
->pblendcount
)
1269 FIXME("path gradient preset blend not implemented\n");
1272 if (!transform_fixme_once
)
1274 BOOL is_identity
=TRUE
;
1275 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1278 FIXME("path gradient transform not implemented\n");
1279 transform_fixme_once
= 1;
1283 stat
= GdipClonePath(fill
->path
, &flat_path
);
1288 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1289 CoordinateSpaceWorld
, &world_to_device
);
1292 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1296 center_point
= fill
->center
;
1297 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1301 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1306 GdipDeletePath(flat_path
);
1310 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1312 int start_center_line
=0, end_center_line
=0;
1313 int seen_start
=0, seen_end
=0, seen_center
=0;
1314 REAL center_distance
;
1315 ARGB start_color
, end_color
;
1318 type
= flat_path
->pathdata
.Types
[i
];
1320 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1323 start_point
= flat_path
->pathdata
.Points
[i
];
1325 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1327 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1329 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1330 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1332 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1334 end_point
= flat_path
->pathdata
.Points
[i
+1];
1335 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1340 outer_color
= start_color
;
1342 min_yf
= center_point
.Y
;
1343 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1344 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1346 if (min_yf
< fill_area
->Y
)
1347 min_y
= fill_area
->Y
;
1349 min_y
= (INT
)ceil(min_yf
);
1351 max_yf
= center_point
.Y
;
1352 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1353 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1355 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1356 max_y
= fill_area
->Y
+ fill_area
->Height
;
1358 max_y
= (INT
)ceil(max_yf
);
1360 dy
= end_point
.Y
- start_point
.Y
;
1361 dx
= end_point
.X
- start_point
.X
;
1363 /* This is proportional to the distance from start-end line to center point. */
1364 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1365 dx
* (center_point
.Y
- start_point
.Y
);
1367 for (y
=min_y
; y
<max_y
; y
++)
1371 if (!seen_start
&& yf
>= start_point
.Y
)
1374 start_center_line
^= 1;
1376 if (!seen_end
&& yf
>= end_point
.Y
)
1379 end_center_line
^= 1;
1381 if (!seen_center
&& yf
>= center_point
.Y
)
1384 start_center_line
^= 1;
1385 end_center_line
^= 1;
1388 if (start_center_line
)
1389 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1391 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1393 if (end_center_line
)
1394 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1396 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1398 if (line1_xf
< line2_xf
)
1400 min_x
= (INT
)ceil(line1_xf
);
1401 max_x
= (INT
)ceil(line2_xf
);
1405 min_x
= (INT
)ceil(line2_xf
);
1406 max_x
= (INT
)ceil(line1_xf
);
1409 if (min_x
< fill_area
->X
)
1410 min_x
= fill_area
->X
;
1411 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1412 max_x
= fill_area
->X
+ fill_area
->Width
;
1414 for (x
=min_x
; x
<max_x
; x
++)
1419 if (start_color
!= end_color
)
1421 REAL blend_amount
, pdy
, pdx
;
1422 pdy
= yf
- center_point
.Y
;
1423 pdx
= xf
- center_point
.X
;
1424 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1425 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1428 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1429 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1431 distance
= distance
/ center_distance
;
1433 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1434 blend_colors(outer_color
, fill
->centercolor
, distance
);
1439 GdipDeletePath(flat_path
);
1443 return NotImplemented
;
1447 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1448 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1449 * should not be called on an hdc that has a path you care about. */
1450 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1451 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1453 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1455 HBRUSH brush
= NULL
;
1457 PointF ptf
[4], *custptf
= NULL
;
1458 POINT pt
[4], *custpt
= NULL
;
1460 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1465 if((x1
== x2
) && (y1
== y2
))
1468 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1470 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1472 brush
= CreateSolidBrush(color
);
1473 lb
.lbStyle
= BS_SOLID
;
1476 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1477 PS_JOIN_MITER
, 1, &lb
, 0,
1479 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1480 oldpen
= SelectObject(graphics
->hdc
, pen
);
1487 case LineCapSquareAnchor
:
1488 case LineCapDiamondAnchor
:
1489 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1490 if(cap
== LineCapDiamondAnchor
){
1491 dsmall
= cos(theta
+ M_PI_2
) * size
;
1492 dbig
= sin(theta
+ M_PI_2
) * size
;
1495 dsmall
= cos(theta
+ M_PI_4
) * size
;
1496 dbig
= sin(theta
+ M_PI_4
) * size
;
1499 ptf
[0].X
= x2
- dsmall
;
1500 ptf
[1].X
= x2
+ dbig
;
1502 ptf
[0].Y
= y2
- dbig
;
1503 ptf
[3].Y
= y2
+ dsmall
;
1505 ptf
[1].Y
= y2
- dsmall
;
1506 ptf
[2].Y
= y2
+ dbig
;
1508 ptf
[3].X
= x2
- dbig
;
1509 ptf
[2].X
= x2
+ dsmall
;
1511 transform_and_round_points(graphics
, pt
, ptf
, 4);
1512 Polygon(graphics
->hdc
, pt
, 4);
1515 case LineCapArrowAnchor
:
1516 size
= size
* 4.0 / sqrt(3.0);
1518 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1519 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1524 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1525 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1533 transform_and_round_points(graphics
, pt
, ptf
, 3);
1534 Polygon(graphics
->hdc
, pt
, 3);
1537 case LineCapRoundAnchor
:
1538 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1545 transform_and_round_points(graphics
, pt
, ptf
, 2);
1546 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1549 case LineCapTriangle
:
1551 dx
= cos(M_PI_2
+ theta
) * size
;
1552 dy
= sin(M_PI_2
+ theta
) * size
;
1559 dx
= cos(theta
) * size
;
1560 dy
= sin(theta
) * size
;
1565 transform_and_round_points(graphics
, pt
, ptf
, 3);
1566 Polygon(graphics
->hdc
, pt
, 3);
1570 dx
= dy
= size
/ 2.0;
1577 dx
= -cos(M_PI_2
+ theta
) * size
;
1578 dy
= -sin(M_PI_2
+ theta
) * size
;
1585 transform_and_round_points(graphics
, pt
, ptf
, 4);
1586 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1587 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1594 count
= custom
->pathdata
.Count
;
1595 custptf
= GdipAlloc(count
* sizeof(PointF
));
1596 custpt
= GdipAlloc(count
* sizeof(POINT
));
1597 tp
= GdipAlloc(count
);
1599 if(!custptf
|| !custpt
|| !tp
)
1602 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1604 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1605 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1606 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1608 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1609 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1611 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1613 for(i
= 0; i
< count
; i
++)
1614 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1617 BeginPath(graphics
->hdc
);
1618 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1619 EndPath(graphics
->hdc
);
1620 StrokeAndFillPath(graphics
->hdc
);
1623 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1635 SelectObject(graphics
->hdc
, oldbrush
);
1636 SelectObject(graphics
->hdc
, oldpen
);
1637 DeleteObject(brush
);
1642 /* Shortens the line by the given percent by changing x2, y2.
1643 * If percent is > 1.0 then the line will change direction.
1644 * If percent is negative it can lengthen the line. */
1645 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1647 REAL dist
, theta
, dx
, dy
;
1649 if((y1
== *y2
) && (x1
== *x2
))
1652 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1653 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1654 dx
= cos(theta
) * dist
;
1655 dy
= sin(theta
) * dist
;
1661 /* Shortens the line by the given amount by changing x2, y2.
1662 * If the amount is greater than the distance, the line will become length 0.
1663 * If the amount is negative, it can lengthen the line. */
1664 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1666 REAL dx
, dy
, percent
;
1670 if(dx
== 0 && dy
== 0)
1673 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1680 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1683 /* Conducts a linear search to find the bezier points that will back off
1684 * the endpoint of the curve by a distance of amt. Linear search works
1685 * better than binary in this case because there are multiple solutions,
1686 * and binary searches often find a bad one. I don't think this is what
1687 * Windows does but short of rendering the bezier without GDI's help it's
1688 * the best we can do. If rev then work from the start of the passed points
1689 * instead of the end. */
1690 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1693 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1694 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1703 origx
= pt
[fourth
].X
;
1704 origy
= pt
[fourth
].Y
;
1705 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1707 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1708 /* reset bezier points to original values */
1709 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1710 /* Perform magic on bezier points. Order is important here.*/
1711 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1712 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1713 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1714 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1715 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1716 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1718 dx
= pt
[fourth
].X
- origx
;
1719 dy
= pt
[fourth
].Y
- origy
;
1721 diff
= sqrt(dx
* dx
+ dy
* dy
);
1722 percent
+= 0.0005 * amt
;
1726 /* Draws a combination of bezier curves and lines between points. */
1727 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1728 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1730 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1731 BYTE
*tp
= GdipAlloc(count
);
1732 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1734 GpStatus status
= GenericError
;
1740 if(!pti
|| !tp
|| !ptcopy
){
1741 status
= OutOfMemory
;
1745 for(i
= 1; i
< count
; i
++){
1746 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1747 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1748 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1749 ERR("Bad bezier points\n");
1756 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1758 /* If we are drawing caps, go through the points and adjust them accordingly,
1759 * and draw the caps. */
1761 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1762 case PathPointTypeBezier
:
1763 if(pen
->endcap
== LineCapArrowAnchor
)
1764 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1765 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1766 shorten_bezier_amt(&ptcopy
[count
- 4],
1767 pen
->width
* pen
->customend
->inset
, FALSE
);
1769 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1770 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1771 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1772 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1775 case PathPointTypeLine
:
1776 if(pen
->endcap
== LineCapArrowAnchor
)
1777 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1778 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1780 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1781 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1782 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1783 pen
->customend
->inset
* pen
->width
);
1785 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1786 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1791 ERR("Bad path last point\n");
1795 /* Find start of points */
1796 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1797 == PathPointTypeStart
); j
++);
1799 switch(types
[j
] & PathPointTypePathTypeMask
){
1800 case PathPointTypeBezier
:
1801 if(pen
->startcap
== LineCapArrowAnchor
)
1802 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1803 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1804 shorten_bezier_amt(&ptcopy
[j
- 1],
1805 pen
->width
* pen
->customstart
->inset
, TRUE
);
1807 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1808 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1809 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1810 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1813 case PathPointTypeLine
:
1814 if(pen
->startcap
== LineCapArrowAnchor
)
1815 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1816 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1818 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1819 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1820 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1821 pen
->customstart
->inset
* pen
->width
);
1823 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1824 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1829 ERR("Bad path points\n");
1834 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1836 for(i
= 0; i
< count
; i
++){
1837 tp
[i
] = convert_path_point_type(types
[i
]);
1840 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1852 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1856 BeginPath(graphics
->hdc
);
1857 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1858 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1859 EndPath(graphics
->hdc
);
1863 typedef struct _GraphicsContainerItem
{
1865 GraphicsContainer contid
;
1867 SmoothingMode smoothing
;
1868 CompositingQuality compqual
;
1869 InterpolationMode interpolation
;
1870 CompositingMode compmode
;
1871 TextRenderingHint texthint
;
1874 PixelOffsetMode pixeloffset
;
1876 GpMatrix worldtrans
;
1878 INT origin_x
, origin_y
;
1879 } GraphicsContainerItem
;
1881 static GpStatus
init_container(GraphicsContainerItem
** container
,
1882 GDIPCONST GpGraphics
* graphics
){
1885 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1889 (*container
)->contid
= graphics
->contid
+ 1;
1891 (*container
)->smoothing
= graphics
->smoothing
;
1892 (*container
)->compqual
= graphics
->compqual
;
1893 (*container
)->interpolation
= graphics
->interpolation
;
1894 (*container
)->compmode
= graphics
->compmode
;
1895 (*container
)->texthint
= graphics
->texthint
;
1896 (*container
)->scale
= graphics
->scale
;
1897 (*container
)->unit
= graphics
->unit
;
1898 (*container
)->textcontrast
= graphics
->textcontrast
;
1899 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1900 (*container
)->origin_x
= graphics
->origin_x
;
1901 (*container
)->origin_y
= graphics
->origin_y
;
1902 (*container
)->worldtrans
= graphics
->worldtrans
;
1904 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1906 GdipFree(*container
);
1914 static void delete_container(GraphicsContainerItem
* container
)
1916 GdipDeleteRegion(container
->clip
);
1917 GdipFree(container
);
1920 static GpStatus
restore_container(GpGraphics
* graphics
,
1921 GDIPCONST GraphicsContainerItem
* container
){
1925 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1926 if(sts
!= Ok
) return sts
;
1928 graphics
->worldtrans
= container
->worldtrans
;
1930 GdipDeleteRegion(graphics
->clip
);
1931 graphics
->clip
= newClip
;
1933 graphics
->contid
= container
->contid
- 1;
1935 graphics
->smoothing
= container
->smoothing
;
1936 graphics
->compqual
= container
->compqual
;
1937 graphics
->interpolation
= container
->interpolation
;
1938 graphics
->compmode
= container
->compmode
;
1939 graphics
->texthint
= container
->texthint
;
1940 graphics
->scale
= container
->scale
;
1941 graphics
->unit
= container
->unit
;
1942 graphics
->textcontrast
= container
->textcontrast
;
1943 graphics
->pixeloffset
= container
->pixeloffset
;
1944 graphics
->origin_x
= container
->origin_x
;
1945 graphics
->origin_y
= container
->origin_y
;
1950 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1956 if(graphics
->hwnd
) {
1957 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1958 return GenericError
;
1960 rect
->X
= wnd_rect
.left
;
1961 rect
->Y
= wnd_rect
.top
;
1962 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1963 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1964 }else if (graphics
->image
){
1965 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1966 if (stat
== Ok
&& unit
!= UnitPixel
)
1967 FIXME("need to convert from unit %i\n", unit
);
1968 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
1975 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
1976 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
1978 rect
->Width
= bmp
.bmWidth
;
1979 rect
->Height
= bmp
.bmHeight
;
1990 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1991 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
1997 /* on success, rgn will contain the region of the graphics object which
1998 * is visible after clipping has been applied */
1999 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2005 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2008 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2011 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2014 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2017 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2020 GdipDeleteRegion(tmp
);
2024 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2028 if (font
->unit
== UnitPixel
)
2030 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2034 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2035 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2037 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2040 lf
->lfHeight
= -(height
+ 0.5);
2042 lf
->lfEscapement
= 0;
2043 lf
->lfOrientation
= 0;
2044 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2045 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2046 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2047 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2048 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2049 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2050 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2051 lf
->lfQuality
= DEFAULT_QUALITY
;
2052 lf
->lfPitchAndFamily
= 0;
2053 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2056 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2057 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2058 GDIPCONST GpMatrix
*matrix
)
2060 HDC hdc
= CreateCompatibleDC(0);
2062 REAL angle
, rel_width
, rel_height
, font_height
;
2064 HFONT unscaled_font
;
2065 TEXTMETRICW textmet
;
2067 if (font
->unit
== UnitPixel
)
2068 font_height
= font
->emSize
;
2071 REAL unit_scale
, res
;
2073 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2074 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2076 font_height
= font
->emSize
* unit_scale
;
2087 GpMatrix xform
= *matrix
;
2088 GdipTransformMatrixPoints(&xform
, pt
, 3);
2091 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2092 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2093 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2094 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2095 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2096 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2098 get_log_fontW(font
, graphics
, &lfw
);
2099 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2100 unscaled_font
= CreateFontIndirectW(&lfw
);
2102 SelectObject(hdc
, unscaled_font
);
2103 GetTextMetricsW(hdc
, &textmet
);
2105 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2106 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2108 *hfont
= CreateFontIndirectW(&lfw
);
2111 DeleteObject(unscaled_font
);
2114 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2116 TRACE("(%p, %p)\n", hdc
, graphics
);
2118 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2121 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2127 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2130 FIXME("Don't know how to handle parameter hDevice\n");
2135 if(graphics
== NULL
)
2136 return InvalidParameter
;
2138 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2139 if(!*graphics
) return OutOfMemory
;
2141 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2143 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2144 GdipFree(*graphics
);
2148 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2149 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2150 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2152 (*graphics
)->alpha_hdc
= 1;
2155 (*graphics
)->hdc
= hdc
;
2156 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2157 (*graphics
)->owndc
= FALSE
;
2158 (*graphics
)->smoothing
= SmoothingModeDefault
;
2159 (*graphics
)->compqual
= CompositingQualityDefault
;
2160 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2161 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2162 (*graphics
)->compmode
= CompositingModeSourceOver
;
2163 (*graphics
)->unit
= UnitDisplay
;
2164 (*graphics
)->scale
= 1.0;
2165 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2166 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2167 (*graphics
)->busy
= FALSE
;
2168 (*graphics
)->textcontrast
= 4;
2169 list_init(&(*graphics
)->containers
);
2170 (*graphics
)->contid
= GDIP_GET_NEW_CONTID_FOR(*graphics
);
2172 TRACE("<-- %p\n", *graphics
);
2177 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2181 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2182 if(!*graphics
) return OutOfMemory
;
2184 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2186 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2187 GdipFree(*graphics
);
2191 (*graphics
)->hdc
= NULL
;
2192 (*graphics
)->hwnd
= NULL
;
2193 (*graphics
)->owndc
= FALSE
;
2194 (*graphics
)->image
= image
;
2195 /* We have to store the image type here because the image may be freed
2196 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2197 (*graphics
)->image_type
= image
->type
;
2198 (*graphics
)->smoothing
= SmoothingModeDefault
;
2199 (*graphics
)->compqual
= CompositingQualityDefault
;
2200 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2201 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2202 (*graphics
)->compmode
= CompositingModeSourceOver
;
2203 (*graphics
)->unit
= UnitDisplay
;
2204 (*graphics
)->scale
= 1.0;
2205 (*graphics
)->xres
= image
->xres
;
2206 (*graphics
)->yres
= image
->yres
;
2207 (*graphics
)->busy
= FALSE
;
2208 (*graphics
)->textcontrast
= 4;
2209 list_init(&(*graphics
)->containers
);
2210 (*graphics
)->contid
= GDIP_GET_NEW_CONTID_FOR(*graphics
);
2212 TRACE("<-- %p\n", *graphics
);
2217 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2222 TRACE("(%p, %p)\n", hwnd
, graphics
);
2226 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2228 ReleaseDC(hwnd
, hdc
);
2232 (*graphics
)->hwnd
= hwnd
;
2233 (*graphics
)->owndc
= TRUE
;
2238 /* FIXME: no icm handling */
2239 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2241 TRACE("(%p, %p)\n", hwnd
, graphics
);
2243 return GdipCreateFromHWND(hwnd
, graphics
);
2246 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2247 GpMetafile
**metafile
)
2249 ENHMETAHEADER header
;
2250 MetafileType metafile_type
;
2252 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2254 if(!hemf
|| !metafile
)
2255 return InvalidParameter
;
2257 if (GetEnhMetaFileHeader(hemf
, sizeof(header
), &header
) == 0)
2258 return GenericError
;
2260 metafile_type
= METAFILE_GetEmfType(hemf
);
2262 if (metafile_type
== MetafileTypeInvalid
)
2263 return GenericError
;
2265 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2269 (*metafile
)->image
.type
= ImageTypeMetafile
;
2270 (*metafile
)->image
.format
= ImageFormatEMF
;
2271 (*metafile
)->image
.frame_count
= 1;
2272 (*metafile
)->image
.xres
= (REAL
)header
.szlDevice
.cx
;
2273 (*metafile
)->image
.yres
= (REAL
)header
.szlDevice
.cy
;
2274 (*metafile
)->bounds
.X
= (REAL
)header
.rclBounds
.left
;
2275 (*metafile
)->bounds
.Y
= (REAL
)header
.rclBounds
.top
;
2276 (*metafile
)->bounds
.Width
= (REAL
)(header
.rclBounds
.right
- header
.rclBounds
.left
);
2277 (*metafile
)->bounds
.Height
= (REAL
)(header
.rclBounds
.bottom
- header
.rclBounds
.top
);
2278 (*metafile
)->unit
= UnitPixel
;
2279 (*metafile
)->metafile_type
= metafile_type
;
2280 (*metafile
)->hemf
= hemf
;
2281 (*metafile
)->preserve_hemf
= !delete;
2283 TRACE("<-- %p\n", *metafile
);
2288 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2289 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2294 GpStatus retval
= Ok
;
2296 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2298 if(!hwmf
|| !metafile
|| !placeable
)
2299 return InvalidParameter
;
2302 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2304 return GenericError
;
2305 copy
= GdipAlloc(read
);
2306 GetMetaFileBitsEx(hwmf
, read
, copy
);
2308 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2311 /* FIXME: We should store and use hwmf instead of converting to hemf */
2312 retval
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
2316 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2317 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2318 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2319 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2320 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2321 placeable
->BoundingBox
.Left
);
2322 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2323 placeable
->BoundingBox
.Top
);
2324 (*metafile
)->metafile_type
= MetafileTypeWmfPlaceable
;
2325 (*metafile
)->image
.format
= ImageFormatWMF
;
2327 if (delete) DeleteMetaFile(hwmf
);
2330 DeleteEnhMetaFile(hemf
);
2334 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2335 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2337 HMETAFILE hmf
= GetMetaFileW(file
);
2339 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2341 if(!hmf
) return InvalidParameter
;
2343 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2346 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2347 GpMetafile
**metafile
)
2349 FIXME("(%p, %p): stub\n", file
, metafile
);
2350 return NotImplemented
;
2353 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2354 GpMetafile
**metafile
)
2356 FIXME("(%p, %p): stub\n", stream
, metafile
);
2357 return NotImplemented
;
2360 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2361 UINT access
, IStream
**stream
)
2366 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2368 if(!stream
|| !filename
)
2369 return InvalidParameter
;
2371 if(access
& GENERIC_WRITE
)
2372 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2373 else if(access
& GENERIC_READ
)
2374 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2376 return InvalidParameter
;
2378 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2380 return hresult_to_status(ret
);
2383 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2385 GraphicsContainerItem
*cont
, *next
;
2387 TRACE("(%p)\n", graphics
);
2389 if(!graphics
) return InvalidParameter
;
2390 if(graphics
->busy
) return ObjectBusy
;
2392 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2394 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2400 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2402 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2403 list_remove(&cont
->entry
);
2404 delete_container(cont
);
2407 GdipDeleteRegion(graphics
->clip
);
2413 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2414 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2419 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2420 width
, height
, startAngle
, sweepAngle
);
2422 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2423 return InvalidParameter
;
2428 status
= GdipCreatePath(FillModeAlternate
, &path
);
2429 if (status
!= Ok
) return status
;
2431 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2433 status
= GdipDrawPath(graphics
, pen
, path
);
2435 GdipDeletePath(path
);
2439 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2440 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2442 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2443 width
, height
, startAngle
, sweepAngle
);
2445 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2448 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2449 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2453 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2454 x2
, y2
, x3
, y3
, x4
, y4
);
2456 if(!graphics
|| !pen
)
2457 return InvalidParameter
;
2470 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2473 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2474 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2476 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2477 x2
, y2
, x3
, y3
, x4
, y4
);
2479 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2482 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2483 GDIPCONST GpPointF
*points
, INT count
)
2488 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2490 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2491 return InvalidParameter
;
2496 status
= GdipCreatePath(FillModeAlternate
, &path
);
2497 if (status
!= Ok
) return status
;
2499 status
= GdipAddPathBeziers(path
, points
, count
);
2501 status
= GdipDrawPath(graphics
, pen
, path
);
2503 GdipDeletePath(path
);
2507 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2508 GDIPCONST GpPoint
*points
, INT count
)
2514 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2516 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2517 return InvalidParameter
;
2522 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2526 for(i
= 0; i
< count
; i
++){
2527 pts
[i
].X
= (REAL
)points
[i
].X
;
2528 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2531 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2538 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2539 GDIPCONST GpPointF
*points
, INT count
)
2541 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2543 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2546 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2547 GDIPCONST GpPoint
*points
, INT count
)
2549 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2551 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2554 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2555 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2560 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2562 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2563 return InvalidParameter
;
2568 status
= GdipCreatePath(FillModeAlternate
, &path
);
2569 if (status
!= Ok
) return status
;
2571 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2573 status
= GdipDrawPath(graphics
, pen
, path
);
2575 GdipDeletePath(path
);
2580 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2581 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2587 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2589 if(!points
|| count
<= 0)
2590 return InvalidParameter
;
2592 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2596 for(i
= 0; i
< count
; i
++){
2597 ptf
[i
].X
= (REAL
)points
[i
].X
;
2598 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2601 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2608 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2609 GDIPCONST GpPointF
*points
, INT count
)
2611 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2613 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2616 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2617 GDIPCONST GpPoint
*points
, INT count
)
2623 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2626 return InvalidParameter
;
2628 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2632 for(i
= 0; i
< count
; i
++){
2633 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2634 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2637 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2643 /* Approximates cardinal spline with Bezier curves. */
2644 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2645 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2650 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2652 if(!graphics
|| !pen
)
2653 return InvalidParameter
;
2659 return InvalidParameter
;
2661 status
= GdipCreatePath(FillModeAlternate
, &path
);
2662 if (status
!= Ok
) return status
;
2664 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2666 status
= GdipDrawPath(graphics
, pen
, path
);
2668 GdipDeletePath(path
);
2672 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2673 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2679 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2682 return InvalidParameter
;
2684 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2688 for(i
= 0; i
< count
; i
++){
2689 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2690 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2693 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2699 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2700 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2703 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2705 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2706 return InvalidParameter
;
2709 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2712 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2713 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2716 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2722 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2723 return InvalidParameter
;
2726 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2729 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2730 REAL y
, REAL width
, REAL height
)
2735 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2737 if(!graphics
|| !pen
)
2738 return InvalidParameter
;
2743 status
= GdipCreatePath(FillModeAlternate
, &path
);
2744 if (status
!= Ok
) return status
;
2746 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2748 status
= GdipDrawPath(graphics
, pen
, path
);
2750 GdipDeletePath(path
);
2754 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2755 INT y
, INT width
, INT height
)
2757 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2759 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2763 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2767 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2769 if(!graphics
|| !image
)
2770 return InvalidParameter
;
2772 GdipGetImageWidth(image
, &width
);
2773 GdipGetImageHeight(image
, &height
);
2775 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2776 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2779 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2782 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2784 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2787 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2788 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2792 REAL scale_x
, scale_y
, width
, height
;
2794 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2796 if (!graphics
|| !image
) return InvalidParameter
;
2798 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2799 scale_x
*= graphics
->xres
/ image
->xres
;
2800 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2801 scale_y
*= graphics
->yres
/ image
->yres
;
2802 width
= srcwidth
* scale_x
;
2803 height
= srcheight
* scale_y
;
2805 points
[0].X
= points
[2].X
= x
;
2806 points
[0].Y
= points
[1].Y
= y
;
2807 points
[1].X
= x
+ width
;
2808 points
[2].Y
= y
+ height
;
2810 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2811 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2814 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2815 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2818 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2821 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2822 GDIPCONST GpPointF
*dstpoints
, INT count
)
2826 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2829 return InvalidParameter
;
2831 GdipGetImageWidth(image
, &width
);
2832 GdipGetImageHeight(image
, &height
);
2834 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2835 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2838 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2839 GDIPCONST GpPoint
*dstpoints
, INT count
)
2843 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2845 if (count
!= 3 || !dstpoints
)
2846 return InvalidParameter
;
2848 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2849 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2850 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2851 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2852 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2853 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2855 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2858 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2859 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2861 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2865 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2866 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2867 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2868 DrawImageAbort callback
, VOID
* callbackData
)
2874 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2875 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2879 return NotImplemented
;
2881 if(!graphics
|| !image
|| !points
|| count
!= 3)
2882 return InvalidParameter
;
2884 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2885 debugstr_pointf(&points
[2]));
2887 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2888 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2889 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2890 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
2892 transform_and_round_points(graphics
, pti
, ptf
, 4);
2894 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2895 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2897 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2898 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2899 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2900 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2901 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2907 FIXME("graphics object has no HDC\n");
2910 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2911 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2912 srcx
, srcy
, srcwidth
, srcheight
, NULL
) != S_OK
)
2915 callback(callbackData
);
2916 return GenericError
;
2919 else if (image
->type
== ImageTypeBitmap
)
2921 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2924 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2925 graphics
->xres
, graphics
->yres
,
2926 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2927 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2928 imageAttributes
? imageAttributes
->outside_color
: 0);
2930 if (imageAttributes
|| graphics
->alpha_hdc
||
2931 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2932 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2933 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2934 srcx
< 0 || srcy
< 0 ||
2935 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2942 int i
, x
, y
, src_stride
, dst_stride
;
2943 GpMatrix dst_to_src
;
2944 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2945 LPBYTE src_data
, dst_data
;
2946 BitmapData lockeddata
;
2947 InterpolationMode interpolation
= graphics
->interpolation
;
2948 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2949 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2950 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2951 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2953 if (!imageAttributes
)
2954 imageAttributes
= &defaultImageAttributes
;
2956 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2957 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2960 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2961 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2962 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2963 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2966 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
2968 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2969 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2970 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2971 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2972 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2973 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2975 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
2977 stat
= GdipInvertMatrix(&dst_to_src
);
2978 if (stat
!= Ok
) return stat
;
2980 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2981 if (!dst_data
) return OutOfMemory
;
2983 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2985 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2986 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2988 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
2990 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
2996 src_stride
= sizeof(ARGB
) * src_area
.Width
;
2998 /* Read the bits we need from the source bitmap into an ARGB buffer. */
2999 lockeddata
.Width
= src_area
.Width
;
3000 lockeddata
.Height
= src_area
.Height
;
3001 lockeddata
.Stride
= src_stride
;
3002 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3003 lockeddata
.Scan0
= src_data
;
3005 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3006 PixelFormat32bppARGB
, &lockeddata
);
3009 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3013 if (src_data
!= dst_data
)
3019 apply_image_attributes(imageAttributes
, src_data
,
3020 src_area
.Width
, src_area
.Height
,
3021 src_stride
, ColorAdjustTypeBitmap
);
3023 /* Transform the bits as needed to the destination. */
3024 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3026 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3027 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3028 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3029 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3031 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3033 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3035 GpPointF src_pointf
;
3038 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3039 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3041 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3043 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3044 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3045 imageAttributes
, interpolation
, offset_mode
);
3053 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3054 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3063 int temp_hdc
=0, temp_bitmap
=0;
3064 HBITMAP hbitmap
, old_hbm
=NULL
;
3066 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3067 bitmap
->format
== PixelFormat24bppRGB
||
3068 bitmap
->format
== PixelFormat32bppRGB
||
3069 bitmap
->format
== PixelFormat32bppPARGB
))
3071 BITMAPINFOHEADER bih
;
3073 PixelFormat dst_format
;
3075 /* we can't draw a bitmap of this format directly */
3076 hdc
= CreateCompatibleDC(0);
3080 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3081 bih
.biWidth
= bitmap
->width
;
3082 bih
.biHeight
= -bitmap
->height
;
3084 bih
.biBitCount
= 32;
3085 bih
.biCompression
= BI_RGB
;
3086 bih
.biSizeImage
= 0;
3087 bih
.biXPelsPerMeter
= 0;
3088 bih
.biYPelsPerMeter
= 0;
3090 bih
.biClrImportant
= 0;
3092 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3093 (void**)&temp_bits
, NULL
, 0);
3095 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3096 dst_format
= PixelFormat32bppPARGB
;
3098 dst_format
= PixelFormat32bppRGB
;
3100 convert_pixels(bitmap
->width
, bitmap
->height
,
3101 bitmap
->width
*4, temp_bits
, dst_format
,
3102 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3103 bitmap
->image
.palette
);
3107 if (bitmap
->hbitmap
)
3108 hbitmap
= bitmap
->hbitmap
;
3111 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3116 temp_hdc
= (hdc
== 0);
3121 if (!hdc
) hdc
= CreateCompatibleDC(0);
3122 old_hbm
= SelectObject(hdc
, hbitmap
);
3125 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3127 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3128 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3132 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3133 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3138 SelectObject(hdc
, old_hbm
);
3143 DeleteObject(hbitmap
);
3146 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3152 rc
.Width
= srcwidth
;
3153 rc
.Height
= srcheight
;
3155 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3156 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3160 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3161 return InvalidParameter
;
3167 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3168 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3169 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3170 DrawImageAbort callback
, VOID
* callbackData
)
3172 GpPointF pointsF
[3];
3175 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3176 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3179 if(!points
|| count
!=3)
3180 return InvalidParameter
;
3182 for(i
= 0; i
< count
; i
++){
3183 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3184 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3187 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3188 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3189 callback
, callbackData
);
3192 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3193 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3194 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3195 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3196 VOID
* callbackData
)
3200 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3201 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3202 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3206 points
[1].X
= dstx
+ dstwidth
;
3209 points
[2].Y
= dsty
+ dstheight
;
3211 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3212 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3215 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3216 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3217 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3218 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3219 VOID
* callbackData
)
3223 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3224 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3225 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3229 points
[1].X
= dstx
+ dstwidth
;
3232 points
[2].Y
= dsty
+ dstheight
;
3234 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3235 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3238 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3239 REAL x
, REAL y
, REAL width
, REAL height
)
3245 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3247 if(!graphics
|| !image
)
3248 return InvalidParameter
;
3250 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3254 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3255 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3256 unit
, NULL
, NULL
, NULL
);
3259 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3260 INT x
, INT y
, INT width
, INT height
)
3262 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3264 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3267 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3268 REAL y1
, REAL x2
, REAL y2
)
3272 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3278 return GdipDrawLines(graphics
, pen
, pt
, 2);
3281 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3282 INT y1
, INT x2
, INT y2
)
3284 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3286 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3289 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3290 GpPointF
*points
, INT count
)
3295 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3297 if(!pen
|| !graphics
|| (count
< 2))
3298 return InvalidParameter
;
3303 status
= GdipCreatePath(FillModeAlternate
, &path
);
3304 if (status
!= Ok
) return status
;
3306 status
= GdipAddPathLine2(path
, points
, count
);
3308 status
= GdipDrawPath(graphics
, pen
, path
);
3310 GdipDeletePath(path
);
3314 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3315 GpPoint
*points
, INT count
)
3321 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3323 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3324 if(!ptf
) return OutOfMemory
;
3326 for(i
= 0; i
< count
; i
++){
3327 ptf
[i
].X
= (REAL
) points
[i
].X
;
3328 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3331 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3337 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3342 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3344 if(!pen
|| !graphics
)
3345 return InvalidParameter
;
3352 FIXME("graphics object has no HDC\n");
3356 save_state
= prepare_dc(graphics
, pen
);
3358 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3359 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3361 restore_dc(graphics
, save_state
);
3366 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3367 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3372 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3373 width
, height
, startAngle
, sweepAngle
);
3375 if(!graphics
|| !pen
)
3376 return InvalidParameter
;
3381 status
= GdipCreatePath(FillModeAlternate
, &path
);
3382 if (status
!= Ok
) return status
;
3384 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3386 status
= GdipDrawPath(graphics
, pen
, path
);
3388 GdipDeletePath(path
);
3392 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3393 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3395 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3396 width
, height
, startAngle
, sweepAngle
);
3398 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3401 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3402 REAL y
, REAL width
, REAL height
)
3407 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3409 if(!pen
|| !graphics
)
3410 return InvalidParameter
;
3415 status
= GdipCreatePath(FillModeAlternate
, &path
);
3416 if (status
!= Ok
) return status
;
3418 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3420 status
= GdipDrawPath(graphics
, pen
, path
);
3422 GdipDeletePath(path
);
3426 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3427 INT y
, INT width
, INT height
)
3429 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3431 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3434 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3435 GDIPCONST GpRectF
* rects
, INT count
)
3440 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3442 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3443 return InvalidParameter
;
3448 status
= GdipCreatePath(FillModeAlternate
, &path
);
3449 if (status
!= Ok
) return status
;
3451 status
= GdipAddPathRectangles(path
, rects
, count
);
3453 status
= GdipDrawPath(graphics
, pen
, path
);
3455 GdipDeletePath(path
);
3459 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3460 GDIPCONST GpRect
* rects
, INT count
)
3466 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3468 if(!rects
|| count
<=0)
3469 return InvalidParameter
;
3471 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3475 for(i
= 0;i
< count
;i
++){
3476 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3477 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3478 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3479 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3482 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3488 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3489 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3494 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3495 count
, tension
, fill
);
3497 if(!graphics
|| !brush
|| !points
)
3498 return InvalidParameter
;
3503 if(count
== 1) /* Do nothing */
3506 status
= GdipCreatePath(fill
, &path
);
3507 if (status
!= Ok
) return status
;
3509 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3511 status
= GdipFillPath(graphics
, brush
, path
);
3513 GdipDeletePath(path
);
3517 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3518 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3524 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3525 count
, tension
, fill
);
3527 if(!points
|| count
== 0)
3528 return InvalidParameter
;
3530 if(count
== 1) /* Do nothing */
3533 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3537 for(i
= 0;i
< count
;i
++){
3538 ptf
[i
].X
= (REAL
)points
[i
].X
;
3539 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3542 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3549 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3550 GDIPCONST GpPointF
*points
, INT count
)
3552 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3553 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3554 0.5f
, FillModeAlternate
);
3557 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3558 GDIPCONST GpPoint
*points
, INT count
)
3560 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3561 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3562 0.5f
, FillModeAlternate
);
3565 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3566 REAL y
, REAL width
, REAL height
)
3571 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3573 if(!graphics
|| !brush
)
3574 return InvalidParameter
;
3579 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3583 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3586 stat
= GdipFillPath(graphics
, brush
, path
);
3588 GdipDeletePath(path
);
3594 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3595 INT y
, INT width
, INT height
)
3597 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3599 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3602 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3607 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3608 return NotImplemented
;
3610 save_state
= SaveDC(graphics
->hdc
);
3611 EndPath(graphics
->hdc
);
3612 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3615 BeginPath(graphics
->hdc
);
3616 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3617 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3622 EndPath(graphics
->hdc
);
3623 brush_fill_path(graphics
, brush
);
3628 RestoreDC(graphics
->hdc
, save_state
);
3633 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3638 if (!brush_can_fill_pixels(brush
))
3639 return NotImplemented
;
3641 /* FIXME: This could probably be done more efficiently without regions. */
3643 stat
= GdipCreateRegionPath(path
, &rgn
);
3647 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3649 GdipDeleteRegion(rgn
);
3655 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3657 GpStatus stat
= NotImplemented
;
3659 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3661 if(!brush
|| !graphics
|| !path
)
3662 return InvalidParameter
;
3667 if (!graphics
->image
&& !graphics
->alpha_hdc
)
3668 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3670 if (stat
== NotImplemented
)
3671 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3673 if (stat
== NotImplemented
)
3675 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3682 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3683 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3688 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3689 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3691 if(!graphics
|| !brush
)
3692 return InvalidParameter
;
3697 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3701 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3704 stat
= GdipFillPath(graphics
, brush
, path
);
3706 GdipDeletePath(path
);
3712 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3713 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3715 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3716 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3718 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3721 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3722 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3727 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3729 if(!graphics
|| !brush
|| !points
|| !count
)
3730 return InvalidParameter
;
3735 stat
= GdipCreatePath(fillMode
, &path
);
3739 stat
= GdipAddPathPolygon(path
, points
, count
);
3742 stat
= GdipFillPath(graphics
, brush
, path
);
3744 GdipDeletePath(path
);
3750 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3751 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3756 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3758 if(!graphics
|| !brush
|| !points
|| !count
)
3759 return InvalidParameter
;
3764 stat
= GdipCreatePath(fillMode
, &path
);
3768 stat
= GdipAddPathPolygonI(path
, points
, count
);
3771 stat
= GdipFillPath(graphics
, brush
, path
);
3773 GdipDeletePath(path
);
3779 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3780 GDIPCONST GpPointF
*points
, INT count
)
3782 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3784 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3787 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3788 GDIPCONST GpPoint
*points
, INT count
)
3790 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3792 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3795 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3796 REAL x
, REAL y
, REAL width
, REAL height
)
3801 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3803 if(!graphics
|| !brush
)
3804 return InvalidParameter
;
3809 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3813 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3816 stat
= GdipFillPath(graphics
, brush
, path
);
3818 GdipDeletePath(path
);
3824 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3825 INT x
, INT y
, INT width
, INT height
)
3827 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3829 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
3832 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3838 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3841 return InvalidParameter
;
3843 status
= GdipCreatePath(FillModeAlternate
, &path
);
3844 if (status
!= Ok
) return status
;
3846 status
= GdipAddPathRectangles(path
, rects
, count
);
3848 status
= GdipFillPath(graphics
, brush
, path
);
3850 GdipDeletePath(path
);
3854 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3861 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3863 if(!rects
|| count
<= 0)
3864 return InvalidParameter
;
3866 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3870 for(i
= 0; i
< count
; i
++){
3871 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3872 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3873 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3874 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3877 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3883 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3891 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3892 return NotImplemented
;
3894 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3898 save_state
= SaveDC(graphics
->hdc
);
3899 EndPath(graphics
->hdc
);
3901 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3903 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3905 BeginPath(graphics
->hdc
);
3906 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3907 EndPath(graphics
->hdc
);
3909 brush_fill_path(graphics
, brush
);
3912 RestoreDC(graphics
->hdc
, save_state
);
3919 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3923 GpRegion
*temp_region
;
3924 GpMatrix world_to_device
;
3925 GpRectF graphics_bounds
;
3929 GpRect gp_bound_rect
;
3931 if (!brush_can_fill_pixels(brush
))
3932 return NotImplemented
;
3934 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3937 stat
= GdipCloneRegion(region
, &temp_region
);
3941 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3942 CoordinateSpaceWorld
, &world_to_device
);
3945 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
3948 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
3951 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
3953 GdipDeleteRegion(temp_region
);
3956 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
3958 DeleteObject(hregion
);
3964 gp_bound_rect
.X
= bound_rect
.left
;
3965 gp_bound_rect
.Y
= bound_rect
.top
;
3966 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
3967 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
3969 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
3975 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
3976 &gp_bound_rect
, gp_bound_rect
.Width
);
3979 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
3980 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
3981 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
3983 GdipFree(pixel_data
);
3986 DeleteObject(hregion
);
3992 /*****************************************************************************
3993 * GdipFillRegion [GDIPLUS.@]
3995 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3998 GpStatus stat
= NotImplemented
;
4000 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4002 if (!(graphics
&& brush
&& region
))
4003 return InvalidParameter
;
4008 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4009 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4011 if (stat
== NotImplemented
)
4012 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4014 if (stat
== NotImplemented
)
4016 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4023 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4025 TRACE("(%p,%u)\n", graphics
, intention
);
4028 return InvalidParameter
;
4033 /* We have no internal operation queue, so there's no need to clear it. */
4041 /*****************************************************************************
4042 * GdipGetClipBounds [GDIPLUS.@]
4044 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4049 TRACE("(%p, %p)\n", graphics
, rect
);
4052 return InvalidParameter
;
4057 status
= GdipCreateRegion(&clip
);
4058 if (status
!= Ok
) return status
;
4060 status
= GdipGetClip(graphics
, clip
);
4062 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4064 GdipDeleteRegion(clip
);
4068 /*****************************************************************************
4069 * GdipGetClipBoundsI [GDIPLUS.@]
4071 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4073 TRACE("(%p, %p)\n", graphics
, rect
);
4076 return InvalidParameter
;
4081 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4084 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4085 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4086 CompositingMode
*mode
)
4088 TRACE("(%p, %p)\n", graphics
, mode
);
4090 if(!graphics
|| !mode
)
4091 return InvalidParameter
;
4096 *mode
= graphics
->compmode
;
4101 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4102 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4103 CompositingQuality
*quality
)
4105 TRACE("(%p, %p)\n", graphics
, quality
);
4107 if(!graphics
|| !quality
)
4108 return InvalidParameter
;
4113 *quality
= graphics
->compqual
;
4118 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4119 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4120 InterpolationMode
*mode
)
4122 TRACE("(%p, %p)\n", graphics
, mode
);
4124 if(!graphics
|| !mode
)
4125 return InvalidParameter
;
4130 *mode
= graphics
->interpolation
;
4135 /* FIXME: Need to handle color depths less than 24bpp */
4136 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4138 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4140 if(!graphics
|| !argb
)
4141 return InvalidParameter
;
4149 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4151 TRACE("(%p, %p)\n", graphics
, scale
);
4153 if(!graphics
|| !scale
)
4154 return InvalidParameter
;
4159 *scale
= graphics
->scale
;
4164 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4166 TRACE("(%p, %p)\n", graphics
, unit
);
4168 if(!graphics
|| !unit
)
4169 return InvalidParameter
;
4174 *unit
= graphics
->unit
;
4179 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4180 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4183 TRACE("(%p, %p)\n", graphics
, mode
);
4185 if(!graphics
|| !mode
)
4186 return InvalidParameter
;
4191 *mode
= graphics
->pixeloffset
;
4196 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4197 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4199 TRACE("(%p, %p)\n", graphics
, mode
);
4201 if(!graphics
|| !mode
)
4202 return InvalidParameter
;
4207 *mode
= graphics
->smoothing
;
4212 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4214 TRACE("(%p, %p)\n", graphics
, contrast
);
4216 if(!graphics
|| !contrast
)
4217 return InvalidParameter
;
4219 *contrast
= graphics
->textcontrast
;
4224 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4225 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4226 TextRenderingHint
*hint
)
4228 TRACE("(%p, %p)\n", graphics
, hint
);
4230 if(!graphics
|| !hint
)
4231 return InvalidParameter
;
4236 *hint
= graphics
->texthint
;
4241 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4246 TRACE("(%p, %p)\n", graphics
, rect
);
4248 if(!graphics
|| !rect
)
4249 return InvalidParameter
;
4254 /* intersect window and graphics clipping regions */
4255 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4258 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4261 /* get bounds of the region */
4262 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4265 GdipDeleteRegion(clip_rgn
);
4270 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4275 TRACE("(%p, %p)\n", graphics
, rect
);
4277 if(!graphics
|| !rect
)
4278 return InvalidParameter
;
4280 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4282 rect
->X
= gdip_round(rectf
.X
);
4283 rect
->Y
= gdip_round(rectf
.Y
);
4284 rect
->Width
= gdip_round(rectf
.Width
);
4285 rect
->Height
= gdip_round(rectf
.Height
);
4291 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4293 TRACE("(%p, %p)\n", graphics
, matrix
);
4295 if(!graphics
|| !matrix
)
4296 return InvalidParameter
;
4301 *matrix
= graphics
->worldtrans
;
4305 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4311 TRACE("(%p, %x)\n", graphics
, color
);
4314 return InvalidParameter
;
4319 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4322 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4323 GdipDeleteBrush((GpBrush
*)brush
);
4327 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4328 wnd_rect
.Width
, wnd_rect
.Height
);
4330 GdipDeleteBrush((GpBrush
*)brush
);
4335 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4337 TRACE("(%p, %p)\n", graphics
, res
);
4339 if(!graphics
|| !res
)
4340 return InvalidParameter
;
4342 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4345 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4351 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4353 if(!graphics
|| !result
)
4354 return InvalidParameter
;
4361 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4362 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4365 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4368 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4371 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4374 GdipDeleteRegion(rgn
);
4378 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4380 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4383 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4389 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4391 if(!graphics
|| !result
)
4392 return InvalidParameter
;
4399 pts
[1].X
= x
+ width
;
4400 pts
[1].Y
= y
+ height
;
4402 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4403 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4406 pts
[1].X
-= pts
[0].X
;
4407 pts
[1].Y
-= pts
[0].Y
;
4409 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4412 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4415 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4418 GdipDeleteRegion(rgn
);
4422 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4424 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4427 GpStatus
gdip_format_string(HDC hdc
,
4428 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4429 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4430 gdip_format_string_callback callback
, void *user_data
)
4433 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4434 nheight
, lineend
, lineno
= 0;
4436 StringAlignment halign
;
4439 HotkeyPrefix hkprefix
;
4440 INT
*hotkeyprefix_offsets
=NULL
;
4441 INT hotkeyprefix_count
=0;
4442 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4445 if(length
== -1) length
= lstrlenW(string
);
4447 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4448 if(!stringdup
) return OutOfMemory
;
4450 nwidth
= rect
->Width
;
4451 nheight
= rect
->Height
;
4452 if (ignore_empty_clip
)
4454 if (!nwidth
) nwidth
= INT_MAX
;
4455 if (!nheight
) nheight
= INT_MAX
;
4459 hkprefix
= format
->hkprefix
;
4461 hkprefix
= HotkeyPrefixNone
;
4463 if (hkprefix
== HotkeyPrefixShow
)
4465 for (i
=0; i
<length
; i
++)
4467 if (string
[i
] == '&')
4468 hotkeyprefix_count
++;
4472 if (hotkeyprefix_count
)
4473 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4475 hotkeyprefix_count
= 0;
4477 for(i
= 0, j
= 0; i
< length
; i
++){
4478 /* FIXME: This makes the indexes passed to callback inaccurate. */
4479 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4482 /* FIXME: tabs should be handled using tabstops from stringformat */
4483 if (string
[i
] == '\t')
4486 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4487 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4488 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4496 stringdup
[j
] = string
[i
];
4502 if (format
) halign
= format
->align
;
4503 else halign
= StringAlignmentNear
;
4505 while(sum
< length
){
4506 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4507 nwidth
, &fit
, NULL
, &size
);
4513 for(lret
= 0; lret
< fit
; lret
++)
4514 if(*(stringdup
+ sum
+ lret
) == '\n')
4517 /* Line break code (may look strange, but it imitates windows). */
4519 lineend
= fit
= lret
; /* this is not an off-by-one error */
4520 else if(fit
< (length
- sum
)){
4521 if(*(stringdup
+ sum
+ fit
) == ' ')
4522 while(*(stringdup
+ sum
+ fit
) == ' ')
4525 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4528 if(*(stringdup
+ sum
+ fit
) == '\t')
4537 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4538 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4544 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4545 nwidth
, &j
, NULL
, &size
);
4547 bounds
.Width
= size
.cx
;
4549 if(height
+ size
.cy
> nheight
)
4550 bounds
.Height
= nheight
- (height
+ size
.cy
);
4552 bounds
.Height
= size
.cy
;
4554 bounds
.Y
= rect
->Y
+ height
;
4558 case StringAlignmentNear
:
4562 case StringAlignmentCenter
:
4563 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4565 case StringAlignmentFar
:
4566 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4570 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4571 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4574 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4575 font
, rect
, format
, lineno
, &bounds
,
4576 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4577 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4582 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4586 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4588 if(height
> nheight
)
4591 /* Stop if this was a linewrap (but not if it was a linebreak). */
4592 if ((lret
== fitcpy
) && format
&&
4593 (format
->attr
& (StringFormatFlagsNoWrap
| StringFormatFlagsLineLimit
)))
4597 GdipFree(stringdup
);
4598 GdipFree(hotkeyprefix_offsets
);
4603 struct measure_ranges_args
{
4605 REAL rel_width
, rel_height
;
4608 static GpStatus
measure_ranges_callback(HDC hdc
,
4609 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4610 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4611 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4612 INT underlined_index_count
, void *user_data
)
4616 struct measure_ranges_args
*args
= user_data
;
4618 for (i
=0; i
<format
->range_count
; i
++)
4620 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4621 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4622 if (range_start
< range_end
)
4627 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4628 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4630 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4631 INT_MAX
, NULL
, NULL
, &range_size
);
4632 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4634 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4635 INT_MAX
, NULL
, NULL
, &range_size
);
4636 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4638 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4647 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4648 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4649 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4650 INT regionCount
, GpRegion
** regions
)
4654 HFONT gdifont
, oldfont
;
4655 struct measure_ranges_args args
;
4656 HDC hdc
, temp_hdc
=NULL
;
4661 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4662 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4664 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4665 return InvalidParameter
;
4667 if (regionCount
< stringFormat
->range_count
)
4668 return InvalidParameter
;
4672 hdc
= temp_hdc
= CreateCompatibleDC(0);
4673 if (!temp_hdc
) return OutOfMemory
;
4676 hdc
= graphics
->hdc
;
4678 if (stringFormat
->attr
)
4679 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4687 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4688 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4689 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4690 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4691 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4693 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4694 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4696 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4697 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4698 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
4699 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
4701 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
4702 oldfont
= SelectObject(hdc
, gdifont
);
4704 for (i
=0; i
<stringFormat
->range_count
; i
++)
4706 stat
= GdipSetEmpty(regions
[i
]);
4711 args
.regions
= regions
;
4713 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
4714 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
4716 SelectObject(hdc
, oldfont
);
4717 DeleteObject(gdifont
);
4725 struct measure_string_args
{
4727 INT
*codepointsfitted
;
4729 REAL rel_width
, rel_height
;
4732 static GpStatus
measure_string_callback(HDC hdc
,
4733 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4734 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4735 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4736 INT underlined_index_count
, void *user_data
)
4738 struct measure_string_args
*args
= user_data
;
4739 REAL new_width
, new_height
;
4741 new_width
= bounds
->Width
/ args
->rel_width
;
4742 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
4744 if (new_width
> args
->bounds
->Width
)
4745 args
->bounds
->Width
= new_width
;
4747 if (new_height
> args
->bounds
->Height
)
4748 args
->bounds
->Height
= new_height
;
4750 if (args
->codepointsfitted
)
4751 *args
->codepointsfitted
= index
+ length
;
4753 if (args
->linesfilled
)
4754 (*args
->linesfilled
)++;
4759 /* Find the smallest rectangle that bounds the text when it is printed in rect
4760 * according to the format options listed in format. If rect has 0 width and
4761 * height, then just find the smallest rectangle that bounds the text when it's
4762 * printed at location (rect->X, rect-Y). */
4763 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4764 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4765 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4766 INT
*codepointsfitted
, INT
*linesfilled
)
4768 HFONT oldfont
, gdifont
;
4769 struct measure_string_args args
;
4770 HDC temp_hdc
=NULL
, hdc
;
4776 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4777 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4778 bounds
, codepointsfitted
, linesfilled
);
4780 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4781 return InvalidParameter
;
4785 hdc
= temp_hdc
= CreateCompatibleDC(0);
4786 if (!temp_hdc
) return OutOfMemory
;
4789 hdc
= graphics
->hdc
;
4791 if(linesfilled
) *linesfilled
= 0;
4792 if(codepointsfitted
) *codepointsfitted
= 0;
4795 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4803 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4804 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4805 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4806 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4807 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4809 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4810 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4812 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
4813 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
4814 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
4815 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
4816 if (scaled_rect
.Width
>= 0.5)
4818 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4819 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4822 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4823 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4825 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
4826 oldfont
= SelectObject(hdc
, gdifont
);
4828 bounds
->X
= rect
->X
;
4829 bounds
->Y
= rect
->Y
;
4830 bounds
->Width
= 0.0;
4831 bounds
->Height
= 0.0;
4833 args
.bounds
= bounds
;
4834 args
.codepointsfitted
= &glyphs
;
4835 args
.linesfilled
= &lines
;
4838 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
4839 measure_string_callback
, &args
);
4841 if (linesfilled
) *linesfilled
= lines
;
4842 if (codepointsfitted
) *codepointsfitted
= glyphs
;
4845 bounds
->Width
+= margin_x
* 2.0;
4847 SelectObject(hdc
, oldfont
);
4848 DeleteObject(gdifont
);
4856 struct draw_string_args
{
4857 GpGraphics
*graphics
;
4858 GDIPCONST GpBrush
*brush
;
4859 REAL x
, y
, rel_width
, rel_height
, ascent
;
4862 static GpStatus
draw_string_callback(HDC hdc
,
4863 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4864 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4865 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4866 INT underlined_index_count
, void *user_data
)
4868 struct draw_string_args
*args
= user_data
;
4872 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4873 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4875 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
4876 args
->brush
, &position
,
4877 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4879 if (stat
== Ok
&& underlined_index_count
)
4881 OUTLINETEXTMETRICW otm
;
4882 REAL underline_y
, underline_height
;
4885 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
4887 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
4888 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
4890 for (i
=0; i
<underlined_index_count
; i
++)
4892 REAL start_x
, end_x
;
4894 INT ofs
= underlined_indexes
[i
] - index
;
4896 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
4897 start_x
= text_size
.cx
/ args
->rel_width
;
4899 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
4900 end_x
= text_size
.cx
/ args
->rel_width
;
4902 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
4909 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4910 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4911 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4915 GpPointF pt
[3], rectcpy
[4];
4917 REAL rel_width
, rel_height
, margin_x
;
4918 INT save_state
, format_flags
= 0;
4920 struct draw_string_args args
;
4922 HDC hdc
, temp_hdc
=NULL
;
4923 TEXTMETRICW textmetric
;
4925 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4926 length
, font
, debugstr_rectf(rect
), format
, brush
);
4928 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4929 return InvalidParameter
;
4933 hdc
= graphics
->hdc
;
4937 hdc
= temp_hdc
= CreateCompatibleDC(0);
4941 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4943 format_flags
= format
->attr
;
4945 /* Should be no need to explicitly test for StringAlignmentNear as
4946 * that is default behavior if no alignment is passed. */
4947 if(format
->vertalign
!= StringAlignmentNear
){
4948 RectF bounds
, in_rect
= *rect
;
4949 in_rect
.Height
= 0.0; /* avoid height clipping */
4950 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
4952 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
4954 if(format
->vertalign
== StringAlignmentCenter
)
4955 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4956 else if(format
->vertalign
== StringAlignmentFar
)
4957 offsety
= (rect
->Height
- bounds
.Height
);
4959 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
4962 save_state
= SaveDC(hdc
);
4970 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4971 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4972 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4973 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4974 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4976 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
4977 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
4978 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
4979 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
4980 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
4982 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4983 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4985 scaled_rect
.X
= margin_x
* rel_width
;
4986 scaled_rect
.Y
= 0.0;
4987 scaled_rect
.Width
= rel_width
* rect
->Width
;
4988 scaled_rect
.Height
= rel_height
* rect
->Height
;
4989 if (scaled_rect
.Width
>= 0.5)
4991 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
4992 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4995 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4996 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4998 if (!(format_flags
& StringFormatFlagsNoClip
) &&
4999 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5000 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5002 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5003 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5004 SelectClipRgn(hdc
, rgn
);
5007 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5008 SelectObject(hdc
, gdifont
);
5010 args
.graphics
= graphics
;
5014 args
.y
= rect
->Y
+ offsety
;
5016 args
.rel_width
= rel_width
;
5017 args
.rel_height
= rel_height
;
5019 GetTextMetricsW(hdc
, &textmetric
);
5020 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5022 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5023 draw_string_callback
, &args
);
5026 DeleteObject(gdifont
);
5028 RestoreDC(hdc
, save_state
);
5035 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5037 TRACE("(%p)\n", graphics
);
5040 return InvalidParameter
;
5045 return GdipSetInfinite(graphics
->clip
);
5048 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5050 TRACE("(%p)\n", graphics
);
5053 return InvalidParameter
;
5058 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5061 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5063 return GdipEndContainer(graphics
, state
);
5066 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5067 GpMatrixOrder order
)
5069 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5072 return InvalidParameter
;
5077 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5080 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5082 return GdipBeginContainer2(graphics
, state
);
5085 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5086 GraphicsContainer
*state
)
5088 GraphicsContainerItem
*container
;
5091 TRACE("(%p, %p)\n", graphics
, state
);
5093 if(!graphics
|| !state
)
5094 return InvalidParameter
;
5096 sts
= init_container(&container
, graphics
);
5100 list_add_head(&graphics
->containers
, &container
->entry
);
5101 *state
= graphics
->contid
= container
->contid
;
5106 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5108 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5109 return NotImplemented
;
5112 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5114 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5115 return NotImplemented
;
5118 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5120 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5121 return NotImplemented
;
5124 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5127 GraphicsContainerItem
*container
, *container2
;
5129 TRACE("(%p, %x)\n", graphics
, state
);
5132 return InvalidParameter
;
5134 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5135 if(container
->contid
== state
)
5139 /* did not find a matching container */
5140 if(&container
->entry
== &graphics
->containers
)
5143 sts
= restore_container(graphics
, container
);
5147 /* remove all of the containers on top of the found container */
5148 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5149 if(container
->contid
== state
)
5151 list_remove(&container
->entry
);
5152 delete_container(container
);
5155 list_remove(&container
->entry
);
5156 delete_container(container
);
5161 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5162 REAL sy
, GpMatrixOrder order
)
5164 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5167 return InvalidParameter
;
5172 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5175 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5178 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5180 if(!graphics
|| !srcgraphics
)
5181 return InvalidParameter
;
5183 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5186 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5187 CompositingMode mode
)
5189 TRACE("(%p, %d)\n", graphics
, mode
);
5192 return InvalidParameter
;
5197 graphics
->compmode
= mode
;
5202 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5203 CompositingQuality quality
)
5205 TRACE("(%p, %d)\n", graphics
, quality
);
5208 return InvalidParameter
;
5213 graphics
->compqual
= quality
;
5218 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5219 InterpolationMode mode
)
5221 TRACE("(%p, %d)\n", graphics
, mode
);
5223 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5224 return InvalidParameter
;
5229 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5230 mode
= InterpolationModeBilinear
;
5232 if (mode
== InterpolationModeHighQuality
)
5233 mode
= InterpolationModeHighQualityBicubic
;
5235 graphics
->interpolation
= mode
;
5240 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5242 TRACE("(%p, %.2f)\n", graphics
, scale
);
5244 if(!graphics
|| (scale
<= 0.0))
5245 return InvalidParameter
;
5250 graphics
->scale
= scale
;
5255 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5257 TRACE("(%p, %d)\n", graphics
, unit
);
5260 return InvalidParameter
;
5265 if(unit
== UnitWorld
)
5266 return InvalidParameter
;
5268 graphics
->unit
= unit
;
5273 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5276 TRACE("(%p, %d)\n", graphics
, mode
);
5279 return InvalidParameter
;
5284 graphics
->pixeloffset
= mode
;
5289 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5293 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5296 FIXME("value is unused in rendering\n");
5299 return InvalidParameter
;
5301 graphics
->origin_x
= x
;
5302 graphics
->origin_y
= y
;
5307 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5309 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5311 if (!graphics
|| !x
|| !y
)
5312 return InvalidParameter
;
5314 *x
= graphics
->origin_x
;
5315 *y
= graphics
->origin_y
;
5320 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5322 TRACE("(%p, %d)\n", graphics
, mode
);
5325 return InvalidParameter
;
5330 graphics
->smoothing
= mode
;
5335 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5337 TRACE("(%p, %d)\n", graphics
, contrast
);
5340 return InvalidParameter
;
5342 graphics
->textcontrast
= contrast
;
5347 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5348 TextRenderingHint hint
)
5350 TRACE("(%p, %d)\n", graphics
, hint
);
5352 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5353 return InvalidParameter
;
5358 graphics
->texthint
= hint
;
5363 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5365 TRACE("(%p, %p)\n", graphics
, matrix
);
5367 if(!graphics
|| !matrix
)
5368 return InvalidParameter
;
5373 TRACE("%f,%f,%f,%f,%f,%f\n",
5374 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5375 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5377 graphics
->worldtrans
= *matrix
;
5382 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5383 REAL dy
, GpMatrixOrder order
)
5385 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5388 return InvalidParameter
;
5393 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5396 /*****************************************************************************
5397 * GdipSetClipHrgn [GDIPLUS.@]
5399 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5404 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5407 return InvalidParameter
;
5412 /* hrgn is already in device units */
5413 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5417 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5419 GdipDeleteRegion(region
);
5423 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5428 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5431 return InvalidParameter
;
5436 status
= GdipClonePath(path
, &clip_path
);
5439 GpMatrix world_to_device
;
5441 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
5442 CoordinateSpaceWorld
, &world_to_device
);
5443 status
= GdipTransformPath(clip_path
, &world_to_device
);
5445 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
5447 GdipDeletePath(clip_path
);
5452 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5453 REAL width
, REAL height
,
5460 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5463 return InvalidParameter
;
5471 rect
.Height
= height
;
5472 status
= GdipCreateRegionRect(&rect
, ®ion
);
5475 GpMatrix world_to_device
;
5477 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5478 status
= GdipTransformRegion(region
, &world_to_device
);
5480 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5482 GdipDeleteRegion(region
);
5487 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5488 INT width
, INT height
,
5491 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5494 return InvalidParameter
;
5499 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5502 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5508 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5510 if(!graphics
|| !region
)
5511 return InvalidParameter
;
5516 status
= GdipCloneRegion(region
, &clip
);
5519 GpMatrix world_to_device
;
5521 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
5522 status
= GdipTransformRegion(clip
, &world_to_device
);
5524 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
5526 GdipDeleteRegion(clip
);
5531 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5536 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5539 FIXME("not implemented\n");
5541 return NotImplemented
;
5544 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5550 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5552 if(!graphics
|| !pen
|| count
<=0)
5553 return InvalidParameter
;
5560 FIXME("graphics object has no HDC\n");
5564 pti
= GdipAlloc(sizeof(POINT
) * count
);
5566 save_state
= prepare_dc(graphics
, pen
);
5567 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5569 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5570 Polygon(graphics
->hdc
, pti
, count
);
5572 restore_dc(graphics
, save_state
);
5578 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5585 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5587 if(count
<=0) return InvalidParameter
;
5588 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5590 for(i
= 0;i
< count
; i
++){
5591 ptf
[i
].X
= (REAL
)points
[i
].X
;
5592 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5595 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5601 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5603 TRACE("(%p, %p)\n", graphics
, dpi
);
5605 if(!graphics
|| !dpi
)
5606 return InvalidParameter
;
5611 *dpi
= graphics
->xres
;
5615 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5617 TRACE("(%p, %p)\n", graphics
, dpi
);
5619 if(!graphics
|| !dpi
)
5620 return InvalidParameter
;
5625 *dpi
= graphics
->yres
;
5629 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5630 GpMatrixOrder order
)
5635 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5637 if(!graphics
|| !matrix
)
5638 return InvalidParameter
;
5643 m
= graphics
->worldtrans
;
5645 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5647 graphics
->worldtrans
= m
;
5652 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5653 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5655 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5659 TRACE("(%p, %p)\n", graphics
, hdc
);
5661 if(!graphics
|| !hdc
)
5662 return InvalidParameter
;
5667 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5669 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5671 else if (!graphics
->hdc
|| graphics
->alpha_hdc
||
5672 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5674 /* Create a fake HDC and fill it with a constant color. */
5678 BITMAPINFOHEADER bmih
;
5681 stat
= get_graphics_bounds(graphics
, &bounds
);
5685 graphics
->temp_hbitmap_width
= bounds
.Width
;
5686 graphics
->temp_hbitmap_height
= bounds
.Height
;
5688 bmih
.biSize
= sizeof(bmih
);
5689 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5690 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5692 bmih
.biBitCount
= 32;
5693 bmih
.biCompression
= BI_RGB
;
5694 bmih
.biSizeImage
= 0;
5695 bmih
.biXPelsPerMeter
= 0;
5696 bmih
.biYPelsPerMeter
= 0;
5698 bmih
.biClrImportant
= 0;
5700 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5701 (void**)&graphics
->temp_bits
, NULL
, 0);
5703 return GenericError
;
5705 temp_hdc
= CreateCompatibleDC(0);
5708 DeleteObject(hbitmap
);
5709 return GenericError
;
5712 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5713 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5715 SelectObject(temp_hdc
, hbitmap
);
5717 graphics
->temp_hbitmap
= hbitmap
;
5718 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5722 *hdc
= graphics
->hdc
;
5726 graphics
->busy
= TRUE
;
5731 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5735 TRACE("(%p, %p)\n", graphics
, hdc
);
5737 if(!graphics
|| !hdc
|| !graphics
->busy
)
5738 return InvalidParameter
;
5740 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5742 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5744 else if (graphics
->temp_hdc
== hdc
)
5749 /* Find the pixels that have changed, and mark them as opaque. */
5750 pos
= (DWORD
*)graphics
->temp_bits
;
5751 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5753 if (*pos
!= DC_BACKGROUND_KEY
)
5760 /* Write the changed pixels to the real target. */
5761 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5762 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5763 graphics
->temp_hbitmap_width
* 4);
5766 DeleteDC(graphics
->temp_hdc
);
5767 DeleteObject(graphics
->temp_hbitmap
);
5768 graphics
->temp_hdc
= NULL
;
5769 graphics
->temp_hbitmap
= NULL
;
5771 else if (hdc
!= graphics
->hdc
)
5773 stat
= InvalidParameter
;
5777 graphics
->busy
= FALSE
;
5782 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5786 GpMatrix device_to_world
;
5788 TRACE("(%p, %p)\n", graphics
, region
);
5790 if(!graphics
|| !region
)
5791 return InvalidParameter
;
5796 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5799 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
5800 status
= GdipTransformRegion(clip
, &device_to_world
);
5803 GdipDeleteRegion(clip
);
5807 /* free everything except root node and header */
5808 delete_element(®ion
->node
);
5809 memcpy(region
, clip
, sizeof(GpRegion
));
5815 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5816 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
5819 REAL scale_x
, scale_y
;
5821 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5823 if (dst_space
!= src_space
)
5825 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5826 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5828 if(graphics
->unit
!= UnitDisplay
)
5830 scale_x
*= graphics
->scale
;
5831 scale_y
*= graphics
->scale
;
5834 /* transform from src_space to CoordinateSpacePage */
5837 case CoordinateSpaceWorld
:
5838 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
5840 case CoordinateSpacePage
:
5842 case CoordinateSpaceDevice
:
5843 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
5847 /* transform from CoordinateSpacePage to dst_space */
5850 case CoordinateSpaceWorld
:
5852 GpMatrix inverted_transform
= graphics
->worldtrans
;
5853 stat
= GdipInvertMatrix(&inverted_transform
);
5855 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
5858 case CoordinateSpacePage
:
5860 case CoordinateSpaceDevice
:
5861 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
5868 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5869 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5874 if(!graphics
|| !points
|| count
<= 0)
5875 return InvalidParameter
;
5880 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5882 if (src_space
== dst_space
) return Ok
;
5884 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5885 if (stat
!= Ok
) return stat
;
5887 return GdipTransformMatrixPoints(&matrix
, points
, count
);
5890 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5891 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5897 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5900 return InvalidParameter
;
5902 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5906 for(i
= 0; i
< count
; i
++){
5907 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5908 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5911 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5914 for(i
= 0; i
< count
; i
++){
5915 points
[i
].X
= gdip_round(pointsF
[i
].X
);
5916 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
5923 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5935 /*****************************************************************************
5936 * GdipTranslateClip [GDIPLUS.@]
5938 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5940 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5943 return InvalidParameter
;
5948 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5951 /*****************************************************************************
5952 * GdipTranslateClipI [GDIPLUS.@]
5954 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5956 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5959 return InvalidParameter
;
5964 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
5968 /*****************************************************************************
5969 * GdipMeasureDriverString [GDIPLUS.@]
5971 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5972 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
5973 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
5975 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
5978 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
5980 TEXTMETRICW textmetric
;
5981 const WORD
*glyph_indices
;
5982 WORD
*dynamic_glyph_indices
=NULL
;
5983 REAL rel_width
, rel_height
, ascent
, descent
;
5986 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
5988 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
5989 return InvalidParameter
;
5992 length
= strlenW(text
);
5996 boundingBox
->X
= 0.0;
5997 boundingBox
->Y
= 0.0;
5998 boundingBox
->Width
= 0.0;
5999 boundingBox
->Height
= 0.0;
6002 if (flags
& unsupported_flags
)
6003 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6005 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6007 hdc
= CreateCompatibleDC(0);
6008 SelectObject(hdc
, hfont
);
6010 GetTextMetricsW(hdc
, &textmetric
);
6020 GpMatrix xform
= *matrix
;
6021 GdipTransformMatrixPoints(&xform
, pt
, 3);
6023 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6024 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6025 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6026 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6027 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6029 if (flags
& DriverStringOptionsCmapLookup
)
6031 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6035 DeleteObject(hfont
);
6039 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6042 glyph_indices
= text
;
6044 min_x
= max_x
= x
= positions
[0].X
;
6045 min_y
= max_y
= y
= positions
[0].Y
;
6047 ascent
= textmetric
.tmAscent
/ rel_height
;
6048 descent
= textmetric
.tmDescent
/ rel_height
;
6050 for (i
=0; i
<length
; i
++)
6055 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6061 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6062 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6064 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6065 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6066 if (min_x
> x
) min_x
= x
;
6068 x
+= char_width
/ rel_width
;
6070 if (max_x
< x
) max_x
= x
;
6073 GdipFree(dynamic_glyph_indices
);
6075 DeleteObject(hfont
);
6077 boundingBox
->X
= min_x
;
6078 boundingBox
->Y
= min_y
;
6079 boundingBox
->Width
= max_x
- min_x
;
6080 boundingBox
->Height
= max_y
- min_y
;
6085 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6086 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6087 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6088 INT flags
, GDIPCONST GpMatrix
*matrix
)
6090 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6096 if (flags
& unsupported_flags
)
6097 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6099 if (!(flags
& DriverStringOptionsCmapLookup
))
6100 eto_flags
|= ETO_GLYPH_INDEX
;
6102 save_state
= SaveDC(graphics
->hdc
);
6103 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6104 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6107 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6109 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6110 SelectObject(graphics
->hdc
, hfont
);
6112 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6114 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6116 RestoreDC(graphics
->hdc
, save_state
);
6118 DeleteObject(hfont
);
6123 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6124 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6125 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6126 INT flags
, GDIPCONST GpMatrix
*matrix
)
6128 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6130 PointF
*real_positions
, real_position
;
6134 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6135 DWORD max_glyphsize
=0;
6136 GLYPHMETRICS glyphmetrics
;
6137 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6140 int text_mask_stride
;
6142 int pixel_data_stride
;
6144 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6149 if (!(flags
& DriverStringOptionsCmapLookup
))
6150 ggo_flags
|= GGO_GLYPH_INDEX
;
6152 if (flags
& unsupported_flags
)
6153 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6155 pti
= GdipAlloc(sizeof(POINT
) * length
);
6159 if (flags
& DriverStringOptionsRealizedAdvance
)
6161 real_position
= positions
[0];
6163 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6167 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6168 if (!real_positions
)
6174 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6176 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6178 GdipFree(real_positions
);
6181 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6183 hdc
= CreateCompatibleDC(0);
6184 SelectObject(hdc
, hfont
);
6186 /* Get the boundaries of the text to be drawn */
6187 for (i
=0; i
<length
; i
++)
6190 int left
, top
, right
, bottom
;
6192 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6193 &glyphmetrics
, 0, NULL
, &identity
);
6195 if (glyphsize
== GDI_ERROR
)
6197 ERR("GetGlyphOutlineW failed\n");
6200 DeleteObject(hfont
);
6201 return GenericError
;
6204 if (glyphsize
> max_glyphsize
)
6205 max_glyphsize
= glyphsize
;
6207 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6208 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6209 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6210 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6212 if (left
< min_x
) min_x
= left
;
6213 if (top
< min_y
) min_y
= top
;
6214 if (right
> max_x
) max_x
= right
;
6215 if (bottom
> max_y
) max_y
= bottom
;
6217 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6219 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6220 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6224 glyph_mask
= GdipAlloc(max_glyphsize
);
6225 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6226 text_mask_stride
= max_x
- min_x
;
6228 if (!(glyph_mask
&& text_mask
))
6230 GdipFree(glyph_mask
);
6231 GdipFree(text_mask
);
6234 DeleteObject(hfont
);
6238 /* Generate a mask for the text */
6239 for (i
=0; i
<length
; i
++)
6241 int left
, top
, stride
;
6243 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6244 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6246 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6247 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6248 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6250 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6252 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6253 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6254 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6256 *text_val
= min(64, *text_val
+ *glyph_val
);
6265 DeleteObject(hfont
);
6266 GdipFree(glyph_mask
);
6268 /* get the brush data */
6269 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6272 GdipFree(text_mask
);
6276 pixel_area
.X
= min_x
;
6277 pixel_area
.Y
= min_y
;
6278 pixel_area
.Width
= max_x
- min_x
;
6279 pixel_area
.Height
= max_y
- min_y
;
6280 pixel_data_stride
= pixel_area
.Width
* 4;
6282 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6285 GdipFree(text_mask
);
6286 GdipFree(pixel_data
);
6290 /* multiply the brush data by the mask */
6291 for (y
=0; y
<pixel_area
.Height
; y
++)
6293 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6294 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6295 for (x
=0; x
<pixel_area
.Width
; x
++)
6297 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6303 GdipFree(text_mask
);
6305 /* draw the result */
6306 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6307 pixel_area
.Height
, pixel_data_stride
);
6309 GdipFree(pixel_data
);
6314 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6315 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6316 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6317 INT flags
, GDIPCONST GpMatrix
*matrix
)
6319 GpStatus stat
= NotImplemented
;
6322 length
= strlenW(text
);
6324 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6325 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6326 brush
->bt
== BrushTypeSolidColor
&&
6327 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6328 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6329 brush
, positions
, flags
, matrix
);
6330 if (stat
== NotImplemented
)
6331 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6332 brush
, positions
, flags
, matrix
);
6336 /*****************************************************************************
6337 * GdipDrawDriverString [GDIPLUS.@]
6339 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6340 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6341 GDIPCONST PointF
*positions
, INT flags
,
6342 GDIPCONST GpMatrix
*matrix
)
6344 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6346 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6347 return InvalidParameter
;
6349 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6350 brush
, positions
, flags
, matrix
);
6353 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6354 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6356 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6357 return NotImplemented
;
6360 /*****************************************************************************
6361 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6363 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6368 TRACE("(%p, %p)\n", graphics
, res
);
6370 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6373 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6376 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6379 GdipDeleteRegion(rgn
);
6383 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6387 TRACE("(%p) stub\n", graphics
);
6390 FIXME("not implemented\n");
6392 return NotImplemented
;