Overview of usvg (micro SVG)
mainusvg (micro SVG) is an SVG parser designed to simplify the complexity of SVG for rendering libraries. It acts as a layer between an XML library and a rendering engine by parsing input SVG into a strongly-typed tree structure.
Key benefits include:
- Resolved Attributes: All inheritable, implicit, and default attributes are pre-resolved.
- Simplified Geometry: Basic shapes (like
rectandcircle) are converted into paths, and all path segments (includingArcTo, implicit, and relative segments) are converted into absoluteMoveTo,LineTo,QuadTo,CurveTo, andClosePathsegments. - Resolved References:
useelements, nestedsvgelements, and all references (e.g.,#elemorurl(#elem)) are resolved and replaced with their content. - Unit Conversion: Relative length units (e.g.,
mm,em) are converted into pixels/points. - Image Handling: External images are loaded and internal base64 images are decoded.
- Text Processing: Text elements are fully resolved, including attribute resolution, whitespace preprocessing (
xml:space), and text chunks/spans. - Filter Support: Supports filters, including filter functions like
filter="contrast(50%)". - Sanitization: Invalid or malformed elements are removed, and recursive elements are detected and removed.