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 /* Draws lines between the given points, and if caps is true then draws an endcap
1717 * at the end of the last line. */
1718 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
1719 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1722 GpPointF
*ptcopy
= NULL
;
1723 GpStatus status
= GenericError
;
1728 pti
= GdipAlloc(count
* sizeof(POINT
));
1729 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1731 if(!pti
|| !ptcopy
){
1732 status
= OutOfMemory
;
1736 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1739 if(pen
->endcap
== LineCapArrowAnchor
)
1740 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1741 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
1742 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1743 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1744 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
1745 pen
->customend
->inset
* pen
->width
);
1747 if(pen
->startcap
== LineCapArrowAnchor
)
1748 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1749 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
1750 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1751 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1752 &ptcopy
[0].X
, &ptcopy
[0].Y
,
1753 pen
->customstart
->inset
* pen
->width
);
1755 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1756 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
1757 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1758 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
1761 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1763 if(Polyline(graphics
->hdc
, pti
, count
))
1773 /* Conducts a linear search to find the bezier points that will back off
1774 * the endpoint of the curve by a distance of amt. Linear search works
1775 * better than binary in this case because there are multiple solutions,
1776 * and binary searches often find a bad one. I don't think this is what
1777 * Windows does but short of rendering the bezier without GDI's help it's
1778 * the best we can do. If rev then work from the start of the passed points
1779 * instead of the end. */
1780 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1783 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1784 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1793 origx
= pt
[fourth
].X
;
1794 origy
= pt
[fourth
].Y
;
1795 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1797 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1798 /* reset bezier points to original values */
1799 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1800 /* Perform magic on bezier points. Order is important here.*/
1801 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1802 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1803 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1804 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1805 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1806 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1808 dx
= pt
[fourth
].X
- origx
;
1809 dy
= pt
[fourth
].Y
- origy
;
1811 diff
= sqrt(dx
* dx
+ dy
* dy
);
1812 percent
+= 0.0005 * amt
;
1816 /* Draws bezier curves between given points, and if caps is true then draws an
1817 * endcap at the end of the last line. */
1818 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
1819 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1823 GpStatus status
= GenericError
;
1828 pti
= GdipAlloc(count
* sizeof(POINT
));
1829 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1831 if(!pti
|| !ptcopy
){
1832 status
= OutOfMemory
;
1836 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1839 if(pen
->endcap
== LineCapArrowAnchor
)
1840 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
1841 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1842 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
1845 if(pen
->startcap
== LineCapArrowAnchor
)
1846 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
1847 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1848 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
1850 /* the direction of the line cap is parallel to the direction at the
1851 * end of the bezier (which, if it has been shortened, is not the same
1852 * as the direction from pt[count-2] to pt[count-1]) */
1853 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1854 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1855 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1856 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1858 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1859 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
1860 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
1863 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1865 PolyBezier(graphics
->hdc
, pti
, count
);
1876 /* Draws a combination of bezier curves and lines between points. */
1877 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1878 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1880 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1881 BYTE
*tp
= GdipAlloc(count
);
1882 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1884 GpStatus status
= GenericError
;
1890 if(!pti
|| !tp
|| !ptcopy
){
1891 status
= OutOfMemory
;
1895 for(i
= 1; i
< count
; i
++){
1896 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1897 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1898 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1899 ERR("Bad bezier points\n");
1906 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1908 /* If we are drawing caps, go through the points and adjust them accordingly,
1909 * and draw the caps. */
1911 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1912 case PathPointTypeBezier
:
1913 if(pen
->endcap
== LineCapArrowAnchor
)
1914 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1915 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1916 shorten_bezier_amt(&ptcopy
[count
- 4],
1917 pen
->width
* pen
->customend
->inset
, FALSE
);
1919 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1920 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1921 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1922 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1925 case PathPointTypeLine
:
1926 if(pen
->endcap
== LineCapArrowAnchor
)
1927 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1928 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1930 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1931 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1932 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1933 pen
->customend
->inset
* pen
->width
);
1935 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1936 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1941 ERR("Bad path last point\n");
1945 /* Find start of points */
1946 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1947 == PathPointTypeStart
); j
++);
1949 switch(types
[j
] & PathPointTypePathTypeMask
){
1950 case PathPointTypeBezier
:
1951 if(pen
->startcap
== LineCapArrowAnchor
)
1952 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1953 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1954 shorten_bezier_amt(&ptcopy
[j
- 1],
1955 pen
->width
* pen
->customstart
->inset
, TRUE
);
1957 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1958 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1959 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1960 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1963 case PathPointTypeLine
:
1964 if(pen
->startcap
== LineCapArrowAnchor
)
1965 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1966 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1968 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1969 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1970 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1971 pen
->customstart
->inset
* pen
->width
);
1973 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1974 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1979 ERR("Bad path points\n");
1984 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1986 for(i
= 0; i
< count
; i
++){
1987 tp
[i
] = convert_path_point_type(types
[i
]);
1990 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
2002 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
2006 BeginPath(graphics
->hdc
);
2007 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2008 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2009 EndPath(graphics
->hdc
);
2013 typedef struct _GraphicsContainerItem
{
2015 GraphicsContainer contid
;
2017 SmoothingMode smoothing
;
2018 CompositingQuality compqual
;
2019 InterpolationMode interpolation
;
2020 CompositingMode compmode
;
2021 TextRenderingHint texthint
;
2024 PixelOffsetMode pixeloffset
;
2026 GpMatrix worldtrans
;
2028 INT origin_x
, origin_y
;
2029 } GraphicsContainerItem
;
2031 static GpStatus
init_container(GraphicsContainerItem
** container
,
2032 GDIPCONST GpGraphics
* graphics
){
2035 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
2039 (*container
)->contid
= graphics
->contid
+ 1;
2041 (*container
)->smoothing
= graphics
->smoothing
;
2042 (*container
)->compqual
= graphics
->compqual
;
2043 (*container
)->interpolation
= graphics
->interpolation
;
2044 (*container
)->compmode
= graphics
->compmode
;
2045 (*container
)->texthint
= graphics
->texthint
;
2046 (*container
)->scale
= graphics
->scale
;
2047 (*container
)->unit
= graphics
->unit
;
2048 (*container
)->textcontrast
= graphics
->textcontrast
;
2049 (*container
)->pixeloffset
= graphics
->pixeloffset
;
2050 (*container
)->origin_x
= graphics
->origin_x
;
2051 (*container
)->origin_y
= graphics
->origin_y
;
2052 (*container
)->worldtrans
= graphics
->worldtrans
;
2054 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
2056 GdipFree(*container
);
2064 static void delete_container(GraphicsContainerItem
* container
)
2066 GdipDeleteRegion(container
->clip
);
2067 GdipFree(container
);
2070 static GpStatus
restore_container(GpGraphics
* graphics
,
2071 GDIPCONST GraphicsContainerItem
* container
){
2075 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2076 if(sts
!= Ok
) return sts
;
2078 graphics
->worldtrans
= container
->worldtrans
;
2080 GdipDeleteRegion(graphics
->clip
);
2081 graphics
->clip
= newClip
;
2083 graphics
->contid
= container
->contid
- 1;
2085 graphics
->smoothing
= container
->smoothing
;
2086 graphics
->compqual
= container
->compqual
;
2087 graphics
->interpolation
= container
->interpolation
;
2088 graphics
->compmode
= container
->compmode
;
2089 graphics
->texthint
= container
->texthint
;
2090 graphics
->scale
= container
->scale
;
2091 graphics
->unit
= container
->unit
;
2092 graphics
->textcontrast
= container
->textcontrast
;
2093 graphics
->pixeloffset
= container
->pixeloffset
;
2094 graphics
->origin_x
= container
->origin_x
;
2095 graphics
->origin_y
= container
->origin_y
;
2100 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2106 if(graphics
->hwnd
) {
2107 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2108 return GenericError
;
2110 rect
->X
= wnd_rect
.left
;
2111 rect
->Y
= wnd_rect
.top
;
2112 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2113 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2114 }else if (graphics
->image
){
2115 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2116 if (stat
== Ok
&& unit
!= UnitPixel
)
2117 FIXME("need to convert from unit %i\n", unit
);
2118 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2125 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2126 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2128 rect
->Width
= bmp
.bmWidth
;
2129 rect
->Height
= bmp
.bmHeight
;
2140 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2141 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2147 /* on success, rgn will contain the region of the graphics object which
2148 * is visible after clipping has been applied */
2149 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2155 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2158 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2161 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2164 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2167 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2170 GdipDeleteRegion(tmp
);
2174 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2178 if (font
->unit
== UnitPixel
)
2180 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2184 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2185 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2187 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2190 lf
->lfHeight
= -(height
+ 0.5);
2192 lf
->lfEscapement
= 0;
2193 lf
->lfOrientation
= 0;
2194 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2195 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2196 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2197 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2198 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2199 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2200 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2201 lf
->lfQuality
= DEFAULT_QUALITY
;
2202 lf
->lfPitchAndFamily
= 0;
2203 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2206 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2207 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2208 GDIPCONST GpMatrix
*matrix
)
2210 HDC hdc
= CreateCompatibleDC(0);
2212 REAL angle
, rel_width
, rel_height
, font_height
;
2214 HFONT unscaled_font
;
2215 TEXTMETRICW textmet
;
2217 if (font
->unit
== UnitPixel
)
2218 font_height
= font
->emSize
;
2221 REAL unit_scale
, res
;
2223 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2224 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2226 font_height
= font
->emSize
* unit_scale
;
2237 GpMatrix xform
= *matrix
;
2238 GdipTransformMatrixPoints(&xform
, pt
, 3);
2241 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2242 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2243 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2244 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2245 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2246 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2248 get_log_fontW(font
, graphics
, &lfw
);
2249 lfw
.lfHeight
= gdip_round(font_height
* rel_height
);
2250 unscaled_font
= CreateFontIndirectW(&lfw
);
2252 SelectObject(hdc
, unscaled_font
);
2253 GetTextMetricsW(hdc
, &textmet
);
2255 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2256 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2258 *hfont
= CreateFontIndirectW(&lfw
);
2261 DeleteObject(unscaled_font
);
2264 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2266 TRACE("(%p, %p)\n", hdc
, graphics
);
2268 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2271 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2277 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2280 FIXME("Don't know how to handle parameter hDevice\n");
2285 if(graphics
== NULL
)
2286 return InvalidParameter
;
2288 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2289 if(!*graphics
) return OutOfMemory
;
2291 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2293 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2294 GdipFree(*graphics
);
2298 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2299 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2300 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2302 (*graphics
)->alpha_hdc
= 1;
2305 (*graphics
)->hdc
= hdc
;
2306 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2307 (*graphics
)->owndc
= FALSE
;
2308 (*graphics
)->smoothing
= SmoothingModeDefault
;
2309 (*graphics
)->compqual
= CompositingQualityDefault
;
2310 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2311 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2312 (*graphics
)->compmode
= CompositingModeSourceOver
;
2313 (*graphics
)->unit
= UnitDisplay
;
2314 (*graphics
)->scale
= 1.0;
2315 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2316 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2317 (*graphics
)->busy
= FALSE
;
2318 (*graphics
)->textcontrast
= 4;
2319 list_init(&(*graphics
)->containers
);
2320 (*graphics
)->contid
= 0;
2322 TRACE("<-- %p\n", *graphics
);
2327 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2331 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2332 if(!*graphics
) return OutOfMemory
;
2334 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2336 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2337 GdipFree(*graphics
);
2341 (*graphics
)->hdc
= NULL
;
2342 (*graphics
)->hwnd
= NULL
;
2343 (*graphics
)->owndc
= FALSE
;
2344 (*graphics
)->image
= image
;
2345 (*graphics
)->smoothing
= SmoothingModeDefault
;
2346 (*graphics
)->compqual
= CompositingQualityDefault
;
2347 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2348 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2349 (*graphics
)->compmode
= CompositingModeSourceOver
;
2350 (*graphics
)->unit
= UnitDisplay
;
2351 (*graphics
)->scale
= 1.0;
2352 (*graphics
)->xres
= image
->xres
;
2353 (*graphics
)->yres
= image
->yres
;
2354 (*graphics
)->busy
= FALSE
;
2355 (*graphics
)->textcontrast
= 4;
2356 list_init(&(*graphics
)->containers
);
2357 (*graphics
)->contid
= 0;
2359 TRACE("<-- %p\n", *graphics
);
2364 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2369 TRACE("(%p, %p)\n", hwnd
, graphics
);
2373 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2375 ReleaseDC(hwnd
, hdc
);
2379 (*graphics
)->hwnd
= hwnd
;
2380 (*graphics
)->owndc
= TRUE
;
2385 /* FIXME: no icm handling */
2386 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2388 TRACE("(%p, %p)\n", hwnd
, graphics
);
2390 return GdipCreateFromHWND(hwnd
, graphics
);
2393 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2394 GpMetafile
**metafile
)
2396 ENHMETAHEADER header
;
2397 MetafileType metafile_type
;
2399 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2401 if(!hemf
|| !metafile
)
2402 return InvalidParameter
;
2404 if (GetEnhMetaFileHeader(hemf
, sizeof(header
), &header
) == 0)
2405 return GenericError
;
2407 metafile_type
= METAFILE_GetEmfType(hemf
);
2409 if (metafile_type
== MetafileTypeInvalid
)
2410 return GenericError
;
2412 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2416 (*metafile
)->image
.type
= ImageTypeMetafile
;
2417 (*metafile
)->image
.format
= ImageFormatEMF
;
2418 (*metafile
)->image
.frame_count
= 1;
2419 (*metafile
)->image
.xres
= (REAL
)header
.szlDevice
.cx
;
2420 (*metafile
)->image
.yres
= (REAL
)header
.szlDevice
.cy
;
2421 (*metafile
)->bounds
.X
= (REAL
)header
.rclBounds
.left
;
2422 (*metafile
)->bounds
.Y
= (REAL
)header
.rclBounds
.top
;
2423 (*metafile
)->bounds
.Width
= (REAL
)(header
.rclBounds
.right
- header
.rclBounds
.left
);
2424 (*metafile
)->bounds
.Height
= (REAL
)(header
.rclBounds
.bottom
- header
.rclBounds
.top
);
2425 (*metafile
)->unit
= UnitPixel
;
2426 (*metafile
)->metafile_type
= metafile_type
;
2427 (*metafile
)->hemf
= hemf
;
2428 (*metafile
)->preserve_hemf
= !delete;
2430 TRACE("<-- %p\n", *metafile
);
2435 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2436 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2441 GpStatus retval
= Ok
;
2443 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2445 if(!hwmf
|| !metafile
|| !placeable
)
2446 return InvalidParameter
;
2449 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2451 return GenericError
;
2452 copy
= GdipAlloc(read
);
2453 GetMetaFileBitsEx(hwmf
, read
, copy
);
2455 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2458 /* FIXME: We should store and use hwmf instead of converting to hemf */
2459 retval
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
2463 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2464 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2465 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2466 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2467 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2468 placeable
->BoundingBox
.Left
);
2469 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2470 placeable
->BoundingBox
.Top
);
2471 (*metafile
)->metafile_type
= MetafileTypeWmfPlaceable
;
2472 (*metafile
)->image
.format
= ImageFormatWMF
;
2474 if (delete) DeleteMetaFile(hwmf
);
2477 DeleteEnhMetaFile(hemf
);
2481 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2482 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2484 HMETAFILE hmf
= GetMetaFileW(file
);
2486 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2488 if(!hmf
) return InvalidParameter
;
2490 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2493 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2494 GpMetafile
**metafile
)
2496 FIXME("(%p, %p): stub\n", file
, metafile
);
2497 return NotImplemented
;
2500 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2501 GpMetafile
**metafile
)
2503 FIXME("(%p, %p): stub\n", stream
, metafile
);
2504 return NotImplemented
;
2507 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2508 UINT access
, IStream
**stream
)
2513 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2515 if(!stream
|| !filename
)
2516 return InvalidParameter
;
2518 if(access
& GENERIC_WRITE
)
2519 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2520 else if(access
& GENERIC_READ
)
2521 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2523 return InvalidParameter
;
2525 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2527 return hresult_to_status(ret
);
2530 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2532 GraphicsContainerItem
*cont
, *next
;
2534 TRACE("(%p)\n", graphics
);
2536 if(!graphics
) return InvalidParameter
;
2537 if(graphics
->busy
) return ObjectBusy
;
2539 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2541 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2547 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2549 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2550 list_remove(&cont
->entry
);
2551 delete_container(cont
);
2554 GdipDeleteRegion(graphics
->clip
);
2560 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2561 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2563 INT save_state
, num_pts
;
2564 GpPointF points
[MAX_ARC_PTS
];
2567 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2568 width
, height
, startAngle
, sweepAngle
);
2570 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2571 return InvalidParameter
;
2578 FIXME("graphics object has no HDC\n");
2582 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2584 save_state
= prepare_dc(graphics
, pen
);
2586 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
2588 restore_dc(graphics
, save_state
);
2593 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2594 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2596 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2597 width
, height
, startAngle
, sweepAngle
);
2599 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2602 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2603 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2609 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2610 x2
, y2
, x3
, y3
, x4
, y4
);
2612 if(!graphics
|| !pen
)
2613 return InvalidParameter
;
2620 FIXME("graphics object has no HDC\n");
2633 save_state
= prepare_dc(graphics
, pen
);
2635 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2637 restore_dc(graphics
, save_state
);
2642 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2643 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2649 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2650 x2
, y2
, x3
, y3
, x4
, y4
);
2652 if(!graphics
|| !pen
)
2653 return InvalidParameter
;
2660 FIXME("graphics object has no HDC\n");
2673 save_state
= prepare_dc(graphics
, pen
);
2675 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2677 restore_dc(graphics
, save_state
);
2682 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2683 GDIPCONST GpPointF
*points
, INT count
)
2688 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2690 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2691 return InvalidParameter
;
2696 for(i
= 0; i
< floor(count
/ 4); i
++){
2697 ret
= GdipDrawBezier(graphics
, pen
,
2698 points
[4*i
].X
, points
[4*i
].Y
,
2699 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
2700 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
2701 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
2709 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2710 GDIPCONST GpPoint
*points
, INT count
)
2716 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2718 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2719 return InvalidParameter
;
2724 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2728 for(i
= 0; i
< count
; i
++){
2729 pts
[i
].X
= (REAL
)points
[i
].X
;
2730 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2733 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2740 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2741 GDIPCONST GpPointF
*points
, INT count
)
2743 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2745 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2748 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2749 GDIPCONST GpPoint
*points
, INT count
)
2751 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2753 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2756 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2757 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2762 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2764 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2765 return InvalidParameter
;
2770 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
2773 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2775 GdipDeletePath(path
);
2779 stat
= GdipDrawPath(graphics
, pen
, path
);
2781 GdipDeletePath(path
);
2786 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2787 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2793 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2795 if(!points
|| count
<= 0)
2796 return InvalidParameter
;
2798 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2802 for(i
= 0; i
< count
; i
++){
2803 ptf
[i
].X
= (REAL
)points
[i
].X
;
2804 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2807 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2814 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2815 GDIPCONST GpPointF
*points
, INT count
)
2817 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2819 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2822 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2823 GDIPCONST GpPoint
*points
, INT count
)
2829 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2832 return InvalidParameter
;
2834 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2838 for(i
= 0; i
< count
; i
++){
2839 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2840 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2843 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2849 /* Approximates cardinal spline with Bezier curves. */
2850 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2851 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2853 /* PolyBezier expects count*3-2 points. */
2854 INT i
, len_pt
= count
*3-2, save_state
;
2856 REAL x1
, x2
, y1
, y2
;
2859 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2861 if(!graphics
|| !pen
)
2862 return InvalidParameter
;
2868 return InvalidParameter
;
2872 FIXME("graphics object has no HDC\n");
2876 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
2880 tension
= tension
* TENSION_CONST
;
2882 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
2885 pt
[0].X
= points
[0].X
;
2886 pt
[0].Y
= points
[0].Y
;
2890 for(i
= 0; i
< count
-2; i
++){
2891 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
2895 pt
[3*i
+3].X
= points
[i
+1].X
;
2896 pt
[3*i
+3].Y
= points
[i
+1].Y
;
2901 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
2902 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
2904 pt
[len_pt
-2].X
= x1
;
2905 pt
[len_pt
-2].Y
= y1
;
2906 pt
[len_pt
-1].X
= points
[count
-1].X
;
2907 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
2909 save_state
= prepare_dc(graphics
, pen
);
2911 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
2914 restore_dc(graphics
, save_state
);
2919 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2920 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2926 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2929 return InvalidParameter
;
2931 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2935 for(i
= 0; i
< count
; i
++){
2936 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2937 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2940 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2946 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2947 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2950 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2952 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2953 return InvalidParameter
;
2956 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2959 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2960 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2963 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2969 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2970 return InvalidParameter
;
2973 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2976 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2977 REAL y
, REAL width
, REAL height
)
2983 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2985 if(!graphics
|| !pen
)
2986 return InvalidParameter
;
2993 FIXME("graphics object has no HDC\n");
2999 ptf
[1].X
= x
+ width
;
3000 ptf
[1].Y
= y
+ height
;
3002 save_state
= prepare_dc(graphics
, pen
);
3003 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3005 transform_and_round_points(graphics
, pti
, ptf
, 2);
3007 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
3009 restore_dc(graphics
, save_state
);
3014 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3015 INT y
, INT width
, INT height
)
3017 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3019 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3023 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
3027 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
3029 if(!graphics
|| !image
)
3030 return InvalidParameter
;
3032 GdipGetImageWidth(image
, &width
);
3033 GdipGetImageHeight(image
, &height
);
3035 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
3036 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
3039 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
3042 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
3044 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
3047 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
3048 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
3052 REAL scale_x
, scale_y
, width
, height
;
3054 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
3056 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
3057 scale_x
*= graphics
->xres
/ image
->xres
;
3058 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
3059 scale_y
*= graphics
->yres
/ image
->yres
;
3060 width
= srcwidth
* scale_x
;
3061 height
= srcheight
* scale_y
;
3063 points
[0].X
= points
[2].X
= x
;
3064 points
[0].Y
= points
[1].Y
= y
;
3065 points
[1].X
= x
+ width
;
3066 points
[2].Y
= y
+ height
;
3068 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3069 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
3072 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
3073 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
3076 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
3079 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
3080 GDIPCONST GpPointF
*dstpoints
, INT count
)
3084 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
3087 return InvalidParameter
;
3089 GdipGetImageWidth(image
, &width
);
3090 GdipGetImageHeight(image
, &height
);
3092 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
3093 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
3096 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
3097 GDIPCONST GpPoint
*dstpoints
, INT count
)
3101 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
3103 if (count
!= 3 || !dstpoints
)
3104 return InvalidParameter
;
3106 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
3107 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
3108 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
3109 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
3110 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
3111 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
3113 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
3116 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
3117 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
3119 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
3123 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
3124 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
3125 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3126 DrawImageAbort callback
, VOID
* callbackData
)
3132 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
3133 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3137 return NotImplemented
;
3139 if(!graphics
|| !image
|| !points
|| count
!= 3)
3140 return InvalidParameter
;
3142 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
3143 debugstr_pointf(&points
[2]));
3145 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
3146 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
3147 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
3148 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
3150 transform_and_round_points(graphics
, pti
, ptf
, 4);
3152 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
3153 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
3155 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
3156 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
3157 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
3158 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
3159 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
3165 FIXME("graphics object has no HDC\n");
3168 if(IPicture_Render(image
->picture
, graphics
->hdc
,
3169 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3170 srcx
, srcy
, srcwidth
, srcheight
, NULL
) != S_OK
)
3173 callback(callbackData
);
3174 return GenericError
;
3177 else if (image
->type
== ImageTypeBitmap
)
3179 GpBitmap
* bitmap
= (GpBitmap
*)image
;
3182 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
3183 graphics
->xres
, graphics
->yres
,
3184 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
3185 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
3186 imageAttributes
? imageAttributes
->outside_color
: 0);
3188 if (imageAttributes
|| graphics
->alpha_hdc
||
3189 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
3190 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
3191 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
3192 srcx
< 0 || srcy
< 0 ||
3193 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
3200 int i
, x
, y
, src_stride
, dst_stride
;
3201 GpMatrix dst_to_src
;
3202 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
3203 LPBYTE src_data
, dst_data
;
3204 BitmapData lockeddata
;
3205 InterpolationMode interpolation
= graphics
->interpolation
;
3206 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
3207 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3208 REAL x_dx
, x_dy
, y_dx
, y_dy
;
3209 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
3211 if (!imageAttributes
)
3212 imageAttributes
= &defaultImageAttributes
;
3214 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3215 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3218 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3219 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3220 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3221 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3224 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
3226 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3227 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3228 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3229 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3230 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3231 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3233 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
3235 stat
= GdipInvertMatrix(&dst_to_src
);
3236 if (stat
!= Ok
) return stat
;
3238 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3239 if (!dst_data
) return OutOfMemory
;
3241 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3243 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3244 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3246 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3248 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3254 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3256 /* Read the bits we need from the source bitmap into an ARGB buffer. */
3257 lockeddata
.Width
= src_area
.Width
;
3258 lockeddata
.Height
= src_area
.Height
;
3259 lockeddata
.Stride
= src_stride
;
3260 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3261 lockeddata
.Scan0
= src_data
;
3263 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3264 PixelFormat32bppARGB
, &lockeddata
);
3267 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3271 if (src_data
!= dst_data
)
3277 apply_image_attributes(imageAttributes
, src_data
,
3278 src_area
.Width
, src_area
.Height
,
3279 src_stride
, ColorAdjustTypeBitmap
);
3281 /* Transform the bits as needed to the destination. */
3282 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3284 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3285 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3286 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3287 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3289 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3291 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3293 GpPointF src_pointf
;
3296 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3297 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3299 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3301 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3302 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3303 imageAttributes
, interpolation
, offset_mode
);
3311 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3312 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3321 int temp_hdc
=0, temp_bitmap
=0;
3322 HBITMAP hbitmap
, old_hbm
=NULL
;
3324 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3325 bitmap
->format
== PixelFormat24bppRGB
||
3326 bitmap
->format
== PixelFormat32bppRGB
||
3327 bitmap
->format
== PixelFormat32bppPARGB
))
3329 BITMAPINFOHEADER bih
;
3331 PixelFormat dst_format
;
3333 /* we can't draw a bitmap of this format directly */
3334 hdc
= CreateCompatibleDC(0);
3338 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3339 bih
.biWidth
= bitmap
->width
;
3340 bih
.biHeight
= -bitmap
->height
;
3342 bih
.biBitCount
= 32;
3343 bih
.biCompression
= BI_RGB
;
3344 bih
.biSizeImage
= 0;
3345 bih
.biXPelsPerMeter
= 0;
3346 bih
.biYPelsPerMeter
= 0;
3348 bih
.biClrImportant
= 0;
3350 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3351 (void**)&temp_bits
, NULL
, 0);
3353 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3354 dst_format
= PixelFormat32bppPARGB
;
3356 dst_format
= PixelFormat32bppRGB
;
3358 convert_pixels(bitmap
->width
, bitmap
->height
,
3359 bitmap
->width
*4, temp_bits
, dst_format
,
3360 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3361 bitmap
->image
.palette
);
3365 if (bitmap
->hbitmap
)
3366 hbitmap
= bitmap
->hbitmap
;
3369 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3374 temp_hdc
= (hdc
== 0);
3379 if (!hdc
) hdc
= CreateCompatibleDC(0);
3380 old_hbm
= SelectObject(hdc
, hbitmap
);
3383 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3385 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3386 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3390 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3391 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3396 SelectObject(hdc
, old_hbm
);
3401 DeleteObject(hbitmap
);
3404 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3410 rc
.Width
= srcwidth
;
3411 rc
.Height
= srcheight
;
3413 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3414 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3418 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3419 return InvalidParameter
;
3425 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3426 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3427 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3428 DrawImageAbort callback
, VOID
* callbackData
)
3430 GpPointF pointsF
[3];
3433 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3434 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3437 if(!points
|| count
!=3)
3438 return InvalidParameter
;
3440 for(i
= 0; i
< count
; i
++){
3441 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3442 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3445 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3446 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3447 callback
, callbackData
);
3450 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3451 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3452 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3453 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3454 VOID
* callbackData
)
3458 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3459 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3460 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3464 points
[1].X
= dstx
+ dstwidth
;
3467 points
[2].Y
= dsty
+ dstheight
;
3469 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3470 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3473 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3474 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3475 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3476 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3477 VOID
* callbackData
)
3481 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3482 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3483 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3487 points
[1].X
= dstx
+ dstwidth
;
3490 points
[2].Y
= dsty
+ dstheight
;
3492 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3493 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3496 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3497 REAL x
, REAL y
, REAL width
, REAL height
)
3503 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3505 if(!graphics
|| !image
)
3506 return InvalidParameter
;
3508 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3512 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3513 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3514 unit
, NULL
, NULL
, NULL
);
3517 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3518 INT x
, INT y
, INT width
, INT height
)
3520 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3522 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3525 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3526 REAL y1
, REAL x2
, REAL y2
)
3530 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3536 return GdipDrawLines(graphics
, pen
, pt
, 2);
3539 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3540 INT y1
, INT x2
, INT y2
)
3542 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3544 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3547 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3548 GpPointF
*points
, INT count
)
3553 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3555 if(!pen
|| !graphics
|| (count
< 2))
3556 return InvalidParameter
;
3563 FIXME("graphics object has no HDC\n");
3567 save_state
= prepare_dc(graphics
, pen
);
3569 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
3571 restore_dc(graphics
, save_state
);
3576 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3577 GpPoint
*points
, INT count
)
3583 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3585 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3586 if(!ptf
) return OutOfMemory
;
3588 for(i
= 0; i
< count
; i
++){
3589 ptf
[i
].X
= (REAL
) points
[i
].X
;
3590 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3593 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3599 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3604 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3606 if(!pen
|| !graphics
)
3607 return InvalidParameter
;
3614 FIXME("graphics object has no HDC\n");
3618 save_state
= prepare_dc(graphics
, pen
);
3620 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3621 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3623 restore_dc(graphics
, save_state
);
3628 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3629 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3633 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3634 width
, height
, startAngle
, sweepAngle
);
3636 if(!graphics
|| !pen
)
3637 return InvalidParameter
;
3644 FIXME("graphics object has no HDC\n");
3648 save_state
= prepare_dc(graphics
, pen
);
3649 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3651 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3653 restore_dc(graphics
, save_state
);
3658 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3659 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3661 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3662 width
, height
, startAngle
, sweepAngle
);
3664 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3667 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3668 REAL y
, REAL width
, REAL height
)
3674 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3676 if(!pen
|| !graphics
)
3677 return InvalidParameter
;
3684 FIXME("graphics object has no HDC\n");
3690 ptf
[1].X
= x
+ width
;
3692 ptf
[2].X
= x
+ width
;
3693 ptf
[2].Y
= y
+ height
;
3695 ptf
[3].Y
= y
+ height
;
3697 save_state
= prepare_dc(graphics
, pen
);
3698 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3700 transform_and_round_points(graphics
, pti
, ptf
, 4);
3701 Polygon(graphics
->hdc
, pti
, 4);
3703 restore_dc(graphics
, save_state
);
3708 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3709 INT y
, INT width
, INT height
)
3711 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3713 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3716 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3717 GDIPCONST GpRectF
* rects
, INT count
)
3723 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3725 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3726 return InvalidParameter
;
3733 FIXME("graphics object has no HDC\n");
3737 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
3738 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
3746 for(i
= 0; i
< count
; i
++){
3747 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
3748 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
3749 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
3750 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
3753 save_state
= prepare_dc(graphics
, pen
);
3754 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3756 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
3758 for(i
= 0; i
< count
; i
++)
3759 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
3761 restore_dc(graphics
, save_state
);
3769 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3770 GDIPCONST GpRect
* rects
, INT count
)
3776 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3778 if(!rects
|| count
<=0)
3779 return InvalidParameter
;
3781 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3785 for(i
= 0;i
< count
;i
++){
3786 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3787 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3788 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3789 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3792 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3798 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3799 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3804 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3805 count
, tension
, fill
);
3807 if(!graphics
|| !brush
|| !points
)
3808 return InvalidParameter
;
3813 if(count
== 1) /* Do nothing */
3816 stat
= GdipCreatePath(fill
, &path
);
3820 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3822 GdipDeletePath(path
);
3826 stat
= GdipFillPath(graphics
, brush
, path
);
3828 GdipDeletePath(path
);
3832 GdipDeletePath(path
);
3837 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3838 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3844 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3845 count
, tension
, fill
);
3847 if(!points
|| count
== 0)
3848 return InvalidParameter
;
3850 if(count
== 1) /* Do nothing */
3853 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3857 for(i
= 0;i
< count
;i
++){
3858 ptf
[i
].X
= (REAL
)points
[i
].X
;
3859 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3862 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3869 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3870 GDIPCONST GpPointF
*points
, INT count
)
3872 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3873 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3874 0.5f
, FillModeAlternate
);
3877 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3878 GDIPCONST GpPoint
*points
, INT count
)
3880 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3881 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3882 0.5f
, FillModeAlternate
);
3885 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3886 REAL y
, REAL width
, REAL height
)
3891 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3893 if(!graphics
|| !brush
)
3894 return InvalidParameter
;
3899 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3903 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3906 stat
= GdipFillPath(graphics
, brush
, path
);
3908 GdipDeletePath(path
);
3914 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3915 INT y
, INT width
, INT height
)
3917 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3919 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3922 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3927 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3928 return NotImplemented
;
3930 save_state
= SaveDC(graphics
->hdc
);
3931 EndPath(graphics
->hdc
);
3932 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3935 BeginPath(graphics
->hdc
);
3936 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3937 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3942 EndPath(graphics
->hdc
);
3943 brush_fill_path(graphics
, brush
);
3948 RestoreDC(graphics
->hdc
, save_state
);
3953 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3958 if (!brush_can_fill_pixels(brush
))
3959 return NotImplemented
;
3961 /* FIXME: This could probably be done more efficiently without regions. */
3963 stat
= GdipCreateRegionPath(path
, &rgn
);
3967 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3969 GdipDeleteRegion(rgn
);
3975 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3977 GpStatus stat
= NotImplemented
;
3979 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3981 if(!brush
|| !graphics
|| !path
)
3982 return InvalidParameter
;
3987 if (!graphics
->image
&& !graphics
->alpha_hdc
)
3988 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3990 if (stat
== NotImplemented
)
3991 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3993 if (stat
== NotImplemented
)
3995 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
4002 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4003 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4008 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
4009 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4011 if(!graphics
|| !brush
)
4012 return InvalidParameter
;
4017 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4021 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4024 stat
= GdipFillPath(graphics
, brush
, path
);
4026 GdipDeletePath(path
);
4032 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4033 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4035 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
4036 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4038 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4041 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
4042 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
4047 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4049 if(!graphics
|| !brush
|| !points
|| !count
)
4050 return InvalidParameter
;
4055 stat
= GdipCreatePath(fillMode
, &path
);
4059 stat
= GdipAddPathPolygon(path
, points
, count
);
4062 stat
= GdipFillPath(graphics
, brush
, path
);
4064 GdipDeletePath(path
);
4070 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4071 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4076 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4078 if(!graphics
|| !brush
|| !points
|| !count
)
4079 return InvalidParameter
;
4084 stat
= GdipCreatePath(fillMode
, &path
);
4088 stat
= GdipAddPathPolygonI(path
, points
, count
);
4091 stat
= GdipFillPath(graphics
, brush
, path
);
4093 GdipDeletePath(path
);
4099 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4100 GDIPCONST GpPointF
*points
, INT count
)
4102 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4104 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4107 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4108 GDIPCONST GpPoint
*points
, INT count
)
4110 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4112 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4115 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4116 REAL x
, REAL y
, REAL width
, REAL height
)
4121 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4123 if(!graphics
|| !brush
)
4124 return InvalidParameter
;
4129 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4133 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
4136 stat
= GdipFillPath(graphics
, brush
, path
);
4138 GdipDeletePath(path
);
4144 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4145 INT x
, INT y
, INT width
, INT height
)
4147 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4149 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
4152 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4158 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4161 return InvalidParameter
;
4163 for(i
= 0; i
< count
; i
++){
4164 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
4165 if(ret
!= Ok
) return ret
;
4171 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4178 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4180 if(!rects
|| count
<= 0)
4181 return InvalidParameter
;
4183 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
4187 for(i
= 0; i
< count
; i
++){
4188 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4189 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4190 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
4191 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4194 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4200 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4208 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
4209 return NotImplemented
;
4211 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4215 save_state
= SaveDC(graphics
->hdc
);
4216 EndPath(graphics
->hdc
);
4218 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4220 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4222 BeginPath(graphics
->hdc
);
4223 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4224 EndPath(graphics
->hdc
);
4226 brush_fill_path(graphics
, brush
);
4229 RestoreDC(graphics
->hdc
, save_state
);
4236 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4240 GpRegion
*temp_region
;
4241 GpMatrix world_to_device
;
4242 GpRectF graphics_bounds
;
4246 GpRect gp_bound_rect
;
4248 if (!brush_can_fill_pixels(brush
))
4249 return NotImplemented
;
4251 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
4254 stat
= GdipCloneRegion(region
, &temp_region
);
4258 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
4259 CoordinateSpaceWorld
, &world_to_device
);
4262 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4265 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4268 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4270 GdipDeleteRegion(temp_region
);
4273 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4275 DeleteObject(hregion
);
4281 gp_bound_rect
.X
= bound_rect
.left
;
4282 gp_bound_rect
.Y
= bound_rect
.top
;
4283 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4284 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4286 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4292 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4293 &gp_bound_rect
, gp_bound_rect
.Width
);
4296 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4297 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4298 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4300 GdipFree(pixel_data
);
4303 DeleteObject(hregion
);
4309 /*****************************************************************************
4310 * GdipFillRegion [GDIPLUS.@]
4312 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4315 GpStatus stat
= NotImplemented
;
4317 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4319 if (!(graphics
&& brush
&& region
))
4320 return InvalidParameter
;
4325 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4326 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4328 if (stat
== NotImplemented
)
4329 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4331 if (stat
== NotImplemented
)
4333 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4340 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4342 TRACE("(%p,%u)\n", graphics
, intention
);
4345 return InvalidParameter
;
4350 /* We have no internal operation queue, so there's no need to clear it. */
4358 /*****************************************************************************
4359 * GdipGetClipBounds [GDIPLUS.@]
4361 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4363 TRACE("(%p, %p)\n", graphics
, rect
);
4366 return InvalidParameter
;
4371 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4374 /*****************************************************************************
4375 * GdipGetClipBoundsI [GDIPLUS.@]
4377 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4379 TRACE("(%p, %p)\n", graphics
, rect
);
4382 return InvalidParameter
;
4387 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4390 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4391 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4392 CompositingMode
*mode
)
4394 TRACE("(%p, %p)\n", graphics
, mode
);
4396 if(!graphics
|| !mode
)
4397 return InvalidParameter
;
4402 *mode
= graphics
->compmode
;
4407 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4408 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4409 CompositingQuality
*quality
)
4411 TRACE("(%p, %p)\n", graphics
, quality
);
4413 if(!graphics
|| !quality
)
4414 return InvalidParameter
;
4419 *quality
= graphics
->compqual
;
4424 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4425 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4426 InterpolationMode
*mode
)
4428 TRACE("(%p, %p)\n", graphics
, mode
);
4430 if(!graphics
|| !mode
)
4431 return InvalidParameter
;
4436 *mode
= graphics
->interpolation
;
4441 /* FIXME: Need to handle color depths less than 24bpp */
4442 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4444 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4446 if(!graphics
|| !argb
)
4447 return InvalidParameter
;
4455 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4457 TRACE("(%p, %p)\n", graphics
, scale
);
4459 if(!graphics
|| !scale
)
4460 return InvalidParameter
;
4465 *scale
= graphics
->scale
;
4470 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4472 TRACE("(%p, %p)\n", graphics
, unit
);
4474 if(!graphics
|| !unit
)
4475 return InvalidParameter
;
4480 *unit
= graphics
->unit
;
4485 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4486 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4489 TRACE("(%p, %p)\n", graphics
, mode
);
4491 if(!graphics
|| !mode
)
4492 return InvalidParameter
;
4497 *mode
= graphics
->pixeloffset
;
4502 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4503 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4505 TRACE("(%p, %p)\n", graphics
, mode
);
4507 if(!graphics
|| !mode
)
4508 return InvalidParameter
;
4513 *mode
= graphics
->smoothing
;
4518 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4520 TRACE("(%p, %p)\n", graphics
, contrast
);
4522 if(!graphics
|| !contrast
)
4523 return InvalidParameter
;
4525 *contrast
= graphics
->textcontrast
;
4530 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4531 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4532 TextRenderingHint
*hint
)
4534 TRACE("(%p, %p)\n", graphics
, hint
);
4536 if(!graphics
|| !hint
)
4537 return InvalidParameter
;
4542 *hint
= graphics
->texthint
;
4547 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4552 TRACE("(%p, %p)\n", graphics
, rect
);
4554 if(!graphics
|| !rect
)
4555 return InvalidParameter
;
4560 /* intersect window and graphics clipping regions */
4561 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4564 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4567 /* get bounds of the region */
4568 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4571 GdipDeleteRegion(clip_rgn
);
4576 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4581 TRACE("(%p, %p)\n", graphics
, rect
);
4583 if(!graphics
|| !rect
)
4584 return InvalidParameter
;
4586 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4588 rect
->X
= gdip_round(rectf
.X
);
4589 rect
->Y
= gdip_round(rectf
.Y
);
4590 rect
->Width
= gdip_round(rectf
.Width
);
4591 rect
->Height
= gdip_round(rectf
.Height
);
4597 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4599 TRACE("(%p, %p)\n", graphics
, matrix
);
4601 if(!graphics
|| !matrix
)
4602 return InvalidParameter
;
4607 *matrix
= graphics
->worldtrans
;
4611 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4617 TRACE("(%p, %x)\n", graphics
, color
);
4620 return InvalidParameter
;
4625 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4628 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4629 GdipDeleteBrush((GpBrush
*)brush
);
4633 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4634 wnd_rect
.Width
, wnd_rect
.Height
);
4636 GdipDeleteBrush((GpBrush
*)brush
);
4641 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4643 TRACE("(%p, %p)\n", graphics
, res
);
4645 if(!graphics
|| !res
)
4646 return InvalidParameter
;
4648 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4651 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4657 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4659 if(!graphics
|| !result
)
4660 return InvalidParameter
;
4667 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4668 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4671 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4674 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4677 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4680 GdipDeleteRegion(rgn
);
4684 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4686 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4689 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4695 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4697 if(!graphics
|| !result
)
4698 return InvalidParameter
;
4705 pts
[1].X
= x
+ width
;
4706 pts
[1].Y
= y
+ height
;
4708 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4709 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4712 pts
[1].X
-= pts
[0].X
;
4713 pts
[1].Y
-= pts
[0].Y
;
4715 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4718 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4721 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4724 GdipDeleteRegion(rgn
);
4728 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4730 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4733 GpStatus
gdip_format_string(HDC hdc
,
4734 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4735 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4736 gdip_format_string_callback callback
, void *user_data
)
4739 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4740 nheight
, lineend
, lineno
= 0;
4742 StringAlignment halign
;
4745 HotkeyPrefix hkprefix
;
4746 INT
*hotkeyprefix_offsets
=NULL
;
4747 INT hotkeyprefix_count
=0;
4748 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4751 if(length
== -1) length
= lstrlenW(string
);
4753 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4754 if(!stringdup
) return OutOfMemory
;
4756 nwidth
= rect
->Width
;
4757 nheight
= rect
->Height
;
4760 hkprefix
= format
->hkprefix
;
4762 hkprefix
= HotkeyPrefixNone
;
4764 if (hkprefix
== HotkeyPrefixShow
)
4766 for (i
=0; i
<length
; i
++)
4768 if (string
[i
] == '&')
4769 hotkeyprefix_count
++;
4773 if (hotkeyprefix_count
)
4774 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4776 hotkeyprefix_count
= 0;
4778 for(i
= 0, j
= 0; i
< length
; i
++){
4779 /* FIXME: This makes the indexes passed to callback inaccurate. */
4780 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4783 /* FIXME: tabs should be handled using tabstops from stringformat */
4784 if (string
[i
] == '\t')
4787 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4788 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4789 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4797 stringdup
[j
] = string
[i
];
4803 if (format
) halign
= format
->align
;
4804 else halign
= StringAlignmentNear
;
4806 while(sum
< length
){
4807 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4808 nwidth
, &fit
, NULL
, &size
);
4814 for(lret
= 0; lret
< fit
; lret
++)
4815 if(*(stringdup
+ sum
+ lret
) == '\n')
4818 /* Line break code (may look strange, but it imitates windows). */
4820 lineend
= fit
= lret
; /* this is not an off-by-one error */
4821 else if(fit
< (length
- sum
)){
4822 if(*(stringdup
+ sum
+ fit
) == ' ')
4823 while(*(stringdup
+ sum
+ fit
) == ' ')
4826 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4829 if(*(stringdup
+ sum
+ fit
) == '\t')
4838 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4839 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4845 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4846 nwidth
, &j
, NULL
, &size
);
4848 bounds
.Width
= size
.cx
;
4850 if(height
+ size
.cy
> nheight
)
4851 bounds
.Height
= nheight
- (height
+ size
.cy
);
4853 bounds
.Height
= size
.cy
;
4855 bounds
.Y
= rect
->Y
+ height
;
4859 case StringAlignmentNear
:
4863 case StringAlignmentCenter
:
4864 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4866 case StringAlignmentFar
:
4867 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4871 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4872 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4875 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4876 font
, rect
, format
, lineno
, &bounds
,
4877 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4878 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4883 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4887 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4889 if(height
> nheight
)
4892 /* Stop if this was a linewrap (but not if it was a linebreak). */
4893 if ((lret
== fitcpy
) && format
&&
4894 (format
->attr
& (StringFormatFlagsNoWrap
| StringFormatFlagsLineLimit
)))
4898 GdipFree(stringdup
);
4899 GdipFree(hotkeyprefix_offsets
);
4904 struct measure_ranges_args
{
4906 REAL rel_width
, rel_height
;
4909 static GpStatus
measure_ranges_callback(HDC hdc
,
4910 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4911 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4912 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4913 INT underlined_index_count
, void *user_data
)
4917 struct measure_ranges_args
*args
= user_data
;
4919 for (i
=0; i
<format
->range_count
; i
++)
4921 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4922 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4923 if (range_start
< range_end
)
4928 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4929 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4931 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4932 INT_MAX
, NULL
, NULL
, &range_size
);
4933 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4935 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4936 INT_MAX
, NULL
, NULL
, &range_size
);
4937 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4939 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4948 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4949 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4950 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4951 INT regionCount
, GpRegion
** regions
)
4955 HFONT gdifont
, oldfont
;
4956 struct measure_ranges_args args
;
4957 HDC hdc
, temp_hdc
=NULL
;
4962 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4963 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4965 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4966 return InvalidParameter
;
4968 if (regionCount
< stringFormat
->range_count
)
4969 return InvalidParameter
;
4973 hdc
= temp_hdc
= CreateCompatibleDC(0);
4974 if (!temp_hdc
) return OutOfMemory
;
4977 hdc
= graphics
->hdc
;
4979 if (stringFormat
->attr
)
4980 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4988 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4989 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4990 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4991 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4992 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4994 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4995 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4997 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4998 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4999 if (stringFormat
->attr
& StringFormatFlagsNoClip
)
5001 scaled_rect
.Width
= (REAL
)(1 << 23);
5002 scaled_rect
.Height
= (REAL
)(1 << 23);
5006 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
5007 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
5009 if (scaled_rect
.Width
>= 0.5)
5011 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5012 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5015 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
5016 oldfont
= SelectObject(hdc
, gdifont
);
5018 for (i
=0; i
<stringFormat
->range_count
; i
++)
5020 stat
= GdipSetEmpty(regions
[i
]);
5025 args
.regions
= regions
;
5027 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
5028 measure_ranges_callback
, &args
);
5030 SelectObject(hdc
, oldfont
);
5031 DeleteObject(gdifont
);
5039 struct measure_string_args
{
5041 INT
*codepointsfitted
;
5043 REAL rel_width
, rel_height
;
5046 static GpStatus
measure_string_callback(HDC hdc
,
5047 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5048 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5049 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5050 INT underlined_index_count
, void *user_data
)
5052 struct measure_string_args
*args
= user_data
;
5053 REAL new_width
, new_height
;
5055 new_width
= bounds
->Width
/ args
->rel_width
;
5056 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
5058 if (new_width
> args
->bounds
->Width
)
5059 args
->bounds
->Width
= new_width
;
5061 if (new_height
> args
->bounds
->Height
)
5062 args
->bounds
->Height
= new_height
;
5064 if (args
->codepointsfitted
)
5065 *args
->codepointsfitted
= index
+ length
;
5067 if (args
->linesfilled
)
5068 (*args
->linesfilled
)++;
5073 /* Find the smallest rectangle that bounds the text when it is printed in rect
5074 * according to the format options listed in format. If rect has 0 width and
5075 * height, then just find the smallest rectangle that bounds the text when it's
5076 * printed at location (rect->X, rect-Y). */
5077 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
5078 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5079 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
5080 INT
*codepointsfitted
, INT
*linesfilled
)
5082 HFONT oldfont
, gdifont
;
5083 struct measure_string_args args
;
5084 HDC temp_hdc
=NULL
, hdc
;
5088 INT lines
, glyphs
, format_flags
= format
? format
->attr
: 0;
5090 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
5091 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
5092 bounds
, codepointsfitted
, linesfilled
);
5094 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
5095 return InvalidParameter
;
5099 hdc
= temp_hdc
= CreateCompatibleDC(0);
5100 if (!temp_hdc
) return OutOfMemory
;
5103 hdc
= graphics
->hdc
;
5105 if(linesfilled
) *linesfilled
= 0;
5106 if(codepointsfitted
) *codepointsfitted
= 0;
5109 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5117 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5118 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5119 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5120 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5121 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5123 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5124 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5126 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
5127 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
5128 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
5129 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
5131 if ((format_flags
& StringFormatFlagsNoClip
) ||
5132 scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5133 if ((format_flags
& StringFormatFlagsNoClip
) ||
5134 scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5136 if (scaled_rect
.Width
>= 0.5)
5138 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5139 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5142 if (scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5143 if (scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5145 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5146 oldfont
= SelectObject(hdc
, gdifont
);
5148 bounds
->X
= rect
->X
;
5149 bounds
->Y
= rect
->Y
;
5150 bounds
->Width
= 0.0;
5151 bounds
->Height
= 0.0;
5153 args
.bounds
= bounds
;
5154 args
.codepointsfitted
= &glyphs
;
5155 args
.linesfilled
= &lines
;
5158 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
5159 measure_string_callback
, &args
);
5161 if (linesfilled
) *linesfilled
= lines
;
5162 if (codepointsfitted
) *codepointsfitted
= glyphs
;
5165 bounds
->Width
+= margin_x
* 2.0;
5167 SelectObject(hdc
, oldfont
);
5168 DeleteObject(gdifont
);
5176 struct draw_string_args
{
5177 GpGraphics
*graphics
;
5178 GDIPCONST GpBrush
*brush
;
5179 REAL x
, y
, rel_width
, rel_height
, ascent
;
5182 static GpStatus
draw_string_callback(HDC hdc
,
5183 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5184 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5185 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5186 INT underlined_index_count
, void *user_data
)
5188 struct draw_string_args
*args
= user_data
;
5192 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5193 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5195 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
5196 args
->brush
, &position
,
5197 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5199 if (stat
== Ok
&& underlined_index_count
)
5201 OUTLINETEXTMETRICW otm
;
5202 REAL underline_y
, underline_height
;
5205 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5207 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5208 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5210 for (i
=0; i
<underlined_index_count
; i
++)
5212 REAL start_x
, end_x
;
5214 INT ofs
= underlined_indexes
[i
] - index
;
5216 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5217 start_x
= text_size
.cx
/ args
->rel_width
;
5219 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5220 end_x
= text_size
.cx
/ args
->rel_width
;
5222 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5229 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5230 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5231 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5235 GpPointF pt
[3], rectcpy
[4];
5237 REAL rel_width
, rel_height
, margin_x
;
5238 INT save_state
, format_flags
= 0;
5240 struct draw_string_args args
;
5242 HDC hdc
, temp_hdc
=NULL
;
5243 TEXTMETRICW textmetric
;
5245 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5246 length
, font
, debugstr_rectf(rect
), format
, brush
);
5248 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5249 return InvalidParameter
;
5253 hdc
= graphics
->hdc
;
5257 hdc
= temp_hdc
= CreateCompatibleDC(0);
5261 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5263 format_flags
= format
->attr
;
5265 /* Should be no need to explicitly test for StringAlignmentNear as
5266 * that is default behavior if no alignment is passed. */
5267 if(format
->vertalign
!= StringAlignmentNear
){
5268 RectF bounds
, in_rect
= *rect
;
5269 in_rect
.Height
= 0.0; /* avoid height clipping */
5270 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5272 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5274 if(format
->vertalign
== StringAlignmentCenter
)
5275 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5276 else if(format
->vertalign
== StringAlignmentFar
)
5277 offsety
= (rect
->Height
- bounds
.Height
);
5279 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
5282 save_state
= SaveDC(hdc
);
5290 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5291 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5292 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5293 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5294 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5296 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5297 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5298 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5299 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5300 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5302 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5303 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5305 scaled_rect
.X
= margin_x
* rel_width
;
5306 scaled_rect
.Y
= 0.0;
5307 scaled_rect
.Width
= rel_width
* rect
->Width
;
5308 scaled_rect
.Height
= rel_height
* rect
->Height
;
5310 if ((format_flags
& StringFormatFlagsNoClip
) ||
5311 scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5312 if ((format_flags
& StringFormatFlagsNoClip
) ||
5313 scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5315 if (scaled_rect
.Width
>= 0.5)
5317 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5318 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5321 if (scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5322 if (scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5324 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5325 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23)
5327 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5328 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5329 SelectClipRgn(hdc
, rgn
);
5332 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5333 SelectObject(hdc
, gdifont
);
5335 args
.graphics
= graphics
;
5339 args
.y
= rect
->Y
+ offsety
;
5341 args
.rel_width
= rel_width
;
5342 args
.rel_height
= rel_height
;
5344 GetTextMetricsW(hdc
, &textmetric
);
5345 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5347 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
5348 draw_string_callback
, &args
);
5351 DeleteObject(gdifont
);
5353 RestoreDC(hdc
, save_state
);
5360 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5362 TRACE("(%p)\n", graphics
);
5365 return InvalidParameter
;
5370 return GdipSetInfinite(graphics
->clip
);
5373 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5375 TRACE("(%p)\n", graphics
);
5378 return InvalidParameter
;
5383 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5386 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5388 return GdipEndContainer(graphics
, state
);
5391 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5392 GpMatrixOrder order
)
5394 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5397 return InvalidParameter
;
5402 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5405 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5407 return GdipBeginContainer2(graphics
, state
);
5410 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5411 GraphicsContainer
*state
)
5413 GraphicsContainerItem
*container
;
5416 TRACE("(%p, %p)\n", graphics
, state
);
5418 if(!graphics
|| !state
)
5419 return InvalidParameter
;
5421 sts
= init_container(&container
, graphics
);
5425 list_add_head(&graphics
->containers
, &container
->entry
);
5426 *state
= graphics
->contid
= container
->contid
;
5431 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5433 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5434 return NotImplemented
;
5437 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5439 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5440 return NotImplemented
;
5443 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5445 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5446 return NotImplemented
;
5449 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5452 GraphicsContainerItem
*container
, *container2
;
5454 TRACE("(%p, %x)\n", graphics
, state
);
5457 return InvalidParameter
;
5459 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5460 if(container
->contid
== state
)
5464 /* did not find a matching container */
5465 if(&container
->entry
== &graphics
->containers
)
5468 sts
= restore_container(graphics
, container
);
5472 /* remove all of the containers on top of the found container */
5473 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5474 if(container
->contid
== state
)
5476 list_remove(&container
->entry
);
5477 delete_container(container
);
5480 list_remove(&container
->entry
);
5481 delete_container(container
);
5486 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5487 REAL sy
, GpMatrixOrder order
)
5489 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5492 return InvalidParameter
;
5497 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5500 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5503 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5505 if(!graphics
|| !srcgraphics
)
5506 return InvalidParameter
;
5508 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5511 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5512 CompositingMode mode
)
5514 TRACE("(%p, %d)\n", graphics
, mode
);
5517 return InvalidParameter
;
5522 graphics
->compmode
= mode
;
5527 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5528 CompositingQuality quality
)
5530 TRACE("(%p, %d)\n", graphics
, quality
);
5533 return InvalidParameter
;
5538 graphics
->compqual
= quality
;
5543 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5544 InterpolationMode mode
)
5546 TRACE("(%p, %d)\n", graphics
, mode
);
5548 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5549 return InvalidParameter
;
5554 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5555 mode
= InterpolationModeBilinear
;
5557 if (mode
== InterpolationModeHighQuality
)
5558 mode
= InterpolationModeHighQualityBicubic
;
5560 graphics
->interpolation
= mode
;
5565 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5567 TRACE("(%p, %.2f)\n", graphics
, scale
);
5569 if(!graphics
|| (scale
<= 0.0))
5570 return InvalidParameter
;
5575 graphics
->scale
= scale
;
5580 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5582 TRACE("(%p, %d)\n", graphics
, unit
);
5585 return InvalidParameter
;
5590 if(unit
== UnitWorld
)
5591 return InvalidParameter
;
5593 graphics
->unit
= unit
;
5598 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5601 TRACE("(%p, %d)\n", graphics
, mode
);
5604 return InvalidParameter
;
5609 graphics
->pixeloffset
= mode
;
5614 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5618 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5621 FIXME("value is unused in rendering\n");
5624 return InvalidParameter
;
5626 graphics
->origin_x
= x
;
5627 graphics
->origin_y
= y
;
5632 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5634 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5636 if (!graphics
|| !x
|| !y
)
5637 return InvalidParameter
;
5639 *x
= graphics
->origin_x
;
5640 *y
= graphics
->origin_y
;
5645 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5647 TRACE("(%p, %d)\n", graphics
, mode
);
5650 return InvalidParameter
;
5655 graphics
->smoothing
= mode
;
5660 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5662 TRACE("(%p, %d)\n", graphics
, contrast
);
5665 return InvalidParameter
;
5667 graphics
->textcontrast
= contrast
;
5672 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5673 TextRenderingHint hint
)
5675 TRACE("(%p, %d)\n", graphics
, hint
);
5677 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5678 return InvalidParameter
;
5683 graphics
->texthint
= hint
;
5688 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5690 TRACE("(%p, %p)\n", graphics
, matrix
);
5692 if(!graphics
|| !matrix
)
5693 return InvalidParameter
;
5698 TRACE("%f,%f,%f,%f,%f,%f\n",
5699 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5700 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5702 graphics
->worldtrans
= *matrix
;
5707 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5708 REAL dy
, GpMatrixOrder order
)
5710 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5713 return InvalidParameter
;
5718 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5721 /*****************************************************************************
5722 * GdipSetClipHrgn [GDIPLUS.@]
5724 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5729 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5732 return InvalidParameter
;
5734 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5738 status
= GdipSetClipRegion(graphics
, region
, mode
);
5740 GdipDeleteRegion(region
);
5744 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5746 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5749 return InvalidParameter
;
5754 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5757 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5758 REAL width
, REAL height
,
5763 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5766 return InvalidParameter
;
5774 rect
.Height
= height
;
5776 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5779 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5780 INT width
, INT height
,
5783 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5786 return InvalidParameter
;
5791 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5794 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5797 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5799 if(!graphics
|| !region
)
5800 return InvalidParameter
;
5805 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5808 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5813 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5816 FIXME("not implemented\n");
5818 return NotImplemented
;
5821 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5827 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5829 if(!graphics
|| !pen
|| count
<=0)
5830 return InvalidParameter
;
5837 FIXME("graphics object has no HDC\n");
5841 pti
= GdipAlloc(sizeof(POINT
) * count
);
5843 save_state
= prepare_dc(graphics
, pen
);
5844 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5846 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5847 Polygon(graphics
->hdc
, pti
, count
);
5849 restore_dc(graphics
, save_state
);
5855 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5862 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5864 if(count
<=0) return InvalidParameter
;
5865 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5867 for(i
= 0;i
< count
; i
++){
5868 ptf
[i
].X
= (REAL
)points
[i
].X
;
5869 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5872 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5878 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5880 TRACE("(%p, %p)\n", graphics
, dpi
);
5882 if(!graphics
|| !dpi
)
5883 return InvalidParameter
;
5888 *dpi
= graphics
->xres
;
5892 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5894 TRACE("(%p, %p)\n", graphics
, dpi
);
5896 if(!graphics
|| !dpi
)
5897 return InvalidParameter
;
5902 *dpi
= graphics
->yres
;
5906 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5907 GpMatrixOrder order
)
5912 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5914 if(!graphics
|| !matrix
)
5915 return InvalidParameter
;
5920 m
= graphics
->worldtrans
;
5922 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5924 graphics
->worldtrans
= m
;
5929 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5930 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5932 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5936 TRACE("(%p, %p)\n", graphics
, hdc
);
5938 if(!graphics
|| !hdc
)
5939 return InvalidParameter
;
5944 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5946 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5948 else if (!graphics
->hdc
|| graphics
->alpha_hdc
||
5949 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5951 /* Create a fake HDC and fill it with a constant color. */
5955 BITMAPINFOHEADER bmih
;
5958 stat
= get_graphics_bounds(graphics
, &bounds
);
5962 graphics
->temp_hbitmap_width
= bounds
.Width
;
5963 graphics
->temp_hbitmap_height
= bounds
.Height
;
5965 bmih
.biSize
= sizeof(bmih
);
5966 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5967 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5969 bmih
.biBitCount
= 32;
5970 bmih
.biCompression
= BI_RGB
;
5971 bmih
.biSizeImage
= 0;
5972 bmih
.biXPelsPerMeter
= 0;
5973 bmih
.biYPelsPerMeter
= 0;
5975 bmih
.biClrImportant
= 0;
5977 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5978 (void**)&graphics
->temp_bits
, NULL
, 0);
5980 return GenericError
;
5982 temp_hdc
= CreateCompatibleDC(0);
5985 DeleteObject(hbitmap
);
5986 return GenericError
;
5989 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5990 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5992 SelectObject(temp_hdc
, hbitmap
);
5994 graphics
->temp_hbitmap
= hbitmap
;
5995 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5999 *hdc
= graphics
->hdc
;
6003 graphics
->busy
= TRUE
;
6008 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
6012 TRACE("(%p, %p)\n", graphics
, hdc
);
6014 if(!graphics
|| !hdc
|| !graphics
->busy
)
6015 return InvalidParameter
;
6017 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6019 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
6021 else if (graphics
->temp_hdc
== hdc
)
6026 /* Find the pixels that have changed, and mark them as opaque. */
6027 pos
= (DWORD
*)graphics
->temp_bits
;
6028 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6030 if (*pos
!= DC_BACKGROUND_KEY
)
6037 /* Write the changed pixels to the real target. */
6038 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
6039 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
6040 graphics
->temp_hbitmap_width
* 4);
6043 DeleteDC(graphics
->temp_hdc
);
6044 DeleteObject(graphics
->temp_hbitmap
);
6045 graphics
->temp_hdc
= NULL
;
6046 graphics
->temp_hbitmap
= NULL
;
6048 else if (hdc
!= graphics
->hdc
)
6050 stat
= InvalidParameter
;
6054 graphics
->busy
= FALSE
;
6059 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
6064 TRACE("(%p, %p)\n", graphics
, region
);
6066 if(!graphics
|| !region
)
6067 return InvalidParameter
;
6072 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
6075 /* free everything except root node and header */
6076 delete_element(®ion
->node
);
6077 memcpy(region
, clip
, sizeof(GpRegion
));
6083 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6084 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
6087 REAL scale_x
, scale_y
;
6089 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
6091 if (dst_space
!= src_space
)
6093 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
6094 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
6096 if(graphics
->unit
!= UnitDisplay
)
6098 scale_x
*= graphics
->scale
;
6099 scale_y
*= graphics
->scale
;
6102 /* transform from src_space to CoordinateSpacePage */
6105 case CoordinateSpaceWorld
:
6106 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
6108 case CoordinateSpacePage
:
6110 case CoordinateSpaceDevice
:
6111 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
6115 /* transform from CoordinateSpacePage to dst_space */
6118 case CoordinateSpaceWorld
:
6120 GpMatrix inverted_transform
= graphics
->worldtrans
;
6121 stat
= GdipInvertMatrix(&inverted_transform
);
6123 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
6126 case CoordinateSpacePage
:
6128 case CoordinateSpaceDevice
:
6129 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
6136 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6137 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6142 if(!graphics
|| !points
|| count
<= 0)
6143 return InvalidParameter
;
6148 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6150 if (src_space
== dst_space
) return Ok
;
6152 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6153 if (stat
!= Ok
) return stat
;
6155 return GdipTransformMatrixPoints(&matrix
, points
, count
);
6158 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6159 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6165 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6168 return InvalidParameter
;
6170 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
6174 for(i
= 0; i
< count
; i
++){
6175 pointsF
[i
].X
= (REAL
)points
[i
].X
;
6176 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
6179 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6182 for(i
= 0; i
< count
; i
++){
6183 points
[i
].X
= gdip_round(pointsF
[i
].X
);
6184 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
6191 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6203 /*****************************************************************************
6204 * GdipTranslateClip [GDIPLUS.@]
6206 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6208 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6211 return InvalidParameter
;
6216 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6219 /*****************************************************************************
6220 * GdipTranslateClipI [GDIPLUS.@]
6222 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6224 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6227 return InvalidParameter
;
6232 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6236 /*****************************************************************************
6237 * GdipMeasureDriverString [GDIPLUS.@]
6239 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6240 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6241 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6243 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6246 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6248 TEXTMETRICW textmetric
;
6249 const WORD
*glyph_indices
;
6250 WORD
*dynamic_glyph_indices
=NULL
;
6251 REAL rel_width
, rel_height
, ascent
, descent
;
6254 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6256 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6257 return InvalidParameter
;
6260 length
= strlenW(text
);
6264 boundingBox
->X
= 0.0;
6265 boundingBox
->Y
= 0.0;
6266 boundingBox
->Width
= 0.0;
6267 boundingBox
->Height
= 0.0;
6270 if (flags
& unsupported_flags
)
6271 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6273 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6275 hdc
= CreateCompatibleDC(0);
6276 SelectObject(hdc
, hfont
);
6278 GetTextMetricsW(hdc
, &textmetric
);
6288 GpMatrix xform
= *matrix
;
6289 GdipTransformMatrixPoints(&xform
, pt
, 3);
6291 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6292 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6293 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6294 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6295 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6297 if (flags
& DriverStringOptionsCmapLookup
)
6299 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6303 DeleteObject(hfont
);
6307 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6310 glyph_indices
= text
;
6312 min_x
= max_x
= x
= positions
[0].X
;
6313 min_y
= max_y
= y
= positions
[0].Y
;
6315 ascent
= textmetric
.tmAscent
/ rel_height
;
6316 descent
= textmetric
.tmDescent
/ rel_height
;
6318 for (i
=0; i
<length
; i
++)
6323 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6329 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6330 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6332 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6333 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6334 if (min_x
> x
) min_x
= x
;
6336 x
+= char_width
/ rel_width
;
6338 if (max_x
< x
) max_x
= x
;
6341 GdipFree(dynamic_glyph_indices
);
6343 DeleteObject(hfont
);
6345 boundingBox
->X
= min_x
;
6346 boundingBox
->Y
= min_y
;
6347 boundingBox
->Width
= max_x
- min_x
;
6348 boundingBox
->Height
= max_y
- min_y
;
6353 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6354 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6355 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6356 INT flags
, GDIPCONST GpMatrix
*matrix
)
6358 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6364 if (flags
& unsupported_flags
)
6365 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6367 if (!(flags
& DriverStringOptionsCmapLookup
))
6368 eto_flags
|= ETO_GLYPH_INDEX
;
6370 save_state
= SaveDC(graphics
->hdc
);
6371 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6372 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6375 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6377 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6378 SelectObject(graphics
->hdc
, hfont
);
6380 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6382 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6384 RestoreDC(graphics
->hdc
, save_state
);
6386 DeleteObject(hfont
);
6391 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6392 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6393 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6394 INT flags
, GDIPCONST GpMatrix
*matrix
)
6396 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6398 PointF
*real_positions
, real_position
;
6402 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6403 DWORD max_glyphsize
=0;
6404 GLYPHMETRICS glyphmetrics
;
6405 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6408 int text_mask_stride
;
6410 int pixel_data_stride
;
6412 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6417 if (!(flags
& DriverStringOptionsCmapLookup
))
6418 ggo_flags
|= GGO_GLYPH_INDEX
;
6420 if (flags
& unsupported_flags
)
6421 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6423 pti
= GdipAlloc(sizeof(POINT
) * length
);
6427 if (flags
& DriverStringOptionsRealizedAdvance
)
6429 real_position
= positions
[0];
6431 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6435 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6436 if (!real_positions
)
6442 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6444 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6446 GdipFree(real_positions
);
6449 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6451 hdc
= CreateCompatibleDC(0);
6452 SelectObject(hdc
, hfont
);
6454 /* Get the boundaries of the text to be drawn */
6455 for (i
=0; i
<length
; i
++)
6458 int left
, top
, right
, bottom
;
6460 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6461 &glyphmetrics
, 0, NULL
, &identity
);
6463 if (glyphsize
== GDI_ERROR
)
6465 ERR("GetGlyphOutlineW failed\n");
6468 DeleteObject(hfont
);
6469 return GenericError
;
6472 if (glyphsize
> max_glyphsize
)
6473 max_glyphsize
= glyphsize
;
6475 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6476 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6477 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6478 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6480 if (left
< min_x
) min_x
= left
;
6481 if (top
< min_y
) min_y
= top
;
6482 if (right
> max_x
) max_x
= right
;
6483 if (bottom
> max_y
) max_y
= bottom
;
6485 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6487 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6488 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6492 glyph_mask
= GdipAlloc(max_glyphsize
);
6493 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6494 text_mask_stride
= max_x
- min_x
;
6496 if (!(glyph_mask
&& text_mask
))
6498 GdipFree(glyph_mask
);
6499 GdipFree(text_mask
);
6502 DeleteObject(hfont
);
6506 /* Generate a mask for the text */
6507 for (i
=0; i
<length
; i
++)
6509 int left
, top
, stride
;
6511 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6512 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6514 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6515 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6516 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6518 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6520 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6521 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6522 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6524 *text_val
= min(64, *text_val
+ *glyph_val
);
6533 DeleteObject(hfont
);
6534 GdipFree(glyph_mask
);
6536 /* get the brush data */
6537 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6540 GdipFree(text_mask
);
6544 pixel_area
.X
= min_x
;
6545 pixel_area
.Y
= min_y
;
6546 pixel_area
.Width
= max_x
- min_x
;
6547 pixel_area
.Height
= max_y
- min_y
;
6548 pixel_data_stride
= pixel_area
.Width
* 4;
6550 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6553 GdipFree(text_mask
);
6554 GdipFree(pixel_data
);
6558 /* multiply the brush data by the mask */
6559 for (y
=0; y
<pixel_area
.Height
; y
++)
6561 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6562 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6563 for (x
=0; x
<pixel_area
.Width
; x
++)
6565 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6571 GdipFree(text_mask
);
6573 /* draw the result */
6574 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6575 pixel_area
.Height
, pixel_data_stride
);
6577 GdipFree(pixel_data
);
6582 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6583 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6584 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6585 INT flags
, GDIPCONST GpMatrix
*matrix
)
6587 GpStatus stat
= NotImplemented
;
6590 length
= strlenW(text
);
6592 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6593 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6594 brush
->bt
== BrushTypeSolidColor
&&
6595 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6596 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6597 brush
, positions
, flags
, matrix
);
6598 if (stat
== NotImplemented
)
6599 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6600 brush
, positions
, flags
, matrix
);
6604 /*****************************************************************************
6605 * GdipDrawDriverString [GDIPLUS.@]
6607 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6608 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6609 GDIPCONST PointF
*positions
, INT flags
,
6610 GDIPCONST GpMatrix
*matrix
)
6612 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6614 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6615 return InvalidParameter
;
6617 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6618 brush
, positions
, flags
, matrix
);
6621 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6622 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6624 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6625 return NotImplemented
;
6628 /*****************************************************************************
6629 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6631 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6636 TRACE("(%p, %p)\n", graphics
, res
);
6638 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6641 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6644 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6647 GdipDeleteRegion(rgn
);
6651 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6655 TRACE("(%p) stub\n", graphics
);
6658 FIXME("not implemented\n");
6660 return NotImplemented
;