utils module

svgwrite.utils.rgb(r=0, g=0, b=0, mode='RGB')

Convert r, g, b values to a string.

Parameters:
  • r – red part
  • g – green part
  • b – blue part
  • mode (string) – 'RGB | %'
Return type:

string

mode Description
'RGB' returns a rgb-string format: 'rgb(r, g, b)'
'%' returns percent-values as rgb-string format: 'rgb(r%, g%, b%)'
svgwrite.utils.iterflatlist(values)

Flatten nested values, returns an iterator.

svgwrite.utils.strlist(values, seperator=', ')

Concatenate values with sepertator, None values will be excluded.

Parameters:valuesiterable object
Returns:string
svgwrite.utils.get_unit(coordinate)

Get the unit identifier of coordinate, if coordinate has a valid unit identifier appended, else returns None.

svgwrite.utils.split_coordinate(coordinate)

Split coordinate into <number> and ‘unit` identifier.

Returns:<2-tuple> (number, unit-identifier) or (number, None) if no unit-identifier is present or coordinate is an int or float.
svgwrite.utils.split_angle(angle)

Split angle into <number> and <angle> identifier.

Returns:<2-tuple> (number, angle-identifier) or (number, None) if no angle-identifier is present or angle is an int or float.
svgwrite.utils.rect_top_left_corner(insert, size, pos='top-left')

Calculate top-left corner of a rectangle.

insert and size must have the same units.

Parameters:
  • insert (2-tuple) – insert point
  • size (2-tuple) – (width, height)
  • pos (string) – insert position 'vert-horiz'
Returns:

'top-left' corner of the rect

Return type:

2-tuple

pos valid values
vert 'top | middle | bottom'
horiz 'left'|'center'|'right'
svgwrite.utils.pretty_xml(xml_string, indent=2)

Create human readable XML string.

Parameters:xml_string – input xml string without line breaks and indentation
Indent int:how much to indent, by default 2 spaces
Returns:xml_string with linebreaks and indentation