small fixes

This commit is contained in:
Mario Voigt 2024-04-02 02:53:04 +02:00
parent 32c5a9f8b3
commit 5cc30dfc73
2 changed files with 11 additions and 6 deletions

View File

@ -164,7 +164,7 @@ class ChainPaths(inkex.EffectExtension):
inkex.utils.debug("Warning: node {} has transform {}. Use 'Apply Transforms' extension before to handle this.".format(node.get('id'), node.get('transform'))) inkex.utils.debug("Warning: node {} has transform {}. Use 'Apply Transforms' extension before to handle this.".format(node.get('id'), node.get('transform')))
return return
if so.debug: inkex.utils.debug("id={}, tag=".format(idnode.get('id'), node.tag)) if so.debug: inkex.utils.debug("id={}, tag=".format(node.get('id'), node.tag))
path_d = CubicSuperPath(Path(node.get('d'))) path_d = CubicSuperPath(Path(node.get('d')))
sub_idx = -1 sub_idx = -1
for sub in path_d: for sub in path_d:

View File

@ -72,13 +72,13 @@ class DestructiveClip(inkex.EffectExtension):
elif cmd[0] == 'C': elif cmd[0] == 'C':
# https://developer.mozilla.org/en/docs/Web/SVG/Tutorial/Paths # https://developer.mozilla.org/en/docs/Web/SVG/Tutorial/Paths
lineSegments.append([prev, [this[4], this[5]]]) lineSegments.append([prev, [this[4], this[5]]])
errors.add("Curve node detected (svg type C), this node will be handled as a regular node") errors.add("Curve node detected (svg type C), this node will be handled as a regular node. Try to flatten bezier curves before running this extension!")
else: else:
errors.add("Invalid node type detected: {}. This script only handle type M, L, Z".format(cmd[0])) errors.add("Invalid node type detected: {}. This script only handles types M, L, Z".format(cmd[0]))
prev = this prev = this
return (lineSegments, errors) return (lineSegments, errors)
def linesgmentsToSimplePath(self, lineSegments): def lineSegmentsToSimplePath(self, lineSegments):
# reverses simplepathToLines - converts line segments to Move/Line-to's # reverses simplepathToLines - converts line segments to Move/Line-to's
path = [] path = []
end = None end = None
@ -202,8 +202,13 @@ class DestructiveClip(inkex.EffectExtension):
self.error_messages.extend(['{}: {}'.format(id, err) for err in errors]) self.error_messages.extend(['{}: {}'.format(id, err) for err in errors])
clippedSegments = self.clipLineSegments(segmentsToClip, clippingLineSegments) clippedSegments = self.clipLineSegments(segmentsToClip, clippingLineSegments)
if len(clippedSegments) != 0: if len(clippedSegments) != 0:
path = str(inkex.Path(self.linesgmentsToSimplePath(clippedSegments))) segsOkay = True
node.set('d', path) for clippedSegment in clippedSegments:
if len(clippedSegment[0]) != 2: #must be 2, otherwise this errors in Path generation.
segsOkay = False
if segsOkay is True:
path = str(inkex.Path(self.lineSegmentsToSimplePath(clippedSegments)))
node.set('d', path)
else: else:
# don't put back an empty path(?) could perhaps put move, move? # don't put back an empty path(?) could perhaps put move, move?
inkex.errormsg('Object {} clipped to nothing, will not be updated.'.format(node.get('id'))) inkex.errormsg('Object {} clipped to nothing, will not be updated.'.format(node.get('id')))