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 COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
93 case BrushTypeSolidColor
:
95 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
99 case BrushTypeHatchFill
:
101 const GpHatch
*hatch
= (const GpHatch
*)brush
;
102 argb
= hatch
->forecol
;
105 case BrushTypeLinearGradient
:
107 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
108 argb
= line
->startcolor
;
111 case BrushTypePathGradient
:
113 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
114 argb
= grad
->centercolor
;
118 FIXME("unhandled brush type %d\n", brush
->bt
);
122 return ARGB2COLORREF(argb
);
125 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
128 BITMAPINFOHEADER bmih
;
132 bmih
.biSize
= sizeof(bmih
);
136 bmih
.biBitCount
= 32;
137 bmih
.biCompression
= BI_RGB
;
138 bmih
.biSizeImage
= 0;
140 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
143 const char *hatch_data
;
145 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
147 for (y
= 0; y
< 8; y
++)
149 for (x
= 0; x
< 8; x
++)
151 if (hatch_data
[y
] & (0x80 >> x
))
152 bits
[y
* 8 + x
] = hatch
->forecol
;
154 bits
[y
* 8 + x
] = hatch
->backcol
;
160 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
162 for (y
= 0; y
< 64; y
++)
163 bits
[y
] = hatch
->forecol
;
170 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
174 case BrushTypeSolidColor
:
176 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
177 lb
->lbStyle
= BS_SOLID
;
178 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
183 case BrushTypeHatchFill
:
185 const GpHatch
*hatch
= (const GpHatch
*)brush
;
188 hbmp
= create_hatch_bitmap(hatch
);
189 if (!hbmp
) return OutOfMemory
;
191 lb
->lbStyle
= BS_PATTERN
;
193 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
198 FIXME("unhandled brush type %d\n", brush
->bt
);
199 lb
->lbStyle
= BS_SOLID
;
200 lb
->lbColor
= get_gdi_brush_color(brush
);
206 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
211 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
217 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
222 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
224 gdibrush
= CreateBrushIndirect(&lb
);
225 free_gdi_logbrush(&lb
);
230 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
235 INT save_state
, i
, numdashes
;
237 DWORD dash_array
[MAX_DASHLEN
];
239 save_state
= SaveDC(graphics
->hdc
);
241 EndPath(graphics
->hdc
);
243 if(pen
->unit
== UnitPixel
){
247 /* Get an estimate for the amount the pen width is affected by the world
248 * transform. (This is similar to what some of the wine drivers do.) */
253 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
254 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
255 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
257 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
260 if(pen
->dash
== DashStyleCustom
){
261 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
263 TRACE("dashes are: ");
264 for(i
= 0; i
< numdashes
; i
++){
265 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
266 TRACE("%d, ", dash_array
[i
]);
268 TRACE("\n and the pen style is %x\n", pen
->style
);
270 create_gdi_logbrush(pen
->brush
, &lb
);
271 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &lb
,
272 numdashes
, dash_array
);
273 free_gdi_logbrush(&lb
);
277 create_gdi_logbrush(pen
->brush
, &lb
);
278 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &lb
, 0, NULL
);
279 free_gdi_logbrush(&lb
);
282 SelectObject(graphics
->hdc
, gdipen
);
287 static void restore_dc(GpGraphics
*graphics
, INT state
)
289 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
290 RestoreDC(graphics
->hdc
, state
);
293 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
294 GpCoordinateSpace src_space
, GpMatrix
**matrix
);
296 /* This helper applies all the changes that the points listed in ptf need in
297 * order to be drawn on the device context. In the end, this should include at
299 * -scaling by page unit
300 * -applying world transformation
301 * -converting from float to int
302 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
303 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
304 * gdi to draw, and these functions would irreparably mess with line widths.
306 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
307 GpPointF
*ptf
, INT count
)
309 REAL scale_x
, scale_y
;
313 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
314 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
316 /* apply page scale */
317 if(graphics
->unit
!= UnitDisplay
)
319 scale_x
*= graphics
->scale
;
320 scale_y
*= graphics
->scale
;
323 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
324 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
325 GdipTransformMatrixPoints(matrix
, ptf
, count
);
326 GdipDeleteMatrix(matrix
);
328 for(i
= 0; i
< count
; i
++){
329 pti
[i
].x
= roundr(ptf
[i
].X
);
330 pti
[i
].y
= roundr(ptf
[i
].Y
);
334 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
335 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
337 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
339 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
341 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
342 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
348 bf
.BlendOp
= AC_SRC_OVER
;
350 bf
.SourceConstantAlpha
= 255;
351 bf
.AlphaFormat
= AC_SRC_ALPHA
;
353 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
354 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
358 /* Draw non-premultiplied ARGB data to the given graphics object */
359 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
360 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
362 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
364 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
367 for (x
=0; x
<src_width
; x
++)
369 for (y
=0; y
<src_height
; y
++)
371 ARGB dst_color
, src_color
;
372 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
373 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
374 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
380 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
382 ERR("This should not be used for metafiles; fix caller\n");
383 return NotImplemented
;
389 BITMAPINFOHEADER bih
;
392 hdc
= CreateCompatibleDC(0);
394 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
395 bih
.biWidth
= src_width
;
396 bih
.biHeight
= -src_height
;
399 bih
.biCompression
= BI_RGB
;
401 bih
.biXPelsPerMeter
= 0;
402 bih
.biYPelsPerMeter
= 0;
404 bih
.biClrImportant
= 0;
406 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
407 (void**)&temp_bits
, NULL
, 0);
409 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
410 4 * src_width
, src
, src_stride
);
412 SelectObject(hdc
, hbitmap
);
413 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
414 hdc
, 0, 0, src_width
, src_height
);
416 DeleteObject(hbitmap
);
422 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
423 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
)
427 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
433 size
= GetRegionData(hregion
, 0, NULL
);
435 rgndata
= GdipAlloc(size
);
439 GetRegionData(hregion
, size
, rgndata
);
441 rects
= (RECT
*)&rgndata
->Buffer
;
443 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
445 stat
= alpha_blend_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
446 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
447 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
455 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
457 ERR("This should not be used for metafiles; fix caller\n");
458 return NotImplemented
;
464 save
= SaveDC(graphics
->hdc
);
466 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
468 stat
= alpha_blend_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
469 src_height
, src_stride
);
471 RestoreDC(graphics
->hdc
, save
);
477 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
483 a1
= (start
>> 24) & 0xff;
484 a2
= (end
>> 24) & 0xff;
486 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
490 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
491 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
495 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
499 /* clamp to between 0.0 and 1.0, using the wrap mode */
500 if (brush
->wrap
== WrapModeTile
)
502 position
= fmodf(position
, 1.0f
);
503 if (position
< 0.0f
) position
+= 1.0f
;
505 else /* WrapModeFlip* */
507 position
= fmodf(position
, 2.0f
);
508 if (position
< 0.0f
) position
+= 2.0f
;
509 if (position
> 1.0f
) position
= 2.0f
- position
;
512 if (brush
->blendcount
== 1)
517 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
520 /* locate the blend positions surrounding this position */
521 while (position
> brush
->blendpos
[i
])
524 /* interpolate between the blend positions */
525 left_blendpos
= brush
->blendpos
[i
-1];
526 left_blendfac
= brush
->blendfac
[i
-1];
527 right_blendpos
= brush
->blendpos
[i
];
528 right_blendfac
= brush
->blendfac
[i
];
529 range
= right_blendpos
- left_blendpos
;
530 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
531 right_blendfac
* (position
- left_blendpos
)) / range
;
534 if (brush
->pblendcount
== 0)
535 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
539 ARGB left_blendcolor
, right_blendcolor
;
540 REAL left_blendpos
, right_blendpos
;
542 /* locate the blend colors surrounding this position */
543 while (blendfac
> brush
->pblendpos
[i
])
546 /* interpolate between the blend colors */
547 left_blendpos
= brush
->pblendpos
[i
-1];
548 left_blendcolor
= brush
->pblendcolor
[i
-1];
549 right_blendpos
= brush
->pblendpos
[i
];
550 right_blendcolor
= brush
->pblendcolor
[i
];
551 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
552 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
556 static ARGB
transform_color(ARGB color
, const ColorMatrix
*matrix
)
560 unsigned char a
, r
, g
, b
;
562 val
[0] = ((color
>> 16) & 0xff) / 255.0; /* red */
563 val
[1] = ((color
>> 8) & 0xff) / 255.0; /* green */
564 val
[2] = (color
& 0xff) / 255.0; /* blue */
565 val
[3] = ((color
>> 24) & 0xff) / 255.0; /* alpha */
566 val
[4] = 1.0; /* translation */
573 res
[i
] += matrix
->m
[j
][i
] * val
[j
];
576 a
= min(max(floorf(res
[3]*255.0), 0.0), 255.0);
577 r
= min(max(floorf(res
[0]*255.0), 0.0), 255.0);
578 g
= min(max(floorf(res
[1]*255.0), 0.0), 255.0);
579 b
= min(max(floorf(res
[2]*255.0), 0.0), 255.0);
581 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
584 static int color_is_gray(ARGB color
)
586 unsigned char r
, g
, b
;
588 r
= (color
>> 16) & 0xff;
589 g
= (color
>> 8) & 0xff;
592 return (r
== g
) && (g
== b
);
595 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
596 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
600 if (attributes
->colorkeys
[type
].enabled
||
601 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
603 const struct color_key
*key
;
604 BYTE min_blue
, min_green
, min_red
;
605 BYTE max_blue
, max_green
, max_red
;
607 if (attributes
->colorkeys
[type
].enabled
)
608 key
= &attributes
->colorkeys
[type
];
610 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
612 min_blue
= key
->low
&0xff;
613 min_green
= (key
->low
>>8)&0xff;
614 min_red
= (key
->low
>>16)&0xff;
616 max_blue
= key
->high
&0xff;
617 max_green
= (key
->high
>>8)&0xff;
618 max_red
= (key
->high
>>16)&0xff;
620 for (x
=0; x
<width
; x
++)
621 for (y
=0; y
<height
; y
++)
624 BYTE blue
, green
, red
;
625 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
626 blue
= *src_color
&0xff;
627 green
= (*src_color
>>8)&0xff;
628 red
= (*src_color
>>16)&0xff;
629 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
630 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
631 *src_color
= 0x00000000;
635 if (attributes
->colorremaptables
[type
].enabled
||
636 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
638 const struct color_remap_table
*table
;
640 if (attributes
->colorremaptables
[type
].enabled
)
641 table
= &attributes
->colorremaptables
[type
];
643 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
645 for (x
=0; x
<width
; x
++)
646 for (y
=0; y
<height
; y
++)
649 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
650 for (i
=0; i
<table
->mapsize
; i
++)
652 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
654 *src_color
= table
->colormap
[i
].newColor
.Argb
;
661 if (attributes
->colormatrices
[type
].enabled
||
662 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
664 const struct color_matrix
*colormatrices
;
666 if (attributes
->colormatrices
[type
].enabled
)
667 colormatrices
= &attributes
->colormatrices
[type
];
669 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
671 for (x
=0; x
<width
; x
++)
672 for (y
=0; y
<height
; y
++)
675 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
677 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
678 !color_is_gray(*src_color
))
680 *src_color
= transform_color(*src_color
, &colormatrices
->colormatrix
);
682 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
684 *src_color
= transform_color(*src_color
, &colormatrices
->graymatrix
);
689 if (attributes
->gamma_enabled
[type
] ||
690 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
694 if (attributes
->gamma_enabled
[type
])
695 gamma
= attributes
->gamma
[type
];
697 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
699 for (x
=0; x
<width
; x
++)
700 for (y
=0; y
<height
; y
++)
703 BYTE blue
, green
, red
;
704 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
706 blue
= *src_color
&0xff;
707 green
= (*src_color
>>8)&0xff;
708 red
= (*src_color
>>16)&0xff;
710 /* FIXME: We should probably use a table for this. */
711 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
712 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
713 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
715 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
720 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
721 * bitmap that contains all the pixels we may need to draw it. */
722 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
723 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
726 INT left
, top
, right
, bottom
;
728 switch (interpolation
)
730 case InterpolationModeHighQualityBilinear
:
731 case InterpolationModeHighQualityBicubic
:
732 /* FIXME: Include a greater range for the prefilter? */
733 case InterpolationModeBicubic
:
734 case InterpolationModeBilinear
:
735 left
= (INT
)(floorf(srcx
));
736 top
= (INT
)(floorf(srcy
));
737 right
= (INT
)(ceilf(srcx
+srcwidth
));
738 bottom
= (INT
)(ceilf(srcy
+srcheight
));
740 case InterpolationModeNearestNeighbor
:
744 right
= roundr(srcx
+srcwidth
);
745 bottom
= roundr(srcy
+srcheight
);
749 if (wrap
== WrapModeClamp
)
755 if (right
>= bitmap
->width
)
756 right
= bitmap
->width
-1;
757 if (bottom
>= bitmap
->height
)
758 bottom
= bitmap
->height
-1;
762 /* In some cases we can make the rectangle smaller here, but the logic
763 * is hard to get right, and tiling suggests we're likely to use the
764 * entire source image. */
765 if (left
< 0 || right
>= bitmap
->width
)
768 right
= bitmap
->width
-1;
771 if (top
< 0 || bottom
>= bitmap
->height
)
774 bottom
= bitmap
->height
-1;
780 rect
->Width
= right
- left
+ 1;
781 rect
->Height
= bottom
- top
+ 1;
784 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
785 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
787 if (attributes
->wrap
== WrapModeClamp
)
789 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
790 return attributes
->outside_color
;
794 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
796 x
= width
*2 + x
% (width
* 2);
798 y
= height
*2 + y
% (height
* 2);
800 if ((attributes
->wrap
& 1) == 1)
803 if ((x
/ width
) % 2 == 0)
806 x
= width
- 1 - x
% width
;
811 if ((attributes
->wrap
& 2) == 2)
814 if ((y
/ height
) % 2 == 0)
817 y
= height
- 1 - y
% height
;
823 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
825 ERR("out of range pixel requested\n");
829 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
832 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
833 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
834 InterpolationMode interpolation
)
838 switch (interpolation
)
842 FIXME("Unimplemented interpolation %i\n", interpolation
);
844 case InterpolationModeBilinear
:
847 INT leftx
, rightx
, topy
, bottomy
;
848 ARGB topleft
, topright
, bottomleft
, bottomright
;
852 leftxf
= floorf(point
->X
);
854 rightx
= (INT
)ceilf(point
->X
);
855 topyf
= floorf(point
->Y
);
857 bottomy
= (INT
)ceilf(point
->Y
);
859 if (leftx
== rightx
&& topy
== bottomy
)
860 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
861 leftx
, topy
, attributes
);
863 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
864 leftx
, topy
, attributes
);
865 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
866 rightx
, topy
, attributes
);
867 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
868 leftx
, bottomy
, attributes
);
869 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
870 rightx
, bottomy
, attributes
);
872 x_offset
= point
->X
- leftxf
;
873 top
= blend_colors(topleft
, topright
, x_offset
);
874 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
876 return blend_colors(top
, bottom
, point
->Y
- topyf
);
878 case InterpolationModeNearestNeighbor
:
879 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
880 roundr(point
->X
), roundr(point
->Y
), attributes
);
884 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
886 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
889 static INT
brush_can_fill_path(GpBrush
*brush
)
893 case BrushTypeSolidColor
:
895 case BrushTypeHatchFill
:
897 GpHatch
*hatch
= (GpHatch
*)brush
;
898 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
899 ((hatch
->backcol
& 0xff000000) == 0xff000000);
901 case BrushTypeLinearGradient
:
902 case BrushTypeTextureFill
:
903 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
909 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
913 case BrushTypeSolidColor
:
915 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
916 HBITMAP bmp
= ARGB2BMP(fill
->color
);
921 /* partially transparent fill */
923 SelectClipPath(graphics
->hdc
, RGN_AND
);
924 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
926 HDC hdc
= CreateCompatibleDC(NULL
);
930 SelectObject(hdc
, bmp
);
931 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
939 /* else fall through */
943 HBRUSH gdibrush
, old_brush
;
945 gdibrush
= create_gdi_brush(brush
);
946 if (!gdibrush
) return;
948 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
949 FillPath(graphics
->hdc
);
950 SelectObject(graphics
->hdc
, old_brush
);
951 DeleteObject(gdibrush
);
957 static INT
brush_can_fill_pixels(GpBrush
*brush
)
961 case BrushTypeSolidColor
:
962 case BrushTypeHatchFill
:
963 case BrushTypeLinearGradient
:
964 case BrushTypeTextureFill
:
965 case BrushTypePathGradient
:
972 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
973 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
977 case BrushTypeSolidColor
:
980 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
981 for (x
=0; x
<fill_area
->Width
; x
++)
982 for (y
=0; y
<fill_area
->Height
; y
++)
983 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
986 case BrushTypeHatchFill
:
989 GpHatch
*fill
= (GpHatch
*)brush
;
990 const char *hatch_data
;
992 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
993 return NotImplemented
;
995 for (x
=0; x
<fill_area
->Width
; x
++)
996 for (y
=0; y
<fill_area
->Height
; y
++)
1000 /* FIXME: Account for the rendering origin */
1001 hx
= (x
+ fill_area
->X
) % 8;
1002 hy
= (y
+ fill_area
->Y
) % 8;
1004 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1005 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1007 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1012 case BrushTypeLinearGradient
:
1014 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1015 GpPointF draw_points
[3], line_points
[3];
1017 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1018 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1021 draw_points
[0].X
= fill_area
->X
;
1022 draw_points
[0].Y
= fill_area
->Y
;
1023 draw_points
[1].X
= fill_area
->X
+1;
1024 draw_points
[1].Y
= fill_area
->Y
;
1025 draw_points
[2].X
= fill_area
->X
;
1026 draw_points
[2].Y
= fill_area
->Y
+1;
1028 /* Transform the points to a co-ordinate space where X is the point's
1029 * position in the gradient, 0.0 being the start point and 1.0 the
1031 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1032 CoordinateSpaceDevice
, draw_points
, 3);
1036 line_points
[0] = fill
->startpoint
;
1037 line_points
[1] = fill
->endpoint
;
1038 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1039 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1041 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1046 stat
= GdipInvertMatrix(world_to_gradient
);
1049 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1051 GdipDeleteMatrix(world_to_gradient
);
1056 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1057 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1059 for (y
=0; y
<fill_area
->Height
; y
++)
1061 for (x
=0; x
<fill_area
->Width
; x
++)
1063 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1065 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1072 case BrushTypeTextureFill
:
1074 GpTexture
*fill
= (GpTexture
*)brush
;
1075 GpPointF draw_points
[3];
1077 GpMatrix
*world_to_texture
;
1083 if (fill
->image
->type
!= ImageTypeBitmap
)
1085 FIXME("metafile texture brushes not implemented\n");
1086 return NotImplemented
;
1089 bitmap
= (GpBitmap
*)fill
->image
;
1090 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1092 src_area
.X
= src_area
.Y
= 0;
1093 src_area
.Width
= bitmap
->width
;
1094 src_area
.Height
= bitmap
->height
;
1096 draw_points
[0].X
= fill_area
->X
;
1097 draw_points
[0].Y
= fill_area
->Y
;
1098 draw_points
[1].X
= fill_area
->X
+1;
1099 draw_points
[1].Y
= fill_area
->Y
;
1100 draw_points
[2].X
= fill_area
->X
;
1101 draw_points
[2].Y
= fill_area
->Y
+1;
1103 /* Transform the points to the co-ordinate space of the bitmap. */
1104 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1105 CoordinateSpaceDevice
, draw_points
, 3);
1109 stat
= GdipCloneMatrix(fill
->transform
, &world_to_texture
);
1114 stat
= GdipInvertMatrix(world_to_texture
);
1117 stat
= GdipTransformMatrixPoints(world_to_texture
, draw_points
, 3);
1119 GdipDeleteMatrix(world_to_texture
);
1122 if (stat
== Ok
&& !fill
->bitmap_bits
)
1124 BitmapData lockeddata
;
1126 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1127 if (!fill
->bitmap_bits
)
1132 lockeddata
.Width
= bitmap
->width
;
1133 lockeddata
.Height
= bitmap
->height
;
1134 lockeddata
.Stride
= src_stride
;
1135 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1136 lockeddata
.Scan0
= fill
->bitmap_bits
;
1138 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1139 PixelFormat32bppARGB
, &lockeddata
);
1143 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1146 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1147 bitmap
->width
, bitmap
->height
,
1148 src_stride
, ColorAdjustTypeBitmap
);
1152 GdipFree(fill
->bitmap_bits
);
1153 fill
->bitmap_bits
= NULL
;
1159 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1160 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1161 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1162 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1164 for (y
=0; y
<fill_area
->Height
; y
++)
1166 for (x
=0; x
<fill_area
->Width
; x
++)
1169 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1170 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1172 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1173 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1174 &point
, fill
->imageattributes
, graphics
->interpolation
);
1181 case BrushTypePathGradient
:
1183 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1185 GpMatrix
*world_to_device
;
1187 int i
, figure_start
=0;
1188 GpPointF start_point
, end_point
, center_point
;
1190 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1191 INT min_y
, max_y
, min_x
, max_x
;
1194 static int transform_fixme_once
;
1196 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1200 FIXME("path gradient focus not implemented\n");
1207 FIXME("path gradient gamma correction not implemented\n");
1210 if (fill
->blendcount
)
1214 FIXME("path gradient blend not implemented\n");
1217 if (fill
->pblendcount
)
1221 FIXME("path gradient preset blend not implemented\n");
1224 if (!transform_fixme_once
)
1226 BOOL is_identity
=TRUE
;
1227 GdipIsMatrixIdentity(fill
->transform
, &is_identity
);
1230 FIXME("path gradient transform not implemented\n");
1231 transform_fixme_once
= 1;
1235 stat
= GdipClonePath(fill
->path
, &flat_path
);
1240 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1241 CoordinateSpaceWorld
, &world_to_device
);
1244 stat
= GdipTransformPath(flat_path
, world_to_device
);
1248 center_point
= fill
->center
;
1249 stat
= GdipTransformMatrixPoints(world_to_device
, ¢er_point
, 1);
1253 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1255 GdipDeleteMatrix(world_to_device
);
1260 GdipDeletePath(flat_path
);
1264 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1266 int start_center_line
=0, end_center_line
=0;
1267 int seen_start
=0, seen_end
=0, seen_center
=0;
1268 REAL center_distance
;
1269 ARGB start_color
, end_color
;
1272 type
= flat_path
->pathdata
.Types
[i
];
1274 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1277 start_point
= flat_path
->pathdata
.Points
[i
];
1279 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1281 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1283 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1284 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1286 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1288 end_point
= flat_path
->pathdata
.Points
[i
+1];
1289 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1294 outer_color
= start_color
;
1296 min_yf
= center_point
.Y
;
1297 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1298 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1300 if (min_yf
< fill_area
->Y
)
1301 min_y
= fill_area
->Y
;
1303 min_y
= (INT
)ceil(min_yf
);
1305 max_yf
= center_point
.Y
;
1306 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1307 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1309 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1310 max_y
= fill_area
->Y
+ fill_area
->Height
;
1312 max_y
= (INT
)ceil(max_yf
);
1314 dy
= end_point
.Y
- start_point
.Y
;
1315 dx
= end_point
.X
- start_point
.X
;
1317 /* This is proportional to the distance from start-end line to center point. */
1318 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1319 dx
* (center_point
.Y
- start_point
.Y
);
1321 for (y
=min_y
; y
<max_y
; y
++)
1325 if (!seen_start
&& yf
>= start_point
.Y
)
1328 start_center_line
^= 1;
1330 if (!seen_end
&& yf
>= end_point
.Y
)
1333 end_center_line
^= 1;
1335 if (!seen_center
&& yf
>= center_point
.Y
)
1338 start_center_line
^= 1;
1339 end_center_line
^= 1;
1342 if (start_center_line
)
1343 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1345 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1347 if (end_center_line
)
1348 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1350 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1352 if (line1_xf
< line2_xf
)
1354 min_x
= (INT
)ceil(line1_xf
);
1355 max_x
= (INT
)ceil(line2_xf
);
1359 min_x
= (INT
)ceil(line2_xf
);
1360 max_x
= (INT
)ceil(line1_xf
);
1363 if (min_x
< fill_area
->X
)
1364 min_x
= fill_area
->X
;
1365 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1366 max_x
= fill_area
->X
+ fill_area
->Width
;
1368 for (x
=min_x
; x
<max_x
; x
++)
1373 if (start_color
!= end_color
)
1375 REAL blend_amount
, pdy
, pdx
;
1376 pdy
= yf
- center_point
.Y
;
1377 pdx
= xf
- center_point
.X
;
1378 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1379 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1382 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1383 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1385 distance
= distance
/ center_distance
;
1387 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1388 blend_colors(outer_color
, fill
->centercolor
, distance
);
1393 GdipDeletePath(flat_path
);
1397 return NotImplemented
;
1401 /* GdipDrawPie/GdipFillPie helper function */
1402 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
1403 REAL height
, REAL startAngle
, REAL sweepAngle
)
1410 ptf
[1].X
= x
+ width
;
1411 ptf
[1].Y
= y
+ height
;
1413 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
1414 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
1416 transform_and_round_points(graphics
, pti
, ptf
, 4);
1418 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
1419 pti
[2].y
, pti
[3].x
, pti
[3].y
);
1422 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1423 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1424 * should not be called on an hdc that has a path you care about. */
1425 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1426 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1428 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1429 GpMatrix
*matrix
= NULL
;
1430 HBRUSH brush
= NULL
;
1432 PointF ptf
[4], *custptf
= NULL
;
1433 POINT pt
[4], *custpt
= NULL
;
1435 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1440 if((x1
== x2
) && (y1
== y2
))
1443 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1445 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1447 brush
= CreateSolidBrush(color
);
1448 lb
.lbStyle
= BS_SOLID
;
1451 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1452 PS_JOIN_MITER
, 1, &lb
, 0,
1454 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1455 oldpen
= SelectObject(graphics
->hdc
, pen
);
1462 case LineCapSquareAnchor
:
1463 case LineCapDiamondAnchor
:
1464 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1465 if(cap
== LineCapDiamondAnchor
){
1466 dsmall
= cos(theta
+ M_PI_2
) * size
;
1467 dbig
= sin(theta
+ M_PI_2
) * size
;
1470 dsmall
= cos(theta
+ M_PI_4
) * size
;
1471 dbig
= sin(theta
+ M_PI_4
) * size
;
1474 ptf
[0].X
= x2
- dsmall
;
1475 ptf
[1].X
= x2
+ dbig
;
1477 ptf
[0].Y
= y2
- dbig
;
1478 ptf
[3].Y
= y2
+ dsmall
;
1480 ptf
[1].Y
= y2
- dsmall
;
1481 ptf
[2].Y
= y2
+ dbig
;
1483 ptf
[3].X
= x2
- dbig
;
1484 ptf
[2].X
= x2
+ dsmall
;
1486 transform_and_round_points(graphics
, pt
, ptf
, 4);
1487 Polygon(graphics
->hdc
, pt
, 4);
1490 case LineCapArrowAnchor
:
1491 size
= size
* 4.0 / sqrt(3.0);
1493 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1494 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1499 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1500 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1508 transform_and_round_points(graphics
, pt
, ptf
, 3);
1509 Polygon(graphics
->hdc
, pt
, 3);
1512 case LineCapRoundAnchor
:
1513 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1520 transform_and_round_points(graphics
, pt
, ptf
, 2);
1521 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1524 case LineCapTriangle
:
1526 dx
= cos(M_PI_2
+ theta
) * size
;
1527 dy
= sin(M_PI_2
+ theta
) * size
;
1534 dx
= cos(theta
) * size
;
1535 dy
= sin(theta
) * size
;
1540 transform_and_round_points(graphics
, pt
, ptf
, 3);
1541 Polygon(graphics
->hdc
, pt
, 3);
1545 dx
= dy
= size
/ 2.0;
1552 dx
= -cos(M_PI_2
+ theta
) * size
;
1553 dy
= -sin(M_PI_2
+ theta
) * size
;
1560 transform_and_round_points(graphics
, pt
, ptf
, 4);
1561 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1562 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1569 count
= custom
->pathdata
.Count
;
1570 custptf
= GdipAlloc(count
* sizeof(PointF
));
1571 custpt
= GdipAlloc(count
* sizeof(POINT
));
1572 tp
= GdipAlloc(count
);
1574 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
1577 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1579 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
1580 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1582 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
1583 GdipTransformMatrixPoints(matrix
, custptf
, count
);
1585 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1587 for(i
= 0; i
< count
; i
++)
1588 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1591 BeginPath(graphics
->hdc
);
1592 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1593 EndPath(graphics
->hdc
);
1594 StrokeAndFillPath(graphics
->hdc
);
1597 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1603 GdipDeleteMatrix(matrix
);
1610 SelectObject(graphics
->hdc
, oldbrush
);
1611 SelectObject(graphics
->hdc
, oldpen
);
1612 DeleteObject(brush
);
1617 /* Shortens the line by the given percent by changing x2, y2.
1618 * If percent is > 1.0 then the line will change direction.
1619 * If percent is negative it can lengthen the line. */
1620 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1622 REAL dist
, theta
, dx
, dy
;
1624 if((y1
== *y2
) && (x1
== *x2
))
1627 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1628 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1629 dx
= cos(theta
) * dist
;
1630 dy
= sin(theta
) * dist
;
1636 /* Shortens the line by the given amount by changing x2, y2.
1637 * If the amount is greater than the distance, the line will become length 0.
1638 * If the amount is negative, it can lengthen the line. */
1639 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1641 REAL dx
, dy
, percent
;
1645 if(dx
== 0 && dy
== 0)
1648 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1655 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1658 /* Draws lines between the given points, and if caps is true then draws an endcap
1659 * at the end of the last line. */
1660 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
1661 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1664 GpPointF
*ptcopy
= NULL
;
1665 GpStatus status
= GenericError
;
1670 pti
= GdipAlloc(count
* sizeof(POINT
));
1671 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1673 if(!pti
|| !ptcopy
){
1674 status
= OutOfMemory
;
1678 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1681 if(pen
->endcap
== LineCapArrowAnchor
)
1682 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1683 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
1684 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1685 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1686 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
1687 pen
->customend
->inset
* pen
->width
);
1689 if(pen
->startcap
== LineCapArrowAnchor
)
1690 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1691 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
1692 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1693 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1694 &ptcopy
[0].X
, &ptcopy
[0].Y
,
1695 pen
->customstart
->inset
* pen
->width
);
1697 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1698 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
1699 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1700 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
1703 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1705 if(Polyline(graphics
->hdc
, pti
, count
))
1715 /* Conducts a linear search to find the bezier points that will back off
1716 * the endpoint of the curve by a distance of amt. Linear search works
1717 * better than binary in this case because there are multiple solutions,
1718 * and binary searches often find a bad one. I don't think this is what
1719 * Windows does but short of rendering the bezier without GDI's help it's
1720 * the best we can do. If rev then work from the start of the passed points
1721 * instead of the end. */
1722 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1725 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1726 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1735 origx
= pt
[fourth
].X
;
1736 origy
= pt
[fourth
].Y
;
1737 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1739 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1740 /* reset bezier points to original values */
1741 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1742 /* Perform magic on bezier points. Order is important here.*/
1743 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1744 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1745 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1746 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1747 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1748 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1750 dx
= pt
[fourth
].X
- origx
;
1751 dy
= pt
[fourth
].Y
- origy
;
1753 diff
= sqrt(dx
* dx
+ dy
* dy
);
1754 percent
+= 0.0005 * amt
;
1758 /* Draws bezier curves between given points, and if caps is true then draws an
1759 * endcap at the end of the last line. */
1760 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
1761 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1765 GpStatus status
= GenericError
;
1770 pti
= GdipAlloc(count
* sizeof(POINT
));
1771 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1773 if(!pti
|| !ptcopy
){
1774 status
= OutOfMemory
;
1778 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1781 if(pen
->endcap
== LineCapArrowAnchor
)
1782 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
1783 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1784 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
1787 if(pen
->startcap
== LineCapArrowAnchor
)
1788 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
1789 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1790 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
1792 /* the direction of the line cap is parallel to the direction at the
1793 * end of the bezier (which, if it has been shortened, is not the same
1794 * as the direction from pt[count-2] to pt[count-1]) */
1795 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1796 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1797 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1798 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1800 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1801 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
1802 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
1805 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1807 PolyBezier(graphics
->hdc
, pti
, count
);
1818 /* Draws a combination of bezier curves and lines between points. */
1819 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1820 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1822 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1823 BYTE
*tp
= GdipAlloc(count
);
1824 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1826 GpStatus status
= GenericError
;
1832 if(!pti
|| !tp
|| !ptcopy
){
1833 status
= OutOfMemory
;
1837 for(i
= 1; i
< count
; i
++){
1838 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1839 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1840 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1841 ERR("Bad bezier points\n");
1848 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1850 /* If we are drawing caps, go through the points and adjust them accordingly,
1851 * and draw the caps. */
1853 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1854 case PathPointTypeBezier
:
1855 if(pen
->endcap
== LineCapArrowAnchor
)
1856 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1857 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1858 shorten_bezier_amt(&ptcopy
[count
- 4],
1859 pen
->width
* pen
->customend
->inset
, FALSE
);
1861 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1862 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1863 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1864 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1867 case PathPointTypeLine
:
1868 if(pen
->endcap
== LineCapArrowAnchor
)
1869 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1870 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1872 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1873 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1874 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1875 pen
->customend
->inset
* pen
->width
);
1877 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1878 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1883 ERR("Bad path last point\n");
1887 /* Find start of points */
1888 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1889 == PathPointTypeStart
); j
++);
1891 switch(types
[j
] & PathPointTypePathTypeMask
){
1892 case PathPointTypeBezier
:
1893 if(pen
->startcap
== LineCapArrowAnchor
)
1894 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1895 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1896 shorten_bezier_amt(&ptcopy
[j
- 1],
1897 pen
->width
* pen
->customstart
->inset
, TRUE
);
1899 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1900 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1901 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1902 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1905 case PathPointTypeLine
:
1906 if(pen
->startcap
== LineCapArrowAnchor
)
1907 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1908 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1910 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1911 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1912 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1913 pen
->customstart
->inset
* pen
->width
);
1915 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1916 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1921 ERR("Bad path points\n");
1926 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1928 for(i
= 0; i
< count
; i
++){
1929 tp
[i
] = convert_path_point_type(types
[i
]);
1932 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1944 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1948 BeginPath(graphics
->hdc
);
1949 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1950 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1951 EndPath(graphics
->hdc
);
1955 typedef struct _GraphicsContainerItem
{
1957 GraphicsContainer contid
;
1959 SmoothingMode smoothing
;
1960 CompositingQuality compqual
;
1961 InterpolationMode interpolation
;
1962 CompositingMode compmode
;
1963 TextRenderingHint texthint
;
1966 PixelOffsetMode pixeloffset
;
1968 GpMatrix
* worldtrans
;
1970 INT origin_x
, origin_y
;
1971 } GraphicsContainerItem
;
1973 static GpStatus
init_container(GraphicsContainerItem
** container
,
1974 GDIPCONST GpGraphics
* graphics
){
1977 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1981 (*container
)->contid
= graphics
->contid
+ 1;
1983 (*container
)->smoothing
= graphics
->smoothing
;
1984 (*container
)->compqual
= graphics
->compqual
;
1985 (*container
)->interpolation
= graphics
->interpolation
;
1986 (*container
)->compmode
= graphics
->compmode
;
1987 (*container
)->texthint
= graphics
->texthint
;
1988 (*container
)->scale
= graphics
->scale
;
1989 (*container
)->unit
= graphics
->unit
;
1990 (*container
)->textcontrast
= graphics
->textcontrast
;
1991 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1992 (*container
)->origin_x
= graphics
->origin_x
;
1993 (*container
)->origin_y
= graphics
->origin_y
;
1995 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1997 GdipFree(*container
);
2002 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
2004 GdipDeleteMatrix((*container
)->worldtrans
);
2005 GdipFree(*container
);
2013 static void delete_container(GraphicsContainerItem
* container
){
2014 GdipDeleteMatrix(container
->worldtrans
);
2015 GdipDeleteRegion(container
->clip
);
2016 GdipFree(container
);
2019 static GpStatus
restore_container(GpGraphics
* graphics
,
2020 GDIPCONST GraphicsContainerItem
* container
){
2025 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
2029 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2031 GdipDeleteMatrix(newTrans
);
2035 GdipDeleteMatrix(graphics
->worldtrans
);
2036 graphics
->worldtrans
= newTrans
;
2038 GdipDeleteRegion(graphics
->clip
);
2039 graphics
->clip
= newClip
;
2041 graphics
->contid
= container
->contid
- 1;
2043 graphics
->smoothing
= container
->smoothing
;
2044 graphics
->compqual
= container
->compqual
;
2045 graphics
->interpolation
= container
->interpolation
;
2046 graphics
->compmode
= container
->compmode
;
2047 graphics
->texthint
= container
->texthint
;
2048 graphics
->scale
= container
->scale
;
2049 graphics
->unit
= container
->unit
;
2050 graphics
->textcontrast
= container
->textcontrast
;
2051 graphics
->pixeloffset
= container
->pixeloffset
;
2052 graphics
->origin_x
= container
->origin_x
;
2053 graphics
->origin_y
= container
->origin_y
;
2058 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2064 if(graphics
->hwnd
) {
2065 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2066 return GenericError
;
2068 rect
->X
= wnd_rect
.left
;
2069 rect
->Y
= wnd_rect
.top
;
2070 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2071 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2072 }else if (graphics
->image
){
2073 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2074 if (stat
== Ok
&& unit
!= UnitPixel
)
2075 FIXME("need to convert from unit %i\n", unit
);
2079 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2080 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2086 /* on success, rgn will contain the region of the graphics object which
2087 * is visible after clipping has been applied */
2088 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2094 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2097 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2100 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2103 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2106 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2109 GdipDeleteRegion(tmp
);
2113 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
, HFONT
*hfont
)
2115 HDC hdc
= CreateCompatibleDC(0);
2117 REAL angle
, rel_width
, rel_height
, font_height
, font_to_pixel_scale
;
2119 HFONT unscaled_font
;
2120 TEXTMETRICW textmet
;
2122 font_to_pixel_scale
= units_scale(UnitPoint
, UnitPixel
, font
->family
->dpi
);
2124 if (font
->unit
== UnitPixel
)
2125 font_height
= font
->emSize
* font_to_pixel_scale
;
2128 REAL unit_scale
, res
;
2130 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2131 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2133 font_height
= font
->emSize
* font_to_pixel_scale
* unit_scale
;
2134 if (graphics
->unit
!= UnitDisplay
)
2135 font_height
/= graphics
->scale
;
2145 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2146 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2147 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2148 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2149 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2150 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2152 get_log_fontW(font
, graphics
, &lfw
);
2153 lfw
.lfHeight
= roundr(font_height
* rel_height
);
2154 unscaled_font
= CreateFontIndirectW(&lfw
);
2156 SelectObject(hdc
, unscaled_font
);
2157 GetTextMetricsW(hdc
, &textmet
);
2159 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2160 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
2162 *hfont
= CreateFontIndirectW(&lfw
);
2165 DeleteObject(unscaled_font
);
2168 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2170 TRACE("(%p, %p)\n", hdc
, graphics
);
2172 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2175 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2179 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2181 if(hDevice
!= NULL
) {
2182 FIXME("Don't know how to handle parameter hDevice\n");
2183 return NotImplemented
;
2189 if(graphics
== NULL
)
2190 return InvalidParameter
;
2192 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2193 if(!*graphics
) return OutOfMemory
;
2195 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
2196 GdipFree(*graphics
);
2200 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2201 GdipFree((*graphics
)->worldtrans
);
2202 GdipFree(*graphics
);
2206 (*graphics
)->hdc
= hdc
;
2207 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2208 (*graphics
)->owndc
= FALSE
;
2209 (*graphics
)->smoothing
= SmoothingModeDefault
;
2210 (*graphics
)->compqual
= CompositingQualityDefault
;
2211 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2212 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2213 (*graphics
)->compmode
= CompositingModeSourceOver
;
2214 (*graphics
)->unit
= UnitDisplay
;
2215 (*graphics
)->scale
= 1.0;
2216 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2217 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2218 (*graphics
)->busy
= FALSE
;
2219 (*graphics
)->textcontrast
= 4;
2220 list_init(&(*graphics
)->containers
);
2221 (*graphics
)->contid
= 0;
2223 TRACE("<-- %p\n", *graphics
);
2228 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2232 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2233 if(!*graphics
) return OutOfMemory
;
2235 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
2236 GdipFree(*graphics
);
2240 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2241 GdipFree((*graphics
)->worldtrans
);
2242 GdipFree(*graphics
);
2246 (*graphics
)->hdc
= NULL
;
2247 (*graphics
)->hwnd
= NULL
;
2248 (*graphics
)->owndc
= FALSE
;
2249 (*graphics
)->image
= image
;
2250 (*graphics
)->smoothing
= SmoothingModeDefault
;
2251 (*graphics
)->compqual
= CompositingQualityDefault
;
2252 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2253 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2254 (*graphics
)->compmode
= CompositingModeSourceOver
;
2255 (*graphics
)->unit
= UnitDisplay
;
2256 (*graphics
)->scale
= 1.0;
2257 (*graphics
)->xres
= image
->xres
;
2258 (*graphics
)->yres
= image
->yres
;
2259 (*graphics
)->busy
= FALSE
;
2260 (*graphics
)->textcontrast
= 4;
2261 list_init(&(*graphics
)->containers
);
2262 (*graphics
)->contid
= 0;
2264 TRACE("<-- %p\n", *graphics
);
2269 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2274 TRACE("(%p, %p)\n", hwnd
, graphics
);
2278 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2280 ReleaseDC(hwnd
, hdc
);
2284 (*graphics
)->hwnd
= hwnd
;
2285 (*graphics
)->owndc
= TRUE
;
2290 /* FIXME: no icm handling */
2291 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2293 TRACE("(%p, %p)\n", hwnd
, graphics
);
2295 return GdipCreateFromHWND(hwnd
, graphics
);
2298 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2299 GpMetafile
**metafile
)
2301 IStream
*stream
= NULL
;
2303 ENHMETAHEADER
*copy
;
2304 GpStatus retval
= Ok
;
2306 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2308 if(!hemf
|| !metafile
)
2309 return InvalidParameter
;
2311 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
2312 copy
= GdipAlloc(read
);
2313 GetEnhMetaFileBits(hemf
, read
, (BYTE
*)copy
);
2315 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
2316 ERR("could not make stream\n");
2318 retval
= GenericError
;
2322 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2324 retval
= OutOfMemory
;
2328 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
2329 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
2331 retval
= GenericError
;
2336 (*metafile
)->image
.type
= ImageTypeMetafile
;
2337 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
2338 (*metafile
)->image
.palette
= NULL
;
2339 (*metafile
)->image
.xres
= (REAL
)copy
->szlDevice
.cx
;
2340 (*metafile
)->image
.yres
= (REAL
)copy
->szlDevice
.cy
;
2341 (*metafile
)->bounds
.X
= (REAL
)copy
->rclBounds
.left
;
2342 (*metafile
)->bounds
.Y
= (REAL
)copy
->rclBounds
.top
;
2343 (*metafile
)->bounds
.Width
= (REAL
)(copy
->rclBounds
.right
- copy
->rclBounds
.left
);
2344 (*metafile
)->bounds
.Height
= (REAL
)(copy
->rclBounds
.bottom
- copy
->rclBounds
.top
);
2345 (*metafile
)->unit
= UnitPixel
;
2348 DeleteEnhMetaFile(hemf
);
2350 TRACE("<-- %p\n", *metafile
);
2354 GdipFree(*metafile
);
2355 IStream_Release(stream
);
2359 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2360 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2365 GpStatus retval
= Ok
;
2367 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2369 if(!hwmf
|| !metafile
|| !placeable
)
2370 return InvalidParameter
;
2373 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2375 return GenericError
;
2376 copy
= GdipAlloc(read
);
2377 GetMetaFileBitsEx(hwmf
, read
, copy
);
2379 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2382 retval
= GdipCreateMetafileFromEmf(hemf
, FALSE
, metafile
);
2386 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2387 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2388 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2389 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2390 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2391 placeable
->BoundingBox
.Left
);
2392 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2393 placeable
->BoundingBox
.Top
);
2395 if (delete) DeleteMetaFile(hwmf
);
2400 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2401 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2403 HMETAFILE hmf
= GetMetaFileW(file
);
2405 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2407 if(!hmf
) return InvalidParameter
;
2409 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2412 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2413 GpMetafile
**metafile
)
2415 FIXME("(%p, %p): stub\n", file
, metafile
);
2416 return NotImplemented
;
2419 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2420 GpMetafile
**metafile
)
2422 FIXME("(%p, %p): stub\n", stream
, metafile
);
2423 return NotImplemented
;
2426 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2427 UINT access
, IStream
**stream
)
2432 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2434 if(!stream
|| !filename
)
2435 return InvalidParameter
;
2437 if(access
& GENERIC_WRITE
)
2438 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2439 else if(access
& GENERIC_READ
)
2440 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2442 return InvalidParameter
;
2444 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2446 return hresult_to_status(ret
);
2449 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2451 GraphicsContainerItem
*cont
, *next
;
2453 TRACE("(%p)\n", graphics
);
2455 if(!graphics
) return InvalidParameter
;
2456 if(graphics
->busy
) return ObjectBusy
;
2458 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2460 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2466 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2468 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2469 list_remove(&cont
->entry
);
2470 delete_container(cont
);
2473 GdipDeleteRegion(graphics
->clip
);
2474 GdipDeleteMatrix(graphics
->worldtrans
);
2480 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2481 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2483 INT save_state
, num_pts
;
2484 GpPointF points
[MAX_ARC_PTS
];
2487 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2488 width
, height
, startAngle
, sweepAngle
);
2490 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2491 return InvalidParameter
;
2498 FIXME("graphics object has no HDC\n");
2502 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2504 save_state
= prepare_dc(graphics
, pen
);
2506 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
2508 restore_dc(graphics
, save_state
);
2513 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2514 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2516 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2517 width
, height
, startAngle
, sweepAngle
);
2519 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2522 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2523 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2529 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2530 x2
, y2
, x3
, y3
, x4
, y4
);
2532 if(!graphics
|| !pen
)
2533 return InvalidParameter
;
2540 FIXME("graphics object has no HDC\n");
2553 save_state
= prepare_dc(graphics
, pen
);
2555 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2557 restore_dc(graphics
, save_state
);
2562 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2563 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2569 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2570 x2
, y2
, x3
, y3
, x4
, y4
);
2572 if(!graphics
|| !pen
)
2573 return InvalidParameter
;
2580 FIXME("graphics object has no HDC\n");
2593 save_state
= prepare_dc(graphics
, pen
);
2595 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2597 restore_dc(graphics
, save_state
);
2602 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2603 GDIPCONST GpPointF
*points
, INT count
)
2608 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2610 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2611 return InvalidParameter
;
2616 for(i
= 0; i
< floor(count
/ 4); i
++){
2617 ret
= GdipDrawBezier(graphics
, pen
,
2618 points
[4*i
].X
, points
[4*i
].Y
,
2619 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
2620 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
2621 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
2629 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2630 GDIPCONST GpPoint
*points
, INT count
)
2636 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2638 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2639 return InvalidParameter
;
2644 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2648 for(i
= 0; i
< count
; i
++){
2649 pts
[i
].X
= (REAL
)points
[i
].X
;
2650 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2653 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2660 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2661 GDIPCONST GpPointF
*points
, INT count
)
2663 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2665 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2668 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2669 GDIPCONST GpPoint
*points
, INT count
)
2671 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2673 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2676 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2677 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2682 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2684 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2685 return InvalidParameter
;
2690 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
2693 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2695 GdipDeletePath(path
);
2699 stat
= GdipDrawPath(graphics
, pen
, path
);
2701 GdipDeletePath(path
);
2706 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2707 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2713 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2715 if(!points
|| count
<= 0)
2716 return InvalidParameter
;
2718 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2722 for(i
= 0; i
< count
; i
++){
2723 ptf
[i
].X
= (REAL
)points
[i
].X
;
2724 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2727 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2734 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2735 GDIPCONST GpPointF
*points
, INT count
)
2737 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2739 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2742 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2743 GDIPCONST GpPoint
*points
, INT count
)
2749 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2752 return InvalidParameter
;
2754 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2758 for(i
= 0; i
< count
; i
++){
2759 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2760 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2763 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2769 /* Approximates cardinal spline with Bezier curves. */
2770 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2771 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2773 /* PolyBezier expects count*3-2 points. */
2774 INT i
, len_pt
= count
*3-2, save_state
;
2776 REAL x1
, x2
, y1
, y2
;
2779 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2781 if(!graphics
|| !pen
)
2782 return InvalidParameter
;
2788 return InvalidParameter
;
2792 FIXME("graphics object has no HDC\n");
2796 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
2800 tension
= tension
* TENSION_CONST
;
2802 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
2805 pt
[0].X
= points
[0].X
;
2806 pt
[0].Y
= points
[0].Y
;
2810 for(i
= 0; i
< count
-2; i
++){
2811 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
2815 pt
[3*i
+3].X
= points
[i
+1].X
;
2816 pt
[3*i
+3].Y
= points
[i
+1].Y
;
2821 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
2822 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
2824 pt
[len_pt
-2].X
= x1
;
2825 pt
[len_pt
-2].Y
= y1
;
2826 pt
[len_pt
-1].X
= points
[count
-1].X
;
2827 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
2829 save_state
= prepare_dc(graphics
, pen
);
2831 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
2834 restore_dc(graphics
, save_state
);
2839 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2840 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2846 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2849 return InvalidParameter
;
2851 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2855 for(i
= 0; i
< count
; i
++){
2856 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2857 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2860 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2866 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2867 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2870 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2872 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2873 return InvalidParameter
;
2876 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2879 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2880 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2883 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2889 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2890 return InvalidParameter
;
2893 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2896 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2897 REAL y
, REAL width
, REAL height
)
2903 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2905 if(!graphics
|| !pen
)
2906 return InvalidParameter
;
2913 FIXME("graphics object has no HDC\n");
2919 ptf
[1].X
= x
+ width
;
2920 ptf
[1].Y
= y
+ height
;
2922 save_state
= prepare_dc(graphics
, pen
);
2923 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2925 transform_and_round_points(graphics
, pti
, ptf
, 2);
2927 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2929 restore_dc(graphics
, save_state
);
2934 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2935 INT y
, INT width
, INT height
)
2937 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2939 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2943 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2947 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2949 if(!graphics
|| !image
)
2950 return InvalidParameter
;
2952 GdipGetImageWidth(image
, &width
);
2953 GdipGetImageHeight(image
, &height
);
2955 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2956 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2959 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2962 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2964 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2967 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2968 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2972 REAL scale_x
, scale_y
, width
, height
;
2974 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2976 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2977 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2978 width
= srcwidth
* scale_x
;
2979 height
= srcheight
* scale_y
;
2981 points
[0].X
= points
[2].X
= x
;
2982 points
[0].Y
= points
[1].Y
= y
;
2983 points
[1].X
= x
+ width
;
2984 points
[2].Y
= y
+ height
;
2986 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2987 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2990 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2991 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2994 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2997 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2998 GDIPCONST GpPointF
*dstpoints
, INT count
)
3002 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
3005 return InvalidParameter
;
3007 GdipGetImageWidth(image
, &width
);
3008 GdipGetImageHeight(image
, &height
);
3010 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
3011 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
3014 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
3015 GDIPCONST GpPoint
*dstpoints
, INT count
)
3019 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
3021 if (count
!= 3 || !dstpoints
)
3022 return InvalidParameter
;
3024 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
3025 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
3026 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
3027 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
3028 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
3029 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
3031 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
3034 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
3035 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
3036 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3037 DrawImageAbort callback
, VOID
* callbackData
)
3044 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
3045 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3049 return NotImplemented
;
3051 if(!graphics
|| !image
|| !points
|| count
!= 3)
3052 return InvalidParameter
;
3054 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
3055 debugstr_pointf(&points
[2]));
3057 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
3058 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
3059 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
3060 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
3062 transform_and_round_points(graphics
, pti
, ptf
, 4);
3068 FIXME("graphics object has no HDC\n");
3071 /* FIXME: partially implemented (only works for rectangular parallelograms) */
3072 if(srcUnit
== UnitInch
)
3073 dx
= dy
= (REAL
) INCH_HIMETRIC
;
3074 else if(srcUnit
== UnitPixel
){
3075 dx
= ((REAL
) INCH_HIMETRIC
) /
3076 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
3077 dy
= ((REAL
) INCH_HIMETRIC
) /
3078 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
3081 return NotImplemented
;
3083 if(IPicture_Render(image
->picture
, graphics
->hdc
,
3084 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3085 srcx
* dx
, srcy
* dy
,
3086 srcwidth
* dx
, srcheight
* dy
,
3089 callback(callbackData
);
3090 return GenericError
;
3093 else if (image
->type
== ImageTypeBitmap
)
3095 GpBitmap
* bitmap
= (GpBitmap
*)image
;
3098 if (srcUnit
== UnitInch
)
3099 dx
= dy
= 96.0; /* FIXME: use the image resolution */
3100 else if (srcUnit
== UnitPixel
)
3103 return NotImplemented
;
3107 srcwidth
= srcwidth
* dx
;
3108 srcheight
= srcheight
* dy
;
3110 if (imageAttributes
||
3111 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
3112 !((GpBitmap
*)image
)->hbitmap
||
3113 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
3114 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
3115 srcx
< 0 || srcy
< 0 ||
3116 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
3123 int i
, x
, y
, src_stride
, dst_stride
;
3124 GpMatrix
*dst_to_src
;
3125 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
3126 LPBYTE src_data
, dst_data
;
3127 BitmapData lockeddata
;
3128 InterpolationMode interpolation
= graphics
->interpolation
;
3129 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3130 REAL x_dx
, x_dy
, y_dx
, y_dy
;
3131 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
3133 if (!imageAttributes
)
3134 imageAttributes
= &defaultImageAttributes
;
3136 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3137 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3140 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3141 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3142 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3143 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3146 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3147 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3148 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3149 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3150 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3151 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3153 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
3154 if (stat
!= Ok
) return stat
;
3156 stat
= GdipInvertMatrix(dst_to_src
);
3159 GdipDeleteMatrix(dst_to_src
);
3163 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3166 GdipDeleteMatrix(dst_to_src
);
3170 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3172 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3173 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3175 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3179 GdipDeleteMatrix(dst_to_src
);
3182 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3184 /* Read the bits we need from the source bitmap into an ARGB buffer. */
3185 lockeddata
.Width
= src_area
.Width
;
3186 lockeddata
.Height
= src_area
.Height
;
3187 lockeddata
.Stride
= src_stride
;
3188 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3189 lockeddata
.Scan0
= src_data
;
3191 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3192 PixelFormat32bppARGB
, &lockeddata
);
3195 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3199 if (src_data
!= dst_data
)
3202 GdipDeleteMatrix(dst_to_src
);
3206 apply_image_attributes(imageAttributes
, src_data
,
3207 src_area
.Width
, src_area
.Height
,
3208 src_stride
, ColorAdjustTypeBitmap
);
3210 /* Transform the bits as needed to the destination. */
3211 GdipTransformMatrixPoints(dst_to_src
, dst_to_src_points
, 3);
3213 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3214 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3215 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3216 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3218 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3220 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3222 GpPointF src_pointf
;
3225 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3226 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3228 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3230 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3231 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
, imageAttributes
, interpolation
);
3237 GdipDeleteMatrix(dst_to_src
);
3241 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3242 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3251 int temp_hdc
=0, temp_bitmap
=0;
3252 HBITMAP hbitmap
, old_hbm
=NULL
;
3254 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3255 bitmap
->format
== PixelFormat24bppRGB
||
3256 bitmap
->format
== PixelFormat32bppRGB
||
3257 bitmap
->format
== PixelFormat32bppPARGB
))
3259 BITMAPINFOHEADER bih
;
3261 PixelFormat dst_format
;
3263 /* we can't draw a bitmap of this format directly */
3264 hdc
= CreateCompatibleDC(0);
3268 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3269 bih
.biWidth
= bitmap
->width
;
3270 bih
.biHeight
= -bitmap
->height
;
3272 bih
.biBitCount
= 32;
3273 bih
.biCompression
= BI_RGB
;
3274 bih
.biSizeImage
= 0;
3275 bih
.biXPelsPerMeter
= 0;
3276 bih
.biYPelsPerMeter
= 0;
3278 bih
.biClrImportant
= 0;
3280 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3281 (void**)&temp_bits
, NULL
, 0);
3283 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3284 dst_format
= PixelFormat32bppPARGB
;
3286 dst_format
= PixelFormat32bppRGB
;
3288 convert_pixels(bitmap
->width
, bitmap
->height
,
3289 bitmap
->width
*4, temp_bits
, dst_format
,
3290 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3291 bitmap
->image
.palette
);
3295 hbitmap
= bitmap
->hbitmap
;
3297 temp_hdc
= (hdc
== 0);
3302 if (!hdc
) hdc
= CreateCompatibleDC(0);
3303 old_hbm
= SelectObject(hdc
, hbitmap
);
3306 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3308 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3309 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3313 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3314 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3319 SelectObject(hdc
, old_hbm
);
3324 DeleteObject(hbitmap
);
3329 ERR("GpImage with no IPicture or HBITMAP?!\n");
3330 return NotImplemented
;
3336 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3337 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3338 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3339 DrawImageAbort callback
, VOID
* callbackData
)
3341 GpPointF pointsF
[3];
3344 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3345 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3348 if(!points
|| count
!=3)
3349 return InvalidParameter
;
3351 for(i
= 0; i
< count
; i
++){
3352 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3353 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3356 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3357 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3358 callback
, callbackData
);
3361 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3362 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3363 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3364 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3365 VOID
* callbackData
)
3369 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3370 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3371 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3375 points
[1].X
= dstx
+ dstwidth
;
3378 points
[2].Y
= dsty
+ dstheight
;
3380 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3381 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3384 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3385 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3386 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3387 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3388 VOID
* callbackData
)
3392 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3393 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3394 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3398 points
[1].X
= dstx
+ dstwidth
;
3401 points
[2].Y
= dsty
+ dstheight
;
3403 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3404 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3407 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3408 REAL x
, REAL y
, REAL width
, REAL height
)
3414 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3416 if(!graphics
|| !image
)
3417 return InvalidParameter
;
3419 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3423 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3424 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3425 unit
, NULL
, NULL
, NULL
);
3428 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3429 INT x
, INT y
, INT width
, INT height
)
3431 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3433 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3436 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3437 REAL y1
, REAL x2
, REAL y2
)
3443 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3445 if(!pen
|| !graphics
)
3446 return InvalidParameter
;
3453 FIXME("graphics object has no HDC\n");
3462 save_state
= prepare_dc(graphics
, pen
);
3464 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3466 restore_dc(graphics
, save_state
);
3471 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3472 INT y1
, INT x2
, INT y2
)
3478 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3480 if(!pen
|| !graphics
)
3481 return InvalidParameter
;
3488 FIXME("graphics object has no HDC\n");
3497 save_state
= prepare_dc(graphics
, pen
);
3499 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3501 restore_dc(graphics
, save_state
);
3506 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3507 GpPointF
*points
, INT count
)
3512 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3514 if(!pen
|| !graphics
|| (count
< 2))
3515 return InvalidParameter
;
3522 FIXME("graphics object has no HDC\n");
3526 save_state
= prepare_dc(graphics
, pen
);
3528 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
3530 restore_dc(graphics
, save_state
);
3535 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3536 GpPoint
*points
, INT count
)
3540 GpPointF
*ptf
= NULL
;
3543 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3545 if(!pen
|| !graphics
|| (count
< 2))
3546 return InvalidParameter
;
3553 FIXME("graphics object has no HDC\n");
3557 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3558 if(!ptf
) return OutOfMemory
;
3560 for(i
= 0; i
< count
; i
++){
3561 ptf
[i
].X
= (REAL
) points
[i
].X
;
3562 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3565 save_state
= prepare_dc(graphics
, pen
);
3567 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
3569 restore_dc(graphics
, save_state
);
3575 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3580 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3582 if(!pen
|| !graphics
)
3583 return InvalidParameter
;
3590 FIXME("graphics object has no HDC\n");
3594 save_state
= prepare_dc(graphics
, pen
);
3596 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3597 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3599 restore_dc(graphics
, save_state
);
3604 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3605 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3609 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3610 width
, height
, startAngle
, sweepAngle
);
3612 if(!graphics
|| !pen
)
3613 return InvalidParameter
;
3620 FIXME("graphics object has no HDC\n");
3624 save_state
= prepare_dc(graphics
, pen
);
3625 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3627 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3629 restore_dc(graphics
, save_state
);
3634 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3635 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3637 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3638 width
, height
, startAngle
, sweepAngle
);
3640 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3643 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3644 REAL y
, REAL width
, REAL height
)
3650 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3652 if(!pen
|| !graphics
)
3653 return InvalidParameter
;
3660 FIXME("graphics object has no HDC\n");
3666 ptf
[1].X
= x
+ width
;
3668 ptf
[2].X
= x
+ width
;
3669 ptf
[2].Y
= y
+ height
;
3671 ptf
[3].Y
= y
+ height
;
3673 save_state
= prepare_dc(graphics
, pen
);
3674 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3676 transform_and_round_points(graphics
, pti
, ptf
, 4);
3677 Polygon(graphics
->hdc
, pti
, 4);
3679 restore_dc(graphics
, save_state
);
3684 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3685 INT y
, INT width
, INT height
)
3687 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3689 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3692 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3693 GDIPCONST GpRectF
* rects
, INT count
)
3699 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3701 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3702 return InvalidParameter
;
3709 FIXME("graphics object has no HDC\n");
3713 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
3714 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
3722 for(i
= 0; i
< count
; i
++){
3723 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
3724 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
3725 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
3726 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
3729 save_state
= prepare_dc(graphics
, pen
);
3730 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3732 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
3734 for(i
= 0; i
< count
; i
++)
3735 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
3737 restore_dc(graphics
, save_state
);
3745 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3746 GDIPCONST GpRect
* rects
, INT count
)
3752 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3754 if(!rects
|| count
<=0)
3755 return InvalidParameter
;
3757 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3761 for(i
= 0;i
< count
;i
++){
3762 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3763 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3764 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3765 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3768 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3774 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3775 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3780 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3781 count
, tension
, fill
);
3783 if(!graphics
|| !brush
|| !points
)
3784 return InvalidParameter
;
3789 if(count
== 1) /* Do nothing */
3792 stat
= GdipCreatePath(fill
, &path
);
3796 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3798 GdipDeletePath(path
);
3802 stat
= GdipFillPath(graphics
, brush
, path
);
3804 GdipDeletePath(path
);
3808 GdipDeletePath(path
);
3813 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3814 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3820 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3821 count
, tension
, fill
);
3823 if(!points
|| count
== 0)
3824 return InvalidParameter
;
3826 if(count
== 1) /* Do nothing */
3829 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3833 for(i
= 0;i
< count
;i
++){
3834 ptf
[i
].X
= (REAL
)points
[i
].X
;
3835 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3838 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3845 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3846 GDIPCONST GpPointF
*points
, INT count
)
3848 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3849 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3850 0.5f
, FillModeAlternate
);
3853 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3854 GDIPCONST GpPoint
*points
, INT count
)
3856 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3857 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3858 0.5f
, FillModeAlternate
);
3861 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3862 REAL y
, REAL width
, REAL height
)
3867 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3869 if(!graphics
|| !brush
)
3870 return InvalidParameter
;
3875 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3879 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3882 stat
= GdipFillPath(graphics
, brush
, path
);
3884 GdipDeletePath(path
);
3890 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3891 INT y
, INT width
, INT height
)
3893 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3895 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3898 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3903 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3904 return NotImplemented
;
3906 save_state
= SaveDC(graphics
->hdc
);
3907 EndPath(graphics
->hdc
);
3908 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3911 BeginPath(graphics
->hdc
);
3912 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3913 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3918 EndPath(graphics
->hdc
);
3919 brush_fill_path(graphics
, brush
);
3924 RestoreDC(graphics
->hdc
, save_state
);
3929 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3934 if (!brush_can_fill_pixels(brush
))
3935 return NotImplemented
;
3937 /* FIXME: This could probably be done more efficiently without regions. */
3939 stat
= GdipCreateRegionPath(path
, &rgn
);
3943 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3945 GdipDeleteRegion(rgn
);
3951 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3953 GpStatus stat
= NotImplemented
;
3955 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3957 if(!brush
|| !graphics
|| !path
)
3958 return InvalidParameter
;
3963 if (!graphics
->image
)
3964 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3966 if (stat
== NotImplemented
)
3967 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3969 if (stat
== NotImplemented
)
3971 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3978 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3979 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3984 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3985 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3987 if(!graphics
|| !brush
)
3988 return InvalidParameter
;
3993 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3997 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4000 stat
= GdipFillPath(graphics
, brush
, path
);
4002 GdipDeletePath(path
);
4008 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4009 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4011 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
4012 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4014 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4017 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
4018 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
4023 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4025 if(!graphics
|| !brush
|| !points
|| !count
)
4026 return InvalidParameter
;
4031 stat
= GdipCreatePath(fillMode
, &path
);
4035 stat
= GdipAddPathPolygon(path
, points
, count
);
4038 stat
= GdipFillPath(graphics
, brush
, path
);
4040 GdipDeletePath(path
);
4046 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4047 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4052 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4054 if(!graphics
|| !brush
|| !points
|| !count
)
4055 return InvalidParameter
;
4060 stat
= GdipCreatePath(fillMode
, &path
);
4064 stat
= GdipAddPathPolygonI(path
, points
, count
);
4067 stat
= GdipFillPath(graphics
, brush
, path
);
4069 GdipDeletePath(path
);
4075 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4076 GDIPCONST GpPointF
*points
, INT count
)
4078 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4080 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4083 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4084 GDIPCONST GpPoint
*points
, INT count
)
4086 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4088 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4091 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4092 REAL x
, REAL y
, REAL width
, REAL height
)
4097 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4099 if(!graphics
|| !brush
)
4100 return InvalidParameter
;
4105 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4109 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
4112 stat
= GdipFillPath(graphics
, brush
, path
);
4114 GdipDeletePath(path
);
4120 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4121 INT x
, INT y
, INT width
, INT height
)
4123 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4125 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
4128 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4134 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4137 return InvalidParameter
;
4139 for(i
= 0; i
< count
; i
++){
4140 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
4141 if(ret
!= Ok
) return ret
;
4147 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4154 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4156 if(!rects
|| count
<= 0)
4157 return InvalidParameter
;
4159 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
4163 for(i
= 0; i
< count
; i
++){
4164 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4165 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4166 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
4167 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4170 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4176 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4184 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
4185 return NotImplemented
;
4187 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4191 save_state
= SaveDC(graphics
->hdc
);
4192 EndPath(graphics
->hdc
);
4194 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4196 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4198 BeginPath(graphics
->hdc
);
4199 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4200 EndPath(graphics
->hdc
);
4202 brush_fill_path(graphics
, brush
);
4205 RestoreDC(graphics
->hdc
, save_state
);
4212 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4216 GpRegion
*temp_region
;
4217 GpMatrix
*world_to_device
;
4218 GpRectF graphics_bounds
;
4222 GpRect gp_bound_rect
;
4224 if (!brush_can_fill_pixels(brush
))
4225 return NotImplemented
;
4227 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
4230 stat
= GdipCloneRegion(region
, &temp_region
);
4234 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
4235 CoordinateSpaceWorld
, &world_to_device
);
4239 stat
= GdipTransformRegion(temp_region
, world_to_device
);
4241 GdipDeleteMatrix(world_to_device
);
4245 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4248 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4250 GdipDeleteRegion(temp_region
);
4253 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4255 DeleteObject(hregion
);
4261 gp_bound_rect
.X
= bound_rect
.left
;
4262 gp_bound_rect
.Y
= bound_rect
.top
;
4263 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4264 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4266 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4272 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4273 &gp_bound_rect
, gp_bound_rect
.Width
);
4276 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4277 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4278 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4280 GdipFree(pixel_data
);
4283 DeleteObject(hregion
);
4289 /*****************************************************************************
4290 * GdipFillRegion [GDIPLUS.@]
4292 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4295 GpStatus stat
= NotImplemented
;
4297 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4299 if (!(graphics
&& brush
&& region
))
4300 return InvalidParameter
;
4305 if (!graphics
->image
)
4306 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4308 if (stat
== NotImplemented
)
4309 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4311 if (stat
== NotImplemented
)
4313 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4320 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4322 TRACE("(%p,%u)\n", graphics
, intention
);
4325 return InvalidParameter
;
4330 /* We have no internal operation queue, so there's no need to clear it. */
4338 /*****************************************************************************
4339 * GdipGetClipBounds [GDIPLUS.@]
4341 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4343 TRACE("(%p, %p)\n", graphics
, rect
);
4346 return InvalidParameter
;
4351 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4354 /*****************************************************************************
4355 * GdipGetClipBoundsI [GDIPLUS.@]
4357 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4359 TRACE("(%p, %p)\n", graphics
, rect
);
4362 return InvalidParameter
;
4367 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4370 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4371 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4372 CompositingMode
*mode
)
4374 TRACE("(%p, %p)\n", graphics
, mode
);
4376 if(!graphics
|| !mode
)
4377 return InvalidParameter
;
4382 *mode
= graphics
->compmode
;
4387 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4388 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4389 CompositingQuality
*quality
)
4391 TRACE("(%p, %p)\n", graphics
, quality
);
4393 if(!graphics
|| !quality
)
4394 return InvalidParameter
;
4399 *quality
= graphics
->compqual
;
4404 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4405 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4406 InterpolationMode
*mode
)
4408 TRACE("(%p, %p)\n", graphics
, mode
);
4410 if(!graphics
|| !mode
)
4411 return InvalidParameter
;
4416 *mode
= graphics
->interpolation
;
4421 /* FIXME: Need to handle color depths less than 24bpp */
4422 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4424 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4426 if(!graphics
|| !argb
)
4427 return InvalidParameter
;
4435 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4437 TRACE("(%p, %p)\n", graphics
, scale
);
4439 if(!graphics
|| !scale
)
4440 return InvalidParameter
;
4445 *scale
= graphics
->scale
;
4450 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4452 TRACE("(%p, %p)\n", graphics
, unit
);
4454 if(!graphics
|| !unit
)
4455 return InvalidParameter
;
4460 *unit
= graphics
->unit
;
4465 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4466 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4469 TRACE("(%p, %p)\n", graphics
, mode
);
4471 if(!graphics
|| !mode
)
4472 return InvalidParameter
;
4477 *mode
= graphics
->pixeloffset
;
4482 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4483 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4485 TRACE("(%p, %p)\n", graphics
, mode
);
4487 if(!graphics
|| !mode
)
4488 return InvalidParameter
;
4493 *mode
= graphics
->smoothing
;
4498 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4500 TRACE("(%p, %p)\n", graphics
, contrast
);
4502 if(!graphics
|| !contrast
)
4503 return InvalidParameter
;
4505 *contrast
= graphics
->textcontrast
;
4510 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4511 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4512 TextRenderingHint
*hint
)
4514 TRACE("(%p, %p)\n", graphics
, hint
);
4516 if(!graphics
|| !hint
)
4517 return InvalidParameter
;
4522 *hint
= graphics
->texthint
;
4527 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4532 TRACE("(%p, %p)\n", graphics
, rect
);
4534 if(!graphics
|| !rect
)
4535 return InvalidParameter
;
4540 /* intersect window and graphics clipping regions */
4541 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4544 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4547 /* get bounds of the region */
4548 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4551 GdipDeleteRegion(clip_rgn
);
4556 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4561 TRACE("(%p, %p)\n", graphics
, rect
);
4563 if(!graphics
|| !rect
)
4564 return InvalidParameter
;
4566 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4568 rect
->X
= roundr(rectf
.X
);
4569 rect
->Y
= roundr(rectf
.Y
);
4570 rect
->Width
= roundr(rectf
.Width
);
4571 rect
->Height
= roundr(rectf
.Height
);
4577 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4579 TRACE("(%p, %p)\n", graphics
, matrix
);
4581 if(!graphics
|| !matrix
)
4582 return InvalidParameter
;
4587 *matrix
= *graphics
->worldtrans
;
4591 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4597 TRACE("(%p, %x)\n", graphics
, color
);
4600 return InvalidParameter
;
4605 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4608 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4609 GdipDeleteBrush((GpBrush
*)brush
);
4613 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4614 wnd_rect
.Width
, wnd_rect
.Height
);
4616 GdipDeleteBrush((GpBrush
*)brush
);
4621 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4623 TRACE("(%p, %p)\n", graphics
, res
);
4625 if(!graphics
|| !res
)
4626 return InvalidParameter
;
4628 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4631 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4637 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4639 if(!graphics
|| !result
)
4640 return InvalidParameter
;
4647 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4648 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4651 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4654 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4657 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4660 GdipDeleteRegion(rgn
);
4664 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4666 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4669 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4675 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4677 if(!graphics
|| !result
)
4678 return InvalidParameter
;
4685 pts
[1].X
= x
+ width
;
4686 pts
[1].Y
= y
+ height
;
4688 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4689 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4692 pts
[1].X
-= pts
[0].X
;
4693 pts
[1].Y
-= pts
[0].Y
;
4695 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4698 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4701 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4704 GdipDeleteRegion(rgn
);
4708 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4710 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4713 GpStatus
gdip_format_string(HDC hdc
,
4714 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4715 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4716 gdip_format_string_callback callback
, void *user_data
)
4719 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4720 nheight
, lineend
, lineno
= 0;
4722 StringAlignment halign
;
4725 HotkeyPrefix hkprefix
;
4726 INT
*hotkeyprefix_offsets
=NULL
;
4727 INT hotkeyprefix_count
=0;
4728 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4731 if(length
== -1) length
= lstrlenW(string
);
4733 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4734 if(!stringdup
) return OutOfMemory
;
4736 nwidth
= roundr(rect
->Width
);
4737 nheight
= roundr(rect
->Height
);
4739 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
4740 if (rect
->Height
>= INT_MAX
|| rect
->Height
< 0.5) nheight
= INT_MAX
;
4743 hkprefix
= format
->hkprefix
;
4745 hkprefix
= HotkeyPrefixNone
;
4747 if (hkprefix
== HotkeyPrefixShow
)
4749 for (i
=0; i
<length
; i
++)
4751 if (string
[i
] == '&')
4752 hotkeyprefix_count
++;
4756 if (hotkeyprefix_count
)
4757 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4759 hotkeyprefix_count
= 0;
4761 for(i
= 0, j
= 0; i
< length
; i
++){
4762 /* FIXME: This makes the indexes passed to callback inaccurate. */
4763 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4766 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4767 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4768 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4776 stringdup
[j
] = string
[i
];
4782 if (format
) halign
= format
->align
;
4783 else halign
= StringAlignmentNear
;
4785 while(sum
< length
){
4786 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4787 nwidth
, &fit
, NULL
, &size
);
4793 for(lret
= 0; lret
< fit
; lret
++)
4794 if(*(stringdup
+ sum
+ lret
) == '\n')
4797 /* Line break code (may look strange, but it imitates windows). */
4799 lineend
= fit
= lret
; /* this is not an off-by-one error */
4800 else if(fit
< (length
- sum
)){
4801 if(*(stringdup
+ sum
+ fit
) == ' ')
4802 while(*(stringdup
+ sum
+ fit
) == ' ')
4805 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4808 if(*(stringdup
+ sum
+ fit
) == '\t')
4817 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4818 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4824 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4825 nwidth
, &j
, NULL
, &size
);
4827 bounds
.Width
= size
.cx
;
4829 if(height
+ size
.cy
> nheight
)
4830 bounds
.Height
= nheight
- (height
+ size
.cy
);
4832 bounds
.Height
= size
.cy
;
4834 bounds
.Y
= rect
->Y
+ height
;
4838 case StringAlignmentNear
:
4842 case StringAlignmentCenter
:
4843 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4845 case StringAlignmentFar
:
4846 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4850 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4851 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4854 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4855 font
, rect
, format
, lineno
, &bounds
,
4856 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4857 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4862 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4866 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4868 if(height
> nheight
)
4871 /* Stop if this was a linewrap (but not if it was a linebreak). */
4872 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
4876 GdipFree(stringdup
);
4877 GdipFree(hotkeyprefix_offsets
);
4882 struct measure_ranges_args
{
4886 static GpStatus
measure_ranges_callback(HDC hdc
,
4887 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4888 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4889 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4890 INT underlined_index_count
, void *user_data
)
4894 struct measure_ranges_args
*args
= user_data
;
4896 for (i
=0; i
<format
->range_count
; i
++)
4898 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4899 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4900 if (range_start
< range_end
)
4905 range_rect
.Y
= bounds
->Y
;
4906 range_rect
.Height
= bounds
->Height
;
4908 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4909 INT_MAX
, NULL
, NULL
, &range_size
);
4910 range_rect
.X
= bounds
->X
+ range_size
.cx
;
4912 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4913 INT_MAX
, NULL
, NULL
, &range_size
);
4914 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
4916 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4925 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4926 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4927 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4928 INT regionCount
, GpRegion
** regions
)
4934 struct measure_ranges_args args
;
4935 HDC hdc
, temp_hdc
=NULL
;
4937 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4938 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4940 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4941 return InvalidParameter
;
4943 if (regionCount
< stringFormat
->range_count
)
4944 return InvalidParameter
;
4946 get_log_fontW(font
, graphics
, &lfw
);
4950 hdc
= temp_hdc
= CreateCompatibleDC(0);
4951 if (!temp_hdc
) return OutOfMemory
;
4954 hdc
= graphics
->hdc
;
4956 if (stringFormat
->attr
)
4957 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4959 oldfont
= SelectObject(hdc
, CreateFontIndirectW(&lfw
));
4961 for (i
=0; i
<stringFormat
->range_count
; i
++)
4963 stat
= GdipSetEmpty(regions
[i
]);
4968 args
.regions
= regions
;
4970 stat
= gdip_format_string(hdc
, string
, length
, font
, layoutRect
, stringFormat
,
4971 measure_ranges_callback
, &args
);
4973 DeleteObject(SelectObject(hdc
, oldfont
));
4981 struct measure_string_args
{
4983 INT
*codepointsfitted
;
4985 REAL rel_width
, rel_height
;
4988 static GpStatus
measure_string_callback(HDC hdc
,
4989 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4990 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4991 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4992 INT underlined_index_count
, void *user_data
)
4994 struct measure_string_args
*args
= user_data
;
4995 REAL new_width
, new_height
;
4997 new_width
= bounds
->Width
/ args
->rel_width
;
4998 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
5000 if (new_width
> args
->bounds
->Width
)
5001 args
->bounds
->Width
= new_width
;
5003 if (new_height
> args
->bounds
->Height
)
5004 args
->bounds
->Height
= new_height
;
5006 if (args
->codepointsfitted
)
5007 *args
->codepointsfitted
= index
+ length
;
5009 if (args
->linesfilled
)
5010 (*args
->linesfilled
)++;
5015 /* Find the smallest rectangle that bounds the text when it is printed in rect
5016 * according to the format options listed in format. If rect has 0 width and
5017 * height, then just find the smallest rectangle that bounds the text when it's
5018 * printed at location (rect->X, rect-Y). */
5019 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
5020 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5021 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
5022 INT
*codepointsfitted
, INT
*linesfilled
)
5024 HFONT oldfont
, gdifont
;
5025 struct measure_string_args args
;
5026 HDC temp_hdc
=NULL
, hdc
;
5030 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
5031 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
5032 bounds
, codepointsfitted
, linesfilled
);
5034 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
5035 return InvalidParameter
;
5039 hdc
= temp_hdc
= CreateCompatibleDC(0);
5040 if (!temp_hdc
) return OutOfMemory
;
5043 hdc
= graphics
->hdc
;
5045 if(linesfilled
) *linesfilled
= 0;
5046 if(codepointsfitted
) *codepointsfitted
= 0;
5049 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5057 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5058 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5059 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5060 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5061 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5063 get_font_hfont(graphics
, font
, &gdifont
);
5064 oldfont
= SelectObject(hdc
, gdifont
);
5066 scaled_rect
.X
= rect
->X
* args
.rel_width
;
5067 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
5068 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
5069 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
5071 bounds
->X
= rect
->X
;
5072 bounds
->Y
= rect
->Y
;
5073 bounds
->Width
= 0.0;
5074 bounds
->Height
= 0.0;
5076 args
.bounds
= bounds
;
5077 args
.codepointsfitted
= codepointsfitted
;
5078 args
.linesfilled
= linesfilled
;
5080 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
5081 measure_string_callback
, &args
);
5083 SelectObject(hdc
, oldfont
);
5084 DeleteObject(gdifont
);
5092 struct draw_string_args
{
5093 GpGraphics
*graphics
;
5094 GDIPCONST GpBrush
*brush
;
5095 REAL x
, y
, rel_width
, rel_height
, ascent
;
5098 static GpStatus
draw_string_callback(HDC hdc
,
5099 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5100 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5101 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5102 INT underlined_index_count
, void *user_data
)
5104 struct draw_string_args
*args
= user_data
;
5108 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5109 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5111 stat
= GdipDrawDriverString(args
->graphics
, &string
[index
], length
, font
,
5112 args
->brush
, &position
,
5113 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5115 if (stat
== Ok
&& underlined_index_count
)
5117 OUTLINETEXTMETRICW otm
;
5118 REAL underline_y
, underline_height
;
5121 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5123 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5124 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5126 for (i
=0; i
<underlined_index_count
; i
++)
5128 REAL start_x
, end_x
;
5130 INT ofs
= underlined_indexes
[i
] - index
;
5132 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5133 start_x
= text_size
.cx
/ args
->rel_width
;
5135 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5136 end_x
= text_size
.cx
/ args
->rel_width
;
5138 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5145 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5146 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5147 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5151 GpPointF pt
[3], rectcpy
[4];
5153 REAL rel_width
, rel_height
;
5156 struct draw_string_args args
;
5158 HDC hdc
, temp_hdc
=NULL
;
5159 TEXTMETRICW textmetric
;
5161 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5162 length
, font
, debugstr_rectf(rect
), format
, brush
);
5164 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5165 return InvalidParameter
;
5169 hdc
= graphics
->hdc
;
5173 hdc
= temp_hdc
= CreateCompatibleDC(0);
5177 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5179 /* Should be no need to explicitly test for StringAlignmentNear as
5180 * that is default behavior if no alignment is passed. */
5181 if(format
->vertalign
!= StringAlignmentNear
){
5182 RectF bounds
, in_rect
= *rect
;
5183 in_rect
.Height
= 0.0; /* avoid height clipping */
5184 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5186 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5188 if(format
->vertalign
== StringAlignmentCenter
)
5189 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5190 else if(format
->vertalign
== StringAlignmentFar
)
5191 offsety
= (rect
->Height
- bounds
.Height
);
5193 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
5196 save_state
= SaveDC(hdc
);
5204 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5205 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5206 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5207 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5208 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5210 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5211 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5212 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5213 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5214 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5216 scaled_rect
.X
= 0.0;
5217 scaled_rect
.Y
= 0.0;
5218 scaled_rect
.Width
= rel_width
* rect
->Width
;
5219 scaled_rect
.Height
= rel_height
* rect
->Height
;
5221 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
5223 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5224 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5225 SelectClipRgn(hdc
, rgn
);
5228 get_font_hfont(graphics
, font
, &gdifont
);
5229 SelectObject(hdc
, gdifont
);
5231 args
.graphics
= graphics
;
5235 args
.y
= rect
->Y
+ offsety
;
5237 args
.rel_width
= rel_width
;
5238 args
.rel_height
= rel_height
;
5240 GetTextMetricsW(hdc
, &textmetric
);
5241 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5243 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
5244 draw_string_callback
, &args
);
5247 DeleteObject(gdifont
);
5249 RestoreDC(hdc
, save_state
);
5256 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5258 TRACE("(%p)\n", graphics
);
5261 return InvalidParameter
;
5266 return GdipSetInfinite(graphics
->clip
);
5269 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5271 TRACE("(%p)\n", graphics
);
5274 return InvalidParameter
;
5279 graphics
->worldtrans
->matrix
[0] = 1.0;
5280 graphics
->worldtrans
->matrix
[1] = 0.0;
5281 graphics
->worldtrans
->matrix
[2] = 0.0;
5282 graphics
->worldtrans
->matrix
[3] = 1.0;
5283 graphics
->worldtrans
->matrix
[4] = 0.0;
5284 graphics
->worldtrans
->matrix
[5] = 0.0;
5289 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5291 return GdipEndContainer(graphics
, state
);
5294 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5295 GpMatrixOrder order
)
5297 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5300 return InvalidParameter
;
5305 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
5308 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5310 return GdipBeginContainer2(graphics
, state
);
5313 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5314 GraphicsContainer
*state
)
5316 GraphicsContainerItem
*container
;
5319 TRACE("(%p, %p)\n", graphics
, state
);
5321 if(!graphics
|| !state
)
5322 return InvalidParameter
;
5324 sts
= init_container(&container
, graphics
);
5328 list_add_head(&graphics
->containers
, &container
->entry
);
5329 *state
= graphics
->contid
= container
->contid
;
5334 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5336 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5337 return NotImplemented
;
5340 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5342 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5343 return NotImplemented
;
5346 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5348 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5349 return NotImplemented
;
5352 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5355 GraphicsContainerItem
*container
, *container2
;
5357 TRACE("(%p, %x)\n", graphics
, state
);
5360 return InvalidParameter
;
5362 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5363 if(container
->contid
== state
)
5367 /* did not find a matching container */
5368 if(&container
->entry
== &graphics
->containers
)
5371 sts
= restore_container(graphics
, container
);
5375 /* remove all of the containers on top of the found container */
5376 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5377 if(container
->contid
== state
)
5379 list_remove(&container
->entry
);
5380 delete_container(container
);
5383 list_remove(&container
->entry
);
5384 delete_container(container
);
5389 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5390 REAL sy
, GpMatrixOrder order
)
5392 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5395 return InvalidParameter
;
5400 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
5403 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5406 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5408 if(!graphics
|| !srcgraphics
)
5409 return InvalidParameter
;
5411 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5414 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5415 CompositingMode mode
)
5417 TRACE("(%p, %d)\n", graphics
, mode
);
5420 return InvalidParameter
;
5425 graphics
->compmode
= mode
;
5430 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5431 CompositingQuality quality
)
5433 TRACE("(%p, %d)\n", graphics
, quality
);
5436 return InvalidParameter
;
5441 graphics
->compqual
= quality
;
5446 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5447 InterpolationMode mode
)
5449 TRACE("(%p, %d)\n", graphics
, mode
);
5451 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5452 return InvalidParameter
;
5457 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5458 mode
= InterpolationModeBilinear
;
5460 if (mode
== InterpolationModeHighQuality
)
5461 mode
= InterpolationModeHighQualityBicubic
;
5463 graphics
->interpolation
= mode
;
5468 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5470 TRACE("(%p, %.2f)\n", graphics
, scale
);
5472 if(!graphics
|| (scale
<= 0.0))
5473 return InvalidParameter
;
5478 graphics
->scale
= scale
;
5483 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5485 TRACE("(%p, %d)\n", graphics
, unit
);
5488 return InvalidParameter
;
5493 if(unit
== UnitWorld
)
5494 return InvalidParameter
;
5496 graphics
->unit
= unit
;
5501 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5504 TRACE("(%p, %d)\n", graphics
, mode
);
5507 return InvalidParameter
;
5512 graphics
->pixeloffset
= mode
;
5517 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5521 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5524 FIXME("value is unused in rendering\n");
5527 return InvalidParameter
;
5529 graphics
->origin_x
= x
;
5530 graphics
->origin_y
= y
;
5535 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5537 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5539 if (!graphics
|| !x
|| !y
)
5540 return InvalidParameter
;
5542 *x
= graphics
->origin_x
;
5543 *y
= graphics
->origin_y
;
5548 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5550 TRACE("(%p, %d)\n", graphics
, mode
);
5553 return InvalidParameter
;
5558 graphics
->smoothing
= mode
;
5563 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5565 TRACE("(%p, %d)\n", graphics
, contrast
);
5568 return InvalidParameter
;
5570 graphics
->textcontrast
= contrast
;
5575 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5576 TextRenderingHint hint
)
5578 TRACE("(%p, %d)\n", graphics
, hint
);
5580 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5581 return InvalidParameter
;
5586 graphics
->texthint
= hint
;
5591 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5593 TRACE("(%p, %p)\n", graphics
, matrix
);
5595 if(!graphics
|| !matrix
)
5596 return InvalidParameter
;
5601 GdipDeleteMatrix(graphics
->worldtrans
);
5602 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
5605 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5606 REAL dy
, GpMatrixOrder order
)
5608 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5611 return InvalidParameter
;
5616 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
5619 /*****************************************************************************
5620 * GdipSetClipHrgn [GDIPLUS.@]
5622 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5627 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5630 return InvalidParameter
;
5632 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5636 status
= GdipSetClipRegion(graphics
, region
, mode
);
5638 GdipDeleteRegion(region
);
5642 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5644 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5647 return InvalidParameter
;
5652 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5655 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5656 REAL width
, REAL height
,
5661 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5664 return InvalidParameter
;
5672 rect
.Height
= height
;
5674 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5677 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5678 INT width
, INT height
,
5681 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5684 return InvalidParameter
;
5689 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5692 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5695 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5697 if(!graphics
|| !region
)
5698 return InvalidParameter
;
5703 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5706 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5711 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5714 FIXME("not implemented\n");
5716 return NotImplemented
;
5719 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5725 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5727 if(!graphics
|| !pen
|| count
<=0)
5728 return InvalidParameter
;
5735 FIXME("graphics object has no HDC\n");
5739 pti
= GdipAlloc(sizeof(POINT
) * count
);
5741 save_state
= prepare_dc(graphics
, pen
);
5742 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5744 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5745 Polygon(graphics
->hdc
, pti
, count
);
5747 restore_dc(graphics
, save_state
);
5753 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5760 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5762 if(count
<=0) return InvalidParameter
;
5763 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5765 for(i
= 0;i
< count
; i
++){
5766 ptf
[i
].X
= (REAL
)points
[i
].X
;
5767 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5770 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5776 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5778 TRACE("(%p, %p)\n", graphics
, dpi
);
5780 if(!graphics
|| !dpi
)
5781 return InvalidParameter
;
5786 *dpi
= graphics
->xres
;
5790 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5792 TRACE("(%p, %p)\n", graphics
, dpi
);
5794 if(!graphics
|| !dpi
)
5795 return InvalidParameter
;
5800 *dpi
= graphics
->yres
;
5804 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5805 GpMatrixOrder order
)
5810 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5812 if(!graphics
|| !matrix
)
5813 return InvalidParameter
;
5818 m
= *(graphics
->worldtrans
);
5820 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5822 *(graphics
->worldtrans
) = m
;
5827 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5828 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5830 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5834 TRACE("(%p, %p)\n", graphics
, hdc
);
5836 if(!graphics
|| !hdc
)
5837 return InvalidParameter
;
5842 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5844 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5846 else if (!graphics
->hdc
||
5847 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5849 /* Create a fake HDC and fill it with a constant color. */
5853 BITMAPINFOHEADER bmih
;
5856 stat
= get_graphics_bounds(graphics
, &bounds
);
5860 graphics
->temp_hbitmap_width
= bounds
.Width
;
5861 graphics
->temp_hbitmap_height
= bounds
.Height
;
5863 bmih
.biSize
= sizeof(bmih
);
5864 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5865 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5867 bmih
.biBitCount
= 32;
5868 bmih
.biCompression
= BI_RGB
;
5869 bmih
.biSizeImage
= 0;
5870 bmih
.biXPelsPerMeter
= 0;
5871 bmih
.biYPelsPerMeter
= 0;
5873 bmih
.biClrImportant
= 0;
5875 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5876 (void**)&graphics
->temp_bits
, NULL
, 0);
5878 return GenericError
;
5880 temp_hdc
= CreateCompatibleDC(0);
5883 DeleteObject(hbitmap
);
5884 return GenericError
;
5887 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5888 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5890 SelectObject(temp_hdc
, hbitmap
);
5892 graphics
->temp_hbitmap
= hbitmap
;
5893 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5897 *hdc
= graphics
->hdc
;
5901 graphics
->busy
= TRUE
;
5906 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5910 TRACE("(%p, %p)\n", graphics
, hdc
);
5912 if(!graphics
|| !hdc
|| !graphics
->busy
)
5913 return InvalidParameter
;
5915 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5917 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5919 else if (graphics
->temp_hdc
== hdc
)
5924 /* Find the pixels that have changed, and mark them as opaque. */
5925 pos
= (DWORD
*)graphics
->temp_bits
;
5926 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5928 if (*pos
!= DC_BACKGROUND_KEY
)
5935 /* Write the changed pixels to the real target. */
5936 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5937 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5938 graphics
->temp_hbitmap_width
* 4);
5941 DeleteDC(graphics
->temp_hdc
);
5942 DeleteObject(graphics
->temp_hbitmap
);
5943 graphics
->temp_hdc
= NULL
;
5944 graphics
->temp_hbitmap
= NULL
;
5946 else if (hdc
!= graphics
->hdc
)
5948 stat
= InvalidParameter
;
5952 graphics
->busy
= FALSE
;
5957 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5962 TRACE("(%p, %p)\n", graphics
, region
);
5964 if(!graphics
|| !region
)
5965 return InvalidParameter
;
5970 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5973 /* free everything except root node and header */
5974 delete_element(®ion
->node
);
5975 memcpy(region
, clip
, sizeof(GpRegion
));
5981 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5982 GpCoordinateSpace src_space
, GpMatrix
**matrix
)
5984 GpStatus stat
= GdipCreateMatrix(matrix
);
5985 REAL scale_x
, scale_y
;
5987 if (dst_space
!= src_space
&& stat
== Ok
)
5989 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5990 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5992 if(graphics
->unit
!= UnitDisplay
)
5994 scale_x
*= graphics
->scale
;
5995 scale_y
*= graphics
->scale
;
5998 /* transform from src_space to CoordinateSpacePage */
6001 case CoordinateSpaceWorld
:
6002 GdipMultiplyMatrix(*matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
6004 case CoordinateSpacePage
:
6006 case CoordinateSpaceDevice
:
6007 GdipScaleMatrix(*matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
6011 /* transform from CoordinateSpacePage to dst_space */
6014 case CoordinateSpaceWorld
:
6016 GpMatrix
*inverted_transform
;
6017 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
6020 stat
= GdipInvertMatrix(inverted_transform
);
6022 GdipMultiplyMatrix(*matrix
, inverted_transform
, MatrixOrderAppend
);
6023 GdipDeleteMatrix(inverted_transform
);
6027 case CoordinateSpacePage
:
6029 case CoordinateSpaceDevice
:
6030 GdipScaleMatrix(*matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
6037 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6038 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6043 if(!graphics
|| !points
|| count
<= 0)
6044 return InvalidParameter
;
6049 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6051 if (src_space
== dst_space
) return Ok
;
6053 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6057 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
6059 GdipDeleteMatrix(matrix
);
6065 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6066 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6072 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6075 return InvalidParameter
;
6077 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
6081 for(i
= 0; i
< count
; i
++){
6082 pointsF
[i
].X
= (REAL
)points
[i
].X
;
6083 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
6086 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6089 for(i
= 0; i
< count
; i
++){
6090 points
[i
].X
= roundr(pointsF
[i
].X
);
6091 points
[i
].Y
= roundr(pointsF
[i
].Y
);
6098 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6110 /*****************************************************************************
6111 * GdipTranslateClip [GDIPLUS.@]
6113 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6115 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6118 return InvalidParameter
;
6123 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6126 /*****************************************************************************
6127 * GdipTranslateClipI [GDIPLUS.@]
6129 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6131 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6134 return InvalidParameter
;
6139 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6143 /*****************************************************************************
6144 * GdipMeasureDriverString [GDIPLUS.@]
6146 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6147 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6148 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6150 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6153 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6155 TEXTMETRICW textmetric
;
6156 const WORD
*glyph_indices
;
6157 WORD
*dynamic_glyph_indices
=NULL
;
6158 REAL rel_width
, rel_height
, ascent
, descent
;
6161 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6163 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6164 return InvalidParameter
;
6167 length
= strlenW(text
);
6171 boundingBox
->X
= 0.0;
6172 boundingBox
->Y
= 0.0;
6173 boundingBox
->Width
= 0.0;
6174 boundingBox
->Height
= 0.0;
6177 if (flags
& unsupported_flags
)
6178 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6181 FIXME("Ignoring matrix\n");
6183 get_font_hfont(graphics
, font
, &hfont
);
6185 hdc
= CreateCompatibleDC(0);
6186 SelectObject(hdc
, hfont
);
6188 GetTextMetricsW(hdc
, &textmetric
);
6196 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6197 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6198 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6199 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6200 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6202 if (flags
& DriverStringOptionsCmapLookup
)
6204 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6208 DeleteObject(hfont
);
6212 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6215 glyph_indices
= text
;
6217 min_x
= max_x
= x
= positions
[0].X
;
6218 min_y
= max_y
= y
= positions
[0].Y
;
6220 ascent
= textmetric
.tmAscent
/ rel_height
;
6221 descent
= textmetric
.tmDescent
/ rel_height
;
6223 for (i
=0; i
<length
; i
++)
6228 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6234 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6235 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcB
;
6237 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6238 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6239 if (min_x
> x
) min_x
= x
;
6241 x
+= char_width
/ rel_width
;
6243 if (max_x
< x
) max_x
= x
;
6246 GdipFree(dynamic_glyph_indices
);
6248 DeleteObject(hfont
);
6250 boundingBox
->X
= min_x
;
6251 boundingBox
->Y
= min_y
;
6252 boundingBox
->Width
= max_x
- min_x
;
6253 boundingBox
->Height
= max_y
- min_y
;
6258 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6259 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6260 GDIPCONST PointF
*positions
, INT flags
,
6261 GDIPCONST GpMatrix
*matrix
)
6263 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6269 if (flags
& unsupported_flags
)
6270 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6273 FIXME("Ignoring matrix\n");
6275 if (!(flags
& DriverStringOptionsCmapLookup
))
6276 eto_flags
|= ETO_GLYPH_INDEX
;
6278 save_state
= SaveDC(graphics
->hdc
);
6279 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6280 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6283 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6285 get_font_hfont(graphics
, font
, &hfont
);
6286 SelectObject(graphics
->hdc
, hfont
);
6288 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6290 ExtTextOutW(graphics
->hdc
, roundr(pt
.X
), roundr(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6292 RestoreDC(graphics
->hdc
, save_state
);
6294 DeleteObject(hfont
);
6299 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6300 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6301 GDIPCONST PointF
*positions
, INT flags
,
6302 GDIPCONST GpMatrix
*matrix
)
6304 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6306 PointF
*real_positions
, real_position
;
6310 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6311 DWORD max_glyphsize
=0;
6312 GLYPHMETRICS glyphmetrics
;
6313 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6316 int text_mask_stride
;
6318 int pixel_data_stride
;
6320 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6325 if (!(flags
& DriverStringOptionsCmapLookup
))
6326 ggo_flags
|= GGO_GLYPH_INDEX
;
6328 if (flags
& unsupported_flags
)
6329 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6332 FIXME("Ignoring matrix\n");
6334 pti
= GdipAlloc(sizeof(POINT
) * length
);
6338 if (flags
& DriverStringOptionsRealizedAdvance
)
6340 real_position
= positions
[0];
6342 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6346 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6347 if (!real_positions
)
6353 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6355 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6357 GdipFree(real_positions
);
6360 get_font_hfont(graphics
, font
, &hfont
);
6362 hdc
= CreateCompatibleDC(0);
6363 SelectObject(hdc
, hfont
);
6365 /* Get the boundaries of the text to be drawn */
6366 for (i
=0; i
<length
; i
++)
6369 int left
, top
, right
, bottom
;
6371 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6372 &glyphmetrics
, 0, NULL
, &identity
);
6374 if (glyphsize
== GDI_ERROR
)
6376 ERR("GetGlyphOutlineW failed\n");
6379 DeleteObject(hfont
);
6380 return GenericError
;
6383 if (glyphsize
> max_glyphsize
)
6384 max_glyphsize
= glyphsize
;
6386 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6387 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6388 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6389 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6391 if (left
< min_x
) min_x
= left
;
6392 if (top
< min_y
) min_y
= top
;
6393 if (right
> max_x
) max_x
= right
;
6394 if (bottom
> max_y
) max_y
= bottom
;
6396 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6398 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6399 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6403 glyph_mask
= GdipAlloc(max_glyphsize
);
6404 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6405 text_mask_stride
= max_x
- min_x
;
6407 if (!(glyph_mask
&& text_mask
))
6409 GdipFree(glyph_mask
);
6410 GdipFree(text_mask
);
6413 DeleteObject(hfont
);
6417 /* Generate a mask for the text */
6418 for (i
=0; i
<length
; i
++)
6420 int left
, top
, stride
;
6422 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6423 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6425 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6426 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6427 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6429 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6431 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6432 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6433 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6435 *text_val
= min(64, *text_val
+ *glyph_val
);
6444 DeleteObject(hfont
);
6445 GdipFree(glyph_mask
);
6447 /* get the brush data */
6448 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6451 GdipFree(text_mask
);
6455 pixel_area
.X
= min_x
;
6456 pixel_area
.Y
= min_y
;
6457 pixel_area
.Width
= max_x
- min_x
;
6458 pixel_area
.Height
= max_y
- min_y
;
6459 pixel_data_stride
= pixel_area
.Width
* 4;
6461 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6464 GdipFree(text_mask
);
6465 GdipFree(pixel_data
);
6469 /* multiply the brush data by the mask */
6470 for (y
=0; y
<pixel_area
.Height
; y
++)
6472 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6473 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6474 for (x
=0; x
<pixel_area
.Width
; x
++)
6476 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6482 GdipFree(text_mask
);
6484 /* draw the result */
6485 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6486 pixel_area
.Height
, pixel_data_stride
);
6488 GdipFree(pixel_data
);
6493 /*****************************************************************************
6494 * GdipDrawDriverString [GDIPLUS.@]
6496 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6497 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6498 GDIPCONST PointF
*positions
, INT flags
,
6499 GDIPCONST GpMatrix
*matrix
)
6501 GpStatus stat
=NotImplemented
;
6503 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6505 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6506 return InvalidParameter
;
6509 length
= strlenW(text
);
6511 if (graphics
->hdc
&&
6512 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6513 brush
->bt
== BrushTypeSolidColor
&&
6514 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6515 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
6516 positions
, flags
, matrix
);
6518 if (stat
== NotImplemented
)
6519 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, brush
,
6520 positions
, flags
, matrix
);
6525 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6526 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6528 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6529 return NotImplemented
;
6532 /*****************************************************************************
6533 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6535 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6540 TRACE("(%p, %p)\n", graphics
, res
);
6542 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6545 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6548 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6551 GdipDeleteRegion(rgn
);
6555 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6559 TRACE("(%p) stub\n", graphics
);
6562 FIXME("not implemented\n");
6564 return NotImplemented
;