U
    Q»{j¨  ã                4   @   s  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t‚edd… Zeed< eed< edd… Zeed < eed!< eed< d"d#d$d%d&d'd(d)d*d+d,d-d.dd/gZ d0d1„ e!e ƒD ƒZ"d2Z#d3d4„ Z$d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhg4Z%didj„ Z&e&dkƒZ'e&dlƒZ(e&dmƒZ)ej*fdndo„Z+ed!ƒedpƒ Z,dqdr„ Z-G dsdt„ dte.ƒZ/G dudv„ dve0ƒZ1d5d6d7d8d9d:d;dwd<d=dxd>dDdEdLdMdydzd{d|d}dVd~dd€gZ2G d�d‚„ d‚e1ƒZ3G dƒd„„ d„e3ƒZ4G d…d†„ d†e4ƒZ5G d‡dˆ„ dˆe0ƒZ6G d‰dŠ„ dŠe6ƒZ7G d‹dŒ„ dŒe0ƒZ8d�dŽ„ Z9dS )�zwpsCharStrings.py -- module implementing various kinds of CharStrings:
CFF dictionary data and Type1/Type2 CharStrings.
é    )ÚfixedToFloatÚfloatToFixedÚfloatToFixedToStrÚstrToFixedToFloat)ÚbytechrÚbyteordÚ	bytesjoinÚstrjoin)Ú	BoundsPenNc                 C   sd   |dkr"|t || ƒf}|d }n|}z| j| }W n tk
rP   d |f Y S X |  |¡}||fS )Né   é   )r   Ú	operatorsÚKeyErrorÚhandle_operator)ÚselfÚb0ÚdataÚindexÚopÚoperatorÚvalue© r   ú[/var/www/html/bwave/python/venv/lib/python3.8/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_shortInt0   s    r,   c                 C   s&   t  d|||d … ¡\}||d fS )Nú>lé   r(   r+   r   r   r   Úread_longInt5   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_fixed1616:   s    r2   c                 C   s   t st‚t|fS ©N)ÚNotImplementedErrorÚAssertionErrorÚNotImplementedr   r   r   r   Úread_reserved?   s    r7   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_realNumberD   s    r?   r   é    é×   r   r.   r$   éÿ   é   é   é   Ú0Ú1Ú2Ú3Ú4Ú5Ú6Ú7Ú8Ú9Ú.ÚEúE-ú-c                 C   s   i | ]\}}||“qS r   r   )Ú.0ÚiÚvr   r   r   Ú
<dictcomp>w   s      rW   éÁ   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   ÚbuildOperatorDict|   s    r^   )r   Zhstem)é   Zvstem)r.   Zvmoveto)é   Zrlineto)é   Zhlineto)é   Zvlineto)é   Z	rrcurveto)é
   Zcallsubr)é   Úreturn)é   Úendchar)r:   Úvsindex)r0   Úblend)é   Zhstemhm)é   Úhintmask)é   Úcntrmask)é   Zrmoveto)é   Zhmoveto)é   Zvstemhm)é   Z
rcurveline)é   Z
rlinecurve)é   Z	vvcurveto)é   Z	hhcurveto)rD   Z	callgsubr)rE   Z	vhcurveto)é   Z	hvcurveto)©r   r   Úignore))r   r_   Úand))r   r.   Úor))r   r`   Únot))r   rc   Ústore))r   é	   Úabs))r   rd   Úadd))r   re   Úsub))r   r   Údiv))r   é   Úload))r   rg   Úneg))r   r:   Úeq))r   rk   Zdrop))r   rn   Úput))r   rp   Úget))r   rq   Zifelse))r   rr   Úrandom))r   rs   Úmul))r   ru   Úsqrt))r   rv   Údup))r   rC   Úexch))r   rD   r   ))r   rE   Zroll))r   é"   Zhflex))r   é#   Zflex))r   é$   Zhflex1))r   é%   Zflex1c                 C   sd   | dkrt dƒ}t dƒ}n.| dkr0d }t dƒ}n| dks<t‚t dƒ}d }|t tjtj|fdd„}|S )	NÚcffrC   rD   Út1rB   Ú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@ ƒ }nd|d k	rÔd|   krÀdkrÔn n||d| ƒ }n4|d krút  d¡ |dƒ|d| ƒ }n||d| ƒ }|S )Ni•ÿÿÿék   r   r   ék  rc   r   rB   i•ûÿÿi”ÿÿÿr$   i €ÿÿiÿ  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*   Ú	twoByteOpÚcoder   r   r   Ú	encodeIntÒ   s"    
 	ÿz getIntEncoder.<locals>.encodeInt)r   r5   r)   rš   r*   )Úformatr›   r™   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£   r:   c                 C   s4  | dkrt S d|  }|d d… dkr2|dd … }nØ|d d… dkrTd|dd …  }n¶| d	¡r‚| d
¡}d|t|ƒt|ƒ f }nˆ| d¡}| d¡}|dk�r
|dk�r
|d |… }||d |… }t||d d … ƒ}|t|ƒ }|dkrüd||f }nd|||f }| d¡�r>| dd¡\}	}d|	| d
¡t|ƒf }g }
|�rÎ|d }|dd … }|dk�r¼|d d… }|dk�rŽ|dd … }d}n|dk�r¤|dd … }| d
¡�r¼|dd … }|
 	t
| ¡ �qB|
 	d¡ t|
ƒd �rð|
 	d¡ tdƒ}tdt|
ƒdƒD ]&}|t|
| d> |
|d  B ƒ }�q|S )Ng        z%.8Gr'   z0.r   r_   z-0.rS   Z000rF   z%sE%drP   rQ   éÿÿÿÿz%s%s0z%s%sE%d)z.0z-.0z%s%sE-%dr   rR   ú+r:   rE   r.   )ÚrealZeroBytesÚendswithÚrstriprY   ÚfindÚintÚ
startswithÚsplitÚlstripÚappendÚrealNibblesDictr   Úrange)r¢   ÚsZsignificantDigitsÚdotIndexZeIndexZintegerPartZfractionalPartÚexponentZnewExponentÚsignZnibblesÚcÚc2ÚdrU   r   r   r   ÚencodeFloat  sX    








$r¸   c                   @   s   e Zd ZdS )ÚCharStringCompileErrorN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r¹   ?  s   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__D  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Å   M  s    zSimpleT2Decompiler.resetc                 C   sÆ   | j  |¡ | ¡ }|r$g }|j}ndd„ }| jj}d}| |¡\}}}|d krRq¬||ƒ |r¢d| }	t| |	d ƒ}
|
d k	r˜|
|ƒ}|r |\}}||ƒ qª|  ¡  q8||ƒ q8|rº| |¡ | j d= d S )Nc                 S   s   d S r3   r   )Úxr   r   r   Ú<lambda>\  ó    z,SimpleT2Decompiler.execute.<locals>.<lambda>r   Zop_r¤   )rÈ   r®   ÚneedsDecompilationrÉ   ÚgetTokenÚgetattrÚpopallÚ
setProgram)r   Ú
charStringrÒ   ÚprogramZpushToProgramZpushToStackr   ÚtokenÚ
isOperatorZhandlerNameÚhandlerÚrvrË   r   r   r   ÚexecuteU  s2    



zSimpleT2Decompiler.executec                 C   s   | j d }| j d= |S ©Nr¤   ©rÉ   ©r   r   r   r   r   Úpopt  s    
zSimpleT2Decompiler.popc                 C   s    | j d d … }g | j d d …< |S r3   rß   ©r   Ústackr   r   r   rÕ   y  s    zSimpleT2Decompiler.popallc                 C   s   | j  |¡ d S r3   )rÉ   r®   rà   r   r   r   Úpush~  s    zSimpleT2Decompiler.pushc                 C   s
   | j rd S r3   rß   ©r   r   r   r   r   Ú	op_return�  s    zSimpleT2Decompiler.op_returnc                 C   s   d S r3   r   rå   r   r   r   Ú
op_endchar…  s    zSimpleT2Decompiler.op_endcharc                 C   s   d S r3   r   rå   r   r   r   Ú	op_ignoreˆ  s    zSimpleT2Decompiler.op_ignorec                 C   s&   |   ¡ }| j|| j  }|  |¡ d S r3   )rá   r¾   rÀ   rÝ   ©r   r   Ú	subrIndexZsubrr   r   r   Úop_callsubr‹  s    zSimpleT2Decompiler.op_callsubrc                 C   s&   |   ¡ }| j|| j  }|  |¡ d S r3   )rá   rÁ   rÂ   rÝ   ré   r   r   r   Úop_callgsubr�  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_vstemhmž  s    zSimpleT2Decompiler.op_vstemhmc                 C   s>   | j s|  ¡  | jd d | _ | jd  || j ¡\}}||fS )Nrb   rc   r¤   )rË   rî   rÊ   rÈ   ÚgetBytes)r   r   rË   r   r   r   Úop_hintmask¡  s
    zSimpleT2Decompiler.op_hintmaskc                 C   s    |   ¡ }| jt|ƒd  | _d S ©Nr'   )rÕ   rÊ   rY   ©r   Úargsr   r   r   rî   ª  s    zSimpleT2Decompiler.countHintsc                 C   s   t ‚d S r3   ©r4   rå   r   r   r   Úop_and¯  s    zSimpleT2Decompiler.op_andc                 C   s   t ‚d S r3   rø   rå   r   r   r   Úop_or²  s    zSimpleT2Decompiler.op_orc                 C   s   t ‚d S r3   rø   rå   r   r   r   Úop_notµ  s    zSimpleT2Decompiler.op_notc                 C   s   t ‚d S r3   rø   rå   r   r   r   Úop_store¸  s    zSimpleT2Decompiler.op_storec                 C   s   t ‚d S r3   rø   rå   r   r   r   Úop_abs»  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 k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½   C  sT   
	r½   )r~   Z	closepath)rƒ   Zhsbw)rx   Z
dotsection))r   r   Zvstem3))r   r'   Zhstem3))r   ra   Zseac))r   rb   Zsbw))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Å   8  s    
zT2WidthExtractor.resetr   c                 C   s`   |   ¡ }| js\|t|ƒd A rN| jd k	s0tdƒ‚| j|d  | _|dd … }n| j| _d| _|S )Nr'   z5CFF2 CharStrings must not have an initial width valuer   r   )rÕ   r  rY   r  r5   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î   L  s    zT2WidthExtractor.countHintsc                 C   s   |   ¡  d S r3   ©r  rå   r   r   r   Ú
op_rmovetoP  s    zT2WidthExtractor.op_rmovetoc                 C   s   |   d¡ d S ©Nr   r  rå   r   r   r   Ú
op_hmovetoS  s    zT2WidthExtractor.op_hmovetoc                 C   s   |   d¡ d S r!  r  rå   r   r   r   Ú
op_vmovetoV  s    zT2WidthExtractor.op_vmovetoc                 C   s   |   ¡  d S r3   r  rå   r   r   r   rç   Y  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Å   t  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Ý   z  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moveTor1  r)  ©r   r/  r   r   r   ÚrMoveTo‡  s    zT2OutlineExtractor.rMoveToc                 C   s&   | j s|  d¡ | j |  |¡¡ d S ©Nr'  )r)  r3  r%  ZlineTor1  r2  r   r   r   ÚrLineTo‹  s    
zT2OutlineExtractor.rLineToc                 C   s6   | j s|  d¡ | j}| j ||ƒ||ƒ||ƒ¡ d S r4  )r)  r3  r1  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   r7  –  s    
zT2OutlineExtractor.closePathc                 C   s   | j r|  ¡  d S r3   )r)  r7  rÎ   r   r   r   r,  ›  s    zT2OutlineExtractor.endPathc                 C   s   |   ¡  |  |  ¡ ¡ d S r3   ©r,  r3  r  rå   r   r   r   r   ¶  s    zT2OutlineExtractor.op_rmovetoc                 C   s$   |   ¡  |  |  d¡d df¡ d S r*  r8  rå   r   r   r   r"  º  s    zT2OutlineExtractor.op_hmovetoc                 C   s$   |   ¡  |  d|  d¡d f¡ d S r  r8  rå   r   r   r   r#  ¾  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    zT2OutlineExtractor.op_endcharc                 C   s<   |   ¡ }tdt|ƒdƒD ]}|||d … }|  |¡ qd S )Nr   r'   )rÕ   r°   rY   r5  )r   r   r÷   rU   r/  r   r   r   Ú
op_rlinetoÓ  s    zT2OutlineExtractor.op_rlinetoc                 C   s   |   d¡ d S r!  ©ÚalternatingLinetorå   r   r   r   Ú
op_hlinetoÙ  s    zT2OutlineExtractor.op_hlinetoc                 C   s   |   d¡ d S rÇ   rE  rå   r   r   r   Ú
op_vlinetoÜ  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   ra   N)rÕ   r°   rY   r6  )
r   r   r÷   rU   ÚdxaÚdyaÚdxbÚdybÚdxcÚdycr   r   r   Úop_rrcurvetoâ  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'   ra   éþÿÿÿN)rÕ   r°   rY   r6  r5  )
r   r   r÷   rU   rK  rL  rM  rN  ÚdxdÚdydr   r   r   Úop_rcurvelineð  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   r5  r6  )r   r   r÷   ZlineArgsrU   rK  rL  rM  rN  rQ  rR  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°   r6  )	r   r   r÷   Údx1rU   rJ  rK  rL  rN  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.   rU  )	r   r   r÷   Údy1rU   rI  rK  rL  rM  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 )zpdx1 dx2 dy2 dy3 {dya dxb dyb dxc dxd dxe dye dyf}* dxf?
        {dxa dxb dyb dyc dyd dxe dye dxf}+ dyf?
        N)rÕ   r[  rZ  r\  r   r   r   Úop_hvcurveto%  s
    
zT2OutlineExtractor.op_hvcurvetoc                 C   sd   |   ¡ \}}}}}}}d }	 }
 }}| }|  ||	f||f||
f¡ |  ||f||f||f¡ d S rÇ   ©rÕ   r6  )r   r   rV  Údx2Údy2Údx3Údx4Údx5Údx6rX  Údy3Údy4Údy6Údy5r   r   r   Úop_hflex2  s
    zT2OutlineExtractor.op_hflexc                 C   sZ   |   ¡ \}}}}}}}}	}
}}}}|  ||f||f||f¡ |  ||	f|
|f||f¡ d S r3   r_  )r   r   rV  rX  r`  ra  rb  rf  rc  rg  rd  ri  re  rh  Úfdr   r   r   Úop_flex9  s    "zT2OutlineExtractor.op_flexc              	   C   sp   |   ¡ \	}}}}}}}}	}
d }}|| | | |	  }|  ||f||f||f¡ |  ||f||	f|
|f¡ d S rÇ   r_  )r   r   rV  rX  r`  ra  rb  rc  rd  ri  re  rf  rg  rh  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   r6  )r   r   rV  rX  r`  ra  rb  rf  rc  rg  rd  ri  Zd6ZdxZdyre  rh  r   r   r   Úop_flex1F  s    zT2OutlineExtractor.op_flex1c                 C   s   t ‚d S r3   rø   rå   r   r   r   rù   T  s    zT2OutlineExtractor.op_andc                 C   s   t ‚d S r3   rø   rå   r   r   r   rú   W  s    zT2OutlineExtractor.op_orc                 C   s   t ‚d S r3   rø   rå   r   r   r   rû   Z  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þ   c  s    zT2OutlineExtractor.op_addc                 C   s   t ‚d S r3   rø   rå   r   r   r   rÿ   f  s    zT2OutlineExtractor.op_subc                 C   sB   |   ¡ }|   ¡ }|| }|| }||kr4|  |¡ n
|  |¡ d S r3   )rá   rä   )r   r   Znum2Znum1Zd1Zd2r   r   r   r   i  s    zT2OutlineExtractor.op_divc                 C   s   t ‚d S r3   rø   rå   r   r   r   r  s  s    zT2OutlineExtractor.op_loadc                 C   s   t ‚d S r3   rø   rå   r   r   r   r  v  s    zT2OutlineExtractor.op_negc                 C   s   t ‚d S r3   rø   rå   r   r   r   r  y  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Õ   r5  )r   ZisHorizontalr÷   Úargr/  r   r   r   rF     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   r6  )r   r÷   rJ  rK  rL  rM  rN  r   r   r   rZ  ª  s    zT2OutlineExtractor.vcurvetoc                 C   s\   |d d… \}}}}|dd … }t |ƒdkr:|d }g }nd}|  |df||f||f¡ |S rp  rq  )r   r÷   rI  rK  rL  rN  rM  r   r   r   r[  µ  s    zT2OutlineExtractor.hcurveto)NN)8rº   r»   r¼   rÆ   rÅ   rÝ   r1  r3  r5  r6  r7  r,  r   r"  r#  rç   rD  rG  rH  rO  rS  rT  rW  rY  r]  r^  rj  rl  rm  rn  rù   rú   rû   rü   rý   rþ   rÿ   r   r  r  r  r  r  r  r  r  r	  r
  r  r  r  r  rF  rZ  r[  Ú__classcell__r   r   r-  r   r$  ]  sl     ø
	


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%  rt  r   r   r   rÆ   Â  s    zT1OutlineExtractor.__init__c                 C   s    d| _ d| _d| _t | ¡ d S rÇ   )Úflexingr  Úsbxr$  rÅ   rÎ   r   r   r   rÅ   Ç  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  Ò  s    zT1OutlineExtractor.popallWidthc                 C   s$   | j }|d |d  |d< |d< d S )NrP  r¤   rß   râ   r   r   r   r�   Õ  s    zT1OutlineExtractor.exchc                 C   s$   | j r
d S |  ¡  |  |  ¡ ¡ d S r3   )ru  r,  r3  rÕ   rå   r   r   r   r   Ü  s    zT1OutlineExtractor.op_rmovetoc                 C   s6   | j r|  d¡ d S |  ¡  |  |  ¡ d df¡ d S rÇ   )ru  rä   r,  r3  rÕ   rå   r   r   r   r"  â  s
    
zT1OutlineExtractor.op_hmovetoc                 C   s>   | j r|  d¡ |  ¡  d S |  ¡  |  d|  ¡ d f¡ d S rÇ   )ru  rä   r�   r,  r3  rÕ   rå   r   r   r   r#  ê  s    
zT1OutlineExtractor.op_vmovetoc                 C   s   |   ¡  d S r3   )r7  rå   r   r   r   Úop_closepathó  s    zT1OutlineExtractor.op_closepathc                 C   s   |   ¡ }|\}}||f| _d S r3   )rÕ   r(  )r   r   r÷   rÏ   r0  r   r   r   Úop_setcurrentpointö  s    z%T1OutlineExtractor.op_setcurrentpointc                 C   s   |   ¡  d S r3   )r,  rå   r   r   r   rç   û  s    zT1OutlineExtractor.op_endcharc                 C   s,   |   ¡ \}}|| _|| _|| jd f| _d S r!  )rÕ   r  rv  r(  )r   r   rv  Zwxr   r   r   Úop_hsbwþ  s    zT1OutlineExtractor.op_hsbwc                 C   s   |   ¡  d S r3   rw  rå   r   r   r   Úop_sbw  s    zT1OutlineExtractor.op_sbwc                 C   s    |   ¡ }| j| }|  |¡ d S r3   )rá   rt  rÝ   ré   r   r   r   rë     s    
zT1OutlineExtractor.op_callsubrc                 C   sJ   |   ¡ }|   ¡ }|dkr0|dkr0|  ¡  d| _n|dkrF|dkrFd| _d S )Nr   r_   r   )rá   ÚdoFlexru  )r   r   rê   ZnArgsr   r   r   Úop_callothersubr  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ä   rO  )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   rw  rå   r   r   r   Úop_dotsectionE  s    z T1OutlineExtractor.op_dotsectionc                 C   s   |   ¡  d S r3   rw  rå   r   r   r   Ú	op_hstem3H  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   r9  r;  r   N)r<  r:  rÕ   r%  r=  rv  )
r   r   r:  Zasbr>  r?  r@  rA  rB  rC  r   r   r   Úop_seacK  s    zT1OutlineExtractor.op_seacc                 C   s   |   ¡  d S r3   rw  rå   r   r   r   Ú	op_vstem3V  s    zT1OutlineExtractor.op_vstem3N)r   )rº   r»   r¼   rÆ   rÅ   r,  r  r�   r   r"  r#  rx  ry  rç   rz  r{  rë   r}  r~  r|  r  r€  r�  r‚  r   r   r   r   rs  Á  s*   
	*rs  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 krg }|| _ || _|| _|d k	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 k	st‚|d k	r"|| _n | jd krBt|dƒr<|jnd| _| | j¡S )Nri   r   )rÃ   r5   r…  Úhasattrri   r  )r   ri   Úpdr   r   r   r  i  s    
zT2CharString.getNumRegionsc                 C   s6   | j d k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„  r.  rº   ÚidrÎ   r   r   r   Ú__repr__r  s    
zT2CharString.__repr__c                 C   s   t S r3   )r¡   rÎ   r   r   r   rŸ   x  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   rt  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Ä   rt  Ú	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 k	rd S | j}| j}|r<|rV|d dkrV|d d… }n|rVt|d tƒsVtdƒ‚g }|  ¡ }|  ¡ }d}t|ƒ}||k �rF|| }	|d }t|	tƒrøz| 	dd„ ||	 D ƒ¡ W n  t
k
rÖ   td|	 ƒ‚Y nX |	d	krö| || ¡ |d }qvt|	tƒ�r| ||	ƒ¡ qvt|	tƒ�r0| ||	ƒ¡ qvdsvtd
t|	ƒ ƒ‚qvzt|ƒ}W n" tk
�rt   t |¡ ‚ Y nX |  |¡ d S )Nr¤   )rf   rh   z@T2CharString or Subr has items on the stack after last operator.r   r   c                 s   s   | ]}t |ƒV  qd S r3   )r   )rT   r>   r   r   r   Ú	<genexpr>±  s     z'T2CharString.compile.<locals>.<genexpr>zillegal operator: %s©rm   ro   zunsupported type: %s)r„  ÚopcodesrØ   rZ   Ústrr¹   rŸ   rŠ  rY   Úextendr   r®   rª   r<   r5   Útyper   Ú	TypeErrorr—   ÚerrorÚsetBytecode)
r   ZisCFF2r”  rØ   r„  r�   r£   rU   ÚendrÙ   r   r   r   Úcompile˜  sL    
ÿ



zT2CharString.compilec                 C   s
   | j d k	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 k	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 k	r&|| }| j ||… }|}n| j| }|d }t|ƒ|ksHt‚||fS r!  )r„  rØ   rY   r5   )r   r   ZnBytesZnewIndexÚbytesr   r   r   ró   ß  s    

zT2CharString.getBytesc                 C   s   |S r3   r   )r   r   r   r   r   r   ê  s    zT2CharString.handle_operatorc                 C   s  ddl m} | jd k	r$| | j¡ nêd}g }|  |¡\}}}|d krFqô|rÈ|dk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“  rc   ú 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   ÚtoXMLí  s6    



zT2CharString.toXMLc                 C   s:  ddl m}m} | d¡r,|  ||ƒ¡ d S t|ƒ}| ¡ }g }t|ƒ}d}||k �r,|| }	|d }zt|	ƒ}	W n¬ t	k
�r   zt
|	dd�}	W nz t	k
�r   | |	¡ |	dk�r
|| }
d}tdt|
ƒd	ƒD ] }|t||
||d	 … ƒƒ }qÖ| |¡ |d }Y nX | |	¡ Y qLX | |	¡ qL|  |¡ d S )
Nr   )Ú
binary2numÚreadHexÚrawr   r0   r1   r“  rÑ   rc   )r¡  r©  rª  rˆ   rš  r	   r¬   rY   rª   Ú
ValueErrorr   r®   r°   r   rÖ   )r   ÚnameÚattrsÚcontentr©  rª  rØ   r›  rU   rÙ   ÚmaskZ	maskBytesÚjr   r   r   ÚfromXML  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ƒ  Z  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Æ   rt  )r   r„  rØ   rt  r-  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£   B  s    z1T1CharString.getFixedEncoder.<locals>.encodeFixedr   )r   r£   r   r   r   rŠ  A  s    zT1CharString.getFixedEncoderc                 C   sJ   | j d krd S g }d}|  |¡\}}}|d kr0q<| |¡ q|  |¡ d S rÇ   )r„  rÓ   r®   rÖ   )r   rØ   r   rÙ   rÚ   r   r   r   r�  E  s    
zT1CharString.decompilec                 C   s"   t || jƒ}| | ¡ |j| _d S r3   )rs  rt  rÝ   r  )r   r%  r�  r   r   r   r�  Q  s    
zT1CharString.draw)NNN)rº   r»   r¼   Út1OperandEncodingr�  r^   Út1Operatorsr   r”  rÆ   rŸ   rŠ  r�  r�  rr  r   r   r-  r   rµ  6  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Æ   Z  s    zDictDecompiler.__init__c                 C   s   t | jƒdkstdƒ‚| jS )Nr   znon-empty stack)rY   rã   r5   r»  rÎ   r   r   r   ÚgetDict`  s    zDictDecompiler.getDictc                 C   sb   d}t |ƒ}| jj}||k r^t|| ƒ}|d }| j| }|| |||ƒ\}}|d k	r||ƒ qd S r  )rY   rã   r®   r   r�  )r   r   r   ZlenDatarä   r   rÛ   r   r   r   r   r�  d  s    
zDictDecompiler.decompilec                 C   s   | j d }| j d= |S rÞ   ©rã   rà   r   r   r   rá   p  s    
zDictDecompiler.popc                 C   s   | j d d … }| j d d …= |S r3   r¾  rö   r   r   r   rÕ   u  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_rj   )rZ   r[   r°   rY   rÔ   rã   r–  r»  )r   r   ZargTyper   rU   ro  Z
arghandlerr   r   r   r   z  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 )Nrj   )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   rw  rÅ  r   r   r   Ú	arg_array�  s    zDictDecompiler.arg_arrayc                 C   s°   | j  dd¡}| j |¡d }|  ¡ }|  ¡ }t|ƒ}||| ksFt‚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.
        ri   r   r   N)r»  rˆ   r¼  r  rá   rÕ   rY   r5   )r   r­  ri   rÃ  r  r÷   ZnumArgsr   Z	numDeltasrU   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Á  ÚcurrentrV   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¹  W  s   
	"r¹  c                 C   s,   t | ƒ}|dk rd}n|dk r$d}nd}|S )NiØ  r•   il„  r–   i €  )rY   )rt  ZnSubrsZbiasr   r   r   r¿   Ð  s    r¿   ):Ú__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   r7   r?   r·  rY   r5   r³  rË  r;   Ú	enumerater¯   Z
maxOpStackr^   r´  rŸ   ZencodeIntCFFr¶  r¡   rš   r£   r¦   r¸   Ú	Exceptionr¹   Úobjectr½   r¸  r  r$  rs  rƒ  rµ  r¹  r¿   r   r   r   r   Ú<module>   s(  

ñÉ;4	4 Læ3  f  ]!y