several bugfixes

This commit is contained in:
Mario Voigt 2021-10-28 03:42:25 +02:00
parent 11ddf343ad
commit 523457b470
4 changed files with 54 additions and 10 deletions

View File

@ -77,9 +77,12 @@ class EpilogDashboardBboxAdjust(inkex.EffectExtension):
The rectangle attributes are set in px. They ignore the real units from namedview.
Strange fact: ellipses, spirals and other primitives work flawlessly.
'''
if isinstance (element, inkex.Rectangle):
if isinstance (element, inkex.Rectangle) or \
isinstance (element, inkex.Circle) or \
isinstance (element, inkex.Ellipse):
bbox += element.bounding_box() * scale_factor
elif isinstance (element, inkex.TextElement):
elif isinstance (element, inkex.TextElement) or \
isinstance (element, inkex.Tspan):
if self.options.skip_errors is False:
self.msg("Text elements are not supported!")
return
@ -91,9 +94,12 @@ class EpilogDashboardBboxAdjust(inkex.EffectExtension):
#for element in self.svg.root.getchildren():
for element in self.document.getroot().iter("*"):
if isinstance (element, inkex.ShapeElement) and element.tag != inkex.addNS('use','svg') and element.get('inkscape:groupmode') != 'layer': #bbox fails for svg:use elements and layers:
if isinstance (element, inkex.Rectangle):
bbox += element.bounding_box() * scale_factor
elif isinstance (element, inkex.TextElement):
if isinstance (element, inkex.Rectangle) or \
isinstance (element, inkex.Circle) or \
isinstance (element, inkex.Ellipse):
bbox += element.bounding_box() * scale_factor
elif isinstance (element, inkex.TextElement) or \
isinstance (element, inkex.Tspan):
if self.options.skip_errors is False:
self.msg("Text elements are not supported!")
return

View File

@ -112,9 +112,12 @@ class ExportObject(inkex.EffectExtension):
The rectangle attributes are set in px. They ignore the real units from namedview.
Strange fact: ellipses, spirals and other primitives work flawlessly.
'''
if isinstance (element, inkex.Rectangle):
if isinstance (element, inkex.Rectangle) or \
isinstance (element, inkex.Circle) or \
isinstance (element, inkex.Ellipse):
bbox += element.bounding_box(transform) * scale_factor
elif isinstance (element, inkex.TextElement):
elif isinstance (element, inkex.TextElement) or \
isinstance (element, inkex.Tspan):
if self.options.skip_errors is False:
self.msg("Text elements are not supported!")
return

View File

@ -52,6 +52,15 @@ class Paperfold(inkex.EffectExtension):
minAngle = 0
angleRange = 0
def getElementChildren(self, element, elements = None):
if elements == None:
elements = []
if element.tag != inkex.addNS('g','svg'):
elements.append(element)
for child in element.getchildren():
self.getElementChildren(child, elements)
return elements
# Compute the third point of a triangle when two points and all edge lengths are given
def getThirdPoint(self, v0, v1, l01, l12, l20):
v2rotx = (l01 ** 2 + l20 ** 2 - l12 ** 2) / (2 * l01)
@ -952,12 +961,37 @@ class Paperfold(inkex.EffectExtension):
paperfoldPageGroup = self.writeSVG(unfoldedComponents[i], maxSize, randomColorSet)
#translate the groups next to each other to remove overlappings
if i != 0:
previous_bbox = paperfoldMainGroup[i-1].bounding_box()
this_bbox = paperfoldPageGroup.bounding_box()
#previous_bbox = paperfoldMainGroup[i-1].bounding_box()
#as TextElement, Tspan and Circle cause wrong BBox calculation, we have to make it more complex
previous_bbox = inkex.BoundingBox()
for child in self.getElementChildren(paperfoldMainGroup[i-1]):
if not isinstance (child, inkex.TextElement) and \
not isinstance (child, inkex.Tspan) and \
not isinstance (child, inkex.Circle):
transform = inkex.Transform()
parent = child.getparent()
if parent is not None and isinstance(parent, inkex.ShapeElement):
transform = parent.composed_transform()
previous_bbox += child.bounding_box(transform)
#this_bbox = paperfoldPageGroup.bounding_box()
this_bbox = inkex.BoundingBox()
for child in self.getElementChildren(paperfoldPageGroup):
#as TextElement, Tspan and Circle cause wrong BBox calculation, we have to make it more complex
if not isinstance (child, inkex.TextElement) and \
not isinstance (child, inkex.Tspan) and \
not isinstance (child, inkex.Circle):
transform = inkex.Transform()
parent = child.getparent()
if parent is not None and isinstance(parent, inkex.ShapeElement):
transform = parent.composed_transform()
this_bbox += child.bounding_box(transform)
#self.msg(previous_bbox)
#self.msg(this_bbox)
paperfoldPageGroup.set("transform", "translate({:0.6f}, 0.0)".format(previous_bbox.left + previous_bbox.width - this_bbox.left + xSpacing))
paperfoldMainGroup.append(paperfoldPageGroup)
#apply scale factor
translation_matrix = [[self.options.scalefactor, 0.0, 0.0], [0.0, self.options.scalefactor, 0.0]]
paperfoldMainGroup.transform = Transform(translation_matrix) * paperfoldMainGroup.transform

@ -0,0 +1 @@
Subproject commit 92b545edd5f12d2e88e0b440e498fac55f0046e2