[reportlab-users] Table of Contents and Style

Bradley Young young.bradley at gmail.com
Fri Mar 28 20:01:11 EDT 2008


On Fri, Mar 28, 2008 at 4:22 PM, Robin Becker <robin at reportlab.com> wrote:

> .....

> not sure what a toc class is, but not against discussion/contributions

> either.

> --


Specifically, I'm referring to reportlab/platypus/tableofcontents.py.
Currently there are these variables in the file:

levelZeroParaStyle = \
ParagraphStyle(name='LevelZero',
fontName='Times-Roman',
fontSize=10,
leading=11,
firstLineIndent = -epsilon,
leftIndent = 0*delta + epsilon)

levelOneParaStyle = \
ParagraphStyle(name='LevelOne',
parent = levelZeroParaStyle,
leading=11,
firstLineIndent = -epsilon,
leftIndent = 1*delta + epsilon)

... there are actually 5 of these. They are then stuffed into an
array. Then the issue is that changing a font, etc. is kinda wonky:

tc = TableOfContents()
for tcstyle in tc.levelStyles:
tcstyle.fontName = "Helvetica"

When there isn't really any difference in all the ParagraphStyles(),
other than indentation. It seems to me that the style should all be
inherited from a single ParagraphStyle() object, and the indentation
can be created at runtime; i.e. since the current usage of the array
of styles is:

178: for (level, text, pageNum) in _tempEntries:
179: leftColStyle = self.levelStyles[level]

The style could be dynamically created like so:

for (level, text, pageNum) in _tempEntries:
leftColStyle = self._style <-- made this variable up, but
the array wouldn't be appropriate any more
leftColStyle.leftIndent = level*delta + epsilon

It seems to me that a single style would be enough to set the default,
but this would break backwards compatibility (if one uses the
levelStyle array). If backwards compatibility is important, then the
alternate is to allow the user to supply a "base" ParagraphStyle()
object, and the levelZeroParaStyle would use that as a starting point
(to make it easier to change fonts, etc.).

Comments or questions welcomed; I'd be happy to submit a patch (I'd
prefer the non-backwards compatible version; the hard coded variables
at the beginning of the file (levelZeroParaStyle, etc.) seem wonky.)

Bradley


More information about the reportlab-users mailing list