o
    g2                     @   sP  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rd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)ree$e&e%e'e( qdS 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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    ]/var/www/rescue_company/venv/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!   _getFragWord8   s   

r:   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   s    z(XPreformatted.__init__.<locals>.<lambda>)caseSensitive_setup)selfr   style
bulletTextr   r>   r<   cleanerr    r    r!   __init__R   s   zXPreformatted.__init__c                  C   sd  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r|j}|j}t||\}}d}|jd}|D ]6}t|||}|| j krr|| _ t||}|| }|||d|f |d }|t
|k r|| p|d	 }qb|j|||||d
}n#|j}|j}|D ]}|dkr|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 ]}t||\}}}|d d }|j}t|j|\}}| g}|d d |d	 _|dd D ]U}|d  }|d |_|| |j}|j}|
rWt|dd}t|ddrOtt|j||j|\}}nt||\}}nt||\}}t||}t||}t||}q|d7 }|t
|k r|| p|d	 }t||}|| }|| j kr|| _ |t|||||||dd qt| 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descentr4      )rH   r   gɿ)rH   r4   r3   	textColorrI   rJ   r   Nr.   r/   T)
extraSpace	wordCountwordsr4   rI   rJ   currentWidthpreformatted) 
_width_maxr   rA   floatr4   r   rB   heightr1   r   lenr#   r3   r
   r   splitr	   maxr   r   rH   r   rP   r/   r   rL   r"   r:   r   r   valignmin) r@   r/   	maxWidthsr   linenor5   rA   	fFontSizerequiredWidthrE   
calcBoundsr   nFragsr(   r4   r3   rI   rJ   rH   LlrP   rM   r%   r6   r   maxSize	maxAscent
minDescentrO   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__rD   re   breakLinesCJKrf   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">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   r7   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dummyr7   er    r    r!   rr      s   
zPythonPreformatted.fontify)Nr   N)rg   rh   ri   __doc__rx   rD   rs   rr   r    r    r    r!   r      s    
r   __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   rU   sysstdoutwriterangerO   rN   r   )	Pr   r6   outwra   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   rU   r   r   r   r   r   r"   r   )r   r   r6   ra   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   rV   )
r   rA   r<   aWaHr   r   hSr7   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   )*__all____version__r   reportlab.libr   reportlab.platypus.paragraphr   r   r   r   r	   r
   r   r   reportlab.lib.utilsr   reportlab.platypus.flowablesr   r"   r*   r-   r:   r   r   rg   r   r   r   r   reportlab.lib.stylesr   r   
styleSheetBDTstyler3   r   r<   rA   r   r   activer    r    r    r!   <module>   sL   (
 )


%4