diagrams-input provides functions to parse several input formats for diagrams:
In the future it would be nice to have:
- HTML + CSS (We need CSS anyway if we want to implement the SVG parser properly). HTML could be a good exercise for developing layouting functions.
- Collada (3d)
- Obj (3d)
The SVG Parser
The SVG parser evolved like maybe most others also did: By taking some SVG images, focussing on one image, getting it displayed correctly. See if the changes affect other images positively. Figuring out what is the most important thing to fix next. The SVG 1.1 spec was used. For testing purposes diagrams-input-test reads and writes all images in a directory.
Support of SVG 1.1:
|Path tag:||All commands|
|Text tag:||Pass the tag through to diagrams-svg or replace it with outlines from the font tag|
|Filling, Stroking and Marker Symbols:||<marker>|
|Gradients, Patterns:||Linear and Radial Gradients||<pattern>|
|Filter effects||No, not supported by diagrams|
|Animation||No, SVG Animation will likely be replaced by Web Animations|
|Fonts:||It is planned to integrate SVGFonts|
- Implement <text>-tag in the svg parser: Passing through without generating the outlines
- fill = "none" => path open
- Scale viewbox to width and height
- Bug in arc command
- Use patched xml-conduit instead of my patched version in the Text folder
- Transform exceptions into Left values in Image.hs (if monad transformers and conduit is easy for you please help me)
- Integrate SVGFonts, because it is too much entangled with SVG to be separate
- loadIamgeExternal for SVG
A Walk through the Code
- Input.hs contains the main functions loadimageEmbedded and loadImageExternal. They call readimage from JuicyPixels and readSVGFile from ReadSVG.hs.
- In ReadSVG.hs the xml file is parsed and translated into a tree. That was necessary because there need to be at least two passes because of references with the <use>-tag. The tree has Constructors that take functions that expect data (like css) that is only known after the first pass.
- All the nodes of the tree are stored in a key value storage. Every node contains the whole subtree, but this is no problem because of lazy evaluation
- Gradients that have nested references to other gradients are flattened into one gradient.
- References are inserted using the key-value-storage and everything is combined into one diagram.