Speed improvements to the HTML document interface
svn: r483
This commit is contained in:
parent
c99d7472a0
commit
39e8e7f792
@ -76,23 +76,30 @@ _bottom = [
|
|||||||
|
|
||||||
class HtmlDoc(TextDoc):
|
class HtmlDoc(TextDoc):
|
||||||
|
|
||||||
def __init__(self,styles,template):
|
def __init__(self,styles,template,source=None):
|
||||||
TextDoc.__init__(self,styles,PaperStyle("",0,0),None)
|
TextDoc.__init__(self,styles,PaperStyle("",0,0),None)
|
||||||
self.f = None
|
if source == None:
|
||||||
self.filename = None
|
self.f = None
|
||||||
self.template = template
|
self.filename = None
|
||||||
self.top = []
|
self.template = template
|
||||||
self.bottom = []
|
self.top = []
|
||||||
self.base = ""
|
self.bottom = []
|
||||||
|
self.base = ""
|
||||||
|
|
||||||
|
self.load_template()
|
||||||
|
else:
|
||||||
|
self.f = None
|
||||||
|
self.filename = source.filename
|
||||||
|
self.template = None
|
||||||
|
self.top = source.top
|
||||||
|
self.bottom = source.bottom
|
||||||
|
self.base = source.base
|
||||||
|
|
||||||
def open(self,filename):
|
def load_template(self):
|
||||||
|
|
||||||
start = re.compile(r"<!--\s*START\s*-->")
|
start = re.compile(r"<!--\s*START\s*-->")
|
||||||
stop = re.compile(r"<!--\s*STOP\s*-->")
|
stop = re.compile(r"<!--\s*STOP\s*-->")
|
||||||
|
|
||||||
top_add = 1
|
top_add = 1
|
||||||
bottom_add = 0
|
bottom_add = 0
|
||||||
|
|
||||||
if self.template and self.template != "":
|
if self.template and self.template != "":
|
||||||
try:
|
try:
|
||||||
templateFile = open(self.template,"r")
|
templateFile = open(self.template,"r")
|
||||||
@ -132,6 +139,9 @@ class HtmlDoc(TextDoc):
|
|||||||
self.bottom = _bottom
|
self.bottom = _bottom
|
||||||
self.top = _top
|
self.top = _top
|
||||||
|
|
||||||
|
def open(self,filename):
|
||||||
|
|
||||||
|
|
||||||
if filename[-5:] == ".html" or filename[-4:0] == ".htm":
|
if filename[-5:] == ".html" or filename[-4:0] == ".htm":
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
else:
|
else:
|
||||||
@ -140,21 +150,30 @@ 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")
|
||||||
|
|
||||||
|
need_start = 1
|
||||||
|
need_stop = 0
|
||||||
|
fl2txt = utils.fl2txt
|
||||||
for line in self.top:
|
for line in self.top:
|
||||||
match = t_one_line_re.match(line)
|
if need_start:
|
||||||
if match:
|
match = t_one_line_re.match(line)
|
||||||
m = match.groups()
|
if match:
|
||||||
self.f.write('%s<TITLE>%s</TITLE>%s\n' % (m[0],self.title,m[1]))
|
m = match.groups()
|
||||||
continue
|
self.f.write('%s<TITLE>%s</TITLE>%s\n' % (m[0],self.title,m[1]))
|
||||||
match = t_start_re.match(line)
|
need_start = 0
|
||||||
if match:
|
continue
|
||||||
m =match.groups()
|
match = t_start_re.match(line)
|
||||||
self.f.write('%s<TITLE>%s\n' % (m[0],self.title))
|
if match:
|
||||||
continue
|
m = match.groups()
|
||||||
if t_stop_re.match(line):
|
self.f.write('%s<TITLE>%s\n' % (m[0],self.title))
|
||||||
self.f.write('</TITLE>\n')
|
need_start = 0
|
||||||
continue
|
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(line)
|
||||||
|
|
||||||
self.f.write('<style type="text/css">\n<!--\n')
|
self.f.write('<style type="text/css">\n<!--\n')
|
||||||
@ -163,7 +182,7 @@ class HtmlDoc(TextDoc):
|
|||||||
|
|
||||||
self.f.write('.')
|
self.f.write('.')
|
||||||
self.f.write(key)
|
self.f.write(key)
|
||||||
pad = utils.fl2txt("%.3fcm ",style.get_padding())
|
pad = fl2txt("%.3fcm ",style.get_padding())
|
||||||
self.f.write(' { padding:' + pad + pad + pad + pad +'; ')
|
self.f.write(' { padding:' + pad + pad + pad + pad +'; ')
|
||||||
if style.get_top_border():
|
if style.get_top_border():
|
||||||
self.f.write('border-top:thin solid #000000; ')
|
self.f.write('border-top:thin solid #000000; ')
|
||||||
@ -201,11 +220,11 @@ class HtmlDoc(TextDoc):
|
|||||||
elif align == PARA_ALIGN_JUSTIFY:
|
elif align == PARA_ALIGN_JUSTIFY:
|
||||||
self.f.write('text-align:justify; ')
|
self.f.write('text-align:justify; ')
|
||||||
self.f.write('text-indent:%scm; ' % \
|
self.f.write('text-indent:%scm; ' % \
|
||||||
utils.fl2txt("%.2f",style.get_first_indent()))
|
fl2txt("%.2f",style.get_first_indent()))
|
||||||
self.f.write('margin-right:%scm; ' % \
|
self.f.write('margin-right:%scm; ' % \
|
||||||
utils.fl2txt("%.2f",style.get_right_margin()))
|
fl2txt("%.2f",style.get_right_margin()))
|
||||||
self.f.write('margin-left:%scm; ' % \
|
self.f.write('margin-left:%scm; ' % \
|
||||||
utils.fl2txt("%.2f",style.get_left_margin()))
|
fl2txt("%.2f",style.get_left_margin()))
|
||||||
if style.get_top_border():
|
if style.get_top_border():
|
||||||
self.f.write('border-top:thin solid #000000; ')
|
self.f.write('border-top:thin solid #000000; ')
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user