U
    '1e+                     @   sT   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
G d
d dZdS )z3.5.14z.A frame is a container for content on a page.
)ShowBoundaryValueFrame    Nzreportlab.platypus)x1y1widthheightleftPaddingbottomPaddingrightPadding
topPadding)	rl_configc                   @   s   e Zd ZdddZdd ZdS )	r   r   r   r   皙?Nc                 C   s   || _ || _|| _d S N)colorr   	dashArray)selfr   r   r    r   =/tmp/pip-unpacked-wheel-109iniqw/reportlab/platypus/frames.py__init__   s    zShowBoundaryValue.__init__c                 C   s   | j d k	o| jdkS )Nr   )r   r   r   r   r   r   __bool__   s    zShowBoundaryValue.__bool__)r   r   N)__name__
__module____qualname__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e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 krpt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 kr| jd|  S t|d S N_)	_geomAttrr&   AttributeError)r   ar   r   r   __getattr__Z   s     zFrame.__getattr__c                 C   s.   |t kr || jd| < |   n
|| j|< d S r,   )r.   r&   r*   )r   r0   vr   r   r   __setattr__^   s    
zFrame.__setattr__c                 K   sV   | j di s4tD ] }d| }| j | | j d |< q| D ]\}}t| || q<d S NZ
_savedGeomr-   )r&   
setdefaultr.   itemssetattr)r   kwdsgakr2   r   r   r   	_saveGeome   s    zFrame._saveGeomc                 C   sH   | j dd rDtD ](}d| }| j | d | j |< | j d= q|   d S r4   )r&   getr.   r*   )r   r9   r   r   r   _restoreGeomm   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*   u   s
    zFrame._geomc                 C   s@   |    | j| j | _| j| j | _d| _d| _d| _	d| _
d S )N   r   g        )r=   r   r    _xr?   r#   _y_atTop_prevASpace_leftExtraIndent_rightExtraIndentr   r   r   r   r+   ~   s    zFrame._resetc                 C   s   | j | j | j S r   )rA   rH   rI   r   r   r   r   _getAvailableWidth   s    zFrame._getAvailableWidthc              
   C   s  | |_ ||_zt|ddr0||  W dS | j}| j}d}|  }t|dd}	| j	s|
 }| jrt|ddsx|	r~| j}t|| j d}|| | }
|
dks|	r|||
\}}
n
W 2dS |
|7 }
||
8 }||t k r2tjs(|
| jks||kr(|s(dd	lm} |d
|j||
|| jf W dS | }t| dd}|rd|d jrd|d }|j}|j}|j}| j| | }| j| }|s||
 | }t||| }td|| }n||
 | }|| j| j k}|dks|dks|r2|dkr2td|r
| jn|| j }| j}|dkr>d|d _nd } }}| || |||| |dkrd|!  |j"|| j#| j$ ||| d ||_| j%rt&'d|(   ||8 }| jrt|ddr| j}|| _|| jkrd| _	|| _W dS W 5 dD ]}t||rt|| qX dS )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canv_frameframeActionNrC   r   	_ZEROSIZEFZ_SPACETRANSFER)LayoutErrorz>Flowable %s (%sx%s points) too large for frame (%sx%s points).Z	_frameBGsframezframe-permanentzframe-permanent-1)Z_sWzdrew %s))rM   rL   hasattrdelattrgetattrrN   rE   r@   rJ   rF   getSpaceBeforer)   rG   maxwrap_FUZZr   ZallowTableBoundsErrorsrB   Zreportlab.platypus.doctemplaterP   	__class__ZgetSpaceAfteractiveleftrightstartr   r   r?   r#   r   renderpopZdrawOnrD   rH   r%   loggerdebugidentity)r   flowablerL   trySplitr0   ypsZaWZzeroSizehwrP   saZfbgbgZfbglZfbgrZbgmZfbwZfbxZfbhZfbyZattr   r   r   _add   s    


"    

$

  z
Frame._addc           	   
   C   s   | j }| j}d}| js4| }| jr4t|| j d}|| | }|dkrXt|ddsXg S | |_||_	z|| j|}W 5 dD ]}t
||r|t|| q|X |S )z7Ask the flowable to split using up the available space.r   rO   FrK   )rE   r@   rF   rV   r)   rW   rG   rU   rM   rL   rS   rT   splitrA   )	r   rd   rL   rf   rg   rh   ri   r0   rr   r   r   rn      s$    
zFrame.splitc                 C   s   ddl m}m} t|tttfp(t||}d}	d}
|rJ||d}|dk}n2t|tr||r|||jd}|dk}|r||j	}	|j
}
|r|   | | |	dkr| |	 |
r| |
 | |||| |r|   dS )zAdraw the frame boundary as a rectangle (primarily for debugging).r   )ColortoColorrQ   N)Zreportlab.lib.colorsrp   rq   
isinstancestrtuplelistr   r   r   r   Z	saveStateZsetStrokeColorZsetLineWidthZsetDashZrectZrestoreState)rL   Zsbr   r   r   r   rp   rq   ssrj   dacr   r   r   _drawBoundary   s.    


 
 
 zFrame._drawBoundaryc              	   C   s2   |  ||p| j| j| j| j| j | j| j  d S r   )ry   r'   r   r   r>   r?   )r   rL   Z__boundary__r   r   r   drawBoundary  s    
 
zFrame.drawBoundaryc                 C   sZ   | j rtd| j  | jr&| | t|dkrV|d }| j||ddrV|d= q&qVq&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   )re   N)r%   ra   rb   r$   r'   rz   lenadd)r   ZdrawlistrL   headr   r   r   addFromList  s     
zFrame.addFromListc                 G   s   | j dg | d S )NZ_generated_content)r&   r5   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)* )rJ   rB   rF   r   r   r   r   _aSpaceString/  s    zFrame._aSpaceString)r   r   r   r   Nr   NN)r   )N)r   r   r   __doc__r   r1   r3   r;   r=   r*   r+   rJ   rm   r|   rn   staticmethodry   rz   r~   r   r   r   r   r   r   r       s2              
	
V

r   )__version__r   __all__logging	getLoggerra   r.   Z	reportlabr   rY   r   r   r   r   r   r   <module>   s   

