From 748bda0ea6e6595de7b4ad000c00216e98b51e72 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Fri, 8 Jun 2001 19:00:10 +0000 Subject: [PATCH] Changed leading text for a paragraph to be more general. Better KWord support. svn: r105 --- gramps/src/AbiWordDoc.py | 5 +- gramps/src/HtmlDoc.py | 7 ++- gramps/src/KwordDoc.py | 71 ++++++++++++++++++++-------- gramps/src/OpenOfficeDoc.py | 6 ++- gramps/src/PdfDoc.py | 26 ++++++++-- gramps/src/TextDoc.py | 2 +- gramps/src/plugins/AncestorReport.py | 3 +- 7 files changed, 87 insertions(+), 33 deletions(-) diff --git a/gramps/src/AbiWordDoc.py b/gramps/src/AbiWordDoc.py index 0cf939d85..49f9ddba8 100644 --- a/gramps/src/AbiWordDoc.py +++ b/gramps/src/AbiWordDoc.py @@ -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('

\n') - def start_paragraph(self,style_name): + def start_paragraph(self,style_name,leader=None): self.f.write('

') + if leader != None: + self.f.write(leader) + self.f.write(' ') def end_paragraph(self): if self.empty == 1: diff --git a/gramps/src/KwordDoc.py b/gramps/src/KwordDoc.py index 3835cf9f9..45b130269 100644 --- a/gramps/src/KwordDoc.py +++ b/gramps/src/KwordDoc.py @@ -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 = '\n' % len(leader) + txt = txt + '\n\n' % self.font_face + txt = txt + '\n' % len(leader) + txt = txt + '\n\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 = '\n\n\n' % self.font_face + self.format_list.append(txt) + self.f.write('\n') self.f.write('') self.f.write(latin_to_utf8(self.text)) self.f.write('\n') + old_pos = 0 + self.f.write('\n') + for format in self.format_list: + self.f.write(format) + self.f.write('\n') self.f.write('\n') self.f.write('\n' % self.style_name) - p = self.style_list[self.style_name] - - padding = p.get_padding() + padding = self.p.get_padding() self.f.write('\n' % sizes(padding)) - if p.get_alignment() == PARA_ALIGN_CENTER: + if self.p.get_alignment() == PARA_ALIGN_CENTER: self.f.write('\n') - elif p.get_alignment() == PARA_ALIGN_JUSTIFY: + elif self.p.get_alignment() == PARA_ALIGN_JUSTIFY: self.f.write('\n') - elif p.get_alignment() == PARA_ALIGN_RIGHT: + elif self.p.get_alignment() == PARA_ALIGN_RIGHT: self.f.write('\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('\n' % sizes(left)) - font = self.style_list[self.style_name].get_font() self.f.write('\n') - if font.get_type_face==FONT_SANS_SERIF: - self.f.write('\n') - else: - self.f.write('\n') - self.f.write('\n' % font.get_size()) - if font.get_bold(): + self.f.write('\n' % self.font_face) + self.f.write('\n' % self.font.get_size()) + if self.font.get_bold(): self.f.write('\n') - if font.get_italic(): + if self.font.get_italic(): self.f.write('\n') self.f.write('\n') if left != 0: @@ -313,10 +333,19 @@ class KwordDoc(TextDoc): self.f.write('\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 = '\n' % length + txt = txt + '\n\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 = '\n' % (self.bold_start,length) + txt = txt + '\n\n\n' % self.font_face + self.format_list.append(txt) def start_table(self,name,style_name): pass diff --git a/gramps/src/OpenOfficeDoc.py b/gramps/src/OpenOfficeDoc.py index b790b7b66..23b54af3f 100644 --- a/gramps/src/OpenOfficeDoc.py +++ b/gramps/src/OpenOfficeDoc.py @@ -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('') + if leader != None: + self.f.write(latin_to_utf8(leader)) + self.f.write('') def end_paragraph(self): if self.level == 0: @@ -425,7 +428,6 @@ class OpenOfficeDoc(TextDoc): self.f.write('\n') def write_text(self,text): - text = string.replace(text,'\t','') text = string.replace(text,'\n','') self.f.write(latin_to_utf8(text)) diff --git a/gramps/src/PdfDoc.py b/gramps/src/PdfDoc.py index 7d10c2de7..20dd0d584 100644 --- a/gramps/src/PdfDoc.py +++ b/gramps/src/PdfDoc.py @@ -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 = '%s' % leader self.image = 0 def end_paragraph(self): diff --git a/gramps/src/TextDoc.py b/gramps/src/TextDoc.py index 1d4ade44b..012b8112e 100644 --- a/gramps/src/TextDoc.py +++ b/gramps/src/TextDoc.py @@ -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): diff --git a/gramps/src/plugins/AncestorReport.py b/gramps/src/plugins/AncestorReport.py index 610c23064..1e458e629 100644 --- a/gramps/src/plugins/AncestorReport.py +++ b/gramps/src/plugins/AncestorReport.py @@ -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()