Skip to content

Commit

Permalink
Autoexporter updates
Browse files Browse the repository at this point in the history
Adds automatic Stroke to Path conversion to the Autoexporter
Adds multithreading
  • Loading branch information
burghoff committed Nov 19, 2022
1 parent cac7d4e commit 1caffc2
Show file tree
Hide file tree
Showing 13 changed files with 781 additions and 725 deletions.
32 changes: 20 additions & 12 deletions examples/Scale example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
671 changes: 331 additions & 340 deletions examples/Scale example_portable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 22 additions & 12 deletions examples/kerning_removalb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion scientific_inkscape/RemoveKerning.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ def External_Merges(els, mergenearby, mergesupersub):
neitherempty = len(wstrip(w.txt())) > 0 and len(wstrip(w2.txt())) > 0
if xpenmatch and neitherempty and not (twospaces(w, w2)):
type = None
# samecolor = Style2(w2.cs[0].nstyc).get('fill')==Style2(w.cs[-1].nstyc).get('fill')
# dh.idebug([w.fs,w2.fs])
# dh.idebug([br1.y+ytol>=bl2.y>=tr1.y-ytol,mergesupersub])
if abs(bl2.y - br1.y) < ytol and abs(w.fs - w2.fs) < 0.001 and mergenearby:
Expand Down
20 changes: 10 additions & 10 deletions scientific_inkscape/Style2.py → scientific_inkscape/Style0.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import inkex


class Style2(inkex.OrderedDict):
class Style0(inkex.OrderedDict):
"""A list of style directives"""

color_props = ("stroke", "fill", "stop-color", "flood-color", "lighting-color")
Expand Down Expand Up @@ -65,8 +65,8 @@ def to_str(self, sep=";"):
def __add__(self, other):
"""Add two styles together to get a third, composing them"""
ret = self.copy()
if not (isinstance(other, Style2)):
other = Style2(other)
if not (isinstance(other, Style0)):
other = Style0(other)
ret.update(other)
return ret

Expand All @@ -89,8 +89,8 @@ def __isub__(self, other):

def __eq__(self, other):
"""Not equals, prefer to overload 'in' but that doesn't seem possible"""
if not isinstance(other, Style2):
other = Style2(other)
if not isinstance(other, Style0):
other = Style0(other)
for arg in set(self) | set(other):
if self.get(arg, None) != other.get(arg, None):
return False
Expand All @@ -100,8 +100,8 @@ def __eq__(self, other):

def update(self, other):
"""Make sure callback is called when updating"""
if not (isinstance(other, Style2)):
other = Style2(other)
if not (isinstance(other, Style0)):
other = Style0(other)
super().update(other)
if self.callback is not None:
self.callback(self)
Expand Down Expand Up @@ -160,15 +160,15 @@ def interpolate_prop(self, other, fraction, prop, svg=None):

def interpolate(self, other, fraction):
"""Interpolate all properties."""
style = Style2()
style = Style0()
for prop, value in self.items():
style[prop] = self.interpolate_prop(other, fraction, prop)
return style


# Replace Style wrapped attr with Style2
# Replace Style wrapped attr with Style0
inkex.BaseElement.WRAPPED_ATTRS = (
("transform", inkex.Transform),
("style", Style2),
("style", Style0),
("classes", "class", inkex.styles.Classes),
)
18 changes: 13 additions & 5 deletions scientific_inkscape/applytransform_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import math
from inkex.paths import CubicSuperPath, Path
from inkex.transforms import Transform
from Style2 import Style2
from Style0 import Style0
from inkex import Line, Rectangle, Polygon, Polyline, Ellipse, Circle

import os, sys
Expand Down Expand Up @@ -51,7 +51,7 @@ def remove_attrs(node):
def applyToStrokes(self, node, transf):
if "style" in node.attrib:
# style = node.attrib.get('style')
# style = dict(Style2.parse_str(style))
# style = dict(Style0.parse_str(style))
style = node.cstyle
update = False
if "stroke-width" in style:
Expand Down Expand Up @@ -84,7 +84,7 @@ def applyToStrokes(self, node, transf):
except AttributeError:
pass
if update:
# node.attrib['style'] = Style2(style).to_str()
# node.attrib['style'] = Style0(style).to_str()
node.cstyle = style

def transform_clipmask(self, el, mask=False):
Expand Down Expand Up @@ -147,7 +147,10 @@ def recursiveFuseTransform(
# Don't do anything if there is effectively no transform applied
if "d" in node.attrib:
d = node.get("d")
p = CubicSuperPath(d)
try:
p = CubicSuperPath(d)
except ZeroDivisionError:
p = Path(d)
if irange is None:
p = Path(p).to_absolute().transform(transf, True)
if irange is not None:
Expand All @@ -161,7 +164,12 @@ def recursiveFuseTransform(
xf, True
)
p = pnew
node.set("d", str(Path(CubicSuperPath(p).to_path())))

try:
p2 = str(Path(CubicSuperPath(p).to_path()))
except ZeroDivisionError:
p2 = str(Path(p))
node.set("d",p2)
elif isinstance(
node, (Polygon, Polyline)
): # node.tag in [inkex.addNS('polygon', 'svg'), inkex.addNS('polyline', 'svg')]:
Expand Down
5 changes: 4 additions & 1 deletion scientific_inkscape/autoexporter.inx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
<param name="texttopath" type="bool" gui-text="Convert text to paths"
gui-description="Conversion of text to paths can help guarantee that it looks identical on all platforms. Recommended for EMFs.">false</param>
<param name="thinline" type="bool" gui-text="Prevent thin line enhancement (recommended)"
gui-description="Some PDF renderers thicken lines at certain zooms; this option makes your lines impervious to this feature.">true</param>
gui-description="Some PDF readers thicken lines at certain zooms; this option makes your lines impervious to this feature.">true</param>

<param name="stroketopath" type="bool" gui-text="Convert all strokes to paths"
gui-description="Most PDF readers draw stroked lines differently than equivalent filled paths. By converting strokes to paths, this can be prevented. (This uses Inkscape's Stroke to Path, which has some unresolved bugs. Double-check the final output.)">false</param>


<param name="margin" type="float" precision="1" min="-9999" max="9999" gui-text="Extra margin (mm)"
Expand Down
Loading

0 comments on commit 1caffc2

Please sign in to comment.