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 INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
91 INT save_state
= SaveDC(graphics
->hdc
), i
, numdashes
;
93 DWORD dash_array
[MAX_DASHLEN
];
95 EndPath(graphics
->hdc
);
97 if(pen
->unit
== UnitPixel
){
101 /* Get an estimate for the amount the pen width is affected by the world
102 * transform. (This is similar to what some of the wine drivers do.) */
107 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
108 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
109 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
111 width
*= pen
->width
* convert_unit(graphics
->hdc
,
112 pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
);
115 if(pen
->dash
== DashStyleCustom
){
116 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
118 TRACE("dashes are: ");
119 for(i
= 0; i
< numdashes
; i
++){
120 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
121 TRACE("%d, ", dash_array
[i
]);
123 TRACE("\n and the pen style is %x\n", pen
->style
);
125 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
,
126 numdashes
, dash_array
);
129 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
, 0, NULL
);
131 SelectObject(graphics
->hdc
, gdipen
);
136 static void restore_dc(GpGraphics
*graphics
, INT state
)
138 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
139 RestoreDC(graphics
->hdc
, state
);
142 /* This helper applies all the changes that the points listed in ptf need in
143 * order to be drawn on the device context. In the end, this should include at
145 * -scaling by page unit
146 * -applying world transformation
147 * -converting from float to int
148 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
149 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
150 * gdi to draw, and these functions would irreparably mess with line widths.
152 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
153 GpPointF
*ptf
, INT count
)
159 unitscale
= convert_unit(graphics
->hdc
, graphics
->unit
);
161 /* apply page scale */
162 if(graphics
->unit
!= UnitDisplay
)
163 unitscale
*= graphics
->scale
;
165 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
166 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
167 GdipTransformMatrixPoints(matrix
, ptf
, count
);
168 GdipDeleteMatrix(matrix
);
170 for(i
= 0; i
< count
; i
++){
171 pti
[i
].x
= roundr(ptf
[i
].X
);
172 pti
[i
].y
= roundr(ptf
[i
].Y
);
176 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
180 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
181 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
185 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
189 /* clamp to between 0.0 and 1.0, using the wrap mode */
190 if (brush
->wrap
== WrapModeTile
)
192 position
= fmodf(position
, 1.0f
);
193 if (position
< 0.0f
) position
+= 1.0f
;
195 else /* WrapModeFlip* */
197 position
= fmodf(position
, 2.0f
);
198 if (position
< 0.0f
) position
+= 2.0f
;
199 if (position
> 1.0f
) position
= 2.0f
- position
;
202 if (brush
->blendcount
== 1)
207 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
210 /* locate the blend positions surrounding this position */
211 while (position
> brush
->blendpos
[i
])
214 /* interpolate between the blend positions */
215 left_blendpos
= brush
->blendpos
[i
-1];
216 left_blendfac
= brush
->blendfac
[i
-1];
217 right_blendpos
= brush
->blendpos
[i
];
218 right_blendfac
= brush
->blendfac
[i
];
219 range
= right_blendpos
- left_blendpos
;
220 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
221 right_blendfac
* (position
- left_blendpos
)) / range
;
223 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
226 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
230 case BrushTypeLinearGradient
:
232 GpLineGradient
*line
= (GpLineGradient
*)brush
;
235 SelectClipPath(graphics
->hdc
, RGN_AND
);
236 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
238 GpPointF endpointsf
[2];
242 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
244 endpointsf
[0] = line
->startpoint
;
245 endpointsf
[1] = line
->endpoint
;
246 transform_and_round_points(graphics
, endpointsi
, endpointsf
, 2);
248 if (abs(endpointsi
[0].x
-endpointsi
[1].x
) > abs(endpointsi
[0].y
-endpointsi
[1].y
))
250 /* vertical-ish gradient */
251 int startx
, endx
; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
252 int startbottomx
; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
255 HBRUSH hbrush
, hprevbrush
;
256 int leftx
, rightx
; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
258 int tilt
; /* horizontal distance covered by a gradient line */
260 startx
= roundr((rc
.top
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
261 endx
= roundr((rc
.top
- endpointsf
[1].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[1].X
);
262 width
= endx
- startx
;
263 startbottomx
= roundr((rc
.bottom
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
264 tilt
= startx
- startbottomx
;
266 if (startx
>= startbottomx
)
269 rightx
= rc
.right
+ tilt
;
273 leftx
= rc
.left
+ tilt
;
277 poly
[0].y
= rc
.bottom
;
280 poly
[3].y
= rc
.bottom
;
282 for (x
=leftx
; x
<=rightx
; x
++)
284 ARGB argb
= blend_line_gradient(line
, (x
-startx
)/(REAL
)width
);
285 col
= ARGB2COLORREF(argb
);
286 hbrush
= CreateSolidBrush(col
);
287 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
288 poly
[0].x
= x
- tilt
- 1;
291 poly
[3].x
= x
- tilt
;
292 Polygon(graphics
->hdc
, poly
, 4);
293 SelectObject(graphics
->hdc
, hprevbrush
);
294 DeleteObject(hbrush
);
297 else if (endpointsi
[0].y
!= endpointsi
[1].y
)
299 /* horizontal-ish gradient */
300 int starty
, endy
; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
301 int startrighty
; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
304 HBRUSH hbrush
, hprevbrush
;
305 int topy
, bottomy
; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
307 int tilt
; /* vertical distance covered by a gradient line */
309 starty
= roundr((rc
.left
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
310 endy
= roundr((rc
.left
- endpointsf
[1].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[1].Y
);
311 height
= endy
- starty
;
312 startrighty
= roundr((rc
.right
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
313 tilt
= starty
- startrighty
;
315 if (starty
>= startrighty
)
318 bottomy
= rc
.bottom
+ tilt
;
322 topy
= rc
.top
+ tilt
;
326 poly
[0].x
= rc
.right
;
329 poly
[3].x
= rc
.right
;
331 for (y
=topy
; y
<=bottomy
; y
++)
333 ARGB argb
= blend_line_gradient(line
, (y
-starty
)/(REAL
)height
);
334 col
= ARGB2COLORREF(argb
);
335 hbrush
= CreateSolidBrush(col
);
336 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
337 poly
[0].y
= y
- tilt
- 1;
340 poly
[3].y
= y
- tilt
;
341 Polygon(graphics
->hdc
, poly
, 4);
342 SelectObject(graphics
->hdc
, hprevbrush
);
343 DeleteObject(hbrush
);
346 /* else startpoint == endpoint */
350 case BrushTypeSolidColor
:
352 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
356 /* partially transparent fill */
358 SelectClipPath(graphics
->hdc
, RGN_AND
);
359 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
361 HDC hdc
= CreateCompatibleDC(NULL
);
367 oldbmp
= SelectObject(hdc
, fill
->bmp
);
369 bf
.BlendOp
= AC_SRC_OVER
;
371 bf
.SourceConstantAlpha
= 255;
372 bf
.AlphaFormat
= AC_SRC_ALPHA
;
374 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
376 SelectObject(hdc
, oldbmp
);
382 /* else fall through */
385 SelectObject(graphics
->hdc
, brush
->gdibrush
);
386 FillPath(graphics
->hdc
);
391 /* GdipDrawPie/GdipFillPie helper function */
392 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
393 REAL height
, REAL startAngle
, REAL sweepAngle
)
400 ptf
[1].X
= x
+ width
;
401 ptf
[1].Y
= y
+ height
;
403 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
404 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
406 transform_and_round_points(graphics
, pti
, ptf
, 4);
408 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
409 pti
[2].y
, pti
[3].x
, pti
[3].y
);
412 /* Draws the linecap the specified color and size on the hdc. The linecap is in
413 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
414 * should not be called on an hdc that has a path you care about. */
415 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
416 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
418 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
419 GpMatrix
*matrix
= NULL
;
422 PointF ptf
[4], *custptf
= NULL
;
423 POINT pt
[4], *custpt
= NULL
;
425 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
430 if((x1
== x2
) && (y1
== y2
))
433 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
435 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
437 brush
= CreateSolidBrush(color
);
438 lb
.lbStyle
= BS_SOLID
;
441 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
442 PS_JOIN_MITER
, 1, &lb
, 0,
444 oldbrush
= SelectObject(graphics
->hdc
, brush
);
445 oldpen
= SelectObject(graphics
->hdc
, pen
);
452 case LineCapSquareAnchor
:
453 case LineCapDiamondAnchor
:
454 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
455 if(cap
== LineCapDiamondAnchor
){
456 dsmall
= cos(theta
+ M_PI_2
) * size
;
457 dbig
= sin(theta
+ M_PI_2
) * size
;
460 dsmall
= cos(theta
+ M_PI_4
) * size
;
461 dbig
= sin(theta
+ M_PI_4
) * size
;
464 ptf
[0].X
= x2
- dsmall
;
465 ptf
[1].X
= x2
+ dbig
;
467 ptf
[0].Y
= y2
- dbig
;
468 ptf
[3].Y
= y2
+ dsmall
;
470 ptf
[1].Y
= y2
- dsmall
;
471 ptf
[2].Y
= y2
+ dbig
;
473 ptf
[3].X
= x2
- dbig
;
474 ptf
[2].X
= x2
+ dsmall
;
476 transform_and_round_points(graphics
, pt
, ptf
, 4);
477 Polygon(graphics
->hdc
, pt
, 4);
480 case LineCapArrowAnchor
:
481 size
= size
* 4.0 / sqrt(3.0);
483 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
484 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
489 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
490 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
498 transform_and_round_points(graphics
, pt
, ptf
, 3);
499 Polygon(graphics
->hdc
, pt
, 3);
502 case LineCapRoundAnchor
:
503 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
510 transform_and_round_points(graphics
, pt
, ptf
, 2);
511 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
514 case LineCapTriangle
:
516 dx
= cos(M_PI_2
+ theta
) * size
;
517 dy
= sin(M_PI_2
+ theta
) * size
;
524 dx
= cos(theta
) * size
;
525 dy
= sin(theta
) * size
;
530 transform_and_round_points(graphics
, pt
, ptf
, 3);
531 Polygon(graphics
->hdc
, pt
, 3);
535 dx
= dy
= size
/ 2.0;
542 dx
= -cos(M_PI_2
+ theta
) * size
;
543 dy
= -sin(M_PI_2
+ theta
) * size
;
550 transform_and_round_points(graphics
, pt
, ptf
, 4);
551 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
552 pt
[2].y
, pt
[3].x
, pt
[3].y
);
559 count
= custom
->pathdata
.Count
;
560 custptf
= GdipAlloc(count
* sizeof(PointF
));
561 custpt
= GdipAlloc(count
* sizeof(POINT
));
562 tp
= GdipAlloc(count
);
564 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
567 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
569 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
570 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
572 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
573 GdipTransformMatrixPoints(matrix
, custptf
, count
);
575 transform_and_round_points(graphics
, custpt
, custptf
, count
);
577 for(i
= 0; i
< count
; i
++)
578 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
581 BeginPath(graphics
->hdc
);
582 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
583 EndPath(graphics
->hdc
);
584 StrokeAndFillPath(graphics
->hdc
);
587 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
593 GdipDeleteMatrix(matrix
);
600 SelectObject(graphics
->hdc
, oldbrush
);
601 SelectObject(graphics
->hdc
, oldpen
);
607 /* Shortens the line by the given percent by changing x2, y2.
608 * If percent is > 1.0 then the line will change direction.
609 * If percent is negative it can lengthen the line. */
610 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
612 REAL dist
, theta
, dx
, dy
;
614 if((y1
== *y2
) && (x1
== *x2
))
617 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
618 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
619 dx
= cos(theta
) * dist
;
620 dy
= sin(theta
) * dist
;
626 /* Shortens the line by the given amount by changing x2, y2.
627 * If the amount is greater than the distance, the line will become length 0.
628 * If the amount is negative, it can lengthen the line. */
629 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
631 REAL dx
, dy
, percent
;
635 if(dx
== 0 && dy
== 0)
638 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
645 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
648 /* Draws lines between the given points, and if caps is true then draws an endcap
649 * at the end of the last line. */
650 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
651 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
654 GpPointF
*ptcopy
= NULL
;
655 GpStatus status
= GenericError
;
660 pti
= GdipAlloc(count
* sizeof(POINT
));
661 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
664 status
= OutOfMemory
;
668 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
671 if(pen
->endcap
== LineCapArrowAnchor
)
672 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
673 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
674 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
675 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
676 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
677 pen
->customend
->inset
* pen
->width
);
679 if(pen
->startcap
== LineCapArrowAnchor
)
680 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
681 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
682 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
683 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
684 &ptcopy
[0].X
, &ptcopy
[0].Y
,
685 pen
->customstart
->inset
* pen
->width
);
687 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
688 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
689 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
690 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
693 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
695 if(Polyline(graphics
->hdc
, pti
, count
))
705 /* Conducts a linear search to find the bezier points that will back off
706 * the endpoint of the curve by a distance of amt. Linear search works
707 * better than binary in this case because there are multiple solutions,
708 * and binary searches often find a bad one. I don't think this is what
709 * Windows does but short of rendering the bezier without GDI's help it's
710 * the best we can do. If rev then work from the start of the passed points
711 * instead of the end. */
712 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
715 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
716 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
725 origx
= pt
[fourth
].X
;
726 origy
= pt
[fourth
].Y
;
727 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
729 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
730 /* reset bezier points to original values */
731 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
732 /* Perform magic on bezier points. Order is important here.*/
733 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
734 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
735 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
736 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
737 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
738 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
740 dx
= pt
[fourth
].X
- origx
;
741 dy
= pt
[fourth
].Y
- origy
;
743 diff
= sqrt(dx
* dx
+ dy
* dy
);
744 percent
+= 0.0005 * amt
;
748 /* Draws bezier curves between given points, and if caps is true then draws an
749 * endcap at the end of the last line. */
750 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
751 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
755 GpStatus status
= GenericError
;
760 pti
= GdipAlloc(count
* sizeof(POINT
));
761 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
764 status
= OutOfMemory
;
768 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
771 if(pen
->endcap
== LineCapArrowAnchor
)
772 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
773 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
774 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
777 if(pen
->startcap
== LineCapArrowAnchor
)
778 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
779 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
780 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
782 /* the direction of the line cap is parallel to the direction at the
783 * end of the bezier (which, if it has been shortened, is not the same
784 * as the direction from pt[count-2] to pt[count-1]) */
785 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
786 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
787 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
788 pt
[count
- 1].X
, pt
[count
- 1].Y
);
790 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
791 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
792 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
795 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
797 PolyBezier(graphics
->hdc
, pti
, count
);
808 /* Draws a combination of bezier curves and lines between points. */
809 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
810 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
812 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
813 BYTE
*tp
= GdipAlloc(count
);
814 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
816 GpStatus status
= GenericError
;
822 if(!pti
|| !tp
|| !ptcopy
){
823 status
= OutOfMemory
;
827 for(i
= 1; i
< count
; i
++){
828 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
829 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
830 || !(types
[i
+ 1] & PathPointTypeBezier
)){
831 ERR("Bad bezier points\n");
838 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
840 /* If we are drawing caps, go through the points and adjust them accordingly,
841 * and draw the caps. */
843 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
844 case PathPointTypeBezier
:
845 if(pen
->endcap
== LineCapArrowAnchor
)
846 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
847 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
848 shorten_bezier_amt(&ptcopy
[count
- 4],
849 pen
->width
* pen
->customend
->inset
, FALSE
);
851 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
852 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
853 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
854 pt
[count
- 1].X
, pt
[count
- 1].Y
);
857 case PathPointTypeLine
:
858 if(pen
->endcap
== LineCapArrowAnchor
)
859 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
860 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
862 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
863 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
864 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
865 pen
->customend
->inset
* pen
->width
);
867 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
868 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
873 ERR("Bad path last point\n");
877 /* Find start of points */
878 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
879 == PathPointTypeStart
); j
++);
881 switch(types
[j
] & PathPointTypePathTypeMask
){
882 case PathPointTypeBezier
:
883 if(pen
->startcap
== LineCapArrowAnchor
)
884 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
885 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
886 shorten_bezier_amt(&ptcopy
[j
- 1],
887 pen
->width
* pen
->customstart
->inset
, TRUE
);
889 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
890 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
891 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
892 pt
[j
- 1].X
, pt
[j
- 1].Y
);
895 case PathPointTypeLine
:
896 if(pen
->startcap
== LineCapArrowAnchor
)
897 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
898 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
900 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
901 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
902 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
903 pen
->customstart
->inset
* pen
->width
);
905 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
906 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
911 ERR("Bad path points\n");
916 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
918 for(i
= 0; i
< count
; i
++){
919 tp
[i
] = convert_path_point_type(types
[i
]);
922 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
934 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
938 BeginPath(graphics
->hdc
);
939 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
940 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
941 EndPath(graphics
->hdc
);
945 typedef struct _GraphicsContainerItem
{
947 GraphicsContainer contid
;
949 SmoothingMode smoothing
;
950 CompositingQuality compqual
;
951 InterpolationMode interpolation
;
952 CompositingMode compmode
;
953 TextRenderingHint texthint
;
956 PixelOffsetMode pixeloffset
;
958 GpMatrix
* worldtrans
;
960 } GraphicsContainerItem
;
962 static GpStatus
init_container(GraphicsContainerItem
** container
,
963 GDIPCONST GpGraphics
* graphics
){
966 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
970 (*container
)->contid
= graphics
->contid
+ 1;
972 (*container
)->smoothing
= graphics
->smoothing
;
973 (*container
)->compqual
= graphics
->compqual
;
974 (*container
)->interpolation
= graphics
->interpolation
;
975 (*container
)->compmode
= graphics
->compmode
;
976 (*container
)->texthint
= graphics
->texthint
;
977 (*container
)->scale
= graphics
->scale
;
978 (*container
)->unit
= graphics
->unit
;
979 (*container
)->textcontrast
= graphics
->textcontrast
;
980 (*container
)->pixeloffset
= graphics
->pixeloffset
;
982 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
984 GdipFree(*container
);
989 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
991 GdipDeleteMatrix((*container
)->worldtrans
);
992 GdipFree(*container
);
1000 static void delete_container(GraphicsContainerItem
* container
){
1001 GdipDeleteMatrix(container
->worldtrans
);
1002 GdipDeleteRegion(container
->clip
);
1003 GdipFree(container
);
1006 static GpStatus
restore_container(GpGraphics
* graphics
,
1007 GDIPCONST GraphicsContainerItem
* container
){
1012 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1016 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1018 GdipDeleteMatrix(newTrans
);
1022 GdipDeleteMatrix(graphics
->worldtrans
);
1023 graphics
->worldtrans
= newTrans
;
1025 GdipDeleteRegion(graphics
->clip
);
1026 graphics
->clip
= newClip
;
1028 graphics
->contid
= container
->contid
- 1;
1030 graphics
->smoothing
= container
->smoothing
;
1031 graphics
->compqual
= container
->compqual
;
1032 graphics
->interpolation
= container
->interpolation
;
1033 graphics
->compmode
= container
->compmode
;
1034 graphics
->texthint
= container
->texthint
;
1035 graphics
->scale
= container
->scale
;
1036 graphics
->unit
= container
->unit
;
1037 graphics
->textcontrast
= container
->textcontrast
;
1038 graphics
->pixeloffset
= container
->pixeloffset
;
1043 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1045 TRACE("(%p, %p)\n", hdc
, graphics
);
1047 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1050 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1054 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1056 if(hDevice
!= NULL
) {
1057 FIXME("Don't know how to handle parameter hDevice\n");
1058 return NotImplemented
;
1064 if(graphics
== NULL
)
1065 return InvalidParameter
;
1067 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1068 if(!*graphics
) return OutOfMemory
;
1070 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1071 GdipFree(*graphics
);
1075 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1076 GdipFree((*graphics
)->worldtrans
);
1077 GdipFree(*graphics
);
1081 (*graphics
)->hdc
= hdc
;
1082 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1083 (*graphics
)->owndc
= FALSE
;
1084 (*graphics
)->smoothing
= SmoothingModeDefault
;
1085 (*graphics
)->compqual
= CompositingQualityDefault
;
1086 (*graphics
)->interpolation
= InterpolationModeDefault
;
1087 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1088 (*graphics
)->compmode
= CompositingModeSourceOver
;
1089 (*graphics
)->unit
= UnitDisplay
;
1090 (*graphics
)->scale
= 1.0;
1091 (*graphics
)->busy
= FALSE
;
1092 (*graphics
)->textcontrast
= 4;
1093 list_init(&(*graphics
)->containers
);
1094 (*graphics
)->contid
= 0;
1099 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1104 TRACE("(%p, %p)\n", hwnd
, graphics
);
1108 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1110 ReleaseDC(hwnd
, hdc
);
1114 (*graphics
)->hwnd
= hwnd
;
1115 (*graphics
)->owndc
= TRUE
;
1120 /* FIXME: no icm handling */
1121 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
1123 TRACE("(%p, %p)\n", hwnd
, graphics
);
1125 return GdipCreateFromHWND(hwnd
, graphics
);
1128 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
1129 GpMetafile
**metafile
)
1133 if(!hemf
|| !metafile
)
1134 return InvalidParameter
;
1137 FIXME("not implemented\n");
1139 return NotImplemented
;
1142 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1143 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1145 IStream
*stream
= NULL
;
1149 GpStatus retval
= GenericError
;
1151 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1153 if(!hwmf
|| !metafile
|| !placeable
)
1154 return InvalidParameter
;
1157 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1159 return GenericError
;
1160 copy
= GdipAlloc(read
);
1161 GetMetaFileBitsEx(hwmf
, read
, copy
);
1163 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1166 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1167 copy
= GdipAlloc(read
);
1168 GetEnhMetaFileBits(hemf
, read
, copy
);
1169 DeleteEnhMetaFile(hemf
);
1171 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1172 ERR("could not make stream\n");
1177 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1179 retval
= OutOfMemory
;
1183 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1184 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1188 (*metafile
)->image
.type
= ImageTypeMetafile
;
1189 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1190 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Right
) / ((REAL
) placeable
->Inch
);
1191 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1192 - placeable
->BoundingBox
.Left
)) / ((REAL
) placeable
->Inch
);
1193 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1194 - placeable
->BoundingBox
.Top
)) / ((REAL
) placeable
->Inch
);
1195 (*metafile
)->unit
= UnitInch
;
1198 DeleteMetaFile(hwmf
);
1203 GdipFree(*metafile
);
1204 IStream_Release(stream
);
1208 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1209 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1211 HMETAFILE hmf
= GetMetaFileW(file
);
1213 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1215 if(!hmf
) return InvalidParameter
;
1217 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1220 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
1221 GpMetafile
**metafile
)
1223 FIXME("(%p, %p): stub\n", file
, metafile
);
1224 return NotImplemented
;
1227 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
1228 GpMetafile
**metafile
)
1230 FIXME("(%p, %p): stub\n", stream
, metafile
);
1231 return NotImplemented
;
1234 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1235 UINT access
, IStream
**stream
)
1240 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1242 if(!stream
|| !filename
)
1243 return InvalidParameter
;
1245 if(access
& GENERIC_WRITE
)
1246 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1247 else if(access
& GENERIC_READ
)
1248 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1250 return InvalidParameter
;
1252 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1254 return hresult_to_status(ret
);
1257 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1259 GraphicsContainerItem
*cont
, *next
;
1260 TRACE("(%p)\n", graphics
);
1262 if(!graphics
) return InvalidParameter
;
1263 if(graphics
->busy
) return ObjectBusy
;
1266 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1268 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
1269 list_remove(&cont
->entry
);
1270 delete_container(cont
);
1273 GdipDeleteRegion(graphics
->clip
);
1274 GdipDeleteMatrix(graphics
->worldtrans
);
1280 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1281 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1283 INT save_state
, num_pts
;
1284 GpPointF points
[MAX_ARC_PTS
];
1287 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1288 width
, height
, startAngle
, sweepAngle
);
1290 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1291 return InvalidParameter
;
1296 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1298 save_state
= prepare_dc(graphics
, pen
);
1300 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
1302 restore_dc(graphics
, save_state
);
1307 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1308 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1310 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1311 width
, height
, startAngle
, sweepAngle
);
1313 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1316 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1317 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
1323 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
1324 x2
, y2
, x3
, y3
, x4
, y4
);
1326 if(!graphics
|| !pen
)
1327 return InvalidParameter
;
1341 save_state
= prepare_dc(graphics
, pen
);
1343 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1345 restore_dc(graphics
, save_state
);
1350 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1351 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1357 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1358 x2
, y2
, x3
, y3
, x4
, y4
);
1360 if(!graphics
|| !pen
)
1361 return InvalidParameter
;
1375 save_state
= prepare_dc(graphics
, pen
);
1377 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1379 restore_dc(graphics
, save_state
);
1384 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1385 GDIPCONST GpPointF
*points
, INT count
)
1390 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1392 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1393 return InvalidParameter
;
1398 for(i
= 0; i
< floor(count
/ 4); i
++){
1399 ret
= GdipDrawBezier(graphics
, pen
,
1400 points
[4*i
].X
, points
[4*i
].Y
,
1401 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1402 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1403 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1411 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1412 GDIPCONST GpPoint
*points
, INT count
)
1418 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1420 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1421 return InvalidParameter
;
1426 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1430 for(i
= 0; i
< count
; i
++){
1431 pts
[i
].X
= (REAL
)points
[i
].X
;
1432 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1435 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1442 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1443 GDIPCONST GpPointF
*points
, INT count
)
1445 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1447 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1450 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1451 GDIPCONST GpPoint
*points
, INT count
)
1453 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1455 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1458 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1459 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1464 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1466 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1467 return InvalidParameter
;
1472 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1475 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1477 GdipDeletePath(path
);
1481 stat
= GdipDrawPath(graphics
, pen
, path
);
1483 GdipDeletePath(path
);
1488 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1489 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1495 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1497 if(!points
|| count
<= 0)
1498 return InvalidParameter
;
1500 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1504 for(i
= 0; i
< count
; i
++){
1505 ptf
[i
].X
= (REAL
)points
[i
].X
;
1506 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1509 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1516 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1517 GDIPCONST GpPointF
*points
, INT count
)
1519 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1521 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1524 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1525 GDIPCONST GpPoint
*points
, INT count
)
1531 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1534 return InvalidParameter
;
1536 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1540 for(i
= 0; i
< count
; i
++){
1541 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1542 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1545 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1551 /* Approximates cardinal spline with Bezier curves. */
1552 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1553 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1555 /* PolyBezier expects count*3-2 points. */
1556 INT i
, len_pt
= count
*3-2, save_state
;
1558 REAL x1
, x2
, y1
, y2
;
1561 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1563 if(!graphics
|| !pen
)
1564 return InvalidParameter
;
1570 return InvalidParameter
;
1572 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1576 tension
= tension
* TENSION_CONST
;
1578 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1581 pt
[0].X
= points
[0].X
;
1582 pt
[0].Y
= points
[0].Y
;
1586 for(i
= 0; i
< count
-2; i
++){
1587 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1591 pt
[3*i
+3].X
= points
[i
+1].X
;
1592 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1597 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1598 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1600 pt
[len_pt
-2].X
= x1
;
1601 pt
[len_pt
-2].Y
= y1
;
1602 pt
[len_pt
-1].X
= points
[count
-1].X
;
1603 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1605 save_state
= prepare_dc(graphics
, pen
);
1607 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1610 restore_dc(graphics
, save_state
);
1615 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1616 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1622 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1625 return InvalidParameter
;
1627 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1631 for(i
= 0; i
< count
; i
++){
1632 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1633 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1636 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1642 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
1643 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
1646 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1648 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1649 return InvalidParameter
;
1652 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1655 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
1656 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
1659 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1665 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1666 return InvalidParameter
;
1669 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1672 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1673 REAL y
, REAL width
, REAL height
)
1679 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1681 if(!graphics
|| !pen
)
1682 return InvalidParameter
;
1689 ptf
[1].X
= x
+ width
;
1690 ptf
[1].Y
= y
+ height
;
1692 save_state
= prepare_dc(graphics
, pen
);
1693 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1695 transform_and_round_points(graphics
, pti
, ptf
, 2);
1697 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1699 restore_dc(graphics
, save_state
);
1704 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1705 INT y
, INT width
, INT height
)
1707 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1709 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1713 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1715 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1717 /* IPicture::Render uses LONG coords */
1718 return GdipDrawImageI(graphics
,image
,roundr(x
),roundr(y
));
1721 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1724 UINT width
, height
, srcw
, srch
;
1726 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1728 if(!graphics
|| !image
)
1729 return InvalidParameter
;
1731 GdipGetImageWidth(image
, &width
);
1732 GdipGetImageHeight(image
, &height
);
1734 srcw
= width
* (((REAL
) INCH_HIMETRIC
) /
1735 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
)));
1736 srch
= height
* (((REAL
) INCH_HIMETRIC
) /
1737 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
)));
1739 if(image
->type
!= ImageTypeMetafile
){
1744 IPicture_Render(image
->picture
, graphics
->hdc
, x
, y
, width
, height
,
1745 0, 0, srcw
, srch
, NULL
);
1750 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
1751 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
1754 FIXME("(%p, %p, %f, %f, %f, %f, %f, %f, %d): stub\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1755 return NotImplemented
;
1758 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
1759 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
1762 FIXME("(%p, %p, %d, %d, %d, %d, %d, %d, %d): stub\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1763 return NotImplemented
;
1766 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
1767 GDIPCONST GpPointF
*dstpoints
, INT count
)
1769 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
1770 return NotImplemented
;
1773 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
1774 GDIPCONST GpPoint
*dstpoints
, INT count
)
1776 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
1777 return NotImplemented
;
1780 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1781 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
1782 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
1783 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1784 DrawImageAbort callback
, VOID
* callbackData
)
1790 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
1791 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1794 if(!graphics
|| !image
|| !points
|| count
!= 3)
1795 return InvalidParameter
;
1797 if(srcUnit
== UnitInch
)
1798 dx
= dy
= (REAL
) INCH_HIMETRIC
;
1799 else if(srcUnit
== UnitPixel
){
1800 dx
= ((REAL
) INCH_HIMETRIC
) /
1801 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
1802 dy
= ((REAL
) INCH_HIMETRIC
) /
1803 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
1806 return NotImplemented
;
1808 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
1809 transform_and_round_points(graphics
, pti
, ptf
, 3);
1811 /* IPicture renders bitmaps with the y-axis reversed
1812 * FIXME: flipping for unknown image type might not be correct. */
1813 if(image
->type
!= ImageTypeMetafile
){
1816 pti
[0].y
= pti
[2].y
;
1820 if(IPicture_Render(image
->picture
, graphics
->hdc
,
1821 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
1822 srcx
* dx
, srcy
* dy
,
1823 srcwidth
* dx
, srcheight
* dy
,
1826 callback(callbackData
);
1827 return GenericError
;
1833 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
1834 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
1835 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1836 DrawImageAbort callback
, VOID
* callbackData
)
1838 GpPointF pointsF
[3];
1841 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
1842 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1845 if(!points
|| count
!=3)
1846 return InvalidParameter
;
1848 for(i
= 0; i
< count
; i
++){
1849 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1850 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1853 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
1854 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
1855 callback
, callbackData
);
1858 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
1859 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
1860 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
1861 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
1862 VOID
* callbackData
)
1866 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
1867 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1868 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1872 points
[1].X
= dstx
+ dstwidth
;
1875 points
[2].Y
= dsty
+ dstheight
;
1877 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1878 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1881 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
1882 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
1883 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
1884 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
1885 VOID
* callbackData
)
1889 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
1890 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1891 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1895 points
[1].X
= dstx
+ dstwidth
;
1898 points
[2].Y
= dsty
+ dstheight
;
1900 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1901 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1904 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
1905 REAL x
, REAL y
, REAL width
, REAL height
)
1911 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
1913 if(!graphics
|| !image
)
1914 return InvalidParameter
;
1916 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
1920 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
1921 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
1922 unit
, NULL
, NULL
, NULL
);
1925 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
1926 INT x
, INT y
, INT width
, INT height
)
1928 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
1930 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
1933 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1934 REAL y1
, REAL x2
, REAL y2
)
1940 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1942 if(!pen
|| !graphics
)
1943 return InvalidParameter
;
1953 save_state
= prepare_dc(graphics
, pen
);
1955 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1957 restore_dc(graphics
, save_state
);
1962 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1963 INT y1
, INT x2
, INT y2
)
1969 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1971 if(!pen
|| !graphics
)
1972 return InvalidParameter
;
1982 save_state
= prepare_dc(graphics
, pen
);
1984 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1986 restore_dc(graphics
, save_state
);
1991 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1992 GpPointF
*points
, INT count
)
1997 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1999 if(!pen
|| !graphics
|| (count
< 2))
2000 return InvalidParameter
;
2005 save_state
= prepare_dc(graphics
, pen
);
2007 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
2009 restore_dc(graphics
, save_state
);
2014 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2015 GpPoint
*points
, INT count
)
2019 GpPointF
*ptf
= NULL
;
2022 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2024 if(!pen
|| !graphics
|| (count
< 2))
2025 return InvalidParameter
;
2030 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2031 if(!ptf
) return OutOfMemory
;
2033 for(i
= 0; i
< count
; i
++){
2034 ptf
[i
].X
= (REAL
) points
[i
].X
;
2035 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2038 save_state
= prepare_dc(graphics
, pen
);
2040 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
2042 restore_dc(graphics
, save_state
);
2048 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
2053 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
2055 if(!pen
|| !graphics
)
2056 return InvalidParameter
;
2061 save_state
= prepare_dc(graphics
, pen
);
2063 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
2064 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
2066 restore_dc(graphics
, save_state
);
2071 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2072 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2076 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2077 width
, height
, startAngle
, sweepAngle
);
2079 if(!graphics
|| !pen
)
2080 return InvalidParameter
;
2085 save_state
= prepare_dc(graphics
, pen
);
2086 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2088 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2090 restore_dc(graphics
, save_state
);
2095 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2096 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2098 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2099 width
, height
, startAngle
, sweepAngle
);
2101 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2104 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2105 REAL y
, REAL width
, REAL height
)
2111 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2113 if(!pen
|| !graphics
)
2114 return InvalidParameter
;
2121 ptf
[1].X
= x
+ width
;
2123 ptf
[2].X
= x
+ width
;
2124 ptf
[2].Y
= y
+ height
;
2126 ptf
[3].Y
= y
+ height
;
2128 save_state
= prepare_dc(graphics
, pen
);
2129 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2131 transform_and_round_points(graphics
, pti
, ptf
, 4);
2132 Polygon(graphics
->hdc
, pti
, 4);
2134 restore_dc(graphics
, save_state
);
2139 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2140 INT y
, INT width
, INT height
)
2142 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2144 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2147 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
2148 GDIPCONST GpRectF
* rects
, INT count
)
2154 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2156 if(!graphics
|| !pen
|| !rects
|| count
< 1)
2157 return InvalidParameter
;
2162 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
2163 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
2171 for(i
= 0; i
< count
; i
++){
2172 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
2173 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
2174 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
2175 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
2178 save_state
= prepare_dc(graphics
, pen
);
2179 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2181 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
2183 for(i
= 0; i
< count
; i
++)
2184 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
2186 restore_dc(graphics
, save_state
);
2194 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
2195 GDIPCONST GpRect
* rects
, INT count
)
2201 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2203 if(!rects
|| count
<=0)
2204 return InvalidParameter
;
2206 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
2210 for(i
= 0;i
< count
;i
++){
2211 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2212 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2213 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2214 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2217 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
2223 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
2224 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
2225 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
2230 TEXTMETRICW textmet
;
2231 GpPointF pt
[2], rectcpy
[4];
2234 REAL angle
, ang_cos
, ang_sin
, rel_width
, rel_height
;
2235 INT sum
= 0, height
= 0, offsety
= 0, fit
, fitcpy
, save_state
, i
, j
, lret
, nwidth
,
2242 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
2243 length
, font
, debugstr_rectf(rect
), format
, brush
);
2245 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
2246 return InvalidParameter
;
2248 if((brush
->bt
!= BrushTypeSolidColor
)){
2249 FIXME("not implemented for given parameters\n");
2250 return NotImplemented
;
2254 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
2256 /* Should be no need to explicitly test for StringAlignmentNear as
2257 * that is default behavior if no alignment is passed. */
2258 if(format
->vertalign
!= StringAlignmentNear
){
2260 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
2262 if(format
->vertalign
== StringAlignmentCenter
)
2263 offsety
= (rect
->Height
- bounds
.Height
) / 2;
2264 else if(format
->vertalign
== StringAlignmentFar
)
2265 offsety
= (rect
->Height
- bounds
.Height
);
2269 if(length
== -1) length
= lstrlenW(string
);
2271 stringdup
= GdipAlloc(length
* sizeof(WCHAR
));
2272 if(!stringdup
) return OutOfMemory
;
2274 save_state
= SaveDC(graphics
->hdc
);
2275 SetBkMode(graphics
->hdc
, TRANSPARENT
);
2276 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
2278 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
2279 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
2280 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
2281 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
2282 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
2284 if (roundr(rect
->Width
) == 0)
2291 rel_width
= sqrt((corners
[1].x
- corners
[0].x
) * (corners
[1].x
- corners
[0].x
) +
2292 (corners
[1].y
- corners
[0].y
) * (corners
[1].y
- corners
[0].y
))
2294 nwidth
= roundr(rel_width
* rect
->Width
);
2297 if (roundr(rect
->Height
) == 0)
2304 rel_height
= sqrt((corners
[2].x
- corners
[1].x
) * (corners
[2].x
- corners
[1].x
) +
2305 (corners
[2].y
- corners
[1].y
) * (corners
[2].y
- corners
[1].y
))
2307 nheight
= roundr(rel_height
* rect
->Height
);
2310 if (roundr(rect
->Width
) != 0 && roundr(rect
->Height
) != 0)
2312 /* FIXME: If only the width or only the height is 0, we should probably still clip */
2313 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
2314 SelectClipRgn(graphics
->hdc
, rgn
);
2317 /* Use gdi to find the font, then perform transformations on it (height,
2319 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2320 GetTextMetricsW(graphics
->hdc
, &textmet
);
2323 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
2324 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
2330 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
2331 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2332 ang_cos
= cos(angle
);
2333 ang_sin
= sin(angle
);
2334 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
2336 gdifont
= CreateFontIndirectW(&lfw
);
2337 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
2339 for(i
= 0, j
= 0; i
< length
; i
++){
2340 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
2343 stringdup
[j
] = string
[i
];
2349 if (!format
|| format
->align
== StringAlignmentNear
)
2351 drawbase
.x
= corners
[0].x
;
2352 drawbase
.y
= corners
[0].y
;
2353 drawflags
= DT_NOCLIP
| DT_EXPANDTABS
;
2355 else if (format
->align
== StringAlignmentCenter
)
2357 drawbase
.x
= (corners
[0].x
+ corners
[1].x
)/2;
2358 drawbase
.y
= (corners
[0].y
+ corners
[1].y
)/2;
2359 drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_CENTER
;
2361 else /* (format->align == StringAlignmentFar) */
2363 drawbase
.x
= corners
[1].x
;
2364 drawbase
.y
= corners
[1].y
;
2365 drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_RIGHT
;
2368 while(sum
< length
){
2369 drawcoord
.left
= drawcoord
.right
= drawbase
.x
+ roundr(ang_sin
* (REAL
) height
);
2370 drawcoord
.top
= drawcoord
.bottom
= drawbase
.y
+ roundr(ang_cos
* (REAL
) height
);
2372 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
2373 nwidth
, &fit
, NULL
, &size
);
2377 DrawTextW(graphics
->hdc
, stringdup
+ sum
, 1, &drawcoord
, drawflags
);
2381 for(lret
= 0; lret
< fit
; lret
++)
2382 if(*(stringdup
+ sum
+ lret
) == '\n')
2385 /* Line break code (may look strange, but it imitates windows). */
2387 lineend
= fit
= lret
; /* this is not an off-by-one error */
2388 else if(fit
< (length
- sum
)){
2389 if(*(stringdup
+ sum
+ fit
) == ' ')
2390 while(*(stringdup
+ sum
+ fit
) == ' ')
2393 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
2396 if(*(stringdup
+ sum
+ fit
) == '\t')
2405 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
2406 *(stringdup
+ sum
+ lineend
- 1) == '\t')
2411 DrawTextW(graphics
->hdc
, stringdup
+ sum
, min(length
- sum
, lineend
),
2412 &drawcoord
, drawflags
);
2414 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
2417 if(height
> nheight
)
2420 /* Stop if this was a linewrap (but not if it was a linebreak). */
2421 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
2425 GdipFree(stringdup
);
2427 DeleteObject(gdifont
);
2429 RestoreDC(graphics
->hdc
, save_state
);
2434 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
2435 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
2440 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2441 count
, tension
, fill
);
2443 if(!graphics
|| !brush
|| !points
)
2444 return InvalidParameter
;
2449 stat
= GdipCreatePath(fill
, &path
);
2453 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2455 GdipDeletePath(path
);
2459 stat
= GdipFillPath(graphics
, brush
, path
);
2461 GdipDeletePath(path
);
2465 GdipDeletePath(path
);
2470 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
2471 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2477 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2478 count
, tension
, fill
);
2480 if(!points
|| count
<= 0)
2481 return InvalidParameter
;
2483 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2487 for(i
= 0;i
< count
;i
++){
2488 ptf
[i
].X
= (REAL
)points
[i
].X
;
2489 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2492 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2499 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2500 REAL y
, REAL width
, REAL height
)
2506 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2508 if(!graphics
|| !brush
)
2509 return InvalidParameter
;
2516 ptf
[1].X
= x
+ width
;
2517 ptf
[1].Y
= y
+ height
;
2519 save_state
= SaveDC(graphics
->hdc
);
2520 EndPath(graphics
->hdc
);
2522 transform_and_round_points(graphics
, pti
, ptf
, 2);
2524 BeginPath(graphics
->hdc
);
2525 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2526 EndPath(graphics
->hdc
);
2528 brush_fill_path(graphics
, brush
);
2530 RestoreDC(graphics
->hdc
, save_state
);
2535 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2536 INT y
, INT width
, INT height
)
2538 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2540 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2543 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2548 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2550 if(!brush
|| !graphics
|| !path
)
2551 return InvalidParameter
;
2556 save_state
= SaveDC(graphics
->hdc
);
2557 EndPath(graphics
->hdc
);
2558 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2561 BeginPath(graphics
->hdc
);
2562 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2563 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2568 EndPath(graphics
->hdc
);
2569 brush_fill_path(graphics
, brush
);
2574 RestoreDC(graphics
->hdc
, save_state
);
2579 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2580 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2584 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2585 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2587 if(!graphics
|| !brush
)
2588 return InvalidParameter
;
2593 save_state
= SaveDC(graphics
->hdc
);
2594 EndPath(graphics
->hdc
);
2596 BeginPath(graphics
->hdc
);
2597 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2598 EndPath(graphics
->hdc
);
2600 brush_fill_path(graphics
, brush
);
2602 RestoreDC(graphics
->hdc
, save_state
);
2607 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2608 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2610 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2611 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2613 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2616 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
2617 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
2620 GpPointF
*ptf
= NULL
;
2622 GpStatus retval
= Ok
;
2624 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2626 if(!graphics
|| !brush
|| !points
|| !count
)
2627 return InvalidParameter
;
2632 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2633 pti
= GdipAlloc(count
* sizeof(POINT
));
2635 retval
= OutOfMemory
;
2639 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
2641 save_state
= SaveDC(graphics
->hdc
);
2642 EndPath(graphics
->hdc
);
2643 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2646 transform_and_round_points(graphics
, pti
, ptf
, count
);
2648 BeginPath(graphics
->hdc
);
2649 Polygon(graphics
->hdc
, pti
, count
);
2650 EndPath(graphics
->hdc
);
2652 brush_fill_path(graphics
, brush
);
2654 RestoreDC(graphics
->hdc
, save_state
);
2663 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
2664 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
2667 GpPointF
*ptf
= NULL
;
2669 GpStatus retval
= Ok
;
2671 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2673 if(!graphics
|| !brush
|| !points
|| !count
)
2674 return InvalidParameter
;
2679 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2680 pti
= GdipAlloc(count
* sizeof(POINT
));
2682 retval
= OutOfMemory
;
2686 for(i
= 0; i
< count
; i
++){
2687 ptf
[i
].X
= (REAL
) points
[i
].X
;
2688 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2691 save_state
= SaveDC(graphics
->hdc
);
2692 EndPath(graphics
->hdc
);
2693 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2696 transform_and_round_points(graphics
, pti
, ptf
, count
);
2698 BeginPath(graphics
->hdc
);
2699 Polygon(graphics
->hdc
, pti
, count
);
2700 EndPath(graphics
->hdc
);
2702 brush_fill_path(graphics
, brush
);
2704 RestoreDC(graphics
->hdc
, save_state
);
2713 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
2714 GDIPCONST GpPointF
*points
, INT count
)
2716 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2718 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
2721 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
2722 GDIPCONST GpPoint
*points
, INT count
)
2724 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2726 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
2729 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
2730 REAL x
, REAL y
, REAL width
, REAL height
)
2736 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2738 if(!graphics
|| !brush
)
2739 return InvalidParameter
;
2746 ptf
[1].X
= x
+ width
;
2748 ptf
[2].X
= x
+ width
;
2749 ptf
[2].Y
= y
+ height
;
2751 ptf
[3].Y
= y
+ height
;
2753 save_state
= SaveDC(graphics
->hdc
);
2754 EndPath(graphics
->hdc
);
2756 transform_and_round_points(graphics
, pti
, ptf
, 4);
2758 BeginPath(graphics
->hdc
);
2759 Polygon(graphics
->hdc
, pti
, 4);
2760 EndPath(graphics
->hdc
);
2762 brush_fill_path(graphics
, brush
);
2764 RestoreDC(graphics
->hdc
, save_state
);
2769 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
2770 INT x
, INT y
, INT width
, INT height
)
2776 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2778 if(!graphics
|| !brush
)
2779 return InvalidParameter
;
2786 ptf
[1].X
= x
+ width
;
2788 ptf
[2].X
= x
+ width
;
2789 ptf
[2].Y
= y
+ height
;
2791 ptf
[3].Y
= y
+ height
;
2793 save_state
= SaveDC(graphics
->hdc
);
2794 EndPath(graphics
->hdc
);
2796 transform_and_round_points(graphics
, pti
, ptf
, 4);
2798 BeginPath(graphics
->hdc
);
2799 Polygon(graphics
->hdc
, pti
, 4);
2800 EndPath(graphics
->hdc
);
2802 brush_fill_path(graphics
, brush
);
2804 RestoreDC(graphics
->hdc
, save_state
);
2809 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
2815 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2818 return InvalidParameter
;
2820 for(i
= 0; i
< count
; i
++){
2821 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2822 if(ret
!= Ok
) return ret
;
2828 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
2835 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2837 if(!rects
|| count
<= 0)
2838 return InvalidParameter
;
2840 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
2844 for(i
= 0; i
< count
; i
++){
2845 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2846 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2847 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
2848 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2851 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
2857 /*****************************************************************************
2858 * GdipFillRegion [GDIPLUS.@]
2860 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
2868 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
2870 if (!(graphics
&& brush
&& region
))
2871 return InvalidParameter
;
2876 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
2880 save_state
= SaveDC(graphics
->hdc
);
2881 EndPath(graphics
->hdc
);
2883 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
2885 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
2887 BeginPath(graphics
->hdc
);
2888 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2889 EndPath(graphics
->hdc
);
2891 brush_fill_path(graphics
, brush
);
2894 RestoreDC(graphics
->hdc
, save_state
);
2901 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
2906 return InvalidParameter
;
2912 FIXME("not implemented\n");
2914 return NotImplemented
;
2917 /*****************************************************************************
2918 * GdipGetClipBounds [GDIPLUS.@]
2920 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
2922 TRACE("(%p, %p)\n", graphics
, rect
);
2925 return InvalidParameter
;
2930 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
2933 /*****************************************************************************
2934 * GdipGetClipBoundsI [GDIPLUS.@]
2936 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
2938 TRACE("(%p, %p)\n", graphics
, rect
);
2941 return InvalidParameter
;
2946 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
2949 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
2950 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
2951 CompositingMode
*mode
)
2953 TRACE("(%p, %p)\n", graphics
, mode
);
2955 if(!graphics
|| !mode
)
2956 return InvalidParameter
;
2961 *mode
= graphics
->compmode
;
2966 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
2967 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
2968 CompositingQuality
*quality
)
2970 TRACE("(%p, %p)\n", graphics
, quality
);
2972 if(!graphics
|| !quality
)
2973 return InvalidParameter
;
2978 *quality
= graphics
->compqual
;
2983 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
2984 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
2985 InterpolationMode
*mode
)
2987 TRACE("(%p, %p)\n", graphics
, mode
);
2989 if(!graphics
|| !mode
)
2990 return InvalidParameter
;
2995 *mode
= graphics
->interpolation
;
3000 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
3002 if(!graphics
|| !argb
)
3003 return InvalidParameter
;
3008 FIXME("(%p, %p): stub\n", graphics
, argb
);
3010 return NotImplemented
;
3013 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
3015 TRACE("(%p, %p)\n", graphics
, scale
);
3017 if(!graphics
|| !scale
)
3018 return InvalidParameter
;
3023 *scale
= graphics
->scale
;
3028 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
3030 TRACE("(%p, %p)\n", graphics
, unit
);
3032 if(!graphics
|| !unit
)
3033 return InvalidParameter
;
3038 *unit
= graphics
->unit
;
3043 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3044 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3047 TRACE("(%p, %p)\n", graphics
, mode
);
3049 if(!graphics
|| !mode
)
3050 return InvalidParameter
;
3055 *mode
= graphics
->pixeloffset
;
3060 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3061 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
3063 TRACE("(%p, %p)\n", graphics
, mode
);
3065 if(!graphics
|| !mode
)
3066 return InvalidParameter
;
3071 *mode
= graphics
->smoothing
;
3076 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
3078 TRACE("(%p, %p)\n", graphics
, contrast
);
3080 if(!graphics
|| !contrast
)
3081 return InvalidParameter
;
3083 *contrast
= graphics
->textcontrast
;
3088 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3089 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
3090 TextRenderingHint
*hint
)
3092 TRACE("(%p, %p)\n", graphics
, hint
);
3094 if(!graphics
|| !hint
)
3095 return InvalidParameter
;
3100 *hint
= graphics
->texthint
;
3105 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3107 TRACE("(%p, %p)\n", graphics
, matrix
);
3109 if(!graphics
|| !matrix
)
3110 return InvalidParameter
;
3115 *matrix
= *graphics
->worldtrans
;
3119 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
3125 TRACE("(%p, %x)\n", graphics
, color
);
3128 return InvalidParameter
;
3133 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
3137 if(!GetWindowRect(graphics
->hwnd
, &rect
)){
3138 GdipDeleteBrush((GpBrush
*)brush
);
3139 return GenericError
;
3142 GdipFillRectangle(graphics
, (GpBrush
*)brush
, 0.0, 0.0, (REAL
)(rect
.right
- rect
.left
),
3143 (REAL
)(rect
.bottom
- rect
.top
));
3146 GdipFillRectangle(graphics
, (GpBrush
*)brush
, 0.0, 0.0, (REAL
)GetDeviceCaps(graphics
->hdc
, HORZRES
),
3147 (REAL
)GetDeviceCaps(graphics
->hdc
, VERTRES
));
3149 GdipDeleteBrush((GpBrush
*)brush
);
3154 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
3156 TRACE("(%p, %p)\n", graphics
, res
);
3158 if(!graphics
|| !res
)
3159 return InvalidParameter
;
3161 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
3164 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
3166 FIXME("(%p, %.2f, %.2f, %p) stub\n", graphics
, x
, y
, result
);
3168 if(!graphics
|| !result
)
3169 return InvalidParameter
;
3174 return NotImplemented
;
3177 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
3179 FIXME("(%p, %d, %d, %p) stub\n", graphics
, x
, y
, result
);
3181 if(!graphics
|| !result
)
3182 return InvalidParameter
;
3187 return NotImplemented
;
3190 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
3191 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
3192 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
3193 INT regionCount
, GpRegion
** regions
)
3195 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
3196 return InvalidParameter
;
3198 FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics
, debugstr_w(string
),
3199 length
, font
, layoutRect
, stringFormat
, regionCount
, regions
);
3201 return NotImplemented
;
3204 /* Find the smallest rectangle that bounds the text when it is printed in rect
3205 * according to the format options listed in format. If rect has 0 width and
3206 * height, then just find the smallest rectangle that bounds the text when it's
3207 * printed at location (rect->X, rect-Y). */
3208 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
3209 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
3210 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
3211 INT
*codepointsfitted
, INT
*linesfilled
)
3215 INT sum
= 0, height
= 0, fit
, fitcpy
, max_width
= 0, i
, j
, lret
, nwidth
,
3219 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
3220 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
3221 bounds
, codepointsfitted
, linesfilled
);
3223 if(!graphics
|| !string
|| !font
|| !rect
)
3224 return InvalidParameter
;
3226 if(linesfilled
) *linesfilled
= 0;
3227 if(codepointsfitted
) *codepointsfitted
= 0;
3230 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
3232 if(length
== -1) length
= lstrlenW(string
);
3234 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
3235 if(!stringdup
) return OutOfMemory
;
3237 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
3238 nwidth
= roundr(rect
->Width
);
3239 nheight
= roundr(rect
->Height
);
3241 if((nwidth
== 0) && (nheight
== 0))
3242 nwidth
= nheight
= INT_MAX
;
3244 for(i
= 0, j
= 0; i
< length
; i
++){
3245 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
3248 stringdup
[j
] = string
[i
];
3255 while(sum
< length
){
3256 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
3257 nwidth
, &fit
, NULL
, &size
);
3263 for(lret
= 0; lret
< fit
; lret
++)
3264 if(*(stringdup
+ sum
+ lret
) == '\n')
3267 /* Line break code (may look strange, but it imitates windows). */
3269 lineend
= fit
= lret
; /* this is not an off-by-one error */
3270 else if(fit
< (length
- sum
)){
3271 if(*(stringdup
+ sum
+ fit
) == ' ')
3272 while(*(stringdup
+ sum
+ fit
) == ' ')
3275 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
3278 if(*(stringdup
+ sum
+ fit
) == '\t')
3287 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
3288 *(stringdup
+ sum
+ lineend
- 1) == '\t')
3294 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, lineend
,
3295 nwidth
, &j
, NULL
, &size
);
3297 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
3298 if(codepointsfitted
) *codepointsfitted
= sum
;
3301 if(linesfilled
) *linesfilled
+= size
.cy
;
3302 max_width
= max(max_width
, size
.cx
);
3304 if(height
> nheight
)
3307 /* Stop if this was a linewrap (but not if it was a linebreak). */
3308 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
3312 bounds
->X
= rect
->X
;
3313 bounds
->Y
= rect
->Y
;
3314 bounds
->Width
= (REAL
)max_width
;
3315 bounds
->Height
= (REAL
) min(height
, nheight
);
3317 GdipFree(stringdup
);
3318 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3323 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
3325 TRACE("(%p)\n", graphics
);
3328 return InvalidParameter
;
3333 return GdipSetInfinite(graphics
->clip
);
3336 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
3338 TRACE("(%p)\n", graphics
);
3341 return InvalidParameter
;
3346 graphics
->worldtrans
->matrix
[0] = 1.0;
3347 graphics
->worldtrans
->matrix
[1] = 0.0;
3348 graphics
->worldtrans
->matrix
[2] = 0.0;
3349 graphics
->worldtrans
->matrix
[3] = 1.0;
3350 graphics
->worldtrans
->matrix
[4] = 0.0;
3351 graphics
->worldtrans
->matrix
[5] = 0.0;
3356 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
3358 return GdipEndContainer(graphics
, state
);
3361 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
3362 GpMatrixOrder order
)
3364 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
3367 return InvalidParameter
;
3372 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
3375 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
3377 return GdipBeginContainer2(graphics
, state
);
3380 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
3381 GraphicsContainer
*state
)
3383 GraphicsContainerItem
*container
;
3386 TRACE("(%p, %p)\n", graphics
, state
);
3388 if(!graphics
|| !state
)
3389 return InvalidParameter
;
3391 sts
= init_container(&container
, graphics
);
3395 list_add_head(&graphics
->containers
, &container
->entry
);
3396 *state
= graphics
->contid
= container
->contid
;
3401 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
3403 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
3404 return NotImplemented
;
3407 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
3409 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
3410 return NotImplemented
;
3413 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
3415 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
3416 return NotImplemented
;
3419 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
3422 GraphicsContainerItem
*container
, *container2
;
3424 TRACE("(%p, %x)\n", graphics
, state
);
3427 return InvalidParameter
;
3429 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
3430 if(container
->contid
== state
)
3434 /* did not find a matching container */
3435 if(&container
->entry
== &graphics
->containers
)
3438 sts
= restore_container(graphics
, container
);
3442 /* remove all of the containers on top of the found container */
3443 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
3444 if(container
->contid
== state
)
3446 list_remove(&container
->entry
);
3447 delete_container(container
);
3450 list_remove(&container
->entry
);
3451 delete_container(container
);
3456 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
3457 REAL sy
, GpMatrixOrder order
)
3459 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
3462 return InvalidParameter
;
3467 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
3470 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
3473 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
3475 if(!graphics
|| !srcgraphics
)
3476 return InvalidParameter
;
3478 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
3481 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
3482 CompositingMode mode
)
3484 TRACE("(%p, %d)\n", graphics
, mode
);
3487 return InvalidParameter
;
3492 graphics
->compmode
= mode
;
3497 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
3498 CompositingQuality quality
)
3500 TRACE("(%p, %d)\n", graphics
, quality
);
3503 return InvalidParameter
;
3508 graphics
->compqual
= quality
;
3513 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
3514 InterpolationMode mode
)
3516 TRACE("(%p, %d)\n", graphics
, mode
);
3519 return InvalidParameter
;
3524 graphics
->interpolation
= mode
;
3529 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
3531 TRACE("(%p, %.2f)\n", graphics
, scale
);
3533 if(!graphics
|| (scale
<= 0.0))
3534 return InvalidParameter
;
3539 graphics
->scale
= scale
;
3544 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
3546 TRACE("(%p, %d)\n", graphics
, unit
);
3549 return InvalidParameter
;
3554 if(unit
== UnitWorld
)
3555 return InvalidParameter
;
3557 graphics
->unit
= unit
;
3562 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3565 TRACE("(%p, %d)\n", graphics
, mode
);
3568 return InvalidParameter
;
3573 graphics
->pixeloffset
= mode
;
3578 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
3582 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
3585 FIXME("not implemented\n");
3587 return NotImplemented
;
3590 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
3592 TRACE("(%p, %d)\n", graphics
, mode
);
3595 return InvalidParameter
;
3600 graphics
->smoothing
= mode
;
3605 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
3607 TRACE("(%p, %d)\n", graphics
, contrast
);
3610 return InvalidParameter
;
3612 graphics
->textcontrast
= contrast
;
3617 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
3618 TextRenderingHint hint
)
3620 TRACE("(%p, %d)\n", graphics
, hint
);
3623 return InvalidParameter
;
3628 graphics
->texthint
= hint
;
3633 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3635 TRACE("(%p, %p)\n", graphics
, matrix
);
3637 if(!graphics
|| !matrix
)
3638 return InvalidParameter
;
3643 GdipDeleteMatrix(graphics
->worldtrans
);
3644 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
3647 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
3648 REAL dy
, GpMatrixOrder order
)
3650 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
3653 return InvalidParameter
;
3658 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
3661 /*****************************************************************************
3662 * GdipSetClipHrgn [GDIPLUS.@]
3664 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
3669 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
3672 return InvalidParameter
;
3674 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
3678 status
= GdipSetClipRegion(graphics
, region
, mode
);
3680 GdipDeleteRegion(region
);
3684 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
3686 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
3689 return InvalidParameter
;
3694 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
3697 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
3698 REAL width
, REAL height
,
3703 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3706 return InvalidParameter
;
3714 rect
.Height
= height
;
3716 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
3719 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
3720 INT width
, INT height
,
3723 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3726 return InvalidParameter
;
3731 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
3734 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
3737 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
3739 if(!graphics
|| !region
)
3740 return InvalidParameter
;
3745 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
3748 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
3754 FIXME("not implemented\n");
3756 return NotImplemented
;
3759 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
3765 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
3767 if(!graphics
|| !pen
|| count
<=0)
3768 return InvalidParameter
;
3773 pti
= GdipAlloc(sizeof(POINT
) * count
);
3775 save_state
= prepare_dc(graphics
, pen
);
3776 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3778 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
3779 Polygon(graphics
->hdc
, pti
, count
);
3781 restore_dc(graphics
, save_state
);
3787 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
3794 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3796 if(count
<=0) return InvalidParameter
;
3797 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
3799 for(i
= 0;i
< count
; i
++){
3800 ptf
[i
].X
= (REAL
)points
[i
].X
;
3801 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3804 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
3810 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
3812 TRACE("(%p, %p)\n", graphics
, dpi
);
3814 if(!graphics
|| !dpi
)
3815 return InvalidParameter
;
3820 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
3825 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
3827 TRACE("(%p, %p)\n", graphics
, dpi
);
3829 if(!graphics
|| !dpi
)
3830 return InvalidParameter
;
3835 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
3840 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
3841 GpMatrixOrder order
)
3846 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
3848 if(!graphics
|| !matrix
)
3849 return InvalidParameter
;
3854 m
= *(graphics
->worldtrans
);
3856 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
3858 *(graphics
->worldtrans
) = m
;
3863 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
3865 TRACE("(%p, %p)\n", graphics
, hdc
);
3867 if(!graphics
|| !hdc
)
3868 return InvalidParameter
;
3873 *hdc
= graphics
->hdc
;
3874 graphics
->busy
= TRUE
;
3879 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
3881 TRACE("(%p, %p)\n", graphics
, hdc
);
3884 return InvalidParameter
;
3886 if(graphics
->hdc
!= hdc
|| !(graphics
->busy
))
3887 return InvalidParameter
;
3889 graphics
->busy
= FALSE
;
3894 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
3899 TRACE("(%p, %p)\n", graphics
, region
);
3901 if(!graphics
|| !region
)
3902 return InvalidParameter
;
3907 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
3910 /* free everything except root node and header */
3911 delete_element(®ion
->node
);
3912 memcpy(region
, clip
, sizeof(GpRegion
));
3917 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3918 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
3924 if(!graphics
|| !points
|| count
<= 0)
3925 return InvalidParameter
;
3930 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
3932 if (src_space
== dst_space
) return Ok
;
3934 stat
= GdipCreateMatrix(&matrix
);
3937 unitscale
= convert_unit(graphics
->hdc
, graphics
->unit
);
3939 if(graphics
->unit
!= UnitDisplay
)
3940 unitscale
*= graphics
->scale
;
3942 /* transform from src_space to CoordinateSpacePage */
3945 case CoordinateSpaceWorld
:
3946 GdipMultiplyMatrix(matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
3948 case CoordinateSpacePage
:
3950 case CoordinateSpaceDevice
:
3951 GdipScaleMatrix(matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
3955 /* transform from CoordinateSpacePage to dst_space */
3958 case CoordinateSpaceWorld
:
3960 GpMatrix
*inverted_transform
;
3961 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
3964 stat
= GdipInvertMatrix(inverted_transform
);
3966 GdipMultiplyMatrix(matrix
, inverted_transform
, MatrixOrderAppend
);
3967 GdipDeleteMatrix(inverted_transform
);
3971 case CoordinateSpacePage
:
3973 case CoordinateSpaceDevice
:
3974 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
3979 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
3981 GdipDeleteMatrix(matrix
);
3987 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3988 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
3994 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
3997 return InvalidParameter
;
3999 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
4003 for(i
= 0; i
< count
; i
++){
4004 pointsF
[i
].X
= (REAL
)points
[i
].X
;
4005 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
4008 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
4011 for(i
= 0; i
< count
; i
++){
4012 points
[i
].X
= roundr(pointsF
[i
].X
);
4013 points
[i
].Y
= roundr(pointsF
[i
].Y
);
4020 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
4027 /*****************************************************************************
4028 * GdipTranslateClip [GDIPLUS.@]
4030 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
4032 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
4035 return InvalidParameter
;
4040 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
4043 /*****************************************************************************
4044 * GdipTranslateClipI [GDIPLUS.@]
4046 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
4048 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
4051 return InvalidParameter
;
4056 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
4060 /*****************************************************************************
4061 * GdipMeasureDriverString [GDIPLUS.@]
4063 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
4064 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
4065 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
4067 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
4068 return NotImplemented
;
4071 /*****************************************************************************
4072 * GdipGetVisibleClipBoundsI [GDIPLUS.@]
4074 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
4076 FIXME("(%p %p): stub\n", graphics
, rect
);
4077 return NotImplemented
;
4080 /*****************************************************************************
4081 * GdipDrawDriverString [GDIPLUS.@]
4083 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
4084 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
4085 GDIPCONST PointF
*positions
, INT flags
,
4086 GDIPCONST GpMatrix
*matrix
)
4088 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics
, text
, length
, font
, brush
, positions
, flags
, matrix
);
4089 return NotImplemented
;
4092 /*****************************************************************************
4093 * GdipIsVisibleRegionPointI [GDIPLUS.@]
4095 GpStatus WINGDIPAPI
GdipIsVisibleRegionPointI(GpRegion
*region
, INT x
, INT y
, GpGraphics
*graphics
, BOOL
*result
)
4097 FIXME("(%p %d %d %p %p): stub\n", region
, x
, y
, graphics
, result
);
4098 return NotImplemented
;