;
0sDc           @   s  d  Z  d Z d k Z d k l Z d k l Z d k l Z d k	 l
 Z
 d k l Z d k l Z l Z d	 e Z d
 e Z e d d d d d d d d d e d d e e  Z e d d d e d d d e d d	 e e  Z e d d d e d d d e d d e e  Z e d d d e d d d e d d e e  Z e d d d e d d d e d d e e  Z e d d d f d d f d  f g  Z d! e f d"     YZ d# e f d$     YZ d% e f d&     YZ d S('   s  
This module defines a single TableOfContents() class that can be used to
create automatically a table of tontents for Platypus documents like
this:

    story = []
    toc = TableOfContents()
    story.append(toc)
    # some heading paragraphs here...
    doc = MyTemplate(path)
    doc.multiBuild(story)

The data needed to create the table is a list of (level, text, pageNum)
triplets, plus some paragraph styles for each level of the table itself.
The triplets will usually be created in a document template's method
like afterFlowable(), making notification calls using the notify()
method with appropriate data like this:

    (level, text, pageNum) = ...
    self.notify('TOCEntry', (level, text, pageNum))

As the table of contents need at least two passes over the Platypus
story which is why the moultiBuild0() method must be called.

The level<NUMBER>ParaStyle variables are the paragraph styles used
to format the entries in the table of contents. Their indentation
is calculated like this: each entry starts at a multiple of some
constant named delta. If one entry spans more than one line, all
lines after the first are indented by the same constant named
epsilon.
s>    $Id: tableofcontents.py 2385 2004-06-17 15:26:05Z rgbecker $ N(   s   enums(   s   cm(   s   ParagraphStyle(   s	   Paragraph(   s   IndexingFlowable(   s
   TableStyles   Tablei   f0.5s   names	   LevelZeros   fontNames   Times-Romans   fontSizei
   s   leadingi   s   firstLineIndents
   leftIndenti    s   LevelOnes   parents   LevelTwoi   s
   LevelThreei   s	   LevelFouri   s   VALIGNis   TOPs   TableOfContentsc           B   st   t  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d d  Z RS(   s   This creates a formatted table of contents.

    It presumes a correct block of data is passed in.
    The data block contains a list of (level, text, pageNumber)
    triplets.  You can supply a paragraph style for each level
    (starting at zero).
    c         C   sR   g  |  _ d |  _ t t t t t g |  _ t	 |  _
 t |  _ g  |  _ g  |  _ d  S(   NiH   (   s   selfs   entriess   rightColumnWidths   levelZeroParaStyles   levelOneParaStyles   levelTwoParaStyles   levelThreeParaStyles   levelFourParaStyles   levelStyless   defaultTableStyles
   tableStyles   Nones   _tables   _entriess   _lastEntries(   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   __init__g   s    					c         C   s   |  i |  _ |  i   d  S(   N(   s   selfs   _entriess   _lastEntriess   clearEntries(   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   beforeBuildu   s    c         C   s   d Sd  S(   Ni   (    (   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys
   isIndexing{   s    c         C   s   |  i |  i j Sd  S(   N(   s   selfs   _entriess   _lastEntries(   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   isSatisfied   s    c         C   s7   | d j o& | \ } } } |  i | | |  n d S(   s   The notification hook called to register all kinds of events.

        Here we are interested in 'TOCEntry' events only.
        s   TOCEntryN(   s   kinds   stuffs   levels   texts   pageNums   selfs   addEntry(   s   selfs   kinds   stuffs   pageNums   levels   text(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   notify   s     c         C   s   g  |  _ d  S(   N(   s   selfs   _entries(   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   clearEntries   s    c         C   sd   t  |  t  d  j p
 t d  | t |  i  j  p t d |  |  i i | | | f  d S(   s   Adds one entry to the table of contents.

        This allows incremental buildup by a doctemplate.
        Requires that enough styles are defined.i   s   Level must be an integersZ   Table of contents must have a style defined for paragraph level %d before you add an entryN(
   s   types   levels   AssertionErrors   lens   selfs   levelStyless   _entriess   appends   texts   pageNum(   s   selfs   levels   texts   pageNum(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   addEntry   s     #$c         C   s1   x* | D]" \ } } } |  i | | |  q Wd S(   s   Bulk creation of entries in the table of contents.

        If you knew the titles but not the page numbers, you could
        supply them to get sensible output on the first run.N(   s   listOfEntriess   levels   texts   pageNums   selfs   addEntry(   s   selfs   listOfEntriess   texts   pageNums   level(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys
   addEntries   s      c      
   C   s0  | |  i |  i f } t |  i  d j o d d d f g } n
 |  i } g  } x | D]{ \ } }
 } |  i | }	 t d d | d |	 d d d t i  } t |
 |	  } t t |  |  } | i | | g  qX Wt | d | d	 |  i |  _ |  i i |  i | |  \ |  _ |  _ |  i |  i f Sd
 S(   s,   All table properties should be known by now.i    s!   Placeholder for table of contentss   names   leftColLevel%ds   parents
   leftIndents	   alignments	   colWidthss   styleN(   s
   availWidths   selfs   rightColumnWidths   widthss   lens   _lastEntriess   _tempEntriess	   tableDatas   levels   texts   pageNums   levelStyless   leftColStyles   ParagraphStyles   enumss   TA_RIGHTs   rightColStyles	   Paragraphs   leftParas   strs	   rightParas   appends   Tables
   tableStyles   _tables   wrapOns   canvs   availHeights   widths   height(   s   selfs
   availWidths   availHeights   rightColStyles   pageNums   levels   widthss   leftParas	   rightParas   leftColStyles   texts   _tempEntriess	   tableData(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   wrap   s(     	 'c         C   s   |  i i |  i | |  Sd S(   s   At this stage we do not care about splitting the entries,
        we will just return a list of platypus tables.  Presumably the
        calling app has a pointer to the original TableOfContents object;
        Platypus just sees tables.
        N(   s   selfs   _tables   splitOns   canvs
   availWidths   availHeight(   s   selfs
   availWidths   availHeight(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   split   s     i    c         C   s   |  i i | | | |  d S(   s   Don't do this at home!  The standard calls for implementing
        draw(); we are hooking this in order to delegate ALL the drawing
        work to the embedded table object.
        N(   s   selfs   _tables   drawOns   canvass   xs   ys   _sW(   s   selfs   canvass   xs   ys   _sW(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   drawOn   s     (   s   __name__s
   __module__s   __doc__s   __init__s   beforeBuilds
   isIndexings   isSatisfieds   notifys   clearEntriess   addEntrys
   addEntriess   wraps   splits   drawOn(    (    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   TableOfContents^   s    					
			
	"		s   SimpleIndexc           B   sk   t  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
 d  Z RS(   s   This creates a very simple index.

    Entries have a string key, and appear with a page number on
    the right.  Prototype for more sophisticated multi-level index.c         C   s=   h  |  _ h  |  _ t |  _ t d d d d d d  |  _ d  S(   Ns   names   indexs   fontNames   Times-Romans   fontSizei   (   s   selfs   _entriess   _lastEntriess   Nones   _tables   ParagraphStyles	   textStyle(   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   __init__   s    				c         C   s   d Sd  S(   Ni   (    (   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys
   isIndexing   s    c         C   s   |  i |  i j Sd  S(   N(   s   selfs   _entriess   _lastEntries(   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   isSatisfied   s    c         C   s    |  i i   |  _ |  i   d  S(   N(   s   selfs   _entriess   copys   _lastEntriess   clearEntries(   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   beforeBuild   s    c         C   s   h  |  _ d  S(   N(   s   selfs   _entries(   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   clearEntries   s    c         C   s1   | d j o  | \ } } |  i | |  n d S(   s   The notification hook called to register all kinds of events.

        Here we are interested in 'IndexEntry' events only.
        s
   IndexEntryN(   s   kinds   stuffs   texts   pageNums   selfs   addEntry(   s   selfs   kinds   stuffs   texts   pageNum(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   notify   s     c         C   sE   |  i i |  o |  i | i t |   n | g |  i | <d S(   s   Allows incremental buildupN(   s   selfs   _entriess   has_keys   texts   appends   strs   pageNum(   s   selfs   texts   pageNum(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   addEntry   s     c         C   s   |  i i |  i | |  Sd S(   s   At this stage we do not care about splitting the entries,
        we will just return a list of platypus tables.  Presumably the
        calling app has a pointer to the original TableOfContents object;
        Platypus just sees tables.
        N(   s   selfs   _tables   splitOns   canvs
   availWidths   availHeight(   s   selfs
   availWidths   availHeight(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   split  s     c   	      C   s   t  |  i  d j o d d d d g f g } n |  i i   } | i   g  } xY | D]Q \ } } | d t	 i
 t t |  d  } t | |  i  } | i | g  qX Wt | d | g |  _ |  i i |  i | |  \ |  _ |  _ |  i |  i f Sd S(	   s,   All table properties should be known by now.i    s   Placeholder for indexi   i   s   : s   , s	   colWidthsN(   s   lens   selfs   _lastEntriess   _tempEntriess   itemss   sorts	   tableDatas   texts   pageNumberss   strings   joins   maps   strs   allTexts	   Paragraphs	   textStyles   paras   appends   Tables
   availWidths   _tables   wrapOns   canvs   availHeights   widths   height(	   s   selfs
   availWidths   availHeights   pageNumberss   allTexts   paras   texts   _tempEntriess	   tableData(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   wrap  s     
 #'i    c         C   s   |  i i | | | |  d S(   s   Don't do this at home!  The standard calls for implementing
        draw(); we are hooking this in order to delegate ALL the drawing
        work to the embedded table object.
        N(   s   selfs   _tables   drawOns   canvass   xs   ys   _sW(   s   selfs   canvass   xs   ys   _sW(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   drawOn&  s     (   s   __name__s
   __module__s   __doc__s   __init__s
   isIndexings   isSatisfieds   beforeBuilds   clearEntriess   notifys   addEntrys   splits   wraps   drawOn(    (    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   SimpleIndex   s    										s   ReferenceTextc           B   s>   t  Z d  Z d   Z d   Z d   Z d   Z d d  Z RS(   sV   Fakery to illustrate how a reference would work if we could
    put it in a paragraph.c         C   s@   | |  _  | |  _ t d  |  _ t |  _ d |  _ t |  _	 d  S(   Ns   tmpi(
   s   textPatterns   selfs	   targetKeys   targets   ParagraphStyles	   paraStyles   Nones   _lastPageNums   _pageNums   _para(   s   selfs   textPatterns	   targetKey(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   __init__0  s    				c         C   s   |  i |  _ d  S(   N(   s   selfs   _pageNums   _lastPageNum(   s   self(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   beforeBuild8  s    c         C   s>   | d j o- | \ } } | |  i j o | |  _ q: n d  S(   Ns   Target(   s   kinds   stuffs   keys   pageNums   selfs   targets   _pageNum(   s   selfs   kinds   stuffs   pageNums   key(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   notify;  s    c         C   s<   |  i |  i } t | |  i  |  _ |  i i | |  Sd  S(   N(
   s   selfs   textPatterns   _lastPageNums   texts	   Paragraphs	   paraStyles   _paras   wraps
   availWidths   availHeight(   s   selfs
   availWidths   availHeights   text(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   wrapA  s    i    c         C   s   |  i i | | | |  d  S(   N(   s   selfs   _paras   drawOns   canvass   xs   ys   _sW(   s   selfs   canvass   xs   ys   _sW(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   drawOnF  s    (   s   __name__s
   __module__s   __doc__s   __init__s   beforeBuilds   notifys   wraps   drawOn(    (    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   ReferenceText-  s    				(   s   __doc__s   __version__s   strings   reportlab.libs   enumss   reportlab.lib.unitss   cms   reportlab.lib.styless   ParagraphStyles   reportlab.platypus.paragraphs	   Paragraphs   reportlab.platypus.doctemplates   IndexingFlowables   reportlab.platypus.tabless
   TableStyles   Tables   deltas   epsilons   levelZeroParaStyles   levelOneParaStyles   levelTwoParaStyles   levelThreeParaStyles   levelFourParaStyles   defaultTableStyles   TableOfContentss   SimpleIndexs   ReferenceText(   s   __version__s   IndexingFlowables   strings   cms   levelThreeParaStyles
   TableStyles   levelZeroParaStyles   TableOfContentss   levelFourParaStyles   epsilons   ReferenceTexts   SimpleIndexs	   Paragraphs   levelTwoParaStyles   levelOneParaStyles   deltas   Tables   enumss   defaultTableStyles   ParagraphStyle(    (    sL   /home/packages/reportlab/reportlab_2_0/reportlab/platypus/tableofcontents.pys   ?"   sP   	

					'}R