~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/gdiplus/graphicspath.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  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*sqrtf((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 GdipAddPathCurve3(GpPath *path, GDIPCONST GpPointF *points,
528     INT count, INT offset, INT nseg, REAL tension)
529 {
530     TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path, points, count, offset, nseg, tension);
531 
532     if(!path || !points || offset + 1 >= count || count - offset < nseg + 1)
533         return InvalidParameter;
534 
535     return GdipAddPathCurve2(path, &points[offset], nseg + 1, tension);
536 }
537 
538 GpStatus WINGDIPAPI GdipAddPathCurve3I(GpPath *path, GDIPCONST GpPoint *points,
539     INT count, INT offset, INT nseg, REAL tension)
540 {
541     TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path, points, count, offset, nseg, tension);
542 
543     if(!path || !points || offset + 1 >= count || count - offset < nseg + 1)
544         return InvalidParameter;
545 
546     return GdipAddPathCurve2I(path, &points[offset], nseg + 1, tension);
547 }
548 
549 GpStatus WINGDIPAPI GdipAddPathEllipse(GpPath *path, REAL x, REAL y, REAL width,
550     REAL height)
551 {
552     INT old_count, numpts;
553 
554     TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x, y, width, height);
555 
556     if(!path)
557         return InvalidParameter;
558 
559     if(!lengthen_path(path, MAX_ARC_PTS))
560         return OutOfMemory;
561 
562     old_count = path->pathdata.Count;
563     if((numpts = arc2polybezier(&path->pathdata.Points[old_count],  x, y, width,
564                                height, 0.0, 360.0)) != MAX_ARC_PTS){
565         ERR("expected %d points but got %d\n", MAX_ARC_PTS, numpts);
566         return GenericError;
567     }
568 
569     memset(&path->pathdata.Types[old_count + 1], PathPointTypeBezier,
570            MAX_ARC_PTS - 1);
571 
572     /* An ellipse is an intrinsic figure (always is its own subpath). */
573     path->pathdata.Types[old_count] = PathPointTypeStart;
574     path->pathdata.Types[old_count + MAX_ARC_PTS - 1] |= PathPointTypeCloseSubpath;
575     path->newfigure = TRUE;
576     path->pathdata.Count += MAX_ARC_PTS;
577 
578     return Ok;
579 }
580 
581 GpStatus WINGDIPAPI GdipAddPathEllipseI(GpPath *path, INT x, INT y, INT width,
582     INT height)
583 {
584     TRACE("(%p, %d, %d, %d, %d)\n", path, x, y, width, height);
585 
586     return GdipAddPathEllipse(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
587 }
588 
589 GpStatus WINGDIPAPI GdipAddPathLine2(GpPath *path, GDIPCONST GpPointF *points,
590     INT count)
591 {
592     INT i, old_count;
593 
594     TRACE("(%p, %p, %d)\n", path, points, count);
595 
596     if(!path || !points)
597         return InvalidParameter;
598 
599     if(!lengthen_path(path, count))
600         return OutOfMemory;
601 
602     old_count = path->pathdata.Count;
603 
604     for(i = 0; i < count; i++){
605         path->pathdata.Points[old_count + i].X = points[i].X;
606         path->pathdata.Points[old_count + i].Y = points[i].Y;
607         path->pathdata.Types[old_count + i] = PathPointTypeLine;
608     }
609 
610     if(path->newfigure){
611         path->pathdata.Types[old_count] = PathPointTypeStart;
612         path->newfigure = FALSE;
613     }
614 
615     path->pathdata.Count += count;
616 
617     return Ok;
618 }
619 
620 GpStatus WINGDIPAPI GdipAddPathLine2I(GpPath *path, GDIPCONST GpPoint *points, INT count)
621 {
622     GpPointF *pointsF;
623     INT i;
624     GpStatus stat;
625 
626     TRACE("(%p, %p, %d)\n", path, points, count);
627 
628     if(count <= 0)
629         return InvalidParameter;
630 
631     pointsF = GdipAlloc(sizeof(GpPointF) * count);
632     if(!pointsF)    return OutOfMemory;
633 
634     for(i = 0;i < count; i++){
635         pointsF[i].X = (REAL)points[i].X;
636         pointsF[i].Y = (REAL)points[i].Y;
637     }
638 
639     stat = GdipAddPathLine2(path, pointsF, count);
640 
641     GdipFree(pointsF);
642 
643     return stat;
644 }
645 
646 GpStatus WINGDIPAPI GdipAddPathLine(GpPath *path, REAL x1, REAL y1, REAL x2, REAL y2)
647 {
648     INT old_count;
649 
650     TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x1, y1, x2, y2);
651 
652     if(!path)
653         return InvalidParameter;
654 
655     if(!lengthen_path(path, 2))
656         return OutOfMemory;
657 
658     old_count = path->pathdata.Count;
659 
660     path->pathdata.Points[old_count].X = x1;
661     path->pathdata.Points[old_count].Y = y1;
662     path->pathdata.Points[old_count + 1].X = x2;
663     path->pathdata.Points[old_count + 1].Y = y2;
664 
665     path->pathdata.Types[old_count] =
666         (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
667     path->pathdata.Types[old_count + 1] = PathPointTypeLine;
668 
669     path->newfigure = FALSE;
670     path->pathdata.Count += 2;
671 
672     return Ok;
673 }
674 
675 GpStatus WINGDIPAPI GdipAddPathLineI(GpPath *path, INT x1, INT y1, INT x2, INT y2)
676 {
677     TRACE("(%p, %d, %d, %d, %d)\n", path, x1, y1, x2, y2);
678 
679     return GdipAddPathLine(path, (REAL)x1, (REAL)y1, (REAL)x2, (REAL)y2);
680 }
681 
682 GpStatus WINGDIPAPI GdipAddPathPath(GpPath *path, GDIPCONST GpPath* addingPath,
683     BOOL connect)
684 {
685     INT old_count, count;
686 
687     TRACE("(%p, %p, %d)\n", path, addingPath, connect);
688 
689     if(!path || !addingPath)
690         return InvalidParameter;
691 
692     old_count = path->pathdata.Count;
693     count = addingPath->pathdata.Count;
694 
695     if(!lengthen_path(path, count))
696         return OutOfMemory;
697 
698     memcpy(&path->pathdata.Points[old_count], addingPath->pathdata.Points,
699            count * sizeof(GpPointF));
700     memcpy(&path->pathdata.Types[old_count], addingPath->pathdata.Types, count);
701 
702     if(path->newfigure || !connect)
703         path->pathdata.Types[old_count] = PathPointTypeStart;
704     else
705         path->pathdata.Types[old_count] = PathPointTypeLine;
706 
707     path->newfigure = FALSE;
708     path->pathdata.Count += count;
709 
710     return Ok;
711 }
712 
713 GpStatus WINGDIPAPI GdipAddPathPie(GpPath *path, REAL x, REAL y, REAL width, REAL height,
714     REAL startAngle, REAL sweepAngle)
715 {
716     GpPointF *ptf;
717     GpStatus status;
718     INT i, count;
719 
720     TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
721           path, x, y, width, height, startAngle, sweepAngle);
722 
723     if(!path)
724         return InvalidParameter;
725 
726     /* on zero width/height only start point added */
727     if(width <= 1e-7 || height <= 1e-7){
728         if(!lengthen_path(path, 1))
729             return OutOfMemory;
730         path->pathdata.Points[0].X = x + width  / 2.0;
731         path->pathdata.Points[0].Y = y + height / 2.0;
732         path->pathdata.Types[0] = PathPointTypeStart | PathPointTypeCloseSubpath;
733         path->pathdata.Count = 1;
734         return InvalidParameter;
735     }
736 
737     count = arc2polybezier(NULL, x, y, width, height, startAngle, sweepAngle);
738 
739     if(count == 0)
740         return Ok;
741 
742     ptf = GdipAlloc(sizeof(GpPointF)*count);
743     if(!ptf)
744         return OutOfMemory;
745 
746     arc2polybezier(ptf, x, y, width, height, startAngle, sweepAngle);
747 
748     status = GdipAddPathLine(path, (width - x)/2, (height - y)/2, ptf[0].X, ptf[0].Y);
749     if(status != Ok){
750         GdipFree(ptf);
751         return status;
752     }
753     /* one spline is already added as a line endpoint */
754     if(!lengthen_path(path, count - 1)){
755         GdipFree(ptf);
756         return OutOfMemory;
757     }
758 
759     memcpy(&(path->pathdata.Points[path->pathdata.Count]), &(ptf[1]),sizeof(GpPointF)*(count-1));
760     for(i = 0; i < count-1; i++)
761         path->pathdata.Types[path->pathdata.Count+i] = PathPointTypeBezier;
762 
763     path->pathdata.Count += count-1;
764 
765     GdipClosePathFigure(path);
766 
767     GdipFree(ptf);
768 
769     return status;
770 }
771 
772 GpStatus WINGDIPAPI GdipAddPathPieI(GpPath *path, INT x, INT y, INT width, INT height,
773     REAL startAngle, REAL sweepAngle)
774 {
775     TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
776           path, x, y, width, height, startAngle, sweepAngle);
777 
778     return GdipAddPathPie(path, (REAL)x, (REAL)y, (REAL)width, (REAL)height, startAngle, sweepAngle);
779 }
780 
781 GpStatus WINGDIPAPI GdipAddPathPolygon(GpPath *path, GDIPCONST GpPointF *points, INT count)
782 {
783     INT old_count;
784 
785     TRACE("(%p, %p, %d)\n", path, points, count);
786 
787     if(!path || !points || count < 3)
788         return InvalidParameter;
789 
790     if(!lengthen_path(path, count))
791         return OutOfMemory;
792 
793     old_count = path->pathdata.Count;
794 
795     memcpy(&path->pathdata.Points[old_count], points, count*sizeof(GpPointF));
796     memset(&path->pathdata.Types[old_count + 1], PathPointTypeLine, count - 1);
797 
798     /* A polygon is an intrinsic figure */
799     path->pathdata.Types[old_count] = PathPointTypeStart;
800     path->pathdata.Types[old_count + count - 1] |= PathPointTypeCloseSubpath;
801     path->newfigure = TRUE;
802     path->pathdata.Count += count;
803 
804     return Ok;
805 }
806 
807 GpStatus WINGDIPAPI GdipAddPathPolygonI(GpPath *path, GDIPCONST GpPoint *points, INT count)
808 {
809     GpPointF *ptf;
810     GpStatus status;
811     INT i;
812 
813     TRACE("(%p, %p, %d)\n", path, points, count);
814 
815     if(!points || count < 3)
816         return InvalidParameter;
817 
818     ptf = GdipAlloc(sizeof(GpPointF) * count);
819     if(!ptf)
820         return OutOfMemory;
821 
822     for(i = 0; i < count; i++){
823         ptf[i].X = (REAL)points[i].X;
824         ptf[i].Y = (REAL)points[i].Y;
825     }
826 
827     status = GdipAddPathPolygon(path, ptf, count);
828 
829     GdipFree(ptf);
830 
831     return status;
832 }
833 
834 GpStatus WINGDIPAPI GdipAddPathString(GpPath* path, GDIPCONST WCHAR* string, INT length, GDIPCONST GpFontFamily* family, INT style, REAL emSize, GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat* format)
835 {
836     FIXME("(%p, %p, %d, %p, %d, %f, %p, %p): stub\n", path, string, length, family, style, emSize, layoutRect, format);
837     return NotImplemented;
838 }
839 
840 GpStatus WINGDIPAPI GdipAddPathStringI(GpPath* path, GDIPCONST WCHAR* string, INT length, GDIPCONST GpFontFamily* family, INT style, REAL emSize, GDIPCONST Rect* layoutRect, GDIPCONST GpStringFormat* format)
841 {
842     FIXME("(%p, %p, %d, %p, %d, %f, %p, %p): stub\n", path, string, length, family, style, emSize, layoutRect, format);
843     return NotImplemented;
844 }
845 
846 GpStatus WINGDIPAPI GdipClonePath(GpPath* path, GpPath **clone)
847 {
848     TRACE("(%p, %p)\n", path, clone);
849 
850     if(!path || !clone)
851         return InvalidParameter;
852 
853     *clone = GdipAlloc(sizeof(GpPath));
854     if(!*clone) return OutOfMemory;
855 
856     **clone = *path;
857 
858     (*clone)->pathdata.Points = GdipAlloc(path->datalen * sizeof(PointF));
859     (*clone)->pathdata.Types = GdipAlloc(path->datalen);
860     if(!(*clone)->pathdata.Points || !(*clone)->pathdata.Types){
861         GdipFree(*clone);
862         GdipFree((*clone)->pathdata.Points);
863         GdipFree((*clone)->pathdata.Types);
864         return OutOfMemory;
865     }
866 
867     memcpy((*clone)->pathdata.Points, path->pathdata.Points,
868            path->datalen * sizeof(PointF));
869     memcpy((*clone)->pathdata.Types, path->pathdata.Types, path->datalen);
870 
871     return Ok;
872 }
873 
874 GpStatus WINGDIPAPI GdipClosePathFigure(GpPath* path)
875 {
876     TRACE("(%p)\n", path);
877 
878     if(!path)
879         return InvalidParameter;
880 
881     if(path->pathdata.Count > 0){
882         path->pathdata.Types[path->pathdata.Count - 1] |= PathPointTypeCloseSubpath;
883         path->newfigure = TRUE;
884     }
885 
886     return Ok;
887 }
888 
889 GpStatus WINGDIPAPI GdipClosePathFigures(GpPath* path)
890 {
891     INT i;
892 
893     TRACE("(%p)\n", path);
894 
895     if(!path)
896         return InvalidParameter;
897 
898     for(i = 1; i < path->pathdata.Count; i++){
899         if(path->pathdata.Types[i] == PathPointTypeStart)
900             path->pathdata.Types[i-1] |= PathPointTypeCloseSubpath;
901     }
902 
903     path->newfigure = TRUE;
904 
905     return Ok;
906 }
907 
908 GpStatus WINGDIPAPI GdipCreatePath(GpFillMode fill, GpPath **path)
909 {
910     TRACE("(%d, %p)\n", fill, path);
911 
912     if(!path)
913         return InvalidParameter;
914 
915     *path = GdipAlloc(sizeof(GpPath));
916     if(!*path)  return OutOfMemory;
917 
918     (*path)->fill = fill;
919     (*path)->newfigure = TRUE;
920 
921     return Ok;
922 }
923 
924 GpStatus WINGDIPAPI GdipCreatePath2(GDIPCONST GpPointF* points,
925     GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
926 {
927     TRACE("(%p, %p, %d, %d, %p)\n", points, types, count, fill, path);
928 
929     if(!path)
930         return InvalidParameter;
931 
932     *path = GdipAlloc(sizeof(GpPath));
933     if(!*path)  return OutOfMemory;
934 
935     (*path)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
936     (*path)->pathdata.Types = GdipAlloc(count);
937 
938     if(!(*path)->pathdata.Points || !(*path)->pathdata.Types){
939         GdipFree((*path)->pathdata.Points);
940         GdipFree((*path)->pathdata.Types);
941         GdipFree(*path);
942         return OutOfMemory;
943     }
944 
945     memcpy((*path)->pathdata.Points, points, count * sizeof(PointF));
946     memcpy((*path)->pathdata.Types, types, count);
947     (*path)->pathdata.Count = count;
948     (*path)->datalen = count;
949 
950     (*path)->fill = fill;
951     (*path)->newfigure = TRUE;
952 
953     return Ok;
954 }
955 
956 GpStatus WINGDIPAPI GdipCreatePath2I(GDIPCONST GpPoint* points,
957     GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
958 {
959     GpPointF *ptF;
960     GpStatus ret;
961     INT i;
962 
963     TRACE("(%p, %p, %d, %d, %p)\n", points, types, count, fill, path);
964 
965     ptF = GdipAlloc(sizeof(GpPointF)*count);
966 
967     for(i = 0;i < count; i++){
968         ptF[i].X = (REAL)points[i].X;
969         ptF[i].Y = (REAL)points[i].Y;
970     }
971 
972     ret = GdipCreatePath2(ptF, types, count, fill, path);
973 
974     GdipFree(ptF);
975 
976     return ret;
977 }
978 
979 GpStatus WINGDIPAPI GdipDeletePath(GpPath *path)
980 {
981     TRACE("(%p)\n", path);
982 
983     if(!path)
984         return InvalidParameter;
985 
986     GdipFree(path->pathdata.Points);
987     GdipFree(path->pathdata.Types);
988     GdipFree(path);
989 
990     return Ok;
991 }
992 
993 GpStatus WINGDIPAPI GdipFlattenPath(GpPath *path, GpMatrix* matrix, REAL flatness)
994 {
995     path_list_node_t *list, *node;
996     GpPointF pt;
997     INT i = 1;
998     INT startidx = 0;
999 
1000     TRACE("(%p, %p, %.2f)\n", path, matrix, flatness);
1001 
1002     if(!path)
1003         return InvalidParameter;
1004 
1005     if(matrix){
1006         WARN("transformation not supported yet!\n");
1007         return NotImplemented;
1008     }
1009 
1010     if(path->pathdata.Count == 0)
1011         return Ok;
1012 
1013     pt = path->pathdata.Points[0];
1014     if(!init_path_list(&list, pt.X, pt.Y))
1015         return OutOfMemory;
1016 
1017     node = list;
1018 
1019     while(i < path->pathdata.Count){
1020 
1021         BYTE type = path->pathdata.Types[i] & PathPointTypePathTypeMask;
1022         path_list_node_t *start;
1023 
1024         pt = path->pathdata.Points[i];
1025 
1026         /* save last start point index */
1027         if(type == PathPointTypeStart)
1028             startidx = i;
1029 
1030         /* always add line points and start points */
1031         if((type == PathPointTypeStart) || (type == PathPointTypeLine)){
1032             if(!add_path_list_node(node, pt.X, pt.Y, path->pathdata.Types[i]))
1033                 goto memout;
1034 
1035             node = node->next;
1036             ++i;
1037             continue;
1038         }
1039 
1040         /* Bezier curve always stored as 4 points */
1041         if((path->pathdata.Types[i-1] & PathPointTypePathTypeMask) != PathPointTypeStart){
1042             type = (path->pathdata.Types[i] & ~PathPointTypePathTypeMask) | PathPointTypeLine;
1043             if(!add_path_list_node(node, pt.X, pt.Y, type))
1044                 goto memout;
1045 
1046             node = node->next;
1047         }
1048 
1049         /* test for closed figure */
1050         if(path->pathdata.Types[i+1] & PathPointTypeCloseSubpath){
1051             pt = path->pathdata.Points[startidx];
1052             ++i;
1053         }
1054         else
1055         {
1056             i += 2;
1057             pt = path->pathdata.Points[i];
1058         };
1059 
1060         start = node;
1061         /* add Bezier end point */
1062         type = (path->pathdata.Types[i] & ~PathPointTypePathTypeMask) | PathPointTypeLine;
1063         if(!add_path_list_node(node, pt.X, pt.Y, type))
1064             goto memout;
1065         node = node->next;
1066 
1067         /* flatten curve */
1068         if(!flatten_bezier(start, path->pathdata.Points[i-2].X, path->pathdata.Points[i-2].Y,
1069                                   path->pathdata.Points[i-1].X, path->pathdata.Points[i-1].Y,
1070                            node, flatness))
1071             goto memout;
1072 
1073         ++i;
1074     }/* while */
1075 
1076     /* store path data back */
1077     i = path_list_count(list);
1078     if(!lengthen_path(path, i))
1079         goto memout;
1080     path->pathdata.Count = i;
1081 
1082     node = list;
1083     for(i = 0; i < path->pathdata.Count; i++){
1084         path->pathdata.Points[i] = node->pt;
1085         path->pathdata.Types[i]  = node->type;
1086         node = node->next;
1087     }
1088 
1089     free_path_list(list);
1090     return Ok;
1091 
1092 memout:
1093     free_path_list(list);
1094     return OutOfMemory;
1095 }
1096 
1097 GpStatus WINGDIPAPI GdipGetPathData(GpPath *path, GpPathData* pathData)
1098 {
1099     TRACE("(%p, %p)\n", path, pathData);
1100 
1101     if(!path || !pathData)
1102         return InvalidParameter;
1103 
1104     /* Only copy data. pathData allocation/freeing controlled by wrapper class.
1105        Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
1106     memcpy(pathData->Points, path->pathdata.Points, sizeof(PointF) * pathData->Count);
1107     memcpy(pathData->Types , path->pathdata.Types , pathData->Count);
1108 
1109     return Ok;
1110 }
1111 
1112 GpStatus WINGDIPAPI GdipGetPathFillMode(GpPath *path, GpFillMode *fillmode)
1113 {
1114     TRACE("(%p, %p)\n", path, fillmode);
1115 
1116     if(!path || !fillmode)
1117         return InvalidParameter;
1118 
1119     *fillmode = path->fill;
1120 
1121     return Ok;
1122 }
1123 
1124 GpStatus WINGDIPAPI GdipGetPathLastPoint(GpPath* path, GpPointF* lastPoint)
1125 {
1126     INT count;
1127 
1128     TRACE("(%p, %p)\n", path, lastPoint);
1129 
1130     if(!path || !lastPoint)
1131         return InvalidParameter;
1132 
1133     count = path->pathdata.Count;
1134     if(count > 0)
1135         *lastPoint = path->pathdata.Points[count-1];
1136 
1137     return Ok;
1138 }
1139 
1140 GpStatus WINGDIPAPI GdipGetPathPoints(GpPath *path, GpPointF* points, INT count)
1141 {
1142     TRACE("(%p, %p, %d)\n", path, points, count);
1143 
1144     if(!path)
1145         return InvalidParameter;
1146 
1147     if(count < path->pathdata.Count)
1148         return InsufficientBuffer;
1149 
1150     memcpy(points, path->pathdata.Points, path->pathdata.Count * sizeof(GpPointF));
1151 
1152     return Ok;
1153 }
1154 
1155 GpStatus WINGDIPAPI GdipGetPathPointsI(GpPath *path, GpPoint* points, INT count)
1156 {
1157     GpStatus ret;
1158     GpPointF *ptf;
1159     INT i;
1160 
1161     TRACE("(%p, %p, %d)\n", path, points, count);
1162 
1163     if(count <= 0)
1164         return InvalidParameter;
1165 
1166     ptf = GdipAlloc(sizeof(GpPointF)*count);
1167     if(!ptf)    return OutOfMemory;
1168 
1169     ret = GdipGetPathPoints(path,ptf,count);
1170     if(ret == Ok)
1171         for(i = 0;i < count;i++){
1172             points[i].X = roundr(ptf[i].X);
1173             points[i].Y = roundr(ptf[i].Y);
1174         };
1175     GdipFree(ptf);
1176 
1177     return ret;
1178 }
1179 
1180 GpStatus WINGDIPAPI GdipGetPathTypes(GpPath *path, BYTE* types, INT count)
1181 {
1182     TRACE("(%p, %p, %d)\n", path, types, count);
1183 
1184     if(!path)
1185         return InvalidParameter;
1186 
1187     if(count < path->pathdata.Count)
1188         return InsufficientBuffer;
1189 
1190     memcpy(types, path->pathdata.Types, path->pathdata.Count);
1191 
1192     return Ok;
1193 }
1194 
1195 /* Windows expands the bounding box to the maximum possible bounding box
1196  * for a given pen.  For example, if a line join can extend past the point
1197  * it's joining by x units, the bounding box is extended by x units in every
1198  * direction (even though this is too conservative for most cases). */
1199 GpStatus WINGDIPAPI GdipGetPathWorldBounds(GpPath* path, GpRectF* bounds,
1200     GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
1201 {
1202     GpPointF * points, temp_pts[4];
1203     INT count, i;
1204     REAL path_width = 1.0, width, height, temp, low_x, low_y, high_x, high_y;
1205 
1206     TRACE("(%p, %p, %p, %p)\n", path, bounds, matrix, pen);
1207 
1208     /* Matrix and pen can be null. */
1209     if(!path || !bounds)
1210         return InvalidParameter;
1211 
1212     /* If path is empty just return. */
1213     count = path->pathdata.Count;
1214     if(count == 0){
1215         bounds->X = bounds->Y = bounds->Width = bounds->Height = 0.0;
1216         return Ok;
1217     }
1218 
1219     points = path->pathdata.Points;
1220 
1221     low_x = high_x = points[0].X;
1222     low_y = high_y = points[0].Y;
1223 
1224     for(i = 1; i < count; i++){
1225         low_x = min(low_x, points[i].X);
1226         low_y = min(low_y, points[i].Y);
1227         high_x = max(high_x, points[i].X);
1228         high_y = max(high_y, points[i].Y);
1229     }
1230 
1231     width = high_x - low_x;
1232     height = high_y - low_y;
1233 
1234     /* This looks unusual but it's the only way I can imitate windows. */
1235     if(matrix){
1236         temp_pts[0].X = low_x;
1237         temp_pts[0].Y = low_y;
1238         temp_pts[1].X = low_x;
1239         temp_pts[1].Y = high_y;
1240         temp_pts[2].X = high_x;
1241         temp_pts[2].Y = high_y;
1242         temp_pts[3].X = high_x;
1243         temp_pts[3].Y = low_y;
1244 
1245         GdipTransformMatrixPoints((GpMatrix*)matrix, temp_pts, 4);
1246         low_x = temp_pts[0].X;
1247         low_y = temp_pts[0].Y;
1248 
1249         for(i = 1; i < 4; i++){
1250             low_x = min(low_x, temp_pts[i].X);
1251             low_y = min(low_y, temp_pts[i].Y);
1252         }
1253 
1254         temp = width;
1255         width = height * fabs(matrix->matrix[2]) + width * fabs(matrix->matrix[0]);
1256         height = height * fabs(matrix->matrix[3]) + temp * fabs(matrix->matrix[1]);
1257     }
1258 
1259     if(pen){
1260         path_width = pen->width / 2.0;
1261 
1262         if(count > 2)
1263             path_width = max(path_width,  pen->width * pen->miterlimit / 2.0);
1264         /* FIXME: this should probably also check for the startcap */
1265         if(pen->endcap & LineCapNoAnchor)
1266             path_width = max(path_width,  pen->width * 2.2);
1267 
1268         low_x -= path_width;
1269         low_y -= path_width;
1270         width += 2.0 * path_width;
1271         height += 2.0 * path_width;
1272     }
1273 
1274     bounds->X = low_x;
1275     bounds->Y = low_y;
1276     bounds->Width = width;
1277     bounds->Height = height;
1278 
1279     return Ok;
1280 }
1281 
1282 GpStatus WINGDIPAPI GdipGetPathWorldBoundsI(GpPath* path, GpRect* bounds,
1283     GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
1284 {
1285     GpStatus ret;
1286     GpRectF boundsF;
1287 
1288     TRACE("(%p, %p, %p, %p)\n", path, bounds, matrix, pen);
1289 
1290     ret = GdipGetPathWorldBounds(path,&boundsF,matrix,pen);
1291 
1292     if(ret == Ok){
1293         bounds->X      = roundr(boundsF.X);
1294         bounds->Y      = roundr(boundsF.Y);
1295         bounds->Width  = roundr(boundsF.Width);
1296         bounds->Height = roundr(boundsF.Height);
1297     }
1298 
1299     return ret;
1300 }
1301 
1302 GpStatus WINGDIPAPI GdipGetPointCount(GpPath *path, INT *count)
1303 {
1304     TRACE("(%p, %p)\n", path, count);
1305 
1306     if(!path)
1307         return InvalidParameter;
1308 
1309     *count = path->pathdata.Count;
1310 
1311     return Ok;
1312 }
1313 
1314 GpStatus WINGDIPAPI GdipReversePath(GpPath* path)
1315 {
1316     INT i, count;
1317     INT start = 0; /* position in reversed path */
1318     GpPathData revpath;
1319 
1320     TRACE("(%p)\n", path);
1321 
1322     if(!path)
1323         return InvalidParameter;
1324 
1325     count = path->pathdata.Count;
1326 
1327     if(count == 0) return Ok;
1328 
1329     revpath.Points = GdipAlloc(sizeof(GpPointF)*count);
1330     revpath.Types  = GdipAlloc(sizeof(BYTE)*count);
1331     revpath.Count  = count;
1332     if(!revpath.Points || !revpath.Types){
1333         GdipFree(revpath.Points);
1334         GdipFree(revpath.Types);
1335         return OutOfMemory;
1336     }
1337 
1338     for(i = 0; i < count; i++){
1339 
1340         /* find next start point */
1341         if(path->pathdata.Types[count-i-1] == PathPointTypeStart){
1342             INT j;
1343             for(j = start; j <= i; j++){
1344                 revpath.Points[j] = path->pathdata.Points[count-j-1];
1345                 revpath.Types[j] = path->pathdata.Types[count-j-1];
1346             }
1347             /* mark start point */
1348             revpath.Types[start] = PathPointTypeStart;
1349             /* set 'figure' endpoint type */
1350             if(i-start > 1){
1351                 revpath.Types[i] = path->pathdata.Types[count-start-1] & ~PathPointTypePathTypeMask;
1352                 revpath.Types[i] |= revpath.Types[i-1];
1353             }
1354             else
1355                 revpath.Types[i] = path->pathdata.Types[start];
1356 
1357             start = i+1;
1358         }
1359     }
1360 
1361     memcpy(path->pathdata.Points, revpath.Points, sizeof(GpPointF)*count);
1362     memcpy(path->pathdata.Types,  revpath.Types,  sizeof(BYTE)*count);
1363 
1364     GdipFree(revpath.Points);
1365     GdipFree(revpath.Types);
1366 
1367     return Ok;
1368 }
1369 
1370 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPointI(GpPath* path, INT x, INT y,
1371     GpPen *pen, GpGraphics *graphics, BOOL *result)
1372 {
1373     TRACE("(%p, %d, %d, %p, %p, %p)\n", path, x, y, pen, graphics, result);
1374 
1375     return GdipIsOutlineVisiblePathPoint(path, x, y, pen, graphics, result);
1376 }
1377 
1378 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPoint(GpPath* path, REAL x, REAL y,
1379     GpPen *pen, GpGraphics *graphics, BOOL *result)
1380 {
1381     static int calls;
1382 
1383     if(!path || !pen)
1384         return InvalidParameter;
1385 
1386     if(!(calls++))
1387         FIXME("not implemented\n");
1388 
1389     return NotImplemented;
1390 }
1391 
1392 GpStatus WINGDIPAPI GdipIsVisiblePathPointI(GpPath* path, INT x, INT y, GpGraphics *graphics, BOOL *result)
1393 {
1394     TRACE("(%p, %d, %d, %p, %p)\n", path, x, y, graphics, result);
1395 
1396     return GdipIsVisiblePathPoint(path, x, y, graphics, result);
1397 }
1398 
1399 /*****************************************************************************
1400  * GdipIsVisiblePathPoint [GDIPLUS.@]
1401  */
1402 GpStatus WINGDIPAPI GdipIsVisiblePathPoint(GpPath* path, REAL x, REAL y, GpGraphics *graphics, BOOL *result)
1403 {
1404     GpRegion *region;
1405     HRGN hrgn;
1406     GpStatus status;
1407 
1408     if(!path || !result) return InvalidParameter;
1409 
1410     status = GdipCreateRegionPath(path, &region);
1411     if(status != Ok)
1412         return status;
1413 
1414     status = GdipGetRegionHRgn(region, graphics, &hrgn);
1415     if(status != Ok){
1416         GdipDeleteRegion(region);
1417         return status;
1418     }
1419 
1420     *result = PtInRegion(hrgn, roundr(x), roundr(y));
1421 
1422     DeleteObject(hrgn);
1423     GdipDeleteRegion(region);
1424 
1425     return Ok;
1426 }
1427 
1428 GpStatus WINGDIPAPI GdipStartPathFigure(GpPath *path)
1429 {
1430     TRACE("(%p)\n", path);
1431 
1432     if(!path)
1433         return InvalidParameter;
1434 
1435     path->newfigure = TRUE;
1436 
1437     return Ok;
1438 }
1439 
1440 GpStatus WINGDIPAPI GdipResetPath(GpPath *path)
1441 {
1442     TRACE("(%p)\n", path);
1443 
1444     if(!path)
1445         return InvalidParameter;
1446 
1447     path->pathdata.Count = 0;
1448     path->newfigure = TRUE;
1449     path->fill = FillModeAlternate;
1450 
1451     return Ok;
1452 }
1453 
1454 GpStatus WINGDIPAPI GdipSetPathFillMode(GpPath *path, GpFillMode fill)
1455 {
1456     TRACE("(%p, %d)\n", path, fill);
1457 
1458     if(!path)
1459         return InvalidParameter;
1460 
1461     path->fill = fill;
1462 
1463     return Ok;
1464 }
1465 
1466 GpStatus WINGDIPAPI GdipTransformPath(GpPath *path, GpMatrix *matrix)
1467 {
1468     TRACE("(%p, %p)\n", path, matrix);
1469 
1470     if(!path)
1471         return InvalidParameter;
1472 
1473     if(path->pathdata.Count == 0)
1474         return Ok;
1475 
1476     return GdipTransformMatrixPoints(matrix, path->pathdata.Points,
1477                                      path->pathdata.Count);
1478 }
1479 
1480 GpStatus WINGDIPAPI GdipWarpPath(GpPath *path, GpMatrix* matrix,
1481     GDIPCONST GpPointF *points, INT count, REAL x, REAL y, REAL width,
1482     REAL height, WarpMode warpmode, REAL flatness)
1483 {
1484     FIXME("(%p,%p,%p,%i,%0.2f,%0.2f,%0.2f,%0.2f,%i,%0.2f)\n", path, matrix,
1485         points, count, x, y, width, height, warpmode, flatness);
1486 
1487     return NotImplemented;
1488 }
1489 
1490 GpStatus WINGDIPAPI GdipWidenPath(GpPath *path, GpPen *pen, GpMatrix *matrix,
1491     REAL flatness)
1492 {
1493     FIXME("(%p,%p,%p,%0.2f)\n", path, pen, matrix, flatness);
1494 
1495     return NotImplemented;
1496 }
1497 
1498 GpStatus WINGDIPAPI GdipAddPathRectangle(GpPath *path, REAL x, REAL y,
1499     REAL width, REAL height)
1500 {
1501     GpPath *backup;
1502     GpPointF ptf[2];
1503     GpStatus retstat;
1504     BOOL old_new;
1505 
1506     TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x, y, width, height);
1507 
1508     if(!path || width < 0.0 || height < 0.0)
1509         return InvalidParameter;
1510 
1511     /* make a backup copy of path data */
1512     if((retstat = GdipClonePath(path, &backup)) != Ok)
1513         return retstat;
1514 
1515     /* rectangle should start as new path */
1516     old_new = path->newfigure;
1517     path->newfigure = TRUE;
1518     if((retstat = GdipAddPathLine(path,x,y,x+width,y)) != Ok){
1519         path->newfigure = old_new;
1520         goto fail;
1521     }
1522 
1523     ptf[0].X = x+width;
1524     ptf[0].Y = y+height;
1525     ptf[1].X = x;
1526     ptf[1].Y = y+height;
1527 
1528     if((retstat = GdipAddPathLine2(path, ptf, 2)) != Ok)  goto fail;
1529     path->pathdata.Types[path->pathdata.Count-1] |= PathPointTypeCloseSubpath;
1530 
1531     /* free backup */
1532     GdipDeletePath(backup);
1533     return Ok;
1534 
1535 fail:
1536     /* reverting */
1537     GdipDeletePath(path);
1538     GdipClonePath(backup, &path);
1539     GdipDeletePath(backup);
1540 
1541     return retstat;
1542 }
1543 
1544 GpStatus WINGDIPAPI GdipAddPathRectangleI(GpPath *path, INT x, INT y,
1545     INT width, INT height)
1546 {
1547     TRACE("(%p, %d, %d, %d, %d)\n", path, x, y, width, height);
1548 
1549     return GdipAddPathRectangle(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1550 }
1551 
1552 GpStatus WINGDIPAPI GdipAddPathRectangles(GpPath *path, GDIPCONST GpRectF *rects, INT count)
1553 {
1554     GpPath *backup;
1555     GpStatus retstat;
1556     INT i;
1557 
1558     TRACE("(%p, %p, %d)\n", path, rects, count);
1559 
1560     /* count == 0 - verified condition  */
1561     if(!path || !rects || count == 0)
1562         return InvalidParameter;
1563 
1564     if(count < 0)
1565         return OutOfMemory;
1566 
1567     /* make a backup copy */
1568     if((retstat = GdipClonePath(path, &backup)) != Ok)
1569         return retstat;
1570 
1571     for(i = 0; i < count; i++){
1572         if((retstat = GdipAddPathRectangle(path,rects[i].X,rects[i].Y,rects[i].Width,rects[i].Height)) != Ok)
1573             goto fail;
1574     }
1575 
1576     /* free backup */
1577     GdipDeletePath(backup);
1578     return Ok;
1579 
1580 fail:
1581     /* reverting */
1582     GdipDeletePath(path);
1583     GdipClonePath(backup, &path);
1584     GdipDeletePath(backup);
1585 
1586     return retstat;
1587 }
1588 
1589 GpStatus WINGDIPAPI GdipAddPathRectanglesI(GpPath *path, GDIPCONST GpRect *rects, INT count)
1590 {
1591     GpRectF *rectsF;
1592     GpStatus retstat;
1593     INT i;
1594 
1595     TRACE("(%p, %p, %d)\n", path, rects, count);
1596 
1597     if(!rects || count == 0)
1598         return InvalidParameter;
1599 
1600     if(count < 0)
1601         return OutOfMemory;
1602 
1603     rectsF = GdipAlloc(sizeof(GpRectF)*count);
1604 
1605     for(i = 0;i < count;i++){
1606         rectsF[i].X      = (REAL)rects[i].X;
1607         rectsF[i].Y      = (REAL)rects[i].Y;
1608         rectsF[i].Width  = (REAL)rects[i].Width;
1609         rectsF[i].Height = (REAL)rects[i].Height;
1610     }
1611 
1612     retstat = GdipAddPathRectangles(path, rectsF, count);
1613     GdipFree(rectsF);
1614 
1615     return retstat;
1616 }
1617 
1618 GpStatus WINGDIPAPI GdipSetPathMarker(GpPath* path)
1619 {
1620     INT count;
1621 
1622     TRACE("(%p)\n", path);
1623 
1624     if(!path)
1625         return InvalidParameter;
1626 
1627     count = path->pathdata.Count;
1628 
1629     /* set marker flag */
1630     if(count > 0)
1631         path->pathdata.Types[count-1] |= PathPointTypePathMarker;
1632 
1633     return Ok;
1634 }
1635 
1636 GpStatus WINGDIPAPI GdipClearPathMarkers(GpPath* path)
1637 {
1638     INT count;
1639     INT i;
1640 
1641     TRACE("(%p)\n", path);
1642 
1643     if(!path)
1644         return InvalidParameter;
1645 
1646     count = path->pathdata.Count;
1647 
1648     for(i = 0; i < count - 1; i++){
1649         path->pathdata.Types[i] &= ~PathPointTypePathMarker;
1650     }
1651 
1652     return Ok;
1653 }
1654 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.