Several small fixes (import cleanings, remove deprecation warnings)
This commit is contained in:
parent
8ac5262163
commit
c7c23a4b4a
@ -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.
|
the resulting path is taken and replaces the letter's original path.
|
||||||
|
|
||||||
TODO:
|
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.
|
* Currently, both letter and envelope must be paths to work.
|
||||||
-> Arbitrary other shapes like circles and rectangles should be interpreted as paths.
|
-> 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 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.
|
* 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.
|
* 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!
|
I hope the comments are not too verbose. Enjoy!
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import math
|
import math
|
||||||
import inkex
|
import inkex
|
||||||
import simpletransform
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
class clonesPerspectiveEffect(inkex.Effect):
|
class clonesPerspectiveEffect(inkex.Effect):
|
||||||
|
@ -2,12 +2,6 @@
|
|||||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
<_name>Ellipse by 5 Points</_name>
|
<_name>Ellipse by 5 Points</_name>
|
||||||
<id>fablabchemnitz.de.ellipse_5pts</id>
|
<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>
|
<effect>
|
||||||
<object-type>path</object-type>
|
<object-type>path</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
@ -16,4 +10,7 @@
|
|||||||
</submenu>
|
</submenu>
|
||||||
</effects-menu>
|
</effects-menu>
|
||||||
</effect>
|
</effect>
|
||||||
|
<script>
|
||||||
|
<command reldir="extensions" interpreter="python">fablabchemnitz_ellipse_5pts.py</command>
|
||||||
|
</script>
|
||||||
</inkscape-extension>
|
</inkscape-extension>
|
@ -156,7 +156,7 @@ class node:
|
|||||||
# Operations on nodes
|
# 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 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 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
|
def dotp(n0, n1): return n0.x * n1.x + n0.y * n1.y
|
||||||
|
|
||||||
# Operation on vectors: rotation. Positive theta means counterclockwise rotation.
|
# Operation on vectors: rotation. Positive theta means counterclockwise rotation.
|
||||||
|
@ -100,12 +100,8 @@
|
|||||||
import math
|
import math
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
import inkex
|
import inkex
|
||||||
import simplepath
|
from inkex import Transform
|
||||||
import simpletransform
|
from inkex.paths import Path, CubicSuperPath
|
||||||
import simplestyle
|
|
||||||
import cubicsuperpath
|
|
||||||
import cspsubdiv
|
|
||||||
import bezmisc
|
|
||||||
|
|
||||||
N_PAGE_WIDTH = 3200
|
N_PAGE_WIDTH = 3200
|
||||||
N_PAGE_HEIGHT = 800
|
N_PAGE_HEIGHT = 800
|
||||||
@ -592,7 +588,6 @@ def subdivideCubicPath(sp, flat, i=1):
|
|||||||
is approximately a straight line within a given tolerance
|
is approximately a straight line within a given tolerance
|
||||||
(the "smoothness" defined by [flat]).
|
(the "smoothness" defined by [flat]).
|
||||||
|
|
||||||
This is a modified version of cspsubdiv.cspsubdiv() rewritten
|
|
||||||
to avoid recurrence.
|
to avoid recurrence.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -653,78 +648,15 @@ class HatchFill(inkex.Effect):
|
|||||||
self.docHeight = float(N_PAGE_HEIGHT)
|
self.docHeight = float(N_PAGE_HEIGHT)
|
||||||
self.docTransform = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
|
self.docTransform = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
|
||||||
|
|
||||||
self.arg_parser.add_argument(
|
self.arg_parser.add_argument( "--holdBackSteps", type=float, default=3.0, help="How far hatch strokes stay from boundary (steps)", )
|
||||||
"--holdBackSteps",
|
self.arg_parser.add_argument( "--hatchScope", type=float, default=3.0, help="Radius searched for segments to join (units of hatch width)", )
|
||||||
action="store",
|
self.arg_parser.add_argument( "--holdBackHatchFromEdges", type=inkex.Boolean, default=True, help="Stay away from edges, so no need for inset", )
|
||||||
type=float,
|
self.arg_parser.add_argument( "--reducePenLifts", type=inkex.Boolean, default=True, help="Reduce plotting time by joining some hatches", )
|
||||||
dest="holdBackSteps",
|
self.arg_parser.add_argument( "--crossHatch", type=inkex.Boolean, default=False, help="Generate a cross hatch pattern", )
|
||||||
default=3.0,
|
self.arg_parser.add_argument( "--hatchAngle", type=float, default=90.0, help="Angle of inclination for hatch lines", )
|
||||||
help="How far hatch strokes stay from boundary (steps)",
|
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(
|
self.arg_parser.add_argument( "--tab", default="splash")
|
||||||
"--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",
|
|
||||||
)
|
|
||||||
|
|
||||||
def getDocProps(self):
|
def getDocProps(self):
|
||||||
|
|
||||||
@ -755,8 +687,8 @@ class HatchFill(inkex.Effect):
|
|||||||
if vinfo[2] != 0 and vinfo[3] != 0:
|
if vinfo[2] != 0 and vinfo[3] != 0:
|
||||||
sx = self.docWidth / float(vinfo[2])
|
sx = self.docWidth / float(vinfo[2])
|
||||||
sy = self.docHeight / float(vinfo[3])
|
sy = self.docHeight / float(vinfo[3])
|
||||||
# self.docTransform = simpletransform.parseTransform('scale({0:f},{1:f})'.format(sx, sy))
|
# self.docTransform = Transform('scale({0:f},{1:f})'.format(sx, sy))
|
||||||
self.docTransform = simpletransform.Transform(
|
self.docTransform = Transform(
|
||||||
f"scale({sx}, {sy})"
|
f"scale({sx}, {sy})"
|
||||||
).matrix
|
).matrix
|
||||||
|
|
||||||
@ -783,13 +715,13 @@ class HatchFill(inkex.Effect):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Get a cubic super duper path
|
# Get a cubic super duper path
|
||||||
p = inkex.paths.CubicSuperPath(sp)
|
p = CubicSuperPath(sp)
|
||||||
if not p or len(p) == 0:
|
if not p or len(p) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Apply any transformation
|
# Apply any transformation
|
||||||
if transform is not None:
|
if transform is not None:
|
||||||
simpletransform.Path(p).transform(transform)
|
Path(p).transform(transform)
|
||||||
|
|
||||||
# Now traverse the simplified path
|
# Now traverse the simplified path
|
||||||
subpaths = []
|
subpaths = []
|
||||||
@ -892,11 +824,7 @@ class HatchFill(inkex.Effect):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# first apply the current matrix transform to this node's transform
|
# first apply the current matrix transform to this node's transform
|
||||||
mat_new = simpletransform.Transform(
|
mat_new = Transform(mat_current) * Transform(Transform(node.get("transform")).matrix)
|
||||||
mat_current
|
|
||||||
) * simpletransform.Transform(
|
|
||||||
simpletransform.Transform(node.get("transform")).matrix
|
|
||||||
)
|
|
||||||
|
|
||||||
if node.tag in [inkex.addNS("g", "svg"), "g"]:
|
if node.tag in [inkex.addNS("g", "svg"), "g"]:
|
||||||
self.recursivelyTraverseSvg(node, mat_new, parent_visibility=v)
|
self.recursivelyTraverseSvg(node, mat_new, parent_visibility=v)
|
||||||
@ -926,12 +854,7 @@ class HatchFill(inkex.Effect):
|
|||||||
y = float(node.get("y", "0"))
|
y = float(node.get("y", "0"))
|
||||||
# Note: the transform has already been applied
|
# Note: the transform has already been applied
|
||||||
if x != 0 or y != 0:
|
if x != 0 or y != 0:
|
||||||
mat_new2 = simpletransform.composeTransform(
|
mat_new2 = Transform(mat_new) * Transform(Transform("translate({0:f},{1:f})".format(x, y)))
|
||||||
mat_new,
|
|
||||||
simpletransform.parseTransform(
|
|
||||||
"translate({0:f},{1:f})".format(x, y)
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
mat_new2 = mat_new
|
mat_new2 = mat_new
|
||||||
v = node.get("visibility", v)
|
v = node.get("visibility", v)
|
||||||
@ -994,7 +917,7 @@ class HatchFill(inkex.Effect):
|
|||||||
["l", [-w, 0]],
|
["l", [-w, 0]],
|
||||||
["Z", []],
|
["Z", []],
|
||||||
]
|
]
|
||||||
ret = simplepath.Path(a)
|
ret = Path(a)
|
||||||
self.addPathVertices(ret, node, mat_new)
|
self.addPathVertices(ret, node, mat_new)
|
||||||
# We now have a path we want to apply a (cross)hatch to
|
# We now have a path we want to apply a (cross)hatch to
|
||||||
# Apply appropriate functions
|
# Apply appropriate functions
|
||||||
@ -1041,7 +964,7 @@ class HatchFill(inkex.Effect):
|
|||||||
["M ", [x1, y1]],
|
["M ", [x1, y1]],
|
||||||
[" L ", [x2, y2]],
|
[" 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
|
# We now have a path we want to apply a (cross)hatch to
|
||||||
# Apply appropriate functions
|
# Apply appropriate functions
|
||||||
b_have_grid = self.makeHatchGrid(
|
b_have_grid = self.makeHatchGrid(
|
||||||
@ -1465,8 +1388,8 @@ class HatchFill(inkex.Effect):
|
|||||||
# resulting line segment.
|
# resulting line segment.
|
||||||
pt1 = [0, 0]
|
pt1 = [0, 0]
|
||||||
pt2 = [s, s]
|
pt2 = [s, s]
|
||||||
simpletransform.Transform(transform).apply_to_point(pt1)
|
Transform(transform).apply_to_point(pt1)
|
||||||
simpletransform.Transform(transform).apply_to_point(pt2)
|
Transform(transform).apply_to_point(pt2)
|
||||||
dx = pt2[0] - pt1[0]
|
dx = pt2[0] - pt1[0]
|
||||||
dy = pt2[1] - pt1[1]
|
dy = pt2[1] - pt1[1]
|
||||||
stroke_width = math.sqrt(dx * dx + dy * dy)
|
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?).
|
# after the fact (i.e., what's this transform here for?).
|
||||||
# So, we compute the inverse transform and apply it here.
|
# So, we compute the inverse transform and apply it here.
|
||||||
if transform is not None:
|
if transform is not None:
|
||||||
simpletransform.Transform(transform).apply_to_point(pt1)
|
Transform(transform).apply_to_point(pt1)
|
||||||
simpletransform.Transform(transform).apply_to_point(pt2)
|
Transform(transform).apply_to_point(pt2)
|
||||||
# Now generate the path data for the <path>
|
# Now generate the path data for the <path>
|
||||||
if direction:
|
if direction:
|
||||||
# Go this direction
|
# Go this direction
|
||||||
@ -1547,8 +1470,8 @@ class HatchFill(inkex.Effect):
|
|||||||
# after the fact (i.e., what's this transform here for?).
|
# after the fact (i.e., what's this transform here for?).
|
||||||
# So, we compute the inverse transform and apply it here.
|
# So, we compute the inverse transform and apply it here.
|
||||||
if transform is not None:
|
if transform is not None:
|
||||||
simpletransform.Transform(transform).apply_to_point(pt1)
|
Transform(transform).apply_to_point(pt1)
|
||||||
simpletransform.Transform(transform).apply_to_point(pt2)
|
Transform(transform).apply_to_point(pt2)
|
||||||
|
|
||||||
# Now generate the path data for the <path>
|
# Now generate the path data for the <path>
|
||||||
# BUT we want to combine as many paths as possible to reduce pen lifts.
|
# BUT we want to combine as many paths as possible to reduce pen lifts.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import math
|
import math
|
||||||
import inkex
|
import inkex
|
||||||
from simpletransform import Transform
|
from inkex import Transform
|
||||||
inkex.localization.localize()
|
inkex.localization.localize()
|
||||||
|
|
||||||
class IsometricProjectionTools(inkex.Effect):
|
class IsometricProjectionTools(inkex.Effect):
|
||||||
|
@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import inkex
|
import inkex
|
||||||
import bezmisc
|
from inkex import bezier
|
||||||
from inkex.paths import Path, CubicSuperPath
|
from inkex.paths import Path, CubicSuperPath
|
||||||
|
|
||||||
class PasteLengthEffect(inkex.Effect):
|
class PasteLengthEffect(inkex.Effect):
|
||||||
@ -42,7 +42,7 @@ class PasteLengthEffect(inkex.Effect):
|
|||||||
elif(scaleFrom == 'topRight'):
|
elif(scaleFrom == 'topRight'):
|
||||||
oldOrigin= [bbox.right, bbox.bottom]
|
oldOrigin= [bbox.right, bbox.bottom]
|
||||||
elif(scaleFrom == 'bottomLeft'):
|
elif(scaleFrom == 'bottomLeft'):
|
||||||
oldOrigin= [bbox.left, ymax]
|
oldOrigin= [bbox.left, bbox.top]
|
||||||
elif(scaleFrom == 'bottomRight'):
|
elif(scaleFrom == 'bottomRight'):
|
||||||
oldOrigin= [bbox.right, bbox.top]
|
oldOrigin= [bbox.right, bbox.top]
|
||||||
else: #if(scaleFrom == 'center'):
|
else: #if(scaleFrom == 'center'):
|
||||||
@ -79,7 +79,7 @@ class PasteLengthEffect(inkex.Effect):
|
|||||||
|
|
||||||
for i, part in enumerate(parts):
|
for i, part in enumerate(parts):
|
||||||
for j, seg in enumerate(part):
|
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
|
return curveLen
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
import inkex
|
import inkex
|
||||||
from inkex import bezier
|
from inkex import bezier
|
||||||
from inkex.paths import CubicSuperPath
|
from inkex.paths import CubicSuperPath
|
||||||
import bezmisc
|
|
||||||
import simpletransform
|
import simpletransform
|
||||||
import copy
|
import copy
|
||||||
from math import ceil
|
from math import ceil
|
||||||
@ -100,8 +99,7 @@ class SubdividePathEffect(inkex.Effect):
|
|||||||
|
|
||||||
newSegs = []
|
newSegs = []
|
||||||
for j, seg in enumerate(part):
|
for j, seg in enumerate(part):
|
||||||
|
segL = bezier.bezierlength((seg[0], seg[1], seg[2], seg[3]), tolerance = tolerance)
|
||||||
segL = bezmisc.bezierlengthSimpson((seg[0], seg[1], seg[2], seg[3]), tolerance = tolerance)
|
|
||||||
|
|
||||||
if(maxL != None):
|
if(maxL != None):
|
||||||
divL = maxL
|
divL = maxL
|
||||||
@ -121,7 +119,7 @@ class SubdividePathEffect(inkex.Effect):
|
|||||||
if(s == seg):
|
if(s == seg):
|
||||||
sL = segL
|
sL = segL
|
||||||
else:
|
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)):
|
if(floatCmpWithMargin(segL, coveredL + divL)):
|
||||||
s2 = s
|
s2 = s
|
||||||
|
Reference in New Issue
Block a user