[reportlab-users] Basic usage question
Tim Roberts
timr at probo.com
Tue Sep 6 14:35:36 EDT 2005
On Sat, 3 Sep 2005 06:25:20 -0500, Kent Tenney <ktenney at gmail.com> wrote:
>I want to lay out business cards on letter size paper.
>If the cards are vertical, 12 can fit on a page;
>3 rows of 3.5" tall, 4 columns of 2" wide: 1/8" border.
>
>
Yes. This is how my print shop prefers to receive orders for business
cards. I found Visio a bit easier than ReportLab for this task, which
is somewhat unusual for me...
>This has led me to questions about how the coordinate system
>works, the relationships between canvas, drawing, widget, group
>and what can be placed on what.
>
>
I don't think of PostScript as having "widgets". PostScript is just
instructions that apply ink to paper. You can pile things on top of
each other to your heart's content, just as you can overprint documents
and drawings on top of one another, and the effect is the same. More ink.
At any point in its list of instructions, PostScript has a "current
transform", which is a 2x3 matrix that converts whatever coordinates you
provide into absolute points on the piece of paper. The default
transform has (0,0) at the lower left, and coordinates are in units of
points. There are several canvas methods that alter the transform
(rotate, scale, translate), or you can set the 6-element matrix
directly. If you're doing to alter the transform, you often want to
wrap those alterations with saveState and restoreState, so that you
don't provide nasty surprises to the next code.
>I am sorry if there is documentation which covers these topics,
>I haven't been able to find it.
>
>Using the RLBusinessCard demo as a starting point
>IE: a card as a horizontal widget.
>
>Questions;
>
>- it looks like I need to make 12 copies of the card widget
> and place them, I can't place the same widget in 12 places ... correct?
>
>
I don't see the difference. A PostScript widget isn't an object that
exists with a life of its own. It's just a set of instructions that
apply ink to paper. Somehow, you are going to have to tell PostScript
to apply that ink 12 times. In Python, your business card is either a
Python function or a Python object that knows how to render itself in
PostScript. It's up to you to decide whether you create 12 such objects
and have them each render onto the canvas, or create one object that can
render itself and then be moved to a new location. The latter is
probably less resource-intensive, but at this level, who cares. If the
"12 separate object" model makes more sense to you, go for it.
>- how would I rotate the card 90 degrees and do the step and repeat?
>
>
You can do this by changing the transform. You can use the
canvas.rotate method to rotate by 90 degrees, and then use the
canvas.translate method to move the current origin by 2" or 3.5". That
way, your object just draws starting at (0,0), and the transform ensures
that it draws in 12 different locations.
Alternatively, you can leave the PostScript transform with the rotation
but no translation, and pass an offset into your business card routine,
which it can add to all of its coordinates. Both schemes have their
benefits.
canvas.rotate( 90 )
for x in range(3):
for y in range(4):
canvas.saveState()
canvas.translate( x * 3.5 * INCH, y * 2 * INCH )
DrawBusinessCard( canvas )
canvas.restoreState()
vs.
canvas.rotate( 90 )
for x in range(3):
for y in range(4):
DrawBusinessCard( canvas, x * 3.5 * INCH, y * 2 * INCH )
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the reportlab-users
mailing list