From 2f41ff44c245a91953540ca82a8abaae4712bbfe Mon Sep 17 00:00:00 2001 From: Serge Noiraud Date: Mon, 17 Aug 2009 22:28:40 +0000 Subject: [PATCH] Added backend for ODFDoc and styled notes. svn: r13055 --- src/plugins/lib/libodfbackend.py | 136 +++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/plugins/lib/libodfbackend.py diff --git a/src/plugins/lib/libodfbackend.py b/src/plugins/lib/libodfbackend.py new file mode 100644 index 000000000..02a2eae51 --- /dev/null +++ b/src/plugins/lib/libodfbackend.py @@ -0,0 +1,136 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Benny Malengier +# Copyright (C) 2009 Serge Noiraud +# +# 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 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id: docbackend.py 12437 2009-04-13 02:11:49Z pez4brian $ + +"""File and File format management for the openoffice reports +""" + +#------------------------------------------------------------------------ +# +# Python modules +# +#------------------------------------------------------------------------ +from xml.sax.saxutils import escape +import os.path + +#------------------------------------------------------------------------- +# +# GTK modules +# +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------ +# +# Gramps modules +# +#------------------------------------------------------------------------ +from gen.plug.docbackend import DocBackend + +try: + from gen.plug import PluginManager, Plugin + from gettext import gettext as _ +except ImportError: + print 'Plugin manager not imported.' +#------------------------------------------------------------------------ +# +# Set up logging +# +#------------------------------------------------------------------------ +import logging +LOG = logging.getLogger(".odfbackend.py") + +#------------------------------------------------------------------------ +# +# Document Backend class for cairo docs +# +#------------------------------------------------------------------------ + +def _escape(string): + """ a write to the file + """ + return string + +class OdfBackend(DocBackend): + """ + Implementation for open document format docs + """ + + STYLETAG_TO_PROPERTY = { + } + + # overwrite base class attributes, they become static var of CairoDoc + SUPPORTED_MARKUP = [ + DocBackend.BOLD, + DocBackend.ITALIC, + DocBackend.UNDERLINE, + DocBackend.FONTFACE, + DocBackend.FONTSIZE, + DocBackend.FONTCOLOR, + DocBackend.HIGHLIGHT, + DocBackend.SUPERSCRIPT ] + + STYLETAG_MARKUP = { + DocBackend.BOLD : + ("", + ""), + DocBackend.ITALIC : + ("", + ""), + DocBackend.UNDERLINE : + ("", + ""), + DocBackend.SUPERSCRIPT : + ("", + ""), + } + + ESCAPE_FUNC = lambda x: _escape + + def __init__(self, filename=None): + """ + @param filename: path name of the file the backend works on + """ + DocBackend.__init__(self, filename) + + def _create_xmltag(self, tagtype, value): + """ + overwrites the method in DocBackend + creates the pango xml tags needed for non bool style types + """ + if tagtype not in self.SUPPORTED_MARKUP: + return None + if ( tagtype == DocBackend.FONTCOLOR ): + return ('' % + self.ESCAPE_FUNC()(value), + '') + elif ( tagtype == DocBackend.FONTFACE ): + return ('' % + self.ESCAPE_FUNC()(value), + '') + elif ( tagtype == DocBackend.FONTSIZE ): + return ('' % + self.ESCAPE_FUNC()(value), + '') + else: #elif ( tagtype == DocBackend.HIGHLIGHT ): + return ('' % + self.ESCAPE_FUNC()(value), + '')