# # 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 tempfile import string import Plugins import intl _ = intl.gettext from TextDoc import * from DrawDoc import * class HtmlDrawDoc(DrawDoc): def __init__(self,styles,type,orientation): 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 translate(self,x,y): return (x,self.height-y) def fontdef(self,para): font = para.get_font() if font.get_type_face() == FONT_SERIF: if font.get_bold(): if font.get_italic(): font_name = "Times" font_style = "italic" font_weight = "bold" else: font_name = "Times" font_style = "normal" font_weight = "bold" else: if font.get_italic(): font_name = "Times" font_style = "italic" font_weight = "normal" else: font_name = "Times" font_style = "normal" font_weight = "normal" else: if font.get_bold(): if font.get_italic(): font_name = "Helvetica-BoldOblique" font_style = "oblique" font_weight = "bold" else: font_name = "Helvetica-Bold" font_style = "normal" font_weight = "bold" else: if font.get_italic(): font_name = "Helvetica-Oblique" font_style = "oblique" font_weight = "normal" else: font_name = "Helvetica" font_style = "normal" font_weight = "normal" return "\n" % (font_name,font.get_size(),font_style,font_weight) def open(self,filename): if filename[-5:] != ".html": self.filename = filename + ".html" else: self.filename = filename self.f = open(filename,"w") self.f.write('\n') self.f.write('
\n') self.f.write('Report\n') self.f.write('\n') def close(self): self.f.write('\n') self.f.write('\n') self.f.close() def start_paragraph(self,style_name): pass def end_paragraph(self): pass def write_text(self,text): pass def start_page(self,orientation=None): self.page = self.page + 1 def end_page(self): pass def draw_line(self,style,x1,y1,x2,y2): line_height = y2 - y1 line_width = x2 - x1 line_top = y1 if y1 > y2: line_top = y2 if y2 > y1: line_top = y1 if y1 == y2: self.f.write('
' %x1) if x1 == x2: self.f.write('
' %x1) self.f.write('
\n') def draw_box(self,style,text,x,y): box_style = self.draw_styles[style] para_name = box_style.get_paragraph_style() p = self.style_list[para_name] bh = box_style.get_height() bw = box_style.get_width() self.f.write('
\n' % x) if text != "": self.f.write(self.fontdef(p)) lines = string.split(text,'\n') nlines = len(lines) for i in range(nlines): self.f.write("%s
\n" % lines[i]) self.f.write('
\n') self.f.write(' 
\n') Plugins.register_draw_doc(_("HTML"),HtmlDrawDoc);