libsvgdom is an SVG Full 1.1 processing library, which allows you to parse, manipulate and generate SVG content.
libsvgdom 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 a enormous library.
That's why libsvgdom supports only static subset of an SVG. No scripts, external resources and complex CSS styling. Parser will convert as much as possible data to simple doc->elements->attributes structure.
For example, the fill
parameter of element can be set: as an element's attribute,
as part of the style
attribute, inside CDATA of the style element as CSS2, inside the ENTITY
,
using the JS code and probably with a lots of other methods.
Not to mention, that the fill
attribute supports a 4 different types of data.
With libsvgdom you can just use node.has_attribute(AttributeId::Fill)
and don't worry were this
attribute was defined in original file.
Same goes to the transforms, paths and other SVG types.
Main downside of this approach is that you can't save original formatting and some data.
Node
doc for details. 
.
<g xmlns:s="http://www.w3.org/2000/svg">
<s:circle/>
</g>
It will be threated as non-SVG element.Error::UnsupportedEntity
. Example:
<!DOCTYPE svg [
<!ENTITY Rect1 "<rect x='.5' y='.5' width='20' height='20'/>">
]>
<svg>&Rect1;</svg>
script
element).Node
. There are no separated ElementNode
, TextNode
, etc.
You still have all the data, but not in the specific struct's.
You can check a node type via Node::node_type()
.Add this to your Cargo.toml
:
toml
[dependencies]
svgdom = "0.0.3"
See documentation and examples for details.
It will be no comparisons with other XML parsers, since they do not parse SVG data. And no comparisons with other SVG parsers, since there are no such*.
Note that most of the time is spend in string to number and number to string conversions.
It's still not as as fast as I want, but here is some examples using resave example:
| Image | Result | | ------------- | ------------- | | Some huge image** (17.3MiB) | ~850ms/~5500M instructions. | | Big image (1.7MiB) | ~80ms/~500M instructions. | | Average image (324.4KiB) | ~20ms/~89M instructions. | | Small image, like SVG Logo (8.8KiB) | ~0.45ms/~2M instructions. |
* At least I don't know.
** It's not a direct downloads links.
Tested on i5-3570k 3.8GHz.
V0.1.0
- [ ] Increase performance:
- [x] f64
to string conversion takes about 75% off all DOM to String conversion time.
Specifically: core::fmt::float_to_decimal_common
.
- [x] VecMap::insert
is very expensive for some reasons.
- [ ] Improve grammar of the documentation.
English is not my native language, so there is probably a lot of errors.
V0.2.0
- [ ] Parsing and writing as a feature.
- [ ] Add support for custom writer.
- [ ] Memory pool for nodes.
- [ ] Implement DOM with less Rc
.
V0.N.0 - [ ] Complete CSS support using external CSS parser.
* this roadmap is not final and will be complemented.
Contributions are welcome, but current API is so much unstable, that it's better to wait until v0.1.0.
libsvgdom is licensed under the MPLv2.0.