Crate usvg

Source
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 and circle) will be converted into paths
    • Paths contain only absolute MoveTo, LineTo, QuadTo, CurveTo and ClosePath segments. ArcTo, implicit and relative segments will be converted
  • 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 and url(#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 with userSpaceOnUse

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

filter
SVG filter types.
layout
Provides access to the layout of a text node.

Structs§

BaseGradient
A generic gradient.
ClipPath
A clip-path element.
Color
A 8-bit RGB color.
Fill
A fill style.
Font
Text font properties.
FontResolver
A font resolver for <text> elements.
Group
A group container.
Image
A raster image element.
ImageHrefResolver
An xlink:href resolver for <image> elements.
LinearGradient
A linear gradient.
Mask
A mask element.
NonZeroF32
A non-zero f32.
NonZeroPositiveF32
An immutable, finite f32 that is known to be > 0.
NonZeroRect
A rectangle defined by left, top, right and bottom edges.
NormalizedF32
An immutable, finite f32 in a 0..=1 range.
Options
Processing options.
Path
A path element.
Pattern
A pattern element.
PositiveF32
An immutable, finite f32 that is known to be >= 0.
RadialGradient
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.
StrokeMiterlimit
A stroke-miterlimit value.
Text
A text element.
TextChunk
A text chunk.
TextDecoration
A text span decoration.
TextDecorationStyle
A text span decoration style.
TextPath
A path used by text-on-path.
TextSpan
A text style span.
Transform
An affine transformation matrix.
Tree
A nodes tree container.
WriteOptions
XML writing options.

Enums§

AlignmentBaseline
An alignment baseline property.
BaselineShift
A baseline shift property.
BlendMode
A blending mode property.
DominantBaseline
A dominant baseline property.
Error
List of all errors.
FillRule
A fill rule.
FontFamily
A type of font family.
FontStretch
A font stretch property.
FontStyle
A font style property.
ImageKind
An embedded image kind.
ImageRendering
An image rendering method.
Indent
An XML node indention.
LengthAdjust
A length adjust property.
LineCap
A line cap.
LineJoin
A line join.
MaskType
A mask type.
Node
Node’s kind.
Paint
A paint style.
PaintOrder
Representation of the paint-order property.
ShapeRendering
A shape rendering method.
SpreadMethod
A spread method.
TextAnchor
A text chunk anchor property.
TextFlow
A text chunk flow property.
TextRendering
A text rendering method.
WritingMode
A writing mode.

Traits§

ApproxEqUlps
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.
ApproxZeroUlps
Approximate zero equality comparisons.

Functions§

decompress_svgz
Decompresses an SVGZ file.

Type Aliases§

FallbackSelectionFn
A shorthand for FontResolver’s fallback selection function.
FontSelectionFn
A shorthand for FontResolver’s font selection function.
ImageHrefDataResolverFn
A shorthand for ImageHrefResolver’s data function.
ImageHrefStringResolverFn
A shorthand for ImageHrefResolver’s string function.
Opacity
An alias to NormalizedF32.
StopOffset
An alias to NormalizedF32.
StrokeWidth
An alias to NonZeroPositiveF32.