Skip to content
Snippets Groups Projects
Commit 2ca82b63 authored by klorpa's avatar klorpa
Browse files

PYSpace

parent bdd60815
No related branches found
No related tags found
1 merge request!4503Small Stuff
......@@ -67,19 +67,11 @@ def get_points(xpath_shape):
points = []
path_length = None
for path_data in paths_data:
<<<<<<< HEAD
p = parse_path(path_data)
points += [
p.point(1.0/float(REFERENCE_PATH_SAMPLES)*i)
for i in range(REFERENCE_PATH_SAMPLES)
]
=======
p = parse_path(path_data)
points += [
p.point(1.0/float(REFERENCE_PATH_SAMPLES)*i)
for i in range(REFERENCE_PATH_SAMPLES)
]
>>>>>>> 14b240a283262b8791485ed8f234dfbe31a62dc7
if (not points):
raise RuntimeError(
'No paths for reference points found by selector "%s".'%(xpath_shape)
......
......@@ -69,15 +69,9 @@ layers = tree.xpath('//svg:g',namespaces=ns)
for layer in layers:
i = layer.get('id')
if ( # disregard non-content groups
<<<<<<< HEAD
i.endswith("_") or # manually suppressed with underscore
i.startswith("XMLID") or # Illustrator generated group
i.startswith("g") # Inkscape generated group
=======
i.endswith("_") or # manually suppressed with underscore
i.startswith("XMLID") or # Illustrator generated group
i.startswith("g") # Inkscape generated group
>>>>>>> 14b240a283262b8791485ed8f234dfbe31a62dc7
):
continue
# create new canvas
......@@ -92,7 +86,6 @@ for layer in layers:
# TODO: extract only referenced defs (filters, gradients, ...)
# TODO: detect necessity by traversing the elements. do not stupidly search in the string representation
if ("filter:" in svg.decode('utf-8')):
<<<<<<< HEAD
# it seems there is a filter referenced in the generated SVG, re-insert defs from main document
canvas.insert(0,defs)
# re-generate output
......@@ -114,29 +107,6 @@ for layer in layers:
else:
svg = svg.replace('<g ','<g transform="\'+_art_transform+\'"') # otherwise use default scaling
svg = svg.encode('utf-8')
=======
# it seems there is a filter referenced in the generated SVG, re-insert defs from main document
canvas.insert(0,defs)
# re-generate output
svg = etree.tostring(output, pretty_print=False)
if (output_format == 'tw'):
# remove unnecessary attributes
# TODO: never generate unnecessary attributes in the first place
svg = svg.decode('utf-8')
svg = regex_xmlns.sub('',svg)
svg = svg.replace(' inkscape:connector-curvature="0"','') # this just saves space
svg = svg.replace('\n','').replace('\r','') # print cannot be multi-line
svg = regex_space.sub('><',svg) # remove indentation
svg = svg.replace('svg:','') # svg namespace was removed
if ("Boob" in i): # internal groups are used for scaling
svg = svg.replace('<g ','<g transform="\'+_artTransformBoob+\'"') # boob art uses the boob scaling
elif ("Belly" in i):
svg = svg.replace('<g ','<g transform="\'+_artTransformBelly+\'"') # belly art uses the belly scaling
else:
svg = svg.replace('<g ','<g transform="\'+_art_transform+\'"') # otherwise use default scaling
svg = svg.encode('utf-8')
>>>>>>> 14b240a283262b8791485ed8f234dfbe31a62dc7
# save SVG string to file
i = layer.get('id')
......
......@@ -74,7 +74,6 @@ regex_transformAttr = re.compile('transform="[^"]*"', )
# find all groups
layers = tree.xpath('//svg:g', namespaces=ns)
for layer in layers:
<<<<<<< HEAD
i = layer.get('id')
if ( # disregard non-content groups
i.endswith("_") or # manually suppressed with underscore
......@@ -139,69 +138,3 @@ for layer in layers:
f.write("<<print '<html>".encode("utf-8"))
f.write(svg)
f.write("</html>' >>".encode("utf-8"))
=======
i = layer.get('id')
if ( # disregard non-content groups
i.endswith("_") or # manually suppressed with underscore
i.startswith("XMLID") or # Illustrator generated group
i.startswith("g") # Inkscape generated group
):
continue
# create new canvas
output = copy.deepcopy(template)
# copy all shapes into template
canvas = output.getroot()
for e in layer:
canvas.append(e)
# represent template as SVG (binary string)
svg = etree.tostring(output, pretty_print=False)
# poor man's conditional defs insertion
# TODO: extract only referenced defs (filters, gradients, ...)
# TODO: detect necessity by traversing the elements. do not stupidly search in the string representation
if ("filter:" in svg.decode('utf-8')):
# it seems there is a filter referenced in the generated SVG, re-insert defs from main document
canvas.insert(0, defs)
# re-generate output
svg = etree.tostring(output, pretty_print=False)
elif ("clip-path=" in svg.decode('utf-8')):
# it seems there is a clip path referenced in the generated SVG, re-insert defs from main document
canvas.insert(0, defs)
# re-generate output
svg = etree.tostring(output, pretty_print=False)
if (output_format == 'tw'):
# remove unnecessary attributes
# TODO: never generate unnecessary attributes in the first place
svg = svg.decode('utf-8')
svg = regex_xmlns.sub('', svg)
svg = svg.replace(' inkscape:connector-curvature="0"', '') # this just saves space
svg = svg.replace('\n', '').replace('\r', '') # print cannot be multi-line
svg = regex_space.sub('><', svg) # remove indentation
svg = svg.replace('svg:', '') # svg namespace was removed
transformGroups = regex_transformVar.findall(svg)
if (len(transformGroups) > 0):
svg = regex_transformAttr.sub('', svg)
for transformGroup in transformGroups:
transformValue = regex_transformValue.search(transformGroup)
if (transformValue is not None):
svg = svg.replace(transformGroup, ' transform="\'+' + transformValue.group() + '+\'" ') # internal groups are used for scaling
svg = svg.encode('utf-8')
# save SVG string to file
i = layer.get('id')
output_path = os.path.join(output_directory, i + '.' + output_format)
with open(output_path, 'wb') as f:
if (output_format == 'svg'):
# Header for normal SVG (XML)
f.write('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'.encode("utf-8"))
f.write(svg)
elif (output_format == 'tw'):
# Header for SVG in Twine file (SugarCube print statement)
f.write((':: Art_Vector_Revamp_%s [nobr]\n\n' % (i)).encode("utf-8"))
f.write("<<print '<html>".encode("utf-8"))
f.write(svg)
f.write("</html>' >>".encode("utf-8"))
>>>>>>> 14b240a283262b8791485ed8f234dfbe31a62dc7
......@@ -36,13 +36,7 @@ Run the node package manager (npm) in the repository:
npm install
CAUTION: dependencies list (located in the package.json file in the repository root) may change from
<<<<<<< HEAD
commit to commit and it differs between branches! Make sure to install correct dependencies after
switching working branch.
=======
commit to commit and it differs between branches! Make sure to install correct dependencies after switching working branch.
>>>>>>> 14b240a283262b8791485ed8f234dfbe31a62dc7
Patching and building SugarCube.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment