[reportlab-users] How to write text upside down?
Tim Roberts
timr at probo.com
Mon Dec 3 13:47:06 EST 2007
Gregory Piñero wrote:
> Ah, I figured it out, you need to make height and width negative when
> drawing strings upside down:
>
> def write_text(c,front_text,inside_text):
> c.setFillColor(black)
> c.setFont("Helvetica", 22)
> c.drawCentredString(3*(width/4), int(.4*height), front_text) #want
> right side up
> c.setFont("Helvetica", 18)
> c.rotate(180) #write text upside down so it's right when folded.
> c.drawCentredString(-width/4, -int(.75*height), inside_text) #want
> upside down
> c.rotate(180) #put back right side up
> c.setFont("Helvetica", 8)
> c.drawCentredString(width/4, int(.13*height),
> "Created while fondly thinking of you at") #want right side up
>
Do you see WHY you have to do that? When you do a transform like rotate
or scale, all of the coordinates change, too. When you do a rotation,
the origin stays the same (lower left hand corner of the page), but the
coordinates get rotated. So, with 180 degree rotation, (72,72) is one
inch below the bottom margin and one inch to the left of the left margin.
This often burns people who try to do scaling. I know that *I* get it
wrong every time I do it. If you set a scale factor of 200% and then
draw text at (72,72), it will be located two inches above the bottom
margin, and two inches in from the left margin.
You almost have to draw a picture by hand to make sure you get the
factors correct.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the reportlab-users
mailing list