[reportlab-users] Absolute coordinates of rendered flowables?

Robin Becker robin at reportlab.com
Tue Mar 4 07:51:52 EST 2008


Dinu Gherman wrote:

> Hi,

>

> I want to find out, where during the rendering process of a document

> template a custom flowable is placed (its absolute x/y-coordinates)

> on a page. Surely, this should be possible, but how?

>

> Thanks,

>

> Dinu

.......
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.
--
Robin Becker


More information about the reportlab-users mailing list