2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/unicode.h"
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
45 /* looks-right constants */
46 #define ANCHOR_WIDTH (2.0)
47 #define MAX_ITERS (50)
49 /* Converts angle (in degrees) to x/y coordinates */
50 static void deg2xy(REAL angle
, REAL x_0
, REAL y_0
, REAL
*x
, REAL
*y
)
52 REAL radAngle
, hypotenuse
;
54 radAngle
= deg2rad(angle
);
55 hypotenuse
= 50.0; /* arbitrary */
57 *x
= x_0
+ cos(radAngle
) * hypotenuse
;
58 *y
= y_0
+ sin(radAngle
) * hypotenuse
;
61 /* Converts from gdiplus path point type to gdi path point type. */
62 static BYTE
convert_path_point_type(BYTE type
)
66 switch(type
& PathPointTypePathTypeMask
){
67 case PathPointTypeBezier
:
70 case PathPointTypeLine
:
73 case PathPointTypeStart
:
77 ERR("Bad point type\n");
81 if(type
& PathPointTypeCloseSubpath
)
82 ret
|= PT_CLOSEFIGURE
;
87 static REAL
graphics_res(GpGraphics
*graphics
)
89 if (graphics
->image
) return graphics
->image
->xres
;
90 else return (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
93 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
99 case BrushTypeSolidColor
:
101 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
105 case BrushTypeHatchFill
:
107 const GpHatch
*hatch
= (const GpHatch
*)brush
;
108 argb
= hatch
->forecol
;
111 case BrushTypeLinearGradient
:
113 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
114 argb
= line
->startcolor
;
117 case BrushTypePathGradient
:
119 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
120 argb
= grad
->centercolor
;
124 FIXME("unhandled brush type %d\n", brush
->bt
);
128 return ARGB2COLORREF(argb
);
131 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
135 BITMAPINFOHEADER bmih
;
139 hdc
= CreateCompatibleDC(0);
143 bmih
.biSize
= sizeof(bmih
);
147 bmih
.biBitCount
= 32;
148 bmih
.biCompression
= BI_RGB
;
149 bmih
.biSizeImage
= 0;
151 hbmp
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
154 const char *hatch_data
;
156 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
158 for (y
= 0; y
< 8; y
++)
160 for (x
= 0; x
< 8; x
++)
162 if (hatch_data
[y
] & (0x80 >> x
))
163 bits
[y
* 8 + x
] = hatch
->forecol
;
165 bits
[y
* 8 + x
] = hatch
->backcol
;
171 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
173 for (y
= 0; y
< 64; y
++)
174 bits
[y
] = hatch
->forecol
;
182 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
186 case BrushTypeSolidColor
:
188 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
189 lb
->lbStyle
= BS_SOLID
;
190 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
195 case BrushTypeHatchFill
:
197 const GpHatch
*hatch
= (const GpHatch
*)brush
;
200 hbmp
= create_hatch_bitmap(hatch
);
201 if (!hbmp
) return OutOfMemory
;
203 lb
->lbStyle
= BS_PATTERN
;
205 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
210 FIXME("unhandled brush type %d\n", brush
->bt
);
211 lb
->lbStyle
= BS_SOLID
;
212 lb
->lbColor
= get_gdi_brush_color(brush
);
218 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
223 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
229 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
234 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
236 gdibrush
= CreateBrushIndirect(&lb
);
237 free_gdi_logbrush(&lb
);
242 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
247 INT save_state
, i
, numdashes
;
249 DWORD dash_array
[MAX_DASHLEN
];
251 save_state
= SaveDC(graphics
->hdc
);
253 EndPath(graphics
->hdc
);
255 if(pen
->unit
== UnitPixel
){
259 /* Get an estimate for the amount the pen width is affected by the world
260 * transform. (This is similar to what some of the wine drivers do.) */
265 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
266 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
267 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
269 width
*= pen
->width
* convert_unit(graphics_res(graphics
),
270 pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
);
273 if(pen
->dash
== DashStyleCustom
){
274 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
276 TRACE("dashes are: ");
277 for(i
= 0; i
< numdashes
; i
++){
278 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
279 TRACE("%d, ", dash_array
[i
]);
281 TRACE("\n and the pen style is %x\n", pen
->style
);
283 create_gdi_logbrush(pen
->brush
, &lb
);
284 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &lb
,
285 numdashes
, dash_array
);
286 free_gdi_logbrush(&lb
);
290 create_gdi_logbrush(pen
->brush
, &lb
);
291 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &lb
, 0, NULL
);
292 free_gdi_logbrush(&lb
);
295 SelectObject(graphics
->hdc
, gdipen
);
300 static void restore_dc(GpGraphics
*graphics
, INT state
)
302 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
303 RestoreDC(graphics
->hdc
, state
);
306 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
307 GpCoordinateSpace src_space
, GpMatrix
**matrix
);
309 /* This helper applies all the changes that the points listed in ptf need in
310 * order to be drawn on the device context. In the end, this should include at
312 * -scaling by page unit
313 * -applying world transformation
314 * -converting from float to int
315 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
316 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
317 * gdi to draw, and these functions would irreparably mess with line widths.
319 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
320 GpPointF
*ptf
, INT count
)
326 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
328 /* apply page scale */
329 if(graphics
->unit
!= UnitDisplay
)
330 unitscale
*= graphics
->scale
;
332 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
333 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
334 GdipTransformMatrixPoints(matrix
, ptf
, count
);
335 GdipDeleteMatrix(matrix
);
337 for(i
= 0; i
< count
; i
++){
338 pti
[i
].x
= roundr(ptf
[i
].X
);
339 pti
[i
].y
= roundr(ptf
[i
].Y
);
343 /* Draw non-premultiplied ARGB data to the given graphics object */
344 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
345 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
347 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
349 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
352 for (x
=0; x
<src_width
; x
++)
354 for (y
=0; y
<src_height
; y
++)
356 ARGB dst_color
, src_color
;
357 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
358 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
359 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
365 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
367 ERR("This should not be used for metafiles; fix caller\n");
368 return NotImplemented
;
373 HBITMAP hbitmap
, old_hbm
=NULL
;
374 BITMAPINFOHEADER bih
;
378 hdc
= CreateCompatibleDC(0);
380 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
381 bih
.biWidth
= src_width
;
382 bih
.biHeight
= -src_height
;
385 bih
.biCompression
= BI_RGB
;
387 bih
.biXPelsPerMeter
= 0;
388 bih
.biYPelsPerMeter
= 0;
390 bih
.biClrImportant
= 0;
392 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
393 (void**)&temp_bits
, NULL
, 0);
395 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
396 4 * src_width
, src
, src_stride
);
398 old_hbm
= SelectObject(hdc
, hbitmap
);
400 bf
.BlendOp
= AC_SRC_OVER
;
402 bf
.SourceConstantAlpha
= 255;
403 bf
.AlphaFormat
= AC_SRC_ALPHA
;
405 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, src_width
, src_height
,
406 hdc
, 0, 0, src_width
, src_height
, bf
);
408 SelectObject(hdc
, old_hbm
);
410 DeleteObject(hbitmap
);
416 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
417 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
)
421 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
427 size
= GetRegionData(hregion
, 0, NULL
);
429 rgndata
= GdipAlloc(size
);
433 GetRegionData(hregion
, size
, rgndata
);
435 rects
= (RECT
*)&rgndata
->Buffer
;
437 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
439 stat
= alpha_blend_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
440 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
441 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
449 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
451 ERR("This should not be used for metafiles; fix caller\n");
452 return NotImplemented
;
458 save
= SaveDC(graphics
->hdc
);
460 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
462 stat
= alpha_blend_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
463 src_height
, src_stride
);
465 RestoreDC(graphics
->hdc
, save
);
471 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
477 a1
= (start
>> 24) & 0xff;
478 a2
= (end
>> 24) & 0xff;
480 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
484 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
485 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
489 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
493 /* clamp to between 0.0 and 1.0, using the wrap mode */
494 if (brush
->wrap
== WrapModeTile
)
496 position
= fmodf(position
, 1.0f
);
497 if (position
< 0.0f
) position
+= 1.0f
;
499 else /* WrapModeFlip* */
501 position
= fmodf(position
, 2.0f
);
502 if (position
< 0.0f
) position
+= 2.0f
;
503 if (position
> 1.0f
) position
= 2.0f
- position
;
506 if (brush
->blendcount
== 1)
511 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
514 /* locate the blend positions surrounding this position */
515 while (position
> brush
->blendpos
[i
])
518 /* interpolate between the blend positions */
519 left_blendpos
= brush
->blendpos
[i
-1];
520 left_blendfac
= brush
->blendfac
[i
-1];
521 right_blendpos
= brush
->blendpos
[i
];
522 right_blendfac
= brush
->blendfac
[i
];
523 range
= right_blendpos
- left_blendpos
;
524 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
525 right_blendfac
* (position
- left_blendpos
)) / range
;
528 if (brush
->pblendcount
== 0)
529 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
533 ARGB left_blendcolor
, right_blendcolor
;
534 REAL left_blendpos
, right_blendpos
;
536 /* locate the blend colors surrounding this position */
537 while (blendfac
> brush
->pblendpos
[i
])
540 /* interpolate between the blend colors */
541 left_blendpos
= brush
->pblendpos
[i
-1];
542 left_blendcolor
= brush
->pblendcolor
[i
-1];
543 right_blendpos
= brush
->pblendpos
[i
];
544 right_blendcolor
= brush
->pblendcolor
[i
];
545 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
546 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
550 static ARGB
transform_color(ARGB color
, const ColorMatrix
*matrix
)
554 unsigned char a
, r
, g
, b
;
556 val
[0] = ((color
>> 16) & 0xff) / 255.0; /* red */
557 val
[1] = ((color
>> 8) & 0xff) / 255.0; /* green */
558 val
[2] = (color
& 0xff) / 255.0; /* blue */
559 val
[3] = ((color
>> 24) & 0xff) / 255.0; /* alpha */
560 val
[4] = 1.0; /* translation */
567 res
[i
] += matrix
->m
[j
][i
] * val
[j
];
570 a
= min(max(floorf(res
[3]*255.0), 0.0), 255.0);
571 r
= min(max(floorf(res
[0]*255.0), 0.0), 255.0);
572 g
= min(max(floorf(res
[1]*255.0), 0.0), 255.0);
573 b
= min(max(floorf(res
[2]*255.0), 0.0), 255.0);
575 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
578 static int color_is_gray(ARGB color
)
580 unsigned char r
, g
, b
;
582 r
= (color
>> 16) & 0xff;
583 g
= (color
>> 8) & 0xff;
586 return (r
== g
) && (g
== b
);
589 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
590 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
594 if (attributes
->colorkeys
[type
].enabled
||
595 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
597 const struct color_key
*key
;
598 BYTE min_blue
, min_green
, min_red
;
599 BYTE max_blue
, max_green
, max_red
;
601 if (attributes
->colorkeys
[type
].enabled
)
602 key
= &attributes
->colorkeys
[type
];
604 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
606 min_blue
= key
->low
&0xff;
607 min_green
= (key
->low
>>8)&0xff;
608 min_red
= (key
->low
>>16)&0xff;
610 max_blue
= key
->high
&0xff;
611 max_green
= (key
->high
>>8)&0xff;
612 max_red
= (key
->high
>>16)&0xff;
614 for (x
=0; x
<width
; x
++)
615 for (y
=0; y
<height
; y
++)
618 BYTE blue
, green
, red
;
619 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
620 blue
= *src_color
&0xff;
621 green
= (*src_color
>>8)&0xff;
622 red
= (*src_color
>>16)&0xff;
623 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
624 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
625 *src_color
= 0x00000000;
629 if (attributes
->colorremaptables
[type
].enabled
||
630 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
632 const struct color_remap_table
*table
;
634 if (attributes
->colorremaptables
[type
].enabled
)
635 table
= &attributes
->colorremaptables
[type
];
637 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
639 for (x
=0; x
<width
; x
++)
640 for (y
=0; y
<height
; y
++)
643 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
644 for (i
=0; i
<table
->mapsize
; i
++)
646 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
648 *src_color
= table
->colormap
[i
].newColor
.Argb
;
655 if (attributes
->colormatrices
[type
].enabled
||
656 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
658 const struct color_matrix
*colormatrices
;
660 if (attributes
->colormatrices
[type
].enabled
)
661 colormatrices
= &attributes
->colormatrices
[type
];
663 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
665 for (x
=0; x
<width
; x
++)
666 for (y
=0; y
<height
; y
++)
669 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
671 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
672 !color_is_gray(*src_color
))
674 *src_color
= transform_color(*src_color
, &colormatrices
->colormatrix
);
676 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
678 *src_color
= transform_color(*src_color
, &colormatrices
->graymatrix
);
683 if (attributes
->gamma_enabled
[type
] ||
684 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
688 if (attributes
->gamma_enabled
[type
])
689 gamma
= attributes
->gamma
[type
];
691 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
693 for (x
=0; x
<width
; x
++)
694 for (y
=0; y
<height
; y
++)
697 BYTE blue
, green
, red
;
698 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
700 blue
= *src_color
&0xff;
701 green
= (*src_color
>>8)&0xff;
702 red
= (*src_color
>>16)&0xff;
704 /* FIXME: We should probably use a table for this. */
705 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
706 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
707 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
709 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
714 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
715 * bitmap that contains all the pixels we may need to draw it. */
716 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
717 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
720 INT left
, top
, right
, bottom
;
722 switch (interpolation
)
724 case InterpolationModeHighQualityBilinear
:
725 case InterpolationModeHighQualityBicubic
:
726 /* FIXME: Include a greater range for the prefilter? */
727 case InterpolationModeBicubic
:
728 case InterpolationModeBilinear
:
729 left
= (INT
)(floorf(srcx
));
730 top
= (INT
)(floorf(srcy
));
731 right
= (INT
)(ceilf(srcx
+srcwidth
));
732 bottom
= (INT
)(ceilf(srcy
+srcheight
));
734 case InterpolationModeNearestNeighbor
:
738 right
= roundr(srcx
+srcwidth
);
739 bottom
= roundr(srcy
+srcheight
);
743 if (wrap
== WrapModeClamp
)
749 if (right
>= bitmap
->width
)
750 right
= bitmap
->width
-1;
751 if (bottom
>= bitmap
->height
)
752 bottom
= bitmap
->height
-1;
756 /* In some cases we can make the rectangle smaller here, but the logic
757 * is hard to get right, and tiling suggests we're likely to use the
758 * entire source image. */
759 if (left
< 0 || right
>= bitmap
->width
)
762 right
= bitmap
->width
-1;
765 if (top
< 0 || bottom
>= bitmap
->height
)
768 bottom
= bitmap
->height
-1;
774 rect
->Width
= right
- left
+ 1;
775 rect
->Height
= bottom
- top
+ 1;
778 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
779 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
781 if (attributes
->wrap
== WrapModeClamp
)
783 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
784 return attributes
->outside_color
;
788 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
790 x
= width
*2 + x
% (width
* 2);
792 y
= height
*2 + y
% (height
* 2);
794 if ((attributes
->wrap
& 1) == 1)
797 if ((x
/ width
) % 2 == 0)
800 x
= width
- 1 - x
% width
;
805 if ((attributes
->wrap
& 2) == 2)
808 if ((y
/ height
) % 2 == 0)
811 y
= height
- 1 - y
% height
;
817 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
819 ERR("out of range pixel requested\n");
823 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
826 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
827 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
828 InterpolationMode interpolation
)
832 switch (interpolation
)
836 FIXME("Unimplemented interpolation %i\n", interpolation
);
838 case InterpolationModeBilinear
:
841 INT leftx
, rightx
, topy
, bottomy
;
842 ARGB topleft
, topright
, bottomleft
, bottomright
;
846 leftxf
= floorf(point
->X
);
848 rightx
= (INT
)ceilf(point
->X
);
849 topyf
= floorf(point
->Y
);
851 bottomy
= (INT
)ceilf(point
->Y
);
853 if (leftx
== rightx
&& topy
== bottomy
)
854 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
855 leftx
, topy
, attributes
);
857 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
858 leftx
, topy
, attributes
);
859 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
860 rightx
, topy
, attributes
);
861 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
862 leftx
, bottomy
, attributes
);
863 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
864 rightx
, bottomy
, attributes
);
866 x_offset
= point
->X
- leftxf
;
867 top
= blend_colors(topleft
, topright
, x_offset
);
868 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
870 return blend_colors(top
, bottom
, point
->Y
- topyf
);
872 case InterpolationModeNearestNeighbor
:
873 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
874 roundr(point
->X
), roundr(point
->Y
), attributes
);
878 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
880 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
883 static INT
brush_can_fill_path(GpBrush
*brush
)
887 case BrushTypeSolidColor
:
889 case BrushTypeHatchFill
:
891 GpHatch
*hatch
= (GpHatch
*)brush
;
892 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
893 ((hatch
->backcol
& 0xff000000) == 0xff000000);
895 case BrushTypeLinearGradient
:
896 case BrushTypeTextureFill
:
897 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
903 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
907 case BrushTypeSolidColor
:
909 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
910 HBITMAP bmp
= ARGB2BMP(fill
->color
);
915 /* partially transparent fill */
917 SelectClipPath(graphics
->hdc
, RGN_AND
);
918 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
920 HDC hdc
= CreateCompatibleDC(NULL
);
925 SelectObject(hdc
, bmp
);
927 bf
.BlendOp
= AC_SRC_OVER
;
929 bf
.SourceConstantAlpha
= 255;
930 bf
.AlphaFormat
= AC_SRC_ALPHA
;
932 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
940 /* else fall through */
944 HBRUSH gdibrush
, old_brush
;
946 gdibrush
= create_gdi_brush(brush
);
947 if (!gdibrush
) return;
949 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
950 FillPath(graphics
->hdc
);
951 SelectObject(graphics
->hdc
, old_brush
);
952 DeleteObject(gdibrush
);
958 static INT
brush_can_fill_pixels(GpBrush
*brush
)
962 case BrushTypeSolidColor
:
963 case BrushTypeHatchFill
:
964 case BrushTypeLinearGradient
:
965 case BrushTypeTextureFill
:
966 case BrushTypePathGradient
:
973 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
974 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
978 case BrushTypeSolidColor
:
981 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
982 for (x
=0; x
<fill_area
->Width
; x
++)
983 for (y
=0; y
<fill_area
->Height
; y
++)
984 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
987 case BrushTypeHatchFill
:
990 GpHatch
*fill
= (GpHatch
*)brush
;
991 const char *hatch_data
;
993 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
994 return NotImplemented
;
996 for (x
=0; x
<fill_area
->Width
; x
++)
997 for (y
=0; y
<fill_area
->Height
; y
++)
1001 /* FIXME: Account for the rendering origin */
1002 hx
= (x
+ fill_area
->X
) % 8;
1003 hy
= (y
+ fill_area
->Y
) % 8;
1005 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1006 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1008 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1013 case BrushTypeLinearGradient
:
1015 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1016 GpPointF draw_points
[3], line_points
[3];
1018 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1019 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1022 draw_points
[0].X
= fill_area
->X
;
1023 draw_points
[0].Y
= fill_area
->Y
;
1024 draw_points
[1].X
= fill_area
->X
+1;
1025 draw_points
[1].Y
= fill_area
->Y
;
1026 draw_points
[2].X
= fill_area
->X
;
1027 draw_points
[2].Y
= fill_area
->Y
+1;
1029 /* Transform the points to a co-ordinate space where X is the point's
1030 * position in the gradient, 0.0 being the start point and 1.0 the
1032 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1033 CoordinateSpaceDevice
, draw_points
, 3);
1037 line_points
[0] = fill
->startpoint
;
1038 line_points
[1] = fill
->endpoint
;
1039 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1040 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1042 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1047 stat
= GdipInvertMatrix(world_to_gradient
);
1050 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1052 GdipDeleteMatrix(world_to_gradient
);
1057 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1058 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1060 for (y
=0; y
<fill_area
->Height
; y
++)
1062 for (x
=0; x
<fill_area
->Width
; x
++)
1064 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1066 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1073 case BrushTypeTextureFill
:
1075 GpTexture
*fill
= (GpTexture
*)brush
;
1076 GpPointF draw_points
[3];
1078 GpMatrix
*world_to_texture
;
1084 if (fill
->image
->type
!= ImageTypeBitmap
)
1086 FIXME("metafile texture brushes not implemented\n");
1087 return NotImplemented
;
1090 bitmap
= (GpBitmap
*)fill
->image
;
1091 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1093 src_area
.X
= src_area
.Y
= 0;
1094 src_area
.Width
= bitmap
->width
;
1095 src_area
.Height
= bitmap
->height
;
1097 draw_points
[0].X
= fill_area
->X
;
1098 draw_points
[0].Y
= fill_area
->Y
;
1099 draw_points
[1].X
= fill_area
->X
+1;
1100 draw_points
[1].Y
= fill_area
->Y
;
1101 draw_points
[2].X
= fill_area
->X
;
1102 draw_points
[2].Y
= fill_area
->Y
+1;
1104 /* Transform the points to the co-ordinate space of the bitmap. */
1105 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1106 CoordinateSpaceDevice
, draw_points
, 3);
1110 stat
= GdipCloneMatrix(fill
->transform
, &world_to_texture
);
1115 stat
= GdipInvertMatrix(world_to_texture
);
1118 stat
= GdipTransformMatrixPoints(world_to_texture
, draw_points
, 3);
1120 GdipDeleteMatrix(world_to_texture
);
1123 if (stat
== Ok
&& !fill
->bitmap_bits
)
1125 BitmapData lockeddata
;
1127 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1128 if (!fill
->bitmap_bits
)
1133 lockeddata
.Width
= bitmap
->width
;
1134 lockeddata
.Height
= bitmap
->height
;
1135 lockeddata
.Stride
= src_stride
;
1136 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1137 lockeddata
.Scan0
= fill
->bitmap_bits
;
1139 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1140 PixelFormat32bppARGB
, &lockeddata
);
1144 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1147 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1148 bitmap
->width
, bitmap
->height
,
1149 src_stride
, ColorAdjustTypeBitmap
);
1153 GdipFree(fill
->bitmap_bits
);
1154 fill
->bitmap_bits
= NULL
;
1160 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1161 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1162 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1163 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1165 for (y
=0; y
<fill_area
->Height
; y
++)
1167 for (x
=0; x
<fill_area
->Width
; x
++)
1170 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1171 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1173 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1174 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1175 &point
, fill
->imageattributes
, graphics
->interpolation
);
1182 case BrushTypePathGradient
:
1184 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1186 GpMatrix
*world_to_device
;
1188 int i
, figure_start
=0;
1189 GpPointF start_point
, end_point
, center_point
;
1191 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1192 INT min_y
, max_y
, min_x
, max_x
;
1196 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1200 FIXME("path gradient focus not implemented\n");
1207 FIXME("path gradient gamma correction not implemented\n");
1210 stat
= GdipClonePath(fill
->path
, &flat_path
);
1215 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1216 CoordinateSpaceWorld
, &world_to_device
);
1219 stat
= GdipTransformPath(flat_path
, world_to_device
);
1223 center_point
= fill
->center
;
1224 stat
= GdipTransformMatrixPoints(world_to_device
, ¢er_point
, 1);
1228 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1230 GdipDeleteMatrix(world_to_device
);
1235 GdipDeletePath(flat_path
);
1239 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1241 int start_center_line
=0, end_center_line
=0;
1242 int seen_start
=0, seen_end
=0, seen_center
=0;
1243 REAL center_distance
;
1244 ARGB start_color
, end_color
;
1247 type
= flat_path
->pathdata
.Types
[i
];
1249 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1252 start_point
= flat_path
->pathdata
.Points
[i
];
1254 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1256 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1258 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1259 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1261 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1263 end_point
= flat_path
->pathdata
.Points
[i
+1];
1264 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1269 outer_color
= start_color
;
1271 min_yf
= center_point
.Y
;
1272 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1273 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1275 if (min_yf
< fill_area
->Y
)
1276 min_y
= fill_area
->Y
;
1278 min_y
= (INT
)ceil(min_yf
);
1280 max_yf
= center_point
.Y
;
1281 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1282 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1284 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1285 max_y
= fill_area
->Y
+ fill_area
->Height
;
1287 max_y
= (INT
)ceil(max_yf
);
1289 dy
= end_point
.Y
- start_point
.Y
;
1290 dx
= end_point
.X
- start_point
.X
;
1292 /* This is proportional to the distance from start-end line to center point. */
1293 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1294 dx
* (center_point
.Y
- start_point
.Y
);
1296 for (y
=min_y
; y
<max_y
; y
++)
1300 if (!seen_start
&& yf
>= start_point
.Y
)
1303 start_center_line
^= 1;
1305 if (!seen_end
&& yf
>= end_point
.Y
)
1308 end_center_line
^= 1;
1310 if (!seen_center
&& yf
>= center_point
.Y
)
1313 start_center_line
^= 1;
1314 end_center_line
^= 1;
1317 if (start_center_line
)
1318 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1320 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1322 if (end_center_line
)
1323 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1325 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1327 if (line1_xf
< line2_xf
)
1329 min_x
= (INT
)ceil(line1_xf
);
1330 max_x
= (INT
)ceil(line2_xf
);
1334 min_x
= (INT
)ceil(line2_xf
);
1335 max_x
= (INT
)ceil(line1_xf
);
1338 if (min_x
< fill_area
->X
)
1339 min_x
= fill_area
->X
;
1340 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1341 max_x
= fill_area
->X
+ fill_area
->Width
;
1343 for (x
=min_x
; x
<max_x
; x
++)
1348 if (start_color
!= end_color
)
1350 REAL blend_amount
, pdy
, pdx
;
1351 pdy
= yf
- center_point
.Y
;
1352 pdx
= xf
- center_point
.X
;
1353 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1354 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1357 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1358 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1360 distance
= distance
/ center_distance
;
1362 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1363 blend_colors(outer_color
, fill
->centercolor
, distance
);
1368 GdipDeletePath(flat_path
);
1372 return NotImplemented
;
1376 /* GdipDrawPie/GdipFillPie helper function */
1377 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
1378 REAL height
, REAL startAngle
, REAL sweepAngle
)
1385 ptf
[1].X
= x
+ width
;
1386 ptf
[1].Y
= y
+ height
;
1388 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
1389 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
1391 transform_and_round_points(graphics
, pti
, ptf
, 4);
1393 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
1394 pti
[2].y
, pti
[3].x
, pti
[3].y
);
1397 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1398 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1399 * should not be called on an hdc that has a path you care about. */
1400 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1401 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1403 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1404 GpMatrix
*matrix
= NULL
;
1405 HBRUSH brush
= NULL
;
1407 PointF ptf
[4], *custptf
= NULL
;
1408 POINT pt
[4], *custpt
= NULL
;
1410 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1415 if((x1
== x2
) && (y1
== y2
))
1418 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1420 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1422 brush
= CreateSolidBrush(color
);
1423 lb
.lbStyle
= BS_SOLID
;
1426 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1427 PS_JOIN_MITER
, 1, &lb
, 0,
1429 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1430 oldpen
= SelectObject(graphics
->hdc
, pen
);
1437 case LineCapSquareAnchor
:
1438 case LineCapDiamondAnchor
:
1439 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1440 if(cap
== LineCapDiamondAnchor
){
1441 dsmall
= cos(theta
+ M_PI_2
) * size
;
1442 dbig
= sin(theta
+ M_PI_2
) * size
;
1445 dsmall
= cos(theta
+ M_PI_4
) * size
;
1446 dbig
= sin(theta
+ M_PI_4
) * size
;
1449 ptf
[0].X
= x2
- dsmall
;
1450 ptf
[1].X
= x2
+ dbig
;
1452 ptf
[0].Y
= y2
- dbig
;
1453 ptf
[3].Y
= y2
+ dsmall
;
1455 ptf
[1].Y
= y2
- dsmall
;
1456 ptf
[2].Y
= y2
+ dbig
;
1458 ptf
[3].X
= x2
- dbig
;
1459 ptf
[2].X
= x2
+ dsmall
;
1461 transform_and_round_points(graphics
, pt
, ptf
, 4);
1462 Polygon(graphics
->hdc
, pt
, 4);
1465 case LineCapArrowAnchor
:
1466 size
= size
* 4.0 / sqrt(3.0);
1468 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1469 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1474 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1475 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1483 transform_and_round_points(graphics
, pt
, ptf
, 3);
1484 Polygon(graphics
->hdc
, pt
, 3);
1487 case LineCapRoundAnchor
:
1488 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1495 transform_and_round_points(graphics
, pt
, ptf
, 2);
1496 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1499 case LineCapTriangle
:
1501 dx
= cos(M_PI_2
+ theta
) * size
;
1502 dy
= sin(M_PI_2
+ theta
) * size
;
1509 dx
= cos(theta
) * size
;
1510 dy
= sin(theta
) * size
;
1515 transform_and_round_points(graphics
, pt
, ptf
, 3);
1516 Polygon(graphics
->hdc
, pt
, 3);
1520 dx
= dy
= size
/ 2.0;
1527 dx
= -cos(M_PI_2
+ theta
) * size
;
1528 dy
= -sin(M_PI_2
+ theta
) * size
;
1535 transform_and_round_points(graphics
, pt
, ptf
, 4);
1536 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1537 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1544 count
= custom
->pathdata
.Count
;
1545 custptf
= GdipAlloc(count
* sizeof(PointF
));
1546 custpt
= GdipAlloc(count
* sizeof(POINT
));
1547 tp
= GdipAlloc(count
);
1549 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
1552 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1554 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
1555 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1557 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
1558 GdipTransformMatrixPoints(matrix
, custptf
, count
);
1560 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1562 for(i
= 0; i
< count
; i
++)
1563 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1566 BeginPath(graphics
->hdc
);
1567 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1568 EndPath(graphics
->hdc
);
1569 StrokeAndFillPath(graphics
->hdc
);
1572 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1578 GdipDeleteMatrix(matrix
);
1585 SelectObject(graphics
->hdc
, oldbrush
);
1586 SelectObject(graphics
->hdc
, oldpen
);
1587 DeleteObject(brush
);
1592 /* Shortens the line by the given percent by changing x2, y2.
1593 * If percent is > 1.0 then the line will change direction.
1594 * If percent is negative it can lengthen the line. */
1595 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1597 REAL dist
, theta
, dx
, dy
;
1599 if((y1
== *y2
) && (x1
== *x2
))
1602 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1603 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1604 dx
= cos(theta
) * dist
;
1605 dy
= sin(theta
) * dist
;
1611 /* Shortens the line by the given amount by changing x2, y2.
1612 * If the amount is greater than the distance, the line will become length 0.
1613 * If the amount is negative, it can lengthen the line. */
1614 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1616 REAL dx
, dy
, percent
;
1620 if(dx
== 0 && dy
== 0)
1623 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1630 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1633 /* Draws lines between the given points, and if caps is true then draws an endcap
1634 * at the end of the last line. */
1635 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
1636 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1639 GpPointF
*ptcopy
= NULL
;
1640 GpStatus status
= GenericError
;
1645 pti
= GdipAlloc(count
* sizeof(POINT
));
1646 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1648 if(!pti
|| !ptcopy
){
1649 status
= OutOfMemory
;
1653 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1656 if(pen
->endcap
== LineCapArrowAnchor
)
1657 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1658 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
1659 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1660 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1661 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
1662 pen
->customend
->inset
* pen
->width
);
1664 if(pen
->startcap
== LineCapArrowAnchor
)
1665 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1666 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
1667 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1668 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1669 &ptcopy
[0].X
, &ptcopy
[0].Y
,
1670 pen
->customstart
->inset
* pen
->width
);
1672 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1673 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
1674 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1675 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
1678 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1680 if(Polyline(graphics
->hdc
, pti
, count
))
1690 /* Conducts a linear search to find the bezier points that will back off
1691 * the endpoint of the curve by a distance of amt. Linear search works
1692 * better than binary in this case because there are multiple solutions,
1693 * and binary searches often find a bad one. I don't think this is what
1694 * Windows does but short of rendering the bezier without GDI's help it's
1695 * the best we can do. If rev then work from the start of the passed points
1696 * instead of the end. */
1697 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1700 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1701 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1710 origx
= pt
[fourth
].X
;
1711 origy
= pt
[fourth
].Y
;
1712 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1714 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1715 /* reset bezier points to original values */
1716 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1717 /* Perform magic on bezier points. Order is important here.*/
1718 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1719 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1720 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1721 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1722 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1723 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1725 dx
= pt
[fourth
].X
- origx
;
1726 dy
= pt
[fourth
].Y
- origy
;
1728 diff
= sqrt(dx
* dx
+ dy
* dy
);
1729 percent
+= 0.0005 * amt
;
1733 /* Draws bezier curves between given points, and if caps is true then draws an
1734 * endcap at the end of the last line. */
1735 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
1736 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1740 GpStatus status
= GenericError
;
1745 pti
= GdipAlloc(count
* sizeof(POINT
));
1746 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1748 if(!pti
|| !ptcopy
){
1749 status
= OutOfMemory
;
1753 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1756 if(pen
->endcap
== LineCapArrowAnchor
)
1757 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
1758 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1759 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
1762 if(pen
->startcap
== LineCapArrowAnchor
)
1763 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
1764 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1765 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
1767 /* the direction of the line cap is parallel to the direction at the
1768 * end of the bezier (which, if it has been shortened, is not the same
1769 * as the direction from pt[count-2] to pt[count-1]) */
1770 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1771 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1772 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1773 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1775 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1776 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
1777 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
1780 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1782 PolyBezier(graphics
->hdc
, pti
, count
);
1793 /* Draws a combination of bezier curves and lines between points. */
1794 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1795 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1797 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1798 BYTE
*tp
= GdipAlloc(count
);
1799 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1801 GpStatus status
= GenericError
;
1807 if(!pti
|| !tp
|| !ptcopy
){
1808 status
= OutOfMemory
;
1812 for(i
= 1; i
< count
; i
++){
1813 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1814 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1815 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1816 ERR("Bad bezier points\n");
1823 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1825 /* If we are drawing caps, go through the points and adjust them accordingly,
1826 * and draw the caps. */
1828 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1829 case PathPointTypeBezier
:
1830 if(pen
->endcap
== LineCapArrowAnchor
)
1831 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1832 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1833 shorten_bezier_amt(&ptcopy
[count
- 4],
1834 pen
->width
* pen
->customend
->inset
, FALSE
);
1836 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1837 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1838 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1839 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1842 case PathPointTypeLine
:
1843 if(pen
->endcap
== LineCapArrowAnchor
)
1844 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1845 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1847 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1848 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1849 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1850 pen
->customend
->inset
* pen
->width
);
1852 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1853 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1858 ERR("Bad path last point\n");
1862 /* Find start of points */
1863 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1864 == PathPointTypeStart
); j
++);
1866 switch(types
[j
] & PathPointTypePathTypeMask
){
1867 case PathPointTypeBezier
:
1868 if(pen
->startcap
== LineCapArrowAnchor
)
1869 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1870 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1871 shorten_bezier_amt(&ptcopy
[j
- 1],
1872 pen
->width
* pen
->customstart
->inset
, TRUE
);
1874 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1875 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1876 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1877 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1880 case PathPointTypeLine
:
1881 if(pen
->startcap
== LineCapArrowAnchor
)
1882 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1883 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1885 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1886 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1887 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1888 pen
->customstart
->inset
* pen
->width
);
1890 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1891 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1896 ERR("Bad path points\n");
1901 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1903 for(i
= 0; i
< count
; i
++){
1904 tp
[i
] = convert_path_point_type(types
[i
]);
1907 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1919 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1923 BeginPath(graphics
->hdc
);
1924 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1925 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1926 EndPath(graphics
->hdc
);
1930 typedef struct _GraphicsContainerItem
{
1932 GraphicsContainer contid
;
1934 SmoothingMode smoothing
;
1935 CompositingQuality compqual
;
1936 InterpolationMode interpolation
;
1937 CompositingMode compmode
;
1938 TextRenderingHint texthint
;
1941 PixelOffsetMode pixeloffset
;
1943 GpMatrix
* worldtrans
;
1945 } GraphicsContainerItem
;
1947 static GpStatus
init_container(GraphicsContainerItem
** container
,
1948 GDIPCONST GpGraphics
* graphics
){
1951 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1955 (*container
)->contid
= graphics
->contid
+ 1;
1957 (*container
)->smoothing
= graphics
->smoothing
;
1958 (*container
)->compqual
= graphics
->compqual
;
1959 (*container
)->interpolation
= graphics
->interpolation
;
1960 (*container
)->compmode
= graphics
->compmode
;
1961 (*container
)->texthint
= graphics
->texthint
;
1962 (*container
)->scale
= graphics
->scale
;
1963 (*container
)->unit
= graphics
->unit
;
1964 (*container
)->textcontrast
= graphics
->textcontrast
;
1965 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1967 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1969 GdipFree(*container
);
1974 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1976 GdipDeleteMatrix((*container
)->worldtrans
);
1977 GdipFree(*container
);
1985 static void delete_container(GraphicsContainerItem
* container
){
1986 GdipDeleteMatrix(container
->worldtrans
);
1987 GdipDeleteRegion(container
->clip
);
1988 GdipFree(container
);
1991 static GpStatus
restore_container(GpGraphics
* graphics
,
1992 GDIPCONST GraphicsContainerItem
* container
){
1997 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
2001 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2003 GdipDeleteMatrix(newTrans
);
2007 GdipDeleteMatrix(graphics
->worldtrans
);
2008 graphics
->worldtrans
= newTrans
;
2010 GdipDeleteRegion(graphics
->clip
);
2011 graphics
->clip
= newClip
;
2013 graphics
->contid
= container
->contid
- 1;
2015 graphics
->smoothing
= container
->smoothing
;
2016 graphics
->compqual
= container
->compqual
;
2017 graphics
->interpolation
= container
->interpolation
;
2018 graphics
->compmode
= container
->compmode
;
2019 graphics
->texthint
= container
->texthint
;
2020 graphics
->scale
= container
->scale
;
2021 graphics
->unit
= container
->unit
;
2022 graphics
->textcontrast
= container
->textcontrast
;
2023 graphics
->pixeloffset
= container
->pixeloffset
;
2028 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2034 if(graphics
->hwnd
) {
2035 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2036 return GenericError
;
2038 rect
->X
= wnd_rect
.left
;
2039 rect
->Y
= wnd_rect
.top
;
2040 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2041 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2042 }else if (graphics
->image
){
2043 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2044 if (stat
== Ok
&& unit
!= UnitPixel
)
2045 FIXME("need to convert from unit %i\n", unit
);
2049 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2050 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2056 /* on success, rgn will contain the region of the graphics object which
2057 * is visible after clipping has been applied */
2058 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2064 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2067 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2070 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2073 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2076 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2079 GdipDeleteRegion(tmp
);
2083 void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
, HFONT
*hfont
)
2085 HDC hdc
= CreateCompatibleDC(0);
2087 REAL angle
, rel_width
, rel_height
;
2089 HFONT unscaled_font
;
2090 TEXTMETRICW textmet
;
2099 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2100 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2101 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2102 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2103 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2104 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2107 lfw
.lfHeight
= roundr(-font
->pixel_size
* rel_height
);
2108 unscaled_font
= CreateFontIndirectW(&lfw
);
2110 SelectObject(hdc
, unscaled_font
);
2111 GetTextMetricsW(hdc
, &textmet
);
2114 lfw
.lfHeight
= roundr(-font
->pixel_size
* rel_height
);
2115 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2116 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
2118 *hfont
= CreateFontIndirectW(&lfw
);
2121 DeleteObject(unscaled_font
);
2124 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2126 TRACE("(%p, %p)\n", hdc
, graphics
);
2128 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2131 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2135 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2137 if(hDevice
!= NULL
) {
2138 FIXME("Don't know how to handle parameter hDevice\n");
2139 return NotImplemented
;
2145 if(graphics
== NULL
)
2146 return InvalidParameter
;
2148 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2149 if(!*graphics
) return OutOfMemory
;
2151 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
2152 GdipFree(*graphics
);
2156 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2157 GdipFree((*graphics
)->worldtrans
);
2158 GdipFree(*graphics
);
2162 (*graphics
)->hdc
= hdc
;
2163 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2164 (*graphics
)->owndc
= FALSE
;
2165 (*graphics
)->smoothing
= SmoothingModeDefault
;
2166 (*graphics
)->compqual
= CompositingQualityDefault
;
2167 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2168 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2169 (*graphics
)->compmode
= CompositingModeSourceOver
;
2170 (*graphics
)->unit
= UnitDisplay
;
2171 (*graphics
)->scale
= 1.0;
2172 (*graphics
)->busy
= FALSE
;
2173 (*graphics
)->textcontrast
= 4;
2174 list_init(&(*graphics
)->containers
);
2175 (*graphics
)->contid
= 0;
2177 TRACE("<-- %p\n", *graphics
);
2182 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2186 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2187 if(!*graphics
) return OutOfMemory
;
2189 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
2190 GdipFree(*graphics
);
2194 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2195 GdipFree((*graphics
)->worldtrans
);
2196 GdipFree(*graphics
);
2200 (*graphics
)->hdc
= NULL
;
2201 (*graphics
)->hwnd
= NULL
;
2202 (*graphics
)->owndc
= FALSE
;
2203 (*graphics
)->image
= image
;
2204 (*graphics
)->smoothing
= SmoothingModeDefault
;
2205 (*graphics
)->compqual
= CompositingQualityDefault
;
2206 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2207 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2208 (*graphics
)->compmode
= CompositingModeSourceOver
;
2209 (*graphics
)->unit
= UnitDisplay
;
2210 (*graphics
)->scale
= 1.0;
2211 (*graphics
)->busy
= FALSE
;
2212 (*graphics
)->textcontrast
= 4;
2213 list_init(&(*graphics
)->containers
);
2214 (*graphics
)->contid
= 0;
2216 TRACE("<-- %p\n", *graphics
);
2221 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2226 TRACE("(%p, %p)\n", hwnd
, graphics
);
2230 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2232 ReleaseDC(hwnd
, hdc
);
2236 (*graphics
)->hwnd
= hwnd
;
2237 (*graphics
)->owndc
= TRUE
;
2242 /* FIXME: no icm handling */
2243 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2245 TRACE("(%p, %p)\n", hwnd
, graphics
);
2247 return GdipCreateFromHWND(hwnd
, graphics
);
2250 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2251 GpMetafile
**metafile
)
2253 IStream
*stream
= NULL
;
2255 ENHMETAHEADER
*copy
;
2256 GpStatus retval
= Ok
;
2258 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2260 if(!hemf
|| !metafile
)
2261 return InvalidParameter
;
2263 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
2264 copy
= GdipAlloc(read
);
2265 GetEnhMetaFileBits(hemf
, read
, (BYTE
*)copy
);
2267 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
2268 ERR("could not make stream\n");
2270 retval
= GenericError
;
2274 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2276 retval
= OutOfMemory
;
2280 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
2281 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
2283 retval
= GenericError
;
2288 (*metafile
)->image
.type
= ImageTypeMetafile
;
2289 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
2290 (*metafile
)->image
.palette_flags
= 0;
2291 (*metafile
)->image
.palette_count
= 0;
2292 (*metafile
)->image
.palette_size
= 0;
2293 (*metafile
)->image
.palette_entries
= NULL
;
2294 (*metafile
)->image
.xres
= (REAL
)copy
->szlDevice
.cx
;
2295 (*metafile
)->image
.yres
= (REAL
)copy
->szlDevice
.cy
;
2296 (*metafile
)->bounds
.X
= (REAL
)copy
->rclBounds
.left
;
2297 (*metafile
)->bounds
.Y
= (REAL
)copy
->rclBounds
.top
;
2298 (*metafile
)->bounds
.Width
= (REAL
)(copy
->rclBounds
.right
- copy
->rclBounds
.left
);
2299 (*metafile
)->bounds
.Height
= (REAL
)(copy
->rclBounds
.bottom
- copy
->rclBounds
.top
);
2300 (*metafile
)->unit
= UnitPixel
;
2303 DeleteEnhMetaFile(hemf
);
2305 TRACE("<-- %p\n", *metafile
);
2309 GdipFree(*metafile
);
2310 IStream_Release(stream
);
2314 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2315 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2320 GpStatus retval
= Ok
;
2322 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2324 if(!hwmf
|| !metafile
|| !placeable
)
2325 return InvalidParameter
;
2328 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2330 return GenericError
;
2331 copy
= GdipAlloc(read
);
2332 GetMetaFileBitsEx(hwmf
, read
, copy
);
2334 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2337 retval
= GdipCreateMetafileFromEmf(hemf
, FALSE
, metafile
);
2341 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2342 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2343 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2344 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2345 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2346 placeable
->BoundingBox
.Left
);
2347 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2348 placeable
->BoundingBox
.Top
);
2350 if (delete) DeleteMetaFile(hwmf
);
2355 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2356 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2358 HMETAFILE hmf
= GetMetaFileW(file
);
2360 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2362 if(!hmf
) return InvalidParameter
;
2364 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2367 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2368 GpMetafile
**metafile
)
2370 FIXME("(%p, %p): stub\n", file
, metafile
);
2371 return NotImplemented
;
2374 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2375 GpMetafile
**metafile
)
2377 FIXME("(%p, %p): stub\n", stream
, metafile
);
2378 return NotImplemented
;
2381 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2382 UINT access
, IStream
**stream
)
2387 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2389 if(!stream
|| !filename
)
2390 return InvalidParameter
;
2392 if(access
& GENERIC_WRITE
)
2393 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2394 else if(access
& GENERIC_READ
)
2395 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2397 return InvalidParameter
;
2399 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2401 return hresult_to_status(ret
);
2404 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2406 GraphicsContainerItem
*cont
, *next
;
2408 TRACE("(%p)\n", graphics
);
2410 if(!graphics
) return InvalidParameter
;
2411 if(graphics
->busy
) return ObjectBusy
;
2413 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2415 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2421 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2423 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2424 list_remove(&cont
->entry
);
2425 delete_container(cont
);
2428 GdipDeleteRegion(graphics
->clip
);
2429 GdipDeleteMatrix(graphics
->worldtrans
);
2435 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2436 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2438 INT save_state
, num_pts
;
2439 GpPointF points
[MAX_ARC_PTS
];
2442 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2443 width
, height
, startAngle
, sweepAngle
);
2445 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2446 return InvalidParameter
;
2453 FIXME("graphics object has no HDC\n");
2457 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2459 save_state
= prepare_dc(graphics
, pen
);
2461 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
2463 restore_dc(graphics
, save_state
);
2468 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2469 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2471 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2472 width
, height
, startAngle
, sweepAngle
);
2474 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2477 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2478 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2484 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2485 x2
, y2
, x3
, y3
, x4
, y4
);
2487 if(!graphics
|| !pen
)
2488 return InvalidParameter
;
2495 FIXME("graphics object has no HDC\n");
2508 save_state
= prepare_dc(graphics
, pen
);
2510 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2512 restore_dc(graphics
, save_state
);
2517 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2518 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2524 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2525 x2
, y2
, x3
, y3
, x4
, y4
);
2527 if(!graphics
|| !pen
)
2528 return InvalidParameter
;
2535 FIXME("graphics object has no HDC\n");
2548 save_state
= prepare_dc(graphics
, pen
);
2550 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2552 restore_dc(graphics
, save_state
);
2557 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2558 GDIPCONST GpPointF
*points
, INT count
)
2563 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2565 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2566 return InvalidParameter
;
2571 for(i
= 0; i
< floor(count
/ 4); i
++){
2572 ret
= GdipDrawBezier(graphics
, pen
,
2573 points
[4*i
].X
, points
[4*i
].Y
,
2574 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
2575 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
2576 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
2584 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2585 GDIPCONST GpPoint
*points
, INT count
)
2591 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2593 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2594 return InvalidParameter
;
2599 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2603 for(i
= 0; i
< count
; i
++){
2604 pts
[i
].X
= (REAL
)points
[i
].X
;
2605 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2608 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2615 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2616 GDIPCONST GpPointF
*points
, INT count
)
2618 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2620 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2623 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2624 GDIPCONST GpPoint
*points
, INT count
)
2626 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2628 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2631 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2632 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2637 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2639 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2640 return InvalidParameter
;
2645 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
2648 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2650 GdipDeletePath(path
);
2654 stat
= GdipDrawPath(graphics
, pen
, path
);
2656 GdipDeletePath(path
);
2661 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2662 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2668 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2670 if(!points
|| count
<= 0)
2671 return InvalidParameter
;
2673 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2677 for(i
= 0; i
< count
; i
++){
2678 ptf
[i
].X
= (REAL
)points
[i
].X
;
2679 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2682 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2689 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2690 GDIPCONST GpPointF
*points
, INT count
)
2692 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2694 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2697 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2698 GDIPCONST GpPoint
*points
, INT count
)
2704 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2707 return InvalidParameter
;
2709 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2713 for(i
= 0; i
< count
; i
++){
2714 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2715 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2718 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2724 /* Approximates cardinal spline with Bezier curves. */
2725 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2726 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2728 /* PolyBezier expects count*3-2 points. */
2729 INT i
, len_pt
= count
*3-2, save_state
;
2731 REAL x1
, x2
, y1
, y2
;
2734 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2736 if(!graphics
|| !pen
)
2737 return InvalidParameter
;
2743 return InvalidParameter
;
2747 FIXME("graphics object has no HDC\n");
2751 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
2755 tension
= tension
* TENSION_CONST
;
2757 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
2760 pt
[0].X
= points
[0].X
;
2761 pt
[0].Y
= points
[0].Y
;
2765 for(i
= 0; i
< count
-2; i
++){
2766 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
2770 pt
[3*i
+3].X
= points
[i
+1].X
;
2771 pt
[3*i
+3].Y
= points
[i
+1].Y
;
2776 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
2777 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
2779 pt
[len_pt
-2].X
= x1
;
2780 pt
[len_pt
-2].Y
= y1
;
2781 pt
[len_pt
-1].X
= points
[count
-1].X
;
2782 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
2784 save_state
= prepare_dc(graphics
, pen
);
2786 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
2789 restore_dc(graphics
, save_state
);
2794 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2795 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2801 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2804 return InvalidParameter
;
2806 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2810 for(i
= 0; i
< count
; i
++){
2811 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2812 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2815 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2821 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2822 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2825 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2827 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2828 return InvalidParameter
;
2831 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2834 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2835 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2838 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2844 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2845 return InvalidParameter
;
2848 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2851 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2852 REAL y
, REAL width
, REAL height
)
2858 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2860 if(!graphics
|| !pen
)
2861 return InvalidParameter
;
2868 FIXME("graphics object has no HDC\n");
2874 ptf
[1].X
= x
+ width
;
2875 ptf
[1].Y
= y
+ height
;
2877 save_state
= prepare_dc(graphics
, pen
);
2878 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2880 transform_and_round_points(graphics
, pti
, ptf
, 2);
2882 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2884 restore_dc(graphics
, save_state
);
2889 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2890 INT y
, INT width
, INT height
)
2892 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2894 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2898 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2903 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2905 if(!graphics
|| !image
)
2906 return InvalidParameter
;
2908 GdipGetImageWidth(image
, &width
);
2909 GdipGetImageHeight(image
, &height
);
2911 /* FIXME: we should use the graphics and image dpi, somehow */
2913 points
[0].X
= points
[2].X
= x
;
2914 points
[0].Y
= points
[1].Y
= y
;
2915 points
[1].X
= x
+ width
;
2916 points
[2].Y
= y
+ height
;
2918 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
2919 UnitPixel
, NULL
, NULL
, NULL
);
2922 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2925 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2927 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2930 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2931 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2935 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2937 points
[0].X
= points
[2].X
= x
;
2938 points
[0].Y
= points
[1].Y
= y
;
2940 /* FIXME: convert image coordinates to Graphics coordinates? */
2941 points
[1].X
= x
+ srcwidth
;
2942 points
[2].Y
= y
+ srcheight
;
2944 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2945 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2948 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2949 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2952 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2955 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2956 GDIPCONST GpPointF
*dstpoints
, INT count
)
2960 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2963 return InvalidParameter
;
2965 GdipGetImageWidth(image
, &width
);
2966 GdipGetImageHeight(image
, &height
);
2968 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2969 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2972 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2973 GDIPCONST GpPoint
*dstpoints
, INT count
)
2977 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2979 if (count
!= 3 || !dstpoints
)
2980 return InvalidParameter
;
2982 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2983 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2984 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2985 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2986 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2987 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2989 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2992 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2993 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2994 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2995 DrawImageAbort callback
, VOID
* callbackData
)
3002 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
3003 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3007 return NotImplemented
;
3009 if(!graphics
|| !image
|| !points
|| count
!= 3)
3010 return InvalidParameter
;
3012 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
3013 debugstr_pointf(&points
[2]));
3015 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
3016 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
3017 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
3018 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
3020 transform_and_round_points(graphics
, pti
, ptf
, 4);
3026 FIXME("graphics object has no HDC\n");
3029 /* FIXME: partially implemented (only works for rectangular parallelograms) */
3030 if(srcUnit
== UnitInch
)
3031 dx
= dy
= (REAL
) INCH_HIMETRIC
;
3032 else if(srcUnit
== UnitPixel
){
3033 dx
= ((REAL
) INCH_HIMETRIC
) /
3034 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
3035 dy
= ((REAL
) INCH_HIMETRIC
) /
3036 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
3039 return NotImplemented
;
3041 if(IPicture_Render(image
->picture
, graphics
->hdc
,
3042 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3043 srcx
* dx
, srcy
* dy
,
3044 srcwidth
* dx
, srcheight
* dy
,
3047 callback(callbackData
);
3048 return GenericError
;
3051 else if (image
->type
== ImageTypeBitmap
)
3053 GpBitmap
* bitmap
= (GpBitmap
*)image
;
3056 if (srcUnit
== UnitInch
)
3057 dx
= dy
= 96.0; /* FIXME: use the image resolution */
3058 else if (srcUnit
== UnitPixel
)
3061 return NotImplemented
;
3065 srcwidth
= srcwidth
* dx
;
3066 srcheight
= srcheight
* dy
;
3068 if (imageAttributes
||
3069 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
3070 !((GpBitmap
*)image
)->hbitmap
||
3071 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
3072 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
3073 srcx
< 0 || srcy
< 0 ||
3074 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
3081 int i
, x
, y
, src_stride
, dst_stride
;
3082 GpMatrix
*dst_to_src
;
3083 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
3084 LPBYTE src_data
, dst_data
;
3085 BitmapData lockeddata
;
3086 InterpolationMode interpolation
= graphics
->interpolation
;
3087 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3088 REAL x_dx
, x_dy
, y_dx
, y_dy
;
3089 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
3091 if (!imageAttributes
)
3092 imageAttributes
= &defaultImageAttributes
;
3094 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3095 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3098 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3099 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3100 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3101 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3104 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3105 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3106 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3107 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3108 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3109 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3111 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
3112 if (stat
!= Ok
) return stat
;
3114 stat
= GdipInvertMatrix(dst_to_src
);
3117 GdipDeleteMatrix(dst_to_src
);
3121 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3124 GdipDeleteMatrix(dst_to_src
);
3128 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3130 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3131 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3133 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3137 GdipDeleteMatrix(dst_to_src
);
3140 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3142 /* Read the bits we need from the source bitmap into an ARGB buffer. */
3143 lockeddata
.Width
= src_area
.Width
;
3144 lockeddata
.Height
= src_area
.Height
;
3145 lockeddata
.Stride
= src_stride
;
3146 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3147 lockeddata
.Scan0
= src_data
;
3149 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3150 PixelFormat32bppARGB
, &lockeddata
);
3153 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3157 if (src_data
!= dst_data
)
3160 GdipDeleteMatrix(dst_to_src
);
3164 apply_image_attributes(imageAttributes
, src_data
,
3165 src_area
.Width
, src_area
.Height
,
3166 src_stride
, ColorAdjustTypeBitmap
);
3168 /* Transform the bits as needed to the destination. */
3169 GdipTransformMatrixPoints(dst_to_src
, dst_to_src_points
, 3);
3171 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3172 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3173 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3174 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3176 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3178 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3180 GpPointF src_pointf
;
3183 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3184 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3186 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3188 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3189 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
, imageAttributes
, interpolation
);
3195 GdipDeleteMatrix(dst_to_src
);
3199 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3200 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3209 int temp_hdc
=0, temp_bitmap
=0;
3210 HBITMAP hbitmap
, old_hbm
=NULL
;
3212 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3213 bitmap
->format
== PixelFormat24bppRGB
||
3214 bitmap
->format
== PixelFormat32bppRGB
||
3215 bitmap
->format
== PixelFormat32bppPARGB
))
3217 BITMAPINFOHEADER bih
;
3219 PixelFormat dst_format
;
3221 /* we can't draw a bitmap of this format directly */
3222 hdc
= CreateCompatibleDC(0);
3226 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3227 bih
.biWidth
= bitmap
->width
;
3228 bih
.biHeight
= -bitmap
->height
;
3230 bih
.biBitCount
= 32;
3231 bih
.biCompression
= BI_RGB
;
3232 bih
.biSizeImage
= 0;
3233 bih
.biXPelsPerMeter
= 0;
3234 bih
.biYPelsPerMeter
= 0;
3236 bih
.biClrImportant
= 0;
3238 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3239 (void**)&temp_bits
, NULL
, 0);
3241 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3242 dst_format
= PixelFormat32bppPARGB
;
3244 dst_format
= PixelFormat32bppRGB
;
3246 convert_pixels(bitmap
->width
, bitmap
->height
,
3247 bitmap
->width
*4, temp_bits
, dst_format
,
3248 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
3252 hbitmap
= bitmap
->hbitmap
;
3254 temp_hdc
= (hdc
== 0);
3259 if (!hdc
) hdc
= CreateCompatibleDC(0);
3260 old_hbm
= SelectObject(hdc
, hbitmap
);
3263 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3267 bf
.BlendOp
= AC_SRC_OVER
;
3269 bf
.SourceConstantAlpha
= 255;
3270 bf
.AlphaFormat
= AC_SRC_ALPHA
;
3272 GdiAlphaBlend(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3273 hdc
, srcx
, srcy
, srcwidth
, srcheight
, bf
);
3277 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3278 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3283 SelectObject(hdc
, old_hbm
);
3288 DeleteObject(hbitmap
);
3293 ERR("GpImage with no IPicture or HBITMAP?!\n");
3294 return NotImplemented
;
3300 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3301 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3302 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3303 DrawImageAbort callback
, VOID
* callbackData
)
3305 GpPointF pointsF
[3];
3308 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3309 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3312 if(!points
|| count
!=3)
3313 return InvalidParameter
;
3315 for(i
= 0; i
< count
; i
++){
3316 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3317 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3320 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3321 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3322 callback
, callbackData
);
3325 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3326 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3327 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3328 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3329 VOID
* callbackData
)
3333 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3334 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3335 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3339 points
[1].X
= dstx
+ dstwidth
;
3342 points
[2].Y
= dsty
+ dstheight
;
3344 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3345 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3348 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3349 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3350 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3351 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3352 VOID
* callbackData
)
3356 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3357 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3358 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3362 points
[1].X
= dstx
+ dstwidth
;
3365 points
[2].Y
= dsty
+ dstheight
;
3367 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3368 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3371 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3372 REAL x
, REAL y
, REAL width
, REAL height
)
3378 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3380 if(!graphics
|| !image
)
3381 return InvalidParameter
;
3383 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3387 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3388 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3389 unit
, NULL
, NULL
, NULL
);
3392 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3393 INT x
, INT y
, INT width
, INT height
)
3395 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3397 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3400 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3401 REAL y1
, REAL x2
, REAL y2
)
3407 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3409 if(!pen
|| !graphics
)
3410 return InvalidParameter
;
3417 FIXME("graphics object has no HDC\n");
3426 save_state
= prepare_dc(graphics
, pen
);
3428 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3430 restore_dc(graphics
, save_state
);
3435 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3436 INT y1
, INT x2
, INT y2
)
3442 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3444 if(!pen
|| !graphics
)
3445 return InvalidParameter
;
3452 FIXME("graphics object has no HDC\n");
3461 save_state
= prepare_dc(graphics
, pen
);
3463 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3465 restore_dc(graphics
, save_state
);
3470 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3471 GpPointF
*points
, INT count
)
3476 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3478 if(!pen
|| !graphics
|| (count
< 2))
3479 return InvalidParameter
;
3486 FIXME("graphics object has no HDC\n");
3490 save_state
= prepare_dc(graphics
, pen
);
3492 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
3494 restore_dc(graphics
, save_state
);
3499 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3500 GpPoint
*points
, INT count
)
3504 GpPointF
*ptf
= NULL
;
3507 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3509 if(!pen
|| !graphics
|| (count
< 2))
3510 return InvalidParameter
;
3517 FIXME("graphics object has no HDC\n");
3521 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3522 if(!ptf
) return OutOfMemory
;
3524 for(i
= 0; i
< count
; i
++){
3525 ptf
[i
].X
= (REAL
) points
[i
].X
;
3526 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3529 save_state
= prepare_dc(graphics
, pen
);
3531 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
3533 restore_dc(graphics
, save_state
);
3539 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3544 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3546 if(!pen
|| !graphics
)
3547 return InvalidParameter
;
3554 FIXME("graphics object has no HDC\n");
3558 save_state
= prepare_dc(graphics
, pen
);
3560 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3561 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3563 restore_dc(graphics
, save_state
);
3568 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3569 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3573 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3574 width
, height
, startAngle
, sweepAngle
);
3576 if(!graphics
|| !pen
)
3577 return InvalidParameter
;
3584 FIXME("graphics object has no HDC\n");
3588 save_state
= prepare_dc(graphics
, pen
);
3589 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3591 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3593 restore_dc(graphics
, save_state
);
3598 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3599 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3601 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3602 width
, height
, startAngle
, sweepAngle
);
3604 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3607 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3608 REAL y
, REAL width
, REAL height
)
3614 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3616 if(!pen
|| !graphics
)
3617 return InvalidParameter
;
3624 FIXME("graphics object has no HDC\n");
3630 ptf
[1].X
= x
+ width
;
3632 ptf
[2].X
= x
+ width
;
3633 ptf
[2].Y
= y
+ height
;
3635 ptf
[3].Y
= y
+ height
;
3637 save_state
= prepare_dc(graphics
, pen
);
3638 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3640 transform_and_round_points(graphics
, pti
, ptf
, 4);
3641 Polygon(graphics
->hdc
, pti
, 4);
3643 restore_dc(graphics
, save_state
);
3648 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3649 INT y
, INT width
, INT height
)
3651 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3653 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3656 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3657 GDIPCONST GpRectF
* rects
, INT count
)
3663 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3665 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3666 return InvalidParameter
;
3673 FIXME("graphics object has no HDC\n");
3677 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
3678 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
3686 for(i
= 0; i
< count
; i
++){
3687 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
3688 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
3689 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
3690 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
3693 save_state
= prepare_dc(graphics
, pen
);
3694 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3696 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
3698 for(i
= 0; i
< count
; i
++)
3699 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
3701 restore_dc(graphics
, save_state
);
3709 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3710 GDIPCONST GpRect
* rects
, INT count
)
3716 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3718 if(!rects
|| count
<=0)
3719 return InvalidParameter
;
3721 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3725 for(i
= 0;i
< count
;i
++){
3726 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3727 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3728 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3729 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3732 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3738 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3739 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3744 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3745 count
, tension
, fill
);
3747 if(!graphics
|| !brush
|| !points
)
3748 return InvalidParameter
;
3753 if(count
== 1) /* Do nothing */
3756 stat
= GdipCreatePath(fill
, &path
);
3760 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3762 GdipDeletePath(path
);
3766 stat
= GdipFillPath(graphics
, brush
, path
);
3768 GdipDeletePath(path
);
3772 GdipDeletePath(path
);
3777 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3778 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3784 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3785 count
, tension
, fill
);
3787 if(!points
|| count
== 0)
3788 return InvalidParameter
;
3790 if(count
== 1) /* Do nothing */
3793 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3797 for(i
= 0;i
< count
;i
++){
3798 ptf
[i
].X
= (REAL
)points
[i
].X
;
3799 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3802 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3809 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3810 GDIPCONST GpPointF
*points
, INT count
)
3812 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3813 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3814 0.5f
, FillModeAlternate
);
3817 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3818 GDIPCONST GpPoint
*points
, INT count
)
3820 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3821 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3822 0.5f
, FillModeAlternate
);
3825 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3826 REAL y
, REAL width
, REAL height
)
3831 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3833 if(!graphics
|| !brush
)
3834 return InvalidParameter
;
3839 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3843 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3846 stat
= GdipFillPath(graphics
, brush
, path
);
3848 GdipDeletePath(path
);
3854 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3855 INT y
, INT width
, INT height
)
3857 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3859 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3862 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3867 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3868 return NotImplemented
;
3870 save_state
= SaveDC(graphics
->hdc
);
3871 EndPath(graphics
->hdc
);
3872 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3875 BeginPath(graphics
->hdc
);
3876 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3877 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3882 EndPath(graphics
->hdc
);
3883 brush_fill_path(graphics
, brush
);
3888 RestoreDC(graphics
->hdc
, save_state
);
3893 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3898 if (!brush_can_fill_pixels(brush
))
3899 return NotImplemented
;
3901 /* FIXME: This could probably be done more efficiently without regions. */
3903 stat
= GdipCreateRegionPath(path
, &rgn
);
3907 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3909 GdipDeleteRegion(rgn
);
3915 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3917 GpStatus stat
= NotImplemented
;
3919 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3921 if(!brush
|| !graphics
|| !path
)
3922 return InvalidParameter
;
3927 if (!graphics
->image
)
3928 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3930 if (stat
== NotImplemented
)
3931 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3933 if (stat
== NotImplemented
)
3935 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3942 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3943 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3948 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3949 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3951 if(!graphics
|| !brush
)
3952 return InvalidParameter
;
3957 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3961 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3964 stat
= GdipFillPath(graphics
, brush
, path
);
3966 GdipDeletePath(path
);
3972 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3973 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3975 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3976 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3978 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3981 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3982 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3987 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3989 if(!graphics
|| !brush
|| !points
|| !count
)
3990 return InvalidParameter
;
3995 stat
= GdipCreatePath(fillMode
, &path
);
3999 stat
= GdipAddPathPolygon(path
, points
, count
);
4002 stat
= GdipFillPath(graphics
, brush
, path
);
4004 GdipDeletePath(path
);
4010 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4011 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4016 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4018 if(!graphics
|| !brush
|| !points
|| !count
)
4019 return InvalidParameter
;
4024 stat
= GdipCreatePath(fillMode
, &path
);
4028 stat
= GdipAddPathPolygonI(path
, points
, count
);
4031 stat
= GdipFillPath(graphics
, brush
, path
);
4033 GdipDeletePath(path
);
4039 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4040 GDIPCONST GpPointF
*points
, INT count
)
4042 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4044 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4047 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4048 GDIPCONST GpPoint
*points
, INT count
)
4050 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4052 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4055 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4056 REAL x
, REAL y
, REAL width
, REAL height
)
4061 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4063 if(!graphics
|| !brush
)
4064 return InvalidParameter
;
4069 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4073 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
4076 stat
= GdipFillPath(graphics
, brush
, path
);
4078 GdipDeletePath(path
);
4084 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4085 INT x
, INT y
, INT width
, INT height
)
4087 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4089 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
4092 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4098 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4101 return InvalidParameter
;
4103 for(i
= 0; i
< count
; i
++){
4104 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
4105 if(ret
!= Ok
) return ret
;
4111 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4118 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4120 if(!rects
|| count
<= 0)
4121 return InvalidParameter
;
4123 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
4127 for(i
= 0; i
< count
; i
++){
4128 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4129 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4130 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
4131 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4134 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4140 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4148 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
4149 return NotImplemented
;
4151 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4155 save_state
= SaveDC(graphics
->hdc
);
4156 EndPath(graphics
->hdc
);
4158 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4160 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4162 BeginPath(graphics
->hdc
);
4163 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4164 EndPath(graphics
->hdc
);
4166 brush_fill_path(graphics
, brush
);
4169 RestoreDC(graphics
->hdc
, save_state
);
4176 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4180 GpRegion
*temp_region
;
4181 GpMatrix
*world_to_device
;
4182 GpRectF graphics_bounds
;
4186 GpRect gp_bound_rect
;
4188 if (!brush_can_fill_pixels(brush
))
4189 return NotImplemented
;
4191 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
4194 stat
= GdipCloneRegion(region
, &temp_region
);
4198 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
4199 CoordinateSpaceWorld
, &world_to_device
);
4203 stat
= GdipTransformRegion(temp_region
, world_to_device
);
4205 GdipDeleteMatrix(world_to_device
);
4209 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4212 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4214 GdipDeleteRegion(temp_region
);
4217 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4219 DeleteObject(hregion
);
4225 gp_bound_rect
.X
= bound_rect
.left
;
4226 gp_bound_rect
.Y
= bound_rect
.top
;
4227 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4228 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4230 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4236 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4237 &gp_bound_rect
, gp_bound_rect
.Width
);
4240 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4241 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4242 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4244 GdipFree(pixel_data
);
4247 DeleteObject(hregion
);
4253 /*****************************************************************************
4254 * GdipFillRegion [GDIPLUS.@]
4256 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4259 GpStatus stat
= NotImplemented
;
4261 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4263 if (!(graphics
&& brush
&& region
))
4264 return InvalidParameter
;
4269 if (!graphics
->image
)
4270 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4272 if (stat
== NotImplemented
)
4273 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4275 if (stat
== NotImplemented
)
4277 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4284 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4286 TRACE("(%p,%u)\n", graphics
, intention
);
4289 return InvalidParameter
;
4294 /* We have no internal operation queue, so there's no need to clear it. */
4302 /*****************************************************************************
4303 * GdipGetClipBounds [GDIPLUS.@]
4305 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4307 TRACE("(%p, %p)\n", graphics
, rect
);
4310 return InvalidParameter
;
4315 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4318 /*****************************************************************************
4319 * GdipGetClipBoundsI [GDIPLUS.@]
4321 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4323 TRACE("(%p, %p)\n", graphics
, rect
);
4326 return InvalidParameter
;
4331 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4334 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4335 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4336 CompositingMode
*mode
)
4338 TRACE("(%p, %p)\n", graphics
, mode
);
4340 if(!graphics
|| !mode
)
4341 return InvalidParameter
;
4346 *mode
= graphics
->compmode
;
4351 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4352 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4353 CompositingQuality
*quality
)
4355 TRACE("(%p, %p)\n", graphics
, quality
);
4357 if(!graphics
|| !quality
)
4358 return InvalidParameter
;
4363 *quality
= graphics
->compqual
;
4368 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4369 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4370 InterpolationMode
*mode
)
4372 TRACE("(%p, %p)\n", graphics
, mode
);
4374 if(!graphics
|| !mode
)
4375 return InvalidParameter
;
4380 *mode
= graphics
->interpolation
;
4385 /* FIXME: Need to handle color depths less than 24bpp */
4386 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4388 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4390 if(!graphics
|| !argb
)
4391 return InvalidParameter
;
4399 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4401 TRACE("(%p, %p)\n", graphics
, scale
);
4403 if(!graphics
|| !scale
)
4404 return InvalidParameter
;
4409 *scale
= graphics
->scale
;
4414 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4416 TRACE("(%p, %p)\n", graphics
, unit
);
4418 if(!graphics
|| !unit
)
4419 return InvalidParameter
;
4424 *unit
= graphics
->unit
;
4429 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4430 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4433 TRACE("(%p, %p)\n", graphics
, mode
);
4435 if(!graphics
|| !mode
)
4436 return InvalidParameter
;
4441 *mode
= graphics
->pixeloffset
;
4446 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4447 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4449 TRACE("(%p, %p)\n", graphics
, mode
);
4451 if(!graphics
|| !mode
)
4452 return InvalidParameter
;
4457 *mode
= graphics
->smoothing
;
4462 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4464 TRACE("(%p, %p)\n", graphics
, contrast
);
4466 if(!graphics
|| !contrast
)
4467 return InvalidParameter
;
4469 *contrast
= graphics
->textcontrast
;
4474 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4475 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4476 TextRenderingHint
*hint
)
4478 TRACE("(%p, %p)\n", graphics
, hint
);
4480 if(!graphics
|| !hint
)
4481 return InvalidParameter
;
4486 *hint
= graphics
->texthint
;
4491 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4496 TRACE("(%p, %p)\n", graphics
, rect
);
4498 if(!graphics
|| !rect
)
4499 return InvalidParameter
;
4504 /* intersect window and graphics clipping regions */
4505 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4508 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4511 /* get bounds of the region */
4512 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4515 GdipDeleteRegion(clip_rgn
);
4520 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4525 TRACE("(%p, %p)\n", graphics
, rect
);
4527 if(!graphics
|| !rect
)
4528 return InvalidParameter
;
4530 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4532 rect
->X
= roundr(rectf
.X
);
4533 rect
->Y
= roundr(rectf
.Y
);
4534 rect
->Width
= roundr(rectf
.Width
);
4535 rect
->Height
= roundr(rectf
.Height
);
4541 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4543 TRACE("(%p, %p)\n", graphics
, matrix
);
4545 if(!graphics
|| !matrix
)
4546 return InvalidParameter
;
4551 *matrix
= *graphics
->worldtrans
;
4555 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4561 TRACE("(%p, %x)\n", graphics
, color
);
4564 return InvalidParameter
;
4569 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4572 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4573 GdipDeleteBrush((GpBrush
*)brush
);
4577 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4578 wnd_rect
.Width
, wnd_rect
.Height
);
4580 GdipDeleteBrush((GpBrush
*)brush
);
4585 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4587 TRACE("(%p, %p)\n", graphics
, res
);
4589 if(!graphics
|| !res
)
4590 return InvalidParameter
;
4592 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4595 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4601 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4603 if(!graphics
|| !result
)
4604 return InvalidParameter
;
4611 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4612 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4615 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4618 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4621 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4624 GdipDeleteRegion(rgn
);
4628 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4630 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4633 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4639 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4641 if(!graphics
|| !result
)
4642 return InvalidParameter
;
4649 pts
[1].X
= x
+ width
;
4650 pts
[1].Y
= y
+ height
;
4652 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4653 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4656 pts
[1].X
-= pts
[0].X
;
4657 pts
[1].Y
-= pts
[0].Y
;
4659 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4662 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4665 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4668 GdipDeleteRegion(rgn
);
4672 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4674 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4677 GpStatus
gdip_format_string(HDC hdc
,
4678 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4679 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4680 gdip_format_string_callback callback
, void *user_data
)
4683 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4684 nheight
, lineend
, lineno
= 0;
4686 StringAlignment halign
;
4689 HotkeyPrefix hkprefix
;
4690 INT
*hotkeyprefix_offsets
=NULL
;
4691 INT hotkeyprefix_count
=0;
4692 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4695 if(length
== -1) length
= lstrlenW(string
);
4697 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4698 if(!stringdup
) return OutOfMemory
;
4700 nwidth
= roundr(rect
->Width
);
4701 nheight
= roundr(rect
->Height
);
4703 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
4704 if (rect
->Height
>= INT_MAX
|| rect
->Height
< 0.5) nheight
= INT_MAX
;
4707 hkprefix
= format
->hkprefix
;
4709 hkprefix
= HotkeyPrefixNone
;
4711 if (hkprefix
== HotkeyPrefixShow
)
4713 for (i
=0; i
<length
; i
++)
4715 if (string
[i
] == '&')
4716 hotkeyprefix_count
++;
4720 if (hotkeyprefix_count
)
4721 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4723 hotkeyprefix_count
= 0;
4725 for(i
= 0, j
= 0; i
< length
; i
++){
4726 /* FIXME: This makes the indexes passed to callback inaccurate. */
4727 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4730 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4731 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4732 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4740 stringdup
[j
] = string
[i
];
4746 if (format
) halign
= format
->align
;
4747 else halign
= StringAlignmentNear
;
4749 while(sum
< length
){
4750 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4751 nwidth
, &fit
, NULL
, &size
);
4757 for(lret
= 0; lret
< fit
; lret
++)
4758 if(*(stringdup
+ sum
+ lret
) == '\n')
4761 /* Line break code (may look strange, but it imitates windows). */
4763 lineend
= fit
= lret
; /* this is not an off-by-one error */
4764 else if(fit
< (length
- sum
)){
4765 if(*(stringdup
+ sum
+ fit
) == ' ')
4766 while(*(stringdup
+ sum
+ fit
) == ' ')
4769 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4772 if(*(stringdup
+ sum
+ fit
) == '\t')
4781 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4782 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4788 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4789 nwidth
, &j
, NULL
, &size
);
4791 bounds
.Width
= size
.cx
;
4793 if(height
+ size
.cy
> nheight
)
4794 bounds
.Height
= nheight
- (height
+ size
.cy
);
4796 bounds
.Height
= size
.cy
;
4798 bounds
.Y
= rect
->Y
+ height
;
4802 case StringAlignmentNear
:
4806 case StringAlignmentCenter
:
4807 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4809 case StringAlignmentFar
:
4810 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4814 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4815 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4818 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4819 font
, rect
, format
, lineno
, &bounds
,
4820 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4821 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4826 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4830 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4832 if(height
> nheight
)
4835 /* Stop if this was a linewrap (but not if it was a linebreak). */
4836 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
4840 GdipFree(stringdup
);
4841 GdipFree(hotkeyprefix_offsets
);
4846 struct measure_ranges_args
{
4850 static GpStatus
measure_ranges_callback(HDC hdc
,
4851 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4852 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4853 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4854 INT underlined_index_count
, void *user_data
)
4858 struct measure_ranges_args
*args
= user_data
;
4860 for (i
=0; i
<format
->range_count
; i
++)
4862 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4863 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4864 if (range_start
< range_end
)
4869 range_rect
.Y
= bounds
->Y
;
4870 range_rect
.Height
= bounds
->Height
;
4872 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4873 INT_MAX
, NULL
, NULL
, &range_size
);
4874 range_rect
.X
= bounds
->X
+ range_size
.cx
;
4876 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4877 INT_MAX
, NULL
, NULL
, &range_size
);
4878 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
4880 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4889 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4890 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4891 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4892 INT regionCount
, GpRegion
** regions
)
4897 struct measure_ranges_args args
;
4898 HDC hdc
, temp_hdc
=NULL
;
4900 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4901 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4903 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4904 return InvalidParameter
;
4906 if (regionCount
< stringFormat
->range_count
)
4907 return InvalidParameter
;
4911 hdc
= temp_hdc
= CreateCompatibleDC(0);
4912 if (!temp_hdc
) return OutOfMemory
;
4915 hdc
= graphics
->hdc
;
4917 if (stringFormat
->attr
)
4918 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4920 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&font
->lfw
));
4922 for (i
=0; i
<stringFormat
->range_count
; i
++)
4924 stat
= GdipSetEmpty(regions
[i
]);
4929 args
.regions
= regions
;
4931 stat
= gdip_format_string(hdc
, string
, length
, font
, layoutRect
, stringFormat
,
4932 measure_ranges_callback
, &args
);
4934 DeleteObject(SelectObject(hdc
, oldfont
));
4942 struct measure_string_args
{
4944 INT
*codepointsfitted
;
4946 REAL rel_width
, rel_height
;
4949 static GpStatus
measure_string_callback(HDC hdc
,
4950 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4951 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4952 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4953 INT underlined_index_count
, void *user_data
)
4955 struct measure_string_args
*args
= user_data
;
4956 REAL new_width
, new_height
;
4958 new_width
= bounds
->Width
/ args
->rel_width
;
4959 new_height
= (bounds
->Height
+ bounds
->Y
- args
->bounds
->Y
) / args
->rel_height
;
4961 if (new_width
> args
->bounds
->Width
)
4962 args
->bounds
->Width
= new_width
;
4964 if (new_height
> args
->bounds
->Height
)
4965 args
->bounds
->Height
= new_height
;
4967 if (args
->codepointsfitted
)
4968 *args
->codepointsfitted
= index
+ length
;
4970 if (args
->linesfilled
)
4971 (*args
->linesfilled
)++;
4976 /* Find the smallest rectangle that bounds the text when it is printed in rect
4977 * according to the format options listed in format. If rect has 0 width and
4978 * height, then just find the smallest rectangle that bounds the text when it's
4979 * printed at location (rect->X, rect-Y). */
4980 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4981 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4982 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4983 INT
*codepointsfitted
, INT
*linesfilled
)
4985 HFONT oldfont
, gdifont
;
4986 struct measure_string_args args
;
4987 HDC temp_hdc
=NULL
, hdc
;
4990 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4991 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4992 bounds
, codepointsfitted
, linesfilled
);
4994 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4995 return InvalidParameter
;
4999 hdc
= temp_hdc
= CreateCompatibleDC(0);
5000 if (!temp_hdc
) return OutOfMemory
;
5003 hdc
= graphics
->hdc
;
5005 if(linesfilled
) *linesfilled
= 0;
5006 if(codepointsfitted
) *codepointsfitted
= 0;
5009 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5017 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5018 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5019 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5020 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5021 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5023 get_font_hfont(graphics
, font
, &gdifont
);
5024 oldfont
= SelectObject(hdc
, gdifont
);
5026 bounds
->X
= rect
->X
;
5027 bounds
->Y
= rect
->Y
;
5028 bounds
->Width
= 0.0;
5029 bounds
->Height
= 0.0;
5031 args
.bounds
= bounds
;
5032 args
.codepointsfitted
= codepointsfitted
;
5033 args
.linesfilled
= linesfilled
;
5035 gdip_format_string(hdc
, string
, length
, font
, rect
, format
,
5036 measure_string_callback
, &args
);
5038 SelectObject(hdc
, oldfont
);
5039 DeleteObject(gdifont
);
5047 struct draw_string_args
{
5048 GpGraphics
*graphics
;
5049 GDIPCONST GpBrush
*brush
;
5050 REAL x
, y
, rel_width
, rel_height
, ascent
;
5053 static GpStatus
draw_string_callback(HDC hdc
,
5054 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5055 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5056 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5057 INT underlined_index_count
, void *user_data
)
5059 struct draw_string_args
*args
= user_data
;
5063 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5064 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5066 stat
= GdipDrawDriverString(args
->graphics
, &string
[index
], length
, font
,
5067 args
->brush
, &position
,
5068 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5070 if (stat
== Ok
&& underlined_index_count
)
5072 OUTLINETEXTMETRICW otm
;
5073 REAL underline_y
, underline_height
;
5076 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5078 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5079 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5081 for (i
=0; i
<underlined_index_count
; i
++)
5083 REAL start_x
, end_x
;
5085 INT ofs
= underlined_indexes
[i
] - index
;
5087 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5088 start_x
= text_size
.cx
/ args
->rel_width
;
5090 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5091 end_x
= text_size
.cx
/ args
->rel_width
;
5093 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5100 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5101 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5102 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5106 GpPointF pt
[3], rectcpy
[4];
5108 REAL rel_width
, rel_height
;
5111 struct draw_string_args args
;
5113 HDC hdc
, temp_hdc
=NULL
;
5114 TEXTMETRICW textmetric
;
5116 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5117 length
, font
, debugstr_rectf(rect
), format
, brush
);
5119 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5120 return InvalidParameter
;
5124 hdc
= graphics
->hdc
;
5128 hdc
= temp_hdc
= CreateCompatibleDC(0);
5132 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5134 /* Should be no need to explicitly test for StringAlignmentNear as
5135 * that is default behavior if no alignment is passed. */
5136 if(format
->vertalign
!= StringAlignmentNear
){
5138 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
5140 if(format
->vertalign
== StringAlignmentCenter
)
5141 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5142 else if(format
->vertalign
== StringAlignmentFar
)
5143 offsety
= (rect
->Height
- bounds
.Height
);
5147 save_state
= SaveDC(hdc
);
5155 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5156 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5157 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5158 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5159 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5161 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5162 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
5163 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5164 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
5165 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5167 scaled_rect
.X
= 0.0;
5168 scaled_rect
.Y
= 0.0;
5169 scaled_rect
.Width
= rel_width
* rect
->Width
;
5170 scaled_rect
.Height
= rel_height
* rect
->Height
;
5172 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
5174 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5175 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5176 SelectClipRgn(hdc
, rgn
);
5179 get_font_hfont(graphics
, font
, &gdifont
);
5180 SelectObject(hdc
, gdifont
);
5182 args
.graphics
= graphics
;
5186 args
.y
= rect
->Y
+ offsety
;
5188 args
.rel_width
= rel_width
;
5189 args
.rel_height
= rel_height
;
5191 GetTextMetricsW(hdc
, &textmetric
);
5192 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5194 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
5195 draw_string_callback
, &args
);
5198 DeleteObject(gdifont
);
5200 RestoreDC(hdc
, save_state
);
5207 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5209 TRACE("(%p)\n", graphics
);
5212 return InvalidParameter
;
5217 return GdipSetInfinite(graphics
->clip
);
5220 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5222 TRACE("(%p)\n", graphics
);
5225 return InvalidParameter
;
5230 graphics
->worldtrans
->matrix
[0] = 1.0;
5231 graphics
->worldtrans
->matrix
[1] = 0.0;
5232 graphics
->worldtrans
->matrix
[2] = 0.0;
5233 graphics
->worldtrans
->matrix
[3] = 1.0;
5234 graphics
->worldtrans
->matrix
[4] = 0.0;
5235 graphics
->worldtrans
->matrix
[5] = 0.0;
5240 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5242 return GdipEndContainer(graphics
, state
);
5245 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5246 GpMatrixOrder order
)
5248 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5251 return InvalidParameter
;
5256 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
5259 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5261 return GdipBeginContainer2(graphics
, state
);
5264 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5265 GraphicsContainer
*state
)
5267 GraphicsContainerItem
*container
;
5270 TRACE("(%p, %p)\n", graphics
, state
);
5272 if(!graphics
|| !state
)
5273 return InvalidParameter
;
5275 sts
= init_container(&container
, graphics
);
5279 list_add_head(&graphics
->containers
, &container
->entry
);
5280 *state
= graphics
->contid
= container
->contid
;
5285 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5287 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5288 return NotImplemented
;
5291 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5293 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5294 return NotImplemented
;
5297 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5299 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5300 return NotImplemented
;
5303 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5306 GraphicsContainerItem
*container
, *container2
;
5308 TRACE("(%p, %x)\n", graphics
, state
);
5311 return InvalidParameter
;
5313 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5314 if(container
->contid
== state
)
5318 /* did not find a matching container */
5319 if(&container
->entry
== &graphics
->containers
)
5322 sts
= restore_container(graphics
, container
);
5326 /* remove all of the containers on top of the found container */
5327 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5328 if(container
->contid
== state
)
5330 list_remove(&container
->entry
);
5331 delete_container(container
);
5334 list_remove(&container
->entry
);
5335 delete_container(container
);
5340 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5341 REAL sy
, GpMatrixOrder order
)
5343 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5346 return InvalidParameter
;
5351 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
5354 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5357 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5359 if(!graphics
|| !srcgraphics
)
5360 return InvalidParameter
;
5362 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5365 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5366 CompositingMode mode
)
5368 TRACE("(%p, %d)\n", graphics
, mode
);
5371 return InvalidParameter
;
5376 graphics
->compmode
= mode
;
5381 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5382 CompositingQuality quality
)
5384 TRACE("(%p, %d)\n", graphics
, quality
);
5387 return InvalidParameter
;
5392 graphics
->compqual
= quality
;
5397 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5398 InterpolationMode mode
)
5400 TRACE("(%p, %d)\n", graphics
, mode
);
5402 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5403 return InvalidParameter
;
5408 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5409 mode
= InterpolationModeBilinear
;
5411 if (mode
== InterpolationModeHighQuality
)
5412 mode
= InterpolationModeHighQualityBicubic
;
5414 graphics
->interpolation
= mode
;
5419 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5421 TRACE("(%p, %.2f)\n", graphics
, scale
);
5423 if(!graphics
|| (scale
<= 0.0))
5424 return InvalidParameter
;
5429 graphics
->scale
= scale
;
5434 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5436 TRACE("(%p, %d)\n", graphics
, unit
);
5439 return InvalidParameter
;
5444 if(unit
== UnitWorld
)
5445 return InvalidParameter
;
5447 graphics
->unit
= unit
;
5452 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5455 TRACE("(%p, %d)\n", graphics
, mode
);
5458 return InvalidParameter
;
5463 graphics
->pixeloffset
= mode
;
5468 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5472 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5475 FIXME("not implemented\n");
5477 return NotImplemented
;
5480 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5484 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5487 FIXME("not implemented\n");
5491 return NotImplemented
;
5494 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5496 TRACE("(%p, %d)\n", graphics
, mode
);
5499 return InvalidParameter
;
5504 graphics
->smoothing
= mode
;
5509 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5511 TRACE("(%p, %d)\n", graphics
, contrast
);
5514 return InvalidParameter
;
5516 graphics
->textcontrast
= contrast
;
5521 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5522 TextRenderingHint hint
)
5524 TRACE("(%p, %d)\n", graphics
, hint
);
5526 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5527 return InvalidParameter
;
5532 graphics
->texthint
= hint
;
5537 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5539 TRACE("(%p, %p)\n", graphics
, matrix
);
5541 if(!graphics
|| !matrix
)
5542 return InvalidParameter
;
5547 GdipDeleteMatrix(graphics
->worldtrans
);
5548 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
5551 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5552 REAL dy
, GpMatrixOrder order
)
5554 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5557 return InvalidParameter
;
5562 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
5565 /*****************************************************************************
5566 * GdipSetClipHrgn [GDIPLUS.@]
5568 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5573 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5576 return InvalidParameter
;
5578 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5582 status
= GdipSetClipRegion(graphics
, region
, mode
);
5584 GdipDeleteRegion(region
);
5588 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5590 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5593 return InvalidParameter
;
5598 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5601 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5602 REAL width
, REAL height
,
5607 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5610 return InvalidParameter
;
5618 rect
.Height
= height
;
5620 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5623 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5624 INT width
, INT height
,
5627 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5630 return InvalidParameter
;
5635 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5638 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5641 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5643 if(!graphics
|| !region
)
5644 return InvalidParameter
;
5649 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5652 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5657 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5660 FIXME("not implemented\n");
5662 return NotImplemented
;
5665 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5671 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5673 if(!graphics
|| !pen
|| count
<=0)
5674 return InvalidParameter
;
5681 FIXME("graphics object has no HDC\n");
5685 pti
= GdipAlloc(sizeof(POINT
) * count
);
5687 save_state
= prepare_dc(graphics
, pen
);
5688 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5690 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5691 Polygon(graphics
->hdc
, pti
, count
);
5693 restore_dc(graphics
, save_state
);
5699 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5706 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5708 if(count
<=0) return InvalidParameter
;
5709 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5711 for(i
= 0;i
< count
; i
++){
5712 ptf
[i
].X
= (REAL
)points
[i
].X
;
5713 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5716 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5722 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5724 TRACE("(%p, %p)\n", graphics
, dpi
);
5726 if(!graphics
|| !dpi
)
5727 return InvalidParameter
;
5732 if (graphics
->image
)
5733 *dpi
= graphics
->image
->xres
;
5735 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
5740 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5742 TRACE("(%p, %p)\n", graphics
, dpi
);
5744 if(!graphics
|| !dpi
)
5745 return InvalidParameter
;
5750 if (graphics
->image
)
5751 *dpi
= graphics
->image
->yres
;
5753 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
5758 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5759 GpMatrixOrder order
)
5764 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5766 if(!graphics
|| !matrix
)
5767 return InvalidParameter
;
5772 m
= *(graphics
->worldtrans
);
5774 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5776 *(graphics
->worldtrans
) = m
;
5781 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5782 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5784 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5788 TRACE("(%p, %p)\n", graphics
, hdc
);
5790 if(!graphics
|| !hdc
)
5791 return InvalidParameter
;
5796 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5798 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5800 else if (!graphics
->hdc
||
5801 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5803 /* Create a fake HDC and fill it with a constant color. */
5807 BITMAPINFOHEADER bmih
;
5810 stat
= get_graphics_bounds(graphics
, &bounds
);
5814 graphics
->temp_hbitmap_width
= bounds
.Width
;
5815 graphics
->temp_hbitmap_height
= bounds
.Height
;
5817 bmih
.biSize
= sizeof(bmih
);
5818 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5819 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5821 bmih
.biBitCount
= 32;
5822 bmih
.biCompression
= BI_RGB
;
5823 bmih
.biSizeImage
= 0;
5824 bmih
.biXPelsPerMeter
= 0;
5825 bmih
.biYPelsPerMeter
= 0;
5827 bmih
.biClrImportant
= 0;
5829 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5830 (void**)&graphics
->temp_bits
, NULL
, 0);
5832 return GenericError
;
5834 temp_hdc
= CreateCompatibleDC(0);
5837 DeleteObject(hbitmap
);
5838 return GenericError
;
5841 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5842 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5844 SelectObject(temp_hdc
, hbitmap
);
5846 graphics
->temp_hbitmap
= hbitmap
;
5847 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5851 *hdc
= graphics
->hdc
;
5855 graphics
->busy
= TRUE
;
5860 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5864 TRACE("(%p, %p)\n", graphics
, hdc
);
5866 if(!graphics
|| !hdc
|| !graphics
->busy
)
5867 return InvalidParameter
;
5869 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5871 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5873 else if (graphics
->temp_hdc
== hdc
)
5878 /* Find the pixels that have changed, and mark them as opaque. */
5879 pos
= (DWORD
*)graphics
->temp_bits
;
5880 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5882 if (*pos
!= DC_BACKGROUND_KEY
)
5889 /* Write the changed pixels to the real target. */
5890 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5891 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5892 graphics
->temp_hbitmap_width
* 4);
5895 DeleteDC(graphics
->temp_hdc
);
5896 DeleteObject(graphics
->temp_hbitmap
);
5897 graphics
->temp_hdc
= NULL
;
5898 graphics
->temp_hbitmap
= NULL
;
5900 else if (hdc
!= graphics
->hdc
)
5902 stat
= InvalidParameter
;
5906 graphics
->busy
= FALSE
;
5911 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5916 TRACE("(%p, %p)\n", graphics
, region
);
5918 if(!graphics
|| !region
)
5919 return InvalidParameter
;
5924 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5927 /* free everything except root node and header */
5928 delete_element(®ion
->node
);
5929 memcpy(region
, clip
, sizeof(GpRegion
));
5935 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5936 GpCoordinateSpace src_space
, GpMatrix
**matrix
)
5938 GpStatus stat
= GdipCreateMatrix(matrix
);
5941 if (dst_space
!= src_space
&& stat
== Ok
)
5943 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
5945 if(graphics
->unit
!= UnitDisplay
)
5946 unitscale
*= graphics
->scale
;
5948 /* transform from src_space to CoordinateSpacePage */
5951 case CoordinateSpaceWorld
:
5952 GdipMultiplyMatrix(*matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
5954 case CoordinateSpacePage
:
5956 case CoordinateSpaceDevice
:
5957 GdipScaleMatrix(*matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
5961 /* transform from CoordinateSpacePage to dst_space */
5964 case CoordinateSpaceWorld
:
5966 GpMatrix
*inverted_transform
;
5967 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
5970 stat
= GdipInvertMatrix(inverted_transform
);
5972 GdipMultiplyMatrix(*matrix
, inverted_transform
, MatrixOrderAppend
);
5973 GdipDeleteMatrix(inverted_transform
);
5977 case CoordinateSpacePage
:
5979 case CoordinateSpaceDevice
:
5980 GdipScaleMatrix(*matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
5987 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5988 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5993 if(!graphics
|| !points
|| count
<= 0)
5994 return InvalidParameter
;
5999 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6001 if (src_space
== dst_space
) return Ok
;
6003 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6007 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
6009 GdipDeleteMatrix(matrix
);
6015 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6016 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6022 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6025 return InvalidParameter
;
6027 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
6031 for(i
= 0; i
< count
; i
++){
6032 pointsF
[i
].X
= (REAL
)points
[i
].X
;
6033 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
6036 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6039 for(i
= 0; i
< count
; i
++){
6040 points
[i
].X
= roundr(pointsF
[i
].X
);
6041 points
[i
].Y
= roundr(pointsF
[i
].Y
);
6048 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6060 /*****************************************************************************
6061 * GdipTranslateClip [GDIPLUS.@]
6063 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6065 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6068 return InvalidParameter
;
6073 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6076 /*****************************************************************************
6077 * GdipTranslateClipI [GDIPLUS.@]
6079 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6081 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6084 return InvalidParameter
;
6089 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6093 /*****************************************************************************
6094 * GdipMeasureDriverString [GDIPLUS.@]
6096 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6097 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6098 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6100 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6103 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6105 TEXTMETRICW textmetric
;
6106 const WORD
*glyph_indices
;
6107 WORD
*dynamic_glyph_indices
=NULL
;
6108 REAL rel_width
, rel_height
, ascent
, descent
;
6111 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6113 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6114 return InvalidParameter
;
6117 length
= strlenW(text
);
6121 boundingBox
->X
= 0.0;
6122 boundingBox
->Y
= 0.0;
6123 boundingBox
->Width
= 0.0;
6124 boundingBox
->Height
= 0.0;
6127 if (flags
& unsupported_flags
)
6128 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6131 FIXME("Ignoring matrix\n");
6133 get_font_hfont(graphics
, font
, &hfont
);
6135 hdc
= CreateCompatibleDC(0);
6136 SelectObject(hdc
, hfont
);
6138 GetTextMetricsW(hdc
, &textmetric
);
6146 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6147 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6148 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6149 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6150 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6152 if (flags
& DriverStringOptionsCmapLookup
)
6154 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6158 DeleteObject(hfont
);
6162 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6165 glyph_indices
= text
;
6167 min_x
= max_x
= x
= positions
[0].X
;
6168 min_y
= max_y
= y
= positions
[0].Y
;
6170 ascent
= textmetric
.tmAscent
/ rel_height
;
6171 descent
= textmetric
.tmDescent
/ rel_height
;
6173 for (i
=0; i
<length
; i
++)
6178 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6184 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6185 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcB
;
6187 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6188 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6189 if (min_x
> x
) min_x
= x
;
6191 x
+= char_width
/ rel_width
;
6193 if (max_x
< x
) max_x
= x
;
6196 GdipFree(dynamic_glyph_indices
);
6198 DeleteObject(hfont
);
6200 boundingBox
->X
= min_x
;
6201 boundingBox
->Y
= min_y
;
6202 boundingBox
->Width
= max_x
- min_x
;
6203 boundingBox
->Height
= max_y
- min_y
;
6208 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6209 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6210 GDIPCONST PointF
*positions
, INT flags
,
6211 GDIPCONST GpMatrix
*matrix
)
6213 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6219 if (flags
& unsupported_flags
)
6220 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6223 FIXME("Ignoring matrix\n");
6225 if (!(flags
& DriverStringOptionsCmapLookup
))
6226 eto_flags
|= ETO_GLYPH_INDEX
;
6228 save_state
= SaveDC(graphics
->hdc
);
6229 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6230 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6233 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6235 get_font_hfont(graphics
, font
, &hfont
);
6236 SelectObject(graphics
->hdc
, hfont
);
6238 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6240 ExtTextOutW(graphics
->hdc
, roundr(pt
.X
), roundr(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6242 RestoreDC(graphics
->hdc
, save_state
);
6244 DeleteObject(hfont
);
6249 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6250 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6251 GDIPCONST PointF
*positions
, INT flags
,
6252 GDIPCONST GpMatrix
*matrix
)
6254 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6256 PointF
*real_positions
, real_position
;
6260 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6261 DWORD max_glyphsize
=0;
6262 GLYPHMETRICS glyphmetrics
;
6263 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6266 int text_mask_stride
;
6268 int pixel_data_stride
;
6270 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6275 if (!(flags
& DriverStringOptionsCmapLookup
))
6276 ggo_flags
|= GGO_GLYPH_INDEX
;
6278 if (flags
& unsupported_flags
)
6279 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6282 FIXME("Ignoring matrix\n");
6284 pti
= GdipAlloc(sizeof(POINT
) * length
);
6288 if (flags
& DriverStringOptionsRealizedAdvance
)
6290 real_position
= positions
[0];
6292 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6296 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6297 if (!real_positions
)
6303 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6305 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6307 GdipFree(real_positions
);
6310 get_font_hfont(graphics
, font
, &hfont
);
6312 hdc
= CreateCompatibleDC(0);
6313 SelectObject(hdc
, hfont
);
6315 /* Get the boundaries of the text to be drawn */
6316 for (i
=0; i
<length
; i
++)
6319 int left
, top
, right
, bottom
;
6321 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6322 &glyphmetrics
, 0, NULL
, &identity
);
6324 if (glyphsize
== GDI_ERROR
)
6326 ERR("GetGlyphOutlineW failed\n");
6329 DeleteObject(hfont
);
6330 return GenericError
;
6333 if (glyphsize
> max_glyphsize
)
6334 max_glyphsize
= glyphsize
;
6336 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6337 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6338 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6339 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6341 if (left
< min_x
) min_x
= left
;
6342 if (top
< min_y
) min_y
= top
;
6343 if (right
> max_x
) max_x
= right
;
6344 if (bottom
> max_y
) max_y
= bottom
;
6346 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6348 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6349 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6353 glyph_mask
= GdipAlloc(max_glyphsize
);
6354 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6355 text_mask_stride
= max_x
- min_x
;
6357 if (!(glyph_mask
&& text_mask
))
6359 GdipFree(glyph_mask
);
6360 GdipFree(text_mask
);
6363 DeleteObject(hfont
);
6367 /* Generate a mask for the text */
6368 for (i
=0; i
<length
; i
++)
6370 int left
, top
, stride
;
6372 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6373 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6375 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6376 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6377 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6379 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6381 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6382 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6383 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6385 *text_val
= min(64, *text_val
+ *glyph_val
);
6394 DeleteObject(hfont
);
6395 GdipFree(glyph_mask
);
6397 /* get the brush data */
6398 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6401 GdipFree(text_mask
);
6405 pixel_area
.X
= min_x
;
6406 pixel_area
.Y
= min_y
;
6407 pixel_area
.Width
= max_x
- min_x
;
6408 pixel_area
.Height
= max_y
- min_y
;
6409 pixel_data_stride
= pixel_area
.Width
* 4;
6411 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6414 GdipFree(text_mask
);
6415 GdipFree(pixel_data
);
6419 /* multiply the brush data by the mask */
6420 for (y
=0; y
<pixel_area
.Height
; y
++)
6422 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6423 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6424 for (x
=0; x
<pixel_area
.Width
; x
++)
6426 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6432 GdipFree(text_mask
);
6434 /* draw the result */
6435 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6436 pixel_area
.Height
, pixel_data_stride
);
6438 GdipFree(pixel_data
);
6443 /*****************************************************************************
6444 * GdipDrawDriverString [GDIPLUS.@]
6446 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6447 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6448 GDIPCONST PointF
*positions
, INT flags
,
6449 GDIPCONST GpMatrix
*matrix
)
6451 GpStatus stat
=NotImplemented
;
6453 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6455 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6456 return InvalidParameter
;
6459 length
= strlenW(text
);
6461 if (graphics
->hdc
&&
6462 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6463 brush
->bt
== BrushTypeSolidColor
&&
6464 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6465 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
6466 positions
, flags
, matrix
);
6468 if (stat
== NotImplemented
)
6469 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
6470 positions
, flags
, matrix
);
6475 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6476 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6478 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6479 return NotImplemented
;
6482 /*****************************************************************************
6483 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6485 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6490 TRACE("(%p, %p)\n", graphics
, res
);
6492 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6495 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6498 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6501 GdipDeleteRegion(rgn
);
6505 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6509 TRACE("(%p) stub\n", graphics
);
6512 FIXME("not implemented\n");
6514 return NotImplemented
;