add support for units and handle mindim=None correctly. (#149)
* add support for units and handle mindim=None correctly. * Move baseunit positional argument to the end to avoid disruption.pull/98/head
parent
3a1fe8695d
commit
a0fc28849c
|
@ -100,7 +100,7 @@ def disvg(paths=None, colors=None, filename=None, stroke_widths=None,
|
|||
mindim=600, dimensions=None, viewbox=None, text=None,
|
||||
text_path=None, font_size=None, attributes=None,
|
||||
svg_attributes=None, svgwrite_debug=False,
|
||||
paths2Drawing=False):
|
||||
paths2Drawing=False, baseunit='px'):
|
||||
"""Creates (and optionally displays) an SVG file.
|
||||
|
||||
REQUIRED INPUTS:
|
||||
|
@ -313,12 +313,16 @@ def disvg(paths=None, colors=None, filename=None, stroke_widths=None,
|
|||
dy += 2*margin_size*dy + extra_space_for_style
|
||||
viewbox = "%s %s %s %s" % (xmin, ymin, dx, dy)
|
||||
|
||||
if dx > dy:
|
||||
szx = str(mindim) + 'px'
|
||||
szy = str(int(ceil(mindim * dy / dx))) + 'px'
|
||||
if mindim is None:
|
||||
szx = "{}{}".format(dx, baseunit)
|
||||
szy = "{}{}".format(dy, baseunit)
|
||||
else:
|
||||
szx = str(int(ceil(mindim * dx / dy))) + 'px'
|
||||
szy = str(mindim) + 'px'
|
||||
if dx > dy:
|
||||
szx = str(mindim) + baseunit
|
||||
szy = str(int(ceil(mindim * dy / dx))) + baseunit
|
||||
else:
|
||||
szx = str(int(ceil(mindim * dx / dy))) + baseunit
|
||||
szy = str(mindim) + baseunit
|
||||
dimensions = szx, szy
|
||||
|
||||
# Create an SVG file
|
||||
|
@ -428,7 +432,7 @@ def wsvg(paths=None, colors=None, filename=None, stroke_widths=None,
|
|||
mindim=600, dimensions=None, viewbox=None, text=None,
|
||||
text_path=None, font_size=None, attributes=None,
|
||||
svg_attributes=None, svgwrite_debug=False,
|
||||
paths2Drawing=False):
|
||||
paths2Drawing=False, baseunit='px'):
|
||||
"""Create SVG and write to disk.
|
||||
|
||||
Note: This is identical to `disvg()` except that `openinbrowser`
|
||||
|
@ -447,7 +451,7 @@ def wsvg(paths=None, colors=None, filename=None, stroke_widths=None,
|
|||
text_path=text_path, font_size=font_size,
|
||||
attributes=attributes, svg_attributes=svg_attributes,
|
||||
svgwrite_debug=svgwrite_debug,
|
||||
paths2Drawing=paths2Drawing)
|
||||
paths2Drawing=paths2Drawing, baseunit=baseunit)
|
||||
|
||||
|
||||
def paths2Drawing(paths=None, colors=None, filename=None,
|
||||
|
@ -456,7 +460,7 @@ def paths2Drawing(paths=None, colors=None, filename=None,
|
|||
margin_size=0.1, mindim=600, dimensions=None,
|
||||
viewbox=None, text=None, text_path=None,
|
||||
font_size=None, attributes=None, svg_attributes=None,
|
||||
svgwrite_debug=False, paths2Drawing=True):
|
||||
svgwrite_debug=False, paths2Drawing=True, baseunit='px'):
|
||||
"""Create and return `svg.Drawing` object.
|
||||
|
||||
Note: This is identical to `disvg()` except that `paths2Drawing`
|
||||
|
@ -474,4 +478,4 @@ def paths2Drawing(paths=None, colors=None, filename=None,
|
|||
text_path=text_path, font_size=font_size,
|
||||
attributes=attributes, svg_attributes=svg_attributes,
|
||||
svgwrite_debug=svgwrite_debug,
|
||||
paths2Drawing=paths2Drawing)
|
||||
paths2Drawing=paths2Drawing, baseunit=baseunit)
|
||||
|
|
Loading…
Reference in New Issue