Crate svgdom

source ·
Expand description

svgdom is an SVG Full 1.1 processing library, which allows you to parse, manipulate, generate and write an SVG content.

Note: the library itself is pretty stable, but API is constantly changing.

Purpose

svgdom is designed to simplify generic SVG processing and manipulations. Unfortunately, an SVG is very complex format (PDF spec is 826 pages long), with lots of features and implementing all of them will lead to an enormous library.

That’s why svgdom supports only a static subset of an SVG. No scripts, external resources and complex CSS styling. Parser will convert as much as possible data to a simple doc->elements->attributes structure.

For example, the fill parameter of an element can be set: as an element’s attribute, as part of a style attribute, inside a style element as CSS2, inside an ENTITY, using a JS code and probably with lots of other methods.

Not to mention, that the fill attribute supports 4 different types of data.

With svgdom you can just use node.has_attribute(AttributeId::Fill) and don’t worry where this attribute was defined in the original file.

Same goes for transforms, paths and other SVG types.

The main downside of this approach is that you can’t save an original formatting and some data.

See the preprocessor doc for details.

Benefits

  • The element link(IRI, FuncIRI) is not just a text, but an actual link to another node.
  • At any time you can check which elements linked to the specific element. See Node’s doc for details.
  • Support for many SVG specific data types like paths, transforms, IRI’s, styles, etc. Thanks to svgtypes.
  • A complete support of text nodes: XML escaping, xml:space.
  • Fine-grained control over the SVG output.

Limitations

  • Only SVG elements and attributes will be parsed.
  • Attribute values, CDATA with CSS, DOCTYPE, text data and whitespaces will not be preserved.
  • UTF-8 only.
  • Only most popular attributes are parsed, other stored as strings.
  • No compressed SVG (.svgz). You should decompress it by yourself.
  • CSS support is minimal.
  • SVG 1.1 Full only (no 2.0 Draft, Basic, Type subsets).

Differences between svgdom and SVG spec

  • Library follows SVG spec in the data parsing, writing, but not in the tree structure.
  • Everything is a Node. There are no separated ElementNode, TextNode, etc. You still have all the data, but not in the specific struct’s. You can check the node type via Node::node_type().

Structs

An iterator of nodes to the ancestors a given node.
Representation of the <angle> type.
Representation of the preserveAspectRatio attribute.
Representation of the SVG attribute object.
An attributes list.
An iterator of nodes to the children of a given node.
Representation of the <color> type.
An iterator of nodes to a given node and its descendants, in tree order.
A wrapper to use fmt::Display with WriteOptions.
Container of Nodes.
An iterator of nodes to the siblings after a given node.
Representation of the <length> type.
Representation of the <list-of-length> type.
Node’s data.
Representation of the <list-of-numbers> type.
Options that defines SVG parsing.
Representation of the SVG path data.
A builder for Path.
Representation of the <list-of-points> type.
An iterator of nodes to the siblings before a given node.
An iterator of nodes to the children of a given node, in reverse order.
An iterator of nodes to a given node and its descendants, in reverse tree order.
Representation of the <transform> type.
An iterator of nodes to a given node and its descendants, in tree order.
Options for SVG types writing.
Representation of the <viewBox> type.
Options that defines SVG writing.

Enums

Representation of the align value of the preserveAspectRatio attribute.
List of all SVG angle units.
List of all SVG attributes.
Value of the SVG attribute.
An attributes order.
List of all SVG elements.
SVG DOM errors.
XML node indention
List of all SVG length units.
A separator type for a list of values.
A node type during traverse.
List of supported node types.
Representation of the fallback part of the <paint> type.
SVG parsing errors.
List of all path commands.
Representation of the path segment.
Qualified name.
Qualified name reference.

Traits

This trait contains methods that check attribute’s type according to the SVG spec.
This trait contains methods that check element’s type according to the SVG spec.
An iterator over SVG elements.
An iterator over SVG attributes.
An iterator over SVG attributes.
A trait for fuzzy/approximate equality comparisons of float numbers.
A trait for fuzzy/approximate comparisons of float numbers.
A trait for SVG id’s.
A trait for writing data to the buffer.
A trait for writing data to the buffer.

Type Definitions

Type alias for QName<AttributeId>.
Type alias for QNameRef<AttributeId>.
Representation of the SVG node.
Type alias for QName<ElementId>.
Type alias for QNameRef<ElementId>.