[reportlab-users] hard text clipping
rptl at s.rhythm.cx
rptl at s.rhythm.cx
Tue Feb 15 23:12:09 EST 2005
Hi. I have another question about something I'm not quite sure how to
implement. I'm trying to draw some arbitrary text on the page which will be
clipped to a certain rectangle. Nothing fancy - no wrapping, just draw what
will fit and forget the rest.
I started by writing something like this:
# This draws a string of text on the specified canvas at position
# posx,posy. If the text is bigger than the passed size, it will
# just be hard clipped.
def block_text(canvas,text,posx,posy,sizex,sizey):
p = canvas.beginPath()
p.moveTo(posx,posy)
p.lineTo(posx+sizex,posy)
p.lineTo(posx+sizex,posy+sizey)
p.lineTo(posx,posy+sizey)
p.close()
canvas.clipPath(p,stroke=0)
canvas.drawString(posx,posy,text)
The first call to this function works as expected. The problem here is that
subsequent calls to this function won't work - the prior clipping rectangle
is still in effect. All new text draw outside of the last call's rectangle
will be invisible.
Is there any way to "reset" the canvas's clipping region established by a
clipPath call? Or, is there a better way to do what I'm trying to do? I
looked at the Paragraph Flowable, but that seems overkill and as far as I
can tell it doesn't want to do hard clipping.
I also looked at textobjects, but I didn't see any way to have those clipped
to a particular size aside from the same way as above.
Thanks
More information about the reportlab-users
mailing list