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 INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
97 INT save_state
, i
, numdashes
;
99 DWORD dash_array
[MAX_DASHLEN
];
101 save_state
= SaveDC(graphics
->hdc
);
103 EndPath(graphics
->hdc
);
105 if(pen
->unit
== UnitPixel
){
109 /* Get an estimate for the amount the pen width is affected by the world
110 * transform. (This is similar to what some of the wine drivers do.) */
115 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
116 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
117 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
119 width
*= pen
->width
* convert_unit(graphics_res(graphics
),
120 pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
);
123 if(pen
->dash
== DashStyleCustom
){
124 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
126 TRACE("dashes are: ");
127 for(i
= 0; i
< numdashes
; i
++){
128 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
129 TRACE("%d, ", dash_array
[i
]);
131 TRACE("\n and the pen style is %x\n", pen
->style
);
133 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
,
134 numdashes
, dash_array
);
137 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
, 0, NULL
);
139 SelectObject(graphics
->hdc
, gdipen
);
144 static void restore_dc(GpGraphics
*graphics
, INT state
)
146 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
147 RestoreDC(graphics
->hdc
, state
);
150 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
151 GpCoordinateSpace src_space
, GpMatrix
**matrix
);
153 /* This helper applies all the changes that the points listed in ptf need in
154 * order to be drawn on the device context. In the end, this should include at
156 * -scaling by page unit
157 * -applying world transformation
158 * -converting from float to int
159 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
160 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
161 * gdi to draw, and these functions would irreparably mess with line widths.
163 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
164 GpPointF
*ptf
, INT count
)
170 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
172 /* apply page scale */
173 if(graphics
->unit
!= UnitDisplay
)
174 unitscale
*= graphics
->scale
;
176 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
177 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
178 GdipTransformMatrixPoints(matrix
, ptf
, count
);
179 GdipDeleteMatrix(matrix
);
181 for(i
= 0; i
< count
; i
++){
182 pti
[i
].x
= roundr(ptf
[i
].X
);
183 pti
[i
].y
= roundr(ptf
[i
].Y
);
187 /* Draw non-premultiplied ARGB data to the given graphics object */
188 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
189 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
191 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
193 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
196 for (x
=0; x
<src_width
; x
++)
198 for (y
=0; y
<src_height
; y
++)
200 ARGB dst_color
, src_color
;
201 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
202 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
203 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
209 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
211 ERR("This should not be used for metafiles; fix caller\n");
212 return NotImplemented
;
217 HBITMAP hbitmap
, old_hbm
=NULL
;
218 BITMAPINFOHEADER bih
;
222 hdc
= CreateCompatibleDC(0);
224 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
225 bih
.biWidth
= src_width
;
226 bih
.biHeight
= -src_height
;
229 bih
.biCompression
= BI_RGB
;
231 bih
.biXPelsPerMeter
= 0;
232 bih
.biYPelsPerMeter
= 0;
234 bih
.biClrImportant
= 0;
236 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
237 (void**)&temp_bits
, NULL
, 0);
239 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
240 4 * src_width
, src
, src_stride
);
242 old_hbm
= SelectObject(hdc
, hbitmap
);
244 bf
.BlendOp
= AC_SRC_OVER
;
246 bf
.SourceConstantAlpha
= 255;
247 bf
.AlphaFormat
= AC_SRC_ALPHA
;
249 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, src_width
, src_height
,
250 hdc
, 0, 0, src_width
, src_height
, bf
);
252 SelectObject(hdc
, old_hbm
);
254 DeleteObject(hbitmap
);
260 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
266 a1
= (start
>> 24) & 0xff;
267 a2
= (end
>> 24) & 0xff;
269 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
273 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
274 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
278 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
282 /* clamp to between 0.0 and 1.0, using the wrap mode */
283 if (brush
->wrap
== WrapModeTile
)
285 position
= fmodf(position
, 1.0f
);
286 if (position
< 0.0f
) position
+= 1.0f
;
288 else /* WrapModeFlip* */
290 position
= fmodf(position
, 2.0f
);
291 if (position
< 0.0f
) position
+= 2.0f
;
292 if (position
> 1.0f
) position
= 2.0f
- position
;
295 if (brush
->blendcount
== 1)
300 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
303 /* locate the blend positions surrounding this position */
304 while (position
> brush
->blendpos
[i
])
307 /* interpolate between the blend positions */
308 left_blendpos
= brush
->blendpos
[i
-1];
309 left_blendfac
= brush
->blendfac
[i
-1];
310 right_blendpos
= brush
->blendpos
[i
];
311 right_blendfac
= brush
->blendfac
[i
];
312 range
= right_blendpos
- left_blendpos
;
313 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
314 right_blendfac
* (position
- left_blendpos
)) / range
;
317 if (brush
->pblendcount
== 0)
318 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
322 ARGB left_blendcolor
, right_blendcolor
;
323 REAL left_blendpos
, right_blendpos
;
325 /* locate the blend colors surrounding this position */
326 while (blendfac
> brush
->pblendpos
[i
])
329 /* interpolate between the blend colors */
330 left_blendpos
= brush
->pblendpos
[i
-1];
331 left_blendcolor
= brush
->pblendcolor
[i
-1];
332 right_blendpos
= brush
->pblendpos
[i
];
333 right_blendcolor
= brush
->pblendcolor
[i
];
334 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
335 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
339 static ARGB
transform_color(ARGB color
, const ColorMatrix
*matrix
)
343 unsigned char a
, r
, g
, b
;
345 val
[0] = ((color
>> 16) & 0xff) / 255.0; /* red */
346 val
[1] = ((color
>> 8) & 0xff) / 255.0; /* green */
347 val
[2] = (color
& 0xff) / 255.0; /* blue */
348 val
[3] = ((color
>> 24) & 0xff) / 255.0; /* alpha */
349 val
[4] = 1.0; /* translation */
356 res
[i
] += matrix
->m
[j
][i
] * val
[j
];
359 a
= min(max(floorf(res
[3]*255.0), 0.0), 255.0);
360 r
= min(max(floorf(res
[0]*255.0), 0.0), 255.0);
361 g
= min(max(floorf(res
[1]*255.0), 0.0), 255.0);
362 b
= min(max(floorf(res
[2]*255.0), 0.0), 255.0);
364 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
367 static int color_is_gray(ARGB color
)
369 unsigned char r
, g
, b
;
371 r
= (color
>> 16) & 0xff;
372 g
= (color
>> 8) & 0xff;
375 return (r
== g
) && (g
== b
);
378 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
379 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
383 if (attributes
->colorkeys
[type
].enabled
||
384 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
386 const struct color_key
*key
;
387 BYTE min_blue
, min_green
, min_red
;
388 BYTE max_blue
, max_green
, max_red
;
390 if (attributes
->colorkeys
[type
].enabled
)
391 key
= &attributes
->colorkeys
[type
];
393 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
395 min_blue
= key
->low
&0xff;
396 min_green
= (key
->low
>>8)&0xff;
397 min_red
= (key
->low
>>16)&0xff;
399 max_blue
= key
->high
&0xff;
400 max_green
= (key
->high
>>8)&0xff;
401 max_red
= (key
->high
>>16)&0xff;
403 for (x
=0; x
<width
; x
++)
404 for (y
=0; y
<height
; y
++)
407 BYTE blue
, green
, red
;
408 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
409 blue
= *src_color
&0xff;
410 green
= (*src_color
>>8)&0xff;
411 red
= (*src_color
>>16)&0xff;
412 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
413 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
414 *src_color
= 0x00000000;
418 if (attributes
->colorremaptables
[type
].enabled
||
419 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
421 const struct color_remap_table
*table
;
423 if (attributes
->colorremaptables
[type
].enabled
)
424 table
= &attributes
->colorremaptables
[type
];
426 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
428 for (x
=0; x
<width
; x
++)
429 for (y
=0; y
<height
; y
++)
432 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
433 for (i
=0; i
<table
->mapsize
; i
++)
435 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
437 *src_color
= table
->colormap
[i
].newColor
.Argb
;
444 if (attributes
->colormatrices
[type
].enabled
||
445 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
447 const struct color_matrix
*colormatrices
;
449 if (attributes
->colormatrices
[type
].enabled
)
450 colormatrices
= &attributes
->colormatrices
[type
];
452 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
454 for (x
=0; x
<width
; x
++)
455 for (y
=0; y
<height
; y
++)
458 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
460 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
461 !color_is_gray(*src_color
))
463 *src_color
= transform_color(*src_color
, &colormatrices
->colormatrix
);
465 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
467 *src_color
= transform_color(*src_color
, &colormatrices
->graymatrix
);
472 if (attributes
->gamma_enabled
[type
] ||
473 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
477 if (attributes
->gamma_enabled
[type
])
478 gamma
= attributes
->gamma
[type
];
480 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
482 for (x
=0; x
<width
; x
++)
483 for (y
=0; y
<height
; y
++)
486 BYTE blue
, green
, red
;
487 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
489 blue
= *src_color
&0xff;
490 green
= (*src_color
>>8)&0xff;
491 red
= (*src_color
>>16)&0xff;
493 /* FIXME: We should probably use a table for this. */
494 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
495 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
496 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
498 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
503 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
504 * bitmap that contains all the pixels we may need to draw it. */
505 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
506 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
509 INT left
, top
, right
, bottom
;
511 switch (interpolation
)
513 case InterpolationModeHighQualityBilinear
:
514 case InterpolationModeHighQualityBicubic
:
515 /* FIXME: Include a greater range for the prefilter? */
516 case InterpolationModeBicubic
:
517 case InterpolationModeBilinear
:
518 left
= (INT
)(floorf(srcx
));
519 top
= (INT
)(floorf(srcy
));
520 right
= (INT
)(ceilf(srcx
+srcwidth
));
521 bottom
= (INT
)(ceilf(srcy
+srcheight
));
523 case InterpolationModeNearestNeighbor
:
527 right
= roundr(srcx
+srcwidth
);
528 bottom
= roundr(srcy
+srcheight
);
532 if (wrap
== WrapModeClamp
)
538 if (right
>= bitmap
->width
)
539 right
= bitmap
->width
-1;
540 if (bottom
>= bitmap
->height
)
541 bottom
= bitmap
->height
-1;
545 /* In some cases we can make the rectangle smaller here, but the logic
546 * is hard to get right, and tiling suggests we're likely to use the
547 * entire source image. */
548 if (left
< 0 || right
>= bitmap
->width
)
551 right
= bitmap
->width
-1;
554 if (top
< 0 || bottom
>= bitmap
->height
)
557 bottom
= bitmap
->height
-1;
563 rect
->Width
= right
- left
+ 1;
564 rect
->Height
= bottom
- top
+ 1;
567 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
568 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
570 if (attributes
->wrap
== WrapModeClamp
)
572 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
573 return attributes
->outside_color
;
577 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
579 x
= width
*2 + x
% (width
* 2);
581 y
= height
*2 + y
% (height
* 2);
583 if ((attributes
->wrap
& 1) == 1)
586 if ((x
/ width
) % 2 == 0)
589 x
= width
- 1 - x
% width
;
594 if ((attributes
->wrap
& 2) == 2)
597 if ((y
/ height
) % 2 == 0)
600 y
= height
- 1 - y
% height
;
606 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
608 ERR("out of range pixel requested\n");
612 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
615 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
616 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
617 InterpolationMode interpolation
)
621 switch (interpolation
)
625 FIXME("Unimplemented interpolation %i\n", interpolation
);
627 case InterpolationModeBilinear
:
630 INT leftx
, rightx
, topy
, bottomy
;
631 ARGB topleft
, topright
, bottomleft
, bottomright
;
635 leftxf
= floorf(point
->X
);
637 rightx
= (INT
)ceilf(point
->X
);
638 topyf
= floorf(point
->Y
);
640 bottomy
= (INT
)ceilf(point
->Y
);
642 if (leftx
== rightx
&& topy
== bottomy
)
643 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
644 leftx
, topy
, attributes
);
646 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
647 leftx
, topy
, attributes
);
648 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
649 rightx
, topy
, attributes
);
650 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
651 leftx
, bottomy
, attributes
);
652 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
653 rightx
, bottomy
, attributes
);
655 x_offset
= point
->X
- leftxf
;
656 top
= blend_colors(topleft
, topright
, x_offset
);
657 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
659 return blend_colors(top
, bottom
, point
->Y
- topyf
);
661 case InterpolationModeNearestNeighbor
:
662 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
663 roundr(point
->X
), roundr(point
->Y
), attributes
);
667 static INT
brush_can_fill_path(GpBrush
*brush
)
671 case BrushTypeSolidColor
:
672 case BrushTypeHatchFill
:
674 case BrushTypeLinearGradient
:
675 case BrushTypeTextureFill
:
676 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
682 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
686 case BrushTypeSolidColor
:
688 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
692 /* partially transparent fill */
694 SelectClipPath(graphics
->hdc
, RGN_AND
);
695 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
697 HDC hdc
= CreateCompatibleDC(NULL
);
703 oldbmp
= SelectObject(hdc
, fill
->bmp
);
705 bf
.BlendOp
= AC_SRC_OVER
;
707 bf
.SourceConstantAlpha
= 255;
708 bf
.AlphaFormat
= AC_SRC_ALPHA
;
710 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
712 SelectObject(hdc
, oldbmp
);
718 /* else fall through */
721 SelectObject(graphics
->hdc
, brush
->gdibrush
);
722 FillPath(graphics
->hdc
);
727 static INT
brush_can_fill_pixels(GpBrush
*brush
)
731 case BrushTypeSolidColor
:
732 case BrushTypeHatchFill
:
733 case BrushTypeLinearGradient
:
734 case BrushTypeTextureFill
:
741 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
742 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
746 case BrushTypeSolidColor
:
749 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
750 for (x
=0; x
<fill_area
->Width
; x
++)
751 for (y
=0; y
<fill_area
->Height
; y
++)
752 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
755 case BrushTypeHatchFill
:
758 GpHatch
*fill
= (GpHatch
*)brush
;
759 const char *hatch_data
;
761 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
762 return NotImplemented
;
764 for (x
=0; x
<fill_area
->Width
; x
++)
765 for (y
=0; y
<fill_area
->Height
; y
++)
769 /* FIXME: Account for the rendering origin */
770 hx
= (x
+ fill_area
->X
) % 8;
771 hy
= (y
+ fill_area
->Y
) % 8;
773 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
774 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
776 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
781 case BrushTypeLinearGradient
:
783 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
784 GpPointF draw_points
[3], line_points
[3];
786 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
787 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
790 draw_points
[0].X
= fill_area
->X
;
791 draw_points
[0].Y
= fill_area
->Y
;
792 draw_points
[1].X
= fill_area
->X
+1;
793 draw_points
[1].Y
= fill_area
->Y
;
794 draw_points
[2].X
= fill_area
->X
;
795 draw_points
[2].Y
= fill_area
->Y
+1;
797 /* Transform the points to a co-ordinate space where X is the point's
798 * position in the gradient, 0.0 being the start point and 1.0 the
800 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
801 CoordinateSpaceDevice
, draw_points
, 3);
805 line_points
[0] = fill
->startpoint
;
806 line_points
[1] = fill
->endpoint
;
807 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
808 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
810 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
815 stat
= GdipInvertMatrix(world_to_gradient
);
818 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
820 GdipDeleteMatrix(world_to_gradient
);
825 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
826 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
828 for (y
=0; y
<fill_area
->Height
; y
++)
830 for (x
=0; x
<fill_area
->Width
; x
++)
832 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
834 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
841 case BrushTypeTextureFill
:
843 GpTexture
*fill
= (GpTexture
*)brush
;
844 GpPointF draw_points
[3];
846 GpMatrix
*world_to_texture
;
852 if (fill
->image
->type
!= ImageTypeBitmap
)
854 FIXME("metafile texture brushes not implemented\n");
855 return NotImplemented
;
858 bitmap
= (GpBitmap
*)fill
->image
;
859 src_stride
= sizeof(ARGB
) * bitmap
->width
;
861 src_area
.X
= src_area
.Y
= 0;
862 src_area
.Width
= bitmap
->width
;
863 src_area
.Height
= bitmap
->height
;
865 draw_points
[0].X
= fill_area
->X
;
866 draw_points
[0].Y
= fill_area
->Y
;
867 draw_points
[1].X
= fill_area
->X
+1;
868 draw_points
[1].Y
= fill_area
->Y
;
869 draw_points
[2].X
= fill_area
->X
;
870 draw_points
[2].Y
= fill_area
->Y
+1;
872 /* Transform the points to the co-ordinate space of the bitmap. */
873 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
874 CoordinateSpaceDevice
, draw_points
, 3);
878 stat
= GdipCloneMatrix(fill
->transform
, &world_to_texture
);
883 stat
= GdipInvertMatrix(world_to_texture
);
886 stat
= GdipTransformMatrixPoints(world_to_texture
, draw_points
, 3);
888 GdipDeleteMatrix(world_to_texture
);
891 if (stat
== Ok
&& !fill
->bitmap_bits
)
893 BitmapData lockeddata
;
895 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
896 if (!fill
->bitmap_bits
)
901 lockeddata
.Width
= bitmap
->width
;
902 lockeddata
.Height
= bitmap
->height
;
903 lockeddata
.Stride
= src_stride
;
904 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
905 lockeddata
.Scan0
= fill
->bitmap_bits
;
907 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
908 PixelFormat32bppARGB
, &lockeddata
);
912 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
915 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
916 bitmap
->width
, bitmap
->height
,
917 src_stride
, ColorAdjustTypeBitmap
);
921 GdipFree(fill
->bitmap_bits
);
922 fill
->bitmap_bits
= NULL
;
928 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
929 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
930 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
931 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
933 for (y
=0; y
<fill_area
->Height
; y
++)
935 for (x
=0; x
<fill_area
->Width
; x
++)
938 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
939 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
941 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
942 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
943 &point
, fill
->imageattributes
, graphics
->interpolation
);
951 return NotImplemented
;
955 /* GdipDrawPie/GdipFillPie helper function */
956 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
957 REAL height
, REAL startAngle
, REAL sweepAngle
)
964 ptf
[1].X
= x
+ width
;
965 ptf
[1].Y
= y
+ height
;
967 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
968 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
970 transform_and_round_points(graphics
, pti
, ptf
, 4);
972 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
973 pti
[2].y
, pti
[3].x
, pti
[3].y
);
976 /* Draws the linecap the specified color and size on the hdc. The linecap is in
977 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
978 * should not be called on an hdc that has a path you care about. */
979 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
980 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
982 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
983 GpMatrix
*matrix
= NULL
;
986 PointF ptf
[4], *custptf
= NULL
;
987 POINT pt
[4], *custpt
= NULL
;
989 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
994 if((x1
== x2
) && (y1
== y2
))
997 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
999 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1001 brush
= CreateSolidBrush(color
);
1002 lb
.lbStyle
= BS_SOLID
;
1005 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1006 PS_JOIN_MITER
, 1, &lb
, 0,
1008 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1009 oldpen
= SelectObject(graphics
->hdc
, pen
);
1016 case LineCapSquareAnchor
:
1017 case LineCapDiamondAnchor
:
1018 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1019 if(cap
== LineCapDiamondAnchor
){
1020 dsmall
= cos(theta
+ M_PI_2
) * size
;
1021 dbig
= sin(theta
+ M_PI_2
) * size
;
1024 dsmall
= cos(theta
+ M_PI_4
) * size
;
1025 dbig
= sin(theta
+ M_PI_4
) * size
;
1028 ptf
[0].X
= x2
- dsmall
;
1029 ptf
[1].X
= x2
+ dbig
;
1031 ptf
[0].Y
= y2
- dbig
;
1032 ptf
[3].Y
= y2
+ dsmall
;
1034 ptf
[1].Y
= y2
- dsmall
;
1035 ptf
[2].Y
= y2
+ dbig
;
1037 ptf
[3].X
= x2
- dbig
;
1038 ptf
[2].X
= x2
+ dsmall
;
1040 transform_and_round_points(graphics
, pt
, ptf
, 4);
1041 Polygon(graphics
->hdc
, pt
, 4);
1044 case LineCapArrowAnchor
:
1045 size
= size
* 4.0 / sqrt(3.0);
1047 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1048 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1053 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1054 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1062 transform_and_round_points(graphics
, pt
, ptf
, 3);
1063 Polygon(graphics
->hdc
, pt
, 3);
1066 case LineCapRoundAnchor
:
1067 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1074 transform_and_round_points(graphics
, pt
, ptf
, 2);
1075 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1078 case LineCapTriangle
:
1080 dx
= cos(M_PI_2
+ theta
) * size
;
1081 dy
= sin(M_PI_2
+ theta
) * size
;
1088 dx
= cos(theta
) * size
;
1089 dy
= sin(theta
) * size
;
1094 transform_and_round_points(graphics
, pt
, ptf
, 3);
1095 Polygon(graphics
->hdc
, pt
, 3);
1099 dx
= dy
= size
/ 2.0;
1106 dx
= -cos(M_PI_2
+ theta
) * size
;
1107 dy
= -sin(M_PI_2
+ theta
) * size
;
1114 transform_and_round_points(graphics
, pt
, ptf
, 4);
1115 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1116 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1123 count
= custom
->pathdata
.Count
;
1124 custptf
= GdipAlloc(count
* sizeof(PointF
));
1125 custpt
= GdipAlloc(count
* sizeof(POINT
));
1126 tp
= GdipAlloc(count
);
1128 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
1131 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1133 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
1134 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1136 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
1137 GdipTransformMatrixPoints(matrix
, custptf
, count
);
1139 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1141 for(i
= 0; i
< count
; i
++)
1142 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1145 BeginPath(graphics
->hdc
);
1146 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1147 EndPath(graphics
->hdc
);
1148 StrokeAndFillPath(graphics
->hdc
);
1151 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1157 GdipDeleteMatrix(matrix
);
1164 SelectObject(graphics
->hdc
, oldbrush
);
1165 SelectObject(graphics
->hdc
, oldpen
);
1166 DeleteObject(brush
);
1171 /* Shortens the line by the given percent by changing x2, y2.
1172 * If percent is > 1.0 then the line will change direction.
1173 * If percent is negative it can lengthen the line. */
1174 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1176 REAL dist
, theta
, dx
, dy
;
1178 if((y1
== *y2
) && (x1
== *x2
))
1181 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1182 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1183 dx
= cos(theta
) * dist
;
1184 dy
= sin(theta
) * dist
;
1190 /* Shortens the line by the given amount by changing x2, y2.
1191 * If the amount is greater than the distance, the line will become length 0.
1192 * If the amount is negative, it can lengthen the line. */
1193 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1195 REAL dx
, dy
, percent
;
1199 if(dx
== 0 && dy
== 0)
1202 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1209 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1212 /* Draws lines between the given points, and if caps is true then draws an endcap
1213 * at the end of the last line. */
1214 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
1215 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1218 GpPointF
*ptcopy
= NULL
;
1219 GpStatus status
= GenericError
;
1224 pti
= GdipAlloc(count
* sizeof(POINT
));
1225 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1227 if(!pti
|| !ptcopy
){
1228 status
= OutOfMemory
;
1232 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1235 if(pen
->endcap
== LineCapArrowAnchor
)
1236 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1237 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
1238 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1239 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1240 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
1241 pen
->customend
->inset
* pen
->width
);
1243 if(pen
->startcap
== LineCapArrowAnchor
)
1244 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1245 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
1246 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1247 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1248 &ptcopy
[0].X
, &ptcopy
[0].Y
,
1249 pen
->customstart
->inset
* pen
->width
);
1251 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
1252 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
1253 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1254 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
1257 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1259 if(Polyline(graphics
->hdc
, pti
, count
))
1269 /* Conducts a linear search to find the bezier points that will back off
1270 * the endpoint of the curve by a distance of amt. Linear search works
1271 * better than binary in this case because there are multiple solutions,
1272 * and binary searches often find a bad one. I don't think this is what
1273 * Windows does but short of rendering the bezier without GDI's help it's
1274 * the best we can do. If rev then work from the start of the passed points
1275 * instead of the end. */
1276 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1279 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1280 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1289 origx
= pt
[fourth
].X
;
1290 origy
= pt
[fourth
].Y
;
1291 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1293 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1294 /* reset bezier points to original values */
1295 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1296 /* Perform magic on bezier points. Order is important here.*/
1297 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1298 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1299 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1300 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1301 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1302 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1304 dx
= pt
[fourth
].X
- origx
;
1305 dy
= pt
[fourth
].Y
- origy
;
1307 diff
= sqrt(dx
* dx
+ dy
* dy
);
1308 percent
+= 0.0005 * amt
;
1312 /* Draws bezier curves between given points, and if caps is true then draws an
1313 * endcap at the end of the last line. */
1314 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
1315 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1319 GpStatus status
= GenericError
;
1324 pti
= GdipAlloc(count
* sizeof(POINT
));
1325 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1327 if(!pti
|| !ptcopy
){
1328 status
= OutOfMemory
;
1332 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1335 if(pen
->endcap
== LineCapArrowAnchor
)
1336 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
1337 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1338 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
1341 if(pen
->startcap
== LineCapArrowAnchor
)
1342 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
1343 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1344 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
1346 /* the direction of the line cap is parallel to the direction at the
1347 * end of the bezier (which, if it has been shortened, is not the same
1348 * as the direction from pt[count-2] to pt[count-1]) */
1349 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
1350 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1351 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1352 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1354 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1355 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
1356 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
1359 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1361 PolyBezier(graphics
->hdc
, pti
, count
);
1372 /* Draws a combination of bezier curves and lines between points. */
1373 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1374 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1376 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1377 BYTE
*tp
= GdipAlloc(count
);
1378 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1380 GpStatus status
= GenericError
;
1386 if(!pti
|| !tp
|| !ptcopy
){
1387 status
= OutOfMemory
;
1391 for(i
= 1; i
< count
; i
++){
1392 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1393 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1394 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1395 ERR("Bad bezier points\n");
1402 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1404 /* If we are drawing caps, go through the points and adjust them accordingly,
1405 * and draw the caps. */
1407 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1408 case PathPointTypeBezier
:
1409 if(pen
->endcap
== LineCapArrowAnchor
)
1410 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1411 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1412 shorten_bezier_amt(&ptcopy
[count
- 4],
1413 pen
->width
* pen
->customend
->inset
, FALSE
);
1415 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
1416 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1417 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1418 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1421 case PathPointTypeLine
:
1422 if(pen
->endcap
== LineCapArrowAnchor
)
1423 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1424 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1426 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1427 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1428 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1429 pen
->customend
->inset
* pen
->width
);
1431 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
1432 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1437 ERR("Bad path last point\n");
1441 /* Find start of points */
1442 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1443 == PathPointTypeStart
); j
++);
1445 switch(types
[j
] & PathPointTypePathTypeMask
){
1446 case PathPointTypeBezier
:
1447 if(pen
->startcap
== LineCapArrowAnchor
)
1448 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1449 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1450 shorten_bezier_amt(&ptcopy
[j
- 1],
1451 pen
->width
* pen
->customstart
->inset
, TRUE
);
1453 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1454 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1455 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1456 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1459 case PathPointTypeLine
:
1460 if(pen
->startcap
== LineCapArrowAnchor
)
1461 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1462 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1464 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1465 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1466 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1467 pen
->customstart
->inset
* pen
->width
);
1469 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1470 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1475 ERR("Bad path points\n");
1480 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1482 for(i
= 0; i
< count
; i
++){
1483 tp
[i
] = convert_path_point_type(types
[i
]);
1486 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1498 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1502 BeginPath(graphics
->hdc
);
1503 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1504 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1505 EndPath(graphics
->hdc
);
1509 typedef struct _GraphicsContainerItem
{
1511 GraphicsContainer contid
;
1513 SmoothingMode smoothing
;
1514 CompositingQuality compqual
;
1515 InterpolationMode interpolation
;
1516 CompositingMode compmode
;
1517 TextRenderingHint texthint
;
1520 PixelOffsetMode pixeloffset
;
1522 GpMatrix
* worldtrans
;
1524 } GraphicsContainerItem
;
1526 static GpStatus
init_container(GraphicsContainerItem
** container
,
1527 GDIPCONST GpGraphics
* graphics
){
1530 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1534 (*container
)->contid
= graphics
->contid
+ 1;
1536 (*container
)->smoothing
= graphics
->smoothing
;
1537 (*container
)->compqual
= graphics
->compqual
;
1538 (*container
)->interpolation
= graphics
->interpolation
;
1539 (*container
)->compmode
= graphics
->compmode
;
1540 (*container
)->texthint
= graphics
->texthint
;
1541 (*container
)->scale
= graphics
->scale
;
1542 (*container
)->unit
= graphics
->unit
;
1543 (*container
)->textcontrast
= graphics
->textcontrast
;
1544 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1546 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1548 GdipFree(*container
);
1553 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1555 GdipDeleteMatrix((*container
)->worldtrans
);
1556 GdipFree(*container
);
1564 static void delete_container(GraphicsContainerItem
* container
){
1565 GdipDeleteMatrix(container
->worldtrans
);
1566 GdipDeleteRegion(container
->clip
);
1567 GdipFree(container
);
1570 static GpStatus
restore_container(GpGraphics
* graphics
,
1571 GDIPCONST GraphicsContainerItem
* container
){
1576 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1580 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1582 GdipDeleteMatrix(newTrans
);
1586 GdipDeleteMatrix(graphics
->worldtrans
);
1587 graphics
->worldtrans
= newTrans
;
1589 GdipDeleteRegion(graphics
->clip
);
1590 graphics
->clip
= newClip
;
1592 graphics
->contid
= container
->contid
- 1;
1594 graphics
->smoothing
= container
->smoothing
;
1595 graphics
->compqual
= container
->compqual
;
1596 graphics
->interpolation
= container
->interpolation
;
1597 graphics
->compmode
= container
->compmode
;
1598 graphics
->texthint
= container
->texthint
;
1599 graphics
->scale
= container
->scale
;
1600 graphics
->unit
= container
->unit
;
1601 graphics
->textcontrast
= container
->textcontrast
;
1602 graphics
->pixeloffset
= container
->pixeloffset
;
1607 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1613 if(graphics
->hwnd
) {
1614 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1615 return GenericError
;
1617 rect
->X
= wnd_rect
.left
;
1618 rect
->Y
= wnd_rect
.top
;
1619 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1620 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1621 }else if (graphics
->image
){
1622 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1623 if (stat
== Ok
&& unit
!= UnitPixel
)
1624 FIXME("need to convert from unit %i\n", unit
);
1628 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1629 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
1635 /* on success, rgn will contain the region of the graphics object which
1636 * is visible after clipping has been applied */
1637 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
1643 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
1646 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
1649 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
1652 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
1655 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
1658 GdipDeleteRegion(tmp
);
1662 void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
, HFONT
*hfont
)
1664 HDC hdc
= CreateCompatibleDC(0);
1666 REAL angle
, rel_width
, rel_height
;
1668 HFONT unscaled_font
;
1669 TEXTMETRICW textmet
;
1678 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
1679 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
1680 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
1681 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
1682 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
1683 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
1686 lfw
.lfHeight
= roundr(-font
->pixel_size
* rel_height
);
1687 unscaled_font
= CreateFontIndirectW(&lfw
);
1689 SelectObject(hdc
, unscaled_font
);
1690 GetTextMetricsW(hdc
, &textmet
);
1693 lfw
.lfHeight
= roundr(-font
->pixel_size
* rel_height
);
1694 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
1695 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
1697 *hfont
= CreateFontIndirectW(&lfw
);
1700 DeleteObject(unscaled_font
);
1703 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1705 TRACE("(%p, %p)\n", hdc
, graphics
);
1707 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1710 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1714 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1716 if(hDevice
!= NULL
) {
1717 FIXME("Don't know how to handle parameter hDevice\n");
1718 return NotImplemented
;
1724 if(graphics
== NULL
)
1725 return InvalidParameter
;
1727 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1728 if(!*graphics
) return OutOfMemory
;
1730 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1731 GdipFree(*graphics
);
1735 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1736 GdipFree((*graphics
)->worldtrans
);
1737 GdipFree(*graphics
);
1741 (*graphics
)->hdc
= hdc
;
1742 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1743 (*graphics
)->owndc
= FALSE
;
1744 (*graphics
)->smoothing
= SmoothingModeDefault
;
1745 (*graphics
)->compqual
= CompositingQualityDefault
;
1746 (*graphics
)->interpolation
= InterpolationModeBilinear
;
1747 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1748 (*graphics
)->compmode
= CompositingModeSourceOver
;
1749 (*graphics
)->unit
= UnitDisplay
;
1750 (*graphics
)->scale
= 1.0;
1751 (*graphics
)->busy
= FALSE
;
1752 (*graphics
)->textcontrast
= 4;
1753 list_init(&(*graphics
)->containers
);
1754 (*graphics
)->contid
= 0;
1756 TRACE("<-- %p\n", *graphics
);
1761 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
1765 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1766 if(!*graphics
) return OutOfMemory
;
1768 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1769 GdipFree(*graphics
);
1773 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1774 GdipFree((*graphics
)->worldtrans
);
1775 GdipFree(*graphics
);
1779 (*graphics
)->hdc
= NULL
;
1780 (*graphics
)->hwnd
= NULL
;
1781 (*graphics
)->owndc
= FALSE
;
1782 (*graphics
)->image
= image
;
1783 (*graphics
)->smoothing
= SmoothingModeDefault
;
1784 (*graphics
)->compqual
= CompositingQualityDefault
;
1785 (*graphics
)->interpolation
= InterpolationModeBilinear
;
1786 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1787 (*graphics
)->compmode
= CompositingModeSourceOver
;
1788 (*graphics
)->unit
= UnitDisplay
;
1789 (*graphics
)->scale
= 1.0;
1790 (*graphics
)->busy
= FALSE
;
1791 (*graphics
)->textcontrast
= 4;
1792 list_init(&(*graphics
)->containers
);
1793 (*graphics
)->contid
= 0;
1795 TRACE("<-- %p\n", *graphics
);
1800 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1805 TRACE("(%p, %p)\n", hwnd
, graphics
);
1809 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1811 ReleaseDC(hwnd
, hdc
);
1815 (*graphics
)->hwnd
= hwnd
;
1816 (*graphics
)->owndc
= TRUE
;
1821 /* FIXME: no icm handling */
1822 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
1824 TRACE("(%p, %p)\n", hwnd
, graphics
);
1826 return GdipCreateFromHWND(hwnd
, graphics
);
1829 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
1830 GpMetafile
**metafile
)
1834 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
1836 if(!hemf
|| !metafile
)
1837 return InvalidParameter
;
1840 FIXME("not implemented\n");
1842 return NotImplemented
;
1845 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1846 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1848 IStream
*stream
= NULL
;
1852 GpStatus retval
= Ok
;
1854 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1856 if(!hwmf
|| !metafile
|| !placeable
)
1857 return InvalidParameter
;
1860 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1862 return GenericError
;
1863 copy
= GdipAlloc(read
);
1864 GetMetaFileBitsEx(hwmf
, read
, copy
);
1866 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1869 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1870 copy
= GdipAlloc(read
);
1871 GetEnhMetaFileBits(hemf
, read
, copy
);
1872 DeleteEnhMetaFile(hemf
);
1874 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1875 ERR("could not make stream\n");
1877 retval
= GenericError
;
1881 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1883 retval
= OutOfMemory
;
1887 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1888 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1890 retval
= GenericError
;
1895 (*metafile
)->image
.type
= ImageTypeMetafile
;
1896 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
1897 (*metafile
)->image
.palette_flags
= 0;
1898 (*metafile
)->image
.palette_count
= 0;
1899 (*metafile
)->image
.palette_size
= 0;
1900 (*metafile
)->image
.palette_entries
= NULL
;
1901 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
1902 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
1903 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1904 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Top
) / ((REAL
) placeable
->Inch
);
1905 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1906 - placeable
->BoundingBox
.Left
));
1907 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1908 - placeable
->BoundingBox
.Top
));
1909 (*metafile
)->unit
= UnitPixel
;
1912 DeleteMetaFile(hwmf
);
1914 TRACE("<-- %p\n", *metafile
);
1918 GdipFree(*metafile
);
1919 IStream_Release(stream
);
1923 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1924 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1926 HMETAFILE hmf
= GetMetaFileW(file
);
1928 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1930 if(!hmf
) return InvalidParameter
;
1932 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1935 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
1936 GpMetafile
**metafile
)
1938 FIXME("(%p, %p): stub\n", file
, metafile
);
1939 return NotImplemented
;
1942 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
1943 GpMetafile
**metafile
)
1945 FIXME("(%p, %p): stub\n", stream
, metafile
);
1946 return NotImplemented
;
1949 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1950 UINT access
, IStream
**stream
)
1955 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1957 if(!stream
|| !filename
)
1958 return InvalidParameter
;
1960 if(access
& GENERIC_WRITE
)
1961 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1962 else if(access
& GENERIC_READ
)
1963 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1965 return InvalidParameter
;
1967 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1969 return hresult_to_status(ret
);
1972 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1974 GraphicsContainerItem
*cont
, *next
;
1976 TRACE("(%p)\n", graphics
);
1978 if(!graphics
) return InvalidParameter
;
1979 if(graphics
->busy
) return ObjectBusy
;
1981 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
1983 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
1989 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1991 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
1992 list_remove(&cont
->entry
);
1993 delete_container(cont
);
1996 GdipDeleteRegion(graphics
->clip
);
1997 GdipDeleteMatrix(graphics
->worldtrans
);
2003 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2004 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2006 INT save_state
, num_pts
;
2007 GpPointF points
[MAX_ARC_PTS
];
2010 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2011 width
, height
, startAngle
, sweepAngle
);
2013 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2014 return InvalidParameter
;
2021 FIXME("graphics object has no HDC\n");
2025 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2027 save_state
= prepare_dc(graphics
, pen
);
2029 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
2031 restore_dc(graphics
, save_state
);
2036 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2037 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2039 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2040 width
, height
, startAngle
, sweepAngle
);
2042 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2045 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2046 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2052 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2053 x2
, y2
, x3
, y3
, x4
, y4
);
2055 if(!graphics
|| !pen
)
2056 return InvalidParameter
;
2063 FIXME("graphics object has no HDC\n");
2076 save_state
= prepare_dc(graphics
, pen
);
2078 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2080 restore_dc(graphics
, save_state
);
2085 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2086 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2092 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2093 x2
, y2
, x3
, y3
, x4
, y4
);
2095 if(!graphics
|| !pen
)
2096 return InvalidParameter
;
2103 FIXME("graphics object has no HDC\n");
2116 save_state
= prepare_dc(graphics
, pen
);
2118 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2120 restore_dc(graphics
, save_state
);
2125 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2126 GDIPCONST GpPointF
*points
, INT count
)
2131 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2133 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2134 return InvalidParameter
;
2139 for(i
= 0; i
< floor(count
/ 4); i
++){
2140 ret
= GdipDrawBezier(graphics
, pen
,
2141 points
[4*i
].X
, points
[4*i
].Y
,
2142 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
2143 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
2144 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
2152 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2153 GDIPCONST GpPoint
*points
, INT count
)
2159 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2161 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2162 return InvalidParameter
;
2167 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2171 for(i
= 0; i
< count
; i
++){
2172 pts
[i
].X
= (REAL
)points
[i
].X
;
2173 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2176 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2183 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2184 GDIPCONST GpPointF
*points
, INT count
)
2186 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2188 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2191 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2192 GDIPCONST GpPoint
*points
, INT count
)
2194 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2196 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2199 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2200 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2205 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2207 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2208 return InvalidParameter
;
2213 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
2216 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2218 GdipDeletePath(path
);
2222 stat
= GdipDrawPath(graphics
, pen
, path
);
2224 GdipDeletePath(path
);
2229 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2230 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2236 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2238 if(!points
|| count
<= 0)
2239 return InvalidParameter
;
2241 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2245 for(i
= 0; i
< count
; i
++){
2246 ptf
[i
].X
= (REAL
)points
[i
].X
;
2247 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2250 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2257 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2258 GDIPCONST GpPointF
*points
, INT count
)
2260 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2262 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2265 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2266 GDIPCONST GpPoint
*points
, INT count
)
2272 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2275 return InvalidParameter
;
2277 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2281 for(i
= 0; i
< count
; i
++){
2282 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2283 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2286 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2292 /* Approximates cardinal spline with Bezier curves. */
2293 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2294 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2296 /* PolyBezier expects count*3-2 points. */
2297 INT i
, len_pt
= count
*3-2, save_state
;
2299 REAL x1
, x2
, y1
, y2
;
2302 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2304 if(!graphics
|| !pen
)
2305 return InvalidParameter
;
2311 return InvalidParameter
;
2315 FIXME("graphics object has no HDC\n");
2319 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
2323 tension
= tension
* TENSION_CONST
;
2325 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
2328 pt
[0].X
= points
[0].X
;
2329 pt
[0].Y
= points
[0].Y
;
2333 for(i
= 0; i
< count
-2; i
++){
2334 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
2338 pt
[3*i
+3].X
= points
[i
+1].X
;
2339 pt
[3*i
+3].Y
= points
[i
+1].Y
;
2344 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
2345 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
2347 pt
[len_pt
-2].X
= x1
;
2348 pt
[len_pt
-2].Y
= y1
;
2349 pt
[len_pt
-1].X
= points
[count
-1].X
;
2350 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
2352 save_state
= prepare_dc(graphics
, pen
);
2354 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
2357 restore_dc(graphics
, save_state
);
2362 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2363 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2369 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2372 return InvalidParameter
;
2374 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2378 for(i
= 0; i
< count
; i
++){
2379 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2380 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2383 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2389 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2390 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2393 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2395 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2396 return InvalidParameter
;
2399 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2402 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2403 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2406 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2412 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2413 return InvalidParameter
;
2416 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2419 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2420 REAL y
, REAL width
, REAL height
)
2426 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2428 if(!graphics
|| !pen
)
2429 return InvalidParameter
;
2436 FIXME("graphics object has no HDC\n");
2442 ptf
[1].X
= x
+ width
;
2443 ptf
[1].Y
= y
+ height
;
2445 save_state
= prepare_dc(graphics
, pen
);
2446 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2448 transform_and_round_points(graphics
, pti
, ptf
, 2);
2450 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2452 restore_dc(graphics
, save_state
);
2457 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2458 INT y
, INT width
, INT height
)
2460 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2462 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2466 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2471 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2473 if(!graphics
|| !image
)
2474 return InvalidParameter
;
2476 GdipGetImageWidth(image
, &width
);
2477 GdipGetImageHeight(image
, &height
);
2479 /* FIXME: we should use the graphics and image dpi, somehow */
2481 points
[0].X
= points
[2].X
= x
;
2482 points
[0].Y
= points
[1].Y
= y
;
2483 points
[1].X
= x
+ width
;
2484 points
[2].Y
= y
+ height
;
2486 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
2487 UnitPixel
, NULL
, NULL
, NULL
);
2490 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2493 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2495 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2498 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2499 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2503 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2505 points
[0].X
= points
[2].X
= x
;
2506 points
[0].Y
= points
[1].Y
= y
;
2508 /* FIXME: convert image coordinates to Graphics coordinates? */
2509 points
[1].X
= x
+ srcwidth
;
2510 points
[2].Y
= y
+ srcheight
;
2512 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2513 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2516 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2517 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2520 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2523 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2524 GDIPCONST GpPointF
*dstpoints
, INT count
)
2526 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
2527 return NotImplemented
;
2530 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2531 GDIPCONST GpPoint
*dstpoints
, INT count
)
2533 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
2534 return NotImplemented
;
2537 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2538 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2539 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2540 DrawImageAbort callback
, VOID
* callbackData
)
2547 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2548 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2552 return NotImplemented
;
2554 if(!graphics
|| !image
|| !points
|| count
!= 3)
2555 return InvalidParameter
;
2557 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2558 debugstr_pointf(&points
[2]));
2560 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2561 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2562 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2563 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
2565 transform_and_round_points(graphics
, pti
, ptf
, 4);
2571 FIXME("graphics object has no HDC\n");
2574 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2575 if(srcUnit
== UnitInch
)
2576 dx
= dy
= (REAL
) INCH_HIMETRIC
;
2577 else if(srcUnit
== UnitPixel
){
2578 dx
= ((REAL
) INCH_HIMETRIC
) /
2579 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
2580 dy
= ((REAL
) INCH_HIMETRIC
) /
2581 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
2584 return NotImplemented
;
2586 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2587 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2588 srcx
* dx
, srcy
* dy
,
2589 srcwidth
* dx
, srcheight
* dy
,
2592 callback(callbackData
);
2593 return GenericError
;
2596 else if (image
->type
== ImageTypeBitmap
)
2598 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2601 if (srcUnit
== UnitInch
)
2602 dx
= dy
= 96.0; /* FIXME: use the image resolution */
2603 else if (srcUnit
== UnitPixel
)
2606 return NotImplemented
;
2610 srcwidth
= srcwidth
* dx
;
2611 srcheight
= srcheight
* dy
;
2613 if (imageAttributes
||
2614 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2615 !((GpBitmap
*)image
)->hbitmap
||
2616 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2617 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2618 srcx
< 0 || srcy
< 0 ||
2619 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2626 int i
, x
, y
, src_stride
, dst_stride
;
2627 GpMatrix
*dst_to_src
;
2628 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2629 LPBYTE src_data
, dst_data
;
2630 BitmapData lockeddata
;
2631 InterpolationMode interpolation
= graphics
->interpolation
;
2632 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2633 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2634 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2636 if (!imageAttributes
)
2637 imageAttributes
= &defaultImageAttributes
;
2639 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2640 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2643 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2644 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2645 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2646 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2649 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2650 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2651 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2652 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2653 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2654 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2656 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
2657 if (stat
!= Ok
) return stat
;
2659 stat
= GdipInvertMatrix(dst_to_src
);
2662 GdipDeleteMatrix(dst_to_src
);
2666 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2669 GdipDeleteMatrix(dst_to_src
);
2673 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2675 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2676 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2678 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
2682 GdipDeleteMatrix(dst_to_src
);
2685 src_stride
= sizeof(ARGB
) * src_area
.Width
;
2687 /* Read the bits we need from the source bitmap into an ARGB buffer. */
2688 lockeddata
.Width
= src_area
.Width
;
2689 lockeddata
.Height
= src_area
.Height
;
2690 lockeddata
.Stride
= src_stride
;
2691 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
2692 lockeddata
.Scan0
= src_data
;
2694 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
2695 PixelFormat32bppARGB
, &lockeddata
);
2698 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2702 if (src_data
!= dst_data
)
2705 GdipDeleteMatrix(dst_to_src
);
2709 apply_image_attributes(imageAttributes
, src_data
,
2710 src_area
.Width
, src_area
.Height
,
2711 src_stride
, ColorAdjustTypeBitmap
);
2713 /* Transform the bits as needed to the destination. */
2714 GdipTransformMatrixPoints(dst_to_src
, dst_to_src_points
, 3);
2716 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
2717 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
2718 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
2719 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
2721 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2723 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2725 GpPointF src_pointf
;
2728 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
2729 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
2731 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2733 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
2734 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
, imageAttributes
, interpolation
);
2740 GdipDeleteMatrix(dst_to_src
);
2744 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
2745 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
2754 int temp_hdc
=0, temp_bitmap
=0;
2755 HBITMAP hbitmap
, old_hbm
=NULL
;
2757 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
2758 bitmap
->format
== PixelFormat24bppRGB
||
2759 bitmap
->format
== PixelFormat32bppRGB
||
2760 bitmap
->format
== PixelFormat32bppPARGB
))
2762 BITMAPINFOHEADER bih
;
2764 PixelFormat dst_format
;
2766 /* we can't draw a bitmap of this format directly */
2767 hdc
= CreateCompatibleDC(0);
2771 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
2772 bih
.biWidth
= bitmap
->width
;
2773 bih
.biHeight
= -bitmap
->height
;
2775 bih
.biBitCount
= 32;
2776 bih
.biCompression
= BI_RGB
;
2777 bih
.biSizeImage
= 0;
2778 bih
.biXPelsPerMeter
= 0;
2779 bih
.biYPelsPerMeter
= 0;
2781 bih
.biClrImportant
= 0;
2783 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
2784 (void**)&temp_bits
, NULL
, 0);
2786 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2787 dst_format
= PixelFormat32bppPARGB
;
2789 dst_format
= PixelFormat32bppRGB
;
2791 convert_pixels(bitmap
->width
, bitmap
->height
,
2792 bitmap
->width
*4, temp_bits
, dst_format
,
2793 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
2797 hbitmap
= bitmap
->hbitmap
;
2799 temp_hdc
= (hdc
== 0);
2804 if (!hdc
) hdc
= CreateCompatibleDC(0);
2805 old_hbm
= SelectObject(hdc
, hbitmap
);
2808 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2812 bf
.BlendOp
= AC_SRC_OVER
;
2814 bf
.SourceConstantAlpha
= 255;
2815 bf
.AlphaFormat
= AC_SRC_ALPHA
;
2817 GdiAlphaBlend(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2818 hdc
, srcx
, srcy
, srcwidth
, srcheight
, bf
);
2822 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2823 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
2828 SelectObject(hdc
, old_hbm
);
2833 DeleteObject(hbitmap
);
2838 ERR("GpImage with no IPicture or HBITMAP?!\n");
2839 return NotImplemented
;
2845 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
2846 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
2847 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2848 DrawImageAbort callback
, VOID
* callbackData
)
2850 GpPointF pointsF
[3];
2853 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
2854 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2857 if(!points
|| count
!=3)
2858 return InvalidParameter
;
2860 for(i
= 0; i
< count
; i
++){
2861 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2862 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2865 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
2866 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
2867 callback
, callbackData
);
2870 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
2871 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
2872 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
2873 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
2874 VOID
* callbackData
)
2878 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2879 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2880 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2884 points
[1].X
= dstx
+ dstwidth
;
2887 points
[2].Y
= dsty
+ dstheight
;
2889 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2890 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2893 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
2894 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
2895 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
2896 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
2897 VOID
* callbackData
)
2901 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2902 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2903 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2907 points
[1].X
= dstx
+ dstwidth
;
2910 points
[2].Y
= dsty
+ dstheight
;
2912 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2913 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2916 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
2917 REAL x
, REAL y
, REAL width
, REAL height
)
2923 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
2925 if(!graphics
|| !image
)
2926 return InvalidParameter
;
2928 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
2932 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
2933 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
2934 unit
, NULL
, NULL
, NULL
);
2937 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
2938 INT x
, INT y
, INT width
, INT height
)
2940 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
2942 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
2945 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2946 REAL y1
, REAL x2
, REAL y2
)
2952 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2954 if(!pen
|| !graphics
)
2955 return InvalidParameter
;
2962 FIXME("graphics object has no HDC\n");
2971 save_state
= prepare_dc(graphics
, pen
);
2973 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2975 restore_dc(graphics
, save_state
);
2980 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2981 INT y1
, INT x2
, INT y2
)
2987 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2989 if(!pen
|| !graphics
)
2990 return InvalidParameter
;
2997 FIXME("graphics object has no HDC\n");
3006 save_state
= prepare_dc(graphics
, pen
);
3008 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3010 restore_dc(graphics
, save_state
);
3015 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3016 GpPointF
*points
, INT count
)
3021 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3023 if(!pen
|| !graphics
|| (count
< 2))
3024 return InvalidParameter
;
3031 FIXME("graphics object has no HDC\n");
3035 save_state
= prepare_dc(graphics
, pen
);
3037 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
3039 restore_dc(graphics
, save_state
);
3044 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3045 GpPoint
*points
, INT count
)
3049 GpPointF
*ptf
= NULL
;
3052 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3054 if(!pen
|| !graphics
|| (count
< 2))
3055 return InvalidParameter
;
3062 FIXME("graphics object has no HDC\n");
3066 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3067 if(!ptf
) return OutOfMemory
;
3069 for(i
= 0; i
< count
; i
++){
3070 ptf
[i
].X
= (REAL
) points
[i
].X
;
3071 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3074 save_state
= prepare_dc(graphics
, pen
);
3076 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
3078 restore_dc(graphics
, save_state
);
3084 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3089 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3091 if(!pen
|| !graphics
)
3092 return InvalidParameter
;
3099 FIXME("graphics object has no HDC\n");
3103 save_state
= prepare_dc(graphics
, pen
);
3105 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3106 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3108 restore_dc(graphics
, save_state
);
3113 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3114 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3118 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3119 width
, height
, startAngle
, sweepAngle
);
3121 if(!graphics
|| !pen
)
3122 return InvalidParameter
;
3129 FIXME("graphics object has no HDC\n");
3133 save_state
= prepare_dc(graphics
, pen
);
3134 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3136 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3138 restore_dc(graphics
, save_state
);
3143 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3144 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3146 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3147 width
, height
, startAngle
, sweepAngle
);
3149 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3152 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3153 REAL y
, REAL width
, REAL height
)
3159 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3161 if(!pen
|| !graphics
)
3162 return InvalidParameter
;
3169 FIXME("graphics object has no HDC\n");
3175 ptf
[1].X
= x
+ width
;
3177 ptf
[2].X
= x
+ width
;
3178 ptf
[2].Y
= y
+ height
;
3180 ptf
[3].Y
= y
+ height
;
3182 save_state
= prepare_dc(graphics
, pen
);
3183 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3185 transform_and_round_points(graphics
, pti
, ptf
, 4);
3186 Polygon(graphics
->hdc
, pti
, 4);
3188 restore_dc(graphics
, save_state
);
3193 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3194 INT y
, INT width
, INT height
)
3196 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3198 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3201 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3202 GDIPCONST GpRectF
* rects
, INT count
)
3208 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3210 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3211 return InvalidParameter
;
3218 FIXME("graphics object has no HDC\n");
3222 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
3223 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
3231 for(i
= 0; i
< count
; i
++){
3232 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
3233 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
3234 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
3235 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
3238 save_state
= prepare_dc(graphics
, pen
);
3239 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3241 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
3243 for(i
= 0; i
< count
; i
++)
3244 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
3246 restore_dc(graphics
, save_state
);
3254 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3255 GDIPCONST GpRect
* rects
, INT count
)
3261 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3263 if(!rects
|| count
<=0)
3264 return InvalidParameter
;
3266 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3270 for(i
= 0;i
< count
;i
++){
3271 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3272 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3273 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3274 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3277 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3283 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3284 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3289 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3290 count
, tension
, fill
);
3292 if(!graphics
|| !brush
|| !points
)
3293 return InvalidParameter
;
3298 if(count
== 1) /* Do nothing */
3301 stat
= GdipCreatePath(fill
, &path
);
3305 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3307 GdipDeletePath(path
);
3311 stat
= GdipFillPath(graphics
, brush
, path
);
3313 GdipDeletePath(path
);
3317 GdipDeletePath(path
);
3322 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3323 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3329 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3330 count
, tension
, fill
);
3332 if(!points
|| count
== 0)
3333 return InvalidParameter
;
3335 if(count
== 1) /* Do nothing */
3338 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3342 for(i
= 0;i
< count
;i
++){
3343 ptf
[i
].X
= (REAL
)points
[i
].X
;
3344 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3347 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3354 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3355 GDIPCONST GpPointF
*points
, INT count
)
3357 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3358 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3359 0.5f
, FillModeAlternate
);
3362 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3363 GDIPCONST GpPoint
*points
, INT count
)
3365 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3366 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3367 0.5f
, FillModeAlternate
);
3370 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3371 REAL y
, REAL width
, REAL height
)
3376 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3378 if(!graphics
|| !brush
)
3379 return InvalidParameter
;
3384 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3388 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3391 stat
= GdipFillPath(graphics
, brush
, path
);
3393 GdipDeletePath(path
);
3399 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3400 INT y
, INT width
, INT height
)
3402 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3404 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3407 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3412 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3413 return NotImplemented
;
3415 save_state
= SaveDC(graphics
->hdc
);
3416 EndPath(graphics
->hdc
);
3417 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3420 BeginPath(graphics
->hdc
);
3421 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3422 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3427 EndPath(graphics
->hdc
);
3428 brush_fill_path(graphics
, brush
);
3433 RestoreDC(graphics
->hdc
, save_state
);
3438 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3443 if (!brush_can_fill_pixels(brush
))
3444 return NotImplemented
;
3446 /* FIXME: This could probably be done more efficiently without regions. */
3448 stat
= GdipCreateRegionPath(path
, &rgn
);
3452 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3454 GdipDeleteRegion(rgn
);
3460 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3462 GpStatus stat
= NotImplemented
;
3464 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3466 if(!brush
|| !graphics
|| !path
)
3467 return InvalidParameter
;
3472 if (!graphics
->image
)
3473 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3475 if (stat
== NotImplemented
)
3476 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3478 if (stat
== NotImplemented
)
3480 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3487 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3488 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3493 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3494 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3496 if(!graphics
|| !brush
)
3497 return InvalidParameter
;
3502 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3506 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3509 stat
= GdipFillPath(graphics
, brush
, path
);
3511 GdipDeletePath(path
);
3517 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3518 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3520 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3521 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3523 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3526 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3527 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3532 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3534 if(!graphics
|| !brush
|| !points
|| !count
)
3535 return InvalidParameter
;
3540 stat
= GdipCreatePath(fillMode
, &path
);
3544 stat
= GdipAddPathPolygon(path
, points
, count
);
3547 stat
= GdipFillPath(graphics
, brush
, path
);
3549 GdipDeletePath(path
);
3555 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3556 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3561 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3563 if(!graphics
|| !brush
|| !points
|| !count
)
3564 return InvalidParameter
;
3569 stat
= GdipCreatePath(fillMode
, &path
);
3573 stat
= GdipAddPathPolygonI(path
, points
, count
);
3576 stat
= GdipFillPath(graphics
, brush
, path
);
3578 GdipDeletePath(path
);
3584 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3585 GDIPCONST GpPointF
*points
, INT count
)
3587 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3589 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3592 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3593 GDIPCONST GpPoint
*points
, INT count
)
3595 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3597 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3600 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3601 REAL x
, REAL y
, REAL width
, REAL height
)
3606 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3608 if(!graphics
|| !brush
)
3609 return InvalidParameter
;
3614 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3618 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3621 stat
= GdipFillPath(graphics
, brush
, path
);
3623 GdipDeletePath(path
);
3629 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3630 INT x
, INT y
, INT width
, INT height
)
3632 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3634 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
3637 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3643 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3646 return InvalidParameter
;
3648 for(i
= 0; i
< count
; i
++){
3649 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
3650 if(ret
!= Ok
) return ret
;
3656 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3663 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3665 if(!rects
|| count
<= 0)
3666 return InvalidParameter
;
3668 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3672 for(i
= 0; i
< count
; i
++){
3673 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3674 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3675 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3676 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3679 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3685 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3693 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3694 return NotImplemented
;
3696 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3700 save_state
= SaveDC(graphics
->hdc
);
3701 EndPath(graphics
->hdc
);
3703 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3705 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3707 BeginPath(graphics
->hdc
);
3708 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3709 EndPath(graphics
->hdc
);
3711 brush_fill_path(graphics
, brush
);
3714 RestoreDC(graphics
->hdc
, save_state
);
3721 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3725 GpRegion
*temp_region
;
3726 GpMatrix
*world_to_device
, *identity
;
3727 GpRectF graphics_bounds
;
3728 UINT scans_count
, i
;
3730 GpRect
*scans
= NULL
;
3733 if (!brush_can_fill_pixels(brush
))
3734 return NotImplemented
;
3736 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3739 stat
= GdipCloneRegion(region
, &temp_region
);
3743 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3744 CoordinateSpaceWorld
, &world_to_device
);
3748 stat
= GdipTransformRegion(temp_region
, world_to_device
);
3750 GdipDeleteMatrix(world_to_device
);
3754 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
3757 stat
= GdipCreateMatrix(&identity
);
3761 stat
= GdipGetRegionScansCount(temp_region
, &scans_count
, identity
);
3763 if (stat
== Ok
&& scans_count
!= 0)
3765 scans
= GdipAlloc(sizeof(*scans
) * scans_count
);
3771 stat
= GdipGetRegionScansI(temp_region
, scans
, &dummy
, identity
);
3778 GdipDeleteMatrix(identity
);
3781 GdipDeleteRegion(temp_region
);
3784 if (stat
== Ok
&& scans_count
== 0)
3789 if (!graphics
->image
)
3791 /* If we have to go through gdi32, use as few alpha blends as possible. */
3792 INT min_x
, min_y
, max_x
, max_y
;
3793 UINT data_width
, data_height
;
3797 max_x
= scans
[0].X
+scans
[0].Width
;
3798 max_y
= scans
[0].Y
+scans
[0].Height
;
3800 for (i
=1; i
<scans_count
; i
++)
3802 min_x
= min(min_x
, scans
[i
].X
);
3803 min_y
= min(min_y
, scans
[i
].Y
);
3804 max_x
= max(max_x
, scans
[i
].X
+scans
[i
].Width
);
3805 max_y
= max(max_y
, scans
[i
].Y
+scans
[i
].Height
);
3808 data_width
= max_x
- min_x
;
3809 data_height
= max_y
- min_y
;
3811 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * data_width
* data_height
);
3817 for (i
=0; i
<scans_count
; i
++)
3819 stat
= brush_fill_pixels(graphics
, brush
,
3820 pixel_data
+ (scans
[i
].X
- min_x
) + (scans
[i
].Y
- min_y
) * data_width
,
3821 &scans
[i
], data_width
);
3829 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
,
3830 (BYTE
*)pixel_data
, data_width
, data_height
,
3834 GdipFree(pixel_data
);
3841 for (i
=0; i
<scans_count
; i
++)
3843 UINT size
= scans
[i
].Width
* scans
[i
].Height
;
3845 if (size
> max_size
)
3849 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * max_size
);
3855 for (i
=0; i
<scans_count
; i
++)
3857 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
, &scans
[i
],
3862 stat
= alpha_blend_pixels(graphics
, scans
[i
].X
, scans
[i
].Y
,
3863 (BYTE
*)pixel_data
, scans
[i
].Width
, scans
[i
].Height
,
3864 scans
[i
].Width
* 4);
3871 GdipFree(pixel_data
);
3881 /*****************************************************************************
3882 * GdipFillRegion [GDIPLUS.@]
3884 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3887 GpStatus stat
= NotImplemented
;
3889 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
3891 if (!(graphics
&& brush
&& region
))
3892 return InvalidParameter
;
3897 if (!graphics
->image
)
3898 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
3900 if (stat
== NotImplemented
)
3901 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
3903 if (stat
== NotImplemented
)
3905 FIXME("not implemented for brushtype %i\n", brush
->bt
);
3912 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
3914 TRACE("(%p,%u)\n", graphics
, intention
);
3917 return InvalidParameter
;
3922 /* We have no internal operation queue, so there's no need to clear it. */
3930 /*****************************************************************************
3931 * GdipGetClipBounds [GDIPLUS.@]
3933 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3935 TRACE("(%p, %p)\n", graphics
, rect
);
3938 return InvalidParameter
;
3943 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
3946 /*****************************************************************************
3947 * GdipGetClipBoundsI [GDIPLUS.@]
3949 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3951 TRACE("(%p, %p)\n", graphics
, rect
);
3954 return InvalidParameter
;
3959 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
3962 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3963 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
3964 CompositingMode
*mode
)
3966 TRACE("(%p, %p)\n", graphics
, mode
);
3968 if(!graphics
|| !mode
)
3969 return InvalidParameter
;
3974 *mode
= graphics
->compmode
;
3979 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3980 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
3981 CompositingQuality
*quality
)
3983 TRACE("(%p, %p)\n", graphics
, quality
);
3985 if(!graphics
|| !quality
)
3986 return InvalidParameter
;
3991 *quality
= graphics
->compqual
;
3996 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3997 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
3998 InterpolationMode
*mode
)
4000 TRACE("(%p, %p)\n", graphics
, mode
);
4002 if(!graphics
|| !mode
)
4003 return InvalidParameter
;
4008 *mode
= graphics
->interpolation
;
4013 /* FIXME: Need to handle color depths less than 24bpp */
4014 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4016 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4018 if(!graphics
|| !argb
)
4019 return InvalidParameter
;
4027 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4029 TRACE("(%p, %p)\n", graphics
, scale
);
4031 if(!graphics
|| !scale
)
4032 return InvalidParameter
;
4037 *scale
= graphics
->scale
;
4042 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4044 TRACE("(%p, %p)\n", graphics
, unit
);
4046 if(!graphics
|| !unit
)
4047 return InvalidParameter
;
4052 *unit
= graphics
->unit
;
4057 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4058 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4061 TRACE("(%p, %p)\n", graphics
, mode
);
4063 if(!graphics
|| !mode
)
4064 return InvalidParameter
;
4069 *mode
= graphics
->pixeloffset
;
4074 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4075 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4077 TRACE("(%p, %p)\n", graphics
, mode
);
4079 if(!graphics
|| !mode
)
4080 return InvalidParameter
;
4085 *mode
= graphics
->smoothing
;
4090 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4092 TRACE("(%p, %p)\n", graphics
, contrast
);
4094 if(!graphics
|| !contrast
)
4095 return InvalidParameter
;
4097 *contrast
= graphics
->textcontrast
;
4102 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4103 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4104 TextRenderingHint
*hint
)
4106 TRACE("(%p, %p)\n", graphics
, hint
);
4108 if(!graphics
|| !hint
)
4109 return InvalidParameter
;
4114 *hint
= graphics
->texthint
;
4119 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4124 TRACE("(%p, %p)\n", graphics
, rect
);
4126 if(!graphics
|| !rect
)
4127 return InvalidParameter
;
4132 /* intersect window and graphics clipping regions */
4133 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4136 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4139 /* get bounds of the region */
4140 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4143 GdipDeleteRegion(clip_rgn
);
4148 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4153 TRACE("(%p, %p)\n", graphics
, rect
);
4155 if(!graphics
|| !rect
)
4156 return InvalidParameter
;
4158 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4160 rect
->X
= roundr(rectf
.X
);
4161 rect
->Y
= roundr(rectf
.Y
);
4162 rect
->Width
= roundr(rectf
.Width
);
4163 rect
->Height
= roundr(rectf
.Height
);
4169 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4171 TRACE("(%p, %p)\n", graphics
, matrix
);
4173 if(!graphics
|| !matrix
)
4174 return InvalidParameter
;
4179 *matrix
= *graphics
->worldtrans
;
4183 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4189 TRACE("(%p, %x)\n", graphics
, color
);
4192 return InvalidParameter
;
4197 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4200 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4201 GdipDeleteBrush((GpBrush
*)brush
);
4205 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4206 wnd_rect
.Width
, wnd_rect
.Height
);
4208 GdipDeleteBrush((GpBrush
*)brush
);
4213 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4215 TRACE("(%p, %p)\n", graphics
, res
);
4217 if(!graphics
|| !res
)
4218 return InvalidParameter
;
4220 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4223 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4229 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4231 if(!graphics
|| !result
)
4232 return InvalidParameter
;
4239 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4240 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4243 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4246 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4249 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4252 GdipDeleteRegion(rgn
);
4256 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4258 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4261 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4267 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4269 if(!graphics
|| !result
)
4270 return InvalidParameter
;
4277 pts
[1].X
= x
+ width
;
4278 pts
[1].Y
= y
+ height
;
4280 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4281 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4284 pts
[1].X
-= pts
[0].X
;
4285 pts
[1].Y
-= pts
[0].Y
;
4287 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4290 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4293 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4296 GdipDeleteRegion(rgn
);
4300 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4302 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4305 GpStatus
gdip_format_string(HDC hdc
,
4306 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4307 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4308 gdip_format_string_callback callback
, void *user_data
)
4311 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4312 nheight
, lineend
, lineno
= 0;
4314 StringAlignment halign
;
4318 if(length
== -1) length
= lstrlenW(string
);
4320 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4321 if(!stringdup
) return OutOfMemory
;
4323 nwidth
= roundr(rect
->Width
);
4324 nheight
= roundr(rect
->Height
);
4326 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
4327 if (rect
->Height
>= INT_MAX
|| rect
->Width
< 0.5) nheight
= INT_MAX
;
4329 for(i
= 0, j
= 0; i
< length
; i
++){
4330 /* FIXME: This makes the indexes passed to callback inaccurate. */
4331 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4334 stringdup
[j
] = string
[i
];
4340 if (format
) halign
= format
->align
;
4341 else halign
= StringAlignmentNear
;
4343 while(sum
< length
){
4344 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4345 nwidth
, &fit
, NULL
, &size
);
4351 for(lret
= 0; lret
< fit
; lret
++)
4352 if(*(stringdup
+ sum
+ lret
) == '\n')
4355 /* Line break code (may look strange, but it imitates windows). */
4357 lineend
= fit
= lret
; /* this is not an off-by-one error */
4358 else if(fit
< (length
- sum
)){
4359 if(*(stringdup
+ sum
+ fit
) == ' ')
4360 while(*(stringdup
+ sum
+ fit
) == ' ')
4363 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4366 if(*(stringdup
+ sum
+ fit
) == '\t')
4375 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4376 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4382 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4383 nwidth
, &j
, NULL
, &size
);
4385 bounds
.Width
= size
.cx
;
4387 if(height
+ size
.cy
> nheight
)
4388 bounds
.Height
= nheight
- (height
+ size
.cy
);
4390 bounds
.Height
= size
.cy
;
4392 bounds
.Y
= rect
->Y
+ height
;
4396 case StringAlignmentNear
:
4400 case StringAlignmentCenter
:
4401 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4403 case StringAlignmentFar
:
4404 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4408 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4409 font
, rect
, format
, lineno
, &bounds
, user_data
);
4414 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4418 if(height
> nheight
)
4421 /* Stop if this was a linewrap (but not if it was a linebreak). */
4422 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
4426 GdipFree(stringdup
);
4431 struct measure_ranges_args
{
4435 static GpStatus
measure_ranges_callback(HDC hdc
,
4436 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4437 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4438 INT lineno
, const RectF
*bounds
, void *user_data
)
4442 struct measure_ranges_args
*args
= user_data
;
4444 for (i
=0; i
<format
->range_count
; i
++)
4446 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4447 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4448 if (range_start
< range_end
)
4453 range_rect
.Y
= bounds
->Y
;
4454 range_rect
.Height
= bounds
->Height
;
4456 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4457 INT_MAX
, NULL
, NULL
, &range_size
);
4458 range_rect
.X
= bounds
->X
+ range_size
.cx
;
4460 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4461 INT_MAX
, NULL
, NULL
, &range_size
);
4462 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
4464 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4473 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4474 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4475 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4476 INT regionCount
, GpRegion
** regions
)
4481 struct measure_ranges_args args
;
4482 HDC hdc
, temp_hdc
=NULL
;
4484 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4485 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4487 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4488 return InvalidParameter
;
4490 if (regionCount
< stringFormat
->range_count
)
4491 return InvalidParameter
;
4495 hdc
= temp_hdc
= CreateCompatibleDC(0);
4496 if (!temp_hdc
) return OutOfMemory
;
4499 hdc
= graphics
->hdc
;
4501 if (stringFormat
->attr
)
4502 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4504 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&font
->lfw
));
4506 for (i
=0; i
<stringFormat
->range_count
; i
++)
4508 stat
= GdipSetEmpty(regions
[i
]);
4513 args
.regions
= regions
;
4515 stat
= gdip_format_string(hdc
, string
, length
, font
, layoutRect
, stringFormat
,
4516 measure_ranges_callback
, &args
);
4518 DeleteObject(SelectObject(hdc
, oldfont
));
4526 struct measure_string_args
{
4528 INT
*codepointsfitted
;
4532 static GpStatus
measure_string_callback(HDC hdc
,
4533 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4534 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4535 INT lineno
, const RectF
*bounds
, void *user_data
)
4537 struct measure_string_args
*args
= user_data
;
4539 if (bounds
->Width
> args
->bounds
->Width
)
4540 args
->bounds
->Width
= bounds
->Width
;
4542 if (bounds
->Height
+ bounds
->Y
> args
->bounds
->Height
+ args
->bounds
->Y
)
4543 args
->bounds
->Height
= bounds
->Height
+ bounds
->Y
- args
->bounds
->Y
;
4545 if (args
->codepointsfitted
)
4546 *args
->codepointsfitted
= index
+ length
;
4548 if (args
->linesfilled
)
4549 (*args
->linesfilled
)++;
4554 /* Find the smallest rectangle that bounds the text when it is printed in rect
4555 * according to the format options listed in format. If rect has 0 width and
4556 * height, then just find the smallest rectangle that bounds the text when it's
4557 * printed at location (rect->X, rect-Y). */
4558 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4559 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4560 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4561 INT
*codepointsfitted
, INT
*linesfilled
)
4564 struct measure_string_args args
;
4565 HDC temp_hdc
=NULL
, hdc
;
4567 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4568 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4569 bounds
, codepointsfitted
, linesfilled
);
4571 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4572 return InvalidParameter
;
4576 hdc
= temp_hdc
= CreateCompatibleDC(0);
4577 if (!temp_hdc
) return OutOfMemory
;
4580 hdc
= graphics
->hdc
;
4582 if(linesfilled
) *linesfilled
= 0;
4583 if(codepointsfitted
) *codepointsfitted
= 0;
4586 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4588 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&font
->lfw
));
4590 bounds
->X
= rect
->X
;
4591 bounds
->Y
= rect
->Y
;
4592 bounds
->Width
= 0.0;
4593 bounds
->Height
= 0.0;
4595 args
.bounds
= bounds
;
4596 args
.codepointsfitted
= codepointsfitted
;
4597 args
.linesfilled
= linesfilled
;
4599 gdip_format_string(hdc
, string
, length
, font
, rect
, format
,
4600 measure_string_callback
, &args
);
4602 DeleteObject(SelectObject(hdc
, oldfont
));
4610 struct draw_string_args
{
4613 REAL ang_cos
, ang_sin
;
4616 static GpStatus
draw_string_callback(HDC hdc
,
4617 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4618 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4619 INT lineno
, const RectF
*bounds
, void *user_data
)
4621 struct draw_string_args
*args
= user_data
;
4624 drawcoord
.left
= drawcoord
.right
= args
->drawbase
.x
+ roundr(args
->ang_sin
* bounds
->Y
);
4625 drawcoord
.top
= drawcoord
.bottom
= args
->drawbase
.y
+ roundr(args
->ang_cos
* bounds
->Y
);
4627 DrawTextW(hdc
, string
+ index
, length
, &drawcoord
, args
->drawflags
);
4632 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4633 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4634 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4638 GpPointF pt
[3], rectcpy
[4];
4640 REAL angle
, rel_width
, rel_height
;
4641 INT offsety
= 0, save_state
;
4642 struct draw_string_args args
;
4645 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4646 length
, font
, debugstr_rectf(rect
), format
, brush
);
4648 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4649 return InvalidParameter
;
4651 if((brush
->bt
!= BrushTypeSolidColor
)){
4652 FIXME("not implemented for given parameters\n");
4653 return NotImplemented
;
4658 FIXME("graphics object has no HDC\n");
4663 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4665 /* Should be no need to explicitly test for StringAlignmentNear as
4666 * that is default behavior if no alignment is passed. */
4667 if(format
->vertalign
!= StringAlignmentNear
){
4669 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
4671 if(format
->vertalign
== StringAlignmentCenter
)
4672 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4673 else if(format
->vertalign
== StringAlignmentFar
)
4674 offsety
= (rect
->Height
- bounds
.Height
);
4678 save_state
= SaveDC(graphics
->hdc
);
4679 SetBkMode(graphics
->hdc
, TRANSPARENT
);
4680 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
4688 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4689 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
4690 args
.ang_cos
= cos(angle
);
4691 args
.ang_sin
= sin(angle
);
4692 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4693 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4694 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4695 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4697 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
4698 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
4699 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
4700 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
4701 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
4703 scaled_rect
.X
= 0.0;
4704 scaled_rect
.Y
= 0.0;
4705 scaled_rect
.Width
= rel_width
* rect
->Width
;
4706 scaled_rect
.Height
= rel_height
* rect
->Height
;
4708 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
4710 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4711 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
4712 SelectClipRgn(graphics
->hdc
, rgn
);
4715 get_font_hfont(graphics
, font
, &gdifont
);
4716 SelectObject(graphics
->hdc
, gdifont
);
4718 if (!format
|| format
->align
== StringAlignmentNear
)
4720 args
.drawbase
.x
= corners
[0].x
;
4721 args
.drawbase
.y
= corners
[0].y
;
4722 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
;
4724 else if (format
->align
== StringAlignmentCenter
)
4726 args
.drawbase
.x
= (corners
[0].x
+ corners
[1].x
)/2;
4727 args
.drawbase
.y
= (corners
[0].y
+ corners
[1].y
)/2;
4728 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_CENTER
;
4730 else /* (format->align == StringAlignmentFar) */
4732 args
.drawbase
.x
= corners
[1].x
;
4733 args
.drawbase
.y
= corners
[1].y
;
4734 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_RIGHT
;
4737 gdip_format_string(graphics
->hdc
, string
, length
, font
, &scaled_rect
, format
,
4738 draw_string_callback
, &args
);
4741 DeleteObject(gdifont
);
4743 RestoreDC(graphics
->hdc
, save_state
);
4748 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
4750 TRACE("(%p)\n", graphics
);
4753 return InvalidParameter
;
4758 return GdipSetInfinite(graphics
->clip
);
4761 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
4763 TRACE("(%p)\n", graphics
);
4766 return InvalidParameter
;
4771 graphics
->worldtrans
->matrix
[0] = 1.0;
4772 graphics
->worldtrans
->matrix
[1] = 0.0;
4773 graphics
->worldtrans
->matrix
[2] = 0.0;
4774 graphics
->worldtrans
->matrix
[3] = 1.0;
4775 graphics
->worldtrans
->matrix
[4] = 0.0;
4776 graphics
->worldtrans
->matrix
[5] = 0.0;
4781 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
4783 return GdipEndContainer(graphics
, state
);
4786 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
4787 GpMatrixOrder order
)
4789 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
4792 return InvalidParameter
;
4797 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
4800 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
4802 return GdipBeginContainer2(graphics
, state
);
4805 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
4806 GraphicsContainer
*state
)
4808 GraphicsContainerItem
*container
;
4811 TRACE("(%p, %p)\n", graphics
, state
);
4813 if(!graphics
|| !state
)
4814 return InvalidParameter
;
4816 sts
= init_container(&container
, graphics
);
4820 list_add_head(&graphics
->containers
, &container
->entry
);
4821 *state
= graphics
->contid
= container
->contid
;
4826 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4828 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4829 return NotImplemented
;
4832 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4834 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4835 return NotImplemented
;
4838 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
4840 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
4841 return NotImplemented
;
4844 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
4847 GraphicsContainerItem
*container
, *container2
;
4849 TRACE("(%p, %x)\n", graphics
, state
);
4852 return InvalidParameter
;
4854 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4855 if(container
->contid
== state
)
4859 /* did not find a matching container */
4860 if(&container
->entry
== &graphics
->containers
)
4863 sts
= restore_container(graphics
, container
);
4867 /* remove all of the containers on top of the found container */
4868 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4869 if(container
->contid
== state
)
4871 list_remove(&container
->entry
);
4872 delete_container(container
);
4875 list_remove(&container
->entry
);
4876 delete_container(container
);
4881 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
4882 REAL sy
, GpMatrixOrder order
)
4884 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
4887 return InvalidParameter
;
4892 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
4895 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
4898 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
4900 if(!graphics
|| !srcgraphics
)
4901 return InvalidParameter
;
4903 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
4906 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
4907 CompositingMode mode
)
4909 TRACE("(%p, %d)\n", graphics
, mode
);
4912 return InvalidParameter
;
4917 graphics
->compmode
= mode
;
4922 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
4923 CompositingQuality quality
)
4925 TRACE("(%p, %d)\n", graphics
, quality
);
4928 return InvalidParameter
;
4933 graphics
->compqual
= quality
;
4938 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
4939 InterpolationMode mode
)
4941 TRACE("(%p, %d)\n", graphics
, mode
);
4943 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
4944 return InvalidParameter
;
4949 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
4950 mode
= InterpolationModeBilinear
;
4952 if (mode
== InterpolationModeHighQuality
)
4953 mode
= InterpolationModeHighQualityBicubic
;
4955 graphics
->interpolation
= mode
;
4960 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
4962 TRACE("(%p, %.2f)\n", graphics
, scale
);
4964 if(!graphics
|| (scale
<= 0.0))
4965 return InvalidParameter
;
4970 graphics
->scale
= scale
;
4975 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
4977 TRACE("(%p, %d)\n", graphics
, unit
);
4980 return InvalidParameter
;
4985 if(unit
== UnitWorld
)
4986 return InvalidParameter
;
4988 graphics
->unit
= unit
;
4993 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4996 TRACE("(%p, %d)\n", graphics
, mode
);
4999 return InvalidParameter
;
5004 graphics
->pixeloffset
= mode
;
5009 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5013 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5016 FIXME("not implemented\n");
5018 return NotImplemented
;
5021 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5025 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5028 FIXME("not implemented\n");
5032 return NotImplemented
;
5035 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5037 TRACE("(%p, %d)\n", graphics
, mode
);
5040 return InvalidParameter
;
5045 graphics
->smoothing
= mode
;
5050 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5052 TRACE("(%p, %d)\n", graphics
, contrast
);
5055 return InvalidParameter
;
5057 graphics
->textcontrast
= contrast
;
5062 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5063 TextRenderingHint hint
)
5065 TRACE("(%p, %d)\n", graphics
, hint
);
5067 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5068 return InvalidParameter
;
5073 graphics
->texthint
= hint
;
5078 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5080 TRACE("(%p, %p)\n", graphics
, matrix
);
5082 if(!graphics
|| !matrix
)
5083 return InvalidParameter
;
5088 GdipDeleteMatrix(graphics
->worldtrans
);
5089 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
5092 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5093 REAL dy
, GpMatrixOrder order
)
5095 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5098 return InvalidParameter
;
5103 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
5106 /*****************************************************************************
5107 * GdipSetClipHrgn [GDIPLUS.@]
5109 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5114 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5117 return InvalidParameter
;
5119 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5123 status
= GdipSetClipRegion(graphics
, region
, mode
);
5125 GdipDeleteRegion(region
);
5129 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5131 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5134 return InvalidParameter
;
5139 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5142 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5143 REAL width
, REAL height
,
5148 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5151 return InvalidParameter
;
5159 rect
.Height
= height
;
5161 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5164 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5165 INT width
, INT height
,
5168 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5171 return InvalidParameter
;
5176 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5179 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5182 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5184 if(!graphics
|| !region
)
5185 return InvalidParameter
;
5190 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5193 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5198 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5201 FIXME("not implemented\n");
5203 return NotImplemented
;
5206 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5212 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5214 if(!graphics
|| !pen
|| count
<=0)
5215 return InvalidParameter
;
5222 FIXME("graphics object has no HDC\n");
5226 pti
= GdipAlloc(sizeof(POINT
) * count
);
5228 save_state
= prepare_dc(graphics
, pen
);
5229 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5231 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5232 Polygon(graphics
->hdc
, pti
, count
);
5234 restore_dc(graphics
, save_state
);
5240 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5247 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5249 if(count
<=0) return InvalidParameter
;
5250 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5252 for(i
= 0;i
< count
; i
++){
5253 ptf
[i
].X
= (REAL
)points
[i
].X
;
5254 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5257 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5263 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5265 TRACE("(%p, %p)\n", graphics
, dpi
);
5267 if(!graphics
|| !dpi
)
5268 return InvalidParameter
;
5273 if (graphics
->image
)
5274 *dpi
= graphics
->image
->xres
;
5276 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
5281 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5283 TRACE("(%p, %p)\n", graphics
, dpi
);
5285 if(!graphics
|| !dpi
)
5286 return InvalidParameter
;
5291 if (graphics
->image
)
5292 *dpi
= graphics
->image
->yres
;
5294 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
5299 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5300 GpMatrixOrder order
)
5305 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5307 if(!graphics
|| !matrix
)
5308 return InvalidParameter
;
5313 m
= *(graphics
->worldtrans
);
5315 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5317 *(graphics
->worldtrans
) = m
;
5322 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5323 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5325 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5327 TRACE("(%p, %p)\n", graphics
, hdc
);
5329 if(!graphics
|| !hdc
)
5330 return InvalidParameter
;
5335 if (!graphics
->hdc
||
5336 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5338 /* Create a fake HDC and fill it with a constant color. */
5343 BITMAPINFOHEADER bmih
;
5346 stat
= get_graphics_bounds(graphics
, &bounds
);
5350 graphics
->temp_hbitmap_width
= bounds
.Width
;
5351 graphics
->temp_hbitmap_height
= bounds
.Height
;
5353 bmih
.biSize
= sizeof(bmih
);
5354 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5355 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5357 bmih
.biBitCount
= 32;
5358 bmih
.biCompression
= BI_RGB
;
5359 bmih
.biSizeImage
= 0;
5360 bmih
.biXPelsPerMeter
= 0;
5361 bmih
.biYPelsPerMeter
= 0;
5363 bmih
.biClrImportant
= 0;
5365 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5366 (void**)&graphics
->temp_bits
, NULL
, 0);
5368 return GenericError
;
5370 temp_hdc
= CreateCompatibleDC(0);
5373 DeleteObject(hbitmap
);
5374 return GenericError
;
5377 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5378 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5380 SelectObject(temp_hdc
, hbitmap
);
5382 graphics
->temp_hbitmap
= hbitmap
;
5383 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5387 *hdc
= graphics
->hdc
;
5390 graphics
->busy
= TRUE
;
5395 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5397 TRACE("(%p, %p)\n", graphics
, hdc
);
5399 if(!graphics
|| !hdc
)
5400 return InvalidParameter
;
5402 if((graphics
->hdc
!= hdc
&& graphics
->temp_hdc
!= hdc
) || !(graphics
->busy
))
5403 return InvalidParameter
;
5405 if (graphics
->temp_hdc
== hdc
)
5410 /* Find the pixels that have changed, and mark them as opaque. */
5411 pos
= (DWORD
*)graphics
->temp_bits
;
5412 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5414 if (*pos
!= DC_BACKGROUND_KEY
)
5421 /* Write the changed pixels to the real target. */
5422 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5423 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5424 graphics
->temp_hbitmap_width
* 4);
5427 DeleteDC(graphics
->temp_hdc
);
5428 DeleteObject(graphics
->temp_hbitmap
);
5429 graphics
->temp_hdc
= NULL
;
5430 graphics
->temp_hbitmap
= NULL
;
5433 graphics
->busy
= FALSE
;
5438 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5443 TRACE("(%p, %p)\n", graphics
, region
);
5445 if(!graphics
|| !region
)
5446 return InvalidParameter
;
5451 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5454 /* free everything except root node and header */
5455 delete_element(®ion
->node
);
5456 memcpy(region
, clip
, sizeof(GpRegion
));
5462 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5463 GpCoordinateSpace src_space
, GpMatrix
**matrix
)
5465 GpStatus stat
= GdipCreateMatrix(matrix
);
5468 if (dst_space
!= src_space
&& stat
== Ok
)
5470 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
5472 if(graphics
->unit
!= UnitDisplay
)
5473 unitscale
*= graphics
->scale
;
5475 /* transform from src_space to CoordinateSpacePage */
5478 case CoordinateSpaceWorld
:
5479 GdipMultiplyMatrix(*matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
5481 case CoordinateSpacePage
:
5483 case CoordinateSpaceDevice
:
5484 GdipScaleMatrix(*matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
5488 /* transform from CoordinateSpacePage to dst_space */
5491 case CoordinateSpaceWorld
:
5493 GpMatrix
*inverted_transform
;
5494 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
5497 stat
= GdipInvertMatrix(inverted_transform
);
5499 GdipMultiplyMatrix(*matrix
, inverted_transform
, MatrixOrderAppend
);
5500 GdipDeleteMatrix(inverted_transform
);
5504 case CoordinateSpacePage
:
5506 case CoordinateSpaceDevice
:
5507 GdipScaleMatrix(*matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
5514 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5515 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5520 if(!graphics
|| !points
|| count
<= 0)
5521 return InvalidParameter
;
5526 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5528 if (src_space
== dst_space
) return Ok
;
5530 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5534 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
5536 GdipDeleteMatrix(matrix
);
5542 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5543 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5549 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5552 return InvalidParameter
;
5554 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5558 for(i
= 0; i
< count
; i
++){
5559 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5560 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5563 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5566 for(i
= 0; i
< count
; i
++){
5567 points
[i
].X
= roundr(pointsF
[i
].X
);
5568 points
[i
].Y
= roundr(pointsF
[i
].Y
);
5575 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5587 /*****************************************************************************
5588 * GdipTranslateClip [GDIPLUS.@]
5590 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5592 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5595 return InvalidParameter
;
5600 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5603 /*****************************************************************************
5604 * GdipTranslateClipI [GDIPLUS.@]
5606 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5608 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5611 return InvalidParameter
;
5616 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
5620 /*****************************************************************************
5621 * GdipMeasureDriverString [GDIPLUS.@]
5623 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5624 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
5625 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
5627 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
5628 return NotImplemented
;
5631 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5632 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
5633 GDIPCONST PointF
*positions
, INT flags
,
5634 GDIPCONST GpMatrix
*matrix
)
5636 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
5642 if (flags
& unsupported_flags
)
5643 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
5646 FIXME("Ignoring matrix\n");
5648 if (!(flags
& DriverStringOptionsCmapLookup
))
5649 eto_flags
|= ETO_GLYPH_INDEX
;
5651 save_state
= SaveDC(graphics
->hdc
);
5652 SetBkMode(graphics
->hdc
, TRANSPARENT
);
5653 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
5656 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
5658 get_font_hfont(graphics
, font
, &hfont
);
5659 SelectObject(graphics
->hdc
, hfont
);
5661 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
5663 ExtTextOutW(graphics
->hdc
, roundr(pt
.X
), roundr(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
5665 RestoreDC(graphics
->hdc
, save_state
);
5667 DeleteObject(hfont
);
5672 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5673 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
5674 GDIPCONST PointF
*positions
, INT flags
,
5675 GDIPCONST GpMatrix
*matrix
)
5677 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
5679 PointF
*real_positions
, real_position
;
5683 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
5684 DWORD max_glyphsize
=0;
5685 GLYPHMETRICS glyphmetrics
;
5686 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
5689 int text_mask_stride
;
5691 int pixel_data_stride
;
5693 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
5698 if (!(flags
& DriverStringOptionsCmapLookup
))
5699 ggo_flags
|= GGO_GLYPH_INDEX
;
5701 if (flags
& unsupported_flags
)
5702 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
5705 FIXME("Ignoring matrix\n");
5707 pti
= GdipAlloc(sizeof(POINT
) * length
);
5711 if (flags
& DriverStringOptionsRealizedAdvance
)
5713 real_position
= positions
[0];
5715 transform_and_round_points(graphics
, pti
, &real_position
, 1);
5719 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
5720 if (!real_positions
)
5726 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
5728 transform_and_round_points(graphics
, pti
, real_positions
, length
);
5730 GdipFree(real_positions
);
5733 get_font_hfont(graphics
, font
, &hfont
);
5735 hdc
= CreateCompatibleDC(0);
5736 SelectObject(hdc
, hfont
);
5738 /* Get the boundaries of the text to be drawn */
5739 for (i
=0; i
<length
; i
++)
5742 int left
, top
, right
, bottom
;
5744 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
5745 &glyphmetrics
, 0, NULL
, &identity
);
5747 if (glyphsize
== GDI_ERROR
)
5749 ERR("GetGlyphOutlineW failed\n");
5752 DeleteObject(hfont
);
5753 return GenericError
;
5756 if (glyphsize
> max_glyphsize
)
5757 max_glyphsize
= glyphsize
;
5759 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
5760 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
5761 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
5762 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
5764 if (left
< min_x
) min_x
= left
;
5765 if (top
< min_y
) min_y
= top
;
5766 if (right
> max_x
) max_x
= right
;
5767 if (bottom
> max_y
) max_y
= bottom
;
5769 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
5771 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
5772 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
5776 glyph_mask
= GdipAlloc(max_glyphsize
);
5777 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
5778 text_mask_stride
= max_x
- min_x
;
5780 if (!(glyph_mask
&& text_mask
))
5782 GdipFree(glyph_mask
);
5783 GdipFree(text_mask
);
5786 DeleteObject(hfont
);
5790 /* Generate a mask for the text */
5791 for (i
=0; i
<length
; i
++)
5793 int left
, top
, stride
;
5795 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
5796 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
5798 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
5799 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
5800 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
5802 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
5804 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
5805 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
5806 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
5808 *text_val
= min(64, *text_val
+ *glyph_val
);
5817 DeleteObject(hfont
);
5818 GdipFree(glyph_mask
);
5820 /* get the brush data */
5821 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
5824 GdipFree(text_mask
);
5828 pixel_area
.X
= min_x
;
5829 pixel_area
.Y
= min_y
;
5830 pixel_area
.Width
= max_x
- min_x
;
5831 pixel_area
.Height
= max_y
- min_y
;
5832 pixel_data_stride
= pixel_area
.Width
* 4;
5834 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
5837 GdipFree(text_mask
);
5838 GdipFree(pixel_data
);
5842 /* multiply the brush data by the mask */
5843 for (y
=0; y
<pixel_area
.Height
; y
++)
5845 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
5846 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
5847 for (x
=0; x
<pixel_area
.Width
; x
++)
5849 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
5855 GdipFree(text_mask
);
5857 /* draw the result */
5858 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
5859 pixel_area
.Height
, pixel_data_stride
);
5861 GdipFree(pixel_data
);
5866 /*****************************************************************************
5867 * GdipDrawDriverString [GDIPLUS.@]
5869 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5870 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
5871 GDIPCONST PointF
*positions
, INT flags
,
5872 GDIPCONST GpMatrix
*matrix
)
5874 GpStatus stat
=NotImplemented
;
5876 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
5878 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
5879 return InvalidParameter
;
5882 length
= strlenW(text
);
5884 if (graphics
->hdc
&&
5885 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
5886 brush
->bt
== BrushTypeSolidColor
&&
5887 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
5888 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
5889 positions
, flags
, matrix
);
5891 if (stat
== NotImplemented
)
5892 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
5893 positions
, flags
, matrix
);
5898 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
5899 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5901 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5902 return NotImplemented
;
5905 /*****************************************************************************
5906 * GdipIsVisibleClipEmpty [GDIPLUS.@]
5908 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
5913 TRACE("(%p, %p)\n", graphics
, res
);
5915 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5918 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5921 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
5924 GdipDeleteRegion(rgn
);