U
    Dvfä¤  ã                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 dd‚„ 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ƒZ8ddŽ„ 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   ú@/tmp/pip-unpacked-wheel-qlge9rch/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   Z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    r1   c                 C   s   t st‚t|fS ©N)ÚNotImplementedErrorÚAssertionErrorÚNotImplementedr   r   r   r   Úread_reserved?   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_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      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   ÚbuildOperatorDict|   s    r]   )r   Zhstem)é   Zvstem)r-   Zvmoveto)é   Zrlineto)é   Zhlineto)é   Zvlineto)é   Z	rrcurveto)é
   Zcallsubr)é   Úreturn)é   Úendchar)r9   Úvsindex)r/   Ú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   r^   Úand))r   r-   Úor))r   r_   Únot))r   rb   Ústore))r   é	   Úabs))r   rc   Úadd))r   rd   Úsub))r   r   Údiv))r   é   Úload))r   rf   Úneg))r   r9   Úeq))r   rj   Zdrop))r   rm   Úput))r   ro   Úget))r   rp   Zifelse))r   rq   Úrandom))r   rr   Úmul))r   rt   Úsqrt))r   ru   Údup))r   rB   Úexch))r   rC   r   ))r   rD   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ÚcffrB   rC   Ú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@ ƒ }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  rb   r   rA   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   r4   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 onlyr/   r0   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   r^   z-0.rR   r   rP   rQ   ú+r9   rD   r-   )ÚrealZeroBytesÚappendÚrealNibblesDictrX   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­   +  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 r2   )Ú
localSubrsÚcalcSubrBiasÚ	localBiasÚglobalSubrsÚ
globalBiasÚprivateÚblenderÚreset)r   r²   rµ   r·   r¸   r   r   r   Ú__init__0  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¹   9  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 r2   r   )Úxr   r   r   Ú<lambda>H  ó    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   ÚexecuteA  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 r2   rÔ   ©r   Ústackr   r   r   rÊ   e  s    zSimpleT2Decompiler.popallc                 C   s   | j  |¡ d S r2   )r½   r¥   rÕ   r   r   r   Úpushj  s    zSimpleT2Decompiler.pushc                 C   s
   | j rd S r2   rÔ   ©r   r   r   r   r   Ú	op_returnm  s    zSimpleT2Decompiler.op_returnc                 C   s   d S r2   r   rÚ   r   r   r   Ú
op_endcharq  s    zSimpleT2Decompiler.op_endcharc                 C   s   d S r2   r   rÚ   r   r   r   Ú	op_ignoret  s    zSimpleT2Decompiler.op_ignorec                 C   s&   |   ¡ }| j|| j  }|  |¡ d S r2   )rÖ   r²   r´   rÒ   ©r   r   Ú	subrIndexZsubrr   r   r   Úop_callsubrw  s    zSimpleT2Decompiler.op_callsubrc                 C   s&   |   ¡ }| j|| j  }|  |¡ d S r2   )rÖ   rµ   r¶   rÒ   rÞ   r   r   r   Úop_callgsubr|  s    zSimpleT2Decompiler.op_callgsubrc                 C   s   |   ¡  d S r2   ©Ú
countHintsrÚ   r   r   r   Úop_hstem  s    zSimpleT2Decompiler.op_hstemc                 C   s   |   ¡  d S r2   râ   rÚ   r   r   r   Úop_vstem„  s    zSimpleT2Decompiler.op_vstemc                 C   s   |   ¡  d S r2   râ   rÚ   r   r   r   Ú
op_hstemhm‡  s    zSimpleT2Decompiler.op_hstemhmc                 C   s   |   ¡  d S r2   râ   rÚ   r   r   r   Ú
op_vstemhmŠ  s    zSimpleT2Decompiler.op_vstemhmc                 C   s>   | j s|  ¡  | jd d | _ | jd  || j ¡\}}||fS )Nra   rb   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¾   rX   ©r   Úargsr   r   r   rã   –  s    zSimpleT2Decompiler.countHintsc                 C   s   t ‚d S r2   ©r3   rÚ   r   r   r   Úop_and›  s    zSimpleT2Decompiler.op_andc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_orž  s    zSimpleT2Decompiler.op_orc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_not¡  s    zSimpleT2Decompiler.op_notc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_store¤  s    zSimpleT2Decompiler.op_storec                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_abs§  s    zSimpleT2Decompiler.op_absc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_addª  s    zSimpleT2Decompiler.op_addc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_sub­  s    zSimpleT2Decompiler.op_subc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_div°  s    zSimpleT2Decompiler.op_divc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_load³  s    zSimpleT2Decompiler.op_loadc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_neg¶  s    zSimpleT2Decompiler.op_negc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_eq¹  s    zSimpleT2Decompiler.op_eqc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_drop¼  s    zSimpleT2Decompiler.op_dropc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_put¿  s    zSimpleT2Decompiler.op_putc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_getÂ  s    zSimpleT2Decompiler.op_getc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Ú	op_ifelseÅ  s    zSimpleT2Decompiler.op_ifelsec                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Ú	op_randomÈ  s    zSimpleT2Decompiler.op_randomc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_mulË  s    zSimpleT2Decompiler.op_mulc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_sqrtÎ  s    zSimpleT2Decompiler.op_sqrtc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_dupÑ  s    zSimpleT2Decompiler.op_dupc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_exchÔ  s    zSimpleT2Decompiler.op_exchc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   Úop_index×  s    zSimpleT2Decompiler.op_indexc                 C   s   t ‚d S r2   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½   rX   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 r2   )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}   Z	closepath)r‚   Zhsbw)rw   Z
dotsection))r   r   Zvstem3))r   r&   Zhstem3))r   r`   Zseac))r   ra   Zsbw))r   r/   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 r2   )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 k	s0tdƒ‚| j|d  | _|dd … }n| j| _d| _|S )Nr&   z5CFF2 CharStrings must not have an initial width valuer   r   )rÊ   r  rX   r  r4   r  r  )r   ÚevenOddrì   r   r   r   ÚpopallWidth)  s    ÿþzT2WidthExtractor.popallWidthc                 C   s    |   ¡ }| jt|ƒd  | _d S rê   )r  r¾   rX   rë   r   r   r   rã   8  s    zT2WidthExtractor.countHintsc                 C   s   |   ¡  d S r2   ©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_vmovetoB  s    zT2WidthExtractor.op_vmovetoc                 C   s   |   ¡  d S r2   r  rÚ   r   r   r   rÜ   E  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º   J  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Ò   f  s
    
zT2OutlineExtractor.executec                 C   s,   | j \}}||d  ||d  f}|| _ |S r  )r  )r   ÚpointrÃ   Úyr   r   r   Ú
_nextPointm  s    
zT2OutlineExtractor._nextPointc                 C   s   | j  |  |¡¡ d| _d S r  )r  ZmoveTor&  r  ©r   r$  r   r   r   ÚrMoveTos  s    zT2OutlineExtractor.rMoveToc                 C   s&   | j s|  d¡ | j |  |¡¡ d S ©Nr  )r  r(  r  ZlineTor&  r'  r   r   r   ÚrLineTow  s    
zT2OutlineExtractor.rLineToc                 C   s6   | j s|  d¡ | j}| j ||ƒ||ƒ||ƒ¡ d S r)  )r  r(  r&  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 r2   )r  r,  rÂ   r   r   r   r!  ‡  s    zT2OutlineExtractor.endPathc                 C   s   |   ¡  |  |  ¡ ¡ d S r2   ©r!  r(  r  rÚ   r   r   r   r  ¢  s    zT2OutlineExtractor.op_rmovetoc                 C   s$   |   ¡  |  |  d¡d df¡ d S r  r-  rÚ   r   r   r   r  ¦  s    zT2OutlineExtractor.op_hmovetoc                 C   s$   |   ¡  |  d|  d¡d f¡ d S r  r-  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§   rX   r*  )r   r   rì   rT   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»   r:  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   r`   N)rÊ   r§   rX   r+  )
r   r   rì   rT   Ú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&   r`   éþÿÿÿN)rÊ   r§   rX   r+  r*  )
r   r   rì   rT   r@  rA  rB  rC  Ú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§   rX   r*  r+  )r   r   rì   ZlineArgsrT   r@  rA  rB  rC  rF  rG  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Ê   rX   r§   r+  )	r   r   rì   Údx1rT   r?  r@  rA  rC  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-   rJ  )	r   r   rì   Údy1rT   r>  r@  rA  rB  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Ê   rP  rO  rQ  r   r   r   Úop_hvcurveto  s
    
zT2OutlineExtractor.op_hvcurvetoc                 C   sd   |   ¡ \}}}}}}}d }	 }
 }}| }|  ||	f||f||
f¡ |  ||f||f||f¡ d S r»   ©rÊ   r+  )r   r   rK  Údx2Údy2Údx3Údx4Údx5Údx6rM  Údy3Údy4Údy6Údy5r   r   r   Úop_hflex  s
    zT2OutlineExtractor.op_hflexc                 C   sZ   |   ¡ \}}}}}}}}	}
}}}}|  ||f||f||f¡ |  ||	f|
|f||f¡ d S r2   rT  )r   r   rK  rM  rU  rV  rW  r[  rX  r\  rY  r^  rZ  r]  Úfdr   r   r   Úop_flex%  s    "zT2OutlineExtractor.op_flexc              	   C   sp   |   ¡ \	}}}}}}}}	}
d }}|| | | |	  }|  ||f||f||f¡ |  ||f||	f|
|f¡ d S r»   rT  )r   r   rK  rM  rU  rV  rW  rX  rY  r^  rZ  r[  r\  r]  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 r2   )rÊ   r~   r+  )r   r   rK  rM  rU  rV  rW  r[  rX  r\  rY  r^  Zd6ZdxZdyrZ  r]  r   r   r   Úop_flex12  s    zT2OutlineExtractor.op_flex1c                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rî   @  s    zT2OutlineExtractor.op_andc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rï   C  s    zT2OutlineExtractor.op_orc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rð   F  s    zT2OutlineExtractor.op_notc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rñ   I  s    zT2OutlineExtractor.op_storec                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rò   L  s    zT2OutlineExtractor.op_absc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   ró   O  s    zT2OutlineExtractor.op_addc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rô   R  s    zT2OutlineExtractor.op_subc                 C   sB   |   ¡ }|   ¡ }|| }|| }||kr4|  |¡ n
|  |¡ d S r2   )rÖ   rÙ   )r   r   Znum2Znum1Úd1Zd2r   r   r   rõ   U  s    zT2OutlineExtractor.op_divc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rö   _  s    zT2OutlineExtractor.op_loadc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   r÷   b  s    zT2OutlineExtractor.op_negc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rø   e  s    zT2OutlineExtractor.op_eqc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rù   h  s    zT2OutlineExtractor.op_dropc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rú   k  s    zT2OutlineExtractor.op_putc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rû   n  s    zT2OutlineExtractor.op_getc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rü   q  s    zT2OutlineExtractor.op_ifelsec                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rý   t  s    zT2OutlineExtractor.op_randomc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rþ   w  s    zT2OutlineExtractor.op_mulc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   rÿ   z  s    zT2OutlineExtractor.op_sqrtc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   r   }  s    zT2OutlineExtractor.op_dupc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   r  €  s    zT2OutlineExtractor.op_exchc                 C   s   t ‚d S r2   rí   rÚ   r   r   r   r  ƒ  s    zT2OutlineExtractor.op_indexc                 C   s   t ‚d S r2   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Ê   r*  )r   ZisHorizontalrì   Úargr$  r   r   r   r;  Œ  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   ©rX   r+  )r   rì   r?  r@  rA  rB  rC  r   r   r   rO  –  s    zT2OutlineExtractor.vcurvetoc                 C   s\   |d d… \}}}}|dd … }t |ƒdkr:|d }g }nd}|  |df||f||f¡ |S rf  rg  )r   rì   r>  r@  rA  rC  rB  r   r   r   rP  ¡  s    zT2OutlineExtractor.hcurveto)NN)8r®   r¯   r°   rº   r¹   rÒ   r&  r(  r*  r+  r,  r!  r  r  r  rÜ   r9  r<  r=  rD  rH  rI  rL  rN  rR  rS  r_  ra  rb  rc  rî   rï   rð   rñ   rò   ró   rô   rõ   rö   r÷   rø   rù   rú   rû   rü   rý   rþ   rÿ   r   r  r  r  r;  rO  rP  Ú__classcell__r   r   r"  r   r  I  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 r2   )r  Úsubrsr¹   )r   r  rj  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 r2   ©rÊ   )r   r  r   r   r   r  ¾  s    zT1OutlineExtractor.popallWidthc                 C   s$   | j }|d |d  |d< |d< d S )NrE  rÆ   rÔ   r×   r   r   r   rŒ   Á  s    zT1OutlineExtractor.exchc                 C   s$   | j r
d S |  ¡  |  |  ¡ ¡ d S r2   )rk  r!  r(  rÊ   rÚ   r   r   r   r  È  s    zT1OutlineExtractor.op_rmovetoc                 C   s6   | j r|  d¡ d S |  ¡  |  |  ¡ d df¡ d S r»   )rk  rÙ   r!  r(  rÊ   rÚ   r   r   r   r  Î  s
    
zT1OutlineExtractor.op_hmovetoc                 C   s>   | j r|  d¡ |  ¡  d S |  ¡  |  d|  ¡ d f¡ d S r»   )rk  rÙ   rŒ   r!  r(  rÊ   rÚ   r   r   r   r  Ö  s    
zT1OutlineExtractor.op_vmovetoc                 C   s   |   ¡  d S r2   )r,  rÚ   r   r   r   Úop_closepathß  s    zT1OutlineExtractor.op_closepathc                 C   s   |   ¡ }|\}}||f| _d S r2   )rÊ   r  )r   r   rì   rÃ   r%  r   r   r   Úop_setcurrentpointâ  s    z%T1OutlineExtractor.op_setcurrentpointc                 C   s   |   ¡  d S r2   )r!  rÚ   r   r   r   rÜ   ç  s    zT1OutlineExtractor.op_endcharc                 C   s,   |   ¡ \}}|| _|| _|| jd f| _d S r  )rÊ   r  rl  r  )r   r   rl  Zwxr   r   r   Úop_hsbwê  s    zT1OutlineExtractor.op_hsbwc                 C   s   |   ¡  d S r2   rm  rÚ   r   r   r   Úop_sbwð  s    zT1OutlineExtractor.op_sbwc                 C   s    |   ¡ }| j| }|  |¡ d S r2   )rÖ   rj  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Ö   ÚdoFlexrk  )r   r   rß   ZnArgsr   r   r   Úop_callothersubrù  s    z#T1OutlineExtractor.op_callothersubrc                 C   s   d S r2   r   rÚ   r   r   r   Úop_pop  s    zT1OutlineExtractor.op_popc                 C   s4  |   ¡ }|   ¡ }|   ¡  |   ¡ }|   ¡ }|   ¡ }|   ¡ }|   ¡ }|   ¡ }|   ¡ }	|   ¡ }
|   ¡ }|   ¡ }|   ¡ }|   ¡ }|   ¡ }|   ¡ }|  || ¡ |  || ¡ |  |¡ |  |¡ |  |
¡ |  |	¡ |  d ¡ |  |¡ |  |¡ |  |¡ |  |¡ |  |¡ |  |¡ |  d ¡ |  |¡ |  |¡ d S r2   )rÖ   rÙ   rD  )r   ZfinalyZfinalxZp3yZp3xZbcp4yZbcp4xZbcp3yZbcp3xZp2yZp2xZbcp2yZbcp2xZbcp1yZbcp1xZrpyZrpxr   r   r   rr    sB    












zT1OutlineExtractor.doFlexc                 C   s   |   ¡  d S r2   rm  rÚ   r   r   r   Úop_dotsection1  s    z T1OutlineExtractor.op_dotsectionc                 C   s   |   ¡  d S r2   rm  rÚ   r   r   r   Ú	op_hstem34  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.  r0  r   N)r1  r/  rÊ   r  r2  rl  )
r   r   r/  Zasbr3  r4  r5  r6  r7  r8  r   r   r   Úop_seac7  s    zT1OutlineExtractor.op_seacc                 C   s   |   ¡  d S r2   rm  rÚ   r   r   r   Ú	op_vstem3B  s    zT1OutlineExtractor.op_vstem3N)r   )r®   r¯   r°   rº   r¹   r!  r  rŒ   r  r  r  rn  ro  rÜ   rp  rq  rà   rs  rt  rr  ru  rv  rw  rx  r   r   r   r   ri  ­  s*   
	*ri  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 r2   )ÚbytecoderÍ   r·   rµ   Ú_cur_vsindex)r   rz  rÍ   r·   rµ   r   r   r   rº   L  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 )Nrh   r   )r·   r4   r{  Úhasattrrh   r  )r   rh   Úpdr   r   r   r  U  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>)rz  r#  r®   ÚidrÂ   r   r   r   Ú__repr__^  s    
zT2CharString.__repr__c                 C   s   t S r2   )r    rÂ   r   r   r   rž   d  s    zT2CharString.getIntEncoderc                 C   s   t S r2   )r¢   rÂ   r   r   r   ÚgetFixedEncoderg  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   rj  Z
decompilerr   r   r   Ú	decompilej  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¸   rj  Ú	extractorr   r   r   Údrawq  s    ù	
zT2CharString.drawc                 C   s   t |ƒ}|  |¡ |jS r2   )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Æ   )re   rg   z@T2CharString or Subr has items on the stack after last operator.r   r   c                 s   s   | ]}t |ƒV  qd S r2   )r   )rS   r=   r   r   r   Ú	<genexpr>  s     z'T2CharString.compile.<locals>.<genexpr>zillegal operator: %s©rl   rn   zunsupported type: %s)rz  ÚopcodesrÍ   rY   Ústrr­   rž   r€  rX   Úextendr   r¥   Úintr;   r4   Útyper   Ú	TypeErrorr–   ÚerrorÚsetBytecode)
r   ZisCFF2rŠ  rÍ   rz  rœ   r¢   rT   ÚendrÎ   r   r   r   Úcompile„  sL    
ÿ



zT2CharString.compilec                 C   s
   | j d k	S r2   )rz  rÂ   r   r   r   rÇ   °  s    zT2CharString.needsDecompilationc                 C   s   || _ d | _d S r2   )rÍ   rz  )r   rÍ   r   r   r   rË   ³  s    zT2CharString.setProgramc                 C   s   || _ d | _d S r2   )rz  rÍ   )r   rz  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   )rz  ÚoperandEncodingrÍ   r‹  )	r   r   rX   r   rY   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  )rz  rÍ   rX   r4   )r   r   ZnBytesZnewIndexÚbytesr   r   r   rè   Ë  s    

zT2CharString.getBytesc                 C   s   |S r2   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‰  rb   ú r/   r0   )ÚfontTools.misc.textToolsr–  rz  ZdumphexrÈ   r¥   r   r	   ÚjoinÚwriteÚnewlinerY   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   r/   r0   r‰  rÅ   rb   )r˜  r   r¡  r‡   r‘  r	   ÚsplitrX   r  Ú
ValueErrorr   r¥   r§   r   rË   )r   ÚnameÚattrsÚcontentr   r¡  rÍ   r’  rT   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‘  rX   r   rY   rÈ   rè   r   rŸ  rª  r   r   r   r   ry  F  s*   
	
	

,
&ry  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 r2   )r   rº   rj  )r   rz  rÍ   rj  r"  r   r   rº   &  s    zT1CharString.__init__c                 C   s   t S r2   )Ú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 krd S g }d}|  |¡\}}}|d kr0q<| |¡ q|  |¡ d S r»   )rz  rÈ   r¥   rË   )r   rÍ   r   rÎ   rÏ   r   r   r   rƒ  1  s    
zT1CharString.decompilec                 C   s"   t || jƒ}| | ¡ |j| _d S r2   )ri  rj  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†  rh  r   r   r"  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 r2   )rØ   ÚstringsÚdictÚparent)r   r²  r´  r   r   r   rº   F  s    zDictDecompiler.__init__c                 C   s   t | jƒdkstdƒ‚| jS )Nr   znon-empty stack)rX   rØ   r4   r³  rÂ   r   r   r   ÚgetDictL  s    zDictDecompiler.getDictc                 C   sb   d}t |ƒ}| jj}||k r^t|| ƒ}|d }| j| }|| |||ƒ\}}|d k	r||ƒ qd S r  )rX   rØ   r¥   r   r”  )r   r   r   ZlenDatarÙ   r   rÐ   r   r   r   r   rƒ  P  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 r2   r¶  rë   r   r   r   rÊ   a  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_ri   )rY   rZ   r§   rX   rÉ   rØ   rŒ  r³  )r   r   ZargTyper   rT   re  Z
arghandlerr   r   r   r   f  s    
zDictDecompiler.handle_operatorc                 C   s*   t | jd tƒr|  | j¡}n|  ¡ }|S r»   )rY   rØ   ÚlistÚarg_blend_numberrÖ   )r   r¥  Úoutr   r   r   Ú
arg_numberv  s    zDictDecompiler.arg_numberc                 C   s4   g }|   ¡ }t|ƒ}| |¡ | d¡ |  ¡ }|S )Nri   )rÖ   rX   r¥   rÊ   )r   r¥  r¹  Z	blendArgsÚ
numMastersÚdummyr   r   r   r¸  }  s    

zDictDecompiler.arg_blend_numberc                 C   s   | j |  ¡  S r2   )r²  rÖ   ©r   r¥  r   r   r   Úarg_SID†  s    zDictDecompiler.arg_SIDc                 C   s   |   ¡ S r2   rm  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.
        rh   r   r   N)r³  r‡   r´  r  rÖ   rÊ   rX   r4   )r   r¥  rh   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Ê   rY   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±  C  s   
	"r±  c                 C   s,   t | ƒ}|dk rd}n|dk r$d}nd}|S )NiØ  r”   il„  r•   i €  )rX   )rj  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.   r1   r6   r>   r¯  rX   r4   r«  rÃ  r:   Ú	enumerater¦   Z
maxOpStackr]   r¬  rž   ZencodeIntCFFr®  r    r™   r¢   r¤   r¬   Ú	Exceptionr­   Úobjectr±   r°  r  r  ri  ry  r­  r±  r³   r   r   r   r   Ú<module>   s(  

ñÉ;4	  Læ3  f  ]!y