Comments (13)
Here's the svg as a txt file:
drawing.svg.txt
from svglib.
Yes, it's known that embedding SVGs is currently buggy (this was revealed by the Slovenia.svg
flag output in the current test suite).
from svglib.
I apologize for the duplicate ticket then. Any suggestions where to look to help squash this bug? I'll be mulling over the code to help patch this :)
from svglib.
No need to apologize, there was no properly-named ticket about this until now.
The problem is probably around the renderSVG
method, which assumes it is always the top-most node of the file.
https://github.com/deeplook/svglib/blob/master/svglib/svglib.py#L526
from svglib.
Ok I have a working Alpha quality patch - testing now
from svglib.
Looks like I may have to open a pull request once I'm more sure ;)
from svglib.
Show us the code, dude :-)
from svglib.
Scaling needs to be fixed...
from svglib.
Here are the two functions I've applied code to class SvgRenderer:
def __init__(self, path=None,color_converter=None):
self.attrConverter = Svg2RlgAttributeConverter(color_converter=color_converter)
self.shape_converter = Svg2RlgShapeConverter(path,self.attrConverter)
self.handled_shapes = self.shape_converter.get_handled_shapes()
self.definitions = {}
self.waiting_use_nodes = defaultdict(list)
self.box = Box(x=0, y=0, width=0, height=0)
self.parent_node = True
def renderSvg(self, node):
getAttr = node.getAttribute
width, height = map(getAttr, ("width", "height",))
width, height = map(self.attrConverter.convertLength, (width, height))
x, y = map(getAttr, ("x", "y",))
x, y = map(self.attrConverter.convertLength, (x, y))
viewBox = getAttr("viewBox")
print( width, height, x, y, self.parent_node, viewBox )
if viewBox:
viewBox = self.attrConverter.convertLengthList(viewBox)
if self.parent_node:
self.box = Box(*viewBox)
else:
if self.parent_node:
self.box = Box(0, 0, width, height)
self.parent_node = False
group = Group()
for child in node.getchildren():
self.renderNode(child, group)
transform = ""
if x or y:
transform += " translate(%s, %s)" % (x or '0', y or '0')
if transform:
self.shape_converter.applyTransformOnGroup(transform, group)
return group
from svglib.
translate works, but I have a scale issue to work through. Still learning the class/object.
from svglib.
Still hacky. Here's the code that's working on my fairly complex SVG:
def renderSvg(self, node):
getAttr = node.getAttribute
width, height = map(getAttr, ("width", "height",))
width, height = map(self.attrConverter.convertLength, (width, height))
x, y = map(getAttr, ("x", "y",))
x, y = map(self.attrConverter.convertLength, (x, y))
viewBox = getAttr("viewBox")
childBox = None
if viewBox:
viewBox = self.attrConverter.convertLengthList(viewBox)
if self.parent_node:
self.box = Box(*viewBox)
else:
childBox = Box(*viewBox)
else:
if self.parent_node:
self.box = Box(0, 0, width, height)
self.parent_node = False
group = Group()
for child in node.getchildren():
self.renderNode(child, group)
transform = ""
x_scale = 1
y_scale = 1
if childBox:
print( "childBox", childBox )
if childBox.height != height:
y_scale = height / childBox.height
if childBox.width != width:
x_scale = width / childBox.width
print( width, height, x, y, self.parent_node, viewBox, x_scale, y_scale )
if x or y:
transform += " translate(%s, %s)" % (x or '0', y or '0')
if transform:
self.shape_converter.applyTransformOnGroup(transform, group)
group.scale(x_scale, y_scale )
return group
from svglib.
Ignore the debug print(), of course ;)
from svglib.
from svglib.
Related Issues (20)
- convert to pdf and png files is incorrect HOT 5
- wrong width and height attributes of drawing obj HOT 1
- Implementation error in rendering of paths with shorthand command for quadratic Bézier curves HOT 5
- Transform on clipPath does not work HOT 2
- Error when svg file contains references to font with space in its name HOT 1
- Error on install svglib HOT 2
- Reportlab 4.0.0 added dependency to pycairo HOT 3
- Error ByteIO HOT 3
- svglib fails to render properly HOT 11
- CI failure because of missing cairo HOT 9
- Using root log instead of logger HOT 3
- Units px and pt are wrong HOT 5
- Embedding SVG fonts in PDF/rlg HOT 5
- Add font size test case to test suite
- Rename default branch to main HOT 2
- Add more example and pip install commands to README.md HOT 4
- svglib doesn't remove temporary files properly? HOT 5
- Problems with embedded image sizes HOT 4
- svglib ignores <switch> nodes HOT 4
- Please share wheel file on pypi HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svglib.