author rgbecker
Wed, 21 Mar 2001 14:12:02 +0000
changeset 735 5dffc9c425d6
parent 494 54257447cfe9
child 1128 bc5ca3b9a13b
permissions -rw-r--r--
Made imageCaching a positive quantity and proeprty of the canvas

#copyright ReportLab Inc. 2000
#see license.txt for license details
#$Header: /tmp/reportlab/docs/userguide/,v 1.7 2001/03/21 14:12:02 rgbecker Exp $
from genuserguide import *

heading1("Writing your own $Flowable$ Objects")
Flowables are intended to be an open standard for creating
reusable report content, and you can easily create your
own objects.  We hope that over time we will build up
a library of contributions, giving reportlab users a
rich selection of charts, graphics and other "report
widgets" they can use in their own reports. This section
shows you how to create your own flowables.""")

todo("""we should put the Figure class in the
standard library, as it is a very useful base.""")

heading2("A very simple $Flowable$")

Recall the $hand$ function from the $pdfgen$ section of this user guide which
generated a drawing of a hand as a closed figure composed from Bezier curves.
illust(examples.hand, "a hand")
To embed this or any other drawing in a Platypus flowable we must define a 
subclass of $Flowable$
with at least a $wrap$ method and a $draw$ method.
The $wrap$ method must provide the size of the drawing -- it is used by
the Platypus mainloop to decide whether this element fits in the space remaining
on the current frame.  The $draw$ method performs the drawing of the object after
the Platypus mainloop has translated the $(0,0)$ origin to an appropriate location
in an appropriate frame.
Below are some example uses of the $HandAnnotation$ flowable.

from reportlab.lib.colors import blue, pink, yellow, cyan, brown
from reportlab.lib.units import inch


disc("""The default.""")


disc("""Just one inch high.""")

handnote(xoffset=3*inch, size=inch, strokecolor=blue, fillcolor=cyan)

disc("""One inch high and shifted to the left with blue and cyan.""")

heading2("Modifying a Built in $Flowable$")
disc("""To modify an existing flowable, you should create a derived class
and override the methods you need to change to get the desired behaviour""")
disc("""As an example to create a rotated image you need to override the wrap
and draw methods of the existing Image class""")
import os
from reportlab.platypus import *
I = '../images/replogo.gif'

class RotatedImage(Image):
	def wrap(self,availWidth,availHeight):
		h, w = Image.wrap(self,availHeight,availWidth)
		return w, h
	def draw(self):
I = RotatedImage('%s')
""" % I,'I')