[reportlab-users] Right-to-Left languages
Wed, 16 Oct 2002 00:20:17 +0200
Andy Robinson wrote:
> anything. But there isn't really a containment mechanism in
> Platypus now. I'll need to play with it to tell you what i think...
In case this might help - here is the approach that I just tried and
that seemed to work for 'containment inheritance':
create a 'Directional' mixin class that has a 'getter' and two
'setter' methods - one user-visible, to force the direction of a
specific element, the other, '_set_inherited_direction' - for
containers to call on their children.
Now the inheritance part - the container needs to pass the
direction attribute down to it's children before they are drawn.
PageTemplate, BaseDocTemplate, Frame and Flowable all inherit from
this mixin class
BaseDocTemplate, being a top-level class immediately forces it's
direction (to LTR) in it's __init__
in addPageTemplates the direction is passed to PageTemplate
PageTemplate's beforeDrawPage() method would've been a good place
to pass the attribute to it's frames, but the method is empty in
the base class, so there could be user-defined classes that do
not perform upcall to PageTemplate. So we create a new method in
PageTemplate, say ._configureFrames(), and call it from
BaseDocTemplate's handle_pageBegin. Inside PageTemplate.configureFrames()
we pass the attribute down to contained frames.
Here we run into Frame's __getattr__/__setattr__ magic: Frame allows
all attributes to be set, but only geometry attributes are allowed
to be read back. Even if such write-only behavior was deliberate,
hopefully we can extend it to allow reading back the direction.
Then in the _add method of the Frame we pass the attribute to the
The table sets the attribute on its contained flowables in it's
_drawCell method, the part that deals with lists of flowables.
Whew. I probably should've sent the diff directly, without
trying to translate it into English ;)
Obviously I don't know the code well enough, so there must be cases
where it will break (break in this case means 'not pass the attribute
down to its children'), so for production use the mixin class can
default to 'LTR', and the non-RTL users won't feel the diference.
P.S. I have to comment on the code - there aren't many packages of
this size that are so readable and modifiable!