[reportlab-users] Implementation of drawImage anchoring

Yoann Roman yroman at altalang.com
Thu Aug 28 18:58:06 EDT 2008


Robin Becker wrote...

> > Am I just missing something?

> >

> In this context anchor is saying what point of the image the x,y you

> give refers to. The x and y are absolute as are the width and height.

> In these cases x,y defines a reference point. Width & height define how

> big the image should be. You choose to regard x,y, width & height as

> defining a box. Unfortunately that's not how we regard them.


I was going off this section in the docstring for drawImage:

New post version 2.0: drawImage can center the image in a box you
provide. This saves developers from doing lots of math in their code.
You can define a box with x,y,width and height. If 'preserveAspectRatio'
is set, the image will be scaled up or down as needed in proportion to
fit entirely within the box. Unless the aspect ratio perfectly matches
the box, this will leave some space. So, the boxAnchor property defines
how the image should be anchored in the box, using imaginary points of
the compass. 'sw' for SouthWest is the default, but 'c' for center
will center it in the given box.

This refers to a boxAnchor property, which I assumed should just be anchor.


> The so called box that you refer to doesn't actually exist, but if it

> did and we could refer to its anchor point then there would be two

> anchors and presumably all sorts of possibilities.


This confusion is probably why I'm lost in the first place :-).


> Since you have absolute control over this virtual box I don't believe

> you really need control over what its x and y should anchor to.


This came about from porting Access reports, where there's the concept of an
"image container" in which the image can be left (nw), centered (n), or
right (sw) aligned. I was trying to replicate this behavior, and the
docstring above led me to drawImage's anchor property. I'm getting what I
want now by overriding the methods in lib.boxstuff in my app only, so I'm
just trying to understand the reasoning at this point.


> If I renamed anchor to referencePoint would it make more sense for you?


Personally, replacing the above docstring with the explanation you just
gave me would do it for me. It might help others if you added another
property that would tell drawImage to use this alternate model I described.
All this needs to do is switch the two lib.boxstuff calls it makes. I'd be
happy to provide my patch for this.

Thanks again,

--
Yoann Roman



More information about the reportlab-users mailing list