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 /* GdipAddPath* helper
171 * Several GdipAddPath functions are expected to add onto an open figure.
172 * So if the first point being added is an exact match to the last point
173 * of the existing line, that point should not be added.
176 * path : path to which points should be added
177 * points : array of points to add
178 * count : number of points to add (at least 1)
179 * type : type of the points being added
182 * OutOfMemory : out of memory, could not lengthen path
185 static GpStatus
extend_current_figure(GpPath
*path
, GDIPCONST PointF
*points
, INT count
, BYTE type
)
187 INT insert_index
= path
->pathdata
.Count
;
188 BYTE first_point_type
= (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
190 if(!path
->newfigure
&&
191 path
->pathdata
.Points
[insert_index
-1].X
== points
[0].X
&&
192 path
->pathdata
.Points
[insert_index
-1].Y
== points
[0].Y
)
196 first_point_type
= type
;
202 if(!lengthen_path(path
, count
))
205 memcpy(path
->pathdata
.Points
+ insert_index
, points
, sizeof(GpPointF
)*count
);
206 path
->pathdata
.Types
[insert_index
] = first_point_type
;
207 memset(path
->pathdata
.Types
+ insert_index
+ 1, type
, count
- 1);
209 path
->newfigure
= FALSE
;
210 path
->pathdata
.Count
+= count
;
215 /*******************************************************************************
216 * GdipAddPathArc [GDIPLUS.1]
218 * Add an elliptical arc to the given path.
221 * path [I/O] Path that the arc is appended to
222 * x1 [I] X coordinate of the boundary box
223 * y1 [I] Y coordinate of the boundary box
224 * x2 [I] Width of the boundary box
225 * y2 [I] Height of the boundary box
226 * startAngle [I] Starting angle of the arc, clockwise
227 * sweepAngle [I] Angle of the arc, clockwise
230 * InvalidParameter If the given path is invalid
231 * OutOfMemory If memory allocation fails, i.e. the path cannot be lengthened
232 * Ok If everything works out as expected
235 * This functions takes the newfigure value of the given path into account,
236 * i.e. the arc is connected to the end of the given path if it was set to
237 * FALSE, otherwise the arc's first point gets the PathPointTypeStart value.
238 * In both cases, the value of newfigure of the given path is FALSE
241 GpStatus WINGDIPAPI
GdipAddPathArc(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
242 REAL y2
, REAL startAngle
, REAL sweepAngle
)
248 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
249 path
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
252 return InvalidParameter
;
254 count
= arc2polybezier(NULL
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
258 points
= heap_alloc_zero(sizeof(GpPointF
)*count
);
262 arc2polybezier(points
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
264 status
= extend_current_figure(path
, points
, count
, PathPointTypeBezier
);
270 /*******************************************************************************
271 * GdipAddPathArcI [GDUPLUS.2]
275 GpStatus WINGDIPAPI
GdipAddPathArcI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
276 INT y2
, REAL startAngle
, REAL sweepAngle
)
278 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
279 path
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
281 return GdipAddPathArc(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,startAngle
,sweepAngle
);
284 GpStatus WINGDIPAPI
GdipAddPathBezier(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
285 REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
289 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
290 path
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
293 return InvalidParameter
;
304 return extend_current_figure(path
, points
, 4, PathPointTypeBezier
);
307 GpStatus WINGDIPAPI
GdipAddPathBezierI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
308 INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
310 TRACE("(%p, %d, %d, %d, %d, %d, %d, %d, %d)\n",
311 path
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
313 return GdipAddPathBezier(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,(REAL
)x3
,(REAL
)y3
,
317 GpStatus WINGDIPAPI
GdipAddPathBeziers(GpPath
*path
, GDIPCONST GpPointF
*points
,
320 TRACE("(%p, %p, %d)\n", path
, points
, count
);
322 if(!path
|| !points
|| ((count
- 1) % 3))
323 return InvalidParameter
;
325 return extend_current_figure(path
, points
, count
, PathPointTypeBezier
);
328 GpStatus WINGDIPAPI
GdipAddPathBeziersI(GpPath
*path
, GDIPCONST GpPoint
*points
,
335 TRACE("(%p, %p, %d)\n", path
, points
, count
);
337 if(!points
|| ((count
- 1) % 3))
338 return InvalidParameter
;
340 ptsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
344 for(i
= 0; i
< count
; i
++){
345 ptsF
[i
].X
= (REAL
)points
[i
].X
;
346 ptsF
[i
].Y
= (REAL
)points
[i
].Y
;
349 ret
= GdipAddPathBeziers(path
, ptsF
, count
);
355 GpStatus WINGDIPAPI
GdipAddPathClosedCurve(GpPath
*path
, GDIPCONST GpPointF
*points
,
358 TRACE("(%p, %p, %d)\n", path
, points
, count
);
360 return GdipAddPathClosedCurve2(path
, points
, count
, 1.0);
363 GpStatus WINGDIPAPI
GdipAddPathClosedCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
,
366 TRACE("(%p, %p, %d)\n", path
, points
, count
);
368 return GdipAddPathClosedCurve2I(path
, points
, count
, 1.0);
371 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
,
372 INT count
, REAL tension
)
374 INT i
, len_pt
= (count
+ 1)*3-2;
380 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
382 if(!path
|| !points
|| count
<= 1)
383 return InvalidParameter
;
385 pt
= heap_alloc_zero(len_pt
* sizeof(GpPointF
));
386 pts
= heap_alloc_zero((count
+ 1)*sizeof(GpPointF
));
393 /* copy source points to extend with the last one */
394 memcpy(pts
, points
, sizeof(GpPointF
)*count
);
397 tension
= tension
* TENSION_CONST
;
399 for(i
= 0; i
< count
-1; i
++){
400 calc_curve_bezier(&(pts
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
404 pt
[3*i
+3].X
= pts
[i
+1].X
;
405 pt
[3*i
+3].Y
= pts
[i
+1].Y
;
410 /* points [len_pt-2] and [0] are calculated
411 separately to connect splines properly */
412 pts
[0] = points
[count
-1];
413 pts
[1] = points
[0]; /* equals to start and end of a resulting path */
416 calc_curve_bezier(pts
, tension
, &x1
, &y1
, &x2
, &y2
);
424 pt
[len_pt
-1].X
= pt
[0].X
;
425 pt
[len_pt
-1].Y
= pt
[0].Y
;
427 stat
= extend_current_figure(path
, pt
, len_pt
, PathPointTypeBezier
);
431 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
432 path
->newfigure
= TRUE
;
441 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
442 INT count
, REAL tension
)
448 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
450 if(!path
|| !points
|| count
<= 1)
451 return InvalidParameter
;
453 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
457 for(i
= 0; i
< count
; i
++){
458 ptf
[i
].X
= (REAL
)points
[i
].X
;
459 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
462 stat
= GdipAddPathClosedCurve2(path
, ptf
, count
, tension
);
469 GpStatus WINGDIPAPI
GdipAddPathCurve(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
471 TRACE("(%p, %p, %d)\n", path
, points
, count
);
473 if(!path
|| !points
|| count
<= 1)
474 return InvalidParameter
;
476 return GdipAddPathCurve2(path
, points
, count
, 1.0);
479 GpStatus WINGDIPAPI
GdipAddPathCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
481 TRACE("(%p, %p, %d)\n", path
, points
, count
);
483 if(!path
|| !points
|| count
<= 1)
484 return InvalidParameter
;
486 return GdipAddPathCurve2I(path
, points
, count
, 1.0);
489 GpStatus WINGDIPAPI
GdipAddPathCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
,
492 INT i
, len_pt
= count
*3-2;
497 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
499 if(!path
|| !points
|| count
<= 1)
500 return InvalidParameter
;
502 pt
= heap_alloc_zero(len_pt
* sizeof(GpPointF
));
506 tension
= tension
* TENSION_CONST
;
508 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
511 pt
[0].X
= points
[0].X
;
512 pt
[0].Y
= points
[0].Y
;
516 for(i
= 0; i
< count
-2; i
++){
517 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
521 pt
[3*i
+3].X
= points
[i
+1].X
;
522 pt
[3*i
+3].Y
= points
[i
+1].Y
;
527 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
528 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
532 pt
[len_pt
-1].X
= points
[count
-1].X
;
533 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
535 stat
= extend_current_figure(path
, pt
, len_pt
, PathPointTypeBezier
);
542 GpStatus WINGDIPAPI
GdipAddPathCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
543 INT count
, REAL tension
)
549 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
551 if(!path
|| !points
|| count
<= 1)
552 return InvalidParameter
;
554 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
558 for(i
= 0; i
< count
; i
++){
559 ptf
[i
].X
= (REAL
)points
[i
].X
;
560 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
563 stat
= GdipAddPathCurve2(path
, ptf
, count
, tension
);
570 GpStatus WINGDIPAPI
GdipAddPathCurve3(GpPath
*path
, GDIPCONST GpPointF
*points
,
571 INT count
, INT offset
, INT nseg
, REAL tension
)
573 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path
, points
, count
, offset
, nseg
, tension
);
575 if(!path
|| !points
|| offset
+ 1 >= count
|| count
- offset
< nseg
+ 1)
576 return InvalidParameter
;
578 return GdipAddPathCurve2(path
, &points
[offset
], nseg
+ 1, tension
);
581 GpStatus WINGDIPAPI
GdipAddPathCurve3I(GpPath
*path
, GDIPCONST GpPoint
*points
,
582 INT count
, INT offset
, INT nseg
, REAL tension
)
584 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path
, points
, count
, offset
, nseg
, tension
);
586 if(!path
|| !points
|| offset
+ 1 >= count
|| count
- offset
< nseg
+ 1)
587 return InvalidParameter
;
589 return GdipAddPathCurve2I(path
, &points
[offset
], nseg
+ 1, tension
);
592 GpStatus WINGDIPAPI
GdipAddPathEllipse(GpPath
*path
, REAL x
, REAL y
, REAL width
,
595 INT old_count
, numpts
;
597 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
600 return InvalidParameter
;
602 if(!lengthen_path(path
, MAX_ARC_PTS
))
605 old_count
= path
->pathdata
.Count
;
606 if((numpts
= arc2polybezier(&path
->pathdata
.Points
[old_count
], x
, y
, width
,
607 height
, 0.0, 360.0)) != MAX_ARC_PTS
){
608 ERR("expected %d points but got %d\n", MAX_ARC_PTS
, numpts
);
612 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeBezier
,
615 /* An ellipse is an intrinsic figure (always is its own subpath). */
616 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
617 path
->pathdata
.Types
[old_count
+ MAX_ARC_PTS
- 1] |= PathPointTypeCloseSubpath
;
618 path
->newfigure
= TRUE
;
619 path
->pathdata
.Count
+= MAX_ARC_PTS
;
624 GpStatus WINGDIPAPI
GdipAddPathEllipseI(GpPath
*path
, INT x
, INT y
, INT width
,
627 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
629 return GdipAddPathEllipse(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
632 GpStatus WINGDIPAPI
GdipAddPathLine2(GpPath
*path
, GDIPCONST GpPointF
*points
,
635 TRACE("(%p, %p, %d)\n", path
, points
, count
);
637 if(!path
|| !points
|| count
< 1)
638 return InvalidParameter
;
640 return extend_current_figure(path
, points
, count
, PathPointTypeLine
);
643 GpStatus WINGDIPAPI
GdipAddPathLine2I(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
649 TRACE("(%p, %p, %d)\n", path
, points
, count
);
652 return InvalidParameter
;
654 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
655 if(!pointsF
) return OutOfMemory
;
657 for(i
= 0;i
< count
; i
++){
658 pointsF
[i
].X
= (REAL
)points
[i
].X
;
659 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
662 stat
= GdipAddPathLine2(path
, pointsF
, count
);
669 /*************************************************************************
670 * GdipAddPathLine [GDIPLUS.21]
672 * Add two points to the given path.
675 * path [I/O] Path that the line is appended to
676 * x1 [I] X coordinate of the first point of the line
677 * y1 [I] Y coordinate of the first point of the line
678 * x2 [I] X coordinate of the second point of the line
679 * y2 [I] Y coordinate of the second point of the line
682 * InvalidParameter If the first parameter is not a valid path
683 * OutOfMemory If the path cannot be lengthened, i.e. memory allocation fails
684 * Ok If everything works out as expected
687 * This functions takes the newfigure value of the given path into account,
688 * i.e. the two new points are connected to the end of the given path if it
689 * was set to FALSE, otherwise the first point is given the PathPointTypeStart
690 * value. In both cases, the value of newfigure of the given path is FALSE
693 GpStatus WINGDIPAPI
GdipAddPathLine(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
697 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x1
, y1
, x2
, y2
);
700 return InvalidParameter
;
707 return extend_current_figure(path
, points
, 2, PathPointTypeLine
);
710 /*************************************************************************
711 * GdipAddPathLineI [GDIPLUS.21]
713 * See GdipAddPathLine
715 GpStatus WINGDIPAPI
GdipAddPathLineI(GpPath
*path
, INT x1
, INT y1
, INT x2
, INT y2
)
717 TRACE("(%p, %d, %d, %d, %d)\n", path
, x1
, y1
, x2
, y2
);
719 return GdipAddPathLine(path
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
722 GpStatus WINGDIPAPI
GdipAddPathPath(GpPath
*path
, GDIPCONST GpPath
* addingPath
,
725 INT old_count
, count
;
727 TRACE("(%p, %p, %d)\n", path
, addingPath
, connect
);
729 if(!path
|| !addingPath
)
730 return InvalidParameter
;
732 old_count
= path
->pathdata
.Count
;
733 count
= addingPath
->pathdata
.Count
;
735 if(!lengthen_path(path
, count
))
738 memcpy(&path
->pathdata
.Points
[old_count
], addingPath
->pathdata
.Points
,
739 count
* sizeof(GpPointF
));
740 memcpy(&path
->pathdata
.Types
[old_count
], addingPath
->pathdata
.Types
, count
);
742 if(path
->newfigure
|| !connect
)
743 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
745 path
->pathdata
.Types
[old_count
] = PathPointTypeLine
;
747 path
->newfigure
= FALSE
;
748 path
->pathdata
.Count
+= count
;
753 GpStatus WINGDIPAPI
GdipAddPathPie(GpPath
*path
, REAL x
, REAL y
, REAL width
, REAL height
,
754 REAL startAngle
, REAL sweepAngle
)
760 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
761 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
764 return InvalidParameter
;
766 /* on zero width/height only start point added */
767 if(width
<= 1e-7 || height
<= 1e-7){
768 if(!lengthen_path(path
, 1))
770 path
->pathdata
.Points
[0].X
= x
+ width
/ 2.0;
771 path
->pathdata
.Points
[0].Y
= y
+ height
/ 2.0;
772 path
->pathdata
.Types
[0] = PathPointTypeStart
| PathPointTypeCloseSubpath
;
773 path
->pathdata
.Count
= 1;
774 return InvalidParameter
;
777 count
= arc2polybezier(NULL
, x
, y
, width
, height
, startAngle
, sweepAngle
);
782 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
786 arc2polybezier(ptf
, x
, y
, width
, height
, startAngle
, sweepAngle
);
788 status
= GdipAddPathLine(path
, x
+ width
/2, y
+ height
/2, ptf
[0].X
, ptf
[0].Y
);
793 /* one spline is already added as a line endpoint */
794 if(!lengthen_path(path
, count
- 1)){
799 memcpy(&(path
->pathdata
.Points
[path
->pathdata
.Count
]), &(ptf
[1]),sizeof(GpPointF
)*(count
-1));
800 for(i
= 0; i
< count
-1; i
++)
801 path
->pathdata
.Types
[path
->pathdata
.Count
+i
] = PathPointTypeBezier
;
803 path
->pathdata
.Count
+= count
-1;
805 GdipClosePathFigure(path
);
812 GpStatus WINGDIPAPI
GdipAddPathPieI(GpPath
*path
, INT x
, INT y
, INT width
, INT height
,
813 REAL startAngle
, REAL sweepAngle
)
815 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
816 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
818 return GdipAddPathPie(path
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, startAngle
, sweepAngle
);
821 GpStatus WINGDIPAPI
GdipAddPathPolygon(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
825 TRACE("(%p, %p, %d)\n", path
, points
, count
);
827 if(!path
|| !points
|| count
< 3)
828 return InvalidParameter
;
830 if(!lengthen_path(path
, count
))
833 old_count
= path
->pathdata
.Count
;
835 memcpy(&path
->pathdata
.Points
[old_count
], points
, count
*sizeof(GpPointF
));
836 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeLine
, count
- 1);
838 /* A polygon is an intrinsic figure */
839 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
840 path
->pathdata
.Types
[old_count
+ count
- 1] |= PathPointTypeCloseSubpath
;
841 path
->newfigure
= TRUE
;
842 path
->pathdata
.Count
+= count
;
847 GpStatus WINGDIPAPI
GdipAddPathPolygonI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
853 TRACE("(%p, %p, %d)\n", path
, points
, count
);
855 if(!points
|| count
< 3)
856 return InvalidParameter
;
858 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
862 for(i
= 0; i
< count
; i
++){
863 ptf
[i
].X
= (REAL
)points
[i
].X
;
864 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
867 status
= GdipAddPathPolygon(path
, ptf
, count
);
874 static float fromfixedpoint(const FIXED v
)
876 float f
= ((float)v
.fract
) / (1<<(sizeof(v
.fract
)*8));
881 struct format_string_args
889 static GpStatus
format_string_callback(HDC dc
,
890 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
891 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
892 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
893 INT underlined_index_count
, void *priv
)
895 static const MAT2 identity
= { {0,1}, {0,0}, {0,0}, {0,1} };
896 struct format_string_args
*args
= priv
;
897 GpPath
*path
= args
->path
;
898 GpStatus status
= Ok
;
899 float x
= rect
->X
+ (bounds
->X
- rect
->X
) * args
->scale
;
900 float y
= rect
->Y
+ (bounds
->Y
- rect
->Y
) * args
->scale
;
903 if (underlined_index_count
)
904 FIXME("hotkey underlines not drawn yet\n");
906 if (y
+ bounds
->Height
* args
->scale
> args
->maxY
)
907 args
->maxY
= y
+ bounds
->Height
* args
->scale
;
909 for (i
= index
; i
< length
; ++i
)
912 TTPOLYGONHEADER
*ph
= NULL
, *origph
;
915 len
= GetGlyphOutlineW(dc
, string
[i
], GGO_BEZIER
, &gm
, 0, NULL
, &identity
);
916 if (len
== GDI_ERROR
)
918 status
= GenericError
;
921 origph
= ph
= heap_alloc_zero(len
);
923 if (!ph
|| !lengthen_path(path
, len
/ sizeof(POINTFX
)))
926 status
= OutOfMemory
;
929 GetGlyphOutlineW(dc
, string
[i
], GGO_BEZIER
, &gm
, len
, start
, &identity
);
934 DWORD ofs_start
= ofs
;
935 ph
= (TTPOLYGONHEADER
*)&start
[ofs
];
936 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeStart
;
937 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(ph
->pfxStart
.x
) * args
->scale
;
938 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(ph
->pfxStart
.y
) * args
->scale
;
939 TRACE("Starting at count %i with pos %f, %f)\n", path
->pathdata
.Count
, x
, y
);
941 while (ofs
- ofs_start
< ph
->cb
)
943 TTPOLYCURVE
*curve
= (TTPOLYCURVE
*)&start
[ofs
];
945 ofs
+= sizeof(TTPOLYCURVE
) + (curve
->cpfx
- 1) * sizeof(POINTFX
);
947 switch (curve
->wType
)
950 for (j
= 0; j
< curve
->cpfx
; ++j
)
952 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeLine
;
953 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(curve
->apfx
[j
].x
) * args
->scale
;
954 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(curve
->apfx
[j
].y
) * args
->scale
;
957 case TT_PRIM_CSPLINE
:
958 for (j
= 0; j
< curve
->cpfx
; ++j
)
960 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeBezier
;
961 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(curve
->apfx
[j
].x
) * args
->scale
;
962 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(curve
->apfx
[j
].y
) * args
->scale
;
966 ERR("Unhandled type: %u\n", curve
->wType
);
967 status
= GenericError
;
970 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
972 path
->newfigure
= TRUE
;
973 x
+= gm
.gmCellIncX
* args
->scale
;
974 y
+= gm
.gmCellIncY
* args
->scale
;
984 GpStatus WINGDIPAPI
GdipAddPathString(GpPath
* path
, GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFontFamily
* family
, INT style
, REAL emSize
, GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
* format
)
991 GpGraphics
*graphics
;
993 struct format_string_args args
;
995 UINT16 native_height
;
996 RectF scaled_layout_rect
;
997 TEXTMETRICW textmetric
;
999 TRACE("(%p, %s, %d, %p, %d, %f, %p, %p)\n", path
, debugstr_w(string
), length
, family
, style
, emSize
, layoutRect
, format
);
1000 if (!path
|| !string
|| !family
|| !emSize
|| !layoutRect
|| !format
)
1001 return InvalidParameter
;
1003 status
= GdipGetEmHeight(family
, style
, &native_height
);
1007 scaled_layout_rect
.X
= layoutRect
->X
;
1008 scaled_layout_rect
.Y
= layoutRect
->Y
;
1009 scaled_layout_rect
.Width
= layoutRect
->Width
* native_height
/ emSize
;
1010 scaled_layout_rect
.Height
= layoutRect
->Height
* native_height
/ emSize
;
1012 if ((status
= GdipClonePath(path
, &backup
)) != Ok
)
1015 dc
= CreateCompatibleDC(0);
1016 status
= GdipCreateFromHDC(dc
, &graphics
);
1020 GdipDeletePath(backup
);
1024 status
= GdipCreateFont(family
, native_height
, style
, UnitPixel
, &font
);
1027 GdipDeleteGraphics(graphics
);
1029 GdipDeletePath(backup
);
1033 get_log_fontW(font
, graphics
, &lfw
);
1034 GdipDeleteFont(font
);
1035 GdipDeleteGraphics(graphics
);
1037 hfont
= CreateFontIndirectW(&lfw
);
1040 WARN("Failed to create font\n");
1042 GdipDeletePath(backup
);
1043 return GenericError
;
1046 SelectObject(dc
, hfont
);
1048 GetTextMetricsW(dc
, &textmetric
);
1052 args
.scale
= emSize
/ native_height
;
1053 args
.ascent
= textmetric
.tmAscent
* args
.scale
;
1054 status
= gdip_format_string(dc
, string
, length
, NULL
, &scaled_layout_rect
,
1055 format
, TRUE
, format_string_callback
, &args
);
1058 DeleteObject(hfont
);
1060 if (status
!= Ok
) /* free backup */
1062 heap_free(path
->pathdata
.Points
);
1063 heap_free(path
->pathdata
.Types
);
1068 if (format
->line_align
== StringAlignmentCenter
&& layoutRect
->Y
+ args
.maxY
< layoutRect
->Height
)
1070 float inc
= layoutRect
->Height
+ layoutRect
->Y
- args
.maxY
;
1072 for (i
= backup
->pathdata
.Count
; i
< path
->pathdata
.Count
; ++i
)
1073 path
->pathdata
.Points
[i
].Y
+= inc
;
1074 } else if (format
->line_align
== StringAlignmentFar
) {
1075 float inc
= layoutRect
->Height
+ layoutRect
->Y
- args
.maxY
;
1076 for (i
= backup
->pathdata
.Count
; i
< path
->pathdata
.Count
; ++i
)
1077 path
->pathdata
.Points
[i
].Y
+= inc
;
1079 GdipDeletePath(backup
);
1083 GpStatus WINGDIPAPI
GdipAddPathStringI(GpPath
* path
, GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFontFamily
* family
,
1084 INT style
, REAL emSize
, GDIPCONST Rect
* layoutRect
, GDIPCONST GpStringFormat
* format
)
1089 return InvalidParameter
;
1091 set_rect(&rect
, layoutRect
->X
, layoutRect
->Y
, layoutRect
->Width
, layoutRect
->Height
);
1092 return GdipAddPathString(path
, string
, length
, family
, style
, emSize
, &rect
, format
);
1095 /*************************************************************************
1096 * GdipClonePath [GDIPLUS.53]
1098 * Duplicate the given path in memory.
1101 * path [I] The path to be duplicated
1102 * clone [O] Pointer to the new path
1105 * InvalidParameter If the input path is invalid
1106 * OutOfMemory If allocation of needed memory fails
1107 * Ok If everything works out as expected
1109 GpStatus WINGDIPAPI
GdipClonePath(GpPath
* path
, GpPath
**clone
)
1111 TRACE("(%p, %p)\n", path
, clone
);
1114 return InvalidParameter
;
1116 *clone
= heap_alloc_zero(sizeof(GpPath
));
1117 if(!*clone
) return OutOfMemory
;
1121 (*clone
)->pathdata
.Points
= heap_alloc_zero(path
->datalen
* sizeof(PointF
));
1122 (*clone
)->pathdata
.Types
= heap_alloc_zero(path
->datalen
);
1123 if(!(*clone
)->pathdata
.Points
|| !(*clone
)->pathdata
.Types
){
1124 heap_free((*clone
)->pathdata
.Points
);
1125 heap_free((*clone
)->pathdata
.Types
);
1130 memcpy((*clone
)->pathdata
.Points
, path
->pathdata
.Points
,
1131 path
->datalen
* sizeof(PointF
));
1132 memcpy((*clone
)->pathdata
.Types
, path
->pathdata
.Types
, path
->datalen
);
1137 GpStatus WINGDIPAPI
GdipClosePathFigure(GpPath
* path
)
1139 TRACE("(%p)\n", path
);
1142 return InvalidParameter
;
1144 if(path
->pathdata
.Count
> 0){
1145 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
1146 path
->newfigure
= TRUE
;
1152 GpStatus WINGDIPAPI
GdipClosePathFigures(GpPath
* path
)
1156 TRACE("(%p)\n", path
);
1159 return InvalidParameter
;
1161 for(i
= 1; i
< path
->pathdata
.Count
; i
++){
1162 if(path
->pathdata
.Types
[i
] == PathPointTypeStart
)
1163 path
->pathdata
.Types
[i
-1] |= PathPointTypeCloseSubpath
;
1166 path
->newfigure
= TRUE
;
1171 GpStatus WINGDIPAPI
GdipCreatePath(GpFillMode fill
, GpPath
**path
)
1173 TRACE("(%d, %p)\n", fill
, path
);
1176 return InvalidParameter
;
1178 *path
= heap_alloc_zero(sizeof(GpPath
));
1179 if(!*path
) return OutOfMemory
;
1181 (*path
)->fill
= fill
;
1182 (*path
)->newfigure
= TRUE
;
1187 GpStatus WINGDIPAPI
GdipCreatePath2(GDIPCONST GpPointF
* points
,
1188 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1192 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1194 if(!points
|| !types
|| !path
)
1195 return InvalidParameter
;
1202 *path
= heap_alloc_zero(sizeof(GpPath
));
1203 if(!*path
) return OutOfMemory
;
1205 if(count
> 1 && (types
[count
-1] & PathPointTypePathTypeMask
) == PathPointTypeStart
)
1208 for(i
= 1; i
< count
; i
++) {
1209 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
) {
1211 (types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeBezier
&&
1212 (types
[i
+2] & PathPointTypePathTypeMask
) == PathPointTypeBezier
)
1221 (*path
)->pathdata
.Points
= heap_alloc_zero(count
* sizeof(PointF
));
1222 (*path
)->pathdata
.Types
= heap_alloc_zero(count
);
1224 if(!(*path
)->pathdata
.Points
|| !(*path
)->pathdata
.Types
){
1225 heap_free((*path
)->pathdata
.Points
);
1226 heap_free((*path
)->pathdata
.Types
);
1231 memcpy((*path
)->pathdata
.Points
, points
, count
* sizeof(PointF
));
1232 memcpy((*path
)->pathdata
.Types
, types
, count
);
1234 (*path
)->pathdata
.Types
[0] = PathPointTypeStart
;
1235 (*path
)->pathdata
.Count
= count
;
1236 (*path
)->datalen
= count
;
1238 (*path
)->fill
= fill
;
1239 (*path
)->newfigure
= TRUE
;
1244 GpStatus WINGDIPAPI
GdipCreatePath2I(GDIPCONST GpPoint
* points
,
1245 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1251 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1253 ptF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1255 for(i
= 0;i
< count
; i
++){
1256 ptF
[i
].X
= (REAL
)points
[i
].X
;
1257 ptF
[i
].Y
= (REAL
)points
[i
].Y
;
1260 ret
= GdipCreatePath2(ptF
, types
, count
, fill
, path
);
1267 GpStatus WINGDIPAPI
GdipDeletePath(GpPath
*path
)
1269 TRACE("(%p)\n", path
);
1272 return InvalidParameter
;
1274 heap_free(path
->pathdata
.Points
);
1275 heap_free(path
->pathdata
.Types
);
1281 GpStatus WINGDIPAPI
GdipFlattenPath(GpPath
*path
, GpMatrix
* matrix
, REAL flatness
)
1283 path_list_node_t
*list
, *node
;
1289 TRACE("(%p, %p, %.2f)\n", path
, matrix
, flatness
);
1292 return InvalidParameter
;
1294 if(path
->pathdata
.Count
== 0)
1297 stat
= GdipTransformPath(path
, matrix
);
1301 pt
= path
->pathdata
.Points
[0];
1302 if(!init_path_list(&list
, pt
.X
, pt
.Y
))
1307 while(i
< path
->pathdata
.Count
){
1309 BYTE type
= path
->pathdata
.Types
[i
] & PathPointTypePathTypeMask
;
1310 path_list_node_t
*start
;
1312 pt
= path
->pathdata
.Points
[i
];
1314 /* save last start point index */
1315 if(type
== PathPointTypeStart
)
1318 /* always add line points and start points */
1319 if((type
== PathPointTypeStart
) || (type
== PathPointTypeLine
)){
1320 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, path
->pathdata
.Types
[i
]))
1330 /* test for closed figure */
1331 if(path
->pathdata
.Types
[i
+1] & PathPointTypeCloseSubpath
){
1332 pt
= path
->pathdata
.Points
[startidx
];
1338 pt
= path
->pathdata
.Points
[i
];
1342 /* add Bezier end point */
1343 type
= (path
->pathdata
.Types
[i
] & ~PathPointTypePathTypeMask
) | PathPointTypeLine
;
1344 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, type
))
1349 if(!flatten_bezier(start
, path
->pathdata
.Points
[i
-2].X
, path
->pathdata
.Points
[i
-2].Y
,
1350 path
->pathdata
.Points
[i
-1].X
, path
->pathdata
.Points
[i
-1].Y
,
1357 /* store path data back */
1358 i
= path_list_count(list
);
1359 if(!lengthen_path(path
, i
))
1361 path
->pathdata
.Count
= i
;
1364 for(i
= 0; i
< path
->pathdata
.Count
; i
++){
1365 path
->pathdata
.Points
[i
] = node
->pt
;
1366 path
->pathdata
.Types
[i
] = node
->type
;
1370 free_path_list(list
);
1374 free_path_list(list
);
1378 GpStatus WINGDIPAPI
GdipGetPathData(GpPath
*path
, GpPathData
* pathData
)
1380 TRACE("(%p, %p)\n", path
, pathData
);
1382 if(!path
|| !pathData
)
1383 return InvalidParameter
;
1385 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
1386 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
1387 memcpy(pathData
->Points
, path
->pathdata
.Points
, sizeof(PointF
) * pathData
->Count
);
1388 memcpy(pathData
->Types
, path
->pathdata
.Types
, pathData
->Count
);
1393 GpStatus WINGDIPAPI
GdipGetPathFillMode(GpPath
*path
, GpFillMode
*fillmode
)
1395 TRACE("(%p, %p)\n", path
, fillmode
);
1397 if(!path
|| !fillmode
)
1398 return InvalidParameter
;
1400 *fillmode
= path
->fill
;
1405 GpStatus WINGDIPAPI
GdipGetPathLastPoint(GpPath
* path
, GpPointF
* lastPoint
)
1409 TRACE("(%p, %p)\n", path
, lastPoint
);
1411 if(!path
|| !lastPoint
)
1412 return InvalidParameter
;
1414 count
= path
->pathdata
.Count
;
1416 *lastPoint
= path
->pathdata
.Points
[count
-1];
1421 GpStatus WINGDIPAPI
GdipGetPathPoints(GpPath
*path
, GpPointF
* points
, INT count
)
1423 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1426 return InvalidParameter
;
1428 if(count
< path
->pathdata
.Count
)
1429 return InsufficientBuffer
;
1431 memcpy(points
, path
->pathdata
.Points
, path
->pathdata
.Count
* sizeof(GpPointF
));
1436 GpStatus WINGDIPAPI
GdipGetPathPointsI(GpPath
*path
, GpPoint
* points
, INT count
)
1442 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1445 return InvalidParameter
;
1447 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1448 if(!ptf
) return OutOfMemory
;
1450 ret
= GdipGetPathPoints(path
,ptf
,count
);
1452 for(i
= 0;i
< count
;i
++){
1453 points
[i
].X
= gdip_round(ptf
[i
].X
);
1454 points
[i
].Y
= gdip_round(ptf
[i
].Y
);
1461 GpStatus WINGDIPAPI
GdipGetPathTypes(GpPath
*path
, BYTE
* types
, INT count
)
1463 TRACE("(%p, %p, %d)\n", path
, types
, count
);
1466 return InvalidParameter
;
1468 if(count
< path
->pathdata
.Count
)
1469 return InsufficientBuffer
;
1471 memcpy(types
, path
->pathdata
.Types
, path
->pathdata
.Count
);
1476 /* Windows expands the bounding box to the maximum possible bounding box
1477 * for a given pen. For example, if a line join can extend past the point
1478 * it's joining by x units, the bounding box is extended by x units in every
1479 * direction (even though this is too conservative for most cases). */
1480 GpStatus WINGDIPAPI
GdipGetPathWorldBounds(GpPath
* path
, GpRectF
* bounds
,
1481 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1483 GpPointF
* points
, temp_pts
[4];
1485 REAL path_width
= 1.0, width
, height
, temp
, low_x
, low_y
, high_x
, high_y
;
1487 TRACE("(%p, %p, %p, %p)\n", path
, bounds
, matrix
, pen
);
1489 /* Matrix and pen can be null. */
1490 if(!path
|| !bounds
)
1491 return InvalidParameter
;
1493 /* If path is empty just return. */
1494 count
= path
->pathdata
.Count
;
1496 bounds
->X
= bounds
->Y
= bounds
->Width
= bounds
->Height
= 0.0;
1500 points
= path
->pathdata
.Points
;
1502 low_x
= high_x
= points
[0].X
;
1503 low_y
= high_y
= points
[0].Y
;
1505 for(i
= 1; i
< count
; i
++){
1506 low_x
= min(low_x
, points
[i
].X
);
1507 low_y
= min(low_y
, points
[i
].Y
);
1508 high_x
= max(high_x
, points
[i
].X
);
1509 high_y
= max(high_y
, points
[i
].Y
);
1512 width
= high_x
- low_x
;
1513 height
= high_y
- low_y
;
1515 /* This looks unusual but it's the only way I can imitate windows. */
1517 temp_pts
[0].X
= low_x
;
1518 temp_pts
[0].Y
= low_y
;
1519 temp_pts
[1].X
= low_x
;
1520 temp_pts
[1].Y
= high_y
;
1521 temp_pts
[2].X
= high_x
;
1522 temp_pts
[2].Y
= high_y
;
1523 temp_pts
[3].X
= high_x
;
1524 temp_pts
[3].Y
= low_y
;
1526 GdipTransformMatrixPoints((GpMatrix
*)matrix
, temp_pts
, 4);
1527 low_x
= temp_pts
[0].X
;
1528 low_y
= temp_pts
[0].Y
;
1530 for(i
= 1; i
< 4; i
++){
1531 low_x
= min(low_x
, temp_pts
[i
].X
);
1532 low_y
= min(low_y
, temp_pts
[i
].Y
);
1536 width
= height
* fabs(matrix
->matrix
[2]) + width
* fabs(matrix
->matrix
[0]);
1537 height
= height
* fabs(matrix
->matrix
[3]) + temp
* fabs(matrix
->matrix
[1]);
1541 path_width
= pen
->width
/ 2.0;
1544 path_width
= max(path_width
, pen
->width
* pen
->miterlimit
/ 2.0);
1545 /* FIXME: this should probably also check for the startcap */
1546 if(pen
->endcap
& LineCapNoAnchor
)
1547 path_width
= max(path_width
, pen
->width
* 2.2);
1549 low_x
-= path_width
;
1550 low_y
-= path_width
;
1551 width
+= 2.0 * path_width
;
1552 height
+= 2.0 * path_width
;
1557 bounds
->Width
= width
;
1558 bounds
->Height
= height
;
1563 GpStatus WINGDIPAPI
GdipGetPathWorldBoundsI(GpPath
* path
, GpRect
* bounds
,
1564 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1569 TRACE("(%p, %p, %p, %p)\n", path
, bounds
, matrix
, pen
);
1571 ret
= GdipGetPathWorldBounds(path
,&boundsF
,matrix
,pen
);
1574 bounds
->X
= gdip_round(boundsF
.X
);
1575 bounds
->Y
= gdip_round(boundsF
.Y
);
1576 bounds
->Width
= gdip_round(boundsF
.Width
);
1577 bounds
->Height
= gdip_round(boundsF
.Height
);
1583 GpStatus WINGDIPAPI
GdipGetPointCount(GpPath
*path
, INT
*count
)
1585 TRACE("(%p, %p)\n", path
, count
);
1588 return InvalidParameter
;
1590 *count
= path
->pathdata
.Count
;
1595 GpStatus WINGDIPAPI
GdipReversePath(GpPath
* path
)
1598 INT start
= 0; /* position in reversed path */
1601 TRACE("(%p)\n", path
);
1604 return InvalidParameter
;
1606 count
= path
->pathdata
.Count
;
1608 if(count
== 0) return Ok
;
1610 revpath
.Points
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1611 revpath
.Types
= heap_alloc_zero(sizeof(BYTE
)*count
);
1612 revpath
.Count
= count
;
1613 if(!revpath
.Points
|| !revpath
.Types
){
1614 heap_free(revpath
.Points
);
1615 heap_free(revpath
.Types
);
1619 for(i
= 0; i
< count
; i
++){
1621 /* find next start point */
1622 if(path
->pathdata
.Types
[count
-i
-1] == PathPointTypeStart
){
1624 for(j
= start
; j
<= i
; j
++){
1625 revpath
.Points
[j
] = path
->pathdata
.Points
[count
-j
-1];
1626 revpath
.Types
[j
] = path
->pathdata
.Types
[count
-j
-1];
1628 /* mark start point */
1629 revpath
.Types
[start
] = PathPointTypeStart
;
1630 /* set 'figure' endpoint type */
1632 revpath
.Types
[i
] = path
->pathdata
.Types
[count
-start
-1] & ~PathPointTypePathTypeMask
;
1633 revpath
.Types
[i
] |= revpath
.Types
[i
-1];
1636 revpath
.Types
[i
] = path
->pathdata
.Types
[start
];
1642 memcpy(path
->pathdata
.Points
, revpath
.Points
, sizeof(GpPointF
)*count
);
1643 memcpy(path
->pathdata
.Types
, revpath
.Types
, sizeof(BYTE
)*count
);
1645 heap_free(revpath
.Points
);
1646 heap_free(revpath
.Types
);
1651 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPointI(GpPath
* path
, INT x
, INT y
,
1652 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1654 TRACE("(%p, %d, %d, %p, %p, %p)\n", path
, x
, y
, pen
, graphics
, result
);
1656 return GdipIsOutlineVisiblePathPoint(path
, x
, y
, pen
, graphics
, result
);
1659 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
,
1660 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1664 GpMatrix
*transform
= NULL
;
1666 TRACE("(%p,%0.2f,%0.2f,%p,%p,%p)\n", path
, x
, y
, pen
, graphics
, result
);
1669 return InvalidParameter
;
1671 stat
= GdipClonePath(path
, &wide_path
);
1676 if (pen
->unit
== UnitPixel
&& graphics
!= NULL
)
1678 stat
= GdipCreateMatrix(&transform
);
1681 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1682 CoordinateSpaceWorld
, transform
);
1686 stat
= GdipWidenPath(wide_path
, pen
, transform
, 1.0);
1688 if (pen
->unit
== UnitPixel
&& graphics
!= NULL
)
1691 stat
= GdipInvertMatrix(transform
);
1694 stat
= GdipTransformPath(wide_path
, transform
);
1698 stat
= GdipIsVisiblePathPoint(wide_path
, x
, y
, graphics
, result
);
1700 GdipDeleteMatrix(transform
);
1702 GdipDeletePath(wide_path
);
1707 GpStatus WINGDIPAPI
GdipIsVisiblePathPointI(GpPath
* path
, INT x
, INT y
, GpGraphics
*graphics
, BOOL
*result
)
1709 TRACE("(%p, %d, %d, %p, %p)\n", path
, x
, y
, graphics
, result
);
1711 return GdipIsVisiblePathPoint(path
, x
, y
, graphics
, result
);
1714 /*****************************************************************************
1715 * GdipIsVisiblePathPoint [GDIPLUS.@]
1717 GpStatus WINGDIPAPI
GdipIsVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
, GpGraphics
*graphics
, BOOL
*result
)
1723 if(!path
|| !result
) return InvalidParameter
;
1725 status
= GdipCreateRegionPath(path
, ®ion
);
1729 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
1731 GdipDeleteRegion(region
);
1735 *result
= PtInRegion(hrgn
, gdip_round(x
), gdip_round(y
));
1738 GdipDeleteRegion(region
);
1743 GpStatus WINGDIPAPI
GdipStartPathFigure(GpPath
*path
)
1745 TRACE("(%p)\n", path
);
1748 return InvalidParameter
;
1750 path
->newfigure
= TRUE
;
1755 GpStatus WINGDIPAPI
GdipResetPath(GpPath
*path
)
1757 TRACE("(%p)\n", path
);
1760 return InvalidParameter
;
1762 path
->pathdata
.Count
= 0;
1763 path
->newfigure
= TRUE
;
1764 path
->fill
= FillModeAlternate
;
1769 GpStatus WINGDIPAPI
GdipSetPathFillMode(GpPath
*path
, GpFillMode fill
)
1771 TRACE("(%p, %d)\n", path
, fill
);
1774 return InvalidParameter
;
1781 GpStatus WINGDIPAPI
GdipTransformPath(GpPath
*path
, GpMatrix
*matrix
)
1783 TRACE("(%p, %p)\n", path
, matrix
);
1786 return InvalidParameter
;
1788 if(path
->pathdata
.Count
== 0 || !matrix
)
1791 return GdipTransformMatrixPoints(matrix
, path
->pathdata
.Points
,
1792 path
->pathdata
.Count
);
1795 GpStatus WINGDIPAPI
GdipWarpPath(GpPath
*path
, GpMatrix
* matrix
,
1796 GDIPCONST GpPointF
*points
, INT count
, REAL x
, REAL y
, REAL width
,
1797 REAL height
, WarpMode warpmode
, REAL flatness
)
1799 FIXME("(%p,%p,%p,%i,%0.2f,%0.2f,%0.2f,%0.2f,%i,%0.2f)\n", path
, matrix
,
1800 points
, count
, x
, y
, width
, height
, warpmode
, flatness
);
1802 return NotImplemented
;
1805 static void add_bevel_point(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1806 REAL pen_width
, int right_side
, path_list_node_t
**last_point
)
1808 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1809 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1810 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1811 REAL distance
= pen_width
/ 2.0;
1812 REAL bevel_dx
, bevel_dy
;
1814 if (segment_length
== 0.0)
1816 *last_point
= add_path_list_node(*last_point
, endpoint
->X
,
1817 endpoint
->Y
, PathPointTypeLine
);
1823 bevel_dx
= -distance
* segment_dy
/ segment_length
;
1824 bevel_dy
= distance
* segment_dx
/ segment_length
;
1828 bevel_dx
= distance
* segment_dy
/ segment_length
;
1829 bevel_dy
= -distance
* segment_dx
/ segment_length
;
1832 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ bevel_dx
,
1833 endpoint
->Y
+ bevel_dy
, PathPointTypeLine
);
1836 static void widen_joint(const GpPointF
*p1
, const GpPointF
*p2
, const GpPointF
*p3
,
1837 GpPen
* pen
, REAL pen_width
, path_list_node_t
**last_point
)
1842 case LineJoinMiterClipped
:
1843 if ((p2
->X
- p1
->X
) * (p3
->Y
- p1
->Y
) > (p2
->Y
- p1
->Y
) * (p3
->X
- p1
->X
))
1845 float distance
= pen_width
/ 2.0;
1846 float length_0
= sqrtf((p2
->X
-p1
->X
)*(p2
->X
-p1
->X
)+(p2
->Y
-p1
->Y
)*(p2
->Y
-p1
->Y
));
1847 float length_1
= sqrtf((p3
->X
-p2
->X
)*(p3
->X
-p2
->X
)+(p3
->Y
-p2
->Y
)*(p3
->Y
-p2
->Y
));
1848 float dx0
= distance
* (p2
->X
- p1
->X
) / length_0
;
1849 float dy0
= distance
* (p2
->Y
- p1
->Y
) / length_0
;
1850 float dx1
= distance
* (p3
->X
- p2
->X
) / length_1
;
1851 float dy1
= distance
* (p3
->Y
- p2
->Y
) / length_1
;
1852 float det
= (dy0
*dx1
- dx0
*dy1
);
1853 float dx
= (dx0
*dx1
*(dx0
-dx1
) + dy0
*dy0
*dx1
- dy1
*dy1
*dx0
)/det
;
1854 float dy
= (dy0
*dy1
*(dy0
-dy1
) + dx0
*dx0
*dy1
- dx1
*dx1
*dy0
)/det
;
1855 if (dx
*dx
+ dy
*dy
< pen
->miterlimit
*pen
->miterlimit
* distance
*distance
)
1857 *last_point
= add_path_list_node(*last_point
, p2
->X
+ dx
,
1858 p2
->Y
+ dy
, PathPointTypeLine
);
1861 else if (pen
->join
== LineJoinMiter
)
1865 FIXME("should add a clipped corner\n");
1867 /* else fall-through */
1869 /* else fall-through */
1872 add_bevel_point(p2
, p1
, pen_width
, 1, last_point
);
1873 add_bevel_point(p2
, p3
, pen_width
, 0, last_point
);
1878 static void widen_cap(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1879 REAL pen_width
, GpLineCap cap
, GpCustomLineCap
*custom
, int add_first_points
,
1880 int add_last_point
, path_list_node_t
**last_point
)
1886 if (add_first_points
)
1887 add_bevel_point(endpoint
, nextpoint
, pen_width
, 1, last_point
);
1889 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
1893 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1894 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1895 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1896 REAL distance
= pen_width
/ 2.0;
1897 REAL bevel_dx
, bevel_dy
;
1898 REAL extend_dx
, extend_dy
;
1900 extend_dx
= -distance
* segment_dx
/ segment_length
;
1901 extend_dy
= -distance
* segment_dy
/ segment_length
;
1903 bevel_dx
= -distance
* segment_dy
/ segment_length
;
1904 bevel_dy
= distance
* segment_dx
/ segment_length
;
1906 if (add_first_points
)
1907 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ extend_dx
+ bevel_dx
,
1908 endpoint
->Y
+ extend_dy
+ bevel_dy
, PathPointTypeLine
);
1911 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ extend_dx
- bevel_dx
,
1912 endpoint
->Y
+ extend_dy
- bevel_dy
, PathPointTypeLine
);
1918 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1919 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1920 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1921 REAL distance
= pen_width
/ 2.0;
1922 REAL dx
, dy
, dx2
, dy2
;
1923 const REAL control_point_distance
= 0.5522847498307935; /* 4/3 * (sqrt(2) - 1) */
1925 if (add_first_points
)
1927 dx
= -distance
* segment_dx
/ segment_length
;
1928 dy
= -distance
* segment_dy
/ segment_length
;
1930 dx2
= dx
* control_point_distance
;
1931 dy2
= dy
* control_point_distance
;
1933 /* first 90-degree arc */
1934 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
1935 endpoint
->Y
- dx
, PathPointTypeLine
);
1937 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
+ dx2
,
1938 endpoint
->Y
- dx
+ dy2
, PathPointTypeBezier
);
1940 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
+ dy2
,
1941 endpoint
->Y
+ dy
- dx2
, PathPointTypeBezier
);
1944 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
,
1945 endpoint
->Y
+ dy
, PathPointTypeBezier
);
1947 /* second 90-degree arc */
1948 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
- dy2
,
1949 endpoint
->Y
+ dy
+ dx2
, PathPointTypeBezier
);
1951 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
+ dx2
,
1952 endpoint
->Y
+ dx
+ dy2
, PathPointTypeBezier
);
1954 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
,
1955 endpoint
->Y
+ dx
, PathPointTypeBezier
);
1957 else if (add_last_point
)
1958 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
1961 case LineCapTriangle
:
1963 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1964 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1965 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1966 REAL distance
= pen_width
/ 2.0;
1969 dx
= distance
* segment_dx
/ segment_length
;
1970 dy
= distance
* segment_dy
/ segment_length
;
1972 if (add_first_points
) {
1973 add_bevel_point(endpoint
, nextpoint
, pen_width
, 1, last_point
);
1975 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
,
1976 endpoint
->Y
- dy
, PathPointTypeLine
);
1978 if (add_first_points
|| add_last_point
)
1979 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
1985 static void add_anchor(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1986 REAL pen_width
, GpLineCap cap
, GpCustomLineCap
*custom
, path_list_node_t
**last_point
)
1991 case LineCapNoAnchor
:
1993 case LineCapSquareAnchor
:
1995 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1996 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1997 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1998 REAL distance
= pen_width
/ sqrtf(2.0);
1999 REAL par_dx
, par_dy
;
2000 REAL perp_dx
, perp_dy
;
2002 par_dx
= -distance
* segment_dx
/ segment_length
;
2003 par_dy
= -distance
* segment_dy
/ segment_length
;
2005 perp_dx
= -distance
* segment_dy
/ segment_length
;
2006 perp_dy
= distance
* segment_dx
/ segment_length
;
2008 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
- perp_dx
,
2009 endpoint
->Y
- par_dy
- perp_dy
, PathPointTypeStart
);
2010 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
+ perp_dx
,
2011 endpoint
->Y
- par_dy
+ perp_dy
, PathPointTypeLine
);
2012 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
+ perp_dx
,
2013 endpoint
->Y
+ par_dy
+ perp_dy
, PathPointTypeLine
);
2014 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
- perp_dx
,
2015 endpoint
->Y
+ par_dy
- perp_dy
, PathPointTypeLine
);
2018 case LineCapRoundAnchor
:
2020 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
2021 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2022 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2023 REAL dx
, dy
, dx2
, dy2
;
2024 const REAL control_point_distance
= 0.55228475; /* 4/3 * (sqrt(2) - 1) */
2026 dx
= -pen_width
* segment_dx
/ segment_length
;
2027 dy
= -pen_width
* segment_dy
/ segment_length
;
2029 dx2
= dx
* control_point_distance
;
2030 dy2
= dy
* control_point_distance
;
2032 /* starting point */
2033 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
2034 endpoint
->Y
- dx
, PathPointTypeStart
);
2036 /* first 90-degree arc */
2037 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
+ dx2
,
2038 endpoint
->Y
- dx
+ dy2
, PathPointTypeBezier
);
2039 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
+ dy2
,
2040 endpoint
->Y
+ dy
- dx2
, PathPointTypeBezier
);
2041 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
,
2042 endpoint
->Y
+ dy
, PathPointTypeBezier
);
2044 /* second 90-degree arc */
2045 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
- dy2
,
2046 endpoint
->Y
+ dy
+ dx2
, PathPointTypeBezier
);
2047 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
+ dx2
,
2048 endpoint
->Y
+ dx
+ dy2
, PathPointTypeBezier
);
2049 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
,
2050 endpoint
->Y
+ dx
, PathPointTypeBezier
);
2052 /* third 90-degree arc */
2053 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
- dx2
,
2054 endpoint
->Y
+ dx
- dy2
, PathPointTypeBezier
);
2055 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
- dy2
,
2056 endpoint
->Y
- dy
+ dx2
, PathPointTypeBezier
);
2057 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
,
2058 endpoint
->Y
- dy
, PathPointTypeBezier
);
2060 /* fourth 90-degree arc */
2061 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
+ dy2
,
2062 endpoint
->Y
- dy
- dx2
, PathPointTypeBezier
);
2063 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
- dx2
,
2064 endpoint
->Y
- dx
- dy2
, PathPointTypeBezier
);
2065 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
2066 endpoint
->Y
- dx
, PathPointTypeBezier
);
2070 case LineCapDiamondAnchor
:
2072 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
2073 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2074 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2075 REAL par_dx
, par_dy
;
2076 REAL perp_dx
, perp_dy
;
2078 par_dx
= -pen_width
* segment_dx
/ segment_length
;
2079 par_dy
= -pen_width
* segment_dy
/ segment_length
;
2081 perp_dx
= -pen_width
* segment_dy
/ segment_length
;
2082 perp_dy
= pen_width
* segment_dx
/ segment_length
;
2084 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
,
2085 endpoint
->Y
+ par_dy
, PathPointTypeStart
);
2086 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- perp_dx
,
2087 endpoint
->Y
- perp_dy
, PathPointTypeLine
);
2088 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
,
2089 endpoint
->Y
- par_dy
, PathPointTypeLine
);
2090 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ perp_dx
,
2091 endpoint
->Y
+ perp_dy
, PathPointTypeLine
);
2096 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2099 static void widen_open_figure(const GpPointF
*points
, int start
, int end
,
2100 GpPen
*pen
, REAL pen_width
, GpLineCap start_cap
, GpCustomLineCap
*start_custom
,
2101 GpLineCap end_cap
, GpCustomLineCap
*end_custom
, path_list_node_t
**last_point
)
2104 path_list_node_t
*prev_point
;
2106 if (end
<= start
|| pen_width
== 0.0)
2109 prev_point
= *last_point
;
2111 widen_cap(&points
[start
], &points
[start
+1],
2112 pen_width
, start_cap
, start_custom
, FALSE
, TRUE
, last_point
);
2114 for (i
=start
+1; i
<end
; i
++)
2115 widen_joint(&points
[i
-1], &points
[i
], &points
[i
+1],
2116 pen
, pen_width
, last_point
);
2118 widen_cap(&points
[end
], &points
[end
-1],
2119 pen_width
, end_cap
, end_custom
, TRUE
, TRUE
, last_point
);
2121 for (i
=end
-1; i
>start
; i
--)
2122 widen_joint(&points
[i
+1], &points
[i
], &points
[i
-1],
2123 pen
, pen_width
, last_point
);
2125 widen_cap(&points
[start
], &points
[start
+1],
2126 pen_width
, start_cap
, start_custom
, TRUE
, FALSE
, last_point
);
2128 prev_point
->next
->type
= PathPointTypeStart
;
2129 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2132 static void widen_closed_figure(GpPath
*path
, int start
, int end
,
2133 GpPen
*pen
, REAL pen_width
, path_list_node_t
**last_point
)
2136 path_list_node_t
*prev_point
;
2138 if (end
<= start
|| pen_width
== 0.0)
2142 prev_point
= *last_point
;
2144 widen_joint(&path
->pathdata
.Points
[end
], &path
->pathdata
.Points
[start
],
2145 &path
->pathdata
.Points
[start
+1], pen
, pen_width
, last_point
);
2147 for (i
=start
+1; i
<end
; i
++)
2148 widen_joint(&path
->pathdata
.Points
[i
-1], &path
->pathdata
.Points
[i
],
2149 &path
->pathdata
.Points
[i
+1], pen
, pen_width
, last_point
);
2151 widen_joint(&path
->pathdata
.Points
[end
-1], &path
->pathdata
.Points
[end
],
2152 &path
->pathdata
.Points
[start
], pen
, pen_width
, last_point
);
2154 prev_point
->next
->type
= PathPointTypeStart
;
2155 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2158 prev_point
= *last_point
;
2160 widen_joint(&path
->pathdata
.Points
[start
], &path
->pathdata
.Points
[end
],
2161 &path
->pathdata
.Points
[end
-1], pen
, pen_width
, last_point
);
2163 for (i
=end
-1; i
>start
; i
--)
2164 widen_joint(&path
->pathdata
.Points
[i
+1], &path
->pathdata
.Points
[i
],
2165 &path
->pathdata
.Points
[i
-1], pen
, pen_width
, last_point
);
2167 widen_joint(&path
->pathdata
.Points
[start
+1], &path
->pathdata
.Points
[start
],
2168 &path
->pathdata
.Points
[end
], pen
, pen_width
, last_point
);
2170 prev_point
->next
->type
= PathPointTypeStart
;
2171 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2174 static void widen_dashed_figure(GpPath
*path
, int start
, int end
, int closed
,
2175 GpPen
*pen
, REAL pen_width
, path_list_node_t
**last_point
)
2180 const REAL
*dash_pattern
;
2181 REAL
*dash_pattern_scaled
;
2183 GpPointF
*tmp_points
;
2186 REAL segment_length
;
2188 int num_tmp_points
=0;
2189 int draw_start_cap
=0;
2190 static const REAL dash_dot_dot
[6] = { 3.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
2192 if (end
<= start
|| pen_width
== 0.0)
2199 dash_pattern
= dash_dot_dot
;
2203 dash_pattern
= &dash_dot_dot
[2];
2206 case DashStyleDashDot
:
2207 dash_pattern
= dash_dot_dot
;
2210 case DashStyleDashDotDot
:
2211 dash_pattern
= dash_dot_dot
;
2214 case DashStyleCustom
:
2215 dash_pattern
= pen
->dashes
;
2216 dash_count
= pen
->numdashes
;
2220 dash_pattern_scaled
= heap_alloc(dash_count
* sizeof(REAL
));
2221 if (!dash_pattern_scaled
) return;
2223 for (i
= 0; i
< dash_count
; i
++)
2224 dash_pattern_scaled
[i
] = pen
->width
* dash_pattern
[i
];
2226 tmp_points
= heap_alloc_zero((end
- start
+ 2) * sizeof(GpPoint
));
2228 heap_free(dash_pattern_scaled
);
2235 for (j
=start
; j
<= end
; j
++)
2247 segment_dy
= path
->pathdata
.Points
[j
].Y
- path
->pathdata
.Points
[i
].Y
;
2248 segment_dx
= path
->pathdata
.Points
[j
].X
- path
->pathdata
.Points
[i
].X
;
2249 segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2254 if (dash_pos
== 0.0)
2256 if ((dash_index
% 2) == 0)
2260 tmp_points
[0].X
= path
->pathdata
.Points
[i
].X
+ segment_dx
* segment_pos
/ segment_length
;
2261 tmp_points
[0].Y
= path
->pathdata
.Points
[i
].Y
+ segment_dy
* segment_pos
/ segment_length
;
2266 tmp_points
[num_tmp_points
].X
= path
->pathdata
.Points
[i
].X
+ segment_dx
* segment_pos
/ segment_length
;
2267 tmp_points
[num_tmp_points
].Y
= path
->pathdata
.Points
[i
].Y
+ segment_dy
* segment_pos
/ segment_length
;
2269 widen_open_figure(tmp_points
, 0, num_tmp_points
, pen
, pen_width
,
2270 draw_start_cap
? pen
->startcap
: LineCapFlat
, pen
->customstart
,
2271 LineCapFlat
, NULL
, last_point
);
2277 if (dash_pattern_scaled
[dash_index
] - dash_pos
> segment_length
- segment_pos
)
2279 /* advance to next segment */
2280 if ((dash_index
% 2) == 0)
2282 tmp_points
[num_tmp_points
] = path
->pathdata
.Points
[j
];
2285 dash_pos
+= segment_length
- segment_pos
;
2290 /* advance to next dash in pattern */
2291 segment_pos
+= dash_pattern_scaled
[dash_index
] - dash_pos
;
2293 if (++dash_index
== dash_count
)
2300 if (dash_index
% 2 == 0 && num_tmp_points
!= 0)
2302 /* last dash overflows last segment */
2303 widen_open_figure(tmp_points
, 0, num_tmp_points
-1, pen
, pen_width
,
2304 draw_start_cap
? pen
->startcap
: LineCapFlat
, pen
->customstart
,
2305 closed
? LineCapFlat
: pen
->endcap
, pen
->customend
, last_point
);
2308 heap_free(dash_pattern_scaled
);
2309 heap_free(tmp_points
);
2312 GpStatus WINGDIPAPI
GdipWidenPath(GpPath
*path
, GpPen
*pen
, GpMatrix
*matrix
,
2315 GpPath
*flat_path
=NULL
;
2317 path_list_node_t
*points
=NULL
, *last_point
=NULL
;
2318 int i
, subpath_start
=0, new_length
;
2320 TRACE("(%p,%p,%p,%0.2f)\n", path
, pen
, matrix
, flatness
);
2323 return InvalidParameter
;
2325 if (path
->pathdata
.Count
<= 1)
2328 status
= GdipClonePath(path
, &flat_path
);
2331 status
= GdipFlattenPath(flat_path
, pen
->unit
== UnitPixel
? matrix
: NULL
, flatness
);
2333 if (status
== Ok
&& !init_path_list(&points
, 314.0, 22.0))
2334 status
= OutOfMemory
;
2338 REAL anchor_pen_width
= max(pen
->width
, 2.0);
2339 REAL pen_width
= (pen
->unit
== UnitWorld
) ? max(pen
->width
, 1.0) : pen
->width
;
2340 BYTE
*types
= flat_path
->pathdata
.Types
;
2342 last_point
= points
;
2344 if (pen
->endcap
> LineCapDiamondAnchor
)
2345 FIXME("unimplemented end cap %x\n", pen
->endcap
);
2347 if (pen
->startcap
> LineCapDiamondAnchor
)
2348 FIXME("unimplemented start cap %x\n", pen
->startcap
);
2350 if (pen
->dashcap
!= DashCapFlat
)
2351 FIXME("unimplemented dash cap %d\n", pen
->dashcap
);
2353 if (pen
->join
== LineJoinRound
)
2354 FIXME("unimplemented line join %d\n", pen
->join
);
2356 if (pen
->align
!= PenAlignmentCenter
)
2357 FIXME("unimplemented pen alignment %d\n", pen
->align
);
2359 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
2361 if ((types
[i
]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2364 if ((types
[i
]&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2366 if (pen
->dash
!= DashStyleSolid
)
2367 widen_dashed_figure(flat_path
, subpath_start
, i
, 1, pen
, pen_width
, &last_point
);
2369 widen_closed_figure(flat_path
, subpath_start
, i
, pen
, pen_width
, &last_point
);
2371 else if (i
== flat_path
->pathdata
.Count
-1 ||
2372 (types
[i
+1]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2374 if (pen
->dash
!= DashStyleSolid
)
2375 widen_dashed_figure(flat_path
, subpath_start
, i
, 0, pen
, pen_width
, &last_point
);
2377 widen_open_figure(flat_path
->pathdata
.Points
, subpath_start
, i
, pen
, pen_width
, pen
->startcap
, pen
->customstart
, pen
->endcap
, pen
->customend
, &last_point
);
2381 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
2383 if ((types
[i
]&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2386 if ((types
[i
]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2389 if (i
== flat_path
->pathdata
.Count
-1 ||
2390 (types
[i
+1]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2392 if (pen
->startcap
& LineCapAnchorMask
)
2393 add_anchor(&flat_path
->pathdata
.Points
[subpath_start
],
2394 &flat_path
->pathdata
.Points
[subpath_start
+1],
2395 anchor_pen_width
, pen
->startcap
, pen
->customstart
, &last_point
);
2397 if (pen
->endcap
& LineCapAnchorMask
)
2398 add_anchor(&flat_path
->pathdata
.Points
[i
],
2399 &flat_path
->pathdata
.Points
[i
-1],
2400 anchor_pen_width
, pen
->endcap
, pen
->customend
, &last_point
);
2404 new_length
= path_list_count(points
)-1;
2406 if (!lengthen_path(path
, new_length
))
2407 status
= OutOfMemory
;
2412 path
->pathdata
.Count
= new_length
;
2414 last_point
= points
->next
;
2415 for (i
= 0; i
< new_length
; i
++)
2417 path
->pathdata
.Points
[i
] = last_point
->pt
;
2418 path
->pathdata
.Types
[i
] = last_point
->type
;
2419 last_point
= last_point
->next
;
2422 path
->fill
= FillModeWinding
;
2425 free_path_list(points
);
2427 GdipDeletePath(flat_path
);
2429 if (status
== Ok
&& pen
->unit
!= UnitPixel
)
2430 status
= GdipTransformPath(path
, matrix
);
2435 GpStatus WINGDIPAPI
GdipAddPathRectangle(GpPath
*path
, REAL x
, REAL y
,
2436 REAL width
, REAL height
)
2443 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
2446 return InvalidParameter
;
2448 if (width
<= 0.0 || height
<= 0.0)
2451 /* make a backup copy of path data */
2452 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2455 /* rectangle should start as new path */
2456 old_new
= path
->newfigure
;
2457 path
->newfigure
= TRUE
;
2458 if((retstat
= GdipAddPathLine(path
,x
,y
,x
+width
,y
)) != Ok
){
2459 path
->newfigure
= old_new
;
2464 ptf
[0].Y
= y
+height
;
2466 ptf
[1].Y
= y
+height
;
2468 if((retstat
= GdipAddPathLine2(path
, ptf
, 2)) != Ok
) goto fail
;
2469 path
->pathdata
.Types
[path
->pathdata
.Count
-1] |= PathPointTypeCloseSubpath
;
2472 GdipDeletePath(backup
);
2477 heap_free(path
->pathdata
.Points
);
2478 heap_free(path
->pathdata
.Types
);
2479 memcpy(path
, backup
, sizeof(*path
));
2485 GpStatus WINGDIPAPI
GdipAddPathRectangleI(GpPath
*path
, INT x
, INT y
,
2486 INT width
, INT height
)
2488 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
2490 return GdipAddPathRectangle(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2493 GpStatus WINGDIPAPI
GdipAddPathRectangles(GpPath
*path
, GDIPCONST GpRectF
*rects
, INT count
)
2499 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2501 /* count == 0 - verified condition */
2502 if(!path
|| !rects
|| count
== 0)
2503 return InvalidParameter
;
2508 /* make a backup copy */
2509 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2512 for(i
= 0; i
< count
; i
++){
2513 if((retstat
= GdipAddPathRectangle(path
,rects
[i
].X
,rects
[i
].Y
,rects
[i
].Width
,rects
[i
].Height
)) != Ok
)
2518 GdipDeletePath(backup
);
2523 heap_free(path
->pathdata
.Points
);
2524 heap_free(path
->pathdata
.Types
);
2525 memcpy(path
, backup
, sizeof(*path
));
2531 GpStatus WINGDIPAPI
GdipAddPathRectanglesI(GpPath
*path
, GDIPCONST GpRect
*rects
, INT count
)
2537 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2539 if(!rects
|| count
== 0)
2540 return InvalidParameter
;
2545 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
2547 for(i
= 0;i
< count
;i
++)
2548 set_rect(&rectsF
[i
], rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2550 retstat
= GdipAddPathRectangles(path
, rectsF
, count
);
2556 GpStatus WINGDIPAPI
GdipSetPathMarker(GpPath
* path
)
2560 TRACE("(%p)\n", path
);
2563 return InvalidParameter
;
2565 count
= path
->pathdata
.Count
;
2567 /* set marker flag */
2569 path
->pathdata
.Types
[count
-1] |= PathPointTypePathMarker
;
2574 GpStatus WINGDIPAPI
GdipClearPathMarkers(GpPath
* path
)
2579 TRACE("(%p)\n", path
);
2582 return InvalidParameter
;
2584 count
= path
->pathdata
.Count
;
2586 for(i
= 0; i
< count
- 1; i
++){
2587 path
->pathdata
.Types
[i
] &= ~PathPointTypePathMarker
;
2593 GpStatus WINGDIPAPI
GdipWindingModeOutline(GpPath
*path
, GpMatrix
*matrix
, REAL flatness
)
2595 FIXME("stub: %p, %p, %.2f\n", path
, matrix
, flatness
);
2596 return NotImplemented
;
2599 #define FLAGS_INTPATH 0x4000
2608 /* Test to see if the path could be stored as an array of shorts */
2609 static BOOL
is_integer_path(const GpPath
*path
)
2613 if (!path
->pathdata
.Count
) return FALSE
;
2615 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2618 x
= gdip_round(path
->pathdata
.Points
[i
].X
);
2619 y
= gdip_round(path
->pathdata
.Points
[i
].Y
);
2620 if (path
->pathdata
.Points
[i
].X
!= (REAL
)x
|| path
->pathdata
.Points
[i
].Y
!= (REAL
)y
)
2626 DWORD
write_path_data(GpPath
*path
, void *data
)
2628 struct path_header
*header
= data
;
2629 BOOL integer_path
= is_integer_path(path
);
2633 size
= sizeof(struct path_header
) + path
->pathdata
.Count
;
2635 size
+= sizeof(short[2]) * path
->pathdata
.Count
;
2637 size
+= sizeof(float[2]) * path
->pathdata
.Count
;
2638 size
= (size
+ 3) & ~3;
2640 if (!data
) return size
;
2642 header
->version
= VERSION_MAGIC2
;
2643 header
->count
= path
->pathdata
.Count
;
2644 header
->flags
= integer_path
? FLAGS_INTPATH
: 0;
2648 short *points
= (short*)(header
+ 1);
2649 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2651 points
[2*i
] = path
->pathdata
.Points
[i
].X
;
2652 points
[2*i
+ 1] = path
->pathdata
.Points
[i
].Y
;
2654 types
= (BYTE
*)(points
+ 2*i
);
2658 float *points
= (float*)(header
+ 1);
2659 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2661 points
[2*i
] = path
->pathdata
.Points
[i
].X
;
2662 points
[2*i
+ 1] = path
->pathdata
.Points
[i
].Y
;
2664 types
= (BYTE
*)(points
+ 2*i
);
2667 for (i
=0; i
<path
->pathdata
.Count
; i
++)
2668 types
[i
] = path
->pathdata
.Types
[i
];
2669 memset(types
+ i
, 0, ((path
->pathdata
.Count
+ 3) & ~3) - path
->pathdata
.Count
);