[reportlab-users] Another problem -- pdfgen\textObject

Dave Rogers reportlab-users@reportlab.com
Fri, 13 Dec 2002 14:15:19 -0500


--------------0440CCE3EE7262BA4B619486
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Thanks for the quick reply Robin re the drawImage.

I'm also having another problem -- this one with pdfgen\textObject.py

Based on my understanding, if I send a trim=0, no whitespace should be removed.

However, I noticed that the code removes leading whitespace on string types (which is a problem for me) even with a trim=0.

I have edited my local version to be this (see the comment with the 'dr'  in it -- that's what I added to preserve leading whitespace):

    def textLines(self, stuff, trim=1):
        """prints multi-line or newlined strings, moving down.  One
        comon use is to quote a multi-line block in your Python code;
        since this may be indented, by default it trims whitespace
        off each line and from the beginning; set trim=0 to preserve
        whitespace."""
        if type(stuff) == StringType:
            if trim==1:
              lines = string.split(string.strip(stuff), '\n')
            else:
              lines = string.split(stuff, '\n') # preserve leading white space dr 10-31-02
            if trim==1:
                lines = map(string.strip,lines)
        elif type(stuff) == ListType:
            lines = stuff
        elif type(stuff) == TupleType:
            lines = stuff
        else:
            assert 1==0, "argument to textlines must be string,, list or tuple"

        for line in lines:
            self._code.append('%s T*' % self._formatText(line))
            if self._canvas.bottomup:
                self._y = self._y - self._leading
            else:
                self._y = self._y + self._leading
        self._x = self._x0

Any idea if this will be corrected in 1.17?

Thanks,
--
Dave Rogers
DaveRogers@StockAlerts.com
http://StockAlerts.com


--------------0440CCE3EE7262BA4B619486
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Thanks for the quick reply Robin re the drawImage.
<p>I'm also having another problem -- this one with pdfgen\textObject.py
<p>Based on my understanding, if I send a trim=0, no whitespace should
be removed.
<p>However, I noticed that the code removes leading whitespace on string
types (which is a problem for me) even with a trim=0.
<p>I have edited my local version to be this (see the comment with the
'dr'&nbsp; in it -- that's what I added to preserve leading whitespace):
<p><tt>&nbsp;&nbsp;&nbsp; def textLines(self, stuff, trim=1):</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; """prints multi-line
or newlined strings, moving down.&nbsp; One</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comon use is to quote
a multi-line block in your Python code;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; since this may be indented,
by default it trims whitespace</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; off each line and from
the beginning; set trim=0 to preserve</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; whitespace."""</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if type(stuff) == StringType:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if trim==1:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
lines = string.split(string.strip(stuff), '\n')</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
else:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
lines = string.split(stuff, '\n') # preserve leading white space dr 10-31-02</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if trim==1:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
lines = map(string.strip,lines)</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif type(stuff) ==
ListType:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
lines = stuff</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif type(stuff) ==
TupleType:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
lines = stuff</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
assert 1==0, "argument to textlines must be string,, list or tuple"</tt><tt></tt>
<p><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for line in lines:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self._code.append('%s T*' % self._formatText(line))</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if self._canvas.bottomup:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self._y = self._y - self._leading</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
else:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self._y = self._y + self._leading</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._x = self._x0</tt>
<p>Any idea if this will be corrected in 1.17?
<p>Thanks,
<br>--
<br>Dave Rogers
<br>DaveRogers@StockAlerts.com
<br><A HREF="http://StockAlerts.com">http://StockAlerts.com</A>
<br>&nbsp;</html>

--------------0440CCE3EE7262BA4B619486--