- Sync gdiplus with wine head
[reactos.git] / reactos / dll / win32 / gdiplus / graphicspath.c
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
3 *
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.
8 *
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.
13 *
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
17 *
18 */
19
20 #include <stdarg.h>
21 #include <math.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27
28 #include "objbase.h"
29
30 #include "gdiplus.h"
31 #include "gdiplus_private.h"
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
35
36 typedef struct path_list_node_t path_list_node_t;
37 struct path_list_node_t {
38 GpPointF pt;
39 BYTE type; /* PathPointTypeStart or PathPointTypeLine */
40 path_list_node_t *next;
41 };
42
43 /* init list */
44 static BOOL init_path_list(path_list_node_t **node, REAL x, REAL y)
45 {
46 *node = GdipAlloc(sizeof(path_list_node_t));
47 if(!*node)
48 return FALSE;
49
50 (*node)->pt.X = x;
51 (*node)->pt.Y = y;
52 (*node)->type = PathPointTypeStart;
53 (*node)->next = NULL;
54
55 return TRUE;
56 }
57
58 /* free all nodes including argument */
59 static void free_path_list(path_list_node_t *node)
60 {
61 path_list_node_t *n = node;
62
63 while(n){
64 n = n->next;
65 GdipFree(node);
66 node = n;
67 }
68 }
69
70 /* Add a node after 'node' */
71 /*
72 * Returns
73 * pointer on success
74 * NULL on allocation problems
75 */
76 static path_list_node_t* add_path_list_node(path_list_node_t *node, REAL x, REAL y, BOOL type)
77 {
78 path_list_node_t *new;
79
80 new = GdipAlloc(sizeof(path_list_node_t));
81 if(!new)
82 return NULL;
83
84 new->pt.X = x;
85 new->pt.Y = y;
86 new->type = type;
87 new->next = node->next;
88 node->next = new;
89
90 return new;
91 }
92
93 /* returns element count */
94 static INT path_list_count(path_list_node_t *node)
95 {
96 INT count = 1;
97
98 while((node = node->next))
99 ++count;
100
101 return count;
102 }
103
104 /* GdipFlattenPath helper */
105 /*
106 * Used to recursively flatten single Bezier curve
107 * Parameters:
108 * - start : pointer to start point node;
109 * - (x2, y2): first control point;
110 * - (x3, y3): second control point;
111 * - end : pointer to end point node
112 * - flatness: admissible error of linear approximation.
113 *
114 * Return value:
115 * TRUE : success
116 * FALSE: out of memory
117 *
118 * TODO: used quality criteria should be revised to match native as
119 * closer as possible.
120 */
121 static BOOL flatten_bezier(path_list_node_t *start, REAL x2, REAL y2, REAL x3, REAL y3,
122 path_list_node_t *end, REAL flatness)
123 {
124 /* this 5 middle points with start/end define to half-curves */
125 GpPointF mp[5];
126 GpPointF pt, pt_st;
127 path_list_node_t *node;
128
129 /* calculate bezier curve middle points == new control points */
130 mp[0].X = (start->pt.X + x2) / 2.0;
131 mp[0].Y = (start->pt.Y + y2) / 2.0;
132 /* middle point between control points */
133 pt.X = (x2 + x3) / 2.0;
134 pt.Y = (y2 + y3) / 2.0;
135 mp[1].X = (mp[0].X + pt.X) / 2.0;
136 mp[1].Y = (mp[0].Y + pt.Y) / 2.0;
137 mp[4].X = (end->pt.X + x3) / 2.0;
138 mp[4].Y = (end->pt.Y + y3) / 2.0;
139 mp[3].X = (mp[4].X + pt.X) / 2.0;
140 mp[3].Y = (mp[4].Y + pt.Y) / 2.0;
141
142 mp[2].X = (mp[1].X + mp[3].X) / 2.0;
143 mp[2].Y = (mp[1].Y + mp[3].Y) / 2.0;
144
145 pt = end->pt;
146 pt_st = start->pt;
147 /* check flatness as a half of distance between middle point and a linearized path */
148 if(fabs(((pt.Y - pt_st.Y)*mp[2].X + (pt_st.X - pt.X)*mp[2].Y +
149 (pt_st.Y*pt.X - pt_st.X*pt.Y))) <=
150 (0.5 * flatness*sqrt((powf(pt.Y - pt_st.Y, 2.0) + powf(pt_st.X - pt.X, 2.0))))){
151 return TRUE;
152 }
153 else
154 /* add a middle point */
155 if(!(node = add_path_list_node(start, mp[2].X, mp[2].Y, PathPointTypeLine)))
156 return FALSE;
157
158 /* do the same with halfs */
159 flatten_bezier(start, mp[0].X, mp[0].Y, mp[1].X, mp[1].Y, node, flatness);
160 flatten_bezier(node, mp[3].X, mp[3].Y, mp[4].X, mp[4].Y, end, flatness);
161
162 return TRUE;
163 }
164
165 GpStatus WINGDIPAPI GdipAddPathArc(GpPath *path, REAL x1, REAL y1, REAL x2,
166 REAL y2, REAL startAngle, REAL sweepAngle)
167 {
168 INT count, old_count, i;
169
170 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
171 path, x1, y1, x2, y2, startAngle, sweepAngle);
172
173 if(!path)
174 return InvalidParameter;
175
176 count = arc2polybezier(NULL, x1, y1, x2, y2, startAngle, sweepAngle);
177
178 if(count == 0)
179 return Ok;
180 if(!lengthen_path(path, count))
181 return OutOfMemory;
182
183 old_count = path->pathdata.Count;
184 arc2polybezier(&path->pathdata.Points[old_count], x1, y1, x2, y2,
185 startAngle, sweepAngle);
186
187 for(i = 0; i < count; i++){
188 path->pathdata.Types[old_count + i] = PathPointTypeBezier;
189 }
190
191 path->pathdata.Types[old_count] =
192 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
193 path->newfigure = FALSE;
194 path->pathdata.Count += count;
195
196 return Ok;
197 }
198
199 GpStatus WINGDIPAPI GdipAddPathArcI(GpPath *path, INT x1, INT y1, INT x2,
200 INT y2, REAL startAngle, REAL sweepAngle)
201 {
202 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
203 path, x1, y1, x2, y2, startAngle, sweepAngle);
204
205 return GdipAddPathArc(path,(REAL)x1,(REAL)y1,(REAL)x2,(REAL)y2,startAngle,sweepAngle);
206 }
207
208 GpStatus WINGDIPAPI GdipAddPathBezier(GpPath *path, REAL x1, REAL y1, REAL x2,
209 REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
210 {
211 INT old_count;
212
213 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
214 path, x1, y1, x2, y2, x3, y3, x4, y4);
215
216 if(!path)
217 return InvalidParameter;
218
219 if(!lengthen_path(path, 4))
220 return OutOfMemory;
221
222 old_count = path->pathdata.Count;
223
224 path->pathdata.Points[old_count].X = x1;
225 path->pathdata.Points[old_count].Y = y1;
226 path->pathdata.Points[old_count + 1].X = x2;
227 path->pathdata.Points[old_count + 1].Y = y2;
228 path->pathdata.Points[old_count + 2].X = x3;
229 path->pathdata.Points[old_count + 2].Y = y3;
230 path->pathdata.Points[old_count + 3].X = x4;
231 path->pathdata.Points[old_count + 3].Y = y4;
232
233 path->pathdata.Types[old_count] =
234 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
235 path->pathdata.Types[old_count + 1] = PathPointTypeBezier;
236 path->pathdata.Types[old_count + 2] = PathPointTypeBezier;
237 path->pathdata.Types[old_count + 3] = PathPointTypeBezier;
238
239 path->newfigure = FALSE;
240 path->pathdata.Count += 4;
241
242 return Ok;
243 }
244
245 GpStatus WINGDIPAPI GdipAddPathBezierI(GpPath *path, INT x1, INT y1, INT x2,
246 INT y2, INT x3, INT y3, INT x4, INT y4)
247 {
248 TRACE("(%p, %d, %d, %d, %d, %d, %d, %d, %d)\n",
249 path, x1, y1, x2, y2, x3, y3, x4, y4);
250
251 return GdipAddPathBezier(path,(REAL)x1,(REAL)y1,(REAL)x2,(REAL)y2,(REAL)x3,(REAL)y3,
252 (REAL)x4,(REAL)y4);
253 }
254
255 GpStatus WINGDIPAPI GdipAddPathBeziers(GpPath *path, GDIPCONST GpPointF *points,
256 INT count)
257 {
258 INT i, old_count;
259
260 TRACE("(%p, %p, %d)\n", path, points, count);
261
262 if(!path || !points || ((count - 1) % 3))
263 return InvalidParameter;
264
265 if(!lengthen_path(path, count))
266 return OutOfMemory;
267
268 old_count = path->pathdata.Count;
269
270 for(i = 0; i < count; i++){
271 path->pathdata.Points[old_count + i].X = points[i].X;
272 path->pathdata.Points[old_count + i].Y = points[i].Y;
273 path->pathdata.Types[old_count + i] = PathPointTypeBezier;
274 }
275
276 path->pathdata.Types[old_count] =
277 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
278 path->newfigure = FALSE;
279 path->pathdata.Count += count;
280
281 return Ok;
282 }
283
284 GpStatus WINGDIPAPI GdipAddPathBeziersI(GpPath *path, GDIPCONST GpPoint *points,
285 INT count)
286 {
287 GpPointF *ptsF;
288 GpStatus ret;
289 INT i;
290
291 TRACE("(%p, %p, %d)\n", path, points, count);
292
293 if(!points || ((count - 1) % 3))
294 return InvalidParameter;
295
296 ptsF = GdipAlloc(sizeof(GpPointF) * count);
297 if(!ptsF)
298 return OutOfMemory;
299
300 for(i = 0; i < count; i++){
301 ptsF[i].X = (REAL)points[i].X;
302 ptsF[i].Y = (REAL)points[i].Y;
303 }
304
305 ret = GdipAddPathBeziers(path, ptsF, count);
306 GdipFree(ptsF);
307
308 return ret;
309 }
310
311 GpStatus WINGDIPAPI GdipAddPathClosedCurve(GpPath *path, GDIPCONST GpPointF *points,
312 INT count)
313 {
314 TRACE("(%p, %p, %d)\n", path, points, count);
315
316 return GdipAddPathClosedCurve2(path, points, count, 1.0);
317 }
318
319 GpStatus WINGDIPAPI GdipAddPathClosedCurveI(GpPath *path, GDIPCONST GpPoint *points,
320 INT count)
321 {
322 TRACE("(%p, %p, %d)\n", path, points, count);
323
324 return GdipAddPathClosedCurve2I(path, points, count, 1.0);
325 }
326
327 GpStatus WINGDIPAPI GdipAddPathClosedCurve2(GpPath *path, GDIPCONST GpPointF *points,
328 INT count, REAL tension)
329 {
330 INT i, len_pt = (count + 1)*3-2;
331 GpPointF *pt;
332 GpPointF *pts;
333 REAL x1, x2, y1, y2;
334 GpStatus stat;
335
336 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
337
338 if(!path || !points || count <= 1)
339 return InvalidParameter;
340
341 pt = GdipAlloc(len_pt * sizeof(GpPointF));
342 pts = GdipAlloc((count + 1)*sizeof(GpPointF));
343 if(!pt || !pts){
344 GdipFree(pt);
345 GdipFree(pts);
346 return OutOfMemory;
347 }
348
349 /* copy source points to extend with the last one */
350 memcpy(pts, points, sizeof(GpPointF)*count);
351 pts[count] = pts[0];
352
353 tension = tension * TENSION_CONST;
354
355 for(i = 0; i < count-1; i++){
356 calc_curve_bezier(&(pts[i]), tension, &x1, &y1, &x2, &y2);
357
358 pt[3*i+2].X = x1;
359 pt[3*i+2].Y = y1;
360 pt[3*i+3].X = pts[i+1].X;
361 pt[3*i+3].Y = pts[i+1].Y;
362 pt[3*i+4].X = x2;
363 pt[3*i+4].Y = y2;
364 }
365
366 /* points [len_pt-2] and [0] are calculated
367 separetely to connect splines properly */
368 pts[0] = points[count-1];
369 pts[1] = points[0]; /* equals to start and end of a resulting path */
370 pts[2] = points[1];
371
372 calc_curve_bezier(pts, tension, &x1, &y1, &x2, &y2);
373 pt[len_pt-2].X = x1;
374 pt[len_pt-2].Y = y1;
375 pt[0].X = pts[1].X;
376 pt[0].Y = pts[1].Y;
377 pt[1].X = x2;
378 pt[1].Y = y2;
379 /* close path */
380 pt[len_pt-1].X = pt[0].X;
381 pt[len_pt-1].Y = pt[0].Y;
382
383 stat = GdipAddPathBeziers(path, pt, len_pt);
384
385 /* close figure */
386 if(stat == Ok){
387 INT count = path->pathdata.Count;
388 path->pathdata.Types[count - 1] |= PathPointTypeCloseSubpath;
389 path->newfigure = TRUE;
390 }
391
392 GdipFree(pts);
393 GdipFree(pt);
394
395 return stat;
396 }
397
398 GpStatus WINGDIPAPI GdipAddPathClosedCurve2I(GpPath *path, GDIPCONST GpPoint *points,
399 INT count, REAL tension)
400 {
401 GpPointF *ptf;
402 INT i;
403 GpStatus stat;
404
405 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
406
407 if(!path || !points || count <= 1)
408 return InvalidParameter;
409
410 ptf = GdipAlloc(sizeof(GpPointF)*count);
411 if(!ptf)
412 return OutOfMemory;
413
414 for(i = 0; i < count; i++){
415 ptf[i].X = (REAL)points[i].X;
416 ptf[i].Y = (REAL)points[i].Y;
417 }
418
419 stat = GdipAddPathClosedCurve2(path, ptf, count, tension);
420
421 GdipFree(ptf);
422
423 return stat;
424 }
425
426 GpStatus WINGDIPAPI GdipAddPathCurve(GpPath *path, GDIPCONST GpPointF *points, INT count)
427 {
428 TRACE("(%p, %p, %d)\n", path, points, count);
429
430 if(!path || !points || count <= 1)
431 return InvalidParameter;
432
433 return GdipAddPathCurve2(path, points, count, 1.0);
434 }
435
436 GpStatus WINGDIPAPI GdipAddPathCurveI(GpPath *path, GDIPCONST GpPoint *points, INT count)
437 {
438 TRACE("(%p, %p, %d)\n", path, points, count);
439
440 if(!path || !points || count <= 1)
441 return InvalidParameter;
442
443 return GdipAddPathCurve2I(path, points, count, 1.0);
444 }
445
446 GpStatus WINGDIPAPI GdipAddPathCurve2(GpPath *path, GDIPCONST GpPointF *points, INT count,
447 REAL tension)
448 {
449 INT i, len_pt = count*3-2;
450 GpPointF *pt;
451 REAL x1, x2, y1, y2;
452 GpStatus stat;
453
454 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
455
456 if(!path || !points || count <= 1)
457 return InvalidParameter;
458
459 pt = GdipAlloc(len_pt * sizeof(GpPointF));
460 if(!pt)
461 return OutOfMemory;
462
463 tension = tension * TENSION_CONST;
464
465 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
466 tension, &x1, &y1);
467
468 pt[0].X = points[0].X;
469 pt[0].Y = points[0].Y;
470 pt[1].X = x1;
471 pt[1].Y = y1;
472
473 for(i = 0; i < count-2; i++){
474 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
475
476 pt[3*i+2].X = x1;
477 pt[3*i+2].Y = y1;
478 pt[3*i+3].X = points[i+1].X;
479 pt[3*i+3].Y = points[i+1].Y;
480 pt[3*i+4].X = x2;
481 pt[3*i+4].Y = y2;
482 }
483
484 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
485 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
486
487 pt[len_pt-2].X = x1;
488 pt[len_pt-2].Y = y1;
489 pt[len_pt-1].X = points[count-1].X;
490 pt[len_pt-1].Y = points[count-1].Y;
491
492 stat = GdipAddPathBeziers(path, pt, len_pt);
493
494 GdipFree(pt);
495
496 return stat;
497 }
498
499 GpStatus WINGDIPAPI GdipAddPathCurve2I(GpPath *path, GDIPCONST GpPoint *points,
500 INT count, REAL tension)
501 {
502 GpPointF *ptf;
503 INT i;
504 GpStatus stat;
505
506 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
507
508 if(!path || !points || count <= 1)
509 return InvalidParameter;
510
511 ptf = GdipAlloc(sizeof(GpPointF)*count);
512 if(!ptf)
513 return OutOfMemory;
514
515 for(i = 0; i < count; i++){
516 ptf[i].X = (REAL)points[i].X;
517 ptf[i].Y = (REAL)points[i].Y;
518 }
519
520 stat = GdipAddPathCurve2(path, ptf, count, tension);
521
522 GdipFree(ptf);
523
524 return stat;
525 }
526
527 GpStatus WINGDIPAPI GdipAddPathEllipse(GpPath *path, REAL x, REAL y, REAL width,
528 REAL height)
529 {
530 INT old_count, numpts;
531
532 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x, y, width, height);
533
534 if(!path)
535 return InvalidParameter;
536
537 if(!lengthen_path(path, MAX_ARC_PTS))
538 return OutOfMemory;
539
540 old_count = path->pathdata.Count;
541 if((numpts = arc2polybezier(&path->pathdata.Points[old_count], x, y, width,
542 height, 0.0, 360.0)) != MAX_ARC_PTS){
543 ERR("expected %d points but got %d\n", MAX_ARC_PTS, numpts);
544 return GenericError;
545 }
546
547 memset(&path->pathdata.Types[old_count + 1], PathPointTypeBezier,
548 MAX_ARC_PTS - 1);
549
550 /* An ellipse is an intrinsic figure (always is its own subpath). */
551 path->pathdata.Types[old_count] = PathPointTypeStart;
552 path->pathdata.Types[old_count + MAX_ARC_PTS - 1] |= PathPointTypeCloseSubpath;
553 path->newfigure = TRUE;
554 path->pathdata.Count += MAX_ARC_PTS;
555
556 return Ok;
557 }
558
559 GpStatus WINGDIPAPI GdipAddPathEllipseI(GpPath *path, INT x, INT y, INT width,
560 INT height)
561 {
562 TRACE("(%p, %d, %d, %d, %d)\n", path, x, y, width, height);
563
564 return GdipAddPathEllipse(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
565 }
566
567 GpStatus WINGDIPAPI GdipAddPathLine2(GpPath *path, GDIPCONST GpPointF *points,
568 INT count)
569 {
570 INT i, old_count;
571
572 TRACE("(%p, %p, %d)\n", path, points, count);
573
574 if(!path || !points)
575 return InvalidParameter;
576
577 if(!lengthen_path(path, count))
578 return OutOfMemory;
579
580 old_count = path->pathdata.Count;
581
582 for(i = 0; i < count; i++){
583 path->pathdata.Points[old_count + i].X = points[i].X;
584 path->pathdata.Points[old_count + i].Y = points[i].Y;
585 path->pathdata.Types[old_count + i] = PathPointTypeLine;
586 }
587
588 if(path->newfigure){
589 path->pathdata.Types[old_count] = PathPointTypeStart;
590 path->newfigure = FALSE;
591 }
592
593 path->pathdata.Count += count;
594
595 return Ok;
596 }
597
598 GpStatus WINGDIPAPI GdipAddPathLine2I(GpPath *path, GDIPCONST GpPoint *points, INT count)
599 {
600 GpPointF *pointsF;
601 INT i;
602 GpStatus stat;
603
604 TRACE("(%p, %p, %d)\n", path, points, count);
605
606 if(count <= 0)
607 return InvalidParameter;
608
609 pointsF = GdipAlloc(sizeof(GpPointF) * count);
610 if(!pointsF) return OutOfMemory;
611
612 for(i = 0;i < count; i++){
613 pointsF[i].X = (REAL)points[i].X;
614 pointsF[i].Y = (REAL)points[i].Y;
615 }
616
617 stat = GdipAddPathLine2(path, pointsF, count);
618
619 GdipFree(pointsF);
620
621 return stat;
622 }
623
624 GpStatus WINGDIPAPI GdipAddPathLine(GpPath *path, REAL x1, REAL y1, REAL x2, REAL y2)
625 {
626 INT old_count;
627
628 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x1, y1, x2, y2);
629
630 if(!path)
631 return InvalidParameter;
632
633 if(!lengthen_path(path, 2))
634 return OutOfMemory;
635
636 old_count = path->pathdata.Count;
637
638 path->pathdata.Points[old_count].X = x1;
639 path->pathdata.Points[old_count].Y = y1;
640 path->pathdata.Points[old_count + 1].X = x2;
641 path->pathdata.Points[old_count + 1].Y = y2;
642
643 path->pathdata.Types[old_count] =
644 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
645 path->pathdata.Types[old_count + 1] = PathPointTypeLine;
646
647 path->newfigure = FALSE;
648 path->pathdata.Count += 2;
649
650 return Ok;
651 }
652
653 GpStatus WINGDIPAPI GdipAddPathLineI(GpPath *path, INT x1, INT y1, INT x2, INT y2)
654 {
655 TRACE("(%p, %d, %d, %d, %d)\n", path, x1, y1, x2, y2);
656
657 return GdipAddPathLine(path, (REAL)x1, (REAL)y1, (REAL)x2, (REAL)y2);
658 }
659
660 GpStatus WINGDIPAPI GdipAddPathPath(GpPath *path, GDIPCONST GpPath* addingPath,
661 BOOL connect)
662 {
663 INT old_count, count;
664
665 TRACE("(%p, %p, %d)\n", path, addingPath, connect);
666
667 if(!path || !addingPath)
668 return InvalidParameter;
669
670 old_count = path->pathdata.Count;
671 count = addingPath->pathdata.Count;
672
673 if(!lengthen_path(path, count))
674 return OutOfMemory;
675
676 memcpy(&path->pathdata.Points[old_count], addingPath->pathdata.Points,
677 count * sizeof(GpPointF));
678 memcpy(&path->pathdata.Types[old_count], addingPath->pathdata.Types, count);
679
680 if(path->newfigure || !connect)
681 path->pathdata.Types[old_count] = PathPointTypeStart;
682 else
683 path->pathdata.Types[old_count] = PathPointTypeLine;
684
685 path->newfigure = FALSE;
686 path->pathdata.Count += count;
687
688 return Ok;
689 }
690
691 GpStatus WINGDIPAPI GdipAddPathPie(GpPath *path, REAL x, REAL y, REAL width, REAL height,
692 REAL startAngle, REAL sweepAngle)
693 {
694 GpPointF *ptf;
695 GpStatus status;
696 INT i, count;
697
698 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
699 path, x, y, width, height, startAngle, sweepAngle);
700
701 if(!path)
702 return InvalidParameter;
703
704 count = arc2polybezier(NULL, x, y, width, height, startAngle, sweepAngle);
705
706 if(count == 0)
707 return Ok;
708
709 ptf = GdipAlloc(sizeof(GpPointF)*count);
710 if(!ptf)
711 return OutOfMemory;
712
713 arc2polybezier(ptf, x, y, width, height, startAngle, sweepAngle);
714
715 status = GdipAddPathLine(path, (width - x)/2, (height - y)/2, ptf[0].X, ptf[0].Y);
716 if(status != Ok){
717 GdipFree(ptf);
718 return status;
719 }
720 /* one spline is already added as a line endpoint */
721 if(!lengthen_path(path, count - 1)){
722 GdipFree(ptf);
723 return OutOfMemory;
724 }
725
726 memcpy(&(path->pathdata.Points[path->pathdata.Count]), &(ptf[1]),sizeof(GpPointF)*(count-1));
727 for(i = 0; i < count-1; i++)
728 path->pathdata.Types[path->pathdata.Count+i] = PathPointTypeBezier;
729
730 path->pathdata.Count += count-1;
731
732 GdipClosePathFigure(path);
733
734 GdipFree(ptf);
735
736 return status;
737 }
738
739 GpStatus WINGDIPAPI GdipAddPathPieI(GpPath *path, INT x, INT y, INT width, INT height,
740 REAL startAngle, REAL sweepAngle)
741 {
742 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
743 path, x, y, width, height, startAngle, sweepAngle);
744
745 return GdipAddPathPieI(path, (REAL)x, (REAL)y, (REAL)width, (REAL)height, startAngle, sweepAngle);
746 }
747
748 GpStatus WINGDIPAPI GdipAddPathPolygon(GpPath *path, GDIPCONST GpPointF *points, INT count)
749 {
750 INT old_count;
751
752 TRACE("(%p, %p, %d)\n", path, points, count);
753
754 if(!path || !points || count < 3)
755 return InvalidParameter;
756
757 if(!lengthen_path(path, count))
758 return OutOfMemory;
759
760 old_count = path->pathdata.Count;
761
762 memcpy(&path->pathdata.Points[old_count], points, count*sizeof(GpPointF));
763 memset(&path->pathdata.Types[old_count + 1], PathPointTypeLine, count - 1);
764
765 /* A polygon is an intrinsic figure */
766 path->pathdata.Types[old_count] = PathPointTypeStart;
767 path->pathdata.Types[old_count + count - 1] |= PathPointTypeCloseSubpath;
768 path->newfigure = TRUE;
769 path->pathdata.Count += count;
770
771 return Ok;
772 }
773
774 GpStatus WINGDIPAPI GdipAddPathPolygonI(GpPath *path, GDIPCONST GpPoint *points, INT count)
775 {
776 GpPointF *ptf;
777 GpStatus status;
778 INT i;
779
780 TRACE("(%p, %p, %d)\n", path, points, count);
781
782 if(!points || count < 3)
783 return InvalidParameter;
784
785 ptf = GdipAlloc(sizeof(GpPointF) * count);
786 if(!ptf)
787 return OutOfMemory;
788
789 for(i = 0; i < count; i++){
790 ptf[i].X = (REAL)points[i].X;
791 ptf[i].Y = (REAL)points[i].Y;
792 }
793
794 status = GdipAddPathPolygon(path, ptf, count);
795
796 GdipFree(ptf);
797
798 return status;
799 }
800
801 GpStatus WINGDIPAPI GdipClonePath(GpPath* path, GpPath **clone)
802 {
803 TRACE("(%p, %p)\n", path, clone);
804
805 if(!path || !clone)
806 return InvalidParameter;
807
808 *clone = GdipAlloc(sizeof(GpPath));
809 if(!*clone) return OutOfMemory;
810
811 **clone = *path;
812
813 (*clone)->pathdata.Points = GdipAlloc(path->datalen * sizeof(PointF));
814 (*clone)->pathdata.Types = GdipAlloc(path->datalen);
815 if(!(*clone)->pathdata.Points || !(*clone)->pathdata.Types){
816 GdipFree(*clone);
817 GdipFree((*clone)->pathdata.Points);
818 GdipFree((*clone)->pathdata.Types);
819 return OutOfMemory;
820 }
821
822 memcpy((*clone)->pathdata.Points, path->pathdata.Points,
823 path->datalen * sizeof(PointF));
824 memcpy((*clone)->pathdata.Types, path->pathdata.Types, path->datalen);
825
826 return Ok;
827 }
828
829 GpStatus WINGDIPAPI GdipClosePathFigure(GpPath* path)
830 {
831 TRACE("(%p)\n", path);
832
833 if(!path)
834 return InvalidParameter;
835
836 if(path->pathdata.Count > 0){
837 path->pathdata.Types[path->pathdata.Count - 1] |= PathPointTypeCloseSubpath;
838 path->newfigure = TRUE;
839 }
840
841 return Ok;
842 }
843
844 GpStatus WINGDIPAPI GdipClosePathFigures(GpPath* path)
845 {
846 INT i;
847
848 TRACE("(%p)\n", path);
849
850 if(!path)
851 return InvalidParameter;
852
853 for(i = 1; i < path->pathdata.Count; i++){
854 if(path->pathdata.Types[i] == PathPointTypeStart)
855 path->pathdata.Types[i-1] |= PathPointTypeCloseSubpath;
856 }
857
858 path->newfigure = TRUE;
859
860 return Ok;
861 }
862
863 GpStatus WINGDIPAPI GdipCreatePath(GpFillMode fill, GpPath **path)
864 {
865 TRACE("(%d, %p)\n", fill, path);
866
867 if(!path)
868 return InvalidParameter;
869
870 *path = GdipAlloc(sizeof(GpPath));
871 if(!*path) return OutOfMemory;
872
873 (*path)->fill = fill;
874 (*path)->newfigure = TRUE;
875
876 return Ok;
877 }
878
879 GpStatus WINGDIPAPI GdipCreatePath2(GDIPCONST GpPointF* points,
880 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
881 {
882 TRACE("(%p, %p, %d, %d, %p)\n", points, types, count, fill, path);
883
884 if(!path)
885 return InvalidParameter;
886
887 *path = GdipAlloc(sizeof(GpPath));
888 if(!*path) return OutOfMemory;
889
890 (*path)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
891 (*path)->pathdata.Types = GdipAlloc(count);
892
893 if(!(*path)->pathdata.Points || !(*path)->pathdata.Types){
894 GdipFree((*path)->pathdata.Points);
895 GdipFree((*path)->pathdata.Types);
896 GdipFree(*path);
897 return OutOfMemory;
898 }
899
900 memcpy((*path)->pathdata.Points, points, count * sizeof(PointF));
901 memcpy((*path)->pathdata.Types, types, count);
902 (*path)->pathdata.Count = count;
903 (*path)->datalen = count;
904
905 (*path)->fill = fill;
906 (*path)->newfigure = TRUE;
907
908 return Ok;
909 }
910
911 GpStatus WINGDIPAPI GdipCreatePath2I(GDIPCONST GpPoint* points,
912 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
913 {
914 GpPointF *ptF;
915 GpStatus ret;
916 INT i;
917
918 TRACE("(%p, %p, %d, %d, %p)\n", points, types, count, fill, path);
919
920 ptF = GdipAlloc(sizeof(GpPointF)*count);
921
922 for(i = 0;i < count; i++){
923 ptF[i].X = (REAL)points[i].X;
924 ptF[i].Y = (REAL)points[i].Y;
925 }
926
927 ret = GdipCreatePath2(ptF, types, count, fill, path);
928
929 GdipFree(ptF);
930
931 return ret;
932 }
933
934 GpStatus WINGDIPAPI GdipDeletePath(GpPath *path)
935 {
936 TRACE("(%p)\n", path);
937
938 if(!path)
939 return InvalidParameter;
940
941 GdipFree(path->pathdata.Points);
942 GdipFree(path->pathdata.Types);
943 GdipFree(path);
944
945 return Ok;
946 }
947
948 GpStatus WINGDIPAPI GdipFlattenPath(GpPath *path, GpMatrix* matrix, REAL flatness)
949 {
950 path_list_node_t *list, *node;
951 GpPointF pt;
952 INT i = 1;
953 INT startidx = 0;
954
955 TRACE("(%p, %p, %.2f)\n", path, matrix, flatness);
956
957 if(!path)
958 return InvalidParameter;
959
960 if(matrix){
961 WARN("transformation not supported yet!\n");
962 return NotImplemented;
963 }
964
965 if(path->pathdata.Count == 0)
966 return Ok;
967
968 pt = path->pathdata.Points[0];
969 if(!init_path_list(&list, pt.X, pt.Y))
970 return OutOfMemory;
971
972 node = list;
973
974 while(i < path->pathdata.Count){
975
976 BYTE type = path->pathdata.Types[i] & PathPointTypePathTypeMask;
977 path_list_node_t *start;
978
979 pt = path->pathdata.Points[i];
980
981 /* save last start point index */
982 if(type == PathPointTypeStart)
983 startidx = i;
984
985 /* always add line points and start points */
986 if((type == PathPointTypeStart) || (type == PathPointTypeLine)){
987 type = (path->pathdata.Types[i] & ~PathPointTypeBezier) | PathPointTypeLine;
988 if(!add_path_list_node(node, pt.X, pt.Y, type))
989 goto memout;
990
991 node = node->next;
992 continue;
993 }
994
995 /* Bezier curve always stored as 4 points */
996 if((path->pathdata.Types[i-1] & PathPointTypePathTypeMask) != PathPointTypeStart){
997 type = (path->pathdata.Types[i] & ~PathPointTypeBezier) | PathPointTypeLine;
998 if(!add_path_list_node(node, pt.X, pt.Y, type))
999 goto memout;
1000
1001 node = node->next;
1002 }
1003
1004 /* test for closed figure */
1005 if(path->pathdata.Types[i+1] & PathPointTypeCloseSubpath){
1006 pt = path->pathdata.Points[startidx];
1007 ++i;
1008 }
1009 else
1010 {
1011 i += 2;
1012 pt = path->pathdata.Points[i];
1013 };
1014
1015 start = node;
1016 /* add Bezier end point */
1017 type = (path->pathdata.Types[i] & ~PathPointTypeBezier) | PathPointTypeLine;
1018 if(!add_path_list_node(node, pt.X, pt.Y, type))
1019 goto memout;
1020 node = node->next;
1021
1022 /* flatten curve */
1023 if(!flatten_bezier(start, path->pathdata.Points[i-2].X, path->pathdata.Points[i-2].Y,
1024 path->pathdata.Points[i-1].X, path->pathdata.Points[i-1].Y,
1025 node, flatness))
1026 goto memout;
1027
1028 ++i;
1029 }/* while */
1030
1031 /* store path data back */
1032 i = path_list_count(list);
1033 if(!lengthen_path(path, i))
1034 goto memout;
1035 path->pathdata.Count = i;
1036
1037 node = list;
1038 for(i = 0; i < path->pathdata.Count; i++){
1039 path->pathdata.Points[i] = node->pt;
1040 path->pathdata.Types[i] = node->type;
1041 node = node->next;
1042 }
1043
1044 free_path_list(list);
1045 return Ok;
1046
1047 memout:
1048 free_path_list(list);
1049 return OutOfMemory;
1050 }
1051
1052 GpStatus WINGDIPAPI GdipGetPathData(GpPath *path, GpPathData* pathData)
1053 {
1054 TRACE("(%p, %p)\n", path, pathData);
1055
1056 if(!path || !pathData)
1057 return InvalidParameter;
1058
1059 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
1060 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
1061 memcpy(pathData->Points, path->pathdata.Points, sizeof(PointF) * pathData->Count);
1062 memcpy(pathData->Types , path->pathdata.Types , pathData->Count);
1063
1064 return Ok;
1065 }
1066
1067 GpStatus WINGDIPAPI GdipGetPathFillMode(GpPath *path, GpFillMode *fillmode)
1068 {
1069 TRACE("(%p, %p)\n", path, fillmode);
1070
1071 if(!path || !fillmode)
1072 return InvalidParameter;
1073
1074 *fillmode = path->fill;
1075
1076 return Ok;
1077 }
1078
1079 GpStatus WINGDIPAPI GdipGetPathLastPoint(GpPath* path, GpPointF* lastPoint)
1080 {
1081 INT count;
1082
1083 TRACE("(%p, %p)\n", path, lastPoint);
1084
1085 if(!path || !lastPoint)
1086 return InvalidParameter;
1087
1088 count = path->pathdata.Count;
1089 if(count > 0)
1090 *lastPoint = path->pathdata.Points[count-1];
1091
1092 return Ok;
1093 }
1094
1095 GpStatus WINGDIPAPI GdipGetPathPoints(GpPath *path, GpPointF* points, INT count)
1096 {
1097 TRACE("(%p, %p, %d)\n", path, points, count);
1098
1099 if(!path)
1100 return InvalidParameter;
1101
1102 if(count < path->pathdata.Count)
1103 return InsufficientBuffer;
1104
1105 memcpy(points, path->pathdata.Points, path->pathdata.Count * sizeof(GpPointF));
1106
1107 return Ok;
1108 }
1109
1110 GpStatus WINGDIPAPI GdipGetPathPointsI(GpPath *path, GpPoint* points, INT count)
1111 {
1112 GpStatus ret;
1113 GpPointF *ptf;
1114 INT i;
1115
1116 TRACE("(%p, %p, %d)\n", path, points, count);
1117
1118 if(count <= 0)
1119 return InvalidParameter;
1120
1121 ptf = GdipAlloc(sizeof(GpPointF)*count);
1122 if(!ptf) return OutOfMemory;
1123
1124 ret = GdipGetPathPoints(path,ptf,count);
1125 if(ret == Ok)
1126 for(i = 0;i < count;i++){
1127 points[i].X = roundr(ptf[i].X);
1128 points[i].Y = roundr(ptf[i].Y);
1129 };
1130 GdipFree(ptf);
1131
1132 return ret;
1133 }
1134
1135 GpStatus WINGDIPAPI GdipGetPathTypes(GpPath *path, BYTE* types, INT count)
1136 {
1137 TRACE("(%p, %p, %d)\n", path, types, count);
1138
1139 if(!path)
1140 return InvalidParameter;
1141
1142 if(count < path->pathdata.Count)
1143 return InsufficientBuffer;
1144
1145 memcpy(types, path->pathdata.Types, path->pathdata.Count);
1146
1147 return Ok;
1148 }
1149
1150 /* Windows expands the bounding box to the maximum possible bounding box
1151 * for a given pen. For example, if a line join can extend past the point
1152 * it's joining by x units, the bounding box is extended by x units in every
1153 * direction (even though this is too conservative for most cases). */
1154 GpStatus WINGDIPAPI GdipGetPathWorldBounds(GpPath* path, GpRectF* bounds,
1155 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
1156 {
1157 GpPointF * points, temp_pts[4];
1158 INT count, i;
1159 REAL path_width = 1.0, width, height, temp, low_x, low_y, high_x, high_y;
1160
1161 TRACE("(%p, %p, %p, %p)\n", path, bounds, matrix, pen);
1162
1163 /* Matrix and pen can be null. */
1164 if(!path || !bounds)
1165 return InvalidParameter;
1166
1167 /* If path is empty just return. */
1168 count = path->pathdata.Count;
1169 if(count == 0){
1170 bounds->X = bounds->Y = bounds->Width = bounds->Height = 0.0;
1171 return Ok;
1172 }
1173
1174 points = path->pathdata.Points;
1175
1176 low_x = high_x = points[0].X;
1177 low_y = high_y = points[0].Y;
1178
1179 for(i = 1; i < count; i++){
1180 low_x = min(low_x, points[i].X);
1181 low_y = min(low_y, points[i].Y);
1182 high_x = max(high_x, points[i].X);
1183 high_y = max(high_y, points[i].Y);
1184 }
1185
1186 width = high_x - low_x;
1187 height = high_y - low_y;
1188
1189 /* This looks unusual but it's the only way I can imitate windows. */
1190 if(matrix){
1191 temp_pts[0].X = low_x;
1192 temp_pts[0].Y = low_y;
1193 temp_pts[1].X = low_x;
1194 temp_pts[1].Y = high_y;
1195 temp_pts[2].X = high_x;
1196 temp_pts[2].Y = high_y;
1197 temp_pts[3].X = high_x;
1198 temp_pts[3].Y = low_y;
1199
1200 GdipTransformMatrixPoints((GpMatrix*)matrix, temp_pts, 4);
1201 low_x = temp_pts[0].X;
1202 low_y = temp_pts[0].Y;
1203
1204 for(i = 1; i < 4; i++){
1205 low_x = min(low_x, temp_pts[i].X);
1206 low_y = min(low_y, temp_pts[i].Y);
1207 }
1208
1209 temp = width;
1210 width = height * fabs(matrix->matrix[2]) + width * fabs(matrix->matrix[0]);
1211 height = height * fabs(matrix->matrix[3]) + temp * fabs(matrix->matrix[1]);
1212 }
1213
1214 if(pen){
1215 path_width = pen->width / 2.0;
1216
1217 if(count > 2)
1218 path_width = max(path_width, pen->width * pen->miterlimit / 2.0);
1219 /* FIXME: this should probably also check for the startcap */
1220 if(pen->endcap & LineCapNoAnchor)
1221 path_width = max(path_width, pen->width * 2.2);
1222
1223 low_x -= path_width;
1224 low_y -= path_width;
1225 width += 2.0 * path_width;
1226 height += 2.0 * path_width;
1227 }
1228
1229 bounds->X = low_x;
1230 bounds->Y = low_y;
1231 bounds->Width = width;
1232 bounds->Height = height;
1233
1234 return Ok;
1235 }
1236
1237 GpStatus WINGDIPAPI GdipGetPathWorldBoundsI(GpPath* path, GpRect* bounds,
1238 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
1239 {
1240 GpStatus ret;
1241 GpRectF boundsF;
1242
1243 TRACE("(%p, %p, %p, %p)\n", path, bounds, matrix, pen);
1244
1245 ret = GdipGetPathWorldBounds(path,&boundsF,matrix,pen);
1246
1247 if(ret == Ok){
1248 bounds->X = roundr(boundsF.X);
1249 bounds->Y = roundr(boundsF.Y);
1250 bounds->Width = roundr(boundsF.Width);
1251 bounds->Height = roundr(boundsF.Height);
1252 }
1253
1254 return ret;
1255 }
1256
1257 GpStatus WINGDIPAPI GdipGetPointCount(GpPath *path, INT *count)
1258 {
1259 TRACE("(%p, %p)\n", path, count);
1260
1261 if(!path)
1262 return InvalidParameter;
1263
1264 *count = path->pathdata.Count;
1265
1266 return Ok;
1267 }
1268
1269 GpStatus WINGDIPAPI GdipReversePath(GpPath* path)
1270 {
1271 INT i, count;
1272 INT start = 0; /* position in reversed path */
1273 GpPathData revpath;
1274
1275 TRACE("(%p)\n", path);
1276
1277 if(!path)
1278 return InvalidParameter;
1279
1280 count = path->pathdata.Count;
1281
1282 if(count == 0) return Ok;
1283
1284 revpath.Points = GdipAlloc(sizeof(GpPointF)*count);
1285 revpath.Types = GdipAlloc(sizeof(BYTE)*count);
1286 revpath.Count = count;
1287 if(!revpath.Points || !revpath.Types){
1288 GdipFree(revpath.Points);
1289 GdipFree(revpath.Types);
1290 return OutOfMemory;
1291 }
1292
1293 for(i = 0; i < count; i++){
1294
1295 /* find next start point */
1296 if(path->pathdata.Types[count-i-1] == PathPointTypeStart){
1297 INT j;
1298 for(j = start; j <= i; j++){
1299 revpath.Points[j] = path->pathdata.Points[count-j-1];
1300 revpath.Types[j] = path->pathdata.Types[count-j-1];
1301 }
1302 /* mark start point */
1303 revpath.Types[start] = PathPointTypeStart;
1304 /* set 'figure' endpoint type */
1305 if(i-start > 1){
1306 revpath.Types[i] = path->pathdata.Types[count-start-1] & ~PathPointTypePathTypeMask;
1307 revpath.Types[i] |= revpath.Types[i-1];
1308 }
1309 else
1310 revpath.Types[i] = path->pathdata.Types[start];
1311
1312 start = i+1;
1313 }
1314 }
1315
1316 memcpy(path->pathdata.Points, revpath.Points, sizeof(GpPointF)*count);
1317 memcpy(path->pathdata.Types, revpath.Types, sizeof(BYTE)*count);
1318
1319 GdipFree(revpath.Points);
1320 GdipFree(revpath.Types);
1321
1322 return Ok;
1323 }
1324
1325 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPointI(GpPath* path, INT x, INT y,
1326 GpPen *pen, GpGraphics *graphics, BOOL *result)
1327 {
1328 TRACE("(%p, %d, %d, %p, %p, %p)\n", path, x, y, pen, graphics, result);
1329
1330 return GdipIsOutlineVisiblePathPoint(path, x, y, pen, graphics, result);
1331 }
1332
1333 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPoint(GpPath* path, REAL x, REAL y,
1334 GpPen *pen, GpGraphics *graphics, BOOL *result)
1335 {
1336 static int calls;
1337
1338 if(!path || !pen)
1339 return InvalidParameter;
1340
1341 if(!(calls++))
1342 FIXME("not implemented\n");
1343
1344 return NotImplemented;
1345 }
1346
1347 GpStatus WINGDIPAPI GdipIsVisiblePathPointI(GpPath* path, INT x, INT y, GpGraphics *graphics, BOOL *result)
1348 {
1349 TRACE("(%p, %d, %d, %p, %p)\n", path, x, y, graphics, result);
1350
1351 return GdipIsVisiblePathPoint(path, x, y, graphics, result);
1352 }
1353
1354 GpStatus WINGDIPAPI GdipIsVisiblePathPoint(GpPath* path, REAL x, REAL y, GpGraphics *graphics, BOOL *result)
1355 {
1356 static int calls;
1357
1358 if(!path) return InvalidParameter;
1359
1360 if(!(calls++))
1361 FIXME("not implemented\n");
1362
1363 return NotImplemented;
1364 }
1365
1366 GpStatus WINGDIPAPI GdipStartPathFigure(GpPath *path)
1367 {
1368 TRACE("(%p)\n", path);
1369
1370 if(!path)
1371 return InvalidParameter;
1372
1373 path->newfigure = TRUE;
1374
1375 return Ok;
1376 }
1377
1378 GpStatus WINGDIPAPI GdipResetPath(GpPath *path)
1379 {
1380 TRACE("(%p)\n", path);
1381
1382 if(!path)
1383 return InvalidParameter;
1384
1385 path->pathdata.Count = 0;
1386 path->newfigure = TRUE;
1387 path->fill = FillModeAlternate;
1388
1389 return Ok;
1390 }
1391
1392 GpStatus WINGDIPAPI GdipSetPathFillMode(GpPath *path, GpFillMode fill)
1393 {
1394 TRACE("(%p, %d)\n", path, fill);
1395
1396 if(!path)
1397 return InvalidParameter;
1398
1399 path->fill = fill;
1400
1401 return Ok;
1402 }
1403
1404 GpStatus WINGDIPAPI GdipTransformPath(GpPath *path, GpMatrix *matrix)
1405 {
1406 TRACE("(%p, %p)\n", path, matrix);
1407
1408 if(!path)
1409 return InvalidParameter;
1410
1411 if(path->pathdata.Count == 0)
1412 return Ok;
1413
1414 return GdipTransformMatrixPoints(matrix, path->pathdata.Points,
1415 path->pathdata.Count);
1416 }
1417
1418 GpStatus WINGDIPAPI GdipAddPathRectangle(GpPath *path, REAL x, REAL y,
1419 REAL width, REAL height)
1420 {
1421 GpPath *backup;
1422 GpPointF ptf[2];
1423 GpStatus retstat;
1424 BOOL old_new;
1425
1426 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x, y, width, height);
1427
1428 if(!path || width < 0.0 || height < 0.0)
1429 return InvalidParameter;
1430
1431 /* make a backup copy of path data */
1432 if((retstat = GdipClonePath(path, &backup)) != Ok)
1433 return retstat;
1434
1435 /* rectangle should start as new path */
1436 old_new = path->newfigure;
1437 path->newfigure = TRUE;
1438 if((retstat = GdipAddPathLine(path,x,y,x+width,y)) != Ok){
1439 path->newfigure = old_new;
1440 goto fail;
1441 }
1442
1443 ptf[0].X = x+width;
1444 ptf[0].Y = y+height;
1445 ptf[1].X = x;
1446 ptf[1].Y = y+height;
1447
1448 if((retstat = GdipAddPathLine2(path, ptf, 2)) != Ok) goto fail;
1449 path->pathdata.Types[path->pathdata.Count-1] |= PathPointTypeCloseSubpath;
1450
1451 /* free backup */
1452 GdipDeletePath(backup);
1453 return Ok;
1454
1455 fail:
1456 /* reverting */
1457 GdipDeletePath(path);
1458 GdipClonePath(backup, &path);
1459 GdipDeletePath(backup);
1460
1461 return retstat;
1462 }
1463
1464 GpStatus WINGDIPAPI GdipAddPathRectangleI(GpPath *path, INT x, INT y,
1465 INT width, INT height)
1466 {
1467 TRACE("(%p, %d, %d, %d, %d)\n", path, x, y, width, height);
1468
1469 return GdipAddPathRectangle(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1470 }
1471
1472 GpStatus WINGDIPAPI GdipAddPathRectangles(GpPath *path, GDIPCONST GpRectF *rects, INT count)
1473 {
1474 GpPath *backup;
1475 GpStatus retstat;
1476 INT i;
1477
1478 TRACE("(%p, %p, %d)\n", path, rects, count);
1479
1480 /* count == 0 - verified condition */
1481 if(!path || !rects || count == 0)
1482 return InvalidParameter;
1483
1484 if(count < 0)
1485 return OutOfMemory;
1486
1487 /* make a backup copy */
1488 if((retstat = GdipClonePath(path, &backup)) != Ok)
1489 return retstat;
1490
1491 for(i = 0; i < count; i++){
1492 if((retstat = GdipAddPathRectangle(path,rects[i].X,rects[i].Y,rects[i].Width,rects[i].Height)) != Ok)
1493 goto fail;
1494 }
1495
1496 /* free backup */
1497 GdipDeletePath(backup);
1498 return Ok;
1499
1500 fail:
1501 /* reverting */
1502 GdipDeletePath(path);
1503 GdipClonePath(backup, &path);
1504 GdipDeletePath(backup);
1505
1506 return retstat;
1507 }
1508
1509 GpStatus WINGDIPAPI GdipAddPathRectanglesI(GpPath *path, GDIPCONST GpRect *rects, INT count)
1510 {
1511 GpRectF *rectsF;
1512 GpStatus retstat;
1513 INT i;
1514
1515 TRACE("(%p, %p, %d)\n", path, rects, count);
1516
1517 if(!rects || count == 0)
1518 return InvalidParameter;
1519
1520 if(count < 0)
1521 return OutOfMemory;
1522
1523 rectsF = GdipAlloc(sizeof(GpRectF)*count);
1524
1525 for(i = 0;i < count;i++){
1526 rectsF[i].X = (REAL)rects[i].X;
1527 rectsF[i].Y = (REAL)rects[i].Y;
1528 rectsF[i].Width = (REAL)rects[i].Width;
1529 rectsF[i].Height = (REAL)rects[i].Height;
1530 }
1531
1532 retstat = GdipAddPathRectangles(path, rectsF, count);
1533 GdipFree(rectsF);
1534
1535 return retstat;
1536 }
1537
1538 GpStatus WINGDIPAPI GdipSetPathMarker(GpPath* path)
1539 {
1540 INT count;
1541
1542 TRACE("(%p)\n", path);
1543
1544 if(!path)
1545 return InvalidParameter;
1546
1547 count = path->pathdata.Count;
1548
1549 /* set marker flag */
1550 if(count > 0)
1551 path->pathdata.Types[count-1] |= PathPointTypePathMarker;
1552
1553 return Ok;
1554 }
1555
1556 GpStatus WINGDIPAPI GdipClearPathMarkers(GpPath* path)
1557 {
1558 INT count;
1559 INT i;
1560
1561 TRACE("(%p)\n", path);
1562
1563 if(!path)
1564 return InvalidParameter;
1565
1566 count = path->pathdata.Count;
1567
1568 for(i = 0; i < count - 1; i++){
1569 path->pathdata.Types[i] &= ~PathPointTypePathMarker;
1570 }
1571
1572 return Ok;
1573 }