Release 8.16.
[wine.git] / dlls / gdiplus / graphicspath.c
blob8e436f96f4ef41362ec111546b73c43aff904371
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
21 #include <math.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
28 #include "objbase.h"
30 #include "gdiplus.h"
31 #include "gdiplus_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
36 #define SQRT3 1.73205080757
38 typedef struct path_list_node_t path_list_node_t;
39 struct path_list_node_t {
40 GpPointF pt;
41 BYTE type; /* PathPointTypeStart or PathPointTypeLine */
42 path_list_node_t *next;
45 /* init list */
46 static BOOL init_path_list(path_list_node_t **node, REAL x, REAL y)
48 *node = heap_alloc_zero(sizeof(path_list_node_t));
49 if(!*node)
50 return FALSE;
52 (*node)->pt.X = x;
53 (*node)->pt.Y = y;
54 (*node)->type = PathPointTypeStart;
55 (*node)->next = NULL;
57 return TRUE;
60 /* free all nodes including argument */
61 static void free_path_list(path_list_node_t *node)
63 path_list_node_t *n = node;
65 while(n){
66 n = n->next;
67 heap_free(node);
68 node = n;
72 /* Add a node after 'node' */
74 * Returns
75 * pointer on success
76 * NULL on allocation problems
78 static path_list_node_t* add_path_list_node(path_list_node_t *node, REAL x, REAL y, BOOL type)
80 path_list_node_t *new;
82 new = heap_alloc_zero(sizeof(path_list_node_t));
83 if(!new)
84 return NULL;
86 new->pt.X = x;
87 new->pt.Y = y;
88 new->type = type;
89 new->next = node->next;
90 node->next = new;
92 return new;
95 /* returns element count */
96 static INT path_list_count(path_list_node_t *node)
98 INT count = 1;
100 while((node = node->next))
101 ++count;
103 return count;
106 struct flatten_bezier_job
108 path_list_node_t *start;
109 REAL x2;
110 REAL y2;
111 REAL x3;
112 REAL y3;
113 path_list_node_t *end;
114 struct list entry;
117 static BOOL flatten_bezier_add(struct list *jobs, path_list_node_t *start, REAL x2, REAL y2, REAL x3, REAL y3, path_list_node_t *end)
119 struct flatten_bezier_job *job = malloc(sizeof(struct flatten_bezier_job));
120 struct flatten_bezier_job temp = { start, x2, y2, x3, y3, end };
121 if (!job)
122 return FALSE;
123 *job = temp;
124 list_add_after(jobs, &job->entry);
125 return TRUE;
128 /* GdipFlattenPath helper */
130 * Used to recursively flatten single Bezier curve
131 * Parameters:
132 * - start : pointer to start point node;
133 * - (x2, y2): first control point;
134 * - (x3, y3): second control point;
135 * - end : pointer to end point node
136 * - flatness: admissible error of linear approximation.
138 * Return value:
139 * TRUE : success
140 * FALSE: out of memory
142 * TODO: used quality criteria should be revised to match native as
143 * closer as possible.
145 static BOOL flatten_bezier(path_list_node_t *start, REAL x2, REAL y2, REAL x3, REAL y3,
146 path_list_node_t *end, REAL flatness)
148 /* this 5 middle points with start/end define to half-curves */
149 GpPointF mp[5];
150 GpPointF pt, pt_st;
151 path_list_node_t *node;
152 REAL area_triangle, distance_start_end;
153 BOOL ret = TRUE;
154 struct list jobs;
155 struct flatten_bezier_job *current, *next;
157 list_init( &jobs );
158 flatten_bezier_add(&jobs, start, x2, y2, x3, y3, end);
159 LIST_FOR_EACH_ENTRY( current, &jobs, struct flatten_bezier_job, entry )
161 start = current->start;
162 x2 = current->x2;
163 y2 = current->y2;
164 x3 = current->x3;
165 y3 = current->y3;
166 end = current->end;
168 /* middle point between control points */
169 pt.X = (x2 + x3) / 2.0;
170 pt.Y = (y2 + y3) / 2.0;
172 /* calculate bezier curve middle points == new control points */
173 mp[0].X = (start->pt.X + x2) / 2.0;
174 mp[0].Y = (start->pt.Y + y2) / 2.0;
175 mp[1].X = (mp[0].X + pt.X) / 2.0;
176 mp[1].Y = (mp[0].Y + pt.Y) / 2.0;
177 mp[4].X = (end->pt.X + x3) / 2.0;
178 mp[4].Y = (end->pt.Y + y3) / 2.0;
179 mp[3].X = (mp[4].X + pt.X) / 2.0;
180 mp[3].Y = (mp[4].Y + pt.Y) / 2.0;
182 /* middle point between new control points */
183 mp[2].X = (mp[1].X + mp[3].X) / 2.0;
184 mp[2].Y = (mp[1].Y + mp[3].Y) / 2.0;
186 pt = end->pt;
187 pt_st = start->pt;
189 /* Test for closely spaced points that don't need to be flattened
190 * Also avoids limited-precision errors in flatness check
192 if((fabs(pt.X - mp[2].X) + fabs(pt.Y - mp[2].Y) +
193 fabs(pt_st.X - mp[2].X) + fabs(pt_st.Y - mp[2].Y) ) <= flatness * 0.5)
194 continue;
196 /* check flatness as a half of distance between middle point and a linearized path
197 * formula for distance point from line for point (x0, y0) and line (x1, y1) (x2, y2)
198 * is defined as (area_triangle / distance_start_end):
199 * | (x2 - x1) * (y1 - y0) - (x1 - x0) * (y2 - y1) / sqrt( (x2 - x1)^2 + (y2 - y1)^2 ) |
200 * Here rearranged to avoid division and simplified:
201 * x0(y2 - y1) + y0(x1 - x2) + (x2*y1 - x1*y2)
203 area_triangle = (pt.Y - pt_st.Y)*mp[2].X + (pt_st.X - pt.X)*mp[2].Y + (pt_st.Y*pt.X - pt_st.X*pt.Y);
204 distance_start_end = sqrtf(powf(pt.Y - pt_st.Y, 2.0) + powf(pt_st.X - pt.X, 2.0));
205 if(fabs(area_triangle) <= (0.5 * flatness * distance_start_end)){
206 continue;
208 else
209 /* add a middle point */
210 if(!(node = add_path_list_node(start, mp[2].X, mp[2].Y, PathPointTypeLine)))
212 ret = FALSE;
213 break;
216 /* do the same with halves */
217 if (!flatten_bezier_add(&current->entry, node, mp[3].X, mp[3].Y, mp[4].X, mp[4].Y, end))
218 break;
219 if (!flatten_bezier_add(&current->entry, start, mp[0].X, mp[0].Y, mp[1].X, mp[1].Y, node))
220 break;
223 /* Cleanup */
224 LIST_FOR_EACH_ENTRY_SAFE( current, next, &jobs, struct flatten_bezier_job, entry )
226 list_remove(&current->entry);
227 free(current);
230 return ret;
233 /* GdipAddPath* helper
235 * Several GdipAddPath functions are expected to add onto an open figure.
236 * So if the first point being added is an exact match to the last point
237 * of the existing line, that point should not be added.
239 * Parameters:
240 * path : path to which points should be added
241 * points : array of points to add
242 * count : number of points to add (at least 1)
243 * type : type of the points being added
245 * Return value:
246 * OutOfMemory : out of memory, could not lengthen path
247 * Ok : success
249 static GpStatus extend_current_figure(GpPath *path, GDIPCONST PointF *points, INT count, BYTE type)
251 INT insert_index = path->pathdata.Count;
252 BYTE first_point_type = (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
254 if(!path->newfigure &&
255 path->pathdata.Points[insert_index-1].X == points[0].X &&
256 path->pathdata.Points[insert_index-1].Y == points[0].Y)
258 points++;
259 count--;
260 first_point_type = type;
263 if(!count)
264 return Ok;
266 if(!lengthen_path(path, count))
267 return OutOfMemory;
269 memcpy(path->pathdata.Points + insert_index, points, sizeof(GpPointF)*count);
270 path->pathdata.Types[insert_index] = first_point_type;
271 memset(path->pathdata.Types + insert_index + 1, type, count - 1);
273 path->newfigure = FALSE;
274 path->pathdata.Count += count;
276 return Ok;
279 /*******************************************************************************
280 * GdipAddPathArc [GDIPLUS.1]
282 * Add an elliptical arc to the given path.
284 * PARAMS
285 * path [I/O] Path that the arc is appended to
286 * x [I] X coordinate of the boundary rectangle
287 * y [I] Y coordinate of the boundary rectangle
288 * width [I] Width of the boundary rectangle
289 * height [I] Height of the boundary rectangle
290 * startAngle [I] Starting angle of the arc, clockwise
291 * sweepAngle [I] Angle of the arc, clockwise
293 * RETURNS
294 * InvalidParameter If the given path is invalid
295 * OutOfMemory If memory allocation fails, i.e. the path cannot be lengthened
296 * Ok If everything works out as expected
298 * NOTES
299 * This functions takes the newfigure value of the given path into account,
300 * i.e. the arc is connected to the end of the given path if it was set to
301 * FALSE, otherwise the arc's first point gets the PathPointTypeStart value.
302 * In both cases, the value of newfigure of the given path is FALSE
303 * afterwards.
305 GpStatus WINGDIPAPI GdipAddPathArc(GpPath *path, REAL x, REAL y, REAL width,
306 REAL height, REAL startAngle, REAL sweepAngle)
308 GpPointF *points;
309 GpStatus status;
310 INT count;
312 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
313 path, x, y, width, height, startAngle, sweepAngle);
315 if(!path || width <= 0.0f || height <= 0.0f)
316 return InvalidParameter;
318 count = arc2polybezier(NULL, x, y, width, height, startAngle, sweepAngle);
319 if(count == 0)
320 return Ok;
322 points = heap_alloc_zero(sizeof(GpPointF)*count);
323 if(!points)
324 return OutOfMemory;
326 arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
328 status = extend_current_figure(path, points, count, PathPointTypeBezier);
330 heap_free(points);
331 return status;
334 /*******************************************************************************
335 * GdipAddPathArcI [GDUPLUS.2]
337 * See GdipAddPathArc
339 GpStatus WINGDIPAPI GdipAddPathArcI(GpPath *path, INT x1, INT y1, INT x2,
340 INT y2, REAL startAngle, REAL sweepAngle)
342 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
343 path, x1, y1, x2, y2, startAngle, sweepAngle);
345 return GdipAddPathArc(path,(REAL)x1,(REAL)y1,(REAL)x2,(REAL)y2,startAngle,sweepAngle);
348 GpStatus WINGDIPAPI GdipAddPathBezier(GpPath *path, REAL x1, REAL y1, REAL x2,
349 REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
351 PointF points[4];
353 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
354 path, x1, y1, x2, y2, x3, y3, x4, y4);
356 if(!path)
357 return InvalidParameter;
359 points[0].X = x1;
360 points[0].Y = y1;
361 points[1].X = x2;
362 points[1].Y = y2;
363 points[2].X = x3;
364 points[2].Y = y3;
365 points[3].X = x4;
366 points[3].Y = y4;
368 return extend_current_figure(path, points, 4, PathPointTypeBezier);
371 GpStatus WINGDIPAPI GdipAddPathBezierI(GpPath *path, INT x1, INT y1, INT x2,
372 INT y2, INT x3, INT y3, INT x4, INT y4)
374 TRACE("(%p, %d, %d, %d, %d, %d, %d, %d, %d)\n",
375 path, x1, y1, x2, y2, x3, y3, x4, y4);
377 return GdipAddPathBezier(path,(REAL)x1,(REAL)y1,(REAL)x2,(REAL)y2,(REAL)x3,(REAL)y3,
378 (REAL)x4,(REAL)y4);
381 GpStatus WINGDIPAPI GdipAddPathBeziers(GpPath *path, GDIPCONST GpPointF *points,
382 INT count)
384 TRACE("(%p, %p, %d)\n", path, points, count);
386 if(!path || !points || ((count - 1) % 3))
387 return InvalidParameter;
389 return extend_current_figure(path, points, count, PathPointTypeBezier);
392 GpStatus WINGDIPAPI GdipAddPathBeziersI(GpPath *path, GDIPCONST GpPoint *points,
393 INT count)
395 GpPointF *ptsF;
396 GpStatus ret;
397 INT i;
399 TRACE("(%p, %p, %d)\n", path, points, count);
401 if(!points || ((count - 1) % 3))
402 return InvalidParameter;
404 ptsF = heap_alloc_zero(sizeof(GpPointF) * count);
405 if(!ptsF)
406 return OutOfMemory;
408 for(i = 0; i < count; i++){
409 ptsF[i].X = (REAL)points[i].X;
410 ptsF[i].Y = (REAL)points[i].Y;
413 ret = GdipAddPathBeziers(path, ptsF, count);
414 heap_free(ptsF);
416 return ret;
419 GpStatus WINGDIPAPI GdipAddPathClosedCurve(GpPath *path, GDIPCONST GpPointF *points,
420 INT count)
422 TRACE("(%p, %p, %d)\n", path, points, count);
424 return GdipAddPathClosedCurve2(path, points, count, 1.0);
427 GpStatus WINGDIPAPI GdipAddPathClosedCurveI(GpPath *path, GDIPCONST GpPoint *points,
428 INT count)
430 TRACE("(%p, %p, %d)\n", path, points, count);
432 return GdipAddPathClosedCurve2I(path, points, count, 1.0);
435 GpStatus WINGDIPAPI GdipAddPathClosedCurve2(GpPath *path, GDIPCONST GpPointF *points,
436 INT count, REAL tension)
438 INT i, len_pt = (count + 1)*3-2;
439 GpPointF *pt;
440 GpPointF *pts;
441 REAL x1, x2, y1, y2;
442 GpStatus stat;
444 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
446 if(!path || !points || count <= 1)
447 return InvalidParameter;
449 pt = heap_alloc_zero(len_pt * sizeof(GpPointF));
450 pts = heap_alloc_zero((count + 1)*sizeof(GpPointF));
451 if(!pt || !pts){
452 heap_free(pt);
453 heap_free(pts);
454 return OutOfMemory;
457 /* copy source points to extend with the last one */
458 memcpy(pts, points, sizeof(GpPointF)*count);
459 pts[count] = pts[0];
461 tension = tension * TENSION_CONST;
463 for(i = 0; i < count-1; i++){
464 calc_curve_bezier(&(pts[i]), tension, &x1, &y1, &x2, &y2);
466 pt[3*i+2].X = x1;
467 pt[3*i+2].Y = y1;
468 pt[3*i+3].X = pts[i+1].X;
469 pt[3*i+3].Y = pts[i+1].Y;
470 pt[3*i+4].X = x2;
471 pt[3*i+4].Y = y2;
474 /* points [len_pt-2] and [0] are calculated
475 separately to connect splines properly */
476 pts[0] = points[count-1];
477 pts[1] = points[0]; /* equals to start and end of a resulting path */
478 pts[2] = points[1];
480 calc_curve_bezier(pts, tension, &x1, &y1, &x2, &y2);
481 pt[len_pt-2].X = x1;
482 pt[len_pt-2].Y = y1;
483 pt[0].X = pts[1].X;
484 pt[0].Y = pts[1].Y;
485 pt[1].X = x2;
486 pt[1].Y = y2;
487 /* close path */
488 pt[len_pt-1].X = pt[0].X;
489 pt[len_pt-1].Y = pt[0].Y;
491 stat = extend_current_figure(path, pt, len_pt, PathPointTypeBezier);
493 /* close figure */
494 if(stat == Ok){
495 path->pathdata.Types[path->pathdata.Count - 1] |= PathPointTypeCloseSubpath;
496 path->newfigure = TRUE;
499 heap_free(pts);
500 heap_free(pt);
502 return stat;
505 GpStatus WINGDIPAPI GdipAddPathClosedCurve2I(GpPath *path, GDIPCONST GpPoint *points,
506 INT count, REAL tension)
508 GpPointF *ptf;
509 INT i;
510 GpStatus stat;
512 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
514 if(!path || !points || count <= 1)
515 return InvalidParameter;
517 ptf = heap_alloc_zero(sizeof(GpPointF)*count);
518 if(!ptf)
519 return OutOfMemory;
521 for(i = 0; i < count; i++){
522 ptf[i].X = (REAL)points[i].X;
523 ptf[i].Y = (REAL)points[i].Y;
526 stat = GdipAddPathClosedCurve2(path, ptf, count, tension);
528 heap_free(ptf);
530 return stat;
533 GpStatus WINGDIPAPI GdipAddPathCurve(GpPath *path, GDIPCONST GpPointF *points, INT count)
535 TRACE("(%p, %p, %d)\n", path, points, count);
537 if(!path || !points || count <= 1)
538 return InvalidParameter;
540 return GdipAddPathCurve2(path, points, count, 1.0);
543 GpStatus WINGDIPAPI GdipAddPathCurveI(GpPath *path, GDIPCONST GpPoint *points, INT count)
545 TRACE("(%p, %p, %d)\n", path, points, count);
547 if(!path || !points || count <= 1)
548 return InvalidParameter;
550 return GdipAddPathCurve2I(path, points, count, 1.0);
553 GpStatus WINGDIPAPI GdipAddPathCurve2(GpPath *path, GDIPCONST GpPointF *points, INT count,
554 REAL tension)
556 INT i, len_pt = count*3-2;
557 GpPointF *pt;
558 REAL x1, x2, y1, y2;
559 GpStatus stat;
561 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
563 if(!path || !points || count <= 1)
564 return InvalidParameter;
566 pt = heap_alloc_zero(len_pt * sizeof(GpPointF));
567 if(!pt)
568 return OutOfMemory;
570 tension = tension * TENSION_CONST;
572 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
573 tension, &x1, &y1);
575 pt[0].X = points[0].X;
576 pt[0].Y = points[0].Y;
577 pt[1].X = x1;
578 pt[1].Y = y1;
580 for(i = 0; i < count-2; i++){
581 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
583 pt[3*i+2].X = x1;
584 pt[3*i+2].Y = y1;
585 pt[3*i+3].X = points[i+1].X;
586 pt[3*i+3].Y = points[i+1].Y;
587 pt[3*i+4].X = x2;
588 pt[3*i+4].Y = y2;
591 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
592 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
594 pt[len_pt-2].X = x1;
595 pt[len_pt-2].Y = y1;
596 pt[len_pt-1].X = points[count-1].X;
597 pt[len_pt-1].Y = points[count-1].Y;
599 stat = extend_current_figure(path, pt, len_pt, PathPointTypeBezier);
601 heap_free(pt);
603 return stat;
606 GpStatus WINGDIPAPI GdipAddPathCurve2I(GpPath *path, GDIPCONST GpPoint *points,
607 INT count, REAL tension)
609 GpPointF *ptf;
610 INT i;
611 GpStatus stat;
613 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
615 if(!path || !points || count <= 1)
616 return InvalidParameter;
618 ptf = heap_alloc_zero(sizeof(GpPointF)*count);
619 if(!ptf)
620 return OutOfMemory;
622 for(i = 0; i < count; i++){
623 ptf[i].X = (REAL)points[i].X;
624 ptf[i].Y = (REAL)points[i].Y;
627 stat = GdipAddPathCurve2(path, ptf, count, tension);
629 heap_free(ptf);
631 return stat;
634 GpStatus WINGDIPAPI GdipAddPathCurve3(GpPath *path, GDIPCONST GpPointF *points,
635 INT count, INT offset, INT nseg, REAL tension)
637 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path, points, count, offset, nseg, tension);
639 if(!path || !points || offset + 1 >= count || count - offset < nseg + 1)
640 return InvalidParameter;
642 return GdipAddPathCurve2(path, &points[offset], nseg + 1, tension);
645 GpStatus WINGDIPAPI GdipAddPathCurve3I(GpPath *path, GDIPCONST GpPoint *points,
646 INT count, INT offset, INT nseg, REAL tension)
648 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path, points, count, offset, nseg, tension);
650 if(!path || !points || offset + 1 >= count || count - offset < nseg + 1)
651 return InvalidParameter;
653 return GdipAddPathCurve2I(path, &points[offset], nseg + 1, tension);
656 GpStatus WINGDIPAPI GdipAddPathEllipse(GpPath *path, REAL x, REAL y, REAL width,
657 REAL height)
659 INT old_count, numpts;
661 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x, y, width, height);
663 if(!path)
664 return InvalidParameter;
666 if(!lengthen_path(path, MAX_ARC_PTS))
667 return OutOfMemory;
669 old_count = path->pathdata.Count;
670 if((numpts = arc2polybezier(&path->pathdata.Points[old_count], x, y, width,
671 height, 0.0, 360.0)) != MAX_ARC_PTS){
672 ERR("expected %d points but got %d\n", MAX_ARC_PTS, numpts);
673 return GenericError;
676 memset(&path->pathdata.Types[old_count + 1], PathPointTypeBezier,
677 MAX_ARC_PTS - 1);
679 /* An ellipse is an intrinsic figure (always is its own subpath). */
680 path->pathdata.Types[old_count] = PathPointTypeStart;
681 path->pathdata.Types[old_count + MAX_ARC_PTS - 1] |= PathPointTypeCloseSubpath;
682 path->newfigure = TRUE;
683 path->pathdata.Count += MAX_ARC_PTS;
685 return Ok;
688 GpStatus WINGDIPAPI GdipAddPathEllipseI(GpPath *path, INT x, INT y, INT width,
689 INT height)
691 TRACE("(%p, %d, %d, %d, %d)\n", path, x, y, width, height);
693 return GdipAddPathEllipse(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
696 GpStatus WINGDIPAPI GdipAddPathLine2(GpPath *path, GDIPCONST GpPointF *points,
697 INT count)
699 TRACE("(%p, %p, %d)\n", path, points, count);
701 if(!path || !points || count < 1)
702 return InvalidParameter;
704 return extend_current_figure(path, points, count, PathPointTypeLine);
707 GpStatus WINGDIPAPI GdipAddPathLine2I(GpPath *path, GDIPCONST GpPoint *points, INT count)
709 GpPointF *pointsF;
710 INT i;
711 GpStatus stat;
713 TRACE("(%p, %p, %d)\n", path, points, count);
715 if(count <= 0)
716 return InvalidParameter;
718 pointsF = heap_alloc_zero(sizeof(GpPointF) * count);
719 if(!pointsF) return OutOfMemory;
721 for(i = 0;i < count; i++){
722 pointsF[i].X = (REAL)points[i].X;
723 pointsF[i].Y = (REAL)points[i].Y;
726 stat = GdipAddPathLine2(path, pointsF, count);
728 heap_free(pointsF);
730 return stat;
733 /*************************************************************************
734 * GdipAddPathLine [GDIPLUS.21]
736 * Add two points to the given path.
738 * PARAMS
739 * path [I/O] Path that the line is appended to
740 * x1 [I] X coordinate of the first point of the line
741 * y1 [I] Y coordinate of the first point of the line
742 * x2 [I] X coordinate of the second point of the line
743 * y2 [I] Y coordinate of the second point of the line
745 * RETURNS
746 * InvalidParameter If the first parameter is not a valid path
747 * OutOfMemory If the path cannot be lengthened, i.e. memory allocation fails
748 * Ok If everything works out as expected
750 * NOTES
751 * This functions takes the newfigure value of the given path into account,
752 * i.e. the two new points are connected to the end of the given path if it
753 * was set to FALSE, otherwise the first point is given the PathPointTypeStart
754 * value. In both cases, the value of newfigure of the given path is FALSE
755 * afterwards.
757 GpStatus WINGDIPAPI GdipAddPathLine(GpPath *path, REAL x1, REAL y1, REAL x2, REAL y2)
759 PointF points[2];
761 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x1, y1, x2, y2);
763 if(!path)
764 return InvalidParameter;
766 points[0].X = x1;
767 points[0].Y = y1;
768 points[1].X = x2;
769 points[1].Y = y2;
771 return extend_current_figure(path, points, 2, PathPointTypeLine);
774 /*************************************************************************
775 * GdipAddPathLineI [GDIPLUS.21]
777 * See GdipAddPathLine
779 GpStatus WINGDIPAPI GdipAddPathLineI(GpPath *path, INT x1, INT y1, INT x2, INT y2)
781 TRACE("(%p, %d, %d, %d, %d)\n", path, x1, y1, x2, y2);
783 return GdipAddPathLine(path, (REAL)x1, (REAL)y1, (REAL)x2, (REAL)y2);
786 GpStatus WINGDIPAPI GdipAddPathPath(GpPath *path, GDIPCONST GpPath* addingPath,
787 BOOL connect)
789 INT old_count, count;
791 TRACE("(%p, %p, %d)\n", path, addingPath, connect);
793 if(!path || !addingPath)
794 return InvalidParameter;
796 old_count = path->pathdata.Count;
797 count = addingPath->pathdata.Count;
799 if(!lengthen_path(path, count))
800 return OutOfMemory;
802 memcpy(&path->pathdata.Points[old_count], addingPath->pathdata.Points,
803 count * sizeof(GpPointF));
804 memcpy(&path->pathdata.Types[old_count], addingPath->pathdata.Types, count);
806 if(path->newfigure || !connect)
807 path->pathdata.Types[old_count] = PathPointTypeStart;
808 else
809 path->pathdata.Types[old_count] = PathPointTypeLine;
811 path->newfigure = FALSE;
812 path->pathdata.Count += count;
814 return Ok;
817 GpStatus WINGDIPAPI GdipAddPathPie(GpPath *path, REAL x, REAL y, REAL width, REAL height,
818 REAL startAngle, REAL sweepAngle)
820 GpPointF *ptf;
821 GpStatus status;
822 INT i, count;
824 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
825 path, x, y, width, height, startAngle, sweepAngle);
827 if(!path)
828 return InvalidParameter;
830 /* on zero width/height only start point added */
831 if(width <= 1e-7 || height <= 1e-7){
832 if(!lengthen_path(path, 1))
833 return OutOfMemory;
834 path->pathdata.Points[0].X = x + width / 2.0;
835 path->pathdata.Points[0].Y = y + height / 2.0;
836 path->pathdata.Types[0] = PathPointTypeStart | PathPointTypeCloseSubpath;
837 path->pathdata.Count = 1;
838 return InvalidParameter;
841 count = arc2polybezier(NULL, x, y, width, height, startAngle, sweepAngle);
843 if(count == 0)
844 return Ok;
846 ptf = heap_alloc_zero(sizeof(GpPointF)*count);
847 if(!ptf)
848 return OutOfMemory;
850 arc2polybezier(ptf, x, y, width, height, startAngle, sweepAngle);
852 status = GdipAddPathLine(path, x + width/2, y + height/2, ptf[0].X, ptf[0].Y);
853 if(status != Ok){
854 heap_free(ptf);
855 return status;
857 /* one spline is already added as a line endpoint */
858 if(!lengthen_path(path, count - 1)){
859 heap_free(ptf);
860 return OutOfMemory;
863 memcpy(&(path->pathdata.Points[path->pathdata.Count]), &(ptf[1]),sizeof(GpPointF)*(count-1));
864 for(i = 0; i < count-1; i++)
865 path->pathdata.Types[path->pathdata.Count+i] = PathPointTypeBezier;
867 path->pathdata.Count += count-1;
869 GdipClosePathFigure(path);
871 heap_free(ptf);
873 return status;
876 GpStatus WINGDIPAPI GdipAddPathPieI(GpPath *path, INT x, INT y, INT width, INT height,
877 REAL startAngle, REAL sweepAngle)
879 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
880 path, x, y, width, height, startAngle, sweepAngle);
882 return GdipAddPathPie(path, (REAL)x, (REAL)y, (REAL)width, (REAL)height, startAngle, sweepAngle);
885 GpStatus WINGDIPAPI GdipAddPathPolygon(GpPath *path, GDIPCONST GpPointF *points, INT count)
887 INT old_count;
889 TRACE("(%p, %p, %d)\n", path, points, count);
891 if(!path || !points || count < 3)
892 return InvalidParameter;
894 if(!lengthen_path(path, count))
895 return OutOfMemory;
897 old_count = path->pathdata.Count;
899 memcpy(&path->pathdata.Points[old_count], points, count*sizeof(GpPointF));
900 memset(&path->pathdata.Types[old_count + 1], PathPointTypeLine, count - 1);
902 /* A polygon is an intrinsic figure */
903 path->pathdata.Types[old_count] = PathPointTypeStart;
904 path->pathdata.Types[old_count + count - 1] |= PathPointTypeCloseSubpath;
905 path->newfigure = TRUE;
906 path->pathdata.Count += count;
908 return Ok;
911 GpStatus WINGDIPAPI GdipAddPathPolygonI(GpPath *path, GDIPCONST GpPoint *points, INT count)
913 GpPointF *ptf;
914 GpStatus status;
915 INT i;
917 TRACE("(%p, %p, %d)\n", path, points, count);
919 if(!points || count < 3)
920 return InvalidParameter;
922 ptf = heap_alloc_zero(sizeof(GpPointF) * count);
923 if(!ptf)
924 return OutOfMemory;
926 for(i = 0; i < count; i++){
927 ptf[i].X = (REAL)points[i].X;
928 ptf[i].Y = (REAL)points[i].Y;
931 status = GdipAddPathPolygon(path, ptf, count);
933 heap_free(ptf);
935 return status;
938 static float fromfixedpoint(const FIXED v)
940 float f = ((float)v.fract) / (1<<(sizeof(v.fract)*8));
941 f += v.value;
942 return f;
945 struct format_string_args
947 GpPath *path;
948 float maxY;
949 float scale;
950 float ascent;
953 static GpStatus format_string_callback(HDC dc,
954 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
955 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
956 INT lineno, const RectF *bounds, INT *underlined_indexes,
957 INT underlined_index_count, void *priv)
959 static const MAT2 identity = { {0,1}, {0,0}, {0,0}, {0,1} };
960 struct format_string_args *args = priv;
961 GpPath *path = args->path;
962 GpStatus status = Ok;
963 float x = rect->X + (bounds->X - rect->X) * args->scale;
964 float y = rect->Y + (bounds->Y - rect->Y) * args->scale;
965 int i;
967 if (underlined_index_count)
968 FIXME("hotkey underlines not drawn yet\n");
970 if (y + bounds->Height * args->scale > args->maxY)
971 args->maxY = y + bounds->Height * args->scale;
973 for (i = index; i < length + index; ++i)
975 GLYPHMETRICS gm;
976 TTPOLYGONHEADER *ph = NULL, *origph;
977 char *start;
978 DWORD len, ofs = 0;
979 len = GetGlyphOutlineW(dc, string[i], GGO_BEZIER, &gm, 0, NULL, &identity);
980 if (len == GDI_ERROR)
982 status = GenericError;
983 break;
985 origph = ph = heap_alloc_zero(len);
986 start = (char *)ph;
987 if (!ph || !lengthen_path(path, len / sizeof(POINTFX)))
989 heap_free(ph);
990 status = OutOfMemory;
991 break;
993 GetGlyphOutlineW(dc, string[i], GGO_BEZIER, &gm, len, start, &identity);
995 ofs = 0;
996 while (ofs < len)
998 DWORD ofs_start = ofs;
999 ph = (TTPOLYGONHEADER*)&start[ofs];
1000 path->pathdata.Types[path->pathdata.Count] = PathPointTypeStart;
1001 path->pathdata.Points[path->pathdata.Count].X = x + fromfixedpoint(ph->pfxStart.x) * args->scale;
1002 path->pathdata.Points[path->pathdata.Count++].Y = y + args->ascent - fromfixedpoint(ph->pfxStart.y) * args->scale;
1003 TRACE("Starting at count %i with pos %f, %f)\n", path->pathdata.Count, x, y);
1004 ofs += sizeof(*ph);
1005 while (ofs - ofs_start < ph->cb)
1007 TTPOLYCURVE *curve = (TTPOLYCURVE*)&start[ofs];
1008 int j;
1009 ofs += sizeof(TTPOLYCURVE) + (curve->cpfx - 1) * sizeof(POINTFX);
1011 switch (curve->wType)
1013 case TT_PRIM_LINE:
1014 for (j = 0; j < curve->cpfx; ++j)
1016 path->pathdata.Types[path->pathdata.Count] = PathPointTypeLine;
1017 path->pathdata.Points[path->pathdata.Count].X = x + fromfixedpoint(curve->apfx[j].x) * args->scale;
1018 path->pathdata.Points[path->pathdata.Count++].Y = y + args->ascent - fromfixedpoint(curve->apfx[j].y) * args->scale;
1020 break;
1021 case TT_PRIM_CSPLINE:
1022 for (j = 0; j < curve->cpfx; ++j)
1024 path->pathdata.Types[path->pathdata.Count] = PathPointTypeBezier;
1025 path->pathdata.Points[path->pathdata.Count].X = x + fromfixedpoint(curve->apfx[j].x) * args->scale;
1026 path->pathdata.Points[path->pathdata.Count++].Y = y + args->ascent - fromfixedpoint(curve->apfx[j].y) * args->scale;
1028 break;
1029 default:
1030 ERR("Unhandled type: %u\n", curve->wType);
1031 status = GenericError;
1034 path->pathdata.Types[path->pathdata.Count - 1] |= PathPointTypeCloseSubpath;
1036 path->newfigure = TRUE;
1037 x += gm.gmCellIncX * args->scale;
1038 y += gm.gmCellIncY * args->scale;
1040 heap_free(origph);
1041 if (status != Ok)
1042 break;
1045 return status;
1048 GpStatus WINGDIPAPI GdipAddPathString(GpPath* path, GDIPCONST WCHAR* string, INT length, GDIPCONST GpFontFamily* family, INT style, REAL emSize, GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat* format)
1050 GpFont *font;
1051 GpStatus status;
1052 LOGFONTW lfw;
1053 HANDLE hfont;
1054 HDC dc;
1055 GpGraphics *graphics;
1056 GpPath *backup;
1057 struct format_string_args args;
1058 int i;
1059 UINT16 native_height;
1060 RectF scaled_layout_rect;
1061 TEXTMETRICW textmetric;
1063 TRACE("(%p, %s, %d, %p, %d, %f, %p, %p)\n", path, debugstr_w(string), length, family, style, emSize, layoutRect, format);
1064 if (!path || !string || !family || !emSize || !layoutRect)
1065 return InvalidParameter;
1067 if (!format)
1068 format = &default_drawstring_format;
1070 status = GdipGetEmHeight(family, style, &native_height);
1071 if (status != Ok)
1072 return status;
1074 scaled_layout_rect.X = layoutRect->X;
1075 scaled_layout_rect.Y = layoutRect->Y;
1076 scaled_layout_rect.Width = layoutRect->Width * native_height / emSize;
1077 scaled_layout_rect.Height = layoutRect->Height * native_height / emSize;
1079 if ((status = GdipClonePath(path, &backup)) != Ok)
1080 return status;
1082 dc = CreateCompatibleDC(0);
1083 status = GdipCreateFromHDC(dc, &graphics);
1084 if (status != Ok)
1086 DeleteDC(dc);
1087 GdipDeletePath(backup);
1088 return status;
1091 status = GdipCreateFont(family, native_height, style, UnitPixel, &font);
1092 if (status != Ok)
1094 GdipDeleteGraphics(graphics);
1095 DeleteDC(dc);
1096 GdipDeletePath(backup);
1097 return status;
1100 get_log_fontW(font, graphics, &lfw);
1101 GdipDeleteFont(font);
1102 GdipDeleteGraphics(graphics);
1104 hfont = CreateFontIndirectW(&lfw);
1105 if (!hfont)
1107 WARN("Failed to create font\n");
1108 DeleteDC(dc);
1109 GdipDeletePath(backup);
1110 return GenericError;
1113 SelectObject(dc, hfont);
1115 GetTextMetricsW(dc, &textmetric);
1117 args.path = path;
1118 args.maxY = 0;
1119 args.scale = emSize / native_height;
1120 args.ascent = textmetric.tmAscent * args.scale;
1121 status = gdip_format_string(dc, string, length, NULL, &scaled_layout_rect,
1122 format, TRUE, format_string_callback, &args);
1124 DeleteDC(dc);
1125 DeleteObject(hfont);
1127 if (status != Ok) /* free backup */
1129 heap_free(path->pathdata.Points);
1130 heap_free(path->pathdata.Types);
1131 *path = *backup;
1132 heap_free(backup);
1133 return status;
1135 if (format->line_align == StringAlignmentCenter && layoutRect->Y + args.maxY < layoutRect->Height)
1137 float inc = layoutRect->Height + layoutRect->Y - args.maxY;
1138 inc /= 2;
1139 for (i = backup->pathdata.Count; i < path->pathdata.Count; ++i)
1140 path->pathdata.Points[i].Y += inc;
1141 } else if (format->line_align == StringAlignmentFar) {
1142 float inc = layoutRect->Height + layoutRect->Y - args.maxY;
1143 for (i = backup->pathdata.Count; i < path->pathdata.Count; ++i)
1144 path->pathdata.Points[i].Y += inc;
1146 GdipDeletePath(backup);
1147 return status;
1150 GpStatus WINGDIPAPI GdipAddPathStringI(GpPath* path, GDIPCONST WCHAR* string, INT length, GDIPCONST GpFontFamily* family,
1151 INT style, REAL emSize, GDIPCONST Rect* layoutRect, GDIPCONST GpStringFormat* format)
1153 RectF rect;
1155 if (!layoutRect)
1156 return InvalidParameter;
1158 set_rect(&rect, layoutRect->X, layoutRect->Y, layoutRect->Width, layoutRect->Height);
1159 return GdipAddPathString(path, string, length, family, style, emSize, &rect, format);
1162 /*************************************************************************
1163 * GdipClonePath [GDIPLUS.53]
1165 * Duplicate the given path in memory.
1167 * PARAMS
1168 * path [I] The path to be duplicated
1169 * clone [O] Pointer to the new path
1171 * RETURNS
1172 * InvalidParameter If the input path is invalid
1173 * OutOfMemory If allocation of needed memory fails
1174 * Ok If everything works out as expected
1176 GpStatus WINGDIPAPI GdipClonePath(GpPath* path, GpPath **clone)
1178 TRACE("(%p, %p)\n", path, clone);
1180 if(!path || !clone)
1181 return InvalidParameter;
1183 *clone = heap_alloc_zero(sizeof(GpPath));
1184 if(!*clone) return OutOfMemory;
1186 **clone = *path;
1188 (*clone)->pathdata.Points = heap_alloc_zero(path->datalen * sizeof(PointF));
1189 (*clone)->pathdata.Types = heap_alloc_zero(path->datalen);
1190 if(!(*clone)->pathdata.Points || !(*clone)->pathdata.Types){
1191 heap_free((*clone)->pathdata.Points);
1192 heap_free((*clone)->pathdata.Types);
1193 heap_free(*clone);
1194 return OutOfMemory;
1197 memcpy((*clone)->pathdata.Points, path->pathdata.Points,
1198 path->datalen * sizeof(PointF));
1199 memcpy((*clone)->pathdata.Types, path->pathdata.Types, path->datalen);
1201 return Ok;
1204 GpStatus WINGDIPAPI GdipClosePathFigure(GpPath* path)
1206 TRACE("(%p)\n", path);
1208 if(!path)
1209 return InvalidParameter;
1211 if(path->pathdata.Count > 0){
1212 path->pathdata.Types[path->pathdata.Count - 1] |= PathPointTypeCloseSubpath;
1213 path->newfigure = TRUE;
1216 return Ok;
1219 GpStatus WINGDIPAPI GdipClosePathFigures(GpPath* path)
1221 INT i;
1223 TRACE("(%p)\n", path);
1225 if(!path)
1226 return InvalidParameter;
1228 for(i = 1; i < path->pathdata.Count; i++){
1229 if(path->pathdata.Types[i] == PathPointTypeStart)
1230 path->pathdata.Types[i-1] |= PathPointTypeCloseSubpath;
1233 path->newfigure = TRUE;
1235 return Ok;
1238 GpStatus WINGDIPAPI GdipCreatePath(GpFillMode fill, GpPath **path)
1240 TRACE("(%d, %p)\n", fill, path);
1242 if(!path)
1243 return InvalidParameter;
1245 *path = heap_alloc_zero(sizeof(GpPath));
1246 if(!*path) return OutOfMemory;
1248 (*path)->fill = fill;
1249 (*path)->newfigure = TRUE;
1251 return Ok;
1254 GpStatus WINGDIPAPI GdipCreatePath2(GDIPCONST GpPointF* points,
1255 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
1257 int i;
1259 TRACE("(%p, %p, %d, %d, %p)\n", points, types, count, fill, path);
1261 if(!points || !types || !path)
1262 return InvalidParameter;
1264 if(count <= 0) {
1265 *path = NULL;
1266 return OutOfMemory;
1269 *path = heap_alloc_zero(sizeof(GpPath));
1270 if(!*path) return OutOfMemory;
1272 if(count > 1 && (types[count-1] & PathPointTypePathTypeMask) == PathPointTypeStart)
1273 count = 0;
1275 for(i = 1; i < count; i++) {
1276 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier) {
1277 if(i+2 < count &&
1278 (types[i+1] & PathPointTypePathTypeMask) == PathPointTypeBezier &&
1279 (types[i+2] & PathPointTypePathTypeMask) == PathPointTypeBezier)
1280 i += 2;
1281 else {
1282 count = 0;
1283 break;
1288 (*path)->pathdata.Points = heap_alloc_zero(count * sizeof(PointF));
1289 (*path)->pathdata.Types = heap_alloc_zero(count);
1291 if(!(*path)->pathdata.Points || !(*path)->pathdata.Types){
1292 heap_free((*path)->pathdata.Points);
1293 heap_free((*path)->pathdata.Types);
1294 heap_free(*path);
1295 return OutOfMemory;
1298 memcpy((*path)->pathdata.Points, points, count * sizeof(PointF));
1299 memcpy((*path)->pathdata.Types, types, count);
1300 if(count > 0)
1301 (*path)->pathdata.Types[0] = PathPointTypeStart;
1302 (*path)->pathdata.Count = count;
1303 (*path)->datalen = count;
1305 (*path)->fill = fill;
1306 (*path)->newfigure = TRUE;
1308 return Ok;
1311 GpStatus WINGDIPAPI GdipCreatePath2I(GDIPCONST GpPoint* points,
1312 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
1314 GpPointF *ptF;
1315 GpStatus ret;
1316 INT i;
1318 TRACE("(%p, %p, %d, %d, %p)\n", points, types, count, fill, path);
1320 ptF = heap_alloc_zero(sizeof(GpPointF)*count);
1322 for(i = 0;i < count; i++){
1323 ptF[i].X = (REAL)points[i].X;
1324 ptF[i].Y = (REAL)points[i].Y;
1327 ret = GdipCreatePath2(ptF, types, count, fill, path);
1329 heap_free(ptF);
1331 return ret;
1334 GpStatus WINGDIPAPI GdipDeletePath(GpPath *path)
1336 TRACE("(%p)\n", path);
1338 if(!path)
1339 return InvalidParameter;
1341 heap_free(path->pathdata.Points);
1342 heap_free(path->pathdata.Types);
1343 heap_free(path);
1345 return Ok;
1348 GpStatus WINGDIPAPI GdipFlattenPath(GpPath *path, GpMatrix* matrix, REAL flatness)
1350 path_list_node_t *list, *node;
1351 GpPointF pt;
1352 INT i = 1;
1353 INT startidx = 0;
1354 GpStatus stat;
1356 TRACE("(%p, %p, %.2f)\n", path, matrix, flatness);
1358 if(!path)
1359 return InvalidParameter;
1361 if(path->pathdata.Count == 0)
1362 return Ok;
1364 stat = GdipTransformPath(path, matrix);
1365 if(stat != Ok)
1366 return stat;
1368 pt = path->pathdata.Points[0];
1369 if(!init_path_list(&list, pt.X, pt.Y))
1370 return OutOfMemory;
1372 node = list;
1374 while(i < path->pathdata.Count){
1376 BYTE type = path->pathdata.Types[i] & PathPointTypePathTypeMask;
1377 path_list_node_t *start;
1379 pt = path->pathdata.Points[i];
1381 /* save last start point index */
1382 if(type == PathPointTypeStart)
1383 startidx = i;
1385 /* always add line points and start points */
1386 if((type == PathPointTypeStart) || (type == PathPointTypeLine)){
1387 if(!add_path_list_node(node, pt.X, pt.Y, path->pathdata.Types[i]))
1388 goto memout;
1390 node = node->next;
1391 ++i;
1392 continue;
1395 /* Bezier curve */
1397 /* test for closed figure */
1398 if(path->pathdata.Types[i+1] & PathPointTypeCloseSubpath){
1399 pt = path->pathdata.Points[startidx];
1400 ++i;
1402 else
1404 i += 2;
1405 pt = path->pathdata.Points[i];
1408 start = node;
1409 /* add Bezier end point */
1410 type = (path->pathdata.Types[i] & ~PathPointTypePathTypeMask) | PathPointTypeLine;
1411 if(!add_path_list_node(node, pt.X, pt.Y, type))
1412 goto memout;
1413 node = node->next;
1415 /* flatten curve */
1416 if(!flatten_bezier(start, path->pathdata.Points[i-2].X, path->pathdata.Points[i-2].Y,
1417 path->pathdata.Points[i-1].X, path->pathdata.Points[i-1].Y,
1418 node, flatness))
1419 goto memout;
1421 ++i;
1422 }/* while */
1424 /* store path data back */
1425 i = path_list_count(list);
1426 if(!lengthen_path(path, i))
1427 goto memout;
1428 path->pathdata.Count = i;
1430 node = list;
1431 for(i = 0; i < path->pathdata.Count; i++){
1432 path->pathdata.Points[i] = node->pt;
1433 path->pathdata.Types[i] = node->type;
1434 node = node->next;
1437 free_path_list(list);
1438 return Ok;
1440 memout:
1441 free_path_list(list);
1442 return OutOfMemory;
1445 GpStatus WINGDIPAPI GdipGetPathData(GpPath *path, GpPathData* pathData)
1447 TRACE("(%p, %p)\n", path, pathData);
1449 if(!path || !pathData)
1450 return InvalidParameter;
1452 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
1453 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
1454 memcpy(pathData->Points, path->pathdata.Points, sizeof(PointF) * pathData->Count);
1455 memcpy(pathData->Types , path->pathdata.Types , pathData->Count);
1457 return Ok;
1460 GpStatus WINGDIPAPI GdipGetPathFillMode(GpPath *path, GpFillMode *fillmode)
1462 TRACE("(%p, %p)\n", path, fillmode);
1464 if(!path || !fillmode)
1465 return InvalidParameter;
1467 *fillmode = path->fill;
1469 return Ok;
1472 GpStatus WINGDIPAPI GdipGetPathLastPoint(GpPath* path, GpPointF* lastPoint)
1474 INT count;
1476 TRACE("(%p, %p)\n", path, lastPoint);
1478 if(!path || !lastPoint)
1479 return InvalidParameter;
1481 count = path->pathdata.Count;
1482 if(count > 0)
1483 *lastPoint = path->pathdata.Points[count-1];
1485 return Ok;
1488 GpStatus WINGDIPAPI GdipGetPathPoints(GpPath *path, GpPointF* points, INT count)
1490 TRACE("(%p, %p, %d)\n", path, points, count);
1492 if(!path)
1493 return InvalidParameter;
1495 if(count < path->pathdata.Count)
1496 return InsufficientBuffer;
1498 memcpy(points, path->pathdata.Points, path->pathdata.Count * sizeof(GpPointF));
1500 return Ok;
1503 GpStatus WINGDIPAPI GdipGetPathPointsI(GpPath *path, GpPoint* points, INT count)
1505 GpStatus ret;
1506 GpPointF *ptf;
1507 INT i;
1509 TRACE("(%p, %p, %d)\n", path, points, count);
1511 if(count <= 0)
1512 return InvalidParameter;
1514 ptf = heap_alloc_zero(sizeof(GpPointF)*count);
1515 if(!ptf) return OutOfMemory;
1517 ret = GdipGetPathPoints(path,ptf,count);
1518 if(ret == Ok)
1519 for(i = 0;i < count;i++){
1520 points[i].X = gdip_round(ptf[i].X);
1521 points[i].Y = gdip_round(ptf[i].Y);
1523 heap_free(ptf);
1525 return ret;
1528 GpStatus WINGDIPAPI GdipGetPathTypes(GpPath *path, BYTE* types, INT count)
1530 TRACE("(%p, %p, %d)\n", path, types, count);
1532 if(!path)
1533 return InvalidParameter;
1535 if(count < path->pathdata.Count)
1536 return InsufficientBuffer;
1538 memcpy(types, path->pathdata.Types, path->pathdata.Count);
1540 return Ok;
1543 /* Windows expands the bounding box to the maximum possible bounding box
1544 * for a given pen. For example, if a line join can extend past the point
1545 * it's joining by x units, the bounding box is extended by x units in every
1546 * direction (even though this is too conservative for most cases). */
1547 GpStatus WINGDIPAPI GdipGetPathWorldBounds(GpPath* path, GpRectF* bounds,
1548 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
1550 GpPointF * points, temp_pts[4];
1551 INT count, i;
1552 REAL path_width = 1.0, width, height, temp, low_x, low_y, high_x, high_y;
1554 TRACE("(%p, %p, %s, %p)\n", path, bounds, debugstr_matrix(matrix), pen);
1556 /* Matrix and pen can be null. */
1557 if(!path || !bounds)
1558 return InvalidParameter;
1560 /* If path is empty just return. */
1561 count = path->pathdata.Count;
1562 if(count == 0){
1563 bounds->X = bounds->Y = bounds->Width = bounds->Height = 0.0;
1564 return Ok;
1567 points = path->pathdata.Points;
1569 low_x = high_x = points[0].X;
1570 low_y = high_y = points[0].Y;
1572 for(i = 1; i < count; i++){
1573 low_x = min(low_x, points[i].X);
1574 low_y = min(low_y, points[i].Y);
1575 high_x = max(high_x, points[i].X);
1576 high_y = max(high_y, points[i].Y);
1579 width = high_x - low_x;
1580 height = high_y - low_y;
1582 /* This looks unusual but it's the only way I can imitate windows. */
1583 if(matrix){
1584 temp_pts[0].X = low_x;
1585 temp_pts[0].Y = low_y;
1586 temp_pts[1].X = low_x;
1587 temp_pts[1].Y = high_y;
1588 temp_pts[2].X = high_x;
1589 temp_pts[2].Y = high_y;
1590 temp_pts[3].X = high_x;
1591 temp_pts[3].Y = low_y;
1593 GdipTransformMatrixPoints((GpMatrix*)matrix, temp_pts, 4);
1594 low_x = temp_pts[0].X;
1595 low_y = temp_pts[0].Y;
1597 for(i = 1; i < 4; i++){
1598 low_x = min(low_x, temp_pts[i].X);
1599 low_y = min(low_y, temp_pts[i].Y);
1602 temp = width;
1603 width = height * fabs(matrix->matrix[2]) + width * fabs(matrix->matrix[0]);
1604 height = height * fabs(matrix->matrix[3]) + temp * fabs(matrix->matrix[1]);
1607 if(pen){
1608 path_width = pen->width / 2.0;
1610 if(count > 2)
1611 path_width = max(path_width, pen->width * pen->miterlimit / 2.0);
1612 /* FIXME: this should probably also check for the startcap */
1613 if(pen->endcap & LineCapNoAnchor)
1614 path_width = max(path_width, pen->width * 2.2);
1616 low_x -= path_width;
1617 low_y -= path_width;
1618 width += 2.0 * path_width;
1619 height += 2.0 * path_width;
1622 bounds->X = low_x;
1623 bounds->Y = low_y;
1624 bounds->Width = width;
1625 bounds->Height = height;
1627 return Ok;
1630 GpStatus WINGDIPAPI GdipGetPathWorldBoundsI(GpPath* path, GpRect* bounds,
1631 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
1633 GpStatus ret;
1634 GpRectF boundsF;
1636 TRACE("(%p, %p, %s, %p)\n", path, bounds, debugstr_matrix(matrix), pen);
1638 ret = GdipGetPathWorldBounds(path,&boundsF,matrix,pen);
1640 if(ret == Ok){
1641 bounds->X = gdip_round(boundsF.X);
1642 bounds->Y = gdip_round(boundsF.Y);
1643 bounds->Width = gdip_round(boundsF.Width);
1644 bounds->Height = gdip_round(boundsF.Height);
1647 return ret;
1650 GpStatus WINGDIPAPI GdipGetPointCount(GpPath *path, INT *count)
1652 TRACE("(%p, %p)\n", path, count);
1654 if(!path)
1655 return InvalidParameter;
1657 *count = path->pathdata.Count;
1659 return Ok;
1662 GpStatus WINGDIPAPI GdipReversePath(GpPath* path)
1664 INT i, count;
1665 INT start = 0; /* position in reversed path */
1666 GpPathData revpath;
1668 TRACE("(%p)\n", path);
1670 if(!path)
1671 return InvalidParameter;
1673 count = path->pathdata.Count;
1675 if(count == 0) return Ok;
1677 revpath.Points = heap_alloc_zero(sizeof(GpPointF)*count);
1678 revpath.Types = heap_alloc_zero(sizeof(BYTE)*count);
1679 revpath.Count = count;
1680 if(!revpath.Points || !revpath.Types){
1681 heap_free(revpath.Points);
1682 heap_free(revpath.Types);
1683 return OutOfMemory;
1686 for(i = 0; i < count; i++){
1688 /* find next start point */
1689 if(path->pathdata.Types[count-i-1] == PathPointTypeStart){
1690 INT j;
1691 for(j = start; j <= i; j++){
1692 revpath.Points[j] = path->pathdata.Points[count-j-1];
1693 revpath.Types[j] = path->pathdata.Types[count-j-1];
1695 /* mark start point */
1696 revpath.Types[start] = PathPointTypeStart;
1697 /* set 'figure' endpoint type */
1698 if(i-start > 1){
1699 revpath.Types[i] = path->pathdata.Types[count-start-1] & ~PathPointTypePathTypeMask;
1700 revpath.Types[i] |= revpath.Types[i-1];
1702 else
1703 revpath.Types[i] = path->pathdata.Types[start];
1705 start = i+1;
1709 memcpy(path->pathdata.Points, revpath.Points, sizeof(GpPointF)*count);
1710 memcpy(path->pathdata.Types, revpath.Types, sizeof(BYTE)*count);
1712 heap_free(revpath.Points);
1713 heap_free(revpath.Types);
1715 return Ok;
1718 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPointI(GpPath* path, INT x, INT y,
1719 GpPen *pen, GpGraphics *graphics, BOOL *result)
1721 TRACE("(%p, %d, %d, %p, %p, %p)\n", path, x, y, pen, graphics, result);
1723 return GdipIsOutlineVisiblePathPoint(path, x, y, pen, graphics, result);
1726 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPoint(GpPath* path, REAL x, REAL y,
1727 GpPen *pen, GpGraphics *graphics, BOOL *result)
1729 GpStatus stat;
1730 GpPath *wide_path;
1731 GpMatrix *transform = NULL;
1733 TRACE("(%p,%0.2f,%0.2f,%p,%p,%p)\n", path, x, y, pen, graphics, result);
1735 if(!path || !pen)
1736 return InvalidParameter;
1738 stat = GdipClonePath(path, &wide_path);
1740 if (stat != Ok)
1741 return stat;
1743 if (pen->unit == UnitPixel && graphics != NULL)
1745 stat = GdipCreateMatrix(&transform);
1747 if (stat == Ok)
1748 stat = get_graphics_transform(graphics, CoordinateSpaceDevice,
1749 CoordinateSpaceWorld, transform);
1752 if (stat == Ok)
1753 stat = GdipWidenPath(wide_path, pen, transform, 1.0);
1755 if (pen->unit == UnitPixel && graphics != NULL)
1757 if (stat == Ok)
1758 stat = GdipInvertMatrix(transform);
1760 if (stat == Ok)
1761 stat = GdipTransformPath(wide_path, transform);
1764 if (stat == Ok)
1765 stat = GdipIsVisiblePathPoint(wide_path, x, y, graphics, result);
1767 GdipDeleteMatrix(transform);
1769 GdipDeletePath(wide_path);
1771 return stat;
1774 GpStatus WINGDIPAPI GdipIsVisiblePathPointI(GpPath* path, INT x, INT y, GpGraphics *graphics, BOOL *result)
1776 TRACE("(%p, %d, %d, %p, %p)\n", path, x, y, graphics, result);
1778 return GdipIsVisiblePathPoint(path, x, y, graphics, result);
1781 /*****************************************************************************
1782 * GdipIsVisiblePathPoint [GDIPLUS.@]
1784 GpStatus WINGDIPAPI GdipIsVisiblePathPoint(GpPath* path, REAL x, REAL y, GpGraphics *graphics, BOOL *result)
1786 GpRegion *region;
1787 HRGN hrgn;
1788 GpStatus status;
1790 if(!path || !result) return InvalidParameter;
1792 status = GdipCreateRegionPath(path, &region);
1793 if(status != Ok)
1794 return status;
1796 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1797 if(status != Ok){
1798 GdipDeleteRegion(region);
1799 return status;
1802 *result = PtInRegion(hrgn, gdip_round(x), gdip_round(y));
1804 DeleteObject(hrgn);
1805 GdipDeleteRegion(region);
1807 return Ok;
1810 GpStatus WINGDIPAPI GdipStartPathFigure(GpPath *path)
1812 TRACE("(%p)\n", path);
1814 if(!path)
1815 return InvalidParameter;
1817 path->newfigure = TRUE;
1819 return Ok;
1822 GpStatus WINGDIPAPI GdipResetPath(GpPath *path)
1824 TRACE("(%p)\n", path);
1826 if(!path)
1827 return InvalidParameter;
1829 path->pathdata.Count = 0;
1830 path->newfigure = TRUE;
1831 path->fill = FillModeAlternate;
1833 return Ok;
1836 GpStatus WINGDIPAPI GdipSetPathFillMode(GpPath *path, GpFillMode fill)
1838 TRACE("(%p, %d)\n", path, fill);
1840 if(!path)
1841 return InvalidParameter;
1843 path->fill = fill;
1845 return Ok;
1848 GpStatus WINGDIPAPI GdipTransformPath(GpPath *path, GpMatrix *matrix)
1850 TRACE("(%p, %s)\n", path, debugstr_matrix(matrix));
1852 if(!path)
1853 return InvalidParameter;
1855 if(path->pathdata.Count == 0 || !matrix)
1856 return Ok;
1858 return GdipTransformMatrixPoints(matrix, path->pathdata.Points,
1859 path->pathdata.Count);
1862 GpStatus WINGDIPAPI GdipWarpPath(GpPath *path, GpMatrix* matrix,
1863 GDIPCONST GpPointF *points, INT count, REAL x, REAL y, REAL width,
1864 REAL height, WarpMode warpmode, REAL flatness)
1866 FIXME("(%p,%s,%p,%i,%0.2f,%0.2f,%0.2f,%0.2f,%i,%0.2f)\n", path, debugstr_matrix(matrix),
1867 points, count, x, y, width, height, warpmode, flatness);
1869 return NotImplemented;
1872 static void add_bevel_point(const GpPointF *endpoint, const GpPointF *nextpoint,
1873 REAL pen_width, int right_side, path_list_node_t **last_point)
1875 REAL segment_dy = nextpoint->Y-endpoint->Y;
1876 REAL segment_dx = nextpoint->X-endpoint->X;
1877 REAL segment_length = sqrtf(segment_dy*segment_dy + segment_dx*segment_dx);
1878 REAL distance = pen_width / 2.0;
1879 REAL bevel_dx, bevel_dy;
1881 if (segment_length == 0.0)
1883 *last_point = add_path_list_node(*last_point, endpoint->X,
1884 endpoint->Y, PathPointTypeLine);
1885 return;
1888 if (right_side)
1890 bevel_dx = -distance * segment_dy / segment_length;
1891 bevel_dy = distance * segment_dx / segment_length;
1893 else
1895 bevel_dx = distance * segment_dy / segment_length;
1896 bevel_dy = -distance * segment_dx / segment_length;
1899 *last_point = add_path_list_node(*last_point, endpoint->X + bevel_dx,
1900 endpoint->Y + bevel_dy, PathPointTypeLine);
1903 static void widen_joint(const GpPointF *p1, const GpPointF *p2, const GpPointF *p3,
1904 GpPen* pen, REAL pen_width, path_list_node_t **last_point)
1906 switch (pen->join)
1908 case LineJoinMiter:
1909 case LineJoinMiterClipped:
1910 if ((p2->X - p1->X) * (p3->Y - p1->Y) > (p2->Y - p1->Y) * (p3->X - p1->X))
1912 float distance = pen_width / 2.0;
1913 float length_0 = sqrtf((p2->X-p1->X)*(p2->X-p1->X)+(p2->Y-p1->Y)*(p2->Y-p1->Y));
1914 float length_1 = sqrtf((p3->X-p2->X)*(p3->X-p2->X)+(p3->Y-p2->Y)*(p3->Y-p2->Y));
1915 float dx0 = distance * (p2->X - p1->X) / length_0;
1916 float dy0 = distance * (p2->Y - p1->Y) / length_0;
1917 float dx1 = distance * (p3->X - p2->X) / length_1;
1918 float dy1 = distance * (p3->Y - p2->Y) / length_1;
1919 float det = (dy0*dx1 - dx0*dy1);
1920 float dx = (dx0*dx1*(dx0-dx1) + dy0*dy0*dx1 - dy1*dy1*dx0)/det;
1921 float dy = (dy0*dy1*(dy0-dy1) + dx0*dx0*dy1 - dx1*dx1*dy0)/det;
1922 if (dx*dx + dy*dy < pen->miterlimit*pen->miterlimit * distance*distance)
1924 *last_point = add_path_list_node(*last_point, p2->X + dx,
1925 p2->Y + dy, PathPointTypeLine);
1926 break;
1928 else if (pen->join == LineJoinMiter)
1930 static int once;
1931 if (!once++)
1932 FIXME("should add a clipped corner\n");
1934 /* else fall-through */
1936 /* else fall-through */
1937 default:
1938 case LineJoinBevel:
1939 add_bevel_point(p2, p1, pen_width, 1, last_point);
1940 add_bevel_point(p2, p3, pen_width, 0, last_point);
1941 break;
1945 static void widen_cap(const GpPointF *endpoint, const GpPointF *nextpoint,
1946 REAL pen_width, GpLineCap cap, GpCustomLineCap* custom_cap, int add_first_points,
1947 int add_last_point, path_list_node_t **last_point)
1949 switch (cap)
1951 default:
1952 case LineCapFlat:
1953 if (add_first_points)
1954 add_bevel_point(endpoint, nextpoint, pen_width, 1, last_point);
1955 if (add_last_point)
1956 add_bevel_point(endpoint, nextpoint, pen_width, 0, last_point);
1957 break;
1958 case LineCapSquare:
1959 case LineCapCustom:
1960 case LineCapArrowAnchor:
1962 REAL segment_dy = nextpoint->Y-endpoint->Y;
1963 REAL segment_dx = nextpoint->X-endpoint->X;
1964 REAL segment_length = sqrtf(segment_dy*segment_dy + segment_dx*segment_dx);
1965 REAL distance = pen_width / 2.0;
1966 REAL bevel_dx, bevel_dy;
1967 REAL extend_dx, extend_dy;
1969 extend_dx = distance * segment_dx / segment_length;
1970 extend_dy = distance * segment_dy / segment_length;
1972 bevel_dx = -extend_dy;
1973 bevel_dy = extend_dx;
1975 if (cap == LineCapCustom)
1977 extend_dx = -2.0 * custom_cap->inset * extend_dx;
1978 extend_dy = -2.0 * custom_cap->inset * extend_dy;
1980 else if (cap == LineCapArrowAnchor)
1982 extend_dx = -3.0 * extend_dx;
1983 extend_dy = -3.0 * extend_dy;
1986 if (add_first_points)
1987 *last_point = add_path_list_node(*last_point, endpoint->X - extend_dx + bevel_dx,
1988 endpoint->Y - extend_dy + bevel_dy, PathPointTypeLine);
1990 if (add_last_point)
1991 *last_point = add_path_list_node(*last_point, endpoint->X - extend_dx - bevel_dx,
1992 endpoint->Y - extend_dy - bevel_dy, PathPointTypeLine);
1993 break;
1995 case LineCapRound:
1997 REAL segment_dy = nextpoint->Y-endpoint->Y;
1998 REAL segment_dx = nextpoint->X-endpoint->X;
1999 REAL segment_length = sqrtf(segment_dy*segment_dy + segment_dx*segment_dx);
2000 REAL distance = pen_width / 2.0;
2001 REAL dx, dy, dx2, dy2;
2002 const REAL control_point_distance = 0.5522847498307935; /* 4/3 * (sqrt(2) - 1) */
2004 if (add_first_points)
2006 dx = -distance * segment_dx / segment_length;
2007 dy = -distance * segment_dy / segment_length;
2009 dx2 = dx * control_point_distance;
2010 dy2 = dy * control_point_distance;
2012 /* first 90-degree arc */
2013 *last_point = add_path_list_node(*last_point, endpoint->X + dy,
2014 endpoint->Y - dx, PathPointTypeLine);
2016 *last_point = add_path_list_node(*last_point, endpoint->X + dy + dx2,
2017 endpoint->Y - dx + dy2, PathPointTypeBezier);
2019 *last_point = add_path_list_node(*last_point, endpoint->X + dx + dy2,
2020 endpoint->Y + dy - dx2, PathPointTypeBezier);
2022 /* midpoint */
2023 *last_point = add_path_list_node(*last_point, endpoint->X + dx,
2024 endpoint->Y + dy, PathPointTypeBezier);
2026 /* second 90-degree arc */
2027 *last_point = add_path_list_node(*last_point, endpoint->X + dx - dy2,
2028 endpoint->Y + dy + dx2, PathPointTypeBezier);
2030 *last_point = add_path_list_node(*last_point, endpoint->X - dy + dx2,
2031 endpoint->Y + dx + dy2, PathPointTypeBezier);
2033 *last_point = add_path_list_node(*last_point, endpoint->X - dy,
2034 endpoint->Y + dx, PathPointTypeBezier);
2036 else if (add_last_point)
2037 add_bevel_point(endpoint, nextpoint, pen_width, 0, last_point);
2038 break;
2040 case LineCapTriangle:
2042 REAL segment_dy = nextpoint->Y-endpoint->Y;
2043 REAL segment_dx = nextpoint->X-endpoint->X;
2044 REAL segment_length = sqrtf(segment_dy*segment_dy + segment_dx*segment_dx);
2045 REAL distance = pen_width / 2.0;
2046 REAL dx, dy;
2048 dx = distance * segment_dx / segment_length;
2049 dy = distance * segment_dy / segment_length;
2051 if (add_first_points) {
2052 add_bevel_point(endpoint, nextpoint, pen_width, 1, last_point);
2054 *last_point = add_path_list_node(*last_point, endpoint->X - dx,
2055 endpoint->Y - dy, PathPointTypeLine);
2057 if (add_first_points || add_last_point)
2058 add_bevel_point(endpoint, nextpoint, pen_width, 0, last_point);
2059 break;
2064 static void widen_open_figure(const GpPointF *points, int start, int end,
2065 GpPen *pen, REAL pen_width, GpLineCap start_cap, GpCustomLineCap* custom_start,
2066 GpLineCap end_cap, GpCustomLineCap* custom_end, path_list_node_t **last_point);
2068 static void widen_closed_figure(const GpPointF *points, int start, int end,
2069 GpPen *pen, REAL pen_width, path_list_node_t **last_point);
2071 static void add_anchor(const GpPointF *endpoint, const GpPointF *nextpoint,
2072 GpPen *pen, GpLineCap cap, GpCustomLineCap *custom, path_list_node_t **last_point)
2074 REAL pen_width = max(pen->width, 2.0);
2075 switch (cap)
2077 default:
2078 case LineCapNoAnchor:
2079 return;
2080 case LineCapSquareAnchor:
2082 REAL segment_dy = nextpoint->Y-endpoint->Y;
2083 REAL segment_dx = nextpoint->X-endpoint->X;
2084 REAL segment_length = sqrtf(segment_dy*segment_dy + segment_dx*segment_dx);
2085 REAL distance = pen_width / sqrtf(2.0);
2086 REAL par_dx, par_dy;
2087 REAL perp_dx, perp_dy;
2089 par_dx = -distance * segment_dx / segment_length;
2090 par_dy = -distance * segment_dy / segment_length;
2092 perp_dx = -distance * segment_dy / segment_length;
2093 perp_dy = distance * segment_dx / segment_length;
2095 *last_point = add_path_list_node(*last_point, endpoint->X - par_dx - perp_dx,
2096 endpoint->Y - par_dy - perp_dy, PathPointTypeStart);
2097 *last_point = add_path_list_node(*last_point, endpoint->X - par_dx + perp_dx,
2098 endpoint->Y - par_dy + perp_dy, PathPointTypeLine);
2099 *last_point = add_path_list_node(*last_point, endpoint->X + par_dx + perp_dx,
2100 endpoint->Y + par_dy + perp_dy, PathPointTypeLine);
2101 *last_point = add_path_list_node(*last_point, endpoint->X + par_dx - perp_dx,
2102 endpoint->Y + par_dy - perp_dy, PathPointTypeLine);
2103 break;
2105 case LineCapRoundAnchor:
2107 REAL segment_dy = nextpoint->Y-endpoint->Y;
2108 REAL segment_dx = nextpoint->X-endpoint->X;
2109 REAL segment_length = sqrtf(segment_dy*segment_dy + segment_dx*segment_dx);
2110 REAL dx, dy, dx2, dy2;
2111 const REAL control_point_distance = 0.55228475; /* 4/3 * (sqrt(2) - 1) */
2113 dx = -pen_width * segment_dx / segment_length;
2114 dy = -pen_width * segment_dy / segment_length;
2116 dx2 = dx * control_point_distance;
2117 dy2 = dy * control_point_distance;
2119 /* starting point */
2120 *last_point = add_path_list_node(*last_point, endpoint->X + dy,
2121 endpoint->Y - dx, PathPointTypeStart);
2123 /* first 90-degree arc */
2124 *last_point = add_path_list_node(*last_point, endpoint->X + dy + dx2,
2125 endpoint->Y - dx + dy2, PathPointTypeBezier);
2126 *last_point = add_path_list_node(*last_point, endpoint->X + dx + dy2,
2127 endpoint->Y + dy - dx2, PathPointTypeBezier);
2128 *last_point = add_path_list_node(*last_point, endpoint->X + dx,
2129 endpoint->Y + dy, PathPointTypeBezier);
2131 /* second 90-degree arc */
2132 *last_point = add_path_list_node(*last_point, endpoint->X + dx - dy2,
2133 endpoint->Y + dy + dx2, PathPointTypeBezier);
2134 *last_point = add_path_list_node(*last_point, endpoint->X - dy + dx2,
2135 endpoint->Y + dx + dy2, PathPointTypeBezier);
2136 *last_point = add_path_list_node(*last_point, endpoint->X - dy,
2137 endpoint->Y + dx, PathPointTypeBezier);
2139 /* third 90-degree arc */
2140 *last_point = add_path_list_node(*last_point, endpoint->X - dy - dx2,
2141 endpoint->Y + dx - dy2, PathPointTypeBezier);
2142 *last_point = add_path_list_node(*last_point, endpoint->X - dx - dy2,
2143 endpoint->Y - dy + dx2, PathPointTypeBezier);
2144 *last_point = add_path_list_node(*last_point, endpoint->X - dx,
2145 endpoint->Y - dy, PathPointTypeBezier);
2147 /* fourth 90-degree arc */
2148 *last_point = add_path_list_node(*last_point, endpoint->X - dx + dy2,
2149 endpoint->Y - dy - dx2, PathPointTypeBezier);
2150 *last_point = add_path_list_node(*last_point, endpoint->X + dy - dx2,
2151 endpoint->Y - dx - dy2, PathPointTypeBezier);
2152 *last_point = add_path_list_node(*last_point, endpoint->X + dy,
2153 endpoint->Y - dx, PathPointTypeBezier);
2155 break;
2157 case LineCapDiamondAnchor:
2159 REAL segment_dy = nextpoint->Y-endpoint->Y;
2160 REAL segment_dx = nextpoint->X-endpoint->X;
2161 REAL segment_length = sqrtf(segment_dy*segment_dy + segment_dx*segment_dx);
2162 REAL par_dx, par_dy;
2163 REAL perp_dx, perp_dy;
2165 par_dx = -pen_width * segment_dx / segment_length;
2166 par_dy = -pen_width * segment_dy / segment_length;
2168 perp_dx = -pen_width * segment_dy / segment_length;
2169 perp_dy = pen_width * segment_dx / segment_length;
2171 *last_point = add_path_list_node(*last_point, endpoint->X + par_dx,
2172 endpoint->Y + par_dy, PathPointTypeStart);
2173 *last_point = add_path_list_node(*last_point, endpoint->X - perp_dx,
2174 endpoint->Y - perp_dy, PathPointTypeLine);
2175 *last_point = add_path_list_node(*last_point, endpoint->X - par_dx,
2176 endpoint->Y - par_dy, PathPointTypeLine);
2177 *last_point = add_path_list_node(*last_point, endpoint->X + perp_dx,
2178 endpoint->Y + perp_dy, PathPointTypeLine);
2179 break;
2181 case LineCapArrowAnchor:
2183 REAL segment_dy = nextpoint->Y - endpoint->Y;
2184 REAL segment_dx = nextpoint->X - endpoint->X;
2185 REAL segment_length = sqrtf(segment_dy * segment_dy + segment_dx * segment_dx);
2186 REAL par_dx = pen_width * segment_dx / segment_length;
2187 REAL par_dy = pen_width * segment_dy / segment_length;
2188 REAL perp_dx = -par_dy;
2189 REAL perp_dy = par_dx;
2191 *last_point = add_path_list_node(*last_point, endpoint->X,
2192 endpoint->Y, PathPointTypeStart);
2193 *last_point = add_path_list_node(*last_point, endpoint->X + SQRT3 * par_dx - perp_dx,
2194 endpoint->Y + SQRT3 * par_dy - perp_dy, PathPointTypeLine);
2195 *last_point = add_path_list_node(*last_point, endpoint->X + SQRT3 * par_dx + perp_dx,
2196 endpoint->Y + SQRT3 * par_dy + perp_dy, PathPointTypeLine);
2197 break;
2199 case LineCapCustom:
2201 REAL segment_dy = nextpoint->Y - endpoint->Y;
2202 REAL segment_dx = nextpoint->X - endpoint->X;
2203 REAL segment_length = sqrtf(segment_dy * segment_dy + segment_dx * segment_dx);
2204 REAL posx, posy;
2205 REAL perp_dx, perp_dy;
2206 REAL sina, cosa;
2207 GpPointF *tmp_points;
2209 if(!custom)
2210 break;
2212 if (custom->type == CustomLineCapTypeAdjustableArrow)
2214 GpAdjustableArrowCap *arrow = (GpAdjustableArrowCap *)custom;
2215 TRACE("GpAdjustableArrowCap middle_inset: %f height: %f width: %f\n",
2216 arrow->middle_inset, arrow->height, arrow->width);
2218 else
2219 TRACE("GpCustomLineCap fill: %d basecap: %d inset: %f join: %d scale: %f pen_width:%f\n",
2220 custom->fill, custom->basecap, custom->inset, custom->join, custom->scale, pen_width);
2222 sina = -pen_width * custom->scale * segment_dx / segment_length;
2223 cosa = pen_width * custom->scale * segment_dy / segment_length;
2225 /* Coordination where cap needs to be drawn */
2226 posx = endpoint->X + sina;
2227 posy = endpoint->Y - cosa;
2229 if (!custom->fill)
2231 tmp_points = heap_alloc_zero(custom->pathdata.Count * sizeof(GpPoint));
2232 if (!tmp_points) {
2233 ERR("Out of memory\n");
2234 return;
2237 for (INT i = 0; i < custom->pathdata.Count; i++)
2239 tmp_points[i].X = posx + custom->pathdata.Points[i].X * cosa + (custom->pathdata.Points[i].Y - 1.0) * sina;
2240 tmp_points[i].Y = posy + custom->pathdata.Points[i].X * sina - (custom->pathdata.Points[i].Y - 1.0) * cosa;
2242 if ((custom->pathdata.Types[custom->pathdata.Count - 1] & PathPointTypeCloseSubpath) == PathPointTypeCloseSubpath)
2243 widen_closed_figure(tmp_points, 0, custom->pathdata.Count - 1, pen, pen_width, last_point);
2244 else
2245 widen_open_figure(tmp_points, 0, custom->pathdata.Count - 1, pen, pen_width, custom->strokeEndCap, NULL, custom->strokeStartCap, NULL, last_point);
2247 else
2249 for (INT i = 0; i < custom->pathdata.Count; i++)
2251 /* rotation of CustomCap according to line */
2252 perp_dx = custom->pathdata.Points[i].X * cosa + (custom->pathdata.Points[i].Y - 1.0) * sina;
2253 perp_dy = custom->pathdata.Points[i].X * sina - (custom->pathdata.Points[i].Y - 1.0) * cosa;
2254 *last_point = add_path_list_node(*last_point, posx + perp_dx,
2255 posy + perp_dy, custom->pathdata.Types[i]);
2258 /* FIXME: The line should be adjusted by the inset value of the custom cap. */
2259 break;
2263 (*last_point)->type |= PathPointTypeCloseSubpath;
2266 static void widen_open_figure(const GpPointF *points, int start, int end,
2267 GpPen *pen, REAL pen_width, GpLineCap start_cap, GpCustomLineCap* custom_start,
2268 GpLineCap end_cap, GpCustomLineCap* custom_end, path_list_node_t **last_point)
2270 int i;
2271 path_list_node_t *prev_point;
2273 if (end <= start || pen_width == 0.0)
2274 return;
2276 prev_point = *last_point;
2278 widen_cap(&points[start], &points[start+1],
2279 pen_width, start_cap, custom_start, FALSE, TRUE, last_point);
2281 for (i=start+1; i<end; i++)
2282 widen_joint(&points[i-1], &points[i], &points[i+1],
2283 pen, pen_width, last_point);
2285 widen_cap(&points[end], &points[end-1],
2286 pen_width, end_cap, custom_end, TRUE, TRUE, last_point);
2288 for (i=end-1; i>start; i--)
2289 widen_joint(&points[i+1], &points[i], &points[i-1],
2290 pen, pen_width, last_point);
2292 widen_cap(&points[start], &points[start+1],
2293 pen_width, start_cap, custom_start, TRUE, FALSE, last_point);
2295 prev_point->next->type = PathPointTypeStart;
2296 (*last_point)->type |= PathPointTypeCloseSubpath;
2299 static void widen_closed_figure(const GpPointF *points, int start, int end,
2300 GpPen *pen, REAL pen_width, path_list_node_t **last_point)
2302 int i;
2303 path_list_node_t *prev_point;
2305 if (end <= start || pen_width == 0.0)
2306 return;
2308 /* left outline */
2309 prev_point = *last_point;
2311 widen_joint(&points[end], &points[start],
2312 &points[start+1], pen, pen_width, last_point);
2314 for (i=start+1; i<end; i++)
2315 widen_joint(&points[i-1], &points[i],
2316 &points[i+1], pen, pen_width, last_point);
2318 widen_joint(&points[end-1], &points[end],
2319 &points[start], pen, pen_width, last_point);
2321 prev_point->next->type = PathPointTypeStart;
2322 (*last_point)->type |= PathPointTypeCloseSubpath;
2324 /* right outline */
2325 prev_point = *last_point;
2327 widen_joint(&points[start], &points[end],
2328 &points[end-1], pen, pen_width, last_point);
2330 for (i=end-1; i>start; i--)
2331 widen_joint(&points[i+1], &points[i],
2332 &points[i-1], pen, pen_width, last_point);
2334 widen_joint(&points[start+1], &points[start],
2335 &points[end], pen, pen_width, last_point);
2337 prev_point->next->type = PathPointTypeStart;
2338 (*last_point)->type |= PathPointTypeCloseSubpath;
2341 static void widen_dashed_figure(GpPath *path, int start, int end, int closed,
2342 GpPen *pen, REAL pen_width, path_list_node_t **last_point)
2344 int i, j;
2345 REAL dash_pos=0.0;
2346 int dash_index=0;
2347 const REAL *dash_pattern;
2348 REAL *dash_pattern_scaled;
2349 REAL dash_pattern_scaling = max(pen->width, 1.0);
2350 int dash_count;
2351 GpPointF *tmp_points;
2352 REAL segment_dy;
2353 REAL segment_dx;
2354 REAL segment_length;
2355 REAL segment_pos;
2356 int num_tmp_points=0;
2357 int draw_start_cap=0;
2358 static const REAL dash_dot_dot[6] = { 3.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
2360 if (end <= start || pen_width == 0.0)
2361 return;
2363 switch (pen->dash)
2365 case DashStyleDash:
2366 default:
2367 dash_pattern = dash_dot_dot;
2368 dash_count = 2;
2369 break;
2370 case DashStyleDot:
2371 dash_pattern = &dash_dot_dot[2];
2372 dash_count = 2;
2373 break;
2374 case DashStyleDashDot:
2375 dash_pattern = dash_dot_dot;
2376 dash_count = 4;
2377 break;
2378 case DashStyleDashDotDot:
2379 dash_pattern = dash_dot_dot;
2380 dash_count = 6;
2381 break;
2382 case DashStyleCustom:
2383 dash_pattern = pen->dashes;
2384 dash_count = pen->numdashes;
2385 break;
2388 dash_pattern_scaled = heap_alloc(dash_count * sizeof(REAL));
2389 if (!dash_pattern_scaled) return;
2391 for (i = 0; i < dash_count; i++)
2392 dash_pattern_scaled[i] = dash_pattern_scaling * dash_pattern[i];
2394 tmp_points = heap_alloc_zero((end - start + 2) * sizeof(GpPoint));
2395 if (!tmp_points) {
2396 heap_free(dash_pattern_scaled);
2397 return; /* FIXME */
2400 if (!closed)
2401 draw_start_cap = 1;
2403 for (j=start; j <= end; j++)
2405 if (j == start)
2407 if (closed)
2408 i = end;
2409 else
2410 continue;
2412 else
2413 i = j-1;
2415 segment_dy = path->pathdata.Points[j].Y - path->pathdata.Points[i].Y;
2416 segment_dx = path->pathdata.Points[j].X - path->pathdata.Points[i].X;
2417 segment_length = sqrtf(segment_dy*segment_dy + segment_dx*segment_dx);
2418 segment_pos = 0.0;
2420 while (1)
2422 if (dash_pos == 0.0)
2424 if ((dash_index % 2) == 0)
2426 /* start dash */
2427 num_tmp_points = 1;
2428 tmp_points[0].X = path->pathdata.Points[i].X + segment_dx * segment_pos / segment_length;
2429 tmp_points[0].Y = path->pathdata.Points[i].Y + segment_dy * segment_pos / segment_length;
2431 else
2433 /* end dash */
2434 tmp_points[num_tmp_points].X = path->pathdata.Points[i].X + segment_dx * segment_pos / segment_length;
2435 tmp_points[num_tmp_points].Y = path->pathdata.Points[i].Y + segment_dy * segment_pos / segment_length;
2437 widen_open_figure(tmp_points, 0, num_tmp_points, pen, pen_width,
2438 draw_start_cap ? pen->startcap : LineCapFlat, pen->customstart,
2439 LineCapFlat, NULL, last_point);
2440 draw_start_cap = 0;
2441 num_tmp_points = 0;
2445 if (dash_pattern_scaled[dash_index] - dash_pos > segment_length - segment_pos)
2447 /* advance to next segment */
2448 if ((dash_index % 2) == 0)
2450 tmp_points[num_tmp_points] = path->pathdata.Points[j];
2451 num_tmp_points++;
2453 dash_pos += segment_length - segment_pos;
2454 break;
2456 else
2458 /* advance to next dash in pattern */
2459 segment_pos += dash_pattern_scaled[dash_index] - dash_pos;
2460 dash_pos = 0.0;
2461 if (++dash_index == dash_count)
2462 dash_index = 0;
2463 continue;
2468 if (dash_index % 2 == 0 && num_tmp_points != 0)
2470 /* last dash overflows last segment */
2471 widen_open_figure(tmp_points, 0, num_tmp_points-1, pen, pen_width,
2472 draw_start_cap ? pen->startcap : LineCapFlat, pen->customstart,
2473 closed ? LineCapFlat : pen->endcap, pen->customend, last_point);
2476 heap_free(dash_pattern_scaled);
2477 heap_free(tmp_points);
2480 GpStatus WINGDIPAPI GdipWidenPath(GpPath *path, GpPen *pen, GpMatrix *matrix,
2481 REAL flatness)
2483 GpPath *flat_path=NULL;
2484 GpStatus status;
2485 path_list_node_t *points=NULL, *last_point=NULL;
2486 int i, subpath_start=0, new_length;
2488 TRACE("(%p,%p,%s,%0.2f)\n", path, pen, debugstr_matrix(matrix), flatness);
2490 if (!path || !pen)
2491 return InvalidParameter;
2493 if (path->pathdata.Count <= 1)
2494 return OutOfMemory;
2496 status = GdipClonePath(path, &flat_path);
2498 if (status == Ok)
2499 status = GdipFlattenPath(flat_path, pen->unit == UnitPixel ? matrix : NULL, flatness);
2501 if (status == Ok && !init_path_list(&points, 314.0, 22.0))
2502 status = OutOfMemory;
2504 if (status == Ok)
2506 REAL pen_width = (pen->unit == UnitWorld) ? max(pen->width, 1.0) : pen->width;
2507 BYTE *types = flat_path->pathdata.Types;
2509 last_point = points;
2511 if (pen->dashcap != DashCapFlat)
2512 FIXME("unimplemented dash cap %d\n", pen->dashcap);
2514 if (pen->join == LineJoinRound)
2515 FIXME("unimplemented line join %d\n", pen->join);
2517 if (pen->align != PenAlignmentCenter)
2518 FIXME("unimplemented pen alignment %d\n", pen->align);
2520 if (pen->compound_array_size != 0)
2521 FIXME("unimplemented pen compoundline. Solid line will be drawn instead: %d\n", pen->compound_array_size);
2523 for (i=0; i < flat_path->pathdata.Count; i++)
2525 if ((types[i]&PathPointTypePathTypeMask) == PathPointTypeStart)
2526 subpath_start = i;
2528 if ((types[i]&PathPointTypeCloseSubpath) == PathPointTypeCloseSubpath)
2530 if (pen->dash != DashStyleSolid)
2531 widen_dashed_figure(flat_path, subpath_start, i, 1, pen, pen_width, &last_point);
2532 else
2533 widen_closed_figure(flat_path->pathdata.Points, subpath_start, i, pen, pen_width, &last_point);
2535 else if (i == flat_path->pathdata.Count-1 ||
2536 (types[i+1]&PathPointTypePathTypeMask) == PathPointTypeStart)
2538 if (pen->dash != DashStyleSolid)
2539 widen_dashed_figure(flat_path, subpath_start, i, 0, pen, pen_width, &last_point);
2540 else
2541 widen_open_figure(flat_path->pathdata.Points, subpath_start, i, pen, pen_width,
2542 pen->startcap, pen->customstart, pen->endcap, pen->customend, &last_point);
2546 for (i=0; i < flat_path->pathdata.Count; i++)
2548 if ((types[i]&PathPointTypeCloseSubpath) == PathPointTypeCloseSubpath)
2549 continue;
2551 if ((types[i]&PathPointTypePathTypeMask) == PathPointTypeStart)
2552 subpath_start = i;
2554 if (i == flat_path->pathdata.Count-1 ||
2555 (types[i+1]&PathPointTypePathTypeMask) == PathPointTypeStart)
2557 if (pen->startcap & LineCapAnchorMask)
2558 add_anchor(&flat_path->pathdata.Points[subpath_start],
2559 &flat_path->pathdata.Points[subpath_start+1],
2560 pen, pen->startcap, pen->customstart, &last_point);
2562 if (pen->endcap & LineCapAnchorMask)
2563 add_anchor(&flat_path->pathdata.Points[i],
2564 &flat_path->pathdata.Points[i-1],
2565 pen, pen->endcap, pen->customend, &last_point);
2569 new_length = path_list_count(points)-1;
2571 if (!lengthen_path(path, new_length))
2572 status = OutOfMemory;
2575 if (status == Ok)
2577 path->pathdata.Count = new_length;
2579 last_point = points->next;
2580 for (i = 0; i < new_length; i++)
2582 path->pathdata.Points[i] = last_point->pt;
2583 path->pathdata.Types[i] = last_point->type;
2584 last_point = last_point->next;
2587 path->fill = FillModeWinding;
2590 free_path_list(points);
2592 GdipDeletePath(flat_path);
2594 if (status == Ok && pen->unit != UnitPixel)
2595 status = GdipTransformPath(path, matrix);
2597 return status;
2600 GpStatus WINGDIPAPI GdipAddPathRectangle(GpPath *path, REAL x, REAL y,
2601 REAL width, REAL height)
2603 GpPath *backup;
2604 GpPointF ptf[2];
2605 GpStatus retstat;
2606 BOOL old_new;
2608 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x, y, width, height);
2610 if(!path)
2611 return InvalidParameter;
2613 if (width <= 0.0 || height <= 0.0)
2614 return Ok;
2616 /* make a backup copy of path data */
2617 if((retstat = GdipClonePath(path, &backup)) != Ok)
2618 return retstat;
2620 /* rectangle should start as new path */
2621 old_new = path->newfigure;
2622 path->newfigure = TRUE;
2623 if((retstat = GdipAddPathLine(path,x,y,x+width,y)) != Ok){
2624 path->newfigure = old_new;
2625 goto fail;
2628 ptf[0].X = x+width;
2629 ptf[0].Y = y+height;
2630 ptf[1].X = x;
2631 ptf[1].Y = y+height;
2633 if((retstat = GdipAddPathLine2(path, ptf, 2)) != Ok) goto fail;
2634 path->pathdata.Types[path->pathdata.Count-1] |= PathPointTypeCloseSubpath;
2636 /* free backup */
2637 GdipDeletePath(backup);
2638 return Ok;
2640 fail:
2641 /* reverting */
2642 heap_free(path->pathdata.Points);
2643 heap_free(path->pathdata.Types);
2644 memcpy(path, backup, sizeof(*path));
2645 heap_free(backup);
2647 return retstat;
2650 GpStatus WINGDIPAPI GdipAddPathRectangleI(GpPath *path, INT x, INT y,
2651 INT width, INT height)
2653 TRACE("(%p, %d, %d, %d, %d)\n", path, x, y, width, height);
2655 return GdipAddPathRectangle(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2658 GpStatus WINGDIPAPI GdipAddPathRectangles(GpPath *path, GDIPCONST GpRectF *rects, INT count)
2660 GpPath *backup;
2661 GpStatus retstat;
2662 INT i;
2664 TRACE("(%p, %p, %d)\n", path, rects, count);
2666 /* count == 0 - verified condition */
2667 if(!path || !rects || count == 0)
2668 return InvalidParameter;
2670 if(count < 0)
2671 return OutOfMemory;
2673 /* make a backup copy */
2674 if((retstat = GdipClonePath(path, &backup)) != Ok)
2675 return retstat;
2677 for(i = 0; i < count; i++){
2678 if((retstat = GdipAddPathRectangle(path,rects[i].X,rects[i].Y,rects[i].Width,rects[i].Height)) != Ok)
2679 goto fail;
2682 /* free backup */
2683 GdipDeletePath(backup);
2684 return Ok;
2686 fail:
2687 /* reverting */
2688 heap_free(path->pathdata.Points);
2689 heap_free(path->pathdata.Types);
2690 memcpy(path, backup, sizeof(*path));
2691 heap_free(backup);
2693 return retstat;
2696 GpStatus WINGDIPAPI GdipAddPathRectanglesI(GpPath *path, GDIPCONST GpRect *rects, INT count)
2698 GpRectF *rectsF;
2699 GpStatus retstat;
2700 INT i;
2702 TRACE("(%p, %p, %d)\n", path, rects, count);
2704 if(!rects || count == 0)
2705 return InvalidParameter;
2707 if(count < 0)
2708 return OutOfMemory;
2710 rectsF = heap_alloc_zero(sizeof(GpRectF)*count);
2712 for(i = 0;i < count;i++)
2713 set_rect(&rectsF[i], rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
2715 retstat = GdipAddPathRectangles(path, rectsF, count);
2716 heap_free(rectsF);
2718 return retstat;
2721 GpStatus WINGDIPAPI GdipSetPathMarker(GpPath* path)
2723 INT count;
2725 TRACE("(%p)\n", path);
2727 if(!path)
2728 return InvalidParameter;
2730 count = path->pathdata.Count;
2732 /* set marker flag */
2733 if(count > 0)
2734 path->pathdata.Types[count-1] |= PathPointTypePathMarker;
2736 return Ok;
2739 GpStatus WINGDIPAPI GdipClearPathMarkers(GpPath* path)
2741 INT count;
2742 INT i;
2744 TRACE("(%p)\n", path);
2746 if(!path)
2747 return InvalidParameter;
2749 count = path->pathdata.Count;
2751 for(i = 0; i < count - 1; i++){
2752 path->pathdata.Types[i] &= ~PathPointTypePathMarker;
2755 return Ok;
2758 GpStatus WINGDIPAPI GdipWindingModeOutline(GpPath *path, GpMatrix *matrix, REAL flatness)
2760 FIXME("stub: %p, %p, %.2f\n", path, matrix, flatness);
2761 return NotImplemented;
2764 #define FLAGS_INTPATH 0x4000
2766 struct path_header
2768 DWORD version;
2769 DWORD count;
2770 DWORD flags;
2773 /* Test to see if the path could be stored as an array of shorts */
2774 static BOOL is_integer_path(const GpPath *path)
2776 int i;
2778 if (!path->pathdata.Count) return FALSE;
2780 for (i = 0; i < path->pathdata.Count; i++)
2782 short x, y;
2783 x = gdip_round(path->pathdata.Points[i].X);
2784 y = gdip_round(path->pathdata.Points[i].Y);
2785 if (path->pathdata.Points[i].X != (REAL)x || path->pathdata.Points[i].Y != (REAL)y)
2786 return FALSE;
2788 return TRUE;
2791 DWORD write_path_data(GpPath *path, void *data)
2793 struct path_header *header = data;
2794 BOOL integer_path = is_integer_path(path);
2795 DWORD i, size;
2796 BYTE *types;
2798 size = sizeof(struct path_header) + path->pathdata.Count;
2799 if (integer_path)
2800 size += sizeof(short[2]) * path->pathdata.Count;
2801 else
2802 size += sizeof(float[2]) * path->pathdata.Count;
2803 size = (size + 3) & ~3;
2805 if (!data) return size;
2807 header->version = VERSION_MAGIC2;
2808 header->count = path->pathdata.Count;
2809 header->flags = integer_path ? FLAGS_INTPATH : 0;
2811 if (integer_path)
2813 short *points = (short*)(header + 1);
2814 for (i = 0; i < path->pathdata.Count; i++)
2816 points[2*i] = path->pathdata.Points[i].X;
2817 points[2*i + 1] = path->pathdata.Points[i].Y;
2819 types = (BYTE*)(points + 2*i);
2821 else
2823 float *points = (float*)(header + 1);
2824 for (i = 0; i < path->pathdata.Count; i++)
2826 points[2*i] = path->pathdata.Points[i].X;
2827 points[2*i + 1] = path->pathdata.Points[i].Y;
2829 types = (BYTE*)(points + 2*i);
2832 for (i=0; i<path->pathdata.Count; i++)
2833 types[i] = path->pathdata.Types[i];
2834 memset(types + i, 0, ((path->pathdata.Count + 3) & ~3) - path->pathdata.Count);
2835 return size;