diagrams-input provides functions to parse several input formats for diagrams:
- Raster images: PNG, JPG, ... (using Juicy.Pixels)
- SVG (using xml-conduit and attoparsec)
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 main functions are loadimageEmbedded and loadImageExternal that return either a Left error-message or a Right diagram. See the [diagrams manual] (http://projects.haskell.org/diagrams/doc/manual.html#images).
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] (https://github.com/diagrams/diagrams-input-test) reads and writes all images in a directory.
Support of SVG 1.1:
Tags | Support | Partial Support | Missing |
---|---|---|---|
Document Structure: | <svg><g><defs><desc><title><symbol><use> | <image> | <switch> |
Style tag: | Yes | CSS | |
Path tag: | All commands | ||
Basic Shapes: | <rect><circle><ellipse><line><polyline><polygon> | ||
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> | |
Clipping, Masking: | Clipping | <mask> | |
Filter effects | No, not supported by diagrams | ||
Linking | No | ||
Animation | No, SVG Animation will likely be replaced by Web Animations | ||
Fonts: | It is planned to integrate SVGFonts | ||
Metadata | No | ||
Inkscape tags | No |
- fill = "none" => path open
- Scale viewbox to width and height
- Bug in arc command
- marker tag
- Transform exceptions into Left values in Image.hs (if monad transformers and conduit is easy for you please help me)
- inherit-attribute
- display-attribute
- Integrate SVGFonts, because it is too much entangled with SVG to be separate
- loadIamgeExternal for SVG
- 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.
- Haskell: [svg-tree] (https://github.com/Twinside/svg-tree) (currently not targeted at
diagrams
) - Java: [Processing] (https://github.com/processing/processing/blob/7f63dad6f21db722fe98d7a1f2afaa3de6c17b4c/core/src/processing/core/PShapeSVG.java)
- Java: [Apache Batik] (https://github.com/apache/batik)
- Javascript: [canvg] (https://github.com/gabelerner/canvg)