gdiplus: Added GdipAddPathEllipse.
[wine] / dlls / gdiplus / pathiterator.c
1 /*
2  * Copyright (C) 2007 Google (Evan Stade)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20
21 #include "windef.h"
22 #include "winbase.h"
23
24 #include "gdiplus.h"
25 #include "gdiplus_private.h"
26
27 GpStatus WINGDIPAPI GdipCreatePathIter(GpPathIterator **iterator, GpPath* path)
28 {
29     INT size;
30
31     if(!iterator || !path)
32         return InvalidParameter;
33
34     size = path->pathdata.Count;
35
36     *iterator = GdipAlloc(sizeof(GpPathIterator));
37     if(!*iterator)  return OutOfMemory;
38
39     (*iterator)->pathdata.Types = GdipAlloc(size);
40     (*iterator)->pathdata.Points = GdipAlloc(size * sizeof(PointF));
41
42     memcpy((*iterator)->pathdata.Types, path->pathdata.Types, size);
43     memcpy((*iterator)->pathdata.Points, path->pathdata.Points,
44            size * sizeof(PointF));
45     (*iterator)->pathdata.Count = size;
46
47     (*iterator)->subpath_pos = 0;
48     (*iterator)->marker_pos = 0;
49     (*iterator)->pathtype_pos = 0;
50
51     return Ok;
52 }
53
54 GpStatus WINGDIPAPI GdipDeletePathIter(GpPathIterator *iter)
55 {
56     if(!iter)
57         return InvalidParameter;
58
59     GdipFree(iter->pathdata.Types);
60     GdipFree(iter->pathdata.Points);
61     GdipFree(iter);
62
63     return Ok;
64 }
65
66 GpStatus WINGDIPAPI GdipPathIterCopyData(GpPathIterator* iterator,
67     INT* resultCount, GpPointF* points, BYTE* types, INT startIndex, INT endIndex)
68 {
69     if(!iterator || !types || !points)
70         return InvalidParameter;
71
72     if(endIndex > iterator->pathdata.Count - 1 || startIndex < 0 ||
73         endIndex < startIndex){
74         *resultCount = 0;
75         return Ok;
76     }
77
78     *resultCount = endIndex - startIndex + 1;
79
80     memcpy(types, &(iterator->pathdata.Types[startIndex]), *resultCount);
81     memcpy(points, &(iterator->pathdata.Points[startIndex]),
82         *resultCount * sizeof(PointF));
83
84     return Ok;
85 }
86
87 GpStatus WINGDIPAPI GdipPathIterNextSubpath(GpPathIterator* iterator,
88     INT *resultCount, INT* startIndex, INT* endIndex, BOOL* isClosed)
89 {
90     INT i, count;
91
92     if(!iterator)
93         return InvalidParameter;
94
95     count = iterator->pathdata.Count;
96
97     if(iterator->subpath_pos == count){
98         *startIndex = *endIndex = *resultCount = 0;
99         *isClosed = 1;
100         return Ok;
101     }
102
103     *startIndex = iterator->subpath_pos;
104
105     for(i = iterator->subpath_pos + 1; i < count &&
106         !(iterator->pathdata.Types[i] == PathPointTypeStart); i++);
107
108     *endIndex = i - 1;
109     iterator->subpath_pos = i;
110
111     *resultCount = *endIndex - *startIndex + 1;
112
113     if(iterator->pathdata.Types[*endIndex] & PathPointTypeCloseSubpath)
114         *isClosed = TRUE;
115     else
116         *isClosed = FALSE;
117
118     return Ok;
119 }
120 GpStatus WINGDIPAPI GdipPathIterRewind(GpPathIterator *iterator)
121 {
122     if(!iterator)
123         return InvalidParameter;
124
125     iterator->subpath_pos = 0;
126     iterator->marker_pos = 0;
127     iterator->pathtype_pos = 0;
128
129     return Ok;
130 }