Changeset 623

Show
Ignore:
Timestamp:
07/14/03 18:22:04 (5 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/Common.py

    r622 r623  
    2323#~ Imports  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     25 
     26import TransformBuilder 
    2527 
    2628#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    6466 
    6567class TransformableRenderItem(RenderItemBase): 
     68    transformbuilder = TransformBuilder.TransformCommandBuilder() 
     69    transformfactoryfactory = TransformBuilder.SaveTransformFactory 
     70 
    6671    def InterpretSettings(self, settings): 
    6772        RenderItemBase.InterpretSettings(self, settings) 
     
    101106 
    102107    def _asTransform(self, transform): 
    103         if transform is not None
    104             for c in transform: pass 
    105             #print "TODO: interpret transform:", transform 
    106         return None 
     108        if isinstance(transform, (str, unicode))
     109            return self.transformbuilder.Build(transform, self.transformfactoryfactory()) 
     110        else: 
     111            return transform 
    107112 
  • trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/PathBuilder.py

    r622 r623  
    5858#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5959 
    60 from __future__ import generators 
    6160import re 
    6261 
     
    8281    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    8382 
    84     #def MoveTo(self, relative, x, y):  
    85     #    raise NotImplementedError 
    86     #def ClosePath(self, relative):  
    87     #    raise NotImplementedError 
    88     #def LineTo(self, relative, x, y):  
    89     #    raise NotImplementedError 
    90     #def HLineTo(self, relative, x):  
    91     #    raise NotImplementedError 
    92     #def VLineTo(self, relative, y):  
    93     #    raise NotImplementedError 
    94     #def CubicBezierTo(self, relative, x1, y1, x2, y2, x, y):  
    95     #    raise NotImplementedError 
    96     #def SmoothCurveTo(self, relative, x2, y2, x, y):  
    97     #    raise NotImplementedError 
    98     #def QuadraticBezierTo(self, relative, x1, y1, x, y):  
    99     #    raise NotImplementedError 
    100     #def SmoothQuadraticBezierTo(self, relative, x, y):  
    101     #    raise NotImplementedError 
    102     #def EllipticArcTo(self, relative, rx, ry, xrotation, largeArcFlag, sweepFlag, x, y):  
     83    #def move(self, relative, x, y):  
     84    #    raise NotImplementedError 
     85    #def closepath(self, relative):  
     86    #    raise NotImplementedError 
     87    #def line(self, relative, x, y):  
     88    #    raise NotImplementedError 
     89    #def hline(self, relative, x):  
     90    #    raise NotImplementedError 
     91    #def vline(self, relative, y):  
     92    #    raise NotImplementedError 
     93    #def cubicbezier(self, relative, x1, y1, x2, y2, x, y):  
     94    #    raise NotImplementedError 
     95    #def smoothcurve(self, relative, x2, y2, x, y):  
     96    #    raise NotImplementedError 
     97    #def quadraticbezier(self, relative, x1, y1, x, y):  
     98    #    raise NotImplementedError 
     99    #def smoothquadraticbezier(self, relative, x, y):  
     100    #    raise NotImplementedError 
     101    #def ellipticarc(self, relative, rx, ry, xrotation, largeArcFlag, sweepFlag, x, y):  
    103102    #    raise NotImplementedError 
    104103 
     
    109108 
    110109    def AddPathElement(self, name, relative, *args): 
    111         self.pathelements.append(name, relative, args
     110        self.pathelements.append((name, relative, args)
    112111         
    113112    def EndPath(self, pathstr):  
     
    139138 
    140139    pathCommandTable = { 
    141         'M': _pathcommand('MoveTo', False, 'L', (_coord, _coord)), 
    142         'm': _pathcommand('MoveTo', True, 'l', (_coord, _coord)), 
    143  
    144         'Z': _pathcommand('ClosePath', False, 'M', ()), 
    145         'z': _pathcommand('ClosePath', True, 'm', ()), 
    146  
    147         'L': _pathcommand('LineTo', False, None, (_coord, _coord)), 
    148         'l': _pathcommand('LineTo', True, None, (_coord, _coord)), 
    149  
    150         'H': _pathcommand('HLineTo', False, None, (_coord, )), 
    151         'h': _pathcommand('HLineTo', True, None, (_coord, )), 
    152  
    153         'V': _pathcommand('VLineTo', False, None, (_coord, )), 
    154         'v': _pathcommand('VLineTo', True, None, (_coord, )), 
    155  
    156         'C': _pathcommand('CubicBezierTo', False, None, (_coord, _coord, _coord, _coord, _coord, _coord)), 
    157         'c': _pathcommand('CubicBezierTo', True, None, (_coord, _coord, _coord, _coord, _coord, _coord)), 
    158  
    159         'S': _pathcommand('SmoothCurveTo', False, None, (_coord, _coord, _coord, _coord)), 
    160         's': _pathcommand('SmoothCurveTo', True, None, (_coord, _coord, _coord, _coord)), 
    161  
    162         'Q': _pathcommand('QuadraticBezierTo', False, None, (_coord, _coord, _coord, _coord)), 
    163         'q': _pathcommand('QuadraticBezierTo', True, None, (_coord, _coord, _coord, _coord)), 
    164  
    165         'T': _pathcommand('SmoothQuadraticBezierTo', False, None, (_coord, _coord)), 
    166         't': _pathcommand('SmoothQuadraticBezierTo', True, None, (_coord, _coord)), 
    167  
    168         'A': _pathcommand('EllipticArcTo', False, None, (_coord, _coord, _rotation, _flag, _flag, _coord, _coord)), 
    169         'a': _pathcommand('EllipticArcTo', True, None, (_coord, _coord, _rotation, _flag, _flag, _coord, _coord)), 
     140        'M': _pathcommand('move', False, 'L', (_coord, _coord)), 
     141        'm': _pathcommand('move', True, 'l', (_coord, _coord)), 
     142 
     143        'Z': _pathcommand('closepath', False, 'M', ()), 
     144        'z': _pathcommand('closepath', True, 'm', ()), 
     145 
     146        'L': _pathcommand('line', False, None, (_coord, _coord)), 
     147        'l': _pathcommand('line', True, None, (_coord, _coord)), 
     148 
     149        'H': _pathcommand('hline', False, None, (_coord, )), 
     150        'h': _pathcommand('hline', True, None, (_coord, )), 
     151 
     152        'V': _pathcommand('vline', False, None, (_coord, )), 
     153        'v': _pathcommand('vline', True, None, (_coord, )), 
     154 
     155        'C': _pathcommand('cubicbezier', False, None, (_coord, _coord, _coord, _coord, _coord, _coord)), 
     156        'c': _pathcommand('cubicbezier', True, None, (_coord, _coord, _coord, _coord, _coord, _coord)), 
     157 
     158        'S': _pathcommand('smoothcurve', False, None, (_coord, _coord, _coord, _coord)), 
     159        's': _pathcommand('smoothcurve', True, None, (_coord, _coord, _coord, _coord)), 
     160 
     161        'Q': _pathcommand('quadraticbezier', False, None, (_coord, _coord, _coord, _coord)), 
     162        'q': _pathcommand('quadraticbezier', True, None, (_coord, _coord, _coord, _coord)), 
     163 
     164        'T': _pathcommand('smoothquadraticbezier', False, None, (_coord, _coord)), 
     165        't': _pathcommand('smoothquadraticbezier', True, None, (_coord, _coord)), 
     166 
     167        'A': _pathcommand('ellipticarc', False, None, (_coord, _coord, _rotation, _flag, _flag, _coord, _coord)), 
     168        'a': _pathcommand('ellipticarc', True, None, (_coord, _coord, _rotation, _flag, _flag, _coord, _coord)), 
    170169        } 
    171170 
     
    174173 
    175174    def Build(self, *args, **kw): 
    176         return list(self.iterBuild(*args, **kw)) 
    177  
    178     def iterBuild(self, pathstr, pathfactory=None): 
     175        return list(self.Build(*args, **kw)) 
     176 
     177    def Build(self, pathstr, pathfactory=None): 
    179178        pathfactory = pathfactory or self.pathfactory 
    180179 
    181         result = pathfactory.BeginPath(pathstr) 
    182         if result is not None: yield result 
     180        pathfactory.BeginPath(pathstr) 
    183181 
    184182        matchidx = 0 
     
    207205 
    208206            # go get the path factory method for our command 
    209             result = pathfactory.AddPathElement(command['name'], command['relative'], *arguments) 
    210             if result is not None: yield result 
     207            pathfactory.AddPathElement(command['name'], command['relative'], *arguments) 
    211208 
    212209            # see if we have a command transfer 
     
    216213                command = self.pathCommandTable[commandidx] 
    217214 
    218         result = pathfactory.EndPath(pathstr) 
    219         if result is not None: yield result 
     215        pathfactory.EndPath(pathstr) 
     216        return pathfactory 
    220217 
    221218#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    225222if __name__=='__main__': 
    226223    class TestPathFactory(PathFactoryAbstract): 
     224        def __iter__(self): 
     225            return iter(self.results) 
    227226        def BeginPath(self, pathstr):  
    228             return "BeginPath" 
    229         def AddPathElement(self, name, relative, *args): 
    230             return getattr(self, name)(relative, *args
     227            self.results = ["begin()"] 
     228        def AddPathElement(self, name, *args): 
     229            self.results.append('%s%r' % (name, args)
    231230        def EndPath(self, pathstr):  
    232             return "EndPath" 
    233  
    234         def MoveTo(self, relative, x, y):  
    235             return "MoveTo", (relative, x, y) 
    236         def ClosePath(self, relative):  
    237             return "ClosePath", (relative,) 
    238         def LineTo(self, relative, x, y):  
    239             return "LineTo", (relative, x, y) 
    240         def HLineTo(self, relative, x):  
    241             return "HLineTo", (relative, x) 
    242         def VLineTo(self, relative, y):  
    243             return "VLineTo", (relative, y) 
    244         def CubicBezierTo(self, relative, x1, y1, x2, y2, x, y):  
    245             return "CubicBezierTo", (relative, x1, y1, x2, y2, x, y) 
    246         def SmoothCurveTo(self, relative, x2, y2, x, y):  
    247             return "SmoothCurveTo", (relative, x2, y2, x, y) 
    248         def QuadraticBezierTo(self, relative, x1, y1, x, y):  
    249             return "QuadraticBezierTo", (relative, x1, y1, x, y) 
    250         def SmoothQuadraticBezierTo(self, relative, x, y):  
    251             return "SmoothQuadraticBezierTo", (relative, x, y) 
    252         def EllipticArcTo(self, relative, rx, ry, xrotation, largeArcFlag, sweepFlag, x, y):  
    253             return "EllipticArcTo", (relative, rx, ry, xrotation, largeArcFlag, sweepFlag, x, y) 
    254  
    255     from pprint import pprint 
     231            self.results.append("end()") 
     232 
     233    separator = '\n    ' 
    256234    builder = PathCommandBuilder(TestPathFactory()) 
    257235 
    258236    print 
    259237    print "Example 1:" 
    260     pprint(builder.Build('M28.495428 -80.762271 L76.495428 -80.762271 ')) 
     238    for each in builder.Build('M28.495428 -80.762271 L76.495428 -80.762271 '): 
     239        print '   ', each 
    261240 
    262241    print 
    263242    print "Example 2:" 
    264     pprint(builder.Build('M28.495428 -80.762271 76.495428 -80.762271 ')) 
     243    for each in builder.Build('M28.495428 -80.762271 76.495428 -80.762271 '): 
     244        print '   ', each 
    265245 
    266246    print 
    267247    print "Example 3:" 
    268     pprint(builder.Build('M-32.351307 -1329.4836 A0.8746 0.8746 0 1 0 -30.602107 -1329.4836')) 
    269  
     248    for each in builder.Build('M-32.351307 -1329.4836 A0.8746 0.8746 0 1 0 -30.602107 -1329.4836'): 
     249        print '   ', each 
     250