push 535a8035db5d709ef8f05977281c2f1a0c4cce0a
[wine/hacks.git] / dlls / gdiplus / pathiterator.c
blobafb4f34d2f474ffb7337825191e877bb92291351
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
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "wingdi.h"
25 #include "objbase.h"
27 #include "gdiplus.h"
28 #include "gdiplus_private.h"
30 GpStatus WINGDIPAPI GdipCreatePathIter(GpPathIterator **iterator, GpPath* path)
32 INT size;
34 if(!iterator)
35 return InvalidParameter;
37 *iterator = GdipAlloc(sizeof(GpPathIterator));
38 if(!*iterator) return OutOfMemory;
40 if(path){
41 size = path->pathdata.Count;
43 (*iterator)->pathdata.Types = GdipAlloc(size);
44 (*iterator)->pathdata.Points = GdipAlloc(size * sizeof(PointF));
46 memcpy((*iterator)->pathdata.Types, path->pathdata.Types, size);
47 memcpy((*iterator)->pathdata.Points, path->pathdata.Points,size * sizeof(PointF));
48 (*iterator)->pathdata.Count = size;
50 else{
51 (*iterator)->pathdata.Types = NULL;
52 (*iterator)->pathdata.Points = NULL;
53 (*iterator)->pathdata.Count = 0;
56 (*iterator)->subpath_pos = 0;
57 (*iterator)->marker_pos = 0;
58 (*iterator)->pathtype_pos = 0;
60 return Ok;
63 GpStatus WINGDIPAPI GdipDeletePathIter(GpPathIterator *iter)
65 if(!iter)
66 return InvalidParameter;
68 GdipFree(iter->pathdata.Types);
69 GdipFree(iter->pathdata.Points);
70 GdipFree(iter);
72 return Ok;
75 GpStatus WINGDIPAPI GdipPathIterCopyData(GpPathIterator* iterator,
76 INT* resultCount, GpPointF* points, BYTE* types, INT startIndex, INT endIndex)
78 if(!iterator || !types || !points)
79 return InvalidParameter;
81 if(endIndex > iterator->pathdata.Count - 1 || startIndex < 0 ||
82 endIndex < startIndex){
83 *resultCount = 0;
84 return Ok;
87 *resultCount = endIndex - startIndex + 1;
89 memcpy(types, &(iterator->pathdata.Types[startIndex]), *resultCount);
90 memcpy(points, &(iterator->pathdata.Points[startIndex]),
91 *resultCount * sizeof(PointF));
93 return Ok;
96 GpStatus WINGDIPAPI GdipPathIterHasCurve(GpPathIterator* iterator, BOOL* hasCurve)
98 INT i;
100 if(!iterator)
101 return InvalidParameter;
103 *hasCurve = FALSE;
105 for(i = 0; i < iterator->pathdata.Count; i++)
106 if((iterator->pathdata.Types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
107 *hasCurve = TRUE;
108 break;
111 return Ok;
114 GpStatus WINGDIPAPI GdipPathIterGetSubpathCount(GpPathIterator* iterator, INT* count)
116 INT i;
118 if(!iterator || !count)
119 return InvalidParameter;
121 *count = 0;
122 for(i = 0; i < iterator->pathdata.Count; i++){
123 if(iterator->pathdata.Types[i] == PathPointTypeStart)
124 (*count)++;
127 return Ok;
130 GpStatus WINGDIPAPI GdipPathIterNextMarker(GpPathIterator* iterator, INT *resultCount,
131 INT* startIndex, INT* endIndex)
133 INT i;
135 if(!iterator || !startIndex || !endIndex)
136 return InvalidParameter;
138 *resultCount = 0;
140 /* first call could start with second point as all subsequent, cause
141 path couldn't contain only one */
142 for(i = iterator->marker_pos + 1; i < iterator->pathdata.Count; i++){
143 if((iterator->pathdata.Types[i] & PathPointTypePathMarker) ||
144 (i == iterator->pathdata.Count - 1)){
145 *startIndex = iterator->marker_pos;
146 if(iterator->marker_pos > 0) (*startIndex)++;
147 *endIndex = iterator->marker_pos = i;
148 *resultCount= *endIndex - *startIndex + 1;
149 break;
153 return Ok;
156 GpStatus WINGDIPAPI GdipPathIterNextSubpath(GpPathIterator* iterator,
157 INT *resultCount, INT* startIndex, INT* endIndex, BOOL* isClosed)
159 INT i, count;
161 if(!iterator || !startIndex || !endIndex || !isClosed || !resultCount)
162 return InvalidParameter;
164 count = iterator->pathdata.Count;
166 /* iterator created with NULL path */
167 if(count == 0){
168 *resultCount = 0;
169 return Ok;
172 if(iterator->subpath_pos == count){
173 *startIndex = *endIndex = *resultCount = 0;
174 *isClosed = 1;
175 return Ok;
178 *startIndex = iterator->subpath_pos;
180 for(i = iterator->subpath_pos + 1; i < count &&
181 !(iterator->pathdata.Types[i] == PathPointTypeStart); i++);
183 *endIndex = i - 1;
184 iterator->subpath_pos = i;
186 *resultCount = *endIndex - *startIndex + 1;
188 if(iterator->pathdata.Types[*endIndex] & PathPointTypeCloseSubpath)
189 *isClosed = TRUE;
190 else
191 *isClosed = FALSE;
193 return Ok;
195 GpStatus WINGDIPAPI GdipPathIterRewind(GpPathIterator *iterator)
197 if(!iterator)
198 return InvalidParameter;
200 iterator->subpath_pos = 0;
201 iterator->marker_pos = 0;
202 iterator->pathtype_pos = 0;
204 return Ok;
207 GpStatus WINGDIPAPI GdipPathIterGetCount(GpPathIterator* iterator, INT* count)
209 if(!iterator || !count)
210 return InvalidParameter;
212 *count = iterator->pathdata.Count;
214 return Ok;
217 GpStatus WINGDIPAPI GdipPathIterEnumerate(GpPathIterator* iterator, INT* resultCount,
218 GpPointF *points, BYTE *types, INT count)
220 if((count < 0) || !resultCount)
221 return InvalidParameter;
223 if(count == 0){
224 *resultCount = 0;
225 return Ok;
228 return GdipPathIterCopyData(iterator, resultCount, points, types, 0, count-1);
231 GpStatus WINGDIPAPI GdipPathIterIsValid(GpPathIterator* iterator, BOOL* valid)
233 if(!iterator || !valid)
234 return InvalidParameter;
236 *valid = TRUE;
238 return Ok;
241 GpStatus WINGDIPAPI GdipPathIterNextSubpathPath(GpPathIterator* iter, INT* result,
242 GpPath* path, BOOL* closed)
244 INT start, end;
246 if(!iter || !result || !closed)
247 return InvalidParameter;
249 GdipPathIterNextSubpath(iter, result, &start, &end, closed);
250 /* return path */
251 if(((*result) > 0) && path){
252 GdipResetPath(path);
254 if(!lengthen_path(path, *result))
255 return OutOfMemory;
257 memcpy(path->pathdata.Points, &(iter->pathdata.Points[start]), sizeof(GpPointF)*(*result));
258 memcpy(path->pathdata.Types, &(iter->pathdata.Types[start]), sizeof(BYTE)*(*result));
259 path->pathdata.Count = *result;
262 return Ok;