a
    èÝEb”>  ã                   @   sn  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 G dd	„ d	ejƒZee d
¡ƒdd„ ƒZd)dd„Zee d
¡ƒdd„ ƒZee d
¡ƒdd„ ƒZeejƒdd„ ƒZeejƒdd„ ƒZG dd„ dejƒZG dd„ dejƒZee d
¡ƒdd„ ƒZdd„ Ze	d ed!�ee d
¡ƒd"d#„ ƒƒZee d
¡ƒd$d%„ ƒZ ee d
¡ƒd&d'„ ƒZ!d(S )*é    )ÚpsCharStrings)ÚttLib)ÚNullPen)ÚotRound)ÚdeprecateFunction)ÚVarStoreInstancer)Ú_add_methodÚ
_uniq_sortc                   @   s   e Zd Zdd„ Zdd„ ZdS )Ú_ClosureGlyphsT2Decompilerc                 C   s   t j | ||¡ || _d S ©N)r   ÚSimpleT2DecompilerÚ__init__Ú
components)Úselfr   Ú
localSubrsÚglobalSubrs© r   úT/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/fontTools/subset/cff.pyr      s
    þz#_ClosureGlyphsT2Decompiler.__init__c           
      C   s`   |   ¡ }t|ƒdkr\ddlm} |dd … \}}}}|| }|| }	| j |¡ | j |	¡ d S )Né   r   )ÚStandardEncodingéüÿÿÿ)ZpopallÚlenZ$fontTools.encodings.StandardEncodingr   r   Úadd)
r   ÚindexÚargsr   ZadxZadyZbcharZacharZ	baseGlyphZaccentGlyphr   r   r   Ú
op_endchar   s    z%_ClosureGlyphsT2Decompiler.op_endcharN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r
   
   s   r
   zCFF c                 C   sž   | j }t|ƒdksJ ‚|| ¡ d  }|j}|j}|rštƒ }|D ]<}||vrNq@|| }t|jdg ƒ}	t||	|j	ƒ}
|
 
|¡ q@||j8 }|j |¡ |}q2d S )Né   r   ÚSubrs)Úcffr   ÚkeysÚCharStringsÚglyphsÚsetÚgetattrÚprivater
   r   ÚexecuteÚupdate)r   Úsr!   ÚfontZglyphSetZ	decomposer   ÚgÚglÚsubrsÚ
decompilerr   r   r   Úclosure_glyphs   s"    
r0   Fc           
      C   sš   | j  |¡\}}|s|r.| |r$g ndg¡ nht| dƒrP| jd urP| j| j}n| j}|j}|j}tƒ }	| 	|	¡ |j
|krŽ|j
| dg|_ndg|_d S )NÚendcharÚFDArray)r#   ÚgetItemAndSelectorZ
setProgramÚhasattrr2   ÚPrivateÚdefaultWidthXÚnominalWidthXr   ZdrawÚwidthÚprogram)
r+   Z	glyphNameÚisCFF2ÚignoreWidthÚcZfdSelectIndexr'   ZdfltWdXZnmnlWdXÚpenr   r   r   Ú_empty_charstring4   s    

r>   c                 C   sp   | j }|jd d… |_|jrP|jsP|jdk}| ¡ D ]}|| }t|d|d� q4| ¡ D ]}|| }d|_qXdS )Nr   z.notdef)r:   r   T)r!   Z	fontNamesZnotdef_glyphZnotdef_outlineÚmajorr"   r>   ÚEncoding)r   r+   Úoptionsr!   r:   Úfontnamer   r   r   Úprune_pre_subsetG   s    
rC   c                    sj  | j }| ¡ D �]T}|| }|j}|j |j¡‰|jD ]}|ˆvrDq6| |¡\}}q6|jrø‡fdd„t	|jƒD ƒ}	|j
‰ ‡ fdd„|	D ƒˆ _ˆ `ˆ `t|dƒr¾|j‰dˆ_‡fdd„|	D ƒˆ_i }
t	|	ƒD ]$\}}|j| }||jv rÊ||
|< qÊ|
|_n‡fdd„|j ¡ D ƒ|_‡fd	d„|jD ƒ|_t|jƒ|_|jjr|jd
k}|jD ]}t|||dd� �qLqdS )Nc                    s   g | ]\}}|ˆ v r|‘qS r   r   )Ú.0Úir,   ©r$   r   r   Ú
<listcomp>j   ó    z!subset_glyphs.<locals>.<listcomp>c                    s   g | ]}ˆ j | ‘qS r   ©Úitems©rD   rE   )Úcsir   r   rG   l   rH   ÚFDSelecté   c                    s   g | ]}ˆ j | ‘qS r   )ÚgidArrayrK   )Úselr   r   rG   y   rH   c                    s   i | ]\}}|ˆ v r||“qS r   r   )rD   r,   ÚvrF   r   r   Ú
<dictcomp>�   s   þz!subset_glyphs.<locals>.<dictcomp>c                    s   g | ]}|ˆ v r|‘qS r   r   )rD   r,   rF   r   r   rG   „   rH   r   T)r:   r;   )r!   r"   r#   r$   ÚunionZglyphs_emptiedÚcharsetr3   ZcharStringsAreIndexedÚ	enumerateZcharStringsIndexrJ   ÚfileÚoffsetsr4   rM   ÚformatrO   ZcharStringsr   Z	numGlyphsrA   Zretain_gidsr?   r>   )r   r*   r!   rB   r+   Úcsr,   r<   Ú_ÚindicesZnewCharStringsZ
indicesIdxZ
charsetIdxr:   r   )rL   r$   rP   r   Úsubset_glyphs[   sB    


	



ÿ

r\   c                 C   s´   | j }tdt|ƒƒD ]š}|| dkrdt||d  tƒs:J ‚|j ||d  |j ¡|j ||d < q|| dkrt||d  tƒs†J ‚|j ||d  |j ¡|j ||d < qd S )Nr   ZcallsubrZ	callgsubr)	r9   Úranger   Ú
isinstanceÚintÚ_usedr   Ú	_old_biasÚ	_new_bias)r   r.   ZgsubrsÚprE   r   r   r   Úsubset_subroutines�   s    *rd   c                 C   s,  | j }|jr0| j}t|jƒD ]}||d |…= q|jr¸|jrP|j|jd ksPJ ‚| j|jd … | _| jst| j d¡ t| dƒr¸| j| j	j
kr¸| j	j
d us J dƒ‚| j d| j| j	j ¡ |j�rd}| j}|t|ƒk �r|| dv �r
|d t|ƒksúJ ‚|||d …= qÊ|d7 }qÊt| jƒ�s$J ‚| ` d S )Né   r   r1   r8   z5CFF2 CharStrings must not have an initial width value)ZhintmaskZcntrmaskr   )Ú_hintsÚ	deletionsr9   ÚreversedÚhas_hintÚ	last_hintÚappendr4   r8   r'   r6   Úinsertr7   Úhas_hintmaskr   )r   Úhintsrc   ÚidxrE   r   r   r   Ú
drop_hints›   s2    

rp   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú_MarkingT2Decompilerc                 C   s:   t j | |||¡ ||fD ]}|rt|dƒstƒ |_qd S )Nr`   )r   r   r   r4   r%   r`   )r   r   r   r'   r.   r   r   r   r   Á   s    ýz_MarkingT2Decompiler.__init__c                 C   s,   | j j | jd | j ¡ tj | |¡ d S ©Néÿÿÿÿ)r   r`   r   ÚoperandStackÚ	localBiasr   r   Úop_callsubr©r   r   r   r   r   rv   Ê   s    z _MarkingT2Decompiler.op_callsubrc                 C   s,   | j j | jd | j ¡ tj | |¡ d S rr   )r   r`   r   rt   Ú
globalBiasr   r   Úop_callgsubrrw   r   r   r   ry   Î   s    z!_MarkingT2Decompiler.op_callgsubrN)r   r   r   r   rv   ry   r   r   r   r   rq   ¿   s   	rq   c                   @   s†   e Zd ZG dd„ deƒZddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú_DehintingT2Decompilerc                   @   s   e Zd Zdd„ ZdS )z_DehintingT2Decompiler.Hintsc                 C   s(   d| _ d| _d| _d| _d| _g | _d S )NFr   )ri   rj   Úlast_checkedÚstatusrm   rg   ©r   r   r   r   r   Õ   s    z%_DehintingT2Decompiler.Hints.__init__N)r   r   r   r   r   r   r   r   ÚHintsÔ   s   r~   Nc                 C   s$   || _ tj | ||||¡ || _d S r   )Ú_cssr   ÚT2WidthExtractorr   r'   )r   Úcssr   r   r7   r6   r'   r   r   r   r   í   s
    
ÿz_DehintingT2Decompiler.__init__c                 C   s¶   t |dƒr|jnd }|  ¡ |_tj | |¡ |j}|js>|jrJ| j 	|¡ |j
dkržt|jt|jƒd ƒD ]&}t|j| tƒrŠd|_
 q’qjd|_
qjt|jƒ|_|r²|j|jks²J ‚d S )Nrf   re   r   )r4   rf   r~   r   r€   r(   ri   rm   r   r   r|   r]   r{   r   r9   r^   ÚstrÚ__dict__)r   Z
charStringZ	old_hintsrn   rE   r   r   r   r(   ó   s    

z_DehintingT2Decompiler.executec                 C   s4   | j | jd | j  }tj | |¡ |  ||¡ d S rr   )r   rt   ru   r   r€   rv   ÚprocessSubr©r   r   Úsubrr   r   r   rv     s    z"_DehintingT2Decompiler.op_callsubrc                 C   s4   | j | jd | j  }tj | |¡ |  ||¡ d S rr   )r   rt   rx   r   r€   ry   r„   r…   r   r   r   ry     s    z#_DehintingT2Decompiler.op_callgsubrc                 C   s   t j | |¡ |  |¡ d S r   )r   r€   Úop_hstemÚprocessHintrw   r   r   r   r‡     s    z_DehintingT2Decompiler.op_hstemc                 C   s   t j | |¡ |  |¡ d S r   )r   r€   Úop_vstemrˆ   rw   r   r   r   r‰     s    z_DehintingT2Decompiler.op_vstemc                 C   s   t j | |¡ |  |¡ d S r   )r   r€   Ú
op_hstemhmrˆ   rw   r   r   r   rŠ     s    z!_DehintingT2Decompiler.op_hstemhmc                 C   s   t j | |¡ |  |¡ d S r   )r   r€   Ú
op_vstemhmrˆ   rw   r   r   r   r‹     s    z!_DehintingT2Decompiler.op_vstemhmc                 C   s   t j | |¡}|  |¡ |S r   )r   r€   Úop_hintmaskÚprocessHintmask©r   r   Úrvr   r   r   rŒ   !  s    
z"_DehintingT2Decompiler.op_hintmaskc                 C   s   t j | |¡}|  |¡ |S r   )r   r€   Úop_cntrmaskr�   rŽ   r   r   r   r�   %  s    
z"_DehintingT2Decompiler.op_cntrmaskc                 C   st   | j d }|j}d|_|jdkrft|j|d ƒD ]}t|j| tƒr0d|_ qfq0d|_	|d |_
d|_|d |_d S )Nrs   Tre   r   r   )ÚcallingStackrf   rm   r|   r]   r{   r^   r9   r‚   ri   rj   )r   r   rY   rn   rE   r   r   r   r�   *  s    


z&_DehintingT2Decompiler.processHintmaskc                 C   s&   | j d }|j}d|_||_||_d S )Nrs   T)r‘   rf   ri   rj   r{   )r   r   rY   rn   r   r   r   rˆ   ;  s
    
z"_DehintingT2Decompiler.processHintc                 C   s´   | j d }|j}|j}|jdkrVt|j|d ƒD ]}t|j| tƒr0d|_ qPq0||_|jdkrŠ|jr d|_|jdkr~||_	q |d |_	n|jdkr |j
 |¡ t|j|jƒ|_d S )Nrs   re   r   Tr   )r‘   rf   r|   r]   r{   r^   r9   r‚   ri   rj   rg   rk   Úmax)r   r   r†   rY   rn   Z
subr_hintsrE   r   r   r   r„   B  s$    




z"_DehintingT2Decompiler.processSubr)N)r   r   r   Úobjectr~   r   r(   rv   ry   r‡   r‰   rŠ   r‹   rŒ   r�   r�   rˆ   r„   r   r   r   r   rz   Ò   s   
rz   c                    s¤   | j }| ¡ D ]d}|| }|j}t|dƒr|j}t|jƒ‰‡fdd„|jD ƒ|_|j‰ ‡ fdd„ˆD ƒˆ _ˆ `	ˆ `
q|jr‚| ¡  |js’|  ¡  n|js |  ¡  dS )NrM   c                    s   g | ]}ˆ   |¡‘qS r   )r   )rD   Úss)r[   r   r   rG   k  rH   z%prune_post_subset.<locals>.<listcomp>c                    s   g | ]}ˆ | ‘qS r   r   rK   )Úarrr   r   rG   m  rH   T)r!   r"   r#   r4   rM   r	   rO   r2   rJ   rV   rW   ÚdesubroutinizeZhintingÚremove_hintsÚremove_unused_subroutines)r   ZttfFontrA   r!   rB   r+   rY   rP   r   )r•   r[   r   Úprune_post_subset`  s$    



r™   c                 C   s*   t | dƒr&| js&d| jv r"| jd= | `d S )Nr    )r4   r    ZrawDict)Zprivate_dictr   r   r   Ú_delete_empty_subrs|  s    
rš   z)use 'CFFFontSet.desubroutinize()' instead)Úcategoryc                 C   s   | j  ¡  d S r   )r!   r–   r}   r   r   r   r–   ƒ  s    r–   c              	   C   s  | j }| ¡ D ]è}|| }|j}tƒ }|jD ]X}| |¡\}}| ¡  t|jdg ƒ}	t	||	|j
|jj|jj|jƒ}
|
 |¡ |
j|_q,|D ]}| ¡  qŠ~g }t|dƒrÀ| dd„ |jD ƒ¡ n| |j¡ |D ]$}dD ]}t||ƒrØt||d ƒ qØqÐq|  ¡  d S )Nr    r2   c                 s   s   | ]}|j V  qd S r   )r5   ©rD   Úfdr   r   r   Ú	<genexpr>°  rH   zremove_hints.<locals>.<genexpr>)Z
BlueValuesZ
OtherBluesZFamilyBluesZFamilyOtherBluesZ	BlueScaleZ	BlueShiftZBlueFuzzZ	StemSnapHZ	StemSnapVZStdHWZStdVWZ	ForceBoldZLanguageGroupZExpansionFactor)r!   r"   r#   r%   rT   r3   Z	decompiler&   r'   rz   r   r7   r6   r(   r8   rp   r4   Úextendr2   rk   r5   Úsetattrr˜   )r   r!   rB   r+   rY   r�   r,   r<   rZ   r.   r/   Z
charstringZ	all_privsZprivÚkr   r   r   r—   ‰  s8    

ý




r—   c                    s  | j }| ¡ D �]}|| }|j}|jD ]:}| |¡\}}t|jdg ƒ‰ tˆ |j|jƒ}| 	|¡ q(|j
g}	t|dƒrŽ|	 dd„ |jD ƒ¡ n"t|jdƒr°|jjr°|	 |jj¡ tˆ ƒ‰ |	D ]<‰ tˆ dƒsÒtƒ ˆ _tˆ jƒˆ _t ˆ ¡ˆ _t ˆ j¡ˆ _q¼|jD ]0}| |¡\}}t|jdg ƒ‰ | ˆ |j
¡ �q |	D ]’‰ ˆ |j
k�rpt|dƒ�sjt|jdƒ�rj|jj}
ng }
nˆ }
‡ fdd„ˆ jD ƒˆ _tˆ dƒ�ršˆ `tˆ d	ƒ�rªˆ `ˆ jD ]}| |
|j
¡ �q°�q6t|dƒ�rð|jD ]}t|jƒ �qÜn
t|jƒ |	D ]‰ ˆ `ˆ `ˆ `�qþqd S )
Nr    r2   c                 s   s*   | ]"}t |jd ƒr|jjr|jjV  qdS )r    N)r4   r5   r    rœ   r   r   r   rž   Ï  rH   z,remove_unused_subroutines.<locals>.<genexpr>r`   c                    s   g | ]}ˆ j | ‘qS r   rI   rK   ©r.   r   r   rG   í  rH   z-remove_unused_subroutines.<locals>.<listcomp>rV   rW   )r!   r"   r#   rT   r3   r&   r'   rq   r   r(   ZGlobalSubrsr4   rŸ   r2   r5   r    rk   r%   r`   r	   r   ZcalcSubrBiasra   rb   rd   rJ   rV   rW   rš   )r   r!   rB   r+   rY   r,   r<   rZ   r/   Z	all_subrsZlocal_subrsr†   r�   r   r¢   r   r˜   ¾  sX    







r˜   N)F)"ZfontTools.miscr   Z	fontToolsr   ZfontTools.pens.basePenr   ZfontTools.misc.roundToolsr   ZfontTools.misc.loggingToolsr   ZfontTools.varLib.varStorer   ZfontTools.subset.utilr   r	   r   r
   ZgetTableClassr0   r>   rC   r\   ZT2CharStringrd   rp   rq   r€   rz   r™   rš   ÚDeprecationWarningr–   r—   r˜   r   r   r   r   Ú<module>   s>   



4


# 


4