Revert "winex11.drv: Optimise getting the bits of a DIB after calling SetDIBits."
[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 #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 GdipPathIterGetSubpathCount(GpPathIterator* iterator, INT* count)
109 {
110     INT i;
111
112     if(!iterator || !count)
113         return InvalidParameter;
114
115     *count = 0;
116     for(i = 0; i < iterator->pathdata.Count; i++){
117         if(iterator->pathdata.Types[i] == PathPointTypeStart)
118             (*count)++;
119     }
120
121     return Ok;
122 }
123
124 GpStatus WINGDIPAPI GdipPathIterNextMarker(GpPathIterator* iterator, INT *resultCount,
125     INT* startIndex, INT* endIndex)
126 {
127     INT i;
128
129     if(!iterator || !startIndex || !endIndex)
130         return InvalidParameter;
131
132     *resultCount = 0;
133
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;
143         }
144     }
145
146     return Ok;
147 }
148
149 GpStatus WINGDIPAPI GdipPathIterNextSubpath(GpPathIterator* iterator,
150     INT *resultCount, INT* startIndex, INT* endIndex, BOOL* isClosed)
151 {
152     INT i, count;
153
154     if(!iterator || !startIndex || !endIndex || !isClosed || !resultCount)
155         return InvalidParameter;
156
157     count = iterator->pathdata.Count;
158
159     if(iterator->subpath_pos == count){
160         *startIndex = *endIndex = *resultCount = 0;
161         *isClosed = 1;
162         return Ok;
163     }
164
165     *startIndex = iterator->subpath_pos;
166
167     for(i = iterator->subpath_pos + 1; i < count &&
168         !(iterator->pathdata.Types[i] == PathPointTypeStart); i++);
169
170     *endIndex = i - 1;
171     iterator->subpath_pos = i;
172
173     *resultCount = *endIndex - *startIndex + 1;
174
175     if(iterator->pathdata.Types[*endIndex] & PathPointTypeCloseSubpath)
176         *isClosed = TRUE;
177     else
178         *isClosed = FALSE;
179
180     return Ok;
181 }
182 GpStatus WINGDIPAPI GdipPathIterRewind(GpPathIterator *iterator)
183 {
184     if(!iterator)
185         return InvalidParameter;
186
187     iterator->subpath_pos = 0;
188     iterator->marker_pos = 0;
189     iterator->pathtype_pos = 0;
190
191     return Ok;
192 }
193
194 GpStatus WINGDIPAPI GdipPathIterGetCount(GpPathIterator* iterator, INT* count)
195 {
196     if(!iterator || !count)
197         return InvalidParameter;
198
199     *count = iterator->pathdata.Count;
200
201     return Ok;
202 }
203
204 GpStatus WINGDIPAPI GdipPathIterEnumerate(GpPathIterator* iterator, INT* resultCount,
205     GpPointF *points, BYTE *types, INT count)
206 {
207     if((count < 0) || !resultCount)
208         return InvalidParameter;
209
210     if(count == 0){
211         *resultCount = 0;
212         return Ok;
213     }
214
215     return GdipPathIterCopyData(iterator, resultCount, points, types, 0, count-1);
216 }