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
28 #include "gdiplus_private.h"
30 GpStatus WINGDIPAPI
GdipCreatePathIter(GpPathIterator
**iterator
, GpPath
* path
)
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;
57 GpStatus WINGDIPAPI
GdipDeletePathIter(GpPathIterator
*iter
)
60 return InvalidParameter
;
62 GdipFree(iter
->pathdata
.Types
);
63 GdipFree(iter
->pathdata
.Points
);
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
){
81 *resultCount
= endIndex
- startIndex
+ 1;
83 memcpy(types
, &(iterator
->pathdata
.Types
[startIndex
]), *resultCount
);
84 memcpy(points
, &(iterator
->pathdata
.Points
[startIndex
]),
85 *resultCount
* sizeof(PointF
));
90 GpStatus WINGDIPAPI
GdipPathIterHasCurve(GpPathIterator
* iterator
, BOOL
* hasCurve
)
95 return InvalidParameter
;
99 for(i
= 0; i
< iterator
->pathdata
.Count
; i
++)
100 if((iterator
->pathdata
.Types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
108 GpStatus WINGDIPAPI
GdipPathIterGetSubpathCount(GpPathIterator
* iterator
, INT
* count
)
112 if(!iterator
|| !count
)
113 return InvalidParameter
;
116 for(i
= 0; i
< iterator
->pathdata
.Count
; i
++){
117 if(iterator
->pathdata
.Types
[i
] == PathPointTypeStart
)
124 GpStatus WINGDIPAPI
GdipPathIterNextMarker(GpPathIterator
* iterator
, INT
*resultCount
,
125 INT
* startIndex
, INT
* endIndex
)
129 if(!iterator
|| !startIndex
|| !endIndex
)
130 return InvalidParameter
;
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;
149 GpStatus WINGDIPAPI
GdipPathIterNextSubpath(GpPathIterator
* iterator
,
150 INT
*resultCount
, INT
* startIndex
, INT
* endIndex
, BOOL
* isClosed
)
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;
165 *startIndex
= iterator
->subpath_pos
;
167 for(i
= iterator
->subpath_pos
+ 1; i
< count
&&
168 !(iterator
->pathdata
.Types
[i
] == PathPointTypeStart
); i
++);
171 iterator
->subpath_pos
= i
;
173 *resultCount
= *endIndex
- *startIndex
+ 1;
175 if(iterator
->pathdata
.Types
[*endIndex
] & PathPointTypeCloseSubpath
)
182 GpStatus WINGDIPAPI
GdipPathIterRewind(GpPathIterator
*iterator
)
185 return InvalidParameter
;
187 iterator
->subpath_pos
= 0;
188 iterator
->marker_pos
= 0;
189 iterator
->pathtype_pos
= 0;
194 GpStatus WINGDIPAPI
GdipPathIterGetCount(GpPathIterator
* iterator
, INT
* count
)
196 if(!iterator
|| !count
)
197 return InvalidParameter
;
199 *count
= iterator
->pathdata
.Count
;
204 GpStatus WINGDIPAPI
GdipPathIterEnumerate(GpPathIterator
* iterator
, INT
* resultCount
,
205 GpPointF
*points
, BYTE
*types
, INT count
)
207 if((count
< 0) || !resultCount
)
208 return InvalidParameter
;
215 return GdipPathIterCopyData(iterator
, resultCount
, points
, types
, 0, count
-1);