int SWFShape_drawCubic(SWFShape shape, float bx, float by, float cx, float cy, float dx, float dy) { int sax = SWFShape_getScaledPenX(shape); int say = SWFShape_getScaledPenY(shape); int sbx = (int)rint(bx*Ming_scale) + sax; int sby = (int)rint(by*Ming_scale) + say; int scx = (int)rint(cx*Ming_scale) + sbx; int scy = (int)rint(cy*Ming_scale) + sby; int sdx = (int)rint(dx*Ming_scale) + scx; int sdy = (int)rint(dy*Ming_scale) + scy; return SWFShape_drawScaledCubicTo(shape, sbx, sby, scx, scy, sdx, sdy); }
void SWFShape_getPen(SWFShape shape, float* penX, float* penY) { *penX = (float)(SWFShape_getScaledPenX(shape)/ Ming_scale); *penY = (float)(SWFShape_getScaledPenY(shape)/ Ming_scale); }
float SWFShape_getPenY(SWFShape shape) { return (float)(SWFShape_getScaledPenY(shape)/Ming_scale); }
void SWFShape_getPen(SWFShape shape, double* penX, double* penY) { *penX = SWFShape_getScaledPenX(shape)/ Ming_scale; *penY = SWFShape_getScaledPenY(shape)/ Ming_scale; }
double SWFShape_getPenY(SWFShape shape) { return SWFShape_getScaledPenY(shape)/Ming_scale; }
int SWFShape_drawScaledCubicTo(SWFShape shape, int bx, int by, int cx, int cy, int dx, int dy) { int ax = SWFShape_getScaledPenX(shape); int ay = SWFShape_getScaledPenY(shape); /* compute coefficients */ int a1x = -ax + 3*bx - 3*cx + dx; int a1y = -ay + 3*by - 3*cy + dy; int a2x = ax - 2*bx + cx; int a2y = ay - 2*by + cy; int a3x = -ax + bx; int a3y = -ay + by; double a = 6*(a2x*a1y-a2y*a1x); double b = 6*(a3x*a1y-a3y*a1x); double c = 2*(a3x*a2y-a3y*a2x); /* First, chop at inflection points, where a*t^2 + b*t + c = 0 */ double d = b*b - 4*a*c; float t1 = 0.0, t2 = 1.0; int nCurves = 0; cubic pts = { { (float)ax, (float)ay }, { (float)bx, (float)by }, { (float)cx, (float)cy }, { (float)dx, (float)dy } }; cubic New; if ( d > 0 ) { /* two roots */ t1 = (float)((-b-sqrt(d))/(2*a)); t2 = (float)((-b+sqrt(d))/(2*a)); if ( a < 0 ) { float tmp = t2; t2 = t1; t1 = tmp; } } else if ( d == 0 ) { /* singular root */ t1 = (float)(-b/(2*a)); } /* use subdivision method to build t=0..t1, t=t1..t2, t=t2..1 curves */ if ( t1 > 0.0 && t1 < 1.0 ) { subdivideCubicLeft(&New, &pts, t1); nCurves += SWFShape_approxCubic(shape, &New); /* nCurves += SWFShape_drawCubicTo(shape, new.b.x, new.b.y, new.c.x, new.c.y, new.d.x, new.d.y); */ subdivideCubicRight(&pts, &pts, t1); t2 = (t2-t1)/(1-t1); } if ( t2 > 0.0 && t2 < 1.0 ) { subdivideCubicLeft(&New, &pts, t2); nCurves += SWFShape_approxCubic(shape, &New); /* nCurves += SWFShape_drawCubicTo(shape, new.b.x, new.b.y, new.c.x, new.c.y, new.d.x, new.d.y); */ subdivideCubicRight(&pts, &pts, t2); } nCurves += SWFShape_approxCubic(shape, &pts); return nCurves; }