Autosyncing with Wine HEAD
[reactos.git] / reactos / dll / win32 / 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 #include "wingdi.h"
24
25 #include "objbase.h"
26
27 #include "gdiplus.h"
28 #include "gdiplus_private.h"
29
30 GpStatus WINGDIPAPI GdipCreatePathIter(GpPathIterator **iterator, GpPath* path)
31 {
32 INT size;
33
34 if(!iterator || !path)
35 return InvalidParameter;
36
37 size = path->pathdata.Count;
38
39 *iterator = GdipAlloc(sizeof(GpPathIterator));
40 if(!*iterator) return OutOfMemory;
41
42 (*iterator)->pathdata.Types = GdipAlloc(size);
43 (*iterator)->pathdata.Points = GdipAlloc(size * sizeof(PointF));
44
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;
49
50 (*iterator)->subpath_pos = 0;
51 (*iterator)->marker_pos = 0;
52 (*iterator)->pathtype_pos = 0;
53
54 return Ok;
55 }
56
57 GpStatus WINGDIPAPI GdipDeletePathIter(GpPathIterator *iter)
58 {
59 if(!iter)
60 return InvalidParameter;
61
62 GdipFree(iter->pathdata.Types);
63 GdipFree(iter->pathdata.Points);
64 GdipFree(iter);
65
66 return Ok;
67 }
68
69 GpStatus WINGDIPAPI GdipPathIterCopyData(GpPathIterator* iterator,
70 INT* resultCount, GpPointF* points, BYTE* types, INT startIndex, INT endIndex)
71 {
72 if(!iterator || !types || !points)
73 return InvalidParameter;
74
75 if(endIndex > iterator->pathdata.Count - 1 || startIndex < 0 ||
76 endIndex < startIndex){
77 *resultCount = 0;
78 return Ok;
79 }
80
81 *resultCount = endIndex - startIndex + 1;
82
83 memcpy(types, &(iterator->pathdata.Types[startIndex]), *resultCount);
84 memcpy(points, &(iterator->pathdata.Points[startIndex]),
85 *resultCount * sizeof(PointF));
86
87 return Ok;
88 }
89
90 GpStatus WINGDIPAPI GdipPathIterHasCurve(GpPathIterator* iterator, BOOL* hasCurve)
91 {
92 INT i;
93
94 if(!iterator)
95 return InvalidParameter;
96
97 *hasCurve = FALSE;
98
99 for(i = 0; i < iterator->pathdata.Count; i++)
100 if((iterator->pathdata.Types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
101 *hasCurve = TRUE;
102 break;
103 }
104
105 return Ok;
106 }
107
108 GpStatus WINGDIPAPI GdipPathIterNextSubpath(GpPathIterator* iterator,
109 INT *resultCount, INT* startIndex, INT* endIndex, BOOL* isClosed)
110 {
111 INT i, count;
112
113 if(!iterator)
114 return InvalidParameter;
115
116 count = iterator->pathdata.Count;
117
118 if(iterator->subpath_pos == count){
119 *startIndex = *endIndex = *resultCount = 0;
120 *isClosed = 1;
121 return Ok;
122 }
123
124 *startIndex = iterator->subpath_pos;
125
126 for(i = iterator->subpath_pos + 1; i < count &&
127 !(iterator->pathdata.Types[i] == PathPointTypeStart); i++);
128
129 *endIndex = i - 1;
130 iterator->subpath_pos = i;
131
132 *resultCount = *endIndex - *startIndex + 1;
133
134 if(iterator->pathdata.Types[*endIndex] & PathPointTypeCloseSubpath)
135 *isClosed = TRUE;
136 else
137 *isClosed = FALSE;
138
139 return Ok;
140 }
141 GpStatus WINGDIPAPI GdipPathIterRewind(GpPathIterator *iterator)
142 {
143 if(!iterator)
144 return InvalidParameter;
145
146 iterator->subpath_pos = 0;
147 iterator->marker_pos = 0;
148 iterator->pathtype_pos = 0;
149
150 return Ok;
151 }
152
153 GpStatus WINGDIPAPI GdipPathIterGetCount(GpPathIterator* iterator, INT* count)
154 {
155 if(!iterator || !count)
156 return InvalidParameter;
157
158 *count = iterator->pathdata.Count;
159
160 return Ok;
161 }
162
163 GpStatus WINGDIPAPI GdipPathIterEnumerate(GpPathIterator* iterator, INT* resultCount,
164 GpPointF *points, BYTE *types, INT count)
165 {
166 if((count < 0) || !resultCount)
167 return InvalidParameter;
168
169 if(count == 0){
170 *resultCount = 0;
171 return Ok;
172 }
173
174 return GdipPathIterCopyData(iterator, resultCount, points, types, 0, count-1);
175 }