o
    ۩Zh                   	   @   s  d dl Z d dlZd dl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mZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl!m#Z# ddl!m$Z$ ddl!m%Z% ddl!m&Z& ddl!m'Z' ddl!m(Z(m)Z) ddl!m*Z* ddl+m,Z, ddl+m-Z- ddl+m.Z. ddl+m/Z/ ddl+m0Z0 ddl+m1Z1 ddl+m2Z2 ddl3m4Z4m5Z5 dd l3m6Z6 dd!l3m7Z7 dd"l3m8Z8 dd#l3m9Z9 erdd$l:m;Z; e <e=Z>d%e	e? d&ee@eAf fd'd(ZBd%e	e? d&ee@eeAe5f f fd)d*ZCG d+d, d,ZDG d-d. d.e1e@ ZEd/ZFd0d1d2ZGd3eHd&ee@eeeAe@f  f fd4d5ZIG d6d7 d7ZJG d8d9 d9ZKG d:d; d;e"ZLG d<d= d=eLZMe-d>ZNe-d?ZOeee@eAf eePeAf f ZQG d@dA dAZRG dBdC dCeRZSG dDdE dEeSZTG dFdG dGeTZUG dHdI dIeSZVG dJdK dKeRZWdLeeP d&dfdMdNZXe=dOkreXejY dS dS )P    N)BytesIO)AnyBinaryIODictIterableIteratorListMappingOptionalTupleUnioncastTYPE_CHECKING   )settings)CMap)CMapBase)CMapDB)
CMapParser)FileUnicodeMap)IdentityUnicodeMap)
UnicodeMap)
EncodingDB)name2unicodeFONT_METRICS)PDFException)	PDFStream)
dict_value)	int_value)
list_value)	num_value)resolve1resolve_all)stream_value)KWD)LIT)PSEOF)	PSKeyword)	PSLiteral)PSStackParser)literal_name)MatrixPoint)Rect)apply_matrix_norm)choplist)nunpack)PDFResourceManagerseqreturnc                 C   s   i }g }| D ]O}t |tr(|r'|d }t|D ]\}}||tt|| < qg }qt |ttfrU|| t|dkrU|\}}}ttt|tt|d D ]}|||< qLg }q|S )z;Build a mapping of character widths for horizontal writing.   r   )	
isinstancelist	enumerater   intfloatappendlenrange)r3   widthsrvchar1iwchar2 rF   G/var/www/html/lang_env/lib/python3.10/site-packages/pdfminer/pdffont.py
get_widths:   s&   



rH   c           
      C   s   i }g }| D ]_}t |tr2|r1|d }ttd|D ]\}\}}}|||ff|tt|| < qg }qt |ttfre|| t|dkre|\}}	}}}t	tt|tt|	d D ]
}|||ff||< qXg }q|S )z9Build a mapping of character widths for vertical writing.r5   r6      r   )
r7   r8   r9   r0   r   r:   r;   r<   r=   r>   )
r3   r?   r@   rA   rB   rC   rD   vxvyrE   rF   rF   rG   get_widths2O   s&   

rL   c                	   @   s:   e Zd Zededeeeef eeef f fddZ	dS )FontMetricsDBfontnamer4   c                 C   s   t | S Nr   )clsrN   rF   rF   rG   get_metricse   s   zFontMetricsDB.get_metricsN)
__name__
__module____qualname__classmethodstrr   r   objectr:   rQ   rF   rF   rF   rG   rM   d   s    0rM   c                   @   s   e Zd ZedZedZedZedZedZedZ	edZ
edZd	ed
dfddZd
eeef fddZdeded
dfddZdS )Type1FontHeaderParsers   begins   ends   defs   puts   dicts   arrays   readonlys   fordatar4   Nc                 C   s   t | | i | _d S rO   )r*   __init___cid2unicode)selfrY   rF   rF   rG   rZ   v   s   zType1FontHeaderParser.__init__c              
   C   sx   	 z|   \}}W n ty   Y | jS w zttt|| j|< W n ty: } ztt| W Y d}~nd}~ww q)a}  Parse the font encoding.

        The Type1 font encoding maps character codes to character names. These
        character names could either be standard Adobe glyph names, or
        character names associated with custom CharStrings for this font. A
        CharString is a sequence of operations that describe how the character
        should be drawn. Currently, this function returns '' (empty string)
        for character names that are associated with a CharStrings.

        Reference: Adobe Systems Incorporated, Adobe Type 1 Font Format

        :returns mapping of character identifiers (cid's) to unicode characters
        r   N)	Z
nextobjectr'   r   r   rV   r[   KeyErrorlogdebug)r\   cidnameerF   rF   rG   get_encoding{   s   z"Type1FontHeaderParser.get_encodingpostokenc                 C   sJ   || j u r#| d\\}}\}}t|tr#t|tr#| |t|f d S )N   )KEYWORD_PUTpopr7   r:   r)   Zadd_resultsr+   )r\   rd   re   _keyvaluerF   rF   rG   
do_keyword   s
   
z Type1FontHeaderParser.do_keyword)rR   rS   rT   r%   ZKEYWORD_BEGINZKEYWORD_ENDZKEYWORD_DEFrg   ZKEYWORD_DICTZKEYWORD_ARRAYZKEYWORD_READONLYZKEYWORD_FORr   rZ   r   r:   rV   rc   r(   rl   rF   rF   rF   rG   rX   k   s    rX   )0123456789.rb   ze-N-z
Identity-Hz
Identity-V)z	DLIdent-Hz	DLIdent-VrY   c                 C   s  i }t | }g }	 |d}|s	 |S t|}|dkr"|||< g }q|dkrZd}d}|rUt|d}|d? |d@ fD ]}	|	dkrDd}q;t|	 }
|
d usNJ ||
7 }q;|s,t|}nhd	|krg|d
krg|d }n[t|d}d|kr|dkr|d d> | d }nAd|kr|dkr|d d>  | d }n-t|d}d|kr|d8 }|dkr|d> |B }n|d> |d> B td|dd B }|| q	)Nr          T      F                   l                        >Hrf   r   )r   readordNIBBLESr;   structunpackr<   )rY   dfpstackcZb0sloopbnZnibblerk   b1b2rF   rF   rG   getdict   sR   
$

	
&
r   c                   @   sN   e Zd ZdZG dd dZdededdfdd	Zd
ede	ee
f fddZdS )CFFFont(  z.notdefspaceZexclamZquotedblZ
numbersigndollarpercentZ	ampersandZ
quoterightZ	parenleftZ
parenrightZasteriskpluscommahyphenZperiodslashzeroonetwothreefourfivesixseveneightninecolon	semicolonlessequalZgreaterquestionatABCDEFGHIJKLMNOPQRSTUVWXYZZbracketleftZ	backslashZbracketrightZasciicircumZ
underscoreZ	quoteleftar   r   r   rb   fghrC   jklmr   opqr@   r   turA   rD   xyzZ	braceleftbarZ
bracerightZ
asciitildeZ
exclamdowncentZsterlingfractionyenZflorinsectioncurrencyZquotesingleZquotedblleftZguillemotleftZguilsinglleftZguilsinglrightfiflZendashdaggerZ	daggerdblZperiodcenteredZ	paragraphZbulletZquotesinglbaseZquotedblbaseZquotedblrightZguillemotrightellipsisZperthousandZquestiondownZgraveacuteZ
circumflextildeZmacronZbreveZ	dotaccentZdieresisringZcedillaZhungarumlautZogonekZcaronZemdashZAEZordfeminineZLslashOslashZOEZordmasculineZaeZdotlessiZlslashoslashZoeZ
germandblsZonesuperiorZ
logicalnotmuZ	trademarkZEthZonehalfZ	plusminusZThornZ
onequarterdivideZ	brokenbarZdegreethornZthreequartersZtwosuperior
registeredminusethmultiplyZthreesuperior	copyrightAacuteZAcircumflexZ	AdieresisAgraveAringAtildeZCcedillaEacuteZEcircumflexZ	EdieresisEgraveIacuteZIcircumflexZ	IdieresisIgraveNtildeOacuteZOcircumflexZ	OdieresisOgraveOtildeScaronUacuteZUcircumflexZ	UdieresisUgraveYacuteZ	YdieresisZZcaronaacuteZacircumflexZ	adieresisagravearingatildeZccedillaeacuteZecircumflexZ	edieresisegraveiacuteZicircumflexZ	idieresisigraventildeoacuteZocircumflexZ	odieresisograveotildescaronuacuteZucircumflexZ	udieresisugraveyacuteZ	ydieresisZzcaronZexclamsmallZHungarumlautsmallZdollaroldstyleZdollarsuperiorZampersandsmallZ
AcutesmallZparenleftsuperiorZparenrightsuperiorZtwodotenleaderZonedotenleaderZzerooldstyleZoneoldstyleZtwooldstyleZthreeoldstyleZfouroldstyleZfiveoldstyleZsixoldstyleZsevenoldstyleZeightoldstyleZnineoldstyleZcommasuperiorZthreequartersemdashZperiodsuperiorZquestionsmallZ	asuperiorZ	bsuperiorZcentsuperiorZ	dsuperiorZ	esuperiorZ	isuperiorZ	lsuperiorZ	msuperiorZ	nsuperiorZ	osuperiorZ	rsuperiorZ	ssuperiorZ	tsuperiorffffifflZparenleftinferiorZparenrightinferiorZCircumflexsmallZhyphensuperiorZ
GravesmallZAsmallZBsmallZCsmallZDsmallZEsmallZFsmallZGsmallZHsmallZIsmallZJsmallZKsmallZLsmallZMsmallZNsmallZOsmallZPsmallZQsmallZRsmallZSsmallZTsmallZUsmallZVsmallZWsmallZXsmallZYsmallZZsmallZcolonmonetaryZ	onefittedZrupiahZ
TildesmallZexclamdownsmallZcentoldstyleZLslashsmallZScaronsmallZZcaronsmallZDieresissmallZ
BrevesmallZ
CaronsmallZDotaccentsmallZMacronsmallZ
figuredashZhypheninferiorZOgoneksmallZ	RingsmallZCedillasmallZquestiondownsmallZ	oneeighthZthreeeighthsZfiveeighthsZseveneighthsZonethirdZ	twothirdsZzerosuperiorZfoursuperiorZfivesuperiorZsixsuperiorZsevensuperiorZeightsuperiorZninesuperiorZzeroinferiorZoneinferiorZtwoinferiorZthreeinferiorZfourinferiorZfiveinferiorZsixinferiorZseveninferiorZeightinferiorZnineinferiorZcentinferiorZdollarinferiorZperiodinferiorZcommainferiorZAgravesmallZAacutesmallZAcircumflexsmallZAtildesmallZAdieresissmallZ
AringsmallZAEsmallZCcedillasmallZEgravesmallZEacutesmallZEcircumflexsmallZEdieresissmallZIgravesmallZIacutesmallZIcircumflexsmallZIdieresissmallZEthsmallZNtildesmallZOgravesmallZOacutesmallZOcircumflexsmallZOtildesmallZOdieresissmallZOEsmallZOslashsmallZUgravesmallZUacutesmallZUcircumflexsmallZUdieresissmallZYacutesmallZ
ThornsmallZYdieresissmallz001.000z001.001z001.002z001.003ZBlackZBoldZBookZLightZMediumZRegularZRomanZSemiboldc                   @   s^   e Zd ZdeddfddZdefddZdefdd	Zd
ede	fddZ
dee	 fddZdS )zCFFFont.INDEXr   r4   Nc                 C   sz   || _ g | _td| j d\}}t|d D ]}| jt| j | q| j  d | _	| j 
| j	| jd   d S )Nz>HBr6   r   r5   )r   offsetsr   r   r   r>   r<   r1   tellbaseseek)r\   r   countoffsizerC   rF   rF   rG   rZ   a  s   zCFFFont.INDEX.__init__c                 C   s   dt |  S )Nz<INDEX: size=%d>)r=   r\   rF   rF   rG   __repr__k     zCFFFont.INDEX.__repr__c                 C   s   t | jd S Nr   )r=   r  r  rF   rF   rG   __len__n  s   zCFFFont.INDEX.__len__rC   c                 C   s8   | j | j| j|   | j | j|d  | j|  S r"  )r   r  r  r  r   )r\   rC   rF   rF   rG   __getitem__q  s    zCFFFont.INDEX.__getitem__c                    s   t  fddtt D S )Nc                 3   s    | ]} | V  qd S rO   rF   ).0rC   r  rF   rG   	<genexpr>v  s    z)CFFFont.INDEX.__iter__.<locals>.<genexpr>)iterr>   r=   r  rF   r  rG   __iter__u  s   zCFFFont.INDEX.__iter__)rR   rS   rT   r   rZ   rV   r   r:   r#  bytesr$  r   r(  rF   rF   rF   rG   INDEX`  s    
r*  ra   r   r4   Nc              
   C   sL  || _ || _td| jd\}}}}| j|d  | | j| _| | j| _| | j| _| | j| _	t
| jd | _| jddg\}| jddg\}| jddg\}	| jtt|	 | | j| _t| j| _i | _i | _| jtt| | jd}
|
dkrtd	| jd\}ttd	| | j|D ]\}}|| j|< || j|< qnE|
d
krtd	| jd\}d}t|D ](}td| jd\}}t||| d D ]}|| j|< || j|< |d7 }qqntd|
 i | _i | _| jtt| | jd}
|
dkrK| jd }ttttdf tdd|  | jd| D ]\}}|d7 }| |}|| j|< || j|< q0d S |
d
krtd	| jd\}d}t|D ]/}td| jd\}}t||| d D ]}| |}|| j|< || j|< |d7 }qxqad S |
dkrJ td|
ftd|
 )NZBBBBr|   r   r}   r      r       r      BBrf   zunsupported encoding format: %r.>r      F	Unhandledzunsupported charset format: %r)ra   r   r   r   r   r*  
name_indexZ
dict_indexstring_indexZ
subr_indexr   Ztop_dictgetr  r   r:   Z
charstringr=   ZnglyphsZcode2gidZgid2coder9   r>   
ValueErrorZname2gidZgid2namer   getstrrV   )r\   ra   r   Z_majorZ_minorZhdrsizer  Zcharset_posZencoding_posZcharstring_posformatr   codegidrC   firstZnleftsidZsidnamerF   rF   rG   rZ   x  s   $





,







zCFFFont.__init__r;  c                 C   s,   |t | jk r| j| S | j|t | j  S rO   )r=   STANDARD_STRINGSr3  )r\   r;  rF   rF   rG   r6    s   
zCFFFont.getstr)rR   rS   rT   r<  r*  rV   r   rZ   r:   r   r)  r6  rF   rF   rF   rG   r      s       Or   c                   @   s@   e Zd ZG dd deZdededdfddZdefd	d
Z	dS )TrueTypeFontc                   @      e Zd ZdS )zTrueTypeFont.CMapNotFoundNrR   rS   rT   rF   rF   rF   rG   CMapNotFound      r@  ra   r   r4   Nc              	   C   s   || _ || _i | _|d| _z=ttttttf t	d|d\}}}}t
|D ]}ttttttf t	d|d\}}	}
}|
|f| j|< q*W d S  tjyW   Y d S w )Nr|   >HHHHr   z>4sLLLr   )ra   r   tablesr   Zfonttyper   r   r:   r   r   r>   r)  error)r\   ra   r   Zntables_1_2_3ri   Z
name_bytesZtsumoffsetlengthrF   rF   rG   rZ     s&   
zTrueTypeFont.__init__c           +      C   s>  d| j vrtj| j d \}}| j}|| ttttf t	d|
d\}}g }t|D ]}|tttttf t	d|
d q/i }|D ]\}	}
}|	dks]|	dkr\|
dv s]qJ|||  tttttf t	d	|
d
\}}}|dkr|ttttdf t	d|
d qJ|dkr2tttdf t	d|
d}dgd }t|D ]
\}}|||d < qt|d d }g }t|D ](}ttttttf t	d|
d\}}}}|||||| d | f q|D ]<\}}}}}|sq||| d>  }|| t|D ] }ttt t	d|
dd }|r(||7 }|||| < qqqJ|dkrttttttf t	d|
d\}}}}|d }tttdf t	d| |
d| } |
d tttdf t	d| |
d| }!tttdf t	d| |
d| }"| }tttdf t	d| |
d| }#t| |!|"|#D ]I\}$}%}&}'|'r|||'  t|%|$d D ]}ttt t	d|
dd }(|(|& d@ ||< qȐqt|%|$d D ]}||& d@ ||< qqqJJ td|f|s
tjt })| D ]\}*}|)||* q|)S )Ns   cmapz>HHr|   z>HHLr   r   r6   )r   
   z>HHH   .z>256Br   rf   z>256Hi   i    r   z>HHhHr   rB  z>%dHz>%dhi  Fr1  )rC  r=  r@  r   r  r   r   r:   r   r   r   r>   r<   updater9   maxr  ziprV   r   itemsZadd_cid2unichr)+r\   Zbase_offsetrI  r   versionZ
nsubtablesZ	subtablesrC   Zchar2gidZplatform_idZencoding_idZ	st_offsetZfmttypeZfmtlenZfmtlangZsubheaderkeysZ
firstbytesr   ZnhdrshdrsZ	firstcodeZentcountdeltarH  rd   r:  r   r9  ZsegcountrE  rF  rG  ZecsZscsZiddsZidrsecscZiddidrr   unicode_mapcharrF   rF   rG   create_unicode_map  s   

$ 


"
 






 
zTrueTypeFont.create_unicode_map)
rR   rS   rT   	Exceptionr@  rV   r   rZ   r   rX  rF   rF   rF   rG   r=    s    r=  c                   @   r>  )PDFFontErrorNr?  rF   rF   rF   rG   rZ  H  rA  rZ  c                   @   r>  )PDFUnicodeNotDefinedNr?  rF   rF   rF   rG   r[  L  rA  r[  ZStandardEncodingZType1Cc                	   @   s
  e Zd Z	d#deeef dedee ddfddZ	defdd	Z
defd
dZdefddZdedee fddZdefddZdefddZdefddZdefddZdedefddZdedeeeee ef f fddZdedefdd Zdedefd!d"ZdS )$PDFFontN
descriptorr?   default_widthr4   c                 C   s  || _ t|| _t|dd| _t| jtrt| j| _t	|dd| _
t|dd| _t|dd| _t|dd| _|d u rOt|dd| _n|| _t| j| _t|d	d| _tttt|d
d| _d | _| _| jdkr| j | _d S )NZFontNameunknownFlagsr   AscentDescentZItalicAngleZMissingWidthZLeadingFontBBox)r   r   r   r   gMbP?)r]  r#   r?   r"   r4  rN   r7   r)   r+   r   flagsr!   ascentdescentZitalic_angler^  leadingr   r.   r    bboxhscalevscale)r\   r]  r?   r^  rF   rF   rG   rZ   Y  s*   


zPDFFont.__init__c                 C      dS )Nz	<PDFFont>rF   r  rF   rF   rG   r   {     zPDFFont.__repr__c                 C   rk  NFrF   r  rF   rF   rG   is_vertical~  rl  zPDFFont.is_verticalc                 C   rk  rm  rF   r  rF   rF   rG   is_multibyte  rl  zPDFFont.is_multibyter)  c                 C   s   t |S rO   )	bytearrayr\   r)  rF   rF   rG   decode  s   zPDFFont.decodec                 C      | j | j S )z.Ascent above the baseline, in text space units)re  rj  r  rF   rF   rG   
get_ascent     zPDFFont.get_ascentc                 C   rs  )z@Descent below the baseline, in text space units; always negative)rf  rj  r  rF   rF   rG   get_descent  ru  zPDFFont.get_descentc                 C   s.   | j d | j d  }|dkr| j }|| j S )Nrf   r   )rh  r^  ri  )r\   rD   rF   rF   rG   	get_width  s   
zPDFFont.get_widthc                 C   s2   | j d | j d  }|dkr| j| j }|| j S )Nr6   r   r   )rh  re  rf  rj  )r\   r   rF   rF   rG   
get_height  s   
zPDFFont.get_heightr`   c                 C   s   zt tttf | j| | j W S  tyB   t tttf | j}z|| | | j W  Y S  tt	fyA   | j
| j  Y  Y S w w rO   )r   r   r:   r;   r?   ri  r]   rV   	to_unichrr[  r^  )r\   r`   Z
str_widthsrF   rF   rG   
char_width  s    zPDFFont.char_widthc                 C   rk  )DReturns an integer for horizontal fonts, a tuple for vertical fonts.r   rF   r\   r`   rF   rF   rG   	char_disp  s   zPDFFont.char_dispr   c                    s   t  fdd |D S )Nc                 3   s    | ]}  |V  qd S rO   )rz  )r%  r`   r  rF   rG   r&    s    z'PDFFont.string_width.<locals>.<genexpr>)sumrr  )r\   r   rF   r  rG   string_width  s   zPDFFont.string_widthc                 C   s   t rO   )NotImplementedErrorr|  rF   rF   rG   ry    rl  zPDFFont.to_unichrrO   )rR   rS   rT   r	   rV   r   FontWidthDictr
   r;   rZ   r   boolrn  ro  r)  r   r:   rr  rt  rv  rw  rx  rz  r   r   r}  r  ry  rF   rF   rF   rG   r\  X  s.    

"&r\  c                   @   sH   e Zd Zdeeef dedeeef ddfddZdedefd	d
Z	dS )PDFSimpleFontr]  r?   specr4   Nc                 C   s   d|v rt |d }nt}t|tr*t|dt}t|dg }t||| _	ntt|| _	d | _
d|v rOt|d }t | _
t| j
t|   t| || d S )NEncodingZBaseEncodingZDifferences	ToUnicode)r"   LITERAL_STANDARD_ENCODINGr7   dictr+   r4  r    r   rc   cid2unicoderV  r$   r   r   r   get_datarunr\  rZ   )r\   r]  r?   r  encodingra   diffstrmrF   rF   rG   rZ     s   	
zPDFSimpleFont.__init__r`   c                 C   sN   | j rz| j |W S  ty   Y nw z| j| W S  ty&   td |w rO   )rV  
get_unichrr]   r  r[  r|  rF   rF   rG   ry    s   
zPDFSimpleFont.to_unichr)
rR   rS   rT   r	   rV   r   r  rZ   r:   ry  rF   rF   rF   rG   r    s    


r  c                   @   8   e Zd Zdddeeef ddfddZdefdd	ZdS )
PDFType1Fontrsrcmgrr2   r  r4   Nc           
   	      s*  z	t |d | _W n ty   tjrtdd| _Y nw zt| j\}}tt	t
tf |}W n/ ty_   t|di }t|dd t|ddgd } fd	d
t|D }Y nw t| ||| d|vrd|v rt|d| _t| jd }| j d | }tt|}	|	 | _d S )NBaseFontBaseFont is missingr_  FontDescriptor	FirstCharr   Widthsr   c                       i | ]	\}}|  |qS rF   rF   r%  rC   rD   Z	firstcharrF   rG   
<dictcomp>      z)PDFType1Font.__init__.<locals>.<dictcomp>r  ZFontFileZLength1)r+   basefontr]   r   STRICTrZ  rM   rQ   r   r   rV   r;   r   r4  r   r    r9   r  rZ   r$   fontfiler  rX   r   rc   r  )
r\   r  r  r]  Z
int_widthsr?   
width_listZlength1rY   parserrF   r  rG   rZ     s0   

zPDFType1Font.__init__c                 C   
   d| j  S )Nz<PDFType1Font: basefont=%r>r  r  rF   rF   rG   r        
zPDFType1Font.__repr__rR   rS   rT   r	   rV   r   rZ   r   rF   rF   rF   rG   r    s    r  c                   @   s   e Zd ZdefddZdS )PDFTrueTypeFontr4   c                 C   r  )Nz<PDFTrueTypeFont: basefont=%r>r  r  rF   rF   rG   r     r  zPDFTrueTypeFont.__repr__N)rR   rS   rT   rV   r   rF   rF   rF   rG   r    s    r  c                   @   r  )
PDFType3Fontr  r2   r  r4   Nc                    s   t |dd t|ddgd } fddt|D }d|v r)t|d }ndd|d d	}t| ||| ttt	t|d
| _
| j\}| _}| _t| j
d\| _| _d S )Nr  r   r  r   c                    r  rF   rF   r  r  rF   rG   r    r  z)PDFType3Font.__init__.<locals>.<dictcomp>r  rc  )ra  rb  rc  Z
FontMatrix)r   r   )r   r4  r    r9   r   r  rZ   r   r,   tuplematrixrh  rf  re  r/   ri  rj  )r\   r  r  r  r?   r]  ri   rF   r  rG   rZ     s   zPDFType3Font.__init__c                 C   rk  )Nz<PDFType3Font>rF   r  rF   rF   rG   r     rl  zPDFType3Font.__repr__r  rF   rF   rF   rG   r     s    r  c                	   @   s
  e Zd ZU eeeee ef f ed< ej	fddde
eef deddfdd	Zde
eef dedefd
dZede
eef dedefddZdefddZdefddZdefddZdedee fddZdedeeeee ef f fddZdedefddZdS )
PDFCIDFontdefault_dispr  r2   r  strictr4   Nc                 C   s  z	t |d | _W n ty   |rtdd| _Y nw t|di | _t| jddd}t| jddd}d		||| _
| ||| _zt|d
 }W n tyd   |r`tdi }Y nw d }d|v r~t|d| _t| jt| j }d | _d|v rt|d trt|d }t | _t| jt|   nOt |d }	t |d }
d|v sd|	v sd|
v rt | _n2| j
dv r|rz| | _W n# tjy   Y nw nzt| j
| j | _W n
 tjy   Y nw | j | _| jr-tt |dg }dd |! D | _"t|dddg\}}d |f| _#dd |! D }|}ni | _"d| _#t$t |dg }|dd}t%j&| |||d d S )Nr  r  r_  ZCIDSystemInfoZRegistrys   unknownlatin1ZOrderingz{}-{}r  zFontDescriptor is missingZ	FontFile2r  r  ZIdentity)zAdobe-Identityz	Adobe-UCSZW2c                 S   s"   i | ]\}\}\}}|||fqS rF   rF   )r%  r`   ri   rJ   rK   rF   rF   rG   r  X  s   " z'PDFCIDFont.__init__.<locals>.<dictcomp>ZDW2ip  ic                 S   s   i | ]	\}\}}||qS rF   rF   )r%  r`   rD   ri   rF   rF   rG   r  [  r  r   r   ZDWi  )r^  )'r+   r  r]   rZ  r   r4  Zcidsysteminfor"   rr  r7  	cidcodingget_cmap_from_speccmapr$   r  r=  r   r  rV  r7   r   r   r   r  r   rX  r@  r   Zget_unicode_maprn  verticalrL   r    rO  dispsr  rH   r\  rZ   )r\   r  r  r  Zcid_registryZcid_orderingr]  Zttfr  	cmap_namer  Zwidths2rK   rD   r?   r^  rF   rF   rG   rZ     s   



zPDFCIDFont.__init__c              
   C   sR   |  ||}zt|W S  tjy( } z|rt|t W  Y d}~S d}~ww )an  Get cmap from font specification

        For certain PDFs, Encoding Type isn't mentioned as an attribute of
        Encoding but as an attribute of CMapName, where CMapName is an
        attribute of spec['Encoding'].
        The horizontal/vertical modes are mentioned with different name
        such as 'DLIdent-H/V','OneByteIdentityH/V','Identity-H/V'.
        N)_get_cmap_namer   Zget_cmapr@  rZ  r   )r\   r  r  r  rb   rF   rF   rG   r  f  s   	zPDFCIDFont.get_cmap_from_specc                 C   s   d}z| d }t |drt| d }nt|d }W n ty)   |r'tdY nw t|tu rFtt|}d|v r@|dj}n|rFtdt	||S )z%Get cmap name from font specificationr_  r  ra   ZCMapNamezEncoding is unspecifiedz!CMapName unspecified for encoding)
hasattrr+   r]   rZ  typer   r   r4  ra   IDENTITY_ENCODER)r  r  r  Zspec_encodingZcmap_name_streamrF   rF   rG   r  x  s&   

zPDFCIDFont._get_cmap_namec                 C   s   d | j| jS )Nz+<PDFCIDFont: basefont={!r}, cidcoding={!r}>)r7  r  r  r  rF   rF   rG   r     s   zPDFCIDFont.__repr__c                 C   s   | j S rO   )r  r  rF   rF   rG   rn    s   zPDFCIDFont.is_verticalc                 C   rk  )NTrF   r  rF   rF   rG   ro    rl  zPDFCIDFont.is_multibyter)  c                 C   s   | j |S rO   )r  rr  rq  rF   rF   rG   rr    r!  zPDFCIDFont.decoder`   c                 C   s   | j || jS )r{  )r  r4  r  r|  rF   rF   rG   r}    s   zPDFCIDFont.char_dispc                 C   s8   z| j st|| j |W S  ty   t| j|w rO   )rV  r]   r  r[  r  r|  rF   rF   rG   ry    s   zPDFCIDFont.to_unichr)rR   rS   rT   r   r;   r   r
   __annotations__r   r  r	   rV   r   r  rZ   r   r  staticmethodr  r   rn  ro  r)  r   r:   rr  r}  ry  rF   rF   rF   rG   r    s*   
 

O &r  argvc                 C   sP   ddl m} |dt | dd  D ]}t|d}t||}t| |  qd S )Nr   )warnzThe function main() from pdffont.py will be removed in 2023. It was probably introduced for testing purposes a long time ago, and no longer relevant. Feel free to create a GitHub issue if you disagree.r   rb)warningsr  DeprecationWarningopenr   printclose)r  r  fnamer   ZfontrF   rF   rG   main  s   


r  __main__)Zloggingr   sysior   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r{   r   Zcmapdbr   r   r   r   r   r   r   Z
encodingdbr   r   Zfontmetricsr   Zpdftypesr   r   r   r   r    r!   r"   r#   r$   Zpsparserr%   r&   r'   r(   r)   r*   r+   utilsr,   r-   r.   r/   r0   r1   Z	pdfinterpr2   	getLoggerrR   r^   rW   r:   r;   rH   rL   rM   rX   r   r  r)  r   r   r=  rZ  r[  r  ZLITERAL_TYPE1CrV   r  r\  r  r  r  r  r  r  r  rF   rF   rF   rG   <module>   s    8
&1&.   ~yZ(! 
