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
20 #include "gdiplus_private.h"
22 typedef struct path_list_node_t path_list_node_t
;
23 struct path_list_node_t
{
25 BYTE type
; /* PathPointTypeStart or PathPointTypeLine */
26 path_list_node_t
*next
;
30 static BOOL
init_path_list(path_list_node_t
**node
, REAL x
, REAL y
)
32 *node
= GdipAlloc(sizeof(path_list_node_t
));
38 (*node
)->type
= PathPointTypeStart
;
44 /* free all nodes including argument */
45 static void free_path_list(path_list_node_t
*node
)
47 path_list_node_t
*n
= node
;
56 /* Add a node after 'node' */
60 * NULL on allocation problems
62 static path_list_node_t
* add_path_list_node(path_list_node_t
*node
, REAL x
, REAL y
, BOOL type
)
64 path_list_node_t
*new;
66 new = GdipAlloc(sizeof(path_list_node_t
));
73 new->next
= node
->next
;
79 /* returns element count */
80 static INT
path_list_count(path_list_node_t
*node
)
84 while((node
= node
->next
))
90 /* GdipFlattenPath helper */
92 * Used to recursively flatten single Bezier curve
94 * - start : pointer to start point node;
95 * - (x2, y2): first control point;
96 * - (x3, y3): second control point;
97 * - end : pointer to end point node
98 * - flatness: admissible error of linear approximation.
102 * FALSE: out of memory
104 * TODO: used quality criteria should be revised to match native as
105 * closer as possible.
107 static BOOL
flatten_bezier(path_list_node_t
*start
, REAL x2
, REAL y2
, REAL x3
, REAL y3
,
108 path_list_node_t
*end
, REAL flatness
)
110 /* this 5 middle points with start/end define to half-curves */
113 path_list_node_t
*node
;
115 /* calculate bezier curve middle points == new control points */
116 mp
[0].X
= (start
->pt
.X
+ x2
) / 2.0;
117 mp
[0].Y
= (start
->pt
.Y
+ y2
) / 2.0;
118 /* middle point between control points */
119 pt
.X
= (x2
+ x3
) / 2.0;
120 pt
.Y
= (y2
+ y3
) / 2.0;
121 mp
[1].X
= (mp
[0].X
+ pt
.X
) / 2.0;
122 mp
[1].Y
= (mp
[0].Y
+ pt
.Y
) / 2.0;
123 mp
[4].X
= (end
->pt
.X
+ x3
) / 2.0;
124 mp
[4].Y
= (end
->pt
.Y
+ y3
) / 2.0;
125 mp
[3].X
= (mp
[4].X
+ pt
.X
) / 2.0;
126 mp
[3].Y
= (mp
[4].Y
+ pt
.Y
) / 2.0;
128 mp
[2].X
= (mp
[1].X
+ mp
[3].X
) / 2.0;
129 mp
[2].Y
= (mp
[1].Y
+ mp
[3].Y
) / 2.0;
133 /* check flatness as a half of distance between middle point and a linearized path */
134 if(fabs(((pt
.Y
- pt_st
.Y
)*mp
[2].X
+ (pt_st
.X
- pt
.X
)*mp
[2].Y
+
135 (pt_st
.Y
*pt
.X
- pt_st
.X
*pt
.Y
))) <=
136 (0.5 * flatness
*sqrtf((powf(pt
.Y
- pt_st
.Y
, 2.0) + powf(pt_st
.X
- pt
.X
, 2.0))))){
140 /* add a middle point */
141 if(!(node
= add_path_list_node(start
, mp
[2].X
, mp
[2].Y
, PathPointTypeLine
)))
144 /* do the same with halves */
145 flatten_bezier(start
, mp
[0].X
, mp
[0].Y
, mp
[1].X
, mp
[1].Y
, node
, flatness
);
146 flatten_bezier(node
, mp
[3].X
, mp
[3].Y
, mp
[4].X
, mp
[4].Y
, end
, flatness
);
151 GpStatus WINGDIPAPI
GdipAddPathArc(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
152 REAL y2
, REAL startAngle
, REAL sweepAngle
)
154 INT count
, old_count
, i
;
156 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
157 path
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
160 return InvalidParameter
;
162 count
= arc2polybezier(NULL
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
166 if(!lengthen_path(path
, count
))
169 old_count
= path
->pathdata
.Count
;
170 arc2polybezier(&path
->pathdata
.Points
[old_count
], x1
, y1
, x2
, y2
,
171 startAngle
, sweepAngle
);
173 for(i
= 0; i
< count
; i
++){
174 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeBezier
;
177 path
->pathdata
.Types
[old_count
] =
178 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
179 path
->newfigure
= FALSE
;
180 path
->pathdata
.Count
+= count
;
185 GpStatus WINGDIPAPI
GdipAddPathArcI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
186 INT y2
, REAL startAngle
, REAL sweepAngle
)
188 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
189 path
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
191 return GdipAddPathArc(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,startAngle
,sweepAngle
);
194 GpStatus WINGDIPAPI
GdipAddPathBezier(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
195 REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
199 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
200 path
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
203 return InvalidParameter
;
205 if(!lengthen_path(path
, 4))
208 old_count
= path
->pathdata
.Count
;
210 path
->pathdata
.Points
[old_count
].X
= x1
;
211 path
->pathdata
.Points
[old_count
].Y
= y1
;
212 path
->pathdata
.Points
[old_count
+ 1].X
= x2
;
213 path
->pathdata
.Points
[old_count
+ 1].Y
= y2
;
214 path
->pathdata
.Points
[old_count
+ 2].X
= x3
;
215 path
->pathdata
.Points
[old_count
+ 2].Y
= y3
;
216 path
->pathdata
.Points
[old_count
+ 3].X
= x4
;
217 path
->pathdata
.Points
[old_count
+ 3].Y
= y4
;
219 path
->pathdata
.Types
[old_count
] =
220 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
221 path
->pathdata
.Types
[old_count
+ 1] = PathPointTypeBezier
;
222 path
->pathdata
.Types
[old_count
+ 2] = PathPointTypeBezier
;
223 path
->pathdata
.Types
[old_count
+ 3] = PathPointTypeBezier
;
225 path
->newfigure
= FALSE
;
226 path
->pathdata
.Count
+= 4;
231 GpStatus WINGDIPAPI
GdipAddPathBezierI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
232 INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
234 TRACE("(%p, %d, %d, %d, %d, %d, %d, %d, %d)\n",
235 path
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
237 return GdipAddPathBezier(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,(REAL
)x3
,(REAL
)y3
,
241 GpStatus WINGDIPAPI
GdipAddPathBeziers(GpPath
*path
, GDIPCONST GpPointF
*points
,
246 TRACE("(%p, %p, %d)\n", path
, points
, count
);
248 if(!path
|| !points
|| ((count
- 1) % 3))
249 return InvalidParameter
;
251 if(!lengthen_path(path
, count
))
254 old_count
= path
->pathdata
.Count
;
256 for(i
= 0; i
< count
; i
++){
257 path
->pathdata
.Points
[old_count
+ i
].X
= points
[i
].X
;
258 path
->pathdata
.Points
[old_count
+ i
].Y
= points
[i
].Y
;
259 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeBezier
;
262 path
->pathdata
.Types
[old_count
] =
263 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
264 path
->newfigure
= FALSE
;
265 path
->pathdata
.Count
+= count
;
270 GpStatus WINGDIPAPI
GdipAddPathBeziersI(GpPath
*path
, GDIPCONST GpPoint
*points
,
277 TRACE("(%p, %p, %d)\n", path
, points
, count
);
279 if(!points
|| ((count
- 1) % 3))
280 return InvalidParameter
;
282 ptsF
= GdipAlloc(sizeof(GpPointF
) * count
);
286 for(i
= 0; i
< count
; i
++){
287 ptsF
[i
].X
= (REAL
)points
[i
].X
;
288 ptsF
[i
].Y
= (REAL
)points
[i
].Y
;
291 ret
= GdipAddPathBeziers(path
, ptsF
, count
);
297 GpStatus WINGDIPAPI
GdipAddPathClosedCurve(GpPath
*path
, GDIPCONST GpPointF
*points
,
300 TRACE("(%p, %p, %d)\n", path
, points
, count
);
302 return GdipAddPathClosedCurve2(path
, points
, count
, 1.0);
305 GpStatus WINGDIPAPI
GdipAddPathClosedCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
,
308 TRACE("(%p, %p, %d)\n", path
, points
, count
);
310 return GdipAddPathClosedCurve2I(path
, points
, count
, 1.0);
313 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
,
314 INT count
, REAL tension
)
316 INT i
, len_pt
= (count
+ 1)*3-2;
322 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
324 if(!path
|| !points
|| count
<= 1)
325 return InvalidParameter
;
327 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
328 pts
= GdipAlloc((count
+ 1)*sizeof(GpPointF
));
335 /* copy source points to extend with the last one */
336 memcpy(pts
, points
, sizeof(GpPointF
)*count
);
339 tension
= tension
* TENSION_CONST
;
341 for(i
= 0; i
< count
-1; i
++){
342 calc_curve_bezier(&(pts
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
346 pt
[3*i
+3].X
= pts
[i
+1].X
;
347 pt
[3*i
+3].Y
= pts
[i
+1].Y
;
352 /* points [len_pt-2] and [0] are calculated
353 separately to connect splines properly */
354 pts
[0] = points
[count
-1];
355 pts
[1] = points
[0]; /* equals to start and end of a resulting path */
358 calc_curve_bezier(pts
, tension
, &x1
, &y1
, &x2
, &y2
);
366 pt
[len_pt
-1].X
= pt
[0].X
;
367 pt
[len_pt
-1].Y
= pt
[0].Y
;
369 stat
= GdipAddPathBeziers(path
, pt
, len_pt
);
373 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
374 path
->newfigure
= TRUE
;
383 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
384 INT count
, REAL tension
)
390 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
392 if(!path
|| !points
|| count
<= 1)
393 return InvalidParameter
;
395 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
399 for(i
= 0; i
< count
; i
++){
400 ptf
[i
].X
= (REAL
)points
[i
].X
;
401 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
404 stat
= GdipAddPathClosedCurve2(path
, ptf
, count
, tension
);
411 GpStatus WINGDIPAPI
GdipAddPathCurve(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
413 TRACE("(%p, %p, %d)\n", path
, points
, count
);
415 if(!path
|| !points
|| count
<= 1)
416 return InvalidParameter
;
418 return GdipAddPathCurve2(path
, points
, count
, 1.0);
421 GpStatus WINGDIPAPI
GdipAddPathCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
423 TRACE("(%p, %p, %d)\n", path
, points
, count
);
425 if(!path
|| !points
|| count
<= 1)
426 return InvalidParameter
;
428 return GdipAddPathCurve2I(path
, points
, count
, 1.0);
431 GpStatus WINGDIPAPI
GdipAddPathCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
,
434 INT i
, len_pt
= count
*3-2;
439 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
441 if(!path
|| !points
|| count
<= 1)
442 return InvalidParameter
;
444 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
448 tension
= tension
* TENSION_CONST
;
450 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
453 pt
[0].X
= points
[0].X
;
454 pt
[0].Y
= points
[0].Y
;
458 for(i
= 0; i
< count
-2; i
++){
459 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
463 pt
[3*i
+3].X
= points
[i
+1].X
;
464 pt
[3*i
+3].Y
= points
[i
+1].Y
;
469 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
470 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
474 pt
[len_pt
-1].X
= points
[count
-1].X
;
475 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
477 stat
= GdipAddPathBeziers(path
, pt
, len_pt
);
484 GpStatus WINGDIPAPI
GdipAddPathCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
485 INT count
, REAL tension
)
491 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
493 if(!path
|| !points
|| count
<= 1)
494 return InvalidParameter
;
496 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
500 for(i
= 0; i
< count
; i
++){
501 ptf
[i
].X
= (REAL
)points
[i
].X
;
502 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
505 stat
= GdipAddPathCurve2(path
, ptf
, count
, tension
);
512 GpStatus WINGDIPAPI
GdipAddPathCurve3(GpPath
*path
, GDIPCONST GpPointF
*points
,
513 INT count
, INT offset
, INT nseg
, REAL tension
)
515 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path
, points
, count
, offset
, nseg
, tension
);
517 if(!path
|| !points
|| offset
+ 1 >= count
|| count
- offset
< nseg
+ 1)
518 return InvalidParameter
;
520 return GdipAddPathCurve2(path
, &points
[offset
], nseg
+ 1, tension
);
523 GpStatus WINGDIPAPI
GdipAddPathCurve3I(GpPath
*path
, GDIPCONST GpPoint
*points
,
524 INT count
, INT offset
, INT nseg
, REAL tension
)
526 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path
, points
, count
, offset
, nseg
, tension
);
528 if(!path
|| !points
|| offset
+ 1 >= count
|| count
- offset
< nseg
+ 1)
529 return InvalidParameter
;
531 return GdipAddPathCurve2I(path
, &points
[offset
], nseg
+ 1, tension
);
534 GpStatus WINGDIPAPI
GdipAddPathEllipse(GpPath
*path
, REAL x
, REAL y
, REAL width
,
537 INT old_count
, numpts
;
539 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
542 return InvalidParameter
;
544 if(!lengthen_path(path
, MAX_ARC_PTS
))
547 old_count
= path
->pathdata
.Count
;
548 if((numpts
= arc2polybezier(&path
->pathdata
.Points
[old_count
], x
, y
, width
,
549 height
, 0.0, 360.0)) != MAX_ARC_PTS
){
550 ERR("expected %d points but got %d\n", MAX_ARC_PTS
, numpts
);
554 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeBezier
,
557 /* An ellipse is an intrinsic figure (always is its own subpath). */
558 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
559 path
->pathdata
.Types
[old_count
+ MAX_ARC_PTS
- 1] |= PathPointTypeCloseSubpath
;
560 path
->newfigure
= TRUE
;
561 path
->pathdata
.Count
+= MAX_ARC_PTS
;
566 GpStatus WINGDIPAPI
GdipAddPathEllipseI(GpPath
*path
, INT x
, INT y
, INT width
,
569 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
571 return GdipAddPathEllipse(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
574 GpStatus WINGDIPAPI
GdipAddPathLine2(GpPath
*path
, GDIPCONST GpPointF
*points
,
579 TRACE("(%p, %p, %d)\n", path
, points
, count
);
582 return InvalidParameter
;
584 if(!lengthen_path(path
, count
))
587 old_count
= path
->pathdata
.Count
;
589 for(i
= 0; i
< count
; i
++){
590 path
->pathdata
.Points
[old_count
+ i
].X
= points
[i
].X
;
591 path
->pathdata
.Points
[old_count
+ i
].Y
= points
[i
].Y
;
592 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeLine
;
596 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
597 path
->newfigure
= FALSE
;
600 path
->pathdata
.Count
+= count
;
605 GpStatus WINGDIPAPI
GdipAddPathLine2I(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
611 TRACE("(%p, %p, %d)\n", path
, points
, count
);
614 return InvalidParameter
;
616 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
617 if(!pointsF
) return OutOfMemory
;
619 for(i
= 0;i
< count
; i
++){
620 pointsF
[i
].X
= (REAL
)points
[i
].X
;
621 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
624 stat
= GdipAddPathLine2(path
, pointsF
, count
);
631 GpStatus WINGDIPAPI
GdipAddPathLine(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
635 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x1
, y1
, x2
, y2
);
638 return InvalidParameter
;
640 if(!lengthen_path(path
, 2))
643 old_count
= path
->pathdata
.Count
;
645 path
->pathdata
.Points
[old_count
].X
= x1
;
646 path
->pathdata
.Points
[old_count
].Y
= y1
;
647 path
->pathdata
.Points
[old_count
+ 1].X
= x2
;
648 path
->pathdata
.Points
[old_count
+ 1].Y
= y2
;
650 path
->pathdata
.Types
[old_count
] =
651 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
652 path
->pathdata
.Types
[old_count
+ 1] = PathPointTypeLine
;
654 path
->newfigure
= FALSE
;
655 path
->pathdata
.Count
+= 2;
660 GpStatus WINGDIPAPI
GdipAddPathLineI(GpPath
*path
, INT x1
, INT y1
, INT x2
, INT y2
)
662 TRACE("(%p, %d, %d, %d, %d)\n", path
, x1
, y1
, x2
, y2
);
664 return GdipAddPathLine(path
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
667 GpStatus WINGDIPAPI
GdipAddPathPath(GpPath
*path
, GDIPCONST GpPath
* addingPath
,
670 INT old_count
, count
;
672 TRACE("(%p, %p, %d)\n", path
, addingPath
, connect
);
674 if(!path
|| !addingPath
)
675 return InvalidParameter
;
677 old_count
= path
->pathdata
.Count
;
678 count
= addingPath
->pathdata
.Count
;
680 if(!lengthen_path(path
, count
))
683 memcpy(&path
->pathdata
.Points
[old_count
], addingPath
->pathdata
.Points
,
684 count
* sizeof(GpPointF
));
685 memcpy(&path
->pathdata
.Types
[old_count
], addingPath
->pathdata
.Types
, count
);
687 if(path
->newfigure
|| !connect
)
688 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
690 path
->pathdata
.Types
[old_count
] = PathPointTypeLine
;
692 path
->newfigure
= FALSE
;
693 path
->pathdata
.Count
+= count
;
698 GpStatus WINGDIPAPI
GdipAddPathPie(GpPath
*path
, REAL x
, REAL y
, REAL width
, REAL height
,
699 REAL startAngle
, REAL sweepAngle
)
705 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
706 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
709 return InvalidParameter
;
711 /* on zero width/height only start point added */
712 if(width
<= 1e-7 || height
<= 1e-7){
713 if(!lengthen_path(path
, 1))
715 path
->pathdata
.Points
[0].X
= x
+ width
/ 2.0;
716 path
->pathdata
.Points
[0].Y
= y
+ height
/ 2.0;
717 path
->pathdata
.Types
[0] = PathPointTypeStart
| PathPointTypeCloseSubpath
;
718 path
->pathdata
.Count
= 1;
719 return InvalidParameter
;
722 count
= arc2polybezier(NULL
, x
, y
, width
, height
, startAngle
, sweepAngle
);
727 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
731 arc2polybezier(ptf
, x
, y
, width
, height
, startAngle
, sweepAngle
);
733 status
= GdipAddPathLine(path
, x
+ width
/2, y
+ height
/2, ptf
[0].X
, ptf
[0].Y
);
738 /* one spline is already added as a line endpoint */
739 if(!lengthen_path(path
, count
- 1)){
744 memcpy(&(path
->pathdata
.Points
[path
->pathdata
.Count
]), &(ptf
[1]),sizeof(GpPointF
)*(count
-1));
745 for(i
= 0; i
< count
-1; i
++)
746 path
->pathdata
.Types
[path
->pathdata
.Count
+i
] = PathPointTypeBezier
;
748 path
->pathdata
.Count
+= count
-1;
750 GdipClosePathFigure(path
);
757 GpStatus WINGDIPAPI
GdipAddPathPieI(GpPath
*path
, INT x
, INT y
, INT width
, INT height
,
758 REAL startAngle
, REAL sweepAngle
)
760 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
761 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
763 return GdipAddPathPie(path
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, startAngle
, sweepAngle
);
766 GpStatus WINGDIPAPI
GdipAddPathPolygon(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
770 TRACE("(%p, %p, %d)\n", path
, points
, count
);
772 if(!path
|| !points
|| count
< 3)
773 return InvalidParameter
;
775 if(!lengthen_path(path
, count
))
778 old_count
= path
->pathdata
.Count
;
780 memcpy(&path
->pathdata
.Points
[old_count
], points
, count
*sizeof(GpPointF
));
781 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeLine
, count
- 1);
783 /* A polygon is an intrinsic figure */
784 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
785 path
->pathdata
.Types
[old_count
+ count
- 1] |= PathPointTypeCloseSubpath
;
786 path
->newfigure
= TRUE
;
787 path
->pathdata
.Count
+= count
;
792 GpStatus WINGDIPAPI
GdipAddPathPolygonI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
798 TRACE("(%p, %p, %d)\n", path
, points
, count
);
800 if(!points
|| count
< 3)
801 return InvalidParameter
;
803 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
807 for(i
= 0; i
< count
; i
++){
808 ptf
[i
].X
= (REAL
)points
[i
].X
;
809 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
812 status
= GdipAddPathPolygon(path
, ptf
, count
);
819 static float fromfixedpoint(const FIXED v
)
821 float f
= ((float)v
.fract
) / (1<<(sizeof(v
.fract
)*8));
826 struct format_string_args
834 static GpStatus
format_string_callback(HDC dc
,
835 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
836 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
837 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
838 INT underlined_index_count
, void *priv
)
840 static const MAT2 identity
= { {0,1}, {0,0}, {0,0}, {0,1} };
841 struct format_string_args
*args
= priv
;
842 GpPath
*path
= args
->path
;
843 GpStatus status
= Ok
;
844 float x
= rect
->X
+ (bounds
->X
- rect
->X
) * args
->scale
;
845 float y
= rect
->Y
+ (bounds
->Y
- rect
->Y
) * args
->scale
;
848 if (underlined_index_count
)
849 FIXME("hotkey underlines not drawn yet\n");
851 if (y
+ bounds
->Height
* args
->scale
> args
->maxY
)
852 args
->maxY
= y
+ bounds
->Height
* args
->scale
;
854 for (i
= index
; i
< length
; ++i
)
857 TTPOLYGONHEADER
*ph
= NULL
;
860 len
= GetGlyphOutlineW(dc
, string
[i
], GGO_BEZIER
, &gm
, 0, NULL
, &identity
);
861 if (len
== GDI_ERROR
)
863 status
= GenericError
;
868 if (!ph
|| !lengthen_path(path
, len
/ sizeof(POINTFX
)))
870 status
= OutOfMemory
;
873 GetGlyphOutlineW(dc
, string
[i
], GGO_BEZIER
, &gm
, len
, start
, &identity
);
878 DWORD ofs_start
= ofs
;
879 ph
= (TTPOLYGONHEADER
*)&start
[ofs
];
880 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeStart
;
881 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(ph
->pfxStart
.x
) * args
->scale
;
882 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(ph
->pfxStart
.y
) * args
->scale
;
883 TRACE("Starting at count %i with pos %f, %f)\n", path
->pathdata
.Count
, x
, y
);
885 while (ofs
- ofs_start
< ph
->cb
)
887 TTPOLYCURVE
*curve
= (TTPOLYCURVE
*)&start
[ofs
];
889 ofs
+= sizeof(TTPOLYCURVE
) + (curve
->cpfx
- 1) * sizeof(POINTFX
);
891 switch (curve
->wType
)
894 for (j
= 0; j
< curve
->cpfx
; ++j
)
896 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeLine
;
897 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(curve
->apfx
[j
].x
) * args
->scale
;
898 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(curve
->apfx
[j
].y
) * args
->scale
;
901 case TT_PRIM_CSPLINE
:
902 for (j
= 0; j
< curve
->cpfx
; ++j
)
904 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeBezier
;
905 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(curve
->apfx
[j
].x
) * args
->scale
;
906 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(curve
->apfx
[j
].y
) * args
->scale
;
910 ERR("Unhandled type: %u\n", curve
->wType
);
911 status
= GenericError
;
914 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
916 path
->newfigure
= TRUE
;
917 x
+= gm
.gmCellIncX
* args
->scale
;
918 y
+= gm
.gmCellIncY
* args
->scale
;
928 GpStatus WINGDIPAPI
GdipAddPathString(GpPath
* path
, GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFontFamily
* family
, INT style
, REAL emSize
, GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
* format
)
935 GpGraphics
*graphics
;
937 struct format_string_args args
;
939 UINT16 native_height
;
940 RectF scaled_layout_rect
;
941 TEXTMETRICW textmetric
;
943 TRACE("(%p, %s, %d, %p, %d, %f, %p, %p)\n", path
, debugstr_w(string
), length
, family
, style
, emSize
, layoutRect
, format
);
944 if (!path
|| !string
|| !family
|| !emSize
|| !layoutRect
|| !format
)
945 return InvalidParameter
;
947 status
= GdipGetEmHeight(family
, style
, &native_height
);
951 scaled_layout_rect
.X
= layoutRect
->X
;
952 scaled_layout_rect
.Y
= layoutRect
->Y
;
953 scaled_layout_rect
.Width
= layoutRect
->Width
* native_height
/ emSize
;
954 scaled_layout_rect
.Height
= layoutRect
->Height
* native_height
/ emSize
;
956 if ((status
= GdipClonePath(path
, &backup
)) != Ok
)
959 dc
= CreateCompatibleDC(0);
960 status
= GdipCreateFromHDC(dc
, &graphics
);
964 GdipDeletePath(backup
);
968 status
= GdipCreateFont(family
, native_height
, style
, UnitPixel
, &font
);
971 GdipDeleteGraphics(graphics
);
973 GdipDeletePath(backup
);
977 get_log_fontW(font
, graphics
, &lfw
);
978 GdipDeleteFont(font
);
979 GdipDeleteGraphics(graphics
);
981 hfont
= CreateFontIndirectW(&lfw
);
984 WARN("Failed to create font\n");
986 GdipDeletePath(backup
);
990 SelectObject(dc
, hfont
);
992 GetTextMetricsW(dc
, &textmetric
);
996 args
.scale
= emSize
/ native_height
;
997 args
.ascent
= textmetric
.tmAscent
* args
.scale
;
998 status
= gdip_format_string(dc
, string
, length
, NULL
, &scaled_layout_rect
,
999 format
, TRUE
, format_string_callback
, &args
);
1002 DeleteObject(hfont
);
1004 if (status
!= Ok
) /* free backup */
1006 GdipFree(path
->pathdata
.Points
);
1007 GdipFree(path
->pathdata
.Types
);
1012 if (format
&& format
->vertalign
== StringAlignmentCenter
&& layoutRect
->Y
+ args
.maxY
< layoutRect
->Height
)
1014 float inc
= layoutRect
->Height
+ layoutRect
->Y
- args
.maxY
;
1016 for (i
= backup
->pathdata
.Count
; i
< path
->pathdata
.Count
; ++i
)
1017 path
->pathdata
.Points
[i
].Y
+= inc
;
1018 } else if (format
&& format
->vertalign
== StringAlignmentFar
) {
1019 float inc
= layoutRect
->Height
+ layoutRect
->Y
- args
.maxY
;
1020 for (i
= backup
->pathdata
.Count
; i
< path
->pathdata
.Count
; ++i
)
1021 path
->pathdata
.Points
[i
].Y
+= inc
;
1023 GdipDeletePath(backup
);
1027 GpStatus WINGDIPAPI
GdipAddPathStringI(GpPath
* path
, GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFontFamily
* family
, INT style
, REAL emSize
, GDIPCONST Rect
* layoutRect
, GDIPCONST GpStringFormat
* format
)
1031 RectF layoutRectF
= {
1032 (REAL
)layoutRect
->X
,
1033 (REAL
)layoutRect
->Y
,
1034 (REAL
)layoutRect
->Width
,
1035 (REAL
)layoutRect
->Height
1037 return GdipAddPathString(path
, string
, length
, family
, style
, emSize
, &layoutRectF
, format
);
1039 return InvalidParameter
;
1042 GpStatus WINGDIPAPI
GdipClonePath(GpPath
* path
, GpPath
**clone
)
1044 TRACE("(%p, %p)\n", path
, clone
);
1047 return InvalidParameter
;
1049 *clone
= GdipAlloc(sizeof(GpPath
));
1050 if(!*clone
) return OutOfMemory
;
1054 (*clone
)->pathdata
.Points
= GdipAlloc(path
->datalen
* sizeof(PointF
));
1055 (*clone
)->pathdata
.Types
= GdipAlloc(path
->datalen
);
1056 if(!(*clone
)->pathdata
.Points
|| !(*clone
)->pathdata
.Types
){
1057 GdipFree((*clone
)->pathdata
.Points
);
1058 GdipFree((*clone
)->pathdata
.Types
);
1063 memcpy((*clone
)->pathdata
.Points
, path
->pathdata
.Points
,
1064 path
->datalen
* sizeof(PointF
));
1065 memcpy((*clone
)->pathdata
.Types
, path
->pathdata
.Types
, path
->datalen
);
1070 GpStatus WINGDIPAPI
GdipClosePathFigure(GpPath
* path
)
1072 TRACE("(%p)\n", path
);
1075 return InvalidParameter
;
1077 if(path
->pathdata
.Count
> 0){
1078 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
1079 path
->newfigure
= TRUE
;
1085 GpStatus WINGDIPAPI
GdipClosePathFigures(GpPath
* path
)
1089 TRACE("(%p)\n", path
);
1092 return InvalidParameter
;
1094 for(i
= 1; i
< path
->pathdata
.Count
; i
++){
1095 if(path
->pathdata
.Types
[i
] == PathPointTypeStart
)
1096 path
->pathdata
.Types
[i
-1] |= PathPointTypeCloseSubpath
;
1099 path
->newfigure
= TRUE
;
1104 GpStatus WINGDIPAPI
GdipCreatePath(GpFillMode fill
, GpPath
**path
)
1106 TRACE("(%d, %p)\n", fill
, path
);
1109 return InvalidParameter
;
1111 *path
= GdipAlloc(sizeof(GpPath
));
1112 if(!*path
) return OutOfMemory
;
1114 (*path
)->fill
= fill
;
1115 (*path
)->newfigure
= TRUE
;
1120 GpStatus WINGDIPAPI
GdipCreatePath2(GDIPCONST GpPointF
* points
,
1121 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1123 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1126 return InvalidParameter
;
1128 *path
= GdipAlloc(sizeof(GpPath
));
1129 if(!*path
) return OutOfMemory
;
1131 (*path
)->pathdata
.Points
= GdipAlloc(count
* sizeof(PointF
));
1132 (*path
)->pathdata
.Types
= GdipAlloc(count
);
1134 if(!(*path
)->pathdata
.Points
|| !(*path
)->pathdata
.Types
){
1135 GdipFree((*path
)->pathdata
.Points
);
1136 GdipFree((*path
)->pathdata
.Types
);
1141 memcpy((*path
)->pathdata
.Points
, points
, count
* sizeof(PointF
));
1142 memcpy((*path
)->pathdata
.Types
, types
, count
);
1143 (*path
)->pathdata
.Count
= count
;
1144 (*path
)->datalen
= count
;
1146 (*path
)->fill
= fill
;
1147 (*path
)->newfigure
= TRUE
;
1152 GpStatus WINGDIPAPI
GdipCreatePath2I(GDIPCONST GpPoint
* points
,
1153 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1159 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1161 ptF
= GdipAlloc(sizeof(GpPointF
)*count
);
1163 for(i
= 0;i
< count
; i
++){
1164 ptF
[i
].X
= (REAL
)points
[i
].X
;
1165 ptF
[i
].Y
= (REAL
)points
[i
].Y
;
1168 ret
= GdipCreatePath2(ptF
, types
, count
, fill
, path
);
1175 GpStatus WINGDIPAPI
GdipDeletePath(GpPath
*path
)
1177 TRACE("(%p)\n", path
);
1180 return InvalidParameter
;
1182 GdipFree(path
->pathdata
.Points
);
1183 GdipFree(path
->pathdata
.Types
);
1189 GpStatus WINGDIPAPI
GdipFlattenPath(GpPath
*path
, GpMatrix
* matrix
, REAL flatness
)
1191 path_list_node_t
*list
, *node
;
1197 TRACE("(%p, %p, %.2f)\n", path
, matrix
, flatness
);
1200 return InvalidParameter
;
1202 if(path
->pathdata
.Count
== 0)
1206 stat
= GdipTransformPath(path
, matrix
);
1211 pt
= path
->pathdata
.Points
[0];
1212 if(!init_path_list(&list
, pt
.X
, pt
.Y
))
1217 while(i
< path
->pathdata
.Count
){
1219 BYTE type
= path
->pathdata
.Types
[i
] & PathPointTypePathTypeMask
;
1220 path_list_node_t
*start
;
1222 pt
= path
->pathdata
.Points
[i
];
1224 /* save last start point index */
1225 if(type
== PathPointTypeStart
)
1228 /* always add line points and start points */
1229 if((type
== PathPointTypeStart
) || (type
== PathPointTypeLine
)){
1230 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, path
->pathdata
.Types
[i
]))
1240 /* test for closed figure */
1241 if(path
->pathdata
.Types
[i
+1] & PathPointTypeCloseSubpath
){
1242 pt
= path
->pathdata
.Points
[startidx
];
1248 pt
= path
->pathdata
.Points
[i
];
1252 /* add Bezier end point */
1253 type
= (path
->pathdata
.Types
[i
] & ~PathPointTypePathTypeMask
) | PathPointTypeLine
;
1254 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, type
))
1259 if(!flatten_bezier(start
, path
->pathdata
.Points
[i
-2].X
, path
->pathdata
.Points
[i
-2].Y
,
1260 path
->pathdata
.Points
[i
-1].X
, path
->pathdata
.Points
[i
-1].Y
,
1267 /* store path data back */
1268 i
= path_list_count(list
);
1269 if(!lengthen_path(path
, i
))
1271 path
->pathdata
.Count
= i
;
1274 for(i
= 0; i
< path
->pathdata
.Count
; i
++){
1275 path
->pathdata
.Points
[i
] = node
->pt
;
1276 path
->pathdata
.Types
[i
] = node
->type
;
1280 free_path_list(list
);
1284 free_path_list(list
);
1288 GpStatus WINGDIPAPI
GdipGetPathData(GpPath
*path
, GpPathData
* pathData
)
1290 TRACE("(%p, %p)\n", path
, pathData
);
1292 if(!path
|| !pathData
)
1293 return InvalidParameter
;
1295 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
1296 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
1297 memcpy(pathData
->Points
, path
->pathdata
.Points
, sizeof(PointF
) * pathData
->Count
);
1298 memcpy(pathData
->Types
, path
->pathdata
.Types
, pathData
->Count
);
1303 GpStatus WINGDIPAPI
GdipGetPathFillMode(GpPath
*path
, GpFillMode
*fillmode
)
1305 TRACE("(%p, %p)\n", path
, fillmode
);
1307 if(!path
|| !fillmode
)
1308 return InvalidParameter
;
1310 *fillmode
= path
->fill
;
1315 GpStatus WINGDIPAPI
GdipGetPathLastPoint(GpPath
* path
, GpPointF
* lastPoint
)
1319 TRACE("(%p, %p)\n", path
, lastPoint
);
1321 if(!path
|| !lastPoint
)
1322 return InvalidParameter
;
1324 count
= path
->pathdata
.Count
;
1326 *lastPoint
= path
->pathdata
.Points
[count
-1];
1331 GpStatus WINGDIPAPI
GdipGetPathPoints(GpPath
*path
, GpPointF
* points
, INT count
)
1333 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1336 return InvalidParameter
;
1338 if(count
< path
->pathdata
.Count
)
1339 return InsufficientBuffer
;
1341 memcpy(points
, path
->pathdata
.Points
, path
->pathdata
.Count
* sizeof(GpPointF
));
1346 GpStatus WINGDIPAPI
GdipGetPathPointsI(GpPath
*path
, GpPoint
* points
, INT count
)
1352 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1355 return InvalidParameter
;
1357 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1358 if(!ptf
) return OutOfMemory
;
1360 ret
= GdipGetPathPoints(path
,ptf
,count
);
1362 for(i
= 0;i
< count
;i
++){
1363 points
[i
].X
= gdip_round(ptf
[i
].X
);
1364 points
[i
].Y
= gdip_round(ptf
[i
].Y
);
1371 GpStatus WINGDIPAPI
GdipGetPathTypes(GpPath
*path
, BYTE
* types
, INT count
)
1373 TRACE("(%p, %p, %d)\n", path
, types
, count
);
1376 return InvalidParameter
;
1378 if(count
< path
->pathdata
.Count
)
1379 return InsufficientBuffer
;
1381 memcpy(types
, path
->pathdata
.Types
, path
->pathdata
.Count
);
1386 /* Windows expands the bounding box to the maximum possible bounding box
1387 * for a given pen. For example, if a line join can extend past the point
1388 * it's joining by x units, the bounding box is extended by x units in every
1389 * direction (even though this is too conservative for most cases). */
1390 GpStatus WINGDIPAPI
GdipGetPathWorldBounds(GpPath
* path
, GpRectF
* bounds
,
1391 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1393 GpPointF
* points
, temp_pts
[4];
1395 REAL path_width
= 1.0, width
, height
, temp
, low_x
, low_y
, high_x
, high_y
;
1397 TRACE("(%p, %p, %p, %p)\n", path
, bounds
, matrix
, pen
);
1399 /* Matrix and pen can be null. */
1400 if(!path
|| !bounds
)
1401 return InvalidParameter
;
1403 /* If path is empty just return. */
1404 count
= path
->pathdata
.Count
;
1406 bounds
->X
= bounds
->Y
= bounds
->Width
= bounds
->Height
= 0.0;
1410 points
= path
->pathdata
.Points
;
1412 low_x
= high_x
= points
[0].X
;
1413 low_y
= high_y
= points
[0].Y
;
1415 for(i
= 1; i
< count
; i
++){
1416 low_x
= min(low_x
, points
[i
].X
);
1417 low_y
= min(low_y
, points
[i
].Y
);
1418 high_x
= max(high_x
, points
[i
].X
);
1419 high_y
= max(high_y
, points
[i
].Y
);
1422 width
= high_x
- low_x
;
1423 height
= high_y
- low_y
;
1425 /* This looks unusual but it's the only way I can imitate windows. */
1427 temp_pts
[0].X
= low_x
;
1428 temp_pts
[0].Y
= low_y
;
1429 temp_pts
[1].X
= low_x
;
1430 temp_pts
[1].Y
= high_y
;
1431 temp_pts
[2].X
= high_x
;
1432 temp_pts
[2].Y
= high_y
;
1433 temp_pts
[3].X
= high_x
;
1434 temp_pts
[3].Y
= low_y
;
1436 GdipTransformMatrixPoints((GpMatrix
*)matrix
, temp_pts
, 4);
1437 low_x
= temp_pts
[0].X
;
1438 low_y
= temp_pts
[0].Y
;
1440 for(i
= 1; i
< 4; i
++){
1441 low_x
= min(low_x
, temp_pts
[i
].X
);
1442 low_y
= min(low_y
, temp_pts
[i
].Y
);
1446 width
= height
* fabs(matrix
->matrix
[2]) + width
* fabs(matrix
->matrix
[0]);
1447 height
= height
* fabs(matrix
->matrix
[3]) + temp
* fabs(matrix
->matrix
[1]);
1451 path_width
= pen
->width
/ 2.0;
1454 path_width
= max(path_width
, pen
->width
* pen
->miterlimit
/ 2.0);
1455 /* FIXME: this should probably also check for the startcap */
1456 if(pen
->endcap
& LineCapNoAnchor
)
1457 path_width
= max(path_width
, pen
->width
* 2.2);
1459 low_x
-= path_width
;
1460 low_y
-= path_width
;
1461 width
+= 2.0 * path_width
;
1462 height
+= 2.0 * path_width
;
1467 bounds
->Width
= width
;
1468 bounds
->Height
= height
;
1473 GpStatus WINGDIPAPI
GdipGetPathWorldBoundsI(GpPath
* path
, GpRect
* bounds
,
1474 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1479 TRACE("(%p, %p, %p, %p)\n", path
, bounds
, matrix
, pen
);
1481 ret
= GdipGetPathWorldBounds(path
,&boundsF
,matrix
,pen
);
1484 bounds
->X
= gdip_round(boundsF
.X
);
1485 bounds
->Y
= gdip_round(boundsF
.Y
);
1486 bounds
->Width
= gdip_round(boundsF
.Width
);
1487 bounds
->Height
= gdip_round(boundsF
.Height
);
1493 GpStatus WINGDIPAPI
GdipGetPointCount(GpPath
*path
, INT
*count
)
1495 TRACE("(%p, %p)\n", path
, count
);
1498 return InvalidParameter
;
1500 *count
= path
->pathdata
.Count
;
1505 GpStatus WINGDIPAPI
GdipReversePath(GpPath
* path
)
1508 INT start
= 0; /* position in reversed path */
1511 TRACE("(%p)\n", path
);
1514 return InvalidParameter
;
1516 count
= path
->pathdata
.Count
;
1518 if(count
== 0) return Ok
;
1520 revpath
.Points
= GdipAlloc(sizeof(GpPointF
)*count
);
1521 revpath
.Types
= GdipAlloc(sizeof(BYTE
)*count
);
1522 revpath
.Count
= count
;
1523 if(!revpath
.Points
|| !revpath
.Types
){
1524 GdipFree(revpath
.Points
);
1525 GdipFree(revpath
.Types
);
1529 for(i
= 0; i
< count
; i
++){
1531 /* find next start point */
1532 if(path
->pathdata
.Types
[count
-i
-1] == PathPointTypeStart
){
1534 for(j
= start
; j
<= i
; j
++){
1535 revpath
.Points
[j
] = path
->pathdata
.Points
[count
-j
-1];
1536 revpath
.Types
[j
] = path
->pathdata
.Types
[count
-j
-1];
1538 /* mark start point */
1539 revpath
.Types
[start
] = PathPointTypeStart
;
1540 /* set 'figure' endpoint type */
1542 revpath
.Types
[i
] = path
->pathdata
.Types
[count
-start
-1] & ~PathPointTypePathTypeMask
;
1543 revpath
.Types
[i
] |= revpath
.Types
[i
-1];
1546 revpath
.Types
[i
] = path
->pathdata
.Types
[start
];
1552 memcpy(path
->pathdata
.Points
, revpath
.Points
, sizeof(GpPointF
)*count
);
1553 memcpy(path
->pathdata
.Types
, revpath
.Types
, sizeof(BYTE
)*count
);
1555 GdipFree(revpath
.Points
);
1556 GdipFree(revpath
.Types
);
1561 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPointI(GpPath
* path
, INT x
, INT y
,
1562 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1564 TRACE("(%p, %d, %d, %p, %p, %p)\n", path
, x
, y
, pen
, graphics
, result
);
1566 return GdipIsOutlineVisiblePathPoint(path
, x
, y
, pen
, graphics
, result
);
1569 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
,
1570 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1574 TRACE("(%p,%0.2f,%0.2f,%p,%p,%p)\n", path
, x
, y
, pen
, graphics
, result
);
1577 return InvalidParameter
;
1580 FIXME("not implemented\n");
1582 return NotImplemented
;
1585 GpStatus WINGDIPAPI
GdipIsVisiblePathPointI(GpPath
* path
, INT x
, INT y
, GpGraphics
*graphics
, BOOL
*result
)
1587 TRACE("(%p, %d, %d, %p, %p)\n", path
, x
, y
, graphics
, result
);
1589 return GdipIsVisiblePathPoint(path
, x
, y
, graphics
, result
);
1592 /*****************************************************************************
1593 * GdipIsVisiblePathPoint [GDIPLUS.@]
1595 GpStatus WINGDIPAPI
GdipIsVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
, GpGraphics
*graphics
, BOOL
*result
)
1601 if(!path
|| !result
) return InvalidParameter
;
1603 status
= GdipCreateRegionPath(path
, ®ion
);
1607 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
1609 GdipDeleteRegion(region
);
1613 *result
= PtInRegion(hrgn
, gdip_round(x
), gdip_round(y
));
1616 GdipDeleteRegion(region
);
1621 GpStatus WINGDIPAPI
GdipStartPathFigure(GpPath
*path
)
1623 TRACE("(%p)\n", path
);
1626 return InvalidParameter
;
1628 path
->newfigure
= TRUE
;
1633 GpStatus WINGDIPAPI
GdipResetPath(GpPath
*path
)
1635 TRACE("(%p)\n", path
);
1638 return InvalidParameter
;
1640 path
->pathdata
.Count
= 0;
1641 path
->newfigure
= TRUE
;
1642 path
->fill
= FillModeAlternate
;
1647 GpStatus WINGDIPAPI
GdipSetPathFillMode(GpPath
*path
, GpFillMode fill
)
1649 TRACE("(%p, %d)\n", path
, fill
);
1652 return InvalidParameter
;
1659 GpStatus WINGDIPAPI
GdipTransformPath(GpPath
*path
, GpMatrix
*matrix
)
1661 TRACE("(%p, %p)\n", path
, matrix
);
1664 return InvalidParameter
;
1666 if(path
->pathdata
.Count
== 0)
1669 return GdipTransformMatrixPoints(matrix
, path
->pathdata
.Points
,
1670 path
->pathdata
.Count
);
1673 GpStatus WINGDIPAPI
GdipWarpPath(GpPath
*path
, GpMatrix
* matrix
,
1674 GDIPCONST GpPointF
*points
, INT count
, REAL x
, REAL y
, REAL width
,
1675 REAL height
, WarpMode warpmode
, REAL flatness
)
1677 FIXME("(%p,%p,%p,%i,%0.2f,%0.2f,%0.2f,%0.2f,%i,%0.2f)\n", path
, matrix
,
1678 points
, count
, x
, y
, width
, height
, warpmode
, flatness
);
1680 return NotImplemented
;
1683 static void add_bevel_point(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1684 GpPen
*pen
, int right_side
, path_list_node_t
**last_point
)
1686 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1687 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1688 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1689 REAL distance
= pen
->width
/2.0;
1690 REAL bevel_dx
, bevel_dy
;
1692 if (segment_length
== 0.0)
1694 *last_point
= add_path_list_node(*last_point
, endpoint
->X
,
1695 endpoint
->Y
, PathPointTypeLine
);
1701 bevel_dx
= -distance
* segment_dy
/ segment_length
;
1702 bevel_dy
= distance
* segment_dx
/ segment_length
;
1706 bevel_dx
= distance
* segment_dy
/ segment_length
;
1707 bevel_dy
= -distance
* segment_dx
/ segment_length
;
1710 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ bevel_dx
,
1711 endpoint
->Y
+ bevel_dy
, PathPointTypeLine
);
1714 static void widen_joint(const GpPointF
*p1
, const GpPointF
*p2
, const GpPointF
*p3
,
1715 GpPen
* pen
, path_list_node_t
**last_point
)
1720 case LineJoinMiterClipped
:
1721 if ((p2
->X
- p1
->X
) * (p3
->Y
- p1
->Y
) > (p2
->Y
- p1
->Y
) * (p3
->X
- p1
->X
))
1723 float distance
= pen
->width
/2.0;
1724 float length_0
= sqrtf((p2
->X
-p1
->X
)*(p2
->X
-p1
->X
)+(p2
->Y
-p1
->Y
)*(p2
->Y
-p1
->Y
));
1725 float length_1
= sqrtf((p3
->X
-p2
->X
)*(p3
->X
-p2
->X
)+(p3
->Y
-p2
->Y
)*(p3
->Y
-p2
->Y
));
1726 float dx0
= distance
* (p2
->X
- p1
->X
) / length_0
;
1727 float dy0
= distance
* (p2
->Y
- p1
->Y
) / length_0
;
1728 float dx1
= distance
* (p3
->X
- p2
->X
) / length_1
;
1729 float dy1
= distance
* (p3
->Y
- p2
->Y
) / length_1
;
1730 float det
= (dy0
*dx1
- dx0
*dy1
);
1731 float dx
= (dx0
*dx1
*(dx0
-dx1
) + dy0
*dy0
*dx1
- dy1
*dy1
*dx0
)/det
;
1732 float dy
= (dy0
*dy1
*(dy0
-dy1
) + dx0
*dx0
*dy1
- dx1
*dx1
*dy0
)/det
;
1733 if (dx
*dx
+ dy
*dy
< pen
->miterlimit
*pen
->miterlimit
* distance
*distance
)
1735 *last_point
= add_path_list_node(*last_point
, p2
->X
+ dx
,
1736 p2
->Y
+ dy
, PathPointTypeLine
);
1739 else if (pen
->join
== LineJoinMiter
)
1743 FIXME("should add a clipped corner\n");
1745 /* else fall-through */
1747 /* else fall-through */
1750 add_bevel_point(p2
, p1
, pen
, 1, last_point
);
1751 add_bevel_point(p2
, p3
, pen
, 0, last_point
);
1756 static void widen_cap(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1757 GpPen
*pen
, GpLineCap cap
, GpCustomLineCap
*custom
, int add_first_points
,
1758 int add_last_point
, path_list_node_t
**last_point
)
1764 if (add_first_points
)
1765 add_bevel_point(endpoint
, nextpoint
, pen
, 1, last_point
);
1767 add_bevel_point(endpoint
, nextpoint
, pen
, 0, last_point
);
1771 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1772 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1773 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1774 REAL distance
= pen
->width
/2.0;
1775 REAL bevel_dx
, bevel_dy
;
1776 REAL extend_dx
, extend_dy
;
1778 extend_dx
= -distance
* segment_dx
/ segment_length
;
1779 extend_dy
= -distance
* segment_dy
/ segment_length
;
1781 bevel_dx
= -distance
* segment_dy
/ segment_length
;
1782 bevel_dy
= distance
* segment_dx
/ segment_length
;
1784 if (add_first_points
)
1785 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ extend_dx
+ bevel_dx
,
1786 endpoint
->Y
+ extend_dy
+ bevel_dy
, PathPointTypeLine
);
1789 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ extend_dx
- bevel_dx
,
1790 endpoint
->Y
+ extend_dy
- bevel_dy
, PathPointTypeLine
);
1796 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1797 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1798 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1799 REAL distance
= pen
->width
/2.0;
1800 REAL dx
, dy
, dx2
, dy2
;
1801 const REAL control_point_distance
= 0.5522847498307935; /* 4/3 * (sqrt(2) - 1) */
1803 if (add_first_points
)
1805 dx
= -distance
* segment_dx
/ segment_length
;
1806 dy
= -distance
* segment_dy
/ segment_length
;
1808 dx2
= dx
* control_point_distance
;
1809 dy2
= dy
* control_point_distance
;
1811 /* first 90-degree arc */
1812 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
1813 endpoint
->Y
- dx
, PathPointTypeLine
);
1815 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
+ dx2
,
1816 endpoint
->Y
- dx
+ dy2
, PathPointTypeBezier
);
1818 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
+ dy2
,
1819 endpoint
->Y
+ dy
- dx2
, PathPointTypeBezier
);
1822 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
,
1823 endpoint
->Y
+ dy
, PathPointTypeBezier
);
1825 /* second 90-degree arc */
1826 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
- dy2
,
1827 endpoint
->Y
+ dy
+ dx2
, PathPointTypeBezier
);
1829 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
+ dx2
,
1830 endpoint
->Y
+ dx
+ dy2
, PathPointTypeBezier
);
1832 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
,
1833 endpoint
->Y
+ dx
, PathPointTypeBezier
);
1840 static void widen_open_figure(GpPath
*path
, GpPen
*pen
, int start
, int end
,
1841 path_list_node_t
**last_point
)
1844 path_list_node_t
*prev_point
;
1849 prev_point
= *last_point
;
1851 widen_cap(&path
->pathdata
.Points
[start
], &path
->pathdata
.Points
[start
+1],
1852 pen
, pen
->startcap
, pen
->customstart
, FALSE
, TRUE
, last_point
);
1854 for (i
=start
+1; i
<end
; i
++)
1855 widen_joint(&path
->pathdata
.Points
[i
-1], &path
->pathdata
.Points
[i
],
1856 &path
->pathdata
.Points
[i
+1], pen
, last_point
);
1858 widen_cap(&path
->pathdata
.Points
[end
], &path
->pathdata
.Points
[end
-1],
1859 pen
, pen
->endcap
, pen
->customend
, TRUE
, TRUE
, last_point
);
1861 for (i
=end
-1; i
>start
; i
--)
1862 widen_joint(&path
->pathdata
.Points
[i
+1], &path
->pathdata
.Points
[i
],
1863 &path
->pathdata
.Points
[i
-1], pen
, last_point
);
1865 widen_cap(&path
->pathdata
.Points
[start
], &path
->pathdata
.Points
[start
+1],
1866 pen
, pen
->startcap
, pen
->customstart
, TRUE
, FALSE
, last_point
);
1868 prev_point
->next
->type
= PathPointTypeStart
;
1869 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
1872 static void widen_closed_figure(GpPath
*path
, GpPen
*pen
, int start
, int end
,
1873 path_list_node_t
**last_point
)
1876 path_list_node_t
*prev_point
;
1882 prev_point
= *last_point
;
1884 widen_joint(&path
->pathdata
.Points
[end
], &path
->pathdata
.Points
[start
],
1885 &path
->pathdata
.Points
[start
+1], pen
, last_point
);
1887 for (i
=start
+1; i
<end
; i
++)
1888 widen_joint(&path
->pathdata
.Points
[i
-1], &path
->pathdata
.Points
[i
],
1889 &path
->pathdata
.Points
[i
+1], pen
, last_point
);
1891 widen_joint(&path
->pathdata
.Points
[end
-1], &path
->pathdata
.Points
[end
],
1892 &path
->pathdata
.Points
[start
], pen
, last_point
);
1894 prev_point
->next
->type
= PathPointTypeStart
;
1895 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
1898 prev_point
= *last_point
;
1900 widen_joint(&path
->pathdata
.Points
[start
], &path
->pathdata
.Points
[end
],
1901 &path
->pathdata
.Points
[end
-1], pen
, last_point
);
1903 for (i
=end
-1; i
>start
; i
--)
1904 widen_joint(&path
->pathdata
.Points
[i
+1], &path
->pathdata
.Points
[i
],
1905 &path
->pathdata
.Points
[i
-1], pen
, last_point
);
1907 widen_joint(&path
->pathdata
.Points
[start
+1], &path
->pathdata
.Points
[start
],
1908 &path
->pathdata
.Points
[end
], pen
, last_point
);
1910 prev_point
->next
->type
= PathPointTypeStart
;
1911 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
1914 GpStatus WINGDIPAPI
GdipWidenPath(GpPath
*path
, GpPen
*pen
, GpMatrix
*matrix
,
1917 GpPath
*flat_path
=NULL
;
1919 path_list_node_t
*points
=NULL
, *last_point
=NULL
;
1920 int i
, subpath_start
=0, new_length
;
1923 TRACE("(%p,%p,%p,%0.2f)\n", path
, pen
, matrix
, flatness
);
1926 return InvalidParameter
;
1928 if (path
->pathdata
.Count
<= 1)
1931 status
= GdipClonePath(path
, &flat_path
);
1934 status
= GdipFlattenPath(flat_path
, matrix
, flatness
);
1936 if (status
== Ok
&& !init_path_list(&points
, 314.0, 22.0))
1937 status
= OutOfMemory
;
1941 last_point
= points
;
1943 if (pen
->endcap
> LineCapRound
)
1944 FIXME("unimplemented end cap %x\n", pen
->endcap
);
1946 if (pen
->startcap
> LineCapRound
)
1947 FIXME("unimplemented start cap %x\n", pen
->startcap
);
1949 if (pen
->dashcap
!= DashCapFlat
)
1950 FIXME("unimplemented dash cap %d\n", pen
->dashcap
);
1952 if (pen
->join
== LineJoinRound
)
1953 FIXME("unimplemented line join %d\n", pen
->join
);
1955 if (pen
->dash
!= DashStyleSolid
)
1956 FIXME("unimplemented dash style %d\n", pen
->dash
);
1958 if (pen
->align
!= PenAlignmentCenter
)
1959 FIXME("unimplemented pen alignment %d\n", pen
->align
);
1961 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
1963 type
= flat_path
->pathdata
.Types
[i
];
1965 if ((type
&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1968 if ((type
&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
1970 widen_closed_figure(flat_path
, pen
, subpath_start
, i
, &last_point
);
1972 else if (i
== flat_path
->pathdata
.Count
-1 ||
1973 (flat_path
->pathdata
.Types
[i
+1]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
1975 widen_open_figure(flat_path
, pen
, subpath_start
, i
, &last_point
);
1979 new_length
= path_list_count(points
)-1;
1981 if (!lengthen_path(path
, new_length
))
1982 status
= OutOfMemory
;
1987 path
->pathdata
.Count
= new_length
;
1989 last_point
= points
->next
;
1990 for (i
= 0; i
< new_length
; i
++)
1992 path
->pathdata
.Points
[i
] = last_point
->pt
;
1993 path
->pathdata
.Types
[i
] = last_point
->type
;
1994 last_point
= last_point
->next
;
1997 path
->fill
= FillModeWinding
;
2000 free_path_list(points
);
2002 GdipDeletePath(flat_path
);
2007 GpStatus WINGDIPAPI
GdipAddPathRectangle(GpPath
*path
, REAL x
, REAL y
,
2008 REAL width
, REAL height
)
2015 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
2018 return InvalidParameter
;
2020 /* make a backup copy of path data */
2021 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2024 /* rectangle should start as new path */
2025 old_new
= path
->newfigure
;
2026 path
->newfigure
= TRUE
;
2027 if((retstat
= GdipAddPathLine(path
,x
,y
,x
+width
,y
)) != Ok
){
2028 path
->newfigure
= old_new
;
2033 ptf
[0].Y
= y
+height
;
2035 ptf
[1].Y
= y
+height
;
2037 if((retstat
= GdipAddPathLine2(path
, ptf
, 2)) != Ok
) goto fail
;
2038 path
->pathdata
.Types
[path
->pathdata
.Count
-1] |= PathPointTypeCloseSubpath
;
2041 GdipDeletePath(backup
);
2046 GdipFree(path
->pathdata
.Points
);
2047 GdipFree(path
->pathdata
.Types
);
2048 memcpy(path
, backup
, sizeof(*path
));
2054 GpStatus WINGDIPAPI
GdipAddPathRectangleI(GpPath
*path
, INT x
, INT y
,
2055 INT width
, INT height
)
2057 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
2059 return GdipAddPathRectangle(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2062 GpStatus WINGDIPAPI
GdipAddPathRectangles(GpPath
*path
, GDIPCONST GpRectF
*rects
, INT count
)
2068 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2070 /* count == 0 - verified condition */
2071 if(!path
|| !rects
|| count
== 0)
2072 return InvalidParameter
;
2077 /* make a backup copy */
2078 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2081 for(i
= 0; i
< count
; i
++){
2082 if((retstat
= GdipAddPathRectangle(path
,rects
[i
].X
,rects
[i
].Y
,rects
[i
].Width
,rects
[i
].Height
)) != Ok
)
2087 GdipDeletePath(backup
);
2092 GdipFree(path
->pathdata
.Points
);
2093 GdipFree(path
->pathdata
.Types
);
2094 memcpy(path
, backup
, sizeof(*path
));
2100 GpStatus WINGDIPAPI
GdipAddPathRectanglesI(GpPath
*path
, GDIPCONST GpRect
*rects
, INT count
)
2106 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2108 if(!rects
|| count
== 0)
2109 return InvalidParameter
;
2114 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
2116 for(i
= 0;i
< count
;i
++){
2117 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2118 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2119 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2120 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2123 retstat
= GdipAddPathRectangles(path
, rectsF
, count
);
2129 GpStatus WINGDIPAPI
GdipSetPathMarker(GpPath
* path
)
2133 TRACE("(%p)\n", path
);
2136 return InvalidParameter
;
2138 count
= path
->pathdata
.Count
;
2140 /* set marker flag */
2142 path
->pathdata
.Types
[count
-1] |= PathPointTypePathMarker
;
2147 GpStatus WINGDIPAPI
GdipClearPathMarkers(GpPath
* path
)
2152 TRACE("(%p)\n", path
);
2155 return InvalidParameter
;
2157 count
= path
->pathdata
.Count
;
2159 for(i
= 0; i
< count
- 1; i
++){
2160 path
->pathdata
.Types
[i
] &= ~PathPointTypePathMarker
;
2166 GpStatus WINGDIPAPI
GdipWindingModeOutline(GpPath
*path
, GpMatrix
*matrix
, REAL flatness
)
2168 FIXME("stub: %p, %p, %.2f\n", path
, matrix
, flatness
);
2169 return NotImplemented
;