[reportlab-users] treatment of space characters

Chris Jerdonek chris.jerdonek at gmail.com
Wed Feb 9 05:16:36 EST 2011


I'm looking for a string that takes up space but is invisible for
passing into a Paragraph -- i.e. so the paragraph looks empty but has
positive height. The string " " seems to work for this.

While experimenting with this, I noticed some unexpected behavior.
Both spaces and non-breaking spaces seem to "take up space" when
encoded as HTML entities, and neither takes up space otherwise:

def check_height(text):
para = Paragraph(text, style)
height = para.wrap(300, 300)[1]
print "%s: %s" % (repr(text), height)

texts = [u"spaces:", u" ", u" ", u"\u0020",
u"non-breaking spaces:", u" ", u" ", u"\u00A0"]

for text in texts:
check_height(text)

This gives--

u'spaces:': 12
u' ': 0
u' ': 12
u' ': 0
u'non-breaking spaces:': 12
u' ': 12
u' ': 12
u'\xa0': 0

Unless I'm doing something wrong, it seems like all strings in the
first group should yield 0 and all strings in the second 12.

--Chris


More information about the reportlab-users mailing list