twinside / svg-tree Goto Github PK
View Code? Open in Web Editor NEWSVG loader/serializer for Haskell
License: BSD 3-Clause "New" or "Revised" License
SVG loader/serializer for Haskell
License: BSD 3-Clause "New" or "Revised" License
See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/clip-path#Usage_notes and https://developer.mozilla.org/en-US/docs/Web/CSS/basic-shape
This is a low priority issue for me.
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 ).
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.
It would be useful for reanimate[1] if Graphics.Svg.NamedColors was exported. Would you accept such as PR?
Noticed with Stackage, trying to build locally to reproduce
After generating some random svg values (Document) some of them are failing if i try to show them with this error:
Exception thrown while printing test case: '<<loop>>'
Unfortunately, i don't know which constructors are used, because i can't print them, but the Arbitrary instances to reproduce this issue are available here:
I would like to have an element inside a text element (See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/text).
Is there a way to do this using the library?
All elements can have an ID but not all elements may have drawing attributes.
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.
I was just wondering about this as I am interfacing my library (which uses Double) to yours. I could change my library to use Float which would avoid using float2Double everywhere so I was wondering why you chose Float over Double? I think the SVG spec says floats should be double precision.
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?
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 ?
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.
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.