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 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
50 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
51 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
52 INT flags
, GDIPCONST GpMatrix
*matrix
);
54 /* Converts angle (in degrees) to x/y coordinates */
55 static void deg2xy(REAL angle
, REAL x_0
, REAL y_0
, REAL
*x
, REAL
*y
)
57 REAL radAngle
, hypotenuse
;
59 radAngle
= deg2rad(angle
);
60 hypotenuse
= 50.0; /* arbitrary */
62 *x
= x_0
+ cos(radAngle
) * hypotenuse
;
63 *y
= y_0
+ sin(radAngle
) * hypotenuse
;
66 /* Converts from gdiplus path point type to gdi path point type. */
67 static BYTE
convert_path_point_type(BYTE type
)
71 switch(type
& PathPointTypePathTypeMask
){
72 case PathPointTypeBezier
:
75 case PathPointTypeLine
:
78 case PathPointTypeStart
:
82 ERR("Bad point type\n");
86 if(type
& PathPointTypeCloseSubpath
)
87 ret
|= PT_CLOSEFIGURE
;
92 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
98 case BrushTypeSolidColor
:
100 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
104 case BrushTypeHatchFill
:
106 const GpHatch
*hatch
= (const GpHatch
*)brush
;
107 argb
= hatch
->forecol
;
110 case BrushTypeLinearGradient
:
112 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
113 argb
= line
->startcolor
;
116 case BrushTypePathGradient
:
118 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
119 argb
= grad
->centercolor
;
123 FIXME("unhandled brush type %d\n", brush
->bt
);
127 return ARGB2COLORREF(argb
);
130 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
133 BITMAPINFOHEADER bmih
;
137 bmih
.biSize
= sizeof(bmih
);
141 bmih
.biBitCount
= 32;
142 bmih
.biCompression
= BI_RGB
;
143 bmih
.biSizeImage
= 0;
145 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
148 const char *hatch_data
;
150 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
152 for (y
= 0; y
< 8; y
++)
154 for (x
= 0; x
< 8; x
++)
156 if (hatch_data
[y
] & (0x80 >> x
))
157 bits
[y
* 8 + x
] = hatch
->forecol
;
159 bits
[y
* 8 + x
] = hatch
->backcol
;
165 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
167 for (y
= 0; y
< 64; y
++)
168 bits
[y
] = hatch
->forecol
;
175 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
179 case BrushTypeSolidColor
:
181 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
182 lb
->lbStyle
= BS_SOLID
;
183 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
188 case BrushTypeHatchFill
:
190 const GpHatch
*hatch
= (const GpHatch
*)brush
;
193 hbmp
= create_hatch_bitmap(hatch
);
194 if (!hbmp
) return OutOfMemory
;
196 lb
->lbStyle
= BS_PATTERN
;
198 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
203 FIXME("unhandled brush type %d\n", brush
->bt
);
204 lb
->lbStyle
= BS_SOLID
;
205 lb
->lbColor
= get_gdi_brush_color(brush
);
211 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
216 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
222 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
227 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
229 gdibrush
= CreateBrushIndirect(&lb
);
230 free_gdi_logbrush(&lb
);
235 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
240 INT save_state
, i
, numdashes
;
242 DWORD dash_array
[MAX_DASHLEN
];
244 save_state
= SaveDC(graphics
->hdc
);
246 EndPath(graphics
->hdc
);
248 if(pen
->unit
== UnitPixel
){
252 /* Get an estimate for the amount the pen width is affected by the world
253 * transform. (This is similar to what some of the wine drivers do.) */
258 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
259 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
260 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
262 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
265 if(pen
->dash
== DashStyleCustom
){
266 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
268 TRACE("dashes are: ");
269 for(i
= 0; i
< numdashes
; i
++){
270 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
271 TRACE("%d, ", dash_array
[i
]);
273 TRACE("\n and the pen style is %x\n", pen
->style
);
275 create_gdi_logbrush(pen
->brush
, &lb
);
276 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
277 numdashes
, dash_array
);
278 free_gdi_logbrush(&lb
);
282 create_gdi_logbrush(pen
->brush
, &lb
);
283 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
284 free_gdi_logbrush(&lb
);
287 SelectObject(graphics
->hdc
, gdipen
);
292 static void restore_dc(GpGraphics
*graphics
, INT state
)
294 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
295 RestoreDC(graphics
->hdc
, state
);
298 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
299 GpCoordinateSpace src_space
, GpMatrix
*matrix
);
301 /* This helper applies all the changes that the points listed in ptf need in
302 * order to be drawn on the device context. In the end, this should include at
304 * -scaling by page unit
305 * -applying world transformation
306 * -converting from float to int
307 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
308 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
309 * gdi to draw, and these functions would irreparably mess with line widths.
311 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
312 GpPointF
*ptf
, INT count
)
314 REAL scale_x
, scale_y
;
318 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
319 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
321 /* apply page scale */
322 if(graphics
->unit
!= UnitDisplay
)
324 scale_x
*= graphics
->scale
;
325 scale_y
*= graphics
->scale
;
328 matrix
= graphics
->worldtrans
;
329 GdipScaleMatrix(&matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
330 GdipTransformMatrixPoints(&matrix
, ptf
, count
);
332 for(i
= 0; i
< count
; i
++){
333 pti
[i
].x
= gdip_round(ptf
[i
].X
);
334 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
338 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
339 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
341 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
343 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
345 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
346 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
352 bf
.BlendOp
= AC_SRC_OVER
;
354 bf
.SourceConstantAlpha
= 255;
355 bf
.AlphaFormat
= AC_SRC_ALPHA
;
357 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
358 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
362 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
364 return GdipGetRegionHRgn(graphics
->clip
, graphics
, hrgn
);
367 /* Draw non-premultiplied ARGB data to the given graphics object */
368 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
369 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
371 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
374 for (x
=0; x
<src_width
; x
++)
376 for (y
=0; y
<src_height
; y
++)
378 ARGB dst_color
, src_color
;
379 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
380 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
381 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
388 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
389 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
393 BITMAPINFOHEADER bih
;
396 hdc
= CreateCompatibleDC(0);
398 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
399 bih
.biWidth
= src_width
;
400 bih
.biHeight
= -src_height
;
403 bih
.biCompression
= BI_RGB
;
405 bih
.biXPelsPerMeter
= 0;
406 bih
.biYPelsPerMeter
= 0;
408 bih
.biClrImportant
= 0;
410 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
411 (void**)&temp_bits
, NULL
, 0);
413 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
414 4 * src_width
, src
, src_stride
);
416 SelectObject(hdc
, hbitmap
);
417 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
418 hdc
, 0, 0, src_width
, src_height
);
420 DeleteObject(hbitmap
);
425 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
426 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
)
430 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
436 HRGN hrgn
, visible_rgn
;
438 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
442 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
451 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
452 DeleteObject(visible_rgn
);
456 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
458 size
= GetRegionData(hrgn
, 0, NULL
);
460 rgndata
= GdipAlloc(size
);
467 GetRegionData(hrgn
, size
, rgndata
);
469 rects
= (RECT
*)rgndata
->Buffer
;
471 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
473 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
474 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
475 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
485 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
487 ERR("This should not be used for metafiles; fix caller\n");
488 return NotImplemented
;
495 stat
= get_clip_hrgn(graphics
, &hrgn
);
500 save
= SaveDC(graphics
->hdc
);
503 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
506 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
508 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
509 src_height
, src_stride
);
511 RestoreDC(graphics
->hdc
, save
);
519 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
520 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
522 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
);
525 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
531 a1
= (start
>> 24) & 0xff;
532 a2
= (end
>> 24) & 0xff;
534 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
538 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
539 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
543 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
547 /* clamp to between 0.0 and 1.0, using the wrap mode */
548 if (brush
->wrap
== WrapModeTile
)
550 position
= fmodf(position
, 1.0f
);
551 if (position
< 0.0f
) position
+= 1.0f
;
553 else /* WrapModeFlip* */
555 position
= fmodf(position
, 2.0f
);
556 if (position
< 0.0f
) position
+= 2.0f
;
557 if (position
> 1.0f
) position
= 2.0f
- position
;
560 if (brush
->blendcount
== 1)
565 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
568 /* locate the blend positions surrounding this position */
569 while (position
> brush
->blendpos
[i
])
572 /* interpolate between the blend positions */
573 left_blendpos
= brush
->blendpos
[i
-1];
574 left_blendfac
= brush
->blendfac
[i
-1];
575 right_blendpos
= brush
->blendpos
[i
];
576 right_blendfac
= brush
->blendfac
[i
];
577 range
= right_blendpos
- left_blendpos
;
578 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
579 right_blendfac
* (position
- left_blendpos
)) / range
;
582 if (brush
->pblendcount
== 0)
583 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
587 ARGB left_blendcolor
, right_blendcolor
;
588 REAL left_blendpos
, right_blendpos
;
590 /* locate the blend colors surrounding this position */
591 while (blendfac
> brush
->pblendpos
[i
])
594 /* interpolate between the blend colors */
595 left_blendpos
= brush
->pblendpos
[i
-1];
596 left_blendcolor
= brush
->pblendcolor
[i
-1];
597 right_blendpos
= brush
->pblendpos
[i
];
598 right_blendcolor
= brush
->pblendcolor
[i
];
599 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
600 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
604 static ARGB
transform_color(ARGB color
, const ColorMatrix
*matrix
)
608 unsigned char a
, r
, g
, b
;
610 val
[0] = ((color
>> 16) & 0xff) / 255.0; /* red */
611 val
[1] = ((color
>> 8) & 0xff) / 255.0; /* green */
612 val
[2] = (color
& 0xff) / 255.0; /* blue */
613 val
[3] = ((color
>> 24) & 0xff) / 255.0; /* alpha */
614 val
[4] = 1.0; /* translation */
621 res
[i
] += matrix
->m
[j
][i
] * val
[j
];
624 a
= min(max(floorf(res
[3]*255.0), 0.0), 255.0);
625 r
= min(max(floorf(res
[0]*255.0), 0.0), 255.0);
626 g
= min(max(floorf(res
[1]*255.0), 0.0), 255.0);
627 b
= min(max(floorf(res
[2]*255.0), 0.0), 255.0);
629 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
632 static int color_is_gray(ARGB color
)
634 unsigned char r
, g
, b
;
636 r
= (color
>> 16) & 0xff;
637 g
= (color
>> 8) & 0xff;
640 return (r
== g
) && (g
== b
);
643 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
644 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
649 if (attributes
->colorkeys
[type
].enabled
||
650 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
652 const struct color_key
*key
;
653 BYTE min_blue
, min_green
, min_red
;
654 BYTE max_blue
, max_green
, max_red
;
656 if (attributes
->colorkeys
[type
].enabled
)
657 key
= &attributes
->colorkeys
[type
];
659 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
661 min_blue
= key
->low
&0xff;
662 min_green
= (key
->low
>>8)&0xff;
663 min_red
= (key
->low
>>16)&0xff;
665 max_blue
= key
->high
&0xff;
666 max_green
= (key
->high
>>8)&0xff;
667 max_red
= (key
->high
>>16)&0xff;
669 for (x
=0; x
<width
; x
++)
670 for (y
=0; y
<height
; y
++)
673 BYTE blue
, green
, red
;
674 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
675 blue
= *src_color
&0xff;
676 green
= (*src_color
>>8)&0xff;
677 red
= (*src_color
>>16)&0xff;
678 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
679 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
680 *src_color
= 0x00000000;
684 if (attributes
->colorremaptables
[type
].enabled
||
685 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
687 const struct color_remap_table
*table
;
689 if (attributes
->colorremaptables
[type
].enabled
)
690 table
= &attributes
->colorremaptables
[type
];
692 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
694 for (x
=0; x
<width
; x
++)
695 for (y
=0; y
<height
; y
++)
698 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
699 for (i
=0; i
<table
->mapsize
; i
++)
701 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
703 *src_color
= table
->colormap
[i
].newColor
.Argb
;
710 if (attributes
->colormatrices
[type
].enabled
||
711 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
713 const struct color_matrix
*colormatrices
;
715 if (attributes
->colormatrices
[type
].enabled
)
716 colormatrices
= &attributes
->colormatrices
[type
];
718 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
720 for (x
=0; x
<width
; x
++)
721 for (y
=0; y
<height
; y
++)
724 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
726 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
727 !color_is_gray(*src_color
))
729 *src_color
= transform_color(*src_color
, &colormatrices
->colormatrix
);
731 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
733 *src_color
= transform_color(*src_color
, &colormatrices
->graymatrix
);
738 if (attributes
->gamma_enabled
[type
] ||
739 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
743 if (attributes
->gamma_enabled
[type
])
744 gamma
= attributes
->gamma
[type
];
746 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
748 for (x
=0; x
<width
; x
++)
749 for (y
=0; y
<height
; y
++)
752 BYTE blue
, green
, red
;
753 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
755 blue
= *src_color
&0xff;
756 green
= (*src_color
>>8)&0xff;
757 red
= (*src_color
>>16)&0xff;
759 /* FIXME: We should probably use a table for this. */
760 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
761 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
762 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
764 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
769 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
770 * bitmap that contains all the pixels we may need to draw it. */
771 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
772 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
775 INT left
, top
, right
, bottom
;
777 switch (interpolation
)
779 case InterpolationModeHighQualityBilinear
:
780 case InterpolationModeHighQualityBicubic
:
781 /* FIXME: Include a greater range for the prefilter? */
782 case InterpolationModeBicubic
:
783 case InterpolationModeBilinear
:
784 left
= (INT
)(floorf(srcx
));
785 top
= (INT
)(floorf(srcy
));
786 right
= (INT
)(ceilf(srcx
+srcwidth
));
787 bottom
= (INT
)(ceilf(srcy
+srcheight
));
789 case InterpolationModeNearestNeighbor
:
791 left
= gdip_round(srcx
);
792 top
= gdip_round(srcy
);
793 right
= gdip_round(srcx
+srcwidth
);
794 bottom
= gdip_round(srcy
+srcheight
);
798 if (wrap
== WrapModeClamp
)
804 if (right
>= bitmap
->width
)
805 right
= bitmap
->width
-1;
806 if (bottom
>= bitmap
->height
)
807 bottom
= bitmap
->height
-1;
811 /* In some cases we can make the rectangle smaller here, but the logic
812 * is hard to get right, and tiling suggests we're likely to use the
813 * entire source image. */
814 if (left
< 0 || right
>= bitmap
->width
)
817 right
= bitmap
->width
-1;
820 if (top
< 0 || bottom
>= bitmap
->height
)
823 bottom
= bitmap
->height
-1;
829 rect
->Width
= right
- left
+ 1;
830 rect
->Height
= bottom
- top
+ 1;
833 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
834 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
836 if (attributes
->wrap
== WrapModeClamp
)
838 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
839 return attributes
->outside_color
;
843 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
845 x
= width
*2 + x
% (width
* 2);
847 y
= height
*2 + y
% (height
* 2);
849 if ((attributes
->wrap
& 1) == 1)
852 if ((x
/ width
) % 2 == 0)
855 x
= width
- 1 - x
% width
;
860 if ((attributes
->wrap
& 2) == 2)
863 if ((y
/ height
) % 2 == 0)
866 y
= height
- 1 - y
% height
;
872 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
874 ERR("out of range pixel requested\n");
878 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
881 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
882 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
883 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
887 switch (interpolation
)
891 FIXME("Unimplemented interpolation %i\n", interpolation
);
893 case InterpolationModeBilinear
:
896 INT leftx
, rightx
, topy
, bottomy
;
897 ARGB topleft
, topright
, bottomleft
, bottomright
;
901 leftxf
= floorf(point
->X
);
903 rightx
= (INT
)ceilf(point
->X
);
904 topyf
= floorf(point
->Y
);
906 bottomy
= (INT
)ceilf(point
->Y
);
908 if (leftx
== rightx
&& topy
== bottomy
)
909 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
910 leftx
, topy
, attributes
);
912 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
913 leftx
, topy
, attributes
);
914 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
915 rightx
, topy
, attributes
);
916 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
917 leftx
, bottomy
, attributes
);
918 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
919 rightx
, bottomy
, attributes
);
921 x_offset
= point
->X
- leftxf
;
922 top
= blend_colors(topleft
, topright
, x_offset
);
923 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
925 return blend_colors(top
, bottom
, point
->Y
- topyf
);
927 case InterpolationModeNearestNeighbor
:
933 case PixelOffsetModeNone
:
934 case PixelOffsetModeHighSpeed
:
938 case PixelOffsetModeHalf
:
939 case PixelOffsetModeHighQuality
:
943 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
944 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
950 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
952 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
955 static INT
brush_can_fill_path(GpBrush
*brush
)
959 case BrushTypeSolidColor
:
961 case BrushTypeHatchFill
:
963 GpHatch
*hatch
= (GpHatch
*)brush
;
964 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
965 ((hatch
->backcol
& 0xff000000) == 0xff000000);
967 case BrushTypeLinearGradient
:
968 case BrushTypeTextureFill
:
969 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
975 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
979 case BrushTypeSolidColor
:
981 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
982 HBITMAP bmp
= ARGB2BMP(fill
->color
);
987 /* partially transparent fill */
989 SelectClipPath(graphics
->hdc
, RGN_AND
);
990 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
992 HDC hdc
= CreateCompatibleDC(NULL
);
996 SelectObject(hdc
, bmp
);
997 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1005 /* else fall through */
1009 HBRUSH gdibrush
, old_brush
;
1011 gdibrush
= create_gdi_brush(brush
);
1012 if (!gdibrush
) return;
1014 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1015 FillPath(graphics
->hdc
);
1016 SelectObject(graphics
->hdc
, old_brush
);
1017 DeleteObject(gdibrush
);
1023 static INT
brush_can_fill_pixels(GpBrush
*brush
)
1027 case BrushTypeSolidColor
:
1028 case BrushTypeHatchFill
:
1029 case BrushTypeLinearGradient
:
1030 case BrushTypeTextureFill
:
1031 case BrushTypePathGradient
:
1038 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1039 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1043 case BrushTypeSolidColor
:
1046 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1047 for (x
=0; x
<fill_area
->Width
; x
++)
1048 for (y
=0; y
<fill_area
->Height
; y
++)
1049 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1052 case BrushTypeHatchFill
:
1055 GpHatch
*fill
= (GpHatch
*)brush
;
1056 const char *hatch_data
;
1058 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1059 return NotImplemented
;
1061 for (x
=0; x
<fill_area
->Width
; x
++)
1062 for (y
=0; y
<fill_area
->Height
; y
++)
1066 /* FIXME: Account for the rendering origin */
1067 hx
= (x
+ fill_area
->X
) % 8;
1068 hy
= (y
+ fill_area
->Y
) % 8;
1070 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1071 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1073 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1078 case BrushTypeLinearGradient
:
1080 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1081 GpPointF draw_points
[3], line_points
[3];
1083 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1084 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1087 draw_points
[0].X
= fill_area
->X
;
1088 draw_points
[0].Y
= fill_area
->Y
;
1089 draw_points
[1].X
= fill_area
->X
+1;
1090 draw_points
[1].Y
= fill_area
->Y
;
1091 draw_points
[2].X
= fill_area
->X
;
1092 draw_points
[2].Y
= fill_area
->Y
+1;
1094 /* Transform the points to a co-ordinate space where X is the point's
1095 * position in the gradient, 0.0 being the start point and 1.0 the
1097 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1098 CoordinateSpaceDevice
, draw_points
, 3);
1102 line_points
[0] = fill
->startpoint
;
1103 line_points
[1] = fill
->endpoint
;
1104 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1105 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1107 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1112 stat
= GdipInvertMatrix(world_to_gradient
);
1115 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1117 GdipDeleteMatrix(world_to_gradient
);
1122 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1123 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1125 for (y
=0; y
<fill_area
->Height
; y
++)
1127 for (x
=0; x
<fill_area
->Width
; x
++)
1129 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1131 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1138 case BrushTypeTextureFill
:
1140 GpTexture
*fill
= (GpTexture
*)brush
;
1141 GpPointF draw_points
[3];
1148 if (fill
->image
->type
!= ImageTypeBitmap
)
1150 FIXME("metafile texture brushes not implemented\n");
1151 return NotImplemented
;
1154 bitmap
= (GpBitmap
*)fill
->image
;
1155 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1157 src_area
.X
= src_area
.Y
= 0;
1158 src_area
.Width
= bitmap
->width
;
1159 src_area
.Height
= bitmap
->height
;
1161 draw_points
[0].X
= fill_area
->X
;
1162 draw_points
[0].Y
= fill_area
->Y
;
1163 draw_points
[1].X
= fill_area
->X
+1;
1164 draw_points
[1].Y
= fill_area
->Y
;
1165 draw_points
[2].X
= fill_area
->X
;
1166 draw_points
[2].Y
= fill_area
->Y
+1;
1168 /* Transform the points to the co-ordinate space of the bitmap. */
1169 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1170 CoordinateSpaceDevice
, draw_points
, 3);
1174 GpMatrix world_to_texture
= fill
->transform
;
1176 stat
= GdipInvertMatrix(&world_to_texture
);
1178 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1181 if (stat
== Ok
&& !fill
->bitmap_bits
)
1183 BitmapData lockeddata
;
1185 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1186 if (!fill
->bitmap_bits
)
1191 lockeddata
.Width
= bitmap
->width
;
1192 lockeddata
.Height
= bitmap
->height
;
1193 lockeddata
.Stride
= src_stride
;
1194 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1195 lockeddata
.Scan0
= fill
->bitmap_bits
;
1197 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1198 PixelFormat32bppARGB
, &lockeddata
);
1202 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1205 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1206 bitmap
->width
, bitmap
->height
,
1207 src_stride
, ColorAdjustTypeBitmap
);
1211 GdipFree(fill
->bitmap_bits
);
1212 fill
->bitmap_bits
= NULL
;
1218 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1219 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1220 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1221 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1223 for (y
=0; y
<fill_area
->Height
; y
++)
1225 for (x
=0; x
<fill_area
->Width
; x
++)
1228 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1229 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1231 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1232 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1233 &point
, fill
->imageattributes
, graphics
->interpolation
,
1234 graphics
->pixeloffset
);
1241 case BrushTypePathGradient
:
1243 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1245 GpMatrix world_to_device
;
1247 int i
, figure_start
=0;
1248 GpPointF start_point
, end_point
, center_point
;
1250 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1251 INT min_y
, max_y
, min_x
, max_x
;
1254 static int transform_fixme_once
;
1256 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1260 FIXME("path gradient focus not implemented\n");
1267 FIXME("path gradient gamma correction not implemented\n");
1270 if (fill
->blendcount
)
1274 FIXME("path gradient blend not implemented\n");
1277 if (fill
->pblendcount
)
1281 FIXME("path gradient preset blend not implemented\n");
1284 if (!transform_fixme_once
)
1286 BOOL is_identity
=TRUE
;
1287 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1290 FIXME("path gradient transform not implemented\n");
1291 transform_fixme_once
= 1;
1295 stat
= GdipClonePath(fill
->path
, &flat_path
);
1300 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1301 CoordinateSpaceWorld
, &world_to_device
);
1304 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1308 center_point
= fill
->center
;
1309 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1313 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1318 GdipDeletePath(flat_path
);
1322 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1324 int start_center_line
=0, end_center_line
=0;
1325 int seen_start
=0, seen_end
=0, seen_center
=0;
1326 REAL center_distance
;
1327 ARGB start_color
, end_color
;
1330 type
= flat_path
->pathdata
.Types
[i
];
1332 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1335 start_point
= flat_path
->pathdata
.Points
[i
];
1337 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1339 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1341 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1342 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1344 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1346 end_point
= flat_path
->pathdata
.Points
[i
+1];
1347 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1352 outer_color
= start_color
;
1354 min_yf
= center_point
.Y
;
1355 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1356 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1358 if (min_yf
< fill_area
->Y
)
1359 min_y
= fill_area
->Y
;
1361 min_y
= (INT
)ceil(min_yf
);
1363 max_yf
= center_point
.Y
;
1364 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1365 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1367 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1368 max_y
= fill_area
->Y
+ fill_area
->Height
;
1370 max_y
= (INT
)ceil(max_yf
);
1372 dy
= end_point
.Y
- start_point
.Y
;
1373 dx
= end_point
.X
- start_point
.X
;
1375 /* This is proportional to the distance from start-end line to center point. */
1376 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1377 dx
* (center_point
.Y
- start_point
.Y
);
1379 for (y
=min_y
; y
<max_y
; y
++)
1383 if (!seen_start
&& yf
>= start_point
.Y
)
1386 start_center_line
^= 1;
1388 if (!seen_end
&& yf
>= end_point
.Y
)
1391 end_center_line
^= 1;
1393 if (!seen_center
&& yf
>= center_point
.Y
)
1396 start_center_line
^= 1;
1397 end_center_line
^= 1;
1400 if (start_center_line
)
1401 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1403 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1405 if (end_center_line
)
1406 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1408 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1410 if (line1_xf
< line2_xf
)
1412 min_x
= (INT
)ceil(line1_xf
);
1413 max_x
= (INT
)ceil(line2_xf
);
1417 min_x
= (INT
)ceil(line2_xf
);
1418 max_x
= (INT
)ceil(line1_xf
);
1421 if (min_x
< fill_area
->X
)
1422 min_x
= fill_area
->X
;
1423 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1424 max_x
= fill_area
->X
+ fill_area
->Width
;
1426 for (x
=min_x
; x
<max_x
; x
++)
1431 if (start_color
!= end_color
)
1433 REAL blend_amount
, pdy
, pdx
;
1434 pdy
= yf
- center_point
.Y
;
1435 pdx
= xf
- center_point
.X
;
1436 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1437 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1440 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1441 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1443 distance
= distance
/ center_distance
;
1445 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1446 blend_colors(outer_color
, fill
->centercolor
, distance
);
1451 GdipDeletePath(flat_path
);
1455 return NotImplemented
;
1459 /* GdipDrawPie/GdipFillPie helper function */
1460 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
1461 REAL height
, REAL startAngle
, REAL sweepAngle
)
1468 ptf
[1].X
= x
+ width
;
1469 ptf
[1].Y
= y
+ height
;
1471 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
1472 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
1474 transform_and_round_points(graphics
, pti
, ptf
, 4);
1476 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
1477 pti
[2].y
, pti
[3].x
, pti
[3].y
);
1480 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1481 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1482 * should not be called on an hdc that has a path you care about. */
1483 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1484 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1486 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1488 HBRUSH brush
= NULL
;
1490 PointF ptf
[4], *custptf
= NULL
;
1491 POINT pt
[4], *custpt
= NULL
;
1493 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1498 if((x1
== x2
) && (y1
== y2
))
1501 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1503 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1505 brush
= CreateSolidBrush(color
);
1506 lb
.lbStyle
= BS_SOLID
;
1509 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1510 PS_JOIN_MITER
, 1, &lb
, 0,
1512 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1513 oldpen
= SelectObject(graphics
->hdc
, pen
);
1520 case LineCapSquareAnchor
:
1521 case LineCapDiamondAnchor
:
1522 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1523 if(cap
== LineCapDiamondAnchor
){
1524 dsmall
= cos(theta
+ M_PI_2
) * size
;
1525 dbig
= sin(theta
+ M_PI_2
) * size
;
1528 dsmall
= cos(theta
+ M_PI_4
) * size
;
1529 dbig
= sin(theta
+ M_PI_4
) * size
;
1532 ptf
[0].X
= x2
- dsmall
;
1533 ptf
[1].X
= x2
+ dbig
;
1535 ptf
[0].Y
= y2
- dbig
;
1536 ptf
[3].Y
= y2
+ dsmall
;
1538 ptf
[1].Y
= y2
- dsmall
;
1539 ptf
[2].Y
= y2
+ dbig
;
1541 ptf
[3].X
= x2
- dbig
;
1542 ptf
[2].X
= x2
+ dsmall
;
1544 transform_and_round_points(graphics
, pt
, ptf
, 4);
1545 Polygon(graphics
->hdc
, pt
, 4);
1548 case LineCapArrowAnchor
:
1549 size
= size
* 4.0 / sqrt(3.0);
1551 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1552 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1557 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1558 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1566 transform_and_round_points(graphics
, pt
, ptf
, 3);
1567 Polygon(graphics
->hdc
, pt
, 3);
1570 case LineCapRoundAnchor
:
1571 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1578 transform_and_round_points(graphics
, pt
, ptf
, 2);
1579 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1582 case LineCapTriangle
:
1584 dx
= cos(M_PI_2
+ theta
) * size
;
1585 dy
= sin(M_PI_2
+ theta
) * size
;
1592 dx
= cos(theta
) * size
;
1593 dy
= sin(theta
) * size
;
1598 transform_and_round_points(graphics
, pt
, ptf
, 3);
1599 Polygon(graphics
->hdc
, pt
, 3);
1603 dx
= dy
= size
/ 2.0;
1610 dx
= -cos(M_PI_2
+ theta
) * size
;
1611 dy
= -sin(M_PI_2
+ theta
) * size
;
1618 transform_and_round_points(graphics
, pt
, ptf
, 4);
1619 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1620 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1627 count
= custom
->pathdata
.Count
;
1628 custptf
= GdipAlloc(count
* sizeof(PointF
));
1629 custpt
= GdipAlloc(count
* sizeof(POINT
));
1630 tp
= GdipAlloc(count
);
1632 if(!custptf
|| !custpt
|| !tp
)
1635 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1637 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1638 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1639 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1641 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1642 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1644 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1646 for(i
= 0; i
< count
; i
++)
1647 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1650 BeginPath(graphics
->hdc
);
1651 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1652 EndPath(graphics
->hdc
);
1653 StrokeAndFillPath(graphics
->hdc
);
1656 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1668 SelectObject(graphics
->hdc
, oldbrush
);
1669 SelectObject(graphics
->hdc
, oldpen
);
1670 DeleteObject(brush
);
1675 /* Shortens the line by the given percent by changing x2, y2.
1676 * If percent is > 1.0 then the line will change direction.
1677 * If percent is negative it can lengthen the line. */
1678 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1680 REAL dist
, theta
, dx
, dy
;
1682 if((y1
== *y2
) && (x1
== *x2
))
1685 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1686 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1687 dx
= cos(theta
) * dist
;
1688 dy
= sin(theta
) * dist
;
1694 /* Shortens the line by the given amount by changing x2, y2.
1695 * If the amount is greater than the distance, the line will become length 0.
1696 * If the amount is negative, it can lengthen the line. */
1697 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1699 REAL dx
, dy
, percent
;
1703 if(dx
== 0 && dy
== 0)
1706 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1713 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1716 /* Conducts a linear search to find the bezier points that will back off
1717 * the endpoint of the curve by a distance of amt. Linear search works
1718 * better than binary in this case because there are multiple solutions,
1719 * and binary searches often find a bad one. I don't think this is what
1720 * Windows does but short of rendering the bezier without GDI's help it's
1721 * the best we can do. If rev then work from the start of the passed points
1722 * instead of the end. */
1723 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1726 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1727 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1736 origx
= pt
[fourth
].X
;
1737 origy
= pt
[fourth
].Y
;
1738 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1740 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1741 /* reset bezier points to original values */
1742 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1743 /* Perform magic on bezier points. Order is important here.*/
1744 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1745 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1746 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1747 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1748 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1749 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1751 dx
= pt
[fourth
].X
- origx
;
1752 dy
= pt
[fourth
].Y
- origy
;
1754 diff
= sqrt(dx
* dx
+ dy
* dy
);
1755 percent
+= 0.0005 * amt
;
1759 /* Draws bezier curves between given points, and if caps is true then draws an
1760 * endcap at the end of the last line. */
1761 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
1762 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1766 GpStatus status
= GenericError
;
1771 pti
= GdipAlloc(count
* sizeof(POINT
));
1772 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1774 if(!pti
|| !ptcopy
){
1775 status
= OutOfMemory
;
1779 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1782 if(pen
->endcap
== LineCapArrowAnchor
)
1783 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
1784 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1785 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
1788 if(pen
->startcap
== LineCapArrowAnchor
)
1789 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
1790 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1791 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
1793 /* the direction of the line cap is parallel to the direction at the
1794 * end of the bezier (which, if it has been shortened, is not the same
1795 * as the direction from pt[count-2] to pt[count-1]) */
1796 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1797 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1798 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1799 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1801 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1802 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
1803 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
1806 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1808 PolyBezier(graphics
->hdc
, pti
, count
);
1819 /* Draws a combination of bezier curves and lines between points. */
1820 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1821 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1823 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1824 BYTE
*tp
= GdipAlloc(count
);
1825 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1827 GpStatus status
= GenericError
;
1833 if(!pti
|| !tp
|| !ptcopy
){
1834 status
= OutOfMemory
;
1838 for(i
= 1; i
< count
; i
++){
1839 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1840 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1841 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1842 ERR("Bad bezier points\n");
1849 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1851 /* If we are drawing caps, go through the points and adjust them accordingly,
1852 * and draw the caps. */
1854 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1855 case PathPointTypeBezier
:
1856 if(pen
->endcap
== LineCapArrowAnchor
)
1857 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1858 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1859 shorten_bezier_amt(&ptcopy
[count
- 4],
1860 pen
->width
* pen
->customend
->inset
, FALSE
);
1862 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1863 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1864 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1865 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1868 case PathPointTypeLine
:
1869 if(pen
->endcap
== LineCapArrowAnchor
)
1870 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1871 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1873 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1874 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1875 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1876 pen
->customend
->inset
* pen
->width
);
1878 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1879 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1884 ERR("Bad path last point\n");
1888 /* Find start of points */
1889 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1890 == PathPointTypeStart
); j
++);
1892 switch(types
[j
] & PathPointTypePathTypeMask
){
1893 case PathPointTypeBezier
:
1894 if(pen
->startcap
== LineCapArrowAnchor
)
1895 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1896 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1897 shorten_bezier_amt(&ptcopy
[j
- 1],
1898 pen
->width
* pen
->customstart
->inset
, TRUE
);
1900 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1901 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1902 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1903 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1906 case PathPointTypeLine
:
1907 if(pen
->startcap
== LineCapArrowAnchor
)
1908 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1909 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1911 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1912 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1913 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1914 pen
->customstart
->inset
* pen
->width
);
1916 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1917 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1922 ERR("Bad path points\n");
1927 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1929 for(i
= 0; i
< count
; i
++){
1930 tp
[i
] = convert_path_point_type(types
[i
]);
1933 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1945 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1949 BeginPath(graphics
->hdc
);
1950 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1951 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1952 EndPath(graphics
->hdc
);
1956 typedef struct _GraphicsContainerItem
{
1958 GraphicsContainer contid
;
1960 SmoothingMode smoothing
;
1961 CompositingQuality compqual
;
1962 InterpolationMode interpolation
;
1963 CompositingMode compmode
;
1964 TextRenderingHint texthint
;
1967 PixelOffsetMode pixeloffset
;
1969 GpMatrix worldtrans
;
1971 INT origin_x
, origin_y
;
1972 } GraphicsContainerItem
;
1974 static GpStatus
init_container(GraphicsContainerItem
** container
,
1975 GDIPCONST GpGraphics
* graphics
){
1978 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1982 (*container
)->contid
= graphics
->contid
+ 1;
1984 (*container
)->smoothing
= graphics
->smoothing
;
1985 (*container
)->compqual
= graphics
->compqual
;
1986 (*container
)->interpolation
= graphics
->interpolation
;
1987 (*container
)->compmode
= graphics
->compmode
;
1988 (*container
)->texthint
= graphics
->texthint
;
1989 (*container
)->scale
= graphics
->scale
;
1990 (*container
)->unit
= graphics
->unit
;
1991 (*container
)->textcontrast
= graphics
->textcontrast
;
1992 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1993 (*container
)->origin_x
= graphics
->origin_x
;
1994 (*container
)->origin_y
= graphics
->origin_y
;
1995 (*container
)->worldtrans
= graphics
->worldtrans
;
1997 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1999 GdipFree(*container
);
2007 static void delete_container(GraphicsContainerItem
* container
)
2009 GdipDeleteRegion(container
->clip
);
2010 GdipFree(container
);
2013 static GpStatus
restore_container(GpGraphics
* graphics
,
2014 GDIPCONST GraphicsContainerItem
* container
){
2018 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2019 if(sts
!= Ok
) return sts
;
2021 graphics
->worldtrans
= container
->worldtrans
;
2023 GdipDeleteRegion(graphics
->clip
);
2024 graphics
->clip
= newClip
;
2026 graphics
->contid
= container
->contid
- 1;
2028 graphics
->smoothing
= container
->smoothing
;
2029 graphics
->compqual
= container
->compqual
;
2030 graphics
->interpolation
= container
->interpolation
;
2031 graphics
->compmode
= container
->compmode
;
2032 graphics
->texthint
= container
->texthint
;
2033 graphics
->scale
= container
->scale
;
2034 graphics
->unit
= container
->unit
;
2035 graphics
->textcontrast
= container
->textcontrast
;
2036 graphics
->pixeloffset
= container
->pixeloffset
;
2037 graphics
->origin_x
= container
->origin_x
;
2038 graphics
->origin_y
= container
->origin_y
;
2043 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2049 if(graphics
->hwnd
) {
2050 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2051 return GenericError
;
2053 rect
->X
= wnd_rect
.left
;
2054 rect
->Y
= wnd_rect
.top
;
2055 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2056 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2057 }else if (graphics
->image
){
2058 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2059 if (stat
== Ok
&& unit
!= UnitPixel
)
2060 FIXME("need to convert from unit %i\n", unit
);
2061 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2068 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2069 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2071 rect
->Width
= bmp
.bmWidth
;
2072 rect
->Height
= bmp
.bmHeight
;
2083 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2084 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2090 /* on success, rgn will contain the region of the graphics object which
2091 * is visible after clipping has been applied */
2092 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2098 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2101 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2104 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2107 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2110 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2113 GdipDeleteRegion(tmp
);
2117 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2121 if (font
->unit
== UnitPixel
)
2123 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2127 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2128 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2130 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2133 lf
->lfHeight
= -(height
+ 0.5);
2135 lf
->lfEscapement
= 0;
2136 lf
->lfOrientation
= 0;
2137 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2138 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2139 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2140 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2141 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2142 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2143 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2144 lf
->lfQuality
= DEFAULT_QUALITY
;
2145 lf
->lfPitchAndFamily
= 0;
2146 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2149 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2150 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2151 GDIPCONST GpMatrix
*matrix
)
2153 HDC hdc
= CreateCompatibleDC(0);
2155 REAL angle
, rel_width
, rel_height
, font_height
;
2157 HFONT unscaled_font
;
2158 TEXTMETRICW textmet
;
2160 if (font
->unit
== UnitPixel
)
2161 font_height
= font
->emSize
;
2164 REAL unit_scale
, res
;
2166 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2167 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2169 font_height
= font
->emSize
* unit_scale
;
2180 GpMatrix xform
= *matrix
;
2181 GdipTransformMatrixPoints(&xform
, pt
, 3);
2184 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2185 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2186 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2187 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2188 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2189 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2191 get_log_fontW(font
, graphics
, &lfw
);
2192 lfw
.lfHeight
= gdip_round(font_height
* rel_height
);
2193 unscaled_font
= CreateFontIndirectW(&lfw
);
2195 SelectObject(hdc
, unscaled_font
);
2196 GetTextMetricsW(hdc
, &textmet
);
2198 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2199 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2201 *hfont
= CreateFontIndirectW(&lfw
);
2204 DeleteObject(unscaled_font
);
2207 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2209 TRACE("(%p, %p)\n", hdc
, graphics
);
2211 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2214 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2220 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2223 FIXME("Don't know how to handle parameter hDevice\n");
2228 if(graphics
== NULL
)
2229 return InvalidParameter
;
2231 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2232 if(!*graphics
) return OutOfMemory
;
2234 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2236 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2237 GdipFree(*graphics
);
2241 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2242 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2243 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2245 (*graphics
)->alpha_hdc
= 1;
2248 (*graphics
)->hdc
= hdc
;
2249 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2250 (*graphics
)->owndc
= FALSE
;
2251 (*graphics
)->smoothing
= SmoothingModeDefault
;
2252 (*graphics
)->compqual
= CompositingQualityDefault
;
2253 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2254 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2255 (*graphics
)->compmode
= CompositingModeSourceOver
;
2256 (*graphics
)->unit
= UnitDisplay
;
2257 (*graphics
)->scale
= 1.0;
2258 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2259 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2260 (*graphics
)->busy
= FALSE
;
2261 (*graphics
)->textcontrast
= 4;
2262 list_init(&(*graphics
)->containers
);
2263 (*graphics
)->contid
= 0;
2265 TRACE("<-- %p\n", *graphics
);
2270 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2274 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2275 if(!*graphics
) return OutOfMemory
;
2277 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2279 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2280 GdipFree(*graphics
);
2284 (*graphics
)->hdc
= NULL
;
2285 (*graphics
)->hwnd
= NULL
;
2286 (*graphics
)->owndc
= FALSE
;
2287 (*graphics
)->image
= image
;
2288 (*graphics
)->smoothing
= SmoothingModeDefault
;
2289 (*graphics
)->compqual
= CompositingQualityDefault
;
2290 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2291 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2292 (*graphics
)->compmode
= CompositingModeSourceOver
;
2293 (*graphics
)->unit
= UnitDisplay
;
2294 (*graphics
)->scale
= 1.0;
2295 (*graphics
)->xres
= image
->xres
;
2296 (*graphics
)->yres
= image
->yres
;
2297 (*graphics
)->busy
= FALSE
;
2298 (*graphics
)->textcontrast
= 4;
2299 list_init(&(*graphics
)->containers
);
2300 (*graphics
)->contid
= 0;
2302 TRACE("<-- %p\n", *graphics
);
2307 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2312 TRACE("(%p, %p)\n", hwnd
, graphics
);
2316 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2318 ReleaseDC(hwnd
, hdc
);
2322 (*graphics
)->hwnd
= hwnd
;
2323 (*graphics
)->owndc
= TRUE
;
2328 /* FIXME: no icm handling */
2329 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2331 TRACE("(%p, %p)\n", hwnd
, graphics
);
2333 return GdipCreateFromHWND(hwnd
, graphics
);
2336 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2337 GpMetafile
**metafile
)
2339 ENHMETAHEADER header
;
2340 MetafileType metafile_type
;
2342 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2344 if(!hemf
|| !metafile
)
2345 return InvalidParameter
;
2347 if (GetEnhMetaFileHeader(hemf
, sizeof(header
), &header
) == 0)
2348 return GenericError
;
2350 metafile_type
= METAFILE_GetEmfType(hemf
);
2352 if (metafile_type
== MetafileTypeInvalid
)
2353 return GenericError
;
2355 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2359 (*metafile
)->image
.type
= ImageTypeMetafile
;
2360 (*metafile
)->image
.format
= ImageFormatEMF
;
2361 (*metafile
)->image
.frame_count
= 1;
2362 (*metafile
)->image
.xres
= (REAL
)header
.szlDevice
.cx
;
2363 (*metafile
)->image
.yres
= (REAL
)header
.szlDevice
.cy
;
2364 (*metafile
)->bounds
.X
= (REAL
)header
.rclBounds
.left
;
2365 (*metafile
)->bounds
.Y
= (REAL
)header
.rclBounds
.top
;
2366 (*metafile
)->bounds
.Width
= (REAL
)(header
.rclBounds
.right
- header
.rclBounds
.left
);
2367 (*metafile
)->bounds
.Height
= (REAL
)(header
.rclBounds
.bottom
- header
.rclBounds
.top
);
2368 (*metafile
)->unit
= UnitPixel
;
2369 (*metafile
)->metafile_type
= metafile_type
;
2370 (*metafile
)->hemf
= hemf
;
2371 (*metafile
)->preserve_hemf
= !delete;
2373 TRACE("<-- %p\n", *metafile
);
2378 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2379 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2384 GpStatus retval
= Ok
;
2386 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2388 if(!hwmf
|| !metafile
|| !placeable
)
2389 return InvalidParameter
;
2392 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2394 return GenericError
;
2395 copy
= GdipAlloc(read
);
2396 GetMetaFileBitsEx(hwmf
, read
, copy
);
2398 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2401 /* FIXME: We should store and use hwmf instead of converting to hemf */
2402 retval
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
2406 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2407 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2408 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2409 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2410 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2411 placeable
->BoundingBox
.Left
);
2412 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2413 placeable
->BoundingBox
.Top
);
2414 (*metafile
)->metafile_type
= MetafileTypeWmfPlaceable
;
2415 (*metafile
)->image
.format
= ImageFormatWMF
;
2417 if (delete) DeleteMetaFile(hwmf
);
2420 DeleteEnhMetaFile(hemf
);
2424 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2425 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2427 HMETAFILE hmf
= GetMetaFileW(file
);
2429 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2431 if(!hmf
) return InvalidParameter
;
2433 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2436 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2437 GpMetafile
**metafile
)
2439 FIXME("(%p, %p): stub\n", file
, metafile
);
2440 return NotImplemented
;
2443 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2444 GpMetafile
**metafile
)
2446 FIXME("(%p, %p): stub\n", stream
, metafile
);
2447 return NotImplemented
;
2450 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2451 UINT access
, IStream
**stream
)
2456 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2458 if(!stream
|| !filename
)
2459 return InvalidParameter
;
2461 if(access
& GENERIC_WRITE
)
2462 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2463 else if(access
& GENERIC_READ
)
2464 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2466 return InvalidParameter
;
2468 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2470 return hresult_to_status(ret
);
2473 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2475 GraphicsContainerItem
*cont
, *next
;
2477 TRACE("(%p)\n", graphics
);
2479 if(!graphics
) return InvalidParameter
;
2480 if(graphics
->busy
) return ObjectBusy
;
2482 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2484 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2490 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2492 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2493 list_remove(&cont
->entry
);
2494 delete_container(cont
);
2497 GdipDeleteRegion(graphics
->clip
);
2503 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2504 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2509 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2510 width
, height
, startAngle
, sweepAngle
);
2512 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2513 return InvalidParameter
;
2518 status
= GdipCreatePath(FillModeAlternate
, &path
);
2519 if (status
!= Ok
) return status
;
2521 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2523 status
= GdipDrawPath(graphics
, pen
, path
);
2525 GdipDeletePath(path
);
2529 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2530 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2532 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2533 width
, height
, startAngle
, sweepAngle
);
2535 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2538 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2539 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2545 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2546 x2
, y2
, x3
, y3
, x4
, y4
);
2548 if(!graphics
|| !pen
)
2549 return InvalidParameter
;
2556 FIXME("graphics object has no HDC\n");
2569 save_state
= prepare_dc(graphics
, pen
);
2571 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2573 restore_dc(graphics
, save_state
);
2578 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2579 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2581 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2582 x2
, y2
, x3
, y3
, x4
, y4
);
2584 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2587 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2588 GDIPCONST GpPointF
*points
, INT count
)
2593 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2595 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2596 return InvalidParameter
;
2601 for(i
= 0; i
< floor(count
/ 4); i
++){
2602 ret
= GdipDrawBezier(graphics
, pen
,
2603 points
[4*i
].X
, points
[4*i
].Y
,
2604 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
2605 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
2606 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
2614 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2615 GDIPCONST GpPoint
*points
, INT count
)
2621 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2623 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2624 return InvalidParameter
;
2629 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2633 for(i
= 0; i
< count
; i
++){
2634 pts
[i
].X
= (REAL
)points
[i
].X
;
2635 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2638 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2645 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2646 GDIPCONST GpPointF
*points
, INT count
)
2648 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2650 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2653 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2654 GDIPCONST GpPoint
*points
, INT count
)
2656 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2658 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2661 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2662 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2667 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2669 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2670 return InvalidParameter
;
2675 status
= GdipCreatePath(FillModeAlternate
, &path
);
2676 if (status
!= Ok
) return status
;
2678 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2680 status
= GdipDrawPath(graphics
, pen
, path
);
2682 GdipDeletePath(path
);
2687 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2688 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2694 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2696 if(!points
|| count
<= 0)
2697 return InvalidParameter
;
2699 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2703 for(i
= 0; i
< count
; i
++){
2704 ptf
[i
].X
= (REAL
)points
[i
].X
;
2705 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2708 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2715 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2716 GDIPCONST GpPointF
*points
, INT count
)
2718 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2720 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2723 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2724 GDIPCONST GpPoint
*points
, INT count
)
2730 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2733 return InvalidParameter
;
2735 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2739 for(i
= 0; i
< count
; i
++){
2740 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2741 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2744 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2750 /* Approximates cardinal spline with Bezier curves. */
2751 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2752 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2757 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2759 if(!graphics
|| !pen
)
2760 return InvalidParameter
;
2766 return InvalidParameter
;
2768 status
= GdipCreatePath(FillModeAlternate
, &path
);
2769 if (status
!= Ok
) return status
;
2771 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2773 status
= GdipDrawPath(graphics
, pen
, path
);
2775 GdipDeletePath(path
);
2779 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2780 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2786 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2789 return InvalidParameter
;
2791 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2795 for(i
= 0; i
< count
; i
++){
2796 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2797 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2800 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2806 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2807 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2810 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2812 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2813 return InvalidParameter
;
2816 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2819 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2820 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2823 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2829 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2830 return InvalidParameter
;
2833 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2836 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2837 REAL y
, REAL width
, REAL height
)
2843 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2845 if(!graphics
|| !pen
)
2846 return InvalidParameter
;
2853 FIXME("graphics object has no HDC\n");
2859 ptf
[1].X
= x
+ width
;
2860 ptf
[1].Y
= y
+ height
;
2862 save_state
= prepare_dc(graphics
, pen
);
2863 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2865 transform_and_round_points(graphics
, pti
, ptf
, 2);
2867 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2869 restore_dc(graphics
, save_state
);
2874 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2875 INT y
, INT width
, INT height
)
2877 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2879 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2883 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2887 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2889 if(!graphics
|| !image
)
2890 return InvalidParameter
;
2892 GdipGetImageWidth(image
, &width
);
2893 GdipGetImageHeight(image
, &height
);
2895 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2896 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2899 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2902 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2904 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2907 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2908 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2912 REAL scale_x
, scale_y
, width
, height
;
2914 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2916 if (!graphics
|| !image
) return InvalidParameter
;
2918 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2919 scale_x
*= graphics
->xres
/ image
->xres
;
2920 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2921 scale_y
*= graphics
->yres
/ image
->yres
;
2922 width
= srcwidth
* scale_x
;
2923 height
= srcheight
* scale_y
;
2925 points
[0].X
= points
[2].X
= x
;
2926 points
[0].Y
= points
[1].Y
= y
;
2927 points
[1].X
= x
+ width
;
2928 points
[2].Y
= y
+ height
;
2930 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2931 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2934 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2935 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2938 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2941 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2942 GDIPCONST GpPointF
*dstpoints
, INT count
)
2946 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2949 return InvalidParameter
;
2951 GdipGetImageWidth(image
, &width
);
2952 GdipGetImageHeight(image
, &height
);
2954 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2955 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2958 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2959 GDIPCONST GpPoint
*dstpoints
, INT count
)
2963 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2965 if (count
!= 3 || !dstpoints
)
2966 return InvalidParameter
;
2968 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2969 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2970 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2971 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2972 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2973 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2975 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2978 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2979 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2981 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2985 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2986 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2987 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2988 DrawImageAbort callback
, VOID
* callbackData
)
2994 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2995 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2999 return NotImplemented
;
3001 if(!graphics
|| !image
|| !points
|| count
!= 3)
3002 return InvalidParameter
;
3004 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
3005 debugstr_pointf(&points
[2]));
3007 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
3008 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
3009 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
3010 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
3012 transform_and_round_points(graphics
, pti
, ptf
, 4);
3014 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
3015 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
3017 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
3018 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
3019 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
3020 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
3021 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
3027 FIXME("graphics object has no HDC\n");
3030 if(IPicture_Render(image
->picture
, graphics
->hdc
,
3031 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3032 srcx
, srcy
, srcwidth
, srcheight
, NULL
) != S_OK
)
3035 callback(callbackData
);
3036 return GenericError
;
3039 else if (image
->type
== ImageTypeBitmap
)
3041 GpBitmap
* bitmap
= (GpBitmap
*)image
;
3044 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
3045 graphics
->xres
, graphics
->yres
,
3046 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
3047 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
3048 imageAttributes
? imageAttributes
->outside_color
: 0);
3050 if (imageAttributes
|| graphics
->alpha_hdc
||
3051 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
3052 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
3053 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
3054 srcx
< 0 || srcy
< 0 ||
3055 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
3062 int i
, x
, y
, src_stride
, dst_stride
;
3063 GpMatrix dst_to_src
;
3064 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
3065 LPBYTE src_data
, dst_data
;
3066 BitmapData lockeddata
;
3067 InterpolationMode interpolation
= graphics
->interpolation
;
3068 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
3069 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3070 REAL x_dx
, x_dy
, y_dx
, y_dy
;
3071 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
3073 if (!imageAttributes
)
3074 imageAttributes
= &defaultImageAttributes
;
3076 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3077 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3080 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3081 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3082 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3083 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3086 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
3088 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3089 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3090 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3091 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3092 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3093 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3095 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
3097 stat
= GdipInvertMatrix(&dst_to_src
);
3098 if (stat
!= Ok
) return stat
;
3100 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3101 if (!dst_data
) return OutOfMemory
;
3103 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3105 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3106 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3108 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3110 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3116 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3118 /* Read the bits we need from the source bitmap into an ARGB buffer. */
3119 lockeddata
.Width
= src_area
.Width
;
3120 lockeddata
.Height
= src_area
.Height
;
3121 lockeddata
.Stride
= src_stride
;
3122 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3123 lockeddata
.Scan0
= src_data
;
3125 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3126 PixelFormat32bppARGB
, &lockeddata
);
3129 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3133 if (src_data
!= dst_data
)
3139 apply_image_attributes(imageAttributes
, src_data
,
3140 src_area
.Width
, src_area
.Height
,
3141 src_stride
, ColorAdjustTypeBitmap
);
3143 /* Transform the bits as needed to the destination. */
3144 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3146 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3147 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3148 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3149 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3151 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3153 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3155 GpPointF src_pointf
;
3158 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3159 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3161 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3163 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3164 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3165 imageAttributes
, interpolation
, offset_mode
);
3173 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3174 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3183 int temp_hdc
=0, temp_bitmap
=0;
3184 HBITMAP hbitmap
, old_hbm
=NULL
;
3186 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3187 bitmap
->format
== PixelFormat24bppRGB
||
3188 bitmap
->format
== PixelFormat32bppRGB
||
3189 bitmap
->format
== PixelFormat32bppPARGB
))
3191 BITMAPINFOHEADER bih
;
3193 PixelFormat dst_format
;
3195 /* we can't draw a bitmap of this format directly */
3196 hdc
= CreateCompatibleDC(0);
3200 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3201 bih
.biWidth
= bitmap
->width
;
3202 bih
.biHeight
= -bitmap
->height
;
3204 bih
.biBitCount
= 32;
3205 bih
.biCompression
= BI_RGB
;
3206 bih
.biSizeImage
= 0;
3207 bih
.biXPelsPerMeter
= 0;
3208 bih
.biYPelsPerMeter
= 0;
3210 bih
.biClrImportant
= 0;
3212 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3213 (void**)&temp_bits
, NULL
, 0);
3215 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3216 dst_format
= PixelFormat32bppPARGB
;
3218 dst_format
= PixelFormat32bppRGB
;
3220 convert_pixels(bitmap
->width
, bitmap
->height
,
3221 bitmap
->width
*4, temp_bits
, dst_format
,
3222 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3223 bitmap
->image
.palette
);
3227 if (bitmap
->hbitmap
)
3228 hbitmap
= bitmap
->hbitmap
;
3231 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3236 temp_hdc
= (hdc
== 0);
3241 if (!hdc
) hdc
= CreateCompatibleDC(0);
3242 old_hbm
= SelectObject(hdc
, hbitmap
);
3245 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3247 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3248 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3252 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3253 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3258 SelectObject(hdc
, old_hbm
);
3263 DeleteObject(hbitmap
);
3266 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3272 rc
.Width
= srcwidth
;
3273 rc
.Height
= srcheight
;
3275 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3276 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3280 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3281 return InvalidParameter
;
3287 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3288 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3289 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3290 DrawImageAbort callback
, VOID
* callbackData
)
3292 GpPointF pointsF
[3];
3295 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3296 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3299 if(!points
|| count
!=3)
3300 return InvalidParameter
;
3302 for(i
= 0; i
< count
; i
++){
3303 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3304 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3307 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3308 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3309 callback
, callbackData
);
3312 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3313 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3314 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3315 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3316 VOID
* callbackData
)
3320 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3321 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3322 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3326 points
[1].X
= dstx
+ dstwidth
;
3329 points
[2].Y
= dsty
+ dstheight
;
3331 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3332 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3335 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3336 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3337 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3338 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3339 VOID
* callbackData
)
3343 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3344 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3345 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3349 points
[1].X
= dstx
+ dstwidth
;
3352 points
[2].Y
= dsty
+ dstheight
;
3354 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3355 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3358 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3359 REAL x
, REAL y
, REAL width
, REAL height
)
3365 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3367 if(!graphics
|| !image
)
3368 return InvalidParameter
;
3370 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3374 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3375 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3376 unit
, NULL
, NULL
, NULL
);
3379 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3380 INT x
, INT y
, INT width
, INT height
)
3382 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3384 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3387 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3388 REAL y1
, REAL x2
, REAL y2
)
3392 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3398 return GdipDrawLines(graphics
, pen
, pt
, 2);
3401 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3402 INT y1
, INT x2
, INT y2
)
3404 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3406 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3409 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3410 GpPointF
*points
, INT count
)
3415 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3417 if(!pen
|| !graphics
|| (count
< 2))
3418 return InvalidParameter
;
3423 status
= GdipCreatePath(FillModeAlternate
, &path
);
3424 if (status
!= Ok
) return status
;
3426 status
= GdipAddPathLine2(path
, points
, count
);
3428 status
= GdipDrawPath(graphics
, pen
, path
);
3430 GdipDeletePath(path
);
3434 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3435 GpPoint
*points
, INT count
)
3441 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3443 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3444 if(!ptf
) return OutOfMemory
;
3446 for(i
= 0; i
< count
; i
++){
3447 ptf
[i
].X
= (REAL
) points
[i
].X
;
3448 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3451 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3457 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3462 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3464 if(!pen
|| !graphics
)
3465 return InvalidParameter
;
3472 FIXME("graphics object has no HDC\n");
3476 save_state
= prepare_dc(graphics
, pen
);
3478 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3479 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3481 restore_dc(graphics
, save_state
);
3486 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3487 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3491 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3492 width
, height
, startAngle
, sweepAngle
);
3494 if(!graphics
|| !pen
)
3495 return InvalidParameter
;
3502 FIXME("graphics object has no HDC\n");
3506 save_state
= prepare_dc(graphics
, pen
);
3507 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3509 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3511 restore_dc(graphics
, save_state
);
3516 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3517 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3519 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3520 width
, height
, startAngle
, sweepAngle
);
3522 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3525 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3526 REAL y
, REAL width
, REAL height
)
3532 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3534 if(!pen
|| !graphics
)
3535 return InvalidParameter
;
3542 FIXME("graphics object has no HDC\n");
3548 ptf
[1].X
= x
+ width
;
3550 ptf
[2].X
= x
+ width
;
3551 ptf
[2].Y
= y
+ height
;
3553 ptf
[3].Y
= y
+ height
;
3555 save_state
= prepare_dc(graphics
, pen
);
3556 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3558 transform_and_round_points(graphics
, pti
, ptf
, 4);
3559 Polygon(graphics
->hdc
, pti
, 4);
3561 restore_dc(graphics
, save_state
);
3566 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3567 INT y
, INT width
, INT height
)
3569 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3571 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3574 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3575 GDIPCONST GpRectF
* rects
, INT count
)
3581 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3583 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3584 return InvalidParameter
;
3591 FIXME("graphics object has no HDC\n");
3595 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
3596 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
3604 for(i
= 0; i
< count
; i
++){
3605 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
3606 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
3607 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
3608 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
3611 save_state
= prepare_dc(graphics
, pen
);
3612 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3614 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
3616 for(i
= 0; i
< count
; i
++)
3617 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
3619 restore_dc(graphics
, save_state
);
3627 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3628 GDIPCONST GpRect
* rects
, INT count
)
3634 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3636 if(!rects
|| count
<=0)
3637 return InvalidParameter
;
3639 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3643 for(i
= 0;i
< count
;i
++){
3644 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3645 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3646 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3647 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3650 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3656 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3657 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3662 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3663 count
, tension
, fill
);
3665 if(!graphics
|| !brush
|| !points
)
3666 return InvalidParameter
;
3671 if(count
== 1) /* Do nothing */
3674 stat
= GdipCreatePath(fill
, &path
);
3678 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3680 GdipDeletePath(path
);
3684 stat
= GdipFillPath(graphics
, brush
, path
);
3686 GdipDeletePath(path
);
3690 GdipDeletePath(path
);
3695 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3696 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3702 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3703 count
, tension
, fill
);
3705 if(!points
|| count
== 0)
3706 return InvalidParameter
;
3708 if(count
== 1) /* Do nothing */
3711 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3715 for(i
= 0;i
< count
;i
++){
3716 ptf
[i
].X
= (REAL
)points
[i
].X
;
3717 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3720 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3727 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3728 GDIPCONST GpPointF
*points
, INT count
)
3730 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3731 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3732 0.5f
, FillModeAlternate
);
3735 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3736 GDIPCONST GpPoint
*points
, INT count
)
3738 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3739 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3740 0.5f
, FillModeAlternate
);
3743 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3744 REAL y
, REAL width
, REAL height
)
3749 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3751 if(!graphics
|| !brush
)
3752 return InvalidParameter
;
3757 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3761 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3764 stat
= GdipFillPath(graphics
, brush
, path
);
3766 GdipDeletePath(path
);
3772 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3773 INT y
, INT width
, INT height
)
3775 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3777 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3780 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3785 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3786 return NotImplemented
;
3788 save_state
= SaveDC(graphics
->hdc
);
3789 EndPath(graphics
->hdc
);
3790 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3793 BeginPath(graphics
->hdc
);
3794 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3795 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3800 EndPath(graphics
->hdc
);
3801 brush_fill_path(graphics
, brush
);
3806 RestoreDC(graphics
->hdc
, save_state
);
3811 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3816 if (!brush_can_fill_pixels(brush
))
3817 return NotImplemented
;
3819 /* FIXME: This could probably be done more efficiently without regions. */
3821 stat
= GdipCreateRegionPath(path
, &rgn
);
3825 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3827 GdipDeleteRegion(rgn
);
3833 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3835 GpStatus stat
= NotImplemented
;
3837 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3839 if(!brush
|| !graphics
|| !path
)
3840 return InvalidParameter
;
3845 if (!graphics
->image
&& !graphics
->alpha_hdc
)
3846 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3848 if (stat
== NotImplemented
)
3849 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3851 if (stat
== NotImplemented
)
3853 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3860 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3861 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3866 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3867 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3869 if(!graphics
|| !brush
)
3870 return InvalidParameter
;
3875 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3879 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3882 stat
= GdipFillPath(graphics
, brush
, path
);
3884 GdipDeletePath(path
);
3890 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3891 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3893 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3894 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3896 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3899 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3900 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3905 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3907 if(!graphics
|| !brush
|| !points
|| !count
)
3908 return InvalidParameter
;
3913 stat
= GdipCreatePath(fillMode
, &path
);
3917 stat
= GdipAddPathPolygon(path
, points
, count
);
3920 stat
= GdipFillPath(graphics
, brush
, path
);
3922 GdipDeletePath(path
);
3928 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3929 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3934 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3936 if(!graphics
|| !brush
|| !points
|| !count
)
3937 return InvalidParameter
;
3942 stat
= GdipCreatePath(fillMode
, &path
);
3946 stat
= GdipAddPathPolygonI(path
, points
, count
);
3949 stat
= GdipFillPath(graphics
, brush
, path
);
3951 GdipDeletePath(path
);
3957 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3958 GDIPCONST GpPointF
*points
, INT count
)
3960 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3962 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3965 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3966 GDIPCONST GpPoint
*points
, INT count
)
3968 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3970 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3973 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3974 REAL x
, REAL y
, REAL width
, REAL height
)
3979 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3981 if(!graphics
|| !brush
)
3982 return InvalidParameter
;
3987 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3991 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3994 stat
= GdipFillPath(graphics
, brush
, path
);
3996 GdipDeletePath(path
);
4002 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4003 INT x
, INT y
, INT width
, INT height
)
4005 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4007 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
4010 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4016 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4019 return InvalidParameter
;
4021 for(i
= 0; i
< count
; i
++){
4022 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
4023 if(ret
!= Ok
) return ret
;
4029 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4036 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4038 if(!rects
|| count
<= 0)
4039 return InvalidParameter
;
4041 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
4045 for(i
= 0; i
< count
; i
++){
4046 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4047 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4048 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
4049 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4052 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4058 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4066 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
4067 return NotImplemented
;
4069 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4073 save_state
= SaveDC(graphics
->hdc
);
4074 EndPath(graphics
->hdc
);
4076 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4078 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4080 BeginPath(graphics
->hdc
);
4081 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4082 EndPath(graphics
->hdc
);
4084 brush_fill_path(graphics
, brush
);
4087 RestoreDC(graphics
->hdc
, save_state
);
4094 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4098 GpRegion
*temp_region
;
4099 GpMatrix world_to_device
;
4100 GpRectF graphics_bounds
;
4104 GpRect gp_bound_rect
;
4106 if (!brush_can_fill_pixels(brush
))
4107 return NotImplemented
;
4109 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
4112 stat
= GdipCloneRegion(region
, &temp_region
);
4116 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
4117 CoordinateSpaceWorld
, &world_to_device
);
4120 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4123 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4126 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4128 GdipDeleteRegion(temp_region
);
4131 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4133 DeleteObject(hregion
);
4139 gp_bound_rect
.X
= bound_rect
.left
;
4140 gp_bound_rect
.Y
= bound_rect
.top
;
4141 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4142 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4144 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4150 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4151 &gp_bound_rect
, gp_bound_rect
.Width
);
4154 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4155 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4156 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4158 GdipFree(pixel_data
);
4161 DeleteObject(hregion
);
4167 /*****************************************************************************
4168 * GdipFillRegion [GDIPLUS.@]
4170 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4173 GpStatus stat
= NotImplemented
;
4175 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4177 if (!(graphics
&& brush
&& region
))
4178 return InvalidParameter
;
4183 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4184 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4186 if (stat
== NotImplemented
)
4187 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4189 if (stat
== NotImplemented
)
4191 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4198 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4200 TRACE("(%p,%u)\n", graphics
, intention
);
4203 return InvalidParameter
;
4208 /* We have no internal operation queue, so there's no need to clear it. */
4216 /*****************************************************************************
4217 * GdipGetClipBounds [GDIPLUS.@]
4219 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4221 TRACE("(%p, %p)\n", graphics
, rect
);
4224 return InvalidParameter
;
4229 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4232 /*****************************************************************************
4233 * GdipGetClipBoundsI [GDIPLUS.@]
4235 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4237 TRACE("(%p, %p)\n", graphics
, rect
);
4240 return InvalidParameter
;
4245 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4248 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4249 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4250 CompositingMode
*mode
)
4252 TRACE("(%p, %p)\n", graphics
, mode
);
4254 if(!graphics
|| !mode
)
4255 return InvalidParameter
;
4260 *mode
= graphics
->compmode
;
4265 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4266 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4267 CompositingQuality
*quality
)
4269 TRACE("(%p, %p)\n", graphics
, quality
);
4271 if(!graphics
|| !quality
)
4272 return InvalidParameter
;
4277 *quality
= graphics
->compqual
;
4282 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4283 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4284 InterpolationMode
*mode
)
4286 TRACE("(%p, %p)\n", graphics
, mode
);
4288 if(!graphics
|| !mode
)
4289 return InvalidParameter
;
4294 *mode
= graphics
->interpolation
;
4299 /* FIXME: Need to handle color depths less than 24bpp */
4300 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4302 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4304 if(!graphics
|| !argb
)
4305 return InvalidParameter
;
4313 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4315 TRACE("(%p, %p)\n", graphics
, scale
);
4317 if(!graphics
|| !scale
)
4318 return InvalidParameter
;
4323 *scale
= graphics
->scale
;
4328 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4330 TRACE("(%p, %p)\n", graphics
, unit
);
4332 if(!graphics
|| !unit
)
4333 return InvalidParameter
;
4338 *unit
= graphics
->unit
;
4343 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4344 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4347 TRACE("(%p, %p)\n", graphics
, mode
);
4349 if(!graphics
|| !mode
)
4350 return InvalidParameter
;
4355 *mode
= graphics
->pixeloffset
;
4360 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4361 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4363 TRACE("(%p, %p)\n", graphics
, mode
);
4365 if(!graphics
|| !mode
)
4366 return InvalidParameter
;
4371 *mode
= graphics
->smoothing
;
4376 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4378 TRACE("(%p, %p)\n", graphics
, contrast
);
4380 if(!graphics
|| !contrast
)
4381 return InvalidParameter
;
4383 *contrast
= graphics
->textcontrast
;
4388 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4389 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4390 TextRenderingHint
*hint
)
4392 TRACE("(%p, %p)\n", graphics
, hint
);
4394 if(!graphics
|| !hint
)
4395 return InvalidParameter
;
4400 *hint
= graphics
->texthint
;
4405 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4410 TRACE("(%p, %p)\n", graphics
, rect
);
4412 if(!graphics
|| !rect
)
4413 return InvalidParameter
;
4418 /* intersect window and graphics clipping regions */
4419 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4422 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4425 /* get bounds of the region */
4426 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4429 GdipDeleteRegion(clip_rgn
);
4434 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4439 TRACE("(%p, %p)\n", graphics
, rect
);
4441 if(!graphics
|| !rect
)
4442 return InvalidParameter
;
4444 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4446 rect
->X
= gdip_round(rectf
.X
);
4447 rect
->Y
= gdip_round(rectf
.Y
);
4448 rect
->Width
= gdip_round(rectf
.Width
);
4449 rect
->Height
= gdip_round(rectf
.Height
);
4455 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4457 TRACE("(%p, %p)\n", graphics
, matrix
);
4459 if(!graphics
|| !matrix
)
4460 return InvalidParameter
;
4465 *matrix
= graphics
->worldtrans
;
4469 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4475 TRACE("(%p, %x)\n", graphics
, color
);
4478 return InvalidParameter
;
4483 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4486 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4487 GdipDeleteBrush((GpBrush
*)brush
);
4491 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4492 wnd_rect
.Width
, wnd_rect
.Height
);
4494 GdipDeleteBrush((GpBrush
*)brush
);
4499 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4501 TRACE("(%p, %p)\n", graphics
, res
);
4503 if(!graphics
|| !res
)
4504 return InvalidParameter
;
4506 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4509 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4515 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4517 if(!graphics
|| !result
)
4518 return InvalidParameter
;
4525 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4526 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4529 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4532 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4535 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4538 GdipDeleteRegion(rgn
);
4542 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4544 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4547 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4553 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4555 if(!graphics
|| !result
)
4556 return InvalidParameter
;
4563 pts
[1].X
= x
+ width
;
4564 pts
[1].Y
= y
+ height
;
4566 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4567 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4570 pts
[1].X
-= pts
[0].X
;
4571 pts
[1].Y
-= pts
[0].Y
;
4573 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4576 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4579 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4582 GdipDeleteRegion(rgn
);
4586 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4588 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4591 GpStatus
gdip_format_string(HDC hdc
,
4592 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4593 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4594 gdip_format_string_callback callback
, void *user_data
)
4597 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4598 nheight
, lineend
, lineno
= 0;
4600 StringAlignment halign
;
4603 HotkeyPrefix hkprefix
;
4604 INT
*hotkeyprefix_offsets
=NULL
;
4605 INT hotkeyprefix_count
=0;
4606 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4609 if(length
== -1) length
= lstrlenW(string
);
4611 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4612 if(!stringdup
) return OutOfMemory
;
4614 nwidth
= rect
->Width
;
4615 nheight
= rect
->Height
;
4618 hkprefix
= format
->hkprefix
;
4620 hkprefix
= HotkeyPrefixNone
;
4622 if (hkprefix
== HotkeyPrefixShow
)
4624 for (i
=0; i
<length
; i
++)
4626 if (string
[i
] == '&')
4627 hotkeyprefix_count
++;
4631 if (hotkeyprefix_count
)
4632 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4634 hotkeyprefix_count
= 0;
4636 for(i
= 0, j
= 0; i
< length
; i
++){
4637 /* FIXME: This makes the indexes passed to callback inaccurate. */
4638 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4641 /* FIXME: tabs should be handled using tabstops from stringformat */
4642 if (string
[i
] == '\t')
4645 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4646 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4647 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4655 stringdup
[j
] = string
[i
];
4661 if (format
) halign
= format
->align
;
4662 else halign
= StringAlignmentNear
;
4664 while(sum
< length
){
4665 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4666 nwidth
, &fit
, NULL
, &size
);
4672 for(lret
= 0; lret
< fit
; lret
++)
4673 if(*(stringdup
+ sum
+ lret
) == '\n')
4676 /* Line break code (may look strange, but it imitates windows). */
4678 lineend
= fit
= lret
; /* this is not an off-by-one error */
4679 else if(fit
< (length
- sum
)){
4680 if(*(stringdup
+ sum
+ fit
) == ' ')
4681 while(*(stringdup
+ sum
+ fit
) == ' ')
4684 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4687 if(*(stringdup
+ sum
+ fit
) == '\t')
4696 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4697 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4703 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4704 nwidth
, &j
, NULL
, &size
);
4706 bounds
.Width
= size
.cx
;
4708 if(height
+ size
.cy
> nheight
)
4709 bounds
.Height
= nheight
- (height
+ size
.cy
);
4711 bounds
.Height
= size
.cy
;
4713 bounds
.Y
= rect
->Y
+ height
;
4717 case StringAlignmentNear
:
4721 case StringAlignmentCenter
:
4722 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4724 case StringAlignmentFar
:
4725 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4729 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4730 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4733 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4734 font
, rect
, format
, lineno
, &bounds
,
4735 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4736 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4741 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4745 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4747 if(height
> nheight
)
4750 /* Stop if this was a linewrap (but not if it was a linebreak). */
4751 if ((lret
== fitcpy
) && format
&&
4752 (format
->attr
& (StringFormatFlagsNoWrap
| StringFormatFlagsLineLimit
)))
4756 GdipFree(stringdup
);
4757 GdipFree(hotkeyprefix_offsets
);
4762 struct measure_ranges_args
{
4764 REAL rel_width
, rel_height
;
4767 static GpStatus
measure_ranges_callback(HDC hdc
,
4768 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4769 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4770 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4771 INT underlined_index_count
, void *user_data
)
4775 struct measure_ranges_args
*args
= user_data
;
4777 for (i
=0; i
<format
->range_count
; i
++)
4779 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4780 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4781 if (range_start
< range_end
)
4786 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4787 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4789 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4790 INT_MAX
, NULL
, NULL
, &range_size
);
4791 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4793 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4794 INT_MAX
, NULL
, NULL
, &range_size
);
4795 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4797 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4806 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4807 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4808 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4809 INT regionCount
, GpRegion
** regions
)
4813 HFONT gdifont
, oldfont
;
4814 struct measure_ranges_args args
;
4815 HDC hdc
, temp_hdc
=NULL
;
4820 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4821 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4823 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4824 return InvalidParameter
;
4826 if (regionCount
< stringFormat
->range_count
)
4827 return InvalidParameter
;
4831 hdc
= temp_hdc
= CreateCompatibleDC(0);
4832 if (!temp_hdc
) return OutOfMemory
;
4835 hdc
= graphics
->hdc
;
4837 if (stringFormat
->attr
)
4838 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4846 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4847 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4848 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4849 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4850 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4852 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4853 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4855 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4856 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4857 if (stringFormat
->attr
& StringFormatFlagsNoClip
)
4859 scaled_rect
.Width
= (REAL
)(1 << 23);
4860 scaled_rect
.Height
= (REAL
)(1 << 23);
4864 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
4865 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
4867 if (scaled_rect
.Width
>= 0.5)
4869 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4870 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4873 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
4874 oldfont
= SelectObject(hdc
, gdifont
);
4876 for (i
=0; i
<stringFormat
->range_count
; i
++)
4878 stat
= GdipSetEmpty(regions
[i
]);
4883 args
.regions
= regions
;
4885 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
4886 measure_ranges_callback
, &args
);
4888 SelectObject(hdc
, oldfont
);
4889 DeleteObject(gdifont
);
4897 struct measure_string_args
{
4899 INT
*codepointsfitted
;
4901 REAL rel_width
, rel_height
;
4904 static GpStatus
measure_string_callback(HDC hdc
,
4905 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4906 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4907 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4908 INT underlined_index_count
, void *user_data
)
4910 struct measure_string_args
*args
= user_data
;
4911 REAL new_width
, new_height
;
4913 new_width
= bounds
->Width
/ args
->rel_width
;
4914 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
4916 if (new_width
> args
->bounds
->Width
)
4917 args
->bounds
->Width
= new_width
;
4919 if (new_height
> args
->bounds
->Height
)
4920 args
->bounds
->Height
= new_height
;
4922 if (args
->codepointsfitted
)
4923 *args
->codepointsfitted
= index
+ length
;
4925 if (args
->linesfilled
)
4926 (*args
->linesfilled
)++;
4931 /* Find the smallest rectangle that bounds the text when it is printed in rect
4932 * according to the format options listed in format. If rect has 0 width and
4933 * height, then just find the smallest rectangle that bounds the text when it's
4934 * printed at location (rect->X, rect-Y). */
4935 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4936 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4937 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4938 INT
*codepointsfitted
, INT
*linesfilled
)
4940 HFONT oldfont
, gdifont
;
4941 struct measure_string_args args
;
4942 HDC temp_hdc
=NULL
, hdc
;
4946 INT lines
, glyphs
, format_flags
= format
? format
->attr
: 0;
4948 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4949 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4950 bounds
, codepointsfitted
, linesfilled
);
4952 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4953 return InvalidParameter
;
4957 hdc
= temp_hdc
= CreateCompatibleDC(0);
4958 if (!temp_hdc
) return OutOfMemory
;
4961 hdc
= graphics
->hdc
;
4963 if(linesfilled
) *linesfilled
= 0;
4964 if(codepointsfitted
) *codepointsfitted
= 0;
4967 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4975 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4976 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4977 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4978 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4979 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4981 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4982 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4984 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
4985 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
4986 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
4987 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
4989 if ((format_flags
& StringFormatFlagsNoClip
) ||
4990 scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
4991 if ((format_flags
& StringFormatFlagsNoClip
) ||
4992 scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
4994 if (scaled_rect
.Width
>= 0.5)
4996 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4997 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5000 if (scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5001 if (scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5003 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5004 oldfont
= SelectObject(hdc
, gdifont
);
5006 bounds
->X
= rect
->X
;
5007 bounds
->Y
= rect
->Y
;
5008 bounds
->Width
= 0.0;
5009 bounds
->Height
= 0.0;
5011 args
.bounds
= bounds
;
5012 args
.codepointsfitted
= &glyphs
;
5013 args
.linesfilled
= &lines
;
5016 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
5017 measure_string_callback
, &args
);
5019 if (linesfilled
) *linesfilled
= lines
;
5020 if (codepointsfitted
) *codepointsfitted
= glyphs
;
5023 bounds
->Width
+= margin_x
* 2.0;
5025 SelectObject(hdc
, oldfont
);
5026 DeleteObject(gdifont
);
5034 struct draw_string_args
{
5035 GpGraphics
*graphics
;
5036 GDIPCONST GpBrush
*brush
;
5037 REAL x
, y
, rel_width
, rel_height
, ascent
;
5040 static GpStatus
draw_string_callback(HDC hdc
,
5041 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5042 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5043 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5044 INT underlined_index_count
, void *user_data
)
5046 struct draw_string_args
*args
= user_data
;
5050 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5051 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5053 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
5054 args
->brush
, &position
,
5055 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5057 if (stat
== Ok
&& underlined_index_count
)
5059 OUTLINETEXTMETRICW otm
;
5060 REAL underline_y
, underline_height
;
5063 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5065 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5066 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5068 for (i
=0; i
<underlined_index_count
; i
++)
5070 REAL start_x
, end_x
;
5072 INT ofs
= underlined_indexes
[i
] - index
;
5074 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5075 start_x
= text_size
.cx
/ args
->rel_width
;
5077 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5078 end_x
= text_size
.cx
/ args
->rel_width
;
5080 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5087 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5088 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5089 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5093 GpPointF pt
[3], rectcpy
[4];
5095 REAL rel_width
, rel_height
, margin_x
;
5096 INT save_state
, format_flags
= 0;
5098 struct draw_string_args args
;
5100 HDC hdc
, temp_hdc
=NULL
;
5101 TEXTMETRICW textmetric
;
5103 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5104 length
, font
, debugstr_rectf(rect
), format
, brush
);
5106 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5107 return InvalidParameter
;
5111 hdc
= graphics
->hdc
;
5115 hdc
= temp_hdc
= CreateCompatibleDC(0);
5119 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5121 format_flags
= format
->attr
;
5123 /* Should be no need to explicitly test for StringAlignmentNear as
5124 * that is default behavior if no alignment is passed. */
5125 if(format
->vertalign
!= StringAlignmentNear
){
5126 RectF bounds
, in_rect
= *rect
;
5127 in_rect
.Height
= 0.0; /* avoid height clipping */
5128 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5130 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5132 if(format
->vertalign
== StringAlignmentCenter
)
5133 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5134 else if(format
->vertalign
== StringAlignmentFar
)
5135 offsety
= (rect
->Height
- bounds
.Height
);
5137 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
5140 save_state
= SaveDC(hdc
);
5148 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5149 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5150 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5151 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5152 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5154 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5155 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5156 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5157 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5158 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5160 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5161 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5163 scaled_rect
.X
= margin_x
* rel_width
;
5164 scaled_rect
.Y
= 0.0;
5165 scaled_rect
.Width
= rel_width
* rect
->Width
;
5166 scaled_rect
.Height
= rel_height
* rect
->Height
;
5168 if ((format_flags
& StringFormatFlagsNoClip
) ||
5169 scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5170 if ((format_flags
& StringFormatFlagsNoClip
) ||
5171 scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5173 if (scaled_rect
.Width
>= 0.5)
5175 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5176 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5179 if (scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5180 if (scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5182 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5183 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23)
5185 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5186 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5187 SelectClipRgn(hdc
, rgn
);
5190 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5191 SelectObject(hdc
, gdifont
);
5193 args
.graphics
= graphics
;
5197 args
.y
= rect
->Y
+ offsety
;
5199 args
.rel_width
= rel_width
;
5200 args
.rel_height
= rel_height
;
5202 GetTextMetricsW(hdc
, &textmetric
);
5203 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5205 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
5206 draw_string_callback
, &args
);
5209 DeleteObject(gdifont
);
5211 RestoreDC(hdc
, save_state
);
5218 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5220 TRACE("(%p)\n", graphics
);
5223 return InvalidParameter
;
5228 return GdipSetInfinite(graphics
->clip
);
5231 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5233 TRACE("(%p)\n", graphics
);
5236 return InvalidParameter
;
5241 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5244 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5246 return GdipEndContainer(graphics
, state
);
5249 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5250 GpMatrixOrder order
)
5252 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5255 return InvalidParameter
;
5260 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5263 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5265 return GdipBeginContainer2(graphics
, state
);
5268 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5269 GraphicsContainer
*state
)
5271 GraphicsContainerItem
*container
;
5274 TRACE("(%p, %p)\n", graphics
, state
);
5276 if(!graphics
|| !state
)
5277 return InvalidParameter
;
5279 sts
= init_container(&container
, graphics
);
5283 list_add_head(&graphics
->containers
, &container
->entry
);
5284 *state
= graphics
->contid
= container
->contid
;
5289 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5291 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5292 return NotImplemented
;
5295 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5297 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5298 return NotImplemented
;
5301 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5303 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5304 return NotImplemented
;
5307 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5310 GraphicsContainerItem
*container
, *container2
;
5312 TRACE("(%p, %x)\n", graphics
, state
);
5315 return InvalidParameter
;
5317 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5318 if(container
->contid
== state
)
5322 /* did not find a matching container */
5323 if(&container
->entry
== &graphics
->containers
)
5326 sts
= restore_container(graphics
, container
);
5330 /* remove all of the containers on top of the found container */
5331 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5332 if(container
->contid
== state
)
5334 list_remove(&container
->entry
);
5335 delete_container(container
);
5338 list_remove(&container
->entry
);
5339 delete_container(container
);
5344 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5345 REAL sy
, GpMatrixOrder order
)
5347 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5350 return InvalidParameter
;
5355 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5358 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5361 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5363 if(!graphics
|| !srcgraphics
)
5364 return InvalidParameter
;
5366 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5369 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5370 CompositingMode mode
)
5372 TRACE("(%p, %d)\n", graphics
, mode
);
5375 return InvalidParameter
;
5380 graphics
->compmode
= mode
;
5385 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5386 CompositingQuality quality
)
5388 TRACE("(%p, %d)\n", graphics
, quality
);
5391 return InvalidParameter
;
5396 graphics
->compqual
= quality
;
5401 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5402 InterpolationMode mode
)
5404 TRACE("(%p, %d)\n", graphics
, mode
);
5406 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5407 return InvalidParameter
;
5412 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5413 mode
= InterpolationModeBilinear
;
5415 if (mode
== InterpolationModeHighQuality
)
5416 mode
= InterpolationModeHighQualityBicubic
;
5418 graphics
->interpolation
= mode
;
5423 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5425 TRACE("(%p, %.2f)\n", graphics
, scale
);
5427 if(!graphics
|| (scale
<= 0.0))
5428 return InvalidParameter
;
5433 graphics
->scale
= scale
;
5438 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5440 TRACE("(%p, %d)\n", graphics
, unit
);
5443 return InvalidParameter
;
5448 if(unit
== UnitWorld
)
5449 return InvalidParameter
;
5451 graphics
->unit
= unit
;
5456 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5459 TRACE("(%p, %d)\n", graphics
, mode
);
5462 return InvalidParameter
;
5467 graphics
->pixeloffset
= mode
;
5472 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5476 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5479 FIXME("value is unused in rendering\n");
5482 return InvalidParameter
;
5484 graphics
->origin_x
= x
;
5485 graphics
->origin_y
= y
;
5490 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5492 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5494 if (!graphics
|| !x
|| !y
)
5495 return InvalidParameter
;
5497 *x
= graphics
->origin_x
;
5498 *y
= graphics
->origin_y
;
5503 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5505 TRACE("(%p, %d)\n", graphics
, mode
);
5508 return InvalidParameter
;
5513 graphics
->smoothing
= mode
;
5518 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5520 TRACE("(%p, %d)\n", graphics
, contrast
);
5523 return InvalidParameter
;
5525 graphics
->textcontrast
= contrast
;
5530 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5531 TextRenderingHint hint
)
5533 TRACE("(%p, %d)\n", graphics
, hint
);
5535 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5536 return InvalidParameter
;
5541 graphics
->texthint
= hint
;
5546 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5548 TRACE("(%p, %p)\n", graphics
, matrix
);
5550 if(!graphics
|| !matrix
)
5551 return InvalidParameter
;
5556 TRACE("%f,%f,%f,%f,%f,%f\n",
5557 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5558 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5560 graphics
->worldtrans
= *matrix
;
5565 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5566 REAL dy
, GpMatrixOrder order
)
5568 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5571 return InvalidParameter
;
5576 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5579 /*****************************************************************************
5580 * GdipSetClipHrgn [GDIPLUS.@]
5582 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5587 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5590 return InvalidParameter
;
5592 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5596 status
= GdipSetClipRegion(graphics
, region
, mode
);
5598 GdipDeleteRegion(region
);
5602 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5604 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5607 return InvalidParameter
;
5612 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5615 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5616 REAL width
, REAL height
,
5621 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5624 return InvalidParameter
;
5632 rect
.Height
= height
;
5634 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5637 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5638 INT width
, INT height
,
5641 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5644 return InvalidParameter
;
5649 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5652 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5655 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5657 if(!graphics
|| !region
)
5658 return InvalidParameter
;
5663 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5666 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5671 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5674 FIXME("not implemented\n");
5676 return NotImplemented
;
5679 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5685 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5687 if(!graphics
|| !pen
|| count
<=0)
5688 return InvalidParameter
;
5695 FIXME("graphics object has no HDC\n");
5699 pti
= GdipAlloc(sizeof(POINT
) * count
);
5701 save_state
= prepare_dc(graphics
, pen
);
5702 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5704 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5705 Polygon(graphics
->hdc
, pti
, count
);
5707 restore_dc(graphics
, save_state
);
5713 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5720 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5722 if(count
<=0) return InvalidParameter
;
5723 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5725 for(i
= 0;i
< count
; i
++){
5726 ptf
[i
].X
= (REAL
)points
[i
].X
;
5727 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5730 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5736 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5738 TRACE("(%p, %p)\n", graphics
, dpi
);
5740 if(!graphics
|| !dpi
)
5741 return InvalidParameter
;
5746 *dpi
= graphics
->xres
;
5750 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5752 TRACE("(%p, %p)\n", graphics
, dpi
);
5754 if(!graphics
|| !dpi
)
5755 return InvalidParameter
;
5760 *dpi
= graphics
->yres
;
5764 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5765 GpMatrixOrder order
)
5770 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5772 if(!graphics
|| !matrix
)
5773 return InvalidParameter
;
5778 m
= graphics
->worldtrans
;
5780 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5782 graphics
->worldtrans
= m
;
5787 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5788 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5790 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5794 TRACE("(%p, %p)\n", graphics
, hdc
);
5796 if(!graphics
|| !hdc
)
5797 return InvalidParameter
;
5802 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5804 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5806 else if (!graphics
->hdc
|| graphics
->alpha_hdc
||
5807 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5809 /* Create a fake HDC and fill it with a constant color. */
5813 BITMAPINFOHEADER bmih
;
5816 stat
= get_graphics_bounds(graphics
, &bounds
);
5820 graphics
->temp_hbitmap_width
= bounds
.Width
;
5821 graphics
->temp_hbitmap_height
= bounds
.Height
;
5823 bmih
.biSize
= sizeof(bmih
);
5824 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5825 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5827 bmih
.biBitCount
= 32;
5828 bmih
.biCompression
= BI_RGB
;
5829 bmih
.biSizeImage
= 0;
5830 bmih
.biXPelsPerMeter
= 0;
5831 bmih
.biYPelsPerMeter
= 0;
5833 bmih
.biClrImportant
= 0;
5835 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5836 (void**)&graphics
->temp_bits
, NULL
, 0);
5838 return GenericError
;
5840 temp_hdc
= CreateCompatibleDC(0);
5843 DeleteObject(hbitmap
);
5844 return GenericError
;
5847 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5848 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5850 SelectObject(temp_hdc
, hbitmap
);
5852 graphics
->temp_hbitmap
= hbitmap
;
5853 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5857 *hdc
= graphics
->hdc
;
5861 graphics
->busy
= TRUE
;
5866 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5870 TRACE("(%p, %p)\n", graphics
, hdc
);
5872 if(!graphics
|| !hdc
|| !graphics
->busy
)
5873 return InvalidParameter
;
5875 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5877 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5879 else if (graphics
->temp_hdc
== hdc
)
5884 /* Find the pixels that have changed, and mark them as opaque. */
5885 pos
= (DWORD
*)graphics
->temp_bits
;
5886 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5888 if (*pos
!= DC_BACKGROUND_KEY
)
5895 /* Write the changed pixels to the real target. */
5896 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5897 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5898 graphics
->temp_hbitmap_width
* 4);
5901 DeleteDC(graphics
->temp_hdc
);
5902 DeleteObject(graphics
->temp_hbitmap
);
5903 graphics
->temp_hdc
= NULL
;
5904 graphics
->temp_hbitmap
= NULL
;
5906 else if (hdc
!= graphics
->hdc
)
5908 stat
= InvalidParameter
;
5912 graphics
->busy
= FALSE
;
5917 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5922 TRACE("(%p, %p)\n", graphics
, region
);
5924 if(!graphics
|| !region
)
5925 return InvalidParameter
;
5930 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5933 /* free everything except root node and header */
5934 delete_element(®ion
->node
);
5935 memcpy(region
, clip
, sizeof(GpRegion
));
5941 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5942 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
5945 REAL scale_x
, scale_y
;
5947 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5949 if (dst_space
!= src_space
)
5951 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5952 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5954 if(graphics
->unit
!= UnitDisplay
)
5956 scale_x
*= graphics
->scale
;
5957 scale_y
*= graphics
->scale
;
5960 /* transform from src_space to CoordinateSpacePage */
5963 case CoordinateSpaceWorld
:
5964 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
5966 case CoordinateSpacePage
:
5968 case CoordinateSpaceDevice
:
5969 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
5973 /* transform from CoordinateSpacePage to dst_space */
5976 case CoordinateSpaceWorld
:
5978 GpMatrix inverted_transform
= graphics
->worldtrans
;
5979 stat
= GdipInvertMatrix(&inverted_transform
);
5981 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
5984 case CoordinateSpacePage
:
5986 case CoordinateSpaceDevice
:
5987 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
5994 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5995 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6000 if(!graphics
|| !points
|| count
<= 0)
6001 return InvalidParameter
;
6006 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6008 if (src_space
== dst_space
) return Ok
;
6010 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6011 if (stat
!= Ok
) return stat
;
6013 return GdipTransformMatrixPoints(&matrix
, points
, count
);
6016 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6017 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6023 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6026 return InvalidParameter
;
6028 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
6032 for(i
= 0; i
< count
; i
++){
6033 pointsF
[i
].X
= (REAL
)points
[i
].X
;
6034 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
6037 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6040 for(i
= 0; i
< count
; i
++){
6041 points
[i
].X
= gdip_round(pointsF
[i
].X
);
6042 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
6049 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6061 /*****************************************************************************
6062 * GdipTranslateClip [GDIPLUS.@]
6064 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6066 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6069 return InvalidParameter
;
6074 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6077 /*****************************************************************************
6078 * GdipTranslateClipI [GDIPLUS.@]
6080 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6082 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6085 return InvalidParameter
;
6090 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6094 /*****************************************************************************
6095 * GdipMeasureDriverString [GDIPLUS.@]
6097 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6098 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6099 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6101 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6104 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6106 TEXTMETRICW textmetric
;
6107 const WORD
*glyph_indices
;
6108 WORD
*dynamic_glyph_indices
=NULL
;
6109 REAL rel_width
, rel_height
, ascent
, descent
;
6112 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6114 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6115 return InvalidParameter
;
6118 length
= strlenW(text
);
6122 boundingBox
->X
= 0.0;
6123 boundingBox
->Y
= 0.0;
6124 boundingBox
->Width
= 0.0;
6125 boundingBox
->Height
= 0.0;
6128 if (flags
& unsupported_flags
)
6129 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6131 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6133 hdc
= CreateCompatibleDC(0);
6134 SelectObject(hdc
, hfont
);
6136 GetTextMetricsW(hdc
, &textmetric
);
6146 GpMatrix xform
= *matrix
;
6147 GdipTransformMatrixPoints(&xform
, pt
, 3);
6149 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6150 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6151 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6152 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6153 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6155 if (flags
& DriverStringOptionsCmapLookup
)
6157 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6161 DeleteObject(hfont
);
6165 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6168 glyph_indices
= text
;
6170 min_x
= max_x
= x
= positions
[0].X
;
6171 min_y
= max_y
= y
= positions
[0].Y
;
6173 ascent
= textmetric
.tmAscent
/ rel_height
;
6174 descent
= textmetric
.tmDescent
/ rel_height
;
6176 for (i
=0; i
<length
; i
++)
6181 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6187 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6188 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6190 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6191 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6192 if (min_x
> x
) min_x
= x
;
6194 x
+= char_width
/ rel_width
;
6196 if (max_x
< x
) max_x
= x
;
6199 GdipFree(dynamic_glyph_indices
);
6201 DeleteObject(hfont
);
6203 boundingBox
->X
= min_x
;
6204 boundingBox
->Y
= min_y
;
6205 boundingBox
->Width
= max_x
- min_x
;
6206 boundingBox
->Height
= max_y
- min_y
;
6211 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6212 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6213 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6214 INT flags
, GDIPCONST GpMatrix
*matrix
)
6216 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6222 if (flags
& unsupported_flags
)
6223 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6225 if (!(flags
& DriverStringOptionsCmapLookup
))
6226 eto_flags
|= ETO_GLYPH_INDEX
;
6228 save_state
= SaveDC(graphics
->hdc
);
6229 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6230 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6233 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6235 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6236 SelectObject(graphics
->hdc
, hfont
);
6238 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6240 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6242 RestoreDC(graphics
->hdc
, save_state
);
6244 DeleteObject(hfont
);
6249 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6250 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6251 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6252 INT flags
, GDIPCONST GpMatrix
*matrix
)
6254 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6256 PointF
*real_positions
, real_position
;
6260 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6261 DWORD max_glyphsize
=0;
6262 GLYPHMETRICS glyphmetrics
;
6263 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6266 int text_mask_stride
;
6268 int pixel_data_stride
;
6270 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6275 if (!(flags
& DriverStringOptionsCmapLookup
))
6276 ggo_flags
|= GGO_GLYPH_INDEX
;
6278 if (flags
& unsupported_flags
)
6279 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6281 pti
= GdipAlloc(sizeof(POINT
) * length
);
6285 if (flags
& DriverStringOptionsRealizedAdvance
)
6287 real_position
= positions
[0];
6289 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6293 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6294 if (!real_positions
)
6300 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6302 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6304 GdipFree(real_positions
);
6307 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6309 hdc
= CreateCompatibleDC(0);
6310 SelectObject(hdc
, hfont
);
6312 /* Get the boundaries of the text to be drawn */
6313 for (i
=0; i
<length
; i
++)
6316 int left
, top
, right
, bottom
;
6318 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6319 &glyphmetrics
, 0, NULL
, &identity
);
6321 if (glyphsize
== GDI_ERROR
)
6323 ERR("GetGlyphOutlineW failed\n");
6326 DeleteObject(hfont
);
6327 return GenericError
;
6330 if (glyphsize
> max_glyphsize
)
6331 max_glyphsize
= glyphsize
;
6333 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6334 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6335 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6336 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6338 if (left
< min_x
) min_x
= left
;
6339 if (top
< min_y
) min_y
= top
;
6340 if (right
> max_x
) max_x
= right
;
6341 if (bottom
> max_y
) max_y
= bottom
;
6343 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6345 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6346 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6350 glyph_mask
= GdipAlloc(max_glyphsize
);
6351 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6352 text_mask_stride
= max_x
- min_x
;
6354 if (!(glyph_mask
&& text_mask
))
6356 GdipFree(glyph_mask
);
6357 GdipFree(text_mask
);
6360 DeleteObject(hfont
);
6364 /* Generate a mask for the text */
6365 for (i
=0; i
<length
; i
++)
6367 int left
, top
, stride
;
6369 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6370 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6372 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6373 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6374 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6376 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6378 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6379 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6380 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6382 *text_val
= min(64, *text_val
+ *glyph_val
);
6391 DeleteObject(hfont
);
6392 GdipFree(glyph_mask
);
6394 /* get the brush data */
6395 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6398 GdipFree(text_mask
);
6402 pixel_area
.X
= min_x
;
6403 pixel_area
.Y
= min_y
;
6404 pixel_area
.Width
= max_x
- min_x
;
6405 pixel_area
.Height
= max_y
- min_y
;
6406 pixel_data_stride
= pixel_area
.Width
* 4;
6408 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6411 GdipFree(text_mask
);
6412 GdipFree(pixel_data
);
6416 /* multiply the brush data by the mask */
6417 for (y
=0; y
<pixel_area
.Height
; y
++)
6419 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6420 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6421 for (x
=0; x
<pixel_area
.Width
; x
++)
6423 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6429 GdipFree(text_mask
);
6431 /* draw the result */
6432 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6433 pixel_area
.Height
, pixel_data_stride
);
6435 GdipFree(pixel_data
);
6440 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6441 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6442 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6443 INT flags
, GDIPCONST GpMatrix
*matrix
)
6445 GpStatus stat
= NotImplemented
;
6448 length
= strlenW(text
);
6450 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6451 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6452 brush
->bt
== BrushTypeSolidColor
&&
6453 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6454 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6455 brush
, positions
, flags
, matrix
);
6456 if (stat
== NotImplemented
)
6457 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6458 brush
, positions
, flags
, matrix
);
6462 /*****************************************************************************
6463 * GdipDrawDriverString [GDIPLUS.@]
6465 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6466 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6467 GDIPCONST PointF
*positions
, INT flags
,
6468 GDIPCONST GpMatrix
*matrix
)
6470 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6472 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6473 return InvalidParameter
;
6475 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6476 brush
, positions
, flags
, matrix
);
6479 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6480 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6482 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6483 return NotImplemented
;
6486 /*****************************************************************************
6487 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6489 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6494 TRACE("(%p, %p)\n", graphics
, res
);
6496 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6499 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6502 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6505 GdipDeleteRegion(rgn
);
6509 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6513 TRACE("(%p) stub\n", graphics
);
6516 FIXME("not implemented\n");
6518 return NotImplemented
;