Drawing#
The Drawing object is the overall container for all SVG elements. It provides the methods to store the drawing into a file or a file-like object. If you want to use stylesheets, the reference links to this stylesheets were also stored (add_stylesheet) in the Drawing object.
set/get SVG attributes:
element['attribute'] = value
value = element['attribute']
The Drawing object also includes a defs section, add elements to the defs section by:
drawing.defs.add(element)
- class svgwrite.drawing.Drawing(filename='noname.svg', size=('100%', '100%'), **extra)#
This is the SVG drawing represented by the top level svg element.
A drawing consists of any number of SVG elements contained within the drawing element, stored in the elements attribute.
A drawing can range from an empty drawing (i.e., no content inside of the drawing), to a very simple drawing containing a single SVG element such as a rect, to a complex, deeply nested collection of container elements and graphics elements.
- Drawing.__init__(filename='noname.svg', size=('100%', '100%'), **extra)#
- 参数:
filename (string) – filesystem filename valid for
open()
size (2-tuple) – width, height
extra (keywords) – additional svg-attributes for the SVG object
Important (and not SVG Attributes) extra parameters:
- 参数:
profile (string) –
'tiny | full'
- define the SVG baseProfiledebug (bool) – switch validation on/off
属性#
Attributes
- Drawing.filename#
string should be valid for
open()
.
方法#
Methods
- Drawing.add(element)#
Add an SVG element as subelement.
- 参数:
element – append this SVG element
- 返回:
the added element
- Drawing.write(fileobj, pretty=False, indent=2)#
Write XML string to fileobj.
- 参数:
fileobj – a file-like object
pretty – True for easy readable output
indent – how much to indent if pretty is enabled, by default 2 spaces
Python 3.x - set encoding at the open command:
open('filename', 'w', encoding='utf-8')
- Drawing.save(pretty=False, indent=2)#
Write the XML string to self.filename.
- 参数:
pretty – True for easy readable output
indent – how much to indent if pretty is enabled, by default 2 spaces
- Drawing.saveas(filename, pretty=False, indent=2)#
Write the XML string to filename.
- 参数:
filename (string) – filesystem filename valid for
open()
pretty – True for easy readable output
indent – how much to indent if pretty is enabled, by default 2 spaces
- Drawing.add_stylesheet(href, title, alternate='no', media='screen')#
Add a stylesheet reference.
- 参数:
href (string) – link to stylesheet <URI>
title (string) – name of stylesheet
alternate (string) –
'yes'|'no'
media (string) –
'all | aureal | braille | embossed | handheld | print | projection | screen | tty | tv'
- Drawing.get_xml()#
Get the XML representation as ElementTree object.
- 返回:
XML ElementTree of this object and all its subelements
- Drawing.tostring()#
获取 XML 表示形式作为 unicode “字符串”。如果将 SVG 对象嵌入 XHTML 页面,则必须链接到周围 XHTML 页面标题部分中的 CSS 文件(如果使用 CSS 类)。
- return:
此对象及其所有子元素的 unicode XML 字符串
Get the XML representation as unicode string. If you embed the SVG object into a XHTML page, you have to link to the CSS files (if you use CSS classes) in the header section of the surrounding XHTML page.
- return:
unicode XML string of this object and all its subelements
工厂函数#
Factory Methods
- Drawing.line(start=(0, 0), end=(0, 0), \*\*extra)#
Create a
svgwrite.shapes.Line
object.
- Drawing.rect(insert=(0, 0), size=(1, 1), rx=None, ry=None, \*\*extra)#
Create a
svgwrite.shapes.Rect
object.
- Drawing.circle(center=(0, 0), r=1, \*\*extra)#
Create a
svgwrite.shapes.Circle
object.
- Drawing.ellipse(center=(0, 0), r=(1, 1), \*\*extra)#
Create a
svgwrite.shapes.Ellipse
object.
- Drawing.polyline(points=[], \*\*extra)#
Create a
svgwrite.shapes.Polyline
object.
- Drawing.polygon(points=[], \*\*extra)#
Create a
svgwrite.shapes.Polygon
object.
- Drawing.text(text, insert=None, x=[], y=[], dx=[], dy=[], rotate=[], \*\*extra)#
Create a
svgwrite.text.Text
object.
- Drawing.tspan(text, insert=None, x=[], y=[], dx=[], dy=[], rotate=[], \*\*extra)#
Create a
svgwrite.text.TSpan
object.
- Drawing.tref(element, \*\*extra)#
Create a
svgwrite.text.TRef
object.
- Drawing.textPath(path, text, startOffset=None, method='align', spacing='exact', \*\*extra)#
Create a
svgwrite.text.TextPath
object.
- Drawing.textArea(text=None, insert=None, size=None, \*\*extra)#
Create a
svgwrite.text.TextArea
object.
- Drawing.path(d=None, \*\*extra)#
Create a
svgwrite.path.Path
object.
- Drawing.image(href, insert=None, size=None, \*\*extra)#
Create a
svgwrite.image.Image
object.
- Drawing.g(\*\*extra)#
Create a
svgwrite.container.Group
object.
- Drawing.symbol(\*\*extra)#
Create a
svgwrite.container.Symbol
object.
- Drawing.svg(insert=None, size=None, \*\*extra)#
Create a
svgwrite.container.SVG
object.
- Drawing.use(href, insert=None, size=None, \*\*extra)#
Create a
svgwrite.container.Use
object.
- Drawing.a(href, target='_blank', \*\*extra)#
Create a
svgwrite.container.Hyperlink
object.
- Drawing.marker(insert=None, size=None, orient=None, \*\*extra)#
Create a
svgwrite.container.Marker
object.
- Drawing.script(href=None, content='', \*\*extra)#
Create a
svgwrite.container.Script
object.
- Drawing.style(content='', \*\*extra)#
Create a
svgwrite.container.Style
object.
- Drawing.linearGradient(start=None, end=None, inherit=None, \*\*extra)#
Create a
svgwrite.gradients.LinearGradient
object.
- Drawing.radialGradient(center=None, r=None, focal=None, inherit=None, \*\*extra)#
Create a
svgwrite.gradients.RadialGradient
object.
- Drawing.mask(start=None, size=None, \*\*extra)#
Create a
svgwrite.masking.Mask
object.
- Drawing.clipPath(\*\*extra)#
Create a
svgwrite.masking.ClipPath
object.
- Drawing.set(element=None, \*\*extra)#
Create a
svgwrite.animate.Set
object.
- Drawing.animate(element=None, \*\*extra)#
Create a
svgwrite.animate.Animate
object.
- Drawing.animateColor(element=None, \*\*extra)#
Create a
svgwrite.animate.AnimateColor
object.
- Drawing.animateMotion(element=None, \*\*extra)#
Create a
svgwrite.animate.AnimateMotion
object.
- Drawing.animateTransform(transform, element=None, \*\*extra)#
Create a
svgwrite.animate.AnimateTransform
object.
- Drawing.filter(start=None, size=None, resolution=None, inherit=None, \*\*extra)#
创建一个
svgwrite.filters.Filter
对象。(过滤器原语由 Filter 类的 工厂方法 创建)Create a
svgwrite.filters.Filter
object. (Filter Primitives are created by factory-methods of the class Filter)
父类#
Parent Classes
svgwrite.elementfactory.ElementFactory