o
    öX¤Sl ã                   @   s  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dZdZdZddlmZmZmZmZ G d	d
„ d
ƒZdd„ Zdd„ ZddlmZ dd„ Zdd„ Zdd„ Zefdd„Zdd„ ZG dd„ dƒZG dd„ dƒZddd d!d"d#d$d%d&d'd(d)d*d+œZG d,d-„ d-eƒZ d.d/„ Z!d|d1d2„Z"G d3d4„ d4eƒZ#G d5d6„ d6ƒZ$G d7d8„ d8ƒZ%G d9d:„ d:e%ƒZ&G d;d<„ d<e%ƒZ'G d=d>„ d>e'ƒZ(G d?d@„ d@e'ƒZ)G dAdB„ dBe%ƒZ*G dCdD„ dDƒZ+dEdF„ Z,d|dGdH„Z-d}dIdJ„Z.G dKdL„ dLƒZ/e/ƒ Z0G dMdN„ dNe/ƒZ1G dOdP„ dPe1ƒZ2G dQdR„ dRe1ƒZ3dSdT„ Z4dUZ5dVZ6dWdX„ Z7e1dYƒZ8dZd[d\d]d^efd_e
fd`dage4dbƒ dce8fg e4ddƒ dee8fdfd^efdgd_e
fd`dag e4dhƒ dfd^efdidjd`dadZdkg e4dlƒ dce0fg e4dmƒ dee0fdndodpdqdrdpdndsdpdtd[dudfd^efdvdwd`dag e4dxƒ dtdfg Z9dydz„ Z:e;d{k�r‡e:ƒ  d0S d0S )~a!  new experimental paragraph implementation

Intended to allow support for paragraphs in paragraphs, hotlinks,
embedded flowables, and underlining.  The main entry point is the
function

def Paragraph(text, style, bulletText=None, frags=None)

Which is intended to be plug compatible with the "usual" platypus
paragraph except that it supports more functionality.

In this implementation you may embed paragraphs inside paragraphs
to create hierarchically organized documents.

This implementation adds the following paragraph-like tags (which
support the same attributes as paragraphs, for font specification, etc).

- Unnumberred lists (ala html)::

    <ul>
        <li>first one</li>
        <li>second one</li>
    </ul>


Also <ul type="disc"> (default) or <ul type="circle">, <ul type="square">.

- Numberred lists (ala html)::

    <ol>
        <li>first one</li>
        <li>second one</li>
    </ol>

Also <ul type="1"> (default) or <ul type="a">, <ul type="A">.

- Display lists (ala HTML):

For example

<dl bulletFontName="Helvetica-BoldOblique" spaceBefore="10" spaceAfter="10">
<dt>frogs</dt> <dd>Little green slimy things. Delicious with <b>garlic</b></dd>
<dt>kittens</dt> <dd>cute, furry, not edible</dd>
<dt>bunnies</dt> <dd>cute, furry,. Delicious with <b>garlic</b></dd>
</dl>

ALSO the following additional internal paragraph markup tags are supported

<u>underlined text</u>

<a href="http://www.reportlab.com">hyperlinked text</a>
<a href="http://www.reportlab.com" color="blue">hyperlinked text</a>

<link destination="end" >Go to the end (go to document internal destination)</link>
<link destination="start" color="cyan">Go to the beginning</link>

<setLink destination="start" color="magenta">This is the document start
  (define document destination inside paragraph, color is optional)</setLink>

é    ©ÚstringWidth)Úfp_str)ÚFlowable©Úcolors)Ú_baseFontNamegñhãˆµøä>)ÚTA_LEFTÚ	TA_CENTERÚTA_RIGHTÚ
TA_JUSTIFYc                   @   s„   e Zd Zd dd„ZdZdd„ Zdd„ Zd!d
d„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )"ÚparagraphEngineNc                 C   s|   ddl m} |d u rg }g | _|| _d | _| _d| _d| _d| _d| _	|| _
d | _ | _| _ddlm} || _g | _d S )Nr   ©Úblackç        Ú	Helveticaé
   é   )r	   )Úreportlab.lib.colorsr   ÚlineOpHandlersÚprogramÚindentÚrightIndentÚ
baseindentÚfontNameÚfontSizeÚleadingÚ	fontColorÚxÚyÚriseÚreportlab.lib.enumsr	   Ú	alignmentÚtextStateStack)Úselfr   r   r	   © r%   úI/var/www/html/env/lib/python3.10/site-packages/reportlab/platypus/para.pyÚ__init__W   s   
zparagraphEngine.__init__)	r   r   r   r   r   r   r   r    r"   c                 C   s6   g }| j D ]}t| |ƒ}| |¡ q| j|g | _|S ©N)ÚTEXT_STATE_VARIABLESÚgetattrÚappendr#   ©r$   ÚstateÚvarÚvalr%   r%   r&   ÚpushTextStatem   s   

zparagraphEngine.pushTextStatec                 C   sP   | j d }| j d d… | _ |d d … }| jD ]}|d }|d= t| ||ƒ qd S )Néÿÿÿÿr   )r#   r)   Úsetattrr,   r%   r%   r&   ÚpopTextStatex   s   

ýzparagraphEngine.popTextStater   c                 C   s0  | j  ¡ }|dd… }g }|}|r|| _d}	d}
|�r|	�r| j}| j}|| | }| j  ¡ }|tk r>td| j| j|f ƒ‚z|  ||¡\}}}}}}}W n   ‚ |
| }
| j}||krb|| }n	d}	| j  |¡ n˜| j	}||d… }|sy|d= |t
kr‹|r…t||ƒ}n|  |¡}ng|tkr¤|r—t||ƒ}n|  |¡}|  |||¡}nN|tkr½|r°t||ƒ}n|  |¡}|  |||¡}n5|tkrê|rÖ|rÖ|rÎt|||ƒ}n$|  |||¡}n|rÞt||ƒ}n|  |¡}trétdƒ ntdt|ƒ ƒ‚|sù|  |¡}| |¡ |�r|	s| j  ¡ }| j  |¡ || }||||fS )zCreturn program with line operations added if at least one line fitsNé   r   z#indents %s %s too wide for space %sr1   z2no justify because line is not full or end of parazbad alignment )Ú__dict__Úcopyr   r   r   ÚTOOSMALLSPACEÚ
ValueErrorÚfitLineÚupdater"   r	   Ú
stringLineÚ
shrinkWrapr
   ÚcenterAlignr   Ú
rightAlignr   ÚsimpleJustifyAlignÚjustifyAlignÚdebugÚprintÚreprÚcleanProgramÚextend)r$   ÚmaxwidthÚ	maxheightr   r   Ú
startstateÚ	remainderÚlineprogramÚheightremainingÚroomÚcursorcountr   r   Ú	linewidthÚbeforelinestateÚ
lineIsFullÚlineÚcursorÚcurrentLengthÚ
usedIndentÚ	maxLengthÚjustStringsr"   Ú	laststateÚ
heightusedr%   r%   r&   Úformat„   sˆ   


ÿ

ÿ





€


§
ZzparagraphEngine.formatc                 C   s
   | j  ¡ S r(   )r5   r6   ©r$   r%   r%   r&   ÚgetStateò   s   
zparagraphEngine.getStatec                 C   s   | j  |¡ d S r(   )r5   r:   )r$   r-   r%   r%   r&   Ú
resetStateö   s   zparagraphEngine.resetStatec           /      C   sÞ  ddl m} | j}|| | j }d}g }d}d}	d}
t|ƒ}d}d}d}| j}| j}|d||ƒ}d}|�sÞ||k �rÞ|| }t|tƒsHt	|dƒr²|}d}t	|dƒr[d}| 
| ¡}d}n |}| ¡ }|rj||||ƒ}nd}|ry|sr|
ry|d dk}nd}|}|rƒ|| }|
| }||kr’|s’d}d}	n|r™| |¡ |r | |¡ t|ƒtkr®| | ¡ |}
d}�nt|tƒrÝd}t|ƒ}|tkrÛ|
| }||krÎ|sÎd}n|tkrÙ|}
| |¡ d}�nót|tƒ�rÈd}|d }|dkrü| |¡ |d }d }}�nÔ|d	k�r#| j}|\}}t|tƒ�rtt|ƒ }| _n| }| _| |¡ �n­|d
k�r>|\}} |  }| _|d||ƒ}| |¡ �n’|dk�r�|\}}!tt|!ƒƒ}"t|!tƒ�r}|!dd… dk�re| j|"  }| _n|!dd… dk�rw| j|"  }| _n|" }| _n|" }| _|d||ƒ}| |¡ �nA|dk�r¢|\}}#|#| _| |¡ �n.|dk�rÉ|\}}$| j|$  }%| _|�rÂt|%|ƒ}|| | j }| |¡ �n|dk�rØ|  ¡  | |¡ nø|dk�rúz|  ¡  W n   ‚ | j}| j}|d||ƒ}| |¡ nÖ|dk�rD|\}}&}%}'}"|%| j }%||&|%|'|"f}|�stdƒ‚t||&|'|"ƒƒ}(t|d|'|"ƒƒ}|%| |( })t|)|ƒ}|�r>|| | j }| |¡ nŒ|dk�rc|\}}$| j|$ | _|�r]|| | j }| |¡ nm|dk�rz|\}}*| j|*  }+| _| |¡ nV|dk�rŒ|\}},|,| _| |¡ nD|dk�r¢|\}}-| |¡ | j|-g | _n.|dk�rÀ|\}}-| jdd… }.|. |-¡ |.| _| |¡ ntdt|ƒ ƒ‚tdt|ƒ ƒ‚|�s×|d }|�sÞ||k s:|�sæ| d¡ |	|||
|||fS )z(fit words (and other things) onto a liner   r   r4   Nú Úwidthr1   ÚnextLineÚcolorÚfaceÚsizeú+ú-r   r   ÚpushÚpopÚbulletúbullet not at beginning of liner   r    ÚalignÚlineOperationÚendLineOperationz*at format time don't understand indicator z-op must be string, float, instance, or tuple ©r_   r   )Úreportlab.pdfbase.pdfmetricsr   r   r   Úlenr   r   Ú
isinstanceÚstrÚhasattrr^   Ústripr+   Úabsr7   ÚfloatÚtupler   r*   r   r   Úmaxr0   r3   r   r8   r    r"   r   ÚremoverC   )/r$   r   ÚtotalLengthr   rT   rU   ÚdonerQ   rR   rP   rS   Ú	maxcursorÚ	needspaceÚfirstÚ
terminatedr   r   Ú
spacewidthrV   ÚopcodeÚlastneedspacer^   Ú
saveopcodeÚ	fullwidthÚ	newlengthÚaopcodeÚ
nextLengthÚ	indicatorÚoldcolorÚiÚ	colornamer`   ÚfontnameÚfontsizerb   r   Ú	incrementr   rg   ÚfontÚbulletwidthÚ	bulletminr    Únewriser"   ÚhandlerÚhr%   r%   r&   r9   þ   sB  





€





















 �Ë <
zparagraphEngine.fitLinec                 C   s(   || }|d }|t kr|  ||¡S |S )Nç       @©r7   ÚinsertShift)r$   rQ   Ú
lineLengthrU   ÚdiffÚshiftr%   r%   r&   r=   Ò  s
   zparagraphEngine.centerAlignc                 C   s    || }|t kr|  ||¡S |S r(   r”   )r$   rQ   r–   rU   r˜   r%   r%   r&   r>   Ù  s   zparagraphEngine.rightAlignc                 C   sF   g }d}|D ]}|rt |tƒst|dƒr| |¡ d}| |¡ q|S )Nr4   r^   r   )ro   rp   rq   r+   )r$   rQ   r˜   Úresultr|   Úer%   r%   r&   r•   à  s   
zparagraphEngine.insertShiftc                 C   s  || }d}d}|D ] }t |tƒr|tkr|r|d }q
|r*t |tƒs(t|dƒr*d}q
|dk r1|S |t|ƒ }	|	tkr=|S d}d}g }
d}t|ƒ}||k r€|| }|
 |¡ |ret |tƒsbt|dƒred}nt |tƒrx|tkrx|rx||	 }||
d< |d }||k sM|
S )Nr   r4   r^   r1   )ro   rt   r7   rp   rq   rn   r+   )r$   rQ   r–   rU   r—   Ú
spacecountÚvisiblerš   r|   r˜   r™   rR   ÚnlineÚexpandedr%   r%   r&   r@   ë  s<   
€
ø	zparagraphEngine.justifyAlignc           
      C   s2  g }d}t |ƒ}||k r—|| }t|tƒrŠ||d k rŠ|g}d}|d }|| }||k rtt|ttfƒrtt|tƒrS|dk rC|dkrC| }|dk rN|dkrN| }|| }n
t|tƒr]| |¡ |d }||k ri|| }||k rtt|ttfƒs3d |¡}	| |	¡ | t|ƒ¡ |d }n| |¡ |d }||k s|S )Nr   r4   r   r]   )rn   ro   rp   rt   r+   Újoin)
r$   rQ   r™   ÚindexÚmaxindexrš   Ú
thestringsÚ	thefloatsÚnexteÚsr%   r%   r&   r<   (  s>   



ô



ãzparagraphEngine.shrinkWrapc                 C   sx  g }d}|D ]6}t |tƒr*|dk r|dkr| }|dk r#|dkr#| }t|ƒ| }qt|ƒtkr5| |¡ | |¡ d}q|rD| |¡ d}ttt|ƒd ƒƒ}|rºd}|D ]a}|d }|| }	|| }
d}t |	tƒszt |
tƒszt	|	dƒszt	|
dƒr}d}n.t |	t
ƒr«|	d }t |
t
ƒr |
d }d}|dkrŸ|dkrŸ|dkrŸd}nt |
tƒr«|dkr«d}|r·|
||< |	||< d}qV|sR|S )zcollapse adjacent spacingsr   r4   r^   rk   rj   )ro   rt   rs   r7   r+   ÚlistÚrangern   rp   rq   ru   )r$   rQ   r™   Úlastrš   ÚchangeÚrliner    Ú	nextindexÚthisÚnextÚdoswapÚthisindicatorÚnextindicatorr%   r%   r&   rD   N  sf   




ÿþþ

€
€ãzparagraphEngine.cleanProgramc           +   	   C   sr  |j }|j}| j ¡ }d}d}| | j¡ | j}	| j}
| j}d}|D �]ˆ}t	|t
ƒs/t|dƒrƒ|sXt|
ƒtkrG| dt|
dƒ ¡ | j|
 | _| jD ]}| | j| j| ||¡ qJd}|| jksd|| jkrp| j}| j}| ||¡ t	|t
ƒr{| |¡ q"| | ||¡ q"t	|tƒr¡t|ƒ}|tkr | dt|dƒ ¡ | j| | _q"t	|tƒ�r¤|d }|dkrå|\}}| j}| j}| j| j  }| _|	 }| _| j}
| j}d}| jD ]}| ||| ||¡ qÒ| ||¡ q"|dk�r| j}|\}}t	|t
ƒrÿtt|ƒ }| _n| }| _||k�r| |¡ q"|dk�r|\}}|| _q"|d	k�rl|\}}tt|ƒƒ}t	|t
ƒ�r[|dd… d
k�rC| j|  }| _n|dd… dk�rU| j|  }| _n| }| _n| }| _|| _| | j| j¡ q"|dk�ry|\}}|| _q"|dk�r�|\}}| j|  }| _t|
|ƒ}
q"|dk�rš|   ¡  q"|dk�r¹| j}| j}| j} |  !¡  || jk�r¸| | j¡ q"|dk�rÈ|\}}!| "|!¡ q"|dk�r |\}}"}}}t| j|	 ƒtk�rât#dƒ‚tt$|"||ƒƒ}#tt$d||ƒƒ}$||$ |# }%|%|
k�rÿ|%}
| %|d¡ | ||¡ | |"¡ | %| d¡ | | j| j¡ q"|dk�r0|\}}| j| | _q"|dk�rG|\}}&| j&|&  }'| _&| '|'¡ q"|dk�rT|\}}(|(| _(q"|dk�rp|\}}| | j| j| ||¡ | j|g | _q"|dk�rœ|\}}| | j| j| ||¡ | jdd…  })| _||)v �rš| j )|¡ q"	 q"t#dt*|ƒ ƒ‚t#dt*|ƒ ƒ‚| j ¡ }*| j +|¡ |*S )zrender the line(s)Nr   r^   z%s Tdr4   r_   r`   ra   rb   rc   rd   r   r   re   rf   ÚwordSpacingrg   rh   r]   r   r    ri   rj   rk   zdon't understand indicator z!op must be string float or tuple ),Ú_escapeÚ_coder5   r6   ÚsetFillColorr   r   r   r   ro   rp   rq   rs   r7   r+   r   r   Ústart_atr   r   r   ÚsetFontÚtextOutÚexecutert   ru   r   Úend_atÚsetTextOriginr*   r   rv   r0   r3   ÚsetWordSpacer8   r   Ú
moveCursorr    ÚsetRiser"   rw   rC   r:   )+r$   r   ÚcanvasÚ
textobjectÚescapeÚcoderH   r�   rb   ÚxstartÚthislineindentÚthislinerightIndentÚindentedr   r‘   r†   rˆ   Úendallmarksr   r   ÚnewyÚnewxr‡   r‰   r`   rŠ   r‹   r   r   rŒ   r   ÚoldfontÚoldsizeÚwsrg   rŽ   r~   r�   r    r�   r"   ÚnewhrW   r%   r%   r&   Ú
runOpCodes�  s  




€






€







€










zparagraphEngine.runOpCodesr(   )r   )Ú__name__Ú
__module__Ú__qualname__r'   r)   r0   r3   rY   r[   r\   r9   r=   r>   r•   r@   r<   rD   rÍ   r%   r%   r%   r&   r   U   s"    

n U=&Ar   c                 C   sZ   g }| D ]}t |tƒr| |¡ qd |¡}|t|ƒg}d}| r+| d |kr+| |¡ |S )zEsimple case: line with just strings and spacings which can be ignoredr]   rl   r1   )ro   rp   r+   rŸ   rt   )rQ   ÚlengthÚstringsr   Útextr™   Únextlinemarkr%   r%   r&   r;   =  s   

€

r;   c                 C   s¢   g }| dd… D ]}t |tƒr| |¡ qt|ƒd }|| }d |¡}|dkr;|dkr;|t|ƒ }d|f||dg}	n||dg}	d}
| rO| d |
krO|	 |
¡ |	S )	z&simple justification with only stringsNr1   r4   r]   r   r±   )r±   r   rl   )ro   rp   r+   rn   rŸ   rt   )rQ   rS   rU   rÒ   r   ÚnspacesÚslackrÓ   Úwordspacingr™   rÔ   r%   r%   r&   r?   K  s    

€


r?   r   c                 C   s,   |   ¡ dv rdS |   ¡ dv rdS td|  ƒ‚)N)ÚYÚYESÚTRUEÚ1r4   )ÚNÚNOÚFALSEÚ0r   z+true/false attribute has illegal value '%s')Úupperr8   )rÓ   r%   r%   r&   ÚreadBoola  s
   rá   c                 C   s<   |   ¡ }|dkr
tS |dkrtS |dv rtS |dkrtS d S )NÚLEFTÚRIGHT)ÚCENTERÚCENTREÚJUSTIFY)rà   r	   r   r
   r   )rÓ   Úupr%   r%   r&   ÚreadAlignmenti  s   ÿrè   c                 C   s²   |   ¡ } zt| ƒW S  tyX   |  ¡ } | dd… | dd… }}|  ¡ }zt|ƒ}W n ty8   td|  ƒ‚w zdddddœ| }W n tyQ   td|  ƒ‚w ||  Y S w )	zIRead a dimension measurement: accept "3in", "5cm",
    "72 pt" and so on.Néþÿÿÿzinvalid length attribute '%s'éH   g^|Åb±X<@gåÉjµZ­@r4   )ÚinÚcmÚmmÚpt)rr   rt   r8   ÚlowerÚKeyError)rÓ   Ú
numberTextÚunitsÚnumberÚ
multiplierr%   r%   r&   Ú
readLengtht  s2   
ÿüûÿîrõ   c                    sb   |   ¡ } | dd… dkr| dd… dkr| dd… } |  d¡}dd„ |D ƒ}‡ fd	d„|D ƒ}|S )
z0from "(2, 1)" or "2,1" return [2,1], for exampleNr4   ú(r1   ú)ú,c                 S   s   g | ]}|  ¡ ‘qS r%   )rr   ©Ú.0r¥   r%   r%   r&   Ú
<listcomp>”  ó    z"lengthSequence.<locals>.<listcomp>c                    s   g | ]}ˆ |ƒ‘qS r%   r%   rù   ©Ú	converterr%   r&   rû   •  rü   )rr   Úsplit)r¥   rþ   Úslr%   rý   r&   ÚlengthSequenceŽ  s    
r  c                 C   sÈ   | sdS ddl m} ddlm} | d |v r|j|  S t| ƒ}d}dt|ƒ  kr0dks5J |ƒ‚ J |ƒ‚d}tt|ƒƒD ]}|| d	ksIJ |ƒ‚q=t|ƒdkrW|j}||Ž S t|ƒdkr`|j	}||Ž S )
zCRead color names or tuples, RGB or CMYK, and return a Color object.Nr   r   )Úlettersz:Color tuple must have 3 (or 4) elements for RGB (or CMYC).é   é   z*Color tuple must have all elements <= 1.0.ç      ð?)
Úreportlab.libr   Ústringr  r5   r  rn   r§   ÚColorÚ	CMYKColor)rÓ   r   r  ÚtupÚmsgrˆ   ÚcolClassr%   r%   r&   Ú	readColor™  s$   
(þr  c                   @   sT   e Zd ZegZegZegZegZegZe	gZ
egZegZegZegZegZegZdS )ÚStyleAttributeConvertersN)rÎ   rÏ   rÐ   rõ   r   r   Ú
leftIndentr   ÚfirstLineIndentrè   r"   ÚspaceBeforeÚ
spaceAfterÚbulletFontSizeÚbulletIndentr  Ú	textColorÚ	backColorr%   r%   r%   r&   r  ¯  s    
r  c                   @   s^   e Zd ZdZdZeZdZdZdZ	dZ
dZeZdZdZeZdZdZeZdZddd„Zd	d
„ ZdS )ÚSimpleStylez6simplified paragraph style without all the fancy stuffÚbasicr   r   r   Nc                 K   sD   | j }|r|j  ¡ D ]\}}|||< q
| ¡ D ]\}}|||< qd S r(   )r5   Úitems)r$   ÚnameÚparentÚkwÚmydictÚaÚbr%   r%   r&   r'   Ï  s   

ÿzSimpleStyle.__init__c                 C   sN   |  ¡ D ] }|| }|d ur$tt|ƒrtt|ƒd }||ƒ}t| ||ƒ qd S ©Nr   )Úkeysrq   r  r*   r2   )r$   Ú
dictionaryÚkeyÚvaluerþ   r%   r%   r&   ÚaddAttributes×  s   
€úzSimpleStyle.addAttributesr(   )rÎ   rÏ   rÐ   Ú__doc__r  r   r   r   r   r  r   r  r	   r"   r  r  ÚbulletFontNamer  r  r   r  r  r'   r%  r%   r%   r%   r&   r  ½  s&    
r  ÚHeading1ÚHeading2ÚHeading3ÚHeading4ÚHeading5ÚHeading6ÚTitleÚSubTitleÚNormalÚCodeÚUnorderedListÚOrderedListÚ
Definition)zh1.defaultStylezh2.defaultStylezh3.defaultStylezh4.defaultStylezh5.defaultStylezh6.defaultStyleztitle.defaultStylezsubtitle.defaultStyleúpara.defaultStylezpre.defaultStylezul.defaultStylezol.defaultStyleúli.defaultStylec                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚFastParazAparagraph with no special features (not even a single ampersand!)c                 C   s&   d|v rt dƒ‚|| _|| _d | _d S )Nú&zno ampersands please!)r8   ÚstyleÚ
simpletextÚlines)r$   r9  r:  r%   r%   r&   r'   ô  s
   
zFastPara.__init__c                 C   sð  | j }|| _| j}| j }|j}|j}|j}|j}	|j}
|j}| 	¡ }g }ddl
m} |d|	|
ƒ}g }d}|| | }|| | }||k rL|| | |fS ||k rT||fS | jd u ràd}d}t|ƒ}d}||k r¸|s¸|}|so|}|| }|||	|
ƒ}|r|| }|| }|r‰||k r•|d }|}| |¡ n| d |¡|t|ƒf¡ g }d}|| }|| |kr²d}||k r¸|ri|rÍ|sÍ| d |¡|t|ƒf¡ || }|| _|| _d ||d … ¡ }| _nd }| j}| j}|rò||| f}|S ||f}|S )Nr   r   r]   r4   )r:  ÚavailableWidthr9  r   r  r   r   r   r  rÿ   rm   r   r;  rn   r+   rŸ   ÚheightrI   )r$   r<  ÚavailableHeightr:  r9  rÓ   r   r  r   r�   rb   ÚfirstindentÚwordsr;  r   r~   ÚcurrentlineÚcurrentlengthÚfirstmaxlengthÚ	maxlengthrX   rR   Únwordsry   ÚthismaxlengthÚthiswordÚthiswordsizeÚ
nextlengthrI   r™   r%   r%   r&   Úwrapý  sz   
êþzFastPara.wrapc                 C   sP   | j }|j}||k rg S | j}|d u rtdƒ‚| j}|r%t||ƒ}| |gS | gS )Nzmust wrap before split)r9  r   r;  r8   rI   r7  )r$   r<  r>  r9  r   r;  rI   r­   r%   r%   r&   rÿ   E  s   
zFastPara.splitc                 C   s„  | j }| j}|j}|j}|j}|j}|j}|j}|j}	| j	}
|
j
}| j}|
 d|| ¡ |
 ¡ }|j}| ||¡ |jrB| |j¡ d}d}| j| }d}t|ƒ}||k r»|| \}}}|d }|}|rf|	}|tkrm|}n;|tkr||| }||d  }n,|tkr‰|| }|| }n|tkr¨|}||k r£|dkr£| || |d  ¡ n| d¡ | ||¡ | |¡ || }||k sU|
 |¡ d S )Nr   r4   r“   r  r   )r9  r;  r   r  r   r   r   r"   r  Úcanvr²   r=  Ú	translateÚ	beginTextr³   r¶   r  r´   r<  rn   r	   r
   r   r   r»   rº   r·   ÚdrawText)r$   r9  r;  r   r  r   r�   rb   r"   r?  ÚcrÀ   r=  r¿   rÁ   r|   r   Ú
basicWidthÚcountÚnlinesrÓ   rÑ   rE  Ú
thisindentr   Úextrar%   r%   r&   ÚdrawT  s^   



ézFastPara.drawc                 C   ó   | j jS r(   )r9  r  rZ   r%   r%   r&   ÚgetSpaceBefore‹  s   zFastPara.getSpaceBeforec                 C   rV  r(   )r9  r  rZ   r%   r%   r&   ÚgetSpaceAfter�  s   zFastPara.getSpaceAfterN)
rÎ   rÏ   rÐ   r&  r'   rJ  rÿ   rU  rW  rX  r%   r%   r%   r&   r7  ñ  s    	H7r7  c                  C   s8   i } ddl m} |ƒ }t ¡ D ]
\}}|| | |< q| S ©Nr   )ÚgetSampleStyleSheet©Úreportlab.lib.stylesrZ  ÚDEFAULT_ALIASESr  )r™   rZ  ÚstylesÚstylenamekeyÚstylenamevaluer%   r%   r&   ÚdefaultContext”  s   ra  Nc                 C   sœ   i }ddl m} | d ur2t ¡ D ]\}}|| v r| | ||< qt ¡ D ]\}}|| v r1| | ||< q#|ƒ }t ¡ D ]\}}||vrK||v rK|| ||< q9|S rY  r[  )Ú
stylesheetr™   rZ  r_  r`  r^  r%   r%   r&   ÚbuildContextœ  s"   €€€rc  c                   @   s8  e Zd ZdZdZdKdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dLdd„ZdMdd„Zdd„ ZdNdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ ZdOd$d%„Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Z d<d=„ Z!d>d?„ Z"d@dA„ Z#dBdC„ Z$dDdE„ Z%dFdG„ Z&dPdIdJ„Z'dS )QÚParar   Nc                 C   sn   || _ t|ƒ| _|| _|| _|| _g | _g | _d | _|| _	|s'|j
| _
|j| _d| _d| _|j| _|j| _d S r   )r   rc  ÚcontextÚ
parsedTextÚ
bulletTextÚstyle1r   ÚformattedProgramrI   r-   r  r  ÚboldÚitalicr   ra   r   rb   )r$   r9  rf  rg  r-   re  r   r%   r%   r&   r'   µ  s    
zPara.__init__c                 C   ó   | j S r(   )r  rZ   r%   r%   r&   rW  Ì  s   zPara.getSpaceBeforec                 C   rl  r(   )r  rZ   r%   r%   r&   rX  Ñ  s   zPara.getSpaceAfterc                 C   sÒ  t rtdt| ƒ||ƒ td| jƒ td| jƒ || _tƒ  | _}| j|_| j	}| j}| j
}|r4|d }n| jj}| j}d| _|rP| |¡ d|_d|_|d }	n| jj}	||	krad| _|d |fS |d u rm|d u rmtdƒ‚|sw|  |¡ | _}| js“| ||||¡\}}
}}|| _|| _|| _|
| _n| j}d }
|
r·|d }t| jd d || jd�| _|
| j_| j| j_d| _nd | _|}||krÄ|d }||f}t rç|\}}t|| ƒd	k rßtd
t||ƒ ƒ td||f|ƒ |S )NÚWRAPPINGz   r   r4   r   zneed parsedText for formatting©rf  rg  r-   re  gš™™™™™¹?gš™™™™™É?zexact match???zwrap is)rA   rB   Úidri  r   r>  r   Úmyenginer   rf  r-   rh  r   Úcansplitr\   r   r   r8   ÚcompileProgramrY   r=  rW   ÚremainderProgramrd  re  rI   r  rs   rC   )r$   r<  r>  Úprf  ri  r-   r   r   ÚneedatleastrI   rW   rX   r=  r™   Úwr’   r%   r%   r&   rJ  Õ  sr   


ÿ
ÿ
z	Para.wrapc                 C   sV   |dks| j s	g S || _| j}|d u rtdƒ‚|sg S | j}|r&| |g}|S | g}|S )Nr   zmust call wrap before split)rq  r>  ri  r8   rI   )r$   r<  r>  ri  rI   r™   r%   r%   r&   rÿ     s   þz
Para.splitc           
      C   sÆ   | j }| j}|d u rtdƒ‚| j}| j}|r!| |¡ d|_d|_| j}| j	}|r.|d }n| j
j}| d|| j ¡ | ¡ }tsCtrUtddƒ |D ]}	t|	ƒ qJtdƒ | |||¡}| |¡ d S )Nzmust call wrap before drawr   r   z,============================================znow running programz,--------------------------------------------)rp  ri  r8   r-   rW   r\   r   r   rK  r=  rh  r   rL  rb   rM  ÚDUMPPROGRAMrA   rB   rÍ   rN  )
r$   rt  ri  r-   rW   rO  r=  r   Útr   r%   r%   r&   rU  5  s0   



z	Para.drawc           	      C   s,  | j }|d u r	g }|j}|j}|d|fƒ ddlm} ||ƒ\| _| _| _|d|jfƒ |j| _	|d|j
fƒ |d|jfƒ |jrH|d|jfƒ |d|jfƒ |d|jfƒ |jr`|d	|jfƒ | jrj|  | j|¡ |  ||¡ |jr”d}|D ]}|d
 }t|tƒs‡t|dƒr‰ nqw| |d|j f¡ |S )Nra   r   )Úps2ttrb   ri   r   r   r   r`   r4   r^   )rh  r+   r   Úreportlab.lib.fontsry  ra   rj  rk  r   rb   r"   r  r  r   r   r  rg  Ú	do_bulletÚcompileComponentro   rp   rq   Úinsert)	r$   rf  r   r9  r  Úfnry  rQ  r   r%   r%   r&   rr  V  s<   ÿzPara.compileProgramc                 C   s¾   |d u r| j }| j}|d u rg }| d¡ |jr$| d|j|j f¡ n| d|jf¡ | d¡ | j||d�}| d¡ | d¡ |jrN| d|jf¡ n| d¡ | d¡ | d¡ d S )N©re   r   rl   ©r   ©rf   )r   r   )rf  rh  r+   r  r   rr  r  )r$   r   rf  r9  r%   r%   r&   Ú	linearize�  s$   





zPara.linearizec                 C   sF  t |tƒr|r| ¡ }|s| d¡ d S t| ||ƒ d S d S t |tƒr0|D ]}|  ||¡ q%d S t |tƒr¡|\}}}}|s?i }d| }	t| |	d ƒ}
|
d urV|
||||ƒ d S t	r™d| g}|j}|sdi }| 
¡ D ]\}}|d||f ƒ qh|rˆ|dƒ |t|ƒƒ |d| ƒ n|dƒ d |¡}t| ||ƒ d S td	t|ƒ ƒ‚d S )
Nr]   Úcompile_ú<z %s=%sú>z</%s>z/>Ú zdon't know how to handle tag )ro   rp   rr   r+   ÚhandleSpecialCharactersr¦   r|  ru   r*   rA   r  rŸ   r8   rC   )r$   rf  r   Ústextrš   ÚtagnameÚattdictÚcontentrT  ÚcompilernameÚcompilerÚLr  ÚkÚvrx  r%   r%   r&   r|  ©  sD   
û
ÿ


çzPara.compileComponentc                 C   s�   | j }| j}| j}|||f}|d u r|}|d u r|}|d u r |}|| _ || _|| _ddlm}	 |	|||ƒ}
|	|||ƒ}|
|krF| d|
f¡ |S )Nr   ©Útt2psra   )ra   rj  rk  rz  r’  r+   )r$   r   ra   rj  rk  ÚoldfaceÚoldboldÚ	olditalicÚoldfontinfor’  r�   rÉ   r%   r%   r&   Ú	shiftfontÒ  s    
zPara.shiftfontc                 C   s   |D ]}|   ||¡ qd S r(   )r|  ©r$   rŠ  r‹  rT  r   rš   r%   r%   r&   rƒ  ä  s   ÿzPara.compile_c                 C   s   |  tƒ ¡ d S r(   )r+   ÚPageNumberObject©r$   rŠ  r‹  rT  r   r%   r%   r&   Úcompile_pageNumberê  s   zPara.compile_pageNumberc           	      C   s<   | j |dd�\}}}|D ]}|  ||¡ q| j ||d� d S )Nr4   )rj  ©r—  r|  ©	r$   rŠ  r‹  rT  r   Úfr  rˆ   rš   r%   r%   r&   Ú	compile_bí  ó   zPara.compile_bc           	      C   s<   | j |dd�\}}}|D ]}|  ||¡ q| j ||d� d S )Nr4   )rk  rœ  r�  r%   r%   r&   Ú	compile_ió  r   zPara.compile_ic                 C   s6   |  dtf¡ |D ]}|  ||¡ q	|  dtf¡ d S )Nrj   rk   )r+   Ú	UNDERLINEr|  r˜  r%   r%   r&   Ú	compile_uù  s   zPara.compile_uc           	      C   sv   | j }|d  | _ }|d }| d|f¡ || _ | d| f¡ |D ]}|  ||¡ q"| d|f¡ | d|f¡ d S ©Ngffffffæ?g      à?rb   r    ©rb   r+   r|  ©	r$   rŠ  r‹  rT  r   rb   Únewsizer    rš   r%   r%   r&   Úcompile_sub  s   zPara.compile_subÚulc                 C   sž   |  ¡ }t||| jƒ}|D ]?}t|tƒr| ¡ rtdƒ‚qt|tƒrL|\}}	}
}|dkr4tdt|ƒ ƒ‚|  ¡ }|	r?| 	|	¡ | 
|¡ |  ||
||¡ qd S )Nú(don't expect CDATA between list elementsÚlizdon't expect %s inside list)r6   ÚbulletMakerre  ro   rp   rr   r8   ru   rC   r:   Ú
makeBulletÚcompile_para)r$   rŠ  r‹  rT  r   r‰  ÚattsÚbulletmakerrš   Úattdict1Úcontent1Únewattsr%   r%   r&   Ú
compile_ul  s$   
ÿ


€ôzPara.compile_ulc                 C   s   | j ||||dd�S )NÚol)r‰  )r´  rš  r%   r%   r&   Ú
compile_ol"  ó   zPara.compile_olc                 C   s"  |  ¡ }|  ¡ }td|| jƒ}t|ƒ}d}|r…|d }	|d= t|	tƒr/|	 ¡ r+tdƒ‚|s.nWqt|	tƒrƒ|	\}
}}}|
dkrJ|
dkrJtdt	|
ƒ ƒ‚|
dkrc|rXtdt	|ƒ ƒ‚|rb|  
||||¡ n |
dkrƒ|  ¡ }|rr| |¡ |j||d	� |  
||||¡ d}|s|r�td
t	|ƒ ƒ‚d S )NÚdlr†  r   rª  ÚddÚdtz5don't expect %s here inside list, expect 'dd' or 'dt'z2dt will not be displayed unless followed by a dd: )Úblz0dt will not be displayed unless followed by a dd)r6   r¬  re  r¦   ro   rp   rr   r8   ru   rC   r®  r:   r­  )r$   rŠ  r‹  rT  r   r¯  r°  Úcontentcopyrg   rš   r‰  r±  r²  r³  r%   r%   r&   Ú
compile_dl%  sJ   

ÿ€
äÿzPara.compile_dlc           	      C   sv   | j }|d  | _ }|d }| d|f¡ | d|f¡ |D ]}|  ||¡ q| d|f¡ || _ | d| f¡ d S r¤  r¥  r¦  r%   r%   r&   Úcompile_superP  s   zPara.compile_superc                 C   s¶   |  d¡ d|v r+|d }ddlm} z
||| j| jƒ}W n   |}Y |  d|f¡ d|v r:|d }|  d|f¡ d|v rI|d }	|  d|	f¡ |D ]}
|  |
|¡ qK|  d¡ d S )Nr  ra   r   r‘  r`   rb   r�  )r+   rz  r’  rj  rk  r|  )r$   rŠ  r‹  rT  r   ra   r’  r�   r‰   rb   rš   r%   r%   r&   Úcompile_font]  s$   
zPara.compile_fontc           	      C   s�   |d }|  dd¡}t|ƒ}| d¡ | d|f¡ | d|f¡ | dtf¡ |D ]}|  ||¡ q*| dtf¡ | d|f¡ | d¡ d S )NÚhrefr`   Úbluer  rj   rk   r�  )ÚgetÚHotLinkr+   r¢  r|  )	r$   rŠ  r‹  rT  r   Úurlr‰   ÚLinkrš   r%   r%   r&   Ú	compile_as  s   
zPara.compile_ac           	      C   s”   |d }|  dd ¡}t|ƒ}| d¡ |r| d|f¡ | d|f¡ | dtf¡ |D ]}|  ||¡ q,| dtf¡ | d|f¡ | d¡ d S )NÚdestinationr`   r  rj   rk   r�  )rÂ  ÚInternalLinkr+   r¢  r|  ©	r$   rŠ  r‹  rT  r   Údestr‰   rÅ  rš   r%   r%   r&   Úcompile_link‚  s   
zPara.compile_linkc           	      C   sœ   |d }|  dd¡}t|ƒ}| d¡ |r| d|f¡ | d|f¡ |r,| dtf¡ |D ]}|  ||¡ q.|r@| dtf¡ | d|f¡ | d¡ d S )NrÇ  r`   rÁ  r  rj   rk   r�  )rÂ  ÚDefDestinationr+   r¢  r|  rÉ  r%   r%   r&   Úcompile_setLink’  s   
zPara.compile_setLinkc                 C   s:   t |ƒdkst|d tƒstdƒ‚|d }|  ||¡ d S )Nr4   r   z*content for bullet must be a single string)rn   ro   rp   r8   r{  )r$   rŠ  r‹  rT  r   rÓ   r%   r%   r&   Úcompile_bullet¨  s   zPara.compile_bulletc                 C   s6   | j }|j| j }|j}|j}| d||||f¡ d S )Nrg   )rh  r  r   r'  r  r+   )r$   rÓ   r   r9  r   r�   rb   r%   r%   r&   r{  ¯  s
   zPara.do_bulletc           	      C   s<   | j |dd�\}}}|D ]}|  ||¡ q| j ||d� d S )NÚCourier)ra   rœ  r�  r%   r%   r&   Ú
compile_tt·  r   zPara.compile_ttc                 C   s   |   ddi|||¡ d S )Nra   Úsymbol)r¿  rš  r%   r%   r&   Úcompile_greek½  s   zPara.compile_greekc                 C   ó   |  t|||| jƒ¡ d S r(   )r+   ÚEvalStringObjectre  rš  r%   r%   r&   Úcompile_evalStringÀ  ó   zPara.compile_evalStringc                 C   rÓ  r(   )r+   Ú
NameObjectre  rš  r%   r%   r&   Úcompile_nameÃ  rÖ  zPara.compile_namec                 C   rÓ  r(   )r+   ÚGetNameObjectre  rš  r%   r%   r&   Úcompile_getNameÆ  rÖ  zPara.compile_getNamec                 C   rÓ  r(   )r+   Ú	SeqObjectre  rš  r%   r%   r&   Úcompile_seqÉ  rÖ  zPara.compile_seqc                 C   rÓ  r(   )r+   ÚSeqResetObjectre  rš  r%   r%   r&   Úcompile_seqResetÌ  rÖ  zPara.compile_seqResetc                 C   rÓ  r(   )r+   ÚSeqDefaultObjectre  rš  r%   r%   r&   Úcompile_seqDefaultÏ  rÖ  zPara.compile_seqDefaultr5  c                 C   s˜   |d u ri }| j }| d|¡}|| }td|d�}| |¡ | dd ¡}	| j}
t||||	d�}| j}|
j| j  | _|_|j|d� | 	d¡ || _d S )Nr9  zrml2pdf internal embedded style©r  r  rg  ©re  rg  r€  rl   )
re  rÂ  r  r%  rh  rd  r   r  r‚  r+   )r$   rŠ  r‹  rT  r   Ú	stylenamere  r9  Únewstylerg  ÚmystyleÚtheparaÚmybaseindentr%   r%   r&   r®  Ò  s   


zPara.compile_para)NNNNr   r(   )NN©NNN)r©  )r5  )(rÎ   rÏ   rÐ   r  r  r'   rW  rX  rJ  rÿ   rU  rr  r‚  r|  r—  rƒ  r›  rŸ  r¡  r£  r¨  r´  r¶  r½  r¾  r¿  rÆ  rË  rÍ  rÎ  r{  rÐ  rÒ  rÕ  rØ  rÚ  rÜ  rÞ  rà  r®  r%   r%   r%   r&   rd  °  sL    
H
!
:
)
+rd  c                   @   s   e Zd Zdd„ Zddd„ZdS )r¬  c           
      C   sˆ   || _ d}| d|¡ | _}ddd dœ| }| d|¡ | _}d|vr<|| }dd	lm} |j}|d
d|ƒ}	t|	ƒ|d< d| _d| _	d S )Nr6  r9  ÚdiscrÛ   )r©  rµ  r¸  Útyper  r   r   ÚXXXrÏ  r4   )
r‰  rÂ  r9  Útyprm   r   r   rp   rQ  Ú_first)
r$   r‰  r¯  re  r9  rì  Úthestyler   rb   r   r%   r%   r&   r'   æ  s   
zbulletMaker.__init__Nc                 C   s^  | j sd|d< nd| _ | j}| j}|d u rš|dkrE|dkr"tdƒ}n|dkr+tdƒ}n|d	kr4td
ƒ}ntdt|ƒ ƒ‚d|vrDd|d< nU|dkr’d|v rUt|d ƒ| _n|  jd7  _|dkrft| jƒ}n4|dkrxt	dƒ| j d }t|ƒ}n"|dkrŠt	dƒ| j d }t|ƒ}ntdt|ƒ ƒ‚tdt|ƒ ƒ‚d|vr¢||d< d|vr­| j
|d< d S d S )Nrß   r  r   r©  ré  ém   Úcircleél   Úsquareén   z&unordered list type %s not implementedr'  ÚZapfDingbatsrµ  r$  r4   rÛ   r  ÚAz&ordered bullet type %s not implementedzbad tagname rg  r9  )rí  rì  r‰  Úchrr8   rC   ÚintrQ  rp   Úordr9  )r$   r¯  r»  rì  r‰  Útheordr%   r%   r&   r­  ù  s@   
€

ÿzbulletMaker.makeBulletr(   )rÎ   rÏ   rÐ   r'   r­  r%   r%   r%   r&   r¬  å  s    r¬  c                   @   s4   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )rÔ  z)this will only work if rml2pdf is presentÚ
evalStringc                 C   s$   |si }|| _ || _|| _|| _d S r(   )rŠ  r‹  re  rT  )r$   rŠ  r‹  rT  re  r%   r%   r&   r'   $  s   
zEvalStringObject.__init__c                 C   s&   ddl m} | || ji ¡ }| _|S )Nr   )Ú
Controller)Úrlextra.rml2pdf.rml2pdfrû  ÚprocessTuplere  Úop)r$   ru   Úenginerû  rþ  r%   r%   r&   ÚgetOp,  s   zEvalStringObject.getOpc                 C   sV   ddl m} | j}|sg }| j| j|| jf}|  ||¡ }| _t|ƒ}|||j	|j
ƒS ©Nr   r   )rm   r   r‹  r‰  rŠ  rT  r   rþ  rp   r   r   )r$   rÿ  r   r‹  ru   rþ  r¥   r%   r%   r&   r^   2  s   zEvalStringObject.widthc                 C   s   |  t| jƒ¡ d S r(   )r·   rp   rþ  ©r$   rÿ  r¿   r¾   r%   r%   r&   r¸   ?  r·  zEvalStringObject.executeN)	rÎ   rÏ   rÐ   r&  r‰  r'   r   r^   r¸   r%   r%   r%   r&   rÔ    s    rÔ  c                   @   ó   e Zd Zdd„ ZdS )rÛ  c           	      C   sd   ddl m} |ƒ }| j}d|v r|d }||  }| _|S d|v r&|d }nd }| |¡ }| _|S )Nr   ©ÚgetSequencerÚtemplatero  )Úreportlab.lib.sequencerr  rŠ  rþ  Únextf)	r$   ru   rÿ  r  ÚglobalsequencerÚattrÚtemplrþ  ro  r%   r%   r&   r   D  s   
zSeqObject.getOpN©rÎ   rÏ   rÐ   r   r%   r%   r%   r&   rÛ  B  ó    rÛ  c                   @   ó   e Zd ZdZdd„ ZdS )r×  r  c                 C   s   d S r(   r%   r  r%   r%   r&   r¸   W  s   zNameObject.executeN)rÎ   rÏ   rÐ   r‰  r¸   r%   r%   r%   r&   r×  U  s    r×  c                   @   r  )rß  c                 C   sP   ddl m} |ƒ }| j}z|d }W n ty   d }Y nw | |¡ d| _dS )Nr   r  ro  r†  )r  r  rŠ  rð   ÚsetDefaultCounterrþ  )r$   ru   rÿ  r  r	  r
  Údefaultr%   r%   r&   r   \  s   ÿ
zSeqDefaultObject.getOpNr  r%   r%   r%   r&   rß  Z  r  rß  c                   @   r  )rÝ  c                 C   sp   ddl m} |ƒ }| j}z|d }W n ty   d }Y nw zt|d ƒ}W n   d}Y | ||¡ d| _dS )Nr   r  ro  Úbaser†  )r  r  rŠ  rð   r÷  Úresetrþ  )r$   ru   rÿ  r  r	  r
  ro  r  r%   r%   r&   r   j  s   ÿzSeqResetObject.getOpNr  r%   r%   r%   r&   rÝ  h  r  rÝ  c                   @   s   e Zd ZdZdS )rÙ  ÚgetNameN)rÎ   rÏ   rÐ   r‰  r%   r%   r%   r&   rÙ  z  s    rÙ  c                   @   s&   e Zd Zd	dd„Zdd„ Zdd„ ZdS )
r™  rë  c                 C   ó
   || _ d S r(   )Úexample)r$   r  r%   r%   r&   r'     ó   
zPageNumberObject.__init__c                 C   s   ddl m} || j|j|jƒS r  )rm   r   r  r   r   )r$   rÿ  r   r%   r%   r&   r^   ‚  s   zPageNumberObject.widthc                 C   s   |  ¡ }| t|ƒ¡ d S r(   )ÚgetPageNumberr·   rp   )r$   rÿ  r¿   r¾   Únr%   r%   r&   r¸   †  s   zPageNumberObject.executeN)rë  )rÎ   rÏ   rÐ   r'   r^   r¸   r%   r%   r%   r&   r™  }  s    
r™  c                  C   s€   ddl m} m} G dd„ d| ƒatƒ aG dd„ d| ƒatƒ }||d< ||d< ||d	< t|d
< t|d< t|d< t|d< t|d< dS )z8make the para the default para implementation in rml2pdfr   )ÚMapNoderû  c                   @   r  )Ú
paraMapperc                 S   sž   |\}}}}|d }	|  d|	¡}	||	 }
td|
d�}| |¡ |  dd ¡}d }|sAt|ƒdkrA|d }t|tƒrAd|vrAt||ƒ}|d u rMt||||d	�}|S )
Nz.defaultStyler9  zrml2pdf internal stylerá  rg  r4   r   r8  râ  )rÂ  r  r%  rn   ro   rp   r7  rd  )r$   Ú	nodetupleÚ
controllerre  Ú	overridesr‰  rŠ  r‹  rT  rã  r9  rå  rg  r™   rÓ   r%   r%   r&   rL  ’  s   

zparaMapper.translateN©rÎ   rÏ   rÐ   rL  r%   r%   r%   r&   r  �  r  r  c                   @   r  )ÚulMapperc                 S   s   di |gd f}t  ||||¡S )NÚpara)ÚtheParaMapperrL  )r$   r  r  re  r  ræ  r%   r%   r&   rL  ¨  s   zulMapper.translateNr  r%   r%   r%   r&   r  ¦  r  r  r©  rµ  r¸  r   Úh1Úh2Úh3ÚtitleN)rü  r  rû  r  r!  r  )r  rû  ÚtheListMapperr%   r%   r&   ÚEmbedInRml2pdf‹  s   r'  c              	   C   s  ddl m} ddlm} ddddœ}|dd… |v r| d	¡ 	 |d u r&g }| d¡}	d}
|	d
 }|	D ]Õ}|
sÎ| d¡}|dkrÊ|d |… }|d dkr‹z|d dkr]t	|dd … dƒ}nt	|dd … ƒ}W n t
yq   d
}Y nw |dkr†t|ƒ d¡||d d …  }nHd| }nC||v r¨|| }t|tƒr�| d¡}|||d d …  }n&||v rÅ|| }t|tƒrº| d¡}|||d d …  }n	d| }nd| }| ¡ }|d d
… D ]	}| |d	 ¡ qØ|�r|�r|d
 |v rø| |d
 d	 ¡ n|d
  ¡ }|�r| |¡ d}
q3|S )Nr   )Úgreeks)Ú
whitespacer„  r…  r8  )ÚltÚgtÚampr4   r]   r1   ú;ú#r   é   é   Úutf8)Úreportlab.platypus.paraparserr(  r  r)  r+   rÿ   rr   rE   Úfindr÷  r8   rö  Úencodero   rp   Údecode)rÿ  rÓ   r   r(  r)  Ústandardr™   r   r¨   Úamptextr|   ÚlastfragÚfragmentÚsemir  r  r¥   Ú	sfragmentrv  r%   r%   r&   r‡  ·  sf   



€ÿ 






r‡  c                 C   sH   d| vrd| vrt || d�S ddlm} |j| dd�}t|||d|d�S )	zf Paragraph(text, style, bulletText=None)
    intended to be like a platypus Paragraph but better.
    r8  r„  )r:  r   ©Ú	rparsexmlN©ÚentityReplacerrn  )r7  r  r=  ÚparsexmlSimplerd  )rÓ   r9  rg  Úfragsre  r=  Ú
parsedparar%   r%   r&   Ú	Paragraph  s
   rC  c                   @   s&   e Zd Zddd„Zdd„ Zdd„ ZdS )	ÚUnderLineHandlerNc                 C   r  r(   )r`   )r$   r`   r%   r%   r&   r'     r  zUnderLineHandler.__init__c                 C   s   || _ || _d S r(   )ÚxStartÚyStart)r$   r   r   r   r¾   r¿   r%   r%   r&   rµ     s   
zUnderLineHandler.start_atc                 C   sZ   |j d }| ¡  | j}| jd u r|j}| |¡ | | j| j| ||| ¡ | ¡  d S )Ng       @)	r   Ú	saveStater`   r   ÚsetStrokeColorrQ   rE  rF  ÚrestoreState)r$   r   r   r   r¾   r¿   Úoffsetr`   r%   r%   r&   r¹     s   


zUnderLineHandler.end_atr(   )rÎ   rÏ   rÐ   r'   rµ   r¹   r%   r%   r%   r&   rD    s    
rD  c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )rÃ  c                 C   r  r(   )rÄ  )r$   rÄ  r%   r%   r&   r'   $  r  zHotLink.__init__c                 C   s8   |j }| j| j||| g}trtd|ƒ |  ||¡ d S )NzLINKING RECTANGLE)r   rE  rF  rA   rB   Úlink)r$   r   r   r   r¾   r¿   r‹   Úrectr%   r%   r&   r¹   '  s
   
zHotLink.end_atc                 C   s   |j | j|dd� d S )Nr4   )Úrelative)ÚlinkURLrÄ  )r$   rL  r¾   r%   r%   r&   rK  /  s   zHotLink.linkN)rÎ   rÏ   rÐ   r'   r¹   rK  r%   r%   r%   r&   rÃ  "  s    rÃ  c                   @   r  )rÈ  c                 C   s    | j }d}|j|||dd� d S )Nr†  z[0 0 0])ÚBorder)rÄ  ÚlinkRect)r$   rL  r¾   ÚdestinationnameÚcontentsr%   r%   r&   rK  4  s   zInternalLink.linkN)rÎ   rÏ   rÐ   rK  r%   r%   r%   r&   rÈ  2  r  rÈ  c                   @   r  )rÌ  r   c                 C   s4   | j }| js|\}}}}| |||¡ d| _d S d S )Nr4   )rÄ  ÚdefinedÚbookmarkHorizontal)r$   rL  r¾   rQ  r   r   Úx1Úy1r%   r%   r&   rK  =  s   
ýzDefDestination.linkN)rÎ   rÏ   rÐ   rS  rK  r%   r%   r%   r&   rÌ  9  s    rÌ  c                 C   s(   |   ¡ }g }|D ]	}| |d ¡ q|S )Nr]   )rÿ   r+   )rÓ   rˆ  r™   rš   r%   r%   r&   Ú
splitspaceD  s
   rW  a—  
This is Text.
<b>This is bold text.</b>
This is Text.
<i>This is italic text.</i>

<ul>
    <li> this is an element at 1
more text and even more text and on and on and so forth
more text and even more text and on and on and so forth
more text and even more text and on and on and so forth
more text and even more text and on and on and so forth
more text and even more text and on and on and so forth
more text <tt>monospaced</tt> and back to normal

    <ul>
        <li> this is an element at 2

more text and even more text and on and on and so forth
more text and even more text and on and on and so forth

        <ul>
            <li> this is an element at 3

more text and even more text and on and on and so forth


                <dl bulletFontName="Helvetica-BoldOblique" spaceBefore="10" spaceAfter="10">
                <dt>frogs</dt> <dd>Little green slimy things. Delicious with <b>garlic</b></dd>
                <dt>kittens</dt> <dd>cute, furry, not edible</dd>
                <dt>bunnies</dt> <dd>cute, furry,. Delicious with <b>garlic</b></dd>
                </dl>

more text and even more text and on and on and so forth

            <ul>
                <li> this is an element at  4
more text and even more text and on and on and so forth
                </li>
                <li> this is an element at4
more text and even more text and on and on and so forth
                </li>
            </ul>
more text and even more text and on and on and so forth
more text and even more text and on and on and so forth

            </li>
        </ul>
more text and even more text and on and on and so forth
more text and even more text and on and on and so forth
        </li>
    </ul>
<u><b>UNDERLINED</b> more text and even more text and on and on and so forth
more text and even more text and on and on and so forth</u>

<ol type="a">
    <li value="3">first element of the alpha list

     <ul type="square">
        <li>first element of the square unnumberred list</li>

        <li>second element of the unnumberred list</li>

        <li>third element of the unnumberred list
        third element of the unnumberred list
        third element of the unnumberred list
        third element of the unnumberred list
        third element of the unnumberred list
        third element of the unnumberred list
        third element of the unnumberred list
        </li>

        <li>fourth element of the unnumberred list</li>

      </ul>

    </li>

    <li>second element of the alpha list</li>

    <li>third element of the alpha list
    third element of the unnumberred list &amp;#33; --> &#33;
    third element of the unnumberred list &amp;#8704; --> &#8704;
    third element of the unnumberred list &amp;exist; --> &exist;
    third element of the unnumberred list
    third element of the unnumberred list
    third element of the unnumberred list
    </li>

    <li>fourth element of the alpha list</li>

  </ol>


    </li>
</ul>
u…  
<a href="http://www.reportlab.com">goto www.reportlab.com</a>.


<para alignment="justify">
<font color="red" size="15">R</font>ed letter. thisisareallylongword andsoisthis andthisislonger
justified text paragraph example with a pound sign Ã‚Â£
justified text paragraph example
justified text paragraph example
</para>

<para alignment="center">
<font color="green" size="15">G</font>reen letter.
centered text paragraph example
centered text paragraph example
centered text paragraph example
</para>
<para alignment="right">
<font color="blue" size="15">B</font>lue letter.
right justified text paragraph example
right justified text paragraph example
right justified text paragraph example
</para>
<para alignment="left">
<font color="yellow" size="15">Y</font>ellow letter.
left justified text paragraph example
left justified text paragraph example
left justified text paragraph example
</para>

c           
      C   sü   ddl m} ddlm} ddlm} |j|d d�}|dd ƒ}t||ƒ}| d| d| ¡\}}	t	d	|	|fƒ |  
¡  |  d
| d
| ¡ | jddd| d| dd
d� | |_|  
¡  | ¡  |  ¡  |  d
dd¡ | jdd||	dd
d� |  ¡  |  ¡  d S )Nr   ©Úinch)ÚParagraphStyler<  r>  r0  é   r   z
wrapped asr4   )ÚfillÚstroke)Úreportlab.lib.unitsrY  r\  rZ  r  r=  r@  rd  rJ  rB   rG  rL  rL  rK  rU  rI  ÚsetStrokeColorRGBÚshowPage)
rK  ÚtestpararY  rZ  r=  rB  ÚSÚPrv  r’   r%   r%   r&   Útest2Ï  s&   

rd  zhttp://www.reportlab.comr  )r   éd   )r   éÈ   )rg   zvery long bulleté2   rÏ  é   ri   ra   )rb   r   )r   rh  z1This is the first segment of the first paragraph.rj   zÐHOTLINK This is the first segment of the first paragraph. This is the first segment of the first paragraph. This is the first segment of the first paragraph. This is the first segment of the first paragraph. rk   rl   )rg   ÚBulletr   rÏ  é   zþThis is the SECOND!!! segment of the first paragraph. This is the first segment of the first paragraph. This is the first segment of the first paragraph. This is the first segment of the first paragraph. This is the first segment of the first paragraph. )rg   z"Bullet not quite as long this timerg  rÏ  rj  )ra   zHelvetica-Oblique)r`   Úredz4This is the THIRD!!! segment of the first paragraph.zÈThis is the first segment of the first paragraph. This is the first segment of the first paragraph. This is the first segment of the first paragraph. This is the first segment of the first paragraph. )r    r[  zraised ztext )r    iöÿÿÿzlowered znormal r�  )r   rg  )rg   ÚOrg  rÏ  rh  )ra   r   a  And this is the remainder of the paragraph indented further. a a a a a a a a And this is the remainder of the paragraph indented further. a a a a a a a a And this is the remainder of the paragraph indented further. a a a a a a a a And this is the remainder of the paragraph indented further. a a a a a a a a And this is the remainder of the paragraph indented further. a a a a a a a a And this is the remainder of the paragraph indented further. a a a a a a a a And this is the remainder of the paragraph indented further. a a a a a a a a c                  C   s"  ddl m }  ddlm} ddlm} d}| |¡}t|tƒ t|tƒ 	 t	t	 t	 }i }|r‡t
dƒ | |d| ¡ | ¡ }| dd¡ tƒ }| |¡ d|_d|_d	| }	d
}
| |	|
|¡\}}}}tri| |ƒ | |||¡}| |¡ | ¡  t
dd|d d|d ƒ |s.| ¡  t
|ƒ d S )Nr   )Úpprint)r¾   rX  zparatest0.pdfr4   zNEW PAGErj  é   iô  z==============================zx=r   zy=r   )rm  Úreportlab.pdfgenr¾   r^  rY  ÚCanvasrd  ÚtestparagraphÚtestparagraph1Útest_programrB   rL  rM  rº   r   r\   r   r   rY   rA   rÍ   rN  r`  Úsave)rm  r¾   rY  r~  rO  rI   rW   rx  rt  rF   rG   Úformattedprogramr=  r%   r%   r&   Útest	  s>   




ïrv  Ú__main__r(   rè  )<r&  rm   r   Úreportlab.lib.rl_accelr   Úreportlab.platypus.flowablesr   r  r   r\  r   rA   rw  r7   r!   r	   r
   r   r   r   r;   r?   r   r   rá   rè   rõ   r  r  r  r  r]  r7  ra  rc  rd  r¬  rÔ  rÛ  r×  rß  rÝ  rÙ  r™  r'  r‡  rC  rD  r¢  rÃ  rÈ  rÌ  rW  rq  rr  rd  Útestlinkrs  rv  rÎ   r%   r%   r%   r&   Ú<module>   s   <	     m%ó $
    9:#
,
L	b ø	÷
ÿ÷õùõíøíäÿãá ðá0Ð1þÐ4
!
ÿ