def __init__(self, text, insert=None, x=[], y=[], dx=[], dy=[], rotate=[], **extra): """ :param string text: **tspan** content :param 2-tuple insert: The **insert** parameter is the absolute insert point of the text, don't use this parameter in combination with the **x** or the **y** parameter. :param list x: list of absolute x-axis values for characters :param list y: list of absolute y-axis values for characters :param list dx: list of relative x-axis values for characters :param list dy: list of relative y-axis values for characters :param list rotate: list of rotation-values for characters (in degrees) """ super(TSpan, self).__init__(**extra) self.text = text if insert is not None: if is_string(insert): raise TypeError("'insert' should be a <tuple> or a <list> with" \ " at least two elements.") if x or y: raise ValueError("Use 'insert' and 'x' or 'y' parameter not" \ " at the same time!") x = [insert[0]] y = [insert[1]] if x: self['x'] = strlist(list(iterflatlist(x)), ' ') if y: self['y'] = strlist(list(iterflatlist(y)), ' ') if dx: self['dx'] = strlist(list(iterflatlist(dx)), ' ') if dy: self['dy'] = strlist(list(iterflatlist(dy)), ' ') if rotate: self['rotate'] = strlist(list(iterflatlist(rotate)), ' ')
def set_value(self, values, calcMode=None, keyTimes=None, keySplines=None, from_=None, to=None, by=None): """ Set animation attributes :ref:`values`, :ref:`calcMode`, :ref:`keyTimes`, :ref:`keySplines`, :ref:`from`, :ref:`to` and :ref:`by`. """ if values is not None: if not is_string(values): values = strlist(values, ';') self['values'] = values if calcMode is not None: self['calcMode'] = calcMode if keyTimes is not None: self['keyTimes'] = keyTimes if keySplines is not None: self['keySplines'] = keySplines if from_ is not None: self['from'] = from_ if to is not None: self['to'] = to if by is not None: self['by'] = by
def __init__(self, start=None, size=None, resolution=None, inherit=None, **extra): """ :param 2-tuple start: defines the start point of the filter effects region (**x**, **y**) :param 2-tuple size: defines the size of the filter effects region (**width**, **height**) :param resolution: takes the form ``'x-pixels [y-pixels]'``, and indicates the width and height of the intermediate images in pixels. :param inherit: inherits properties from Filter `inherit` see: **xlink:href** """ super(Filter, self).__init__(**extra) if start is not None: self['x'] = start[0] self['y'] = start[1] if size is not None: self['width'] = size[0] self['height'] = size[1] if resolution is not None: if is_string(resolution): self['filterRes'] = resolution elif hasattr(resolution, '__iter__'): self['filterRes'] = strlist(resolution, ' ') else: self['filterRes'] = str(resolution) if inherit is not None: self.href = inherit self.update_id()
def get_xml(self): """ Get the XML representation as `ElementTree` object. :return: XML `ElementTree` of this object and all its subelements """ self.attribs['d'] = str(strlist(self.commands, ' ')) return super(Path, self).get_xml()
def get_xml(self): """ Get the XML representation as `ElementTree` object. :return: XML `ElementTree` of this object and all its subelements """ self.attribs['d'] = to_unicode(strlist(self.commands, ' ')) return super(Path, self).get_xml()
def translate(self, tx, ty=None): """ Specifies a translation by **tx** and **ty**. If **ty** is not provided, it is assumed to be zero. :param number tx: user coordinate - no units allowed :param number ty: user coordinate - no units allowed """ self._add_transformation("translate(%s)" % strlist( [tx, ty] ))
def translate(self, tx, ty=None): """ Specifies a translation by **tx** and **ty**. If **ty** is not provided, it is assumed to be zero. :param number tx: user coordinate - no units allowed :param number ty: user coordinate - no units allowed """ self._add_transformation("translate(%s)" % strlist([tx, ty]))
def scale(self, sx, sy=None): """ Specifies a scale operation by **sx** and **sy**. If **sy** is not provided, it is assumed to be equal to **sx**. :param number sx: scalar factor x-axis, no units allowed :param number sy: scalar factor y-axis, no units allowed """ self._add_transformation("scale(%s)" % strlist( [sx, sy] ))
def scale(self, sx, sy=None): """ Specifies a scale operation by **sx** and **sy**. If **sy** is not provided, it is assumed to be equal to **sx**. :param number sx: scalar factor x-axis, no units allowed :param number sy: scalar factor y-axis, no units allowed """ self._add_transformation("scale(%s)" % strlist([sx, sy]))
def rotate(self, angle, center=None): """ Specifies a rotation by **angle** degrees about a given point. If optional parameter **center** are not supplied, the rotate is about the origin of the current user coordinate system. :param number angle: rotate-angle in degrees :param 2-tuple center: rotate-center as user coordinate - no units allowed """ self._add_transformation("rotate(%s)" % strlist( [angle, center] ))
def rotate(self, angle, center=None): """ Specifies a rotation by **angle** degrees about a given point. If optional parameter **center** are not supplied, the rotate is about the origin of the current user coordinate system. :param number angle: rotate-angle in degrees :param 2-tuple center: rotate-center as user coordinate - no units allowed """ self._add_transformation("rotate(%s)" % strlist([angle, center]))
def viewbox(self, minx=0, miny=0, width=0, height=0): """ Specify a rectangle in **user space** (no units allowed) which should be mapped to the bounds of the viewport established by the given element. :param number minx: left border of the viewBox :param number miny: top border of the viewBox :param number width: width of the viewBox :param number height: height of the viewBox """ self['viewBox'] = strlist([minx, miny, width, height])
def viewbox(self, minx=0, miny=0, width=0, height=0): """ Specify a rectangle in **user space** (no units allowed) which should be mapped to the bounds of the viewport established by the given element. :param number minx: left border of the viewBox :param number miny: top border of the viewBox :param number width: width of the viewBox :param number height: height of the viewBox """ self['viewBox'] = strlist( [minx, miny, width, height] )
def dasharray(self, dasharray=None, offset=None): """ Set SVG Properties **stroke-dashoffset** and **stroke-dasharray**. Where *dasharray* specify the lengths of alternating dashes and gaps as <list> of <int> or <float> values or a <string> of comma and/or white space separated <lengths> or <percentages>. (e.g. as <list> dasharray=[1, 0.5] or as <string> dasharray='1 0.5') """ if dasharray: self['stroke-dasharray'] = strlist(dasharray, ' ') if offset: self['stroke-dashoffset'] = offset return self
def dasharray(self, dasharray=None, offset=None): """ Set SVG Properties **stroke-dashoffset** and **stroke-dasharray**. Where *dasharray* specify the lengths of alternating dashes and gaps as <list> of <int> or <float> values or a <string> of comma and/or white space separated <lengths> or <percentages>. (e.g. as <list> dasharray=[1, 0.5] or as <string> dasharray='1 0.5') """ if dasharray is not None: self['stroke-dasharray'] = strlist(dasharray, ' ') if offset is not None: self['stroke-dashoffset'] = offset return self
def test_basic_types(self): self.assertEqual(strlist([1, 2, 3]), "1,2,3") self.assertEqual(strlist([1, None, 3]), "1,3") self.assertEqual(strlist([1, 2, None]), "1,2")
def test_list(self): self.assertEqual(strlist([(5, 'abc', None), (1, 2, None)]), "5,abc,1,2") self.assertEqual(strlist([(1, None, 3), 4]), "1,3,4")
def test_string(self): self.assertEqual(strlist("5,abc,1,2"), "5,abc,1,2")
def test_basic_types(self): self.assertEqual(strlist([1,2,3]), "1,2,3" ) self.assertEqual(strlist([1,None,3]), "1,3") self.assertEqual(strlist([1,2,None]), "1,2")
def test_seperator(self): self.assertEqual(strlist([1,2,3], ' '), "1 2 3" ) self.assertEqual(strlist([1,None,3], ';'), "1;3") self.assertEqual(strlist([1,2,None], ':'), "1:2")
def matrix(self, a, b, c, d, e, f): self._add_transformation("matrix(%s)" % strlist([a, b, c, d, e, f]))
def test_list(self): self.assertEqual(strlist( [(5, 'abc', None), (1, 2, None)] ), "5,abc,1,2") self.assertEqual(strlist( [(1,None,3), 4]), "1,3,4")
def test_string(self): self.assertEqual(strlist("5,abc,1,2") , "5,abc,1,2")
def matrix(self, a, b, c, d, e, f): self._add_transformation("matrix(%s)" % strlist( [a, b, c, d, e, f] ))
def test_seperator(self): self.assertEqual(strlist([1, 2, 3], ' '), "1 2 3") self.assertEqual(strlist([1, None, 3], ';'), "1;3") self.assertEqual(strlist([1, 2, None], ':'), "1:2")