X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fgfxpoly%2Fconvert.c;h=0e458be37346bc59eebf00e5a4719e2f6e238f76;hp=f293d164750cca21ac19d8cc3a9dc0c6eaf389d5;hb=f7e9e8a9616f1ecb26776369fda6807cf8821a68;hpb=de3641737991ed13571eb947068472cf73001032 diff --git a/lib/gfxpoly/convert.c b/lib/gfxpoly/convert.c index f293d16..0e458be 100644 --- a/lib/gfxpoly/convert.c +++ b/lib/gfxpoly/convert.c @@ -5,6 +5,9 @@ #include "../mem.h" #include "poly.h" +/* factor that determines into how many line fragments a spline is converted */ +#define SUBFRACTION (2.4) + static edge_t*edge_new(int x1, int y1, int x2, int y2) { edge_t*s = rfx_calloc(sizeof(edge_t)); @@ -17,10 +20,23 @@ static edge_t*edge_new(int x1, int y1, int x2, int y2) static inline void gfxpoly_add_edge(gfxpoly_t*poly, double _x1, double _y1, double _x2, double _y2) { + /* we clamp to 31 bit instead of 32 bit because we use + a (x1-x2) shortcut when comparing coordinates + */ + if(_x1 < -0x40000000) _x1 = -0x40000000; + if(_x1 > 0x3fffffff) _x1 = 0x3fffffff; + if(_y1 < -0x40000000) _y1 = -0x40000000; + if(_y1 > 0x3fffffff) _y1 = 0x3fffffff; + if(_x2 < -0x40000000) _x2 = -0x40000000; + if(_x2 > 0x3fffffff) _x2 = 0x3fffffff; + if(_y2 < -0x40000000) _y2 = -0x40000000; + if(_y2 > 0x3fffffff) _y2 = 0x3fffffff; + int x1 = ceil(_x1); int y1 = ceil(_y1); int x2 = ceil(_x2); int y2 = ceil(_y2); + if(x1!=x2 || y1!=y2) { edge_t*s = edge_new(x1, y1, x2, y2); s->next = poly->edges; @@ -32,9 +48,6 @@ gfxpoly_t* gfxpoly_from_gfxline(gfxline_t*line, double gridsize) { gfxpoly_t*p = gfxpoly_new(gridsize); - /* factor that determines into how many line fragments a spline is converted */ - double subfraction = 2.4;//0.3 - double z = 1.0 / gridsize; double lastx=0, lasty=0; @@ -47,7 +60,7 @@ gfxpoly_t* gfxpoly_from_gfxline(gfxline_t*line, double gridsize) gfxpoly_add_edge(p, lastx, lasty, x, y); } else if(line->type == gfx_splineTo) { int parts = (int)(sqrt(fabs(line->x-2*line->sx+lastx) + - fabs(line->y-2*line->sy+lasty))*subfraction); + fabs(line->y-2*line->sy+lasty))*SUBFRACTION); if(!parts) parts = 1; double stepsize = 1.0/parts; int i; @@ -65,11 +78,23 @@ gfxpoly_t* gfxpoly_from_gfxline(gfxline_t*line, double gridsize) lasty = y; line = line->next; } - + gfxline_free(line); return p; } +typedef struct _gfxstroke { + segment_dir_t dir; + point_t*stroke; + fillstyle_t*fs; + int num_points; +} gfxstroke_t; +typedef struct _gfxcompactpoly { + double gridsize; + int num_strokes; + gfxstroke_t strokes[0]; +} gfxcompactpoly_t; + static char* readline(FILE*fi) { char c; @@ -104,6 +129,7 @@ gfxpoly_t* gfxpoly_from_file(const char*filename, double gridsize) return 0; } int count = 0; + double g = 0; double lastx=0,lasty=0; while(1) { char*line = readline(fi); @@ -124,10 +150,16 @@ gfxpoly_t* gfxpoly_from_file(const char*filename, double gridsize) } lastx = x; lasty = y; + } else if(sscanf(line, "%% gridsize %lf", &g) == 1) { + p->gridsize = g; } free(line); } fclose(fi); - printf("loaded %d points from %s\n", count, filename); + if(g) { + printf("loaded %d points from %s (gridsize %f)\n", count, filename, g); + } else { + printf("loaded %d points from %s\n", count, filename); + } return p; }