The svg
element is the root element of the document.
It’s defined only once and can’t be nested, unlike the SVG spec.
Always present.
Children: defs
, g
, path
, text
and image
.
Attributes: width
, height
, viewBox
and preserveAspectRatio
.
Always present.
All defs
children have an id
attribute. It always set and newer empty.
Children: linearGradient
, radialGradient
, clipPath
, mask
, pattern
and filter
.
Gradient has all attributes resolved and at least two stop
children.
stop
children will always have unique, ordered offset
values.
Gradient doesn’t have xlink:href
attribute because all attributes and stop
children
are already resolved and copied to the gradient.
Children: stop
.
Attributes: id
, x1
, y1
, x2
, y2
, gradientUnits
, spreadMethod
,
gradientTransform
.
-
See
transform
forgradientTransform
.
See linearGradient
.
Children: stop
.
Attributes: id
, cx
, cy
, r
, fx
, fy
, gradientUnits
, spreadMethod
,
gradientTransform
.
-
r
always > 0. -
fx
andfy
are always inside the circle defined bycx
,cy
andr
. -
See
transform
forgradientTransform
.
Attributes: offset
, stop-color
, stop-opacity
.
-
offset
andstop-opacity
are always in 0..1 range. -
stop-color
is always a valid #RRGGBB color.
Pattern defines a texture image that can be used by fill
and stroke
.
Children: g
, path
, text
and image
.
Attributes: id
, patternUnits
, patternContentUnits
, transform
,
x
, y
, width
, height
, viewBox
and preserveAspectRatio
.
clipPath
defines a 1-bit mask using children elements.
Children: path
and text
.
Attributes: id
, clipPathUnits
, transform
and clip-path
.
Children: g
, path
, text
and image
.
Attributes: id
, maskUnits
, maskContentUnits
, x
, y
, width
and height
.
The group element indicates that a new canvas should be created. All groups children elements will be rendered on it and then merged into the parent canvas.
Since it’s pretty expensive, especially memory wise, usvg will remove as many groups as possible. All the remaining one will indicate that a new canvas must be created.
A group can be empty when it has a filter
attribute.
Children: g
, path
, text
and image
.
Attributes: id
, transform
, opacity
, clip-path
, mask
and filter
.
-
id
is optional but never empty.
First, the usvg preprocessor will convert all shapes into paths. Then it will simplify path’s data so it will contain only absolute MoveTo, LineTo, CurveTo and ClosePath segments.
Attributes: id
, filling, stroking,
clip-rule
(when inside the clipPath
), clip-path
(when inside the clipPath
),
visibility
and transform
.
-
id
is optional but never empty.
The text is one of the most complex parts of the SVG. usvg will modify the input element and its children a lot.
The simplest text
element like <text>Text</text>
will be converted to:
<text>
<tspan
x="0"
y="0">
<tspan
fill="#000000"
font-family="Times New Roman"
font-size="12"
stroke="none">
Text
</tspan>
</tspan>
</text>
In usvg, the text
element is just a container for
text chunks,
represented via tspan
.
So all text
elements will have a three-level structure:
-
text
- container-
tspan
- text chunk-
tspan
- text container
-
-
The text
itself can have only id
, transform
, rotate
, xml:space
and clip-path
(when inside the clipPath
) attributes.
Text chunk can have x
, y
, dx
, dy
and text-anchor
attributes.
And the text container can have filling,
stroking, font, baseline-shift
, letter-spacing
, word-spacing
,
text-decoration
, visibility
and clip-rule
(when inside the clipPath
) attributes.
-
id
is optional but never empty.
Note: text-decoration
is currently ignored.
All attributes can’t have inherit
, invalid or empty value.
Numeric attributes can’t have units.
Filling attributes refers to:
-
fill
-
Possible values:
none
,#RRGGBB
,url(#id)
. -
Impossible values:
currentColor
, icccolor, FuncIRI with a fallback color. -
FuncIRI is always valid and points to an existing element.
-
-
fill-opacity
-
Possible values: 0..1.
-
-
fill-rule
Stroking attributes refers to:
-
stroke
-
See
fill
attribute.
-
-
stroke-dasharray
-
Possible values:
none
, list of numbers. -
Impossible values: odd amount of numbers.
-
-
stroke-dashoffset
-
stroke-miterlimit
-
Possible values: number > 1.
-
-
stroke-opacity
-
Possible values: 0..1.
-
-
stroke-width
-
Possible values: number > 0.
-
-
stroke-linecap
-
stroke-linejoin
Font attributes refers to:
-
font-family
-
font-size
-
Possible values: number > 0.
-
Impossible values: number < 0, 0, number%,
xx-small
,x-small
,small
medium
,large
,x-large
,xx-large
,larger
,smaller
.
-
-
font-style
-
font-variant
-
font-weight
-
Possible values:
100
,200
,300
,400
,500
,600
,700
,800
,900
. -
Impossible values:
normal
,bold
,bolder
,lighter
.
-
-
font-stretch