a
    còf…(  ã                   @   s6  U d Z ddlZddlmZmZmZmZmZmZm	Z	 ddl
mZmZmZ daeed< daeed< g aee ed	< d
Zeed< G dd„ deƒZde	eedf e	eedf e	eee df eeeee f dœdd„Zee ee ee dœdd„Zee edœdd„Zeeee ee f eee ee f eee ee f ee	eeeef f eeef eee f eedf eeeeeeeeegdf  eeeeee ee f dœdd„Zeee	eef  ee ee ee	eeeef f eeef eee f eedf eeeeeeeeeegdf  eeef dœdd„ZdS )ze
Code related to text extraction.

Some parts are still in _page.py. In doubt, they will stay there.
é    N)ÚAnyÚCallableÚDictÚListÚOptionalÚTupleÚUnioné   )ÚDictionaryObjectÚTextStringObjectÚencode_pdfdocencodingéÿÿÿÿÚCUSTOM_RTL_MINÚCUSTOM_RTL_MAXÚCUSTOM_RTL_SPECIAL_CHARSé   Ú LAYOUT_NEW_BT_GROUP_SPACE_WIDTHSc                   @   s   e Zd ZdS )ÚOrientationNotFoundErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú\/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/pypdf/_text_extraction/__init__.pyr      s   r   )Ú_minÚ_maxÚspecialsÚreturnc                 C   sv   t | tƒr| ant | tƒr"t| ƒat |tƒr2|ant |tƒrDt|ƒat |tƒr^dd„ |D ƒant |tƒrl|atttfS )aÙ  
    Change the Right-To-Left and special characters custom parameters.

    Args:
        _min: The new minimum value for the range of custom characters that
            will be written right to left.
            If set to ``None``, the value will not be changed.
            If set to an integer or string, it will be converted to its ASCII code.
            The default value is -1, which sets no additional range to be converted.
        _max: The new maximum value for the range of custom characters that will
            be written right to left.
            If set to ``None``, the value will not be changed.
            If set to an integer or string, it will be converted to its ASCII code.
            The default value is -1, which sets no additional range to be converted.
        specials: The new list of special characters to be inserted in the
            current insertion order.
            If set to ``None``, the current value will not be changed.
            If set to a string, it will be converted to a list of ASCII codes.
            The default value is an empty list.

    Returns:
        A tuple containing the new values for ``CUSTOM_RTL_MIN``,
        ``CUSTOM_RTL_MAX``, and ``CUSTOM_RTL_SPECIAL_CHARS``.
    c                 S   s   g | ]}t |ƒ‘qS r   )Úord©Ú.0Úxr   r   r   Ú
<listcomp>=   ó    z"set_custom_rtl.<locals>.<listcomp>)Ú
isinstanceÚintr   Ústrr   r   r   Úlist)r   r   r   r   r   r   Úset_custom_rtl   s    





r'   )ÚmÚnr   c              	   C   sÈ   | d |d  | d |d   | d |d  | d |d   | d |d  | d |d   | d |d  | d |d   | d |d  | d |d   |d  | d |d  | d |d   |d  gS )Nr   é   r	   é   é   r   r   )r(   r)   r   r   r   ÚmultC   s    &&úr-   )r(   r   c                 C   s8   | d dkrdS | d dk r dS | d dkr0dS dS d S )	Nr+   g�íµ ÷Æ°>r   g�íµ ÷Æ°¾é´   r*   éZ   é  r   )r(   r   r   r   ÚorientN   s    r1   .)ÚtextÚ	cmtm_prevÚcmtm_matrixÚ	memo_cmtmÚcmapÚorientationsÚoutputÚ	font_sizeÚvisitor_textÚ
spacewidthr   c
                 C   st  |d }
|d }|d }|d }|d }|d }t ||
ƒ}t ||ƒ}t|ƒ}|d |d  }|d |d  }t t|d |d  ƒt|d |d  ƒ ¡}|| }|}
||vr²t‚�zŽ|dk�rZ|d| k �r||  d d	k�rV|| d	 7 }|d u�r|| d	 |||d |ƒ d
} nBt|ƒ|d k �r@t|ƒ|	| d k�r@||  d dk�r@| d7 } �næ|dk�rþ|d| k�r¸||  d d	k�rú|| d	 7 }|d u�r²|| d	 |||d |ƒ d
} nBt|ƒ|d k �r@t|ƒ|	| d k�r@||  d dk�r@| d7 } �nB|dk�r |d| k�r\||  d d	k�rž|| d	 7 }|d u�rV|| d	 |||d |ƒ d
} nBt|ƒ|d k �r@t|ƒ|	| d k�r@||  d dk�r@| d7 } n |dk�r@|d| k �rþ||  d d	k�r@|| d	 7 }|d u�rø|| d	 |||d |ƒ d
} nBt|ƒ|d k �r@t|ƒ|	| d k�r@||  d dk�r@| d7 } W n t�yV   Y n0 | ¡ }| ¡ }
| ||
|fS )Nr   r*   r,   r   r+   r	   gš™™™™™é¿r   Ú
Ú g333333Ó?é   ú r.   gš™™™™™é?r/   r0   )r-   r1   ÚmathÚsqrtÚabsr   Ú	ExceptionÚcopy)r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   Zcm_prevZtm_prevÚ	cm_matrixÚ	tm_matrixZmemo_cmZmemo_tmZm_prevr(   ÚorientationZdelta_xZdelta_yÚkÚfr   r   r   Úcrlf_space_checkY   sÌ    

.

ûÿþý

ûÿþý

ûÿþý


ûÿþýrJ   )r2   ÚoperandsrE   rF   r6   r7   r8   r9   Úrtl_dirr:   r   c
                    sv  t ||ƒ}
t|
ƒ}||v �rnt|ƒdk�rnt|d tƒrH| |d 7 } �n&d}t|d tƒrft|d ƒn|d }tˆ d tƒrÂz| ˆ d d¡}W qÚ ty¾   | ˆ d dkr²dndd¡}Y qÚ0 nd ‡ fdd„|D ƒ¡}‡ fdd„|D ƒD �]~}t|ƒd	k�r
t	|ƒ}nd	}|d
k�spd|  k�r0dk�spn d|  k�rJdk�spn d|  k�rddk�spn |t
v �rˆ|�r~||  n| | } qìd|  k�r dk�sòn d|  k�rºdk�sòn d|  k�rÔdk�sòn t|  k�rîtk�r0n n>|�s&d}|| 7 }|	d u�r"|	| ||ˆ d |ƒ d} ||  } qì|�rdd}|| 7 }|	d u�r`|	| ||ˆ d |ƒ d} | | } qì| |fS )Nr   r=   ÚsurrogatepassÚcharmapz	utf-16-bec                    s2   g | ]*}|ˆ d  v r ˆ d  | nt |fƒ ¡ ‘qS )r   )ÚbytesÚdecoder   ©r6   r   r   r!   ó   r"   zhandle_tj.<locals>.<listcomp>c                    s(   g | ] }|ˆ d  v r ˆ d  | n|‘qS )r*   r   r   rQ   r   r   r!   ö   r"   r*   é/   é:   é@   i    io   i    iÿ!  i�  iÿ  iû  iÿý  ipþ  iÿþ  Tr+   F)r-   r1   Úlenr#   r%   r   rP   rC   Újoinr   r   r   r   )r2   rK   rE   rF   r6   r7   r8   r9   rL   r:   r(   rG   ÚtÚttr    Úxxr   rQ   r   Ú	handle_tjÌ   s’    
ÿýþÿ
þý
ý
ü
ü
û
û
úÿ
ÿ
þ
þ
ý
ý
ü
ü



rZ   )NNN)Ú__doc__r@   Útypingr   r   r   r   r   r   r   Zgenericr
   r   r   r   r$   Ú__annotations__r   r   r   rC   r   r%   r'   Úfloatr-   r1   rJ   ÚboolrZ   r   r   r   r   Ú<module>   s^   $   ýü-&ÿ
ót&ÿ

ó