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
31 #include "gdiplus_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
36 typedef struct path_list_node_t path_list_node_t
;
37 struct path_list_node_t
{
39 BYTE type
; /* PathPointTypeStart or PathPointTypeLine */
40 path_list_node_t
*next
;
44 static BOOL
init_path_list(path_list_node_t
**node
, REAL x
, REAL y
)
46 *node
= heap_alloc_zero(sizeof(path_list_node_t
));
52 (*node
)->type
= PathPointTypeStart
;
58 /* free all nodes including argument */
59 static void free_path_list(path_list_node_t
*node
)
61 path_list_node_t
*n
= node
;
70 /* Add a node after 'node' */
74 * NULL on allocation problems
76 static path_list_node_t
* add_path_list_node(path_list_node_t
*node
, REAL x
, REAL y
, BOOL type
)
78 path_list_node_t
*new;
80 new = heap_alloc_zero(sizeof(path_list_node_t
));
87 new->next
= node
->next
;
93 /* returns element count */
94 static INT
path_list_count(path_list_node_t
*node
)
98 while((node
= node
->next
))
104 /* GdipFlattenPath helper */
106 * Used to recursively flatten single Bezier curve
108 * - start : pointer to start point node;
109 * - (x2, y2): first control point;
110 * - (x3, y3): second control point;
111 * - end : pointer to end point node
112 * - flatness: admissible error of linear approximation.
116 * FALSE: out of memory
118 * TODO: used quality criteria should be revised to match native as
119 * closer as possible.
121 static BOOL
flatten_bezier(path_list_node_t
*start
, REAL x2
, REAL y2
, REAL x3
, REAL y3
,
122 path_list_node_t
*end
, REAL flatness
)
124 /* this 5 middle points with start/end define to half-curves */
127 path_list_node_t
*node
;
129 /* calculate bezier curve middle points == new control points */
130 mp
[0].X
= (start
->pt
.X
+ x2
) / 2.0;
131 mp
[0].Y
= (start
->pt
.Y
+ y2
) / 2.0;
132 /* middle point between control points */
133 pt
.X
= (x2
+ x3
) / 2.0;
134 pt
.Y
= (y2
+ y3
) / 2.0;
135 mp
[1].X
= (mp
[0].X
+ pt
.X
) / 2.0;
136 mp
[1].Y
= (mp
[0].Y
+ pt
.Y
) / 2.0;
137 mp
[4].X
= (end
->pt
.X
+ x3
) / 2.0;
138 mp
[4].Y
= (end
->pt
.Y
+ y3
) / 2.0;
139 mp
[3].X
= (mp
[4].X
+ pt
.X
) / 2.0;
140 mp
[3].Y
= (mp
[4].Y
+ pt
.Y
) / 2.0;
142 mp
[2].X
= (mp
[1].X
+ mp
[3].X
) / 2.0;
143 mp
[2].Y
= (mp
[1].Y
+ mp
[3].Y
) / 2.0;
145 if ((x2
== mp
[0].X
&& y2
== mp
[0].Y
&& x3
== mp
[1].X
&& y3
== mp
[1].Y
) ||
146 (x2
== mp
[3].X
&& y2
== mp
[3].Y
&& x3
== mp
[4].X
&& y3
== mp
[4].Y
))
151 /* check flatness as a half of distance between middle point and a linearized path */
152 if(fabs(((pt
.Y
- pt_st
.Y
)*mp
[2].X
+ (pt_st
.X
- pt
.X
)*mp
[2].Y
+
153 (pt_st
.Y
*pt
.X
- pt_st
.X
*pt
.Y
))) <=
154 (0.5 * flatness
*sqrtf((powf(pt
.Y
- pt_st
.Y
, 2.0) + powf(pt_st
.X
- pt
.X
, 2.0))))){
158 /* add a middle point */
159 if(!(node
= add_path_list_node(start
, mp
[2].X
, mp
[2].Y
, PathPointTypeLine
)))
162 /* do the same with halves */
163 flatten_bezier(start
, mp
[0].X
, mp
[0].Y
, mp
[1].X
, mp
[1].Y
, node
, flatness
);
164 flatten_bezier(node
, mp
[3].X
, mp
[3].Y
, mp
[4].X
, mp
[4].Y
, end
, flatness
);
169 /*******************************************************************************
170 * GdipAddPathArc [GDIPLUS.1]
172 * Add an elliptical arc to the given path.
175 * path [I/O] Path that the arc is appended to
176 * x1 [I] X coordinate of the boundary box
177 * y1 [I] Y coordinate of the boundary box
178 * x2 [I] Width of the boundary box
179 * y2 [I] Height of the boundary box
180 * startAngle [I] Starting angle of the arc, clockwise
181 * sweepAngle [I] Angle of the arc, clockwise
184 * InvalidParameter If the given path is invalid
185 * OutOfMemory If memory allocation fails, i.e. the path cannot be lengthened
186 * Ok If everything works out as expected
189 * This functions takes the newfigure value of the given path into account,
190 * i.e. the arc is connected to the end of the given path if it was set to
191 * FALSE, otherwise the arc's first point gets the PathPointTypeStart value.
192 * In both cases, the value of newfigure of the given path is FALSE
195 GpStatus WINGDIPAPI
GdipAddPathArc(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
196 REAL y2
, REAL startAngle
, REAL sweepAngle
)
198 INT count
, old_count
, i
;
200 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
201 path
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
204 return InvalidParameter
;
206 count
= arc2polybezier(NULL
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
210 if(!lengthen_path(path
, count
))
213 old_count
= path
->pathdata
.Count
;
214 arc2polybezier(&path
->pathdata
.Points
[old_count
], x1
, y1
, x2
, y2
,
215 startAngle
, sweepAngle
);
217 for(i
= 0; i
< count
; i
++){
218 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeBezier
;
221 path
->pathdata
.Types
[old_count
] =
222 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
223 path
->newfigure
= FALSE
;
224 path
->pathdata
.Count
+= count
;
229 /*******************************************************************************
230 * GdipAddPathArcI [GDUPLUS.2]
234 GpStatus WINGDIPAPI
GdipAddPathArcI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
235 INT y2
, REAL startAngle
, REAL sweepAngle
)
237 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
238 path
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
240 return GdipAddPathArc(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,startAngle
,sweepAngle
);
243 GpStatus WINGDIPAPI
GdipAddPathBezier(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
244 REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
248 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
249 path
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
252 return InvalidParameter
;
254 if(!lengthen_path(path
, 4))
257 old_count
= path
->pathdata
.Count
;
259 path
->pathdata
.Points
[old_count
].X
= x1
;
260 path
->pathdata
.Points
[old_count
].Y
= y1
;
261 path
->pathdata
.Points
[old_count
+ 1].X
= x2
;
262 path
->pathdata
.Points
[old_count
+ 1].Y
= y2
;
263 path
->pathdata
.Points
[old_count
+ 2].X
= x3
;
264 path
->pathdata
.Points
[old_count
+ 2].Y
= y3
;
265 path
->pathdata
.Points
[old_count
+ 3].X
= x4
;
266 path
->pathdata
.Points
[old_count
+ 3].Y
= y4
;
268 path
->pathdata
.Types
[old_count
] =
269 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
270 path
->pathdata
.Types
[old_count
+ 1] = PathPointTypeBezier
;
271 path
->pathdata
.Types
[old_count
+ 2] = PathPointTypeBezier
;
272 path
->pathdata
.Types
[old_count
+ 3] = PathPointTypeBezier
;
274 path
->newfigure
= FALSE
;
275 path
->pathdata
.Count
+= 4;
280 GpStatus WINGDIPAPI
GdipAddPathBezierI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
281 INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
283 TRACE("(%p, %d, %d, %d, %d, %d, %d, %d, %d)\n",
284 path
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
286 return GdipAddPathBezier(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,(REAL
)x3
,(REAL
)y3
,
290 GpStatus WINGDIPAPI
GdipAddPathBeziers(GpPath
*path
, GDIPCONST GpPointF
*points
,
295 TRACE("(%p, %p, %d)\n", path
, points
, count
);
297 if(!path
|| !points
|| ((count
- 1) % 3))
298 return InvalidParameter
;
300 if(!lengthen_path(path
, count
))
303 old_count
= path
->pathdata
.Count
;
305 for(i
= 0; i
< count
; i
++){
306 path
->pathdata
.Points
[old_count
+ i
].X
= points
[i
].X
;
307 path
->pathdata
.Points
[old_count
+ i
].Y
= points
[i
].Y
;
308 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeBezier
;
311 path
->pathdata
.Types
[old_count
] =
312 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
313 path
->newfigure
= FALSE
;
314 path
->pathdata
.Count
+= count
;
319 GpStatus WINGDIPAPI
GdipAddPathBeziersI(GpPath
*path
, GDIPCONST GpPoint
*points
,
326 TRACE("(%p, %p, %d)\n", path
, points
, count
);
328 if(!points
|| ((count
- 1) % 3))
329 return InvalidParameter
;
331 ptsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
335 for(i
= 0; i
< count
; i
++){
336 ptsF
[i
].X
= (REAL
)points
[i
].X
;
337 ptsF
[i
].Y
= (REAL
)points
[i
].Y
;
340 ret
= GdipAddPathBeziers(path
, ptsF
, count
);
346 GpStatus WINGDIPAPI
GdipAddPathClosedCurve(GpPath
*path
, GDIPCONST GpPointF
*points
,
349 TRACE("(%p, %p, %d)\n", path
, points
, count
);
351 return GdipAddPathClosedCurve2(path
, points
, count
, 1.0);
354 GpStatus WINGDIPAPI
GdipAddPathClosedCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
,
357 TRACE("(%p, %p, %d)\n", path
, points
, count
);
359 return GdipAddPathClosedCurve2I(path
, points
, count
, 1.0);
362 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
,
363 INT count
, REAL tension
)
365 INT i
, len_pt
= (count
+ 1)*3-2;
371 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
373 if(!path
|| !points
|| count
<= 1)
374 return InvalidParameter
;
376 pt
= heap_alloc_zero(len_pt
* sizeof(GpPointF
));
377 pts
= heap_alloc_zero((count
+ 1)*sizeof(GpPointF
));
384 /* copy source points to extend with the last one */
385 memcpy(pts
, points
, sizeof(GpPointF
)*count
);
388 tension
= tension
* TENSION_CONST
;
390 for(i
= 0; i
< count
-1; i
++){
391 calc_curve_bezier(&(pts
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
395 pt
[3*i
+3].X
= pts
[i
+1].X
;
396 pt
[3*i
+3].Y
= pts
[i
+1].Y
;
401 /* points [len_pt-2] and [0] are calculated
402 separately to connect splines properly */
403 pts
[0] = points
[count
-1];
404 pts
[1] = points
[0]; /* equals to start and end of a resulting path */
407 calc_curve_bezier(pts
, tension
, &x1
, &y1
, &x2
, &y2
);
415 pt
[len_pt
-1].X
= pt
[0].X
;
416 pt
[len_pt
-1].Y
= pt
[0].Y
;
418 stat
= GdipAddPathBeziers(path
, pt
, len_pt
);
422 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
423 path
->newfigure
= TRUE
;
432 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
433 INT count
, REAL tension
)
439 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
441 if(!path
|| !points
|| count
<= 1)
442 return InvalidParameter
;
444 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
448 for(i
= 0; i
< count
; i
++){
449 ptf
[i
].X
= (REAL
)points
[i
].X
;
450 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
453 stat
= GdipAddPathClosedCurve2(path
, ptf
, count
, tension
);
460 GpStatus WINGDIPAPI
GdipAddPathCurve(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
462 TRACE("(%p, %p, %d)\n", path
, points
, count
);
464 if(!path
|| !points
|| count
<= 1)
465 return InvalidParameter
;
467 return GdipAddPathCurve2(path
, points
, count
, 1.0);
470 GpStatus WINGDIPAPI
GdipAddPathCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
472 TRACE("(%p, %p, %d)\n", path
, points
, count
);
474 if(!path
|| !points
|| count
<= 1)
475 return InvalidParameter
;
477 return GdipAddPathCurve2I(path
, points
, count
, 1.0);
480 GpStatus WINGDIPAPI
GdipAddPathCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
,
483 INT i
, len_pt
= count
*3-2;
488 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
490 if(!path
|| !points
|| count
<= 1)
491 return InvalidParameter
;
493 pt
= heap_alloc_zero(len_pt
* sizeof(GpPointF
));
497 tension
= tension
* TENSION_CONST
;
499 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
502 pt
[0].X
= points
[0].X
;
503 pt
[0].Y
= points
[0].Y
;
507 for(i
= 0; i
< count
-2; i
++){
508 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
512 pt
[3*i
+3].X
= points
[i
+1].X
;
513 pt
[3*i
+3].Y
= points
[i
+1].Y
;
518 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
519 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
523 pt
[len_pt
-1].X
= points
[count
-1].X
;
524 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
526 stat
= GdipAddPathBeziers(path
, pt
, len_pt
);
533 GpStatus WINGDIPAPI
GdipAddPathCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
534 INT count
, REAL tension
)
540 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
542 if(!path
|| !points
|| count
<= 1)
543 return InvalidParameter
;
545 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
549 for(i
= 0; i
< count
; i
++){
550 ptf
[i
].X
= (REAL
)points
[i
].X
;
551 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
554 stat
= GdipAddPathCurve2(path
, ptf
, count
, tension
);
561 GpStatus WINGDIPAPI
GdipAddPathCurve3(GpPath
*path
, GDIPCONST GpPointF
*points
,
562 INT count
, INT offset
, INT nseg
, REAL tension
)
564 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path
, points
, count
, offset
, nseg
, tension
);
566 if(!path
|| !points
|| offset
+ 1 >= count
|| count
- offset
< nseg
+ 1)
567 return InvalidParameter
;
569 return GdipAddPathCurve2(path
, &points
[offset
], nseg
+ 1, tension
);
572 GpStatus WINGDIPAPI
GdipAddPathCurve3I(GpPath
*path
, GDIPCONST GpPoint
*points
,
573 INT count
, INT offset
, INT nseg
, REAL tension
)
575 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path
, points
, count
, offset
, nseg
, tension
);
577 if(!path
|| !points
|| offset
+ 1 >= count
|| count
- offset
< nseg
+ 1)
578 return InvalidParameter
;
580 return GdipAddPathCurve2I(path
, &points
[offset
], nseg
+ 1, tension
);
583 GpStatus WINGDIPAPI
GdipAddPathEllipse(GpPath
*path
, REAL x
, REAL y
, REAL width
,
586 INT old_count
, numpts
;
588 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
591 return InvalidParameter
;
593 if(!lengthen_path(path
, MAX_ARC_PTS
))
596 old_count
= path
->pathdata
.Count
;
597 if((numpts
= arc2polybezier(&path
->pathdata
.Points
[old_count
], x
, y
, width
,
598 height
, 0.0, 360.0)) != MAX_ARC_PTS
){
599 ERR("expected %d points but got %d\n", MAX_ARC_PTS
, numpts
);
603 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeBezier
,
606 /* An ellipse is an intrinsic figure (always is its own subpath). */
607 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
608 path
->pathdata
.Types
[old_count
+ MAX_ARC_PTS
- 1] |= PathPointTypeCloseSubpath
;
609 path
->newfigure
= TRUE
;
610 path
->pathdata
.Count
+= MAX_ARC_PTS
;
615 GpStatus WINGDIPAPI
GdipAddPathEllipseI(GpPath
*path
, INT x
, INT y
, INT width
,
618 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
620 return GdipAddPathEllipse(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
623 GpStatus WINGDIPAPI
GdipAddPathLine2(GpPath
*path
, GDIPCONST GpPointF
*points
,
628 TRACE("(%p, %p, %d)\n", path
, points
, count
);
631 return InvalidParameter
;
633 if(!lengthen_path(path
, count
))
636 old_count
= path
->pathdata
.Count
;
638 for(i
= 0; i
< count
; i
++){
639 path
->pathdata
.Points
[old_count
+ i
].X
= points
[i
].X
;
640 path
->pathdata
.Points
[old_count
+ i
].Y
= points
[i
].Y
;
641 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeLine
;
645 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
646 path
->newfigure
= FALSE
;
649 path
->pathdata
.Count
+= count
;
654 GpStatus WINGDIPAPI
GdipAddPathLine2I(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
660 TRACE("(%p, %p, %d)\n", path
, points
, count
);
663 return InvalidParameter
;
665 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
666 if(!pointsF
) return OutOfMemory
;
668 for(i
= 0;i
< count
; i
++){
669 pointsF
[i
].X
= (REAL
)points
[i
].X
;
670 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
673 stat
= GdipAddPathLine2(path
, pointsF
, count
);
680 /*************************************************************************
681 * GdipAddPathLine [GDIPLUS.21]
683 * Add two points to the given path.
686 * path [I/O] Path that the line is appended to
687 * x1 [I] X coordinate of the first point of the line
688 * y1 [I] Y coordinate of the first point of the line
689 * x2 [I] X coordinate of the second point of the line
690 * y2 [I] Y coordinate of the second point of the line
693 * InvalidParameter If the first parameter is not a valid path
694 * OutOfMemory If the path cannot be lengthened, i.e. memory allocation fails
695 * Ok If everything works out as expected
698 * This functions takes the newfigure value of the given path into account,
699 * i.e. the two new points are connected to the end of the given path if it
700 * was set to FALSE, otherwise the first point is given the PathPointTypeStart
701 * value. In both cases, the value of newfigure of the given path is FALSE
704 GpStatus WINGDIPAPI
GdipAddPathLine(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
708 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x1
, y1
, x2
, y2
);
711 return InvalidParameter
;
713 if(!lengthen_path(path
, 2))
716 old_count
= path
->pathdata
.Count
;
718 path
->pathdata
.Points
[old_count
].X
= x1
;
719 path
->pathdata
.Points
[old_count
].Y
= y1
;
720 path
->pathdata
.Points
[old_count
+ 1].X
= x2
;
721 path
->pathdata
.Points
[old_count
+ 1].Y
= y2
;
723 path
->pathdata
.Types
[old_count
] =
724 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
725 path
->pathdata
.Types
[old_count
+ 1] = PathPointTypeLine
;
727 path
->newfigure
= FALSE
;
728 path
->pathdata
.Count
+= 2;
733 /*************************************************************************
734 * GdipAddPathLineI [GDIPLUS.21]
736 * See GdipAddPathLine
738 GpStatus WINGDIPAPI
GdipAddPathLineI(GpPath
*path
, INT x1
, INT y1
, INT x2
, INT y2
)
740 TRACE("(%p, %d, %d, %d, %d)\n", path
, x1
, y1
, x2
, y2
);
742 return GdipAddPathLine(path
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
745 GpStatus WINGDIPAPI
GdipAddPathPath(GpPath
*path
, GDIPCONST GpPath
* addingPath
,
748 INT old_count
, count
;
750 TRACE("(%p, %p, %d)\n", path
, addingPath
, connect
);
752 if(!path
|| !addingPath
)
753 return InvalidParameter
;
755 old_count
= path
->pathdata
.Count
;
756 count
= addingPath
->pathdata
.Count
;
758 if(!lengthen_path(path
, count
))
761 memcpy(&path
->pathdata
.Points
[old_count
], addingPath
->pathdata
.Points
,
762 count
* sizeof(GpPointF
));
763 memcpy(&path
->pathdata
.Types
[old_count
], addingPath
->pathdata
.Types
, count
);
765 if(path
->newfigure
|| !connect
)
766 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
768 path
->pathdata
.Types
[old_count
] = PathPointTypeLine
;
770 path
->newfigure
= FALSE
;
771 path
->pathdata
.Count
+= count
;
776 GpStatus WINGDIPAPI
GdipAddPathPie(GpPath
*path
, REAL x
, REAL y
, REAL width
, REAL height
,
777 REAL startAngle
, REAL sweepAngle
)
783 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
784 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
787 return InvalidParameter
;
789 /* on zero width/height only start point added */
790 if(width
<= 1e-7 || height
<= 1e-7){
791 if(!lengthen_path(path
, 1))
793 path
->pathdata
.Points
[0].X
= x
+ width
/ 2.0;
794 path
->pathdata
.Points
[0].Y
= y
+ height
/ 2.0;
795 path
->pathdata
.Types
[0] = PathPointTypeStart
| PathPointTypeCloseSubpath
;
796 path
->pathdata
.Count
= 1;
797 return InvalidParameter
;
800 count
= arc2polybezier(NULL
, x
, y
, width
, height
, startAngle
, sweepAngle
);
805 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
809 arc2polybezier(ptf
, x
, y
, width
, height
, startAngle
, sweepAngle
);
811 status
= GdipAddPathLine(path
, x
+ width
/2, y
+ height
/2, ptf
[0].X
, ptf
[0].Y
);
816 /* one spline is already added as a line endpoint */
817 if(!lengthen_path(path
, count
- 1)){
822 memcpy(&(path
->pathdata
.Points
[path
->pathdata
.Count
]), &(ptf
[1]),sizeof(GpPointF
)*(count
-1));
823 for(i
= 0; i
< count
-1; i
++)
824 path
->pathdata
.Types
[path
->pathdata
.Count
+i
] = PathPointTypeBezier
;
826 path
->pathdata
.Count
+= count
-1;
828 GdipClosePathFigure(path
);
835 GpStatus WINGDIPAPI
GdipAddPathPieI(GpPath
*path
, INT x
, INT y
, INT width
, INT height
,
836 REAL startAngle
, REAL sweepAngle
)
838 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
839 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
841 return GdipAddPathPie(path
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, startAngle
, sweepAngle
);
844 GpStatus WINGDIPAPI
GdipAddPathPolygon(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
848 TRACE("(%p, %p, %d)\n", path
, points
, count
);
850 if(!path
|| !points
|| count
< 3)
851 return InvalidParameter
;
853 if(!lengthen_path(path
, count
))
856 old_count
= path
->pathdata
.Count
;
858 memcpy(&path
->pathdata
.Points
[old_count
], points
, count
*sizeof(GpPointF
));
859 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeLine
, count
- 1);
861 /* A polygon is an intrinsic figure */
862 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
863 path
->pathdata
.Types
[old_count
+ count
- 1] |= PathPointTypeCloseSubpath
;
864 path
->newfigure
= TRUE
;
865 path
->pathdata
.Count
+= count
;
870 GpStatus WINGDIPAPI
GdipAddPathPolygonI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
876 TRACE("(%p, %p, %d)\n", path
, points
, count
);
878 if(!points
|| count
< 3)
879 return InvalidParameter
;
881 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
885 for(i
= 0; i
< count
; i
++){
886 ptf
[i
].X
= (REAL
)points
[i
].X
;
887 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
890 status
= GdipAddPathPolygon(path
, ptf
, count
);
897 static float fromfixedpoint(const FIXED v
)
899 float f
= ((float)v
.fract
) / (1<<(sizeof(v
.fract
)*8));
904 struct format_string_args
912 static GpStatus
format_string_callback(HDC dc
,
913 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
914 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
915 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
916 INT underlined_index_count
, void *priv
)
918 static const MAT2 identity
= { {0,1}, {0,0}, {0,0}, {0,1} };
919 struct format_string_args
*args
= priv
;
920 GpPath
*path
= args
->path
;
921 GpStatus status
= Ok
;
922 float x
= rect
->X
+ (bounds
->X
- rect
->X
) * args
->scale
;
923 float y
= rect
->Y
+ (bounds
->Y
- rect
->Y
) * args
->scale
;
926 if (underlined_index_count
)
927 FIXME("hotkey underlines not drawn yet\n");
929 if (y
+ bounds
->Height
* args
->scale
> args
->maxY
)
930 args
->maxY
= y
+ bounds
->Height
* args
->scale
;
932 for (i
= index
; i
< length
; ++i
)
935 TTPOLYGONHEADER
*ph
= NULL
, *origph
;
938 len
= GetGlyphOutlineW(dc
, string
[i
], GGO_BEZIER
, &gm
, 0, NULL
, &identity
);
939 if (len
== GDI_ERROR
)
941 status
= GenericError
;
944 origph
= ph
= heap_alloc_zero(len
);
946 if (!ph
|| !lengthen_path(path
, len
/ sizeof(POINTFX
)))
949 status
= OutOfMemory
;
952 GetGlyphOutlineW(dc
, string
[i
], GGO_BEZIER
, &gm
, len
, start
, &identity
);
957 DWORD ofs_start
= ofs
;
958 ph
= (TTPOLYGONHEADER
*)&start
[ofs
];
959 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeStart
;
960 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(ph
->pfxStart
.x
) * args
->scale
;
961 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(ph
->pfxStart
.y
) * args
->scale
;
962 TRACE("Starting at count %i with pos %f, %f)\n", path
->pathdata
.Count
, x
, y
);
964 while (ofs
- ofs_start
< ph
->cb
)
966 TTPOLYCURVE
*curve
= (TTPOLYCURVE
*)&start
[ofs
];
968 ofs
+= sizeof(TTPOLYCURVE
) + (curve
->cpfx
- 1) * sizeof(POINTFX
);
970 switch (curve
->wType
)
973 for (j
= 0; j
< curve
->cpfx
; ++j
)
975 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeLine
;
976 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(curve
->apfx
[j
].x
) * args
->scale
;
977 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(curve
->apfx
[j
].y
) * args
->scale
;
980 case TT_PRIM_CSPLINE
:
981 for (j
= 0; j
< curve
->cpfx
; ++j
)
983 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeBezier
;
984 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(curve
->apfx
[j
].x
) * args
->scale
;
985 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(curve
->apfx
[j
].y
) * args
->scale
;
989 ERR("Unhandled type: %u\n", curve
->wType
);
990 status
= GenericError
;
993 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
995 path
->newfigure
= TRUE
;
996 x
+= gm
.gmCellIncX
* args
->scale
;
997 y
+= gm
.gmCellIncY
* args
->scale
;
1007 GpStatus WINGDIPAPI
GdipAddPathString(GpPath
* path
, GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFontFamily
* family
, INT style
, REAL emSize
, GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
* format
)
1014 GpGraphics
*graphics
;
1016 struct format_string_args args
;
1018 UINT16 native_height
;
1019 RectF scaled_layout_rect
;
1020 TEXTMETRICW textmetric
;
1022 TRACE("(%p, %s, %d, %p, %d, %f, %p, %p)\n", path
, debugstr_w(string
), length
, family
, style
, emSize
, layoutRect
, format
);
1023 if (!path
|| !string
|| !family
|| !emSize
|| !layoutRect
|| !format
)
1024 return InvalidParameter
;
1026 status
= GdipGetEmHeight(family
, style
, &native_height
);
1030 scaled_layout_rect
.X
= layoutRect
->X
;
1031 scaled_layout_rect
.Y
= layoutRect
->Y
;
1032 scaled_layout_rect
.Width
= layoutRect
->Width
* native_height
/ emSize
;
1033 scaled_layout_rect
.Height
= layoutRect
->Height
* native_height
/ emSize
;
1035 if ((status
= GdipClonePath(path
, &backup
)) != Ok
)
1038 dc
= CreateCompatibleDC(0);
1039 status
= GdipCreateFromHDC(dc
, &graphics
);
1043 GdipDeletePath(backup
);
1047 status
= GdipCreateFont(family
, native_height
, style
, UnitPixel
, &font
);
1050 GdipDeleteGraphics(graphics
);
1052 GdipDeletePath(backup
);
1056 get_log_fontW(font
, graphics
, &lfw
);
1057 GdipDeleteFont(font
);
1058 GdipDeleteGraphics(graphics
);
1060 hfont
= CreateFontIndirectW(&lfw
);
1063 WARN("Failed to create font\n");
1065 GdipDeletePath(backup
);
1066 return GenericError
;
1069 SelectObject(dc
, hfont
);
1071 GetTextMetricsW(dc
, &textmetric
);
1075 args
.scale
= emSize
/ native_height
;
1076 args
.ascent
= textmetric
.tmAscent
* args
.scale
;
1077 status
= gdip_format_string(dc
, string
, length
, NULL
, &scaled_layout_rect
,
1078 format
, TRUE
, format_string_callback
, &args
);
1081 DeleteObject(hfont
);
1083 if (status
!= Ok
) /* free backup */
1085 heap_free(path
->pathdata
.Points
);
1086 heap_free(path
->pathdata
.Types
);
1091 if (format
&& format
->line_align
== StringAlignmentCenter
&& layoutRect
->Y
+ args
.maxY
< layoutRect
->Height
)
1093 float inc
= layoutRect
->Height
+ layoutRect
->Y
- args
.maxY
;
1095 for (i
= backup
->pathdata
.Count
; i
< path
->pathdata
.Count
; ++i
)
1096 path
->pathdata
.Points
[i
].Y
+= inc
;
1097 } else if (format
&& format
->line_align
== StringAlignmentFar
) {
1098 float inc
= layoutRect
->Height
+ layoutRect
->Y
- args
.maxY
;
1099 for (i
= backup
->pathdata
.Count
; i
< path
->pathdata
.Count
; ++i
)
1100 path
->pathdata
.Points
[i
].Y
+= inc
;
1102 GdipDeletePath(backup
);
1106 GpStatus WINGDIPAPI
GdipAddPathStringI(GpPath
* path
, GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFontFamily
* family
, INT style
, REAL emSize
, GDIPCONST Rect
* layoutRect
, GDIPCONST GpStringFormat
* format
)
1110 RectF layoutRectF
= {
1111 (REAL
)layoutRect
->X
,
1112 (REAL
)layoutRect
->Y
,
1113 (REAL
)layoutRect
->Width
,
1114 (REAL
)layoutRect
->Height
1116 return GdipAddPathString(path
, string
, length
, family
, style
, emSize
, &layoutRectF
, format
);
1118 return InvalidParameter
;
1121 /*************************************************************************
1122 * GdipClonePath [GDIPLUS.53]
1124 * Duplicate the given path in memory.
1127 * path [I] The path to be duplicated
1128 * clone [O] Pointer to the new path
1131 * InvalidParameter If the input path is invalid
1132 * OutOfMemory If allocation of needed memory fails
1133 * Ok If everything works out as expected
1135 GpStatus WINGDIPAPI
GdipClonePath(GpPath
* path
, GpPath
**clone
)
1137 TRACE("(%p, %p)\n", path
, clone
);
1140 return InvalidParameter
;
1142 *clone
= heap_alloc_zero(sizeof(GpPath
));
1143 if(!*clone
) return OutOfMemory
;
1147 (*clone
)->pathdata
.Points
= heap_alloc_zero(path
->datalen
* sizeof(PointF
));
1148 (*clone
)->pathdata
.Types
= heap_alloc_zero(path
->datalen
);
1149 if(!(*clone
)->pathdata
.Points
|| !(*clone
)->pathdata
.Types
){
1150 heap_free((*clone
)->pathdata
.Points
);
1151 heap_free((*clone
)->pathdata
.Types
);
1156 memcpy((*clone
)->pathdata
.Points
, path
->pathdata
.Points
,
1157 path
->datalen
* sizeof(PointF
));
1158 memcpy((*clone
)->pathdata
.Types
, path
->pathdata
.Types
, path
->datalen
);
1163 GpStatus WINGDIPAPI
GdipClosePathFigure(GpPath
* path
)
1165 TRACE("(%p)\n", path
);
1168 return InvalidParameter
;
1170 if(path
->pathdata
.Count
> 0){
1171 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
1172 path
->newfigure
= TRUE
;
1178 GpStatus WINGDIPAPI
GdipClosePathFigures(GpPath
* path
)
1182 TRACE("(%p)\n", path
);
1185 return InvalidParameter
;
1187 for(i
= 1; i
< path
->pathdata
.Count
; i
++){
1188 if(path
->pathdata
.Types
[i
] == PathPointTypeStart
)
1189 path
->pathdata
.Types
[i
-1] |= PathPointTypeCloseSubpath
;
1192 path
->newfigure
= TRUE
;
1197 GpStatus WINGDIPAPI
GdipCreatePath(GpFillMode fill
, GpPath
**path
)
1199 TRACE("(%d, %p)\n", fill
, path
);
1202 return InvalidParameter
;
1204 *path
= heap_alloc_zero(sizeof(GpPath
));
1205 if(!*path
) return OutOfMemory
;
1207 (*path
)->fill
= fill
;
1208 (*path
)->newfigure
= TRUE
;
1213 GpStatus WINGDIPAPI
GdipCreatePath2(GDIPCONST GpPointF
* points
,
1214 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1216 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1219 return InvalidParameter
;
1221 *path
= heap_alloc_zero(sizeof(GpPath
));
1222 if(!*path
) return OutOfMemory
;
1224 (*path
)->pathdata
.Points
= heap_alloc_zero(count
* sizeof(PointF
));
1225 (*path
)->pathdata
.Types
= heap_alloc_zero(count
);
1227 if(!(*path
)->pathdata
.Points
|| !(*path
)->pathdata
.Types
){
1228 heap_free((*path
)->pathdata
.Points
);
1229 heap_free((*path
)->pathdata
.Types
);
1234 memcpy((*path
)->pathdata
.Points
, points
, count
* sizeof(PointF
));
1235 memcpy((*path
)->pathdata
.Types
, types
, count
);
1236 (*path
)->pathdata
.Count
= count
;
1237 (*path
)->datalen
= count
;
1239 (*path
)->fill
= fill
;
1240 (*path
)->newfigure
= TRUE
;
1245 GpStatus WINGDIPAPI
GdipCreatePath2I(GDIPCONST GpPoint
* points
,
1246 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1252 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1254 ptF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1256 for(i
= 0;i
< count
; i
++){
1257 ptF
[i
].X
= (REAL
)points
[i
].X
;
1258 ptF
[i
].Y
= (REAL
)points
[i
].Y
;
1261 ret
= GdipCreatePath2(ptF
, types
, count
, fill
, path
);
1268 GpStatus WINGDIPAPI
GdipDeletePath(GpPath
*path
)
1270 TRACE("(%p)\n", path
);
1273 return InvalidParameter
;
1275 heap_free(path
->pathdata
.Points
);
1276 heap_free(path
->pathdata
.Types
);
1282 GpStatus WINGDIPAPI
GdipFlattenPath(GpPath
*path
, GpMatrix
* matrix
, REAL flatness
)
1284 path_list_node_t
*list
, *node
;
1290 TRACE("(%p, %p, %.2f)\n", path
, matrix
, flatness
);
1293 return InvalidParameter
;
1295 if(path
->pathdata
.Count
== 0)
1298 stat
= GdipTransformPath(path
, matrix
);
1302 pt
= path
->pathdata
.Points
[0];
1303 if(!init_path_list(&list
, pt
.X
, pt
.Y
))
1308 while(i
< path
->pathdata
.Count
){
1310 BYTE type
= path
->pathdata
.Types
[i
] & PathPointTypePathTypeMask
;
1311 path_list_node_t
*start
;
1313 pt
= path
->pathdata
.Points
[i
];
1315 /* save last start point index */
1316 if(type
== PathPointTypeStart
)
1319 /* always add line points and start points */
1320 if((type
== PathPointTypeStart
) || (type
== PathPointTypeLine
)){
1321 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, path
->pathdata
.Types
[i
]))
1331 /* test for closed figure */
1332 if(path
->pathdata
.Types
[i
+1] & PathPointTypeCloseSubpath
){
1333 pt
= path
->pathdata
.Points
[startidx
];
1339 pt
= path
->pathdata
.Points
[i
];
1343 /* add Bezier end point */
1344 type
= (path
->pathdata
.Types
[i
] & ~PathPointTypePathTypeMask
) | PathPointTypeLine
;
1345 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, type
))
1350 if(!flatten_bezier(start
, path
->pathdata
.Points
[i
-2].X
, path
->pathdata
.Points
[i
-2].Y
,
1351 path
->pathdata
.Points
[i
-1].X
, path
->pathdata
.Points
[i
-1].Y
,
1358 /* store path data back */
1359 i
= path_list_count(list
);
1360 if(!lengthen_path(path
, i
))
1362 path
->pathdata
.Count
= i
;
1365 for(i
= 0; i
< path
->pathdata
.Count
; i
++){
1366 path
->pathdata
.Points
[i
] = node
->pt
;
1367 path
->pathdata
.Types
[i
] = node
->type
;
1371 free_path_list(list
);
1375 free_path_list(list
);
1379 GpStatus WINGDIPAPI
GdipGetPathData(GpPath
*path
, GpPathData
* pathData
)
1381 TRACE("(%p, %p)\n", path
, pathData
);
1383 if(!path
|| !pathData
)
1384 return InvalidParameter
;
1386 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
1387 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
1388 memcpy(pathData
->Points
, path
->pathdata
.Points
, sizeof(PointF
) * pathData
->Count
);
1389 memcpy(pathData
->Types
, path
->pathdata
.Types
, pathData
->Count
);
1394 GpStatus WINGDIPAPI
GdipGetPathFillMode(GpPath
*path
, GpFillMode
*fillmode
)
1396 TRACE("(%p, %p)\n", path
, fillmode
);
1398 if(!path
|| !fillmode
)
1399 return InvalidParameter
;
1401 *fillmode
= path
->fill
;
1406 GpStatus WINGDIPAPI
GdipGetPathLastPoint(GpPath
* path
, GpPointF
* lastPoint
)
1410 TRACE("(%p, %p)\n", path
, lastPoint
);
1412 if(!path
|| !lastPoint
)
1413 return InvalidParameter
;
1415 count
= path
->pathdata
.Count
;
1417 *lastPoint
= path
->pathdata
.Points
[count
-1];
1422 GpStatus WINGDIPAPI
GdipGetPathPoints(GpPath
*path
, GpPointF
* points
, INT count
)
1424 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1427 return InvalidParameter
;
1429 if(count
< path
->pathdata
.Count
)
1430 return InsufficientBuffer
;
1432 memcpy(points
, path
->pathdata
.Points
, path
->pathdata
.Count
* sizeof(GpPointF
));
1437 GpStatus WINGDIPAPI
GdipGetPathPointsI(GpPath
*path
, GpPoint
* points
, INT count
)
1443 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1446 return InvalidParameter
;
1448 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1449 if(!ptf
) return OutOfMemory
;
1451 ret
= GdipGetPathPoints(path
,ptf
,count
);
1453 for(i
= 0;i
< count
;i
++){
1454 points
[i
].X
= gdip_round(ptf
[i
].X
);
1455 points
[i
].Y
= gdip_round(ptf
[i
].Y
);
1462 GpStatus WINGDIPAPI
GdipGetPathTypes(GpPath
*path
, BYTE
* types
, INT count
)
1464 TRACE("(%p, %p, %d)\n", path
, types
, count
);
1467 return InvalidParameter
;
1469 if(count
< path
->pathdata
.Count
)
1470 return InsufficientBuffer
;
1472 memcpy(types
, path
->pathdata
.Types
, path
->pathdata
.Count
);
1477 /* Windows expands the bounding box to the maximum possible bounding box
1478 * for a given pen. For example, if a line join can extend past the point
1479 * it's joining by x units, the bounding box is extended by x units in every
1480 * direction (even though this is too conservative for most cases). */
1481 GpStatus WINGDIPAPI
GdipGetPathWorldBounds(GpPath
* path
, GpRectF
* bounds
,
1482 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1484 GpPointF
* points
, temp_pts
[4];
1486 REAL path_width
= 1.0, width
, height
, temp
, low_x
, low_y
, high_x
, high_y
;
1488 TRACE("(%p, %p, %p, %p)\n", path
, bounds
, matrix
, pen
);
1490 /* Matrix and pen can be null. */
1491 if(!path
|| !bounds
)
1492 return InvalidParameter
;
1494 /* If path is empty just return. */
1495 count
= path
->pathdata
.Count
;
1497 bounds
->X
= bounds
->Y
= bounds
->Width
= bounds
->Height
= 0.0;
1501 points
= path
->pathdata
.Points
;
1503 low_x
= high_x
= points
[0].X
;
1504 low_y
= high_y
= points
[0].Y
;
1506 for(i
= 1; i
< count
; i
++){
1507 low_x
= min(low_x
, points
[i
].X
);
1508 low_y
= min(low_y
, points
[i
].Y
);
1509 high_x
= max(high_x
, points
[i
].X
);
1510 high_y
= max(high_y
, points
[i
].Y
);
1513 width
= high_x
- low_x
;
1514 height
= high_y
- low_y
;
1516 /* This looks unusual but it's the only way I can imitate windows. */
1518 temp_pts
[0].X
= low_x
;
1519 temp_pts
[0].Y
= low_y
;
1520 temp_pts
[1].X
= low_x
;
1521 temp_pts
[1].Y
= high_y
;
1522 temp_pts
[2].X
= high_x
;
1523 temp_pts
[2].Y
= high_y
;
1524 temp_pts
[3].X
= high_x
;
1525 temp_pts
[3].Y
= low_y
;
1527 GdipTransformMatrixPoints((GpMatrix
*)matrix
, temp_pts
, 4);
1528 low_x
= temp_pts
[0].X
;
1529 low_y
= temp_pts
[0].Y
;
1531 for(i
= 1; i
< 4; i
++){
1532 low_x
= min(low_x
, temp_pts
[i
].X
);
1533 low_y
= min(low_y
, temp_pts
[i
].Y
);
1537 width
= height
* fabs(matrix
->matrix
[2]) + width
* fabs(matrix
->matrix
[0]);
1538 height
= height
* fabs(matrix
->matrix
[3]) + temp
* fabs(matrix
->matrix
[1]);
1542 path_width
= pen
->width
/ 2.0;
1545 path_width
= max(path_width
, pen
->width
* pen
->miterlimit
/ 2.0);
1546 /* FIXME: this should probably also check for the startcap */
1547 if(pen
->endcap
& LineCapNoAnchor
)
1548 path_width
= max(path_width
, pen
->width
* 2.2);
1550 low_x
-= path_width
;
1551 low_y
-= path_width
;
1552 width
+= 2.0 * path_width
;
1553 height
+= 2.0 * path_width
;
1558 bounds
->Width
= width
;
1559 bounds
->Height
= height
;
1564 GpStatus WINGDIPAPI
GdipGetPathWorldBoundsI(GpPath
* path
, GpRect
* bounds
,
1565 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1570 TRACE("(%p, %p, %p, %p)\n", path
, bounds
, matrix
, pen
);
1572 ret
= GdipGetPathWorldBounds(path
,&boundsF
,matrix
,pen
);
1575 bounds
->X
= gdip_round(boundsF
.X
);
1576 bounds
->Y
= gdip_round(boundsF
.Y
);
1577 bounds
->Width
= gdip_round(boundsF
.Width
);
1578 bounds
->Height
= gdip_round(boundsF
.Height
);
1584 GpStatus WINGDIPAPI
GdipGetPointCount(GpPath
*path
, INT
*count
)
1586 TRACE("(%p, %p)\n", path
, count
);
1589 return InvalidParameter
;
1591 *count
= path
->pathdata
.Count
;
1596 GpStatus WINGDIPAPI
GdipReversePath(GpPath
* path
)
1599 INT start
= 0; /* position in reversed path */
1602 TRACE("(%p)\n", path
);
1605 return InvalidParameter
;
1607 count
= path
->pathdata
.Count
;
1609 if(count
== 0) return Ok
;
1611 revpath
.Points
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1612 revpath
.Types
= heap_alloc_zero(sizeof(BYTE
)*count
);
1613 revpath
.Count
= count
;
1614 if(!revpath
.Points
|| !revpath
.Types
){
1615 heap_free(revpath
.Points
);
1616 heap_free(revpath
.Types
);
1620 for(i
= 0; i
< count
; i
++){
1622 /* find next start point */
1623 if(path
->pathdata
.Types
[count
-i
-1] == PathPointTypeStart
){
1625 for(j
= start
; j
<= i
; j
++){
1626 revpath
.Points
[j
] = path
->pathdata
.Points
[count
-j
-1];
1627 revpath
.Types
[j
] = path
->pathdata
.Types
[count
-j
-1];
1629 /* mark start point */
1630 revpath
.Types
[start
] = PathPointTypeStart
;
1631 /* set 'figure' endpoint type */
1633 revpath
.Types
[i
] = path
->pathdata
.Types
[count
-start
-1] & ~PathPointTypePathTypeMask
;
1634 revpath
.Types
[i
] |= revpath
.Types
[i
-1];
1637 revpath
.Types
[i
] = path
->pathdata
.Types
[start
];
1643 memcpy(path
->pathdata
.Points
, revpath
.Points
, sizeof(GpPointF
)*count
);
1644 memcpy(path
->pathdata
.Types
, revpath
.Types
, sizeof(BYTE
)*count
);
1646 heap_free(revpath
.Points
);
1647 heap_free(revpath
.Types
);
1652 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPointI(GpPath
* path
, INT x
, INT y
,
1653 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1655 TRACE("(%p, %d, %d, %p, %p, %p)\n", path
, x
, y
, pen
, graphics
, result
);
1657 return GdipIsOutlineVisiblePathPoint(path
, x
, y
, pen
, graphics
, result
);
1660 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
,
1661 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1665 GpMatrix
*transform
= NULL
;
1667 TRACE("(%p,%0.2f,%0.2f,%p,%p,%p)\n", path
, x
, y
, pen
, graphics
, result
);
1670 return InvalidParameter
;
1672 stat
= GdipClonePath(path
, &wide_path
);
1677 if (pen
->unit
== UnitPixel
&& graphics
!= NULL
)
1679 stat
= GdipCreateMatrix(&transform
);
1682 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1683 CoordinateSpaceWorld
, transform
);
1687 stat
= GdipWidenPath(wide_path
, pen
, transform
, 1.0);
1689 if (pen
->unit
== UnitPixel
&& graphics
!= NULL
)
1692 stat
= GdipInvertMatrix(transform
);
1695 stat
= GdipTransformPath(wide_path
, transform
);
1699 stat
= GdipIsVisiblePathPoint(wide_path
, x
, y
, graphics
, result
);
1701 GdipDeleteMatrix(transform
);
1703 GdipDeletePath(wide_path
);
1708 GpStatus WINGDIPAPI
GdipIsVisiblePathPointI(GpPath
* path
, INT x
, INT y
, GpGraphics
*graphics
, BOOL
*result
)
1710 TRACE("(%p, %d, %d, %p, %p)\n", path
, x
, y
, graphics
, result
);
1712 return GdipIsVisiblePathPoint(path
, x
, y
, graphics
, result
);
1715 /*****************************************************************************
1716 * GdipIsVisiblePathPoint [GDIPLUS.@]
1718 GpStatus WINGDIPAPI
GdipIsVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
, GpGraphics
*graphics
, BOOL
*result
)
1724 if(!path
|| !result
) return InvalidParameter
;
1726 status
= GdipCreateRegionPath(path
, ®ion
);
1730 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
1732 GdipDeleteRegion(region
);
1736 *result
= PtInRegion(hrgn
, gdip_round(x
), gdip_round(y
));
1739 GdipDeleteRegion(region
);
1744 GpStatus WINGDIPAPI
GdipStartPathFigure(GpPath
*path
)
1746 TRACE("(%p)\n", path
);
1749 return InvalidParameter
;
1751 path
->newfigure
= TRUE
;
1756 GpStatus WINGDIPAPI
GdipResetPath(GpPath
*path
)
1758 TRACE("(%p)\n", path
);
1761 return InvalidParameter
;
1763 path
->pathdata
.Count
= 0;
1764 path
->newfigure
= TRUE
;
1765 path
->fill
= FillModeAlternate
;
1770 GpStatus WINGDIPAPI
GdipSetPathFillMode(GpPath
*path
, GpFillMode fill
)
1772 TRACE("(%p, %d)\n", path
, fill
);
1775 return InvalidParameter
;
1782 GpStatus WINGDIPAPI
GdipTransformPath(GpPath
*path
, GpMatrix
*matrix
)
1784 TRACE("(%p, %p)\n", path
, matrix
);
1787 return InvalidParameter
;
1789 if(path
->pathdata
.Count
== 0 || !matrix
)
1792 return GdipTransformMatrixPoints(matrix
, path
->pathdata
.Points
,
1793 path
->pathdata
.Count
);
1796 GpStatus WINGDIPAPI
GdipWarpPath(GpPath
*path
, GpMatrix
* matrix
,
1797 GDIPCONST GpPointF
*points
, INT count
, REAL x
, REAL y
, REAL width
,
1798 REAL height
, WarpMode warpmode
, REAL flatness
)
1800 FIXME("(%p,%p,%p,%i,%0.2f,%0.2f,%0.2f,%0.2f,%i,%0.2f)\n", path
, matrix
,
1801 points
, count
, x
, y
, width
, height
, warpmode
, flatness
);
1803 return NotImplemented
;
1806 static void add_bevel_point(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1807 GpPen
*pen
, int right_side
, path_list_node_t
**last_point
)
1809 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1810 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1811 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1812 REAL distance
= pen
->width
/2.0;
1813 REAL bevel_dx
, bevel_dy
;
1815 if (segment_length
== 0.0)
1817 *last_point
= add_path_list_node(*last_point
, endpoint
->X
,
1818 endpoint
->Y
, PathPointTypeLine
);
1824 bevel_dx
= -distance
* segment_dy
/ segment_length
;
1825 bevel_dy
= distance
* segment_dx
/ segment_length
;
1829 bevel_dx
= distance
* segment_dy
/ segment_length
;
1830 bevel_dy
= -distance
* segment_dx
/ segment_length
;
1833 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ bevel_dx
,
1834 endpoint
->Y
+ bevel_dy
, PathPointTypeLine
);
1837 static void widen_joint(const GpPointF
*p1
, const GpPointF
*p2
, const GpPointF
*p3
,
1838 GpPen
* pen
, path_list_node_t
**last_point
)
1843 case LineJoinMiterClipped
:
1844 if ((p2
->X
- p1
->X
) * (p3
->Y
- p1
->Y
) > (p2
->Y
- p1
->Y
) * (p3
->X
- p1
->X
))
1846 float distance
= pen
->width
/2.0;
1847 float length_0
= sqrtf((p2
->X
-p1
->X
)*(p2
->X
-p1
->X
)+(p2
->Y
-p1
->Y
)*(p2
->Y
-p1
->Y
));
1848 float length_1
= sqrtf((p3
->X
-p2
->X
)*(p3
->X
-p2
->X
)+(p3
->Y
-p2
->Y
)*(p3
->Y
-p2
->Y
));
1849 float dx0
= distance
* (p2
->X
- p1
->X
) / length_0
;
1850 float dy0
= distance
* (p2
->Y
- p1
->Y
) / length_0
;
1851 float dx1
= distance
* (p3
->X
- p2
->X
) / length_1
;
1852 float dy1
= distance
* (p3
->Y
- p2
->Y
) / length_1
;
1853 float det
= (dy0
*dx1
- dx0
*dy1
);
1854 float dx
= (dx0
*dx1
*(dx0
-dx1
) + dy0
*dy0
*dx1
- dy1
*dy1
*dx0
)/det
;
1855 float dy
= (dy0
*dy1
*(dy0
-dy1
) + dx0
*dx0
*dy1
- dx1
*dx1
*dy0
)/det
;
1856 if (dx
*dx
+ dy
*dy
< pen
->miterlimit
*pen
->miterlimit
* distance
*distance
)
1858 *last_point
= add_path_list_node(*last_point
, p2
->X
+ dx
,
1859 p2
->Y
+ dy
, PathPointTypeLine
);
1862 else if (pen
->join
== LineJoinMiter
)
1866 FIXME("should add a clipped corner\n");
1868 /* else fall-through */
1870 /* else fall-through */
1873 add_bevel_point(p2
, p1
, pen
, 1, last_point
);
1874 add_bevel_point(p2
, p3
, pen
, 0, last_point
);
1879 static void widen_cap(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1880 GpPen
*pen
, GpLineCap cap
, GpCustomLineCap
*custom
, int add_first_points
,
1881 int add_last_point
, path_list_node_t
**last_point
)
1887 if (add_first_points
)
1888 add_bevel_point(endpoint
, nextpoint
, pen
, 1, last_point
);
1890 add_bevel_point(endpoint
, nextpoint
, pen
, 0, last_point
);
1894 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1895 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1896 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1897 REAL distance
= pen
->width
/2.0;
1898 REAL bevel_dx
, bevel_dy
;
1899 REAL extend_dx
, extend_dy
;
1901 extend_dx
= -distance
* segment_dx
/ segment_length
;
1902 extend_dy
= -distance
* segment_dy
/ segment_length
;
1904 bevel_dx
= -distance
* segment_dy
/ segment_length
;
1905 bevel_dy
= distance
* segment_dx
/ segment_length
;
1907 if (add_first_points
)
1908 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ extend_dx
+ bevel_dx
,
1909 endpoint
->Y
+ extend_dy
+ bevel_dy
, PathPointTypeLine
);
1912 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ extend_dx
- bevel_dx
,
1913 endpoint
->Y
+ extend_dy
- bevel_dy
, PathPointTypeLine
);
1919 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1920 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1921 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1922 REAL distance
= pen
->width
/2.0;
1923 REAL dx
, dy
, dx2
, dy2
;
1924 const REAL control_point_distance
= 0.5522847498307935; /* 4/3 * (sqrt(2) - 1) */
1926 if (add_first_points
)
1928 dx
= -distance
* segment_dx
/ segment_length
;
1929 dy
= -distance
* segment_dy
/ segment_length
;
1931 dx2
= dx
* control_point_distance
;
1932 dy2
= dy
* control_point_distance
;
1934 /* first 90-degree arc */
1935 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
1936 endpoint
->Y
- dx
, PathPointTypeLine
);
1938 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
+ dx2
,
1939 endpoint
->Y
- dx
+ dy2
, PathPointTypeBezier
);
1941 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
+ dy2
,
1942 endpoint
->Y
+ dy
- dx2
, PathPointTypeBezier
);
1945 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
,
1946 endpoint
->Y
+ dy
, PathPointTypeBezier
);
1948 /* second 90-degree arc */
1949 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
- dy2
,
1950 endpoint
->Y
+ dy
+ dx2
, PathPointTypeBezier
);
1952 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
+ dx2
,
1953 endpoint
->Y
+ dx
+ dy2
, PathPointTypeBezier
);
1955 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
,
1956 endpoint
->Y
+ dx
, PathPointTypeBezier
);
1960 case LineCapTriangle
:
1962 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1963 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1964 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1965 REAL distance
= pen
->width
/2.0;
1968 dx
= distance
* segment_dx
/ segment_length
;
1969 dy
= distance
* segment_dy
/ segment_length
;
1971 if (add_first_points
) {
1972 add_bevel_point(endpoint
, nextpoint
, pen
, 1, last_point
);
1974 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
,
1975 endpoint
->Y
- dy
, PathPointTypeLine
);
1978 add_bevel_point(endpoint
, nextpoint
, pen
, 0, last_point
);
1984 static void widen_open_figure(const GpPointF
*points
, GpPen
*pen
, int start
, int end
,
1985 GpLineCap start_cap
, GpCustomLineCap
*start_custom
, GpLineCap end_cap
,
1986 GpCustomLineCap
*end_custom
, path_list_node_t
**last_point
)
1989 path_list_node_t
*prev_point
;
1994 prev_point
= *last_point
;
1996 widen_cap(&points
[start
], &points
[start
+1],
1997 pen
, start_cap
, start_custom
, FALSE
, TRUE
, last_point
);
1999 for (i
=start
+1; i
<end
; i
++)
2000 widen_joint(&points
[i
-1], &points
[i
],
2001 &points
[i
+1], pen
, last_point
);
2003 widen_cap(&points
[end
], &points
[end
-1],
2004 pen
, end_cap
, end_custom
, TRUE
, TRUE
, last_point
);
2006 for (i
=end
-1; i
>start
; i
--)
2007 widen_joint(&points
[i
+1], &points
[i
],
2008 &points
[i
-1], pen
, last_point
);
2010 widen_cap(&points
[start
], &points
[start
+1],
2011 pen
, start_cap
, start_custom
, TRUE
, FALSE
, last_point
);
2013 prev_point
->next
->type
= PathPointTypeStart
;
2014 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2017 static void widen_closed_figure(GpPath
*path
, GpPen
*pen
, int start
, int end
,
2018 path_list_node_t
**last_point
)
2021 path_list_node_t
*prev_point
;
2027 prev_point
= *last_point
;
2029 widen_joint(&path
->pathdata
.Points
[end
], &path
->pathdata
.Points
[start
],
2030 &path
->pathdata
.Points
[start
+1], pen
, last_point
);
2032 for (i
=start
+1; i
<end
; i
++)
2033 widen_joint(&path
->pathdata
.Points
[i
-1], &path
->pathdata
.Points
[i
],
2034 &path
->pathdata
.Points
[i
+1], pen
, last_point
);
2036 widen_joint(&path
->pathdata
.Points
[end
-1], &path
->pathdata
.Points
[end
],
2037 &path
->pathdata
.Points
[start
], pen
, last_point
);
2039 prev_point
->next
->type
= PathPointTypeStart
;
2040 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2043 prev_point
= *last_point
;
2045 widen_joint(&path
->pathdata
.Points
[start
], &path
->pathdata
.Points
[end
],
2046 &path
->pathdata
.Points
[end
-1], pen
, last_point
);
2048 for (i
=end
-1; i
>start
; i
--)
2049 widen_joint(&path
->pathdata
.Points
[i
+1], &path
->pathdata
.Points
[i
],
2050 &path
->pathdata
.Points
[i
-1], pen
, last_point
);
2052 widen_joint(&path
->pathdata
.Points
[start
+1], &path
->pathdata
.Points
[start
],
2053 &path
->pathdata
.Points
[end
], pen
, last_point
);
2055 prev_point
->next
->type
= PathPointTypeStart
;
2056 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2059 static void widen_dashed_figure(GpPath
*path
, GpPen
*pen
, int start
, int end
,
2060 int closed
, path_list_node_t
**last_point
)
2065 const REAL
*dash_pattern
;
2066 REAL
*dash_pattern_scaled
;
2068 GpPointF
*tmp_points
;
2071 REAL segment_length
;
2073 int num_tmp_points
=0;
2074 int draw_start_cap
=0;
2075 static const REAL dash_dot_dot
[6] = { 3.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
2084 dash_pattern
= dash_dot_dot
;
2088 dash_pattern
= &dash_dot_dot
[2];
2091 case DashStyleDashDot
:
2092 dash_pattern
= dash_dot_dot
;
2095 case DashStyleDashDotDot
:
2096 dash_pattern
= dash_dot_dot
;
2099 case DashStyleCustom
:
2100 dash_pattern
= pen
->dashes
;
2101 dash_count
= pen
->numdashes
;
2105 dash_pattern_scaled
= heap_alloc(dash_count
* sizeof(REAL
));
2106 if (!dash_pattern_scaled
) return;
2108 for (i
= 0; i
< dash_count
; i
++)
2109 dash_pattern_scaled
[i
] = pen
->width
* dash_pattern
[i
];
2111 tmp_points
= heap_alloc_zero((end
- start
+ 2) * sizeof(GpPoint
));
2112 if (!tmp_points
) return; /* FIXME */
2117 for (j
=start
; j
<= end
; j
++)
2129 segment_dy
= path
->pathdata
.Points
[j
].Y
- path
->pathdata
.Points
[i
].Y
;
2130 segment_dx
= path
->pathdata
.Points
[j
].X
- path
->pathdata
.Points
[i
].X
;
2131 segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2136 if (dash_pos
== 0.0)
2138 if ((dash_index
% 2) == 0)
2142 tmp_points
[0].X
= path
->pathdata
.Points
[i
].X
+ segment_dx
* segment_pos
/ segment_length
;
2143 tmp_points
[0].Y
= path
->pathdata
.Points
[i
].Y
+ segment_dy
* segment_pos
/ segment_length
;
2148 tmp_points
[num_tmp_points
].X
= path
->pathdata
.Points
[i
].X
+ segment_dx
* segment_pos
/ segment_length
;
2149 tmp_points
[num_tmp_points
].Y
= path
->pathdata
.Points
[i
].Y
+ segment_dy
* segment_pos
/ segment_length
;
2151 widen_open_figure(tmp_points
, pen
, 0, num_tmp_points
,
2152 draw_start_cap
? pen
->startcap
: LineCapFlat
, pen
->customstart
,
2153 LineCapFlat
, NULL
, last_point
);
2159 if (dash_pattern_scaled
[dash_index
] - dash_pos
> segment_length
- segment_pos
)
2161 /* advance to next segment */
2162 if ((dash_index
% 2) == 0)
2164 tmp_points
[num_tmp_points
] = path
->pathdata
.Points
[j
];
2167 dash_pos
+= segment_length
- segment_pos
;
2172 /* advance to next dash in pattern */
2173 segment_pos
+= dash_pattern_scaled
[dash_index
] - dash_pos
;
2175 if (++dash_index
== dash_count
)
2182 if (dash_index
% 2 == 0 && num_tmp_points
!= 0)
2184 /* last dash overflows last segment */
2185 widen_open_figure(tmp_points
, pen
, 0, num_tmp_points
-1,
2186 draw_start_cap
? pen
->startcap
: LineCapFlat
, pen
->customstart
,
2187 closed
? LineCapFlat
: pen
->endcap
, pen
->customend
, last_point
);
2190 heap_free(dash_pattern_scaled
);
2191 heap_free(tmp_points
);
2194 GpStatus WINGDIPAPI
GdipWidenPath(GpPath
*path
, GpPen
*pen
, GpMatrix
*matrix
,
2197 GpPath
*flat_path
=NULL
;
2199 path_list_node_t
*points
=NULL
, *last_point
=NULL
;
2200 int i
, subpath_start
=0, new_length
;
2203 TRACE("(%p,%p,%p,%0.2f)\n", path
, pen
, matrix
, flatness
);
2206 return InvalidParameter
;
2208 if (path
->pathdata
.Count
<= 1)
2211 status
= GdipClonePath(path
, &flat_path
);
2214 status
= GdipFlattenPath(flat_path
, pen
->unit
== UnitPixel
? matrix
: NULL
, flatness
);
2216 if (status
== Ok
&& !init_path_list(&points
, 314.0, 22.0))
2217 status
= OutOfMemory
;
2221 last_point
= points
;
2223 if (pen
->endcap
> LineCapTriangle
)
2224 FIXME("unimplemented end cap %x\n", pen
->endcap
);
2226 if (pen
->startcap
> LineCapTriangle
)
2227 FIXME("unimplemented start cap %x\n", pen
->startcap
);
2229 if (pen
->dashcap
!= DashCapFlat
)
2230 FIXME("unimplemented dash cap %d\n", pen
->dashcap
);
2232 if (pen
->join
== LineJoinRound
)
2233 FIXME("unimplemented line join %d\n", pen
->join
);
2235 if (pen
->align
!= PenAlignmentCenter
)
2236 FIXME("unimplemented pen alignment %d\n", pen
->align
);
2238 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
2240 type
= flat_path
->pathdata
.Types
[i
];
2242 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2245 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2247 if (pen
->dash
!= DashStyleSolid
)
2248 widen_dashed_figure(flat_path
, pen
, subpath_start
, i
, 1, &last_point
);
2250 widen_closed_figure(flat_path
, pen
, subpath_start
, i
, &last_point
);
2252 else if (i
== flat_path
->pathdata
.Count
-1 ||
2253 (flat_path
->pathdata
.Types
[i
+1]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2255 if (pen
->dash
!= DashStyleSolid
)
2256 widen_dashed_figure(flat_path
, pen
, subpath_start
, i
, 0, &last_point
);
2258 widen_open_figure(flat_path
->pathdata
.Points
, pen
, subpath_start
, i
, pen
->startcap
, pen
->customstart
, pen
->endcap
, pen
->customend
, &last_point
);
2262 new_length
= path_list_count(points
)-1;
2264 if (!lengthen_path(path
, new_length
))
2265 status
= OutOfMemory
;
2270 path
->pathdata
.Count
= new_length
;
2272 last_point
= points
->next
;
2273 for (i
= 0; i
< new_length
; i
++)
2275 path
->pathdata
.Points
[i
] = last_point
->pt
;
2276 path
->pathdata
.Types
[i
] = last_point
->type
;
2277 last_point
= last_point
->next
;
2280 path
->fill
= FillModeWinding
;
2283 free_path_list(points
);
2285 GdipDeletePath(flat_path
);
2287 if (status
== Ok
&& pen
->unit
!= UnitPixel
)
2288 status
= GdipTransformPath(path
, matrix
);
2293 GpStatus WINGDIPAPI
GdipAddPathRectangle(GpPath
*path
, REAL x
, REAL y
,
2294 REAL width
, REAL height
)
2301 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
2304 return InvalidParameter
;
2306 /* make a backup copy of path data */
2307 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2310 /* rectangle should start as new path */
2311 old_new
= path
->newfigure
;
2312 path
->newfigure
= TRUE
;
2313 if((retstat
= GdipAddPathLine(path
,x
,y
,x
+width
,y
)) != Ok
){
2314 path
->newfigure
= old_new
;
2319 ptf
[0].Y
= y
+height
;
2321 ptf
[1].Y
= y
+height
;
2323 if((retstat
= GdipAddPathLine2(path
, ptf
, 2)) != Ok
) goto fail
;
2324 path
->pathdata
.Types
[path
->pathdata
.Count
-1] |= PathPointTypeCloseSubpath
;
2327 GdipDeletePath(backup
);
2332 heap_free(path
->pathdata
.Points
);
2333 heap_free(path
->pathdata
.Types
);
2334 memcpy(path
, backup
, sizeof(*path
));
2340 GpStatus WINGDIPAPI
GdipAddPathRectangleI(GpPath
*path
, INT x
, INT y
,
2341 INT width
, INT height
)
2343 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
2345 return GdipAddPathRectangle(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2348 GpStatus WINGDIPAPI
GdipAddPathRectangles(GpPath
*path
, GDIPCONST GpRectF
*rects
, INT count
)
2354 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2356 /* count == 0 - verified condition */
2357 if(!path
|| !rects
|| count
== 0)
2358 return InvalidParameter
;
2363 /* make a backup copy */
2364 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2367 for(i
= 0; i
< count
; i
++){
2368 if((retstat
= GdipAddPathRectangle(path
,rects
[i
].X
,rects
[i
].Y
,rects
[i
].Width
,rects
[i
].Height
)) != Ok
)
2373 GdipDeletePath(backup
);
2378 heap_free(path
->pathdata
.Points
);
2379 heap_free(path
->pathdata
.Types
);
2380 memcpy(path
, backup
, sizeof(*path
));
2386 GpStatus WINGDIPAPI
GdipAddPathRectanglesI(GpPath
*path
, GDIPCONST GpRect
*rects
, INT count
)
2392 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2394 if(!rects
|| count
== 0)
2395 return InvalidParameter
;
2400 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
2402 for(i
= 0;i
< count
;i
++){
2403 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2404 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2405 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2406 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2409 retstat
= GdipAddPathRectangles(path
, rectsF
, count
);
2415 GpStatus WINGDIPAPI
GdipSetPathMarker(GpPath
* path
)
2419 TRACE("(%p)\n", path
);
2422 return InvalidParameter
;
2424 count
= path
->pathdata
.Count
;
2426 /* set marker flag */
2428 path
->pathdata
.Types
[count
-1] |= PathPointTypePathMarker
;
2433 GpStatus WINGDIPAPI
GdipClearPathMarkers(GpPath
* path
)
2438 TRACE("(%p)\n", path
);
2441 return InvalidParameter
;
2443 count
= path
->pathdata
.Count
;
2445 for(i
= 0; i
< count
- 1; i
++){
2446 path
->pathdata
.Types
[i
] &= ~PathPointTypePathMarker
;
2452 GpStatus WINGDIPAPI
GdipWindingModeOutline(GpPath
*path
, GpMatrix
*matrix
, REAL flatness
)
2454 FIXME("stub: %p, %p, %.2f\n", path
, matrix
, flatness
);
2455 return NotImplemented
;
2458 #define FLAGS_INTPATH 0x4000
2467 /* Test to see if the path could be stored as an array of shorts */
2468 static BOOL
is_integer_path(const GpPath
*path
)
2472 if (!path
->pathdata
.Count
) return FALSE
;
2474 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2477 x
= gdip_round(path
->pathdata
.Points
[i
].X
);
2478 y
= gdip_round(path
->pathdata
.Points
[i
].Y
);
2479 if (path
->pathdata
.Points
[i
].X
!= (REAL
)x
|| path
->pathdata
.Points
[i
].Y
!= (REAL
)y
)
2485 DWORD
write_path_data(GpPath
*path
, void *data
)
2487 struct path_header
*header
= data
;
2488 BOOL integer_path
= is_integer_path(path
);
2492 size
= sizeof(struct path_header
) + path
->pathdata
.Count
;
2494 size
+= sizeof(short[2]) * path
->pathdata
.Count
;
2496 size
+= sizeof(float[2]) * path
->pathdata
.Count
;
2497 size
= (size
+ 3) & ~3;
2499 if (!data
) return size
;
2501 header
->version
= VERSION_MAGIC2
;
2502 header
->count
= path
->pathdata
.Count
;
2503 header
->flags
= integer_path
? FLAGS_INTPATH
: 0;
2507 short *points
= (short*)(header
+ 1);
2508 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2510 points
[2*i
] = path
->pathdata
.Points
[i
].X
;
2511 points
[2*i
+ 1] = path
->pathdata
.Points
[i
].Y
;
2513 types
= (BYTE
*)(points
+ 2*i
);
2517 float *points
= (float*)(header
+ 1);
2518 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2520 points
[2*i
] = path
->pathdata
.Points
[i
].X
;
2521 points
[2*i
+ 1] = path
->pathdata
.Points
[i
].Y
;
2523 types
= (BYTE
*)(points
+ 2*i
);
2526 for (i
=0; i
<path
->pathdata
.Count
; i
++)
2527 types
[i
] = path
->pathdata
.Types
[i
];
2528 memset(types
+ i
, 0, ((path
->pathdata
.Count
+ 3) & ~3) - path
->pathdata
.Count
);