Several small fixes (import cleanings, remove deprecation warnings)

This commit is contained in:
Mario Voigt 2020-08-07 18:31:30 +02:00
parent 8ac5262163
commit c7c23a4b4a
8 changed files with 37 additions and 126 deletions

View File

@ -52,16 +52,10 @@ Finally, after all of the letter's points have been recalculated in this manner,
the resulting path is taken and replaces the letter's original path.
TODO:
* Some points of the letter appear outside the envelope, apparently because the bounding box
calculated by simpletransform.py is only a rough estimate. -> Calculate the real bbox,
perhaps using other existing extensions, or py2geom.
* Currently, both letter and envelope must be paths to work.
-> Arbitrary other shapes like circles and rectangles should be interpreted as paths.
* It should be possible to select several letters, and squeeze them into one envelope as a group.
* It should be possible to insert a clone of the letter, instead of replacing it.
* Bug #241565 prevented the matrix parser constructors from working. This extension can
only be used with the fixed version of simpletransform.py. As a workaround, two matrix constructors
were copied into this file.
* This program was originally written in Java. Maybe for some code, Python shortcuts can be used.
I hope the comments are not too verbose. Enjoy!

View File

@ -2,7 +2,6 @@
import sys
import math
import inkex
import simpletransform
from lxml import etree
class clonesPerspectiveEffect(inkex.Effect):

View File

@ -2,12 +2,6 @@
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>Ellipse by 5 Points</_name>
<id>fablabchemnitz.de.ellipse_5pts</id>
<script>
<command reldir="extensions" interpreter="python">fablabchemnitz_ellipse_5pts.py</command>
</script>
<dependency type="executable" location="extensions">fablabchemnitz_ellipse_5pts.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<dependency type="executable" location="extensions">simplepath.py</dependency>
<effect>
<object-type>path</object-type>
<effects-menu>
@ -16,4 +10,7 @@
</submenu>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">fablabchemnitz_ellipse_5pts.py</command>
</script>
</inkscape-extension>

View File

@ -156,7 +156,7 @@ class node:
# Operations on nodes
def dist(n0, n1 = None): return hypot(n1.y - n0.y, n1.x - n0.x) if n1 else hypot(n0.y, n0.x) # For these two functions
def dirc(n0, n1 = None): return atan2(n1.y - n0.y, n1.x - n0.x) if n1 else atan2(n0.y, n0.x) # n0 is the origin if n1 is present
def slide(n0, n1, t): return n0 + t * (n1 - n0) # node version of tpoint in bezmisc.py
def slide(n0, n1, t): return n0 + t * (n1 - n0)
def dotp(n0, n1): return n0.x * n1.x + n0.y * n1.y
# Operation on vectors: rotation. Positive theta means counterclockwise rotation.

View File

@ -100,12 +100,8 @@
import math
from lxml import etree
import inkex
import simplepath
import simpletransform
import simplestyle
import cubicsuperpath
import cspsubdiv
import bezmisc
from inkex import Transform
from inkex.paths import Path, CubicSuperPath
N_PAGE_WIDTH = 3200
N_PAGE_HEIGHT = 800
@ -592,7 +588,6 @@ def subdivideCubicPath(sp, flat, i=1):
is approximately a straight line within a given tolerance
(the "smoothness" defined by [flat]).
This is a modified version of cspsubdiv.cspsubdiv() rewritten
to avoid recurrence.
"""
@ -653,78 +648,15 @@ class HatchFill(inkex.Effect):
self.docHeight = float(N_PAGE_HEIGHT)
self.docTransform = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
self.arg_parser.add_argument(
"--holdBackSteps",
action="store",
type=float,
dest="holdBackSteps",
default=3.0,
help="How far hatch strokes stay from boundary (steps)",
)
self.arg_parser.add_argument(
"--hatchScope",
action="store",
type=float,
dest="hatchScope",
default=3.0,
help="Radius searched for segments to join (units of hatch width)",
)
self.arg_parser.add_argument(
"--holdBackHatchFromEdges",
action="store",
dest="holdBackHatchFromEdges",
type=inkex.Boolean,
default=True,
help="Stay away from edges, so no need for inset",
)
self.arg_parser.add_argument(
"--reducePenLifts",
action="store",
dest="reducePenLifts",
type=inkex.Boolean,
default=True,
help="Reduce plotting time by joining some hatches",
)
self.arg_parser.add_argument(
"--crossHatch",
action="store",
dest="crossHatch",
type=inkex.Boolean,
default=False,
help="Generate a cross hatch pattern",
)
self.arg_parser.add_argument(
"--hatchAngle",
action="store",
type=float,
dest="hatchAngle",
default=90.0,
help="Angle of inclination for hatch lines",
)
self.arg_parser.add_argument(
"--hatchSpacing",
action="store",
type=float,
dest="hatchSpacing",
default=10.0,
help="Spacing between hatch lines",
)
self.arg_parser.add_argument(
"--tolerance",
action="store",
type=float,
dest="tolerance",
default=20.0,
help="Allowed deviation from original paths",
)
self.arg_parser.add_argument(
"--tab", # NOTE: value is not used.
action="store",
type=str,
dest="tab",
default="splash",
help="The active tab when Apply was pressed",
)
self.arg_parser.add_argument( "--holdBackSteps", type=float, default=3.0, help="How far hatch strokes stay from boundary (steps)", )
self.arg_parser.add_argument( "--hatchScope", type=float, default=3.0, help="Radius searched for segments to join (units of hatch width)", )
self.arg_parser.add_argument( "--holdBackHatchFromEdges", type=inkex.Boolean, default=True, help="Stay away from edges, so no need for inset", )
self.arg_parser.add_argument( "--reducePenLifts", type=inkex.Boolean, default=True, help="Reduce plotting time by joining some hatches", )
self.arg_parser.add_argument( "--crossHatch", type=inkex.Boolean, default=False, help="Generate a cross hatch pattern", )
self.arg_parser.add_argument( "--hatchAngle", type=float, default=90.0, help="Angle of inclination for hatch lines", )
self.arg_parser.add_argument( "--hatchSpacing", type=float, default=10.0, help="Spacing between hatch lines", )
self.arg_parser.add_argument( "--tolerance", type=float, default=20.0, help="Allowed deviation from original paths", )
self.arg_parser.add_argument( "--tab", default="splash")
def getDocProps(self):
@ -755,8 +687,8 @@ class HatchFill(inkex.Effect):
if vinfo[2] != 0 and vinfo[3] != 0:
sx = self.docWidth / float(vinfo[2])
sy = self.docHeight / float(vinfo[3])
# self.docTransform = simpletransform.parseTransform('scale({0:f},{1:f})'.format(sx, sy))
self.docTransform = simpletransform.Transform(
# self.docTransform = Transform('scale({0:f},{1:f})'.format(sx, sy))
self.docTransform = Transform(
f"scale({sx}, {sy})"
).matrix
@ -783,13 +715,13 @@ class HatchFill(inkex.Effect):
return
# Get a cubic super duper path
p = inkex.paths.CubicSuperPath(sp)
p = CubicSuperPath(sp)
if not p or len(p) == 0:
return
# Apply any transformation
if transform is not None:
simpletransform.Path(p).transform(transform)
Path(p).transform(transform)
# Now traverse the simplified path
subpaths = []
@ -892,11 +824,7 @@ class HatchFill(inkex.Effect):
pass
# first apply the current matrix transform to this node's transform
mat_new = simpletransform.Transform(
mat_current
) * simpletransform.Transform(
simpletransform.Transform(node.get("transform")).matrix
)
mat_new = Transform(mat_current) * Transform(Transform(node.get("transform")).matrix)
if node.tag in [inkex.addNS("g", "svg"), "g"]:
self.recursivelyTraverseSvg(node, mat_new, parent_visibility=v)
@ -926,12 +854,7 @@ class HatchFill(inkex.Effect):
y = float(node.get("y", "0"))
# Note: the transform has already been applied
if x != 0 or y != 0:
mat_new2 = simpletransform.composeTransform(
mat_new,
simpletransform.parseTransform(
"translate({0:f},{1:f})".format(x, y)
),
)
mat_new2 = Transform(mat_new) * Transform(Transform("translate({0:f},{1:f})".format(x, y)))
else:
mat_new2 = mat_new
v = node.get("visibility", v)
@ -994,7 +917,7 @@ class HatchFill(inkex.Effect):
["l", [-w, 0]],
["Z", []],
]
ret = simplepath.Path(a)
ret = Path(a)
self.addPathVertices(ret, node, mat_new)
# We now have a path we want to apply a (cross)hatch to
# Apply appropriate functions
@ -1041,7 +964,7 @@ class HatchFill(inkex.Effect):
["M ", [x1, y1]],
[" L ", [x2, y2]],
]
self.addPathVertices(simplepath.formatPath(a), node, mat_new)
self.addPathVertices(Path(a), node, mat_new)
# We now have a path we want to apply a (cross)hatch to
# Apply appropriate functions
b_have_grid = self.makeHatchGrid(
@ -1465,8 +1388,8 @@ class HatchFill(inkex.Effect):
# resulting line segment.
pt1 = [0, 0]
pt2 = [s, s]
simpletransform.Transform(transform).apply_to_point(pt1)
simpletransform.Transform(transform).apply_to_point(pt2)
Transform(transform).apply_to_point(pt1)
Transform(transform).apply_to_point(pt2)
dx = pt2[0] - pt1[0]
dy = pt2[1] - pt1[1]
stroke_width = math.sqrt(dx * dx + dy * dy)
@ -1503,8 +1426,8 @@ class HatchFill(inkex.Effect):
# after the fact (i.e., what's this transform here for?).
# So, we compute the inverse transform and apply it here.
if transform is not None:
simpletransform.Transform(transform).apply_to_point(pt1)
simpletransform.Transform(transform).apply_to_point(pt2)
Transform(transform).apply_to_point(pt1)
Transform(transform).apply_to_point(pt2)
# Now generate the path data for the <path>
if direction:
# Go this direction
@ -1547,8 +1470,8 @@ class HatchFill(inkex.Effect):
# after the fact (i.e., what's this transform here for?).
# So, we compute the inverse transform and apply it here.
if transform is not None:
simpletransform.Transform(transform).apply_to_point(pt1)
simpletransform.Transform(transform).apply_to_point(pt2)
Transform(transform).apply_to_point(pt1)
Transform(transform).apply_to_point(pt2)
# Now generate the path data for the <path>
# BUT we want to combine as many paths as possible to reduce pen lifts.

View File

@ -2,7 +2,7 @@
import math
import inkex
from simpletransform import Transform
from inkex import Transform
inkex.localization.localize()
class IsometricProjectionTools(inkex.Effect):

View File

@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
'''
import inkex
import bezmisc
from inkex import bezier
from inkex.paths import Path, CubicSuperPath
class PasteLengthEffect(inkex.Effect):
@ -42,7 +42,7 @@ class PasteLengthEffect(inkex.Effect):
elif(scaleFrom == 'topRight'):
oldOrigin= [bbox.right, bbox.bottom]
elif(scaleFrom == 'bottomLeft'):
oldOrigin= [bbox.left, ymax]
oldOrigin= [bbox.left, bbox.top]
elif(scaleFrom == 'bottomRight'):
oldOrigin= [bbox.right, bbox.top]
else: #if(scaleFrom == 'center'):
@ -79,7 +79,7 @@ class PasteLengthEffect(inkex.Effect):
for i, part in enumerate(parts):
for j, seg in enumerate(part):
curveLen += bezmisc.bezierlengthSimpson((seg[0], seg[1], seg[2], seg[3]), tolerance = tolerance)
curveLen += bezier.bezierlength((seg[0], seg[1], seg[2], seg[3]), tolerance = tolerance)
return curveLen

View File

@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
import inkex
from inkex import bezier
from inkex.paths import CubicSuperPath
import bezmisc
import simpletransform
import copy
from math import ceil
@ -100,8 +99,7 @@ class SubdividePathEffect(inkex.Effect):
newSegs = []
for j, seg in enumerate(part):
segL = bezmisc.bezierlengthSimpson((seg[0], seg[1], seg[2], seg[3]), tolerance = tolerance)
segL = bezier.bezierlength((seg[0], seg[1], seg[2], seg[3]), tolerance = tolerance)
if(maxL != None):
divL = maxL
@ -121,7 +119,7 @@ class SubdividePathEffect(inkex.Effect):
if(s == seg):
sL = segL
else:
sL = bezmisc.bezierlengthSimpson((s[0], s[1], s[2], s[3]), tolerance = tolerance)
sL = bezier.bezierlength((s[0], s[1], s[2], s[3]), tolerance = tolerance)
if(floatCmpWithMargin(segL, coveredL + divL)):
s2 = s