#
# 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
#
import BaseDoc
from latin_utf8 import latin_to_utf8
import time
import cStringIO
import gzip
import Errors
from TarFile import TarFile
import Plugins
import ImgManip
from gettext import gettext as _
def points(val):
inch = float(val)/2.54
return (int(inch*72))
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
class KwordDoc(BaseDoc.BaseDoc):
def open(self,filename):
self.photo_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()
if self.paper.name == "A3":
self.f.write('\n')
self.f.write('' % points(self.lmargin))
self.f.write('\n')
self.f.write('\n')
self.f.write('\n')
self.f.write('\n')
self.frameset_flg= 0
for p in self.photo_list:
self.f.write('\n')
self.f.write('\n')
self.f.write('\n')
for name in self.style_list.keys():
self.f.write('\n')
self.f.write('\n')
self.f.write('\n')
for file in self.photo_list:
self.f.write('\n' % a[0])
self.f.write('\n')
self.f.write('\n')
try:
tar = TarFile(self.filename)
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
tar.add_file("documentinfo.xml",self.mtime,self.m)
tar.add_file("maindoc.xml",self.mtime,self.f)
for file in self.photo_list:
f = open(file[0],"r")
tar.add_file(file[1],self.mtime,f)
f.close()
tar.close()
self.f.close()
self.m.close()
def start_page(self,orientation=None):
pass
def end_page(self):
pass
def start_paragraph(self,style_name,leader=None):
self.format_list = []
self.bold_start = 0
self.text = ""
self.style_name = style_name
self.p = self.style_list[self.style_name]
self.font = self.p.get_font()
if self.font.get_type_face() == BaseDoc.FONT_SERIF:
self.font_face = "Arial"
else:
self.font_face = "Times New Roman"
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.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.lmargin * 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.cell_col= self.cell_col + 1
self.frameset_flg= 0
self.cell_left= self.cell_right
def add_photo(self,name,pos,x_cm,y_cm):
im = ImgManip.ImgManip(name)
(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.photo_list)+1
tag = 'pictures/picture%d.jpeg' % index
self.photo_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 horizontal_line(self):
pass
def write_text(self,text):
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
Plugins.register_text_doc(_("KWord"),KwordDoc,1,1,1,".kwd")