# # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2006 Donald N. Allingham # Copyright (C) 2005-2009 Serge Noiraud # Copyright (C) 2007-2009 Brian G. Matherly # # 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$ """ ODFDoc : used to generate Open Office Document """ #------------------------------------------------------------------------- # # pylint : disable messages ... # #------------------------------------------------------------------------- # disable-msg=C0302 # Too many lines in module # pylint: disable-msg=C0302 # disable-msg # Regular expression which should only match # pylint: disable-msg=C0103 # disable-msg=R0902 # Too many instance attributes # pylint: disable-msg=R0902 # disable-msg=R0904 # Too many public methods # pylint: disable-msg=R0904 # disable-msg=R0912 # Too many branches # pylint: disable-msg=R0912 # disable-msg=R0913 # Too many arguments # pylint: disable-msg=R0913 # disable-msg=R0914 # Too many local variables # pylint: disable-msg=R0914 # disable-msg=R0915 # Too many statements # pylint: disable-msg=R0915 # warnings : # disable-msg=W0613 # Unused argument # pylint: disable-msg=W0613 # errors : # disable-msg=E1101 # has no member # pylint: disable-msg=E1101 #------------------------------------------------------------------------- # # Standard Python Modules # #------------------------------------------------------------------------- import os try: from hashlib import md5 except ImportError: from md5 import md5 import zipfile import time import locale from cStringIO import StringIO from math import pi, cos, sin from xml.sax.saxutils import escape #------------------------------------------------------------------------- # # Gramps modules # #------------------------------------------------------------------------- from gui.utils import open_file_with_default_application from gen.plug import PluginManager, DocGenPlugin from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, FONT_SANS_SERIF, DASHED, PAPER_PORTRAIT, INDEX_TYPE_TOC, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT, INDEX_TYPE_ALP, PARA_ALIGN_RIGHT) from gen.plug.docgen.fontscale import string_width from libodfbackend import OdfBackend import const from ReportBase import ReportUtils import ImgManip import Errors #------------------------------------------------------------------------- # # internationalization # #------------------------------------------------------------------------- from gettext import gettext as _ _apptype = 'application/vnd.oasis.opendocument.text' _esc_map = { '\x1a' : '', '\x0c' : '', '\n' : '', '\t' : '', } #------------------------------------------------------------------------- # # regexp for Styled Notes ... # #------------------------------------------------------------------------- import re NewStyle = re.compile('style-name="([a-zA-Z0-9]*)__([#a-zA-Z0-9 ]*)__">') #------------------------------------------------------------------------- # # ODFDoc # #------------------------------------------------------------------------- class ODFDoc(BaseDoc, TextDoc, DrawDoc): """ The ODF document class """ def __init__(self, styles, ftype): """ Class init """ BaseDoc.__init__(self, styles, ftype) self.media_list = [] self.init_called = False self.cntnt = None self.cntnt1 = None self.cntnt2 = None self.cntntx = None self.sfile = None self.mimetype = None self.meta = None self.mfile = None self.filename = None self.lang = None self._backend = None self.span = 0 self.level = 0 self.time = "0000-00-00T00:00:00" self.new_page = 0 self.new_cell = 0 self.page = 0 self.first_page = 1 self.StyleList = [] # styles to create depending on styled notes. def open(self, filename): """ Open the new document """ t = time.localtime(time.time()) self.time = "%04d-%02d-%02dT%02d:%02d:%02d" % t[:6] if filename[-4:] != ".odt": self.filename = filename + ".odt" else: self.filename = filename self.filename = os.path.normpath(os.path.abspath(self.filename)) self._backend = OdfBackend() self.cntnt = StringIO() self.cntnt1 = StringIO() self.cntnt2 = StringIO() def init(self): """ Create the document header """ assert (not self.init_called) self.init_called = True current_locale = locale.getlocale() self.lang = current_locale[0] if self.lang: self.lang = self.lang.replace('_', '-') else: self.lang = "en-US" self.StyleList = [] # styles to create depending on styled notes. self.cntnt1.write('\n') self.cntnt1.write('\n') self.cntnt1.write('\n') self.cntnt1.write('\n') self.cntnt1.write('\n') self.cntnt1.write('\n') self.cntnt1.write('\n') self.cntnt2.write('\n') self.cntnt2.write('\n') self.cntnt2.write('\n') self.cntnt2.write('\n') self.cntnt2.write('\n') self.cntnt2.write('') self.cntnt2.write('') self.cntnt2.write('\n') self.cntnt2.write('') self.cntnt2.write('') self.cntnt2.write('\n') styles = self.get_style_sheet() for style_name in styles.get_draw_style_names(): style = styles.get_draw_style(style_name) self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') # Graphic style for items with a clear background self.cntnt.write('\n') self.cntnt.write('') self.cntnt.write('\n') for style_name in styles.get_paragraph_style_names(): style = styles.get_paragraph_style(style_name) self.cntnt.write('\n' % style_name) self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write(' 0: self.cntnt.write('fo:keep-with-next="true" ') align = style.get_alignment() if align == PARA_ALIGN_LEFT: self.cntnt.write('fo:text-align="start" ') elif align == PARA_ALIGN_RIGHT: self.cntnt.write('fo:text-align="end" ') elif align == PARA_ALIGN_CENTER: self.cntnt.write('fo:text-align="center" ') self.cntnt.write('style:justify-single-word="false" ') else: self.cntnt.write('fo:text-align="justify" ') self.cntnt.write('style:justify-single-word="false" ') font = style.get_font() if font.get_type_face() == FONT_SANS_SERIF: self.cntnt.write('style:font-name="Arial" ') else: self.cntnt.write('style:font-name="Times New Roman" ') self.cntnt.write('fo:font-size="%.2fpt" ' % font.get_size()) self.cntnt.write('style:font-size-asian="%.2fpt" ' % font.get_size()) color = font.get_color() self.cntnt.write('fo:color="#%02x%02x%02x" ' % color) if font.get_bold(): self.cntnt.write('fo:font-weight="bold" ') if font.get_italic(): self.cntnt.write('fo:font-style="italic" ') if font.get_underline(): self.cntnt.write('style:text-underline="single" ') self.cntnt.write('style:text-underline-color="font-color" ') self.cntnt.write('fo:text-indent="%.2fcm"\n' % style.get_first_indent()) self.cntnt.write('fo:margin-right="%.2fcm"\n' % style.get_right_margin()) self.cntnt.write('fo:margin-left="%.2fcm"\n' % style.get_left_margin()) self.cntnt.write('fo:margin-top="0.00cm"\n') self.cntnt.write('fo:margin-bottom="0.212cm" ') self.cntnt.write('/>\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write(' ' % font.get_size()) self.cntnt.write('\n') for style_name in styles.get_table_style_names(): style = styles.get_table_style(style_name) self.cntnt.write('\n') table_width = float(self.get_usable_width()) table_width_str = "%.2f" % table_width self.cntnt.write('\n') self.cntnt.write('\n') for col in range(0, style.get_columns()): self.cntnt.write('') width = table_width * float(style.get_column_width(col)/100.0) width_str = "%.4f" % width self.cntnt.write('' % width_str) self.cntnt.write('\n') for cell in styles.get_cell_style_names(): cell_style = styles.get_cell_style(cell) self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('') self.cntnt.write('\n') #Begin photo style self.cntnt.write('') self.cntnt.write('') self.cntnt.write('\n') self.cntnt.write('') self.cntnt.write('') self.cntnt.write('\n') self.cntnt.write(' ') self.cntnt.write(' ') self.cntnt.write('\n') self.cntnt.write('') self.cntnt.write('') self.cntnt.write('\n') #end of Photo style edits self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write(' \n') self.cntnt.write(' \n') def uniq(self, List, funct=None): """ We want no duplicate in the list """ # order preserving if funct is None: def funct(x): """ function used to compare elements """ return x seen = {} result = [] for item in List: marker = funct(item[0]) if marker in seen: continue seen[marker] = 1 result.append(item) return result def finish_cntnt_creation(self): """ We have finished the document. So me must integrate the new fonts and styles where they should be. The content.xml file is closed. """ self.cntntx = StringIO() self.StyleList = self.uniq(self.StyleList) self.add_styled_notes_fonts() self.add_styled_notes_styles() self.cntntx.write(self.cntnt1.getvalue()) self.cntntx.write(self.cntnt2.getvalue()) self.cntntx.write(self.cntnt.getvalue()) self.cntnt1.close() self.cntnt2.close() self.cntnt.close() def close(self): """ Close the document and create the odt file """ self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('\n') self.finish_cntnt_creation() self._write_styles_file() self._write_manifest() self._write_meta_file() self._write_mimetype_file() self._write_zip() if self.open_req: open_file_with_default_application(self.filename) def add_styled_notes_fonts(self): """ Add the new fonts for Styled notes in the font-face-decls section. """ # Need to add new font for styled notes here. for style in self.StyleList: if ( style[1] == "FontFace" ): self.cntnt1.write('\n') def add_styled_notes_styles(self): """ Add the new styles for Styled notes in the automatic-styles section. """ # Need to add new style for styled notes here. for style in self.StyleList: if ( style[1] == "FontSize" ): self.cntnt2.write(' ') self.cntnt2.write('' % style[2]) self.cntnt2.write('\n') elif ( style[1] == "FontColor" ): self.cntnt2.write('') self.cntnt2.write(' ' % style[2]) self.cntnt2.write('\n') elif ( style[1] == "FontHighlight" ): self.cntnt2.write(' ') self.cntnt2.write('' % style[2]) self.cntnt2.write('\n') elif ( style[1] == "FontFace" ): self.cntnt2.write(' ') self.cntnt2.write('') self.cntnt2.write('\n') def add_media_object(self, file_name, pos, x_cm, y_cm, alt=''): """ Add multi-media documents : photos """ # try to open the image. If the open fails, it probably wasn't # a valid image (could be a PDF, or a non-image) (x, y) = ImgManip.image_size(file_name) if (x, y) == (0, 0): return ratio = float(x_cm)*float(y)/(float(y_cm)*float(x)) if ratio < 1: act_width = x_cm act_height = y_cm*ratio else: act_height = y_cm act_width = x_cm/ratio not_extension, extension = os.path.splitext(file_name) odf_name = md5(file_name).hexdigest() + extension media_list_item = (file_name, odf_name) if not media_list_item in self.media_list: self.media_list.append(media_list_item) base = escape(os.path.basename(file_name)) tag = base.replace('.', '_') if self.new_cell: self.cntnt.write('') if pos == "left": self.cntnt.write('') self.cntnt.write('\n') self.cntnt.write('\n') if self.new_cell: self.cntnt.write('\n') def start_table(self, name, style_name): """ open a table """ self.cntnt.write('\n' % style_name) styles = self.get_style_sheet() table = styles.get_table_style(style_name) for col in range(0, table.get_columns()): self.cntnt.write('\n') def end_table(self): """ close a table """ self.cntnt.write('\n') def start_row(self): """ open a row """ self.cntnt.write('\n') def end_row(self): """ close a row """ self.cntnt.write('\n') def start_cell(self, style_name, span=1): """ open a cell """ self.span = span self.cntnt.write(' 1: self.cntnt.write(' table:number-columns-spanned="%s">\n' % span) else: self.cntnt.write('>\n') self.new_cell = 1 def end_cell(self): """ close a cell """ self.cntnt.write('\n') #for col in range(1, self.span): # self.cntnt.write('\n') self.new_cell = 0 def start_bold(self): """ open bold """ self.cntnt.write('') def end_bold(self): """ close bold """ self.cntnt.write('') def start_superscript(self): """ open superscript """ self.cntnt.write('') def end_superscript(self): """ close superscript """ self.cntnt.write('') def _add_zip(self, zfile, name, data, t): """ Add a zip file to an archive """ zipinfo = zipfile.ZipInfo(name.encode('utf-8')) zipinfo.date_time = t zipinfo.compress_type = zipfile.ZIP_DEFLATED zipinfo.external_attr = 0644 << 16L zfile.writestr(zipinfo, data) def _write_zip(self): """ Create the odt file. This is a zip file """ try: zfile = zipfile.ZipFile(self.filename, "w", zipfile.ZIP_DEFLATED) except IOError, msg: errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg) raise Errors.ReportError(errmsg) except: raise Errors.ReportError(_("Could not create %s") % self.filename) t = time.localtime(time.time())[:6] self._add_zip(zfile, "META-INF/manifest.xml", self.mfile.getvalue(), t) self._add_zip(zfile, "content.xml", self.cntntx.getvalue(), t) self._add_zip(zfile, "meta.xml", self.meta.getvalue(), t) self._add_zip(zfile, "styles.xml", self.sfile.getvalue(), t) self._add_zip(zfile, "mimetype", self.mimetype.getvalue(), t) self.mfile.close() self.cntnt.close() self.meta.close() self.sfile.close() self.mimetype.close() for image in self.media_list: try: ifile = open(image[0], mode='rb') self._add_zip(zfile, "Pictures/%s" % image[1], ifile.read(), t) ifile.close() except: errmsg = "%s\n%s" % (_("Could not open %s") % image[0], msg) raise Errors.ReportError(errmsg) zfile.close() def _write_styles_file(self): """ create the styles.xml file """ self.sfile = StringIO() self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('') self.sfile.write('') self.sfile.write(' ') self.sfile.write(' ') self.sfile.write('') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write(' \n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write(' ') self.sfile.write(' ') self.sfile.write('\n') self.sfile.write(' ') self.sfile.write(' ') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') styles = self.get_style_sheet() for style_name in styles.get_paragraph_style_names(): style = styles.get_paragraph_style(style_name) self.sfile.write('\n') self.sfile.write(' 0: self.sfile.write('fo:keep-with-next="always" ') align = style.get_alignment() if align == PARA_ALIGN_LEFT: self.sfile.write('fo:text-align="start" ') self.sfile.write('style:justify-single-word="false" ') elif align == PARA_ALIGN_RIGHT: self.sfile.write('fo:text-align="end" ') elif align == PARA_ALIGN_CENTER: self.sfile.write('fo:text-align="center" ') self.sfile.write('style:justify-single-word="false" ') else: self.sfile.write('fo:text-align="justify" ') self.sfile.write('style:justify-single-word="false" ') self.sfile.write('fo:text-indent="%.2fcm" ' % style.get_first_indent()) self.sfile.write('style:auto-text-indent="false"/> ') self.sfile.write('\n') self.sfile.write('\n') # Current no leading number format for headers #self.sfile.write('\n') #self.sfile.write('\n') #self.sfile.write('\n') #self.sfile.write('\n') #self.sfile.write('\n') #self.sfile.write('\n') #self.sfile.write('\n') #self.sfile.write('\n') #self.sfile.write('\n') #self.sfile.write('\n') #self.sfile.write('\n') #self.sfile.write('\n') self.sfile.write(' ') self.sfile.write(' ') self.sfile.write(' ') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('') self.sfile.write('') self.sfile.write('\n') self.sfile.write('') self.sfile.write('') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') # header self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') # footer self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') # self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') # header #self.sfile.write('') #self.sfile.write('') # How to get the document title here ? #self.sfile.write(' TITRE : %s' % self.title) #self.sfile.write('') #self.sfile.write('') # footer #self.sfile.write('') #self.sfile.write('') #self.sfile.write('1') #self.sfile.write('/') #self.sfile.write('1') #self.sfile.write('') #self.sfile.write('') #self.sfile.write('') # self.sfile.write('') self.sfile.write('\n') self.sfile.write('\n') def page_break(self): """ prepare a new page """ self.new_page = 1 def start_page(self): """ create a new page """ self.cntnt.write('\n') def end_page(self): """ close the page """ self.cntnt.write('\n') def start_paragraph(self, style_name, leader=None): """ open a new paragraph """ style_sheet = self.get_style_sheet() style = style_sheet.get_paragraph_style(style_name) self.level = style.get_header_level() if self.new_page == 1: self.new_page = 0 name = "NL%s" % style_name else: name = style_name if self.level == 0: self.cntnt.write('' % name) else: self.cntnt.write('') if leader is not None: self.cntnt.write(leader) self.cntnt.write('') self.new_cell = 0 def end_paragraph(self): """ close a paragraph """ if self.level == 0: self.cntnt.write('\n') else: self.cntnt.write('\n') self.new_cell = 1 def write_note(self, text, format, style_name): """ write a note """ if format == 1: text = escape(text, _esc_map) # Replace multiple spaces: have to go from the largest number down for n in range(text.count(' '), 1, -1): text = text.replace(' '*n, ' ' % (n-1) ) self.start_paragraph(style_name) self.cntnt.write('') self.cntnt.write(text) self.cntnt.write('') self.end_paragraph() elif format == 0: for line in text.split('\n\n'): self.start_paragraph(style_name) line = line.replace('\n', ' ') line = ' '.join(line.split()) self.write_text(line) self.end_paragraph() def write_styled_note(self, styledtext, format, style_name): """ Convenience function to write a styledtext to the latex doc. styledtext : assumed a StyledText object to write format : = 0 : Flowed, = 1 : Preformatted style_name : name of the style to use for default presentation """ text = str(styledtext) s_tags = styledtext.get_tags() markuptext = self._backend.add_markup_from_styled(text, s_tags) # we need to know if we have new styles to add. # if markuptext contains : FontColor, FontFace, FontSize ... # we must prepare the new styles for the styles.xml file. # We are looking for the following format : # style-name="([a-zA-Z0-9]*)__([a-zA-Z0-9 ])"> # The first element is the StyleType and the second one is the value start = 0 while 1: m = NewStyle.search(markuptext, start) if not m: break self.StyleList.append([m.group(1)+m.group(2), m.group(1), m.group(2)]) start = m.end() self.cntnt.write('') linenb = 1 for line in markuptext.split('\n'): if ( linenb > 1 ): self.cntnt.write('') self.cntnt.write(line) linenb += 1 self.cntnt.write('') def write_text(self, text, mark=None): """ Uses the xml.sax.saxutils.escape function to convert XML entities. The _esc_map dictionary allows us to add our own mappings. """ if mark: key = escape(mark.key, _esc_map) key = key.replace('"', '"') if mark.type == INDEX_TYPE_ALP: self.cntnt.write('' % key) elif mark.type == INDEX_TYPE_TOC: self.cntnt.write('' % mark.level) self.cntnt.write(escape(text, _esc_map)) def _write_manifest(self): """ create the manifest.xml file """ self.mfile = StringIO() self.mfile.write('\n') self.mfile.write('') self.mfile.write('') for image in self.media_list: self.mfile.write('') self.mfile.write('') self.mfile.write('') self.mfile.write('') self.mfile.write('') self.mfile.write('\n') def _write_mimetype_file(self): """ create the mimetype.xml file """ self.mimetype = StringIO() self.mimetype.write('application/vnd.oasis.opendocument.text') def _write_meta_file(self): """ create the meta.xml file """ self.meta = StringIO() self.meta.write('\n') self.meta.write('\n') self.meta.write('\n') self.meta.write('') self.meta.write(const.PROGRAM_NAME + ' ' + const.VERSION) self.meta.write('\n') self.meta.write('') # It should be reasonable to have a true document title. but how ? # self.title ? #self.meta.write(_("Summary of %s") % self.name) self.meta.write('\n') self.meta.write('') #self.meta.write(_("Summary of %s") % name) self.meta.write('\n') self.meta.write('') self.meta.write('\n') self.meta.write('') self.meta.write(self.get_creator()) self.meta.write('\n') self.meta.write('') self.meta.write(self.time) self.meta.write('\n') self.meta.write('') self.meta.write(self.get_creator()) self.meta.write('\n') self.meta.write('') self.meta.write(self.time) self.meta.write('\n') self.meta.write('') self.meta.write('\n') self.meta.write('0-00-00T00:00:00\n') self.meta.write('%s\n' % self.lang) self.meta.write('1\n') self.meta.write('PT0S\n') self.meta.write('') self.meta.write('http://gramps-project.org') self.meta.write('\n') self.meta.write('\n') self.meta.write('\n') self.meta.write('\n') self.meta.write('\n') self.meta.write('\n') def rotate_text(self, style, text, x, y, angle): """ Used to rotate a text with an angle. """ style_sheet = self.get_style_sheet() stype = style_sheet.get_draw_style(style) pname = stype.get_paragraph_style() p = style_sheet.get_paragraph_style(pname) font = p.get_font() size = font.get_size() height = size*(len(text)) width = 0 for line in text: width = max(width, string_width(font, line)) wcm = ReportUtils.pt2cm(width) hcm = ReportUtils.pt2cm(height) rangle = (pi/180.0) * angle self.cntnt.write('\n' % (xloc, yloc)) self.cntnt.write('\n') self.cntnt.write('' % pname) self.cntnt.write('' % pname) self.cntnt.write(escape('\n'.join(text), _esc_map)) self.cntnt.write('\n\n') self.cntnt.write('\n') def draw_path(self, style, path): """ Draw a path """ minx = 9e12 miny = 9e12 maxx = 0 maxy = 0 for point in path: minx = min(point[0], minx) miny = min(point[1], miny) maxx = max(point[0], maxx) maxy = max(point[1], maxy) self.cntnt.write('\n') def draw_line(self, style, x1, y1, x2, y2): """ Draw a line """ self.cntnt.write('' % y2) self.cntnt.write('\n') self.cntnt.write('\n') def draw_text(self, style, text, x, y): """ Draw a text """ style_sheet = self.get_style_sheet() box_style = style_sheet.get_draw_style(style) para_name = box_style.get_paragraph_style() pstyle = style_sheet.get_paragraph_style(para_name) font = pstyle.get_font() sw = ReportUtils.pt2cm(string_width(font, text))*1.3 self.cntnt.write('' % float(y)) self.cntnt.write(' ' ) self.cntnt.write('' % para_name) self.cntnt.write('' % font.get_size() ) self.cntnt.write(escape(text, _esc_map)) self.cntnt.write('') self.cntnt.write('\n') self.cntnt.write('\n') def draw_box(self, style, text, x, y, w, h): """ Draw a box """ style_sheet = self.get_style_sheet() box_style = style_sheet.get_draw_style(style) para_name = box_style.get_paragraph_style() shadow_width = box_style.get_shadow_space() if box_style.get_shadow(): self.cntnt.write('\n' % (float(y)+shadow_width)) self.cntnt.write('\n') self.cntnt.write('\n' % float(y)) if text != "": self.cntnt.write('' % para_name) self.cntnt.write('' % para_name) self.cntnt.write(escape(text, _esc_map)) self.cntnt.write('') self.cntnt.write('\n') self.cntnt.write('\n') def center_text(self, style, text, x, y): """ Center a text in a cell, a row, a line, ... """ style_sheet = self.get_style_sheet() box_style = style_sheet.get_draw_style(style) para_name = box_style.get_paragraph_style() pstyle = style_sheet.get_paragraph_style(para_name) font = pstyle.get_font() size = (string_width(font, text)/72.0) * 2.54 self.cntnt.write('\n' % float(y)) if text != "": self.cntnt.write('') self.cntnt.write('' % para_name) self.cntnt.write('' % para_name) self.cntnt.write(escape(text, _esc_map)) self.cntnt.write('\n') self.cntnt.write('\n') self.cntnt.write('') self.cntnt.write('\n') #------------------------------------------------------------------------ # # register_plugin # #------------------------------------------------------------------------ def register_plugin(): """ Register the document generator with the GRAMPS plugin system. """ pmgr = PluginManager.get_instance() plugin = DocGenPlugin(name = _('Open Document Text'), description = _("Generates documents in Open " "Document Text format (.odt)."), basedoc = ODFDoc, paper = True, style = True, extension = "odt" ) pmgr.register_plugin(plugin) register_plugin()