summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/asymptote/GUI/xasyFile.py
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/asymptote/GUI/xasyFile.py')
-rwxr-xr-xMaster/texmf-dist/asymptote/GUI/xasyFile.py68
1 files changed, 52 insertions, 16 deletions
diff --git a/Master/texmf-dist/asymptote/GUI/xasyFile.py b/Master/texmf-dist/asymptote/GUI/xasyFile.py
index eee6d69a856..54c70cf5c2b 100755
--- a/Master/texmf-dist/asymptote/GUI/xasyFile.py
+++ b/Master/texmf-dist/asymptote/GUI/xasyFile.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
###########################################################################
#
-# xasyFile implements the loading, parsing, and saving of an xasy file.
+# xasyFile implements the loading, parsing, and saving of an asy file.
#
#
# Author: Orest Shardt
@@ -10,7 +10,7 @@
############################################################################
from string import *
-import xasy2asy as x2a
+import xasy2asy as xasy2asy
import io
import re
@@ -28,7 +28,7 @@ class xasyFileError(Exception):
def extractTransform(line):
"""Returns key and the new transform."""
# see https://regex101.com/r/6DqkRJ/4 for info
- mapString = x2a.xasyItem.mapString
+ mapString = xasy2asy.xasyItem.mapString
testMatch = re.match(
r'^{0:s}\s*\(\s*\"([^\"]+)\"\s*,\s*\(([-\d, .]+)\)\s*\)'.format(mapString), line.strip())
if testMatch is None:
@@ -37,7 +37,7 @@ def extractTransform(line):
return None
else:
key = mapOnlyMatch.group(1)
- return key, x2a.identity()
+ return key, xasy2asy.identity()
else:
key = testMatch.group(1)
rawStr = testMatch.group(2)
@@ -46,7 +46,7 @@ def extractTransform(line):
if len(rawStrArray) != 6:
return None
transf = [float(val.strip()) for val in rawStrArray]
- return key, x2a.asyTransform(transf)
+ return key, xasy2asy.asyTransform(transf)
def extractTransformsFromFile(fileStr):
@@ -62,22 +62,58 @@ def extractTransformsFromFile(fileStr):
if key not in transfDict.keys():
transfDict[key] = []
transfDict[key].append(transf)
-
- # see https://regex101.com/r/RgeBVc/2 for regex
-
- testNum = re.match(r'^x(\d+)($|:.*$)', key)
- if testNum is not None:
- maxItemCount = max(maxItemCount, int(testNum.group(1)))
final_str = rawCode.getvalue()
- return final_str, transfDict, maxItemCount
+ return final_str, transfDict
+
+def xasy2asyCode(xasyItems, asy2psmap):
+ asyCode = ''
+ for item in xasyItems:
+ asyCode += item.getTransformCode(asy2psmap)
+ for item in xasyItems:
+ asyCode += item.getObjectCode(asy2psmap)
+ asyCode += 'size('+str(asy2psmap*xasy2asy.yflip())+'); '+ xasy2asy.xasyItem.resizeComment+'\n'
+ return asyCode
def saveFile(file, xasyItems, asy2psmap):
"""Write a list of xasyItems to a file"""
- for item in xasyItems:
- file.write(item.getTransformCode(asy2psmap))
+ file.write(xasy2asyCode(xasyItems, asy2psmap))
+def xasyToDict(file, xasyItems, asy2psmap):
+ fileItems = []
+ asyItems = []
for item in xasyItems:
- file.write(item.getObjectCode(asy2psmap))
+ if isinstance(item, xasy2asy.xasyScript):
+ # reusing xasyFile code for objects
+ # imported from asy script.
+ asyItems.append({'item':item, 'type': 'xasyScript'})
+
+ elif isinstance(item, xasy2asy.xasyText):
+ # At the moment xasyText cannot be edited
+ # so we treat it the same as xasyScript
+ penData = {'color': item.pen.color, 'width': item.pen.width, 'options': item.pen.options}
+ fileItems.append({'type': 'xasyText',
+ 'align': item.label.align,
+ 'location': item.label.location,
+ 'fontSize': item.label.fontSize,
+ 'text': item.label.text,
+ 'transform': item.transfKeymap[item.transfKey][0].t,
+ 'transfKey': item.transfKey,
+ 'pen': penData
+ })
+
+ elif isinstance(item, xasy2asy.xasyShape):
+ penData = {'color': item.pen.color, 'width': item.pen.width, 'options': item.pen.options}
+ fileItems.append({'type': 'xasyShape',
+ 'nodes': item.path.nodeSet,
+ 'links': item.path.linkSet,
+ 'transform': item.transfKeymap[item.transfKey][0].t,
+ 'transfKey': item.transfKey,
+ 'pen': penData
+ })
+
+ else:
+ # DEBUGGING PURPOSES ONLY
+ print(type(item))
- file.write('size('+str(asy2psmap*x2a.yflip())+'); '+ x2a.xasyItem.resizeComment+'\n')
+ return {'objects': fileItems, 'asy2psmap': asy2psmap.t}, asyItems