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
, INT style
, REAL emSize
, GDIPCONST Rect
* layoutRect
, GDIPCONST GpStringFormat
* format
)
1087 RectF layoutRectF
= {
1088 (REAL
)layoutRect
->X
,
1089 (REAL
)layoutRect
->Y
,
1090 (REAL
)layoutRect
->Width
,
1091 (REAL
)layoutRect
->Height
1093 return GdipAddPathString(path
, string
, length
, family
, style
, emSize
, &layoutRectF
, format
);
1095 return InvalidParameter
;
1098 /*************************************************************************
1099 * GdipClonePath [GDIPLUS.53]
1101 * Duplicate the given path in memory.
1104 * path [I] The path to be duplicated
1105 * clone [O] Pointer to the new path
1108 * InvalidParameter If the input path is invalid
1109 * OutOfMemory If allocation of needed memory fails
1110 * Ok If everything works out as expected
1112 GpStatus WINGDIPAPI
GdipClonePath(GpPath
* path
, GpPath
**clone
)
1114 TRACE("(%p, %p)\n", path
, clone
);
1117 return InvalidParameter
;
1119 *clone
= heap_alloc_zero(sizeof(GpPath
));
1120 if(!*clone
) return OutOfMemory
;
1124 (*clone
)->pathdata
.Points
= heap_alloc_zero(path
->datalen
* sizeof(PointF
));
1125 (*clone
)->pathdata
.Types
= heap_alloc_zero(path
->datalen
);
1126 if(!(*clone
)->pathdata
.Points
|| !(*clone
)->pathdata
.Types
){
1127 heap_free((*clone
)->pathdata
.Points
);
1128 heap_free((*clone
)->pathdata
.Types
);
1133 memcpy((*clone
)->pathdata
.Points
, path
->pathdata
.Points
,
1134 path
->datalen
* sizeof(PointF
));
1135 memcpy((*clone
)->pathdata
.Types
, path
->pathdata
.Types
, path
->datalen
);
1140 GpStatus WINGDIPAPI
GdipClosePathFigure(GpPath
* path
)
1142 TRACE("(%p)\n", path
);
1145 return InvalidParameter
;
1147 if(path
->pathdata
.Count
> 0){
1148 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
1149 path
->newfigure
= TRUE
;
1155 GpStatus WINGDIPAPI
GdipClosePathFigures(GpPath
* path
)
1159 TRACE("(%p)\n", path
);
1162 return InvalidParameter
;
1164 for(i
= 1; i
< path
->pathdata
.Count
; i
++){
1165 if(path
->pathdata
.Types
[i
] == PathPointTypeStart
)
1166 path
->pathdata
.Types
[i
-1] |= PathPointTypeCloseSubpath
;
1169 path
->newfigure
= TRUE
;
1174 GpStatus WINGDIPAPI
GdipCreatePath(GpFillMode fill
, GpPath
**path
)
1176 TRACE("(%d, %p)\n", fill
, path
);
1179 return InvalidParameter
;
1181 *path
= heap_alloc_zero(sizeof(GpPath
));
1182 if(!*path
) return OutOfMemory
;
1184 (*path
)->fill
= fill
;
1185 (*path
)->newfigure
= TRUE
;
1190 GpStatus WINGDIPAPI
GdipCreatePath2(GDIPCONST GpPointF
* points
,
1191 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1195 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1197 if(!points
|| !types
|| !path
)
1198 return InvalidParameter
;
1205 *path
= heap_alloc_zero(sizeof(GpPath
));
1206 if(!*path
) return OutOfMemory
;
1208 if(count
> 1 && (types
[count
-1] & PathPointTypePathTypeMask
) == PathPointTypeStart
)
1211 for(i
= 1; i
< count
; i
++) {
1212 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
) {
1214 (types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeBezier
&&
1215 (types
[i
+2] & PathPointTypePathTypeMask
) == PathPointTypeBezier
)
1224 (*path
)->pathdata
.Points
= heap_alloc_zero(count
* sizeof(PointF
));
1225 (*path
)->pathdata
.Types
= heap_alloc_zero(count
);
1227 if(!(*path
)->pathdata
.Points
|| !(*path
)->pathdata
.Types
){
1228 heap_free((*path
)->pathdata
.Points
);
1229 heap_free((*path
)->pathdata
.Types
);
1234 memcpy((*path
)->pathdata
.Points
, points
, count
* sizeof(PointF
));
1235 memcpy((*path
)->pathdata
.Types
, types
, count
);
1237 (*path
)->pathdata
.Types
[0] = PathPointTypeStart
;
1238 (*path
)->pathdata
.Count
= count
;
1239 (*path
)->datalen
= count
;
1241 (*path
)->fill
= fill
;
1242 (*path
)->newfigure
= TRUE
;
1247 GpStatus WINGDIPAPI
GdipCreatePath2I(GDIPCONST GpPoint
* points
,
1248 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1254 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1256 ptF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1258 for(i
= 0;i
< count
; i
++){
1259 ptF
[i
].X
= (REAL
)points
[i
].X
;
1260 ptF
[i
].Y
= (REAL
)points
[i
].Y
;
1263 ret
= GdipCreatePath2(ptF
, types
, count
, fill
, path
);
1270 GpStatus WINGDIPAPI
GdipDeletePath(GpPath
*path
)
1272 TRACE("(%p)\n", path
);
1275 return InvalidParameter
;
1277 heap_free(path
->pathdata
.Points
);
1278 heap_free(path
->pathdata
.Types
);
1284 GpStatus WINGDIPAPI
GdipFlattenPath(GpPath
*path
, GpMatrix
* matrix
, REAL flatness
)
1286 path_list_node_t
*list
, *node
;
1292 TRACE("(%p, %p, %.2f)\n", path
, matrix
, flatness
);
1295 return InvalidParameter
;
1297 if(path
->pathdata
.Count
== 0)
1300 stat
= GdipTransformPath(path
, matrix
);
1304 pt
= path
->pathdata
.Points
[0];
1305 if(!init_path_list(&list
, pt
.X
, pt
.Y
))
1310 while(i
< path
->pathdata
.Count
){
1312 BYTE type
= path
->pathdata
.Types
[i
] & PathPointTypePathTypeMask
;
1313 path_list_node_t
*start
;
1315 pt
= path
->pathdata
.Points
[i
];
1317 /* save last start point index */
1318 if(type
== PathPointTypeStart
)
1321 /* always add line points and start points */
1322 if((type
== PathPointTypeStart
) || (type
== PathPointTypeLine
)){
1323 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, path
->pathdata
.Types
[i
]))
1333 /* test for closed figure */
1334 if(path
->pathdata
.Types
[i
+1] & PathPointTypeCloseSubpath
){
1335 pt
= path
->pathdata
.Points
[startidx
];
1341 pt
= path
->pathdata
.Points
[i
];
1345 /* add Bezier end point */
1346 type
= (path
->pathdata
.Types
[i
] & ~PathPointTypePathTypeMask
) | PathPointTypeLine
;
1347 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, type
))
1352 if(!flatten_bezier(start
, path
->pathdata
.Points
[i
-2].X
, path
->pathdata
.Points
[i
-2].Y
,
1353 path
->pathdata
.Points
[i
-1].X
, path
->pathdata
.Points
[i
-1].Y
,
1360 /* store path data back */
1361 i
= path_list_count(list
);
1362 if(!lengthen_path(path
, i
))
1364 path
->pathdata
.Count
= i
;
1367 for(i
= 0; i
< path
->pathdata
.Count
; i
++){
1368 path
->pathdata
.Points
[i
] = node
->pt
;
1369 path
->pathdata
.Types
[i
] = node
->type
;
1373 free_path_list(list
);
1377 free_path_list(list
);
1381 GpStatus WINGDIPAPI
GdipGetPathData(GpPath
*path
, GpPathData
* pathData
)
1383 TRACE("(%p, %p)\n", path
, pathData
);
1385 if(!path
|| !pathData
)
1386 return InvalidParameter
;
1388 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
1389 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
1390 memcpy(pathData
->Points
, path
->pathdata
.Points
, sizeof(PointF
) * pathData
->Count
);
1391 memcpy(pathData
->Types
, path
->pathdata
.Types
, pathData
->Count
);
1396 GpStatus WINGDIPAPI
GdipGetPathFillMode(GpPath
*path
, GpFillMode
*fillmode
)
1398 TRACE("(%p, %p)\n", path
, fillmode
);
1400 if(!path
|| !fillmode
)
1401 return InvalidParameter
;
1403 *fillmode
= path
->fill
;
1408 GpStatus WINGDIPAPI
GdipGetPathLastPoint(GpPath
* path
, GpPointF
* lastPoint
)
1412 TRACE("(%p, %p)\n", path
, lastPoint
);
1414 if(!path
|| !lastPoint
)
1415 return InvalidParameter
;
1417 count
= path
->pathdata
.Count
;
1419 *lastPoint
= path
->pathdata
.Points
[count
-1];
1424 GpStatus WINGDIPAPI
GdipGetPathPoints(GpPath
*path
, GpPointF
* points
, INT count
)
1426 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1429 return InvalidParameter
;
1431 if(count
< path
->pathdata
.Count
)
1432 return InsufficientBuffer
;
1434 memcpy(points
, path
->pathdata
.Points
, path
->pathdata
.Count
* sizeof(GpPointF
));
1439 GpStatus WINGDIPAPI
GdipGetPathPointsI(GpPath
*path
, GpPoint
* points
, INT count
)
1445 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1448 return InvalidParameter
;
1450 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1451 if(!ptf
) return OutOfMemory
;
1453 ret
= GdipGetPathPoints(path
,ptf
,count
);
1455 for(i
= 0;i
< count
;i
++){
1456 points
[i
].X
= gdip_round(ptf
[i
].X
);
1457 points
[i
].Y
= gdip_round(ptf
[i
].Y
);
1464 GpStatus WINGDIPAPI
GdipGetPathTypes(GpPath
*path
, BYTE
* types
, INT count
)
1466 TRACE("(%p, %p, %d)\n", path
, types
, count
);
1469 return InvalidParameter
;
1471 if(count
< path
->pathdata
.Count
)
1472 return InsufficientBuffer
;
1474 memcpy(types
, path
->pathdata
.Types
, path
->pathdata
.Count
);
1479 /* Windows expands the bounding box to the maximum possible bounding box
1480 * for a given pen. For example, if a line join can extend past the point
1481 * it's joining by x units, the bounding box is extended by x units in every
1482 * direction (even though this is too conservative for most cases). */
1483 GpStatus WINGDIPAPI
GdipGetPathWorldBounds(GpPath
* path
, GpRectF
* bounds
,
1484 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1486 GpPointF
* points
, temp_pts
[4];
1488 REAL path_width
= 1.0, width
, height
, temp
, low_x
, low_y
, high_x
, high_y
;
1490 TRACE("(%p, %p, %p, %p)\n", path
, bounds
, matrix
, pen
);
1492 /* Matrix and pen can be null. */
1493 if(!path
|| !bounds
)
1494 return InvalidParameter
;
1496 /* If path is empty just return. */
1497 count
= path
->pathdata
.Count
;
1499 bounds
->X
= bounds
->Y
= bounds
->Width
= bounds
->Height
= 0.0;
1503 points
= path
->pathdata
.Points
;
1505 low_x
= high_x
= points
[0].X
;
1506 low_y
= high_y
= points
[0].Y
;
1508 for(i
= 1; i
< count
; i
++){
1509 low_x
= min(low_x
, points
[i
].X
);
1510 low_y
= min(low_y
, points
[i
].Y
);
1511 high_x
= max(high_x
, points
[i
].X
);
1512 high_y
= max(high_y
, points
[i
].Y
);
1515 width
= high_x
- low_x
;
1516 height
= high_y
- low_y
;
1518 /* This looks unusual but it's the only way I can imitate windows. */
1520 temp_pts
[0].X
= low_x
;
1521 temp_pts
[0].Y
= low_y
;
1522 temp_pts
[1].X
= low_x
;
1523 temp_pts
[1].Y
= high_y
;
1524 temp_pts
[2].X
= high_x
;
1525 temp_pts
[2].Y
= high_y
;
1526 temp_pts
[3].X
= high_x
;
1527 temp_pts
[3].Y
= low_y
;
1529 GdipTransformMatrixPoints((GpMatrix
*)matrix
, temp_pts
, 4);
1530 low_x
= temp_pts
[0].X
;
1531 low_y
= temp_pts
[0].Y
;
1533 for(i
= 1; i
< 4; i
++){
1534 low_x
= min(low_x
, temp_pts
[i
].X
);
1535 low_y
= min(low_y
, temp_pts
[i
].Y
);
1539 width
= height
* fabs(matrix
->matrix
[2]) + width
* fabs(matrix
->matrix
[0]);
1540 height
= height
* fabs(matrix
->matrix
[3]) + temp
* fabs(matrix
->matrix
[1]);
1544 path_width
= pen
->width
/ 2.0;
1547 path_width
= max(path_width
, pen
->width
* pen
->miterlimit
/ 2.0);
1548 /* FIXME: this should probably also check for the startcap */
1549 if(pen
->endcap
& LineCapNoAnchor
)
1550 path_width
= max(path_width
, pen
->width
* 2.2);
1552 low_x
-= path_width
;
1553 low_y
-= path_width
;
1554 width
+= 2.0 * path_width
;
1555 height
+= 2.0 * path_width
;
1560 bounds
->Width
= width
;
1561 bounds
->Height
= height
;
1566 GpStatus WINGDIPAPI
GdipGetPathWorldBoundsI(GpPath
* path
, GpRect
* bounds
,
1567 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1572 TRACE("(%p, %p, %p, %p)\n", path
, bounds
, matrix
, pen
);
1574 ret
= GdipGetPathWorldBounds(path
,&boundsF
,matrix
,pen
);
1577 bounds
->X
= gdip_round(boundsF
.X
);
1578 bounds
->Y
= gdip_round(boundsF
.Y
);
1579 bounds
->Width
= gdip_round(boundsF
.Width
);
1580 bounds
->Height
= gdip_round(boundsF
.Height
);
1586 GpStatus WINGDIPAPI
GdipGetPointCount(GpPath
*path
, INT
*count
)
1588 TRACE("(%p, %p)\n", path
, count
);
1591 return InvalidParameter
;
1593 *count
= path
->pathdata
.Count
;
1598 GpStatus WINGDIPAPI
GdipReversePath(GpPath
* path
)
1601 INT start
= 0; /* position in reversed path */
1604 TRACE("(%p)\n", path
);
1607 return InvalidParameter
;
1609 count
= path
->pathdata
.Count
;
1611 if(count
== 0) return Ok
;
1613 revpath
.Points
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1614 revpath
.Types
= heap_alloc_zero(sizeof(BYTE
)*count
);
1615 revpath
.Count
= count
;
1616 if(!revpath
.Points
|| !revpath
.Types
){
1617 heap_free(revpath
.Points
);
1618 heap_free(revpath
.Types
);
1622 for(i
= 0; i
< count
; i
++){
1624 /* find next start point */
1625 if(path
->pathdata
.Types
[count
-i
-1] == PathPointTypeStart
){
1627 for(j
= start
; j
<= i
; j
++){
1628 revpath
.Points
[j
] = path
->pathdata
.Points
[count
-j
-1];
1629 revpath
.Types
[j
] = path
->pathdata
.Types
[count
-j
-1];
1631 /* mark start point */
1632 revpath
.Types
[start
] = PathPointTypeStart
;
1633 /* set 'figure' endpoint type */
1635 revpath
.Types
[i
] = path
->pathdata
.Types
[count
-start
-1] & ~PathPointTypePathTypeMask
;
1636 revpath
.Types
[i
] |= revpath
.Types
[i
-1];
1639 revpath
.Types
[i
] = path
->pathdata
.Types
[start
];
1645 memcpy(path
->pathdata
.Points
, revpath
.Points
, sizeof(GpPointF
)*count
);
1646 memcpy(path
->pathdata
.Types
, revpath
.Types
, sizeof(BYTE
)*count
);
1648 heap_free(revpath
.Points
);
1649 heap_free(revpath
.Types
);
1654 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPointI(GpPath
* path
, INT x
, INT y
,
1655 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1657 TRACE("(%p, %d, %d, %p, %p, %p)\n", path
, x
, y
, pen
, graphics
, result
);
1659 return GdipIsOutlineVisiblePathPoint(path
, x
, y
, pen
, graphics
, result
);
1662 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
,
1663 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1667 GpMatrix
*transform
= NULL
;
1669 TRACE("(%p,%0.2f,%0.2f,%p,%p,%p)\n", path
, x
, y
, pen
, graphics
, result
);
1672 return InvalidParameter
;
1674 stat
= GdipClonePath(path
, &wide_path
);
1679 if (pen
->unit
== UnitPixel
&& graphics
!= NULL
)
1681 stat
= GdipCreateMatrix(&transform
);
1684 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1685 CoordinateSpaceWorld
, transform
);
1689 stat
= GdipWidenPath(wide_path
, pen
, transform
, 1.0);
1691 if (pen
->unit
== UnitPixel
&& graphics
!= NULL
)
1694 stat
= GdipInvertMatrix(transform
);
1697 stat
= GdipTransformPath(wide_path
, transform
);
1701 stat
= GdipIsVisiblePathPoint(wide_path
, x
, y
, graphics
, result
);
1703 GdipDeleteMatrix(transform
);
1705 GdipDeletePath(wide_path
);
1710 GpStatus WINGDIPAPI
GdipIsVisiblePathPointI(GpPath
* path
, INT x
, INT y
, GpGraphics
*graphics
, BOOL
*result
)
1712 TRACE("(%p, %d, %d, %p, %p)\n", path
, x
, y
, graphics
, result
);
1714 return GdipIsVisiblePathPoint(path
, x
, y
, graphics
, result
);
1717 /*****************************************************************************
1718 * GdipIsVisiblePathPoint [GDIPLUS.@]
1720 GpStatus WINGDIPAPI
GdipIsVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
, GpGraphics
*graphics
, BOOL
*result
)
1726 if(!path
|| !result
) return InvalidParameter
;
1728 status
= GdipCreateRegionPath(path
, ®ion
);
1732 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
1734 GdipDeleteRegion(region
);
1738 *result
= PtInRegion(hrgn
, gdip_round(x
), gdip_round(y
));
1741 GdipDeleteRegion(region
);
1746 GpStatus WINGDIPAPI
GdipStartPathFigure(GpPath
*path
)
1748 TRACE("(%p)\n", path
);
1751 return InvalidParameter
;
1753 path
->newfigure
= TRUE
;
1758 GpStatus WINGDIPAPI
GdipResetPath(GpPath
*path
)
1760 TRACE("(%p)\n", path
);
1763 return InvalidParameter
;
1765 path
->pathdata
.Count
= 0;
1766 path
->newfigure
= TRUE
;
1767 path
->fill
= FillModeAlternate
;
1772 GpStatus WINGDIPAPI
GdipSetPathFillMode(GpPath
*path
, GpFillMode fill
)
1774 TRACE("(%p, %d)\n", path
, fill
);
1777 return InvalidParameter
;
1784 GpStatus WINGDIPAPI
GdipTransformPath(GpPath
*path
, GpMatrix
*matrix
)
1786 TRACE("(%p, %p)\n", path
, matrix
);
1789 return InvalidParameter
;
1791 if(path
->pathdata
.Count
== 0 || !matrix
)
1794 return GdipTransformMatrixPoints(matrix
, path
->pathdata
.Points
,
1795 path
->pathdata
.Count
);
1798 GpStatus WINGDIPAPI
GdipWarpPath(GpPath
*path
, GpMatrix
* matrix
,
1799 GDIPCONST GpPointF
*points
, INT count
, REAL x
, REAL y
, REAL width
,
1800 REAL height
, WarpMode warpmode
, REAL flatness
)
1802 FIXME("(%p,%p,%p,%i,%0.2f,%0.2f,%0.2f,%0.2f,%i,%0.2f)\n", path
, matrix
,
1803 points
, count
, x
, y
, width
, height
, warpmode
, flatness
);
1805 return NotImplemented
;
1808 static void add_bevel_point(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1809 REAL pen_width
, int right_side
, path_list_node_t
**last_point
)
1811 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1812 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1813 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1814 REAL distance
= pen_width
/ 2.0;
1815 REAL bevel_dx
, bevel_dy
;
1817 if (segment_length
== 0.0)
1819 *last_point
= add_path_list_node(*last_point
, endpoint
->X
,
1820 endpoint
->Y
, PathPointTypeLine
);
1826 bevel_dx
= -distance
* segment_dy
/ segment_length
;
1827 bevel_dy
= distance
* segment_dx
/ segment_length
;
1831 bevel_dx
= distance
* segment_dy
/ segment_length
;
1832 bevel_dy
= -distance
* segment_dx
/ segment_length
;
1835 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ bevel_dx
,
1836 endpoint
->Y
+ bevel_dy
, PathPointTypeLine
);
1839 static void widen_joint(const GpPointF
*p1
, const GpPointF
*p2
, const GpPointF
*p3
,
1840 GpPen
* pen
, REAL pen_width
, path_list_node_t
**last_point
)
1845 case LineJoinMiterClipped
:
1846 if ((p2
->X
- p1
->X
) * (p3
->Y
- p1
->Y
) > (p2
->Y
- p1
->Y
) * (p3
->X
- p1
->X
))
1848 float distance
= pen_width
/ 2.0;
1849 float length_0
= sqrtf((p2
->X
-p1
->X
)*(p2
->X
-p1
->X
)+(p2
->Y
-p1
->Y
)*(p2
->Y
-p1
->Y
));
1850 float length_1
= sqrtf((p3
->X
-p2
->X
)*(p3
->X
-p2
->X
)+(p3
->Y
-p2
->Y
)*(p3
->Y
-p2
->Y
));
1851 float dx0
= distance
* (p2
->X
- p1
->X
) / length_0
;
1852 float dy0
= distance
* (p2
->Y
- p1
->Y
) / length_0
;
1853 float dx1
= distance
* (p3
->X
- p2
->X
) / length_1
;
1854 float dy1
= distance
* (p3
->Y
- p2
->Y
) / length_1
;
1855 float det
= (dy0
*dx1
- dx0
*dy1
);
1856 float dx
= (dx0
*dx1
*(dx0
-dx1
) + dy0
*dy0
*dx1
- dy1
*dy1
*dx0
)/det
;
1857 float dy
= (dy0
*dy1
*(dy0
-dy1
) + dx0
*dx0
*dy1
- dx1
*dx1
*dy0
)/det
;
1858 if (dx
*dx
+ dy
*dy
< pen
->miterlimit
*pen
->miterlimit
* distance
*distance
)
1860 *last_point
= add_path_list_node(*last_point
, p2
->X
+ dx
,
1861 p2
->Y
+ dy
, PathPointTypeLine
);
1864 else if (pen
->join
== LineJoinMiter
)
1868 FIXME("should add a clipped corner\n");
1870 /* else fall-through */
1872 /* else fall-through */
1875 add_bevel_point(p2
, p1
, pen_width
, 1, last_point
);
1876 add_bevel_point(p2
, p3
, pen_width
, 0, last_point
);
1881 static void widen_cap(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1882 REAL pen_width
, GpLineCap cap
, GpCustomLineCap
*custom
, int add_first_points
,
1883 int add_last_point
, path_list_node_t
**last_point
)
1889 if (add_first_points
)
1890 add_bevel_point(endpoint
, nextpoint
, pen_width
, 1, last_point
);
1892 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
1896 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1897 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1898 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1899 REAL distance
= pen_width
/ 2.0;
1900 REAL bevel_dx
, bevel_dy
;
1901 REAL extend_dx
, extend_dy
;
1903 extend_dx
= -distance
* segment_dx
/ segment_length
;
1904 extend_dy
= -distance
* segment_dy
/ segment_length
;
1906 bevel_dx
= -distance
* segment_dy
/ segment_length
;
1907 bevel_dy
= distance
* segment_dx
/ segment_length
;
1909 if (add_first_points
)
1910 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ extend_dx
+ bevel_dx
,
1911 endpoint
->Y
+ extend_dy
+ bevel_dy
, PathPointTypeLine
);
1914 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ extend_dx
- bevel_dx
,
1915 endpoint
->Y
+ extend_dy
- bevel_dy
, PathPointTypeLine
);
1921 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1922 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1923 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1924 REAL distance
= pen_width
/ 2.0;
1925 REAL dx
, dy
, dx2
, dy2
;
1926 const REAL control_point_distance
= 0.5522847498307935; /* 4/3 * (sqrt(2) - 1) */
1928 if (add_first_points
)
1930 dx
= -distance
* segment_dx
/ segment_length
;
1931 dy
= -distance
* segment_dy
/ segment_length
;
1933 dx2
= dx
* control_point_distance
;
1934 dy2
= dy
* control_point_distance
;
1936 /* first 90-degree arc */
1937 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
1938 endpoint
->Y
- dx
, PathPointTypeLine
);
1940 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
+ dx2
,
1941 endpoint
->Y
- dx
+ dy2
, PathPointTypeBezier
);
1943 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
+ dy2
,
1944 endpoint
->Y
+ dy
- dx2
, PathPointTypeBezier
);
1947 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
,
1948 endpoint
->Y
+ dy
, PathPointTypeBezier
);
1950 /* second 90-degree arc */
1951 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
- dy2
,
1952 endpoint
->Y
+ dy
+ dx2
, PathPointTypeBezier
);
1954 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
+ dx2
,
1955 endpoint
->Y
+ dx
+ dy2
, PathPointTypeBezier
);
1957 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
,
1958 endpoint
->Y
+ dx
, PathPointTypeBezier
);
1960 else if (add_last_point
)
1961 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
1964 case LineCapTriangle
:
1966 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1967 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1968 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1969 REAL distance
= pen_width
/ 2.0;
1972 dx
= distance
* segment_dx
/ segment_length
;
1973 dy
= distance
* segment_dy
/ segment_length
;
1975 if (add_first_points
) {
1976 add_bevel_point(endpoint
, nextpoint
, pen_width
, 1, last_point
);
1978 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
,
1979 endpoint
->Y
- dy
, PathPointTypeLine
);
1981 if (add_first_points
|| add_last_point
)
1982 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
1988 static void add_anchor(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1989 REAL pen_width
, GpLineCap cap
, GpCustomLineCap
*custom
, path_list_node_t
**last_point
)
1994 case LineCapNoAnchor
:
1996 case LineCapSquareAnchor
:
1998 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1999 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2000 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2001 REAL distance
= pen_width
/ sqrtf(2.0);
2002 REAL par_dx
, par_dy
;
2003 REAL perp_dx
, perp_dy
;
2005 par_dx
= -distance
* segment_dx
/ segment_length
;
2006 par_dy
= -distance
* segment_dy
/ segment_length
;
2008 perp_dx
= -distance
* segment_dy
/ segment_length
;
2009 perp_dy
= distance
* segment_dx
/ segment_length
;
2011 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
- perp_dx
,
2012 endpoint
->Y
- par_dy
- perp_dy
, PathPointTypeStart
);
2013 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
+ perp_dx
,
2014 endpoint
->Y
- par_dy
+ perp_dy
, PathPointTypeLine
);
2015 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
+ perp_dx
,
2016 endpoint
->Y
+ par_dy
+ perp_dy
, PathPointTypeLine
);
2017 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
- perp_dx
,
2018 endpoint
->Y
+ par_dy
- perp_dy
, PathPointTypeLine
);
2021 case LineCapRoundAnchor
:
2023 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
2024 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2025 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2026 REAL dx
, dy
, dx2
, dy2
;
2027 const REAL control_point_distance
= 0.55228475; /* 4/3 * (sqrt(2) - 1) */
2029 dx
= -pen_width
* segment_dx
/ segment_length
;
2030 dy
= -pen_width
* segment_dy
/ segment_length
;
2032 dx2
= dx
* control_point_distance
;
2033 dy2
= dy
* control_point_distance
;
2035 /* starting point */
2036 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
2037 endpoint
->Y
- dx
, PathPointTypeStart
);
2039 /* first 90-degree arc */
2040 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
+ dx2
,
2041 endpoint
->Y
- dx
+ dy2
, PathPointTypeBezier
);
2042 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
+ dy2
,
2043 endpoint
->Y
+ dy
- dx2
, PathPointTypeBezier
);
2044 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
,
2045 endpoint
->Y
+ dy
, PathPointTypeBezier
);
2047 /* second 90-degree arc */
2048 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
- dy2
,
2049 endpoint
->Y
+ dy
+ dx2
, PathPointTypeBezier
);
2050 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
+ dx2
,
2051 endpoint
->Y
+ dx
+ dy2
, PathPointTypeBezier
);
2052 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
,
2053 endpoint
->Y
+ dx
, PathPointTypeBezier
);
2055 /* third 90-degree arc */
2056 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
- dx2
,
2057 endpoint
->Y
+ dx
- dy2
, PathPointTypeBezier
);
2058 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
- dy2
,
2059 endpoint
->Y
- dy
+ dx2
, PathPointTypeBezier
);
2060 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
,
2061 endpoint
->Y
- dy
, PathPointTypeBezier
);
2063 /* fourth 90-degree arc */
2064 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
+ dy2
,
2065 endpoint
->Y
- dy
- dx2
, PathPointTypeBezier
);
2066 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
- dx2
,
2067 endpoint
->Y
- dx
- dy2
, PathPointTypeBezier
);
2068 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
2069 endpoint
->Y
- dx
, PathPointTypeBezier
);
2073 case LineCapDiamondAnchor
:
2075 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
2076 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2077 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2078 REAL par_dx
, par_dy
;
2079 REAL perp_dx
, perp_dy
;
2081 par_dx
= -pen_width
* segment_dx
/ segment_length
;
2082 par_dy
= -pen_width
* segment_dy
/ segment_length
;
2084 perp_dx
= -pen_width
* segment_dy
/ segment_length
;
2085 perp_dy
= pen_width
* segment_dx
/ segment_length
;
2087 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
,
2088 endpoint
->Y
+ par_dy
, PathPointTypeStart
);
2089 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- perp_dx
,
2090 endpoint
->Y
- perp_dy
, PathPointTypeLine
);
2091 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
,
2092 endpoint
->Y
- par_dy
, PathPointTypeLine
);
2093 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ perp_dx
,
2094 endpoint
->Y
+ perp_dy
, PathPointTypeLine
);
2099 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2102 static void widen_open_figure(const GpPointF
*points
, int start
, int end
,
2103 GpPen
*pen
, REAL pen_width
, GpLineCap start_cap
, GpCustomLineCap
*start_custom
,
2104 GpLineCap end_cap
, GpCustomLineCap
*end_custom
, path_list_node_t
**last_point
)
2107 path_list_node_t
*prev_point
;
2109 if (end
<= start
|| pen_width
== 0.0)
2112 prev_point
= *last_point
;
2114 widen_cap(&points
[start
], &points
[start
+1],
2115 pen_width
, start_cap
, start_custom
, FALSE
, TRUE
, last_point
);
2117 for (i
=start
+1; i
<end
; i
++)
2118 widen_joint(&points
[i
-1], &points
[i
], &points
[i
+1],
2119 pen
, pen_width
, last_point
);
2121 widen_cap(&points
[end
], &points
[end
-1],
2122 pen_width
, end_cap
, end_custom
, TRUE
, TRUE
, last_point
);
2124 for (i
=end
-1; i
>start
; i
--)
2125 widen_joint(&points
[i
+1], &points
[i
], &points
[i
-1],
2126 pen
, pen_width
, last_point
);
2128 widen_cap(&points
[start
], &points
[start
+1],
2129 pen_width
, start_cap
, start_custom
, TRUE
, FALSE
, last_point
);
2131 prev_point
->next
->type
= PathPointTypeStart
;
2132 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2135 static void widen_closed_figure(GpPath
*path
, int start
, int end
,
2136 GpPen
*pen
, REAL pen_width
, path_list_node_t
**last_point
)
2139 path_list_node_t
*prev_point
;
2141 if (end
<= start
|| pen_width
== 0.0)
2145 prev_point
= *last_point
;
2147 widen_joint(&path
->pathdata
.Points
[end
], &path
->pathdata
.Points
[start
],
2148 &path
->pathdata
.Points
[start
+1], pen
, pen_width
, last_point
);
2150 for (i
=start
+1; i
<end
; i
++)
2151 widen_joint(&path
->pathdata
.Points
[i
-1], &path
->pathdata
.Points
[i
],
2152 &path
->pathdata
.Points
[i
+1], pen
, pen_width
, last_point
);
2154 widen_joint(&path
->pathdata
.Points
[end
-1], &path
->pathdata
.Points
[end
],
2155 &path
->pathdata
.Points
[start
], pen
, pen_width
, last_point
);
2157 prev_point
->next
->type
= PathPointTypeStart
;
2158 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2161 prev_point
= *last_point
;
2163 widen_joint(&path
->pathdata
.Points
[start
], &path
->pathdata
.Points
[end
],
2164 &path
->pathdata
.Points
[end
-1], pen
, pen_width
, last_point
);
2166 for (i
=end
-1; i
>start
; i
--)
2167 widen_joint(&path
->pathdata
.Points
[i
+1], &path
->pathdata
.Points
[i
],
2168 &path
->pathdata
.Points
[i
-1], pen
, pen_width
, last_point
);
2170 widen_joint(&path
->pathdata
.Points
[start
+1], &path
->pathdata
.Points
[start
],
2171 &path
->pathdata
.Points
[end
], pen
, pen_width
, last_point
);
2173 prev_point
->next
->type
= PathPointTypeStart
;
2174 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2177 static void widen_dashed_figure(GpPath
*path
, int start
, int end
, int closed
,
2178 GpPen
*pen
, REAL pen_width
, path_list_node_t
**last_point
)
2183 const REAL
*dash_pattern
;
2184 REAL
*dash_pattern_scaled
;
2186 GpPointF
*tmp_points
;
2189 REAL segment_length
;
2191 int num_tmp_points
=0;
2192 int draw_start_cap
=0;
2193 static const REAL dash_dot_dot
[6] = { 3.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
2195 if (end
<= start
|| pen_width
== 0.0)
2202 dash_pattern
= dash_dot_dot
;
2206 dash_pattern
= &dash_dot_dot
[2];
2209 case DashStyleDashDot
:
2210 dash_pattern
= dash_dot_dot
;
2213 case DashStyleDashDotDot
:
2214 dash_pattern
= dash_dot_dot
;
2217 case DashStyleCustom
:
2218 dash_pattern
= pen
->dashes
;
2219 dash_count
= pen
->numdashes
;
2223 dash_pattern_scaled
= heap_alloc(dash_count
* sizeof(REAL
));
2224 if (!dash_pattern_scaled
) return;
2226 for (i
= 0; i
< dash_count
; i
++)
2227 dash_pattern_scaled
[i
] = pen
->width
* dash_pattern
[i
];
2229 tmp_points
= heap_alloc_zero((end
- start
+ 2) * sizeof(GpPoint
));
2231 heap_free(dash_pattern_scaled
);
2238 for (j
=start
; j
<= end
; j
++)
2250 segment_dy
= path
->pathdata
.Points
[j
].Y
- path
->pathdata
.Points
[i
].Y
;
2251 segment_dx
= path
->pathdata
.Points
[j
].X
- path
->pathdata
.Points
[i
].X
;
2252 segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2257 if (dash_pos
== 0.0)
2259 if ((dash_index
% 2) == 0)
2263 tmp_points
[0].X
= path
->pathdata
.Points
[i
].X
+ segment_dx
* segment_pos
/ segment_length
;
2264 tmp_points
[0].Y
= path
->pathdata
.Points
[i
].Y
+ segment_dy
* segment_pos
/ segment_length
;
2269 tmp_points
[num_tmp_points
].X
= path
->pathdata
.Points
[i
].X
+ segment_dx
* segment_pos
/ segment_length
;
2270 tmp_points
[num_tmp_points
].Y
= path
->pathdata
.Points
[i
].Y
+ segment_dy
* segment_pos
/ segment_length
;
2272 widen_open_figure(tmp_points
, 0, num_tmp_points
, pen
, pen_width
,
2273 draw_start_cap
? pen
->startcap
: LineCapFlat
, pen
->customstart
,
2274 LineCapFlat
, NULL
, last_point
);
2280 if (dash_pattern_scaled
[dash_index
] - dash_pos
> segment_length
- segment_pos
)
2282 /* advance to next segment */
2283 if ((dash_index
% 2) == 0)
2285 tmp_points
[num_tmp_points
] = path
->pathdata
.Points
[j
];
2288 dash_pos
+= segment_length
- segment_pos
;
2293 /* advance to next dash in pattern */
2294 segment_pos
+= dash_pattern_scaled
[dash_index
] - dash_pos
;
2296 if (++dash_index
== dash_count
)
2303 if (dash_index
% 2 == 0 && num_tmp_points
!= 0)
2305 /* last dash overflows last segment */
2306 widen_open_figure(tmp_points
, 0, num_tmp_points
-1, pen
, pen_width
,
2307 draw_start_cap
? pen
->startcap
: LineCapFlat
, pen
->customstart
,
2308 closed
? LineCapFlat
: pen
->endcap
, pen
->customend
, last_point
);
2311 heap_free(dash_pattern_scaled
);
2312 heap_free(tmp_points
);
2315 GpStatus WINGDIPAPI
GdipWidenPath(GpPath
*path
, GpPen
*pen
, GpMatrix
*matrix
,
2318 GpPath
*flat_path
=NULL
;
2320 path_list_node_t
*points
=NULL
, *last_point
=NULL
;
2321 int i
, subpath_start
=0, new_length
;
2323 TRACE("(%p,%p,%p,%0.2f)\n", path
, pen
, matrix
, flatness
);
2326 return InvalidParameter
;
2328 if (path
->pathdata
.Count
<= 1)
2331 status
= GdipClonePath(path
, &flat_path
);
2334 status
= GdipFlattenPath(flat_path
, pen
->unit
== UnitPixel
? matrix
: NULL
, flatness
);
2336 if (status
== Ok
&& !init_path_list(&points
, 314.0, 22.0))
2337 status
= OutOfMemory
;
2341 REAL anchor_pen_width
= max(pen
->width
, 2.0);
2342 REAL pen_width
= (pen
->unit
== UnitWorld
) ? max(pen
->width
, 1.0) : pen
->width
;
2343 BYTE
*types
= flat_path
->pathdata
.Types
;
2345 last_point
= points
;
2347 if (pen
->endcap
> LineCapDiamondAnchor
)
2348 FIXME("unimplemented end cap %x\n", pen
->endcap
);
2350 if (pen
->startcap
> LineCapDiamondAnchor
)
2351 FIXME("unimplemented start cap %x\n", pen
->startcap
);
2353 if (pen
->dashcap
!= DashCapFlat
)
2354 FIXME("unimplemented dash cap %d\n", pen
->dashcap
);
2356 if (pen
->join
== LineJoinRound
)
2357 FIXME("unimplemented line join %d\n", pen
->join
);
2359 if (pen
->align
!= PenAlignmentCenter
)
2360 FIXME("unimplemented pen alignment %d\n", pen
->align
);
2362 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
2364 if ((types
[i
]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2367 if ((types
[i
]&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2369 if (pen
->dash
!= DashStyleSolid
)
2370 widen_dashed_figure(flat_path
, subpath_start
, i
, 1, pen
, pen_width
, &last_point
);
2372 widen_closed_figure(flat_path
, subpath_start
, i
, pen
, pen_width
, &last_point
);
2374 else if (i
== flat_path
->pathdata
.Count
-1 ||
2375 (types
[i
+1]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2377 if (pen
->dash
!= DashStyleSolid
)
2378 widen_dashed_figure(flat_path
, subpath_start
, i
, 0, pen
, pen_width
, &last_point
);
2380 widen_open_figure(flat_path
->pathdata
.Points
, subpath_start
, i
, pen
, pen_width
, pen
->startcap
, pen
->customstart
, pen
->endcap
, pen
->customend
, &last_point
);
2384 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
2386 if ((types
[i
]&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2389 if ((types
[i
]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2392 if (i
== flat_path
->pathdata
.Count
-1 ||
2393 (types
[i
+1]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2395 if (pen
->startcap
& LineCapAnchorMask
)
2396 add_anchor(&flat_path
->pathdata
.Points
[subpath_start
],
2397 &flat_path
->pathdata
.Points
[subpath_start
+1],
2398 anchor_pen_width
, pen
->startcap
, pen
->customstart
, &last_point
);
2400 if (pen
->endcap
& LineCapAnchorMask
)
2401 add_anchor(&flat_path
->pathdata
.Points
[i
],
2402 &flat_path
->pathdata
.Points
[i
-1],
2403 anchor_pen_width
, pen
->endcap
, pen
->customend
, &last_point
);
2407 new_length
= path_list_count(points
)-1;
2409 if (!lengthen_path(path
, new_length
))
2410 status
= OutOfMemory
;
2415 path
->pathdata
.Count
= new_length
;
2417 last_point
= points
->next
;
2418 for (i
= 0; i
< new_length
; i
++)
2420 path
->pathdata
.Points
[i
] = last_point
->pt
;
2421 path
->pathdata
.Types
[i
] = last_point
->type
;
2422 last_point
= last_point
->next
;
2425 path
->fill
= FillModeWinding
;
2428 free_path_list(points
);
2430 GdipDeletePath(flat_path
);
2432 if (status
== Ok
&& pen
->unit
!= UnitPixel
)
2433 status
= GdipTransformPath(path
, matrix
);
2438 GpStatus WINGDIPAPI
GdipAddPathRectangle(GpPath
*path
, REAL x
, REAL y
,
2439 REAL width
, REAL height
)
2446 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
2449 return InvalidParameter
;
2451 if (width
<= 0.0 || height
<= 0.0)
2454 /* make a backup copy of path data */
2455 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2458 /* rectangle should start as new path */
2459 old_new
= path
->newfigure
;
2460 path
->newfigure
= TRUE
;
2461 if((retstat
= GdipAddPathLine(path
,x
,y
,x
+width
,y
)) != Ok
){
2462 path
->newfigure
= old_new
;
2467 ptf
[0].Y
= y
+height
;
2469 ptf
[1].Y
= y
+height
;
2471 if((retstat
= GdipAddPathLine2(path
, ptf
, 2)) != Ok
) goto fail
;
2472 path
->pathdata
.Types
[path
->pathdata
.Count
-1] |= PathPointTypeCloseSubpath
;
2475 GdipDeletePath(backup
);
2480 heap_free(path
->pathdata
.Points
);
2481 heap_free(path
->pathdata
.Types
);
2482 memcpy(path
, backup
, sizeof(*path
));
2488 GpStatus WINGDIPAPI
GdipAddPathRectangleI(GpPath
*path
, INT x
, INT y
,
2489 INT width
, INT height
)
2491 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
2493 return GdipAddPathRectangle(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2496 GpStatus WINGDIPAPI
GdipAddPathRectangles(GpPath
*path
, GDIPCONST GpRectF
*rects
, INT count
)
2502 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2504 /* count == 0 - verified condition */
2505 if(!path
|| !rects
|| count
== 0)
2506 return InvalidParameter
;
2511 /* make a backup copy */
2512 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2515 for(i
= 0; i
< count
; i
++){
2516 if((retstat
= GdipAddPathRectangle(path
,rects
[i
].X
,rects
[i
].Y
,rects
[i
].Width
,rects
[i
].Height
)) != Ok
)
2521 GdipDeletePath(backup
);
2526 heap_free(path
->pathdata
.Points
);
2527 heap_free(path
->pathdata
.Types
);
2528 memcpy(path
, backup
, sizeof(*path
));
2534 GpStatus WINGDIPAPI
GdipAddPathRectanglesI(GpPath
*path
, GDIPCONST GpRect
*rects
, INT count
)
2540 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2542 if(!rects
|| count
== 0)
2543 return InvalidParameter
;
2548 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
2550 for(i
= 0;i
< count
;i
++){
2551 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2552 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2553 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2554 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2557 retstat
= GdipAddPathRectangles(path
, rectsF
, count
);
2563 GpStatus WINGDIPAPI
GdipSetPathMarker(GpPath
* path
)
2567 TRACE("(%p)\n", path
);
2570 return InvalidParameter
;
2572 count
= path
->pathdata
.Count
;
2574 /* set marker flag */
2576 path
->pathdata
.Types
[count
-1] |= PathPointTypePathMarker
;
2581 GpStatus WINGDIPAPI
GdipClearPathMarkers(GpPath
* path
)
2586 TRACE("(%p)\n", path
);
2589 return InvalidParameter
;
2591 count
= path
->pathdata
.Count
;
2593 for(i
= 0; i
< count
- 1; i
++){
2594 path
->pathdata
.Types
[i
] &= ~PathPointTypePathMarker
;
2600 GpStatus WINGDIPAPI
GdipWindingModeOutline(GpPath
*path
, GpMatrix
*matrix
, REAL flatness
)
2602 FIXME("stub: %p, %p, %.2f\n", path
, matrix
, flatness
);
2603 return NotImplemented
;
2606 #define FLAGS_INTPATH 0x4000
2615 /* Test to see if the path could be stored as an array of shorts */
2616 static BOOL
is_integer_path(const GpPath
*path
)
2620 if (!path
->pathdata
.Count
) return FALSE
;
2622 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2625 x
= gdip_round(path
->pathdata
.Points
[i
].X
);
2626 y
= gdip_round(path
->pathdata
.Points
[i
].Y
);
2627 if (path
->pathdata
.Points
[i
].X
!= (REAL
)x
|| path
->pathdata
.Points
[i
].Y
!= (REAL
)y
)
2633 DWORD
write_path_data(GpPath
*path
, void *data
)
2635 struct path_header
*header
= data
;
2636 BOOL integer_path
= is_integer_path(path
);
2640 size
= sizeof(struct path_header
) + path
->pathdata
.Count
;
2642 size
+= sizeof(short[2]) * path
->pathdata
.Count
;
2644 size
+= sizeof(float[2]) * path
->pathdata
.Count
;
2645 size
= (size
+ 3) & ~3;
2647 if (!data
) return size
;
2649 header
->version
= VERSION_MAGIC2
;
2650 header
->count
= path
->pathdata
.Count
;
2651 header
->flags
= integer_path
? FLAGS_INTPATH
: 0;
2655 short *points
= (short*)(header
+ 1);
2656 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2658 points
[2*i
] = path
->pathdata
.Points
[i
].X
;
2659 points
[2*i
+ 1] = path
->pathdata
.Points
[i
].Y
;
2661 types
= (BYTE
*)(points
+ 2*i
);
2665 float *points
= (float*)(header
+ 1);
2666 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2668 points
[2*i
] = path
->pathdata
.Points
[i
].X
;
2669 points
[2*i
+ 1] = path
->pathdata
.Points
[i
].Y
;
2671 types
= (BYTE
*)(points
+ 2*i
);
2674 for (i
=0; i
<path
->pathdata
.Count
; i
++)
2675 types
[i
] = path
->pathdata
.Types
[i
];
2676 memset(types
+ i
, 0, ((path
->pathdata
.Count
+ 3) & ~3) - path
->pathdata
.Count
);