Giter Club home page Giter Club logo

Comments (13)

jdgwf avatar jdgwf commented on May 18, 2024

Here's the svg as a txt file:
drawing.svg.txt

from svglib.

claudep avatar claudep commented on May 18, 2024

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.

jdgwf avatar jdgwf commented on May 18, 2024

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.

claudep avatar claudep commented on May 18, 2024

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.

jdgwf avatar jdgwf commented on May 18, 2024

Ok I have a working Alpha quality patch - testing now
screenshot from 2018-04-03 10-46-45

from svglib.

jdgwf avatar jdgwf commented on May 18, 2024

Looks like I may have to open a pull request once I'm more sure ;)

from svglib.

claudep avatar claudep commented on May 18, 2024

Show us the code, dude :-)

from svglib.

jdgwf avatar jdgwf commented on May 18, 2024

Scaling needs to be fixed...

from svglib.

jdgwf avatar jdgwf commented on May 18, 2024

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.

jdgwf avatar jdgwf commented on May 18, 2024

translate works, but I have a scale issue to work through. Still learning the class/object.

from svglib.

jdgwf avatar jdgwf commented on May 18, 2024

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.

jdgwf avatar jdgwf commented on May 18, 2024

Ignore the debug print(), of course ;)

from svglib.

jdgwf avatar jdgwf commented on May 18, 2024

screenshot from 2018-04-03 11-22-50

from svglib.

Related Issues (20)

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.