X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fgfxpoly%2Fconvert.c;h=9fbe40d2620752e6f57201048bc1e1fda5878163;hb=HEAD;hp=39517d7c7743043eb6f4a23f434bd91cd63c31cb;hpb=ff04f157cec57e3a19a7078040e1d9604812d32c;p=swftools.git diff --git a/lib/gfxpoly/convert.c b/lib/gfxpoly/convert.c index 39517d7..9fbe40d 100644 --- a/lib/gfxpoly/convert.c +++ b/lib/gfxpoly/convert.c @@ -92,11 +92,11 @@ static void convert_file(const char*filename, polywriter_t*w, double gridsize) break; double x,y; char s[256]; - if(sscanf(line, "%lf %lf %s", &x, &y, &s) == 3) { - if(s && !strcmp(s,"moveto")) { + if(sscanf(line, "%lf %lf %s", &x, &y, (char*)&s) == 3) { + if(!strcmp(s,"moveto")) { w->moveto(w, convert_coord(x,z), convert_coord(y,z)); count++; - } else if(s && !strcmp(s,"lineto")) { + } else if(!strcmp(s,"lineto")) { w->lineto(w, convert_coord(x,z), convert_coord(y,z)); count++; } else { @@ -133,6 +133,7 @@ void finish_segment(compactpoly_t*data) return; point_t*p = malloc(sizeof(point_t)*data->num_points); gfxpolystroke_t*s = rfx_calloc(sizeof(gfxpolystroke_t)); + s->fs = &edgestyle_default; s->next = data->poly->strokes; data->poly->strokes = s; s->num_points = s->points_size = data->num_points; @@ -166,19 +167,29 @@ static void compactmoveto(polywriter_t*w, int32_t x, int32_t y) } data->last = p; } + +static inline int direction(point_t p1, point_t p2) +{ + int diff = p1.y - p2.y; + if(diff) return diff; + return p1.x - p2.x; +} + static void compactlineto(polywriter_t*w, int32_t x, int32_t y) { compactpoly_t*data = (compactpoly_t*)w->internal; point_t p; p.x = x; p.y = y; - if(p.x == data->last.x && p.y == data->last.y) + + int diff = direction(p, data->last); + if(!diff) return; + segment_dir_t dir = diff<0?DIR_UP:DIR_DOWN; - if((p.y < data->last.y && data->dir != DIR_UP) || - (p.y > data->last.y && data->dir != DIR_DOWN) || data->new) { + if(dir!=data->dir || data->new) { finish_segment(data); - data->dir = p.y > data->last.y ? DIR_DOWN : DIR_UP; + data->dir = dir; data->points[0] = data->last; data->num_points = 1; } @@ -513,7 +524,7 @@ gfxline_t*gfxline_from_gfxpoly(gfxpoly_t*poly) return mkgfxline(poly, 0); } -gfxline_t*gfxline_from_gfxpoly_updown(gfxpoly_t*poly) +gfxline_t*gfxline_from_gfxpoly_with_direction(gfxpoly_t*poly) { return mkgfxline(poly, 1); }