[reportlab-users] Re: How to use textobject.setTextTransform()

Bill Bell reportlab-users@reportlab.com
Wed, 26 Jun 2002 08:02:24 -0400


ruediger.maehl@web.de wrote, in part:

>could anybody perhaps explain the usage of
>textobject.setTextTransform(a,b,c,d,e,f)
>to me. For what are the a,b,c,d,e,f used
>
>I already found that e and f stands for x and y coordinates.
>But I couldn't figure out the full meaning of the others.

Ruediger:

I couldn't find a definition either. However, perhaps the following will=
 suffice, if an expert doesn't respond.

This is some code intended to create index tabs (grey rectangles) on the=
 right edge of letter-size paper. It's drawn from something in the=
 ReportLab distribution.

def sideRectangle ( c, section, p ):
    c . saveState ( )
    c . setFillColor ( gray )
    c . setStrokeColor ( gray )
    c . rect ( 8.0 * inch, ( 9 - 2.5 * ( p % 4 ) ) * inch, 0.5 * inch, 2.5=
 * inch, stroke =3D 1, fill =3D 1 )
    c . setFillColor ( white )
    c . setStrokeColor ( white )
    c . setFillColor ( white )
    c . setStrokeColor ( white )
    t =3D c . beginText ( )
    angle =3D 270
    co =3D cos ( angle * pi / 180.0 )
    si =3D sin ( angle * pi / 180.0 )
    t . setTextTransform ( co, -si, si, co, 8.2 * inch, ( 9 - 2.5 * ( p % 4=
 ) + 0.125 ) * inch )
    t . setFont ( "Helvetica", 10 )
    t . textOut ( section )
    c . drawText ( t )
    c . restoreState ( )

Notice the first four arguments to setTextTransform. They form the 2 x 2=
 orthogonal matrix:

	cos	-sin
	sin	cos

so they describe a rotation. If the 2 x 2 matrix passed to setTextTransform=
 is not a (pure) rotation then it will map rectangles onto parallelograms=
 (or whatever) which implies that the characters in the text will be drawn=
 with a slant, that the text will be drawn at an angle other than=
 horizontal and/or that the enclosing rectangle will be shortened or=
 lengthened in one or two directions.

Bill

------------
"It is the time that you have wasted for your rose that makes your rose so=
 important."--St-Exupery