o
    &zh'                     @   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   T/var/www/html/kangema/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  | |_ ||_zt|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 rtjs|
| jks||kr|sdd	lm} |d
|j||
|| jf W dD ]}t||rt|| qd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rt|ddr| j}|| _|| jkrd| _	|| _W dD ]}t||rt|| qdS dD ]}t||rt|| qw )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 )zConsumes 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   
