From fc3d17f1df90c15715f0e2ec28175c804d6a7b2e Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Tue, 14 Feb 2012 23:14:57 +0000 Subject: [PATCH] 5326: Add table of contents and index support for ODF documents svn: r18887 --- src/gen/plug/report/_options.py | 4 +- src/plugins/docgen/ODFDoc.py | 75 +++++++++++++++++++++ src/plugins/docgen/PdfDoc.py | 14 ++-- src/plugins/textreport/AlphabeticalIndex.py | 12 ++-- src/plugins/textreport/TableOfContents.py | 15 ++--- src/plugins/textreport/textplugins.gpr.py | 8 +-- 6 files changed, 99 insertions(+), 29 deletions(-) diff --git a/src/gen/plug/report/_options.py b/src/gen/plug/report/_options.py index ef70769ae..e2e0cb08a 100644 --- a/src/gen/plug/report/_options.py +++ b/src/gen/plug/report/_options.py @@ -772,10 +772,12 @@ class ReportOptions(_options.Options): FTA- FTM Style Ancestral report FTD- FTM Style Descendant report IDS- Individual Complete Report + IDX- Alphabetical Index IVS- Individual Summary Report PLC- Place Report - SBT- Simple Boot Title + SBT- Simple Book Title TLG- Timeline Graph + TOC- Table Of Contents """ pass diff --git a/src/plugins/docgen/ODFDoc.py b/src/plugins/docgen/ODFDoc.py index 200e661e9..1daeb3625 100644 --- a/src/plugins/docgen/ODFDoc.py +++ b/src/plugins/docgen/ODFDoc.py @@ -1609,6 +1609,81 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): self.cntnt.write(text) + def insert_toc(self): + """ + Insert a Table of Contents at this point in the document. + """ + title = _('Contents') + self.cntnt.write('') + + self.cntnt.write('') + + self.cntnt.write('' + title) + self.cntnt.write('') + + for level in range(1, 4): + self.cntnt.write('' % level) + + self.cntnt.write('') + self.cntnt.write('') + self.cntnt.write('') + self.cntnt.write('') + self.cntnt.write('') + + self.cntnt.write('') + + self.cntnt.write('') + self.cntnt.write('') + self.cntnt.write('%s' % + title) + self.cntnt.write('') + self.cntnt.write('') + + self.cntnt.write('') + + def insert_index(self): + """ + Insert an Alphabetical Index at this point in the document. + """ + title = _('Index') + self.cntnt.write('') + self.cntnt.write('') + + self.cntnt.write('' + title) + self.cntnt.write('') + + self.cntnt.write('') + self.cntnt.write('') + self.cntnt.write('') + self.cntnt.write('') + self.cntnt.write('') + + self.cntnt.write('') + + self.cntnt.write('') + self.cntnt.write('') + self.cntnt.write('%s' % + title) + self.cntnt.write('') + self.cntnt.write('') + + self.cntnt.write('') + def _write_manifest(self): """ create the manifest.xml file diff --git a/src/plugins/docgen/PdfDoc.py b/src/plugins/docgen/PdfDoc.py index ef95c4b24..8db4b3ea8 100644 --- a/src/plugins/docgen/PdfDoc.py +++ b/src/plugins/docgen/PdfDoc.py @@ -248,7 +248,7 @@ def write_toc(toc, doc): doc.end_paragraph() doc.end_cell() doc.start_cell('TOC-Cell') - doc.start_paragraph('TOC-Number') + doc.start_paragraph(style_name) doc.write_text(str(page_nr)) doc.end_paragraph() doc.end_cell() @@ -262,20 +262,20 @@ def write_index(index, doc): if not index: return - doc.start_paragraph('Index-Title') + doc.start_paragraph('IDX-Title') doc.write_text(_('Index')) doc.end_paragraph() - doc.start_table('index', 'Index-Table') + doc.start_table('index', 'IDX-Table') for key in sorted(index.iterkeys()): doc.start_row() - doc.start_cell('Index-Cell') - doc.start_paragraph('Index-Number') + doc.start_cell('IDX-Cell') + doc.start_paragraph('IDX-Entry') doc.write_text(key) doc.end_paragraph() doc.end_cell() - doc.start_cell('Index-Cell') - doc.start_paragraph('Index-Number') + doc.start_cell('IDX-Cell') + doc.start_paragraph('IDX-Entry') pages = [str(page_nr) for page_nr in index[key]] doc.write_text(', '.join(pages)) doc.end_paragraph() diff --git a/src/plugins/textreport/AlphabeticalIndex.py b/src/plugins/textreport/AlphabeticalIndex.py index 83aab8b04..307fa04f3 100644 --- a/src/plugins/textreport/AlphabeticalIndex.py +++ b/src/plugins/textreport/AlphabeticalIndex.py @@ -87,22 +87,22 @@ class AlphabeticalIndexOptions(MenuReportOptions): para = ParagraphStyle() para.set_font(font) para.set_bottom_margin(0.25) - para.set_description(_('The style used for the Index title.')) - default_style.add_paragraph_style("Index-Title", para) + para.set_description(_('The style used for the title.')) + default_style.add_paragraph_style("IDX-Title", para) table = TableStyle() table.set_width(100) table.set_columns(2) table.set_column_width(0, 80) table.set_column_width(1, 20) - default_style.add_table_style("Index-Table", table) + default_style.add_table_style("IDX-Table", table) cell = TableCellStyle() - default_style.add_cell_style("Index-Cell", cell) + default_style.add_cell_style("IDX-Cell", cell) font = FontStyle() font.set(face=FONT_SANS_SERIF, size=10) para = ParagraphStyle() para.set_font(font) - para.set_description(_('The style used for the Index page numbers.')) - default_style.add_paragraph_style("Index-Number", para) + para.set_description(_('The style used for index entries.')) + default_style.add_paragraph_style("IDX-Entry", para) diff --git a/src/plugins/textreport/TableOfContents.py b/src/plugins/textreport/TableOfContents.py index 2fccab290..2c9f09c28 100644 --- a/src/plugins/textreport/TableOfContents.py +++ b/src/plugins/textreport/TableOfContents.py @@ -87,7 +87,7 @@ class TableOfContentsOptions(MenuReportOptions): para = ParagraphStyle() para.set_font(font) para.set_bottom_margin(0.25) - para.set_description(_('The style used for the TOC title.')) + para.set_description(_('The style used for the title.')) default_style.add_paragraph_style("TOC-Title", para) table = TableStyle() @@ -100,26 +100,19 @@ class TableOfContentsOptions(MenuReportOptions): cell = TableCellStyle() default_style.add_cell_style("TOC-Cell", cell) - font = FontStyle() - font.set(face=FONT_SANS_SERIF, size=10) para = ParagraphStyle() para.set_font(font) - para.set_description(_('The style used for the TOC page numbers.')) - default_style.add_paragraph_style("TOC-Number", para) - - para = ParagraphStyle() - para.set_font(font) - para.set_description(_('The style used for the TOC first level heading.')) + para.set_description(_('The style used for first level headings.')) default_style.add_paragraph_style("TOC-Heading1", para) para = ParagraphStyle() para.set_font(font) para.set_first_indent(0.5) - para.set_description(_('The style used for the TOC second level heading.')) + para.set_description(_('The style used for second level headings.')) default_style.add_paragraph_style("TOC-Heading2", para) para = ParagraphStyle() para.set_font(font) para.set_first_indent(1) - para.set_description(_('The style used for the TOC third level heading.')) + para.set_description(_('The style used for third level headings.')) default_style.add_paragraph_style("TOC-Heading3", para) diff --git a/src/plugins/textreport/textplugins.gpr.py b/src/plugins/textreport/textplugins.gpr.py index c8d080f91..e175ec5c1 100644 --- a/src/plugins/textreport/textplugins.gpr.py +++ b/src/plugins/textreport/textplugins.gpr.py @@ -369,8 +369,8 @@ plg.gramps_target_version = '3.4' plg.status = STABLE plg.fname = 'TableOfContents.py' plg.ptype = REPORT -plg.authors = ["Brian G. Matherly"] -plg.authors_email = ["brian@gramps-project.org"] +plg.authors = ["Nick Hall"] +plg.authors_email = ["nick__hall@hotmail.com"] plg.category = CATEGORY_TEXT plg.reportclass = 'TableOfContents' plg.optionclass = 'TableOfContentsOptions' @@ -391,8 +391,8 @@ plg.gramps_target_version = '3.4' plg.status = STABLE plg.fname = 'AlphabeticalIndex.py' plg.ptype = REPORT -plg.authors = ["Brian G. Matherly"] -plg.authors_email = ["brian@gramps-project.org"] +plg.authors = ["Nick Hall"] +plg.authors_email = ["nick__hall@hotmail.com"] plg.category = CATEGORY_TEXT plg.reportclass = 'AlphabeticalIndex' plg.optionclass = 'AlphabeticalIndexOptions'