o
    ¢�Z¢(  ã                   @   sT   d Z dZddlZe d¡ZdZddlmZmZ ej	Z	G dd„ dƒZ
G d	d
„ d
ƒZdS )z3.3.0z.A frame is a container for content on a page.
é    Nzreportlab.platypus)Úx1Úy1ÚwidthÚheightÚleftPaddingÚbottomPaddingÚrightPaddingÚ
topPadding)Ú	rl_configÚisPy3c                   @   s.   e Zd Zd
dd„Zerdd„ Zd	S dd„ Zd	S )ÚShowBoundaryValue©r   r   r   çš™™™™™¹?c                 C   s   || _ || _d S ©N©Úcolorr   )Úselfr   r   © r   úK/var/www/html/env/lib/python3.10/site-packages/reportlab/platypus/frames.pyÚ__init__   s   
zShowBoundaryValue.__init__c                 C   ó   | j d uo	| jdkS ©Nr   r   ©r   r   r   r   Ú__bool__   ó   zShowBoundaryValue.__bool__c                 C   r   r   r   r   r   r   r   Ú__nonzero__   r   zShowBoundaryValue.__nonzero__N)r   r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r      s
    
r   c                   @   sŽ   e Zd Z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d„ZeZdd„ Zdd„ Zdd„ Zdd„ Zdd „ ZdS )#ÚFrameah  
    A Frame is a piece of space in a document that is filled by the
    "flowables" in the story.  For example in a book like document most
    pages have the text paragraphs in one or two frames.  For generality
    a page might have several frames (for example for 3 column text or
    for text that wraps around a graphic).

    After creation a Frame is not usually manipulated directly by the
    applications program -- it is used internally by the platypus modules.

    Here is a diagramatid abstraction for the definitional part of a Frame::

                width                    x2,y2
        +---------------------------------+
        | l  top padding                r | h
        | e +-------------------------+ i | e
        | f |                         | g | i
        | t |                         | h | g
        |   |                         | t | h
        | p |                         |   | t
        | a |                         | p |
        | d |                         | a |
        |   |                         | d |
        |   +-------------------------+   |
        |    bottom padding               |
        +---------------------------------+
        (x1,y1) <-- lower left corner

    NOTE!! Frames are stateful objects.  No single frame should be used in
    two documents at the same time (especially in the presence of multithreading.
    é   Nr   c                 C   sŠ   |	| _ || _|| jd< || jd< || jd< || jd< || jd< || jd< || jd< || jd< |
| _|d u r8tj}|| _|  ¡  |  ¡  d S )	NÚ_x1Ú_y1Ú_widthÚ_heightÚ_leftPaddingÚ_bottomPaddingÚ_rightPaddingÚ_topPadding)	ÚidÚ_debugÚ__dict__ÚshowBoundaryr
   ÚoverlapAttachedSpaceÚ_oASpaceÚ_geomÚ_reset)r   r   r   r   r   r   r   r   r	   r)   r,   r-   r*   r   r   r   r   >   s   







zFrame.__init__c                 C   s   |t v r| jd|  S t|ƒ‚©NÚ_)Ú	_geomAttrr+   ÚAttributeError)r   Úar   r   r   Ú__getattr__X   s   zFrame.__getattr__c                 C   s0   |t v r|| jd| < |  ¡  d S || j|< d S r1   )r3   r+   r/   )r   r5   Úvr   r   r   Ú__setattr__\   s   zFrame.__setattr__c                 K   sV   | j  di ¡stD ]}d| }| j | | j d |< q	| ¡ D ]
\}}t| ||ƒ qd S ©NÚ
_savedGeomr2   )r+   Ú
setdefaultr3   ÚitemsÚsetattr)r   ÚkwdsÚgaÚkr7   r   r   r   Ú	_saveGeomc   s   ÿzFrame._saveGeomc                 C   sL   | j  dd ¡r$tD ]}d| }| j | d | j |< | j d= q	|  ¡  d S d S r9   )r+   Úgetr3   r/   )r   r?   r   r   r   Ú_restoreGeomk   s   
ûzFrame._restoreGeomc                 C   s\   | j | j | _| j| j | _| j| j | _| j| j  | j | j	 | _
| j| j | j | _d S r   )r!   r#   Ú_x2r"   r$   Ú_y2r&   Ú_y1pr%   r'   Ú_aWr(   Ú_aHr   r   r   r   r/   s   s
   zFrame._geomc                 C   s@   |   ¡  | j| j | _| j| j | _d| _d| _d| _	d| _
d S )Né   r   g        )rC   r!   r%   Ú_xrE   r(   Ú_yÚ_atTopÚ_prevASpaceÚ_leftExtraIndentÚ_rightExtraIndentr   r   r   r   r0   |   s   
zFrame._resetc                 C   s   | j | j | j S r   )rG   rN   rO   r   r   r   r   Ú_getAvailableWidthŠ   s   zFrame._getAvailableWidthc              
   C   sô  | |_ ||_�z`t|ddƒr%| | ¡ W dD ]}t||ƒr"t||ƒ qdS | j}| j}d}|  ¡ }t|ddƒ}	| j	sT| 
¡ }| jrTt|ddƒsI|	rL| j}t|| j dƒ}|| | }
|
dks`|	ri| ||
¡\}}
nW dD ]}t||ƒrxt||ƒ qldS |
|7 }
||
8 }||t k r¼tjsª|
| jks•||krª|sªdd	lm} |d
|j||
|| jf ƒ‚W dD ]}t||ƒr¹t||ƒ q­dS | ¡ }t| ddƒ}|�r|d \}}}| j| | }||
 | }t||| ƒ}td|| ƒ}t|ƒtk�rt|ƒtk�r| ¡  | |¡ |j| j| |||ddd� | ¡  |j|| j| j  ||| d� ||_| j!�r3t" #d| $¡  ¡ ||8 }| j�rHt|ddƒ�rE| j}|| _|| jk�rQd| _	|| _W dD ]}t||ƒ�rdt||ƒ �qWdS dD ]}t||ƒ�rwt||ƒ �qjw )zô Draws the flowable at the current position.
        Returns 1 if successful, 0 if it would not fit.
        Raises a LayoutError if the object is too wide,
        or if it is too high for a totally empty frame,
        to avoid infinite loopsÚframeActionN©ÚcanvÚ_framerI   r   Ú	_ZEROSIZEFÚ_SPACETRANSFER)ÚLayoutErrorz>Flowable %s (%sx%s points) too large for frame (%sx%s points).Ú	_frameBGséÿÿÿÿ)ÚstrokeÚfill)Ú_sWzdrew %s)%rT   rS   ÚgetattrrQ   ÚhasattrÚdelattrrK   rF   rP   rL   ÚgetSpaceBeforer.   rM   ÚmaxÚwrapÚ_FUZZr
   ÚallowTableBoundsErrorsrH   Úreportlab.platypus.doctemplaterW   Ú	__class__ÚgetSpaceAfterr#   ÚabsÚ	saveStateÚsetFillColorÚrectr!   ÚrestoreStateÚdrawOnrJ   rN   r*   ÚloggerÚdebugÚidentity)r   ÚflowablerS   ÚtrySplitr5   ÚyÚpÚsÚaWÚzeroSizeÚhÚwrW   ÚfbgÚfbglÚfbgrÚfbgcÚfbwÚfbhÚfbyr   r   r   Ú_add�   sœ   
9

€þÉ(

€þÚÿ

€þå

€þ
€þz
Frame._addc           	   
   C   s¸   | j }| j}d}| js| ¡ }| jrt|| j dƒ}|| | }|dkr,t|ddƒs,g S | |_||_	z| 
| j|¡}W dD ]}t||ƒrIt||ƒ q=|S dD ]}t||ƒrZt||ƒ qNw )z7Ask the flowable to split using up the available space.r   rU   FrR   )rK   rF   rL   r`   r.   ra   rM   r]   rT   rS   ÚsplitrG   r^   r_   )	r   rq   rS   rs   rt   ru   rx   Úrr5   r   r   r   r‚   ×   s0   

€ý

€þzFrame.splitc                 C   sÔ   ddl m}m} | j}t|tttfƒpt||ƒ}d}|r&||| ƒ}|| u}nt|tƒr:|r:||j	| ƒ}|j
}|| u}|rN| ¡  | |¡ |dkrN| |¡ | | j| j| j| j | j| j ¡ |rh| ¡  dS dS )zAdraw the frame boundary as a rectangle (primarily for debugging).r   )ÚColorÚtoColorrY   N)Úreportlab.lib.colorsr„   r…   r,   Ú
isinstanceÚstrÚtupleÚlistr   r   r   ri   ÚsetStrokeColorÚsetLineWidthrk   r!   r"   rD   rE   rl   )r   rS   r„   r…   ÚsbÚssry   Úcr   r   r   ÚdrawBoundaryï   s.   





üzFrame.drawBoundaryc                 C   sj   | j rt d| j ¡ | jr|  |¡ t|ƒdkr3|d }| j||dd�r)|d= ndS t|ƒdksdS dS )z‡Consumes objects from the front of the list until the
        frame is full.  If it cannot fit one object, raises
        an exception.z&enter Frame.addFromlist() for frame %sr   )rr   N)r*   rn   ro   r)   r,   r�   ÚlenÚadd)r   ÚdrawlistrS   Úheadr   r   r   ÚaddFromList	  s   
úzFrame.addFromListc                 G   s   | j  dg ¡ |¡ d S )NÚ_generated_content)r+   r;   Úextend)r   ÚCr   r   r   Úadd_generated_content  s   zFrame.add_generated_contentc                 C   s   d|   ¡ | j| jrdpdf S )Nz(%s x %s%s)Ú*Ú )rP   rH   rL   r   r   r   r   Ú_aSpaceString  s   zFrame._aSpaceString)r    r    r    r    Nr   NN)r   )r   r   r   Ú__doc__r   r6   r8   rA   rC   r/   r0   rP   r�   r’   r‚   r�   r•   r™   rœ   r   r   r   r   r      s(    
þ	
Hr   )Ú__version__r�   ÚloggingÚ	getLoggerrn   r3   Ú	reportlabr
   r   rc   r   r   r   r   r   r   Ú<module>   s   
