[reportlab-users] Absolute coordinates of rendered flowables?

Robin Becker robin at reportlab.com
Tue Mar 4 11:35:51 EST 2008


Dinu Gherman wrote:

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

>>

>.........

> 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)

>

........

well OK you need to provide the drawOn method to eliminate any translation
provided by the default behaviour. So I suspect your drawOn needs to look like this

def drawOn(self, canv, x, y, _sW=0):
try:
self.canv = canv
self.draw()
finally:
del self.canv

but this won't be sufficient if any other part of the process has modified the
canvas transformation. In that case you probably need to reset the
transformation in drawOn ie try doing


def drawOn(self, canv, x, y, _sW=0):
self.canv = canv
self.canv.saveState()
self.resetTransforms()
try:
self.draw()
finally:
del self.canv
self.canv.restoreState()

so in this last version you're using the default user space
--
Robin Becker


More information about the reportlab-users mailing list