Changed leading text for a paragraph to be more general. Better KWord support.

svn: r105
This commit is contained in:
Don Allingham 2001-06-08 19:00:10 +00:00
parent 727f03d995
commit 748bda0ea6
7 changed files with 87 additions and 33 deletions

View File

@ -123,7 +123,7 @@ class AbiWordDoc(TextDoc):
self.f.write('" props="width:%sin; ' % width)
self.f.write('height:%sin"/>' % height)
def start_paragraph(self,style_name):
def start_paragraph(self,style_name,leader=None):
style = self.style_list[style_name]
self.current_style = style
self.f.write('<p props="')
@ -163,6 +163,9 @@ class AbiWordDoc(TextDoc):
if self.new_page == 1:
self.new_page = 0
self.f.write('<pbr/>')
if leader != None:
self.f.write(leader)
self.f.write('\t')
def page_break(self,orientation=None):
self.new_page = 1

View File

@ -73,9 +73,11 @@ class HtmlDoc(TextDoc):
top_add = 1
bottom_add = 0
print "Template name is",self.template
if self.template and self.template != "":
try:
templateFile = open(self.template,"r")
print "template opened"
for line in templateFile.readlines():
if top_add == 1:
self.top.append(line)
@ -220,8 +222,11 @@ class HtmlDoc(TextDoc):
def end_cell(self):
self.f.write('</td>\n')
def start_paragraph(self,style_name):
def start_paragraph(self,style_name,leader=None):
self.f.write('<p class="' + style_name + '">')
if leader != None:
self.f.write(leader)
self.f.write(' ')
def end_paragraph(self):
if self.empty == 1:

View File

@ -260,34 +260,58 @@ class KwordDoc(TextDoc):
def end_page(self):
pass
def start_paragraph(self,style_name):
def start_paragraph(self,style_name,leader=None):
self.format_list = []
self.bold_start = 0
self.text = ""
self.style_name = style_name
pass
self.p = self.style_list[self.style_name]
self.font = self.p.get_font()
if self.font.get_type_face() == FONT_SERIF:
self.font_face = "times"
else:
self.font_face = "helvetica"
if leader != None:
self.text = leader + chr(1)
txt = '<FORMAT id="1" pos="0" len="%d">\n' % len(leader)
txt = txt + '<FONT name="%s"/>\n</FORMAT>\n' % self.font_face
txt = txt + '<FORMAT id="3" pos="%d">\n' % len(leader)
txt = txt + '<FONT name="%s"/>\n</FORMAT>\n' % self.font_face
self.format_list.append(txt)
self.bold_stop = len(self.text)
def end_paragraph(self):
if self.bold_start != 0 and self.bold_stop != len(self.text):
txt = '<FORMAT>\n<FONT name="%s"/>\n</FORMAT>\n' % self.font_face
self.format_list.append(txt)
self.f.write('<PARAGRAPH>\n')
self.f.write('<TEXT>')
self.f.write(latin_to_utf8(self.text))
self.f.write('</TEXT>\n')
old_pos = 0
self.f.write('<FORMATS>\n')
for format in self.format_list:
self.f.write(format)
self.f.write('</FORMATS>\n')
self.f.write('<LAYOUT>\n')
self.f.write('<NAME value="%s"/>\n' % self.style_name)
p = self.style_list[self.style_name]
padding = p.get_padding()
padding = self.p.get_padding()
self.f.write('<OFOOT pt="%d" mm="%s" inch="%s"/>\n' % sizes(padding))
if p.get_alignment() == PARA_ALIGN_CENTER:
if self.p.get_alignment() == PARA_ALIGN_CENTER:
self.f.write('<FLOW value="2">\n')
elif p.get_alignment() == PARA_ALIGN_JUSTIFY:
elif self.p.get_alignment() == PARA_ALIGN_JUSTIFY:
self.f.write('<FLOW value="3">\n')
elif p.get_alignment() == PARA_ALIGN_RIGHT:
elif self.p.get_alignment() == PARA_ALIGN_RIGHT:
self.f.write('<FLOW value="1">\n')
first = p.get_first_indent()
right = p.get_right_margin()
left = p.get_left_margin()
first = self.p.get_first_indent()
right = self.p.get_right_margin()
left = self.p.get_left_margin()
first = left+first
if first != 0:
@ -295,16 +319,12 @@ class KwordDoc(TextDoc):
if left != 0:
self.f.write('<ILEFT pt="%d" mm="%s" inch="%s"/>\n' % sizes(left))
font = self.style_list[self.style_name].get_font()
self.f.write('<FORMAT>\n')
if font.get_type_face==FONT_SANS_SERIF:
self.f.write('<FONT name="helvetica"/>\n')
else:
self.f.write('<FONT name="times"/>\n')
self.f.write('<SIZE value="%d"/>\n' % font.get_size())
if font.get_bold():
self.f.write('<FONT name="%s"/>\n' % self.font_face)
self.f.write('<SIZE value="%d"/>\n' % self.font.get_size())
if self.font.get_bold():
self.f.write('<WEIGHT value="75"/>\n')
if font.get_italic():
if self.font.get_italic():
self.f.write('<ITALIC value="1"/>\n')
self.f.write('</FORMAT>\n')
if left != 0:
@ -313,10 +333,19 @@ class KwordDoc(TextDoc):
self.f.write('</PARAGRAPH>\n')
def start_bold(self):
pass
self.bold_start = len(self.text)
if self.bold_stop != self.bold_start:
length = self.bold_stop - self.bold_start
txt = '<FORMAT id="1" pos="0" len="%d">\n' % length
txt = txt + '<FONT name="%s"/>\n</FORMAT>\n' % self.font_face
self.format_list.append(txt)
def end_bold(self):
pass
self.bold_stop = len(self.text)
length = self.bold_stop - self.bold_start
txt = '<FORMAT id="1" pos="%d" len="%d">\n' % (self.bold_start,length)
txt = txt + '<FONT name="%s"/>\n<WEIGHT value="75"/>\n</FORMAT>\n' % self.font_face
self.format_list.append(txt)
def start_table(self,name,style_name):
pass

View File

@ -403,7 +403,7 @@ class OpenOfficeDoc(TextDoc):
def page_break(self):
self.new_page = 1
def start_paragraph(self,style_name):
def start_paragraph(self,style_name,leader=None):
style = self.style_list[style_name]
self.level = style.get_header_level()
if self.new_page == 1:
@ -417,6 +417,9 @@ class OpenOfficeDoc(TextDoc):
self.f.write('<text:h text:style-name="')
self.f.write(name)
self.f.write('" text:level="' + str(self.level) + '">')
if leader != None:
self.f.write(latin_to_utf8(leader))
self.f.write('<text:tab-stop/>')
def end_paragraph(self):
if self.level == 0:
@ -425,7 +428,6 @@ class OpenOfficeDoc(TextDoc):
self.f.write('</text:h>\n')
def write_text(self,text):
text = string.replace(text,'\t','<text:tab-stop/>')
text = string.replace(text,'\n','<text:line-break/>')
self.f.write(latin_to_utf8(text))

View File

@ -75,6 +75,8 @@ class PdfDoc(TextDoc):
pdf_style = reportlab.lib.styles.ParagraphStyle(name=style_name)
pdf_style.fontSize = font.get_size()
pdf_style.bulletFontSize = font.get_size()
if font.get_type_face() == FONT_SERIF:
if font.get_bold():
pdf_style.fontName = "Times-Bold"
@ -85,9 +87,20 @@ class PdfDoc(TextDoc):
pdf_style.fontName = "Helvetica-Bold"
else:
pdf_style.fontName = "Helvetica"
pdf_style.rightIndent = style.get_right_margin()*cm
pdf_style.leftIndent = style.get_left_margin()*cm
pdf_style.firstLineIndent = style.get_first_indent()*cm
pdf_style.bulletFontName = pdf_style.fontName
right = style.get_right_margin()*cm
left = style.get_left_margin()*cm
first = left + style.get_first_indent()*cm
pdf_style.rightIndent = right
pdf_style.leftIndent = left
pdf_style.firstLineIndent = first
pdf_style.bulletIndent = first
print first,left
align = style.get_alignment()
if align == PARA_ALIGN_RIGHT:
pdf_style.alignment = TA_RIGHT
@ -114,10 +127,13 @@ class PdfDoc(TextDoc):
def end_page(self):
self.story.append(PageBreak())
def start_paragraph(self,style_name):
def start_paragraph(self,style_name,leader=None):
self.current_para = self.pdfstyles[style_name]
self.my_para = self.style_list[style_name]
self.text = ""
if leader==None:
self.text = ''
else:
self.text = '<bullet>%s</bullet>' % leader
self.image = 0
def end_paragraph(self):

View File

@ -609,7 +609,7 @@ class TextDoc:
def end_bold(self):
pass
def start_paragraph(self,style_name):
def start_paragraph(self,style_name,leader=None):
pass
def end_paragraph(self):

View File

@ -152,11 +152,10 @@ class AncestorReport:
self.doc.end_paragraph()
generation = generation + 1
self.doc.start_paragraph("Entry")
self.doc.start_paragraph("Entry","%s." % str(key))
person = self.map[key]
name = person.getPrimaryName().getRegularName()
self.doc.write_text(str(key) + ".\t")
self.doc.start_bold()
self.doc.write_text(name)
self.doc.end_bold()