Commit 22442c75 by colm

Merge branch 'master' of gitlab.constantvzw.org:osp/workshop.metapost-workshops

parents 794beff2 aa03d756
......@@ -66,10 +66,16 @@ app = Flask(__name__)
@app.route("/api/plot/")
def plot():
timestamp = int(time.time())
charnum = int(request.args.get('charcode'))
svgfile = 'svg/{}.svg'.format(charnum)
svgsnap = 'svg/snaps/{}-{}.svg'.format(charnum, int(time.time()))
svgsnap = 'svg/snaps/{}-{}.svg'.format(charnum, timestamp)
mpfile = 'mpost/{}.mp'.format(charnum)
mpsnap = 'mpost/snaps/{}-{}.mp'.format(charnum, timestamp)
shutil.copy(svgfile, svgsnap)
shutil.copy(mpfile, mpsnap)
hpgl = svg_to_hpgl(svgsnap, speed, force, penCount)
hpgl += ';PU;SP1;SI{},{};'.format(labelsize[0], labelsize[1])
......
......@@ -208,8 +208,10 @@ class hpglMultipenEncoder:
paths = []
for node in doc:
if (node.tag == inkex.addNS('g', 'svg') and self.isGroupVisible(node)) or node.tag == inkex.addNS('path', 'svg'):
paths.append([node.tag, node, self.mergeTransform(
node, groupmat), self.getPenNumber(node)])
pen = self.getPenNumber(node)
if pen <> 0:
paths.append([node.tag, node, self.mergeTransform(
node, groupmat), self.getPenNumber(node)])
doc = ''
hasGroups = True
while hasGroups:
......@@ -219,8 +221,9 @@ class hpglMultipenEncoder:
hasGroups = True
for path in paths[i][1]:
if (path.tag == inkex.addNS('g', 'svg') and self.isGroupVisible(path)) or path.tag == inkex.addNS('path', 'svg'):
pen = self.getPenNumber(path)
paths.insert(
i + 1, [path.tag, path, self.mergeTransform(path, paths[i][2]), paths[i][3]])
i + 1, [path.tag, path, self.mergeTransform(path, paths[i][2]), pen if pen is not None else paths[i][3]])
paths[i][0] = ''
for node in paths:
if node[0] == inkex.addNS('path', 'svg'):
......@@ -229,13 +232,22 @@ class hpglMultipenEncoder:
def getPenNumber(self, doc):
penNum = str(
doc.get('{' + inkex.NSS['inkscape'] + '}label')).lower().strip(' \t\n\r')
style = doc.get('style')
style = doc.get('style')
style = simplestyle.parseStyle(style)
if re.search(r'( |\A)pen *\d+( |\Z)', penNum):
penNum = re.sub(r'(.* |\A)pen *(\d+)( .*|\Z)', r'\2', penNum, 1)
return int(penNum)
else:
color = style['stroke'] if 'stroke' in style and style['stroke'] <> 'none' else style['fill']
if 'stroke' in style and style['stroke'] <> 'none':
color = style['stroke']
elif 'fill' in style and style['fill'] <> 'none':
color = style['fill']
else:
color = None
#color = style['stroke'] if 'stroke' in style and style['stroke'] <> 'none' else style['fill']
if color is None:
return None
if not self.penIndex.has_key(color):
penNum = (len(self.penIndex) + 1) % self.penCount
self.penIndex[color] = self.penCount if penNum == 0 else penNum
......@@ -404,7 +416,7 @@ class hpglMultipenEncoder:
self.sizeX = x
if self.sizeY == 'False' or y > self.sizeY:
self.sizeY = y
else:
elif pen is not None:
# store point
if not self.options.center:
# only positive values are allowed (usually)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment