#
# 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
#
import os
import base64
from TextDoc import *
from latin_utf8 import latin_to_utf8
import const
import string
import utils
cnv = utils.fl2txt
try:
import PIL.Image
no_pil = 0
except:
no_pil = 1
class AbiWordDoc(TextDoc):
def __init__(self,styles,type,orientation):
TextDoc.__init__(self,styles,type,orientation)
self.f = None
self.level = 0
self.new_page = 0
def open(self,filename):
if filename[-4:] != ".abw":
self.filename = "%s.abw" % filename
else:
self.filename = filename
self.f = open(self.filename,"w")
self.f.write('\n')
self.f.write('\n')
self.f.write('\n')
self.f.write('\n')
def close(self):
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]
width = file_tuple[1]
height = file_tuple[2]
base = "/tmp/%s.png" % os.path.basename(file)
tag = string.replace(base,'.','_')
if no_pil:
cmd = "%s -geometry %dx%d '%s' '%s'" % (const.convert,width,height,file,base)
os.system(cmd)
else:
im = PIL.Image.open(file)
im.thumbnail((width,height))
im.save(base,"PNG")
self.f.write('\n')
f = open(base,"rb")
base64.encode(f,self.f)
f.close()
os.unlink(base)
self.f.write('\n')
self.f.write('\n')
self.f.write('\n')
self.f.close()
def add_photo(self,pos,name,x_cm,y_cm):
import gtk
import GdkImlib
image = GdkImlib.Image(name)
scale = float(image.rgb_width)/float(image.rgb_height)
act_width = int(((x_cm * scale)*2.54)*72)
act_height = int(((y_cm * scale)*2.54)*72)
self.photo_list.append((name,act_width,act_height))
base = "/tmp/%s.png" % os.path.basename(name)
tag = string.replace(base,'.','_')
self.f.write('' % height)
def start_paragraph(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 page_break(self):
self.new_page = 1
def end_paragraph(self):
self.f.write('
\n')
def write_text(self,text):
text = string.replace(text,'&','&'); # Must be first
text = string.replace(text,'<','<');
text = string.replace(text,'>','>');
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('')