2 * Copyright (C) 2007 Google (Evan Stade)
3 * Copyright (C) 2008 Nikolay Sivov <bunglehead at gmail dot com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "gdiplus_private.h"
22 GpStatus WINGDIPAPI
GdipCreatePathIter(GpPathIterator
**iterator
, GpPath
* path
)
26 TRACE("(%p, %p)\n", iterator
, path
);
29 return InvalidParameter
;
31 *iterator
= GdipAlloc(sizeof(GpPathIterator
));
32 if(!*iterator
) return OutOfMemory
;
35 size
= path
->pathdata
.Count
;
37 (*iterator
)->pathdata
.Types
= GdipAlloc(size
);
38 (*iterator
)->pathdata
.Points
= GdipAlloc(size
* sizeof(PointF
));
40 memcpy((*iterator
)->pathdata
.Types
, path
->pathdata
.Types
, size
);
41 memcpy((*iterator
)->pathdata
.Points
, path
->pathdata
.Points
,size
* sizeof(PointF
));
42 (*iterator
)->pathdata
.Count
= size
;
45 (*iterator
)->pathdata
.Types
= NULL
;
46 (*iterator
)->pathdata
.Points
= NULL
;
47 (*iterator
)->pathdata
.Count
= 0;
50 (*iterator
)->subpath_pos
= 0;
51 (*iterator
)->marker_pos
= 0;
52 (*iterator
)->pathtype_pos
= 0;
57 GpStatus WINGDIPAPI
GdipDeletePathIter(GpPathIterator
*iter
)
59 TRACE("(%p)\n", iter
);
62 return InvalidParameter
;
64 GdipFree(iter
->pathdata
.Types
);
65 GdipFree(iter
->pathdata
.Points
);
71 GpStatus WINGDIPAPI
GdipPathIterCopyData(GpPathIterator
* iterator
,
72 INT
* resultCount
, GpPointF
* points
, BYTE
* types
, INT startIndex
, INT endIndex
)
74 TRACE("(%p, %p, %p, %p, %d, %d)\n", iterator
, resultCount
, points
, types
,
75 startIndex
, endIndex
);
77 if(!iterator
|| !types
|| !points
)
78 return InvalidParameter
;
80 if(endIndex
> iterator
->pathdata
.Count
- 1 || startIndex
< 0 ||
81 endIndex
< startIndex
){
86 *resultCount
= endIndex
- startIndex
+ 1;
88 memcpy(types
, &(iterator
->pathdata
.Types
[startIndex
]), *resultCount
);
89 memcpy(points
, &(iterator
->pathdata
.Points
[startIndex
]),
90 *resultCount
* sizeof(PointF
));
95 GpStatus WINGDIPAPI
GdipPathIterHasCurve(GpPathIterator
* iterator
, BOOL
* hasCurve
)
99 TRACE("(%p, %p)\n", iterator
, hasCurve
);
102 return InvalidParameter
;
106 for(i
= 0; i
< iterator
->pathdata
.Count
; i
++)
107 if((iterator
->pathdata
.Types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
115 GpStatus WINGDIPAPI
GdipPathIterGetSubpathCount(GpPathIterator
* iterator
, INT
* count
)
119 TRACE("(%p, %p)\n", iterator
, count
);
121 if(!iterator
|| !count
)
122 return InvalidParameter
;
125 for(i
= 0; i
< iterator
->pathdata
.Count
; i
++){
126 if(iterator
->pathdata
.Types
[i
] == PathPointTypeStart
)
133 GpStatus WINGDIPAPI
GdipPathIterNextMarker(GpPathIterator
* iterator
, INT
*resultCount
,
134 INT
* startIndex
, INT
* endIndex
)
138 TRACE("(%p, %p, %p, %p)\n", iterator
, resultCount
, startIndex
, endIndex
);
140 if(!iterator
|| !startIndex
|| !endIndex
)
141 return InvalidParameter
;
145 /* first call could start with second point as all subsequent, cause
146 path couldn't contain only one */
147 for(i
= iterator
->marker_pos
+ 1; i
< iterator
->pathdata
.Count
; i
++){
148 if((iterator
->pathdata
.Types
[i
] & PathPointTypePathMarker
) ||
149 (i
== iterator
->pathdata
.Count
- 1)){
150 *startIndex
= iterator
->marker_pos
;
151 if(iterator
->marker_pos
> 0) (*startIndex
)++;
152 *endIndex
= iterator
->marker_pos
= i
;
153 *resultCount
= *endIndex
- *startIndex
+ 1;
161 GpStatus WINGDIPAPI
GdipPathIterNextMarkerPath(GpPathIterator
* iterator
, INT
* result
,
166 TRACE("(%p, %p, %p)\n", iterator
, result
, path
);
168 if(!iterator
|| !result
)
169 return InvalidParameter
;
171 GdipPathIterNextMarker(iterator
, result
, &start
, &end
);
173 if(((*result
) > 0) && path
){
176 if(!lengthen_path(path
, *result
))
179 memcpy(path
->pathdata
.Points
, &(iterator
->pathdata
.Points
[start
]), sizeof(GpPointF
)*(*result
));
180 memcpy(path
->pathdata
.Types
, &(iterator
->pathdata
.Types
[start
]), sizeof(BYTE
)*(*result
));
181 path
->pathdata
.Count
= *result
;
187 GpStatus WINGDIPAPI
GdipPathIterNextSubpath(GpPathIterator
* iterator
,
188 INT
*resultCount
, INT
* startIndex
, INT
* endIndex
, BOOL
* isClosed
)
192 TRACE("(%p, %p, %p, %p, %p)\n", iterator
, resultCount
, startIndex
,
195 if(!iterator
|| !startIndex
|| !endIndex
|| !isClosed
|| !resultCount
)
196 return InvalidParameter
;
198 count
= iterator
->pathdata
.Count
;
200 /* iterator created with NULL path */
206 if(iterator
->subpath_pos
== count
){
207 *startIndex
= *endIndex
= *resultCount
= 0;
212 *startIndex
= iterator
->subpath_pos
;
214 for(i
= iterator
->subpath_pos
+ 1; i
< count
&&
215 !(iterator
->pathdata
.Types
[i
] == PathPointTypeStart
); i
++);
218 iterator
->subpath_pos
= i
;
220 *resultCount
= *endIndex
- *startIndex
+ 1;
222 if(iterator
->pathdata
.Types
[*endIndex
] & PathPointTypeCloseSubpath
)
229 GpStatus WINGDIPAPI
GdipPathIterRewind(GpPathIterator
*iterator
)
231 TRACE("(%p)\n", iterator
);
234 return InvalidParameter
;
236 iterator
->subpath_pos
= 0;
237 iterator
->marker_pos
= 0;
238 iterator
->pathtype_pos
= 0;
243 GpStatus WINGDIPAPI
GdipPathIterGetCount(GpPathIterator
* iterator
, INT
* count
)
245 TRACE("(%p, %p)\n", iterator
, count
);
247 if(!iterator
|| !count
)
248 return InvalidParameter
;
250 *count
= iterator
->pathdata
.Count
;
255 GpStatus WINGDIPAPI
GdipPathIterEnumerate(GpPathIterator
* iterator
, INT
* resultCount
,
256 GpPointF
*points
, BYTE
*types
, INT count
)
258 TRACE("(%p, %p, %p, %p, %d)\n", iterator
, resultCount
, points
, types
, count
);
260 if((count
< 0) || !resultCount
)
261 return InvalidParameter
;
268 return GdipPathIterCopyData(iterator
, resultCount
, points
, types
, 0, count
-1);
271 GpStatus WINGDIPAPI
GdipPathIterIsValid(GpPathIterator
* iterator
, BOOL
* valid
)
273 TRACE("(%p, %p)\n", iterator
, valid
);
275 if(!iterator
|| !valid
)
276 return InvalidParameter
;
283 GpStatus WINGDIPAPI
GdipPathIterNextPathType(GpPathIterator
* iter
, INT
* result
,
284 BYTE
* type
, INT
* start
, INT
* end
)
286 FIXME("(%p, %p, %p, %p, %p) stub\n", iter
, result
, type
, start
, end
);
288 if(!iter
|| !result
|| !type
|| !start
|| !end
)
289 return InvalidParameter
;
291 return NotImplemented
;
294 GpStatus WINGDIPAPI
GdipPathIterNextSubpathPath(GpPathIterator
* iter
, INT
* result
,
295 GpPath
* path
, BOOL
* closed
)
299 TRACE("(%p, %p, %p, %p)\n", iter
, result
, path
, closed
);
301 if(!iter
|| !result
|| !closed
)
302 return InvalidParameter
;
304 GdipPathIterNextSubpath(iter
, result
, &start
, &end
, closed
);
306 if(((*result
) > 0) && path
){
309 if(!lengthen_path(path
, *result
))
312 memcpy(path
->pathdata
.Points
, &(iter
->pathdata
.Points
[start
]), sizeof(GpPointF
)*(*result
));
313 memcpy(path
->pathdata
.Types
, &(iter
->pathdata
.Types
[start
]), sizeof(BYTE
)*(*result
));
314 path
->pathdata
.Count
= *result
;