X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fgfxtools.c;h=aec892a781349f28c60ba8a3e9d34c3a77b55194;hb=4d69b67e4c0234d1be6e84acb68f00ff0a9f869f;hp=eba172ce695ca953740bafd5d1ca15551d590792;hpb=34f34cad958196297962e61ae40d9490c5f1f8a8;p=swftools.git diff --git a/lib/gfxtools.c b/lib/gfxtools.c index eba172c..aec892a 100644 --- a/lib/gfxtools.c +++ b/lib/gfxtools.c @@ -37,6 +37,12 @@ static void linedraw_moveTo(gfxdrawer_t*d, gfxcoord_t x, gfxcoord_t y) linedraw_internal_t*i = (linedraw_internal_t*)d->internal; gfxline_t*l = rfx_alloc(sizeof(gfxline_t)); l->type = gfx_moveTo; + if((int)((d->x * 5120) == (int)(x * 5120)) && + (int)((d->y * 5120) == (int)(y * 5120))) { + /* never mind- we're already there */ + return; + + } d->x = l->x = x; d->y = l->y = y; l->next = 0; @@ -142,11 +148,13 @@ static void spline_get_controlpoint(qspline_abc_t*q, double t1, double t2, doubl static double get_spline_len(qspline_abc_t*s) { int parts = (int)(sqrt(fabs(s->ax) + fabs(s->ay))*3); - if(parts < 3) parts = 3; int i; double len = 0; - double r = 1.0/parts; - double r2 = 1.0/(parts*parts); + double r; + double r2; + if(parts < 3) parts = 3; + r = 1.0/parts; + r2 = 1.0/(parts*parts); for(i=0;iax*(2*i+1)*r2 + s->bx*r; @@ -200,11 +208,13 @@ void gfxtool_draw_dashed_line(gfxdrawer_t*d, gfxline_t*line, float*r, float phas double dx = line->x - x; double dy = line->y - y; double len = sqrt(dx*dx+dy*dy); + double vx; + double vy; + double lineend = linepos+len; if(len==0) continue; - double vx = dx/len; - double vy = dy/len; - double lineend = linepos+len; + vx = dx/len; + vy = dy/len; assert(nextpos>=linepos); //printf("(line) on:%d apos: %d nextpos: %f, line pos: %f, line end: %f\n", on, apos, nextpos, linepos, linepos+len); while(nextposx; y = line->y; } else if(line->type == gfx_splineTo) { qspline_abc_t q; + double len, lineend,lastt; mkspline(&q, x, y, line); - double len = get_spline_len(&q); + len = get_spline_len(&q); //printf("%f %f -> %f %f, len: %f\n", x, y, line->x, line->y, len); if(len==0) continue; - double lineend = linepos+len; - double lastt = 0; + lineend = linepos+len; + lastt = 0; if(nextpos=linepos); @@ -272,9 +283,10 @@ void gfxtool_draw_dashed_line(gfxdrawer_t*d, gfxline_t*line, float*r, float phas gfxline_t* gfxtool_dash_line(gfxline_t*line, float*dashes, float phase) { gfxdrawer_t d; + gfxline_t*result; gfxdrawer_target_gfxline(&d); gfxtool_draw_dashed_line(&d, line, dashes, phase); - gfxline_t*result= (gfxline_t*)d.result(&d); + result= (gfxline_t*)d.result(&d); return result; } @@ -442,6 +454,16 @@ static int approximate3(const cspline_t*s, qspline_t*q, int size, double quality return num; } +void gfxdraw_conicTo(gfxdrawer_t*draw, double cx, double cy, double tox, double toy) +{ + double c1x = (draw->x + 2 * cx) / 3; + double c1y = (draw->y + 2 * cy) / 3; + double c2x = (2 * cx + tox) / 3; + double c2y = (2 * cy + toy) / 3; + gfxdraw_cubicTo(draw, c1x, c1y, c2x, c2y, tox, toy); +} + + void gfxdraw_cubicTo(gfxdrawer_t*draw, double c1x, double c1y, double c2x, double c2y, double x, double y) { qspline_t q[128]; @@ -461,8 +483,8 @@ void gfxdraw_cubicTo(gfxdrawer_t*draw, double c1x, double c1y, double c2x, doubl num = approximate3(&c, q, 128, maxerror*maxerror); for(t=0;tx; - y = line->x; + y = line->y; line = line->next; } return bbox; } -void gfxline_dump(gfxline_t*line, FILE*fi) +void gfxline_dump(gfxline_t*line, FILE*fi, char*prefix) { while(line) { if(line->type == gfx_moveTo) { - fprintf(fi, "moveTo %.2f %.2f\n", line->x, line->y); + fprintf(fi, "%smoveTo %.2f %.2f\n", prefix, line->x, line->y); } else if(line->type == gfx_lineTo) { - fprintf(fi, "lineTo %.2f %.2f\n", line->x, line->y); + fprintf(fi, "%slineTo %.2f %.2f\n", prefix, line->x, line->y); } else if(line->type == gfx_splineTo) { - fprintf(fi, "splineTo (%.2f %.2f) %.2f %.2f\n", line->sx, line->sy, line->x, line->y); + fprintf(fi, "%ssplineTo (%.2f %.2f) %.2f %.2f\n", prefix, line->sx, line->sy, line->x, line->y); } line = line->next; } } +void gfxline_append(gfxline_t*line1, gfxline_t*line2) +{ + while(line1) { + line1 = line1->next; + } + line1->next = line2; +}