MyNixOS website logo
Description

Parse raster and SVG files for diagrams.

Parse raster and SVG images for the diagrams DSL.

diagrams-input

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.
  • PDF
  • Collada (3d)
  • Obj (3d)

Usage

The main functions are loadimageEmbedded and loadImageExternal that return either a Left error-message or a Right diagram. See the diagrams manual.

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.

Supported Tags

Support of SVG 1.1:

TagsSupportPartial SupportMissing
Document Structure:\<svg\>\<g\>\<defs\>\<desc\>\<title\>\<symbol\>\<use\>\<image\>\<switch\>
Style tag:YesCSS
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 effectsNo, not supported by diagrams
LinkingNo
AnimationNo, SVG Animation will likely be replaced by Web Animations
Fonts:It is planned to integrate SVGFonts
MetadataNo
Inkscape tagsNo

TODO

  • [ ] fill = "none" => path open
  • [ ] Scale viewbox to width and height
  • [ ] 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

A Walk through the Code

  1. Input.hs contains the main functions loadimageEmbedded and loadImageExternal. They call readimage from JuicyPixels and readSVGFile from ReadSVG.hs.
  2. 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.
  3. 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
  4. Gradients that have nested references to other gradients are flattened into one gradient.
  5. References are inserted using the key-value-storage and everything is combined into one diagram.

Other SVG Parsers

Metadata

Version

0.1.3.1

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows