#!/usr/bin/env python # -*- coding: utf-8 -*- #Copyright (c) 2011 Walter Bender # Port To GTK3: # Ignacio Rodriguez # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # You should have received a copy of the GNU General Public License # along with this library; if not, write to the Free Software # Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA import os class SVG: ''' SVG generators ''' def __init__(self): self._scale = 1 self._stroke_width = 1 self._fill = '#FFFFFF' self._stroke = '#000000' def _svg_style(self, extras=""): return "%s%s%s%s%s%f%s%s%s" % (" style=\"fill:", self._fill, ";stroke:", self._stroke, ";stroke-width:", self._stroke_width, ";", extras, "\" />\n") def _svg_xo(self): self.set_stroke_width(3.5) svg_string = "\n" svg_string += "\n" svg_string += "\n") svg_string += "%s%f%s%f%s" % ("\n") if background: svg_string += self._background(scale) return svg_string def footer(self): svg_string = "\n" svg_string += "\n" return svg_string # # Utility functions # def set_scale(self, scale=1.0): self._scale = scale def set_colors(self, colors): self._stroke = colors[0] self._fill = colors[1] def set_stroke_width(self, stroke_width=1.0): self._stroke_width = stroke_width def generate_xo(scale=1, colors=["#FFFFFF", "#000000"]): svg = SVG() svg.set_scale(scale) svg.set_colors(colors) svg_string = svg.header(background=False) svg_string += svg._svg_xo() svg_string += svg.footer() return svg_string