5483: graphic reports should allow indexing (and thus a t.o.c.) -- partial

(this is my patch-5483=drawindexing-20120702.svndiff.trunk -- from 5483)


svn: r19971
This commit is contained in:
Paul Franklin 2012-07-10 13:29:44 +00:00
parent 5696864675
commit c52933f9ec
14 changed files with 181 additions and 74 deletions

View File

@ -6,6 +6,7 @@
# Copyright (C) 2007 Brian G. Matherly # Copyright (C) 2007 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier # Copyright (C) 2009 Benny Malengier
# Copyright (C) 2009 Gary Burton # Copyright (C) 2009 Gary Burton
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -91,16 +92,20 @@ class DrawDoc(object):
def draw_path(self, style, path): def draw_path(self, style, path):
raise NotImplementedError raise NotImplementedError
def draw_box(self, style, text, x, y, w, h): def draw_box(self, style, text, x, y, w, h, mark=None):
""" @param mark: IndexMark to use for indexing (if supported) """
raise NotImplementedError raise NotImplementedError
def draw_text(self, style, text, x1, y1): def draw_text(self, style, text, x1, y1, mark=None):
""" @param mark: IndexMark to use for indexing (if supported) """
raise NotImplementedError raise NotImplementedError
def center_text(self, style, text, x1, y1): def center_text(self, style, text, x1, y1, mark=None):
""" @param mark: IndexMark to use for indexing (if supported) """
raise NotImplementedError raise NotImplementedError
def rotate_text(self, style, text, x, y, angle): def rotate_text(self, style, text, x, y, angle, mark=None):
""" @param mark: IndexMark to use for indexing (if supported) """
raise NotImplementedError raise NotImplementedError
def draw_line(self, style, x1, y1, x2, y2): def draw_line(self, style, x1, y1, x2, y2):

View File

@ -310,7 +310,7 @@ class HtmlDoc(BaseDoc, TextDoc):
def __write_text(self, text, mark=None, markup=False, links=False): def __write_text(self, text, mark=None, markup=False, links=False):
""" """
@param text: text to write. @param text: text to write.
@param mark: IndexMark to use for indexing (if supported) @param mark: IndexMark to use for indexing (not supported)
@param markup: True if text already contains markup info. @param markup: True if text already contains markup info.
Then text will no longer be escaped Then text will no longer be escaped
@param links: make URLs clickable if True @param links: make URLs clickable if True

View File

@ -7,6 +7,7 @@
# Copyright (C) 2010 Peter Landgren # Copyright (C) 2010 Peter Landgren
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2011 Adam Stein <adam@csh.rit.edu> # Copyright (C) 2011 Adam Stein <adam@csh.rit.edu>
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -1576,12 +1577,21 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
Uses the xml.sax.saxutils.escape function to convert XML Uses the xml.sax.saxutils.escape function to convert XML
entities. The _esc_map dictionary allows us to add our own entities. The _esc_map dictionary allows us to add our own
mappings. mappings.
@param mark: IndexMark to use for indexing
""" """
text = escape(text, _esc_map) text = escape(text, _esc_map)
if links == True: if links == True:
text = re.sub(URL_PATTERN, _CLICKABLE, text) text = re.sub(URL_PATTERN, _CLICKABLE, text)
self._write_mark(mark, text)
self.cntnt.write(text)
def _write_mark(self, mark, text):
"""
Insert a mark at this point in the document.
"""
if mark: if mark:
key = escape(mark.key, _esc_map) key = escape(mark.key, _esc_map)
key = key.replace('"', '&quot;') key = key.replace('"', '&quot;')
@ -1590,7 +1600,6 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
'<text:alphabetical-index-mark ' '<text:alphabetical-index-mark '
'text:string-value="%s" />' % key 'text:string-value="%s" />' % key
) )
elif mark.type == INDEX_TYPE_TOC: elif mark.type == INDEX_TYPE_TOC:
self.cntnt.write( self.cntnt.write(
'<text:toc-mark ' + '<text:toc-mark ' +
@ -1607,8 +1616,6 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
self.cntnt.write( self.cntnt.write(
'<text:bookmark text:name="%s"/>' % key) '<text:bookmark text:name="%s"/>' % key)
self.cntnt.write(text)
def insert_toc(self): def insert_toc(self):
""" """
Insert a Table of Contents at this point in the document. Insert a Table of Contents at this point in the document.
@ -1763,9 +1770,10 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
_META_XML % locals() _META_XML % locals()
) )
def rotate_text(self, style, text, x, y, angle): def rotate_text(self, style, text, x, y, angle, mark=None):
""" """
Used to rotate a text with an angle. Used to rotate a text with an angle.
@param mark: IndexMark to use for indexing
""" """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
stype = style_sheet.get_draw_style(style) stype = style_sheet.get_draw_style(style)
@ -1785,6 +1793,8 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
xloc = x - (wcm / 2.0) * cos(rangle) + (hcm / 2.0) * sin(rangle) xloc = x - (wcm / 2.0) * cos(rangle) + (hcm / 2.0) * sin(rangle)
yloc = y - (hcm / 2.0) * cos(rangle) - (wcm / 2.0) * sin(rangle) yloc = y - (hcm / 2.0) * cos(rangle) - (wcm / 2.0) * sin(rangle)
self._write_mark(mark, text)
self.cntnt.write( self.cntnt.write(
'<draw:frame text:anchor-type="paragraph" ' + '<draw:frame text:anchor-type="paragraph" ' +
'draw:z-index="2" ' + 'draw:z-index="2" ' +
@ -1855,9 +1865,10 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
'</draw:line>\n' '</draw:line>\n'
) )
def draw_text(self, style, text, x, y): def draw_text(self, style, text, x, y, mark=None):
""" """
Draw a text Draw a text
@param mark: IndexMark to use for indexing
""" """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
box_style = style_sheet.get_draw_style(style) box_style = style_sheet.get_draw_style(style)
@ -1866,6 +1877,8 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
font = pstyle.get_font() font = pstyle.get_font()
sw = ReportUtils.pt2cm(string_width(font, text))*1.3 sw = ReportUtils.pt2cm(string_width(font, text))*1.3
self._write_mark(mark, text)
self.cntnt.write( self.cntnt.write(
'<draw:frame text:anchor-type="paragraph" ' + '<draw:frame text:anchor-type="paragraph" ' +
'draw:z-index="2" ' + 'draw:z-index="2" ' +
@ -1886,15 +1899,18 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
'</draw:frame>\n' '</draw:frame>\n'
) )
def draw_box(self, style, text, x, y, w, h): def draw_box(self, style, text, x, y, w, h, mark=None):
""" """
Draw a box Draw a box
@param mark: IndexMark to use for indexing
""" """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
box_style = style_sheet.get_draw_style(style) box_style = style_sheet.get_draw_style(style)
para_name = box_style.get_paragraph_style() para_name = box_style.get_paragraph_style()
shadow_width = box_style.get_shadow_space() shadow_width = box_style.get_shadow_space()
self._write_mark(mark, text)
if box_style.get_shadow(): if box_style.get_shadow():
self.cntnt.write( self.cntnt.write(
'<draw:rect text:anchor-type="paragraph" ' + '<draw:rect text:anchor-type="paragraph" ' +
@ -1928,9 +1944,10 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
) )
self.cntnt.write('</draw:rect>\n') self.cntnt.write('</draw:rect>\n')
def center_text(self, style, text, x, y): def center_text(self, style, text, x, y, mark=None):
""" """
Center a text in a cell, a row, a line, ... Center a text in a cell, a row, a line, ...
@param mark: IndexMark to use for indexing
""" """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
box_style = style_sheet.get_draw_style(style) box_style = style_sheet.get_draw_style(style)
@ -1940,6 +1957,8 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
size = (string_width(font, text) / 72.0) * 2.54 size = (string_width(font, text) / 72.0) * 2.54
self._write_mark(mark, text)
self.cntnt.write( self.cntnt.write(
'<draw:frame text:anchor-type="paragraph" ' + '<draw:frame text:anchor-type="paragraph" ' +
'draw:style-name="%s" ' % style + 'draw:style-name="%s" ' % style +

View File

@ -180,7 +180,8 @@ class PSDrawDoc(BaseDoc, DrawDoc):
new_text = self.encode(text) new_text = self.encode(text)
return (new_text, fdef) return (new_text, fdef)
def center_text(self, style, text, x, y): def center_text(self, style, text, x, y, mark=None):
""" @param mark: IndexMark to use for indexing (not supported) """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
stype = style_sheet.get_draw_style(style) stype = style_sheet.get_draw_style(style)
pname = stype.get_paragraph_style() pname = stype.get_paragraph_style()
@ -201,7 +202,8 @@ class PSDrawDoc(BaseDoc, DrawDoc):
'grestore\n' 'grestore\n'
) )
def draw_text(self, style, text, x1, y1): def draw_text(self, style, text, x1, y1, mark=None):
""" @param mark: IndexMark to use for indexing (not supported) """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
stype = style_sheet.get_draw_style(style) stype = style_sheet.get_draw_style(style)
pname = stype.get_paragraph_style() pname = stype.get_paragraph_style()
@ -219,7 +221,8 @@ class PSDrawDoc(BaseDoc, DrawDoc):
'(%s) show grestore\n' % text '(%s) show grestore\n' % text
) )
def rotate_text(self, style, text, x, y, angle): def rotate_text(self, style, text, x, y, angle, mark=None):
""" @param mark: IndexMark to use for indexing (not supported) """
x += self.paper.get_left_margin() x += self.paper.get_left_margin()
y += self.paper.get_top_margin() y += self.paper.get_top_margin()
@ -321,7 +324,8 @@ class PSDrawDoc(BaseDoc, DrawDoc):
'grestore\n' 'grestore\n'
) )
def draw_box(self, style, text, x, y, w, h): def draw_box(self, style, text, x, y, w, h, mark=None):
""" @param mark: IndexMark to use for indexing (not supported) """
x += self.paper.get_left_margin() x += self.paper.get_left_margin()
y += self.paper.get_top_margin() y += self.paper.get_top_margin()

View File

@ -92,7 +92,8 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
'xmlns="http://www.w3.org/2000/svg">\n' 'xmlns="http://www.w3.org/2000/svg">\n'
) )
def rotate_text(self, style, text, x, y, angle): def rotate_text(self, style, text, x, y, angle, mark=None):
""" @param mark: IndexMark to use for indexing (not supported) """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
stype = style_sheet.get_draw_style(style) stype = style_sheet.get_draw_style(style)
pname = stype.get_paragraph_style() pname = stype.get_paragraph_style()
@ -187,7 +188,8 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
) )
self.f.write('"/>\n') self.f.write('"/>\n')
def draw_box(self, style, text, x, y, w, h): def draw_box(self, style, text, x, y, w, h, mark=None):
""" @param mark: IndexMark to use for indexing (not supported) """
x += self.paper.get_left_margin() x += self.paper.get_left_margin()
y += self.paper.get_top_margin() y += self.paper.get_top_margin()
@ -252,7 +254,8 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
'</text>\n' '</text>\n'
) )
def draw_text(self, style, text, x, y): def draw_text(self, style, text, x, y, mark=None):
""" @param mark: IndexMark to use for indexing (not supported) """
x += self.paper.get_left_margin() x += self.paper.get_left_margin()
y += self.paper.get_top_margin() y += self.paper.get_top_margin()
@ -285,7 +288,8 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
'</text>\n' '</text>\n'
) )
def center_text(self, style, text, x, y): def center_text(self, style, text, x, y, mark=None):
""" @param mark: IndexMark to use for indexing (not supported) """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
box_style = style_sheet.get_draw_style(style) box_style = style_sheet.get_draw_style(style)
para_name = box_style.get_paragraph_style() para_name = box_style.get_paragraph_style()

View File

@ -3,6 +3,7 @@
# Copyright (C) 2000-2007 Donald N. Allingham # Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2008-2009 Brian G. Matherly # Copyright (C) 2008-2009 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -41,7 +42,8 @@ from gen.errors import ReportError
from gen.relationship import get_relationship_calculator from gen.relationship import get_relationship_calculator
from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SERIF, PARA_ALIGN_CENTER, FONT_SERIF, PARA_ALIGN_CENTER,
PARA_ALIGN_LEFT, PARA_ALIGN_RIGHT) PARA_ALIGN_LEFT, PARA_ALIGN_RIGHT,
IndexMark, INDEX_TYPE_TOC)
from gen.plug.docgen.fontscale import string_trim from gen.plug.docgen.fontscale import string_trim
from gen.plug.menu import (BooleanOption, StringOption, NumberOption, from gen.plug.menu import (BooleanOption, StringOption, NumberOption,
EnumeratedListOption, FilterOption, PersonOption) EnumeratedListOption, FilterOption, PersonOption)
@ -131,11 +133,11 @@ class Calendar(Report):
### The rest of these all have to deal with calendar specific things ### The rest of these all have to deal with calendar specific things
def add_day_item(self, text, month, day, format="CAL-Text"): def add_day_item(self, text, month, day, format="CAL-Text", marks=[None]):
""" Add an item to a day. """ """ Add an item to a day. """
month_dict = self.calendar.get(month, {}) month_dict = self.calendar.get(month, {})
day_list = month_dict.get(day, []) day_list = month_dict.get(day, [])
day_list.append((format, text)) day_list.append((format, text, marks))
month_dict[day] = day_list month_dict[day] = day_list
self.calendar[month] = month_dict self.calendar[month] = month_dict
@ -184,13 +186,18 @@ class Calendar(Report):
width = self.doc.get_usable_width() width = self.doc.get_usable_width()
height = self.doc.get_usable_height() height = self.doc.get_usable_height()
header = 2.54 # one inch header = 2.54 # one inch
mark = None
if month == 1:
mark = IndexMark(_('Calendar Report'), INDEX_TYPE_TOC, 1)
self.draw_rectangle("CAL-Border", 0, 0, width, height) self.draw_rectangle("CAL-Border", 0, 0, width, height)
self.doc.draw_box("CAL-Title", "", 0, 0, width, header) self.doc.draw_box("CAL-Title", "", 0, 0, width, header, mark)
self.doc.draw_line("CAL-Border", 0, header, width, header) self.doc.draw_line("CAL-Border", 0, header, width, header)
year = self.year year = self.year
title = "%s %d" % (_dd.long_months[month].capitalize(), year) title = "%s %d" % (_dd.long_months[month].capitalize(), year)
mark = IndexMark(title, INDEX_TYPE_TOC, 2)
font_height = pt2cm(ptitle.get_font().get_size()) font_height = pt2cm(ptitle.get_font().get_size())
self.doc.center_text("CAL-Title", title, width/2, font_height * 0.25) self.doc.center_text("CAL-Title", title,
width/2, font_height * 0.25, mark)
cell_width = width / 7 cell_width = width / 7
cell_height = (height - header)/ 6 cell_height = (height - header)/ 6
current_date = datetime.date(year, month, 1) current_date = datetime.date(year, month, 1)
@ -226,7 +233,7 @@ class Calendar(Report):
list_ = self.calendar.get(month, {}).get(thisday.day, []) list_ = self.calendar.get(month, {}).get(thisday.day, [])
list_.sort() # to get CAL-Holiday on bottom list_.sort() # to get CAL-Holiday on bottom
position = 0.0 position = 0.0
for (format, p) in list_: for (format, p, m_list) in list_:
lines = p.count("\n") + 1 # lines in the text lines = p.count("\n") + 1 # lines in the text
position += (lines * spacing) position += (lines * spacing)
current = 0 current = 0
@ -239,7 +246,9 @@ class Calendar(Report):
line = string_trim(font, line, cm2pt(cell_width + 0.2)) line = string_trim(font, line, cm2pt(cell_width + 0.2))
self.doc.draw_text(format, line, self.doc.draw_text(format, line,
day_col * cell_width + 0.1, day_col * cell_width + 0.1,
header + (week_row + 1) * cell_height - position + (current * spacing) - 0.1) header + (week_row + 1) * cell_height - position + (current * spacing) - 0.1, m_list[0])
if len(m_list) > 1: # index the spouse too
self.doc.draw_text(format, "",0,0, m_list[1])
current += 1 current += 1
current_ord += 1 current_ord += 1
if not something_this_week: if not something_this_week:
@ -272,6 +281,7 @@ class Calendar(Report):
for person_handle in people: for person_handle in people:
self._user.step_progress() self._user.step_progress()
person = db.get_person_from_handle(person_handle) person = db.get_person_from_handle(person_handle)
mark = ReportUtils.get_person_mark(db, person)
birth_ref = person.get_birth_ref() birth_ref = person.get_birth_ref()
birth_date = None birth_date = None
if birth_ref: if birth_ref:
@ -318,7 +328,7 @@ class Calendar(Report):
% {'person' : short_name, % {'person' : short_name,
'age' : nyears, 'age' : nyears,
'relation' : ""}) 'relation' : ""})
self.add_day_item(text, month, day) self.add_day_item(text, month, day, marks=[mark])
if self.anniversaries: if self.anniversaries:
family_list = person.get_family_handle_list() family_list = person.get_family_handle_list()
for fhandle in family_list: for fhandle in family_list:
@ -333,6 +343,7 @@ class Calendar(Report):
if spouse_handle: if spouse_handle:
spouse = db.get_person_from_handle(spouse_handle) spouse = db.get_person_from_handle(spouse_handle)
if spouse: if spouse:
s_m = ReportUtils.get_person_mark(db, spouse)
spouse_name = self.get_name(spouse) spouse_name = self.get_name(spouse)
short_name = self.get_name(person) short_name = self.get_name(person)
# TEMP: this will handle ordered events # TEMP: this will handle ordered events
@ -383,7 +394,8 @@ class Calendar(Report):
alive2 = probably_alive(spouse, self.database, alive2 = probably_alive(spouse, self.database,
prob_alive_date) prob_alive_date)
if ((self.alive and alive1 and alive2) or not self.alive): if ((self.alive and alive1 and alive2) or not self.alive):
self.add_day_item(text, month, day) self.add_day_item(text, month, day,
marks=[mark,s_m])
self._user.end_progress() self._user.end_progress()
#------------------------------------------------------------------------ #------------------------------------------------------------------------

View File

@ -3,7 +3,8 @@
# #
# Copyright (C) 2003-2006 Donald N. Allingham # Copyright (C) 2003-2006 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -43,7 +44,8 @@ def log2(val):
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gen.errors import ReportError from gen.errors import ReportError
from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SANS_SERIF, PARA_ALIGN_CENTER) FONT_SANS_SERIF, PARA_ALIGN_CENTER,
IndexMark, INDEX_TYPE_TOC)
from gen.plug.menu import EnumeratedListOption, NumberOption, PersonOption from gen.plug.menu import EnumeratedListOption, NumberOption, PersonOption
from gen.plug.report import Report from gen.plug.report import Report
from gen.plug.report import utils as ReportUtils from gen.plug.report import utils as ReportUtils
@ -249,7 +251,9 @@ class FanChart(Report):
block_size = min_xy / self.max_generations block_size = min_xy / self.max_generations
text = _("%(generations)d Generation Fan Chart for %(person)s" ) % \ text = _("%(generations)d Generation Fan Chart for %(person)s" ) % \
{ 'generations' : self.max_generations, 'person' : n } { 'generations' : self.max_generations, 'person' : n }
self.doc.center_text ('t', text, self.doc.get_usable_width() / 2, 0) mark = IndexMark(text, INDEX_TYPE_TOC, 1)
self.doc.center_text ('t', text,
self.doc.get_usable_width() / 2, 0, mark)
for generation in range (0, min (max_circular, self.max_generations)): for generation in range (0, min (max_circular, self.max_generations)):
self.draw_circular (x, y, start_angle, max_angle, block_size, generation) self.draw_circular (x, y, start_angle, max_angle, block_size, generation)
@ -339,9 +343,11 @@ class FanChart(Report):
if self.map[index]: if self.map[index]:
if (generation == 0) and self.circle == FULL_CIRCLE: if (generation == 0) and self.circle == FULL_CIRCLE:
yc = y yc = y
person = self.database.get_person_from_handle(self.map[index])
mark = ReportUtils.get_person_mark(self.database, person)
txt = '\n'.join(self.text[index]) txt = '\n'.join(self.text[index])
self.doc.rotate_text(text_style, txt, self.doc.rotate_text(text_style, txt,
xc, yc, text_angle) xc, yc, text_angle, mark)
text_angle += delta text_angle += delta
@ -369,13 +375,15 @@ class FanChart(Report):
start_angle, end_angle, rad1) start_angle, end_angle, rad1)
text_angle += delta text_angle += delta
if self.map[index]: if self.map[index]:
person = self.database.get_person_from_handle(self.map[index])
mark = ReportUtils.get_person_mark(self.database, person)
txt = '\n'.join(self.text[index]) txt = '\n'.join(self.text[index])
if self.radial == RADIAL_UPRIGHT and (start_angle >= 90) and (start_angle < 270): if self.radial == RADIAL_UPRIGHT and (start_angle >= 90) and (start_angle < 270):
self.doc.rotate_text(text_style, txt, self.doc.rotate_text(text_style, txt,
xc, yc, text_angle + 180) xc, yc, text_angle + 180, mark)
else: else:
self.doc.rotate_text(text_style, txt, self.doc.rotate_text(text_style, txt,
xc, yc, text_angle) xc, yc, text_angle, mark)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #

View File

@ -5,7 +5,8 @@
# Copyright (C) 2004-2005 Eero Tamminen # Copyright (C) 2004-2005 Eero Tamminen
# Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2008 Peter Landgren # Copyright (C) 2008 Peter Landgren
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -46,10 +47,11 @@ from gen.lib import Person, FamilyRelType, EventType, EventRoleType
from gen.lib.date import Date from gen.lib.date import Date
# gender and report type names # gender and report type names
from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SANS_SERIF, FONT_SERIF, FONT_SANS_SERIF, FONT_SERIF,
PARA_ALIGN_CENTER, PARA_ALIGN_LEFT) PARA_ALIGN_CENTER, PARA_ALIGN_LEFT,
from gen.plug.menu import BooleanOption, NumberOption, EnumeratedListOption, \ IndexMark, INDEX_TYPE_TOC)
FilterOption, PersonOption from gen.plug.menu import (BooleanOption, NumberOption, EnumeratedListOption,
FilterOption, PersonOption)
from gen.plug.report import Report from gen.plug.report import Report
from gen.plug.report import utils as ReportUtils from gen.plug.report import utils as ReportUtils
from gen.plug.report import MenuReportOptions from gen.plug.report import MenuReportOptions
@ -782,10 +784,14 @@ class StatisticsChart(Report):
def write_report(self): def write_report(self):
"output the selected statistics..." "output the selected statistics..."
mark = IndexMark(_('Statistics Charts'), INDEX_TYPE_TOC, 1)
self._user.begin_progress(_('Statistics Charts'), self._user.begin_progress(_('Statistics Charts'),
_('Saving charts...'), len(self.data)) _('Saving charts...'), len(self.data))
for data in self.data: for data in self.data:
self.doc.start_page() self.doc.start_page()
if mark:
self.doc.draw_text('SC-title', '', 0, 0, mark) # put it in TOC
mark = None # crock, but we only want one of them
if len(data[2]) < self.bar_items: if len(data[2]) < self.bar_items:
self.output_piechart(*data[:4]) self.output_piechart(*data[:4])
else: else:
@ -803,7 +809,8 @@ class StatisticsChart(Report):
middle = min(middle_w,middle_h) middle = min(middle_w,middle_h)
# start output # start output
self.doc.center_text('SC-title', title, middle_w, 0) mark = IndexMark(title, INDEX_TYPE_TOC, 2)
self.doc.center_text('SC-title', title, middle_w, 0, mark)
style_sheet = self.doc.get_style_sheet() style_sheet = self.doc.get_style_sheet()
pstyle = style_sheet.get_paragraph_style('SC-Title') pstyle = style_sheet.get_paragraph_style('SC-Title')
yoffset = ReportUtils.pt2cm(pstyle.get_font().get_size()) yoffset = ReportUtils.pt2cm(pstyle.get_font().get_size())
@ -857,7 +864,8 @@ class StatisticsChart(Report):
maxsize = stopx - margin maxsize = stopx - margin
# start output # start output
self.doc.center_text('SC-title', title, middle, 0) mark = IndexMark(title, INDEX_TYPE_TOC, 2)
self.doc.center_text('SC-title', title, middle, 0, mark)
pstyle = style_sheet.get_paragraph_style('SC-Title') pstyle = style_sheet.get_paragraph_style('SC-Title')
yoffset = pt2cm(pstyle.get_font().get_size()) yoffset = pt2cm(pstyle.get_font().get_size())
#print title #print title

View File

@ -3,7 +3,8 @@
# #
# Copyright (C) 2003-2007 Donald N. Allingham # Copyright (C) 2003-2007 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -44,7 +45,8 @@ from gen.plug.report import utils as ReportUtils
from gen.plug.report import MenuReportOptions from gen.plug.report import MenuReportOptions
pt2cm = ReportUtils.pt2cm pt2cm = ReportUtils.pt2cm
from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SANS_SERIF, DASHED, PARA_ALIGN_CENTER) FONT_SANS_SERIF, DASHED, PARA_ALIGN_CENTER,
IndexMark, INDEX_TYPE_TOC)
from gen.sort import Sort from gen.sort import Sort
from gen.display.name import displayer as name_displayer from gen.display.name import displayer as name_displayer
from gen.config import config from gen.config import config
@ -138,7 +140,7 @@ class TimeLine(Report):
self._user.end_progress() self._user.end_progress()
self.doc.start_page() self.doc.start_page()
self.build_grid(low, high, start, stop) self.build_grid(low, high, start, stop, True)
index = 1 index = 1
current = 1; current = 1;
@ -163,8 +165,9 @@ class TimeLine(Report):
d = None d = None
n = name_displayer.display_formal(p) n = name_displayer.display_formal(p)
mark = ReportUtils.get_person_mark(self.database, p)
self.doc.draw_text('TLG-text', n,incr+pad, self.doc.draw_text('TLG-text', n,incr+pad,
self.header + (incr+pad)*index) self.header + (incr+pad)*index, mark)
y1 = self.header + (pad+incr)*index y1 = self.header + (pad+incr)*index
y2 = self.header + ((pad+incr)*index)+incr y2 = self.header + ((pad+incr)*index)+incr
@ -205,7 +208,7 @@ class TimeLine(Report):
self.doc.end_page() self.doc.end_page()
self._user.end_progress() self._user.end_progress()
def build_grid(self, year_low, year_high, start_pos, stop_pos): def build_grid(self, year_low, year_high, start_pos, stop_pos, toc=False):
""" """
Draws the grid outline for the chart. Sets the document label, Draws the grid outline for the chart. Sets the document label,
draws the vertical lines, and adds the year labels. Arguments draws the vertical lines, and adds the year labels. Arguments
@ -216,7 +219,7 @@ class TimeLine(Report):
start_pos - x position of the lowest leftmost grid line start_pos - x position of the lowest leftmost grid line
stop_pos - x position of the rightmost grid line stop_pos - x position of the rightmost grid line
""" """
self.draw_title() self.draw_title(toc)
self.draw_columns(start_pos, stop_pos) self.draw_columns(start_pos, stop_pos)
if year_high is not None and year_low is not None: if year_high is not None and year_low is not None:
self.draw_year_headings(year_low, year_high, start_pos, stop_pos) self.draw_year_headings(year_low, year_high, start_pos, stop_pos)
@ -237,7 +240,7 @@ class TimeLine(Report):
xpos = start_pos + (val * delta) xpos = start_pos + (val * delta)
self.doc.draw_line('TLG-grid', xpos, top_y, xpos, bottom_y) self.doc.draw_line('TLG-grid', xpos, top_y, xpos, bottom_y)
def draw_title(self): def draw_title(self, toc):
""" """
Draws the title for the page. Draws the title for the page.
""" """
@ -246,7 +249,11 @@ class TimeLine(Report):
byline = _("Sorted by %s") % self.sort_name byline = _("Sorted by %s") % self.sort_name
# feature request 2356: avoid genitive form # feature request 2356: avoid genitive form
title = _("Timeline Graph for %s") % self.filter.get_name() title = _("Timeline Graph for %s") % self.filter.get_name()
self.doc.center_text('TLG-title', title + "\n" + byline, width / 2.0, 0) mark = None
if toc:
mark = IndexMark(title, INDEX_TYPE_TOC, 1)
self.doc.center_text('TLG-title', title + "\n" + byline,
width / 2.0, 0, mark)
def draw_year_headings(self, year_low, year_high, start_pos, stop_pos): def draw_year_headings(self, year_low, year_high, start_pos, stop_pos):
""" """

View File

@ -1,13 +1,14 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2007 Zsolt Foldvari # Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2009 Benny Malengier # Copyright (C) 2007 Zsolt Foldvari
# Copyright (C) 2009 Brian Matherly # Copyright (C) 2009 Benny Malengier
# Copyright (C) 2010 Peter Landgren # Copyright (C) 2009 Brian Matherly
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Peter Landgren
# Copyright (C) 2011 Paul Franklin # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2012 Craig Anderson # Copyright (C) 2011-2012 Paul Franklin
# Copyright (C) 2012 Craig Anderson
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -1228,13 +1229,17 @@ class GtkDocText(GtkDocBaseElement):
# line spacing is not defined in ParagraphStyle # line spacing is not defined in ParagraphStyle
spacingfractionfont = 0.2 spacingfractionfont = 0.2
def __init__(self, style, vertical_alignment, text, x, y, angle=0): def __init__(self, style, vertical_alignment, text, x, y,
angle=0, mark=None):
GtkDocBaseElement.__init__(self, style) GtkDocBaseElement.__init__(self, style)
self._align_y = vertical_alignment self._align_y = vertical_alignment
self._text = text self._text = text
self._x = x self._x = x
self._y = y self._y = y
self._angle = angle self._angle = angle
self._marklist = []
if mark:
self._marklist = [mark]
def draw(self, cr, layout, width, dpi_x, dpi_y): def draw(self, cr, layout, width, dpi_x, dpi_y):
text_x = self._x * dpi_x / 2.54 text_x = self._x * dpi_x / 2.54
@ -1296,6 +1301,12 @@ class GtkDocText(GtkDocBaseElement):
return layout_height return layout_height
def get_marks(self):
"""
Return the index mark for this text
"""
return self._marklist
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# CairoDoc class # CairoDoc class
@ -1444,7 +1455,7 @@ class CairoDoc(BaseDoc, TextDoc, DrawDoc):
def __write_text(self, text, mark=None, markup=False, links=False): def __write_text(self, text, mark=None, markup=False, links=False):
""" """
@param text: text to write. @param text: text to write.
@param mark: IndexMark to use for indexing (if supported) @param mark: IndexMark to use for indexing
@param markup: True if text already contains markup info. @param markup: True if text already contains markup info.
Then text will no longer be escaped Then text will no longer be escaped
@param links: True if URLs should be made clickable @param links: True if URLs should be made clickable
@ -1477,7 +1488,7 @@ links (like ODF) and write PDF from that format.
"""Write a normal piece of text according to the """Write a normal piece of text according to the
present style present style
@param text: text to write. @param text: text to write.
@param mark: IndexMark to use for indexing (if supported) @param mark: IndexMark to use for indexing
@param links: True if URLs should be made clickable @param links: True if URLs should be made clickable
""" """
self.__write_text(text, mark, links=links) self.__write_text(text, mark, links=links)
@ -1557,7 +1568,8 @@ links (like ODF) and write PDF from that format.
new_polygon = GtkDocPolygon(style, path) new_polygon = GtkDocPolygon(style, path)
self._active_element.add_child(new_polygon) self._active_element.add_child(new_polygon)
def draw_box(self, style_name, text, x, y, w, h): def draw_box(self, style_name, text, x, y, w, h, mark=None):
""" @param mark: IndexMark to use for indexing """
# we handle the box and... # we handle the box and...
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
style = style_sheet.get_draw_style(style_name) style = style_sheet.get_draw_style(style_name)
@ -1580,10 +1592,11 @@ links (like ODF) and write PDF from that format.
new_text = GtkDocText(paragraph_style, 'center', new_text = GtkDocText(paragraph_style, 'center',
self.__markup(text), self.__markup(text),
x + x_offset , y + h / 2, angle=0) x + x_offset, y + h / 2, angle=0, mark=mark)
self._active_element.add_child(new_text) self._active_element.add_child(new_text)
def draw_text(self, style_name, text, x, y): def draw_text(self, style_name, text, x, y, mark=None):
""" @param mark: IndexMark to use for indexing """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
style = style_sheet.get_draw_style(style_name) style = style_sheet.get_draw_style(style_name)
paragraph_style_name = style.get_paragraph_style() paragraph_style_name = style.get_paragraph_style()
@ -1591,10 +1604,11 @@ links (like ODF) and write PDF from that format.
paragraph_style.set_alignment(PARA_ALIGN_LEFT) paragraph_style.set_alignment(PARA_ALIGN_LEFT)
new_text = GtkDocText(paragraph_style, 'top', new_text = GtkDocText(paragraph_style, 'top',
self.__markup(text), x, y, angle=0) self.__markup(text), x, y, angle=0, mark=mark)
self._active_element.add_child(new_text) self._active_element.add_child(new_text)
def center_text(self, style_name, text, x, y): def center_text(self, style_name, text, x, y, mark=None):
""" @param mark: IndexMark to use for indexing """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
style = style_sheet.get_draw_style(style_name) style = style_sheet.get_draw_style(style_name)
paragraph_style_name = style.get_paragraph_style() paragraph_style_name = style.get_paragraph_style()
@ -1602,10 +1616,11 @@ links (like ODF) and write PDF from that format.
paragraph_style.set_alignment(PARA_ALIGN_CENTER) paragraph_style.set_alignment(PARA_ALIGN_CENTER)
new_text = GtkDocText(paragraph_style, 'top', new_text = GtkDocText(paragraph_style, 'top',
self.__markup(text), x, y, angle=0) self.__markup(text), x, y, angle=0, mark=mark)
self._active_element.add_child(new_text) self._active_element.add_child(new_text)
def rotate_text(self, style_name, text, x, y, angle): def rotate_text(self, style_name, text, x, y, angle, mark=None):
""" @param mark: IndexMark to use for indexing """
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
style = style_sheet.get_draw_style(style_name) style = style_sheet.get_draw_style(style_name)
paragraph_style_name = style.get_paragraph_style() paragraph_style_name = style.get_paragraph_style()
@ -1613,7 +1628,7 @@ links (like ODF) and write PDF from that format.
paragraph_style.set_alignment(PARA_ALIGN_CENTER) paragraph_style.set_alignment(PARA_ALIGN_CENTER)
new_text = GtkDocText(paragraph_style, 'center', new_text = GtkDocText(paragraph_style, 'center',
self.__markup(text), x, y, angle) self.__markup(text), x, y, angle, mark)
self._active_element.add_child(new_text) self._active_element.add_child(new_text)
# paginating and drawing interface # paginating and drawing interface

View File

@ -1,6 +1,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2012 Nick Hall # Copyright (C) 2012 Nick Hall
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -33,7 +34,8 @@ from gen.ggettext import sgettext as _
from gen.plug.report import Report from gen.plug.report import Report
from gen.plug.report import MenuReportOptions from gen.plug.report import MenuReportOptions
from gen.plug.docgen import (FontStyle, ParagraphStyle, TableStyle, from gen.plug.docgen import (FontStyle, ParagraphStyle, TableStyle,
TableCellStyle, FONT_SANS_SERIF) TableCellStyle, FONT_SANS_SERIF,
IndexMark, INDEX_TYPE_TOC)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -59,6 +61,10 @@ class AlphabeticalIndex(Report):
def write_report(self): def write_report(self):
""" Generate the contents of the report """ """ Generate the contents of the report """
mark = IndexMark(_("Alphabetical Index"), INDEX_TYPE_TOC, 1)
self.doc.start_paragraph("IDX-Title")
self.doc.write_text('', mark)
self.doc.end_paragraph()
self.doc.insert_index() self.doc.insert_index()
#------------------------------------------------------------------------ #------------------------------------------------------------------------

View File

@ -4,6 +4,7 @@
# Copyright (C) 2000-2007 Donald N. Allingham # Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2007-2009 Brian G. Matherly # Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -209,9 +210,12 @@ class AncestorReport(Report):
generation += 1 generation += 1
# Create the Generation title, set an index marker # Create the Generation title, set an index marker
mark = IndexMark(title, INDEX_TYPE_TOC, 2) gen_text = self._("Generation %d") % generation
mark = None # don't need any with no page breaks
if self.pgbrk:
mark = IndexMark(gen_text, INDEX_TYPE_TOC, 2)
self.doc.start_paragraph("AHN-Generation") self.doc.start_paragraph("AHN-Generation")
self.doc.write_text(self._("Generation %d") % generation, mark) self.doc.write_text(gen_text, mark)
self.doc.end_paragraph() self.doc.end_paragraph()
# Build the entry # Build the entry

View File

@ -3,6 +3,7 @@
# Copyright (C) 2003-2006 Donald N. Allingham # Copyright (C) 2003-2006 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly # Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -46,7 +47,7 @@ from gen.plug.menu import TextOption
from gen.plug.report import Report from gen.plug.report import Report
from gen.plug.report import MenuReportOptions from gen.plug.report import MenuReportOptions
from gen.plug.docgen import (FontStyle, ParagraphStyle, FONT_SANS_SERIF, from gen.plug.docgen import (FontStyle, ParagraphStyle, FONT_SANS_SERIF,
PARA_ALIGN_CENTER) PARA_ALIGN_CENTER, IndexMark, INDEX_TYPE_TOC)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -80,9 +81,17 @@ class CustomText(Report):
self.bottom_text = menu.get_option_by_name('bot').get_value() self.bottom_text = menu.get_option_by_name('bot').get_value()
def write_report(self): def write_report(self):
mark_text = _("Custom Text")
if self.top_text[0]:
mark_text = "%s (%s)" % (_("Custom Text"), self.top_text[0])
elif self.middle_text[0]:
mark_text = "%s (%s)" % (_("Custom Text"), self.middle_text[0])
elif self.bottom_text[0]:
mark_text = "%s (%s)" % (_("Custom Text"), self.bottom_text[0])
mark = IndexMark(mark_text, INDEX_TYPE_TOC, 1)
self.doc.start_paragraph('CBT-Initial') self.doc.start_paragraph('CBT-Initial')
for line in self.top_text: for line in self.top_text:
self.doc.write_text(line) self.doc.write_text(line, mark)
self.doc.write_text("\n") self.doc.write_text("\n")
self.doc.end_paragraph() self.doc.end_paragraph()

View File

@ -1,6 +1,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2012 Nick Hall # Copyright (C) 2012 Nick Hall
# Copyright (C) 2012 Paul Franklin
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -33,7 +34,8 @@ from gen.ggettext import sgettext as _
from gen.plug.report import Report from gen.plug.report import Report
from gen.plug.report import MenuReportOptions from gen.plug.report import MenuReportOptions
from gen.plug.docgen import (FontStyle, ParagraphStyle, TableStyle, from gen.plug.docgen import (FontStyle, ParagraphStyle, TableStyle,
TableCellStyle, FONT_SANS_SERIF) TableCellStyle, FONT_SANS_SERIF,
IndexMark, INDEX_TYPE_TOC)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -59,6 +61,10 @@ class TableOfContents(Report):
def write_report(self): def write_report(self):
""" Generate the contents of the report """ """ Generate the contents of the report """
mark = IndexMark(_("Table Of Contents"), INDEX_TYPE_TOC, 1)
self.doc.start_paragraph("TOC-Title")
self.doc.write_text('', mark)
self.doc.end_paragraph()
self.doc.insert_toc() self.doc.insert_toc()
#------------------------------------------------------------------------ #------------------------------------------------------------------------