"mymodule.py implements example plug-in functionality for rml2pdf"

# <plugInGraphic module="mymodule" function="myfunction">example data</plugInGraphic>

def myfunction(canv, data):
    print "myfunction", (canv, data)
    canv.line(0,0, 100, 100)

# <plugInFlowable module="mymodule" function="myFlowable">this data</plugInFlowable>

# note: this is wrapped in a "real" flowable so it doesn't need to inherit from platypus.Flowable
class myFlowable:
    def __init__(self, data):
        print "myFlowable init", data
    def wrap(self, w, h):
        print "myFlowable wrap", w, h
        return (0,0)
    def draw(self):
        self.canv.line(0,0,100,0)
        print "myFlowable drew a line", (0,0,100,0)

from reportlab.platypus.xpreformatted import XPreformatted
from reportlab.platypus.flowables import Flowable
from reportlab.lib.styles import getSampleStyleSheet
class myPreformatted(XPreformatted):
    """This is used by test_009_splitting under the test directory. It
    has been placed here to make sure that it is available in any
    standard installation of RML."""
    def __init__(self, text=None, style=getSampleStyleSheet()["Normal"],bulletText = None, dedent=0, frags=None):
        if text is None: text = """This page tests splitting - this is a pluginFlowable from
mymodule.py, using XPreformatted a reportlab style 'Normal' . It
should split between the two frames on this page. These frames should
be ON A NEW PAGE, otherwise this test has FAILED. This page tests
splitting - this XPreformatted should split between the two frames on
this page. This page tests splitting - this XPreformatted should split
between the two frames on this page. This page tests splitting - this
XPreformatted should split between the two frames on this page. This
page tests splitting - this XPreformatted should split between the two
frames on this page."""
        XPreformatted.__init__(self,text,style,bulletText,frags,dedent)

class linkURL(Flowable):
	def __init__(self, URL, text=None):
		self._URL = URL
		self._text = text or URL

	def wrap(self, w, h):
		c = self.canv
		fs = c._fontsize
		w = c.stringWidth(self._text,c._fontname,fs)
		self._width, self._height = w, 1.2*fs
		return (w,self._height)

	def draw(self):
		c = self.canv
		w, h = self._width, self._height
		c.drawString(0,h/6.,self._text)
		c.linkURL(self._URL,(0,0,w,h),relative=1,color=None,dashArray=None)

def _getArgs(*args,**kw):
	return args, kw

def _evalArgs(data):
	if data[0]!='(': data = '(%s)' % data
	return eval('_getArgs'+data)

def linkRect(canv,data):
	args, kw = _evalArgs(data)
	apply(canv.linkRect,args,kw)

def bookmarkPage(canv,name):
	canv.bookmarkPage(name)
