Changeset 226
- Timestamp:
- 07/04/07 01:15:13
- Files:
-
- trunk/autogen.sh (modified) (1 diff)
- trunk/src/Geom.cpp (added)
- trunk/src/Geom.h (added)
- trunk/src/Makefile.am (modified) (2 diffs)
- trunk/src/SWFAction.h (modified) (1 diff)
- trunk/src/SWFFilter.h (modified) (1 diff)
- trunk/src/SWFGlyphList.h (modified) (1 diff)
- trunk/src/SWFItem.h (modified) (2 diffs)
- trunk/src/SWFList.h (modified) (1 diff)
- trunk/src/SWFShapeMaker.cpp (modified) (9 diffs)
- trunk/src/SWFShapeMaker.h (modified) (4 diffs)
- trunk/src/SWFTag.h (modified) (1 diff)
- trunk/src/codegen/header.xsl (modified) (1 diff)
- trunk/src/codegen/source.xml (modified) (2 diffs)
- trunk/src/swfmill.cpp (modified) (4 diffs)
- trunk/src/swft/Makefile.am (modified) (3 diffs)
- trunk/src/swft/Parser.cpp (added)
- trunk/src/swft/Parser.h (added)
- trunk/src/swft/SVGAttributeParser.cpp (added)
- trunk/src/swft/SVGAttributeParser.h (added)
- trunk/src/swft/SVGColor.cpp (added)
- trunk/src/swft/SVGColor.h (added)
- trunk/src/swft/SVGColors.h (added)
- trunk/src/swft/SVGGradient.cpp (added)
- trunk/src/swft/SVGGradient.h (added)
- trunk/src/swft/SVGPathParser.cpp (added)
- trunk/src/swft/SVGPathParser.h (added)
- trunk/src/swft/SVGPointsParser.cpp (added)
- trunk/src/swft/SVGPointsParser.h (added)
- trunk/src/swft/SVGStyle.cpp (added)
- trunk/src/swft/SVGStyle.h (added)
- trunk/src/swft/SVGTransformParser.cpp (added)
- trunk/src/swft/SVGTransformParser.h (added)
- trunk/src/swft/swft.cpp (modified) (5 diffs)
- trunk/src/swft/swft.h (modified) (3 diffs)
- trunk/src/swft/swft_css.cpp (deleted)
- trunk/src/swft/swft_import_ttf.cpp (modified) (1 diff)
- trunk/src/swft/swft_path.cpp (modified) (2 diffs)
- trunk/src/xslt/simple-import.xslt (modified) (1 diff)
- trunk/src/xslt/simple-svg.xslt (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/autogen.sh
r79 r226 10 10 xsltproc codegen/mk.xsl codegen/source.xml 11 11 cd .. 12 ./configure 12 ./configure $* trunk/src/Makefile.am
r141 r226 36 36 swfmill_SOURCES = \ 37 37 base64.c \ 38 Geom.cpp \ 38 39 SWFReader.cpp \ 39 40 SWFWriter.cpp \ … … 62 63 noinst_HEADERS = \ 63 64 base64.h \ 65 Geom.h \ 64 66 SWFBasic.h \ 65 67 SWFReader.h \ trunk/src/SWFAction.h
r50 r226 9 9 public: 10 10 Action(); 11 virtual ~Action() {} 11 12 void setTypeAndLength( int t, int l ) { 12 13 // must be called before parse()! trunk/src/SWFFilter.h
r141 r226 9 9 public: 10 10 Filter(); 11 virtual ~Filter() {} 11 12 void setTypeAndLength( int t, int l ) { 12 13 type = t; trunk/src/SWFGlyphList.h
r50 r226 12 12 public: 13 13 GlyphList(); 14 ~GlyphList();14 virtual ~GlyphList(); 15 15 virtual bool parse( Reader *r, int end, Context *ctx ); 16 16 virtual void dump( int indent, Context *ctx ); trunk/src/SWFItem.h
r50 r226 16 16 public: 17 17 Item(); 18 virtual ~Item() {} 18 19 19 20 virtual bool parse( Reader *r, int end, Context *ctx ) = 0; … … 40 41 public: 41 42 Rest(); 42 ~Rest();43 virtual ~Rest(); 43 44 virtual bool parse( Reader *r, int end, Context *ctx ); 44 45 virtual void dump( int indent, Context *ctx ); trunk/src/SWFList.h
r141 r226 44 44 } else { 45 45 WARNING("Linked List has First but no Last item\n"); 46 return NULL; 46 47 } 47 48 } else { trunk/src/SWFShapeMaker.cpp
r211 r226 4 4 #include "SWFItem.h" 5 5 #include "SWF.h" 6 #include <math.h> 6 7 #define TMP_STRLEN 0xFF 7 8 8 9 namespace SWF { … … 15 16 offsetx = ofsx; 16 17 offsety = ofsy; 18 diffx = diffy = 0; 17 19 lastx = lasty = 0; 18 diffx = diffy = 0;20 smoothx = smoothy = 0; 19 21 have_first = false; 20 22 21 23 fillStyle0 = lineStyle = fillStyle1 = -1; 22 } 23 24 void ShapeMaker::do_setup( double _x, double _y ) { 24 25 25 roundReset(); 26 int x = roundX(factorx * ( _x ) ); 27 int y = roundY(factory * ( _y ) ); 28 29 diffx = diffy = 0; 30 26 } 27 28 void ShapeMaker::doSetup( double _x, double _y, bool hasMoveTo, int _fillStyle0, int _fillStyle1, int _lineStyle ) { 31 29 // append shapesetup (whithout styles, this is glyph only for now) 32 30 ShapeSetup *setup = new ShapeSetup; 33 31 34 setup->setxybits( SWFMaxBitsNeeded( true, 2, x, y ) ); 35 36 if( fillStyle0 != -1 ) { 37 setup->setfillStyle0( fillStyle0 ); 32 33 if( _fillStyle0 != -1 ) { 34 setup->setfillStyle0( _fillStyle0 ); 38 35 setup->sethasFillStyle0( 1 ); 39 36 } 40 if( fillStyle1 != -1 ) {41 setup->setfillStyle1( fillStyle1 );37 if( _fillStyle1 != -1 ) { 38 setup->setfillStyle1( _fillStyle1 ); 42 39 setup->sethasFillStyle1( 1 ); 43 40 } 44 if( lineStyle != -1 ) {45 setup->setlineStyle( lineStyle );41 if( _lineStyle != -1 ) { 42 setup->setlineStyle( _lineStyle ); 46 43 setup->sethasLineStyle( 1 ); 47 44 } 48 45 49 setup->sethasMoveTo( 1 ); 50 setup->setx( x ); 51 setup->sety( y ); 46 if( hasMoveTo ) { 47 roundReset(); 48 int x = roundX(factorx * ( _x ) ); 49 int y = roundY(factory * ( _y ) ); 50 51 diffx = diffy = 0; 52 53 setup->setxybits( SWFMaxBitsNeeded( true, 2, x, y ) ); 54 55 setup->sethasMoveTo( 1 ); 56 setup->setx( x ); 57 setup->sety( y ); 58 59 minmax( x, y ); 60 61 lastx = _x; lasty = _y; 62 lastsetupx = _x; lastsetupy = _y; 63 } 52 64 53 65 edges->append( setup ); 54 55 minmax( x+(lastx*factorx), y+(lasty*factory) );56 66 57 67 // fprintf(stderr,"setup %i/%i\n", x, y ); … … 71 81 edges->append( segment ); 72 82 minmax( x+(lastx*factorx), y+(lasty*factory) ); 83 84 lastx += _x; lasty += _y; 73 85 } 74 86 … … 76 88 int cx = roundX(factorx * ( _cx ) ); 77 89 int cy = roundY(factory * ( _cy ) ); 78 int x = roundX(factorx * ( ax ) ); 79 int y = roundY(factory * ( ay ) ); 80 81 diffx += cx; diffy += cy; 82 diffx += x; diffy += y; 90 int x = roundX(factorx * ( ax - _cx ) ); 91 int y = roundY(factory * ( ay - _cy) ); 92 93 smoothx = lastx + _cx; 94 smoothy = lasty + _cy; 95 96 diffx += cx + x; diffy += cy + y; 83 97 84 98 CurveTo *segment = new CurveTo; … … 90 104 segment->sety2( y ); 91 105 edges->append( segment ); 92 minmax( x+(lastx*factorx), y+(lasty*factory) ); 106 minmax( x+cx+(lastx*factorx), y+cy+(lasty*factory) ); 107 108 lastx += ax; lasty += ay; 109 110 smoothx = ax - _cx; 111 smoothy = ay - _cy; 112 } 113 114 void ShapeMaker::curveTo( double cx, double cy, double ax, double ay ) { 115 curveToR( cx - lastx, cy - lasty, ax - lastx, ay - lasty ); 116 } 117 118 void ShapeMaker::smoothCurveToR( double ax, double ay ) { 119 curveToR( smoothx, smoothy, ax, ay ); 120 121 } 122 123 void ShapeMaker::smoothCurveTo( double ax, double ay ) { 124 curveTo( lastx + smoothx, lasty + smoothy, ax, ay ); 93 125 } 94 126 … … 174 206 175 207 cubicToRec( a, b, c, d, .01 ); 176 //lastx = ax; lasty = ay; 177 } 178 179 void ShapeMaker::close() { 208 209 lastx = ax; lasty = ay; 210 smoothx = ax - x2; 211 smoothy = ay - y2; 212 } 213 214 void ShapeMaker::cubicToR( double x1, double y1, double x2, double y2, double ax, double ay ) { 215 cubicTo(lastx + x1, lasty + y1, 216 lastx + x2, lasty + y2, 217 lastx + ax, lasty + ay); 218 } 219 220 void ShapeMaker::smoothCubicTo( double x2, double y2, double ax, double ay ) { 221 cubicTo( lastx + smoothx, lasty + smoothy, x2, y2, ax, ay ); 222 223 } 224 225 void ShapeMaker::smoothCubicToR( double x2, double y2, double ax, double ay ) { 226 cubicToR( smoothx, smoothy, x2, y2, ax, ay ); 227 } 228 229 void ShapeMaker::close(bool stroke) { 180 230 // diffx/diffy captures rounding errors. they can accumulate a bit! FIXME 181 231 … … 183 233 fprintf(stderr,"WARNING: shape not closed; closing (%f/%f).\n", diffx, diffy); 184 234 fprintf(stderr,"DEBUG: accumulated rounding error (%f/%f).\n", roundx, roundy); 235 236 if(!stroke) { 237 doSetup( 0, 0, false, -1, -1, 0 ); 238 } 239 185 240 // closing line 186 241 LineTo *segment = new LineTo; … … 190 245 segment->sety( (int)-diffy ); 191 246 edges->append( segment ); 192 } 193 194 lastx = lasty = 0; 247 248 if(!stroke) { 249 doSetup( 0, 0, false, -1, -1, lineStyle ); 250 } 251 252 diffx = diffy = 0; 253 if(stroke) { 254 lastx = lastsetupx; lasty = lastsetupy; 255 } 256 } 195 257 } 196 258 … … 202 264 203 265 void ShapeMaker::setupR( double x, double y ) { 204 x+=lastx; y+=lasty; 205 do_setup( x, y ); 206 lastx = x; 207 lasty = y; 266 x += lastx; y += lasty; 267 doSetup( x, y, true, fillStyle0, fillStyle1, lineStyle ); 208 268 } 209 269 210 270 void ShapeMaker::setup( double x, double y ) { 211 x+=offsetx; y+=offsety; 212 do_setup( x, y ); 213 lastx = x; 214 lasty = y; 271 x += offsetx; y += offsety; 272 doSetup( x, y, true, fillStyle0, fillStyle1, lineStyle ); 215 273 } 216 274 217 275 void ShapeMaker::lineTo( double x, double y ) { 218 x+=offsetx; y+=offsety; 219 lineToR( x-lastx, y-lasty ); 220 lastx = x; 221 lasty = y; 222 } 223 224 void ShapeMaker::curveTo( double cx, double cy, double ax, double ay ) { 225 curveToR( cx-lastx, cy-lasty, ax-cx, ay-cy ); 226 lastx = ax; 227 lasty = ay; 228 } 229 230 } 276 x += offsetx; y += offsety; 277 lineToR( x - lastx, y - lasty ); 278 } 279 280 void ShapeMaker::rect( double x, double y, double w, double h, double rx, double ry ) { 281 if(rx > 0 || ry > 0) { 282 setup(x + rx, y); 283 lineTo(x + w - rx, y); 284 arcTo(rx, ry, 0, false, true, x + w, y + ry); 285 lineTo(x + w, y + h - ry); 286 arcTo(rx, ry, 0, false, true, x + w - rx, y + h); 287 lineTo(x + rx, y + h); 288 arcTo(rx, ry, 0, false, true, x, y + h - ry); 289 lineTo(x, y + ry); 290 arcTo(rx, ry, 0, false, true, x + rx, y); 291 close(); 292 } else { 293 setup(x, y); 294 lineToR(0, h); 295 lineToR(w, 0); 296 lineToR(0, -h); 297 lineToR(-w, 0); 298 close(); 299 } 300 } 301 302 #define ELLIPSE_SEGMENTS 8 303 #define ELLIPSE_ANGLE ( M_PI * 2 / ELLIPSE_SEGMENTS ) 304 305 void ShapeMaker::ellipseSegment( double cx, double cy, double rx, double ry, double phi, double theta, double dTheta) { 306 double a1 = theta + dTheta / 2; 307 double a2 = theta + dTheta; 308 double f = cos(dTheta / 2); 309 310 Point p1(cos(a1) * rx / f, sin(a1) * ry / f); 311 Point p2(cos(a2) * rx, sin(a2) * ry); 312 p1.rotate(phi); 313 p2.rotate(phi); 314 315 curveTo(cx + p1.x, cy + p1.y, cx + p2.x, cy + p2.y); 316 } 317 318 void ShapeMaker::ellipse( double cx, double cy, double rx, double ry ) { 319 setup(cx + rx, cy); 320 for(int i = 0; i < ELLIPSE_SEGMENTS; i++) { 321 ellipseSegment(cx, cy, rx, ry, 0, ELLIPSE_ANGLE * i, ELLIPSE_ANGLE); 322 } 323 close(); 324 } 325 326 void ShapeMaker::arcTo( double rx, double ry, double rotation, bool largeArcFlag, bool sweepFlag, double x, double y ) { 327 double a, f, lambda, theta, dTheta; 328 329 a = rotation / 180 * M_PI; 330 331 Point A(lastx, lasty); 332 Point B(x, y); 333 334 Point P = (A - B) / 2; 335 P.rotate(-a); 336 337 lambda = pow(P.x, 2) / pow(rx, 2) + pow(P.y, 2) / pow(ry, 2); 338 if(lambda > 1) { 339 rx *= sqrt(lambda); 340 ry *= sqrt(lambda); 341 } 342 343 f = (pow(rx, 2)*pow(ry, 2)-pow(rx, 2)*pow(P.y, 2)-pow(ry, 2)*pow(P.x, 2))/(pow(rx, 2)*pow(P.y, 2)+pow(ry, 2)*pow(P.x, 2)); 344 if(f < 0) { 345 f = 0; 346 } else { 347 f = sqrt(f); 348 } 349 if(largeArcFlag == sweepFlag) f *= -1; 350 351 Point C_(rx / ry * P.y, -ry / rx * P.x); 352 C_ = C_ * f; 353 354 Point C = C_; 355 C.rotate(a); 356 C = C + (A + B) / 2; 357 358 theta = atan2((P.y-C_.y)/ry, (P.x-C_.x)/rx); 359 dTheta = atan2((-P.y-C_.y)/ry, (-P.x-C_.x)/rx) - theta; 360 361 if(sweepFlag && dTheta < 0) 362 dTheta += 2 * M_PI; 363 364 if(!sweepFlag && dTheta > 0) 365 dTheta -= 2 * M_PI; 366 367 double dThetaAbs = (dTheta < 0 ? -dTheta : dTheta); 368 int segments = (int)ceil(dThetaAbs / ELLIPSE_ANGLE); 369 370 for(int i = 0; i < segments; i++) { 371 ellipseSegment(C.x, C.y, rx, ry, a, dTheta / segments * i + theta, dTheta / segments); 372 } 373 } 374 375 void ShapeMaker::arcToR( double rx, double ry, double rotation, bool largeArcFlag, bool sweepFlag, double x, double y ) { 376 arcTo(rx, ry, rotation, largeArcFlag, sweepFlag, lastx + x, lasty + y); 377 } 378 379 void ShapeMaker::boundsWriteXML( xmlNodePtr parent, double border ) { 380 char tmp[TMP_STRLEN]; 381 xmlNodePtr node; 382 383 if(border >= 0) { 384 node = xmlNewChild(parent, NULL, (const xmlChar *)"bounds", NULL); 385 } else { 386 node = xmlNewChild(parent, NULL, (const xmlChar *)"strokeBounds", NULL); 387 } 388 node = xmlNewChild(node, NULL, (const xmlChar *)"Rectangle", NULL); 389 snprintf(tmp, TMP_STRLEN, "%f", minx - border * 20); 390 xmlSetProp(node, (const xmlChar *)"left", (const xmlChar *)&tmp); 391 snprintf(tmp, TMP_STRLEN,"%f", miny - border * 20); 392 xmlSetProp(node, (const xmlChar *)"top", (const xmlChar *)&tmp); 393 snprintf(tmp,TMP_STRLEN,"%f", maxx + border * 20); 394 xmlSetProp(node, (const xmlChar *)"right", (const xmlChar *)&tmp); 395 snprintf(tmp,TMP_STRLEN,"%f", maxy + border * 20); 396 xmlSetProp(node, (const xmlChar *)"bottom", (const xmlChar *)&tmp); 397 } 398 399 } trunk/src/SWFShapeMaker.h
r211 r226 2 2 #define SWF_SHAPEMAKER_H 3 3 4 #include "Geom.h" 4 5 #include <stdio.h> 6 #include <libxml/tree.h> 7 #include <math.h> 5 8 6 9 namespace SWF { … … 8 11 class ShapeItem; 9 12 template <class T> class List; 10 11 class Point {12 public:13 double x, y;14 15 Point( double _x=0, double _y=0 ) {16 x = _x; y = _y;17 }18 Point( const Point& p ) {19 x=p.x; y=p.y;20 }21 const Point operator -( const Point& p ) const {22 Point p2(x-p.x, y-p.y);23 return p2;24 }25 Point operator =( const Point& p ) {26 x=p.x; y=p.y;27 return *this;28 }29 };30 13 31 14 class Bezier { … … 51 34 } 52 35 53 void do_setup( double x=0, double y=0 ); 54 void setup( double x=0, double y=0 ); 36 void setup( double x = 0, double y = 0 ); 37 void setupR( double x = 0, double y = 0 ); 38 55 39 void lineTo( double x, double y ); 40 void lineToR( double x, double y ); 41 56 42 void curveTo( double cx, double cy, double ax, double ay ); 43 void curveToR( double cx, double cy, double ax, double ay ); 44 45 void smoothCurveTo( double ax, double ay ); 46 void smoothCurveToR( double ax, double ay ); 47 57 48 void cubicTo( double x1, double y1, double x2, double y2, double ax, double ay ); 58 void close(); 49 void cubicToR( double x1, double y1, double x2, double y2, double ax, double ay ); 50 51 void smoothCubicTo( double x2, double y2, double ax, double ay ); 52 void smoothCubicToR( double x2, double y2, double ax, double ay ); 53 54 void close(bool stroke = true); 59 55 void finish(); 60 56 61 void setupR( double x=0, double y=0 ); 62 void lineToR( double x, double y ); 63 void curveToR( double cx, double cy, double ax, double ay ); 57 void rect( double x, double y, double width, double height, double rx = 0, double ry = 0 ); 58 void ellipse( double cx, double cy, double rx, double ry ); 59 60 void arcTo( double rx, double ry, double rotation, bool largeArcFlag, bool sweepFlag, double x, double y ); 61 void arcToR( double rx, double ry, double rotation, bool largeArcFlag, bool sweepFlag, double x, double y ); 62 63 void boundsWriteXML( xmlNodePtr node, double border = -1 ); 64 64 65 65 double getLastX() { return lastx; } 66 66 double getLastY() { return lasty; } 67 67 68 double get MinX() { return minx; }69 double get MinY() { return miny; }70 double getMaxX() { return maxx; } 71 double getMaxY() { return maxy; }68 double getSmoothX() { return smoothx; } 69 double getSmoothY() { return smoothy; } 70 71 Rect getBounds() { return Rect(minx, miny, maxx, maxy); } 72 72 73 73 protected: 74 74 void cubicToRec( const Point& a, const Point& b, const Point& c, const Point& d, double k, int iteration=0 ); 75 76 void doSetup( double _x=0, double _y=0, bool hasMoveTo=true, int _fillStyle0=-1, int _fillStyle1=-1, int _lineStyle=-1); 77 78 void ellipseSegment( double cx, double cy, double rx, double ry, double phi, double theta, double dTheta); 75 79 76 80 void minmax( double x, double y ) { … … 89 93 double factorx, factory; 90 94 double offsetx, offsety; 95 double diffx, diffy; 91 96 double lastx, lasty; 92 double diffx, diffy;97 double lastsetupx, lastsetupy; 93 98 double minx, miny, maxx, maxy; 99 double smoothx, smoothy; 94 100 bool have_first; 95 101 96 102 int fillStyle0, fillStyle1, lineStyle; 97 103 98 104 // rounding error accumulation compensation 99 105 double roundx, roundy; trunk/src/SWFTag.h
r50 r226 11 11 Tag(); 12 12 void setTypeAndLength( int t, int l ); 13 intsetType( int t ) { type = t; }13 void setType( int t ) { type = t; } 14 14 int getType() { return type; } 15 15 int getLength() { return len; } trunk/src/codegen/header.xsl
r146 r226 44 44 public: 45 45 <xsl:value-of select="@name"/>(); 46 ~<xsl:value-of select="@name"/>();46 virtual ~<xsl:value-of select="@name"/>(); 47 47 48 48 virtual bool parse( Reader *r, int end, Context *ctx ); trunk/src/codegen/source.xml
r221 r226 93 93 94 94 <if expression="jointStyle==2"> 95 <word name="miterLimitFactor" prop="true"/> 95 <fixedpoint2 name="miterLimitFactor" signed="false" size="16" constant-size="true" exp="8" prop="true"/> 96 <!-- <word name="miterLimitFactor" prop="true"/>--> 96 97 </if> 97 98 … … 614 615 <integer name="count" size="4" constant-size="true"/> 615 616 <list type="GradientItem" name="gradientColors" length="count" prop="true"/> 616 < word name="shift" prop="true"/>617 <fixedpoint2 name="shift" signed="true" size="16" constant-size="true" exp="8" prop="true"/> 617 618 </style> 618 619 trunk/src/swfmill.cpp
r145 r226 17 17 bool verbose = false; 18 18 bool dump = false; 19 bool nonet = false; 19 20 const char *internal_stylesheet = NULL; 20 21 … … 60 61 " -V extra-verbose debugging output\n" 61 62 " -d dump SWF data when loaded (for debugging)\n" 63 " -n deactivate libxml network access" 62 64 "\n" 63 65 "E-mail bug reports to "PACKAGE_BUGREPORT"\n\n" … … 429 431 dump = true; 430 432 break; 433 case 'n': 434 nonet = true; 435 break; 431 436 case '?': 432 437 usage(); … … 449 454 goto fail; 450 455 } 456 457 if( nonet ) xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader ); 451 458 452 459 if( !quiet ) fprintf( stderr, "%s %s\n", PACKAGE_NAME, PACKAGE_VERSION ); trunk/src/swft/Makefile.am
r162 r226 24 24 swft_document.cpp \ 25 25 swft_path.cpp \ 26 swft_css.cpp \27 26 swft_import.cpp \ 28 27 swft_import_jpeg.cpp \ … … 30 29 swft_import_ttf.cpp \ 31 30 swft_import_mp3.cpp \ 31 Parser.cpp \ 32 SVGStyle.cpp \ 33 SVGGradient.cpp \ 34 SVGColor.cpp \ 35 SVGPathParser.cpp \ 36 SVGPointsParser.cpp \ 37 SVGTransformParser.cpp \ 38 SVGAttributeParser.cpp \ 32 39 readpng.c \ 33 40 $(NULL) … … 35 42 noinst_HEADERS = \ 36 43 swft.h \ 44 Parser.h \ 45 SVGStyle.h \ 46 SVGGradient.h \ 47 SVGColor.h \ 48 SVGColors.h \ 49 SVGPathParser.h \ 50 SVGPointsParser.h \ 51 SVGTransformParser.h \ 52 SVGAttributeParser.h \ 37 53 readpng.h \ 38 54 $(NULL) trunk/src/swft/swft.cpp
r194 r226 11 11 #define SWFT_MAPSIZE 32 12 12 13 using namespace SWF; 13 14 14 15 void *swft_init( xsltTransformContextPtr ctx, const xmlChar *URI ); … … 42 43 void swft_transform( xmlXPathParserContextPtr ctx, int nargs ); 43 44 44 // in swft_css 45 void swft_css( xmlXPathParserContextPtr ctx, int nargs ); 46 void swft_unit( xmlXPathParserContextPtr ctx, int nargs ); 47 void swft_css_lookup( xmlXPathParserContextPtr ctx, int nargs ); 45 static void swft_pushgradient( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr com ) { 46 swft_ctx *c = (swft_ctx*)xsltGetExtData( ctx, SWFT_NAMESPACE ); 47 xmlChar *id, *href; 48 SVGGradient *gradient; 49 50 id = xmlGetProp(node, (const xmlChar *)"id"); 51 if(id) { 52 if(!xmlStrcmp(node->name, (const xmlChar *)"linearGradient")) { 53 gradient = new SVGLinearGradient(); 54 } else if(!xmlStrcmp(node->name, (const xmlChar *)"radialGradient")) { 55 gradient = new SVGRadialGradient(); 56 } 57 58 href = xmlGetProp(node, (const xmlChar *)"href"); 59 if (href) { 60 string hrefStr = (const char *)href; 61 hrefStr.erase(0, 1); 62 63 map<string, SVGGradient*>::iterator i = c->gradients.find(hrefStr); 64 if(i != c->gradients.end()) { 65 *gradient = *((*i).second); 66 } 67 68 xmlFree(href); 69 } 70 71 gradient->parse(node); 72 c->gradients[(char *)id] = gradient; 73 xmlFree(id); 74 } 75 76 } 77 78 static void swft_popstyle( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr com ) { 79 swft_ctx *c = (swft_ctx*)xsltGetExtData( ctx, SWFT_NAMESPACE ); 80 c->styles.pop(); 81 } 82 83 static void swft_pushstyle( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr com ) { 84 swft_ctx *c = (swft_ctx*)xsltGetExtData( ctx, SWFT_NAMESPACE ); 85 86 SVGStyle style; 87 if(c->styles.size() > 0) { 88 style = c->styles.top(); 89 } 90 style.parseNode(node, c->gradients); 91 c->styles.push(style); 92 } 48 93 49 94 static void swft_nextid( xmlXPathParserContextPtr ctx, int nargs ) { … … 146 191 oldID = obj->stringval; 147 192 newID = c->doMap((const char*)oldID); 148 193 149 194 xmlFree( oldID ); 150 195 … … 180 225 xsltRegisterExtFunction( ctx, (const xmlChar *) "path", SWFT_NAMESPACE, swft_path); 181 226 // xsltRegisterExtFunction( ctx, (const xmlChar *) "bounds", SWFT_NAMESPACE, swft_bounds); 182 xsltRegisterExtFunction( ctx, (const xmlChar *) "css", SWFT_NAMESPACE, swft_css);183 xsltRegisterExtFunction( ctx, (const xmlChar *) "css-lookup", SWFT_NAMESPACE, swft_css_lookup);184 xsltRegisterExtFunction( ctx, (const xmlChar *) "unit", SWFT_NAMESPACE, swft_unit);185 227 xsltRegisterExtFunction( ctx, (const xmlChar *) "transform", SWFT_NAMESPACE, swft_transform); 228 xsltRegisterExtElement( ctx, (const xmlChar *) "push-style", SWFT_NAMESPACE, swft_pushstyle); 229 xsltRegisterExtElement( ctx, (const xmlChar *) "pop-style", SWFT_NAMESPACE, swft_popstyle); 230 xsltRegisterExtElement( ctx, (const xmlChar *) "push-gradient", SWFT_NAMESPACE, swft_pushgradient); 186 231 187 232 xsltRegisterExtFunction( ctx, (const xmlChar *) "import-jpeg", SWFT_NAMESPACE, swft_import_jpeg ); … … 200 245 } 201 246 247 trunk/src/swft/swft.h
r197 r226 6 6 #include <stack> 7 7 #include <map> 8 8 #include "SVGGradient.h" 9 #include "SVGStyle.h" 10 9 11 void swft_register(); 10 12 … … 19 21 class swft_ctx { 20 22 public: 23 std::stack<SWF::SVGStyle> styles; 24 std::map<std::string, SWF::SVGGradient*> gradients; 21 25 22 26 int last_id; … … 58 62 }; 59 63 60 // CSS style stuff61 62 struct CSSColor {63 CSSColor() {64 r=g=b=a=0;65 };66 67 unsigned char r, g, b, a;68 };69 70 struct CSSStyle {71 CSSStyle() {72 no_fill = no_stroke = false;73 width = 0;74 }75 76 bool no_fill, no_stroke;77 CSSColor fill;78 CSSColor stroke;79 double width;80 81 std::map<std::string,std::string> styles;82 };83 84 void parse_css_simple( const char *style_str, CSSStyle *style );85 86 64 #endif trunk/src/swft/swft_import_ttf.cpp
r219 r226 203 203 Rectangle *r = new Rectangle(); 204 204 205 r->setleft( (int)shaper.getMinX() ); 206 r->settop( (int)shaper.getMinY() ); 207 r->setright( (int)shaper.getMaxX() ); 208 r->setbottom( (int)shaper.getMaxY() ); 205 Rect rect = shaper.getBounds(); 206 r->setleft( (int)rect.left ); 207 r->settop( (int)rect.top ); 208 r->setright( (int)rect.right ); 209 r->setbottom( (int)rect.bottom ); 209 210 210 211 r->setbits( SWFMaxBitsNeeded( true, 3, r->gettop(), r->getright(), r->getbottom() ) ); trunk/src/swft/swft_path.cpp
r96 r226 1 #include "SWFShapeMaker.h"2 #include "SWF.h"3 1 #include "swft.h" 2 #include "SVGPathParser.h" 3 #include "SVGTransformParser.h" 4 #include "SVGAttributeParser.h" 5 #include "SVGPointsParser.h" 6 #include "SVGStyle.h" 7 #include <libxml/xpathInternals.h> 8 #include <libxslt/xsltutils.h> 4 9 #include <libxslt/extensions.h> 5 #include <libxslt/xsltutils.h>6 #include <libxml/xpathInternals.h>7 10 8 11 using namespace SWF; 9 12 10 #define TMP_STRLEN 0xff11 12 // returns true when a segment is finished.13 bool mkShapeSegment( ShapeMaker& shaper, double *coord, int *C, char *tmp, char mode, double *smoothx, double *smoothy ) {14 bool fin=true;15 int c = *C;16 17 if( tmp[0] ) {18 *C=c+1;19 coord[c] = atof( tmp );20 //fprintf(stderr, "coord[%i]: %i, mode %c, tmp %s\n", c, coord[c], mode, tmp );21 }22 if( mode == 'Q' && c==3 ) {23 shaper.curveTo( coord[0], coord[1], coord[2], coord[3] );24 *smoothx = coord[2] + (coord[2]-coord[0]);25 *smoothy = coord[3] + (coord[3]-coord[1]);26 } else if( mode == 'q' && c==3 ) {27 shaper.curveToR( coord[0], coord[1], coord[2], coord[3] );28 } else if( mode == 'T' && c==1 ) {29 shaper.curveTo( *smoothx, *smoothy, coord[0], coord[1] );30 *smoothx = coord[0] + (coord[0]-*smoothx);31 *smoothy = coord[1] + (coord[1]-*smoothy);32 } else if( mode == 'C' && c==5 ) {33 shaper.cubicTo( coord[0], coord[1], coord[2], coord[3], coord[4], coord[5] );34 *smoothx = coord[4] + (coord[4]-coord[2]);35 *smoothy = coord[5] + (coord[5]-coord[3]);36 } else if( mode == 'S' && c==3 ) {37 shaper.cubicTo( *smoothx, *smoothy, coord[0], coord[1], coord[2], coord[3] );38 *smoothx = coord[2] + (coord[2]-coord[0]);39 *smoothy = coord[3] + (coord[3]-coord[1]);40 } else if( mode == 'L' && c==1 ) {41 shaper.lineTo( coord[0], coord[1] );42 } else if( mode == 'l' && c==1 ) {43 shaper.lineToR( coord[0], coord[1] );44 } else if( mode == 'M' && c==1 ) {45 shaper.setup( coord[0], coord[1] );46 } else if( mode == 'm' && c==1 ) {47 shaper.setupR( coord[0], coord[1] );48 } else if( mode == 'H' && c==0 ) {49 shaper.lineTo( coord[0], shaper.getLastY() );50 } else if( mode == 'V' && c==0 ) {51 shaper.lineTo( shaper.getLastX(), coord[0] );52 } else {53 return false;54 }55 return true;56 }57 58 13 /* 59 14 Create a complete DefineShape3 element. 60 syntax: swft:path( < svg path string>, <id>, <style attr> [, <xofs>, <yofs>])15 syntax: swft:path( <node> , <shapeid> , <movie-version> ) 61 16 */ 62 void swft_path( xmlXPathParserContextPtr ctx, int nargs ) { 63 xmlChar *string, *styleString, *idString; 64 xmlXPathObjectPtr obj; 65 Shape shape; 66 Context swfctx; 17 void swft_path(xmlXPathParserContextPtr ctx, int nargs) { 18 xmlChar *styleString, *idString, *pathString; 67 19 <
