[reportlab-users] Absolute coordinates of rendered flowables?
Dinu Gherman
gherman at darwin.in-berlin.de
Tue Mar 4 11:03:24 EST 2008
Robin Becker:
> Dinu flowable drawOn methods are the ones that are passed the x, y.
>
> f.drawOn(canvas,x,y,_sW)
>
> _sW is supposed to be the spare width available for purposes of
> horizontal adjustment ie available - flowable width.
>
> Unfortunately the generic version Flowable.drawOn also handles the
> adjustment of x according to the flowable's hAlign attribute so by
> the time the f._drawOn method gets called the translation to x',y
> may have already occurred.
>
> However, the translation is the very last thing done prior to
> _drawOn being called. So the very last thing on the code stack looks
> like 'a b c d e f cm' where a b c d e f are numeric values
> representing the latest transformation. If canvas.py has
> ENABLE_TRACKING = 1 (which is the default) then canv._currentMatrix
> should hold our estimate of the canvas transformation. Since the
> flowable will be 'drawn' at 0,0 in the that frame of reference you
> should be able to use the inverse transformation to map 0, 0 back to
> the 'absolute' position.
I know about drawOn methods, but I'm not sure if they solve my problem.
What want to do is use flowables like the following, which draw some-
thing at absolute coordinates on the page while not consuming any space
in the story themselves:
class AbsoluteRect(Flowable):
"""A rectangle given in absolute canvas coordinates.
Use in a Platypus story like this: AbsoluteRect((x, y, w, h))
(This is mostly like XBox, but with absolute coordinates.)
"""
def __init__(self, rect):
Flowable.__init__(self)
self.width = 0
self.height = 0
self.rect = rect
def __repr__(self):
return "AbsoluteRect(x=%s, y=%s, w=%s, h=%s)" % self.rect
def draw(self):
x, y, w, h = self.rect
self.canv.rect(x, y, w, h)
self.canv.line(x, y, x+w, y+h)
self.canv.line(x, y+h, x+w, y)
Regards,
Dinu
More information about the reportlab-users
mailing list