├── MANIFEST.in ├── pysvg ├── util.py ├── __init__.py ├── script.py ├── style.py ├── linking.py ├── parser.py ├── gradient.py ├── text.py ├── turtle.py ├── structure.py ├── animate.py ├── core.py ├── builders.py ├── shape.py ├── filter.py └── attributes.py ├── README.md ├── .gitignore ├── setup.py ├── LICENSE.md └── sample └── tutorial.py /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.md 2 | -------------------------------------------------------------------------------- /pysvg/util.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Created on 12.04.2009 3 | 4 | @author: kerim 5 | ''' 6 | 7 | 8 | -------------------------------------------------------------------------------- /pysvg/__init__.py: -------------------------------------------------------------------------------- 1 | #__all__ = [] 2 | #for subpackage in ['core', 'filter', 'gradient', 'linking', 'script','shape','structure','style','text']: 3 | # try: 4 | # exec 'import ' + subpackage 5 | # __all__.append( subpackage ) 6 | # except ImportError: 7 | # pass 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /pysvg/script.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from .attributes import CoreAttrib, XLinkAttrib 8 | from .core import BaseElement 9 | 10 | 11 | 12 | class Script(BaseElement, CoreAttrib, XLinkAttrib): 13 | """ 14 | Class representing the script element of an svg doc. 15 | """ 16 | def __init__(self, **kwargs): 17 | BaseElement.__init__(self,'script') 18 | self.setKWARGS(**kwargs) 19 | 20 | def set_type(self, type): 21 | self._attributes['type']=type 22 | def get_type(self): 23 | return self._attributes.get('type') 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pysvg-py3 2 | ========= 3 | 4 | pysvg-py3 is a Python 3 portage of popular library [pysvg](http://codeboje.de/pysvg/). **I am not the original author 5 | of the library**. 6 | 7 | The original code has been duplicated, then lib2to3 has been used with default parameters to update the code 8 | for Python 3. Original code were also patched to run well on Python 3. See : 9 | - PR #4, related to issue #3 (thanks to @virresh) 10 | 11 | The resulting library is available on Pypi 12 | > Note: the root module has name 'pysvg' to silently replace the original version on Python 3 environments. For that 13 | reason, you should remove the original package before installing this one. 14 | 15 | pip uninstall pysvg 16 | pip install pysvg-py3 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | .pypirc 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *,cover 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | 55 | # Sphinx documentation 56 | docs/_build/ 57 | 58 | # PyBuilder 59 | target/ 60 | 61 | # PyCharm 62 | .idea/ 63 | -------------------------------------------------------------------------------- /pysvg/style.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from .attributes import CoreAttrib, XLinkAttrib 8 | from .core import BaseElement 9 | 10 | 11 | 12 | class Style(BaseElement, CoreAttrib, XLinkAttrib): 13 | """ 14 | Class representing the style element of an svg doc. 15 | """ 16 | def __init__(self, **kwargs): 17 | BaseElement.__init__(self,'style') 18 | self.setKWARGS(**kwargs) 19 | 20 | def set_type(self, type): 21 | self._attributes['type']=type 22 | def get_type(self): 23 | return self._attributes.get('type') 24 | 25 | def set_media(self, media): 26 | self._attributes['media']=media 27 | def get_media(self): 28 | return self._attributes.get('media') 29 | 30 | def set_title(self, title): 31 | self._attributes['title']=title 32 | def get_title(self): 33 | return self._attributes.get('title') 34 | 35 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from setuptools import setup, find_packages 3 | 4 | CURRENT_VERSION = '0.2.2-post3' 5 | 6 | setup( 7 | name='pysvg-py3', 8 | version=CURRENT_VERSION, 9 | description='Python 3 portage of pysvg', 10 | long_description=open('README.md').read(), 11 | long_description_content_type="text/markdown", 12 | author='Kerim Mansour', 13 | author_email='', 14 | url='https://github.com/alorence/pysvg-py3', 15 | packages=find_packages(), 16 | # Files included in sdist (using MANIFEST.in) will also be included in bdist* 17 | include_package_data=True, 18 | classifiers=[ 19 | "Development Status :: 4 - Beta", 20 | "Intended Audience :: Developers", 21 | "License :: OSI Approved :: BSD License", 22 | "Operating System :: OS Independent", 23 | 'Operating System :: MacOS :: MacOS X', 24 | 'Operating System :: Microsoft :: Windows', 25 | 'Operating System :: POSIX', 26 | "Programming Language :: Python", 27 | "Programming Language :: Python :: 3", 28 | "Programming Language :: Python :: 3.4", 29 | "Programming Language :: Python :: 3.5", 30 | "Programming Language :: Python :: 3.6", 31 | "Programming Language :: Python :: 3.7", 32 | "Topic :: Multimedia :: Graphics", 33 | ] 34 | ) 35 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2008-2012, Kerim Mansour 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /pysvg/linking.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from .attributes import * 8 | from .core import BaseElement 9 | 10 | 11 | 12 | class A(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib, XLinkAttrib): 13 | """ 14 | Class representing the a element of an svg doc. 15 | """ 16 | def __init__(self, target=None): 17 | BaseElement.__init__(self,'a') 18 | self.set_target(target) 19 | 20 | def set_transform(self, transform): 21 | self._attributes['transform']=transform 22 | def get_transform(self): 23 | return self._attributes.get('transform') 24 | 25 | def set_target(self, target): 26 | self._attributes['target']=target 27 | def get_target(self): 28 | return self._attributes.get('target') 29 | 30 | class View(BaseElement, CoreAttrib, ExternalAttrib): 31 | """ 32 | Class representing the view element of an svg doc. 33 | """ 34 | def __init__(self, ): 35 | BaseElement.__init__(self,'view') 36 | 37 | def set_transform(self, transform): 38 | self._attributes['transform']=transform 39 | def get_transform(self): 40 | return self._attributes.get('transform') 41 | 42 | def set_target(self, target): 43 | self._attributes['target']=target 44 | def get_target(self): 45 | return self._attributes.get('target') 46 | 47 | def set_viewBox(self,viewBox): 48 | self._attributes['viewBox']=viewBox 49 | 50 | def get_viewBox(self): 51 | return self._attributes['viewBox'] 52 | 53 | def set_preserveAspectRatio(self,preserveAspectRatio): 54 | self._attributes['preserveAspectRatio']=preserveAspectRatio 55 | 56 | def get_preserveAspectRatio(self): 57 | return self._attributes['preserveAspectRatio'] 58 | 59 | def set_zoomAndPan(self,zoomAndPan): 60 | self._attributes['zoomAndPan']=zoomAndPan 61 | def get_zoomAndPan(self): 62 | return self._attributes['zoomAndPan'] 63 | 64 | def set_viewTarget(self,viewTarget): 65 | self._attributes['viewTarget']=viewTarget 66 | def get_viewTarget(self): 67 | return self._attributes['viewTarget'] -------------------------------------------------------------------------------- /pysvg/parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from xml.dom import minidom 8 | from xml.dom import Node 9 | import string 10 | from pysvg.animate import * 11 | from pysvg.filter import * 12 | from pysvg.gradient import * 13 | from pysvg.linking import * 14 | from pysvg.script import * 15 | from pysvg.shape import * 16 | from pysvg.structure import * 17 | from pysvg.style import * 18 | from pysvg.text import * 19 | 20 | def calculateMethodName(attr): 21 | name=attr 22 | name=name.replace(':','_') 23 | name=name.replace('-','_') 24 | name='set_'+name 25 | return name 26 | 27 | def setAttributes(attrs,obj): 28 | for attr in list(attrs.keys()): 29 | if hasattr(obj, calculateMethodName(attr)): 30 | eval ('obj.'+calculateMethodName(attr))(attrs[attr].value) 31 | else: 32 | print(calculateMethodName(attr)+' not found in:'+obj._elementName) 33 | 34 | def build(node_, object): 35 | attrs = node_.attributes 36 | if attrs != None: 37 | setAttributes(attrs, object) 38 | for child_ in node_.childNodes: 39 | nodeName_ = child_.nodeName.split(':')[-1] 40 | if child_.nodeType == Node.ELEMENT_NODE: 41 | try: 42 | capitalLetter = nodeName_[0].upper() 43 | objectinstance=eval(capitalLetter+nodeName_[1:]) () 44 | except: 45 | print('no class for: '+nodeName_) 46 | continue 47 | object.addElement(build(child_,objectinstance)) 48 | elif child_.nodeType == Node.TEXT_NODE: 49 | #print "TextNode:"+child_.nodeValue 50 | #if child_.nodeValue.startswith('\n'): 51 | # print "TextNode starts with return:"+child_.nodeValue 52 | #else: 53 | # print "TextNode is:"+child_.nodeValue 54 | #object.setTextContent(child_.nodeValue) 55 | if child_.nodeValue != None and child_.nodeValue.strip() != '': 56 | # print(len(child_.nodeValue)) 57 | object.appendTextContent(child_.nodeValue) 58 | elif child_.nodeType == Node.CDATA_SECTION_NODE: 59 | object.appendTextContent('') 60 | elif child_.nodeType == Node.COMMENT_NODE: 61 | object.appendTextContent('') 62 | else: 63 | print("Some node:"+nodeName_+" value: "+child_.nodeValue) 64 | return object 65 | 66 | #TODO: packageprefix ? 67 | def parse(inFileName): 68 | doc = minidom.parse(inFileName) 69 | rootNode = doc.documentElement 70 | rootObj = Svg() 71 | build(rootNode,rootObj) 72 | # Enable Python to collect the space used by the DOM. 73 | doc = None 74 | #print rootObj.getXML() 75 | return rootObj 76 | 77 | 78 | -------------------------------------------------------------------------------- /pysvg/gradient.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from .attributes import * 8 | from .core import BaseElement, PointAttrib, DimensionAttrib 9 | 10 | 11 | 12 | class LinearGradient(BaseElement, CoreAttrib, XLinkAttrib, PaintAttrib, StyleAttrib, ExternalAttrib): 13 | """ 14 | Class representing the linearGradient element of an svg doc. 15 | """ 16 | def __init__(self, x1=None, y1=None, x2=None, y2=None, **kwargs): 17 | BaseElement.__init__(self, 'linearGradient') 18 | self.set_x1(x1) 19 | self.set_y1(y1) 20 | self.set_x2(x2) 21 | self.set_y2(y2) 22 | self.setKWARGS(**kwargs) 23 | 24 | def set_x1(self, x1): 25 | self._attributes['x1'] = x1 26 | def get_x1(self): 27 | return self._attributes.get('x1') 28 | 29 | def set_y1(self, y1): 30 | self._attributes['y1'] = y1 31 | def get_y1(self): 32 | return self._attributes.get('y1') 33 | 34 | def set_x2(self, x2): 35 | self._attributes['x2'] = x2 36 | def get_x2(self): 37 | return self._attributes.get('x2') 38 | 39 | def set_y2(self, y2): 40 | self._attributes['y2'] = y2 41 | def get_y2(self): 42 | return self._attributes.get('y2') 43 | 44 | def set_gradientUnits(self, gradientUnits): 45 | self._attributes['gradientUnits'] = gradientUnits 46 | def get_gradientUnits(self): 47 | return self._attributes.get('gradientUnits') 48 | 49 | def set_gradientTransform(self, gradientTransform): 50 | self._attributes['gradientTransform'] = gradientTransform 51 | def get_gradientTransform(self): 52 | return self._attributes.get('gradientTransform') 53 | 54 | def set_spreadMethod(self, spreadMethod): 55 | self._attributes['spreadMethod'] = spreadMethod 56 | def get_spreadMethod(self): 57 | return self._attributes.get('spreadMethod') 58 | 59 | class RadialGradient(BaseElement, CoreAttrib, XLinkAttrib, PaintAttrib, StyleAttrib, ExternalAttrib): 60 | """ 61 | Class representing the radialGradient element of an svg doc. 62 | """ 63 | def __init__(self, cx='50%', cy='50%', r='50%', fx='50%', fy='50%', **kwargs): 64 | BaseElement.__init__(self, 'radialGradient') 65 | self.set_cx(cx) 66 | self.set_cy(cy) 67 | self.set_fx(fx) 68 | self.set_fy(fy) 69 | self.set_r(r) 70 | self.setKWARGS(**kwargs) 71 | 72 | def set_cx(self, cx): 73 | self._attributes['cx'] = cx 74 | def get_cx(self): 75 | return self._attributes.get('cx') 76 | 77 | def set_cy(self, cy): 78 | self._attributes['cy'] = cy 79 | def get_cy(self): 80 | return self._attributes.get('cy') 81 | 82 | def set_r(self, r): 83 | self._attributes['r'] = r 84 | def get_r(self): 85 | return self._attributes.get('r') 86 | 87 | def set_fx(self, fx): 88 | self._attributes['fx'] = fx 89 | def get_fx(self): 90 | return self._attributes.get('fx') 91 | 92 | def set_fy(self, fy): 93 | self._attributes['fy'] = fy 94 | def get_fy(self): 95 | return self._attributes.get('fy') 96 | 97 | def set_gradientUnits(self, gradientUnits): 98 | self._attributes['gradientUnits'] = gradientUnits 99 | def get_gradientUnits(self): 100 | return self._attributes.get('gradientUnits') 101 | 102 | def set_gradientTransform(self, gradientTransform): 103 | self._attributes['gradientTransform'] = gradientTransform 104 | def get_gradientTransform(self): 105 | return self._attributes.get('gradientTransform') 106 | 107 | def set_spreadMethod(self, spreadMethod): 108 | self._attributes['spreadMethod'] = spreadMethod 109 | def get_spreadMethod(self): 110 | return self._attributes.get('spreadMethod') 111 | 112 | class Stop(BaseElement, CoreAttrib, StyleAttrib, PaintAttrib, GradientAttrib): 113 | """ 114 | Class representing the stop element of an svg doc. 115 | """ 116 | def __init__(self, offset=None, **kwargs): 117 | BaseElement.__init__(self, 'stop') 118 | self.set_offset(offset) 119 | self.setKWARGS(**kwargs) 120 | 121 | def set_offset(self, offset): 122 | self._attributes['offset'] = offset 123 | def get_offset(self): 124 | return self._attributes.get('offset') 125 | 126 | class Pattern(BaseElement, CoreAttrib, XLinkAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, PresentationAttributes_All, PointAttrib, DimensionAttrib): 127 | """ 128 | Class representing the pattern element of an svg doc. 129 | """ 130 | def __init__(self, x=None, y=None, width=None, height=None, patternUnits=None, patternContentUnits=None, patternTransform=None, viewBox=None, preserveAspectRatio=None, **kwargs): 131 | BaseElement.__init__(self, 'pattern') 132 | self.set_x(x) 133 | self.set_y(y) 134 | self.set_width(width) 135 | self.set_height(height) 136 | self.set_patternUnits(patternUnits) 137 | self.set_patternContentUnits(patternContentUnits) 138 | self.set_patternTransform(patternTransform) 139 | self.set_viewBox(viewBox) 140 | self.set_preserveAspectRatio(preserveAspectRatio) 141 | self.setKWARGS(**kwargs) 142 | 143 | def set_viewBox(self, viewBox): 144 | self._attributes['viewBox'] = viewBox 145 | 146 | def get_viewBox(self): 147 | return self._attributes['viewBox'] 148 | 149 | def set_preserveAspectRatio(self, preserveAspectRatio): 150 | self._attributes['preserveAspectRatio'] = preserveAspectRatio 151 | 152 | def get_preserveAspectRatio(self): 153 | return self._attributes['preserveAspectRatio'] 154 | 155 | def set_patternUnits(self, patternUnits): 156 | self._attributes['patternUnits'] = patternUnits 157 | 158 | def get_patternUnits(self): 159 | return self._attributes['patternUnits'] 160 | 161 | def set_patternContentUnits(self, patternContentUnits): 162 | self._attributes['patternContentUnits'] = patternContentUnits 163 | def get_patternContentUnits(self): 164 | return self._attributes['patternContentUnits'] 165 | 166 | def set_patternTransform(self, patternTransform): 167 | self._attributes['patternTransform'] = patternTransform 168 | 169 | def get_patternTransform(self): 170 | return self._attributes['patternTransform'] 171 | -------------------------------------------------------------------------------- /pysvg/text.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from .attributes import * 8 | from .core import BaseElement, PointAttrib, DeltaPointAttrib, RotateAttrib 9 | 10 | class AltGlyphDef(BaseElement, CoreAttrib): 11 | """ 12 | Class representing the altGlyphDef element of an svg doc. 13 | """ 14 | def __init__(self, **kwargs): 15 | BaseElement.__init__(self, 'altGlypfDef') 16 | self.setKWARGS(**kwargs) 17 | 18 | class AltGlyphItem(BaseElement, CoreAttrib): 19 | """ 20 | Class representing the altGlyphItem element of an svg doc. 21 | """ 22 | def __init__(self, **kwargs): 23 | BaseElement.__init__(self, 'altGlypfItem') 24 | self.setKWARGS(**kwargs) 25 | 26 | class GlyphRef(BaseElement, CoreAttrib, ExternalAttrib, StyleAttrib, FontAttrib, XLinkAttrib, PaintAttrib, PointAttrib, DeltaPointAttrib): 27 | """ 28 | Class representing the glyphRef element of an svg doc. 29 | """ 30 | def __init__(self, **kwargs): 31 | BaseElement.__init__(self, 'glyphRef') 32 | self.setKWARGS(**kwargs) 33 | 34 | def set_glyphRef(self, glyphRef): 35 | self._attributes['glyphRef'] = glyphRef 36 | def get_glyphRef(self): 37 | return self._attributes.get('glyphRef') 38 | 39 | def set_format(self, format): 40 | self._attributes['format'] = format 41 | def get_format(self): 42 | return self._attributes.get('format') 43 | 44 | def set_lengthAdjust(self, lengthAdjust): 45 | self._attributes['lengthAdjust'] = lengthAdjust 46 | def get_lengthAdjust(self): 47 | return self._attributes.get('lengthAdjust') 48 | 49 | class AltGlyph(GlyphRef, ConditionalAttrib, GraphicalEventsAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib, RotateAttrib): 50 | """ 51 | Class representing the altGlyph element of an svg doc. 52 | """ 53 | def __init__(self, **kwargs): 54 | BaseElement.__init__(self, 'altGlyph') 55 | self.setKWARGS(**kwargs) 56 | 57 | def set_textLength(self, textLength): 58 | self._attributes['textLength'] = textLength 59 | def get_textLength(self): 60 | return self._attributes.get('textLength') 61 | 62 | class TextPath(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, XLinkAttrib, FontAttrib, PaintAttrib, GraphicalEventsAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib): 63 | """ 64 | Class representing the textPath element of an svg doc. 65 | """ 66 | def __init__(self, **kwargs): 67 | BaseElement.__init__(self, 'textPath') 68 | self.setKWARGS(**kwargs) 69 | 70 | def set_startOffset(self, startOffset): 71 | self._attributes['startOffset'] = startOffset 72 | def get_startOffset(self): 73 | return self._attributes.get('startOffset') 74 | 75 | def set_textLength(self, textLength): 76 | self._attributes['textLength'] = textLength 77 | def get_textLength(self): 78 | return self._attributes.get('textLength') 79 | 80 | def set_lengthAdjust(self, lengthAdjust): 81 | self._attributes['lengthAdjust'] = lengthAdjust 82 | def get_lengthAdjust(self): 83 | return self._attributes.get('lengthAdjust') 84 | 85 | def set_method(self, method): 86 | self._attributes['method'] = method 87 | def get_method(self): 88 | return self._attributes.get('method') 89 | 90 | def set_spacing(self, spacing): 91 | self._attributes['spacing'] = spacing 92 | def get_spacing(self): 93 | return self._attributes.get('spacing') 94 | 95 | class Tref(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, XLinkAttrib, PointAttrib, DeltaPointAttrib, RotateAttrib, GraphicalEventsAttrib, PaintAttrib, FontAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib): 96 | """ 97 | Class representing the tref element of an svg doc. 98 | """ 99 | def __init__(self, **kwargs): 100 | BaseElement.__init__(self, 'tref') 101 | self.setKWARGS(**kwargs) 102 | 103 | def set_textLength(self, textLength): 104 | self._attributes['textLength'] = textLength 105 | def get_textLength(self): 106 | return self._attributes.get('textLength') 107 | 108 | def set_lengthAdjust(self, lengthAdjust): 109 | self._attributes['lengthAdjust'] = lengthAdjust 110 | def get_lengthAdjust(self): 111 | return self._attributes.get('lengthAdjust') 112 | 113 | class Tspan(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, PointAttrib, DeltaPointAttrib, RotateAttrib, GraphicalEventsAttrib, PaintAttrib, FontAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib): 114 | """ 115 | Class representing the tspan element of an svg doc. 116 | """ 117 | def __init__(self, x=None, y=None, dx=None, dy=None, rotate=None, textLength=None, lengthAdjust=None, **kwargs): 118 | BaseElement.__init__(self, 'tspan') 119 | self.set_x(x) 120 | self.set_y(y) 121 | self.set_dx(dx) 122 | self.set_dy(dy) 123 | self.set_rotate(rotate) 124 | self.set_textLength(textLength) 125 | self.set_lengthAdjust(lengthAdjust) 126 | self.setKWARGS(**kwargs) 127 | 128 | def set_textLength(self, textLength): 129 | self._attributes['textLength'] = textLength 130 | def get_textLength(self): 131 | return self._attributes.get('textLength') 132 | 133 | def set_lengthAdjust(self, lengthAdjust): 134 | self._attributes['lengthAdjust'] = lengthAdjust 135 | def get_lengthAdjust(self): 136 | return self._attributes.get('lengthAdjust') 137 | 138 | class Text(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, PointAttrib, DeltaPointAttrib, RotateAttrib, GraphicalEventsAttrib, PaintAttrib, FontAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib, TextAttrib): 139 | """ 140 | Class representing the text element of an svg doc. 141 | """ 142 | def __init__(self, content=None, x=None, y=None, dx=None, dy=None, rotate=None, textLength=None, lengthAdjust=None, **kwargs): 143 | BaseElement.__init__(self, 'text') 144 | if content != None: 145 | self.appendTextContent(content) 146 | self.set_x(x) 147 | self.set_y(y) 148 | self.set_dx(dx) 149 | self.set_dy(dy) 150 | self.set_rotate(rotate) 151 | self.set_textLength(textLength) 152 | self.set_lengthAdjust(lengthAdjust) 153 | self.setKWARGS(**kwargs) 154 | 155 | def set_transform(self, transform): 156 | self._attributes['transform'] = transform 157 | def get_transform(self): 158 | return self._attributes.get('transform') 159 | 160 | def set_textLength(self, textLength): 161 | self._attributes['textLength'] = textLength 162 | def get_textLength(self): 163 | return self._attributes.get('textLength') 164 | 165 | def set_lengthAdjust(self, lengthAdjust): 166 | self._attributes['lengthAdjust'] = lengthAdjust 167 | def get_lengthAdjust(self): 168 | return self._attributes.get('lengthAdjust') 169 | 170 | -------------------------------------------------------------------------------- /pysvg/turtle.py: -------------------------------------------------------------------------------- 1 | ''' 2 | (C) 2008, 2009, 2010 Kerim Mansour 3 | For licensing information please refer to license.txt 4 | ''' 5 | import math 6 | from .shape import Polyline 7 | 8 | class Vector(object): 9 | """ 10 | Class representing a vector. Used to determine position of the turtle as well as heading. 11 | Also used to calculate movement. 12 | Vector class is inspired by tips and code from: 13 | - http://slowchop.com/2006/07/15/a-fast-python-vector-class/ 14 | - http://www.kokkugia.com/wiki/index.php5?title=Python_vector_class 15 | - http://xturtle.rg16.at/code/xturtle.py 16 | """ 17 | __slots__ = ('x', 'y') 18 | def __init__(self, x, y): 19 | """ Initializes the vector. 20 | x and y are coordinates and should be numbers. 21 | They will be cast to floats 22 | """ 23 | self.x = float(x) 24 | self.y = float(y) 25 | 26 | def __add__(self, vector): 27 | return Vector(self.x + vector.x, self.y + vector.y) 28 | 29 | def __sub__(self, vector): 30 | return Vector(self.x - vector.x, self.y - vector.y) 31 | 32 | def __mul__(self, vector): 33 | if isinstance(vector, Vector): 34 | return self.x * vector.x + self.y * vector.y 35 | return Vector(self.x * vector, self.y * vector) 36 | 37 | def __rmul__(self, vector): 38 | if isinstance(vector, int) or isinstance(vector, float): 39 | return Vector(self.x * vector, self.y * vector) 40 | 41 | def __neg__(self): 42 | return Vector(-self.x, -self.y) 43 | 44 | def __abs__(self): 45 | return (self.x ** 2 + self.y ** 2) ** 0.5 46 | 47 | def rotate(self, angle): 48 | """Rotates self counterclockwise by angle 49 | (the angle must be given in a 360 degree system) 50 | """ 51 | perp = Vector(-self.y, self.x) 52 | angle = angle * math.pi / 180.0 53 | c, s = math.cos(angle), math.sin(angle) 54 | return Vector(self.x * c + perp.x * s, self.y * c + perp.y * s) 55 | 56 | def __getnewargs__(self): 57 | return (self.x, self.y) 58 | 59 | def __repr__(self): 60 | return "%.2f,%.2f " % (self.x, self.y) 61 | 62 | class Turtle(object): 63 | """ 64 | Class representing a classical turtle object known from logo and other implementations. 65 | Note that currently each turtle has exactly ONE style of drawing, so if you intend to draw in multiple styles several instances of turtles are needed. 66 | A turtle will only actually draw when the pen is down (default=false). 67 | An xml representation usable for pysvg can ge retrieved using the getXML()-method. 68 | To add the turtles paths to an svg you have two opions: 69 | Either you simply call "addTurtlePathToSVG" or you can create an svg element and append the Elements of the turtle using a loop, e.g: 70 | s=svg(...) 71 | t=Turtle(...) 72 | for element in t.getSVGElements(): 73 | s.addElement(element) 74 | """ 75 | def __init__(self, initialPosition=Vector(0.0, 0.0), initialOrientation=Vector(1.0, 0.0), fill='white', stroke='black', strokeWidth='1', penDown=False): 76 | """ Initializes a new Turtle with a new initial position and orientation as well as defaultvalues for style. 77 | """ 78 | self.fill = fill 79 | self.stroke = stroke 80 | self.strokeWidth = strokeWidth 81 | self._position = initialPosition 82 | self._orient = initialOrientation 83 | self._penDown = penDown 84 | self._svgElements = [] 85 | self._pointsOfPolyline = [] 86 | 87 | 88 | def forward(self, distance): 89 | """ Moves the turtle forwards by distance in the direction it is facing. 90 | If the pen is lowered it will also add to the currently drawn polyline. 91 | """ 92 | self._move(distance) 93 | 94 | def backward(self, distance): 95 | """ Moves the turtle backwards by distance in the direction it is facing. 96 | If the pen is lowered it will also add to the currently drawn polyline. 97 | """ 98 | self._move(-distance) 99 | 100 | def right(self, angle): 101 | """Rotates the turtle to the right by angle. 102 | """ 103 | self._rotate(angle) 104 | 105 | def left(self, angle): 106 | """Rotates the turtle to the left by angle. 107 | """ 108 | self._rotate(-angle) 109 | 110 | def moveTo(self, vector): 111 | """ Moves the turtle to the new position. Orientation is kept as it is. 112 | If the pen is lowered it will also add to the currently drawn polyline. 113 | """ 114 | self._position = vector 115 | if self.isPenDown(): 116 | self._pointsOfPolyline.append(self._position) 117 | 118 | def penUp(self): 119 | """ Raises the pen. Any movement will not draw lines till pen is lowered again. 120 | """ 121 | if self._penDown==True: 122 | self._penDown = False 123 | self._addPolylineToElements() 124 | 125 | def penDown(self): 126 | """ Lowers the pen down again. A new polyline will be created for drawing. 127 | Old polylines will be stored in the stack 128 | """ 129 | #if self._penDown==False: 130 | self._penDown = True 131 | self._addPolylineToElements() 132 | 133 | def finish(self): 134 | """MUST be called when drawing is finished. Else the last path will not be added to the stack. 135 | """ 136 | self._addPolylineToElements() 137 | 138 | def isPenDown(self): 139 | """ Retrieve current status of the pen.(boolean) 140 | """ 141 | return self._penDown 142 | 143 | def getPosition(self): 144 | """ Retrieve current position of the turtle.(Vector) 145 | """ 146 | return self._position 147 | 148 | def getOrientation(self): 149 | """ Retrieve current orientation of the turtle.(Vector) 150 | """ 151 | return self._orient 152 | 153 | def setOrientation(self, vec): 154 | """ Sets the orientation of the turtle.(Vector) 155 | """ 156 | self._orient=vec 157 | 158 | def _move(self, distance): 159 | """ Moves the turtle by distance in the direction it is facing. 160 | If the pen is lowered it will also add to the currently drawn polyline. 161 | """ 162 | self._position = self._position + self._orient * distance 163 | if self.isPenDown(): 164 | x = round(self._position.x, 2) 165 | y = round(self._position.y, 2) 166 | self._pointsOfPolyline.append(Vector(x, y)) 167 | 168 | def _rotate(self, angle): 169 | """Rotates the turtle. 170 | """ 171 | self._orient = self._orient.rotate(angle) 172 | 173 | def _addPolylineToElements(self): 174 | """Creates a new Polyline element that will be used for future movement/drawing. 175 | The old one (if filled) will be stored on the movement stack. 176 | """ 177 | if (len(self._pointsOfPolyline) > 1): 178 | s = '' 179 | for point in self._pointsOfPolyline: 180 | s += str(point) + ' '#str(point.x) + ',' + str(point.y) + ' ' 181 | p = Polyline(s) 182 | p.set_style('fill:' + self.fill + '; stroke:' + self.stroke + '; stroke-width:' + self.strokeWidth) 183 | self._svgElements.append(p) 184 | self._pointsOfPolyline = [] 185 | self._pointsOfPolyline.append(Vector(self._position.x, self._position.y)) 186 | 187 | def getXML(self): 188 | """Retrieves the pysvg elements that make up the turtles path and returns them as String in an xml representation. 189 | """ 190 | s = '' 191 | for element in self._svgElements: 192 | s += element.getXML() 193 | return s 194 | 195 | def getSVGElements(self): 196 | """Retrieves the pysvg elements that make up the turtles path and returns them as list. 197 | """ 198 | return self._svgElements 199 | 200 | def addTurtlePathToSVG(self, svgContainer): 201 | """Adds the paths of the turtle to an existing svg container. 202 | """ 203 | for element in self.getSVGElements(): 204 | svgContainer.addElement(element) 205 | return svgContainer 206 | -------------------------------------------------------------------------------- /pysvg/structure.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | This module includes the elements found in http://www.w3.org/TR/SVG/struct.html 5 | 6 | (C) 2008, 2009 Kerim Mansour 7 | For licensing information please refer to license.txt 8 | ''' 9 | from .attributes import * 10 | from .core import BaseElement, PointAttrib, DimensionAttrib 11 | 12 | 13 | 14 | 15 | class G(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib): 16 | """ 17 | Class representing the g element of an svg doc. 18 | """ 19 | def __init__(self, **kwargs): 20 | BaseElement.__init__(self, 'g') 21 | self.setKWARGS(**kwargs) 22 | 23 | def set_transform(self, transform): 24 | self._attributes['transform'] = transform 25 | def get_transform(self): 26 | return self._attributes.get('transform') 27 | 28 | class Defs(G): 29 | """ 30 | Class representing the defs element of an svg doc. 31 | """ 32 | def __init__(self,**kwargs): 33 | BaseElement.__init__(self, 'defs') 34 | self.setKWARGS(**kwargs) 35 | 36 | 37 | class Desc(BaseElement, CoreAttrib, StyleAttrib): 38 | """ 39 | Class representing the desc element of an svg doc. 40 | """ 41 | def __init__(self,**kwargs): 42 | BaseElement.__init__(self, 'desc') 43 | self.setKWARGS(**kwargs) 44 | 45 | class Title(Desc): 46 | """ 47 | Class representing the title element of an svg doc. 48 | """ 49 | def __init__(self,**kwargs): 50 | BaseElement.__init__(self, 'title') 51 | self.setKWARGS(**kwargs) 52 | 53 | class Metadata(BaseElement, CoreAttrib): 54 | """ 55 | Class representing the metadata element of an svg doc. 56 | """ 57 | def __init__(self,**kwargs): 58 | BaseElement.__init__(self, 'metadata') 59 | self.setKWARGS(**kwargs) 60 | 61 | class Symbol(BaseElement, CoreAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib): 62 | """ 63 | Class representing the symbol element of an svg doc. 64 | """ 65 | def __init__(self,**kwargs): 66 | BaseElement.__init__(self, 'symbol') 67 | self.setKWARGS(**kwargs) 68 | 69 | def set_viewBox(self, viewBox): 70 | self._attributes['viewBox'] = viewBox 71 | 72 | def get_viewBox(self): 73 | return self._attributes['viewBox'] 74 | 75 | def set_preserveAspectRatio(self, preserveAspectRatio): 76 | self._attributes['preserveAspectRatio'] = preserveAspectRatio 77 | 78 | def get_preserveAspectRatio(self): 79 | return self._attributes['preserveAspectRatio'] 80 | 81 | class Use(BaseElement, CoreAttrib, StyleAttrib, ConditionalAttrib, PointAttrib, DimensionAttrib, XLinkAttrib, PresentationAttributes_All, GraphicalEventsAttrib): 82 | """ 83 | Class representing the use element of an svg doc. 84 | """ 85 | def __init__(self,**kwargs): 86 | BaseElement.__init__(self, 'use') 87 | self.setKWARGS(**kwargs) 88 | 89 | def set_transform(self, transform): 90 | self._attributes['transform'] = transform 91 | def get_transform(self): 92 | return self._attributes.get('transform') 93 | 94 | class Svg(BaseElement, CoreAttrib, StyleAttrib, ConditionalAttrib, PointAttrib, DimensionAttrib, XLinkAttrib, PresentationAttributes_All, GraphicalEventsAttrib, DocumentEventsAttrib): 95 | """ 96 | Class representing the svg element of an svg doc. 97 | """ 98 | def __init__(self, x=None, y=None, width=None, height=None,**kwargs): 99 | BaseElement.__init__(self, 'svg') 100 | self.set_xmlns('http://www.w3.org/2000/svg') 101 | self.set_xmlns_xlink('http://www.w3.org/1999/xlink') 102 | self.set_version('1.1') 103 | self.set_x(x) 104 | self.set_y(y) 105 | self.set_height(height) 106 | self.set_width(width) 107 | self.setKWARGS(**kwargs) 108 | 109 | def set_version(self, version): 110 | self._attributes['version'] = version 111 | 112 | def get_version(self): 113 | return self._attributes['version'] 114 | 115 | def set_xmlns(self, xmlns): 116 | self._attributes['xmlns'] = xmlns 117 | 118 | def get_xmlns(self): 119 | return self._attributes['xmlns'] 120 | 121 | def set_xmlns_xlink(self, xmlns_xlink): 122 | self._attributes['xmlns:xlink'] = xmlns_xlink 123 | 124 | def get_xmlns_xlink(self): 125 | return self._attributes.get('xmlns:xlink') 126 | 127 | def set_viewBox(self, viewBox): 128 | self._attributes['viewBox'] = viewBox 129 | def get_viewBox(self): 130 | return self._attributes['viewBox'] 131 | 132 | def set_preserveAspectRatio(self, preserveAspectRatio): 133 | self._attributes['preserveAspectRatio'] = preserveAspectRatio 134 | def get_preserveAspectRatio(self): 135 | return self._attributes['preserveAspectRatio'] 136 | 137 | def set_transform(self, transform): 138 | self._attributes['transform'] = transform 139 | def get_transform(self): 140 | return self._attributes.get('transform') 141 | 142 | def set_zoomAndPan(self, zoomAndPan): 143 | self._attributes['zoomAndPan'] = zoomAndPan 144 | def get_zoomAndPan(self): 145 | return self._attributes['zoomAndPan'] 146 | 147 | def set_contentScriptType(self, contentScriptType): 148 | self._attributes['contentScriptType'] = contentScriptType 149 | def get_contentScriptType(self): 150 | return self._attributes['contentScriptType'] 151 | 152 | def set_contentStyleType(self, contentStyleType): 153 | self._attributes['contentStyleType'] = contentStyleType 154 | def get_contentStyleType(self): 155 | return self._attributes['contentStyleType'] 156 | 157 | def set_baseProfile(self, baseProfile): 158 | self._attributes['baseProfile'] = baseProfile 159 | def get_baseProfile(self): 160 | return self._attributes['baseProfile'] 161 | #todo: check color.attrib and colorprofile.attrib. supposedly in image 162 | class Image(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ViewportAttrib, PaintAttrib, OpacityAttrib, GraphicsAttrib, ClipAttrib, MaskAttrib, FilterAttrib, GraphicalEventsAttrib, CursorAttrib, XLinkAttrib, ExternalAttrib, PointAttrib, DimensionAttrib): 163 | """ 164 | Class representing the image element of an svg doc. 165 | """ 166 | def __init__(self, x=None, y=None, width=None, height=None, preserveAspectRatio=None,**kwargs): 167 | BaseElement.__init__(self, 'image') 168 | self.set_x(x) 169 | self.set_y(y) 170 | self.set_height(height) 171 | self.set_width(width) 172 | self.set_preserveAspectRatio(preserveAspectRatio) 173 | self.setKWARGS(**kwargs) 174 | 175 | #def set_embedded(self,embedded): 176 | # self._attributes['embedded']=embedded 177 | 178 | def set_preserveAspectRatio(self, preserveAspectRatio): 179 | self._attributes['preserveAspectRatio'] = preserveAspectRatio 180 | def get_preserveAspectRatio(self): 181 | return self._attributes['preserveAspectRatio'] 182 | 183 | def set_transform(self, transform): 184 | self._attributes['transform'] = transform 185 | def get_transform(self): 186 | return self._attributes.get('transform') 187 | 188 | class Switch(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, PresentationAttributes_All, GraphicalEventsAttrib, ExternalAttrib): 189 | """ 190 | Class representing the switch element of an svg doc. 191 | """ 192 | def __init__(self,**kwargs): 193 | BaseElement.__init__(self, 'switch') 194 | self.setKWARGS(**kwargs) 195 | 196 | def set_transform(self, transform): 197 | self._attributes['transform'] = transform 198 | def get_transform(self): 199 | return self._attributes.get('transform') 200 | 201 | class ClipPath(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib): 202 | """ 203 | Class representing the clipPath element of an svg doc. 204 | """ 205 | def __init__(self, id=None, transform=None, clipPathUnits=None,**kwargs): 206 | BaseElement.__init__(self, 'clipPath') 207 | self.set_id(id) 208 | self.set_transform(transform) 209 | self.set_clipPathUnits(clipPathUnits) 210 | self.setKWARGS(**kwargs) 211 | 212 | 213 | def set_transform(self, transform): 214 | self._attributes['transform'] = transform 215 | def get_transform(self): 216 | return self._attributes.get('transform') 217 | 218 | def set_clipPathUnits(self, clipPathUnits): 219 | self._attributes['clipPathUnits'] = clipPathUnits 220 | 221 | def get_clipPathUnits(self): 222 | return self._attributes['clipPathUnits'] 223 | -------------------------------------------------------------------------------- /pysvg/animate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from .attributes import * 8 | from .core import BaseShape, BaseElement 9 | 10 | ##################################################### 11 | # Attribute sets for animations 12 | # Animation elements see below 13 | ##################################################### 14 | class AnimationAttrib(XLinkAttrib): 15 | """ 16 | The AnimationAttrib class defines the Animation.attrib attribute set. 17 | """ 18 | 19 | class AnimationAttributeAttrib: 20 | """ 21 | The AnimationAttributeAttrib class defines the AnimationAttribute.attrib attribute set. 22 | """ 23 | def set_attributeName(self, attributeName): 24 | self._attributes['attributeName'] = attributeName 25 | def get_attributeName(self): 26 | return self._attributes.get('attributeName') 27 | 28 | def set_attributeType(self, attributeType): 29 | self._attributes['attributeType'] = attributeType 30 | def get_attributeType(self): 31 | return self._attributes.get('attributeType') 32 | 33 | class AnimationTimingAttrib: 34 | """ 35 | The AnimationTimingAttrib class defines the AnimationTiming.attrib attribute set. 36 | """ 37 | def set_begin(self, begin): 38 | self._attributes['begin'] = begin 39 | def get_begin(self): 40 | return self._attributes.get('begin') 41 | 42 | def set_dur(self, dur): 43 | self._attributes['dur'] = dur 44 | def get_dur(self): 45 | return self._attributes.get('dur') 46 | 47 | def set_end(self, end): 48 | self._attributes['end'] = end 49 | def get_end(self): 50 | return self._attributes.get('end') 51 | 52 | def set_min(self, min): 53 | self._attributes['min'] = min 54 | def get_min(self): 55 | return self._attributes.get('min') 56 | 57 | def set_max(self, max): 58 | self._attributes['max'] = max 59 | def get_max(self): 60 | return self._attributes.get('max') 61 | 62 | def set_restart(self, restart): 63 | self._attributes['restart'] = restart 64 | def get_restart(self): 65 | return self._attributes.get('restart') 66 | 67 | def set_repeatCount(self, repeatCount): 68 | self._attributes['repeatCount'] = repeatCount 69 | def get_repeatCount(self): 70 | return self._attributes.get('repeatCount') 71 | 72 | def set_repeatDur(self, repeatDur): 73 | self._attributes['repeatDur'] = repeatDur 74 | def get_repeatDur(self): 75 | return self._attributes.get('repeatDur') 76 | 77 | def set_fill(self, fill): 78 | self._attributes['fill'] = fill 79 | def get_fill(self): 80 | return self._attributes.get('fill') 81 | 82 | class AnimationValueAttrib: 83 | """ 84 | The AnimationValueAttrib class defines the AnimationValue.attrib attribute set. 85 | """ 86 | def set_calcMode(self, calcMode): 87 | self._attributes['calcMode'] = calcMode 88 | def get_calcMode(self): 89 | return self._attributes.get('calcMode') 90 | 91 | def set_values(self, values): 92 | self._attributes['values'] = values 93 | def get_values(self): 94 | return self._attributes.get('values') 95 | 96 | def set_keyTimes(self, keyTimes): 97 | self._attributes['keyTimes'] = keyTimes 98 | def get_keyTimes(self): 99 | return self._attributes.get('keyTimes') 100 | 101 | def set_keySplines(self, keySplines): 102 | self._attributes['keySplines'] = keySplines 103 | def get_keySplines(self): 104 | return self._attributes.get('keySplines') 105 | 106 | def set_from(self, fromField): 107 | self._attributes['from'] = fromField 108 | def get_from(self): 109 | return self._attributes.get('from') 110 | 111 | def set_to(self, toField): 112 | self._attributes['to'] = toField 113 | def get_to(self): 114 | return self._attributes.get('to') 115 | 116 | def set_by(self, by): 117 | self._attributes['by'] = by 118 | def get_by(self): 119 | return self._attributes.get('by') 120 | 121 | class AnimationAdditionAttrib: 122 | """ 123 | The AnimationAdditionAttrib class defines the AnimationAddition.attrib attribute set. 124 | """ 125 | def set_additive(self, additive): 126 | self._attributes['additive'] = additive 127 | def get_additive(self): 128 | return self._attributes.get('additive') 129 | 130 | def set_accumulate(self, accumulate): 131 | self._attributes['accumulate'] = accumulate 132 | def get_accumulate(self): 133 | return self._attributes.get('accumulate') 134 | 135 | class AnimationEventsAttrib: 136 | """ 137 | The AnimationEventsAttrib class defines the AnimationEvents.attrib attribute set. 138 | """ 139 | def set_onbegin(self, onbegin): 140 | self._attributes['onbegin'] = onbegin 141 | def get_onbegin(self): 142 | return self._attributes.get('onbegin') 143 | 144 | def set_onend(self, onend): 145 | self._attributes['onend'] = onend 146 | def get_onend(self): 147 | return self._attributes.get('onend') 148 | 149 | def set_onrepeat(self, onrepeat): 150 | self._attributes['onrepeat'] = onrepeat 151 | def get_onrepeat(self): 152 | return self._attributes.get('onrepeat') 153 | 154 | def set_onload(self, onload): 155 | self._attributes['onload'] = onload 156 | def get_onload(self): 157 | return self._attributes.get('onload') 158 | ############################################## 159 | # Animation Elements 160 | ############################################## 161 | class Animate(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, AnimationEventsAttrib, AnimationAttrib, AnimationAttributeAttrib, AnimationTimingAttrib, AnimationValueAttrib, AnimationAdditionAttrib): 162 | """ 163 | Class representing the animate element of an svg doc. 164 | """ 165 | def __init__(self, **kwargs): 166 | BaseElement.__init__(self, 'animate') 167 | self.setKWARGS(**kwargs) 168 | 169 | class Set(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, AnimationEventsAttrib, AnimationAttrib, AnimationAttributeAttrib, AnimationTimingAttrib): 170 | """ 171 | Class representing the set element of an svg doc. 172 | """ 173 | def __init__(self, **kwargs): 174 | BaseElement.__init__(self, 'set') 175 | self.setKWARGS(**kwargs) 176 | 177 | def set_to(self, toField): 178 | self._attributes['to'] = toField 179 | def get_to(self): 180 | return self._attributes.get('to') 181 | 182 | class AnimateMotion(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, AnimationEventsAttrib, AnimationAttrib, AnimationTimingAttrib, AnimationValueAttrib, AnimationAdditionAttrib): 183 | """ 184 | Class representing the animateMotion element of an svg doc. 185 | """ 186 | def __init__(self, **kwargs): 187 | BaseElement.__init__(self, 'animateMotion') 188 | self.setKWARGS(**kwargs) 189 | 190 | def set_path(self, path): 191 | self._attributes['path'] = path 192 | def get_path(self): 193 | return self._attributes.get('path') 194 | 195 | def set_keyPoints(self, keyPoints): 196 | self._attributes['keyPoints'] = keyPoints 197 | def get_keyPoints(self): 198 | return self._attributes.get('keyPoints') 199 | 200 | def set_rotate(self, rotate): 201 | self._attributes['rotate'] = rotate 202 | def get_rotate(self): 203 | return self._attributes.get('rotate') 204 | 205 | def set_origin(self, origin): 206 | self._attributes['origin'] = origin 207 | def get_origin(self): 208 | return self._attributes.get('origin') 209 | 210 | class AnimateTransform(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, AnimationEventsAttrib, AnimationAttrib, AnimationAttributeAttrib, AnimationTimingAttrib, AnimationValueAttrib, AnimationAdditionAttrib): 211 | """ 212 | Class representing the animateTransform element of an svg doc. 213 | """ 214 | def __init__(self, **kwargs): 215 | BaseElement.__init__(self, 'animateTransform') 216 | self.setKWARGS(**kwargs) 217 | 218 | def set_type(self, type): 219 | self._attributes['type'] = type 220 | def get_type(self): 221 | return self._attributes.get('type') 222 | 223 | class AnimateColor(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, AnimationEventsAttrib, AnimationAttrib, AnimationAttributeAttrib, AnimationTimingAttrib, AnimationValueAttrib, AnimationAdditionAttrib): 224 | """ 225 | Class representing the animateColor element of an svg doc. 226 | """ 227 | def __init__(self, **kwargs): 228 | BaseElement.__init__(self, 'animateColor') 229 | self.setKWARGS(**kwargs) 230 | 231 | class Mpath(BaseShape, CoreAttrib, XLinkAttrib, ExternalAttrib): 232 | """ 233 | Class representing the animateColor element of an svg doc. 234 | """ 235 | def __init__(self, **kwargs): 236 | BaseElement.__init__(self, 'mpath') 237 | self.setKWARGS(**kwargs) 238 | -------------------------------------------------------------------------------- /pysvg/core.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from .attributes import CoreAttrib, ConditionalAttrib, StyleAttrib, GraphicalEventsAttrib, PaintAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib 8 | import codecs 9 | 10 | class BaseElement: 11 | """ 12 | This is the base class for all svg elements like title etc. It provides common functionality. 13 | It should NOT be directly used by anyone. 14 | """ 15 | def __init__(self, elementName): 16 | """ 17 | initializes the object 18 | @type elementName: string 19 | @param elementName: name of the element (used for the xml tag) 20 | """ 21 | self._elementName=elementName 22 | self._attributes={} #key value 23 | self._textContent="" 24 | self._subElements=[] 25 | 26 | def appendTextContent(self,text): 27 | self.addElement(TextContent(text)) 28 | 29 | def addElement(self,element): 30 | self._subElements.append(element) 31 | 32 | def getElementAt(self,pos): 33 | """ returns the element at a specific position within this svg 34 | """ 35 | return self._subElements[pos] 36 | 37 | def getAllElements(self): 38 | """ returns all elements contained within the top level element list of this element 39 | """ 40 | return self._subElements 41 | 42 | def getAllElementsOfHirarchy(self): 43 | """ returns ALL elements of the complete hirarchy as a flat list 44 | """ 45 | allElements=[] 46 | for element in self.getAllElements(): 47 | allElements.append(element) 48 | if isinstance(element, BaseElement): 49 | allElements.extend(element.getAllElementsOfHirarchy()) 50 | return allElements 51 | 52 | def getElementByID(self, id): 53 | """ returns an element with the specific id and the position of that element within the svg elements array 54 | """ 55 | pos=0 56 | for element in self._subElements: 57 | if element.get_id()==id: 58 | return (element,pos) 59 | pos+=1 60 | 61 | def getElementsByType(self, type): 62 | """ 63 | retrieves all Elements that are of type type 64 | @type type: class 65 | @param type: type of the element 66 | """ 67 | foundElements=[] 68 | for element in self.getAllElementsOfHirarchy(): 69 | if isinstance(element, type): 70 | foundElements.append(element) 71 | 72 | return foundElements 73 | 74 | def insertElementAt(self, element, pos): 75 | return self._subElements.insert(pos, element) 76 | 77 | 78 | def getXML(self): 79 | """ 80 | Return a XML representation of the current element. 81 | This function can be used for debugging purposes. It is also used by getXML in SVG 82 | 83 | @return: the representation of the current element as an xml string 84 | """ 85 | xml='<'+self._elementName+' ' 86 | for key,value in list(self._attributes.items()): 87 | if value != None: 88 | xml+=key+'="'+self.quote_attrib(str(value))+'" ' 89 | if len(self._subElements)==0: #self._textContent==None and 90 | xml+=' />\n' 91 | else: 92 | xml+=' >\n' 93 | #if self._textContent==None: 94 | for subelement in self._subElements: 95 | s = subelement.getXML() 96 | if type(s) != str: 97 | s = str(s) 98 | xml+=s 99 | # xml+=str(subelement.getXML()) 100 | #else: 101 | #if self._textContent!=None: 102 | # xml+=self._textContent 103 | xml+='\n' 104 | #print xml 105 | return xml 106 | 107 | #generic methods to set and get atributes (should only be used if something is not supported yet 108 | def setAttribute(self, attribute_name, attribute_value): 109 | self._attributes[attribute_name]=attribute_value 110 | 111 | def getAttribute(self, attribute_name): 112 | return self._attributes.get(attribute_name) 113 | 114 | def getAttributes(self): 115 | """ get all atributes of the element 116 | """ 117 | return self._attributes 118 | 119 | def setKWARGS(self, **kwargs): 120 | """ 121 | Used to set all attributes given in a **kwargs parameter. 122 | Might throw an Exception if attribute was not found. 123 | #TODO: check if we should fix this using "setAttribute" 124 | """ 125 | for key in list(kwargs.keys()): 126 | #try: 127 | f = getattr(self,'set_' + key) 128 | f(kwargs[key]) 129 | #except: 130 | # print('attribute not found via setter ') 131 | # self.setAttribute(self, key, kwargs[key]) 132 | 133 | def wrap_xml(self, xml, encoding ='ISO-8859-1', standalone='no'): 134 | """ 135 | Method that provides a standard svg header string for a file 136 | """ 137 | header = '''''' %(encoding, standalone) 138 | return header+xml 139 | 140 | def save(self, filename, encoding ='ISO-8859-1', standalone='no'): 141 | """ 142 | Stores any element in a svg file (including header). 143 | Calling this method only makes sense if the root element is an svg elemnt 144 | """ 145 | f = codecs.open(filename, 'w', encoding) 146 | s = self.wrap_xml(self.getXML(), encoding, standalone) 147 | #s = s.replace("&", "&") 148 | f.write(s) 149 | f.close() 150 | #f = open(filename, 'w') 151 | #f.write(self.wrap_xml(self.getXML(), encoding, standalone)) 152 | #f.close() 153 | 154 | def quote_attrib(self, inStr): 155 | """ 156 | Transforms characters between xml notation and python notation. 157 | """ 158 | s1 = (isinstance(inStr, str) and inStr or 159 | '%s' % inStr) 160 | s1 = s1.replace('&', '&') 161 | s1 = s1.replace('<', '<') 162 | s1 = s1.replace('>', '>') 163 | if '"' in s1: 164 | # if "'" in s1: 165 | s1 = '%s' % s1.replace('"', """) 166 | # else: 167 | # s1 = "'%s'" % s1 168 | #else: 169 | # s1 = '"%s"' % s1 170 | return s1 171 | 172 | class TextContent: 173 | """ 174 | Class for the text content of an xml element. Can also include PCDATA 175 | """ 176 | def __init__(self,content): 177 | self.content=content 178 | def setContent(self,content): 179 | self.content=content 180 | def getXML(self): 181 | return self.content 182 | def get_id(self): 183 | return None 184 | 185 | #--------------------------------------------------------------------------# 186 | # Below are classes that define attribute sets that pysvg uses for convenience. 187 | # There exist no corresponding attribute sets in svg. 188 | # We simply use these classes as containers for often used attributes. 189 | #--------------------------------------------------------------------------# 190 | class PointAttrib: 191 | """ 192 | The PointAttrib class defines x and y. 193 | """ 194 | def set_x(self, x): 195 | self._attributes['x']=x 196 | def get_x(self): 197 | return self._attributes.get('x') 198 | 199 | def set_y(self, y): 200 | self._attributes['y']=y 201 | def get_y(self): 202 | return self._attributes.get('y') 203 | 204 | class DeltaPointAttrib: 205 | """ 206 | The DeltaPointAttrib class defines dx and dy. 207 | """ 208 | def set_dx(self, dx): 209 | self._attributes['dx']=dx 210 | def get_dx(self): 211 | return self._attributes.get('dx') 212 | 213 | def set_dy(self, dy): 214 | self._attributes['dy']=dy 215 | def get_dy(self): 216 | return self._attributes.get('dy') 217 | 218 | class PointToAttrib: 219 | """ 220 | The PointToAttrib class defines x2 and y2. 221 | """ 222 | def set_x2(self, x2): 223 | self._attributes['x2']=x2 224 | def get_x2(self): 225 | return self._attributes.get('x2') 226 | 227 | def set_y2(self, y2): 228 | self._attributes['y2']=y2 229 | def get_y2(self): 230 | return self._attributes.get('y2') 231 | 232 | class DimensionAttrib: 233 | """ 234 | The DimensionAttrib class defines height and width. 235 | """ 236 | def set_height(self, height): 237 | self._attributes['height']=height 238 | 239 | def get_height(self): 240 | return self._attributes.get('height') 241 | 242 | def set_width(self, width): 243 | self._attributes['width']=width 244 | 245 | def get_width(self): 246 | return self._attributes.get('width') 247 | 248 | class RotateAttrib: 249 | """ 250 | The RotateAttrib class defines rotation. 251 | """ 252 | def set_rotate(self, rotate): 253 | self._attributes['rotate']=rotate 254 | 255 | def get_rotate(self): 256 | return self._attributes.get('rotate') 257 | 258 | class BaseShape(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, GraphicalEventsAttrib, PaintAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib): 259 | """ 260 | Baseclass for all shapes. Do not use this class directly. There is no svg element for it 261 | """ 262 | def set_transform(self, transform): 263 | self._attributes['transform']=transform 264 | def get_transform(self): 265 | return self._attributes.get('transform') 266 | -------------------------------------------------------------------------------- /sample/tutorial.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | 4 | 5 | from pysvg.filter import * 6 | from pysvg.gradient import * 7 | from pysvg.linking import * 8 | from pysvg.script import * 9 | from pysvg.shape import * 10 | from pysvg.structure import * 11 | from pysvg.style import * 12 | from pysvg.text import * 13 | from pysvg.builders import * 14 | from pysvg.parser import parse 15 | 16 | class MyDropShadow(Filter): 17 | def __init__(self): 18 | Filter.__init__(self) 19 | self.set_x('-0.25') 20 | self.set_y('-0.25') 21 | self.set_width(3) 22 | self.set_height(3) 23 | self.set_id('MyDropShadow') 24 | self.myGauss = FeGaussianBlur() 25 | self.myGauss.set_id('DropShadowGauss') 26 | self.myGauss.set_stdDeviation(1.0) 27 | self.myGauss.set_in('SourceAlpha') 28 | self.myGauss.set_result('blur') 29 | self.addElement(self.myGauss) 30 | self.feColorMatrix = FeColorMatrix() 31 | self.feColorMatrix.set_id('DropShadowColorMatrix') 32 | self.feColorMatrix.set_result('bluralpha') 33 | self.feColorMatrix.set_type('matrix') 34 | self.feColorMatrix.set_values('1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0.500000 0 ') 35 | self.addElement(self.feColorMatrix) 36 | self.feOffset = FeOffset() 37 | self.feOffset.set_id('DropShadowOffset') 38 | self.feOffset.set_dx(1.0) 39 | self.feOffset.set_dy(1.0) 40 | self.feOffset.set_in('bluralpha') 41 | self.feOffset.set_result('offsetBlur') 42 | self.addElement(self.feOffset) 43 | self.feMerge = FeMerge() 44 | self.feMerge.set_id('DropShadowMerge') 45 | self.addElement(self.feMerge) 46 | self.firstFeMergeNode = FeMergeNode() 47 | self.feMerge.addElement(self.firstFeMergeNode) 48 | self.firstFeMergeNode.set_id('DropShadowMergeNode1') 49 | self.firstFeMergeNode.set_in('offsetBlur') 50 | self.secondFeMergeNode = FeMergeNode() 51 | self.feMerge.addElement(self.secondFeMergeNode) 52 | self.secondFeMergeNode.set_id('DropShadowMergeNode2') 53 | self.secondFeMergeNode.set_in('SourceGraphic') 54 | 55 | 56 | def Image_f(): 57 | s = Svg() 58 | i = Image(x=80, y=25, width=88, height=31) 59 | i.set_xlink_href('http://img0.gmodules.com/ig/images/googlemail.gif') 60 | s.addElement(i) 61 | i = Image(x=80, y=125, width=88, height=31) 62 | i.set_xlink_href('../sourceimages/images.jpg') 63 | s.addElement(i) 64 | print(s.getXML()) 65 | s.save('./testoutput/10_Image.svg') 66 | 67 | 68 | def LinearGradient_f(): 69 | mySVG = Svg("test") 70 | d = Defs() 71 | 72 | lg = LinearGradient() 73 | lg.set_id("orange_red") 74 | s = Stop(offset="0%") 75 | s.set_stop_color('rgb(255,255,0)') 76 | s.set_stop_opacity(1) 77 | lg.addElement(s) 78 | s = Stop(offset="100%") 79 | s.set_stop_color('rgb(255,0,0)') 80 | s.set_stop_opacity(1) 81 | lg.addElement(s) 82 | d.addElement(lg) 83 | 84 | oh = ShapeBuilder() 85 | e = oh.createEllipse(cx="200", cy="190", rx="85", ry="55", fill="url(#orange_red)") 86 | 87 | mySVG.addElement(d) 88 | mySVG.addElement(e) 89 | print(mySVG.getXML()) 90 | mySVG.save('./testoutput/8_LinearGradient.svg') 91 | 92 | def RadialGradient_f(): 93 | mySVG = Svg() 94 | d = Defs() 95 | 96 | lg = RadialGradient() 97 | lg.set_id("grey_blue") 98 | s = Stop(offset='0%') 99 | s.set_stop_color('rgb(200,200,200)') 100 | s.set_stop_opacity(1) 101 | lg.addElement(s) 102 | s = Stop(offset='100%') 103 | s.set_stop_color('rgb(0,0,255)') 104 | s.set_stop_opacity(1) 105 | lg.addElement(s) 106 | d.addElement(lg) 107 | 108 | oh = ShapeBuilder() 109 | e = oh.createEllipse(cx="230", cy="200", rx="110", ry="100", fill="url(#grey_blue)") 110 | 111 | mySVG.addElement(d) 112 | mySVG.addElement(e) 113 | print(mySVG.getXML()) 114 | mySVG.save('./testoutput/9_RadialGradient.svg') 115 | 116 | def Grouping(): 117 | s = Svg() 118 | 119 | #testing container 120 | myStyle = StyleBuilder() 121 | myStyle.setStrokeWidth(2) 122 | myStyle.setStroke("green") 123 | 124 | group = G() 125 | group.set_style(myStyle.getStyle()) 126 | group.addElement(Line(300, 300, 600, 600)) 127 | group.addElement(Circle(500, 500, 50)) 128 | s.addElement(group) 129 | 130 | group = G() 131 | group.set_style(myStyle.getStyle()) 132 | style_dict = {"stroke":"#000000", "fill":"none" , "stroke-width":"49" , "stroke-opacity":"0.027276"} 133 | p = Path(pathData="M 300 100 A 1,1 0 0 1 802,800") 134 | p.set_style(StyleBuilder(style_dict).getStyle()) 135 | p2 = Path(pathData="M 100 300 A 1,1 0 0 1 802,800") 136 | p2.set_style(StyleBuilder(style_dict).getStyle()) 137 | group.addElement(p) 138 | group.addElement(p2) 139 | s.addElement(group) 140 | print(s.getXML()) 141 | s.save('./testoutput/7_Grouping.svg') 142 | 143 | 144 | def ComplexShapes(): 145 | oh=ShapeBuilder() 146 | mySVG=Svg("test") 147 | d = Defs() 148 | d.addElement(MyDropShadow()) 149 | mySVG.addElement(d) 150 | 151 | pl=oh.createPolyline(points="50,375 150,375 150,325 250,325 250,375 350,375 350,250 450,250 450,375 \ 152 | 550,375 550,175 650,175 650,375 750,375 750,100 850,100 850,375 950,375 \ 153 | 950,25 1050,25 1050,375 1150,375 ",strokewidth=10, stroke='blue') 154 | mySVG.addElement(pl) 155 | 156 | pointsAsTuples=[(350,75),(379,161),(469,161),(397,215),(423,301),(350,250),(277,301),(303,215),(231,161),(321,161)] 157 | pg=oh.createPolygon(points=oh.convertTupleArrayToPoints(pointsAsTuples),strokewidth=10, stroke='blue', fill='red') 158 | pg.set_filter('url(#MyDropShadow)') 159 | mySVG.addElement(pg) 160 | 161 | sh=StyleBuilder() 162 | sh.setFilling('#EEE') 163 | sh.setStroke('#00F') 164 | sh.setStrokeWidth('2px') 165 | path1=Path('M 40,530 L 100,560 L 60,520 Z', style=sh.getStyle()) 166 | 167 | sh2=StyleBuilder() 168 | sh2.setFilling('#FFC') 169 | sh2.setStroke('#00F') 170 | sh2.setStrokeWidth('2px') 171 | path2=Path(style=sh2.getStyle()) 172 | path2.appendMoveToPath(190, 520, False) 173 | #as you can see we can mix strings and ints without trouble 174 | path2.appendCubicCurveToPath('+0', '+0', 30, 30, -60, 30, True) 175 | path2.appendCloseCurve() 176 | 177 | sh3=StyleBuilder() 178 | sh3.setFilling('none') 179 | sh3.setStroke('#00F') 180 | sh3.setStrokeWidth('2px') 181 | path3=Path('M 230,530', style=sh3.getStyle()) 182 | path3.appendQuadraticCurveToPath(0, 30, 30, 0) 183 | path3.appendQuadraticCurveToPath(30, -30, 30, 0) 184 | path3.appendQuadraticCurveToPath(-0, 30, 30, 0) 185 | path3.appendQuadraticCurveToPath(30, -20, 30, 0) 186 | 187 | mySVG.addElement(path1) 188 | mySVG.addElement(path2) 189 | mySVG.addElement(path3) 190 | 191 | mySVG.save('./testoutput/6_ComplexShapes.svg') 192 | 193 | 194 | def Shapes(): 195 | oh = ShapeBuilder() 196 | s = Svg("test") 197 | 198 | s.addElement(oh.createRect(0, 0, 400, 200, 12, 12, strokewidth=2, stroke='navy')) 199 | s.addElement(oh.createRect(100, 50, 200, 100, strokewidth=2, stroke='navy', fill='yellow')) 200 | s.addElement(oh.createCircle(700, 500, 50, strokewidth=5, stroke='red')) 201 | s.addElement(oh.createCircle(810, 500, 50, strokewidth=5, stroke='yellow', fill='#AAAAAA')) 202 | s.addElement(oh.createEllipse(600, 50, 50, 30, strokewidth=5, stroke='red')) 203 | s.addElement(oh.createEllipse(700, 50, 50, 30, strokewidth=5, stroke='yellow', fill='#00AABB')) 204 | s.addElement(oh.createLine(0, 0, 300, 300, strokewidth=2, stroke="black")) 205 | s.save('./testoutput/4_Shapes.svg') 206 | 207 | def Line_f(): 208 | s = Svg("test") 209 | myStyle = StyleBuilder() 210 | myStyle.setStrokeWidth(2) 211 | myStyle.setStroke('black') 212 | l = Line(0, 0, 300, 300) 213 | l.set_style(myStyle.getStyle()) 214 | s.addElement(l) 215 | #easier method with ShapeBuilder 216 | oh = ShapeBuilder() 217 | s.addElement(oh.createLine(10, 0, 300, 300, strokewidth=2, stroke="blue")) 218 | s.save('./testoutput/5_Line.svg') 219 | 220 | def TextFeatures(): 221 | s = Svg("test") 222 | myStyle = StyleBuilder() 223 | myStyle.setFontFamily(fontfamily="Verdana") 224 | myStyle.setFontSize('5em') 225 | myStyle.setFilling(fill="blue") 226 | t1 = Text("Verdana, blue, 5em", 0, 100) 227 | t1.set_style(myStyle.getStyle()) 228 | t2 = Text("pySVG simple", 0, 200) 229 | s.addElement(t1) 230 | s.addElement(t2) 231 | 232 | r = Rect(350, 250, 100, 100, id="myRect") 233 | r.set_fill("green") 234 | s.addElement(r) 235 | 236 | myStyle = StyleBuilder() 237 | myStyle.setFontFamily(fontfamily="Times") 238 | myStyle.setFontSize('2em') 239 | myStyle.setFontStyle('italic') 240 | myStyle.setFontWeight('bold') 241 | myStyle.setFilling(fill="red") 242 | myStyle.setFillOpacity('0.5') 243 | myStyle.setFillRule('evenodd') 244 | 245 | t3 = Text("Times, italic, 2em, bold, opacity=0.5, fillrule=evenodd", 0, 300) 246 | t3.set_style(myStyle.getStyle()) 247 | s.addElement(t3) 248 | 249 | myStyle = StyleBuilder() 250 | myStyle.setFontFamily(fontfamily="Times") 251 | myStyle.setFontSize('2em') 252 | myStyle.setFontStyle('italic') 253 | myStyle.setFilling(fill="red") 254 | myStyle.setFillOpacity('0.5') 255 | #myStyle.fill="blue" 256 | t4 = Text("Times, italic, 2em, non bold, opacity=0.5", 0, 400) 257 | t4.set_style(myStyle.getStyle()) 258 | s.addElement(t4) 259 | 260 | 261 | print(s.getXML()) 262 | s.save('./testoutput/3_TextFeatures.svg') 263 | 264 | def HelloWorld2(): 265 | s = Svg() 266 | myStyle = StyleBuilder() 267 | myStyle.setFontFamily(fontfamily="Verdana") 268 | myStyle.setFontSize('5em') #no need for the keywords all the time 269 | myStyle.setFilling("blue") 270 | t1 = Text("Hello World", 0, 100) 271 | t1.set_style(myStyle.getStyle()) 272 | s.addElement(t1) 273 | print(s.getXML()) 274 | s.save('./testoutput/2_HelloWorld2.svg') 275 | 276 | def HelloWorld1(): 277 | s = Svg() 278 | t = Text("Hello World", 0, 100) 279 | s.addElement(t) 280 | print(s.getXML()) 281 | s.save('./testoutput/1_HelloWorld1.svg', encoding='UTF-8') 282 | 283 | def KWARGS(): 284 | s = Svg() 285 | kw={} 286 | kw['style']= 'font-size:20em; font-family:Verdana; fill:blue; ' 287 | t1 = Text("KWARGS Text", 0, 300, **kw) 288 | s.addElement(t1) 289 | print(s.getXML()) 290 | s.save('./testoutput/KWARGS.svg') 291 | 292 | 293 | def tutorialChain(): 294 | HelloWorld1() 295 | HelloWorld2() 296 | TextFeatures() 297 | Shapes() 298 | Line_f() 299 | ComplexShapes() 300 | Grouping() 301 | LinearGradient_f() 302 | RadialGradient_f() 303 | Image_f() 304 | KWARGS() 305 | 306 | def load_tutorial(): 307 | s = parse('./testoutput/5_Line.svg') 308 | print(s.getXML()) 309 | 310 | if __name__ == '__main__': 311 | tutorialChain() 312 | load_tutorial() 313 | -------------------------------------------------------------------------------- /pysvg/builders.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from pysvg.animate import * 8 | from pysvg.filter import * 9 | from pysvg.gradient import * 10 | from pysvg.linking import * 11 | from pysvg.script import * 12 | from pysvg.shape import * 13 | from pysvg.structure import * 14 | from pysvg.style import * 15 | from pysvg.text import * 16 | 17 | class ShapeBuilder: 18 | """ 19 | Helper class that creates commonly used objects and shapes with predefined styles and 20 | few but often used parameters. Used to avoid more complex coding for common tasks. 21 | """ 22 | 23 | def createCircle(self, cx, cy, r, strokewidth=1, stroke='black', fill='none'): 24 | """ 25 | Creates a circle 26 | @type cx: string or int 27 | @param cx: starting x-coordinate 28 | @type cy: string or int 29 | @param cy: starting y-coordinate 30 | @type r: string or int 31 | @param r: radius 32 | @type strokewidth: string or int 33 | @param strokewidth: width of the pen used to draw 34 | @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF") 35 | @param stroke: color with which to draw the outer limits 36 | @type fill: string (either css constants like "black" or numerical values like "#FFFFFF") 37 | @param fill: color with which to fill the element (default: no filling) 38 | @return: a circle object 39 | """ 40 | style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke} 41 | myStyle = StyleBuilder(style_dict) 42 | c = Circle(cx, cy, r) 43 | c.set_style(myStyle.getStyle()) 44 | return c 45 | 46 | def createEllipse(self, cx, cy, rx, ry, strokewidth=1, stroke='black', fill='none'): 47 | """ 48 | Creates an ellipse 49 | @type cx: string or int 50 | @param cx: starting x-coordinate 51 | @type cy: string or int 52 | @param cy: starting y-coordinate 53 | @type rx: string or int 54 | @param rx: radius in x direction 55 | @type ry: string or int 56 | @param ry: radius in y direction 57 | @type strokewidth: string or int 58 | @param strokewidth: width of the pen used to draw 59 | @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF") 60 | @param stroke: color with which to draw the outer limits 61 | @type fill: string (either css constants like "black" or numerical values like "#FFFFFF") 62 | @param fill: color with which to fill the element (default: no filling) 63 | @return: an ellipse object 64 | """ 65 | style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke} 66 | myStyle = StyleBuilder(style_dict) 67 | e = Ellipse(cx, cy, rx, ry) 68 | e.set_style(myStyle.getStyle()) 69 | return e 70 | 71 | def createRect(self, x, y, width, height, rx=None, ry=None, strokewidth=1, stroke='black', fill='none'): 72 | """ 73 | Creates a Rectangle 74 | @type x: string or int 75 | @param x: starting x-coordinate 76 | @type y: string or int 77 | @param y: starting y-coordinate 78 | @type width: string or int 79 | @param width: width of the rectangle 80 | @type height: string or int 81 | @param height: height of the rectangle 82 | @type rx: string or int 83 | @param rx: For rounded rectangles, the x-axis radius of the ellipse used to round off the corners of the rectangle. 84 | @type ry: string or int 85 | @param ry: For rounded rectangles, the y-axis radius of the ellipse used to round off the corners of the rectangle. 86 | @type strokewidth: string or int 87 | @param strokewidth: width of the pen used to draw 88 | @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF") 89 | @param stroke: color with which to draw the outer limits 90 | @type fill: string (either css constants like "black" or numerical values like "#FFFFFF") 91 | @param fill: color with which to fill the element (default: no filling) 92 | @return: a rect object 93 | """ 94 | style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke} 95 | myStyle = StyleBuilder(style_dict) 96 | r = Rect(x, y, width, height, rx, ry) 97 | r.set_style(myStyle.getStyle()) 98 | return r 99 | 100 | def createPolygon(self, points, strokewidth=1, stroke='black', fill='none'): 101 | """ 102 | Creates a Polygon 103 | @type points: string in the form "x1,y1 x2,y2 x3,y3" 104 | @param points: all points relevant to the polygon 105 | @type strokewidth: string or int 106 | @param strokewidth: width of the pen used to draw 107 | @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF") 108 | @param stroke: color with which to draw the outer limits 109 | @type fill: string (either css constants like "black" or numerical values like "#FFFFFF") 110 | @param fill: color with which to fill the element (default: no filling) 111 | @return: a polygon object 112 | """ 113 | style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke} 114 | myStyle = StyleBuilder(style_dict) 115 | p = Polygon(points=points) 116 | p.set_style(myStyle.getStyle()) 117 | return p 118 | 119 | def createPolyline(self, points, strokewidth=1, stroke='black'): 120 | """ 121 | Creates a Polyline 122 | @type points: string in the form "x1,y1 x2,y2 x3,y3" 123 | @param points: all points relevant to the polygon 124 | @type strokewidth: string or int 125 | @param strokewidth: width of the pen used to draw 126 | @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF") 127 | @param stroke: color with which to draw the outer limits 128 | @return: a polyline object 129 | """ 130 | style_dict = {'fill':'none', 'stroke-width':strokewidth, 'stroke':stroke} 131 | myStyle = StyleBuilder(style_dict) 132 | p = Polyline(points=points) 133 | p.set_style(myStyle.getStyle()) 134 | return p 135 | 136 | 137 | def createLine(self, x1, y1, x2, y2, strokewidth=1, stroke="black"): 138 | """ 139 | Creates a line 140 | @type x1: string or int 141 | @param x1: starting x-coordinate 142 | @type y1: string or int 143 | @param y1: starting y-coordinate 144 | @type x2: string or int 145 | @param x2: ending x-coordinate 146 | @type y2: string or int 147 | @param y2: ending y-coordinate 148 | @type strokewidth: string or int 149 | @param strokewidth: width of the pen used to draw 150 | @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF") 151 | @param stroke: color with which to draw the outer limits 152 | @return: a line object 153 | """ 154 | style_dict = {'stroke-width':strokewidth, 'stroke':stroke} 155 | myStyle = StyleBuilder(style_dict) 156 | l = Line(x1, y1, x2, y2) 157 | l.set_style(myStyle.getStyle()) 158 | return l 159 | 160 | def convertTupleArrayToPoints(self, arrayOfPointTuples): 161 | """Method used to convert an array of tuples (x,y) into a string 162 | suitable for createPolygon or createPolyline 163 | @type arrayOfPointTuples: An array containing tuples eg.[(x1,y1),(x2,y2] 164 | @param arrayOfPointTuples: All points needed to create the shape 165 | @return a string in the form "x1,y1 x2,y2 x3,y3" 166 | """ 167 | points = "" 168 | for tuple in arrayOfPointTuples: 169 | points += str(tuple[0]) + "," + str(tuple[1]) + " " 170 | return points 171 | 172 | 173 | 174 | ###################################################################### 175 | # Style Builder. Utility class to create styles for your shapes etc. 176 | ###################################################################### 177 | class StyleBuilder: 178 | """ 179 | Class to create a style string for those not familiar with svg attribute names. 180 | How to use it: 181 | 1) create an instance of StyleBuilder (builder=....) 182 | 2) set the attributes you want to have 183 | 3) create the shape (element) you want 184 | 4) call set_style on the element with "builder.getStyle()" as parameter 185 | """ 186 | def __init__(self, aStyle_dict=None): 187 | if aStyle_dict == None: 188 | self.style_dict = {} 189 | else: 190 | self.style_dict = aStyle_dict 191 | 192 | 193 | # tested below 194 | def setFontFamily(self, fontfamily): 195 | self.style_dict["font-family"] = fontfamily 196 | 197 | def setFontSize(self, fontsize): 198 | self.style_dict["font-size"] = fontsize 199 | 200 | def setFontStyle(self, fontstyle): 201 | self.style_dict["font-style"] = fontstyle 202 | 203 | def setFontWeight(self, fontweight): 204 | self.style_dict["font-weight"] = fontweight 205 | 206 | #tested 207 | def setFilling(self, fill): 208 | self.style_dict["fill"] = fill 209 | 210 | def setFillOpacity(self, fillopacity): 211 | self.style_dict["fill-opacity"] = fillopacity 212 | 213 | def setFillRule(self, fillrule): 214 | self.style_dict["fill-rule"] = fillrule 215 | 216 | def setStrokeWidth(self, strokewidth): 217 | self.style_dict["stroke-width"] = strokewidth 218 | 219 | def setStroke(self, stroke): 220 | self.style_dict["stroke"] = stroke 221 | 222 | #untested below 223 | def setStrokeDashArray(self, strokedasharray): 224 | self.style_dict["stroke-dasharray"] = strokedasharray 225 | def setStrokeDashOffset(self, strokedashoffset): 226 | self.style_dict["stroke-dashoffset"] = strokedashoffset 227 | def setStrokeLineCap(self, strikelinecap): 228 | self.style_dict["stroke-linecap"] = strikelinecap 229 | def setStrokeLineJoin(self, strokelinejoin): 230 | self.style_dict["stroke-linejoin"] = strokelinejoin 231 | def setStrokeMiterLimit(self, strokemiterlimit): 232 | self.style_dict["stroke-miterlimit"] = strokemiterlimit 233 | def setStrokeOpacity(self, strokeopacity): 234 | self.style_dict["stroke-opacity"] = strokeopacity 235 | 236 | 237 | #is used to provide a potential indirect value (currentColor) for the 'fill', 'stroke', 'stop-color' properties. 238 | def setCurrentColor(self, color): 239 | self.style_dict["color"] = color 240 | 241 | # Gradient properties: 242 | def setStopColor(self, stopcolor): 243 | self.style_dict["stop-color"] = stopcolor 244 | 245 | def setStopOpacity(self, stopopacity): 246 | self.style_dict["stop-opacity"] = stopopacity 247 | 248 | #rendering properties 249 | def setColorRendering(self, colorrendering): 250 | self.style_dict["color-rendering"] = colorrendering 251 | 252 | def setImageRendering(self, imagerendering): 253 | self.style_dict["image-rendering"] = imagerendering 254 | 255 | def setShapeRendering(self, shaperendering): 256 | self.style_dict["shape-rendering"] = shaperendering 257 | 258 | def setTextRendering(self, textrendering): 259 | self.style_dict["text-rendering"] = textrendering 260 | 261 | def setSolidColor(self, solidcolor): 262 | self.style_dict["solid-color"] = solidcolor 263 | 264 | def setSolidOpacity(self, solidopacity): 265 | self.style_dict["solid-opacity"] = solidopacity 266 | 267 | #Viewport properties 268 | def setVectorEffect(self, vectoreffect): 269 | self.style_dict["vector-effect"] = vectoreffect 270 | 271 | def setViewPortFill(self, viewportfill): 272 | self.style_dict["viewport-fill"] = viewportfill 273 | 274 | def setViewPortOpacity(self, viewportfillopacity): 275 | self.style_dict["viewport-fill_opacity"] = viewportfillopacity 276 | 277 | # Text properties 278 | def setDisplayAlign(self, displayalign): 279 | self.style_dict["display-align"] = displayalign 280 | 281 | def setLineIncrement(self, lineincrement): 282 | self.style_dict["line-increment"] = lineincrement 283 | 284 | def setTextAnchor(self, textanchor): 285 | self.style_dict["text-anchor"] = textanchor 286 | 287 | #def getStyleDict(self): 288 | # return self.style_dict 289 | 290 | 291 | def getStyle(self): 292 | string = ''#style="' 293 | for key, value in list(self.style_dict.items()): 294 | if value != None and value != '': 295 | string += str(key) + ':' + str(value) + '; ' 296 | return string 297 | 298 | ###################################################################### 299 | # Transform Builder. Utility class to create transformations for your shapes etc. 300 | ###################################################################### 301 | class TransformBuilder: 302 | """ 303 | Class to create a transform string for those not familiar with svg attribute names. 304 | How to use it: 305 | 1) create an instance of TransformBuilder (builder=....) 306 | 2) set the attributes you want to have 307 | 3) create the shape (element) you want 308 | 4) call set_transform on the element with "builder.getTransform()" as parameter 309 | """ 310 | def __init__(self): 311 | self.transform_dict = {} 312 | 313 | #def setMatrix(self, matrix): 314 | # self.transform_dict["matrix"] = 'matrix(%s)' % matrix 315 | 316 | def setMatrix(self, a, b, c, d, e, f): 317 | self.transform_dict["matrix"] = 'matrix(%s %s %s %s %s %s)' % (a, b, c, d, e, f) 318 | 319 | def setRotation(self, rotate): 320 | self.transform_dict["rotate"] = 'rotate(%s)' % rotate 321 | 322 | #def setRotation(self, rotation, cx=None, cy=None): 323 | # if cx != None and cy != None: 324 | # self.transform_dict["rotate"] = 'rotate(%s %s %s)' % (rotation, cx, cy) 325 | # else: 326 | # self.transform_dict["rotate"] = 'rotate(%s)' % (rotation) 327 | 328 | def setTranslation(self, translate): 329 | self.transform_dict["translate"] = 'translate(%s)' % (translate) 330 | 331 | #def setTranslation(self, x, y=0): 332 | # self.transform_dict["translate"] = 'translate(%s %s)' % (x, y) 333 | 334 | #def setScaling(self, scale): 335 | # self.transform_dict["scale"] = 'scale(%s)' % (scale) 336 | 337 | def setScaling(self, x=None, y=None): 338 | if x == None and y != None: 339 | x = y 340 | elif x != None and y == None: 341 | y = x 342 | self.transform_dict["scale"] = 'scale(%s %s)' % (x, y) 343 | 344 | def setSkewY(self, skewY): 345 | self.transform_dict["skewY"] = 'skewY(%s)' % (skewY) 346 | 347 | def setSkewX(self, skewX): 348 | self.transform_dict["skewX"] = 'skewX(%s)' % (skewX) 349 | 350 | #def getTransformDict(self): 351 | # return self.transform_dict 352 | 353 | def getTransform(self): 354 | string = ''#style="' 355 | for key, value in list(self.transform_dict.items()): 356 | if value != None and value != '': 357 | #string+=str(key)+':'+str(value)+'; ' 358 | string += str(value) + ' ' 359 | return string 360 | -------------------------------------------------------------------------------- /pysvg/shape.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from .attributes import * 8 | from .core import BaseElement, BaseShape, PointAttrib, DimensionAttrib, PointToAttrib 9 | 10 | 11 | class Rect(BaseShape, PointAttrib, DimensionAttrib): 12 | """ 13 | Class representing the rect element of an svg doc. 14 | """ 15 | def __init__(self, x=None, y=None, width=None, height=None, rx=None, ry=None, **kwargs): 16 | BaseElement.__init__(self,'rect') 17 | self.set_x(x) 18 | self.set_y(y) 19 | self.set_height(height) 20 | self.set_width(width) 21 | self.set_rx(rx) 22 | self.set_ry(ry) 23 | self.setKWARGS(**kwargs) 24 | 25 | def set_rx(self, rx): 26 | self._attributes['rx']=rx 27 | def get_rx(self): 28 | return self._attributes.get('rx') 29 | 30 | def set_ry(self, ry): 31 | self._attributes['ry']=ry 32 | def get_ry(self): 33 | return self._attributes.get('ry') 34 | 35 | #extra methods. Methods do rely on number values in the attributes. You might get an exception else! 36 | def getEdgePoints(self): 37 | """ 38 | Returns a list with the coordinates of the points at the edge of the rectangle as tuples. 39 | e.g.[(x1,y1),(x2,y2)] 40 | The sorting is counterclockwise starting with the lower left corner. 41 | Coordinates must be numbers or an exception will be thrown. 42 | """ 43 | result = [(float(self.get_x()),float(self.get_y()))] 44 | result.append((float(self.get_x())+float(self.get_width()),float(self.get_y()))) 45 | result.append((float(self.get_x())+float(self.get_width()),float(self.get_y())+float(self.get_height()))) 46 | result.append((float(self.get_x()),float(self.get_y())+float(self.get_height()))) 47 | return result 48 | 49 | def getInnerEdgePoints(self): 50 | """ 51 | Returns a list with the coordinates of the points at the inner edge of a rounded rectangle as tuples. 52 | e.g.[(x1,y1),(x2,y2)] 53 | The sorting is counterclockwise starting with the lower left corner. 54 | Coordinates must be numbers or an exception will be thrown. 55 | """ 56 | result = [] 57 | result.append((float(self.get_x()) + float(self.get_rx()), float(self.get_y()) + float(self.get_ry()))) 58 | result.append((float(self.get_x()) + float(self.get_width()) - float(self.get_rx()), float(self.get_y()) + float(self.get_ry()))) 59 | result.append((float(self.get_x()) + float(self.get_width()) - float(self.get_rx()), float(self.get_y()) + float(self.get_height()) - float(self.get_ry()))) 60 | result.append((float(self.get_x()) + float(self.get_rx()), float(self.get_y()) + float(self.get_height()) - float(self.get_ry()))) 61 | return result 62 | 63 | def getBottomLeft(self): 64 | """ 65 | Retrieves a tuple with the x,y coordinates of the lower left point of the rect. 66 | Requires the coordinates, width, height to be numbers 67 | """ 68 | return (float(self.get_x()), float(self.get_y())) 69 | 70 | def getBottomRight(self): 71 | """ 72 | Retrieves a tuple with the x,y coordinates of the lower right point of the rect. 73 | Requires the coordinates, width, height to be numbers 74 | """ 75 | return (float(self.get_x()) + float(self.get_width()), float(self.get_y())) 76 | 77 | def getTopLeft(self): 78 | """ 79 | Retrieves a tuple with the x,y coordinates of the upper left point of the rect. 80 | Requires the coordinates, width, height to be numbers 81 | """ 82 | return (float(self.get_x()), float(self.get_y())+ float(self.get_height())) 83 | 84 | def getTopRight(self): 85 | """ 86 | Retrieves a tuple with the x,y coordinates of the upper right point of the rect. 87 | Requires the coordinates, width, height to be numbers 88 | """ 89 | return (float(self.get_x()) + float(self.get_width()), float(self.get_y()) + float(self.get_height())) 90 | 91 | def moveToPoint(self, xxx_todo_changeme): 92 | """ 93 | Moves the rect to the point x,y 94 | """ 95 | (x,y) = xxx_todo_changeme 96 | self.set_x(float(self.get_x()) + float(x)) 97 | self.set_y(float(self.get_y()) + float(y)) 98 | 99 | 100 | class Circle(BaseShape): 101 | """ 102 | Class representing the circle element of an svg doc. 103 | """ 104 | def __init__(self, cx=None,cy=None,r=None, **kwargs): 105 | BaseElement.__init__(self,'circle') 106 | self.set_cx(cx) 107 | self.set_cy(cy) 108 | self.set_r(r) 109 | self.setKWARGS(**kwargs) 110 | 111 | def set_cx(self, cx): 112 | self._attributes['cx']=cx 113 | def get_cx(self): 114 | return self._attributes.get('cx') 115 | 116 | def set_cy(self, cy): 117 | self._attributes['cy']=cy 118 | def get_cy(self): 119 | return self._attributes.get('cy') 120 | 121 | def set_r(self, r): 122 | self._attributes['r']=r 123 | def get_r(self): 124 | return self._attributes.get('r') 125 | 126 | #extra methods. Methods do rely on number values in the attributes. You might get an exception else! 127 | def getDiameter(self): 128 | """ 129 | Retrieves the diameter of the circle. Requires the radius to be a number 130 | """ 131 | return 2 * float(self.get_r()) 132 | 133 | def getWidth(self): 134 | """ 135 | Retrieves the width of the circle. Requires the radius to be a number 136 | """ 137 | return self.getDiameter() 138 | 139 | def getHeight(self): 140 | """ 141 | Retrieves the height of the circle. Requires the radius to be a number 142 | """ 143 | return self.getDiameter() 144 | 145 | def getBottomLeft(self): 146 | """ 147 | Retrieves a tuple with the x,y coordinates of the lower left point of the circle. 148 | Requires the radius and the coordinates to be numbers 149 | """ 150 | return (float(self.get_cx()) - float(self.get_r()), float(self.get_cy()) - float(self.get_r())) 151 | 152 | def getBottomRight(self): 153 | """ 154 | Retrieves a tuple with the x,y coordinates of the lower right point of the circle. 155 | Requires the radius and the coordinates to be numbers 156 | """ 157 | return (float(self.get_cx()) + float(self.get_r()), float(self.get_cy()) - float(self.get_r())) 158 | 159 | def getTopLeft(self): 160 | """ 161 | Retrieves a tuple with the x,y coordinates of the upper left point of the circle. 162 | Requires the radius and the coordinates to be numbers 163 | """ 164 | return (float(self.get_cx()) - float(self.get_r()), float(self.get_cy()) + float(self.get_r())) 165 | 166 | def getTopRight(self): 167 | """ 168 | Retrieves a tuple with the x,y coordinates of the upper right point of the circle. 169 | Requires the radius and the coordinates to be numbers 170 | """ 171 | return (float(self.get_cx()) + float(self.get_r()), float(self.get_cy()) + float(self.get_r())) 172 | 173 | def moveToPoint(self, xxx_todo_changeme1): 174 | """ 175 | Moves the circle to the point x,y 176 | """ 177 | (x,y) = xxx_todo_changeme1 178 | self.set_cx(float(self.get_cx()) + float(x)) 179 | self.set_cy(float(self.get_cy()) + float(y)) 180 | 181 | class Ellipse(BaseShape): 182 | """ 183 | Class representing the ellipse element of an svg doc. 184 | """ 185 | def __init__(self, cx=None,cy=None,rx=None,ry=None, **kwargs): 186 | BaseElement.__init__(self,'ellipse') 187 | self.set_cx(cx) 188 | self.set_cy(cy) 189 | self.set_rx(rx) 190 | self.set_ry(ry) 191 | self.setKWARGS(**kwargs) 192 | 193 | def set_cx(self, cx): 194 | self._attributes['cx']=cx 195 | def get_cx(self): 196 | return self._attributes.get('cx') 197 | 198 | def set_cy(self, cy): 199 | self._attributes['cy']=cy 200 | def get_cy(self): 201 | return self._attributes.get('cy') 202 | 203 | def set_rx(self, rx): 204 | self._attributes['rx']=rx 205 | def get_rx(self): 206 | return self._attributes.get('rx') 207 | 208 | def set_ry(self, ry): 209 | self._attributes['ry']=ry 210 | def get_ry(self): 211 | return self._attributes.get('ry') 212 | 213 | #extra methods. Methods do rely on number values in the attributes. You might get an exception else! 214 | def getWidth(self): 215 | return abs(2 * float(self.get_rx())) 216 | 217 | def getHeight(self): 218 | return abs(2 * float(self.get_ry())) 219 | 220 | def getBottomLeft(self): 221 | """ 222 | Retrieves a tuple with the x,y coordinates of the lower left point of the ellipse. 223 | Requires the radius and the coordinates to be numbers 224 | """ 225 | return (float(self.get_cx()) - float(self.get_rx()), float(self.get_cy()) - float(self.get_ry())) 226 | 227 | def getBottomRight(self): 228 | """ 229 | Retrieves a tuple with the x,y coordinates of the lower right point of the ellipse. 230 | Requires the radius and the coordinates to be numbers 231 | """ 232 | return (float(self.get_cx()) + float(self.get_rx()), float(self.get_cy()) - float(self.get_ry())) 233 | 234 | def getTopLeft(self): 235 | """ 236 | Retrieves a tuple with the x,y coordinates of the upper left point of the ellipse. 237 | Requires the radius and the coordinates to be numbers 238 | """ 239 | return (float(self.get_cx()) - float(self.get_rx()), float(self.get_cy()) + float(self.get_ry())) 240 | 241 | def getTopRight(self): 242 | """ 243 | Retrieves a tuple with the x,y coordinates of the upper right point of the ellipse. 244 | Requires the radius and the coordinates to be numbers 245 | """ 246 | return (float(self.get_cx()) + float(self.get_rx()), float(self.get_cy()) + float(self.get_ry())) 247 | 248 | class Line(BaseShape, PointToAttrib): 249 | """ 250 | Class representing the line element of an svg doc. 251 | Note that this element is NOT painted VISIBLY by default UNLESS you provide 252 | a style including STROKE and STROKE-WIDTH 253 | """ 254 | def __init__(self, X1=None, Y1=None, X2=None, Y2=None, **kwargs): 255 | """ 256 | Creates a line 257 | @type X1: string or int 258 | @param X1: starting x-coordinate 259 | @type Y1: string or int 260 | @param Y1: starting y-coordinate 261 | @type X2: string or int 262 | @param X2: ending x-coordinate 263 | @type Y2: string or int 264 | @param Y2: ending y-coordinate 265 | """ 266 | BaseElement.__init__(self,'line') 267 | self.set_x1(X1) 268 | self.set_y1(Y1) 269 | self.set_x2(X2) 270 | self.set_y2(Y2) 271 | self.setKWARGS(**kwargs) 272 | 273 | def set_x1(self, x1): 274 | self._attributes['x1']=x1 275 | def get_x1(self): 276 | return self._attributes.get('x1') 277 | 278 | def set_y1(self, y1): 279 | self._attributes['y1']=y1 280 | def get_y1(self): 281 | return self._attributes.get('y1') 282 | 283 | def set_x2(self, x2): 284 | self._attributes['x2']=x2 285 | def get_x2(self): 286 | return self._attributes.get('x2') 287 | 288 | def set_y2(self, y2): 289 | self._attributes['y2']=y2 290 | def get_y2(self): 291 | return self._attributes.get('y2') 292 | 293 | #extra methods. Methods do rely on number values in the attributes. You might get an exception else! 294 | def getWidth(self): 295 | """ 296 | Retrieves the width of the line. This is always a positive number. 297 | Coordinates must be numbers. 298 | """ 299 | return abs(float(self.get_x1()) - float(self.get_x2())) 300 | 301 | def getHeight(self): 302 | """ 303 | Retrieves the height of the line. This is always a positive number. 304 | Coordinates must be numbers. 305 | """ 306 | return abs(float(self.get_y1()) - float(self.get_y2())) 307 | 308 | def getBottomLeft(self): 309 | """ 310 | Retrieves the the bottom left coordinate of the line as tuple. 311 | Coordinates must be numbers. 312 | """ 313 | x1 = float(self.get_x1()) 314 | x2 = float(self.get_x2()) 315 | y1 = float(self.get_y1()) 316 | y2 = float(self.get_y2()) 317 | if x1 < x2: 318 | if y1 < y2: 319 | return (x1, y1) 320 | else: 321 | return (x1, y2) 322 | else: 323 | if y1 < y2: 324 | return (x2, y1) 325 | else: 326 | return (x2, y2) 327 | 328 | def getBottomRight(self): 329 | """ 330 | Retrieves the the bottom right coordinate of the line as tuple. 331 | Coordinates must be numbers. 332 | """ 333 | x1 = float(self.get_x1()) 334 | x2 = float(self.get_x2()) 335 | y1 = float(self.get_y1()) 336 | y2 = float(self.get_y2()) 337 | if x1 < x2: 338 | if y1 < y2: 339 | return (x2, y1) 340 | else: 341 | return (x2, y2) 342 | else: 343 | if y1 < y2: 344 | return (x1, y1) 345 | else: 346 | return (x1, y2) 347 | 348 | def getTopRight(self): 349 | """ 350 | Retrieves the the top right coordinate of the line as tuple. 351 | Coordinates must be numbers. 352 | """ 353 | x1 = float(self.get_x1()) 354 | x2 = float(self.get_x2()) 355 | y1 = float(self.get_y1()) 356 | y2 = float(self.get_y2()) 357 | if x1 < x2: 358 | if y1 < y2: 359 | return (x2, y2) 360 | else: 361 | return (x2, y1) 362 | else: 363 | if y1 < y2: 364 | return (x1, y2) 365 | else: 366 | return (x1, y1) 367 | 368 | def getTopLeft(self): 369 | """ 370 | Retrieves the the top left coordinate of the line as tuple. 371 | Coordinates must be numbers. 372 | """ 373 | x1 = float(self.get_x1()) 374 | x2 = float(self.get_x2()) 375 | y1 = float(self.get_y1()) 376 | y2 = float(self.get_y2()) 377 | if x1 < x2: 378 | if y1 < y2: 379 | return (x1, y2) 380 | else: 381 | return (x1, y1) 382 | else: 383 | if y1 < y2: 384 | return (x2, y2) 385 | else: 386 | return (x2, y1) 387 | 388 | def moveToPoint(self, xxx_todo_changeme2): 389 | """ 390 | Moves the line to the point x,y 391 | """ 392 | (x,y) = xxx_todo_changeme2 393 | self.set_x1(float(self.get_x1()) + float(x)) 394 | self.set_x2(float(self.get_x2()) + float(x)) 395 | self.set_y1(float(self.get_y1()) + float(y)) 396 | self.set_y2(float(self.get_y2()) + float(y)) 397 | 398 | class Path(BaseShape, ExternalAttrib, MarkerAttrib): 399 | """ 400 | Class representing the path element of an svg doc. 401 | """ 402 | def __init__(self, pathData="",pathLength=None, style=None, focusable=None, **kwargs): 403 | BaseElement.__init__(self,'path') 404 | if pathData!='' and not pathData.endswith(' '): 405 | pathData+=' ' 406 | self.set_d(pathData) 407 | if style!=None: 408 | self.set_style(style) 409 | self.setKWARGS(**kwargs) 410 | 411 | def set_d(self, d): 412 | self._attributes['d']=d 413 | def get_d(self): 414 | return self._attributes.get('d') 415 | 416 | def set_pathLength(self, pathLength): 417 | self._attributes['pathLength']=pathLength 418 | def get_pathLength(self): 419 | return self._attributes.get('pathLength') 420 | 421 | def __append__(self,command, params, relative=True): 422 | d = self.get_d() 423 | if relative==True: 424 | d+=command.lower() 425 | else: 426 | d+=command.upper() 427 | for param in params: 428 | d+=' %s ' %(param) 429 | self.set_d(d) 430 | 431 | def appendLineToPath(self,endx,endy, relative=True): 432 | self.__append__('l',[endx,endy], relative) 433 | 434 | def appendHorizontalLineToPath(self,endx, relative=True): 435 | self.__append__('h',[endx], relative) 436 | 437 | def appendVerticalLineToPath(self,endy, relative=True): 438 | self.__append__('v',[endy], relative) 439 | 440 | def appendMoveToPath(self,endx,endy, relative=True): 441 | self.__append__('m',[endx,endy], relative) 442 | 443 | def appendCloseCurve(self): 444 | d = self.get_d() 445 | d+="z" 446 | self.set_d(d) 447 | 448 | def appendCubicCurveToPath(self, controlstartx, controlstarty, controlendx, controlendy, endx,endy,relative=True): 449 | self.__append__('c',[controlstartx, controlstarty, controlendx, controlendy, endx,endy], relative) 450 | 451 | def appendCubicShorthandCurveToPath(self, controlendx, controlendy, endx,endy,relative=True): 452 | self.__append__('s',[controlendx, controlendy, endx,endy], relative) 453 | 454 | def appendQuadraticCurveToPath(self, controlx, controly, endx,endy,relative=True): 455 | self.__append__('q',[controlx, controly, endx,endy], relative) 456 | 457 | def appendQuadraticShorthandCurveToPath(self, endx,endy,relative=True): 458 | self.__append__('t',[endx,endy], relative) 459 | 460 | def appendArcToPath(self,rx,ry,x,y,x_axis_rotation=0,large_arc_flag=0,sweep_flag=1 ,relative=True): 461 | self.__append__('a',[rx,ry,x_axis_rotation,large_arc_flag,sweep_flag,x,y], relative) 462 | 463 | class Polyline(BaseShape): 464 | """ 465 | Class representing the polyline element of an svg doc. 466 | """ 467 | def __init__(self, points=None, **kwargs): 468 | BaseElement.__init__(self,'polyline') 469 | self.set_points(points) 470 | self.setKWARGS(**kwargs) 471 | 472 | def set_points(self, points): 473 | self._attributes['points']=points 474 | def get_points(self): 475 | return self._attributes.get('points') 476 | 477 | class Polygon(Polyline): 478 | """ 479 | Class representing the polygon element of an svg doc. 480 | """ 481 | def __init__(self, points=None, **kwargs): 482 | BaseElement.__init__(self,'polygon') 483 | self.set_points(points) 484 | self.setKWARGS(**kwargs) -------------------------------------------------------------------------------- /pysvg/filter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | from .attributes import * 8 | from .core import BaseElement, DeltaPointAttrib, PointAttrib, DimensionAttrib 9 | 10 | class Filter(BaseElement, CoreAttrib, XLinkAttrib, ExternalAttrib, StyleAttrib, PresentationAttributes_All, PointAttrib, DimensionAttrib): 11 | """ 12 | Class representing the filter element of an svg doc. 13 | """ 14 | def __init__(self, x=None, y=None, width=None, height=None, filterRes=None, filterUnits=None, primitiveUnits=None, **kwargs): 15 | BaseElement.__init__(self, 'filter') 16 | self.set_x(x) 17 | self.set_y(y) 18 | self.set_height(height) 19 | self.set_width(width) 20 | self.set_filterRes(filterRes) 21 | self.set_filterUnits(filterUnits) 22 | self.set_primitiveUnits(primitiveUnits) 23 | self.setKWARGS(**kwargs) 24 | 25 | def set_filterUnits(self, filterUnits): 26 | self._attributes['filterUnits'] = filterUnits 27 | def get_filterUnits(self): 28 | return self._attributes.get('filterUnits') 29 | 30 | def set_primitiveUnits(self, primitiveUnits): 31 | self._attributes['primitiveUnits'] = primitiveUnits 32 | def get_primitiveUnits(self): 33 | return self._attributes.get('primitiveUnits') 34 | 35 | def set_filterRes(self, filterRes): 36 | self._attributes['filterRes'] = filterRes 37 | def get_filterRes(self): 38 | return self._attributes.get('filterRes') 39 | 40 | class FeComponentTransfer(BaseElement, CoreAttrib, FilterColorAttrib, FilterPrimitiveWithInAttrib): 41 | """ 42 | Class representing the feComponentTransfer element of an svg doc. 43 | """ 44 | def __init__(self, **kwargs): 45 | BaseElement.__init__(self, 'feComponentTransfer') 46 | self.setKWARGS(**kwargs) 47 | 48 | 49 | class FeBlend(FeComponentTransfer): 50 | """ 51 | Class representing the feBlend element of an svg doc. 52 | """ 53 | def __init__(self, in2=None, mode=None, **kwargs): 54 | BaseElement.__init__(self, 'feBlend') 55 | self.set_in2(in2) 56 | self.set_mode(mode) 57 | self.setKWARGS(**kwargs) 58 | 59 | def set_in2(self, in2): 60 | self._attributes['in2'] = in2 61 | def get_in2(self): 62 | return self._attributes.get('in2') 63 | 64 | def set_mode(self, mode): 65 | self._attributes['mode'] = mode 66 | def get_mode(self): 67 | return self._attributes.get('mode') 68 | 69 | class FeColorMatrix(FeComponentTransfer): 70 | """ 71 | Class representing the feColorMatrix element of an svg doc. 72 | """ 73 | def __init__(self, type=None, values=None, **kwargs): 74 | BaseElement.__init__(self, 'feColorMatrix') 75 | self.set_type(type) 76 | self.set_values(values) 77 | self.setKWARGS(**kwargs) 78 | 79 | def set_type(self, type): 80 | self._attributes['type'] = type 81 | def get_type(self): 82 | return self._attributes.get('type') 83 | 84 | def set_values(self, values): 85 | self._attributes['values'] = values 86 | def get_values(self): 87 | return self._attributes.get('values') 88 | 89 | class FeComposite(FeComponentTransfer): 90 | """ 91 | Class representing the feComposite element of an svg doc. 92 | """ 93 | def __init__(self, in2=None, operator=None, k1=None, k2=None, k3=None, k4=None, **kwargs): 94 | BaseElement.__init__(self, 'feComposite') 95 | self.set_in2(in2) 96 | self.set_k1(k1) 97 | self.set_k2(k2) 98 | self.set_k3(k3) 99 | self.set_k4(k4) 100 | self.set_operator(operator) 101 | self.setKWARGS(**kwargs) 102 | 103 | def set_in2(self, in2): 104 | self._attributes['in2'] = in2 105 | def get_in2(self): 106 | return self._attributes.get('in2') 107 | 108 | def set_operator(self, operator): 109 | self._attributes['operator'] = operator 110 | def get_operator(self): 111 | return self._attributes.get('operator') 112 | 113 | def set_k1(self, k1): 114 | self._attributes['k1'] = k1 115 | def get_k1(self): 116 | return self._attributes.get('k1') 117 | 118 | def set_k2(self, k2): 119 | self._attributes['k2'] = k2 120 | def get_k2(self): 121 | return self._attributes.get('k2') 122 | 123 | def set_k3(self, k3): 124 | self._attributes['k3'] = k3 125 | def get_k3(self): 126 | return self._attributes.get('k3') 127 | 128 | def set_k4(self, k4): 129 | self._attributes['k4'] = k4 130 | def get_k4(self): 131 | return self._attributes.get('k4') 132 | 133 | class FeConvolveMatrix(FeComponentTransfer): 134 | """ 135 | Class representing the feConvolveMatrix element of an svg doc. 136 | """ 137 | def __init__(self, order=None, kernelMatrix=None, divisor=None, bias=None, targetX=None, targetY=None, edgeMode=None, kernelUnitLength=None, preserveAlpha=None, **kwargs): 138 | BaseElement.__init__(self, 'feConvolveMatrix') 139 | self.set_order(order) 140 | self.set_kernelMatrix(kernelMatrix) 141 | self.set_divisor(divisor) 142 | self.set_bias(bias) 143 | self.set_targetX(targetX) 144 | self.set_targetY(targetY) 145 | self.set_edgeMode(edgeMode) 146 | self.set_kernelUnitLength(kernelUnitLength) 147 | self.set_preserveAlpha(preserveAlpha) 148 | self.setKWARGS(**kwargs) 149 | 150 | def set_order(self, order): 151 | self._attributes['order'] = order 152 | def get_order(self): 153 | return self._attributes.get('order') 154 | 155 | def set_kernelMatrix(self, kernelMatrix): 156 | self._attributes['kernelMatrix'] = kernelMatrix 157 | def get_kernelMatrix(self): 158 | return self._attributes.get('kernelMatrix') 159 | 160 | def set_divisor(self, divisor): 161 | self._attributes['divisor'] = divisor 162 | def get_divisor(self): 163 | return self._attributes.get('divisor') 164 | 165 | def set_bias(self, bias): 166 | self._attributes['bias'] = bias 167 | def get_bias(self): 168 | return self._attributes.get('bias') 169 | 170 | def set_targetX(self, targetX): 171 | self._attributes['targetX'] = targetX 172 | def get_targetX(self): 173 | return self._attributes.get('targetX') 174 | 175 | def set_targetY(self, targetY): 176 | self._attributes['targetY'] = targetY 177 | def get_targetY(self): 178 | return self._attributes.get('targetY') 179 | 180 | def set_edgeMode(self, edgeMode): 181 | self._attributes['edgeMode'] = edgeMode 182 | def get_edgeMode(self): 183 | return self._attributes.get('edgeMode') 184 | 185 | def set_kernelUnitLength(self, kernelUnitLength): 186 | self._attributes['kernelUnitLength'] = kernelUnitLength 187 | def get_kernelUnitLength(self): 188 | return self._attributes.get('kernelUnitLength') 189 | 190 | def set_preserveAlpha(self, preserveAlpha): 191 | self._attributes['preserveAlpha'] = preserveAlpha 192 | def get_preserveAlpha(self): 193 | return self._attributes.get('preserveAlpha') 194 | 195 | class FeDiffuseLighting(FeComponentTransfer, StyleAttrib, PaintAttrib, PresentationAttributes_LightingEffects): 196 | """ 197 | Class representing the feDiffuseLighting element of an svg doc. 198 | """ 199 | def __init__(self, surfaceScale=None, diffuseConstant=None, kernelUnitLength=None , **kwargs): 200 | BaseElement.__init__(self, 'feDiffuseLighting') 201 | self.set_surfaceScale(surfaceScale) 202 | self.set_diffuseConstant(diffuseConstant) 203 | self.set_kernelUnitLength(kernelUnitLength) 204 | self.setKWARGS(**kwargs) 205 | 206 | def set_surfaceScale(self, surfaceScale): 207 | self._attributes['surfaceScale'] = surfaceScale 208 | def get_surfaceScale(self): 209 | return self._attributes.get('surfaceScale') 210 | 211 | def set_diffuseConstant(self, diffuseConstant): 212 | self._attributes['diffuseConstant'] = diffuseConstant 213 | def get_diffuseConstant(self): 214 | return self._attributes.get('diffuseConstant') 215 | 216 | def set_kernelUnitLength(self, kernelUnitLength): 217 | self._attributes['kernelUnitLength'] = kernelUnitLength 218 | def get_kernelUnitLength(self): 219 | return self._attributes.get('kernelUnitLength') 220 | 221 | class FeDisplacementMap(FeComponentTransfer): 222 | """ 223 | Class representing the feDisplacementMap element of an svg doc. 224 | """ 225 | def __init__(self, in2=None, scale=None, xChannelSelector=None, yChannelSelector=None, **kwargs): 226 | BaseElement.__init__(self, 'feDisplacementMap') 227 | self.set_in2(in2) 228 | self.set_scale(scale) 229 | self.set_xChannelSelector(xChannelSelector) 230 | self.set_yChannelSelector(yChannelSelector) 231 | self.setKWARGS(**kwargs) 232 | 233 | def set_in2(self, in2): 234 | self._attributes['in2'] = in2 235 | def get_in2(self): 236 | return self._attributes.get('in2') 237 | 238 | def set_scale(self, scale): 239 | self._attributes['scale'] = scale 240 | def get_scale(self): 241 | return self._attributes.get('scale') 242 | 243 | def set_xChannelSelector(self, xChannelSelector): 244 | self._attributes['xChannelSelector'] = xChannelSelector 245 | def get_xChannelSelector(self): 246 | return self._attributes.get('xChannelSelector') 247 | 248 | def set_yChannelSelector(self, yChannelSelector): 249 | self._attributes['yChannelSelector'] = yChannelSelector 250 | def get_yChannelSelector(self): 251 | return self._attributes.get('yChannelSelector') 252 | 253 | class FeFlood(FeComponentTransfer, StyleAttrib, PaintAttrib, PresentationAttributes_feFlood): 254 | """ 255 | Class representing the feFlood element of an svg doc. 256 | """ 257 | def __init__(self, x=None, y=None, width=None, height=None, flood_color=None, flood_opacity=None, **kwargs): 258 | BaseElement.__init__(self, 'feFlood') 259 | self.set_x(x) 260 | self.set_y(y) 261 | self.set_height(height) 262 | self.set_width(width) 263 | self.set_flood_color(flood_color) 264 | self.set_flood_opacity(flood_opacity) 265 | self.setKWARGS(**kwargs) 266 | 267 | class FeGaussianBlur(FeComponentTransfer): 268 | """ 269 | Class representing the feGaussianBlur element of an svg doc. 270 | """ 271 | def __init__(self, inValue=None, x=None, y=None, width=None, height=None, stdDeviation=None, **kwargs): 272 | BaseElement.__init__(self, 'feGaussianBlur') 273 | self.set_x(x) 274 | self.set_y(y) 275 | self.set_height(height) 276 | self.set_width(width) 277 | self.set_in(inValue) 278 | self.set_stdDeviation(stdDeviation) 279 | self.setKWARGS(**kwargs) 280 | 281 | def set_stdDeviation(self, stdDeviation): 282 | self._attributes['stdDeviation'] = stdDeviation 283 | def get_stdDeviation(self): 284 | return self._attributes.get('stdDeviation') 285 | 286 | class FeImage(BaseElement, CoreAttrib, XLinkAttrib, FilterColorAttrib, FilterPrimitiveAttrib, ExternalAttrib, StyleAttrib, PresentationAttributes_All): 287 | """ 288 | Class representing the feImage element of an svg doc. 289 | """ 290 | def __init__(self, xlink_href=None, x=None, y=None, width=None, height=None, result=None, **kwargs): 291 | BaseElement.__init__(self, 'feImage') 292 | self.set_xlink_href(xlink_href) 293 | self.set_x(x) 294 | self.set_y(y) 295 | self.set_height(height) 296 | self.set_width(width) 297 | self.set_result(result) 298 | self.setKWARGS(**kwargs) 299 | 300 | class FeMerge(BaseElement, CoreAttrib, FilterPrimitiveAttrib): 301 | """ 302 | Class representing the feMerge element of an svg doc. 303 | """ 304 | def __init__(self, x=None, y=None, width=None, height=None, **kwargs): 305 | BaseElement.__init__(self, 'feMerge') 306 | self.set_x(x) 307 | self.set_y(y) 308 | self.set_height(height) 309 | self.set_width(width) 310 | self.setKWARGS(**kwargs) 311 | 312 | class FeMergeNode(BaseElement, CoreAttrib, FilterColorAttrib, FilterPrimitiveWithInAttrib): 313 | """ 314 | Class representing the feMergeNode element of an svg doc. 315 | """ 316 | def __init__(self, inValue=None, **kwargs): 317 | BaseElement.__init__(self, 'feMergeNode') 318 | self.set_in(inValue) 319 | self.setKWARGS(**kwargs) 320 | 321 | class FeMorphology(FeComponentTransfer): 322 | """ 323 | Class representing the feMorphology element of an svg doc. 324 | """ 325 | def __init__(self, x=None, y=None, width=None, height=None, operator=None, radius=None, **kwargs): 326 | BaseElement.__init__(self, 'feMorphology') 327 | self.set_x(x) 328 | self.set_y(y) 329 | self.set_height(height) 330 | self.set_width(width) 331 | self.set_operator(operator) 332 | self.set_radius(radius) 333 | self.setKWARGS(**kwargs) 334 | 335 | def set_operator(self, operator): 336 | self._attributes['operator'] = operator 337 | def get_operator(self): 338 | return self._attributes.get('operator') 339 | 340 | def set_radius(self, radius): 341 | self._attributes['radius'] = radius 342 | def get_radius(self): 343 | return self._attributes.get('radius') 344 | 345 | class FeOffset(FeComponentTransfer, DeltaPointAttrib): 346 | """ 347 | Class representing the feOffset element of an svg doc. 348 | """ 349 | def __init__(self, inValue=None, dx=None, dy=None, **kwargs): 350 | BaseElement.__init__(self, 'feOffset') 351 | self.set_in(inValue) 352 | self.set_dx(dx) 353 | self.set_dy(dy) 354 | self.setKWARGS(**kwargs) 355 | 356 | class FeSpecularLighting(FeComponentTransfer, StyleAttrib, PaintAttrib, PresentationAttributes_LightingEffects): 357 | """ 358 | Class representing the feSpecularLighting element of an svg doc. 359 | """ 360 | def __init__(self, lighting_color=None, surfaceScale=None, specularConstant=None, specularExponent=None, kernelUnitLength=None, **kwargs): 361 | BaseElement.__init__(self, 'feSpecularLighting') 362 | self.set_lighting_color(lighting_color) 363 | self.set_surfaceScale(surfaceScale) 364 | self.set_specularConstant(specularConstant) 365 | self.set_specularExponent(specularExponent) 366 | self.set_kernelUnitLength(kernelUnitLength) 367 | self.setKWARGS(**kwargs) 368 | 369 | def set_surfaceScale(self, surfaceScale): 370 | self._attributes['surfaceScale'] = surfaceScale 371 | def get_surfaceScale(self): 372 | return self._attributes.get('surfaceScale') 373 | 374 | def set_specularConstant(self, specularConstant): 375 | self._attributes['specularConstant'] = specularConstant 376 | def get_specularConstant(self): 377 | return self._attributes.get('specularConstant') 378 | 379 | def set_specularExponent(self, specularExponent): 380 | self._attributes['specularExponent'] = specularExponent 381 | def get_specularExponent(self): 382 | return self._attributes.get('specularExponent') 383 | 384 | def set_kernelUnitLength(self, kernelUnitLength): 385 | self._attributes['kernelUnitLength'] = kernelUnitLength 386 | def get_kernelUnitLength(self): 387 | return self._attributes.get('kernelUnitLength') 388 | 389 | class FeTile(FeComponentTransfer): 390 | """ 391 | Class representing the feTile element of an svg doc. 392 | """ 393 | def __init__(self, **kwargs): 394 | BaseElement.__init__(self, 'feTile') 395 | self.setKWARGS(**kwargs) 396 | 397 | class feTurbulence(BaseElement, CoreAttrib, FilterColorAttrib, FilterPrimitiveAttrib): 398 | """ 399 | Class representing the feTurbulence element of an svg doc. 400 | """ 401 | def __init__(self, **kwargs): 402 | BaseElement.__init__(self, 'feTurbulence') 403 | self.setKWARGS(**kwargs) 404 | 405 | def set_baseFrequency(self, baseFrequency): 406 | self._attributes['baseFrequency'] = baseFrequency 407 | def get_baseFrequency(self): 408 | return self._attributes.get('baseFrequency') 409 | 410 | def set_numOctaves(self, numOctaves): 411 | self._attributes['numOctaves'] = numOctaves 412 | def get_numOctaves(self): 413 | return self._attributes.get('numOctaves') 414 | 415 | def set_seed(self, seed): 416 | self._attributes['seed'] = seed 417 | def get_seed(self): 418 | return self._attributes.get('seed') 419 | 420 | def set_stitchTiles(self, stitchTiles): 421 | self._attributes['stitchTiles'] = stitchTiles 422 | def get_stitchTiles(self): 423 | return self._attributes.get('stitchTiles') 424 | 425 | def set_type(self, type): 426 | self._attributes['type'] = type 427 | def get_type(self): 428 | return self._attributes.get('type') 429 | 430 | class FeDistantLight(BaseElement, CoreAttrib): 431 | """ 432 | Class representing the feDistantLight element of an svg doc. 433 | """ 434 | def __init__(self, azimuth=None, elevation=None, **kwargs): 435 | BaseElement.__init__(self, 'feDistantLight') 436 | self.set_azimuth(azimuth) 437 | self.set_elevation(elevation) 438 | self.setKWARGS(**kwargs) 439 | 440 | def set_azimuth(self, azimuth): 441 | self._attributes['azimuth'] = azimuth 442 | def get_azimuth(self): 443 | return self._attributes.get('azimuth') 444 | 445 | def set_elevation(self, elevation): 446 | self._attributes['elevation'] = elevation 447 | def get_elevation(self): 448 | return self._attributes.get('elevation') 449 | 450 | class FePointLight(BaseElement, CoreAttrib, PointAttrib): 451 | """ 452 | Class representing the fePointLight element of an svg doc. 453 | """ 454 | def __init__(self, x=None, y=None, z=None, **kwargs): 455 | BaseElement.__init__(self, 'fePointLight') 456 | self.set_x(x) 457 | self.set_y(y) 458 | self.set_z(z) 459 | self.setKWARGS(**kwargs) 460 | 461 | def set_z(self, z): 462 | self._attributes['z'] = z 463 | def get_z(self): 464 | return self._attributes.get('z') 465 | 466 | class FeSpotLight(FePointLight): 467 | """ 468 | Class representing the feSpotLight element of an svg doc. 469 | """ 470 | def __init__(self, x=None, y=None, z=None, pointsAtX=None, pointsAtY=None, pointsAtZ=None, specularExponent=None, limitingConeAngle=None, **kwargs): 471 | BaseElement.__init__(self, 'feSpotLight') 472 | self.set_x(x) 473 | self.set_y(y) 474 | self.set_z(z) 475 | self.set_pointsAtX(pointsAtX) 476 | self.set_pointsAtY(pointsAtY) 477 | self.set_pointsAtZ(pointsAtZ) 478 | self.set_specularExponent(specularExponent) 479 | self.set_limitingConeAngle(limitingConeAngle) 480 | self.setKWARGS(**kwargs) 481 | 482 | def set_pointsAtX(self, pointsAtX): 483 | self._attributes['pointsAtX'] = pointsAtX 484 | def get_pointsAtX(self): 485 | return self._attributes.get('pointsAtX') 486 | 487 | def set_pointsAtY(self, pointsAtY): 488 | self._attributes['pointsAtY'] = pointsAtY 489 | def get_pointsAtY(self): 490 | return self._attributes.get('pointsAtY') 491 | 492 | def set_pointsAtZ(self, pointsAtZ): 493 | self._attributes['pointsAtZ'] = pointsAtZ 494 | def get_pointsAtZ(self): 495 | return self._attributes.get('pointsAtZ') 496 | 497 | def set_specularExponent(self, specularExponent): 498 | self._attributes['specularExponent'] = specularExponent 499 | def get_specularExponent(self): 500 | return self._attributes.get('specularExponent') 501 | 502 | def set_limitingConeAngle(self, limitingConeAngle): 503 | self._attributes['limitingConeAngle'] = limitingConeAngle 504 | def get_limitingConeAngle(self): 505 | return self._attributes.get('limitingConeAngle') 506 | 507 | class FeFuncR(BaseElement, CoreAttrib): 508 | """ 509 | Class representing the feFuncR element of an svg doc. 510 | """ 511 | def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs): 512 | BaseElement.__init__(self, 'feFuncR') 513 | self.set_type(type) 514 | self.set_tableValues(tableValues) 515 | self.set_slope(slope) 516 | self.set_intercept(intercept) 517 | self.set_amplitude(amplitude) 518 | self.set_exponent(exponent) 519 | self.set_offset(offset) 520 | self.setKWARGS(**kwargs) 521 | 522 | def set_type(self, type): 523 | self._attributes['type'] = type 524 | def get_type(self): 525 | return self._attributes.get('type') 526 | 527 | def set_tableValues(self, tableValues): 528 | self._attributes['tableValues'] = tableValues 529 | def get_tableValues(self): 530 | return self._attributes.get('tableValues') 531 | 532 | def set_slope(self, slope): 533 | self._attributes['slope'] = slope 534 | def get_slope(self): 535 | return self._attributes.get('slope') 536 | 537 | def set_intercept(self, intercept): 538 | self._attributes['intercept'] = intercept 539 | def get_intercept(self): 540 | return self._attributes.get('intercept') 541 | 542 | def set_amplitude(self, amplitude): 543 | self._attributes['amplitude'] = amplitude 544 | def get_amplitude(self): 545 | return self._attributes.get('amplitude') 546 | 547 | def set_exponent(self, exponent): 548 | self._attributes['exponent'] = exponent 549 | def get_exponent(self): 550 | return self._attributes.get('exponent') 551 | 552 | def set_offset(self, offset): 553 | self._attributes['offset'] = offset 554 | def get_offset(self): 555 | return self._attributes.get('offset') 556 | 557 | class FeFuncG(FeFuncR): 558 | """ 559 | Class representing the feFuncG element of an svg doc. 560 | """ 561 | def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs): 562 | BaseElement.__init__(self, 'feFuncG') 563 | self.set_type(type) 564 | self.set_tableValues(tableValues) 565 | self.set_slope(slope) 566 | self.set_intercept(intercept) 567 | self.set_amplitude(amplitude) 568 | self.set_exponent(exponent) 569 | self.set_offset(offset) 570 | self.setKWARGS(**kwargs) 571 | 572 | class FeFuncB(FeFuncR): 573 | """ 574 | Class representing the feFuncB element of an svg doc. 575 | """ 576 | def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs): 577 | BaseElement.__init__(self, 'feFuncB') 578 | self.set_type(type) 579 | self.set_tableValues(tableValues) 580 | self.set_slope(slope) 581 | self.set_intercept(intercept) 582 | self.set_amplitude(amplitude) 583 | self.set_exponent(exponent) 584 | self.set_offset(offset) 585 | self.setKWARGS(**kwargs) 586 | 587 | class FeFuncA(FeFuncR): 588 | """ 589 | Class representing the feFuncA element of an svg doc. 590 | """ 591 | def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs): 592 | BaseElement.__init__(self, 'feFuncA') 593 | self.set_type(type) 594 | self.set_tableValues(tableValues) 595 | self.set_slope(slope) 596 | self.set_intercept(intercept) 597 | self.set_amplitude(amplitude) 598 | self.set_exponent(exponent) 599 | self.set_offset(offset) 600 | self.setKWARGS(**kwargs) 601 | -------------------------------------------------------------------------------- /pysvg/attributes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: iso-8859-1 -*- 3 | ''' 4 | (C) 2008, 2009 Kerim Mansour 5 | For licensing information please refer to license.txt 6 | ''' 7 | class CoreAttrib: 8 | """ 9 | The CoreAttrib class defines the attribute set Core.attrib 10 | that is the core set of attributes that can be present on any element. 11 | """ 12 | def set_id(self, id): 13 | self._attributes['id'] = id 14 | 15 | def get_id(self): 16 | return self._attributes.get('id') 17 | 18 | def set_xml_base(self, xml_base): 19 | self._attributes['xml:base'] = xml_base 20 | 21 | def get_xml_base(self): 22 | return self._attributes.get('xml:base') 23 | 24 | def set_xml_lang(self, language_code): 25 | self._attributes['xml:lang'] = language_code 26 | 27 | def get_xml_lang(self): 28 | return self._attributes.get('xml:lang') 29 | 30 | def set_xml_space(self, xml_space): 31 | self._attributes['xml:space'] = xml_space 32 | 33 | def get_xml_space(self): 34 | return self._attributes.get('xml:space') 35 | 36 | class ConditionalAttrib: 37 | """ 38 | The ConditionalAttrib class defines the Conditional.attrib attribute set. 39 | """ 40 | def set_requiredFeatures(self, requiredFeatures): 41 | self._attributes['requiredFeatures'] = requiredFeatures 42 | 43 | def get_requiredFeatures(self): 44 | return self._attributes.get('requiredFeatures') 45 | 46 | def set_requiredExtensions(self, requiredExtensions): 47 | self._attributes['requiredExtensions'] = requiredExtensions 48 | 49 | def get_requiredExtensions(self): 50 | return self._attributes.get('requiredExtensions') 51 | 52 | def set_systemLanguage(self, language_code): 53 | self._attributes['systemLanguage'] = language_code 54 | 55 | def get_systemLanguage(self): 56 | return self._attributes.get('systemLanguage') 57 | 58 | class StyleAttrib: 59 | """ 60 | The StyleAttrib class defines the Style.attrib attribute set. 61 | """ 62 | def set_style(self, style): 63 | self._attributes['style'] = style 64 | 65 | def get_style(self): 66 | return self._attributes.get('style') 67 | 68 | def set_class(self, aClass): 69 | self._attributes['class'] = aClass 70 | 71 | def get_class(self): 72 | return self._attributes.get('class') 73 | 74 | class GraphicalEventsAttrib: 75 | """ 76 | The GraphicalEventsAttrib class defines the GraphicalEvents.attrib attribute set. 77 | """ 78 | def set_onfocusin(self, onfocusin): 79 | self._attributes['onfocusin'] = onfocusin 80 | 81 | def get_onfocusin(self): 82 | return self._attributes.get('onfocusin') 83 | 84 | def set_onfocusout(self, onfocusout): 85 | self._attributes['onfocusout'] = onfocusout 86 | 87 | def get_onfocusout(self): 88 | return self._attributes.get('onfocusout') 89 | 90 | def set_onactivate(self, onactivate): 91 | self._attributes['onactivate'] = onactivate 92 | 93 | def get_onactivate(self): 94 | return self._attributes.get('onactivate') 95 | 96 | def set_onclick(self, onclick): 97 | self._attributes['onclick'] = onclick 98 | 99 | def get_onclick(self): 100 | return self._attributes.get('onclick') 101 | 102 | def set_onmousedown(self, onmousedown): 103 | self._attributes['onmousedown'] = onmousedown 104 | 105 | def get_onmousedown(self): 106 | return self._attributes.get('onmousedown') 107 | 108 | def set_onmouseup(self, onmouseup): 109 | self._attributes['onmouseup'] = onmouseup 110 | 111 | def get_onmouseup(self): 112 | return self._attributes.get('onmouseup') 113 | 114 | def set_onmouseover(self, onmouseover): 115 | self._attributes['onmouseover'] = onmouseover 116 | 117 | def get_onmouseover(self): 118 | return self._attributes.get('onmouseover') 119 | 120 | def set_onmousemove(self, onmousemove): 121 | self._attributes['onmousemove'] = onmousemove 122 | 123 | def get_onmousemove(self): 124 | return self._attributes.get('onmousemove') 125 | 126 | def set_onmouseout(self, onmouseout): 127 | self._attributes['onmouseout'] = onmouseout 128 | 129 | def get_onmouseout(self): 130 | return self._attributes.get('onmouseout') 131 | 132 | def set_onload(self, onload): 133 | self._attributes['onload'] = onload 134 | 135 | def get_onload(self): 136 | return self._attributes.get('onload') 137 | 138 | 139 | 140 | class CursorAttrib: 141 | """ 142 | The CursorAttrib class defines the Cursor.attrib attribute set. 143 | """ 144 | def set_cursor(self, cursor): 145 | self._attributes['cursor'] = cursor 146 | 147 | def get_cursor(self): 148 | return self._attributes.get('cursor') 149 | 150 | class ExternalAttrib: 151 | """ 152 | The ExternalAttrib class defines the External.attrib attribute set. 153 | """ 154 | def set_externalResourcesRequired(self, externalResourcesRequired): 155 | self._attributes['externalResourcesRequired'] = externalResourcesRequired 156 | 157 | def get_externalResourcesRequired(self): 158 | return self._attributes.get('externalResourcesRequired') 159 | 160 | class DocumentEventsAttrib: 161 | """ 162 | The DocumentEventsAttrib class defines the DocumentEvents.attrib attribute set. 163 | """ 164 | def set_onunload(self, onunload): 165 | self._attributes['onunload'] = onunload 166 | 167 | def get_onunload(self): 168 | return self._attributes.get('onunload') 169 | 170 | def set_onabort(self, onabort): 171 | self._attributes['onabort'] = onabort 172 | 173 | def get_onabort(self): 174 | return self._attributes.get('onabort') 175 | 176 | def set_onerror(self, onerror): 177 | self._attributes['onerror'] = onerror 178 | 179 | def get_onerror(self): 180 | return self._attributes.get('onerror') 181 | 182 | def set_onresize(self, onresize): 183 | self._attributes['onresize'] = onresize 184 | 185 | def get_onresize(self): 186 | return self._attributes.get('onresize') 187 | 188 | def set_onscroll(self, onscroll): 189 | self._attributes['onscroll'] = onscroll 190 | 191 | def get_onscroll(self): 192 | return self._attributes.get('onscroll') 193 | 194 | def set_onzoom(self, onzoom): 195 | self._attributes['onzoom'] = onzoom 196 | 197 | def get_onzoom(self): 198 | return self._attributes.get('onzoom') 199 | 200 | class OpacityAttrib: 201 | """ 202 | The OpacityAttrib class defines the Opacity.attrib attribute set. 203 | """ 204 | def set_opacity(self, opacity): 205 | self._attributes['opacity'] = opacity 206 | 207 | def get_opacity(self): 208 | return self._attributes.get('opacity') 209 | 210 | def set_stroke_opacity(self, stroke_opacity): 211 | self._attributes['stroke-opacity'] = stroke_opacity 212 | 213 | def get_stroke_opacity(self): 214 | return self._attributes.get('stroke-opacity') 215 | 216 | def set_fill_opacity(self, fill_opacity): 217 | self._attributes['fill-opacity'] = fill_opacity 218 | 219 | def get_fill_opacity(self): 220 | return self._attributes.get('fill-opacity') 221 | 222 | class PaintAttrib: 223 | """ 224 | The PaintAttrib class defines the Paint.attrib attribute set. 225 | """ 226 | def set_color(self, color): 227 | self._attributes['color'] = color 228 | 229 | def get_color(self): 230 | return self._attributes.get('color') 231 | 232 | def set_color_interpolation(self, color_interpolation): 233 | self._attributes['color-interpolation'] = color_interpolation 234 | 235 | def get_color_interpolation(self): 236 | return self._attributes.get('color-interpolation') 237 | 238 | def set_color_rendering(self, color_rendering): 239 | self._attributes['color-rendering'] = color_rendering 240 | 241 | def get_color_rendering(self): 242 | return self._attributes.get('color-rendering') 243 | 244 | def set_fill(self, fill): 245 | self._attributes['fill'] = fill 246 | 247 | def get_fill(self): 248 | return self._attributes.get('fill') 249 | 250 | def set_fill_rule(self, fill_rule): 251 | self._attributes['fill-rule'] = fill_rule 252 | 253 | def get_fill_rule(self): 254 | return self._attributes.get('fill-rule') 255 | 256 | def set_stroke(self, stroke): 257 | self._attributes['stroke'] = stroke 258 | 259 | def get_stroke(self): 260 | return self._attributes.get('stroke') 261 | 262 | def set_stroke_dasharray(self, stroke_dasharray): 263 | self._attributes['stroke-dasharray'] = stroke_dasharray 264 | 265 | def get_stroke_dasharray(self): 266 | return self._attributes.get('stroke-dasharray') 267 | 268 | def set_stroke_dashoffset(self, stroke_dashoffset): 269 | self._attributes['stroke-dashoffset'] = stroke_dashoffset 270 | 271 | def get_stroke_dashoffset(self): 272 | return self._attributes.get('stroke-offset') 273 | 274 | def set_stroke_linecap(self, stroke_linecap): 275 | self._attributes['stroke-linecap'] = stroke_linecap 276 | 277 | def get_stroke_linecap(self): 278 | return self._attributes.get('stroke-linecap') 279 | 280 | def set_stroke_linejoin(self, stroke_linejoin): 281 | self._attributes['stroke-linejoin'] = stroke_linejoin 282 | 283 | def get_stroke_linejoin(self): 284 | return self._attributes.get('stroke-linejoin') 285 | 286 | def set_stroke_miterlimit(self, stroke_miterlimit): 287 | self._attributes['stroke-miterlimit'] = stroke_miterlimit 288 | 289 | def get_stroke_miterlimit(self): 290 | return self._attributes.get('stroke-miterlimit') 291 | 292 | def set_stroke_width(self, stroke_width): 293 | self._attributes['stroke-width'] = stroke_width 294 | 295 | def get_stroke_width(self): 296 | return self._attributes.get('stroke-width') 297 | 298 | class GraphicsAttrib: 299 | """ 300 | The GraphicsAttrib class defines the Graphics.attrib attribute set. 301 | """ 302 | def set_display(self, display): 303 | self._attributes['display'] = display 304 | 305 | def get_display(self): 306 | return self._attributes.get('display') 307 | 308 | def set_image_rendering(self, image_rendering): 309 | self._attributes['image-rendering'] = image_rendering 310 | 311 | def get_image_rendering(self): 312 | return self._attributes.get('image-rendering') 313 | 314 | def set_pointer_events(self, pointer_events): 315 | self._attributes['pointer-events'] = pointer_events 316 | 317 | def get_pointer_events(self): 318 | return self._attributes.get('pointer-events') 319 | 320 | def set_shape_rendering(self, shape_rendering): 321 | self._attributes['shape-rendering'] = shape_rendering 322 | 323 | def get_shape_rendering(self): 324 | return self._attributes.get('shape-rendering') 325 | 326 | def set_text_rendering(self, text_rendering): 327 | self._attributes['text-rendering'] = text_rendering 328 | 329 | def get_text_rendering(self): 330 | return self._attributes.get('text-rendering') 331 | 332 | def set_visibility(self, visibility): 333 | self._attributes['visibility'] = visibility 334 | 335 | def get_visibility(self): 336 | return self._attributes.get('visibility') 337 | 338 | class MarkerAttrib: 339 | """ 340 | The MarkerAttrib class defines the Marker.attrib attribute set. 341 | """ 342 | def set_marker_start(self, marker_start): 343 | self._attributes['marker-start'] = marker_start 344 | 345 | def get_marker_start(self): 346 | return self._attributes.get('marker-start') 347 | 348 | def set_marker_mid(self, marker_mid): 349 | self._attributes['marker-mid'] = marker_mid 350 | 351 | def get_marker_mid(self): 352 | return self._attributes.get('marker-mid') 353 | 354 | def set_marker_end(self, marker_end): 355 | self._attributes['marker-end'] = marker_end 356 | 357 | def get_marker_end(self): 358 | return self._attributes.get('marker-end') 359 | 360 | class ViewportAttrib: 361 | """ 362 | The ViewportAttrib class defines the Viewport.attrib attribute set. 363 | """ 364 | def set_clip(self, clip): 365 | self._attributes['clip'] = clip 366 | 367 | def get_clip(self): 368 | return self._attributes.get('clip') 369 | 370 | def set_overflow(self, overflow): 371 | self._attributes['overflow'] = overflow 372 | 373 | def get_overflow(self): 374 | return self._attributes.get('overflow') 375 | 376 | class FilterAttrib: 377 | """ 378 | The FilterAttrib class defines the Filter.attrib attribute sets. 379 | """ 380 | def set_filter(self, filter): 381 | self._attributes['filter'] = filter 382 | 383 | def get_filter(self): 384 | return self._attributes.get('filter') 385 | 386 | class FilterColorAttrib: 387 | """ 388 | The FilterColorAttrib class defines the FilterColor.attrib attribute sets. 389 | """ 390 | def set_color_interpolation_filters(self, color_interpolation_filters): 391 | self._attributes['color-interpolation-filters'] = color_interpolation_filters 392 | 393 | def get_color_interpolation_filters(self): 394 | return self._attributes.get('color-interpolation-filters') 395 | 396 | class FilterPrimitiveAttrib: 397 | """ 398 | The FilterPrimitiveAttrib class defines the FilterPrimitive.attrib attribute sets. 399 | """ 400 | def set_x(self, x): 401 | self._attributes['x'] = x 402 | 403 | def get_x(self): 404 | return self._attributes.get('x') 405 | 406 | def set_y(self, y): 407 | self._attributes['y'] = y 408 | 409 | def get_y(self): 410 | return self._attributes.get('y') 411 | 412 | def set_height(self, height): 413 | self._attributes['height'] = height 414 | 415 | def get_height(self): 416 | return self._attributes.get('height') 417 | 418 | def set_width(self, width): 419 | self._attributes['width'] = width 420 | 421 | def get_width(self): 422 | return self._attributes.get('width') 423 | 424 | def set_result(self, result): 425 | self._attributes['result'] = result 426 | 427 | def get_result(self): 428 | return self._attributes.get('result') 429 | 430 | class FilterPrimitiveWithInAttrib(FilterPrimitiveAttrib): 431 | """ 432 | The FilterPrimitiveWithInAttrib class defines the FilterPrimitiveWithIn.attrib attribute sets. 433 | """ 434 | def set_in(self, inValue): 435 | self._attributes['in'] = inValue 436 | 437 | def get_in(self): 438 | return self._attributes.get('in') 439 | 440 | class XLinkAttrib: 441 | """ 442 | The XLinkAttrib class defines the XLink.attrib, XLinkRequired.attrib, XLinkEmbed.attrib and XLinkReplace.attrib attribute sets. 443 | """ 444 | def set_xlink_type(self, xlink_type): 445 | self._attributes['xlink:type'] = xlink_type 446 | def get_xlink_type(self): 447 | return self._attributes['xlink:type'] 448 | 449 | def set_xlink_href(self, xlink_href): 450 | self._attributes['xlink:href'] = xlink_href 451 | def get_xlink_href(self): 452 | return self._attributes['xlink:href'] 453 | 454 | def set_xlink_role(self, xlink_role): 455 | self._attributes['xlink:role'] = xlink_role 456 | def get_xlink_role(self): 457 | return self._attributes['xlink:role'] 458 | 459 | def set_xlink_arcrole(self, xlink_arcrole): 460 | self._attributes['xlink:arcrole'] = xlink_arcrole 461 | def get_xlink_arcrole(self): 462 | return self._attributes['xlink:arcrole'] 463 | 464 | def set_xlink_title(self, xlink_title): 465 | self._attributes['xlink:title'] = xlink_title 466 | def get_xlink_title(self): 467 | return self._attributes['xlink:title'] 468 | 469 | def set_xlink_show(self, xlink_show): 470 | self._attributes['xlink:show'] = xlink_show 471 | def get_xlink_show(self): 472 | return self._attributes['xlink:show'] 473 | 474 | def set_xlink_actuate(self, xlink_actuate): 475 | self._attributes['xlink:actuate'] = xlink_actuate 476 | def get_xlink_actuate(self): 477 | return self._attributes['xlink:actuate'] 478 | 479 | class TextAttrib: 480 | """ 481 | The TextAttrib class defines the Text.attrib attribute set. 482 | """ 483 | def set_writing_mode(self, writing_mode): 484 | self._attributes['writing-mode'] = writing_mode 485 | def get_writing_mode(self): 486 | return self._attributes['writing-mode'] 487 | 488 | class TextContentAttrib: 489 | """ 490 | The TextContentAttrib class defines the TextContent.attrib attribute set. 491 | """ 492 | def set_alignment_baseline(self, alignment_baseline): 493 | self._attributes['alignment-baseline'] = alignment_baseline 494 | def get_alignment_baseline(self): 495 | return self._attributes['alignment-baseline'] 496 | 497 | def set_baseline_shift(self, baseline_shift): 498 | self._attributes['baseline-shift'] = baseline_shift 499 | def get_baseline_shift(self): 500 | return self._attributes['baseline-shift'] 501 | 502 | def set_direction(self, direction): 503 | self._attributes['direction'] = direction 504 | def get_direction(self): 505 | return self._attributes['direction'] 506 | 507 | def set_dominant_baseline(self, dominant_baseline): 508 | self._attributes['dominant-baseline'] = dominant_baseline 509 | def get_dominant_baseline(self): 510 | return self._attributes['dominant-baseline'] 511 | 512 | def set_glyph_orientation_horizontal(self, glyph_orientation_horizontal): 513 | self._attributes['glyph-orientation-horizontal'] = glyph_orientation_horizontal 514 | def get_glyph_orientation_horizontal(self): 515 | return self._attributes['glyph-orientation-horizontal'] 516 | 517 | def set_glyph_orientation_vertical(self, glyph_orientation_vertical): 518 | self._attributes['glyph-orientation-vertical'] = glyph_orientation_vertical 519 | def get_glyph_orientation_vertical(self): 520 | return self._attributes['glyph-orientation-vertical'] 521 | 522 | def set_kerning(self, kerning): 523 | self._attributes['kerning'] = kerning 524 | def get_kerning(self): 525 | return self._attributes['kerning'] 526 | 527 | def set_letter_spacing(self, letter_spacing): 528 | self._attributes['letter-spacing'] = letter_spacing 529 | def get_letter_spacing(self): 530 | return self._attributes['letter-spacing'] 531 | 532 | def set_text_anchor(self, text_anchor): 533 | self._attributes['text-anchor'] = text_anchor 534 | def get_text_anchor(self): 535 | return self._attributes['text-anchor'] 536 | 537 | def set_text_decoration(self, text_decoration): 538 | self._attributes['text-decoration'] = text_decoration 539 | def get_text_decoration(self): 540 | return self._attributes['text-decoration'] 541 | 542 | def set_unicode_bidi(self, unicode_bidi): 543 | self._attributes['unicode-bidi'] = unicode_bidi 544 | def get_unicode_bidi(self): 545 | return self._attributes['unicode-bidi'] 546 | 547 | def set_word_spacing(self, word_spacing): 548 | self._attributes['word-spacing'] = word_spacing 549 | def get_word_spacing(self): 550 | return self._attributes['word-spacing'] 551 | 552 | class FontAttrib: 553 | """ 554 | The FontAttrib class defines the Font.attrib attribute set. 555 | """ 556 | def set_font_family(self, font_family): 557 | self._attributes['font-family'] = font_family 558 | def get_font_family(self): 559 | return self._attributes['font-family'] 560 | 561 | def set_font_size(self, font_size): 562 | self._attributes['font-size'] = font_size 563 | def get_font_size(self): 564 | return self._attributes['font-size'] 565 | 566 | def set_font_size_adjust(self, font_size_adjust): 567 | self._attributes['font-size-adjust'] = font_size_adjust 568 | def get_font_size_adjust(self): 569 | return self._attributes['font-size-adjust'] 570 | 571 | def set_font_stretch(self, font_stretch): 572 | self._attributes['font-stretch'] = font_stretch 573 | def get_font_stretch(self): 574 | return self._attributes['font-stretch'] 575 | 576 | def set_font_style(self, font_style): 577 | self._attributes['font-style'] = font_style 578 | def get_font_style(self): 579 | return self._attributes['font-style'] 580 | 581 | def set_font_variant(self, font_variant): 582 | self._attributes['font-variant'] = font_variant 583 | def get_font_variant(self): 584 | return self._attributes['font-variant'] 585 | 586 | def set_font_weight(self, font_weight): 587 | self._attributes['font-weight'] = font_weight 588 | def get_font_weight(self): 589 | return self._attributes['font-weight'] 590 | 591 | class MaskAttrib: 592 | """ 593 | The MaskAttrib class defines the Mask.attrib attribute set. 594 | """ 595 | def set_mask(self, mask): 596 | self._attributes['mask'] = mask 597 | 598 | def get_mask(self): 599 | return self._attributes.get('mask') 600 | 601 | class ClipAttrib: 602 | """ 603 | The ClipAttrib class defines the Clip.attrib attribute set. 604 | """ 605 | def set_clip_path(self, clip_path): 606 | self._attributes['clip-path'] = clip_path 607 | 608 | def get_clip_path(self): 609 | return self._attributes.get('clip-path') 610 | 611 | def set_clip_rule(self, clip_rule): 612 | self._attributes['clip-rule'] = clip_rule 613 | 614 | def get_clip_rule(self): 615 | return self._attributes.get('clip-rule') 616 | 617 | class GradientAttrib: 618 | """ 619 | The GradientAttrib class defines the Gradient.attrib attribute set. 620 | """ 621 | def set_stop_color(self, stop_color): 622 | self._attributes['stop-color'] = stop_color 623 | 624 | def get_stop_color(self): 625 | return self._attributes.get('stop-color') 626 | 627 | def set_stop_opacity(self, stop_opacity): 628 | self._attributes['stop-opacity'] = stop_opacity 629 | 630 | def get_stop_opacity(self): 631 | return self._attributes.get('stop-opacity') 632 | 633 | class PresentationAttributes_Color: 634 | """ 635 | The PresentationAttributes_Color class defines the PresentationAttributes_Color.attrib attribute set. 636 | The following presentation attributes have to do with specifying color. 637 | """ 638 | def set_color(self, color): 639 | self._attributes['color'] = color 640 | 641 | def get_color(self): 642 | return self._attributes.get('color') 643 | 644 | def set_color_interpolation(self, color_interpolation): 645 | self._attributes['color-interpolation'] = color_interpolation 646 | 647 | def get_color_interpolation(self): 648 | return self._attributes.get('color-interpolation') 649 | 650 | def set_color_rendering(self, color_rendering): 651 | self._attributes['color-rendering'] = color_rendering 652 | 653 | def get_color_rendering(self): 654 | return self._attributes.get('color-rendering') 655 | 656 | class PresentationAttributes_Containers: 657 | """ 658 | The PresentationAttributes_Containers class defines the PresentationAttributes_Containers.attrib attribute set. 659 | The following presentation attributes apply to container elements. 660 | """ 661 | def set_enable_background(self, enableBackground): 662 | self._attributes['enable-background'] = enableBackground 663 | 664 | def get_enable_background(self): 665 | return self._attributes.get('enable-background') 666 | 667 | class PresentationAttributes_feFlood: 668 | """ 669 | The PresentationAttributes_feFlood class defines the PresentationAttributes_feFlood.attrib attribute set. 670 | The following presentation attributes apply to 'feFlood' elements. 671 | """ 672 | def set_flood_color(self, flood_color): 673 | self._attributes['flood-color'] = flood_color 674 | def get_flood_color(self): 675 | return self._attributes.get('flood-color') 676 | 677 | def set_flood_opacity(self, flood_opacity): 678 | self._attributes['flood-opacity'] = flood_opacity 679 | def get_flood_opacity(self): 680 | return self._attributes.get('flood-opacity') 681 | 682 | class PresentationAttributes_FilterPrimitives: 683 | """ 684 | The PresentationAttributes_FilterPrimitives class defines the PresentationAttributes_FilterPrimitives.attrib attribute set. 685 | The following presentation attributes apply to filter primitives 686 | """ 687 | def set_color_interpolation_filters(self, color_interpolation_filters): 688 | self._attributes['color-interpolation-filters'] = color_interpolation_filters 689 | def get_color_interpolation_filters(self): 690 | return self._attributes.get('color-interpolation-filters') 691 | 692 | class PresentationAttributes_FillStroke: 693 | """ 694 | The PresentationAttributes_FillStroke class defines the PresentationAttributes_FillStroke.attrib attribute set. 695 | The following presentation attributes apply to filling and stroking operations. 696 | """ 697 | def set_fill(self, fill): 698 | self._attributes['fill'] = fill 699 | 700 | def get_fill(self): 701 | return self._attributes.get('fill') 702 | 703 | def set_fill_opacity(self, fill_opacity): 704 | self._attributes['fill-opacity'] = fill_opacity 705 | 706 | def get_fill_opacity(self): 707 | return self._attributes.get('fill-opacity') 708 | 709 | def set_fill_rule(self, fill_rule): 710 | self._attributes['fill-rule'] = fill_rule 711 | 712 | def get_fill_rule(self): 713 | return self._attributes.get('fill-rule') 714 | 715 | def set_stroke(self, stroke): 716 | self._attributes['stroke'] = stroke 717 | 718 | def get_stroke(self): 719 | return self._attributes.get('stroke') 720 | 721 | def set_stroke_opacity(self, stroke_opacity): 722 | self._attributes['stroke-opacity'] = stroke_opacity 723 | 724 | def get_stroke_opacity(self): 725 | return self._attributes.get('stroke-opacity') 726 | 727 | def set_stroke_dasharray(self, stroke_dasharray): 728 | self._attributes['stroke-dasharray'] = stroke_dasharray 729 | 730 | def get_stroke_dasharray(self): 731 | return self._attributes.get('stroke-dasharray') 732 | 733 | def set_stroke_dashoffset(self, stroke_dashoffset): 734 | self._attributes['stroke-dashoffset'] = stroke_dashoffset 735 | 736 | def get_stroke_dashoffset(self): 737 | return self._attributes.get('stroke-offset') 738 | 739 | def set_stroke_linecap(self, stroke_linecap): 740 | self._attributes['stroke-linecap'] = stroke_linecap 741 | 742 | def get_stroke_linecap(self): 743 | return self._attributes.get('stroke-linecap') 744 | 745 | def set_stroke_linejoin(self, stroke_linejoin): 746 | self._attributes['stroke-linejoin'] = stroke_linejoin 747 | 748 | def get_stroke_linejoin(self): 749 | return self._attributes.get('stroke-linejoin') 750 | 751 | def set_stroke_miterlimit(self, stroke_miterlimit): 752 | self._attributes['stroke-miterlimit'] = stroke_miterlimit 753 | 754 | def get_stroke_miterlimit(self): 755 | return self._attributes.get('stroke-miterlimit') 756 | 757 | def set_stroke_width(self, stroke_width): 758 | self._attributes['stroke-width'] = stroke_width 759 | 760 | def get_stroke_width(self): 761 | return self._attributes.get('stroke-width') 762 | 763 | class PresentationAttributes_FontSpecification(FontAttrib): 764 | """ 765 | The PresentationAttributes_FontSpecification class defines the PresentationAttributes_FontSpecification.attrib attribute set. 766 | The following presentation attributes have to do with selecting a font to use. 767 | """ 768 | 769 | class PresentationAttributes_Gradients(GradientAttrib): 770 | """ 771 | The PresentationAttributes_Gradients class defines the PresentationAttributes_Gradients.attrib attribute set. 772 | The following presentation attributes apply to gradient 'stop' elements. 773 | """ 774 | 775 | class PresentationAttributes_Graphics(ClipAttrib, CursorAttrib, GraphicsAttrib, MaskAttrib, FilterAttrib): 776 | """ 777 | The PresentationAttributes_Graphics class defines the PresentationAttributes_Graphics.attrib attribute set. 778 | The following presentation attributes apply to graphics elements 779 | """ 780 | def set_opacity(self, opacity): 781 | self._attributes['opacity'] = opacity 782 | 783 | def get_opacity(self): 784 | return self._attributes.get('opacity') 785 | 786 | class PresentationAttributes_Images: 787 | """ 788 | The PresentationAttributes_Images class defines the PresentationAttributes_Images.attrib attribute set. 789 | The following presentation attributes apply to 'image' elements 790 | """ 791 | def set_color_profile(self, color_profile): 792 | self._attributes['color-profile'] = color_profile 793 | 794 | def get_color_profile(self): 795 | return self._attributes.get('color-profile') 796 | 797 | class PresentationAttributes_LightingEffects: 798 | """ 799 | The PresentationAttributes_LightingEffects class defines the PresentationAttributes_LightingEffects.attrib attribute set. 800 | The following presentation attributes apply to 'feDiffuseLighting' and 'feSpecularLighting' elements 801 | """ 802 | def set_lighting_color(self, lighting_color): 803 | self._attributes['lighting-color'] = lighting_color 804 | def get_lighting_color(self): 805 | return self._attributes.get('lighting-color') 806 | 807 | class PresentationAttributes_Marker(MarkerAttrib): 808 | """ 809 | The PresentationAttributes_Marker class defines the PresentationAttributes_Marker.attrib attribute set. 810 | The following presentation attributes apply to marker operations 811 | """ 812 | 813 | class PresentationAttributes_TextContentElements(TextContentAttrib): 814 | """ 815 | The PresentationAttributes_TextContentElements class defines the PresentationAttributes_TextContentElements.attrib attribute set. 816 | The following presentation attributes apply to text content elements 817 | """ 818 | 819 | class PresentationAttributes_TextElements(TextAttrib): 820 | """ 821 | The following presentation attributes apply to 'text' elements 822 | """ 823 | 824 | class PresentationAttributes_Viewports(ViewportAttrib): 825 | """ 826 | The following presentation attributes apply to elements that establish viewports 827 | """ 828 | 829 | class PresentationAttributes_All(PresentationAttributes_Color, PresentationAttributes_Containers, PresentationAttributes_feFlood, PresentationAttributes_FillStroke, PresentationAttributes_FilterPrimitives, PresentationAttributes_FontSpecification, PresentationAttributes_Gradients, PresentationAttributes_Graphics, PresentationAttributes_Images, PresentationAttributes_LightingEffects, PresentationAttributes_Marker, PresentationAttributes_TextContentElements, PresentationAttributes_TextElements, PresentationAttributes_Viewports): 830 | """ 831 | The PresentationAttributes_All class defines the Presentation.attrib attribute set. 832 | """ 833 | 834 | 835 | class ColorAttrib: 836 | """ 837 | The ColorAttrib class defines the Color.attrib attribute set. 838 | """ 839 | 840 | 841 | --------------------------------------------------------------------------------