diff --git a/gramps/plugins/docgen/docgen.gpr.py b/gramps/plugins/docgen/docgen.gpr.py index 8aab0ba65..a66bb04c3 100644 --- a/gramps/plugins/docgen/docgen.gpr.py +++ b/gramps/plugins/docgen/docgen.gpr.py @@ -206,7 +206,7 @@ plg.status = STABLE plg.fname = 'svgdrawdoc.py' plg.ptype = DOCGEN plg.docclass = 'SvgDrawDoc' -plg.optionclass = None +plg.optionclass = 'SvgDrawDocOptions' plg.paper = True plg.style = True plg.extension = "svg" diff --git a/gramps/plugins/docgen/svgdrawdoc.py b/gramps/plugins/docgen/svgdrawdoc.py index ef17972d4..879709554 100644 --- a/gramps/plugins/docgen/svgdrawdoc.py +++ b/gramps/plugins/docgen/svgdrawdoc.py @@ -4,6 +4,7 @@ # Copyright (C) 2000-2006 Donald N. Allingham # Copyright (C) 2007-2009 Brian G. Matherly # Copyright (C) 2010 Jakim Friant +# Copyright (C) 2013 Paul Franklin # # 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 @@ -46,6 +47,8 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.get_translation().gettext from gramps.gen.plug.docgen import BaseDoc, DrawDoc, SOLID, FONT_SANS_SERIF from gramps.gen.errors import ReportError +from gramps.gen.plug.menu import EnumeratedListOption +from gramps.gen.plug.report import DocOptions #------------------------------------------------------------------------- # @@ -54,7 +57,7 @@ from gramps.gen.errors import ReportError #------------------------------------------------------------------------- class SvgDrawDoc(BaseDoc, DrawDoc): - def __init__(self, styles, type): + def __init__(self, styles, type, options=None): BaseDoc.__init__(self, styles, type) self.f = None self.filename = None @@ -62,6 +65,13 @@ class SvgDrawDoc(BaseDoc, DrawDoc): self.time = "0000-00-00T00:00:00" self.page = 0 + self._bg = 'none' # SVG background, in case options are ignored + if options: + menu = options.menu + self._bg = menu.get_option_by_name('svg_background').get_value() + if self._bg == 'transparent': + self._bg = 'none' + def open(self, filename): if filename[-4:] != ".svg": self.root = filename @@ -87,14 +97,18 @@ class SvgDrawDoc(BaseDoc, DrawDoc): self.t = StringIO() + width = self.paper.get_size().get_width() + height = self.paper.get_size().get_height() + self.f.write( - '\n' + - '\n' + + '\n' + '\n' '\n' + '\n' + % (width, height, width, height, self._bg) ) def rotate_text(self, style, text, x, y, angle, mark=None): @@ -306,3 +320,36 @@ class SvgDrawDoc(BaseDoc, DrawDoc): def units(val): return (val[0]*35.433, val[1]*35.433) + +#------------------------------------------------------------------------ +# +# SvgDrawDocOptions class +# +#------------------------------------------------------------------------ +class SvgDrawDocOptions(DocOptions): + """ + Defines options and provides handling interface. + """ + + def __init__(self, name, dbase): + DocOptions.__init__(self, name) + + def add_menu_options(self, menu): + """ + Add options to the document menu for the docgen. + """ + category_name = 'Document Options' # internal name: don't translate + + background = EnumeratedListOption(_('SVG background color'), + 'transparent') + background.set_items([('transparent', _('transparent background')), + ('white', _('white')), + ('black', _('black')), + ('red', _('red')), + ('green', _('green')), + ('blue', _('blue')), + ('cyan', _('cyan')), + ('magenta', _('magenta')), + ('yellow', _('yellow')) ]) + background.set_help(_('The color, if any, of the SVG background')) + menu.add_option(category_name, 'svg_background', background)