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 /* make sure path has enough space for len more points */
37 static BOOL
lengthen_path(GpPath
*path
, INT len
)
39 /* initial allocation */
40 if(path
->datalen
== 0){
41 path
->datalen
= len
* 2;
43 path
->pathdata
.Points
= GdipAlloc(path
->datalen
* sizeof(PointF
));
44 if(!path
->pathdata
.Points
) return FALSE
;
46 path
->pathdata
.Types
= GdipAlloc(path
->datalen
);
47 if(!path
->pathdata
.Types
){
48 GdipFree(path
->pathdata
.Points
);
52 /* reallocation, double size of arrays */
53 else if(path
->datalen
- path
->pathdata
.Count
< len
){
54 while(path
->datalen
- path
->pathdata
.Count
< len
)
57 path
->pathdata
.Points
= HeapReAlloc(GetProcessHeap(), 0,
58 path
->pathdata
.Points
, path
->datalen
* sizeof(PointF
));
59 if(!path
->pathdata
.Points
) return FALSE
;
61 path
->pathdata
.Types
= HeapReAlloc(GetProcessHeap(), 0,
62 path
->pathdata
.Types
, path
->datalen
);
63 if(!path
->pathdata
.Types
) return FALSE
;
69 GpStatus WINGDIPAPI
GdipAddPathArc(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
70 REAL y2
, REAL startAngle
, REAL sweepAngle
)
72 INT count
, old_count
, i
;
75 return InvalidParameter
;
77 count
= arc2polybezier(NULL
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
81 if(!lengthen_path(path
, count
))
84 old_count
= path
->pathdata
.Count
;
85 arc2polybezier(&path
->pathdata
.Points
[old_count
], x1
, y1
, x2
, y2
,
86 startAngle
, sweepAngle
);
88 for(i
= 0; i
< count
; i
++){
89 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeBezier
;
92 path
->pathdata
.Types
[old_count
] =
93 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
94 path
->newfigure
= FALSE
;
95 path
->pathdata
.Count
+= count
;
100 GpStatus WINGDIPAPI
GdipAddPathArcI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
101 INT y2
, REAL startAngle
, REAL sweepAngle
)
103 return GdipAddPathArc(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,startAngle
,sweepAngle
);
106 GpStatus WINGDIPAPI
GdipAddPathBezier(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
107 REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
112 return InvalidParameter
;
114 if(!lengthen_path(path
, 4))
117 old_count
= path
->pathdata
.Count
;
119 path
->pathdata
.Points
[old_count
].X
= x1
;
120 path
->pathdata
.Points
[old_count
].Y
= y1
;
121 path
->pathdata
.Points
[old_count
+ 1].X
= x2
;
122 path
->pathdata
.Points
[old_count
+ 1].Y
= y2
;
123 path
->pathdata
.Points
[old_count
+ 2].X
= x3
;
124 path
->pathdata
.Points
[old_count
+ 2].Y
= y3
;
125 path
->pathdata
.Points
[old_count
+ 3].X
= x4
;
126 path
->pathdata
.Points
[old_count
+ 3].Y
= y4
;
128 path
->pathdata
.Types
[old_count
] =
129 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
130 path
->pathdata
.Types
[old_count
+ 1] = PathPointTypeBezier
;
131 path
->pathdata
.Types
[old_count
+ 2] = PathPointTypeBezier
;
132 path
->pathdata
.Types
[old_count
+ 3] = PathPointTypeBezier
;
134 path
->newfigure
= FALSE
;
135 path
->pathdata
.Count
+= 4;
140 GpStatus WINGDIPAPI
GdipAddPathBezierI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
141 INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
143 return GdipAddPathBezier(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,(REAL
)x3
,(REAL
)y3
,
147 GpStatus WINGDIPAPI
GdipAddPathBeziers(GpPath
*path
, GDIPCONST GpPointF
*points
,
152 if(!path
|| !points
|| ((count
- 1) % 3))
153 return InvalidParameter
;
155 if(!lengthen_path(path
, count
))
158 old_count
= path
->pathdata
.Count
;
160 for(i
= 0; i
< count
; i
++){
161 path
->pathdata
.Points
[old_count
+ i
].X
= points
[i
].X
;
162 path
->pathdata
.Points
[old_count
+ i
].Y
= points
[i
].Y
;
163 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeBezier
;
166 path
->pathdata
.Types
[old_count
] =
167 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
168 path
->newfigure
= FALSE
;
169 path
->pathdata
.Count
+= count
;
174 GpStatus WINGDIPAPI
GdipAddPathBeziersI(GpPath
*path
, GDIPCONST GpPoint
*points
,
181 if(!points
|| ((count
- 1) % 3))
182 return InvalidParameter
;
184 ptsF
= GdipAlloc(sizeof(GpPointF
) * count
);
188 for(i
= 0; i
< count
; i
++){
189 ptsF
[i
].X
= (REAL
)points
[i
].X
;
190 ptsF
[i
].Y
= (REAL
)points
[i
].Y
;
193 ret
= GdipAddPathBeziers(path
, ptsF
, count
);
199 GpStatus WINGDIPAPI
GdipAddPathClosedCurve(GpPath
*path
, GDIPCONST GpPointF
*points
,
202 return GdipAddPathClosedCurve2(path
, points
, count
, 1.0);
205 GpStatus WINGDIPAPI
GdipAddPathClosedCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
,
208 return GdipAddPathClosedCurve2I(path
, points
, count
, 1.0);
211 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
,
212 INT count
, REAL tension
)
214 INT i
, len_pt
= (count
+ 1)*3-2;
220 if(!path
|| !points
|| count
<= 1)
221 return InvalidParameter
;
223 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
224 pts
= GdipAlloc((count
+ 1)*sizeof(GpPointF
));
231 /* copy source points to extend with the last one */
232 memcpy(pts
, points
, sizeof(GpPointF
)*count
);
235 tension
= tension
* TENSION_CONST
;
237 for(i
= 0; i
< count
-1; i
++){
238 calc_curve_bezier(&(pts
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
242 pt
[3*i
+3].X
= pts
[i
+1].X
;
243 pt
[3*i
+3].Y
= pts
[i
+1].Y
;
248 /* points [len_pt-2] and [0] are calculated
249 separetely to connect splines properly */
250 pts
[0] = points
[count
-1];
251 pts
[1] = points
[0]; /* equals to start and end of a resulting path */
254 calc_curve_bezier(pts
, tension
, &x1
, &y1
, &x2
, &y2
);
262 pt
[len_pt
-1].X
= pt
[0].X
;
263 pt
[len_pt
-1].Y
= pt
[0].Y
;
265 stat
= GdipAddPathBeziers(path
, pt
, len_pt
);
269 INT count
= path
->pathdata
.Count
;
270 path
->pathdata
.Types
[count
- 1] |= PathPointTypeCloseSubpath
;
271 path
->newfigure
= TRUE
;
280 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
281 INT count
, REAL tension
)
287 if(!path
|| !points
|| count
<= 1)
288 return InvalidParameter
;
290 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
294 for(i
= 0; i
< count
; i
++){
295 ptf
[i
].X
= (REAL
)points
[i
].X
;
296 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
299 stat
= GdipAddPathClosedCurve2(path
, ptf
, count
, tension
);
306 GpStatus WINGDIPAPI
GdipAddPathCurve(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
308 if(!path
|| !points
|| count
<= 1)
309 return InvalidParameter
;
311 return GdipAddPathCurve2(path
, points
, count
, 1.0);
314 GpStatus WINGDIPAPI
GdipAddPathCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
316 if(!path
|| !points
|| count
<= 1)
317 return InvalidParameter
;
319 return GdipAddPathCurve2I(path
, points
, count
, 1.0);
322 GpStatus WINGDIPAPI
GdipAddPathCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
,
325 INT i
, len_pt
= count
*3-2;
330 if(!path
|| !points
|| count
<= 1)
331 return InvalidParameter
;
333 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
337 tension
= tension
* TENSION_CONST
;
339 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
342 pt
[0].X
= points
[0].X
;
343 pt
[0].Y
= points
[0].Y
;
347 for(i
= 0; i
< count
-2; i
++){
348 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
352 pt
[3*i
+3].X
= points
[i
+1].X
;
353 pt
[3*i
+3].Y
= points
[i
+1].Y
;
358 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
359 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
363 pt
[len_pt
-1].X
= points
[count
-1].X
;
364 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
366 stat
= GdipAddPathBeziers(path
, pt
, len_pt
);
373 GpStatus WINGDIPAPI
GdipAddPathCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
374 INT count
, REAL tension
)
380 if(!path
|| !points
|| count
<= 1)
381 return InvalidParameter
;
383 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
387 for(i
= 0; i
< count
; i
++){
388 ptf
[i
].X
= (REAL
)points
[i
].X
;
389 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
392 stat
= GdipAddPathCurve2(path
, ptf
, count
, tension
);
399 GpStatus WINGDIPAPI
GdipAddPathEllipse(GpPath
*path
, REAL x
, REAL y
, REAL width
,
402 INT old_count
, numpts
;
405 return InvalidParameter
;
407 if(!lengthen_path(path
, MAX_ARC_PTS
))
410 old_count
= path
->pathdata
.Count
;
411 if((numpts
= arc2polybezier(&path
->pathdata
.Points
[old_count
], x
, y
, width
,
412 height
, 0.0, 360.0)) != MAX_ARC_PTS
){
413 ERR("expected %d points but got %d\n", MAX_ARC_PTS
, numpts
);
417 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeBezier
,
420 /* An ellipse is an intrinsic figure (always is its own subpath). */
421 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
422 path
->pathdata
.Types
[old_count
+ MAX_ARC_PTS
- 1] |= PathPointTypeCloseSubpath
;
423 path
->newfigure
= TRUE
;
424 path
->pathdata
.Count
+= MAX_ARC_PTS
;
429 GpStatus WINGDIPAPI
GdipAddPathEllipseI(GpPath
*path
, INT x
, INT y
, INT width
,
432 return GdipAddPathEllipse(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
435 GpStatus WINGDIPAPI
GdipAddPathLine2(GpPath
*path
, GDIPCONST GpPointF
*points
,
441 return InvalidParameter
;
443 if(!lengthen_path(path
, count
))
446 old_count
= path
->pathdata
.Count
;
448 for(i
= 0; i
< count
; i
++){
449 path
->pathdata
.Points
[old_count
+ i
].X
= points
[i
].X
;
450 path
->pathdata
.Points
[old_count
+ i
].Y
= points
[i
].Y
;
451 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeLine
;
455 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
456 path
->newfigure
= FALSE
;
459 path
->pathdata
.Count
+= count
;
464 GpStatus WINGDIPAPI
GdipAddPathLine2I(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
471 return InvalidParameter
;
473 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
474 if(!pointsF
) return OutOfMemory
;
476 for(i
= 0;i
< count
; i
++){
477 pointsF
[i
].X
= (REAL
)points
[i
].X
;
478 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
481 stat
= GdipAddPathLine2(path
, pointsF
, count
);
488 GpStatus WINGDIPAPI
GdipAddPathLine(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
493 return InvalidParameter
;
495 if(!lengthen_path(path
, 2))
498 old_count
= path
->pathdata
.Count
;
500 path
->pathdata
.Points
[old_count
].X
= x1
;
501 path
->pathdata
.Points
[old_count
].Y
= y1
;
502 path
->pathdata
.Points
[old_count
+ 1].X
= x2
;
503 path
->pathdata
.Points
[old_count
+ 1].Y
= y2
;
505 path
->pathdata
.Types
[old_count
] =
506 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
507 path
->pathdata
.Types
[old_count
+ 1] = PathPointTypeLine
;
509 path
->newfigure
= FALSE
;
510 path
->pathdata
.Count
+= 2;
515 GpStatus WINGDIPAPI
GdipAddPathLineI(GpPath
*path
, INT x1
, INT y1
, INT x2
, INT y2
)
517 return GdipAddPathLine(path
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
520 GpStatus WINGDIPAPI
GdipAddPathPath(GpPath
*path
, GDIPCONST GpPath
* addingPath
,
523 INT old_count
, count
;
525 if(!path
|| !addingPath
)
526 return InvalidParameter
;
528 old_count
= path
->pathdata
.Count
;
529 count
= addingPath
->pathdata
.Count
;
531 if(!lengthen_path(path
, count
))
534 memcpy(&path
->pathdata
.Points
[old_count
], addingPath
->pathdata
.Points
,
535 count
* sizeof(GpPointF
));
536 memcpy(&path
->pathdata
.Types
[old_count
], addingPath
->pathdata
.Types
, count
);
538 if(path
->newfigure
|| !connect
)
539 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
541 path
->pathdata
.Types
[old_count
] = PathPointTypeLine
;
543 path
->newfigure
= FALSE
;
544 path
->pathdata
.Count
+= count
;
549 GpStatus WINGDIPAPI
GdipAddPathPolygon(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
553 if(!path
|| !points
|| count
< 3)
554 return InvalidParameter
;
556 if(!lengthen_path(path
, count
))
559 old_count
= path
->pathdata
.Count
;
561 memcpy(&path
->pathdata
.Points
[old_count
], points
, count
*sizeof(GpPointF
));
562 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeLine
, count
- 1);
564 /* A polygon is an intrinsic figure */
565 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
566 path
->pathdata
.Types
[old_count
+ count
- 1] |= PathPointTypeCloseSubpath
;
567 path
->newfigure
= TRUE
;
568 path
->pathdata
.Count
+= count
;
573 GpStatus WINGDIPAPI
GdipAddPathPolygonI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
579 if(!points
|| count
< 3)
580 return InvalidParameter
;
582 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
586 for(i
= 0; i
< count
; i
++){
587 ptf
[i
].X
= (REAL
)points
[i
].X
;
588 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
591 status
= GdipAddPathPolygon(path
, ptf
, count
);
598 GpStatus WINGDIPAPI
GdipClonePath(GpPath
* path
, GpPath
**clone
)
601 return InvalidParameter
;
603 *clone
= GdipAlloc(sizeof(GpPath
));
604 if(!*clone
) return OutOfMemory
;
608 (*clone
)->pathdata
.Points
= GdipAlloc(path
->datalen
* sizeof(PointF
));
609 (*clone
)->pathdata
.Types
= GdipAlloc(path
->datalen
);
610 if(!(*clone
)->pathdata
.Points
|| !(*clone
)->pathdata
.Types
){
612 GdipFree((*clone
)->pathdata
.Points
);
613 GdipFree((*clone
)->pathdata
.Types
);
617 memcpy((*clone
)->pathdata
.Points
, path
->pathdata
.Points
,
618 path
->datalen
* sizeof(PointF
));
619 memcpy((*clone
)->pathdata
.Types
, path
->pathdata
.Types
, path
->datalen
);
624 GpStatus WINGDIPAPI
GdipClosePathFigure(GpPath
* path
)
627 return InvalidParameter
;
629 if(path
->pathdata
.Count
> 0){
630 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
631 path
->newfigure
= TRUE
;
637 GpStatus WINGDIPAPI
GdipClosePathFigures(GpPath
* path
)
642 return InvalidParameter
;
644 for(i
= 1; i
< path
->pathdata
.Count
; i
++){
645 if(path
->pathdata
.Types
[i
] == PathPointTypeStart
)
646 path
->pathdata
.Types
[i
-1] |= PathPointTypeCloseSubpath
;
649 path
->newfigure
= TRUE
;
654 GpStatus WINGDIPAPI
GdipCreatePath(GpFillMode fill
, GpPath
**path
)
657 return InvalidParameter
;
659 *path
= GdipAlloc(sizeof(GpPath
));
660 if(!*path
) return OutOfMemory
;
662 (*path
)->fill
= fill
;
663 (*path
)->newfigure
= TRUE
;
668 GpStatus WINGDIPAPI
GdipCreatePath2(GDIPCONST GpPointF
* points
,
669 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
672 return InvalidParameter
;
674 *path
= GdipAlloc(sizeof(GpPath
));
675 if(!*path
) return OutOfMemory
;
677 (*path
)->pathdata
.Points
= GdipAlloc(count
* sizeof(PointF
));
678 (*path
)->pathdata
.Types
= GdipAlloc(count
);
680 if(!(*path
)->pathdata
.Points
|| !(*path
)->pathdata
.Types
){
681 GdipFree((*path
)->pathdata
.Points
);
682 GdipFree((*path
)->pathdata
.Types
);
687 memcpy((*path
)->pathdata
.Points
, points
, count
* sizeof(PointF
));
688 memcpy((*path
)->pathdata
.Types
, types
, count
);
689 (*path
)->pathdata
.Count
= count
;
690 (*path
)->datalen
= count
;
692 (*path
)->fill
= fill
;
693 (*path
)->newfigure
= TRUE
;
698 GpStatus WINGDIPAPI
GdipCreatePath2I(GDIPCONST GpPoint
* points
,
699 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
705 ptF
= GdipAlloc(sizeof(GpPointF
)*count
);
707 for(i
= 0;i
< count
; i
++){
708 ptF
[i
].X
= (REAL
)points
[i
].X
;
709 ptF
[i
].Y
= (REAL
)points
[i
].Y
;
712 ret
= GdipCreatePath2(ptF
, types
, count
, fill
, path
);
719 GpStatus WINGDIPAPI
GdipDeletePath(GpPath
*path
)
722 return InvalidParameter
;
724 GdipFree(path
->pathdata
.Points
);
725 GdipFree(path
->pathdata
.Types
);
731 GpStatus WINGDIPAPI
GdipGetPathData(GpPath
*path
, GpPathData
* pathData
)
733 if(!path
|| !pathData
)
734 return InvalidParameter
;
736 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
737 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
738 memcpy(pathData
->Points
, path
->pathdata
.Points
, sizeof(PointF
) * pathData
->Count
);
739 memcpy(pathData
->Types
, path
->pathdata
.Types
, pathData
->Count
);
744 GpStatus WINGDIPAPI
GdipGetPathFillMode(GpPath
*path
, GpFillMode
*fillmode
)
746 if(!path
|| !fillmode
)
747 return InvalidParameter
;
749 *fillmode
= path
->fill
;
754 GpStatus WINGDIPAPI
GdipGetPathLastPoint(GpPath
* path
, GpPointF
* lastPoint
)
758 if(!path
|| !lastPoint
)
759 return InvalidParameter
;
761 count
= path
->pathdata
.Count
;
763 *lastPoint
= path
->pathdata
.Points
[count
-1];
768 GpStatus WINGDIPAPI
GdipGetPathPoints(GpPath
*path
, GpPointF
* points
, INT count
)
771 return InvalidParameter
;
773 if(count
< path
->pathdata
.Count
)
774 return InsufficientBuffer
;
776 memcpy(points
, path
->pathdata
.Points
, path
->pathdata
.Count
* sizeof(GpPointF
));
781 GpStatus WINGDIPAPI
GdipGetPathPointsI(GpPath
*path
, GpPoint
* points
, INT count
)
788 return InvalidParameter
;
790 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
791 if(!ptf
) return OutOfMemory
;
793 ret
= GdipGetPathPoints(path
,ptf
,count
);
795 for(i
= 0;i
< count
;i
++){
796 points
[i
].X
= roundr(ptf
[i
].X
);
797 points
[i
].Y
= roundr(ptf
[i
].Y
);
804 GpStatus WINGDIPAPI
GdipGetPathTypes(GpPath
*path
, BYTE
* types
, INT count
)
807 return InvalidParameter
;
809 if(count
< path
->pathdata
.Count
)
810 return InsufficientBuffer
;
812 memcpy(types
, path
->pathdata
.Types
, path
->pathdata
.Count
);
817 /* Windows expands the bounding box to the maximum possible bounding box
818 * for a given pen. For example, if a line join can extend past the point
819 * it's joining by x units, the bounding box is extended by x units in every
820 * direction (even though this is too conservative for most cases). */
821 GpStatus WINGDIPAPI
GdipGetPathWorldBounds(GpPath
* path
, GpRectF
* bounds
,
822 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
824 GpPointF
* points
, temp_pts
[4];
826 REAL path_width
= 1.0, width
, height
, temp
, low_x
, low_y
, high_x
, high_y
;
828 /* Matrix and pen can be null. */
830 return InvalidParameter
;
832 /* If path is empty just return. */
833 count
= path
->pathdata
.Count
;
835 bounds
->X
= bounds
->Y
= bounds
->Width
= bounds
->Height
= 0.0;
839 points
= path
->pathdata
.Points
;
841 low_x
= high_x
= points
[0].X
;
842 low_y
= high_y
= points
[0].Y
;
844 for(i
= 1; i
< count
; i
++){
845 low_x
= min(low_x
, points
[i
].X
);
846 low_y
= min(low_y
, points
[i
].Y
);
847 high_x
= max(high_x
, points
[i
].X
);
848 high_y
= max(high_y
, points
[i
].Y
);
851 width
= high_x
- low_x
;
852 height
= high_y
- low_y
;
854 /* This looks unusual but it's the only way I can imitate windows. */
856 temp_pts
[0].X
= low_x
;
857 temp_pts
[0].Y
= low_y
;
858 temp_pts
[1].X
= low_x
;
859 temp_pts
[1].Y
= high_y
;
860 temp_pts
[2].X
= high_x
;
861 temp_pts
[2].Y
= high_y
;
862 temp_pts
[3].X
= high_x
;
863 temp_pts
[3].Y
= low_y
;
865 GdipTransformMatrixPoints((GpMatrix
*)matrix
, temp_pts
, 4);
866 low_x
= temp_pts
[0].X
;
867 low_y
= temp_pts
[0].Y
;
869 for(i
= 1; i
< 4; i
++){
870 low_x
= min(low_x
, temp_pts
[i
].X
);
871 low_y
= min(low_y
, temp_pts
[i
].Y
);
875 width
= height
* fabs(matrix
->matrix
[2]) + width
* fabs(matrix
->matrix
[0]);
876 height
= height
* fabs(matrix
->matrix
[3]) + temp
* fabs(matrix
->matrix
[1]);
880 path_width
= pen
->width
/ 2.0;
883 path_width
= max(path_width
, pen
->width
* pen
->miterlimit
/ 2.0);
884 /* FIXME: this should probably also check for the startcap */
885 if(pen
->endcap
& LineCapNoAnchor
)
886 path_width
= max(path_width
, pen
->width
* 2.2);
890 width
+= 2.0 * path_width
;
891 height
+= 2.0 * path_width
;
896 bounds
->Width
= width
;
897 bounds
->Height
= height
;
902 GpStatus WINGDIPAPI
GdipGetPathWorldBoundsI(GpPath
* path
, GpRect
* bounds
,
903 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
908 ret
= GdipGetPathWorldBounds(path
,&boundsF
,matrix
,pen
);
911 bounds
->X
= roundr(boundsF
.X
);
912 bounds
->Y
= roundr(boundsF
.Y
);
913 bounds
->Width
= roundr(boundsF
.Width
);
914 bounds
->Height
= roundr(boundsF
.Height
);
920 GpStatus WINGDIPAPI
GdipGetPointCount(GpPath
*path
, INT
*count
)
923 return InvalidParameter
;
925 *count
= path
->pathdata
.Count
;
930 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPointI(GpPath
* path
, INT x
, INT y
,
931 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
933 return GdipIsOutlineVisiblePathPoint(path
, x
, y
, pen
, graphics
, result
);
936 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
,
937 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
942 return InvalidParameter
;
945 FIXME("not implemented\n");
947 return NotImplemented
;
950 GpStatus WINGDIPAPI
GdipIsVisiblePathPointI(GpPath
* path
, INT x
, INT y
, GpGraphics
*graphics
, BOOL
*result
)
952 return GdipIsVisiblePathPoint(path
, x
, y
, graphics
, result
);
955 GpStatus WINGDIPAPI
GdipIsVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
, GpGraphics
*graphics
, BOOL
*result
)
959 if(!path
) return InvalidParameter
;
962 FIXME("not implemented\n");
964 return NotImplemented
;
967 GpStatus WINGDIPAPI
GdipStartPathFigure(GpPath
*path
)
970 return InvalidParameter
;
972 path
->newfigure
= TRUE
;
977 GpStatus WINGDIPAPI
GdipResetPath(GpPath
*path
)
980 return InvalidParameter
;
982 path
->pathdata
.Count
= 0;
983 path
->newfigure
= TRUE
;
984 path
->fill
= FillModeAlternate
;
989 GpStatus WINGDIPAPI
GdipSetPathFillMode(GpPath
*path
, GpFillMode fill
)
992 return InvalidParameter
;
999 GpStatus WINGDIPAPI
GdipTransformPath(GpPath
*path
, GpMatrix
*matrix
)
1002 return InvalidParameter
;
1004 if(path
->pathdata
.Count
== 0)
1007 return GdipTransformMatrixPoints(matrix
, path
->pathdata
.Points
,
1008 path
->pathdata
.Count
);
1011 GpStatus WINGDIPAPI
GdipAddPathRectangle(GpPath
*path
, REAL x
, REAL y
,
1012 REAL width
, REAL height
)
1019 if(!path
|| width
< 0.0 || height
< 0.0)
1020 return InvalidParameter
;
1022 /* make a backup copy of path data */
1023 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
1026 /* rectangle should start as new path */
1027 old_new
= path
->newfigure
;
1028 path
->newfigure
= TRUE
;
1029 if((retstat
= GdipAddPathLine(path
,x
,y
,x
+width
,y
)) != Ok
){
1030 path
->newfigure
= old_new
;
1035 ptf
[0].Y
= y
+height
;
1037 ptf
[1].Y
= y
+height
;
1039 if((retstat
= GdipAddPathLine2(path
, ptf
, 2)) != Ok
) goto fail
;
1040 path
->pathdata
.Types
[path
->pathdata
.Count
-1] |= PathPointTypeCloseSubpath
;
1043 GdipDeletePath(backup
);
1048 GdipDeletePath(path
);
1049 GdipClonePath(backup
, &path
);
1050 GdipDeletePath(backup
);
1055 GpStatus WINGDIPAPI
GdipAddPathRectangleI(GpPath
*path
, INT x
, INT y
,
1056 INT width
, INT height
)
1058 return GdipAddPathRectangle(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1061 GpStatus WINGDIPAPI
GdipAddPathRectangles(GpPath
*path
, GDIPCONST GpRectF
*rects
, INT count
)
1067 /* count == 0 - verified condition */
1068 if(!path
|| !rects
|| count
== 0)
1069 return InvalidParameter
;
1074 /* make a backup copy */
1075 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
1078 for(i
= 0; i
< count
; i
++){
1079 if((retstat
= GdipAddPathRectangle(path
,rects
[i
].X
,rects
[i
].Y
,rects
[i
].Width
,rects
[i
].Height
)) != Ok
)
1084 GdipDeletePath(backup
);
1089 GdipDeletePath(path
);
1090 GdipClonePath(backup
, &path
);
1091 GdipDeletePath(backup
);
1096 GpStatus WINGDIPAPI
GdipAddPathRectanglesI(GpPath
*path
, GDIPCONST GpRect
*rects
, INT count
)
1102 if(!rects
|| count
== 0)
1103 return InvalidParameter
;
1108 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
1110 for(i
= 0;i
< count
;i
++){
1111 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
1112 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
1113 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
1114 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
1117 retstat
= GdipAddPathRectangles(path
, rectsF
, count
);
1123 GpStatus WINGDIPAPI
GdipSetPathMarker(GpPath
* path
)
1128 return InvalidParameter
;
1130 count
= path
->pathdata
.Count
;
1132 /* set marker flag */
1134 path
->pathdata
.Types
[count
-1] |= PathPointTypePathMarker
;
1139 GpStatus WINGDIPAPI
GdipClearPathMarkers(GpPath
* path
)
1145 return InvalidParameter
;
1147 count
= path
->pathdata
.Count
;
1149 for(i
= 0; i
< count
- 1; i
++){
1150 path
->pathdata
.Types
[i
] &= ~PathPointTypePathMarker
;