o
    à’Oj '  ã                   @   sF   d Z dZdZddlZe d¡ZdZddlmZ ej	Z	G dd	„ d	ƒZ
dS )
z3.5.14z.A frame is a container for content on a page.
)ÚFrameé    Nzreportlab.platypus)Úx1Úy1ÚwidthÚheightÚleftPaddingÚbottomPaddingÚrightPaddingÚ
topPadding)Ú	rl_configc                   @   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d„Zdd„ Zdd„ Zdd „ ZdS )$r   ah  
    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)Úselfr   r   r   r   r   r   r	   r
   r   r   r   r   © r   ú_/var/www/html/pharmsmart-cdr-gen/venv/lib/python3.10/site-packages/reportlab/platypus/frames.pyÚ__init__5   s   







zFrame.__init__c                 C   s   |t v r| jd|  S t|ƒ‚©NÚ_)Ú	_geomAttrr   ÚAttributeError)r   Úar   r   r   Ú__getattr__O   s   zFrame.__getattr__c                 C   s0   |t v r|| jd| < |  ¡  d S || j|< d S r!   )r#   r   r   )r   r%   Úvr   r   r   Ú__setattr__S   s   zFrame.__setattr__c                 K   sV   | j  di ¡stD ]}d| }| j | | j d |< q	| ¡ D ]
\}}t| ||ƒ qd S ©NÚ
_savedGeomr"   )r   Ú
setdefaultr#   ÚitemsÚsetattr)r   ÚkwdsÚgaÚkr'   r   r   r   Ú	_saveGeomZ   s   ÿzFrame._saveGeomc                 C   sL   | j  dd ¡r$tD ]}d| }| j | d | j |< | j d= q	|  ¡  d S d S r)   )r   Úgetr#   r   )r   r/   r   r   r   Ú_restoreGeomb   s   
ûzFrame._restoreGeomc                 C   s\   | j | j | _| j| j | _| j| j | _| j| j  | j | j	 | _
| j| j | j | _d S ©N)r   r   Ú_x2r   r   Ú_y2r   Ú_y1pr   r   Ú_aWr   Ú_aH©r   r   r   r   r   j   s
   zFrame._geomc                 C   s@   |   ¡  | j| j | _| j| j | _d| _d| _d| _	d| _
d S )Né   r   g        )r3   r   r   Ú_xr6   r   Ú_yÚ_atTopÚ_prevASpaceÚ_leftExtraIndentÚ_rightExtraIndentr:   r   r   r   r   s   s   
zFrame._resetc                 C   s   | j | j | j S r4   )r8   r@   rA   r:   r   r   r   Ú_getAvailableWidth�   s   zFrame._getAvailableWidthc              
   C   st  | |_ ||_�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ƒ}|�rT|d j�rT|d }|j}|j}|j}| j| | }| j| }|sÿ||
 | }t||| ƒ}td|| ƒ}nB||
 | }|| j| j k}|dk�s|dk�s|�r;|dk�r;td|�r'| jn|| j ƒ}| j}|dk�r:d|d _nd } }}|  || ||||¡ |dk�rT| !¡  |j"|| j#| j$ ||| d� ||_| j%�rst& 'd| (¡  ¡ ||8 }| j�rˆt|ddƒ�r…| j}|| _|| jk�r‘d| _	|| _W dD ]}t||ƒ�r¤t||ƒ �q—dS dD ]}t||ƒ�r·t||ƒ �qªw )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Ú_framer;   r   Ú	_ZEROSIZEFÚ_SPACETRANSFER)ÚLayoutErrorz>Flowable %s (%sx%s points) too large for frame (%sx%s points).Ú	_frameBGséÿÿÿÿÚframezframe-permanentzframe-permanent-1)Ú_sWzdrew %s))rF   rE   ÚgetattrrC   ÚhasattrÚdelattrr=   r7   rB   r>   ÚgetSpaceBeforer   r?   ÚmaxÚwrapÚ_FUZZr   ÚallowTableBoundsErrorsr9   Úreportlab.platypus.doctemplaterI   Ú	__class__ÚgetSpaceAfterÚactiveÚleftÚrightÚstartr   r   r6   r   r   ÚrenderÚpopÚdrawOnr<   r@   r   ÚloggerÚdebugÚidentity)r   ÚflowablerE   ÚtrySplitr%   ÚyÚpÚsÚaWÚzeroSizeÚhÚwrI   ÚsaÚfbgÚbgÚfbglÚfbgrÚbgmÚfbwÚfbxÚfbhÚfbyÚattr   r   r   Ú_add„   s´   
G

€þ»6

€þÌÿ,

€þ×
$

€

€þ
€þ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   rG   FrD   )r=   r7   r>   rQ   r   rR   r?   rN   rF   rE   Úsplitr8   rO   rP   )	r   rc   rE   re   rf   rg   rj   Úrr%   r   r   r   rx   Ü   s0   

€ý

€þzFrame.splitc                 C   s0   |  |p| j| j| j| j| j | j| j ¡ d S r4   )ÚdrawBoundaryr   r   r   r5   r6   )r   rE   Ú__boundary__r   r   r   rz   ó   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   )rd   N)r   r`   ra   r   r   rz   ÚlenÚadd)r   ÚdrawlistrE   Ú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)Ú*Ú )rB   r9   r>   r:   r   r   r   Ú_aSpaceString  s   zFrame._aSpaceString)r   r   r   r   Nr   NN)r   r4   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    r&   r(   r1   r3   r   r   rB   rw   r}   rx   rz   r€   r„   r‡   r   r   r   r   r      s(    
þ	
V
r   )Ú__version__r‹   Ú__all__ÚloggingÚ	getLoggerr`   r#   Ú	reportlabr   rT   r   r   r   r   r   Ú<module>   s   
