Git Product home page Git Product logo

svg-tree's People

Contributors

bodigrim avatar codedmart avatar jyp avatar kasbah avatar ndmitchell avatar tungd avatar twinside avatar www avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

svg-tree's Issues

Are the monoids necessary?

A lot of the draw attributes (such as strokeWidth and strokeColor) use the 'Last' monoid. As I see it, the only purpose of this is to tell when attributes have been omitted. Are there any use-cases that require this or can we simply fill in missing attributes with their default values?

Confusion with reanimate-svg

I was going to offer PR for svg-tree, but before doing so I reviewed existing PRs and forks, and noticed the https://github.com/reanimate/reanimate-svg fork (preferably I'd file this issue there but it has GitHub issues disabled).

It would be nice to know what are the differences between the two. Preferably reanimate-svg would explain it (as it initiated the fork) but lacking that, an explanation in svg-tree's readme would clear things up!

Support <desc> tag

Looking at the SVG spec, and the documents produced by Inkscape, I see things like:

    <ellipse
       style="fill:none;fill-opacity:1;stroke:#ff0000;stroke-width:31.24999809;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
       id="whatever"
       cx="-1514.915"
       cy="-19145.889"
       rx="185.75783"
       ry="181.22716"
       inkscape:label="#unk"
       transform="matrix(0.93969262,0.34202015,-0.34202015,0.93969262,0,0)"
       clip-path="none">
      <desc
         id="desc11832">test</desc>
    </ellipse>

I think that desc should be parsed and added to DrawAttributes? I couldn't immediately figure out how when looking at the code though.

documentSize return type

Would you please consider changing the documentSize function to return (Double, Double) instead of (Int, Int)? The rounding causes an annoying precision loss in my gcode converter.

Id redefination is still possible

Hi,

Even in the last revision, it is still possible to serialize a svg and obtain an invalid svg because of a duplicated id. For instance:

Document {_viewBox = Just (10.93378015676586,-2.5002198377193974,1.1076888622404122,1.3056209094151552), _width = Nothing, _height = Nothing, _elements = [], _definitions = fromList [("d",ElementClipPath (ClipPath {_clipPathDrawAttributes = DrawAttributes {_strokeWidth = Last {getLast = Nothing}, _strokeColor = Last {getLast = Just (TextureRef "d")}, _strokeOpacity = Nothing, _strokeLineCap = Last {getLast = Just CapButt}, _strokeLineJoin = Last {getLast = Just JoinMiter}, _strokeMiterLimit = Last {getLast = Just 0.608029056458719}, _fillColor = Last {getLast = Just (TextureRef "a")}, _fillOpacity = Nothing, _groupOpacity = Just (-1.1104697), _transform = Just [], _fillRule = Last {getLast = Nothing}, _maskRef = Last {getLast = Nothing}, _clipPathRef = Last {getLast = Nothing}, _clipRule = Last {getLast = Nothing}, _attrClass = ["b"], _attrId = Just "e", _strokeOffset = Last {getLast = Nothing}, _strokeDashArray = Last {getLast = Nothing}, _fontSize = Last {getLast = Nothing}, _fontFamily = Last {getLast = Just ["e"]}, _fontStyle = Last {getLast = Just FontStyleItalic}, _textAnchor = Last {getLast = Just TextAnchorStart}, _markerStart = Last {getLast = Nothing}, _markerMid = Last {getLast = Nothing}, _markerEnd = Last {getLast = Just (Ref "d")}}, _clipPathUnits = CoordBoundingBox, _clipPathContent = [CircleTree (Circle {_circleDrawAttributes = DrawAttributes {_strokeWidth = Last {getLast = Nothing}, _strokeColor = Last {getLast = Nothing}, _strokeOpacity = Nothing, _strokeLineCap = Last {getLast = Nothing}, _strokeLineJoin = Last {getLast = Nothing}, _strokeMiterLimit = Last {getLast = Nothing}, _fillColor = Last {getLast = Just (TextureRef "c")}, _fillOpacity = Just 0.0, _groupOpacity = Just 0.0, _transform = Just [], _fillRule = Last {getLast = Nothing}, _maskRef = Last {getLast = Nothing}, _clipPathRef = Last {getLast = Just RefNone}, _clipRule = Last {getLast = Just FillNonZero}, _attrClass = [], _attrId = Just "d", _strokeOffset = Last {getLast = Nothing}, _strokeDashArray = Last {getLast = Nothing}, _fontSize = Last {getLast = Just (Num 0.0)}, _fontFamily = Last {getLast = Nothing}, _fontStyle = Last {getLast = Just FontStyleNormal}, _textAnchor = Last {getLast = Just TextAnchorEnd}, _markerStart = Last {getLast = Just (Ref "e")}, _markerMid = Last {getLast = Just RefNone}, _markerEnd = Last {getLast = Just (Ref "a")}}, _circleCenter = (Num 0.0,Point 0.0), _circleRadius = Mm 0.0})]}))], _description = "d", _styleRules = [], _documentLocation = "b"}

I'm not sure if this is a bug in svg-tree.

Serialization of None values in Trees

Hi,

We recently discovered that the value None in the Tree datatype is serialized as "< />" and this element is not validated by some XML libraries (for instance libxml2). Such SVG files are rejected by libraries like librsvg2 or Firefox. For instance, this svg file.

This issue was found using QuickFuzz (we have a new engine to generate arbitrary instances in using svg-tree, thanks to @martinceresa ).

strange bug in parsing/printing xlink:href attributes

I have the following simple code:

module SvgTree.IO where
import Graphics.Svg
import Data.Maybe

fn="data/input/00.jpg.svg"
svgTest = loadSvgFile fn
save= do
  l<-svgTest
  saveXmlFile "testSvgTree.svg" $ fromJust l

if I have in data/input/00.jpg.svg the following:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     viewBox="0 1023.8 612 382.5" enable-background="new 0 1023.8 612 382.5" xml:space="preserve">
<image overflow="visible" enable-background="new    " width="1680" height="1050" xlink:href="00.jpg"  transform="matrix(0.3643 0 0 0.3643 0 1023.75)">
</image>
<rect x="289.4" y="1221.2" fill="#FFFFFF" stroke="#FFFFFF" stroke-miterlimit="10" width="7" height="9.1"/>
<rect x="319" y="1141.9" fill="#FFFFFF" width="10.2" height="12.2"/>
<rect x="327.3" y="1315.9" fill="#FFFFFF" width="9.1" height="15"/>
<rect x="277.1" y="1089.2" fill="#FFFFFF" width="9.1" height="12.6"/>
</svg>

then in testSvgTree.svg I get this :

<?xml version='1.0' ?>
<svg viewBox="0 1023 612 382" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
  <image transform="matrix(0.3643, 0.0, 0.0, 0.3643, 0.0, 1023.75)" class="" width="1680.0" height="1050.0" xlink:href="#00.jpg" />
  <rect stroke="#FFFFFF" fill="#FFFFFF" stroke-miterlimit="10.0" class="" width="7.0" height="9.1" x="289.4" y="1221.2" />
  <rect fill="#FFFFFF" class="" width="10.2" height="12.2" x="319.0" y="1141.9" />
  <rect fill="#FFFFFF" class="" width="9.1" height="15.0" x="327.3" y="1315.9" />
  <rect fill="#FFFFFF" class="" width="9.1" height="12.6" x="277.1" y="1089.2" />
</svg>

which has the problem that xlink:href="#00.jpg" has an extra # in front of the file name.

Any idea how to fix this ? Which part of the library causes the issue ?

I wonder if it were possible to create some kind of QuickCheck test with the property that whatever was parsed in should produce the same output ? Maybe that would have catched this bug ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.