2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/unicode.h"
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
45 /* looks-right constants */
46 #define ANCHOR_WIDTH (2.0)
47 #define MAX_ITERS (50)
49 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
50 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
51 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
52 INT flags
, GDIPCONST GpMatrix
*matrix
);
54 /* Converts from gdiplus path point type to gdi path point type. */
55 static BYTE
convert_path_point_type(BYTE type
)
59 switch(type
& PathPointTypePathTypeMask
){
60 case PathPointTypeBezier
:
63 case PathPointTypeLine
:
66 case PathPointTypeStart
:
70 ERR("Bad point type\n");
74 if(type
& PathPointTypeCloseSubpath
)
75 ret
|= PT_CLOSEFIGURE
;
80 static COLORREF
get_gdi_brush_color(const GpBrush
*brush
)
86 case BrushTypeSolidColor
:
88 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
92 case BrushTypeHatchFill
:
94 const GpHatch
*hatch
= (const GpHatch
*)brush
;
95 argb
= hatch
->forecol
;
98 case BrushTypeLinearGradient
:
100 const GpLineGradient
*line
= (const GpLineGradient
*)brush
;
101 argb
= line
->startcolor
;
104 case BrushTypePathGradient
:
106 const GpPathGradient
*grad
= (const GpPathGradient
*)brush
;
107 argb
= grad
->centercolor
;
111 FIXME("unhandled brush type %d\n", brush
->bt
);
115 return ARGB2COLORREF(argb
);
118 static HBITMAP
create_hatch_bitmap(const GpHatch
*hatch
)
121 BITMAPINFOHEADER bmih
;
125 bmih
.biSize
= sizeof(bmih
);
129 bmih
.biBitCount
= 32;
130 bmih
.biCompression
= BI_RGB
;
131 bmih
.biSizeImage
= 0;
133 hbmp
= CreateDIBSection(0, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void **)&bits
, NULL
, 0);
136 const char *hatch_data
;
138 if (get_hatch_data(hatch
->hatchstyle
, &hatch_data
) == Ok
)
140 for (y
= 0; y
< 8; y
++)
142 for (x
= 0; x
< 8; x
++)
144 if (hatch_data
[y
] & (0x80 >> x
))
145 bits
[y
* 8 + x
] = hatch
->forecol
;
147 bits
[y
* 8 + x
] = hatch
->backcol
;
153 FIXME("Unimplemented hatch style %d\n", hatch
->hatchstyle
);
155 for (y
= 0; y
< 64; y
++)
156 bits
[y
] = hatch
->forecol
;
163 static GpStatus
create_gdi_logbrush(const GpBrush
*brush
, LOGBRUSH
*lb
)
167 case BrushTypeSolidColor
:
169 const GpSolidFill
*sf
= (const GpSolidFill
*)brush
;
170 lb
->lbStyle
= BS_SOLID
;
171 lb
->lbColor
= ARGB2COLORREF(sf
->color
);
176 case BrushTypeHatchFill
:
178 const GpHatch
*hatch
= (const GpHatch
*)brush
;
181 hbmp
= create_hatch_bitmap(hatch
);
182 if (!hbmp
) return OutOfMemory
;
184 lb
->lbStyle
= BS_PATTERN
;
186 lb
->lbHatch
= (ULONG_PTR
)hbmp
;
191 FIXME("unhandled brush type %d\n", brush
->bt
);
192 lb
->lbStyle
= BS_SOLID
;
193 lb
->lbColor
= get_gdi_brush_color(brush
);
199 static GpStatus
free_gdi_logbrush(LOGBRUSH
*lb
)
204 DeleteObject((HGDIOBJ
)(ULONG_PTR
)lb
->lbHatch
);
210 static HBRUSH
create_gdi_brush(const GpBrush
*brush
)
215 if (create_gdi_logbrush(brush
, &lb
) != Ok
) return 0;
217 gdibrush
= CreateBrushIndirect(&lb
);
218 free_gdi_logbrush(&lb
);
223 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
228 INT save_state
, i
, numdashes
;
230 DWORD dash_array
[MAX_DASHLEN
];
232 save_state
= SaveDC(graphics
->hdc
);
234 EndPath(graphics
->hdc
);
236 if(pen
->unit
== UnitPixel
){
240 /* Get an estimate for the amount the pen width is affected by the world
241 * transform. (This is similar to what some of the wine drivers do.) */
246 GdipTransformMatrixPoints(&graphics
->worldtrans
, pt
, 2);
247 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
248 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
250 width
*= units_to_pixels(pen
->width
, pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
, graphics
->xres
);
251 width
*= graphics
->scale
;
254 if(pen
->dash
== DashStyleCustom
){
255 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
257 TRACE("dashes are: ");
258 for(i
= 0; i
< numdashes
; i
++){
259 dash_array
[i
] = gdip_round(width
* pen
->dashes
[i
]);
260 TRACE("%d, ", dash_array
[i
]);
262 TRACE("\n and the pen style is %x\n", pen
->style
);
264 create_gdi_logbrush(pen
->brush
, &lb
);
265 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
,
266 numdashes
, dash_array
);
267 free_gdi_logbrush(&lb
);
271 create_gdi_logbrush(pen
->brush
, &lb
);
272 gdipen
= ExtCreatePen(pen
->style
, gdip_round(width
), &lb
, 0, NULL
);
273 free_gdi_logbrush(&lb
);
276 SelectObject(graphics
->hdc
, gdipen
);
281 static void restore_dc(GpGraphics
*graphics
, INT state
)
283 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
284 RestoreDC(graphics
->hdc
, state
);
287 /* This helper applies all the changes that the points listed in ptf need in
288 * order to be drawn on the device context. In the end, this should include at
290 * -scaling by page unit
291 * -applying world transformation
292 * -converting from float to int
293 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
294 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
295 * gdi to draw, and these functions would irreparably mess with line widths.
297 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
298 GpPointF
*ptf
, INT count
)
300 REAL scale_x
, scale_y
;
304 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
305 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
307 /* apply page scale */
308 if(graphics
->unit
!= UnitDisplay
)
310 scale_x
*= graphics
->scale
;
311 scale_y
*= graphics
->scale
;
314 matrix
= graphics
->worldtrans
;
315 GdipScaleMatrix(&matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
316 GdipTransformMatrixPoints(&matrix
, ptf
, count
);
318 for(i
= 0; i
< count
; i
++){
319 pti
[i
].x
= gdip_round(ptf
[i
].X
);
320 pti
[i
].y
= gdip_round(ptf
[i
].Y
);
324 static void gdi_alpha_blend(GpGraphics
*graphics
, INT dst_x
, INT dst_y
, INT dst_width
, INT dst_height
,
325 HDC hdc
, INT src_x
, INT src_y
, INT src_width
, INT src_height
)
327 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
)
329 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
331 StretchBlt(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
332 hdc
, src_x
, src_y
, src_width
, src_height
, SRCCOPY
);
338 bf
.BlendOp
= AC_SRC_OVER
;
340 bf
.SourceConstantAlpha
= 255;
341 bf
.AlphaFormat
= AC_SRC_ALPHA
;
343 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, dst_width
, dst_height
,
344 hdc
, src_x
, src_y
, src_width
, src_height
, bf
);
348 static GpStatus
get_clip_hrgn(GpGraphics
*graphics
, HRGN
*hrgn
)
350 /* clipping region is in device coords */
351 return GdipGetRegionHRgn(graphics
->clip
, NULL
, hrgn
);
354 /* Draw ARGB data to the given graphics object */
355 static GpStatus
alpha_blend_bmp_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
356 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, const PixelFormat fmt
)
358 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
361 for (y
=0; y
<src_height
; y
++)
363 for (x
=0; x
<src_width
; x
++)
365 ARGB dst_color
, src_color
;
366 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
368 if (!(src_color
& 0xff000000))
371 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
372 if (fmt
& PixelFormatPAlpha
)
373 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over_fgpremult(dst_color
, src_color
));
375 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
382 static GpStatus
alpha_blend_hdc_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
383 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
387 BITMAPINFOHEADER bih
;
390 hdc
= CreateCompatibleDC(0);
392 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
393 bih
.biWidth
= src_width
;
394 bih
.biHeight
= -src_height
;
397 bih
.biCompression
= BI_RGB
;
399 bih
.biXPelsPerMeter
= 0;
400 bih
.biYPelsPerMeter
= 0;
402 bih
.biClrImportant
= 0;
404 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
405 (void**)&temp_bits
, NULL
, 0);
407 if (GetDeviceCaps(graphics
->hdc
, SHADEBLENDCAPS
) == SB_NONE
||
408 fmt
& PixelFormatPAlpha
)
409 memcpy(temp_bits
, src
, src_width
* src_height
* 4);
411 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
412 4 * src_width
, src
, src_stride
);
414 SelectObject(hdc
, hbitmap
);
415 gdi_alpha_blend(graphics
, dst_x
, dst_y
, src_width
, src_height
,
416 hdc
, 0, 0, src_width
, src_height
);
418 DeleteObject(hbitmap
);
423 static GpStatus
alpha_blend_pixels_hrgn(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
424 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, HRGN hregion
, PixelFormat fmt
)
428 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
434 HRGN hrgn
, visible_rgn
;
436 hrgn
= CreateRectRgn(dst_x
, dst_y
, dst_x
+ src_width
, dst_y
+ src_height
);
440 stat
= get_clip_hrgn(graphics
, &visible_rgn
);
449 CombineRgn(hrgn
, hrgn
, visible_rgn
, RGN_AND
);
450 DeleteObject(visible_rgn
);
454 CombineRgn(hrgn
, hrgn
, hregion
, RGN_AND
);
456 size
= GetRegionData(hrgn
, 0, NULL
);
458 rgndata
= heap_alloc_zero(size
);
465 GetRegionData(hrgn
, size
, rgndata
);
467 rects
= (RECT
*)rgndata
->Buffer
;
469 for (i
=0; stat
== Ok
&& i
<rgndata
->rdh
.nCount
; i
++)
471 stat
= alpha_blend_bmp_pixels(graphics
, rects
[i
].left
, rects
[i
].top
,
472 &src
[(rects
[i
].left
- dst_x
) * 4 + (rects
[i
].top
- dst_y
) * src_stride
],
473 rects
[i
].right
- rects
[i
].left
, rects
[i
].bottom
- rects
[i
].top
,
483 else if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
485 ERR("This should not be used for metafiles; fix caller\n");
486 return NotImplemented
;
493 stat
= get_clip_hrgn(graphics
, &hrgn
);
498 save
= SaveDC(graphics
->hdc
);
501 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
504 ExtSelectClipRgn(graphics
->hdc
, hregion
, RGN_AND
);
506 stat
= alpha_blend_hdc_pixels(graphics
, dst_x
, dst_y
, src
, src_width
,
507 src_height
, src_stride
, fmt
);
509 RestoreDC(graphics
->hdc
, save
);
517 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
518 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
, PixelFormat fmt
)
520 return alpha_blend_pixels_hrgn(graphics
, dst_x
, dst_y
, src
, src_width
, src_height
, src_stride
, NULL
, fmt
);
523 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
525 INT start_a
, end_a
, final_a
;
528 pos
= gdip_round(position
* 0xff);
530 start_a
= ((start
>> 24) & 0xff) * (pos
^ 0xff);
531 end_a
= ((end
>> 24) & 0xff) * pos
;
533 final_a
= start_a
+ end_a
;
535 if (final_a
< 0xff) return 0;
537 return (final_a
/ 0xff) << 24 |
538 ((((start
>> 16) & 0xff) * start_a
+ (((end
>> 16) & 0xff) * end_a
)) / final_a
) << 16 |
539 ((((start
>> 8) & 0xff) * start_a
+ (((end
>> 8) & 0xff) * end_a
)) / final_a
) << 8 |
540 (((start
& 0xff) * start_a
+ ((end
& 0xff) * end_a
)) / final_a
);
543 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
547 /* clamp to between 0.0 and 1.0, using the wrap mode */
548 if (brush
->wrap
== WrapModeTile
)
550 position
= fmodf(position
, 1.0f
);
551 if (position
< 0.0f
) position
+= 1.0f
;
553 else /* WrapModeFlip* */
555 position
= fmodf(position
, 2.0f
);
556 if (position
< 0.0f
) position
+= 2.0f
;
557 if (position
> 1.0f
) position
= 2.0f
- position
;
560 if (brush
->blendcount
== 1)
565 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
568 /* locate the blend positions surrounding this position */
569 while (position
> brush
->blendpos
[i
])
572 /* interpolate between the blend positions */
573 left_blendpos
= brush
->blendpos
[i
-1];
574 left_blendfac
= brush
->blendfac
[i
-1];
575 right_blendpos
= brush
->blendpos
[i
];
576 right_blendfac
= brush
->blendfac
[i
];
577 range
= right_blendpos
- left_blendpos
;
578 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
579 right_blendfac
* (position
- left_blendpos
)) / range
;
582 if (brush
->pblendcount
== 0)
583 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
587 ARGB left_blendcolor
, right_blendcolor
;
588 REAL left_blendpos
, right_blendpos
;
590 /* locate the blend colors surrounding this position */
591 while (blendfac
> brush
->pblendpos
[i
])
594 /* interpolate between the blend colors */
595 left_blendpos
= brush
->pblendpos
[i
-1];
596 left_blendcolor
= brush
->pblendcolor
[i
-1];
597 right_blendpos
= brush
->pblendpos
[i
];
598 right_blendcolor
= brush
->pblendcolor
[i
];
599 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
600 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
604 static BOOL
round_color_matrix(const ColorMatrix
*matrix
, int values
[5][5])
606 /* Convert floating point color matrix to int[5][5], return TRUE if it's an identity */
607 BOOL identity
= TRUE
;
613 if (matrix
->m
[j
][i
] != (i
== j
? 1.0 : 0.0))
615 values
[j
][i
] = gdip_round(matrix
->m
[j
][i
] * 256.0);
621 static ARGB
transform_color(ARGB color
, int matrix
[5][5])
625 unsigned char a
, r
, g
, b
;
627 val
[0] = ((color
>> 16) & 0xff); /* red */
628 val
[1] = ((color
>> 8) & 0xff); /* green */
629 val
[2] = (color
& 0xff); /* blue */
630 val
[3] = ((color
>> 24) & 0xff); /* alpha */
631 val
[4] = 255; /* translation */
638 res
[i
] += matrix
[j
][i
] * val
[j
];
641 a
= min(max(res
[3] / 256, 0), 255);
642 r
= min(max(res
[0] / 256, 0), 255);
643 g
= min(max(res
[1] / 256, 0), 255);
644 b
= min(max(res
[2] / 256, 0), 255);
646 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
649 static BOOL
color_is_gray(ARGB color
)
651 unsigned char r
, g
, b
;
653 r
= (color
>> 16) & 0xff;
654 g
= (color
>> 8) & 0xff;
657 return (r
== g
) && (g
== b
);
660 /* returns preferred pixel format for the applied attributes */
661 PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
662 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
)
667 if (attributes
->colorkeys
[type
].enabled
||
668 attributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
670 const struct color_key
*key
;
671 BYTE min_blue
, min_green
, min_red
;
672 BYTE max_blue
, max_green
, max_red
;
674 if (!data
|| fmt
!= PixelFormat32bppARGB
)
675 return PixelFormat32bppARGB
;
677 if (attributes
->colorkeys
[type
].enabled
)
678 key
= &attributes
->colorkeys
[type
];
680 key
= &attributes
->colorkeys
[ColorAdjustTypeDefault
];
682 min_blue
= key
->low
&0xff;
683 min_green
= (key
->low
>>8)&0xff;
684 min_red
= (key
->low
>>16)&0xff;
686 max_blue
= key
->high
&0xff;
687 max_green
= (key
->high
>>8)&0xff;
688 max_red
= (key
->high
>>16)&0xff;
690 for (x
=0; x
<width
; x
++)
691 for (y
=0; y
<height
; y
++)
694 BYTE blue
, green
, red
;
695 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
696 blue
= *src_color
&0xff;
697 green
= (*src_color
>>8)&0xff;
698 red
= (*src_color
>>16)&0xff;
699 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
700 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
701 *src_color
= 0x00000000;
705 if (attributes
->colorremaptables
[type
].enabled
||
706 attributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
708 const struct color_remap_table
*table
;
710 if (!data
|| fmt
!= PixelFormat32bppARGB
)
711 return PixelFormat32bppARGB
;
713 if (attributes
->colorremaptables
[type
].enabled
)
714 table
= &attributes
->colorremaptables
[type
];
716 table
= &attributes
->colorremaptables
[ColorAdjustTypeDefault
];
718 for (x
=0; x
<width
; x
++)
719 for (y
=0; y
<height
; y
++)
722 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
723 for (i
=0; i
<table
->mapsize
; i
++)
725 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
727 *src_color
= table
->colormap
[i
].newColor
.Argb
;
734 if (attributes
->colormatrices
[type
].enabled
||
735 attributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
737 const struct color_matrix
*colormatrices
;
738 int color_matrix
[5][5];
739 int gray_matrix
[5][5];
742 if (!data
|| fmt
!= PixelFormat32bppARGB
)
743 return PixelFormat32bppARGB
;
745 if (attributes
->colormatrices
[type
].enabled
)
746 colormatrices
= &attributes
->colormatrices
[type
];
748 colormatrices
= &attributes
->colormatrices
[ColorAdjustTypeDefault
];
750 identity
= round_color_matrix(&colormatrices
->colormatrix
, color_matrix
);
752 if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
753 identity
= (round_color_matrix(&colormatrices
->graymatrix
, gray_matrix
) && identity
);
757 for (x
=0; x
<width
; x
++)
759 for (y
=0; y
<height
; y
++)
762 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
764 if (colormatrices
->flags
== ColorMatrixFlagsDefault
||
765 !color_is_gray(*src_color
))
767 *src_color
= transform_color(*src_color
, color_matrix
);
769 else if (colormatrices
->flags
== ColorMatrixFlagsAltGray
)
771 *src_color
= transform_color(*src_color
, gray_matrix
);
778 if (attributes
->gamma_enabled
[type
] ||
779 attributes
->gamma_enabled
[ColorAdjustTypeDefault
])
783 if (!data
|| fmt
!= PixelFormat32bppARGB
)
784 return PixelFormat32bppARGB
;
786 if (attributes
->gamma_enabled
[type
])
787 gamma
= attributes
->gamma
[type
];
789 gamma
= attributes
->gamma
[ColorAdjustTypeDefault
];
791 for (x
=0; x
<width
; x
++)
792 for (y
=0; y
<height
; y
++)
795 BYTE blue
, green
, red
;
796 src_color
= (ARGB
*)(data
+ stride
* y
+ sizeof(ARGB
) * x
);
798 blue
= *src_color
&0xff;
799 green
= (*src_color
>>8)&0xff;
800 red
= (*src_color
>>16)&0xff;
802 /* FIXME: We should probably use a table for this. */
803 blue
= floorf(powf(blue
/ 255.0, gamma
) * 255.0);
804 green
= floorf(powf(green
/ 255.0, gamma
) * 255.0);
805 red
= floorf(powf(red
/ 255.0, gamma
) * 255.0);
807 *src_color
= (*src_color
& 0xff000000) | (red
<< 16) | (green
<< 8) | blue
;
814 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
815 * bitmap that contains all the pixels we may need to draw it. */
816 static void get_bitmap_sample_size(InterpolationMode interpolation
, WrapMode wrap
,
817 GpBitmap
* bitmap
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
820 INT left
, top
, right
, bottom
;
822 switch (interpolation
)
824 case InterpolationModeHighQualityBilinear
:
825 case InterpolationModeHighQualityBicubic
:
826 /* FIXME: Include a greater range for the prefilter? */
827 case InterpolationModeBicubic
:
828 case InterpolationModeBilinear
:
829 left
= (INT
)(floorf(srcx
));
830 top
= (INT
)(floorf(srcy
));
831 right
= (INT
)(ceilf(srcx
+srcwidth
));
832 bottom
= (INT
)(ceilf(srcy
+srcheight
));
834 case InterpolationModeNearestNeighbor
:
836 left
= gdip_round(srcx
);
837 top
= gdip_round(srcy
);
838 right
= gdip_round(srcx
+srcwidth
);
839 bottom
= gdip_round(srcy
+srcheight
);
843 if (wrap
== WrapModeClamp
)
849 if (right
>= bitmap
->width
)
850 right
= bitmap
->width
-1;
851 if (bottom
>= bitmap
->height
)
852 bottom
= bitmap
->height
-1;
853 if (bottom
< top
|| right
< left
)
854 /* entirely outside image, just sample a pixel so we don't have to
855 * special-case this later */
856 left
= top
= right
= bottom
= 0;
860 /* In some cases we can make the rectangle smaller here, but the logic
861 * is hard to get right, and tiling suggests we're likely to use the
862 * entire source image. */
863 if (left
< 0 || right
>= bitmap
->width
)
866 right
= bitmap
->width
-1;
869 if (top
< 0 || bottom
>= bitmap
->height
)
872 bottom
= bitmap
->height
-1;
878 rect
->Width
= right
- left
+ 1;
879 rect
->Height
= bottom
- top
+ 1;
882 static ARGB
sample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
883 UINT height
, INT x
, INT y
, GDIPCONST GpImageAttributes
*attributes
)
885 if (attributes
->wrap
== WrapModeClamp
)
887 if (x
< 0 || y
< 0 || x
>= width
|| y
>= height
)
888 return attributes
->outside_color
;
892 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
894 x
= width
*2 + x
% (width
* 2);
896 y
= height
*2 + y
% (height
* 2);
898 if ((attributes
->wrap
& 1) == 1)
901 if ((x
/ width
) % 2 == 0)
904 x
= width
- 1 - x
% width
;
909 if ((attributes
->wrap
& 2) == 2)
912 if ((y
/ height
) % 2 == 0)
915 y
= height
- 1 - y
% height
;
921 if (x
< src_rect
->X
|| y
< src_rect
->Y
|| x
>= src_rect
->X
+ src_rect
->Width
|| y
>= src_rect
->Y
+ src_rect
->Height
)
923 ERR("out of range pixel requested\n");
927 return ((DWORD
*)(bits
))[(x
- src_rect
->X
) + (y
- src_rect
->Y
) * src_rect
->Width
];
930 static ARGB
resample_bitmap_pixel(GDIPCONST GpRect
*src_rect
, LPBYTE bits
, UINT width
,
931 UINT height
, GpPointF
*point
, GDIPCONST GpImageAttributes
*attributes
,
932 InterpolationMode interpolation
, PixelOffsetMode offset_mode
)
936 switch (interpolation
)
940 FIXME("Unimplemented interpolation %i\n", interpolation
);
942 case InterpolationModeBilinear
:
945 INT leftx
, rightx
, topy
, bottomy
;
946 ARGB topleft
, topright
, bottomleft
, bottomright
;
950 leftxf
= floorf(point
->X
);
952 rightx
= (INT
)ceilf(point
->X
);
953 topyf
= floorf(point
->Y
);
955 bottomy
= (INT
)ceilf(point
->Y
);
957 if (leftx
== rightx
&& topy
== bottomy
)
958 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
959 leftx
, topy
, attributes
);
961 topleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
962 leftx
, topy
, attributes
);
963 topright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
964 rightx
, topy
, attributes
);
965 bottomleft
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
966 leftx
, bottomy
, attributes
);
967 bottomright
= sample_bitmap_pixel(src_rect
, bits
, width
, height
,
968 rightx
, bottomy
, attributes
);
970 x_offset
= point
->X
- leftxf
;
971 top
= blend_colors(topleft
, topright
, x_offset
);
972 bottom
= blend_colors(bottomleft
, bottomright
, x_offset
);
974 return blend_colors(top
, bottom
, point
->Y
- topyf
);
976 case InterpolationModeNearestNeighbor
:
982 case PixelOffsetModeNone
:
983 case PixelOffsetModeHighSpeed
:
987 case PixelOffsetModeHalf
:
988 case PixelOffsetModeHighQuality
:
992 return sample_bitmap_pixel(src_rect
, bits
, width
, height
,
993 floorf(point
->X
+ pixel_offset
), floorf(point
->Y
+ pixel_offset
), attributes
);
999 static REAL
intersect_line_scanline(const GpPointF
*p1
, const GpPointF
*p2
, REAL y
)
1001 return (p1
->X
- p2
->X
) * (p2
->Y
- y
) / (p2
->Y
- p1
->Y
) + p2
->X
;
1004 static BOOL
brush_can_fill_path(GpBrush
*brush
)
1008 case BrushTypeSolidColor
:
1010 case BrushTypeHatchFill
:
1012 GpHatch
*hatch
= (GpHatch
*)brush
;
1013 return ((hatch
->forecol
& 0xff000000) == 0xff000000) &&
1014 ((hatch
->backcol
& 0xff000000) == 0xff000000);
1016 case BrushTypeLinearGradient
:
1017 case BrushTypeTextureFill
:
1018 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
1024 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
1028 case BrushTypeSolidColor
:
1030 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1031 HBITMAP bmp
= ARGB2BMP(fill
->color
);
1036 /* partially transparent fill */
1038 SelectClipPath(graphics
->hdc
, RGN_AND
);
1039 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
1041 HDC hdc
= CreateCompatibleDC(NULL
);
1045 SelectObject(hdc
, bmp
);
1046 gdi_alpha_blend(graphics
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1054 /* else fall through */
1058 HBRUSH gdibrush
, old_brush
;
1060 gdibrush
= create_gdi_brush(brush
);
1061 if (!gdibrush
) return;
1063 old_brush
= SelectObject(graphics
->hdc
, gdibrush
);
1064 FillPath(graphics
->hdc
);
1065 SelectObject(graphics
->hdc
, old_brush
);
1066 DeleteObject(gdibrush
);
1072 static BOOL
brush_can_fill_pixels(GpBrush
*brush
)
1076 case BrushTypeSolidColor
:
1077 case BrushTypeHatchFill
:
1078 case BrushTypeLinearGradient
:
1079 case BrushTypeTextureFill
:
1080 case BrushTypePathGradient
:
1087 static GpStatus
brush_fill_pixels(GpGraphics
*graphics
, GpBrush
*brush
,
1088 DWORD
*argb_pixels
, GpRect
*fill_area
, UINT cdwStride
)
1092 case BrushTypeSolidColor
:
1095 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
1096 for (x
=0; x
<fill_area
->Width
; x
++)
1097 for (y
=0; y
<fill_area
->Height
; y
++)
1098 argb_pixels
[x
+ y
*cdwStride
] = fill
->color
;
1101 case BrushTypeHatchFill
:
1104 GpHatch
*fill
= (GpHatch
*)brush
;
1105 const char *hatch_data
;
1107 if (get_hatch_data(fill
->hatchstyle
, &hatch_data
) != Ok
)
1108 return NotImplemented
;
1110 for (x
=0; x
<fill_area
->Width
; x
++)
1111 for (y
=0; y
<fill_area
->Height
; y
++)
1115 /* FIXME: Account for the rendering origin */
1116 hx
= (x
+ fill_area
->X
) % 8;
1117 hy
= (y
+ fill_area
->Y
) % 8;
1119 if ((hatch_data
[7-hy
] & (0x80 >> hx
)) != 0)
1120 argb_pixels
[x
+ y
*cdwStride
] = fill
->forecol
;
1122 argb_pixels
[x
+ y
*cdwStride
] = fill
->backcol
;
1127 case BrushTypeLinearGradient
:
1129 GpLineGradient
*fill
= (GpLineGradient
*)brush
;
1130 GpPointF draw_points
[3], line_points
[3];
1132 static const GpRectF box_1
= { 0.0, 0.0, 1.0, 1.0 };
1133 GpMatrix
*world_to_gradient
; /* FIXME: Store this in the brush? */
1136 draw_points
[0].X
= fill_area
->X
;
1137 draw_points
[0].Y
= fill_area
->Y
;
1138 draw_points
[1].X
= fill_area
->X
+1;
1139 draw_points
[1].Y
= fill_area
->Y
;
1140 draw_points
[2].X
= fill_area
->X
;
1141 draw_points
[2].Y
= fill_area
->Y
+1;
1143 /* Transform the points to a co-ordinate space where X is the point's
1144 * position in the gradient, 0.0 being the start point and 1.0 the
1146 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1147 CoordinateSpaceDevice
, draw_points
, 3);
1151 line_points
[0] = fill
->startpoint
;
1152 line_points
[1] = fill
->endpoint
;
1153 line_points
[2].X
= fill
->startpoint
.X
+ (fill
->startpoint
.Y
- fill
->endpoint
.Y
);
1154 line_points
[2].Y
= fill
->startpoint
.Y
+ (fill
->endpoint
.X
- fill
->startpoint
.X
);
1156 stat
= GdipCreateMatrix3(&box_1
, line_points
, &world_to_gradient
);
1161 stat
= GdipInvertMatrix(world_to_gradient
);
1164 stat
= GdipTransformMatrixPoints(world_to_gradient
, draw_points
, 3);
1166 GdipDeleteMatrix(world_to_gradient
);
1171 REAL x_delta
= draw_points
[1].X
- draw_points
[0].X
;
1172 REAL y_delta
= draw_points
[2].X
- draw_points
[0].X
;
1174 for (y
=0; y
<fill_area
->Height
; y
++)
1176 for (x
=0; x
<fill_area
->Width
; x
++)
1178 REAL pos
= draw_points
[0].X
+ x
* x_delta
+ y
* y_delta
;
1180 argb_pixels
[x
+ y
*cdwStride
] = blend_line_gradient(fill
, pos
);
1187 case BrushTypeTextureFill
:
1189 GpTexture
*fill
= (GpTexture
*)brush
;
1190 GpPointF draw_points
[3];
1197 if (fill
->image
->type
!= ImageTypeBitmap
)
1199 FIXME("metafile texture brushes not implemented\n");
1200 return NotImplemented
;
1203 bitmap
= (GpBitmap
*)fill
->image
;
1204 src_stride
= sizeof(ARGB
) * bitmap
->width
;
1206 src_area
.X
= src_area
.Y
= 0;
1207 src_area
.Width
= bitmap
->width
;
1208 src_area
.Height
= bitmap
->height
;
1210 draw_points
[0].X
= fill_area
->X
;
1211 draw_points
[0].Y
= fill_area
->Y
;
1212 draw_points
[1].X
= fill_area
->X
+1;
1213 draw_points
[1].Y
= fill_area
->Y
;
1214 draw_points
[2].X
= fill_area
->X
;
1215 draw_points
[2].Y
= fill_area
->Y
+1;
1217 /* Transform the points to the co-ordinate space of the bitmap. */
1218 stat
= GdipTransformPoints(graphics
, CoordinateSpaceWorld
,
1219 CoordinateSpaceDevice
, draw_points
, 3);
1223 GpMatrix world_to_texture
= fill
->transform
;
1225 stat
= GdipInvertMatrix(&world_to_texture
);
1227 stat
= GdipTransformMatrixPoints(&world_to_texture
, draw_points
, 3);
1230 if (stat
== Ok
&& !fill
->bitmap_bits
)
1232 BitmapData lockeddata
;
1234 fill
->bitmap_bits
= heap_alloc_zero(sizeof(ARGB
) * bitmap
->width
* bitmap
->height
);
1235 if (!fill
->bitmap_bits
)
1240 lockeddata
.Width
= bitmap
->width
;
1241 lockeddata
.Height
= bitmap
->height
;
1242 lockeddata
.Stride
= src_stride
;
1243 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
1244 lockeddata
.Scan0
= fill
->bitmap_bits
;
1246 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1247 PixelFormat32bppARGB
, &lockeddata
);
1251 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1254 apply_image_attributes(fill
->imageattributes
, fill
->bitmap_bits
,
1255 bitmap
->width
, bitmap
->height
,
1256 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
1260 heap_free(fill
->bitmap_bits
);
1261 fill
->bitmap_bits
= NULL
;
1267 REAL x_dx
= draw_points
[1].X
- draw_points
[0].X
;
1268 REAL x_dy
= draw_points
[1].Y
- draw_points
[0].Y
;
1269 REAL y_dx
= draw_points
[2].X
- draw_points
[0].X
;
1270 REAL y_dy
= draw_points
[2].Y
- draw_points
[0].Y
;
1272 for (y
=0; y
<fill_area
->Height
; y
++)
1274 for (x
=0; x
<fill_area
->Width
; x
++)
1277 point
.X
= draw_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
1278 point
.Y
= draw_points
[0].Y
+ y
* x_dy
+ y
* y_dy
;
1280 argb_pixels
[x
+ y
*cdwStride
] = resample_bitmap_pixel(
1281 &src_area
, fill
->bitmap_bits
, bitmap
->width
, bitmap
->height
,
1282 &point
, fill
->imageattributes
, graphics
->interpolation
,
1283 graphics
->pixeloffset
);
1290 case BrushTypePathGradient
:
1292 GpPathGradient
*fill
= (GpPathGradient
*)brush
;
1294 GpMatrix world_to_device
;
1296 int i
, figure_start
=0;
1297 GpPointF start_point
, end_point
, center_point
;
1299 REAL min_yf
, max_yf
, line1_xf
, line2_xf
;
1300 INT min_y
, max_y
, min_x
, max_x
;
1303 static BOOL transform_fixme_once
;
1305 if (fill
->focus
.X
!= 0.0 || fill
->focus
.Y
!= 0.0)
1309 FIXME("path gradient focus not implemented\n");
1316 FIXME("path gradient gamma correction not implemented\n");
1319 if (fill
->blendcount
)
1323 FIXME("path gradient blend not implemented\n");
1326 if (fill
->pblendcount
)
1330 FIXME("path gradient preset blend not implemented\n");
1333 if (!transform_fixme_once
)
1335 BOOL is_identity
=TRUE
;
1336 GdipIsMatrixIdentity(&fill
->transform
, &is_identity
);
1339 FIXME("path gradient transform not implemented\n");
1340 transform_fixme_once
= TRUE
;
1344 stat
= GdipClonePath(fill
->path
, &flat_path
);
1349 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1350 CoordinateSpaceWorld
, &world_to_device
);
1353 stat
= GdipTransformPath(flat_path
, &world_to_device
);
1357 center_point
= fill
->center
;
1358 stat
= GdipTransformMatrixPoints(&world_to_device
, ¢er_point
, 1);
1362 stat
= GdipFlattenPath(flat_path
, NULL
, 0.5);
1367 GdipDeletePath(flat_path
);
1371 for (i
=0; i
<flat_path
->pathdata
.Count
; i
++)
1373 int start_center_line
=0, end_center_line
=0;
1374 BOOL seen_start
= FALSE
, seen_end
= FALSE
, seen_center
= FALSE
;
1375 REAL center_distance
;
1376 ARGB start_color
, end_color
;
1379 type
= flat_path
->pathdata
.Types
[i
];
1381 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1384 start_point
= flat_path
->pathdata
.Points
[i
];
1386 start_color
= fill
->surroundcolors
[min(i
, fill
->surroundcolorcount
-1)];
1388 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
|| i
+1 >= flat_path
->pathdata
.Count
)
1390 end_point
= flat_path
->pathdata
.Points
[figure_start
];
1391 end_color
= fill
->surroundcolors
[min(figure_start
, fill
->surroundcolorcount
-1)];
1393 else if ((flat_path
->pathdata
.Types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeLine
)
1395 end_point
= flat_path
->pathdata
.Points
[i
+1];
1396 end_color
= fill
->surroundcolors
[min(i
+1, fill
->surroundcolorcount
-1)];
1401 outer_color
= start_color
;
1403 min_yf
= center_point
.Y
;
1404 if (min_yf
> start_point
.Y
) min_yf
= start_point
.Y
;
1405 if (min_yf
> end_point
.Y
) min_yf
= end_point
.Y
;
1407 if (min_yf
< fill_area
->Y
)
1408 min_y
= fill_area
->Y
;
1410 min_y
= (INT
)ceil(min_yf
);
1412 max_yf
= center_point
.Y
;
1413 if (max_yf
< start_point
.Y
) max_yf
= start_point
.Y
;
1414 if (max_yf
< end_point
.Y
) max_yf
= end_point
.Y
;
1416 if (max_yf
> fill_area
->Y
+ fill_area
->Height
)
1417 max_y
= fill_area
->Y
+ fill_area
->Height
;
1419 max_y
= (INT
)ceil(max_yf
);
1421 dy
= end_point
.Y
- start_point
.Y
;
1422 dx
= end_point
.X
- start_point
.X
;
1424 /* This is proportional to the distance from start-end line to center point. */
1425 center_distance
= dy
* (start_point
.X
- center_point
.X
) +
1426 dx
* (center_point
.Y
- start_point
.Y
);
1428 for (y
=min_y
; y
<max_y
; y
++)
1432 if (!seen_start
&& yf
>= start_point
.Y
)
1435 start_center_line
^= 1;
1437 if (!seen_end
&& yf
>= end_point
.Y
)
1440 end_center_line
^= 1;
1442 if (!seen_center
&& yf
>= center_point
.Y
)
1445 start_center_line
^= 1;
1446 end_center_line
^= 1;
1449 if (start_center_line
)
1450 line1_xf
= intersect_line_scanline(&start_point
, ¢er_point
, yf
);
1452 line1_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1454 if (end_center_line
)
1455 line2_xf
= intersect_line_scanline(&end_point
, ¢er_point
, yf
);
1457 line2_xf
= intersect_line_scanline(&start_point
, &end_point
, yf
);
1459 if (line1_xf
< line2_xf
)
1461 min_x
= (INT
)ceil(line1_xf
);
1462 max_x
= (INT
)ceil(line2_xf
);
1466 min_x
= (INT
)ceil(line2_xf
);
1467 max_x
= (INT
)ceil(line1_xf
);
1470 if (min_x
< fill_area
->X
)
1471 min_x
= fill_area
->X
;
1472 if (max_x
> fill_area
->X
+ fill_area
->Width
)
1473 max_x
= fill_area
->X
+ fill_area
->Width
;
1475 for (x
=min_x
; x
<max_x
; x
++)
1480 if (start_color
!= end_color
)
1482 REAL blend_amount
, pdy
, pdx
;
1483 pdy
= yf
- center_point
.Y
;
1484 pdx
= xf
- center_point
.X
;
1485 blend_amount
= ( (center_point
.Y
- start_point
.Y
) * pdx
+ (start_point
.X
- center_point
.X
) * pdy
) / ( dy
* pdx
- dx
* pdy
);
1486 outer_color
= blend_colors(start_color
, end_color
, blend_amount
);
1489 distance
= (end_point
.Y
- start_point
.Y
) * (start_point
.X
- xf
) +
1490 (end_point
.X
- start_point
.X
) * (yf
- start_point
.Y
);
1492 distance
= distance
/ center_distance
;
1494 argb_pixels
[(x
-fill_area
->X
) + (y
-fill_area
->Y
)*cdwStride
] =
1495 blend_colors(outer_color
, fill
->centercolor
, distance
);
1500 GdipDeletePath(flat_path
);
1504 return NotImplemented
;
1508 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1509 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1510 * should not be called on an hdc that has a path you care about. */
1511 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
1512 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
1514 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
1516 HBRUSH brush
= NULL
;
1518 PointF ptf
[4], *custptf
= NULL
;
1519 POINT pt
[4], *custpt
= NULL
;
1521 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
1526 if((x1
== x2
) && (y1
== y2
))
1529 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
1531 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
1533 brush
= CreateSolidBrush(color
);
1534 lb
.lbStyle
= BS_SOLID
;
1537 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
1538 PS_JOIN_MITER
, 1, &lb
, 0,
1540 oldbrush
= SelectObject(graphics
->hdc
, brush
);
1541 oldpen
= SelectObject(graphics
->hdc
, pen
);
1548 case LineCapSquareAnchor
:
1549 case LineCapDiamondAnchor
:
1550 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
1551 if(cap
== LineCapDiamondAnchor
){
1552 dsmall
= cos(theta
+ M_PI_2
) * size
;
1553 dbig
= sin(theta
+ M_PI_2
) * size
;
1556 dsmall
= cos(theta
+ M_PI_4
) * size
;
1557 dbig
= sin(theta
+ M_PI_4
) * size
;
1560 ptf
[0].X
= x2
- dsmall
;
1561 ptf
[1].X
= x2
+ dbig
;
1563 ptf
[0].Y
= y2
- dbig
;
1564 ptf
[3].Y
= y2
+ dsmall
;
1566 ptf
[1].Y
= y2
- dsmall
;
1567 ptf
[2].Y
= y2
+ dbig
;
1569 ptf
[3].X
= x2
- dbig
;
1570 ptf
[2].X
= x2
+ dsmall
;
1572 transform_and_round_points(graphics
, pt
, ptf
, 4);
1573 Polygon(graphics
->hdc
, pt
, 4);
1576 case LineCapArrowAnchor
:
1577 size
= size
* 4.0 / sqrt(3.0);
1579 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
1580 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
1585 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
1586 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
1594 transform_and_round_points(graphics
, pt
, ptf
, 3);
1595 Polygon(graphics
->hdc
, pt
, 3);
1598 case LineCapRoundAnchor
:
1599 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
1606 transform_and_round_points(graphics
, pt
, ptf
, 2);
1607 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
1610 case LineCapTriangle
:
1612 dx
= cos(M_PI_2
+ theta
) * size
;
1613 dy
= sin(M_PI_2
+ theta
) * size
;
1620 dx
= cos(theta
) * size
;
1621 dy
= sin(theta
) * size
;
1626 transform_and_round_points(graphics
, pt
, ptf
, 3);
1627 Polygon(graphics
->hdc
, pt
, 3);
1631 dx
= dy
= size
/ 2.0;
1638 dx
= -cos(M_PI_2
+ theta
) * size
;
1639 dy
= -sin(M_PI_2
+ theta
) * size
;
1646 transform_and_round_points(graphics
, pt
, ptf
, 4);
1647 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
1648 pt
[2].y
, pt
[3].x
, pt
[3].y
);
1655 count
= custom
->pathdata
.Count
;
1656 custptf
= heap_alloc_zero(count
* sizeof(PointF
));
1657 custpt
= heap_alloc_zero(count
* sizeof(POINT
));
1658 tp
= heap_alloc_zero(count
);
1660 if(!custptf
|| !custpt
|| !tp
)
1663 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
1665 GdipSetMatrixElements(&matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1666 GdipScaleMatrix(&matrix
, size
, size
, MatrixOrderAppend
);
1667 GdipRotateMatrix(&matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
1669 GdipTranslateMatrix(&matrix
, x2
, y2
, MatrixOrderAppend
);
1670 GdipTransformMatrixPoints(&matrix
, custptf
, count
);
1672 transform_and_round_points(graphics
, custpt
, custptf
, count
);
1674 for(i
= 0; i
< count
; i
++)
1675 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
1678 BeginPath(graphics
->hdc
);
1679 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1680 EndPath(graphics
->hdc
);
1681 StrokeAndFillPath(graphics
->hdc
);
1684 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
1696 SelectObject(graphics
->hdc
, oldbrush
);
1697 SelectObject(graphics
->hdc
, oldpen
);
1698 DeleteObject(brush
);
1703 /* Shortens the line by the given percent by changing x2, y2.
1704 * If percent is > 1.0 then the line will change direction.
1705 * If percent is negative it can lengthen the line. */
1706 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
1708 REAL dist
, theta
, dx
, dy
;
1710 if((y1
== *y2
) && (x1
== *x2
))
1713 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
1714 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
1715 dx
= cos(theta
) * dist
;
1716 dy
= sin(theta
) * dist
;
1722 /* Shortens the line by the given amount by changing x2, y2.
1723 * If the amount is greater than the distance, the line will become length 0.
1724 * If the amount is negative, it can lengthen the line. */
1725 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
1727 REAL dx
, dy
, percent
;
1731 if(dx
== 0 && dy
== 0)
1734 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
1741 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
1744 /* Conducts a linear search to find the bezier points that will back off
1745 * the endpoint of the curve by a distance of amt. Linear search works
1746 * better than binary in this case because there are multiple solutions,
1747 * and binary searches often find a bad one. I don't think this is what
1748 * Windows does but short of rendering the bezier without GDI's help it's
1749 * the best we can do. If rev then work from the start of the passed points
1750 * instead of the end. */
1751 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
1754 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
1755 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
1764 origx
= pt
[fourth
].X
;
1765 origy
= pt
[fourth
].Y
;
1766 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
1768 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
1769 /* reset bezier points to original values */
1770 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
1771 /* Perform magic on bezier points. Order is important here.*/
1772 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1773 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1774 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1775 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
1776 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
1777 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
1779 dx
= pt
[fourth
].X
- origx
;
1780 dy
= pt
[fourth
].Y
- origy
;
1782 diff
= sqrt(dx
* dx
+ dy
* dy
);
1783 percent
+= 0.0005 * amt
;
1787 /* Draws a combination of bezier curves and lines between points. */
1788 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
1789 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
1791 POINT
*pti
= heap_alloc_zero(count
* sizeof(POINT
));
1792 BYTE
*tp
= heap_alloc_zero(count
);
1793 GpPointF
*ptcopy
= heap_alloc_zero(count
* sizeof(GpPointF
));
1795 GpStatus status
= GenericError
;
1801 if(!pti
|| !tp
|| !ptcopy
){
1802 status
= OutOfMemory
;
1806 for(i
= 1; i
< count
; i
++){
1807 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
1808 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
1809 || !(types
[i
+ 2] & PathPointTypeBezier
)){
1810 ERR("Bad bezier points\n");
1817 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
1819 /* If we are drawing caps, go through the points and adjust them accordingly,
1820 * and draw the caps. */
1822 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
1823 case PathPointTypeBezier
:
1824 if(pen
->endcap
== LineCapArrowAnchor
)
1825 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
1826 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1827 shorten_bezier_amt(&ptcopy
[count
- 4],
1828 pen
->width
* pen
->customend
->inset
, FALSE
);
1830 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1831 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
1832 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
1833 pt
[count
- 1].X
, pt
[count
- 1].Y
);
1836 case PathPointTypeLine
:
1837 if(pen
->endcap
== LineCapArrowAnchor
)
1838 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1839 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1841 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
1842 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
1843 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
1844 pen
->customend
->inset
* pen
->width
);
1846 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->endcap
, pen
->width
, pen
->customend
,
1847 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
1852 ERR("Bad path last point\n");
1856 /* Find start of points */
1857 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
1858 == PathPointTypeStart
); j
++);
1860 switch(types
[j
] & PathPointTypePathTypeMask
){
1861 case PathPointTypeBezier
:
1862 if(pen
->startcap
== LineCapArrowAnchor
)
1863 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
1864 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1865 shorten_bezier_amt(&ptcopy
[j
- 1],
1866 pen
->width
* pen
->customstart
->inset
, TRUE
);
1868 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1869 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
1870 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
1871 pt
[j
- 1].X
, pt
[j
- 1].Y
);
1874 case PathPointTypeLine
:
1875 if(pen
->startcap
== LineCapArrowAnchor
)
1876 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1877 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1879 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1880 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1881 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1882 pen
->customstart
->inset
* pen
->width
);
1884 draw_cap(graphics
, get_gdi_brush_color(pen
->brush
), pen
->startcap
, pen
->width
, pen
->customstart
,
1885 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1890 ERR("Bad path points\n");
1895 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1897 for(i
= 0; i
< count
; i
++){
1898 tp
[i
] = convert_path_point_type(types
[i
]);
1901 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1913 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1917 BeginPath(graphics
->hdc
);
1918 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1919 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1920 EndPath(graphics
->hdc
);
1924 typedef enum GraphicsContainerType
{
1927 } GraphicsContainerType
;
1929 typedef struct _GraphicsContainerItem
{
1931 GraphicsContainer contid
;
1932 GraphicsContainerType type
;
1934 SmoothingMode smoothing
;
1935 CompositingQuality compqual
;
1936 InterpolationMode interpolation
;
1937 CompositingMode compmode
;
1938 TextRenderingHint texthint
;
1941 PixelOffsetMode pixeloffset
;
1943 GpMatrix worldtrans
;
1945 INT origin_x
, origin_y
;
1946 } GraphicsContainerItem
;
1948 static GpStatus
init_container(GraphicsContainerItem
** container
,
1949 GDIPCONST GpGraphics
* graphics
, GraphicsContainerType type
){
1952 *container
= heap_alloc_zero(sizeof(GraphicsContainerItem
));
1956 (*container
)->contid
= graphics
->contid
+ 1;
1957 (*container
)->type
= type
;
1959 (*container
)->smoothing
= graphics
->smoothing
;
1960 (*container
)->compqual
= graphics
->compqual
;
1961 (*container
)->interpolation
= graphics
->interpolation
;
1962 (*container
)->compmode
= graphics
->compmode
;
1963 (*container
)->texthint
= graphics
->texthint
;
1964 (*container
)->scale
= graphics
->scale
;
1965 (*container
)->unit
= graphics
->unit
;
1966 (*container
)->textcontrast
= graphics
->textcontrast
;
1967 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1968 (*container
)->origin_x
= graphics
->origin_x
;
1969 (*container
)->origin_y
= graphics
->origin_y
;
1970 (*container
)->worldtrans
= graphics
->worldtrans
;
1972 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1974 heap_free(*container
);
1982 static void delete_container(GraphicsContainerItem
* container
)
1984 GdipDeleteRegion(container
->clip
);
1985 heap_free(container
);
1988 static GpStatus
restore_container(GpGraphics
* graphics
,
1989 GDIPCONST GraphicsContainerItem
* container
){
1993 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1994 if(sts
!= Ok
) return sts
;
1996 graphics
->worldtrans
= container
->worldtrans
;
1998 GdipDeleteRegion(graphics
->clip
);
1999 graphics
->clip
= newClip
;
2001 graphics
->contid
= container
->contid
- 1;
2003 graphics
->smoothing
= container
->smoothing
;
2004 graphics
->compqual
= container
->compqual
;
2005 graphics
->interpolation
= container
->interpolation
;
2006 graphics
->compmode
= container
->compmode
;
2007 graphics
->texthint
= container
->texthint
;
2008 graphics
->scale
= container
->scale
;
2009 graphics
->unit
= container
->unit
;
2010 graphics
->textcontrast
= container
->textcontrast
;
2011 graphics
->pixeloffset
= container
->pixeloffset
;
2012 graphics
->origin_x
= container
->origin_x
;
2013 graphics
->origin_y
= container
->origin_y
;
2018 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
2024 if(graphics
->hwnd
) {
2025 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
2026 return GenericError
;
2028 rect
->X
= wnd_rect
.left
;
2029 rect
->Y
= wnd_rect
.top
;
2030 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
2031 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
2032 }else if (graphics
->image
){
2033 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
2034 if (stat
== Ok
&& unit
!= UnitPixel
)
2035 FIXME("need to convert from unit %i\n", unit
);
2036 }else if (GetObjectType(graphics
->hdc
) == OBJ_MEMDC
){
2043 hbmp
= GetCurrentObject(graphics
->hdc
, OBJ_BITMAP
);
2044 if (hbmp
&& GetObjectW(hbmp
, sizeof(bmp
), &bmp
))
2046 rect
->Width
= bmp
.bmWidth
;
2047 rect
->Height
= bmp
.bmHeight
;
2058 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
2059 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
2066 points
[0].x
= rect
->X
;
2067 points
[0].y
= rect
->Y
;
2068 points
[1].x
= rect
->X
+ rect
->Width
;
2069 points
[1].y
= rect
->Y
+ rect
->Height
;
2071 DPtoLP(graphics
->hdc
, points
, sizeof(points
)/sizeof(points
[0]));
2073 rect
->X
= min(points
[0].x
, points
[1].x
);
2074 rect
->Y
= min(points
[0].y
, points
[1].y
);
2075 rect
->Width
= abs(points
[1].x
- points
[0].x
);
2076 rect
->Height
= abs(points
[1].y
- points
[0].y
);
2082 /* on success, rgn will contain the region of the graphics object which
2083 * is visible after clipping has been applied */
2084 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
2090 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
2093 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
2096 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
2099 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
2102 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
2105 GdipDeleteRegion(tmp
);
2109 void get_log_fontW(const GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
2113 if (font
->unit
== UnitPixel
)
2115 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
2119 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
2120 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
2122 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
2125 lf
->lfHeight
= -(height
+ 0.5);
2127 lf
->lfEscapement
= 0;
2128 lf
->lfOrientation
= 0;
2129 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
2130 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
2131 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
2132 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
2133 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
2134 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2135 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2136 lf
->lfQuality
= DEFAULT_QUALITY
;
2137 lf
->lfPitchAndFamily
= 0;
2138 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
2141 static void get_font_hfont(GpGraphics
*graphics
, GDIPCONST GpFont
*font
,
2142 GDIPCONST GpStringFormat
*format
, HFONT
*hfont
,
2143 GDIPCONST GpMatrix
*matrix
)
2145 HDC hdc
= CreateCompatibleDC(0);
2147 REAL angle
, rel_width
, rel_height
, font_height
;
2149 HFONT unscaled_font
;
2150 TEXTMETRICW textmet
;
2152 if (font
->unit
== UnitPixel
|| font
->unit
== UnitWorld
)
2153 font_height
= font
->emSize
;
2156 REAL unit_scale
, res
;
2158 res
= (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
) ? graphics
->xres
: graphics
->yres
;
2159 unit_scale
= units_scale(font
->unit
, graphics
->unit
, res
);
2161 font_height
= font
->emSize
* unit_scale
;
2172 GpMatrix xform
= *matrix
;
2173 GdipTransformMatrixPoints(&xform
, pt
, 3);
2176 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
2177 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2178 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
2179 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
2180 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
2181 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
2183 get_log_fontW(font
, graphics
, &lfw
);
2184 lfw
.lfHeight
= -gdip_round(font_height
* rel_height
);
2185 unscaled_font
= CreateFontIndirectW(&lfw
);
2187 SelectObject(hdc
, unscaled_font
);
2188 GetTextMetricsW(hdc
, &textmet
);
2190 lfw
.lfWidth
= gdip_round(textmet
.tmAveCharWidth
* rel_width
/ rel_height
);
2191 lfw
.lfEscapement
= lfw
.lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
2193 *hfont
= CreateFontIndirectW(&lfw
);
2196 DeleteObject(unscaled_font
);
2199 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
2201 TRACE("(%p, %p)\n", hdc
, graphics
);
2203 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
2206 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
2212 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
2215 FIXME("Don't know how to handle parameter hDevice\n");
2220 if(graphics
== NULL
)
2221 return InvalidParameter
;
2223 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2224 if(!*graphics
) return OutOfMemory
;
2226 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2228 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2229 heap_free(*graphics
);
2233 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2234 if (hbitmap
&& GetObjectW(hbitmap
, sizeof(dib
), &dib
) == sizeof(dib
) &&
2235 dib
.dsBmih
.biBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_RGB
)
2237 (*graphics
)->alpha_hdc
= 1;
2240 (*graphics
)->hdc
= hdc
;
2241 (*graphics
)->hwnd
= WindowFromDC(hdc
);
2242 (*graphics
)->owndc
= FALSE
;
2243 (*graphics
)->smoothing
= SmoothingModeDefault
;
2244 (*graphics
)->compqual
= CompositingQualityDefault
;
2245 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2246 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2247 (*graphics
)->compmode
= CompositingModeSourceOver
;
2248 (*graphics
)->unit
= UnitDisplay
;
2249 (*graphics
)->scale
= 1.0;
2250 (*graphics
)->xres
= GetDeviceCaps(hdc
, LOGPIXELSX
);
2251 (*graphics
)->yres
= GetDeviceCaps(hdc
, LOGPIXELSY
);
2252 (*graphics
)->busy
= FALSE
;
2253 (*graphics
)->textcontrast
= 4;
2254 list_init(&(*graphics
)->containers
);
2255 (*graphics
)->contid
= 0;
2257 TRACE("<-- %p\n", *graphics
);
2262 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
2266 *graphics
= heap_alloc_zero(sizeof(GpGraphics
));
2267 if(!*graphics
) return OutOfMemory
;
2269 GdipSetMatrixElements(&(*graphics
)->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2271 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
2272 heap_free(*graphics
);
2276 (*graphics
)->hdc
= NULL
;
2277 (*graphics
)->hwnd
= NULL
;
2278 (*graphics
)->owndc
= FALSE
;
2279 (*graphics
)->image
= image
;
2280 /* We have to store the image type here because the image may be freed
2281 * before GdipDeleteGraphics is called, and metafiles need special treatment. */
2282 (*graphics
)->image_type
= image
->type
;
2283 (*graphics
)->smoothing
= SmoothingModeDefault
;
2284 (*graphics
)->compqual
= CompositingQualityDefault
;
2285 (*graphics
)->interpolation
= InterpolationModeBilinear
;
2286 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
2287 (*graphics
)->compmode
= CompositingModeSourceOver
;
2288 (*graphics
)->unit
= UnitDisplay
;
2289 (*graphics
)->scale
= 1.0;
2290 (*graphics
)->xres
= image
->xres
;
2291 (*graphics
)->yres
= image
->yres
;
2292 (*graphics
)->busy
= FALSE
;
2293 (*graphics
)->textcontrast
= 4;
2294 list_init(&(*graphics
)->containers
);
2295 (*graphics
)->contid
= 0;
2297 TRACE("<-- %p\n", *graphics
);
2302 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
2307 TRACE("(%p, %p)\n", hwnd
, graphics
);
2311 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
2313 ReleaseDC(hwnd
, hdc
);
2317 (*graphics
)->hwnd
= hwnd
;
2318 (*graphics
)->owndc
= TRUE
;
2323 /* FIXME: no icm handling */
2324 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
2326 TRACE("(%p, %p)\n", hwnd
, graphics
);
2328 return GdipCreateFromHWND(hwnd
, graphics
);
2331 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
2332 UINT access
, IStream
**stream
)
2337 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
2339 if(!stream
|| !filename
)
2340 return InvalidParameter
;
2342 if(access
& GENERIC_WRITE
)
2343 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
2344 else if(access
& GENERIC_READ
)
2345 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
2347 return InvalidParameter
;
2349 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
2351 return hresult_to_status(ret
);
2354 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
2356 GraphicsContainerItem
*cont
, *next
;
2358 TRACE("(%p)\n", graphics
);
2360 if(!graphics
) return InvalidParameter
;
2361 if(graphics
->busy
) return ObjectBusy
;
2363 if (graphics
->image
&& graphics
->image_type
== ImageTypeMetafile
)
2365 stat
= METAFILE_GraphicsDeleted((GpMetafile
*)graphics
->image
);
2371 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
2373 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
2374 list_remove(&cont
->entry
);
2375 delete_container(cont
);
2378 GdipDeleteRegion(graphics
->clip
);
2380 /* Native returns ObjectBusy on the second free, instead of crashing as we'd
2381 * do otherwise, but we can't have that in the test suite because it means
2382 * accessing freed memory. */
2383 graphics
->busy
= TRUE
;
2385 heap_free(graphics
);
2390 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2391 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2396 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2397 width
, height
, startAngle
, sweepAngle
);
2399 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
2400 return InvalidParameter
;
2405 status
= GdipCreatePath(FillModeAlternate
, &path
);
2406 if (status
!= Ok
) return status
;
2408 status
= GdipAddPathArc(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2410 status
= GdipDrawPath(graphics
, pen
, path
);
2412 GdipDeletePath(path
);
2416 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2417 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2419 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2420 width
, height
, startAngle
, sweepAngle
);
2422 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2425 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2426 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
2430 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
2431 x2
, y2
, x3
, y3
, x4
, y4
);
2433 if(!graphics
|| !pen
)
2434 return InvalidParameter
;
2447 return GdipDrawBeziers(graphics
, pen
, pt
, 4);
2450 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2451 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
2453 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
2454 x2
, y2
, x3
, y3
, x4
, y4
);
2456 return GdipDrawBezier(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
, (REAL
)x3
, (REAL
)y3
, (REAL
)x4
, (REAL
)y4
);
2459 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
2460 GDIPCONST GpPointF
*points
, INT count
)
2465 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2467 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2468 return InvalidParameter
;
2473 status
= GdipCreatePath(FillModeAlternate
, &path
);
2474 if (status
!= Ok
) return status
;
2476 status
= GdipAddPathBeziers(path
, points
, count
);
2478 status
= GdipDrawPath(graphics
, pen
, path
);
2480 GdipDeletePath(path
);
2484 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
2485 GDIPCONST GpPoint
*points
, INT count
)
2491 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2493 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
2494 return InvalidParameter
;
2499 pts
= heap_alloc_zero(sizeof(GpPointF
) * count
);
2503 for(i
= 0; i
< count
; i
++){
2504 pts
[i
].X
= (REAL
)points
[i
].X
;
2505 pts
[i
].Y
= (REAL
)points
[i
].Y
;
2508 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
2515 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
2516 GDIPCONST GpPointF
*points
, INT count
)
2518 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2520 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
2523 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2524 GDIPCONST GpPoint
*points
, INT count
)
2526 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2528 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
2531 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2532 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2537 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2539 if(!graphics
|| !pen
|| !points
|| count
<= 0)
2540 return InvalidParameter
;
2545 status
= GdipCreatePath(FillModeAlternate
, &path
);
2546 if (status
!= Ok
) return status
;
2548 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2550 status
= GdipDrawPath(graphics
, pen
, path
);
2552 GdipDeletePath(path
);
2557 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2558 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2564 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2566 if(!points
|| count
<= 0)
2567 return InvalidParameter
;
2569 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2573 for(i
= 0; i
< count
; i
++){
2574 ptf
[i
].X
= (REAL
)points
[i
].X
;
2575 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2578 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
2585 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
2586 GDIPCONST GpPointF
*points
, INT count
)
2588 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2590 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
2593 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
2594 GDIPCONST GpPoint
*points
, INT count
)
2600 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2603 return InvalidParameter
;
2605 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2609 for(i
= 0; i
< count
; i
++){
2610 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2611 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2614 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
2620 /* Approximates cardinal spline with Bezier curves. */
2621 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
2622 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
2627 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2629 if(!graphics
|| !pen
)
2630 return InvalidParameter
;
2636 return InvalidParameter
;
2638 status
= GdipCreatePath(FillModeAlternate
, &path
);
2639 if (status
!= Ok
) return status
;
2641 status
= GdipAddPathCurve2(path
, points
, count
, tension
);
2643 status
= GdipDrawPath(graphics
, pen
, path
);
2645 GdipDeletePath(path
);
2649 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
2650 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
2656 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
2659 return InvalidParameter
;
2661 pointsF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
2665 for(i
= 0; i
< count
; i
++){
2666 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2667 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2670 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
2676 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
2677 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
2680 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2682 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2683 return InvalidParameter
;
2686 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2689 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
2690 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
2693 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
2699 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
2700 return InvalidParameter
;
2703 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
2706 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2707 REAL y
, REAL width
, REAL height
)
2712 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2714 if(!graphics
|| !pen
)
2715 return InvalidParameter
;
2720 status
= GdipCreatePath(FillModeAlternate
, &path
);
2721 if (status
!= Ok
) return status
;
2723 status
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
2725 status
= GdipDrawPath(graphics
, pen
, path
);
2727 GdipDeletePath(path
);
2731 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2732 INT y
, INT width
, INT height
)
2734 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2736 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2740 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
2744 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
2746 if(!graphics
|| !image
)
2747 return InvalidParameter
;
2749 GdipGetImageWidth(image
, &width
);
2750 GdipGetImageHeight(image
, &height
);
2752 return GdipDrawImagePointRect(graphics
, image
, x
, y
,
2753 0.0, 0.0, (REAL
)width
, (REAL
)height
, UnitPixel
);
2756 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
2759 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
2761 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
2764 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
2765 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
2769 REAL scale_x
, scale_y
, width
, height
;
2771 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2773 if (!graphics
|| !image
) return InvalidParameter
;
2775 scale_x
= units_scale(srcUnit
, graphics
->unit
, graphics
->xres
);
2776 scale_x
*= graphics
->xres
/ image
->xres
;
2777 scale_y
= units_scale(srcUnit
, graphics
->unit
, graphics
->yres
);
2778 scale_y
*= graphics
->yres
/ image
->yres
;
2779 width
= srcwidth
* scale_x
;
2780 height
= srcheight
* scale_y
;
2782 points
[0].X
= points
[2].X
= x
;
2783 points
[0].Y
= points
[1].Y
= y
;
2784 points
[1].X
= x
+ width
;
2785 points
[2].Y
= y
+ height
;
2787 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2788 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
2791 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2792 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2795 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2798 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2799 GDIPCONST GpPointF
*dstpoints
, INT count
)
2803 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2806 return InvalidParameter
;
2808 GdipGetImageWidth(image
, &width
);
2809 GdipGetImageHeight(image
, &height
);
2811 return GdipDrawImagePointsRect(graphics
, image
, dstpoints
, count
, 0, 0,
2812 width
, height
, UnitPixel
, NULL
, NULL
, NULL
);
2815 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2816 GDIPCONST GpPoint
*dstpoints
, INT count
)
2820 TRACE("(%p, %p, %p, %d)\n", graphics
, image
, dstpoints
, count
);
2822 if (count
!= 3 || !dstpoints
)
2823 return InvalidParameter
;
2825 ptf
[0].X
= (REAL
)dstpoints
[0].X
;
2826 ptf
[0].Y
= (REAL
)dstpoints
[0].Y
;
2827 ptf
[1].X
= (REAL
)dstpoints
[1].X
;
2828 ptf
[1].Y
= (REAL
)dstpoints
[1].Y
;
2829 ptf
[2].X
= (REAL
)dstpoints
[2].X
;
2830 ptf
[2].Y
= (REAL
)dstpoints
[2].Y
;
2832 return GdipDrawImagePoints(graphics
, image
, ptf
, count
);
2835 static BOOL CALLBACK
play_metafile_proc(EmfPlusRecordType record_type
, unsigned int flags
,
2836 unsigned int dataSize
, const unsigned char *pStr
, void *userdata
)
2838 GdipPlayMetafileRecord(userdata
, record_type
, flags
, dataSize
, pStr
);
2842 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2843 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2844 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2845 DrawImageAbort callback
, VOID
* callbackData
)
2851 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2852 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2856 return NotImplemented
;
2858 if(!graphics
|| !image
|| !points
|| count
!= 3)
2859 return InvalidParameter
;
2861 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2862 debugstr_pointf(&points
[2]));
2864 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2866 /* Ensure source width/height is positive */
2869 GpPointF tmp
= ptf
[1];
2870 srcx
= srcx
+ srcwidth
;
2871 srcwidth
= -srcwidth
;
2872 ptf
[2].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2873 ptf
[2].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2880 GpPointF tmp
= ptf
[2];
2881 srcy
= srcy
+ srcheight
;
2882 srcheight
= -srcheight
;
2883 ptf
[1].X
= ptf
[1].X
+ ptf
[2].X
- ptf
[0].X
;
2884 ptf
[1].Y
= ptf
[1].Y
+ ptf
[2].Y
- ptf
[0].Y
;
2889 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2890 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2891 if (!srcwidth
|| !srcheight
|| (ptf
[3].X
== ptf
[0].X
&& ptf
[3].Y
== ptf
[0].Y
))
2893 transform_and_round_points(graphics
, pti
, ptf
, 4);
2895 TRACE("%s %s %s %s\n", wine_dbgstr_point(&pti
[0]), wine_dbgstr_point(&pti
[1]),
2896 wine_dbgstr_point(&pti
[2]), wine_dbgstr_point(&pti
[3]));
2898 srcx
= units_to_pixels(srcx
, srcUnit
, image
->xres
);
2899 srcy
= units_to_pixels(srcy
, srcUnit
, image
->yres
);
2900 srcwidth
= units_to_pixels(srcwidth
, srcUnit
, image
->xres
);
2901 srcheight
= units_to_pixels(srcheight
, srcUnit
, image
->yres
);
2902 TRACE("src pixels: %f,%f %fx%f\n", srcx
, srcy
, srcwidth
, srcheight
);
2904 if (image
->type
== ImageTypeBitmap
)
2906 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2907 BOOL do_resampling
= FALSE
;
2908 BOOL use_software
= FALSE
;
2910 TRACE("graphics: %.2fx%.2f dpi, fmt %#x, scale %f, image: %.2fx%.2f dpi, fmt %#x, color %08x\n",
2911 graphics
->xres
, graphics
->yres
,
2912 graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
? ((GpBitmap
*)graphics
->image
)->format
: 0,
2913 graphics
->scale
, image
->xres
, image
->yres
, bitmap
->format
,
2914 imageAttributes
? imageAttributes
->outside_color
: 0);
2916 if (ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
||
2917 ptf
[1].X
- ptf
[0].X
!= srcwidth
|| ptf
[2].Y
- ptf
[0].Y
!= srcheight
||
2918 srcx
< 0 || srcy
< 0 ||
2919 srcx
+ srcwidth
> bitmap
->width
|| srcy
+ srcheight
> bitmap
->height
)
2920 do_resampling
= TRUE
;
2922 if (imageAttributes
|| graphics
->alpha_hdc
|| do_resampling
||
2923 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
))
2924 use_software
= TRUE
;
2929 GpRectF graphics_bounds
;
2931 int i
, x
, y
, src_stride
, dst_stride
;
2932 GpMatrix dst_to_src
;
2933 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2934 LPBYTE src_data
, dst_data
, dst_dyn_data
=NULL
;
2935 BitmapData lockeddata
;
2936 InterpolationMode interpolation
= graphics
->interpolation
;
2937 PixelOffsetMode offset_mode
= graphics
->pixeloffset
;
2938 GpPointF dst_to_src_points
[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2939 REAL x_dx
, x_dy
, y_dx
, y_dy
;
2940 static const GpImageAttributes defaultImageAttributes
= {WrapModeClamp
, 0, FALSE
};
2942 if (!imageAttributes
)
2943 imageAttributes
= &defaultImageAttributes
;
2945 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2946 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2949 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2950 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2951 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2952 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2955 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
2956 if (stat
!= Ok
) return stat
;
2958 if (graphics_bounds
.X
> dst_area
.left
) dst_area
.left
= floorf(graphics_bounds
.X
);
2959 if (graphics_bounds
.Y
> dst_area
.top
) dst_area
.top
= floorf(graphics_bounds
.Y
);
2960 if (graphics_bounds
.X
+ graphics_bounds
.Width
< dst_area
.right
) dst_area
.right
= ceilf(graphics_bounds
.X
+ graphics_bounds
.Width
);
2961 if (graphics_bounds
.Y
+ graphics_bounds
.Height
< dst_area
.bottom
) dst_area
.bottom
= ceilf(graphics_bounds
.Y
+ graphics_bounds
.Height
);
2963 TRACE("dst_area: %s\n", wine_dbgstr_rect(&dst_area
));
2965 if (IsRectEmpty(&dst_area
)) return Ok
;
2967 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2968 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2969 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2970 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2971 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2972 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2974 GdipSetMatrixElements(&dst_to_src
, m11
, m12
, m21
, m22
, mdx
, mdy
);
2976 stat
= GdipInvertMatrix(&dst_to_src
);
2977 if (stat
!= Ok
) return stat
;
2981 get_bitmap_sample_size(interpolation
, imageAttributes
->wrap
,
2982 bitmap
, srcx
, srcy
, srcwidth
, srcheight
, &src_area
);
2986 /* Make sure src_area is equal in size to dst_area. */
2987 src_area
.X
= srcx
+ dst_area
.left
- pti
[0].x
;
2988 src_area
.Y
= srcy
+ dst_area
.top
- pti
[0].y
;
2989 src_area
.Width
= dst_area
.right
- dst_area
.left
;
2990 src_area
.Height
= dst_area
.bottom
- dst_area
.top
;
2993 TRACE("src_area: %d x %d\n", src_area
.Width
, src_area
.Height
);
2995 src_data
= heap_alloc_zero(sizeof(ARGB
) * src_area
.Width
* src_area
.Height
);
2998 src_stride
= sizeof(ARGB
) * src_area
.Width
;
3000 /* Read the bits we need from the source bitmap into a compatible buffer. */
3001 lockeddata
.Width
= src_area
.Width
;
3002 lockeddata
.Height
= src_area
.Height
;
3003 lockeddata
.Stride
= src_stride
;
3004 lockeddata
.Scan0
= src_data
;
3005 if (!do_resampling
&& bitmap
->format
== PixelFormat32bppPARGB
)
3006 lockeddata
.PixelFormat
= apply_image_attributes(imageAttributes
, NULL
, 0, 0, 0, ColorAdjustTypeBitmap
, bitmap
->format
);
3008 lockeddata
.PixelFormat
= PixelFormat32bppARGB
;
3010 stat
= GdipBitmapLockBits(bitmap
, &src_area
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
3011 lockeddata
.PixelFormat
, &lockeddata
);
3014 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3018 heap_free(src_data
);
3022 apply_image_attributes(imageAttributes
, src_data
,
3023 src_area
.Width
, src_area
.Height
,
3024 src_stride
, ColorAdjustTypeBitmap
, lockeddata
.PixelFormat
);
3028 /* Transform the bits as needed to the destination. */
3029 dst_data
= dst_dyn_data
= heap_alloc_zero(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
3032 heap_free(src_data
);
3036 dst_stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
3038 GdipTransformMatrixPoints(&dst_to_src
, dst_to_src_points
, 3);
3040 x_dx
= dst_to_src_points
[1].X
- dst_to_src_points
[0].X
;
3041 x_dy
= dst_to_src_points
[1].Y
- dst_to_src_points
[0].Y
;
3042 y_dx
= dst_to_src_points
[2].X
- dst_to_src_points
[0].X
;
3043 y_dy
= dst_to_src_points
[2].Y
- dst_to_src_points
[0].Y
;
3045 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
3047 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
3049 GpPointF src_pointf
;
3052 src_pointf
.X
= dst_to_src_points
[0].X
+ x
* x_dx
+ y
* y_dx
;
3053 src_pointf
.Y
= dst_to_src_points
[0].Y
+ x
* x_dy
+ y
* y_dy
;
3055 dst_color
= (ARGB
*)(dst_data
+ dst_stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
3057 if (src_pointf
.X
>= srcx
&& src_pointf
.X
< srcx
+ srcwidth
&& src_pointf
.Y
>= srcy
&& src_pointf
.Y
< srcy
+srcheight
)
3058 *dst_color
= resample_bitmap_pixel(&src_area
, src_data
, bitmap
->width
, bitmap
->height
, &src_pointf
,
3059 imageAttributes
, interpolation
, offset_mode
);
3067 dst_data
= src_data
;
3068 dst_stride
= src_stride
;
3071 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
3072 dst_data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, dst_stride
,
3073 lockeddata
.PixelFormat
);
3075 heap_free(src_data
);
3077 heap_free(dst_dyn_data
);
3084 BOOL temp_hdc
= FALSE
, temp_bitmap
= FALSE
;
3085 HBITMAP hbitmap
, old_hbm
=NULL
;
3089 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
3090 bitmap
->format
== PixelFormat24bppRGB
||
3091 bitmap
->format
== PixelFormat32bppRGB
||
3092 bitmap
->format
== PixelFormat32bppPARGB
))
3094 BITMAPINFOHEADER bih
;
3096 PixelFormat dst_format
;
3098 /* we can't draw a bitmap of this format directly */
3099 hdc
= CreateCompatibleDC(0);
3103 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
3104 bih
.biWidth
= bitmap
->width
;
3105 bih
.biHeight
= -bitmap
->height
;
3107 bih
.biBitCount
= 32;
3108 bih
.biCompression
= BI_RGB
;
3109 bih
.biSizeImage
= 0;
3110 bih
.biXPelsPerMeter
= 0;
3111 bih
.biYPelsPerMeter
= 0;
3113 bih
.biClrImportant
= 0;
3115 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
3116 (void**)&temp_bits
, NULL
, 0);
3118 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3119 dst_format
= PixelFormat32bppPARGB
;
3121 dst_format
= PixelFormat32bppRGB
;
3123 convert_pixels(bitmap
->width
, bitmap
->height
,
3124 bitmap
->width
*4, temp_bits
, dst_format
,
3125 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
3126 bitmap
->image
.palette
);
3130 if (bitmap
->hbitmap
)
3131 hbitmap
= bitmap
->hbitmap
;
3134 GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3139 temp_hdc
= (hdc
== 0);
3144 if (!hdc
) hdc
= CreateCompatibleDC(0);
3145 old_hbm
= SelectObject(hdc
, hbitmap
);
3148 save_state
= SaveDC(graphics
->hdc
);
3150 stat
= get_clip_hrgn(graphics
, &hrgn
);
3152 if (stat
== Ok
&& hrgn
)
3154 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3158 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
3160 gdi_alpha_blend(graphics
, pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
3161 hdc
, srcx
, srcy
, srcwidth
, srcheight
);
3165 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
3166 hdc
, srcx
, srcy
, srcwidth
, srcheight
, SRCCOPY
);
3169 RestoreDC(graphics
->hdc
, save_state
);
3173 SelectObject(hdc
, old_hbm
);
3178 DeleteObject(hbitmap
);
3181 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
3187 rc
.Width
= srcwidth
;
3188 rc
.Height
= srcheight
;
3190 return GdipEnumerateMetafileSrcRectDestPoints(graphics
, (GpMetafile
*)image
,
3191 points
, count
, &rc
, srcUnit
, play_metafile_proc
, image
, imageAttributes
);
3195 WARN("GpImage with nothing we can draw (metafile in wrong state?)\n");
3196 return InvalidParameter
;
3202 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
3203 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
3204 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
3205 DrawImageAbort callback
, VOID
* callbackData
)
3207 GpPointF pointsF
[3];
3210 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
3211 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
3214 if(!points
|| count
!=3)
3215 return InvalidParameter
;
3217 for(i
= 0; i
< count
; i
++){
3218 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3219 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3222 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
3223 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
3224 callback
, callbackData
);
3227 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
3228 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
3229 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
3230 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
3231 VOID
* callbackData
)
3235 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3236 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3237 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3241 points
[1].X
= dstx
+ dstwidth
;
3244 points
[2].Y
= dsty
+ dstheight
;
3246 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3247 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
3250 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
3251 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
3252 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
3253 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
3254 VOID
* callbackData
)
3258 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3259 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
3260 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3264 points
[1].X
= dstx
+ dstwidth
;
3267 points
[2].Y
= dsty
+ dstheight
;
3269 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
3270 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
3273 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
3274 REAL x
, REAL y
, REAL width
, REAL height
)
3280 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
3282 if(!graphics
|| !image
)
3283 return InvalidParameter
;
3285 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
3289 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
3290 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
3291 unit
, NULL
, NULL
, NULL
);
3294 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
3295 INT x
, INT y
, INT width
, INT height
)
3297 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
3299 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
3302 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
3303 REAL y1
, REAL x2
, REAL y2
)
3307 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3310 return InvalidParameter
;
3312 if (pen
->unit
== UnitPixel
&& pen
->width
<= 0.0)
3319 return GdipDrawLines(graphics
, pen
, pt
, 2);
3322 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
3323 INT y1
, INT x2
, INT y2
)
3325 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
3327 return GdipDrawLine(graphics
, pen
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
3330 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3331 GpPointF
*points
, INT count
)
3336 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3338 if(!pen
|| !graphics
|| (count
< 2))
3339 return InvalidParameter
;
3344 status
= GdipCreatePath(FillModeAlternate
, &path
);
3345 if (status
!= Ok
) return status
;
3347 status
= GdipAddPathLine2(path
, points
, count
);
3349 status
= GdipDrawPath(graphics
, pen
, path
);
3351 GdipDeletePath(path
);
3355 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
3356 GpPoint
*points
, INT count
)
3362 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3364 ptf
= heap_alloc_zero(count
* sizeof(GpPointF
));
3365 if(!ptf
) return OutOfMemory
;
3367 for(i
= 0; i
< count
; i
++){
3368 ptf
[i
].X
= (REAL
) points
[i
].X
;
3369 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3372 retval
= GdipDrawLines(graphics
, pen
, ptf
, count
);
3378 static GpStatus
GDI32_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3384 save_state
= prepare_dc(graphics
, pen
);
3386 retval
= get_clip_hrgn(graphics
, &hrgn
);
3392 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3394 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
3395 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
3398 restore_dc(graphics
, save_state
);
3404 static GpStatus
SOFTWARE_GdipDrawThinPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3408 GpMatrix
* transform
;
3409 GpRectF gp_bound_rect
;
3410 GpRect gp_output_area
;
3412 INT output_height
, output_width
;
3413 DWORD
*output_bits
, *brush_bits
=NULL
;
3415 static const BYTE static_dash_pattern
[] = {1,1,1,0,1,0,1,0};
3416 const BYTE
*dash_pattern
;
3417 INT dash_pattern_size
;
3418 BYTE
*dyn_dash_pattern
= NULL
;
3420 stat
= GdipClonePath(path
, &flat_path
);
3425 stat
= GdipCreateMatrix(&transform
);
3429 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3430 CoordinateSpaceWorld
, transform
);
3433 stat
= GdipFlattenPath(flat_path
, transform
, 1.0);
3435 GdipDeleteMatrix(transform
);
3438 /* estimate the output size in pixels, can be larger than necessary */
3441 output_area
.left
= floorf(flat_path
->pathdata
.Points
[0].X
);
3442 output_area
.right
= ceilf(flat_path
->pathdata
.Points
[0].X
);
3443 output_area
.top
= floorf(flat_path
->pathdata
.Points
[0].Y
);
3444 output_area
.bottom
= ceilf(flat_path
->pathdata
.Points
[0].Y
);
3446 for (i
=1; i
<flat_path
->pathdata
.Count
; i
++)
3449 x
= flat_path
->pathdata
.Points
[i
].X
;
3450 y
= flat_path
->pathdata
.Points
[i
].Y
;
3452 if (floorf(x
) < output_area
.left
) output_area
.left
= floorf(x
);
3453 if (floorf(y
) < output_area
.top
) output_area
.top
= floorf(y
);
3454 if (ceilf(x
) > output_area
.right
) output_area
.right
= ceilf(x
);
3455 if (ceilf(y
) > output_area
.bottom
) output_area
.bottom
= ceilf(y
);
3458 stat
= get_graphics_bounds(graphics
, &gp_bound_rect
);
3463 output_area
.left
= max(output_area
.left
, floorf(gp_bound_rect
.X
));
3464 output_area
.top
= max(output_area
.top
, floorf(gp_bound_rect
.Y
));
3465 output_area
.right
= min(output_area
.right
, ceilf(gp_bound_rect
.X
+ gp_bound_rect
.Width
));
3466 output_area
.bottom
= min(output_area
.bottom
, ceilf(gp_bound_rect
.Y
+ gp_bound_rect
.Height
));
3468 output_width
= output_area
.right
- output_area
.left
+ 1;
3469 output_height
= output_area
.bottom
- output_area
.top
+ 1;
3471 if (output_width
<= 0 || output_height
<= 0)
3473 GdipDeletePath(flat_path
);
3477 gp_output_area
.X
= output_area
.left
;
3478 gp_output_area
.Y
= output_area
.top
;
3479 gp_output_area
.Width
= output_width
;
3480 gp_output_area
.Height
= output_height
;
3482 output_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3489 if (pen
->brush
->bt
!= BrushTypeSolidColor
)
3491 /* allocate and draw brush output */
3492 brush_bits
= heap_alloc_zero(output_width
* output_height
* sizeof(DWORD
));
3496 stat
= brush_fill_pixels(graphics
, pen
->brush
, brush_bits
,
3497 &gp_output_area
, output_width
);
3505 /* convert dash pattern to bool array */
3508 case DashStyleCustom
:
3510 dash_pattern_size
= 0;
3512 for (i
=0; i
< pen
->numdashes
; i
++)
3513 dash_pattern_size
+= gdip_round(pen
->dashes
[i
]);
3515 if (dash_pattern_size
!= 0)
3517 dash_pattern
= dyn_dash_pattern
= heap_alloc(dash_pattern_size
);
3519 if (dyn_dash_pattern
)
3522 for (i
=0; i
< pen
->numdashes
; i
++)
3525 for (k
=0; k
< gdip_round(pen
->dashes
[i
]); k
++)
3526 dyn_dash_pattern
[j
++] = (i
&1)^1;
3534 /* else fall through */
3536 case DashStyleSolid
:
3538 dash_pattern
= static_dash_pattern
;
3539 dash_pattern_size
= 1;
3542 dash_pattern
= static_dash_pattern
;
3543 dash_pattern_size
= 4;
3546 dash_pattern
= &static_dash_pattern
[4];
3547 dash_pattern_size
= 2;
3549 case DashStyleDashDot
:
3550 dash_pattern
= static_dash_pattern
;
3551 dash_pattern_size
= 6;
3553 case DashStyleDashDotDot
:
3554 dash_pattern
= static_dash_pattern
;
3555 dash_pattern_size
= 8;
3563 GpPointF subpath_start
= flat_path
->pathdata
.Points
[0];
3564 INT prev_x
= INT_MAX
, prev_y
= INT_MAX
;
3565 int dash_pos
= dash_pattern_size
- 1;
3567 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
3570 GpPointF start_point
, end_point
;
3571 GpPoint start_pointi
, end_pointi
;
3573 type
= flat_path
->pathdata
.Types
[i
];
3574 if (i
+1 < flat_path
->pathdata
.Count
)
3575 type2
= flat_path
->pathdata
.Types
[i
+1];
3577 type2
= PathPointTypeStart
;
3579 start_point
= flat_path
->pathdata
.Points
[i
];
3581 if ((type
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3582 subpath_start
= start_point
;
3584 if ((type
& PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
3585 end_point
= subpath_start
;
3586 else if ((type2
& PathPointTypePathTypeMask
) == PathPointTypeStart
)
3589 end_point
= flat_path
->pathdata
.Points
[i
+1];
3591 start_pointi
.X
= floorf(start_point
.X
);
3592 start_pointi
.Y
= floorf(start_point
.Y
);
3593 end_pointi
.X
= floorf(end_point
.X
);
3594 end_pointi
.Y
= floorf(end_point
.Y
);
3596 /* draw line segment */
3597 if (abs(start_pointi
.Y
- end_pointi
.Y
) > abs(start_pointi
.X
- end_pointi
.X
))
3599 INT x
, y
, start_y
, end_y
, step
;
3601 if (start_pointi
.Y
< end_pointi
.Y
)
3604 start_y
= ceilf(start_point
.Y
) - output_area
.top
;
3605 end_y
= end_pointi
.Y
- output_area
.top
;
3610 start_y
= start_point
.Y
- output_area
.top
;
3611 end_y
= ceilf(end_point
.Y
) - output_area
.top
;
3614 for (y
=start_y
; y
!= (end_y
+step
); y
+=step
)
3616 x
= gdip_round( start_point
.X
+
3617 (end_point
.X
- start_point
.X
) * (y
+ output_area
.top
- start_point
.Y
) / (end_point
.Y
- start_point
.Y
) )
3620 if (x
== prev_x
&& y
== prev_y
)
3625 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3627 if (!dash_pattern
[dash_pos
])
3630 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3634 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3636 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3641 INT x
, y
, start_x
, end_x
, step
;
3643 if (start_pointi
.X
< end_pointi
.X
)
3646 start_x
= ceilf(start_point
.X
) - output_area
.left
;
3647 end_x
= end_pointi
.X
- output_area
.left
;
3652 start_x
= start_point
.X
- output_area
.left
;
3653 end_x
= ceilf(end_point
.X
) - output_area
.left
;
3656 for (x
=start_x
; x
!= (end_x
+step
); x
+=step
)
3658 y
= gdip_round( start_point
.Y
+
3659 (end_point
.Y
- start_point
.Y
) * (x
+ output_area
.left
- start_point
.X
) / (end_point
.X
- start_point
.X
) )
3662 if (x
== prev_x
&& y
== prev_y
)
3667 dash_pos
= (dash_pos
+ 1 == dash_pattern_size
) ? 0 : dash_pos
+ 1;
3669 if (!dash_pattern
[dash_pos
])
3672 if (x
< 0 || x
>= output_width
|| y
< 0 || y
>= output_height
)
3676 output_bits
[x
+ y
*output_width
] = brush_bits
[x
+ y
*output_width
];
3678 output_bits
[x
+ y
*output_width
] = ((GpSolidFill
*)pen
->brush
)->color
;
3684 /* draw output image */
3687 stat
= alpha_blend_pixels(graphics
, output_area
.left
, output_area
.top
,
3688 (BYTE
*)output_bits
, output_width
, output_height
, output_width
* 4,
3689 PixelFormat32bppARGB
);
3692 heap_free(brush_bits
);
3693 heap_free(dyn_dash_pattern
);
3694 heap_free(output_bits
);
3697 GdipDeletePath(flat_path
);
3702 static GpStatus
SOFTWARE_GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3706 GpMatrix
*transform
=NULL
;
3708 /* Check if the final pen thickness in pixels is too thin. */
3709 if (pen
->unit
== UnitPixel
)
3711 if (pen
->width
< 1.415)
3712 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3716 GpPointF points
[3] = {{0,0}, {1,0}, {0,1}};
3718 points
[1].X
= pen
->width
;
3719 points
[2].Y
= pen
->width
;
3721 stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3722 CoordinateSpaceWorld
, points
, 3);
3727 if (((points
[1].X
-points
[0].X
)*(points
[1].X
-points
[0].X
) +
3728 (points
[1].Y
-points
[0].Y
)*(points
[1].Y
-points
[0].Y
) < 2.0001) &&
3729 ((points
[2].X
-points
[0].X
)*(points
[2].X
-points
[0].X
) +
3730 (points
[2].Y
-points
[0].Y
)*(points
[2].Y
-points
[0].Y
) < 2.0001))
3731 return SOFTWARE_GdipDrawThinPath(graphics
, pen
, path
);
3734 stat
= GdipClonePath(path
, &wide_path
);
3739 if (pen
->unit
== UnitPixel
)
3741 /* We have to transform this to device coordinates to get the widths right. */
3742 stat
= GdipCreateMatrix(&transform
);
3745 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
3746 CoordinateSpaceWorld
, transform
);
3750 stat
= GdipWidenPath(wide_path
, pen
, transform
, 1.0);
3752 if (pen
->unit
== UnitPixel
)
3754 /* Transform the path back to world coordinates */
3756 stat
= GdipInvertMatrix(transform
);
3759 stat
= GdipTransformPath(wide_path
, transform
);
3762 /* Actually draw the path */
3764 stat
= GdipFillPath(graphics
, pen
->brush
, wide_path
);
3766 GdipDeleteMatrix(transform
);
3768 GdipDeletePath(wide_path
);
3773 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
3777 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
3779 if(!pen
|| !graphics
)
3780 return InvalidParameter
;
3785 if (path
->pathdata
.Count
== 0)
3789 retval
= SOFTWARE_GdipDrawPath(graphics
, pen
, path
);
3791 retval
= GDI32_GdipDrawPath(graphics
, pen
, path
);
3796 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3797 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
3802 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3803 width
, height
, startAngle
, sweepAngle
);
3805 if(!graphics
|| !pen
)
3806 return InvalidParameter
;
3811 status
= GdipCreatePath(FillModeAlternate
, &path
);
3812 if (status
!= Ok
) return status
;
3814 status
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3816 status
= GdipDrawPath(graphics
, pen
, path
);
3818 GdipDeletePath(path
);
3822 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3823 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3825 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
3826 width
, height
, startAngle
, sweepAngle
);
3828 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3831 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
3832 REAL y
, REAL width
, REAL height
)
3837 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
3839 if(!pen
|| !graphics
)
3840 return InvalidParameter
;
3845 status
= GdipCreatePath(FillModeAlternate
, &path
);
3846 if (status
!= Ok
) return status
;
3848 status
= GdipAddPathRectangle(path
, x
, y
, width
, height
);
3850 status
= GdipDrawPath(graphics
, pen
, path
);
3852 GdipDeletePath(path
);
3856 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
3857 INT y
, INT width
, INT height
)
3859 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
3861 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
3864 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
3865 GDIPCONST GpRectF
* rects
, INT count
)
3870 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3872 if(!graphics
|| !pen
|| !rects
|| count
< 1)
3873 return InvalidParameter
;
3878 status
= GdipCreatePath(FillModeAlternate
, &path
);
3879 if (status
!= Ok
) return status
;
3881 status
= GdipAddPathRectangles(path
, rects
, count
);
3883 status
= GdipDrawPath(graphics
, pen
, path
);
3885 GdipDeletePath(path
);
3889 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
3890 GDIPCONST GpRect
* rects
, INT count
)
3896 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
3898 if(!rects
|| count
<=0)
3899 return InvalidParameter
;
3901 rectsF
= heap_alloc_zero(sizeof(GpRectF
) * count
);
3905 for(i
= 0;i
< count
;i
++){
3906 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3907 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3908 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
3909 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3912 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
3918 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
3919 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
3924 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3925 count
, tension
, fill
);
3927 if(!graphics
|| !brush
|| !points
)
3928 return InvalidParameter
;
3933 if(count
== 1) /* Do nothing */
3936 status
= GdipCreatePath(fill
, &path
);
3937 if (status
!= Ok
) return status
;
3939 status
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
3941 status
= GdipFillPath(graphics
, brush
, path
);
3943 GdipDeletePath(path
);
3947 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
3948 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
3954 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
3955 count
, tension
, fill
);
3957 if(!points
|| count
== 0)
3958 return InvalidParameter
;
3960 if(count
== 1) /* Do nothing */
3963 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
3967 for(i
= 0;i
< count
;i
++){
3968 ptf
[i
].X
= (REAL
)points
[i
].X
;
3969 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3972 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
3979 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
3980 GDIPCONST GpPointF
*points
, INT count
)
3982 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3983 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
3984 0.5f
, FillModeAlternate
);
3987 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
3988 GDIPCONST GpPoint
*points
, INT count
)
3990 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3991 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
3992 0.5f
, FillModeAlternate
);
3995 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
3996 REAL y
, REAL width
, REAL height
)
4001 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4003 if(!graphics
|| !brush
)
4004 return InvalidParameter
;
4009 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4013 stat
= GdipAddPathEllipse(path
, x
, y
, width
, height
);
4016 stat
= GdipFillPath(graphics
, brush
, path
);
4018 GdipDeletePath(path
);
4024 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4025 INT y
, INT width
, INT height
)
4027 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4029 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
4032 static GpStatus
GDI32_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4038 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
4039 return NotImplemented
;
4041 save_state
= SaveDC(graphics
->hdc
);
4042 EndPath(graphics
->hdc
);
4043 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
4046 retval
= get_clip_hrgn(graphics
, &hrgn
);
4052 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4054 BeginPath(graphics
->hdc
);
4055 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
4056 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
4061 EndPath(graphics
->hdc
);
4062 brush_fill_path(graphics
, brush
);
4067 RestoreDC(graphics
->hdc
, save_state
);
4073 static GpStatus
SOFTWARE_GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4078 if (!brush_can_fill_pixels(brush
))
4079 return NotImplemented
;
4081 /* FIXME: This could probably be done more efficiently without regions. */
4083 stat
= GdipCreateRegionPath(path
, &rgn
);
4087 stat
= GdipFillRegion(graphics
, brush
, rgn
);
4089 GdipDeleteRegion(rgn
);
4095 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
4097 GpStatus stat
= NotImplemented
;
4099 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
4101 if(!brush
|| !graphics
|| !path
)
4102 return InvalidParameter
;
4107 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4108 stat
= GDI32_GdipFillPath(graphics
, brush
, path
);
4110 if (stat
== NotImplemented
)
4111 stat
= SOFTWARE_GdipFillPath(graphics
, brush
, path
);
4113 if (stat
== NotImplemented
)
4115 FIXME("Not implemented for brushtype %i\n", brush
->bt
);
4122 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
4123 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
4128 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
4129 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4131 if(!graphics
|| !brush
)
4132 return InvalidParameter
;
4137 stat
= GdipCreatePath(FillModeAlternate
, &path
);
4141 stat
= GdipAddPathPie(path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4144 stat
= GdipFillPath(graphics
, brush
, path
);
4146 GdipDeletePath(path
);
4152 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
4153 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
4155 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
4156 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
4158 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
4161 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
4162 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
4167 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4169 if(!graphics
|| !brush
|| !points
|| !count
)
4170 return InvalidParameter
;
4175 stat
= GdipCreatePath(fillMode
, &path
);
4179 stat
= GdipAddPathPolygon(path
, points
, count
);
4182 stat
= GdipFillPath(graphics
, brush
, path
);
4184 GdipDeletePath(path
);
4190 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
4191 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
4196 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
4198 if(!graphics
|| !brush
|| !points
|| !count
)
4199 return InvalidParameter
;
4204 stat
= GdipCreatePath(fillMode
, &path
);
4208 stat
= GdipAddPathPolygonI(path
, points
, count
);
4211 stat
= GdipFillPath(graphics
, brush
, path
);
4213 GdipDeletePath(path
);
4219 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
4220 GDIPCONST GpPointF
*points
, INT count
)
4222 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4224 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
4227 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
4228 GDIPCONST GpPoint
*points
, INT count
)
4230 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
4232 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
4235 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
4236 REAL x
, REAL y
, REAL width
, REAL height
)
4240 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
4245 rect
.Height
= height
;
4247 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4250 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
4251 INT x
, INT y
, INT width
, INT height
)
4255 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
4259 rect
.Width
= (REAL
)width
;
4260 rect
.Height
= (REAL
)height
;
4262 return GdipFillRectangles(graphics
, brush
, &rect
, 1);
4265 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
4271 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4273 if(!graphics
|| !brush
|| !rects
|| count
<= 0)
4274 return InvalidParameter
;
4276 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4278 status
= METAFILE_FillRectangles((GpMetafile
*)graphics
->image
, brush
, rects
, count
);
4279 /* FIXME: Add gdi32 drawing. */
4283 status
= GdipCreatePath(FillModeAlternate
, &path
);
4284 if (status
!= Ok
) return status
;
4286 status
= GdipAddPathRectangles(path
, rects
, count
);
4288 status
= GdipFillPath(graphics
, brush
, path
);
4290 GdipDeletePath(path
);
4294 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
4301 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
4303 if(!rects
|| count
<= 0)
4304 return InvalidParameter
;
4306 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
4310 for(i
= 0; i
< count
; i
++){
4311 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
4312 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
4313 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
4314 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
4317 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
4323 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4331 if(!graphics
->hdc
|| !brush_can_fill_path(brush
))
4332 return NotImplemented
;
4334 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
4338 save_state
= SaveDC(graphics
->hdc
);
4339 EndPath(graphics
->hdc
);
4341 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4346 status
= get_clip_hrgn(graphics
, &hrgn
);
4350 RestoreDC(graphics
->hdc
, save_state
);
4356 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
4360 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
4362 BeginPath(graphics
->hdc
);
4363 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4364 EndPath(graphics
->hdc
);
4366 brush_fill_path(graphics
, brush
);
4369 RestoreDC(graphics
->hdc
, save_state
);
4375 static GpStatus
SOFTWARE_GdipFillRegion(GpGraphics
*graphics
, GpBrush
*brush
,
4379 GpRegion
*temp_region
;
4380 GpMatrix world_to_device
;
4381 GpRectF graphics_bounds
;
4385 GpRect gp_bound_rect
;
4387 if (!brush_can_fill_pixels(brush
))
4388 return NotImplemented
;
4390 stat
= get_graphics_bounds(graphics
, &graphics_bounds
);
4393 stat
= GdipCloneRegion(region
, &temp_region
);
4397 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
4398 CoordinateSpaceWorld
, &world_to_device
);
4401 stat
= GdipTransformRegion(temp_region
, &world_to_device
);
4404 stat
= GdipCombineRegionRect(temp_region
, &graphics_bounds
, CombineModeIntersect
);
4407 stat
= GdipGetRegionHRgn(temp_region
, NULL
, &hregion
);
4409 GdipDeleteRegion(temp_region
);
4412 if (stat
== Ok
&& GetRgnBox(hregion
, &bound_rect
) == NULLREGION
)
4414 DeleteObject(hregion
);
4420 gp_bound_rect
.X
= bound_rect
.left
;
4421 gp_bound_rect
.Y
= bound_rect
.top
;
4422 gp_bound_rect
.Width
= bound_rect
.right
- bound_rect
.left
;
4423 gp_bound_rect
.Height
= bound_rect
.bottom
- bound_rect
.top
;
4425 pixel_data
= heap_alloc_zero(sizeof(*pixel_data
) * gp_bound_rect
.Width
* gp_bound_rect
.Height
);
4431 stat
= brush_fill_pixels(graphics
, brush
, pixel_data
,
4432 &gp_bound_rect
, gp_bound_rect
.Width
);
4435 stat
= alpha_blend_pixels_hrgn(graphics
, gp_bound_rect
.X
,
4436 gp_bound_rect
.Y
, (BYTE
*)pixel_data
, gp_bound_rect
.Width
,
4437 gp_bound_rect
.Height
, gp_bound_rect
.Width
* 4, hregion
,
4438 PixelFormat32bppARGB
);
4440 heap_free(pixel_data
);
4443 DeleteObject(hregion
);
4449 /*****************************************************************************
4450 * GdipFillRegion [GDIPLUS.@]
4452 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
4455 GpStatus stat
= NotImplemented
;
4457 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
4459 if (!(graphics
&& brush
&& region
))
4460 return InvalidParameter
;
4465 if (!graphics
->image
&& !graphics
->alpha_hdc
)
4466 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
4468 if (stat
== NotImplemented
)
4469 stat
= SOFTWARE_GdipFillRegion(graphics
, brush
, region
);
4471 if (stat
== NotImplemented
)
4473 FIXME("not implemented for brushtype %i\n", brush
->bt
);
4480 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
4482 TRACE("(%p,%u)\n", graphics
, intention
);
4485 return InvalidParameter
;
4490 /* We have no internal operation queue, so there's no need to clear it. */
4498 /*****************************************************************************
4499 * GdipGetClipBounds [GDIPLUS.@]
4501 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4506 TRACE("(%p, %p)\n", graphics
, rect
);
4509 return InvalidParameter
;
4514 status
= GdipCreateRegion(&clip
);
4515 if (status
!= Ok
) return status
;
4517 status
= GdipGetClip(graphics
, clip
);
4519 status
= GdipGetRegionBounds(clip
, graphics
, rect
);
4521 GdipDeleteRegion(clip
);
4525 /*****************************************************************************
4526 * GdipGetClipBoundsI [GDIPLUS.@]
4528 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4530 TRACE("(%p, %p)\n", graphics
, rect
);
4533 return InvalidParameter
;
4538 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
4541 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4542 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
4543 CompositingMode
*mode
)
4545 TRACE("(%p, %p)\n", graphics
, mode
);
4547 if(!graphics
|| !mode
)
4548 return InvalidParameter
;
4553 *mode
= graphics
->compmode
;
4558 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4559 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
4560 CompositingQuality
*quality
)
4562 TRACE("(%p, %p)\n", graphics
, quality
);
4564 if(!graphics
|| !quality
)
4565 return InvalidParameter
;
4570 *quality
= graphics
->compqual
;
4575 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4576 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
4577 InterpolationMode
*mode
)
4579 TRACE("(%p, %p)\n", graphics
, mode
);
4581 if(!graphics
|| !mode
)
4582 return InvalidParameter
;
4587 *mode
= graphics
->interpolation
;
4592 /* FIXME: Need to handle color depths less than 24bpp */
4593 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
4595 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
4597 if(!graphics
|| !argb
)
4598 return InvalidParameter
;
4606 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
4608 TRACE("(%p, %p)\n", graphics
, scale
);
4610 if(!graphics
|| !scale
)
4611 return InvalidParameter
;
4616 *scale
= graphics
->scale
;
4621 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
4623 TRACE("(%p, %p)\n", graphics
, unit
);
4625 if(!graphics
|| !unit
)
4626 return InvalidParameter
;
4631 *unit
= graphics
->unit
;
4636 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4637 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4640 TRACE("(%p, %p)\n", graphics
, mode
);
4642 if(!graphics
|| !mode
)
4643 return InvalidParameter
;
4648 *mode
= graphics
->pixeloffset
;
4653 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4654 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
4656 TRACE("(%p, %p)\n", graphics
, mode
);
4658 if(!graphics
|| !mode
)
4659 return InvalidParameter
;
4664 *mode
= graphics
->smoothing
;
4669 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
4671 TRACE("(%p, %p)\n", graphics
, contrast
);
4673 if(!graphics
|| !contrast
)
4674 return InvalidParameter
;
4676 *contrast
= graphics
->textcontrast
;
4681 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4682 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
4683 TextRenderingHint
*hint
)
4685 TRACE("(%p, %p)\n", graphics
, hint
);
4687 if(!graphics
|| !hint
)
4688 return InvalidParameter
;
4693 *hint
= graphics
->texthint
;
4698 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
4702 GpMatrix device_to_world
;
4704 TRACE("(%p, %p)\n", graphics
, rect
);
4706 if(!graphics
|| !rect
)
4707 return InvalidParameter
;
4712 /* intersect window and graphics clipping regions */
4713 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
4716 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
4719 /* transform to world coordinates */
4720 if((stat
= get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
)) != Ok
)
4723 if((stat
= GdipTransformRegion(clip_rgn
, &device_to_world
)) != Ok
)
4726 /* get bounds of the region */
4727 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
4730 GdipDeleteRegion(clip_rgn
);
4735 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4740 TRACE("(%p, %p)\n", graphics
, rect
);
4742 if(!graphics
|| !rect
)
4743 return InvalidParameter
;
4745 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
4747 rect
->X
= gdip_round(rectf
.X
);
4748 rect
->Y
= gdip_round(rectf
.Y
);
4749 rect
->Width
= gdip_round(rectf
.Width
);
4750 rect
->Height
= gdip_round(rectf
.Height
);
4756 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4758 TRACE("(%p, %p)\n", graphics
, matrix
);
4760 if(!graphics
|| !matrix
)
4761 return InvalidParameter
;
4766 *matrix
= graphics
->worldtrans
;
4770 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
4776 TRACE("(%p, %x)\n", graphics
, color
);
4779 return InvalidParameter
;
4784 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
4785 return METAFILE_GraphicsClear((GpMetafile
*)graphics
->image
, color
);
4787 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
4790 if((stat
= GdipGetVisibleClipBounds(graphics
, &wnd_rect
)) != Ok
){
4791 GdipDeleteBrush((GpBrush
*)brush
);
4795 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
4796 wnd_rect
.Width
, wnd_rect
.Height
);
4798 GdipDeleteBrush((GpBrush
*)brush
);
4803 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4805 TRACE("(%p, %p)\n", graphics
, res
);
4807 if(!graphics
|| !res
)
4808 return InvalidParameter
;
4810 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
4813 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
4819 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
4821 if(!graphics
|| !result
)
4822 return InvalidParameter
;
4829 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4830 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
4833 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4836 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4839 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
4842 GdipDeleteRegion(rgn
);
4846 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
4848 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
4851 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
4857 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
4859 if(!graphics
|| !result
)
4860 return InvalidParameter
;
4867 pts
[1].X
= x
+ width
;
4868 pts
[1].Y
= y
+ height
;
4870 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
4871 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
4874 pts
[1].X
-= pts
[0].X
;
4875 pts
[1].Y
-= pts
[0].Y
;
4877 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4880 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4883 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
4886 GdipDeleteRegion(rgn
);
4890 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4892 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
4895 GpStatus
gdip_format_string(HDC hdc
,
4896 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4897 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
4898 gdip_format_string_callback callback
, void *user_data
)
4901 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
4902 nheight
, lineend
, lineno
= 0;
4904 StringAlignment halign
;
4907 HotkeyPrefix hkprefix
;
4908 INT
*hotkeyprefix_offsets
=NULL
;
4909 INT hotkeyprefix_count
=0;
4910 INT hotkeyprefix_pos
=0, hotkeyprefix_end_pos
=0;
4911 BOOL seen_prefix
= FALSE
;
4912 GpStringFormat
*dyn_format
=NULL
;
4914 if(length
== -1) length
= lstrlenW(string
);
4916 stringdup
= heap_alloc_zero((length
+ 1) * sizeof(WCHAR
));
4917 if(!stringdup
) return OutOfMemory
;
4921 stat
= GdipStringFormatGetGenericDefault(&dyn_format
);
4924 heap_free(stringdup
);
4927 format
= dyn_format
;
4930 nwidth
= rect
->Width
;
4931 nheight
= rect
->Height
;
4932 if (ignore_empty_clip
)
4934 if (!nwidth
) nwidth
= INT_MAX
;
4935 if (!nheight
) nheight
= INT_MAX
;
4938 hkprefix
= format
->hkprefix
;
4940 if (hkprefix
== HotkeyPrefixShow
)
4942 for (i
=0; i
<length
; i
++)
4944 if (string
[i
] == '&')
4945 hotkeyprefix_count
++;
4949 if (hotkeyprefix_count
)
4950 hotkeyprefix_offsets
= heap_alloc_zero(sizeof(INT
) * hotkeyprefix_count
);
4952 hotkeyprefix_count
= 0;
4954 for(i
= 0, j
= 0; i
< length
; i
++){
4955 /* FIXME: This makes the indexes passed to callback inaccurate. */
4956 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
4959 /* FIXME: tabs should be handled using tabstops from stringformat */
4960 if (string
[i
] == '\t')
4963 if (seen_prefix
&& hkprefix
== HotkeyPrefixShow
&& string
[i
] != '&')
4964 hotkeyprefix_offsets
[hotkeyprefix_count
++] = j
;
4965 else if (!seen_prefix
&& hkprefix
!= HotkeyPrefixNone
&& string
[i
] == '&')
4971 seen_prefix
= FALSE
;
4973 stringdup
[j
] = string
[i
];
4979 halign
= format
->align
;
4981 while(sum
< length
){
4982 GetTextExtentExPointW(hdc
, stringdup
+ sum
, length
- sum
,
4983 nwidth
, &fit
, NULL
, &size
);
4989 for(lret
= 0; lret
< fit
; lret
++)
4990 if(*(stringdup
+ sum
+ lret
) == '\n')
4993 /* Line break code (may look strange, but it imitates windows). */
4995 lineend
= fit
= lret
; /* this is not an off-by-one error */
4996 else if(fit
< (length
- sum
)){
4997 if(*(stringdup
+ sum
+ fit
) == ' ')
4998 while(*(stringdup
+ sum
+ fit
) == ' ')
5001 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
5004 if(*(stringdup
+ sum
+ fit
) == '\t')
5013 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
5014 *(stringdup
+ sum
+ lineend
- 1) == '\t')
5020 GetTextExtentExPointW(hdc
, stringdup
+ sum
, lineend
,
5021 nwidth
, &j
, NULL
, &size
);
5023 bounds
.Width
= size
.cx
;
5025 if(height
+ size
.cy
> nheight
)
5027 if (format
->attr
& StringFormatFlagsLineLimit
)
5029 bounds
.Height
= nheight
- (height
+ size
.cy
);
5032 bounds
.Height
= size
.cy
;
5034 bounds
.Y
= rect
->Y
+ height
;
5038 case StringAlignmentNear
:
5042 case StringAlignmentCenter
:
5043 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
5045 case StringAlignmentFar
:
5046 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
5050 for (hotkeyprefix_end_pos
=hotkeyprefix_pos
; hotkeyprefix_end_pos
<hotkeyprefix_count
; hotkeyprefix_end_pos
++)
5051 if (hotkeyprefix_offsets
[hotkeyprefix_end_pos
] >= sum
+ lineend
)
5054 stat
= callback(hdc
, stringdup
, sum
, lineend
,
5055 font
, rect
, format
, lineno
, &bounds
,
5056 &hotkeyprefix_offsets
[hotkeyprefix_pos
],
5057 hotkeyprefix_end_pos
-hotkeyprefix_pos
, user_data
);
5062 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
5066 hotkeyprefix_pos
= hotkeyprefix_end_pos
;
5068 if(height
> nheight
)
5071 /* Stop if this was a linewrap (but not if it was a linebreak). */
5072 if ((lret
== fitcpy
) && (format
->attr
& StringFormatFlagsNoWrap
))
5076 heap_free(stringdup
);
5077 heap_free(hotkeyprefix_offsets
);
5078 GdipDeleteStringFormat(dyn_format
);
5083 struct measure_ranges_args
{
5085 REAL rel_width
, rel_height
;
5088 static GpStatus
measure_ranges_callback(HDC hdc
,
5089 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5090 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5091 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5092 INT underlined_index_count
, void *user_data
)
5096 struct measure_ranges_args
*args
= user_data
;
5098 for (i
=0; i
<format
->range_count
; i
++)
5100 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
5101 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
5102 if (range_start
< range_end
)
5107 range_rect
.Y
= bounds
->Y
/ args
->rel_height
;
5108 range_rect
.Height
= bounds
->Height
/ args
->rel_height
;
5110 GetTextExtentExPointW(hdc
, string
+ index
, range_start
- index
,
5111 INT_MAX
, NULL
, NULL
, &range_size
);
5112 range_rect
.X
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
;
5114 GetTextExtentExPointW(hdc
, string
+ index
, range_end
- index
,
5115 INT_MAX
, NULL
, NULL
, &range_size
);
5116 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) / args
->rel_width
- range_rect
.X
;
5118 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
5127 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
5128 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
5129 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
5130 INT regionCount
, GpRegion
** regions
)
5134 HFONT gdifont
, oldfont
;
5135 struct measure_ranges_args args
;
5136 HDC hdc
, temp_hdc
=NULL
;
5141 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
5142 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
5144 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
5145 return InvalidParameter
;
5147 if (regionCount
< stringFormat
->range_count
)
5148 return InvalidParameter
;
5152 hdc
= temp_hdc
= CreateCompatibleDC(0);
5153 if (!temp_hdc
) return OutOfMemory
;
5156 hdc
= graphics
->hdc
;
5158 if (stringFormat
->attr
)
5159 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
5167 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5168 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5169 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5170 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5171 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5173 margin_x
= stringFormat
->generic_typographic
? 0.0 : font
->emSize
/ 6.0;
5174 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5176 scaled_rect
.X
= (layoutRect
->X
+ margin_x
) * args
.rel_width
;
5177 scaled_rect
.Y
= layoutRect
->Y
* args
.rel_height
;
5178 scaled_rect
.Width
= layoutRect
->Width
* args
.rel_width
;
5179 scaled_rect
.Height
= layoutRect
->Height
* args
.rel_height
;
5181 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5182 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5184 get_font_hfont(graphics
, font
, stringFormat
, &gdifont
, NULL
);
5185 oldfont
= SelectObject(hdc
, gdifont
);
5187 for (i
=0; i
<stringFormat
->range_count
; i
++)
5189 stat
= GdipSetEmpty(regions
[i
]);
5194 args
.regions
= regions
;
5196 stat
= gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, stringFormat
,
5197 (stringFormat
->attr
& StringFormatFlagsNoClip
) != 0, measure_ranges_callback
, &args
);
5199 SelectObject(hdc
, oldfont
);
5200 DeleteObject(gdifont
);
5208 struct measure_string_args
{
5210 INT
*codepointsfitted
;
5212 REAL rel_width
, rel_height
;
5215 static GpStatus
measure_string_callback(HDC hdc
,
5216 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5217 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5218 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5219 INT underlined_index_count
, void *user_data
)
5221 struct measure_string_args
*args
= user_data
;
5222 REAL new_width
, new_height
;
5224 new_width
= bounds
->Width
/ args
->rel_width
;
5225 new_height
= (bounds
->Height
+ bounds
->Y
) / args
->rel_height
- args
->bounds
->Y
;
5227 if (new_width
> args
->bounds
->Width
)
5228 args
->bounds
->Width
= new_width
;
5230 if (new_height
> args
->bounds
->Height
)
5231 args
->bounds
->Height
= new_height
;
5233 if (args
->codepointsfitted
)
5234 *args
->codepointsfitted
= index
+ length
;
5236 if (args
->linesfilled
)
5237 (*args
->linesfilled
)++;
5242 /* Find the smallest rectangle that bounds the text when it is printed in rect
5243 * according to the format options listed in format. If rect has 0 width and
5244 * height, then just find the smallest rectangle that bounds the text when it's
5245 * printed at location (rect->X, rect-Y). */
5246 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
5247 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
5248 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
5249 INT
*codepointsfitted
, INT
*linesfilled
)
5251 HFONT oldfont
, gdifont
;
5252 struct measure_string_args args
;
5253 HDC temp_hdc
=NULL
, hdc
;
5259 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
5260 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
5261 bounds
, codepointsfitted
, linesfilled
);
5263 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
5264 return InvalidParameter
;
5268 hdc
= temp_hdc
= CreateCompatibleDC(0);
5269 if (!temp_hdc
) return OutOfMemory
;
5272 hdc
= graphics
->hdc
;
5274 if(linesfilled
) *linesfilled
= 0;
5275 if(codepointsfitted
) *codepointsfitted
= 0;
5278 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5286 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5287 args
.rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5288 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5289 args
.rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5290 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5292 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5293 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5295 scaled_rect
.X
= (rect
->X
+ margin_x
) * args
.rel_width
;
5296 scaled_rect
.Y
= rect
->Y
* args
.rel_height
;
5297 scaled_rect
.Width
= rect
->Width
* args
.rel_width
;
5298 scaled_rect
.Height
= rect
->Height
* args
.rel_height
;
5299 if (scaled_rect
.Width
>= 0.5)
5301 scaled_rect
.Width
-= margin_x
* 2.0 * args
.rel_width
;
5302 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5305 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5306 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5308 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5309 oldfont
= SelectObject(hdc
, gdifont
);
5311 bounds
->X
= rect
->X
;
5312 bounds
->Y
= rect
->Y
;
5313 bounds
->Width
= 0.0;
5314 bounds
->Height
= 0.0;
5316 args
.bounds
= bounds
;
5317 args
.codepointsfitted
= &glyphs
;
5318 args
.linesfilled
= &lines
;
5321 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5322 measure_string_callback
, &args
);
5324 if (linesfilled
) *linesfilled
= lines
;
5325 if (codepointsfitted
) *codepointsfitted
= glyphs
;
5328 bounds
->Width
+= margin_x
* 2.0;
5330 SelectObject(hdc
, oldfont
);
5331 DeleteObject(gdifont
);
5339 struct draw_string_args
{
5340 GpGraphics
*graphics
;
5341 GDIPCONST GpBrush
*brush
;
5342 REAL x
, y
, rel_width
, rel_height
, ascent
;
5345 static GpStatus
draw_string_callback(HDC hdc
,
5346 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
5347 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
5348 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
5349 INT underlined_index_count
, void *user_data
)
5351 struct draw_string_args
*args
= user_data
;
5355 position
.X
= args
->x
+ bounds
->X
/ args
->rel_width
;
5356 position
.Y
= args
->y
+ bounds
->Y
/ args
->rel_height
+ args
->ascent
;
5358 stat
= draw_driver_string(args
->graphics
, &string
[index
], length
, font
, format
,
5359 args
->brush
, &position
,
5360 DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
, NULL
);
5362 if (stat
== Ok
&& underlined_index_count
)
5364 OUTLINETEXTMETRICW otm
;
5365 REAL underline_y
, underline_height
;
5368 GetOutlineTextMetricsW(hdc
, sizeof(otm
), &otm
);
5370 underline_height
= otm
.otmsUnderscoreSize
/ args
->rel_height
;
5371 underline_y
= position
.Y
- otm
.otmsUnderscorePosition
/ args
->rel_height
- underline_height
/ 2;
5373 for (i
=0; i
<underlined_index_count
; i
++)
5375 REAL start_x
, end_x
;
5377 INT ofs
= underlined_indexes
[i
] - index
;
5379 GetTextExtentExPointW(hdc
, string
+ index
, ofs
, INT_MAX
, NULL
, NULL
, &text_size
);
5380 start_x
= text_size
.cx
/ args
->rel_width
;
5382 GetTextExtentExPointW(hdc
, string
+ index
, ofs
+1, INT_MAX
, NULL
, NULL
, &text_size
);
5383 end_x
= text_size
.cx
/ args
->rel_width
;
5385 GdipFillRectangle(args
->graphics
, (GpBrush
*)args
->brush
, position
.X
+start_x
, underline_y
, end_x
-start_x
, underline_height
);
5392 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
5393 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
5394 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
5398 GpPointF pt
[3], rectcpy
[4];
5400 REAL rel_width
, rel_height
, margin_x
;
5401 INT save_state
, format_flags
= 0;
5403 struct draw_string_args args
;
5405 HDC hdc
, temp_hdc
=NULL
;
5406 TEXTMETRICW textmetric
;
5408 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
5409 length
, font
, debugstr_rectf(rect
), format
, brush
);
5411 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
5412 return InvalidParameter
;
5416 hdc
= graphics
->hdc
;
5420 hdc
= temp_hdc
= CreateCompatibleDC(0);
5424 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
5426 format_flags
= format
->attr
;
5428 /* Should be no need to explicitly test for StringAlignmentNear as
5429 * that is default behavior if no alignment is passed. */
5430 if(format
->vertalign
!= StringAlignmentNear
){
5431 RectF bounds
, in_rect
= *rect
;
5432 in_rect
.Height
= 0.0; /* avoid height clipping */
5433 GdipMeasureString(graphics
, string
, length
, font
, &in_rect
, format
, &bounds
, 0, 0);
5435 TRACE("bounds %s\n", debugstr_rectf(&bounds
));
5437 if(format
->vertalign
== StringAlignmentCenter
)
5438 offsety
= (rect
->Height
- bounds
.Height
) / 2;
5439 else if(format
->vertalign
== StringAlignmentFar
)
5440 offsety
= (rect
->Height
- bounds
.Height
);
5442 TRACE("vertical align %d, offsety %f\n", format
->vertalign
, offsety
);
5445 save_state
= SaveDC(hdc
);
5453 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
5454 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
5455 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
5456 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
5457 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
5459 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
5460 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
5461 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
5462 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
5463 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
5465 margin_x
= (format
&& format
->generic_typographic
) ? 0.0 : font
->emSize
/ 6.0;
5466 margin_x
*= units_scale(font
->unit
, graphics
->unit
, graphics
->xres
);
5468 scaled_rect
.X
= margin_x
* rel_width
;
5469 scaled_rect
.Y
= 0.0;
5470 scaled_rect
.Width
= rel_width
* rect
->Width
;
5471 scaled_rect
.Height
= rel_height
* rect
->Height
;
5472 if (scaled_rect
.Width
>= 0.5)
5474 scaled_rect
.Width
-= margin_x
* 2.0 * rel_width
;
5475 if (scaled_rect
.Width
< 0.5) return Ok
; /* doesn't fit */
5478 if (scaled_rect
.Width
>= 1 << 23) scaled_rect
.Width
= 1 << 23;
5479 if (scaled_rect
.Height
>= 1 << 23) scaled_rect
.Height
= 1 << 23;
5481 if (!(format_flags
& StringFormatFlagsNoClip
) &&
5482 scaled_rect
.Width
!= 1 << 23 && scaled_rect
.Height
!= 1 << 23 &&
5483 rect
->Width
> 0.0 && rect
->Height
> 0.0)
5485 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5486 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
5487 SelectClipRgn(hdc
, rgn
);
5490 get_font_hfont(graphics
, font
, format
, &gdifont
, NULL
);
5491 SelectObject(hdc
, gdifont
);
5493 args
.graphics
= graphics
;
5497 args
.y
= rect
->Y
+ offsety
;
5499 args
.rel_width
= rel_width
;
5500 args
.rel_height
= rel_height
;
5502 GetTextMetricsW(hdc
, &textmetric
);
5503 args
.ascent
= textmetric
.tmAscent
/ rel_height
;
5505 gdip_format_string(hdc
, string
, length
, font
, &scaled_rect
, format
, TRUE
,
5506 draw_string_callback
, &args
);
5509 DeleteObject(gdifont
);
5511 RestoreDC(hdc
, save_state
);
5518 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
5520 TRACE("(%p)\n", graphics
);
5523 return InvalidParameter
;
5528 return GdipSetInfinite(graphics
->clip
);
5531 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
5535 TRACE("(%p)\n", graphics
);
5538 return InvalidParameter
;
5543 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5544 stat
= METAFILE_ResetWorldTransform((GpMetafile
*)graphics
->image
);
5550 return GdipSetMatrixElements(&graphics
->worldtrans
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
5553 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
5554 GpMatrixOrder order
)
5558 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
5561 return InvalidParameter
;
5566 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5567 stat
= METAFILE_RotateWorldTransform((GpMetafile
*)graphics
->image
, angle
, order
);
5573 return GdipRotateMatrix(&graphics
->worldtrans
, angle
, order
);
5576 static GpStatus
begin_container(GpGraphics
*graphics
,
5577 GraphicsContainerType type
, GraphicsContainer
*state
)
5579 GraphicsContainerItem
*container
;
5582 if(!graphics
|| !state
)
5583 return InvalidParameter
;
5585 sts
= init_container(&container
, graphics
, type
);
5589 list_add_head(&graphics
->containers
, &container
->entry
);
5590 *state
= graphics
->contid
= container
->contid
;
5592 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5593 if (type
== BEGIN_CONTAINER
)
5594 METAFILE_BeginContainerNoParams((GpMetafile
*)graphics
->image
, container
->contid
);
5596 METAFILE_SaveGraphics((GpMetafile
*)graphics
->image
, container
->contid
);
5602 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
5604 TRACE("(%p, %p)\n", graphics
, state
);
5605 return begin_container(graphics
, SAVE_GRAPHICS
, state
);
5608 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
5609 GraphicsContainer
*state
)
5611 TRACE("(%p, %p)\n", graphics
, state
);
5612 return begin_container(graphics
, BEGIN_CONTAINER
, state
);
5615 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5617 GraphicsContainerItem
*container
;
5620 GpRectF scaled_srcrect
;
5621 REAL scale_x
, scale_y
;
5623 TRACE("(%p, %s, %s, %d, %p)\n", graphics
, debugstr_rectf(dstrect
), debugstr_rectf(srcrect
), unit
, state
);
5625 if(!graphics
|| !dstrect
|| !srcrect
|| unit
< UnitPixel
|| unit
> UnitMillimeter
|| !state
)
5626 return InvalidParameter
;
5628 stat
= init_container(&container
, graphics
, BEGIN_CONTAINER
);
5632 list_add_head(&graphics
->containers
, &container
->entry
);
5633 *state
= graphics
->contid
= container
->contid
;
5635 scale_x
= units_to_pixels(1.0, unit
, graphics
->xres
);
5636 scale_y
= units_to_pixels(1.0, unit
, graphics
->yres
);
5638 scaled_srcrect
.X
= scale_x
* srcrect
->X
;
5639 scaled_srcrect
.Y
= scale_y
* srcrect
->Y
;
5640 scaled_srcrect
.Width
= scale_x
* srcrect
->Width
;
5641 scaled_srcrect
.Height
= scale_y
* srcrect
->Height
;
5643 transform
.matrix
[0] = dstrect
->Width
/ scaled_srcrect
.Width
;
5644 transform
.matrix
[1] = 0.0;
5645 transform
.matrix
[2] = 0.0;
5646 transform
.matrix
[3] = dstrect
->Height
/ scaled_srcrect
.Height
;
5647 transform
.matrix
[4] = dstrect
->X
- scaled_srcrect
.X
;
5648 transform
.matrix
[5] = dstrect
->Y
- scaled_srcrect
.Y
;
5650 GdipMultiplyMatrix(&graphics
->worldtrans
, &transform
, MatrixOrderPrepend
);
5652 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5653 METAFILE_BeginContainer((GpMetafile
*)graphics
->image
, dstrect
, srcrect
, unit
, container
->contid
);
5659 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
5661 GpRectF dstrectf
, srcrectf
;
5663 TRACE("(%p, %p, %p, %d, %p)\n", graphics
, dstrect
, srcrect
, unit
, state
);
5665 if (!dstrect
|| !srcrect
)
5666 return InvalidParameter
;
5668 dstrectf
.X
= dstrect
->X
;
5669 dstrectf
.Y
= dstrect
->Y
;
5670 dstrectf
.Width
= dstrect
->Width
;
5671 dstrectf
.Height
= dstrect
->Height
;
5673 srcrectf
.X
= srcrect
->X
;
5674 srcrectf
.Y
= srcrect
->Y
;
5675 srcrectf
.Width
= srcrect
->Width
;
5676 srcrectf
.Height
= srcrect
->Height
;
5678 return GdipBeginContainer(graphics
, &dstrectf
, &srcrectf
, unit
, state
);
5681 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
5683 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
5684 return NotImplemented
;
5687 static GpStatus
end_container(GpGraphics
*graphics
, GraphicsContainerType type
,
5688 GraphicsContainer state
)
5691 GraphicsContainerItem
*container
, *container2
;
5694 return InvalidParameter
;
5696 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5697 if(container
->contid
== state
&& container
->type
== type
)
5701 /* did not find a matching container */
5702 if(&container
->entry
== &graphics
->containers
)
5705 sts
= restore_container(graphics
, container
);
5709 /* remove all of the containers on top of the found container */
5710 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
5711 if(container
->contid
== state
)
5713 list_remove(&container
->entry
);
5714 delete_container(container
);
5717 list_remove(&container
->entry
);
5718 delete_container(container
);
5720 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5721 if (type
== BEGIN_CONTAINER
)
5722 METAFILE_EndContainer((GpMetafile
*)graphics
->image
, state
);
5724 METAFILE_RestoreGraphics((GpMetafile
*)graphics
->image
, state
);
5730 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
5732 TRACE("(%p, %x)\n", graphics
, state
);
5733 return end_container(graphics
, BEGIN_CONTAINER
, state
);
5736 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
5738 TRACE("(%p, %x)\n", graphics
, state
);
5739 return end_container(graphics
, SAVE_GRAPHICS
, state
);
5742 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
5743 REAL sy
, GpMatrixOrder order
)
5747 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
5750 return InvalidParameter
;
5755 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5756 stat
= METAFILE_ScaleWorldTransform((GpMetafile
*)graphics
->image
, sx
, sy
, order
);
5762 return GdipScaleMatrix(&graphics
->worldtrans
, sx
, sy
, order
);
5765 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
5768 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
5770 if(!graphics
|| !srcgraphics
)
5771 return InvalidParameter
;
5773 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
5776 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
5777 CompositingMode mode
)
5779 TRACE("(%p, %d)\n", graphics
, mode
);
5782 return InvalidParameter
;
5787 graphics
->compmode
= mode
;
5792 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
5793 CompositingQuality quality
)
5795 TRACE("(%p, %d)\n", graphics
, quality
);
5798 return InvalidParameter
;
5803 graphics
->compqual
= quality
;
5808 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
5809 InterpolationMode mode
)
5811 TRACE("(%p, %d)\n", graphics
, mode
);
5813 if(!graphics
|| mode
== InterpolationModeInvalid
|| mode
> InterpolationModeHighQualityBicubic
)
5814 return InvalidParameter
;
5819 if (mode
== InterpolationModeDefault
|| mode
== InterpolationModeLowQuality
)
5820 mode
= InterpolationModeBilinear
;
5822 if (mode
== InterpolationModeHighQuality
)
5823 mode
= InterpolationModeHighQualityBicubic
;
5825 graphics
->interpolation
= mode
;
5830 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
5834 TRACE("(%p, %.2f)\n", graphics
, scale
);
5836 if(!graphics
|| (scale
<= 0.0))
5837 return InvalidParameter
;
5842 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5844 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, graphics
->unit
, scale
);
5849 graphics
->scale
= scale
;
5854 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
5858 TRACE("(%p, %d)\n", graphics
, unit
);
5861 return InvalidParameter
;
5866 if(unit
== UnitWorld
)
5867 return InvalidParameter
;
5869 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
5871 stat
= METAFILE_SetPageTransform((GpMetafile
*)graphics
->image
, unit
, graphics
->scale
);
5876 graphics
->unit
= unit
;
5881 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
5884 TRACE("(%p, %d)\n", graphics
, mode
);
5887 return InvalidParameter
;
5892 graphics
->pixeloffset
= mode
;
5897 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
5901 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
5904 FIXME("value is unused in rendering\n");
5907 return InvalidParameter
;
5909 graphics
->origin_x
= x
;
5910 graphics
->origin_y
= y
;
5915 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
5917 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
5919 if (!graphics
|| !x
|| !y
)
5920 return InvalidParameter
;
5922 *x
= graphics
->origin_x
;
5923 *y
= graphics
->origin_y
;
5928 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
5930 TRACE("(%p, %d)\n", graphics
, mode
);
5933 return InvalidParameter
;
5938 graphics
->smoothing
= mode
;
5943 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
5945 TRACE("(%p, %d)\n", graphics
, contrast
);
5948 return InvalidParameter
;
5950 graphics
->textcontrast
= contrast
;
5955 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
5956 TextRenderingHint hint
)
5958 TRACE("(%p, %d)\n", graphics
, hint
);
5960 if(!graphics
|| hint
> TextRenderingHintClearTypeGridFit
)
5961 return InvalidParameter
;
5966 graphics
->texthint
= hint
;
5971 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
5975 TRACE("(%p, %p)\n", graphics
, matrix
);
5977 if(!graphics
|| !matrix
)
5978 return InvalidParameter
;
5983 TRACE("%f,%f,%f,%f,%f,%f\n",
5984 matrix
->matrix
[0], matrix
->matrix
[1], matrix
->matrix
[2],
5985 matrix
->matrix
[3], matrix
->matrix
[4], matrix
->matrix
[5]);
5987 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
5988 stat
= METAFILE_SetWorldTransform((GpMetafile
*)graphics
->image
, matrix
);
5994 graphics
->worldtrans
= *matrix
;
5999 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
6000 REAL dy
, GpMatrixOrder order
)
6004 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
6007 return InvalidParameter
;
6012 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6013 stat
= METAFILE_TranslateWorldTransform((GpMetafile
*)graphics
->image
, dx
, dy
, order
);
6019 return GdipTranslateMatrix(&graphics
->worldtrans
, dx
, dy
, order
);
6022 /*****************************************************************************
6023 * GdipSetClipHrgn [GDIPLUS.@]
6025 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
6030 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
6033 return InvalidParameter
;
6038 /* hrgn is already in device units */
6039 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
6043 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6045 GdipDeleteRegion(region
);
6049 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
6054 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
6057 return InvalidParameter
;
6062 status
= GdipClonePath(path
, &clip_path
);
6065 GpMatrix world_to_device
;
6067 get_graphics_transform(graphics
, CoordinateSpaceDevice
,
6068 CoordinateSpaceWorld
, &world_to_device
);
6069 status
= GdipTransformPath(clip_path
, &world_to_device
);
6071 GdipCombineRegionPath(graphics
->clip
, clip_path
, mode
);
6073 GdipDeletePath(clip_path
);
6078 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
6079 REAL width
, REAL height
,
6086 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6089 return InvalidParameter
;
6094 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6096 status
= METAFILE_SetClipRect((GpMetafile
*)graphics
->image
, x
, y
, width
, height
, mode
);
6104 rect
.Height
= height
;
6105 status
= GdipCreateRegionRect(&rect
, ®ion
);
6108 GpMatrix world_to_device
;
6110 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6111 status
= GdipTransformRegion(region
, &world_to_device
);
6113 status
= GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
6115 GdipDeleteRegion(region
);
6120 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
6121 INT width
, INT height
,
6124 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
6127 return InvalidParameter
;
6132 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
6135 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
6141 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
6143 if(!graphics
|| !region
)
6144 return InvalidParameter
;
6149 status
= GdipCloneRegion(region
, &clip
);
6152 GpMatrix world_to_device
;
6154 get_graphics_transform(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &world_to_device
);
6155 status
= GdipTransformRegion(clip
, &world_to_device
);
6157 status
= GdipCombineRegionRegion(graphics
->clip
, clip
, mode
);
6159 GdipDeleteRegion(clip
);
6164 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
6170 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
6172 if(!graphics
|| !pen
|| count
<=0)
6173 return InvalidParameter
;
6178 status
= GdipCreatePath(FillModeAlternate
, &path
);
6179 if (status
!= Ok
) return status
;
6181 status
= GdipAddPathPolygon(path
, points
, count
);
6183 status
= GdipDrawPath(graphics
, pen
, path
);
6185 GdipDeletePath(path
);
6190 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
6197 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
6199 if(count
<=0) return InvalidParameter
;
6200 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6202 for(i
= 0;i
< count
; i
++){
6203 ptf
[i
].X
= (REAL
)points
[i
].X
;
6204 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
6207 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
6213 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
6215 TRACE("(%p, %p)\n", graphics
, dpi
);
6217 if(!graphics
|| !dpi
)
6218 return InvalidParameter
;
6223 *dpi
= graphics
->xres
;
6227 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
6229 TRACE("(%p, %p)\n", graphics
, dpi
);
6231 if(!graphics
|| !dpi
)
6232 return InvalidParameter
;
6237 *dpi
= graphics
->yres
;
6241 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
6242 GpMatrixOrder order
)
6247 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
6249 if(!graphics
|| !matrix
)
6250 return InvalidParameter
;
6255 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
) {
6256 ret
= METAFILE_MultiplyWorldTransform((GpMetafile
*)graphics
->image
, matrix
, order
);
6262 m
= graphics
->worldtrans
;
6264 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
6266 graphics
->worldtrans
= m
;
6271 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
6272 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
6274 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
6278 TRACE("(%p, %p)\n", graphics
, hdc
);
6280 if(!graphics
|| !hdc
)
6281 return InvalidParameter
;
6286 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6288 stat
= METAFILE_GetDC((GpMetafile
*)graphics
->image
, hdc
);
6290 else if (!graphics
->hdc
||
6291 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
6293 /* Create a fake HDC and fill it with a constant color. */
6297 BITMAPINFOHEADER bmih
;
6300 stat
= get_graphics_bounds(graphics
, &bounds
);
6304 graphics
->temp_hbitmap_width
= bounds
.Width
;
6305 graphics
->temp_hbitmap_height
= bounds
.Height
;
6307 bmih
.biSize
= sizeof(bmih
);
6308 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
6309 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
6311 bmih
.biBitCount
= 32;
6312 bmih
.biCompression
= BI_RGB
;
6313 bmih
.biSizeImage
= 0;
6314 bmih
.biXPelsPerMeter
= 0;
6315 bmih
.biYPelsPerMeter
= 0;
6317 bmih
.biClrImportant
= 0;
6319 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
6320 (void**)&graphics
->temp_bits
, NULL
, 0);
6322 return GenericError
;
6324 temp_hdc
= CreateCompatibleDC(0);
6327 DeleteObject(hbitmap
);
6328 return GenericError
;
6331 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6332 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
6334 SelectObject(temp_hdc
, hbitmap
);
6336 graphics
->temp_hbitmap
= hbitmap
;
6337 *hdc
= graphics
->temp_hdc
= temp_hdc
;
6341 *hdc
= graphics
->hdc
;
6345 graphics
->busy
= TRUE
;
6350 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
6354 TRACE("(%p, %p)\n", graphics
, hdc
);
6356 if(!graphics
|| !hdc
|| !graphics
->busy
)
6357 return InvalidParameter
;
6359 if (graphics
->image
&& graphics
->image
->type
== ImageTypeMetafile
)
6361 stat
= METAFILE_ReleaseDC((GpMetafile
*)graphics
->image
, hdc
);
6363 else if (graphics
->temp_hdc
== hdc
)
6368 /* Find the pixels that have changed, and mark them as opaque. */
6369 pos
= (DWORD
*)graphics
->temp_bits
;
6370 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
6372 if (*pos
!= DC_BACKGROUND_KEY
)
6379 /* Write the changed pixels to the real target. */
6380 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
6381 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
6382 graphics
->temp_hbitmap_width
* 4, PixelFormat32bppARGB
);
6385 DeleteDC(graphics
->temp_hdc
);
6386 DeleteObject(graphics
->temp_hbitmap
);
6387 graphics
->temp_hdc
= NULL
;
6388 graphics
->temp_hbitmap
= NULL
;
6390 else if (hdc
!= graphics
->hdc
)
6392 stat
= InvalidParameter
;
6396 graphics
->busy
= FALSE
;
6401 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
6405 GpMatrix device_to_world
;
6407 TRACE("(%p, %p)\n", graphics
, region
);
6409 if(!graphics
|| !region
)
6410 return InvalidParameter
;
6415 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
6418 get_graphics_transform(graphics
, CoordinateSpaceWorld
, CoordinateSpaceDevice
, &device_to_world
);
6419 status
= GdipTransformRegion(clip
, &device_to_world
);
6422 GdipDeleteRegion(clip
);
6426 /* free everything except root node and header */
6427 delete_element(®ion
->node
);
6428 memcpy(region
, clip
, sizeof(GpRegion
));
6434 GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6435 GpCoordinateSpace src_space
, GpMatrix
*matrix
)
6438 REAL scale_x
, scale_y
;
6440 GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
6442 if (dst_space
!= src_space
)
6444 scale_x
= units_to_pixels(1.0, graphics
->unit
, graphics
->xres
);
6445 scale_y
= units_to_pixels(1.0, graphics
->unit
, graphics
->yres
);
6447 if(graphics
->unit
!= UnitDisplay
)
6449 scale_x
*= graphics
->scale
;
6450 scale_y
*= graphics
->scale
;
6453 /* transform from src_space to CoordinateSpacePage */
6456 case CoordinateSpaceWorld
:
6457 GdipMultiplyMatrix(matrix
, &graphics
->worldtrans
, MatrixOrderAppend
);
6459 case CoordinateSpacePage
:
6461 case CoordinateSpaceDevice
:
6462 GdipScaleMatrix(matrix
, 1.0/scale_x
, 1.0/scale_y
, MatrixOrderAppend
);
6466 /* transform from CoordinateSpacePage to dst_space */
6469 case CoordinateSpaceWorld
:
6471 GpMatrix inverted_transform
= graphics
->worldtrans
;
6472 stat
= GdipInvertMatrix(&inverted_transform
);
6474 GdipMultiplyMatrix(matrix
, &inverted_transform
, MatrixOrderAppend
);
6477 case CoordinateSpacePage
:
6479 case CoordinateSpaceDevice
:
6480 GdipScaleMatrix(matrix
, scale_x
, scale_y
, MatrixOrderAppend
);
6487 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6488 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
6493 if(!graphics
|| !points
|| count
<= 0)
6494 return InvalidParameter
;
6499 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6501 if (src_space
== dst_space
) return Ok
;
6503 stat
= get_graphics_transform(graphics
, dst_space
, src_space
, &matrix
);
6504 if (stat
!= Ok
) return stat
;
6506 return GdipTransformMatrixPoints(&matrix
, points
, count
);
6509 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
6510 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
6516 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
6519 return InvalidParameter
;
6521 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
6525 for(i
= 0; i
< count
; i
++){
6526 pointsF
[i
].X
= (REAL
)points
[i
].X
;
6527 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
6530 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
6533 for(i
= 0; i
< count
; i
++){
6534 points
[i
].X
= gdip_round(pointsF
[i
].X
);
6535 points
[i
].Y
= gdip_round(pointsF
[i
].Y
);
6542 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
6554 /*****************************************************************************
6555 * GdipTranslateClip [GDIPLUS.@]
6557 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
6559 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
6562 return InvalidParameter
;
6567 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
6570 /*****************************************************************************
6571 * GdipTranslateClipI [GDIPLUS.@]
6573 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
6575 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
6578 return InvalidParameter
;
6583 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
6587 /*****************************************************************************
6588 * GdipMeasureDriverString [GDIPLUS.@]
6590 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6591 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
6592 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
6594 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6597 REAL min_x
, min_y
, max_x
, max_y
, x
, y
;
6599 TEXTMETRICW textmetric
;
6600 const WORD
*glyph_indices
;
6601 WORD
*dynamic_glyph_indices
=NULL
;
6602 REAL rel_width
, rel_height
, ascent
, descent
;
6605 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
6607 if (!graphics
|| !text
|| !font
|| !positions
|| !boundingBox
)
6608 return InvalidParameter
;
6611 length
= strlenW(text
);
6615 boundingBox
->X
= 0.0;
6616 boundingBox
->Y
= 0.0;
6617 boundingBox
->Width
= 0.0;
6618 boundingBox
->Height
= 0.0;
6621 if (flags
& unsupported_flags
)
6622 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6624 get_font_hfont(graphics
, font
, NULL
, &hfont
, matrix
);
6626 hdc
= CreateCompatibleDC(0);
6627 SelectObject(hdc
, hfont
);
6629 GetTextMetricsW(hdc
, &textmetric
);
6639 GpMatrix xform
= *matrix
;
6640 GdipTransformMatrixPoints(&xform
, pt
, 3);
6642 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
6643 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
6644 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
6645 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
6646 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
6648 if (flags
& DriverStringOptionsCmapLookup
)
6650 glyph_indices
= dynamic_glyph_indices
= heap_alloc_zero(sizeof(WORD
) * length
);
6654 DeleteObject(hfont
);
6658 GetGlyphIndicesW(hdc
, text
, length
, dynamic_glyph_indices
, 0);
6661 glyph_indices
= text
;
6663 min_x
= max_x
= x
= positions
[0].X
;
6664 min_y
= max_y
= y
= positions
[0].Y
;
6666 ascent
= textmetric
.tmAscent
/ rel_height
;
6667 descent
= textmetric
.tmDescent
/ rel_height
;
6669 for (i
=0; i
<length
; i
++)
6674 if (!(flags
& DriverStringOptionsRealizedAdvance
))
6680 GetCharABCWidthsW(hdc
, glyph_indices
[i
], glyph_indices
[i
], &abc
);
6681 char_width
= abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
6683 if (min_y
> y
- ascent
) min_y
= y
- ascent
;
6684 if (max_y
< y
+ descent
) max_y
= y
+ descent
;
6685 if (min_x
> x
) min_x
= x
;
6687 x
+= char_width
/ rel_width
;
6689 if (max_x
< x
) max_x
= x
;
6692 heap_free(dynamic_glyph_indices
);
6694 DeleteObject(hfont
);
6696 boundingBox
->X
= min_x
;
6697 boundingBox
->Y
= min_y
;
6698 boundingBox
->Width
= max_x
- min_x
;
6699 boundingBox
->Height
= max_y
- min_y
;
6704 static GpStatus
GDI32_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6705 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6706 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6707 INT flags
, GDIPCONST GpMatrix
*matrix
)
6709 static const INT unsupported_flags
= ~(DriverStringOptionsRealizedAdvance
|DriverStringOptionsCmapLookup
);
6717 if (flags
& unsupported_flags
)
6718 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6720 if (!(flags
& DriverStringOptionsCmapLookup
))
6721 eto_flags
|= ETO_GLYPH_INDEX
;
6723 save_state
= SaveDC(graphics
->hdc
);
6724 SetBkMode(graphics
->hdc
, TRANSPARENT
);
6725 SetTextColor(graphics
->hdc
, get_gdi_brush_color(brush
));
6727 status
= get_clip_hrgn(graphics
, &hrgn
);
6729 if (status
== Ok
&& hrgn
)
6731 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
6736 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, &pt
, 1);
6738 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6739 SelectObject(graphics
->hdc
, hfont
);
6741 SetTextAlign(graphics
->hdc
, TA_BASELINE
|TA_LEFT
);
6743 ExtTextOutW(graphics
->hdc
, gdip_round(pt
.X
), gdip_round(pt
.Y
), eto_flags
, NULL
, text
, length
, NULL
);
6745 RestoreDC(graphics
->hdc
, save_state
);
6747 DeleteObject(hfont
);
6752 static GpStatus
SOFTWARE_GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6753 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6754 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6755 INT flags
, GDIPCONST GpMatrix
*matrix
)
6757 static const INT unsupported_flags
= ~(DriverStringOptionsCmapLookup
|DriverStringOptionsRealizedAdvance
);
6759 PointF
*real_positions
, real_position
;
6763 int min_x
=INT_MAX
, min_y
=INT_MAX
, max_x
=INT_MIN
, max_y
=INT_MIN
, i
, x
, y
;
6764 DWORD max_glyphsize
=0;
6765 GLYPHMETRICS glyphmetrics
;
6766 static const MAT2 identity
= {{0,1}, {0,0}, {0,0}, {0,1}};
6769 int text_mask_stride
;
6771 int pixel_data_stride
;
6773 UINT ggo_flags
= GGO_GRAY8_BITMAP
;
6778 if (!(flags
& DriverStringOptionsCmapLookup
))
6779 ggo_flags
|= GGO_GLYPH_INDEX
;
6781 if (flags
& unsupported_flags
)
6782 FIXME("Ignoring flags %x\n", flags
& unsupported_flags
);
6784 pti
= heap_alloc_zero(sizeof(POINT
) * length
);
6788 if (flags
& DriverStringOptionsRealizedAdvance
)
6790 real_position
= positions
[0];
6792 transform_and_round_points(graphics
, pti
, &real_position
, 1);
6796 real_positions
= heap_alloc_zero(sizeof(PointF
) * length
);
6797 if (!real_positions
)
6803 memcpy(real_positions
, positions
, sizeof(PointF
) * length
);
6805 transform_and_round_points(graphics
, pti
, real_positions
, length
);
6807 heap_free(real_positions
);
6810 get_font_hfont(graphics
, font
, format
, &hfont
, matrix
);
6812 hdc
= CreateCompatibleDC(0);
6813 SelectObject(hdc
, hfont
);
6815 /* Get the boundaries of the text to be drawn */
6816 for (i
=0; i
<length
; i
++)
6819 int left
, top
, right
, bottom
;
6821 glyphsize
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6822 &glyphmetrics
, 0, NULL
, &identity
);
6824 if (glyphsize
== GDI_ERROR
)
6826 ERR("GetGlyphOutlineW failed\n");
6829 DeleteObject(hfont
);
6830 return GenericError
;
6833 if (glyphsize
> max_glyphsize
)
6834 max_glyphsize
= glyphsize
;
6838 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6839 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6840 right
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
+ glyphmetrics
.gmBlackBoxX
;
6841 bottom
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
+ glyphmetrics
.gmBlackBoxY
;
6843 if (left
< min_x
) min_x
= left
;
6844 if (top
< min_y
) min_y
= top
;
6845 if (right
> max_x
) max_x
= right
;
6846 if (bottom
> max_y
) max_y
= bottom
;
6849 if (i
+1 < length
&& (flags
& DriverStringOptionsRealizedAdvance
) == DriverStringOptionsRealizedAdvance
)
6851 pti
[i
+1].x
= pti
[i
].x
+ glyphmetrics
.gmCellIncX
;
6852 pti
[i
+1].y
= pti
[i
].y
+ glyphmetrics
.gmCellIncY
;
6856 if (max_glyphsize
== 0)
6857 /* Nothing to draw. */
6860 glyph_mask
= heap_alloc_zero(max_glyphsize
);
6861 text_mask
= heap_alloc_zero((max_x
- min_x
) * (max_y
- min_y
));
6862 text_mask_stride
= max_x
- min_x
;
6864 if (!(glyph_mask
&& text_mask
))
6866 heap_free(glyph_mask
);
6867 heap_free(text_mask
);
6870 DeleteObject(hfont
);
6874 /* Generate a mask for the text */
6875 for (i
=0; i
<length
; i
++)
6878 int left
, top
, stride
;
6880 ret
= GetGlyphOutlineW(hdc
, text
[i
], ggo_flags
,
6881 &glyphmetrics
, max_glyphsize
, glyph_mask
, &identity
);
6883 if (ret
== GDI_ERROR
|| ret
== 0)
6884 continue; /* empty glyph */
6886 left
= pti
[i
].x
+ glyphmetrics
.gmptGlyphOrigin
.x
;
6887 top
= pti
[i
].y
- glyphmetrics
.gmptGlyphOrigin
.y
;
6888 stride
= (glyphmetrics
.gmBlackBoxX
+ 3) & (~3);
6890 for (y
=0; y
<glyphmetrics
.gmBlackBoxY
; y
++)
6892 BYTE
*glyph_val
= glyph_mask
+ y
* stride
;
6893 BYTE
*text_val
= text_mask
+ (left
- min_x
) + (top
- min_y
+ y
) * text_mask_stride
;
6894 for (x
=0; x
<glyphmetrics
.gmBlackBoxX
; x
++)
6896 *text_val
= min(64, *text_val
+ *glyph_val
);
6905 DeleteObject(hfont
);
6906 heap_free(glyph_mask
);
6908 /* get the brush data */
6909 pixel_data
= heap_alloc_zero(4 * (max_x
- min_x
) * (max_y
- min_y
));
6912 heap_free(text_mask
);
6916 pixel_area
.X
= min_x
;
6917 pixel_area
.Y
= min_y
;
6918 pixel_area
.Width
= max_x
- min_x
;
6919 pixel_area
.Height
= max_y
- min_y
;
6920 pixel_data_stride
= pixel_area
.Width
* 4;
6922 stat
= brush_fill_pixels(graphics
, (GpBrush
*)brush
, (DWORD
*)pixel_data
, &pixel_area
, pixel_area
.Width
);
6925 heap_free(text_mask
);
6926 heap_free(pixel_data
);
6930 /* multiply the brush data by the mask */
6931 for (y
=0; y
<pixel_area
.Height
; y
++)
6933 BYTE
*text_val
= text_mask
+ text_mask_stride
* y
;
6934 BYTE
*pixel_val
= pixel_data
+ pixel_data_stride
* y
+ 3;
6935 for (x
=0; x
<pixel_area
.Width
; x
++)
6937 *pixel_val
= (*pixel_val
) * (*text_val
) / 64;
6943 heap_free(text_mask
);
6945 /* draw the result */
6946 stat
= alpha_blend_pixels(graphics
, min_x
, min_y
, pixel_data
, pixel_area
.Width
,
6947 pixel_area
.Height
, pixel_data_stride
, PixelFormat32bppARGB
);
6949 heap_free(pixel_data
);
6954 static GpStatus
draw_driver_string(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6955 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
,
6956 GDIPCONST GpBrush
*brush
, GDIPCONST PointF
*positions
,
6957 INT flags
, GDIPCONST GpMatrix
*matrix
)
6959 GpStatus stat
= NotImplemented
;
6962 length
= strlenW(text
);
6964 if (graphics
->hdc
&& !graphics
->alpha_hdc
&&
6965 ((flags
& DriverStringOptionsRealizedAdvance
) || length
<= 1) &&
6966 brush
->bt
== BrushTypeSolidColor
&&
6967 (((GpSolidFill
*)brush
)->color
& 0xff000000) == 0xff000000)
6968 stat
= GDI32_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6969 brush
, positions
, flags
, matrix
);
6970 if (stat
== NotImplemented
)
6971 stat
= SOFTWARE_GdipDrawDriverString(graphics
, text
, length
, font
, format
,
6972 brush
, positions
, flags
, matrix
);
6976 /*****************************************************************************
6977 * GdipDrawDriverString [GDIPLUS.@]
6979 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
6980 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
6981 GDIPCONST PointF
*positions
, INT flags
,
6982 GDIPCONST GpMatrix
*matrix
)
6984 TRACE("(%p %s %p %p %p %d %p)\n", graphics
, debugstr_wn(text
, length
), font
, brush
, positions
, flags
, matrix
);
6986 if (!graphics
|| !text
|| !font
|| !brush
|| !positions
)
6987 return InvalidParameter
;
6989 return draw_driver_string(graphics
, text
, length
, font
, NULL
,
6990 brush
, positions
, flags
, matrix
);
6993 /*****************************************************************************
6994 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6996 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
7001 TRACE("(%p, %p)\n", graphics
, res
);
7003 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
7006 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
7009 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
7012 GdipDeleteRegion(rgn
);
7016 GpStatus WINGDIPAPI
GdipResetPageTransform(GpGraphics
*graphics
)
7020 TRACE("(%p) stub\n", graphics
);
7023 FIXME("not implemented\n");
7025 return NotImplemented
;