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
;
1194 ARGB outer_color
=0xffffffff;
1196 stat
= GdipClonePath(fill
->path
, &flat_path
);
1201 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1202 CoordinateSpaceWorld
, &world_to_device
);
1205 stat
= GdipTransformPath(flat_path
, world_to_device
);
1209 center_point
= fill
->center
;
1210 stat
= GdipTransformMatrixPoints(world_to_device
, ¢er_point
, 1);
1214 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1216 GdipDeleteMatrix(world_to_device
);
1221 GdipDeletePath(flat_path
);
1225 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1227 int start_center_line
=0, end_center_line
=0;
1228 int seen_start
=0, seen_end
=0, seen_center
=0;
1229 REAL center_distance
;
1231 type
= flat_path
->pathdata
.Types
[i
];
1233 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1236 start_point
= flat_path
->pathdata
.Points
[i
];
1238 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1239 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1240 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1241 end_point
= flat_path
->pathdata
.Points
[i
+1];
1245 min_yf
= center_point
.Y
;
1246 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1247 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1249 if (min_yf
< fill_area
->Y
)
1250 min_y
= fill_area
->Y
;
1252 min_y
= (INT
)ceil(min_yf
);
1254 max_yf
= center_point
.Y
;
1255 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1256 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1258 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1259 max_y
= fill_area
->Y
+ fill_area
->Height
;
1261 max_y
= (INT
)ceil(max_yf
);
1263 /* This is proportional to the distance from start-end line to center point. */
1264 center_distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- center_point
.X
) +
1265 (end_point
.X
- start_point
.X
) * (center_point
.Y
- start_point
.Y
);
1267 for (y
=min_y
; y
<max_y
; y
++)
1271 if (!seen_start
&& yf
>= start_point
.Y
)
1274 start_center_line
^= 1;
1276 if (!seen_end
&& yf
>= end_point
.Y
)
1279 end_center_line
^= 1;
1281 if (!seen_center
&& yf
>= center_point
.Y
)
1284 start_center_line
^= 1;
1285 end_center_line
^= 1;
1288 if (start_center_line
)
1289 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1291 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1293 if (end_center_line
)
1294 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1296 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1298 if (line1_xf
< line2_xf
)
1300 min_x
= (INT
)ceil(line1_xf
);
1301 max_x
= (INT
)ceil(line2_xf
);
1305 min_x
= (INT
)ceil(line2_xf
);
1306 max_x
= (INT
)ceil(line1_xf
);
1309 if (min_x
< fill_area
->X
)
1310 min_x
= fill_area
->X
;
1311 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1312 max_x
= fill_area
->X
+ fill_area
->Width
;
1314 for (x
=min_x
; x
<max_x
; x
++)
1318 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- (REAL
)x
) +
1319 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1321 distance
= distance
/ center_distance
;
1323 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1324 blend_colors(outer_color
, fill
->centercolor
, distance
);
1329 GdipDeletePath(flat_path
);
1333 return NotImplemented
;
1337 /* GdipDrawPie/GdipFillPie helper function */
1338 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
1339 REAL height
, REAL startAngle
, REAL sweepAngle
)
1346 ptf
[1].X
= x
+ width
;
1347 ptf
[1].Y
= y
+ height
;
1349 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
1350 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
1352 transform_and_round_points(graphics
, pti
, ptf
, 4);
1354 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
1355 pti
[2].y
, pti
[3].x
, pti
[3].y
);
1358 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1359 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1360 * should not be called on an hdc that has a path you care about. */
1361 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1362 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1364 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1365 GpMatrix
*matrix
= NULL
;
1366 HBRUSH brush
= NULL
;
1368 PointF ptf
[4], *custptf
= NULL
;
1369 POINT pt
[4], *custpt
= NULL
;
1371 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1376 if((x1
== x2
) && (y1
== y2
))
1379 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1381 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1383 brush
= CreateSolidBrush(color
);
1384 lb
.lbStyle
= BS_SOLID
;
1387 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1388 PS_JOIN_MITER
, 1, &lb
, 0,
1390 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1391 oldpen
= SelectObject(graphics
->hdc
, pen
);
1398 case LineCapSquareAnchor
:
1399 case LineCapDiamondAnchor
:
1400 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1401 if(cap
== LineCapDiamondAnchor
){
1402 dsmall
= cos(theta
+ M_PI_2
) * size
;
1403 dbig
= sin(theta
+ M_PI_2
) * size
;
1406 dsmall
= cos(theta
+ M_PI_4
) * size
;
1407 dbig
= sin(theta
+ M_PI_4
) * size
;
1410 ptf
[0].X
= x2
- dsmall
;
1411 ptf
[1].X
= x2
+ dbig
;
1413 ptf
[0].Y
= y2
- dbig
;
1414 ptf
[3].Y
= y2
+ dsmall
;
1416 ptf
[1].Y
= y2
- dsmall
;
1417 ptf
[2].Y
= y2
+ dbig
;
1419 ptf
[3].X
= x2
- dbig
;
1420 ptf
[2].X
= x2
+ dsmall
;
1422 transform_and_round_points(graphics
, pt
, ptf
, 4);
1423 Polygon(graphics
->hdc
, pt
, 4);
1426 case LineCapArrowAnchor
:
1427 size
= size
* 4.0 / sqrt(3.0);
1429 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1430 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1435 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1436 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1444 transform_and_round_points(graphics
, pt
, ptf
, 3);
1445 Polygon(graphics
->hdc
, pt
, 3);
1448 case LineCapRoundAnchor
:
1449 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1456 transform_and_round_points(graphics
, pt
, ptf
, 2);
1457 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1460 case LineCapTriangle
:
1462 dx
= cos(M_PI_2
+ theta
) * size
;
1463 dy
= sin(M_PI_2
+ theta
) * size
;
1470 dx
= cos(theta
) * size
;
1471 dy
= sin(theta
) * size
;
1476 transform_and_round_points(graphics
, pt
, ptf
, 3);
1477 Polygon(graphics
->hdc
, pt
, 3);
1481 dx
= dy
= size
/ 2.0;
1488 dx
= -cos(M_PI_2
+ theta
) * size
;
1489 dy
= -sin(M_PI_2
+ theta
) * size
;
1496 transform_and_round_points(graphics
, pt
, ptf
, 4);
1497 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1498 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1505 count
= custom
->pathdata
.Count
;
1506 custptf
= GdipAlloc(count
* sizeof(PointF
));
1507 custpt
= GdipAlloc(count
* sizeof(POINT
));
1508 tp
= GdipAlloc(count
);
1510 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
1513 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1515 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
1516 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1518 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
1519 GdipTransformMatrixPoints(matrix
, custptf
, count
);
1521 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1523 for(i
= 0; i
< count
; i
++)
1524 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1527 BeginPath(graphics
->hdc
);
1528 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1529 EndPath(graphics
->hdc
);
1530 StrokeAndFillPath(graphics
->hdc
);
1533 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1539 GdipDeleteMatrix(matrix
);
1546 SelectObject(graphics
->hdc
, oldbrush
);
1547 SelectObject(graphics
->hdc
, oldpen
);
1548 DeleteObject(brush
);
1553 /* Shortens the line by the given percent by changing x2, y2.
1554 * If percent is > 1.0 then the line will change direction.
1555 * If percent is negative it can lengthen the line. */
1556 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1558 REAL dist
, theta
, dx
, dy
;
1560 if((y1
== *y2
) && (x1
== *x2
))
1563 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1564 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1565 dx
= cos(theta
) * dist
;
1566 dy
= sin(theta
) * dist
;
1572 /* Shortens the line by the given amount by changing x2, y2.
1573 * If the amount is greater than the distance, the line will become length 0.
1574 * If the amount is negative, it can lengthen the line. */
1575 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1577 REAL dx
, dy
, percent
;
1581 if(dx
== 0 && dy
== 0)
1584 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1591 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1594 /* Draws lines between the given points, and if caps is true then draws an endcap
1595 * at the end of the last line. */
1596 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
1597 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1600 GpPointF
*ptcopy
= NULL
;
1601 GpStatus status
= GenericError
;
1606 pti
= GdipAlloc(count
* sizeof(POINT
));
1607 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1609 if(!pti
|| !ptcopy
){
1610 status
= OutOfMemory
;
1614 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1617 if(pen
->endcap
== LineCapArrowAnchor
)
1618 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1619 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
1620 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1621 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1622 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
1623 pen
->customend
->inset
* pen
->width
);
1625 if(pen
->startcap
== LineCapArrowAnchor
)
1626 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1627 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
1628 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1629 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1630 &ptcopy
[0].X
, &ptcopy
[0].Y
,
1631 pen
->customstart
->inset
* pen
->width
);
1633 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1634 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
1635 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1636 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
1639 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1641 if(Polyline(graphics
->hdc
, pti
, count
))
1651 /* Conducts a linear search to find the bezier points that will back off
1652 * the endpoint of the curve by a distance of amt. Linear search works
1653 * better than binary in this case because there are multiple solutions,
1654 * and binary searches often find a bad one. I don't think this is what
1655 * Windows does but short of rendering the bezier without GDI's help it's
1656 * the best we can do. If rev then work from the start of the passed points
1657 * instead of the end. */
1658 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1661 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1662 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1671 origx
= pt
[fourth
].X
;
1672 origy
= pt
[fourth
].Y
;
1673 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1675 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1676 /* reset bezier points to original values */
1677 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1678 /* Perform magic on bezier points. Order is important here.*/
1679 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1680 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1681 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1682 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1683 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1684 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1686 dx
= pt
[fourth
].X
- origx
;
1687 dy
= pt
[fourth
].Y
- origy
;
1689 diff
= sqrt(dx
* dx
+ dy
* dy
);
1690 percent
+= 0.0005 * amt
;
1694 /* Draws bezier curves between given points, and if caps is true then draws an
1695 * endcap at the end of the last line. */
1696 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
1697 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1701 GpStatus status
= GenericError
;
1706 pti
= GdipAlloc(count
* sizeof(POINT
));
1707 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1709 if(!pti
|| !ptcopy
){
1710 status
= OutOfMemory
;
1714 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1717 if(pen
->endcap
== LineCapArrowAnchor
)
1718 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
1719 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1720 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
1723 if(pen
->startcap
== LineCapArrowAnchor
)
1724 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
1725 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1726 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
1728 /* the direction of the line cap is parallel to the direction at the
1729 * end of the bezier (which, if it has been shortened, is not the same
1730 * as the direction from pt[count-2] to pt[count-1]) */
1731 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1732 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1733 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1734 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1736 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1737 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
1738 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
1741 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1743 PolyBezier(graphics
->hdc
, pti
, count
);
1754 /* Draws a combination of bezier curves and lines between points. */
1755 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1756 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1758 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1759 BYTE
*tp
= GdipAlloc(count
);
1760 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1762 GpStatus status
= GenericError
;
1768 if(!pti
|| !tp
|| !ptcopy
){
1769 status
= OutOfMemory
;
1773 for(i
= 1; i
< count
; i
++){
1774 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1775 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1776 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1777 ERR("Bad bezier points\n");
1784 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1786 /* If we are drawing caps, go through the points and adjust them accordingly,
1787 * and draw the caps. */
1789 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1790 case PathPointTypeBezier
:
1791 if(pen
->endcap
== LineCapArrowAnchor
)
1792 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1793 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1794 shorten_bezier_amt(&ptcopy
[count
- 4],
1795 pen
->width
* pen
->customend
->inset
, FALSE
);
1797 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1798 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1799 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1800 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1803 case PathPointTypeLine
:
1804 if(pen
->endcap
== LineCapArrowAnchor
)
1805 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1806 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1808 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1809 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1810 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1811 pen
->customend
->inset
* pen
->width
);
1813 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1814 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1819 ERR("Bad path last point\n");
1823 /* Find start of points */
1824 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1825 == PathPointTypeStart
); j
++);
1827 switch(types
[j
] & PathPointTypePathTypeMask
){
1828 case PathPointTypeBezier
:
1829 if(pen
->startcap
== LineCapArrowAnchor
)
1830 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1831 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1832 shorten_bezier_amt(&ptcopy
[j
- 1],
1833 pen
->width
* pen
->customstart
->inset
, TRUE
);
1835 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1836 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1837 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1838 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1841 case PathPointTypeLine
:
1842 if(pen
->startcap
== LineCapArrowAnchor
)
1843 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1844 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1846 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1847 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1848 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1849 pen
->customstart
->inset
* pen
->width
);
1851 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1852 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1857 ERR("Bad path points\n");
1862 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1864 for(i
= 0; i
< count
; i
++){
1865 tp
[i
] = convert_path_point_type(types
[i
]);
1868 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1880 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1884 BeginPath(graphics
->hdc
);
1885 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1886 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1887 EndPath(graphics
->hdc
);
1891 typedef struct _GraphicsContainerItem
{
1893 GraphicsContainer contid
;
1895 SmoothingMode smoothing
;
1896 CompositingQuality compqual
;
1897 InterpolationMode interpolation
;
1898 CompositingMode compmode
;
1899 TextRenderingHint texthint
;
1902 PixelOffsetMode pixeloffset
;
1904 GpMatrix
* worldtrans
;
1906 } GraphicsContainerItem
;
1908 static GpStatus
init_container(GraphicsContainerItem
** container
,
1909 GDIPCONST GpGraphics
* graphics
){
1912 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1916 (*container
)->contid
= graphics
->contid
+ 1;
1918 (*container
)->smoothing
= graphics
->smoothing
;
1919 (*container
)->compqual
= graphics
->compqual
;
1920 (*container
)->interpolation
= graphics
->interpolation
;
1921 (*container
)->compmode
= graphics
->compmode
;
1922 (*container
)->texthint
= graphics
->texthint
;
1923 (*container
)->scale
= graphics
->scale
;
1924 (*container
)->unit
= graphics
->unit
;
1925 (*container
)->textcontrast
= graphics
->textcontrast
;
1926 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1928 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1930 GdipFree(*container
);
1935 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1937 GdipDeleteMatrix((*container
)->worldtrans
);
1938 GdipFree(*container
);
1946 static void delete_container(GraphicsContainerItem
* container
){
1947 GdipDeleteMatrix(container
->worldtrans
);
1948 GdipDeleteRegion(container
->clip
);
1949 GdipFree(container
);
1952 static GpStatus
restore_container(GpGraphics
* graphics
,
1953 GDIPCONST GraphicsContainerItem
* container
){
1958 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1962 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1964 GdipDeleteMatrix(newTrans
);
1968 GdipDeleteMatrix(graphics
->worldtrans
);
1969 graphics
->worldtrans
= newTrans
;
1971 GdipDeleteRegion(graphics
->clip
);
1972 graphics
->clip
= newClip
;
1974 graphics
->contid
= container
->contid
- 1;
1976 graphics
->smoothing
= container
->smoothing
;
1977 graphics
->compqual
= container
->compqual
;
1978 graphics
->interpolation
= container
->interpolation
;
1979 graphics
->compmode
= container
->compmode
;
1980 graphics
->texthint
= container
->texthint
;
1981 graphics
->scale
= container
->scale
;
1982 graphics
->unit
= container
->unit
;
1983 graphics
->textcontrast
= container
->textcontrast
;
1984 graphics
->pixeloffset
= container
->pixeloffset
;
1989 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1995 if(graphics
->hwnd
) {
1996 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1997 return GenericError
;
1999 rect
->X
= wnd_rect
.left
;
2000 rect
->Y
= wnd_rect
.top
;
2001 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2002 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2003 }else if (graphics
->image
){
2004 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2005 if (stat
== Ok
&& unit
!= UnitPixel
)
2006 FIXME("need to convert from unit %i\n", unit
);
2010 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2011 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2017 /* on success, rgn will contain the region of the graphics object which
2018 * is visible after clipping has been applied */
2019 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2025 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2028 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2031 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2034 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2037 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2040 GdipDeleteRegion(tmp
);
2044 void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
, HFONT
*hfont
)
2046 HDC hdc
= CreateCompatibleDC(0);
2048 REAL angle
, rel_width
, rel_height
;
2050 HFONT unscaled_font
;
2051 TEXTMETRICW textmet
;
2060 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2061 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2062 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2063 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2064 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2065 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2068 lfw
.lfHeight
= roundr(-font
->pixel_size
* rel_height
);
2069 unscaled_font
= CreateFontIndirectW(&lfw
);
2071 SelectObject(hdc
, unscaled_font
);
2072 GetTextMetricsW(hdc
, &textmet
);
2075 lfw
.lfHeight
= roundr(-font
->pixel_size
* rel_height
);
2076 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2077 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
2079 *hfont
= CreateFontIndirectW(&lfw
);
2082 DeleteObject(unscaled_font
);
2085 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2087 TRACE("(%p, %p)\n", hdc
, graphics
);
2089 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2092 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2096 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2098 if(hDevice
!= NULL
) {
2099 FIXME("Don't know how to handle parameter hDevice\n");
2100 return NotImplemented
;
2106 if(graphics
== NULL
)
2107 return InvalidParameter
;
2109 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2110 if(!*graphics
) return OutOfMemory
;
2112 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
2113 GdipFree(*graphics
);
2117 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2118 GdipFree((*graphics
)->worldtrans
);
2119 GdipFree(*graphics
);
2123 (*graphics
)->hdc
= hdc
;
2124 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2125 (*graphics
)->owndc
= FALSE
;
2126 (*graphics
)->smoothing
= SmoothingModeDefault
;
2127 (*graphics
)->compqual
= CompositingQualityDefault
;
2128 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2129 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2130 (*graphics
)->compmode
= CompositingModeSourceOver
;
2131 (*graphics
)->unit
= UnitDisplay
;
2132 (*graphics
)->scale
= 1.0;
2133 (*graphics
)->busy
= FALSE
;
2134 (*graphics
)->textcontrast
= 4;
2135 list_init(&(*graphics
)->containers
);
2136 (*graphics
)->contid
= 0;
2138 TRACE("<-- %p\n", *graphics
);
2143 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2147 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2148 if(!*graphics
) return OutOfMemory
;
2150 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
2151 GdipFree(*graphics
);
2155 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2156 GdipFree((*graphics
)->worldtrans
);
2157 GdipFree(*graphics
);
2161 (*graphics
)->hdc
= NULL
;
2162 (*graphics
)->hwnd
= NULL
;
2163 (*graphics
)->owndc
= FALSE
;
2164 (*graphics
)->image
= image
;
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 WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2187 TRACE("(%p, %p)\n", hwnd
, graphics
);
2191 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2193 ReleaseDC(hwnd
, hdc
);
2197 (*graphics
)->hwnd
= hwnd
;
2198 (*graphics
)->owndc
= TRUE
;
2203 /* FIXME: no icm handling */
2204 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2206 TRACE("(%p, %p)\n", hwnd
, graphics
);
2208 return GdipCreateFromHWND(hwnd
, graphics
);
2211 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2212 GpMetafile
**metafile
)
2214 IStream
*stream
= NULL
;
2216 ENHMETAHEADER
*copy
;
2217 GpStatus retval
= Ok
;
2219 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2221 if(!hemf
|| !metafile
)
2222 return InvalidParameter
;
2224 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
2225 copy
= GdipAlloc(read
);
2226 GetEnhMetaFileBits(hemf
, read
, (BYTE
*)copy
);
2228 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
2229 ERR("could not make stream\n");
2231 retval
= GenericError
;
2235 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2237 retval
= OutOfMemory
;
2241 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
2242 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
2244 retval
= GenericError
;
2249 (*metafile
)->image
.type
= ImageTypeMetafile
;
2250 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
2251 (*metafile
)->image
.palette_flags
= 0;
2252 (*metafile
)->image
.palette_count
= 0;
2253 (*metafile
)->image
.palette_size
= 0;
2254 (*metafile
)->image
.palette_entries
= NULL
;
2255 (*metafile
)->image
.xres
= (REAL
)copy
->szlDevice
.cx
;
2256 (*metafile
)->image
.yres
= (REAL
)copy
->szlDevice
.cy
;
2257 (*metafile
)->bounds
.X
= (REAL
)copy
->rclBounds
.left
;
2258 (*metafile
)->bounds
.Y
= (REAL
)copy
->rclBounds
.top
;
2259 (*metafile
)->bounds
.Width
= (REAL
)(copy
->rclBounds
.right
- copy
->rclBounds
.left
);
2260 (*metafile
)->bounds
.Height
= (REAL
)(copy
->rclBounds
.bottom
- copy
->rclBounds
.top
);
2261 (*metafile
)->unit
= UnitPixel
;
2264 DeleteEnhMetaFile(hemf
);
2266 TRACE("<-- %p\n", *metafile
);
2270 GdipFree(*metafile
);
2271 IStream_Release(stream
);
2275 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2276 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2281 GpStatus retval
= Ok
;
2283 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2285 if(!hwmf
|| !metafile
|| !placeable
)
2286 return InvalidParameter
;
2289 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2291 return GenericError
;
2292 copy
= GdipAlloc(read
);
2293 GetMetaFileBitsEx(hwmf
, read
, copy
);
2295 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2298 retval
= GdipCreateMetafileFromEmf(hemf
, FALSE
, metafile
);
2302 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2303 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2304 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2305 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2306 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2307 placeable
->BoundingBox
.Left
);
2308 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2309 placeable
->BoundingBox
.Top
);
2311 if (delete) DeleteMetaFile(hwmf
);
2316 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2317 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2319 HMETAFILE hmf
= GetMetaFileW(file
);
2321 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2323 if(!hmf
) return InvalidParameter
;
2325 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2328 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2329 GpMetafile
**metafile
)
2331 FIXME("(%p, %p): stub\n", file
, metafile
);
2332 return NotImplemented
;
2335 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2336 GpMetafile
**metafile
)
2338 FIXME("(%p, %p): stub\n", stream
, metafile
);
2339 return NotImplemented
;
2342 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2343 UINT access
, IStream
**stream
)
2348 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2350 if(!stream
|| !filename
)
2351 return InvalidParameter
;
2353 if(access
& GENERIC_WRITE
)
2354 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2355 else if(access
& GENERIC_READ
)
2356 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2358 return InvalidParameter
;
2360 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2362 return hresult_to_status(ret
);
2365 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2367 GraphicsContainerItem
*cont
, *next
;
2369 TRACE("(%p)\n", graphics
);
2371 if(!graphics
) return InvalidParameter
;
2372 if(graphics
->busy
) return ObjectBusy
;
2374 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2376 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2382 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2384 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2385 list_remove(&cont
->entry
);
2386 delete_container(cont
);
2389 GdipDeleteRegion(graphics
->clip
);
2390 GdipDeleteMatrix(graphics
->worldtrans
);
2396 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2397 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2399 INT save_state
, num_pts
;
2400 GpPointF points
[MAX_ARC_PTS
];
2403 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2404 width
, height
, startAngle
, sweepAngle
);
2406 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2407 return InvalidParameter
;
2414 FIXME("graphics object has no HDC\n");
2418 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2420 save_state
= prepare_dc(graphics
, pen
);
2422 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
2424 restore_dc(graphics
, save_state
);
2429 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2430 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2432 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2433 width
, height
, startAngle
, sweepAngle
);
2435 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2438 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2439 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2445 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2446 x2
, y2
, x3
, y3
, x4
, y4
);
2448 if(!graphics
|| !pen
)
2449 return InvalidParameter
;
2456 FIXME("graphics object has no HDC\n");
2469 save_state
= prepare_dc(graphics
, pen
);
2471 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2473 restore_dc(graphics
, save_state
);
2478 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2479 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2485 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2486 x2
, y2
, x3
, y3
, x4
, y4
);
2488 if(!graphics
|| !pen
)
2489 return InvalidParameter
;
2496 FIXME("graphics object has no HDC\n");
2509 save_state
= prepare_dc(graphics
, pen
);
2511 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2513 restore_dc(graphics
, save_state
);
2518 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2519 GDIPCONST GpPointF
*points
, INT count
)
2524 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2526 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2527 return InvalidParameter
;
2532 for(i
= 0; i
< floor(count
/ 4); i
++){
2533 ret
= GdipDrawBezier(graphics
, pen
,
2534 points
[4*i
].X
, points
[4*i
].Y
,
2535 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
2536 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
2537 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
2545 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2546 GDIPCONST GpPoint
*points
, INT count
)
2552 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2554 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2555 return InvalidParameter
;
2560 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2564 for(i
= 0; i
< count
; i
++){
2565 pts
[i
].X
= (REAL
)points
[i
].X
;
2566 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2569 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2576 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2577 GDIPCONST GpPointF
*points
, INT count
)
2579 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2581 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2584 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2585 GDIPCONST GpPoint
*points
, INT count
)
2587 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2589 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2592 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2593 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2598 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2600 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2601 return InvalidParameter
;
2606 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
2609 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2611 GdipDeletePath(path
);
2615 stat
= GdipDrawPath(graphics
, pen
, path
);
2617 GdipDeletePath(path
);
2622 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2623 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2629 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2631 if(!points
|| count
<= 0)
2632 return InvalidParameter
;
2634 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2638 for(i
= 0; i
< count
; i
++){
2639 ptf
[i
].X
= (REAL
)points
[i
].X
;
2640 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2643 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2650 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2651 GDIPCONST GpPointF
*points
, INT count
)
2653 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2655 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2658 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2659 GDIPCONST GpPoint
*points
, INT count
)
2665 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2668 return InvalidParameter
;
2670 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2674 for(i
= 0; i
< count
; i
++){
2675 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2676 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2679 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2685 /* Approximates cardinal spline with Bezier curves. */
2686 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2687 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2689 /* PolyBezier expects count*3-2 points. */
2690 INT i
, len_pt
= count
*3-2, save_state
;
2692 REAL x1
, x2
, y1
, y2
;
2695 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2697 if(!graphics
|| !pen
)
2698 return InvalidParameter
;
2704 return InvalidParameter
;
2708 FIXME("graphics object has no HDC\n");
2712 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
2716 tension
= tension
* TENSION_CONST
;
2718 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
2721 pt
[0].X
= points
[0].X
;
2722 pt
[0].Y
= points
[0].Y
;
2726 for(i
= 0; i
< count
-2; i
++){
2727 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
2731 pt
[3*i
+3].X
= points
[i
+1].X
;
2732 pt
[3*i
+3].Y
= points
[i
+1].Y
;
2737 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
2738 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
2740 pt
[len_pt
-2].X
= x1
;
2741 pt
[len_pt
-2].Y
= y1
;
2742 pt
[len_pt
-1].X
= points
[count
-1].X
;
2743 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
2745 save_state
= prepare_dc(graphics
, pen
);
2747 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
2750 restore_dc(graphics
, save_state
);
2755 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2756 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2762 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2765 return InvalidParameter
;
2767 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2771 for(i
= 0; i
< count
; i
++){
2772 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2773 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2776 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2782 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2783 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2786 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2788 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2789 return InvalidParameter
;
2792 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2795 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2796 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2799 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2805 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2806 return InvalidParameter
;
2809 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2812 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2813 REAL y
, REAL width
, REAL height
)
2819 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2821 if(!graphics
|| !pen
)
2822 return InvalidParameter
;
2829 FIXME("graphics object has no HDC\n");
2835 ptf
[1].X
= x
+ width
;
2836 ptf
[1].Y
= y
+ height
;
2838 save_state
= prepare_dc(graphics
, pen
);
2839 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2841 transform_and_round_points(graphics
, pti
, ptf
, 2);
2843 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2845 restore_dc(graphics
, save_state
);
2850 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2851 INT y
, INT width
, INT height
)
2853 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2855 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2859 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2864 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2866 if(!graphics
|| !image
)
2867 return InvalidParameter
;
2869 GdipGetImageWidth(image
, &width
);
2870 GdipGetImageHeight(image
, &height
);
2872 /* FIXME: we should use the graphics and image dpi, somehow */
2874 points
[0].X
= points
[2].X
= x
;
2875 points
[0].Y
= points
[1].Y
= y
;
2876 points
[1].X
= x
+ width
;
2877 points
[2].Y
= y
+ height
;
2879 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
2880 UnitPixel
, NULL
, NULL
, NULL
);
2883 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2886 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2888 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2891 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2892 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2896 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2898 points
[0].X
= points
[2].X
= x
;
2899 points
[0].Y
= points
[1].Y
= y
;
2901 /* FIXME: convert image coordinates to Graphics coordinates? */
2902 points
[1].X
= x
+ srcwidth
;
2903 points
[2].Y
= y
+ srcheight
;
2905 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2906 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2909 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2910 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2913 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2916 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2917 GDIPCONST GpPointF
*dstpoints
, INT count
)
2921 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2924 return InvalidParameter
;
2926 GdipGetImageWidth(image
, &width
);
2927 GdipGetImageHeight(image
, &height
);
2929 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2930 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2933 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2934 GDIPCONST GpPoint
*dstpoints
, INT count
)
2938 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2940 if (count
!= 3 || !dstpoints
)
2941 return InvalidParameter
;
2943 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2944 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2945 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2946 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2947 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2948 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2950 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2953 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2954 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2955 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2956 DrawImageAbort callback
, VOID
* callbackData
)
2963 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2964 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2968 return NotImplemented
;
2970 if(!graphics
|| !image
|| !points
|| count
!= 3)
2971 return InvalidParameter
;
2973 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2974 debugstr_pointf(&points
[2]));
2976 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2977 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2978 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2979 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
2981 transform_and_round_points(graphics
, pti
, ptf
, 4);
2987 FIXME("graphics object has no HDC\n");
2990 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2991 if(srcUnit
== UnitInch
)
2992 dx
= dy
= (REAL
) INCH_HIMETRIC
;
2993 else if(srcUnit
== UnitPixel
){
2994 dx
= ((REAL
) INCH_HIMETRIC
) /
2995 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
2996 dy
= ((REAL
) INCH_HIMETRIC
) /
2997 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
3000 return NotImplemented
;
3002 if(IPicture_Render(image
->picture
, graphics
->hdc
,
3003 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3004 srcx
* dx
, srcy
* dy
,
3005 srcwidth
* dx
, srcheight
* dy
,
3008 callback(callbackData
);
3009 return GenericError
;
3012 else if (image
->type
== ImageTypeBitmap
)
3014 GpBitmap
* bitmap
= (GpBitmap
*)image
;
3017 if (srcUnit
== UnitInch
)
3018 dx
= dy
= 96.0; /* FIXME: use the image resolution */
3019 else if (srcUnit
== UnitPixel
)
3022 return NotImplemented
;
3026 srcwidth
= srcwidth
* dx
;
3027 srcheight
= srcheight
* dy
;
3029 if (imageAttributes
||
3030 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
3031 !((GpBitmap
*)image
)->hbitmap
||
3032 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
3033 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
3034 srcx
< 0 || srcy
< 0 ||
3035 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
3042 int i
, x
, y
, src_stride
, dst_stride
;
3043 GpMatrix
*dst_to_src
;
3044 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
3045 LPBYTE src_data
, dst_data
;
3046 BitmapData lockeddata
;
3047 InterpolationMode interpolation
= graphics
->interpolation
;
3048 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3049 REAL x_dx
, x_dy
, y_dx
, y_dy
;
3050 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
3052 if (!imageAttributes
)
3053 imageAttributes
= &defaultImageAttributes
;
3055 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3056 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3059 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3060 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3061 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3062 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3065 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3066 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3067 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3068 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3069 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3070 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3072 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
3073 if (stat
!= Ok
) return stat
;
3075 stat
= GdipInvertMatrix(dst_to_src
);
3078 GdipDeleteMatrix(dst_to_src
);
3082 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3085 GdipDeleteMatrix(dst_to_src
);
3089 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3091 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3092 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3094 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3098 GdipDeleteMatrix(dst_to_src
);
3101 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3103 /* Read the bits we need from the source bitmap into an ARGB buffer. */
3104 lockeddata
.Width
= src_area
.Width
;
3105 lockeddata
.Height
= src_area
.Height
;
3106 lockeddata
.Stride
= src_stride
;
3107 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3108 lockeddata
.Scan0
= src_data
;
3110 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3111 PixelFormat32bppARGB
, &lockeddata
);
3114 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3118 if (src_data
!= dst_data
)
3121 GdipDeleteMatrix(dst_to_src
);
3125 apply_image_attributes(imageAttributes
, src_data
,
3126 src_area
.Width
, src_area
.Height
,
3127 src_stride
, ColorAdjustTypeBitmap
);
3129 /* Transform the bits as needed to the destination. */
3130 GdipTransformMatrixPoints(dst_to_src
, dst_to_src_points
, 3);
3132 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3133 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3134 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3135 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3137 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3139 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3141 GpPointF src_pointf
;
3144 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3145 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3147 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3149 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3150 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
, imageAttributes
, interpolation
);
3156 GdipDeleteMatrix(dst_to_src
);
3160 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3161 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3170 int temp_hdc
=0, temp_bitmap
=0;
3171 HBITMAP hbitmap
, old_hbm
=NULL
;
3173 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3174 bitmap
->format
== PixelFormat24bppRGB
||
3175 bitmap
->format
== PixelFormat32bppRGB
||
3176 bitmap
->format
== PixelFormat32bppPARGB
))
3178 BITMAPINFOHEADER bih
;
3180 PixelFormat dst_format
;
3182 /* we can't draw a bitmap of this format directly */
3183 hdc
= CreateCompatibleDC(0);
3187 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3188 bih
.biWidth
= bitmap
->width
;
3189 bih
.biHeight
= -bitmap
->height
;
3191 bih
.biBitCount
= 32;
3192 bih
.biCompression
= BI_RGB
;
3193 bih
.biSizeImage
= 0;
3194 bih
.biXPelsPerMeter
= 0;
3195 bih
.biYPelsPerMeter
= 0;
3197 bih
.biClrImportant
= 0;
3199 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3200 (void**)&temp_bits
, NULL
, 0);
3202 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3203 dst_format
= PixelFormat32bppPARGB
;
3205 dst_format
= PixelFormat32bppRGB
;
3207 convert_pixels(bitmap
->width
, bitmap
->height
,
3208 bitmap
->width
*4, temp_bits
, dst_format
,
3209 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
3213 hbitmap
= bitmap
->hbitmap
;
3215 temp_hdc
= (hdc
== 0);
3220 if (!hdc
) hdc
= CreateCompatibleDC(0);
3221 old_hbm
= SelectObject(hdc
, hbitmap
);
3224 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3228 bf
.BlendOp
= AC_SRC_OVER
;
3230 bf
.SourceConstantAlpha
= 255;
3231 bf
.AlphaFormat
= AC_SRC_ALPHA
;
3233 GdiAlphaBlend(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3234 hdc
, srcx
, srcy
, srcwidth
, srcheight
, bf
);
3238 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3239 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3244 SelectObject(hdc
, old_hbm
);
3249 DeleteObject(hbitmap
);
3254 ERR("GpImage with no IPicture or HBITMAP?!\n");
3255 return NotImplemented
;
3261 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3262 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3263 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3264 DrawImageAbort callback
, VOID
* callbackData
)
3266 GpPointF pointsF
[3];
3269 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3270 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3273 if(!points
|| count
!=3)
3274 return InvalidParameter
;
3276 for(i
= 0; i
< count
; i
++){
3277 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3278 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3281 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3282 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3283 callback
, callbackData
);
3286 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3287 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3288 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3289 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3290 VOID
* callbackData
)
3294 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3295 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3296 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3300 points
[1].X
= dstx
+ dstwidth
;
3303 points
[2].Y
= dsty
+ dstheight
;
3305 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3306 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3309 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3310 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3311 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3312 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3313 VOID
* callbackData
)
3317 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3318 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3319 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3323 points
[1].X
= dstx
+ dstwidth
;
3326 points
[2].Y
= dsty
+ dstheight
;
3328 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3329 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3332 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3333 REAL x
, REAL y
, REAL width
, REAL height
)
3339 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3341 if(!graphics
|| !image
)
3342 return InvalidParameter
;
3344 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3348 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3349 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3350 unit
, NULL
, NULL
, NULL
);
3353 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3354 INT x
, INT y
, INT width
, INT height
)
3356 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3358 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3361 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3362 REAL y1
, REAL x2
, REAL y2
)
3368 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3370 if(!pen
|| !graphics
)
3371 return InvalidParameter
;
3378 FIXME("graphics object has no HDC\n");
3387 save_state
= prepare_dc(graphics
, pen
);
3389 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3391 restore_dc(graphics
, save_state
);
3396 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3397 INT y1
, INT x2
, INT y2
)
3403 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3405 if(!pen
|| !graphics
)
3406 return InvalidParameter
;
3413 FIXME("graphics object has no HDC\n");
3422 save_state
= prepare_dc(graphics
, pen
);
3424 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3426 restore_dc(graphics
, save_state
);
3431 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3432 GpPointF
*points
, INT count
)
3437 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3439 if(!pen
|| !graphics
|| (count
< 2))
3440 return InvalidParameter
;
3447 FIXME("graphics object has no HDC\n");
3451 save_state
= prepare_dc(graphics
, pen
);
3453 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
3455 restore_dc(graphics
, save_state
);
3460 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3461 GpPoint
*points
, INT count
)
3465 GpPointF
*ptf
= NULL
;
3468 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3470 if(!pen
|| !graphics
|| (count
< 2))
3471 return InvalidParameter
;
3478 FIXME("graphics object has no HDC\n");
3482 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3483 if(!ptf
) return OutOfMemory
;
3485 for(i
= 0; i
< count
; i
++){
3486 ptf
[i
].X
= (REAL
) points
[i
].X
;
3487 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3490 save_state
= prepare_dc(graphics
, pen
);
3492 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
3494 restore_dc(graphics
, save_state
);
3500 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3505 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3507 if(!pen
|| !graphics
)
3508 return InvalidParameter
;
3515 FIXME("graphics object has no HDC\n");
3519 save_state
= prepare_dc(graphics
, pen
);
3521 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3522 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3524 restore_dc(graphics
, save_state
);
3529 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3530 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3534 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3535 width
, height
, startAngle
, sweepAngle
);
3537 if(!graphics
|| !pen
)
3538 return InvalidParameter
;
3545 FIXME("graphics object has no HDC\n");
3549 save_state
= prepare_dc(graphics
, pen
);
3550 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3552 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3554 restore_dc(graphics
, save_state
);
3559 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3560 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3562 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3563 width
, height
, startAngle
, sweepAngle
);
3565 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3568 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3569 REAL y
, REAL width
, REAL height
)
3575 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3577 if(!pen
|| !graphics
)
3578 return InvalidParameter
;
3585 FIXME("graphics object has no HDC\n");
3591 ptf
[1].X
= x
+ width
;
3593 ptf
[2].X
= x
+ width
;
3594 ptf
[2].Y
= y
+ height
;
3596 ptf
[3].Y
= y
+ height
;
3598 save_state
= prepare_dc(graphics
, pen
);
3599 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3601 transform_and_round_points(graphics
, pti
, ptf
, 4);
3602 Polygon(graphics
->hdc
, pti
, 4);
3604 restore_dc(graphics
, save_state
);
3609 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3610 INT y
, INT width
, INT height
)
3612 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3614 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3617 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3618 GDIPCONST GpRectF
* rects
, INT count
)
3624 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3626 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3627 return InvalidParameter
;
3634 FIXME("graphics object has no HDC\n");
3638 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
3639 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
3647 for(i
= 0; i
< count
; i
++){
3648 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
3649 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
3650 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
3651 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
3654 save_state
= prepare_dc(graphics
, pen
);
3655 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3657 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
3659 for(i
= 0; i
< count
; i
++)
3660 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
3662 restore_dc(graphics
, save_state
);
3670 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3671 GDIPCONST GpRect
* rects
, INT count
)
3677 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3679 if(!rects
|| count
<=0)
3680 return InvalidParameter
;
3682 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3686 for(i
= 0;i
< count
;i
++){
3687 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3688 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3689 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3690 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3693 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3699 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3700 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3705 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3706 count
, tension
, fill
);
3708 if(!graphics
|| !brush
|| !points
)
3709 return InvalidParameter
;
3714 if(count
== 1) /* Do nothing */
3717 stat
= GdipCreatePath(fill
, &path
);
3721 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3723 GdipDeletePath(path
);
3727 stat
= GdipFillPath(graphics
, brush
, path
);
3729 GdipDeletePath(path
);
3733 GdipDeletePath(path
);
3738 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3739 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3745 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3746 count
, tension
, fill
);
3748 if(!points
|| count
== 0)
3749 return InvalidParameter
;
3751 if(count
== 1) /* Do nothing */
3754 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3758 for(i
= 0;i
< count
;i
++){
3759 ptf
[i
].X
= (REAL
)points
[i
].X
;
3760 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3763 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3770 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3771 GDIPCONST GpPointF
*points
, INT count
)
3773 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3774 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3775 0.5f
, FillModeAlternate
);
3778 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3779 GDIPCONST GpPoint
*points
, INT count
)
3781 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3782 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3783 0.5f
, FillModeAlternate
);
3786 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3787 REAL y
, REAL width
, REAL height
)
3792 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3794 if(!graphics
|| !brush
)
3795 return InvalidParameter
;
3800 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3804 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3807 stat
= GdipFillPath(graphics
, brush
, path
);
3809 GdipDeletePath(path
);
3815 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3816 INT y
, INT width
, INT height
)
3818 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3820 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3823 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3828 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3829 return NotImplemented
;
3831 save_state
= SaveDC(graphics
->hdc
);
3832 EndPath(graphics
->hdc
);
3833 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3836 BeginPath(graphics
->hdc
);
3837 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3838 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3843 EndPath(graphics
->hdc
);
3844 brush_fill_path(graphics
, brush
);
3849 RestoreDC(graphics
->hdc
, save_state
);
3854 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3859 if (!brush_can_fill_pixels(brush
))
3860 return NotImplemented
;
3862 /* FIXME: This could probably be done more efficiently without regions. */
3864 stat
= GdipCreateRegionPath(path
, &rgn
);
3868 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3870 GdipDeleteRegion(rgn
);
3876 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3878 GpStatus stat
= NotImplemented
;
3880 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3882 if(!brush
|| !graphics
|| !path
)
3883 return InvalidParameter
;
3888 if (!graphics
->image
)
3889 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3891 if (stat
== NotImplemented
)
3892 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3894 if (stat
== NotImplemented
)
3896 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3903 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3904 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3909 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3910 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3912 if(!graphics
|| !brush
)
3913 return InvalidParameter
;
3918 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3922 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3925 stat
= GdipFillPath(graphics
, brush
, path
);
3927 GdipDeletePath(path
);
3933 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3934 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3936 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3937 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3939 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3942 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3943 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3948 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3950 if(!graphics
|| !brush
|| !points
|| !count
)
3951 return InvalidParameter
;
3956 stat
= GdipCreatePath(fillMode
, &path
);
3960 stat
= GdipAddPathPolygon(path
, points
, count
);
3963 stat
= GdipFillPath(graphics
, brush
, path
);
3965 GdipDeletePath(path
);
3971 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3972 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3977 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3979 if(!graphics
|| !brush
|| !points
|| !count
)
3980 return InvalidParameter
;
3985 stat
= GdipCreatePath(fillMode
, &path
);
3989 stat
= GdipAddPathPolygonI(path
, points
, count
);
3992 stat
= GdipFillPath(graphics
, brush
, path
);
3994 GdipDeletePath(path
);
4000 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4001 GDIPCONST GpPointF
*points
, INT count
)
4003 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4005 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4008 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4009 GDIPCONST GpPoint
*points
, INT count
)
4011 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4013 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4016 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4017 REAL x
, REAL y
, REAL width
, REAL height
)
4022 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4024 if(!graphics
|| !brush
)
4025 return InvalidParameter
;
4030 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4034 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
4037 stat
= GdipFillPath(graphics
, brush
, path
);
4039 GdipDeletePath(path
);
4045 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4046 INT x
, INT y
, INT width
, INT height
)
4048 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4050 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
4053 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4059 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4062 return InvalidParameter
;
4064 for(i
= 0; i
< count
; i
++){
4065 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
4066 if(ret
!= Ok
) return ret
;
4072 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4079 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4081 if(!rects
|| count
<= 0)
4082 return InvalidParameter
;
4084 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
4088 for(i
= 0; i
< count
; i
++){
4089 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4090 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4091 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
4092 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4095 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4101 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4109 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
4110 return NotImplemented
;
4112 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4116 save_state
= SaveDC(graphics
->hdc
);
4117 EndPath(graphics
->hdc
);
4119 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4121 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4123 BeginPath(graphics
->hdc
);
4124 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4125 EndPath(graphics
->hdc
);
4127 brush_fill_path(graphics
, brush
);
4130 RestoreDC(graphics
->hdc
, save_state
);
4137 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4141 GpRegion
*temp_region
;
4142 GpMatrix
*world_to_device
;
4143 GpRectF graphics_bounds
;
4147 GpRect gp_bound_rect
;
4149 if (!brush_can_fill_pixels(brush
))
4150 return NotImplemented
;
4152 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
4155 stat
= GdipCloneRegion(region
, &temp_region
);
4159 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
4160 CoordinateSpaceWorld
, &world_to_device
);
4164 stat
= GdipTransformRegion(temp_region
, world_to_device
);
4166 GdipDeleteMatrix(world_to_device
);
4170 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4173 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4175 GdipDeleteRegion(temp_region
);
4178 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4180 DeleteObject(hregion
);
4186 gp_bound_rect
.X
= bound_rect
.left
;
4187 gp_bound_rect
.Y
= bound_rect
.top
;
4188 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4189 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4191 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4197 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4198 &gp_bound_rect
, gp_bound_rect
.Width
);
4201 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4202 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4203 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4205 GdipFree(pixel_data
);
4208 DeleteObject(hregion
);
4214 /*****************************************************************************
4215 * GdipFillRegion [GDIPLUS.@]
4217 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4220 GpStatus stat
= NotImplemented
;
4222 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4224 if (!(graphics
&& brush
&& region
))
4225 return InvalidParameter
;
4230 if (!graphics
->image
)
4231 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4233 if (stat
== NotImplemented
)
4234 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4236 if (stat
== NotImplemented
)
4238 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4245 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4247 TRACE("(%p,%u)\n", graphics
, intention
);
4250 return InvalidParameter
;
4255 /* We have no internal operation queue, so there's no need to clear it. */
4263 /*****************************************************************************
4264 * GdipGetClipBounds [GDIPLUS.@]
4266 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4268 TRACE("(%p, %p)\n", graphics
, rect
);
4271 return InvalidParameter
;
4276 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4279 /*****************************************************************************
4280 * GdipGetClipBoundsI [GDIPLUS.@]
4282 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4284 TRACE("(%p, %p)\n", graphics
, rect
);
4287 return InvalidParameter
;
4292 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4295 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4296 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4297 CompositingMode
*mode
)
4299 TRACE("(%p, %p)\n", graphics
, mode
);
4301 if(!graphics
|| !mode
)
4302 return InvalidParameter
;
4307 *mode
= graphics
->compmode
;
4312 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4313 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4314 CompositingQuality
*quality
)
4316 TRACE("(%p, %p)\n", graphics
, quality
);
4318 if(!graphics
|| !quality
)
4319 return InvalidParameter
;
4324 *quality
= graphics
->compqual
;
4329 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4330 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4331 InterpolationMode
*mode
)
4333 TRACE("(%p, %p)\n", graphics
, mode
);
4335 if(!graphics
|| !mode
)
4336 return InvalidParameter
;
4341 *mode
= graphics
->interpolation
;
4346 /* FIXME: Need to handle color depths less than 24bpp */
4347 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4349 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4351 if(!graphics
|| !argb
)
4352 return InvalidParameter
;
4360 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4362 TRACE("(%p, %p)\n", graphics
, scale
);
4364 if(!graphics
|| !scale
)
4365 return InvalidParameter
;
4370 *scale
= graphics
->scale
;
4375 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4377 TRACE("(%p, %p)\n", graphics
, unit
);
4379 if(!graphics
|| !unit
)
4380 return InvalidParameter
;
4385 *unit
= graphics
->unit
;
4390 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4391 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4394 TRACE("(%p, %p)\n", graphics
, mode
);
4396 if(!graphics
|| !mode
)
4397 return InvalidParameter
;
4402 *mode
= graphics
->pixeloffset
;
4407 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4408 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4410 TRACE("(%p, %p)\n", graphics
, mode
);
4412 if(!graphics
|| !mode
)
4413 return InvalidParameter
;
4418 *mode
= graphics
->smoothing
;
4423 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4425 TRACE("(%p, %p)\n", graphics
, contrast
);
4427 if(!graphics
|| !contrast
)
4428 return InvalidParameter
;
4430 *contrast
= graphics
->textcontrast
;
4435 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4436 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4437 TextRenderingHint
*hint
)
4439 TRACE("(%p, %p)\n", graphics
, hint
);
4441 if(!graphics
|| !hint
)
4442 return InvalidParameter
;
4447 *hint
= graphics
->texthint
;
4452 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4457 TRACE("(%p, %p)\n", graphics
, rect
);
4459 if(!graphics
|| !rect
)
4460 return InvalidParameter
;
4465 /* intersect window and graphics clipping regions */
4466 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4469 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4472 /* get bounds of the region */
4473 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4476 GdipDeleteRegion(clip_rgn
);
4481 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4486 TRACE("(%p, %p)\n", graphics
, rect
);
4488 if(!graphics
|| !rect
)
4489 return InvalidParameter
;
4491 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4493 rect
->X
= roundr(rectf
.X
);
4494 rect
->Y
= roundr(rectf
.Y
);
4495 rect
->Width
= roundr(rectf
.Width
);
4496 rect
->Height
= roundr(rectf
.Height
);
4502 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4504 TRACE("(%p, %p)\n", graphics
, matrix
);
4506 if(!graphics
|| !matrix
)
4507 return InvalidParameter
;
4512 *matrix
= *graphics
->worldtrans
;
4516 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4522 TRACE("(%p, %x)\n", graphics
, color
);
4525 return InvalidParameter
;
4530 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4533 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4534 GdipDeleteBrush((GpBrush
*)brush
);
4538 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4539 wnd_rect
.Width
, wnd_rect
.Height
);
4541 GdipDeleteBrush((GpBrush
*)brush
);
4546 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4548 TRACE("(%p, %p)\n", graphics
, res
);
4550 if(!graphics
|| !res
)
4551 return InvalidParameter
;
4553 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4556 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4562 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4564 if(!graphics
|| !result
)
4565 return InvalidParameter
;
4572 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4573 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4576 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4579 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4582 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4585 GdipDeleteRegion(rgn
);
4589 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4591 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4594 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4600 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4602 if(!graphics
|| !result
)
4603 return InvalidParameter
;
4610 pts
[1].X
= x
+ width
;
4611 pts
[1].Y
= y
+ height
;
4613 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4614 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4617 pts
[1].X
-= pts
[0].X
;
4618 pts
[1].Y
-= pts
[0].Y
;
4620 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4623 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4626 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4629 GdipDeleteRegion(rgn
);
4633 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4635 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4638 GpStatus
gdip_format_string(HDC hdc
,
4639 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4640 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4641 gdip_format_string_callback callback
, void *user_data
)
4644 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4645 nheight
, lineend
, lineno
= 0;
4647 StringAlignment halign
;
4651 if(length
== -1) length
= lstrlenW(string
);
4653 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4654 if(!stringdup
) return OutOfMemory
;
4656 nwidth
= roundr(rect
->Width
);
4657 nheight
= roundr(rect
->Height
);
4659 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
4660 if (rect
->Height
>= INT_MAX
|| rect
->Height
< 0.5) nheight
= INT_MAX
;
4662 for(i
= 0, j
= 0; i
< length
; i
++){
4663 /* FIXME: This makes the indexes passed to callback inaccurate. */
4664 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4667 stringdup
[j
] = string
[i
];
4673 if (format
) halign
= format
->align
;
4674 else halign
= StringAlignmentNear
;
4676 while(sum
< length
){
4677 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4678 nwidth
, &fit
, NULL
, &size
);
4684 for(lret
= 0; lret
< fit
; lret
++)
4685 if(*(stringdup
+ sum
+ lret
) == '\n')
4688 /* Line break code (may look strange, but it imitates windows). */
4690 lineend
= fit
= lret
; /* this is not an off-by-one error */
4691 else if(fit
< (length
- sum
)){
4692 if(*(stringdup
+ sum
+ fit
) == ' ')
4693 while(*(stringdup
+ sum
+ fit
) == ' ')
4696 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4699 if(*(stringdup
+ sum
+ fit
) == '\t')
4708 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4709 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4715 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4716 nwidth
, &j
, NULL
, &size
);
4718 bounds
.Width
= size
.cx
;
4720 if(height
+ size
.cy
> nheight
)
4721 bounds
.Height
= nheight
- (height
+ size
.cy
);
4723 bounds
.Height
= size
.cy
;
4725 bounds
.Y
= rect
->Y
+ height
;
4729 case StringAlignmentNear
:
4733 case StringAlignmentCenter
:
4734 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4736 case StringAlignmentFar
:
4737 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4741 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4742 font
, rect
, format
, lineno
, &bounds
, user_data
);
4747 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4751 if(height
> nheight
)
4754 /* Stop if this was a linewrap (but not if it was a linebreak). */
4755 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
4759 GdipFree(stringdup
);
4764 struct measure_ranges_args
{
4768 static GpStatus
measure_ranges_callback(HDC hdc
,
4769 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4770 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4771 INT lineno
, const RectF
*bounds
, void *user_data
)
4775 struct measure_ranges_args
*args
= user_data
;
4777 for (i
=0; i
<format
->range_count
; i
++)
4779 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4780 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4781 if (range_start
< range_end
)
4786 range_rect
.Y
= bounds
->Y
;
4787 range_rect
.Height
= bounds
->Height
;
4789 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4790 INT_MAX
, NULL
, NULL
, &range_size
);
4791 range_rect
.X
= bounds
->X
+ range_size
.cx
;
4793 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4794 INT_MAX
, NULL
, NULL
, &range_size
);
4795 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
4797 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4806 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4807 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4808 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4809 INT regionCount
, GpRegion
** regions
)
4814 struct measure_ranges_args args
;
4815 HDC hdc
, temp_hdc
=NULL
;
4817 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4818 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4820 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4821 return InvalidParameter
;
4823 if (regionCount
< stringFormat
->range_count
)
4824 return InvalidParameter
;
4828 hdc
= temp_hdc
= CreateCompatibleDC(0);
4829 if (!temp_hdc
) return OutOfMemory
;
4832 hdc
= graphics
->hdc
;
4834 if (stringFormat
->attr
)
4835 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4837 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&font
->lfw
));
4839 for (i
=0; i
<stringFormat
->range_count
; i
++)
4841 stat
= GdipSetEmpty(regions
[i
]);
4846 args
.regions
= regions
;
4848 stat
= gdip_format_string(hdc
, string
, length
, font
, layoutRect
, stringFormat
,
4849 measure_ranges_callback
, &args
);
4851 DeleteObject(SelectObject(hdc
, oldfont
));
4859 struct measure_string_args
{
4861 INT
*codepointsfitted
;
4865 static GpStatus
measure_string_callback(HDC hdc
,
4866 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4867 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4868 INT lineno
, const RectF
*bounds
, void *user_data
)
4870 struct measure_string_args
*args
= user_data
;
4872 if (bounds
->Width
> args
->bounds
->Width
)
4873 args
->bounds
->Width
= bounds
->Width
;
4875 if (bounds
->Height
+ bounds
->Y
> args
->bounds
->Height
+ args
->bounds
->Y
)
4876 args
->bounds
->Height
= bounds
->Height
+ bounds
->Y
- args
->bounds
->Y
;
4878 if (args
->codepointsfitted
)
4879 *args
->codepointsfitted
= index
+ length
;
4881 if (args
->linesfilled
)
4882 (*args
->linesfilled
)++;
4887 /* Find the smallest rectangle that bounds the text when it is printed in rect
4888 * according to the format options listed in format. If rect has 0 width and
4889 * height, then just find the smallest rectangle that bounds the text when it's
4890 * printed at location (rect->X, rect-Y). */
4891 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4892 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4893 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4894 INT
*codepointsfitted
, INT
*linesfilled
)
4897 struct measure_string_args args
;
4898 HDC temp_hdc
=NULL
, hdc
;
4900 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4901 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4902 bounds
, codepointsfitted
, linesfilled
);
4904 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4905 return InvalidParameter
;
4909 hdc
= temp_hdc
= CreateCompatibleDC(0);
4910 if (!temp_hdc
) return OutOfMemory
;
4913 hdc
= graphics
->hdc
;
4915 if(linesfilled
) *linesfilled
= 0;
4916 if(codepointsfitted
) *codepointsfitted
= 0;
4919 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4921 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&font
->lfw
));
4923 bounds
->X
= rect
->X
;
4924 bounds
->Y
= rect
->Y
;
4925 bounds
->Width
= 0.0;
4926 bounds
->Height
= 0.0;
4928 args
.bounds
= bounds
;
4929 args
.codepointsfitted
= codepointsfitted
;
4930 args
.linesfilled
= linesfilled
;
4932 gdip_format_string(hdc
, string
, length
, font
, rect
, format
,
4933 measure_string_callback
, &args
);
4935 DeleteObject(SelectObject(hdc
, oldfont
));
4943 struct draw_string_args
{
4944 GpGraphics
*graphics
;
4945 GDIPCONST GpBrush
*brush
;
4946 REAL x
, y
, rel_width
, rel_height
, ascent
;
4949 static GpStatus
draw_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
, void *user_data
)
4954 struct draw_string_args
*args
= user_data
;
4957 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4958 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4960 return GdipDrawDriverString(args
->graphics
, &string
[index
], length
, font
,
4961 args
->brush
, &position
,
4962 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4965 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4966 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4967 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4971 GpPointF pt
[3], rectcpy
[4];
4973 REAL rel_width
, rel_height
;
4976 struct draw_string_args args
;
4978 HDC hdc
, temp_hdc
=NULL
;
4979 TEXTMETRICW textmetric
;
4981 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4982 length
, font
, debugstr_rectf(rect
), format
, brush
);
4984 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4985 return InvalidParameter
;
4989 hdc
= graphics
->hdc
;
4993 hdc
= temp_hdc
= CreateCompatibleDC(0);
4997 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4999 /* Should be no need to explicitly test for StringAlignmentNear as
5000 * that is default behavior if no alignment is passed. */
5001 if(format
->vertalign
!= StringAlignmentNear
){
5003 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
5005 if(format
->vertalign
== StringAlignmentCenter
)
5006 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5007 else if(format
->vertalign
== StringAlignmentFar
)
5008 offsety
= (rect
->Height
- bounds
.Height
);
5012 save_state
= SaveDC(hdc
);
5020 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5021 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5022 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5023 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5024 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5026 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5027 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
5028 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5029 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
5030 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5032 scaled_rect
.X
= 0.0;
5033 scaled_rect
.Y
= 0.0;
5034 scaled_rect
.Width
= rel_width
* rect
->Width
;
5035 scaled_rect
.Height
= rel_height
* rect
->Height
;
5037 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
5039 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5040 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5041 SelectClipRgn(hdc
, rgn
);
5044 get_font_hfont(graphics
, font
, &gdifont
);
5045 SelectObject(hdc
, gdifont
);
5047 args
.graphics
= graphics
;
5051 args
.y
= rect
->Y
+ offsety
;
5053 args
.rel_width
= rel_width
;
5054 args
.rel_height
= rel_height
;
5056 GetTextMetricsW(hdc
, &textmetric
);
5057 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5059 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
5060 draw_string_callback
, &args
);
5063 DeleteObject(gdifont
);
5065 RestoreDC(hdc
, save_state
);
5072 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5074 TRACE("(%p)\n", graphics
);
5077 return InvalidParameter
;
5082 return GdipSetInfinite(graphics
->clip
);
5085 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5087 TRACE("(%p)\n", graphics
);
5090 return InvalidParameter
;
5095 graphics
->worldtrans
->matrix
[0] = 1.0;
5096 graphics
->worldtrans
->matrix
[1] = 0.0;
5097 graphics
->worldtrans
->matrix
[2] = 0.0;
5098 graphics
->worldtrans
->matrix
[3] = 1.0;
5099 graphics
->worldtrans
->matrix
[4] = 0.0;
5100 graphics
->worldtrans
->matrix
[5] = 0.0;
5105 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5107 return GdipEndContainer(graphics
, state
);
5110 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5111 GpMatrixOrder order
)
5113 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5116 return InvalidParameter
;
5121 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
5124 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5126 return GdipBeginContainer2(graphics
, state
);
5129 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5130 GraphicsContainer
*state
)
5132 GraphicsContainerItem
*container
;
5135 TRACE("(%p, %p)\n", graphics
, state
);
5137 if(!graphics
|| !state
)
5138 return InvalidParameter
;
5140 sts
= init_container(&container
, graphics
);
5144 list_add_head(&graphics
->containers
, &container
->entry
);
5145 *state
= graphics
->contid
= container
->contid
;
5150 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5152 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5153 return NotImplemented
;
5156 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5158 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5159 return NotImplemented
;
5162 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5164 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5165 return NotImplemented
;
5168 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5171 GraphicsContainerItem
*container
, *container2
;
5173 TRACE("(%p, %x)\n", graphics
, state
);
5176 return InvalidParameter
;
5178 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5179 if(container
->contid
== state
)
5183 /* did not find a matching container */
5184 if(&container
->entry
== &graphics
->containers
)
5187 sts
= restore_container(graphics
, container
);
5191 /* remove all of the containers on top of the found container */
5192 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5193 if(container
->contid
== state
)
5195 list_remove(&container
->entry
);
5196 delete_container(container
);
5199 list_remove(&container
->entry
);
5200 delete_container(container
);
5205 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5206 REAL sy
, GpMatrixOrder order
)
5208 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5211 return InvalidParameter
;
5216 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
5219 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5222 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5224 if(!graphics
|| !srcgraphics
)
5225 return InvalidParameter
;
5227 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5230 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5231 CompositingMode mode
)
5233 TRACE("(%p, %d)\n", graphics
, mode
);
5236 return InvalidParameter
;
5241 graphics
->compmode
= mode
;
5246 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5247 CompositingQuality quality
)
5249 TRACE("(%p, %d)\n", graphics
, quality
);
5252 return InvalidParameter
;
5257 graphics
->compqual
= quality
;
5262 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5263 InterpolationMode mode
)
5265 TRACE("(%p, %d)\n", graphics
, mode
);
5267 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5268 return InvalidParameter
;
5273 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5274 mode
= InterpolationModeBilinear
;
5276 if (mode
== InterpolationModeHighQuality
)
5277 mode
= InterpolationModeHighQualityBicubic
;
5279 graphics
->interpolation
= mode
;
5284 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5286 TRACE("(%p, %.2f)\n", graphics
, scale
);
5288 if(!graphics
|| (scale
<= 0.0))
5289 return InvalidParameter
;
5294 graphics
->scale
= scale
;
5299 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5301 TRACE("(%p, %d)\n", graphics
, unit
);
5304 return InvalidParameter
;
5309 if(unit
== UnitWorld
)
5310 return InvalidParameter
;
5312 graphics
->unit
= unit
;
5317 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5320 TRACE("(%p, %d)\n", graphics
, mode
);
5323 return InvalidParameter
;
5328 graphics
->pixeloffset
= mode
;
5333 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5337 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5340 FIXME("not implemented\n");
5342 return NotImplemented
;
5345 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5349 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5352 FIXME("not implemented\n");
5356 return NotImplemented
;
5359 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5361 TRACE("(%p, %d)\n", graphics
, mode
);
5364 return InvalidParameter
;
5369 graphics
->smoothing
= mode
;
5374 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5376 TRACE("(%p, %d)\n", graphics
, contrast
);
5379 return InvalidParameter
;
5381 graphics
->textcontrast
= contrast
;
5386 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5387 TextRenderingHint hint
)
5389 TRACE("(%p, %d)\n", graphics
, hint
);
5391 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5392 return InvalidParameter
;
5397 graphics
->texthint
= hint
;
5402 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5404 TRACE("(%p, %p)\n", graphics
, matrix
);
5406 if(!graphics
|| !matrix
)
5407 return InvalidParameter
;
5412 GdipDeleteMatrix(graphics
->worldtrans
);
5413 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
5416 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5417 REAL dy
, GpMatrixOrder order
)
5419 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5422 return InvalidParameter
;
5427 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
5430 /*****************************************************************************
5431 * GdipSetClipHrgn [GDIPLUS.@]
5433 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5438 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5441 return InvalidParameter
;
5443 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5447 status
= GdipSetClipRegion(graphics
, region
, mode
);
5449 GdipDeleteRegion(region
);
5453 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5455 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5458 return InvalidParameter
;
5463 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5466 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5467 REAL width
, REAL height
,
5472 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5475 return InvalidParameter
;
5483 rect
.Height
= height
;
5485 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5488 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5489 INT width
, INT height
,
5492 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5495 return InvalidParameter
;
5500 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5503 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5506 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5508 if(!graphics
|| !region
)
5509 return InvalidParameter
;
5514 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5517 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5522 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5525 FIXME("not implemented\n");
5527 return NotImplemented
;
5530 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5536 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5538 if(!graphics
|| !pen
|| count
<=0)
5539 return InvalidParameter
;
5546 FIXME("graphics object has no HDC\n");
5550 pti
= GdipAlloc(sizeof(POINT
) * count
);
5552 save_state
= prepare_dc(graphics
, pen
);
5553 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5555 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5556 Polygon(graphics
->hdc
, pti
, count
);
5558 restore_dc(graphics
, save_state
);
5564 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5571 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5573 if(count
<=0) return InvalidParameter
;
5574 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5576 for(i
= 0;i
< count
; i
++){
5577 ptf
[i
].X
= (REAL
)points
[i
].X
;
5578 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5581 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5587 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5589 TRACE("(%p, %p)\n", graphics
, dpi
);
5591 if(!graphics
|| !dpi
)
5592 return InvalidParameter
;
5597 if (graphics
->image
)
5598 *dpi
= graphics
->image
->xres
;
5600 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
5605 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5607 TRACE("(%p, %p)\n", graphics
, dpi
);
5609 if(!graphics
|| !dpi
)
5610 return InvalidParameter
;
5615 if (graphics
->image
)
5616 *dpi
= graphics
->image
->yres
;
5618 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
5623 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5624 GpMatrixOrder order
)
5629 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5631 if(!graphics
|| !matrix
)
5632 return InvalidParameter
;
5637 m
= *(graphics
->worldtrans
);
5639 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5641 *(graphics
->worldtrans
) = m
;
5646 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5647 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5649 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5653 TRACE("(%p, %p)\n", graphics
, hdc
);
5655 if(!graphics
|| !hdc
)
5656 return InvalidParameter
;
5661 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5663 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5665 else if (!graphics
->hdc
||
5666 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5668 /* Create a fake HDC and fill it with a constant color. */
5672 BITMAPINFOHEADER bmih
;
5675 stat
= get_graphics_bounds(graphics
, &bounds
);
5679 graphics
->temp_hbitmap_width
= bounds
.Width
;
5680 graphics
->temp_hbitmap_height
= bounds
.Height
;
5682 bmih
.biSize
= sizeof(bmih
);
5683 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5684 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5686 bmih
.biBitCount
= 32;
5687 bmih
.biCompression
= BI_RGB
;
5688 bmih
.biSizeImage
= 0;
5689 bmih
.biXPelsPerMeter
= 0;
5690 bmih
.biYPelsPerMeter
= 0;
5692 bmih
.biClrImportant
= 0;
5694 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5695 (void**)&graphics
->temp_bits
, NULL
, 0);
5697 return GenericError
;
5699 temp_hdc
= CreateCompatibleDC(0);
5702 DeleteObject(hbitmap
);
5703 return GenericError
;
5706 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5707 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5709 SelectObject(temp_hdc
, hbitmap
);
5711 graphics
->temp_hbitmap
= hbitmap
;
5712 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5716 *hdc
= graphics
->hdc
;
5720 graphics
->busy
= TRUE
;
5725 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5729 TRACE("(%p, %p)\n", graphics
, hdc
);
5731 if(!graphics
|| !hdc
|| !graphics
->busy
)
5732 return InvalidParameter
;
5734 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5736 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5738 else if (graphics
->temp_hdc
== hdc
)
5743 /* Find the pixels that have changed, and mark them as opaque. */
5744 pos
= (DWORD
*)graphics
->temp_bits
;
5745 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5747 if (*pos
!= DC_BACKGROUND_KEY
)
5754 /* Write the changed pixels to the real target. */
5755 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5756 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5757 graphics
->temp_hbitmap_width
* 4);
5760 DeleteDC(graphics
->temp_hdc
);
5761 DeleteObject(graphics
->temp_hbitmap
);
5762 graphics
->temp_hdc
= NULL
;
5763 graphics
->temp_hbitmap
= NULL
;
5765 else if (hdc
!= graphics
->hdc
)
5767 stat
= InvalidParameter
;
5771 graphics
->busy
= FALSE
;
5776 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5781 TRACE("(%p, %p)\n", graphics
, region
);
5783 if(!graphics
|| !region
)
5784 return InvalidParameter
;
5789 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5792 /* free everything except root node and header */
5793 delete_element(®ion
->node
);
5794 memcpy(region
, clip
, sizeof(GpRegion
));
5800 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5801 GpCoordinateSpace src_space
, GpMatrix
**matrix
)
5803 GpStatus stat
= GdipCreateMatrix(matrix
);
5806 if (dst_space
!= src_space
&& stat
== Ok
)
5808 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
5810 if(graphics
->unit
!= UnitDisplay
)
5811 unitscale
*= graphics
->scale
;
5813 /* transform from src_space to CoordinateSpacePage */
5816 case CoordinateSpaceWorld
:
5817 GdipMultiplyMatrix(*matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
5819 case CoordinateSpacePage
:
5821 case CoordinateSpaceDevice
:
5822 GdipScaleMatrix(*matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
5826 /* transform from CoordinateSpacePage to dst_space */
5829 case CoordinateSpaceWorld
:
5831 GpMatrix
*inverted_transform
;
5832 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
5835 stat
= GdipInvertMatrix(inverted_transform
);
5837 GdipMultiplyMatrix(*matrix
, inverted_transform
, MatrixOrderAppend
);
5838 GdipDeleteMatrix(inverted_transform
);
5842 case CoordinateSpacePage
:
5844 case CoordinateSpaceDevice
:
5845 GdipScaleMatrix(*matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
5852 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5853 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5858 if(!graphics
|| !points
|| count
<= 0)
5859 return InvalidParameter
;
5864 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5866 if (src_space
== dst_space
) return Ok
;
5868 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5872 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
5874 GdipDeleteMatrix(matrix
);
5880 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5881 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5887 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5890 return InvalidParameter
;
5892 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5896 for(i
= 0; i
< count
; i
++){
5897 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5898 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5901 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5904 for(i
= 0; i
< count
; i
++){
5905 points
[i
].X
= roundr(pointsF
[i
].X
);
5906 points
[i
].Y
= roundr(pointsF
[i
].Y
);
5913 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5925 /*****************************************************************************
5926 * GdipTranslateClip [GDIPLUS.@]
5928 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5930 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5933 return InvalidParameter
;
5938 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5941 /*****************************************************************************
5942 * GdipTranslateClipI [GDIPLUS.@]
5944 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5946 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5949 return InvalidParameter
;
5954 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
5958 /*****************************************************************************
5959 * GdipMeasureDriverString [GDIPLUS.@]
5961 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5962 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
5963 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
5965 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
5968 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
5970 TEXTMETRICW textmetric
;
5971 const WORD
*glyph_indices
;
5972 WORD
*dynamic_glyph_indices
=NULL
;
5973 REAL rel_width
, rel_height
, ascent
, descent
;
5976 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
5978 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
5979 return InvalidParameter
;
5982 length
= strlenW(text
);
5986 boundingBox
->X
= 0.0;
5987 boundingBox
->Y
= 0.0;
5988 boundingBox
->Width
= 0.0;
5989 boundingBox
->Height
= 0.0;
5992 if (flags
& unsupported_flags
)
5993 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
5996 FIXME("Ignoring matrix\n");
5998 get_font_hfont(graphics
, font
, &hfont
);
6000 hdc
= CreateCompatibleDC(0);
6001 SelectObject(hdc
, hfont
);
6003 GetTextMetricsW(hdc
, &textmetric
);
6011 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6012 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6013 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6014 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6015 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6017 if (flags
& DriverStringOptionsCmapLookup
)
6019 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6023 DeleteObject(hfont
);
6027 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6030 glyph_indices
= text
;
6032 min_x
= max_x
= x
= positions
[0].X
;
6033 min_y
= max_y
= y
= positions
[0].Y
;
6035 ascent
= textmetric
.tmAscent
/ rel_height
;
6036 descent
= textmetric
.tmDescent
/ rel_height
;
6038 for (i
=0; i
<length
; i
++)
6043 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6049 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6050 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcB
;
6052 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6053 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6054 if (min_x
> x
) min_x
= x
;
6056 x
+= char_width
/ rel_width
;
6058 if (max_x
< x
) max_x
= x
;
6061 GdipFree(dynamic_glyph_indices
);
6063 DeleteObject(hfont
);
6065 boundingBox
->X
= min_x
;
6066 boundingBox
->Y
= min_y
;
6067 boundingBox
->Width
= max_x
- min_x
;
6068 boundingBox
->Height
= max_y
- min_y
;
6073 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6074 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6075 GDIPCONST PointF
*positions
, INT flags
,
6076 GDIPCONST GpMatrix
*matrix
)
6078 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6084 if (flags
& unsupported_flags
)
6085 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6088 FIXME("Ignoring matrix\n");
6090 if (!(flags
& DriverStringOptionsCmapLookup
))
6091 eto_flags
|= ETO_GLYPH_INDEX
;
6093 save_state
= SaveDC(graphics
->hdc
);
6094 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6095 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6098 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6100 get_font_hfont(graphics
, font
, &hfont
);
6101 SelectObject(graphics
->hdc
, hfont
);
6103 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6105 ExtTextOutW(graphics
->hdc
, roundr(pt
.X
), roundr(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6107 RestoreDC(graphics
->hdc
, save_state
);
6109 DeleteObject(hfont
);
6114 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6115 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6116 GDIPCONST PointF
*positions
, INT flags
,
6117 GDIPCONST GpMatrix
*matrix
)
6119 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6121 PointF
*real_positions
, real_position
;
6125 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6126 DWORD max_glyphsize
=0;
6127 GLYPHMETRICS glyphmetrics
;
6128 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6131 int text_mask_stride
;
6133 int pixel_data_stride
;
6135 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6140 if (!(flags
& DriverStringOptionsCmapLookup
))
6141 ggo_flags
|= GGO_GLYPH_INDEX
;
6143 if (flags
& unsupported_flags
)
6144 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6147 FIXME("Ignoring matrix\n");
6149 pti
= GdipAlloc(sizeof(POINT
) * length
);
6153 if (flags
& DriverStringOptionsRealizedAdvance
)
6155 real_position
= positions
[0];
6157 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6161 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6162 if (!real_positions
)
6168 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6170 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6172 GdipFree(real_positions
);
6175 get_font_hfont(graphics
, font
, &hfont
);
6177 hdc
= CreateCompatibleDC(0);
6178 SelectObject(hdc
, hfont
);
6180 /* Get the boundaries of the text to be drawn */
6181 for (i
=0; i
<length
; i
++)
6184 int left
, top
, right
, bottom
;
6186 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6187 &glyphmetrics
, 0, NULL
, &identity
);
6189 if (glyphsize
== GDI_ERROR
)
6191 ERR("GetGlyphOutlineW failed\n");
6194 DeleteObject(hfont
);
6195 return GenericError
;
6198 if (glyphsize
> max_glyphsize
)
6199 max_glyphsize
= glyphsize
;
6201 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6202 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6203 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6204 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6206 if (left
< min_x
) min_x
= left
;
6207 if (top
< min_y
) min_y
= top
;
6208 if (right
> max_x
) max_x
= right
;
6209 if (bottom
> max_y
) max_y
= bottom
;
6211 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6213 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6214 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6218 glyph_mask
= GdipAlloc(max_glyphsize
);
6219 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6220 text_mask_stride
= max_x
- min_x
;
6222 if (!(glyph_mask
&& text_mask
))
6224 GdipFree(glyph_mask
);
6225 GdipFree(text_mask
);
6228 DeleteObject(hfont
);
6232 /* Generate a mask for the text */
6233 for (i
=0; i
<length
; i
++)
6235 int left
, top
, stride
;
6237 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6238 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6240 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6241 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6242 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6244 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6246 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6247 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6248 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6250 *text_val
= min(64, *text_val
+ *glyph_val
);
6259 DeleteObject(hfont
);
6260 GdipFree(glyph_mask
);
6262 /* get the brush data */
6263 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6266 GdipFree(text_mask
);
6270 pixel_area
.X
= min_x
;
6271 pixel_area
.Y
= min_y
;
6272 pixel_area
.Width
= max_x
- min_x
;
6273 pixel_area
.Height
= max_y
- min_y
;
6274 pixel_data_stride
= pixel_area
.Width
* 4;
6276 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6279 GdipFree(text_mask
);
6280 GdipFree(pixel_data
);
6284 /* multiply the brush data by the mask */
6285 for (y
=0; y
<pixel_area
.Height
; y
++)
6287 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6288 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6289 for (x
=0; x
<pixel_area
.Width
; x
++)
6291 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6297 GdipFree(text_mask
);
6299 /* draw the result */
6300 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6301 pixel_area
.Height
, pixel_data_stride
);
6303 GdipFree(pixel_data
);
6308 /*****************************************************************************
6309 * GdipDrawDriverString [GDIPLUS.@]
6311 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6312 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6313 GDIPCONST PointF
*positions
, INT flags
,
6314 GDIPCONST GpMatrix
*matrix
)
6316 GpStatus stat
=NotImplemented
;
6318 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6320 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6321 return InvalidParameter
;
6324 length
= strlenW(text
);
6326 if (graphics
->hdc
&&
6327 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6328 brush
->bt
== BrushTypeSolidColor
&&
6329 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6330 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
6331 positions
, flags
, matrix
);
6333 if (stat
== NotImplemented
)
6334 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
6335 positions
, flags
, matrix
);
6340 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6341 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6343 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6344 return NotImplemented
;
6347 /*****************************************************************************
6348 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6350 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6355 TRACE("(%p, %p)\n", graphics
, res
);
6357 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6360 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6363 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6366 GdipDeleteRegion(rgn
);