o
    vùr[Ž1  ã                   @   sP  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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r¤d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 dS ))z3.3.0z:A 'rich preformatted text' widget allowing internal markupé    )Ú	PyFontify)	Ú	ParagraphÚcleanBlockQuotedTextÚ_handleBulletWidthÚ	ParaLinesÚ_getFragWordsÚstringWidthÚgetAscentDescentÚ	imgVRangeÚimgNormV)ÚisSeq)Ú	_dedenterc                 C   sÀ   g }g }| d d … }|g krU|d }|j }|d= | d¡}|dkrL||d d … }| |j|d |… d�¡ | |¡ g }|dkrK| d|j|d�¡ n| |¡ |g ks|g kr^| |¡ |S )Nr   Ú
é   ©ÚtextÚ )r   ÚfindÚappendÚcloneÚinsert)ÚfragsÚlinesÚclineÚWÚwÚtÚiÚtleft© r   úR/var/www/html/env/lib/python3.10/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 ]7}|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    Ú_getFragWord4   s   

r9   c                   @   s*   e Zd Zd
dd„Zdd„ ZeZdd	„ ZdS )ÚXPreformattedNr   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>P   s    z(XPreformatted.__init__.<locals>.<lambda>)ÚcaseSensitiveÚ_setup)Úselfr   ÚstyleÚ
bulletTextr   r>   r<   Úcleanerr   r   r    Ú__init__N   s   zXPreformatted.__init__c                  C   s<  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ƒr™|j}|j}t||ƒ\}}d}|j d¡}|D ].}t|||ƒ}t||ƒ}|| }| || d¡|f¡ |d }|t	|ƒk r‰|| pŒ|d	 }q_|j|||||d
�}n#|j}|j}|D ]}|dkr¬|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 ]±}t||ƒ\}}}|d d }|j}t|j|ƒ\}}| ¡ g}|d d |d	 _|dd… D ]U}|d  ¡ }|d |_| |¡ |j}|j}|
�rLt|ddƒ}t|ddƒ�rDtt|j|ƒ|j|ƒ\}}nt||ƒ\}}nt||ƒ\}}t||ƒ}t||ƒ}t||ƒ}�q|d7 }|t	|ƒk �rt|| �pw|d	 }t||ƒ}|| }| t|||||||dd�¡ qßt| j|ƒ| _td|d�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Údescentr3   é   )rH   r   gš™™™™™É¿)rH   r3   r2   Ú	textColorrI   rJ   r   Nr-   r.   T)Ú
extraSpaceÚ	wordCountÚwordsr3   rI   rJ   ÚcurrentWidthÚpreformatted)r   rA   Úfloatr3   r   rB   Úheightr0   r   Úlenr"   r2   r	   r   Úsplitr   Úmaxr   r   rH   r   rP   r.   r   rL   r!   r9   r
   r   ÚvalignÚmin) r@   r.   Ú	maxWidthsr   Úlinenor4   rA   Ú	fFontSizeÚrequiredWidthrE   Ú
calcBoundsr   ÚnFragsr'   r3   r2   rI   rJ   rH   ÚLÚlrP   rM   r$   r5   r   ÚmaxSizeÚ	maxAscentÚ
minDescentrO   r   r-   r   r   r    Ú
breakLinesS   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__rD   rd   ÚbreakLinesCJKre   r   r   r   r    r:   M   s
    
w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 )ÚPythonPreformattedzGUsed 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">rk   )z<font color="red">rk   )z<font color="gray">rk   )ÚrestÚcommentÚkeywordÚ	parameterÚ
identifierÚstringNr   c                 C   s.   |r
|   |  |¡¡}tj| |||||d� d S )N)rB   r<   r   )ÚfontifyÚ
escapeHtmlr:   rD   )r@   r   rA   rB   r<   r   r   r   r    rD   Û   s   zPythonPreformatted.__init__c                 C   s(   |  dd¡}|  dd¡}|  dd¡}|S )Nú&z&amp;ú<z&lt;ú>z&gt;)Úreplace)r@   r   r6   r   r   r    rs   à   s   zPythonPreformatted.escapeHtmlc                 C   sŠ   |d dkr|dd… }t  |¡}d}d}|D ]#\}}}}||||…  }| j| \}	}
||	 |||…  |
 }|}q|||d…  }|S )z/Return a fontified version of some Python code.r   r   r   Nr   )r   rr   Úformats)r@   ÚcodeÚtagsÚfontifiedCodeÚposÚkr   ÚjÚdummyr6   Úer   r   r    rr   æ   s   
zPythonPreformatted.fontify)Nr   N)rf   rg   rh   Ú__doc__rx   rD   rs   rr   r   r   r   r    rj   Ð   s    ú
rj   Ú__main__Nc           	      C   sŽ   t dt| ƒ ƒ | jj}t|ƒ}tjj}t|ƒD ],}|| }|j	}t|ƒ}|d|||j
f ƒ t|ƒD ]}|d||| jf ƒ q3t ƒ  qd S )Nz(
############dumpXPreforemattedLines(%s)zline%d: %d(%d)
  z %d:'%s')ÚprintÚstrr$   r   rT   ÚsysÚstdoutÚwriteÚrangerO   rN   r   )	ÚPr   r5   Úoutwr`   ÚlinerO   Ú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 ]3}d}t
|dƒD ]%}|d|||d f ƒ |d }|dd … D ]
}|d|d  ƒ qKt ƒ  q4|d }q+d 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   r5   r`   rŠ   r_   r   r   r   r   r    ÚdumpXPreformattedFrags	  s"   
ørŽ   c           
      C   sh   t | ||d�}t|ƒ | ||¡\}}t|ƒ | ||¡}t|ƒ |D ]}	|	 ||¡ t|	ƒ d}q#d S )N)r<   iô  )r:   rŽ   Úwrapr�   rU   )
r   rA   r<   ÚaWÚaHr‰   r   ÚhÚSr6   r   r   r    Útry_it  s   ýr”   )ÚgetSampleStyleSheetÚParagraphStyleÚBodyTextÚ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   )*Ú__version__r�   Úreportlab.libr   Úreportlab.platypus.paragraphr   r   r   r   r   r   r	   r
   r   Úreportlab.lib.utilsr   Úreportlab.platypus.flowablesr   r!   r)   r,   r9   r:   rj   rf   r…   r�   rŽ   r”   Úreportlab.lib.stylesr•   r–   Ú
styleSheetÚBÚDTstyler2   r   r<   rA   r�   r‘   Úactiver   r   r   r    Ú<module>   sJ   ,
 )
î

öûâ%€§4