SVG#
- class svgwrite.container.SVG(insert=None, size=None, **extra)#
A SVG document fragment consists of any number of SVG elements contained within an svg element.
An SVG document fragment can range from an empty fragment (i.e., no content inside of the svg element), to a very simple SVG document fragment containing a single SVG graphics element such as a rect, to a complex, deeply nested collection of container elements and graphics elements.
- SVG.__init__(insert=None, size=None, **extra)#
- 参数:
insert (2-tuple) – insert position (x, y)
size (2-tuple) – (width, height)
extra – additional SVG attributes as keyword-arguments
- SVG.embed_stylesheet(content)#
Add <style> tag to the defs section.
- 参数:
content – style sheet content as string
- 返回:
Style
object
- SVG.embed_font(name, filename)#
Embed font as base64 encoded data from font file.
- 参数:
name – font name
filename – file name of local stored font
- SVG.embed_google_web_font(name, uri)#
Embed font as base64 encoded data acquired from google fonts.
- 参数:
name – font name
uri – google fonts request uri like ‘http://fonts.googleapis.com/css?family=Indie+Flower’
属性#
Attributes
- SVG.defs#
引用元素的 Defs 容器
将 SVG 元素添加到 defs:
svgobject.defs.add(element)
Defs container for referenced elements
adding SVG elements to defs:
svgobject.defs.add(element)
父类#
Parent Classes
SVG 属性#
SVG Attributes
class – string
为元素分配一个或多个 CSS 类名。
style – string
允许直接在指定元素上定义每个元素的 CSS 样式规则。
externalResourcesRequired – bool
False:如果文档渲染可以继续进行,即使外部资源不可用;否则为 True。
transform – 使用
svgwrite.mixins.Transform
接口。x – <coordinate> – 插入 参数
(对
Drawing
无意义或无影响。)矩形区域的一个角的 x 轴坐标,该区域用于放置嵌入的 svg 元素。
默认值为
'0'
。y – <coordinate> – 插入 参数
(对
Drawing
无意义或无影响。)矩形区域的一个角的 y 轴坐标,该区域用于放置嵌入的 svg 元素。
默认值为
'0'
。width – <length> – 尺寸 参数
对于最外层的 svg 元素(
Drawing
),表示 SVG 文档片段的内在宽度。 对于嵌入的 svg 元素,表示 svg 元素被放置的矩形区域的宽度。负值是错误的。值为零时,将禁用该元素的渲染。
默认值为
'100%'
。height – <length> – 尺寸 参数
对于最外层的 svg 元素(
Drawing
),表示 SVG 文档片段的内在高度。 对于嵌入的 svg 元素,表示 svg 元素被放置的矩形区域的高度。负值是错误的。值为零时,将禁用该元素的渲染。
默认值为
'100%'
。viewBox –
svgwrite.mixins.ViewBox
接口。preserveAspectRatio –
svgwrite.mixins.ViewBox
接口。zoomAndPan –
'disable | magnify'
默认值为
'magnify'
。
备注
请勿设置或更改以下 SVG 属性: version、baseProfile、contentScriptType、contentStyleType。
class – string
assigns one or more css-class-names to an element
style – string
allows per-element css-style rules to be specified directly on a given element
externalResourcesRequired – bool
False: if document rendering can proceed even if external resources are unavailable else: True
transform – use
svgwrite.mixins.Transform
interfacex – <coordinate> – insert parameter
(Has no meaning or effect on
Drawing
.)The x-axis coordinate of one corner of the rectangular region into which an embedded svg element is placed.
Default is
'0'
.y – <coordinate> – insert parameter
(Has no meaning or effect on
Drawing
.)The y-axis coordinate of one corner of the rectangular region into which an embedded svg element is placed.
Default is
'0'
.width – <length> – size parameter
For outermost svg elements (
Drawing
), the intrinsic width of the SVG document fragment. For embedded svg elements, the width of the rectangular region into which the svg element is placed.A negative value is an error. A value of zero disables rendering of the element.
Default is
'100%'
.height – <length> – size parameter
For outermost svg elements (
Drawing
), the intrinsic height of the SVG document fragment. For embedded svg elements, the height of the rectangular region into which the svg element is placed.A negative value is an error. A value of zero disables rendering of the element.
Default is
'100%'
.viewBox –
svgwrite.mixins.ViewBox
interfacepreserveAspectRatio –
svgwrite.mixins.ViewBox
interfacezoomAndPan –
'disable | magnify'
Default is
'magnify'
.
备注
do not set or change following SVG attributes: version, baseProfile, contentScriptType, contentStyleType
标准 SVG 属性#
Standard SVG Attributes