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 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
723 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
727 if(hDevice
!= NULL
) {
728 FIXME("Don't know how to hadle parameter hDevice\n");
729 return NotImplemented
;
736 return InvalidParameter
;
738 *graphics
= GdipAlloc(sizeof(GpGraphics
));
739 if(!*graphics
) return OutOfMemory
;
741 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
746 (*graphics
)->hdc
= hdc
;
747 (*graphics
)->hwnd
= NULL
;
748 (*graphics
)->smoothing
= SmoothingModeDefault
;
749 (*graphics
)->compqual
= CompositingQualityDefault
;
750 (*graphics
)->interpolation
= InterpolationModeDefault
;
751 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
752 (*graphics
)->compmode
= CompositingModeSourceOver
;
753 (*graphics
)->unit
= UnitDisplay
;
754 (*graphics
)->scale
= 1.0;
759 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
763 if((ret
= GdipCreateFromHDC(GetDC(hwnd
), graphics
)) != Ok
)
766 (*graphics
)->hwnd
= hwnd
;
771 /* FIXME: no icm handling */
772 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
774 return GdipCreateFromHWND(hwnd
, graphics
);
777 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
778 GpMetafile
**metafile
)
782 if(!hemf
|| !metafile
)
783 return InvalidParameter
;
786 FIXME("not implemented\n");
788 return NotImplemented
;
791 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
792 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
794 IStream
*stream
= NULL
;
798 GpStatus retval
= GenericError
;
800 if(!hwmf
|| !metafile
|| !placeable
)
801 return InvalidParameter
;
804 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
807 copy
= GdipAlloc(read
);
808 GetMetaFileBitsEx(hwmf
, read
, copy
);
810 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
813 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
814 copy
= GdipAlloc(read
);
815 GetEnhMetaFileBits(hemf
, read
, copy
);
816 DeleteEnhMetaFile(hemf
);
818 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
819 ERR("could not make stream\n");
824 *metafile
= GdipAlloc(sizeof(GpMetafile
));
826 retval
= OutOfMemory
;
830 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
831 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
835 (*metafile
)->image
.type
= ImageTypeMetafile
;
836 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
837 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Right
) / ((REAL
) placeable
->Inch
);
838 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
839 - placeable
->BoundingBox
.Left
)) / ((REAL
) placeable
->Inch
);
840 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
841 - placeable
->BoundingBox
.Top
)) / ((REAL
) placeable
->Inch
);
842 (*metafile
)->unit
= UnitInch
;
845 DeleteMetaFile(hwmf
);
851 IStream_Release(stream
);
855 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
856 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
858 HMETAFILE hmf
= GetMetaFileW(file
);
860 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
862 if(!hmf
) return InvalidParameter
;
864 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
867 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
868 UINT access
, IStream
**stream
)
873 if(!stream
|| !filename
)
874 return InvalidParameter
;
876 if(access
& GENERIC_WRITE
)
877 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
878 else if(access
& GENERIC_READ
)
879 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
881 return InvalidParameter
;
883 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
885 return hresult_to_status(ret
);
888 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
890 if(!graphics
) return InvalidParameter
;
892 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
894 GdipDeleteMatrix(graphics
->worldtrans
);
895 HeapFree(GetProcessHeap(), 0, graphics
);
900 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
901 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
903 INT save_state
, num_pts
;
904 GpPointF points
[MAX_ARC_PTS
];
907 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
908 return InvalidParameter
;
910 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
912 save_state
= prepare_dc(graphics
, pen
);
914 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
916 restore_dc(graphics
, save_state
);
921 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
922 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
924 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
927 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
928 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
934 if(!graphics
|| !pen
)
935 return InvalidParameter
;
946 save_state
= prepare_dc(graphics
, pen
);
948 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
950 restore_dc(graphics
, save_state
);
955 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
956 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
962 if(!graphics
|| !pen
)
963 return InvalidParameter
;
974 save_state
= prepare_dc(graphics
, pen
);
976 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
978 restore_dc(graphics
, save_state
);
983 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
984 GDIPCONST GpPointF
*points
, INT count
)
989 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
990 return InvalidParameter
;
992 for(i
= 0; i
< floor(count
/ 4); i
++){
993 ret
= GdipDrawBezier(graphics
, pen
,
994 points
[4*i
].X
, points
[4*i
].Y
,
995 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
996 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
997 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1005 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1006 GDIPCONST GpPoint
*points
, INT count
)
1012 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1013 return InvalidParameter
;
1015 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1019 for(i
= 0; i
< count
; i
++){
1020 pts
[i
].X
= (REAL
)points
[i
].X
;
1021 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1024 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1031 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1032 GDIPCONST GpPointF
*points
, INT count
)
1034 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1037 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1038 GDIPCONST GpPoint
*points
, INT count
)
1040 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1043 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1044 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1049 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1050 return InvalidParameter
;
1052 /* make a full points copy.. */
1053 ptf
= GdipAlloc(sizeof(GpPointF
)*(count
+1));
1056 memcpy(ptf
, points
, sizeof(GpPointF
)*count
);
1058 /* ..and add a first point as a last one */
1059 ptf
[count
] = ptf
[0];
1061 stat
= GdipDrawCurve2(graphics
, pen
, ptf
, count
+ 1, tension
);
1068 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1069 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1075 if(!points
|| count
<= 0)
1076 return InvalidParameter
;
1078 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1082 for(i
= 0; i
< count
; i
++){
1083 ptf
[i
].X
= (REAL
)points
[i
].X
;
1084 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1087 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1094 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1095 GDIPCONST GpPointF
*points
, INT count
)
1097 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1100 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1101 GDIPCONST GpPoint
*points
, INT count
)
1107 if(!points
|| count
<= 0)
1108 return InvalidParameter
;
1110 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1114 for(i
= 0; i
< count
; i
++){
1115 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1116 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1119 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1125 /* Approximates cardinal spline with Bezier curves. */
1126 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1127 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1129 /* PolyBezier expects count*3-2 points. */
1130 INT i
, len_pt
= count
*3-2, save_state
;
1132 REAL x1
, x2
, y1
, y2
;
1135 if(!graphics
|| !pen
)
1136 return InvalidParameter
;
1138 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1139 tension
= tension
* TENSION_CONST
;
1141 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1144 pt
[0].X
= points
[0].X
;
1145 pt
[0].Y
= points
[0].Y
;
1149 for(i
= 0; i
< count
-2; i
++){
1150 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1154 pt
[3*i
+3].X
= points
[i
+1].X
;
1155 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1160 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1161 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1163 pt
[len_pt
-2].X
= x1
;
1164 pt
[len_pt
-2].Y
= y1
;
1165 pt
[len_pt
-1].X
= points
[count
-1].X
;
1166 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1168 save_state
= prepare_dc(graphics
, pen
);
1170 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1173 restore_dc(graphics
, save_state
);
1178 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1179 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1185 if(!points
|| count
<= 0)
1186 return InvalidParameter
;
1188 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1192 for(i
= 0; i
< count
; i
++){
1193 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1194 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1197 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1203 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1204 REAL y
, REAL width
, REAL height
)
1210 if(!graphics
|| !pen
)
1211 return InvalidParameter
;
1215 ptf
[1].X
= x
+ width
;
1216 ptf
[1].Y
= y
+ height
;
1218 save_state
= prepare_dc(graphics
, pen
);
1219 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1221 transform_and_round_points(graphics
, pti
, ptf
, 2);
1223 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1225 restore_dc(graphics
, save_state
);
1230 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1231 INT y
, INT width
, INT height
)
1233 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1237 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1239 /* IPicture::Render uses LONG coords */
1240 return GdipDrawImageI(graphics
,image
,roundr(x
),roundr(y
));
1243 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1246 UINT width
, height
, srcw
, srch
;
1248 if(!graphics
|| !image
)
1249 return InvalidParameter
;
1251 GdipGetImageWidth(image
, &width
);
1252 GdipGetImageHeight(image
, &height
);
1254 srcw
= width
* (((REAL
) INCH_HIMETRIC
) /
1255 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
)));
1256 srch
= height
* (((REAL
) INCH_HIMETRIC
) /
1257 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
)));
1259 if(image
->type
!= ImageTypeMetafile
){
1264 IPicture_Render(image
->picture
, graphics
->hdc
, x
, y
, width
, height
,
1265 0, 0, srcw
, srch
, NULL
);
1270 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1271 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
1272 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
1273 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1274 DrawImageAbort callback
, VOID
* callbackData
)
1280 TRACE("%p %p %p %d %f %f %f %f %d %p %p %p\n", graphics
, image
, points
, count
,
1281 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1284 if(!graphics
|| !image
|| !points
|| count
!= 3)
1285 return InvalidParameter
;
1287 if(srcUnit
== UnitInch
)
1288 dx
= dy
= (REAL
) INCH_HIMETRIC
;
1289 else if(srcUnit
== UnitPixel
){
1290 dx
= ((REAL
) INCH_HIMETRIC
) /
1291 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
1292 dy
= ((REAL
) INCH_HIMETRIC
) /
1293 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
1296 return NotImplemented
;
1298 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
1299 transform_and_round_points(graphics
, pti
, ptf
, 3);
1301 /* IPicture renders bitmaps with the y-axis reversed
1302 * FIXME: flipping for unknown image type might not be correct. */
1303 if(image
->type
!= ImageTypeMetafile
){
1306 pti
[0].y
= pti
[2].y
;
1310 if(IPicture_Render(image
->picture
, graphics
->hdc
,
1311 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
1312 srcx
* dx
, srcy
* dy
,
1313 srcwidth
* dx
, srcheight
* dy
,
1316 callback(callbackData
);
1317 return GenericError
;
1323 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
1324 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
1325 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1326 DrawImageAbort callback
, VOID
* callbackData
)
1328 GpPointF pointsF
[3];
1331 if(!points
|| count
!=3)
1332 return InvalidParameter
;
1334 for(i
= 0; i
< count
; i
++){
1335 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1336 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1339 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
1340 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
1341 callback
, callbackData
);
1344 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
1345 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
1346 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
1347 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
1348 VOID
* callbackData
)
1354 points
[1].X
= dstx
+ dstwidth
;
1357 points
[2].Y
= dsty
+ dstheight
;
1359 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1360 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1363 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
1364 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
1365 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
1366 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
1367 VOID
* callbackData
)
1373 points
[1].X
= dstx
+ dstwidth
;
1376 points
[2].Y
= dsty
+ dstheight
;
1378 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1379 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1382 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
1383 REAL x
, REAL y
, REAL width
, REAL height
)
1389 if(!graphics
|| !image
)
1390 return InvalidParameter
;
1392 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
1396 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
1397 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
1398 unit
, NULL
, NULL
, NULL
);
1401 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
1402 INT x
, INT y
, INT width
, INT height
)
1404 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
1407 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1408 REAL y1
, REAL x2
, REAL y2
)
1414 if(!pen
|| !graphics
)
1415 return InvalidParameter
;
1422 save_state
= prepare_dc(graphics
, pen
);
1424 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1426 restore_dc(graphics
, save_state
);
1431 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1432 INT y1
, INT x2
, INT y2
)
1438 if(!pen
|| !graphics
)
1439 return InvalidParameter
;
1446 save_state
= prepare_dc(graphics
, pen
);
1448 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1450 restore_dc(graphics
, save_state
);
1455 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1456 GpPointF
*points
, INT count
)
1461 if(!pen
|| !graphics
|| (count
< 2))
1462 return InvalidParameter
;
1464 save_state
= prepare_dc(graphics
, pen
);
1466 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
1468 restore_dc(graphics
, save_state
);
1473 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1474 GpPoint
*points
, INT count
)
1478 GpPointF
*ptf
= NULL
;
1481 if(!pen
|| !graphics
|| (count
< 2))
1482 return InvalidParameter
;
1484 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
1485 if(!ptf
) return OutOfMemory
;
1487 for(i
= 0; i
< count
; i
++){
1488 ptf
[i
].X
= (REAL
) points
[i
].X
;
1489 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
1492 save_state
= prepare_dc(graphics
, pen
);
1494 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
1496 restore_dc(graphics
, save_state
);
1502 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
1507 if(!pen
|| !graphics
)
1508 return InvalidParameter
;
1510 save_state
= prepare_dc(graphics
, pen
);
1512 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
1513 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
1515 restore_dc(graphics
, save_state
);
1520 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1521 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1525 if(!graphics
|| !pen
)
1526 return InvalidParameter
;
1528 save_state
= prepare_dc(graphics
, pen
);
1529 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1531 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1533 restore_dc(graphics
, save_state
);
1538 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1539 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1541 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1544 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1545 REAL y
, REAL width
, REAL height
)
1551 if(!pen
|| !graphics
)
1552 return InvalidParameter
;
1556 ptf
[1].X
= x
+ width
;
1558 ptf
[2].X
= x
+ width
;
1559 ptf
[2].Y
= y
+ height
;
1561 ptf
[3].Y
= y
+ height
;
1563 save_state
= prepare_dc(graphics
, pen
);
1564 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1566 transform_and_round_points(graphics
, pti
, ptf
, 4);
1567 Polygon(graphics
->hdc
, pti
, 4);
1569 restore_dc(graphics
, save_state
);
1574 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1575 INT y
, INT width
, INT height
)
1577 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1580 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
1581 GDIPCONST GpRectF
* rects
, INT count
)
1587 if(!graphics
|| !pen
|| !rects
|| count
< 1)
1588 return InvalidParameter
;
1590 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
1591 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
1599 for(i
= 0; i
< count
; i
++){
1600 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
1601 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
1602 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
1603 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
1606 save_state
= prepare_dc(graphics
, pen
);
1607 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1609 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
1611 for(i
= 0; i
< count
; i
++)
1612 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
1614 restore_dc(graphics
, save_state
);
1622 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
1623 GDIPCONST GpRect
* rects
, INT count
)
1629 if(!rects
|| count
<=0)
1630 return InvalidParameter
;
1632 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
1636 for(i
= 0;i
< count
;i
++){
1637 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
1638 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
1639 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
1640 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
1643 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
1649 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
1650 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
1651 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
1656 TEXTMETRICW textmet
;
1657 GpPointF pt
[2], rectcpy
[4];
1660 REAL angle
, ang_cos
, ang_sin
, rel_width
, rel_height
;
1661 INT sum
= 0, height
= 0, fit
, fitcpy
, save_state
, i
, j
, lret
, nwidth
,
1666 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
1667 return InvalidParameter
;
1669 if((brush
->bt
!= BrushTypeSolidColor
)){
1670 FIXME("not implemented for given parameters\n");
1671 return NotImplemented
;
1675 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
1677 if(length
== -1) length
= lstrlenW(string
);
1679 stringdup
= GdipAlloc(length
* sizeof(WCHAR
));
1680 if(!stringdup
) return OutOfMemory
;
1682 save_state
= SaveDC(graphics
->hdc
);
1683 SetBkMode(graphics
->hdc
, TRANSPARENT
);
1684 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
1686 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
1687 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
1688 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
1689 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
1690 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
1692 if(roundr(rect
->Width
) == 0 && roundr(rect
->Height
) == 0){
1693 rel_width
= rel_height
= 1.0;
1694 nwidth
= nheight
= INT_MAX
;
1697 rel_width
= sqrt((corners
[1].x
- corners
[0].x
) * (corners
[1].x
- corners
[0].x
) +
1698 (corners
[1].y
- corners
[0].y
) * (corners
[1].y
- corners
[0].y
))
1700 rel_height
= sqrt((corners
[2].x
- corners
[1].x
) * (corners
[2].x
- corners
[1].x
) +
1701 (corners
[2].y
- corners
[1].y
) * (corners
[2].y
- corners
[1].y
))
1704 nwidth
= roundr(rel_width
* rect
->Width
);
1705 nheight
= roundr(rel_height
* rect
->Height
);
1706 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
1707 SelectClipRgn(graphics
->hdc
, rgn
);
1710 /* Use gdi to find the font, then perform transformations on it (height,
1712 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
1713 GetTextMetricsW(graphics
->hdc
, &textmet
);
1716 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
1717 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
1723 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
1724 angle
= gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
1725 ang_cos
= cos(angle
);
1726 ang_sin
= sin(angle
);
1727 lfw
.lfEscapement
= lfw
.lfOrientation
= -roundr((angle
/ M_PI
) * 1800.0);
1729 gdifont
= CreateFontIndirectW(&lfw
);
1730 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
1732 for(i
= 0, j
= 0; i
< length
; i
++){
1733 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
1736 stringdup
[j
] = string
[i
];
1743 while(sum
< length
){
1744 drawcoord
.left
= corners
[0].x
+ roundr(ang_sin
* (REAL
) height
);
1745 drawcoord
.top
= corners
[0].y
+ roundr(ang_cos
* (REAL
) height
);
1747 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
1748 nwidth
, &fit
, NULL
, &size
);
1752 DrawTextW(graphics
->hdc
, stringdup
+ sum
, 1, &drawcoord
, DT_NOCLIP
|
1757 for(lret
= 0; lret
< fit
; lret
++)
1758 if(*(stringdup
+ sum
+ lret
) == '\n')
1761 /* Line break code (may look strange, but it imitates windows). */
1763 fit
= lret
; /* this is not an off-by-one error */
1764 else if(fit
< (length
- sum
)){
1765 if(*(stringdup
+ sum
+ fit
) == ' ')
1766 while(*(stringdup
+ sum
+ fit
) == ' ')
1769 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
1772 if(*(stringdup
+ sum
+ fit
) == '\t')
1781 DrawTextW(graphics
->hdc
, stringdup
+ sum
, min(length
- sum
, fit
),
1782 &drawcoord
, DT_NOCLIP
| DT_EXPANDTABS
);
1784 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
1787 if(height
> nheight
)
1790 /* Stop if this was a linewrap (but not if it was a linebreak). */
1791 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
1795 GdipFree(stringdup
);
1797 DeleteObject(gdifont
);
1799 RestoreDC(graphics
->hdc
, save_state
);
1804 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
1805 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
1810 if(!graphics
|| !brush
|| !points
)
1811 return InvalidParameter
;
1813 stat
= GdipCreatePath(fill
, &path
);
1817 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1819 GdipDeletePath(path
);
1823 stat
= GdipFillPath(graphics
, brush
, path
);
1825 GdipDeletePath(path
);
1829 GdipDeletePath(path
);
1834 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
1835 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
1841 if(!points
|| count
<= 0)
1842 return InvalidParameter
;
1844 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1848 for(i
= 0;i
< count
;i
++){
1849 ptf
[i
].X
= (REAL
)points
[i
].X
;
1850 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1853 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
1860 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
1861 REAL y
, REAL width
, REAL height
)
1867 if(!graphics
|| !brush
)
1868 return InvalidParameter
;
1872 ptf
[1].X
= x
+ width
;
1873 ptf
[1].Y
= y
+ height
;
1875 save_state
= SaveDC(graphics
->hdc
);
1876 EndPath(graphics
->hdc
);
1877 SelectObject(graphics
->hdc
, brush
->gdibrush
);
1878 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
1880 transform_and_round_points(graphics
, pti
, ptf
, 2);
1882 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1884 RestoreDC(graphics
->hdc
, save_state
);
1889 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
1890 INT y
, INT width
, INT height
)
1892 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1895 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
1900 if(!brush
|| !graphics
|| !path
)
1901 return InvalidParameter
;
1903 save_state
= SaveDC(graphics
->hdc
);
1904 EndPath(graphics
->hdc
);
1905 SelectObject(graphics
->hdc
, brush
->gdibrush
);
1906 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
1909 BeginPath(graphics
->hdc
);
1910 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1911 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1916 EndPath(graphics
->hdc
);
1917 FillPath(graphics
->hdc
);
1922 RestoreDC(graphics
->hdc
, save_state
);
1927 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
1928 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1932 if(!graphics
|| !brush
)
1933 return InvalidParameter
;
1935 save_state
= SaveDC(graphics
->hdc
);
1936 EndPath(graphics
->hdc
);
1937 SelectObject(graphics
->hdc
, brush
->gdibrush
);
1938 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
1940 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1942 RestoreDC(graphics
->hdc
, save_state
);
1947 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
1948 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1950 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1953 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
1954 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
1957 GpPointF
*ptf
= NULL
;
1959 GpStatus retval
= Ok
;
1961 if(!graphics
|| !brush
|| !points
|| !count
)
1962 return InvalidParameter
;
1964 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
1965 pti
= GdipAlloc(count
* sizeof(POINT
));
1967 retval
= OutOfMemory
;
1971 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
1973 save_state
= SaveDC(graphics
->hdc
);
1974 EndPath(graphics
->hdc
);
1975 SelectObject(graphics
->hdc
, brush
->gdibrush
);
1976 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
1977 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
1980 transform_and_round_points(graphics
, pti
, ptf
, count
);
1981 Polygon(graphics
->hdc
, pti
, count
);
1983 RestoreDC(graphics
->hdc
, save_state
);
1992 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
1993 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
1996 GpPointF
*ptf
= NULL
;
1998 GpStatus retval
= Ok
;
2000 if(!graphics
|| !brush
|| !points
|| !count
)
2001 return InvalidParameter
;
2003 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2004 pti
= GdipAlloc(count
* sizeof(POINT
));
2006 retval
= OutOfMemory
;
2010 for(i
= 0; i
< count
; i
++){
2011 ptf
[i
].X
= (REAL
) points
[i
].X
;
2012 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2015 save_state
= SaveDC(graphics
->hdc
);
2016 EndPath(graphics
->hdc
);
2017 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2018 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2019 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2022 transform_and_round_points(graphics
, pti
, ptf
, count
);
2023 Polygon(graphics
->hdc
, pti
, count
);
2025 RestoreDC(graphics
->hdc
, save_state
);
2034 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
2035 GDIPCONST GpPointF
*points
, INT count
)
2037 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
2040 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
2041 GDIPCONST GpPoint
*points
, INT count
)
2043 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
2046 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
2047 REAL x
, REAL y
, REAL width
, REAL height
)
2053 if(!graphics
|| !brush
)
2054 return InvalidParameter
;
2058 ptf
[1].X
= x
+ width
;
2060 ptf
[2].X
= x
+ width
;
2061 ptf
[2].Y
= y
+ height
;
2063 ptf
[3].Y
= y
+ height
;
2065 save_state
= SaveDC(graphics
->hdc
);
2066 EndPath(graphics
->hdc
);
2067 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2068 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2070 transform_and_round_points(graphics
, pti
, ptf
, 4);
2072 Polygon(graphics
->hdc
, pti
, 4);
2074 RestoreDC(graphics
->hdc
, save_state
);
2079 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
2080 INT x
, INT y
, INT width
, INT height
)
2086 if(!graphics
|| !brush
)
2087 return InvalidParameter
;
2091 ptf
[1].X
= x
+ width
;
2093 ptf
[2].X
= x
+ width
;
2094 ptf
[2].Y
= y
+ height
;
2096 ptf
[3].Y
= y
+ height
;
2098 save_state
= SaveDC(graphics
->hdc
);
2099 EndPath(graphics
->hdc
);
2100 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2101 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2103 transform_and_round_points(graphics
, pti
, ptf
, 4);
2105 Polygon(graphics
->hdc
, pti
, 4);
2107 RestoreDC(graphics
->hdc
, save_state
);
2112 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
2119 return InvalidParameter
;
2121 for(i
= 0; i
< count
; i
++){
2122 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2123 if(ret
!= Ok
) return ret
;
2129 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
2136 if(!rects
|| count
<= 0)
2137 return InvalidParameter
;
2139 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
2143 for(i
= 0; i
< count
; i
++){
2144 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2145 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2146 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
2147 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2150 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
2156 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
2159 if (!(graphics
&& brush
&& region
))
2160 return InvalidParameter
;
2162 FIXME("(%p, %p, %p): stub\n", graphics
, brush
, region
);
2164 return NotImplemented
;
2167 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
2172 return InvalidParameter
;
2175 FIXME("not implemented\n");
2177 return NotImplemented
;
2180 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
2181 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
2182 CompositingMode
*mode
)
2184 if(!graphics
|| !mode
)
2185 return InvalidParameter
;
2187 *mode
= graphics
->compmode
;
2192 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
2193 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
2194 CompositingQuality
*quality
)
2196 if(!graphics
|| !quality
)
2197 return InvalidParameter
;
2199 *quality
= graphics
->compqual
;
2204 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
2205 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
2206 InterpolationMode
*mode
)
2208 if(!graphics
|| !mode
)
2209 return InvalidParameter
;
2211 *mode
= graphics
->interpolation
;
2216 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
2218 if(!graphics
|| !scale
)
2219 return InvalidParameter
;
2221 *scale
= graphics
->scale
;
2226 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
2228 if(!graphics
|| !unit
)
2229 return InvalidParameter
;
2231 *unit
= graphics
->unit
;
2236 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
2237 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
2240 if(!graphics
|| !mode
)
2241 return InvalidParameter
;
2243 *mode
= graphics
->pixeloffset
;
2248 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
2249 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
2251 if(!graphics
|| !mode
)
2252 return InvalidParameter
;
2254 *mode
= graphics
->smoothing
;
2259 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
2260 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
2261 TextRenderingHint
*hint
)
2263 if(!graphics
|| !hint
)
2264 return InvalidParameter
;
2266 *hint
= graphics
->texthint
;
2271 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2273 if(!graphics
|| !matrix
)
2274 return InvalidParameter
;
2276 *matrix
= *graphics
->worldtrans
;
2280 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
2281 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
2282 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
2283 INT regionCount
, GpRegion
** regions
)
2285 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
2286 return InvalidParameter
;
2288 FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics
, debugstr_w(string
),
2289 length
, font
, layoutRect
, stringFormat
, regionCount
, regions
);
2291 return NotImplemented
;
2294 /* Find the smallest rectangle that bounds the text when it is printed in rect
2295 * according to the format options listed in format. If rect has 0 width and
2296 * height, then just find the smallest rectangle that bounds the text when it's
2297 * printed at location (rect->X, rect-Y). */
2298 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
2299 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
2300 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
2301 INT
*codepointsfitted
, INT
*linesfilled
)
2305 INT sum
= 0, height
= 0, fit
, fitcpy
, max_width
= 0, i
, j
, lret
, nwidth
,
2309 if(!graphics
|| !string
|| !font
|| !rect
)
2310 return InvalidParameter
;
2312 if(codepointsfitted
|| linesfilled
){
2313 FIXME("not implemented for given parameters\n");
2314 return NotImplemented
;
2318 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
2320 if(length
== -1) length
= lstrlenW(string
);
2322 stringdup
= GdipAlloc(length
* sizeof(WCHAR
));
2323 if(!stringdup
) return OutOfMemory
;
2325 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2326 nwidth
= roundr(rect
->Width
);
2327 nheight
= roundr(rect
->Height
);
2329 if((nwidth
== 0) && (nheight
== 0))
2330 nwidth
= nheight
= INT_MAX
;
2332 for(i
= 0, j
= 0; i
< length
; i
++){
2333 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
2336 stringdup
[j
] = string
[i
];
2343 while(sum
< length
){
2344 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
2345 nwidth
, &fit
, NULL
, &size
);
2351 for(lret
= 0; lret
< fit
; lret
++)
2352 if(*(stringdup
+ sum
+ lret
) == '\n')
2355 /* Line break code (may look strange, but it imitates windows). */
2357 fit
= lret
; /* this is not an off-by-one error */
2358 else if(fit
< (length
- sum
)){
2359 if(*(stringdup
+ sum
+ fit
) == ' ')
2360 while(*(stringdup
+ sum
+ fit
) == ' ')
2363 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
2366 if(*(stringdup
+ sum
+ fit
) == '\t')
2376 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, fit
,
2377 nwidth
, &j
, NULL
, &size
);
2379 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
2381 max_width
= max(max_width
, size
.cx
);
2383 if(height
> nheight
)
2386 /* Stop if this was a linewrap (but not if it was a linebreak). */
2387 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
2391 bounds
->X
= rect
->X
;
2392 bounds
->Y
= rect
->Y
;
2393 bounds
->Width
= (REAL
)max_width
;
2394 bounds
->Height
= (REAL
) min(height
, nheight
);
2396 GdipFree(stringdup
);
2397 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
2402 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
2405 return InvalidParameter
;
2407 graphics
->worldtrans
->matrix
[0] = 1.0;
2408 graphics
->worldtrans
->matrix
[1] = 0.0;
2409 graphics
->worldtrans
->matrix
[2] = 0.0;
2410 graphics
->worldtrans
->matrix
[3] = 1.0;
2411 graphics
->worldtrans
->matrix
[4] = 0.0;
2412 graphics
->worldtrans
->matrix
[5] = 0.0;
2417 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
2422 return InvalidParameter
;
2425 FIXME("graphics state not implemented\n");
2427 return NotImplemented
;
2430 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
2431 GpMatrixOrder order
)
2434 return InvalidParameter
;
2436 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
2439 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
2443 if(!graphics
|| !state
)
2444 return InvalidParameter
;
2447 FIXME("graphics state not implemented\n");
2449 return NotImplemented
;
2452 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
2453 REAL sy
, GpMatrixOrder order
)
2456 return InvalidParameter
;
2458 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
2461 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
2462 CompositingMode mode
)
2465 return InvalidParameter
;
2467 graphics
->compmode
= mode
;
2472 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
2473 CompositingQuality quality
)
2476 return InvalidParameter
;
2478 graphics
->compqual
= quality
;
2483 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
2484 InterpolationMode mode
)
2487 return InvalidParameter
;
2489 graphics
->interpolation
= mode
;
2494 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
2496 if(!graphics
|| (scale
<= 0.0))
2497 return InvalidParameter
;
2499 graphics
->scale
= scale
;
2504 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
2506 if(!graphics
|| (unit
== UnitWorld
))
2507 return InvalidParameter
;
2509 graphics
->unit
= unit
;
2514 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
2518 return InvalidParameter
;
2520 graphics
->pixeloffset
= mode
;
2525 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
2528 return InvalidParameter
;
2530 graphics
->smoothing
= mode
;
2535 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
2536 TextRenderingHint hint
)
2539 return InvalidParameter
;
2541 graphics
->texthint
= hint
;
2546 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2548 if(!graphics
|| !matrix
)
2549 return InvalidParameter
;
2551 GdipDeleteMatrix(graphics
->worldtrans
);
2552 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
2555 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
2556 REAL dy
, GpMatrixOrder order
)
2559 return InvalidParameter
;
2561 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
2564 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
2565 INT width
, INT height
,
2566 CombineMode combineMode
)
2571 FIXME("not implemented\n");
2573 return NotImplemented
;
2576 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
2577 CombineMode combineMode
)
2582 FIXME("not implemented\n");
2584 return NotImplemented
;
2587 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpGraphics
*graphics
,
2593 FIXME("not implemented\n");
2595 return NotImplemented
;
2598 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
2604 if(!graphics
|| !pen
|| count
<=0)
2605 return InvalidParameter
;
2607 pti
= GdipAlloc(sizeof(POINT
) * count
);
2609 save_state
= prepare_dc(graphics
, pen
);
2610 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2612 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
2613 Polygon(graphics
->hdc
, pti
, count
);
2615 restore_dc(graphics
, save_state
);
2621 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
2628 if(count
<=0) return InvalidParameter
;
2629 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
2631 for(i
= 0;i
< count
; i
++){
2632 ptf
[i
].X
= (REAL
)points
[i
].X
;
2633 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2636 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
2642 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
2644 if(!graphics
|| !dpi
)
2645 return InvalidParameter
;
2647 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
2652 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
2654 if(!graphics
|| !dpi
)
2655 return InvalidParameter
;
2657 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
2662 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
2663 GpMatrixOrder order
)
2668 if(!graphics
|| !matrix
)
2669 return InvalidParameter
;
2671 m
= *(graphics
->worldtrans
);
2673 ret
= GdipMultiplyMatrix(&m
, (GpMatrix
*)matrix
, order
);
2675 *(graphics
->worldtrans
) = m
;
2680 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
2682 FIXME("(%p, %p): stub\n", graphics
, hdc
);
2685 return NotImplemented
;
2688 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
2690 FIXME("(%p, %p): stub\n", graphics
, hdc
);
2692 return NotImplemented
;
2695 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
2697 FIXME("(%p, %p): stub\n", graphics
, region
);
2699 return NotImplemented
;
2702 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
2703 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
2705 FIXME("(%p, %d, %d, %p, %d): stub\n", graphics
, dst_space
, src_space
, points
, count
);
2707 return NotImplemented
;
2710 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
2711 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
2713 FIXME("(%p, %d, %d, %p, %d): stub\n", graphics
, dst_space
, src_space
, points
, count
);
2715 return NotImplemented
;