Commit c82da85e authored by Gary Hodgson's avatar Gary Hodgson Committed by Guillaume Seguin

formatting of code

parent a5281465
...@@ -52,14 +52,14 @@ def main(): ...@@ -52,14 +52,14 @@ def main():
"""Entry-point of the executable.""" """Entry-point of the executable."""
# Get command-line options # Get command-line options
option_parser = optparse.OptionParser( option_parser = optparse.OptionParser(
usage="usage: %prog filename [options]", version=VERSION) usage = "usage: %prog filename [options]", version = VERSION)
option_parser.add_option( option_parser.add_option(
"-f", "--format", help="output format") "-f", "--format", help = "output format")
option_parser.add_option( option_parser.add_option(
"-d", "--dpi", help="svg resolution", default=96) "-d", "--dpi", help = "svg resolution", default = 96)
option_parser.add_option( option_parser.add_option(
"-o", "--output", "-o", "--output",
default="", help="output filename") default = "", help = "output filename")
options, args = option_parser.parse_args() options, args = option_parser.parse_args()
# Print help if no argument is given # Print help if no argument is given
......
...@@ -79,7 +79,7 @@ def remove_svg_namespace(tree): ...@@ -79,7 +79,7 @@ def remove_svg_namespace(tree):
class Node(dict): class Node(dict):
"""SVG node with dict-like properties and children.""" """SVG node with dict-like properties and children."""
def __init__(self, node, parent=None): def __init__(self, node, parent = None):
"""Create the Node from ElementTree ``node``, with ``parent`` Node.""" """Create the Node from ElementTree ``node``, with ``parent`` Node."""
super(Node, self).__init__() super(Node, self).__init__()
self.children = () self.children = ()
...@@ -145,11 +145,11 @@ class Node(dict): ...@@ -145,11 +145,11 @@ class Node(dict):
children = [] children = []
for child in node: for child in node:
children.append(Node(child, parent=self)) children.append(Node(child, parent = self))
if child.tail: if child.tail:
anonymous = ElementTree.Element('tspan') anonymous = ElementTree.Element('tspan')
anonymous.text = child.tail anonymous.text = child.tail
children.append(Node(anonymous, parent=self)) children.append(Node(anonymous, parent = self))
return list(children) return list(children)
......
...@@ -50,7 +50,7 @@ class Surface(object): ...@@ -50,7 +50,7 @@ class Surface(object):
surface_class = None surface_class = None
@classmethod @classmethod
def convert(cls, bytestring=None, **kwargs): def convert(cls, bytestring = None, **kwargs):
"""Convert a SVG document to the format for this class. """Convert a SVG document to the format for this class.
Specify the input by passing one of these: Specify the input by passing one of these:
...@@ -172,7 +172,7 @@ class Surface(object): ...@@ -172,7 +172,7 @@ class Surface(object):
"""Draw the root ``node``.""" """Draw the root ``node``."""
self.draw(node) self.draw(node)
def draw(self, node, stroke_and_fill=True): def draw(self, node, stroke_and_fill = True):
"""Draw ``node`` and its children.""" """Draw ``node`` and its children."""
old_font_size = self.font_size old_font_size = self.font_size
self.font_size = size(self, node.get("font-size", "12pt")) self.font_size = size(self, node.get("font-size", "12pt"))
......
...@@ -200,7 +200,7 @@ COLORS = { ...@@ -200,7 +200,7 @@ COLORS = {
"windowtext": "#000000"} "windowtext": "#000000"}
def color(string=None, opacity=1): def color(string = None, opacity = 1):
"""Replace ``string`` representing a color by a RGBA tuple.""" """Replace ``string`` representing a color by a RGBA tuple."""
if not string or string in ("none", "transparent"): if not string or string in ("none", "transparent"):
return (0, 0, 0, 0) return (0, 0, 0, 0)
......
...@@ -107,7 +107,7 @@ def draw_gradient(surface, node, name): ...@@ -107,7 +107,7 @@ def draw_gradient(surface, node, name):
if gradient_node.get("gradientUnits") != "userSpaceOnUse": if gradient_node.get("gradientUnits") != "userSpaceOnUse":
gradient_pattern.set_matrix(cairo.Matrix( gradient_pattern.set_matrix(cairo.Matrix(
1 / width, 0, 0, 1 / height, - x / width, - y / height)) 1 / width, 0, 0, 1 / height, -x / width, -y / height))
gradient_pattern.set_extend(getattr( gradient_pattern.set_extend(getattr(
cairo, "EXTEND_%s" % node.get("spreadMethod", "pad").upper())) cairo, "EXTEND_%s" % node.get("spreadMethod", "pad").upper()))
...@@ -141,7 +141,7 @@ def draw_pattern(surface, name): ...@@ -141,7 +141,7 @@ def draw_pattern(surface, name):
surface.context.set_source(pattern_pattern) surface.context.set_source(pattern_pattern)
def draw_marker(surface, node, position="mid"): def draw_marker(surface, node, position = "mid"):
"""Draw a marker.""" """Draw a marker."""
# TODO: manage markers for other tags than path # TODO: manage markers for other tags than path
if position == "start": if position == "start":
...@@ -229,7 +229,7 @@ def use(surface, node): ...@@ -229,7 +229,7 @@ def use(surface, node):
del node["viewBox"] del node["viewBox"]
href = node.get("{http://www.w3.org/1999/xlink}href") href = node.get("{http://www.w3.org/1999/xlink}href")
url = list(urls(href))[0] url = list(urls(href))[0]
tree = Tree(url=url, parent=node) tree = Tree(url = url, parent = node)
surface.set_context_size(*node_format(surface, tree)) surface.set_context_size(*node_format(surface, tree))
surface.draw(tree) surface.draw(tree)
surface.context.restore() surface.context.restore()
......
...@@ -68,7 +68,7 @@ def node_format(surface, node): ...@@ -68,7 +68,7 @@ def node_format(surface, node):
return width, height, viewbox return width, height, viewbox
def normalize(string=None): def normalize(string = None):
"""Normalize a string corresponding to an array of various values.""" """Normalize a string corresponding to an array of various values."""
string = string.replace("-", " -") string = string.replace("-", " -")
string = string.replace(",", " ") string = string.replace(",", " ")
...@@ -91,7 +91,7 @@ def normalize(string=None): ...@@ -91,7 +91,7 @@ def normalize(string=None):
return string.strip() return string.strip()
def point(surface, string=None): def point(surface, string = None):
"""Return ``(x, y, trailing_text)`` from ``string``.""" """Return ``(x, y, trailing_text)`` from ``string``."""
if not string: if not string:
return (0, 0, "") return (0, 0, "")
......
...@@ -56,7 +56,7 @@ def open_data_url(url): ...@@ -56,7 +56,7 @@ def open_data_url(url):
if header: if header:
semi = header.rfind(";") semi = header.rfind(";")
if semi >= 0 and "=" not in header[semi:]: if semi >= 0 and "=" not in header[semi:]:
encoding = header[semi+1:] encoding = header[semi + 1:]
else: else:
encoding = "" encoding = ""
else: else:
...@@ -110,7 +110,7 @@ def image(surface, node): ...@@ -110,7 +110,7 @@ def image(surface, node):
del node["y"] del node["y"]
if "viewBox" in node: if "viewBox" in node:
del node["viewBox"] del node["viewBox"]
tree = Tree(bytestring=image_bytes) tree = Tree(bytestring = image_bytes)
tree_width, tree_height, viewbox = node_format(surface, tree) tree_width, tree_height, viewbox = node_format(surface, tree)
if not tree_width or not tree_height: if not tree_width or not tree_height:
tree_width = tree["width"] = width tree_width = tree["width"] = width
......
...@@ -30,7 +30,7 @@ UNITS = { ...@@ -30,7 +30,7 @@ UNITS = {
"px": None} "px": None}
def size(surface, string, reference="xy"): def size(surface, string, reference = "xy"):
"""Replace a ``string`` with units by a float value. """Replace a ``string`` with units by a float value.
If ``reference`` is a float, it is used as reference for percentages. If it If ``reference`` is a float, it is used as reference for percentages. If it
......
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