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"
42 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
44 /* looks-right constants */
45 #define ANCHOR_WIDTH (2.0)
46 #define MAX_ITERS (50)
48 /* Converts angle (in degrees) to x/y coordinates */
49 static void deg2xy(REAL angle
, REAL x_0
, REAL y_0
, REAL
*x
, REAL
*y
)
51 REAL radAngle
, hypotenuse
;
53 radAngle
= deg2rad(angle
);
54 hypotenuse
= 50.0; /* arbitrary */
56 *x
= x_0
+ cos(radAngle
) * hypotenuse
;
57 *y
= y_0
+ sin(radAngle
) * hypotenuse
;
60 /* Converts from gdiplus path point type to gdi path point type. */
61 static BYTE
convert_path_point_type(BYTE type
)
65 switch(type
& PathPointTypePathTypeMask
){
66 case PathPointTypeBezier
:
69 case PathPointTypeLine
:
72 case PathPointTypeStart
:
76 ERR("Bad point type\n");
80 if(type
& PathPointTypeCloseSubpath
)
81 ret
|= PT_CLOSEFIGURE
;
86 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
90 INT save_state
= SaveDC(graphics
->hdc
), i
, numdashes
;
92 DWORD dash_array
[MAX_DASHLEN
];
94 EndPath(graphics
->hdc
);
96 if(pen
->unit
== UnitPixel
){
100 /* Get an estimate for the amount the pen width is affected by the world
101 * transform. (This is similar to what some of the wine drivers do.) */
106 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
107 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
108 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
110 width
*= pen
->width
* convert_unit(graphics
->hdc
,
111 pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
);
114 if(pen
->dash
== DashStyleCustom
){
115 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
117 TRACE("dashes are: ");
118 for(i
= 0; i
< numdashes
; i
++){
119 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
120 TRACE("%d, ", dash_array
[i
]);
122 TRACE("\n and the pen style is %x\n", pen
->style
);
124 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
,
125 numdashes
, dash_array
);
128 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
, 0, NULL
);
130 SelectObject(graphics
->hdc
, gdipen
);
135 static void restore_dc(GpGraphics
*graphics
, INT state
)
137 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
138 RestoreDC(graphics
->hdc
, state
);
141 /* This helper applies all the changes that the points listed in ptf need in
142 * order to be drawn on the device context. In the end, this should include at
144 * -scaling by page unit
145 * -applying world transformation
146 * -converting from float to int
147 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
148 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
149 * gdi to draw, and these functions would irreparably mess with line widths.
151 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
152 GpPointF
*ptf
, INT count
)
158 unitscale
= convert_unit(graphics
->hdc
, graphics
->unit
);
160 /* apply page scale */
161 if(graphics
->unit
!= UnitDisplay
)
162 unitscale
*= graphics
->scale
;
164 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
165 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
166 GdipTransformMatrixPoints(matrix
, ptf
, count
);
167 GdipDeleteMatrix(matrix
);
169 for(i
= 0; i
< count
; i
++){
170 pti
[i
].x
= roundr(ptf
[i
].X
);
171 pti
[i
].y
= roundr(ptf
[i
].Y
);
175 /* GdipDrawPie/GdipFillPie helper function */
176 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
177 REAL height
, REAL startAngle
, REAL sweepAngle
)
184 ptf
[1].X
= x
+ width
;
185 ptf
[1].Y
= y
+ height
;
187 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
188 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
190 transform_and_round_points(graphics
, pti
, ptf
, 4);
192 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
193 pti
[2].y
, pti
[3].x
, pti
[3].y
);
196 /* Draws the linecap the specified color and size on the hdc. The linecap is in
197 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
198 * should not be called on an hdc that has a path you care about. */
199 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
200 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
202 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
203 GpMatrix
*matrix
= NULL
;
206 PointF ptf
[4], *custptf
= NULL
;
207 POINT pt
[4], *custpt
= NULL
;
209 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
214 if((x1
== x2
) && (y1
== y2
))
217 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
219 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
221 brush
= CreateSolidBrush(color
);
222 lb
.lbStyle
= BS_SOLID
;
225 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
226 PS_JOIN_MITER
, 1, &lb
, 0,
228 oldbrush
= SelectObject(graphics
->hdc
, brush
);
229 oldpen
= SelectObject(graphics
->hdc
, pen
);
236 case LineCapSquareAnchor
:
237 case LineCapDiamondAnchor
:
238 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
239 if(cap
== LineCapDiamondAnchor
){
240 dsmall
= cos(theta
+ M_PI_2
) * size
;
241 dbig
= sin(theta
+ M_PI_2
) * size
;
244 dsmall
= cos(theta
+ M_PI_4
) * size
;
245 dbig
= sin(theta
+ M_PI_4
) * size
;
248 ptf
[0].X
= x2
- dsmall
;
249 ptf
[1].X
= x2
+ dbig
;
251 ptf
[0].Y
= y2
- dbig
;
252 ptf
[3].Y
= y2
+ dsmall
;
254 ptf
[1].Y
= y2
- dsmall
;
255 ptf
[2].Y
= y2
+ dbig
;
257 ptf
[3].X
= x2
- dbig
;
258 ptf
[2].X
= x2
+ dsmall
;
260 transform_and_round_points(graphics
, pt
, ptf
, 4);
261 Polygon(graphics
->hdc
, pt
, 4);
264 case LineCapArrowAnchor
:
265 size
= size
* 4.0 / sqrt(3.0);
267 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
268 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
273 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
274 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
282 transform_and_round_points(graphics
, pt
, ptf
, 3);
283 Polygon(graphics
->hdc
, pt
, 3);
286 case LineCapRoundAnchor
:
287 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
294 transform_and_round_points(graphics
, pt
, ptf
, 2);
295 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
298 case LineCapTriangle
:
300 dx
= cos(M_PI_2
+ theta
) * size
;
301 dy
= sin(M_PI_2
+ theta
) * size
;
308 dx
= cos(theta
) * size
;
309 dy
= sin(theta
) * size
;
314 transform_and_round_points(graphics
, pt
, ptf
, 3);
315 Polygon(graphics
->hdc
, pt
, 3);
319 dx
= dy
= size
/ 2.0;
326 dx
= -cos(M_PI_2
+ theta
) * size
;
327 dy
= -sin(M_PI_2
+ theta
) * size
;
334 transform_and_round_points(graphics
, pt
, ptf
, 4);
335 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
336 pt
[2].y
, pt
[3].x
, pt
[3].y
);
343 count
= custom
->pathdata
.Count
;
344 custptf
= GdipAlloc(count
* sizeof(PointF
));
345 custpt
= GdipAlloc(count
* sizeof(POINT
));
346 tp
= GdipAlloc(count
);
348 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
351 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
353 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
354 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
356 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
357 GdipTransformMatrixPoints(matrix
, custptf
, count
);
359 transform_and_round_points(graphics
, custpt
, custptf
, count
);
361 for(i
= 0; i
< count
; i
++)
362 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
365 BeginPath(graphics
->hdc
);
366 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
367 EndPath(graphics
->hdc
);
368 StrokeAndFillPath(graphics
->hdc
);
371 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
377 GdipDeleteMatrix(matrix
);
384 SelectObject(graphics
->hdc
, oldbrush
);
385 SelectObject(graphics
->hdc
, oldpen
);
391 /* Shortens the line by the given percent by changing x2, y2.
392 * If percent is > 1.0 then the line will change direction.
393 * If percent is negative it can lengthen the line. */
394 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
396 REAL dist
, theta
, dx
, dy
;
398 if((y1
== *y2
) && (x1
== *x2
))
401 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
402 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
403 dx
= cos(theta
) * dist
;
404 dy
= sin(theta
) * dist
;
410 /* Shortens the line by the given amount by changing x2, y2.
411 * If the amount is greater than the distance, the line will become length 0.
412 * If the amount is negative, it can lengthen the line. */
413 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
415 REAL dx
, dy
, percent
;
419 if(dx
== 0 && dy
== 0)
422 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
429 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
432 /* Draws lines between the given points, and if caps is true then draws an endcap
433 * at the end of the last line. */
434 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
435 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
438 GpPointF
*ptcopy
= NULL
;
439 GpStatus status
= GenericError
;
444 pti
= GdipAlloc(count
* sizeof(POINT
));
445 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
448 status
= OutOfMemory
;
452 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
455 if(pen
->endcap
== LineCapArrowAnchor
)
456 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
457 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
458 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
459 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
460 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
461 pen
->customend
->inset
* pen
->width
);
463 if(pen
->startcap
== LineCapArrowAnchor
)
464 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
465 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
466 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
467 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
468 &ptcopy
[0].X
, &ptcopy
[0].Y
,
469 pen
->customstart
->inset
* pen
->width
);
471 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
472 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
473 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
474 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
477 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
479 if(Polyline(graphics
->hdc
, pti
, count
))
489 /* Conducts a linear search to find the bezier points that will back off
490 * the endpoint of the curve by a distance of amt. Linear search works
491 * better than binary in this case because there are multiple solutions,
492 * and binary searches often find a bad one. I don't think this is what
493 * Windows does but short of rendering the bezier without GDI's help it's
494 * the best we can do. If rev then work from the start of the passed points
495 * instead of the end. */
496 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
499 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
500 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
509 origx
= pt
[fourth
].X
;
510 origy
= pt
[fourth
].Y
;
511 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
513 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
514 /* reset bezier points to original values */
515 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
516 /* Perform magic on bezier points. Order is important here.*/
517 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
518 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
519 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
520 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
521 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
522 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
524 dx
= pt
[fourth
].X
- origx
;
525 dy
= pt
[fourth
].Y
- origy
;
527 diff
= sqrt(dx
* dx
+ dy
* dy
);
528 percent
+= 0.0005 * amt
;
532 /* Draws bezier curves between given points, and if caps is true then draws an
533 * endcap at the end of the last line. */
534 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
535 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
539 GpStatus status
= GenericError
;
544 pti
= GdipAlloc(count
* sizeof(POINT
));
545 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
548 status
= OutOfMemory
;
552 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
555 if(pen
->endcap
== LineCapArrowAnchor
)
556 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
557 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
558 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
561 if(pen
->startcap
== LineCapArrowAnchor
)
562 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
563 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
564 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
566 /* the direction of the line cap is parallel to the direction at the
567 * end of the bezier (which, if it has been shortened, is not the same
568 * as the direction from pt[count-2] to pt[count-1]) */
569 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
570 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
571 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
572 pt
[count
- 1].X
, pt
[count
- 1].Y
);
574 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
575 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
576 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
579 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
581 PolyBezier(graphics
->hdc
, pti
, count
);
592 /* Draws a combination of bezier curves and lines between points. */
593 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
594 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
596 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
597 BYTE
*tp
= GdipAlloc(count
);
598 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
600 GpStatus status
= GenericError
;
606 if(!pti
|| !tp
|| !ptcopy
){
607 status
= OutOfMemory
;
611 for(i
= 1; i
< count
; i
++){
612 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
613 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
614 || !(types
[i
+ 1] & PathPointTypeBezier
)){
615 ERR("Bad bezier points\n");
622 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
624 /* If we are drawing caps, go through the points and adjust them accordingly,
625 * and draw the caps. */
627 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
628 case PathPointTypeBezier
:
629 if(pen
->endcap
== LineCapArrowAnchor
)
630 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
631 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
632 shorten_bezier_amt(&ptcopy
[count
- 4],
633 pen
->width
* pen
->customend
->inset
, FALSE
);
635 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
636 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
637 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
638 pt
[count
- 1].X
, pt
[count
- 1].Y
);
641 case PathPointTypeLine
:
642 if(pen
->endcap
== LineCapArrowAnchor
)
643 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
644 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
646 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
647 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
648 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
649 pen
->customend
->inset
* pen
->width
);
651 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
652 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
657 ERR("Bad path last point\n");
661 /* Find start of points */
662 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
663 == PathPointTypeStart
); j
++);
665 switch(types
[j
] & PathPointTypePathTypeMask
){
666 case PathPointTypeBezier
:
667 if(pen
->startcap
== LineCapArrowAnchor
)
668 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
669 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
670 shorten_bezier_amt(&ptcopy
[j
- 1],
671 pen
->width
* pen
->customstart
->inset
, TRUE
);
673 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
674 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
675 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
676 pt
[j
- 1].X
, pt
[j
- 1].Y
);
679 case PathPointTypeLine
:
680 if(pen
->startcap
== LineCapArrowAnchor
)
681 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
682 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
684 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
685 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
686 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
687 pen
->customstart
->inset
* pen
->width
);
689 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
690 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
695 ERR("Bad path points\n");
700 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
702 for(i
= 0; i
< count
; i
++){
703 tp
[i
] = convert_path_point_type(types
[i
]);
706 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
718 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
720 TRACE("(%p, %p)\n", hdc
, graphics
);
722 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
725 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
729 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
731 if(hDevice
!= NULL
) {
732 FIXME("Don't know how to hadle parameter hDevice\n");
733 return NotImplemented
;
740 return InvalidParameter
;
742 *graphics
= GdipAlloc(sizeof(GpGraphics
));
743 if(!*graphics
) return OutOfMemory
;
745 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
750 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
751 GdipFree((*graphics
)->worldtrans
);
756 (*graphics
)->hdc
= hdc
;
757 (*graphics
)->hwnd
= WindowFromDC(hdc
);
758 (*graphics
)->smoothing
= SmoothingModeDefault
;
759 (*graphics
)->compqual
= CompositingQualityDefault
;
760 (*graphics
)->interpolation
= InterpolationModeDefault
;
761 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
762 (*graphics
)->compmode
= CompositingModeSourceOver
;
763 (*graphics
)->unit
= UnitDisplay
;
764 (*graphics
)->scale
= 1.0;
765 (*graphics
)->busy
= FALSE
;
766 (*graphics
)->textcontrast
= 4;
771 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
775 TRACE("(%p, %p)\n", hwnd
, graphics
);
777 if((ret
= GdipCreateFromHDC(GetDC(hwnd
), graphics
)) != Ok
)
780 (*graphics
)->hwnd
= hwnd
;
785 /* FIXME: no icm handling */
786 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
788 TRACE("(%p, %p)\n", hwnd
, graphics
);
790 return GdipCreateFromHWND(hwnd
, graphics
);
793 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
794 GpMetafile
**metafile
)
798 if(!hemf
|| !metafile
)
799 return InvalidParameter
;
802 FIXME("not implemented\n");
804 return NotImplemented
;
807 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
808 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
810 IStream
*stream
= NULL
;
814 GpStatus retval
= GenericError
;
816 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
818 if(!hwmf
|| !metafile
|| !placeable
)
819 return InvalidParameter
;
822 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
825 copy
= GdipAlloc(read
);
826 GetMetaFileBitsEx(hwmf
, read
, copy
);
828 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
831 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
832 copy
= GdipAlloc(read
);
833 GetEnhMetaFileBits(hemf
, read
, copy
);
834 DeleteEnhMetaFile(hemf
);
836 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
837 ERR("could not make stream\n");
842 *metafile
= GdipAlloc(sizeof(GpMetafile
));
844 retval
= OutOfMemory
;
848 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
849 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
853 (*metafile
)->image
.type
= ImageTypeMetafile
;
854 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
855 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Right
) / ((REAL
) placeable
->Inch
);
856 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
857 - placeable
->BoundingBox
.Left
)) / ((REAL
) placeable
->Inch
);
858 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
859 - placeable
->BoundingBox
.Top
)) / ((REAL
) placeable
->Inch
);
860 (*metafile
)->unit
= UnitInch
;
863 DeleteMetaFile(hwmf
);
869 IStream_Release(stream
);
873 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
874 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
876 HMETAFILE hmf
= GetMetaFileW(file
);
878 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
880 if(!hmf
) return InvalidParameter
;
882 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
885 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
886 UINT access
, IStream
**stream
)
891 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
893 if(!stream
|| !filename
)
894 return InvalidParameter
;
896 if(access
& GENERIC_WRITE
)
897 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
898 else if(access
& GENERIC_READ
)
899 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
901 return InvalidParameter
;
903 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
905 return hresult_to_status(ret
);
908 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
910 TRACE("(%p)\n", graphics
);
912 if(!graphics
) return InvalidParameter
;
913 if(graphics
->busy
) return ObjectBusy
;
916 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
918 GdipDeleteRegion(graphics
->clip
);
919 GdipDeleteMatrix(graphics
->worldtrans
);
925 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
926 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
928 INT save_state
, num_pts
;
929 GpPointF points
[MAX_ARC_PTS
];
932 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
933 width
, height
, startAngle
, sweepAngle
);
935 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
936 return InvalidParameter
;
941 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
943 save_state
= prepare_dc(graphics
, pen
);
945 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
947 restore_dc(graphics
, save_state
);
952 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
953 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
955 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
956 width
, height
, startAngle
, sweepAngle
);
958 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
961 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
962 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
968 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
969 x2
, y2
, x3
, y3
, x4
, y4
);
971 if(!graphics
|| !pen
)
972 return InvalidParameter
;
986 save_state
= prepare_dc(graphics
, pen
);
988 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
990 restore_dc(graphics
, save_state
);
995 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
996 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1002 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1003 x2
, y2
, x3
, y3
, x4
, y4
);
1005 if(!graphics
|| !pen
)
1006 return InvalidParameter
;
1020 save_state
= prepare_dc(graphics
, pen
);
1022 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1024 restore_dc(graphics
, save_state
);
1029 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1030 GDIPCONST GpPointF
*points
, INT count
)
1035 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1037 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1038 return InvalidParameter
;
1043 for(i
= 0; i
< floor(count
/ 4); i
++){
1044 ret
= GdipDrawBezier(graphics
, pen
,
1045 points
[4*i
].X
, points
[4*i
].Y
,
1046 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1047 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1048 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1056 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1057 GDIPCONST GpPoint
*points
, INT count
)
1063 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1065 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1066 return InvalidParameter
;
1071 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1075 for(i
= 0; i
< count
; i
++){
1076 pts
[i
].X
= (REAL
)points
[i
].X
;
1077 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1080 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1087 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1088 GDIPCONST GpPointF
*points
, INT count
)
1090 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1092 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1095 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1096 GDIPCONST GpPoint
*points
, INT count
)
1098 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1100 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1103 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1104 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1109 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1111 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1112 return InvalidParameter
;
1117 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1120 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1122 GdipDeletePath(path
);
1126 stat
= GdipDrawPath(graphics
, pen
, path
);
1128 GdipDeletePath(path
);
1133 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1134 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1140 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1142 if(!points
|| count
<= 0)
1143 return InvalidParameter
;
1145 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1149 for(i
= 0; i
< count
; i
++){
1150 ptf
[i
].X
= (REAL
)points
[i
].X
;
1151 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1154 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1161 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1162 GDIPCONST GpPointF
*points
, INT count
)
1164 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1166 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1169 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1170 GDIPCONST GpPoint
*points
, INT count
)
1176 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1178 if(!points
|| count
<= 0)
1179 return InvalidParameter
;
1181 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1185 for(i
= 0; i
< count
; i
++){
1186 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1187 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1190 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1196 /* Approximates cardinal spline with Bezier curves. */
1197 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1198 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1200 /* PolyBezier expects count*3-2 points. */
1201 INT i
, len_pt
= count
*3-2, save_state
;
1203 REAL x1
, x2
, y1
, y2
;
1206 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1208 if(!graphics
|| !pen
)
1209 return InvalidParameter
;
1214 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1215 tension
= tension
* TENSION_CONST
;
1217 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1220 pt
[0].X
= points
[0].X
;
1221 pt
[0].Y
= points
[0].Y
;
1225 for(i
= 0; i
< count
-2; i
++){
1226 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1230 pt
[3*i
+3].X
= points
[i
+1].X
;
1231 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1236 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1237 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1239 pt
[len_pt
-2].X
= x1
;
1240 pt
[len_pt
-2].Y
= y1
;
1241 pt
[len_pt
-1].X
= points
[count
-1].X
;
1242 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1244 save_state
= prepare_dc(graphics
, pen
);
1246 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1249 restore_dc(graphics
, save_state
);
1254 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1255 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1261 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1263 if(!points
|| count
<= 0)
1264 return InvalidParameter
;
1266 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1270 for(i
= 0; i
< count
; i
++){
1271 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1272 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1275 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1281 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1282 REAL y
, REAL width
, REAL height
)
1288 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1290 if(!graphics
|| !pen
)
1291 return InvalidParameter
;
1298 ptf
[1].X
= x
+ width
;
1299 ptf
[1].Y
= y
+ height
;
1301 save_state
= prepare_dc(graphics
, pen
);
1302 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1304 transform_and_round_points(graphics
, pti
, ptf
, 2);
1306 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1308 restore_dc(graphics
, save_state
);
1313 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1314 INT y
, INT width
, INT height
)
1316 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1318 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1322 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1324 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1326 /* IPicture::Render uses LONG coords */
1327 return GdipDrawImageI(graphics
,image
,roundr(x
),roundr(y
));
1330 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1333 UINT width
, height
, srcw
, srch
;
1335 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1337 if(!graphics
|| !image
)
1338 return InvalidParameter
;
1340 GdipGetImageWidth(image
, &width
);
1341 GdipGetImageHeight(image
, &height
);
1343 srcw
= width
* (((REAL
) INCH_HIMETRIC
) /
1344 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
)));
1345 srch
= height
* (((REAL
) INCH_HIMETRIC
) /
1346 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
)));
1348 if(image
->type
!= ImageTypeMetafile
){
1353 IPicture_Render(image
->picture
, graphics
->hdc
, x
, y
, width
, height
,
1354 0, 0, srcw
, srch
, NULL
);
1359 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1360 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
1361 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
1362 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1363 DrawImageAbort callback
, VOID
* callbackData
)
1369 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
1370 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1373 if(!graphics
|| !image
|| !points
|| count
!= 3)
1374 return InvalidParameter
;
1376 if(srcUnit
== UnitInch
)
1377 dx
= dy
= (REAL
) INCH_HIMETRIC
;
1378 else if(srcUnit
== UnitPixel
){
1379 dx
= ((REAL
) INCH_HIMETRIC
) /
1380 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
1381 dy
= ((REAL
) INCH_HIMETRIC
) /
1382 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
1385 return NotImplemented
;
1387 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
1388 transform_and_round_points(graphics
, pti
, ptf
, 3);
1390 /* IPicture renders bitmaps with the y-axis reversed
1391 * FIXME: flipping for unknown image type might not be correct. */
1392 if(image
->type
!= ImageTypeMetafile
){
1395 pti
[0].y
= pti
[2].y
;
1399 if(IPicture_Render(image
->picture
, graphics
->hdc
,
1400 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
1401 srcx
* dx
, srcy
* dy
,
1402 srcwidth
* dx
, srcheight
* dy
,
1405 callback(callbackData
);
1406 return GenericError
;
1412 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
1413 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
1414 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1415 DrawImageAbort callback
, VOID
* callbackData
)
1417 GpPointF pointsF
[3];
1420 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
1421 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1424 if(!points
|| count
!=3)
1425 return InvalidParameter
;
1427 for(i
= 0; i
< count
; i
++){
1428 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1429 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1432 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
1433 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
1434 callback
, callbackData
);
1437 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
1438 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
1439 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
1440 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
1441 VOID
* callbackData
)
1445 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
1446 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1447 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1451 points
[1].X
= dstx
+ dstwidth
;
1454 points
[2].Y
= dsty
+ dstheight
;
1456 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1457 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1460 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
1461 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
1462 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
1463 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
1464 VOID
* callbackData
)
1468 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
1469 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1470 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1474 points
[1].X
= dstx
+ dstwidth
;
1477 points
[2].Y
= dsty
+ dstheight
;
1479 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1480 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1483 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
1484 REAL x
, REAL y
, REAL width
, REAL height
)
1490 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
1492 if(!graphics
|| !image
)
1493 return InvalidParameter
;
1495 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
1499 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
1500 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
1501 unit
, NULL
, NULL
, NULL
);
1504 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
1505 INT x
, INT y
, INT width
, INT height
)
1507 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
1509 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
1512 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1513 REAL y1
, REAL x2
, REAL y2
)
1519 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1521 if(!pen
|| !graphics
)
1522 return InvalidParameter
;
1532 save_state
= prepare_dc(graphics
, pen
);
1534 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1536 restore_dc(graphics
, save_state
);
1541 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1542 INT y1
, INT x2
, INT y2
)
1548 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1550 if(!pen
|| !graphics
)
1551 return InvalidParameter
;
1561 save_state
= prepare_dc(graphics
, pen
);
1563 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1565 restore_dc(graphics
, save_state
);
1570 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1571 GpPointF
*points
, INT count
)
1576 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1578 if(!pen
|| !graphics
|| (count
< 2))
1579 return InvalidParameter
;
1584 save_state
= prepare_dc(graphics
, pen
);
1586 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
1588 restore_dc(graphics
, save_state
);
1593 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1594 GpPoint
*points
, INT count
)
1598 GpPointF
*ptf
= NULL
;
1601 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1603 if(!pen
|| !graphics
|| (count
< 2))
1604 return InvalidParameter
;
1609 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
1610 if(!ptf
) return OutOfMemory
;
1612 for(i
= 0; i
< count
; i
++){
1613 ptf
[i
].X
= (REAL
) points
[i
].X
;
1614 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
1617 save_state
= prepare_dc(graphics
, pen
);
1619 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
1621 restore_dc(graphics
, save_state
);
1627 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
1632 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
1634 if(!pen
|| !graphics
)
1635 return InvalidParameter
;
1640 save_state
= prepare_dc(graphics
, pen
);
1642 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
1643 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
1645 restore_dc(graphics
, save_state
);
1650 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1651 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1655 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1656 width
, height
, startAngle
, sweepAngle
);
1658 if(!graphics
|| !pen
)
1659 return InvalidParameter
;
1664 save_state
= prepare_dc(graphics
, pen
);
1665 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1667 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1669 restore_dc(graphics
, save_state
);
1674 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1675 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1677 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1678 width
, height
, startAngle
, sweepAngle
);
1680 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1683 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1684 REAL y
, REAL width
, REAL height
)
1690 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1692 if(!pen
|| !graphics
)
1693 return InvalidParameter
;
1700 ptf
[1].X
= x
+ width
;
1702 ptf
[2].X
= x
+ width
;
1703 ptf
[2].Y
= y
+ height
;
1705 ptf
[3].Y
= y
+ height
;
1707 save_state
= prepare_dc(graphics
, pen
);
1708 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1710 transform_and_round_points(graphics
, pti
, ptf
, 4);
1711 Polygon(graphics
->hdc
, pti
, 4);
1713 restore_dc(graphics
, save_state
);
1718 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1719 INT y
, INT width
, INT height
)
1721 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1723 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1726 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
1727 GDIPCONST GpRectF
* rects
, INT count
)
1733 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
1735 if(!graphics
|| !pen
|| !rects
|| count
< 1)
1736 return InvalidParameter
;
1741 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
1742 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
1750 for(i
= 0; i
< count
; i
++){
1751 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
1752 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
1753 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
1754 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
1757 save_state
= prepare_dc(graphics
, pen
);
1758 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1760 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
1762 for(i
= 0; i
< count
; i
++)
1763 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
1765 restore_dc(graphics
, save_state
);
1773 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
1774 GDIPCONST GpRect
* rects
, INT count
)
1780 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
1782 if(!rects
|| count
<=0)
1783 return InvalidParameter
;
1785 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
1789 for(i
= 0;i
< count
;i
++){
1790 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
1791 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
1792 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
1793 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
1796 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
1802 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
1803 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
1804 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
1809 TEXTMETRICW textmet
;
1810 GpPointF pt
[2], rectcpy
[4];
1813 REAL angle
, ang_cos
, ang_sin
, rel_width
, rel_height
;
1814 INT sum
= 0, height
= 0, fit
, fitcpy
, save_state
, i
, j
, lret
, nwidth
,
1819 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
1820 return InvalidParameter
;
1822 if((brush
->bt
!= BrushTypeSolidColor
)){
1823 FIXME("not implemented for given parameters\n");
1824 return NotImplemented
;
1828 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
1830 if(length
== -1) length
= lstrlenW(string
);
1832 stringdup
= GdipAlloc(length
* sizeof(WCHAR
));
1833 if(!stringdup
) return OutOfMemory
;
1835 save_state
= SaveDC(graphics
->hdc
);
1836 SetBkMode(graphics
->hdc
, TRANSPARENT
);
1837 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
1839 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
1840 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
1841 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
1842 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
1843 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
1845 if(roundr(rect
->Width
) == 0 && roundr(rect
->Height
) == 0){
1846 rel_width
= rel_height
= 1.0;
1847 nwidth
= nheight
= INT_MAX
;
1850 rel_width
= sqrt((corners
[1].x
- corners
[0].x
) * (corners
[1].x
- corners
[0].x
) +
1851 (corners
[1].y
- corners
[0].y
) * (corners
[1].y
- corners
[0].y
))
1853 rel_height
= sqrt((corners
[2].x
- corners
[1].x
) * (corners
[2].x
- corners
[1].x
) +
1854 (corners
[2].y
- corners
[1].y
) * (corners
[2].y
- corners
[1].y
))
1857 nwidth
= roundr(rel_width
* rect
->Width
);
1858 nheight
= roundr(rel_height
* rect
->Height
);
1859 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
1860 SelectClipRgn(graphics
->hdc
, rgn
);
1863 /* Use gdi to find the font, then perform transformations on it (height,
1865 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
1866 GetTextMetricsW(graphics
->hdc
, &textmet
);
1869 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
1870 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
1876 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
1877 angle
= gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
1878 ang_cos
= cos(angle
);
1879 ang_sin
= sin(angle
);
1880 lfw
.lfEscapement
= lfw
.lfOrientation
= -roundr((angle
/ M_PI
) * 1800.0);
1882 gdifont
= CreateFontIndirectW(&lfw
);
1883 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
1885 for(i
= 0, j
= 0; i
< length
; i
++){
1886 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
1889 stringdup
[j
] = string
[i
];
1896 while(sum
< length
){
1897 drawcoord
.left
= corners
[0].x
+ roundr(ang_sin
* (REAL
) height
);
1898 drawcoord
.top
= corners
[0].y
+ roundr(ang_cos
* (REAL
) height
);
1900 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
1901 nwidth
, &fit
, NULL
, &size
);
1905 DrawTextW(graphics
->hdc
, stringdup
+ sum
, 1, &drawcoord
, DT_NOCLIP
|
1910 for(lret
= 0; lret
< fit
; lret
++)
1911 if(*(stringdup
+ sum
+ lret
) == '\n')
1914 /* Line break code (may look strange, but it imitates windows). */
1916 fit
= lret
; /* this is not an off-by-one error */
1917 else if(fit
< (length
- sum
)){
1918 if(*(stringdup
+ sum
+ fit
) == ' ')
1919 while(*(stringdup
+ sum
+ fit
) == ' ')
1922 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
1925 if(*(stringdup
+ sum
+ fit
) == '\t')
1934 DrawTextW(graphics
->hdc
, stringdup
+ sum
, min(length
- sum
, fit
),
1935 &drawcoord
, DT_NOCLIP
| DT_EXPANDTABS
);
1937 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
1940 if(height
> nheight
)
1943 /* Stop if this was a linewrap (but not if it was a linebreak). */
1944 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
1948 GdipFree(stringdup
);
1950 DeleteObject(gdifont
);
1952 RestoreDC(graphics
->hdc
, save_state
);
1957 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
1958 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
1963 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
1964 count
, tension
, fill
);
1966 if(!graphics
|| !brush
|| !points
)
1967 return InvalidParameter
;
1972 stat
= GdipCreatePath(fill
, &path
);
1976 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1978 GdipDeletePath(path
);
1982 stat
= GdipFillPath(graphics
, brush
, path
);
1984 GdipDeletePath(path
);
1988 GdipDeletePath(path
);
1993 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
1994 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2000 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2001 count
, tension
, fill
);
2003 if(!points
|| count
<= 0)
2004 return InvalidParameter
;
2006 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2010 for(i
= 0;i
< count
;i
++){
2011 ptf
[i
].X
= (REAL
)points
[i
].X
;
2012 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2015 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2022 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2023 REAL y
, REAL width
, REAL height
)
2029 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2031 if(!graphics
|| !brush
)
2032 return InvalidParameter
;
2039 ptf
[1].X
= x
+ width
;
2040 ptf
[1].Y
= y
+ height
;
2042 save_state
= SaveDC(graphics
->hdc
);
2043 EndPath(graphics
->hdc
);
2044 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2045 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2047 transform_and_round_points(graphics
, pti
, ptf
, 2);
2049 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2051 RestoreDC(graphics
->hdc
, save_state
);
2056 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2057 INT y
, INT width
, INT height
)
2059 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2061 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2064 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2069 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2071 if(!brush
|| !graphics
|| !path
)
2072 return InvalidParameter
;
2077 save_state
= SaveDC(graphics
->hdc
);
2078 EndPath(graphics
->hdc
);
2079 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2080 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2083 BeginPath(graphics
->hdc
);
2084 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2085 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2090 EndPath(graphics
->hdc
);
2091 FillPath(graphics
->hdc
);
2096 RestoreDC(graphics
->hdc
, save_state
);
2101 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2102 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2106 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2107 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2109 if(!graphics
|| !brush
)
2110 return InvalidParameter
;
2115 save_state
= SaveDC(graphics
->hdc
);
2116 EndPath(graphics
->hdc
);
2117 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2118 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2120 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2122 RestoreDC(graphics
->hdc
, save_state
);
2127 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2128 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2130 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2131 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2133 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2136 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
2137 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
2140 GpPointF
*ptf
= NULL
;
2142 GpStatus retval
= Ok
;
2144 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2146 if(!graphics
|| !brush
|| !points
|| !count
)
2147 return InvalidParameter
;
2152 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2153 pti
= GdipAlloc(count
* sizeof(POINT
));
2155 retval
= OutOfMemory
;
2159 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
2161 save_state
= SaveDC(graphics
->hdc
);
2162 EndPath(graphics
->hdc
);
2163 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2164 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2165 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2168 transform_and_round_points(graphics
, pti
, ptf
, count
);
2169 Polygon(graphics
->hdc
, pti
, count
);
2171 RestoreDC(graphics
->hdc
, save_state
);
2180 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
2181 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
2184 GpPointF
*ptf
= NULL
;
2186 GpStatus retval
= Ok
;
2188 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2190 if(!graphics
|| !brush
|| !points
|| !count
)
2191 return InvalidParameter
;
2196 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2197 pti
= GdipAlloc(count
* sizeof(POINT
));
2199 retval
= OutOfMemory
;
2203 for(i
= 0; i
< count
; i
++){
2204 ptf
[i
].X
= (REAL
) points
[i
].X
;
2205 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2208 save_state
= SaveDC(graphics
->hdc
);
2209 EndPath(graphics
->hdc
);
2210 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2211 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2212 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2215 transform_and_round_points(graphics
, pti
, ptf
, count
);
2216 Polygon(graphics
->hdc
, pti
, count
);
2218 RestoreDC(graphics
->hdc
, save_state
);
2227 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
2228 GDIPCONST GpPointF
*points
, INT count
)
2230 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2232 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
2235 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
2236 GDIPCONST GpPoint
*points
, INT count
)
2238 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2240 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
2243 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
2244 REAL x
, REAL y
, REAL width
, REAL height
)
2250 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2252 if(!graphics
|| !brush
)
2253 return InvalidParameter
;
2260 ptf
[1].X
= x
+ width
;
2262 ptf
[2].X
= x
+ width
;
2263 ptf
[2].Y
= y
+ height
;
2265 ptf
[3].Y
= y
+ height
;
2267 save_state
= SaveDC(graphics
->hdc
);
2268 EndPath(graphics
->hdc
);
2269 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2270 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2272 transform_and_round_points(graphics
, pti
, ptf
, 4);
2274 Polygon(graphics
->hdc
, pti
, 4);
2276 RestoreDC(graphics
->hdc
, save_state
);
2281 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
2282 INT x
, INT y
, INT width
, INT height
)
2288 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2290 if(!graphics
|| !brush
)
2291 return InvalidParameter
;
2298 ptf
[1].X
= x
+ width
;
2300 ptf
[2].X
= x
+ width
;
2301 ptf
[2].Y
= y
+ height
;
2303 ptf
[3].Y
= y
+ height
;
2305 save_state
= SaveDC(graphics
->hdc
);
2306 EndPath(graphics
->hdc
);
2307 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2308 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2310 transform_and_round_points(graphics
, pti
, ptf
, 4);
2312 Polygon(graphics
->hdc
, pti
, 4);
2314 RestoreDC(graphics
->hdc
, save_state
);
2319 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
2325 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2328 return InvalidParameter
;
2330 for(i
= 0; i
< count
; i
++){
2331 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2332 if(ret
!= Ok
) return ret
;
2338 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
2345 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2347 if(!rects
|| count
<= 0)
2348 return InvalidParameter
;
2350 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
2354 for(i
= 0; i
< count
; i
++){
2355 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2356 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2357 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
2358 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2361 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
2367 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
2370 if (!(graphics
&& brush
&& region
))
2371 return InvalidParameter
;
2376 FIXME("(%p, %p, %p): stub\n", graphics
, brush
, region
);
2378 return NotImplemented
;
2381 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
2386 return InvalidParameter
;
2392 FIXME("not implemented\n");
2394 return NotImplemented
;
2397 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
2398 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
2399 CompositingMode
*mode
)
2401 TRACE("(%p, %p)\n", graphics
, mode
);
2403 if(!graphics
|| !mode
)
2404 return InvalidParameter
;
2409 *mode
= graphics
->compmode
;
2414 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
2415 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
2416 CompositingQuality
*quality
)
2418 TRACE("(%p, %p)\n", graphics
, quality
);
2420 if(!graphics
|| !quality
)
2421 return InvalidParameter
;
2426 *quality
= graphics
->compqual
;
2431 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
2432 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
2433 InterpolationMode
*mode
)
2435 TRACE("(%p, %p)\n", graphics
, mode
);
2437 if(!graphics
|| !mode
)
2438 return InvalidParameter
;
2443 *mode
= graphics
->interpolation
;
2448 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
2450 TRACE("(%p, %p)\n", graphics
, scale
);
2452 if(!graphics
|| !scale
)
2453 return InvalidParameter
;
2458 *scale
= graphics
->scale
;
2463 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
2465 TRACE("(%p, %p)\n", graphics
, unit
);
2467 if(!graphics
|| !unit
)
2468 return InvalidParameter
;
2473 *unit
= graphics
->unit
;
2478 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
2479 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
2482 TRACE("(%p, %p)\n", graphics
, mode
);
2484 if(!graphics
|| !mode
)
2485 return InvalidParameter
;
2490 *mode
= graphics
->pixeloffset
;
2495 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
2496 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
2498 TRACE("(%p, %p)\n", graphics
, mode
);
2500 if(!graphics
|| !mode
)
2501 return InvalidParameter
;
2506 *mode
= graphics
->smoothing
;
2511 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
2513 TRACE("(%p, %p)\n", graphics
, contrast
);
2515 if(!graphics
|| !contrast
)
2516 return InvalidParameter
;
2518 *contrast
= graphics
->textcontrast
;
2523 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
2524 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
2525 TextRenderingHint
*hint
)
2527 TRACE("(%p, %p)\n", graphics
, hint
);
2529 if(!graphics
|| !hint
)
2530 return InvalidParameter
;
2535 *hint
= graphics
->texthint
;
2540 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2542 TRACE("(%p, %p)\n", graphics
, matrix
);
2544 if(!graphics
|| !matrix
)
2545 return InvalidParameter
;
2550 *matrix
= *graphics
->worldtrans
;
2554 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
2560 TRACE("(%p, %x)\n", graphics
, color
);
2563 return InvalidParameter
;
2568 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
2572 if(!GetWindowRect(graphics
->hwnd
, &rect
)){
2573 GdipDeleteBrush((GpBrush
*)brush
);
2574 return GenericError
;
2577 GdipFillRectangle(graphics
, (GpBrush
*)brush
, 0.0, 0.0, (REAL
)(rect
.right
- rect
.left
),
2578 (REAL
)(rect
.bottom
- rect
.top
));
2581 GdipFillRectangle(graphics
, (GpBrush
*)brush
, 0.0, 0.0, (REAL
)GetDeviceCaps(graphics
->hdc
, HORZRES
),
2582 (REAL
)GetDeviceCaps(graphics
->hdc
, VERTRES
));
2584 GdipDeleteBrush((GpBrush
*)brush
);
2589 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
2591 TRACE("(%p, %p)\n", graphics
, res
);
2593 if(!graphics
|| !res
)
2594 return InvalidParameter
;
2596 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
2599 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
2601 FIXME("(%p, %.2f, %.2f, %p) stub\n", graphics
, x
, y
, result
);
2603 if(!graphics
|| !result
)
2604 return InvalidParameter
;
2609 return NotImplemented
;
2612 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
2614 FIXME("(%p, %d, %d, %p) stub\n", graphics
, x
, y
, result
);
2616 if(!graphics
|| !result
)
2617 return InvalidParameter
;
2622 return NotImplemented
;
2625 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
2626 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
2627 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
2628 INT regionCount
, GpRegion
** regions
)
2630 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
2631 return InvalidParameter
;
2633 FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics
, debugstr_w(string
),
2634 length
, font
, layoutRect
, stringFormat
, regionCount
, regions
);
2636 return NotImplemented
;
2639 /* Find the smallest rectangle that bounds the text when it is printed in rect
2640 * according to the format options listed in format. If rect has 0 width and
2641 * height, then just find the smallest rectangle that bounds the text when it's
2642 * printed at location (rect->X, rect-Y). */
2643 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
2644 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
2645 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
2646 INT
*codepointsfitted
, INT
*linesfilled
)
2650 INT sum
= 0, height
= 0, fit
, fitcpy
, max_width
= 0, i
, j
, lret
, nwidth
,
2654 if(!graphics
|| !string
|| !font
|| !rect
)
2655 return InvalidParameter
;
2657 if(codepointsfitted
|| linesfilled
){
2658 FIXME("not implemented for given parameters\n");
2659 return NotImplemented
;
2663 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
2665 if(length
== -1) length
= lstrlenW(string
);
2667 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
2668 if(!stringdup
) return OutOfMemory
;
2670 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2671 nwidth
= roundr(rect
->Width
);
2672 nheight
= roundr(rect
->Height
);
2674 if((nwidth
== 0) && (nheight
== 0))
2675 nwidth
= nheight
= INT_MAX
;
2677 for(i
= 0, j
= 0; i
< length
; i
++){
2678 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
2681 stringdup
[j
] = string
[i
];
2688 while(sum
< length
){
2689 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
2690 nwidth
, &fit
, NULL
, &size
);
2696 for(lret
= 0; lret
< fit
; lret
++)
2697 if(*(stringdup
+ sum
+ lret
) == '\n')
2700 /* Line break code (may look strange, but it imitates windows). */
2702 fit
= lret
; /* this is not an off-by-one error */
2703 else if(fit
< (length
- sum
)){
2704 if(*(stringdup
+ sum
+ fit
) == ' ')
2705 while(*(stringdup
+ sum
+ fit
) == ' ')
2708 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
2711 if(*(stringdup
+ sum
+ fit
) == '\t')
2721 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, fit
,
2722 nwidth
, &j
, NULL
, &size
);
2724 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
2726 max_width
= max(max_width
, size
.cx
);
2728 if(height
> nheight
)
2731 /* Stop if this was a linewrap (but not if it was a linebreak). */
2732 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
2736 bounds
->X
= rect
->X
;
2737 bounds
->Y
= rect
->Y
;
2738 bounds
->Width
= (REAL
)max_width
;
2739 bounds
->Height
= (REAL
) min(height
, nheight
);
2741 GdipFree(stringdup
);
2742 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
2747 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
2749 TRACE("(%p)\n", graphics
);
2752 return InvalidParameter
;
2757 return GdipSetInfinite(graphics
->clip
);
2760 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
2762 TRACE("(%p)\n", graphics
);
2765 return InvalidParameter
;
2770 graphics
->worldtrans
->matrix
[0] = 1.0;
2771 graphics
->worldtrans
->matrix
[1] = 0.0;
2772 graphics
->worldtrans
->matrix
[2] = 0.0;
2773 graphics
->worldtrans
->matrix
[3] = 1.0;
2774 graphics
->worldtrans
->matrix
[4] = 0.0;
2775 graphics
->worldtrans
->matrix
[5] = 0.0;
2780 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
2785 return InvalidParameter
;
2788 FIXME("graphics state not implemented\n");
2790 return NotImplemented
;
2793 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
2794 GpMatrixOrder order
)
2796 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
2799 return InvalidParameter
;
2804 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
2807 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
2811 if(!graphics
|| !state
)
2812 return InvalidParameter
;
2815 FIXME("graphics state not implemented\n");
2817 return NotImplemented
;
2820 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
2821 REAL sy
, GpMatrixOrder order
)
2823 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
2826 return InvalidParameter
;
2831 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
2834 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
2837 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
2839 if(!graphics
|| !srcgraphics
)
2840 return InvalidParameter
;
2842 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
2845 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
2846 CompositingMode mode
)
2848 TRACE("(%p, %d)\n", graphics
, mode
);
2851 return InvalidParameter
;
2856 graphics
->compmode
= mode
;
2861 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
2862 CompositingQuality quality
)
2864 TRACE("(%p, %d)\n", graphics
, quality
);
2867 return InvalidParameter
;
2872 graphics
->compqual
= quality
;
2877 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
2878 InterpolationMode mode
)
2880 TRACE("(%p, %d)\n", graphics
, mode
);
2883 return InvalidParameter
;
2888 graphics
->interpolation
= mode
;
2893 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
2895 TRACE("(%p, %.2f)\n", graphics
, scale
);
2897 if(!graphics
|| (scale
<= 0.0))
2898 return InvalidParameter
;
2903 graphics
->scale
= scale
;
2908 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
2910 TRACE("(%p, %d)\n", graphics
, unit
);
2913 return InvalidParameter
;
2918 if(unit
== UnitWorld
)
2919 return InvalidParameter
;
2921 graphics
->unit
= unit
;
2926 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
2929 TRACE("(%p, %d)\n", graphics
, mode
);
2932 return InvalidParameter
;
2937 graphics
->pixeloffset
= mode
;
2942 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
2944 TRACE("(%p, %d)\n", graphics
, mode
);
2947 return InvalidParameter
;
2952 graphics
->smoothing
= mode
;
2957 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
2959 TRACE("(%p, %d)\n", graphics
, contrast
);
2962 return InvalidParameter
;
2964 graphics
->textcontrast
= contrast
;
2969 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
2970 TextRenderingHint hint
)
2972 TRACE("(%p, %d)\n", graphics
, hint
);
2975 return InvalidParameter
;
2980 graphics
->texthint
= hint
;
2985 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2987 TRACE("(%p, %p)\n", graphics
, matrix
);
2989 if(!graphics
|| !matrix
)
2990 return InvalidParameter
;
2995 GdipDeleteMatrix(graphics
->worldtrans
);
2996 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
2999 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
3000 REAL dy
, GpMatrixOrder order
)
3002 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
3005 return InvalidParameter
;
3010 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
3013 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
3015 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
3018 return InvalidParameter
;
3023 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
3026 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
3027 REAL width
, REAL height
,
3032 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3035 return InvalidParameter
;
3043 rect
.Height
= height
;
3045 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
3048 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
3049 INT width
, INT height
,
3052 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3055 return InvalidParameter
;
3060 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
3063 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
3066 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
3068 if(!graphics
|| !region
)
3069 return InvalidParameter
;
3074 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
3077 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
3083 FIXME("not implemented\n");
3085 return NotImplemented
;
3088 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
3094 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
3096 if(!graphics
|| !pen
|| count
<=0)
3097 return InvalidParameter
;
3102 pti
= GdipAlloc(sizeof(POINT
) * count
);
3104 save_state
= prepare_dc(graphics
, pen
);
3105 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3107 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
3108 Polygon(graphics
->hdc
, pti
, count
);
3110 restore_dc(graphics
, save_state
);
3116 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
3123 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3125 if(count
<=0) return InvalidParameter
;
3126 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
3128 for(i
= 0;i
< count
; i
++){
3129 ptf
[i
].X
= (REAL
)points
[i
].X
;
3130 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3133 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
3139 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
3141 TRACE("(%p, %p)\n", graphics
, dpi
);
3143 if(!graphics
|| !dpi
)
3144 return InvalidParameter
;
3149 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
3154 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
3156 TRACE("(%p, %p)\n", graphics
, dpi
);
3158 if(!graphics
|| !dpi
)
3159 return InvalidParameter
;
3164 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
3169 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
3170 GpMatrixOrder order
)
3175 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
3177 if(!graphics
|| !matrix
)
3178 return InvalidParameter
;
3183 m
= *(graphics
->worldtrans
);
3185 ret
= GdipMultiplyMatrix(&m
, (GpMatrix
*)matrix
, order
);
3187 *(graphics
->worldtrans
) = m
;
3192 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
3194 TRACE("(%p, %p)\n", graphics
, hdc
);
3196 if(!graphics
|| !hdc
)
3197 return InvalidParameter
;
3202 *hdc
= graphics
->hdc
;
3203 graphics
->busy
= TRUE
;
3208 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
3210 TRACE("(%p, %p)\n", graphics
, hdc
);
3213 return InvalidParameter
;
3215 if(graphics
->hdc
!= hdc
|| !(graphics
->busy
))
3216 return InvalidParameter
;
3218 graphics
->busy
= FALSE
;
3223 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
3228 TRACE("(%p, %p)\n", graphics
, region
);
3230 if(!graphics
|| !region
)
3231 return InvalidParameter
;
3236 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
3239 /* free everything except root node and header */
3240 delete_element(®ion
->node
);
3241 memcpy(region
, clip
, sizeof(GpRegion
));
3246 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3247 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
3249 if(!graphics
|| !points
|| count
<= 0)
3250 return InvalidParameter
;
3255 FIXME("(%p, %d, %d, %p, %d): stub\n", graphics
, dst_space
, src_space
, points
, count
);
3257 return NotImplemented
;
3260 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3261 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
3263 FIXME("(%p, %d, %d, %p, %d): stub\n", graphics
, dst_space
, src_space
, points
, count
);
3265 return NotImplemented
;