From 91d5a4c7b7e6f8f91b0d792b1a941c7bd974edfb Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 14 Dec 2003 21:45:11 +0000 Subject: [PATCH] * src/docgen/AbiWordDoc.py: removed the 1.0 version of AbiWord, since GRAMPS is a GNOME 2 application, support the GNOME 2 version of AbiWord * src/docgen/OpenOfficeDoc.py: Fixed width fonts for preformatted text * src/docgen/AbiWord2Doc.py: Fixed width fonts for preformatted text svn: r2521 --- gramps2/src/docgen/AbiWord2Doc.py | 4 +- gramps2/src/docgen/AbiWordDoc.py | 359 ---------------------------- gramps2/src/docgen/OpenOfficeDoc.py | 7 + 3 files changed, 10 insertions(+), 360 deletions(-) delete mode 100644 gramps2/src/docgen/AbiWordDoc.py diff --git a/gramps2/src/docgen/AbiWord2Doc.py b/gramps2/src/docgen/AbiWord2Doc.py index 2c1a8d274..57c0f2303 100644 --- a/gramps2/src/docgen/AbiWord2Doc.py +++ b/gramps2/src/docgen/AbiWord2Doc.py @@ -232,9 +232,11 @@ class AbiWordDoc(BaseDoc.BaseDoc): elif format == 0: for line in text.split('\n\n'): self.start_paragraph(style_name) + self.f.write('') line = line.replace('\n',' ') line = string.join(string.split(line)) self.write_text(line) + self.f.write('') self.end_paragraph() def write_text(self,text): @@ -295,4 +297,4 @@ class AbiWordDoc(BaseDoc.BaseDoc): def end_cell(self): self.f.write('\n') -Plugins.register_text_doc(_("AbiWord (version 1.9 or greater)"),AbiWordDoc,1,1,1,".abw") +Plugins.register_text_doc(_("AbiWord"),AbiWordDoc,1,1,1,".abw") diff --git a/gramps2/src/docgen/AbiWordDoc.py b/gramps2/src/docgen/AbiWordDoc.py deleted file mode 100644 index 29e2b276c..000000000 --- a/gramps2/src/docgen/AbiWordDoc.py +++ /dev/null @@ -1,359 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2003 Donald N. Allingham -# -# 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. -""" - -#------------------------------------------------------------------------- -# -# Imported Modules -# -#------------------------------------------------------------------------- -import os -import base64 -import string - -import BaseDoc -from latin_utf8 import latin_to_utf8 -import string -import Plugins -import ImgManip -import Errors -from gettext import gettext as _ - -#------------------------------------------------------------------------- -# -# Class Definitions -# -#------------------------------------------------------------------------- -class AbiWordDoc(BaseDoc.BaseDoc): - """AbiWord document generator. Inherits from the BaseDoc generic - document interface class.""" - - def __init__(self,styles,type,template,orientation): - """Initializes the AbiWordDoc class, calling the __init__ routine - of the parent BaseDoc class""" - BaseDoc.BaseDoc.__init__(self,styles,type,template,orientation) - self.f = None - self.level = 0 - self.new_page = 0 - self.in_table = 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) - - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('
\n') - - def close(self): - """Write the trailing information and closes the file""" - self.f.write('
\n') - if len(self.photo_list) > 0: - self.f.write('\n') - for file_tuple in self.photo_list: - file = file_tuple[0] - base = "%s/%s_png" % (os.path.dirname(file), - os.path.basename(file)) - tag = string.replace(base,'.','_') - - img = ImgManip.ImgManip(file) - buf = img.png_data() - - self.f.write('\n') - self.f.write(base64.encodestring(buf)) - self.f.write('\n') - self.f.write('\n') - - self.f.write('
\n') - self.f.close() - - def add_photo(self,name,pos,x_cm,y_cm): - - try: - image = ImgManip.ImgManip(name) - except: - return - (x,y) = image.size() - aspect_ratio = float(x)/float(y) - - 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 - - self.photo_list.append((name,act_width,act_height)) - - base = "/tmp/%s.png" % os.path.basename(name) - tag = string.replace(base,'.','_') - - self.f.write('' % act_height) - - def start_superscript(self): - self.text = self.text + '' - - def end_superscript(self): - self.text = self.text + '' - - def start_paragraph(self,style_name,leader=None): - if self.in_table: - self.start_paragraph_intable(style_name,leader) - else: - self.start_paragraph_notable(style_name,leader) - - def start_paragraph_notable(self,style_name,leader=None): - style = self.style_list[style_name] - self.current_style = style - self.f.write('

') - font = style.get_font() - self.f.write('') - if self.new_page == 1: - self.new_page = 0 - self.f.write('') - if leader != None: - self.f.write(leader) - self.f.write('\t') - - def start_paragraph_intable(self,style_name,leader=None): - style = self.style_list[style_name] - self.current_style = style - font = style.get_font() - self.cdata = '' - if self.new_page == 1: - self.new_page = 0 - self.f.write('') - - def page_break(self): - self.new_page = 1 - - def end_paragraph(self): - if self.in_table: - self.cdata = self.cdata + '\t' - else: - self.f.write('

\n') - - 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 = string.join(string.split(line)) - self.write_text(line) - self.end_paragraph() - - def write_text(self,text): - text = text.replace('&','&'); # Must be first - text = text.replace('<','<'); - text = text.replace('>','>'); - text = text.replace('<super>','') - text = text.replace('</super>','') - if self.in_table: - self.cdata = self.cdata + text - else: - self.f.write(text) - - def start_bold(self): - font = self.current_style.get_font() - self.f.write('') - - def end_bold(self): - font = self.current_style.get_font() - self.f.write('') - - def start_table(self,name,style_name): - self.in_table = 1 - self.tblstyle = self.table_styles[style_name] - - def end_table(self): - self.in_table = 0 - - def start_row(self): - self.tabs = [] - self.ledge = 0.0 - self.col = 0 - self.cdatalist = [] - - def end_row(self): - first = 0 - self.f.write(' 0: - self.f.write(' props="tabstops:') - for val,t in self.tabs: - if val == oldv: - if t == 'B0': - useb = 1 - continue - oldv = val - if not first: - first = 1 - else: - self.f.write(',') - edge = (val * self.get_usable_width()) - - if val == 1.0: - edge = edge-0.1 - elif val == 0.0: - edge = edge+0.1 - if useb: - t = 'B0' - self.f.write("%6.4fin/%s" % (edge/2.54,t)) - self.f.write('"') - self.f.write('>') - for data in self.cdatalist: - self.f.write(data) - self.f.write('

\n') - - def start_cell(self,style_name,span=1): - self.cstyle = self.cell_styles[style_name] - for i in range(self.col,self.col+span): - self.col = self.col + 1 - self.ledge = self.ledge + self.tblstyle.get_column_width(i) - self.tabs.append((self.ledge/100.0,"L")) - - def end_cell(self): - self.cdata = self.cdata + "
" - self.cdatalist.append(self.cdata) - -Plugins.register_text_doc(_("AbiWord (version 1.0.x)"),AbiWordDoc,1,1,1,".abw") diff --git a/gramps2/src/docgen/OpenOfficeDoc.py b/gramps2/src/docgen/OpenOfficeDoc.py index 704a03e18..33a65b090 100644 --- a/gramps2/src/docgen/OpenOfficeDoc.py +++ b/gramps2/src/docgen/OpenOfficeDoc.py @@ -112,6 +112,8 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): self.f.write('office:class="text" office:version="0.9">\n') self.f.write('\n') self.f.write('\n') + self.f.write('\n') self.f.write('') self.f.write('') self.f.write('\n') + self.f.write('') + self.f.write('') + self.f.write('\n') for style_name in self.draw_styles.keys(): style = self.draw_styles[style_name] @@ -686,9 +691,11 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): elif format == 0: for line in text.split('\n\n'): self.start_paragraph(style_name) + self.f.write('') line = line.replace('\n',' ') line = string.join(string.split(line)) self.write_text(line) + self.f.write('') self.end_paragraph() def write_text(self,text):