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 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
344 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
346 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
348 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
350 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
351 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
357 bf
.BlendOp
= AC_SRC_OVER
;
359 bf
.SourceConstantAlpha
= 255;
360 bf
.AlphaFormat
= AC_SRC_ALPHA
;
362 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
363 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
367 /* Draw non-premultiplied ARGB data to the given graphics object */
368 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
369 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
371 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
373 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
376 for (x
=0; x
<src_width
; x
++)
378 for (y
=0; y
<src_height
; y
++)
380 ARGB dst_color
, src_color
;
381 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
382 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
383 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
389 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
391 ERR("This should not be used for metafiles; fix caller\n");
392 return NotImplemented
;
398 BITMAPINFOHEADER bih
;
401 hdc
= CreateCompatibleDC(0);
403 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
404 bih
.biWidth
= src_width
;
405 bih
.biHeight
= -src_height
;
408 bih
.biCompression
= BI_RGB
;
410 bih
.biXPelsPerMeter
= 0;
411 bih
.biYPelsPerMeter
= 0;
413 bih
.biClrImportant
= 0;
415 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
416 (void**)&temp_bits
, NULL
, 0);
418 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
419 4 * src_width
, src
, src_stride
);
421 SelectObject(hdc
, hbitmap
);
422 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
423 hdc
, 0, 0, src_width
, src_height
);
425 DeleteObject(hbitmap
);
431 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
437 a1
= (start
>> 24) & 0xff;
438 a2
= (end
>> 24) & 0xff;
440 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
444 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
445 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
449 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
453 /* clamp to between 0.0 and 1.0, using the wrap mode */
454 if (brush
->wrap
== WrapModeTile
)
456 position
= fmodf(position
, 1.0f
);
457 if (position
< 0.0f
) position
+= 1.0f
;
459 else /* WrapModeFlip* */
461 position
= fmodf(position
, 2.0f
);
462 if (position
< 0.0f
) position
+= 2.0f
;
463 if (position
> 1.0f
) position
= 2.0f
- position
;
466 if (brush
->blendcount
== 1)
471 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
474 /* locate the blend positions surrounding this position */
475 while (position
> brush
->blendpos
[i
])
478 /* interpolate between the blend positions */
479 left_blendpos
= brush
->blendpos
[i
-1];
480 left_blendfac
= brush
->blendfac
[i
-1];
481 right_blendpos
= brush
->blendpos
[i
];
482 right_blendfac
= brush
->blendfac
[i
];
483 range
= right_blendpos
- left_blendpos
;
484 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
485 right_blendfac
* (position
- left_blendpos
)) / range
;
488 if (brush
->pblendcount
== 0)
489 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
493 ARGB left_blendcolor
, right_blendcolor
;
494 REAL left_blendpos
, right_blendpos
;
496 /* locate the blend colors surrounding this position */
497 while (blendfac
> brush
->pblendpos
[i
])
500 /* interpolate between the blend colors */
501 left_blendpos
= brush
->pblendpos
[i
-1];
502 left_blendcolor
= brush
->pblendcolor
[i
-1];
503 right_blendpos
= brush
->pblendpos
[i
];
504 right_blendcolor
= brush
->pblendcolor
[i
];
505 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
506 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
510 static ARGB
transform_color(ARGB color
, const ColorMatrix
*matrix
)
514 unsigned char a
, r
, g
, b
;
516 val
[0] = ((color
>> 16) & 0xff) / 255.0; /* red */
517 val
[1] = ((color
>> 8) & 0xff) / 255.0; /* green */
518 val
[2] = (color
& 0xff) / 255.0; /* blue */
519 val
[3] = ((color
>> 24) & 0xff) / 255.0; /* alpha */
520 val
[4] = 1.0; /* translation */
527 res
[i
] += matrix
->m
[j
][i
] * val
[j
];
530 a
= min(max(floorf(res
[3]*255.0), 0.0), 255.0);
531 r
= min(max(floorf(res
[0]*255.0), 0.0), 255.0);
532 g
= min(max(floorf(res
[1]*255.0), 0.0), 255.0);
533 b
= min(max(floorf(res
[2]*255.0), 0.0), 255.0);
535 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
538 static int color_is_gray(ARGB color
)
540 unsigned char r
, g
, b
;
542 r
= (color
>> 16) & 0xff;
543 g
= (color
>> 8) & 0xff;
546 return (r
== g
) && (g
== b
);
549 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
550 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
554 if (attributes
->colorkeys
[type
].enabled
||
555 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
557 const struct color_key
*key
;
558 BYTE min_blue
, min_green
, min_red
;
559 BYTE max_blue
, max_green
, max_red
;
561 if (attributes
->colorkeys
[type
].enabled
)
562 key
= &attributes
->colorkeys
[type
];
564 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
566 min_blue
= key
->low
&0xff;
567 min_green
= (key
->low
>>8)&0xff;
568 min_red
= (key
->low
>>16)&0xff;
570 max_blue
= key
->high
&0xff;
571 max_green
= (key
->high
>>8)&0xff;
572 max_red
= (key
->high
>>16)&0xff;
574 for (x
=0; x
<width
; x
++)
575 for (y
=0; y
<height
; y
++)
578 BYTE blue
, green
, red
;
579 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
580 blue
= *src_color
&0xff;
581 green
= (*src_color
>>8)&0xff;
582 red
= (*src_color
>>16)&0xff;
583 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
584 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
585 *src_color
= 0x00000000;
589 if (attributes
->colorremaptables
[type
].enabled
||
590 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
592 const struct color_remap_table
*table
;
594 if (attributes
->colorremaptables
[type
].enabled
)
595 table
= &attributes
->colorremaptables
[type
];
597 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
599 for (x
=0; x
<width
; x
++)
600 for (y
=0; y
<height
; y
++)
603 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
604 for (i
=0; i
<table
->mapsize
; i
++)
606 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
608 *src_color
= table
->colormap
[i
].newColor
.Argb
;
615 if (attributes
->colormatrices
[type
].enabled
||
616 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
618 const struct color_matrix
*colormatrices
;
620 if (attributes
->colormatrices
[type
].enabled
)
621 colormatrices
= &attributes
->colormatrices
[type
];
623 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
625 for (x
=0; x
<width
; x
++)
626 for (y
=0; y
<height
; y
++)
629 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
631 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
632 !color_is_gray(*src_color
))
634 *src_color
= transform_color(*src_color
, &colormatrices
->colormatrix
);
636 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
638 *src_color
= transform_color(*src_color
, &colormatrices
->graymatrix
);
643 if (attributes
->gamma_enabled
[type
] ||
644 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
648 if (attributes
->gamma_enabled
[type
])
649 gamma
= attributes
->gamma
[type
];
651 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
653 for (x
=0; x
<width
; x
++)
654 for (y
=0; y
<height
; y
++)
657 BYTE blue
, green
, red
;
658 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
660 blue
= *src_color
&0xff;
661 green
= (*src_color
>>8)&0xff;
662 red
= (*src_color
>>16)&0xff;
664 /* FIXME: We should probably use a table for this. */
665 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
666 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
667 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
669 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
674 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
675 * bitmap that contains all the pixels we may need to draw it. */
676 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
677 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
680 INT left
, top
, right
, bottom
;
682 switch (interpolation
)
684 case InterpolationModeHighQualityBilinear
:
685 case InterpolationModeHighQualityBicubic
:
686 /* FIXME: Include a greater range for the prefilter? */
687 case InterpolationModeBicubic
:
688 case InterpolationModeBilinear
:
689 left
= (INT
)(floorf(srcx
));
690 top
= (INT
)(floorf(srcy
));
691 right
= (INT
)(ceilf(srcx
+srcwidth
));
692 bottom
= (INT
)(ceilf(srcy
+srcheight
));
694 case InterpolationModeNearestNeighbor
:
698 right
= roundr(srcx
+srcwidth
);
699 bottom
= roundr(srcy
+srcheight
);
703 if (wrap
== WrapModeClamp
)
709 if (right
>= bitmap
->width
)
710 right
= bitmap
->width
-1;
711 if (bottom
>= bitmap
->height
)
712 bottom
= bitmap
->height
-1;
716 /* In some cases we can make the rectangle smaller here, but the logic
717 * is hard to get right, and tiling suggests we're likely to use the
718 * entire source image. */
719 if (left
< 0 || right
>= bitmap
->width
)
722 right
= bitmap
->width
-1;
725 if (top
< 0 || bottom
>= bitmap
->height
)
728 bottom
= bitmap
->height
-1;
734 rect
->Width
= right
- left
+ 1;
735 rect
->Height
= bottom
- top
+ 1;
738 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
739 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
741 if (attributes
->wrap
== WrapModeClamp
)
743 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
744 return attributes
->outside_color
;
748 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
750 x
= width
*2 + x
% (width
* 2);
752 y
= height
*2 + y
% (height
* 2);
754 if ((attributes
->wrap
& 1) == 1)
757 if ((x
/ width
) % 2 == 0)
760 x
= width
- 1 - x
% width
;
765 if ((attributes
->wrap
& 2) == 2)
768 if ((y
/ height
) % 2 == 0)
771 y
= height
- 1 - y
% height
;
777 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
779 ERR("out of range pixel requested\n");
783 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
786 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
787 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
788 InterpolationMode interpolation
)
792 switch (interpolation
)
796 FIXME("Unimplemented interpolation %i\n", interpolation
);
798 case InterpolationModeBilinear
:
801 INT leftx
, rightx
, topy
, bottomy
;
802 ARGB topleft
, topright
, bottomleft
, bottomright
;
806 leftxf
= floorf(point
->X
);
808 rightx
= (INT
)ceilf(point
->X
);
809 topyf
= floorf(point
->Y
);
811 bottomy
= (INT
)ceilf(point
->Y
);
813 if (leftx
== rightx
&& topy
== bottomy
)
814 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
815 leftx
, topy
, attributes
);
817 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
818 leftx
, topy
, attributes
);
819 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
820 rightx
, topy
, attributes
);
821 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
822 leftx
, bottomy
, attributes
);
823 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
824 rightx
, bottomy
, attributes
);
826 x_offset
= point
->X
- leftxf
;
827 top
= blend_colors(topleft
, topright
, x_offset
);
828 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
830 return blend_colors(top
, bottom
, point
->Y
- topyf
);
832 case InterpolationModeNearestNeighbor
:
833 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
834 roundr(point
->X
), roundr(point
->Y
), attributes
);
838 static INT
brush_can_fill_path(GpBrush
*brush
)
842 case BrushTypeSolidColor
:
844 case BrushTypeHatchFill
:
846 GpHatch
*hatch
= (GpHatch
*)brush
;
847 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
848 ((hatch
->backcol
& 0xff000000) == 0xff000000);
850 case BrushTypeLinearGradient
:
851 case BrushTypeTextureFill
:
852 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
858 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
862 case BrushTypeSolidColor
:
864 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
865 HBITMAP bmp
= ARGB2BMP(fill
->color
);
870 /* partially transparent fill */
872 SelectClipPath(graphics
->hdc
, RGN_AND
);
873 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
875 HDC hdc
= CreateCompatibleDC(NULL
);
879 SelectObject(hdc
, bmp
);
880 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
888 /* else fall through */
892 HBRUSH gdibrush
, old_brush
;
894 gdibrush
= create_gdi_brush(brush
);
895 if (!gdibrush
) return;
897 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
898 FillPath(graphics
->hdc
);
899 SelectObject(graphics
->hdc
, old_brush
);
900 DeleteObject(gdibrush
);
906 static INT
brush_can_fill_pixels(GpBrush
*brush
)
910 case BrushTypeSolidColor
:
911 case BrushTypeHatchFill
:
912 case BrushTypeLinearGradient
:
913 case BrushTypeTextureFill
:
920 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
921 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
925 case BrushTypeSolidColor
:
928 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
929 for (x
=0; x
<fill_area
->Width
; x
++)
930 for (y
=0; y
<fill_area
->Height
; y
++)
931 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
934 case BrushTypeHatchFill
:
937 GpHatch
*fill
= (GpHatch
*)brush
;
938 const char *hatch_data
;
940 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
941 return NotImplemented
;
943 for (x
=0; x
<fill_area
->Width
; x
++)
944 for (y
=0; y
<fill_area
->Height
; y
++)
948 /* FIXME: Account for the rendering origin */
949 hx
= (x
+ fill_area
->X
) % 8;
950 hy
= (y
+ fill_area
->Y
) % 8;
952 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
953 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
955 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
960 case BrushTypeLinearGradient
:
962 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
963 GpPointF draw_points
[3], line_points
[3];
965 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
966 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
969 draw_points
[0].X
= fill_area
->X
;
970 draw_points
[0].Y
= fill_area
->Y
;
971 draw_points
[1].X
= fill_area
->X
+1;
972 draw_points
[1].Y
= fill_area
->Y
;
973 draw_points
[2].X
= fill_area
->X
;
974 draw_points
[2].Y
= fill_area
->Y
+1;
976 /* Transform the points to a co-ordinate space where X is the point's
977 * position in the gradient, 0.0 being the start point and 1.0 the
979 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
980 CoordinateSpaceDevice
, draw_points
, 3);
984 line_points
[0] = fill
->startpoint
;
985 line_points
[1] = fill
->endpoint
;
986 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
987 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
989 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
994 stat
= GdipInvertMatrix(world_to_gradient
);
997 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
999 GdipDeleteMatrix(world_to_gradient
);
1004 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1005 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1007 for (y
=0; y
<fill_area
->Height
; y
++)
1009 for (x
=0; x
<fill_area
->Width
; x
++)
1011 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1013 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1020 case BrushTypeTextureFill
:
1022 GpTexture
*fill
= (GpTexture
*)brush
;
1023 GpPointF draw_points
[3];
1025 GpMatrix
*world_to_texture
;
1031 if (fill
->image
->type
!= ImageTypeBitmap
)
1033 FIXME("metafile texture brushes not implemented\n");
1034 return NotImplemented
;
1037 bitmap
= (GpBitmap
*)fill
->image
;
1038 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1040 src_area
.X
= src_area
.Y
= 0;
1041 src_area
.Width
= bitmap
->width
;
1042 src_area
.Height
= bitmap
->height
;
1044 draw_points
[0].X
= fill_area
->X
;
1045 draw_points
[0].Y
= fill_area
->Y
;
1046 draw_points
[1].X
= fill_area
->X
+1;
1047 draw_points
[1].Y
= fill_area
->Y
;
1048 draw_points
[2].X
= fill_area
->X
;
1049 draw_points
[2].Y
= fill_area
->Y
+1;
1051 /* Transform the points to the co-ordinate space of the bitmap. */
1052 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1053 CoordinateSpaceDevice
, draw_points
, 3);
1057 stat
= GdipCloneMatrix(fill
->transform
, &world_to_texture
);
1062 stat
= GdipInvertMatrix(world_to_texture
);
1065 stat
= GdipTransformMatrixPoints(world_to_texture
, draw_points
, 3);
1067 GdipDeleteMatrix(world_to_texture
);
1070 if (stat
== Ok
&& !fill
->bitmap_bits
)
1072 BitmapData lockeddata
;
1074 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1075 if (!fill
->bitmap_bits
)
1080 lockeddata
.Width
= bitmap
->width
;
1081 lockeddata
.Height
= bitmap
->height
;
1082 lockeddata
.Stride
= src_stride
;
1083 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1084 lockeddata
.Scan0
= fill
->bitmap_bits
;
1086 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1087 PixelFormat32bppARGB
, &lockeddata
);
1091 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1094 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1095 bitmap
->width
, bitmap
->height
,
1096 src_stride
, ColorAdjustTypeBitmap
);
1100 GdipFree(fill
->bitmap_bits
);
1101 fill
->bitmap_bits
= NULL
;
1107 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1108 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1109 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1110 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1112 for (y
=0; y
<fill_area
->Height
; y
++)
1114 for (x
=0; x
<fill_area
->Width
; x
++)
1117 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1118 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1120 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1121 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1122 &point
, fill
->imageattributes
, graphics
->interpolation
);
1130 return NotImplemented
;
1134 /* GdipDrawPie/GdipFillPie helper function */
1135 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
1136 REAL height
, REAL startAngle
, REAL sweepAngle
)
1143 ptf
[1].X
= x
+ width
;
1144 ptf
[1].Y
= y
+ height
;
1146 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
1147 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
1149 transform_and_round_points(graphics
, pti
, ptf
, 4);
1151 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
1152 pti
[2].y
, pti
[3].x
, pti
[3].y
);
1155 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1156 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1157 * should not be called on an hdc that has a path you care about. */
1158 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1159 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1161 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1162 GpMatrix
*matrix
= NULL
;
1163 HBRUSH brush
= NULL
;
1165 PointF ptf
[4], *custptf
= NULL
;
1166 POINT pt
[4], *custpt
= NULL
;
1168 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1173 if((x1
== x2
) && (y1
== y2
))
1176 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1178 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1180 brush
= CreateSolidBrush(color
);
1181 lb
.lbStyle
= BS_SOLID
;
1184 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1185 PS_JOIN_MITER
, 1, &lb
, 0,
1187 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1188 oldpen
= SelectObject(graphics
->hdc
, pen
);
1195 case LineCapSquareAnchor
:
1196 case LineCapDiamondAnchor
:
1197 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1198 if(cap
== LineCapDiamondAnchor
){
1199 dsmall
= cos(theta
+ M_PI_2
) * size
;
1200 dbig
= sin(theta
+ M_PI_2
) * size
;
1203 dsmall
= cos(theta
+ M_PI_4
) * size
;
1204 dbig
= sin(theta
+ M_PI_4
) * size
;
1207 ptf
[0].X
= x2
- dsmall
;
1208 ptf
[1].X
= x2
+ dbig
;
1210 ptf
[0].Y
= y2
- dbig
;
1211 ptf
[3].Y
= y2
+ dsmall
;
1213 ptf
[1].Y
= y2
- dsmall
;
1214 ptf
[2].Y
= y2
+ dbig
;
1216 ptf
[3].X
= x2
- dbig
;
1217 ptf
[2].X
= x2
+ dsmall
;
1219 transform_and_round_points(graphics
, pt
, ptf
, 4);
1220 Polygon(graphics
->hdc
, pt
, 4);
1223 case LineCapArrowAnchor
:
1224 size
= size
* 4.0 / sqrt(3.0);
1226 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1227 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1232 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1233 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1241 transform_and_round_points(graphics
, pt
, ptf
, 3);
1242 Polygon(graphics
->hdc
, pt
, 3);
1245 case LineCapRoundAnchor
:
1246 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1253 transform_and_round_points(graphics
, pt
, ptf
, 2);
1254 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1257 case LineCapTriangle
:
1259 dx
= cos(M_PI_2
+ theta
) * size
;
1260 dy
= sin(M_PI_2
+ theta
) * size
;
1267 dx
= cos(theta
) * size
;
1268 dy
= sin(theta
) * size
;
1273 transform_and_round_points(graphics
, pt
, ptf
, 3);
1274 Polygon(graphics
->hdc
, pt
, 3);
1278 dx
= dy
= size
/ 2.0;
1285 dx
= -cos(M_PI_2
+ theta
) * size
;
1286 dy
= -sin(M_PI_2
+ theta
) * size
;
1293 transform_and_round_points(graphics
, pt
, ptf
, 4);
1294 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1295 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1302 count
= custom
->pathdata
.Count
;
1303 custptf
= GdipAlloc(count
* sizeof(PointF
));
1304 custpt
= GdipAlloc(count
* sizeof(POINT
));
1305 tp
= GdipAlloc(count
);
1307 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
1310 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1312 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
1313 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1315 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
1316 GdipTransformMatrixPoints(matrix
, custptf
, count
);
1318 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1320 for(i
= 0; i
< count
; i
++)
1321 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1324 BeginPath(graphics
->hdc
);
1325 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1326 EndPath(graphics
->hdc
);
1327 StrokeAndFillPath(graphics
->hdc
);
1330 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1336 GdipDeleteMatrix(matrix
);
1343 SelectObject(graphics
->hdc
, oldbrush
);
1344 SelectObject(graphics
->hdc
, oldpen
);
1345 DeleteObject(brush
);
1350 /* Shortens the line by the given percent by changing x2, y2.
1351 * If percent is > 1.0 then the line will change direction.
1352 * If percent is negative it can lengthen the line. */
1353 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1355 REAL dist
, theta
, dx
, dy
;
1357 if((y1
== *y2
) && (x1
== *x2
))
1360 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1361 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1362 dx
= cos(theta
) * dist
;
1363 dy
= sin(theta
) * dist
;
1369 /* Shortens the line by the given amount by changing x2, y2.
1370 * If the amount is greater than the distance, the line will become length 0.
1371 * If the amount is negative, it can lengthen the line. */
1372 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1374 REAL dx
, dy
, percent
;
1378 if(dx
== 0 && dy
== 0)
1381 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1388 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1391 /* Draws lines between the given points, and if caps is true then draws an endcap
1392 * at the end of the last line. */
1393 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
1394 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1397 GpPointF
*ptcopy
= NULL
;
1398 GpStatus status
= GenericError
;
1403 pti
= GdipAlloc(count
* sizeof(POINT
));
1404 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1406 if(!pti
|| !ptcopy
){
1407 status
= OutOfMemory
;
1411 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1414 if(pen
->endcap
== LineCapArrowAnchor
)
1415 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1416 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
1417 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1418 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1419 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
1420 pen
->customend
->inset
* pen
->width
);
1422 if(pen
->startcap
== LineCapArrowAnchor
)
1423 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1424 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
1425 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1426 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1427 &ptcopy
[0].X
, &ptcopy
[0].Y
,
1428 pen
->customstart
->inset
* pen
->width
);
1430 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1431 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
1432 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1433 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
1436 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1438 if(Polyline(graphics
->hdc
, pti
, count
))
1448 /* Conducts a linear search to find the bezier points that will back off
1449 * the endpoint of the curve by a distance of amt. Linear search works
1450 * better than binary in this case because there are multiple solutions,
1451 * and binary searches often find a bad one. I don't think this is what
1452 * Windows does but short of rendering the bezier without GDI's help it's
1453 * the best we can do. If rev then work from the start of the passed points
1454 * instead of the end. */
1455 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1458 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1459 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1468 origx
= pt
[fourth
].X
;
1469 origy
= pt
[fourth
].Y
;
1470 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1472 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1473 /* reset bezier points to original values */
1474 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1475 /* Perform magic on bezier points. Order is important here.*/
1476 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1477 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1478 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1479 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1480 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1481 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1483 dx
= pt
[fourth
].X
- origx
;
1484 dy
= pt
[fourth
].Y
- origy
;
1486 diff
= sqrt(dx
* dx
+ dy
* dy
);
1487 percent
+= 0.0005 * amt
;
1491 /* Draws bezier curves between given points, and if caps is true then draws an
1492 * endcap at the end of the last line. */
1493 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
1494 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1498 GpStatus status
= GenericError
;
1503 pti
= GdipAlloc(count
* sizeof(POINT
));
1504 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1506 if(!pti
|| !ptcopy
){
1507 status
= OutOfMemory
;
1511 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1514 if(pen
->endcap
== LineCapArrowAnchor
)
1515 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
1516 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1517 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
1520 if(pen
->startcap
== LineCapArrowAnchor
)
1521 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
1522 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1523 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
1525 /* the direction of the line cap is parallel to the direction at the
1526 * end of the bezier (which, if it has been shortened, is not the same
1527 * as the direction from pt[count-2] to pt[count-1]) */
1528 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1529 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1530 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1531 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1533 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1534 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
1535 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
1538 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1540 PolyBezier(graphics
->hdc
, pti
, count
);
1551 /* Draws a combination of bezier curves and lines between points. */
1552 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1553 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1555 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1556 BYTE
*tp
= GdipAlloc(count
);
1557 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1559 GpStatus status
= GenericError
;
1565 if(!pti
|| !tp
|| !ptcopy
){
1566 status
= OutOfMemory
;
1570 for(i
= 1; i
< count
; i
++){
1571 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1572 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1573 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1574 ERR("Bad bezier points\n");
1581 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1583 /* If we are drawing caps, go through the points and adjust them accordingly,
1584 * and draw the caps. */
1586 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1587 case PathPointTypeBezier
:
1588 if(pen
->endcap
== LineCapArrowAnchor
)
1589 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1590 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1591 shorten_bezier_amt(&ptcopy
[count
- 4],
1592 pen
->width
* pen
->customend
->inset
, FALSE
);
1594 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1595 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1596 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1597 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1600 case PathPointTypeLine
:
1601 if(pen
->endcap
== LineCapArrowAnchor
)
1602 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1603 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1605 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1606 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1607 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1608 pen
->customend
->inset
* pen
->width
);
1610 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1611 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1616 ERR("Bad path last point\n");
1620 /* Find start of points */
1621 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1622 == PathPointTypeStart
); j
++);
1624 switch(types
[j
] & PathPointTypePathTypeMask
){
1625 case PathPointTypeBezier
:
1626 if(pen
->startcap
== LineCapArrowAnchor
)
1627 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1628 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1629 shorten_bezier_amt(&ptcopy
[j
- 1],
1630 pen
->width
* pen
->customstart
->inset
, TRUE
);
1632 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1633 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1634 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1635 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1638 case PathPointTypeLine
:
1639 if(pen
->startcap
== LineCapArrowAnchor
)
1640 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1641 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1643 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1644 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1645 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1646 pen
->customstart
->inset
* pen
->width
);
1648 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1649 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1654 ERR("Bad path points\n");
1659 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1661 for(i
= 0; i
< count
; i
++){
1662 tp
[i
] = convert_path_point_type(types
[i
]);
1665 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1677 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1681 BeginPath(graphics
->hdc
);
1682 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1683 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1684 EndPath(graphics
->hdc
);
1688 typedef struct _GraphicsContainerItem
{
1690 GraphicsContainer contid
;
1692 SmoothingMode smoothing
;
1693 CompositingQuality compqual
;
1694 InterpolationMode interpolation
;
1695 CompositingMode compmode
;
1696 TextRenderingHint texthint
;
1699 PixelOffsetMode pixeloffset
;
1701 GpMatrix
* worldtrans
;
1703 } GraphicsContainerItem
;
1705 static GpStatus
init_container(GraphicsContainerItem
** container
,
1706 GDIPCONST GpGraphics
* graphics
){
1709 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1713 (*container
)->contid
= graphics
->contid
+ 1;
1715 (*container
)->smoothing
= graphics
->smoothing
;
1716 (*container
)->compqual
= graphics
->compqual
;
1717 (*container
)->interpolation
= graphics
->interpolation
;
1718 (*container
)->compmode
= graphics
->compmode
;
1719 (*container
)->texthint
= graphics
->texthint
;
1720 (*container
)->scale
= graphics
->scale
;
1721 (*container
)->unit
= graphics
->unit
;
1722 (*container
)->textcontrast
= graphics
->textcontrast
;
1723 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1725 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1727 GdipFree(*container
);
1732 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1734 GdipDeleteMatrix((*container
)->worldtrans
);
1735 GdipFree(*container
);
1743 static void delete_container(GraphicsContainerItem
* container
){
1744 GdipDeleteMatrix(container
->worldtrans
);
1745 GdipDeleteRegion(container
->clip
);
1746 GdipFree(container
);
1749 static GpStatus
restore_container(GpGraphics
* graphics
,
1750 GDIPCONST GraphicsContainerItem
* container
){
1755 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1759 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1761 GdipDeleteMatrix(newTrans
);
1765 GdipDeleteMatrix(graphics
->worldtrans
);
1766 graphics
->worldtrans
= newTrans
;
1768 GdipDeleteRegion(graphics
->clip
);
1769 graphics
->clip
= newClip
;
1771 graphics
->contid
= container
->contid
- 1;
1773 graphics
->smoothing
= container
->smoothing
;
1774 graphics
->compqual
= container
->compqual
;
1775 graphics
->interpolation
= container
->interpolation
;
1776 graphics
->compmode
= container
->compmode
;
1777 graphics
->texthint
= container
->texthint
;
1778 graphics
->scale
= container
->scale
;
1779 graphics
->unit
= container
->unit
;
1780 graphics
->textcontrast
= container
->textcontrast
;
1781 graphics
->pixeloffset
= container
->pixeloffset
;
1786 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1792 if(graphics
->hwnd
) {
1793 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1794 return GenericError
;
1796 rect
->X
= wnd_rect
.left
;
1797 rect
->Y
= wnd_rect
.top
;
1798 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1799 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1800 }else if (graphics
->image
){
1801 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1802 if (stat
== Ok
&& unit
!= UnitPixel
)
1803 FIXME("need to convert from unit %i\n", unit
);
1807 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1808 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
1814 /* on success, rgn will contain the region of the graphics object which
1815 * is visible after clipping has been applied */
1816 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
1822 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
1825 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
1828 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
1831 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
1834 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
1837 GdipDeleteRegion(tmp
);
1841 void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
, HFONT
*hfont
)
1843 HDC hdc
= CreateCompatibleDC(0);
1845 REAL angle
, rel_width
, rel_height
;
1847 HFONT unscaled_font
;
1848 TEXTMETRICW textmet
;
1857 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
1858 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
1859 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
1860 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
1861 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
1862 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
1865 lfw
.lfHeight
= roundr(-font
->pixel_size
* rel_height
);
1866 unscaled_font
= CreateFontIndirectW(&lfw
);
1868 SelectObject(hdc
, unscaled_font
);
1869 GetTextMetricsW(hdc
, &textmet
);
1872 lfw
.lfHeight
= roundr(-font
->pixel_size
* rel_height
);
1873 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
1874 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
1876 *hfont
= CreateFontIndirectW(&lfw
);
1879 DeleteObject(unscaled_font
);
1882 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1884 TRACE("(%p, %p)\n", hdc
, graphics
);
1886 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1889 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1893 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1895 if(hDevice
!= NULL
) {
1896 FIXME("Don't know how to handle parameter hDevice\n");
1897 return NotImplemented
;
1903 if(graphics
== NULL
)
1904 return InvalidParameter
;
1906 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1907 if(!*graphics
) return OutOfMemory
;
1909 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1910 GdipFree(*graphics
);
1914 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1915 GdipFree((*graphics
)->worldtrans
);
1916 GdipFree(*graphics
);
1920 (*graphics
)->hdc
= hdc
;
1921 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1922 (*graphics
)->owndc
= FALSE
;
1923 (*graphics
)->smoothing
= SmoothingModeDefault
;
1924 (*graphics
)->compqual
= CompositingQualityDefault
;
1925 (*graphics
)->interpolation
= InterpolationModeBilinear
;
1926 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1927 (*graphics
)->compmode
= CompositingModeSourceOver
;
1928 (*graphics
)->unit
= UnitDisplay
;
1929 (*graphics
)->scale
= 1.0;
1930 (*graphics
)->busy
= FALSE
;
1931 (*graphics
)->textcontrast
= 4;
1932 list_init(&(*graphics
)->containers
);
1933 (*graphics
)->contid
= 0;
1935 TRACE("<-- %p\n", *graphics
);
1940 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
1944 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1945 if(!*graphics
) return OutOfMemory
;
1947 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1948 GdipFree(*graphics
);
1952 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1953 GdipFree((*graphics
)->worldtrans
);
1954 GdipFree(*graphics
);
1958 (*graphics
)->hdc
= NULL
;
1959 (*graphics
)->hwnd
= NULL
;
1960 (*graphics
)->owndc
= FALSE
;
1961 (*graphics
)->image
= image
;
1962 (*graphics
)->smoothing
= SmoothingModeDefault
;
1963 (*graphics
)->compqual
= CompositingQualityDefault
;
1964 (*graphics
)->interpolation
= InterpolationModeBilinear
;
1965 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1966 (*graphics
)->compmode
= CompositingModeSourceOver
;
1967 (*graphics
)->unit
= UnitDisplay
;
1968 (*graphics
)->scale
= 1.0;
1969 (*graphics
)->busy
= FALSE
;
1970 (*graphics
)->textcontrast
= 4;
1971 list_init(&(*graphics
)->containers
);
1972 (*graphics
)->contid
= 0;
1974 TRACE("<-- %p\n", *graphics
);
1979 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1984 TRACE("(%p, %p)\n", hwnd
, graphics
);
1988 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1990 ReleaseDC(hwnd
, hdc
);
1994 (*graphics
)->hwnd
= hwnd
;
1995 (*graphics
)->owndc
= TRUE
;
2000 /* FIXME: no icm handling */
2001 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2003 TRACE("(%p, %p)\n", hwnd
, graphics
);
2005 return GdipCreateFromHWND(hwnd
, graphics
);
2008 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2009 GpMetafile
**metafile
)
2013 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2015 if(!hemf
|| !metafile
)
2016 return InvalidParameter
;
2019 FIXME("not implemented\n");
2021 return NotImplemented
;
2024 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2025 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2027 IStream
*stream
= NULL
;
2031 GpStatus retval
= Ok
;
2033 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2035 if(!hwmf
|| !metafile
|| !placeable
)
2036 return InvalidParameter
;
2039 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2041 return GenericError
;
2042 copy
= GdipAlloc(read
);
2043 GetMetaFileBitsEx(hwmf
, read
, copy
);
2045 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2048 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
2049 copy
= GdipAlloc(read
);
2050 GetEnhMetaFileBits(hemf
, read
, copy
);
2051 DeleteEnhMetaFile(hemf
);
2053 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
2054 ERR("could not make stream\n");
2056 retval
= GenericError
;
2060 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2062 retval
= OutOfMemory
;
2066 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
2067 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
2069 retval
= GenericError
;
2074 (*metafile
)->image
.type
= ImageTypeMetafile
;
2075 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
2076 (*metafile
)->image
.palette_flags
= 0;
2077 (*metafile
)->image
.palette_count
= 0;
2078 (*metafile
)->image
.palette_size
= 0;
2079 (*metafile
)->image
.palette_entries
= NULL
;
2080 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2081 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2082 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
2083 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Top
) / ((REAL
) placeable
->Inch
);
2084 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
2085 - placeable
->BoundingBox
.Left
));
2086 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
2087 - placeable
->BoundingBox
.Top
));
2088 (*metafile
)->unit
= UnitPixel
;
2091 DeleteMetaFile(hwmf
);
2093 TRACE("<-- %p\n", *metafile
);
2097 GdipFree(*metafile
);
2098 IStream_Release(stream
);
2102 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2103 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2105 HMETAFILE hmf
= GetMetaFileW(file
);
2107 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2109 if(!hmf
) return InvalidParameter
;
2111 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2114 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2115 GpMetafile
**metafile
)
2117 FIXME("(%p, %p): stub\n", file
, metafile
);
2118 return NotImplemented
;
2121 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2122 GpMetafile
**metafile
)
2124 FIXME("(%p, %p): stub\n", stream
, metafile
);
2125 return NotImplemented
;
2128 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2129 UINT access
, IStream
**stream
)
2134 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2136 if(!stream
|| !filename
)
2137 return InvalidParameter
;
2139 if(access
& GENERIC_WRITE
)
2140 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2141 else if(access
& GENERIC_READ
)
2142 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2144 return InvalidParameter
;
2146 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2148 return hresult_to_status(ret
);
2151 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2153 GraphicsContainerItem
*cont
, *next
;
2155 TRACE("(%p)\n", graphics
);
2157 if(!graphics
) return InvalidParameter
;
2158 if(graphics
->busy
) return ObjectBusy
;
2160 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2162 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2168 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2170 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2171 list_remove(&cont
->entry
);
2172 delete_container(cont
);
2175 GdipDeleteRegion(graphics
->clip
);
2176 GdipDeleteMatrix(graphics
->worldtrans
);
2182 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2183 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2185 INT save_state
, num_pts
;
2186 GpPointF points
[MAX_ARC_PTS
];
2189 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2190 width
, height
, startAngle
, sweepAngle
);
2192 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2193 return InvalidParameter
;
2200 FIXME("graphics object has no HDC\n");
2204 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2206 save_state
= prepare_dc(graphics
, pen
);
2208 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
2210 restore_dc(graphics
, save_state
);
2215 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2216 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2218 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2219 width
, height
, startAngle
, sweepAngle
);
2221 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2224 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2225 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2231 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2232 x2
, y2
, x3
, y3
, x4
, y4
);
2234 if(!graphics
|| !pen
)
2235 return InvalidParameter
;
2242 FIXME("graphics object has no HDC\n");
2255 save_state
= prepare_dc(graphics
, pen
);
2257 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2259 restore_dc(graphics
, save_state
);
2264 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2265 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2271 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2272 x2
, y2
, x3
, y3
, x4
, y4
);
2274 if(!graphics
|| !pen
)
2275 return InvalidParameter
;
2282 FIXME("graphics object has no HDC\n");
2295 save_state
= prepare_dc(graphics
, pen
);
2297 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2299 restore_dc(graphics
, save_state
);
2304 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2305 GDIPCONST GpPointF
*points
, INT count
)
2310 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2312 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2313 return InvalidParameter
;
2318 for(i
= 0; i
< floor(count
/ 4); i
++){
2319 ret
= GdipDrawBezier(graphics
, pen
,
2320 points
[4*i
].X
, points
[4*i
].Y
,
2321 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
2322 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
2323 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
2331 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2332 GDIPCONST GpPoint
*points
, INT count
)
2338 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2340 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2341 return InvalidParameter
;
2346 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2350 for(i
= 0; i
< count
; i
++){
2351 pts
[i
].X
= (REAL
)points
[i
].X
;
2352 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2355 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2362 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2363 GDIPCONST GpPointF
*points
, INT count
)
2365 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2367 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2370 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2371 GDIPCONST GpPoint
*points
, INT count
)
2373 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2375 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2378 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2379 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2384 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2386 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2387 return InvalidParameter
;
2392 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
2395 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2397 GdipDeletePath(path
);
2401 stat
= GdipDrawPath(graphics
, pen
, path
);
2403 GdipDeletePath(path
);
2408 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2409 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2415 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2417 if(!points
|| count
<= 0)
2418 return InvalidParameter
;
2420 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2424 for(i
= 0; i
< count
; i
++){
2425 ptf
[i
].X
= (REAL
)points
[i
].X
;
2426 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2429 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2436 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2437 GDIPCONST GpPointF
*points
, INT count
)
2439 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2441 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2444 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2445 GDIPCONST GpPoint
*points
, INT count
)
2451 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2454 return InvalidParameter
;
2456 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2460 for(i
= 0; i
< count
; i
++){
2461 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2462 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2465 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2471 /* Approximates cardinal spline with Bezier curves. */
2472 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2473 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2475 /* PolyBezier expects count*3-2 points. */
2476 INT i
, len_pt
= count
*3-2, save_state
;
2478 REAL x1
, x2
, y1
, y2
;
2481 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2483 if(!graphics
|| !pen
)
2484 return InvalidParameter
;
2490 return InvalidParameter
;
2494 FIXME("graphics object has no HDC\n");
2498 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
2502 tension
= tension
* TENSION_CONST
;
2504 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
2507 pt
[0].X
= points
[0].X
;
2508 pt
[0].Y
= points
[0].Y
;
2512 for(i
= 0; i
< count
-2; i
++){
2513 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
2517 pt
[3*i
+3].X
= points
[i
+1].X
;
2518 pt
[3*i
+3].Y
= points
[i
+1].Y
;
2523 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
2524 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
2526 pt
[len_pt
-2].X
= x1
;
2527 pt
[len_pt
-2].Y
= y1
;
2528 pt
[len_pt
-1].X
= points
[count
-1].X
;
2529 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
2531 save_state
= prepare_dc(graphics
, pen
);
2533 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
2536 restore_dc(graphics
, save_state
);
2541 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2542 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2548 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2551 return InvalidParameter
;
2553 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2557 for(i
= 0; i
< count
; i
++){
2558 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2559 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2562 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2568 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2569 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2572 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2574 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2575 return InvalidParameter
;
2578 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2581 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2582 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2585 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2591 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2592 return InvalidParameter
;
2595 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2598 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2599 REAL y
, REAL width
, REAL height
)
2605 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2607 if(!graphics
|| !pen
)
2608 return InvalidParameter
;
2615 FIXME("graphics object has no HDC\n");
2621 ptf
[1].X
= x
+ width
;
2622 ptf
[1].Y
= y
+ height
;
2624 save_state
= prepare_dc(graphics
, pen
);
2625 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2627 transform_and_round_points(graphics
, pti
, ptf
, 2);
2629 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2631 restore_dc(graphics
, save_state
);
2636 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2637 INT y
, INT width
, INT height
)
2639 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2641 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2645 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2650 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2652 if(!graphics
|| !image
)
2653 return InvalidParameter
;
2655 GdipGetImageWidth(image
, &width
);
2656 GdipGetImageHeight(image
, &height
);
2658 /* FIXME: we should use the graphics and image dpi, somehow */
2660 points
[0].X
= points
[2].X
= x
;
2661 points
[0].Y
= points
[1].Y
= y
;
2662 points
[1].X
= x
+ width
;
2663 points
[2].Y
= y
+ height
;
2665 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
2666 UnitPixel
, NULL
, NULL
, NULL
);
2669 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2672 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2674 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2677 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2678 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2682 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2684 points
[0].X
= points
[2].X
= x
;
2685 points
[0].Y
= points
[1].Y
= y
;
2687 /* FIXME: convert image coordinates to Graphics coordinates? */
2688 points
[1].X
= x
+ srcwidth
;
2689 points
[2].Y
= y
+ srcheight
;
2691 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2692 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2695 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2696 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2699 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2702 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2703 GDIPCONST GpPointF
*dstpoints
, INT count
)
2707 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2710 return InvalidParameter
;
2712 GdipGetImageWidth(image
, &width
);
2713 GdipGetImageHeight(image
, &height
);
2715 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2716 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2719 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2720 GDIPCONST GpPoint
*dstpoints
, INT count
)
2724 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2726 if (count
!= 3 || !dstpoints
)
2727 return InvalidParameter
;
2729 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2730 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2731 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2732 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2733 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2734 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2736 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2739 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2740 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2741 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2742 DrawImageAbort callback
, VOID
* callbackData
)
2749 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2750 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2754 return NotImplemented
;
2756 if(!graphics
|| !image
|| !points
|| count
!= 3)
2757 return InvalidParameter
;
2759 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2760 debugstr_pointf(&points
[2]));
2762 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2763 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2764 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2765 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
2767 transform_and_round_points(graphics
, pti
, ptf
, 4);
2773 FIXME("graphics object has no HDC\n");
2776 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2777 if(srcUnit
== UnitInch
)
2778 dx
= dy
= (REAL
) INCH_HIMETRIC
;
2779 else if(srcUnit
== UnitPixel
){
2780 dx
= ((REAL
) INCH_HIMETRIC
) /
2781 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
2782 dy
= ((REAL
) INCH_HIMETRIC
) /
2783 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
2786 return NotImplemented
;
2788 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2789 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2790 srcx
* dx
, srcy
* dy
,
2791 srcwidth
* dx
, srcheight
* dy
,
2794 callback(callbackData
);
2795 return GenericError
;
2798 else if (image
->type
== ImageTypeBitmap
)
2800 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2803 if (srcUnit
== UnitInch
)
2804 dx
= dy
= 96.0; /* FIXME: use the image resolution */
2805 else if (srcUnit
== UnitPixel
)
2808 return NotImplemented
;
2812 srcwidth
= srcwidth
* dx
;
2813 srcheight
= srcheight
* dy
;
2815 if (imageAttributes
||
2816 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2817 !((GpBitmap
*)image
)->hbitmap
||
2818 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2819 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2820 srcx
< 0 || srcy
< 0 ||
2821 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2828 int i
, x
, y
, src_stride
, dst_stride
;
2829 GpMatrix
*dst_to_src
;
2830 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2831 LPBYTE src_data
, dst_data
;
2832 BitmapData lockeddata
;
2833 InterpolationMode interpolation
= graphics
->interpolation
;
2834 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2835 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2836 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2838 if (!imageAttributes
)
2839 imageAttributes
= &defaultImageAttributes
;
2841 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2842 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2845 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2846 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2847 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2848 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2851 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2852 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2853 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2854 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2855 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2856 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2858 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
2859 if (stat
!= Ok
) return stat
;
2861 stat
= GdipInvertMatrix(dst_to_src
);
2864 GdipDeleteMatrix(dst_to_src
);
2868 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2871 GdipDeleteMatrix(dst_to_src
);
2875 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2877 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2878 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2880 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
2884 GdipDeleteMatrix(dst_to_src
);
2887 src_stride
= sizeof(ARGB
) * src_area
.Width
;
2889 /* Read the bits we need from the source bitmap into an ARGB buffer. */
2890 lockeddata
.Width
= src_area
.Width
;
2891 lockeddata
.Height
= src_area
.Height
;
2892 lockeddata
.Stride
= src_stride
;
2893 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
2894 lockeddata
.Scan0
= src_data
;
2896 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
2897 PixelFormat32bppARGB
, &lockeddata
);
2900 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2904 if (src_data
!= dst_data
)
2907 GdipDeleteMatrix(dst_to_src
);
2911 apply_image_attributes(imageAttributes
, src_data
,
2912 src_area
.Width
, src_area
.Height
,
2913 src_stride
, ColorAdjustTypeBitmap
);
2915 /* Transform the bits as needed to the destination. */
2916 GdipTransformMatrixPoints(dst_to_src
, dst_to_src_points
, 3);
2918 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
2919 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
2920 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
2921 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
2923 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2925 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2927 GpPointF src_pointf
;
2930 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
2931 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
2933 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2935 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
2936 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
, imageAttributes
, interpolation
);
2942 GdipDeleteMatrix(dst_to_src
);
2946 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
2947 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
2956 int temp_hdc
=0, temp_bitmap
=0;
2957 HBITMAP hbitmap
, old_hbm
=NULL
;
2959 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
2960 bitmap
->format
== PixelFormat24bppRGB
||
2961 bitmap
->format
== PixelFormat32bppRGB
||
2962 bitmap
->format
== PixelFormat32bppPARGB
))
2964 BITMAPINFOHEADER bih
;
2966 PixelFormat dst_format
;
2968 /* we can't draw a bitmap of this format directly */
2969 hdc
= CreateCompatibleDC(0);
2973 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
2974 bih
.biWidth
= bitmap
->width
;
2975 bih
.biHeight
= -bitmap
->height
;
2977 bih
.biBitCount
= 32;
2978 bih
.biCompression
= BI_RGB
;
2979 bih
.biSizeImage
= 0;
2980 bih
.biXPelsPerMeter
= 0;
2981 bih
.biYPelsPerMeter
= 0;
2983 bih
.biClrImportant
= 0;
2985 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
2986 (void**)&temp_bits
, NULL
, 0);
2988 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2989 dst_format
= PixelFormat32bppPARGB
;
2991 dst_format
= PixelFormat32bppRGB
;
2993 convert_pixels(bitmap
->width
, bitmap
->height
,
2994 bitmap
->width
*4, temp_bits
, dst_format
,
2995 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
2999 hbitmap
= bitmap
->hbitmap
;
3001 temp_hdc
= (hdc
== 0);
3006 if (!hdc
) hdc
= CreateCompatibleDC(0);
3007 old_hbm
= SelectObject(hdc
, hbitmap
);
3010 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3012 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3013 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3017 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3018 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3023 SelectObject(hdc
, old_hbm
);
3028 DeleteObject(hbitmap
);
3033 ERR("GpImage with no IPicture or HBITMAP?!\n");
3034 return NotImplemented
;
3040 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3041 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3042 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3043 DrawImageAbort callback
, VOID
* callbackData
)
3045 GpPointF pointsF
[3];
3048 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3049 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3052 if(!points
|| count
!=3)
3053 return InvalidParameter
;
3055 for(i
= 0; i
< count
; i
++){
3056 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3057 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3060 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3061 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3062 callback
, callbackData
);
3065 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3066 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3067 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3068 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3069 VOID
* callbackData
)
3073 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3074 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3075 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3079 points
[1].X
= dstx
+ dstwidth
;
3082 points
[2].Y
= dsty
+ dstheight
;
3084 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3085 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3088 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3089 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3090 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3091 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3092 VOID
* callbackData
)
3096 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3097 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3098 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3102 points
[1].X
= dstx
+ dstwidth
;
3105 points
[2].Y
= dsty
+ dstheight
;
3107 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3108 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3111 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3112 REAL x
, REAL y
, REAL width
, REAL height
)
3118 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3120 if(!graphics
|| !image
)
3121 return InvalidParameter
;
3123 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3127 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3128 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3129 unit
, NULL
, NULL
, NULL
);
3132 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3133 INT x
, INT y
, INT width
, INT height
)
3135 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3137 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3140 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3141 REAL y1
, REAL x2
, REAL y2
)
3147 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3149 if(!pen
|| !graphics
)
3150 return InvalidParameter
;
3157 FIXME("graphics object has no HDC\n");
3166 save_state
= prepare_dc(graphics
, pen
);
3168 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3170 restore_dc(graphics
, save_state
);
3175 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3176 INT y1
, INT x2
, INT y2
)
3182 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3184 if(!pen
|| !graphics
)
3185 return InvalidParameter
;
3192 FIXME("graphics object has no HDC\n");
3201 save_state
= prepare_dc(graphics
, pen
);
3203 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3205 restore_dc(graphics
, save_state
);
3210 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3211 GpPointF
*points
, INT count
)
3216 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3218 if(!pen
|| !graphics
|| (count
< 2))
3219 return InvalidParameter
;
3226 FIXME("graphics object has no HDC\n");
3230 save_state
= prepare_dc(graphics
, pen
);
3232 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
3234 restore_dc(graphics
, save_state
);
3239 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3240 GpPoint
*points
, INT count
)
3244 GpPointF
*ptf
= NULL
;
3247 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3249 if(!pen
|| !graphics
|| (count
< 2))
3250 return InvalidParameter
;
3257 FIXME("graphics object has no HDC\n");
3261 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3262 if(!ptf
) return OutOfMemory
;
3264 for(i
= 0; i
< count
; i
++){
3265 ptf
[i
].X
= (REAL
) points
[i
].X
;
3266 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3269 save_state
= prepare_dc(graphics
, pen
);
3271 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
3273 restore_dc(graphics
, save_state
);
3279 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3284 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3286 if(!pen
|| !graphics
)
3287 return InvalidParameter
;
3294 FIXME("graphics object has no HDC\n");
3298 save_state
= prepare_dc(graphics
, pen
);
3300 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3301 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3303 restore_dc(graphics
, save_state
);
3308 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3309 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3313 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3314 width
, height
, startAngle
, sweepAngle
);
3316 if(!graphics
|| !pen
)
3317 return InvalidParameter
;
3324 FIXME("graphics object has no HDC\n");
3328 save_state
= prepare_dc(graphics
, pen
);
3329 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3331 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3333 restore_dc(graphics
, save_state
);
3338 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3339 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3341 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3342 width
, height
, startAngle
, sweepAngle
);
3344 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3347 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3348 REAL y
, REAL width
, REAL height
)
3354 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3356 if(!pen
|| !graphics
)
3357 return InvalidParameter
;
3364 FIXME("graphics object has no HDC\n");
3370 ptf
[1].X
= x
+ width
;
3372 ptf
[2].X
= x
+ width
;
3373 ptf
[2].Y
= y
+ height
;
3375 ptf
[3].Y
= y
+ height
;
3377 save_state
= prepare_dc(graphics
, pen
);
3378 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3380 transform_and_round_points(graphics
, pti
, ptf
, 4);
3381 Polygon(graphics
->hdc
, pti
, 4);
3383 restore_dc(graphics
, save_state
);
3388 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3389 INT y
, INT width
, INT height
)
3391 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3393 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3396 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3397 GDIPCONST GpRectF
* rects
, INT count
)
3403 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3405 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3406 return InvalidParameter
;
3413 FIXME("graphics object has no HDC\n");
3417 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
3418 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
3426 for(i
= 0; i
< count
; i
++){
3427 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
3428 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
3429 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
3430 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
3433 save_state
= prepare_dc(graphics
, pen
);
3434 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3436 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
3438 for(i
= 0; i
< count
; i
++)
3439 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
3441 restore_dc(graphics
, save_state
);
3449 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3450 GDIPCONST GpRect
* rects
, INT count
)
3456 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3458 if(!rects
|| count
<=0)
3459 return InvalidParameter
;
3461 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3465 for(i
= 0;i
< count
;i
++){
3466 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3467 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3468 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3469 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3472 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3478 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3479 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3484 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3485 count
, tension
, fill
);
3487 if(!graphics
|| !brush
|| !points
)
3488 return InvalidParameter
;
3493 if(count
== 1) /* Do nothing */
3496 stat
= GdipCreatePath(fill
, &path
);
3500 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3502 GdipDeletePath(path
);
3506 stat
= GdipFillPath(graphics
, brush
, path
);
3508 GdipDeletePath(path
);
3512 GdipDeletePath(path
);
3517 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3518 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3524 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3525 count
, tension
, fill
);
3527 if(!points
|| count
== 0)
3528 return InvalidParameter
;
3530 if(count
== 1) /* Do nothing */
3533 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3537 for(i
= 0;i
< count
;i
++){
3538 ptf
[i
].X
= (REAL
)points
[i
].X
;
3539 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3542 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3549 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3550 GDIPCONST GpPointF
*points
, INT count
)
3552 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3553 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3554 0.5f
, FillModeAlternate
);
3557 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3558 GDIPCONST GpPoint
*points
, INT count
)
3560 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3561 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3562 0.5f
, FillModeAlternate
);
3565 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3566 REAL y
, REAL width
, REAL height
)
3571 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3573 if(!graphics
|| !brush
)
3574 return InvalidParameter
;
3579 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3583 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3586 stat
= GdipFillPath(graphics
, brush
, path
);
3588 GdipDeletePath(path
);
3594 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3595 INT y
, INT width
, INT height
)
3597 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3599 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3602 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3607 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3608 return NotImplemented
;
3610 save_state
= SaveDC(graphics
->hdc
);
3611 EndPath(graphics
->hdc
);
3612 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3615 BeginPath(graphics
->hdc
);
3616 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3617 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3622 EndPath(graphics
->hdc
);
3623 brush_fill_path(graphics
, brush
);
3628 RestoreDC(graphics
->hdc
, save_state
);
3633 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3638 if (!brush_can_fill_pixels(brush
))
3639 return NotImplemented
;
3641 /* FIXME: This could probably be done more efficiently without regions. */
3643 stat
= GdipCreateRegionPath(path
, &rgn
);
3647 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3649 GdipDeleteRegion(rgn
);
3655 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3657 GpStatus stat
= NotImplemented
;
3659 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3661 if(!brush
|| !graphics
|| !path
)
3662 return InvalidParameter
;
3667 if (!graphics
->image
)
3668 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3670 if (stat
== NotImplemented
)
3671 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3673 if (stat
== NotImplemented
)
3675 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3682 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3683 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3688 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3689 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3691 if(!graphics
|| !brush
)
3692 return InvalidParameter
;
3697 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3701 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3704 stat
= GdipFillPath(graphics
, brush
, path
);
3706 GdipDeletePath(path
);
3712 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3713 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3715 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3716 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3718 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3721 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3722 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3727 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3729 if(!graphics
|| !brush
|| !points
|| !count
)
3730 return InvalidParameter
;
3735 stat
= GdipCreatePath(fillMode
, &path
);
3739 stat
= GdipAddPathPolygon(path
, points
, count
);
3742 stat
= GdipFillPath(graphics
, brush
, path
);
3744 GdipDeletePath(path
);
3750 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3751 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3756 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3758 if(!graphics
|| !brush
|| !points
|| !count
)
3759 return InvalidParameter
;
3764 stat
= GdipCreatePath(fillMode
, &path
);
3768 stat
= GdipAddPathPolygonI(path
, points
, count
);
3771 stat
= GdipFillPath(graphics
, brush
, path
);
3773 GdipDeletePath(path
);
3779 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3780 GDIPCONST GpPointF
*points
, INT count
)
3782 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3784 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3787 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3788 GDIPCONST GpPoint
*points
, INT count
)
3790 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3792 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3795 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3796 REAL x
, REAL y
, REAL width
, REAL height
)
3801 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3803 if(!graphics
|| !brush
)
3804 return InvalidParameter
;
3809 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3813 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3816 stat
= GdipFillPath(graphics
, brush
, path
);
3818 GdipDeletePath(path
);
3824 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3825 INT x
, INT y
, INT width
, INT height
)
3827 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3829 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
3832 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3838 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3841 return InvalidParameter
;
3843 for(i
= 0; i
< count
; i
++){
3844 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
3845 if(ret
!= Ok
) return ret
;
3851 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3858 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3860 if(!rects
|| count
<= 0)
3861 return InvalidParameter
;
3863 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3867 for(i
= 0; i
< count
; i
++){
3868 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3869 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3870 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3871 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3874 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3880 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3888 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3889 return NotImplemented
;
3891 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3895 save_state
= SaveDC(graphics
->hdc
);
3896 EndPath(graphics
->hdc
);
3898 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3900 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3902 BeginPath(graphics
->hdc
);
3903 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3904 EndPath(graphics
->hdc
);
3906 brush_fill_path(graphics
, brush
);
3909 RestoreDC(graphics
->hdc
, save_state
);
3916 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3920 GpRegion
*temp_region
;
3921 GpMatrix
*world_to_device
, *identity
;
3922 GpRectF graphics_bounds
;
3923 UINT scans_count
, i
;
3925 GpRect
*scans
= NULL
;
3928 if (!brush_can_fill_pixels(brush
))
3929 return NotImplemented
;
3931 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3934 stat
= GdipCloneRegion(region
, &temp_region
);
3938 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3939 CoordinateSpaceWorld
, &world_to_device
);
3943 stat
= GdipTransformRegion(temp_region
, world_to_device
);
3945 GdipDeleteMatrix(world_to_device
);
3949 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
3952 stat
= GdipCreateMatrix(&identity
);
3956 stat
= GdipGetRegionScansCount(temp_region
, &scans_count
, identity
);
3958 if (stat
== Ok
&& scans_count
!= 0)
3960 scans
= GdipAlloc(sizeof(*scans
) * scans_count
);
3966 stat
= GdipGetRegionScansI(temp_region
, scans
, &dummy
, identity
);
3973 GdipDeleteMatrix(identity
);
3976 GdipDeleteRegion(temp_region
);
3979 if (stat
== Ok
&& scans_count
== 0)
3984 if (!graphics
->image
)
3986 /* If we have to go through gdi32, use as few alpha blends as possible. */
3987 INT min_x
, min_y
, max_x
, max_y
;
3988 UINT data_width
, data_height
;
3992 max_x
= scans
[0].X
+scans
[0].Width
;
3993 max_y
= scans
[0].Y
+scans
[0].Height
;
3995 for (i
=1; i
<scans_count
; i
++)
3997 min_x
= min(min_x
, scans
[i
].X
);
3998 min_y
= min(min_y
, scans
[i
].Y
);
3999 max_x
= max(max_x
, scans
[i
].X
+scans
[i
].Width
);
4000 max_y
= max(max_y
, scans
[i
].Y
+scans
[i
].Height
);
4003 data_width
= max_x
- min_x
;
4004 data_height
= max_y
- min_y
;
4006 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * data_width
* data_height
);
4012 for (i
=0; i
<scans_count
; i
++)
4014 stat
= brush_fill_pixels(graphics
, brush
,
4015 pixel_data
+ (scans
[i
].X
- min_x
) + (scans
[i
].Y
- min_y
) * data_width
,
4016 &scans
[i
], data_width
);
4024 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
,
4025 (BYTE
*)pixel_data
, data_width
, data_height
,
4029 GdipFree(pixel_data
);
4036 for (i
=0; i
<scans_count
; i
++)
4038 UINT size
= scans
[i
].Width
* scans
[i
].Height
;
4040 if (size
> max_size
)
4044 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * max_size
);
4050 for (i
=0; i
<scans_count
; i
++)
4052 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
, &scans
[i
],
4057 stat
= alpha_blend_pixels(graphics
, scans
[i
].X
, scans
[i
].Y
,
4058 (BYTE
*)pixel_data
, scans
[i
].Width
, scans
[i
].Height
,
4059 scans
[i
].Width
* 4);
4066 GdipFree(pixel_data
);
4076 /*****************************************************************************
4077 * GdipFillRegion [GDIPLUS.@]
4079 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4082 GpStatus stat
= NotImplemented
;
4084 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4086 if (!(graphics
&& brush
&& region
))
4087 return InvalidParameter
;
4092 if (!graphics
->image
)
4093 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4095 if (stat
== NotImplemented
)
4096 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4098 if (stat
== NotImplemented
)
4100 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4107 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4109 TRACE("(%p,%u)\n", graphics
, intention
);
4112 return InvalidParameter
;
4117 /* We have no internal operation queue, so there's no need to clear it. */
4125 /*****************************************************************************
4126 * GdipGetClipBounds [GDIPLUS.@]
4128 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4130 TRACE("(%p, %p)\n", graphics
, rect
);
4133 return InvalidParameter
;
4138 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4141 /*****************************************************************************
4142 * GdipGetClipBoundsI [GDIPLUS.@]
4144 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4146 TRACE("(%p, %p)\n", graphics
, rect
);
4149 return InvalidParameter
;
4154 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4157 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4158 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4159 CompositingMode
*mode
)
4161 TRACE("(%p, %p)\n", graphics
, mode
);
4163 if(!graphics
|| !mode
)
4164 return InvalidParameter
;
4169 *mode
= graphics
->compmode
;
4174 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4175 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4176 CompositingQuality
*quality
)
4178 TRACE("(%p, %p)\n", graphics
, quality
);
4180 if(!graphics
|| !quality
)
4181 return InvalidParameter
;
4186 *quality
= graphics
->compqual
;
4191 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4192 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4193 InterpolationMode
*mode
)
4195 TRACE("(%p, %p)\n", graphics
, mode
);
4197 if(!graphics
|| !mode
)
4198 return InvalidParameter
;
4203 *mode
= graphics
->interpolation
;
4208 /* FIXME: Need to handle color depths less than 24bpp */
4209 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4211 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4213 if(!graphics
|| !argb
)
4214 return InvalidParameter
;
4222 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4224 TRACE("(%p, %p)\n", graphics
, scale
);
4226 if(!graphics
|| !scale
)
4227 return InvalidParameter
;
4232 *scale
= graphics
->scale
;
4237 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4239 TRACE("(%p, %p)\n", graphics
, unit
);
4241 if(!graphics
|| !unit
)
4242 return InvalidParameter
;
4247 *unit
= graphics
->unit
;
4252 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4253 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4256 TRACE("(%p, %p)\n", graphics
, mode
);
4258 if(!graphics
|| !mode
)
4259 return InvalidParameter
;
4264 *mode
= graphics
->pixeloffset
;
4269 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4270 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4272 TRACE("(%p, %p)\n", graphics
, mode
);
4274 if(!graphics
|| !mode
)
4275 return InvalidParameter
;
4280 *mode
= graphics
->smoothing
;
4285 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4287 TRACE("(%p, %p)\n", graphics
, contrast
);
4289 if(!graphics
|| !contrast
)
4290 return InvalidParameter
;
4292 *contrast
= graphics
->textcontrast
;
4297 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4298 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4299 TextRenderingHint
*hint
)
4301 TRACE("(%p, %p)\n", graphics
, hint
);
4303 if(!graphics
|| !hint
)
4304 return InvalidParameter
;
4309 *hint
= graphics
->texthint
;
4314 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4319 TRACE("(%p, %p)\n", graphics
, rect
);
4321 if(!graphics
|| !rect
)
4322 return InvalidParameter
;
4327 /* intersect window and graphics clipping regions */
4328 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4331 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4334 /* get bounds of the region */
4335 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4338 GdipDeleteRegion(clip_rgn
);
4343 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4348 TRACE("(%p, %p)\n", graphics
, rect
);
4350 if(!graphics
|| !rect
)
4351 return InvalidParameter
;
4353 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4355 rect
->X
= roundr(rectf
.X
);
4356 rect
->Y
= roundr(rectf
.Y
);
4357 rect
->Width
= roundr(rectf
.Width
);
4358 rect
->Height
= roundr(rectf
.Height
);
4364 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4366 TRACE("(%p, %p)\n", graphics
, matrix
);
4368 if(!graphics
|| !matrix
)
4369 return InvalidParameter
;
4374 *matrix
= *graphics
->worldtrans
;
4378 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4384 TRACE("(%p, %x)\n", graphics
, color
);
4387 return InvalidParameter
;
4392 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4395 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4396 GdipDeleteBrush((GpBrush
*)brush
);
4400 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4401 wnd_rect
.Width
, wnd_rect
.Height
);
4403 GdipDeleteBrush((GpBrush
*)brush
);
4408 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4410 TRACE("(%p, %p)\n", graphics
, res
);
4412 if(!graphics
|| !res
)
4413 return InvalidParameter
;
4415 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4418 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4424 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4426 if(!graphics
|| !result
)
4427 return InvalidParameter
;
4434 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4435 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4438 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4441 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4444 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4447 GdipDeleteRegion(rgn
);
4451 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4453 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4456 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4462 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4464 if(!graphics
|| !result
)
4465 return InvalidParameter
;
4472 pts
[1].X
= x
+ width
;
4473 pts
[1].Y
= y
+ height
;
4475 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4476 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4479 pts
[1].X
-= pts
[0].X
;
4480 pts
[1].Y
-= pts
[0].Y
;
4482 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4485 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4488 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4491 GdipDeleteRegion(rgn
);
4495 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4497 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4500 GpStatus
gdip_format_string(HDC hdc
,
4501 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4502 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4503 gdip_format_string_callback callback
, void *user_data
)
4506 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4507 nheight
, lineend
, lineno
= 0;
4509 StringAlignment halign
;
4513 if(length
== -1) length
= lstrlenW(string
);
4515 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4516 if(!stringdup
) return OutOfMemory
;
4518 nwidth
= roundr(rect
->Width
);
4519 nheight
= roundr(rect
->Height
);
4521 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
4522 if (rect
->Height
>= INT_MAX
|| rect
->Height
< 0.5) nheight
= INT_MAX
;
4524 for(i
= 0, j
= 0; i
< length
; i
++){
4525 /* FIXME: This makes the indexes passed to callback inaccurate. */
4526 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4529 stringdup
[j
] = string
[i
];
4535 if (format
) halign
= format
->align
;
4536 else halign
= StringAlignmentNear
;
4538 while(sum
< length
){
4539 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4540 nwidth
, &fit
, NULL
, &size
);
4546 for(lret
= 0; lret
< fit
; lret
++)
4547 if(*(stringdup
+ sum
+ lret
) == '\n')
4550 /* Line break code (may look strange, but it imitates windows). */
4552 lineend
= fit
= lret
; /* this is not an off-by-one error */
4553 else if(fit
< (length
- sum
)){
4554 if(*(stringdup
+ sum
+ fit
) == ' ')
4555 while(*(stringdup
+ sum
+ fit
) == ' ')
4558 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4561 if(*(stringdup
+ sum
+ fit
) == '\t')
4570 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4571 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4577 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4578 nwidth
, &j
, NULL
, &size
);
4580 bounds
.Width
= size
.cx
;
4582 if(height
+ size
.cy
> nheight
)
4583 bounds
.Height
= nheight
- (height
+ size
.cy
);
4585 bounds
.Height
= size
.cy
;
4587 bounds
.Y
= rect
->Y
+ height
;
4591 case StringAlignmentNear
:
4595 case StringAlignmentCenter
:
4596 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4598 case StringAlignmentFar
:
4599 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4603 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4604 font
, rect
, format
, lineno
, &bounds
, user_data
);
4609 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4613 if(height
> nheight
)
4616 /* Stop if this was a linewrap (but not if it was a linebreak). */
4617 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
4621 GdipFree(stringdup
);
4626 struct measure_ranges_args
{
4630 static GpStatus
measure_ranges_callback(HDC hdc
,
4631 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4632 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4633 INT lineno
, const RectF
*bounds
, void *user_data
)
4637 struct measure_ranges_args
*args
= user_data
;
4639 for (i
=0; i
<format
->range_count
; i
++)
4641 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4642 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4643 if (range_start
< range_end
)
4648 range_rect
.Y
= bounds
->Y
;
4649 range_rect
.Height
= bounds
->Height
;
4651 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4652 INT_MAX
, NULL
, NULL
, &range_size
);
4653 range_rect
.X
= bounds
->X
+ range_size
.cx
;
4655 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4656 INT_MAX
, NULL
, NULL
, &range_size
);
4657 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
4659 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4668 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4669 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4670 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4671 INT regionCount
, GpRegion
** regions
)
4676 struct measure_ranges_args args
;
4677 HDC hdc
, temp_hdc
=NULL
;
4679 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4680 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4682 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4683 return InvalidParameter
;
4685 if (regionCount
< stringFormat
->range_count
)
4686 return InvalidParameter
;
4690 hdc
= temp_hdc
= CreateCompatibleDC(0);
4691 if (!temp_hdc
) return OutOfMemory
;
4694 hdc
= graphics
->hdc
;
4696 if (stringFormat
->attr
)
4697 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4699 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&font
->lfw
));
4701 for (i
=0; i
<stringFormat
->range_count
; i
++)
4703 stat
= GdipSetEmpty(regions
[i
]);
4708 args
.regions
= regions
;
4710 stat
= gdip_format_string(hdc
, string
, length
, font
, layoutRect
, stringFormat
,
4711 measure_ranges_callback
, &args
);
4713 DeleteObject(SelectObject(hdc
, oldfont
));
4721 struct measure_string_args
{
4723 INT
*codepointsfitted
;
4727 static GpStatus
measure_string_callback(HDC hdc
,
4728 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4729 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4730 INT lineno
, const RectF
*bounds
, void *user_data
)
4732 struct measure_string_args
*args
= user_data
;
4734 if (bounds
->Width
> args
->bounds
->Width
)
4735 args
->bounds
->Width
= bounds
->Width
;
4737 if (bounds
->Height
+ bounds
->Y
> args
->bounds
->Height
+ args
->bounds
->Y
)
4738 args
->bounds
->Height
= bounds
->Height
+ bounds
->Y
- args
->bounds
->Y
;
4740 if (args
->codepointsfitted
)
4741 *args
->codepointsfitted
= index
+ length
;
4743 if (args
->linesfilled
)
4744 (*args
->linesfilled
)++;
4749 /* Find the smallest rectangle that bounds the text when it is printed in rect
4750 * according to the format options listed in format. If rect has 0 width and
4751 * height, then just find the smallest rectangle that bounds the text when it's
4752 * printed at location (rect->X, rect-Y). */
4753 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4754 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4755 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4756 INT
*codepointsfitted
, INT
*linesfilled
)
4759 struct measure_string_args args
;
4760 HDC temp_hdc
=NULL
, hdc
;
4762 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4763 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4764 bounds
, codepointsfitted
, linesfilled
);
4766 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4767 return InvalidParameter
;
4771 hdc
= temp_hdc
= CreateCompatibleDC(0);
4772 if (!temp_hdc
) return OutOfMemory
;
4775 hdc
= graphics
->hdc
;
4777 if(linesfilled
) *linesfilled
= 0;
4778 if(codepointsfitted
) *codepointsfitted
= 0;
4781 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4783 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&font
->lfw
));
4785 bounds
->X
= rect
->X
;
4786 bounds
->Y
= rect
->Y
;
4787 bounds
->Width
= 0.0;
4788 bounds
->Height
= 0.0;
4790 args
.bounds
= bounds
;
4791 args
.codepointsfitted
= codepointsfitted
;
4792 args
.linesfilled
= linesfilled
;
4794 gdip_format_string(hdc
, string
, length
, font
, rect
, format
,
4795 measure_string_callback
, &args
);
4797 DeleteObject(SelectObject(hdc
, oldfont
));
4805 struct draw_string_args
{
4806 GpGraphics
*graphics
;
4807 GDIPCONST GpBrush
*brush
;
4808 REAL x
, y
, rel_width
, rel_height
, ascent
;
4811 static GpStatus
draw_string_callback(HDC hdc
,
4812 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4813 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4814 INT lineno
, const RectF
*bounds
, void *user_data
)
4816 struct draw_string_args
*args
= user_data
;
4819 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4820 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4822 return GdipDrawDriverString(args
->graphics
, &string
[index
], length
, font
,
4823 args
->brush
, &position
,
4824 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4827 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4828 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4829 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4833 GpPointF pt
[3], rectcpy
[4];
4835 REAL rel_width
, rel_height
;
4838 struct draw_string_args args
;
4840 HDC hdc
, temp_hdc
=NULL
;
4841 TEXTMETRICW textmetric
;
4843 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4844 length
, font
, debugstr_rectf(rect
), format
, brush
);
4846 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4847 return InvalidParameter
;
4851 hdc
= graphics
->hdc
;
4855 hdc
= temp_hdc
= CreateCompatibleDC(0);
4859 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4861 /* Should be no need to explicitly test for StringAlignmentNear as
4862 * that is default behavior if no alignment is passed. */
4863 if(format
->vertalign
!= StringAlignmentNear
){
4865 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
4867 if(format
->vertalign
== StringAlignmentCenter
)
4868 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4869 else if(format
->vertalign
== StringAlignmentFar
)
4870 offsety
= (rect
->Height
- bounds
.Height
);
4874 save_state
= SaveDC(hdc
);
4882 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4883 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4884 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4885 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4886 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4888 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
4889 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
4890 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
4891 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
4892 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
4894 scaled_rect
.X
= 0.0;
4895 scaled_rect
.Y
= 0.0;
4896 scaled_rect
.Width
= rel_width
* rect
->Width
;
4897 scaled_rect
.Height
= rel_height
* rect
->Height
;
4899 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
4901 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4902 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
4903 SelectClipRgn(hdc
, rgn
);
4906 get_font_hfont(graphics
, font
, &gdifont
);
4907 SelectObject(hdc
, gdifont
);
4909 args
.graphics
= graphics
;
4913 args
.y
= rect
->Y
+ offsety
;
4915 args
.rel_width
= rel_width
;
4916 args
.rel_height
= rel_height
;
4918 GetTextMetricsW(hdc
, &textmetric
);
4919 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
4921 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
4922 draw_string_callback
, &args
);
4925 DeleteObject(gdifont
);
4927 RestoreDC(hdc
, save_state
);
4934 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
4936 TRACE("(%p)\n", graphics
);
4939 return InvalidParameter
;
4944 return GdipSetInfinite(graphics
->clip
);
4947 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
4949 TRACE("(%p)\n", graphics
);
4952 return InvalidParameter
;
4957 graphics
->worldtrans
->matrix
[0] = 1.0;
4958 graphics
->worldtrans
->matrix
[1] = 0.0;
4959 graphics
->worldtrans
->matrix
[2] = 0.0;
4960 graphics
->worldtrans
->matrix
[3] = 1.0;
4961 graphics
->worldtrans
->matrix
[4] = 0.0;
4962 graphics
->worldtrans
->matrix
[5] = 0.0;
4967 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
4969 return GdipEndContainer(graphics
, state
);
4972 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
4973 GpMatrixOrder order
)
4975 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
4978 return InvalidParameter
;
4983 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
4986 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
4988 return GdipBeginContainer2(graphics
, state
);
4991 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
4992 GraphicsContainer
*state
)
4994 GraphicsContainerItem
*container
;
4997 TRACE("(%p, %p)\n", graphics
, state
);
4999 if(!graphics
|| !state
)
5000 return InvalidParameter
;
5002 sts
= init_container(&container
, graphics
);
5006 list_add_head(&graphics
->containers
, &container
->entry
);
5007 *state
= graphics
->contid
= container
->contid
;
5012 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5014 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5015 return NotImplemented
;
5018 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5020 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5021 return NotImplemented
;
5024 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5026 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5027 return NotImplemented
;
5030 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5033 GraphicsContainerItem
*container
, *container2
;
5035 TRACE("(%p, %x)\n", graphics
, state
);
5038 return InvalidParameter
;
5040 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5041 if(container
->contid
== state
)
5045 /* did not find a matching container */
5046 if(&container
->entry
== &graphics
->containers
)
5049 sts
= restore_container(graphics
, container
);
5053 /* remove all of the containers on top of the found container */
5054 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5055 if(container
->contid
== state
)
5057 list_remove(&container
->entry
);
5058 delete_container(container
);
5061 list_remove(&container
->entry
);
5062 delete_container(container
);
5067 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5068 REAL sy
, GpMatrixOrder order
)
5070 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5073 return InvalidParameter
;
5078 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
5081 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5084 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5086 if(!graphics
|| !srcgraphics
)
5087 return InvalidParameter
;
5089 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5092 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5093 CompositingMode mode
)
5095 TRACE("(%p, %d)\n", graphics
, mode
);
5098 return InvalidParameter
;
5103 graphics
->compmode
= mode
;
5108 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5109 CompositingQuality quality
)
5111 TRACE("(%p, %d)\n", graphics
, quality
);
5114 return InvalidParameter
;
5119 graphics
->compqual
= quality
;
5124 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5125 InterpolationMode mode
)
5127 TRACE("(%p, %d)\n", graphics
, mode
);
5129 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5130 return InvalidParameter
;
5135 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5136 mode
= InterpolationModeBilinear
;
5138 if (mode
== InterpolationModeHighQuality
)
5139 mode
= InterpolationModeHighQualityBicubic
;
5141 graphics
->interpolation
= mode
;
5146 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5148 TRACE("(%p, %.2f)\n", graphics
, scale
);
5150 if(!graphics
|| (scale
<= 0.0))
5151 return InvalidParameter
;
5156 graphics
->scale
= scale
;
5161 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5163 TRACE("(%p, %d)\n", graphics
, unit
);
5166 return InvalidParameter
;
5171 if(unit
== UnitWorld
)
5172 return InvalidParameter
;
5174 graphics
->unit
= unit
;
5179 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5182 TRACE("(%p, %d)\n", graphics
, mode
);
5185 return InvalidParameter
;
5190 graphics
->pixeloffset
= mode
;
5195 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5199 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5202 FIXME("not implemented\n");
5204 return NotImplemented
;
5207 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5211 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5214 FIXME("not implemented\n");
5218 return NotImplemented
;
5221 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5223 TRACE("(%p, %d)\n", graphics
, mode
);
5226 return InvalidParameter
;
5231 graphics
->smoothing
= mode
;
5236 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5238 TRACE("(%p, %d)\n", graphics
, contrast
);
5241 return InvalidParameter
;
5243 graphics
->textcontrast
= contrast
;
5248 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5249 TextRenderingHint hint
)
5251 TRACE("(%p, %d)\n", graphics
, hint
);
5253 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5254 return InvalidParameter
;
5259 graphics
->texthint
= hint
;
5264 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5266 TRACE("(%p, %p)\n", graphics
, matrix
);
5268 if(!graphics
|| !matrix
)
5269 return InvalidParameter
;
5274 GdipDeleteMatrix(graphics
->worldtrans
);
5275 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
5278 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5279 REAL dy
, GpMatrixOrder order
)
5281 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5284 return InvalidParameter
;
5289 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
5292 /*****************************************************************************
5293 * GdipSetClipHrgn [GDIPLUS.@]
5295 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5300 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5303 return InvalidParameter
;
5305 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5309 status
= GdipSetClipRegion(graphics
, region
, mode
);
5311 GdipDeleteRegion(region
);
5315 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5317 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5320 return InvalidParameter
;
5325 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5328 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5329 REAL width
, REAL height
,
5334 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5337 return InvalidParameter
;
5345 rect
.Height
= height
;
5347 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5350 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5351 INT width
, INT height
,
5354 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5357 return InvalidParameter
;
5362 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5365 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5368 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5370 if(!graphics
|| !region
)
5371 return InvalidParameter
;
5376 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5379 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5384 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5387 FIXME("not implemented\n");
5389 return NotImplemented
;
5392 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5398 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5400 if(!graphics
|| !pen
|| count
<=0)
5401 return InvalidParameter
;
5408 FIXME("graphics object has no HDC\n");
5412 pti
= GdipAlloc(sizeof(POINT
) * count
);
5414 save_state
= prepare_dc(graphics
, pen
);
5415 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5417 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5418 Polygon(graphics
->hdc
, pti
, count
);
5420 restore_dc(graphics
, save_state
);
5426 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5433 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5435 if(count
<=0) return InvalidParameter
;
5436 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5438 for(i
= 0;i
< count
; i
++){
5439 ptf
[i
].X
= (REAL
)points
[i
].X
;
5440 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5443 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5449 GpStatus WINGDIPAPI
GdipGetDpiX(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
->xres
;
5462 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
5467 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5469 TRACE("(%p, %p)\n", graphics
, dpi
);
5471 if(!graphics
|| !dpi
)
5472 return InvalidParameter
;
5477 if (graphics
->image
)
5478 *dpi
= graphics
->image
->yres
;
5480 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
5485 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5486 GpMatrixOrder order
)
5491 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5493 if(!graphics
|| !matrix
)
5494 return InvalidParameter
;
5499 m
= *(graphics
->worldtrans
);
5501 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5503 *(graphics
->worldtrans
) = m
;
5508 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5509 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5511 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5515 TRACE("(%p, %p)\n", graphics
, hdc
);
5517 if(!graphics
|| !hdc
)
5518 return InvalidParameter
;
5523 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5525 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5527 else if (!graphics
->hdc
||
5528 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5530 /* Create a fake HDC and fill it with a constant color. */
5534 BITMAPINFOHEADER bmih
;
5537 stat
= get_graphics_bounds(graphics
, &bounds
);
5541 graphics
->temp_hbitmap_width
= bounds
.Width
;
5542 graphics
->temp_hbitmap_height
= bounds
.Height
;
5544 bmih
.biSize
= sizeof(bmih
);
5545 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5546 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5548 bmih
.biBitCount
= 32;
5549 bmih
.biCompression
= BI_RGB
;
5550 bmih
.biSizeImage
= 0;
5551 bmih
.biXPelsPerMeter
= 0;
5552 bmih
.biYPelsPerMeter
= 0;
5554 bmih
.biClrImportant
= 0;
5556 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5557 (void**)&graphics
->temp_bits
, NULL
, 0);
5559 return GenericError
;
5561 temp_hdc
= CreateCompatibleDC(0);
5564 DeleteObject(hbitmap
);
5565 return GenericError
;
5568 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5569 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5571 SelectObject(temp_hdc
, hbitmap
);
5573 graphics
->temp_hbitmap
= hbitmap
;
5574 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5578 *hdc
= graphics
->hdc
;
5582 graphics
->busy
= TRUE
;
5587 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5591 TRACE("(%p, %p)\n", graphics
, hdc
);
5593 if(!graphics
|| !hdc
|| !graphics
->busy
)
5594 return InvalidParameter
;
5596 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5598 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5600 else if (graphics
->temp_hdc
== hdc
)
5605 /* Find the pixels that have changed, and mark them as opaque. */
5606 pos
= (DWORD
*)graphics
->temp_bits
;
5607 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5609 if (*pos
!= DC_BACKGROUND_KEY
)
5616 /* Write the changed pixels to the real target. */
5617 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5618 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5619 graphics
->temp_hbitmap_width
* 4);
5622 DeleteDC(graphics
->temp_hdc
);
5623 DeleteObject(graphics
->temp_hbitmap
);
5624 graphics
->temp_hdc
= NULL
;
5625 graphics
->temp_hbitmap
= NULL
;
5627 else if (hdc
!= graphics
->hdc
)
5629 stat
= InvalidParameter
;
5633 graphics
->busy
= FALSE
;
5638 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5643 TRACE("(%p, %p)\n", graphics
, region
);
5645 if(!graphics
|| !region
)
5646 return InvalidParameter
;
5651 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5654 /* free everything except root node and header */
5655 delete_element(®ion
->node
);
5656 memcpy(region
, clip
, sizeof(GpRegion
));
5662 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5663 GpCoordinateSpace src_space
, GpMatrix
**matrix
)
5665 GpStatus stat
= GdipCreateMatrix(matrix
);
5668 if (dst_space
!= src_space
&& stat
== Ok
)
5670 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
5672 if(graphics
->unit
!= UnitDisplay
)
5673 unitscale
*= graphics
->scale
;
5675 /* transform from src_space to CoordinateSpacePage */
5678 case CoordinateSpaceWorld
:
5679 GdipMultiplyMatrix(*matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
5681 case CoordinateSpacePage
:
5683 case CoordinateSpaceDevice
:
5684 GdipScaleMatrix(*matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
5688 /* transform from CoordinateSpacePage to dst_space */
5691 case CoordinateSpaceWorld
:
5693 GpMatrix
*inverted_transform
;
5694 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
5697 stat
= GdipInvertMatrix(inverted_transform
);
5699 GdipMultiplyMatrix(*matrix
, inverted_transform
, MatrixOrderAppend
);
5700 GdipDeleteMatrix(inverted_transform
);
5704 case CoordinateSpacePage
:
5706 case CoordinateSpaceDevice
:
5707 GdipScaleMatrix(*matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
5714 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5715 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5720 if(!graphics
|| !points
|| count
<= 0)
5721 return InvalidParameter
;
5726 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5728 if (src_space
== dst_space
) return Ok
;
5730 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5734 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
5736 GdipDeleteMatrix(matrix
);
5742 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5743 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5749 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5752 return InvalidParameter
;
5754 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5758 for(i
= 0; i
< count
; i
++){
5759 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5760 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5763 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5766 for(i
= 0; i
< count
; i
++){
5767 points
[i
].X
= roundr(pointsF
[i
].X
);
5768 points
[i
].Y
= roundr(pointsF
[i
].Y
);
5775 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5787 /*****************************************************************************
5788 * GdipTranslateClip [GDIPLUS.@]
5790 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5792 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5795 return InvalidParameter
;
5800 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5803 /*****************************************************************************
5804 * GdipTranslateClipI [GDIPLUS.@]
5806 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5808 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5811 return InvalidParameter
;
5816 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
5820 /*****************************************************************************
5821 * GdipMeasureDriverString [GDIPLUS.@]
5823 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5824 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
5825 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
5827 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
5830 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
5832 TEXTMETRICW textmetric
;
5833 const WORD
*glyph_indices
;
5834 WORD
*dynamic_glyph_indices
=NULL
;
5835 REAL rel_width
, rel_height
, ascent
, descent
;
5838 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
5840 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
5841 return InvalidParameter
;
5844 length
= strlenW(text
);
5848 boundingBox
->X
= 0.0;
5849 boundingBox
->Y
= 0.0;
5850 boundingBox
->Width
= 0.0;
5851 boundingBox
->Height
= 0.0;
5854 if (flags
& unsupported_flags
)
5855 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
5858 FIXME("Ignoring matrix\n");
5860 get_font_hfont(graphics
, font
, &hfont
);
5862 hdc
= CreateCompatibleDC(0);
5863 SelectObject(hdc
, hfont
);
5865 GetTextMetricsW(hdc
, &textmetric
);
5873 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5874 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5875 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5876 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5877 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5879 if (flags
& DriverStringOptionsCmapLookup
)
5881 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
5885 DeleteObject(hfont
);
5889 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
5892 glyph_indices
= text
;
5894 min_x
= max_x
= x
= positions
[0].X
;
5895 min_y
= max_y
= y
= positions
[0].Y
;
5897 ascent
= textmetric
.tmAscent
/ rel_height
;
5898 descent
= textmetric
.tmDescent
/ rel_height
;
5900 for (i
=0; i
<length
; i
++)
5905 if (!(flags
& DriverStringOptionsRealizedAdvance
))
5911 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
5912 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcB
;
5914 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
5915 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
5916 if (min_x
> x
) min_x
= x
;
5918 x
+= char_width
/ rel_width
;
5920 if (max_x
< x
) max_x
= x
;
5923 GdipFree(dynamic_glyph_indices
);
5925 DeleteObject(hfont
);
5927 boundingBox
->X
= min_x
;
5928 boundingBox
->Y
= min_y
;
5929 boundingBox
->Width
= max_x
- min_x
;
5930 boundingBox
->Height
= max_y
- min_y
;
5935 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5936 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
5937 GDIPCONST PointF
*positions
, INT flags
,
5938 GDIPCONST GpMatrix
*matrix
)
5940 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
5946 if (flags
& unsupported_flags
)
5947 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
5950 FIXME("Ignoring matrix\n");
5952 if (!(flags
& DriverStringOptionsCmapLookup
))
5953 eto_flags
|= ETO_GLYPH_INDEX
;
5955 save_state
= SaveDC(graphics
->hdc
);
5956 SetBkMode(graphics
->hdc
, TRANSPARENT
);
5957 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
5960 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
5962 get_font_hfont(graphics
, font
, &hfont
);
5963 SelectObject(graphics
->hdc
, hfont
);
5965 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
5967 ExtTextOutW(graphics
->hdc
, roundr(pt
.X
), roundr(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
5969 RestoreDC(graphics
->hdc
, save_state
);
5971 DeleteObject(hfont
);
5976 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5977 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
5978 GDIPCONST PointF
*positions
, INT flags
,
5979 GDIPCONST GpMatrix
*matrix
)
5981 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
5983 PointF
*real_positions
, real_position
;
5987 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
5988 DWORD max_glyphsize
=0;
5989 GLYPHMETRICS glyphmetrics
;
5990 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
5993 int text_mask_stride
;
5995 int pixel_data_stride
;
5997 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6002 if (!(flags
& DriverStringOptionsCmapLookup
))
6003 ggo_flags
|= GGO_GLYPH_INDEX
;
6005 if (flags
& unsupported_flags
)
6006 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6009 FIXME("Ignoring matrix\n");
6011 pti
= GdipAlloc(sizeof(POINT
) * length
);
6015 if (flags
& DriverStringOptionsRealizedAdvance
)
6017 real_position
= positions
[0];
6019 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6023 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6024 if (!real_positions
)
6030 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6032 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6034 GdipFree(real_positions
);
6037 get_font_hfont(graphics
, font
, &hfont
);
6039 hdc
= CreateCompatibleDC(0);
6040 SelectObject(hdc
, hfont
);
6042 /* Get the boundaries of the text to be drawn */
6043 for (i
=0; i
<length
; i
++)
6046 int left
, top
, right
, bottom
;
6048 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6049 &glyphmetrics
, 0, NULL
, &identity
);
6051 if (glyphsize
== GDI_ERROR
)
6053 ERR("GetGlyphOutlineW failed\n");
6056 DeleteObject(hfont
);
6057 return GenericError
;
6060 if (glyphsize
> max_glyphsize
)
6061 max_glyphsize
= glyphsize
;
6063 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6064 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6065 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6066 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6068 if (left
< min_x
) min_x
= left
;
6069 if (top
< min_y
) min_y
= top
;
6070 if (right
> max_x
) max_x
= right
;
6071 if (bottom
> max_y
) max_y
= bottom
;
6073 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6075 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6076 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6080 glyph_mask
= GdipAlloc(max_glyphsize
);
6081 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6082 text_mask_stride
= max_x
- min_x
;
6084 if (!(glyph_mask
&& text_mask
))
6086 GdipFree(glyph_mask
);
6087 GdipFree(text_mask
);
6090 DeleteObject(hfont
);
6094 /* Generate a mask for the text */
6095 for (i
=0; i
<length
; i
++)
6097 int left
, top
, stride
;
6099 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6100 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6102 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6103 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6104 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6106 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6108 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6109 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6110 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6112 *text_val
= min(64, *text_val
+ *glyph_val
);
6121 DeleteObject(hfont
);
6122 GdipFree(glyph_mask
);
6124 /* get the brush data */
6125 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6128 GdipFree(text_mask
);
6132 pixel_area
.X
= min_x
;
6133 pixel_area
.Y
= min_y
;
6134 pixel_area
.Width
= max_x
- min_x
;
6135 pixel_area
.Height
= max_y
- min_y
;
6136 pixel_data_stride
= pixel_area
.Width
* 4;
6138 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6141 GdipFree(text_mask
);
6142 GdipFree(pixel_data
);
6146 /* multiply the brush data by the mask */
6147 for (y
=0; y
<pixel_area
.Height
; y
++)
6149 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6150 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6151 for (x
=0; x
<pixel_area
.Width
; x
++)
6153 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6159 GdipFree(text_mask
);
6161 /* draw the result */
6162 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6163 pixel_area
.Height
, pixel_data_stride
);
6165 GdipFree(pixel_data
);
6170 /*****************************************************************************
6171 * GdipDrawDriverString [GDIPLUS.@]
6173 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6174 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6175 GDIPCONST PointF
*positions
, INT flags
,
6176 GDIPCONST GpMatrix
*matrix
)
6178 GpStatus stat
=NotImplemented
;
6180 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6182 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6183 return InvalidParameter
;
6186 length
= strlenW(text
);
6188 if (graphics
->hdc
&&
6189 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6190 brush
->bt
== BrushTypeSolidColor
&&
6191 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6192 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
6193 positions
, flags
, matrix
);
6195 if (stat
== NotImplemented
)
6196 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
6197 positions
, flags
, matrix
);
6202 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6203 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6205 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6206 return NotImplemented
;
6209 /*****************************************************************************
6210 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6212 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6217 TRACE("(%p, %p)\n", graphics
, res
);
6219 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6222 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6225 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6228 GdipDeleteRegion(rgn
);