diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/animate.py pysvg-0.2.2b/src/pysvg/animate.py
--- pysvg-0.2.2b.orig/src/pysvg/animate.py 2012-11-15 14:34:42.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/animate.py 2016-07-15 11:11:20.799965389 -0500
@@ -1,237 +1,237 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from attributes import *
-from core import BaseShape, BaseElement
-
-#####################################################
-# Attribute sets for animations
-# animation elements see below
-#####################################################
-class animationAttrib(XLinkAttrib):
- """
- The animationAttrib class defines the animation.attrib attribute set.
- """
-
-class animationAttributeAttrib:
- """
- The animationAttributeAttrib class defines the animationAttribute.attrib attribute set.
- """
- def set_attributeName(self, attributeName):
- self._attributes['attributeName'] = attributeName
- def get_attributeName(self):
- return self._attributes.get('attributeName')
-
- def set_attributeType(self, attributeType):
- self._attributes['attributeType'] = attributeType
- def get_attributeType(self):
- return self._attributes.get('attributeType')
-
-class animationTimingAttrib:
- """
- The animationTimingAttrib class defines the animationTiming.attrib attribute set.
- """
- def set_begin(self, begin):
- self._attributes['begin'] = begin
- def get_begin(self):
- return self._attributes.get('begin')
-
- def set_dur(self, dur):
- self._attributes['dur'] = dur
- def get_dur(self):
- return self._attributes.get('dur')
-
- def set_end(self, end):
- self._attributes['end'] = end
- def get_end(self):
- return self._attributes.get('end')
-
- def set_min(self, min):
- self._attributes['min'] = min
- def get_min(self):
- return self._attributes.get('min')
-
- def set_max(self, max):
- self._attributes['max'] = max
- def get_max(self):
- return self._attributes.get('max')
-
- def set_restart(self, restart):
- self._attributes['restart'] = restart
- def get_restart(self):
- return self._attributes.get('restart')
-
- def set_repeatCount(self, repeatCount):
- self._attributes['repeatCount'] = repeatCount
- def get_repeatCount(self):
- return self._attributes.get('repeatCount')
-
- def set_repeatDur(self, repeatDur):
- self._attributes['repeatDur'] = repeatDur
- def get_repeatDur(self):
- return self._attributes.get('repeatDur')
-
- def set_fill(self, fill):
- self._attributes['fill'] = fill
- def get_fill(self):
- return self._attributes.get('fill')
-
-class animationValueAttrib:
- """
- The animationValueAttrib class defines the animationValue.attrib attribute set.
- """
- def set_calcMode(self, calcMode):
- self._attributes['calcMode'] = calcMode
- def get_calcMode(self):
- return self._attributes.get('calcMode')
-
- def set_values(self, values):
- self._attributes['values'] = values
- def get_values(self):
- return self._attributes.get('values')
-
- def set_keyTimes(self, keyTimes):
- self._attributes['keyTimes'] = keyTimes
- def get_keyTimes(self):
- return self._attributes.get('keyTimes')
-
- def set_keySplines(self, keySplines):
- self._attributes['keySplines'] = keySplines
- def get_keySplines(self):
- return self._attributes.get('keySplines')
-
- def set_from(self, fromField):
- self._attributes['from'] = fromField
- def get_from(self):
- return self._attributes.get('from')
-
- def set_to(self, toField):
- self._attributes['to'] = toField
- def get_to(self):
- return self._attributes.get('to')
-
- def set_by(self, by):
- self._attributes['by'] = by
- def get_by(self):
- return self._attributes.get('by')
-
-class animationAdditionAttrib:
- """
- The animationAdditionAttrib class defines the animationAddition.attrib attribute set.
- """
- def set_additive(self, additive):
- self._attributes['additive'] = additive
- def get_additive(self):
- return self._attributes.get('additive')
-
- def set_accumulate(self, accumulate):
- self._attributes['accumulate'] = accumulate
- def get_accumulate(self):
- return self._attributes.get('accumulate')
-
-class animationEventsAttrib:
- """
- The animationEventsAttrib class defines the animationEvents.attrib attribute set.
- """
- def set_onbegin(self, onbegin):
- self._attributes['onbegin'] = onbegin
- def get_onbegin(self):
- return self._attributes.get('onbegin')
-
- def set_onend(self, onend):
- self._attributes['onend'] = onend
- def get_onend(self):
- return self._attributes.get('onend')
-
- def set_onrepeat(self, onrepeat):
- self._attributes['onrepeat'] = onrepeat
- def get_onrepeat(self):
- return self._attributes.get('onrepeat')
-
- def set_onload(self, onload):
- self._attributes['onload'] = onload
- def get_onload(self):
- return self._attributes.get('onload')
-##############################################
-# animation Elements
-##############################################
-class animate(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, animationEventsAttrib, animationAttrib, animationAttributeAttrib, animationTimingAttrib, animationValueAttrib, animationAdditionAttrib):
- """
- Class representing the animate element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'animate')
- self.setKWARGS(**kwargs)
-
-class set(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, animationEventsAttrib, animationAttrib, animationAttributeAttrib, animationTimingAttrib):
- """
- Class representing the set element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'set')
- self.setKWARGS(**kwargs)
-
- def set_to(self, toField):
- self._attributes['to'] = toField
- def get_to(self):
- return self._attributes.get('to')
-
-class animateMotion(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, animationEventsAttrib, animationAttrib, animationTimingAttrib, animationValueAttrib, animationAdditionAttrib):
- """
- Class representing the animateMotion element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'animateMotion')
- self.setKWARGS(**kwargs)
-
- def set_path(self, path):
- self._attributes['path'] = path
- def get_path(self):
- return self._attributes.get('path')
-
- def set_keyPoints(self, keyPoints):
- self._attributes['keyPoints'] = keyPoints
- def get_keyPoints(self):
- return self._attributes.get('keyPoints')
-
- def set_rotate(self, rotate):
- self._attributes['rotate'] = rotate
- def get_rotate(self):
- return self._attributes.get('rotate')
-
- def set_origin(self, origin):
- self._attributes['origin'] = origin
- def get_origin(self):
- return self._attributes.get('origin')
-
-class animateTransform(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, animationEventsAttrib, animationAttrib, animationAttributeAttrib, animationTimingAttrib, animationValueAttrib, animationAdditionAttrib):
- """
- Class representing the animateTransform element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'animateTransform')
- self.setKWARGS(**kwargs)
-
- def set_type(self, type):
- self._attributes['type'] = type
- def get_type(self):
- return self._attributes.get('type')
-
-class animateColor(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, animationEventsAttrib, animationAttrib, animationAttributeAttrib, animationTimingAttrib, animationValueAttrib, animationAdditionAttrib):
- """
- Class representing the animateColor element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'animateColor')
- self.setKWARGS(**kwargs)
-
-class mpath(BaseShape, CoreAttrib, XLinkAttrib, ExternalAttrib):
- """
- Class representing the animateColor element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'mpath')
- self.setKWARGS(**kwargs)
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from .attributes import *
+from .core import BaseShape, BaseElement
+
+#####################################################
+# Attribute sets for animations
+# animation elements see below
+#####################################################
+class animationAttrib(XLinkAttrib):
+ """
+ The animationAttrib class defines the animation.attrib attribute set.
+ """
+
+class animationAttributeAttrib:
+ """
+ The animationAttributeAttrib class defines the animationAttribute.attrib attribute set.
+ """
+ def set_attributeName(self, attributeName):
+ self._attributes['attributeName'] = attributeName
+ def get_attributeName(self):
+ return self._attributes.get('attributeName')
+
+ def set_attributeType(self, attributeType):
+ self._attributes['attributeType'] = attributeType
+ def get_attributeType(self):
+ return self._attributes.get('attributeType')
+
+class animationTimingAttrib:
+ """
+ The animationTimingAttrib class defines the animationTiming.attrib attribute set.
+ """
+ def set_begin(self, begin):
+ self._attributes['begin'] = begin
+ def get_begin(self):
+ return self._attributes.get('begin')
+
+ def set_dur(self, dur):
+ self._attributes['dur'] = dur
+ def get_dur(self):
+ return self._attributes.get('dur')
+
+ def set_end(self, end):
+ self._attributes['end'] = end
+ def get_end(self):
+ return self._attributes.get('end')
+
+ def set_min(self, min):
+ self._attributes['min'] = min
+ def get_min(self):
+ return self._attributes.get('min')
+
+ def set_max(self, max):
+ self._attributes['max'] = max
+ def get_max(self):
+ return self._attributes.get('max')
+
+ def set_restart(self, restart):
+ self._attributes['restart'] = restart
+ def get_restart(self):
+ return self._attributes.get('restart')
+
+ def set_repeatCount(self, repeatCount):
+ self._attributes['repeatCount'] = repeatCount
+ def get_repeatCount(self):
+ return self._attributes.get('repeatCount')
+
+ def set_repeatDur(self, repeatDur):
+ self._attributes['repeatDur'] = repeatDur
+ def get_repeatDur(self):
+ return self._attributes.get('repeatDur')
+
+ def set_fill(self, fill):
+ self._attributes['fill'] = fill
+ def get_fill(self):
+ return self._attributes.get('fill')
+
+class animationValueAttrib:
+ """
+ The animationValueAttrib class defines the animationValue.attrib attribute set.
+ """
+ def set_calcMode(self, calcMode):
+ self._attributes['calcMode'] = calcMode
+ def get_calcMode(self):
+ return self._attributes.get('calcMode')
+
+ def set_values(self, values):
+ self._attributes['values'] = values
+ def get_values(self):
+ return self._attributes.get('values')
+
+ def set_keyTimes(self, keyTimes):
+ self._attributes['keyTimes'] = keyTimes
+ def get_keyTimes(self):
+ return self._attributes.get('keyTimes')
+
+ def set_keySplines(self, keySplines):
+ self._attributes['keySplines'] = keySplines
+ def get_keySplines(self):
+ return self._attributes.get('keySplines')
+
+ def set_from(self, fromField):
+ self._attributes['from'] = fromField
+ def get_from(self):
+ return self._attributes.get('from')
+
+ def set_to(self, toField):
+ self._attributes['to'] = toField
+ def get_to(self):
+ return self._attributes.get('to')
+
+ def set_by(self, by):
+ self._attributes['by'] = by
+ def get_by(self):
+ return self._attributes.get('by')
+
+class animationAdditionAttrib:
+ """
+ The animationAdditionAttrib class defines the animationAddition.attrib attribute set.
+ """
+ def set_additive(self, additive):
+ self._attributes['additive'] = additive
+ def get_additive(self):
+ return self._attributes.get('additive')
+
+ def set_accumulate(self, accumulate):
+ self._attributes['accumulate'] = accumulate
+ def get_accumulate(self):
+ return self._attributes.get('accumulate')
+
+class animationEventsAttrib:
+ """
+ The animationEventsAttrib class defines the animationEvents.attrib attribute set.
+ """
+ def set_onbegin(self, onbegin):
+ self._attributes['onbegin'] = onbegin
+ def get_onbegin(self):
+ return self._attributes.get('onbegin')
+
+ def set_onend(self, onend):
+ self._attributes['onend'] = onend
+ def get_onend(self):
+ return self._attributes.get('onend')
+
+ def set_onrepeat(self, onrepeat):
+ self._attributes['onrepeat'] = onrepeat
+ def get_onrepeat(self):
+ return self._attributes.get('onrepeat')
+
+ def set_onload(self, onload):
+ self._attributes['onload'] = onload
+ def get_onload(self):
+ return self._attributes.get('onload')
+##############################################
+# animation Elements
+##############################################
+class animate(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, animationEventsAttrib, animationAttrib, animationAttributeAttrib, animationTimingAttrib, animationValueAttrib, animationAdditionAttrib):
+ """
+ Class representing the animate element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'animate')
+ self.setKWARGS(**kwargs)
+
+class set(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, animationEventsAttrib, animationAttrib, animationAttributeAttrib, animationTimingAttrib):
+ """
+ Class representing the set element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'set')
+ self.setKWARGS(**kwargs)
+
+ def set_to(self, toField):
+ self._attributes['to'] = toField
+ def get_to(self):
+ return self._attributes.get('to')
+
+class animateMotion(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, animationEventsAttrib, animationAttrib, animationTimingAttrib, animationValueAttrib, animationAdditionAttrib):
+ """
+ Class representing the animateMotion element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'animateMotion')
+ self.setKWARGS(**kwargs)
+
+ def set_path(self, path):
+ self._attributes['path'] = path
+ def get_path(self):
+ return self._attributes.get('path')
+
+ def set_keyPoints(self, keyPoints):
+ self._attributes['keyPoints'] = keyPoints
+ def get_keyPoints(self):
+ return self._attributes.get('keyPoints')
+
+ def set_rotate(self, rotate):
+ self._attributes['rotate'] = rotate
+ def get_rotate(self):
+ return self._attributes.get('rotate')
+
+ def set_origin(self, origin):
+ self._attributes['origin'] = origin
+ def get_origin(self):
+ return self._attributes.get('origin')
+
+class animateTransform(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, animationEventsAttrib, animationAttrib, animationAttributeAttrib, animationTimingAttrib, animationValueAttrib, animationAdditionAttrib):
+ """
+ Class representing the animateTransform element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'animateTransform')
+ self.setKWARGS(**kwargs)
+
+ def set_type(self, type):
+ self._attributes['type'] = type
+ def get_type(self):
+ return self._attributes.get('type')
+
+class animateColor(BaseShape, CoreAttrib, ConditionalAttrib, ExternalAttrib, animationEventsAttrib, animationAttrib, animationAttributeAttrib, animationTimingAttrib, animationValueAttrib, animationAdditionAttrib):
+ """
+ Class representing the animateColor element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'animateColor')
+ self.setKWARGS(**kwargs)
+
+class mpath(BaseShape, CoreAttrib, XLinkAttrib, ExternalAttrib):
+ """
+ Class representing the animateColor element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'mpath')
+ self.setKWARGS(**kwargs)
Only in pysvg-0.2.2b/src/pysvg: animate.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/builders.py pysvg-0.2.2b/src/pysvg/builders.py
--- pysvg-0.2.2b.orig/src/pysvg/builders.py 2012-11-15 14:41:12.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/builders.py 2016-07-15 11:11:21.261962824 -0500
@@ -1,359 +1,359 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from pysvg.animate import *
-from pysvg.filter import *
-from pysvg.gradient import *
-from pysvg.linking import *
-from pysvg.script import *
-from pysvg.shape import *
-from pysvg.structure import *
-from pysvg.style import *
-from pysvg.text import *
-
-class ShapeBuilder:
- """
- Helper class that creates commonly used objects and shapes with predefined styles and
- few but often used parameters. Used to avoid more complex coding for common tasks.
- """
-
- def createCircle(self, cx, cy, r, strokewidth=1, stroke='black', fill='none'):
- """
- Creates a circle
- @type cx: string or int
- @param cx: starting x-coordinate
- @type cy: string or int
- @param cy: starting y-coordinate
- @type r: string or int
- @param r: radius
- @type strokewidth: string or int
- @param strokewidth: width of the pen used to draw
- @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
- @param stroke: color with which to draw the outer limits
- @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
- @param fill: color with which to fill the element (default: no filling)
- @return: a circle object
- """
- style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke}
- myStyle = StyleBuilder(style_dict)
- c = circle(cx, cy, r)
- c.set_style(myStyle.getStyle())
- return c
-
- def createEllipse(self, cx, cy, rx, ry, strokewidth=1, stroke='black', fill='none'):
- """
- Creates an ellipse
- @type cx: string or int
- @param cx: starting x-coordinate
- @type cy: string or int
- @param cy: starting y-coordinate
- @type rx: string or int
- @param rx: radius in x direction
- @type ry: string or int
- @param ry: radius in y direction
- @type strokewidth: string or int
- @param strokewidth: width of the pen used to draw
- @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
- @param stroke: color with which to draw the outer limits
- @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
- @param fill: color with which to fill the element (default: no filling)
- @return: an ellipse object
- """
- style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke}
- myStyle = StyleBuilder(style_dict)
- e = ellipse(cx, cy, rx, ry)
- e.set_style(myStyle.getStyle())
- return e
-
- def createRect(self, x, y, width, height, rx=None, ry=None, strokewidth=1, stroke='black', fill='none'):
- """
- Creates a Rectangle
- @type x: string or int
- @param x: starting x-coordinate
- @type y: string or int
- @param y: starting y-coordinate
- @type width: string or int
- @param width: width of the rectangle
- @type height: string or int
- @param height: height of the rectangle
- @type rx: string or int
- @param rx: For rounded rectangles, the x-axis radius of the ellipse used to round off the corners of the rectangle.
- @type ry: string or int
- @param ry: For rounded rectangles, the y-axis radius of the ellipse used to round off the corners of the rectangle.
- @type strokewidth: string or int
- @param strokewidth: width of the pen used to draw
- @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
- @param stroke: color with which to draw the outer limits
- @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
- @param fill: color with which to fill the element (default: no filling)
- @return: a rect object
- """
- style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke}
- myStyle = StyleBuilder(style_dict)
- r = rect(x, y, width, height, rx, ry)
- r.set_style(myStyle.getStyle())
- return r
-
- def createPolygon(self, points, strokewidth=1, stroke='black', fill='none'):
- """
- Creates a Polygon
- @type points: string in the form "x1,y1 x2,y2 x3,y3"
- @param points: all points relevant to the polygon
- @type strokewidth: string or int
- @param strokewidth: width of the pen used to draw
- @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
- @param stroke: color with which to draw the outer limits
- @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
- @param fill: color with which to fill the element (default: no filling)
- @return: a polygon object
- """
- style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke}
- myStyle = StyleBuilder(style_dict)
- p = polygon(points=points)
- p.set_style(myStyle.getStyle())
- return p
-
- def createPolyline(self, points, strokewidth=1, stroke='black'):
- """
- Creates a Polyline
- @type points: string in the form "x1,y1 x2,y2 x3,y3"
- @param points: all points relevant to the polygon
- @type strokewidth: string or int
- @param strokewidth: width of the pen used to draw
- @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
- @param stroke: color with which to draw the outer limits
- @return: a polyline object
- """
- style_dict = {'fill':'none', 'stroke-width':strokewidth, 'stroke':stroke}
- myStyle = StyleBuilder(style_dict)
- p = polyline(points=points)
- p.set_style(myStyle.getStyle())
- return p
-
-
- def createLine(self, x1, y1, x2, y2, strokewidth=1, stroke="black"):
- """
- Creates a line
- @type x1: string or int
- @param x1: starting x-coordinate
- @type y1: string or int
- @param y1: starting y-coordinate
- @type x2: string or int
- @param x2: ending x-coordinate
- @type y2: string or int
- @param y2: ending y-coordinate
- @type strokewidth: string or int
- @param strokewidth: width of the pen used to draw
- @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
- @param stroke: color with which to draw the outer limits
- @return: a line object
- """
- style_dict = {'stroke-width':strokewidth, 'stroke':stroke}
- myStyle = StyleBuilder(style_dict)
- l = line(x1, y1, x2, y2)
- l.set_style(myStyle.getStyle())
- return l
-
- def convertTupleArrayToPoints(self, arrayOfPointTuples):
- """Method used to convert an array of tuples (x,y) into a string
- suitable for createPolygon or createPolyline
- @type arrayOfPointTuples: An array containing tuples eg.[(x1,y1),(x2,y2]
- @param arrayOfPointTuples: All points needed to create the shape
- @return a string in the form "x1,y1 x2,y2 x3,y3"
- """
- points = ""
- for tuple in arrayOfPointTuples:
- points += str(tuple[0]) + "," + str(tuple[1]) + " "
- return points
-
-
-
-######################################################################
-# Style Builder. Utility class to create styles for your shapes etc.
-######################################################################
-class StyleBuilder:
- """
- Class to create a style string for those not familiar with svg attribute names.
- How to use it:
- 1) create an instance of StyleBuilder (builder=....)
- 2) set the attributes you want to have
- 3) create the shape (element) you want
- 4) call set_style on the element with "builder.getStyle()" as parameter
- """
- def __init__(self, aStyle_dict=None):
- if aStyle_dict == None:
- self.style_dict = {}
- else:
- self.style_dict = aStyle_dict
-
-
- # tested below
- def setFontFamily(self, fontfamily):
- self.style_dict["font-family"] = fontfamily
-
- def setFontSize(self, fontsize):
- self.style_dict["font-size"] = fontsize
-
- def setFontStyle(self, fontstyle):
- self.style_dict["font-style"] = fontstyle
-
- def setFontWeight(self, fontweight):
- self.style_dict["font-weight"] = fontweight
-
- #tested
- def setFilling(self, fill):
- self.style_dict["fill"] = fill
-
- def setFillOpacity(self, fillopacity):
- self.style_dict["fill-opacity"] = fillopacity
-
- def setFillRule(self, fillrule):
- self.style_dict["fill-rule"] = fillrule
-
- def setStrokeWidth(self, strokewidth):
- self.style_dict["stroke-width"] = strokewidth
-
- def setStroke(self, stroke):
- self.style_dict["stroke"] = stroke
-
- #untested below
- def setStrokeDashArray(self, strokedasharray):
- self.style_dict["stroke-dasharray"] = strokedasharray
- def setStrokeDashOffset(self, strokedashoffset):
- self.style_dict["stroke-dashoffset"] = strokedashoffset
- def setStrokeLineCap(self, strikelinecap):
- self.style_dict["stroke-linecap"] = strikelinecap
- def setStrokeLineJoin(self, strokelinejoin):
- self.style_dict["stroke-linejoin"] = strokelinejoin
- def setStrokeMiterLimit(self, strokemiterlimit):
- self.style_dict["stroke-miterlimit"] = strokemiterlimit
- def setStrokeOpacity(self, strokeopacity):
- self.style_dict["stroke-opacity"] = strokeopacity
-
-
- #is used to provide a potential indirect value (currentColor) for the 'fill', 'stroke', 'stop-color' properties.
- def setCurrentColor(self, color):
- self.style_dict["color"] = color
-
- # Gradient properties:
- def setStopColor(self, stopcolor):
- self.style_dict["stop-color"] = stopcolor
-
- def setStopOpacity(self, stopopacity):
- self.style_dict["stop-opacity"] = stopopacity
-
- #rendering properties
- def setColorRendering(self, colorrendering):
- self.style_dict["color-rendering"] = colorrendering
-
- def setImageRendering(self, imagerendering):
- self.style_dict["image-rendering"] = imagerendering
-
- def setShapeRendering(self, shaperendering):
- self.style_dict["shape-rendering"] = shaperendering
-
- def setTextRendering(self, textrendering):
- self.style_dict["text-rendering"] = textrendering
-
- def setSolidColor(self, solidcolor):
- self.style_dict["solid-color"] = solidcolor
-
- def setSolidOpacity(self, solidopacity):
- self.style_dict["solid-opacity"] = solidopacity
-
- #Viewport properties
- def setVectorEffect(self, vectoreffect):
- self.style_dict["vector-effect"] = vectoreffect
-
- def setViewPortFill(self, viewportfill):
- self.style_dict["viewport-fill"] = viewportfill
-
- def setViewPortOpacity(self, viewportfillopacity):
- self.style_dict["viewport-fill_opacity"] = viewportfillopacity
-
- # Text properties
- def setDisplayAlign(self, displayalign):
- self.style_dict["display-align"] = displayalign
-
- def setLineIncrement(self, lineincrement):
- self.style_dict["line-increment"] = lineincrement
-
- def setTextAnchor(self, textanchor):
- self.style_dict["text-anchor"] = textanchor
-
- #def getStyleDict(self):
- # return self.style_dict
-
-
- def getStyle(self):
- string = ''#style="'
- for key, value in self.style_dict.items():
- if value <> None and value <> '':
- string += str(key) + ':' + str(value) + '; '
- return string
-
-######################################################################
-# Transform Builder. Utility class to create transformations for your shapes etc.
-######################################################################
-class TransformBuilder:
- """
- Class to create a transform string for those not familiar with svg attribute names.
- How to use it:
- 1) create an instance of TransformBuilder (builder=....)
- 2) set the attributes you want to have
- 3) create the shape (element) you want
- 4) call set_transform on the element with "builder.getTransform()" as parameter
- """
- def __init__(self):
- self.transform_dict = {}
-
- #def setMatrix(self, matrix):
- # self.transform_dict["matrix"] = 'matrix(%s)' % matrix
-
- def setMatrix(self, a, b, c, d, e, f):
- self.transform_dict["matrix"] = 'matrix(%s %s %s %s %s %s)' % (a, b, c, d, e, f)
-
- def setRotation(self, rotate):
- self.transform_dict["rotate"] = 'rotate(%s)' % rotate
-
- #def setRotation(self, rotation, cx=None, cy=None):
- # if cx != None and cy != None:
- # self.transform_dict["rotate"] = 'rotate(%s %s %s)' % (rotation, cx, cy)
- # else:
- # self.transform_dict["rotate"] = 'rotate(%s)' % (rotation)
-
- def setTranslation(self, translate):
- self.transform_dict["translate"] = 'translate(%s)' % (translate)
-
- #def setTranslation(self, x, y=0):
- # self.transform_dict["translate"] = 'translate(%s %s)' % (x, y)
-
- #def setScaling(self, scale):
- # self.transform_dict["scale"] = 'scale(%s)' % (scale)
-
- def setScaling(self, x=None, y=None):
- if x == None and y != None:
- x = y
- elif x != None and y == None:
- y = x
- self.transform_dict["scale"] = 'scale(%s %s)' % (x, y)
-
- def setSkewY(self, skewY):
- self.transform_dict["skewY"] = 'skewY(%s)' % (skewY)
-
- def setSkewX(self, skewX):
- self.transform_dict["skewX"] = 'skewX(%s)' % (skewX)
-
- #def getTransformDict(self):
- # return self.transform_dict
-
- def getTransform(self):
- string = ''#style="'
- for key, value in self.transform_dict.items():
- if value <> None and value <> '':
- #string+=str(key)+':'+str(value)+'; '
- string += str(value) + ' '
- return string
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from pysvg.animate import *
+from pysvg.filter import *
+from pysvg.gradient import *
+from pysvg.linking import *
+from pysvg.script import *
+from pysvg.shape import *
+from pysvg.structure import *
+from pysvg.style import *
+from pysvg.text import *
+
+class ShapeBuilder:
+ """
+ Helper class that creates commonly used objects and shapes with predefined styles and
+ few but often used parameters. Used to avoid more complex coding for common tasks.
+ """
+
+ def createCircle(self, cx, cy, r, strokewidth=1, stroke='black', fill='none'):
+ """
+ Creates a circle
+ @type cx: string or int
+ @param cx: starting x-coordinate
+ @type cy: string or int
+ @param cy: starting y-coordinate
+ @type r: string or int
+ @param r: radius
+ @type strokewidth: string or int
+ @param strokewidth: width of the pen used to draw
+ @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
+ @param stroke: color with which to draw the outer limits
+ @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
+ @param fill: color with which to fill the element (default: no filling)
+ @return: a circle object
+ """
+ style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke}
+ myStyle = StyleBuilder(style_dict)
+ c = circle(cx, cy, r)
+ c.set_style(myStyle.getStyle())
+ return c
+
+ def createEllipse(self, cx, cy, rx, ry, strokewidth=1, stroke='black', fill='none'):
+ """
+ Creates an ellipse
+ @type cx: string or int
+ @param cx: starting x-coordinate
+ @type cy: string or int
+ @param cy: starting y-coordinate
+ @type rx: string or int
+ @param rx: radius in x direction
+ @type ry: string or int
+ @param ry: radius in y direction
+ @type strokewidth: string or int
+ @param strokewidth: width of the pen used to draw
+ @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
+ @param stroke: color with which to draw the outer limits
+ @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
+ @param fill: color with which to fill the element (default: no filling)
+ @return: an ellipse object
+ """
+ style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke}
+ myStyle = StyleBuilder(style_dict)
+ e = ellipse(cx, cy, rx, ry)
+ e.set_style(myStyle.getStyle())
+ return e
+
+ def createRect(self, x, y, width, height, rx=None, ry=None, strokewidth=1, stroke='black', fill='none'):
+ """
+ Creates a Rectangle
+ @type x: string or int
+ @param x: starting x-coordinate
+ @type y: string or int
+ @param y: starting y-coordinate
+ @type width: string or int
+ @param width: width of the rectangle
+ @type height: string or int
+ @param height: height of the rectangle
+ @type rx: string or int
+ @param rx: For rounded rectangles, the x-axis radius of the ellipse used to round off the corners of the rectangle.
+ @type ry: string or int
+ @param ry: For rounded rectangles, the y-axis radius of the ellipse used to round off the corners of the rectangle.
+ @type strokewidth: string or int
+ @param strokewidth: width of the pen used to draw
+ @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
+ @param stroke: color with which to draw the outer limits
+ @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
+ @param fill: color with which to fill the element (default: no filling)
+ @return: a rect object
+ """
+ style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke}
+ myStyle = StyleBuilder(style_dict)
+ r = rect(x, y, width, height, rx, ry)
+ r.set_style(myStyle.getStyle())
+ return r
+
+ def createPolygon(self, points, strokewidth=1, stroke='black', fill='none'):
+ """
+ Creates a Polygon
+ @type points: string in the form "x1,y1 x2,y2 x3,y3"
+ @param points: all points relevant to the polygon
+ @type strokewidth: string or int
+ @param strokewidth: width of the pen used to draw
+ @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
+ @param stroke: color with which to draw the outer limits
+ @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
+ @param fill: color with which to fill the element (default: no filling)
+ @return: a polygon object
+ """
+ style_dict = {'fill':fill, 'stroke-width':strokewidth, 'stroke':stroke}
+ myStyle = StyleBuilder(style_dict)
+ p = polygon(points=points)
+ p.set_style(myStyle.getStyle())
+ return p
+
+ def createPolyline(self, points, strokewidth=1, stroke='black'):
+ """
+ Creates a Polyline
+ @type points: string in the form "x1,y1 x2,y2 x3,y3"
+ @param points: all points relevant to the polygon
+ @type strokewidth: string or int
+ @param strokewidth: width of the pen used to draw
+ @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
+ @param stroke: color with which to draw the outer limits
+ @return: a polyline object
+ """
+ style_dict = {'fill':'none', 'stroke-width':strokewidth, 'stroke':stroke}
+ myStyle = StyleBuilder(style_dict)
+ p = polyline(points=points)
+ p.set_style(myStyle.getStyle())
+ return p
+
+
+ def createLine(self, x1, y1, x2, y2, strokewidth=1, stroke="black"):
+ """
+ Creates a line
+ @type x1: string or int
+ @param x1: starting x-coordinate
+ @type y1: string or int
+ @param y1: starting y-coordinate
+ @type x2: string or int
+ @param x2: ending x-coordinate
+ @type y2: string or int
+ @param y2: ending y-coordinate
+ @type strokewidth: string or int
+ @param strokewidth: width of the pen used to draw
+ @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
+ @param stroke: color with which to draw the outer limits
+ @return: a line object
+ """
+ style_dict = {'stroke-width':strokewidth, 'stroke':stroke}
+ myStyle = StyleBuilder(style_dict)
+ l = line(x1, y1, x2, y2)
+ l.set_style(myStyle.getStyle())
+ return l
+
+ def convertTupleArrayToPoints(self, arrayOfPointTuples):
+ """Method used to convert an array of tuples (x,y) into a string
+ suitable for createPolygon or createPolyline
+ @type arrayOfPointTuples: An array containing tuples eg.[(x1,y1),(x2,y2]
+ @param arrayOfPointTuples: All points needed to create the shape
+ @return a string in the form "x1,y1 x2,y2 x3,y3"
+ """
+ points = ""
+ for tuple in arrayOfPointTuples:
+ points += str(tuple[0]) + "," + str(tuple[1]) + " "
+ return points
+
+
+
+######################################################################
+# Style Builder. Utility class to create styles for your shapes etc.
+######################################################################
+class StyleBuilder:
+ """
+ Class to create a style string for those not familiar with svg attribute names.
+ How to use it:
+ 1) create an instance of StyleBuilder (builder=....)
+ 2) set the attributes you want to have
+ 3) create the shape (element) you want
+ 4) call set_style on the element with "builder.getStyle()" as parameter
+ """
+ def __init__(self, aStyle_dict=None):
+ if aStyle_dict == None:
+ self.style_dict = {}
+ else:
+ self.style_dict = aStyle_dict
+
+
+ # tested below
+ def setFontFamily(self, fontfamily):
+ self.style_dict["font-family"] = fontfamily
+
+ def setFontSize(self, fontsize):
+ self.style_dict["font-size"] = fontsize
+
+ def setFontStyle(self, fontstyle):
+ self.style_dict["font-style"] = fontstyle
+
+ def setFontWeight(self, fontweight):
+ self.style_dict["font-weight"] = fontweight
+
+ #tested
+ def setFilling(self, fill):
+ self.style_dict["fill"] = fill
+
+ def setFillOpacity(self, fillopacity):
+ self.style_dict["fill-opacity"] = fillopacity
+
+ def setFillRule(self, fillrule):
+ self.style_dict["fill-rule"] = fillrule
+
+ def setStrokeWidth(self, strokewidth):
+ self.style_dict["stroke-width"] = strokewidth
+
+ def setStroke(self, stroke):
+ self.style_dict["stroke"] = stroke
+
+ #untested below
+ def setStrokeDashArray(self, strokedasharray):
+ self.style_dict["stroke-dasharray"] = strokedasharray
+ def setStrokeDashOffset(self, strokedashoffset):
+ self.style_dict["stroke-dashoffset"] = strokedashoffset
+ def setStrokeLineCap(self, strikelinecap):
+ self.style_dict["stroke-linecap"] = strikelinecap
+ def setStrokeLineJoin(self, strokelinejoin):
+ self.style_dict["stroke-linejoin"] = strokelinejoin
+ def setStrokeMiterLimit(self, strokemiterlimit):
+ self.style_dict["stroke-miterlimit"] = strokemiterlimit
+ def setStrokeOpacity(self, strokeopacity):
+ self.style_dict["stroke-opacity"] = strokeopacity
+
+
+ #is used to provide a potential indirect value (currentColor) for the 'fill', 'stroke', 'stop-color' properties.
+ def setCurrentColor(self, color):
+ self.style_dict["color"] = color
+
+ # Gradient properties:
+ def setStopColor(self, stopcolor):
+ self.style_dict["stop-color"] = stopcolor
+
+ def setStopOpacity(self, stopopacity):
+ self.style_dict["stop-opacity"] = stopopacity
+
+ #rendering properties
+ def setColorRendering(self, colorrendering):
+ self.style_dict["color-rendering"] = colorrendering
+
+ def setImageRendering(self, imagerendering):
+ self.style_dict["image-rendering"] = imagerendering
+
+ def setShapeRendering(self, shaperendering):
+ self.style_dict["shape-rendering"] = shaperendering
+
+ def setTextRendering(self, textrendering):
+ self.style_dict["text-rendering"] = textrendering
+
+ def setSolidColor(self, solidcolor):
+ self.style_dict["solid-color"] = solidcolor
+
+ def setSolidOpacity(self, solidopacity):
+ self.style_dict["solid-opacity"] = solidopacity
+
+ #Viewport properties
+ def setVectorEffect(self, vectoreffect):
+ self.style_dict["vector-effect"] = vectoreffect
+
+ def setViewPortFill(self, viewportfill):
+ self.style_dict["viewport-fill"] = viewportfill
+
+ def setViewPortOpacity(self, viewportfillopacity):
+ self.style_dict["viewport-fill_opacity"] = viewportfillopacity
+
+ # Text properties
+ def setDisplayAlign(self, displayalign):
+ self.style_dict["display-align"] = displayalign
+
+ def setLineIncrement(self, lineincrement):
+ self.style_dict["line-increment"] = lineincrement
+
+ def setTextAnchor(self, textanchor):
+ self.style_dict["text-anchor"] = textanchor
+
+ #def getStyleDict(self):
+ # return self.style_dict
+
+
+ def getStyle(self):
+ string = ''#style="'
+ for key, value in list(self.style_dict.items()):
+ if value != None and value != '':
+ string += str(key) + ':' + str(value) + '; '
+ return string
+
+######################################################################
+# Transform Builder. Utility class to create transformations for your shapes etc.
+######################################################################
+class TransformBuilder:
+ """
+ Class to create a transform string for those not familiar with svg attribute names.
+ How to use it:
+ 1) create an instance of TransformBuilder (builder=....)
+ 2) set the attributes you want to have
+ 3) create the shape (element) you want
+ 4) call set_transform on the element with "builder.getTransform()" as parameter
+ """
+ def __init__(self):
+ self.transform_dict = {}
+
+ #def setMatrix(self, matrix):
+ # self.transform_dict["matrix"] = 'matrix(%s)' % matrix
+
+ def setMatrix(self, a, b, c, d, e, f):
+ self.transform_dict["matrix"] = 'matrix(%s %s %s %s %s %s)' % (a, b, c, d, e, f)
+
+ def setRotation(self, rotate):
+ self.transform_dict["rotate"] = 'rotate(%s)' % rotate
+
+ #def setRotation(self, rotation, cx=None, cy=None):
+ # if cx != None and cy != None:
+ # self.transform_dict["rotate"] = 'rotate(%s %s %s)' % (rotation, cx, cy)
+ # else:
+ # self.transform_dict["rotate"] = 'rotate(%s)' % (rotation)
+
+ def setTranslation(self, translate):
+ self.transform_dict["translate"] = 'translate(%s)' % (translate)
+
+ #def setTranslation(self, x, y=0):
+ # self.transform_dict["translate"] = 'translate(%s %s)' % (x, y)
+
+ #def setScaling(self, scale):
+ # self.transform_dict["scale"] = 'scale(%s)' % (scale)
+
+ def setScaling(self, x=None, y=None):
+ if x == None and y != None:
+ x = y
+ elif x != None and y == None:
+ y = x
+ self.transform_dict["scale"] = 'scale(%s %s)' % (x, y)
+
+ def setSkewY(self, skewY):
+ self.transform_dict["skewY"] = 'skewY(%s)' % (skewY)
+
+ def setSkewX(self, skewX):
+ self.transform_dict["skewX"] = 'skewX(%s)' % (skewX)
+
+ #def getTransformDict(self):
+ # return self.transform_dict
+
+ def getTransform(self):
+ string = ''#style="'
+ for key, value in list(self.transform_dict.items()):
+ if value != None and value != '':
+ #string+=str(key)+':'+str(value)+'; '
+ string += str(value) + ' '
+ return string
Only in pysvg-0.2.2b/src/pysvg: builders.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/core.py pysvg-0.2.2b/src/pysvg/core.py
--- pysvg-0.2.2b.orig/src/pysvg/core.py 2012-11-06 09:18:58.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/core.py 2016-07-15 11:11:21.367962235 -0500
@@ -1,265 +1,265 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from attributes import CoreAttrib, ConditionalAttrib, StyleAttrib, GraphicalEventsAttrib, PaintAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib
-import codecs
-
-class BaseElement:
- """
- This is the base class for all svg elements like title etc. It provides common functionality.
- It should NOT be directly used by anyone.
- """
- def __init__(self, elementName):
- """
- initializes the object
- @type elementName: string
- @param elementName: name of the element (used for the xml tag)
- """
- self._elementName=elementName
- self._attributes={} #key value
- self._textContent=""
- self._subElements=[]
-
- def appendTextContent(self,text):
- self.addElement(TextContent(text))
-
- def addElement(self,element):
- self._subElements.append(element)
-
- def getElementAt(self,pos):
- """ returns the element at a specific position within this svg
- """
- return self._subElements[pos]
-
- def getAllElements(self):
- """ returns all elements contained within the top level element list of this element
- """
- return self._subElements
-
- def getAllElementsOfHirarchy(self):
- """ returns ALL elements of the complete hirarchy as a flat list
- """
- allElements=[]
- for element in self.getAllElements():
- allElements.append(element)
- if isinstance(element, BaseElement):
- allElements.extend(element.getAllElementsOfHirarchy())
- return allElements
-
- def getElementByID(self, id):
- """ returns an element with the specific id and the position of that element within the svg elements array
- """
- pos=0
- for element in self._subElements:
- if element.get_id()==id:
- return (element,pos)
- pos+=1
-
- def getElementsByType(self, type):
- """
- retrieves all Elements that are of type type
- @type type: class
- @param type: type of the element
- """
- foundElements=[]
- for element in self.getAllElementsOfHirarchy():
- if isinstance(element, type):
- foundElements.append(element)
-
- return foundElements
-
- def insertElementAt(self, element, pos):
- return self._subElements.insert(pos, element)
-
-
- def getXML(self):
- """
- Return a XML representation of the current element.
- This function can be used for debugging purposes. It is also used by getXML in SVG
-
- @return: the representation of the current element as an xml string
- """
- xml='<'+self._elementName+' '
- for key,value in self._attributes.items():
- if value != None:
- xml+=key+'="'+self.quote_attrib(str(value))+'" '
- if len(self._subElements)==0: #self._textContent==None and
- xml+=' />\n'
- else:
- xml+=' >\n'
- #if self._textContent==None:
- for subelement in self._subElements:
- s = subelement.getXML()
- if type(s) != unicode:
- s = str(s)
- xml+=s
- # xml+=str(subelement.getXML())
- #else:
- #if self._textContent!=None:
- # xml+=self._textContent
- xml+='</'+self._elementName+'>\n'
- #print xml
- return xml
-
- #generic methods to set and get atributes (should only be used if something is not supported yet
- def setAttribute(self, attribute_name, attribute_value):
- self._attributes[attribute_name]=attribute_value
-
- def getAttribute(self, attribute_name):
- return self._attributes.get(attribute_name)
-
- def getAttributes(self):
- """ get all atributes of the element
- """
- return self._attributes
-
- def setKWARGS(self, **kwargs):
- """
- Used to set all attributes given in a **kwargs parameter.
- Might throw an Exception if attribute was not found.
- #TODO: check if we should fix this using "setAttribute"
- """
- for key in kwargs.keys():
- #try:
- f = getattr(self,'set_' + key)
- f(kwargs[key])
- #except:
- # print('attribute not found via setter ')
- # self.setAttribute(self, key, kwargs[key])
-
- def wrap_xml(self, xml, encoding ='ISO-8859-1', standalone='no'):
- """
- Method that provides a standard svg header string for a file
- """
- header = '''<?xml version="1.0" encoding="%s" standalone="%s"?>''' %(encoding, standalone)
- return header+xml
-
- def save(self, filename, encoding ='ISO-8859-1', standalone='no'):
- """
- Stores any element in a svg file (including header).
- Calling this method only makes sense if the root element is an svg elemnt
- """
- f = codecs.open(filename, 'w', encoding)
- s = self.wrap_xml(self.getXML(), encoding, standalone)
- #s = s.replace("&", "&")
- f.write(s)
- f.close()
- #f = open(filename, 'w')
- #f.write(self.wrap_xml(self.getXML(), encoding, standalone))
- #f.close()
-
- def quote_attrib(self, inStr):
- """
- Transforms characters between xml notation and python notation.
- """
- s1 = (isinstance(inStr, basestring) and inStr or
- '%s' % inStr)
- s1 = s1.replace('&', '&')
- s1 = s1.replace('<', '<')
- s1 = s1.replace('>', '>')
- if '"' in s1:
- # if "'" in s1:
- s1 = '%s' % s1.replace('"', """)
- # else:
- # s1 = "'%s'" % s1
- #else:
- # s1 = '"%s"' % s1
- return s1
-
-class TextContent:
- """
- Class for the text content of an xml element. Can also include PCDATA
- """
- def __init__(self,content):
- self.content=content
- def setContent(self,content):
- self.content=content
- def getXML(self):
- return self.content
- def get_id(self):
- return None
-
-#--------------------------------------------------------------------------#
-# Below are classes that define attribute sets that pysvg uses for convenience.
-# There exist no corresponding attribute sets in svg.
-# We simply use these classes as containers for often used attributes.
-#--------------------------------------------------------------------------#
-class PointAttrib:
- """
- The PointAttrib class defines x and y.
- """
- def set_x(self, x):
- self._attributes['x']=x
- def get_x(self):
- return self._attributes.get('x')
-
- def set_y(self, y):
- self._attributes['y']=y
- def get_y(self):
- return self._attributes.get('y')
-
-class DeltaPointAttrib:
- """
- The DeltaPointAttrib class defines dx and dy.
- """
- def set_dx(self, dx):
- self._attributes['dx']=dx
- def get_dx(self):
- return self._attributes.get('dx')
-
- def set_dy(self, dy):
- self._attributes['dy']=dy
- def get_dy(self):
- return self._attributes.get('dy')
-
-class PointToAttrib:
- """
- The PointToAttrib class defines x2 and y2.
- """
- def set_x2(self, x2):
- self._attributes['x2']=x2
- def get_x2(self):
- return self._attributes.get('x2')
-
- def set_y2(self, y2):
- self._attributes['y2']=y2
- def get_y2(self):
- return self._attributes.get('y2')
-
-class DimensionAttrib:
- """
- The DimensionAttrib class defines height and width.
- """
- def set_height(self, height):
- self._attributes['height']=height
-
- def get_height(self):
- return self._attributes.get('height')
-
- def set_width(self, width):
- self._attributes['width']=width
-
- def get_width(self):
- return self._attributes.get('width')
-
-class RotateAttrib:
- """
- The RotateAttrib class defines rotation.
- """
- def set_rotate(self, rotate):
- self._attributes['rotate']=rotate
-
- def get_rotate(self):
- return self._attributes.get('rotate')
-
-class BaseShape(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, GraphicalEventsAttrib, PaintAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib):
- """
- Baseclass for all shapes. Do not use this class directly. There is no svg element for it
- """
- def set_transform(self, transform):
- self._attributes['transform']=transform
- def get_transform(self):
- return self._attributes.get('transform')
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from .attributes import CoreAttrib, ConditionalAttrib, StyleAttrib, GraphicalEventsAttrib, PaintAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib
+import codecs
+
+class BaseElement:
+ """
+ This is the base class for all svg elements like title etc. It provides common functionality.
+ It should NOT be directly used by anyone.
+ """
+ def __init__(self, elementName):
+ """
+ initializes the object
+ @type elementName: string
+ @param elementName: name of the element (used for the xml tag)
+ """
+ self._elementName=elementName
+ self._attributes={} #key value
+ self._textContent=""
+ self._subElements=[]
+
+ def appendTextContent(self,text):
+ self.addElement(TextContent(text))
+
+ def addElement(self,element):
+ self._subElements.append(element)
+
+ def getElementAt(self,pos):
+ """ returns the element at a specific position within this svg
+ """
+ return self._subElements[pos]
+
+ def getAllElements(self):
+ """ returns all elements contained within the top level element list of this element
+ """
+ return self._subElements
+
+ def getAllElementsOfHirarchy(self):
+ """ returns ALL elements of the complete hirarchy as a flat list
+ """
+ allElements=[]
+ for element in self.getAllElements():
+ allElements.append(element)
+ if isinstance(element, BaseElement):
+ allElements.extend(element.getAllElementsOfHirarchy())
+ return allElements
+
+ def getElementByID(self, id):
+ """ returns an element with the specific id and the position of that element within the svg elements array
+ """
+ pos=0
+ for element in self._subElements:
+ if element.get_id()==id:
+ return (element,pos)
+ pos+=1
+
+ def getElementsByType(self, type):
+ """
+ retrieves all Elements that are of type type
+ @type type: class
+ @param type: type of the element
+ """
+ foundElements=[]
+ for element in self.getAllElementsOfHirarchy():
+ if isinstance(element, type):
+ foundElements.append(element)
+
+ return foundElements
+
+ def insertElementAt(self, element, pos):
+ return self._subElements.insert(pos, element)
+
+
+ def getXML(self):
+ """
+ Return a XML representation of the current element.
+ This function can be used for debugging purposes. It is also used by getXML in SVG
+
+ @return: the representation of the current element as an xml string
+ """
+ xml='<'+self._elementName+' '
+ for key,value in list(self._attributes.items()):
+ if value != None:
+ xml+=key+'="'+self.quote_attrib(str(value))+'" '
+ if len(self._subElements)==0: #self._textContent==None and
+ xml+=' />\n'
+ else:
+ xml+=' >\n'
+ #if self._textContent==None:
+ for subelement in self._subElements:
+ s = subelement.getXML()
+ if type(s) != str:
+ s = str(s)
+ xml+=s
+ # xml+=str(subelement.getXML())
+ #else:
+ #if self._textContent!=None:
+ # xml+=self._textContent
+ xml+='</'+self._elementName+'>\n'
+ #print xml
+ return xml
+
+ #generic methods to set and get atributes (should only be used if something is not supported yet
+ def setAttribute(self, attribute_name, attribute_value):
+ self._attributes[attribute_name]=attribute_value
+
+ def getAttribute(self, attribute_name):
+ return self._attributes.get(attribute_name)
+
+ def getAttributes(self):
+ """ get all atributes of the element
+ """
+ return self._attributes
+
+ def setKWARGS(self, **kwargs):
+ """
+ Used to set all attributes given in a **kwargs parameter.
+ Might throw an Exception if attribute was not found.
+ #TODO: check if we should fix this using "setAttribute"
+ """
+ for key in list(kwargs.keys()):
+ #try:
+ f = getattr(self,'set_' + key)
+ f(kwargs[key])
+ #except:
+ # print('attribute not found via setter ')
+ # self.setAttribute(self, key, kwargs[key])
+
+ def wrap_xml(self, xml, encoding ='ISO-8859-1', standalone='no'):
+ """
+ Method that provides a standard svg header string for a file
+ """
+ header = '''<?xml version="1.0" encoding="%s" standalone="%s"?>''' %(encoding, standalone)
+ return header+xml
+
+ def save(self, filename, encoding ='ISO-8859-1', standalone='no'):
+ """
+ Stores any element in a svg file (including header).
+ Calling this method only makes sense if the root element is an svg elemnt
+ """
+ f = codecs.open(filename, 'w', encoding)
+ s = self.wrap_xml(self.getXML(), encoding, standalone)
+ #s = s.replace("&", "&")
+ f.write(s)
+ f.close()
+ #f = open(filename, 'w')
+ #f.write(self.wrap_xml(self.getXML(), encoding, standalone))
+ #f.close()
+
+ def quote_attrib(self, inStr):
+ """
+ Transforms characters between xml notation and python notation.
+ """
+ s1 = (isinstance(inStr, str) and inStr or
+ '%s' % inStr)
+ s1 = s1.replace('&', '&')
+ s1 = s1.replace('<', '<')
+ s1 = s1.replace('>', '>')
+ if '"' in s1:
+ # if "'" in s1:
+ s1 = '%s' % s1.replace('"', """)
+ # else:
+ # s1 = "'%s'" % s1
+ #else:
+ # s1 = '"%s"' % s1
+ return s1
+
+class TextContent:
+ """
+ Class for the text content of an xml element. Can also include PCDATA
+ """
+ def __init__(self,content):
+ self.content=content
+ def setContent(self,content):
+ self.content=content
+ def getXML(self):
+ return self.content
+ def get_id(self):
+ return None
+
+#--------------------------------------------------------------------------#
+# Below are classes that define attribute sets that pysvg uses for convenience.
+# There exist no corresponding attribute sets in svg.
+# We simply use these classes as containers for often used attributes.
+#--------------------------------------------------------------------------#
+class PointAttrib:
+ """
+ The PointAttrib class defines x and y.
+ """
+ def set_x(self, x):
+ self._attributes['x']=x
+ def get_x(self):
+ return self._attributes.get('x')
+
+ def set_y(self, y):
+ self._attributes['y']=y
+ def get_y(self):
+ return self._attributes.get('y')
+
+class DeltaPointAttrib:
+ """
+ The DeltaPointAttrib class defines dx and dy.
+ """
+ def set_dx(self, dx):
+ self._attributes['dx']=dx
+ def get_dx(self):
+ return self._attributes.get('dx')
+
+ def set_dy(self, dy):
+ self._attributes['dy']=dy
+ def get_dy(self):
+ return self._attributes.get('dy')
+
+class PointToAttrib:
+ """
+ The PointToAttrib class defines x2 and y2.
+ """
+ def set_x2(self, x2):
+ self._attributes['x2']=x2
+ def get_x2(self):
+ return self._attributes.get('x2')
+
+ def set_y2(self, y2):
+ self._attributes['y2']=y2
+ def get_y2(self):
+ return self._attributes.get('y2')
+
+class DimensionAttrib:
+ """
+ The DimensionAttrib class defines height and width.
+ """
+ def set_height(self, height):
+ self._attributes['height']=height
+
+ def get_height(self):
+ return self._attributes.get('height')
+
+ def set_width(self, width):
+ self._attributes['width']=width
+
+ def get_width(self):
+ return self._attributes.get('width')
+
+class RotateAttrib:
+ """
+ The RotateAttrib class defines rotation.
+ """
+ def set_rotate(self, rotate):
+ self._attributes['rotate']=rotate
+
+ def get_rotate(self):
+ return self._attributes.get('rotate')
+
+class BaseShape(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, GraphicalEventsAttrib, PaintAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib):
+ """
+ Baseclass for all shapes. Do not use this class directly. There is no svg element for it
+ """
+ def set_transform(self, transform):
+ self._attributes['transform']=transform
+ def get_transform(self):
+ return self._attributes.get('transform')
Only in pysvg-0.2.2b/src/pysvg: core.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/filter.py pysvg-0.2.2b/src/pysvg/filter.py
--- pysvg-0.2.2b.orig/src/pysvg/filter.py 2012-11-15 14:36:46.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/filter.py 2016-07-15 11:11:21.609960891 -0500
@@ -1,600 +1,600 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from attributes import *
-from core import BaseElement, DeltaPointAttrib, PointAttrib, DimensionAttrib
-
-class filter(BaseElement, CoreAttrib, XLinkAttrib, ExternalAttrib, StyleAttrib, PresentationAttributes_All, PointAttrib, DimensionAttrib):
- """
- Class representing the filter element of an svg doc.
- """
- def __init__(self, x=None, y=None, width=None, height=None, filterRes=None, filterUnits=None, primitiveUnits=None, **kwargs):
- BaseElement.__init__(self, 'filter')
- self.set_x(x)
- self.set_y(y)
- self.set_height(height)
- self.set_width(width)
- self.set_filterRes(filterRes)
- self.set_filterUnits(filterUnits)
- self.set_primitiveUnits(primitiveUnits)
- self.setKWARGS(**kwargs)
-
- def set_filterUnits(self, filterUnits):
- self._attributes['filterUnits'] = filterUnits
- def get_filterUnits(self):
- return self._attributes.get('filterUnits')
-
- def set_primitiveUnits(self, primitiveUnits):
- self._attributes['primitiveUnits'] = primitiveUnits
- def get_primitiveUnits(self):
- return self._attributes.get('primitiveUnits')
-
- def set_filterRes(self, filterRes):
- self._attributes['filterRes'] = filterRes
- def get_filterRes(self):
- return self._attributes.get('filterRes')
-
-class feComponentTransfer(BaseElement, CoreAttrib, FilterColorAttrib, FilterPrimitiveWithInAttrib):
- """
- Class representing the feComponentTransfer element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'feComponentTransfer')
- self.setKWARGS(**kwargs)
-
-
-class feBlend(feComponentTransfer):
- """
- Class representing the feBlend element of an svg doc.
- """
- def __init__(self, in2=None, mode=None, **kwargs):
- BaseElement.__init__(self, 'feBlend')
- self.set_in2(in2)
- self.set_mode(mode)
- self.setKWARGS(**kwargs)
-
- def set_in2(self, in2):
- self._attributes['in2'] = in2
- def get_in2(self):
- return self._attributes.get('in2')
-
- def set_mode(self, mode):
- self._attributes['mode'] = mode
- def get_mode(self):
- return self._attributes.get('mode')
-
-class feColorMatrix(feComponentTransfer):
- """
- Class representing the feColorMatrix element of an svg doc.
- """
- def __init__(self, type=None, values=None, **kwargs):
- BaseElement.__init__(self, 'feColorMatrix')
- self.set_type(type)
- self.set_values(values)
- self.setKWARGS(**kwargs)
-
- def set_type(self, type):
- self._attributes['type'] = type
- def get_type(self):
- return self._attributes.get('type')
-
- def set_values(self, values):
- self._attributes['values'] = values
- def get_values(self):
- return self._attributes.get('values')
-
-class feComposite(feComponentTransfer):
- """
- Class representing the feComposite element of an svg doc.
- """
- def __init__(self, in2=None, operator=None, k1=None, k2=None, k3=None, k4=None, **kwargs):
- BaseElement.__init__(self, 'feComposite')
- self.set_in2(in2)
- self.set_k1(k1)
- self.set_k2(k2)
- self.set_k3(k3)
- self.set_k4(k4)
- self.set_operator(operator)
- self.setKWARGS(**kwargs)
-
- def set_in2(self, in2):
- self._attributes['in2'] = in2
- def get_in2(self):
- return self._attributes.get('in2')
-
- def set_operator(self, operator):
- self._attributes['operator'] = operator
- def get_operator(self):
- return self._attributes.get('operator')
-
- def set_k1(self, k1):
- self._attributes['k1'] = k1
- def get_k1(self):
- return self._attributes.get('k1')
-
- def set_k2(self, k2):
- self._attributes['k2'] = k2
- def get_k2(self):
- return self._attributes.get('k2')
-
- def set_k3(self, k3):
- self._attributes['k3'] = k3
- def get_k3(self):
- return self._attributes.get('k3')
-
- def set_k4(self, k4):
- self._attributes['k4'] = k4
- def get_k4(self):
- return self._attributes.get('k4')
-
-class feConvolveMatrix(feComponentTransfer):
- """
- Class representing the feConvolveMatrix element of an svg doc.
- """
- def __init__(self, order=None, kernelMatrix=None, divisor=None, bias=None, targetX=None, targetY=None, edgeMode=None, kernelUnitLength=None, preserveAlpha=None, **kwargs):
- BaseElement.__init__(self, 'feConvolveMatrix')
- self.set_order(order)
- self.set_kernelMatrix(kernelMatrix)
- self.set_divisor(divisor)
- self.set_bias(bias)
- self.set_targetX(targetX)
- self.set_targetY(targetY)
- self.set_edgeMode(edgeMode)
- self.set_kernelUnitLength(kernelUnitLength)
- self.set_preserveAlpha(preserveAlpha)
- self.setKWARGS(**kwargs)
-
- def set_order(self, order):
- self._attributes['order'] = order
- def get_order(self):
- return self._attributes.get('order')
-
- def set_kernelMatrix(self, kernelMatrix):
- self._attributes['kernelMatrix'] = kernelMatrix
- def get_kernelMatrix(self):
- return self._attributes.get('kernelMatrix')
-
- def set_divisor(self, divisor):
- self._attributes['divisor'] = divisor
- def get_divisor(self):
- return self._attributes.get('divisor')
-
- def set_bias(self, bias):
- self._attributes['bias'] = bias
- def get_bias(self):
- return self._attributes.get('bias')
-
- def set_targetX(self, targetX):
- self._attributes['targetX'] = targetX
- def get_targetX(self):
- return self._attributes.get('targetX')
-
- def set_targetY(self, targetY):
- self._attributes['targetY'] = targetY
- def get_targetY(self):
- return self._attributes.get('targetY')
-
- def set_edgeMode(self, edgeMode):
- self._attributes['edgeMode'] = edgeMode
- def get_edgeMode(self):
- return self._attributes.get('edgeMode')
-
- def set_kernelUnitLength(self, kernelUnitLength):
- self._attributes['kernelUnitLength'] = kernelUnitLength
- def get_kernelUnitLength(self):
- return self._attributes.get('kernelUnitLength')
-
- def set_preserveAlpha(self, preserveAlpha):
- self._attributes['preserveAlpha'] = preserveAlpha
- def get_preserveAlpha(self):
- return self._attributes.get('preserveAlpha')
-
-class feDiffuseLighting(feComponentTransfer, StyleAttrib, PaintAttrib, PresentationAttributes_LightingEffects):
- """
- Class representing the feDiffuseLighting element of an svg doc.
- """
- def __init__(self, surfaceScale=None, diffuseConstant=None, kernelUnitLength=None , **kwargs):
- BaseElement.__init__(self, 'feDiffuseLighting')
- self.set_surfaceScale(surfaceScale)
- self.set_diffuseConstant(diffuseConstant)
- self.set_kernelUnitLength(kernelUnitLength)
- self.setKWARGS(**kwargs)
-
- def set_surfaceScale(self, surfaceScale):
- self._attributes['surfaceScale'] = surfaceScale
- def get_surfaceScale(self):
- return self._attributes.get('surfaceScale')
-
- def set_diffuseConstant(self, diffuseConstant):
- self._attributes['diffuseConstant'] = diffuseConstant
- def get_diffuseConstant(self):
- return self._attributes.get('diffuseConstant')
-
- def set_kernelUnitLength(self, kernelUnitLength):
- self._attributes['kernelUnitLength'] = kernelUnitLength
- def get_kernelUnitLength(self):
- return self._attributes.get('kernelUnitLength')
-
-class feDisplacementMap(feComponentTransfer):
- """
- Class representing the feDisplacementMap element of an svg doc.
- """
- def __init__(self, in2=None, scale=None, xChannelSelector=None, yChannelSelector=None, **kwargs):
- BaseElement.__init__(self, 'feDisplacementMap')
- self.set_in2(in2)
- self.set_scale(scale)
- self.set_xChannelSelector(xChannelSelector)
- self.set_yChannelSelector(yChannelSelector)
- self.setKWARGS(**kwargs)
-
- def set_in2(self, in2):
- self._attributes['in2'] = in2
- def get_in2(self):
- return self._attributes.get('in2')
-
- def set_scale(self, scale):
- self._attributes['scale'] = scale
- def get_scale(self):
- return self._attributes.get('scale')
-
- def set_xChannelSelector(self, xChannelSelector):
- self._attributes['xChannelSelector'] = xChannelSelector
- def get_xChannelSelector(self):
- return self._attributes.get('xChannelSelector')
-
- def set_yChannelSelector(self, yChannelSelector):
- self._attributes['yChannelSelector'] = yChannelSelector
- def get_yChannelSelector(self):
- return self._attributes.get('yChannelSelector')
-
-class feFlood(feComponentTransfer, StyleAttrib, PaintAttrib, PresentationAttributes_feFlood):
- """
- Class representing the feFlood element of an svg doc.
- """
- def __init__(self, x=None, y=None, width=None, height=None, flood_color=None, flood_opacity=None, **kwargs):
- BaseElement.__init__(self, 'feFlood')
- self.set_x(x)
- self.set_y(y)
- self.set_height(height)
- self.set_width(width)
- self.set_flood_color(flood_color)
- self.set_flood_opacity(flood_opacity)
- self.setKWARGS(**kwargs)
-
-class feGaussianBlur(feComponentTransfer):
- """
- Class representing the feGaussianBlur element of an svg doc.
- """
- def __init__(self, inValue=None, x=None, y=None, width=None, height=None, stdDeviation=None, **kwargs):
- BaseElement.__init__(self, 'feGaussianBlur')
- self.set_x(x)
- self.set_y(y)
- self.set_height(height)
- self.set_width(width)
- self.set_in(inValue)
- self.set_stdDeviation(stdDeviation)
- self.setKWARGS(**kwargs)
-
- def set_stdDeviation(self, stdDeviation):
- self._attributes['stdDeviation'] = stdDeviation
- def get_stdDeviation(self):
- return self._attributes.get('stdDeviation')
-
-class feImage(BaseElement, CoreAttrib, XLinkAttrib, FilterColorAttrib, FilterPrimitiveAttrib, ExternalAttrib, StyleAttrib, PresentationAttributes_All):
- """
- Class representing the feImage element of an svg doc.
- """
- def __init__(self, xlink_href=None, x=None, y=None, width=None, height=None, result=None, **kwargs):
- BaseElement.__init__(self, 'feImage')
- self.set_xlink_href(xlink_href)
- self.set_x(x)
- self.set_y(y)
- self.set_height(height)
- self.set_width(width)
- self.set_result(result)
- self.setKWARGS(**kwargs)
-
-class feMerge(BaseElement, CoreAttrib, FilterPrimitiveAttrib):
- """
- Class representing the feMerge element of an svg doc.
- """
- def __init__(self, x=None, y=None, width=None, height=None, **kwargs):
- BaseElement.__init__(self, 'feMerge')
- self.set_x(x)
- self.set_y(y)
- self.set_height(height)
- self.set_width(width)
- self.setKWARGS(**kwargs)
-
-class feMergeNode(BaseElement, CoreAttrib, FilterColorAttrib, FilterPrimitiveWithInAttrib):
- """
- Class representing the feMergeNode element of an svg doc.
- """
- def __init__(self, inValue=None, **kwargs):
- BaseElement.__init__(self, 'feMergeNode')
- self.set_in(inValue)
- self.setKWARGS(**kwargs)
-
-class feMorphology(feComponentTransfer):
- """
- Class representing the feMorphology element of an svg doc.
- """
- def __init__(self, x=None, y=None, width=None, height=None, operator=None, radius=None, **kwargs):
- BaseElement.__init__(self, 'feMorphology')
- self.set_x(x)
- self.set_y(y)
- self.set_height(height)
- self.set_width(width)
- self.set_operator(operator)
- self.set_radius(radius)
- self.setKWARGS(**kwargs)
-
- def set_operator(self, operator):
- self._attributes['operator'] = operator
- def get_operator(self):
- return self._attributes.get('operator')
-
- def set_radius(self, radius):
- self._attributes['radius'] = radius
- def get_radius(self):
- return self._attributes.get('radius')
-
-class feOffset(feComponentTransfer, DeltaPointAttrib):
- """
- Class representing the feOffset element of an svg doc.
- """
- def __init__(self, inValue=None, dx=None, dy=None, **kwargs):
- BaseElement.__init__(self, 'feOffset')
- self.set_in(inValue)
- self.set_dx(dx)
- self.set_dy(dy)
- self.setKWARGS(**kwargs)
-
-class feSpecularLighting(feComponentTransfer, StyleAttrib, PaintAttrib, PresentationAttributes_LightingEffects):
- """
- Class representing the feSpecularLighting element of an svg doc.
- """
- def __init__(self, lighting_color=None, surfaceScale=None, specularConstant=None, specularExponent=None, kernelUnitLength=None, **kwargs):
- BaseElement.__init__(self, 'feSpecularLighting')
- self.set_lighting_color(lighting_color)
- self.set_surfaceScale(surfaceScale)
- self.set_specularConstant(specularConstant)
- self.set_specularExponent(specularExponent)
- self.set_kernelUnitLength(kernelUnitLength)
- self.setKWARGS(**kwargs)
-
- def set_surfaceScale(self, surfaceScale):
- self._attributes['surfaceScale'] = surfaceScale
- def get_surfaceScale(self):
- return self._attributes.get('surfaceScale')
-
- def set_specularConstant(self, specularConstant):
- self._attributes['specularConstant'] = specularConstant
- def get_specularConstant(self):
- return self._attributes.get('specularConstant')
-
- def set_specularExponent(self, specularExponent):
- self._attributes['specularExponent'] = specularExponent
- def get_specularExponent(self):
- return self._attributes.get('specularExponent')
-
- def set_kernelUnitLength(self, kernelUnitLength):
- self._attributes['kernelUnitLength'] = kernelUnitLength
- def get_kernelUnitLength(self):
- return self._attributes.get('kernelUnitLength')
-
-class feTile(feComponentTransfer):
- """
- Class representing the feTile element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'feTile')
- self.setKWARGS(**kwargs)
-
-class feTurbulence(BaseElement, CoreAttrib, FilterColorAttrib, FilterPrimitiveAttrib):
- """
- Class representing the feTurbulence element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'feTurbulence')
- self.setKWARGS(**kwargs)
-
- def set_baseFrequency(self, baseFrequency):
- self._attributes['baseFrequency'] = baseFrequency
- def get_baseFrequency(self):
- return self._attributes.get('baseFrequency')
-
- def set_numOctaves(self, numOctaves):
- self._attributes['numOctaves'] = numOctaves
- def get_numOctaves(self):
- return self._attributes.get('numOctaves')
-
- def set_seed(self, seed):
- self._attributes['seed'] = seed
- def get_seed(self):
- return self._attributes.get('seed')
-
- def set_stitchTiles(self, stitchTiles):
- self._attributes['stitchTiles'] = stitchTiles
- def get_stitchTiles(self):
- return self._attributes.get('stitchTiles')
-
- def set_type(self, type):
- self._attributes['type'] = type
- def get_type(self):
- return self._attributes.get('type')
-
-class feDistantLight(BaseElement, CoreAttrib):
- """
- Class representing the feDistantLight element of an svg doc.
- """
- def __init__(self, azimuth=None, elevation=None, **kwargs):
- BaseElement.__init__(self, 'feDistantLight')
- self.set_azimuth(azimuth)
- self.set_elevation(elevation)
- self.setKWARGS(**kwargs)
-
- def set_azimuth(self, azimuth):
- self._attributes['azimuth'] = azimuth
- def get_azimuth(self):
- return self._attributes.get('azimuth')
-
- def set_elevation(self, elevation):
- self._attributes['elevation'] = elevation
- def get_elevation(self):
- return self._attributes.get('elevation')
-
-class fePointLight(BaseElement, CoreAttrib, PointAttrib):
- """
- Class representing the fePointLight element of an svg doc.
- """
- def __init__(self, x=None, y=None, z=None, **kwargs):
- BaseElement.__init__(self, 'fePointLight')
- self.set_x(x)
- self.set_y(y)
- self.set_z(z)
- self.setKWARGS(**kwargs)
-
- def set_z(self, z):
- self._attributes['z'] = z
- def get_z(self):
- return self._attributes.get('z')
-
-class feSpotLight(fePointLight):
- """
- Class representing the feSpotLight element of an svg doc.
- """
- def __init__(self, x=None, y=None, z=None, pointsAtX=None, pointsAtY=None, pointsAtZ=None, specularExponent=None, limitingConeAngle=None, **kwargs):
- BaseElement.__init__(self, 'feSpotLight')
- self.set_x(x)
- self.set_y(y)
- self.set_z(z)
- self.set_pointsAtX(pointsAtX)
- self.set_pointsAtY(pointsAtY)
- self.set_pointsAtZ(pointsAtZ)
- self.set_specularExponent(specularExponent)
- self.set_limitingConeAngle(limitingConeAngle)
- self.setKWARGS(**kwargs)
-
- def set_pointsAtX(self, pointsAtX):
- self._attributes['pointsAtX'] = pointsAtX
- def get_pointsAtX(self):
- return self._attributes.get('pointsAtX')
-
- def set_pointsAtY(self, pointsAtY):
- self._attributes['pointsAtY'] = pointsAtY
- def get_pointsAtY(self):
- return self._attributes.get('pointsAtY')
-
- def set_pointsAtZ(self, pointsAtZ):
- self._attributes['pointsAtZ'] = pointsAtZ
- def get_pointsAtZ(self):
- return self._attributes.get('pointsAtZ')
-
- def set_specularExponent(self, specularExponent):
- self._attributes['specularExponent'] = specularExponent
- def get_specularExponent(self):
- return self._attributes.get('specularExponent')
-
- def set_limitingConeAngle(self, limitingConeAngle):
- self._attributes['limitingConeAngle'] = limitingConeAngle
- def get_limitingConeAngle(self):
- return self._attributes.get('limitingConeAngle')
-
-class feFuncR(BaseElement, CoreAttrib):
- """
- Class representing the feFuncR element of an svg doc.
- """
- def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs):
- BaseElement.__init__(self, 'feFuncR')
- self.set_type(type)
- self.set_tableValues(tableValues)
- self.set_slope(slope)
- self.set_intercept(intercept)
- self.set_amplitude(amplitude)
- self.set_exponent(exponent)
- self.set_offset(offset)
- self.setKWARGS(**kwargs)
-
- def set_type(self, type):
- self._attributes['type'] = type
- def get_type(self):
- return self._attributes.get('type')
-
- def set_tableValues(self, tableValues):
- self._attributes['tableValues'] = tableValues
- def get_tableValues(self):
- return self._attributes.get('tableValues')
-
- def set_slope(self, slope):
- self._attributes['slope'] = slope
- def get_slope(self):
- return self._attributes.get('slope')
-
- def set_intercept(self, intercept):
- self._attributes['intercept'] = intercept
- def get_intercept(self):
- return self._attributes.get('intercept')
-
- def set_amplitude(self, amplitude):
- self._attributes['amplitude'] = amplitude
- def get_amplitude(self):
- return self._attributes.get('amplitude')
-
- def set_exponent(self, exponent):
- self._attributes['exponent'] = exponent
- def get_exponent(self):
- return self._attributes.get('exponent')
-
- def set_offset(self, offset):
- self._attributes['offset'] = offset
- def get_offset(self):
- return self._attributes.get('offset')
-
-class feFuncG(feFuncR):
- """
- Class representing the feFuncG element of an svg doc.
- """
- def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs):
- BaseElement.__init__(self, 'feFuncG')
- self.set_type(type)
- self.set_tableValues(tableValues)
- self.set_slope(slope)
- self.set_intercept(intercept)
- self.set_amplitude(amplitude)
- self.set_exponent(exponent)
- self.set_offset(offset)
- self.setKWARGS(**kwargs)
-
-class feFuncB(feFuncR):
- """
- Class representing the feFuncB element of an svg doc.
- """
- def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs):
- BaseElement.__init__(self, 'feFuncB')
- self.set_type(type)
- self.set_tableValues(tableValues)
- self.set_slope(slope)
- self.set_intercept(intercept)
- self.set_amplitude(amplitude)
- self.set_exponent(exponent)
- self.set_offset(offset)
- self.setKWARGS(**kwargs)
-
-class feFuncA(feFuncR):
- """
- Class representing the feFuncA element of an svg doc.
- """
- def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs):
- BaseElement.__init__(self, 'feFuncA')
- self.set_type(type)
- self.set_tableValues(tableValues)
- self.set_slope(slope)
- self.set_intercept(intercept)
- self.set_amplitude(amplitude)
- self.set_exponent(exponent)
- self.set_offset(offset)
- self.setKWARGS(**kwargs)
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from .attributes import *
+from .core import BaseElement, DeltaPointAttrib, PointAttrib, DimensionAttrib
+
+class filter(BaseElement, CoreAttrib, XLinkAttrib, ExternalAttrib, StyleAttrib, PresentationAttributes_All, PointAttrib, DimensionAttrib):
+ """
+ Class representing the filter element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, width=None, height=None, filterRes=None, filterUnits=None, primitiveUnits=None, **kwargs):
+ BaseElement.__init__(self, 'filter')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_height(height)
+ self.set_width(width)
+ self.set_filterRes(filterRes)
+ self.set_filterUnits(filterUnits)
+ self.set_primitiveUnits(primitiveUnits)
+ self.setKWARGS(**kwargs)
+
+ def set_filterUnits(self, filterUnits):
+ self._attributes['filterUnits'] = filterUnits
+ def get_filterUnits(self):
+ return self._attributes.get('filterUnits')
+
+ def set_primitiveUnits(self, primitiveUnits):
+ self._attributes['primitiveUnits'] = primitiveUnits
+ def get_primitiveUnits(self):
+ return self._attributes.get('primitiveUnits')
+
+ def set_filterRes(self, filterRes):
+ self._attributes['filterRes'] = filterRes
+ def get_filterRes(self):
+ return self._attributes.get('filterRes')
+
+class feComponentTransfer(BaseElement, CoreAttrib, FilterColorAttrib, FilterPrimitiveWithInAttrib):
+ """
+ Class representing the feComponentTransfer element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'feComponentTransfer')
+ self.setKWARGS(**kwargs)
+
+
+class feBlend(feComponentTransfer):
+ """
+ Class representing the feBlend element of an svg doc.
+ """
+ def __init__(self, in2=None, mode=None, **kwargs):
+ BaseElement.__init__(self, 'feBlend')
+ self.set_in2(in2)
+ self.set_mode(mode)
+ self.setKWARGS(**kwargs)
+
+ def set_in2(self, in2):
+ self._attributes['in2'] = in2
+ def get_in2(self):
+ return self._attributes.get('in2')
+
+ def set_mode(self, mode):
+ self._attributes['mode'] = mode
+ def get_mode(self):
+ return self._attributes.get('mode')
+
+class feColorMatrix(feComponentTransfer):
+ """
+ Class representing the feColorMatrix element of an svg doc.
+ """
+ def __init__(self, type=None, values=None, **kwargs):
+ BaseElement.__init__(self, 'feColorMatrix')
+ self.set_type(type)
+ self.set_values(values)
+ self.setKWARGS(**kwargs)
+
+ def set_type(self, type):
+ self._attributes['type'] = type
+ def get_type(self):
+ return self._attributes.get('type')
+
+ def set_values(self, values):
+ self._attributes['values'] = values
+ def get_values(self):
+ return self._attributes.get('values')
+
+class feComposite(feComponentTransfer):
+ """
+ Class representing the feComposite element of an svg doc.
+ """
+ def __init__(self, in2=None, operator=None, k1=None, k2=None, k3=None, k4=None, **kwargs):
+ BaseElement.__init__(self, 'feComposite')
+ self.set_in2(in2)
+ self.set_k1(k1)
+ self.set_k2(k2)
+ self.set_k3(k3)
+ self.set_k4(k4)
+ self.set_operator(operator)
+ self.setKWARGS(**kwargs)
+
+ def set_in2(self, in2):
+ self._attributes['in2'] = in2
+ def get_in2(self):
+ return self._attributes.get('in2')
+
+ def set_operator(self, operator):
+ self._attributes['operator'] = operator
+ def get_operator(self):
+ return self._attributes.get('operator')
+
+ def set_k1(self, k1):
+ self._attributes['k1'] = k1
+ def get_k1(self):
+ return self._attributes.get('k1')
+
+ def set_k2(self, k2):
+ self._attributes['k2'] = k2
+ def get_k2(self):
+ return self._attributes.get('k2')
+
+ def set_k3(self, k3):
+ self._attributes['k3'] = k3
+ def get_k3(self):
+ return self._attributes.get('k3')
+
+ def set_k4(self, k4):
+ self._attributes['k4'] = k4
+ def get_k4(self):
+ return self._attributes.get('k4')
+
+class feConvolveMatrix(feComponentTransfer):
+ """
+ Class representing the feConvolveMatrix element of an svg doc.
+ """
+ def __init__(self, order=None, kernelMatrix=None, divisor=None, bias=None, targetX=None, targetY=None, edgeMode=None, kernelUnitLength=None, preserveAlpha=None, **kwargs):
+ BaseElement.__init__(self, 'feConvolveMatrix')
+ self.set_order(order)
+ self.set_kernelMatrix(kernelMatrix)
+ self.set_divisor(divisor)
+ self.set_bias(bias)
+ self.set_targetX(targetX)
+ self.set_targetY(targetY)
+ self.set_edgeMode(edgeMode)
+ self.set_kernelUnitLength(kernelUnitLength)
+ self.set_preserveAlpha(preserveAlpha)
+ self.setKWARGS(**kwargs)
+
+ def set_order(self, order):
+ self._attributes['order'] = order
+ def get_order(self):
+ return self._attributes.get('order')
+
+ def set_kernelMatrix(self, kernelMatrix):
+ self._attributes['kernelMatrix'] = kernelMatrix
+ def get_kernelMatrix(self):
+ return self._attributes.get('kernelMatrix')
+
+ def set_divisor(self, divisor):
+ self._attributes['divisor'] = divisor
+ def get_divisor(self):
+ return self._attributes.get('divisor')
+
+ def set_bias(self, bias):
+ self._attributes['bias'] = bias
+ def get_bias(self):
+ return self._attributes.get('bias')
+
+ def set_targetX(self, targetX):
+ self._attributes['targetX'] = targetX
+ def get_targetX(self):
+ return self._attributes.get('targetX')
+
+ def set_targetY(self, targetY):
+ self._attributes['targetY'] = targetY
+ def get_targetY(self):
+ return self._attributes.get('targetY')
+
+ def set_edgeMode(self, edgeMode):
+ self._attributes['edgeMode'] = edgeMode
+ def get_edgeMode(self):
+ return self._attributes.get('edgeMode')
+
+ def set_kernelUnitLength(self, kernelUnitLength):
+ self._attributes['kernelUnitLength'] = kernelUnitLength
+ def get_kernelUnitLength(self):
+ return self._attributes.get('kernelUnitLength')
+
+ def set_preserveAlpha(self, preserveAlpha):
+ self._attributes['preserveAlpha'] = preserveAlpha
+ def get_preserveAlpha(self):
+ return self._attributes.get('preserveAlpha')
+
+class feDiffuseLighting(feComponentTransfer, StyleAttrib, PaintAttrib, PresentationAttributes_LightingEffects):
+ """
+ Class representing the feDiffuseLighting element of an svg doc.
+ """
+ def __init__(self, surfaceScale=None, diffuseConstant=None, kernelUnitLength=None , **kwargs):
+ BaseElement.__init__(self, 'feDiffuseLighting')
+ self.set_surfaceScale(surfaceScale)
+ self.set_diffuseConstant(diffuseConstant)
+ self.set_kernelUnitLength(kernelUnitLength)
+ self.setKWARGS(**kwargs)
+
+ def set_surfaceScale(self, surfaceScale):
+ self._attributes['surfaceScale'] = surfaceScale
+ def get_surfaceScale(self):
+ return self._attributes.get('surfaceScale')
+
+ def set_diffuseConstant(self, diffuseConstant):
+ self._attributes['diffuseConstant'] = diffuseConstant
+ def get_diffuseConstant(self):
+ return self._attributes.get('diffuseConstant')
+
+ def set_kernelUnitLength(self, kernelUnitLength):
+ self._attributes['kernelUnitLength'] = kernelUnitLength
+ def get_kernelUnitLength(self):
+ return self._attributes.get('kernelUnitLength')
+
+class feDisplacementMap(feComponentTransfer):
+ """
+ Class representing the feDisplacementMap element of an svg doc.
+ """
+ def __init__(self, in2=None, scale=None, xChannelSelector=None, yChannelSelector=None, **kwargs):
+ BaseElement.__init__(self, 'feDisplacementMap')
+ self.set_in2(in2)
+ self.set_scale(scale)
+ self.set_xChannelSelector(xChannelSelector)
+ self.set_yChannelSelector(yChannelSelector)
+ self.setKWARGS(**kwargs)
+
+ def set_in2(self, in2):
+ self._attributes['in2'] = in2
+ def get_in2(self):
+ return self._attributes.get('in2')
+
+ def set_scale(self, scale):
+ self._attributes['scale'] = scale
+ def get_scale(self):
+ return self._attributes.get('scale')
+
+ def set_xChannelSelector(self, xChannelSelector):
+ self._attributes['xChannelSelector'] = xChannelSelector
+ def get_xChannelSelector(self):
+ return self._attributes.get('xChannelSelector')
+
+ def set_yChannelSelector(self, yChannelSelector):
+ self._attributes['yChannelSelector'] = yChannelSelector
+ def get_yChannelSelector(self):
+ return self._attributes.get('yChannelSelector')
+
+class feFlood(feComponentTransfer, StyleAttrib, PaintAttrib, PresentationAttributes_feFlood):
+ """
+ Class representing the feFlood element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, width=None, height=None, flood_color=None, flood_opacity=None, **kwargs):
+ BaseElement.__init__(self, 'feFlood')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_height(height)
+ self.set_width(width)
+ self.set_flood_color(flood_color)
+ self.set_flood_opacity(flood_opacity)
+ self.setKWARGS(**kwargs)
+
+class feGaussianBlur(feComponentTransfer):
+ """
+ Class representing the feGaussianBlur element of an svg doc.
+ """
+ def __init__(self, inValue=None, x=None, y=None, width=None, height=None, stdDeviation=None, **kwargs):
+ BaseElement.__init__(self, 'feGaussianBlur')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_height(height)
+ self.set_width(width)
+ self.set_in(inValue)
+ self.set_stdDeviation(stdDeviation)
+ self.setKWARGS(**kwargs)
+
+ def set_stdDeviation(self, stdDeviation):
+ self._attributes['stdDeviation'] = stdDeviation
+ def get_stdDeviation(self):
+ return self._attributes.get('stdDeviation')
+
+class feImage(BaseElement, CoreAttrib, XLinkAttrib, FilterColorAttrib, FilterPrimitiveAttrib, ExternalAttrib, StyleAttrib, PresentationAttributes_All):
+ """
+ Class representing the feImage element of an svg doc.
+ """
+ def __init__(self, xlink_href=None, x=None, y=None, width=None, height=None, result=None, **kwargs):
+ BaseElement.__init__(self, 'feImage')
+ self.set_xlink_href(xlink_href)
+ self.set_x(x)
+ self.set_y(y)
+ self.set_height(height)
+ self.set_width(width)
+ self.set_result(result)
+ self.setKWARGS(**kwargs)
+
+class feMerge(BaseElement, CoreAttrib, FilterPrimitiveAttrib):
+ """
+ Class representing the feMerge element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, width=None, height=None, **kwargs):
+ BaseElement.__init__(self, 'feMerge')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_height(height)
+ self.set_width(width)
+ self.setKWARGS(**kwargs)
+
+class feMergeNode(BaseElement, CoreAttrib, FilterColorAttrib, FilterPrimitiveWithInAttrib):
+ """
+ Class representing the feMergeNode element of an svg doc.
+ """
+ def __init__(self, inValue=None, **kwargs):
+ BaseElement.__init__(self, 'feMergeNode')
+ self.set_in(inValue)
+ self.setKWARGS(**kwargs)
+
+class feMorphology(feComponentTransfer):
+ """
+ Class representing the feMorphology element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, width=None, height=None, operator=None, radius=None, **kwargs):
+ BaseElement.__init__(self, 'feMorphology')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_height(height)
+ self.set_width(width)
+ self.set_operator(operator)
+ self.set_radius(radius)
+ self.setKWARGS(**kwargs)
+
+ def set_operator(self, operator):
+ self._attributes['operator'] = operator
+ def get_operator(self):
+ return self._attributes.get('operator')
+
+ def set_radius(self, radius):
+ self._attributes['radius'] = radius
+ def get_radius(self):
+ return self._attributes.get('radius')
+
+class feOffset(feComponentTransfer, DeltaPointAttrib):
+ """
+ Class representing the feOffset element of an svg doc.
+ """
+ def __init__(self, inValue=None, dx=None, dy=None, **kwargs):
+ BaseElement.__init__(self, 'feOffset')
+ self.set_in(inValue)
+ self.set_dx(dx)
+ self.set_dy(dy)
+ self.setKWARGS(**kwargs)
+
+class feSpecularLighting(feComponentTransfer, StyleAttrib, PaintAttrib, PresentationAttributes_LightingEffects):
+ """
+ Class representing the feSpecularLighting element of an svg doc.
+ """
+ def __init__(self, lighting_color=None, surfaceScale=None, specularConstant=None, specularExponent=None, kernelUnitLength=None, **kwargs):
+ BaseElement.__init__(self, 'feSpecularLighting')
+ self.set_lighting_color(lighting_color)
+ self.set_surfaceScale(surfaceScale)
+ self.set_specularConstant(specularConstant)
+ self.set_specularExponent(specularExponent)
+ self.set_kernelUnitLength(kernelUnitLength)
+ self.setKWARGS(**kwargs)
+
+ def set_surfaceScale(self, surfaceScale):
+ self._attributes['surfaceScale'] = surfaceScale
+ def get_surfaceScale(self):
+ return self._attributes.get('surfaceScale')
+
+ def set_specularConstant(self, specularConstant):
+ self._attributes['specularConstant'] = specularConstant
+ def get_specularConstant(self):
+ return self._attributes.get('specularConstant')
+
+ def set_specularExponent(self, specularExponent):
+ self._attributes['specularExponent'] = specularExponent
+ def get_specularExponent(self):
+ return self._attributes.get('specularExponent')
+
+ def set_kernelUnitLength(self, kernelUnitLength):
+ self._attributes['kernelUnitLength'] = kernelUnitLength
+ def get_kernelUnitLength(self):
+ return self._attributes.get('kernelUnitLength')
+
+class feTile(feComponentTransfer):
+ """
+ Class representing the feTile element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'feTile')
+ self.setKWARGS(**kwargs)
+
+class feTurbulence(BaseElement, CoreAttrib, FilterColorAttrib, FilterPrimitiveAttrib):
+ """
+ Class representing the feTurbulence element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'feTurbulence')
+ self.setKWARGS(**kwargs)
+
+ def set_baseFrequency(self, baseFrequency):
+ self._attributes['baseFrequency'] = baseFrequency
+ def get_baseFrequency(self):
+ return self._attributes.get('baseFrequency')
+
+ def set_numOctaves(self, numOctaves):
+ self._attributes['numOctaves'] = numOctaves
+ def get_numOctaves(self):
+ return self._attributes.get('numOctaves')
+
+ def set_seed(self, seed):
+ self._attributes['seed'] = seed
+ def get_seed(self):
+ return self._attributes.get('seed')
+
+ def set_stitchTiles(self, stitchTiles):
+ self._attributes['stitchTiles'] = stitchTiles
+ def get_stitchTiles(self):
+ return self._attributes.get('stitchTiles')
+
+ def set_type(self, type):
+ self._attributes['type'] = type
+ def get_type(self):
+ return self._attributes.get('type')
+
+class feDistantLight(BaseElement, CoreAttrib):
+ """
+ Class representing the feDistantLight element of an svg doc.
+ """
+ def __init__(self, azimuth=None, elevation=None, **kwargs):
+ BaseElement.__init__(self, 'feDistantLight')
+ self.set_azimuth(azimuth)
+ self.set_elevation(elevation)
+ self.setKWARGS(**kwargs)
+
+ def set_azimuth(self, azimuth):
+ self._attributes['azimuth'] = azimuth
+ def get_azimuth(self):
+ return self._attributes.get('azimuth')
+
+ def set_elevation(self, elevation):
+ self._attributes['elevation'] = elevation
+ def get_elevation(self):
+ return self._attributes.get('elevation')
+
+class fePointLight(BaseElement, CoreAttrib, PointAttrib):
+ """
+ Class representing the fePointLight element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, z=None, **kwargs):
+ BaseElement.__init__(self, 'fePointLight')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_z(z)
+ self.setKWARGS(**kwargs)
+
+ def set_z(self, z):
+ self._attributes['z'] = z
+ def get_z(self):
+ return self._attributes.get('z')
+
+class feSpotLight(fePointLight):
+ """
+ Class representing the feSpotLight element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, z=None, pointsAtX=None, pointsAtY=None, pointsAtZ=None, specularExponent=None, limitingConeAngle=None, **kwargs):
+ BaseElement.__init__(self, 'feSpotLight')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_z(z)
+ self.set_pointsAtX(pointsAtX)
+ self.set_pointsAtY(pointsAtY)
+ self.set_pointsAtZ(pointsAtZ)
+ self.set_specularExponent(specularExponent)
+ self.set_limitingConeAngle(limitingConeAngle)
+ self.setKWARGS(**kwargs)
+
+ def set_pointsAtX(self, pointsAtX):
+ self._attributes['pointsAtX'] = pointsAtX
+ def get_pointsAtX(self):
+ return self._attributes.get('pointsAtX')
+
+ def set_pointsAtY(self, pointsAtY):
+ self._attributes['pointsAtY'] = pointsAtY
+ def get_pointsAtY(self):
+ return self._attributes.get('pointsAtY')
+
+ def set_pointsAtZ(self, pointsAtZ):
+ self._attributes['pointsAtZ'] = pointsAtZ
+ def get_pointsAtZ(self):
+ return self._attributes.get('pointsAtZ')
+
+ def set_specularExponent(self, specularExponent):
+ self._attributes['specularExponent'] = specularExponent
+ def get_specularExponent(self):
+ return self._attributes.get('specularExponent')
+
+ def set_limitingConeAngle(self, limitingConeAngle):
+ self._attributes['limitingConeAngle'] = limitingConeAngle
+ def get_limitingConeAngle(self):
+ return self._attributes.get('limitingConeAngle')
+
+class feFuncR(BaseElement, CoreAttrib):
+ """
+ Class representing the feFuncR element of an svg doc.
+ """
+ def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs):
+ BaseElement.__init__(self, 'feFuncR')
+ self.set_type(type)
+ self.set_tableValues(tableValues)
+ self.set_slope(slope)
+ self.set_intercept(intercept)
+ self.set_amplitude(amplitude)
+ self.set_exponent(exponent)
+ self.set_offset(offset)
+ self.setKWARGS(**kwargs)
+
+ def set_type(self, type):
+ self._attributes['type'] = type
+ def get_type(self):
+ return self._attributes.get('type')
+
+ def set_tableValues(self, tableValues):
+ self._attributes['tableValues'] = tableValues
+ def get_tableValues(self):
+ return self._attributes.get('tableValues')
+
+ def set_slope(self, slope):
+ self._attributes['slope'] = slope
+ def get_slope(self):
+ return self._attributes.get('slope')
+
+ def set_intercept(self, intercept):
+ self._attributes['intercept'] = intercept
+ def get_intercept(self):
+ return self._attributes.get('intercept')
+
+ def set_amplitude(self, amplitude):
+ self._attributes['amplitude'] = amplitude
+ def get_amplitude(self):
+ return self._attributes.get('amplitude')
+
+ def set_exponent(self, exponent):
+ self._attributes['exponent'] = exponent
+ def get_exponent(self):
+ return self._attributes.get('exponent')
+
+ def set_offset(self, offset):
+ self._attributes['offset'] = offset
+ def get_offset(self):
+ return self._attributes.get('offset')
+
+class feFuncG(feFuncR):
+ """
+ Class representing the feFuncG element of an svg doc.
+ """
+ def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs):
+ BaseElement.__init__(self, 'feFuncG')
+ self.set_type(type)
+ self.set_tableValues(tableValues)
+ self.set_slope(slope)
+ self.set_intercept(intercept)
+ self.set_amplitude(amplitude)
+ self.set_exponent(exponent)
+ self.set_offset(offset)
+ self.setKWARGS(**kwargs)
+
+class feFuncB(feFuncR):
+ """
+ Class representing the feFuncB element of an svg doc.
+ """
+ def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs):
+ BaseElement.__init__(self, 'feFuncB')
+ self.set_type(type)
+ self.set_tableValues(tableValues)
+ self.set_slope(slope)
+ self.set_intercept(intercept)
+ self.set_amplitude(amplitude)
+ self.set_exponent(exponent)
+ self.set_offset(offset)
+ self.setKWARGS(**kwargs)
+
+class feFuncA(feFuncR):
+ """
+ Class representing the feFuncA element of an svg doc.
+ """
+ def __init__(self, type=None, tableValues=None, slope=None, intercept=None, amplitude=None, exponent=None, offset=None, **kwargs):
+ BaseElement.__init__(self, 'feFuncA')
+ self.set_type(type)
+ self.set_tableValues(tableValues)
+ self.set_slope(slope)
+ self.set_intercept(intercept)
+ self.set_amplitude(amplitude)
+ self.set_exponent(exponent)
+ self.set_offset(offset)
+ self.setKWARGS(**kwargs)
Only in pysvg-0.2.2b/src/pysvg: filter.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/gradient.py pysvg-0.2.2b/src/pysvg/gradient.py
--- pysvg-0.2.2b.orig/src/pysvg/gradient.py 2012-11-15 14:37:12.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/gradient.py 2016-07-15 11:11:21.691960436 -0500
@@ -1,170 +1,170 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from attributes import *
-from core import BaseElement, PointAttrib, DimensionAttrib
-
-
-
-class linearGradient(BaseElement, CoreAttrib, XLinkAttrib, PaintAttrib, StyleAttrib, ExternalAttrib):
- """
- Class representing the linearGradient element of an svg doc.
- """
- def __init__(self, x1=None, y1=None, x2=None, y2=None, **kwargs):
- BaseElement.__init__(self, 'linearGradient')
- self.set_x1(x1)
- self.set_y1(y1)
- self.set_x2(x2)
- self.set_y2(y2)
- self.setKWARGS(**kwargs)
-
- def set_x1(self, x1):
- self._attributes['x1'] = x1
- def get_x1(self):
- return self._attributes.get('x1')
-
- def set_y1(self, y1):
- self._attributes['y1'] = y1
- def get_y1(self):
- return self._attributes.get('y1')
-
- def set_x2(self, x2):
- self._attributes['x2'] = x2
- def get_x2(self):
- return self._attributes.get('x2')
-
- def set_y2(self, y2):
- self._attributes['y2'] = y2
- def get_y2(self):
- return self._attributes.get('y2')
-
- def set_gradientUnits(self, gradientUnits):
- self._attributes['gradientUnits'] = gradientUnits
- def get_gradientUnits(self):
- return self._attributes.get('gradientUnits')
-
- def set_gradientTransform(self, gradientTransform):
- self._attributes['gradientTransform'] = gradientTransform
- def get_gradientTransform(self):
- return self._attributes.get('gradientTransform')
-
- def set_spreadMethod(self, spreadMethod):
- self._attributes['spreadMethod'] = spreadMethod
- def get_spreadMethod(self):
- return self._attributes.get('spreadMethod')
-
-class radialGradient(BaseElement, CoreAttrib, XLinkAttrib, PaintAttrib, StyleAttrib, ExternalAttrib):
- """
- Class representing the radialGradient element of an svg doc.
- """
- def __init__(self, cx='50%', cy='50%', r='50%', fx='50%', fy='50%', **kwargs):
- BaseElement.__init__(self, 'radialGradient')
- self.set_cx(cx)
- self.set_cy(cy)
- self.set_fx(fx)
- self.set_fy(fy)
- self.set_r(r)
- self.setKWARGS(**kwargs)
-
- def set_cx(self, cx):
- self._attributes['cx'] = cx
- def get_cx(self):
- return self._attributes.get('cx')
-
- def set_cy(self, cy):
- self._attributes['cy'] = cy
- def get_cy(self):
- return self._attributes.get('cy')
-
- def set_r(self, r):
- self._attributes['r'] = r
- def get_r(self):
- return self._attributes.get('r')
-
- def set_fx(self, fx):
- self._attributes['fx'] = fx
- def get_fx(self):
- return self._attributes.get('fx')
-
- def set_fy(self, fy):
- self._attributes['fy'] = fy
- def get_fy(self):
- return self._attributes.get('fy')
-
- def set_gradientUnits(self, gradientUnits):
- self._attributes['gradientUnits'] = gradientUnits
- def get_gradientUnits(self):
- return self._attributes.get('gradientUnits')
-
- def set_gradientTransform(self, gradientTransform):
- self._attributes['gradientTransform'] = gradientTransform
- def get_gradientTransform(self):
- return self._attributes.get('gradientTransform')
-
- def set_spreadMethod(self, spreadMethod):
- self._attributes['spreadMethod'] = spreadMethod
- def get_spreadMethod(self):
- return self._attributes.get('spreadMethod')
-
-class stop(BaseElement, CoreAttrib, StyleAttrib, PaintAttrib, GradientAttrib):
- """
- Class representing the stop element of an svg doc.
- """
- def __init__(self, offset=None, **kwargs):
- BaseElement.__init__(self, 'stop')
- self.set_offset(offset)
- self.setKWARGS(**kwargs)
-
- def set_offset(self, offset):
- self._attributes['offset'] = offset
- def get_offset(self):
- return self._attributes.get('offset')
-
-class pattern(BaseElement, CoreAttrib, XLinkAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, PresentationAttributes_All, PointAttrib, DimensionAttrib):
- """
- Class representing the pattern element of an svg doc.
- """
- def __init__(self, x=None, y=None, width=None, height=None, patternUnits=None, patternContentUnits=None, patternTransform=None, viewBox=None, preserveAspectRatio=None, **kwargs):
- BaseElement.__init__(self, 'pattern')
- self.set_x(x)
- self.set_y(y)
- self.set_width(width)
- self.set_height(height)
- self.set_patternUnits(patternUnits)
- self.set_patternContentUnits(patternContentUnits)
- self.set_patternTransform(patternTransform)
- self.set_viewBox(viewBox)
- self.set_preserveAspectRatio(preserveAspectRatio)
- self.setKWARGS(**kwargs)
-
- def set_viewBox(self, viewBox):
- self._attributes['viewBox'] = viewBox
-
- def get_viewBox(self):
- return self._attributes['viewBox']
-
- def set_preserveAspectRatio(self, preserveAspectRatio):
- self._attributes['preserveAspectRatio'] = preserveAspectRatio
-
- def get_preserveAspectRatio(self):
- return self._attributes['preserveAspectRatio']
-
- def set_patternUnits(self, patternUnits):
- self._attributes['patternUnits'] = patternUnits
-
- def get_patternUnits(self):
- return self._attributes['patternUnits']
-
- def set_patternContentUnits(self, patternContentUnits):
- self._attributes['patternContentUnits'] = patternContentUnits
- def get_patternContentUnits(self):
- return self._attributes['patternContentUnits']
-
- def set_patternTransform(self, patternTransform):
- self._attributes['patternTransform'] = patternTransform
-
- def get_patternTransform(self):
- return self._attributes['patternTransform']
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from .attributes import *
+from .core import BaseElement, PointAttrib, DimensionAttrib
+
+
+
+class linearGradient(BaseElement, CoreAttrib, XLinkAttrib, PaintAttrib, StyleAttrib, ExternalAttrib):
+ """
+ Class representing the linearGradient element of an svg doc.
+ """
+ def __init__(self, x1=None, y1=None, x2=None, y2=None, **kwargs):
+ BaseElement.__init__(self, 'linearGradient')
+ self.set_x1(x1)
+ self.set_y1(y1)
+ self.set_x2(x2)
+ self.set_y2(y2)
+ self.setKWARGS(**kwargs)
+
+ def set_x1(self, x1):
+ self._attributes['x1'] = x1
+ def get_x1(self):
+ return self._attributes.get('x1')
+
+ def set_y1(self, y1):
+ self._attributes['y1'] = y1
+ def get_y1(self):
+ return self._attributes.get('y1')
+
+ def set_x2(self, x2):
+ self._attributes['x2'] = x2
+ def get_x2(self):
+ return self._attributes.get('x2')
+
+ def set_y2(self, y2):
+ self._attributes['y2'] = y2
+ def get_y2(self):
+ return self._attributes.get('y2')
+
+ def set_gradientUnits(self, gradientUnits):
+ self._attributes['gradientUnits'] = gradientUnits
+ def get_gradientUnits(self):
+ return self._attributes.get('gradientUnits')
+
+ def set_gradientTransform(self, gradientTransform):
+ self._attributes['gradientTransform'] = gradientTransform
+ def get_gradientTransform(self):
+ return self._attributes.get('gradientTransform')
+
+ def set_spreadMethod(self, spreadMethod):
+ self._attributes['spreadMethod'] = spreadMethod
+ def get_spreadMethod(self):
+ return self._attributes.get('spreadMethod')
+
+class radialGradient(BaseElement, CoreAttrib, XLinkAttrib, PaintAttrib, StyleAttrib, ExternalAttrib):
+ """
+ Class representing the radialGradient element of an svg doc.
+ """
+ def __init__(self, cx='50%', cy='50%', r='50%', fx='50%', fy='50%', **kwargs):
+ BaseElement.__init__(self, 'radialGradient')
+ self.set_cx(cx)
+ self.set_cy(cy)
+ self.set_fx(fx)
+ self.set_fy(fy)
+ self.set_r(r)
+ self.setKWARGS(**kwargs)
+
+ def set_cx(self, cx):
+ self._attributes['cx'] = cx
+ def get_cx(self):
+ return self._attributes.get('cx')
+
+ def set_cy(self, cy):
+ self._attributes['cy'] = cy
+ def get_cy(self):
+ return self._attributes.get('cy')
+
+ def set_r(self, r):
+ self._attributes['r'] = r
+ def get_r(self):
+ return self._attributes.get('r')
+
+ def set_fx(self, fx):
+ self._attributes['fx'] = fx
+ def get_fx(self):
+ return self._attributes.get('fx')
+
+ def set_fy(self, fy):
+ self._attributes['fy'] = fy
+ def get_fy(self):
+ return self._attributes.get('fy')
+
+ def set_gradientUnits(self, gradientUnits):
+ self._attributes['gradientUnits'] = gradientUnits
+ def get_gradientUnits(self):
+ return self._attributes.get('gradientUnits')
+
+ def set_gradientTransform(self, gradientTransform):
+ self._attributes['gradientTransform'] = gradientTransform
+ def get_gradientTransform(self):
+ return self._attributes.get('gradientTransform')
+
+ def set_spreadMethod(self, spreadMethod):
+ self._attributes['spreadMethod'] = spreadMethod
+ def get_spreadMethod(self):
+ return self._attributes.get('spreadMethod')
+
+class stop(BaseElement, CoreAttrib, StyleAttrib, PaintAttrib, GradientAttrib):
+ """
+ Class representing the stop element of an svg doc.
+ """
+ def __init__(self, offset=None, **kwargs):
+ BaseElement.__init__(self, 'stop')
+ self.set_offset(offset)
+ self.setKWARGS(**kwargs)
+
+ def set_offset(self, offset):
+ self._attributes['offset'] = offset
+ def get_offset(self):
+ return self._attributes.get('offset')
+
+class pattern(BaseElement, CoreAttrib, XLinkAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, PresentationAttributes_All, PointAttrib, DimensionAttrib):
+ """
+ Class representing the pattern element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, width=None, height=None, patternUnits=None, patternContentUnits=None, patternTransform=None, viewBox=None, preserveAspectRatio=None, **kwargs):
+ BaseElement.__init__(self, 'pattern')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_width(width)
+ self.set_height(height)
+ self.set_patternUnits(patternUnits)
+ self.set_patternContentUnits(patternContentUnits)
+ self.set_patternTransform(patternTransform)
+ self.set_viewBox(viewBox)
+ self.set_preserveAspectRatio(preserveAspectRatio)
+ self.setKWARGS(**kwargs)
+
+ def set_viewBox(self, viewBox):
+ self._attributes['viewBox'] = viewBox
+
+ def get_viewBox(self):
+ return self._attributes['viewBox']
+
+ def set_preserveAspectRatio(self, preserveAspectRatio):
+ self._attributes['preserveAspectRatio'] = preserveAspectRatio
+
+ def get_preserveAspectRatio(self):
+ return self._attributes['preserveAspectRatio']
+
+ def set_patternUnits(self, patternUnits):
+ self._attributes['patternUnits'] = patternUnits
+
+ def get_patternUnits(self):
+ return self._attributes['patternUnits']
+
+ def set_patternContentUnits(self, patternContentUnits):
+ self._attributes['patternContentUnits'] = patternContentUnits
+ def get_patternContentUnits(self):
+ return self._attributes['patternContentUnits']
+
+ def set_patternTransform(self, patternTransform):
+ self._attributes['patternTransform'] = patternTransform
+
+ def get_patternTransform(self):
+ return self._attributes['patternTransform']
Only in pysvg-0.2.2b/src/pysvg: gradient.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/linking.py pysvg-0.2.2b/src/pysvg/linking.py
--- pysvg-0.2.2b.orig/src/pysvg/linking.py 2012-11-15 14:37:26.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/linking.py 2016-07-15 11:11:21.722960264 -0500
@@ -1,67 +1,67 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from attributes import *
-from core import BaseElement
-
-
-
-class a(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib, XLinkAttrib):
- """
- Class representing the a element of an svg doc.
- """
- def __init__(self, target=None):
- BaseElement.__init__(self,'a')
- self.set_target(target)
-
- def set_transform(self, transform):
- self._attributes['transform']=transform
- def get_transform(self):
- return self._attributes.get('transform')
-
- def set_target(self, target):
- self._attributes['target']=target
- def get_target(self):
- return self._attributes.get('target')
-
-class view(BaseElement, CoreAttrib, ExternalAttrib):
- """
- Class representing the view element of an svg doc.
- """
- def __init__(self, ):
- BaseElement.__init__(self,'view')
-
- def set_transform(self, transform):
- self._attributes['transform']=transform
- def get_transform(self):
- return self._attributes.get('transform')
-
- def set_target(self, target):
- self._attributes['target']=target
- def get_target(self):
- return self._attributes.get('target')
-
- def set_viewBox(self,viewBox):
- self._attributes['viewBox']=viewBox
-
- def get_viewBox(self):
- return self._attributes['viewBox']
-
- def set_preserveAspectRatio(self,preserveAspectRatio):
- self._attributes['preserveAspectRatio']=preserveAspectRatio
-
- def get_preserveAspectRatio(self):
- return self._attributes['preserveAspectRatio']
-
- def set_zoomAndPan(self,zoomAndPan):
- self._attributes['zoomAndPan']=zoomAndPan
- def get_zoomAndPan(self):
- return self._attributes['zoomAndPan']
-
- def set_viewTarget(self,viewTarget):
- self._attributes['viewTarget']=viewTarget
- def get_viewTarget(self):
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from .attributes import *
+from .core import BaseElement
+
+
+
+class a(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib, XLinkAttrib):
+ """
+ Class representing the a element of an svg doc.
+ """
+ def __init__(self, target=None):
+ BaseElement.__init__(self,'a')
+ self.set_target(target)
+
+ def set_transform(self, transform):
+ self._attributes['transform']=transform
+ def get_transform(self):
+ return self._attributes.get('transform')
+
+ def set_target(self, target):
+ self._attributes['target']=target
+ def get_target(self):
+ return self._attributes.get('target')
+
+class view(BaseElement, CoreAttrib, ExternalAttrib):
+ """
+ Class representing the view element of an svg doc.
+ """
+ def __init__(self, ):
+ BaseElement.__init__(self,'view')
+
+ def set_transform(self, transform):
+ self._attributes['transform']=transform
+ def get_transform(self):
+ return self._attributes.get('transform')
+
+ def set_target(self, target):
+ self._attributes['target']=target
+ def get_target(self):
+ return self._attributes.get('target')
+
+ def set_viewBox(self,viewBox):
+ self._attributes['viewBox']=viewBox
+
+ def get_viewBox(self):
+ return self._attributes['viewBox']
+
+ def set_preserveAspectRatio(self,preserveAspectRatio):
+ self._attributes['preserveAspectRatio']=preserveAspectRatio
+
+ def get_preserveAspectRatio(self):
+ return self._attributes['preserveAspectRatio']
+
+ def set_zoomAndPan(self,zoomAndPan):
+ self._attributes['zoomAndPan']=zoomAndPan
+ def get_zoomAndPan(self):
+ return self._attributes['zoomAndPan']
+
+ def set_viewTarget(self,viewTarget):
+ self._attributes['viewTarget']=viewTarget
+ def get_viewTarget(self):
return self._attributes['viewTarget']
\ No newline at end of file
Only in pysvg-0.2.2b/src/pysvg: linking.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/parser.py pysvg-0.2.2b/src/pysvg/parser.py
--- pysvg-0.2.2b.orig/src/pysvg/parser.py 2012-11-15 15:07:44.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/parser.py 2016-07-15 11:11:21.758960064 -0500
@@ -1,75 +1,75 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from xml.dom import minidom
-from xml.dom import Node
-import string
-from pysvg.animate import *
-from pysvg.filter import *
-from pysvg.gradient import *
-from pysvg.linking import *
-from pysvg.script import *
-from pysvg.shape import *
-from pysvg.structure import *
-from pysvg.style import *
-from pysvg.text import *
-
-def calculateMethodName(attr):
- name=attr
- name=name.replace(':','_')
- name=name.replace('-','_')
- name='set_'+name
- return name
-
-def setAttributes(attrs,obj):
- for attr in attrs.keys():
- if hasattr(obj, calculateMethodName(attr)):
- eval ('obj.'+calculateMethodName(attr))(attrs[attr].value)
- else:
- print calculateMethodName(attr)+' not found in:'+obj._elementName
-
-def build(node_, object):
- attrs = node_.attributes
- if attrs != None:
- setAttributes(attrs, object)
- for child_ in node_.childNodes:
- nodeName_ = child_.nodeName.split(':')[-1]
- if child_.nodeType == Node.ELEMENT_NODE:
- try:
- objectinstance=eval(nodeName_)()
- except:
- print 'no class for: '+nodeName_
- continue
- object.addElement(build(child_,objectinstance))
- elif child_.nodeType == Node.TEXT_NODE:
- #print "TextNode:"+child_.nodeValue
- #if child_.nodeValue.startswith('\n'):
- # print "TextNode starts with return:"+child_.nodeValue
- #else:
-# print "TextNode is:"+child_.nodeValue
- #object.setTextContent(child_.nodeValue)
- if child_.nodeValue <> None:
- object.appendTextContent(child_.nodeValue)
- elif child_.nodeType == Node.CDATA_SECTION_NODE:
- object.appendTextContent('<![CDATA['+child_.nodeValue+']]>')
- elif child_.nodeType == Node.COMMENT_NODE:
- object.appendTextContent('<!-- '+child_.nodeValue+' -->')
- else:
- print "Some node:"+nodeName_+" value: "+child_.nodeValue
- return object
-
-#TODO: packageprefix ?
-def parse(inFileName):
- doc = minidom.parse(inFileName)
- rootNode = doc.documentElement
- rootObj = svg()
- build(rootNode,rootObj)
- # Enable Python to collect the space used by the DOM.
- doc = None
- #print rootObj.getXML()
- return rootObj
-
-
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from xml.dom import minidom
+from xml.dom import Node
+import string
+from pysvg.animate import *
+from pysvg.filter import *
+from pysvg.gradient import *
+from pysvg.linking import *
+from pysvg.script import *
+from pysvg.shape import *
+from pysvg.structure import *
+from pysvg.style import *
+from pysvg.text import *
+
+def calculateMethodName(attr):
+ name=attr
+ name=name.replace(':','_')
+ name=name.replace('-','_')
+ name='set_'+name
+ return name
+
+def setAttributes(attrs,obj):
+ for attr in list(attrs.keys()):
+ if hasattr(obj, calculateMethodName(attr)):
+ eval ('obj.'+calculateMethodName(attr))(attrs[attr].value)
+ else:
+ print(calculateMethodName(attr)+' not found in:'+obj._elementName)
+
+def build(node_, object):
+ attrs = node_.attributes
+ if attrs != None:
+ setAttributes(attrs, object)
+ for child_ in node_.childNodes:
+ nodeName_ = child_.nodeName.split(':')[-1]
+ if child_.nodeType == Node.ELEMENT_NODE:
+ try:
+ objectinstance=eval(nodeName_)()
+ except:
+ print('no class for: '+nodeName_)
+ continue
+ object.addElement(build(child_,objectinstance))
+ elif child_.nodeType == Node.TEXT_NODE:
+ #print "TextNode:"+child_.nodeValue
+ #if child_.nodeValue.startswith('\n'):
+ # print "TextNode starts with return:"+child_.nodeValue
+ #else:
+# print "TextNode is:"+child_.nodeValue
+ #object.setTextContent(child_.nodeValue)
+ if child_.nodeValue != None:
+ object.appendTextContent(child_.nodeValue)
+ elif child_.nodeType == Node.CDATA_SECTION_NODE:
+ object.appendTextContent('<![CDATA['+child_.nodeValue+']]>')
+ elif child_.nodeType == Node.COMMENT_NODE:
+ object.appendTextContent('<!-- '+child_.nodeValue+' -->')
+ else:
+ print("Some node:"+nodeName_+" value: "+child_.nodeValue)
+ return object
+
+#TODO: packageprefix ?
+def parse(inFileName):
+ doc = minidom.parse(inFileName)
+ rootNode = doc.documentElement
+ rootObj = svg()
+ build(rootNode,rootObj)
+ # Enable Python to collect the space used by the DOM.
+ doc = None
+ #print rootObj.getXML()
+ return rootObj
+
+
Only in pysvg-0.2.2b/src/pysvg: parser.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/script.py pysvg-0.2.2b/src/pysvg/script.py
--- pysvg-0.2.2b.orig/src/pysvg/script.py 2012-11-15 14:38:20.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/script.py 2016-07-15 11:11:21.767960014 -0500
@@ -1,23 +1,23 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from attributes import CoreAttrib, XLinkAttrib
-from core import BaseElement
-
-
-
-class script(BaseElement, CoreAttrib, XLinkAttrib):
- """
- Class representing the script element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self,'script')
- self.setKWARGS(**kwargs)
-
- def set_type(self, type):
- self._attributes['type']=type
- def get_type(self):
- return self._attributes.get('type')
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from .attributes import CoreAttrib, XLinkAttrib
+from .core import BaseElement
+
+
+
+class script(BaseElement, CoreAttrib, XLinkAttrib):
+ """
+ Class representing the script element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self,'script')
+ self.setKWARGS(**kwargs)
+
+ def set_type(self, type):
+ self._attributes['type']=type
+ def get_type(self):
+ return self._attributes.get('type')
Only in pysvg-0.2.2b/src/pysvg: script.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/shape.py pysvg-0.2.2b/src/pysvg/shape.py
--- pysvg-0.2.2b.orig/src/pysvg/shape.py 2012-11-15 14:38:56.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/shape.py 2016-07-15 11:11:21.955958970 -0500
@@ -1,481 +1,484 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from attributes import *
-from core import BaseElement, BaseShape, PointAttrib, DimensionAttrib, PointToAttrib
-
-
-class rect(BaseShape, PointAttrib, DimensionAttrib):
- """
- Class representing the rect element of an svg doc.
- """
- def __init__(self, x=None, y=None, width=None, height=None, rx=None, ry=None, **kwargs):
- BaseElement.__init__(self,'rect')
- self.set_x(x)
- self.set_y(y)
- self.set_height(height)
- self.set_width(width)
- self.set_rx(rx)
- self.set_ry(ry)
- self.setKWARGS(**kwargs)
-
- def set_rx(self, rx):
- self._attributes['rx']=rx
- def get_rx(self):
- return self._attributes.get('rx')
-
- def set_ry(self, ry):
- self._attributes['ry']=ry
- def get_ry(self):
- return self._attributes.get('ry')
-
- #extra methods. Methods do rely on number values in the attributes. You might get an exception else!
- def getEdgePoints(self):
- """
- Returns a list with the coordinates of the points at the edge of the rectangle as tuples.
- e.g.[(x1,y1),(x2,y2)]
- The sorting is counterclockwise starting with the lower left corner.
- Coordinates must be numbers or an exception will be thrown.
- """
- result = [(float(self.get_x()),float(self.get_y()))]
- result.append((float(self.get_x())+float(self.get_width()),float(self.get_y())))
- result.append((float(self.get_x())+float(self.get_width()),float(self.get_y())+float(self.get_height())))
- result.append((float(self.get_x()),float(self.get_y())+float(self.get_height())))
- return result
-
- def getInnerEdgePoints(self):
- """
- Returns a list with the coordinates of the points at the inner edge of a rounded rectangle as tuples.
- e.g.[(x1,y1),(x2,y2)]
- The sorting is counterclockwise starting with the lower left corner.
- Coordinates must be numbers or an exception will be thrown.
- """
- result = []
- result.append((float(self.get_x()) + float(self.get_rx()), float(self.get_y()) + float(self.get_ry())))
- result.append((float(self.get_x()) + float(self.get_width()) - float(self.get_rx()), float(self.get_y()) + float(self.get_ry())))
- 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())))
- result.append((float(self.get_x()) + float(self.get_rx()), float(self.get_y()) + float(self.get_height()) - float(self.get_ry())))
- return result
-
- def getBottomLeft(self):
- """
- Retrieves a tuple with the x,y coordinates of the lower left point of the rect.
- Requires the coordinates, width, height to be numbers
- """
- return (float(self.get_x()), float(self.get_y()))
-
- def getBottomRight(self):
- """
- Retrieves a tuple with the x,y coordinates of the lower right point of the rect.
- Requires the coordinates, width, height to be numbers
- """
- return (float(self.get_x()) + float(self.get_width()), float(self.get_y()))
-
- def getTopLeft(self):
- """
- Retrieves a tuple with the x,y coordinates of the upper left point of the rect.
- Requires the coordinates, width, height to be numbers
- """
- return (float(self.get_x()), float(self.get_y())+ float(self.get_height()))
-
- def getTopRight(self):
- """
- Retrieves a tuple with the x,y coordinates of the upper right point of the rect.
- Requires the coordinates, width, height to be numbers
- """
- return (float(self.get_x()) + float(self.get_width()), float(self.get_y()) + float(self.get_height()))
-
- def moveToPoint(self, (x,y)):
- """
- Moves the rect to the point x,y
- """
- self.set_x(float(self.get_x()) + float(x))
- self.set_y(float(self.get_y()) + float(y))
-
-
-class circle(BaseShape):
- """
- Class representing the circle element of an svg doc.
- """
- def __init__(self, cx=None,cy=None,r=None, **kwargs):
- BaseElement.__init__(self,'circle')
- self.set_cx(cx)
- self.set_cy(cy)
- self.set_r(r)
- self.setKWARGS(**kwargs)
-
- def set_cx(self, cx):
- self._attributes['cx']=cx
- def get_cx(self):
- return self._attributes.get('cx')
-
- def set_cy(self, cy):
- self._attributes['cy']=cy
- def get_cy(self):
- return self._attributes.get('cy')
-
- def set_r(self, r):
- self._attributes['r']=r
- def get_r(self):
- return self._attributes.get('r')
-
- #extra methods. Methods do rely on number values in the attributes. You might get an exception else!
- def getDiameter(self):
- """
- Retrieves the diameter of the circle. Requires the radius to be a number
- """
- return 2 * float(self.get_r())
-
- def getWidth(self):
- """
- Retrieves the width of the circle. Requires the radius to be a number
- """
- return self.getDiameter()
-
- def getHeight(self):
- """
- Retrieves the height of the circle. Requires the radius to be a number
- """
- return self.getDiameter()
-
- def getBottomLeft(self):
- """
- Retrieves a tuple with the x,y coordinates of the lower left point of the circle.
- Requires the radius and the coordinates to be numbers
- """
- return (float(self.get_cx()) - float(self.get_r()), float(self.get_cy()) - float(self.get_r()))
-
- def getBottomRight(self):
- """
- Retrieves a tuple with the x,y coordinates of the lower right point of the circle.
- Requires the radius and the coordinates to be numbers
- """
- return (float(self.get_cx()) + float(self.get_r()), float(self.get_cy()) - float(self.get_r()))
-
- def getTopLeft(self):
- """
- Retrieves a tuple with the x,y coordinates of the upper left point of the circle.
- Requires the radius and the coordinates to be numbers
- """
- return (float(self.get_cx()) - float(self.get_r()), float(self.get_cy()) + float(self.get_r()))
-
- def getTopRight(self):
- """
- Retrieves a tuple with the x,y coordinates of the upper right point of the circle.
- Requires the radius and the coordinates to be numbers
- """
- return (float(self.get_cx()) + float(self.get_r()), float(self.get_cy()) + float(self.get_r()))
-
- def moveToPoint(self, (x,y)):
- """
- Moves the circle to the point x,y
- """
- self.set_cx(float(self.get_cx()) + float(x))
- self.set_cy(float(self.get_cy()) + float(y))
-
-class ellipse(BaseShape):
- """
- Class representing the ellipse element of an svg doc.
- """
- def __init__(self, cx=None,cy=None,rx=None,ry=None, **kwargs):
- BaseElement.__init__(self,'ellipse')
- self.set_cx(cx)
- self.set_cy(cy)
- self.set_rx(rx)
- self.set_ry(ry)
- self.setKWARGS(**kwargs)
-
- def set_cx(self, cx):
- self._attributes['cx']=cx
- def get_cx(self):
- return self._attributes.get('cx')
-
- def set_cy(self, cy):
- self._attributes['cy']=cy
- def get_cy(self):
- return self._attributes.get('cy')
-
- def set_rx(self, rx):
- self._attributes['rx']=rx
- def get_rx(self):
- return self._attributes.get('rx')
-
- def set_ry(self, ry):
- self._attributes['ry']=ry
- def get_ry(self):
- return self._attributes.get('ry')
-
- #extra methods. Methods do rely on number values in the attributes. You might get an exception else!
- def getWidth(self):
- return abs(2 * float(self.get_rx()))
-
- def getHeight(self):
- return abs(2 * float(self.get_ry()))
-
- def getBottomLeft(self):
- """
- Retrieves a tuple with the x,y coordinates of the lower left point of the ellipse.
- Requires the radius and the coordinates to be numbers
- """
- return (float(self.get_cx()) - float(self.get_rx()), float(self.get_cy()) - float(self.get_ry()))
-
- def getBottomRight(self):
- """
- Retrieves a tuple with the x,y coordinates of the lower right point of the ellipse.
- Requires the radius and the coordinates to be numbers
- """
- return (float(self.get_cx()) + float(self.get_rx()), float(self.get_cy()) - float(self.get_ry()))
-
- def getTopLeft(self):
- """
- Retrieves a tuple with the x,y coordinates of the upper left point of the ellipse.
- Requires the radius and the coordinates to be numbers
- """
- return (float(self.get_cx()) - float(self.get_rx()), float(self.get_cy()) + float(self.get_ry()))
-
- def getTopRight(self):
- """
- Retrieves a tuple with the x,y coordinates of the upper right point of the ellipse.
- Requires the radius and the coordinates to be numbers
- """
- return (float(self.get_cx()) + float(self.get_rx()), float(self.get_cy()) + float(self.get_ry()))
-
-class line(BaseShape, PointToAttrib):
- """
- Class representing the line element of an svg doc.
- Note that this element is NOT painted VISIBLY by default UNLESS you provide
- a style including STROKE and STROKE-WIDTH
- """
- def __init__(self, X1=None, Y1=None, X2=None, Y2=None, **kwargs):
- """
- Creates a line
- @type X1: string or int
- @param X1: starting x-coordinate
- @type Y1: string or int
- @param Y1: starting y-coordinate
- @type X2: string or int
- @param X2: ending x-coordinate
- @type Y2: string or int
- @param Y2: ending y-coordinate
- """
- BaseElement.__init__(self,'line')
- self.set_x1(X1)
- self.set_y1(Y1)
- self.set_x2(X2)
- self.set_y2(Y2)
- self.setKWARGS(**kwargs)
-
- def set_x1(self, x1):
- self._attributes['x1']=x1
- def get_x1(self):
- return self._attributes.get('x1')
-
- def set_y1(self, y1):
- self._attributes['y1']=y1
- def get_y1(self):
- return self._attributes.get('y1')
-
- def set_x2(self, x2):
- self._attributes['x2']=x2
- def get_x2(self):
- return self._attributes.get('x2')
-
- def set_y2(self, y2):
- self._attributes['y2']=y2
- def get_y2(self):
- return self._attributes.get('y2')
-
- #extra methods. Methods do rely on number values in the attributes. You might get an exception else!
- def getWidth(self):
- """
- Retrieves the width of the line. This is always a positive number.
- Coordinates must be numbers.
- """
- return abs(float(self.get_x1()) - float(self.get_x2()))
-
- def getHeight(self):
- """
- Retrieves the height of the line. This is always a positive number.
- Coordinates must be numbers.
- """
- return abs(float(self.get_y1()) - float(self.get_y2()))
-
- def getBottomLeft(self):
- """
- Retrieves the the bottom left coordinate of the line as tuple.
- Coordinates must be numbers.
- """
- x1 = float(self.get_x1())
- x2 = float(self.get_x2())
- y1 = float(self.get_y1())
- y2 = float(self.get_y2())
- if x1 < x2:
- if y1 < y2:
- return (x1, y1)
- else:
- return (x1, y2)
- else:
- if y1 < y2:
- return (x2, y1)
- else:
- return (x2, y2)
-
- def getBottomRight(self):
- """
- Retrieves the the bottom right coordinate of the line as tuple.
- Coordinates must be numbers.
- """
- x1 = float(self.get_x1())
- x2 = float(self.get_x2())
- y1 = float(self.get_y1())
- y2 = float(self.get_y2())
- if x1 < x2:
- if y1 < y2:
- return (x2, y1)
- else:
- return (x2, y2)
- else:
- if y1 < y2:
- return (x1, y1)
- else:
- return (x1, y2)
-
- def getTopRight(self):
- """
- Retrieves the the top right coordinate of the line as tuple.
- Coordinates must be numbers.
- """
- x1 = float(self.get_x1())
- x2 = float(self.get_x2())
- y1 = float(self.get_y1())
- y2 = float(self.get_y2())
- if x1 < x2:
- if y1 < y2:
- return (x2, y2)
- else:
- return (x2, y1)
- else:
- if y1 < y2:
- return (x1, y2)
- else:
- return (x1, y1)
-
- def getTopLeft(self):
- """
- Retrieves the the top left coordinate of the line as tuple.
- Coordinates must be numbers.
- """
- x1 = float(self.get_x1())
- x2 = float(self.get_x2())
- y1 = float(self.get_y1())
- y2 = float(self.get_y2())
- if x1 < x2:
- if y1 < y2:
- return (x1, y2)
- else:
- return (x1, y1)
- else:
- if y1 < y2:
- return (x2, y2)
- else:
- return (x2, y1)
-
- def moveToPoint(self, (x,y)):
- """
- Moves the line to the point x,y
- """
- self.set_x1(float(self.get_x1()) + float(x))
- self.set_x2(float(self.get_x2()) + float(x))
- self.set_y1(float(self.get_y1()) + float(y))
- self.set_y2(float(self.get_y2()) + float(y))
-
-class path(BaseShape, ExternalAttrib, MarkerAttrib):
- """
- Class representing the path element of an svg doc.
- """
- def __init__(self, pathData="",pathLength=None, style=None, focusable=None, **kwargs):
- BaseElement.__init__(self,'path')
- if pathData!='' and not pathData.endswith(' '):
- pathData+=' '
- self.set_d(pathData)
- if style!=None:
- self.set_style(style)
- self.setKWARGS(**kwargs)
-
- def set_d(self, d):
- self._attributes['d']=d
- def get_d(self):
- return self._attributes.get('d')
-
- def set_pathLength(self, pathLength):
- self._attributes['pathLength']=pathLength
- def get_pathLength(self):
- return self._attributes.get('pathLength')
-
- def __append__(self,command, params, relative=True):
- d = self.get_d()
- if relative==True:
- d+=command.lower()
- else:
- d+=command.upper()
- for param in params:
- d+=' %s ' %(param)
- self.set_d(d)
-
- def appendLineToPath(self,endx,endy, relative=True):
- self.__append__('l',[endx,endy], relative)
-
- def appendHorizontalLineToPath(self,endx, relative=True):
- self.__append__('h',[endx], relative)
-
- def appendVerticalLineToPath(self,endy, relative=True):
- self.__append__('v',[endy], relative)
-
- def appendMoveToPath(self,endx,endy, relative=True):
- self.__append__('m',[endx,endy], relative)
-
- def appendCloseCurve(self):
- d = self.get_d()
- d+="z"
- self.set_d(d)
-
- def appendCubicCurveToPath(self, controlstartx, controlstarty, controlendx, controlendy, endx,endy,relative=True):
- self.__append__('c',[controlstartx, controlstarty, controlendx, controlendy, endx,endy], relative)
-
- def appendCubicShorthandCurveToPath(self, controlendx, controlendy, endx,endy,relative=True):
- self.__append__('s',[controlendx, controlendy, endx,endy], relative)
-
- def appendQuadraticCurveToPath(self, controlx, controly, endx,endy,relative=True):
- self.__append__('q',[controlx, controly, endx,endy], relative)
-
- def appendQuadraticShorthandCurveToPath(self, endx,endy,relative=True):
- self.__append__('t',[endx,endy], relative)
-
- def appendArcToPath(self,rx,ry,x,y,x_axis_rotation=0,large_arc_flag=0,sweep_flag=1 ,relative=True):
- self.__append__('a',[rx,ry,x_axis_rotation,large_arc_flag,sweep_flag,x,y], relative)
-
-class polyline(BaseShape):
- """
- Class representing the polyline element of an svg doc.
- """
- def __init__(self, points=None, **kwargs):
- BaseElement.__init__(self,'polyline')
- self.set_points(points)
- self.setKWARGS(**kwargs)
-
- def set_points(self, points):
- self._attributes['points']=points
- def get_points(self):
- return self._attributes.get('points')
-
-class polygon(polyline):
- """
- Class representing the polygon element of an svg doc.
- """
- def __init__(self, points=None, **kwargs):
- BaseElement.__init__(self,'polygon')
- self.set_points(points)
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from .attributes import *
+from .core import BaseElement, BaseShape, PointAttrib, DimensionAttrib, PointToAttrib
+
+
+class rect(BaseShape, PointAttrib, DimensionAttrib):
+ """
+ Class representing the rect element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, width=None, height=None, rx=None, ry=None, **kwargs):
+ BaseElement.__init__(self,'rect')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_height(height)
+ self.set_width(width)
+ self.set_rx(rx)
+ self.set_ry(ry)
+ self.setKWARGS(**kwargs)
+
+ def set_rx(self, rx):
+ self._attributes['rx']=rx
+ def get_rx(self):
+ return self._attributes.get('rx')
+
+ def set_ry(self, ry):
+ self._attributes['ry']=ry
+ def get_ry(self):
+ return self._attributes.get('ry')
+
+ #extra methods. Methods do rely on number values in the attributes. You might get an exception else!
+ def getEdgePoints(self):
+ """
+ Returns a list with the coordinates of the points at the edge of the rectangle as tuples.
+ e.g.[(x1,y1),(x2,y2)]
+ The sorting is counterclockwise starting with the lower left corner.
+ Coordinates must be numbers or an exception will be thrown.
+ """
+ result = [(float(self.get_x()),float(self.get_y()))]
+ result.append((float(self.get_x())+float(self.get_width()),float(self.get_y())))
+ result.append((float(self.get_x())+float(self.get_width()),float(self.get_y())+float(self.get_height())))
+ result.append((float(self.get_x()),float(self.get_y())+float(self.get_height())))
+ return result
+
+ def getInnerEdgePoints(self):
+ """
+ Returns a list with the coordinates of the points at the inner edge of a rounded rectangle as tuples.
+ e.g.[(x1,y1),(x2,y2)]
+ The sorting is counterclockwise starting with the lower left corner.
+ Coordinates must be numbers or an exception will be thrown.
+ """
+ result = []
+ result.append((float(self.get_x()) + float(self.get_rx()), float(self.get_y()) + float(self.get_ry())))
+ result.append((float(self.get_x()) + float(self.get_width()) - float(self.get_rx()), float(self.get_y()) + float(self.get_ry())))
+ 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())))
+ result.append((float(self.get_x()) + float(self.get_rx()), float(self.get_y()) + float(self.get_height()) - float(self.get_ry())))
+ return result
+
+ def getBottomLeft(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the lower left point of the rect.
+ Requires the coordinates, width, height to be numbers
+ """
+ return (float(self.get_x()), float(self.get_y()))
+
+ def getBottomRight(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the lower right point of the rect.
+ Requires the coordinates, width, height to be numbers
+ """
+ return (float(self.get_x()) + float(self.get_width()), float(self.get_y()))
+
+ def getTopLeft(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the upper left point of the rect.
+ Requires the coordinates, width, height to be numbers
+ """
+ return (float(self.get_x()), float(self.get_y())+ float(self.get_height()))
+
+ def getTopRight(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the upper right point of the rect.
+ Requires the coordinates, width, height to be numbers
+ """
+ return (float(self.get_x()) + float(self.get_width()), float(self.get_y()) + float(self.get_height()))
+
+ def moveToPoint(self, xxx_todo_changeme):
+ """
+ Moves the rect to the point x,y
+ """
+ (x,y) = xxx_todo_changeme
+ self.set_x(float(self.get_x()) + float(x))
+ self.set_y(float(self.get_y()) + float(y))
+
+
+class circle(BaseShape):
+ """
+ Class representing the circle element of an svg doc.
+ """
+ def __init__(self, cx=None,cy=None,r=None, **kwargs):
+ BaseElement.__init__(self,'circle')
+ self.set_cx(cx)
+ self.set_cy(cy)
+ self.set_r(r)
+ self.setKWARGS(**kwargs)
+
+ def set_cx(self, cx):
+ self._attributes['cx']=cx
+ def get_cx(self):
+ return self._attributes.get('cx')
+
+ def set_cy(self, cy):
+ self._attributes['cy']=cy
+ def get_cy(self):
+ return self._attributes.get('cy')
+
+ def set_r(self, r):
+ self._attributes['r']=r
+ def get_r(self):
+ return self._attributes.get('r')
+
+ #extra methods. Methods do rely on number values in the attributes. You might get an exception else!
+ def getDiameter(self):
+ """
+ Retrieves the diameter of the circle. Requires the radius to be a number
+ """
+ return 2 * float(self.get_r())
+
+ def getWidth(self):
+ """
+ Retrieves the width of the circle. Requires the radius to be a number
+ """
+ return self.getDiameter()
+
+ def getHeight(self):
+ """
+ Retrieves the height of the circle. Requires the radius to be a number
+ """
+ return self.getDiameter()
+
+ def getBottomLeft(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the lower left point of the circle.
+ Requires the radius and the coordinates to be numbers
+ """
+ return (float(self.get_cx()) - float(self.get_r()), float(self.get_cy()) - float(self.get_r()))
+
+ def getBottomRight(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the lower right point of the circle.
+ Requires the radius and the coordinates to be numbers
+ """
+ return (float(self.get_cx()) + float(self.get_r()), float(self.get_cy()) - float(self.get_r()))
+
+ def getTopLeft(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the upper left point of the circle.
+ Requires the radius and the coordinates to be numbers
+ """
+ return (float(self.get_cx()) - float(self.get_r()), float(self.get_cy()) + float(self.get_r()))
+
+ def getTopRight(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the upper right point of the circle.
+ Requires the radius and the coordinates to be numbers
+ """
+ return (float(self.get_cx()) + float(self.get_r()), float(self.get_cy()) + float(self.get_r()))
+
+ def moveToPoint(self, xxx_todo_changeme1):
+ """
+ Moves the circle to the point x,y
+ """
+ (x,y) = xxx_todo_changeme1
+ self.set_cx(float(self.get_cx()) + float(x))
+ self.set_cy(float(self.get_cy()) + float(y))
+
+class ellipse(BaseShape):
+ """
+ Class representing the ellipse element of an svg doc.
+ """
+ def __init__(self, cx=None,cy=None,rx=None,ry=None, **kwargs):
+ BaseElement.__init__(self,'ellipse')
+ self.set_cx(cx)
+ self.set_cy(cy)
+ self.set_rx(rx)
+ self.set_ry(ry)
+ self.setKWARGS(**kwargs)
+
+ def set_cx(self, cx):
+ self._attributes['cx']=cx
+ def get_cx(self):
+ return self._attributes.get('cx')
+
+ def set_cy(self, cy):
+ self._attributes['cy']=cy
+ def get_cy(self):
+ return self._attributes.get('cy')
+
+ def set_rx(self, rx):
+ self._attributes['rx']=rx
+ def get_rx(self):
+ return self._attributes.get('rx')
+
+ def set_ry(self, ry):
+ self._attributes['ry']=ry
+ def get_ry(self):
+ return self._attributes.get('ry')
+
+ #extra methods. Methods do rely on number values in the attributes. You might get an exception else!
+ def getWidth(self):
+ return abs(2 * float(self.get_rx()))
+
+ def getHeight(self):
+ return abs(2 * float(self.get_ry()))
+
+ def getBottomLeft(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the lower left point of the ellipse.
+ Requires the radius and the coordinates to be numbers
+ """
+ return (float(self.get_cx()) - float(self.get_rx()), float(self.get_cy()) - float(self.get_ry()))
+
+ def getBottomRight(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the lower right point of the ellipse.
+ Requires the radius and the coordinates to be numbers
+ """
+ return (float(self.get_cx()) + float(self.get_rx()), float(self.get_cy()) - float(self.get_ry()))
+
+ def getTopLeft(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the upper left point of the ellipse.
+ Requires the radius and the coordinates to be numbers
+ """
+ return (float(self.get_cx()) - float(self.get_rx()), float(self.get_cy()) + float(self.get_ry()))
+
+ def getTopRight(self):
+ """
+ Retrieves a tuple with the x,y coordinates of the upper right point of the ellipse.
+ Requires the radius and the coordinates to be numbers
+ """
+ return (float(self.get_cx()) + float(self.get_rx()), float(self.get_cy()) + float(self.get_ry()))
+
+class line(BaseShape, PointToAttrib):
+ """
+ Class representing the line element of an svg doc.
+ Note that this element is NOT painted VISIBLY by default UNLESS you provide
+ a style including STROKE and STROKE-WIDTH
+ """
+ def __init__(self, X1=None, Y1=None, X2=None, Y2=None, **kwargs):
+ """
+ Creates a line
+ @type X1: string or int
+ @param X1: starting x-coordinate
+ @type Y1: string or int
+ @param Y1: starting y-coordinate
+ @type X2: string or int
+ @param X2: ending x-coordinate
+ @type Y2: string or int
+ @param Y2: ending y-coordinate
+ """
+ BaseElement.__init__(self,'line')
+ self.set_x1(X1)
+ self.set_y1(Y1)
+ self.set_x2(X2)
+ self.set_y2(Y2)
+ self.setKWARGS(**kwargs)
+
+ def set_x1(self, x1):
+ self._attributes['x1']=x1
+ def get_x1(self):
+ return self._attributes.get('x1')
+
+ def set_y1(self, y1):
+ self._attributes['y1']=y1
+ def get_y1(self):
+ return self._attributes.get('y1')
+
+ def set_x2(self, x2):
+ self._attributes['x2']=x2
+ def get_x2(self):
+ return self._attributes.get('x2')
+
+ def set_y2(self, y2):
+ self._attributes['y2']=y2
+ def get_y2(self):
+ return self._attributes.get('y2')
+
+ #extra methods. Methods do rely on number values in the attributes. You might get an exception else!
+ def getWidth(self):
+ """
+ Retrieves the width of the line. This is always a positive number.
+ Coordinates must be numbers.
+ """
+ return abs(float(self.get_x1()) - float(self.get_x2()))
+
+ def getHeight(self):
+ """
+ Retrieves the height of the line. This is always a positive number.
+ Coordinates must be numbers.
+ """
+ return abs(float(self.get_y1()) - float(self.get_y2()))
+
+ def getBottomLeft(self):
+ """
+ Retrieves the the bottom left coordinate of the line as tuple.
+ Coordinates must be numbers.
+ """
+ x1 = float(self.get_x1())
+ x2 = float(self.get_x2())
+ y1 = float(self.get_y1())
+ y2 = float(self.get_y2())
+ if x1 < x2:
+ if y1 < y2:
+ return (x1, y1)
+ else:
+ return (x1, y2)
+ else:
+ if y1 < y2:
+ return (x2, y1)
+ else:
+ return (x2, y2)
+
+ def getBottomRight(self):
+ """
+ Retrieves the the bottom right coordinate of the line as tuple.
+ Coordinates must be numbers.
+ """
+ x1 = float(self.get_x1())
+ x2 = float(self.get_x2())
+ y1 = float(self.get_y1())
+ y2 = float(self.get_y2())
+ if x1 < x2:
+ if y1 < y2:
+ return (x2, y1)
+ else:
+ return (x2, y2)
+ else:
+ if y1 < y2:
+ return (x1, y1)
+ else:
+ return (x1, y2)
+
+ def getTopRight(self):
+ """
+ Retrieves the the top right coordinate of the line as tuple.
+ Coordinates must be numbers.
+ """
+ x1 = float(self.get_x1())
+ x2 = float(self.get_x2())
+ y1 = float(self.get_y1())
+ y2 = float(self.get_y2())
+ if x1 < x2:
+ if y1 < y2:
+ return (x2, y2)
+ else:
+ return (x2, y1)
+ else:
+ if y1 < y2:
+ return (x1, y2)
+ else:
+ return (x1, y1)
+
+ def getTopLeft(self):
+ """
+ Retrieves the the top left coordinate of the line as tuple.
+ Coordinates must be numbers.
+ """
+ x1 = float(self.get_x1())
+ x2 = float(self.get_x2())
+ y1 = float(self.get_y1())
+ y2 = float(self.get_y2())
+ if x1 < x2:
+ if y1 < y2:
+ return (x1, y2)
+ else:
+ return (x1, y1)
+ else:
+ if y1 < y2:
+ return (x2, y2)
+ else:
+ return (x2, y1)
+
+ def moveToPoint(self, xxx_todo_changeme2):
+ """
+ Moves the line to the point x,y
+ """
+ (x,y) = xxx_todo_changeme2
+ self.set_x1(float(self.get_x1()) + float(x))
+ self.set_x2(float(self.get_x2()) + float(x))
+ self.set_y1(float(self.get_y1()) + float(y))
+ self.set_y2(float(self.get_y2()) + float(y))
+
+class path(BaseShape, ExternalAttrib, MarkerAttrib):
+ """
+ Class representing the path element of an svg doc.
+ """
+ def __init__(self, pathData="",pathLength=None, style=None, focusable=None, **kwargs):
+ BaseElement.__init__(self,'path')
+ if pathData!='' and not pathData.endswith(' '):
+ pathData+=' '
+ self.set_d(pathData)
+ if style!=None:
+ self.set_style(style)
+ self.setKWARGS(**kwargs)
+
+ def set_d(self, d):
+ self._attributes['d']=d
+ def get_d(self):
+ return self._attributes.get('d')
+
+ def set_pathLength(self, pathLength):
+ self._attributes['pathLength']=pathLength
+ def get_pathLength(self):
+ return self._attributes.get('pathLength')
+
+ def __append__(self,command, params, relative=True):
+ d = self.get_d()
+ if relative==True:
+ d+=command.lower()
+ else:
+ d+=command.upper()
+ for param in params:
+ d+=' %s ' %(param)
+ self.set_d(d)
+
+ def appendLineToPath(self,endx,endy, relative=True):
+ self.__append__('l',[endx,endy], relative)
+
+ def appendHorizontalLineToPath(self,endx, relative=True):
+ self.__append__('h',[endx], relative)
+
+ def appendVerticalLineToPath(self,endy, relative=True):
+ self.__append__('v',[endy], relative)
+
+ def appendMoveToPath(self,endx,endy, relative=True):
+ self.__append__('m',[endx,endy], relative)
+
+ def appendCloseCurve(self):
+ d = self.get_d()
+ d+="z"
+ self.set_d(d)
+
+ def appendCubicCurveToPath(self, controlstartx, controlstarty, controlendx, controlendy, endx,endy,relative=True):
+ self.__append__('c',[controlstartx, controlstarty, controlendx, controlendy, endx,endy], relative)
+
+ def appendCubicShorthandCurveToPath(self, controlendx, controlendy, endx,endy,relative=True):
+ self.__append__('s',[controlendx, controlendy, endx,endy], relative)
+
+ def appendQuadraticCurveToPath(self, controlx, controly, endx,endy,relative=True):
+ self.__append__('q',[controlx, controly, endx,endy], relative)
+
+ def appendQuadraticShorthandCurveToPath(self, endx,endy,relative=True):
+ self.__append__('t',[endx,endy], relative)
+
+ def appendArcToPath(self,rx,ry,x,y,x_axis_rotation=0,large_arc_flag=0,sweep_flag=1 ,relative=True):
+ self.__append__('a',[rx,ry,x_axis_rotation,large_arc_flag,sweep_flag,x,y], relative)
+
+class polyline(BaseShape):
+ """
+ Class representing the polyline element of an svg doc.
+ """
+ def __init__(self, points=None, **kwargs):
+ BaseElement.__init__(self,'polyline')
+ self.set_points(points)
+ self.setKWARGS(**kwargs)
+
+ def set_points(self, points):
+ self._attributes['points']=points
+ def get_points(self):
+ return self._attributes.get('points')
+
+class polygon(polyline):
+ """
+ Class representing the polygon element of an svg doc.
+ """
+ def __init__(self, points=None, **kwargs):
+ BaseElement.__init__(self,'polygon')
+ self.set_points(points)
self.setKWARGS(**kwargs)
\ No newline at end of file
Only in pysvg-0.2.2b/src/pysvg: shape.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/structure.py pysvg-0.2.2b/src/pysvg/structure.py
--- pysvg-0.2.2b.orig/src/pysvg/structure.py 2012-11-15 14:39:54.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/structure.py 2016-07-15 11:11:22.045958470 -0500
@@ -1,222 +1,222 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-This module includes the elements found in http://www.w3.org/TR/SVG/struct.html
-
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from attributes import *
-from core import BaseElement, PointAttrib, DimensionAttrib
-
-
-
-
-class g(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib):
- """
- Class representing the g element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'g')
- self.setKWARGS(**kwargs)
-
- def set_transform(self, transform):
- self._attributes['transform'] = transform
- def get_transform(self):
- return self._attributes.get('transform')
-
-class defs(g):
- """
- Class representing the defs element of an svg doc.
- """
- def __init__(self,**kwargs):
- BaseElement.__init__(self, 'defs')
- self.setKWARGS(**kwargs)
-
-
-class desc(BaseElement, CoreAttrib, StyleAttrib):
- """
- Class representing the desc element of an svg doc.
- """
- def __init__(self,**kwargs):
- BaseElement.__init__(self, 'desc')
- self.setKWARGS(**kwargs)
-
-class title(desc):
- """
- Class representing the title element of an svg doc.
- """
- def __init__(self,**kwargs):
- BaseElement.__init__(self, 'title')
- self.setKWARGS(**kwargs)
-
-class metadata(BaseElement, CoreAttrib):
- """
- Class representing the metadata element of an svg doc.
- """
- def __init__(self,**kwargs):
- BaseElement.__init__(self, 'metadata')
- self.setKWARGS(**kwargs)
-
-class symbol(BaseElement, CoreAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib):
- """
- Class representing the symbol element of an svg doc.
- """
- def __init__(self,**kwargs):
- BaseElement.__init__(self, 'symbol')
- self.setKWARGS(**kwargs)
-
- def set_viewBox(self, viewBox):
- self._attributes['viewBox'] = viewBox
-
- def get_viewBox(self):
- return self._attributes['viewBox']
-
- def set_preserveAspectRatio(self, preserveAspectRatio):
- self._attributes['preserveAspectRatio'] = preserveAspectRatio
-
- def get_preserveAspectRatio(self):
- return self._attributes['preserveAspectRatio']
-
-class use(BaseElement, CoreAttrib, StyleAttrib, ConditionalAttrib, PointAttrib, DimensionAttrib, XLinkAttrib, PresentationAttributes_All, GraphicalEventsAttrib):
- """
- Class representing the use element of an svg doc.
- """
- def __init__(self,**kwargs):
- BaseElement.__init__(self, 'use')
- self.setKWARGS(**kwargs)
-
- def set_transform(self, transform):
- self._attributes['transform'] = transform
- def get_transform(self):
- return self._attributes.get('transform')
-
-class svg(BaseElement, CoreAttrib, StyleAttrib, ConditionalAttrib, PointAttrib, DimensionAttrib, XLinkAttrib, PresentationAttributes_All, GraphicalEventsAttrib, DocumentEventsAttrib):
- """
- Class representing the svg element of an svg doc.
- """
- def __init__(self, x=None, y=None, width=None, height=None,**kwargs):
- BaseElement.__init__(self, 'svg')
- self.set_xmlns('http://www.w3.org/2000/svg')
- self.set_xmlns_xlink('http://www.w3.org/1999/xlink')
- self.set_version('1.1')
- self.set_x(x)
- self.set_y(y)
- self.set_height(height)
- self.set_width(width)
- self.setKWARGS(**kwargs)
-
- def set_version(self, version):
- self._attributes['version'] = version
-
- def get_version(self):
- return self._attributes['version']
-
- def set_xmlns(self, xmlns):
- self._attributes['xmlns'] = xmlns
-
- def get_xmlns(self):
- return self._attributes['xmlns']
-
- def set_xmlns_xlink(self, xmlns_xlink):
- self._attributes['xmlns:xlink'] = xmlns_xlink
-
- def get_xmlns_xlink(self):
- return self._attributes.get('xmlns:xlink')
-
- def set_viewBox(self, viewBox):
- self._attributes['viewBox'] = viewBox
- def get_viewBox(self):
- return self._attributes['viewBox']
-
- def set_preserveAspectRatio(self, preserveAspectRatio):
- self._attributes['preserveAspectRatio'] = preserveAspectRatio
- def get_preserveAspectRatio(self):
- return self._attributes['preserveAspectRatio']
-
- def set_transform(self, transform):
- self._attributes['transform'] = transform
- def get_transform(self):
- return self._attributes.get('transform')
-
- def set_zoomAndPan(self, zoomAndPan):
- self._attributes['zoomAndPan'] = zoomAndPan
- def get_zoomAndPan(self):
- return self._attributes['zoomAndPan']
-
- def set_contentScriptType(self, contentScriptType):
- self._attributes['contentScriptType'] = contentScriptType
- def get_contentScriptType(self):
- return self._attributes['contentScriptType']
-
- def set_contentStyleType(self, contentStyleType):
- self._attributes['contentStyleType'] = contentStyleType
- def get_contentStyleType(self):
- return self._attributes['contentStyleType']
-
- def set_baseProfile(self, baseProfile):
- self._attributes['baseProfile'] = baseProfile
- def get_baseProfile(self):
- return self._attributes['baseProfile']
-#todo: check color.attrib and colorprofile.attrib. supposedly in image
-class image(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ViewportAttrib, PaintAttrib, OpacityAttrib, GraphicsAttrib, ClipAttrib, MaskAttrib, FilterAttrib, GraphicalEventsAttrib, CursorAttrib, XLinkAttrib, ExternalAttrib, PointAttrib, DimensionAttrib):
- """
- Class representing the image element of an svg doc.
- """
- def __init__(self, x=None, y=None, width=None, height=None, preserveAspectRatio=None,**kwargs):
- BaseElement.__init__(self, 'image')
- self.set_x(x)
- self.set_y(y)
- self.set_height(height)
- self.set_width(width)
- self.set_preserveAspectRatio(preserveAspectRatio)
- self.setKWARGS(**kwargs)
-
- #def set_embedded(self,embedded):
- # self._attributes['embedded']=embedded
-
- def set_preserveAspectRatio(self, preserveAspectRatio):
- self._attributes['preserveAspectRatio'] = preserveAspectRatio
- def get_preserveAspectRatio(self):
- return self._attributes['preserveAspectRatio']
-
- def set_transform(self, transform):
- self._attributes['transform'] = transform
- def get_transform(self):
- return self._attributes.get('transform')
-
-class switch(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, PresentationAttributes_All, GraphicalEventsAttrib, ExternalAttrib):
- """
- Class representing the switch element of an svg doc.
- """
- def __init__(self,**kwargs):
- BaseElement.__init__(self, 'switch')
- self.setKWARGS(**kwargs)
-
- def set_transform(self, transform):
- self._attributes['transform'] = transform
- def get_transform(self):
- return self._attributes.get('transform')
-
-class clipPath(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib):
- """
- Class representing the clipPath element of an svg doc.
- """
- def __init__(self, id=None, transform=None, clipPathUnits=None,**kwargs):
- BaseElement.__init__(self, 'clipPath')
- self.set_id(id)
- self.set_transform(transform)
- self.set_clipPathUnits(clipPathUnits)
- self.setKWARGS(**kwargs)
-
-
- def set_transform(self, transform):
- self._attributes['transform'] = transform
- def get_transform(self):
- return self._attributes.get('transform')
-
- def set_clipPathUnits(self, clipPathUnits):
- self._attributes['clipPathUnits'] = clipPathUnits
-
- def get_clipPathUnits(self):
- return self._attributes['clipPathUnits']
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+This module includes the elements found in http://www.w3.org/TR/SVG/struct.html
+
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from .attributes import *
+from .core import BaseElement, PointAttrib, DimensionAttrib
+
+
+
+
+class g(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib):
+ """
+ Class representing the g element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'g')
+ self.setKWARGS(**kwargs)
+
+ def set_transform(self, transform):
+ self._attributes['transform'] = transform
+ def get_transform(self):
+ return self._attributes.get('transform')
+
+class defs(g):
+ """
+ Class representing the defs element of an svg doc.
+ """
+ def __init__(self,**kwargs):
+ BaseElement.__init__(self, 'defs')
+ self.setKWARGS(**kwargs)
+
+
+class desc(BaseElement, CoreAttrib, StyleAttrib):
+ """
+ Class representing the desc element of an svg doc.
+ """
+ def __init__(self,**kwargs):
+ BaseElement.__init__(self, 'desc')
+ self.setKWARGS(**kwargs)
+
+class title(desc):
+ """
+ Class representing the title element of an svg doc.
+ """
+ def __init__(self,**kwargs):
+ BaseElement.__init__(self, 'title')
+ self.setKWARGS(**kwargs)
+
+class metadata(BaseElement, CoreAttrib):
+ """
+ Class representing the metadata element of an svg doc.
+ """
+ def __init__(self,**kwargs):
+ BaseElement.__init__(self, 'metadata')
+ self.setKWARGS(**kwargs)
+
+class symbol(BaseElement, CoreAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib):
+ """
+ Class representing the symbol element of an svg doc.
+ """
+ def __init__(self,**kwargs):
+ BaseElement.__init__(self, 'symbol')
+ self.setKWARGS(**kwargs)
+
+ def set_viewBox(self, viewBox):
+ self._attributes['viewBox'] = viewBox
+
+ def get_viewBox(self):
+ return self._attributes['viewBox']
+
+ def set_preserveAspectRatio(self, preserveAspectRatio):
+ self._attributes['preserveAspectRatio'] = preserveAspectRatio
+
+ def get_preserveAspectRatio(self):
+ return self._attributes['preserveAspectRatio']
+
+class use(BaseElement, CoreAttrib, StyleAttrib, ConditionalAttrib, PointAttrib, DimensionAttrib, XLinkAttrib, PresentationAttributes_All, GraphicalEventsAttrib):
+ """
+ Class representing the use element of an svg doc.
+ """
+ def __init__(self,**kwargs):
+ BaseElement.__init__(self, 'use')
+ self.setKWARGS(**kwargs)
+
+ def set_transform(self, transform):
+ self._attributes['transform'] = transform
+ def get_transform(self):
+ return self._attributes.get('transform')
+
+class svg(BaseElement, CoreAttrib, StyleAttrib, ConditionalAttrib, PointAttrib, DimensionAttrib, XLinkAttrib, PresentationAttributes_All, GraphicalEventsAttrib, DocumentEventsAttrib):
+ """
+ Class representing the svg element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, width=None, height=None,**kwargs):
+ BaseElement.__init__(self, 'svg')
+ self.set_xmlns('http://www.w3.org/2000/svg')
+ self.set_xmlns_xlink('http://www.w3.org/1999/xlink')
+ self.set_version('1.1')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_height(height)
+ self.set_width(width)
+ self.setKWARGS(**kwargs)
+
+ def set_version(self, version):
+ self._attributes['version'] = version
+
+ def get_version(self):
+ return self._attributes['version']
+
+ def set_xmlns(self, xmlns):
+ self._attributes['xmlns'] = xmlns
+
+ def get_xmlns(self):
+ return self._attributes['xmlns']
+
+ def set_xmlns_xlink(self, xmlns_xlink):
+ self._attributes['xmlns:xlink'] = xmlns_xlink
+
+ def get_xmlns_xlink(self):
+ return self._attributes.get('xmlns:xlink')
+
+ def set_viewBox(self, viewBox):
+ self._attributes['viewBox'] = viewBox
+ def get_viewBox(self):
+ return self._attributes['viewBox']
+
+ def set_preserveAspectRatio(self, preserveAspectRatio):
+ self._attributes['preserveAspectRatio'] = preserveAspectRatio
+ def get_preserveAspectRatio(self):
+ return self._attributes['preserveAspectRatio']
+
+ def set_transform(self, transform):
+ self._attributes['transform'] = transform
+ def get_transform(self):
+ return self._attributes.get('transform')
+
+ def set_zoomAndPan(self, zoomAndPan):
+ self._attributes['zoomAndPan'] = zoomAndPan
+ def get_zoomAndPan(self):
+ return self._attributes['zoomAndPan']
+
+ def set_contentScriptType(self, contentScriptType):
+ self._attributes['contentScriptType'] = contentScriptType
+ def get_contentScriptType(self):
+ return self._attributes['contentScriptType']
+
+ def set_contentStyleType(self, contentStyleType):
+ self._attributes['contentStyleType'] = contentStyleType
+ def get_contentStyleType(self):
+ return self._attributes['contentStyleType']
+
+ def set_baseProfile(self, baseProfile):
+ self._attributes['baseProfile'] = baseProfile
+ def get_baseProfile(self):
+ return self._attributes['baseProfile']
+#todo: check color.attrib and colorprofile.attrib. supposedly in image
+class image(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ViewportAttrib, PaintAttrib, OpacityAttrib, GraphicsAttrib, ClipAttrib, MaskAttrib, FilterAttrib, GraphicalEventsAttrib, CursorAttrib, XLinkAttrib, ExternalAttrib, PointAttrib, DimensionAttrib):
+ """
+ Class representing the image element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, width=None, height=None, preserveAspectRatio=None,**kwargs):
+ BaseElement.__init__(self, 'image')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_height(height)
+ self.set_width(width)
+ self.set_preserveAspectRatio(preserveAspectRatio)
+ self.setKWARGS(**kwargs)
+
+ #def set_embedded(self,embedded):
+ # self._attributes['embedded']=embedded
+
+ def set_preserveAspectRatio(self, preserveAspectRatio):
+ self._attributes['preserveAspectRatio'] = preserveAspectRatio
+ def get_preserveAspectRatio(self):
+ return self._attributes['preserveAspectRatio']
+
+ def set_transform(self, transform):
+ self._attributes['transform'] = transform
+ def get_transform(self):
+ return self._attributes.get('transform')
+
+class switch(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, PresentationAttributes_All, GraphicalEventsAttrib, ExternalAttrib):
+ """
+ Class representing the switch element of an svg doc.
+ """
+ def __init__(self,**kwargs):
+ BaseElement.__init__(self, 'switch')
+ self.setKWARGS(**kwargs)
+
+ def set_transform(self, transform):
+ self._attributes['transform'] = transform
+ def get_transform(self):
+ return self._attributes.get('transform')
+
+class clipPath(BaseElement, CoreAttrib, ConditionalAttrib, StyleAttrib, ExternalAttrib, PresentationAttributes_All, GraphicalEventsAttrib):
+ """
+ Class representing the clipPath element of an svg doc.
+ """
+ def __init__(self, id=None, transform=None, clipPathUnits=None,**kwargs):
+ BaseElement.__init__(self, 'clipPath')
+ self.set_id(id)
+ self.set_transform(transform)
+ self.set_clipPathUnits(clipPathUnits)
+ self.setKWARGS(**kwargs)
+
+
+ def set_transform(self, transform):
+ self._attributes['transform'] = transform
+ def get_transform(self):
+ return self._attributes.get('transform')
+
+ def set_clipPathUnits(self, clipPathUnits):
+ self._attributes['clipPathUnits'] = clipPathUnits
+
+ def get_clipPathUnits(self):
+ return self._attributes['clipPathUnits']
Only in pysvg-0.2.2b/src/pysvg: structure.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/style.py pysvg-0.2.2b/src/pysvg/style.py
--- pysvg-0.2.2b.orig/src/pysvg/style.py 2012-11-15 14:40:02.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/style.py 2016-07-15 11:11:22.059958392 -0500
@@ -1,34 +1,34 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from attributes import CoreAttrib, XLinkAttrib
-from core import BaseElement
-
-
-
-class style(BaseElement, CoreAttrib, XLinkAttrib):
- """
- Class representing the style element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self,'style')
- self.setKWARGS(**kwargs)
-
- def set_type(self, type):
- self._attributes['type']=type
- def get_type(self):
- return self._attributes.get('type')
-
- def set_media(self, media):
- self._attributes['media']=media
- def get_media(self):
- return self._attributes.get('media')
-
- def set_title(self, title):
- self._attributes['title']=title
- def get_title(self):
- return self._attributes.get('title')
-
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from .attributes import CoreAttrib, XLinkAttrib
+from .core import BaseElement
+
+
+
+class style(BaseElement, CoreAttrib, XLinkAttrib):
+ """
+ Class representing the style element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self,'style')
+ self.setKWARGS(**kwargs)
+
+ def set_type(self, type):
+ self._attributes['type']=type
+ def get_type(self):
+ return self._attributes.get('type')
+
+ def set_media(self, media):
+ self._attributes['media']=media
+ def get_media(self):
+ return self._attributes.get('media')
+
+ def set_title(self, title):
+ self._attributes['title']=title
+ def get_title(self):
+ return self._attributes.get('title')
+
Only in pysvg-0.2.2b/src/pysvg: style.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/text.py pysvg-0.2.2b/src/pysvg/text.py
--- pysvg-0.2.2b.orig/src/pysvg/text.py 2012-11-15 14:40:42.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/text.py 2016-07-15 11:11:22.137957959 -0500
@@ -1,169 +1,169 @@
-#!/usr/bin/python
-# -*- coding: iso-8859-1 -*-
-'''
-(C) 2008, 2009 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-from attributes import *
-from core import BaseElement, PointAttrib, DeltaPointAttrib, RotateAttrib
-
-class altGlyphDef(BaseElement, CoreAttrib):
- """
- Class representing the altGlyphDef element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'altGlypfDef')
- self.setKWARGS(**kwargs)
-
-class altGlyphItem(BaseElement, CoreAttrib):
- """
- Class representing the altGlyphItem element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'altGlypfItem')
- self.setKWARGS(**kwargs)
-
-class glyphRef(BaseElement, CoreAttrib, ExternalAttrib, StyleAttrib, FontAttrib, XLinkAttrib, PaintAttrib, PointAttrib, DeltaPointAttrib):
- """
- Class representing the glyphRef element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'glyphRef')
- self.setKWARGS(**kwargs)
-
- def set_glyphRef(self, glyphRef):
- self._attributes['glyphRef'] = glyphRef
- def get_glyphRef(self):
- return self._attributes.get('glyphRef')
-
- def set_format(self, format):
- self._attributes['format'] = format
- def get_format(self):
- return self._attributes.get('format')
-
- def set_lengthAdjust(self, lengthAdjust):
- self._attributes['lengthAdjust'] = lengthAdjust
- def get_lengthAdjust(self):
- return self._attributes.get('lengthAdjust')
-
-class altGlyph(glyphRef, ConditionalAttrib, GraphicalEventsAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib, RotateAttrib):
- """
- Class representing the altGlyph element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'altGlyph')
- self.setKWARGS(**kwargs)
-
- def set_textLength(self, textLength):
- self._attributes['textLength'] = textLength
- def get_textLength(self):
- return self._attributes.get('textLength')
-
-class textPath(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, XLinkAttrib, FontAttrib, PaintAttrib, GraphicalEventsAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib):
- """
- Class representing the textPath element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'textPath')
- self.setKWARGS(**kwargs)
-
- def set_startOffset(self, startOffset):
- self._attributes['startOffset'] = startOffset
- def get_startOffset(self):
- return self._attributes.get('startOffset')
-
- def set_textLength(self, textLength):
- self._attributes['textLength'] = textLength
- def get_textLength(self):
- return self._attributes.get('textLength')
-
- def set_lengthAdjust(self, lengthAdjust):
- self._attributes['lengthAdjust'] = lengthAdjust
- def get_lengthAdjust(self):
- return self._attributes.get('lengthAdjust')
-
- def set_method(self, method):
- self._attributes['method'] = method
- def get_method(self):
- return self._attributes.get('method')
-
- def set_spacing(self, spacing):
- self._attributes['spacing'] = spacing
- def get_spacing(self):
- return self._attributes.get('spacing')
-
-class tref(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, XLinkAttrib, PointAttrib, DeltaPointAttrib, RotateAttrib, GraphicalEventsAttrib, PaintAttrib, FontAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib):
- """
- Class representing the tref element of an svg doc.
- """
- def __init__(self, **kwargs):
- BaseElement.__init__(self, 'tref')
- self.setKWARGS(**kwargs)
-
- def set_textLength(self, textLength):
- self._attributes['textLength'] = textLength
- def get_textLength(self):
- return self._attributes.get('textLength')
-
- def set_lengthAdjust(self, lengthAdjust):
- self._attributes['lengthAdjust'] = lengthAdjust
- def get_lengthAdjust(self):
- return self._attributes.get('lengthAdjust')
-
-class tspan(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, PointAttrib, DeltaPointAttrib, RotateAttrib, GraphicalEventsAttrib, PaintAttrib, FontAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib):
- """
- Class representing the tspan element of an svg doc.
- """
- def __init__(self, x=None, y=None, dx=None, dy=None, rotate=None, textLength=None, lengthAdjust=None, **kwargs):
- BaseElement.__init__(self, 'tspan')
- self.set_x(x)
- self.set_y(y)
- self.set_dx(dx)
- self.set_dy(dy)
- self.set_rotate(rotate)
- self.set_textLength(textLength)
- self.set_lengthAdjust(lengthAdjust)
- self.setKWARGS(**kwargs)
-
- def set_textLength(self, textLength):
- self._attributes['textLength'] = textLength
- def get_textLength(self):
- return self._attributes.get('textLength')
-
- def set_lengthAdjust(self, lengthAdjust):
- self._attributes['lengthAdjust'] = lengthAdjust
- def get_lengthAdjust(self):
- return self._attributes.get('lengthAdjust')
-
-class text(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, PointAttrib, DeltaPointAttrib, RotateAttrib, GraphicalEventsAttrib, PaintAttrib, FontAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib, TextAttrib):
- """
- Class representing the text element of an svg doc.
- """
- def __init__(self, content=None, x=None, y=None, dx=None, dy=None, rotate=None, textLength=None, lengthAdjust=None, **kwargs):
- BaseElement.__init__(self, 'text')
- if content <> None:
- self.appendTextContent(content)
- self.set_x(x)
- self.set_y(y)
- self.set_dx(dx)
- self.set_dy(dy)
- self.set_rotate(rotate)
- self.set_textLength(textLength)
- self.set_lengthAdjust(lengthAdjust)
- self.setKWARGS(**kwargs)
-
- def set_transform(self, transform):
- self._attributes['transform'] = transform
- def get_transform(self):
- return self._attributes.get('transform')
-
- def set_textLength(self, textLength):
- self._attributes['textLength'] = textLength
- def get_textLength(self):
- return self._attributes.get('textLength')
-
- def set_lengthAdjust(self, lengthAdjust):
- self._attributes['lengthAdjust'] = lengthAdjust
- def get_lengthAdjust(self):
- return self._attributes.get('lengthAdjust')
-
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+'''
+(C) 2008, 2009 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+from .attributes import *
+from .core import BaseElement, PointAttrib, DeltaPointAttrib, RotateAttrib
+
+class altGlyphDef(BaseElement, CoreAttrib):
+ """
+ Class representing the altGlyphDef element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'altGlypfDef')
+ self.setKWARGS(**kwargs)
+
+class altGlyphItem(BaseElement, CoreAttrib):
+ """
+ Class representing the altGlyphItem element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'altGlypfItem')
+ self.setKWARGS(**kwargs)
+
+class glyphRef(BaseElement, CoreAttrib, ExternalAttrib, StyleAttrib, FontAttrib, XLinkAttrib, PaintAttrib, PointAttrib, DeltaPointAttrib):
+ """
+ Class representing the glyphRef element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'glyphRef')
+ self.setKWARGS(**kwargs)
+
+ def set_glyphRef(self, glyphRef):
+ self._attributes['glyphRef'] = glyphRef
+ def get_glyphRef(self):
+ return self._attributes.get('glyphRef')
+
+ def set_format(self, format):
+ self._attributes['format'] = format
+ def get_format(self):
+ return self._attributes.get('format')
+
+ def set_lengthAdjust(self, lengthAdjust):
+ self._attributes['lengthAdjust'] = lengthAdjust
+ def get_lengthAdjust(self):
+ return self._attributes.get('lengthAdjust')
+
+class altGlyph(glyphRef, ConditionalAttrib, GraphicalEventsAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib, RotateAttrib):
+ """
+ Class representing the altGlyph element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'altGlyph')
+ self.setKWARGS(**kwargs)
+
+ def set_textLength(self, textLength):
+ self._attributes['textLength'] = textLength
+ def get_textLength(self):
+ return self._attributes.get('textLength')
+
+class textPath(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, XLinkAttrib, FontAttrib, PaintAttrib, GraphicalEventsAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib):
+ """
+ Class representing the textPath element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'textPath')
+ self.setKWARGS(**kwargs)
+
+ def set_startOffset(self, startOffset):
+ self._attributes['startOffset'] = startOffset
+ def get_startOffset(self):
+ return self._attributes.get('startOffset')
+
+ def set_textLength(self, textLength):
+ self._attributes['textLength'] = textLength
+ def get_textLength(self):
+ return self._attributes.get('textLength')
+
+ def set_lengthAdjust(self, lengthAdjust):
+ self._attributes['lengthAdjust'] = lengthAdjust
+ def get_lengthAdjust(self):
+ return self._attributes.get('lengthAdjust')
+
+ def set_method(self, method):
+ self._attributes['method'] = method
+ def get_method(self):
+ return self._attributes.get('method')
+
+ def set_spacing(self, spacing):
+ self._attributes['spacing'] = spacing
+ def get_spacing(self):
+ return self._attributes.get('spacing')
+
+class tref(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, XLinkAttrib, PointAttrib, DeltaPointAttrib, RotateAttrib, GraphicalEventsAttrib, PaintAttrib, FontAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib):
+ """
+ Class representing the tref element of an svg doc.
+ """
+ def __init__(self, **kwargs):
+ BaseElement.__init__(self, 'tref')
+ self.setKWARGS(**kwargs)
+
+ def set_textLength(self, textLength):
+ self._attributes['textLength'] = textLength
+ def get_textLength(self):
+ return self._attributes.get('textLength')
+
+ def set_lengthAdjust(self, lengthAdjust):
+ self._attributes['lengthAdjust'] = lengthAdjust
+ def get_lengthAdjust(self):
+ return self._attributes.get('lengthAdjust')
+
+class tspan(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, PointAttrib, DeltaPointAttrib, RotateAttrib, GraphicalEventsAttrib, PaintAttrib, FontAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib):
+ """
+ Class representing the tspan element of an svg doc.
+ """
+ def __init__(self, x=None, y=None, dx=None, dy=None, rotate=None, textLength=None, lengthAdjust=None, **kwargs):
+ BaseElement.__init__(self, 'tspan')
+ self.set_x(x)
+ self.set_y(y)
+ self.set_dx(dx)
+ self.set_dy(dy)
+ self.set_rotate(rotate)
+ self.set_textLength(textLength)
+ self.set_lengthAdjust(lengthAdjust)
+ self.setKWARGS(**kwargs)
+
+ def set_textLength(self, textLength):
+ self._attributes['textLength'] = textLength
+ def get_textLength(self):
+ return self._attributes.get('textLength')
+
+ def set_lengthAdjust(self, lengthAdjust):
+ self._attributes['lengthAdjust'] = lengthAdjust
+ def get_lengthAdjust(self):
+ return self._attributes.get('lengthAdjust')
+
+class text(BaseElement, CoreAttrib, ConditionalAttrib, ExternalAttrib, StyleAttrib, PointAttrib, DeltaPointAttrib, RotateAttrib, GraphicalEventsAttrib, PaintAttrib, FontAttrib, OpacityAttrib, GraphicsAttrib, CursorAttrib, FilterAttrib, MaskAttrib, ClipAttrib, TextContentAttrib, TextAttrib):
+ """
+ Class representing the text element of an svg doc.
+ """
+ def __init__(self, content=None, x=None, y=None, dx=None, dy=None, rotate=None, textLength=None, lengthAdjust=None, **kwargs):
+ BaseElement.__init__(self, 'text')
+ if content != None:
+ self.appendTextContent(content)
+ self.set_x(x)
+ self.set_y(y)
+ self.set_dx(dx)
+ self.set_dy(dy)
+ self.set_rotate(rotate)
+ self.set_textLength(textLength)
+ self.set_lengthAdjust(lengthAdjust)
+ self.setKWARGS(**kwargs)
+
+ def set_transform(self, transform):
+ self._attributes['transform'] = transform
+ def get_transform(self):
+ return self._attributes.get('transform')
+
+ def set_textLength(self, textLength):
+ self._attributes['textLength'] = textLength
+ def get_textLength(self):
+ return self._attributes.get('textLength')
+
+ def set_lengthAdjust(self, lengthAdjust):
+ self._attributes['lengthAdjust'] = lengthAdjust
+ def get_lengthAdjust(self):
+ return self._attributes.get('lengthAdjust')
+
Only in pysvg-0.2.2b/src/pysvg: text.py.bak
diff -U3 -r pysvg-0.2.2b.orig/src/pysvg/turtle.py pysvg-0.2.2b/src/pysvg/turtle.py
--- pysvg-0.2.2b.orig/src/pysvg/turtle.py 2012-11-15 14:40:58.000000000 -0600
+++ pysvg-0.2.2b/src/pysvg/turtle.py 2016-07-15 11:11:22.207957571 -0500
@@ -1,206 +1,206 @@
-'''
-(C) 2008, 2009, 2010 Kerim Mansour
-For licensing information please refer to license.txt
-'''
-import math
-from shape import polyline
-
-class Vector(object):
- """
- Class representing a vector. Used to determine position of the turtle as well as heading.
- Also used to calculate movement.
- Vector class is inspired by tips and code from:
- - http://slowchop.com/2006/07/15/a-fast-python-vector-class/
- - http://www.kokkugia.com/wiki/index.php5?title=Python_vector_class
- - http://xturtle.rg16.at/code/xturtle.py
- """
- __slots__ = ('x', 'y')
- def __init__(self, x, y):
- """ Initializes the vector.
- x and y are coordinates and should be numbers.
- They will be cast to floats
- """
- self.x = float(x)
- self.y = float(y)
-
- def __add__(self, vector):
- return Vector(self.x + vector.x, self.y + vector.y)
-
- def __sub__(self, vector):
- return Vector(self.x - vector.x, self.y - vector.y)
-
- def __mul__(self, vector):
- if isinstance(vector, Vector):
- return self.x * vector.x + self.y * vector.y
- return Vector(self.x * vector, self.y * vector)
-
- def __rmul__(self, vector):
- if isinstance(vector, int) or isinstance(vector, float):
- return Vector(self.x * vector, self.y * vector)
-
- def __neg__(self):
- return Vector(-self.x, -self.y)
-
- def __abs__(self):
- return (self.x ** 2 + self.y ** 2) ** 0.5
-
- def rotate(self, angle):
- """Rotates self counterclockwise by angle
- (the angle must be given in a 360 degree system)
- """
- perp = Vector(-self.y, self.x)
- angle = angle * math.pi / 180.0
- c, s = math.cos(angle), math.sin(angle)
- return Vector(self.x * c + perp.x * s, self.y * c + perp.y * s)
-
- def __getnewargs__(self):
- return (self.x, self.y)
-
- def __repr__(self):
- return "%.2f,%.2f " % (self.x, self.y)
-
-class Turtle(object):
- """
- Class representing a classical turtle object known from logo and other implementations.
- 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.
- A turtle will only actually draw when the pen is down (default=false).
- An xml representation usable for pysvg can ge retrieved using the getXML()-method.
- To add the turtles paths to an svg you have two opions:
- Either you simply call "addTurtlePathToSVG" or you can create an svg element and append the Elements of the turtle using a loop, e.g:
- s=svg(...)
- t=Turtle(...)
- for element in t.getSVGElements():
- s.addElement(element)
- """
- def __init__(self, initialPosition=Vector(0.0, 0.0), initialOrientation=Vector(1.0, 0.0), fill='white', stroke='black', strokeWidth='1', penDown=False):
- """ Initializes a new Turtle with a new initial position and orientation as well as defaultvalues for style.
- """
- self.fill = fill
- self.stroke = stroke
- self.strokeWidth = strokeWidth
- self._position = initialPosition
- self._orient = initialOrientation
- self._penDown = penDown
- self._svgElements = []
- self._pointsOfPolyline = []
-
-
- def forward(self, distance):
- """ Moves the turtle forwards by distance in the direction it is facing.
- If the pen is lowered it will also add to the currently drawn polyline.
- """
- self._move(distance)
-
- def backward(self, distance):
- """ Moves the turtle backwards by distance in the direction it is facing.
- If the pen is lowered it will also add to the currently drawn polyline.
- """
- self._move(-distance)
-
- def right(self, angle):
- """Rotates the turtle to the right by angle.
- """
- self._rotate(angle)
-
- def left(self, angle):
- """Rotates the turtle to the left by angle.
- """
- self._rotate(-angle)
-
- def moveTo(self, vector):
- """ Moves the turtle to the new position. Orientation is kept as it is.
- If the pen is lowered it will also add to the currently drawn polyline.
- """
- self._position = vector
- if self.isPenDown():
- self._pointsOfPolyline.append(self._position)
-
- def penUp(self):
- """ Raises the pen. Any movement will not draw lines till pen is lowered again.
- """
- if self._penDown==True:
- self._penDown = False
- self._addPolylineToElements()
-
- def penDown(self):
- """ Lowers the pen down again. A new polyline will be created for drawing.
- Old polylines will be stored in the stack
- """
- #if self._penDown==False:
- self._penDown = True
- self._addPolylineToElements()
-
- def finish(self):
- """MUST be called when drawing is finished. Else the last path will not be added to the stack.
- """
- self._addPolylineToElements()
-
- def isPenDown(self):
- """ Retrieve current status of the pen.(boolean)
- """
- return self._penDown
-
- def getPosition(self):
- """ Retrieve current position of the turtle.(Vector)
- """
- return self._position
-
- def getOrientation(self):
- """ Retrieve current orientation of the turtle.(Vector)
- """
- return self._orient
-
- def setOrientation(self, vec):
- """ Sets the orientation of the turtle.(Vector)
- """
- self._orient=vec
-
- def _move(self, distance):
- """ Moves the turtle by distance in the direction it is facing.
- If the pen is lowered it will also add to the currently drawn polyline.
- """
- self._position = self._position + self._orient * distance
- if self.isPenDown():
- x = round(self._position.x, 2)
- y = round(self._position.y, 2)
- self._pointsOfPolyline.append(Vector(x, y))
-
- def _rotate(self, angle):
- """Rotates the turtle.
- """
- self._orient = self._orient.rotate(angle)
-
- def _addPolylineToElements(self):
- """Creates a new Polyline element that will be used for future movement/drawing.
- The old one (if filled) will be stored on the movement stack.
- """
- if (len(self._pointsOfPolyline) > 1):
- s = ''
- for point in self._pointsOfPolyline:
- s += str(point) + ' '#str(point.x) + ',' + str(point.y) + ' '
- p = polyline(s)
- p.set_style('fill:' + self.fill + '; stroke:' + self.stroke + '; stroke-width:' + self.strokeWidth)
- self._svgElements.append(p)
- self._pointsOfPolyline = []
- self._pointsOfPolyline.append(Vector(self._position.x, self._position.y))
-
- def getXML(self):
- """Retrieves the pysvg elements that make up the turtles path and returns them as String in an xml representation.
- """
- s = ''
- for element in self._svgElements:
- s += element.getXML()
- return s
-
- def getSVGElements(self):
- """Retrieves the pysvg elements that make up the turtles path and returns them as list.
- """
- return self._svgElements
-
- def addTurtlePathToSVG(self, svgContainer):
- """Adds the paths of the turtle to an existing svg container.
- """
- for element in self.getSVGElements():
- svgContainer.addElement(element)
- return svgContainer
+'''
+(C) 2008, 2009, 2010 Kerim Mansour
+For licensing information please refer to license.txt
+'''
+import math
+from .shape import polyline
+
+class Vector(object):
+ """
+ Class representing a vector. Used to determine position of the turtle as well as heading.
+ Also used to calculate movement.
+ Vector class is inspired by tips and code from:
+ - http://slowchop.com/2006/07/15/a-fast-python-vector-class/
+ - http://www.kokkugia.com/wiki/index.php5?title=Python_vector_class
+ - http://xturtle.rg16.at/code/xturtle.py
+ """
+ __slots__ = ('x', 'y')
+ def __init__(self, x, y):
+ """ Initializes the vector.
+ x and y are coordinates and should be numbers.
+ They will be cast to floats
+ """
+ self.x = float(x)
+ self.y = float(y)
+
+ def __add__(self, vector):
+ return Vector(self.x + vector.x, self.y + vector.y)
+
+ def __sub__(self, vector):
+ return Vector(self.x - vector.x, self.y - vector.y)
+
+ def __mul__(self, vector):
+ if isinstance(vector, Vector):
+ return self.x * vector.x + self.y * vector.y
+ return Vector(self.x * vector, self.y * vector)
+
+ def __rmul__(self, vector):
+ if isinstance(vector, int) or isinstance(vector, float):
+ return Vector(self.x * vector, self.y * vector)
+
+ def __neg__(self):
+ return Vector(-self.x, -self.y)
+
+ def __abs__(self):
+ return (self.x ** 2 + self.y ** 2) ** 0.5
+
+ def rotate(self, angle):
+ """Rotates self counterclockwise by angle
+ (the angle must be given in a 360 degree system)
+ """
+ perp = Vector(-self.y, self.x)
+ angle = angle * math.pi / 180.0
+ c, s = math.cos(angle), math.sin(angle)
+ return Vector(self.x * c + perp.x * s, self.y * c + perp.y * s)
+
+ def __getnewargs__(self):
+ return (self.x, self.y)
+
+ def __repr__(self):
+ return "%.2f,%.2f " % (self.x, self.y)
+
+class Turtle(object):
+ """
+ Class representing a classical turtle object known from logo and other implementations.
+ 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.
+ A turtle will only actually draw when the pen is down (default=false).
+ An xml representation usable for pysvg can ge retrieved using the getXML()-method.
+ To add the turtles paths to an svg you have two opions:
+ Either you simply call "addTurtlePathToSVG" or you can create an svg element and append the Elements of the turtle using a loop, e.g:
+ s=svg(...)
+ t=Turtle(...)
+ for element in t.getSVGElements():
+ s.addElement(element)
+ """
+ def __init__(self, initialPosition=Vector(0.0, 0.0), initialOrientation=Vector(1.0, 0.0), fill='white', stroke='black', strokeWidth='1', penDown=False):
+ """ Initializes a new Turtle with a new initial position and orientation as well as defaultvalues for style.
+ """
+ self.fill = fill
+ self.stroke = stroke
+ self.strokeWidth = strokeWidth
+ self._position = initialPosition
+ self._orient = initialOrientation
+ self._penDown = penDown
+ self._svgElements = []
+ self._pointsOfPolyline = []
+
+
+ def forward(self, distance):
+ """ Moves the turtle forwards by distance in the direction it is facing.
+ If the pen is lowered it will also add to the currently drawn polyline.
+ """
+ self._move(distance)
+
+ def backward(self, distance):
+ """ Moves the turtle backwards by distance in the direction it is facing.
+ If the pen is lowered it will also add to the currently drawn polyline.
+ """
+ self._move(-distance)
+
+ def right(self, angle):
+ """Rotates the turtle to the right by angle.
+ """
+ self._rotate(angle)
+
+ def left(self, angle):
+ """Rotates the turtle to the left by angle.
+ """
+ self._rotate(-angle)
+
+ def moveTo(self, vector):
+ """ Moves the turtle to the new position. Orientation is kept as it is.
+ If the pen is lowered it will also add to the currently drawn polyline.
+ """
+ self._position = vector
+ if self.isPenDown():
+ self._pointsOfPolyline.append(self._position)
+
+ def penUp(self):
+ """ Raises the pen. Any movement will not draw lines till pen is lowered again.
+ """
+ if self._penDown==True:
+ self._penDown = False
+ self._addPolylineToElements()
+
+ def penDown(self):
+ """ Lowers the pen down again. A new polyline will be created for drawing.
+ Old polylines will be stored in the stack
+ """
+ #if self._penDown==False:
+ self._penDown = True
+ self._addPolylineToElements()
+
+ def finish(self):
+ """MUST be called when drawing is finished. Else the last path will not be added to the stack.
+ """
+ self._addPolylineToElements()
+
+ def isPenDown(self):
+ """ Retrieve current status of the pen.(boolean)
+ """
+ return self._penDown
+
+ def getPosition(self):
+ """ Retrieve current position of the turtle.(Vector)
+ """
+ return self._position
+
+ def getOrientation(self):
+ """ Retrieve current orientation of the turtle.(Vector)
+ """
+ return self._orient
+
+ def setOrientation(self, vec):
+ """ Sets the orientation of the turtle.(Vector)
+ """
+ self._orient=vec
+
+ def _move(self, distance):
+ """ Moves the turtle by distance in the direction it is facing.
+ If the pen is lowered it will also add to the currently drawn polyline.
+ """
+ self._position = self._position + self._orient * distance
+ if self.isPenDown():
+ x = round(self._position.x, 2)
+ y = round(self._position.y, 2)
+ self._pointsOfPolyline.append(Vector(x, y))
+
+ def _rotate(self, angle):
+ """Rotates the turtle.
+ """
+ self._orient = self._orient.rotate(angle)
+
+ def _addPolylineToElements(self):
+ """Creates a new Polyline element that will be used for future movement/drawing.
+ The old one (if filled) will be stored on the movement stack.
+ """
+ if (len(self._pointsOfPolyline) > 1):
+ s = ''
+ for point in self._pointsOfPolyline:
+ s += str(point) + ' '#str(point.x) + ',' + str(point.y) + ' '
+ p = polyline(s)
+ p.set_style('fill:' + self.fill + '; stroke:' + self.stroke + '; stroke-width:' + self.strokeWidth)
+ self._svgElements.append(p)
+ self._pointsOfPolyline = []
+ self._pointsOfPolyline.append(Vector(self._position.x, self._position.y))
+
+ def getXML(self):
+ """Retrieves the pysvg elements that make up the turtles path and returns them as String in an xml representation.
+ """
+ s = ''
+ for element in self._svgElements:
+ s += element.getXML()
+ return s
+
+ def getSVGElements(self):
+ """Retrieves the pysvg elements that make up the turtles path and returns them as list.
+ """
+ return self._svgElements
+
+ def addTurtlePathToSVG(self, svgContainer):
+ """Adds the paths of the turtle to an existing svg container.
+ """
+ for element in self.getSVGElements():
+ svgContainer.addElement(element)
+ return svgContainer
\ No newline at end of file
Only in pysvg-0.2.2b/src/pysvg: turtle.py.bak