diagrams-input: Parse raster and SVG files for diagrams

[ bsd3, diagrams, graphics, library ] [ Propose Tags ] [ Report a vulnerability ]

Parse raster and SVG images for the diagrams DSL.


[Skip to Readme]

Modules

[Last Documentation]

  • Diagrams
    • SVG
      • Diagrams.SVG.Arguments
      • Diagrams.SVG.Attributes
      • Diagrams.SVG.Path
      • Diagrams.SVG.ReadSVG
      • Diagrams.SVG.Tree
    • TwoD
      • Diagrams.TwoD.Input

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.1.1, 0.1.2, 0.1.3, 0.1.3.1, 0.1.4
Change log CHANGELOG.md
Dependencies attoparsec (>=0.10), base (>=4 && <5), base64-bytestring, blaze-builder, blaze-markup, bytestring, colour, conduit, conduit-extra, containers, css-text, data-default (>=0.8 && <0.9), diagrams-core (>=1.3 && <1.6), diagrams-lib (>=1.3 && <1.5), digits, either (>=4.4), JuicyPixels (>=3.1.5 && <3.4), linear (>=1.11.3), resourcet, semigroups, split, system-filepath, text (>=0.11), transformers, unordered-containers, vector, xml-conduit (>=1.3), xml-types (>=0.3 && <0.4) [details]
Tested with ghc ==8.4.4 || ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.5 || ==9.8.2 || ==9.10.1
License BSD-3-Clause
Copyright Tillmann Vogt (2014)
Author Tillmann Vogt
Maintainer diagrams-discuss@googlegroups.com
Category Graphics, Diagrams
Source repo head: git clone http://github.com/diagrams/diagrams-input.git
Uploaded by BrentYorgey at 2024-11-05T20:35:20Z
Distributions NixOS:0.1.3.1
Downloads 304 total (10 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2024-11-06 [all 2 reports]

Readme for diagrams-input-0.1.4

[back to package description]

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:

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

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