[reportlab-users] Adding charSpace as a paragraph style attribute

Robin Becker robin at reportlab.com
Wed Aug 20 06:02:33 EDT 2008


Paul.Keating at nibc.com wrote:

> 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.



Presumably this is the initial/default charSpace that gets used where the
default style applies. Is it your intention that that space should apply to
places where fonts change etc etc or should we allow charSpace to be changed
with the font / para attributes and similar.


>

> 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

>

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>



--
Robin Becker


More information about the reportlab-users mailing list