Commit 6b956b31 authored by Martin Owens's avatar Martin Owens 🤖

Remove use of addNS in extension code

parent 2abd28b4
Pipeline #152145737 running with stages
in 3 minutes and 57 seconds
......@@ -27,9 +27,10 @@ Import a DHW file from ACECAD DigiMemo, a hardware based digitiser
import struct
import inkex
from inkex import AbortExtension, errormsg, addNS, Group, Polyline
from inkex.utils import NSS
from inkex import AbortExtension, errormsg, Group, Polyline
NSDM = 'http://github.com/nikitakit/DM2SVG'
NSS['dm'] = 'http://github.com/nikitakit/DM2SVG'
class DhwInput(inkex.InputExtension):
"""Open DHW files and convert to svg on the fly"""
......@@ -91,7 +92,7 @@ class DhwInput(inkex.InputExtension):
poly = layer.add(Polyline())
poly.path = coords
poly.set(addNS('timestamp', NSDM), str(timestamp))
poly.set('dm:timestamp', timestamp)
return doc
......
......@@ -137,7 +137,7 @@ def check_text_on_path(svg, element, scale_x, scale_y):
element.set('style', str(inkex.Style(sdict)))
# inner tspans
for child in element.iterdescendants():
if child.tag == inkex.addNS('tspan', 'svg'):
if isinstance(element, inkex.Tspan):
sdict = dict(inkex.Style.parse_str(child.get('style')))
if prop in sdict:
sdict[prop] = float(sdict[prop]) * descrim
......
......@@ -52,35 +52,32 @@ def draw_SVG_circle(rad, centre, params, style, name, parent): # draw an SVG ci
circ_style = {'stroke': style.c_col, 'stroke-width': str(style.c_th), 'fill': style.c_fill}
cx, cy = get_cartesian_pt(centre, params)
circ_attribs = {'style': str(inkex.Style(circ_style)),
inkex.addNS('label', 'inkscape'): name,
'cx': str(cx), 'cy': str(cy),
'r': str(r)}
parent.add(Circle(**circ_attribs))
circ_attribs = {'cx': str(cx), 'cy': str(cy), 'r': str(r)}
elem = parent.add(Circle(**circ_attribs))
elem.style = circ_style
elem.label = name
# draw an SVG triangle given in trilinar coords
def draw_SVG_tri(vert_mat, params, style, name, parent):
p1, p2, p3 = get_cartesian_tri(vert_mat, params) # get the vertex matrix in cartesian points
tri_style = {'stroke': style.l_col, 'stroke-width': str(style.l_th), 'fill': style.l_fill}
tri_attribs = {'style': str(inkex.Style(tri_style)),
inkex.addNS('label', 'inkscape'): name,
'd': 'M ' + str(p1[0]) + ',' + str(p1[1]) +
' L ' + str(p2[0]) + ',' + str(p2[1]) +
' L ' + str(p3[0]) + ',' + str(p3[1]) +
' L ' + str(p1[0]) + ',' + str(p1[1]) + ' z'}
parent.add(PathElement(**tri_attribs))
elem = parent.add(PathElement())
elem.path = 'M ' + str(p1[0]) + ',' + str(p1[1]) +\
' L ' + str(p2[0]) + ',' + str(p2[1]) +\
' L ' + str(p3[0]) + ',' + str(p3[1]) +\
' L ' + str(p1[0]) + ',' + str(p1[1]) + ' z'
elem.style = {'stroke': style.l_col, 'stroke-width': str(style.l_th), 'fill': style.l_fill}
elem.label = name
# draw an SVG line segment between the given (raw) points
def draw_SVG_line(a, b, style, name, parent):
(x1, y1) = a
(x2, y2) = b
line_style = {'stroke': style.l_col, 'stroke-width': str(style.l_th), 'fill': style.l_fill}
line_attribs = {'style': str(inkex.Style(line_style)),
inkex.addNS('label', 'inkscape'): name,
'd': 'M ' + str(x1) + ',' + str(y1) + ' L ' + str(x2) + ',' + str(y2)}
parent.add(PathElement(**line_attribs))
line = parent.add(PathElement())
line.style = {'stroke': style.l_col, 'stroke-width': str(style.l_th), 'fill': style.l_fill}
line.path = 'M ' + str(x1) + ',' + str(y1) + ' L ' + str(x2) + ',' + str(y2)
line.lavel = name
# lines from each vertex to a corresponding point in trilinears
......@@ -244,10 +241,8 @@ class DrawFromTriangle(inkex.EffectExtension):
# CREATE A GROUP TO HOLD ALL GENERATED ELEMENTS IN
# Hold relative to point A (pt[0])
group_translation = 'translate(' + str(pts[0][0]) + ',' + str(pts[0][1]) + ')'
group_attribs = {inkex.addNS('label', 'inkscape'): 'TriangleElements',
'transform': group_translation}
layer = self.svg.get_current_layer().add(inkex.Group(**group_attribs))
layer = self.svg.get_current_layer().add(inkex.Group.new('TriangleElements'))
layer.transform = 'translate(' + str(pts[0][0]) + ',' + str(pts[0][1]) + ')'
# GET METRICS OF THE TRIANGLE
# vertices in the local coordinates (set pt[0] to be the origin)
......
......@@ -69,8 +69,8 @@ def export_MTEXT():
attribs.update({'transform': 'rotate (%f %f %f)' % (-90, x, y)})
elif vals[groups['21']][0] == -1.0:
attribs.update({'transform': 'rotate (%f %f %f)' % (90, x, y)})
attribs.update({inkex.addNS('linespacing', 'sodipodi'): '125%'})
node = etree.SubElement(layer, 'text', attribs)
node = layer.add(inkex.Text(**attribs))
node.set('sodipodi:linespacing', '125%')
text = ''
if vals[groups['3']]:
for i in range(0, len(vals[groups['3']])):
......@@ -79,11 +79,13 @@ def export_MTEXT():
text += vals[groups['1']][0]
found = text.find(r'\P') # new line
while found > -1:
tspan = etree.SubElement(node, 'tspan', {inkex.addNS('role', 'sodipodi'): 'line'})
tspan = node.add(inkex.Tspan())
tspan.set('sodipodi:role', 'line')
tspan.text = text[:found]
text = text[(found + 2):]
found = text.find(r'\P')
tspan = etree.SubElement(node, 'tspan', {inkex.addNS('role', 'sodipodi'): 'line'})
tspan = node.add(inkex.Tspan())
tspan.set('sodipodi:role', 'line')
tspan.text = text
......@@ -303,7 +305,8 @@ def export_DIMENSION():
if dx == 0:
attribs.update({'transform': 'rotate (%f %f %f)' % (-90, x, y)})
node = etree.SubElement(layer, 'text', attribs)
tspan = etree.SubElement(node, 'tspan', {inkex.addNS('role', 'sodipodi'): 'line'})
tspan = node.add(inkex.Tspan())
tspan.set('sodipodi:role', 'line')
tspan.text = str(float('%.2f' % d))
......@@ -312,12 +315,11 @@ def export_INSERT():
if vals[groups['2']] and vals[groups['10']] and vals[groups['20']]:
x = vals[groups['10']][0] + scale * xmin
y = vals[groups['20']][0] - scale * ymin - height
attribs = {inkex.addNS('href', 'xlink'): '#' + quote(vals[groups['2']][0].replace(" ", "_").encode("utf-8"))}
tform = 'translate(%f, %f)' % (x, y)
elem = layer.add(inkex.Use())
elem.set('xlink:href', '#' + quote(vals[groups['2']][0].replace(" ", "_").encode("utf-8")))
elem.transform = 'translate(%f, %f)' % (x, y)
if vals[groups['41']] and vals[groups['42']]:
tform += ' scale(%f, %f)' % (vals[groups['41']][0], vals[groups['42']][0])
attribs.update({'transform': tform})
etree.SubElement(layer, 'use', attribs)
elem.transform.add_scale(vals[groups['41']][0], vals[groups['42']][0])
def export_BLOCK():
......@@ -363,9 +365,10 @@ def generate_ellipse(xc, yc, xm, ym, w, a1, a2):
def generate_gcodetools_point(xc, yc):
path = 'm %s,%s 2.9375,-6.34375 0.8125,1.90625 6.84375,-6.84375 0,0 0.6875,0.6875 -6.84375,6.84375 1.90625,0.8125 z' % (xc, yc)
attribs = {'d': path, inkex.addNS('dxfpoint', 'inkscape'): '1', 'style': 'stroke:none;fill:#ff0000'}
etree.SubElement(layer, 'path', attribs)
elem = layer.add(inkex.PathElement())
elem.style = 'stroke:none;fill:#ff0000'
elem.set('inkscape:dxfpoint', '1')
elem.path = 'm %s,%s 2.9375,-6.34375 0.8125,1.90625 6.84375,-6.84375 0,0 0.6875,0.6875 -6.84375,6.84375 1.90625,0.8125 z' % (xc, yc)
# define DXF Entities and specify which Group Codes to monitor
......@@ -437,7 +440,8 @@ class DxfInput(inkex.InputExtension):
options = self.options
doc = self.get_template(width=210 * 96 / 25.4, height=297 * 96 / 25.4)
defs = doc.getroot().defs
svg = doc.getroot()
defs = svg.defs
marker = etree.SubElement(defs, 'marker', {'id': 'DistanceX', 'orient': 'auto', 'refX': '0.0', 'refY': '0.0', 'style': 'overflow:visible'})
etree.SubElement(marker, 'path', {'d': 'M 3,-3 L -3,3 M 0,-5 L 0,5', 'style': 'stroke:#000000; stroke-width:0.5'})
pattern = etree.SubElement(defs, 'pattern', {'id': 'Hatch', 'patternUnits': 'userSpaceOnUse', 'width': '8', 'height': '8', 'x': '0', 'y': '0'})
......@@ -481,8 +485,7 @@ class DxfInput(inkex.InputExtension):
xmax = get_group('10')
if flag == 1 and line[0] == '2':
layername = line[1]
attribs = {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): '%s' % layername}
layer_nodes[layername] = etree.SubElement(doc.getroot(), 'g', attribs)
layer_nodes[layername] = svg.add(inkex.Layer.new(layername))
if flag == 2 and line[0] == '2':
linename = line[1]
linetypes[linename] = []
......@@ -515,13 +518,13 @@ class DxfInput(inkex.InputExtension):
scale = float(options.scale) # manual scale factor
xmin = float(options.xmin)
ymin = float(options.ymin)
doc.getroot().description('%s - scale = %f, origin = (%f, %f), method = %s' % (
svg.description('%s - scale = %f, origin = (%f, %f), method = %s' % (
os.path.basename(options.input_file), scale, xmin, ymin, options.scalemethod))
scale *= 96.0 / 25.4 # convert from mm to pixels
if '0' not in layer_nodes:
attribs = {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): '0'}
layer_nodes['0'] = etree.SubElement(doc.getroot(), 'g', attribs)
layer_nodes['0'] = svg.add(inkex.Layer.new('0'))
layer_colors['0'] = 7
for linename in linetypes.keys(): # scale the dashed lines
......@@ -571,8 +574,7 @@ class DxfInput(inkex.InputExtension):
if not vals[groups['8']][0]:
vals[groups['8']][0] = '0' # use default name
if vals[groups['8']][0] not in layer_nodes:
attribs = {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): '%s' % vals[groups['8']][0]}
layer_nodes[vals[groups['8']][0]] = etree.SubElement(doc.getroot(), 'g', attribs)
layer_nodes[vals[groups['8']][0]] = svg.add(inkex.Layer.new(vals[groups['8']][0]))
layer = layer_nodes[vals[groups['8']][0]]
color = '#000000' # default color
if vals[groups['8']]:
......
......@@ -1403,11 +1403,7 @@ def draw_text(text, x, y, group=None, style=None, font_size=10, gcodetools_tag=N
if style is None:
style = "font-family:DejaVu Sans;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:DejaVu Sans;fill:#000000;fill-opacity:1;stroke:none;"
style += "font-size:{:f}px;".format(font_size)
attributes = {'x': str(x),
inkex.addNS("space", "xml"): "preserve",
'y': str(y),
'style': style
}
attributes = {'x': str(x), 'y': str(y), 'style': style}
if gcodetools_tag is not None:
attributes["gcodetools"] = str(gcodetools_tag)
......@@ -1415,6 +1411,7 @@ def draw_text(text, x, y, group=None, style=None, font_size=10, gcodetools_tag=N
group = options.doc_root
text_elem = group.add(TextElement(**attributes))
text_elem.set("xml:space", "preserve")
text = str(text).split("\n")
for string in text:
span = text_elem.add(Tspan(x=str(x), y=str(y)))
......@@ -3444,19 +3441,19 @@ class Gcodetools(inkex.EffectExtension):
if self.layers[i] in self.orientation_points:
break
if self.layers[i] not in self.orientation_points:
self.error("Orientation points for '{}' layer have not been found! Please add orientation points using Orientation tab!".format(layer.get(inkex.addNS('label', 'inkscape'))), "error")
self.error(f"Orientation points for '{layer.label}' layer have not been found! Please add orientation points using Orientation tab!", "error")
elif self.layers[i] in self.transform_matrix:
self.transform_matrix[layer] = self.transform_matrix[self.layers[i]]
self.Zcoordinates[layer] = self.Zcoordinates[self.layers[i]]
else:
orientation_layer = self.layers[i]
if len(self.orientation_points[orientation_layer]) > 1:
self.error("There are more than one orientation point groups in '{}' layer".format(orientation_layer.get(inkex.addNS('label', 'inkscape'))))
self.error(f"There are more than one orientation point groups in '{orientation_layer.label}' layer")
points = self.orientation_points[orientation_layer][0]
if len(points) == 2:
points += [[[(points[1][0][1] - points[0][0][1]) + points[0][0][0], -(points[1][0][0] - points[0][0][0]) + points[0][0][1]], [-(points[1][1][1] - points[0][1][1]) + points[0][1][0], points[1][1][0] - points[0][1][0] + points[0][1][1]]]]
if len(points) == 3:
print_("Layer '{}' Orientation points: ".format(orientation_layer.get(inkex.addNS('label', 'inkscape'))))
print_("Layer '{orientation_layer.label}' Orientation points: ")
for point in points:
print_(point)
# Zcoordinates definition taken from Orientatnion point 1 and 2
......@@ -3487,7 +3484,7 @@ class Gcodetools(inkex.EffectExtension):
self.error("Orientation points are wrong! (if there are two orientation points they should not be the same. If there are three orientation points they should not be in a straight line.)", "error")
self.transform_matrix_reverse[layer] = numpy.linalg.inv(self.transform_matrix[layer]).tolist()
print_("\n Layer '{}' transformation matrixes:".format(layer.get(inkex.addNS('label', 'inkscape'))))
print_(f"\n Layer '{layer.label}' transformation matrixes:")
print_(self.transform_matrix)
print_(self.transform_matrix_reverse)
......@@ -3574,7 +3571,7 @@ class Gcodetools(inkex.EffectExtension):
if selected:
self.svg.selected[i.get("id")] = i
if isinstance(i, Layer):
if i.get(inkex.addNS('label', 'inkscape')) == '3D':
if i.label == '3D':
self.my3Dlayer = i
else:
self.layers += [i]
......@@ -3584,24 +3581,24 @@ class Gcodetools(inkex.EffectExtension):
points = self.get_orientation_points(i)
if points is not None:
self.orientation_points[layer] = self.orientation_points[layer] + [points[:]] if layer in self.orientation_points else [points[:]]
print_("Found orientation points in '{}' layer: {}".format(layer.get(inkex.addNS('label', 'inkscape')), points))
print_(f"Found orientation points in '{layer.label}' layer: {points}")
else:
self.error("Warning! Found bad orientation points in '{}' layer. Resulting Gcode could be corrupt!".format(layer.get(inkex.addNS('label', 'inkscape'))))
self.error(f"Warning! Found bad orientation points in '{layer.label}' layer. Resulting Gcode could be corrupt!")
# Need to recognise old files ver 1.6.04 and earlier
elif i.get("gcodetools") == "Gcodetools tool definition" or i.get("gcodetools") == "Gcodetools tool definition":
tool = self.get_tool(i)
self.tools[layer] = self.tools[layer] + [tool.copy()] if layer in self.tools else [tool.copy()]
print_("Found tool in '{}' layer: {}".format(layer.get(inkex.addNS('label', 'inkscape')), tool))
print_(f"Found tool in '{layer.label}' layer: {tool}")
elif i.get("gcodetools") == "Gcodetools graffiti reference point":
point = self.get_graffiti_reference_points(i)
if point:
self.graffiti_reference_points[layer] = self.graffiti_reference_points[layer] + [point[:]] if layer in self.graffiti_reference_points else [point]
else:
self.error("Warning! Found bad graffiti reference point in '{}' layer. Resulting Gcode could be corrupt!".format(layer.get(inkex.addNS('label', 'inkscape'))))
self.error(f"Warning! Found bad graffiti reference point in '{layer.label}' layer. Resulting Gcode could be corrupt!")
elif i.tag == inkex.addNS('path', 'svg'):
elif isinstance(i, inkex.PathElement):
if "gcodetools" not in i.keys():
self.paths[layer] = self.paths[layer] + [i] if layer in self.paths else [i]
if i.get("id") in self.svg.selected.ids:
......@@ -3614,7 +3611,7 @@ class Gcodetools(inkex.EffectExtension):
if j.get("gcodetools") == "In-out reference point":
self.in_out_reference_points.append(self.apply_transforms(j, j.path.to_superpath())[0][0][1])
elif i.tag == inkex.addNS("g", 'svg'):
elif isinstance(i, inkex.Group):
recursive_search(i, layer, (i.get("id") in self.svg.selected))
elif i.get("id") in self.svg.selected:
......@@ -3655,10 +3652,11 @@ class Gcodetools(inkex.EffectExtension):
p3 = []
p = None
for i in items:
if i.tag == inkex.addNS("g", 'svg') and i.get("gcodetools") == "Gcodetools orientation point (2 points)":
p2 += [i]
if i.tag == inkex.addNS("g", 'svg') and i.get("gcodetools") == "Gcodetools orientation point (3 points)":
p3 += [i]
if isinstance(i, inkex.Group):
if i.get("gcodetools") == "Gcodetools orientation point (2 points)":
p2 += [i]
if i.get("gcodetools") == "Gcodetools orientation point (3 points)":
p3 += [i]
if len(p2) == 2:
p = p2
elif len(p3) == 3:
......@@ -3733,10 +3731,11 @@ class Gcodetools(inkex.EffectExtension):
if self.layers[i] != layer:
self.tools[layer] = self.tools[self.layers[i]]
if len(self.tools[layer]) > 1:
self.error("Layer '{}' contains more than one tool!".format(self.layers[i].get(inkex.addNS('label', 'inkscape'))))
label = self.layers[i].label
self.error(f"Layer '{label}' contains more than one tool!")
return self.tools[layer]
else:
self.error("Can not find tool for '{}' layer! Please add one with Tools library tab!".format(layer.get(inkex.addNS('label', 'inkscape'))), "error")
self.error(f"Can not find tool for '{layer.label}' layer! Please add one with Tools library tab!", "error")
################################################################################
#
......@@ -3852,17 +3851,15 @@ class Gcodetools(inkex.EffectExtension):
gcode += "(drilling dxfpoint)\nG00 Z{:f}\nG00 X{:f} Y{:f}\nG01 Z{:f} F{:f}\nG04 P{:f}\nG00 Z{:f}\n".format(self.options.Zsafe, point[0], point[1], self.Zcoordinates[layer][1], self.tools[layer][0]["penetration feed"], 0.2, self.options.Zsafe)
return gcode
def get_path_properties(node, tags=None):
if tags is None:
tags = {inkex.addNS('desc', 'svg'): "Description",
inkex.addNS('title', 'svg'): "Title"}
def get_path_properties(node):
res = {}
done = False
root = self.document.getroot()
while not done and node != root:
while not done and node != self.svg:
for i in node.getchildren():
if i.tag in tags:
res[tags[i.tag]] = i.text
if isinstance(i, inkex.Desc):
res["Description"] = i.text
elif isinstance(i, inkex.Title):
res["Title"] = i.text
done = True
node = node.getparent()
return res
......@@ -4089,7 +4086,7 @@ class Gcodetools(inkex.EffectExtension):
if layer in self.selected_paths:
self.set_tool(layer)
if self.tools[layer][0]['diameter'] <= 0:
self.error("Tool diameter must be > 0 but tool's diameter on '{}' layer is not!".format(layer.get(inkex.addNS('label', 'inkscape'))), "error")
self.error(f"Tool diameter must be > 0 but tool's diameter on '{layer.label}' layer is not!", "error")
for path in self.selected_paths[layer]:
print_(("doing path", path.get("style"), path.get("d")))
......@@ -4184,7 +4181,7 @@ class Gcodetools(inkex.EffectExtension):
if layer in self.selected_paths:
self.set_tool(layer)
if self.tools[layer][0]['diameter'] <= 0:
self.error("Tool diameter must be > 0 but tool's diameter on '{}' layer is not!".format(layer.get(inkex.addNS('label', 'inkscape'))), "error")
self.error(f"Tool diameter must be > 0 but tool's diameter on '{layer.label}' layer is not!", "error")
tool = self.tools[layer][0]
for path in self.selected_paths[layer]:
lines = []
......@@ -4339,14 +4336,12 @@ class Gcodetools(inkex.EffectExtension):
# layer number n appears in XML as <svg:g id="layern" inkscape:label="layername">
#
# to create it, use
# Mylayer=etree.SubElement(self.document.getroot(), 'g') #Create a generic element
# Mylayer.set(inkex.addNS('label', 'inkscape'), "layername") #Gives it a name
# Mylayer.set(inkex.addNS('groupmode', 'inkscape'), 'layer') #Tells Inkscape it's a layer
# Mylayer = self.svg.add(Layer.new('layername'))
#
# group appears in XML as <svg:g id="gnnnnn"> where nnnnn is a number
#
# to create it, use
# Mygroup=etree.SubElement(parent, inkex.addNS('g','svg'), {"gcodetools":"My group label"})
# Mygroup = parent.add(Group(gcodetools="My group label")
# where parent may be the layer or a parent group. To get the parent group, you can use
# parent = self.selected_paths[layer][0].getparent()
################################################################################
......@@ -4775,7 +4770,7 @@ class Gcodetools(inkex.EffectExtension):
gcode_3Dright = self.my3Dlayer.add(Group(gcodetools="Gcode 3D R"))
for node in self.selected_paths[layer]:
if node.tag == inkex.addNS('path', 'svg'):
if isinstance(node, inkex.PathElement):
cspi = node.path.to_superpath()
# LT: Create my own list. n1LT[j] is for subpath j
nlLT = []
......
......@@ -115,7 +115,7 @@ class GenerateVoronoi(inkex.EffectExtension):
pts.append(voronoi.Site(x, y - bbox.height))
elif x > -b and y > -b and x < bbox.width + b and y < bbox.height + b:
pts.append(voronoi.Site(x, y)) # leave border area blank
# dot = etree.SubElement(pattern, inkex.addNS('rect','svg'))
# dot = pattern.add(inkex.Rectangle())
# dot.set('x', str(x-1))
# dot.set('y', str(y-1))
# dot.set('width', '2')
......@@ -168,7 +168,7 @@ class GenerateVoronoi(inkex.EffectExtension):
style = dict(inkex.Style.parse_str(obj.attrib['style']))
style['fill'] = 'url(#%s)' % pattern.get('id')
obj.attrib['style'] = str(inkex.Style(style))
if obj.tag == inkex.addNS('g', 'svg'):
if isinstance(obj, inkex.Group):
for node in obj:
style = {}
if 'style' in node.attrib:
......
......@@ -83,7 +83,7 @@ class GimpXcf(TempDirMixin, inkex.OutputExtension):
@property
def docname(self):
"""Get the document name suitable for export"""
return self.svg.get(inkex.addNS('docname', u'sodipodi')) or 'document'
return self.svg.get('sodipodi:docname') or 'document'
def save(self, stream):
......
......@@ -57,8 +57,8 @@ from copy import deepcopy
import inkex
from inkex import Transform, Style, units
from inkex import load_svg, Group, TextElement, FlowPara, \
FlowSpan, Tspan, FlowRoot, Rectangle, Use, PathElement, Defs
from inkex import load_svg, Group, TextElement, FlowPara, SVGfont, FontFace,\
FlowSpan, Glyph, MissingGlyph, Tspan, FlowRoot, Rectangle, Use, PathElement, Defs
class Hershey(inkex.Effect):
......@@ -509,10 +509,9 @@ Evil Mad Scientist Laboratories
for node in node_list:
if isinstance(node, Defs):
# if node.tag == inkex.addNS('defs', 'svg') or node.tag == 'defs':
return self.parse_svg_font(node) # Recursive call
if node.tag == inkex.addNS('font', 'svg') or node.tag == 'font':
if isinstance(node, SVGfont):
'''
=== Internal structure for storing font information ===
......@@ -574,13 +573,9 @@ Evil Mad Scientist Laboratories
geometry['horiz_adv_x'] = float(horiz_adv_x)
# Note: case of no horiz_adv_x value is not handled.
glyph_tag = inkex.addNS('glyph', 'svg')
ff_tag = inkex.addNS('font-face', 'svg')
mg_tag = inkex.addNS('missing-glyph', 'svg')
for element in node:
if element.tag == 'glyph' or element.tag == glyph_tag:
if isinstance(element, Glyph):
# First, because it is the most common element
try:
uni_text = element.get('unicode')
......@@ -610,7 +605,7 @@ Evil Mad Scientist Laboratories
glyph_dict['d'] = element.get('d') # SVG path data
glyphs[uni_text] = glyph_dict
elif element.tag == 'font-face' or element.tag == ff_tag:
elif isinstance(element, FontFace):
digest['font_family'] = element.get('font-family')
units_per_em = element.get('units-per-em')
......@@ -636,7 +631,7 @@ Evil Mad Scientist Laboratories
geometry['underline_position'] = element.get('underline-position')
'''
elif element.tag == 'missing-glyph' or element.tag == mg_tag:
elif isinstance(element, MissingGlyph):
horiz_adv_x = element.get('horiz-adv-x')
if horiz_adv_x is not None:
......@@ -1461,10 +1456,10 @@ Evil Mad Scientist Laboratories
# Group generated paths together, to make the rendered letters
# easier to manipulate in Inkscape once generated:
g_attribs = {inkex.addNS('label', 'inkscape'):'Hershey Text'}
parent = node.getparent()
group = parent.add(Group(**g_attribs))
group = parent.add(Group())
group.label = 'Hershey Text'
style = {'stroke' : '#000000', 'fill' : 'none', \
'stroke-linecap' : 'round', 'stroke-linejoin' : 'round'}
......@@ -1524,14 +1519,14 @@ Evil Mad Scientist Laboratories
# as a rotated rectangle -- for which text *should* flow in a diamond shape.
# For the time being, we skip these and issue a warning.
#
# refid = flowref.get(inkex.addNS('href', 'xlink'))
# refid = flowref.get('xlink:href')
# if refid is not None:
# # [1:] to ignore leading '#' in reference
# path = '//*[@id="%s"]' % refid[1:]
# refnode = flowref.xpath(path)
# if refnode is not None:
# refnode = refnode[0]
# if refnode.tag == inkex.addNS("rect", "svg"):
# if isinstance(refnode, Rectangle):
# start_x = refnode.get('x")
# start_y = refnode.get('y")
# rect_height = refnode.get('height")
......
......@@ -29,10 +29,8 @@ class Element(object):
def __init__(self, node):
self.node = node
def attr(self, val, ns=""):
def attr(self, val):
"""Get attribute"""
if ns:
val = inkex.addNS(val, ns)
try:
attr = float(self.node.get(val))
except:
......@@ -142,7 +140,6 @@ class AbstractShape(Element):
class G(AbstractShape):
def draw(self):
# get layer label, if exists
gtype = self.attr("groupmode", "inkscape") or "group"
if self.has_transform():
trans_matrix = self.get_transform()
self.ctx.transform(*trans_matrix)
......
......@@ -119,16 +119,15 @@ class ExportSlices(inkex.EffectExtension):
return the nodes of the rectangles.
"""
# get layer we intend to slice
document = self.document
slice_node = None
slice_layer = document.findall(inkex.addNS('g', 'svg'))
slice_layer = self.svg.findall('svg:g')
for node in slice_layer:
label_value = node.label
if label_value == layer_name:
slice_node = node
if slice_node is not None:
return slice_node.findall(inkex.addNS('rect', "svg"))
return slice_node.findall('svg:rect')
return slice_node
......
......@@ -94,14 +94,13 @@ class MeasureLength(inkex.EffectExtension):
self.options.method(node, str(val))
def method_textonpath(self, node, lenstr):
_id = node.get('id')
startOffset = self.options.startOffset
if startOffset == "custom":
startOffset = str(self.options.startOffsetCustom) + '%'
if self.options.mtype == "length":
self.add_textonpath(self.group, 0, 0, lenstr + ' ' + self.options.unit, _id, self.options.anchor, startOffset, self.options.offset)
self.add_textonpath(self.group, 0, 0, lenstr + ' ' + self.options.unit, node, self.options.anchor, startOffset, self.options.offset)
else:
self.add_textonpath(self.group, 0, 0, lenstr + ' ' + self.options.unit + '^2', _id, self.options.anchor, startOffset, self.options.offset)
self.add_textonpath(self.group, 0, 0</