#
# 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
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
import Plugins
import Errors
import TextDoc
import DrawDoc
import const
import FontScale
from intl 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('\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)
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 = string.replace(text,'\t','')
text = string.replace(text,'\n','')
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 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
#
#-------------------------------------------------------------------------
Plugins.register_draw_doc(_("OpenOffice/StarOffice 6"),OpenDrawDoc,1,1,".sxd");