a
    ¥Q•h“2  ã                   @   sR  d Z dZdZddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ dd	„ Zd
d„ Zdd„ Zdd„ ZG dd„ deƒZG dd„ deƒZedk�rNddlZdd„ Zdd„ Zdd„ ZddlmZmZ eƒ Z e d Z!ede!d�Z"d e"_#d!de"d"d#dfd$d%e"d"d#dfd&de d' d"d(d)ffD ](\Z$Z%Z&Z'Z(Z)e)�r$ee$e&e%e'e(ƒ �q$dS )*)ÚXPreformattedÚPythonPreformattedz3.5.20z:A 'rich preformatted text' widget allowing internal markupé    )Ú	PyFontify)Ú	ParagraphÚ_handleBulletWidthÚ	ParaLinesÚ_getFragWordsÚstringWidthÚgetAscentDescentÚ	imgVRangeÚimgNormV)ÚisSeq)Ú	_dedenterc                 C   sº   g }g }| d d … }|g kr¤|d }|j }|d= | d¡}|dkr˜||d d … }| |j|d |… d�¡ | |¡ g }|dkr¢| d|j|d�¡ q| |¡ q|g kr¶| |¡ |S )Nr   Ú
é   ©ÚtextÚ )r   ÚfindÚappendÚcloneÚinsert)ÚfragsÚlinesZclineÚWÚwÚtÚiZtleft© r   úY/var/www/sistema_ama/venv/lib/python3.9/site-packages/reportlab/platypus/xpreformatted.pyÚ_getFragLines   s&    


r    c                 C   s<   |   ¡ }dD ]}t||ƒrt||ƒ q| j||… |_|gS )N)r   r   )r   ÚhasattrÚdelattrr   )ÚblParaÚstartÚstopÚfÚar   r   r   Ú_split_blPara&   s
    r(   c                 C   s
   |   d¡S )Nú )Úcountr   r   r   r   Ú_countSpaces.   s    r+   c           	      C   sŠ   g }d}d}| D ]n}|j dd… }| ||f¡ t|ddƒ}|r\t|ddƒ}t|dƒr\||_|t||j|jƒ7 }|| d¡7 }q|||fS )z� given a fragment list return a list of lists
        [size, spaces, (f00,w00), ..., (f0n,w0n)]
        each pair f,w represents a style and some string
    r   NÚcbDefnÚwidthÚnormalizedValuer)   )	r   r   Úgetattrr!   Ú_normalizerr	   ÚfontNameÚfontSizer*   )	r   ÚmaxWidthr   ÚnÚsr&   r   ÚcbÚ_wr   r   r   Ú_getFragWord8   s    
r8   c                   @   s*   e Zd Zd
dd„Zdd„ ZeZdd	„ ZdS )r   Nr   r   c                 C   s(   || _ |fdd„}|  |||||¡ d S )Nc                 S   s   d  t| pd|ƒ¡S )Nr   r   )Újoinr   )r   Údedentr   r   r   Ú<lambda>T   ó    z(XPreformatted.__init__.<locals>.<lambda>)ÚcaseSensitiveÚ_setup)Úselfr   ÚstyleÚ
bulletTextr   r=   r:   Úcleanerr   r   r   Ú__init__R   s    zXPreformatted.__init__c                  C   sz  d| _ t|ƒs|g}n|}g }d}|| }| j}t|jƒ}d}t| j||ƒ d| _t| dt|ddƒƒ}	|	dv}
| j	}t
|ƒ}|dk�r¬|d }t|dƒ�rP|j}|j}t||ƒ\}}d}|j d¡}|D ]p}t|||ƒ}|| j krè|| _ t||ƒ}|| }| || d¡|f¡ |d }|t
|ƒk �r0|| �p6|d	 }qÈ|j|||||d
�}nJ|j}|j}|D ]*}|dk�rx|d }n|j}t||ƒ}�q`|j||d�}t| j|ƒ| _|S |dk�rÚtd|j|j|j|jd|j g d�S t|ƒD �]v}t||ƒ\}}}|d d }|j}t|j|ƒ\}}| ¡ g}|d d |d	 _|dd… D ]ª}|d  ¡ }|d |_| |¡ |j}|j}|
�r¾t|ddƒ}t|ddƒ�r®tt|j|ƒ|j|ƒ\}}nt||ƒ\}}nt||ƒ\}}t||ƒ}t||ƒ}t||ƒ}�qB|d7 }|t
|ƒk �r|| �p|d	 }t||ƒ}|| }|| j k�r:|| _ | t|||||||dd�¡ �qât| j|ƒ| _td|d�S |S )a/  
        Returns a broken line structure. There are two cases

        A) For the simple case of a single formatting input fragment the output is
            A fragment specifier with
                - kind = 0
                - fontName, fontSize, leading, textColor
                - lines=  A list of lines
                
                    Each line has two items:
                    
                    1. unused width in points
                    2. a list of words

        B) When there is more than one input formatting fragment the out put is
            A fragment specifier with
                - kind = 1
                - lines =  A list of fragments each having fields:
                
                    - extraspace (needed for justified)
                    - fontSize
                    - words=word list
                    - each word is itself a fragment with
                    - various settings

        This structure can be used to easily draw paragraphs with the various alignments.
        You can supply either a single width or a list of widths; the latter will have its
        last item repeated until necessary. A 2-element list is useful when there is a
        different first line indent; a longer list could be created to facilitate custom wraps
        around irregular objects.r   ÚautoLeadingr   )r   Úoffr   r   r   r)   éÿÿÿÿ)Úkindr   ÚascentÚdescentr2   é   )rG   r   gš™™™™™É¿)rG   r2   r1   Ú	textColorrH   rI   r   Nr,   r-   T)Ú
extraSpaceÚ	wordCountÚwordsr2   rH   rI   ÚcurrentWidthÚpreformatted) Ú
_width_maxr   r@   Úfloatr2   r   rA   Úheightr/   r   Úlenr!   r1   r
   r   Úsplitr	   Úmaxr   r   rG   r   rO   r-   r   rK   r    r8   r   r   ÚvalignÚmin) r?   r-   Ú	maxWidthsr   Úlinenor3   r@   Z	fFontSizeZrequiredWidthrD   Ú
calcBoundsr   ÚnFragsr&   r2   r1   rH   rI   rG   ÚLÚlrO   rL   r#   r4   r   ÚmaxSizeÚ	maxAscentÚ
minDescentrN   r   r,   r   r   r   Ú
breakLinesW   sœ     


"


þ




 
"zXPreformatted.breakLinesc                 C   s   t S )N)r(   )r?   r   r   r   Ú_get_split_blParaFuncÔ   s    z#XPreformatted._get_split_blParaFunc)NNr   r   )Ú__name__Ú
__module__Ú__qualname__rC   rb   ÚbreakLinesCJKrc   r   r   r   r   r   Q   s   
zr   c                   @   s<   e Zd ZdZdddddddœZddd„Zdd„ Zdd„ Zd	S )r   zGUsed for syntax-colored Python code, otherwise like XPreformatted.
    )r   r   )z<font color="green">ú</font>)z<font color="blue"><b>z</b></font>)z<font color="black">rh   )z<font color="red">rh   )z<font color="gray">rh   )ÚrestÚcommentÚkeywordÚ	parameterÚ
identifierÚstringNr   c                 C   s.   |r|   |  |¡¡}tj| |||||d� d S )N)rA   r:   r   )ÚfontifyÚ
escapeHtmlr   rC   )r?   r   r@   rA   r:   r   r   r   r   rC   â   s    zPythonPreformatted.__init__c                 C   s(   |  dd¡}|  dd¡}|  dd¡}|S )Nú&z&amp;ú<z&lt;ú>z&gt;)Úreplace)r?   r   r5   r   r   r   rp   ç   s    zPythonPreformatted.escapeHtmlc                 C   sŠ   |d dkr|dd… }t  |¡}d}d}|D ]F\}}}}||||…  }| j| \}	}
||	 |||…  |
 }|}q.|||d…  }|S )z/Return a fontified version of some Python code.r   r   r   Nr   )r   ro   Úformats)r?   ÚcodeÚtagsZfontifiedCodeÚposÚkr   ÚjÚdummyr5   Úer   r   r   ro   í   s    
zPythonPreformatted.fontify)Nr   N)rd   re   rf   Ú__doc__ru   rC   rp   ro   r   r   r   r   r   ×   s   ú
r   Ú__main__Nc           	      C   sŽ   t dt| ƒ ƒ | jj}t|ƒ}tjj}t|ƒD ]X}|| }|j	}t|ƒ}|d|||j
f ƒ t|ƒD ]}|d||| jf ƒ qft ƒ  q0d S )Nz(
############dumpXPreforemattedLines(%s)zline%d: %d(%d)
  z %d:'%s')ÚprintÚstrr#   r   rT   ÚsysÚstdoutÚwriteÚrangerN   rM   r   )	ÚPr   r4   Úoutwr^   ÚlinerN   Znwordsr   r   r   r   ÚdumpXPreformattedLines  s    rˆ   c                 C   sÂ   t dt| ƒ ƒ | j}t|ƒ}t|ƒD ]}t d||| jf ƒ q&tjj}d}t	|ƒD ]f}d}t
|dƒD ]J}|d|||d f ƒ |d }|dd … D ]}|d|d  ƒ q–t ƒ  qh|d }qVd S )Nz(
############dumpXPreforemattedFrags(%s)zfrag%d: '%s'r   ih  zfrag%d.%d: size=%dr   z '%s')r   r€   r   rT   r„   r   r�   r‚   rƒ   r    r   )r…   r   r4   r^   r†   r]   r   r   r   r   r   ÚdumpXPreformattedFrags  s     r‰   c           
      C   sh   t | ||d�}t|ƒ | ||¡\}}t|ƒ | ||¡}t|ƒ |D ]}	|	 ||¡ t|	ƒ d}qFd S )N)r:   iô  )r   r‰   Úwraprˆ   rU   )
r   r@   r:   ÚaWÚaHr…   r   ÚhÚSr5   r   r   r   Útry_it#  s    r�   )ÚgetSampleStyleSheetÚParagraphStyleÚBodyTextZdiscussiontext)ÚparentÚ	Helveticaa?  


The <font name=courier color=green>CMYK</font> or subtractive

method follows the way a printer
mixes three pigments (cyan, magenta, and yellow) to form colors.
Because mixing chemicals is more difficult than combining light there
is a fourth parameter for darkness.  For example a chemical
combination of the <font name=courier color=green>CMY</font> pigments generally never makes a perfect

black -- instead producing a muddy color -- so, to get black printers
don't use the <font name=courier color=green>CMY</font> pigments but use a direct black ink.  Because
<font name=courier color=green>CMYK</font> maps more directly to the way printer hardware works it may
be the case that &amp;| &amp; | colors specified in <font name=courier color=green>CMYK</font> will provide better fidelity
and better control when printed.


g     €|@gffffffE@av  

   This is a non rearranging form of the <b>Paragraph</b> class;
   <b><font color=red>XML</font></b> tags are allowed in <i>text</i> and have the same

      meanings as for the <b>Paragraph</b> class.
   As for <b>Preformatted</b>, if dedent is non zero <font color=red size=+1>dedent</font>
       common leading spaces will be removed from the
   front of each line.

é   z›    <font color=blue>class </font><font color=red>FastXMLParser</font>:
        # Nonsense method
        def nonsense(self):
            self.foo = 'bar'
ÚCodeg333333@r   )*Ú__all__Ú__version__r}   Úreportlab.libr   Úreportlab.platypus.paragraphr   r   r   r   r	   r
   r   r   Úreportlab.lib.utilsr   Zreportlab.platypus.flowablesr   r    r(   r+   r8   r   r   rd   r�   rˆ   r‰   r�   Úreportlab.lib.stylesr�   r‘   Z
styleSheetÚBZDTstyler1   r   r:   r@   r‹   rŒ   Úactiver   r   r   r   Ú<module>   sD   (
 )

î

öûâ%