utils 模块#

utils module

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

Convert r, g, b values to a string.

参数:
  • r – red part

  • g – green part

  • b – blue part

  • mode (string) – 'RGB | %'

返回类型:

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.

参数:

valuesiterable object

返回:

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.

返回:

<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.

返回:

<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.

参数:
  • insert (2-tuple) – insert point

  • size (2-tuple) – (width, height)

  • pos (string) – insert position 'vert-horiz'

返回:

'top-left' corner of the rect

返回类型:

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.

参数:

xml_string – input xml string without line breaks and indentation

Indent int:

how much to indent, by default 2 spaces

返回:

xml_string with linebreaks and indentation