X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswfdraw.c;h=2613e0cc441efd17fb8e3ec9fc364ae96f70b4c2;hb=6c3ab5574d31504d24710c2756899d49275c1a37;hp=f9a28829f5cfd593ea326c115048271ddc01ac6e;hpb=19c7bc67ec99913b1f0ec52c5f98d56ef0345c3b;p=swftools.git diff --git a/lib/modules/swfdraw.c b/lib/modules/swfdraw.c index f9a2882..2613e0c 100644 --- a/lib/modules/swfdraw.c +++ b/lib/modules/swfdraw.c @@ -23,8 +23,7 @@ static void swf_ShapeDrawerClear(drawer_t*draw); static void swf_ShapeDrawerInit(drawer_t*draw, TAG*tag, int fillstylebits, int linestylebits) { - SWFSHAPEDRAWER*sdraw = malloc(sizeof(SWFSHAPEDRAWER)); - memset(sdraw, 0, sizeof(SWFSHAPEDRAWER)); + SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)rfx_calloc(sizeof(SWFSHAPEDRAWER)); draw->internal = sdraw; draw->setLineStyle = swf_ShapeDrawerSetLineStyle; @@ -57,6 +56,11 @@ static void swf_ShapeDrawerInit(drawer_t*draw, TAG*tag, int fillstylebits, int l swf_ShapeSetStyle(sdraw->tag,sdraw->shape,linestylebits?1:0,fillstylebits?1:0,0/*?*/); } +void swf_Shape10DrawerInit(drawer_t*draw, TAG*tag) +{ + swf_ShapeDrawerInit(draw, tag, 0, 1); +} + void swf_Shape01DrawerInit(drawer_t*draw, TAG*tag) { swf_ShapeDrawerInit(draw, tag, 1, 0); @@ -81,31 +85,40 @@ static void fixEndPoint(drawer_t*draw) if( sdraw->firstx != sdraw->lastx || sdraw->firsty != sdraw->lasty) { /* fix non-closing shapes */ - /* TODO: do this only if the shape is filled */ FPOINT to; to.x = sdraw->firstx/20.0; to.y = sdraw->firsty/20.0; - draw->lineTo(draw, &to); + if(sdraw->shape->bits.fill) // do this only if the shape is filled + draw->lineTo(draw, &to); } } static void swf_ShapeDrawerMoveTo(drawer_t*draw, FPOINT * to) { SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal; - int x = to->x*20; - int y = to->y*20; - if(sdraw->lastx != x || sdraw->lasty != y) { + int x = to->x*20+0.001; + int y = to->y*20+0.001; + + /* we need to write moveto always- it + might be that it signals the end of a polygon, otherwise + we would end up connecting two polygons which should + be seperate + TODO: check if the last operation was a moveTo- if + yes we *can* skip it. + */ + + //if(sdraw->lastx != x || sdraw->lasty != y) { fixEndPoint(draw); swf_ShapeSetMove(sdraw->tag,sdraw->shape,x,y); sdraw->firstx = sdraw->lastx = x; sdraw->firsty = sdraw->lasty = y; draw->pos = *to; - } + //} } static void swf_ShapeDrawerLineTo(drawer_t*draw, FPOINT * to) { SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal; - int x = to->x*20; - int y = to->y*20; + int x = to->x*20+0.001; + int y = to->y*20+0.001; if(sdraw->lastx < sdraw->bbox.xmin) sdraw->bbox.xmin = sdraw->lastx; if(sdraw->lasty < sdraw->bbox.ymin) sdraw->bbox.ymin = sdraw->lasty; if(sdraw->lastx > sdraw->bbox.xmax) sdraw->bbox.xmax = sdraw->lastx; @@ -122,10 +135,10 @@ static void swf_ShapeDrawerLineTo(drawer_t*draw, FPOINT * to) static void swf_ShapeDrawerSplineTo(drawer_t*draw, FPOINT * c1, FPOINT* to) { SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal; - int tx = c1->x*20; - int ty = c1->y*20; - int x = to->x*20; - int y = to->y*20; + int tx = c1->x*20+0.001; + int ty = c1->y*20+0.001; + int x = to->x*20+0.001; + int y = to->y*20+0.001; if(sdraw->lastx < sdraw->bbox.xmin) sdraw->bbox.xmin = sdraw->lastx; if(sdraw->lasty < sdraw->bbox.ymin) sdraw->bbox.ymin = sdraw->lasty; if(sdraw->lastx > sdraw->bbox.xmax) sdraw->bbox.xmax = sdraw->lastx; @@ -146,6 +159,8 @@ static void swf_ShapeDrawerSplineTo(drawer_t*draw, FPOINT * c1, FPOINT* to) static void swf_ShapeDrawerFinish(drawer_t*draw) { SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal; + if(sdraw->isfinished) + return; fixEndPoint(draw); @@ -168,7 +183,7 @@ static void swf_ShapeDrawerClear(drawer_t*draw) swf_ShapeFree(sdraw->shape); sdraw->shape = 0; - free(draw->internal); + rfx_free(draw->internal); draw->internal = 0; } @@ -181,14 +196,14 @@ SRECT swf_ShapeDrawerGetBBox(drawer_t*draw) SHAPE* swf_ShapeDrawerToShape(drawer_t*draw) { SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal; - SHAPE* shape = malloc(sizeof(SHAPE)); + SHAPE* shape = (SHAPE*)rfx_alloc(sizeof(SHAPE)); if(!sdraw->isfinished) { fprintf(stderr, "Warning: you should Finish() your drawer before calling DrawerToShape"); swf_ShapeDrawerFinish(draw); } memcpy(shape, sdraw->shape, sizeof(SHAPE)); shape->bitlen = (sdraw->tag->len-1)*8; - shape->data = (U8*)malloc(sdraw->tag->len-1); + shape->data = (U8*)rfx_alloc(sdraw->tag->len-1); memcpy(shape->data, &sdraw->tag->data[1], sdraw->tag->len-1); return shape; }