#
# 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
class AbiWordDoc(TextDoc):
def __init__(self,type,orientation):
TextDoc.__init__(self,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,'.','_')
cmd = "%s -size %dx%d %s %s" % (const.convert,width,height,file,base)
os.system(cmd)
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,name,x,y):
import GdkImlib
image = GdkImlib.Image(name)
scale = float(y)/float(image.rgb_height)
act_width = int(image.rgb_width * scale)
act_height = int(image.rgb_height * scale)
self.photo_list.append((name,act_width,act_height))
base = "/tmp/%s.png" % os.path.basename(name)
tag = string.replace(base,'.','_')
self.f.write('' % ((float(act_height)/72.0)/2.54))
def start_paragraph(self,style_name):
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('')
def page_break(self,orientation=None):
self.new_page = 1
def end_paragraph(self):
self.f.write('
\n')
def write_text(self,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('')
if __name__ == "__main__":
paper = PaperStyle("Letter",27.94,21.59)
doc = AbiWordDoc(paper,PAPER_PORTRAIT)
foo = FontStyle()
foo.set_type_face(FONT_SANS_SERIF)
foo.set_color((255,0,0))
foo.set_size(24)
para = ParagraphStyle()
doc.add_style("Normal",para)
doc.open("test")
doc.start_paragraph("Normal")
doc.add_photo("image.jpg",200,200)
doc.end_paragraph()
doc.close()