From 59bb4c9ea9fd5d619631a60cd73bdbfafe405c67 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 10 Sep 2007 17:59:54 +0000 Subject: [PATCH] svn: r8957 --- src/docgen/AbiWord2Doc.py | 351 ---------- src/docgen/KwordDoc.py | 541 --------------- src/docgen/LPRDoc.py | 1245 ----------------------------------- src/docgen/OpenOfficeDoc.py | 1014 ---------------------------- src/docgen/PdfDoc.py | 682 ------------------- 5 files changed, 3833 deletions(-) delete mode 100644 src/docgen/AbiWord2Doc.py delete mode 100644 src/docgen/KwordDoc.py delete mode 100644 src/docgen/LPRDoc.py delete mode 100644 src/docgen/OpenOfficeDoc.py delete mode 100644 src/docgen/PdfDoc.py diff --git a/src/docgen/AbiWord2Doc.py b/src/docgen/AbiWord2Doc.py deleted file mode 100644 index 5bd47c12b..000000000 --- a/src/docgen/AbiWord2Doc.py +++ /dev/null @@ -1,351 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2006 Donald N. Allingham -# Copyright (C) 2007 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$ - -""" -Provides a BaseDoc based interface to the AbiWord document format. -""" - -#------------------------------------------------------------------------- -# -# Python Modules -# -#------------------------------------------------------------------------- -import base64 -from gettext import gettext as _ - -#------------------------------------------------------------------------- -# -# Gramps Modules -# -#------------------------------------------------------------------------- -import BaseDoc -import Errors -from PluginUtils import register_text_doc -import ImgManip -import Mime -import Utils - -mime_type = "" -#------------------------------------------------------------------------- -# -# Class Definitions -# -#------------------------------------------------------------------------- -class AbiWordDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc): - """AbiWord document generator. Inherits from the BaseDoc generic - document interface class.""" - - def __init__(self,styles,type,template): - """Initializes the AbiWordDoc class, calling the __init__ routine - of the parent BaseDoc class""" - BaseDoc.BaseDoc.__init__(self,styles,type,template) - self.media_list = [] - self.f = None - self.level = 0 - self.new_page = 0 - self.in_table = 0 - self.in_paragraph = 0 - - def open(self,filename): - """Opens the document, writing the necessary header information. - AbiWord uses an XML format, so the document format is pretty easy - to understand""" - if filename[-4:] != ".abw": - self.filename = "%s.abw" % filename - else: - self.filename = filename - - try: - self.f = open(self.filename,"w") - 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) - - # doctype - self.f.write('\n') - self.f.write('\n') - self.f.write('\n' % Utils.xml_lang()) - - # metadata section - self.f.write('\n') - self.f.write('application/x-abiword\n') - self.f.write('AbiWord\n') - self.f.write('Mon May 19 14:16:24 2003\n') - self.f.write('\n') - - self.write_styles() - - # page size section - self.f.write('\n') - self.f.write('
\n') - - def write_styles(self): - self.f.write('\n') - styles = self.get_style_sheet() - for style_name in styles.get_paragraph_style_names(): - style = styles.get_paragraph_style(style_name) - self.current_style = style - self.f.write('\n') - self.f.write('\n') - - def close(self): - """Write the trailing information and closes the file""" - self.f.write('
\n') - if self.media_list: - self.f.write('\n') - for tag_number in range(len(self.media_list)): - name = self.media_list[tag_number] - img = ImgManip.ImgManip(name) - buf = img.png_data() - - self.f.write( - '\n' - % tag_number) - self.f.write(base64.encodestring(buf)) - self.f.write('\n') - self.f.write('\n') - - self.f.write('
\n') - self.f.close() - - if self.print_req: - try: - app = Mime.get_application(mime_type)[0] - Utils.launch(app,self.filename) - except: - pass - - def add_media_object(self,name,pos,x_cm,y_cm): - - try: - image = ImgManip.ImgManip(name) - (x,y) = image.size() - except: - return - - if y: - aspect_ratio = float(x)/float(y) - else: - aspect_ratio = 1 - - if aspect_ratio > x_cm/y_cm: - act_width = x_cm - act_height = y_cm/aspect_ratio - else: - act_height = y_cm - act_width = x_cm*aspect_ratio - - if name in self.media_list: - tag_number = self.media_list.index(name) - else: - tag_number = len(self.media_list) - self.media_list.append(name) - - if self.in_paragraph: # We cannot insert photo - start_p = end_p = '' # outside text paragraph. - else: # So if not in paragraph, insert one. - start_p = '

' - end_p = '

' - - self.f.write('%s%s ' - % (start_p,tag_number,act_height,act_width,end_p)) - - def start_superscript(self): - self.f.write('') - - def end_superscript(self): - self.f.write('') - - def start_paragraph(self,style_name,leader=None): - self.in_paragraph = 1 - styles = self.get_style_sheet() - style = styles.get_paragraph_style(style_name) - self.current_style = style - self.f.write('

' % style_name) - if self.new_page == 1: - self.new_page = 0 - self.f.write('') - if leader != None: - self.f.write(leader) - self.f.write('\t') - - def page_break(self): - self.new_page = 1 - - def end_paragraph(self): - self.in_paragraph = 0 - self.f.write('

\n') - - def write_note(self,text,format,style_name): - if format == 1: - self.start_paragraph(style_name) - self.f.write('') - self.write_text(text) - self.f.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_text(self,text,mark=None): - text = text.replace('&','&'); # Must be first - text = text.replace('<','<'); - text = text.replace('>','>'); - text = text.replace('<super>','') - text = text.replace('</super>','') - self.f.write(text) - - def start_bold(self): - self.f.write('') - - def end_bold(self): - self.f.write('') - - def start_table(self,name,style_name): - self.in_table = 1 - styles = self.get_style_sheet() - self.tblstyle = styles.get_table_style(style_name) - self.f.write('\n') - self.current_row = -1 - - def end_table(self): - self.in_table = 0 - self.f.write('
\n') - - def start_row(self): - self.ledge = 0.0 - self.col = 0 - self.current_row += 1 - - def end_row(self): - pass - - def start_cell(self,style_name,span=1): - styles = self.get_style_sheet() - self.cstyle = styles.get_cell_style(style_name) - self.f.write('\n') - self.col += span - - def end_cell(self): - self.f.write('\n') - -#-------------------------------------------------------------------------- -# -# Register plugins -# -#-------------------------------------------------------------------------- - -try: - if Mime.mime_type_is_defined("application/x-abiword"): - mime_type = "application/x-abiword" - elif Mime.mime_type_is_defined("application/abiword"): - mime_type = "application/abiword" - - prog = Mime.get_application(mime_type) - mtype = Mime.get_description(mime_type) - - if Utils.search_for(prog[0]): - print_label=_("Open in %s") % prog[1] - else: - print_label=None - register_text_doc(mtype,AbiWordDoc,1,1,1,".abw", print_label) -except: - register_text_doc(_('AbiWord document'),AbiWordDoc,1,1,1,".abw", None) diff --git a/src/docgen/KwordDoc.py b/src/docgen/KwordDoc.py deleted file mode 100644 index cae1e8da6..000000000 --- a/src/docgen/KwordDoc.py +++ /dev/null @@ -1,541 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2006 Donald N. Allingham -# Copyright (C) 2007 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$ - -#------------------------------------------------------------------------ -# -# Python modules -# -#------------------------------------------------------------------------ -import time -import cStringIO -import os -import tarfile -from gettext import gettext as _ - -#------------------------------------------------------------------------ -# -# Gramps modules -# -#------------------------------------------------------------------------ -import BaseDoc -import Errors -from PluginUtils import register_text_doc -import ImgManip -import Mime - -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ -def points(val): - inch = float(val)/2.54 - return (int(inch*72)) - -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ -class KwordDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc): - - def open(self,filename): - self.media_list = [] - - if filename[-4:] != ".kwd": - self.filename = filename + ".kwd" - else: - self.filename = filename - - self.f = cStringIO.StringIO() - self.m = cStringIO.StringIO() - - self.m.write('') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - self.m.write('\n') - - self.f.write('') - self.f.write('') - self.f.write('\n') - self.mtime = time.time() - - paper_name = self.paper.get_size().get_name() - if paper_name == "A3": - self.f.write('\n') - self.f.write('' % points(self.paper.get_left_margin())) - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - - self.cell_row= 0 - self.cell_col= 0 - self.frameset_flg= 1 - self.table_no= 0 - self.cell_style= "" - self.cell_span= 1 - - def close(self): - if self.frameset_flg == 1: - self.f.write('\n') - self.frameset_flg= 0 - - for p in self.media_list: - self.f.write('\n' % p[1]) - self.f.write('\n') - self.f.write('\n') - self.f.write('\n' % a[0]) - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - style_sheet = self.get_style_sheet() - for name in style_sheet.get_paragraph_style_names(): - self.f.write('\n') - - self.f.write('\n') - self.f.write('\n') - for filedata in self.media_list: - self.f.write('\n' % a[0]) - self.f.write('\n') - self.f.write('\n') - - try: - archive = tarfile.open(self.filename,'w:gz') - except IOError, msg: - text = _("Could not open %s") % self.filename - Errors.ReportError(text + "\n" + str(msg)) - return - except: - Errors.ReportError(_("Could not open %s") % self.filename) - return - - tarinfo = tarfile.TarInfo('documentinfo.xml') - tarinfo.size = len(self.m.getvalue()) - tarinfo.mtime = self.mtime - if os.sys.platform != "win32": - tarinfo.uid = os.getuid() - tarinfo.gid = os.getgid() - self.m.seek(0) - archive.addfile(tarinfo,self.m) - - tarinfo = tarfile.TarInfo('maindoc.xml') - tarinfo.size = len(self.f.getvalue()) - tarinfo.mtime = self.mtime - if os.sys.platform != "win32": - tarinfo.uid = os.getuid() - tarinfo.gid = os.getgid() - self.f.seek(0) - archive.addfile(tarinfo,self.f) - - for filedata in self.media_list: - archive.add(filedata[0]) - - archive.close() - self.f.close() - self.m.close() - - if self.print_req: - apptype = 'application/x-kword' - app = Mime.get_application(apptype) - os.environ["FILE"] = self.filename - os.system ('%s "$FILE" &' % app[0]) - - def start_paragraph(self,style_name,leader=None): - self.format_list = [] - self.bold_start = 0 - self.text = "" - self.style_name = style_name - style_sheet = self.get_style_sheet() - self.p = style_sheet.get_paragraph_style(self.style_name) - self.font = self.p.get_font() - if self.font.get_type_face() == BaseDoc.FONT_SERIF: - self.font_face = "Bitstream Vera Serif" - else: - self.font_face = "Bitstream Vera Sans" - - if leader != None: - self.text = leader + '\t' - txt = '\n' % (len(leader)+1) - txt = txt + '\n\n' % self.font_face - self.format_list.append(txt) - - self.bold_stop = len(self.text) - - def end_paragraph(self): - if self.frameset_flg == 0: - self.f.write('\n') - self.frameset_flg= 1 - - if self.bold_start != 0 and self.bold_stop != len(self.text): - txt = '\n\n\n' % self.font_face - self.format_list.append(txt) - - self.f.write('\n') - self.f.write('') - self.f.write(unicode(self.text)) - self.f.write('\n') - self.f.write('\n') - for format in self.format_list: - self.f.write(format) - self.f.write('\n') - self.f.write('\n') - self.f.write('\n' % self.style_name) - - tpad = points(self.p.get_top_margin()) - bpad = points(self.p.get_bottom_margin()) - self.f.write('\n' % (tpad,bpad)) - - if self.p.get_alignment() == BaseDoc.PARA_ALIGN_CENTER: - self.f.write('\n') - elif self.p.get_alignment() == BaseDoc.PARA_ALIGN_JUSTIFY: - self.f.write('\n') - elif self.p.get_alignment() == BaseDoc.PARA_ALIGN_RIGHT: - self.f.write('\n') - else: - self.f.write('\n') - - first = self.p.get_first_indent() - left = self.p.get_left_margin() - right = self.p.get_right_margin() - self.f.write('\n' % (points(left),points(right))) - - self.f.write('\n') - self.f.write('\n' % self.font_face) - self.f.write('\n' % self.font.get_size()) - self.f.write('\n' % self.font.get_color()) - if self.font.get_bold(): - self.f.write('\n') - if self.font.get_italic(): - self.f.write('\n') - if self.font.get_underline(): - self.f.write('\n') - if self.p.get_top_border(): - self.f.write('\n') - if self.p.get_bottom_border(): - self.f.write('\n') - if self.p.get_right_border(): - self.f.write('\n') - if self.p.get_left_border(): - self.f.write('\n') - self.f.write('\n') - if left != 0: - self.f.write('\n' % points(left)) - self.f.write('\n') - self.f.write('\n') - - def start_bold(self): - self.bold_start = len(self.text) - if self.bold_stop != self.bold_start: - length = self.bold_stop - self.bold_start - txt = '\n' % (self.bold_stop,length) - txt = txt + '\n\n' % self.font_face - self.format_list.append(txt) - - def end_bold(self): - self.bold_stop = len(self.text) - length = self.bold_stop - self.bold_start - txt = '\n' % (self.bold_start,length) - txt = txt + '\n\n\n' % self.font_face - self.format_list.append(txt) - - def start_superscript(self): - self.sup_start = len(self.text) - - def end_superscript(self): - length = len(self.text) - self.sup_start - txt = '\n' % (self.sup_start, length) - txt = txt + '\n' - self.format_list.append(txt) - - def start_table(self,name,style_name): - styles = self.get_style_sheet() - self.tbl = styles.get_table_style(style_name) - self.cell_left= (self.paper.get_left_margin() * 72)/ 2.54 - self.tbl_width= ((self.paper.get_size().get_width() - self.paper.get_left_margin() - self.paper.get_right_margin()) * 72 ) / 2.54 - if self.frameset_flg == 1: - self.f.write(' \n') - self.cell_row= 0 - self.cell_col= 0 - self.frameset_flg= 0 - - def end_table(self): - self.table_no= self.table_no + 1 - - def start_row(self): - pass - - def end_row(self): - self.cell_row= self.cell_row + 1 - self.cell_col= 0 - self.cell_left= (self.paper.get_left_margin() * 72)/ 2.54 - - def start_cell(self,style_name,span=1): - self.cell_span= span - self.cell_style= style_name - self.cell_right = self.cell_left - for i in range(0,span): - col_width = self.tbl.get_column_width(self.cell_col+i) - spc = (self.tbl_width * col_width) / 100 - self.cell_right = self.cell_right + spc - self.f.write('\n' % (self.table_no, self.cell_row, self.cell_col)) - self.f.write('\n' % (self.cell_row*23+self.table_no*125+95)) - self.frameset_flg= 1 - self.cell_col = self.cell_col + span - 1 - - def end_cell(self): - self.f.write('\n') - self.cell_col= self.cell_col + 1 - self.frameset_flg= 0 - self.cell_left= self.cell_right - - def add_media_object(self,name,pos,x_cm,y_cm): - - try: - im = ImgManip.ImgManip(name) - except: - return - - (x,y)= im.size() - 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 - - index = len(self.media_list)+1 - tag = 'pictures/picture%d.jpeg' % index - self.media_list.append((name,tag,act_width,act_height)) - txt = '\n' % len(self.text) - txt = txt + '\n' % tag - txt = txt + '\n' - - self.bold_stop = len(self.text) - self.format_list.append(txt) - - self.text = self.text + '#' - - def write_note(self,text,format,style_name): - if format == 1: - self.start_paragraph(style_name) - self.write_text(text) - 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_text(self,text,mark=None): - text = text.replace('&','&'); # Must be first - text = text.replace('<','<'); - text = text.replace('>','>'); - - pos = text.find('<super>') - if pos >= 0: - self.start_pos = len(self.text)+pos - text = text.replace('<super>','') - pos = text.find('</super>') - if pos >= 0: - end = len(self.text)+pos - self.start_pos - text = text.replace('<super>','') - - txt = '\n' % (self.start_pos, end) - txt = txt + '\n' - text = text.replace('</super>','') - self.format_list.append(txt) - - self.text = self.text + text - -#------------------------------------------------------------------------ -# -# Register the document generator with the GRAMPS plugin system -# -#------------------------------------------------------------------------ - -try: - import Utils - - prog = Mime.get_application("application/x-kword") - mtype = Mime.get_description("application/x-kword") - - if prog and Utils.search_for(prog[0]): - print_label=_("Open in %s") % prog[1] - else: - print_label=None - - if mtype == _("unknown"): - mtype = _('KWord') - - register_text_doc(mtype, KwordDoc, 1, 1, 1, ".kwd", print_label) -except: - register_text_doc(_('KWord'), KwordDoc, 1, 1, 1, ".kwd", print_label) diff --git a/src/docgen/LPRDoc.py b/src/docgen/LPRDoc.py deleted file mode 100644 index a3e4f9bd5..000000000 --- a/src/docgen/LPRDoc.py +++ /dev/null @@ -1,1245 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2006 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly -# -# Modifications and feature additions: -# 2002 Donald A. Peterson -# -# 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 -# - -# Written by Billy C. Earney, 2003-2004 -# Modified by Alex Roitman, 2004-2005 - -# $Id$ - -"""LPR document generator""" - -#------------------------------------------------------------------------ -# -# python modules -# -#------------------------------------------------------------------------ -from string import punctuation -from gettext import gettext as _ - -#------------------------------------------------------------------------ -# -# GNOME/GTK Modules -# -#------------------------------------------------------------------------ -import gtk.gdk -import Errors - -try: - import gnomeprint, gnomeprint.ui -except ImportError: - raise Errors.UnavailableError( - _("Cannot be loaded because python bindings " - "for GNOME print are not installed")) - -### FIXME ### -if gnomeprint.Context.__dict__.has_key('grestore'): - support_photos = 1 -else: - support_photos = 0 - print "LPRDoc: Photos and rotated text (used in FanChart)" - print " are not supported for direct printing." - print " Get gnome-python from CVS" - print " or wait for the next gnome-python release." -### end FIXME ### - -#------------------------------------------------------------------------ -# -# gramps modules -# -#------------------------------------------------------------------------ -import BaseDoc -from PluginUtils import register_text_doc, register_draw_doc, register_book_doc -from ReportBase import ReportUtils -rgb_color = ReportUtils.rgb_color - -#------------------------------------------------------------------------ -# -# Constants -# -#------------------------------------------------------------------------ - -# Spacing in points (distance between the bottoms of two adjacent lines) -_LINE_SPACING = 20 - -# Elevation of superscripts: a fraction of it's size -_SUPER_ELEVATION_FRACTION = 0.3 - -# Number of points to subtract to get the superscrip size -_SUPER_SIZE_REDUCTION = 2 - -# Factor which multiplies the font size to get line spacing for the font -_EXTRA_SPACING_FACTOR = 1.2 - -# Grey color to use for box shadows -_SHADOW_COLOR = (192,192,192) - -# Font constants -- specific for gnome-print -_TTF_FREEFONT = ( -('FreeSerif Medium','FreeSerif Bold','FreeSerif Italic','FreeSerif BoldItalic' ), -('FreeSans Medium','FreeSans Bold','FreeSans Oblique','FreeSans BoldOblique'), -('FreeMono Medium','FreeMono Bold','FreeMono Oblique','FreeMono BoldOblique') - ) -_MS_TTFONT = ( -('Times New Roman Regular','Times New Roman Bold','Times New Roman Italic','Times New Roman Bold Italic' ), -('Arial Regular','Arial Bold','Arial Italic','Arial Bold Italic'), -('Courier New Regular','Courier New Bold','Courier New Italic','Courier New Bold Italic') - ) -_GNOME_FONT = ( -('Serif Regular','Serif Bold','Serif Italic','Serif Bold Italic' ), -('Sans Regular','Sans Bold','Sans Italic','Sans Bold Italic'), -('Monospace Regular','Monospace New Bold','Monospace New Italic','Monospace New Bold Italic') - ) - -# Search for ttf-freefont first -ttf_not_found = 0 -for family in _TTF_FREEFONT: - for font in family: - if font not in gnomeprint.font_list(): - ttf_not_found = 1 - break - -if ttf_not_found: - print "LPRDoc: Free true type fonts not found." - # Search for MS ttfs - ms_not_found = 0 - for family in _MS_TTFONT: - for font in family: - if font not in gnomeprint.font_list(): - ms_not_found = 1 - break - if ms_not_found: - print " Microsoft true type fonts not found." - print " Using Gnome standard fonts." - print " Non-ascii characters will appear garbled in the output." - print " INSTALL Free true type fonts" - print " from http://www.nongnu.org/freefont/" - _FONT_SET = _GNOME_FONT - else: - print " Found Microsoft true type fonts. Will use them for now." - print " These fonts are not free. " - print " You are advised to switch to Free true type fonts" - print " INSTALL Free true type fonts" - print " from http://www.nongnu.org/freefont/" - _FONT_SET = _MS_TTFONT -else: - _FONT_SET = _TTF_FREEFONT - -# Formatting directive constants -_LINE_BREAK = "Break" -_BOLD = "Bold" -_SUPER = "Super" -_MONO = "Mono" -_POSTLEADER = "Postleader" - -#------------------------------------------------------------------------ -# -# Units conversion -# -#------------------------------------------------------------------------ -def cm2u(cm): - """ - Convert cm to gnome-print units. - """ - return cm * 72.0 / 2.54 - -#------------------------------------------------------------------------ -# -# font lookup function -# -#------------------------------------------------------------------------ -def find_font_from_fontstyle(fontstyle): - """ - This function returns the gnomeprint.Font() object instance - corresponding to the parameters of BaseDoc.FontStyle() object. - - fontstyle - a BaseDoc.FontStyle() instance - """ - - if fontstyle.get_type_face() == BaseDoc.FONT_SERIF: - family = _FONT_SET[0] - elif fontstyle.get_type_face() == BaseDoc.FONT_SANS_SERIF: - family = _FONT_SET[1] - elif fontstyle.get_type_face() == BaseDoc.FONT_MONOSPACE: - family = _FONT_SET[2] - - if fontstyle.get_bold(): - if fontstyle.get_italic(): - font = family[3] - else: - font = family[1] - elif fontstyle.get_italic(): - font = family[2] - else: - font = family[0] - - size = fontstyle.get_size() - return gnomeprint.font_find_closest(font,size) - -#------------------------------------------------------------------------ -# -# basic font-specific text formatting functions -# -#------------------------------------------------------------------------ -def get_text_width(text,fontstyle): - """ - This function returns the width of text using given fontstyle - when not formatted. - - text - a text whose width to find - fontstyle - a BaseDoc.FontStyle() instance - """ - font = find_font_from_fontstyle(fontstyle) - return font.get_width_utf8(text) - -#------------------------------------------------------------------------ -# -# add to paragraph taking care of the newline characters -# -#------------------------------------------------------------------------ -def append_to_paragraph(paragraph,directive,text): - """ - Add a piece to the paragraph while - taking care of the newline characters. - - paragraph - a GnomePrintParagraph() instance - directive - what to do with this piece - text - the text of the corresponding piece - """ - if not directive and not text: - return - text_list = text.split('\n') - for the_text in text_list[:-1]: - paragraph.add_piece(directive,the_text) - paragraph.add_piece(_LINE_BREAK,"") - paragraph.add_piece(directive,text_list[-1:][0]) - -#------------------------------------------------------------------------ -# -# Paragraph class -# -#------------------------------------------------------------------------ -class GnomePrintParagraph: - """ - A paragraph abstraction which provides the means for in-paragraph - formatting. - """ - - def __init__(self,paragraph_style): - """ - Creates a GnomePrintParapgrah instance. - - paragraph_style - an instance of BaseDoc paragraph style object - """ - self.style = paragraph_style - self.fontstyle = self.style.get_font() - self.piece_list = [] - self.lines = [] - self.height = None - - def add_piece(self,directive,text): - """ - Add a piece to the paragraph. - - directive - what to do with this piece - text - the text of the corresponding piece - """ - self.piece_list.append((directive,text)) - - def get_piece_list(self): - """ - Return a list of pieces for the paragraph. - """ - return self.piece_list - - def get_fontstyle(self): - """ - Return fontstyle for the paragraph. - """ - return self.fontstyle - - def get_alignment(self): - """ - Return requested alignment of the paragraph. - """ - return self.style.get_alignment() - - def get_min_width(self): - """ - Determine the minimal width of the paragraph (longest word). - """ - max_word_size = 0 - - for (directive,text) in self.piece_list: - fontstyle = BaseDoc.FontStyle(self.fontstyle) - if directive == _BOLD: - fontstyle.set_bold(1) - elif directive == _SUPER: - size = fontstyle.get_size() - fontstyle.set_size(size-_SUPER_SIZE_REDUCTION) - elif directive == _MONO: - fontstyle.set_type_face(BaseDoc.FONT_MONOSPACE) - - for word in text.split(): - length = get_text_width(word,fontstyle) - if length > max_word_size: - max_word_size = length - - return max_word_size - - def get_height(self,width): - """ - Determine the height the paragraph would have - if formatted for a given width. - - width - required formatting width - """ - if not self.lines: - self.format(width) - return self.height - - def format(self,width): - """ - Format the paragraph for a given width. - This is a complex procedure. It assembles lines from the paragraph's - pieces. It also sets the height of the whole paragraph and - the widths available after the lines are assembled. - - width - required formatting width - """ - - if self.lines: - return - - width = width - cm2u(self.style.get_right_margin()) \ - - cm2u(self.style.get_left_margin()) - - nlines = 1 - avail_width = width - - start_piece = end_piece = start_word = end_word = 0 - first = 1 - - for piece_num in range(len(self.piece_list)): - end_piece = piece_num - - (directive,text) = self.piece_list[piece_num] - - fontstyle = BaseDoc.FontStyle(self.fontstyle) - if directive == _BOLD: - fontstyle.set_bold(1) - elif directive == _SUPER: - size = fontstyle.get_size() - fontstyle.set_size(size-_SUPER_SIZE_REDUCTION) - elif directive == _MONO: - fontstyle.set_type_face(BaseDoc.FONT_MONOSPACE) - - if first: - first = 0 - avail_width = avail_width - cm2u(self.style.get_first_indent()) - - if text and avail_width > get_text_width(text,fontstyle): - avail_width -= get_text_width(text,fontstyle) - end_word = len(text.split()) - elif directive == _LINE_BREAK: - nlines += 1 - end_word = 0 - self.lines.append((start_piece,start_word,end_piece,end_word,avail_width)) - avail_width = width - start_piece = end_piece - start_word = 0 - elif text and avail_width <= get_text_width(text,fontstyle): - # divide up text - textlist = text.split() - the_text = "" - for word_num in range(len(textlist)): - word = textlist[word_num] - if get_text_width(the_text + word + " ",fontstyle) <= avail_width: - the_text = the_text + word + " " - else: - # the_text contains as much as avail_width allows - nlines += 1 - end_word = word_num - avail_width -= get_text_width(the_text,fontstyle) - self.lines.append((start_piece,start_word,end_piece,end_word,avail_width)) - avail_width = width - the_text = word + " " - start_piece = end_piece - start_word = word_num - - # if the_text still contains data, we will want to print it out - if the_text: - avail_width = width - get_text_width(the_text,fontstyle) - end_word = len(textlist) - - self.lines.append((start_piece,start_word,end_piece,end_word,avail_width)) - self.height = nlines * self.fontstyle.get_size() \ - * _EXTRA_SPACING_FACTOR \ - + cm2u(self.style.get_top_margin() - +self.style.get_bottom_margin()) - - def get_lines(self): - """ - Return a list of assemlbed lines for the paragraph. - - Each element is a tuple corresponding to the line's contents: - (start_piece,start_word,end_piece,end_word,avail_width) - """ - return self.lines - -#------------------------------------------------------------------------ -# -# Photo class -# -#------------------------------------------------------------------------ -class GnomePrintPhoto: - """ - A photo abstraction which provides the means for correct photo placement. - Way less complex that paragraph, but still useful. - """ - - def __init__(self,name,pos,x_size,y_size): - """ - Creates a GnomePrintPhoto instance. - """ - self.name = name - self.alignment = pos - self.pixbuf = gtk.gdk.pixbuf_new_from_file(name) - self.height = self.pixbuf.get_height() - self.width = self.pixbuf.get_width() - max_size = cm2u(max(x_size,y_size)) - self.scale_x = int(max_size * float(self.width)/max(self.height, - self.width)) - self.scale_y = int(max_size * float(self.height)/max(self.height, - self.width)) - - def get_image(self): - """ - Return the raw image of the photo. - """ - return self.pixbuf.get_pixels() - - def get_has_alpha(self): - """ - Return has_alpha of the photo. - """ - return self.pixbuf.get_has_alpha() - - def get_rowstride(self): - """ - Return the rowstride of the photo. - """ - return self.pixbuf.get_rowstride() - - def get_height(self,width=None): - """ - Return the real height of the photo as it should appear on the page. - """ - return self.scale_y - - def get_width(self): - """ - Return the real width of the photo as it should appear on the page. - """ - return self.scale_x - - def get_min_width(self): - """ - Return the minimum width of the photo as it should appear on the page. - """ - return self.scale_x - - def get_image_height(self): - """ - Return the height of the photo in terms of image's pixels. - """ - return self.height - - def get_image_width(self): - """ - Return the width of the photo in terms of image's pixels. - """ - return self.width - - def get_alignment(self): - """ - Return the alignment of the photo. - """ - return self.alignment - -#------------------------------------------------------------------------ -# -# LPRDoc class -# -#------------------------------------------------------------------------ -class LPRDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc,BaseDoc.DrawDoc): - """Gnome-print document interface class. Derived from BaseDoc.""" - - #------------------------------------------------------------------------ - # - # General methods - # - #------------------------------------------------------------------------ - def open(self,filename): - """Sets up initialization.""" - #set up variables needed to keep track of which state we are in - self.in_table = 0 - self.in_cell = 0 - self.page_count = 0 - self.page_open = 0 - self.brand_new_page = 0 - self.paragraph = None - self.cell_data = [] - self.table_data = [] - - #create main variables for this print job - self.job = gnomeprint.Job(gnomeprint.config_default()) - self.gpc = self.job.get_context() - - #find out what the width and height of the page is - width, height = gnomeprint.job_get_page_size_from_config( - self.job.get_config()) - - self.left_margin = cm2u(self.paper.get_left_margin()) - self.right_margin = width - cm2u(self.paper.get_right_margin()) - self.top_margin = height - cm2u(self.paper.get_top_margin()) - self.bottom_margin = cm2u(self.paper.get_bottom_margin()) - - self.start_page(self) - self.filename = "" - - def close(self): - """Clean up and close the document.""" - #gracefully end page before we close the doc if a page is open - if self.page_open: - self.end_page() - - self.job.close() - self.show_print_dialog() - - def start_page(self,orientation=None): - """Create a new page.""" - # Don't start new page if it is just started - if self.brand_new_page: - return - #reset variables dealing with opening a page - if (self.page_open): - self.end_page() - - self.page_open = 1 - self.page_count += 1 - self.x = self.left_margin - self.y = self.top_margin - - self.gpc.beginpage(str(self.page_count)) - self.gpc.moveto(self.x, self.y) - self.brand_new_page = 1 - - def end_page(self): - """Close the current page.""" - if (self.page_open): - self.page_open = 0 - self.gpc.showpage() - self.brand_new_page = 0 - - def page_break(self): - "Forces a page break, creating a new page." - # If we're already at the very top, relax and do nothing - if not self.brand_new_page: - self.end_page() - self.start_page() - - #------------------------------------------------------------------------ - # - # Text methods - # - #------------------------------------------------------------------------ - - def string_width(self,fontstyle,text): - "Override generic Fontscale-based width." - return get_text_width(text,fontstyle) - - def start_paragraph(self,style_name,leader=None): - """Paragraphs handling - A Gramps paragraph is any - single body of text, from a single word, to several sentences. - We assume a linebreak at the end of each paragraph.""" - # Instantiate paragraph object and initialize buffers - style_sheet = self.get_style_sheet() - style = style_sheet.get_paragraph_style(style_name) - self.paragraph = GnomePrintParagraph(style) - if leader: - append_to_paragraph(self.paragraph,"",leader) - self.paragraph_directive = _POSTLEADER - else: - self.paragraph_directive = "" - self.paragraph_text = "" - self.brand_new_page = 0 - - def end_paragraph(self): - """End the current paragraph.""" - # Add current text/directive to paragraoh, - # then either add paragrah to the list of cell's paragraphs - # or print it right away if not in cell - append_to_paragraph(self.paragraph,self.paragraph_directive, - self.paragraph_text) - if self.in_cell: - # We're inside cell. Add paragrah to celldata - self.cell_data.append(self.paragraph) - else: - # paragraph not in table: write it right away - self.x, self.y = self.write_paragraph(self.paragraph, - self.x, self.y, - self.right_margin - self.left_margin) - self.paragraph = None - self.brand_new_page = 0 - - def start_bold(self): - """Bold face.""" - append_to_paragraph(self.paragraph,self.paragraph_directive, - self.paragraph_text) - self.paragraph_directive = _BOLD - self.paragraph_text = "" - self.brand_new_page = 0 - - def end_bold(self): - """End bold face.""" - append_to_paragraph(self.paragraph,self.paragraph_directive, - self.paragraph_text) - self.paragraph_directive = "" - self.paragraph_text = "" - self.brand_new_page = 0 - - def start_superscript(self): - append_to_paragraph(self.paragraph,self.paragraph_directive, - self.paragraph_text) - self.paragraph_directive = _SUPER - self.paragraph_text = "" - self.brand_new_page = 0 - - def end_superscript(self): - append_to_paragraph(self.paragraph,self.paragraph_directive, - self.paragraph_text) - self.paragraph_directive = "" - self.paragraph_text = "" - self.brand_new_page = 0 - - def start_table(self,name,style_name): - """Begin new table.""" - # initialize table, compute its width, find number of columns - self.table_data = [] - self.in_table = 1 - styles = self.get_style_sheet() - self.tbl_style = styles.get_table_style(style_name) - self.ncols = self.tbl_style.get_columns() - self.rownum = -1 - self.table_width = (self.right_margin - self.left_margin) * \ - self.tbl_style.get_width() / 100.0 - self.cell_widths = [] - self.gp_cell_styles = [] - self.brand_new_page = 0 - - def end_table(self): - """Close the table environment.""" - # output table contents - self.output_table() - self.in_table = 0 - self.y = self.advance_line(self.y) - self.brand_new_page = 0 - - def start_row(self): - """Begin a new row.""" - # Initialize row, compute cell widths - self.row_data = [] - self.rownum = self.rownum + 1 - self.cellnum = -1 - self.span = 1 - self.cell_widths.append([0] * self.ncols) - self.gp_cell_styles.append([None] * self.ncols) - for cell in range(self.ncols): - self.cell_widths[self.rownum][cell] = self.table_width * \ - self.tbl_style.get_column_width(cell) / 100.0 - self.brand_new_page = 0 - - def end_row(self): - """End the row (new line).""" - # add row data to the data we have for the current table - self.table_data.append(self.row_data) - self.brand_new_page = 0 - - def start_cell(self,style_name,span=1): - """Add an entry to the table.""" - # Initialize a cell, take care of span>1 cases - self.brand_new_page = 0 - self.in_cell = 1 - self.cell_data = [] - self.cellnum = self.cellnum + self.span - self.span = span - styles = self.get_style_sheet() - cstyle = styles.get_cell_style(style_name) - self.gp_cell_styles[self.rownum][self.cellnum] = cstyle - for extra_cell in range(1,span): - self.cell_widths[self.rownum][self.cellnum] += \ - self.cell_widths[self.rownum][self.cellnum + extra_cell] - self.cell_widths[self.rownum][self.cellnum + extra_cell] = 0 - - def end_cell(self): - """Prepares for next cell.""" - # append the cell text to the row data - self.in_cell = 0 - self.row_data.append(self.cell_data) - self.brand_new_page = 0 - - def add_media_object(self,name,pos,x,y): - """Add photo to report.""" - - photo = GnomePrintPhoto(name,pos,x,y) - if self.in_cell: - # We're inside cell. Add photo to celldata - self.cell_data.append(photo) - else: - # photo not in table: write it right away - self.x, self.y = self.write_photo(photo, - self.x, self.y, - self.right_margin - self.left_margin) - self.brand_new_page = 0 - - def write_photo(self,photo,x,y,alloc_width): - """ - Write the photo. - - photo - GnomePrintPhoto instance - x,y - coordinates to start at - alloc_width - allocated width - """ - - self.brand_new_page = 0 - # FIXME -- remove when gnome-python is released and hits every distro - if not support_photos: - return (x,y) - # end FIXME - - width = photo.get_width() - height = photo.get_height() - - if y - height < self.bottom_margin: - self.end_page() - self.start_page() - y = self.y - - if photo.get_alignment() == 'center': - add_x = 0.5* (alloc_width - width) - elif photo.get_alignment() == 'right': - add_x = alloc_width - width - else: - add_x = 0 - - self.gpc.gsave() - self.gpc.translate(x+add_x,y-height) - self.gpc.scale(width,height) - - if photo.get_has_alpha(): - self.gpc.rgbaimage(photo.get_image(), - photo.get_image_width(), - photo.get_image_height(), - photo.get_rowstride()) - else: - self.gpc.rgbimage(photo.get_image(), - photo.get_image_width(), - photo.get_image_height(), - photo.get_rowstride()) - - self.gpc.grestore() - y = y - height - return (x,y) - - def write_text(self,text,mark=None): - """Add the text to the paragraph""" - self.brand_new_page = 0 - # Take care of superscript tags - super_count = text.count('') - for num in range(super_count): - start = text.find('') - self.paragraph_text = self.paragraph_text + text[:start] - append_to_paragraph(self.paragraph,self.paragraph_directive,self.paragraph_text) - self.paragraph_text = "" - text = text[start+7:] - - start = text.find('') - self.paragraph_text = self.paragraph_text + text[:start] - append_to_paragraph(self.paragraph,_SUPER,self.paragraph_text) - self.paragraph_text = "" - text = text[start+8:] - - self.paragraph_text = self.paragraph_text + text - - def write_note(self,text,format,style_name): - self.brand_new_page = 0 - if format == 1: - for line in text.split('\n'): - self.start_paragraph(style_name) - self.paragraph_directive = _MONO - self.write_text(line) - 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() - - #function to help us advance a line - def advance_line(self,y,paragraph=None): - self.brand_new_page = 0 - if paragraph: - spacing = paragraph.fontstyle.get_size() * _EXTRA_SPACING_FACTOR - else: - spacing = _LINE_SPACING - new_y = y - spacing - if y < self.bottom_margin: - x = self.x - self.end_page() - self.start_page() - new_y = self.y - self.x = x - return new_y - - def write_paragraph(self,paragraph,x,y,width): - """ - Write the contents of the paragraph, observing per-piece info. - - paragraph - GnomePrintParagraph instance - x,y - coordinates to start at - width - allocated width - """ - - self.brand_new_page = 0 - if not paragraph.get_piece_list(): - return (x,y) - - paragraph.format(width) - - x = x + cm2u(paragraph.style.get_left_margin()) - - width = width - cm2u(paragraph.style.get_right_margin()) \ - - cm2u(paragraph.style.get_left_margin()) - - left_margin = x - no_space = 0 - next_no_space = 0 - first = 1 - - if y - paragraph.fontstyle.get_size() * _EXTRA_SPACING_FACTOR \ - < self.bottom_margin: - self.end_page() - self.start_page() - x = left_margin - y = self.y - - if y != self.top_margin: - y = y - cm2u(paragraph.style.get_top_margin()) - - line_number = 0 - total_lines = len(paragraph.get_lines()) - - # Loop over lines which were assembled by paragraph.format() - for (start_piece,start_word,end_piece,end_word,avail_width) \ - in paragraph.get_lines(): - - line_number += 1 - - if paragraph.get_alignment() == BaseDoc.PARA_ALIGN_CENTER: - x = x + 0.5 * avail_width - elif paragraph.get_alignment() == BaseDoc.PARA_ALIGN_RIGHT: - x = x + avail_width - elif paragraph.get_alignment() == BaseDoc.PARA_ALIGN_LEFT: - pass - elif paragraph.get_alignment() == BaseDoc.PARA_ALIGN_JUSTIFY: - print "LPRDoc: Paragraph justification not supported." - print " Falling back to left-justified mode." - - if first: - first = 0 - x = x + cm2u(paragraph.style.get_first_indent()) - y = y - paragraph.fontstyle.get_size() * _EXTRA_SPACING_FACTOR - - # Loop over pieces that constitute the line - for piece_num in range(start_piece,end_piece+1): - (directive,text) = paragraph.get_piece_list()[piece_num] - fontstyle = BaseDoc.FontStyle(paragraph.get_fontstyle()) - if directive == _BOLD: - fontstyle.set_bold(1) - elif directive == _SUPER: - size = fontstyle.get_size() - fontstyle.set_size(size-_SUPER_SIZE_REDUCTION) - y = y + _SUPER_ELEVATION_FRACTION * fontstyle.get_size() - elif directive == _MONO: - fontstyle.set_type_face(BaseDoc.FONT_MONOSPACE) - elif directive == _POSTLEADER: - x = left_margin - if text == '': - next_no_space = 1 - textlist = text.split() - if start_piece == end_piece: - the_textlist = textlist[start_word:end_word] - elif piece_num > start_piece and piece_num < end_piece: - the_textlist = textlist[:] - elif piece_num == start_piece: - the_textlist = textlist[start_word:] - elif piece_num == end_piece: - the_textlist = textlist[:end_word] - - the_text = ' '.join(the_textlist) - if piece_num == start_piece \ - or directive == _SUPER \ - or directive == _POSTLEADER \ - or next_no_space \ - or no_space \ - or (the_text and the_text[0] in punctuation): - spacer = "" - else: - spacer = " " - the_text = spacer + the_text - - self.gpc.setfont(find_font_from_fontstyle(fontstyle)) - self.gpc.moveto(x, y) - self.gpc.show(the_text) - x = x + get_text_width(the_text,fontstyle) - if directive == _SUPER: - y = y - _SUPER_ELEVATION_FRACTION * fontstyle.get_size() - if directive != _POSTLEADER and next_no_space: - next_no_space = 0 - - # If this was the linebreak, no space on the next line's start - if end_word: - no_space = 0 - else: - no_space = 1 - - if line_number < total_lines: - y = self.advance_line(y,paragraph) - x = left_margin - - x = x - cm2u(paragraph.style.get_left_margin()) - y = y - cm2u(paragraph.style.get_bottom_margin()) - return (x,y) - - def output_table(self): - """Do calcs on data in table and output data in a formatted way.""" - self.brand_new_page = 0 - min_col_size = [0] * self.ncols - max_vspace = [0] * len(self.table_data) - - for row_num in range(len(self.table_data)): - row = self.table_data[row_num][:] - #do calcs on each row and keep track on max length of each column - for col in range(self.ncols): - if not self.cell_widths[row_num][col]: - continue - - padding = cm2u(self.gp_cell_styles[row_num][col].get_padding()) - the_max = 0 - for paragraph in row[col]: - the_min = paragraph.get_min_width() - if the_min > min_col_size[col]: - min_col_size[col] = the_min - - the_max += paragraph.get_height( - self.cell_widths[row_num][col]) - the_max += 2 * padding - if the_max > max_vspace[row_num]: - max_vspace[row_num] = the_max - - #is table width larger than the width of the paper? - min_table_width = 0 - for size in min_col_size: - min_table_width = min_table_width + size - - if min_table_width > (self.right_margin - self.left_margin): - print "LPRDoc: Table does not fit onto the page." - - #for now we will assume left justification of tables - #output data in table - for row_num in range(len(self.table_data)): - row = self.table_data[row_num] - # If this row puts us below the bottom, start new page here - if self.y - max_vspace[row_num] < self.bottom_margin: - self.end_page() - self.start_page() - - x = self.left_margin #reset so that x is at margin - col_y = self.y # all columns start at the same height - for col in range(self.ncols): - if not self.cell_widths[row_num][col]: - continue - self.y = col_y - padding = cm2u(self.gp_cell_styles [row_num][col].get_padding()) - for paragraph in row[col]: - if paragraph.__class__.__name__ == 'GnomePrintPhoto': - write_item = self.write_photo - else: - write_item = self.write_paragraph - junk, self.y = write_item(paragraph, - x + padding, self.y - padding, - self.cell_widths[row_num][col] \ - - 2 * padding) - - x = x + self.cell_widths[row_num][col] # set up margin for this row - self.y = col_y - max_vspace[row_num] - - #------------------------------------------------------------------------ - # - # Graphic methods - # - #------------------------------------------------------------------------ - - def draw_path(self,style,path): - self.brand_new_page = 0 - style_sheet = self.get_style_sheet() - stype = style_sheet.get_draw_style(style) - self.gpc.setlinewidth(stype.get_line_width()) - fill_color = rgb_color(stype.get_fill_color()) - color = rgb_color(stype.get_color()) - - point = path[0] - x = cm2u(point[0]) + self.left_margin - y = self.top_margin - cm2u(point[1]) - self.gpc.moveto(x,y) - - for point in path[1:]: - x = cm2u(point[0]) + self.left_margin - y = self.top_margin - cm2u(point[1]) - self.gpc.lineto(x,y) - self.gpc.closepath() - - self.gpc.setrgbcolor(fill_color[0],fill_color[1],fill_color[2]) - self.gpc.fill() - - point = path[0] - x = cm2u(point[0]) + self.left_margin - y = self.top_margin - cm2u(point[1]) - self.gpc.moveto(x,y) - - for point in path[1:]: - x = cm2u(point[0]) + self.left_margin - y = self.top_margin - cm2u(point[1]) - self.gpc.lineto(x,y) - self.gpc.closepath() - - self.gpc.setrgbcolor(color[0],color[1],color[2]) - self.gpc.stroke() - - self.gpc.setrgbcolor(0,0,0) - - def draw_box(self,style,text,x,y, w, h): - #assuming that we start drawing box from current position - style_sheet = self.get_style_sheet() - - self.brand_new_page = 0 - x = self.left_margin + cm2u(x) - y = self.top_margin - cm2u(y) - - box_style = style_sheet.get_draw_style(style) - bh = cm2u(h) - bw = cm2u(w) - - if box_style.get_shadow(): - ss = cm2u(box_style.get_shadow_space()) - color = rgb_color(_SHADOW_COLOR) - path = ( - (x+ss,y-bh), (x+ss,y-bh-ss), (x+bw+ss,y-bh-ss), - (x+bw+ss,y-ss), (x+bw,y-ss), (x+bw,y-bh), (x+ss,y-bh), - ) - x_i,y_i = path[0] - self.gpc.moveto(x_i,y_i) - for (x_i,y_i) in path[1:]: - self.gpc.lineto(x_i,y_i) - self.gpc.closepath() - - self.gpc.setrgbcolor(color[0],color[1],color[2]) - self.gpc.fill() - self.gpc.setrgbcolor(0,0,0) - - self.gpc.rect_stroked(x,y,bw,-bh) - - if text: - para_name = box_style.get_paragraph_style() - para_style = style_sheet.get_paragraph_style(para_name) - fontstyle = para_style.get_font() - lines = text.split('\n') - start_x = x + 0.5 * fontstyle.get_size() - start_y = y - fontstyle.get_size() * _EXTRA_SPACING_FACTOR - for line in lines: - if not line.split(): - continue - self.gpc.setfont(find_font_from_fontstyle(fontstyle)) - self.gpc.moveto(start_x,start_y) - self.gpc.show(line) - start_y -= fontstyle.get_size() * _EXTRA_SPACING_FACTOR - - def draw_text(self,style,text,x,y): - self.brand_new_page = 0 - style_sheet = self.get_style_sheet() - box_style = style_sheet.get_draw_style(style) - para_name = box_style.get_paragraph_style() - para_style = style_sheet.get_paragraph_style(para_name) - fontstyle = para_style.get_font() - - start_x = self.left_margin + cm2u(x) - start_y = self.top_margin - cm2u(y) - fontstyle.get_size() * _EXTRA_SPACING_FACTOR - - self.gpc.setfont(find_font_from_fontstyle(fontstyle)) - self.gpc.moveto(start_x,start_y) - self.gpc.show(text) - - def center_text(self,style,text,x,y): - self.brand_new_page = 0 - style_sheet = self.get_style_sheet() - box_style = style_sheet.get_draw_style(style) - para_name = box_style.get_paragraph_style() - para_style = style_sheet.get_paragraph_style(para_name) - fontstyle = para_style.get_font() - - width = get_text_width(text,fontstyle) - start_x = self.left_margin + cm2u(x) - 0.5 * width - start_y = self.top_margin - cm2u(y) \ - - fontstyle.get_size() * _EXTRA_SPACING_FACTOR - self.gpc.setfont(find_font_from_fontstyle(fontstyle)) - self.gpc.moveto(start_x, start_y) - self.gpc.show(text) - - def rotate_text(self,style,text,x,y,angle): - self.brand_new_page = 0 - # FIXME - remove when new gnome-python is in all distros - if not support_photos: - return - # end FIXME - style_sheet = self.get_style_sheet() - box_style = style_sheet.get_draw_style(style) - para_name = box_style.get_paragraph_style() - para_style = style_sheet.get_paragraph_style(para_name) - fontstyle = para_style.get_font() - - y_start = self.top_margin - cm2u(y) - x_start = self.left_margin + cm2u(x) - size = fontstyle.get_size() - - self.gpc.gsave() - self.gpc.translate(x_start,y_start) - self.gpc.rotate(-angle) - - this_y = 0 - for line in text: - if not line.split(): - continue - width = get_text_width(line,fontstyle) - this_x = -0.5 * width - self.gpc.setfont(find_font_from_fontstyle(fontstyle)) - self.gpc.moveto(this_x,this_y) - self.gpc.show(line) - this_y -= size * _EXTRA_SPACING_FACTOR - - self.gpc.grestore() - - def draw_line(self,style,x1,y1,x2,y2): - self.brand_new_page = 0 - x1 = cm2u(x1) + self.left_margin - x2 = cm2u(x2) + self.left_margin - y1 = self.top_margin - cm2u(y1) - y2 = self.top_margin - cm2u(y2) - self.gpc.line_stroked(x1,y1,x2,y2) - - #------------------------------------------------------------------------ - # - # Print job methods - # - #------------------------------------------------------------------------ - - #function to print text to a printer - def do_print(self,dialog,job): - self.gpc = gnomeprint.Context(dialog.get_config()) - job.render(self.gpc) - self.gpc.close() - - #I believe this is a print preview - def show_preview(self,dialog): - w = gnomeprint.ui.JobPreview(self.job, _("Print Preview")) - w.set_property('allow-grow', 1) - w.set_property('allow-shrink', 1) - w.set_transient_for(dialog) - w.show_all() - - #function used to get users response and do a certain - #action depending on that response - def print_dialog_response(self, dialog, resp, job): - if resp == gnomeprint.ui.DIALOG_RESPONSE_PREVIEW: - self.show_preview(dialog) - elif resp == gnomeprint.ui.DIALOG_RESPONSE_CANCEL: - dialog.destroy() - elif resp == gnomeprint.ui.DIALOG_RESPONSE_PRINT: - self.do_print(dialog, self.job) - dialog.destroy() - - #function displays a window that allows user to choose - #to print, show, etc - def show_print_dialog(self): - dialog = gnomeprint.ui.Dialog(self.job, _("Print..."), - gnomeprint.ui.DIALOG_RANGE|gnomeprint.ui.DIALOG_COPIES) - dialog.construct_range_page( - gnomeprint.ui.RANGE_ALL|gnomeprint.ui.RANGE_RANGE, - 1, self.page_count, "A", "Pages: ") - dialog.connect('response', self.print_dialog_response, self.job) - dialog.show() - -#------------------------------------------------------------------------ -# -# Register the document generator with the system -# -#------------------------------------------------------------------------ -register_text_doc( - name=_("Print..."), - classref=LPRDoc, - table=1, - paper=1, - style=1, - ext="", - print_report_label=None, - clname='print') - -register_book_doc( - _("Print..."), - LPRDoc, - 1, - 1, - 1, - "", - 'print') - -register_draw_doc( - _("Print..."), - LPRDoc, - 1, - 1, - "", - None, - 'print') diff --git a/src/docgen/OpenOfficeDoc.py b/src/docgen/OpenOfficeDoc.py deleted file mode 100644 index 6fb1f3f80..000000000 --- a/src/docgen/OpenOfficeDoc.py +++ /dev/null @@ -1,1014 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2006 Donald N. Allingham -# Copyright (C) 2007 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$ - -#------------------------------------------------------------------------- -# -# Standard Python Modules -# -#------------------------------------------------------------------------- -import os -import zipfile -import time -from cStringIO import StringIO -from math import pi, cos, sin -from gettext import gettext as _ -from xml.sax.saxutils import escape - -#------------------------------------------------------------------------- -# -# Gramps modules -# -#------------------------------------------------------------------------- -import BaseDoc -import const -from PluginUtils import register_text_doc, register_draw_doc, register_book_doc -from ReportBase import ReportUtils -import ImgManip -import FontScale -import Mime -import Utils -import Errors - -#------------------------------------------------------------------------- -# -# constants -# -#------------------------------------------------------------------------- -_apptype = 'application/vnd.sun.xml.writer' - -_esc_map = { - '\x1a' : '', - '\x0c' : '', - '\n' : '', - '<super>' : '', - '</super>' : '', - } - -#------------------------------------------------------------------------- -# -# OpenOfficeDoc -# -#------------------------------------------------------------------------- -class OpenOfficeDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc,BaseDoc.DrawDoc): - - def __init__(self,styles,type,template): - BaseDoc.BaseDoc.__init__(self,styles,type,template) - self.media_list = [] - self.cntnt = None - self.filename = None - 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 - - def open(self,filename): - t = time.localtime(time.time()) - self.time = "%04d-%02d-%02dT%02d:%02d:%02d" % \ - (t[0],t[1],t[2],t[3],t[4],t[5]) - - if filename[-4:] != ".sxw": - self.filename = filename + ".sxw" - else: - self.filename = filename - - self.filename = os.path.normpath(os.path.abspath(self.filename)) - self.cntnt = StringIO() - - def init(self): - - assert (not self.init_called) - self.init_called = True - - self.lang = Utils.xml_lang() - style_sheet = self.get_style_sheet() - - 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('\n') - self.cntnt.write('\n') - self.cntnt.write('') - self.cntnt.write('') - self.cntnt.write('\n') - self.cntnt.write('') - self.cntnt.write('') - self.cntnt.write('\n') - - for style_name in style_sheet.get_draw_style_names(): - style = style_sheet.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') - - self.cntnt.write('\n') - self.cntnt.write('\t\n') - self.cntnt.write('\n') - - for style_name in style_sheet.get_paragraph_style_names(): - style = style_sheet.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 == BaseDoc.PARA_ALIGN_LEFT: - self.cntnt.write('fo:text-align="start" ') - elif align == BaseDoc.PARA_ALIGN_RIGHT: - self.cntnt.write('fo:text-align="end" ') - elif align == BaseDoc.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() == BaseDoc.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="%.3fpt" ' % font.get_size()) - self.cntnt.write('style:font-size-asian="%.3fpt" ' - % 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" ' - % style.get_first_indent()) - self.cntnt.write('fo:margin-right="%.2fcm" ' - % style.get_right_margin()) - self.cntnt.write('fo:margin-left="%.2fcm" ' - % style.get_left_margin()) - self.cntnt.write('fo:margin-top="%.2fcm" ' - % style.get_top_margin()) - self.cntnt.write('fo:margin-bottom="%.2fcm"' - % style.get_bottom_margin()) - 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 style_sheet.get_table_style_names(): - style = style_sheet.get_table_style(style_name) - self.cntnt.write('\n') - table_width = float(self.get_usable_width()) - table_width_str = "%.4f" % 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 style_sheet.get_cell_style_names(): - cell_style = style_sheet.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') - - #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') - - def close(self): - self.cntnt.write('\n') - self.cntnt.write('\n') - self._write_styles_file() - self._write_manifest() - self._write_meta_file() - self._write_zip() - if self.print_req: - app = Mime.get_application(_apptype) - Utils.launch(app[0],self.filename) - - def add_media_object(self,name,pos,x_cm,y_cm): - - # try to open the image. If the open fails, it probably wasn't - # a valid image (could be a PDF, or a non-image) - try: - image = ImgManip.ImgManip(name) - (x,y) = image.size() - ratio = float(x_cm)*float(y)/(float(y_cm)*float(x)) - except: - return - - if ratio < 1: - act_width = x_cm - act_height = y_cm*ratio - else: - act_height = y_cm - act_width = x_cm/ratio - - media_list_item = (name,act_width,act_height) - if not media_list_item in self.media_list: - self.media_list.append(media_list_item) - - base = os.path.basename(name) - tag = base.replace('.','_') - - if self.new_cell: - self.cntnt.write('') - if pos == "left": - self.cntnt.write('\n') - if self.new_cell: - self.cntnt.write('\n') - - def start_table(self,name,style_name): - 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): - self.cntnt.write('\n') - - def start_row(self): - self.cntnt.write('\n') - - def end_row(self): - self.cntnt.write('\n') - - def start_cell(self,style_name,span=1): - 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): - self.cntnt.write('\n') - for col in range(1,self.span): - self.cntnt.write('\n') - self.new_cell = 0 - - def start_bold(self): - self.cntnt.write('') - - def end_bold(self): - self.cntnt.write('') - - def start_superscript(self): - self.cntnt.write('') - - def end_superscript(self): - self.cntnt.write('') - - def _add_zip(self,zfile,name,data,t): - zipinfo = zipfile.ZipInfo(name.encode('latin-1')) - zipinfo.date_time = t - zipinfo.compress_type = zipfile.ZIP_DEFLATED - zfile.writestr(zipinfo,data) - - def _write_zip(self): - 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.cntnt.getvalue(),t) - self._add_zip(zfile,"meta.xml",self.meta.getvalue(),t) - self._add_zip(zfile,"styles.xml",self.sfile.getvalue(),t) - - self.mfile.close() - self.cntnt.close() - self.meta.close() - self.sfile.close() - - for image in self.media_list: - try: - ifile = open(image[0],mode='rb') - base = os.path.basename(image[0]) - self._add_zip(zfile,"Pictures/%s" % base, ifile.read(),t) - ifile.close() - except: - print "Could not open %s" % image[0] - zfile.close() - - def _write_styles_file(self): - self.sfile = StringIO() - style_sheet = self.get_style_sheet() - - 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('\n') - self.sfile.write('\n') - - for name in style_sheet.get_paragraph_style_names(): - style = style_sheet.get_paragraph_style(name) - self.sfile.write('\n') - self.sfile.write(' 0: - self.sfile.write('fo:keep-with-next="true" ') - - align = style.get_alignment() - if align == BaseDoc.PARA_ALIGN_LEFT: - self.sfile.write('fo:text-align="start" ') - elif align == BaseDoc.PARA_ALIGN_RIGHT: - self.sfile.write('fo:text-align="end" ') - elif align == BaseDoc.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" ') - font = style.get_font() - if font.get_type_face() == BaseDoc.FONT_SANS_SERIF: - self.sfile.write('style:font-name="Arial" ') - else: - self.sfile.write('style:font-name="Times New Roman" ') - self.sfile.write('fo:font-size="%.3fpt" ' % font.get_size()) - color = font.get_color() - self.sfile.write('fo:color="#%02x%02x%02x" ' % color) - if font.get_bold(): - self.sfile.write('fo:font-weight="bold" ') - if font.get_italic(): - self.sfile.write('fo:font-style="italic" ') - if font.get_underline(): - self.sfile.write('style:text-underline="single" ') - self.sfile.write('style:text-underline-color="font-color" ') - self.sfile.write('fo:text-indent="%.2fcm" ' - % style.get_first_indent()) - self.sfile.write('fo:margin-right="%.2fcm" ' - % style.get_right_margin()) - self.sfile.write('fo:margin-left="%.2fcm" ' - % style.get_left_margin()) - self.sfile.write('fo:margin-top="%.2fcm" ' - % style.get_top_margin()) - self.sfile.write('fo:margin-bottom="%.2fcm"' - % style.get_bottom_margin()) - 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('\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('\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') - - def page_break(self): - self.new_page = 1 - - def start_page(self): - self.cntnt.write('\n') - - def end_page(self): - self.cntnt.write('\n') - - def start_paragraph(self,style_name,leader=None): - 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('' % self.level) - if leader != None: - self.cntnt.write(leader) - self.cntnt.write('') - self.new_cell = 0 - - def end_paragraph(self): - 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): - if format == 1: - text = text.replace('&','&') # Must be first - text = text.replace('<','<') - text = text.replace('>','>') - # 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) ) - text = text.replace('\n','') - text = text.replace('\t','') - text = text.replace('<super>', - '') - text = text.replace('</super>','') - - 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_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 == BaseDoc.INDEX_TYPE_ALP: - self.cntnt.write('' % key) - elif mark.type == BaseDoc.INDEX_TYPE_TOC: - self.cntnt.write('' % mark.level) - self.cntnt.write(escape(text,_esc_map)) - - def _write_manifest(self): - self.mfile = StringIO() - - self.mfile.write('\n') - self.mfile.write('') - self.mfile.write('') - for image in self.media_list: - i = image[0] - base = os.path.basename(i) - self.mfile.write('') - self.mfile.write('') - self.mfile.write('') - self.mfile.write('') - self.mfile.write('') - self.mfile.write('\n') - - def _write_meta_file(self): - 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('') - 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('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('\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): - 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)) - oneline = (size/72.0)*2.54 - width = 0 - for line in text: - width = max(width,FontScale.string_width(font,line)) - wcm = (width/72.0)*2.54 - hcm = (height/72.0)*2.54 - - rangle = (pi/180.0) * angle - - self.cntnt.write('') - self.cntnt.write('' % pname) - - self.cntnt.write('\n' % pname) - self.write_text('\n'.join(text)) - self.cntnt.write('\n\n\n') - - def draw_path(self,style,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): - self.cntnt.write('\n') - - def draw_text(self,style,text,x,y): - 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(FontScale.string_width(font,text))*1.3 - - self.cntnt.write('' % float(y)) - self.cntnt.write('' % para_name) - self.cntnt.write('' % para_name) - self.cntnt.write(text) - self.cntnt.write('') - self.cntnt.write('\n') - - def draw_box(self,style,text,x,y, w, h): - 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) - text = text.replace('\t','') - text = text.replace('\n','') - self.cntnt.write(text) - self.cntnt.write('') - self.cntnt.write('\n') - self.cntnt.write('\n') - - def center_text(self,style,text,x,y): - 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 = (FontScale.string_width(font,text)/72.0) * 2.54 - - self.cntnt.write('\n' % float(y)) - - if text != "": - self.cntnt.write('' % para_name) - self.cntnt.write(text) - self.cntnt.write('\n') - self.cntnt.write('\n') - -#-------------------------------------------------------------------------- -# -# Register plugins -# -#-------------------------------------------------------------------------- -print_label = None -try: - - mprog = Mime.get_application(_apptype) - mtype = Mime.get_description(_apptype) - - if Utils.search_for(mprog[0]): - print_label = _("Open in OpenOffice.org") - else: - print_label = None - - register_text_doc(mtype,OpenOfficeDoc,1,1,1,".sxw",print_label) - register_book_doc(mtype,OpenOfficeDoc,1,1,1,".sxw", print_label) - register_draw_doc(mtype,OpenOfficeDoc,1,1, ".sxw",print_label); -except: - register_text_doc(_('OpenOffice.org Writer'), - OpenOfficeDoc,1,1,1,".sxw", None) - register_book_doc(_("OpenOffice.org Writer"), OpenOfficeDoc,1,1,1,".sxw") - register_draw_doc(_("OpenOffice.org Writer"), - OpenOfficeDoc,1,1,".sxw",None); diff --git a/src/docgen/PdfDoc.py b/src/docgen/PdfDoc.py deleted file mode 100644 index 3f2c9848e..000000000 --- a/src/docgen/PdfDoc.py +++ /dev/null @@ -1,682 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2006 Donald N. Allingham -# Copyright (C) 2007 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$ - -#------------------------------------------------------------------------ -# -# Python modules -# -#------------------------------------------------------------------------ -from gettext import gettext as _ - -#------------------------------------------------------------------------ -# -# gramps modules -# -#------------------------------------------------------------------------ -import BaseDoc -from PluginUtils import register_text_doc, register_draw_doc, register_book_doc -import Errors -from QuestionDialog import ErrorDialog -import ImgManip -import Mime - -_H = 'Helvetica' -_HB = 'Helvetica-Bold' -_HO = 'Helvetica-Oblique' -_HBO = 'Helvetica-BoldOblique' -_T = 'Times-Roman' -_TB = 'Times-Bold' -_TI = 'Times-Italic' -_TBI = 'Times-BoldItalic' - -#------------------------------------------------------------------------ -# -# Set up logging -# -#------------------------------------------------------------------------ -import logging -log = logging.getLogger(".PdfDoc") - -#------------------------------------------------------------------------ -# -# ReportLab python/PDF modules -# -#------------------------------------------------------------------------ -try: - import reportlab.platypus.tables - from reportlab.platypus import * - from reportlab.lib.units import cm - from reportlab.lib.colors import Color - from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY - import reportlab.graphics.shapes - import reportlab.lib.styles - from reportlab.pdfbase.pdfmetrics import * - from reportlab.platypus.doctemplate import LayoutError - - for faceName in reportlab.pdfbase.pdfmetrics.standardFonts: - reportlab.pdfbase.pdfmetrics.registerTypeFace( - reportlab.pdfbase.pdfmetrics.TypeFace(faceName)) - -except ImportError: - raise Errors.UnavailableError(_("Cannot be loaded because ReportLab is not installed")) - - -# Old reportlab versions < 2.0 did not work with utf8 or unicode -# so for those we need to encode text into latin1 -# For the utf8-capable reportlab we should not. -def enc_latin1(s): - try: - new_s = s - return new_s.encode('iso-8859-1') - except: - return str(s) - -def pass_through(s): - return s - -from reportlab import Version as reportlab_version -version_tuple = tuple( [int(item) for item in reportlab_version.split('.')] ) -if version_tuple < (2,0): - enc = enc_latin1 -else: - enc = pass_through - -# Only announce PIL warning once per use of Gramps -_pil_warn = True - -#------------------------------------------------------------------------ -# -# GrampsDocTemplate -# -#------------------------------------------------------------------------ -class GrampsDocTemplate(BaseDocTemplate): - """A document template for the ReportLab routines.""" - - def build(self,flowables): - """Override the default build routine, to recalculate - for any changes in the document (margins, etc.)""" - self._calc() - BaseDocTemplate.build(self,flowables) - -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ -class PdfDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc,BaseDoc.DrawDoc): - - def open(self,filename): - if filename[-4:] != ".pdf": - self.filename = "%s.pdf" % filename - else: - self.filename = filename - - page_w = self.paper.get_size().get_width() * cm - page_h = self.paper.get_size().get_height() * cm - self.pagesize = (page_w,page_h) - - self.doc = GrampsDocTemplate(self.filename, - pagesize=self.pagesize, - allowSplitting=1, - _pageBreakQuick=0, - leftMargin=self.paper.get_left_margin()*cm, - rightMargin=self.paper.get_right_margin()*cm, - topMargin=self.paper.get_top_margin()*cm, - bottomMargin=self.paper.get_bottom_margin()*cm) - frameT = Frame(0,0,page_w,page_h, - self.paper.get_left_margin()*cm, self.paper.get_bottom_margin()*cm, - self.paper.get_right_margin()*cm,self.paper.get_top_margin()*cm, - id='normal') - ptemp = PageTemplate(frames=frameT,pagesize=self.pagesize) - self.doc.addPageTemplates([ptemp]) - - self.pdfstyles = {} - style_sheet = self.get_style_sheet() - for style_name in style_sheet.get_paragraph_style_names(): - style = style_sheet.get_paragraph_style(style_name) - font = style.get_font() - - pdf_style = reportlab.lib.styles.ParagraphStyle(name=style_name) - pdf_style.fontSize = font.get_size() - pdf_style.bulletFontSize = font.get_size() - pdf_style.leading = font.get_size()*1.2 - - pdf_style.fontName = self.pdf_set_font(font) - pdf_style.bulletFontName = pdf_style.fontName - - pdf_style.rightIndent = style.get_right_margin()*cm - pdf_style.leftIndent = style.get_left_margin()*cm - pdf_style.firstLineIndent = style.get_first_indent()*cm - pdf_style.bulletIndent = pdf_style.firstLineIndent + \ - pdf_style.leftIndent - - align = style.get_alignment() - if align == BaseDoc.PARA_ALIGN_RIGHT: - pdf_style.alignment = TA_RIGHT - elif align == BaseDoc.PARA_ALIGN_LEFT: - pdf_style.alignment = TA_LEFT - elif align == BaseDoc.PARA_ALIGN_CENTER: - pdf_style.alignment = TA_CENTER - else: - pdf_style.alignment = TA_JUSTIFY - pdf_style.spaceBefore = style.get_top_margin()*cm - pdf_style.spaceAfter = style.get_bottom_margin()*cm - pdf_style.textColor = make_color(font.get_color()) - self.pdfstyles[style_name] = pdf_style - - self.story = [] - self.in_table = 0 - - def close(self): - try: - self.doc.build(self.story) - except IOError,msg: - errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg) - raise Errors.ReportError(errmsg) - except LayoutError,msg: - if str(msg).rfind("too large on page") > -1: - errmsg = "Reportlab is unable to layout your report. " + \ - "This is probably because you have some text that " + \ - "is too large to fit on one page or in one cell. " + \ - "Try changing some report options or use a " + \ - "different output format." - else: - errmsg = "Reportlab is unable to layout your report. " + \ - "Try changing some report options or use a " + \ - "different output format." - raise Errors.ReportError(errmsg) - - if self.print_req: - apptype = 'application/pdf' - app = Mime.get_application(apptype) - os.environ["FILE"] = self.filename - os.system ('%s "$FILE" &' % app[0]) - - def page_break(self): - self.story.append(PageBreak()) - - def start_paragraph(self,style_name,leader=None): - style_sheet = self.get_style_sheet() - self.current_para = self.pdfstyles[style_name] - self.my_para = style_sheet.get_paragraph_style(style_name) - self.super = "" \ - % (self.my_para.get_font().get_size()-2) - if leader==None: - self.text = '' - else: - self.current_para.firstLineIndent = 0 - self.text = '%s' % leader - - def end_paragraph(self): - if self.in_table: - self.cur_cell.append(Paragraph(enc(self.text),self.current_para)) - else: - self.story.append(Paragraph(enc(self.text),self.current_para)) - - def start_bold(self): - self.text = self.text + '' - - def end_bold(self): - self.text = self.text + '' - - def start_superscript(self): - fsize = self.my_para.get_font().get_size() - self.text = self.text + '' % (fsize-2) - - def end_superscript(self): - self.text = self.text + '' - - def start_table(self,name,style_name): - self.in_table = 1 - styles = self.get_style_sheet() - self.cur_table = styles.get_table_style(style_name) - self.row = -1 - self.col = 0 - self.cur_row = [] - self.table_data = [] - - self.tblstyle = [] - self.text = "" - - def end_table(self): - # Calculate optimal widths - self.cur_table_cols = [] - width = float(self.cur_table.get_width()/100.0) * self.get_usable_width() - for val in range(self.cur_table.get_columns()): - percent = float(self.cur_table.get_column_width(val))/100.0 - self.cur_table_cols.append(int(width * percent * cm)) - - ts = reportlab.platypus.tables.TableStyle(self.tblstyle) - tbl = reportlab.platypus.tables.Table(data=self.table_data, - colWidths=self.cur_table_cols, - style=ts) - self.story.append(tbl) - self.in_table = 0 - - def start_row(self): - self.row = self.row + 1 - self.col = 0 - self.cur_row = [] - self.cur_table_cols = [] - - def end_row(self): - self.table_data.append(self.cur_row) - - def start_cell(self,style_name,span=1): - self.span = span - styles = self.get_style_sheet() - self.my_table_style = styles.get_cell_style(style_name) - self.cur_cell = [] - - def end_cell(self): - if self.cur_cell: - self.cur_row.append(self.cur_cell) - else: - self.cur_row.append("") - - # Fill in cells that this cell spans over - for val in range(1,self.span): - self.cur_row.append("") - - p = self.my_para - f = p.get_font() - fn = self.pdf_set_font(f) - black = Color(0,0,0) - - for inc in range(self.col,self.col+self.span): - loc = (inc,self.row) - self.tblstyle.append(('FONT', loc, loc, fn, f.get_size())) - if self.span == 1 or inc == self.col + self.span - 1: - if self.my_table_style.get_right_border(): - self.tblstyle.append(('LINEAFTER', loc, loc, 1, black)) - if self.span == 1 or inc == self.col: - if self.my_table_style.get_left_border(): - self.tblstyle.append(('LINEBEFORE', loc, loc, 1, black)) - if self.my_table_style.get_top_border(): - self.tblstyle.append(('LINEABOVE', loc, loc, 1, black)) - if self.my_table_style.get_bottom_border(): - self.tblstyle.append(('LINEBELOW', loc, loc, 1, black)) - - # Set the alignment - if p.get_alignment() == BaseDoc.PARA_ALIGN_LEFT: - self.tblstyle.append(('ALIGN', loc, loc, 'LEFT')) - elif p.get_alignment() == BaseDoc.PARA_ALIGN_RIGHT: - self.tblstyle.append(('ALIGN', loc, loc, 'RIGHT')) - else: - self.tblstyle.append(('ALIGN', loc, loc, 'CENTER')) - self.tblstyle.append(('VALIGN', loc, loc, 'TOP')) - - # The following lines will enable the span feature. - # This is nice, except when spanning, lines that would have overfilled - # their cells still increase the height of the cell to make room for the - # wrapped text (even though the text does not actually wrap because it - # is spanned) - #if self.span != 1: - # self.tblstyle.append(('SPAN', (self.col, self.row), (self.col + self.span - 1, self.row ) )) - - # The following lines will enable the span feature. - # This is nice, except when spanning, lines that would have overfilled - # their cells still increase the height of the cell to make room for the - # wrapped text (even though the text does not actually wrap because it is spanned) - #if self.span != 1: - # self.tblstyle.append(('SPAN', (self.col, self.row), (self.col + self.span - 1, self.row ) )) - - self.col = self.col + self.span - self.text = "" - - def add_media_object(self,name,pos,x_cm,y_cm): - try: - img = ImgManip.ImgManip(name) - except: - return - - x,y = img.size() - - 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 - - try: - # Reportlab uses PIL to layout images. Make sure it is installed. - import PIL - except: - global _pil_warn - if _pil_warn: - ErrorDialog( - _("You do not have the Python Imaging Library installed " - "Images will not be added to this report")) - _pil_warn = False - return - - try: - im = Image(str(name),act_width*cm,act_height*cm) - except: - ErrorDialog( _("Reportlab is unable to add this image: %s") % name ) - return - - if pos in ['left','right','center']: - im.hAlign = pos.upper() - else: - im.hAlign = 'LEFT' - - if self.in_table: - self.cur_cell.append(Spacer(1,0.5*cm)) - self.cur_cell.append(im) - self.cur_cell.append(Spacer(1,0.5*cm)) - else: - self.story.append(Spacer(1,0.5*cm)) - self.story.append(im) - self.story.append(Spacer(1,0.5*cm)) - - def write_note(self,text,format,style_name): - text = enc(text) - current_para = self.pdfstyles[style_name] - style_sheet = self.get_style_sheet() - self.my_para = style_sheet.get_paragraph_style(style_name) - self.super = "" \ - % (self.my_para.get_font().get_size()-2) - - text = text.replace('&','&') # Must be first - text = text.replace('<','<') - text = text.replace('>','>') - text = text.replace('<super>',self.super) - text = text.replace('</super>','') - - if format == 1: - text = '%s' \ - % text.replace('\t',' '*8) - if self.in_table: - self.cur_cell.append(XPreformatted(text,current_para)) - else: - self.story.append(XPreformatted(text,current_para)) - elif format == 0: - for line in text.split('\n\n'): - if self.in_table: - self.cur_cell.append(Paragraph(line,current_para)) - else: - self.story.append(Paragraph(line,current_para)) - - def write_text(self,text,mark=None): - text = text.replace('&','&') # Must be first - text = text.replace('<','<') - text = text.replace('>','>') - text = text.replace('<super>',self.super) - text = text.replace('</super>','') - self.text = self.text + text.replace('\n','
') - - def start_page(self): - x = self.get_usable_width()*cm - y = self.get_usable_height()*cm - self.drawing = reportlab.graphics.shapes.Drawing(x,y) - - def end_page(self): - self.story.append(self.drawing) - - def draw_line(self,style,x1,y1,x2,y2): - y1 = self.get_usable_height() - y1 - y2 = self.get_usable_height() - y2 - style_sheet = self.get_style_sheet() - stype = style_sheet.get_draw_style(style) - if stype.get_line_style() == BaseDoc.SOLID: - line_array = None - else: - line_array = [2,4] - - l = reportlab.graphics.shapes.Line(x1*cm,y1*cm, - x2*cm,y2*cm, - strokeWidth=stype.get_line_width(), - strokeDashArray=line_array) - self.drawing.add(l) - - def draw_path(self,style,path): - style_sheet = self.get_style_sheet() - stype = style_sheet.get_draw_style(style) - color = make_color(stype.get_fill_color()) - y = self.get_usable_height()*cm - - if stype.get_line_style() == BaseDoc.SOLID: - line_array = None - else: - line_array = [2,4] - - scol = make_color(stype.get_color()) - p = reportlab.graphics.shapes.Path(strokeWidth=stype.get_line_width(), - strokeDashArray=line_array, - fillColor=color, - strokeColor=scol) - - point = path[0] - p.moveTo(point[0]*cm,y-point[1]*cm) - for point in path[1:]: - p.lineTo(point[0]*cm,y-point[1]*cm) - p.closePath() - self.drawing.add(p) - - def draw_box(self,style,text,x,y, w, h): - y = self.get_usable_height() - y - style_sheet = self.get_style_sheet() - box_style = style_sheet.get_draw_style(style) - - sspace = box_style.get_shadow_space() - if box_style.get_shadow(): - col = make_color((0xc0,0xc0,0xc0)) - r = reportlab.graphics.shapes.Rect((x+sspace)*cm, - (y-sspace)*cm-(h*cm), - w*cm,h*cm, - fillColor=col, - strokeColor=col) - self.drawing.add(r) - - sw = box_style.get_line_width() - fc = box_style.get_fill_color() - sc = box_style.get_color() - r = reportlab.graphics.shapes.Rect((x)*cm,(y*cm)-(h*cm),w*cm,h*cm, - strokeWidth=sw, - fillColor=fc, - strokeColor=sc) - self.drawing.add(r) - - if text != "": - para_name = box_style.get_paragraph_style() - p = style_sheet.get_paragraph_style(para_name) - size = p.get_font().get_size() - x = x + sspace - lines = text.split('\n') - self.left_print(lines,p.get_font(),x*cm,y*cm - size) - - def draw_text(self,style,text,x,y): - 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() - y = (self.get_usable_height()*cm)-(y*cm) - sc = make_color(font.get_color()) - fc = make_color(font.get_color()) - fnt = self.pdf_set_font(font) - if p.get_alignment() == BaseDoc.PARA_ALIGN_CENTER: - twidth = ((self.string_width(font,enc(text)))/2.0)*cm - xcm = (stype.get_width() - x) - twidth - else: - xcm = x * cm - s = reportlab.graphics.shapes.String(xcm, - y - size, - enc(text), - strokeColor=sc, - fillColor=fc, - fontName=fnt, - fontSize=size) - self.drawing.add(s) - - def pdf_set_font(self, font): - if font.get_type_face() == BaseDoc.FONT_SANS_SERIF: - if font.get_bold() and font.get_italic(): - fn = _HBO - elif font.get_bold(): - fn = _HB - elif font.get_italic(): - fn = _HO - else: - fn = _H - else: - if font.get_bold() and font.get_italic(): - fn = _TBI - elif font.get_bold(): - fn = _TB - elif font.get_italic(): - fn = _TI - else: - fn = _T - return fn - - def rotate_text(self,style,text,x,y,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() - yt = (self.get_usable_height()*cm) - (y*cm) - - yval = 0 - g = reportlab.graphics.shapes.Group() - fnt = self.pdf_set_font(font) - sc = make_color(font.get_color()) - fc = make_color(font.get_color()) - for line in text: - s = reportlab.graphics.shapes.String(0,yval,enc(line), - fontName=fnt, - fontSize=size, - strokeColor=sc, - fillColor=fc, - textAnchor='middle') - yval -= size - g.add(s) - - g.translate(x*cm,yt) - g.rotate(-angle) - self.drawing.add(g) - - def center_text(self,style,text,x,y): - 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() - yt = (self.get_usable_height()*cm) - (y*cm) - size = font.get_size() - fnt = self.pdf_set_font(font) - sc = make_color(font.get_color()) - fc = make_color(font.get_color()) - s = reportlab.graphics.shapes.String(x*cm, - yt - size, - enc(text), - fontName=fnt, - fontSize=font.get_size(), - strokeColor=sc, - fillColor=fc, - textAnchor='middle') - self.drawing.add(s) - - def center_print(self,lines,font,x,y,w,h): - l = len(lines) - size = font.get_size() - start_y = (y + h/2.0 + l/2.0 + l) - ((l*size) + ((l-1)*0.2))/2.0 - start_x = (x + w/2.0) - - fnt = self.pdf_set_font(font) - size = font.get_size() - sc = make_color(font.get_color()) - fc = make_color(font.get_color()) - for text in lines: - s = reportlab.graphics.shapes.String(start_x*cm, - start_y*cm, - enc(text), - fontName=fnt, - fontSize=size, - strokeColor=sc, - fillColor=fc) - self.drawing.add(s) - start_y = start_y - size*1.2 - - def left_print(self,lines,font,x,y): - size = font.get_size() - start_y = y - start_x = x - - fnt = self.pdf_set_font(font) - sc = make_color(font.get_color()) - fc = make_color(font.get_color()) - for text in lines: - s = reportlab.graphics.shapes.String(start_x, - start_y, - enc(text), - fontSize=size, - strokeColor=sc, - fillColor=fc, - fontName=fnt) - self.drawing.add(s) - start_y = start_y - size*1.2 - -#------------------------------------------------------------------------ -# -# Convert an RGB color tulple to a Color instance -# -#------------------------------------------------------------------------ -def make_color(c): - return Color(float(c[0])/255.0, float(c[1])/255.0, float(c[2])/255.0) - -#------------------------------------------------------------------------ -# -# Register the document generator with the GRAMPS plugin system -# -#------------------------------------------------------------------------ -print_label = None -try: - import Utils - - mprog = Mime.get_application("application/pdf") - mtype = Mime.get_description("application/pdf") - - if Utils.search_for(mprog[0]): - print_label=_("Open in %s") % mprog[1] - else: - print_label=None - register_text_doc(mtype, PdfDoc, 1, 1, 1, ".pdf", print_label) - register_draw_doc(mtype, PdfDoc, 1, 1, ".pdf", print_label) - register_book_doc(mtype,classref=PdfDoc, - table=1,paper=1,style=1,ext=".pdf") -except: - register_text_doc(_('PDF document'), PdfDoc,1, 1, 1,".pdf", None) - register_draw_doc(_('PDF document'), PdfDoc,1, 1, ".pdf", None) - register_book_doc(name=_("PDF document"),classref=PdfDoc, - table=1,paper=1,style=1,ext=".pdf")