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 struct flatten_bezier_job
108 path_list_node_t
*start
;
113 path_list_node_t
*end
;
117 static BOOL
flatten_bezier_add(struct list
*jobs
, path_list_node_t
*start
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, path_list_node_t
*end
)
119 struct flatten_bezier_job
*job
= malloc(sizeof(struct flatten_bezier_job
));
120 struct flatten_bezier_job temp
= { start
, x2
, y2
, x3
, y3
, end
};
124 list_add_after(jobs
, &job
->entry
);
128 /* GdipFlattenPath helper */
130 * Used to recursively flatten single Bezier curve
132 * - start : pointer to start point node;
133 * - (x2, y2): first control point;
134 * - (x3, y3): second control point;
135 * - end : pointer to end point node
136 * - flatness: admissible error of linear approximation.
140 * FALSE: out of memory
142 * TODO: used quality criteria should be revised to match native as
143 * closer as possible.
145 static BOOL
flatten_bezier(path_list_node_t
*start
, REAL x2
, REAL y2
, REAL x3
, REAL y3
,
146 path_list_node_t
*end
, REAL flatness
)
148 /* this 5 middle points with start/end define to half-curves */
151 path_list_node_t
*node
;
152 REAL area_triangle
, distance_start_end
;
155 struct flatten_bezier_job
*current
, *next
;
158 flatten_bezier_add(&jobs
, start
, x2
, y2
, x3
, y3
, end
);
159 LIST_FOR_EACH_ENTRY( current
, &jobs
, struct flatten_bezier_job
, entry
)
161 start
= current
->start
;
168 /* middle point between control points */
169 pt
.X
= (x2
+ x3
) / 2.0;
170 pt
.Y
= (y2
+ y3
) / 2.0;
172 /* calculate bezier curve middle points == new control points */
173 mp
[0].X
= (start
->pt
.X
+ x2
) / 2.0;
174 mp
[0].Y
= (start
->pt
.Y
+ y2
) / 2.0;
175 mp
[1].X
= (mp
[0].X
+ pt
.X
) / 2.0;
176 mp
[1].Y
= (mp
[0].Y
+ pt
.Y
) / 2.0;
177 mp
[4].X
= (end
->pt
.X
+ x3
) / 2.0;
178 mp
[4].Y
= (end
->pt
.Y
+ y3
) / 2.0;
179 mp
[3].X
= (mp
[4].X
+ pt
.X
) / 2.0;
180 mp
[3].Y
= (mp
[4].Y
+ pt
.Y
) / 2.0;
182 /* middle point between new control points */
183 mp
[2].X
= (mp
[1].X
+ mp
[3].X
) / 2.0;
184 mp
[2].Y
= (mp
[1].Y
+ mp
[3].Y
) / 2.0;
189 /* Test for closely spaced points that don't need to be flattened
190 * Also avoids limited-precision errors in flatness check
192 if((fabs(pt
.X
- mp
[2].X
) + fabs(pt
.Y
- mp
[2].Y
) +
193 fabs(pt_st
.X
- mp
[2].X
) + fabs(pt_st
.Y
- mp
[2].Y
) ) <= flatness
* 0.5)
196 /* check flatness as a half of distance between middle point and a linearized path
197 * formula for distance point from line for point (x0, y0) and line (x1, y1) (x2, y2)
198 * is defined as (area_triangle / distance_start_end):
199 * | (x2 - x1) * (y1 - y0) - (x1 - x0) * (y2 - y1) / sqrt( (x2 - x1)^2 + (y2 - y1)^2 ) |
200 * Here rearranged to avoid division and simplified:
201 * x0(y2 - y1) + y0(x1 - x2) + (x2*y1 - x1*y2)
203 area_triangle
= (pt
.Y
- pt_st
.Y
)*mp
[2].X
+ (pt_st
.X
- pt
.X
)*mp
[2].Y
+ (pt_st
.Y
*pt
.X
- pt_st
.X
*pt
.Y
);
204 distance_start_end
= sqrtf(powf(pt
.Y
- pt_st
.Y
, 2.0) + powf(pt_st
.X
- pt
.X
, 2.0));
205 if(fabs(area_triangle
) <= (0.5 * flatness
* distance_start_end
)){
209 /* add a middle point */
210 if(!(node
= add_path_list_node(start
, mp
[2].X
, mp
[2].Y
, PathPointTypeLine
)))
216 /* do the same with halves */
217 if (!flatten_bezier_add(¤t
->entry
, node
, mp
[3].X
, mp
[3].Y
, mp
[4].X
, mp
[4].Y
, end
))
219 if (!flatten_bezier_add(¤t
->entry
, start
, mp
[0].X
, mp
[0].Y
, mp
[1].X
, mp
[1].Y
, node
))
224 LIST_FOR_EACH_ENTRY_SAFE( current
, next
, &jobs
, struct flatten_bezier_job
, entry
)
226 list_remove(¤t
->entry
);
233 /* GdipAddPath* helper
235 * Several GdipAddPath functions are expected to add onto an open figure.
236 * So if the first point being added is an exact match to the last point
237 * of the existing line, that point should not be added.
240 * path : path to which points should be added
241 * points : array of points to add
242 * count : number of points to add (at least 1)
243 * type : type of the points being added
246 * OutOfMemory : out of memory, could not lengthen path
249 static GpStatus
extend_current_figure(GpPath
*path
, GDIPCONST PointF
*points
, INT count
, BYTE type
)
251 INT insert_index
= path
->pathdata
.Count
;
252 BYTE first_point_type
= (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
254 if(!path
->newfigure
&&
255 path
->pathdata
.Points
[insert_index
-1].X
== points
[0].X
&&
256 path
->pathdata
.Points
[insert_index
-1].Y
== points
[0].Y
)
260 first_point_type
= type
;
266 if(!lengthen_path(path
, count
))
269 memcpy(path
->pathdata
.Points
+ insert_index
, points
, sizeof(GpPointF
)*count
);
270 path
->pathdata
.Types
[insert_index
] = first_point_type
;
271 memset(path
->pathdata
.Types
+ insert_index
+ 1, type
, count
- 1);
273 path
->newfigure
= FALSE
;
274 path
->pathdata
.Count
+= count
;
279 /*******************************************************************************
280 * GdipAddPathArc [GDIPLUS.1]
282 * Add an elliptical arc to the given path.
285 * path [I/O] Path that the arc is appended to
286 * x [I] X coordinate of the boundary rectangle
287 * y [I] Y coordinate of the boundary rectangle
288 * width [I] Width of the boundary rectangle
289 * height [I] Height of the boundary rectangle
290 * startAngle [I] Starting angle of the arc, clockwise
291 * sweepAngle [I] Angle of the arc, clockwise
294 * InvalidParameter If the given path is invalid
295 * OutOfMemory If memory allocation fails, i.e. the path cannot be lengthened
296 * Ok If everything works out as expected
299 * This functions takes the newfigure value of the given path into account,
300 * i.e. the arc is connected to the end of the given path if it was set to
301 * FALSE, otherwise the arc's first point gets the PathPointTypeStart value.
302 * In both cases, the value of newfigure of the given path is FALSE
305 GpStatus WINGDIPAPI
GdipAddPathArc(GpPath
*path
, REAL x
, REAL y
, REAL width
,
306 REAL height
, REAL startAngle
, REAL sweepAngle
)
312 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
313 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
315 if(!path
|| width
<= 0.0f
|| height
<= 0.0f
)
316 return InvalidParameter
;
318 count
= arc2polybezier(NULL
, x
, y
, width
, height
, startAngle
, sweepAngle
);
322 points
= heap_alloc_zero(sizeof(GpPointF
)*count
);
326 arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
328 status
= extend_current_figure(path
, points
, count
, PathPointTypeBezier
);
334 /*******************************************************************************
335 * GdipAddPathArcI [GDUPLUS.2]
339 GpStatus WINGDIPAPI
GdipAddPathArcI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
340 INT y2
, REAL startAngle
, REAL sweepAngle
)
342 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
343 path
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
345 return GdipAddPathArc(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,startAngle
,sweepAngle
);
348 GpStatus WINGDIPAPI
GdipAddPathBezier(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
349 REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
353 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
354 path
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
357 return InvalidParameter
;
368 return extend_current_figure(path
, points
, 4, PathPointTypeBezier
);
371 GpStatus WINGDIPAPI
GdipAddPathBezierI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
372 INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
374 TRACE("(%p, %d, %d, %d, %d, %d, %d, %d, %d)\n",
375 path
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
377 return GdipAddPathBezier(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,(REAL
)x3
,(REAL
)y3
,
381 GpStatus WINGDIPAPI
GdipAddPathBeziers(GpPath
*path
, GDIPCONST GpPointF
*points
,
384 TRACE("(%p, %p, %d)\n", path
, points
, count
);
386 if(!path
|| !points
|| ((count
- 1) % 3))
387 return InvalidParameter
;
389 return extend_current_figure(path
, points
, count
, PathPointTypeBezier
);
392 GpStatus WINGDIPAPI
GdipAddPathBeziersI(GpPath
*path
, GDIPCONST GpPoint
*points
,
399 TRACE("(%p, %p, %d)\n", path
, points
, count
);
401 if(!points
|| ((count
- 1) % 3))
402 return InvalidParameter
;
404 ptsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
408 for(i
= 0; i
< count
; i
++){
409 ptsF
[i
].X
= (REAL
)points
[i
].X
;
410 ptsF
[i
].Y
= (REAL
)points
[i
].Y
;
413 ret
= GdipAddPathBeziers(path
, ptsF
, count
);
419 GpStatus WINGDIPAPI
GdipAddPathClosedCurve(GpPath
*path
, GDIPCONST GpPointF
*points
,
422 TRACE("(%p, %p, %d)\n", path
, points
, count
);
424 return GdipAddPathClosedCurve2(path
, points
, count
, 1.0);
427 GpStatus WINGDIPAPI
GdipAddPathClosedCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
,
430 TRACE("(%p, %p, %d)\n", path
, points
, count
);
432 return GdipAddPathClosedCurve2I(path
, points
, count
, 1.0);
435 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
,
436 INT count
, REAL tension
)
438 INT i
, len_pt
= (count
+ 1)*3-2;
444 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
446 if(!path
|| !points
|| count
<= 1)
447 return InvalidParameter
;
449 pt
= heap_alloc_zero(len_pt
* sizeof(GpPointF
));
450 pts
= heap_alloc_zero((count
+ 1)*sizeof(GpPointF
));
457 /* copy source points to extend with the last one */
458 memcpy(pts
, points
, sizeof(GpPointF
)*count
);
461 tension
= tension
* TENSION_CONST
;
463 for(i
= 0; i
< count
-1; i
++){
464 calc_curve_bezier(&(pts
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
468 pt
[3*i
+3].X
= pts
[i
+1].X
;
469 pt
[3*i
+3].Y
= pts
[i
+1].Y
;
474 /* points [len_pt-2] and [0] are calculated
475 separately to connect splines properly */
476 pts
[0] = points
[count
-1];
477 pts
[1] = points
[0]; /* equals to start and end of a resulting path */
480 calc_curve_bezier(pts
, tension
, &x1
, &y1
, &x2
, &y2
);
488 pt
[len_pt
-1].X
= pt
[0].X
;
489 pt
[len_pt
-1].Y
= pt
[0].Y
;
491 stat
= extend_current_figure(path
, pt
, len_pt
, PathPointTypeBezier
);
495 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
496 path
->newfigure
= TRUE
;
505 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
506 INT count
, REAL tension
)
512 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
514 if(!path
|| !points
|| count
<= 1)
515 return InvalidParameter
;
517 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
521 for(i
= 0; i
< count
; i
++){
522 ptf
[i
].X
= (REAL
)points
[i
].X
;
523 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
526 stat
= GdipAddPathClosedCurve2(path
, ptf
, count
, tension
);
533 GpStatus WINGDIPAPI
GdipAddPathCurve(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
535 TRACE("(%p, %p, %d)\n", path
, points
, count
);
537 if(!path
|| !points
|| count
<= 1)
538 return InvalidParameter
;
540 return GdipAddPathCurve2(path
, points
, count
, 1.0);
543 GpStatus WINGDIPAPI
GdipAddPathCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
545 TRACE("(%p, %p, %d)\n", path
, points
, count
);
547 if(!path
|| !points
|| count
<= 1)
548 return InvalidParameter
;
550 return GdipAddPathCurve2I(path
, points
, count
, 1.0);
553 GpStatus WINGDIPAPI
GdipAddPathCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
,
556 INT i
, len_pt
= count
*3-2;
561 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
563 if(!path
|| !points
|| count
<= 1)
564 return InvalidParameter
;
566 pt
= heap_alloc_zero(len_pt
* sizeof(GpPointF
));
570 tension
= tension
* TENSION_CONST
;
572 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
575 pt
[0].X
= points
[0].X
;
576 pt
[0].Y
= points
[0].Y
;
580 for(i
= 0; i
< count
-2; i
++){
581 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
585 pt
[3*i
+3].X
= points
[i
+1].X
;
586 pt
[3*i
+3].Y
= points
[i
+1].Y
;
591 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
592 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
596 pt
[len_pt
-1].X
= points
[count
-1].X
;
597 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
599 stat
= extend_current_figure(path
, pt
, len_pt
, PathPointTypeBezier
);
606 GpStatus WINGDIPAPI
GdipAddPathCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
607 INT count
, REAL tension
)
613 TRACE("(%p, %p, %d, %.2f)\n", path
, points
, count
, tension
);
615 if(!path
|| !points
|| count
<= 1)
616 return InvalidParameter
;
618 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
622 for(i
= 0; i
< count
; i
++){
623 ptf
[i
].X
= (REAL
)points
[i
].X
;
624 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
627 stat
= GdipAddPathCurve2(path
, ptf
, count
, tension
);
634 GpStatus WINGDIPAPI
GdipAddPathCurve3(GpPath
*path
, GDIPCONST GpPointF
*points
,
635 INT count
, INT offset
, INT nseg
, REAL tension
)
637 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path
, points
, count
, offset
, nseg
, tension
);
639 if(!path
|| !points
|| offset
+ 1 >= count
|| count
- offset
< nseg
+ 1)
640 return InvalidParameter
;
642 return GdipAddPathCurve2(path
, &points
[offset
], nseg
+ 1, tension
);
645 GpStatus WINGDIPAPI
GdipAddPathCurve3I(GpPath
*path
, GDIPCONST GpPoint
*points
,
646 INT count
, INT offset
, INT nseg
, REAL tension
)
648 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path
, points
, count
, offset
, nseg
, tension
);
650 if(!path
|| !points
|| offset
+ 1 >= count
|| count
- offset
< nseg
+ 1)
651 return InvalidParameter
;
653 return GdipAddPathCurve2I(path
, &points
[offset
], nseg
+ 1, tension
);
656 GpStatus WINGDIPAPI
GdipAddPathEllipse(GpPath
*path
, REAL x
, REAL y
, REAL width
,
659 INT old_count
, numpts
;
661 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
664 return InvalidParameter
;
666 if(!lengthen_path(path
, MAX_ARC_PTS
))
669 old_count
= path
->pathdata
.Count
;
670 if((numpts
= arc2polybezier(&path
->pathdata
.Points
[old_count
], x
, y
, width
,
671 height
, 0.0, 360.0)) != MAX_ARC_PTS
){
672 ERR("expected %d points but got %d\n", MAX_ARC_PTS
, numpts
);
676 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeBezier
,
679 /* An ellipse is an intrinsic figure (always is its own subpath). */
680 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
681 path
->pathdata
.Types
[old_count
+ MAX_ARC_PTS
- 1] |= PathPointTypeCloseSubpath
;
682 path
->newfigure
= TRUE
;
683 path
->pathdata
.Count
+= MAX_ARC_PTS
;
688 GpStatus WINGDIPAPI
GdipAddPathEllipseI(GpPath
*path
, INT x
, INT y
, INT width
,
691 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
693 return GdipAddPathEllipse(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
696 GpStatus WINGDIPAPI
GdipAddPathLine2(GpPath
*path
, GDIPCONST GpPointF
*points
,
699 TRACE("(%p, %p, %d)\n", path
, points
, count
);
701 if(!path
|| !points
|| count
< 1)
702 return InvalidParameter
;
704 return extend_current_figure(path
, points
, count
, PathPointTypeLine
);
707 GpStatus WINGDIPAPI
GdipAddPathLine2I(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
713 TRACE("(%p, %p, %d)\n", path
, points
, count
);
716 return InvalidParameter
;
718 pointsF
= heap_alloc_zero(sizeof(GpPointF
) * count
);
719 if(!pointsF
) return OutOfMemory
;
721 for(i
= 0;i
< count
; i
++){
722 pointsF
[i
].X
= (REAL
)points
[i
].X
;
723 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
726 stat
= GdipAddPathLine2(path
, pointsF
, count
);
733 /*************************************************************************
734 * GdipAddPathLine [GDIPLUS.21]
736 * Add two points to the given path.
739 * path [I/O] Path that the line is appended to
740 * x1 [I] X coordinate of the first point of the line
741 * y1 [I] Y coordinate of the first point of the line
742 * x2 [I] X coordinate of the second point of the line
743 * y2 [I] Y coordinate of the second point of the line
746 * InvalidParameter If the first parameter is not a valid path
747 * OutOfMemory If the path cannot be lengthened, i.e. memory allocation fails
748 * Ok If everything works out as expected
751 * This functions takes the newfigure value of the given path into account,
752 * i.e. the two new points are connected to the end of the given path if it
753 * was set to FALSE, otherwise the first point is given the PathPointTypeStart
754 * value. In both cases, the value of newfigure of the given path is FALSE
757 GpStatus WINGDIPAPI
GdipAddPathLine(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
761 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x1
, y1
, x2
, y2
);
764 return InvalidParameter
;
771 return extend_current_figure(path
, points
, 2, PathPointTypeLine
);
774 /*************************************************************************
775 * GdipAddPathLineI [GDIPLUS.21]
777 * See GdipAddPathLine
779 GpStatus WINGDIPAPI
GdipAddPathLineI(GpPath
*path
, INT x1
, INT y1
, INT x2
, INT y2
)
781 TRACE("(%p, %d, %d, %d, %d)\n", path
, x1
, y1
, x2
, y2
);
783 return GdipAddPathLine(path
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
786 GpStatus WINGDIPAPI
GdipAddPathPath(GpPath
*path
, GDIPCONST GpPath
* addingPath
,
789 INT old_count
, count
;
791 TRACE("(%p, %p, %d)\n", path
, addingPath
, connect
);
793 if(!path
|| !addingPath
)
794 return InvalidParameter
;
796 old_count
= path
->pathdata
.Count
;
797 count
= addingPath
->pathdata
.Count
;
799 if(!lengthen_path(path
, count
))
802 memcpy(&path
->pathdata
.Points
[old_count
], addingPath
->pathdata
.Points
,
803 count
* sizeof(GpPointF
));
804 memcpy(&path
->pathdata
.Types
[old_count
], addingPath
->pathdata
.Types
, count
);
806 if(path
->newfigure
|| !connect
)
807 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
809 path
->pathdata
.Types
[old_count
] = PathPointTypeLine
;
811 path
->newfigure
= FALSE
;
812 path
->pathdata
.Count
+= count
;
817 GpStatus WINGDIPAPI
GdipAddPathPie(GpPath
*path
, REAL x
, REAL y
, REAL width
, REAL height
,
818 REAL startAngle
, REAL sweepAngle
)
824 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
825 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
828 return InvalidParameter
;
830 /* on zero width/height only start point added */
831 if(width
<= 1e-7 || height
<= 1e-7){
832 if(!lengthen_path(path
, 1))
834 path
->pathdata
.Points
[0].X
= x
+ width
/ 2.0;
835 path
->pathdata
.Points
[0].Y
= y
+ height
/ 2.0;
836 path
->pathdata
.Types
[0] = PathPointTypeStart
| PathPointTypeCloseSubpath
;
837 path
->pathdata
.Count
= 1;
838 return InvalidParameter
;
841 count
= arc2polybezier(NULL
, x
, y
, width
, height
, startAngle
, sweepAngle
);
846 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
850 arc2polybezier(ptf
, x
, y
, width
, height
, startAngle
, sweepAngle
);
852 status
= GdipAddPathLine(path
, x
+ width
/2, y
+ height
/2, ptf
[0].X
, ptf
[0].Y
);
857 /* one spline is already added as a line endpoint */
858 if(!lengthen_path(path
, count
- 1)){
863 memcpy(&(path
->pathdata
.Points
[path
->pathdata
.Count
]), &(ptf
[1]),sizeof(GpPointF
)*(count
-1));
864 for(i
= 0; i
< count
-1; i
++)
865 path
->pathdata
.Types
[path
->pathdata
.Count
+i
] = PathPointTypeBezier
;
867 path
->pathdata
.Count
+= count
-1;
869 GdipClosePathFigure(path
);
876 GpStatus WINGDIPAPI
GdipAddPathPieI(GpPath
*path
, INT x
, INT y
, INT width
, INT height
,
877 REAL startAngle
, REAL sweepAngle
)
879 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
880 path
, x
, y
, width
, height
, startAngle
, sweepAngle
);
882 return GdipAddPathPie(path
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, startAngle
, sweepAngle
);
885 GpStatus WINGDIPAPI
GdipAddPathPolygon(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
889 TRACE("(%p, %p, %d)\n", path
, points
, count
);
891 if(!path
|| !points
|| count
< 3)
892 return InvalidParameter
;
894 if(!lengthen_path(path
, count
))
897 old_count
= path
->pathdata
.Count
;
899 memcpy(&path
->pathdata
.Points
[old_count
], points
, count
*sizeof(GpPointF
));
900 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeLine
, count
- 1);
902 /* A polygon is an intrinsic figure */
903 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
904 path
->pathdata
.Types
[old_count
+ count
- 1] |= PathPointTypeCloseSubpath
;
905 path
->newfigure
= TRUE
;
906 path
->pathdata
.Count
+= count
;
911 GpStatus WINGDIPAPI
GdipAddPathPolygonI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
917 TRACE("(%p, %p, %d)\n", path
, points
, count
);
919 if(!points
|| count
< 3)
920 return InvalidParameter
;
922 ptf
= heap_alloc_zero(sizeof(GpPointF
) * count
);
926 for(i
= 0; i
< count
; i
++){
927 ptf
[i
].X
= (REAL
)points
[i
].X
;
928 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
931 status
= GdipAddPathPolygon(path
, ptf
, count
);
938 static float fromfixedpoint(const FIXED v
)
940 float f
= ((float)v
.fract
) / (1<<(sizeof(v
.fract
)*8));
945 struct format_string_args
953 static GpStatus
format_string_callback(HDC dc
,
954 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
955 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
956 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
957 INT underlined_index_count
, void *priv
)
959 static const MAT2 identity
= { {0,1}, {0,0}, {0,0}, {0,1} };
960 struct format_string_args
*args
= priv
;
961 GpPath
*path
= args
->path
;
962 GpStatus status
= Ok
;
963 float x
= rect
->X
+ (bounds
->X
- rect
->X
) * args
->scale
;
964 float y
= rect
->Y
+ (bounds
->Y
- rect
->Y
) * args
->scale
;
967 if (underlined_index_count
)
968 FIXME("hotkey underlines not drawn yet\n");
970 if (y
+ bounds
->Height
* args
->scale
> args
->maxY
)
971 args
->maxY
= y
+ bounds
->Height
* args
->scale
;
973 for (i
= index
; i
< length
+ index
; ++i
)
976 TTPOLYGONHEADER
*ph
= NULL
, *origph
;
979 len
= GetGlyphOutlineW(dc
, string
[i
], GGO_BEZIER
, &gm
, 0, NULL
, &identity
);
980 if (len
== GDI_ERROR
)
982 status
= GenericError
;
985 origph
= ph
= heap_alloc_zero(len
);
987 if (!ph
|| !lengthen_path(path
, len
/ sizeof(POINTFX
)))
990 status
= OutOfMemory
;
993 GetGlyphOutlineW(dc
, string
[i
], GGO_BEZIER
, &gm
, len
, start
, &identity
);
998 DWORD ofs_start
= ofs
;
999 ph
= (TTPOLYGONHEADER
*)&start
[ofs
];
1000 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeStart
;
1001 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(ph
->pfxStart
.x
) * args
->scale
;
1002 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(ph
->pfxStart
.y
) * args
->scale
;
1003 TRACE("Starting at count %i with pos %f, %f)\n", path
->pathdata
.Count
, x
, y
);
1005 while (ofs
- ofs_start
< ph
->cb
)
1007 TTPOLYCURVE
*curve
= (TTPOLYCURVE
*)&start
[ofs
];
1009 ofs
+= sizeof(TTPOLYCURVE
) + (curve
->cpfx
- 1) * sizeof(POINTFX
);
1011 switch (curve
->wType
)
1014 for (j
= 0; j
< curve
->cpfx
; ++j
)
1016 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeLine
;
1017 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(curve
->apfx
[j
].x
) * args
->scale
;
1018 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(curve
->apfx
[j
].y
) * args
->scale
;
1021 case TT_PRIM_CSPLINE
:
1022 for (j
= 0; j
< curve
->cpfx
; ++j
)
1024 path
->pathdata
.Types
[path
->pathdata
.Count
] = PathPointTypeBezier
;
1025 path
->pathdata
.Points
[path
->pathdata
.Count
].X
= x
+ fromfixedpoint(curve
->apfx
[j
].x
) * args
->scale
;
1026 path
->pathdata
.Points
[path
->pathdata
.Count
++].Y
= y
+ args
->ascent
- fromfixedpoint(curve
->apfx
[j
].y
) * args
->scale
;
1030 ERR("Unhandled type: %u\n", curve
->wType
);
1031 status
= GenericError
;
1034 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
1036 path
->newfigure
= TRUE
;
1037 x
+= gm
.gmCellIncX
* args
->scale
;
1038 y
+= gm
.gmCellIncY
* args
->scale
;
1048 GpStatus WINGDIPAPI
GdipAddPathString(GpPath
* path
, GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFontFamily
* family
, INT style
, REAL emSize
, GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
* format
)
1055 GpGraphics
*graphics
;
1057 struct format_string_args args
;
1059 UINT16 native_height
;
1060 RectF scaled_layout_rect
;
1061 TEXTMETRICW textmetric
;
1063 TRACE("(%p, %s, %d, %p, %d, %f, %p, %p)\n", path
, debugstr_w(string
), length
, family
, style
, emSize
, layoutRect
, format
);
1064 if (!path
|| !string
|| !family
|| !emSize
|| !layoutRect
)
1065 return InvalidParameter
;
1068 format
= &default_drawstring_format
;
1070 status
= GdipGetEmHeight(family
, style
, &native_height
);
1074 scaled_layout_rect
.X
= layoutRect
->X
;
1075 scaled_layout_rect
.Y
= layoutRect
->Y
;
1076 scaled_layout_rect
.Width
= layoutRect
->Width
* native_height
/ emSize
;
1077 scaled_layout_rect
.Height
= layoutRect
->Height
* native_height
/ emSize
;
1079 if ((status
= GdipClonePath(path
, &backup
)) != Ok
)
1082 dc
= CreateCompatibleDC(0);
1083 status
= GdipCreateFromHDC(dc
, &graphics
);
1087 GdipDeletePath(backup
);
1091 status
= GdipCreateFont(family
, native_height
, style
, UnitPixel
, &font
);
1094 GdipDeleteGraphics(graphics
);
1096 GdipDeletePath(backup
);
1100 get_log_fontW(font
, graphics
, &lfw
);
1101 GdipDeleteFont(font
);
1102 GdipDeleteGraphics(graphics
);
1104 hfont
= CreateFontIndirectW(&lfw
);
1107 WARN("Failed to create font\n");
1109 GdipDeletePath(backup
);
1110 return GenericError
;
1113 SelectObject(dc
, hfont
);
1115 GetTextMetricsW(dc
, &textmetric
);
1119 args
.scale
= emSize
/ native_height
;
1120 args
.ascent
= textmetric
.tmAscent
* args
.scale
;
1121 status
= gdip_format_string(dc
, string
, length
, NULL
, &scaled_layout_rect
,
1122 format
, TRUE
, format_string_callback
, &args
);
1125 DeleteObject(hfont
);
1127 if (status
!= Ok
) /* free backup */
1129 heap_free(path
->pathdata
.Points
);
1130 heap_free(path
->pathdata
.Types
);
1135 if (format
->line_align
== StringAlignmentCenter
&& layoutRect
->Y
+ args
.maxY
< layoutRect
->Height
)
1137 float inc
= layoutRect
->Height
+ layoutRect
->Y
- args
.maxY
;
1139 for (i
= backup
->pathdata
.Count
; i
< path
->pathdata
.Count
; ++i
)
1140 path
->pathdata
.Points
[i
].Y
+= inc
;
1141 } else if (format
->line_align
== StringAlignmentFar
) {
1142 float inc
= layoutRect
->Height
+ layoutRect
->Y
- args
.maxY
;
1143 for (i
= backup
->pathdata
.Count
; i
< path
->pathdata
.Count
; ++i
)
1144 path
->pathdata
.Points
[i
].Y
+= inc
;
1146 GdipDeletePath(backup
);
1150 GpStatus WINGDIPAPI
GdipAddPathStringI(GpPath
* path
, GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFontFamily
* family
,
1151 INT style
, REAL emSize
, GDIPCONST Rect
* layoutRect
, GDIPCONST GpStringFormat
* format
)
1156 return InvalidParameter
;
1158 set_rect(&rect
, layoutRect
->X
, layoutRect
->Y
, layoutRect
->Width
, layoutRect
->Height
);
1159 return GdipAddPathString(path
, string
, length
, family
, style
, emSize
, &rect
, format
);
1162 /*************************************************************************
1163 * GdipClonePath [GDIPLUS.53]
1165 * Duplicate the given path in memory.
1168 * path [I] The path to be duplicated
1169 * clone [O] Pointer to the new path
1172 * InvalidParameter If the input path is invalid
1173 * OutOfMemory If allocation of needed memory fails
1174 * Ok If everything works out as expected
1176 GpStatus WINGDIPAPI
GdipClonePath(GpPath
* path
, GpPath
**clone
)
1178 TRACE("(%p, %p)\n", path
, clone
);
1181 return InvalidParameter
;
1183 *clone
= heap_alloc_zero(sizeof(GpPath
));
1184 if(!*clone
) return OutOfMemory
;
1188 (*clone
)->pathdata
.Points
= heap_alloc_zero(path
->datalen
* sizeof(PointF
));
1189 (*clone
)->pathdata
.Types
= heap_alloc_zero(path
->datalen
);
1190 if(!(*clone
)->pathdata
.Points
|| !(*clone
)->pathdata
.Types
){
1191 heap_free((*clone
)->pathdata
.Points
);
1192 heap_free((*clone
)->pathdata
.Types
);
1197 memcpy((*clone
)->pathdata
.Points
, path
->pathdata
.Points
,
1198 path
->datalen
* sizeof(PointF
));
1199 memcpy((*clone
)->pathdata
.Types
, path
->pathdata
.Types
, path
->datalen
);
1204 GpStatus WINGDIPAPI
GdipClosePathFigure(GpPath
* path
)
1206 TRACE("(%p)\n", path
);
1209 return InvalidParameter
;
1211 if(path
->pathdata
.Count
> 0){
1212 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
1213 path
->newfigure
= TRUE
;
1219 GpStatus WINGDIPAPI
GdipClosePathFigures(GpPath
* path
)
1223 TRACE("(%p)\n", path
);
1226 return InvalidParameter
;
1228 for(i
= 1; i
< path
->pathdata
.Count
; i
++){
1229 if(path
->pathdata
.Types
[i
] == PathPointTypeStart
)
1230 path
->pathdata
.Types
[i
-1] |= PathPointTypeCloseSubpath
;
1233 path
->newfigure
= TRUE
;
1238 GpStatus WINGDIPAPI
GdipCreatePath(GpFillMode fill
, GpPath
**path
)
1240 TRACE("(%d, %p)\n", fill
, path
);
1243 return InvalidParameter
;
1245 *path
= heap_alloc_zero(sizeof(GpPath
));
1246 if(!*path
) return OutOfMemory
;
1248 (*path
)->fill
= fill
;
1249 (*path
)->newfigure
= TRUE
;
1254 GpStatus WINGDIPAPI
GdipCreatePath2(GDIPCONST GpPointF
* points
,
1255 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1259 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1261 if(!points
|| !types
|| !path
)
1262 return InvalidParameter
;
1269 *path
= heap_alloc_zero(sizeof(GpPath
));
1270 if(!*path
) return OutOfMemory
;
1272 if(count
> 1 && (types
[count
-1] & PathPointTypePathTypeMask
) == PathPointTypeStart
)
1275 for(i
= 1; i
< count
; i
++) {
1276 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
) {
1278 (types
[i
+1] & PathPointTypePathTypeMask
) == PathPointTypeBezier
&&
1279 (types
[i
+2] & PathPointTypePathTypeMask
) == PathPointTypeBezier
)
1288 (*path
)->pathdata
.Points
= heap_alloc_zero(count
* sizeof(PointF
));
1289 (*path
)->pathdata
.Types
= heap_alloc_zero(count
);
1291 if(!(*path
)->pathdata
.Points
|| !(*path
)->pathdata
.Types
){
1292 heap_free((*path
)->pathdata
.Points
);
1293 heap_free((*path
)->pathdata
.Types
);
1298 memcpy((*path
)->pathdata
.Points
, points
, count
* sizeof(PointF
));
1299 memcpy((*path
)->pathdata
.Types
, types
, count
);
1301 (*path
)->pathdata
.Types
[0] = PathPointTypeStart
;
1302 (*path
)->pathdata
.Count
= count
;
1303 (*path
)->datalen
= count
;
1305 (*path
)->fill
= fill
;
1306 (*path
)->newfigure
= TRUE
;
1311 GpStatus WINGDIPAPI
GdipCreatePath2I(GDIPCONST GpPoint
* points
,
1312 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
1318 TRACE("(%p, %p, %d, %d, %p)\n", points
, types
, count
, fill
, path
);
1320 ptF
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1322 for(i
= 0;i
< count
; i
++){
1323 ptF
[i
].X
= (REAL
)points
[i
].X
;
1324 ptF
[i
].Y
= (REAL
)points
[i
].Y
;
1327 ret
= GdipCreatePath2(ptF
, types
, count
, fill
, path
);
1334 GpStatus WINGDIPAPI
GdipDeletePath(GpPath
*path
)
1336 TRACE("(%p)\n", path
);
1339 return InvalidParameter
;
1341 heap_free(path
->pathdata
.Points
);
1342 heap_free(path
->pathdata
.Types
);
1348 GpStatus WINGDIPAPI
GdipFlattenPath(GpPath
*path
, GpMatrix
* matrix
, REAL flatness
)
1350 path_list_node_t
*list
, *node
;
1356 TRACE("(%p, %p, %.2f)\n", path
, matrix
, flatness
);
1359 return InvalidParameter
;
1361 if(path
->pathdata
.Count
== 0)
1364 stat
= GdipTransformPath(path
, matrix
);
1368 pt
= path
->pathdata
.Points
[0];
1369 if(!init_path_list(&list
, pt
.X
, pt
.Y
))
1374 while(i
< path
->pathdata
.Count
){
1376 BYTE type
= path
->pathdata
.Types
[i
] & PathPointTypePathTypeMask
;
1377 path_list_node_t
*start
;
1379 pt
= path
->pathdata
.Points
[i
];
1381 /* save last start point index */
1382 if(type
== PathPointTypeStart
)
1385 /* always add line points and start points */
1386 if((type
== PathPointTypeStart
) || (type
== PathPointTypeLine
)){
1387 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, path
->pathdata
.Types
[i
]))
1397 /* test for closed figure */
1398 if(path
->pathdata
.Types
[i
+1] & PathPointTypeCloseSubpath
){
1399 pt
= path
->pathdata
.Points
[startidx
];
1405 pt
= path
->pathdata
.Points
[i
];
1409 /* add Bezier end point */
1410 type
= (path
->pathdata
.Types
[i
] & ~PathPointTypePathTypeMask
) | PathPointTypeLine
;
1411 if(!add_path_list_node(node
, pt
.X
, pt
.Y
, type
))
1416 if(!flatten_bezier(start
, path
->pathdata
.Points
[i
-2].X
, path
->pathdata
.Points
[i
-2].Y
,
1417 path
->pathdata
.Points
[i
-1].X
, path
->pathdata
.Points
[i
-1].Y
,
1424 /* store path data back */
1425 i
= path_list_count(list
);
1426 if(!lengthen_path(path
, i
))
1428 path
->pathdata
.Count
= i
;
1431 for(i
= 0; i
< path
->pathdata
.Count
; i
++){
1432 path
->pathdata
.Points
[i
] = node
->pt
;
1433 path
->pathdata
.Types
[i
] = node
->type
;
1437 free_path_list(list
);
1441 free_path_list(list
);
1445 GpStatus WINGDIPAPI
GdipGetPathData(GpPath
*path
, GpPathData
* pathData
)
1447 TRACE("(%p, %p)\n", path
, pathData
);
1449 if(!path
|| !pathData
)
1450 return InvalidParameter
;
1452 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
1453 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
1454 memcpy(pathData
->Points
, path
->pathdata
.Points
, sizeof(PointF
) * pathData
->Count
);
1455 memcpy(pathData
->Types
, path
->pathdata
.Types
, pathData
->Count
);
1460 GpStatus WINGDIPAPI
GdipGetPathFillMode(GpPath
*path
, GpFillMode
*fillmode
)
1462 TRACE("(%p, %p)\n", path
, fillmode
);
1464 if(!path
|| !fillmode
)
1465 return InvalidParameter
;
1467 *fillmode
= path
->fill
;
1472 GpStatus WINGDIPAPI
GdipGetPathLastPoint(GpPath
* path
, GpPointF
* lastPoint
)
1476 TRACE("(%p, %p)\n", path
, lastPoint
);
1478 if(!path
|| !lastPoint
)
1479 return InvalidParameter
;
1481 count
= path
->pathdata
.Count
;
1483 *lastPoint
= path
->pathdata
.Points
[count
-1];
1488 GpStatus WINGDIPAPI
GdipGetPathPoints(GpPath
*path
, GpPointF
* points
, INT count
)
1490 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1493 return InvalidParameter
;
1495 if(count
< path
->pathdata
.Count
)
1496 return InsufficientBuffer
;
1498 memcpy(points
, path
->pathdata
.Points
, path
->pathdata
.Count
* sizeof(GpPointF
));
1503 GpStatus WINGDIPAPI
GdipGetPathPointsI(GpPath
*path
, GpPoint
* points
, INT count
)
1509 TRACE("(%p, %p, %d)\n", path
, points
, count
);
1512 return InvalidParameter
;
1514 ptf
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1515 if(!ptf
) return OutOfMemory
;
1517 ret
= GdipGetPathPoints(path
,ptf
,count
);
1519 for(i
= 0;i
< count
;i
++){
1520 points
[i
].X
= gdip_round(ptf
[i
].X
);
1521 points
[i
].Y
= gdip_round(ptf
[i
].Y
);
1528 GpStatus WINGDIPAPI
GdipGetPathTypes(GpPath
*path
, BYTE
* types
, INT count
)
1530 TRACE("(%p, %p, %d)\n", path
, types
, count
);
1533 return InvalidParameter
;
1535 if(count
< path
->pathdata
.Count
)
1536 return InsufficientBuffer
;
1538 memcpy(types
, path
->pathdata
.Types
, path
->pathdata
.Count
);
1543 /* Windows expands the bounding box to the maximum possible bounding box
1544 * for a given pen. For example, if a line join can extend past the point
1545 * it's joining by x units, the bounding box is extended by x units in every
1546 * direction (even though this is too conservative for most cases). */
1547 GpStatus WINGDIPAPI
GdipGetPathWorldBounds(GpPath
* path
, GpRectF
* bounds
,
1548 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1550 GpPointF
* points
, temp_pts
[4];
1552 REAL path_width
= 1.0, width
, height
, temp
, low_x
, low_y
, high_x
, high_y
;
1554 TRACE("(%p, %p, %s, %p)\n", path
, bounds
, debugstr_matrix(matrix
), pen
);
1556 /* Matrix and pen can be null. */
1557 if(!path
|| !bounds
)
1558 return InvalidParameter
;
1560 /* If path is empty just return. */
1561 count
= path
->pathdata
.Count
;
1563 bounds
->X
= bounds
->Y
= bounds
->Width
= bounds
->Height
= 0.0;
1567 points
= path
->pathdata
.Points
;
1569 low_x
= high_x
= points
[0].X
;
1570 low_y
= high_y
= points
[0].Y
;
1572 for(i
= 1; i
< count
; i
++){
1573 low_x
= min(low_x
, points
[i
].X
);
1574 low_y
= min(low_y
, points
[i
].Y
);
1575 high_x
= max(high_x
, points
[i
].X
);
1576 high_y
= max(high_y
, points
[i
].Y
);
1579 width
= high_x
- low_x
;
1580 height
= high_y
- low_y
;
1582 /* This looks unusual but it's the only way I can imitate windows. */
1584 temp_pts
[0].X
= low_x
;
1585 temp_pts
[0].Y
= low_y
;
1586 temp_pts
[1].X
= low_x
;
1587 temp_pts
[1].Y
= high_y
;
1588 temp_pts
[2].X
= high_x
;
1589 temp_pts
[2].Y
= high_y
;
1590 temp_pts
[3].X
= high_x
;
1591 temp_pts
[3].Y
= low_y
;
1593 GdipTransformMatrixPoints((GpMatrix
*)matrix
, temp_pts
, 4);
1594 low_x
= temp_pts
[0].X
;
1595 low_y
= temp_pts
[0].Y
;
1597 for(i
= 1; i
< 4; i
++){
1598 low_x
= min(low_x
, temp_pts
[i
].X
);
1599 low_y
= min(low_y
, temp_pts
[i
].Y
);
1603 width
= height
* fabs(matrix
->matrix
[2]) + width
* fabs(matrix
->matrix
[0]);
1604 height
= height
* fabs(matrix
->matrix
[3]) + temp
* fabs(matrix
->matrix
[1]);
1608 path_width
= pen
->width
/ 2.0;
1611 path_width
= max(path_width
, pen
->width
* pen
->miterlimit
/ 2.0);
1612 /* FIXME: this should probably also check for the startcap */
1613 if(pen
->endcap
& LineCapNoAnchor
)
1614 path_width
= max(path_width
, pen
->width
* 2.2);
1616 low_x
-= path_width
;
1617 low_y
-= path_width
;
1618 width
+= 2.0 * path_width
;
1619 height
+= 2.0 * path_width
;
1624 bounds
->Width
= width
;
1625 bounds
->Height
= height
;
1630 GpStatus WINGDIPAPI
GdipGetPathWorldBoundsI(GpPath
* path
, GpRect
* bounds
,
1631 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
1636 TRACE("(%p, %p, %s, %p)\n", path
, bounds
, debugstr_matrix(matrix
), pen
);
1638 ret
= GdipGetPathWorldBounds(path
,&boundsF
,matrix
,pen
);
1641 bounds
->X
= gdip_round(boundsF
.X
);
1642 bounds
->Y
= gdip_round(boundsF
.Y
);
1643 bounds
->Width
= gdip_round(boundsF
.Width
);
1644 bounds
->Height
= gdip_round(boundsF
.Height
);
1650 GpStatus WINGDIPAPI
GdipGetPointCount(GpPath
*path
, INT
*count
)
1652 TRACE("(%p, %p)\n", path
, count
);
1655 return InvalidParameter
;
1657 *count
= path
->pathdata
.Count
;
1662 GpStatus WINGDIPAPI
GdipReversePath(GpPath
* path
)
1665 INT start
= 0; /* position in reversed path */
1668 TRACE("(%p)\n", path
);
1671 return InvalidParameter
;
1673 count
= path
->pathdata
.Count
;
1675 if(count
== 0) return Ok
;
1677 revpath
.Points
= heap_alloc_zero(sizeof(GpPointF
)*count
);
1678 revpath
.Types
= heap_alloc_zero(sizeof(BYTE
)*count
);
1679 revpath
.Count
= count
;
1680 if(!revpath
.Points
|| !revpath
.Types
){
1681 heap_free(revpath
.Points
);
1682 heap_free(revpath
.Types
);
1686 for(i
= 0; i
< count
; i
++){
1688 /* find next start point */
1689 if(path
->pathdata
.Types
[count
-i
-1] == PathPointTypeStart
){
1691 for(j
= start
; j
<= i
; j
++){
1692 revpath
.Points
[j
] = path
->pathdata
.Points
[count
-j
-1];
1693 revpath
.Types
[j
] = path
->pathdata
.Types
[count
-j
-1];
1695 /* mark start point */
1696 revpath
.Types
[start
] = PathPointTypeStart
;
1697 /* set 'figure' endpoint type */
1699 revpath
.Types
[i
] = path
->pathdata
.Types
[count
-start
-1] & ~PathPointTypePathTypeMask
;
1700 revpath
.Types
[i
] |= revpath
.Types
[i
-1];
1703 revpath
.Types
[i
] = path
->pathdata
.Types
[start
];
1709 memcpy(path
->pathdata
.Points
, revpath
.Points
, sizeof(GpPointF
)*count
);
1710 memcpy(path
->pathdata
.Types
, revpath
.Types
, sizeof(BYTE
)*count
);
1712 heap_free(revpath
.Points
);
1713 heap_free(revpath
.Types
);
1718 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPointI(GpPath
* path
, INT x
, INT y
,
1719 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1721 TRACE("(%p, %d, %d, %p, %p, %p)\n", path
, x
, y
, pen
, graphics
, result
);
1723 return GdipIsOutlineVisiblePathPoint(path
, x
, y
, pen
, graphics
, result
);
1726 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
,
1727 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1731 GpMatrix
*transform
= NULL
;
1733 TRACE("(%p,%0.2f,%0.2f,%p,%p,%p)\n", path
, x
, y
, pen
, graphics
, result
);
1736 return InvalidParameter
;
1738 stat
= GdipClonePath(path
, &wide_path
);
1743 if (pen
->unit
== UnitPixel
&& graphics
!= NULL
)
1745 stat
= GdipCreateMatrix(&transform
);
1748 stat
= get_graphics_transform(graphics
, CoordinateSpaceDevice
,
1749 CoordinateSpaceWorld
, transform
);
1753 stat
= GdipWidenPath(wide_path
, pen
, transform
, 1.0);
1755 if (pen
->unit
== UnitPixel
&& graphics
!= NULL
)
1758 stat
= GdipInvertMatrix(transform
);
1761 stat
= GdipTransformPath(wide_path
, transform
);
1765 stat
= GdipIsVisiblePathPoint(wide_path
, x
, y
, graphics
, result
);
1767 GdipDeleteMatrix(transform
);
1769 GdipDeletePath(wide_path
);
1774 GpStatus WINGDIPAPI
GdipIsVisiblePathPointI(GpPath
* path
, INT x
, INT y
, GpGraphics
*graphics
, BOOL
*result
)
1776 TRACE("(%p, %d, %d, %p, %p)\n", path
, x
, y
, graphics
, result
);
1778 return GdipIsVisiblePathPoint(path
, x
, y
, graphics
, result
);
1781 /*****************************************************************************
1782 * GdipIsVisiblePathPoint [GDIPLUS.@]
1784 GpStatus WINGDIPAPI
GdipIsVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
, GpGraphics
*graphics
, BOOL
*result
)
1790 if(!path
|| !result
) return InvalidParameter
;
1792 status
= GdipCreateRegionPath(path
, ®ion
);
1796 status
= GdipGetRegionHRgn(region
, NULL
, &hrgn
);
1798 GdipDeleteRegion(region
);
1802 *result
= PtInRegion(hrgn
, gdip_round(x
), gdip_round(y
));
1805 GdipDeleteRegion(region
);
1810 GpStatus WINGDIPAPI
GdipStartPathFigure(GpPath
*path
)
1812 TRACE("(%p)\n", path
);
1815 return InvalidParameter
;
1817 path
->newfigure
= TRUE
;
1822 GpStatus WINGDIPAPI
GdipResetPath(GpPath
*path
)
1824 TRACE("(%p)\n", path
);
1827 return InvalidParameter
;
1829 path
->pathdata
.Count
= 0;
1830 path
->newfigure
= TRUE
;
1831 path
->fill
= FillModeAlternate
;
1836 GpStatus WINGDIPAPI
GdipSetPathFillMode(GpPath
*path
, GpFillMode fill
)
1838 TRACE("(%p, %d)\n", path
, fill
);
1841 return InvalidParameter
;
1848 GpStatus WINGDIPAPI
GdipTransformPath(GpPath
*path
, GpMatrix
*matrix
)
1850 TRACE("(%p, %s)\n", path
, debugstr_matrix(matrix
));
1853 return InvalidParameter
;
1855 if(path
->pathdata
.Count
== 0 || !matrix
)
1858 return GdipTransformMatrixPoints(matrix
, path
->pathdata
.Points
,
1859 path
->pathdata
.Count
);
1862 GpStatus WINGDIPAPI
GdipWarpPath(GpPath
*path
, GpMatrix
* matrix
,
1863 GDIPCONST GpPointF
*points
, INT count
, REAL x
, REAL y
, REAL width
,
1864 REAL height
, WarpMode warpmode
, REAL flatness
)
1866 FIXME("(%p,%s,%p,%i,%0.2f,%0.2f,%0.2f,%0.2f,%i,%0.2f)\n", path
, debugstr_matrix(matrix
),
1867 points
, count
, x
, y
, width
, height
, warpmode
, flatness
);
1869 return NotImplemented
;
1872 static void add_bevel_point(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1873 REAL pen_width
, int right_side
, path_list_node_t
**last_point
)
1875 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1876 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1877 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1878 REAL distance
= pen_width
/ 2.0;
1879 REAL bevel_dx
, bevel_dy
;
1881 if (segment_length
== 0.0)
1883 *last_point
= add_path_list_node(*last_point
, endpoint
->X
,
1884 endpoint
->Y
, PathPointTypeLine
);
1890 bevel_dx
= -distance
* segment_dy
/ segment_length
;
1891 bevel_dy
= distance
* segment_dx
/ segment_length
;
1895 bevel_dx
= distance
* segment_dy
/ segment_length
;
1896 bevel_dy
= -distance
* segment_dx
/ segment_length
;
1899 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ bevel_dx
,
1900 endpoint
->Y
+ bevel_dy
, PathPointTypeLine
);
1903 static void widen_joint(const GpPointF
*p1
, const GpPointF
*p2
, const GpPointF
*p3
,
1904 GpPen
* pen
, REAL pen_width
, path_list_node_t
**last_point
)
1909 case LineJoinMiterClipped
:
1910 if ((p2
->X
- p1
->X
) * (p3
->Y
- p1
->Y
) > (p2
->Y
- p1
->Y
) * (p3
->X
- p1
->X
))
1912 float distance
= pen_width
/ 2.0;
1913 float length_0
= sqrtf((p2
->X
-p1
->X
)*(p2
->X
-p1
->X
)+(p2
->Y
-p1
->Y
)*(p2
->Y
-p1
->Y
));
1914 float length_1
= sqrtf((p3
->X
-p2
->X
)*(p3
->X
-p2
->X
)+(p3
->Y
-p2
->Y
)*(p3
->Y
-p2
->Y
));
1915 float dx0
= distance
* (p2
->X
- p1
->X
) / length_0
;
1916 float dy0
= distance
* (p2
->Y
- p1
->Y
) / length_0
;
1917 float dx1
= distance
* (p3
->X
- p2
->X
) / length_1
;
1918 float dy1
= distance
* (p3
->Y
- p2
->Y
) / length_1
;
1919 float det
= (dy0
*dx1
- dx0
*dy1
);
1920 float dx
= (dx0
*dx1
*(dx0
-dx1
) + dy0
*dy0
*dx1
- dy1
*dy1
*dx0
)/det
;
1921 float dy
= (dy0
*dy1
*(dy0
-dy1
) + dx0
*dx0
*dy1
- dx1
*dx1
*dy0
)/det
;
1922 if (dx
*dx
+ dy
*dy
< pen
->miterlimit
*pen
->miterlimit
* distance
*distance
)
1924 *last_point
= add_path_list_node(*last_point
, p2
->X
+ dx
,
1925 p2
->Y
+ dy
, PathPointTypeLine
);
1928 else if (pen
->join
== LineJoinMiter
)
1932 FIXME("should add a clipped corner\n");
1934 /* else fall-through */
1936 /* else fall-through */
1939 add_bevel_point(p2
, p1
, pen_width
, 1, last_point
);
1940 add_bevel_point(p2
, p3
, pen_width
, 0, last_point
);
1945 static void widen_cap(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
1946 REAL pen_width
, GpLineCap cap
, GpCustomLineCap
* custom_cap
, int add_first_points
,
1947 int add_last_point
, path_list_node_t
**last_point
)
1953 if (add_first_points
)
1954 add_bevel_point(endpoint
, nextpoint
, pen_width
, 1, last_point
);
1956 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
1960 case LineCapArrowAnchor
:
1962 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1963 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1964 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
1965 REAL distance
= pen_width
/ 2.0;
1966 REAL bevel_dx
, bevel_dy
;
1967 REAL extend_dx
, extend_dy
;
1969 extend_dx
= distance
* segment_dx
/ segment_length
;
1970 extend_dy
= distance
* segment_dy
/ segment_length
;
1972 bevel_dx
= -extend_dy
;
1973 bevel_dy
= extend_dx
;
1975 if (cap
== LineCapCustom
)
1977 extend_dx
= -2.0 * custom_cap
->inset
* extend_dx
;
1978 extend_dy
= -2.0 * custom_cap
->inset
* extend_dy
;
1980 else if (cap
== LineCapArrowAnchor
)
1982 extend_dx
= -3.0 * extend_dx
;
1983 extend_dy
= -3.0 * extend_dy
;
1986 if (add_first_points
)
1987 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- extend_dx
+ bevel_dx
,
1988 endpoint
->Y
- extend_dy
+ bevel_dy
, PathPointTypeLine
);
1991 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- extend_dx
- bevel_dx
,
1992 endpoint
->Y
- extend_dy
- bevel_dy
, PathPointTypeLine
);
1997 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
1998 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
1999 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2000 REAL distance
= pen_width
/ 2.0;
2001 REAL dx
, dy
, dx2
, dy2
;
2002 const REAL control_point_distance
= 0.5522847498307935; /* 4/3 * (sqrt(2) - 1) */
2004 if (add_first_points
)
2006 dx
= -distance
* segment_dx
/ segment_length
;
2007 dy
= -distance
* segment_dy
/ segment_length
;
2009 dx2
= dx
* control_point_distance
;
2010 dy2
= dy
* control_point_distance
;
2012 /* first 90-degree arc */
2013 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
2014 endpoint
->Y
- dx
, PathPointTypeLine
);
2016 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
+ dx2
,
2017 endpoint
->Y
- dx
+ dy2
, PathPointTypeBezier
);
2019 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
+ dy2
,
2020 endpoint
->Y
+ dy
- dx2
, PathPointTypeBezier
);
2023 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
,
2024 endpoint
->Y
+ dy
, PathPointTypeBezier
);
2026 /* second 90-degree arc */
2027 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
- dy2
,
2028 endpoint
->Y
+ dy
+ dx2
, PathPointTypeBezier
);
2030 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
+ dx2
,
2031 endpoint
->Y
+ dx
+ dy2
, PathPointTypeBezier
);
2033 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
,
2034 endpoint
->Y
+ dx
, PathPointTypeBezier
);
2036 else if (add_last_point
)
2037 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
2040 case LineCapTriangle
:
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 distance
= pen_width
/ 2.0;
2048 dx
= distance
* segment_dx
/ segment_length
;
2049 dy
= distance
* segment_dy
/ segment_length
;
2051 if (add_first_points
) {
2052 add_bevel_point(endpoint
, nextpoint
, pen_width
, 1, last_point
);
2054 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
,
2055 endpoint
->Y
- dy
, PathPointTypeLine
);
2057 if (add_first_points
|| add_last_point
)
2058 add_bevel_point(endpoint
, nextpoint
, pen_width
, 0, last_point
);
2064 static void widen_open_figure(const GpPointF
*points
, int start
, int end
,
2065 GpPen
*pen
, REAL pen_width
, GpLineCap start_cap
, GpCustomLineCap
* custom_start
,
2066 GpLineCap end_cap
, GpCustomLineCap
* custom_end
, path_list_node_t
**last_point
);
2068 static void widen_closed_figure(const GpPointF
*points
, int start
, int end
,
2069 GpPen
*pen
, REAL pen_width
, path_list_node_t
**last_point
);
2071 static void add_anchor(const GpPointF
*endpoint
, const GpPointF
*nextpoint
,
2072 GpPen
*pen
, GpLineCap cap
, GpCustomLineCap
*custom
, path_list_node_t
**last_point
)
2074 REAL pen_width
= max(pen
->width
, 2.0);
2078 case LineCapNoAnchor
:
2080 case LineCapSquareAnchor
:
2082 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
2083 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2084 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2085 REAL distance
= pen_width
/ sqrtf(2.0);
2086 REAL par_dx
, par_dy
;
2087 REAL perp_dx
, perp_dy
;
2089 par_dx
= -distance
* segment_dx
/ segment_length
;
2090 par_dy
= -distance
* segment_dy
/ segment_length
;
2092 perp_dx
= -distance
* segment_dy
/ segment_length
;
2093 perp_dy
= distance
* segment_dx
/ segment_length
;
2095 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
- perp_dx
,
2096 endpoint
->Y
- par_dy
- perp_dy
, PathPointTypeStart
);
2097 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
+ perp_dx
,
2098 endpoint
->Y
- par_dy
+ perp_dy
, PathPointTypeLine
);
2099 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
+ perp_dx
,
2100 endpoint
->Y
+ par_dy
+ perp_dy
, PathPointTypeLine
);
2101 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
- perp_dx
,
2102 endpoint
->Y
+ par_dy
- perp_dy
, PathPointTypeLine
);
2105 case LineCapRoundAnchor
:
2107 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
2108 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2109 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2110 REAL dx
, dy
, dx2
, dy2
;
2111 const REAL control_point_distance
= 0.55228475; /* 4/3 * (sqrt(2) - 1) */
2113 dx
= -pen_width
* segment_dx
/ segment_length
;
2114 dy
= -pen_width
* segment_dy
/ segment_length
;
2116 dx2
= dx
* control_point_distance
;
2117 dy2
= dy
* control_point_distance
;
2119 /* starting point */
2120 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
2121 endpoint
->Y
- dx
, PathPointTypeStart
);
2123 /* first 90-degree arc */
2124 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
+ dx2
,
2125 endpoint
->Y
- dx
+ dy2
, PathPointTypeBezier
);
2126 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
+ dy2
,
2127 endpoint
->Y
+ dy
- dx2
, PathPointTypeBezier
);
2128 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
,
2129 endpoint
->Y
+ dy
, PathPointTypeBezier
);
2131 /* second 90-degree arc */
2132 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dx
- dy2
,
2133 endpoint
->Y
+ dy
+ dx2
, PathPointTypeBezier
);
2134 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
+ dx2
,
2135 endpoint
->Y
+ dx
+ dy2
, PathPointTypeBezier
);
2136 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
,
2137 endpoint
->Y
+ dx
, PathPointTypeBezier
);
2139 /* third 90-degree arc */
2140 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dy
- dx2
,
2141 endpoint
->Y
+ dx
- dy2
, PathPointTypeBezier
);
2142 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
- dy2
,
2143 endpoint
->Y
- dy
+ dx2
, PathPointTypeBezier
);
2144 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
,
2145 endpoint
->Y
- dy
, PathPointTypeBezier
);
2147 /* fourth 90-degree arc */
2148 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- dx
+ dy2
,
2149 endpoint
->Y
- dy
- dx2
, PathPointTypeBezier
);
2150 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
- dx2
,
2151 endpoint
->Y
- dx
- dy2
, PathPointTypeBezier
);
2152 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ dy
,
2153 endpoint
->Y
- dx
, PathPointTypeBezier
);
2157 case LineCapDiamondAnchor
:
2159 REAL segment_dy
= nextpoint
->Y
-endpoint
->Y
;
2160 REAL segment_dx
= nextpoint
->X
-endpoint
->X
;
2161 REAL segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2162 REAL par_dx
, par_dy
;
2163 REAL perp_dx
, perp_dy
;
2165 par_dx
= -pen_width
* segment_dx
/ segment_length
;
2166 par_dy
= -pen_width
* segment_dy
/ segment_length
;
2168 perp_dx
= -pen_width
* segment_dy
/ segment_length
;
2169 perp_dy
= pen_width
* segment_dx
/ segment_length
;
2171 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ par_dx
,
2172 endpoint
->Y
+ par_dy
, PathPointTypeStart
);
2173 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- perp_dx
,
2174 endpoint
->Y
- perp_dy
, PathPointTypeLine
);
2175 *last_point
= add_path_list_node(*last_point
, endpoint
->X
- par_dx
,
2176 endpoint
->Y
- par_dy
, PathPointTypeLine
);
2177 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ perp_dx
,
2178 endpoint
->Y
+ perp_dy
, PathPointTypeLine
);
2181 case LineCapArrowAnchor
:
2183 REAL segment_dy
= nextpoint
->Y
- endpoint
->Y
;
2184 REAL segment_dx
= nextpoint
->X
- endpoint
->X
;
2185 REAL segment_length
= sqrtf(segment_dy
* segment_dy
+ segment_dx
* segment_dx
);
2186 REAL par_dx
= pen_width
* segment_dx
/ segment_length
;
2187 REAL par_dy
= pen_width
* segment_dy
/ segment_length
;
2188 REAL perp_dx
= -par_dy
;
2189 REAL perp_dy
= par_dx
;
2191 *last_point
= add_path_list_node(*last_point
, endpoint
->X
,
2192 endpoint
->Y
, PathPointTypeStart
);
2193 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ SQRT3
* par_dx
- perp_dx
,
2194 endpoint
->Y
+ SQRT3
* par_dy
- perp_dy
, PathPointTypeLine
);
2195 *last_point
= add_path_list_node(*last_point
, endpoint
->X
+ SQRT3
* par_dx
+ perp_dx
,
2196 endpoint
->Y
+ SQRT3
* par_dy
+ perp_dy
, PathPointTypeLine
);
2201 REAL segment_dy
= nextpoint
->Y
- endpoint
->Y
;
2202 REAL segment_dx
= nextpoint
->X
- endpoint
->X
;
2203 REAL segment_length
= sqrtf(segment_dy
* segment_dy
+ segment_dx
* segment_dx
);
2205 REAL perp_dx
, perp_dy
;
2207 GpPointF
*tmp_points
;
2212 if (custom
->type
== CustomLineCapTypeAdjustableArrow
)
2214 GpAdjustableArrowCap
*arrow
= (GpAdjustableArrowCap
*)custom
;
2215 TRACE("GpAdjustableArrowCap middle_inset: %f height: %f width: %f\n",
2216 arrow
->middle_inset
, arrow
->height
, arrow
->width
);
2219 TRACE("GpCustomLineCap fill: %d basecap: %d inset: %f join: %d scale: %f pen_width:%f\n",
2220 custom
->fill
, custom
->basecap
, custom
->inset
, custom
->join
, custom
->scale
, pen_width
);
2222 sina
= -pen_width
* custom
->scale
* segment_dx
/ segment_length
;
2223 cosa
= pen_width
* custom
->scale
* segment_dy
/ segment_length
;
2225 /* Coordination where cap needs to be drawn */
2226 posx
= endpoint
->X
+ sina
;
2227 posy
= endpoint
->Y
- cosa
;
2231 tmp_points
= heap_alloc_zero(custom
->pathdata
.Count
* sizeof(GpPoint
));
2233 ERR("Out of memory\n");
2237 for (INT i
= 0; i
< custom
->pathdata
.Count
; i
++)
2239 tmp_points
[i
].X
= posx
+ custom
->pathdata
.Points
[i
].X
* cosa
+ (custom
->pathdata
.Points
[i
].Y
- 1.0) * sina
;
2240 tmp_points
[i
].Y
= posy
+ custom
->pathdata
.Points
[i
].X
* sina
- (custom
->pathdata
.Points
[i
].Y
- 1.0) * cosa
;
2242 if ((custom
->pathdata
.Types
[custom
->pathdata
.Count
- 1] & PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2243 widen_closed_figure(tmp_points
, 0, custom
->pathdata
.Count
- 1, pen
, pen_width
, last_point
);
2245 widen_open_figure(tmp_points
, 0, custom
->pathdata
.Count
- 1, pen
, pen_width
, custom
->strokeEndCap
, NULL
, custom
->strokeStartCap
, NULL
, last_point
);
2249 for (INT i
= 0; i
< custom
->pathdata
.Count
; i
++)
2251 /* rotation of CustomCap according to line */
2252 perp_dx
= custom
->pathdata
.Points
[i
].X
* cosa
+ (custom
->pathdata
.Points
[i
].Y
- 1.0) * sina
;
2253 perp_dy
= custom
->pathdata
.Points
[i
].X
* sina
- (custom
->pathdata
.Points
[i
].Y
- 1.0) * cosa
;
2254 *last_point
= add_path_list_node(*last_point
, posx
+ perp_dx
,
2255 posy
+ perp_dy
, custom
->pathdata
.Types
[i
]);
2258 /* FIXME: The line should be adjusted by the inset value of the custom cap. */
2263 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2266 static void widen_open_figure(const GpPointF
*points
, int start
, int end
,
2267 GpPen
*pen
, REAL pen_width
, GpLineCap start_cap
, GpCustomLineCap
* custom_start
,
2268 GpLineCap end_cap
, GpCustomLineCap
* custom_end
, path_list_node_t
**last_point
)
2271 path_list_node_t
*prev_point
;
2273 if (end
<= start
|| pen_width
== 0.0)
2276 prev_point
= *last_point
;
2278 widen_cap(&points
[start
], &points
[start
+1],
2279 pen_width
, start_cap
, custom_start
, FALSE
, TRUE
, last_point
);
2281 for (i
=start
+1; i
<end
; i
++)
2282 widen_joint(&points
[i
-1], &points
[i
], &points
[i
+1],
2283 pen
, pen_width
, last_point
);
2285 widen_cap(&points
[end
], &points
[end
-1],
2286 pen_width
, end_cap
, custom_end
, TRUE
, TRUE
, last_point
);
2288 for (i
=end
-1; i
>start
; i
--)
2289 widen_joint(&points
[i
+1], &points
[i
], &points
[i
-1],
2290 pen
, pen_width
, last_point
);
2292 widen_cap(&points
[start
], &points
[start
+1],
2293 pen_width
, start_cap
, custom_start
, TRUE
, FALSE
, last_point
);
2295 prev_point
->next
->type
= PathPointTypeStart
;
2296 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2299 static void widen_closed_figure(const GpPointF
*points
, int start
, int end
,
2300 GpPen
*pen
, REAL pen_width
, path_list_node_t
**last_point
)
2303 path_list_node_t
*prev_point
;
2305 if (end
<= start
|| pen_width
== 0.0)
2309 prev_point
= *last_point
;
2311 widen_joint(&points
[end
], &points
[start
],
2312 &points
[start
+1], pen
, pen_width
, last_point
);
2314 for (i
=start
+1; i
<end
; i
++)
2315 widen_joint(&points
[i
-1], &points
[i
],
2316 &points
[i
+1], pen
, pen_width
, last_point
);
2318 widen_joint(&points
[end
-1], &points
[end
],
2319 &points
[start
], pen
, pen_width
, last_point
);
2321 prev_point
->next
->type
= PathPointTypeStart
;
2322 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2325 prev_point
= *last_point
;
2327 widen_joint(&points
[start
], &points
[end
],
2328 &points
[end
-1], pen
, pen_width
, last_point
);
2330 for (i
=end
-1; i
>start
; i
--)
2331 widen_joint(&points
[i
+1], &points
[i
],
2332 &points
[i
-1], pen
, pen_width
, last_point
);
2334 widen_joint(&points
[start
+1], &points
[start
],
2335 &points
[end
], pen
, pen_width
, last_point
);
2337 prev_point
->next
->type
= PathPointTypeStart
;
2338 (*last_point
)->type
|= PathPointTypeCloseSubpath
;
2341 static void widen_dashed_figure(GpPath
*path
, int start
, int end
, int closed
,
2342 GpPen
*pen
, REAL pen_width
, path_list_node_t
**last_point
)
2347 const REAL
*dash_pattern
;
2348 REAL
*dash_pattern_scaled
;
2349 REAL dash_pattern_scaling
= max(pen
->width
, 1.0);
2351 GpPointF
*tmp_points
;
2354 REAL segment_length
;
2356 int num_tmp_points
=0;
2357 int draw_start_cap
=0;
2358 static const REAL dash_dot_dot
[6] = { 3.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
2360 if (end
<= start
|| pen_width
== 0.0)
2367 dash_pattern
= dash_dot_dot
;
2371 dash_pattern
= &dash_dot_dot
[2];
2374 case DashStyleDashDot
:
2375 dash_pattern
= dash_dot_dot
;
2378 case DashStyleDashDotDot
:
2379 dash_pattern
= dash_dot_dot
;
2382 case DashStyleCustom
:
2383 dash_pattern
= pen
->dashes
;
2384 dash_count
= pen
->numdashes
;
2388 dash_pattern_scaled
= heap_alloc(dash_count
* sizeof(REAL
));
2389 if (!dash_pattern_scaled
) return;
2391 for (i
= 0; i
< dash_count
; i
++)
2392 dash_pattern_scaled
[i
] = dash_pattern_scaling
* dash_pattern
[i
];
2394 tmp_points
= heap_alloc_zero((end
- start
+ 2) * sizeof(GpPoint
));
2396 heap_free(dash_pattern_scaled
);
2403 for (j
=start
; j
<= end
; j
++)
2415 segment_dy
= path
->pathdata
.Points
[j
].Y
- path
->pathdata
.Points
[i
].Y
;
2416 segment_dx
= path
->pathdata
.Points
[j
].X
- path
->pathdata
.Points
[i
].X
;
2417 segment_length
= sqrtf(segment_dy
*segment_dy
+ segment_dx
*segment_dx
);
2422 if (dash_pos
== 0.0)
2424 if ((dash_index
% 2) == 0)
2428 tmp_points
[0].X
= path
->pathdata
.Points
[i
].X
+ segment_dx
* segment_pos
/ segment_length
;
2429 tmp_points
[0].Y
= path
->pathdata
.Points
[i
].Y
+ segment_dy
* segment_pos
/ segment_length
;
2434 tmp_points
[num_tmp_points
].X
= path
->pathdata
.Points
[i
].X
+ segment_dx
* segment_pos
/ segment_length
;
2435 tmp_points
[num_tmp_points
].Y
= path
->pathdata
.Points
[i
].Y
+ segment_dy
* segment_pos
/ segment_length
;
2437 widen_open_figure(tmp_points
, 0, num_tmp_points
, pen
, pen_width
,
2438 draw_start_cap
? pen
->startcap
: LineCapFlat
, pen
->customstart
,
2439 LineCapFlat
, NULL
, last_point
);
2445 if (dash_pattern_scaled
[dash_index
] - dash_pos
> segment_length
- segment_pos
)
2447 /* advance to next segment */
2448 if ((dash_index
% 2) == 0)
2450 tmp_points
[num_tmp_points
] = path
->pathdata
.Points
[j
];
2453 dash_pos
+= segment_length
- segment_pos
;
2458 /* advance to next dash in pattern */
2459 segment_pos
+= dash_pattern_scaled
[dash_index
] - dash_pos
;
2461 if (++dash_index
== dash_count
)
2468 if (dash_index
% 2 == 0 && num_tmp_points
!= 0)
2470 /* last dash overflows last segment */
2471 widen_open_figure(tmp_points
, 0, num_tmp_points
-1, pen
, pen_width
,
2472 draw_start_cap
? pen
->startcap
: LineCapFlat
, pen
->customstart
,
2473 closed
? LineCapFlat
: pen
->endcap
, pen
->customend
, last_point
);
2476 heap_free(dash_pattern_scaled
);
2477 heap_free(tmp_points
);
2480 GpStatus WINGDIPAPI
GdipWidenPath(GpPath
*path
, GpPen
*pen
, GpMatrix
*matrix
,
2483 GpPath
*flat_path
=NULL
;
2485 path_list_node_t
*points
=NULL
, *last_point
=NULL
;
2486 int i
, subpath_start
=0, new_length
;
2488 TRACE("(%p,%p,%s,%0.2f)\n", path
, pen
, debugstr_matrix(matrix
), flatness
);
2491 return InvalidParameter
;
2493 if (path
->pathdata
.Count
<= 1)
2496 status
= GdipClonePath(path
, &flat_path
);
2499 status
= GdipFlattenPath(flat_path
, pen
->unit
== UnitPixel
? matrix
: NULL
, flatness
);
2501 if (status
== Ok
&& !init_path_list(&points
, 314.0, 22.0))
2502 status
= OutOfMemory
;
2506 REAL pen_width
= (pen
->unit
== UnitWorld
) ? max(pen
->width
, 1.0) : pen
->width
;
2507 BYTE
*types
= flat_path
->pathdata
.Types
;
2509 last_point
= points
;
2511 if (pen
->dashcap
!= DashCapFlat
)
2512 FIXME("unimplemented dash cap %d\n", pen
->dashcap
);
2514 if (pen
->join
== LineJoinRound
)
2515 FIXME("unimplemented line join %d\n", pen
->join
);
2517 if (pen
->align
!= PenAlignmentCenter
)
2518 FIXME("unimplemented pen alignment %d\n", pen
->align
);
2520 if (pen
->compound_array_size
!= 0)
2521 FIXME("unimplemented pen compoundline. Solid line will be drawn instead: %d\n", pen
->compound_array_size
);
2523 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
2525 if ((types
[i
]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2528 if ((types
[i
]&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2530 if (pen
->dash
!= DashStyleSolid
)
2531 widen_dashed_figure(flat_path
, subpath_start
, i
, 1, pen
, pen_width
, &last_point
);
2533 widen_closed_figure(flat_path
->pathdata
.Points
, subpath_start
, i
, pen
, pen_width
, &last_point
);
2535 else if (i
== flat_path
->pathdata
.Count
-1 ||
2536 (types
[i
+1]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2538 if (pen
->dash
!= DashStyleSolid
)
2539 widen_dashed_figure(flat_path
, subpath_start
, i
, 0, pen
, pen_width
, &last_point
);
2541 widen_open_figure(flat_path
->pathdata
.Points
, subpath_start
, i
, pen
, pen_width
,
2542 pen
->startcap
, pen
->customstart
, pen
->endcap
, pen
->customend
, &last_point
);
2546 for (i
=0; i
< flat_path
->pathdata
.Count
; i
++)
2548 if ((types
[i
]&PathPointTypeCloseSubpath
) == PathPointTypeCloseSubpath
)
2551 if ((types
[i
]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2554 if (i
== flat_path
->pathdata
.Count
-1 ||
2555 (types
[i
+1]&PathPointTypePathTypeMask
) == PathPointTypeStart
)
2557 if (pen
->startcap
& LineCapAnchorMask
)
2558 add_anchor(&flat_path
->pathdata
.Points
[subpath_start
],
2559 &flat_path
->pathdata
.Points
[subpath_start
+1],
2560 pen
, pen
->startcap
, pen
->customstart
, &last_point
);
2562 if (pen
->endcap
& LineCapAnchorMask
)
2563 add_anchor(&flat_path
->pathdata
.Points
[i
],
2564 &flat_path
->pathdata
.Points
[i
-1],
2565 pen
, pen
->endcap
, pen
->customend
, &last_point
);
2569 new_length
= path_list_count(points
)-1;
2571 if (!lengthen_path(path
, new_length
))
2572 status
= OutOfMemory
;
2577 path
->pathdata
.Count
= new_length
;
2579 last_point
= points
->next
;
2580 for (i
= 0; i
< new_length
; i
++)
2582 path
->pathdata
.Points
[i
] = last_point
->pt
;
2583 path
->pathdata
.Types
[i
] = last_point
->type
;
2584 last_point
= last_point
->next
;
2587 path
->fill
= FillModeWinding
;
2590 free_path_list(points
);
2592 GdipDeletePath(flat_path
);
2594 if (status
== Ok
&& pen
->unit
!= UnitPixel
)
2595 status
= GdipTransformPath(path
, matrix
);
2600 GpStatus WINGDIPAPI
GdipAddPathRectangle(GpPath
*path
, REAL x
, REAL y
,
2601 REAL width
, REAL height
)
2608 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path
, x
, y
, width
, height
);
2611 return InvalidParameter
;
2613 if (width
<= 0.0 || height
<= 0.0)
2616 /* make a backup copy of path data */
2617 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2620 /* rectangle should start as new path */
2621 old_new
= path
->newfigure
;
2622 path
->newfigure
= TRUE
;
2623 if((retstat
= GdipAddPathLine(path
,x
,y
,x
+width
,y
)) != Ok
){
2624 path
->newfigure
= old_new
;
2629 ptf
[0].Y
= y
+height
;
2631 ptf
[1].Y
= y
+height
;
2633 if((retstat
= GdipAddPathLine2(path
, ptf
, 2)) != Ok
) goto fail
;
2634 path
->pathdata
.Types
[path
->pathdata
.Count
-1] |= PathPointTypeCloseSubpath
;
2637 GdipDeletePath(backup
);
2642 heap_free(path
->pathdata
.Points
);
2643 heap_free(path
->pathdata
.Types
);
2644 memcpy(path
, backup
, sizeof(*path
));
2650 GpStatus WINGDIPAPI
GdipAddPathRectangleI(GpPath
*path
, INT x
, INT y
,
2651 INT width
, INT height
)
2653 TRACE("(%p, %d, %d, %d, %d)\n", path
, x
, y
, width
, height
);
2655 return GdipAddPathRectangle(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2658 GpStatus WINGDIPAPI
GdipAddPathRectangles(GpPath
*path
, GDIPCONST GpRectF
*rects
, INT count
)
2664 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2666 /* count == 0 - verified condition */
2667 if(!path
|| !rects
|| count
== 0)
2668 return InvalidParameter
;
2673 /* make a backup copy */
2674 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
2677 for(i
= 0; i
< count
; i
++){
2678 if((retstat
= GdipAddPathRectangle(path
,rects
[i
].X
,rects
[i
].Y
,rects
[i
].Width
,rects
[i
].Height
)) != Ok
)
2683 GdipDeletePath(backup
);
2688 heap_free(path
->pathdata
.Points
);
2689 heap_free(path
->pathdata
.Types
);
2690 memcpy(path
, backup
, sizeof(*path
));
2696 GpStatus WINGDIPAPI
GdipAddPathRectanglesI(GpPath
*path
, GDIPCONST GpRect
*rects
, INT count
)
2702 TRACE("(%p, %p, %d)\n", path
, rects
, count
);
2704 if(!rects
|| count
== 0)
2705 return InvalidParameter
;
2710 rectsF
= heap_alloc_zero(sizeof(GpRectF
)*count
);
2712 for(i
= 0;i
< count
;i
++)
2713 set_rect(&rectsF
[i
], rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2715 retstat
= GdipAddPathRectangles(path
, rectsF
, count
);
2721 GpStatus WINGDIPAPI
GdipSetPathMarker(GpPath
* path
)
2725 TRACE("(%p)\n", path
);
2728 return InvalidParameter
;
2730 count
= path
->pathdata
.Count
;
2732 /* set marker flag */
2734 path
->pathdata
.Types
[count
-1] |= PathPointTypePathMarker
;
2739 GpStatus WINGDIPAPI
GdipClearPathMarkers(GpPath
* path
)
2744 TRACE("(%p)\n", path
);
2747 return InvalidParameter
;
2749 count
= path
->pathdata
.Count
;
2751 for(i
= 0; i
< count
- 1; i
++){
2752 path
->pathdata
.Types
[i
] &= ~PathPointTypePathMarker
;
2758 GpStatus WINGDIPAPI
GdipWindingModeOutline(GpPath
*path
, GpMatrix
*matrix
, REAL flatness
)
2760 FIXME("stub: %p, %p, %.2f\n", path
, matrix
, flatness
);
2761 return NotImplemented
;
2764 #define FLAGS_INTPATH 0x4000
2773 /* Test to see if the path could be stored as an array of shorts */
2774 static BOOL
is_integer_path(const GpPath
*path
)
2778 if (!path
->pathdata
.Count
) return FALSE
;
2780 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2783 x
= gdip_round(path
->pathdata
.Points
[i
].X
);
2784 y
= gdip_round(path
->pathdata
.Points
[i
].Y
);
2785 if (path
->pathdata
.Points
[i
].X
!= (REAL
)x
|| path
->pathdata
.Points
[i
].Y
!= (REAL
)y
)
2791 DWORD
write_path_data(GpPath
*path
, void *data
)
2793 struct path_header
*header
= data
;
2794 BOOL integer_path
= is_integer_path(path
);
2798 size
= sizeof(struct path_header
) + path
->pathdata
.Count
;
2800 size
+= sizeof(short[2]) * path
->pathdata
.Count
;
2802 size
+= sizeof(float[2]) * path
->pathdata
.Count
;
2803 size
= (size
+ 3) & ~3;
2805 if (!data
) return size
;
2807 header
->version
= VERSION_MAGIC2
;
2808 header
->count
= path
->pathdata
.Count
;
2809 header
->flags
= integer_path
? FLAGS_INTPATH
: 0;
2813 short *points
= (short*)(header
+ 1);
2814 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2816 points
[2*i
] = path
->pathdata
.Points
[i
].X
;
2817 points
[2*i
+ 1] = path
->pathdata
.Points
[i
].Y
;
2819 types
= (BYTE
*)(points
+ 2*i
);
2823 float *points
= (float*)(header
+ 1);
2824 for (i
= 0; i
< path
->pathdata
.Count
; i
++)
2826 points
[2*i
] = path
->pathdata
.Points
[i
].X
;
2827 points
[2*i
+ 1] = path
->pathdata
.Points
[i
].Y
;
2829 types
= (BYTE
*)(points
+ 2*i
);
2832 for (i
=0; i
<path
->pathdata
.Count
; i
++)
2833 types
[i
] = path
->pathdata
.Types
[i
];
2834 memset(types
+ i
, 0, ((path
->pathdata
.Count
+ 3) & ~3) - path
->pathdata
.Count
);