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 #define SQRT3 1.73205080757
38 typedef struct path_list_node_t path_list_node_t
;
39 struct path_list_node_t
{
41 BYTE type
; /* PathPointTypeStart or PathPointTypeLine */
42 path_list_node_t
*next
;
46 static BOOL
init_path_list(path_list_node_t
**node
, REAL x
, REAL y
)
48 *node
= heap_alloc_zero(sizeof(path_list_node_t
));
54 (*node
)->type
= PathPointTypeStart
;
60 /* free all nodes including argument */
61 static void free_path_list(path_list_node_t
*node
)
63 path_list_node_t
*n
= node
;
72 /* Add a node after 'node' */
76 * NULL on allocation problems
78 static path_list_node_t
* add_path_list_node(path_list_node_t
*node
, REAL x
, REAL y
, BOOL type
)
80 path_list_node_t
*new;
82 new = heap_alloc_zero(sizeof(path_list_node_t
));
89 new->next
= node
->next
;
95 /* returns element count */
96 static INT
path_list_count(path_list_node_t
*node
)
100 while((node
= node
->next
))
106 /* GdipFlattenPath helper */
108 * Used to recursively flatten single Bezier curve
110 * - start : pointer to start point node;
111 * - (x2, y2): first control point;
112 * - (x3, y3): second control point;
113 * - end : pointer to end point node
114 * - flatness: admissible error of linear approximation.
118 * FALSE: out of memory
120 * TODO: used quality criteria should be revised to match native as
121 * closer as possible.
123 static BOOL
flatten_bezier(path_list_node_t
*start
, REAL x2
, REAL y2
, REAL x3
, REAL y3
,
124 path_list_node_t
*end
, REAL flatness
)
126 /* this 5 middle points with start/end define to half-curves */
129 path_list_node_t
*node
;
131 /* calculate bezier curve middle points == new control points */
132 mp
[0].X
= (start
->pt
.X
+ x2
) / 2.0;
133 mp
[0].Y
= (start
->pt
.Y
+ y2
) / 2.0;
134 /* middle point between control points */
135 pt
.X
= (x2
+ x3
) / 2.0;
136 pt
.Y
= (y2
+ y3
) / 2.0;
137 mp
[1].X
= (mp
[0].X
+ pt
.X
) / 2.0;
138 mp
[1].Y
= (mp
[0].Y
+ pt
.Y
) / 2.0;
139 mp
[4].X
= (end
->pt
.X
+ x3
) / 2.0;
140 mp
[4].Y
= (end
->pt
.Y
+ y3
) / 2.0;
141 mp
[3].X
= (mp
[4].X
+ pt
.X
) / 2.0;
142 mp
[3].Y
= (mp
[4].Y
+ pt
.Y
) / 2.0;
144 mp
[2].X
= (mp
[1].X
+ mp
[3].X
) / 2.0;
145 mp
[2].Y
= (mp
[1].Y
+ mp
[3].Y
) / 2.0;
147 if ((x2
== mp
[0].X
&& y2
== mp
[0].Y
&& x3
== mp
[1].X
&& y3
== mp
[1].Y
) ||
148 (x2
== mp
[3].X
&& y2
== mp
[3].Y
&& x3
== mp
[4].X
&& y3
== mp
[4].Y
))
153 /* check flatness as a half of distance between middle point and a linearized path */
154 if(fabs(((pt
.Y
- pt_st
.Y
)*mp
[2].X
+ (pt_st
.X
- pt
.X
)*mp
[2].Y
+
155 (pt_st
.Y
*pt
.X
- pt_st
.X
*pt
.Y
))) <=
156 (0.5 * flatness
*sqrtf((powf(pt
.Y
- pt_st
.Y
, 2.0) + powf(pt_st
.X
- pt
.X
, 2.0))))){
160 /* add a middle point */
161 if(!(node
= add_path_list_node(start
, mp
[2].X
, mp
[2].Y
, PathPointTypeLine
)))
164 /* do the same with halves */
165 flatten_bezier(start
, mp
[0].X
, mp
[0].Y
, mp
[1].X
, mp
[1].Y
, node
, flatness
);
166 flatten_bezier(node
, mp
[3].X
, mp
[3].Y
, mp
[4].X
, mp
[4].Y
, end
, flatness
);
171 /* GdipAddPath* helper
173 * Several GdipAddPath functions are expected to add onto an open figure.
174 * So if the first point being added is an exact match to the last point
175 * of the existing line, that point should not be added.
178 * path : path to which points should be added
179 * points : array of points to add
180 * count : number of points to add (at least 1)
181 * type : type of the points being added
184 * OutOfMemory : out of memory, could not lengthen path
187 static GpStatus
extend_current_figure(GpPath
*path
, GDIPCONST PointF
*points
, INT count
, BYTE type
)
189 INT insert_index
= path
->pathdata
.Count
;
190 BYTE first_point_type
= (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
192 if(!path
->newfigure
&&
193 path
->pathdata
.Points
[insert_index
-1].X
== points
[0].X
&&
194 path
->pathdata
.Points
[insert_index
-1].Y
== points
[0].Y
)
198 first_point_type
= type
;
204 if(!lengthen_path(path
, count
))
207 memcpy(path
->pathdata
.Points
+ insert_index
, points
, sizeof(GpPointF
)*count
);
208 path
->pathdata
.Types
[insert_index
] = first_point_type
;
209 memset(path
->pathdata
.Types
+ insert_index
+ 1, type
, count
- 1);
211 path
->newfigure
= FALSE
;
212 path
->pathdata
.Count
+= count
;
217 /*******************************************************************************
218 * GdipAddPathArc [GDIPLUS.1]
220 * Add an elliptical arc to the given path.
223 * path [I/O] Path that the arc is appended to
224 * x1 [I] X coordinate of the boundary box
225 * y1 [I] Y coordinate of the boundary box
226 * x2 [I] Width of the boundary box
227 * y2 [I] Height of the boundary box
228 * startAngle [I] Starting angle of the arc, clockwise
229 * sweepAngle [I] Angle of the arc, clockwise
232 * InvalidParameter If the given path is invalid
233 * OutOfMemory If memory allocation fails, i.e. the path cannot be lengthened
234 * Ok If everything works out as expected
237 * This functions takes the newfigure value of the given path into account,
238 * i.e. the arc is connected to the end of the given path if it was set to
239 * FALSE, otherwise the arc's first point gets the PathPointTypeStart value.
240 * In both cases, the value of newfigure of the given path is FALSE
243 GpStatus WINGDIPAPI
GdipAddPathArc(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
244 REAL y2
, REAL startAngle
, REAL sweepAngle
)
250 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
251 path
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
254 return InvalidParameter
;
256 count
= arc2polybezier(NULL
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
260 points
= heap_alloc_zero(sizeof(GpPointF
)*count
);
264 arc2polybezier(points
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
266 status
= extend_current_figure(path
, points
, count
, PathPointTypeBezier
);
272 /*******************************************************************************
273 * GdipAddPathArcI [GDUPLUS.2]
277 GpStatus WINGDIPAPI
GdipAddPathArcI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
278 INT y2
, REAL startAngle
, REAL sweepAngle
)
280 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
281 path
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
283 return GdipAddPathArc(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,startAngle
,sweepAngle
);
286 GpStatus WINGDIPAPI
GdipAddPathBezier(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
287 REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
291 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
292 path
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
295 return InvalidParameter
;
306 return extend_current_figure(path
, points
, 4, PathPointTypeBezier
);
309 GpStatus WINGDIPAPI
GdipAddPathBezierI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
310 INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
312 TRACE("(%p, %d, %d, %d, %d, %d, %d, %d, %d)\n",
313 path
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
315 return GdipAddPathBezier(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,(REAL
)x3
,(REAL
)y3
,
319 GpStatus WINGDIPAPI
GdipAddPathBeziers(GpPath
*path
, GDIPCONST GpPointF
*points
,
322 TRACE("(%p, %p, %d)\n", path
, points
, count
);
324 if(!path
|| !points
|| ((count
- 1) % 3))
325 return InvalidParameter
;
327 return extend_current_figure(path
, points
, count
, PathPointTypeBezier
);
330 GpStatus WINGDIPAPI
GdipAddPathBeziersI(GpPath
*path
, GDIPCONST GpPoint
*points
,
337 TRACE("(%p, %p, %d)\n", path
, points
, count
);
339 if(!points
|| ((count
- 1) % 3))
340 return InvalidParameter
;
342 ptsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
346 for(i
= 0; i
< count
; i
++){
347 ptsF
[i
].X
= (REAL
)points
[i
].X
;
348 ptsF
[i
].Y
= (REAL
)points
[i
].Y
;
351 ret
= GdipAddPathBeziers(path
, ptsF
, count
);
357 GpStatus WINGDIPAPI
GdipAddPathClosedCurve(GpPath
*path
, GDIPCONST GpPointF
*points
,
360 TRACE("(%p, %p, %d)\n", path
, points
, count
);
362 return GdipAddPathClosedCurve2(path
, points
, count
, 1.0);
365 GpStatus WINGDIPAPI
GdipAddPathClosedCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
,
368 TRACE("(%p, %p, %d)\n", path
, points
, count
);
370 return GdipAddPathClosedCurve2I(path
, points
, count
, 1.0);
373 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
,
374 INT count
, REAL tension
)
376 INT i
, len_pt
= (count
+ 1)*3-2;
382 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
384 if(!path
|| !points
|| count
<= 1)
385 return InvalidParameter
;
387 pt
= heap_alloc_zero(len_pt
* sizeof(GpPointF
));
388 pts
= heap_alloc_zero((count
+ 1)*sizeof(GpPointF
));
395 /* copy source points to extend with the last one */
396 memcpy(pts
, points
, sizeof(GpPointF
)*count
);
399 tension
= tension
* TENSION_CONST
;
401 for(i
= 0; i
< count
-1; i
++){
402 calc_curve_bezier(&(pts
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
406 pt
[3*i
+3].X
= pts
[i
+1].X
;
407 pt
[3*i
+3].Y
= pts
[i
+1].Y
;
412 /* points [len_pt-2] and [0] are calculated
413 separately to connect splines properly */
414 pts
[0] = points
[count
-1];
415 pts
[1] = points
[0]; /* equals to start and end of a resulting path */
418 calc_curve_bezier(pts
, tension
, &x1
, &y1
, &x2
, &y2
);
426 pt
[len_pt
-1].X
= pt
[0].X
;
427 pt
[len_pt
-1].Y
= pt
[0].Y
;
429 stat
= extend_current_figure(path
, pt
, len_pt
, PathPointTypeBezier
);
433 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
434 path
->newfigure
= TRUE
;
443 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
444 INT count
, REAL tension
)
450 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
452 if(!path
|| !points
|| count
<= 1)
453 return InvalidParameter
;
455 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
459 for(i
= 0; i
< count
; i
++){
460 ptf
[i
].X
= (REAL
)points
[i
].X
;
461 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
464 stat
= GdipAddPathClosedCurve2(path
, ptf
, count
, tension
);
471 GpStatus WINGDIPAPI
GdipAddPathCurve(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
473 TRACE("(%p, %p, %d)\n", path
, points
, count
);
475 if(!path
|| !points
|| count
<= 1)
476 return InvalidParameter
;
478 return GdipAddPathCurve2(path
, points
, count
, 1.0);
481 GpStatus WINGDIPAPI
GdipAddPathCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
483 TRACE("(%p, %p, %d)\n", path
, points
, count
);
485 if(!path
|| !points
|| count
<= 1)
486 return InvalidParameter
;
488 return GdipAddPathCurve2I(path
, points
, count
, 1.0);
491 GpStatus WINGDIPAPI
GdipAddPathCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
,
494 INT i
, len_pt
= count
*3-2;
499 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
501 if(!path
|| !points
|| count
<= 1)
502 return InvalidParameter
;
504 pt
= heap_alloc_zero(len_pt
* sizeof(GpPointF
));
508 tension
= tension
* TENSION_CONST
;
510 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
513 pt
[0].X
= points
[0].X
;
514 pt
[0].Y
= points
[0].Y
;
518 for(i
= 0; i
< count
-2; i
++){
519 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
523 pt
[3*i
+3].X
= points
[i
+1].X
;
524 pt
[3*i
+3].Y
= points
[i
+1].Y
;
529 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
530 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
534 pt
[len_pt
-1].X
= points
[count
-1].X
;
535 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
537 stat
= extend_current_figure(path
, pt
, len_pt
, PathPointTypeBezier
);
544 GpStatus WINGDIPAPI
GdipAddPathCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
545 INT count
, REAL tension
)
551 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
553 if(!path
|| !points
|| count
<= 1)
554 return InvalidParameter
;
556 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
560 for(i
= 0; i
< count
; i
++){
561 ptf
[i
].X
= (REAL
)points
[i
].X
;
562 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
565 stat
= GdipAddPathCurve2(path
, ptf
, count
, tension
);
572 GpStatus WINGDIPAPI
GdipAddPathCurve3(GpPath
*path
, GDIPCONST GpPointF
*points
,
573 INT count
, INT offset
, INT nseg
, REAL tension
)
575 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path
, points
, count
, offset
, nseg
, tension
);
577 if(!path
|| !points
|| offset
+ 1 >= count
|| count
- offset
< nseg
+ 1)
578 return InvalidParameter
;
580 return GdipAddPathCurve2(path
, &points
[offset
], nseg
+ 1, tension
);
583 GpStatus WINGDIPAPI
GdipAddPathCurve3I(GpPath
*path
, GDIPCONST GpPoint
*points
,
584 INT count
, INT offset
, INT nseg
, REAL tension
)
586 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path
, points
, count
, offset
, nseg
, tension
);
588 if(!path
|| !points
|| offset
+ 1 >= count
|| count
- offset
< nseg
+ 1)
589 return InvalidParameter
;
591 return GdipAddPathCurve2I(path
, &points
[offset
], nseg
+ 1, tension
);
594 GpStatus WINGDIPAPI
GdipAddPathEllipse(GpPath
*path
, REAL x
, REAL y
, REAL width
,
597 INT old_count
, numpts
;
599 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
602 return InvalidParameter
;
604 if(!lengthen_path(path
, MAX_ARC_PTS
))
607 old_count
= path
->pathdata
.Count
;
608 if((numpts
= arc2polybezier(&path
->pathdata
.Points
[old_count
], x
, y
, width
,
609 height
, 0.0, 360.0)) != MAX_ARC_PTS
){
610 ERR("expected %d points but got %d\n", MAX_ARC_PTS
, numpts
);
614 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeBezier
,
617 /* An ellipse is an intrinsic figure (always is its own subpath). */
618 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
619 path
->pathdata
.Types
[old_count
+ MAX_ARC_PTS
- 1] |= PathPointTypeCloseSubpath
;
620 path
->newfigure
= TRUE
;
621 path
->pathdata
.Count
+= MAX_ARC_PTS
;
626 GpStatus WINGDIPAPI
GdipAddPathEllipseI(GpPath
*path
, INT x
, INT y
, INT width
,
629 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
631 return GdipAddPathEllipse(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
634 GpStatus WINGDIPAPI
GdipAddPathLine2(GpPath
*path
, GDIPCONST GpPointF
*points
,
637 TRACE("(%p, %p, %d)\n", path
, points
, count
);
639 if(!path
|| !points
|| count
< 1)
640 return InvalidParameter
;
642 return extend_current_figure(path
, points
, count
, PathPointTypeLine
);
645 GpStatus WINGDIPAPI
GdipAddPathLine2I(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
651 TRACE("(%p, %p, %d)\n", path
, points
, count
);
654 return InvalidParameter
;
656 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
657 if(!pointsF
) return OutOfMemory
;
659 for(i
= 0;i
< count
; i
++){
660 pointsF
[i
].X
= (REAL
)points
[i
].X
;
661 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
664 stat
= GdipAddPathLine2(path
, pointsF
, count
);
671 /*************************************************************************
672 * GdipAddPathLine [GDIPLUS.21]
674 * Add two points to the given path.
677 * path [I/O] Path that the line is appended to
678 * x1 [I] X coordinate of the first point of the line
679 * y1 [I] Y coordinate of the first point of the line
680 * x2 [I] X coordinate of the second point of the line
681 * y2 [I] Y coordinate of the second point of the line
684 * InvalidParameter If the first parameter is not a valid path
685 * OutOfMemory If the path cannot be lengthened, i.e. memory allocation fails
686 * Ok If everything works out as expected
689 * This functions takes the newfigure value of the given path into account,
690 * i.e. the two new points are connected to the end of the given path if it
691 * was set to FALSE, otherwise the first point is given the PathPointTypeStart
692 * value. In both cases, the value of newfigure of the given path is FALSE
695 GpStatus WINGDIPAPI
GdipAddPathLine(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
699 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x1
, y1
, x2
, y2
);
702 return InvalidParameter
;
709 return extend_current_figure(path
, points
, 2, PathPointTypeLine
);
712 /*************************************************************************
713 * GdipAddPathLineI [GDIPLUS.21]
715 * See GdipAddPathLine
717 GpStatus WINGDIPAPI
GdipAddPathLineI(GpPath
*path
, INT x1
, INT y1
, INT x2
, INT y2
)
719 TRACE("(%p, %d, %d, %d, %d)\n", path
, x1
, y1
, x2
, y2
);
721 return GdipAddPathLine(path
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
724 GpStatus WINGDIPAPI
GdipAddPathPath(GpPath
*path
, GDIPCONST GpPath
* addingPath
,
727 INT old_count
, count
;
729 TRACE("(%p, %p, %d)\n", path
, addingPath
, connect
);
731 if(!path
|| !addingPath
)
732 return InvalidParameter
;
734 old_count
= path
->pathdata
.Count
;
735 count
= addingPath
->pathdata
.Count
;
737 if(!lengthen_path(path
, count
))
740 memcpy(&path
->pathdata
.Points
[old_count
], addingPath
->pathdata
.Points
,
741 count
* sizeof(GpPointF
));
742 memcpy(&path
->pathdata
.Types
[old_count
], addingPath
->pathdata
.Types
, count
);
744 if(path
->newfigure
|| !connect
)
745 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
747 path
->pathdata
.Types
[old_count
] = PathPointTypeLine
;
749 path
->newfigure
= FALSE
;
750 path
->pathdata
.Count
+= count
;
755 GpStatus WINGDIPAPI
GdipAddPathPie(GpPath
*path
, REAL x
, REAL y
, REAL width
, REAL height
,
756 REAL startAngle
, REAL sweepAngle
)
762 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
763 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
766 return InvalidParameter
;
768 /* on zero width/height only start point added */
769 if(width
<= 1e-7 || height
<= 1e-7){
770 if(!lengthen_path(path
, 1))
772 path
->pathdata
.Points
[0].X
= x
+ width
/ 2.0;
773 path
->pathdata
.Points
[0].Y
= y
+ height
/ 2.0;
774 path
->pathdata
.Types
[0] = PathPointTypeStart
| PathPointTypeCloseSubpath
;
775 path
->pathdata
.Count
= 1;
776 return InvalidParameter
;
779 count
= arc2polybezier(NULL
, x
, y
, width
, height
, startAngle
, sweepAngle
);
784 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
788 arc2polybezier(ptf
, x
, y
, width
, height
, startAngle
, sweepAngle
);
790 status
= GdipAddPathLine(path
, x
+ width
/2, y
+ height
/2, ptf
[0].X
, ptf
[0].Y
);
795 /* one spline is already added as a line endpoint */
796 if(!lengthen_path(path
, count
- 1)){
801 memcpy(&(path
->pathdata
.Points
[path
->pathdata
.Count
]), &(ptf
[1]),sizeof(GpPointF
)*(count
-1));
802 for(i
= 0; i
< count
-1; i
++)
803 path
->pathdata
.Types
[path
->pathdata
.Count
+i
] = PathPointTypeBezier
;
805 path
->pathdata
.Count
+= count
-1;
807 GdipClosePathFigure(path
);
814 GpStatus WINGDIPAPI
GdipAddPathPieI(GpPath
*path
, INT x
, INT y
, INT width
, INT height
,
815 REAL startAngle
, REAL sweepAngle
)
817 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
818 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
820 return GdipAddPathPie(path
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, startAngle
, sweepAngle
);
823 GpStatus WINGDIPAPI
GdipAddPathPolygon(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
827 TRACE("(%p, %p, %d)\n", path
, points
, count
);
829 if(!path
|| !points
|| count
< 3)
830 return InvalidParameter
;
832 if(!lengthen_path(path
, count
))
835 old_count
= path
->pathdata
.Count
;
837 memcpy(&path
->pathdata
.Points
[old_count
], points
, count
*sizeof(GpPointF
));
838 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeLine
, count
- 1);
840 /* A polygon is an intrinsic figure */
841 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
842 path
->pathdata
.Types
[old_count
+ count
- 1] |= PathPointTypeCloseSubpath
;
843 path
->newfigure
= TRUE
;
844 path
->pathdata
.Count
+= count
;
849 GpStatus WINGDIPAPI
GdipAddPathPolygonI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
855 TRACE("(%p, %p, %d)\n", path
, points
, count
);
857 if(!points
|| count
< 3)
858 return InvalidParameter
;
860 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
864 for(i
= 0; i
< count
; i
++){
865 ptf
[i
].X
= (REAL
)points
[i
].X
;
866 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
869 status
= GdipAddPathPolygon(path
, ptf
, count
);
876 static float fromfixedpoint(const FIXED v
)
878 float f
= ((float)v
.fract
) / (1<<(sizeof(v
.fract
)*8));
883 struct format_string_args
891 static GpStatus
format_string_callback(HDC dc
,
892 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
893 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
894 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
895 INT underlined_index_count
, void *priv
)
897 static const MAT2 identity
= { {0,1}, {0,0}, {0,0}, {0,1} };
898 struct format_string_args
*args
= priv
;
899 GpPath
*path
= args
->path
;
900 GpStatus status
= Ok
;
901 float x
= rect
->X
+ (bounds
->X
- rect
->X
) * args
->scale
;
902 float y
= rect
->Y
+ (bounds
->Y
- rect
->Y
) * args
->scale
;
905 if (underlined_index_count
)
906 FIXME("hotkey underlines not drawn yet\n");
908 if (y
+ bounds
->Height
* args
->scale
> args
->maxY
)
909 args
->maxY
= y
+ bounds
->Height
* args
->scale
;
911 for (i
= index
; i
< length
+ index
; ++i
)
914 TTPOLYGONHEADER
*ph
= NULL
, *origph
;
917 len
= GetGlyphOutlineW(dc
, string
[i
], GGO_BEZIER
, &gm
, 0, NULL
, &identity
);
918 if (len
== GDI_ERROR
)
920 status
= GenericError
;
923 origph
= ph
= heap_alloc_zero(len
);
925 if (!ph
|| !lengthen_path(path
, len
/ sizeof(POINTFX
)))
928 status
= OutOfMemory
;
931 GetGlyphOutlineW(dc
, string
[i
], GGO_BEZIER
, &gm
, len
, start
, &identity
);
936 DWORD ofs_start
= ofs
;
937 ph
= (TTPOLYGONHEADER
*)&start
[ofs
];
938 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeStart
;
939 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(ph
->pfxStart
.x
) * args
->scale
;
940 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(ph
->pfxStart
.y
) * args
->scale
;
941 TRACE("Starting at count %i with pos %f, %f)\n", path
->pathdata
.Count
, x
, y
);
943 while (ofs
- ofs_start
< ph
->cb
)
945 TTPOLYCURVE
*curve
= (TTPOLYCURVE
*)&start
[ofs
];
947 ofs
+= sizeof(TTPOLYCURVE
) + (curve
->cpfx
- 1) * sizeof(POINTFX
);
949 switch (curve
->wType
)
952 for (j
= 0; j
< curve
->cpfx
; ++j
)
954 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeLine
;
955 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(curve
->apfx
[j
].x
) * args
->scale
;
956 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(curve
->apfx
[j
].y
) * args
->scale
;
959 case TT_PRIM_CSPLINE
:
960 for (j
= 0; j
< curve
->cpfx
; ++j
)
962 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeBezier
;
963 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(curve
->apfx
[j
].x
) * args
->scale
;
964 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(curve
->apfx
[j
].y
) * args
->scale
;
968 ERR("Unhandled type: %u\n", curve
->wType
);
969 status
= GenericError
;
972 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
974 path
->newfigure
= TRUE
;
975 x
+= gm
.gmCellIncX
* args
->scale
;
976 y
+= gm
.gmCellIncY
* args
->scale
;
986 GpStatus WINGDIPAPI
GdipAddPathString(GpPath
* path
, GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFontFamily
* family
, INT style
, REAL emSize
, GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
* format
)
993 GpGraphics
*graphics
;
995 struct format_string_args args
;
997 UINT16 native_height
;
998 RectF scaled_layout_rect
;
999 TEXTMETRICW textmetric
;
1001 TRACE("(%p, %s, %d, %p, %d, %f, %p, %p)\n", path
, debugstr_w(string
), length
, family
, style
, emSize
, layoutRect
, format
);
1002 if (!path
|| !string
|| !family
|| !emSize
|| !layoutRect
|| !format
)
1003 return InvalidParameter
;
1005 status
= GdipGetEmHeight(family
, style
, &native_height
);
1009 scaled_layout_rect
.X
= layoutRect
->X
;
1010 scaled_layout_rect
.Y
= layoutRect
->Y
;
1011 scaled_layout_rect
.Width
= layoutRect
->Width
* native_height
/ emSize
;
1012 scaled_layout_rect
.Height
= layoutRect
->Height
* native_height
/ emSize
;
1014 if ((status
= GdipClonePath(path
, &backup
)) != Ok
)
1017 dc
= CreateCompatibleDC(0);
1018 status
= GdipCreateFromHDC(dc
, &graphics
);
1022 GdipDeletePath(backup
);
1026 status
= GdipCreateFont(family
, native_height
, style
, UnitPixel
, &font
);
1029 GdipDeleteGraphics(graphics
);
1031 GdipDeletePath(backup
);
1035 get_log_fontW(font
, graphics
, &lfw
);
1036 GdipDeleteFont(font
);
1037 GdipDeleteGraphics(graphics
);
1039 hfont
= CreateFontIndirectW(&lfw
);
1042 WARN("Failed to create font\n");
1044 GdipDeletePath(backup
);
1045 return GenericError
;
1048 SelectObject(dc
, hfont
);
1050 GetTextMetricsW(dc
, &textmetric
);
1054 args
.scale
= emSize
/ native_height
;
1055 args
.ascent
= textmetric
.tmAscent
* args
.scale
;
1056 status
= gdip_format_string(dc
, string
, length
, NULL
, &scaled_layout_rect
,
1057 format
, TRUE
, format_string_callback
, &args
);
1060 DeleteObject(hfont
);
1062 if (status
!= Ok
) /* free backup */
1064 heap_free(path
->pathdata
.Points
);
1065 heap_free(path
->pathdata
.Types
);
1070 if (format
->line_align
== StringAlignmentCenter
&& layoutRect
->Y
+ args
.maxY
< layoutRect
->Height
)
1072 float inc
= layoutRect
->Height
+ layoutRect
->Y
- args
.maxY
;
1074 for (i
= backup
->pathdata
.Count
; i
< path
->pathdata
.Count
; ++i
)
1075 path
->pathdata
.Points
[i
].Y
+= inc
;
1076 } else if (format
->line_align
== StringAlignmentFar
) {
1077 float inc
= layoutRect
->Height
+ layoutRect
->Y
- args
.maxY
;
1078 for (i
= backup
->pathdata
.Count
; i
< path
->pathdata
.Count
; ++i
)
1079 path
->pathdata
.Points
[i
].Y
+= inc
;
1081 GdipDeletePath(backup
);
1085 GpStatus WINGDIPAPI
GdipAddPathStringI(GpPath
* path
, GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFontFamily
* family
,
1086 INT style
, REAL emSize
, GDIPCONST Rect
* layoutRect
, GDIPCONST GpStringFormat
* format
)
1091 return InvalidParameter
;
1093 set_rect(&rect
, layoutRect
->X
, layoutRect
->Y
, layoutRect
->Width
, layoutRect
->Height
);
1094 return GdipAddPathString(path
, string
, length
, family
, style
, emSize
, &rect
, format
);
1097 /*************************************************************************
1098 * GdipClonePath [GDIPLUS.53]
1100 * Duplicate the given path in memory.
1103 * path [I] The path to be duplicated
1104 * clone [O] Pointer to the new path
1107 * InvalidParameter If the input path is invalid
1108 * OutOfMemory If allocation of needed memory fails
1109 * Ok If everything works out as expected
1111 GpStatus WINGDIPAPI
GdipClonePath(GpPath
* path
, GpPath
**clone
)
1113 TRACE("(%p, %p)\n", path
, clone
);
1116 return InvalidParameter
;
1118 *clone
= heap_alloc_zero(sizeof(GpPath
));
1119 if(!*clone
) return OutOfMemory
;
1123 (*clone
)->pathdata
.Points
= heap_alloc_zero(path
->datalen
* sizeof(PointF
));
1124 (*clone
)->pathdata
.Types
= heap_alloc_zero(path
->datalen
);
1125 if(!(*clone
)->pathdata
.Points
|| !(*clone
)->pathdata
.Types
){
1126 heap_free((*clone
)->pathdata
.Points
);
1127 heap_free((*clone
)->pathdata
.Types
);
1132 memcpy((*clone
)->pathdata
.Points
, path
->pathdata
.Points
,
1133 path
->datalen
* sizeof(PointF
));
1134 memcpy((*clone
)->pathdata
.Types
, path
->pathdata
.Types
, path
->datalen
);
1139 GpStatus WINGDIPAPI
GdipClosePathFigure(GpPath
* path
)
1141 TRACE("(%p)\n", path
);
1144 return InvalidParameter
;
1146 if(path
->pathdata
.Count
> 0){
1147 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
1148 path
->newfigure
= TRUE
;
1154 GpStatus WINGDIPAPI
GdipClosePathFigures(GpPath
* path
)
1158 TRACE("(%p)\n", path
);
1161 return InvalidParameter
;
1163 for(i
= 1; i
< path
->pathdata
.Count
; i
++){
1164 if(path
->pathdata
.Types
[i
] == PathPointTypeStart
)
1165 path
->pathdata
.Types
[i
-1] |= PathPointTypeCloseSubpath
;
1168 path
->newfigure
= TRUE
;
1173 GpStatus WINGDIPAPI
GdipCreatePath(GpFillMode fill
, GpPath
**path
)
1175 TRACE("(%d, %p)\n", fill
, path
);
1178 return InvalidParameter
;
1180 *path
= heap_alloc_zero(sizeof(GpPath
));
1181 if(!*path
) return OutOfMemory
;
1183 (*path
)->fill
= fill
;
1184 (*path
)->newfigure
= TRUE
;
1189 GpStatus WINGDIPAPI
GdipCreatePath2(GDIPCONST GpPointF
* points
,
1190 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1194 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1196 if(!points
|| !types
|| !path
)
1197 return InvalidParameter
;
1204 *path
= heap_alloc_zero(sizeof(GpPath
));
1205 if(!*path
) return OutOfMemory
;
1207 if(count
> 1 && (types
[count
-1] & PathPointTypePathTypeMask
) == PathPointTypeStart
)
1210 for(i
= 1; i
< count
; i
++) {
1211 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
) {
1213 (types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeBezier
&&
1214 (types
[i
+2] & PathPointTypePathTypeMask
) == PathPointTypeBezier
)
1223 (*path
)->pathdata
.Points
= heap_alloc_zero(count
* sizeof(PointF
));
1224 (*path
)->pathdata
.Types
= heap_alloc_zero(count
);
1226 if(!(*path
)->pathdata
.Points
|| !(*path
)->pathdata
.Types
){
1227 heap_free((*path
)->pathdata
.Points
);
1228 heap_free((*path
)->pathdata
.Types
);
1233 memcpy((*path
)->pathdata
.Points
, points
, count
* sizeof(PointF
));
1234 memcpy((*path
)->pathdata
.Types
, types
, count
);
1236 (*path
)->pathdata
.Types
[0] = PathPointTypeStart
;
1237 (*path
)->pathdata
.Count
= count
;
1238 (*path
)->datalen
= count
;
1240 (*path
)->fill
= fill
;
1241 (*path
)->newfigure
= TRUE
;
1246 GpStatus WINGDIPAPI
GdipCreatePath2I(GDIPCONST GpPoint
* points
,
1247 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1253 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1255 ptF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1257 for(i
= 0;i
< count
; i
++){
1258 ptF
[i
].X
= (REAL
)points
[i
].X
;
1259 ptF
[i
].Y
= (REAL
)points
[i
].Y
;
1262 ret
= GdipCreatePath2(ptF
, types
, count
, fill
, path
);
1269 GpStatus WINGDIPAPI
GdipDeletePath(GpPath
*path
)
1271 TRACE("(%p)\n", path
);
1274 return InvalidParameter
;
1276 heap_free(path
->pathdata
.Points
);
1277 heap_free(path
->pathdata
.Types
);
1283 GpStatus WINGDIPAPI
GdipFlattenPath(GpPath
*path
, GpMatrix
* matrix
, REAL flatness
)
1285 path_list_node_t
*list
, *node
;
1291 TRACE("(%p, %p, %.2f)\n", path
, matrix
, flatness
);
1294 return InvalidParameter
;
1296 if(path
->pathdata
.Count
== 0)
1299 stat
= GdipTransformPath(path
, matrix
);
1303 pt
= path
->pathdata
.Points
[0];
1304 if(!init_path_list(&list
, pt
.X
, pt
.Y
))
1309 while(i
< path
->pathdata
.Count
){
1311 BYTE type
= path
->pathdata
.Types
[i
] & PathPointTypePathTypeMask
;
1312 path_list_node_t
*start
;
1314 pt
= path
->pathdata
.Points
[i
];
1316 /* save last start point index */
1317 if(type
== PathPointTypeStart
)
1320 /* always add line points and start points */
1321 if((type
== PathPointTypeStart
) || (type
== PathPointTypeLine
)){
1322 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, path
->pathdata
.Types
[i
]))
1332 /* test for closed figure */
1333 if(path
->pathdata
.Types
[i
+1] & PathPointTypeCloseSubpath
){
1334 pt
= path
->pathdata
.Points
[startidx
];
1340 pt
= path
->pathdata
.Points
[i
];
1344 /* add Bezier end point */
1345 type
= (path
->pathdata
.Types
[i
] & ~PathPointTypePathTypeMask
) | PathPointTypeLine
;
1346 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, type
))
1351 if(!flatten_bezier(start
, path
->pathdata
.Points
[i
-2].X
, path
->pathdata
.Points
[i
-2].Y
,
1352 path
->pathdata
.Points
[i
-1].X
, path
->pathdata
.Points
[i
-1].Y
,
1359 /* store path data back */
1360 i
= path_list_count(list
);
1361 if(!lengthen_path(path
, i
))
1363 path
->pathdata
.Count
= i
;
1366 for(i
= 0; i
< path
->pathdata
.Count
; i
++){
1367 path
->pathdata
.Points
[i
] = node
->pt
;
1368 path
->pathdata
.Types
[i
] = node
->type
;
1372 free_path_list(list
);
1376 free_path_list(list
);
1380 GpStatus WINGDIPAPI
GdipGetPathData(GpPath
*path
, GpPathData
* pathData
)
1382 TRACE("(%p, %p)\n", path
, pathData
);
1384 if(!path
|| !pathData
)
1385 return InvalidParameter
;
1387 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
1388 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
1389 memcpy(pathData
->Points
, path
->pathdata
.Points
, sizeof(PointF
) * pathData
->Count
);
1390 memcpy(pathData
->Types
, path
->pathdata
.Types
, pathData
->Count
);
1395 GpStatus WINGDIPAPI
GdipGetPathFillMode(GpPath
*path
, GpFillMode
*fillmode
)
1397 TRACE("(%p, %p)\n", path
, fillmode
);
1399 if(!path
|| !fillmode
)
1400 return InvalidParameter
;
1402 *fillmode
= path
->fill
;
1407 GpStatus WINGDIPAPI
GdipGetPathLastPoint(GpPath
* path
, GpPointF
* lastPoint
)
1411 TRACE("(%p, %p)\n", path
, lastPoint
);
1413 if(!path
|| !lastPoint
)
1414 return InvalidParameter
;
1416 count
= path
->pathdata
.Count
;
1418 *lastPoint
= path
->pathdata
.Points
[count
-1];
1423 GpStatus WINGDIPAPI
GdipGetPathPoints(GpPath
*path
, GpPointF
* points
, INT count
)
1425 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1428 return InvalidParameter
;
1430 if(count
< path
->pathdata
.Count
)
1431 return InsufficientBuffer
;
1433 memcpy(points
, path
->pathdata
.Points
, path
->pathdata
.Count
* sizeof(GpPointF
));
1438 GpStatus WINGDIPAPI
GdipGetPathPointsI(GpPath
*path
, GpPoint
* points
, INT count
)
1444 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1447 return InvalidParameter
;
1449 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1450 if(!ptf
) return OutOfMemory
;
1452 ret
= GdipGetPathPoints(path
,ptf
,count
);
1454 for(i
= 0;i
< count
;i
++){
1455 points
[i
].X
= gdip_round(ptf
[i
].X
);
1456 points
[i
].Y
= gdip_round(ptf
[i
].Y
);
1463 GpStatus WINGDIPAPI
GdipGetPathTypes(GpPath
*path
, BYTE
* types
, INT count
)
1465 TRACE("(%p, %p, %d)\n", path
, types
, count
);
1468 return InvalidParameter
;
1470 if(count
< path
->pathdata
.Count
)
1471 return InsufficientBuffer
;
1473 memcpy(types
, path
->pathdata
.Types
, path
->pathdata
.Count
);
1478 /* Windows expands the bounding box to the maximum possible bounding box
1479 * for a given pen. For example, if a line join can extend past the point
1480 * it's joining by x units, the bounding box is extended by x units in every
1481 * direction (even though this is too conservative for most cases). */
1482 GpStatus WINGDIPAPI
GdipGetPathWorldBounds(GpPath
* path
, GpRectF
* bounds
,
1483 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1485 GpPointF
* points
, temp_pts
[4];
1487 REAL path_width
= 1.0, width
, height
, temp
, low_x
, low_y
, high_x
, high_y
;
1489 TRACE("(%p, %p, %p, %p)\n", path
, bounds
, matrix
, pen
);
1491 /* Matrix and pen can be null. */
1492 if(!path
|| !bounds
)
1493 return InvalidParameter
;
1495 /* If path is empty just return. */
1496 count
= path
->pathdata
.Count
;
1498 bounds
->X
= bounds
->Y
= bounds
->Width
= bounds
->Height
= 0.0;
1502 points
= path
->pathdata
.Points
;
1504 low_x
= high_x
= points
[0].X
;
1505 low_y
= high_y
= points
[0].Y
;
1507 for(i
= 1; i
< count
; i
++){
1508 low_x
= min(low_x
, points
[i
].X
);
1509 low_y
= min(low_y
, points
[i
].Y
);
1510 high_x
= max(high_x
, points
[i
].X
);
1511 high_y
= max(high_y
, points
[i
].Y
);
1514 width
= high_x
- low_x
;
1515 height
= high_y
- low_y
;
1517 /* This looks unusual but it's the only way I can imitate windows. */
1519 temp_pts
[0].X
= low_x
;
1520 temp_pts
[0].Y
= low_y
;
1521 temp_pts
[1].X
= low_x
;
1522 temp_pts
[1].Y
= high_y
;
1523 temp_pts
[2].X
= high_x
;
1524 temp_pts
[2].Y
= high_y
;
1525 temp_pts
[3].X
= high_x
;
1526 temp_pts
[3].Y
= low_y
;
1528 GdipTransformMatrixPoints((GpMatrix
*)matrix
, temp_pts
, 4);
1529 low_x
= temp_pts
[0].X
;
1530 low_y
= temp_pts
[0].Y
;
1532 for(i
= 1; i
< 4; i
++){
1533 low_x
= min(low_x
, temp_pts
[i
].X
);
1534 low_y
= min(low_y
, temp_pts
[i
].Y
);
1538 width
= height
* fabs(matrix
->matrix
[2]) + width
* fabs(matrix
->matrix
[0]);
1539 height
= height
* fabs(matrix
->matrix
[3]) + temp
* fabs(matrix
->matrix
[1]);
1543 path_width
= pen
->width
/ 2.0;
1546 path_width
= max(path_width
, pen
->width
* pen
->miterlimit
/ 2.0);
1547 /* FIXME: this should probably also check for the startcap */
1548 if(pen
->endcap
& LineCapNoAnchor
)
1549 path_width
= max(path_width
, pen
->width
* 2.2);
1551 low_x
-= path_width
;
1552 low_y
-= path_width
;
1553 width
+= 2.0 * path_width
;
1554 height
+= 2.0 * path_width
;
1559 bounds
->Width
= width
;
1560 bounds
->Height
= height
;
1565 GpStatus WINGDIPAPI
GdipGetPathWorldBoundsI(GpPath
* path
, GpRect
* bounds
,
1566 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1571 TRACE("(%p, %p, %p, %p)\n", path
, bounds
, matrix
, pen
);
1573 ret
= GdipGetPathWorldBounds(path
,&boundsF
,matrix
,pen
);
1576 bounds
->X
= gdip_round(boundsF
.X
);
1577 bounds
->Y
= gdip_round(boundsF
.Y
);
1578 bounds
->Width
= gdip_round(boundsF
.Width
);
1579 bounds
->Height
= gdip_round(boundsF
.Height
);
1585 GpStatus WINGDIPAPI
GdipGetPointCount(GpPath
*path
, INT
*count
)
1587 TRACE("(%p, %p)\n", path
, count
);
1590 return InvalidParameter
;
1592 *count
= path
->pathdata
.Count
;
1597 GpStatus WINGDIPAPI
GdipReversePath(GpPath
* path
)
1600 INT start
= 0; /* position in reversed path */
1603 TRACE("(%p)\n", path
);
1606 return InvalidParameter
;
1608 count
= path
->pathdata
.Count
;
1610 if(count
== 0) return Ok
;
1612 revpath
.Points
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1613 revpath
.Types
= heap_alloc_zero(sizeof(BYTE
)*count
);
1614 revpath
.Count
= count
;
1615 if(!revpath
.Points
|| !revpath
.Types
){
1616 heap_free(revpath
.Points
);
1617 heap_free(revpath
.Types
);
1621 for(i
= 0; i
< count
; i
++){
1623 /* find next start point */
1624 if(path
->pathdata
.Types
[count
-i
-1] == PathPointTypeStart
){
1626 for(j
= start
; j
<= i
; j
++){
1627 revpath
.Points
[j
] = path
->pathdata
.Points
[count
-j
-1];
1628 revpath
.Types
[j
] = path
->pathdata
.Types
[count
-j
-1];
1630 /* mark start point */
1631 revpath
.Types
[start
] = PathPointTypeStart
;
1632 /* set 'figure' endpoint type */
1634 revpath
.Types
[i
] = path
->pathdata
.Types
[count
-start
-1] & ~PathPointTypePathTypeMask
;
1635 revpath
.Types
[i
] |= revpath
.Types
[i
-1];
1638 revpath
.Types
[i
] = path
->pathdata
.Types
[start
];
1644 memcpy(path
->pathdata
.Points
, revpath
.Points
, sizeof(GpPointF
)*count
);
1645 memcpy(path
->pathdata
.Types
, revpath
.Types
, sizeof(BYTE
)*count
);
1647 heap_free(revpath
.Points
);
1648 heap_free(revpath
.Types
);
1653 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPointI(GpPath
* path
, INT x
, INT y
,
1654 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1656 TRACE("(%p, %d, %d, %p, %p, %p)\n", path
, x
, y
, pen
, graphics
, result
);
1658 return GdipIsOutlineVisiblePathPoint(path
, x
, y
, pen
, graphics
, result
);
1661 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
,
1662 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1666 GpMatrix
*transform
= NULL
;
1668 TRACE("(%p,%0.2f,%0.2f,%p,%p,%p)\n", path
, x
, y
, pen
, graphics
, result
);
1671 return InvalidParameter
;
1673 stat
= GdipClonePath(path
, &wide_path
);
1678 if (pen
->unit
== UnitPixel
&& graphics
!= NULL
)
1680 stat
= GdipCreateMatrix(&transform
);
1683 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1684 CoordinateSpaceWorld
, transform
);
1688 stat
= GdipWidenPath(wide_path
, pen
, transform
, 1.0);
1690 if (pen
->unit
== UnitPixel
&& graphics
!= NULL
)
1693 stat
= GdipInvertMatrix(transform
);
1696 stat
= GdipTransformPath(wide_path
, transform
);
1700 stat
= GdipIsVisiblePathPoint(wide_path
, x
, y
, graphics
, result
);
1702 GdipDeleteMatrix(transform
);
1704 GdipDeletePath(wide_path
);
1709 GpStatus WINGDIPAPI
GdipIsVisiblePathPointI(GpPath
* path
, INT x
, INT y
, GpGraphics
*graphics
, BOOL
*result
)
1711 TRACE("(%p, %d, %d, %p, %p)\n", path
, x
, y
, graphics
, result
);
1713 return GdipIsVisiblePathPoint(path
, x
, y
, graphics
, result
);
1716 /*****************************************************************************
1717 * GdipIsVisiblePathPoint [GDIPLUS.@]
1719 GpStatus WINGDIPAPI
GdipIsVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
, GpGraphics
*graphics
, BOOL
*result
)
1725 if(!path
|| !result
) return InvalidParameter
;
1727 status
= GdipCreateRegionPath(path
, ®ion
);
1731 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
1733 GdipDeleteRegion(region
);
1737 *result
= PtInRegion(hrgn
, gdip_round(x
), gdip_round(y
));
1740 GdipDeleteRegion(region
);
1745 GpStatus WINGDIPAPI
GdipStartPathFigure(GpPath
*path
)
1747 TRACE("(%p)\n", path
);
1750 return InvalidParameter
;
1752 path
->newfigure
= TRUE
;
1757 GpStatus WINGDIPAPI
GdipResetPath(GpPath
*path
)
1759 TRACE("(%p)\n", path
);
1762 return InvalidParameter
;
1764 path
->pathdata
.Count
= 0;
1765 path
->newfigure
= TRUE
;
1766 path
->fill
= FillModeAlternate
;
1771 GpStatus WINGDIPAPI
GdipSetPathFillMode(GpPath
*path
, GpFillMode fill
)
1773 TRACE("(%p, %d)\n", path
, fill
);
1776 return InvalidParameter
;
1783 GpStatus WINGDIPAPI
GdipTransformPath(GpPath
*path
, GpMatrix
*matrix
)
1785 TRACE("(%p, %p)\n", path
, matrix
);
1788 return InvalidParameter
;
1790 if(path
->pathdata
.Count
== 0 || !matrix
)
1793 return GdipTransformMatrixPoints(matrix
, path
->pathdata
.Points
,
1794 path
->pathdata
.Count
);
1797 GpStatus WINGDIPAPI
GdipWarpPath(GpPath
*path
, GpMatrix
* matrix
,
1798 GDIPCONST GpPointF
*points
, INT count
, REAL x
, REAL y
, REAL width
,
1799 REAL height
, WarpMode warpmode
, REAL flatness
)
1801 FIXME("(%p,%p,%p,%i,%0.2f,%0.2f,%0.2f,%0.2f,%i,%0.2f)\n", path
, matrix
,
1802 points
, count
, x
, y
, width
, height
, warpmode
, flatness
);
1804 return NotImplemented
;
1807 static void add_bevel_point(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1808 REAL pen_width
, int right_side
, path_list_node_t
**last_point
)
1810 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1811 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1812 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1813 REAL distance
= pen_width
/ 2.0;
1814 REAL bevel_dx
, bevel_dy
;
1816 if (segment_length
== 0.0)
1818 *last_point
= add_path_list_node(*last_point
, endpoint
->X
,
1819 endpoint
->Y
, PathPointTypeLine
);
1825 bevel_dx
= -distance
* segment_dy
/ segment_length
;
1826 bevel_dy
= distance
* segment_dx
/ segment_length
;
1830 bevel_dx
= distance
* segment_dy
/ segment_length
;
1831 bevel_dy
= -distance
* segment_dx
/ segment_length
;
1834 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ bevel_dx
,
1835 endpoint
->Y
+ bevel_dy
, PathPointTypeLine
);
1838 static void widen_joint(const GpPointF
*p1
, const GpPointF
*p2
, const GpPointF
*p3
,
1839 GpPen
* pen
, REAL pen_width
, path_list_node_t
**last_point
)
1844 case LineJoinMiterClipped
:
1845 if ((p2
->X
- p1
->X
) * (p3
->Y
- p1
->Y
) > (p2
->Y
- p1
->Y
) * (p3
->X
- p1
->X
))
1847 float distance
= pen_width
/ 2.0;
1848 float length_0
= sqrtf((p2
->X
-p1
->X
)*(p2
->X
-p1
->X
)+(p2
->Y
-p1
->Y
)*(p2
->Y
-p1
->Y
));
1849 float length_1
= sqrtf((p3
->X
-p2
->X
)*(p3
->X
-p2
->X
)+(p3
->Y
-p2
->Y
)*(p3
->Y
-p2
->Y
));
1850 float dx0
= distance
* (p2
->X
- p1
->X
) / length_0
;
1851 float dy0
= distance
* (p2
->Y
- p1
->Y
) / length_0
;
1852 float dx1
= distance
* (p3
->X
- p2
->X
) / length_1
;
1853 float dy1
= distance
* (p3
->Y
- p2
->Y
) / length_1
;
1854 float det
= (dy0
*dx1
- dx0
*dy1
);
1855 float dx
= (dx0
*dx1
*(dx0
-dx1
) + dy0
*dy0
*dx1
- dy1
*dy1
*dx0
)/det
;
1856 float dy
= (dy0
*dy1
*(dy0
-dy1
) + dx0
*dx0
*dy1
- dx1
*dx1
*dy0
)/det
;
1857 if (dx
*dx
+ dy
*dy
< pen
->miterlimit
*pen
->miterlimit
* distance
*distance
)
1859 *last_point
= add_path_list_node(*last_point
, p2
->X
+ dx
,
1860 p2
->Y
+ dy
, PathPointTypeLine
);
1863 else if (pen
->join
== LineJoinMiter
)
1867 FIXME("should add a clipped corner\n");
1869 /* else fall-through */
1871 /* else fall-through */
1874 add_bevel_point(p2
, p1
, pen_width
, 1, last_point
);
1875 add_bevel_point(p2
, p3
, pen_width
, 0, last_point
);
1880 static void widen_cap(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1881 REAL pen_width
, GpLineCap cap
, GpCustomLineCap
* custom_cap
, int add_first_points
,
1882 int add_last_point
, path_list_node_t
**last_point
)
1888 if (add_first_points
)
1889 add_bevel_point(endpoint
, nextpoint
, pen_width
, 1, last_point
);
1891 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
1895 case LineCapArrowAnchor
:
1897 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1898 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1899 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1900 REAL distance
= pen_width
/ 2.0;
1901 REAL bevel_dx
, bevel_dy
;
1902 REAL extend_dx
, extend_dy
;
1904 extend_dx
= distance
* segment_dx
/ segment_length
;
1905 extend_dy
= distance
* segment_dy
/ segment_length
;
1907 bevel_dx
= -extend_dy
;
1908 bevel_dy
= extend_dx
;
1910 if (cap
== LineCapCustom
)
1912 extend_dx
= -2.0 * custom_cap
->inset
* extend_dx
;
1913 extend_dy
= -2.0 * custom_cap
->inset
* extend_dy
;
1915 else if (cap
== LineCapArrowAnchor
)
1917 extend_dx
= -3.0 * extend_dx
;
1918 extend_dy
= -3.0 * extend_dy
;
1921 if (add_first_points
)
1922 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- extend_dx
+ bevel_dx
,
1923 endpoint
->Y
- extend_dy
+ bevel_dy
, PathPointTypeLine
);
1926 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- extend_dx
- bevel_dx
,
1927 endpoint
->Y
- extend_dy
- bevel_dy
, PathPointTypeLine
);
1932 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1933 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1934 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1935 REAL distance
= pen_width
/ 2.0;
1936 REAL dx
, dy
, dx2
, dy2
;
1937 const REAL control_point_distance
= 0.5522847498307935; /* 4/3 * (sqrt(2) - 1) */
1939 if (add_first_points
)
1941 dx
= -distance
* segment_dx
/ segment_length
;
1942 dy
= -distance
* segment_dy
/ segment_length
;
1944 dx2
= dx
* control_point_distance
;
1945 dy2
= dy
* control_point_distance
;
1947 /* first 90-degree arc */
1948 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
1949 endpoint
->Y
- dx
, PathPointTypeLine
);
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
+ dx
+ dy2
,
1955 endpoint
->Y
+ dy
- dx2
, PathPointTypeBezier
);
1958 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
,
1959 endpoint
->Y
+ dy
, PathPointTypeBezier
);
1961 /* second 90-degree arc */
1962 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
- dy2
,
1963 endpoint
->Y
+ dy
+ dx2
, PathPointTypeBezier
);
1965 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
+ dx2
,
1966 endpoint
->Y
+ dx
+ dy2
, PathPointTypeBezier
);
1968 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
,
1969 endpoint
->Y
+ dx
, PathPointTypeBezier
);
1971 else if (add_last_point
)
1972 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
1975 case LineCapTriangle
:
1977 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1978 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1979 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1980 REAL distance
= pen_width
/ 2.0;
1983 dx
= distance
* segment_dx
/ segment_length
;
1984 dy
= distance
* segment_dy
/ segment_length
;
1986 if (add_first_points
) {
1987 add_bevel_point(endpoint
, nextpoint
, pen_width
, 1, last_point
);
1989 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
,
1990 endpoint
->Y
- dy
, PathPointTypeLine
);
1992 if (add_first_points
|| add_last_point
)
1993 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
1999 static void widen_open_figure(const GpPointF
*points
, int start
, int end
,
2000 GpPen
*pen
, REAL pen_width
, GpLineCap start_cap
, GpCustomLineCap
* custom_start
,
2001 GpLineCap end_cap
, GpCustomLineCap
* custom_end
, path_list_node_t
**last_point
);
2003 static void widen_closed_figure(const GpPointF
*points
, int start
, int end
,
2004 GpPen
*pen
, REAL pen_width
, path_list_node_t
**last_point
);
2006 static void add_anchor(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
2007 GpPen
*pen
, GpLineCap cap
, GpCustomLineCap
*custom
, path_list_node_t
**last_point
)
2009 REAL pen_width
= max(pen
->width
, 2.0);
2013 case LineCapNoAnchor
:
2015 case LineCapSquareAnchor
:
2017 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
2018 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2019 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2020 REAL distance
= pen_width
/ sqrtf(2.0);
2021 REAL par_dx
, par_dy
;
2022 REAL perp_dx
, perp_dy
;
2024 par_dx
= -distance
* segment_dx
/ segment_length
;
2025 par_dy
= -distance
* segment_dy
/ segment_length
;
2027 perp_dx
= -distance
* segment_dy
/ segment_length
;
2028 perp_dy
= distance
* segment_dx
/ segment_length
;
2030 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
- perp_dx
,
2031 endpoint
->Y
- par_dy
- perp_dy
, PathPointTypeStart
);
2032 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
+ perp_dx
,
2033 endpoint
->Y
- par_dy
+ perp_dy
, PathPointTypeLine
);
2034 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
+ perp_dx
,
2035 endpoint
->Y
+ par_dy
+ perp_dy
, PathPointTypeLine
);
2036 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
- perp_dx
,
2037 endpoint
->Y
+ par_dy
- perp_dy
, PathPointTypeLine
);
2040 case LineCapRoundAnchor
:
2042 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
2043 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2044 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2045 REAL dx
, dy
, dx2
, dy2
;
2046 const REAL control_point_distance
= 0.55228475; /* 4/3 * (sqrt(2) - 1) */
2048 dx
= -pen_width
* segment_dx
/ segment_length
;
2049 dy
= -pen_width
* segment_dy
/ segment_length
;
2051 dx2
= dx
* control_point_distance
;
2052 dy2
= dy
* control_point_distance
;
2054 /* starting point */
2055 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
2056 endpoint
->Y
- dx
, PathPointTypeStart
);
2058 /* first 90-degree arc */
2059 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
+ dx2
,
2060 endpoint
->Y
- dx
+ dy2
, PathPointTypeBezier
);
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
+ dx
,
2064 endpoint
->Y
+ dy
, PathPointTypeBezier
);
2066 /* second 90-degree arc */
2067 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
- dy2
,
2068 endpoint
->Y
+ dy
+ dx2
, PathPointTypeBezier
);
2069 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
+ dx2
,
2070 endpoint
->Y
+ dx
+ dy2
, PathPointTypeBezier
);
2071 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
,
2072 endpoint
->Y
+ dx
, PathPointTypeBezier
);
2074 /* third 90-degree arc */
2075 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
- dx2
,
2076 endpoint
->Y
+ dx
- dy2
, PathPointTypeBezier
);
2077 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
- dy2
,
2078 endpoint
->Y
- dy
+ dx2
, PathPointTypeBezier
);
2079 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
,
2080 endpoint
->Y
- dy
, PathPointTypeBezier
);
2082 /* fourth 90-degree arc */
2083 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
+ dy2
,
2084 endpoint
->Y
- dy
- dx2
, PathPointTypeBezier
);
2085 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
- dx2
,
2086 endpoint
->Y
- dx
- dy2
, PathPointTypeBezier
);
2087 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
2088 endpoint
->Y
- dx
, PathPointTypeBezier
);
2092 case LineCapDiamondAnchor
:
2094 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
2095 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2096 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2097 REAL par_dx
, par_dy
;
2098 REAL perp_dx
, perp_dy
;
2100 par_dx
= -pen_width
* segment_dx
/ segment_length
;
2101 par_dy
= -pen_width
* segment_dy
/ segment_length
;
2103 perp_dx
= -pen_width
* segment_dy
/ segment_length
;
2104 perp_dy
= pen_width
* segment_dx
/ segment_length
;
2106 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
,
2107 endpoint
->Y
+ par_dy
, PathPointTypeStart
);
2108 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- perp_dx
,
2109 endpoint
->Y
- perp_dy
, PathPointTypeLine
);
2110 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
,
2111 endpoint
->Y
- par_dy
, PathPointTypeLine
);
2112 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ perp_dx
,
2113 endpoint
->Y
+ perp_dy
, PathPointTypeLine
);
2116 case LineCapArrowAnchor
:
2118 REAL segment_dy
= nextpoint
->Y
- endpoint
->Y
;
2119 REAL segment_dx
= nextpoint
->X
- endpoint
->X
;
2120 REAL segment_length
= sqrtf(segment_dy
* segment_dy
+ segment_dx
* segment_dx
);
2121 REAL par_dx
= pen_width
* segment_dx
/ segment_length
;
2122 REAL par_dy
= pen_width
* segment_dy
/ segment_length
;
2123 REAL perp_dx
= -par_dy
;
2124 REAL perp_dy
= par_dx
;
2126 *last_point
= add_path_list_node(*last_point
, endpoint
->X
,
2127 endpoint
->Y
, PathPointTypeStart
);
2128 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ SQRT3
* par_dx
- perp_dx
,
2129 endpoint
->Y
+ SQRT3
* par_dy
- perp_dy
, PathPointTypeLine
);
2130 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ SQRT3
* par_dx
+ perp_dx
,
2131 endpoint
->Y
+ SQRT3
* par_dy
+ perp_dy
, PathPointTypeLine
);
2136 REAL segment_dy
= nextpoint
->Y
- endpoint
->Y
;
2137 REAL segment_dx
= nextpoint
->X
- endpoint
->X
;
2138 REAL segment_length
= sqrtf(segment_dy
* segment_dy
+ segment_dx
* segment_dx
);
2140 REAL perp_dx
, perp_dy
;
2142 GpPointF
*tmp_points
;
2147 if (custom
->type
== CustomLineCapTypeAdjustableArrow
)
2149 GpAdjustableArrowCap
*arrow
= (GpAdjustableArrowCap
*)custom
;
2150 TRACE("GpAdjustableArrowCap middle_inset: %f height: %f width: %f\n",
2151 arrow
->middle_inset
, arrow
->height
, arrow
->width
);
2154 TRACE("GpCustomLineCap fill: %d basecap: %d inset: %f join: %d scale: %f pen_width:%f\n",
2155 custom
->fill
, custom
->basecap
, custom
->inset
, custom
->join
, custom
->scale
, pen_width
);
2157 sina
= -pen_width
* custom
->scale
* segment_dx
/ segment_length
;
2158 cosa
= pen_width
* custom
->scale
* segment_dy
/ segment_length
;
2160 /* Coordination where cap needs to be drawn */
2161 posx
= endpoint
->X
+ sina
;
2162 posy
= endpoint
->Y
- cosa
;
2166 tmp_points
= heap_alloc_zero(custom
->pathdata
.Count
* sizeof(GpPoint
));
2168 ERR("Out of memory\n");
2172 for (INT i
= 0; i
< custom
->pathdata
.Count
; i
++)
2174 tmp_points
[i
].X
= posx
+ custom
->pathdata
.Points
[i
].X
* cosa
+ (custom
->pathdata
.Points
[i
].Y
- 1.0) * sina
;
2175 tmp_points
[i
].Y
= posy
+ custom
->pathdata
.Points
[i
].X
* sina
- (custom
->pathdata
.Points
[i
].Y
- 1.0) * cosa
;
2177 if ((custom
->pathdata
.Types
[custom
->pathdata
.Count
- 1] & PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2178 widen_closed_figure(tmp_points
, 0, custom
->pathdata
.Count
- 1, pen
, pen_width
, last_point
);
2180 widen_open_figure(tmp_points
, 0, custom
->pathdata
.Count
- 1, pen
, pen_width
, custom
->strokeEndCap
, NULL
, custom
->strokeStartCap
, NULL
, last_point
);
2184 for (INT i
= 0; i
< custom
->pathdata
.Count
; i
++)
2186 /* rotation of CustomCap according to line */
2187 perp_dx
= custom
->pathdata
.Points
[i
].X
* cosa
+ (custom
->pathdata
.Points
[i
].Y
- 1.0) * sina
;
2188 perp_dy
= custom
->pathdata
.Points
[i
].X
* sina
- (custom
->pathdata
.Points
[i
].Y
- 1.0) * cosa
;
2189 *last_point
= add_path_list_node(*last_point
, posx
+ perp_dx
,
2190 posy
+ perp_dy
, custom
->pathdata
.Types
[i
]);
2193 /* FIXME: The line should be adjusted by the inset value of the custom cap. */
2198 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2201 static void widen_open_figure(const GpPointF
*points
, int start
, int end
,
2202 GpPen
*pen
, REAL pen_width
, GpLineCap start_cap
, GpCustomLineCap
* custom_start
,
2203 GpLineCap end_cap
, GpCustomLineCap
* custom_end
, path_list_node_t
**last_point
)
2206 path_list_node_t
*prev_point
;
2208 if (end
<= start
|| pen_width
== 0.0)
2211 prev_point
= *last_point
;
2213 widen_cap(&points
[start
], &points
[start
+1],
2214 pen_width
, start_cap
, custom_start
, FALSE
, TRUE
, last_point
);
2216 for (i
=start
+1; i
<end
; i
++)
2217 widen_joint(&points
[i
-1], &points
[i
], &points
[i
+1],
2218 pen
, pen_width
, last_point
);
2220 widen_cap(&points
[end
], &points
[end
-1],
2221 pen_width
, end_cap
, custom_end
, TRUE
, TRUE
, last_point
);
2223 for (i
=end
-1; i
>start
; i
--)
2224 widen_joint(&points
[i
+1], &points
[i
], &points
[i
-1],
2225 pen
, pen_width
, last_point
);
2227 widen_cap(&points
[start
], &points
[start
+1],
2228 pen_width
, start_cap
, custom_start
, TRUE
, FALSE
, last_point
);
2230 prev_point
->next
->type
= PathPointTypeStart
;
2231 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2234 static void widen_closed_figure(const GpPointF
*points
, int start
, int end
,
2235 GpPen
*pen
, REAL pen_width
, path_list_node_t
**last_point
)
2238 path_list_node_t
*prev_point
;
2240 if (end
<= start
|| pen_width
== 0.0)
2244 prev_point
= *last_point
;
2246 widen_joint(&points
[end
], &points
[start
],
2247 &points
[start
+1], pen
, pen_width
, last_point
);
2249 for (i
=start
+1; i
<end
; i
++)
2250 widen_joint(&points
[i
-1], &points
[i
],
2251 &points
[i
+1], pen
, pen_width
, last_point
);
2253 widen_joint(&points
[end
-1], &points
[end
],
2254 &points
[start
], pen
, pen_width
, last_point
);
2256 prev_point
->next
->type
= PathPointTypeStart
;
2257 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2260 prev_point
= *last_point
;
2262 widen_joint(&points
[start
], &points
[end
],
2263 &points
[end
-1], pen
, pen_width
, last_point
);
2265 for (i
=end
-1; i
>start
; i
--)
2266 widen_joint(&points
[i
+1], &points
[i
],
2267 &points
[i
-1], pen
, pen_width
, last_point
);
2269 widen_joint(&points
[start
+1], &points
[start
],
2270 &points
[end
], pen
, pen_width
, last_point
);
2272 prev_point
->next
->type
= PathPointTypeStart
;
2273 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2276 static void widen_dashed_figure(GpPath
*path
, int start
, int end
, int closed
,
2277 GpPen
*pen
, REAL pen_width
, path_list_node_t
**last_point
)
2282 const REAL
*dash_pattern
;
2283 REAL
*dash_pattern_scaled
;
2285 GpPointF
*tmp_points
;
2288 REAL segment_length
;
2290 int num_tmp_points
=0;
2291 int draw_start_cap
=0;
2292 static const REAL dash_dot_dot
[6] = { 3.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
2294 if (end
<= start
|| pen_width
== 0.0)
2301 dash_pattern
= dash_dot_dot
;
2305 dash_pattern
= &dash_dot_dot
[2];
2308 case DashStyleDashDot
:
2309 dash_pattern
= dash_dot_dot
;
2312 case DashStyleDashDotDot
:
2313 dash_pattern
= dash_dot_dot
;
2316 case DashStyleCustom
:
2317 dash_pattern
= pen
->dashes
;
2318 dash_count
= pen
->numdashes
;
2322 dash_pattern_scaled
= heap_alloc(dash_count
* sizeof(REAL
));
2323 if (!dash_pattern_scaled
) return;
2325 for (i
= 0; i
< dash_count
; i
++)
2326 dash_pattern_scaled
[i
] = pen
->width
* dash_pattern
[i
];
2328 tmp_points
= heap_alloc_zero((end
- start
+ 2) * sizeof(GpPoint
));
2330 heap_free(dash_pattern_scaled
);
2337 for (j
=start
; j
<= end
; j
++)
2349 segment_dy
= path
->pathdata
.Points
[j
].Y
- path
->pathdata
.Points
[i
].Y
;
2350 segment_dx
= path
->pathdata
.Points
[j
].X
- path
->pathdata
.Points
[i
].X
;
2351 segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2356 if (dash_pos
== 0.0)
2358 if ((dash_index
% 2) == 0)
2362 tmp_points
[0].X
= path
->pathdata
.Points
[i
].X
+ segment_dx
* segment_pos
/ segment_length
;
2363 tmp_points
[0].Y
= path
->pathdata
.Points
[i
].Y
+ segment_dy
* segment_pos
/ segment_length
;
2368 tmp_points
[num_tmp_points
].X
= path
->pathdata
.Points
[i
].X
+ segment_dx
* segment_pos
/ segment_length
;
2369 tmp_points
[num_tmp_points
].Y
= path
->pathdata
.Points
[i
].Y
+ segment_dy
* segment_pos
/ segment_length
;
2371 widen_open_figure(tmp_points
, 0, num_tmp_points
, pen
, pen_width
,
2372 draw_start_cap
? pen
->startcap
: LineCapFlat
, pen
->customstart
,
2373 LineCapFlat
, NULL
, last_point
);
2379 if (dash_pattern_scaled
[dash_index
] - dash_pos
> segment_length
- segment_pos
)
2381 /* advance to next segment */
2382 if ((dash_index
% 2) == 0)
2384 tmp_points
[num_tmp_points
] = path
->pathdata
.Points
[j
];
2387 dash_pos
+= segment_length
- segment_pos
;
2392 /* advance to next dash in pattern */
2393 segment_pos
+= dash_pattern_scaled
[dash_index
] - dash_pos
;
2395 if (++dash_index
== dash_count
)
2402 if (dash_index
% 2 == 0 && num_tmp_points
!= 0)
2404 /* last dash overflows last segment */
2405 widen_open_figure(tmp_points
, 0, num_tmp_points
-1, pen
, pen_width
,
2406 draw_start_cap
? pen
->startcap
: LineCapFlat
, pen
->customstart
,
2407 closed
? LineCapFlat
: pen
->endcap
, pen
->customend
, last_point
);
2410 heap_free(dash_pattern_scaled
);
2411 heap_free(tmp_points
);
2414 GpStatus WINGDIPAPI
GdipWidenPath(GpPath
*path
, GpPen
*pen
, GpMatrix
*matrix
,
2417 GpPath
*flat_path
=NULL
;
2419 path_list_node_t
*points
=NULL
, *last_point
=NULL
;
2420 int i
, subpath_start
=0, new_length
;
2422 TRACE("(%p,%p,%p,%0.2f)\n", path
, pen
, matrix
, flatness
);
2425 return InvalidParameter
;
2427 if (path
->pathdata
.Count
<= 1)
2430 status
= GdipClonePath(path
, &flat_path
);
2433 status
= GdipFlattenPath(flat_path
, pen
->unit
== UnitPixel
? matrix
: NULL
, flatness
);
2435 if (status
== Ok
&& !init_path_list(&points
, 314.0, 22.0))
2436 status
= OutOfMemory
;
2440 REAL pen_width
= (pen
->unit
== UnitWorld
) ? max(pen
->width
, 1.0) : pen
->width
;
2441 BYTE
*types
= flat_path
->pathdata
.Types
;
2443 last_point
= points
;
2445 if (pen
->dashcap
!= DashCapFlat
)
2446 FIXME("unimplemented dash cap %d\n", pen
->dashcap
);
2448 if (pen
->join
== LineJoinRound
)
2449 FIXME("unimplemented line join %d\n", pen
->join
);
2451 if (pen
->align
!= PenAlignmentCenter
)
2452 FIXME("unimplemented pen alignment %d\n", pen
->align
);
2454 if (pen
->compound_array_size
!= 0)
2455 FIXME("unimplemented pen compoundline. Solid line will be drawn instead: %d\n", pen
->compound_array_size
);
2457 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
2459 if ((types
[i
]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2462 if ((types
[i
]&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2464 if (pen
->dash
!= DashStyleSolid
)
2465 widen_dashed_figure(flat_path
, subpath_start
, i
, 1, pen
, pen_width
, &last_point
);
2467 widen_closed_figure(flat_path
->pathdata
.Points
, subpath_start
, i
, pen
, pen_width
, &last_point
);
2469 else if (i
== flat_path
->pathdata
.Count
-1 ||
2470 (types
[i
+1]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2472 if (pen
->dash
!= DashStyleSolid
)
2473 widen_dashed_figure(flat_path
, subpath_start
, i
, 0, pen
, pen_width
, &last_point
);
2475 widen_open_figure(flat_path
->pathdata
.Points
, subpath_start
, i
, pen
, pen_width
,
2476 pen
->startcap
, pen
->customstart
, pen
->endcap
, pen
->customend
, &last_point
);
2480 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
2482 if ((types
[i
]&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2485 if ((types
[i
]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2488 if (i
== flat_path
->pathdata
.Count
-1 ||
2489 (types
[i
+1]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2491 if (pen
->startcap
& LineCapAnchorMask
)
2492 add_anchor(&flat_path
->pathdata
.Points
[subpath_start
],
2493 &flat_path
->pathdata
.Points
[subpath_start
+1],
2494 pen
, pen
->startcap
, pen
->customstart
, &last_point
);
2496 if (pen
->endcap
& LineCapAnchorMask
)
2497 add_anchor(&flat_path
->pathdata
.Points
[i
],
2498 &flat_path
->pathdata
.Points
[i
-1],
2499 pen
, pen
->endcap
, pen
->customend
, &last_point
);
2503 new_length
= path_list_count(points
)-1;
2505 if (!lengthen_path(path
, new_length
))
2506 status
= OutOfMemory
;
2511 path
->pathdata
.Count
= new_length
;
2513 last_point
= points
->next
;
2514 for (i
= 0; i
< new_length
; i
++)
2516 path
->pathdata
.Points
[i
] = last_point
->pt
;
2517 path
->pathdata
.Types
[i
] = last_point
->type
;
2518 last_point
= last_point
->next
;
2521 path
->fill
= FillModeWinding
;
2524 free_path_list(points
);
2526 GdipDeletePath(flat_path
);
2528 if (status
== Ok
&& pen
->unit
!= UnitPixel
)
2529 status
= GdipTransformPath(path
, matrix
);
2534 GpStatus WINGDIPAPI
GdipAddPathRectangle(GpPath
*path
, REAL x
, REAL y
,
2535 REAL width
, REAL height
)
2542 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
2545 return InvalidParameter
;
2547 if (width
<= 0.0 || height
<= 0.0)
2550 /* make a backup copy of path data */
2551 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2554 /* rectangle should start as new path */
2555 old_new
= path
->newfigure
;
2556 path
->newfigure
= TRUE
;
2557 if((retstat
= GdipAddPathLine(path
,x
,y
,x
+width
,y
)) != Ok
){
2558 path
->newfigure
= old_new
;
2563 ptf
[0].Y
= y
+height
;
2565 ptf
[1].Y
= y
+height
;
2567 if((retstat
= GdipAddPathLine2(path
, ptf
, 2)) != Ok
) goto fail
;
2568 path
->pathdata
.Types
[path
->pathdata
.Count
-1] |= PathPointTypeCloseSubpath
;
2571 GdipDeletePath(backup
);
2576 heap_free(path
->pathdata
.Points
);
2577 heap_free(path
->pathdata
.Types
);
2578 memcpy(path
, backup
, sizeof(*path
));
2584 GpStatus WINGDIPAPI
GdipAddPathRectangleI(GpPath
*path
, INT x
, INT y
,
2585 INT width
, INT height
)
2587 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
2589 return GdipAddPathRectangle(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2592 GpStatus WINGDIPAPI
GdipAddPathRectangles(GpPath
*path
, GDIPCONST GpRectF
*rects
, INT count
)
2598 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2600 /* count == 0 - verified condition */
2601 if(!path
|| !rects
|| count
== 0)
2602 return InvalidParameter
;
2607 /* make a backup copy */
2608 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2611 for(i
= 0; i
< count
; i
++){
2612 if((retstat
= GdipAddPathRectangle(path
,rects
[i
].X
,rects
[i
].Y
,rects
[i
].Width
,rects
[i
].Height
)) != Ok
)
2617 GdipDeletePath(backup
);
2622 heap_free(path
->pathdata
.Points
);
2623 heap_free(path
->pathdata
.Types
);
2624 memcpy(path
, backup
, sizeof(*path
));
2630 GpStatus WINGDIPAPI
GdipAddPathRectanglesI(GpPath
*path
, GDIPCONST GpRect
*rects
, INT count
)
2636 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2638 if(!rects
|| count
== 0)
2639 return InvalidParameter
;
2644 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
2646 for(i
= 0;i
< count
;i
++)
2647 set_rect(&rectsF
[i
], rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2649 retstat
= GdipAddPathRectangles(path
, rectsF
, count
);
2655 GpStatus WINGDIPAPI
GdipSetPathMarker(GpPath
* path
)
2659 TRACE("(%p)\n", path
);
2662 return InvalidParameter
;
2664 count
= path
->pathdata
.Count
;
2666 /* set marker flag */
2668 path
->pathdata
.Types
[count
-1] |= PathPointTypePathMarker
;
2673 GpStatus WINGDIPAPI
GdipClearPathMarkers(GpPath
* path
)
2678 TRACE("(%p)\n", path
);
2681 return InvalidParameter
;
2683 count
= path
->pathdata
.Count
;
2685 for(i
= 0; i
< count
- 1; i
++){
2686 path
->pathdata
.Types
[i
] &= ~PathPointTypePathMarker
;
2692 GpStatus WINGDIPAPI
GdipWindingModeOutline(GpPath
*path
, GpMatrix
*matrix
, REAL flatness
)
2694 FIXME("stub: %p, %p, %.2f\n", path
, matrix
, flatness
);
2695 return NotImplemented
;
2698 #define FLAGS_INTPATH 0x4000
2707 /* Test to see if the path could be stored as an array of shorts */
2708 static BOOL
is_integer_path(const GpPath
*path
)
2712 if (!path
->pathdata
.Count
) return FALSE
;
2714 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2717 x
= gdip_round(path
->pathdata
.Points
[i
].X
);
2718 y
= gdip_round(path
->pathdata
.Points
[i
].Y
);
2719 if (path
->pathdata
.Points
[i
].X
!= (REAL
)x
|| path
->pathdata
.Points
[i
].Y
!= (REAL
)y
)
2725 DWORD
write_path_data(GpPath
*path
, void *data
)
2727 struct path_header
*header
= data
;
2728 BOOL integer_path
= is_integer_path(path
);
2732 size
= sizeof(struct path_header
) + path
->pathdata
.Count
;
2734 size
+= sizeof(short[2]) * path
->pathdata
.Count
;
2736 size
+= sizeof(float[2]) * path
->pathdata
.Count
;
2737 size
= (size
+ 3) & ~3;
2739 if (!data
) return size
;
2741 header
->version
= VERSION_MAGIC2
;
2742 header
->count
= path
->pathdata
.Count
;
2743 header
->flags
= integer_path
? FLAGS_INTPATH
: 0;
2747 short *points
= (short*)(header
+ 1);
2748 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2750 points
[2*i
] = path
->pathdata
.Points
[i
].X
;
2751 points
[2*i
+ 1] = path
->pathdata
.Points
[i
].Y
;
2753 types
= (BYTE
*)(points
+ 2*i
);
2757 float *points
= (float*)(header
+ 1);
2758 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2760 points
[2*i
] = path
->pathdata
.Points
[i
].X
;
2761 points
[2*i
+ 1] = path
->pathdata
.Points
[i
].Y
;
2763 types
= (BYTE
*)(points
+ 2*i
);
2766 for (i
=0; i
<path
->pathdata
.Count
; i
++)
2767 types
[i
] = path
->pathdata
.Types
[i
];
2768 memset(types
+ i
, 0, ((path
->pathdata
.Count
+ 3) & ~3) - path
->pathdata
.Count
);