o
    j$                     @   sP  d Z ddlmZ ddlZddlmZ ddlmZm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ZG dd dZdd Zdd Zd<dedefddZdefddZd=defdd Zd!efd"d#Zd$efd%d&Zd>d(ed)ed*ed+ed,ef
d-d.Zd/efd0d1Zd2ed3ed4efd5d6Zd?d4efd8d9Zd@d:d;ZdS )AzCommon methods.    )EnumN)Iterable)getColorListgetColorInfoListc                   @   (   e Zd ZdZdZdZdZdZdZdZ	dS )		BlockTypezBlock types.r               N)
__name__
__module____qualname____doc__Z	UNDEFINEDZTEXTZIMAGEZLATTICE_TABLEZSTREAM_TABLEZFLOAT_IMAGE r   r   V/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/pdf2docx/common/share.pyr   	       r   c                   @   r   )	RectTypezShape type in context.r	   r
   r             N)
r   r   r   r   Z	HIGHLIGHTZ	UNDERLINEZSTRIKEZ	HYPERLINKZBORDERZSHADINGr   r   r   r   r      r   r   c                   @   s    e Zd ZdZdZdZdZdZdS )TextDirectiona)  Text direction.
    * LEFT_RIGHT: from left to right within a line, and lines go from top to bottom
    * BOTTOM_TOP: from bottom to top within a line, and lines go from left to right
    * MIX       : a mixture if LEFT_RIGHT and BOTTOM_TOP
    * IGNORE    : neither LEFT_RIGHT nor BOTTOM_TOP
    r   r   r	   r
   N)r   r   r   r   ZIGNORE
LEFT_RIGHT
BOTTOM_TOPMIXr   r   r   r   r      s    r   c                   @   r   )	TextAlignmentzText alignment.

    .. note::
        The difference between ``NONE`` and ``UNKNOWN``: 

        * NONE: none of left/right/center align -> need TAB stop
        * UNKNOWN: can't decide, e.g. single line only
    r   r   r	   r
   r   r   N)
r   r   r   r   NONEUNKNOWNZLEFTZCENTERZRIGHTZJUSTIFYr   r   r   r   r   *   s    r   c                   @   s@   e Zd ZdZedd Zedd Zedd Zedd	 Zd
S )ITextz2Text related interface considering text direction.c                 C   s   t jS )z0Text direction is from left to right by default.)r   r   selfr   r   r   text_direction=   s   zIText.text_directionc                 C   s   | j tjkp| j tjkS )z3Check whether text direction is from left to right.)r"   r   r   r   r    r   r   r   is_horizontal_textB   s   
zIText.is_horizontal_textc                 C      | j tjkS )z3Check whether text direction is from bottom to top.)r"   r   r   r    r   r   r   is_vertical_textH   s   zIText.is_vertical_textc                 C   r$   )zYCheck whether text direction is either from left to 
        right or from bottom to top.)r"   r   r   r    r   r   r   is_mix_textM   s   zIText.is_mix_textN)	r   r   r   r   propertyr"   r#   r%   r&   r   r   r   r   r   ;   s    


r   c                   @   s    e Zd ZdZdd Zdd ZdS )lazypropertyz-Calculate only once and cache property value.c                 C   s
   || _ d S Nfunc)r!   r+   r   r   r   __init__V   s   
zlazyproperty.__init__c                 C   s*   |d u r| S |  |}t|| j j| |S r)   )r+   setattrr   )r!   instanceclsvaluer   r   r   __get__Y   s
   
zlazyproperty.__get__N)r   r   r   r   r,   r1   r   r   r   r   r(   T   s    r(   c                 C   s$   zt |  W dS  ty   Y dS w )z$Whether can be converted to a float.FT)float
ValueError)Z
str_numberr   r   r   	is_numbere   s   
r4   c                 c   s<    | D ]}t |trt ||st||E dH  q|V  qdS )z%Yield items from any nested iterable.N)
isinstancer   flatten)itemsklassitemr   r   r   r6   o   s   r6   numberndigitsc                 C   s   d| }t ||  | S )zPRound number to lower bound with specified digits, e.g. lower_round(1.26, 1)=1.2g      $@int)r:   r;   nr   r   r   lower_roundx   s   r?   sc                 C   s<   t dd | D }dD ]}z	||}W  |S    Y q|S )zTry to decode a unicode string.c                 s   s    | ]}t |V  qd S r)   )ord).0cr   r   r   	<genexpr>   s    zdecode.<locals>.<genexpr>)zutf-8gbkgb2312z
iso-8859-1)bytesdecode)r@   bencodingresr   r   r   rH   ~   s   
rH    namec                 C   sf   | r|   t v rt |   }ntdtt d }t | }|d d |d d |d d fS )zaGet a named RGB color (or random color) from fitz predefined colors, e.g. 'red' -> (1.0,0.0,0.0).r   r	   g     o@r
   r   )upperr   indexrandomrandintlenr   )rM   posrC   r   r   r   rgb_component_from_name   s
   
"rT   srgbc                    s(   t | dd d  fdddD S )zsrgb value to R,G,B components, e.g. 16711680 -> (255, 0, 0).

    Equal to PyMuPDF built-in method::

        [int(255*x) for x in fitz.sRGB_to_pdf(x)]
    r
   N   c                    s"   g | ]}t  ||d   dqS )r
   r   r<   )rB   ir@   r   r   
<listcomp>   s   " z!rgb_component.<locals>.<listcomp>)r   r
   r   )hexzfill)rU   r   rX   r   rgb_component   s   r\   rgbc                 C   s>   d}t | D ]\}}|t|d ddd|    7 }qt|S )z:RGB components to decimal value, e.g. (1,0,0) -> 16711680.r      r   r   r
   )	enumerater=   )r]   rK   rW   xr   r   r   rgb_to_value   s   "ra   d   rC   myk
cmyk_scalec           	      C   sr   d| t |  d|t |   }d|t |  d|t |   }d|t |  d|t |   }t|||g}|S )zCMYK components to GRB value.      ?)r2   ra   )	rC   rc   rd   re   rf   rgrI   rK   r   r   r   cmyk_to_rgb   s
      rj   
componentsc           
      C   s   t | }|dkrtt| \}}}}t||||dd}|S |dkr1tt| \}}}	t|||	g}|S |dkrDt| d }t|||g}|S d}|S )z-Gray/RGB/CMYK mode components to color value.r   rg   )rf   r   r	   r   )rR   mapr2   rj   ra   )
rk   numrC   rc   rd   re   colorrh   ri   rI   r   r   r   	rgb_value   s   ro   widthheighttitlec                 C   s,   | j ||d}td}|jd||dd |S )zInsert a new page with given title.

    Args:
        doc (fitz.Document): pdf document object.
        width (float): Page width.
        height (float): Page height.
        title (str): Page title shown in page.
    )rp   rq   gray)   r      )rn   Zfontsize)new_pagerT   Zinsert_text)docrp   rq   rr   pagers   r   r   r   rv      s   
rv   Tc                    s    fdd}|S )a  Plot the returned objects of inner function.

    Args:
        title (str): Page title.
        show (bool, optional): Don't plot if show==False. Default to True.

    .. note::
        Prerequisite of the inner function: 
            - the first argument is a :py:class:`~pdf2docx.page.BasePage` instance.
            - the last argument is configuration parameters in ``dict`` type.
    c                    s    fdd}|S )Nc                     sx    | i |}| d }| dd}| dd }| dd }r:|r:|r:|d ur:t||j|j}|| || |S )Nr   debugFZ	debug_docZdebug_filename)getrv   rp   rq   Zplotsave)argskwargsobjectsrx   ry   rw   filenameZ
debug_page)r+   showrr   r   r   inner   s   

z*debug_plot.<locals>.wrapper.<locals>.innerr   )r+   r   r   rr   r*   r   wrapper   s   zdebug_plot.<locals>.wrapperr   )rr   r   r   r   r   r   
debug_plot   s   r   c                 C   s   dS )aA  Returns `text` if `bullets` is true and `text` is a bullet character, or
    `numbers` is true and `text` is not empty and consists entirely of digits
    0-9. Otherwise returns None.

    If `bullets` is True we use an internal list of bullet characters;
    otherwise it should be a list of integer Unicode values.
    F)rR   rA   chrr5   list)textZbulletsnumbersZbullets2rC   ccr   r   r   is_list_item  s   r   )r   )rL   )rb   )T)TT)r   enumr   rP   collections.abcr   Z
fitz.utilsr   r   r   r   r   r   r   r(   r4   r6   r2   r=   r?   strrH   rT   r\   r   ra   rj   ro   rv   r   r   r   r   r   r   <module>   s.    


	 	"