257 :(NSArray*)dataArray outlineWidth:(float)outlineWidth
258{
259 NSParameterAssert(dataArray !=
nil);
260
261 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
262 GLUtesselator* tesselator = NULL;
263
264 TessPolygonData polygonData;
265 memset(&polygonData, 0, sizeof polygonData);
266 polygonData.
OK = YES;
267#ifndef NDEBUG
268 polygonData.
name = _name;
269 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"polygon-sprite-dump-svg"])
271#endif
272
273
276 goto END;
277 }
278
279 tesselator = gluNewTess();
280 if (tesselator == NULL) {
282 goto END;
283 }
284
286
287
293
294 gluTessBeginPolygon(tesselator, &polygonData);
296
297 NSUInteger contourCount = [dataArray count], contourIndex;
298 for (contourIndex = 0; contourIndex < contourCount && polygonData.
OK; contourIndex++) {
299 NSArray* contour = [dataArray oo_arrayAtIndex:contourIndex];
300 if (contour ==
nil) {
302 break;
303 }
304
306 }
307
308 gluTessEndPolygon(tesselator);
310
311 if (polygonData.
OK) {
312 _solidCount = polygonData.
count;
313
314 if (_solidCount != 0) {
315 _solidData = realloc(polygonData.
data, polygonData.
count *
sizeof(GLfloat) * 2);
316 if (_solidData != NULL)
317 polygonData.
data = NULL;
318 else {
319
320 _solidData = polygonData.
data;
321 if (_solidData == NULL)
323 }
324 } else {
325
326 _solidData = NULL;
327 }
328 }
330 goto END;
331
332
333 gluDeleteTess(tesselator);
334 tesselator = gluNewTess();
335 if (tesselator == NULL) {
337 goto END;
338 }
339
340 polygonData.
count = 0;
344 goto END;
345 }
346#ifndef NDEBUG
348#endif
349
355 gluTessProperty(tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE);
356
357 gluTessBeginPolygon(tesselator, &polygonData);
359
360 outlineWidth *= 0.5f;
361 contourCount = [dataArray count];
362 for (contourIndex = 0; contourIndex < contourCount && polygonData.
OK; contourIndex++) {
363 NSArray* contour = [dataArray oo_arrayAtIndex:contourIndex];
364 if (contour ==
nil) {
366 break;
367 }
368
371 }
372
373 gluTessEndPolygon(tesselator);
375
376 if (polygonData.
OK) {
377 if (polygonData.
count != 0) {
378 _outlineCount = polygonData.
count;
379 _outlineData = realloc(polygonData.
data, polygonData.
count *
sizeof(GLfloat) * 2);
380 if (_outlineData != NULL)
381 polygonData.
data = NULL;
382 else {
383
384 _outlineData = polygonData.
data;
385 if (_outlineData == NULL)
387 }
388 } else {
389
390 _outlineCount = 0;
391 _outlineData = NULL;
392 }
393 }
394
395END:
397 free(polygonData.
data);
398 gluDeleteTess(tesselator);
399 [pool release];
400#ifndef NDEBUG
402#endif
403 return polygonData.
OK;
404}
static void APIENTRY TessVertexCallback(void *vertexData, void *polygonData)
static void APIENTRY TessEndCallback(void *polygonData)
static void APIENTRY TessBeginCallback(GLenum type, void *polygonData)
static void SVGDumpBeginGroup(TessPolygonData *data, NSString *name)
static NSArray * DataArrayToPoints(TessPolygonData *data, NSArray *dataArray)
static void SubmitVertices(GLUtesselator *tesselator, TessPolygonData *polygonData, NSArray *contour)
static void APIENTRY ErrorCallback(GLenum error, void *polygonData)
static void APIENTRY TessCombineCallback(GLdouble coords[3], void *vertexData[4], GLfloat weight[4], void **outData, void *polygonData)
static NSArray * BuildOutlineContour(NSArray *dataArray, GLfloat width, BOOL inner)
static void SVGDumpBegin(TessPolygonData *data)
static void SVGDumpEndGroup(TessPolygonData *data)
static void SVGDumpEnd(TessPolygonData *data)
static BOOL GrowTessPolygonData(TessPolygonData *data, size_t capacityHint)
NSMutableString * debugSVG