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 from gdiplus path point type to gdi path point type. */
55 static BYTE
convert_path_point_type(BYTE type
)
59 switch(type
& PathPointTypePathTypeMask
){
60 case PathPointTypeBezier
:
63 case PathPointTypeLine
:
66 case PathPointTypeStart
:
70 ERR("Bad point type\n");
74 if(type
& PathPointTypeCloseSubpath
)
75 ret
|= PT_CLOSEFIGURE
;
80 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
86 case BrushTypeSolidColor
:
88 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
92 case BrushTypeHatchFill
:
94 const GpHatch
*hatch
= (const GpHatch
*)brush
;
95 argb
= hatch
->forecol
;
98 case BrushTypeLinearGradient
:
100 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
101 argb
= line
->startcolor
;
104 case BrushTypePathGradient
:
106 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
107 argb
= grad
->centercolor
;
111 FIXME("unhandled brush type %d\n", brush
->bt
);
115 return ARGB2COLORREF(argb
);
118 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
121 BITMAPINFOHEADER bmih
;
125 bmih
.biSize
= sizeof(bmih
);
129 bmih
.biBitCount
= 32;
130 bmih
.biCompression
= BI_RGB
;
131 bmih
.biSizeImage
= 0;
133 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
136 const char *hatch_data
;
138 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
140 for (y
= 0; y
< 8; y
++)
142 for (x
= 0; x
< 8; x
++)
144 if (hatch_data
[y
] & (0x80 >> x
))
145 bits
[y
* 8 + x
] = hatch
->forecol
;
147 bits
[y
* 8 + x
] = hatch
->backcol
;
153 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
155 for (y
= 0; y
< 64; y
++)
156 bits
[y
] = hatch
->forecol
;
163 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
167 case BrushTypeSolidColor
:
169 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
170 lb
->lbStyle
= BS_SOLID
;
171 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
176 case BrushTypeHatchFill
:
178 const GpHatch
*hatch
= (const GpHatch
*)brush
;
181 hbmp
= create_hatch_bitmap(hatch
);
182 if (!hbmp
) return OutOfMemory
;
184 lb
->lbStyle
= BS_PATTERN
;
186 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
191 FIXME("unhandled brush type %d\n", brush
->bt
);
192 lb
->lbStyle
= BS_SOLID
;
193 lb
->lbColor
= get_gdi_brush_color(brush
);
199 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
204 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
210 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
215 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
217 gdibrush
= CreateBrushIndirect(&lb
);
218 free_gdi_logbrush(&lb
);
223 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
228 INT save_state
, i
, numdashes
;
230 DWORD dash_array
[MAX_DASHLEN
];
232 save_state
= SaveDC(graphics
->hdc
);
234 EndPath(graphics
->hdc
);
236 if(pen
->unit
== UnitPixel
){
240 /* Get an estimate for the amount the pen width is affected by the world
241 * transform. (This is similar to what some of the wine drivers do.) */
246 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
247 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
248 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
250 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
253 if(pen
->dash
== DashStyleCustom
){
254 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
256 TRACE("dashes are: ");
257 for(i
= 0; i
< numdashes
; i
++){
258 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
259 TRACE("%d, ", dash_array
[i
]);
261 TRACE("\n and the pen style is %x\n", pen
->style
);
263 create_gdi_logbrush(pen
->brush
, &lb
);
264 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
265 numdashes
, dash_array
);
266 free_gdi_logbrush(&lb
);
270 create_gdi_logbrush(pen
->brush
, &lb
);
271 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
272 free_gdi_logbrush(&lb
);
275 SelectObject(graphics
->hdc
, gdipen
);
280 static void restore_dc(GpGraphics
*graphics
, INT state
)
282 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
283 RestoreDC(graphics
->hdc
, state
);
286 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
287 GpCoordinateSpace src_space
, GpMatrix
*matrix
);
289 /* This helper applies all the changes that the points listed in ptf need in
290 * order to be drawn on the device context. In the end, this should include at
292 * -scaling by page unit
293 * -applying world transformation
294 * -converting from float to int
295 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
296 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
297 * gdi to draw, and these functions would irreparably mess with line widths.
299 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
300 GpPointF
*ptf
, INT count
)
302 REAL scale_x
, scale_y
;
306 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
307 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
309 /* apply page scale */
310 if(graphics
->unit
!= UnitDisplay
)
312 scale_x
*= graphics
->scale
;
313 scale_y
*= graphics
->scale
;
316 matrix
= graphics
->worldtrans
;
317 GdipScaleMatrix(&matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
318 GdipTransformMatrixPoints(&matrix
, ptf
, count
);
320 for(i
= 0; i
< count
; i
++){
321 pti
[i
].x
= gdip_round(ptf
[i
].X
);
322 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
326 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
327 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
329 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
331 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
333 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
334 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
340 bf
.BlendOp
= AC_SRC_OVER
;
342 bf
.SourceConstantAlpha
= 255;
343 bf
.AlphaFormat
= AC_SRC_ALPHA
;
345 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
346 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
350 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
352 return GdipGetRegionHRgn(graphics
->clip
, NULL
, hrgn
);
355 /* Draw non-premultiplied ARGB data to the given graphics object */
356 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
357 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
359 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
362 for (x
=0; x
<src_width
; x
++)
364 for (y
=0; y
<src_height
; y
++)
366 ARGB dst_color
, src_color
;
367 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
368 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
369 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
376 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
377 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
381 BITMAPINFOHEADER bih
;
384 hdc
= CreateCompatibleDC(0);
386 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
387 bih
.biWidth
= src_width
;
388 bih
.biHeight
= -src_height
;
391 bih
.biCompression
= BI_RGB
;
393 bih
.biXPelsPerMeter
= 0;
394 bih
.biYPelsPerMeter
= 0;
396 bih
.biClrImportant
= 0;
398 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
399 (void**)&temp_bits
, NULL
, 0);
401 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
402 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
404 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
405 4 * src_width
, src
, src_stride
);
407 SelectObject(hdc
, hbitmap
);
408 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
409 hdc
, 0, 0, src_width
, src_height
);
411 DeleteObject(hbitmap
);
416 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
417 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
)
421 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
427 HRGN hrgn
, visible_rgn
;
429 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
433 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
442 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
443 DeleteObject(visible_rgn
);
447 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
449 size
= GetRegionData(hrgn
, 0, NULL
);
451 rgndata
= GdipAlloc(size
);
458 GetRegionData(hrgn
, size
, rgndata
);
460 rects
= (RECT
*)rgndata
->Buffer
;
462 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
464 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
465 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
466 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
476 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
478 ERR("This should not be used for metafiles; fix caller\n");
479 return NotImplemented
;
486 stat
= get_clip_hrgn(graphics
, &hrgn
);
491 save
= SaveDC(graphics
->hdc
);
494 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
497 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
499 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
500 src_height
, src_stride
);
502 RestoreDC(graphics
->hdc
, save
);
510 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
511 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
513 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
);
516 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
522 a1
= (start
>> 24) & 0xff;
523 a2
= (end
>> 24) & 0xff;
525 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
529 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
530 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
534 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
538 /* clamp to between 0.0 and 1.0, using the wrap mode */
539 if (brush
->wrap
== WrapModeTile
)
541 position
= fmodf(position
, 1.0f
);
542 if (position
< 0.0f
) position
+= 1.0f
;
544 else /* WrapModeFlip* */
546 position
= fmodf(position
, 2.0f
);
547 if (position
< 0.0f
) position
+= 2.0f
;
548 if (position
> 1.0f
) position
= 2.0f
- position
;
551 if (brush
->blendcount
== 1)
556 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
559 /* locate the blend positions surrounding this position */
560 while (position
> brush
->blendpos
[i
])
563 /* interpolate between the blend positions */
564 left_blendpos
= brush
->blendpos
[i
-1];
565 left_blendfac
= brush
->blendfac
[i
-1];
566 right_blendpos
= brush
->blendpos
[i
];
567 right_blendfac
= brush
->blendfac
[i
];
568 range
= right_blendpos
- left_blendpos
;
569 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
570 right_blendfac
* (position
- left_blendpos
)) / range
;
573 if (brush
->pblendcount
== 0)
574 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
578 ARGB left_blendcolor
, right_blendcolor
;
579 REAL left_blendpos
, right_blendpos
;
581 /* locate the blend colors surrounding this position */
582 while (blendfac
> brush
->pblendpos
[i
])
585 /* interpolate between the blend colors */
586 left_blendpos
= brush
->pblendpos
[i
-1];
587 left_blendcolor
= brush
->pblendcolor
[i
-1];
588 right_blendpos
= brush
->pblendpos
[i
];
589 right_blendcolor
= brush
->pblendcolor
[i
];
590 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
591 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
595 static ARGB
transform_color(ARGB color
, const ColorMatrix
*matrix
)
599 unsigned char a
, r
, g
, b
;
601 val
[0] = ((color
>> 16) & 0xff) / 255.0; /* red */
602 val
[1] = ((color
>> 8) & 0xff) / 255.0; /* green */
603 val
[2] = (color
& 0xff) / 255.0; /* blue */
604 val
[3] = ((color
>> 24) & 0xff) / 255.0; /* alpha */
605 val
[4] = 1.0; /* translation */
612 res
[i
] += matrix
->m
[j
][i
] * val
[j
];
615 a
= min(max(floorf(res
[3]*255.0), 0.0), 255.0);
616 r
= min(max(floorf(res
[0]*255.0), 0.0), 255.0);
617 g
= min(max(floorf(res
[1]*255.0), 0.0), 255.0);
618 b
= min(max(floorf(res
[2]*255.0), 0.0), 255.0);
620 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
623 static int color_is_gray(ARGB color
)
625 unsigned char r
, g
, b
;
627 r
= (color
>> 16) & 0xff;
628 g
= (color
>> 8) & 0xff;
631 return (r
== g
) && (g
== b
);
634 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
635 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
640 if (attributes
->colorkeys
[type
].enabled
||
641 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
643 const struct color_key
*key
;
644 BYTE min_blue
, min_green
, min_red
;
645 BYTE max_blue
, max_green
, max_red
;
647 if (attributes
->colorkeys
[type
].enabled
)
648 key
= &attributes
->colorkeys
[type
];
650 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
652 min_blue
= key
->low
&0xff;
653 min_green
= (key
->low
>>8)&0xff;
654 min_red
= (key
->low
>>16)&0xff;
656 max_blue
= key
->high
&0xff;
657 max_green
= (key
->high
>>8)&0xff;
658 max_red
= (key
->high
>>16)&0xff;
660 for (x
=0; x
<width
; x
++)
661 for (y
=0; y
<height
; y
++)
664 BYTE blue
, green
, red
;
665 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
666 blue
= *src_color
&0xff;
667 green
= (*src_color
>>8)&0xff;
668 red
= (*src_color
>>16)&0xff;
669 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
670 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
671 *src_color
= 0x00000000;
675 if (attributes
->colorremaptables
[type
].enabled
||
676 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
678 const struct color_remap_table
*table
;
680 if (attributes
->colorremaptables
[type
].enabled
)
681 table
= &attributes
->colorremaptables
[type
];
683 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
685 for (x
=0; x
<width
; x
++)
686 for (y
=0; y
<height
; y
++)
689 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
690 for (i
=0; i
<table
->mapsize
; i
++)
692 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
694 *src_color
= table
->colormap
[i
].newColor
.Argb
;
701 if (attributes
->colormatrices
[type
].enabled
||
702 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
704 const struct color_matrix
*colormatrices
;
706 if (attributes
->colormatrices
[type
].enabled
)
707 colormatrices
= &attributes
->colormatrices
[type
];
709 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
711 for (x
=0; x
<width
; x
++)
712 for (y
=0; y
<height
; y
++)
715 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
717 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
718 !color_is_gray(*src_color
))
720 *src_color
= transform_color(*src_color
, &colormatrices
->colormatrix
);
722 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
724 *src_color
= transform_color(*src_color
, &colormatrices
->graymatrix
);
729 if (attributes
->gamma_enabled
[type
] ||
730 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
734 if (attributes
->gamma_enabled
[type
])
735 gamma
= attributes
->gamma
[type
];
737 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
739 for (x
=0; x
<width
; x
++)
740 for (y
=0; y
<height
; y
++)
743 BYTE blue
, green
, red
;
744 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
746 blue
= *src_color
&0xff;
747 green
= (*src_color
>>8)&0xff;
748 red
= (*src_color
>>16)&0xff;
750 /* FIXME: We should probably use a table for this. */
751 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
752 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
753 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
755 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
760 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
761 * bitmap that contains all the pixels we may need to draw it. */
762 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
763 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
766 INT left
, top
, right
, bottom
;
768 switch (interpolation
)
770 case InterpolationModeHighQualityBilinear
:
771 case InterpolationModeHighQualityBicubic
:
772 /* FIXME: Include a greater range for the prefilter? */
773 case InterpolationModeBicubic
:
774 case InterpolationModeBilinear
:
775 left
= (INT
)(floorf(srcx
));
776 top
= (INT
)(floorf(srcy
));
777 right
= (INT
)(ceilf(srcx
+srcwidth
));
778 bottom
= (INT
)(ceilf(srcy
+srcheight
));
780 case InterpolationModeNearestNeighbor
:
782 left
= gdip_round(srcx
);
783 top
= gdip_round(srcy
);
784 right
= gdip_round(srcx
+srcwidth
);
785 bottom
= gdip_round(srcy
+srcheight
);
789 if (wrap
== WrapModeClamp
)
795 if (right
>= bitmap
->width
)
796 right
= bitmap
->width
-1;
797 if (bottom
>= bitmap
->height
)
798 bottom
= bitmap
->height
-1;
802 /* In some cases we can make the rectangle smaller here, but the logic
803 * is hard to get right, and tiling suggests we're likely to use the
804 * entire source image. */
805 if (left
< 0 || right
>= bitmap
->width
)
808 right
= bitmap
->width
-1;
811 if (top
< 0 || bottom
>= bitmap
->height
)
814 bottom
= bitmap
->height
-1;
820 rect
->Width
= right
- left
+ 1;
821 rect
->Height
= bottom
- top
+ 1;
824 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
825 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
827 if (attributes
->wrap
== WrapModeClamp
)
829 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
830 return attributes
->outside_color
;
834 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
836 x
= width
*2 + x
% (width
* 2);
838 y
= height
*2 + y
% (height
* 2);
840 if ((attributes
->wrap
& 1) == 1)
843 if ((x
/ width
) % 2 == 0)
846 x
= width
- 1 - x
% width
;
851 if ((attributes
->wrap
& 2) == 2)
854 if ((y
/ height
) % 2 == 0)
857 y
= height
- 1 - y
% height
;
863 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
865 ERR("out of range pixel requested\n");
869 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
872 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
873 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
874 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
878 switch (interpolation
)
882 FIXME("Unimplemented interpolation %i\n", interpolation
);
884 case InterpolationModeBilinear
:
887 INT leftx
, rightx
, topy
, bottomy
;
888 ARGB topleft
, topright
, bottomleft
, bottomright
;
892 leftxf
= floorf(point
->X
);
894 rightx
= (INT
)ceilf(point
->X
);
895 topyf
= floorf(point
->Y
);
897 bottomy
= (INT
)ceilf(point
->Y
);
899 if (leftx
== rightx
&& topy
== bottomy
)
900 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
901 leftx
, topy
, attributes
);
903 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
904 leftx
, topy
, attributes
);
905 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
906 rightx
, topy
, attributes
);
907 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
908 leftx
, bottomy
, attributes
);
909 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
910 rightx
, bottomy
, attributes
);
912 x_offset
= point
->X
- leftxf
;
913 top
= blend_colors(topleft
, topright
, x_offset
);
914 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
916 return blend_colors(top
, bottom
, point
->Y
- topyf
);
918 case InterpolationModeNearestNeighbor
:
924 case PixelOffsetModeNone
:
925 case PixelOffsetModeHighSpeed
:
929 case PixelOffsetModeHalf
:
930 case PixelOffsetModeHighQuality
:
934 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
935 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
941 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
943 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
946 static INT
brush_can_fill_path(GpBrush
*brush
)
950 case BrushTypeSolidColor
:
952 case BrushTypeHatchFill
:
954 GpHatch
*hatch
= (GpHatch
*)brush
;
955 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
956 ((hatch
->backcol
& 0xff000000) == 0xff000000);
958 case BrushTypeLinearGradient
:
959 case BrushTypeTextureFill
:
960 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
966 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
970 case BrushTypeSolidColor
:
972 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
973 HBITMAP bmp
= ARGB2BMP(fill
->color
);
978 /* partially transparent fill */
980 SelectClipPath(graphics
->hdc
, RGN_AND
);
981 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
983 HDC hdc
= CreateCompatibleDC(NULL
);
987 SelectObject(hdc
, bmp
);
988 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
996 /* else fall through */
1000 HBRUSH gdibrush
, old_brush
;
1002 gdibrush
= create_gdi_brush(brush
);
1003 if (!gdibrush
) return;
1005 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1006 FillPath(graphics
->hdc
);
1007 SelectObject(graphics
->hdc
, old_brush
);
1008 DeleteObject(gdibrush
);
1014 static INT
brush_can_fill_pixels(GpBrush
*brush
)
1018 case BrushTypeSolidColor
:
1019 case BrushTypeHatchFill
:
1020 case BrushTypeLinearGradient
:
1021 case BrushTypeTextureFill
:
1022 case BrushTypePathGradient
:
1029 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1030 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1034 case BrushTypeSolidColor
:
1037 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1038 for (x
=0; x
<fill_area
->Width
; x
++)
1039 for (y
=0; y
<fill_area
->Height
; y
++)
1040 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1043 case BrushTypeHatchFill
:
1046 GpHatch
*fill
= (GpHatch
*)brush
;
1047 const char *hatch_data
;
1049 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1050 return NotImplemented
;
1052 for (x
=0; x
<fill_area
->Width
; x
++)
1053 for (y
=0; y
<fill_area
->Height
; y
++)
1057 /* FIXME: Account for the rendering origin */
1058 hx
= (x
+ fill_area
->X
) % 8;
1059 hy
= (y
+ fill_area
->Y
) % 8;
1061 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1062 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1064 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1069 case BrushTypeLinearGradient
:
1071 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1072 GpPointF draw_points
[3], line_points
[3];
1074 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1075 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1078 draw_points
[0].X
= fill_area
->X
;
1079 draw_points
[0].Y
= fill_area
->Y
;
1080 draw_points
[1].X
= fill_area
->X
+1;
1081 draw_points
[1].Y
= fill_area
->Y
;
1082 draw_points
[2].X
= fill_area
->X
;
1083 draw_points
[2].Y
= fill_area
->Y
+1;
1085 /* Transform the points to a co-ordinate space where X is the point's
1086 * position in the gradient, 0.0 being the start point and 1.0 the
1088 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1089 CoordinateSpaceDevice
, draw_points
, 3);
1093 line_points
[0] = fill
->startpoint
;
1094 line_points
[1] = fill
->endpoint
;
1095 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1096 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1098 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1103 stat
= GdipInvertMatrix(world_to_gradient
);
1106 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1108 GdipDeleteMatrix(world_to_gradient
);
1113 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1114 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1116 for (y
=0; y
<fill_area
->Height
; y
++)
1118 for (x
=0; x
<fill_area
->Width
; x
++)
1120 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1122 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1129 case BrushTypeTextureFill
:
1131 GpTexture
*fill
= (GpTexture
*)brush
;
1132 GpPointF draw_points
[3];
1139 if (fill
->image
->type
!= ImageTypeBitmap
)
1141 FIXME("metafile texture brushes not implemented\n");
1142 return NotImplemented
;
1145 bitmap
= (GpBitmap
*)fill
->image
;
1146 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1148 src_area
.X
= src_area
.Y
= 0;
1149 src_area
.Width
= bitmap
->width
;
1150 src_area
.Height
= bitmap
->height
;
1152 draw_points
[0].X
= fill_area
->X
;
1153 draw_points
[0].Y
= fill_area
->Y
;
1154 draw_points
[1].X
= fill_area
->X
+1;
1155 draw_points
[1].Y
= fill_area
->Y
;
1156 draw_points
[2].X
= fill_area
->X
;
1157 draw_points
[2].Y
= fill_area
->Y
+1;
1159 /* Transform the points to the co-ordinate space of the bitmap. */
1160 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1161 CoordinateSpaceDevice
, draw_points
, 3);
1165 GpMatrix world_to_texture
= fill
->transform
;
1167 stat
= GdipInvertMatrix(&world_to_texture
);
1169 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1172 if (stat
== Ok
&& !fill
->bitmap_bits
)
1174 BitmapData lockeddata
;
1176 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1177 if (!fill
->bitmap_bits
)
1182 lockeddata
.Width
= bitmap
->width
;
1183 lockeddata
.Height
= bitmap
->height
;
1184 lockeddata
.Stride
= src_stride
;
1185 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1186 lockeddata
.Scan0
= fill
->bitmap_bits
;
1188 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1189 PixelFormat32bppARGB
, &lockeddata
);
1193 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1196 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1197 bitmap
->width
, bitmap
->height
,
1198 src_stride
, ColorAdjustTypeBitmap
);
1202 GdipFree(fill
->bitmap_bits
);
1203 fill
->bitmap_bits
= NULL
;
1209 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1210 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1211 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1212 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1214 for (y
=0; y
<fill_area
->Height
; y
++)
1216 for (x
=0; x
<fill_area
->Width
; x
++)
1219 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1220 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1222 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1223 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1224 &point
, fill
->imageattributes
, graphics
->interpolation
,
1225 graphics
->pixeloffset
);
1232 case BrushTypePathGradient
:
1234 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1236 GpMatrix world_to_device
;
1238 int i
, figure_start
=0;
1239 GpPointF start_point
, end_point
, center_point
;
1241 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1242 INT min_y
, max_y
, min_x
, max_x
;
1245 static int transform_fixme_once
;
1247 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1251 FIXME("path gradient focus not implemented\n");
1258 FIXME("path gradient gamma correction not implemented\n");
1261 if (fill
->blendcount
)
1265 FIXME("path gradient blend not implemented\n");
1268 if (fill
->pblendcount
)
1272 FIXME("path gradient preset blend not implemented\n");
1275 if (!transform_fixme_once
)
1277 BOOL is_identity
=TRUE
;
1278 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1281 FIXME("path gradient transform not implemented\n");
1282 transform_fixme_once
= 1;
1286 stat
= GdipClonePath(fill
->path
, &flat_path
);
1291 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1292 CoordinateSpaceWorld
, &world_to_device
);
1295 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1299 center_point
= fill
->center
;
1300 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1304 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1309 GdipDeletePath(flat_path
);
1313 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1315 int start_center_line
=0, end_center_line
=0;
1316 int seen_start
=0, seen_end
=0, seen_center
=0;
1317 REAL center_distance
;
1318 ARGB start_color
, end_color
;
1321 type
= flat_path
->pathdata
.Types
[i
];
1323 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1326 start_point
= flat_path
->pathdata
.Points
[i
];
1328 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1330 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1332 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1333 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1335 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1337 end_point
= flat_path
->pathdata
.Points
[i
+1];
1338 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1343 outer_color
= start_color
;
1345 min_yf
= center_point
.Y
;
1346 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1347 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1349 if (min_yf
< fill_area
->Y
)
1350 min_y
= fill_area
->Y
;
1352 min_y
= (INT
)ceil(min_yf
);
1354 max_yf
= center_point
.Y
;
1355 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1356 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1358 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1359 max_y
= fill_area
->Y
+ fill_area
->Height
;
1361 max_y
= (INT
)ceil(max_yf
);
1363 dy
= end_point
.Y
- start_point
.Y
;
1364 dx
= end_point
.X
- start_point
.X
;
1366 /* This is proportional to the distance from start-end line to center point. */
1367 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1368 dx
* (center_point
.Y
- start_point
.Y
);
1370 for (y
=min_y
; y
<max_y
; y
++)
1374 if (!seen_start
&& yf
>= start_point
.Y
)
1377 start_center_line
^= 1;
1379 if (!seen_end
&& yf
>= end_point
.Y
)
1382 end_center_line
^= 1;
1384 if (!seen_center
&& yf
>= center_point
.Y
)
1387 start_center_line
^= 1;
1388 end_center_line
^= 1;
1391 if (start_center_line
)
1392 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1394 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1396 if (end_center_line
)
1397 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1399 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1401 if (line1_xf
< line2_xf
)
1403 min_x
= (INT
)ceil(line1_xf
);
1404 max_x
= (INT
)ceil(line2_xf
);
1408 min_x
= (INT
)ceil(line2_xf
);
1409 max_x
= (INT
)ceil(line1_xf
);
1412 if (min_x
< fill_area
->X
)
1413 min_x
= fill_area
->X
;
1414 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1415 max_x
= fill_area
->X
+ fill_area
->Width
;
1417 for (x
=min_x
; x
<max_x
; x
++)
1422 if (start_color
!= end_color
)
1424 REAL blend_amount
, pdy
, pdx
;
1425 pdy
= yf
- center_point
.Y
;
1426 pdx
= xf
- center_point
.X
;
1427 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1428 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1431 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1432 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1434 distance
= distance
/ center_distance
;
1436 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1437 blend_colors(outer_color
, fill
->centercolor
, distance
);
1442 GdipDeletePath(flat_path
);
1446 return NotImplemented
;
1450 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1451 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1452 * should not be called on an hdc that has a path you care about. */
1453 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1454 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1456 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1458 HBRUSH brush
= NULL
;
1460 PointF ptf
[4], *custptf
= NULL
;
1461 POINT pt
[4], *custpt
= NULL
;
1463 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1468 if((x1
== x2
) && (y1
== y2
))
1471 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1473 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1475 brush
= CreateSolidBrush(color
);
1476 lb
.lbStyle
= BS_SOLID
;
1479 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1480 PS_JOIN_MITER
, 1, &lb
, 0,
1482 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1483 oldpen
= SelectObject(graphics
->hdc
, pen
);
1490 case LineCapSquareAnchor
:
1491 case LineCapDiamondAnchor
:
1492 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1493 if(cap
== LineCapDiamondAnchor
){
1494 dsmall
= cos(theta
+ M_PI_2
) * size
;
1495 dbig
= sin(theta
+ M_PI_2
) * size
;
1498 dsmall
= cos(theta
+ M_PI_4
) * size
;
1499 dbig
= sin(theta
+ M_PI_4
) * size
;
1502 ptf
[0].X
= x2
- dsmall
;
1503 ptf
[1].X
= x2
+ dbig
;
1505 ptf
[0].Y
= y2
- dbig
;
1506 ptf
[3].Y
= y2
+ dsmall
;
1508 ptf
[1].Y
= y2
- dsmall
;
1509 ptf
[2].Y
= y2
+ dbig
;
1511 ptf
[3].X
= x2
- dbig
;
1512 ptf
[2].X
= x2
+ dsmall
;
1514 transform_and_round_points(graphics
, pt
, ptf
, 4);
1515 Polygon(graphics
->hdc
, pt
, 4);
1518 case LineCapArrowAnchor
:
1519 size
= size
* 4.0 / sqrt(3.0);
1521 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1522 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1527 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1528 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1536 transform_and_round_points(graphics
, pt
, ptf
, 3);
1537 Polygon(graphics
->hdc
, pt
, 3);
1540 case LineCapRoundAnchor
:
1541 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1548 transform_and_round_points(graphics
, pt
, ptf
, 2);
1549 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1552 case LineCapTriangle
:
1554 dx
= cos(M_PI_2
+ theta
) * size
;
1555 dy
= sin(M_PI_2
+ theta
) * size
;
1562 dx
= cos(theta
) * size
;
1563 dy
= sin(theta
) * size
;
1568 transform_and_round_points(graphics
, pt
, ptf
, 3);
1569 Polygon(graphics
->hdc
, pt
, 3);
1573 dx
= dy
= size
/ 2.0;
1580 dx
= -cos(M_PI_2
+ theta
) * size
;
1581 dy
= -sin(M_PI_2
+ theta
) * size
;
1588 transform_and_round_points(graphics
, pt
, ptf
, 4);
1589 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1590 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1597 count
= custom
->pathdata
.Count
;
1598 custptf
= GdipAlloc(count
* sizeof(PointF
));
1599 custpt
= GdipAlloc(count
* sizeof(POINT
));
1600 tp
= GdipAlloc(count
);
1602 if(!custptf
|| !custpt
|| !tp
)
1605 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1607 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1608 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1609 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1611 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1612 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1614 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1616 for(i
= 0; i
< count
; i
++)
1617 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1620 BeginPath(graphics
->hdc
);
1621 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1622 EndPath(graphics
->hdc
);
1623 StrokeAndFillPath(graphics
->hdc
);
1626 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1638 SelectObject(graphics
->hdc
, oldbrush
);
1639 SelectObject(graphics
->hdc
, oldpen
);
1640 DeleteObject(brush
);
1645 /* Shortens the line by the given percent by changing x2, y2.
1646 * If percent is > 1.0 then the line will change direction.
1647 * If percent is negative it can lengthen the line. */
1648 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1650 REAL dist
, theta
, dx
, dy
;
1652 if((y1
== *y2
) && (x1
== *x2
))
1655 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1656 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1657 dx
= cos(theta
) * dist
;
1658 dy
= sin(theta
) * dist
;
1664 /* Shortens the line by the given amount by changing x2, y2.
1665 * If the amount is greater than the distance, the line will become length 0.
1666 * If the amount is negative, it can lengthen the line. */
1667 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1669 REAL dx
, dy
, percent
;
1673 if(dx
== 0 && dy
== 0)
1676 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1683 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1686 /* Conducts a linear search to find the bezier points that will back off
1687 * the endpoint of the curve by a distance of amt. Linear search works
1688 * better than binary in this case because there are multiple solutions,
1689 * and binary searches often find a bad one. I don't think this is what
1690 * Windows does but short of rendering the bezier without GDI's help it's
1691 * the best we can do. If rev then work from the start of the passed points
1692 * instead of the end. */
1693 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1696 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1697 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1706 origx
= pt
[fourth
].X
;
1707 origy
= pt
[fourth
].Y
;
1708 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1710 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1711 /* reset bezier points to original values */
1712 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1713 /* Perform magic on bezier points. Order is important here.*/
1714 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1715 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1716 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1717 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1718 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1719 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1721 dx
= pt
[fourth
].X
- origx
;
1722 dy
= pt
[fourth
].Y
- origy
;
1724 diff
= sqrt(dx
* dx
+ dy
* dy
);
1725 percent
+= 0.0005 * amt
;
1729 /* Draws a combination of bezier curves and lines between points. */
1730 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1731 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1733 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1734 BYTE
*tp
= GdipAlloc(count
);
1735 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1737 GpStatus status
= GenericError
;
1743 if(!pti
|| !tp
|| !ptcopy
){
1744 status
= OutOfMemory
;
1748 for(i
= 1; i
< count
; i
++){
1749 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1750 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1751 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1752 ERR("Bad bezier points\n");
1759 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1761 /* If we are drawing caps, go through the points and adjust them accordingly,
1762 * and draw the caps. */
1764 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1765 case PathPointTypeBezier
:
1766 if(pen
->endcap
== LineCapArrowAnchor
)
1767 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1768 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1769 shorten_bezier_amt(&ptcopy
[count
- 4],
1770 pen
->width
* pen
->customend
->inset
, FALSE
);
1772 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1773 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1774 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1775 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1778 case PathPointTypeLine
:
1779 if(pen
->endcap
== LineCapArrowAnchor
)
1780 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1781 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1783 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1784 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1785 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1786 pen
->customend
->inset
* pen
->width
);
1788 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1789 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1794 ERR("Bad path last point\n");
1798 /* Find start of points */
1799 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1800 == PathPointTypeStart
); j
++);
1802 switch(types
[j
] & PathPointTypePathTypeMask
){
1803 case PathPointTypeBezier
:
1804 if(pen
->startcap
== LineCapArrowAnchor
)
1805 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1806 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1807 shorten_bezier_amt(&ptcopy
[j
- 1],
1808 pen
->width
* pen
->customstart
->inset
, TRUE
);
1810 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1811 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1812 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1813 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1816 case PathPointTypeLine
:
1817 if(pen
->startcap
== LineCapArrowAnchor
)
1818 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1819 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1821 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1822 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1823 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1824 pen
->customstart
->inset
* pen
->width
);
1826 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1827 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1832 ERR("Bad path points\n");
1837 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1839 for(i
= 0; i
< count
; i
++){
1840 tp
[i
] = convert_path_point_type(types
[i
]);
1843 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1855 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1859 BeginPath(graphics
->hdc
);
1860 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1861 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1862 EndPath(graphics
->hdc
);
1866 typedef struct _GraphicsContainerItem
{
1868 GraphicsContainer contid
;
1870 SmoothingMode smoothing
;
1871 CompositingQuality compqual
;
1872 InterpolationMode interpolation
;
1873 CompositingMode compmode
;
1874 TextRenderingHint texthint
;
1877 PixelOffsetMode pixeloffset
;
1879 GpMatrix worldtrans
;
1881 INT origin_x
, origin_y
;
1882 } GraphicsContainerItem
;
1884 static GpStatus
init_container(GraphicsContainerItem
** container
,
1885 GDIPCONST GpGraphics
* graphics
){
1888 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1892 (*container
)->contid
= graphics
->contid
+ 1;
1894 (*container
)->smoothing
= graphics
->smoothing
;
1895 (*container
)->compqual
= graphics
->compqual
;
1896 (*container
)->interpolation
= graphics
->interpolation
;
1897 (*container
)->compmode
= graphics
->compmode
;
1898 (*container
)->texthint
= graphics
->texthint
;
1899 (*container
)->scale
= graphics
->scale
;
1900 (*container
)->unit
= graphics
->unit
;
1901 (*container
)->textcontrast
= graphics
->textcontrast
;
1902 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1903 (*container
)->origin_x
= graphics
->origin_x
;
1904 (*container
)->origin_y
= graphics
->origin_y
;
1905 (*container
)->worldtrans
= graphics
->worldtrans
;
1907 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1909 GdipFree(*container
);
1917 static void delete_container(GraphicsContainerItem
* container
)
1919 GdipDeleteRegion(container
->clip
);
1920 GdipFree(container
);
1923 static GpStatus
restore_container(GpGraphics
* graphics
,
1924 GDIPCONST GraphicsContainerItem
* container
){
1928 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1929 if(sts
!= Ok
) return sts
;
1931 graphics
->worldtrans
= container
->worldtrans
;
1933 GdipDeleteRegion(graphics
->clip
);
1934 graphics
->clip
= newClip
;
1936 graphics
->contid
= container
->contid
- 1;
1938 graphics
->smoothing
= container
->smoothing
;
1939 graphics
->compqual
= container
->compqual
;
1940 graphics
->interpolation
= container
->interpolation
;
1941 graphics
->compmode
= container
->compmode
;
1942 graphics
->texthint
= container
->texthint
;
1943 graphics
->scale
= container
->scale
;
1944 graphics
->unit
= container
->unit
;
1945 graphics
->textcontrast
= container
->textcontrast
;
1946 graphics
->pixeloffset
= container
->pixeloffset
;
1947 graphics
->origin_x
= container
->origin_x
;
1948 graphics
->origin_y
= container
->origin_y
;
1953 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1959 if(graphics
->hwnd
) {
1960 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1961 return GenericError
;
1963 rect
->X
= wnd_rect
.left
;
1964 rect
->Y
= wnd_rect
.top
;
1965 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1966 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1967 }else if (graphics
->image
){
1968 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1969 if (stat
== Ok
&& unit
!= UnitPixel
)
1970 FIXME("need to convert from unit %i\n", unit
);
1971 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
1978 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
1979 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
1981 rect
->Width
= bmp
.bmWidth
;
1982 rect
->Height
= bmp
.bmHeight
;
1993 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1994 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2000 /* on success, rgn will contain the region of the graphics object which
2001 * is visible after clipping has been applied */
2002 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2008 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2011 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2014 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2017 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2020 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2023 GdipDeleteRegion(tmp
);
2027 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2031 if (font
->unit
== UnitPixel
)
2033 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2037 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2038 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2040 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2043 lf
->lfHeight
= -(height
+ 0.5);
2045 lf
->lfEscapement
= 0;
2046 lf
->lfOrientation
= 0;
2047 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2048 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2049 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2050 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2051 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2052 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2053 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2054 lf
->lfQuality
= DEFAULT_QUALITY
;
2055 lf
->lfPitchAndFamily
= 0;
2056 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2059 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2060 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2061 GDIPCONST GpMatrix
*matrix
)
2063 HDC hdc
= CreateCompatibleDC(0);
2065 REAL angle
, rel_width
, rel_height
, font_height
;
2067 HFONT unscaled_font
;
2068 TEXTMETRICW textmet
;
2070 if (font
->unit
== UnitPixel
)
2071 font_height
= font
->emSize
;
2074 REAL unit_scale
, res
;
2076 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2077 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2079 font_height
= font
->emSize
* unit_scale
;
2090 GpMatrix xform
= *matrix
;
2091 GdipTransformMatrixPoints(&xform
, pt
, 3);
2094 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2095 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2096 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2097 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2098 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2099 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2101 get_log_fontW(font
, graphics
, &lfw
);
2102 lfw
.lfHeight
= gdip_round(font_height
* rel_height
);
2103 unscaled_font
= CreateFontIndirectW(&lfw
);
2105 SelectObject(hdc
, unscaled_font
);
2106 GetTextMetricsW(hdc
, &textmet
);
2108 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2109 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2111 *hfont
= CreateFontIndirectW(&lfw
);
2114 DeleteObject(unscaled_font
);
2117 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2119 TRACE("(%p, %p)\n", hdc
, graphics
);
2121 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2124 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2130 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2133 FIXME("Don't know how to handle parameter hDevice\n");
2138 if(graphics
== NULL
)
2139 return InvalidParameter
;
2141 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2142 if(!*graphics
) return OutOfMemory
;
2144 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2146 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2147 GdipFree(*graphics
);
2151 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2152 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2153 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2155 (*graphics
)->alpha_hdc
= 1;
2158 (*graphics
)->hdc
= hdc
;
2159 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2160 (*graphics
)->owndc
= FALSE
;
2161 (*graphics
)->smoothing
= SmoothingModeDefault
;
2162 (*graphics
)->compqual
= CompositingQualityDefault
;
2163 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2164 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2165 (*graphics
)->compmode
= CompositingModeSourceOver
;
2166 (*graphics
)->unit
= UnitDisplay
;
2167 (*graphics
)->scale
= 1.0;
2168 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2169 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2170 (*graphics
)->busy
= FALSE
;
2171 (*graphics
)->textcontrast
= 4;
2172 list_init(&(*graphics
)->containers
);
2173 (*graphics
)->contid
= 0;
2175 TRACE("<-- %p\n", *graphics
);
2180 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2184 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2185 if(!*graphics
) return OutOfMemory
;
2187 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2189 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2190 GdipFree(*graphics
);
2194 (*graphics
)->hdc
= NULL
;
2195 (*graphics
)->hwnd
= NULL
;
2196 (*graphics
)->owndc
= FALSE
;
2197 (*graphics
)->image
= image
;
2198 /* We have to store the image type here because the image may be freed
2199 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2200 (*graphics
)->image_type
= image
->type
;
2201 (*graphics
)->smoothing
= SmoothingModeDefault
;
2202 (*graphics
)->compqual
= CompositingQualityDefault
;
2203 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2204 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2205 (*graphics
)->compmode
= CompositingModeSourceOver
;
2206 (*graphics
)->unit
= UnitDisplay
;
2207 (*graphics
)->scale
= 1.0;
2208 (*graphics
)->xres
= image
->xres
;
2209 (*graphics
)->yres
= image
->yres
;
2210 (*graphics
)->busy
= FALSE
;
2211 (*graphics
)->textcontrast
= 4;
2212 list_init(&(*graphics
)->containers
);
2213 (*graphics
)->contid
= 0;
2215 TRACE("<-- %p\n", *graphics
);
2220 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2225 TRACE("(%p, %p)\n", hwnd
, graphics
);
2229 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2231 ReleaseDC(hwnd
, hdc
);
2235 (*graphics
)->hwnd
= hwnd
;
2236 (*graphics
)->owndc
= TRUE
;
2241 /* FIXME: no icm handling */
2242 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2244 TRACE("(%p, %p)\n", hwnd
, graphics
);
2246 return GdipCreateFromHWND(hwnd
, graphics
);
2249 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2250 GpMetafile
**metafile
)
2252 ENHMETAHEADER header
;
2253 MetafileType metafile_type
;
2255 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2257 if(!hemf
|| !metafile
)
2258 return InvalidParameter
;
2260 if (GetEnhMetaFileHeader(hemf
, sizeof(header
), &header
) == 0)
2261 return GenericError
;
2263 metafile_type
= METAFILE_GetEmfType(hemf
);
2265 if (metafile_type
== MetafileTypeInvalid
)
2266 return GenericError
;
2268 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2272 (*metafile
)->image
.type
= ImageTypeMetafile
;
2273 (*metafile
)->image
.format
= ImageFormatEMF
;
2274 (*metafile
)->image
.frame_count
= 1;
2275 (*metafile
)->image
.xres
= (REAL
)header
.szlDevice
.cx
;
2276 (*metafile
)->image
.yres
= (REAL
)header
.szlDevice
.cy
;
2277 (*metafile
)->bounds
.X
= (REAL
)header
.rclBounds
.left
;
2278 (*metafile
)->bounds
.Y
= (REAL
)header
.rclBounds
.top
;
2279 (*metafile
)->bounds
.Width
= (REAL
)(header
.rclBounds
.right
- header
.rclBounds
.left
);
2280 (*metafile
)->bounds
.Height
= (REAL
)(header
.rclBounds
.bottom
- header
.rclBounds
.top
);
2281 (*metafile
)->unit
= UnitPixel
;
2282 (*metafile
)->metafile_type
= metafile_type
;
2283 (*metafile
)->hemf
= hemf
;
2284 (*metafile
)->preserve_hemf
= !delete;
2286 TRACE("<-- %p\n", *metafile
);
2291 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2292 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2297 GpStatus retval
= Ok
;
2299 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2301 if(!hwmf
|| !metafile
|| !placeable
)
2302 return InvalidParameter
;
2305 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2307 return GenericError
;
2308 copy
= GdipAlloc(read
);
2309 GetMetaFileBitsEx(hwmf
, read
, copy
);
2311 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2314 /* FIXME: We should store and use hwmf instead of converting to hemf */
2315 retval
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
2319 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2320 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2321 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2322 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2323 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2324 placeable
->BoundingBox
.Left
);
2325 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2326 placeable
->BoundingBox
.Top
);
2327 (*metafile
)->metafile_type
= MetafileTypeWmfPlaceable
;
2328 (*metafile
)->image
.format
= ImageFormatWMF
;
2330 if (delete) DeleteMetaFile(hwmf
);
2333 DeleteEnhMetaFile(hemf
);
2337 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2338 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2340 HMETAFILE hmf
= GetMetaFileW(file
);
2342 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2344 if(!hmf
) return InvalidParameter
;
2346 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2349 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2350 GpMetafile
**metafile
)
2352 FIXME("(%p, %p): stub\n", file
, metafile
);
2353 return NotImplemented
;
2356 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2357 GpMetafile
**metafile
)
2359 FIXME("(%p, %p): stub\n", stream
, metafile
);
2360 return NotImplemented
;
2363 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2364 UINT access
, IStream
**stream
)
2369 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2371 if(!stream
|| !filename
)
2372 return InvalidParameter
;
2374 if(access
& GENERIC_WRITE
)
2375 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2376 else if(access
& GENERIC_READ
)
2377 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2379 return InvalidParameter
;
2381 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2383 return hresult_to_status(ret
);
2386 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2388 GraphicsContainerItem
*cont
, *next
;
2390 TRACE("(%p)\n", graphics
);
2392 if(!graphics
) return InvalidParameter
;
2393 if(graphics
->busy
) return ObjectBusy
;
2395 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2397 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2403 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2405 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2406 list_remove(&cont
->entry
);
2407 delete_container(cont
);
2410 GdipDeleteRegion(graphics
->clip
);
2416 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2417 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2422 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2423 width
, height
, startAngle
, sweepAngle
);
2425 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2426 return InvalidParameter
;
2431 status
= GdipCreatePath(FillModeAlternate
, &path
);
2432 if (status
!= Ok
) return status
;
2434 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2436 status
= GdipDrawPath(graphics
, pen
, path
);
2438 GdipDeletePath(path
);
2442 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2443 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2445 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2446 width
, height
, startAngle
, sweepAngle
);
2448 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2451 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2452 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2456 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2457 x2
, y2
, x3
, y3
, x4
, y4
);
2459 if(!graphics
|| !pen
)
2460 return InvalidParameter
;
2473 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2476 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2477 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2479 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2480 x2
, y2
, x3
, y3
, x4
, y4
);
2482 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2485 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2486 GDIPCONST GpPointF
*points
, INT count
)
2491 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2493 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2494 return InvalidParameter
;
2499 status
= GdipCreatePath(FillModeAlternate
, &path
);
2500 if (status
!= Ok
) return status
;
2502 status
= GdipAddPathBeziers(path
, points
, count
);
2504 status
= GdipDrawPath(graphics
, pen
, path
);
2506 GdipDeletePath(path
);
2510 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2511 GDIPCONST GpPoint
*points
, INT count
)
2517 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2519 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2520 return InvalidParameter
;
2525 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2529 for(i
= 0; i
< count
; i
++){
2530 pts
[i
].X
= (REAL
)points
[i
].X
;
2531 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2534 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2541 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2542 GDIPCONST GpPointF
*points
, INT count
)
2544 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2546 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2549 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2550 GDIPCONST GpPoint
*points
, INT count
)
2552 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2554 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2557 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2558 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2563 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2565 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2566 return InvalidParameter
;
2571 status
= GdipCreatePath(FillModeAlternate
, &path
);
2572 if (status
!= Ok
) return status
;
2574 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2576 status
= GdipDrawPath(graphics
, pen
, path
);
2578 GdipDeletePath(path
);
2583 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2584 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2590 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2592 if(!points
|| count
<= 0)
2593 return InvalidParameter
;
2595 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2599 for(i
= 0; i
< count
; i
++){
2600 ptf
[i
].X
= (REAL
)points
[i
].X
;
2601 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2604 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2611 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2612 GDIPCONST GpPointF
*points
, INT count
)
2614 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2616 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2619 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2620 GDIPCONST GpPoint
*points
, INT count
)
2626 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2629 return InvalidParameter
;
2631 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2635 for(i
= 0; i
< count
; i
++){
2636 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2637 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2640 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2646 /* Approximates cardinal spline with Bezier curves. */
2647 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2648 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2653 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2655 if(!graphics
|| !pen
)
2656 return InvalidParameter
;
2662 return InvalidParameter
;
2664 status
= GdipCreatePath(FillModeAlternate
, &path
);
2665 if (status
!= Ok
) return status
;
2667 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2669 status
= GdipDrawPath(graphics
, pen
, path
);
2671 GdipDeletePath(path
);
2675 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2676 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2682 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2685 return InvalidParameter
;
2687 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2691 for(i
= 0; i
< count
; i
++){
2692 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2693 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2696 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2702 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2703 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2706 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2708 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2709 return InvalidParameter
;
2712 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2715 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2716 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2719 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2725 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2726 return InvalidParameter
;
2729 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2732 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2733 REAL y
, REAL width
, REAL height
)
2738 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2740 if(!graphics
|| !pen
)
2741 return InvalidParameter
;
2746 status
= GdipCreatePath(FillModeAlternate
, &path
);
2747 if (status
!= Ok
) return status
;
2749 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2751 status
= GdipDrawPath(graphics
, pen
, path
);
2753 GdipDeletePath(path
);
2757 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2758 INT y
, INT width
, INT height
)
2760 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2762 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2766 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2770 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2772 if(!graphics
|| !image
)
2773 return InvalidParameter
;
2775 GdipGetImageWidth(image
, &width
);
2776 GdipGetImageHeight(image
, &height
);
2778 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2779 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2782 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2785 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2787 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2790 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2791 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2795 REAL scale_x
, scale_y
, width
, height
;
2797 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2799 if (!graphics
|| !image
) return InvalidParameter
;
2801 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2802 scale_x
*= graphics
->xres
/ image
->xres
;
2803 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2804 scale_y
*= graphics
->yres
/ image
->yres
;
2805 width
= srcwidth
* scale_x
;
2806 height
= srcheight
* scale_y
;
2808 points
[0].X
= points
[2].X
= x
;
2809 points
[0].Y
= points
[1].Y
= y
;
2810 points
[1].X
= x
+ width
;
2811 points
[2].Y
= y
+ height
;
2813 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2814 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2817 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2818 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2821 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2824 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2825 GDIPCONST GpPointF
*dstpoints
, INT count
)
2829 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2832 return InvalidParameter
;
2834 GdipGetImageWidth(image
, &width
);
2835 GdipGetImageHeight(image
, &height
);
2837 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2838 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2841 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2842 GDIPCONST GpPoint
*dstpoints
, INT count
)
2846 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2848 if (count
!= 3 || !dstpoints
)
2849 return InvalidParameter
;
2851 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2852 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2853 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2854 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2855 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2856 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2858 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2861 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2862 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2864 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2868 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2869 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2870 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2871 DrawImageAbort callback
, VOID
* callbackData
)
2877 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2878 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2882 return NotImplemented
;
2884 if(!graphics
|| !image
|| !points
|| count
!= 3)
2885 return InvalidParameter
;
2887 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2888 debugstr_pointf(&points
[2]));
2890 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2891 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2892 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2893 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
2895 transform_and_round_points(graphics
, pti
, ptf
, 4);
2897 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2898 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2900 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2901 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2902 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2903 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2904 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2910 FIXME("graphics object has no HDC\n");
2913 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2914 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2915 srcx
, srcy
, srcwidth
, srcheight
, NULL
) != S_OK
)
2918 callback(callbackData
);
2919 return GenericError
;
2922 else if (image
->type
== ImageTypeBitmap
)
2924 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2927 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2928 graphics
->xres
, graphics
->yres
,
2929 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2930 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2931 imageAttributes
? imageAttributes
->outside_color
: 0);
2933 if (imageAttributes
|| graphics
->alpha_hdc
||
2934 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2935 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2936 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2937 srcx
< 0 || srcy
< 0 ||
2938 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2945 int i
, x
, y
, src_stride
, dst_stride
;
2946 GpMatrix dst_to_src
;
2947 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2948 LPBYTE src_data
, dst_data
;
2949 BitmapData lockeddata
;
2950 InterpolationMode interpolation
= graphics
->interpolation
;
2951 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2952 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2953 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2954 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2956 if (!imageAttributes
)
2957 imageAttributes
= &defaultImageAttributes
;
2959 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2960 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2963 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2964 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2965 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2966 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2969 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
2971 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2972 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2973 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2974 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2975 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2976 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2978 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
2980 stat
= GdipInvertMatrix(&dst_to_src
);
2981 if (stat
!= Ok
) return stat
;
2983 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2984 if (!dst_data
) return OutOfMemory
;
2986 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2988 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2989 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2991 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
2993 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
2999 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3001 /* Read the bits we need from the source bitmap into an ARGB buffer. */
3002 lockeddata
.Width
= src_area
.Width
;
3003 lockeddata
.Height
= src_area
.Height
;
3004 lockeddata
.Stride
= src_stride
;
3005 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3006 lockeddata
.Scan0
= src_data
;
3008 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3009 PixelFormat32bppARGB
, &lockeddata
);
3012 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3016 if (src_data
!= dst_data
)
3022 apply_image_attributes(imageAttributes
, src_data
,
3023 src_area
.Width
, src_area
.Height
,
3024 src_stride
, ColorAdjustTypeBitmap
);
3026 /* Transform the bits as needed to the destination. */
3027 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3029 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3030 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3031 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3032 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3034 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3036 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3038 GpPointF src_pointf
;
3041 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3042 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3044 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3046 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3047 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3048 imageAttributes
, interpolation
, offset_mode
);
3056 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3057 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3066 int temp_hdc
=0, temp_bitmap
=0;
3067 HBITMAP hbitmap
, old_hbm
=NULL
;
3069 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3070 bitmap
->format
== PixelFormat24bppRGB
||
3071 bitmap
->format
== PixelFormat32bppRGB
||
3072 bitmap
->format
== PixelFormat32bppPARGB
))
3074 BITMAPINFOHEADER bih
;
3076 PixelFormat dst_format
;
3078 /* we can't draw a bitmap of this format directly */
3079 hdc
= CreateCompatibleDC(0);
3083 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3084 bih
.biWidth
= bitmap
->width
;
3085 bih
.biHeight
= -bitmap
->height
;
3087 bih
.biBitCount
= 32;
3088 bih
.biCompression
= BI_RGB
;
3089 bih
.biSizeImage
= 0;
3090 bih
.biXPelsPerMeter
= 0;
3091 bih
.biYPelsPerMeter
= 0;
3093 bih
.biClrImportant
= 0;
3095 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3096 (void**)&temp_bits
, NULL
, 0);
3098 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3099 dst_format
= PixelFormat32bppPARGB
;
3101 dst_format
= PixelFormat32bppRGB
;
3103 convert_pixels(bitmap
->width
, bitmap
->height
,
3104 bitmap
->width
*4, temp_bits
, dst_format
,
3105 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3106 bitmap
->image
.palette
);
3110 if (bitmap
->hbitmap
)
3111 hbitmap
= bitmap
->hbitmap
;
3114 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3119 temp_hdc
= (hdc
== 0);
3124 if (!hdc
) hdc
= CreateCompatibleDC(0);
3125 old_hbm
= SelectObject(hdc
, hbitmap
);
3128 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3130 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3131 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3135 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3136 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3141 SelectObject(hdc
, old_hbm
);
3146 DeleteObject(hbitmap
);
3149 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3155 rc
.Width
= srcwidth
;
3156 rc
.Height
= srcheight
;
3158 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3159 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3163 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3164 return InvalidParameter
;
3170 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3171 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3172 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3173 DrawImageAbort callback
, VOID
* callbackData
)
3175 GpPointF pointsF
[3];
3178 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3179 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3182 if(!points
|| count
!=3)
3183 return InvalidParameter
;
3185 for(i
= 0; i
< count
; i
++){
3186 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3187 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3190 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3191 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3192 callback
, callbackData
);
3195 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3196 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3197 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3198 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3199 VOID
* callbackData
)
3203 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3204 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3205 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3209 points
[1].X
= dstx
+ dstwidth
;
3212 points
[2].Y
= dsty
+ dstheight
;
3214 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3215 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3218 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3219 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3220 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3221 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3222 VOID
* callbackData
)
3226 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3227 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3228 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3232 points
[1].X
= dstx
+ dstwidth
;
3235 points
[2].Y
= dsty
+ dstheight
;
3237 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3238 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3241 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3242 REAL x
, REAL y
, REAL width
, REAL height
)
3248 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3250 if(!graphics
|| !image
)
3251 return InvalidParameter
;
3253 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3257 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3258 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3259 unit
, NULL
, NULL
, NULL
);
3262 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3263 INT x
, INT y
, INT width
, INT height
)
3265 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3267 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3270 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3271 REAL y1
, REAL x2
, REAL y2
)
3275 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3281 return GdipDrawLines(graphics
, pen
, pt
, 2);
3284 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3285 INT y1
, INT x2
, INT y2
)
3287 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3289 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3292 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3293 GpPointF
*points
, INT count
)
3298 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3300 if(!pen
|| !graphics
|| (count
< 2))
3301 return InvalidParameter
;
3306 status
= GdipCreatePath(FillModeAlternate
, &path
);
3307 if (status
!= Ok
) return status
;
3309 status
= GdipAddPathLine2(path
, points
, count
);
3311 status
= GdipDrawPath(graphics
, pen
, path
);
3313 GdipDeletePath(path
);
3317 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3318 GpPoint
*points
, INT count
)
3324 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3326 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3327 if(!ptf
) return OutOfMemory
;
3329 for(i
= 0; i
< count
; i
++){
3330 ptf
[i
].X
= (REAL
) points
[i
].X
;
3331 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3334 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3340 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3345 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3347 if(!pen
|| !graphics
)
3348 return InvalidParameter
;
3355 FIXME("graphics object has no HDC\n");
3359 save_state
= prepare_dc(graphics
, pen
);
3361 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3362 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3364 restore_dc(graphics
, save_state
);
3369 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3370 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3375 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3376 width
, height
, startAngle
, sweepAngle
);
3378 if(!graphics
|| !pen
)
3379 return InvalidParameter
;
3384 status
= GdipCreatePath(FillModeAlternate
, &path
);
3385 if (status
!= Ok
) return status
;
3387 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3389 status
= GdipDrawPath(graphics
, pen
, path
);
3391 GdipDeletePath(path
);
3395 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3396 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3398 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3399 width
, height
, startAngle
, sweepAngle
);
3401 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3404 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3405 REAL y
, REAL width
, REAL height
)
3410 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3412 if(!pen
|| !graphics
)
3413 return InvalidParameter
;
3418 status
= GdipCreatePath(FillModeAlternate
, &path
);
3419 if (status
!= Ok
) return status
;
3421 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3423 status
= GdipDrawPath(graphics
, pen
, path
);
3425 GdipDeletePath(path
);
3429 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3430 INT y
, INT width
, INT height
)
3432 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3434 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3437 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3438 GDIPCONST GpRectF
* rects
, INT count
)
3443 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3445 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3446 return InvalidParameter
;
3451 status
= GdipCreatePath(FillModeAlternate
, &path
);
3452 if (status
!= Ok
) return status
;
3454 status
= GdipAddPathRectangles(path
, rects
, count
);
3456 status
= GdipDrawPath(graphics
, pen
, path
);
3458 GdipDeletePath(path
);
3462 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3463 GDIPCONST GpRect
* rects
, INT count
)
3469 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3471 if(!rects
|| count
<=0)
3472 return InvalidParameter
;
3474 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3478 for(i
= 0;i
< count
;i
++){
3479 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3480 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3481 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3482 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3485 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3491 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3492 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3497 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3498 count
, tension
, fill
);
3500 if(!graphics
|| !brush
|| !points
)
3501 return InvalidParameter
;
3506 if(count
== 1) /* Do nothing */
3509 status
= GdipCreatePath(fill
, &path
);
3510 if (status
!= Ok
) return status
;
3512 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3514 status
= GdipFillPath(graphics
, brush
, path
);
3516 GdipDeletePath(path
);
3520 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3521 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3527 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3528 count
, tension
, fill
);
3530 if(!points
|| count
== 0)
3531 return InvalidParameter
;
3533 if(count
== 1) /* Do nothing */
3536 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3540 for(i
= 0;i
< count
;i
++){
3541 ptf
[i
].X
= (REAL
)points
[i
].X
;
3542 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3545 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3552 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3553 GDIPCONST GpPointF
*points
, INT count
)
3555 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3556 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3557 0.5f
, FillModeAlternate
);
3560 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3561 GDIPCONST GpPoint
*points
, INT count
)
3563 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3564 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3565 0.5f
, FillModeAlternate
);
3568 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3569 REAL y
, REAL width
, REAL height
)
3574 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3576 if(!graphics
|| !brush
)
3577 return InvalidParameter
;
3582 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3586 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3589 stat
= GdipFillPath(graphics
, brush
, path
);
3591 GdipDeletePath(path
);
3597 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3598 INT y
, INT width
, INT height
)
3600 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3602 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3605 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3610 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3611 return NotImplemented
;
3613 save_state
= SaveDC(graphics
->hdc
);
3614 EndPath(graphics
->hdc
);
3615 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
3618 BeginPath(graphics
->hdc
);
3619 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
3620 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
3625 EndPath(graphics
->hdc
);
3626 brush_fill_path(graphics
, brush
);
3631 RestoreDC(graphics
->hdc
, save_state
);
3636 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3641 if (!brush_can_fill_pixels(brush
))
3642 return NotImplemented
;
3644 /* FIXME: This could probably be done more efficiently without regions. */
3646 stat
= GdipCreateRegionPath(path
, &rgn
);
3650 stat
= GdipFillRegion(graphics
, brush
, rgn
);
3652 GdipDeleteRegion(rgn
);
3658 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
3660 GpStatus stat
= NotImplemented
;
3662 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
3664 if(!brush
|| !graphics
|| !path
)
3665 return InvalidParameter
;
3670 if (!graphics
->image
&& !graphics
->alpha_hdc
)
3671 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
3673 if (stat
== NotImplemented
)
3674 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
3676 if (stat
== NotImplemented
)
3678 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
3685 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3686 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3691 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3692 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3694 if(!graphics
|| !brush
)
3695 return InvalidParameter
;
3700 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3704 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3707 stat
= GdipFillPath(graphics
, brush
, path
);
3709 GdipDeletePath(path
);
3715 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3716 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3718 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3719 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3721 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3724 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3725 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3730 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3732 if(!graphics
|| !brush
|| !points
|| !count
)
3733 return InvalidParameter
;
3738 stat
= GdipCreatePath(fillMode
, &path
);
3742 stat
= GdipAddPathPolygon(path
, points
, count
);
3745 stat
= GdipFillPath(graphics
, brush
, path
);
3747 GdipDeletePath(path
);
3753 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3754 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3759 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3761 if(!graphics
|| !brush
|| !points
|| !count
)
3762 return InvalidParameter
;
3767 stat
= GdipCreatePath(fillMode
, &path
);
3771 stat
= GdipAddPathPolygonI(path
, points
, count
);
3774 stat
= GdipFillPath(graphics
, brush
, path
);
3776 GdipDeletePath(path
);
3782 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3783 GDIPCONST GpPointF
*points
, INT count
)
3785 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3787 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3790 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3791 GDIPCONST GpPoint
*points
, INT count
)
3793 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3795 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3798 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3799 REAL x
, REAL y
, REAL width
, REAL height
)
3804 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3806 if(!graphics
|| !brush
)
3807 return InvalidParameter
;
3812 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3816 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3819 stat
= GdipFillPath(graphics
, brush
, path
);
3821 GdipDeletePath(path
);
3827 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3828 INT x
, INT y
, INT width
, INT height
)
3830 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3832 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
3835 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3841 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3844 return InvalidParameter
;
3846 status
= GdipCreatePath(FillModeAlternate
, &path
);
3847 if (status
!= Ok
) return status
;
3849 status
= GdipAddPathRectangles(path
, rects
, count
);
3851 status
= GdipFillPath(graphics
, brush
, path
);
3853 GdipDeletePath(path
);
3857 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3864 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3866 if(!rects
|| count
<= 0)
3867 return InvalidParameter
;
3869 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3873 for(i
= 0; i
< count
; i
++){
3874 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3875 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3876 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3877 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3880 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3886 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3894 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
3895 return NotImplemented
;
3897 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3901 save_state
= SaveDC(graphics
->hdc
);
3902 EndPath(graphics
->hdc
);
3904 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3906 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3908 BeginPath(graphics
->hdc
);
3909 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3910 EndPath(graphics
->hdc
);
3912 brush_fill_path(graphics
, brush
);
3915 RestoreDC(graphics
->hdc
, save_state
);
3922 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
3926 GpRegion
*temp_region
;
3927 GpMatrix world_to_device
;
3928 GpRectF graphics_bounds
;
3932 GpRect gp_bound_rect
;
3934 if (!brush_can_fill_pixels(brush
))
3935 return NotImplemented
;
3937 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
3940 stat
= GdipCloneRegion(region
, &temp_region
);
3944 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3945 CoordinateSpaceWorld
, &world_to_device
);
3948 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
3951 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
3954 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
3956 GdipDeleteRegion(temp_region
);
3959 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
3961 DeleteObject(hregion
);
3967 gp_bound_rect
.X
= bound_rect
.left
;
3968 gp_bound_rect
.Y
= bound_rect
.top
;
3969 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
3970 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
3972 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
3978 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
3979 &gp_bound_rect
, gp_bound_rect
.Width
);
3982 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
3983 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
3984 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
3986 GdipFree(pixel_data
);
3989 DeleteObject(hregion
);
3995 /*****************************************************************************
3996 * GdipFillRegion [GDIPLUS.@]
3998 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4001 GpStatus stat
= NotImplemented
;
4003 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4005 if (!(graphics
&& brush
&& region
))
4006 return InvalidParameter
;
4011 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4012 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4014 if (stat
== NotImplemented
)
4015 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4017 if (stat
== NotImplemented
)
4019 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4026 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4028 TRACE("(%p,%u)\n", graphics
, intention
);
4031 return InvalidParameter
;
4036 /* We have no internal operation queue, so there's no need to clear it. */
4044 /*****************************************************************************
4045 * GdipGetClipBounds [GDIPLUS.@]
4047 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4049 TRACE("(%p, %p)\n", graphics
, rect
);
4052 return InvalidParameter
;
4057 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4060 /*****************************************************************************
4061 * GdipGetClipBoundsI [GDIPLUS.@]
4063 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4065 TRACE("(%p, %p)\n", graphics
, rect
);
4068 return InvalidParameter
;
4073 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4076 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4077 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4078 CompositingMode
*mode
)
4080 TRACE("(%p, %p)\n", graphics
, mode
);
4082 if(!graphics
|| !mode
)
4083 return InvalidParameter
;
4088 *mode
= graphics
->compmode
;
4093 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4094 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4095 CompositingQuality
*quality
)
4097 TRACE("(%p, %p)\n", graphics
, quality
);
4099 if(!graphics
|| !quality
)
4100 return InvalidParameter
;
4105 *quality
= graphics
->compqual
;
4110 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4111 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4112 InterpolationMode
*mode
)
4114 TRACE("(%p, %p)\n", graphics
, mode
);
4116 if(!graphics
|| !mode
)
4117 return InvalidParameter
;
4122 *mode
= graphics
->interpolation
;
4127 /* FIXME: Need to handle color depths less than 24bpp */
4128 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4130 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4132 if(!graphics
|| !argb
)
4133 return InvalidParameter
;
4141 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4143 TRACE("(%p, %p)\n", graphics
, scale
);
4145 if(!graphics
|| !scale
)
4146 return InvalidParameter
;
4151 *scale
= graphics
->scale
;
4156 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4158 TRACE("(%p, %p)\n", graphics
, unit
);
4160 if(!graphics
|| !unit
)
4161 return InvalidParameter
;
4166 *unit
= graphics
->unit
;
4171 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4172 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4175 TRACE("(%p, %p)\n", graphics
, mode
);
4177 if(!graphics
|| !mode
)
4178 return InvalidParameter
;
4183 *mode
= graphics
->pixeloffset
;
4188 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4189 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4191 TRACE("(%p, %p)\n", graphics
, mode
);
4193 if(!graphics
|| !mode
)
4194 return InvalidParameter
;
4199 *mode
= graphics
->smoothing
;
4204 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4206 TRACE("(%p, %p)\n", graphics
, contrast
);
4208 if(!graphics
|| !contrast
)
4209 return InvalidParameter
;
4211 *contrast
= graphics
->textcontrast
;
4216 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4217 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4218 TextRenderingHint
*hint
)
4220 TRACE("(%p, %p)\n", graphics
, hint
);
4222 if(!graphics
|| !hint
)
4223 return InvalidParameter
;
4228 *hint
= graphics
->texthint
;
4233 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4238 TRACE("(%p, %p)\n", graphics
, rect
);
4240 if(!graphics
|| !rect
)
4241 return InvalidParameter
;
4246 /* intersect window and graphics clipping regions */
4247 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4250 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4253 /* get bounds of the region */
4254 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4257 GdipDeleteRegion(clip_rgn
);
4262 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4267 TRACE("(%p, %p)\n", graphics
, rect
);
4269 if(!graphics
|| !rect
)
4270 return InvalidParameter
;
4272 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4274 rect
->X
= gdip_round(rectf
.X
);
4275 rect
->Y
= gdip_round(rectf
.Y
);
4276 rect
->Width
= gdip_round(rectf
.Width
);
4277 rect
->Height
= gdip_round(rectf
.Height
);
4283 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4285 TRACE("(%p, %p)\n", graphics
, matrix
);
4287 if(!graphics
|| !matrix
)
4288 return InvalidParameter
;
4293 *matrix
= graphics
->worldtrans
;
4297 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4303 TRACE("(%p, %x)\n", graphics
, color
);
4306 return InvalidParameter
;
4311 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4314 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4315 GdipDeleteBrush((GpBrush
*)brush
);
4319 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4320 wnd_rect
.Width
, wnd_rect
.Height
);
4322 GdipDeleteBrush((GpBrush
*)brush
);
4327 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4329 TRACE("(%p, %p)\n", graphics
, res
);
4331 if(!graphics
|| !res
)
4332 return InvalidParameter
;
4334 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4337 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4343 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4345 if(!graphics
|| !result
)
4346 return InvalidParameter
;
4353 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4354 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4357 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4360 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4363 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4366 GdipDeleteRegion(rgn
);
4370 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4372 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4375 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4381 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4383 if(!graphics
|| !result
)
4384 return InvalidParameter
;
4391 pts
[1].X
= x
+ width
;
4392 pts
[1].Y
= y
+ height
;
4394 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4395 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4398 pts
[1].X
-= pts
[0].X
;
4399 pts
[1].Y
-= pts
[0].Y
;
4401 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4404 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4407 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4410 GdipDeleteRegion(rgn
);
4414 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4416 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4419 GpStatus
gdip_format_string(HDC hdc
,
4420 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4421 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4422 gdip_format_string_callback callback
, void *user_data
)
4425 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4426 nheight
, lineend
, lineno
= 0;
4428 StringAlignment halign
;
4431 HotkeyPrefix hkprefix
;
4432 INT
*hotkeyprefix_offsets
=NULL
;
4433 INT hotkeyprefix_count
=0;
4434 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4437 if(length
== -1) length
= lstrlenW(string
);
4439 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4440 if(!stringdup
) return OutOfMemory
;
4442 nwidth
= rect
->Width
;
4443 nheight
= rect
->Height
;
4444 if (ignore_empty_clip
)
4446 if (!nwidth
) nwidth
= INT_MAX
;
4447 if (!nheight
) nheight
= INT_MAX
;
4451 hkprefix
= format
->hkprefix
;
4453 hkprefix
= HotkeyPrefixNone
;
4455 if (hkprefix
== HotkeyPrefixShow
)
4457 for (i
=0; i
<length
; i
++)
4459 if (string
[i
] == '&')
4460 hotkeyprefix_count
++;
4464 if (hotkeyprefix_count
)
4465 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4467 hotkeyprefix_count
= 0;
4469 for(i
= 0, j
= 0; i
< length
; i
++){
4470 /* FIXME: This makes the indexes passed to callback inaccurate. */
4471 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4474 /* FIXME: tabs should be handled using tabstops from stringformat */
4475 if (string
[i
] == '\t')
4478 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4479 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4480 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4488 stringdup
[j
] = string
[i
];
4494 if (format
) halign
= format
->align
;
4495 else halign
= StringAlignmentNear
;
4497 while(sum
< length
){
4498 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4499 nwidth
, &fit
, NULL
, &size
);
4505 for(lret
= 0; lret
< fit
; lret
++)
4506 if(*(stringdup
+ sum
+ lret
) == '\n')
4509 /* Line break code (may look strange, but it imitates windows). */
4511 lineend
= fit
= lret
; /* this is not an off-by-one error */
4512 else if(fit
< (length
- sum
)){
4513 if(*(stringdup
+ sum
+ fit
) == ' ')
4514 while(*(stringdup
+ sum
+ fit
) == ' ')
4517 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4520 if(*(stringdup
+ sum
+ fit
) == '\t')
4529 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4530 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4536 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4537 nwidth
, &j
, NULL
, &size
);
4539 bounds
.Width
= size
.cx
;
4541 if(height
+ size
.cy
> nheight
)
4542 bounds
.Height
= nheight
- (height
+ size
.cy
);
4544 bounds
.Height
= size
.cy
;
4546 bounds
.Y
= rect
->Y
+ height
;
4550 case StringAlignmentNear
:
4554 case StringAlignmentCenter
:
4555 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4557 case StringAlignmentFar
:
4558 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4562 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4563 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4566 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4567 font
, rect
, format
, lineno
, &bounds
,
4568 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4569 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4574 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4578 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4580 if(height
> nheight
)
4583 /* Stop if this was a linewrap (but not if it was a linebreak). */
4584 if ((lret
== fitcpy
) && format
&&
4585 (format
->attr
& (StringFormatFlagsNoWrap
| StringFormatFlagsLineLimit
)))
4589 GdipFree(stringdup
);
4590 GdipFree(hotkeyprefix_offsets
);
4595 struct measure_ranges_args
{
4597 REAL rel_width
, rel_height
;
4600 static GpStatus
measure_ranges_callback(HDC hdc
,
4601 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4602 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4603 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4604 INT underlined_index_count
, void *user_data
)
4608 struct measure_ranges_args
*args
= user_data
;
4610 for (i
=0; i
<format
->range_count
; i
++)
4612 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
4613 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
4614 if (range_start
< range_end
)
4619 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
4620 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
4622 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
4623 INT_MAX
, NULL
, NULL
, &range_size
);
4624 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
4626 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
4627 INT_MAX
, NULL
, NULL
, &range_size
);
4628 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
4630 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
4639 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
4640 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
4641 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
4642 INT regionCount
, GpRegion
** regions
)
4646 HFONT gdifont
, oldfont
;
4647 struct measure_ranges_args args
;
4648 HDC hdc
, temp_hdc
=NULL
;
4653 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
4654 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
4656 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
4657 return InvalidParameter
;
4659 if (regionCount
< stringFormat
->range_count
)
4660 return InvalidParameter
;
4664 hdc
= temp_hdc
= CreateCompatibleDC(0);
4665 if (!temp_hdc
) return OutOfMemory
;
4668 hdc
= graphics
->hdc
;
4670 if (stringFormat
->attr
)
4671 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
4679 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4680 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4681 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4682 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4683 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4685 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
4686 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4688 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
4689 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
4690 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
4691 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
4693 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
4694 oldfont
= SelectObject(hdc
, gdifont
);
4696 for (i
=0; i
<stringFormat
->range_count
; i
++)
4698 stat
= GdipSetEmpty(regions
[i
]);
4703 args
.regions
= regions
;
4705 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
4706 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
4708 SelectObject(hdc
, oldfont
);
4709 DeleteObject(gdifont
);
4717 struct measure_string_args
{
4719 INT
*codepointsfitted
;
4721 REAL rel_width
, rel_height
;
4724 static GpStatus
measure_string_callback(HDC hdc
,
4725 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4726 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4727 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4728 INT underlined_index_count
, void *user_data
)
4730 struct measure_string_args
*args
= user_data
;
4731 REAL new_width
, new_height
;
4733 new_width
= bounds
->Width
/ args
->rel_width
;
4734 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
4736 if (new_width
> args
->bounds
->Width
)
4737 args
->bounds
->Width
= new_width
;
4739 if (new_height
> args
->bounds
->Height
)
4740 args
->bounds
->Height
= new_height
;
4742 if (args
->codepointsfitted
)
4743 *args
->codepointsfitted
= index
+ length
;
4745 if (args
->linesfilled
)
4746 (*args
->linesfilled
)++;
4751 /* Find the smallest rectangle that bounds the text when it is printed in rect
4752 * according to the format options listed in format. If rect has 0 width and
4753 * height, then just find the smallest rectangle that bounds the text when it's
4754 * printed at location (rect->X, rect-Y). */
4755 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4756 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4757 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4758 INT
*codepointsfitted
, INT
*linesfilled
)
4760 HFONT oldfont
, gdifont
;
4761 struct measure_string_args args
;
4762 HDC temp_hdc
=NULL
, hdc
;
4768 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4769 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4770 bounds
, codepointsfitted
, linesfilled
);
4772 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4773 return InvalidParameter
;
4777 hdc
= temp_hdc
= CreateCompatibleDC(0);
4778 if (!temp_hdc
) return OutOfMemory
;
4781 hdc
= graphics
->hdc
;
4783 if(linesfilled
) *linesfilled
= 0;
4784 if(codepointsfitted
) *codepointsfitted
= 0;
4787 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4795 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4796 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4797 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4798 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4799 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4801 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4802 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4804 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
4805 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
4806 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
4807 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
4808 if (scaled_rect
.Width
>= 0.5)
4810 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
4811 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4814 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4815 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4817 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
4818 oldfont
= SelectObject(hdc
, gdifont
);
4820 bounds
->X
= rect
->X
;
4821 bounds
->Y
= rect
->Y
;
4822 bounds
->Width
= 0.0;
4823 bounds
->Height
= 0.0;
4825 args
.bounds
= bounds
;
4826 args
.codepointsfitted
= &glyphs
;
4827 args
.linesfilled
= &lines
;
4830 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
4831 measure_string_callback
, &args
);
4833 if (linesfilled
) *linesfilled
= lines
;
4834 if (codepointsfitted
) *codepointsfitted
= glyphs
;
4837 bounds
->Width
+= margin_x
* 2.0;
4839 SelectObject(hdc
, oldfont
);
4840 DeleteObject(gdifont
);
4848 struct draw_string_args
{
4849 GpGraphics
*graphics
;
4850 GDIPCONST GpBrush
*brush
;
4851 REAL x
, y
, rel_width
, rel_height
, ascent
;
4854 static GpStatus
draw_string_callback(HDC hdc
,
4855 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4856 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4857 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4858 INT underlined_index_count
, void *user_data
)
4860 struct draw_string_args
*args
= user_data
;
4864 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
4865 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
4867 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
4868 args
->brush
, &position
,
4869 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
4871 if (stat
== Ok
&& underlined_index_count
)
4873 OUTLINETEXTMETRICW otm
;
4874 REAL underline_y
, underline_height
;
4877 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
4879 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
4880 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
4882 for (i
=0; i
<underlined_index_count
; i
++)
4884 REAL start_x
, end_x
;
4886 INT ofs
= underlined_indexes
[i
] - index
;
4888 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
4889 start_x
= text_size
.cx
/ args
->rel_width
;
4891 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
4892 end_x
= text_size
.cx
/ args
->rel_width
;
4894 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
4901 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4902 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4903 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4907 GpPointF pt
[3], rectcpy
[4];
4909 REAL rel_width
, rel_height
, margin_x
;
4910 INT save_state
, format_flags
= 0;
4912 struct draw_string_args args
;
4914 HDC hdc
, temp_hdc
=NULL
;
4915 TEXTMETRICW textmetric
;
4917 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4918 length
, font
, debugstr_rectf(rect
), format
, brush
);
4920 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4921 return InvalidParameter
;
4925 hdc
= graphics
->hdc
;
4929 hdc
= temp_hdc
= CreateCompatibleDC(0);
4933 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4935 format_flags
= format
->attr
;
4937 /* Should be no need to explicitly test for StringAlignmentNear as
4938 * that is default behavior if no alignment is passed. */
4939 if(format
->vertalign
!= StringAlignmentNear
){
4940 RectF bounds
, in_rect
= *rect
;
4941 in_rect
.Height
= 0.0; /* avoid height clipping */
4942 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
4944 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
4946 if(format
->vertalign
== StringAlignmentCenter
)
4947 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4948 else if(format
->vertalign
== StringAlignmentFar
)
4949 offsety
= (rect
->Height
- bounds
.Height
);
4951 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
4954 save_state
= SaveDC(hdc
);
4962 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4963 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4964 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4965 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4966 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4968 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
4969 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
4970 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
4971 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
4972 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
4974 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
4975 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
4977 scaled_rect
.X
= margin_x
* rel_width
;
4978 scaled_rect
.Y
= 0.0;
4979 scaled_rect
.Width
= rel_width
* rect
->Width
;
4980 scaled_rect
.Height
= rel_height
* rect
->Height
;
4981 if (scaled_rect
.Width
>= 0.5)
4983 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
4984 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
4987 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
4988 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
4990 if (!(format_flags
& StringFormatFlagsNoClip
) &&
4991 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23)
4993 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4994 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
4995 SelectClipRgn(hdc
, rgn
);
4998 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
4999 SelectObject(hdc
, gdifont
);
5001 args
.graphics
= graphics
;
5005 args
.y
= rect
->Y
+ offsety
;
5007 args
.rel_width
= rel_width
;
5008 args
.rel_height
= rel_height
;
5010 GetTextMetricsW(hdc
, &textmetric
);
5011 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5013 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5014 draw_string_callback
, &args
);
5017 DeleteObject(gdifont
);
5019 RestoreDC(hdc
, save_state
);
5026 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5028 TRACE("(%p)\n", graphics
);
5031 return InvalidParameter
;
5036 return GdipSetInfinite(graphics
->clip
);
5039 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5041 TRACE("(%p)\n", graphics
);
5044 return InvalidParameter
;
5049 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5052 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5054 return GdipEndContainer(graphics
, state
);
5057 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5058 GpMatrixOrder order
)
5060 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5063 return InvalidParameter
;
5068 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5071 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5073 return GdipBeginContainer2(graphics
, state
);
5076 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5077 GraphicsContainer
*state
)
5079 GraphicsContainerItem
*container
;
5082 TRACE("(%p, %p)\n", graphics
, state
);
5084 if(!graphics
|| !state
)
5085 return InvalidParameter
;
5087 sts
= init_container(&container
, graphics
);
5091 list_add_head(&graphics
->containers
, &container
->entry
);
5092 *state
= graphics
->contid
= container
->contid
;
5097 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5099 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5100 return NotImplemented
;
5103 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5105 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5106 return NotImplemented
;
5109 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5111 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5112 return NotImplemented
;
5115 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5118 GraphicsContainerItem
*container
, *container2
;
5120 TRACE("(%p, %x)\n", graphics
, state
);
5123 return InvalidParameter
;
5125 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5126 if(container
->contid
== state
)
5130 /* did not find a matching container */
5131 if(&container
->entry
== &graphics
->containers
)
5134 sts
= restore_container(graphics
, container
);
5138 /* remove all of the containers on top of the found container */
5139 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5140 if(container
->contid
== state
)
5142 list_remove(&container
->entry
);
5143 delete_container(container
);
5146 list_remove(&container
->entry
);
5147 delete_container(container
);
5152 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5153 REAL sy
, GpMatrixOrder order
)
5155 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5158 return InvalidParameter
;
5163 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5166 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5169 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5171 if(!graphics
|| !srcgraphics
)
5172 return InvalidParameter
;
5174 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5177 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5178 CompositingMode mode
)
5180 TRACE("(%p, %d)\n", graphics
, mode
);
5183 return InvalidParameter
;
5188 graphics
->compmode
= mode
;
5193 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5194 CompositingQuality quality
)
5196 TRACE("(%p, %d)\n", graphics
, quality
);
5199 return InvalidParameter
;
5204 graphics
->compqual
= quality
;
5209 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5210 InterpolationMode mode
)
5212 TRACE("(%p, %d)\n", graphics
, mode
);
5214 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5215 return InvalidParameter
;
5220 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5221 mode
= InterpolationModeBilinear
;
5223 if (mode
== InterpolationModeHighQuality
)
5224 mode
= InterpolationModeHighQualityBicubic
;
5226 graphics
->interpolation
= mode
;
5231 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5233 TRACE("(%p, %.2f)\n", graphics
, scale
);
5235 if(!graphics
|| (scale
<= 0.0))
5236 return InvalidParameter
;
5241 graphics
->scale
= scale
;
5246 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5248 TRACE("(%p, %d)\n", graphics
, unit
);
5251 return InvalidParameter
;
5256 if(unit
== UnitWorld
)
5257 return InvalidParameter
;
5259 graphics
->unit
= unit
;
5264 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5267 TRACE("(%p, %d)\n", graphics
, mode
);
5270 return InvalidParameter
;
5275 graphics
->pixeloffset
= mode
;
5280 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5284 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5287 FIXME("value is unused in rendering\n");
5290 return InvalidParameter
;
5292 graphics
->origin_x
= x
;
5293 graphics
->origin_y
= y
;
5298 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5300 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5302 if (!graphics
|| !x
|| !y
)
5303 return InvalidParameter
;
5305 *x
= graphics
->origin_x
;
5306 *y
= graphics
->origin_y
;
5311 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5313 TRACE("(%p, %d)\n", graphics
, mode
);
5316 return InvalidParameter
;
5321 graphics
->smoothing
= mode
;
5326 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5328 TRACE("(%p, %d)\n", graphics
, contrast
);
5331 return InvalidParameter
;
5333 graphics
->textcontrast
= contrast
;
5338 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5339 TextRenderingHint hint
)
5341 TRACE("(%p, %d)\n", graphics
, hint
);
5343 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5344 return InvalidParameter
;
5349 graphics
->texthint
= hint
;
5354 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5356 TRACE("(%p, %p)\n", graphics
, matrix
);
5358 if(!graphics
|| !matrix
)
5359 return InvalidParameter
;
5364 TRACE("%f,%f,%f,%f,%f,%f\n",
5365 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5366 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5368 graphics
->worldtrans
= *matrix
;
5373 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5374 REAL dy
, GpMatrixOrder order
)
5376 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5379 return InvalidParameter
;
5384 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5387 /*****************************************************************************
5388 * GdipSetClipHrgn [GDIPLUS.@]
5390 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5395 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5398 return InvalidParameter
;
5400 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5404 status
= GdipSetClipRegion(graphics
, region
, mode
);
5406 GdipDeleteRegion(region
);
5410 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5412 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5415 return InvalidParameter
;
5420 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5423 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5424 REAL width
, REAL height
,
5429 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5432 return InvalidParameter
;
5440 rect
.Height
= height
;
5442 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5445 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5446 INT width
, INT height
,
5449 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5452 return InvalidParameter
;
5457 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5460 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5463 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5465 if(!graphics
|| !region
)
5466 return InvalidParameter
;
5471 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5474 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5479 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5482 FIXME("not implemented\n");
5484 return NotImplemented
;
5487 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5493 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5495 if(!graphics
|| !pen
|| count
<=0)
5496 return InvalidParameter
;
5503 FIXME("graphics object has no HDC\n");
5507 pti
= GdipAlloc(sizeof(POINT
) * count
);
5509 save_state
= prepare_dc(graphics
, pen
);
5510 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5512 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5513 Polygon(graphics
->hdc
, pti
, count
);
5515 restore_dc(graphics
, save_state
);
5521 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5528 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5530 if(count
<=0) return InvalidParameter
;
5531 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5533 for(i
= 0;i
< count
; i
++){
5534 ptf
[i
].X
= (REAL
)points
[i
].X
;
5535 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5538 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5544 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5546 TRACE("(%p, %p)\n", graphics
, dpi
);
5548 if(!graphics
|| !dpi
)
5549 return InvalidParameter
;
5554 *dpi
= graphics
->xres
;
5558 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5560 TRACE("(%p, %p)\n", graphics
, dpi
);
5562 if(!graphics
|| !dpi
)
5563 return InvalidParameter
;
5568 *dpi
= graphics
->yres
;
5572 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5573 GpMatrixOrder order
)
5578 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5580 if(!graphics
|| !matrix
)
5581 return InvalidParameter
;
5586 m
= graphics
->worldtrans
;
5588 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
5590 graphics
->worldtrans
= m
;
5595 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5596 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
5598 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
5602 TRACE("(%p, %p)\n", graphics
, hdc
);
5604 if(!graphics
|| !hdc
)
5605 return InvalidParameter
;
5610 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5612 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
5614 else if (!graphics
->hdc
|| graphics
->alpha_hdc
||
5615 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
5617 /* Create a fake HDC and fill it with a constant color. */
5621 BITMAPINFOHEADER bmih
;
5624 stat
= get_graphics_bounds(graphics
, &bounds
);
5628 graphics
->temp_hbitmap_width
= bounds
.Width
;
5629 graphics
->temp_hbitmap_height
= bounds
.Height
;
5631 bmih
.biSize
= sizeof(bmih
);
5632 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
5633 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
5635 bmih
.biBitCount
= 32;
5636 bmih
.biCompression
= BI_RGB
;
5637 bmih
.biSizeImage
= 0;
5638 bmih
.biXPelsPerMeter
= 0;
5639 bmih
.biYPelsPerMeter
= 0;
5641 bmih
.biClrImportant
= 0;
5643 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
5644 (void**)&graphics
->temp_bits
, NULL
, 0);
5646 return GenericError
;
5648 temp_hdc
= CreateCompatibleDC(0);
5651 DeleteObject(hbitmap
);
5652 return GenericError
;
5655 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5656 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
5658 SelectObject(temp_hdc
, hbitmap
);
5660 graphics
->temp_hbitmap
= hbitmap
;
5661 *hdc
= graphics
->temp_hdc
= temp_hdc
;
5665 *hdc
= graphics
->hdc
;
5669 graphics
->busy
= TRUE
;
5674 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
5678 TRACE("(%p, %p)\n", graphics
, hdc
);
5680 if(!graphics
|| !hdc
|| !graphics
->busy
)
5681 return InvalidParameter
;
5683 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5685 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
5687 else if (graphics
->temp_hdc
== hdc
)
5692 /* Find the pixels that have changed, and mark them as opaque. */
5693 pos
= (DWORD
*)graphics
->temp_bits
;
5694 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
5696 if (*pos
!= DC_BACKGROUND_KEY
)
5703 /* Write the changed pixels to the real target. */
5704 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
5705 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
5706 graphics
->temp_hbitmap_width
* 4);
5709 DeleteDC(graphics
->temp_hdc
);
5710 DeleteObject(graphics
->temp_hbitmap
);
5711 graphics
->temp_hdc
= NULL
;
5712 graphics
->temp_hbitmap
= NULL
;
5714 else if (hdc
!= graphics
->hdc
)
5716 stat
= InvalidParameter
;
5720 graphics
->busy
= FALSE
;
5725 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
5730 TRACE("(%p, %p)\n", graphics
, region
);
5732 if(!graphics
|| !region
)
5733 return InvalidParameter
;
5738 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
5741 /* free everything except root node and header */
5742 delete_element(®ion
->node
);
5743 memcpy(region
, clip
, sizeof(GpRegion
));
5749 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5750 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
5753 REAL scale_x
, scale_y
;
5755 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5757 if (dst_space
!= src_space
)
5759 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
5760 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
5762 if(graphics
->unit
!= UnitDisplay
)
5764 scale_x
*= graphics
->scale
;
5765 scale_y
*= graphics
->scale
;
5768 /* transform from src_space to CoordinateSpacePage */
5771 case CoordinateSpaceWorld
:
5772 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
5774 case CoordinateSpacePage
:
5776 case CoordinateSpaceDevice
:
5777 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
5781 /* transform from CoordinateSpacePage to dst_space */
5784 case CoordinateSpaceWorld
:
5786 GpMatrix inverted_transform
= graphics
->worldtrans
;
5787 stat
= GdipInvertMatrix(&inverted_transform
);
5789 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
5792 case CoordinateSpacePage
:
5794 case CoordinateSpaceDevice
:
5795 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
5802 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5803 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
5808 if(!graphics
|| !points
|| count
<= 0)
5809 return InvalidParameter
;
5814 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5816 if (src_space
== dst_space
) return Ok
;
5818 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
5819 if (stat
!= Ok
) return stat
;
5821 return GdipTransformMatrixPoints(&matrix
, points
, count
);
5824 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
5825 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
5831 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
5834 return InvalidParameter
;
5836 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
5840 for(i
= 0; i
< count
; i
++){
5841 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5842 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5845 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5848 for(i
= 0; i
< count
; i
++){
5849 points
[i
].X
= gdip_round(pointsF
[i
].X
);
5850 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
5857 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5869 /*****************************************************************************
5870 * GdipTranslateClip [GDIPLUS.@]
5872 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5874 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5877 return InvalidParameter
;
5882 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5885 /*****************************************************************************
5886 * GdipTranslateClipI [GDIPLUS.@]
5888 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5890 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5893 return InvalidParameter
;
5898 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
5902 /*****************************************************************************
5903 * GdipMeasureDriverString [GDIPLUS.@]
5905 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5906 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
5907 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
5909 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
5912 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
5914 TEXTMETRICW textmetric
;
5915 const WORD
*glyph_indices
;
5916 WORD
*dynamic_glyph_indices
=NULL
;
5917 REAL rel_width
, rel_height
, ascent
, descent
;
5920 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
5922 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
5923 return InvalidParameter
;
5926 length
= strlenW(text
);
5930 boundingBox
->X
= 0.0;
5931 boundingBox
->Y
= 0.0;
5932 boundingBox
->Width
= 0.0;
5933 boundingBox
->Height
= 0.0;
5936 if (flags
& unsupported_flags
)
5937 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
5939 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
5941 hdc
= CreateCompatibleDC(0);
5942 SelectObject(hdc
, hfont
);
5944 GetTextMetricsW(hdc
, &textmetric
);
5954 GpMatrix xform
= *matrix
;
5955 GdipTransformMatrixPoints(&xform
, pt
, 3);
5957 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5958 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5959 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5960 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5961 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5963 if (flags
& DriverStringOptionsCmapLookup
)
5965 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
5969 DeleteObject(hfont
);
5973 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
5976 glyph_indices
= text
;
5978 min_x
= max_x
= x
= positions
[0].X
;
5979 min_y
= max_y
= y
= positions
[0].Y
;
5981 ascent
= textmetric
.tmAscent
/ rel_height
;
5982 descent
= textmetric
.tmDescent
/ rel_height
;
5984 for (i
=0; i
<length
; i
++)
5989 if (!(flags
& DriverStringOptionsRealizedAdvance
))
5995 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
5996 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
5998 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
5999 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6000 if (min_x
> x
) min_x
= x
;
6002 x
+= char_width
/ rel_width
;
6004 if (max_x
< x
) max_x
= x
;
6007 GdipFree(dynamic_glyph_indices
);
6009 DeleteObject(hfont
);
6011 boundingBox
->X
= min_x
;
6012 boundingBox
->Y
= min_y
;
6013 boundingBox
->Width
= max_x
- min_x
;
6014 boundingBox
->Height
= max_y
- min_y
;
6019 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6020 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6021 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6022 INT flags
, GDIPCONST GpMatrix
*matrix
)
6024 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6030 if (flags
& unsupported_flags
)
6031 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6033 if (!(flags
& DriverStringOptionsCmapLookup
))
6034 eto_flags
|= ETO_GLYPH_INDEX
;
6036 save_state
= SaveDC(graphics
->hdc
);
6037 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6038 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6041 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6043 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6044 SelectObject(graphics
->hdc
, hfont
);
6046 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6048 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6050 RestoreDC(graphics
->hdc
, save_state
);
6052 DeleteObject(hfont
);
6057 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6058 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6059 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6060 INT flags
, GDIPCONST GpMatrix
*matrix
)
6062 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6064 PointF
*real_positions
, real_position
;
6068 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6069 DWORD max_glyphsize
=0;
6070 GLYPHMETRICS glyphmetrics
;
6071 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6074 int text_mask_stride
;
6076 int pixel_data_stride
;
6078 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6083 if (!(flags
& DriverStringOptionsCmapLookup
))
6084 ggo_flags
|= GGO_GLYPH_INDEX
;
6086 if (flags
& unsupported_flags
)
6087 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6089 pti
= GdipAlloc(sizeof(POINT
) * length
);
6093 if (flags
& DriverStringOptionsRealizedAdvance
)
6095 real_position
= positions
[0];
6097 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6101 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6102 if (!real_positions
)
6108 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6110 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6112 GdipFree(real_positions
);
6115 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6117 hdc
= CreateCompatibleDC(0);
6118 SelectObject(hdc
, hfont
);
6120 /* Get the boundaries of the text to be drawn */
6121 for (i
=0; i
<length
; i
++)
6124 int left
, top
, right
, bottom
;
6126 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6127 &glyphmetrics
, 0, NULL
, &identity
);
6129 if (glyphsize
== GDI_ERROR
)
6131 ERR("GetGlyphOutlineW failed\n");
6134 DeleteObject(hfont
);
6135 return GenericError
;
6138 if (glyphsize
> max_glyphsize
)
6139 max_glyphsize
= glyphsize
;
6141 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6142 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6143 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6144 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6146 if (left
< min_x
) min_x
= left
;
6147 if (top
< min_y
) min_y
= top
;
6148 if (right
> max_x
) max_x
= right
;
6149 if (bottom
> max_y
) max_y
= bottom
;
6151 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6153 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6154 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6158 glyph_mask
= GdipAlloc(max_glyphsize
);
6159 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6160 text_mask_stride
= max_x
- min_x
;
6162 if (!(glyph_mask
&& text_mask
))
6164 GdipFree(glyph_mask
);
6165 GdipFree(text_mask
);
6168 DeleteObject(hfont
);
6172 /* Generate a mask for the text */
6173 for (i
=0; i
<length
; i
++)
6175 int left
, top
, stride
;
6177 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6178 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6180 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6181 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6182 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6184 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6186 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6187 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6188 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6190 *text_val
= min(64, *text_val
+ *glyph_val
);
6199 DeleteObject(hfont
);
6200 GdipFree(glyph_mask
);
6202 /* get the brush data */
6203 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6206 GdipFree(text_mask
);
6210 pixel_area
.X
= min_x
;
6211 pixel_area
.Y
= min_y
;
6212 pixel_area
.Width
= max_x
- min_x
;
6213 pixel_area
.Height
= max_y
- min_y
;
6214 pixel_data_stride
= pixel_area
.Width
* 4;
6216 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6219 GdipFree(text_mask
);
6220 GdipFree(pixel_data
);
6224 /* multiply the brush data by the mask */
6225 for (y
=0; y
<pixel_area
.Height
; y
++)
6227 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6228 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6229 for (x
=0; x
<pixel_area
.Width
; x
++)
6231 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6237 GdipFree(text_mask
);
6239 /* draw the result */
6240 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6241 pixel_area
.Height
, pixel_data_stride
);
6243 GdipFree(pixel_data
);
6248 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6249 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6250 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6251 INT flags
, GDIPCONST GpMatrix
*matrix
)
6253 GpStatus stat
= NotImplemented
;
6256 length
= strlenW(text
);
6258 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6259 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6260 brush
->bt
== BrushTypeSolidColor
&&
6261 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6262 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6263 brush
, positions
, flags
, matrix
);
6264 if (stat
== NotImplemented
)
6265 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6266 brush
, positions
, flags
, matrix
);
6270 /*****************************************************************************
6271 * GdipDrawDriverString [GDIPLUS.@]
6273 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6274 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6275 GDIPCONST PointF
*positions
, INT flags
,
6276 GDIPCONST GpMatrix
*matrix
)
6278 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6280 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6281 return InvalidParameter
;
6283 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6284 brush
, positions
, flags
, matrix
);
6287 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6288 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6290 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6291 return NotImplemented
;
6294 /*****************************************************************************
6295 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6297 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6302 TRACE("(%p, %p)\n", graphics
, res
);
6304 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6307 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6310 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6313 GdipDeleteRegion(rgn
);
6317 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6321 TRACE("(%p) stub\n", graphics
);
6324 FIXME("not implemented\n");
6326 return NotImplemented
;