
    Ng                         d dl Z d dlZd dlmZmZmZmZ ddlmZ ddl	m
Z
 ddlmZ  ej        d          Z e j        e          Zded	efd
Zded	dfdZ G d d          ZdS )    N)DictIterableOptionalcast   )glyphname2unicode)ENCODING)	PSLiteralz[0-9a-fA-F]+namereturnc                 >   t          | t                    s"t          d| dt          |                     |                     d          d         } |                     d          }t          |          dk    r(d                    t          t          |                    S | t          v rt          |          S | 
                    d          r|                     d          t                                        r~t                    d	z  dk    rhfd
t          dt                    d	          D             }|D ]}t          |           t          t           |          }d                    |          S n| 
                    d          r{|                     d          }t                              |          rLd	t          |          cxk    rdk    r2n n/t#          |d          }t          |           t!          |          S t          d| z            )a  Converts Adobe glyph names to Unicode numbers.

    In contrast to the specification, this raises a KeyError instead of return
    an empty string when the key is unknown.
    This way the caller must explicitly define what to do
    when there is not a match.

    Reference:
    https://github.com/adobe-type-tools/agl-specification#2-the-mapping

    :returns unicode character if name resembles something,
    otherwise a KeyError
    z Could not convert unicode name "z?" to character because it should be of type str but is of type .r   _r    uni   c                 H    g | ]}t          ||d z            d          S )r      base)int).0iname_without_unis     O/var/www/html/ai-engine/env/lib/python3.11/site-packages/pdfminer/encodingdb.py
<listcomp>z name2unicode.<locals>.<listcomp>0   sD     " " " (QU3"===" " "    u   r   r   zXCould not convert unicode name "%s" to character because it does not match specification)
isinstancestrKeyErrortypesplitlenjoinmapname2unicoder   
startswithstripHEXADECIMALmatchrange#raise_key_error_for_invalid_unicodechrr   )r   
componentsunicode_digitsdigit
charactersname_without_uunicode_digitr   s          @r   r(   r(      s4    dC   
h<@DD$t***N
 
 	

 ::c??1DCJ
:wws<44555 $$$$T**__U## 	*#zz%00  !122 +s;K7L7Lq7PTU7U7U" " " ""1c*:&;&;Q??" " " , ? ?E7>>>> n55
wwz***__S!! 	*!ZZ__N  00 *Q#n:M:M5R5R5R5RQR5R5R5R5R5R #N < < <3MBBB=)))
	*,0	1  r   r5   c                 L    d| cxk     rdk     rn dS t          d| z            dS )zUnicode values should not be in the range D800 through DFFF because
    that is used for surrogate pairs in UTF-16

    :raises KeyError if unicode digit is invalid
    i  i   zHUnicode digit %d is invalid because it is in the range D800 through DFFFN)r"   )r5   s    r   r.   r.   G   sQ     }$$$$u$$$$$$35BC
 
 	
 %$r   c            
       J   e Zd ZU i Zeeef         ed<   i Zeeef         ed<   i Z	eeef         ed<   i Z
eeef         ed<   eD ]/\  ZZZZZ ee          Zereee<   ereee<   eree	e<   eree
e<   0eee	e
dZe	 ddedeee                  d	eeef         fd
            ZdS )
EncodingDBstd2unicodemac2unicodewin2unicodepdf2unicode)StandardEncodingMacRomanEncodingWinAnsiEncodingPDFDocEncodingNr   diffr   c                    | j                             || j                  }|r|                                }d}|D ]}t	          |t
                    r|}t	          |t                    rv	 t          t          t          |j
                            ||<   nE# t          t          f$ r1}t                              t          |                     Y d }~nd }~ww xY w|dz  }|S )Nr   r   )	encodingsgetr9   copyr    r   r
   r(   r   r!   r   r"   
ValueErrorlogdebug)clsr   rA   cid2unicodecidxes          r   get_encodingzEncodingDB.get_encodingl   s     m''co>> 	%**,,KC  a%% CC9-- *+7S!&8I8I+J+JC(($j1 * * *		#a&&))))))))*1HCs   +*BC''CC)N)__name__
__module____qualname__r9   r   r   r!   __annotations__r:   r;   r<   r	   r   stdmacwinpdfr(   crC   classmethodr   r   objectrN    r   r   r8   r8   T   sT        "$Kc3h$$$"$Kc3h$$$"$Kc3h$$$"$Kc3h$$$&. 	! 	!"sCcL 	! K 	! K 	! K 	! K ('&%	 I ;? &x'78	c3h   [  r   r8   )loggingretypingr   r   r   r   	glyphlistr   	latin_encr	   psparserr
   compiler+   	getLoggerrO   rG   r!   r(   r   r.   r8   rZ   r   r   <module>rc      s    				 1 1 1 1 1 1 1 1 1 1 1 1 ( ( ( ( ( (            bj))g!!6s 6s 6 6 6 6r

s 

t 

 

 

 

) ) ) ) ) ) ) ) ) )r   