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
24 //#include "winbase.h"
25 //#include "winuser.h"
27 #include <wine/unicode.h>
30 //#include "objbase.h"
37 //#include "gdiplus.h"
38 #include "gdiplus_private.h"
40 #include <wine/debug.h>
41 //#include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
45 /* Mike "tamlin" Nordell 2012-09-14 for ReactOS:
46 * NOTE: Wine uses per-GpGraphics id's ('contid' starting from zero in
47 * every GpGraphics). Windows seems to use process-global id's, or at
48 * least more unique id's.
49 * This have the following implications. It:
50 * 1. fails the current gdiplus test case.
51 * 2. is not what Windows does.
53 * We therefore "obfuscate" the 'contid' a little to more match Windows'
54 * behaviour. The observable behviour should still remain the same,
55 * except for handing out more "unique" id's.
57 #define GDIP_CONTID_STEP 64
58 static volatile LONG g_priv_contid
= GDIP_CONTID_STEP
;
59 #define GDIP_GET_NEW_CONTID_FOR(pGpGraphics) \
60 (UINT)(InterlockedExchangeAdd(&g_priv_contid,GDIP_CONTID_STEP))
62 /* looks-right constants */
63 #define ANCHOR_WIDTH (2.0)
64 #define MAX_ITERS (50)
66 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
67 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
68 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
69 INT flags
, GDIPCONST GpMatrix
*matrix
);
71 /* Converts angle (in degrees) to x/y coordinates */
72 static void deg2xy(REAL angle
, REAL x_0
, REAL y_0
, REAL
*x
, REAL
*y
)
74 REAL radAngle
, hypotenuse
;
76 radAngle
= deg2rad(angle
);
77 hypotenuse
= 50.0; /* arbitrary */
79 *x
= x_0
+ cos(radAngle
) * hypotenuse
;
80 *y
= y_0
+ sin(radAngle
) * hypotenuse
;
83 /* Converts from gdiplus path point type to gdi path point type. */
84 static BYTE
convert_path_point_type(BYTE type
)
88 switch(type
& PathPointTypePathTypeMask
){
89 case PathPointTypeBezier
:
92 case PathPointTypeLine
:
95 case PathPointTypeStart
:
99 ERR("Bad point type\n");
103 if(type
& PathPointTypeCloseSubpath
)
104 ret
|= PT_CLOSEFIGURE
;
109 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
115 case BrushTypeSolidColor
:
117 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
121 case BrushTypeHatchFill
:
123 const GpHatch
*hatch
= (const GpHatch
*)brush
;
124 argb
= hatch
->forecol
;
127 case BrushTypeLinearGradient
:
129 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
130 argb
= line
->startcolor
;
133 case BrushTypePathGradient
:
135 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
136 argb
= grad
->centercolor
;
140 FIXME("unhandled brush type %d\n", brush
->bt
);
144 return ARGB2COLORREF(argb
);
147 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
150 BITMAPINFOHEADER bmih
;
154 bmih
.biSize
= sizeof(bmih
);
158 bmih
.biBitCount
= 32;
159 bmih
.biCompression
= BI_RGB
;
160 bmih
.biSizeImage
= 0;
162 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
165 const char *hatch_data
;
167 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
169 for (y
= 0; y
< 8; y
++)
171 for (x
= 0; x
< 8; x
++)
173 if (hatch_data
[y
] & (0x80 >> x
))
174 bits
[y
* 8 + x
] = hatch
->forecol
;
176 bits
[y
* 8 + x
] = hatch
->backcol
;
182 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
184 for (y
= 0; y
< 64; y
++)
185 bits
[y
] = hatch
->forecol
;
192 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
196 case BrushTypeSolidColor
:
198 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
199 lb
->lbStyle
= BS_SOLID
;
200 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
205 case BrushTypeHatchFill
:
207 const GpHatch
*hatch
= (const GpHatch
*)brush
;
210 hbmp
= create_hatch_bitmap(hatch
);
211 if (!hbmp
) return OutOfMemory
;
213 lb
->lbStyle
= BS_PATTERN
;
215 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
220 FIXME("unhandled brush type %d\n", brush
->bt
);
221 lb
->lbStyle
= BS_SOLID
;
222 lb
->lbColor
= get_gdi_brush_color(brush
);
228 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
233 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
239 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
244 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
246 gdibrush
= CreateBrushIndirect(&lb
);
247 free_gdi_logbrush(&lb
);
252 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
257 INT save_state
, i
, numdashes
;
259 DWORD dash_array
[MAX_DASHLEN
];
261 save_state
= SaveDC(graphics
->hdc
);
263 EndPath(graphics
->hdc
);
265 if(pen
->unit
== UnitPixel
){
269 /* Get an estimate for the amount the pen width is affected by the world
270 * transform. (This is similar to what some of the wine drivers do.) */
275 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
276 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
277 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
279 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
282 if(pen
->dash
== DashStyleCustom
){
283 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
285 TRACE("dashes are: ");
286 for(i
= 0; i
< numdashes
; i
++){
287 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
288 TRACE("%d, ", dash_array
[i
]);
290 TRACE("\n and the pen style is %x\n", pen
->style
);
292 create_gdi_logbrush(pen
->brush
, &lb
);
293 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
294 numdashes
, dash_array
);
295 free_gdi_logbrush(&lb
);
299 create_gdi_logbrush(pen
->brush
, &lb
);
300 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
301 free_gdi_logbrush(&lb
);
304 SelectObject(graphics
->hdc
, gdipen
);
309 static void restore_dc(GpGraphics
*graphics
, INT state
)
311 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
312 RestoreDC(graphics
->hdc
, state
);
315 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
316 GpCoordinateSpace src_space
, GpMatrix
*matrix
);
318 /* This helper applies all the changes that the points listed in ptf need in
319 * order to be drawn on the device context. In the end, this should include at
321 * -scaling by page unit
322 * -applying world transformation
323 * -converting from float to int
324 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
325 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
326 * gdi to draw, and these functions would irreparably mess with line widths.
328 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
329 GpPointF
*ptf
, INT count
)
331 REAL scale_x
, scale_y
;
335 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
336 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
338 /* apply page scale */
339 if(graphics
->unit
!= UnitDisplay
)
341 scale_x
*= graphics
->scale
;
342 scale_y
*= graphics
->scale
;
345 matrix
= graphics
->worldtrans
;
346 GdipScaleMatrix(&matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
347 GdipTransformMatrixPoints(&matrix
, ptf
, count
);
349 for(i
= 0; i
< count
; i
++){
350 pti
[i
].x
= gdip_round(ptf
[i
].X
);
351 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
355 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
356 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
358 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
360 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
362 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
363 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
369 bf
.BlendOp
= AC_SRC_OVER
;
371 bf
.SourceConstantAlpha
= 255;
372 bf
.AlphaFormat
= AC_SRC_ALPHA
;
374 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
375 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
379 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
381 return GdipGetRegionHRgn(graphics
->clip
, graphics
, hrgn
);
384 /* Draw non-premultiplied ARGB data to the given graphics object */
385 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
386 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
388 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
391 for (x
=0; x
<src_width
; x
++)
393 for (y
=0; y
<src_height
; y
++)
395 ARGB dst_color
, src_color
;
396 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
397 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
398 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
405 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
406 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
410 BITMAPINFOHEADER bih
;
413 hdc
= CreateCompatibleDC(0);
415 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
416 bih
.biWidth
= src_width
;
417 bih
.biHeight
= -src_height
;
420 bih
.biCompression
= BI_RGB
;
422 bih
.biXPelsPerMeter
= 0;
423 bih
.biYPelsPerMeter
= 0;
425 bih
.biClrImportant
= 0;
427 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
428 (void**)&temp_bits
, NULL
, 0);
430 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
431 4 * src_width
, src
, src_stride
);
433 SelectObject(hdc
, hbitmap
);
434 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
435 hdc
, 0, 0, src_width
, src_height
);
437 DeleteObject(hbitmap
);
442 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
443 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
)
447 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
452 HRGN hrgn
, visible_rgn
;
454 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
458 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
467 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
468 DeleteObject(visible_rgn
);
472 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
474 size
= GetRegionData(hrgn
, 0, NULL
);
476 rgndata
= GdipAlloc(size
);
483 GetRegionData(hrgn
, size
, rgndata
);
485 rects
= (RECT
*)rgndata
->Buffer
;
487 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
489 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
490 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
491 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
501 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
503 ERR("This should not be used for metafiles; fix caller\n");
504 return NotImplemented
;
511 stat
= get_clip_hrgn(graphics
, &hrgn
);
516 save
= SaveDC(graphics
->hdc
);
519 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
522 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
524 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
525 src_height
, src_stride
);
527 RestoreDC(graphics
->hdc
, save
);
535 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
536 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
538 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
);
541 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
547 a1
= (start
>> 24) & 0xff;
548 a2
= (end
>> 24) & 0xff;
550 a3
= (int)(a1
*(1.0f
- position
)+a2
*(position
));
554 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
555 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
559 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
563 /* clamp to between 0.0 and 1.0, using the wrap mode */
564 if (brush
->wrap
== WrapModeTile
)
566 position
= fmodf(position
, 1.0f
);
567 if (position
< 0.0f
) position
+= 1.0f
;
569 else /* WrapModeFlip* */
571 position
= fmodf(position
, 2.0f
);
572 if (position
< 0.0f
) position
+= 2.0f
;
573 if (position
> 1.0f
) position
= 2.0f
- position
;
576 if (brush
->blendcount
== 1)
581 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
584 /* locate the blend positions surrounding this position */
585 while (position
> brush
->blendpos
[i
])
588 /* interpolate between the blend positions */
589 left_blendpos
= brush
->blendpos
[i
-1];
590 left_blendfac
= brush
->blendfac
[i
-1];
591 right_blendpos
= brush
->blendpos
[i
];
592 right_blendfac
= brush
->blendfac
[i
];
593 range
= right_blendpos
- left_blendpos
;
594 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
595 right_blendfac
* (position
- left_blendpos
)) / range
;
598 if (brush
->pblendcount
== 0)
599 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
603 ARGB left_blendcolor
, right_blendcolor
;
604 REAL left_blendpos
, right_blendpos
;
606 /* locate the blend colors surrounding this position */
607 while (blendfac
> brush
->pblendpos
[i
])
610 /* interpolate between the blend colors */
611 left_blendpos
= brush
->pblendpos
[i
-1];
612 left_blendcolor
= brush
->pblendcolor
[i
-1];
613 right_blendpos
= brush
->pblendpos
[i
];
614 right_blendcolor
= brush
->pblendcolor
[i
];
615 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
616 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
620 static ARGB
transform_color(ARGB color
, const ColorMatrix
*matrix
)
624 unsigned char a
, r
, g
, b
;
626 val
[0] = ((color
>> 16) & 0xff) / 255.0; /* red */
627 val
[1] = ((color
>> 8) & 0xff) / 255.0; /* green */
628 val
[2] = (color
& 0xff) / 255.0; /* blue */
629 val
[3] = ((color
>> 24) & 0xff) / 255.0; /* alpha */
630 val
[4] = 1.0; /* translation */
637 res
[i
] += matrix
->m
[j
][i
] * val
[j
];
640 a
= min(max(floorf(res
[3]*255.0), 0.0), 255.0);
641 r
= min(max(floorf(res
[0]*255.0), 0.0), 255.0);
642 g
= min(max(floorf(res
[1]*255.0), 0.0), 255.0);
643 b
= min(max(floorf(res
[2]*255.0), 0.0), 255.0);
645 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
648 static int color_is_gray(ARGB color
)
650 unsigned char r
, g
, b
;
652 r
= (color
>> 16) & 0xff;
653 g
= (color
>> 8) & 0xff;
656 return (r
== g
) && (g
== b
);
659 static void apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
660 UINT width
, UINT height
, INT stride
, ColorAdjustType type
)
664 if (attributes
->colorkeys
[type
].enabled
||
665 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
667 const struct color_key
*key
;
668 BYTE min_blue
, min_green
, min_red
;
669 BYTE max_blue
, max_green
, max_red
;
671 if (attributes
->colorkeys
[type
].enabled
)
672 key
= &attributes
->colorkeys
[type
];
674 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
676 min_blue
= key
->low
&0xff;
677 min_green
= (key
->low
>>8)&0xff;
678 min_red
= (key
->low
>>16)&0xff;
680 max_blue
= key
->high
&0xff;
681 max_green
= (key
->high
>>8)&0xff;
682 max_red
= (key
->high
>>16)&0xff;
684 for (x
=0; x
<width
; x
++)
685 for (y
=0; y
<height
; y
++)
688 BYTE blue
, green
, red
;
689 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
690 blue
= *src_color
&0xff;
691 green
= (*src_color
>>8)&0xff;
692 red
= (*src_color
>>16)&0xff;
693 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
694 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
695 *src_color
= 0x00000000;
699 if (attributes
->colorremaptables
[type
].enabled
||
700 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
702 const struct color_remap_table
*table
;
704 if (attributes
->colorremaptables
[type
].enabled
)
705 table
= &attributes
->colorremaptables
[type
];
707 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
709 for (x
=0; x
<width
; x
++)
710 for (y
=0; y
<height
; y
++)
713 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
714 for (i
=0; i
<table
->mapsize
; i
++)
716 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
718 *src_color
= table
->colormap
[i
].newColor
.Argb
;
725 if (attributes
->colormatrices
[type
].enabled
||
726 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
728 const struct color_matrix
*colormatrices
;
730 if (attributes
->colormatrices
[type
].enabled
)
731 colormatrices
= &attributes
->colormatrices
[type
];
733 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
735 for (x
=0; x
<width
; x
++)
736 for (y
=0; y
<height
; y
++)
739 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
741 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
742 !color_is_gray(*src_color
))
744 *src_color
= transform_color(*src_color
, &colormatrices
->colormatrix
);
746 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
748 *src_color
= transform_color(*src_color
, &colormatrices
->graymatrix
);
753 if (attributes
->gamma_enabled
[type
] ||
754 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
758 if (attributes
->gamma_enabled
[type
])
759 gamma
= attributes
->gamma
[type
];
761 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
763 for (x
=0; x
<width
; x
++)
764 for (y
=0; y
<height
; y
++)
767 BYTE blue
, green
, red
;
768 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
770 blue
= *src_color
&0xff;
771 green
= (*src_color
>>8)&0xff;
772 red
= (*src_color
>>16)&0xff;
774 /* FIXME: We should probably use a table for this. */
775 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
776 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
777 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
779 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
784 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
785 * bitmap that contains all the pixels we may need to draw it. */
786 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
787 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
790 INT left
, top
, right
, bottom
;
792 switch (interpolation
)
794 case InterpolationModeHighQualityBilinear
:
795 case InterpolationModeHighQualityBicubic
:
796 /* FIXME: Include a greater range for the prefilter? */
797 case InterpolationModeBicubic
:
798 case InterpolationModeBilinear
:
799 left
= (INT
)(floorf(srcx
));
800 top
= (INT
)(floorf(srcy
));
801 right
= (INT
)(ceilf(srcx
+srcwidth
));
802 bottom
= (INT
)(ceilf(srcy
+srcheight
));
804 case InterpolationModeNearestNeighbor
:
806 left
= gdip_round(srcx
);
807 top
= gdip_round(srcy
);
808 right
= gdip_round(srcx
+srcwidth
);
809 bottom
= gdip_round(srcy
+srcheight
);
813 if (wrap
== WrapModeClamp
)
819 if (right
>= bitmap
->width
)
820 right
= bitmap
->width
-1;
821 if (bottom
>= bitmap
->height
)
822 bottom
= bitmap
->height
-1;
826 /* In some cases we can make the rectangle smaller here, but the logic
827 * is hard to get right, and tiling suggests we're likely to use the
828 * entire source image. */
829 if (left
< 0 || right
>= bitmap
->width
)
832 right
= bitmap
->width
-1;
835 if (top
< 0 || bottom
>= bitmap
->height
)
838 bottom
= bitmap
->height
-1;
844 rect
->Width
= right
- left
+ 1;
845 rect
->Height
= bottom
- top
+ 1;
848 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
849 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
851 if (attributes
->wrap
== WrapModeClamp
)
853 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
854 return attributes
->outside_color
;
858 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
860 x
= width
*2 + x
% (width
* 2);
862 y
= height
*2 + y
% (height
* 2);
864 if ((attributes
->wrap
& 1) == 1)
867 if ((x
/ width
) % 2 == 0)
870 x
= width
- 1 - x
% width
;
875 if ((attributes
->wrap
& 2) == 2)
878 if ((y
/ height
) % 2 == 0)
881 y
= height
- 1 - y
% height
;
887 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
889 ERR("out of range pixel requested\n");
893 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
896 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
897 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
898 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
902 switch (interpolation
)
906 FIXME("Unimplemented interpolation %i\n", interpolation
);
908 case InterpolationModeBilinear
:
911 INT leftx
, rightx
, topy
, bottomy
;
912 ARGB topleft
, topright
, bottomleft
, bottomright
;
916 leftxf
= floorf(point
->X
);
918 rightx
= (INT
)ceilf(point
->X
);
919 topyf
= floorf(point
->Y
);
921 bottomy
= (INT
)ceilf(point
->Y
);
923 if (leftx
== rightx
&& topy
== bottomy
)
924 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
925 leftx
, topy
, attributes
);
927 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
928 leftx
, topy
, attributes
);
929 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
930 rightx
, topy
, attributes
);
931 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
932 leftx
, bottomy
, attributes
);
933 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
934 rightx
, bottomy
, attributes
);
936 x_offset
= point
->X
- leftxf
;
937 top
= blend_colors(topleft
, topright
, x_offset
);
938 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
940 return blend_colors(top
, bottom
, point
->Y
- topyf
);
942 case InterpolationModeNearestNeighbor
:
948 case PixelOffsetModeNone
:
949 case PixelOffsetModeHighSpeed
:
953 case PixelOffsetModeHalf
:
954 case PixelOffsetModeHighQuality
:
958 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
959 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
965 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
967 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
970 static INT
brush_can_fill_path(GpBrush
*brush
)
974 case BrushTypeSolidColor
:
976 case BrushTypeHatchFill
:
978 GpHatch
*hatch
= (GpHatch
*)brush
;
979 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
980 ((hatch
->backcol
& 0xff000000) == 0xff000000);
982 case BrushTypeLinearGradient
:
983 case BrushTypeTextureFill
:
984 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
990 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
994 case BrushTypeSolidColor
:
996 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
997 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1002 /* partially transparent fill */
1004 SelectClipPath(graphics
->hdc
, RGN_AND
);
1005 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1007 HDC hdc
= CreateCompatibleDC(NULL
);
1011 SelectObject(hdc
, bmp
);
1012 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1020 /* else fall through */
1024 HBRUSH gdibrush
, old_brush
;
1026 gdibrush
= create_gdi_brush(brush
);
1027 if (!gdibrush
) return;
1029 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1030 FillPath(graphics
->hdc
);
1031 SelectObject(graphics
->hdc
, old_brush
);
1032 DeleteObject(gdibrush
);
1038 static INT
brush_can_fill_pixels(GpBrush
*brush
)
1042 case BrushTypeSolidColor
:
1043 case BrushTypeHatchFill
:
1044 case BrushTypeLinearGradient
:
1045 case BrushTypeTextureFill
:
1046 case BrushTypePathGradient
:
1053 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1054 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1058 case BrushTypeSolidColor
:
1061 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1062 for (x
=0; x
<fill_area
->Width
; x
++)
1063 for (y
=0; y
<fill_area
->Height
; y
++)
1064 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1067 case BrushTypeHatchFill
:
1070 GpHatch
*fill
= (GpHatch
*)brush
;
1071 const char *hatch_data
;
1073 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1074 return NotImplemented
;
1076 for (x
=0; x
<fill_area
->Width
; x
++)
1077 for (y
=0; y
<fill_area
->Height
; y
++)
1081 /* FIXME: Account for the rendering origin */
1082 hx
= (x
+ fill_area
->X
) % 8;
1083 hy
= (y
+ fill_area
->Y
) % 8;
1085 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1086 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1088 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1093 case BrushTypeLinearGradient
:
1095 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1096 GpPointF draw_points
[3], line_points
[3];
1098 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1099 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1102 draw_points
[0].X
= fill_area
->X
;
1103 draw_points
[0].Y
= fill_area
->Y
;
1104 draw_points
[1].X
= fill_area
->X
+1;
1105 draw_points
[1].Y
= fill_area
->Y
;
1106 draw_points
[2].X
= fill_area
->X
;
1107 draw_points
[2].Y
= fill_area
->Y
+1;
1109 /* Transform the points to a co-ordinate space where X is the point's
1110 * position in the gradient, 0.0 being the start point and 1.0 the
1112 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1113 CoordinateSpaceDevice
, draw_points
, 3);
1117 line_points
[0] = fill
->startpoint
;
1118 line_points
[1] = fill
->endpoint
;
1119 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1120 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1122 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1127 stat
= GdipInvertMatrix(world_to_gradient
);
1130 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1132 GdipDeleteMatrix(world_to_gradient
);
1137 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1138 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1140 for (y
=0; y
<fill_area
->Height
; y
++)
1142 for (x
=0; x
<fill_area
->Width
; x
++)
1144 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1146 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1153 case BrushTypeTextureFill
:
1155 GpTexture
*fill
= (GpTexture
*)brush
;
1156 GpPointF draw_points
[3];
1163 if (fill
->image
->type
!= ImageTypeBitmap
)
1165 FIXME("metafile texture brushes not implemented\n");
1166 return NotImplemented
;
1169 bitmap
= (GpBitmap
*)fill
->image
;
1170 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1172 src_area
.X
= src_area
.Y
= 0;
1173 src_area
.Width
= bitmap
->width
;
1174 src_area
.Height
= bitmap
->height
;
1176 draw_points
[0].X
= fill_area
->X
;
1177 draw_points
[0].Y
= fill_area
->Y
;
1178 draw_points
[1].X
= fill_area
->X
+1;
1179 draw_points
[1].Y
= fill_area
->Y
;
1180 draw_points
[2].X
= fill_area
->X
;
1181 draw_points
[2].Y
= fill_area
->Y
+1;
1183 /* Transform the points to the co-ordinate space of the bitmap. */
1184 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1185 CoordinateSpaceDevice
, draw_points
, 3);
1189 GpMatrix world_to_texture
= fill
->transform
;
1191 stat
= GdipInvertMatrix(&world_to_texture
);
1193 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1196 if (stat
== Ok
&& !fill
->bitmap_bits
)
1198 BitmapData lockeddata
;
1200 fill
->bitmap_bits
= GdipAlloc(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1201 if (!fill
->bitmap_bits
)
1206 lockeddata
.Width
= bitmap
->width
;
1207 lockeddata
.Height
= bitmap
->height
;
1208 lockeddata
.Stride
= src_stride
;
1209 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1210 lockeddata
.Scan0
= fill
->bitmap_bits
;
1212 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1213 PixelFormat32bppARGB
, &lockeddata
);
1217 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1220 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1221 bitmap
->width
, bitmap
->height
,
1222 src_stride
, ColorAdjustTypeBitmap
);
1226 GdipFree(fill
->bitmap_bits
);
1227 fill
->bitmap_bits
= NULL
;
1233 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1234 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1235 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1236 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1238 for (y
=0; y
<fill_area
->Height
; y
++)
1240 for (x
=0; x
<fill_area
->Width
; x
++)
1243 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1244 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1246 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1247 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1248 &point
, fill
->imageattributes
, graphics
->interpolation
,
1249 graphics
->pixeloffset
);
1256 case BrushTypePathGradient
:
1258 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1260 GpMatrix world_to_device
;
1262 int i
, figure_start
=0;
1263 GpPointF start_point
, end_point
, center_point
;
1265 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1266 INT min_y
, max_y
, min_x
, max_x
;
1269 static int transform_fixme_once
;
1271 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1275 FIXME("path gradient focus not implemented\n");
1282 FIXME("path gradient gamma correction not implemented\n");
1285 if (fill
->blendcount
)
1289 FIXME("path gradient blend not implemented\n");
1292 if (fill
->pblendcount
)
1296 FIXME("path gradient preset blend not implemented\n");
1299 if (!transform_fixme_once
)
1301 BOOL is_identity
=TRUE
;
1302 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1305 FIXME("path gradient transform not implemented\n");
1306 transform_fixme_once
= 1;
1310 stat
= GdipClonePath(fill
->path
, &flat_path
);
1315 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1316 CoordinateSpaceWorld
, &world_to_device
);
1319 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1323 center_point
= fill
->center
;
1324 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1328 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1333 GdipDeletePath(flat_path
);
1337 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1339 int start_center_line
=0, end_center_line
=0;
1340 int seen_start
=0, seen_end
=0, seen_center
=0;
1341 REAL center_distance
;
1342 ARGB start_color
, end_color
;
1345 type
= flat_path
->pathdata
.Types
[i
];
1347 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1350 start_point
= flat_path
->pathdata
.Points
[i
];
1352 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1354 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1356 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1357 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1359 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1361 end_point
= flat_path
->pathdata
.Points
[i
+1];
1362 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1367 outer_color
= start_color
;
1369 min_yf
= center_point
.Y
;
1370 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1371 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1373 if (min_yf
< fill_area
->Y
)
1374 min_y
= fill_area
->Y
;
1376 min_y
= (INT
)ceil(min_yf
);
1378 max_yf
= center_point
.Y
;
1379 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1380 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1382 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1383 max_y
= fill_area
->Y
+ fill_area
->Height
;
1385 max_y
= (INT
)ceil(max_yf
);
1387 dy
= end_point
.Y
- start_point
.Y
;
1388 dx
= end_point
.X
- start_point
.X
;
1390 /* This is proportional to the distance from start-end line to center point. */
1391 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1392 dx
* (center_point
.Y
- start_point
.Y
);
1394 for (y
=min_y
; y
<max_y
; y
++)
1398 if (!seen_start
&& yf
>= start_point
.Y
)
1401 start_center_line
^= 1;
1403 if (!seen_end
&& yf
>= end_point
.Y
)
1406 end_center_line
^= 1;
1408 if (!seen_center
&& yf
>= center_point
.Y
)
1411 start_center_line
^= 1;
1412 end_center_line
^= 1;
1415 if (start_center_line
)
1416 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1418 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1420 if (end_center_line
)
1421 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1423 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1425 if (line1_xf
< line2_xf
)
1427 min_x
= (INT
)ceil(line1_xf
);
1428 max_x
= (INT
)ceil(line2_xf
);
1432 min_x
= (INT
)ceil(line2_xf
);
1433 max_x
= (INT
)ceil(line1_xf
);
1436 if (min_x
< fill_area
->X
)
1437 min_x
= fill_area
->X
;
1438 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1439 max_x
= fill_area
->X
+ fill_area
->Width
;
1441 for (x
=min_x
; x
<max_x
; x
++)
1446 if (start_color
!= end_color
)
1448 REAL blend_amount
, pdy
, pdx
;
1449 pdy
= yf
- center_point
.Y
;
1450 pdx
= xf
- center_point
.X
;
1451 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1452 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1455 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1456 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1458 distance
= distance
/ center_distance
;
1460 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1461 blend_colors(outer_color
, fill
->centercolor
, distance
);
1466 GdipDeletePath(flat_path
);
1470 return NotImplemented
;
1474 /* GdipDrawPie/GdipFillPie helper function */
1475 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
1476 REAL height
, REAL startAngle
, REAL sweepAngle
)
1483 ptf
[1].X
= x
+ width
;
1484 ptf
[1].Y
= y
+ height
;
1486 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
1487 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
1489 transform_and_round_points(graphics
, pti
, ptf
, 4);
1491 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
1492 pti
[2].y
, pti
[3].x
, pti
[3].y
);
1495 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1496 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1497 * should not be called on an hdc that has a path you care about. */
1498 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1499 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1501 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1503 HBRUSH brush
= NULL
;
1505 PointF ptf
[4], *custptf
= NULL
;
1506 POINT pt
[4], *custpt
= NULL
;
1508 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1513 if((x1
== x2
) && (y1
== y2
))
1516 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1518 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1520 brush
= CreateSolidBrush(color
);
1521 lb
.lbStyle
= BS_SOLID
;
1524 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1525 PS_JOIN_MITER
, 1, &lb
, 0,
1527 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1528 oldpen
= SelectObject(graphics
->hdc
, pen
);
1535 case LineCapSquareAnchor
:
1536 case LineCapDiamondAnchor
:
1537 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1538 if(cap
== LineCapDiamondAnchor
){
1539 dsmall
= cos(theta
+ M_PI_2
) * size
;
1540 dbig
= sin(theta
+ M_PI_2
) * size
;
1543 dsmall
= cos(theta
+ M_PI_4
) * size
;
1544 dbig
= sin(theta
+ M_PI_4
) * size
;
1547 ptf
[0].X
= x2
- dsmall
;
1548 ptf
[1].X
= x2
+ dbig
;
1550 ptf
[0].Y
= y2
- dbig
;
1551 ptf
[3].Y
= y2
+ dsmall
;
1553 ptf
[1].Y
= y2
- dsmall
;
1554 ptf
[2].Y
= y2
+ dbig
;
1556 ptf
[3].X
= x2
- dbig
;
1557 ptf
[2].X
= x2
+ dsmall
;
1559 transform_and_round_points(graphics
, pt
, ptf
, 4);
1560 Polygon(graphics
->hdc
, pt
, 4);
1563 case LineCapArrowAnchor
:
1564 size
= size
* 4.0 / sqrt(3.0);
1566 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1567 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1572 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1573 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1581 transform_and_round_points(graphics
, pt
, ptf
, 3);
1582 Polygon(graphics
->hdc
, pt
, 3);
1585 case LineCapRoundAnchor
:
1586 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1593 transform_and_round_points(graphics
, pt
, ptf
, 2);
1594 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1597 case LineCapTriangle
:
1599 dx
= cos(M_PI_2
+ theta
) * size
;
1600 dy
= sin(M_PI_2
+ theta
) * size
;
1607 dx
= cos(theta
) * size
;
1608 dy
= sin(theta
) * size
;
1613 transform_and_round_points(graphics
, pt
, ptf
, 3);
1614 Polygon(graphics
->hdc
, pt
, 3);
1618 dx
= dy
= size
/ 2.0;
1625 dx
= -cos(M_PI_2
+ theta
) * size
;
1626 dy
= -sin(M_PI_2
+ theta
) * size
;
1633 transform_and_round_points(graphics
, pt
, ptf
, 4);
1634 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1635 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1642 count
= custom
->pathdata
.Count
;
1643 custptf
= GdipAlloc(count
* sizeof(PointF
));
1644 custpt
= GdipAlloc(count
* sizeof(POINT
));
1645 tp
= GdipAlloc(count
);
1647 if(!custptf
|| !custpt
|| !tp
)
1650 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1652 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1653 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1654 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1656 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1657 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1659 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1661 for(i
= 0; i
< count
; i
++)
1662 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1665 BeginPath(graphics
->hdc
);
1666 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1667 EndPath(graphics
->hdc
);
1668 StrokeAndFillPath(graphics
->hdc
);
1671 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1683 SelectObject(graphics
->hdc
, oldbrush
);
1684 SelectObject(graphics
->hdc
, oldpen
);
1685 DeleteObject(brush
);
1690 /* Shortens the line by the given percent by changing x2, y2.
1691 * If percent is > 1.0 then the line will change direction.
1692 * If percent is negative it can lengthen the line. */
1693 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1695 REAL dist
, theta
, dx
, dy
;
1697 if((y1
== *y2
) && (x1
== *x2
))
1700 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1701 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1702 dx
= cos(theta
) * dist
;
1703 dy
= sin(theta
) * dist
;
1709 /* Shortens the line by the given amount by changing x2, y2.
1710 * If the amount is greater than the distance, the line will become length 0.
1711 * If the amount is negative, it can lengthen the line. */
1712 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1714 REAL dx
, dy
, percent
;
1718 if(dx
== 0 && dy
== 0)
1721 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1728 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1731 /* Draws lines between the given points, and if caps is true then draws an endcap
1732 * at the end of the last line. */
1733 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
1734 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1737 GpPointF
*ptcopy
= NULL
;
1738 GpStatus status
= GenericError
;
1743 pti
= GdipAlloc(count
* sizeof(POINT
));
1744 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1746 if(!pti
|| !ptcopy
){
1747 status
= OutOfMemory
;
1751 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1754 if(pen
->endcap
== LineCapArrowAnchor
)
1755 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1756 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
1757 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1758 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
1759 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
1760 pen
->customend
->inset
* pen
->width
);
1762 if(pen
->startcap
== LineCapArrowAnchor
)
1763 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1764 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
1765 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1766 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
1767 &ptcopy
[0].X
, &ptcopy
[0].Y
,
1768 pen
->customstart
->inset
* pen
->width
);
1770 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1771 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
1772 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1773 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
1776 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1778 if(Polyline(graphics
->hdc
, pti
, count
))
1788 /* Conducts a linear search to find the bezier points that will back off
1789 * the endpoint of the curve by a distance of amt. Linear search works
1790 * better than binary in this case because there are multiple solutions,
1791 * and binary searches often find a bad one. I don't think this is what
1792 * Windows does but short of rendering the bezier without GDI's help it's
1793 * the best we can do. If rev then work from the start of the passed points
1794 * instead of the end. */
1795 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1798 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1799 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1808 origx
= pt
[fourth
].X
;
1809 origy
= pt
[fourth
].Y
;
1810 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1812 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1813 /* reset bezier points to original values */
1814 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1815 /* Perform magic on bezier points. Order is important here.*/
1816 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1817 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1818 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1819 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1820 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1821 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1823 dx
= pt
[fourth
].X
- origx
;
1824 dy
= pt
[fourth
].Y
- origy
;
1826 diff
= sqrt(dx
* dx
+ dy
* dy
);
1827 percent
+= 0.0005 * amt
;
1831 /* Draws bezier curves between given points, and if caps is true then draws an
1832 * endcap at the end of the last line. */
1833 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
1834 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
1838 GpStatus status
= GenericError
;
1843 pti
= GdipAlloc(count
* sizeof(POINT
));
1844 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1846 if(!pti
|| !ptcopy
){
1847 status
= OutOfMemory
;
1851 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1854 if(pen
->endcap
== LineCapArrowAnchor
)
1855 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
1856 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1857 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
1860 if(pen
->startcap
== LineCapArrowAnchor
)
1861 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
1862 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1863 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
1865 /* the direction of the line cap is parallel to the direction at the
1866 * end of the bezier (which, if it has been shortened, is not the same
1867 * as the direction from pt[count-2] to pt[count-1]) */
1868 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1869 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1870 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1871 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1873 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1874 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
1875 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
1878 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1880 PolyBezier(graphics
->hdc
, pti
, count
);
1891 /* Draws a combination of bezier curves and lines between points. */
1892 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1893 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1895 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
1896 BYTE
*tp
= GdipAlloc(count
);
1897 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
1899 GpStatus status
= GenericError
;
1905 if(!pti
|| !tp
|| !ptcopy
){
1906 status
= OutOfMemory
;
1910 for(i
= 1; i
< count
; i
++){
1911 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1912 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1913 || !(types
[i
+ 1] & PathPointTypeBezier
)){
1914 ERR("Bad bezier points\n");
1921 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1923 /* If we are drawing caps, go through the points and adjust them accordingly,
1924 * and draw the caps. */
1926 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1927 case PathPointTypeBezier
:
1928 if(pen
->endcap
== LineCapArrowAnchor
)
1929 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1930 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1931 shorten_bezier_amt(&ptcopy
[count
- 4],
1932 pen
->width
* pen
->customend
->inset
, FALSE
);
1934 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1935 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1936 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1937 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1940 case PathPointTypeLine
:
1941 if(pen
->endcap
== LineCapArrowAnchor
)
1942 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1943 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1945 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1946 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1947 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1948 pen
->customend
->inset
* pen
->width
);
1950 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1951 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1956 ERR("Bad path last point\n");
1960 /* Find start of points */
1961 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1962 == PathPointTypeStart
); j
++);
1964 switch(types
[j
] & PathPointTypePathTypeMask
){
1965 case PathPointTypeBezier
:
1966 if(pen
->startcap
== LineCapArrowAnchor
)
1967 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1968 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1969 shorten_bezier_amt(&ptcopy
[j
- 1],
1970 pen
->width
* pen
->customstart
->inset
, TRUE
);
1972 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1973 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1974 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1975 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1978 case PathPointTypeLine
:
1979 if(pen
->startcap
== LineCapArrowAnchor
)
1980 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1981 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1983 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1984 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1985 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1986 pen
->customstart
->inset
* pen
->width
);
1988 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1989 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1994 ERR("Bad path points\n");
1999 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
2001 for(i
= 0; i
< count
; i
++){
2002 tp
[i
] = convert_path_point_type(types
[i
]);
2005 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
2017 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
2021 BeginPath(graphics
->hdc
);
2022 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2023 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2024 EndPath(graphics
->hdc
);
2028 typedef struct _GraphicsContainerItem
{
2030 GraphicsContainer contid
;
2032 SmoothingMode smoothing
;
2033 CompositingQuality compqual
;
2034 InterpolationMode interpolation
;
2035 CompositingMode compmode
;
2036 TextRenderingHint texthint
;
2039 PixelOffsetMode pixeloffset
;
2041 GpMatrix worldtrans
;
2043 INT origin_x
, origin_y
;
2044 } GraphicsContainerItem
;
2046 static GpStatus
init_container(GraphicsContainerItem
** container
,
2047 GDIPCONST GpGraphics
* graphics
){
2050 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
2054 (*container
)->contid
= graphics
->contid
+ 1;
2056 (*container
)->smoothing
= graphics
->smoothing
;
2057 (*container
)->compqual
= graphics
->compqual
;
2058 (*container
)->interpolation
= graphics
->interpolation
;
2059 (*container
)->compmode
= graphics
->compmode
;
2060 (*container
)->texthint
= graphics
->texthint
;
2061 (*container
)->scale
= graphics
->scale
;
2062 (*container
)->unit
= graphics
->unit
;
2063 (*container
)->textcontrast
= graphics
->textcontrast
;
2064 (*container
)->pixeloffset
= graphics
->pixeloffset
;
2065 (*container
)->origin_x
= graphics
->origin_x
;
2066 (*container
)->origin_y
= graphics
->origin_y
;
2067 (*container
)->worldtrans
= graphics
->worldtrans
;
2069 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
2071 GdipFree(*container
);
2079 static void delete_container(GraphicsContainerItem
* container
)
2081 GdipDeleteRegion(container
->clip
);
2082 GdipFree(container
);
2085 static GpStatus
restore_container(GpGraphics
* graphics
,
2086 GDIPCONST GraphicsContainerItem
* container
){
2090 sts
= GdipCloneRegion(container
->clip
, &newClip
);
2091 if(sts
!= Ok
) return sts
;
2093 graphics
->worldtrans
= container
->worldtrans
;
2095 GdipDeleteRegion(graphics
->clip
);
2096 graphics
->clip
= newClip
;
2098 graphics
->contid
= container
->contid
- 1;
2100 graphics
->smoothing
= container
->smoothing
;
2101 graphics
->compqual
= container
->compqual
;
2102 graphics
->interpolation
= container
->interpolation
;
2103 graphics
->compmode
= container
->compmode
;
2104 graphics
->texthint
= container
->texthint
;
2105 graphics
->scale
= container
->scale
;
2106 graphics
->unit
= container
->unit
;
2107 graphics
->textcontrast
= container
->textcontrast
;
2108 graphics
->pixeloffset
= container
->pixeloffset
;
2109 graphics
->origin_x
= container
->origin_x
;
2110 graphics
->origin_y
= container
->origin_y
;
2115 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2121 if(graphics
->hwnd
) {
2122 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2123 return GenericError
;
2125 rect
->X
= wnd_rect
.left
;
2126 rect
->Y
= wnd_rect
.top
;
2127 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2128 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2129 }else if (graphics
->image
){
2130 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2131 if (stat
== Ok
&& unit
!= UnitPixel
)
2132 FIXME("need to convert from unit %i\n", unit
);
2133 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2140 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2141 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2143 rect
->Width
= bmp
.bmWidth
;
2144 rect
->Height
= bmp
.bmHeight
;
2155 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2156 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2162 /* on success, rgn will contain the region of the graphics object which
2163 * is visible after clipping has been applied */
2164 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2170 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2173 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2176 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2179 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2182 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2185 GdipDeleteRegion(tmp
);
2189 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2193 if (font
->unit
== UnitPixel
)
2195 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2199 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2200 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2202 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2205 lf
->lfHeight
= -(height
+ 0.5);
2207 lf
->lfEscapement
= 0;
2208 lf
->lfOrientation
= 0;
2209 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2210 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2211 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2212 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2213 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2214 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2215 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2216 lf
->lfQuality
= DEFAULT_QUALITY
;
2217 lf
->lfPitchAndFamily
= 0;
2218 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2221 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2222 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2223 GDIPCONST GpMatrix
*matrix
)
2225 HDC hdc
= CreateCompatibleDC(0);
2227 REAL angle
, rel_width
, rel_height
, font_height
;
2229 HFONT unscaled_font
;
2230 TEXTMETRICW textmet
;
2232 if (font
->unit
== UnitPixel
)
2233 font_height
= font
->emSize
;
2236 REAL unit_scale
, res
;
2238 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2239 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2241 font_height
= font
->emSize
* unit_scale
;
2252 GpMatrix xform
= *matrix
;
2253 GdipTransformMatrixPoints(&xform
, pt
, 3);
2256 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2257 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2258 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2259 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2260 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2261 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2263 get_log_fontW(font
, graphics
, &lfw
);
2264 lfw
.lfHeight
= gdip_round(font_height
* rel_height
);
2265 unscaled_font
= CreateFontIndirectW(&lfw
);
2267 SelectObject(hdc
, unscaled_font
);
2268 GetTextMetricsW(hdc
, &textmet
);
2270 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2271 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2273 *hfont
= CreateFontIndirectW(&lfw
);
2276 DeleteObject(unscaled_font
);
2279 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2281 TRACE("(%p, %p)\n", hdc
, graphics
);
2283 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2286 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2292 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2294 if(hDevice
!= NULL
) {
2295 FIXME("Don't know how to handle parameter hDevice\n");
2296 return NotImplemented
;
2302 if(graphics
== NULL
)
2303 return InvalidParameter
;
2305 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2306 if(!*graphics
) return OutOfMemory
;
2308 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2310 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2311 GdipFree(*graphics
);
2315 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2316 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2317 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2319 (*graphics
)->alpha_hdc
= 1;
2322 (*graphics
)->hdc
= hdc
;
2323 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2324 (*graphics
)->owndc
= FALSE
;
2325 (*graphics
)->smoothing
= SmoothingModeDefault
;
2326 (*graphics
)->compqual
= CompositingQualityDefault
;
2327 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2328 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2329 (*graphics
)->compmode
= CompositingModeSourceOver
;
2330 (*graphics
)->unit
= UnitDisplay
;
2331 (*graphics
)->scale
= 1.0;
2332 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2333 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2334 (*graphics
)->busy
= FALSE
;
2335 (*graphics
)->textcontrast
= 4;
2336 list_init(&(*graphics
)->containers
);
2337 (*graphics
)->contid
= GDIP_GET_NEW_CONTID_FOR(*graphics
);
2339 TRACE("<-- %p\n", *graphics
);
2344 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2348 *graphics
= GdipAlloc(sizeof(GpGraphics
));
2349 if(!*graphics
) return OutOfMemory
;
2351 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2353 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2354 GdipFree(*graphics
);
2358 (*graphics
)->hdc
= NULL
;
2359 (*graphics
)->hwnd
= NULL
;
2360 (*graphics
)->owndc
= FALSE
;
2361 (*graphics
)->image
= image
;
2362 (*graphics
)->smoothing
= SmoothingModeDefault
;
2363 (*graphics
)->compqual
= CompositingQualityDefault
;
2364 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2365 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2366 (*graphics
)->compmode
= CompositingModeSourceOver
;
2367 (*graphics
)->unit
= UnitDisplay
;
2368 (*graphics
)->scale
= 1.0;
2369 (*graphics
)->xres
= image
->xres
;
2370 (*graphics
)->yres
= image
->yres
;
2371 (*graphics
)->busy
= FALSE
;
2372 (*graphics
)->textcontrast
= 4;
2373 list_init(&(*graphics
)->containers
);
2374 (*graphics
)->contid
= GDIP_GET_NEW_CONTID_FOR(*graphics
);
2376 TRACE("<-- %p\n", *graphics
);
2381 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2386 TRACE("(%p, %p)\n", hwnd
, graphics
);
2390 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2392 ReleaseDC(hwnd
, hdc
);
2396 (*graphics
)->hwnd
= hwnd
;
2397 (*graphics
)->owndc
= TRUE
;
2402 /* FIXME: no icm handling */
2403 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2405 TRACE("(%p, %p)\n", hwnd
, graphics
);
2407 return GdipCreateFromHWND(hwnd
, graphics
);
2410 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
2411 GpMetafile
**metafile
)
2413 ENHMETAHEADER header
;
2414 MetafileType metafile_type
;
2416 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
2418 if(!hemf
|| !metafile
)
2419 return InvalidParameter
;
2421 if (GetEnhMetaFileHeader(hemf
, sizeof(header
), &header
) == 0)
2422 return GenericError
;
2424 metafile_type
= METAFILE_GetEmfType(hemf
);
2426 if (metafile_type
== MetafileTypeInvalid
)
2427 return GenericError
;
2429 *metafile
= GdipAlloc(sizeof(GpMetafile
));
2433 (*metafile
)->image
.type
= ImageTypeMetafile
;
2434 (*metafile
)->image
.format
= ImageFormatEMF
;
2435 (*metafile
)->image
.frame_count
= 1;
2436 (*metafile
)->image
.xres
= (REAL
)header
.szlDevice
.cx
;
2437 (*metafile
)->image
.yres
= (REAL
)header
.szlDevice
.cy
;
2438 (*metafile
)->bounds
.X
= (REAL
)header
.rclBounds
.left
;
2439 (*metafile
)->bounds
.Y
= (REAL
)header
.rclBounds
.top
;
2440 (*metafile
)->bounds
.Width
= (REAL
)(header
.rclBounds
.right
- header
.rclBounds
.left
);
2441 (*metafile
)->bounds
.Height
= (REAL
)(header
.rclBounds
.bottom
- header
.rclBounds
.top
);
2442 (*metafile
)->unit
= UnitPixel
;
2443 (*metafile
)->metafile_type
= metafile_type
;
2444 (*metafile
)->hemf
= hemf
;
2445 (*metafile
)->preserve_hemf
= !delete;
2447 TRACE("<-- %p\n", *metafile
);
2452 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
2453 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2458 GpStatus retval
= Ok
;
2460 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
2462 if(!hwmf
|| !metafile
|| !placeable
)
2463 return InvalidParameter
;
2466 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
2468 return GenericError
;
2469 copy
= GdipAlloc(read
);
2470 GetMetaFileBitsEx(hwmf
, read
, copy
);
2472 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
2475 /* FIXME: We should store and use hwmf instead of converting to hemf */
2476 retval
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
2480 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
2481 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
2482 (*metafile
)->bounds
.X
= ((REAL
)placeable
->BoundingBox
.Left
) / ((REAL
)placeable
->Inch
);
2483 (*metafile
)->bounds
.Y
= ((REAL
)placeable
->BoundingBox
.Top
) / ((REAL
)placeable
->Inch
);
2484 (*metafile
)->bounds
.Width
= (REAL
)(placeable
->BoundingBox
.Right
-
2485 placeable
->BoundingBox
.Left
);
2486 (*metafile
)->bounds
.Height
= (REAL
)(placeable
->BoundingBox
.Bottom
-
2487 placeable
->BoundingBox
.Top
);
2488 (*metafile
)->metafile_type
= MetafileTypeWmfPlaceable
;
2489 (*metafile
)->image
.format
= ImageFormatWMF
;
2491 if (delete) DeleteMetaFile(hwmf
);
2494 DeleteEnhMetaFile(hemf
);
2498 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
2499 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
2501 HMETAFILE hmf
= GetMetaFileW(file
);
2503 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
2505 if(!hmf
) return InvalidParameter
;
2507 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
2510 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
2511 GpMetafile
**metafile
)
2513 FIXME("(%p, %p): stub\n", file
, metafile
);
2514 return NotImplemented
;
2517 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
2518 GpMetafile
**metafile
)
2520 FIXME("(%p, %p): stub\n", stream
, metafile
);
2521 return NotImplemented
;
2524 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2525 UINT access
, IStream
**stream
)
2530 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2532 if(!stream
|| !filename
)
2533 return InvalidParameter
;
2535 if(access
& GENERIC_WRITE
)
2536 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2537 else if(access
& GENERIC_READ
)
2538 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2540 return InvalidParameter
;
2542 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2544 return hresult_to_status(ret
);
2547 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2549 GraphicsContainerItem
*cont
, *next
;
2551 TRACE("(%p)\n", graphics
);
2553 if(!graphics
) return InvalidParameter
;
2554 if(graphics
->busy
) return ObjectBusy
;
2556 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
2558 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2564 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2566 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2567 list_remove(&cont
->entry
);
2568 delete_container(cont
);
2571 GdipDeleteRegion(graphics
->clip
);
2577 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2578 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2580 INT save_state
, num_pts
;
2581 GpPointF points
[MAX_ARC_PTS
];
2584 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2585 width
, height
, startAngle
, sweepAngle
);
2587 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2588 return InvalidParameter
;
2595 FIXME("graphics object has no HDC\n");
2599 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2601 save_state
= prepare_dc(graphics
, pen
);
2603 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
2605 restore_dc(graphics
, save_state
);
2610 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2611 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2613 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2614 width
, height
, startAngle
, sweepAngle
);
2616 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2619 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2620 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2626 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2627 x2
, y2
, x3
, y3
, x4
, y4
);
2629 if(!graphics
|| !pen
)
2630 return InvalidParameter
;
2637 FIXME("graphics object has no HDC\n");
2650 save_state
= prepare_dc(graphics
, pen
);
2652 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2654 restore_dc(graphics
, save_state
);
2659 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2660 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2666 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2667 x2
, y2
, x3
, y3
, x4
, y4
);
2669 if(!graphics
|| !pen
)
2670 return InvalidParameter
;
2677 FIXME("graphics object has no HDC\n");
2690 save_state
= prepare_dc(graphics
, pen
);
2692 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
2694 restore_dc(graphics
, save_state
);
2699 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2700 GDIPCONST GpPointF
*points
, INT count
)
2705 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2707 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2708 return InvalidParameter
;
2713 for(i
= 0; i
< floor(count
/ 4); i
++){
2714 ret
= GdipDrawBezier(graphics
, pen
,
2715 points
[4*i
].X
, points
[4*i
].Y
,
2716 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
2717 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
2718 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
2726 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2727 GDIPCONST GpPoint
*points
, INT count
)
2733 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2735 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2736 return InvalidParameter
;
2741 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
2745 for(i
= 0; i
< count
; i
++){
2746 pts
[i
].X
= (REAL
)points
[i
].X
;
2747 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2750 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2757 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2758 GDIPCONST GpPointF
*points
, INT count
)
2760 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2762 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2765 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2766 GDIPCONST GpPoint
*points
, INT count
)
2768 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2770 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2773 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2774 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2779 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2781 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2782 return InvalidParameter
;
2787 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
2790 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2792 GdipDeletePath(path
);
2796 stat
= GdipDrawPath(graphics
, pen
, path
);
2798 GdipDeletePath(path
);
2803 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2804 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2810 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2812 if(!points
|| count
<= 0)
2813 return InvalidParameter
;
2815 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2819 for(i
= 0; i
< count
; i
++){
2820 ptf
[i
].X
= (REAL
)points
[i
].X
;
2821 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2824 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2831 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2832 GDIPCONST GpPointF
*points
, INT count
)
2834 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2836 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2839 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2840 GDIPCONST GpPoint
*points
, INT count
)
2846 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2849 return InvalidParameter
;
2851 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2855 for(i
= 0; i
< count
; i
++){
2856 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2857 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2860 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2866 /* Approximates cardinal spline with Bezier curves. */
2867 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2868 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2870 /* PolyBezier expects count*3-2 points. */
2871 INT i
, len_pt
= count
*3-2, save_state
;
2873 REAL x1
, x2
, y1
, y2
;
2876 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2878 if(!graphics
|| !pen
)
2879 return InvalidParameter
;
2885 return InvalidParameter
;
2889 FIXME("graphics object has no HDC\n");
2893 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
2897 tension
= tension
* TENSION_CONST
;
2899 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
2902 pt
[0].X
= points
[0].X
;
2903 pt
[0].Y
= points
[0].Y
;
2907 for(i
= 0; i
< count
-2; i
++){
2908 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
2912 pt
[3*i
+3].X
= points
[i
+1].X
;
2913 pt
[3*i
+3].Y
= points
[i
+1].Y
;
2918 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
2919 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
2921 pt
[len_pt
-2].X
= x1
;
2922 pt
[len_pt
-2].Y
= y1
;
2923 pt
[len_pt
-1].X
= points
[count
-1].X
;
2924 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
2926 save_state
= prepare_dc(graphics
, pen
);
2928 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
2931 restore_dc(graphics
, save_state
);
2936 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2937 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2943 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2946 return InvalidParameter
;
2948 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
2952 for(i
= 0; i
< count
; i
++){
2953 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2954 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2957 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2963 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2964 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2967 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2969 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2970 return InvalidParameter
;
2973 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2976 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2977 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2980 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2986 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2987 return InvalidParameter
;
2990 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2993 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2994 REAL y
, REAL width
, REAL height
)
3000 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3002 if(!graphics
|| !pen
)
3003 return InvalidParameter
;
3010 FIXME("graphics object has no HDC\n");
3016 ptf
[1].X
= x
+ width
;
3017 ptf
[1].Y
= y
+ height
;
3019 save_state
= prepare_dc(graphics
, pen
);
3020 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3022 transform_and_round_points(graphics
, pti
, ptf
, 2);
3024 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
3026 restore_dc(graphics
, save_state
);
3031 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3032 INT y
, INT width
, INT height
)
3034 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3036 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3040 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
3044 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
3046 if(!graphics
|| !image
)
3047 return InvalidParameter
;
3049 GdipGetImageWidth(image
, &width
);
3050 GdipGetImageHeight(image
, &height
);
3052 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
3053 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
3056 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
3059 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
3061 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
3064 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
3065 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
3069 REAL scale_x
, scale_y
, width
, height
;
3071 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
3073 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
3074 scale_x
*= graphics
->xres
/ image
->xres
;
3075 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
3076 scale_y
*= graphics
->yres
/ image
->yres
;
3077 width
= srcwidth
* scale_x
;
3078 height
= srcheight
* scale_y
;
3080 points
[0].X
= points
[2].X
= x
;
3081 points
[0].Y
= points
[1].Y
= y
;
3082 points
[1].X
= x
+ width
;
3083 points
[2].Y
= y
+ height
;
3085 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3086 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
3089 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
3090 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
3093 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
3096 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
3097 GDIPCONST GpPointF
*dstpoints
, INT count
)
3101 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
3104 return InvalidParameter
;
3106 GdipGetImageWidth(image
, &width
);
3107 GdipGetImageHeight(image
, &height
);
3109 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
3110 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
3113 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
3114 GDIPCONST GpPoint
*dstpoints
, INT count
)
3118 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
3120 if (count
!= 3 || !dstpoints
)
3121 return InvalidParameter
;
3123 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
3124 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
3125 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
3126 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
3127 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
3128 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
3130 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
3133 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
3134 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
3136 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
3140 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
3141 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
3142 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3143 DrawImageAbort callback
, VOID
* callbackData
)
3149 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
3150 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3154 return NotImplemented
;
3156 if(!graphics
|| !image
|| !points
|| count
!= 3)
3157 return InvalidParameter
;
3159 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
3160 debugstr_pointf(&points
[2]));
3162 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
3163 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
3164 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
3165 if (!srcwidth
|| !srcheight
|| ptf
[3].X
== ptf
[0].X
|| ptf
[3].Y
== ptf
[0].Y
)
3167 transform_and_round_points(graphics
, pti
, ptf
, 4);
3169 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
3170 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
3172 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
3173 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
3174 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
3175 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
3176 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
3182 FIXME("graphics object has no HDC\n");
3185 if(IPicture_Render(image
->picture
, graphics
->hdc
,
3186 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3187 srcx
, srcy
, srcwidth
, srcheight
, NULL
) != S_OK
)
3190 callback(callbackData
);
3191 return GenericError
;
3194 else if (image
->type
== ImageTypeBitmap
)
3196 GpBitmap
* bitmap
= (GpBitmap
*)image
;
3199 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
3200 graphics
->xres
, graphics
->yres
,
3201 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
3202 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
3203 imageAttributes
? imageAttributes
->outside_color
: 0);
3205 if (imageAttributes
|| graphics
->alpha_hdc
||
3206 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
3207 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
3208 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
3209 srcx
< 0 || srcy
< 0 ||
3210 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
3217 int i
, x
, y
, src_stride
, dst_stride
;
3218 GpMatrix dst_to_src
;
3219 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
3220 LPBYTE src_data
, dst_data
;
3221 BitmapData lockeddata
;
3222 InterpolationMode interpolation
= graphics
->interpolation
;
3223 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
3224 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3225 REAL x_dx
, x_dy
, y_dx
, y_dy
;
3226 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
3228 if (!imageAttributes
)
3229 imageAttributes
= &defaultImageAttributes
;
3231 dst_area
.left
= dst_area
.right
= pti
[0].x
;
3232 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
3235 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
3236 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
3237 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
3238 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
3241 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
3243 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
3244 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
3245 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
3246 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
3247 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
3248 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
3250 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
3252 stat
= GdipInvertMatrix(&dst_to_src
);
3253 if (stat
!= Ok
) return stat
;
3255 dst_data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3256 if (!dst_data
) return OutOfMemory
;
3258 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3260 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
3261 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
3263 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
3265 src_data
= GdipAlloc(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
3271 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3273 /* Read the bits we need from the source bitmap into an ARGB buffer. */
3274 lockeddata
.Width
= src_area
.Width
;
3275 lockeddata
.Height
= src_area
.Height
;
3276 lockeddata
.Stride
= src_stride
;
3277 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3278 lockeddata
.Scan0
= src_data
;
3280 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3281 PixelFormat32bppARGB
, &lockeddata
);
3284 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3288 if (src_data
!= dst_data
)
3294 apply_image_attributes(imageAttributes
, src_data
,
3295 src_area
.Width
, src_area
.Height
,
3296 src_stride
, ColorAdjustTypeBitmap
);
3298 /* Transform the bits as needed to the destination. */
3299 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3301 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3302 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3303 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3304 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3306 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3308 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3310 GpPointF src_pointf
;
3313 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3314 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3316 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3318 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3319 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3320 imageAttributes
, interpolation
, offset_mode
);
3328 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3329 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
);
3338 int temp_hdc
=0, temp_bitmap
=0;
3339 HBITMAP hbitmap
, old_hbm
=NULL
;
3341 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3342 bitmap
->format
== PixelFormat24bppRGB
||
3343 bitmap
->format
== PixelFormat32bppRGB
||
3344 bitmap
->format
== PixelFormat32bppPARGB
))
3346 BITMAPINFOHEADER bih
;
3348 PixelFormat dst_format
;
3350 /* we can't draw a bitmap of this format directly */
3351 hdc
= CreateCompatibleDC(0);
3355 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3356 bih
.biWidth
= bitmap
->width
;
3357 bih
.biHeight
= -bitmap
->height
;
3359 bih
.biBitCount
= 32;
3360 bih
.biCompression
= BI_RGB
;
3361 bih
.biSizeImage
= 0;
3362 bih
.biXPelsPerMeter
= 0;
3363 bih
.biYPelsPerMeter
= 0;
3365 bih
.biClrImportant
= 0;
3367 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3368 (void**)&temp_bits
, NULL
, 0);
3370 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3371 dst_format
= PixelFormat32bppPARGB
;
3373 dst_format
= PixelFormat32bppRGB
;
3375 convert_pixels(bitmap
->width
, bitmap
->height
,
3376 bitmap
->width
*4, temp_bits
, dst_format
,
3377 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3378 bitmap
->image
.palette
);
3382 if (bitmap
->hbitmap
)
3383 hbitmap
= bitmap
->hbitmap
;
3386 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3391 temp_hdc
= (hdc
== 0);
3396 if (!hdc
) hdc
= CreateCompatibleDC(0);
3397 old_hbm
= SelectObject(hdc
, hbitmap
);
3400 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3402 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3403 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3407 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3408 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3413 SelectObject(hdc
, old_hbm
);
3418 DeleteObject(hbitmap
);
3421 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3427 rc
.Width
= srcwidth
;
3428 rc
.Height
= srcheight
;
3430 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3431 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3435 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3436 return InvalidParameter
;
3442 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3443 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3444 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3445 DrawImageAbort callback
, VOID
* callbackData
)
3447 GpPointF pointsF
[3];
3450 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3451 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3454 if(!points
|| count
!=3)
3455 return InvalidParameter
;
3457 for(i
= 0; i
< count
; i
++){
3458 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3459 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3462 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3463 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3464 callback
, callbackData
);
3467 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3468 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3469 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3470 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3471 VOID
* callbackData
)
3475 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3476 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3477 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3481 points
[1].X
= dstx
+ dstwidth
;
3484 points
[2].Y
= dsty
+ dstheight
;
3486 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3487 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3490 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3491 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3492 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3493 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3494 VOID
* callbackData
)
3498 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3499 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3500 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3504 points
[1].X
= dstx
+ dstwidth
;
3507 points
[2].Y
= dsty
+ dstheight
;
3509 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3510 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3513 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3514 REAL x
, REAL y
, REAL width
, REAL height
)
3520 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3522 if(!graphics
|| !image
)
3523 return InvalidParameter
;
3525 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3529 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3530 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3531 unit
, NULL
, NULL
, NULL
);
3534 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3535 INT x
, INT y
, INT width
, INT height
)
3537 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3539 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3542 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3543 REAL y1
, REAL x2
, REAL y2
)
3549 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3551 if(!pen
|| !graphics
)
3552 return InvalidParameter
;
3559 FIXME("graphics object has no HDC\n");
3568 save_state
= prepare_dc(graphics
, pen
);
3570 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3572 restore_dc(graphics
, save_state
);
3577 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3578 INT y1
, INT x2
, INT y2
)
3584 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3586 if(!pen
|| !graphics
)
3587 return InvalidParameter
;
3594 FIXME("graphics object has no HDC\n");
3603 save_state
= prepare_dc(graphics
, pen
);
3605 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
3607 restore_dc(graphics
, save_state
);
3612 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3613 GpPointF
*points
, INT count
)
3618 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3620 if(!pen
|| !graphics
|| (count
< 2))
3621 return InvalidParameter
;
3628 FIXME("graphics object has no HDC\n");
3632 save_state
= prepare_dc(graphics
, pen
);
3634 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
3636 restore_dc(graphics
, save_state
);
3641 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3642 GpPoint
*points
, INT count
)
3646 GpPointF
*ptf
= NULL
;
3649 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3651 if(!pen
|| !graphics
|| (count
< 2))
3652 return InvalidParameter
;
3659 FIXME("graphics object has no HDC\n");
3663 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3664 if(!ptf
) return OutOfMemory
;
3666 for(i
= 0; i
< count
; i
++){
3667 ptf
[i
].X
= (REAL
) points
[i
].X
;
3668 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3671 save_state
= prepare_dc(graphics
, pen
);
3673 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
3675 restore_dc(graphics
, save_state
);
3681 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3686 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3688 if(!pen
|| !graphics
)
3689 return InvalidParameter
;
3696 FIXME("graphics object has no HDC\n");
3700 save_state
= prepare_dc(graphics
, pen
);
3702 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3703 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3705 restore_dc(graphics
, save_state
);
3710 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3711 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3715 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3716 width
, height
, startAngle
, sweepAngle
);
3718 if(!graphics
|| !pen
)
3719 return InvalidParameter
;
3726 FIXME("graphics object has no HDC\n");
3730 save_state
= prepare_dc(graphics
, pen
);
3731 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3733 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3735 restore_dc(graphics
, save_state
);
3740 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3741 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3743 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3744 width
, height
, startAngle
, sweepAngle
);
3746 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3749 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3750 REAL y
, REAL width
, REAL height
)
3756 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3758 if(!pen
|| !graphics
)
3759 return InvalidParameter
;
3766 FIXME("graphics object has no HDC\n");
3772 ptf
[1].X
= x
+ width
;
3774 ptf
[2].X
= x
+ width
;
3775 ptf
[2].Y
= y
+ height
;
3777 ptf
[3].Y
= y
+ height
;
3779 save_state
= prepare_dc(graphics
, pen
);
3780 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3782 transform_and_round_points(graphics
, pti
, ptf
, 4);
3783 Polygon(graphics
->hdc
, pti
, 4);
3785 restore_dc(graphics
, save_state
);
3790 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3791 INT y
, INT width
, INT height
)
3793 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3795 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3798 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3799 GDIPCONST GpRectF
* rects
, INT count
)
3805 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3807 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3808 return InvalidParameter
;
3815 FIXME("graphics object has no HDC\n");
3819 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
3820 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
3828 for(i
= 0; i
< count
; i
++){
3829 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
3830 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
3831 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
3832 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
3835 save_state
= prepare_dc(graphics
, pen
);
3836 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3838 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
3840 for(i
= 0; i
< count
; i
++)
3841 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
3843 restore_dc(graphics
, save_state
);
3851 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3852 GDIPCONST GpRect
* rects
, INT count
)
3858 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3860 if(!rects
|| count
<=0)
3861 return InvalidParameter
;
3863 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
3867 for(i
= 0;i
< count
;i
++){
3868 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3869 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3870 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3871 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3874 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3880 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3881 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3886 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3887 count
, tension
, fill
);
3889 if(!graphics
|| !brush
|| !points
)
3890 return InvalidParameter
;
3895 if(count
== 1) /* Do nothing */
3898 stat
= GdipCreatePath(fill
, &path
);
3902 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3904 GdipDeletePath(path
);
3908 stat
= GdipFillPath(graphics
, brush
, path
);
3910 GdipDeletePath(path
);
3914 GdipDeletePath(path
);
3919 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3920 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3926 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3927 count
, tension
, fill
);
3929 if(!points
|| count
== 0)
3930 return InvalidParameter
;
3932 if(count
== 1) /* Do nothing */
3935 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
3939 for(i
= 0;i
< count
;i
++){
3940 ptf
[i
].X
= (REAL
)points
[i
].X
;
3941 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3944 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3951 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3952 GDIPCONST GpPointF
*points
, INT count
)
3954 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3955 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3956 0.5f
, FillModeAlternate
);
3959 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3960 GDIPCONST GpPoint
*points
, INT count
)
3962 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3963 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3964 0.5f
, FillModeAlternate
);
3967 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3968 REAL y
, REAL width
, REAL height
)
3973 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3975 if(!graphics
|| !brush
)
3976 return InvalidParameter
;
3981 stat
= GdipCreatePath(FillModeAlternate
, &path
);
3985 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
3988 stat
= GdipFillPath(graphics
, brush
, path
);
3990 GdipDeletePath(path
);
3996 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3997 INT y
, INT width
, INT height
)
3999 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4001 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
4004 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4009 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
4010 return NotImplemented
;
4012 save_state
= SaveDC(graphics
->hdc
);
4013 EndPath(graphics
->hdc
);
4014 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
4017 BeginPath(graphics
->hdc
);
4018 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
4019 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
4024 EndPath(graphics
->hdc
);
4025 brush_fill_path(graphics
, brush
);
4030 RestoreDC(graphics
->hdc
, save_state
);
4035 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4040 if (!brush_can_fill_pixels(brush
))
4041 return NotImplemented
;
4043 /* FIXME: This could probably be done more efficiently without regions. */
4045 stat
= GdipCreateRegionPath(path
, &rgn
);
4049 stat
= GdipFillRegion(graphics
, brush
, rgn
);
4051 GdipDeleteRegion(rgn
);
4057 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4059 GpStatus stat
= NotImplemented
;
4061 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
4063 if(!brush
|| !graphics
|| !path
)
4064 return InvalidParameter
;
4069 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4070 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
4072 if (stat
== NotImplemented
)
4073 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
4075 if (stat
== NotImplemented
)
4077 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
4084 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4085 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4090 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
4091 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4093 if(!graphics
|| !brush
)
4094 return InvalidParameter
;
4099 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4103 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4106 stat
= GdipFillPath(graphics
, brush
, path
);
4108 GdipDeletePath(path
);
4114 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4115 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4117 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
4118 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4120 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4123 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
4124 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
4129 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4131 if(!graphics
|| !brush
|| !points
|| !count
)
4132 return InvalidParameter
;
4137 stat
= GdipCreatePath(fillMode
, &path
);
4141 stat
= GdipAddPathPolygon(path
, points
, count
);
4144 stat
= GdipFillPath(graphics
, brush
, path
);
4146 GdipDeletePath(path
);
4152 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4153 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4158 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4160 if(!graphics
|| !brush
|| !points
|| !count
)
4161 return InvalidParameter
;
4166 stat
= GdipCreatePath(fillMode
, &path
);
4170 stat
= GdipAddPathPolygonI(path
, points
, count
);
4173 stat
= GdipFillPath(graphics
, brush
, path
);
4175 GdipDeletePath(path
);
4181 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4182 GDIPCONST GpPointF
*points
, INT count
)
4184 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4186 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4189 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4190 GDIPCONST GpPoint
*points
, INT count
)
4192 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4194 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4197 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4198 REAL x
, REAL y
, REAL width
, REAL height
)
4203 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4205 if(!graphics
|| !brush
)
4206 return InvalidParameter
;
4211 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4215 stat
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
4218 stat
= GdipFillPath(graphics
, brush
, path
);
4220 GdipDeletePath(path
);
4226 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4227 INT x
, INT y
, INT width
, INT height
)
4229 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4231 return GdipFillRectangle(graphics
, brush
, x
, y
, width
, height
);
4234 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4240 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4243 return InvalidParameter
;
4245 for(i
= 0; i
< count
; i
++){
4246 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
4247 if(ret
!= Ok
) return ret
;
4253 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4260 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4262 if(!rects
|| count
<= 0)
4263 return InvalidParameter
;
4265 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
4269 for(i
= 0; i
< count
; i
++){
4270 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4271 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4272 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
4273 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4276 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4282 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4290 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
4291 return NotImplemented
;
4293 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4297 save_state
= SaveDC(graphics
->hdc
);
4298 EndPath(graphics
->hdc
);
4300 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4302 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4304 BeginPath(graphics
->hdc
);
4305 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4306 EndPath(graphics
->hdc
);
4308 brush_fill_path(graphics
, brush
);
4311 RestoreDC(graphics
->hdc
, save_state
);
4318 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4322 GpRegion
*temp_region
;
4323 GpMatrix world_to_device
;
4324 GpRectF graphics_bounds
;
4328 GpRect gp_bound_rect
;
4330 if (!brush_can_fill_pixels(brush
))
4331 return NotImplemented
;
4333 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
4336 stat
= GdipCloneRegion(region
, &temp_region
);
4340 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
4341 CoordinateSpaceWorld
, &world_to_device
);
4344 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4347 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4350 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4352 GdipDeleteRegion(temp_region
);
4355 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4357 DeleteObject(hregion
);
4363 gp_bound_rect
.X
= bound_rect
.left
;
4364 gp_bound_rect
.Y
= bound_rect
.top
;
4365 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4366 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4368 pixel_data
= GdipAlloc(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4374 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4375 &gp_bound_rect
, gp_bound_rect
.Width
);
4378 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4379 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4380 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
);
4382 GdipFree(pixel_data
);
4385 DeleteObject(hregion
);
4391 /*****************************************************************************
4392 * GdipFillRegion [GDIPLUS.@]
4394 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4397 GpStatus stat
= NotImplemented
;
4399 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4401 if (!(graphics
&& brush
&& region
))
4402 return InvalidParameter
;
4407 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4408 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4410 if (stat
== NotImplemented
)
4411 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4413 if (stat
== NotImplemented
)
4415 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4422 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4424 TRACE("(%p,%u)\n", graphics
, intention
);
4427 return InvalidParameter
;
4432 /* We have no internal operation queue, so there's no need to clear it. */
4440 /*****************************************************************************
4441 * GdipGetClipBounds [GDIPLUS.@]
4443 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4445 TRACE("(%p, %p)\n", graphics
, rect
);
4448 return InvalidParameter
;
4453 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
4456 /*****************************************************************************
4457 * GdipGetClipBoundsI [GDIPLUS.@]
4459 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4461 TRACE("(%p, %p)\n", graphics
, rect
);
4464 return InvalidParameter
;
4469 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4472 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4473 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4474 CompositingMode
*mode
)
4476 TRACE("(%p, %p)\n", graphics
, mode
);
4478 if(!graphics
|| !mode
)
4479 return InvalidParameter
;
4484 *mode
= graphics
->compmode
;
4489 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4490 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4491 CompositingQuality
*quality
)
4493 TRACE("(%p, %p)\n", graphics
, quality
);
4495 if(!graphics
|| !quality
)
4496 return InvalidParameter
;
4501 *quality
= graphics
->compqual
;
4506 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4507 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4508 InterpolationMode
*mode
)
4510 TRACE("(%p, %p)\n", graphics
, mode
);
4512 if(!graphics
|| !mode
)
4513 return InvalidParameter
;
4518 *mode
= graphics
->interpolation
;
4523 /* FIXME: Need to handle color depths less than 24bpp */
4524 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4526 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4528 if(!graphics
|| !argb
)
4529 return InvalidParameter
;
4537 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4539 TRACE("(%p, %p)\n", graphics
, scale
);
4541 if(!graphics
|| !scale
)
4542 return InvalidParameter
;
4547 *scale
= graphics
->scale
;
4552 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4554 TRACE("(%p, %p)\n", graphics
, unit
);
4556 if(!graphics
|| !unit
)
4557 return InvalidParameter
;
4562 *unit
= graphics
->unit
;
4567 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4568 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4571 TRACE("(%p, %p)\n", graphics
, mode
);
4573 if(!graphics
|| !mode
)
4574 return InvalidParameter
;
4579 *mode
= graphics
->pixeloffset
;
4584 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4585 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4587 TRACE("(%p, %p)\n", graphics
, mode
);
4589 if(!graphics
|| !mode
)
4590 return InvalidParameter
;
4595 *mode
= graphics
->smoothing
;
4600 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4602 TRACE("(%p, %p)\n", graphics
, contrast
);
4604 if(!graphics
|| !contrast
)
4605 return InvalidParameter
;
4607 *contrast
= graphics
->textcontrast
;
4612 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4613 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4614 TextRenderingHint
*hint
)
4616 TRACE("(%p, %p)\n", graphics
, hint
);
4618 if(!graphics
|| !hint
)
4619 return InvalidParameter
;
4624 *hint
= graphics
->texthint
;
4629 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4634 TRACE("(%p, %p)\n", graphics
, rect
);
4636 if(!graphics
|| !rect
)
4637 return InvalidParameter
;
4642 /* intersect window and graphics clipping regions */
4643 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4646 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4649 /* get bounds of the region */
4650 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4653 GdipDeleteRegion(clip_rgn
);
4658 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4663 TRACE("(%p, %p)\n", graphics
, rect
);
4665 if(!graphics
|| !rect
)
4666 return InvalidParameter
;
4668 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4670 rect
->X
= gdip_round(rectf
.X
);
4671 rect
->Y
= gdip_round(rectf
.Y
);
4672 rect
->Width
= gdip_round(rectf
.Width
);
4673 rect
->Height
= gdip_round(rectf
.Height
);
4679 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4681 TRACE("(%p, %p)\n", graphics
, matrix
);
4683 if(!graphics
|| !matrix
)
4684 return InvalidParameter
;
4689 *matrix
= graphics
->worldtrans
;
4693 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4699 TRACE("(%p, %x)\n", graphics
, color
);
4702 return InvalidParameter
;
4707 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4710 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
4711 GdipDeleteBrush((GpBrush
*)brush
);
4715 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4716 wnd_rect
.Width
, wnd_rect
.Height
);
4718 GdipDeleteBrush((GpBrush
*)brush
);
4723 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4725 TRACE("(%p, %p)\n", graphics
, res
);
4727 if(!graphics
|| !res
)
4728 return InvalidParameter
;
4730 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4733 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4739 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4741 if(!graphics
|| !result
)
4742 return InvalidParameter
;
4749 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4750 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4753 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4756 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4759 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4762 GdipDeleteRegion(rgn
);
4766 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4768 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4771 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4777 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4779 if(!graphics
|| !result
)
4780 return InvalidParameter
;
4787 pts
[1].X
= x
+ width
;
4788 pts
[1].Y
= y
+ height
;
4790 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4791 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4794 pts
[1].X
-= pts
[0].X
;
4795 pts
[1].Y
-= pts
[0].Y
;
4797 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4800 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4803 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4806 GdipDeleteRegion(rgn
);
4810 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4812 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4815 GpStatus
gdip_format_string(HDC hdc
,
4816 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4817 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4818 gdip_format_string_callback callback
, void *user_data
)
4821 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4822 nheight
, lineend
, lineno
= 0;
4824 StringAlignment halign
;
4827 HotkeyPrefix hkprefix
;
4828 INT
*hotkeyprefix_offsets
=NULL
;
4829 INT hotkeyprefix_count
=0;
4830 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4833 if(length
== -1) length
= lstrlenW(string
);
4835 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
4836 if(!stringdup
) return OutOfMemory
;
4838 nwidth
= rect
->Width
;
4839 nheight
= rect
->Height
;
4842 hkprefix
= format
->hkprefix
;
4844 hkprefix
= HotkeyPrefixNone
;
4846 if (hkprefix
== HotkeyPrefixShow
)
4848 for (i
=0; i
<length
; i
++)
4850 if (string
[i
] == '&')
4851 hotkeyprefix_count
++;
4855 if (hotkeyprefix_count
)
4856 hotkeyprefix_offsets
= GdipAlloc(sizeof(INT
) * hotkeyprefix_count
);
4858 hotkeyprefix_count
= 0;
4860 for(i
= 0, j
= 0; i
< length
; i
++){
4861 /* FIXME: This makes the indexes passed to callback inaccurate. */
4862 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4865 /* FIXME: tabs should be handled using tabstops from stringformat */
4866 if (string
[i
] == '\t')
4869 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4870 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4871 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4879 stringdup
[j
] = string
[i
];
4885 if (format
) halign
= format
->align
;
4886 else halign
= StringAlignmentNear
;
4888 while(sum
< length
){
4889 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4890 nwidth
, &fit
, NULL
, &size
);
4896 for(lret
= 0; lret
< fit
; lret
++)
4897 if(*(stringdup
+ sum
+ lret
) == '\n')
4900 /* Line break code (may look strange, but it imitates windows). */
4902 lineend
= fit
= lret
; /* this is not an off-by-one error */
4903 else if(fit
< (length
- sum
)){
4904 if(*(stringdup
+ sum
+ fit
) == ' ')
4905 while(*(stringdup
+ sum
+ fit
) == ' ')
4908 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
4911 if(*(stringdup
+ sum
+ fit
) == '\t')
4920 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
4921 *(stringdup
+ sum
+ lineend
- 1) == '\t')
4927 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
4928 nwidth
, &j
, NULL
, &size
);
4930 bounds
.Width
= size
.cx
;
4932 if(height
+ size
.cy
> nheight
)
4933 bounds
.Height
= nheight
- (height
+ size
.cy
);
4935 bounds
.Height
= size
.cy
;
4937 bounds
.Y
= rect
->Y
+ height
;
4941 case StringAlignmentNear
:
4945 case StringAlignmentCenter
:
4946 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
4948 case StringAlignmentFar
:
4949 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
4953 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
4954 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
4957 stat
= callback(hdc
, stringdup
, sum
, lineend
,
4958 font
, rect
, format
, lineno
, &bounds
,
4959 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
4960 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
4965 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
4969 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
4971 if(height
> nheight
)
4974 /* Stop if this was a linewrap (but not if it was a linebreak). */
4975 if ((lret
== fitcpy
) && format
&&
4976 (format
->attr
& (StringFormatFlagsNoWrap
| StringFormatFlagsLineLimit
)))
4980 GdipFree(stringdup
);
4981 GdipFree(hotkeyprefix_offsets
);
4986 struct measure_ranges_args
{
4988 REAL rel_width
, rel_height
;
4991 static GpStatus
measure_ranges_callback(HDC hdc
,
4992 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4993 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4994 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
4995 INT underlined_index_count
, void *user_data
)
4999 struct measure_ranges_args
*args
= user_data
;
5001 for (i
=0; i
<format
->range_count
; i
++)
5003 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
5004 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
5005 if (range_start
< range_end
)
5010 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
5011 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
5013 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
5014 INT_MAX
, NULL
, NULL
, &range_size
);
5015 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
5017 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
5018 INT_MAX
, NULL
, NULL
, &range_size
);
5019 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
5021 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
5030 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
5031 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
5032 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
5033 INT regionCount
, GpRegion
** regions
)
5037 HFONT gdifont
, oldfont
;
5038 struct measure_ranges_args args
;
5039 HDC hdc
, temp_hdc
=NULL
;
5044 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
5045 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
5047 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
5048 return InvalidParameter
;
5050 if (regionCount
< stringFormat
->range_count
)
5051 return InvalidParameter
;
5055 hdc
= temp_hdc
= CreateCompatibleDC(0);
5056 if (!temp_hdc
) return OutOfMemory
;
5059 hdc
= graphics
->hdc
;
5061 if (stringFormat
->attr
)
5062 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
5070 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5071 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5072 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5073 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5074 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5076 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
5077 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5079 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
5080 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
5081 if (stringFormat
->attr
& StringFormatFlagsNoClip
)
5083 scaled_rect
.Width
= (REAL
)(1 << 23);
5084 scaled_rect
.Height
= (REAL
)(1 << 23);
5088 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
5089 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
5091 if (scaled_rect
.Width
>= 0.5)
5093 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5094 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5097 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
5098 oldfont
= SelectObject(hdc
, gdifont
);
5100 for (i
=0; i
<stringFormat
->range_count
; i
++)
5102 stat
= GdipSetEmpty(regions
[i
]);
5107 args
.regions
= regions
;
5109 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
5110 measure_ranges_callback
, &args
);
5112 SelectObject(hdc
, oldfont
);
5113 DeleteObject(gdifont
);
5121 struct measure_string_args
{
5123 INT
*codepointsfitted
;
5125 REAL rel_width
, rel_height
;
5128 static GpStatus
measure_string_callback(HDC hdc
,
5129 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5130 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5131 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5132 INT underlined_index_count
, void *user_data
)
5134 struct measure_string_args
*args
= user_data
;
5135 REAL new_width
, new_height
;
5137 new_width
= bounds
->Width
/ args
->rel_width
;
5138 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
5140 if (new_width
> args
->bounds
->Width
)
5141 args
->bounds
->Width
= new_width
;
5143 if (new_height
> args
->bounds
->Height
)
5144 args
->bounds
->Height
= new_height
;
5146 if (args
->codepointsfitted
)
5147 *args
->codepointsfitted
= index
+ length
;
5149 if (args
->linesfilled
)
5150 (*args
->linesfilled
)++;
5155 /* Find the smallest rectangle that bounds the text when it is printed in rect
5156 * according to the format options listed in format. If rect has 0 width and
5157 * height, then just find the smallest rectangle that bounds the text when it's
5158 * printed at location (rect->X, rect-Y). */
5159 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
5160 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5161 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
5162 INT
*codepointsfitted
, INT
*linesfilled
)
5164 HFONT oldfont
, gdifont
;
5165 struct measure_string_args args
;
5166 HDC temp_hdc
=NULL
, hdc
;
5170 INT lines
, glyphs
, format_flags
= format
? format
->attr
: 0;
5172 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
5173 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
5174 bounds
, codepointsfitted
, linesfilled
);
5176 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
5177 return InvalidParameter
;
5181 hdc
= temp_hdc
= CreateCompatibleDC(0);
5182 if (!temp_hdc
) return OutOfMemory
;
5185 hdc
= graphics
->hdc
;
5187 if(linesfilled
) *linesfilled
= 0;
5188 if(codepointsfitted
) *codepointsfitted
= 0;
5191 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5199 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5200 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5201 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5202 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5203 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5205 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5206 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5208 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
5209 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
5210 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
5211 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
5213 if ((format_flags
& StringFormatFlagsNoClip
) ||
5214 scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5215 if ((format_flags
& StringFormatFlagsNoClip
) ||
5216 scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5218 if (scaled_rect
.Width
>= 0.5)
5220 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5221 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5224 if (scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5225 if (scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5227 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5228 oldfont
= SelectObject(hdc
, gdifont
);
5230 bounds
->X
= rect
->X
;
5231 bounds
->Y
= rect
->Y
;
5232 bounds
->Width
= 0.0;
5233 bounds
->Height
= 0.0;
5235 args
.bounds
= bounds
;
5236 args
.codepointsfitted
= &glyphs
;
5237 args
.linesfilled
= &lines
;
5240 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
5241 measure_string_callback
, &args
);
5243 if (linesfilled
) *linesfilled
= lines
;
5244 if (codepointsfitted
) *codepointsfitted
= glyphs
;
5247 bounds
->Width
+= margin_x
* 2.0;
5249 SelectObject(hdc
, oldfont
);
5250 DeleteObject(gdifont
);
5258 struct draw_string_args
{
5259 GpGraphics
*graphics
;
5260 GDIPCONST GpBrush
*brush
;
5261 REAL x
, y
, rel_width
, rel_height
, ascent
;
5264 static GpStatus
draw_string_callback(HDC hdc
,
5265 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5266 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5267 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5268 INT underlined_index_count
, void *user_data
)
5270 struct draw_string_args
*args
= user_data
;
5274 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5275 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5277 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
5278 args
->brush
, &position
,
5279 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5281 if (stat
== Ok
&& underlined_index_count
)
5283 OUTLINETEXTMETRICW otm
;
5284 REAL underline_y
, underline_height
;
5287 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5289 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5290 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5292 for (i
=0; i
<underlined_index_count
; i
++)
5294 REAL start_x
, end_x
;
5296 INT ofs
= underlined_indexes
[i
] - index
;
5298 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5299 start_x
= text_size
.cx
/ args
->rel_width
;
5301 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5302 end_x
= text_size
.cx
/ args
->rel_width
;
5304 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5311 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5312 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5313 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5317 GpPointF pt
[3], rectcpy
[4];
5319 REAL rel_width
, rel_height
, margin_x
;
5320 INT save_state
, format_flags
= 0;
5322 struct draw_string_args args
;
5324 HDC hdc
, temp_hdc
=NULL
;
5325 TEXTMETRICW textmetric
;
5327 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5328 length
, font
, debugstr_rectf(rect
), format
, brush
);
5330 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5331 return InvalidParameter
;
5335 hdc
= graphics
->hdc
;
5339 hdc
= temp_hdc
= CreateCompatibleDC(0);
5343 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5345 format_flags
= format
->attr
;
5347 /* Should be no need to explicitly test for StringAlignmentNear as
5348 * that is default behavior if no alignment is passed. */
5349 if(format
->vertalign
!= StringAlignmentNear
){
5350 RectF bounds
, in_rect
= *rect
;
5351 in_rect
.Height
= 0.0; /* avoid height clipping */
5352 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5354 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5356 if(format
->vertalign
== StringAlignmentCenter
)
5357 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5358 else if(format
->vertalign
== StringAlignmentFar
)
5359 offsety
= (rect
->Height
- bounds
.Height
);
5361 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
5364 save_state
= SaveDC(hdc
);
5372 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5373 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5374 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5375 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5376 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5378 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5379 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5380 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5381 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5382 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5384 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5385 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5387 scaled_rect
.X
= margin_x
* rel_width
;
5388 scaled_rect
.Y
= 0.0;
5389 scaled_rect
.Width
= rel_width
* rect
->Width
;
5390 scaled_rect
.Height
= rel_height
* rect
->Height
;
5392 if ((format_flags
& StringFormatFlagsNoClip
) ||
5393 scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5394 if ((format_flags
& StringFormatFlagsNoClip
) ||
5395 scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5397 if (scaled_rect
.Width
>= 0.5)
5399 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5400 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5403 if (scaled_rect
.Width
>= 1 << 23 || scaled_rect
.Width
< 0.5) scaled_rect
.Width
= 1 << 23;
5404 if (scaled_rect
.Height
>= 1 << 23 || scaled_rect
.Height
< 0.5) scaled_rect
.Height
= 1 << 23;
5406 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5407 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23)
5409 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5410 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5411 SelectClipRgn(hdc
, rgn
);
5414 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5415 SelectObject(hdc
, gdifont
);
5417 args
.graphics
= graphics
;
5421 args
.y
= rect
->Y
+ offsety
;
5423 args
.rel_width
= rel_width
;
5424 args
.rel_height
= rel_height
;
5426 GetTextMetricsW(hdc
, &textmetric
);
5427 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5429 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
,
5430 draw_string_callback
, &args
);
5433 DeleteObject(gdifont
);
5435 RestoreDC(hdc
, save_state
);
5442 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5444 TRACE("(%p)\n", graphics
);
5447 return InvalidParameter
;
5452 return GdipSetInfinite(graphics
->clip
);
5455 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5457 TRACE("(%p)\n", graphics
);
5460 return InvalidParameter
;
5465 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5468 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5470 return GdipEndContainer(graphics
, state
);
5473 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5474 GpMatrixOrder order
)
5476 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5479 return InvalidParameter
;
5484 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5487 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5489 return GdipBeginContainer2(graphics
, state
);
5492 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5493 GraphicsContainer
*state
)
5495 GraphicsContainerItem
*container
;
5498 TRACE("(%p, %p)\n", graphics
, state
);
5500 if(!graphics
|| !state
)
5501 return InvalidParameter
;
5503 sts
= init_container(&container
, graphics
);
5507 list_add_head(&graphics
->containers
, &container
->entry
);
5508 *state
= graphics
->contid
= container
->contid
;
5513 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5515 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5516 return NotImplemented
;
5519 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5521 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
5522 return NotImplemented
;
5525 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5527 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5528 return NotImplemented
;
5531 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5534 GraphicsContainerItem
*container
, *container2
;
5536 TRACE("(%p, %x)\n", graphics
, state
);
5539 return InvalidParameter
;
5541 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5542 if(container
->contid
== state
)
5546 /* did not find a matching container */
5547 if(&container
->entry
== &graphics
->containers
)
5550 sts
= restore_container(graphics
, container
);
5554 /* remove all of the containers on top of the found container */
5555 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5556 if(container
->contid
== state
)
5558 list_remove(&container
->entry
);
5559 delete_container(container
);
5562 list_remove(&container
->entry
);
5563 delete_container(container
);
5568 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5569 REAL sy
, GpMatrixOrder order
)
5571 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5574 return InvalidParameter
;
5579 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5582 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5585 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5587 if(!graphics
|| !srcgraphics
)
5588 return InvalidParameter
;
5590 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5593 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5594 CompositingMode mode
)
5596 TRACE("(%p, %d)\n", graphics
, mode
);
5599 return InvalidParameter
;
5604 graphics
->compmode
= mode
;
5609 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5610 CompositingQuality quality
)
5612 TRACE("(%p, %d)\n", graphics
, quality
);
5615 return InvalidParameter
;
5620 graphics
->compqual
= quality
;
5625 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5626 InterpolationMode mode
)
5628 TRACE("(%p, %d)\n", graphics
, mode
);
5630 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5631 return InvalidParameter
;
5636 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5637 mode
= InterpolationModeBilinear
;
5639 if (mode
== InterpolationModeHighQuality
)
5640 mode
= InterpolationModeHighQualityBicubic
;
5642 graphics
->interpolation
= mode
;
5647 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5649 TRACE("(%p, %.2f)\n", graphics
, scale
);
5651 if(!graphics
|| (scale
<= 0.0))
5652 return InvalidParameter
;
5657 graphics
->scale
= scale
;
5662 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5664 TRACE("(%p, %d)\n", graphics
, unit
);
5667 return InvalidParameter
;
5672 if(unit
== UnitWorld
)
5673 return InvalidParameter
;
5675 graphics
->unit
= unit
;
5680 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5683 TRACE("(%p, %d)\n", graphics
, mode
);
5686 return InvalidParameter
;
5691 graphics
->pixeloffset
= mode
;
5696 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5700 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5703 FIXME("value is unused in rendering\n");
5706 return InvalidParameter
;
5708 graphics
->origin_x
= x
;
5709 graphics
->origin_y
= y
;
5714 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5716 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5718 if (!graphics
|| !x
|| !y
)
5719 return InvalidParameter
;
5721 *x
= graphics
->origin_x
;
5722 *y
= graphics
->origin_y
;
5727 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5729 TRACE("(%p, %d)\n", graphics
, mode
);
5732 return InvalidParameter
;
5737 graphics
->smoothing
= mode
;
5742 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5744 TRACE("(%p, %d)\n", graphics
, contrast
);
5747 return InvalidParameter
;
5749 graphics
->textcontrast
= contrast
;
5754 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5755 TextRenderingHint hint
)
5757 TRACE("(%p, %d)\n", graphics
, hint
);
5759 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5760 return InvalidParameter
;
5765 graphics
->texthint
= hint
;
5770 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5772 TRACE("(%p, %p)\n", graphics
, matrix
);
5774 if(!graphics
|| !matrix
)
5775 return InvalidParameter
;
5780 TRACE("%f,%f,%f,%f,%f,%f\n",
5781 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5782 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5784 graphics
->worldtrans
= *matrix
;
5789 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
5790 REAL dy
, GpMatrixOrder order
)
5792 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
5795 return InvalidParameter
;
5800 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
5803 /*****************************************************************************
5804 * GdipSetClipHrgn [GDIPLUS.@]
5806 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
5811 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
5814 return InvalidParameter
;
5816 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
5820 status
= GdipSetClipRegion(graphics
, region
, mode
);
5822 GdipDeleteRegion(region
);
5826 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
5828 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
5831 return InvalidParameter
;
5836 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
5839 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
5840 REAL width
, REAL height
,
5845 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5848 return InvalidParameter
;
5856 rect
.Height
= height
;
5858 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
5861 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
5862 INT width
, INT height
,
5865 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
5868 return InvalidParameter
;
5873 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
5876 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
5879 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
5881 if(!graphics
|| !region
)
5882 return InvalidParameter
;
5887 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
5890 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
5895 TRACE("(%p,%u)\n", metafile
, limitDpi
);
5898 FIXME("not implemented\n");
5900 return NotImplemented
;
5903 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
5909 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
5911 if(!graphics
|| !pen
|| count
<=0)
5912 return InvalidParameter
;
5919 FIXME("graphics object has no HDC\n");
5923 pti
= GdipAlloc(sizeof(POINT
) * count
);
5925 save_state
= prepare_dc(graphics
, pen
);
5926 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
5928 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
5929 Polygon(graphics
->hdc
, pti
, count
);
5931 restore_dc(graphics
, save_state
);
5937 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
5944 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
5946 if(count
<=0) return InvalidParameter
;
5947 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
5949 for(i
= 0;i
< count
; i
++){
5950 ptf
[i
].X
= (REAL
)points
[i
].X
;
5951 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
5954 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
5960 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
5962 TRACE("(%p, %p)\n", graphics
, dpi
);
5964 if(!graphics
|| !dpi
)
5965 return InvalidParameter
;
5970 *dpi
= graphics
->xres
;
5974 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
5976 TRACE("(%p, %p)\n", graphics
, dpi
);
5978 if(!graphics
|| !dpi
)
5979 return InvalidParameter
;
5984 *dpi
= graphics
->yres
;
5988 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
5989 GpMatrixOrder order
)
5994 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
5996 if(!graphics
|| !matrix
)
5997 return InvalidParameter
;
6002 m
= graphics
->worldtrans
;
6004 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
6006 graphics
->worldtrans
= m
;
6011 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
6012 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
6014 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
6018 TRACE("(%p, %p)\n", graphics
, hdc
);
6020 if(!graphics
|| !hdc
)
6021 return InvalidParameter
;
6026 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6028 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
6030 else if (!graphics
->hdc
|| graphics
->alpha_hdc
||
6031 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
6033 /* Create a fake HDC and fill it with a constant color. */
6037 BITMAPINFOHEADER bmih
;
6040 stat
= get_graphics_bounds(graphics
, &bounds
);
6044 graphics
->temp_hbitmap_width
= bounds
.Width
;
6045 graphics
->temp_hbitmap_height
= bounds
.Height
;
6047 bmih
.biSize
= sizeof(bmih
);
6048 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
6049 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
6051 bmih
.biBitCount
= 32;
6052 bmih
.biCompression
= BI_RGB
;
6053 bmih
.biSizeImage
= 0;
6054 bmih
.biXPelsPerMeter
= 0;
6055 bmih
.biYPelsPerMeter
= 0;
6057 bmih
.biClrImportant
= 0;
6059 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
6060 (void**)&graphics
->temp_bits
, NULL
, 0);
6062 return GenericError
;
6064 temp_hdc
= CreateCompatibleDC(0);
6067 DeleteObject(hbitmap
);
6068 return GenericError
;
6071 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6072 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
6074 SelectObject(temp_hdc
, hbitmap
);
6076 graphics
->temp_hbitmap
= hbitmap
;
6077 *hdc
= graphics
->temp_hdc
= temp_hdc
;
6081 *hdc
= graphics
->hdc
;
6085 graphics
->busy
= TRUE
;
6090 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
6094 TRACE("(%p, %p)\n", graphics
, hdc
);
6096 if(!graphics
|| !hdc
|| !graphics
->busy
)
6097 return InvalidParameter
;
6099 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6101 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
6103 else if (graphics
->temp_hdc
== hdc
)
6108 /* Find the pixels that have changed, and mark them as opaque. */
6109 pos
= (DWORD
*)graphics
->temp_bits
;
6110 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6112 if (*pos
!= DC_BACKGROUND_KEY
)
6119 /* Write the changed pixels to the real target. */
6120 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
6121 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
6122 graphics
->temp_hbitmap_width
* 4);
6125 DeleteDC(graphics
->temp_hdc
);
6126 DeleteObject(graphics
->temp_hbitmap
);
6127 graphics
->temp_hdc
= NULL
;
6128 graphics
->temp_hbitmap
= NULL
;
6130 else if (hdc
!= graphics
->hdc
)
6132 stat
= InvalidParameter
;
6136 graphics
->busy
= FALSE
;
6141 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
6146 TRACE("(%p, %p)\n", graphics
, region
);
6148 if(!graphics
|| !region
)
6149 return InvalidParameter
;
6154 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
6157 /* free everything except root node and header */
6158 delete_element(®ion
->node
);
6159 memcpy(region
, clip
, sizeof(GpRegion
));
6165 static GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6166 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
6169 REAL scale_x
, scale_y
;
6171 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
6173 if (dst_space
!= src_space
)
6175 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
6176 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
6178 if(graphics
->unit
!= UnitDisplay
)
6180 scale_x
*= graphics
->scale
;
6181 scale_y
*= graphics
->scale
;
6184 /* transform from src_space to CoordinateSpacePage */
6187 case CoordinateSpaceWorld
:
6188 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
6190 case CoordinateSpacePage
:
6192 case CoordinateSpaceDevice
:
6193 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
6197 /* transform from CoordinateSpacePage to dst_space */
6200 case CoordinateSpaceWorld
:
6202 GpMatrix inverted_transform
= graphics
->worldtrans
;
6203 stat
= GdipInvertMatrix(&inverted_transform
);
6205 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
6208 case CoordinateSpacePage
:
6210 case CoordinateSpaceDevice
:
6211 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
6218 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6219 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6224 if(!graphics
|| !points
|| count
<= 0)
6225 return InvalidParameter
;
6230 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6232 if (src_space
== dst_space
) return Ok
;
6234 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6235 if (stat
!= Ok
) return stat
;
6237 return GdipTransformMatrixPoints(&matrix
, points
, count
);
6240 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6241 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6247 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6250 return InvalidParameter
;
6252 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
6256 for(i
= 0; i
< count
; i
++){
6257 pointsF
[i
].X
= (REAL
)points
[i
].X
;
6258 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
6261 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6264 for(i
= 0; i
< count
; i
++){
6265 points
[i
].X
= gdip_round(pointsF
[i
].X
);
6266 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
6273 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6285 /*****************************************************************************
6286 * GdipTranslateClip [GDIPLUS.@]
6288 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6290 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6293 return InvalidParameter
;
6298 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6301 /*****************************************************************************
6302 * GdipTranslateClipI [GDIPLUS.@]
6304 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6306 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6309 return InvalidParameter
;
6314 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6318 /*****************************************************************************
6319 * GdipMeasureDriverString [GDIPLUS.@]
6321 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6322 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6323 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6325 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6328 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6330 TEXTMETRICW textmetric
;
6331 const WORD
*glyph_indices
;
6332 WORD
*dynamic_glyph_indices
=NULL
;
6333 REAL rel_width
, rel_height
, ascent
, descent
;
6336 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6338 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6339 return InvalidParameter
;
6342 length
= strlenW(text
);
6346 boundingBox
->X
= 0.0;
6347 boundingBox
->Y
= 0.0;
6348 boundingBox
->Width
= 0.0;
6349 boundingBox
->Height
= 0.0;
6352 if (flags
& unsupported_flags
)
6353 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6355 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6357 hdc
= CreateCompatibleDC(0);
6358 SelectObject(hdc
, hfont
);
6360 GetTextMetricsW(hdc
, &textmetric
);
6370 GpMatrix xform
= *matrix
;
6371 GdipTransformMatrixPoints(&xform
, pt
, 3);
6373 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6374 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6375 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6376 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6377 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6379 if (flags
& DriverStringOptionsCmapLookup
)
6381 glyph_indices
= dynamic_glyph_indices
= GdipAlloc(sizeof(WORD
) * length
);
6385 DeleteObject(hfont
);
6389 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6392 glyph_indices
= text
;
6394 min_x
= max_x
= x
= positions
[0].X
;
6395 min_y
= max_y
= y
= positions
[0].Y
;
6397 ascent
= textmetric
.tmAscent
/ rel_height
;
6398 descent
= textmetric
.tmDescent
/ rel_height
;
6400 for (i
=0; i
<length
; i
++)
6405 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6411 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6412 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6414 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6415 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6416 if (min_x
> x
) min_x
= x
;
6418 x
+= char_width
/ rel_width
;
6420 if (max_x
< x
) max_x
= x
;
6423 GdipFree(dynamic_glyph_indices
);
6425 DeleteObject(hfont
);
6427 boundingBox
->X
= min_x
;
6428 boundingBox
->Y
= min_y
;
6429 boundingBox
->Width
= max_x
- min_x
;
6430 boundingBox
->Height
= max_y
- min_y
;
6435 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6436 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6437 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6438 INT flags
, GDIPCONST GpMatrix
*matrix
)
6440 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6446 if (flags
& unsupported_flags
)
6447 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6449 if (!(flags
& DriverStringOptionsCmapLookup
))
6450 eto_flags
|= ETO_GLYPH_INDEX
;
6452 save_state
= SaveDC(graphics
->hdc
);
6453 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6454 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6457 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6459 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6460 SelectObject(graphics
->hdc
, hfont
);
6462 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6464 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6466 RestoreDC(graphics
->hdc
, save_state
);
6468 DeleteObject(hfont
);
6473 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6474 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6475 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6476 INT flags
, GDIPCONST GpMatrix
*matrix
)
6478 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6480 PointF
*real_positions
, real_position
;
6484 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6485 DWORD max_glyphsize
=0;
6486 GLYPHMETRICS glyphmetrics
;
6487 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6490 int text_mask_stride
;
6492 int pixel_data_stride
;
6494 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6499 if (!(flags
& DriverStringOptionsCmapLookup
))
6500 ggo_flags
|= GGO_GLYPH_INDEX
;
6502 if (flags
& unsupported_flags
)
6503 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6505 pti
= GdipAlloc(sizeof(POINT
) * length
);
6509 if (flags
& DriverStringOptionsRealizedAdvance
)
6511 real_position
= positions
[0];
6513 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6517 real_positions
= GdipAlloc(sizeof(PointF
) * length
);
6518 if (!real_positions
)
6524 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6526 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6528 GdipFree(real_positions
);
6531 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6533 hdc
= CreateCompatibleDC(0);
6534 SelectObject(hdc
, hfont
);
6536 /* Get the boundaries of the text to be drawn */
6537 for (i
=0; i
<length
; i
++)
6540 int left
, top
, right
, bottom
;
6542 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6543 &glyphmetrics
, 0, NULL
, &identity
);
6545 if (glyphsize
== GDI_ERROR
)
6547 ERR("GetGlyphOutlineW failed\n");
6550 DeleteObject(hfont
);
6551 return GenericError
;
6554 if (glyphsize
> max_glyphsize
)
6555 max_glyphsize
= glyphsize
;
6557 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6558 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6559 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6560 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6562 if (left
< min_x
) min_x
= left
;
6563 if (top
< min_y
) min_y
= top
;
6564 if (right
> max_x
) max_x
= right
;
6565 if (bottom
> max_y
) max_y
= bottom
;
6567 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6569 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6570 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6574 glyph_mask
= GdipAlloc(max_glyphsize
);
6575 text_mask
= GdipAlloc((max_x
- min_x
) * (max_y
- min_y
));
6576 text_mask_stride
= max_x
- min_x
;
6578 if (!(glyph_mask
&& text_mask
))
6580 GdipFree(glyph_mask
);
6581 GdipFree(text_mask
);
6584 DeleteObject(hfont
);
6588 /* Generate a mask for the text */
6589 for (i
=0; i
<length
; i
++)
6591 int left
, top
, stride
;
6593 GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6594 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6596 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6597 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6598 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6600 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6602 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6603 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6604 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6606 *text_val
= min(64, *text_val
+ *glyph_val
);
6615 DeleteObject(hfont
);
6616 GdipFree(glyph_mask
);
6618 /* get the brush data */
6619 pixel_data
= GdipAlloc(4 * (max_x
- min_x
) * (max_y
- min_y
));
6622 GdipFree(text_mask
);
6626 pixel_area
.X
= min_x
;
6627 pixel_area
.Y
= min_y
;
6628 pixel_area
.Width
= max_x
- min_x
;
6629 pixel_area
.Height
= max_y
- min_y
;
6630 pixel_data_stride
= pixel_area
.Width
* 4;
6632 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6635 GdipFree(text_mask
);
6636 GdipFree(pixel_data
);
6640 /* multiply the brush data by the mask */
6641 for (y
=0; y
<pixel_area
.Height
; y
++)
6643 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6644 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6645 for (x
=0; x
<pixel_area
.Width
; x
++)
6647 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6653 GdipFree(text_mask
);
6655 /* draw the result */
6656 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6657 pixel_area
.Height
, pixel_data_stride
);
6659 GdipFree(pixel_data
);
6664 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6665 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6666 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6667 INT flags
, GDIPCONST GpMatrix
*matrix
)
6669 GpStatus stat
= NotImplemented
;
6672 length
= strlenW(text
);
6674 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6675 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6676 brush
->bt
== BrushTypeSolidColor
&&
6677 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6678 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6679 brush
, positions
, flags
, matrix
);
6680 if (stat
== NotImplemented
)
6681 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6682 brush
, positions
, flags
, matrix
);
6686 /*****************************************************************************
6687 * GdipDrawDriverString [GDIPLUS.@]
6689 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6690 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6691 GDIPCONST PointF
*positions
, INT flags
,
6692 GDIPCONST GpMatrix
*matrix
)
6694 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6696 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6697 return InvalidParameter
;
6699 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6700 brush
, positions
, flags
, matrix
);
6703 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
6704 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
6706 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
6707 return NotImplemented
;
6710 /*****************************************************************************
6711 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6713 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
6718 TRACE("(%p, %p)\n", graphics
, res
);
6720 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
6723 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
6726 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
6729 GdipDeleteRegion(rgn
);
6733 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
6737 TRACE("(%p) stub\n", graphics
);
6740 FIXME("not implemented\n");
6742 return NotImplemented
;