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 /* Converts angle (in degrees) to x/y coordinates */
50 static void deg2xy(REAL angle
, REAL x_0
, REAL y_0
, REAL
*x
, REAL
*y
)
52 REAL radAngle
, hypotenuse
;
54 radAngle
= deg2rad(angle
);
55 hypotenuse
= 50.0; /* arbitrary */
57 *x
= x_0
+ cos(radAngle
) * hypotenuse
;
58 *y
= y_0
+ sin(radAngle
) * hypotenuse
;
61 /* Converts from gdiplus path point type to gdi path point type. */
62 static BYTE
convert_path_point_type(BYTE type
)
66 switch(type
& PathPointTypePathTypeMask
){
67 case PathPointTypeBezier
:
70 case PathPointTypeLine
:
73 case PathPointTypeStart
:
77 ERR("Bad point type\n");
81 if(type
& PathPointTypeCloseSubpath
)
82 ret
|= PT_CLOSEFIGURE
;
87 static REAL
graphics_res(GpGraphics
*graphics
)
89 if (graphics
->image
) return graphics
->image
->xres
;
90 else return (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
93 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
97 INT save_state
, i
, numdashes
;
99 DWORD dash_array
[MAX_DASHLEN
];
101 save_state
= SaveDC(graphics
->hdc
);
103 EndPath(graphics
->hdc
);
105 if(pen
->unit
== UnitPixel
){
109 /* Get an estimate for the amount the pen width is affected by the world
110 * transform. (This is similar to what some of the wine drivers do.) */
115 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
116 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
117 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
119 width
*= pen
->width
* convert_unit(graphics_res(graphics
),
120 pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
);
123 if(pen
->dash
== DashStyleCustom
){
124 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
126 TRACE("dashes are: ");
127 for(i
= 0; i
< numdashes
; i
++){
128 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
129 TRACE("%d, ", dash_array
[i
]);
131 TRACE("\n and the pen style is %x\n", pen
->style
);
133 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
,
134 numdashes
, dash_array
);
137 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
, 0, NULL
);
139 SelectObject(graphics
->hdc
, gdipen
);
144 static void restore_dc(GpGraphics
*graphics
, INT state
)
146 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
147 RestoreDC(graphics
->hdc
, state
);
150 /* This helper applies all the changes that the points listed in ptf need in
151 * order to be drawn on the device context. In the end, this should include at
153 * -scaling by page unit
154 * -applying world transformation
155 * -converting from float to int
156 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
157 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
158 * gdi to draw, and these functions would irreparably mess with line widths.
160 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
161 GpPointF
*ptf
, INT count
)
167 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
169 /* apply page scale */
170 if(graphics
->unit
!= UnitDisplay
)
171 unitscale
*= graphics
->scale
;
173 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
174 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
175 GdipTransformMatrixPoints(matrix
, ptf
, count
);
176 GdipDeleteMatrix(matrix
);
178 for(i
= 0; i
< count
; i
++){
179 pti
[i
].x
= roundr(ptf
[i
].X
);
180 pti
[i
].y
= roundr(ptf
[i
].Y
);
184 /* Draw non-premultiplied ARGB data to the given graphics object */
185 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
186 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
188 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
190 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
193 for (x
=0; x
<src_width
; x
++)
195 for (y
=0; y
<src_height
; y
++)
197 ARGB dst_color
, src_color
;
198 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
199 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
200 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
209 HBITMAP hbitmap
, old_hbm
=NULL
;
210 BITMAPINFOHEADER bih
;
214 hdc
= CreateCompatibleDC(0);
216 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
217 bih
.biWidth
= src_width
;
218 bih
.biHeight
= -src_height
;
221 bih
.biCompression
= BI_RGB
;
223 bih
.biXPelsPerMeter
= 0;
224 bih
.biYPelsPerMeter
= 0;
226 bih
.biClrImportant
= 0;
228 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
229 (void**)&temp_bits
, NULL
, 0);
231 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
232 4 * src_width
, src
, src_stride
);
234 old_hbm
= SelectObject(hdc
, hbitmap
);
236 bf
.BlendOp
= AC_SRC_OVER
;
238 bf
.SourceConstantAlpha
= 255;
239 bf
.AlphaFormat
= AC_SRC_ALPHA
;
241 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, src_width
, src_height
,
242 hdc
, 0, 0, src_width
, src_height
, bf
);
244 SelectObject(hdc
, old_hbm
);
246 DeleteObject(hbitmap
);
252 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
256 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
257 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
261 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
265 /* clamp to between 0.0 and 1.0, using the wrap mode */
266 if (brush
->wrap
== WrapModeTile
)
268 position
= fmodf(position
, 1.0f
);
269 if (position
< 0.0f
) position
+= 1.0f
;
271 else /* WrapModeFlip* */
273 position
= fmodf(position
, 2.0f
);
274 if (position
< 0.0f
) position
+= 2.0f
;
275 if (position
> 1.0f
) position
= 2.0f
- position
;
278 if (brush
->blendcount
== 1)
283 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
286 /* locate the blend positions surrounding this position */
287 while (position
> brush
->blendpos
[i
])
290 /* interpolate between the blend positions */
291 left_blendpos
= brush
->blendpos
[i
-1];
292 left_blendfac
= brush
->blendfac
[i
-1];
293 right_blendpos
= brush
->blendpos
[i
];
294 right_blendfac
= brush
->blendfac
[i
];
295 range
= right_blendpos
- left_blendpos
;
296 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
297 right_blendfac
* (position
- left_blendpos
)) / range
;
300 if (brush
->pblendcount
== 0)
301 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
305 ARGB left_blendcolor
, right_blendcolor
;
306 REAL left_blendpos
, right_blendpos
;
308 /* locate the blend colors surrounding this position */
309 while (blendfac
> brush
->pblendpos
[i
])
312 /* interpolate between the blend colors */
313 left_blendpos
= brush
->pblendpos
[i
-1];
314 left_blendcolor
= brush
->pblendcolor
[i
-1];
315 right_blendpos
= brush
->pblendpos
[i
];
316 right_blendcolor
= brush
->pblendcolor
[i
];
317 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
318 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
322 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
326 case BrushTypeLinearGradient
:
328 GpLineGradient
*line
= (GpLineGradient
*)brush
;
331 SelectClipPath(graphics
->hdc
, RGN_AND
);
332 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
334 GpPointF endpointsf
[2];
338 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
340 endpointsf
[0] = line
->startpoint
;
341 endpointsf
[1] = line
->endpoint
;
342 transform_and_round_points(graphics
, endpointsi
, endpointsf
, 2);
344 if (abs(endpointsi
[0].x
-endpointsi
[1].x
) > abs(endpointsi
[0].y
-endpointsi
[1].y
))
346 /* vertical-ish gradient */
347 int startx
, endx
; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
348 int startbottomx
; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
351 HBRUSH hbrush
, hprevbrush
;
352 int leftx
, rightx
; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
354 int tilt
; /* horizontal distance covered by a gradient line */
356 startx
= roundr((rc
.top
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
357 endx
= roundr((rc
.top
- endpointsf
[1].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[1].X
);
358 width
= endx
- startx
;
359 startbottomx
= roundr((rc
.bottom
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
360 tilt
= startx
- startbottomx
;
362 if (startx
>= startbottomx
)
365 rightx
= rc
.right
+ tilt
;
369 leftx
= rc
.left
+ tilt
;
373 poly
[0].y
= rc
.bottom
;
376 poly
[3].y
= rc
.bottom
;
378 for (x
=leftx
; x
<=rightx
; x
++)
380 ARGB argb
= blend_line_gradient(line
, (x
-startx
)/(REAL
)width
);
381 col
= ARGB2COLORREF(argb
);
382 hbrush
= CreateSolidBrush(col
);
383 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
384 poly
[0].x
= x
- tilt
- 1;
387 poly
[3].x
= x
- tilt
;
388 Polygon(graphics
->hdc
, poly
, 4);
389 SelectObject(graphics
->hdc
, hprevbrush
);
390 DeleteObject(hbrush
);
393 else if (endpointsi
[0].y
!= endpointsi
[1].y
)
395 /* horizontal-ish gradient */
396 int starty
, endy
; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
397 int startrighty
; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
400 HBRUSH hbrush
, hprevbrush
;
401 int topy
, bottomy
; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
403 int tilt
; /* vertical distance covered by a gradient line */
405 starty
= roundr((rc
.left
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
406 endy
= roundr((rc
.left
- endpointsf
[1].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[1].Y
);
407 height
= endy
- starty
;
408 startrighty
= roundr((rc
.right
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
409 tilt
= starty
- startrighty
;
411 if (starty
>= startrighty
)
414 bottomy
= rc
.bottom
+ tilt
;
418 topy
= rc
.top
+ tilt
;
422 poly
[0].x
= rc
.right
;
425 poly
[3].x
= rc
.right
;
427 for (y
=topy
; y
<=bottomy
; y
++)
429 ARGB argb
= blend_line_gradient(line
, (y
-starty
)/(REAL
)height
);
430 col
= ARGB2COLORREF(argb
);
431 hbrush
= CreateSolidBrush(col
);
432 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
433 poly
[0].y
= y
- tilt
- 1;
436 poly
[3].y
= y
- tilt
;
437 Polygon(graphics
->hdc
, poly
, 4);
438 SelectObject(graphics
->hdc
, hprevbrush
);
439 DeleteObject(hbrush
);
442 /* else startpoint == endpoint */
446 case BrushTypeSolidColor
:
448 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
452 /* partially transparent fill */
454 SelectClipPath(graphics
->hdc
, RGN_AND
);
455 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
457 HDC hdc
= CreateCompatibleDC(NULL
);
463 oldbmp
= SelectObject(hdc
, fill
->bmp
);
465 bf
.BlendOp
= AC_SRC_OVER
;
467 bf
.SourceConstantAlpha
= 255;
468 bf
.AlphaFormat
= AC_SRC_ALPHA
;
470 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
472 SelectObject(hdc
, oldbmp
);
478 /* else fall through */
481 SelectObject(graphics
->hdc
, brush
->gdibrush
);
482 FillPath(graphics
->hdc
);
487 /* GdipDrawPie/GdipFillPie helper function */
488 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
489 REAL height
, REAL startAngle
, REAL sweepAngle
)
496 ptf
[1].X
= x
+ width
;
497 ptf
[1].Y
= y
+ height
;
499 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
500 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
502 transform_and_round_points(graphics
, pti
, ptf
, 4);
504 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
505 pti
[2].y
, pti
[3].x
, pti
[3].y
);
508 /* Draws the linecap the specified color and size on the hdc. The linecap is in
509 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
510 * should not be called on an hdc that has a path you care about. */
511 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
512 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
514 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
515 GpMatrix
*matrix
= NULL
;
518 PointF ptf
[4], *custptf
= NULL
;
519 POINT pt
[4], *custpt
= NULL
;
521 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
526 if((x1
== x2
) && (y1
== y2
))
529 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
531 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
533 brush
= CreateSolidBrush(color
);
534 lb
.lbStyle
= BS_SOLID
;
537 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
538 PS_JOIN_MITER
, 1, &lb
, 0,
540 oldbrush
= SelectObject(graphics
->hdc
, brush
);
541 oldpen
= SelectObject(graphics
->hdc
, pen
);
548 case LineCapSquareAnchor
:
549 case LineCapDiamondAnchor
:
550 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
551 if(cap
== LineCapDiamondAnchor
){
552 dsmall
= cos(theta
+ M_PI_2
) * size
;
553 dbig
= sin(theta
+ M_PI_2
) * size
;
556 dsmall
= cos(theta
+ M_PI_4
) * size
;
557 dbig
= sin(theta
+ M_PI_4
) * size
;
560 ptf
[0].X
= x2
- dsmall
;
561 ptf
[1].X
= x2
+ dbig
;
563 ptf
[0].Y
= y2
- dbig
;
564 ptf
[3].Y
= y2
+ dsmall
;
566 ptf
[1].Y
= y2
- dsmall
;
567 ptf
[2].Y
= y2
+ dbig
;
569 ptf
[3].X
= x2
- dbig
;
570 ptf
[2].X
= x2
+ dsmall
;
572 transform_and_round_points(graphics
, pt
, ptf
, 4);
573 Polygon(graphics
->hdc
, pt
, 4);
576 case LineCapArrowAnchor
:
577 size
= size
* 4.0 / sqrt(3.0);
579 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
580 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
585 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
586 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
594 transform_and_round_points(graphics
, pt
, ptf
, 3);
595 Polygon(graphics
->hdc
, pt
, 3);
598 case LineCapRoundAnchor
:
599 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
606 transform_and_round_points(graphics
, pt
, ptf
, 2);
607 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
610 case LineCapTriangle
:
612 dx
= cos(M_PI_2
+ theta
) * size
;
613 dy
= sin(M_PI_2
+ theta
) * size
;
620 dx
= cos(theta
) * size
;
621 dy
= sin(theta
) * size
;
626 transform_and_round_points(graphics
, pt
, ptf
, 3);
627 Polygon(graphics
->hdc
, pt
, 3);
631 dx
= dy
= size
/ 2.0;
638 dx
= -cos(M_PI_2
+ theta
) * size
;
639 dy
= -sin(M_PI_2
+ theta
) * size
;
646 transform_and_round_points(graphics
, pt
, ptf
, 4);
647 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
648 pt
[2].y
, pt
[3].x
, pt
[3].y
);
655 count
= custom
->pathdata
.Count
;
656 custptf
= GdipAlloc(count
* sizeof(PointF
));
657 custpt
= GdipAlloc(count
* sizeof(POINT
));
658 tp
= GdipAlloc(count
);
660 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
663 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
665 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
666 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
668 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
669 GdipTransformMatrixPoints(matrix
, custptf
, count
);
671 transform_and_round_points(graphics
, custpt
, custptf
, count
);
673 for(i
= 0; i
< count
; i
++)
674 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
677 BeginPath(graphics
->hdc
);
678 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
679 EndPath(graphics
->hdc
);
680 StrokeAndFillPath(graphics
->hdc
);
683 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
689 GdipDeleteMatrix(matrix
);
696 SelectObject(graphics
->hdc
, oldbrush
);
697 SelectObject(graphics
->hdc
, oldpen
);
703 /* Shortens the line by the given percent by changing x2, y2.
704 * If percent is > 1.0 then the line will change direction.
705 * If percent is negative it can lengthen the line. */
706 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
708 REAL dist
, theta
, dx
, dy
;
710 if((y1
== *y2
) && (x1
== *x2
))
713 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
714 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
715 dx
= cos(theta
) * dist
;
716 dy
= sin(theta
) * dist
;
722 /* Shortens the line by the given amount by changing x2, y2.
723 * If the amount is greater than the distance, the line will become length 0.
724 * If the amount is negative, it can lengthen the line. */
725 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
727 REAL dx
, dy
, percent
;
731 if(dx
== 0 && dy
== 0)
734 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
741 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
744 /* Draws lines between the given points, and if caps is true then draws an endcap
745 * at the end of the last line. */
746 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
747 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
750 GpPointF
*ptcopy
= NULL
;
751 GpStatus status
= GenericError
;
756 pti
= GdipAlloc(count
* sizeof(POINT
));
757 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
760 status
= OutOfMemory
;
764 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
767 if(pen
->endcap
== LineCapArrowAnchor
)
768 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
769 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
770 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
771 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
772 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
773 pen
->customend
->inset
* pen
->width
);
775 if(pen
->startcap
== LineCapArrowAnchor
)
776 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
777 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
778 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
779 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
780 &ptcopy
[0].X
, &ptcopy
[0].Y
,
781 pen
->customstart
->inset
* pen
->width
);
783 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
784 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
785 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
786 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
789 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
791 if(Polyline(graphics
->hdc
, pti
, count
))
801 /* Conducts a linear search to find the bezier points that will back off
802 * the endpoint of the curve by a distance of amt. Linear search works
803 * better than binary in this case because there are multiple solutions,
804 * and binary searches often find a bad one. I don't think this is what
805 * Windows does but short of rendering the bezier without GDI's help it's
806 * the best we can do. If rev then work from the start of the passed points
807 * instead of the end. */
808 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
811 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
812 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
821 origx
= pt
[fourth
].X
;
822 origy
= pt
[fourth
].Y
;
823 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
825 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
826 /* reset bezier points to original values */
827 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
828 /* Perform magic on bezier points. Order is important here.*/
829 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
830 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
831 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
832 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
833 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
834 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
836 dx
= pt
[fourth
].X
- origx
;
837 dy
= pt
[fourth
].Y
- origy
;
839 diff
= sqrt(dx
* dx
+ dy
* dy
);
840 percent
+= 0.0005 * amt
;
844 /* Draws bezier curves between given points, and if caps is true then draws an
845 * endcap at the end of the last line. */
846 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
847 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
851 GpStatus status
= GenericError
;
856 pti
= GdipAlloc(count
* sizeof(POINT
));
857 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
860 status
= OutOfMemory
;
864 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
867 if(pen
->endcap
== LineCapArrowAnchor
)
868 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
869 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
870 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
873 if(pen
->startcap
== LineCapArrowAnchor
)
874 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
875 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
876 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
878 /* the direction of the line cap is parallel to the direction at the
879 * end of the bezier (which, if it has been shortened, is not the same
880 * as the direction from pt[count-2] to pt[count-1]) */
881 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
882 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
883 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
884 pt
[count
- 1].X
, pt
[count
- 1].Y
);
886 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
887 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
888 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
891 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
893 PolyBezier(graphics
->hdc
, pti
, count
);
904 /* Draws a combination of bezier curves and lines between points. */
905 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
906 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
908 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
909 BYTE
*tp
= GdipAlloc(count
);
910 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
912 GpStatus status
= GenericError
;
918 if(!pti
|| !tp
|| !ptcopy
){
919 status
= OutOfMemory
;
923 for(i
= 1; i
< count
; i
++){
924 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
925 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
926 || !(types
[i
+ 1] & PathPointTypeBezier
)){
927 ERR("Bad bezier points\n");
934 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
936 /* If we are drawing caps, go through the points and adjust them accordingly,
937 * and draw the caps. */
939 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
940 case PathPointTypeBezier
:
941 if(pen
->endcap
== LineCapArrowAnchor
)
942 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
943 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
944 shorten_bezier_amt(&ptcopy
[count
- 4],
945 pen
->width
* pen
->customend
->inset
, FALSE
);
947 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
948 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
949 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
950 pt
[count
- 1].X
, pt
[count
- 1].Y
);
953 case PathPointTypeLine
:
954 if(pen
->endcap
== LineCapArrowAnchor
)
955 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
956 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
958 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
959 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
960 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
961 pen
->customend
->inset
* pen
->width
);
963 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
964 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
969 ERR("Bad path last point\n");
973 /* Find start of points */
974 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
975 == PathPointTypeStart
); j
++);
977 switch(types
[j
] & PathPointTypePathTypeMask
){
978 case PathPointTypeBezier
:
979 if(pen
->startcap
== LineCapArrowAnchor
)
980 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
981 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
982 shorten_bezier_amt(&ptcopy
[j
- 1],
983 pen
->width
* pen
->customstart
->inset
, TRUE
);
985 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
986 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
987 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
988 pt
[j
- 1].X
, pt
[j
- 1].Y
);
991 case PathPointTypeLine
:
992 if(pen
->startcap
== LineCapArrowAnchor
)
993 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
994 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
996 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
997 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
998 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
999 pen
->customstart
->inset
* pen
->width
);
1001 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1002 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1007 ERR("Bad path points\n");
1012 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1014 for(i
= 0; i
< count
; i
++){
1015 tp
[i
] = convert_path_point_type(types
[i
]);
1018 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1030 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1034 BeginPath(graphics
->hdc
);
1035 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1036 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1037 EndPath(graphics
->hdc
);
1041 typedef struct _GraphicsContainerItem
{
1043 GraphicsContainer contid
;
1045 SmoothingMode smoothing
;
1046 CompositingQuality compqual
;
1047 InterpolationMode interpolation
;
1048 CompositingMode compmode
;
1049 TextRenderingHint texthint
;
1052 PixelOffsetMode pixeloffset
;
1054 GpMatrix
* worldtrans
;
1056 } GraphicsContainerItem
;
1058 static GpStatus
init_container(GraphicsContainerItem
** container
,
1059 GDIPCONST GpGraphics
* graphics
){
1062 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1066 (*container
)->contid
= graphics
->contid
+ 1;
1068 (*container
)->smoothing
= graphics
->smoothing
;
1069 (*container
)->compqual
= graphics
->compqual
;
1070 (*container
)->interpolation
= graphics
->interpolation
;
1071 (*container
)->compmode
= graphics
->compmode
;
1072 (*container
)->texthint
= graphics
->texthint
;
1073 (*container
)->scale
= graphics
->scale
;
1074 (*container
)->unit
= graphics
->unit
;
1075 (*container
)->textcontrast
= graphics
->textcontrast
;
1076 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1078 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1080 GdipFree(*container
);
1085 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1087 GdipDeleteMatrix((*container
)->worldtrans
);
1088 GdipFree(*container
);
1096 static void delete_container(GraphicsContainerItem
* container
){
1097 GdipDeleteMatrix(container
->worldtrans
);
1098 GdipDeleteRegion(container
->clip
);
1099 GdipFree(container
);
1102 static GpStatus
restore_container(GpGraphics
* graphics
,
1103 GDIPCONST GraphicsContainerItem
* container
){
1108 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1112 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1114 GdipDeleteMatrix(newTrans
);
1118 GdipDeleteMatrix(graphics
->worldtrans
);
1119 graphics
->worldtrans
= newTrans
;
1121 GdipDeleteRegion(graphics
->clip
);
1122 graphics
->clip
= newClip
;
1124 graphics
->contid
= container
->contid
- 1;
1126 graphics
->smoothing
= container
->smoothing
;
1127 graphics
->compqual
= container
->compqual
;
1128 graphics
->interpolation
= container
->interpolation
;
1129 graphics
->compmode
= container
->compmode
;
1130 graphics
->texthint
= container
->texthint
;
1131 graphics
->scale
= container
->scale
;
1132 graphics
->unit
= container
->unit
;
1133 graphics
->textcontrast
= container
->textcontrast
;
1134 graphics
->pixeloffset
= container
->pixeloffset
;
1139 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1145 if(graphics
->hwnd
) {
1146 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1147 return GenericError
;
1149 rect
->X
= wnd_rect
.left
;
1150 rect
->Y
= wnd_rect
.top
;
1151 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1152 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1153 }else if (graphics
->image
){
1154 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1155 if (stat
== Ok
&& unit
!= UnitPixel
)
1156 FIXME("need to convert from unit %i\n", unit
);
1160 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1161 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
1167 /* on success, rgn will contain the region of the graphics object which
1168 * is visible after clipping has been applied */
1169 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
1175 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
1178 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
1181 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
1184 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
1187 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
1190 GdipDeleteRegion(tmp
);
1194 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1196 TRACE("(%p, %p)\n", hdc
, graphics
);
1198 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1201 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1205 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1207 if(hDevice
!= NULL
) {
1208 FIXME("Don't know how to handle parameter hDevice\n");
1209 return NotImplemented
;
1215 if(graphics
== NULL
)
1216 return InvalidParameter
;
1218 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1219 if(!*graphics
) return OutOfMemory
;
1221 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1222 GdipFree(*graphics
);
1226 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1227 GdipFree((*graphics
)->worldtrans
);
1228 GdipFree(*graphics
);
1232 (*graphics
)->hdc
= hdc
;
1233 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1234 (*graphics
)->owndc
= FALSE
;
1235 (*graphics
)->smoothing
= SmoothingModeDefault
;
1236 (*graphics
)->compqual
= CompositingQualityDefault
;
1237 (*graphics
)->interpolation
= InterpolationModeDefault
;
1238 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1239 (*graphics
)->compmode
= CompositingModeSourceOver
;
1240 (*graphics
)->unit
= UnitDisplay
;
1241 (*graphics
)->scale
= 1.0;
1242 (*graphics
)->busy
= FALSE
;
1243 (*graphics
)->textcontrast
= 4;
1244 list_init(&(*graphics
)->containers
);
1245 (*graphics
)->contid
= 0;
1247 TRACE("<-- %p\n", *graphics
);
1252 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
1256 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1257 if(!*graphics
) return OutOfMemory
;
1259 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1260 GdipFree(*graphics
);
1264 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1265 GdipFree((*graphics
)->worldtrans
);
1266 GdipFree(*graphics
);
1270 (*graphics
)->hdc
= NULL
;
1271 (*graphics
)->hwnd
= NULL
;
1272 (*graphics
)->owndc
= FALSE
;
1273 (*graphics
)->image
= image
;
1274 (*graphics
)->smoothing
= SmoothingModeDefault
;
1275 (*graphics
)->compqual
= CompositingQualityDefault
;
1276 (*graphics
)->interpolation
= InterpolationModeDefault
;
1277 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1278 (*graphics
)->compmode
= CompositingModeSourceOver
;
1279 (*graphics
)->unit
= UnitDisplay
;
1280 (*graphics
)->scale
= 1.0;
1281 (*graphics
)->busy
= FALSE
;
1282 (*graphics
)->textcontrast
= 4;
1283 list_init(&(*graphics
)->containers
);
1284 (*graphics
)->contid
= 0;
1286 TRACE("<-- %p\n", *graphics
);
1291 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1296 TRACE("(%p, %p)\n", hwnd
, graphics
);
1300 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1302 ReleaseDC(hwnd
, hdc
);
1306 (*graphics
)->hwnd
= hwnd
;
1307 (*graphics
)->owndc
= TRUE
;
1312 /* FIXME: no icm handling */
1313 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
1315 TRACE("(%p, %p)\n", hwnd
, graphics
);
1317 return GdipCreateFromHWND(hwnd
, graphics
);
1320 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
1321 GpMetafile
**metafile
)
1325 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
1327 if(!hemf
|| !metafile
)
1328 return InvalidParameter
;
1331 FIXME("not implemented\n");
1333 return NotImplemented
;
1336 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1337 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1339 IStream
*stream
= NULL
;
1343 GpStatus retval
= Ok
;
1345 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1347 if(!hwmf
|| !metafile
|| !placeable
)
1348 return InvalidParameter
;
1351 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1353 return GenericError
;
1354 copy
= GdipAlloc(read
);
1355 GetMetaFileBitsEx(hwmf
, read
, copy
);
1357 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1360 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1361 copy
= GdipAlloc(read
);
1362 GetEnhMetaFileBits(hemf
, read
, copy
);
1363 DeleteEnhMetaFile(hemf
);
1365 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1366 ERR("could not make stream\n");
1368 retval
= GenericError
;
1372 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1374 retval
= OutOfMemory
;
1378 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1379 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1381 retval
= GenericError
;
1386 (*metafile
)->image
.type
= ImageTypeMetafile
;
1387 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
1388 (*metafile
)->image
.palette_flags
= 0;
1389 (*metafile
)->image
.palette_count
= 0;
1390 (*metafile
)->image
.palette_size
= 0;
1391 (*metafile
)->image
.palette_entries
= NULL
;
1392 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
1393 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
1394 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1395 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Top
) / ((REAL
) placeable
->Inch
);
1396 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1397 - placeable
->BoundingBox
.Left
));
1398 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1399 - placeable
->BoundingBox
.Top
));
1400 (*metafile
)->unit
= UnitPixel
;
1403 DeleteMetaFile(hwmf
);
1405 TRACE("<-- %p\n", *metafile
);
1409 GdipFree(*metafile
);
1410 IStream_Release(stream
);
1414 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1415 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1417 HMETAFILE hmf
= GetMetaFileW(file
);
1419 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1421 if(!hmf
) return InvalidParameter
;
1423 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1426 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
1427 GpMetafile
**metafile
)
1429 FIXME("(%p, %p): stub\n", file
, metafile
);
1430 return NotImplemented
;
1433 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
1434 GpMetafile
**metafile
)
1436 FIXME("(%p, %p): stub\n", stream
, metafile
);
1437 return NotImplemented
;
1440 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1441 UINT access
, IStream
**stream
)
1446 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1448 if(!stream
|| !filename
)
1449 return InvalidParameter
;
1451 if(access
& GENERIC_WRITE
)
1452 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1453 else if(access
& GENERIC_READ
)
1454 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1456 return InvalidParameter
;
1458 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1460 return hresult_to_status(ret
);
1463 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1465 GraphicsContainerItem
*cont
, *next
;
1466 TRACE("(%p)\n", graphics
);
1468 if(!graphics
) return InvalidParameter
;
1469 if(graphics
->busy
) return ObjectBusy
;
1472 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1474 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
1475 list_remove(&cont
->entry
);
1476 delete_container(cont
);
1479 GdipDeleteRegion(graphics
->clip
);
1480 GdipDeleteMatrix(graphics
->worldtrans
);
1486 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1487 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1489 INT save_state
, num_pts
;
1490 GpPointF points
[MAX_ARC_PTS
];
1493 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1494 width
, height
, startAngle
, sweepAngle
);
1496 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1497 return InvalidParameter
;
1504 FIXME("graphics object has no HDC\n");
1508 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1510 save_state
= prepare_dc(graphics
, pen
);
1512 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
1514 restore_dc(graphics
, save_state
);
1519 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1520 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1522 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1523 width
, height
, startAngle
, sweepAngle
);
1525 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1528 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1529 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
1535 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
1536 x2
, y2
, x3
, y3
, x4
, y4
);
1538 if(!graphics
|| !pen
)
1539 return InvalidParameter
;
1546 FIXME("graphics object has no HDC\n");
1559 save_state
= prepare_dc(graphics
, pen
);
1561 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1563 restore_dc(graphics
, save_state
);
1568 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1569 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1575 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1576 x2
, y2
, x3
, y3
, x4
, y4
);
1578 if(!graphics
|| !pen
)
1579 return InvalidParameter
;
1586 FIXME("graphics object has no HDC\n");
1599 save_state
= prepare_dc(graphics
, pen
);
1601 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1603 restore_dc(graphics
, save_state
);
1608 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1609 GDIPCONST GpPointF
*points
, INT count
)
1614 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1616 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1617 return InvalidParameter
;
1622 for(i
= 0; i
< floor(count
/ 4); i
++){
1623 ret
= GdipDrawBezier(graphics
, pen
,
1624 points
[4*i
].X
, points
[4*i
].Y
,
1625 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1626 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1627 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1635 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1636 GDIPCONST GpPoint
*points
, INT count
)
1642 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1644 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1645 return InvalidParameter
;
1650 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1654 for(i
= 0; i
< count
; i
++){
1655 pts
[i
].X
= (REAL
)points
[i
].X
;
1656 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1659 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1666 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1667 GDIPCONST GpPointF
*points
, INT count
)
1669 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1671 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1674 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1675 GDIPCONST GpPoint
*points
, INT count
)
1677 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1679 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1682 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1683 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1688 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1690 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1691 return InvalidParameter
;
1696 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1699 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1701 GdipDeletePath(path
);
1705 stat
= GdipDrawPath(graphics
, pen
, path
);
1707 GdipDeletePath(path
);
1712 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1713 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1719 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1721 if(!points
|| count
<= 0)
1722 return InvalidParameter
;
1724 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1728 for(i
= 0; i
< count
; i
++){
1729 ptf
[i
].X
= (REAL
)points
[i
].X
;
1730 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1733 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1740 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1741 GDIPCONST GpPointF
*points
, INT count
)
1743 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1745 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1748 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1749 GDIPCONST GpPoint
*points
, INT count
)
1755 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1758 return InvalidParameter
;
1760 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1764 for(i
= 0; i
< count
; i
++){
1765 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1766 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1769 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1775 /* Approximates cardinal spline with Bezier curves. */
1776 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1777 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1779 /* PolyBezier expects count*3-2 points. */
1780 INT i
, len_pt
= count
*3-2, save_state
;
1782 REAL x1
, x2
, y1
, y2
;
1785 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1787 if(!graphics
|| !pen
)
1788 return InvalidParameter
;
1794 return InvalidParameter
;
1798 FIXME("graphics object has no HDC\n");
1802 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1806 tension
= tension
* TENSION_CONST
;
1808 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1811 pt
[0].X
= points
[0].X
;
1812 pt
[0].Y
= points
[0].Y
;
1816 for(i
= 0; i
< count
-2; i
++){
1817 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1821 pt
[3*i
+3].X
= points
[i
+1].X
;
1822 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1827 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1828 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1830 pt
[len_pt
-2].X
= x1
;
1831 pt
[len_pt
-2].Y
= y1
;
1832 pt
[len_pt
-1].X
= points
[count
-1].X
;
1833 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1835 save_state
= prepare_dc(graphics
, pen
);
1837 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1840 restore_dc(graphics
, save_state
);
1845 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1846 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1852 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1855 return InvalidParameter
;
1857 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1861 for(i
= 0; i
< count
; i
++){
1862 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1863 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1866 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1872 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
1873 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
1876 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1878 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1879 return InvalidParameter
;
1882 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1885 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
1886 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
1889 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1895 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1896 return InvalidParameter
;
1899 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1902 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1903 REAL y
, REAL width
, REAL height
)
1909 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1911 if(!graphics
|| !pen
)
1912 return InvalidParameter
;
1919 FIXME("graphics object has no HDC\n");
1925 ptf
[1].X
= x
+ width
;
1926 ptf
[1].Y
= y
+ height
;
1928 save_state
= prepare_dc(graphics
, pen
);
1929 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1931 transform_and_round_points(graphics
, pti
, ptf
, 2);
1933 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1935 restore_dc(graphics
, save_state
);
1940 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1941 INT y
, INT width
, INT height
)
1943 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1945 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1949 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1954 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1956 if(!graphics
|| !image
)
1957 return InvalidParameter
;
1959 GdipGetImageWidth(image
, &width
);
1960 GdipGetImageHeight(image
, &height
);
1962 /* FIXME: we should use the graphics and image dpi, somehow */
1964 points
[0].X
= points
[2].X
= x
;
1965 points
[0].Y
= points
[1].Y
= y
;
1966 points
[1].X
= x
+ width
;
1967 points
[2].Y
= y
+ height
;
1969 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
1970 UnitPixel
, NULL
, NULL
, NULL
);
1973 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1976 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1978 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
1981 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
1982 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
1986 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1988 points
[0].X
= points
[2].X
= x
;
1989 points
[0].Y
= points
[1].Y
= y
;
1991 /* FIXME: convert image coordinates to Graphics coordinates? */
1992 points
[1].X
= x
+ srcwidth
;
1993 points
[2].Y
= y
+ srcheight
;
1995 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1996 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
1999 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2000 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2003 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2006 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2007 GDIPCONST GpPointF
*dstpoints
, INT count
)
2009 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
2010 return NotImplemented
;
2013 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2014 GDIPCONST GpPoint
*dstpoints
, INT count
)
2016 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
2017 return NotImplemented
;
2020 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2021 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2022 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2023 DrawImageAbort callback
, VOID
* callbackData
)
2030 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2031 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2034 if(!graphics
|| !image
|| !points
|| count
!= 3)
2035 return InvalidParameter
;
2037 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2038 debugstr_pointf(&points
[2]));
2040 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2041 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2042 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2043 transform_and_round_points(graphics
, pti
, ptf
, 4);
2049 FIXME("graphics object has no HDC\n");
2052 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2053 if(srcUnit
== UnitInch
)
2054 dx
= dy
= (REAL
) INCH_HIMETRIC
;
2055 else if(srcUnit
== UnitPixel
){
2056 dx
= ((REAL
) INCH_HIMETRIC
) /
2057 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
2058 dy
= ((REAL
) INCH_HIMETRIC
) /
2059 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
2062 return NotImplemented
;
2064 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2065 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2066 srcx
* dx
, srcy
* dy
,
2067 srcwidth
* dx
, srcheight
* dy
,
2070 callback(callbackData
);
2071 return GenericError
;
2074 else if (image
->type
== ImageTypeBitmap
)
2076 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2079 if (srcUnit
== UnitInch
)
2080 dx
= dy
= 96.0; /* FIXME: use the image resolution */
2081 else if (srcUnit
== UnitPixel
)
2084 return NotImplemented
;
2086 if (imageAttributes
||
2087 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2088 !((GpBitmap
*)image
)->hbitmap
||
2089 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
)
2094 RECT src_area
, dst_area
;
2095 int i
, x
, y
, stride
;
2096 GpMatrix
*dst_to_src
;
2097 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2100 src_area
.left
= srcx
*dx
;
2101 src_area
.top
= srcy
*dy
;
2102 src_area
.right
= (srcx
+srcwidth
)*dx
;
2103 src_area
.bottom
= (srcy
+srcheight
)*dy
;
2105 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2106 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2109 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2110 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2111 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2112 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2115 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2116 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2117 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2118 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2119 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2120 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2122 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
2123 if (stat
!= Ok
) return stat
;
2125 stat
= GdipInvertMatrix(dst_to_src
);
2128 GdipDeleteMatrix(dst_to_src
);
2132 data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2135 GdipDeleteMatrix(dst_to_src
);
2139 stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2141 if (imageAttributes
&&
2142 (imageAttributes
->wrap
!= WrapModeClamp
||
2143 imageAttributes
->outside_color
!= 0x00000000 ||
2144 imageAttributes
->clamp
))
2148 FIXME("Image wrap mode not implemented\n");
2151 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2153 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2155 GpPointF src_pointf
;
2162 GdipTransformMatrixPoints(dst_to_src
, &src_pointf
, 1);
2164 src_x
= roundr(src_pointf
.X
);
2165 src_y
= roundr(src_pointf
.Y
);
2167 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2169 if (src_x
< src_area
.left
|| src_x
>= src_area
.right
||
2170 src_y
< src_area
.top
|| src_y
>= src_area
.bottom
)
2173 GdipBitmapGetPixel(bitmap
, src_x
, src_y
, src_color
);
2177 GdipDeleteMatrix(dst_to_src
);
2179 if (imageAttributes
)
2181 if (imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
].enabled
||
2182 imageAttributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
2184 const struct color_key
*key
;
2185 BYTE min_blue
, min_green
, min_red
;
2186 BYTE max_blue
, max_green
, max_red
;
2188 if (imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
].enabled
)
2189 key
= &imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
];
2191 key
= &imageAttributes
->colorkeys
[ColorAdjustTypeDefault
];
2193 min_blue
= key
->low
&0xff;
2194 min_green
= (key
->low
>>8)&0xff;
2195 min_red
= (key
->low
>>16)&0xff;
2197 max_blue
= key
->high
&0xff;
2198 max_green
= (key
->high
>>8)&0xff;
2199 max_red
= (key
->high
>>16)&0xff;
2201 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2202 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2205 BYTE blue
, green
, red
;
2206 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2207 blue
= *src_color
&0xff;
2208 green
= (*src_color
>>8)&0xff;
2209 red
= (*src_color
>>16)&0xff;
2210 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
2211 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
2212 *src_color
= 0x00000000;
2216 if (imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
].enabled
||
2217 imageAttributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
2219 const struct color_remap_table
*table
;
2221 if (imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
].enabled
)
2222 table
= &imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
];
2224 table
= &imageAttributes
->colorremaptables
[ColorAdjustTypeDefault
];
2226 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2227 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2230 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2231 for (i
=0; i
<table
->mapsize
; i
++)
2233 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
2235 *src_color
= table
->colormap
[i
].newColor
.Argb
;
2242 if (imageAttributes
->colormatrices
[ColorAdjustTypeBitmap
].enabled
||
2243 imageAttributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
2247 FIXME("Color transforms not implemented\n");
2250 if (imageAttributes
->gamma_enabled
[ColorAdjustTypeBitmap
] ||
2251 imageAttributes
->gamma_enabled
[ColorAdjustTypeDefault
])
2255 FIXME("Gamma adjustment not implemented\n");
2259 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
2260 data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, stride
);
2269 int temp_hdc
=0, temp_bitmap
=0;
2270 HBITMAP hbitmap
, old_hbm
=NULL
;
2272 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
2273 bitmap
->format
== PixelFormat24bppRGB
||
2274 bitmap
->format
== PixelFormat32bppRGB
||
2275 bitmap
->format
== PixelFormat32bppPARGB
))
2277 BITMAPINFOHEADER bih
;
2279 PixelFormat dst_format
;
2281 /* we can't draw a bitmap of this format directly */
2282 hdc
= CreateCompatibleDC(0);
2286 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
2287 bih
.biWidth
= bitmap
->width
;
2288 bih
.biHeight
= -bitmap
->height
;
2290 bih
.biBitCount
= 32;
2291 bih
.biCompression
= BI_RGB
;
2292 bih
.biSizeImage
= 0;
2293 bih
.biXPelsPerMeter
= 0;
2294 bih
.biYPelsPerMeter
= 0;
2296 bih
.biClrImportant
= 0;
2298 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
2299 (void**)&temp_bits
, NULL
, 0);
2301 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2302 dst_format
= PixelFormat32bppPARGB
;
2304 dst_format
= PixelFormat32bppRGB
;
2306 convert_pixels(bitmap
->width
, bitmap
->height
,
2307 bitmap
->width
*4, temp_bits
, dst_format
,
2308 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
2312 hbitmap
= bitmap
->hbitmap
;
2314 temp_hdc
= (hdc
== 0);
2319 if (!hdc
) hdc
= CreateCompatibleDC(0);
2320 old_hbm
= SelectObject(hdc
, hbitmap
);
2323 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2327 bf
.BlendOp
= AC_SRC_OVER
;
2329 bf
.SourceConstantAlpha
= 255;
2330 bf
.AlphaFormat
= AC_SRC_ALPHA
;
2332 GdiAlphaBlend(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2333 hdc
, srcx
*dx
, srcy
*dy
, srcwidth
*dx
, srcheight
*dy
, bf
);
2337 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2338 hdc
, srcx
*dx
, srcy
*dy
, srcwidth
*dx
, srcheight
*dy
, SRCCOPY
);
2343 SelectObject(hdc
, old_hbm
);
2348 DeleteObject(hbitmap
);
2353 ERR("GpImage with no IPicture or HBITMAP?!\n");
2354 return NotImplemented
;
2360 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
2361 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
2362 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2363 DrawImageAbort callback
, VOID
* callbackData
)
2365 GpPointF pointsF
[3];
2368 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
2369 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2372 if(!points
|| count
!=3)
2373 return InvalidParameter
;
2375 for(i
= 0; i
< count
; i
++){
2376 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2377 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2380 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
2381 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
2382 callback
, callbackData
);
2385 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
2386 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
2387 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
2388 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
2389 VOID
* callbackData
)
2393 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2394 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2395 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2399 points
[1].X
= dstx
+ dstwidth
;
2402 points
[2].Y
= dsty
+ dstheight
;
2404 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2405 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2408 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
2409 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
2410 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
2411 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
2412 VOID
* callbackData
)
2416 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2417 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2418 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2422 points
[1].X
= dstx
+ dstwidth
;
2425 points
[2].Y
= dsty
+ dstheight
;
2427 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2428 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2431 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
2432 REAL x
, REAL y
, REAL width
, REAL height
)
2438 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
2440 if(!graphics
|| !image
)
2441 return InvalidParameter
;
2443 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
2447 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
2448 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
2449 unit
, NULL
, NULL
, NULL
);
2452 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
2453 INT x
, INT y
, INT width
, INT height
)
2455 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
2457 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
2460 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2461 REAL y1
, REAL x2
, REAL y2
)
2467 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2469 if(!pen
|| !graphics
)
2470 return InvalidParameter
;
2477 FIXME("graphics object has no HDC\n");
2486 save_state
= prepare_dc(graphics
, pen
);
2488 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2490 restore_dc(graphics
, save_state
);
2495 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2496 INT y1
, INT x2
, INT y2
)
2502 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2504 if(!pen
|| !graphics
)
2505 return InvalidParameter
;
2512 FIXME("graphics object has no HDC\n");
2521 save_state
= prepare_dc(graphics
, pen
);
2523 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2525 restore_dc(graphics
, save_state
);
2530 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2531 GpPointF
*points
, INT count
)
2536 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2538 if(!pen
|| !graphics
|| (count
< 2))
2539 return InvalidParameter
;
2546 FIXME("graphics object has no HDC\n");
2550 save_state
= prepare_dc(graphics
, pen
);
2552 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
2554 restore_dc(graphics
, save_state
);
2559 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2560 GpPoint
*points
, INT count
)
2564 GpPointF
*ptf
= NULL
;
2567 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2569 if(!pen
|| !graphics
|| (count
< 2))
2570 return InvalidParameter
;
2577 FIXME("graphics object has no HDC\n");
2581 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2582 if(!ptf
) return OutOfMemory
;
2584 for(i
= 0; i
< count
; i
++){
2585 ptf
[i
].X
= (REAL
) points
[i
].X
;
2586 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2589 save_state
= prepare_dc(graphics
, pen
);
2591 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
2593 restore_dc(graphics
, save_state
);
2599 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
2604 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
2606 if(!pen
|| !graphics
)
2607 return InvalidParameter
;
2614 FIXME("graphics object has no HDC\n");
2618 save_state
= prepare_dc(graphics
, pen
);
2620 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
2621 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
2623 restore_dc(graphics
, save_state
);
2628 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2629 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2633 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2634 width
, height
, startAngle
, sweepAngle
);
2636 if(!graphics
|| !pen
)
2637 return InvalidParameter
;
2644 FIXME("graphics object has no HDC\n");
2648 save_state
= prepare_dc(graphics
, pen
);
2649 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2651 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2653 restore_dc(graphics
, save_state
);
2658 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2659 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2661 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2662 width
, height
, startAngle
, sweepAngle
);
2664 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2667 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2668 REAL y
, REAL width
, REAL height
)
2674 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2676 if(!pen
|| !graphics
)
2677 return InvalidParameter
;
2684 FIXME("graphics object has no HDC\n");
2690 ptf
[1].X
= x
+ width
;
2692 ptf
[2].X
= x
+ width
;
2693 ptf
[2].Y
= y
+ height
;
2695 ptf
[3].Y
= y
+ height
;
2697 save_state
= prepare_dc(graphics
, pen
);
2698 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2700 transform_and_round_points(graphics
, pti
, ptf
, 4);
2701 Polygon(graphics
->hdc
, pti
, 4);
2703 restore_dc(graphics
, save_state
);
2708 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2709 INT y
, INT width
, INT height
)
2711 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2713 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2716 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
2717 GDIPCONST GpRectF
* rects
, INT count
)
2723 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2725 if(!graphics
|| !pen
|| !rects
|| count
< 1)
2726 return InvalidParameter
;
2733 FIXME("graphics object has no HDC\n");
2737 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
2738 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
2746 for(i
= 0; i
< count
; i
++){
2747 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
2748 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
2749 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
2750 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
2753 save_state
= prepare_dc(graphics
, pen
);
2754 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2756 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
2758 for(i
= 0; i
< count
; i
++)
2759 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
2761 restore_dc(graphics
, save_state
);
2769 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
2770 GDIPCONST GpRect
* rects
, INT count
)
2776 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2778 if(!rects
|| count
<=0)
2779 return InvalidParameter
;
2781 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
2785 for(i
= 0;i
< count
;i
++){
2786 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2787 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2788 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2789 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2792 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
2798 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
2799 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
2804 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2805 count
, tension
, fill
);
2807 if(!graphics
|| !brush
|| !points
)
2808 return InvalidParameter
;
2813 if(count
== 1) /* Do nothing */
2816 stat
= GdipCreatePath(fill
, &path
);
2820 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2822 GdipDeletePath(path
);
2826 stat
= GdipFillPath(graphics
, brush
, path
);
2828 GdipDeletePath(path
);
2832 GdipDeletePath(path
);
2837 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
2838 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2844 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2845 count
, tension
, fill
);
2847 if(!points
|| count
== 0)
2848 return InvalidParameter
;
2850 if(count
== 1) /* Do nothing */
2853 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2857 for(i
= 0;i
< count
;i
++){
2858 ptf
[i
].X
= (REAL
)points
[i
].X
;
2859 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2862 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2869 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
2870 GDIPCONST GpPointF
*points
, INT count
)
2872 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2873 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
2874 0.5f
, FillModeAlternate
);
2877 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
2878 GDIPCONST GpPoint
*points
, INT count
)
2880 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2881 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
2882 0.5f
, FillModeAlternate
);
2885 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2886 REAL y
, REAL width
, REAL height
)
2892 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2894 if(!graphics
|| !brush
)
2895 return InvalidParameter
;
2902 FIXME("graphics object has no HDC\n");
2908 ptf
[1].X
= x
+ width
;
2909 ptf
[1].Y
= y
+ height
;
2911 save_state
= SaveDC(graphics
->hdc
);
2912 EndPath(graphics
->hdc
);
2914 transform_and_round_points(graphics
, pti
, ptf
, 2);
2916 BeginPath(graphics
->hdc
);
2917 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2918 EndPath(graphics
->hdc
);
2920 brush_fill_path(graphics
, brush
);
2922 RestoreDC(graphics
->hdc
, save_state
);
2927 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2928 INT y
, INT width
, INT height
)
2930 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2932 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2935 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2940 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2942 if(!brush
|| !graphics
|| !path
)
2943 return InvalidParameter
;
2950 FIXME("graphics object has no HDC\n");
2954 save_state
= SaveDC(graphics
->hdc
);
2955 EndPath(graphics
->hdc
);
2956 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2959 BeginPath(graphics
->hdc
);
2960 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2961 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2966 EndPath(graphics
->hdc
);
2967 brush_fill_path(graphics
, brush
);
2972 RestoreDC(graphics
->hdc
, save_state
);
2977 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2978 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2982 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2983 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2985 if(!graphics
|| !brush
)
2986 return InvalidParameter
;
2993 FIXME("graphics object has no HDC\n");
2997 save_state
= SaveDC(graphics
->hdc
);
2998 EndPath(graphics
->hdc
);
3000 BeginPath(graphics
->hdc
);
3001 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3002 EndPath(graphics
->hdc
);
3004 brush_fill_path(graphics
, brush
);
3006 RestoreDC(graphics
->hdc
, save_state
);
3011 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3012 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3014 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3015 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3017 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3020 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3021 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3024 GpPointF
*ptf
= NULL
;
3026 GpStatus retval
= Ok
;
3028 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3030 if(!graphics
|| !brush
|| !points
|| !count
)
3031 return InvalidParameter
;
3038 FIXME("graphics object has no HDC\n");
3042 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3043 pti
= GdipAlloc(count
* sizeof(POINT
));
3045 retval
= OutOfMemory
;
3049 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
3051 save_state
= SaveDC(graphics
->hdc
);
3052 EndPath(graphics
->hdc
);
3053 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
3056 transform_and_round_points(graphics
, pti
, ptf
, count
);
3058 BeginPath(graphics
->hdc
);
3059 Polygon(graphics
->hdc
, pti
, count
);
3060 EndPath(graphics
->hdc
);
3062 brush_fill_path(graphics
, brush
);
3064 RestoreDC(graphics
->hdc
, save_state
);
3073 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3074 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3077 GpPointF
*ptf
= NULL
;
3079 GpStatus retval
= Ok
;
3081 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3083 if(!graphics
|| !brush
|| !points
|| !count
)
3084 return InvalidParameter
;
3091 FIXME("graphics object has no HDC\n");
3095 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3096 pti
= GdipAlloc(count
* sizeof(POINT
));
3098 retval
= OutOfMemory
;
3102 for(i
= 0; i
< count
; i
++){
3103 ptf
[i
].X
= (REAL
) points
[i
].X
;
3104 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3107 save_state
= SaveDC(graphics
->hdc
);
3108 EndPath(graphics
->hdc
);
3109 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
3112 transform_and_round_points(graphics
, pti
, ptf
, count
);
3114 BeginPath(graphics
->hdc
);
3115 Polygon(graphics
->hdc
, pti
, count
);
3116 EndPath(graphics
->hdc
);
3118 brush_fill_path(graphics
, brush
);
3120 RestoreDC(graphics
->hdc
, save_state
);
3129 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3130 GDIPCONST GpPointF
*points
, INT count
)
3132 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3134 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3137 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3138 GDIPCONST GpPoint
*points
, INT count
)
3140 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3142 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3145 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3146 REAL x
, REAL y
, REAL width
, REAL height
)
3152 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3154 if(!graphics
|| !brush
)
3155 return InvalidParameter
;
3162 FIXME("graphics object has no HDC\n");
3168 ptf
[1].X
= x
+ width
;
3170 ptf
[2].X
= x
+ width
;
3171 ptf
[2].Y
= y
+ height
;
3173 ptf
[3].Y
= y
+ height
;
3175 save_state
= SaveDC(graphics
->hdc
);
3176 EndPath(graphics
->hdc
);
3178 transform_and_round_points(graphics
, pti
, ptf
, 4);
3180 BeginPath(graphics
->hdc
);
3181 Polygon(graphics
->hdc
, pti
, 4);
3182 EndPath(graphics
->hdc
);
3184 brush_fill_path(graphics
, brush
);
3186 RestoreDC(graphics
->hdc
, save_state
);
3191 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3192 INT x
, INT y
, INT width
, INT height
)
3198 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3200 if(!graphics
|| !brush
)
3201 return InvalidParameter
;
3208 FIXME("graphics object has no HDC\n");
3214 ptf
[1].X
= x
+ width
;
3216 ptf
[2].X
= x
+ width
;
3217 ptf
[2].Y
= y
+ height
;
3219 ptf
[3].Y
= y
+ height
;
3221 save_state
= SaveDC(graphics
->hdc
);
3222 EndPath(graphics
->hdc
);
3224 transform_and_round_points(graphics
, pti
, ptf
, 4);
3226 BeginPath(graphics
->hdc
);
3227 Polygon(graphics
->hdc
, pti
, 4);
3228 EndPath(graphics
->hdc
);
3230 brush_fill_path(graphics
, brush
);
3232 RestoreDC(graphics
->hdc
, save_state
);
3237 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3243 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3246 return InvalidParameter
;
3248 for(i
= 0; i
< count
; i
++){
3249 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
3250 if(ret
!= Ok
) return ret
;
3256 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3263 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3265 if(!rects
|| count
<= 0)
3266 return InvalidParameter
;
3268 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3272 for(i
= 0; i
< count
; i
++){
3273 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3274 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3275 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3276 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3279 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3285 /*****************************************************************************
3286 * GdipFillRegion [GDIPLUS.@]
3288 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3296 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
3298 if (!(graphics
&& brush
&& region
))
3299 return InvalidParameter
;
3306 FIXME("graphics object has no HDC\n");
3310 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3314 save_state
= SaveDC(graphics
->hdc
);
3315 EndPath(graphics
->hdc
);
3317 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3319 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3321 BeginPath(graphics
->hdc
);
3322 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3323 EndPath(graphics
->hdc
);
3325 brush_fill_path(graphics
, brush
);
3328 RestoreDC(graphics
->hdc
, save_state
);
3335 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
3337 TRACE("(%p,%u)\n", graphics
, intention
);
3340 return InvalidParameter
;
3345 /* We have no internal operation queue, so there's no need to clear it. */
3353 /*****************************************************************************
3354 * GdipGetClipBounds [GDIPLUS.@]
3356 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3358 TRACE("(%p, %p)\n", graphics
, rect
);
3361 return InvalidParameter
;
3366 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
3369 /*****************************************************************************
3370 * GdipGetClipBoundsI [GDIPLUS.@]
3372 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3374 TRACE("(%p, %p)\n", graphics
, rect
);
3377 return InvalidParameter
;
3382 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
3385 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3386 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
3387 CompositingMode
*mode
)
3389 TRACE("(%p, %p)\n", graphics
, mode
);
3391 if(!graphics
|| !mode
)
3392 return InvalidParameter
;
3397 *mode
= graphics
->compmode
;
3402 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3403 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
3404 CompositingQuality
*quality
)
3406 TRACE("(%p, %p)\n", graphics
, quality
);
3408 if(!graphics
|| !quality
)
3409 return InvalidParameter
;
3414 *quality
= graphics
->compqual
;
3419 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3420 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
3421 InterpolationMode
*mode
)
3423 TRACE("(%p, %p)\n", graphics
, mode
);
3425 if(!graphics
|| !mode
)
3426 return InvalidParameter
;
3431 *mode
= graphics
->interpolation
;
3436 /* FIXME: Need to handle color depths less than 24bpp */
3437 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
3439 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
3441 if(!graphics
|| !argb
)
3442 return InvalidParameter
;
3450 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
3452 TRACE("(%p, %p)\n", graphics
, scale
);
3454 if(!graphics
|| !scale
)
3455 return InvalidParameter
;
3460 *scale
= graphics
->scale
;
3465 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
3467 TRACE("(%p, %p)\n", graphics
, unit
);
3469 if(!graphics
|| !unit
)
3470 return InvalidParameter
;
3475 *unit
= graphics
->unit
;
3480 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3481 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3484 TRACE("(%p, %p)\n", graphics
, mode
);
3486 if(!graphics
|| !mode
)
3487 return InvalidParameter
;
3492 *mode
= graphics
->pixeloffset
;
3497 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3498 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
3500 TRACE("(%p, %p)\n", graphics
, mode
);
3502 if(!graphics
|| !mode
)
3503 return InvalidParameter
;
3508 *mode
= graphics
->smoothing
;
3513 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
3515 TRACE("(%p, %p)\n", graphics
, contrast
);
3517 if(!graphics
|| !contrast
)
3518 return InvalidParameter
;
3520 *contrast
= graphics
->textcontrast
;
3525 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3526 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
3527 TextRenderingHint
*hint
)
3529 TRACE("(%p, %p)\n", graphics
, hint
);
3531 if(!graphics
|| !hint
)
3532 return InvalidParameter
;
3537 *hint
= graphics
->texthint
;
3542 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3547 TRACE("(%p, %p)\n", graphics
, rect
);
3549 if(!graphics
|| !rect
)
3550 return InvalidParameter
;
3555 /* intersect window and graphics clipping regions */
3556 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
3559 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
3562 /* get bounds of the region */
3563 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
3566 GdipDeleteRegion(clip_rgn
);
3571 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3576 TRACE("(%p, %p)\n", graphics
, rect
);
3578 if(!graphics
|| !rect
)
3579 return InvalidParameter
;
3581 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
3583 rect
->X
= roundr(rectf
.X
);
3584 rect
->Y
= roundr(rectf
.Y
);
3585 rect
->Width
= roundr(rectf
.Width
);
3586 rect
->Height
= roundr(rectf
.Height
);
3592 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3594 TRACE("(%p, %p)\n", graphics
, matrix
);
3596 if(!graphics
|| !matrix
)
3597 return InvalidParameter
;
3602 *matrix
= *graphics
->worldtrans
;
3606 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
3612 TRACE("(%p, %x)\n", graphics
, color
);
3615 return InvalidParameter
;
3620 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
3623 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
3624 GdipDeleteBrush((GpBrush
*)brush
);
3628 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
3629 wnd_rect
.Width
, wnd_rect
.Height
);
3631 GdipDeleteBrush((GpBrush
*)brush
);
3636 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
3638 TRACE("(%p, %p)\n", graphics
, res
);
3640 if(!graphics
|| !res
)
3641 return InvalidParameter
;
3643 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
3646 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
3652 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
3654 if(!graphics
|| !result
)
3655 return InvalidParameter
;
3662 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3663 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
3666 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
3669 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
3672 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
3675 GdipDeleteRegion(rgn
);
3679 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
3681 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
3684 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
3690 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
3692 if(!graphics
|| !result
)
3693 return InvalidParameter
;
3700 pts
[1].X
= x
+ width
;
3701 pts
[1].Y
= y
+ height
;
3703 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3704 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
3707 pts
[1].X
-= pts
[0].X
;
3708 pts
[1].Y
-= pts
[0].Y
;
3710 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
3713 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
3716 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
3719 GdipDeleteRegion(rgn
);
3723 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
3725 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
3728 typedef GpStatus (*gdip_format_string_callback
)(GpGraphics
*graphics
,
3729 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3730 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3731 INT lineno
, const RectF
*bounds
, void *user_data
);
3733 static GpStatus
gdip_format_string(GpGraphics
*graphics
,
3734 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
3735 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3736 gdip_format_string_callback callback
, void *user_data
)
3739 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
3740 nheight
, lineend
, lineno
= 0;
3742 StringAlignment halign
;
3746 if(length
== -1) length
= lstrlenW(string
);
3748 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
3749 if(!stringdup
) return OutOfMemory
;
3751 nwidth
= roundr(rect
->Width
);
3752 nheight
= roundr(rect
->Height
);
3754 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
3755 if (rect
->Height
>= INT_MAX
|| rect
->Width
< 0.5) nheight
= INT_MAX
;
3757 for(i
= 0, j
= 0; i
< length
; i
++){
3758 /* FIXME: This makes the indexes passed to callback inaccurate. */
3759 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
3762 stringdup
[j
] = string
[i
];
3768 if (format
) halign
= format
->align
;
3769 else halign
= StringAlignmentNear
;
3771 while(sum
< length
){
3772 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
3773 nwidth
, &fit
, NULL
, &size
);
3779 for(lret
= 0; lret
< fit
; lret
++)
3780 if(*(stringdup
+ sum
+ lret
) == '\n')
3783 /* Line break code (may look strange, but it imitates windows). */
3785 lineend
= fit
= lret
; /* this is not an off-by-one error */
3786 else if(fit
< (length
- sum
)){
3787 if(*(stringdup
+ sum
+ fit
) == ' ')
3788 while(*(stringdup
+ sum
+ fit
) == ' ')
3791 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
3794 if(*(stringdup
+ sum
+ fit
) == '\t')
3803 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
3804 *(stringdup
+ sum
+ lineend
- 1) == '\t')
3810 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, lineend
,
3811 nwidth
, &j
, NULL
, &size
);
3813 bounds
.Width
= size
.cx
;
3815 if(height
+ size
.cy
> nheight
)
3816 bounds
.Height
= nheight
- (height
+ size
.cy
);
3818 bounds
.Height
= size
.cy
;
3820 bounds
.Y
= rect
->Y
+ height
;
3824 case StringAlignmentNear
:
3828 case StringAlignmentCenter
:
3829 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
3831 case StringAlignmentFar
:
3832 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
3836 stat
= callback(graphics
, stringdup
, sum
, lineend
,
3837 font
, rect
, format
, lineno
, &bounds
, user_data
);
3842 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
3846 if(height
> nheight
)
3849 /* Stop if this was a linewrap (but not if it was a linebreak). */
3850 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
3854 GdipFree(stringdup
);
3859 struct measure_ranges_args
{
3863 static GpStatus
measure_ranges_callback(GpGraphics
*graphics
,
3864 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3865 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3866 INT lineno
, const RectF
*bounds
, void *user_data
)
3870 struct measure_ranges_args
*args
= user_data
;
3872 for (i
=0; i
<format
->range_count
; i
++)
3874 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
3875 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
3876 if (range_start
< range_end
)
3881 range_rect
.Y
= bounds
->Y
;
3882 range_rect
.Height
= bounds
->Height
;
3884 GetTextExtentExPointW(graphics
->hdc
, string
+ index
, range_start
- index
,
3885 INT_MAX
, NULL
, NULL
, &range_size
);
3886 range_rect
.X
= bounds
->X
+ range_size
.cx
;
3888 GetTextExtentExPointW(graphics
->hdc
, string
+ index
, range_end
- index
,
3889 INT_MAX
, NULL
, NULL
, &range_size
);
3890 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
3892 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
3901 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
3902 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
3903 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
3904 INT regionCount
, GpRegion
** regions
)
3909 struct measure_ranges_args args
;
3912 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
3913 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
3915 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
3916 return InvalidParameter
;
3918 if (regionCount
< stringFormat
->range_count
)
3919 return InvalidParameter
;
3923 temp_hdc
= graphics
->hdc
= CreateCompatibleDC(0);
3924 if (!temp_hdc
) return OutOfMemory
;
3927 if (stringFormat
->attr
)
3928 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
3930 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
3932 for (i
=0; i
<stringFormat
->range_count
; i
++)
3934 stat
= GdipSetEmpty(regions
[i
]);
3939 args
.regions
= regions
;
3941 stat
= gdip_format_string(graphics
, string
, length
, font
, layoutRect
, stringFormat
,
3942 measure_ranges_callback
, &args
);
3944 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3948 graphics
->hdc
= NULL
;
3955 struct measure_string_args
{
3957 INT
*codepointsfitted
;
3961 static GpStatus
measure_string_callback(GpGraphics
*graphics
,
3962 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3963 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3964 INT lineno
, const RectF
*bounds
, void *user_data
)
3966 struct measure_string_args
*args
= user_data
;
3968 if (bounds
->Width
> args
->bounds
->Width
)
3969 args
->bounds
->Width
= bounds
->Width
;
3971 if (bounds
->Height
+ bounds
->Y
> args
->bounds
->Height
+ args
->bounds
->Y
)
3972 args
->bounds
->Height
= bounds
->Height
+ bounds
->Y
- args
->bounds
->Y
;
3974 if (args
->codepointsfitted
)
3975 *args
->codepointsfitted
= index
+ length
;
3977 if (args
->linesfilled
)
3978 (*args
->linesfilled
)++;
3983 /* Find the smallest rectangle that bounds the text when it is printed in rect
3984 * according to the format options listed in format. If rect has 0 width and
3985 * height, then just find the smallest rectangle that bounds the text when it's
3986 * printed at location (rect->X, rect-Y). */
3987 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
3988 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
3989 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
3990 INT
*codepointsfitted
, INT
*linesfilled
)
3993 struct measure_string_args args
;
3996 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
3997 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
3998 bounds
, codepointsfitted
, linesfilled
);
4000 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4001 return InvalidParameter
;
4005 temp_hdc
= graphics
->hdc
= CreateCompatibleDC(0);
4006 if (!temp_hdc
) return OutOfMemory
;
4009 if(linesfilled
) *linesfilled
= 0;
4010 if(codepointsfitted
) *codepointsfitted
= 0;
4013 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4015 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
4017 bounds
->X
= rect
->X
;
4018 bounds
->Y
= rect
->Y
;
4019 bounds
->Width
= 0.0;
4020 bounds
->Height
= 0.0;
4022 args
.bounds
= bounds
;
4023 args
.codepointsfitted
= codepointsfitted
;
4024 args
.linesfilled
= linesfilled
;
4026 gdip_format_string(graphics
, string
, length
, font
, rect
, format
,
4027 measure_string_callback
, &args
);
4029 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
4033 graphics
->hdc
= NULL
;
4040 struct draw_string_args
{
4043 REAL ang_cos
, ang_sin
;
4046 static GpStatus
draw_string_callback(GpGraphics
*graphics
,
4047 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4048 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4049 INT lineno
, const RectF
*bounds
, void *user_data
)
4051 struct draw_string_args
*args
= user_data
;
4054 drawcoord
.left
= drawcoord
.right
= args
->drawbase
.x
+ roundr(args
->ang_sin
* bounds
->Y
);
4055 drawcoord
.top
= drawcoord
.bottom
= args
->drawbase
.y
+ roundr(args
->ang_cos
* bounds
->Y
);
4057 DrawTextW(graphics
->hdc
, string
+ index
, length
, &drawcoord
, args
->drawflags
);
4062 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4063 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4064 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4069 TEXTMETRICW textmet
;
4070 GpPointF pt
[3], rectcpy
[4];
4072 REAL angle
, rel_width
, rel_height
;
4073 INT offsety
= 0, save_state
;
4074 struct draw_string_args args
;
4077 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4078 length
, font
, debugstr_rectf(rect
), format
, brush
);
4080 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4081 return InvalidParameter
;
4083 if((brush
->bt
!= BrushTypeSolidColor
)){
4084 FIXME("not implemented for given parameters\n");
4085 return NotImplemented
;
4090 FIXME("graphics object has no HDC\n");
4095 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4097 /* Should be no need to explicitly test for StringAlignmentNear as
4098 * that is default behavior if no alignment is passed. */
4099 if(format
->vertalign
!= StringAlignmentNear
){
4101 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
4103 if(format
->vertalign
== StringAlignmentCenter
)
4104 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4105 else if(format
->vertalign
== StringAlignmentFar
)
4106 offsety
= (rect
->Height
- bounds
.Height
);
4110 save_state
= SaveDC(graphics
->hdc
);
4111 SetBkMode(graphics
->hdc
, TRANSPARENT
);
4112 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
4120 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4121 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
4122 args
.ang_cos
= cos(angle
);
4123 args
.ang_sin
= sin(angle
);
4124 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4125 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4126 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4127 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4129 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
4130 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
4131 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
4132 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
4133 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
4135 scaled_rect
.X
= 0.0;
4136 scaled_rect
.Y
= 0.0;
4137 scaled_rect
.Width
= rel_width
* rect
->Width
;
4138 scaled_rect
.Height
= rel_height
* rect
->Height
;
4140 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
4142 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4143 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
4144 SelectClipRgn(graphics
->hdc
, rgn
);
4147 /* Use gdi to find the font, then perform transformations on it (height,
4149 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
4150 GetTextMetricsW(graphics
->hdc
, &textmet
);
4153 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
4154 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
4156 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
4158 gdifont
= CreateFontIndirectW(&lfw
);
4159 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
4161 if (!format
|| format
->align
== StringAlignmentNear
)
4163 args
.drawbase
.x
= corners
[0].x
;
4164 args
.drawbase
.y
= corners
[0].y
;
4165 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
;
4167 else if (format
->align
== StringAlignmentCenter
)
4169 args
.drawbase
.x
= (corners
[0].x
+ corners
[1].x
)/2;
4170 args
.drawbase
.y
= (corners
[0].y
+ corners
[1].y
)/2;
4171 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_CENTER
;
4173 else /* (format->align == StringAlignmentFar) */
4175 args
.drawbase
.x
= corners
[1].x
;
4176 args
.drawbase
.y
= corners
[1].y
;
4177 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_RIGHT
;
4180 gdip_format_string(graphics
, string
, length
, font
, &scaled_rect
, format
,
4181 draw_string_callback
, &args
);
4184 DeleteObject(gdifont
);
4186 RestoreDC(graphics
->hdc
, save_state
);
4191 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
4193 TRACE("(%p)\n", graphics
);
4196 return InvalidParameter
;
4201 return GdipSetInfinite(graphics
->clip
);
4204 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
4206 TRACE("(%p)\n", graphics
);
4209 return InvalidParameter
;
4214 graphics
->worldtrans
->matrix
[0] = 1.0;
4215 graphics
->worldtrans
->matrix
[1] = 0.0;
4216 graphics
->worldtrans
->matrix
[2] = 0.0;
4217 graphics
->worldtrans
->matrix
[3] = 1.0;
4218 graphics
->worldtrans
->matrix
[4] = 0.0;
4219 graphics
->worldtrans
->matrix
[5] = 0.0;
4224 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
4226 return GdipEndContainer(graphics
, state
);
4229 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
4230 GpMatrixOrder order
)
4232 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
4235 return InvalidParameter
;
4240 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
4243 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
4245 return GdipBeginContainer2(graphics
, state
);
4248 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
4249 GraphicsContainer
*state
)
4251 GraphicsContainerItem
*container
;
4254 TRACE("(%p, %p)\n", graphics
, state
);
4256 if(!graphics
|| !state
)
4257 return InvalidParameter
;
4259 sts
= init_container(&container
, graphics
);
4263 list_add_head(&graphics
->containers
, &container
->entry
);
4264 *state
= graphics
->contid
= container
->contid
;
4269 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4271 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4272 return NotImplemented
;
4275 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4277 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4278 return NotImplemented
;
4281 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
4283 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
4284 return NotImplemented
;
4287 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
4290 GraphicsContainerItem
*container
, *container2
;
4292 TRACE("(%p, %x)\n", graphics
, state
);
4295 return InvalidParameter
;
4297 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4298 if(container
->contid
== state
)
4302 /* did not find a matching container */
4303 if(&container
->entry
== &graphics
->containers
)
4306 sts
= restore_container(graphics
, container
);
4310 /* remove all of the containers on top of the found container */
4311 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4312 if(container
->contid
== state
)
4314 list_remove(&container
->entry
);
4315 delete_container(container
);
4318 list_remove(&container
->entry
);
4319 delete_container(container
);
4324 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
4325 REAL sy
, GpMatrixOrder order
)
4327 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
4330 return InvalidParameter
;
4335 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
4338 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
4341 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
4343 if(!graphics
|| !srcgraphics
)
4344 return InvalidParameter
;
4346 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
4349 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
4350 CompositingMode mode
)
4352 TRACE("(%p, %d)\n", graphics
, mode
);
4355 return InvalidParameter
;
4360 graphics
->compmode
= mode
;
4365 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
4366 CompositingQuality quality
)
4368 TRACE("(%p, %d)\n", graphics
, quality
);
4371 return InvalidParameter
;
4376 graphics
->compqual
= quality
;
4381 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
4382 InterpolationMode mode
)
4384 TRACE("(%p, %d)\n", graphics
, mode
);
4387 return InvalidParameter
;
4392 graphics
->interpolation
= mode
;
4397 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
4399 TRACE("(%p, %.2f)\n", graphics
, scale
);
4401 if(!graphics
|| (scale
<= 0.0))
4402 return InvalidParameter
;
4407 graphics
->scale
= scale
;
4412 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
4414 TRACE("(%p, %d)\n", graphics
, unit
);
4417 return InvalidParameter
;
4422 if(unit
== UnitWorld
)
4423 return InvalidParameter
;
4425 graphics
->unit
= unit
;
4430 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4433 TRACE("(%p, %d)\n", graphics
, mode
);
4436 return InvalidParameter
;
4441 graphics
->pixeloffset
= mode
;
4446 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
4450 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
4453 FIXME("not implemented\n");
4455 return NotImplemented
;
4458 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
4462 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
4465 FIXME("not implemented\n");
4469 return NotImplemented
;
4472 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
4474 TRACE("(%p, %d)\n", graphics
, mode
);
4477 return InvalidParameter
;
4482 graphics
->smoothing
= mode
;
4487 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
4489 TRACE("(%p, %d)\n", graphics
, contrast
);
4492 return InvalidParameter
;
4494 graphics
->textcontrast
= contrast
;
4499 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
4500 TextRenderingHint hint
)
4502 TRACE("(%p, %d)\n", graphics
, hint
);
4505 return InvalidParameter
;
4510 graphics
->texthint
= hint
;
4515 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4517 TRACE("(%p, %p)\n", graphics
, matrix
);
4519 if(!graphics
|| !matrix
)
4520 return InvalidParameter
;
4525 GdipDeleteMatrix(graphics
->worldtrans
);
4526 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
4529 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
4530 REAL dy
, GpMatrixOrder order
)
4532 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
4535 return InvalidParameter
;
4540 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
4543 /*****************************************************************************
4544 * GdipSetClipHrgn [GDIPLUS.@]
4546 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
4551 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
4554 return InvalidParameter
;
4556 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
4560 status
= GdipSetClipRegion(graphics
, region
, mode
);
4562 GdipDeleteRegion(region
);
4566 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
4568 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
4571 return InvalidParameter
;
4576 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
4579 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
4580 REAL width
, REAL height
,
4585 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
4588 return InvalidParameter
;
4596 rect
.Height
= height
;
4598 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
4601 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
4602 INT width
, INT height
,
4605 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
4608 return InvalidParameter
;
4613 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
4616 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
4619 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
4621 if(!graphics
|| !region
)
4622 return InvalidParameter
;
4627 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
4630 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
4635 TRACE("(%p,%u)\n", metafile
, limitDpi
);
4638 FIXME("not implemented\n");
4640 return NotImplemented
;
4643 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
4649 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
4651 if(!graphics
|| !pen
|| count
<=0)
4652 return InvalidParameter
;
4659 FIXME("graphics object has no HDC\n");
4663 pti
= GdipAlloc(sizeof(POINT
) * count
);
4665 save_state
= prepare_dc(graphics
, pen
);
4666 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
4668 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
4669 Polygon(graphics
->hdc
, pti
, count
);
4671 restore_dc(graphics
, save_state
);
4677 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
4684 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
4686 if(count
<=0) return InvalidParameter
;
4687 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
4689 for(i
= 0;i
< count
; i
++){
4690 ptf
[i
].X
= (REAL
)points
[i
].X
;
4691 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4694 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
4700 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
4702 TRACE("(%p, %p)\n", graphics
, dpi
);
4704 if(!graphics
|| !dpi
)
4705 return InvalidParameter
;
4710 if (graphics
->image
)
4711 *dpi
= graphics
->image
->xres
;
4713 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
4718 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
4720 TRACE("(%p, %p)\n", graphics
, dpi
);
4722 if(!graphics
|| !dpi
)
4723 return InvalidParameter
;
4728 if (graphics
->image
)
4729 *dpi
= graphics
->image
->yres
;
4731 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
4736 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
4737 GpMatrixOrder order
)
4742 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
4744 if(!graphics
|| !matrix
)
4745 return InvalidParameter
;
4750 m
= *(graphics
->worldtrans
);
4752 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
4754 *(graphics
->worldtrans
) = m
;
4759 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
4760 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
4762 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
4764 TRACE("(%p, %p)\n", graphics
, hdc
);
4766 if(!graphics
|| !hdc
)
4767 return InvalidParameter
;
4772 if (!graphics
->hdc
||
4773 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
4775 /* Create a fake HDC and fill it with a constant color. */
4780 BITMAPINFOHEADER bmih
;
4783 stat
= get_graphics_bounds(graphics
, &bounds
);
4787 graphics
->temp_hbitmap_width
= bounds
.Width
;
4788 graphics
->temp_hbitmap_height
= bounds
.Height
;
4790 bmih
.biSize
= sizeof(bmih
);
4791 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
4792 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
4794 bmih
.biBitCount
= 32;
4795 bmih
.biCompression
= BI_RGB
;
4796 bmih
.biSizeImage
= 0;
4797 bmih
.biXPelsPerMeter
= 0;
4798 bmih
.biYPelsPerMeter
= 0;
4800 bmih
.biClrImportant
= 0;
4802 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
4803 (void**)&graphics
->temp_bits
, NULL
, 0);
4805 return GenericError
;
4807 temp_hdc
= CreateCompatibleDC(0);
4810 DeleteObject(hbitmap
);
4811 return GenericError
;
4814 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
4815 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
4817 SelectObject(temp_hdc
, hbitmap
);
4819 graphics
->temp_hbitmap
= hbitmap
;
4820 *hdc
= graphics
->temp_hdc
= temp_hdc
;
4824 *hdc
= graphics
->hdc
;
4827 graphics
->busy
= TRUE
;
4832 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
4834 TRACE("(%p, %p)\n", graphics
, hdc
);
4836 if(!graphics
|| !hdc
)
4837 return InvalidParameter
;
4839 if((graphics
->hdc
!= hdc
&& graphics
->temp_hdc
!= hdc
) || !(graphics
->busy
))
4840 return InvalidParameter
;
4842 if (graphics
->temp_hdc
== hdc
)
4847 /* Find the pixels that have changed, and mark them as opaque. */
4848 pos
= (DWORD
*)graphics
->temp_bits
;
4849 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
4851 if (*pos
!= DC_BACKGROUND_KEY
)
4858 /* Write the changed pixels to the real target. */
4859 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
4860 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
4861 graphics
->temp_hbitmap_width
* 4);
4864 DeleteDC(graphics
->temp_hdc
);
4865 DeleteObject(graphics
->temp_hbitmap
);
4866 graphics
->temp_hdc
= NULL
;
4867 graphics
->temp_hbitmap
= NULL
;
4870 graphics
->busy
= FALSE
;
4875 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
4880 TRACE("(%p, %p)\n", graphics
, region
);
4882 if(!graphics
|| !region
)
4883 return InvalidParameter
;
4888 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
4891 /* free everything except root node and header */
4892 delete_element(®ion
->node
);
4893 memcpy(region
, clip
, sizeof(GpRegion
));
4899 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4900 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
4906 if(!graphics
|| !points
|| count
<= 0)
4907 return InvalidParameter
;
4912 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4914 if (src_space
== dst_space
) return Ok
;
4916 stat
= GdipCreateMatrix(&matrix
);
4919 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
4921 if(graphics
->unit
!= UnitDisplay
)
4922 unitscale
*= graphics
->scale
;
4924 /* transform from src_space to CoordinateSpacePage */
4927 case CoordinateSpaceWorld
:
4928 GdipMultiplyMatrix(matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
4930 case CoordinateSpacePage
:
4932 case CoordinateSpaceDevice
:
4933 GdipScaleMatrix(matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
4937 /* transform from CoordinateSpacePage to dst_space */
4940 case CoordinateSpaceWorld
:
4942 GpMatrix
*inverted_transform
;
4943 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
4946 stat
= GdipInvertMatrix(inverted_transform
);
4948 GdipMultiplyMatrix(matrix
, inverted_transform
, MatrixOrderAppend
);
4949 GdipDeleteMatrix(inverted_transform
);
4953 case CoordinateSpacePage
:
4955 case CoordinateSpaceDevice
:
4956 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
4961 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
4963 GdipDeleteMatrix(matrix
);
4969 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4970 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
4976 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4979 return InvalidParameter
;
4981 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
4985 for(i
= 0; i
< count
; i
++){
4986 pointsF
[i
].X
= (REAL
)points
[i
].X
;
4987 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
4990 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
4993 for(i
= 0; i
< count
; i
++){
4994 points
[i
].X
= roundr(pointsF
[i
].X
);
4995 points
[i
].Y
= roundr(pointsF
[i
].Y
);
5002 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5014 /*****************************************************************************
5015 * GdipTranslateClip [GDIPLUS.@]
5017 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5019 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5022 return InvalidParameter
;
5027 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5030 /*****************************************************************************
5031 * GdipTranslateClipI [GDIPLUS.@]
5033 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5035 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5038 return InvalidParameter
;
5043 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
5047 /*****************************************************************************
5048 * GdipMeasureDriverString [GDIPLUS.@]
5050 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5051 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
5052 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
5054 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
5055 return NotImplemented
;
5058 /*****************************************************************************
5059 * GdipDrawDriverString [GDIPLUS.@]
5061 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5062 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
5063 GDIPCONST PointF
*positions
, INT flags
,
5064 GDIPCONST GpMatrix
*matrix
)
5066 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics
, text
, length
, font
, brush
, positions
, flags
, matrix
);
5067 return NotImplemented
;
5070 GpStatus WINGDIPAPI
GdipRecordMetafile(HDC hdc
, EmfType type
, GDIPCONST GpRectF
*frameRect
,
5071 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5073 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5074 return NotImplemented
;
5077 /*****************************************************************************
5078 * GdipRecordMetafileI [GDIPLUS.@]
5080 GpStatus WINGDIPAPI
GdipRecordMetafileI(HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
5081 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5083 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5084 return NotImplemented
;
5087 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
5088 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5090 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5091 return NotImplemented
;
5094 /*****************************************************************************
5095 * GdipIsVisibleClipEmpty [GDIPLUS.@]
5097 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
5102 TRACE("(%p, %p)\n", graphics
, res
);
5104 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5107 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5110 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
5113 GdipDeleteRegion(rgn
);