[reportlab-users] treatment of space characters
Richard Galka
rgalka at seccuris.com
Wed Feb 9 12:38:52 EST 2011
I should have mentioned that we are using the simpleWrap method of reportlab.lib.utils (RL 2.4), which provides the same result as Paragraph.wrap for height. In our case, even though the wrap/simpleWrap identifies a height of '0', our paragraph class actually draws on the canvas with a positive size.
-- Richard
-----Original Message-----
From: Richard Galka
Sent: Wednesday, February 09, 2011 11:20 AM
To: 'reportlab-users at lists2.reportlab.com'
Subject: RE: [reportlab-users] treatment of space characters
I've noticed this as well. Likely not the best solution, but a quick solution for determining height when your input has blank lines is to substitute a character for the blank line when performing your height check.
Ie:
for text in texts:
if not text.strip():
check_height('x') # x is dummy character to replace blank line
else:
check_height(text)
This will result in each of your samples providing '12' as the result.
Hope this helps,
Richard Galka
Secure Software Analyst
Seccuris Inc.
100 - 321 McDermot Ave, Winnipeg, MB R3A 0A3
Tel: (204) 255-4136 ext #219
Fax: (204) 942-6705
MSS Tel: 1-866-770-7958
MSS Email: MSS at seccuris.com
Date: Wed, 9 Feb 2011 02:16:36 -0800
From: Chris Jerdonek <chris.jerdonek at gmail.com>
Subject: [reportlab-users] treatment of space characters
To: reportlab-users at lists2.reportlab.com
Message-ID:
<AANLkTi=f9LxtM0AraEbLpo+NM18sKSdL-t8vr=GStxGa at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
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
This communication, including any attachments, does not necessarily represent official policy of Seccuris Inc.
Please see http://www.seccuris.com/Contact-PrivacyPolicy.htm for further details about Seccuris Inc.'s Privacy Policy.
If you have received this communication in error, please notify Seccuris Inc. at info at seccuris.com or at 1-866-644-8442.
More information about the reportlab-users
mailing list