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 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
179 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
180 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
184 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
188 /* clamp to between 0.0 and 1.0, using the wrap mode */
189 if (brush
->wrap
== WrapModeTile
)
191 position
= fmodf(position
, 1.0f
);
192 if (position
< 0.0f
) position
+= 1.0f
;
194 else /* WrapModeFlip* */
196 position
= fmodf(position
, 2.0f
);
197 if (position
< 0.0f
) position
+= 2.0f
;
198 if (position
> 1.0f
) position
= 2.0f
- position
;
201 if (brush
->blendcount
== 1)
206 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
209 /* locate the blend positions surrounding this position */
210 while (position
> brush
->blendpos
[i
])
213 /* interpolate between the blend positions */
214 left_blendpos
= brush
->blendpos
[i
-1];
215 left_blendfac
= brush
->blendfac
[i
-1];
216 right_blendpos
= brush
->blendpos
[i
];
217 right_blendfac
= brush
->blendfac
[i
];
218 range
= right_blendpos
- left_blendpos
;
219 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
220 right_blendfac
* (position
- left_blendpos
)) / range
;
222 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
225 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
229 case BrushTypeLinearGradient
:
231 GpLineGradient
*line
= (GpLineGradient
*)brush
;
234 SelectClipPath(graphics
->hdc
, RGN_AND
);
235 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
237 GpPointF endpointsf
[2];
241 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
243 endpointsf
[0] = line
->startpoint
;
244 endpointsf
[1] = line
->endpoint
;
245 transform_and_round_points(graphics
, endpointsi
, endpointsf
, 2);
247 if (abs(endpointsi
[0].x
-endpointsi
[1].x
) > abs(endpointsi
[0].y
-endpointsi
[1].y
))
249 /* vertical-ish gradient */
250 int startx
, endx
; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
251 int startbottomx
; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
254 HBRUSH hbrush
, hprevbrush
;
255 int leftx
, rightx
; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
257 int tilt
; /* horizontal distance covered by a gradient line */
259 startx
= roundr((rc
.top
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
260 endx
= roundr((rc
.top
- endpointsf
[1].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[1].X
);
261 width
= endx
- startx
;
262 startbottomx
= roundr((rc
.bottom
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
263 tilt
= startx
- startbottomx
;
265 if (startx
>= startbottomx
)
268 rightx
= rc
.right
+ tilt
;
272 leftx
= rc
.left
+ tilt
;
276 poly
[0].y
= rc
.bottom
;
279 poly
[3].y
= rc
.bottom
;
281 for (x
=leftx
; x
<=rightx
; x
++)
283 ARGB argb
= blend_line_gradient(line
, (x
-startx
)/(REAL
)width
);
284 col
= ARGB2COLORREF(argb
);
285 hbrush
= CreateSolidBrush(col
);
286 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
287 poly
[0].x
= x
- tilt
- 1;
290 poly
[3].x
= x
- tilt
;
291 Polygon(graphics
->hdc
, poly
, 4);
292 SelectObject(graphics
->hdc
, hprevbrush
);
293 DeleteObject(hbrush
);
296 else if (endpointsi
[0].y
!= endpointsi
[1].y
)
298 /* horizontal-ish gradient */
299 int starty
, endy
; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
300 int startrighty
; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
303 HBRUSH hbrush
, hprevbrush
;
304 int topy
, bottomy
; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
306 int tilt
; /* vertical distance covered by a gradient line */
308 starty
= roundr((rc
.left
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
309 endy
= roundr((rc
.left
- endpointsf
[1].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[1].Y
);
310 height
= endy
- starty
;
311 startrighty
= roundr((rc
.right
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
312 tilt
= starty
- startrighty
;
314 if (starty
>= startrighty
)
317 bottomy
= rc
.bottom
+ tilt
;
321 topy
= rc
.top
+ tilt
;
325 poly
[0].x
= rc
.right
;
328 poly
[3].x
= rc
.right
;
330 for (y
=topy
; y
<=bottomy
; y
++)
332 ARGB argb
= blend_line_gradient(line
, (y
-starty
)/(REAL
)height
);
333 col
= ARGB2COLORREF(argb
);
334 hbrush
= CreateSolidBrush(col
);
335 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
336 poly
[0].y
= y
- tilt
- 1;
339 poly
[3].y
= y
- tilt
;
340 Polygon(graphics
->hdc
, poly
, 4);
341 SelectObject(graphics
->hdc
, hprevbrush
);
342 DeleteObject(hbrush
);
345 /* else startpoint == endpoint */
349 case BrushTypeSolidColor
:
351 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
355 /* partially transparent fill */
357 SelectClipPath(graphics
->hdc
, RGN_AND
);
358 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
360 HDC hdc
= CreateCompatibleDC(NULL
);
366 oldbmp
= SelectObject(hdc
, fill
->bmp
);
368 bf
.BlendOp
= AC_SRC_OVER
;
370 bf
.SourceConstantAlpha
= 255;
371 bf
.AlphaFormat
= AC_SRC_ALPHA
;
373 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
375 SelectObject(hdc
, oldbmp
);
381 /* else fall through */
384 SelectObject(graphics
->hdc
, brush
->gdibrush
);
385 FillPath(graphics
->hdc
);
390 /* GdipDrawPie/GdipFillPie helper function */
391 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
392 REAL height
, REAL startAngle
, REAL sweepAngle
)
399 ptf
[1].X
= x
+ width
;
400 ptf
[1].Y
= y
+ height
;
402 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
403 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
405 transform_and_round_points(graphics
, pti
, ptf
, 4);
407 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
408 pti
[2].y
, pti
[3].x
, pti
[3].y
);
411 /* Draws the linecap the specified color and size on the hdc. The linecap is in
412 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
413 * should not be called on an hdc that has a path you care about. */
414 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
415 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
417 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
418 GpMatrix
*matrix
= NULL
;
421 PointF ptf
[4], *custptf
= NULL
;
422 POINT pt
[4], *custpt
= NULL
;
424 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
429 if((x1
== x2
) && (y1
== y2
))
432 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
434 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
436 brush
= CreateSolidBrush(color
);
437 lb
.lbStyle
= BS_SOLID
;
440 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
441 PS_JOIN_MITER
, 1, &lb
, 0,
443 oldbrush
= SelectObject(graphics
->hdc
, brush
);
444 oldpen
= SelectObject(graphics
->hdc
, pen
);
451 case LineCapSquareAnchor
:
452 case LineCapDiamondAnchor
:
453 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
454 if(cap
== LineCapDiamondAnchor
){
455 dsmall
= cos(theta
+ M_PI_2
) * size
;
456 dbig
= sin(theta
+ M_PI_2
) * size
;
459 dsmall
= cos(theta
+ M_PI_4
) * size
;
460 dbig
= sin(theta
+ M_PI_4
) * size
;
463 ptf
[0].X
= x2
- dsmall
;
464 ptf
[1].X
= x2
+ dbig
;
466 ptf
[0].Y
= y2
- dbig
;
467 ptf
[3].Y
= y2
+ dsmall
;
469 ptf
[1].Y
= y2
- dsmall
;
470 ptf
[2].Y
= y2
+ dbig
;
472 ptf
[3].X
= x2
- dbig
;
473 ptf
[2].X
= x2
+ dsmall
;
475 transform_and_round_points(graphics
, pt
, ptf
, 4);
476 Polygon(graphics
->hdc
, pt
, 4);
479 case LineCapArrowAnchor
:
480 size
= size
* 4.0 / sqrt(3.0);
482 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
483 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
488 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
489 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
497 transform_and_round_points(graphics
, pt
, ptf
, 3);
498 Polygon(graphics
->hdc
, pt
, 3);
501 case LineCapRoundAnchor
:
502 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
509 transform_and_round_points(graphics
, pt
, ptf
, 2);
510 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
513 case LineCapTriangle
:
515 dx
= cos(M_PI_2
+ theta
) * size
;
516 dy
= sin(M_PI_2
+ theta
) * size
;
523 dx
= cos(theta
) * size
;
524 dy
= sin(theta
) * size
;
529 transform_and_round_points(graphics
, pt
, ptf
, 3);
530 Polygon(graphics
->hdc
, pt
, 3);
534 dx
= dy
= size
/ 2.0;
541 dx
= -cos(M_PI_2
+ theta
) * size
;
542 dy
= -sin(M_PI_2
+ theta
) * size
;
549 transform_and_round_points(graphics
, pt
, ptf
, 4);
550 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
551 pt
[2].y
, pt
[3].x
, pt
[3].y
);
558 count
= custom
->pathdata
.Count
;
559 custptf
= GdipAlloc(count
* sizeof(PointF
));
560 custpt
= GdipAlloc(count
* sizeof(POINT
));
561 tp
= GdipAlloc(count
);
563 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
566 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
568 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
569 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
571 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
572 GdipTransformMatrixPoints(matrix
, custptf
, count
);
574 transform_and_round_points(graphics
, custpt
, custptf
, count
);
576 for(i
= 0; i
< count
; i
++)
577 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
580 BeginPath(graphics
->hdc
);
581 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
582 EndPath(graphics
->hdc
);
583 StrokeAndFillPath(graphics
->hdc
);
586 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
592 GdipDeleteMatrix(matrix
);
599 SelectObject(graphics
->hdc
, oldbrush
);
600 SelectObject(graphics
->hdc
, oldpen
);
606 /* Shortens the line by the given percent by changing x2, y2.
607 * If percent is > 1.0 then the line will change direction.
608 * If percent is negative it can lengthen the line. */
609 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
611 REAL dist
, theta
, dx
, dy
;
613 if((y1
== *y2
) && (x1
== *x2
))
616 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
617 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
618 dx
= cos(theta
) * dist
;
619 dy
= sin(theta
) * dist
;
625 /* Shortens the line by the given amount by changing x2, y2.
626 * If the amount is greater than the distance, the line will become length 0.
627 * If the amount is negative, it can lengthen the line. */
628 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
630 REAL dx
, dy
, percent
;
634 if(dx
== 0 && dy
== 0)
637 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
644 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
647 /* Draws lines between the given points, and if caps is true then draws an endcap
648 * at the end of the last line. */
649 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
650 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
653 GpPointF
*ptcopy
= NULL
;
654 GpStatus status
= GenericError
;
659 pti
= GdipAlloc(count
* sizeof(POINT
));
660 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
663 status
= OutOfMemory
;
667 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
670 if(pen
->endcap
== LineCapArrowAnchor
)
671 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
672 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
673 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
674 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
675 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
676 pen
->customend
->inset
* pen
->width
);
678 if(pen
->startcap
== LineCapArrowAnchor
)
679 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
680 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
681 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
682 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
683 &ptcopy
[0].X
, &ptcopy
[0].Y
,
684 pen
->customstart
->inset
* pen
->width
);
686 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
687 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
688 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
689 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
692 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
694 if(Polyline(graphics
->hdc
, pti
, count
))
704 /* Conducts a linear search to find the bezier points that will back off
705 * the endpoint of the curve by a distance of amt. Linear search works
706 * better than binary in this case because there are multiple solutions,
707 * and binary searches often find a bad one. I don't think this is what
708 * Windows does but short of rendering the bezier without GDI's help it's
709 * the best we can do. If rev then work from the start of the passed points
710 * instead of the end. */
711 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
714 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
715 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
724 origx
= pt
[fourth
].X
;
725 origy
= pt
[fourth
].Y
;
726 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
728 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
729 /* reset bezier points to original values */
730 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
731 /* Perform magic on bezier points. Order is important here.*/
732 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
733 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
734 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
735 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
736 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
737 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
739 dx
= pt
[fourth
].X
- origx
;
740 dy
= pt
[fourth
].Y
- origy
;
742 diff
= sqrt(dx
* dx
+ dy
* dy
);
743 percent
+= 0.0005 * amt
;
747 /* Draws bezier curves between given points, and if caps is true then draws an
748 * endcap at the end of the last line. */
749 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
750 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
754 GpStatus status
= GenericError
;
759 pti
= GdipAlloc(count
* sizeof(POINT
));
760 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
763 status
= OutOfMemory
;
767 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
770 if(pen
->endcap
== LineCapArrowAnchor
)
771 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
772 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
773 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
776 if(pen
->startcap
== LineCapArrowAnchor
)
777 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
778 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
779 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
781 /* the direction of the line cap is parallel to the direction at the
782 * end of the bezier (which, if it has been shortened, is not the same
783 * as the direction from pt[count-2] to pt[count-1]) */
784 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
785 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
786 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
787 pt
[count
- 1].X
, pt
[count
- 1].Y
);
789 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
790 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
791 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
794 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
796 PolyBezier(graphics
->hdc
, pti
, count
);
807 /* Draws a combination of bezier curves and lines between points. */
808 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
809 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
811 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
812 BYTE
*tp
= GdipAlloc(count
);
813 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
815 GpStatus status
= GenericError
;
821 if(!pti
|| !tp
|| !ptcopy
){
822 status
= OutOfMemory
;
826 for(i
= 1; i
< count
; i
++){
827 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
828 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
829 || !(types
[i
+ 1] & PathPointTypeBezier
)){
830 ERR("Bad bezier points\n");
837 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
839 /* If we are drawing caps, go through the points and adjust them accordingly,
840 * and draw the caps. */
842 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
843 case PathPointTypeBezier
:
844 if(pen
->endcap
== LineCapArrowAnchor
)
845 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
846 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
847 shorten_bezier_amt(&ptcopy
[count
- 4],
848 pen
->width
* pen
->customend
->inset
, FALSE
);
850 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
851 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
852 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
853 pt
[count
- 1].X
, pt
[count
- 1].Y
);
856 case PathPointTypeLine
:
857 if(pen
->endcap
== LineCapArrowAnchor
)
858 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
859 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
861 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
862 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
863 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
864 pen
->customend
->inset
* pen
->width
);
866 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
867 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
872 ERR("Bad path last point\n");
876 /* Find start of points */
877 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
878 == PathPointTypeStart
); j
++);
880 switch(types
[j
] & PathPointTypePathTypeMask
){
881 case PathPointTypeBezier
:
882 if(pen
->startcap
== LineCapArrowAnchor
)
883 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
884 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
885 shorten_bezier_amt(&ptcopy
[j
- 1],
886 pen
->width
* pen
->customstart
->inset
, TRUE
);
888 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
889 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
890 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
891 pt
[j
- 1].X
, pt
[j
- 1].Y
);
894 case PathPointTypeLine
:
895 if(pen
->startcap
== LineCapArrowAnchor
)
896 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
897 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
899 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
900 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
901 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
902 pen
->customstart
->inset
* pen
->width
);
904 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
905 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
910 ERR("Bad path points\n");
915 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
917 for(i
= 0; i
< count
; i
++){
918 tp
[i
] = convert_path_point_type(types
[i
]);
921 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
933 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
937 BeginPath(graphics
->hdc
);
938 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
939 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
940 EndPath(graphics
->hdc
);
944 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
946 TRACE("(%p, %p)\n", hdc
, graphics
);
948 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
951 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
955 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
957 if(hDevice
!= NULL
) {
958 FIXME("Don't know how to hadle parameter hDevice\n");
959 return NotImplemented
;
966 return InvalidParameter
;
968 *graphics
= GdipAlloc(sizeof(GpGraphics
));
969 if(!*graphics
) return OutOfMemory
;
971 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
976 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
977 GdipFree((*graphics
)->worldtrans
);
982 (*graphics
)->hdc
= hdc
;
983 (*graphics
)->hwnd
= WindowFromDC(hdc
);
984 (*graphics
)->owndc
= FALSE
;
985 (*graphics
)->smoothing
= SmoothingModeDefault
;
986 (*graphics
)->compqual
= CompositingQualityDefault
;
987 (*graphics
)->interpolation
= InterpolationModeDefault
;
988 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
989 (*graphics
)->compmode
= CompositingModeSourceOver
;
990 (*graphics
)->unit
= UnitDisplay
;
991 (*graphics
)->scale
= 1.0;
992 (*graphics
)->busy
= FALSE
;
993 (*graphics
)->textcontrast
= 4;
998 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1003 TRACE("(%p, %p)\n", hwnd
, graphics
);
1007 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1009 ReleaseDC(hwnd
, hdc
);
1013 (*graphics
)->hwnd
= hwnd
;
1014 (*graphics
)->owndc
= TRUE
;
1019 /* FIXME: no icm handling */
1020 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
1022 TRACE("(%p, %p)\n", hwnd
, graphics
);
1024 return GdipCreateFromHWND(hwnd
, graphics
);
1027 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
1028 GpMetafile
**metafile
)
1032 if(!hemf
|| !metafile
)
1033 return InvalidParameter
;
1036 FIXME("not implemented\n");
1038 return NotImplemented
;
1041 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1042 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1044 IStream
*stream
= NULL
;
1048 GpStatus retval
= GenericError
;
1050 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1052 if(!hwmf
|| !metafile
|| !placeable
)
1053 return InvalidParameter
;
1056 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1058 return GenericError
;
1059 copy
= GdipAlloc(read
);
1060 GetMetaFileBitsEx(hwmf
, read
, copy
);
1062 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1065 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1066 copy
= GdipAlloc(read
);
1067 GetEnhMetaFileBits(hemf
, read
, copy
);
1068 DeleteEnhMetaFile(hemf
);
1070 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1071 ERR("could not make stream\n");
1076 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1078 retval
= OutOfMemory
;
1082 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1083 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1087 (*metafile
)->image
.type
= ImageTypeMetafile
;
1088 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1089 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Right
) / ((REAL
) placeable
->Inch
);
1090 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1091 - placeable
->BoundingBox
.Left
)) / ((REAL
) placeable
->Inch
);
1092 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1093 - placeable
->BoundingBox
.Top
)) / ((REAL
) placeable
->Inch
);
1094 (*metafile
)->unit
= UnitInch
;
1097 DeleteMetaFile(hwmf
);
1102 GdipFree(*metafile
);
1103 IStream_Release(stream
);
1107 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1108 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1110 HMETAFILE hmf
= GetMetaFileW(file
);
1112 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1114 if(!hmf
) return InvalidParameter
;
1116 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1119 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1120 UINT access
, IStream
**stream
)
1125 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1127 if(!stream
|| !filename
)
1128 return InvalidParameter
;
1130 if(access
& GENERIC_WRITE
)
1131 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1132 else if(access
& GENERIC_READ
)
1133 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1135 return InvalidParameter
;
1137 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1139 return hresult_to_status(ret
);
1142 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1144 TRACE("(%p)\n", graphics
);
1146 if(!graphics
) return InvalidParameter
;
1147 if(graphics
->busy
) return ObjectBusy
;
1150 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1152 GdipDeleteRegion(graphics
->clip
);
1153 GdipDeleteMatrix(graphics
->worldtrans
);
1159 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1160 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1162 INT save_state
, num_pts
;
1163 GpPointF points
[MAX_ARC_PTS
];
1166 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1167 width
, height
, startAngle
, sweepAngle
);
1169 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1170 return InvalidParameter
;
1175 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1177 save_state
= prepare_dc(graphics
, pen
);
1179 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
1181 restore_dc(graphics
, save_state
);
1186 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1187 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1189 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1190 width
, height
, startAngle
, sweepAngle
);
1192 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1195 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1196 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
1202 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
1203 x2
, y2
, x3
, y3
, x4
, y4
);
1205 if(!graphics
|| !pen
)
1206 return InvalidParameter
;
1220 save_state
= prepare_dc(graphics
, pen
);
1222 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1224 restore_dc(graphics
, save_state
);
1229 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1230 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1236 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1237 x2
, y2
, x3
, y3
, x4
, y4
);
1239 if(!graphics
|| !pen
)
1240 return InvalidParameter
;
1254 save_state
= prepare_dc(graphics
, pen
);
1256 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1258 restore_dc(graphics
, save_state
);
1263 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1264 GDIPCONST GpPointF
*points
, INT count
)
1269 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1271 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1272 return InvalidParameter
;
1277 for(i
= 0; i
< floor(count
/ 4); i
++){
1278 ret
= GdipDrawBezier(graphics
, pen
,
1279 points
[4*i
].X
, points
[4*i
].Y
,
1280 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1281 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1282 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1290 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1291 GDIPCONST GpPoint
*points
, INT count
)
1297 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1299 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1300 return InvalidParameter
;
1305 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1309 for(i
= 0; i
< count
; i
++){
1310 pts
[i
].X
= (REAL
)points
[i
].X
;
1311 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1314 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1321 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1322 GDIPCONST GpPointF
*points
, INT count
)
1324 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1326 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1329 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1330 GDIPCONST GpPoint
*points
, INT count
)
1332 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1334 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1337 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1338 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1343 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1345 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1346 return InvalidParameter
;
1351 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1354 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1356 GdipDeletePath(path
);
1360 stat
= GdipDrawPath(graphics
, pen
, path
);
1362 GdipDeletePath(path
);
1367 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1368 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1374 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1376 if(!points
|| count
<= 0)
1377 return InvalidParameter
;
1379 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1383 for(i
= 0; i
< count
; i
++){
1384 ptf
[i
].X
= (REAL
)points
[i
].X
;
1385 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1388 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1395 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1396 GDIPCONST GpPointF
*points
, INT count
)
1398 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1400 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1403 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1404 GDIPCONST GpPoint
*points
, INT count
)
1410 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1412 if(!points
|| count
<= 0)
1413 return InvalidParameter
;
1415 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1419 for(i
= 0; i
< count
; i
++){
1420 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1421 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1424 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1430 /* Approximates cardinal spline with Bezier curves. */
1431 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1432 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1434 /* PolyBezier expects count*3-2 points. */
1435 INT i
, len_pt
= count
*3-2, save_state
;
1437 REAL x1
, x2
, y1
, y2
;
1440 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1442 if(!graphics
|| !pen
)
1443 return InvalidParameter
;
1448 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1449 tension
= tension
* TENSION_CONST
;
1451 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1454 pt
[0].X
= points
[0].X
;
1455 pt
[0].Y
= points
[0].Y
;
1459 for(i
= 0; i
< count
-2; i
++){
1460 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1464 pt
[3*i
+3].X
= points
[i
+1].X
;
1465 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1470 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1471 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1473 pt
[len_pt
-2].X
= x1
;
1474 pt
[len_pt
-2].Y
= y1
;
1475 pt
[len_pt
-1].X
= points
[count
-1].X
;
1476 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1478 save_state
= prepare_dc(graphics
, pen
);
1480 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1483 restore_dc(graphics
, save_state
);
1488 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1489 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1495 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1497 if(!points
|| count
<= 0)
1498 return InvalidParameter
;
1500 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1504 for(i
= 0; i
< count
; i
++){
1505 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1506 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1509 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1515 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1516 REAL y
, REAL width
, REAL height
)
1522 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1524 if(!graphics
|| !pen
)
1525 return InvalidParameter
;
1532 ptf
[1].X
= x
+ width
;
1533 ptf
[1].Y
= y
+ height
;
1535 save_state
= prepare_dc(graphics
, pen
);
1536 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1538 transform_and_round_points(graphics
, pti
, ptf
, 2);
1540 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1542 restore_dc(graphics
, save_state
);
1547 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1548 INT y
, INT width
, INT height
)
1550 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1552 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1556 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1558 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1560 /* IPicture::Render uses LONG coords */
1561 return GdipDrawImageI(graphics
,image
,roundr(x
),roundr(y
));
1564 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1567 UINT width
, height
, srcw
, srch
;
1569 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1571 if(!graphics
|| !image
)
1572 return InvalidParameter
;
1574 GdipGetImageWidth(image
, &width
);
1575 GdipGetImageHeight(image
, &height
);
1577 srcw
= width
* (((REAL
) INCH_HIMETRIC
) /
1578 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
)));
1579 srch
= height
* (((REAL
) INCH_HIMETRIC
) /
1580 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
)));
1582 if(image
->type
!= ImageTypeMetafile
){
1587 IPicture_Render(image
->picture
, graphics
->hdc
, x
, y
, width
, height
,
1588 0, 0, srcw
, srch
, NULL
);
1593 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1594 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
1595 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
1596 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1597 DrawImageAbort callback
, VOID
* callbackData
)
1603 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
1604 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1607 if(!graphics
|| !image
|| !points
|| count
!= 3)
1608 return InvalidParameter
;
1610 if(srcUnit
== UnitInch
)
1611 dx
= dy
= (REAL
) INCH_HIMETRIC
;
1612 else if(srcUnit
== UnitPixel
){
1613 dx
= ((REAL
) INCH_HIMETRIC
) /
1614 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
1615 dy
= ((REAL
) INCH_HIMETRIC
) /
1616 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
1619 return NotImplemented
;
1621 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
1622 transform_and_round_points(graphics
, pti
, ptf
, 3);
1624 /* IPicture renders bitmaps with the y-axis reversed
1625 * FIXME: flipping for unknown image type might not be correct. */
1626 if(image
->type
!= ImageTypeMetafile
){
1629 pti
[0].y
= pti
[2].y
;
1633 if(IPicture_Render(image
->picture
, graphics
->hdc
,
1634 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
1635 srcx
* dx
, srcy
* dy
,
1636 srcwidth
* dx
, srcheight
* dy
,
1639 callback(callbackData
);
1640 return GenericError
;
1646 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
1647 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
1648 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1649 DrawImageAbort callback
, VOID
* callbackData
)
1651 GpPointF pointsF
[3];
1654 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
1655 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1658 if(!points
|| count
!=3)
1659 return InvalidParameter
;
1661 for(i
= 0; i
< count
; i
++){
1662 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1663 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1666 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
1667 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
1668 callback
, callbackData
);
1671 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
1672 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
1673 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
1674 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
1675 VOID
* callbackData
)
1679 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
1680 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1681 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1685 points
[1].X
= dstx
+ dstwidth
;
1688 points
[2].Y
= dsty
+ dstheight
;
1690 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1691 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1694 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
1695 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
1696 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
1697 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
1698 VOID
* callbackData
)
1702 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
1703 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1704 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1708 points
[1].X
= dstx
+ dstwidth
;
1711 points
[2].Y
= dsty
+ dstheight
;
1713 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1714 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1717 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
1718 REAL x
, REAL y
, REAL width
, REAL height
)
1724 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
1726 if(!graphics
|| !image
)
1727 return InvalidParameter
;
1729 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
1733 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
1734 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
1735 unit
, NULL
, NULL
, NULL
);
1738 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
1739 INT x
, INT y
, INT width
, INT height
)
1741 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
1743 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
1746 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1747 REAL y1
, REAL x2
, REAL y2
)
1753 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1755 if(!pen
|| !graphics
)
1756 return InvalidParameter
;
1766 save_state
= prepare_dc(graphics
, pen
);
1768 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1770 restore_dc(graphics
, save_state
);
1775 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1776 INT y1
, INT x2
, INT y2
)
1782 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1784 if(!pen
|| !graphics
)
1785 return InvalidParameter
;
1795 save_state
= prepare_dc(graphics
, pen
);
1797 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1799 restore_dc(graphics
, save_state
);
1804 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1805 GpPointF
*points
, INT count
)
1810 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1812 if(!pen
|| !graphics
|| (count
< 2))
1813 return InvalidParameter
;
1818 save_state
= prepare_dc(graphics
, pen
);
1820 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
1822 restore_dc(graphics
, save_state
);
1827 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1828 GpPoint
*points
, INT count
)
1832 GpPointF
*ptf
= NULL
;
1835 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1837 if(!pen
|| !graphics
|| (count
< 2))
1838 return InvalidParameter
;
1843 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
1844 if(!ptf
) return OutOfMemory
;
1846 for(i
= 0; i
< count
; i
++){
1847 ptf
[i
].X
= (REAL
) points
[i
].X
;
1848 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
1851 save_state
= prepare_dc(graphics
, pen
);
1853 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
1855 restore_dc(graphics
, save_state
);
1861 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
1866 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
1868 if(!pen
|| !graphics
)
1869 return InvalidParameter
;
1874 save_state
= prepare_dc(graphics
, pen
);
1876 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
1877 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
1879 restore_dc(graphics
, save_state
);
1884 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1885 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1889 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1890 width
, height
, startAngle
, sweepAngle
);
1892 if(!graphics
|| !pen
)
1893 return InvalidParameter
;
1898 save_state
= prepare_dc(graphics
, pen
);
1899 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1901 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1903 restore_dc(graphics
, save_state
);
1908 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1909 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1911 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1912 width
, height
, startAngle
, sweepAngle
);
1914 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1917 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1918 REAL y
, REAL width
, REAL height
)
1924 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1926 if(!pen
|| !graphics
)
1927 return InvalidParameter
;
1934 ptf
[1].X
= x
+ width
;
1936 ptf
[2].X
= x
+ width
;
1937 ptf
[2].Y
= y
+ height
;
1939 ptf
[3].Y
= y
+ height
;
1941 save_state
= prepare_dc(graphics
, pen
);
1942 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1944 transform_and_round_points(graphics
, pti
, ptf
, 4);
1945 Polygon(graphics
->hdc
, pti
, 4);
1947 restore_dc(graphics
, save_state
);
1952 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1953 INT y
, INT width
, INT height
)
1955 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1957 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1960 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
1961 GDIPCONST GpRectF
* rects
, INT count
)
1967 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
1969 if(!graphics
|| !pen
|| !rects
|| count
< 1)
1970 return InvalidParameter
;
1975 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
1976 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
1984 for(i
= 0; i
< count
; i
++){
1985 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
1986 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
1987 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
1988 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
1991 save_state
= prepare_dc(graphics
, pen
);
1992 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1994 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
1996 for(i
= 0; i
< count
; i
++)
1997 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
1999 restore_dc(graphics
, save_state
);
2007 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
2008 GDIPCONST GpRect
* rects
, INT count
)
2014 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2016 if(!rects
|| count
<=0)
2017 return InvalidParameter
;
2019 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
2023 for(i
= 0;i
< count
;i
++){
2024 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2025 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2026 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2027 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2030 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
2036 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
2037 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
2038 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
2043 TEXTMETRICW textmet
;
2044 GpPointF pt
[2], rectcpy
[4];
2047 REAL angle
, ang_cos
, ang_sin
, rel_width
, rel_height
;
2048 INT sum
= 0, height
= 0, fit
, fitcpy
, save_state
, i
, j
, lret
, nwidth
,
2053 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
2054 length
, font
, debugstr_rectf(rect
), format
, brush
);
2056 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
2057 return InvalidParameter
;
2059 if((brush
->bt
!= BrushTypeSolidColor
)){
2060 FIXME("not implemented for given parameters\n");
2061 return NotImplemented
;
2065 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
2067 if(length
== -1) length
= lstrlenW(string
);
2069 stringdup
= GdipAlloc(length
* sizeof(WCHAR
));
2070 if(!stringdup
) return OutOfMemory
;
2072 save_state
= SaveDC(graphics
->hdc
);
2073 SetBkMode(graphics
->hdc
, TRANSPARENT
);
2074 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
2076 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
2077 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
2078 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
2079 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
2080 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
2082 if (roundr(rect
->Width
) == 0)
2089 rel_width
= sqrt((corners
[1].x
- corners
[0].x
) * (corners
[1].x
- corners
[0].x
) +
2090 (corners
[1].y
- corners
[0].y
) * (corners
[1].y
- corners
[0].y
))
2092 nwidth
= roundr(rel_width
* rect
->Width
);
2095 if (roundr(rect
->Height
) == 0)
2102 rel_height
= sqrt((corners
[2].x
- corners
[1].x
) * (corners
[2].x
- corners
[1].x
) +
2103 (corners
[2].y
- corners
[1].y
) * (corners
[2].y
- corners
[1].y
))
2105 nheight
= roundr(rel_height
* rect
->Height
);
2108 if (roundr(rect
->Width
) != 0 && roundr(rect
->Height
) != 0)
2110 /* FIXME: If only the width or only the height is 0, we should probably still clip */
2111 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
2112 SelectClipRgn(graphics
->hdc
, rgn
);
2115 /* Use gdi to find the font, then perform transformations on it (height,
2117 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2118 GetTextMetricsW(graphics
->hdc
, &textmet
);
2121 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
2122 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
2128 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
2129 angle
= gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2130 ang_cos
= cos(angle
);
2131 ang_sin
= sin(angle
);
2132 lfw
.lfEscapement
= lfw
.lfOrientation
= -roundr((angle
/ M_PI
) * 1800.0);
2134 gdifont
= CreateFontIndirectW(&lfw
);
2135 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
2137 for(i
= 0, j
= 0; i
< length
; i
++){
2138 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
2141 stringdup
[j
] = string
[i
];
2147 while(sum
< length
){
2148 drawcoord
.left
= corners
[0].x
+ roundr(ang_sin
* (REAL
) height
);
2149 drawcoord
.top
= corners
[0].y
+ roundr(ang_cos
* (REAL
) height
);
2151 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
2152 nwidth
, &fit
, NULL
, &size
);
2156 DrawTextW(graphics
->hdc
, stringdup
+ sum
, 1, &drawcoord
, DT_NOCLIP
|
2161 for(lret
= 0; lret
< fit
; lret
++)
2162 if(*(stringdup
+ sum
+ lret
) == '\n')
2165 /* Line break code (may look strange, but it imitates windows). */
2167 fit
= lret
; /* this is not an off-by-one error */
2168 else if(fit
< (length
- sum
)){
2169 if(*(stringdup
+ sum
+ fit
) == ' ')
2170 while(*(stringdup
+ sum
+ fit
) == ' ')
2173 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
2176 if(*(stringdup
+ sum
+ fit
) == '\t')
2185 DrawTextW(graphics
->hdc
, stringdup
+ sum
, min(length
- sum
, fit
),
2186 &drawcoord
, DT_NOCLIP
| DT_EXPANDTABS
);
2188 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
2191 if(height
> nheight
)
2194 /* Stop if this was a linewrap (but not if it was a linebreak). */
2195 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
2199 GdipFree(stringdup
);
2201 DeleteObject(gdifont
);
2203 RestoreDC(graphics
->hdc
, save_state
);
2208 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
2209 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
2214 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2215 count
, tension
, fill
);
2217 if(!graphics
|| !brush
|| !points
)
2218 return InvalidParameter
;
2223 stat
= GdipCreatePath(fill
, &path
);
2227 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2229 GdipDeletePath(path
);
2233 stat
= GdipFillPath(graphics
, brush
, path
);
2235 GdipDeletePath(path
);
2239 GdipDeletePath(path
);
2244 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
2245 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2251 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2252 count
, tension
, fill
);
2254 if(!points
|| count
<= 0)
2255 return InvalidParameter
;
2257 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2261 for(i
= 0;i
< count
;i
++){
2262 ptf
[i
].X
= (REAL
)points
[i
].X
;
2263 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2266 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2273 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2274 REAL y
, REAL width
, REAL height
)
2280 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2282 if(!graphics
|| !brush
)
2283 return InvalidParameter
;
2290 ptf
[1].X
= x
+ width
;
2291 ptf
[1].Y
= y
+ height
;
2293 save_state
= SaveDC(graphics
->hdc
);
2294 EndPath(graphics
->hdc
);
2295 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2296 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2298 transform_and_round_points(graphics
, pti
, ptf
, 2);
2300 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2302 RestoreDC(graphics
->hdc
, save_state
);
2307 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2308 INT y
, INT width
, INT height
)
2310 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2312 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2315 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2320 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2322 if(!brush
|| !graphics
|| !path
)
2323 return InvalidParameter
;
2328 save_state
= SaveDC(graphics
->hdc
);
2329 EndPath(graphics
->hdc
);
2330 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2333 BeginPath(graphics
->hdc
);
2334 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2335 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2340 EndPath(graphics
->hdc
);
2341 brush_fill_path(graphics
, brush
);
2346 RestoreDC(graphics
->hdc
, save_state
);
2351 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2352 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2356 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2357 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2359 if(!graphics
|| !brush
)
2360 return InvalidParameter
;
2365 save_state
= SaveDC(graphics
->hdc
);
2366 EndPath(graphics
->hdc
);
2367 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2368 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2370 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2372 RestoreDC(graphics
->hdc
, save_state
);
2377 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2378 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2380 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2381 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2383 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2386 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
2387 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
2390 GpPointF
*ptf
= NULL
;
2392 GpStatus retval
= Ok
;
2394 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2396 if(!graphics
|| !brush
|| !points
|| !count
)
2397 return InvalidParameter
;
2402 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2403 pti
= GdipAlloc(count
* sizeof(POINT
));
2405 retval
= OutOfMemory
;
2409 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
2411 save_state
= SaveDC(graphics
->hdc
);
2412 EndPath(graphics
->hdc
);
2413 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2414 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2415 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2418 transform_and_round_points(graphics
, pti
, ptf
, count
);
2419 Polygon(graphics
->hdc
, pti
, count
);
2421 RestoreDC(graphics
->hdc
, save_state
);
2430 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
2431 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
2434 GpPointF
*ptf
= NULL
;
2436 GpStatus retval
= Ok
;
2438 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2440 if(!graphics
|| !brush
|| !points
|| !count
)
2441 return InvalidParameter
;
2446 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2447 pti
= GdipAlloc(count
* sizeof(POINT
));
2449 retval
= OutOfMemory
;
2453 for(i
= 0; i
< count
; i
++){
2454 ptf
[i
].X
= (REAL
) points
[i
].X
;
2455 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2458 save_state
= SaveDC(graphics
->hdc
);
2459 EndPath(graphics
->hdc
);
2460 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2461 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2462 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2465 transform_and_round_points(graphics
, pti
, ptf
, count
);
2466 Polygon(graphics
->hdc
, pti
, count
);
2468 RestoreDC(graphics
->hdc
, save_state
);
2477 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
2478 GDIPCONST GpPointF
*points
, INT count
)
2480 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2482 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
2485 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
2486 GDIPCONST GpPoint
*points
, INT count
)
2488 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2490 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
2493 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
2494 REAL x
, REAL y
, REAL width
, REAL height
)
2500 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2502 if(!graphics
|| !brush
)
2503 return InvalidParameter
;
2510 ptf
[1].X
= x
+ width
;
2512 ptf
[2].X
= x
+ width
;
2513 ptf
[2].Y
= y
+ height
;
2515 ptf
[3].Y
= y
+ height
;
2517 save_state
= SaveDC(graphics
->hdc
);
2518 EndPath(graphics
->hdc
);
2520 transform_and_round_points(graphics
, pti
, ptf
, 4);
2522 BeginPath(graphics
->hdc
);
2523 Polygon(graphics
->hdc
, pti
, 4);
2524 EndPath(graphics
->hdc
);
2526 brush_fill_path(graphics
, brush
);
2528 RestoreDC(graphics
->hdc
, save_state
);
2533 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
2534 INT x
, INT y
, INT width
, INT height
)
2540 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2542 if(!graphics
|| !brush
)
2543 return InvalidParameter
;
2550 ptf
[1].X
= x
+ width
;
2552 ptf
[2].X
= x
+ width
;
2553 ptf
[2].Y
= y
+ height
;
2555 ptf
[3].Y
= y
+ height
;
2557 save_state
= SaveDC(graphics
->hdc
);
2558 EndPath(graphics
->hdc
);
2559 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2560 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2562 transform_and_round_points(graphics
, pti
, ptf
, 4);
2564 Polygon(graphics
->hdc
, pti
, 4);
2566 RestoreDC(graphics
->hdc
, save_state
);
2571 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
2577 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2580 return InvalidParameter
;
2582 for(i
= 0; i
< count
; i
++){
2583 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2584 if(ret
!= Ok
) return ret
;
2590 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
2597 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2599 if(!rects
|| count
<= 0)
2600 return InvalidParameter
;
2602 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
2606 for(i
= 0; i
< count
; i
++){
2607 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2608 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2609 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
2610 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2613 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
2619 /*****************************************************************************
2620 * GdipFillRegion [GDIPLUS.@]
2622 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
2629 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
2631 if (!(graphics
&& brush
&& region
))
2632 return InvalidParameter
;
2637 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
2641 save_state
= SaveDC(graphics
->hdc
);
2642 EndPath(graphics
->hdc
);
2643 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2645 FillRgn(graphics
->hdc
, hrgn
, brush
->gdibrush
);
2647 RestoreDC(graphics
->hdc
, save_state
);
2654 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
2659 return InvalidParameter
;
2665 FIXME("not implemented\n");
2667 return NotImplemented
;
2670 /*****************************************************************************
2671 * GdipGetClipBounds [GDIPLUS.@]
2673 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
2675 TRACE("(%p, %p)\n", graphics
, rect
);
2678 return InvalidParameter
;
2683 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
2686 /*****************************************************************************
2687 * GdipGetClipBoundsI [GDIPLUS.@]
2689 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
2691 TRACE("(%p, %p)\n", graphics
, rect
);
2694 return InvalidParameter
;
2699 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
2702 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
2703 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
2704 CompositingMode
*mode
)
2706 TRACE("(%p, %p)\n", graphics
, mode
);
2708 if(!graphics
|| !mode
)
2709 return InvalidParameter
;
2714 *mode
= graphics
->compmode
;
2719 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
2720 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
2721 CompositingQuality
*quality
)
2723 TRACE("(%p, %p)\n", graphics
, quality
);
2725 if(!graphics
|| !quality
)
2726 return InvalidParameter
;
2731 *quality
= graphics
->compqual
;
2736 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
2737 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
2738 InterpolationMode
*mode
)
2740 TRACE("(%p, %p)\n", graphics
, mode
);
2742 if(!graphics
|| !mode
)
2743 return InvalidParameter
;
2748 *mode
= graphics
->interpolation
;
2753 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
2755 if(!graphics
|| !argb
)
2756 return InvalidParameter
;
2761 FIXME("(%p, %p): stub\n", graphics
, argb
);
2763 return NotImplemented
;
2766 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
2768 TRACE("(%p, %p)\n", graphics
, scale
);
2770 if(!graphics
|| !scale
)
2771 return InvalidParameter
;
2776 *scale
= graphics
->scale
;
2781 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
2783 TRACE("(%p, %p)\n", graphics
, unit
);
2785 if(!graphics
|| !unit
)
2786 return InvalidParameter
;
2791 *unit
= graphics
->unit
;
2796 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
2797 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
2800 TRACE("(%p, %p)\n", graphics
, mode
);
2802 if(!graphics
|| !mode
)
2803 return InvalidParameter
;
2808 *mode
= graphics
->pixeloffset
;
2813 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
2814 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
2816 TRACE("(%p, %p)\n", graphics
, mode
);
2818 if(!graphics
|| !mode
)
2819 return InvalidParameter
;
2824 *mode
= graphics
->smoothing
;
2829 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
2831 TRACE("(%p, %p)\n", graphics
, contrast
);
2833 if(!graphics
|| !contrast
)
2834 return InvalidParameter
;
2836 *contrast
= graphics
->textcontrast
;
2841 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
2842 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
2843 TextRenderingHint
*hint
)
2845 TRACE("(%p, %p)\n", graphics
, hint
);
2847 if(!graphics
|| !hint
)
2848 return InvalidParameter
;
2853 *hint
= graphics
->texthint
;
2858 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2860 TRACE("(%p, %p)\n", graphics
, matrix
);
2862 if(!graphics
|| !matrix
)
2863 return InvalidParameter
;
2868 *matrix
= *graphics
->worldtrans
;
2872 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
2878 TRACE("(%p, %x)\n", graphics
, color
);
2881 return InvalidParameter
;
2886 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
2890 if(!GetWindowRect(graphics
->hwnd
, &rect
)){
2891 GdipDeleteBrush((GpBrush
*)brush
);
2892 return GenericError
;
2895 GdipFillRectangle(graphics
, (GpBrush
*)brush
, 0.0, 0.0, (REAL
)(rect
.right
- rect
.left
),
2896 (REAL
)(rect
.bottom
- rect
.top
));
2899 GdipFillRectangle(graphics
, (GpBrush
*)brush
, 0.0, 0.0, (REAL
)GetDeviceCaps(graphics
->hdc
, HORZRES
),
2900 (REAL
)GetDeviceCaps(graphics
->hdc
, VERTRES
));
2902 GdipDeleteBrush((GpBrush
*)brush
);
2907 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
2909 TRACE("(%p, %p)\n", graphics
, res
);
2911 if(!graphics
|| !res
)
2912 return InvalidParameter
;
2914 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
2917 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
2919 FIXME("(%p, %.2f, %.2f, %p) stub\n", graphics
, x
, y
, result
);
2921 if(!graphics
|| !result
)
2922 return InvalidParameter
;
2927 return NotImplemented
;
2930 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
2932 FIXME("(%p, %d, %d, %p) stub\n", graphics
, x
, y
, result
);
2934 if(!graphics
|| !result
)
2935 return InvalidParameter
;
2940 return NotImplemented
;
2943 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
2944 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
2945 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
2946 INT regionCount
, GpRegion
** regions
)
2948 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
2949 return InvalidParameter
;
2951 FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics
, debugstr_w(string
),
2952 length
, font
, layoutRect
, stringFormat
, regionCount
, regions
);
2954 return NotImplemented
;
2957 /* Find the smallest rectangle that bounds the text when it is printed in rect
2958 * according to the format options listed in format. If rect has 0 width and
2959 * height, then just find the smallest rectangle that bounds the text when it's
2960 * printed at location (rect->X, rect-Y). */
2961 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
2962 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
2963 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
2964 INT
*codepointsfitted
, INT
*linesfilled
)
2968 INT sum
= 0, height
= 0, fit
, fitcpy
, max_width
= 0, i
, j
, lret
, nwidth
,
2972 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
2973 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
2974 bounds
, codepointsfitted
, linesfilled
);
2976 if(!graphics
|| !string
|| !font
|| !rect
)
2977 return InvalidParameter
;
2979 if(linesfilled
) *linesfilled
= 0;
2980 if(codepointsfitted
) *codepointsfitted
= 0;
2983 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
2985 if(length
== -1) length
= lstrlenW(string
);
2987 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
2988 if(!stringdup
) return OutOfMemory
;
2990 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2991 nwidth
= roundr(rect
->Width
);
2992 nheight
= roundr(rect
->Height
);
2994 if((nwidth
== 0) && (nheight
== 0))
2995 nwidth
= nheight
= INT_MAX
;
2997 for(i
= 0, j
= 0; i
< length
; i
++){
2998 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
3001 stringdup
[j
] = string
[i
];
3008 while(sum
< length
){
3009 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
3010 nwidth
, &fit
, NULL
, &size
);
3016 for(lret
= 0; lret
< fit
; lret
++)
3017 if(*(stringdup
+ sum
+ lret
) == '\n')
3020 /* Line break code (may look strange, but it imitates windows). */
3022 fit
= lret
; /* this is not an off-by-one error */
3023 else if(fit
< (length
- sum
)){
3024 if(*(stringdup
+ sum
+ fit
) == ' ')
3025 while(*(stringdup
+ sum
+ fit
) == ' ')
3028 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
3031 if(*(stringdup
+ sum
+ fit
) == '\t')
3041 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, fit
,
3042 nwidth
, &j
, NULL
, &size
);
3044 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
3045 if(codepointsfitted
) *codepointsfitted
= sum
;
3048 if(linesfilled
) *linesfilled
+= size
.cy
;
3049 max_width
= max(max_width
, size
.cx
);
3051 if(height
> nheight
)
3054 /* Stop if this was a linewrap (but not if it was a linebreak). */
3055 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
3059 bounds
->X
= rect
->X
;
3060 bounds
->Y
= rect
->Y
;
3061 bounds
->Width
= (REAL
)max_width
;
3062 bounds
->Height
= (REAL
) min(height
, nheight
);
3064 GdipFree(stringdup
);
3065 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3070 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
3072 TRACE("(%p)\n", graphics
);
3075 return InvalidParameter
;
3080 return GdipSetInfinite(graphics
->clip
);
3083 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
3085 TRACE("(%p)\n", graphics
);
3088 return InvalidParameter
;
3093 graphics
->worldtrans
->matrix
[0] = 1.0;
3094 graphics
->worldtrans
->matrix
[1] = 0.0;
3095 graphics
->worldtrans
->matrix
[2] = 0.0;
3096 graphics
->worldtrans
->matrix
[3] = 1.0;
3097 graphics
->worldtrans
->matrix
[4] = 0.0;
3098 graphics
->worldtrans
->matrix
[5] = 0.0;
3103 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
3108 return InvalidParameter
;
3111 FIXME("graphics state not implemented\n");
3116 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
3117 GpMatrixOrder order
)
3119 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
3122 return InvalidParameter
;
3127 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
3130 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
3134 if(!graphics
|| !state
)
3135 return InvalidParameter
;
3138 FIXME("graphics state not implemented\n");
3140 *state
= 0xdeadbeef;
3144 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
, GraphicsContainer
*state
)
3146 FIXME("(%p, %p)\n", graphics
, state
);
3148 if(!graphics
|| !state
)
3149 return InvalidParameter
;
3151 *state
= 0xdeadbeef;
3155 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsState state
)
3157 FIXME("(%p, 0x%x)\n", graphics
, state
);
3159 if(!graphics
|| !state
)
3160 return InvalidParameter
;
3165 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
3166 REAL sy
, GpMatrixOrder order
)
3168 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
3171 return InvalidParameter
;
3176 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
3179 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
3182 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
3184 if(!graphics
|| !srcgraphics
)
3185 return InvalidParameter
;
3187 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
3190 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
3191 CompositingMode mode
)
3193 TRACE("(%p, %d)\n", graphics
, mode
);
3196 return InvalidParameter
;
3201 graphics
->compmode
= mode
;
3206 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
3207 CompositingQuality quality
)
3209 TRACE("(%p, %d)\n", graphics
, quality
);
3212 return InvalidParameter
;
3217 graphics
->compqual
= quality
;
3222 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
3223 InterpolationMode mode
)
3225 TRACE("(%p, %d)\n", graphics
, mode
);
3228 return InvalidParameter
;
3233 graphics
->interpolation
= mode
;
3238 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
3240 TRACE("(%p, %.2f)\n", graphics
, scale
);
3242 if(!graphics
|| (scale
<= 0.0))
3243 return InvalidParameter
;
3248 graphics
->scale
= scale
;
3253 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
3255 TRACE("(%p, %d)\n", graphics
, unit
);
3258 return InvalidParameter
;
3263 if(unit
== UnitWorld
)
3264 return InvalidParameter
;
3266 graphics
->unit
= unit
;
3271 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3274 TRACE("(%p, %d)\n", graphics
, mode
);
3277 return InvalidParameter
;
3282 graphics
->pixeloffset
= mode
;
3287 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
3291 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
3294 FIXME("not implemented\n");
3296 return NotImplemented
;
3299 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
3301 TRACE("(%p, %d)\n", graphics
, mode
);
3304 return InvalidParameter
;
3309 graphics
->smoothing
= mode
;
3314 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
3316 TRACE("(%p, %d)\n", graphics
, contrast
);
3319 return InvalidParameter
;
3321 graphics
->textcontrast
= contrast
;
3326 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
3327 TextRenderingHint hint
)
3329 TRACE("(%p, %d)\n", graphics
, hint
);
3332 return InvalidParameter
;
3337 graphics
->texthint
= hint
;
3342 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3344 TRACE("(%p, %p)\n", graphics
, matrix
);
3346 if(!graphics
|| !matrix
)
3347 return InvalidParameter
;
3352 GdipDeleteMatrix(graphics
->worldtrans
);
3353 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
3356 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
3357 REAL dy
, GpMatrixOrder order
)
3359 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
3362 return InvalidParameter
;
3367 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
3370 /*****************************************************************************
3371 * GdipSetClipHrgn [GDIPLUS.@]
3373 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
3378 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
3381 return InvalidParameter
;
3383 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
3387 status
= GdipSetClipRegion(graphics
, region
, mode
);
3389 GdipDeleteRegion(region
);
3393 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
3395 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
3398 return InvalidParameter
;
3403 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
3406 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
3407 REAL width
, REAL height
,
3412 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3415 return InvalidParameter
;
3423 rect
.Height
= height
;
3425 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
3428 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
3429 INT width
, INT height
,
3432 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3435 return InvalidParameter
;
3440 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
3443 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
3446 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
3448 if(!graphics
|| !region
)
3449 return InvalidParameter
;
3454 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
3457 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
3463 FIXME("not implemented\n");
3465 return NotImplemented
;
3468 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
3474 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
3476 if(!graphics
|| !pen
|| count
<=0)
3477 return InvalidParameter
;
3482 pti
= GdipAlloc(sizeof(POINT
) * count
);
3484 save_state
= prepare_dc(graphics
, pen
);
3485 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3487 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
3488 Polygon(graphics
->hdc
, pti
, count
);
3490 restore_dc(graphics
, save_state
);
3496 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
3503 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3505 if(count
<=0) return InvalidParameter
;
3506 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
3508 for(i
= 0;i
< count
; i
++){
3509 ptf
[i
].X
= (REAL
)points
[i
].X
;
3510 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3513 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
3519 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
3521 TRACE("(%p, %p)\n", graphics
, dpi
);
3523 if(!graphics
|| !dpi
)
3524 return InvalidParameter
;
3529 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
3534 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
3536 TRACE("(%p, %p)\n", graphics
, dpi
);
3538 if(!graphics
|| !dpi
)
3539 return InvalidParameter
;
3544 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
3549 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
3550 GpMatrixOrder order
)
3555 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
3557 if(!graphics
|| !matrix
)
3558 return InvalidParameter
;
3563 m
= *(graphics
->worldtrans
);
3565 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
3567 *(graphics
->worldtrans
) = m
;
3572 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
3574 TRACE("(%p, %p)\n", graphics
, hdc
);
3576 if(!graphics
|| !hdc
)
3577 return InvalidParameter
;
3582 *hdc
= graphics
->hdc
;
3583 graphics
->busy
= TRUE
;
3588 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
3590 TRACE("(%p, %p)\n", graphics
, hdc
);
3593 return InvalidParameter
;
3595 if(graphics
->hdc
!= hdc
|| !(graphics
->busy
))
3596 return InvalidParameter
;
3598 graphics
->busy
= FALSE
;
3603 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
3608 TRACE("(%p, %p)\n", graphics
, region
);
3610 if(!graphics
|| !region
)
3611 return InvalidParameter
;
3616 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
3619 /* free everything except root node and header */
3620 delete_element(®ion
->node
);
3621 memcpy(region
, clip
, sizeof(GpRegion
));
3626 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3627 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
3633 if(!graphics
|| !points
|| count
<= 0)
3634 return InvalidParameter
;
3639 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
3641 if (src_space
== dst_space
) return Ok
;
3643 stat
= GdipCreateMatrix(&matrix
);
3646 unitscale
= convert_unit(graphics
->hdc
, graphics
->unit
);
3648 if(graphics
->unit
!= UnitDisplay
)
3649 unitscale
*= graphics
->scale
;
3651 /* transform from src_space to CoordinateSpacePage */
3654 case CoordinateSpaceWorld
:
3655 GdipMultiplyMatrix(matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
3657 case CoordinateSpacePage
:
3659 case CoordinateSpaceDevice
:
3660 GdipScaleMatrix(matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
3664 /* transform from CoordinateSpacePage to dst_space */
3667 case CoordinateSpaceWorld
:
3669 GpMatrix
*inverted_transform
;
3670 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
3673 stat
= GdipInvertMatrix(inverted_transform
);
3675 GdipMultiplyMatrix(matrix
, inverted_transform
, MatrixOrderAppend
);
3676 GdipDeleteMatrix(inverted_transform
);
3680 case CoordinateSpacePage
:
3682 case CoordinateSpaceDevice
:
3683 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
3688 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
3690 GdipDeleteMatrix(matrix
);
3696 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3697 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
3703 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
3706 return InvalidParameter
;
3708 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
3712 for(i
= 0; i
< count
; i
++){
3713 pointsF
[i
].X
= (REAL
)points
[i
].X
;
3714 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
3717 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
3720 for(i
= 0; i
< count
; i
++){
3721 points
[i
].X
= roundr(pointsF
[i
].X
);
3722 points
[i
].Y
= roundr(pointsF
[i
].Y
);
3729 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
3736 /*****************************************************************************
3737 * GdipTranslateClip [GDIPLUS.@]
3739 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
3741 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
3744 return InvalidParameter
;
3749 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
3752 /*****************************************************************************
3753 * GdipTranslateClipI [GDIPLUS.@]
3755 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
3757 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
3760 return InvalidParameter
;
3765 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);