kete: Normalize SVG dimensions (increase viewer compatibility)

This commit is contained in:
Ishak BELAHMAR 2019-04-22 12:10:57 +02:00 committed by Benjamin Tissoires
parent 9e85b4d248
commit 7cd269b092
1 changed files with 14 additions and 4 deletions

View File

@ -586,18 +586,28 @@ class Fetcher(Worker):
def json_to_svg(self, js, filename): def json_to_svg(self, js, filename):
dimensions = js['dimensions'] dimensions = js['dimensions']
if dimensions == [0, 0]: if dimensions == [0, 0]:
dimensions = 100, 100 width, height = 100, 100
svg = svgwrite.Drawing(filename=filename, size=dimensions) else:
# Original diemnsions are too big for SVG Standard
# so we nomalize them
width, height = dimensions[0]/100, dimensions[1]/100
svg = svgwrite.Drawing(filename=filename, size=(width, height))
g = svgwrite.container.Group(id='layer0') g = svgwrite.container.Group(id='layer0')
for s in js['strokes']: for s in js['strokes']:
svgpoints = [] svgpoints = []
mode = 'M' mode = 'M'
for p in s['points']: for p in s['points']:
x, y = p['position'] x, y = p['position']
# Normalize coordinates too
x, y = x/100, y/100
svgpoints.append((mode, x, y)) svgpoints.append((mode, x, y))
mode = 'L' mode = 'L'
path = svgwrite.path.Path(d=svgpoints, path = svgwrite.path.Path(
style='fill:none;stroke:black;stroke-width:5') d=svgpoints,
stroke_width=0.2,
stroke='black',
fill='none'
)
g.add(path) g.add(path)
svg.add(g) svg.add(g)