a
    7Xh2                     @   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   e/var/www/viveiro_mudafortebrasil/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widthZnormalizedValuer)   )	r   r   getattrr!   Z_normalizerr	   fontNamefontSizer*   )	r   maxWidthr   nsr&   r   cb_wr   r   r   _getFragWord8   s    
r6   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;   r8   Z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rt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}|
rt|dd}t|ddrt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 qt| 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descentr0      )rD   r   gɿ)rD   r0   r/   	textColorrE   rF   r   Nr,   r-   T)
extraSpace	wordCountwordsr0   rE   rF   currentWidthZpreformatted) Z
_width_maxr   r>   floatr0   r   r?   heightr.   r   lenr!   r/   r
   r   splitr	   maxr   r   rD   r   rL   r-   r   rH   r    r6   r   r   Zvalignmin) r=   r-   Z	maxWidthsr   linenor1   r>   Z	fFontSizeZrequiredWidthrA   Z
calcBoundsr   ZnFragsr&   r0   r/   rE   rF   rD   LlrL   rI   r#   r2   r   ZmaxSizeZ	maxAscentZ
minDescentrK   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__r@   rV   ZbreakLinesCJKrW   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">r[   )z<font color="red">r[   )z<font color="gray">r[   )restcommentkeywordZ	parameter
identifierstringNr   c                 C   s.   |r|  | |}tj| |||||d d S )N)r?   r8   r   )fontify
escapeHtmlr   r@   )r=   r   r>   r?   r8   r   r   r   r   r@      s    zPythonPreformatted.__init__c                 C   s(   | dd}| dd}| dd}|S )N&z&amp;<z&lt;>z&gt;)replace)r=   r   r3   r   r   r   rb      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   ra   formats)r=   codetagsZfontifiedCodeposkr   jdummyr3   er   r   r   ra      s    
zPythonPreformatted.fontify)Nr   N)rX   rY   rZ   __doc__rg   r@   rb   ra   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   rO   sysstdoutwriterangerK   rJ   r   )	Pr   r2   outwrU   linerK   Znwordsr   r   r   r   dumpXPreformattedLines  s    rz   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   qt   qh|d }qVd S )Nz(
############dumpXPreforemattedFrags(%s)zfrag%d: '%s'r   ih  zfrag%d.%d: size=%dr   z '%s')rq   rr   r   rO   rv   r   rs   rt   ru   r    r   )rw   r   r2   rU   rx   rT   r   r   r   r   r   dumpXPreformattedFrags  s     r{   c           
      C   sh   t | ||d}t| |||\}}t| |||}t| |D ]}	|	|| t|	 d}qFd S )N)r8   i  )r   r{   wraprz   rP   )
r   r>   r8   aWaHrw   r   hSr3   r   r   r   try_it#  s    r   )getSampleStyleSheetParagraphStyleZBodyTextZdiscussiontext)parentZ	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'
ZCodeg333333@r   )*__all____version__ro   Zreportlab.libr   Zreportlab.platypus.paragraphr   r   r   r   r	   r
   r   r   Zreportlab.lib.utilsr   Zreportlab.platypus.flowablesr   r    r(   r+   r6   r   r   rX   rs   rz   r{   r   Zreportlab.lib.stylesr   r   Z
styleSheetBZDTstyler/   r   r8   r>   r}   r~   activer   r   r   r   <module>   sD   (
 )



%