quartz: Only allocate 1 buffer in transform filter.
[wine/wine64.git] / dlls / gdiplus / pathiterator.c
blob026665a3a78bdade1eaabac6c7a690c9d7f42ab4
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 || !path)
35 return InvalidParameter;
37 size = path->pathdata.Count;
39 *iterator = GdipAlloc(sizeof(GpPathIterator));
40 if(!*iterator) return OutOfMemory;
42 (*iterator)->pathdata.Types = GdipAlloc(size);
43 (*iterator)->pathdata.Points = GdipAlloc(size * sizeof(PointF));
45 memcpy((*iterator)->pathdata.Types, path->pathdata.Types, size);
46 memcpy((*iterator)->pathdata.Points, path->pathdata.Points,
47 size * sizeof(PointF));
48 (*iterator)->pathdata.Count = size;
50 (*iterator)->subpath_pos = 0;
51 (*iterator)->marker_pos = 0;
52 (*iterator)->pathtype_pos = 0;
54 return Ok;
57 GpStatus WINGDIPAPI GdipDeletePathIter(GpPathIterator *iter)
59 if(!iter)
60 return InvalidParameter;
62 GdipFree(iter->pathdata.Types);
63 GdipFree(iter->pathdata.Points);
64 GdipFree(iter);
66 return Ok;
69 GpStatus WINGDIPAPI GdipPathIterCopyData(GpPathIterator* iterator,
70 INT* resultCount, GpPointF* points, BYTE* types, INT startIndex, INT endIndex)
72 if(!iterator || !types || !points)
73 return InvalidParameter;
75 if(endIndex > iterator->pathdata.Count - 1 || startIndex < 0 ||
76 endIndex < startIndex){
77 *resultCount = 0;
78 return Ok;
81 *resultCount = endIndex - startIndex + 1;
83 memcpy(types, &(iterator->pathdata.Types[startIndex]), *resultCount);
84 memcpy(points, &(iterator->pathdata.Points[startIndex]),
85 *resultCount * sizeof(PointF));
87 return Ok;
90 GpStatus WINGDIPAPI GdipPathIterHasCurve(GpPathIterator* iterator, BOOL* hasCurve)
92 INT i;
94 if(!iterator)
95 return InvalidParameter;
97 *hasCurve = FALSE;
99 for(i = 0; i < iterator->pathdata.Count; i++)
100 if((iterator->pathdata.Types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
101 *hasCurve = TRUE;
102 break;
105 return Ok;
108 GpStatus WINGDIPAPI GdipPathIterGetSubpathCount(GpPathIterator* iterator, INT* count)
110 INT i;
112 if(!iterator || !count)
113 return InvalidParameter;
115 *count = 0;
116 for(i = 0; i < iterator->pathdata.Count; i++){
117 if(iterator->pathdata.Types[i] == PathPointTypeStart)
118 (*count)++;
121 return Ok;
124 GpStatus WINGDIPAPI GdipPathIterNextMarker(GpPathIterator* iterator, INT *resultCount,
125 INT* startIndex, INT* endIndex)
127 INT i;
129 if(!iterator || !startIndex || !endIndex)
130 return InvalidParameter;
132 *resultCount = 0;
134 /* first call could start with second point as all subsequent, cause
135 path couldn't contain only one */
136 for(i = iterator->marker_pos + 1; i < iterator->pathdata.Count; i++){
137 if(iterator->pathdata.Types[i] & PathPointTypePathMarker){
138 *startIndex = iterator->marker_pos;
139 if(iterator->marker_pos > 0) (*startIndex)++;
140 *endIndex = iterator->marker_pos = i;
141 *resultCount= *endIndex - *startIndex + 1;
142 break;
146 return Ok;
149 GpStatus WINGDIPAPI GdipPathIterNextSubpath(GpPathIterator* iterator,
150 INT *resultCount, INT* startIndex, INT* endIndex, BOOL* isClosed)
152 INT i, count;
154 if(!iterator || !startIndex || !endIndex || !isClosed || !resultCount)
155 return InvalidParameter;
157 count = iterator->pathdata.Count;
159 if(iterator->subpath_pos == count){
160 *startIndex = *endIndex = *resultCount = 0;
161 *isClosed = 1;
162 return Ok;
165 *startIndex = iterator->subpath_pos;
167 for(i = iterator->subpath_pos + 1; i < count &&
168 !(iterator->pathdata.Types[i] == PathPointTypeStart); i++);
170 *endIndex = i - 1;
171 iterator->subpath_pos = i;
173 *resultCount = *endIndex - *startIndex + 1;
175 if(iterator->pathdata.Types[*endIndex] & PathPointTypeCloseSubpath)
176 *isClosed = TRUE;
177 else
178 *isClosed = FALSE;
180 return Ok;
182 GpStatus WINGDIPAPI GdipPathIterRewind(GpPathIterator *iterator)
184 if(!iterator)
185 return InvalidParameter;
187 iterator->subpath_pos = 0;
188 iterator->marker_pos = 0;
189 iterator->pathtype_pos = 0;
191 return Ok;
194 GpStatus WINGDIPAPI GdipPathIterGetCount(GpPathIterator* iterator, INT* count)
196 if(!iterator || !count)
197 return InvalidParameter;
199 *count = iterator->pathdata.Count;
201 return Ok;
204 GpStatus WINGDIPAPI GdipPathIterEnumerate(GpPathIterator* iterator, INT* resultCount,
205 GpPointF *points, BYTE *types, INT count)
207 if((count < 0) || !resultCount)
208 return InvalidParameter;
210 if(count == 0){
211 *resultCount = 0;
212 return Ok;
215 return GdipPathIterCopyData(iterator, resultCount, points, types, 0, count-1);