From 3f6c2b23ef14e926a33696fc1d54aae42c4c5875 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Tue, 16 Sep 2003 03:33:05 +0000 Subject: [PATCH] * src/docgen/OpenOfficeDoc.py: set z-index properly for paths so they appear over text, fix font for draw_text svn: r2136 --- src/docgen/OpenDrawDoc.py | 611 ------------------------------------ src/docgen/OpenOfficeDoc.py | 33 +- 2 files changed, 14 insertions(+), 630 deletions(-) delete mode 100644 src/docgen/OpenDrawDoc.py diff --git a/src/docgen/OpenDrawDoc.py b/src/docgen/OpenDrawDoc.py deleted file mode 100644 index 558df27df..000000000 --- a/src/docgen/OpenDrawDoc.py +++ /dev/null @@ -1,611 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000 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 -# - -#------------------------------------------------------------------------- -# -# python modules -# -#------------------------------------------------------------------------- -import os -import tempfile -import string -import zipfile -from math import sin, cos, pi, fabs - -#------------------------------------------------------------------------- -# -# Gramps modules -# -#------------------------------------------------------------------------- -import Plugins -import Errors -import TextDoc -import DrawDoc -import const -import FontScale - -from gettext import gettext as _ - -#------------------------------------------------------------------------- -# -# OpenDrawDoc -# -#------------------------------------------------------------------------- -class OpenDrawDoc(DrawDoc.DrawDoc): - - def __init__(self,styles,type,orientation): - DrawDoc.DrawDoc.__init__(self,styles,type,orientation) - self.f = None - self.filename = None - self.level = 0 - self.time = "0000-00-00T00:00:00" - self.page = 0 - - def open(self,filename): - import time - - 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:] != ".sxd": - self.filename = filename + ".sxd" - else: - self.filename = filename - - try: - self.content_xml = tempfile.mktemp() - self.f = open(self.content_xml,"wb") - 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') - 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('\n') - self.f.write('\n') - self.f.write('\n') - for key in self.style_list.keys(): - style = self.style_list[key] - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - - def close(self): - self.f.write('\n') - self.f.write('\n') - self.f.close() - try: - self._write_styles_file() - self._write_manifest() - self._write_meta_file() - self._write_zip() - except: - raise Errors.ReportError("Could not create %s" % self.filename) - - print self.print_req - if self.print_req: - os.environ["FILE"] = self.filename - os.system ('/usr/bin/oodraw "$FILE" &') - - def _write_zip(self): - - file = zipfile.ZipFile(self.filename,"w",zipfile.ZIP_DEFLATED) - file.write(self.manifest_xml,"META-INF/manifest.xml") - file.write(self.content_xml,"content.xml") - file.write(self.meta_xml,"meta.xml") - file.write(self.styles_xml,"styles.xml") - file.close() - - os.unlink(self.manifest_xml) - os.unlink(self.content_xml) - os.unlink(self.meta_xml) - os.unlink(self.styles_xml) - - def _write_styles_file(self): - self.styles_xml = tempfile.mktemp() - self.f = open(self.styles_xml,"wb") - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - - self.f.write('\n') - self.f.write('svg:stroke-width="0cm" ') - self.f.write('svg:stroke-color="#000000" ') - self.f.write('draw:marker-start-width="0.3cm" ') - self.f.write('draw:marker-start-center="false" ') - self.f.write('draw:marker-end-width="0.3cm" ') - self.f.write('draw:marker-end-center="false" ') - self.f.write('draw:fill="solid" ') - self.f.write('draw:fill-color="#00b8ff" ') - self.f.write('draw:shadow="hidden" ') - self.f.write('draw:shadow-offset-x="0.3cm" ') - self.f.write('draw:shadow-offset-y="0.3cm" ') - self.f.write('draw:shadow-color="#808080" ') - self.f.write('fo:color="#000000" ') - self.f.write('style:text-outline="false" ') - self.f.write('style:text-crossing-out="none" ') - self.f.write('fo:font-family="'Times New Roman'" ') - self.f.write('style:font-style-name="" ') - self.f.write('style:font-family-generic="roman" ') - self.f.write('style:font-pitch="variable" ') - self.f.write('fo:font-size="24pt" ') - self.f.write('fo:font-style="normal" ') - self.f.write('fo:text-shadow="none" ') - self.f.write('style:text-underline="none" ') - self.f.write('fo:font-weight="normal" ') - self.f.write('fo:line-height="100%" ') - self.f.write('fo:text-align="start" ') - self.f.write('text:enable-numbering="false" ') - self.f.write('fo:margin-left="0cm" ') - self.f.write('fo:margin-right="0cm" ') - self.f.write('fo:text-indent="0cm" ') - self.f.write('fo:margin-top="0cm" ') - self.f.write('fo:margin-bottom="0cm"/>\n') - self.f.write('\n') - - for style_name in self.draw_styles.keys(): - style = self.draw_styles[style_name] - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - - self.f.write('\n') - for key in self.style_list.keys(): - style = self.style_list[key] - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - - # Current no leading number format for headers - - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n' % self.rmargin) - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.close() - - def start_paragraph(self,style_name): - self.f.write('' % style_name) - - def end_paragraph(self): - self.f.write('\n') - - def write_text(self,text): - text = text.replace('&','&'); # Must be first - text = text.replace('<','<'); - text = text.replace('>','>'); - text = text.replace('\t','') - text = text.replace('\n','') - text = text.replace('<super>','') - text = text.replace('</super>','') - self.f.write(text) - - def _write_manifest(self): - self.manifest_xml = tempfile.mktemp() - self.f = open(self.manifest_xml,"wb") - self.f.write('\n') - self.f.write('') - self.f.write('') - self.f.write('') - self.f.write('') - self.f.write('') - self.f.write('') - #self.f.write('') - self.f.write('\n') - self.f.close() - - def _write_meta_file(self): - name = self.name - self.meta_xml = tempfile.mktemp() - self.f = open(self.meta_xml,"wb") - self.f.write('\n') - self.f.write('\n'); - self.f.write('\n') - self.f.write('') - self.f.write(const.progName + ' ' + const.version) - self.f.write('\n') - self.f.write('') - self.f.write(name) - self.f.write('\n') - self.f.write('') - self.f.write(self.time) - self.f.write('\n') - self.f.write('') - self.f.write(name) - self.f.write('\n') - self.f.write('') - self.f.write(self.time) - self.f.write('\n') - self.f.write('0-00-00T00:00:00\n') - self.f.write('en-US\n') - self.f.write('1\n') - self.f.write('PT0S\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.write('\n') - self.f.close() - - def start_page(self,orientation=None): - self.page = self.page + 1 - self.f.write('\n') - - def end_page(self): - self.f.write('\n') - - def rotate_text(self,style,text,x,y,angle): - - stype = self.draw_styles[style] - pname = stype.get_paragraph_style() - p = self.style_list[pname] - font = p.get_font() - size = font.get_size() - - height = size*(len(text)) - 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.f.write('') - self.f.write('' % pname) - self.write_text(string.join(text,'\n')) - self.f.write('\n') - - def draw_path(self,style,path): - stype = self.draw_styles[style] - - 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.f.write('\n') - - def draw_line(self,style,x1,y1,x2,y2): - x1 = x1 + self.lmargin - x2 = x2 + self.lmargin - y1 = y1 + self.tmargin - y2 = y2 + self.tmargin - box_style = self.draw_styles[style] - - self.f.write('\n') - - def draw_text(self,style,text,x,y): - x = x + self.lmargin - y = y + self.tmargin - box_style = self.draw_styles[style] - para_name = box_style.get_paragraph_style() - - pstyle = self.style_list[para_name] - font = pstyle.get_font() - sw = FontScale.string_width(font,text)*1.3 - - self.f.write('' % float(y)) - self.f.write('') - self.f.write('' % para_name) - self.f.write(text) - self.f.write('') - self.f.write('\n') - - def draw_bar(self,style,x,y,x2,y2): - x = x + self.lmargin - x2 = x2 + self.lmargin - y = y + self.tmargin - y2 = y2 + self.tmargin - - box_style = self.draw_styles[style] - para_name = box_style.get_paragraph_style() - - self.f.write('' % float(y)) - self.f.write('\n') - - def draw_box(self,style,text,x,y): - x = x + self.lmargin - y = y + self.tmargin - box_style = self.draw_styles[style] - para_name = box_style.get_paragraph_style() - - self.f.write('') - text = string.replace(text,'\n','') - self.f.write('>\n') - self.f.write('') - self.f.write('' % para_name) - self.f.write(text) - self.f.write('\n') - self.f.write('\n') - else: - self.f.write('/>\n') - -#------------------------------------------------------------------------- -# -# Register document generator -# -#------------------------------------------------------------------------- -print_label = None -if os.access ("/usr/bin/oodraw", os.X_OK): - print_label = _("Open in OpenOffice.org") - -Plugins.register_draw_doc(_("OpenOffice.org Draw"),OpenDrawDoc,1,1,".sxd", - print_label); diff --git a/src/docgen/OpenOfficeDoc.py b/src/docgen/OpenOfficeDoc.py index a30185c62..fad69fcf7 100644 --- a/src/docgen/OpenOfficeDoc.py +++ b/src/docgen/OpenOfficeDoc.py @@ -387,9 +387,8 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): else: self.f.write('\n') def start_table(self,name,style_name): - self.f.write('\n' % style_name) + self.f.write('\n' % style_name) table = self.table_styles[style_name] for col in range(0,table.get_columns()): self.f.write(' 1: self.f.write(' table:number-columns-spanned="%s">\n' % span) else: @@ -442,7 +439,6 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): self.f.write('') def _write_zip(self): - file = zipfile.ZipFile(self.filename,"w",zipfile.ZIP_DEFLATED) file.write(self.manifest_xml,str("META-INF/manifest.xml")) file.write(self.content_xml,str("content.xml")) @@ -801,12 +797,12 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): maxy = max(point[1],maxy) self.f.write('' % float(y)) - self.f.write('') - self.f.write('' % para_name) + self.f.write('' % para_name) + self.f.write('' % para_name) self.f.write(text) self.f.write('') self.f.write('\n')