a
    Mˆc?†  ã                   @   sV  d Z ddlmZmZmZmZ ddlmZmZm	Z	m
Z
 ddlmZ ddlZddlZe e¡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gd Zdeg edd…< deg edd…< deg edd…< deg edd…< eed< eeƒdk�sJ ‚edd… Zeed< eed< edd… Zeed < eed!< eed< g d"¢Zd#d$„ e eƒD ƒZ!d%Z"d&d'„ Z#g d(¢Z$d)d*„ Z%e%d+ƒZ&e%d,ƒZ'e%d-ƒZ(ej)fd.d/„Z*ed!ƒed0ƒ Z+d1d2„ Z,G d3d4„ d4e-ƒZ.G d5d6„ d6e/ƒZ0g d7¢Z1G d8d9„ d9e0ƒZ2G d:d;„ d;e2ƒZ3G d<d=„ d=e3ƒZ4G d>d?„ d?e/ƒZ5G d@dA„ dAe5ƒZ6G dBdC„ dCe/ƒZ7dDdE„ Z8dS )FzwpsCharStrings.py -- module implementing various kinds of CharStrings:
CFF dictionary data and Type1/Type2 CharStrings.
é    )ÚfixedToFloatÚfloatToFixedÚfloatToFixedToStrÚstrToFixedToFloat)ÚbytechrÚbyteordÚ	bytesjoinÚstrjoin)Ú	BoundsPenNc                 C   sb   |dkr"|t || ƒf}|d }n|}z| j| }W n tyN   d |f Y S 0 |  |¡}||fS )Né   é   )r   Ú	operatorsÚKeyErrorÚhandle_operator)ÚselfÚb0ÚdataÚindexÚopÚoperatorÚvalue© r   ú_/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/fontTools/misc/psCharStrings.pyÚread_operator   s    

r   c                 C   s   |d |fS )Né‹   r   ©r   r   r   r   r   r   r   Ú	read_byte   s    r   c                 C   s(   t || ƒ}|d d | d |d fS )Né÷   é   él   r   ©r   ©r   r   r   r   Úb1r   r   r   Úread_smallInt1!   s    r#   c                 C   s*   t || ƒ}|d  d | d |d fS )Néû   r   r   r   r    r!   r   r   r   Úread_smallInt2%   s    r%   c                 C   s&   t  d|||d … ¡\}||d fS )Nú>hé   ©ÚstructÚunpack©r   r   r   r   r   r   r   r   Úread_shortInt)   s    r,   c                 C   s&   t  d|||d … ¡\}||d fS )Nú>lé   r(   r+   r   r   r   Úread_longInt-   s    r/   c                 C   s.   t  d|||d … ¡\}t|dd�|d fS )Nr-   r.   é   ©ZprecisionBits)r)   r*   r   r+   r   r   r   Úread_fixed16161   s    r2   c                 C   s   t sJ ‚t|fS ©N)ÚNotImplementedErrorÚNotImplementedr   r   r   r   Úread_reserved5   s    r6   c                 C   sf   d}t || ƒ}|d }|d@ d? }|d@ }|dkr6qZ|t|  }|dkrLqZ|t|  }qt|ƒ|fS )NÚ r   éð   r.   é   )r   ÚrealNibblesÚfloat)r   r   r   r   ÚnumberÚbZnibble0Znibble1r   r   r   Úread_realNumber9   s    r>   r   é    é×   r   r.   r$   éÿ   é   é   é   )Ú0Ú1Ú2Ú3Ú4Ú5Ú6Ú7Ú8Ú9Ú.ÚEúE-Nú-c                 C   s   i | ]\}}||“qS r   r   )Ú.0ÚiÚvr   r   r   Ú
<dictcomp>]   ó    rV   éÁ   c                 C   s~   i }i }| D ]h}t |ƒdkr.|d ||d < n|dd … ||d < t|d tƒrb|d ||d < q|d f||d < q||fS )Nr'   r   r   )ÚlenÚ
isinstanceÚtuple)ZoperatorListÚoperZopcÚitemr   r   r   ÚbuildOperatorDictb   s    r^   )4©r   Zhstem©é   Zvstem©r.   Zvmoveto©é   Zrlineto©é   Zhlineto©é   Zvlineto©é   Z	rrcurveto©é
   Zcallsubr©é   Úreturn©é   Úendchar)r9   Úvsindex)r0   Úblend)é   Zhstemhm)é   Úhintmask)é   Úcntrmask©é   Zrmoveto©é   Zhmoveto)é   Zvstemhm)é   Z
rcurveline)é   Z
rlinecurve)é   Z	vvcurveto)é   Z	hhcurveto)rC   Z	callgsubr©rD   Z	vhcurveto©é   Z	hvcurveto)©r   r   Úignore))r   ra   Úand))r   r.   Úor))r   rd   Únot))r   rj   Ústore))r   é	   Úabs))r   rl   Úadd))r   rn   Úsub©)r   r   Údiv))r   é   Úload))r   rq   Úneg))r   r9   Úeq))r   ru   Zdrop))r   rx   Úput))r   r{   Úget))r   r}   Zifelse))r   r~   Úrandom))r   r   Úmul))r   r�   Úsqrt))r   r‚   Údup))r   rB   Úexch))r   rC   r   ))r   rD   Zroll))r   é"   Zhflex))r   é#   Zflex))r   é$   Zhflex1))r   é%   Zflex1c                 C   sN   | dkrt dƒ}n"| dkr$t dƒ}n| dks0J ‚d }|t tjtjfdd„}|S )NÚcffrC   Út1rA   Út2c                 S   s  d|   krdkr&n n|| d ƒ}nÞd|   kr:dkrdn n&| d } || d? d ƒ|| d@ ƒ }n d	|   krxd
kr¤n n(|  d } || d? d ƒ|| d@ ƒ }n`|d u röd|   krÀdkrØn n|dƒ|d| ƒ }nt  d¡ |dƒ|d| ƒ }n||d| ƒ }|S )Ni•ÿÿÿék   r   r   ék  rj   r   rA   i•ûÿÿi”ÿÿÿr$   i €ÿÿiÿ  rB   r&   zk4-byte T2 number got passed to the IntType handler. This should happen only when reading in old XML files.
r-   )ÚlogÚwarning)r   Ú
fourByteOpr   Úpackr*   Úcoder   r   r   Ú	encodeInt´   s    


z getIntEncoder.<locals>.encodeInt)r   r)   r©   r*   )Úformatr¨   r«   r   r   r   ÚgetIntEncoder«   s    

ÿ
r­   r¡   r¢   r£   c                 C   s6   t | dd�}|d@ dkr$t|d? ƒS d|d|ƒ S dS )zFor T2 onlyr0   r1   iÿÿ  r   ó   ÿr-   N)r   ÚencodeIntT2)Úfr©   r   r   r   r   ÚencodeFixedÚ   s    r±   r9   c                 C   s"  | dkrt S d|  }|d d… dkr2|dd … }n |d d… dkrRd|dd …  }g }|rÀ|d	 }|dd … }|d
kr°|d d… }|dkrœ|dd … }d}n|dkr°|dd … }| t| ¡ qV| d¡ t|ƒd rà| d¡ tdƒ}td	t|ƒdƒD ]$}|t|| d> ||d  B ƒ }qø|S )Ng        z%.8Gr'   z0.r   ra   z-0.rR   r   rP   rQ   ú+r9   rD   r.   )ÚrealZeroBytesÚappendÚrealNibblesDictrY   r   Úrange)r°   ÚsZnibblesÚcÚc2ÚdrT   r   r   r   ÚencodeFloatå   s4    

"r»   c                   @   s   e Zd ZdS )ÚCharStringCompileErrorN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r¼     rW   r¼   c                   @   sZ  e Zd ZdTd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d„ Zdd„ Zd d!„ ZeZd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Z d<d=„ Z!d>d?„ Z"d@dA„ Z#dBdC„ Z$dDdE„ Z%dFdG„ Z&dHdI„ Z'dJdK„ Z(dLdM„ Z)dNdO„ Z*dPdQ„ Z+dRdS„ Z,dS )UÚSimpleT2DecompilerNc                 C   s8   || _ t|ƒ| _|| _t|ƒ| _|| _|| _|  ¡  d S r3   )Ú
localSubrsÚcalcSubrBiasÚ	localBiasÚglobalSubrsÚ
globalBiasÚprivateÚblenderÚreset)r   rÁ   rÄ   rÆ   rÇ   r   r   r   Ú__init__
  s    

zSimpleT2Decompiler.__init__c                 C   s(   g | _ g | _d| _d| _d| _d| _d S ©Nr   )ÚcallingStackÚoperandStackÚ	hintCountÚhintMaskBytesÚ
numRegionsÚvsIndex©r   r   r   r   rÈ     s    zSimpleT2Decompiler.resetc                 C   sÆ   | j  |¡ | ¡ }|r$g }|j}ndd„ }| jj}d}| |¡\}}}|d u rRq¬||ƒ |r¢d| }	t| |	d ƒ}
|
d ur˜|
|ƒ}|r |\}}||ƒ qª|  ¡  q8||ƒ q8|rº| |¡ | j d= d S )Nc                 S   s   d S r3   r   )Úxr   r   r   Ú<lambda>"  rW   z,SimpleT2Decompiler.execute.<locals>.<lambda>r   Zop_éÿÿÿÿ)rË   r´   ÚneedsDecompilationrÌ   ÚgetTokenÚgetattrÚpopallÚ
setProgram)r   Ú
charStringrÕ   ÚprogramZpushToProgramZpushToStackr   ÚtokenÚ
isOperatorZhandlerNameÚhandlerÚrvrÎ   r   r   r   Úexecute  s2    



zSimpleT2Decompiler.executec                 C   s   | j d }| j d= |S ©NrÔ   ©rÌ   ©r   r   r   r   r   Úpop:  s    
zSimpleT2Decompiler.popc                 C   s    | j d d … }g | j d d …< |S r3   râ   ©r   Ústackr   r   r   rØ   ?  s    zSimpleT2Decompiler.popallc                 C   s   | j  |¡ d S r3   )rÌ   r´   rã   r   r   r   ÚpushD  s    zSimpleT2Decompiler.pushc                 C   s
   | j rd S r3   râ   ©r   r   r   r   r   Ú	op_returnG  s    zSimpleT2Decompiler.op_returnc                 C   s   d S r3   r   rè   r   r   r   Ú
op_endcharK  s    zSimpleT2Decompiler.op_endcharc                 C   s   d S r3   r   rè   r   r   r   Ú	op_ignoreN  s    zSimpleT2Decompiler.op_ignorec                 C   s&   |   ¡ }| j|| j  }|  |¡ d S r3   )rä   rÁ   rÃ   rà   ©r   r   Ú	subrIndexZsubrr   r   r   Úop_callsubrQ  s    zSimpleT2Decompiler.op_callsubrc                 C   s&   |   ¡ }| j|| j  }|  |¡ d S r3   )rä   rÄ   rÅ   rà   rì   r   r   r   Úop_callgsubrV  s    zSimpleT2Decompiler.op_callgsubrc                 C   s   |   ¡  d S r3   ©Ú
countHintsrè   r   r   r   Úop_hstem[  s    zSimpleT2Decompiler.op_hstemc                 C   s   |   ¡  d S r3   rð   rè   r   r   r   Úop_vstem]  s    zSimpleT2Decompiler.op_vstemc                 C   s   |   ¡  d S r3   rð   rè   r   r   r   Ú
op_hstemhm_  s    zSimpleT2Decompiler.op_hstemhmc                 C   s   |   ¡  d S r3   rð   rè   r   r   r   Ú
op_vstemhma  s    zSimpleT2Decompiler.op_vstemhmc                 C   s>   | j s|  ¡  | jd d | _ | jd  || j ¡\}}||fS )Nrh   rj   rÔ   )rÎ   rñ   rÍ   rË   ÚgetBytes)r   r   rÎ   r   r   r   Úop_hintmaskd  s
    zSimpleT2Decompiler.op_hintmaskc                 C   s    |   ¡ }| jt|ƒd  | _d S ©Nr'   )rØ   rÍ   rY   ©r   Úargsr   r   r   rñ   m  s    zSimpleT2Decompiler.countHintsc                 C   s   t ‚d S r3   ©r4   rè   r   r   r   Úop_andr  s    zSimpleT2Decompiler.op_andc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_ort  s    zSimpleT2Decompiler.op_orc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_notv  s    zSimpleT2Decompiler.op_notc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_storex  s    zSimpleT2Decompiler.op_storec                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_absz  s    zSimpleT2Decompiler.op_absc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_add|  s    zSimpleT2Decompiler.op_addc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_sub~  s    zSimpleT2Decompiler.op_subc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_div€  s    zSimpleT2Decompiler.op_divc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_load‚  s    zSimpleT2Decompiler.op_loadc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_neg„  s    zSimpleT2Decompiler.op_negc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_eq†  s    zSimpleT2Decompiler.op_eqc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_dropˆ  s    zSimpleT2Decompiler.op_dropc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_putŠ  s    zSimpleT2Decompiler.op_putc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_getŒ  s    zSimpleT2Decompiler.op_getc                 C   s   t ‚d S r3   rû   rè   r   r   r   Ú	op_ifelseŽ  s    zSimpleT2Decompiler.op_ifelsec                 C   s   t ‚d S r3   rû   rè   r   r   r   Ú	op_random�  s    zSimpleT2Decompiler.op_randomc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_mul’  s    zSimpleT2Decompiler.op_mulc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_sqrt”  s    zSimpleT2Decompiler.op_sqrtc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_dup–  s    zSimpleT2Decompiler.op_dupc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_exch˜  s    zSimpleT2Decompiler.op_exchc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_indexš  s    zSimpleT2Decompiler.op_indexc                 C   s   t ‚d S r3   rû   rè   r   r   r   Úop_rollœ  s    zSimpleT2Decompiler.op_rollc           
      C   sÄ   | j dkr| j ¡ | _ |  ¡ }|| j d  }| jd u rJ| j||  d …= nvt| jƒ| }||  }}||k r²|| j  }| j||… }|  | j|¡}	| j|  |	7  < |}|d7 }qdg | j|d …< d S ©Nr   r   )rÏ   rÆ   ÚgetNumRegionsrä   rÇ   rÌ   rY   rÐ   )
r   r   Ú	numBlendsZnumOpsZargiZend_argsZtupleiZnext_tiZdeltasÚdeltar   r   r   Úop_blendŸ  s     



zSimpleT2Decompiler.op_blendc                 C   s    |   ¡ }|| _| j |¡| _d S r3   )rä   rÐ   rÆ   r  rÏ   )r   r   Úvir   r   r   Ú
op_vsindex²  s    zSimpleT2Decompiler.op_vsindex)NN)-r½   r¾   r¿   rÉ   rÈ   rà   rä   rØ   rç   ré   rê   rë   rî   rï   rò   ró   rô   rõ   r÷   Zop_cntrmaskrñ   rü   rý   rþ   rÿ   r   r  r  r  r  r  r  r  r  r	  r
  r  r  r  r  r  r  r  r  r  r   r   r   r   rÀ     sT   
	rÀ   )r_   r`   rb   rc   re   rg   ri   )rŒ   Z	closepathrk   rm   )r’   Zhsbwrp   rz   r|   rƒ   r„   )r†   Z
dotsection))r   r   Zvstem3))r   r'   Zhstem3))r   rf   Zseac))r   rh   Zsbwr�   ))r   r0   Zcallothersubr))r   é   rä   ))r   é!   Zsetcurrentpointc                   @   sP   e Zd Zddd„Zdd„ Zddd„Zd	d
„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚT2WidthExtractorNc                 C   s"   t  | ||||¡ || _|| _d S r3   )rÀ   rÉ   ÚnominalWidthXÚdefaultWidthX)r   rÁ   rÄ   r  r  rÆ   rÇ   r   r   r   rÉ   Ø  s    zT2WidthExtractor.__init__c                 C   s   t  | ¡ d| _d| _d S rÊ   )rÀ   rÈ   ÚgotWidthÚwidthrÑ   r   r   r   rÈ   Ý  s    
zT2WidthExtractor.resetr   c                 C   s`   |   ¡ }| js\|t|ƒd A rN| jd us0J dƒ‚| j|d  | _|dd … }n| j| _d| _|S )Nr'   z5CFF2 CharStrings must not have an initial width valuer   r   )rØ   r  rY   r  r  r  )r   ÚevenOddrú   r   r   r   ÚpopallWidthâ  s    zT2WidthExtractor.popallWidthc                 C   s    |   ¡ }| jt|ƒd  | _d S rø   )r!  rÍ   rY   rù   r   r   r   rñ   ï  s    zT2WidthExtractor.countHintsc                 C   s   |   ¡  d S r3   ©r!  rè   r   r   r   Ú
op_rmovetoó  s    zT2WidthExtractor.op_rmovetoc                 C   s   |   d¡ d S ©Nr   r"  rè   r   r   r   Ú
op_hmovetoö  s    zT2WidthExtractor.op_hmovetoc                 C   s   |   d¡ d S r$  r"  rè   r   r   r   Ú
op_vmovetoù  s    zT2WidthExtractor.op_vmovetoc                 C   s   |   ¡  d S r3   r"  rè   r   r   r   rê   ü  s    zT2WidthExtractor.op_endchar)NN)r   )r½   r¾   r¿   rÉ   rÈ   r!  rñ   r#  r%  r&  rê   r   r   r   r   r  Ö  s   

r  c                       s¶  e Zd Zdjdd„Zdd„ Z‡ f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 d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Z d>d?„ Z!d@dA„ Z"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHdI„ Z&dJdK„ Z'dLdM„ Z(dNdO„ Z)dPdQ„ Z*dRdS„ Z+dTdU„ Z,dVdW„ Z-dXdY„ Z.dZd[„ Z/d\d]„ Z0d^d_„ Z1d`da„ Z2dbdc„ Z3ddde„ Z4dfdg„ Z5dhdi„ Z6‡  Z7S )kÚT2OutlineExtractorNc              	   C   s&   t  | ||||||¡ || _d| _d S rÊ   )r  rÉ   ÚpenÚ	subrLevel)r   r(  rÁ   rÄ   r  r  rÆ   rÇ   r   r   r   rÉ     s
    ÿzT2OutlineExtractor.__init__c                 C   s    t  | ¡ d| _d| _d| _d S )N©r   r   r   )r  rÈ   ÚcurrentPointÚ	sawMoveTor)  rÑ   r   r   r   rÈ     s    
zT2OutlineExtractor.resetc                    s>   |  j d7  _ tƒ  |¡ |  j d8  _ | j dkr:|  ¡  d S ©Nr   r   )r)  Úsuperrà   ÚendPath)r   rÚ   ©Ú	__class__r   r   rà     s
    
zT2OutlineExtractor.executec                 C   s,   | j \}}||d  ||d  f}|| _ |S r  )r+  )r   ÚpointrÒ   Úyr   r   r   Ú
_nextPoint  s    
zT2OutlineExtractor._nextPointc                 C   s   | j  |  |¡¡ d| _d S r$  )r(  ZmoveTor4  r,  ©r   r2  r   r   r   ÚrMoveTo  s    zT2OutlineExtractor.rMoveToc                 C   s&   | j s|  d¡ | j |  |¡¡ d S ©Nr*  )r,  r6  r(  ZlineTor4  r5  r   r   r   ÚrLineTo  s    
zT2OutlineExtractor.rLineToc                 C   s6   | j s|  d¡ | j}| j ||ƒ||ƒ||ƒ¡ d S r7  )r,  r6  r4  r(  ZcurveTo)r   Zpt1Zpt2Zpt3Z	nextPointr   r   r   ÚrCurveTo$  s    
zT2OutlineExtractor.rCurveToc                 C   s   | j r| j ¡  d| _ d S rÊ   )r,  r(  Ú	closePathrÑ   r   r   r   r:  *  s    
zT2OutlineExtractor.closePathc                 C   s   | j r|  ¡  d S r3   )r,  r:  rÑ   r   r   r   r/  /  s    zT2OutlineExtractor.endPathc                 C   s   |   ¡  |  |  ¡ ¡ d S r3   ©r/  r6  r!  rè   r   r   r   r#  J  s    zT2OutlineExtractor.op_rmovetoc                 C   s$   |   ¡  |  |  d¡d df¡ d S r-  r;  rè   r   r   r   r%  M  s    zT2OutlineExtractor.op_hmovetoc                 C   s$   |   ¡  |  d|  d¡d f¡ d S r  r;  rè   r   r   r   r&  P  s    zT2OutlineExtractor.op_vmovetoc           
   	   C   sh   |   ¡  |  ¡ }|rdddlm} |\}}}}|| }| j |d¡ || }	| j |	dddd||f¡ d S )Nr   ©ÚStandardEncoding©r   r   r   r   r   r   r   )r/  r!  Ú$fontTools.encodings.StandardEncodingr=  r(  ÚaddComponent)
r   r   rú   r=  ÚadxÚadyÚbcharÚacharÚ	baseGlyphÚaccentGlyphr   r   r   rê   S  s    zT2OutlineExtractor.op_endcharc                 C   s<   |   ¡ }tdt|ƒdƒD ]}|||d … }|  |¡ qd S )Nr   r'   )rØ   r¶   rY   r8  )r   r   rú   rT   r2  r   r   r   Ú
op_rlinetoc  s    zT2OutlineExtractor.op_rlinetoc                 C   s   |   d¡ d S r$  ©ÚalternatingLinetorè   r   r   r   Ú
op_hlinetoi  s    zT2OutlineExtractor.op_hlinetoc                 C   s   |   d¡ d S rÊ   rH  rè   r   r   r   Ú
op_vlinetok  s    zT2OutlineExtractor.op_vlinetoc           
      C   sX   |   ¡ }tdt|ƒdƒD ]:}|||d … \}}}}}}	|  ||f||f||	f¡ qdS )z${dxa dya dxb dyb dxc dyc}+ rrcurvetor   rf   N)rØ   r¶   rY   r9  )
r   r   rú   rT   ÚdxaÚdyaÚdxbÚdybÚdxcÚdycr   r   r   Úop_rrcurvetoq  s    zT2OutlineExtractor.op_rrcurvetoc           
      C   sn   |   ¡ }tdt|ƒd dƒD ]:}|||d … \}}}}}}	|  ||f||f||	f¡ q|  |dd… ¡ dS )z-{dxa dya dxb dyb dxc dyc}+ dxd dyd rcurveliner   r'   rf   éþÿÿÿN)rØ   r¶   rY   r9  r8  )
r   r   rú   rT   rN  rO  rP  rQ  ÚdxdÚdydr   r   r   Úop_rcurvelinex  s
    z T2OutlineExtractor.op_rcurvelinec                 C   sv   |   ¡ }|dd… }tdt|ƒdƒD ]}|  |||d … ¡ q$|dd… \}}}}}	}
|  ||f||f|	|
f¡ dS )z-{dxa dya}+ dxb dyb dxc dyc dxd dyd rlinecurveNiúÿÿÿr   r'   )rØ   r¶   rY   r8  r9  )r   r   rú   ZlineArgsrT   rN  rO  rP  rQ  rT  rU  r   r   r   Úop_rlinecurve€  s    z T2OutlineExtractor.op_rlinecurvec           	      C   s~   |   ¡ }t|ƒd r*|d }|dd… }nd}tdt|ƒdƒD ]:}|||d … \}}}}|  ||f||fd|f¡ d}q>dS )z!dx1? {dya dxb dyb dyc}+ vvcurvetor'   r   r   Nr.   ©rØ   rY   r¶   r9  )	r   r   rú   Údx1rT   rM  rN  rO  rQ  r   r   r   Úop_vvcurveto‰  s    zT2OutlineExtractor.op_vvcurvetoc           	      C   s~   |   ¡ }t|ƒd r*|d }|dd… }nd}tdt|ƒdƒD ]:}|||d … \}}}}|  ||f||f|df¡ d}q>dS )z!dy1? {dxa dxb dyb dxc}+ hhcurvetor'   r   r   Nr.   rX  )	r   r   rú   Údy1rT   rL  rN  rO  rP  r   r   r   Úop_hhcurveto–  s    zT2OutlineExtractor.op_hhcurvetoc                 C   s*   |   ¡ }|r&|  |¡}|r|  |¡}qdS )z}dy1 dx2 dy2 dx3 {dxa dxb dyb dyc dyd dxe dye dxf}* dyf? vhcurveto (30)
		{dya dxb dyb dxc dxd dxe dye dyf}+ dxf? vhcurveto
		N)rØ   ÚvcurvetoÚhcurveto©r   r   rú   r   r   r   Úop_vhcurveto£  s
    
zT2OutlineExtractor.op_vhcurvetoc                 C   s*   |   ¡ }|r&|  |¡}|r|  |¡}qdS )zddx1 dx2 dy2 dy3 {dya dxb dyb dxc dxd dxe dye dyf}* dxf?
		{dxa dxb dyb dyc dyd dxe dye dxf}+ dyf?
		N)rØ   r^  r]  r_  r   r   r   Úop_hvcurveto­  s
    
zT2OutlineExtractor.op_hvcurvetoc                 C   sd   |   ¡ \}}}}}}}d }	 }
 }}| }|  ||	f||f||
f¡ |  ||f||f||f¡ d S rÊ   ©rØ   r9  )r   r   rY  Údx2Údy2Údx3Údx4Údx5Údx6r[  Údy3Údy4Údy6Údy5r   r   r   Úop_hflexº  s
    zT2OutlineExtractor.op_hflexc                 C   sZ   |   ¡ \}}}}}}}}	}
}}}}|  ||f||f||f¡ |  ||	f|
|f||f¡ d S r3   rb  )r   r   rY  r[  rc  rd  re  ri  rf  rj  rg  rl  rh  rk  Úfdr   r   r   Úop_flexÀ  s    "zT2OutlineExtractor.op_flexc              	   C   sp   |   ¡ \	}}}}}}}}	}
d }}|| | | |	  }|  ||f||f||f¡ |  ||f||	f|
|f¡ d S rÊ   rb  )r   r   rY  r[  rc  rd  re  rf  rg  rl  rh  ri  rj  rk  r   r   r   Ú	op_hflex1Ä  s
    zT2OutlineExtractor.op_hflex1c                 C   s¤   |   ¡ \}}}}}}}}	}
}}|| | | |
 }|| | |	 | }t|ƒt|ƒkrb|}| }n
| }|}|  ||f||f||f¡ |  ||	f|
|f||f¡ d S r3   )rØ   r�   r9  )r   r   rY  r[  rc  rd  re  ri  rf  rj  rg  rl  Zd6ZdxZdyrh  rk  r   r   r   Úop_flex1Ë  s    zT2OutlineExtractor.op_flex1c                 C   s   t ‚d S r3   rû   rè   r   r   r   rü   Ù  s    zT2OutlineExtractor.op_andc                 C   s   t ‚d S r3   rû   rè   r   r   r   rý   Û  s    zT2OutlineExtractor.op_orc                 C   s   t ‚d S r3   rû   rè   r   r   r   rþ   Ý  s    zT2OutlineExtractor.op_notc                 C   s   t ‚d S r3   rû   rè   r   r   r   rÿ   ß  s    zT2OutlineExtractor.op_storec                 C   s   t ‚d S r3   rû   rè   r   r   r   r   á  s    zT2OutlineExtractor.op_absc                 C   s   t ‚d S r3   rû   rè   r   r   r   r  ã  s    zT2OutlineExtractor.op_addc                 C   s   t ‚d S r3   rû   rè   r   r   r   r  å  s    zT2OutlineExtractor.op_subc                 C   sB   |   ¡ }|   ¡ }|| }|| }||kr4|  |¡ n
|  |¡ d S r3   )rä   rç   )r   r   Znum2Znum1Úd1Zd2r   r   r   r  ç  s    zT2OutlineExtractor.op_divc                 C   s   t ‚d S r3   rû   rè   r   r   r   r  ð  s    zT2OutlineExtractor.op_loadc                 C   s   t ‚d S r3   rû   rè   r   r   r   r  ò  s    zT2OutlineExtractor.op_negc                 C   s   t ‚d S r3   rû   rè   r   r   r   r  ô  s    zT2OutlineExtractor.op_eqc                 C   s   t ‚d S r3   rû   rè   r   r   r   r  ö  s    zT2OutlineExtractor.op_dropc                 C   s   t ‚d S r3   rû   rè   r   r   r   r  ø  s    zT2OutlineExtractor.op_putc                 C   s   t ‚d S r3   rû   rè   r   r   r   r	  ú  s    zT2OutlineExtractor.op_getc                 C   s   t ‚d S r3   rû   rè   r   r   r   r
  ü  s    zT2OutlineExtractor.op_ifelsec                 C   s   t ‚d S r3   rû   rè   r   r   r   r  þ  s    zT2OutlineExtractor.op_randomc                 C   s   t ‚d S r3   rû   rè   r   r   r   r     s    zT2OutlineExtractor.op_mulc                 C   s   t ‚d S r3   rû   rè   r   r   r   r    s    zT2OutlineExtractor.op_sqrtc                 C   s   t ‚d S r3   rû   rè   r   r   r   r    s    zT2OutlineExtractor.op_dupc                 C   s   t ‚d S r3   rû   rè   r   r   r   r    s    zT2OutlineExtractor.op_exchc                 C   s   t ‚d S r3   rû   rè   r   r   r   r    s    zT2OutlineExtractor.op_indexc                 C   s   t ‚d S r3   rû   rè   r   r   r   r  
  s    zT2OutlineExtractor.op_rollc                 C   s<   |   ¡ }|D ]*}|r|df}nd|f}|  |¡ | }qd S rÊ   )rØ   r8  )r   ZisHorizontalrú   Úargr2  r   r   r   rI    s    

z$T2OutlineExtractor.alternatingLinetoc                 C   s\   |d d… \}}}}|dd … }t |ƒdkr:|d }g }nd}|  d|f||f||f¡ |S ©Nr.   r   r   ©rY   r9  )r   rú   rM  rN  rO  rP  rQ  r   r   r   r]    s    zT2OutlineExtractor.vcurvetoc                 C   s\   |d d… \}}}}|dd … }t |ƒdkr:|d }g }nd}|  |df||f||f¡ |S rt  ru  )r   rú   rL  rN  rO  rQ  rP  r   r   r   r^  %  s    zT2OutlineExtractor.hcurveto)NN)8r½   r¾   r¿   rÉ   rÈ   rà   r4  r6  r8  r9  r:  r/  r#  r%  r&  rê   rG  rJ  rK  rR  rV  rW  rZ  r\  r`  ra  rm  ro  rp  rq  rü   rý   rþ   rÿ   r   r  r  r  r  r  r  r  r  r	  r
  r  r  r  r  r  r  r  rI  r]  r^  Ú__classcell__r   r   r0  r   r'     sh   
	
	
r'  c                   @   s¶   e Zd Zdd„ Zdd„ Zdd„ 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"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,S ).ÚT1OutlineExtractorc                 C   s   || _ || _|  ¡  d S r3   )r(  ÚsubrsrÈ   )r   r(  rx  r   r   r   rÉ   2  s    zT1OutlineExtractor.__init__c                 C   s    d| _ d| _d| _t | ¡ d S rÊ   )Úflexingr  Úsbxr'  rÈ   rÑ   r   r   r   rÈ   7  s    zT1OutlineExtractor.resetc                 C   s   | j r| j ¡  d| _ d S rÊ   )r,  r(  r/  rÑ   r   r   r   r/  =  s    
zT1OutlineExtractor.endPathr   c                 C   s   |   ¡ S r3   ©rØ   )r   r   r   r   r   r!  B  s    zT1OutlineExtractor.popallWidthc                 C   s$   | j }|d |d  |d< |d< d S )NrS  rÔ   râ   rå   r   r   r   rœ   E  s    zT1OutlineExtractor.exchc                 C   s$   | j r
d S |  ¡  |  |  ¡ ¡ d S r3   )ry  r/  r6  rØ   rè   r   r   r   r#  L  s    zT1OutlineExtractor.op_rmovetoc                 C   s6   | j r|  d¡ d S |  ¡  |  |  ¡ d df¡ d S rÊ   )ry  rç   r/  r6  rØ   rè   r   r   r   r%  Q  s
    
zT1OutlineExtractor.op_hmovetoc                 C   s>   | j r|  d¡ |  ¡  d S |  ¡  |  d|  ¡ d f¡ d S rÊ   )ry  rç   rœ   r/  r6  rØ   rè   r   r   r   r&  X  s    
zT1OutlineExtractor.op_vmovetoc                 C   s   |   ¡  d S r3   )r:  rè   r   r   r   Úop_closepath`  s    zT1OutlineExtractor.op_closepathc                 C   s   |   ¡ }|\}}||f| _d S r3   )rØ   r+  )r   r   rú   rÒ   r3  r   r   r   Úop_setcurrentpointb  s    z%T1OutlineExtractor.op_setcurrentpointc                 C   s   |   ¡  d S r3   )r/  rè   r   r   r   rê   g  s    zT1OutlineExtractor.op_endcharc                 C   s,   |   ¡ \}}|| _|| _|| jd f| _d S r$  )rØ   r  rz  r+  )r   r   rz  Zwxr   r   r   Úop_hsbwj  s    zT1OutlineExtractor.op_hsbwc                 C   s   |   ¡  d S r3   r{  rè   r   r   r   Úop_sbwo  s    zT1OutlineExtractor.op_sbwc                 C   s    |   ¡ }| j| }|  |¡ d S r3   )rä   rx  rà   rì   r   r   r   rî   s  s    
zT1OutlineExtractor.op_callsubrc                 C   sJ   |   ¡ }|   ¡ }|dkr0|dkr0|  ¡  d| _n|dkrF|dkrFd| _d S )Nr   ra   r   )rä   ÚdoFlexry  )r   r   rí   ZnArgsr   r   r   Úop_callothersubrw  s    z#T1OutlineExtractor.op_callothersubrc                 C   s   d S r3   r   rè   r   r   r   Úop_pop�  s    zT1OutlineExtractor.op_popc                 C   s4  |   ¡ }|   ¡ }|   ¡  |   ¡ }|   ¡ }|   ¡ }|   ¡ }|   ¡ }|   ¡ }|   ¡ }	|   ¡ }
|   ¡ }|   ¡ }|   ¡ }|   ¡ }|   ¡ }|   ¡ }|  || ¡ |  || ¡ |  |¡ |  |¡ |  |
¡ |  |	¡ |  d ¡ |  |¡ |  |¡ |  |¡ |  |¡ |  |¡ |  |¡ |  d ¡ |  |¡ |  |¡ d S r3   )rä   rç   rR  )r   ZfinalyZfinalxZp3yZp3xZbcp4yZbcp4xZbcp3yZbcp3xZp2yZp2xZbcp2yZbcp2xZbcp1yZbcp1xZrpyZrpxr   r   r   r€  „  sB    












zT1OutlineExtractor.doFlexc                 C   s   |   ¡  d S r3   r{  rè   r   r   r   Úop_dotsection®  s    z T1OutlineExtractor.op_dotsectionc                 C   s   |   ¡  d S r3   r{  rè   r   r   r   Ú	op_hstem3°  s    zT1OutlineExtractor.op_hstem3c           
   	   C   sh   ddl m} |  ¡ \}}}}}|| }| j |d¡ || }	|| j | }| j |	dddd||f¡ dS )zasb adx ady bchar achar seacr   r<  r>  r   N)r?  r=  rØ   r(  r@  rz  )
r   r   r=  ZasbrA  rB  rC  rD  rE  rF  r   r   r   Úop_seac²  s    zT1OutlineExtractor.op_seacc                 C   s   |   ¡  d S r3   r{  rè   r   r   r   Ú	op_vstem3»  s    zT1OutlineExtractor.op_vstem3N)r   )r½   r¾   r¿   rÉ   rÈ   r/  r!  rœ   r#  r%  r&  r|  r}  rê   r~  r  rî   r�  r‚  r€  rƒ  r„  r…  r†  r   r   r   r   rw  0  s*   

*	rw  c                   @   s¾   e Zd ZeZeeƒ\ZZe	Z
eZd%dd„Zd&dd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zd'dd„Zdd„ Zd(dd„Zdd„ Zdd„ Zdd„ Zeeefdd„Zdd„ Zdd „ Zd)d!d"„Zd#d$„ Z dS )*ÚT2CharStringNc                 C   s:   |d u rg }|| _ || _|| _|d ur*|ng | _d | _d S r3   )ÚbytecoderÛ   rÆ   rÄ   Ú_cur_vsindex)r   rˆ  rÛ   rÆ   rÄ   r   r   r   rÉ   Å  s    zT2CharString.__init__c                 C   sN   | j }|d usJ ‚|d ur"|| _n | jd u rBt|dƒr<|jnd| _| | j¡S )Nrs   r   )rÆ   r‰  Úhasattrrs   r  )r   rs   Úpdr   r   r   r  Î  s    
zT2CharString.getNumRegionsc                 C   s6   | j d u rd| jjt| ƒf S d| jjt| ƒf S d S )Nz<%s (source) at %x>z<%s (bytecode) at %x>)rˆ  r1  r½   ÚidrÑ   r   r   r   Ú__repr__×  s    
zT2CharString.__repr__c                 C   s   t S r3   )r¯   rÑ   r   r   r   r­   Ý  s    zT2CharString.getIntEncoderc                 C   s   t S r3   )r±   rÑ   r   r   r   ÚgetFixedEncoderà  s    zT2CharString.getFixedEncoderc                 C   s:   |   ¡ sd S t| jdg ƒ}|  || j| j¡}| | ¡ d S ©NZSubrs)rÕ   r×   rÆ   ÚdecompilerClassrÄ   rà   )r   rx  Z
decompilerr   r   r   Ú	decompileã  s
    zT2CharString.decompilec              	   C   sF   t | jdg ƒ}|  ||| j| jj| jj| j|¡}| | ¡ |j| _d S r�  )r×   rÆ   ÚoutlineExtractorrÄ   r  r  rà   r  )r   r(  rÇ   rx  Ú	extractorr   r   r   Údrawê  s    þ
zT2CharString.drawc                 C   s   t |ƒ}|  |¡ |jS r3   )r
   r”  Zbounds)r   ZglyphSetZ	boundsPenr   r   r   Ú
calcBoundsò  s    
zT2CharString.calcBoundsFc           
      C   s€  | j d urd S | j}| j}|r<|rV|d dv rV|d d… }n|rVt|d tƒsVtdƒ‚g }|  ¡ }|  ¡ }d}t|ƒ}||k �rD|| }	|d }t|	tƒröz| 	dd„ ||	 D ƒ¡ W n t
yÔ   td|	 ƒ‚Y n0 |	d	v rô| || ¡ |d }qvt|	tƒ�r| ||	ƒ¡ qvt|	tƒ�r.| ||	ƒ¡ qvdsvJ d
t|	ƒ ƒ‚qvzt|ƒ}W n  t�yp   t |¡ ‚ Y n0 |  |¡ d S )NrÔ   )ro   rr   z@T2CharString or Subr has items on the stack after last operator.r   r   c                 s   s   | ]}t |ƒV  qd S r3   )r   )rS   r=   r   r   r   Ú	<genexpr>  rW   z'T2CharString.compile.<locals>.<genexpr>zillegal operator: %s©rw   ry   zunsupported type: %s)rˆ  ÚopcodesrÛ   rZ   Ústrr¼   r­   rŽ  rY   Úextendr   r´   Úintr;   Útyper   Ú	TypeErrorr¦   ÚerrorÚsetBytecode)
r   ZisCFF2r˜  rÛ   rˆ  r«   r±   rT   ÚendrÜ   r   r   r   Úcompile÷  sL    
ÿ



zT2CharString.compilec                 C   s
   | j d uS r3   )rˆ  rÑ   r   r   r   rÕ   #  s    zT2CharString.needsDecompilationc                 C   s   || _ d | _d S r3   )rÛ   rˆ  )r   rÛ   r   r   r   rÙ   &  s    zT2CharString.setProgramc                 C   s   || _ d | _d S r3   )rˆ  rÛ   )r   rˆ  r   r   r   rŸ  *  s    zT2CharString.setBytecodec           	      C   sŠ   | j d urR||| j ƒkrdS || j | ƒ}|d }| j| }|| || j |ƒ\}}n$||| jƒkrddS | j| }|d }||tƒ}|||fS )N)Nr   r   r   )rˆ  ÚoperandEncodingrÛ   r™  )	r   r   rY   r   rZ   r   rÞ   rÜ   rÝ   r   r   r   rÖ   .  s    



zT2CharString.getTokenc                 C   sP   | j d ur&|| }| j ||… }|}n| j| }|d }t|ƒ|ksHJ ‚||fS r$  )rˆ  rÛ   rY   )r   r   ZnBytesZnewIndexÚbytesr   r   r   rö   ?  s    

zT2CharString.getBytesc                 C   s   |S r3   r   )r   r   r   r   r   r   J  s    zT2CharString.handle_operatorc                 C   s  ddl m} | jd ur$| | j¡ nêd}g }|  |¡\}}}|d u rFqô|rÈ|dv r |  |¡\}}}g }	|D ]}
|	 |t|
ƒdƒ¡ qjt|	ƒ}d |||g ¡}nd ||g ¡}| 	|¡ | 
¡  g }q,t|tƒràt|dd�}nt|ƒ}| |¡ q,|�rd |¡}| 	|¡ d S )Nr   )Ú
num2binaryr—  rj   ú r0   r1   )ÚfontTools.misc.textToolsr¤  rˆ  ZdumphexrÖ   r´   r   r	   ÚjoinÚwriteÚnewlinerZ   r;   r   r™  )r   Z	xmlWriterZttFontr¤  r   rú   rÜ   rÝ   ZhintMaskÚbitsÚbyteÚliner   r   r   ÚtoXMLM  s6    



zT2CharString.toXMLc                 C   s6  ddl m}m} | d¡r,|  ||ƒ¡ d S t|ƒ}| ¡ }g }t|ƒ}d}||k �r(|| }	|d }zt|	ƒ}	W n¨ t	�y   zt
|	dd�}	W nx t	�y
   | |	¡ |	dv �r|| }
d}tdt|
ƒd	ƒD ] }|t||
||d	 … ƒƒ }qÒ| |¡ |d }Y n0 | |	¡ Y qL0 | |	¡ qL|  |¡ d S )
Nr   )Ú
binary2numÚreadHexÚrawr   r0   r1   r—  rW   rj   )r¦  r®  r¯  r—   rŸ  r	   ÚsplitrY   r›  Ú
ValueErrorr   r´   r¶   r   rÙ   )r   ÚnameÚattrsÚcontentr®  r¯  rÛ   r   rT   rÜ   ÚmaskZ	maskBytesÚjr   r   r   ÚfromXMLr  s:    




zT2CharString.fromXML)NNNN)N)N)F)N)!r½   r¾   r¿   Út2OperandEncodingr¢  r^   Út2Operatorsr   r˜  rÀ   r�  r'  r’  rÉ   r  r�  r­   rŽ  r‘  r”  r•  r¡  rÕ   rÙ   rŸ  rY   r   rZ   rÖ   rö   r   r­  r¸  r   r   r   r   r‡  ¾  s,   
	
	

,ÿ

%r‡  c                       sN   e Zd ZeZeeƒ\ZZd‡ fdd„	Z	dd„ Z
dd„ Zdd	„ Zd
d„ Z‡  ZS )ÚT1CharStringNc                    s   t ƒ  ||¡ || _d S r3   )r.  rÉ   rx  )r   rˆ  rÛ   rx  r0  r   r   rÉ   ˜  s    zT1CharString.__init__c                 C   s   t S r3   )ÚencodeIntT1rÑ   r   r   r   r­   œ  s    zT1CharString.getIntEncoderc                 C   s   dd„ }d S )Nc                 S   s   t dƒ‚d S )Nz8Type 1 charstrings don't support floating point operands)r�  )r   r   r   r   r±      s    z1T1CharString.getFixedEncoder.<locals>.encodeFixedr   )r   r±   r   r   r   rŽ  Ÿ  s    zT1CharString.getFixedEncoderc                 C   sJ   | j d u rd S g }d}|  |¡\}}}|d u r0q<| |¡ q|  |¡ d S rÊ   )rˆ  rÖ   r´   rÙ   )r   rÛ   r   rÜ   rÝ   r   r   r   r‘  £  s    
zT1CharString.decompilec                 C   s"   t || jƒ}| | ¡ |j| _d S r3   )rw  rx  rà   r  )r   r(  r“  r   r   r   r”  ¯  s    
zT1CharString.draw)NNN)r½   r¾   r¿   Út1OperandEncodingr¢  r^   Út1Operatorsr   r˜  rÉ   r­   rŽ  r‘  r”  rv  r   r   r0  r   r»  “  s   r»  c                   @   sr   e Zd Z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S )ÚDictDecompilerNc                 C   s   g | _ || _i | _|| _d S r3   )ræ   ÚstringsÚdictÚparent)r   rÀ  rÂ  r   r   r   rÉ   ¸  s    zDictDecompiler.__init__c                 C   s   t | jƒdksJ dƒ‚| jS )Nr   znon-empty stack)rY   ræ   rÁ  rÑ   r   r   r   ÚgetDict¾  s    zDictDecompiler.getDictc                 C   sb   d}t |ƒ}| jj}||k r^t|| ƒ}|d }| j| }|| |||ƒ\}}|d ur||ƒ qd S r  )rY   ræ   r´   r   r¢  )r   r   r   ZlenDatarç   r   rÞ   r   r   r   r   r‘  Â  s    
zDictDecompiler.decompilec                 C   s   | j d }| j d= |S rá   ©ræ   rã   r   r   r   rä   Í  s    
zDictDecompiler.popc                 C   s   | j d d … }| j d d …= |S r3   rÄ  rù   r   r   r   rØ   Ò  s    zDictDecompiler.popallc                 C   s�   |\}}t |tƒrVd}tt|ƒd ddƒD ](}|| }t| d| ƒ}||ƒf| }q*nt| d| ƒ}||ƒ}|dkr‚| j |¡ n
|| j|< d S )Nr   r   rÔ   Zarg_rt   )rZ   r[   r¶   rY   r×   ræ   rš  rÁ  )r   r   ZargTyper   rT   rs  Z
arghandlerr   r   r   r   ×  s    
zDictDecompiler.handle_operatorc                 C   s*   t | jd tƒr|  | j¡}n|  ¡ }|S rÊ   )rZ   ræ   ÚlistÚarg_blend_numberrä   )r   r³  Úoutr   r   r   Ú
arg_numberç  s    zDictDecompiler.arg_numberc                 C   s4   g }|   ¡ }t|ƒ}| |¡ | d¡ |  ¡ }|S )Nrt   )rä   rY   r´   rØ   )r   r³  rÇ  Z	blendArgsÚ
numMastersÚdummyr   r   r   rÆ  î  s    

zDictDecompiler.arg_blend_numberc                 C   s   | j |  ¡  S r3   )rÀ  rä   ©r   r³  r   r   r   Úarg_SID÷  s    zDictDecompiler.arg_SIDc                 C   s   |   ¡ S r3   r{  rË  r   r   r   Ú	arg_arrayù  s    zDictDecompiler.arg_arrayc                 C   s°   | j  dd¡}| j |¡d }|  ¡ }|  ¡ }t|ƒ}||| ksFJ ‚dg| }|d }d}	d}
|	|k r¬||	 |
 }|}
||	|  }|g|||| …  }|||	< |	d7 }	q`|S )a³  
		There may be non-blend args at the top of the stack. We first calculate
		where the blend args start in the stack. These are the last
		numMasters*numBlends) +1 args.
		The blend args starts with numMasters relative coordinate values, the  BlueValues in the list from the default master font. This is followed by
		numBlends list of values. Each of  value in one of these lists is the
		Variable Font delta for the matching region.

		We re-arrange this to be a list of numMaster entries. Each entry starts with the corresponding default font relative value, and is followed by
		the delta values. We then convert the default values, the first item in each entry, to an absolute value.
		rs   r   r   N)rÁ  r—   rÂ  r  rä   rØ   rY   )r   r³  rs   rÉ  r  rú   ZnumArgsr   Z	numDeltasrT   ZprevValZnewValZmasterOffsetZ	blendListr   r   r   Úarg_blendListû  s$    

zDictDecompiler.arg_blendListc                 C   sH   |   ¡ }g }|r$t|d tƒr$|}n d}|D ]}|| }| |¡ q,|S rÊ   )rØ   rZ   rÅ  r´   )r   r³  Z	valueListrÇ  ÚcurrentrU   r   r   r   Ú	arg_delta  s    zDictDecompiler.arg_delta)N)r½   r¾   r¿   ÚcffDictOperandEncodingr¢  rÉ   rÃ  r‘  rä   rØ   r   rÈ  rÆ  rÌ  rÍ  rÎ  rÐ  r   r   r   r   r¿  ´  s   
	 r¿  c                 C   s,   t | ƒ}|dk rd}n|dk r$d}nd}|S )NiØ  r¤   il„  r¥   i €  )rY   )rx  ZnSubrsZbiasr   r   r   rÂ   )  s    rÂ   )9Ú__doc__ZfontTools.misc.fixedToolsr   r   r   r   r¦  r   r   r   r	   ZfontTools.pens.boundsPenr
   r)   ÚloggingÚ	getLoggerr½   r¦   r   r   r#   r%   r,   r/   r2   r6   r>   r½  rY   r¹  rÑ  r:   Ú	enumeraterµ   Z
maxOpStackr^   rº  r­   ZencodeIntCFFr¼  r¯   r©   r±   r³   r»   Ú	Exceptionr¼   ÚobjectrÀ   r¾  r  r'  rw  r‡  r»  r¿  rÂ   r   r   r   r   Ú<module>   sp   

:+	  1*  2  V!u