Expand description
usvg
(micro SVG) is an SVG parser that tries to solve most of SVG complexity.
SVG is notoriously hard to parse. usvg
presents a layer between an XML library and
a potential SVG rendering library. It will parse an input SVG into a strongly-typed tree structure
were all the elements, attributes, references and other SVG features are already resolved
and presented in the simplest way possible.
So a caller doesn’t have to worry about most of the issues related to SVG parsing
and can focus just on the rendering part.
§Features
- All supported attributes are resolved. No need to worry about inheritable, implicit and default attributes
- CSS will be applied
- Only simple paths
- Basic shapes (like
rect
andcircle
) will be converted into paths - Paths contain only absolute MoveTo, LineTo, QuadTo, CurveTo and ClosePath segments. ArcTo, implicit and relative segments will be converted
- Basic shapes (like
use
will be resolved and replaced with the reference content- Nested
svg
will be resolved - Invalid, malformed elements will be removed
- Relative length units (mm, em, etc.) will be converted into pixels/points
- External images will be loaded
- Internal, base64 images will be decoded
- All references (like
#elem
andurl(#elem)
) will be resolved switch
will be resolved- Text elements, which are probably the hardest part of SVG, will be completely resolved.
This includes all the attributes resolving, whitespaces preprocessing (
xml:space
), text chunks and spans resolving - Markers will be converted into regular elements. No need to place them manually
- All filters are supported. Including filter functions, like
filter="contrast(50%)"
- Recursive elements will be detected and removed
objectBoundingBox
will be replaced withuserSpaceOnUse
§Limitations
- Unsupported SVG features will be ignored
- CSS support is minimal
- Only static SVG features,
e.g. no
a
,view
,cursor
,script
, no events and no animations
Re-exports§
pub use roxmltree;
pub use fontdb;
pub use strict_num;
pub use tiny_skia_path;
Modules§
Structs§
- Base
Gradient - A generic gradient.
- Clip
Path - A clip-path element.
- Color
- A 8-bit RGB color.
- Fill
- A fill style.
- Font
- Text font properties.
- Font
Resolver - A font resolver for
<text>
elements. - Group
- A group container.
- Image
- A raster image element.
- Image
Href Resolver - An
xlink:href
resolver for<image>
elements. - Linear
Gradient - A linear gradient.
- Mask
- A mask element.
- NonZero
F32 - A non-zero
f32
. - NonZero
Positive F32 - An immutable, finite
f32
that is known to be > 0. - NonZero
Rect - A rectangle defined by left, top, right and bottom edges.
- Normalized
F32 - An immutable, finite
f32
in a 0..=1 range. - Options
- Processing options.
- Path
- A path element.
- Pattern
- A pattern element.
- Positive
F32 - An immutable, finite
f32
that is known to be >= 0. - Radial
Gradient - A radial gradient.
- Rect
- A rectangle defined by left, top, right and bottom edges.
- Size
- A size.
- Stop
- Gradient’s stop element.
- Stroke
- A stroke style.
- Stroke
Miterlimit - A
stroke-miterlimit
value. - Text
- A text element.
- Text
Chunk - A text chunk.
- Text
Decoration - A text span decoration.
- Text
Decoration Style - A text span decoration style.
- Text
Path - A path used by text-on-path.
- Text
Span - A text style span.
- Transform
- An affine transformation matrix.
- Tree
- A nodes tree container.
- Write
Options - XML writing options.
Enums§
- Alignment
Baseline - An alignment baseline property.
- Baseline
Shift - A baseline shift property.
- Blend
Mode - A blending mode property.
- Dominant
Baseline - A dominant baseline property.
- Error
- List of all errors.
- Fill
Rule - A fill rule.
- Font
Family - A type of font family.
- Font
Stretch - A font stretch property.
- Font
Style - A font style property.
- Image
Kind - An embedded image kind.
- Image
Rendering - An image rendering method.
- Indent
- An XML node indention.
- Length
Adjust - A length adjust property.
- LineCap
- A line cap.
- Line
Join - A line join.
- Mask
Type - A mask type.
- Node
- Node’s kind.
- Paint
- A paint style.
- Paint
Order - Representation of the
paint-order
property. - Shape
Rendering - A shape rendering method.
- Spread
Method - A spread method.
- Text
Anchor - A text chunk anchor property.
- Text
Flow - A text chunk flow property.
- Text
Rendering - A text rendering method.
- Writing
Mode - A writing mode.
Traits§
- Approx
EqUlps - ApproxEqUlps is a trait for approximate equality comparisons. The associated type Flt is a floating point type which implements Ulps, and is required so that this trait can be implemented for compound types (e.g. vectors), not just for the floats themselves.
- Approx
Zero Ulps - Approximate zero equality comparisons.
Functions§
- decompress_
svgz - Decompresses an SVGZ file.
Type Aliases§
- Fallback
Selection Fn - A shorthand for FontResolver’s fallback selection function.
- Font
Selection Fn - A shorthand for FontResolver’s font selection function.
- Image
Href Data Resolver Fn - A shorthand for ImageHrefResolver’s data function.
- Image
Href String Resolver Fn - A shorthand for ImageHrefResolver’s string function.
- Opacity
- An alias to
NormalizedF32
. - Stop
Offset - An alias to
NormalizedF32
. - Stroke
Width - An alias to
NonZeroPositiveF32
.