[reportlab-users] Adding charSpace as a paragraph style attribute
Paul.Keating at nibc.com
Paul.Keating at nibc.com
Wed Aug 20 05:35:06 EDT 2008
Ok, here it is:
The charSpace attribute is already present in and supported at canvas
level.
This little patch surfaces it as a pargraph style attribute. Increased
character spacing is occasionally useful for making all-caps headings in
sans fonts more legible at small point sizes. I needed to put it in because
it's a house-style requirement for a project I'm working on.
Typical use is as follows, last line of example:
styleSheet.add(
ParagraphStyle('Heading Rubrics', styleSheet['Normal'],
fontSize=6,
leading=7,
spaceAfter=0,
charSpace=1))
I'v run the standard test suite against it and it doesn't appear to break
anything, though that is of course hard to judge because the visual tests
rely on one knowing exactly what they should look like.
Index: lib/styles.py
===================================================================
--- lib/styles.py (revision 3252)
+++ lib/styles.py (working copy)
@@ -75,6 +75,7 @@
'alignment':TA_LEFT,
'spaceBefore':0,
'spaceAfter':0,
+ 'charSpace': 0,
'bulletFontName':'Times-Roman',
'bulletFontSize':10,
'bulletIndent':0,
Index: pdfgen/canvas.py
===================================================================
--- pdfgen/canvas.py (revision 3252)
+++ pdfgen/canvas.py (working copy)
@@ -1306,8 +1306,11 @@
font = pdfmetrics.getFont(self._fontname)
if not font._dynamicFont:
pdffontname = self._doc.getInternalFontName(psfontname)
- self._code.append('BT %s %s Tf %s TL ET' % (pdffontname,
fp_str(size), fp_str(leading)))
+ self._code.append('BT %s %s Tf %s TL %s Tc ET' % (pdffontname,
fp_str(size), fp_str(leading), fp_str(self._charSpace)))
+ def setCharSpace(self, charSpace):
+ self._charSpace = charSpace
+
def setFontSize(self, size=None, leading=None):
'''Sets font size or leading without knowing the font face'''
if size is None: size = self._fontsize
Index: platypus/paragraph.py
===================================================================
--- platypus/paragraph.py (revision 3252)
+++ platypus/paragraph.py (working copy)
@@ -1288,6 +1288,8 @@
#now the font for the rest of the paragraph
tx.setFont(f.fontName, f.fontSize, leading)
+ if style.charSpace: tx.setCharSpace(style.charSpace)
+
ws = lines[0][0]
t_off = dpl( tx, offset, ws, lines[0][1], noJustifyLast
and nLines==1)
if f.underline or f.link or f.strike:
reportlab-users-bounces at reportlab.com wrote on 2008-08-19 16:20:35:
> >> If you have working code then by all means submit it here.
...
> Or to me directly; if you show in the mailing list more eyes will
> get to see it
> and they may have valid insights/criticisms.
> --
> Robin Becker
More information about the reportlab-users
mailing list