[reportlab-users] ParagraphAndImage flowable

Matt Page-Lieberman mjpl at itautec.cin.ufpe.br
Fri Jun 2 09:08:43 EDT 2006


Hi, we're working on a project and we would like to have an icon 
followed immediatly by text.  One solution that we found was to use the 
ParagraphAndImage flowable (PAIf).  The problem is that the PAIf hard 
codes the decision that the paragraph will appear before the image and 
there are no arguments that can be passed to the PAIf to change this 
behavior.  Additionally, the image has no associated style; only the 
paragraph does.  So, when we want to have an indented PAIf where the 
image is immediately followed by text, we have to resort to a variety of 
hacks of the PAIf by using the paragraph style's leftIndent to indent 
the image within the implementation of PAI.draw().

Thus, we have created a new flowable named ImageAndParagraph (IAP) which 
differs from PAI only in the implementation of IAP.draw().  Ideally, 
there would be one flowable - PAI - where an argument (which would of 
course have a default) would specify which object (Image or Paragraph) 
to put first, and which, unfortunately, would probably result in an ugly 
if-else in draw().  Another option in order to take advantage of shared 
code would to have a paragraph and image type be abstract with both PAI 
and IAP each implementing draw() as necessary.

Unfortunately, as it now stands, it looks like our temporary solution 
would be to either inherit IAP from PAI and override draw() so that we 
can take advantage of the implmentations for wrap(), split(), etc - 
(This is one sad hack though since an IAP should not descend from a PAI) 
- or to copy and paste all the implementation of PAI to our new class 
IAP which is being used as the current solution.  But, this would cause 
us to not be able to rely on any new implementations of PAI if the code 
were to be changed in the future; we would have to verify for 
differences with every release and since we have very little control of 
which versions of reportlab will be packaged/used with our program in 
the future, this is quite the dilemma.

Are there any other suggestions or possibilities to chage this class 
hierarchy in the future.  I'm sure that the team that I work on would be 
able to arrange a change to this hierarchy if warranted.

Would the new type ImageAndFlowables be able to address any of these issues?

Thanks in advance,
Matt Page-Lieberman

Specifications:
Library version: reportlab-1.20
O.S.: Librix (Gentoo)



More information about the reportlab-users mailing list