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
));
212 HBITMAP hbitmap
, old_hbm
=NULL
;
213 BITMAPINFOHEADER bih
;
217 hdc
= CreateCompatibleDC(0);
219 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
220 bih
.biWidth
= src_width
;
221 bih
.biHeight
= -src_height
;
224 bih
.biCompression
= BI_RGB
;
226 bih
.biXPelsPerMeter
= 0;
227 bih
.biYPelsPerMeter
= 0;
229 bih
.biClrImportant
= 0;
231 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
232 (void**)&temp_bits
, NULL
, 0);
234 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
235 4 * src_width
, src
, src_stride
);
237 old_hbm
= SelectObject(hdc
, hbitmap
);
239 bf
.BlendOp
= AC_SRC_OVER
;
241 bf
.SourceConstantAlpha
= 255;
242 bf
.AlphaFormat
= AC_SRC_ALPHA
;
244 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, src_width
, src_height
,
245 hdc
, 0, 0, src_width
, src_height
, bf
);
247 SelectObject(hdc
, old_hbm
);
249 DeleteObject(hbitmap
);
255 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
261 a1
= (start
>> 24) & 0xff;
262 a2
= (end
>> 24) & 0xff;
264 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
268 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
269 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
273 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
277 /* clamp to between 0.0 and 1.0, using the wrap mode */
278 if (brush
->wrap
== WrapModeTile
)
280 position
= fmodf(position
, 1.0f
);
281 if (position
< 0.0f
) position
+= 1.0f
;
283 else /* WrapModeFlip* */
285 position
= fmodf(position
, 2.0f
);
286 if (position
< 0.0f
) position
+= 2.0f
;
287 if (position
> 1.0f
) position
= 2.0f
- position
;
290 if (brush
->blendcount
== 1)
295 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
298 /* locate the blend positions surrounding this position */
299 while (position
> brush
->blendpos
[i
])
302 /* interpolate between the blend positions */
303 left_blendpos
= brush
->blendpos
[i
-1];
304 left_blendfac
= brush
->blendfac
[i
-1];
305 right_blendpos
= brush
->blendpos
[i
];
306 right_blendfac
= brush
->blendfac
[i
];
307 range
= right_blendpos
- left_blendpos
;
308 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
309 right_blendfac
* (position
- left_blendpos
)) / range
;
312 if (brush
->pblendcount
== 0)
313 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
317 ARGB left_blendcolor
, right_blendcolor
;
318 REAL left_blendpos
, right_blendpos
;
320 /* locate the blend colors surrounding this position */
321 while (blendfac
> brush
->pblendpos
[i
])
324 /* interpolate between the blend colors */
325 left_blendpos
= brush
->pblendpos
[i
-1];
326 left_blendcolor
= brush
->pblendcolor
[i
-1];
327 right_blendpos
= brush
->pblendpos
[i
];
328 right_blendcolor
= brush
->pblendcolor
[i
];
329 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
330 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
334 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
335 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
339 if (attributes
->colorkeys
[type
].enabled
||
340 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
342 const struct color_key
*key
;
343 BYTE min_blue
, min_green
, min_red
;
344 BYTE max_blue
, max_green
, max_red
;
346 if (attributes
->colorkeys
[type
].enabled
)
347 key
= &attributes
->colorkeys
[type
];
349 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
351 min_blue
= key
->low
&0xff;
352 min_green
= (key
->low
>>8)&0xff;
353 min_red
= (key
->low
>>16)&0xff;
355 max_blue
= key
->high
&0xff;
356 max_green
= (key
->high
>>8)&0xff;
357 max_red
= (key
->high
>>16)&0xff;
359 for (x
=0; x
<width
; x
++)
360 for (y
=0; y
<height
; y
++)
363 BYTE blue
, green
, red
;
364 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
365 blue
= *src_color
&0xff;
366 green
= (*src_color
>>8)&0xff;
367 red
= (*src_color
>>16)&0xff;
368 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
369 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
370 *src_color
= 0x00000000;
374 if (attributes
->colorremaptables
[type
].enabled
||
375 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
377 const struct color_remap_table
*table
;
379 if (attributes
->colorremaptables
[type
].enabled
)
380 table
= &attributes
->colorremaptables
[type
];
382 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
384 for (x
=0; x
<width
; x
++)
385 for (y
=0; y
<height
; y
++)
388 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
389 for (i
=0; i
<table
->mapsize
; i
++)
391 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
393 *src_color
= table
->colormap
[i
].newColor
.Argb
;
400 if (attributes
->colormatrices
[type
].enabled
||
401 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
405 FIXME("Color transforms not implemented\n");
408 if (attributes
->gamma_enabled
[type
] ||
409 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
413 FIXME("Gamma adjustment not implemented\n");
417 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
418 * bitmap that contains all the pixels we may need to draw it. */
419 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
420 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
423 INT left
, top
, right
, bottom
;
425 switch (interpolation
)
427 case InterpolationModeHighQualityBilinear
:
428 case InterpolationModeHighQualityBicubic
:
429 /* FIXME: Include a greater range for the prefilter? */
430 case InterpolationModeBicubic
:
431 case InterpolationModeBilinear
:
432 left
= (INT
)(floorf(srcx
));
433 top
= (INT
)(floorf(srcy
));
434 right
= (INT
)(ceilf(srcx
+srcwidth
));
435 bottom
= (INT
)(ceilf(srcy
+srcheight
));
437 case InterpolationModeNearestNeighbor
:
441 right
= roundr(srcx
+srcwidth
);
442 bottom
= roundr(srcy
+srcheight
);
446 if (wrap
== WrapModeClamp
)
452 if (right
>= bitmap
->width
)
453 right
= bitmap
->width
-1;
454 if (bottom
>= bitmap
->height
)
455 bottom
= bitmap
->height
-1;
459 /* In some cases we can make the rectangle smaller here, but the logic
460 * is hard to get right, and tiling suggests we're likely to use the
461 * entire source image. */
462 if (left
< 0 || right
>= bitmap
->width
)
465 right
= bitmap
->width
-1;
468 if (top
< 0 || bottom
>= bitmap
->height
)
471 bottom
= bitmap
->height
-1;
477 rect
->Width
= right
- left
+ 1;
478 rect
->Height
= bottom
- top
+ 1;
481 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
482 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
484 if (attributes
->wrap
== WrapModeClamp
)
486 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
487 return attributes
->outside_color
;
491 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
493 x
= width
*2 + x
% (width
* 2);
495 y
= height
*2 + y
% (height
* 2);
497 if ((attributes
->wrap
& 1) == 1)
500 if ((x
/ width
) % 2 == 0)
503 x
= width
- 1 - x
% width
;
508 if ((attributes
->wrap
& 2) == 2)
511 if ((y
/ height
) % 2 == 0)
514 y
= height
- 1 - y
% height
;
520 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
522 ERR("out of range pixel requested\n");
526 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
529 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
530 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
531 InterpolationMode interpolation
)
535 switch (interpolation
)
539 FIXME("Unimplemented interpolation %i\n", interpolation
);
541 case InterpolationModeBilinear
:
544 INT leftx
, rightx
, topy
, bottomy
;
545 ARGB topleft
, topright
, bottomleft
, bottomright
;
549 leftxf
= floorf(point
->X
);
551 rightx
= (INT
)ceilf(point
->X
);
552 topyf
= floorf(point
->Y
);
554 bottomy
= (INT
)ceilf(point
->Y
);
556 if (leftx
== rightx
&& topy
== bottomy
)
557 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
558 leftx
, topy
, attributes
);
560 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
561 leftx
, topy
, attributes
);
562 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
563 rightx
, topy
, attributes
);
564 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
565 leftx
, bottomy
, attributes
);
566 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
567 rightx
, bottomy
, attributes
);
569 x_offset
= point
->X
- leftxf
;
570 top
= blend_colors(topleft
, topright
, x_offset
);
571 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
573 return blend_colors(top
, bottom
, point
->Y
- topyf
);
575 case InterpolationModeNearestNeighbor
:
576 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
577 roundr(point
->X
), roundr(point
->Y
), attributes
);
581 static INT
brush_can_fill_path(GpBrush
*brush
)
585 case BrushTypeSolidColor
:
586 case BrushTypeHatchFill
:
588 case BrushTypeLinearGradient
:
589 case BrushTypeTextureFill
:
590 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
596 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
600 case BrushTypeLinearGradient
:
602 GpLineGradient
*line
= (GpLineGradient
*)brush
;
605 SelectClipPath(graphics
->hdc
, RGN_AND
);
606 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
608 GpPointF endpointsf
[2];
612 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
614 endpointsf
[0] = line
->startpoint
;
615 endpointsf
[1] = line
->endpoint
;
616 transform_and_round_points(graphics
, endpointsi
, endpointsf
, 2);
618 if (abs(endpointsi
[0].x
-endpointsi
[1].x
) > abs(endpointsi
[0].y
-endpointsi
[1].y
))
620 /* vertical-ish gradient */
621 int startx
, endx
; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
622 int startbottomx
; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
625 HBRUSH hbrush
, hprevbrush
;
626 int leftx
, rightx
; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
628 int tilt
; /* horizontal distance covered by a gradient line */
630 startx
= roundr((rc
.top
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
631 endx
= roundr((rc
.top
- endpointsf
[1].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[1].X
);
632 width
= endx
- startx
;
633 startbottomx
= roundr((rc
.bottom
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
634 tilt
= startx
- startbottomx
;
636 if (startx
>= startbottomx
)
639 rightx
= rc
.right
+ tilt
;
643 leftx
= rc
.left
+ tilt
;
647 poly
[0].y
= rc
.bottom
;
650 poly
[3].y
= rc
.bottom
;
652 for (x
=leftx
; x
<=rightx
; x
++)
654 ARGB argb
= blend_line_gradient(line
, (x
-startx
)/(REAL
)width
);
655 col
= ARGB2COLORREF(argb
);
656 hbrush
= CreateSolidBrush(col
);
657 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
658 poly
[0].x
= x
- tilt
- 1;
661 poly
[3].x
= x
- tilt
;
662 Polygon(graphics
->hdc
, poly
, 4);
663 SelectObject(graphics
->hdc
, hprevbrush
);
664 DeleteObject(hbrush
);
667 else if (endpointsi
[0].y
!= endpointsi
[1].y
)
669 /* horizontal-ish gradient */
670 int starty
, endy
; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
671 int startrighty
; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
674 HBRUSH hbrush
, hprevbrush
;
675 int topy
, bottomy
; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
677 int tilt
; /* vertical distance covered by a gradient line */
679 starty
= roundr((rc
.left
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
680 endy
= roundr((rc
.left
- endpointsf
[1].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[1].Y
);
681 height
= endy
- starty
;
682 startrighty
= roundr((rc
.right
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
683 tilt
= starty
- startrighty
;
685 if (starty
>= startrighty
)
688 bottomy
= rc
.bottom
+ tilt
;
692 topy
= rc
.top
+ tilt
;
696 poly
[0].x
= rc
.right
;
699 poly
[3].x
= rc
.right
;
701 for (y
=topy
; y
<=bottomy
; y
++)
703 ARGB argb
= blend_line_gradient(line
, (y
-starty
)/(REAL
)height
);
704 col
= ARGB2COLORREF(argb
);
705 hbrush
= CreateSolidBrush(col
);
706 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
707 poly
[0].y
= y
- tilt
- 1;
710 poly
[3].y
= y
- tilt
;
711 Polygon(graphics
->hdc
, poly
, 4);
712 SelectObject(graphics
->hdc
, hprevbrush
);
713 DeleteObject(hbrush
);
716 /* else startpoint == endpoint */
720 case BrushTypeSolidColor
:
722 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
726 /* partially transparent fill */
728 SelectClipPath(graphics
->hdc
, RGN_AND
);
729 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
731 HDC hdc
= CreateCompatibleDC(NULL
);
737 oldbmp
= SelectObject(hdc
, fill
->bmp
);
739 bf
.BlendOp
= AC_SRC_OVER
;
741 bf
.SourceConstantAlpha
= 255;
742 bf
.AlphaFormat
= AC_SRC_ALPHA
;
744 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
746 SelectObject(hdc
, oldbmp
);
752 /* else fall through */
755 SelectObject(graphics
->hdc
, brush
->gdibrush
);
756 FillPath(graphics
->hdc
);
761 static INT
brush_can_fill_pixels(GpBrush
*brush
)
765 case BrushTypeSolidColor
:
766 case BrushTypeHatchFill
:
767 case BrushTypeLinearGradient
:
768 case BrushTypeTextureFill
:
775 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
776 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
780 case BrushTypeSolidColor
:
783 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
784 for (x
=0; x
<fill_area
->Width
; x
++)
785 for (y
=0; y
<fill_area
->Height
; y
++)
786 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
789 case BrushTypeHatchFill
:
792 GpHatch
*fill
= (GpHatch
*)brush
;
793 const char *hatch_data
;
795 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
796 return NotImplemented
;
798 for (x
=0; x
<fill_area
->Width
; x
++)
799 for (y
=0; y
<fill_area
->Height
; y
++)
803 /* FIXME: Account for the rendering origin */
804 hx
= (x
+ fill_area
->X
) % 8;
805 hy
= (y
+ fill_area
->Y
) % 8;
807 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
808 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
810 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
815 case BrushTypeLinearGradient
:
817 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
818 GpPointF draw_points
[3], line_points
[3];
820 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
821 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
824 draw_points
[0].X
= fill_area
->X
;
825 draw_points
[0].Y
= fill_area
->Y
;
826 draw_points
[1].X
= fill_area
->X
+1;
827 draw_points
[1].Y
= fill_area
->Y
;
828 draw_points
[2].X
= fill_area
->X
;
829 draw_points
[2].Y
= fill_area
->Y
+1;
831 /* Transform the points to a co-ordinate space where X is the point's
832 * position in the gradient, 0.0 being the start point and 1.0 the
834 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
835 CoordinateSpaceDevice
, draw_points
, 3);
839 line_points
[0] = fill
->startpoint
;
840 line_points
[1] = fill
->endpoint
;
841 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
842 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
844 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
849 stat
= GdipInvertMatrix(world_to_gradient
);
852 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
854 GdipDeleteMatrix(world_to_gradient
);
859 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
860 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
862 for (y
=0; y
<fill_area
->Height
; y
++)
864 for (x
=0; x
<fill_area
->Width
; x
++)
866 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
868 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
875 case BrushTypeTextureFill
:
877 GpTexture
*fill
= (GpTexture
*)brush
;
878 GpPointF draw_points
[3];
880 GpMatrix
*world_to_texture
;
886 if (fill
->image
->type
!= ImageTypeBitmap
)
888 FIXME("metafile texture brushes not implemented\n");
889 return NotImplemented
;
892 bitmap
= (GpBitmap
*)fill
->image
;
893 src_stride
= sizeof(ARGB
) * bitmap
->width
;
895 src_area
.X
= src_area
.Y
= 0;
896 src_area
.Width
= bitmap
->width
;
897 src_area
.Height
= bitmap
->height
;
899 draw_points
[0].X
= fill_area
->X
;
900 draw_points
[0].Y
= fill_area
->Y
;
901 draw_points
[1].X
= fill_area
->X
+1;
902 draw_points
[1].Y
= fill_area
->Y
;
903 draw_points
[2].X
= fill_area
->X
;
904 draw_points
[2].Y
= fill_area
->Y
+1;
906 /* Transform the points to the co-ordinate space of the bitmap. */
907 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
908 CoordinateSpaceDevice
, draw_points
, 3);
912 stat
= GdipCloneMatrix(fill
->transform
, &world_to_texture
);
917 stat
= GdipInvertMatrix(world_to_texture
);
920 stat
= GdipTransformMatrixPoints(world_to_texture
, draw_points
, 3);
922 GdipDeleteMatrix(world_to_texture
);
925 if (stat
== Ok
&& !fill
->bitmap_bits
)
927 BitmapData lockeddata
;
929 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
930 if (!fill
->bitmap_bits
)
935 lockeddata
.Width
= bitmap
->width
;
936 lockeddata
.Height
= bitmap
->height
;
937 lockeddata
.Stride
= src_stride
;
938 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
939 lockeddata
.Scan0
= fill
->bitmap_bits
;
941 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
942 PixelFormat32bppARGB
, &lockeddata
);
946 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
949 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
950 bitmap
->width
, bitmap
->height
,
951 src_stride
, ColorAdjustTypeBitmap
);
955 GdipFree(fill
->bitmap_bits
);
956 fill
->bitmap_bits
= NULL
;
962 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
963 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
964 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
965 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
967 for (y
=0; y
<fill_area
->Height
; y
++)
969 for (x
=0; x
<fill_area
->Width
; x
++)
972 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
973 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
975 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
976 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
977 &point
, fill
->imageattributes
, graphics
->interpolation
);
985 return NotImplemented
;
989 /* GdipDrawPie/GdipFillPie helper function */
990 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
991 REAL height
, REAL startAngle
, REAL sweepAngle
)
998 ptf
[1].X
= x
+ width
;
999 ptf
[1].Y
= y
+ height
;
1001 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
1002 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
1004 transform_and_round_points(graphics
, pti
, ptf
, 4);
1006 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
1007 pti
[2].y
, pti
[3].x
, pti
[3].y
);
1010 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1011 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1012 * should not be called on an hdc that has a path you care about. */
1013 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1014 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1016 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1017 GpMatrix
*matrix
= NULL
;
1018 HBRUSH brush
= NULL
;
1020 PointF ptf
[4], *custptf
= NULL
;
1021 POINT pt
[4], *custpt
= NULL
;
1023 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1028 if((x1
== x2
) && (y1
== y2
))
1031 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1033 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1035 brush
= CreateSolidBrush(color
);
1036 lb
.lbStyle
= BS_SOLID
;
1039 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1040 PS_JOIN_MITER
, 1, &lb
, 0,
1042 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1043 oldpen
= SelectObject(graphics
->hdc
, pen
);
1050 case LineCapSquareAnchor
:
1051 case LineCapDiamondAnchor
:
1052 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1053 if(cap
== LineCapDiamondAnchor
){
1054 dsmall
= cos(theta
+ M_PI_2
) * size
;
1055 dbig
= sin(theta
+ M_PI_2
) * size
;
1058 dsmall
= cos(theta
+ M_PI_4
) * size
;
1059 dbig
= sin(theta
+ M_PI_4
) * size
;
1062 ptf
[0].X
= x2
- dsmall
;
1063 ptf
[1].X
= x2
+ dbig
;
1065 ptf
[0].Y
= y2
- dbig
;
1066 ptf
[3].Y
= y2
+ dsmall
;
1068 ptf
[1].Y
= y2
- dsmall
;
1069 ptf
[2].Y
= y2
+ dbig
;
1071 ptf
[3].X
= x2
- dbig
;
1072 ptf
[2].X
= x2
+ dsmall
;
1074 transform_and_round_points(graphics
, pt
, ptf
, 4);
1075 Polygon(graphics
->hdc
, pt
, 4);
1078 case LineCapArrowAnchor
:
1079 size
= size
* 4.0 / sqrt(3.0);
1081 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1082 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1087 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1088 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1096 transform_and_round_points(graphics
, pt
, ptf
, 3);
1097 Polygon(graphics
->hdc
, pt
, 3);
1100 case LineCapRoundAnchor
:
1101 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1108 transform_and_round_points(graphics
, pt
, ptf
, 2);
1109 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1112 case LineCapTriangle
:
1114 dx
= cos(M_PI_2
+ theta
) * size
;
1115 dy
= sin(M_PI_2
+ theta
) * size
;
1122 dx
= cos(theta
) * size
;
1123 dy
= sin(theta
) * size
;
1128 transform_and_round_points(graphics
, pt
, ptf
, 3);
1129 Polygon(graphics
->hdc
, pt
, 3);
1133 dx
= dy
= size
/ 2.0;
1140 dx
= -cos(M_PI_2
+ theta
) * size
;
1141 dy
= -sin(M_PI_2
+ theta
) * size
;
1148 transform_and_round_points(graphics
, pt
, ptf
, 4);
1149 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1150 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1157 count
= custom
->pathdata
.Count
;
1158 custptf
= GdipAlloc(count
* sizeof(PointF
));
1159 custpt
= GdipAlloc(count
* sizeof(POINT
));
1160 tp
= GdipAlloc(count
);
1162 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
1165 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1167 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
1168 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1170 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
1171 GdipTransformMatrixPoints(matrix
, custptf
, count
);
1173 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1175 for(i
= 0; i
< count
; i
++)
1176 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1179 BeginPath(graphics
->hdc
);
1180 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1181 EndPath(graphics
->hdc
);
1182 StrokeAndFillPath(graphics
->hdc
);
1185 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1191 GdipDeleteMatrix(matrix
);
1198 SelectObject(graphics
->hdc
, oldbrush
);
1199 SelectObject(graphics
->hdc
, oldpen
);
1200 DeleteObject(brush
);
1205 /* Shortens the line by the given percent by changing x2, y2.
1206 * If percent is > 1.0 then the line will change direction.
1207 * If percent is negative it can lengthen the line. */
1208 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1210 REAL dist
, theta
, dx
, dy
;
1212 if((y1
== *y2
) && (x1
== *x2
))
1215 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1216 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1217 dx
= cos(theta
) * dist
;
1218 dy
= sin(theta
) * dist
;
1224 /* Shortens the line by the given amount by changing x2, y2.
1225 * If the amount is greater than the distance, the line will become length 0.
1226 * If the amount is negative, it can lengthen the line. */
1227 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1229 REAL dx
, dy
, percent
;
1233 if(dx
== 0 && dy
== 0)
1236 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1243 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1246 /* Draws lines between the given points, and if caps is true then draws an endcap
1247 * at the end of the last line. */
1248 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
1249 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1252 GpPointF
*ptcopy
= NULL
;
1253 GpStatus status
= GenericError
;
1258 pti
= GdipAlloc(count
* sizeof(POINT
));
1259 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1261 if(!pti
|| !ptcopy
){
1262 status
= OutOfMemory
;
1266 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1269 if(pen
->endcap
== LineCapArrowAnchor
)
1270 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1271 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
1272 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1273 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1274 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
1275 pen
->customend
->inset
* pen
->width
);
1277 if(pen
->startcap
== LineCapArrowAnchor
)
1278 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1279 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
1280 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1281 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1282 &ptcopy
[0].X
, &ptcopy
[0].Y
,
1283 pen
->customstart
->inset
* pen
->width
);
1285 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
1286 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
1287 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1288 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
1291 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1293 if(Polyline(graphics
->hdc
, pti
, count
))
1303 /* Conducts a linear search to find the bezier points that will back off
1304 * the endpoint of the curve by a distance of amt. Linear search works
1305 * better than binary in this case because there are multiple solutions,
1306 * and binary searches often find a bad one. I don't think this is what
1307 * Windows does but short of rendering the bezier without GDI's help it's
1308 * the best we can do. If rev then work from the start of the passed points
1309 * instead of the end. */
1310 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1313 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1314 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1323 origx
= pt
[fourth
].X
;
1324 origy
= pt
[fourth
].Y
;
1325 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1327 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1328 /* reset bezier points to original values */
1329 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1330 /* Perform magic on bezier points. Order is important here.*/
1331 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1332 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1333 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1334 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1335 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1336 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1338 dx
= pt
[fourth
].X
- origx
;
1339 dy
= pt
[fourth
].Y
- origy
;
1341 diff
= sqrt(dx
* dx
+ dy
* dy
);
1342 percent
+= 0.0005 * amt
;
1346 /* Draws bezier curves between given points, and if caps is true then draws an
1347 * endcap at the end of the last line. */
1348 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
1349 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1353 GpStatus status
= GenericError
;
1358 pti
= GdipAlloc(count
* sizeof(POINT
));
1359 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1361 if(!pti
|| !ptcopy
){
1362 status
= OutOfMemory
;
1366 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1369 if(pen
->endcap
== LineCapArrowAnchor
)
1370 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
1371 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1372 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
1375 if(pen
->startcap
== LineCapArrowAnchor
)
1376 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
1377 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1378 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
1380 /* the direction of the line cap is parallel to the direction at the
1381 * end of the bezier (which, if it has been shortened, is not the same
1382 * as the direction from pt[count-2] to pt[count-1]) */
1383 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
1384 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1385 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1386 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1388 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1389 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
1390 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
1393 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1395 PolyBezier(graphics
->hdc
, pti
, count
);
1406 /* Draws a combination of bezier curves and lines between points. */
1407 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1408 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1410 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1411 BYTE
*tp
= GdipAlloc(count
);
1412 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1414 GpStatus status
= GenericError
;
1420 if(!pti
|| !tp
|| !ptcopy
){
1421 status
= OutOfMemory
;
1425 for(i
= 1; i
< count
; i
++){
1426 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1427 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1428 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1429 ERR("Bad bezier points\n");
1436 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1438 /* If we are drawing caps, go through the points and adjust them accordingly,
1439 * and draw the caps. */
1441 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1442 case PathPointTypeBezier
:
1443 if(pen
->endcap
== LineCapArrowAnchor
)
1444 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1445 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1446 shorten_bezier_amt(&ptcopy
[count
- 4],
1447 pen
->width
* pen
->customend
->inset
, FALSE
);
1449 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
1450 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1451 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1452 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1455 case PathPointTypeLine
:
1456 if(pen
->endcap
== LineCapArrowAnchor
)
1457 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1458 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1460 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1461 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1462 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1463 pen
->customend
->inset
* pen
->width
);
1465 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
1466 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1471 ERR("Bad path last point\n");
1475 /* Find start of points */
1476 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1477 == PathPointTypeStart
); j
++);
1479 switch(types
[j
] & PathPointTypePathTypeMask
){
1480 case PathPointTypeBezier
:
1481 if(pen
->startcap
== LineCapArrowAnchor
)
1482 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1483 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1484 shorten_bezier_amt(&ptcopy
[j
- 1],
1485 pen
->width
* pen
->customstart
->inset
, TRUE
);
1487 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1488 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1489 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1490 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1493 case PathPointTypeLine
:
1494 if(pen
->startcap
== LineCapArrowAnchor
)
1495 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1496 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1498 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1499 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1500 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1501 pen
->customstart
->inset
* pen
->width
);
1503 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1504 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1509 ERR("Bad path points\n");
1514 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1516 for(i
= 0; i
< count
; i
++){
1517 tp
[i
] = convert_path_point_type(types
[i
]);
1520 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1532 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1536 BeginPath(graphics
->hdc
);
1537 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1538 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1539 EndPath(graphics
->hdc
);
1543 typedef struct _GraphicsContainerItem
{
1545 GraphicsContainer contid
;
1547 SmoothingMode smoothing
;
1548 CompositingQuality compqual
;
1549 InterpolationMode interpolation
;
1550 CompositingMode compmode
;
1551 TextRenderingHint texthint
;
1554 PixelOffsetMode pixeloffset
;
1556 GpMatrix
* worldtrans
;
1558 } GraphicsContainerItem
;
1560 static GpStatus
init_container(GraphicsContainerItem
** container
,
1561 GDIPCONST GpGraphics
* graphics
){
1564 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1568 (*container
)->contid
= graphics
->contid
+ 1;
1570 (*container
)->smoothing
= graphics
->smoothing
;
1571 (*container
)->compqual
= graphics
->compqual
;
1572 (*container
)->interpolation
= graphics
->interpolation
;
1573 (*container
)->compmode
= graphics
->compmode
;
1574 (*container
)->texthint
= graphics
->texthint
;
1575 (*container
)->scale
= graphics
->scale
;
1576 (*container
)->unit
= graphics
->unit
;
1577 (*container
)->textcontrast
= graphics
->textcontrast
;
1578 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1580 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1582 GdipFree(*container
);
1587 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1589 GdipDeleteMatrix((*container
)->worldtrans
);
1590 GdipFree(*container
);
1598 static void delete_container(GraphicsContainerItem
* container
){
1599 GdipDeleteMatrix(container
->worldtrans
);
1600 GdipDeleteRegion(container
->clip
);
1601 GdipFree(container
);
1604 static GpStatus
restore_container(GpGraphics
* graphics
,
1605 GDIPCONST GraphicsContainerItem
* container
){
1610 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1614 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1616 GdipDeleteMatrix(newTrans
);
1620 GdipDeleteMatrix(graphics
->worldtrans
);
1621 graphics
->worldtrans
= newTrans
;
1623 GdipDeleteRegion(graphics
->clip
);
1624 graphics
->clip
= newClip
;
1626 graphics
->contid
= container
->contid
- 1;
1628 graphics
->smoothing
= container
->smoothing
;
1629 graphics
->compqual
= container
->compqual
;
1630 graphics
->interpolation
= container
->interpolation
;
1631 graphics
->compmode
= container
->compmode
;
1632 graphics
->texthint
= container
->texthint
;
1633 graphics
->scale
= container
->scale
;
1634 graphics
->unit
= container
->unit
;
1635 graphics
->textcontrast
= container
->textcontrast
;
1636 graphics
->pixeloffset
= container
->pixeloffset
;
1641 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1647 if(graphics
->hwnd
) {
1648 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1649 return GenericError
;
1651 rect
->X
= wnd_rect
.left
;
1652 rect
->Y
= wnd_rect
.top
;
1653 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1654 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1655 }else if (graphics
->image
){
1656 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1657 if (stat
== Ok
&& unit
!= UnitPixel
)
1658 FIXME("need to convert from unit %i\n", unit
);
1662 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1663 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
1669 /* on success, rgn will contain the region of the graphics object which
1670 * is visible after clipping has been applied */
1671 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
1677 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
1680 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
1683 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
1686 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
1689 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
1692 GdipDeleteRegion(tmp
);
1696 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1698 TRACE("(%p, %p)\n", hdc
, graphics
);
1700 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1703 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1707 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1709 if(hDevice
!= NULL
) {
1710 FIXME("Don't know how to handle parameter hDevice\n");
1711 return NotImplemented
;
1717 if(graphics
== NULL
)
1718 return InvalidParameter
;
1720 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1721 if(!*graphics
) return OutOfMemory
;
1723 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1724 GdipFree(*graphics
);
1728 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1729 GdipFree((*graphics
)->worldtrans
);
1730 GdipFree(*graphics
);
1734 (*graphics
)->hdc
= hdc
;
1735 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1736 (*graphics
)->owndc
= FALSE
;
1737 (*graphics
)->smoothing
= SmoothingModeDefault
;
1738 (*graphics
)->compqual
= CompositingQualityDefault
;
1739 (*graphics
)->interpolation
= InterpolationModeBilinear
;
1740 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1741 (*graphics
)->compmode
= CompositingModeSourceOver
;
1742 (*graphics
)->unit
= UnitDisplay
;
1743 (*graphics
)->scale
= 1.0;
1744 (*graphics
)->busy
= FALSE
;
1745 (*graphics
)->textcontrast
= 4;
1746 list_init(&(*graphics
)->containers
);
1747 (*graphics
)->contid
= 0;
1749 TRACE("<-- %p\n", *graphics
);
1754 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
1758 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1759 if(!*graphics
) return OutOfMemory
;
1761 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1762 GdipFree(*graphics
);
1766 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1767 GdipFree((*graphics
)->worldtrans
);
1768 GdipFree(*graphics
);
1772 (*graphics
)->hdc
= NULL
;
1773 (*graphics
)->hwnd
= NULL
;
1774 (*graphics
)->owndc
= FALSE
;
1775 (*graphics
)->image
= image
;
1776 (*graphics
)->smoothing
= SmoothingModeDefault
;
1777 (*graphics
)->compqual
= CompositingQualityDefault
;
1778 (*graphics
)->interpolation
= InterpolationModeBilinear
;
1779 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1780 (*graphics
)->compmode
= CompositingModeSourceOver
;
1781 (*graphics
)->unit
= UnitDisplay
;
1782 (*graphics
)->scale
= 1.0;
1783 (*graphics
)->busy
= FALSE
;
1784 (*graphics
)->textcontrast
= 4;
1785 list_init(&(*graphics
)->containers
);
1786 (*graphics
)->contid
= 0;
1788 TRACE("<-- %p\n", *graphics
);
1793 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1798 TRACE("(%p, %p)\n", hwnd
, graphics
);
1802 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1804 ReleaseDC(hwnd
, hdc
);
1808 (*graphics
)->hwnd
= hwnd
;
1809 (*graphics
)->owndc
= TRUE
;
1814 /* FIXME: no icm handling */
1815 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
1817 TRACE("(%p, %p)\n", hwnd
, graphics
);
1819 return GdipCreateFromHWND(hwnd
, graphics
);
1822 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
1823 GpMetafile
**metafile
)
1827 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
1829 if(!hemf
|| !metafile
)
1830 return InvalidParameter
;
1833 FIXME("not implemented\n");
1835 return NotImplemented
;
1838 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1839 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1841 IStream
*stream
= NULL
;
1845 GpStatus retval
= Ok
;
1847 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1849 if(!hwmf
|| !metafile
|| !placeable
)
1850 return InvalidParameter
;
1853 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1855 return GenericError
;
1856 copy
= GdipAlloc(read
);
1857 GetMetaFileBitsEx(hwmf
, read
, copy
);
1859 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1862 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1863 copy
= GdipAlloc(read
);
1864 GetEnhMetaFileBits(hemf
, read
, copy
);
1865 DeleteEnhMetaFile(hemf
);
1867 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1868 ERR("could not make stream\n");
1870 retval
= GenericError
;
1874 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1876 retval
= OutOfMemory
;
1880 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1881 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1883 retval
= GenericError
;
1888 (*metafile
)->image
.type
= ImageTypeMetafile
;
1889 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
1890 (*metafile
)->image
.palette_flags
= 0;
1891 (*metafile
)->image
.palette_count
= 0;
1892 (*metafile
)->image
.palette_size
= 0;
1893 (*metafile
)->image
.palette_entries
= NULL
;
1894 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
1895 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
1896 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1897 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Top
) / ((REAL
) placeable
->Inch
);
1898 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1899 - placeable
->BoundingBox
.Left
));
1900 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1901 - placeable
->BoundingBox
.Top
));
1902 (*metafile
)->unit
= UnitPixel
;
1905 DeleteMetaFile(hwmf
);
1907 TRACE("<-- %p\n", *metafile
);
1911 GdipFree(*metafile
);
1912 IStream_Release(stream
);
1916 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1917 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1919 HMETAFILE hmf
= GetMetaFileW(file
);
1921 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1923 if(!hmf
) return InvalidParameter
;
1925 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1928 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
1929 GpMetafile
**metafile
)
1931 FIXME("(%p, %p): stub\n", file
, metafile
);
1932 return NotImplemented
;
1935 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
1936 GpMetafile
**metafile
)
1938 FIXME("(%p, %p): stub\n", stream
, metafile
);
1939 return NotImplemented
;
1942 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1943 UINT access
, IStream
**stream
)
1948 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1950 if(!stream
|| !filename
)
1951 return InvalidParameter
;
1953 if(access
& GENERIC_WRITE
)
1954 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1955 else if(access
& GENERIC_READ
)
1956 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1958 return InvalidParameter
;
1960 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1962 return hresult_to_status(ret
);
1965 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1967 GraphicsContainerItem
*cont
, *next
;
1968 TRACE("(%p)\n", graphics
);
1970 if(!graphics
) return InvalidParameter
;
1971 if(graphics
->busy
) return ObjectBusy
;
1974 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1976 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
1977 list_remove(&cont
->entry
);
1978 delete_container(cont
);
1981 GdipDeleteRegion(graphics
->clip
);
1982 GdipDeleteMatrix(graphics
->worldtrans
);
1988 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1989 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1991 INT save_state
, num_pts
;
1992 GpPointF points
[MAX_ARC_PTS
];
1995 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1996 width
, height
, startAngle
, sweepAngle
);
1998 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1999 return InvalidParameter
;
2006 FIXME("graphics object has no HDC\n");
2010 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2012 save_state
= prepare_dc(graphics
, pen
);
2014 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
2016 restore_dc(graphics
, save_state
);
2021 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2022 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2024 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2025 width
, height
, startAngle
, sweepAngle
);
2027 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2030 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2031 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2037 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2038 x2
, y2
, x3
, y3
, x4
, y4
);
2040 if(!graphics
|| !pen
)
2041 return InvalidParameter
;
2048 FIXME("graphics object has no HDC\n");
2061 save_state
= prepare_dc(graphics
, pen
);
2063 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2065 restore_dc(graphics
, save_state
);
2070 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2071 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2077 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2078 x2
, y2
, x3
, y3
, x4
, y4
);
2080 if(!graphics
|| !pen
)
2081 return InvalidParameter
;
2088 FIXME("graphics object has no HDC\n");
2101 save_state
= prepare_dc(graphics
, pen
);
2103 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2105 restore_dc(graphics
, save_state
);
2110 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2111 GDIPCONST GpPointF
*points
, INT count
)
2116 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2118 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2119 return InvalidParameter
;
2124 for(i
= 0; i
< floor(count
/ 4); i
++){
2125 ret
= GdipDrawBezier(graphics
, pen
,
2126 points
[4*i
].X
, points
[4*i
].Y
,
2127 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
2128 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
2129 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
2137 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2138 GDIPCONST GpPoint
*points
, INT count
)
2144 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2146 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2147 return InvalidParameter
;
2152 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2156 for(i
= 0; i
< count
; i
++){
2157 pts
[i
].X
= (REAL
)points
[i
].X
;
2158 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2161 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2168 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2169 GDIPCONST GpPointF
*points
, INT count
)
2171 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2173 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2176 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2177 GDIPCONST GpPoint
*points
, INT count
)
2179 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2181 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2184 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2185 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2190 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2192 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2193 return InvalidParameter
;
2198 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
2201 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2203 GdipDeletePath(path
);
2207 stat
= GdipDrawPath(graphics
, pen
, path
);
2209 GdipDeletePath(path
);
2214 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2215 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2221 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2223 if(!points
|| count
<= 0)
2224 return InvalidParameter
;
2226 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2230 for(i
= 0; i
< count
; i
++){
2231 ptf
[i
].X
= (REAL
)points
[i
].X
;
2232 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2235 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2242 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2243 GDIPCONST GpPointF
*points
, INT count
)
2245 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2247 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2250 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2251 GDIPCONST GpPoint
*points
, INT count
)
2257 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2260 return InvalidParameter
;
2262 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2266 for(i
= 0; i
< count
; i
++){
2267 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2268 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2271 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2277 /* Approximates cardinal spline with Bezier curves. */
2278 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2279 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2281 /* PolyBezier expects count*3-2 points. */
2282 INT i
, len_pt
= count
*3-2, save_state
;
2284 REAL x1
, x2
, y1
, y2
;
2287 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2289 if(!graphics
|| !pen
)
2290 return InvalidParameter
;
2296 return InvalidParameter
;
2300 FIXME("graphics object has no HDC\n");
2304 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
2308 tension
= tension
* TENSION_CONST
;
2310 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
2313 pt
[0].X
= points
[0].X
;
2314 pt
[0].Y
= points
[0].Y
;
2318 for(i
= 0; i
< count
-2; i
++){
2319 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
2323 pt
[3*i
+3].X
= points
[i
+1].X
;
2324 pt
[3*i
+3].Y
= points
[i
+1].Y
;
2329 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
2330 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
2332 pt
[len_pt
-2].X
= x1
;
2333 pt
[len_pt
-2].Y
= y1
;
2334 pt
[len_pt
-1].X
= points
[count
-1].X
;
2335 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
2337 save_state
= prepare_dc(graphics
, pen
);
2339 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
2342 restore_dc(graphics
, save_state
);
2347 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2348 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2354 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2357 return InvalidParameter
;
2359 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2363 for(i
= 0; i
< count
; i
++){
2364 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2365 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2368 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2374 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2375 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2378 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2380 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2381 return InvalidParameter
;
2384 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2387 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2388 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2391 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2397 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2398 return InvalidParameter
;
2401 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2404 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2405 REAL y
, REAL width
, REAL height
)
2411 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2413 if(!graphics
|| !pen
)
2414 return InvalidParameter
;
2421 FIXME("graphics object has no HDC\n");
2427 ptf
[1].X
= x
+ width
;
2428 ptf
[1].Y
= y
+ height
;
2430 save_state
= prepare_dc(graphics
, pen
);
2431 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2433 transform_and_round_points(graphics
, pti
, ptf
, 2);
2435 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2437 restore_dc(graphics
, save_state
);
2442 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2443 INT y
, INT width
, INT height
)
2445 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2447 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2451 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2456 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2458 if(!graphics
|| !image
)
2459 return InvalidParameter
;
2461 GdipGetImageWidth(image
, &width
);
2462 GdipGetImageHeight(image
, &height
);
2464 /* FIXME: we should use the graphics and image dpi, somehow */
2466 points
[0].X
= points
[2].X
= x
;
2467 points
[0].Y
= points
[1].Y
= y
;
2468 points
[1].X
= x
+ width
;
2469 points
[2].Y
= y
+ height
;
2471 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
2472 UnitPixel
, NULL
, NULL
, NULL
);
2475 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2478 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2480 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2483 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2484 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2488 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2490 points
[0].X
= points
[2].X
= x
;
2491 points
[0].Y
= points
[1].Y
= y
;
2493 /* FIXME: convert image coordinates to Graphics coordinates? */
2494 points
[1].X
= x
+ srcwidth
;
2495 points
[2].Y
= y
+ srcheight
;
2497 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2498 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2501 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2502 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2505 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2508 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2509 GDIPCONST GpPointF
*dstpoints
, INT count
)
2511 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
2512 return NotImplemented
;
2515 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2516 GDIPCONST GpPoint
*dstpoints
, INT count
)
2518 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
2519 return NotImplemented
;
2522 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2523 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2524 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2525 DrawImageAbort callback
, VOID
* callbackData
)
2532 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2533 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2537 return NotImplemented
;
2539 if(!graphics
|| !image
|| !points
|| count
!= 3)
2540 return InvalidParameter
;
2542 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2543 debugstr_pointf(&points
[2]));
2545 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2546 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2547 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2548 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
2550 transform_and_round_points(graphics
, pti
, ptf
, 4);
2556 FIXME("graphics object has no HDC\n");
2559 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2560 if(srcUnit
== UnitInch
)
2561 dx
= dy
= (REAL
) INCH_HIMETRIC
;
2562 else if(srcUnit
== UnitPixel
){
2563 dx
= ((REAL
) INCH_HIMETRIC
) /
2564 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
2565 dy
= ((REAL
) INCH_HIMETRIC
) /
2566 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
2569 return NotImplemented
;
2571 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2572 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2573 srcx
* dx
, srcy
* dy
,
2574 srcwidth
* dx
, srcheight
* dy
,
2577 callback(callbackData
);
2578 return GenericError
;
2581 else if (image
->type
== ImageTypeBitmap
)
2583 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2586 if (srcUnit
== UnitInch
)
2587 dx
= dy
= 96.0; /* FIXME: use the image resolution */
2588 else if (srcUnit
== UnitPixel
)
2591 return NotImplemented
;
2595 srcwidth
= srcwidth
* dx
;
2596 srcheight
= srcheight
* dy
;
2598 if (imageAttributes
||
2599 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2600 !((GpBitmap
*)image
)->hbitmap
||
2601 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2602 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2603 srcx
< 0 || srcy
< 0 ||
2604 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2611 int i
, x
, y
, src_stride
, dst_stride
;
2612 GpMatrix
*dst_to_src
;
2613 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2614 LPBYTE src_data
, dst_data
;
2615 BitmapData lockeddata
;
2616 InterpolationMode interpolation
= graphics
->interpolation
;
2617 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2618 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2619 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2621 if (!imageAttributes
)
2622 imageAttributes
= &defaultImageAttributes
;
2624 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2625 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2628 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2629 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2630 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2631 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2634 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2635 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2636 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2637 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2638 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2639 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2641 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
2642 if (stat
!= Ok
) return stat
;
2644 stat
= GdipInvertMatrix(dst_to_src
);
2647 GdipDeleteMatrix(dst_to_src
);
2651 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2654 GdipDeleteMatrix(dst_to_src
);
2658 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2660 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2661 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2663 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
2667 GdipDeleteMatrix(dst_to_src
);
2670 src_stride
= sizeof(ARGB
) * src_area
.Width
;
2672 /* Read the bits we need from the source bitmap into an ARGB buffer. */
2673 lockeddata
.Width
= src_area
.Width
;
2674 lockeddata
.Height
= src_area
.Height
;
2675 lockeddata
.Stride
= src_stride
;
2676 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
2677 lockeddata
.Scan0
= src_data
;
2679 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
2680 PixelFormat32bppARGB
, &lockeddata
);
2683 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2687 if (src_data
!= dst_data
)
2690 GdipDeleteMatrix(dst_to_src
);
2694 apply_image_attributes(imageAttributes
, src_data
,
2695 src_area
.Width
, src_area
.Height
,
2696 src_stride
, ColorAdjustTypeBitmap
);
2698 /* Transform the bits as needed to the destination. */
2699 GdipTransformMatrixPoints(dst_to_src
, dst_to_src_points
, 3);
2701 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
2702 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
2703 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
2704 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
2706 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2708 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2710 GpPointF src_pointf
;
2713 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
2714 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
2716 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2718 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
2719 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
, imageAttributes
, interpolation
);
2725 GdipDeleteMatrix(dst_to_src
);
2729 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
2730 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
2739 int temp_hdc
=0, temp_bitmap
=0;
2740 HBITMAP hbitmap
, old_hbm
=NULL
;
2742 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
2743 bitmap
->format
== PixelFormat24bppRGB
||
2744 bitmap
->format
== PixelFormat32bppRGB
||
2745 bitmap
->format
== PixelFormat32bppPARGB
))
2747 BITMAPINFOHEADER bih
;
2749 PixelFormat dst_format
;
2751 /* we can't draw a bitmap of this format directly */
2752 hdc
= CreateCompatibleDC(0);
2756 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
2757 bih
.biWidth
= bitmap
->width
;
2758 bih
.biHeight
= -bitmap
->height
;
2760 bih
.biBitCount
= 32;
2761 bih
.biCompression
= BI_RGB
;
2762 bih
.biSizeImage
= 0;
2763 bih
.biXPelsPerMeter
= 0;
2764 bih
.biYPelsPerMeter
= 0;
2766 bih
.biClrImportant
= 0;
2768 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
2769 (void**)&temp_bits
, NULL
, 0);
2771 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2772 dst_format
= PixelFormat32bppPARGB
;
2774 dst_format
= PixelFormat32bppRGB
;
2776 convert_pixels(bitmap
->width
, bitmap
->height
,
2777 bitmap
->width
*4, temp_bits
, dst_format
,
2778 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
2782 hbitmap
= bitmap
->hbitmap
;
2784 temp_hdc
= (hdc
== 0);
2789 if (!hdc
) hdc
= CreateCompatibleDC(0);
2790 old_hbm
= SelectObject(hdc
, hbitmap
);
2793 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2797 bf
.BlendOp
= AC_SRC_OVER
;
2799 bf
.SourceConstantAlpha
= 255;
2800 bf
.AlphaFormat
= AC_SRC_ALPHA
;
2802 GdiAlphaBlend(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2803 hdc
, srcx
, srcy
, srcwidth
, srcheight
, bf
);
2807 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2808 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
2813 SelectObject(hdc
, old_hbm
);
2818 DeleteObject(hbitmap
);
2823 ERR("GpImage with no IPicture or HBITMAP?!\n");
2824 return NotImplemented
;
2830 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
2831 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
2832 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2833 DrawImageAbort callback
, VOID
* callbackData
)
2835 GpPointF pointsF
[3];
2838 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
2839 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2842 if(!points
|| count
!=3)
2843 return InvalidParameter
;
2845 for(i
= 0; i
< count
; i
++){
2846 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2847 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2850 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
2851 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
2852 callback
, callbackData
);
2855 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
2856 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
2857 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
2858 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
2859 VOID
* callbackData
)
2863 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2864 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2865 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2869 points
[1].X
= dstx
+ dstwidth
;
2872 points
[2].Y
= dsty
+ dstheight
;
2874 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2875 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2878 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
2879 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
2880 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
2881 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
2882 VOID
* callbackData
)
2886 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2887 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2888 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2892 points
[1].X
= dstx
+ dstwidth
;
2895 points
[2].Y
= dsty
+ dstheight
;
2897 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2898 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2901 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
2902 REAL x
, REAL y
, REAL width
, REAL height
)
2908 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
2910 if(!graphics
|| !image
)
2911 return InvalidParameter
;
2913 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
2917 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
2918 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
2919 unit
, NULL
, NULL
, NULL
);
2922 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
2923 INT x
, INT y
, INT width
, INT height
)
2925 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
2927 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
2930 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2931 REAL y1
, REAL x2
, REAL y2
)
2937 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2939 if(!pen
|| !graphics
)
2940 return InvalidParameter
;
2947 FIXME("graphics object has no HDC\n");
2956 save_state
= prepare_dc(graphics
, pen
);
2958 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2960 restore_dc(graphics
, save_state
);
2965 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2966 INT y1
, INT x2
, INT y2
)
2972 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2974 if(!pen
|| !graphics
)
2975 return InvalidParameter
;
2982 FIXME("graphics object has no HDC\n");
2991 save_state
= prepare_dc(graphics
, pen
);
2993 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2995 restore_dc(graphics
, save_state
);
3000 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3001 GpPointF
*points
, INT count
)
3006 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3008 if(!pen
|| !graphics
|| (count
< 2))
3009 return InvalidParameter
;
3016 FIXME("graphics object has no HDC\n");
3020 save_state
= prepare_dc(graphics
, pen
);
3022 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
3024 restore_dc(graphics
, save_state
);
3029 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3030 GpPoint
*points
, INT count
)
3034 GpPointF
*ptf
= NULL
;
3037 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3039 if(!pen
|| !graphics
|| (count
< 2))
3040 return InvalidParameter
;
3047 FIXME("graphics object has no HDC\n");
3051 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3052 if(!ptf
) return OutOfMemory
;
3054 for(i
= 0; i
< count
; i
++){
3055 ptf
[i
].X
= (REAL
) points
[i
].X
;
3056 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3059 save_state
= prepare_dc(graphics
, pen
);
3061 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
3063 restore_dc(graphics
, save_state
);
3069 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3074 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3076 if(!pen
|| !graphics
)
3077 return InvalidParameter
;
3084 FIXME("graphics object has no HDC\n");
3088 save_state
= prepare_dc(graphics
, pen
);
3090 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3091 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3093 restore_dc(graphics
, save_state
);
3098 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3099 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3103 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3104 width
, height
, startAngle
, sweepAngle
);
3106 if(!graphics
|| !pen
)
3107 return InvalidParameter
;
3114 FIXME("graphics object has no HDC\n");
3118 save_state
= prepare_dc(graphics
, pen
);
3119 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3121 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3123 restore_dc(graphics
, save_state
);
3128 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3129 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3131 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3132 width
, height
, startAngle
, sweepAngle
);
3134 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3137 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3138 REAL y
, REAL width
, REAL height
)
3144 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3146 if(!pen
|| !graphics
)
3147 return InvalidParameter
;
3154 FIXME("graphics object has no HDC\n");
3160 ptf
[1].X
= x
+ width
;
3162 ptf
[2].X
= x
+ width
;
3163 ptf
[2].Y
= y
+ height
;
3165 ptf
[3].Y
= y
+ height
;
3167 save_state
= prepare_dc(graphics
, pen
);
3168 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3170 transform_and_round_points(graphics
, pti
, ptf
, 4);
3171 Polygon(graphics
->hdc
, pti
, 4);
3173 restore_dc(graphics
, save_state
);
3178 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3179 INT y
, INT width
, INT height
)
3181 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3183 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3186 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3187 GDIPCONST GpRectF
* rects
, INT count
)
3193 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3195 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3196 return InvalidParameter
;
3203 FIXME("graphics object has no HDC\n");
3207 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
3208 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
3216 for(i
= 0; i
< count
; i
++){
3217 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
3218 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
3219 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
3220 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
3223 save_state
= prepare_dc(graphics
, pen
);
3224 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3226 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
3228 for(i
= 0; i
< count
; i
++)
3229 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
3231 restore_dc(graphics
, save_state
);
3239 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3240 GDIPCONST GpRect
* rects
, INT count
)
3246 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3248 if(!rects
|| count
<=0)
3249 return InvalidParameter
;
3251 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3255 for(i
= 0;i
< count
;i
++){
3256 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3257 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3258 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3259 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3262 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3268 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3269 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3274 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3275 count
, tension
, fill
);
3277 if(!graphics
|| !brush
|| !points
)
3278 return InvalidParameter
;
3283 if(count
== 1) /* Do nothing */
3286 stat
= GdipCreatePath(fill
, &path
);
3290 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3292 GdipDeletePath(path
);
3296 stat
= GdipFillPath(graphics
, brush
, path
);
3298 GdipDeletePath(path
);
3302 GdipDeletePath(path
);
3307 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3308 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3314 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3315 count
, tension
, fill
);
3317 if(!points
|| count
== 0)
3318 return InvalidParameter
;
3320 if(count
== 1) /* Do nothing */
3323 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3327 for(i
= 0;i
< count
;i
++){
3328 ptf
[i
].X
= (REAL
)points
[i
].X
;
3329 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3332 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3339 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3340 GDIPCONST GpPointF
*points
, INT count
)
3342 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3343 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3344 0.5f
, FillModeAlternate
);
3347 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3348 GDIPCONST GpPoint
*points
, INT count
)
3350 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3351 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3352 0.5f
, FillModeAlternate
);
3355 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3356 REAL y
, REAL width
, REAL height
)
3361 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3363 if(!graphics
|| !brush
)
3364 return InvalidParameter
;
3369 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3373 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3376 stat
= GdipFillPath(graphics
, brush
, path
);
3378 GdipDeletePath(path
);
3384 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3385 INT y
, INT width
, INT height
)
3387 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3389 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3392 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3397 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3398 return NotImplemented
;
3400 save_state
= SaveDC(graphics
->hdc
);
3401 EndPath(graphics
->hdc
);
3402 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3405 BeginPath(graphics
->hdc
);
3406 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3407 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3412 EndPath(graphics
->hdc
);
3413 brush_fill_path(graphics
, brush
);
3418 RestoreDC(graphics
->hdc
, save_state
);
3423 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3428 if (!brush_can_fill_pixels(brush
))
3429 return NotImplemented
;
3431 /* FIXME: This could probably be done more efficiently without regions. */
3433 stat
= GdipCreateRegionPath(path
, &rgn
);
3437 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3439 GdipDeleteRegion(rgn
);
3445 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3447 GpStatus stat
= NotImplemented
;
3449 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3451 if(!brush
|| !graphics
|| !path
)
3452 return InvalidParameter
;
3457 if (!graphics
->image
)
3458 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3460 if (stat
== NotImplemented
)
3461 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3463 if (stat
== NotImplemented
)
3465 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3472 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3473 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3477 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3478 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3480 if(!graphics
|| !brush
)
3481 return InvalidParameter
;
3488 FIXME("graphics object has no HDC\n");
3492 save_state
= SaveDC(graphics
->hdc
);
3493 EndPath(graphics
->hdc
);
3495 BeginPath(graphics
->hdc
);
3496 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3497 EndPath(graphics
->hdc
);
3499 brush_fill_path(graphics
, brush
);
3501 RestoreDC(graphics
->hdc
, save_state
);
3506 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3507 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3509 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3510 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3512 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3515 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3516 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3519 GpPointF
*ptf
= NULL
;
3521 GpStatus retval
= Ok
;
3523 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3525 if(!graphics
|| !brush
|| !points
|| !count
)
3526 return InvalidParameter
;
3533 FIXME("graphics object has no HDC\n");
3537 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3538 pti
= GdipAlloc(count
* sizeof(POINT
));
3540 retval
= OutOfMemory
;
3544 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
3546 save_state
= SaveDC(graphics
->hdc
);
3547 EndPath(graphics
->hdc
);
3548 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
3551 transform_and_round_points(graphics
, pti
, ptf
, count
);
3553 BeginPath(graphics
->hdc
);
3554 Polygon(graphics
->hdc
, pti
, count
);
3555 EndPath(graphics
->hdc
);
3557 brush_fill_path(graphics
, brush
);
3559 RestoreDC(graphics
->hdc
, save_state
);
3568 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3569 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3572 GpPointF
*ptf
= NULL
;
3574 GpStatus retval
= Ok
;
3576 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3578 if(!graphics
|| !brush
|| !points
|| !count
)
3579 return InvalidParameter
;
3586 FIXME("graphics object has no HDC\n");
3590 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3591 pti
= GdipAlloc(count
* sizeof(POINT
));
3593 retval
= OutOfMemory
;
3597 for(i
= 0; i
< count
; i
++){
3598 ptf
[i
].X
= (REAL
) points
[i
].X
;
3599 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3602 save_state
= SaveDC(graphics
->hdc
);
3603 EndPath(graphics
->hdc
);
3604 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
3607 transform_and_round_points(graphics
, pti
, ptf
, count
);
3609 BeginPath(graphics
->hdc
);
3610 Polygon(graphics
->hdc
, pti
, count
);
3611 EndPath(graphics
->hdc
);
3613 brush_fill_path(graphics
, brush
);
3615 RestoreDC(graphics
->hdc
, save_state
);
3624 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3625 GDIPCONST GpPointF
*points
, INT count
)
3627 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3629 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3632 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3633 GDIPCONST GpPoint
*points
, INT count
)
3635 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3637 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3640 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3641 REAL x
, REAL y
, REAL width
, REAL height
)
3647 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3649 if(!graphics
|| !brush
)
3650 return InvalidParameter
;
3657 FIXME("graphics object has no HDC\n");
3663 ptf
[1].X
= x
+ width
;
3665 ptf
[2].X
= x
+ width
;
3666 ptf
[2].Y
= y
+ height
;
3668 ptf
[3].Y
= y
+ height
;
3670 save_state
= SaveDC(graphics
->hdc
);
3671 EndPath(graphics
->hdc
);
3673 transform_and_round_points(graphics
, pti
, ptf
, 4);
3675 BeginPath(graphics
->hdc
);
3676 Polygon(graphics
->hdc
, pti
, 4);
3677 EndPath(graphics
->hdc
);
3679 brush_fill_path(graphics
, brush
);
3681 RestoreDC(graphics
->hdc
, save_state
);
3686 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3687 INT x
, INT y
, INT width
, INT height
)
3693 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3695 if(!graphics
|| !brush
)
3696 return InvalidParameter
;
3703 FIXME("graphics object has no HDC\n");
3709 ptf
[1].X
= x
+ width
;
3711 ptf
[2].X
= x
+ width
;
3712 ptf
[2].Y
= y
+ height
;
3714 ptf
[3].Y
= y
+ height
;
3716 save_state
= SaveDC(graphics
->hdc
);
3717 EndPath(graphics
->hdc
);
3719 transform_and_round_points(graphics
, pti
, ptf
, 4);
3721 BeginPath(graphics
->hdc
);
3722 Polygon(graphics
->hdc
, pti
, 4);
3723 EndPath(graphics
->hdc
);
3725 brush_fill_path(graphics
, brush
);
3727 RestoreDC(graphics
->hdc
, save_state
);
3732 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3738 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3741 return InvalidParameter
;
3743 for(i
= 0; i
< count
; i
++){
3744 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
3745 if(ret
!= Ok
) return ret
;
3751 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3758 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3760 if(!rects
|| count
<= 0)
3761 return InvalidParameter
;
3763 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3767 for(i
= 0; i
< count
; i
++){
3768 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3769 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3770 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3771 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3774 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3780 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3788 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3789 return NotImplemented
;
3791 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3795 save_state
= SaveDC(graphics
->hdc
);
3796 EndPath(graphics
->hdc
);
3798 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3800 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3802 BeginPath(graphics
->hdc
);
3803 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3804 EndPath(graphics
->hdc
);
3806 brush_fill_path(graphics
, brush
);
3809 RestoreDC(graphics
->hdc
, save_state
);
3816 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3820 GpRegion
*temp_region
;
3821 GpMatrix
*world_to_device
, *identity
;
3822 GpRectF graphics_bounds
;
3823 UINT scans_count
, i
;
3828 if (!brush_can_fill_pixels(brush
))
3829 return NotImplemented
;
3831 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3834 stat
= GdipCloneRegion(region
, &temp_region
);
3838 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3839 CoordinateSpaceWorld
, &world_to_device
);
3843 stat
= GdipTransformRegion(temp_region
, world_to_device
);
3845 GdipDeleteMatrix(world_to_device
);
3849 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
3852 stat
= GdipCreateMatrix(&identity
);
3856 stat
= GdipGetRegionScansCount(temp_region
, &scans_count
, identity
);
3858 if (stat
== Ok
&& scans_count
!= 0)
3860 scans
= GdipAlloc(sizeof(*scans
) * scans_count
);
3866 stat
= GdipGetRegionScansI(temp_region
, scans
, &dummy
, identity
);
3873 GdipDeleteMatrix(identity
);
3876 GdipDeleteRegion(temp_region
);
3879 if (stat
== Ok
&& scans_count
== 0)
3884 if (!graphics
->image
)
3886 /* If we have to go through gdi32, use as few alpha blends as possible. */
3887 INT min_x
, min_y
, max_x
, max_y
;
3888 UINT data_width
, data_height
;
3892 max_x
= scans
[0].X
+scans
[0].Width
;
3893 max_y
= scans
[0].Y
+scans
[0].Height
;
3895 for (i
=1; i
<scans_count
; i
++)
3897 min_x
= min(min_x
, scans
[i
].X
);
3898 min_y
= min(min_y
, scans
[i
].Y
);
3899 max_x
= max(max_x
, scans
[i
].X
+scans
[i
].Width
);
3900 max_y
= max(max_y
, scans
[i
].Y
+scans
[i
].Height
);
3903 data_width
= max_x
- min_x
;
3904 data_height
= max_y
- min_y
;
3906 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * data_width
* data_height
);
3912 for (i
=0; i
<scans_count
; i
++)
3914 stat
= brush_fill_pixels(graphics
, brush
,
3915 pixel_data
+ (scans
[i
].X
- min_x
) + (scans
[i
].Y
- min_y
) * data_width
,
3916 &scans
[i
], data_width
);
3924 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
,
3925 (BYTE
*)pixel_data
, data_width
, data_height
,
3929 GdipFree(pixel_data
);
3936 for (i
=0; i
<scans_count
; i
++)
3938 UINT size
= scans
[i
].Width
* scans
[i
].Height
;
3940 if (size
> max_size
)
3944 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * max_size
);
3950 for (i
=0; i
<scans_count
; i
++)
3952 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
, &scans
[i
],
3957 stat
= alpha_blend_pixels(graphics
, scans
[i
].X
, scans
[i
].Y
,
3958 (BYTE
*)pixel_data
, scans
[i
].Width
, scans
[i
].Height
,
3959 scans
[i
].Width
* 4);
3966 GdipFree(pixel_data
);
3976 /*****************************************************************************
3977 * GdipFillRegion [GDIPLUS.@]
3979 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3982 GpStatus stat
= NotImplemented
;
3984 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
3986 if (!(graphics
&& brush
&& region
))
3987 return InvalidParameter
;
3992 if (!graphics
->image
)
3993 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
3995 if (stat
== NotImplemented
)
3996 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
3998 if (stat
== NotImplemented
)
4000 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4007 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4009 TRACE("(%p,%u)\n", graphics
, intention
);
4012 return InvalidParameter
;
4017 /* We have no internal operation queue, so there's no need to clear it. */
4025 /*****************************************************************************
4026 * GdipGetClipBounds [GDIPLUS.@]
4028 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4030 TRACE("(%p, %p)\n", graphics
, rect
);
4033 return InvalidParameter
;
4038 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4041 /*****************************************************************************
4042 * GdipGetClipBoundsI [GDIPLUS.@]
4044 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4046 TRACE("(%p, %p)\n", graphics
, rect
);
4049 return InvalidParameter
;
4054 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4057 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4058 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4059 CompositingMode
*mode
)
4061 TRACE("(%p, %p)\n", graphics
, mode
);
4063 if(!graphics
|| !mode
)
4064 return InvalidParameter
;
4069 *mode
= graphics
->compmode
;
4074 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4075 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4076 CompositingQuality
*quality
)
4078 TRACE("(%p, %p)\n", graphics
, quality
);
4080 if(!graphics
|| !quality
)
4081 return InvalidParameter
;
4086 *quality
= graphics
->compqual
;
4091 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4092 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4093 InterpolationMode
*mode
)
4095 TRACE("(%p, %p)\n", graphics
, mode
);
4097 if(!graphics
|| !mode
)
4098 return InvalidParameter
;
4103 *mode
= graphics
->interpolation
;
4108 /* FIXME: Need to handle color depths less than 24bpp */
4109 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4111 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4113 if(!graphics
|| !argb
)
4114 return InvalidParameter
;
4122 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4124 TRACE("(%p, %p)\n", graphics
, scale
);
4126 if(!graphics
|| !scale
)
4127 return InvalidParameter
;
4132 *scale
= graphics
->scale
;
4137 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4139 TRACE("(%p, %p)\n", graphics
, unit
);
4141 if(!graphics
|| !unit
)
4142 return InvalidParameter
;
4147 *unit
= graphics
->unit
;
4152 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4153 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4156 TRACE("(%p, %p)\n", graphics
, mode
);
4158 if(!graphics
|| !mode
)
4159 return InvalidParameter
;
4164 *mode
= graphics
->pixeloffset
;
4169 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4170 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4172 TRACE("(%p, %p)\n", graphics
, mode
);
4174 if(!graphics
|| !mode
)
4175 return InvalidParameter
;
4180 *mode
= graphics
->smoothing
;
4185 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4187 TRACE("(%p, %p)\n", graphics
, contrast
);
4189 if(!graphics
|| !contrast
)
4190 return InvalidParameter
;
4192 *contrast
= graphics
->textcontrast
;
4197 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4198 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4199 TextRenderingHint
*hint
)
4201 TRACE("(%p, %p)\n", graphics
, hint
);
4203 if(!graphics
|| !hint
)
4204 return InvalidParameter
;
4209 *hint
= graphics
->texthint
;
4214 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4219 TRACE("(%p, %p)\n", graphics
, rect
);
4221 if(!graphics
|| !rect
)
4222 return InvalidParameter
;
4227 /* intersect window and graphics clipping regions */
4228 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4231 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4234 /* get bounds of the region */
4235 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4238 GdipDeleteRegion(clip_rgn
);
4243 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4248 TRACE("(%p, %p)\n", graphics
, rect
);
4250 if(!graphics
|| !rect
)
4251 return InvalidParameter
;
4253 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4255 rect
->X
= roundr(rectf
.X
);
4256 rect
->Y
= roundr(rectf
.Y
);
4257 rect
->Width
= roundr(rectf
.Width
);
4258 rect
->Height
= roundr(rectf
.Height
);
4264 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4266 TRACE("(%p, %p)\n", graphics
, matrix
);
4268 if(!graphics
|| !matrix
)
4269 return InvalidParameter
;
4274 *matrix
= *graphics
->worldtrans
;
4278 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4284 TRACE("(%p, %x)\n", graphics
, color
);
4287 return InvalidParameter
;
4292 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4295 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4296 GdipDeleteBrush((GpBrush
*)brush
);
4300 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4301 wnd_rect
.Width
, wnd_rect
.Height
);
4303 GdipDeleteBrush((GpBrush
*)brush
);
4308 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4310 TRACE("(%p, %p)\n", graphics
, res
);
4312 if(!graphics
|| !res
)
4313 return InvalidParameter
;
4315 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4318 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4324 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4326 if(!graphics
|| !result
)
4327 return InvalidParameter
;
4334 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4335 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4338 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4341 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4344 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4347 GdipDeleteRegion(rgn
);
4351 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4353 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4356 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4362 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4364 if(!graphics
|| !result
)
4365 return InvalidParameter
;
4372 pts
[1].X
= x
+ width
;
4373 pts
[1].Y
= y
+ height
;
4375 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4376 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4379 pts
[1].X
-= pts
[0].X
;
4380 pts
[1].Y
-= pts
[0].Y
;
4382 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4385 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4388 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4391 GdipDeleteRegion(rgn
);
4395 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4397 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4400 GpStatus
gdip_format_string(HDC hdc
,
4401 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4402 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4403 gdip_format_string_callback callback
, void *user_data
)
4406 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4407 nheight
, lineend
, lineno
= 0;
4409 StringAlignment halign
;
4413 if(length
== -1) length
= lstrlenW(string
);
4415 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4416 if(!stringdup
) return OutOfMemory
;
4418 nwidth
= roundr(rect
->Width
);
4419 nheight
= roundr(rect
->Height
);
4421 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
4422 if (rect
->Height
>= INT_MAX
|| rect
->Width
< 0.5) nheight
= INT_MAX
;
4424 for(i
= 0, j
= 0; i
< length
; i
++){
4425 /* FIXME: This makes the indexes passed to callback inaccurate. */
4426 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4429 stringdup
[j
] = string
[i
];
4435 if (format
) halign
= format
->align
;
4436 else halign
= StringAlignmentNear
;
4438 while(sum
< length
){
4439 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4440 nwidth
, &fit
, NULL
, &size
);
4446 for(lret
= 0; lret
< fit
; lret
++)
4447 if(*(stringdup
+ sum
+ lret
) == '\n')
4450 /* Line break code (may look strange, but it imitates windows). */
4452 lineend
= fit
= lret
; /* this is not an off-by-one error */
4453 else if(fit
< (length
- sum
)){
4454 if(*(stringdup
+ sum
+ fit
) == ' ')
4455 while(*(stringdup
+ sum
+ fit
) == ' ')
4458 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4461 if(*(stringdup
+ sum
+ fit
) == '\t')
4470 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4471 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4477 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4478 nwidth
, &j
, NULL
, &size
);
4480 bounds
.Width
= size
.cx
;
4482 if(height
+ size
.cy
> nheight
)
4483 bounds
.Height
= nheight
- (height
+ size
.cy
);
4485 bounds
.Height
= size
.cy
;
4487 bounds
.Y
= rect
->Y
+ height
;
4491 case StringAlignmentNear
:
4495 case StringAlignmentCenter
:
4496 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4498 case StringAlignmentFar
:
4499 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4503 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4504 font
, rect
, format
, lineno
, &bounds
, user_data
);
4509 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4513 if(height
> nheight
)
4516 /* Stop if this was a linewrap (but not if it was a linebreak). */
4517 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
4521 GdipFree(stringdup
);
4526 struct measure_ranges_args
{
4530 static GpStatus
measure_ranges_callback(HDC hdc
,
4531 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4532 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4533 INT lineno
, const RectF
*bounds
, void *user_data
)
4537 struct measure_ranges_args
*args
= user_data
;
4539 for (i
=0; i
<format
->range_count
; i
++)
4541 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4542 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4543 if (range_start
< range_end
)
4548 range_rect
.Y
= bounds
->Y
;
4549 range_rect
.Height
= bounds
->Height
;
4551 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4552 INT_MAX
, NULL
, NULL
, &range_size
);
4553 range_rect
.X
= bounds
->X
+ range_size
.cx
;
4555 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4556 INT_MAX
, NULL
, NULL
, &range_size
);
4557 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
4559 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4568 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4569 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4570 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4571 INT regionCount
, GpRegion
** regions
)
4576 struct measure_ranges_args args
;
4577 HDC hdc
, temp_hdc
=NULL
;
4579 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4580 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4582 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4583 return InvalidParameter
;
4585 if (regionCount
< stringFormat
->range_count
)
4586 return InvalidParameter
;
4590 hdc
= temp_hdc
= CreateCompatibleDC(0);
4591 if (!temp_hdc
) return OutOfMemory
;
4594 hdc
= graphics
->hdc
;
4596 if (stringFormat
->attr
)
4597 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4599 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&font
->lfw
));
4601 for (i
=0; i
<stringFormat
->range_count
; i
++)
4603 stat
= GdipSetEmpty(regions
[i
]);
4608 args
.regions
= regions
;
4610 stat
= gdip_format_string(hdc
, string
, length
, font
, layoutRect
, stringFormat
,
4611 measure_ranges_callback
, &args
);
4613 DeleteObject(SelectObject(hdc
, oldfont
));
4621 struct measure_string_args
{
4623 INT
*codepointsfitted
;
4627 static GpStatus
measure_string_callback(HDC hdc
,
4628 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4629 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4630 INT lineno
, const RectF
*bounds
, void *user_data
)
4632 struct measure_string_args
*args
= user_data
;
4634 if (bounds
->Width
> args
->bounds
->Width
)
4635 args
->bounds
->Width
= bounds
->Width
;
4637 if (bounds
->Height
+ bounds
->Y
> args
->bounds
->Height
+ args
->bounds
->Y
)
4638 args
->bounds
->Height
= bounds
->Height
+ bounds
->Y
- args
->bounds
->Y
;
4640 if (args
->codepointsfitted
)
4641 *args
->codepointsfitted
= index
+ length
;
4643 if (args
->linesfilled
)
4644 (*args
->linesfilled
)++;
4649 /* Find the smallest rectangle that bounds the text when it is printed in rect
4650 * according to the format options listed in format. If rect has 0 width and
4651 * height, then just find the smallest rectangle that bounds the text when it's
4652 * printed at location (rect->X, rect-Y). */
4653 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4654 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4655 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4656 INT
*codepointsfitted
, INT
*linesfilled
)
4659 struct measure_string_args args
;
4662 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4663 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4664 bounds
, codepointsfitted
, linesfilled
);
4666 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4667 return InvalidParameter
;
4671 temp_hdc
= CreateCompatibleDC(0);
4672 if (!temp_hdc
) return OutOfMemory
;
4675 if(linesfilled
) *linesfilled
= 0;
4676 if(codepointsfitted
) *codepointsfitted
= 0;
4679 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4681 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
4683 bounds
->X
= rect
->X
;
4684 bounds
->Y
= rect
->Y
;
4685 bounds
->Width
= 0.0;
4686 bounds
->Height
= 0.0;
4688 args
.bounds
= bounds
;
4689 args
.codepointsfitted
= codepointsfitted
;
4690 args
.linesfilled
= linesfilled
;
4692 gdip_format_string(graphics
->hdc
? graphics
->hdc
: temp_hdc
, string
, length
, font
, rect
, format
,
4693 measure_string_callback
, &args
);
4695 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
4703 struct draw_string_args
{
4706 REAL ang_cos
, ang_sin
;
4709 static GpStatus
draw_string_callback(HDC hdc
,
4710 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4711 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4712 INT lineno
, const RectF
*bounds
, void *user_data
)
4714 struct draw_string_args
*args
= user_data
;
4717 drawcoord
.left
= drawcoord
.right
= args
->drawbase
.x
+ roundr(args
->ang_sin
* bounds
->Y
);
4718 drawcoord
.top
= drawcoord
.bottom
= args
->drawbase
.y
+ roundr(args
->ang_cos
* bounds
->Y
);
4720 DrawTextW(hdc
, string
+ index
, length
, &drawcoord
, args
->drawflags
);
4725 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4726 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4727 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4732 TEXTMETRICW textmet
;
4733 GpPointF pt
[3], rectcpy
[4];
4735 REAL angle
, rel_width
, rel_height
;
4736 INT offsety
= 0, save_state
;
4737 struct draw_string_args args
;
4740 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4741 length
, font
, debugstr_rectf(rect
), format
, brush
);
4743 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4744 return InvalidParameter
;
4746 if((brush
->bt
!= BrushTypeSolidColor
)){
4747 FIXME("not implemented for given parameters\n");
4748 return NotImplemented
;
4753 FIXME("graphics object has no HDC\n");
4758 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4760 /* Should be no need to explicitly test for StringAlignmentNear as
4761 * that is default behavior if no alignment is passed. */
4762 if(format
->vertalign
!= StringAlignmentNear
){
4764 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
4766 if(format
->vertalign
== StringAlignmentCenter
)
4767 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4768 else if(format
->vertalign
== StringAlignmentFar
)
4769 offsety
= (rect
->Height
- bounds
.Height
);
4773 save_state
= SaveDC(graphics
->hdc
);
4774 SetBkMode(graphics
->hdc
, TRANSPARENT
);
4775 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
4783 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4784 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
4785 args
.ang_cos
= cos(angle
);
4786 args
.ang_sin
= sin(angle
);
4787 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4788 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4789 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4790 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4792 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
4793 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
4794 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
4795 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
4796 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
4798 scaled_rect
.X
= 0.0;
4799 scaled_rect
.Y
= 0.0;
4800 scaled_rect
.Width
= rel_width
* rect
->Width
;
4801 scaled_rect
.Height
= rel_height
* rect
->Height
;
4803 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
4805 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4806 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
4807 SelectClipRgn(graphics
->hdc
, rgn
);
4810 /* Use gdi to find the font, then perform transformations on it (height,
4812 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
4813 GetTextMetricsW(graphics
->hdc
, &textmet
);
4816 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
4817 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
4819 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
4821 gdifont
= CreateFontIndirectW(&lfw
);
4822 DeleteObject(SelectObject(graphics
->hdc
, gdifont
));
4824 if (!format
|| format
->align
== StringAlignmentNear
)
4826 args
.drawbase
.x
= corners
[0].x
;
4827 args
.drawbase
.y
= corners
[0].y
;
4828 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
;
4830 else if (format
->align
== StringAlignmentCenter
)
4832 args
.drawbase
.x
= (corners
[0].x
+ corners
[1].x
)/2;
4833 args
.drawbase
.y
= (corners
[0].y
+ corners
[1].y
)/2;
4834 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_CENTER
;
4836 else /* (format->align == StringAlignmentFar) */
4838 args
.drawbase
.x
= corners
[1].x
;
4839 args
.drawbase
.y
= corners
[1].y
;
4840 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_RIGHT
;
4843 gdip_format_string(graphics
->hdc
, string
, length
, font
, &scaled_rect
, format
,
4844 draw_string_callback
, &args
);
4847 DeleteObject(gdifont
);
4849 RestoreDC(graphics
->hdc
, save_state
);
4854 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
4856 TRACE("(%p)\n", graphics
);
4859 return InvalidParameter
;
4864 return GdipSetInfinite(graphics
->clip
);
4867 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
4869 TRACE("(%p)\n", graphics
);
4872 return InvalidParameter
;
4877 graphics
->worldtrans
->matrix
[0] = 1.0;
4878 graphics
->worldtrans
->matrix
[1] = 0.0;
4879 graphics
->worldtrans
->matrix
[2] = 0.0;
4880 graphics
->worldtrans
->matrix
[3] = 1.0;
4881 graphics
->worldtrans
->matrix
[4] = 0.0;
4882 graphics
->worldtrans
->matrix
[5] = 0.0;
4887 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
4889 return GdipEndContainer(graphics
, state
);
4892 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
4893 GpMatrixOrder order
)
4895 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
4898 return InvalidParameter
;
4903 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
4906 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
4908 return GdipBeginContainer2(graphics
, state
);
4911 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
4912 GraphicsContainer
*state
)
4914 GraphicsContainerItem
*container
;
4917 TRACE("(%p, %p)\n", graphics
, state
);
4919 if(!graphics
|| !state
)
4920 return InvalidParameter
;
4922 sts
= init_container(&container
, graphics
);
4926 list_add_head(&graphics
->containers
, &container
->entry
);
4927 *state
= graphics
->contid
= container
->contid
;
4932 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4934 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4935 return NotImplemented
;
4938 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4940 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4941 return NotImplemented
;
4944 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
4946 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
4947 return NotImplemented
;
4950 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
4953 GraphicsContainerItem
*container
, *container2
;
4955 TRACE("(%p, %x)\n", graphics
, state
);
4958 return InvalidParameter
;
4960 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4961 if(container
->contid
== state
)
4965 /* did not find a matching container */
4966 if(&container
->entry
== &graphics
->containers
)
4969 sts
= restore_container(graphics
, container
);
4973 /* remove all of the containers on top of the found container */
4974 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4975 if(container
->contid
== state
)
4977 list_remove(&container
->entry
);
4978 delete_container(container
);
4981 list_remove(&container
->entry
);
4982 delete_container(container
);
4987 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
4988 REAL sy
, GpMatrixOrder order
)
4990 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
4993 return InvalidParameter
;
4998 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
5001 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5004 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5006 if(!graphics
|| !srcgraphics
)
5007 return InvalidParameter
;
5009 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5012 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5013 CompositingMode mode
)
5015 TRACE("(%p, %d)\n", graphics
, mode
);
5018 return InvalidParameter
;
5023 graphics
->compmode
= mode
;
5028 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5029 CompositingQuality quality
)
5031 TRACE("(%p, %d)\n", graphics
, quality
);
5034 return InvalidParameter
;
5039 graphics
->compqual
= quality
;
5044 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5045 InterpolationMode mode
)
5047 TRACE("(%p, %d)\n", graphics
, mode
);
5049 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5050 return InvalidParameter
;
5055 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5056 mode
= InterpolationModeBilinear
;
5058 if (mode
== InterpolationModeHighQuality
)
5059 mode
= InterpolationModeHighQualityBicubic
;
5061 graphics
->interpolation
= mode
;
5066 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5068 TRACE("(%p, %.2f)\n", graphics
, scale
);
5070 if(!graphics
|| (scale
<= 0.0))
5071 return InvalidParameter
;
5076 graphics
->scale
= scale
;
5081 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5083 TRACE("(%p, %d)\n", graphics
, unit
);
5086 return InvalidParameter
;
5091 if(unit
== UnitWorld
)
5092 return InvalidParameter
;
5094 graphics
->unit
= unit
;
5099 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5102 TRACE("(%p, %d)\n", graphics
, mode
);
5105 return InvalidParameter
;
5110 graphics
->pixeloffset
= mode
;
5115 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5119 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5122 FIXME("not implemented\n");
5124 return NotImplemented
;
5127 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5131 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5134 FIXME("not implemented\n");
5138 return NotImplemented
;
5141 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5143 TRACE("(%p, %d)\n", graphics
, mode
);
5146 return InvalidParameter
;
5151 graphics
->smoothing
= mode
;
5156 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5158 TRACE("(%p, %d)\n", graphics
, contrast
);
5161 return InvalidParameter
;
5163 graphics
->textcontrast
= contrast
;
5168 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5169 TextRenderingHint hint
)
5171 TRACE("(%p, %d)\n", graphics
, hint
);
5174 return InvalidParameter
;
5179 graphics
->texthint
= hint
;
5184 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5186 TRACE("(%p, %p)\n", graphics
, matrix
);
5188 if(!graphics
|| !matrix
)
5189 return InvalidParameter
;
5194 GdipDeleteMatrix(graphics
->worldtrans
);
5195 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
5198 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5199 REAL dy
, GpMatrixOrder order
)
5201 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5204 return InvalidParameter
;
5209 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
5212 /*****************************************************************************
5213 * GdipSetClipHrgn [GDIPLUS.@]
5215 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5220 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5223 return InvalidParameter
;
5225 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5229 status
= GdipSetClipRegion(graphics
, region
, mode
);
5231 GdipDeleteRegion(region
);
5235 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5237 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5240 return InvalidParameter
;
5245 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5248 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5249 REAL width
, REAL height
,
5254 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5257 return InvalidParameter
;
5265 rect
.Height
= height
;
5267 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5270 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5271 INT width
, INT height
,
5274 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5277 return InvalidParameter
;
5282 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5285 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5288 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5290 if(!graphics
|| !region
)
5291 return InvalidParameter
;
5296 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5299 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5304 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5307 FIXME("not implemented\n");
5309 return NotImplemented
;
5312 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5318 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5320 if(!graphics
|| !pen
|| count
<=0)
5321 return InvalidParameter
;
5328 FIXME("graphics object has no HDC\n");
5332 pti
= GdipAlloc(sizeof(POINT
) * count
);
5334 save_state
= prepare_dc(graphics
, pen
);
5335 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5337 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5338 Polygon(graphics
->hdc
, pti
, count
);
5340 restore_dc(graphics
, save_state
);
5346 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5353 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5355 if(count
<=0) return InvalidParameter
;
5356 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5358 for(i
= 0;i
< count
; i
++){
5359 ptf
[i
].X
= (REAL
)points
[i
].X
;
5360 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5363 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5369 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5371 TRACE("(%p, %p)\n", graphics
, dpi
);
5373 if(!graphics
|| !dpi
)
5374 return InvalidParameter
;
5379 if (graphics
->image
)
5380 *dpi
= graphics
->image
->xres
;
5382 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
5387 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5389 TRACE("(%p, %p)\n", graphics
, dpi
);
5391 if(!graphics
|| !dpi
)
5392 return InvalidParameter
;
5397 if (graphics
->image
)
5398 *dpi
= graphics
->image
->yres
;
5400 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
5405 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5406 GpMatrixOrder order
)
5411 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5413 if(!graphics
|| !matrix
)
5414 return InvalidParameter
;
5419 m
= *(graphics
->worldtrans
);
5421 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5423 *(graphics
->worldtrans
) = m
;
5428 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5429 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5431 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5433 TRACE("(%p, %p)\n", graphics
, hdc
);
5435 if(!graphics
|| !hdc
)
5436 return InvalidParameter
;
5441 if (!graphics
->hdc
||
5442 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5444 /* Create a fake HDC and fill it with a constant color. */
5449 BITMAPINFOHEADER bmih
;
5452 stat
= get_graphics_bounds(graphics
, &bounds
);
5456 graphics
->temp_hbitmap_width
= bounds
.Width
;
5457 graphics
->temp_hbitmap_height
= bounds
.Height
;
5459 bmih
.biSize
= sizeof(bmih
);
5460 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5461 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5463 bmih
.biBitCount
= 32;
5464 bmih
.biCompression
= BI_RGB
;
5465 bmih
.biSizeImage
= 0;
5466 bmih
.biXPelsPerMeter
= 0;
5467 bmih
.biYPelsPerMeter
= 0;
5469 bmih
.biClrImportant
= 0;
5471 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5472 (void**)&graphics
->temp_bits
, NULL
, 0);
5474 return GenericError
;
5476 temp_hdc
= CreateCompatibleDC(0);
5479 DeleteObject(hbitmap
);
5480 return GenericError
;
5483 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5484 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5486 SelectObject(temp_hdc
, hbitmap
);
5488 graphics
->temp_hbitmap
= hbitmap
;
5489 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5493 *hdc
= graphics
->hdc
;
5496 graphics
->busy
= TRUE
;
5501 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5503 TRACE("(%p, %p)\n", graphics
, hdc
);
5505 if(!graphics
|| !hdc
)
5506 return InvalidParameter
;
5508 if((graphics
->hdc
!= hdc
&& graphics
->temp_hdc
!= hdc
) || !(graphics
->busy
))
5509 return InvalidParameter
;
5511 if (graphics
->temp_hdc
== hdc
)
5516 /* Find the pixels that have changed, and mark them as opaque. */
5517 pos
= (DWORD
*)graphics
->temp_bits
;
5518 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5520 if (*pos
!= DC_BACKGROUND_KEY
)
5527 /* Write the changed pixels to the real target. */
5528 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5529 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5530 graphics
->temp_hbitmap_width
* 4);
5533 DeleteDC(graphics
->temp_hdc
);
5534 DeleteObject(graphics
->temp_hbitmap
);
5535 graphics
->temp_hdc
= NULL
;
5536 graphics
->temp_hbitmap
= NULL
;
5539 graphics
->busy
= FALSE
;
5544 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5549 TRACE("(%p, %p)\n", graphics
, region
);
5551 if(!graphics
|| !region
)
5552 return InvalidParameter
;
5557 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5560 /* free everything except root node and header */
5561 delete_element(®ion
->node
);
5562 memcpy(region
, clip
, sizeof(GpRegion
));
5568 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5569 GpCoordinateSpace src_space
, GpMatrix
**matrix
)
5571 GpStatus stat
= GdipCreateMatrix(matrix
);
5574 if (dst_space
!= src_space
&& stat
== Ok
)
5576 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
5578 if(graphics
->unit
!= UnitDisplay
)
5579 unitscale
*= graphics
->scale
;
5581 /* transform from src_space to CoordinateSpacePage */
5584 case CoordinateSpaceWorld
:
5585 GdipMultiplyMatrix(*matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
5587 case CoordinateSpacePage
:
5589 case CoordinateSpaceDevice
:
5590 GdipScaleMatrix(*matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
5594 /* transform from CoordinateSpacePage to dst_space */
5597 case CoordinateSpaceWorld
:
5599 GpMatrix
*inverted_transform
;
5600 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
5603 stat
= GdipInvertMatrix(inverted_transform
);
5605 GdipMultiplyMatrix(*matrix
, inverted_transform
, MatrixOrderAppend
);
5606 GdipDeleteMatrix(inverted_transform
);
5610 case CoordinateSpacePage
:
5612 case CoordinateSpaceDevice
:
5613 GdipScaleMatrix(*matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
5620 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5621 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5626 if(!graphics
|| !points
|| count
<= 0)
5627 return InvalidParameter
;
5632 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5634 if (src_space
== dst_space
) return Ok
;
5636 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5640 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
5642 GdipDeleteMatrix(matrix
);
5648 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5649 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5655 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5658 return InvalidParameter
;
5660 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5664 for(i
= 0; i
< count
; i
++){
5665 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5666 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5669 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5672 for(i
= 0; i
< count
; i
++){
5673 points
[i
].X
= roundr(pointsF
[i
].X
);
5674 points
[i
].Y
= roundr(pointsF
[i
].Y
);
5681 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5693 /*****************************************************************************
5694 * GdipTranslateClip [GDIPLUS.@]
5696 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5698 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5701 return InvalidParameter
;
5706 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5709 /*****************************************************************************
5710 * GdipTranslateClipI [GDIPLUS.@]
5712 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5714 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5717 return InvalidParameter
;
5722 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
5726 /*****************************************************************************
5727 * GdipMeasureDriverString [GDIPLUS.@]
5729 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5730 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
5731 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
5733 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
5734 return NotImplemented
;
5737 /*****************************************************************************
5738 * GdipDrawDriverString [GDIPLUS.@]
5740 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5741 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
5742 GDIPCONST PointF
*positions
, INT flags
,
5743 GDIPCONST GpMatrix
*matrix
)
5745 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics
, text
, length
, font
, brush
, positions
, flags
, matrix
);
5746 return NotImplemented
;
5749 GpStatus WINGDIPAPI
GdipRecordMetafile(HDC hdc
, EmfType type
, GDIPCONST GpRectF
*frameRect
,
5750 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5752 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5753 return NotImplemented
;
5756 /*****************************************************************************
5757 * GdipRecordMetafileI [GDIPLUS.@]
5759 GpStatus WINGDIPAPI
GdipRecordMetafileI(HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
5760 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5762 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5763 return NotImplemented
;
5766 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
5767 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5769 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5770 return NotImplemented
;
5773 /*****************************************************************************
5774 * GdipIsVisibleClipEmpty [GDIPLUS.@]
5776 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
5781 TRACE("(%p, %p)\n", graphics
, res
);
5783 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5786 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5789 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
5792 GdipDeleteRegion(rgn
);
5796 GpStatus WINGDIPAPI
GdipGetHemfFromMetafile(GpMetafile
*metafile
, HENHMETAFILE
*hEmf
)
5798 FIXME("(%p,%p): stub\n", metafile
, hEmf
);
5800 if (!metafile
|| !hEmf
)
5801 return InvalidParameter
;
5805 return NotImplemented
;