Changeset 226

Show
Ignore:
Timestamp:
07/04/07 01:15:13
Author:
ralf
Message:

improved svg support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/autogen.sh

    r79 r226  
    1010xsltproc codegen/mk.xsl codegen/source.xml 
    1111cd .. 
    12 ./configure 
     12./configure $* 
  • trunk/src/Makefile.am

    r141 r226  
    3636swfmill_SOURCES = \ 
    3737        base64.c \ 
     38        Geom.cpp \ 
    3839        SWFReader.cpp \ 
    3940        SWFWriter.cpp \ 
     
    6263noinst_HEADERS = \ 
    6364        base64.h \ 
     65        Geom.h \ 
    6466        SWFBasic.h \ 
    6567        SWFReader.h \ 
  • trunk/src/SWFAction.h

    r50 r226  
    99        public: 
    1010                Action(); 
     11                virtual ~Action() {} 
    1112                void setTypeAndLength( int t, int l ) { 
    1213                        // must be called before parse()! 
  • trunk/src/SWFFilter.h

    r141 r226  
    99        public: 
    1010                Filter(); 
     11                virtual ~Filter() {} 
    1112                void setTypeAndLength( int t, int l ) {  
    1213                        type = t;  
  • trunk/src/SWFGlyphList.h

    r50 r226  
    1212        public: 
    1313                GlyphList(); 
    14                 ~GlyphList(); 
     14                virtual ~GlyphList(); 
    1515                virtual bool parse( Reader *r, int end, Context *ctx ); 
    1616                virtual void dump( int indent, Context *ctx ); 
  • trunk/src/SWFItem.h

    r50 r226  
    1616        public: 
    1717                Item(); 
     18                virtual ~Item() {} 
    1819         
    1920                virtual bool parse( Reader *r, int end, Context *ctx ) = 0; 
     
    4041        public: 
    4142                Rest(); 
    42                 ~Rest(); 
     43                virtual ~Rest(); 
    4344                virtual bool parse( Reader *r, int end, Context *ctx ); 
    4445                virtual void dump( int indent, Context *ctx ); 
  • trunk/src/SWFList.h

    r141 r226  
    4444                                        } else { 
    4545                                                WARNING("Linked List has First but no Last item\n"); 
     46                                                return NULL; 
    4647                                        } 
    4748                                } else { 
  • trunk/src/SWFShapeMaker.cpp

    r211 r226  
    44#include "SWFItem.h" 
    55#include "SWF.h" 
    6 #include <math.h> 
     6 
     7#define TMP_STRLEN 0xFF 
    78 
    89namespace SWF { 
     
    1516        offsetx = ofsx; 
    1617        offsety = ofsy; 
     18        diffx = diffy = 0; 
    1719        lastx = lasty = 0; 
    18         diffx = diffy = 0; 
     20        smoothx = smoothy = 0; 
    1921        have_first = false; 
    2022         
    2123        fillStyle0 = lineStyle = fillStyle1 = -1; 
    22 
    23  
    24 void ShapeMaker::do_setup( double _x, double _y ) { 
     24 
    2525        roundReset(); 
    26         int x = roundX(factorx * ( _x ) ); 
    27         int y = roundY(factory * ( _y ) ); 
    28  
    29         diffx = diffy = 0; 
    30  
     26
     27 
     28void ShapeMaker::doSetup( double _x, double _y, bool hasMoveTo, int _fillStyle0, int _fillStyle1, int _lineStyle ) { 
    3129        // append shapesetup (whithout styles, this is glyph only for now) 
    3230        ShapeSetup *setup = new ShapeSetup; 
    3331 
    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 ); 
    3835                setup->sethasFillStyle0( 1 ); 
    3936        } 
    40         if( fillStyle1 != -1 ) { 
    41                 setup->setfillStyle1( fillStyle1 ); 
     37        if( _fillStyle1 != -1 ) { 
     38                setup->setfillStyle1( _fillStyle1 ); 
    4239                setup->sethasFillStyle1( 1 ); 
    4340        } 
    44         if( lineStyle != -1 ) { 
    45                 setup->setlineStyle( lineStyle ); 
     41        if( _lineStyle != -1 ) { 
     42                setup->setlineStyle( _lineStyle ); 
    4643                setup->sethasLineStyle( 1 ); 
    4744        } 
    4845         
    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        } 
    5264                         
    5365        edges->append( setup ); 
    54  
    55         minmax( x+(lastx*factorx), y+(lasty*factory) ); 
    5666         
    5767//      fprintf(stderr,"setup %i/%i\n", x, y ); 
     
    7181        edges->append( segment ); 
    7282        minmax( x+(lastx*factorx), y+(lasty*factory) ); 
     83 
     84        lastx += _x; lasty += _y; 
    7385} 
    7486 
     
    7688        int cx = roundX(factorx * ( _cx ) ); 
    7789        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; 
    8397         
    8498        CurveTo *segment = new CurveTo; 
     
    90104        segment->sety2( y ); 
    91105        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 
     114void ShapeMaker::curveTo( double cx, double cy, double ax, double ay ) { 
     115        curveToR( cx - lastx, cy - lasty, ax - lastx, ay - lasty ); 
     116
     117 
     118void ShapeMaker::smoothCurveToR( double ax, double ay ) { 
     119        curveToR( smoothx, smoothy, ax, ay ); 
     120 
     121
     122 
     123void ShapeMaker::smoothCurveTo( double ax, double ay ) { 
     124        curveTo( lastx + smoothx, lasty + smoothy, ax, ay ); 
    93125} 
    94126 
     
    174206 
    175207        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 
     214void 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 
     220void ShapeMaker::smoothCubicTo( double x2, double y2, double ax, double ay ) { 
     221        cubicTo( lastx + smoothx, lasty + smoothy, x2, y2, ax, ay ); 
     222 
     223
     224 
     225void ShapeMaker::smoothCubicToR( double x2, double y2, double ax, double ay ) { 
     226        cubicToR( smoothx, smoothy, x2, y2, ax, ay ); 
     227
     228 
     229void ShapeMaker::close(bool stroke) { 
    180230        // diffx/diffy captures rounding errors. they can accumulate a bit! FIXME 
    181231         
     
    183233                fprintf(stderr,"WARNING: shape not closed; closing (%f/%f).\n", diffx, diffy); 
    184234                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                 
    185240                // closing line 
    186241                LineTo *segment = new LineTo; 
     
    190245                segment->sety( (int)-diffy ); 
    191246                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        } 
    195257} 
    196258 
     
    202264 
    203265void 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 ); 
    208268} 
    209269 
    210270void 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 ); 
    215273} 
    216274 
    217275void 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 
     280void 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 
     305void 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 
     318void 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 
     326void 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 
     375void 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 
     379void 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  
    22#define SWF_SHAPEMAKER_H 
    33 
     4#include "Geom.h" 
    45#include <stdio.h> 
     6#include <libxml/tree.h> 
     7#include <math.h> 
    58 
    69namespace SWF { 
     
    811class ShapeItem; 
    912template <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 }; 
    3013 
    3114class Bezier { 
     
    5134                } 
    5235         
    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 
    5539                void lineTo( double x, double y ); 
     40                void lineToR( double x, double y ); 
     41                 
    5642                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 
    5748                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); 
    5955                void finish(); 
    6056         
    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 ); 
    6464         
    6565                double getLastX() { return lastx; } 
    6666                double getLastY() { return lasty; } 
    6767 
    68                 double getMinX() { return minx; } 
    69                 double getMinY() { 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); } 
    7272                 
    7373        protected: 
    7474                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); 
    7579         
    7680                void minmax( double x, double y ) { 
     
    8993                double factorx, factory; 
    9094                double offsetx, offsety; 
     95                double diffx, diffy; 
    9196                double lastx, lasty; 
    92                 double diffx, diffy; 
     97                double lastsetupx, lastsetupy; 
    9398                double minx, miny, maxx, maxy; 
     99                double smoothx, smoothy; 
    94100                bool have_first; 
    95101         
    96102                int fillStyle0, fillStyle1, lineStyle; 
    97                  
     103 
    98104                // rounding error accumulation compensation 
    99105                double roundx, roundy; 
  • trunk/src/SWFTag.h

    r50 r226  
    1111                Tag(); 
    1212                void setTypeAndLength( int t, int l ); 
    13                 int setType( int t ) { type = t; } 
     13                void setType( int t ) { type = t; } 
    1414                int getType() { return type; } 
    1515                int getLength() { return len; } 
  • trunk/src/codegen/header.xsl

    r146 r226  
    4444        public: 
    4545                <xsl:value-of select="@name"/>(); 
    46                 ~<xsl:value-of select="@name"/>(); 
     46                virtual ~<xsl:value-of select="@name"/>(); 
    4747                 
    4848                virtual bool parse( Reader *r, int end, Context *ctx ); 
  • trunk/src/codegen/source.xml

    r221 r226  
    9393 
    9494        <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"/>--> 
    9697        </if> 
    9798 
     
    614615        <integer name="count" size="4" constant-size="true"/> 
    615616        <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"/> 
    617618</style> 
    618619 
  • trunk/src/swfmill.cpp

    r145 r226  
    1717bool verbose = false; 
    1818bool dump = false; 
     19bool nonet = false; 
    1920const char *internal_stylesheet = NULL; 
    2021 
     
    6061                "    -V extra-verbose debugging output\n" 
    6162                "    -d dump SWF data when loaded (for debugging)\n" 
     63                "    -n deactivate libxml network access" 
    6264                "\n" 
    6365                "E-mail bug reports to "PACKAGE_BUGREPORT"\n\n" 
     
    429431                                                dump = true; 
    430432                                                break; 
     433                                        case 'n': 
     434                                                nonet = true; 
     435                                                break; 
    431436                                        case '?': 
    432437                                                usage(); 
     
    449454                goto fail; 
    450455        } 
     456         
     457        if( nonet ) xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader ); 
    451458         
    452459        if( !quiet ) fprintf( stderr, "%s %s\n", PACKAGE_NAME, PACKAGE_VERSION ); 
  • trunk/src/swft/Makefile.am

    r162 r226  
    2424        swft_document.cpp \ 
    2525        swft_path.cpp \ 
    26         swft_css.cpp \ 
    2726        swft_import.cpp \ 
    2827        swft_import_jpeg.cpp \ 
     
    3029        swft_import_ttf.cpp \ 
    3130        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 \ 
    3239        readpng.c \ 
    3340        $(NULL) 
     
    3542noinst_HEADERS = \ 
    3643        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 \ 
    3753        readpng.h \ 
    3854        $(NULL) 
  • trunk/src/swft/swft.cpp

    r194 r226  
    1111#define SWFT_MAPSIZE 32 
    1212 
     13using namespace SWF; 
    1314 
    1415void *swft_init( xsltTransformContextPtr ctx, const xmlChar *URI ); 
     
    4243void swft_transform( xmlXPathParserContextPtr ctx, int nargs ); 
    4344 
    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 ); 
     45static 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 
     78static 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 
     83static 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
    4893 
    4994static void swft_nextid( xmlXPathParserContextPtr ctx, int nargs ) { 
     
    146191        oldID = obj->stringval; 
    147192        newID = c->doMap((const char*)oldID); 
    148          
     193 
    149194        xmlFree( oldID ); 
    150195         
     
    180225        xsltRegisterExtFunction( ctx, (const xmlChar *) "path", SWFT_NAMESPACE, swft_path); 
    181226//      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); 
    185227        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); 
    186231 
    187232        xsltRegisterExtFunction( ctx, (const xmlChar *) "import-jpeg", SWFT_NAMESPACE, swft_import_jpeg ); 
     
    200245} 
    201246 
     247 
  • trunk/src/swft/swft.h

    r197 r226  
    66#include <stack> 
    77#include <map> 
    8          
     8#include "SVGGradient.h" 
     9#include "SVGStyle.h" 
     10 
    911void swft_register(); 
    1012         
     
    1921class swft_ctx { 
    2022public: 
     23        std::stack<SWF::SVGStyle> styles; 
     24        std::map<std::string, SWF::SVGGradient*> gradients; 
    2125 
    2226        int last_id; 
     
    5862}; 
    5963 
    60 // CSS style stuff 
    61  
    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  
    8664#endif 
  • trunk/src/swft/swft_import_ttf.cpp

    r219 r226  
    203203                Rectangle *r = new Rectangle(); 
    204204         
    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 ); 
    209210         
    210211                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" 
    31#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> 
    49#include <libxslt/extensions.h> 
    5 #include <libxslt/xsltutils.h> 
    6 #include <libxml/xpathInternals.h> 
    710 
    811using namespace SWF; 
    912 
    10 #define TMP_STRLEN 0xff 
    11  
    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          
    5813/* 
    5914        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>
    6116*/ 
    62 void swft_path( xmlXPathParserContextPtr ctx, int nargs ) { 
    63         xmlChar *string, *styleString, *idString; 
    64         xmlXPathObjectPtr obj; 
    65         Shape shape; 
    66         Context swfctx; 
     17void swft_path(xmlXPathParserContextPtr ctx, int nargs) { 
     18        xmlChar *styleString, *idString, *pathString; 
    6719<