Speed up generation of web pages.

svn: r650
This commit is contained in:
David Hampton 2001-12-21 06:04:24 +00:00
parent 986b825786
commit e85e78fb6c
3 changed files with 111 additions and 113 deletions

View File

@ -40,9 +40,7 @@ try:
except: except:
no_pil = 1 no_pil = 1
t_one_line_re = re.compile(r"^(.*)<TITLE>.*</TITLE>(.*)$") t_header_line_re = re.compile(r"(.*)<TITLE>.*</TITLE>(.*)", re.DOTALL)
t_start_re = re.compile(r"^(.*)<TITLE>.*$")
t_stop_re = re.compile(r"^(.*)</TITLE>")
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -87,6 +85,9 @@ class HtmlDoc(TextDoc):
self.base = "" self.base = ""
self.load_template() self.load_template()
self.build_header()
self.build_style_declaration()
else: else:
self.f = None self.f = None
self.filename = source.filename self.filename = source.filename
@ -94,6 +95,10 @@ class HtmlDoc(TextDoc):
self.top = source.top self.top = source.top
self.bottom = source.bottom self.bottom = source.bottom
self.base = source.base self.base = source.base
self.file_header = source.file_header
self.style_declaration = source.style_declaration
self.table_styles = source.table_styles;
self.cell_styles = source.cell_styles;
def load_template(self): def load_template(self):
start = re.compile(r"<!--\s*START\s*-->") start = re.compile(r"<!--\s*START\s*-->")
@ -150,108 +155,85 @@ class HtmlDoc(TextDoc):
self.base = os.path.dirname(self.filename) self.base = os.path.dirname(self.filename)
self.f = open(self.filename,"w") self.f = open(self.filename,"w")
self.f.write(self.file_header % self.title)
self.f.write(self.style_declaration)
need_start = 1 def build_header(self):
need_stop = 0 top = string.join(self.top, "")
match = t_header_line_re.match(top)
if match:
m = match.groups()
self.file_header = '%s<TITLE>%%s</TITLE>%s\n' % (m[0],m[1])
else:
self.file_header = None
def build_style_declaration(self):
fl2txt = utils.fl2txt fl2txt = utils.fl2txt
for line in self.top: text = ['<style type="text/css">\n<!--']
if need_start:
match = t_one_line_re.match(line)
if match:
m = match.groups()
self.f.write('%s<TITLE>%s</TITLE>%s\n' % (m[0],self.title,m[1]))
need_start = 0
continue
match = t_start_re.match(line)
if match:
m = match.groups()
self.f.write('%s<TITLE>%s\n' % (m[0],self.title))
need_start = 0
need_stop = 1
continue
elif need_stop:
if t_stop_re.match(line):
self.f.write('</TITLE>\n')
need_stop = 0
continue
self.f.write(line)
self.f.write('<style type="text/css">\n<!--\n')
for key in self.cell_styles.keys(): for key in self.cell_styles.keys():
style = self.cell_styles[key] style = self.cell_styles[key]
self.f.write('.')
self.f.write(key)
pad = fl2txt("%.3fcm ",style.get_padding()) pad = fl2txt("%.3fcm ",style.get_padding())
self.f.write(' { padding:' + pad + pad + pad + pad +'; ') top = bottom = left = right = 'none'
if style.get_top_border(): if style.get_top_border():
self.f.write('border-top:thin solid #000000; ') top = 'thin solid #000000'
else:
self.f.write('border-top:none; ')
if style.get_bottom_border(): if style.get_bottom_border():
self.f.write('border-bottom:thin solid #000000; ') bottom = 'thin solid #000000'
else:
self.f.write('border-bottom:none; ')
if style.get_right_border():
self.f.write('border-right:thin solid #000000; ')
else:
self.f.write('border-right:none; ')
if style.get_left_border(): if style.get_left_border():
self.f.write('border-left:thin solid #000000 }\n') left = 'thin solid #000000'
else: if style.get_right_border():
self.f.write('border-left:none }\n') right = 'thin solid #000000'
text.append('.%s {\n' \
'\tpadding: %s %s %s %s;\n' \
'\tborder-top:%s; border-bottom:%s;\n' \
'\tborder-left:%s; border-right:%s;\n}' \
% (key, pad, pad, pad, pad, top, bottom, left, right))
for key in self.style_list.keys(): for key in self.style_list.keys():
style = self.style_list[key] style = self.style_list[key]
font = style.get_font() font = style.get_font()
self.f.write('.') font_size = font.get_size()
self.f.write(key) font_color = '#%02x%02x%02x' % font.get_color()
self.f.write(' { font-size:' + str(font.get_size()) + 'pt; ') align = style.get_alignment_text()
text_indent = fl2txt("%.2f",style.get_first_indent())
right_margin = fl2txt("%.2f",style.get_right_margin())
left_margin = fl2txt("%.2f",style.get_left_margin())
self.f.write('color:#%02x%02x%02x; ' % font.get_color()) top = bottom = left = right = 'none'
align = style.get_alignment()
if align == PARA_ALIGN_LEFT:
self.f.write('text-align:left; ')
elif align == PARA_ALIGN_CENTER:
self.f.write('text-align:center; ')
elif align == PARA_ALIGN_RIGHT:
self.f.write('text-align:right; ')
elif align == PARA_ALIGN_JUSTIFY:
self.f.write('text-align:justify; ')
self.f.write('text-indent:%scm; ' % \
fl2txt("%.2f",style.get_first_indent()))
self.f.write('margin-right:%scm; ' % \
fl2txt("%.2f",style.get_right_margin()))
self.f.write('margin-left:%scm; ' % \
fl2txt("%.2f",style.get_left_margin()))
if style.get_top_border(): if style.get_top_border():
self.f.write('border-top:thin solid #000000; ') top = 'thin solid #000000'
else:
self.f.write('border-top:none; ')
if style.get_bottom_border(): if style.get_bottom_border():
self.f.write('border-bottom:thin solid #000000; ') bottom = 'thin solid #000000'
else:
self.f.write('border-bottom:none; ')
if style.get_right_border():
self.f.write('border-right:thin solid #000000; ')
else:
self.f.write('border-right:none; ')
if style.get_left_border(): if style.get_left_border():
self.f.write('border-left:thin solid #000000; ') left = 'thin solid #000000'
else: if style.get_right_border():
self.f.write('border-left:none; ') right = 'thin solid #000000'
italic = bold = ''
if font.get_italic(): if font.get_italic():
self.f.write('font-style:italic; ') italic = 'font-style:italic; '
if font.get_bold(): if font.get_bold():
self.f.write('font-weight:bold; ') bold = 'font-weight:bold; '
if font.get_type_face() == FONT_SANS_SERIF: if font.get_type_face() == FONT_SANS_SERIF:
self.f.write('font-family:"Helvetica","Arial","sans-serif"}\n') family = '"Helvetica","Arial","sans-serif"'
else: else:
self.f.write('font-family:"Times New Roman","Times","serif"}\n') family = '"Times New Roman","Times","serif"'
text.append('.%s {\n' \
'\tfont-size: %dpt; color: %s;\n' \
'\ttext-align: %s; text-indent: %scm;\n' \
'\tmargin-right: %scm; margin-left: %scm;\n' \
'\tborder-top:%s; border-bottom:%s;\n' \
'\tborder-left:%s; border-right:%s;\n' \
'\t%s%sfont-family:%s;\n}' \
% (key, font_size, font_color,
align, text_indent,
right_margin, left_margin,
top, bottom, left, right,
italic, bold, family))
self.f.write('-->\n</style>\n') text.append('-->\n</style>')
self.style_declaration = string.join(text,'\n')
def close(self): def close(self):
for line in self.bottom: for line in self.bottom:

View File

@ -370,6 +370,17 @@ class ParagraphStyle:
def get_alignment(self): def get_alignment(self):
return self.align return self.align
def get_alignment_text(self):
if self.align == PARA_ALIGN_LEFT:
return "left"
elif self.align == PARA_ALIGN_CENTER:
return "center"
elif self.align == PARA_ALIGN_RIGHT:
return "right"
elif self.align == PARA_ALIGN_JUSTIFY:
return "justify"
return "unknown"
def set_left_margin(self,value): def set_left_margin(self,value):
"sets the left paragraph margin in centimeters" "sets the left paragraph margin in centimeters"
self.lmargin = value self.lmargin = value

View File

@ -86,22 +86,6 @@ class IndividualPage:
self.slist = [] self.slist = []
self.scnt = 1 self.scnt = 1
tbl = TableStyle()
tbl.set_width(100)
tbl.set_column_widths([15,85])
self.doc.add_table_style("IndTable",tbl)
cell = TableCellStyle()
self.doc.add_cell_style("NormalCell",cell)
cell = TableCellStyle()
cell.set_padding(0.2)
self.doc.add_cell_style("ImageCell",cell)
cell = TableCellStyle()
cell.set_padding(0.2)
self.doc.add_cell_style("NoteCell",cell)
name = person.getPrimaryName().getRegularName() name = person.getPrimaryName().getRegularName()
self.doc.set_title(_("Summary of %s") % name) self.doc.set_title(_("Summary of %s") % name)
@ -743,6 +727,9 @@ class WebReport(Report):
self.progress_bar_setup(float(len(ind_list))) self.progress_bar_setup(float(len(ind_list)))
doc = HtmlLinkDoc(self.selected_style,self.template_name) doc = HtmlLinkDoc(self.selected_style,self.template_name)
self.add_styles(doc)
doc.build_style_declaration()
my_map = {} my_map = {}
for l in ind_list: for l in ind_list:
my_map[l] = 1 my_map[l] = 1
@ -762,6 +749,24 @@ class WebReport(Report):
self.progress_bar_done() self.progress_bar_done()
def add_styles(self,doc):
tbl = TableStyle()
tbl.set_width(100)
tbl.set_column_widths([15,85])
doc.add_table_style("IndTable",tbl)
cell = TableCellStyle()
doc.add_cell_style("NormalCell",cell)
cell = TableCellStyle()
cell.set_padding(0.2)
doc.add_cell_style("ImageCell",cell)
cell = TableCellStyle()
cell.set_padding(0.2)
doc.add_cell_style("NoteCell",cell)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# #