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 INT
brush_can_fill_path(GpBrush
*brush
)
882 case BrushTypeSolidColor
:
884 case BrushTypeHatchFill
:
886 GpHatch
*hatch
= (GpHatch
*)brush
;
887 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
888 ((hatch
->backcol
& 0xff000000) == 0xff000000);
890 case BrushTypeLinearGradient
:
891 case BrushTypeTextureFill
:
892 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
898 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
902 case BrushTypeSolidColor
:
904 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
905 HBITMAP bmp
= ARGB2BMP(fill
->color
);
910 /* partially transparent fill */
912 SelectClipPath(graphics
->hdc
, RGN_AND
);
913 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
915 HDC hdc
= CreateCompatibleDC(NULL
);
920 SelectObject(hdc
, bmp
);
922 bf
.BlendOp
= AC_SRC_OVER
;
924 bf
.SourceConstantAlpha
= 255;
925 bf
.AlphaFormat
= AC_SRC_ALPHA
;
927 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
935 /* else fall through */
939 HBRUSH gdibrush
, old_brush
;
941 gdibrush
= create_gdi_brush(brush
);
942 if (!gdibrush
) return;
944 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
945 FillPath(graphics
->hdc
);
946 SelectObject(graphics
->hdc
, old_brush
);
947 DeleteObject(gdibrush
);
953 static INT
brush_can_fill_pixels(GpBrush
*brush
)
957 case BrushTypeSolidColor
:
958 case BrushTypeHatchFill
:
959 case BrushTypeLinearGradient
:
960 case BrushTypeTextureFill
:
967 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
968 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
972 case BrushTypeSolidColor
:
975 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
976 for (x
=0; x
<fill_area
->Width
; x
++)
977 for (y
=0; y
<fill_area
->Height
; y
++)
978 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
981 case BrushTypeHatchFill
:
984 GpHatch
*fill
= (GpHatch
*)brush
;
985 const char *hatch_data
;
987 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
988 return NotImplemented
;
990 for (x
=0; x
<fill_area
->Width
; x
++)
991 for (y
=0; y
<fill_area
->Height
; y
++)
995 /* FIXME: Account for the rendering origin */
996 hx
= (x
+ fill_area
->X
) % 8;
997 hy
= (y
+ fill_area
->Y
) % 8;
999 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1000 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1002 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1007 case BrushTypeLinearGradient
:
1009 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1010 GpPointF draw_points
[3], line_points
[3];
1012 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1013 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1016 draw_points
[0].X
= fill_area
->X
;
1017 draw_points
[0].Y
= fill_area
->Y
;
1018 draw_points
[1].X
= fill_area
->X
+1;
1019 draw_points
[1].Y
= fill_area
->Y
;
1020 draw_points
[2].X
= fill_area
->X
;
1021 draw_points
[2].Y
= fill_area
->Y
+1;
1023 /* Transform the points to a co-ordinate space where X is the point's
1024 * position in the gradient, 0.0 being the start point and 1.0 the
1026 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1027 CoordinateSpaceDevice
, draw_points
, 3);
1031 line_points
[0] = fill
->startpoint
;
1032 line_points
[1] = fill
->endpoint
;
1033 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1034 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1036 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1041 stat
= GdipInvertMatrix(world_to_gradient
);
1044 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1046 GdipDeleteMatrix(world_to_gradient
);
1051 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1052 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1054 for (y
=0; y
<fill_area
->Height
; y
++)
1056 for (x
=0; x
<fill_area
->Width
; x
++)
1058 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1060 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1067 case BrushTypeTextureFill
:
1069 GpTexture
*fill
= (GpTexture
*)brush
;
1070 GpPointF draw_points
[3];
1072 GpMatrix
*world_to_texture
;
1078 if (fill
->image
->type
!= ImageTypeBitmap
)
1080 FIXME("metafile texture brushes not implemented\n");
1081 return NotImplemented
;
1084 bitmap
= (GpBitmap
*)fill
->image
;
1085 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1087 src_area
.X
= src_area
.Y
= 0;
1088 src_area
.Width
= bitmap
->width
;
1089 src_area
.Height
= bitmap
->height
;
1091 draw_points
[0].X
= fill_area
->X
;
1092 draw_points
[0].Y
= fill_area
->Y
;
1093 draw_points
[1].X
= fill_area
->X
+1;
1094 draw_points
[1].Y
= fill_area
->Y
;
1095 draw_points
[2].X
= fill_area
->X
;
1096 draw_points
[2].Y
= fill_area
->Y
+1;
1098 /* Transform the points to the co-ordinate space of the bitmap. */
1099 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1100 CoordinateSpaceDevice
, draw_points
, 3);
1104 stat
= GdipCloneMatrix(fill
->transform
, &world_to_texture
);
1109 stat
= GdipInvertMatrix(world_to_texture
);
1112 stat
= GdipTransformMatrixPoints(world_to_texture
, draw_points
, 3);
1114 GdipDeleteMatrix(world_to_texture
);
1117 if (stat
== Ok
&& !fill
->bitmap_bits
)
1119 BitmapData lockeddata
;
1121 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1122 if (!fill
->bitmap_bits
)
1127 lockeddata
.Width
= bitmap
->width
;
1128 lockeddata
.Height
= bitmap
->height
;
1129 lockeddata
.Stride
= src_stride
;
1130 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1131 lockeddata
.Scan0
= fill
->bitmap_bits
;
1133 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1134 PixelFormat32bppARGB
, &lockeddata
);
1138 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1141 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1142 bitmap
->width
, bitmap
->height
,
1143 src_stride
, ColorAdjustTypeBitmap
);
1147 GdipFree(fill
->bitmap_bits
);
1148 fill
->bitmap_bits
= NULL
;
1154 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1155 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1156 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1157 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1159 for (y
=0; y
<fill_area
->Height
; y
++)
1161 for (x
=0; x
<fill_area
->Width
; x
++)
1164 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1165 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1167 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1168 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1169 &point
, fill
->imageattributes
, graphics
->interpolation
);
1177 return NotImplemented
;
1181 /* GdipDrawPie/GdipFillPie helper function */
1182 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
1183 REAL height
, REAL startAngle
, REAL sweepAngle
)
1190 ptf
[1].X
= x
+ width
;
1191 ptf
[1].Y
= y
+ height
;
1193 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
1194 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
1196 transform_and_round_points(graphics
, pti
, ptf
, 4);
1198 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
1199 pti
[2].y
, pti
[3].x
, pti
[3].y
);
1202 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1203 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1204 * should not be called on an hdc that has a path you care about. */
1205 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1206 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1208 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1209 GpMatrix
*matrix
= NULL
;
1210 HBRUSH brush
= NULL
;
1212 PointF ptf
[4], *custptf
= NULL
;
1213 POINT pt
[4], *custpt
= NULL
;
1215 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1220 if((x1
== x2
) && (y1
== y2
))
1223 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1225 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1227 brush
= CreateSolidBrush(color
);
1228 lb
.lbStyle
= BS_SOLID
;
1231 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1232 PS_JOIN_MITER
, 1, &lb
, 0,
1234 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1235 oldpen
= SelectObject(graphics
->hdc
, pen
);
1242 case LineCapSquareAnchor
:
1243 case LineCapDiamondAnchor
:
1244 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1245 if(cap
== LineCapDiamondAnchor
){
1246 dsmall
= cos(theta
+ M_PI_2
) * size
;
1247 dbig
= sin(theta
+ M_PI_2
) * size
;
1250 dsmall
= cos(theta
+ M_PI_4
) * size
;
1251 dbig
= sin(theta
+ M_PI_4
) * size
;
1254 ptf
[0].X
= x2
- dsmall
;
1255 ptf
[1].X
= x2
+ dbig
;
1257 ptf
[0].Y
= y2
- dbig
;
1258 ptf
[3].Y
= y2
+ dsmall
;
1260 ptf
[1].Y
= y2
- dsmall
;
1261 ptf
[2].Y
= y2
+ dbig
;
1263 ptf
[3].X
= x2
- dbig
;
1264 ptf
[2].X
= x2
+ dsmall
;
1266 transform_and_round_points(graphics
, pt
, ptf
, 4);
1267 Polygon(graphics
->hdc
, pt
, 4);
1270 case LineCapArrowAnchor
:
1271 size
= size
* 4.0 / sqrt(3.0);
1273 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1274 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1279 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1280 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1288 transform_and_round_points(graphics
, pt
, ptf
, 3);
1289 Polygon(graphics
->hdc
, pt
, 3);
1292 case LineCapRoundAnchor
:
1293 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1300 transform_and_round_points(graphics
, pt
, ptf
, 2);
1301 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1304 case LineCapTriangle
:
1306 dx
= cos(M_PI_2
+ theta
) * size
;
1307 dy
= sin(M_PI_2
+ theta
) * size
;
1314 dx
= cos(theta
) * size
;
1315 dy
= sin(theta
) * size
;
1320 transform_and_round_points(graphics
, pt
, ptf
, 3);
1321 Polygon(graphics
->hdc
, pt
, 3);
1325 dx
= dy
= size
/ 2.0;
1332 dx
= -cos(M_PI_2
+ theta
) * size
;
1333 dy
= -sin(M_PI_2
+ theta
) * size
;
1340 transform_and_round_points(graphics
, pt
, ptf
, 4);
1341 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1342 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1349 count
= custom
->pathdata
.Count
;
1350 custptf
= GdipAlloc(count
* sizeof(PointF
));
1351 custpt
= GdipAlloc(count
* sizeof(POINT
));
1352 tp
= GdipAlloc(count
);
1354 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
1357 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1359 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
1360 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1362 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
1363 GdipTransformMatrixPoints(matrix
, custptf
, count
);
1365 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1367 for(i
= 0; i
< count
; i
++)
1368 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1371 BeginPath(graphics
->hdc
);
1372 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1373 EndPath(graphics
->hdc
);
1374 StrokeAndFillPath(graphics
->hdc
);
1377 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1383 GdipDeleteMatrix(matrix
);
1390 SelectObject(graphics
->hdc
, oldbrush
);
1391 SelectObject(graphics
->hdc
, oldpen
);
1392 DeleteObject(brush
);
1397 /* Shortens the line by the given percent by changing x2, y2.
1398 * If percent is > 1.0 then the line will change direction.
1399 * If percent is negative it can lengthen the line. */
1400 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1402 REAL dist
, theta
, dx
, dy
;
1404 if((y1
== *y2
) && (x1
== *x2
))
1407 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1408 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1409 dx
= cos(theta
) * dist
;
1410 dy
= sin(theta
) * dist
;
1416 /* Shortens the line by the given amount by changing x2, y2.
1417 * If the amount is greater than the distance, the line will become length 0.
1418 * If the amount is negative, it can lengthen the line. */
1419 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1421 REAL dx
, dy
, percent
;
1425 if(dx
== 0 && dy
== 0)
1428 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1435 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1438 /* Draws lines between the given points, and if caps is true then draws an endcap
1439 * at the end of the last line. */
1440 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
1441 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1444 GpPointF
*ptcopy
= NULL
;
1445 GpStatus status
= GenericError
;
1450 pti
= GdipAlloc(count
* sizeof(POINT
));
1451 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1453 if(!pti
|| !ptcopy
){
1454 status
= OutOfMemory
;
1458 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1461 if(pen
->endcap
== LineCapArrowAnchor
)
1462 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1463 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
1464 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1465 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1466 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
1467 pen
->customend
->inset
* pen
->width
);
1469 if(pen
->startcap
== LineCapArrowAnchor
)
1470 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1471 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
1472 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1473 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1474 &ptcopy
[0].X
, &ptcopy
[0].Y
,
1475 pen
->customstart
->inset
* pen
->width
);
1477 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1478 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
1479 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1480 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
1483 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1485 if(Polyline(graphics
->hdc
, pti
, count
))
1495 /* Conducts a linear search to find the bezier points that will back off
1496 * the endpoint of the curve by a distance of amt. Linear search works
1497 * better than binary in this case because there are multiple solutions,
1498 * and binary searches often find a bad one. I don't think this is what
1499 * Windows does but short of rendering the bezier without GDI's help it's
1500 * the best we can do. If rev then work from the start of the passed points
1501 * instead of the end. */
1502 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1505 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1506 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1515 origx
= pt
[fourth
].X
;
1516 origy
= pt
[fourth
].Y
;
1517 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1519 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1520 /* reset bezier points to original values */
1521 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1522 /* Perform magic on bezier points. Order is important here.*/
1523 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1524 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1525 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1526 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1527 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1528 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1530 dx
= pt
[fourth
].X
- origx
;
1531 dy
= pt
[fourth
].Y
- origy
;
1533 diff
= sqrt(dx
* dx
+ dy
* dy
);
1534 percent
+= 0.0005 * amt
;
1538 /* Draws bezier curves between given points, and if caps is true then draws an
1539 * endcap at the end of the last line. */
1540 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
1541 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1545 GpStatus status
= GenericError
;
1550 pti
= GdipAlloc(count
* sizeof(POINT
));
1551 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1553 if(!pti
|| !ptcopy
){
1554 status
= OutOfMemory
;
1558 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1561 if(pen
->endcap
== LineCapArrowAnchor
)
1562 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
1563 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1564 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
1567 if(pen
->startcap
== LineCapArrowAnchor
)
1568 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
1569 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1570 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
1572 /* the direction of the line cap is parallel to the direction at the
1573 * end of the bezier (which, if it has been shortened, is not the same
1574 * as the direction from pt[count-2] to pt[count-1]) */
1575 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1576 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1577 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1578 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1580 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1581 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
1582 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
1585 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1587 PolyBezier(graphics
->hdc
, pti
, count
);
1598 /* Draws a combination of bezier curves and lines between points. */
1599 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1600 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1602 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1603 BYTE
*tp
= GdipAlloc(count
);
1604 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1606 GpStatus status
= GenericError
;
1612 if(!pti
|| !tp
|| !ptcopy
){
1613 status
= OutOfMemory
;
1617 for(i
= 1; i
< count
; i
++){
1618 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1619 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1620 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1621 ERR("Bad bezier points\n");
1628 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1630 /* If we are drawing caps, go through the points and adjust them accordingly,
1631 * and draw the caps. */
1633 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1634 case PathPointTypeBezier
:
1635 if(pen
->endcap
== LineCapArrowAnchor
)
1636 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1637 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1638 shorten_bezier_amt(&ptcopy
[count
- 4],
1639 pen
->width
* pen
->customend
->inset
, FALSE
);
1641 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1642 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1643 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1644 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1647 case PathPointTypeLine
:
1648 if(pen
->endcap
== LineCapArrowAnchor
)
1649 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1650 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1652 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1653 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1654 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1655 pen
->customend
->inset
* pen
->width
);
1657 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1658 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1663 ERR("Bad path last point\n");
1667 /* Find start of points */
1668 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1669 == PathPointTypeStart
); j
++);
1671 switch(types
[j
] & PathPointTypePathTypeMask
){
1672 case PathPointTypeBezier
:
1673 if(pen
->startcap
== LineCapArrowAnchor
)
1674 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1675 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1676 shorten_bezier_amt(&ptcopy
[j
- 1],
1677 pen
->width
* pen
->customstart
->inset
, TRUE
);
1679 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1680 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1681 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1682 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1685 case PathPointTypeLine
:
1686 if(pen
->startcap
== LineCapArrowAnchor
)
1687 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1688 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1690 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1691 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1692 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1693 pen
->customstart
->inset
* pen
->width
);
1695 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1696 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1701 ERR("Bad path points\n");
1706 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1708 for(i
= 0; i
< count
; i
++){
1709 tp
[i
] = convert_path_point_type(types
[i
]);
1712 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1724 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1728 BeginPath(graphics
->hdc
);
1729 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1730 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1731 EndPath(graphics
->hdc
);
1735 typedef struct _GraphicsContainerItem
{
1737 GraphicsContainer contid
;
1739 SmoothingMode smoothing
;
1740 CompositingQuality compqual
;
1741 InterpolationMode interpolation
;
1742 CompositingMode compmode
;
1743 TextRenderingHint texthint
;
1746 PixelOffsetMode pixeloffset
;
1748 GpMatrix
* worldtrans
;
1750 } GraphicsContainerItem
;
1752 static GpStatus
init_container(GraphicsContainerItem
** container
,
1753 GDIPCONST GpGraphics
* graphics
){
1756 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1760 (*container
)->contid
= graphics
->contid
+ 1;
1762 (*container
)->smoothing
= graphics
->smoothing
;
1763 (*container
)->compqual
= graphics
->compqual
;
1764 (*container
)->interpolation
= graphics
->interpolation
;
1765 (*container
)->compmode
= graphics
->compmode
;
1766 (*container
)->texthint
= graphics
->texthint
;
1767 (*container
)->scale
= graphics
->scale
;
1768 (*container
)->unit
= graphics
->unit
;
1769 (*container
)->textcontrast
= graphics
->textcontrast
;
1770 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1772 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1774 GdipFree(*container
);
1779 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1781 GdipDeleteMatrix((*container
)->worldtrans
);
1782 GdipFree(*container
);
1790 static void delete_container(GraphicsContainerItem
* container
){
1791 GdipDeleteMatrix(container
->worldtrans
);
1792 GdipDeleteRegion(container
->clip
);
1793 GdipFree(container
);
1796 static GpStatus
restore_container(GpGraphics
* graphics
,
1797 GDIPCONST GraphicsContainerItem
* container
){
1802 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1806 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1808 GdipDeleteMatrix(newTrans
);
1812 GdipDeleteMatrix(graphics
->worldtrans
);
1813 graphics
->worldtrans
= newTrans
;
1815 GdipDeleteRegion(graphics
->clip
);
1816 graphics
->clip
= newClip
;
1818 graphics
->contid
= container
->contid
- 1;
1820 graphics
->smoothing
= container
->smoothing
;
1821 graphics
->compqual
= container
->compqual
;
1822 graphics
->interpolation
= container
->interpolation
;
1823 graphics
->compmode
= container
->compmode
;
1824 graphics
->texthint
= container
->texthint
;
1825 graphics
->scale
= container
->scale
;
1826 graphics
->unit
= container
->unit
;
1827 graphics
->textcontrast
= container
->textcontrast
;
1828 graphics
->pixeloffset
= container
->pixeloffset
;
1833 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1839 if(graphics
->hwnd
) {
1840 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1841 return GenericError
;
1843 rect
->X
= wnd_rect
.left
;
1844 rect
->Y
= wnd_rect
.top
;
1845 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1846 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1847 }else if (graphics
->image
){
1848 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1849 if (stat
== Ok
&& unit
!= UnitPixel
)
1850 FIXME("need to convert from unit %i\n", unit
);
1854 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1855 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
1861 /* on success, rgn will contain the region of the graphics object which
1862 * is visible after clipping has been applied */
1863 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
1869 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
1872 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
1875 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
1878 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
1881 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
1884 GdipDeleteRegion(tmp
);
1888 void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
, HFONT
*hfont
)
1890 HDC hdc
= CreateCompatibleDC(0);
1892 REAL angle
, rel_width
, rel_height
;
1894 HFONT unscaled_font
;
1895 TEXTMETRICW textmet
;
1904 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
1905 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
1906 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
1907 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
1908 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
1909 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
1912 lfw
.lfHeight
= roundr(-font
->pixel_size
* rel_height
);
1913 unscaled_font
= CreateFontIndirectW(&lfw
);
1915 SelectObject(hdc
, unscaled_font
);
1916 GetTextMetricsW(hdc
, &textmet
);
1919 lfw
.lfHeight
= roundr(-font
->pixel_size
* rel_height
);
1920 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
1921 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
1923 *hfont
= CreateFontIndirectW(&lfw
);
1926 DeleteObject(unscaled_font
);
1929 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1931 TRACE("(%p, %p)\n", hdc
, graphics
);
1933 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1936 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1940 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1942 if(hDevice
!= NULL
) {
1943 FIXME("Don't know how to handle parameter hDevice\n");
1944 return NotImplemented
;
1950 if(graphics
== NULL
)
1951 return InvalidParameter
;
1953 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1954 if(!*graphics
) return OutOfMemory
;
1956 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1957 GdipFree(*graphics
);
1961 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1962 GdipFree((*graphics
)->worldtrans
);
1963 GdipFree(*graphics
);
1967 (*graphics
)->hdc
= hdc
;
1968 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1969 (*graphics
)->owndc
= FALSE
;
1970 (*graphics
)->smoothing
= SmoothingModeDefault
;
1971 (*graphics
)->compqual
= CompositingQualityDefault
;
1972 (*graphics
)->interpolation
= InterpolationModeBilinear
;
1973 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1974 (*graphics
)->compmode
= CompositingModeSourceOver
;
1975 (*graphics
)->unit
= UnitDisplay
;
1976 (*graphics
)->scale
= 1.0;
1977 (*graphics
)->busy
= FALSE
;
1978 (*graphics
)->textcontrast
= 4;
1979 list_init(&(*graphics
)->containers
);
1980 (*graphics
)->contid
= 0;
1982 TRACE("<-- %p\n", *graphics
);
1987 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
1991 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1992 if(!*graphics
) return OutOfMemory
;
1994 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1995 GdipFree(*graphics
);
1999 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2000 GdipFree((*graphics
)->worldtrans
);
2001 GdipFree(*graphics
);
2005 (*graphics
)->hdc
= NULL
;
2006 (*graphics
)->hwnd
= NULL
;
2007 (*graphics
)->owndc
= FALSE
;
2008 (*graphics
)->image
= image
;
2009 (*graphics
)->smoothing
= SmoothingModeDefault
;
2010 (*graphics
)->compqual
= CompositingQualityDefault
;
2011 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2012 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2013 (*graphics
)->compmode
= CompositingModeSourceOver
;
2014 (*graphics
)->unit
= UnitDisplay
;
2015 (*graphics
)->scale
= 1.0;
2016 (*graphics
)->busy
= FALSE
;
2017 (*graphics
)->textcontrast
= 4;
2018 list_init(&(*graphics
)->containers
);
2019 (*graphics
)->contid
= 0;
2021 TRACE("<-- %p\n", *graphics
);
2026 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2031 TRACE("(%p, %p)\n", hwnd
, graphics
);
2035 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2037 ReleaseDC(hwnd
, hdc
);
2041 (*graphics
)->hwnd
= hwnd
;
2042 (*graphics
)->owndc
= TRUE
;
2047 /* FIXME: no icm handling */
2048 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2050 TRACE("(%p, %p)\n", hwnd
, graphics
);
2052 return GdipCreateFromHWND(hwnd
, graphics
);
2055 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2056 GpMetafile
**metafile
)
2058 IStream
*stream
= NULL
;
2060 ENHMETAHEADER
*copy
;
2061 GpStatus retval
= Ok
;
2063 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2065 if(!hemf
|| !metafile
)
2066 return InvalidParameter
;
2068 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
2069 copy
= GdipAlloc(read
);
2070 GetEnhMetaFileBits(hemf
, read
, (BYTE
*)copy
);
2072 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
2073 ERR("could not make stream\n");
2075 retval
= GenericError
;
2079 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2081 retval
= OutOfMemory
;
2085 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
2086 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
2088 retval
= GenericError
;
2093 (*metafile
)->image
.type
= ImageTypeMetafile
;
2094 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
2095 (*metafile
)->image
.palette_flags
= 0;
2096 (*metafile
)->image
.palette_count
= 0;
2097 (*metafile
)->image
.palette_size
= 0;
2098 (*metafile
)->image
.palette_entries
= NULL
;
2099 (*metafile
)->image
.xres
= (REAL
)copy
->szlDevice
.cx
;
2100 (*metafile
)->image
.yres
= (REAL
)copy
->szlDevice
.cy
;
2101 (*metafile
)->bounds
.X
= (REAL
)copy
->rclBounds
.left
;
2102 (*metafile
)->bounds
.Y
= (REAL
)copy
->rclBounds
.top
;
2103 (*metafile
)->bounds
.Width
= (REAL
)(copy
->rclBounds
.right
- copy
->rclBounds
.left
);
2104 (*metafile
)->bounds
.Height
= (REAL
)(copy
->rclBounds
.bottom
- copy
->rclBounds
.top
);
2105 (*metafile
)->unit
= UnitPixel
;
2108 DeleteEnhMetaFile(hemf
);
2110 TRACE("<-- %p\n", *metafile
);
2114 GdipFree(*metafile
);
2115 IStream_Release(stream
);
2119 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2120 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2125 GpStatus retval
= Ok
;
2127 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2129 if(!hwmf
|| !metafile
|| !placeable
)
2130 return InvalidParameter
;
2133 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2135 return GenericError
;
2136 copy
= GdipAlloc(read
);
2137 GetMetaFileBitsEx(hwmf
, read
, copy
);
2139 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2142 retval
= GdipCreateMetafileFromEmf(hemf
, FALSE
, metafile
);
2146 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2147 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2148 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2149 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2150 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2151 placeable
->BoundingBox
.Left
);
2152 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2153 placeable
->BoundingBox
.Top
);
2155 if (delete) DeleteMetaFile(hwmf
);
2160 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2161 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2163 HMETAFILE hmf
= GetMetaFileW(file
);
2165 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2167 if(!hmf
) return InvalidParameter
;
2169 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2172 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2173 GpMetafile
**metafile
)
2175 FIXME("(%p, %p): stub\n", file
, metafile
);
2176 return NotImplemented
;
2179 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2180 GpMetafile
**metafile
)
2182 FIXME("(%p, %p): stub\n", stream
, metafile
);
2183 return NotImplemented
;
2186 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2187 UINT access
, IStream
**stream
)
2192 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2194 if(!stream
|| !filename
)
2195 return InvalidParameter
;
2197 if(access
& GENERIC_WRITE
)
2198 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2199 else if(access
& GENERIC_READ
)
2200 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2202 return InvalidParameter
;
2204 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2206 return hresult_to_status(ret
);
2209 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2211 GraphicsContainerItem
*cont
, *next
;
2213 TRACE("(%p)\n", graphics
);
2215 if(!graphics
) return InvalidParameter
;
2216 if(graphics
->busy
) return ObjectBusy
;
2218 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2220 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2226 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2228 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2229 list_remove(&cont
->entry
);
2230 delete_container(cont
);
2233 GdipDeleteRegion(graphics
->clip
);
2234 GdipDeleteMatrix(graphics
->worldtrans
);
2240 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2241 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2243 INT save_state
, num_pts
;
2244 GpPointF points
[MAX_ARC_PTS
];
2247 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2248 width
, height
, startAngle
, sweepAngle
);
2250 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2251 return InvalidParameter
;
2258 FIXME("graphics object has no HDC\n");
2262 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2264 save_state
= prepare_dc(graphics
, pen
);
2266 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
2268 restore_dc(graphics
, save_state
);
2273 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2274 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2276 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2277 width
, height
, startAngle
, sweepAngle
);
2279 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2282 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2283 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2289 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2290 x2
, y2
, x3
, y3
, x4
, y4
);
2292 if(!graphics
|| !pen
)
2293 return InvalidParameter
;
2300 FIXME("graphics object has no HDC\n");
2313 save_state
= prepare_dc(graphics
, pen
);
2315 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2317 restore_dc(graphics
, save_state
);
2322 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2323 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2329 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2330 x2
, y2
, x3
, y3
, x4
, y4
);
2332 if(!graphics
|| !pen
)
2333 return InvalidParameter
;
2340 FIXME("graphics object has no HDC\n");
2353 save_state
= prepare_dc(graphics
, pen
);
2355 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2357 restore_dc(graphics
, save_state
);
2362 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2363 GDIPCONST GpPointF
*points
, INT count
)
2368 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2370 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2371 return InvalidParameter
;
2376 for(i
= 0; i
< floor(count
/ 4); i
++){
2377 ret
= GdipDrawBezier(graphics
, pen
,
2378 points
[4*i
].X
, points
[4*i
].Y
,
2379 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
2380 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
2381 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
2389 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2390 GDIPCONST GpPoint
*points
, INT count
)
2396 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2398 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2399 return InvalidParameter
;
2404 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2408 for(i
= 0; i
< count
; i
++){
2409 pts
[i
].X
= (REAL
)points
[i
].X
;
2410 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2413 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2420 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2421 GDIPCONST GpPointF
*points
, INT count
)
2423 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2425 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2428 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2429 GDIPCONST GpPoint
*points
, INT count
)
2431 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2433 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2436 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2437 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2442 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2444 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2445 return InvalidParameter
;
2450 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
2453 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2455 GdipDeletePath(path
);
2459 stat
= GdipDrawPath(graphics
, pen
, path
);
2461 GdipDeletePath(path
);
2466 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2467 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2473 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2475 if(!points
|| count
<= 0)
2476 return InvalidParameter
;
2478 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2482 for(i
= 0; i
< count
; i
++){
2483 ptf
[i
].X
= (REAL
)points
[i
].X
;
2484 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2487 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2494 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2495 GDIPCONST GpPointF
*points
, INT count
)
2497 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2499 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2502 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2503 GDIPCONST GpPoint
*points
, INT count
)
2509 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2512 return InvalidParameter
;
2514 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2518 for(i
= 0; i
< count
; i
++){
2519 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2520 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2523 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2529 /* Approximates cardinal spline with Bezier curves. */
2530 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2531 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2533 /* PolyBezier expects count*3-2 points. */
2534 INT i
, len_pt
= count
*3-2, save_state
;
2536 REAL x1
, x2
, y1
, y2
;
2539 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2541 if(!graphics
|| !pen
)
2542 return InvalidParameter
;
2548 return InvalidParameter
;
2552 FIXME("graphics object has no HDC\n");
2556 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
2560 tension
= tension
* TENSION_CONST
;
2562 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
2565 pt
[0].X
= points
[0].X
;
2566 pt
[0].Y
= points
[0].Y
;
2570 for(i
= 0; i
< count
-2; i
++){
2571 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
2575 pt
[3*i
+3].X
= points
[i
+1].X
;
2576 pt
[3*i
+3].Y
= points
[i
+1].Y
;
2581 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
2582 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
2584 pt
[len_pt
-2].X
= x1
;
2585 pt
[len_pt
-2].Y
= y1
;
2586 pt
[len_pt
-1].X
= points
[count
-1].X
;
2587 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
2589 save_state
= prepare_dc(graphics
, pen
);
2591 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
2594 restore_dc(graphics
, save_state
);
2599 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2600 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2606 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2609 return InvalidParameter
;
2611 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2615 for(i
= 0; i
< count
; i
++){
2616 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2617 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2620 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2626 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2627 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2630 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2632 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2633 return InvalidParameter
;
2636 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2639 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2640 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2643 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2649 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2650 return InvalidParameter
;
2653 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2656 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2657 REAL y
, REAL width
, REAL height
)
2663 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2665 if(!graphics
|| !pen
)
2666 return InvalidParameter
;
2673 FIXME("graphics object has no HDC\n");
2679 ptf
[1].X
= x
+ width
;
2680 ptf
[1].Y
= y
+ height
;
2682 save_state
= prepare_dc(graphics
, pen
);
2683 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2685 transform_and_round_points(graphics
, pti
, ptf
, 2);
2687 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2689 restore_dc(graphics
, save_state
);
2694 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2695 INT y
, INT width
, INT height
)
2697 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2699 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2703 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2708 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2710 if(!graphics
|| !image
)
2711 return InvalidParameter
;
2713 GdipGetImageWidth(image
, &width
);
2714 GdipGetImageHeight(image
, &height
);
2716 /* FIXME: we should use the graphics and image dpi, somehow */
2718 points
[0].X
= points
[2].X
= x
;
2719 points
[0].Y
= points
[1].Y
= y
;
2720 points
[1].X
= x
+ width
;
2721 points
[2].Y
= y
+ height
;
2723 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
2724 UnitPixel
, NULL
, NULL
, NULL
);
2727 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2730 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2732 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2735 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2736 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2740 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2742 points
[0].X
= points
[2].X
= x
;
2743 points
[0].Y
= points
[1].Y
= y
;
2745 /* FIXME: convert image coordinates to Graphics coordinates? */
2746 points
[1].X
= x
+ srcwidth
;
2747 points
[2].Y
= y
+ srcheight
;
2749 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2750 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2753 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2754 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2757 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2760 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2761 GDIPCONST GpPointF
*dstpoints
, INT count
)
2765 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2768 return InvalidParameter
;
2770 GdipGetImageWidth(image
, &width
);
2771 GdipGetImageHeight(image
, &height
);
2773 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2774 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2777 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2778 GDIPCONST GpPoint
*dstpoints
, INT count
)
2782 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2784 if (count
!= 3 || !dstpoints
)
2785 return InvalidParameter
;
2787 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2788 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2789 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2790 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2791 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2792 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2794 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2797 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2798 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2799 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2800 DrawImageAbort callback
, VOID
* callbackData
)
2807 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2808 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2812 return NotImplemented
;
2814 if(!graphics
|| !image
|| !points
|| count
!= 3)
2815 return InvalidParameter
;
2817 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2818 debugstr_pointf(&points
[2]));
2820 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2821 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2822 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2823 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
2825 transform_and_round_points(graphics
, pti
, ptf
, 4);
2831 FIXME("graphics object has no HDC\n");
2834 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2835 if(srcUnit
== UnitInch
)
2836 dx
= dy
= (REAL
) INCH_HIMETRIC
;
2837 else if(srcUnit
== UnitPixel
){
2838 dx
= ((REAL
) INCH_HIMETRIC
) /
2839 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
2840 dy
= ((REAL
) INCH_HIMETRIC
) /
2841 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
2844 return NotImplemented
;
2846 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2847 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2848 srcx
* dx
, srcy
* dy
,
2849 srcwidth
* dx
, srcheight
* dy
,
2852 callback(callbackData
);
2853 return GenericError
;
2856 else if (image
->type
== ImageTypeBitmap
)
2858 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2861 if (srcUnit
== UnitInch
)
2862 dx
= dy
= 96.0; /* FIXME: use the image resolution */
2863 else if (srcUnit
== UnitPixel
)
2866 return NotImplemented
;
2870 srcwidth
= srcwidth
* dx
;
2871 srcheight
= srcheight
* dy
;
2873 if (imageAttributes
||
2874 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2875 !((GpBitmap
*)image
)->hbitmap
||
2876 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2877 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2878 srcx
< 0 || srcy
< 0 ||
2879 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2886 int i
, x
, y
, src_stride
, dst_stride
;
2887 GpMatrix
*dst_to_src
;
2888 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2889 LPBYTE src_data
, dst_data
;
2890 BitmapData lockeddata
;
2891 InterpolationMode interpolation
= graphics
->interpolation
;
2892 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2893 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2894 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2896 if (!imageAttributes
)
2897 imageAttributes
= &defaultImageAttributes
;
2899 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2900 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2903 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2904 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2905 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2906 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2909 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2910 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2911 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2912 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2913 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2914 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2916 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
2917 if (stat
!= Ok
) return stat
;
2919 stat
= GdipInvertMatrix(dst_to_src
);
2922 GdipDeleteMatrix(dst_to_src
);
2926 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2929 GdipDeleteMatrix(dst_to_src
);
2933 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2935 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2936 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2938 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
2942 GdipDeleteMatrix(dst_to_src
);
2945 src_stride
= sizeof(ARGB
) * src_area
.Width
;
2947 /* Read the bits we need from the source bitmap into an ARGB buffer. */
2948 lockeddata
.Width
= src_area
.Width
;
2949 lockeddata
.Height
= src_area
.Height
;
2950 lockeddata
.Stride
= src_stride
;
2951 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
2952 lockeddata
.Scan0
= src_data
;
2954 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
2955 PixelFormat32bppARGB
, &lockeddata
);
2958 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2962 if (src_data
!= dst_data
)
2965 GdipDeleteMatrix(dst_to_src
);
2969 apply_image_attributes(imageAttributes
, src_data
,
2970 src_area
.Width
, src_area
.Height
,
2971 src_stride
, ColorAdjustTypeBitmap
);
2973 /* Transform the bits as needed to the destination. */
2974 GdipTransformMatrixPoints(dst_to_src
, dst_to_src_points
, 3);
2976 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
2977 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
2978 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
2979 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
2981 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2983 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2985 GpPointF src_pointf
;
2988 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
2989 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
2991 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2993 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
2994 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
, imageAttributes
, interpolation
);
3000 GdipDeleteMatrix(dst_to_src
);
3004 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3005 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3014 int temp_hdc
=0, temp_bitmap
=0;
3015 HBITMAP hbitmap
, old_hbm
=NULL
;
3017 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3018 bitmap
->format
== PixelFormat24bppRGB
||
3019 bitmap
->format
== PixelFormat32bppRGB
||
3020 bitmap
->format
== PixelFormat32bppPARGB
))
3022 BITMAPINFOHEADER bih
;
3024 PixelFormat dst_format
;
3026 /* we can't draw a bitmap of this format directly */
3027 hdc
= CreateCompatibleDC(0);
3031 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3032 bih
.biWidth
= bitmap
->width
;
3033 bih
.biHeight
= -bitmap
->height
;
3035 bih
.biBitCount
= 32;
3036 bih
.biCompression
= BI_RGB
;
3037 bih
.biSizeImage
= 0;
3038 bih
.biXPelsPerMeter
= 0;
3039 bih
.biYPelsPerMeter
= 0;
3041 bih
.biClrImportant
= 0;
3043 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3044 (void**)&temp_bits
, NULL
, 0);
3046 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3047 dst_format
= PixelFormat32bppPARGB
;
3049 dst_format
= PixelFormat32bppRGB
;
3051 convert_pixels(bitmap
->width
, bitmap
->height
,
3052 bitmap
->width
*4, temp_bits
, dst_format
,
3053 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
3057 hbitmap
= bitmap
->hbitmap
;
3059 temp_hdc
= (hdc
== 0);
3064 if (!hdc
) hdc
= CreateCompatibleDC(0);
3065 old_hbm
= SelectObject(hdc
, hbitmap
);
3068 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3072 bf
.BlendOp
= AC_SRC_OVER
;
3074 bf
.SourceConstantAlpha
= 255;
3075 bf
.AlphaFormat
= AC_SRC_ALPHA
;
3077 GdiAlphaBlend(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3078 hdc
, srcx
, srcy
, srcwidth
, srcheight
, bf
);
3082 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3083 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3088 SelectObject(hdc
, old_hbm
);
3093 DeleteObject(hbitmap
);
3098 ERR("GpImage with no IPicture or HBITMAP?!\n");
3099 return NotImplemented
;
3105 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3106 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3107 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3108 DrawImageAbort callback
, VOID
* callbackData
)
3110 GpPointF pointsF
[3];
3113 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3114 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3117 if(!points
|| count
!=3)
3118 return InvalidParameter
;
3120 for(i
= 0; i
< count
; i
++){
3121 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3122 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3125 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3126 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3127 callback
, callbackData
);
3130 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3131 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3132 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3133 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3134 VOID
* callbackData
)
3138 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3139 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3140 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3144 points
[1].X
= dstx
+ dstwidth
;
3147 points
[2].Y
= dsty
+ dstheight
;
3149 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3150 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3153 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3154 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3155 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3156 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3157 VOID
* callbackData
)
3161 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3162 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3163 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3167 points
[1].X
= dstx
+ dstwidth
;
3170 points
[2].Y
= dsty
+ dstheight
;
3172 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3173 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3176 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3177 REAL x
, REAL y
, REAL width
, REAL height
)
3183 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3185 if(!graphics
|| !image
)
3186 return InvalidParameter
;
3188 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3192 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3193 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3194 unit
, NULL
, NULL
, NULL
);
3197 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3198 INT x
, INT y
, INT width
, INT height
)
3200 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3202 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3205 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3206 REAL y1
, REAL x2
, REAL y2
)
3212 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3214 if(!pen
|| !graphics
)
3215 return InvalidParameter
;
3222 FIXME("graphics object has no HDC\n");
3231 save_state
= prepare_dc(graphics
, pen
);
3233 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3235 restore_dc(graphics
, save_state
);
3240 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3241 INT y1
, INT x2
, INT y2
)
3247 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3249 if(!pen
|| !graphics
)
3250 return InvalidParameter
;
3257 FIXME("graphics object has no HDC\n");
3266 save_state
= prepare_dc(graphics
, pen
);
3268 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3270 restore_dc(graphics
, save_state
);
3275 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3276 GpPointF
*points
, INT count
)
3281 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3283 if(!pen
|| !graphics
|| (count
< 2))
3284 return InvalidParameter
;
3291 FIXME("graphics object has no HDC\n");
3295 save_state
= prepare_dc(graphics
, pen
);
3297 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
3299 restore_dc(graphics
, save_state
);
3304 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3305 GpPoint
*points
, INT count
)
3309 GpPointF
*ptf
= NULL
;
3312 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3314 if(!pen
|| !graphics
|| (count
< 2))
3315 return InvalidParameter
;
3322 FIXME("graphics object has no HDC\n");
3326 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3327 if(!ptf
) return OutOfMemory
;
3329 for(i
= 0; i
< count
; i
++){
3330 ptf
[i
].X
= (REAL
) points
[i
].X
;
3331 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3334 save_state
= prepare_dc(graphics
, pen
);
3336 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
3338 restore_dc(graphics
, save_state
);
3344 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3349 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3351 if(!pen
|| !graphics
)
3352 return InvalidParameter
;
3359 FIXME("graphics object has no HDC\n");
3363 save_state
= prepare_dc(graphics
, pen
);
3365 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3366 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3368 restore_dc(graphics
, save_state
);
3373 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3374 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3378 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3379 width
, height
, startAngle
, sweepAngle
);
3381 if(!graphics
|| !pen
)
3382 return InvalidParameter
;
3389 FIXME("graphics object has no HDC\n");
3393 save_state
= prepare_dc(graphics
, pen
);
3394 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3396 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3398 restore_dc(graphics
, save_state
);
3403 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3404 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3406 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3407 width
, height
, startAngle
, sweepAngle
);
3409 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3412 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3413 REAL y
, REAL width
, REAL height
)
3419 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3421 if(!pen
|| !graphics
)
3422 return InvalidParameter
;
3429 FIXME("graphics object has no HDC\n");
3435 ptf
[1].X
= x
+ width
;
3437 ptf
[2].X
= x
+ width
;
3438 ptf
[2].Y
= y
+ height
;
3440 ptf
[3].Y
= y
+ height
;
3442 save_state
= prepare_dc(graphics
, pen
);
3443 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3445 transform_and_round_points(graphics
, pti
, ptf
, 4);
3446 Polygon(graphics
->hdc
, pti
, 4);
3448 restore_dc(graphics
, save_state
);
3453 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3454 INT y
, INT width
, INT height
)
3456 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3458 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3461 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3462 GDIPCONST GpRectF
* rects
, INT count
)
3468 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3470 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3471 return InvalidParameter
;
3478 FIXME("graphics object has no HDC\n");
3482 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
3483 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
3491 for(i
= 0; i
< count
; i
++){
3492 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
3493 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
3494 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
3495 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
3498 save_state
= prepare_dc(graphics
, pen
);
3499 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3501 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
3503 for(i
= 0; i
< count
; i
++)
3504 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
3506 restore_dc(graphics
, save_state
);
3514 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3515 GDIPCONST GpRect
* rects
, INT count
)
3521 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3523 if(!rects
|| count
<=0)
3524 return InvalidParameter
;
3526 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3530 for(i
= 0;i
< count
;i
++){
3531 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3532 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3533 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3534 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3537 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3543 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3544 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3549 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3550 count
, tension
, fill
);
3552 if(!graphics
|| !brush
|| !points
)
3553 return InvalidParameter
;
3558 if(count
== 1) /* Do nothing */
3561 stat
= GdipCreatePath(fill
, &path
);
3565 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3567 GdipDeletePath(path
);
3571 stat
= GdipFillPath(graphics
, brush
, path
);
3573 GdipDeletePath(path
);
3577 GdipDeletePath(path
);
3582 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3583 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3589 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3590 count
, tension
, fill
);
3592 if(!points
|| count
== 0)
3593 return InvalidParameter
;
3595 if(count
== 1) /* Do nothing */
3598 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3602 for(i
= 0;i
< count
;i
++){
3603 ptf
[i
].X
= (REAL
)points
[i
].X
;
3604 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3607 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3614 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3615 GDIPCONST GpPointF
*points
, INT count
)
3617 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3618 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3619 0.5f
, FillModeAlternate
);
3622 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3623 GDIPCONST GpPoint
*points
, INT count
)
3625 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3626 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3627 0.5f
, FillModeAlternate
);
3630 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3631 REAL y
, REAL width
, REAL height
)
3636 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3638 if(!graphics
|| !brush
)
3639 return InvalidParameter
;
3644 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3648 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3651 stat
= GdipFillPath(graphics
, brush
, path
);
3653 GdipDeletePath(path
);
3659 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3660 INT y
, INT width
, INT height
)
3662 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3664 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3667 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3672 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3673 return NotImplemented
;
3675 save_state
= SaveDC(graphics
->hdc
);
3676 EndPath(graphics
->hdc
);
3677 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3680 BeginPath(graphics
->hdc
);
3681 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3682 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3687 EndPath(graphics
->hdc
);
3688 brush_fill_path(graphics
, brush
);
3693 RestoreDC(graphics
->hdc
, save_state
);
3698 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3703 if (!brush_can_fill_pixels(brush
))
3704 return NotImplemented
;
3706 /* FIXME: This could probably be done more efficiently without regions. */
3708 stat
= GdipCreateRegionPath(path
, &rgn
);
3712 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3714 GdipDeleteRegion(rgn
);
3720 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3722 GpStatus stat
= NotImplemented
;
3724 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3726 if(!brush
|| !graphics
|| !path
)
3727 return InvalidParameter
;
3732 if (!graphics
->image
)
3733 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3735 if (stat
== NotImplemented
)
3736 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3738 if (stat
== NotImplemented
)
3740 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3747 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3748 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3753 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3754 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3756 if(!graphics
|| !brush
)
3757 return InvalidParameter
;
3762 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3766 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3769 stat
= GdipFillPath(graphics
, brush
, path
);
3771 GdipDeletePath(path
);
3777 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3778 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3780 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3781 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3783 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3786 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3787 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3792 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3794 if(!graphics
|| !brush
|| !points
|| !count
)
3795 return InvalidParameter
;
3800 stat
= GdipCreatePath(fillMode
, &path
);
3804 stat
= GdipAddPathPolygon(path
, points
, count
);
3807 stat
= GdipFillPath(graphics
, brush
, path
);
3809 GdipDeletePath(path
);
3815 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3816 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3821 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3823 if(!graphics
|| !brush
|| !points
|| !count
)
3824 return InvalidParameter
;
3829 stat
= GdipCreatePath(fillMode
, &path
);
3833 stat
= GdipAddPathPolygonI(path
, points
, count
);
3836 stat
= GdipFillPath(graphics
, brush
, path
);
3838 GdipDeletePath(path
);
3844 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3845 GDIPCONST GpPointF
*points
, INT count
)
3847 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3849 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3852 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3853 GDIPCONST GpPoint
*points
, INT count
)
3855 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3857 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3860 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3861 REAL x
, REAL y
, REAL width
, REAL height
)
3866 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3868 if(!graphics
|| !brush
)
3869 return InvalidParameter
;
3874 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3878 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3881 stat
= GdipFillPath(graphics
, brush
, path
);
3883 GdipDeletePath(path
);
3889 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3890 INT x
, INT y
, INT width
, INT height
)
3892 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3894 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
3897 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3903 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3906 return InvalidParameter
;
3908 for(i
= 0; i
< count
; i
++){
3909 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
3910 if(ret
!= Ok
) return ret
;
3916 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3923 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3925 if(!rects
|| count
<= 0)
3926 return InvalidParameter
;
3928 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3932 for(i
= 0; i
< count
; i
++){
3933 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3934 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3935 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3936 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3939 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3945 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3953 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3954 return NotImplemented
;
3956 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3960 save_state
= SaveDC(graphics
->hdc
);
3961 EndPath(graphics
->hdc
);
3963 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3965 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3967 BeginPath(graphics
->hdc
);
3968 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3969 EndPath(graphics
->hdc
);
3971 brush_fill_path(graphics
, brush
);
3974 RestoreDC(graphics
->hdc
, save_state
);
3981 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3985 GpRegion
*temp_region
;
3986 GpMatrix
*world_to_device
;
3987 GpRectF graphics_bounds
;
3991 GpRect gp_bound_rect
;
3993 if (!brush_can_fill_pixels(brush
))
3994 return NotImplemented
;
3996 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3999 stat
= GdipCloneRegion(region
, &temp_region
);
4003 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
4004 CoordinateSpaceWorld
, &world_to_device
);
4008 stat
= GdipTransformRegion(temp_region
, world_to_device
);
4010 GdipDeleteMatrix(world_to_device
);
4014 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4017 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4019 GdipDeleteRegion(temp_region
);
4022 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4024 DeleteObject(hregion
);
4030 gp_bound_rect
.X
= bound_rect
.left
;
4031 gp_bound_rect
.Y
= bound_rect
.top
;
4032 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4033 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4035 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4041 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4042 &gp_bound_rect
, gp_bound_rect
.Width
);
4045 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4046 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4047 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4049 GdipFree(pixel_data
);
4052 DeleteObject(hregion
);
4058 /*****************************************************************************
4059 * GdipFillRegion [GDIPLUS.@]
4061 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4064 GpStatus stat
= NotImplemented
;
4066 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4068 if (!(graphics
&& brush
&& region
))
4069 return InvalidParameter
;
4074 if (!graphics
->image
)
4075 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4077 if (stat
== NotImplemented
)
4078 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4080 if (stat
== NotImplemented
)
4082 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4089 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4091 TRACE("(%p,%u)\n", graphics
, intention
);
4094 return InvalidParameter
;
4099 /* We have no internal operation queue, so there's no need to clear it. */
4107 /*****************************************************************************
4108 * GdipGetClipBounds [GDIPLUS.@]
4110 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4112 TRACE("(%p, %p)\n", graphics
, rect
);
4115 return InvalidParameter
;
4120 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4123 /*****************************************************************************
4124 * GdipGetClipBoundsI [GDIPLUS.@]
4126 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4128 TRACE("(%p, %p)\n", graphics
, rect
);
4131 return InvalidParameter
;
4136 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4139 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4140 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4141 CompositingMode
*mode
)
4143 TRACE("(%p, %p)\n", graphics
, mode
);
4145 if(!graphics
|| !mode
)
4146 return InvalidParameter
;
4151 *mode
= graphics
->compmode
;
4156 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4157 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4158 CompositingQuality
*quality
)
4160 TRACE("(%p, %p)\n", graphics
, quality
);
4162 if(!graphics
|| !quality
)
4163 return InvalidParameter
;
4168 *quality
= graphics
->compqual
;
4173 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4174 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4175 InterpolationMode
*mode
)
4177 TRACE("(%p, %p)\n", graphics
, mode
);
4179 if(!graphics
|| !mode
)
4180 return InvalidParameter
;
4185 *mode
= graphics
->interpolation
;
4190 /* FIXME: Need to handle color depths less than 24bpp */
4191 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4193 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4195 if(!graphics
|| !argb
)
4196 return InvalidParameter
;
4204 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4206 TRACE("(%p, %p)\n", graphics
, scale
);
4208 if(!graphics
|| !scale
)
4209 return InvalidParameter
;
4214 *scale
= graphics
->scale
;
4219 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4221 TRACE("(%p, %p)\n", graphics
, unit
);
4223 if(!graphics
|| !unit
)
4224 return InvalidParameter
;
4229 *unit
= graphics
->unit
;
4234 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4235 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4238 TRACE("(%p, %p)\n", graphics
, mode
);
4240 if(!graphics
|| !mode
)
4241 return InvalidParameter
;
4246 *mode
= graphics
->pixeloffset
;
4251 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4252 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4254 TRACE("(%p, %p)\n", graphics
, mode
);
4256 if(!graphics
|| !mode
)
4257 return InvalidParameter
;
4262 *mode
= graphics
->smoothing
;
4267 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4269 TRACE("(%p, %p)\n", graphics
, contrast
);
4271 if(!graphics
|| !contrast
)
4272 return InvalidParameter
;
4274 *contrast
= graphics
->textcontrast
;
4279 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4280 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4281 TextRenderingHint
*hint
)
4283 TRACE("(%p, %p)\n", graphics
, hint
);
4285 if(!graphics
|| !hint
)
4286 return InvalidParameter
;
4291 *hint
= graphics
->texthint
;
4296 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4301 TRACE("(%p, %p)\n", graphics
, rect
);
4303 if(!graphics
|| !rect
)
4304 return InvalidParameter
;
4309 /* intersect window and graphics clipping regions */
4310 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4313 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4316 /* get bounds of the region */
4317 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4320 GdipDeleteRegion(clip_rgn
);
4325 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4330 TRACE("(%p, %p)\n", graphics
, rect
);
4332 if(!graphics
|| !rect
)
4333 return InvalidParameter
;
4335 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4337 rect
->X
= roundr(rectf
.X
);
4338 rect
->Y
= roundr(rectf
.Y
);
4339 rect
->Width
= roundr(rectf
.Width
);
4340 rect
->Height
= roundr(rectf
.Height
);
4346 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4348 TRACE("(%p, %p)\n", graphics
, matrix
);
4350 if(!graphics
|| !matrix
)
4351 return InvalidParameter
;
4356 *matrix
= *graphics
->worldtrans
;
4360 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4366 TRACE("(%p, %x)\n", graphics
, color
);
4369 return InvalidParameter
;
4374 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4377 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4378 GdipDeleteBrush((GpBrush
*)brush
);
4382 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4383 wnd_rect
.Width
, wnd_rect
.Height
);
4385 GdipDeleteBrush((GpBrush
*)brush
);
4390 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4392 TRACE("(%p, %p)\n", graphics
, res
);
4394 if(!graphics
|| !res
)
4395 return InvalidParameter
;
4397 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4400 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4406 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4408 if(!graphics
|| !result
)
4409 return InvalidParameter
;
4416 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4417 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4420 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4423 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4426 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4429 GdipDeleteRegion(rgn
);
4433 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4435 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4438 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4444 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4446 if(!graphics
|| !result
)
4447 return InvalidParameter
;
4454 pts
[1].X
= x
+ width
;
4455 pts
[1].Y
= y
+ height
;
4457 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4458 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4461 pts
[1].X
-= pts
[0].X
;
4462 pts
[1].Y
-= pts
[0].Y
;
4464 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4467 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4470 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4473 GdipDeleteRegion(rgn
);
4477 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4479 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4482 GpStatus
gdip_format_string(HDC hdc
,
4483 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4484 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4485 gdip_format_string_callback callback
, void *user_data
)
4488 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4489 nheight
, lineend
, lineno
= 0;
4491 StringAlignment halign
;
4495 if(length
== -1) length
= lstrlenW(string
);
4497 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4498 if(!stringdup
) return OutOfMemory
;
4500 nwidth
= roundr(rect
->Width
);
4501 nheight
= roundr(rect
->Height
);
4503 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
4504 if (rect
->Height
>= INT_MAX
|| rect
->Height
< 0.5) nheight
= INT_MAX
;
4506 for(i
= 0, j
= 0; i
< length
; i
++){
4507 /* FIXME: This makes the indexes passed to callback inaccurate. */
4508 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4511 stringdup
[j
] = string
[i
];
4517 if (format
) halign
= format
->align
;
4518 else halign
= StringAlignmentNear
;
4520 while(sum
< length
){
4521 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4522 nwidth
, &fit
, NULL
, &size
);
4528 for(lret
= 0; lret
< fit
; lret
++)
4529 if(*(stringdup
+ sum
+ lret
) == '\n')
4532 /* Line break code (may look strange, but it imitates windows). */
4534 lineend
= fit
= lret
; /* this is not an off-by-one error */
4535 else if(fit
< (length
- sum
)){
4536 if(*(stringdup
+ sum
+ fit
) == ' ')
4537 while(*(stringdup
+ sum
+ fit
) == ' ')
4540 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4543 if(*(stringdup
+ sum
+ fit
) == '\t')
4552 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4553 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4559 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4560 nwidth
, &j
, NULL
, &size
);
4562 bounds
.Width
= size
.cx
;
4564 if(height
+ size
.cy
> nheight
)
4565 bounds
.Height
= nheight
- (height
+ size
.cy
);
4567 bounds
.Height
= size
.cy
;
4569 bounds
.Y
= rect
->Y
+ height
;
4573 case StringAlignmentNear
:
4577 case StringAlignmentCenter
:
4578 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4580 case StringAlignmentFar
:
4581 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4585 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4586 font
, rect
, format
, lineno
, &bounds
, user_data
);
4591 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4595 if(height
> nheight
)
4598 /* Stop if this was a linewrap (but not if it was a linebreak). */
4599 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
4603 GdipFree(stringdup
);
4608 struct measure_ranges_args
{
4612 static GpStatus
measure_ranges_callback(HDC hdc
,
4613 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4614 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4615 INT lineno
, const RectF
*bounds
, void *user_data
)
4619 struct measure_ranges_args
*args
= user_data
;
4621 for (i
=0; i
<format
->range_count
; i
++)
4623 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4624 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4625 if (range_start
< range_end
)
4630 range_rect
.Y
= bounds
->Y
;
4631 range_rect
.Height
= bounds
->Height
;
4633 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4634 INT_MAX
, NULL
, NULL
, &range_size
);
4635 range_rect
.X
= bounds
->X
+ range_size
.cx
;
4637 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4638 INT_MAX
, NULL
, NULL
, &range_size
);
4639 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
4641 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4650 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4651 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4652 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4653 INT regionCount
, GpRegion
** regions
)
4658 struct measure_ranges_args args
;
4659 HDC hdc
, temp_hdc
=NULL
;
4661 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4662 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4664 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4665 return InvalidParameter
;
4667 if (regionCount
< stringFormat
->range_count
)
4668 return InvalidParameter
;
4672 hdc
= temp_hdc
= CreateCompatibleDC(0);
4673 if (!temp_hdc
) return OutOfMemory
;
4676 hdc
= graphics
->hdc
;
4678 if (stringFormat
->attr
)
4679 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4681 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&font
->lfw
));
4683 for (i
=0; i
<stringFormat
->range_count
; i
++)
4685 stat
= GdipSetEmpty(regions
[i
]);
4690 args
.regions
= regions
;
4692 stat
= gdip_format_string(hdc
, string
, length
, font
, layoutRect
, stringFormat
,
4693 measure_ranges_callback
, &args
);
4695 DeleteObject(SelectObject(hdc
, oldfont
));
4703 struct measure_string_args
{
4705 INT
*codepointsfitted
;
4709 static GpStatus
measure_string_callback(HDC hdc
,
4710 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4711 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4712 INT lineno
, const RectF
*bounds
, void *user_data
)
4714 struct measure_string_args
*args
= user_data
;
4716 if (bounds
->Width
> args
->bounds
->Width
)
4717 args
->bounds
->Width
= bounds
->Width
;
4719 if (bounds
->Height
+ bounds
->Y
> args
->bounds
->Height
+ args
->bounds
->Y
)
4720 args
->bounds
->Height
= bounds
->Height
+ bounds
->Y
- args
->bounds
->Y
;
4722 if (args
->codepointsfitted
)
4723 *args
->codepointsfitted
= index
+ length
;
4725 if (args
->linesfilled
)
4726 (*args
->linesfilled
)++;
4731 /* Find the smallest rectangle that bounds the text when it is printed in rect
4732 * according to the format options listed in format. If rect has 0 width and
4733 * height, then just find the smallest rectangle that bounds the text when it's
4734 * printed at location (rect->X, rect-Y). */
4735 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4736 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4737 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4738 INT
*codepointsfitted
, INT
*linesfilled
)
4741 struct measure_string_args args
;
4742 HDC temp_hdc
=NULL
, hdc
;
4744 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4745 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4746 bounds
, codepointsfitted
, linesfilled
);
4748 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4749 return InvalidParameter
;
4753 hdc
= temp_hdc
= CreateCompatibleDC(0);
4754 if (!temp_hdc
) return OutOfMemory
;
4757 hdc
= graphics
->hdc
;
4759 if(linesfilled
) *linesfilled
= 0;
4760 if(codepointsfitted
) *codepointsfitted
= 0;
4763 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4765 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&font
->lfw
));
4767 bounds
->X
= rect
->X
;
4768 bounds
->Y
= rect
->Y
;
4769 bounds
->Width
= 0.0;
4770 bounds
->Height
= 0.0;
4772 args
.bounds
= bounds
;
4773 args
.codepointsfitted
= codepointsfitted
;
4774 args
.linesfilled
= linesfilled
;
4776 gdip_format_string(hdc
, string
, length
, font
, rect
, format
,
4777 measure_string_callback
, &args
);
4779 DeleteObject(SelectObject(hdc
, oldfont
));
4787 struct draw_string_args
{
4788 GpGraphics
*graphics
;
4789 GDIPCONST GpBrush
*brush
;
4790 REAL x
, y
, rel_width
, rel_height
, ascent
;
4793 static GpStatus
draw_string_callback(HDC hdc
,
4794 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4795 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4796 INT lineno
, const RectF
*bounds
, void *user_data
)
4798 struct draw_string_args
*args
= user_data
;
4801 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4802 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4804 return GdipDrawDriverString(args
->graphics
, &string
[index
], length
, font
,
4805 args
->brush
, &position
,
4806 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4809 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4810 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4811 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4815 GpPointF pt
[3], rectcpy
[4];
4817 REAL rel_width
, rel_height
;
4820 struct draw_string_args args
;
4822 HDC hdc
, temp_hdc
=NULL
;
4823 TEXTMETRICW textmetric
;
4825 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4826 length
, font
, debugstr_rectf(rect
), format
, brush
);
4828 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4829 return InvalidParameter
;
4833 hdc
= graphics
->hdc
;
4837 hdc
= temp_hdc
= CreateCompatibleDC(0);
4841 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4843 /* Should be no need to explicitly test for StringAlignmentNear as
4844 * that is default behavior if no alignment is passed. */
4845 if(format
->vertalign
!= StringAlignmentNear
){
4847 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
4849 if(format
->vertalign
== StringAlignmentCenter
)
4850 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4851 else if(format
->vertalign
== StringAlignmentFar
)
4852 offsety
= (rect
->Height
- bounds
.Height
);
4856 save_state
= SaveDC(hdc
);
4864 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4865 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4866 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4867 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4868 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4870 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
4871 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
4872 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
4873 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
4874 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
4876 scaled_rect
.X
= 0.0;
4877 scaled_rect
.Y
= 0.0;
4878 scaled_rect
.Width
= rel_width
* rect
->Width
;
4879 scaled_rect
.Height
= rel_height
* rect
->Height
;
4881 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
4883 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4884 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
4885 SelectClipRgn(hdc
, rgn
);
4888 get_font_hfont(graphics
, font
, &gdifont
);
4889 SelectObject(hdc
, gdifont
);
4891 args
.graphics
= graphics
;
4895 args
.y
= rect
->Y
+ offsety
;
4897 args
.rel_width
= rel_width
;
4898 args
.rel_height
= rel_height
;
4900 GetTextMetricsW(hdc
, &textmetric
);
4901 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
4903 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
4904 draw_string_callback
, &args
);
4907 DeleteObject(gdifont
);
4909 RestoreDC(hdc
, save_state
);
4916 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
4918 TRACE("(%p)\n", graphics
);
4921 return InvalidParameter
;
4926 return GdipSetInfinite(graphics
->clip
);
4929 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
4931 TRACE("(%p)\n", graphics
);
4934 return InvalidParameter
;
4939 graphics
->worldtrans
->matrix
[0] = 1.0;
4940 graphics
->worldtrans
->matrix
[1] = 0.0;
4941 graphics
->worldtrans
->matrix
[2] = 0.0;
4942 graphics
->worldtrans
->matrix
[3] = 1.0;
4943 graphics
->worldtrans
->matrix
[4] = 0.0;
4944 graphics
->worldtrans
->matrix
[5] = 0.0;
4949 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
4951 return GdipEndContainer(graphics
, state
);
4954 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
4955 GpMatrixOrder order
)
4957 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
4960 return InvalidParameter
;
4965 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
4968 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
4970 return GdipBeginContainer2(graphics
, state
);
4973 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
4974 GraphicsContainer
*state
)
4976 GraphicsContainerItem
*container
;
4979 TRACE("(%p, %p)\n", graphics
, state
);
4981 if(!graphics
|| !state
)
4982 return InvalidParameter
;
4984 sts
= init_container(&container
, graphics
);
4988 list_add_head(&graphics
->containers
, &container
->entry
);
4989 *state
= graphics
->contid
= container
->contid
;
4994 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4996 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4997 return NotImplemented
;
5000 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5002 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5003 return NotImplemented
;
5006 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5008 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5009 return NotImplemented
;
5012 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5015 GraphicsContainerItem
*container
, *container2
;
5017 TRACE("(%p, %x)\n", graphics
, state
);
5020 return InvalidParameter
;
5022 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5023 if(container
->contid
== state
)
5027 /* did not find a matching container */
5028 if(&container
->entry
== &graphics
->containers
)
5031 sts
= restore_container(graphics
, container
);
5035 /* remove all of the containers on top of the found container */
5036 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5037 if(container
->contid
== state
)
5039 list_remove(&container
->entry
);
5040 delete_container(container
);
5043 list_remove(&container
->entry
);
5044 delete_container(container
);
5049 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5050 REAL sy
, GpMatrixOrder order
)
5052 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5055 return InvalidParameter
;
5060 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
5063 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5066 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5068 if(!graphics
|| !srcgraphics
)
5069 return InvalidParameter
;
5071 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5074 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5075 CompositingMode mode
)
5077 TRACE("(%p, %d)\n", graphics
, mode
);
5080 return InvalidParameter
;
5085 graphics
->compmode
= mode
;
5090 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5091 CompositingQuality quality
)
5093 TRACE("(%p, %d)\n", graphics
, quality
);
5096 return InvalidParameter
;
5101 graphics
->compqual
= quality
;
5106 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5107 InterpolationMode mode
)
5109 TRACE("(%p, %d)\n", graphics
, mode
);
5111 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5112 return InvalidParameter
;
5117 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5118 mode
= InterpolationModeBilinear
;
5120 if (mode
== InterpolationModeHighQuality
)
5121 mode
= InterpolationModeHighQualityBicubic
;
5123 graphics
->interpolation
= mode
;
5128 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5130 TRACE("(%p, %.2f)\n", graphics
, scale
);
5132 if(!graphics
|| (scale
<= 0.0))
5133 return InvalidParameter
;
5138 graphics
->scale
= scale
;
5143 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5145 TRACE("(%p, %d)\n", graphics
, unit
);
5148 return InvalidParameter
;
5153 if(unit
== UnitWorld
)
5154 return InvalidParameter
;
5156 graphics
->unit
= unit
;
5161 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5164 TRACE("(%p, %d)\n", graphics
, mode
);
5167 return InvalidParameter
;
5172 graphics
->pixeloffset
= mode
;
5177 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5181 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5184 FIXME("not implemented\n");
5186 return NotImplemented
;
5189 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5193 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5196 FIXME("not implemented\n");
5200 return NotImplemented
;
5203 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5205 TRACE("(%p, %d)\n", graphics
, mode
);
5208 return InvalidParameter
;
5213 graphics
->smoothing
= mode
;
5218 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5220 TRACE("(%p, %d)\n", graphics
, contrast
);
5223 return InvalidParameter
;
5225 graphics
->textcontrast
= contrast
;
5230 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5231 TextRenderingHint hint
)
5233 TRACE("(%p, %d)\n", graphics
, hint
);
5235 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5236 return InvalidParameter
;
5241 graphics
->texthint
= hint
;
5246 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5248 TRACE("(%p, %p)\n", graphics
, matrix
);
5250 if(!graphics
|| !matrix
)
5251 return InvalidParameter
;
5256 GdipDeleteMatrix(graphics
->worldtrans
);
5257 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
5260 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5261 REAL dy
, GpMatrixOrder order
)
5263 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5266 return InvalidParameter
;
5271 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
5274 /*****************************************************************************
5275 * GdipSetClipHrgn [GDIPLUS.@]
5277 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5282 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5285 return InvalidParameter
;
5287 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5291 status
= GdipSetClipRegion(graphics
, region
, mode
);
5293 GdipDeleteRegion(region
);
5297 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5299 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5302 return InvalidParameter
;
5307 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5310 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5311 REAL width
, REAL height
,
5316 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5319 return InvalidParameter
;
5327 rect
.Height
= height
;
5329 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5332 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5333 INT width
, INT height
,
5336 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5339 return InvalidParameter
;
5344 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5347 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5350 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5352 if(!graphics
|| !region
)
5353 return InvalidParameter
;
5358 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5361 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5366 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5369 FIXME("not implemented\n");
5371 return NotImplemented
;
5374 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5380 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5382 if(!graphics
|| !pen
|| count
<=0)
5383 return InvalidParameter
;
5390 FIXME("graphics object has no HDC\n");
5394 pti
= GdipAlloc(sizeof(POINT
) * count
);
5396 save_state
= prepare_dc(graphics
, pen
);
5397 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5399 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5400 Polygon(graphics
->hdc
, pti
, count
);
5402 restore_dc(graphics
, save_state
);
5408 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5415 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5417 if(count
<=0) return InvalidParameter
;
5418 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5420 for(i
= 0;i
< count
; i
++){
5421 ptf
[i
].X
= (REAL
)points
[i
].X
;
5422 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5425 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5431 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5433 TRACE("(%p, %p)\n", graphics
, dpi
);
5435 if(!graphics
|| !dpi
)
5436 return InvalidParameter
;
5441 if (graphics
->image
)
5442 *dpi
= graphics
->image
->xres
;
5444 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
5449 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5451 TRACE("(%p, %p)\n", graphics
, dpi
);
5453 if(!graphics
|| !dpi
)
5454 return InvalidParameter
;
5459 if (graphics
->image
)
5460 *dpi
= graphics
->image
->yres
;
5462 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
5467 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5468 GpMatrixOrder order
)
5473 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5475 if(!graphics
|| !matrix
)
5476 return InvalidParameter
;
5481 m
= *(graphics
->worldtrans
);
5483 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5485 *(graphics
->worldtrans
) = m
;
5490 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5491 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5493 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5497 TRACE("(%p, %p)\n", graphics
, hdc
);
5499 if(!graphics
|| !hdc
)
5500 return InvalidParameter
;
5505 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5507 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5509 else if (!graphics
->hdc
||
5510 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5512 /* Create a fake HDC and fill it with a constant color. */
5516 BITMAPINFOHEADER bmih
;
5519 stat
= get_graphics_bounds(graphics
, &bounds
);
5523 graphics
->temp_hbitmap_width
= bounds
.Width
;
5524 graphics
->temp_hbitmap_height
= bounds
.Height
;
5526 bmih
.biSize
= sizeof(bmih
);
5527 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5528 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5530 bmih
.biBitCount
= 32;
5531 bmih
.biCompression
= BI_RGB
;
5532 bmih
.biSizeImage
= 0;
5533 bmih
.biXPelsPerMeter
= 0;
5534 bmih
.biYPelsPerMeter
= 0;
5536 bmih
.biClrImportant
= 0;
5538 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5539 (void**)&graphics
->temp_bits
, NULL
, 0);
5541 return GenericError
;
5543 temp_hdc
= CreateCompatibleDC(0);
5546 DeleteObject(hbitmap
);
5547 return GenericError
;
5550 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5551 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5553 SelectObject(temp_hdc
, hbitmap
);
5555 graphics
->temp_hbitmap
= hbitmap
;
5556 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5560 *hdc
= graphics
->hdc
;
5564 graphics
->busy
= TRUE
;
5569 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5573 TRACE("(%p, %p)\n", graphics
, hdc
);
5575 if(!graphics
|| !hdc
|| !graphics
->busy
)
5576 return InvalidParameter
;
5578 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5580 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5582 else if (graphics
->temp_hdc
== hdc
)
5587 /* Find the pixels that have changed, and mark them as opaque. */
5588 pos
= (DWORD
*)graphics
->temp_bits
;
5589 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5591 if (*pos
!= DC_BACKGROUND_KEY
)
5598 /* Write the changed pixels to the real target. */
5599 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5600 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5601 graphics
->temp_hbitmap_width
* 4);
5604 DeleteDC(graphics
->temp_hdc
);
5605 DeleteObject(graphics
->temp_hbitmap
);
5606 graphics
->temp_hdc
= NULL
;
5607 graphics
->temp_hbitmap
= NULL
;
5609 else if (hdc
!= graphics
->hdc
)
5611 stat
= InvalidParameter
;
5615 graphics
->busy
= FALSE
;
5620 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5625 TRACE("(%p, %p)\n", graphics
, region
);
5627 if(!graphics
|| !region
)
5628 return InvalidParameter
;
5633 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5636 /* free everything except root node and header */
5637 delete_element(®ion
->node
);
5638 memcpy(region
, clip
, sizeof(GpRegion
));
5644 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5645 GpCoordinateSpace src_space
, GpMatrix
**matrix
)
5647 GpStatus stat
= GdipCreateMatrix(matrix
);
5650 if (dst_space
!= src_space
&& stat
== Ok
)
5652 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
5654 if(graphics
->unit
!= UnitDisplay
)
5655 unitscale
*= graphics
->scale
;
5657 /* transform from src_space to CoordinateSpacePage */
5660 case CoordinateSpaceWorld
:
5661 GdipMultiplyMatrix(*matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
5663 case CoordinateSpacePage
:
5665 case CoordinateSpaceDevice
:
5666 GdipScaleMatrix(*matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
5670 /* transform from CoordinateSpacePage to dst_space */
5673 case CoordinateSpaceWorld
:
5675 GpMatrix
*inverted_transform
;
5676 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
5679 stat
= GdipInvertMatrix(inverted_transform
);
5681 GdipMultiplyMatrix(*matrix
, inverted_transform
, MatrixOrderAppend
);
5682 GdipDeleteMatrix(inverted_transform
);
5686 case CoordinateSpacePage
:
5688 case CoordinateSpaceDevice
:
5689 GdipScaleMatrix(*matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
5696 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5697 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5702 if(!graphics
|| !points
|| count
<= 0)
5703 return InvalidParameter
;
5708 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5710 if (src_space
== dst_space
) return Ok
;
5712 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5716 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
5718 GdipDeleteMatrix(matrix
);
5724 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5725 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5731 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5734 return InvalidParameter
;
5736 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5740 for(i
= 0; i
< count
; i
++){
5741 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5742 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5745 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5748 for(i
= 0; i
< count
; i
++){
5749 points
[i
].X
= roundr(pointsF
[i
].X
);
5750 points
[i
].Y
= roundr(pointsF
[i
].Y
);
5757 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5769 /*****************************************************************************
5770 * GdipTranslateClip [GDIPLUS.@]
5772 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5774 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5777 return InvalidParameter
;
5782 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5785 /*****************************************************************************
5786 * GdipTranslateClipI [GDIPLUS.@]
5788 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5790 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5793 return InvalidParameter
;
5798 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
5802 /*****************************************************************************
5803 * GdipMeasureDriverString [GDIPLUS.@]
5805 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5806 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
5807 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
5809 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
5812 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
5814 TEXTMETRICW textmetric
;
5815 const WORD
*glyph_indices
;
5816 WORD
*dynamic_glyph_indices
=NULL
;
5817 REAL rel_width
, rel_height
, ascent
, descent
;
5820 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
5822 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
5823 return InvalidParameter
;
5826 length
= strlenW(text
);
5830 boundingBox
->X
= 0.0;
5831 boundingBox
->Y
= 0.0;
5832 boundingBox
->Width
= 0.0;
5833 boundingBox
->Height
= 0.0;
5836 if (flags
& unsupported_flags
)
5837 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
5840 FIXME("Ignoring matrix\n");
5842 get_font_hfont(graphics
, font
, &hfont
);
5844 hdc
= CreateCompatibleDC(0);
5845 SelectObject(hdc
, hfont
);
5847 GetTextMetricsW(hdc
, &textmetric
);
5855 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5856 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5857 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5858 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5859 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5861 if (flags
& DriverStringOptionsCmapLookup
)
5863 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
5867 DeleteObject(hfont
);
5871 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
5874 glyph_indices
= text
;
5876 min_x
= max_x
= x
= positions
[0].X
;
5877 min_y
= max_y
= y
= positions
[0].Y
;
5879 ascent
= textmetric
.tmAscent
/ rel_height
;
5880 descent
= textmetric
.tmDescent
/ rel_height
;
5882 for (i
=0; i
<length
; i
++)
5887 if (!(flags
& DriverStringOptionsRealizedAdvance
))
5893 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
5894 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcB
;
5896 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
5897 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
5898 if (min_x
> x
) min_x
= x
;
5900 x
+= char_width
/ rel_width
;
5902 if (max_x
< x
) max_x
= x
;
5905 GdipFree(dynamic_glyph_indices
);
5907 DeleteObject(hfont
);
5909 boundingBox
->X
= min_x
;
5910 boundingBox
->Y
= min_y
;
5911 boundingBox
->Width
= max_x
- min_x
;
5912 boundingBox
->Height
= max_y
- min_y
;
5917 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5918 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
5919 GDIPCONST PointF
*positions
, INT flags
,
5920 GDIPCONST GpMatrix
*matrix
)
5922 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
5928 if (flags
& unsupported_flags
)
5929 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
5932 FIXME("Ignoring matrix\n");
5934 if (!(flags
& DriverStringOptionsCmapLookup
))
5935 eto_flags
|= ETO_GLYPH_INDEX
;
5937 save_state
= SaveDC(graphics
->hdc
);
5938 SetBkMode(graphics
->hdc
, TRANSPARENT
);
5939 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
5942 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
5944 get_font_hfont(graphics
, font
, &hfont
);
5945 SelectObject(graphics
->hdc
, hfont
);
5947 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
5949 ExtTextOutW(graphics
->hdc
, roundr(pt
.X
), roundr(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
5951 RestoreDC(graphics
->hdc
, save_state
);
5953 DeleteObject(hfont
);
5958 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5959 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
5960 GDIPCONST PointF
*positions
, INT flags
,
5961 GDIPCONST GpMatrix
*matrix
)
5963 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
5965 PointF
*real_positions
, real_position
;
5969 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
5970 DWORD max_glyphsize
=0;
5971 GLYPHMETRICS glyphmetrics
;
5972 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
5975 int text_mask_stride
;
5977 int pixel_data_stride
;
5979 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
5984 if (!(flags
& DriverStringOptionsCmapLookup
))
5985 ggo_flags
|= GGO_GLYPH_INDEX
;
5987 if (flags
& unsupported_flags
)
5988 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
5991 FIXME("Ignoring matrix\n");
5993 pti
= GdipAlloc(sizeof(POINT
) * length
);
5997 if (flags
& DriverStringOptionsRealizedAdvance
)
5999 real_position
= positions
[0];
6001 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6005 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6006 if (!real_positions
)
6012 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6014 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6016 GdipFree(real_positions
);
6019 get_font_hfont(graphics
, font
, &hfont
);
6021 hdc
= CreateCompatibleDC(0);
6022 SelectObject(hdc
, hfont
);
6024 /* Get the boundaries of the text to be drawn */
6025 for (i
=0; i
<length
; i
++)
6028 int left
, top
, right
, bottom
;
6030 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6031 &glyphmetrics
, 0, NULL
, &identity
);
6033 if (glyphsize
== GDI_ERROR
)
6035 ERR("GetGlyphOutlineW failed\n");
6038 DeleteObject(hfont
);
6039 return GenericError
;
6042 if (glyphsize
> max_glyphsize
)
6043 max_glyphsize
= glyphsize
;
6045 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6046 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6047 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6048 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6050 if (left
< min_x
) min_x
= left
;
6051 if (top
< min_y
) min_y
= top
;
6052 if (right
> max_x
) max_x
= right
;
6053 if (bottom
> max_y
) max_y
= bottom
;
6055 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6057 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6058 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6062 glyph_mask
= GdipAlloc(max_glyphsize
);
6063 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6064 text_mask_stride
= max_x
- min_x
;
6066 if (!(glyph_mask
&& text_mask
))
6068 GdipFree(glyph_mask
);
6069 GdipFree(text_mask
);
6072 DeleteObject(hfont
);
6076 /* Generate a mask for the text */
6077 for (i
=0; i
<length
; i
++)
6079 int left
, top
, stride
;
6081 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6082 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6084 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6085 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6086 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6088 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6090 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6091 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6092 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6094 *text_val
= min(64, *text_val
+ *glyph_val
);
6103 DeleteObject(hfont
);
6104 GdipFree(glyph_mask
);
6106 /* get the brush data */
6107 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6110 GdipFree(text_mask
);
6114 pixel_area
.X
= min_x
;
6115 pixel_area
.Y
= min_y
;
6116 pixel_area
.Width
= max_x
- min_x
;
6117 pixel_area
.Height
= max_y
- min_y
;
6118 pixel_data_stride
= pixel_area
.Width
* 4;
6120 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6123 GdipFree(text_mask
);
6124 GdipFree(pixel_data
);
6128 /* multiply the brush data by the mask */
6129 for (y
=0; y
<pixel_area
.Height
; y
++)
6131 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6132 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6133 for (x
=0; x
<pixel_area
.Width
; x
++)
6135 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6141 GdipFree(text_mask
);
6143 /* draw the result */
6144 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6145 pixel_area
.Height
, pixel_data_stride
);
6147 GdipFree(pixel_data
);
6152 /*****************************************************************************
6153 * GdipDrawDriverString [GDIPLUS.@]
6155 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6156 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6157 GDIPCONST PointF
*positions
, INT flags
,
6158 GDIPCONST GpMatrix
*matrix
)
6160 GpStatus stat
=NotImplemented
;
6162 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6164 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6165 return InvalidParameter
;
6168 length
= strlenW(text
);
6170 if (graphics
->hdc
&&
6171 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6172 brush
->bt
== BrushTypeSolidColor
&&
6173 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6174 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
6175 positions
, flags
, matrix
);
6177 if (stat
== NotImplemented
)
6178 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
6179 positions
, flags
, matrix
);
6184 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6185 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6187 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6188 return NotImplemented
;
6191 /*****************************************************************************
6192 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6194 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6199 TRACE("(%p, %p)\n", graphics
, res
);
6201 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6204 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6207 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6210 GdipDeleteRegion(rgn
);