a
    7¤Xh‰G  ã                   @   sÜ  d Z dZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
m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mZmZ ddlmZ ddlmZ ddlmZmZ edededZG dd„ deƒZdd„ ZG dd„ deƒZG dd„ deƒZ G dd„ deƒZ!G dd„ de!ƒZ"G dd „ d e!ƒZ#z dd!l$m%Z%m&Z&m'Z'm(Z( d"Z)W n e*y`   dZ)Y n0 e)r¸G d#d$„ d$ƒZ+G d%d&„ d&e!e+ƒZ,G d'd(„ d(e,ƒZ-G d)d*„ d*e!ƒZ.G d+d,„ d,e.ƒZ/d-d.„ Z0d/d0„ Z1e2d1krØe1ƒ  dS )2z@This includes some demos of platypus for use in the API proposalz3.3.0é    N)Úcolors)ÚCanvas)ÚParagraphStyle)ÚrecursiveImportÚstrTypes)ÚFrame)ÚFlowable)Ú	Paragraph)Úinch)ÚTA_LEFTÚTA_RIGHTÚ	TA_CENTER)ÚisColor)ÚtoColor)Ú_baseFontNameÚ_baseFontNameIÚCaptioné
   )ÚfontNameÚfontSizeÚ	alignmentc                   @   st   e Zd Zdeddedƒddddddddf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 )ÚFigureÚ é   NÚblackÚcentreÚbottomÚCENTERc                 C   s„   t  | ¡ || _|| _|| _|| _|| _|| _|| _|p>d| | _	|| _
|| _d | _d| _|| _|	| _|
| _|| _|| _|  ¡  d S )Nç      à?r   )r   Ú__init__ÚwidthÚfigureHeightÚcaptionÚcaptionFontÚcaptionSizeÚcaptionTextColorÚcaptionBackColorÚ
captionGapÚcaptionAlignÚcaptionPositionÚ_captionDataÚcaptionHeightÚ
backgroundÚborderÚspaceBeforeÚ
spaceAfterÚhAlignÚ_getCaptionPara)Úselfr    Úheightr"   r#   r$   r,   r%   r&   r-   r.   r/   r'   r(   r)   r0   © r4   ú_/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/reportlab/platypus/figures.pyr      s&    
zFigure.__init__c              
   C   sÐ   | j }| j}| j}| j}| j}| j}| j}| j|||||||fkrÌ|||||||f| _t|t	ƒrh|| _
ndt|tƒr¼td||d| ||| j|dkr”tn|dkr tntd| _t	| j | jƒ| _
ntdt|ƒ ƒ‚d S )Nr   g333333ó?ÚleftÚright)r   r   ÚleadingZ	textColorZ	backColorr.   r   z6Figure caption of type %r is not a string or Paragraph)r"   r#   r$   r%   r&   r(   r)   r*   Ú
isinstancer	   ÚcaptionParar   r   r'   r   r   r   ÚcaptionStyleÚ
ValueErrorÚtype)r2   r"   r#   r$   r%   r&   r(   r)   r4   r4   r5   r1   :   s0    

÷zFigure._getCaptionParac                 C   s¬   | j rT|  ¡  | j | j|| j ¡\}}|| j | _| j| j | _|| jkr\|| _n| j| _| j	ddt
fv r~d|| j  | _n"| j	dtfv rš|| j | _nd| _| j| jfS )Nr   ZCENTREr   ÚRIGHTr   )r"   r1   r:   Úwrapr    r!   r'   r+   r3   r0   r   Údxr   )r2   Ú
availWidthÚavailHeightÚwÚhr4   r4   r5   r?   W   s    zFigure.wrapc                 C   s¶   | j  | jd¡ | jr0| jdkr0| j  d| j¡ | jr>|  ¡  | jrL|  	¡  | j  
¡  |  ¡  | j  ¡  | jr²| jdkrŒ| j  d| j ¡ n| j  d| j| j ¡ |  ¡  |  ¡  d S )Nr   r   )ÚcanvÚ	translater@   r"   r)   r+   r,   ÚdrawBackgroundr-   Ú
drawBorderÚ	saveStateÚ
drawFigureÚrestoreStater!   r'   r1   ÚdrawCaption©r2   r4   r4   r5   Údrawi   s     


zFigure.drawc                 C   s   | j  | jdd| j| j¡ d S ©Nr   )rE   ZdrawBoundaryr-   r    r!   rM   r4   r4   r5   rH   |   s    zFigure.drawBorderc                 C   s@   | j  ¡  | j  | j¡ | j jdd| j| jdd | j  ¡  d S )Nr   é   )Úfill)rE   rI   ZsetFillColorr,   Úrectr    r!   rK   )r2   Úcolorr4   r4   r5   Ú_doBackground   s    
zFigure._doBackgroundc                 C   sB   t | jƒr|  | j¡ n&zt| jƒ}|  |¡ W n   Y n0 dS )z“For use when using a figure on a differently coloured background.
        Allows you to specify a colour to be used as a background for the figure.N)r   r,   rT   r   )r2   Úcr4   r4   r5   rG   …   s    

zFigure.drawBackgroundc                 C   s   | j  | jdd¡ d S rO   )r:   ÚdrawOnrE   rM   r4   r4   r5   rL   ‘   s    zFigure.drawCaptionc                 C   s   d S ©Nr4   rM   r4   r4   r5   rJ   ”   s    zFigure.drawFigure)Ú__name__Ú
__module__Ú__qualname__r   r   r   r1   r?   rN   rH   rT   rG   rL   rJ   r4   r4   r4   r5   r      s*   õ
!r   c                 C   sŠ   |   ¡ }d| }|  ddd¡ | j|| || ||ddd |  ddd¡ |  d¡ | j||||ddd |  ddd¡ |  ddd¡ d S )Ngš™™™™™©?r   r   rP   )ZstrokerQ   gÍÌÌÌÌÌì?)Z	beginPathZsetFillColorRGBrR   ZsetLineWidthZsetStrokeColorRGB)ÚcanvasÚxÚyr    r3   ÚpthZcornerr4   r4   r5   ÚdrawPage—   s    
r_   c                   @   s*   e Zd ZdZd	dd„Zdd„ Zdd„ ZdS )
Ú
PageFigurezcShows a blank page in a frame, and draws on that.  Used in
    illustrations of how PLATYPUS works.Nc                 C   s,   t  | dt dt ¡ d| _t| _|| _d S )Né   zFigure 1 - a blank page)r   r   r
   r"   r;   r,   )r2   r,   r4   r4   r5   r   ¬   s    zPageFigure.__init__c                 C   s   d S rW   r4   rM   r4   r4   r5   ÚdrawVirtualPage²   s    zPageFigure.drawVirtualPagec                 C   sR   t | jdt dt dt dt ƒ | j dt dt ¡ | j dd¡ |  ¡  d S )Ng      ä?g      Ð?g      ü?g      @gå”múË?g	çQê²_Ë?)r_   rE   r
   rF   Úscalerb   rM   r4   r4   r5   rJ   µ   s    "zPageFigure.drawFigure)N)rX   rY   rZ   Ú__doc__r   rb   rJ   r4   r4   r4   r5   r`   ©   s   
r`   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚPlatPropFigure1z$This shows a page with a frame on itc                 C   s   t  | ¡ d| _d S )Nz%Figure 1 - a page with a simple frame)r`   r   r"   rM   r4   r4   r5   r   ½   s    
zPlatPropFigure1.__init__c                 C   s   t | jƒ d S rW   )Údemo1rE   rM   r4   r4   r5   rb   À   s    zPlatPropFigure1.drawVirtualPageN)rX   rY   rZ   rd   r   rb   r4   r4   r4   r5   re   »   s   re   c                   @   sP   e Zd ZdZdddejddddddd	dd
dfdd„Zdd„ Zdd„ Zdd„ Z	dS )Ú
FlexFigurezHBase for a figure class with a caption. Can grow or shrink in proportionNzHelvetica-Obliqueé   rP   r   é	   r   Útopr   c                 C   sJ   t j| |||||d ||
||||||d || _|	| _|| _d | _|| _d S )N)r#   r$   r,   r%   r.   r/   r'   r(   r)   r0   r-   )r   r   ÚshrinkToFitÚ	growToFitÚscaleFactorÚ_scaleFactorr,   )r2   r    r3   r"   r,   r#   r$   r%   rk   rl   r.   r/   r'   r(   r)   rm   r0   r-   r4   r4   r5   r   Å   s$    õzFlexFigure.__init__c                 C   sÐ   | j du s| j|ks| j|krÌt | ||¡\}}|| j }| jdu rbt|| j || | j ƒ| _ n| j| _ | j dk rœ| jrœ| j| j  d | _| j| j  | _n0| j dkrÌ| j	rÌ| j| j  d | _| j| j  | _dS )z4Rescale to fit according to the rules, but only onceNrP   g-Cëâ6?)
rn   r    r3   r   r?   r!   rm   Úminrk   rl   )r2   rA   rB   rC   rD   r+   r4   r4   r5   Ú_scaleæ   s    

zFlexFigure._scalec                 C   s   |   ||¡ t | ||¡S rW   )rp   r   r?   ©r2   rA   rB   r4   r4   r5   r?   ÷   s    zFlexFigure.wrapc                 C   s   |   ||¡ t | ||¡S rW   )rp   r   Úsplitrq   r4   r4   r5   rr   û   s    zFlexFigure.split)
rX   rY   rZ   rd   r   r   r   rp   r?   rr   r4   r4   r4   r5   rg   Ã   s$   ô
!rg   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )	ÚImageFigurezImage with a caption below itNr   c           
   
   C   sX   t j |¡sJ d| ƒ‚ddlm} ||ƒ ¡ \}}	|| _tj| ||	|||||d d S )Nzimage file %s not foundr   )ÚImageReader)rm   r0   r-   )	ÚosÚpathÚisfileÚreportlab.lib.utilsrt   ZgetSizeÚfilenamerg   r   )
r2   ry   r"   r,   rm   r0   r-   rt   rC   rD   r4   r4   r5   r     s
    zImageFigure.__init__c                 C   s   | j  | jdd| j| j¡ d S rO   )rE   Z	drawImagery   r    r!   rM   r4   r4   r5   rJ     s    
ÿzImageFigure.drawFigure)NNr   N©rX   rY   rZ   rd   r   rJ   r4   r4   r4   r5   rs   ÿ   s   
rs   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )ÚDrawingFigurez8Drawing with a caption below it.  Clunky, scaling fails.Nc                 C   s@   t ||ƒ}t||ƒ}|ƒ | _t | | jj| jj||¡ d| _d S )NrP   )r   ÚgetattrÚdrawingrg   r   r    r3   rl   )r2   Ú
modulenameÚ	classnamer"   ZbaseDirr,   ÚmoduleÚklassr4   r4   r5   r     s    

üzDrawingFigure.__init__c                 C   s(   | j  | j| j¡ | j | j dd¡ d S rO   )rE   rc   rn   r}   rV   rM   r4   r4   r5   rJ     s    zDrawingFigure.drawFigure)NNrz   r4   r4   r4   r5   r{     s   
r{   )ÚrestoreFormsÚ
storeFormsÚstoreFormsInMemoryÚrestoreFormsInMemoryrP   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚPageCatcherCachingMixInz+Helper functions to cache pages for figuresc                 C   s,   t j |¡\}}t j |¡\}}d||f S )Nz	%s_page%d)ru   rv   rr   Úsplitext)r2   ÚpdfFileNameÚpageNoÚdirnamery   ÚrootÚextr4   r4   r5   ÚgetFormName,  s    z#PageCatcherCachingMixIn.getFormNamec                 C   sL   |   ||¡}tj |d ¡rDt |d ¡d }t |¡d }||kS dS dS )z&returns 1 if no forms or form is olderú.frmrh   rP   N)r   ru   rv   ÚexistsÚstat)r2   rˆ   r‰   ÚformNameZformModTimeZ
pdfModTimer4   r4   r5   ÚneedsProcessing2  s    z'PageCatcherCachingMixIn.needsProcessingc                 C   s.   |   ||¡}t||d |d |gd |d S )NrŽ   Ú_)ÚprefixÚpagenumbers)r   rƒ   )r2   rˆ   r‰   r‘   r4   r4   r5   Ú
processPDF<  s    
þz"PageCatcherCachingMixIn.processPDFN)rX   rY   rZ   rd   r   r’   r–   r4   r4   r4   r5   r†   )  s   
r†   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )ÚcachePageCatcherFigureNonA4ú?PageCatcher page with a caption below it.  Size to be supplied.Nc                 C   s`   t j |¡\| _| _| jdkr&t j| _|| _|  | j| j¡d t|ƒ | _	t
 | ||||¡ d S )Nr   r“   )ru   rv   rr   rŠ   ry   Úcurdirr‰   r   Ústrr‘   rg   r   ©r2   ry   r‰   r"   r    r3   r,   r4   r4   r5   r   H  s    
z$cachePageCatcherFigureNonA4.__init__c                 C   s’   | j  ¡  | j  | j¡sd| jtj | j }|  || j	¡d }|  
|| j	¡rX|  || j	¡ t|| j ƒ}| j  | j| j¡ | j  | j¡ | j  ¡  d S )NrŽ   )rE   rI   ÚhasFormr‘   rŠ   ru   Úsepry   r   r‰   r’   r–   r‚   rc   rn   ÚdoFormrK   )r2   ZrestorePathZformFileNameÚnamesr4   r4   r5   rJ   P  s    
z&cachePageCatcherFigureNonA4.drawFigure)Nrz   r4   r4   r4   r5   r—   D  s   
r—   c                   @   s   e Zd ZdZddd„ZdS )ÚcachePageCatcherFigureúPageCatcher page with a caption below it.  Presumes A4, Portrait.
        This needs our commercial PageCatcher product, or you'll get a blank.éS  éJ  Nc              	   C   s   t j| ||||||d d S )N)r,   )r—   r   r›   r4   r4   r5   r   a  s    zcachePageCatcherFigure.__init__)r¢   r£   N©rX   rY   rZ   rd   r   r4   r4   r4   r5   r    ^  s   r    c                   @   s&   e Zd ZdZi Zddd„Zdd„ ZdS )ÚPageCatcherFigureNonA4r˜   Nc           	      C   sˆ   | }| _ || _| tjd¡ dd¡ dd¡ dd¡ dd¡}| dd¡d t|ƒ d | _| jt|ƒ | _|| _t	 
| ||||¡ d S )Nr“   ú/ú\ú-ú:Ú.)ry   r‰   Úreplaceru   r   rš   r”   r‘   Úcachingrg   r   )	r2   ry   r‰   r"   r    r3   r,   r¬   Úfnr4   r4   r5   r   i  s    
.zPageCatcherFigureNonA4.__init__c                 C   s¾   | j  | j¡s†| j| jv r,| j| j \}}nNt| jdƒ}| ¡ }| ¡  t|| j	g| j
d\}}| jdkrz||f| j| j< t|| j ƒ}| j  ¡  | j  | j| j¡ | j  | j¡ | j  ¡  d S )NÚrb)r•   r”   Zmemory)rE   rœ   r‘   ry   Ú_cacheÚopenÚreadÚcloser„   r‰   r”   r¬   r…   rI   rc   rn   rž   rK   )r2   ÚfÚdataZpdfr4   r4   r5   rJ   r  s    

z!PageCatcherFigureNonA4.drawFigure)NN)rX   rY   rZ   rd   r¯   r   rJ   r4   r4   r4   r5   r¥   d  s   
	r¥   c                   @   s   e Zd ZdZddd„ZdS )ÚPageCatcherFigurer¡   r¢   r£   Nc              
   C   s   t j| |||||||d d S )N)r,   r¬   )r¥   r   )r2   ry   r‰   r"   r    r3   r,   r¬   r4   r4   r5   r   †  s    zPageCatcherFigure.__init__)r¢   r£   NNr¤   r4   r4   r4   r5   rµ   ƒ  s   rµ   c                 C   s`   t dt dt dt dt dd}tdtddd	d
}td|ƒ}td|ƒ}||g}| || ¡ d S )Né   é   é   rP   ©ZshowBoundaryZBodyé   é   é   )r   r   r8   r.   ziSpam spam spam spam. Spam spam spam spam. Spam spam spam spam. Spam spam spam spam. Spam spam spam spam. zPEggs eggs eggs. Eggs eggs eggs. Eggs eggs eggs. Eggs eggs eggs. Eggs eggs eggs. )r   r
   r   r   r	   ÚaddFromList)r[   ÚframeZ	bodyStyleZpara1Zpara2Zmydatar4   r4   r5   rf   ‰  s    û

rf   c                  C   sV   t dƒ} tttdt dt dd}tƒ }tdƒ|_tdƒ|_| |g| ¡ |  ¡  d S )Nzfigures.pdfr¼   ri   rP   r¹   ZblueZlightyellow)	r   r   r
   re   r   r%   r&   r½   Úsave)rU   r³   Úvr4   r4   r5   Útest1š  s    

rÁ   Ú__main__)3rd   Ú__version__ru   Zreportlab.libr   Zreportlab.pdfgen.canvasr   Zreportlab.lib.stylesr   rx   r   r   Zreportlab.platypusr   r   r	   Zreportlab.lib.unitsr
   Zreportlab.lib.enumsr   r   r   Zreportlab.lib.validatorsr   Zreportlab.lib.colorsr   r   r   r;   r   r_   r`   re   rg   rs   r{   Zrlextra.pageCatcher.pageCatcherr‚   rƒ   r„   r…   Z_hasPageCatcherÚImportErrorr†   r—   r    r¥   rµ   rf   rÁ   rX   r4   r4   r4   r5   Ú<module>   sJ   <
	
