
    jke                        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j                  e      Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zdgdz  Zdegz  edd degz  edd degz  edd degz  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 e e      D  ci c]  \  } }|| 
 c}} Z!dZ"d Z#g dZ$d Z% e%d      Z& e%d      Z' e%d       Z(ejR                  fd!Z* ed       ed"      z   Z+d# Z, G d$ d%e-      Z. G d& d'e/      Z0g d(Z1 G d) d*e0      Z2 G d+ d,e2      Z3 G d- d.e3      Z4 G d/ d0e/      Z5 G d1 d2e5      Z6 G d3 d4e/      Z7d5 Z8yc c}} w )6zwpsCharStrings.py -- module implementing various kinds of CharStrings:
CFF dictionary data and Type1/Type2 CharStrings.
    )fixedToFloatfloatToFixedfloatToFixedToStrstrToFixedToFloat)bytechrbyteord	bytesjoinstrjoin)	BoundsPenNc                     |dk(  r|t        ||         f}|dz   }n|}	 | j                  |   }| j                  |      }||fS # t        $ r d |fcY S w xY w)N      )r   	operatorsKeyErrorhandle_operator)selfb0dataindexopoperatorvalues          >/usr/lib/python3/dist-packages/fontTools/misc/psCharStrings.pyread_operatorr      st    	Rx'$u+&'	>>"%   *E%<  U{s   A AAc                     |dz
  |fS )N    r   r   r   r   s       r   	read_byter   "   s    8U?    c                 D    t        ||         }|dz
  dz  |z   dz   |dz   fS )N      l   r   r   r   r   r   r   b1s        r   read_smallInt1r(   &   s2    	e	BHb 3&	11r    c                 F    t        ||         }|dz
   dz  |z
  dz
  |dz   fS )N   r#   r$   r   r%   r&   s        r   read_smallInt2r+   +   s4    	e	B#X;r!C'22r    c                 L    t        j                  d|||dz          \  }||dz   fS )N>h   structunpackr   r   r   r   r   s        r   read_shortIntr3   0   .    }}T4	#:;HU%!)r    c                 L    t        j                  d|||dz          \  }||dz   fS )N>l   r/   r2   s        r   read_longIntr8   5   r4   r    c                 b    t        j                  d|||dz          \  }t        |d      |dz   fS )Nr6   r7      precisionBits)r0   r1   r   r2   s        r   read_fixed1616r=   :   s5    }}T4	#:;HUR0%!);;r    c                 "    t         sJ t        |fS N)NotImplementedErrorNotImplementedr   s       r   read_reservedrB   ?   s    5  r    c                     d}	 t        ||         }|dz   }|dz  dz	  }|dz  }|dk(  rn|t        |   z   }|dk(  rn|t        |   z   }Et        |      |fS )N r      r7      )r   realNibblesfloat)r   r   r   r   numberbnibble0nibble1s           r   read_realNumberrM   D   s    F
DK 	t8/d(c>+g..c>+g..  =%r    r#          r"   r7   r*               )0123456789.EE-N-   c                     i }i }| D ]R  }t        |      dk(  r|d   ||d   <   n|dd  ||d   <   t        |d   t              r|d   ||d   <   G|d   f||d   <   T ||fS )Nr.   r   r   )len
isinstancetuple)operatorListoperopcitems       r   buildOperatorDictrk   |   s    D
C &t9> GDaM HDaMd1gu%7CQL G:CQL& 9r    )4r   hstem   vstemr7   vmoveto   rlineto   hlineto   vlineto   	rrcurveto
   callsubr   return   endchar)rF   vsindex)r:   blend)   hstemhm)   hintmask)   cntrmask   rmoveto   hmoveto)   vstemhm)   
rcurveline)   
rlinecurve)   	vvcurveto)   	hhcurveto)rR   	callgsubrrS   	vhcurveto   	hvcurveto)r   r   ignore))r   ro   and))r   r7   or))r   rt   not))r   r}   store))r   	   abs))r   r   add))r   r   sub)r   r   div))r      load))r   r   neg))r   rF   eq))r   r   drop))r   r   put))r   r   get))r   r   ifelse))r   r   random))r   r   mul))r   r   sqrt))r   r   dup))r   rQ   exch))r   rR   r   ))r   rS   roll))r   "   hflex))r   #   flex))r   $   hflex1))r   %   flex1c                     | dk(  rt        d      }t        d      }n'| dk(  rd }t        d      }n| dk(  sJ t        d      }d }|t         t        j                  t        j                  |fd}|S )NcffrQ   rR   t1rP   t2c                    d| cxk  rdk  rn n || dz         }|S d| cxk  rdk  r$n n!| dz
  }  || dz	  dz          || dz        z   }|S d	| cxk  rd
k  r%n n"|  dz
  }  || dz	  dz          || dz        z   }|S |d| cxk  rdk  rn n| |d|       z   }|S |)t         j                  d        |d       |d|       z   }|S | |d|       z   }|S )Nik   r   r$   k  r}   r"   rP   iir*   i i  r-   zk4-byte T2 number got passed to the IntType handler. This should happen only when reading in old XML files.
r6   )logwarning)r   
fourByteOpr   packr1   	twoByteOpcodes          r   	encodeIntz getIntEncoder.<locals>.encodeInt   s%    5C53;'D4 3 E!T!CKEEQJ#-.1FFD. - e#t#FSLEEQJ#-.1FFD( ' "v'?%'?tD%00D$ #  KK#
 3<$tU"33D  T5 11Dr    )r   r0   r   r1   )formatr   r   r   s       r   getIntEncoderr      sq    BK	R[
	4	S\
~~BK	
 [[}}#J r    r   r   r   c                 `    t        | d      }|dz  dk(  rt        |dz	        S d |d|      z   S )zFor T2 onlyr:   r;   i  r      r6   )r   encodeIntT2)fr   r   s      r   encodeFixedr      s;    "-Ev~5B;''dE***r    rF   c                    | dk(  rt         S d| z  }|d d dk(  r|dd  }n|d d dk(  rd|dd  z   }g }|rF|d	   }|dd  }|d
k(  r|d d }|dk(  r|dd  }d}n
|dk(  r|dd  }|j                  t        |          |rF|j                  d       t        |      dz  r|j                  d       t	        d      }t        d	t        |      d      D ]  }|t	        ||   dz  ||dz      z        z   }! |S )Ng        z%.8Gr.   z0.r   ro   z-0.ra   r   r_   r`   +rF   rS   r7   )realZeroBytesappendrealNibblesDictrd   r   range)r   snibblescc2dis          r   encodeFloatr     s/   Cx 	
A!u}abE	
2A%!AB%KG
aDabE82ABSyabEsabEq)*  NN3
7|asA1c'lA& :
a'!a%.899:Hr    c                       e Zd Zy)CharStringCompileErrorN)__name__
__module____qualname__r   r    r   r   r   +  s    r    r   c                      e Zd Zd+dZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd ZeZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,y),SimpleT2DecompilerNc                     || _         t        |      | _        || _        t        |      | _        || _        || _        | j                          y r?   )
localSubrscalcSubrBias	localBiasglobalSubrs
globalBiasprivateblenderreset)r   r   r   r   r   s        r   __init__zSimpleT2Decompiler.__init__0  s@    $%j1&&{3

r    c                 X    g | _         g | _        d| _        d| _        d| _        d| _        y Nr   )callingStackoperandStack	hintCounthintMaskBytes
numRegionsvsIndexr   s    r   r   zSimpleT2Decompiler.reset9  s/    r    c                    | j                   j                  |       |j                         }|rg }|j                  }nd }| j                  j                  }d}	 |j	                  |      \  }}}|nP ||       |r=d|z   }	t        | |	d       }
|
 |
|      }|r'|\  }} ||       n| j                          n ||       h|r|j                         | j                   d= y )Nc                      y r?   r   )xs    r   <lambda>z,SimpleT2Decompiler.execute.<locals>.<lambda>H  s    r    r   op_)r   r   needsDecompilationr   getTokengetattrpopall
setProgram)r   
charStringr
  programpushToProgrampushToStackr   token
isOperatorhandlerNamehandlerrvr   s                r   executezSimpleT2Decompiler.executeA  s      ,'::<G#NNM*M''..'1':':5'A$E:u}% #em!$T:& B/1,u%m4KKME"! " !!'*b!r    c                 >    | j                   d   }| j                   d= |S Nr	  r   r   r   s     r   popzSimpleT2Decompiler.pop`  s%    !!"%b!r    c                 B    | j                   d d  }g | j                   d d  |S r?   r  r   stacks     r   r  zSimpleT2Decompiler.popalle  s'    !!!$!!r    c                 :    | j                   j                  |       y r?   )r   r   r  s     r   pushzSimpleT2Decompiler.pushj  s      'r    c                     | j                   ry y r?   r  r   r   s     r   	op_returnzSimpleT2Decompiler.op_returnm  s     r    c                      y r?   r   r$  s     r   
op_endcharzSimpleT2Decompiler.op_endcharq      r    c                      y r?   r   r$  s     r   	op_ignorezSimpleT2Decompiler.op_ignoret  r(  r    c                 ~    | j                         }| j                  || j                  z      }| j                  |       y r?   )r  r   r   r  r   r   	subrIndexsubrs       r   op_callsubrzSimpleT2Decompiler.op_callsubrw  s0    HHJ	y4>>9:Tr    c                 ~    | j                         }| j                  || j                  z      }| j                  |       y r?   )r  r   r   r  r,  s       r   op_callgsubrzSimpleT2Decompiler.op_callgsubr|  s2    HHJ		DOO ;<Tr    c                 $    | j                          y r?   
countHintsr$  s     r   op_hstemzSimpleT2Decompiler.op_hstem      r    c                 $    | j                          y r?   r3  r$  s     r   op_vstemzSimpleT2Decompiler.op_vstem  r6  r    c                 $    | j                          y r?   r3  r$  s     r   
op_hstemhmzSimpleT2Decompiler.op_hstemhm  r6  r    c                 $    | j                          y r?   r3  r$  s     r   
op_vstemhmzSimpleT2Decompiler.op_vstemhm  r6  r    c                     | j                   s'| j                          | j                  dz   dz  | _         | j                  d   j	                  || j                         \  }}||fS )Nrz   r}   r	  )r   r4  r   r   getBytes)r   r   r   s      r   op_hintmaskzSimpleT2Decompiler.op_hintmask  s^    !!OO"&..1"4!:D#004==eTEWEWXue##r    c                 d    | j                         }| j                  t        |      dz  z   | _        y Nr.   )r  r   rd   r   argss     r   r4  zSimpleT2Decompiler.countHints  s%    {{}#d)q.8r    c                     t         r?   r@   r$  s     r   op_andzSimpleT2Decompiler.op_and      !!r    c                     t         r?   rE  r$  s     r   op_orzSimpleT2Decompiler.op_or  rG  r    c                     t         r?   rE  r$  s     r   op_notzSimpleT2Decompiler.op_not  rG  r    c                     t         r?   rE  r$  s     r   op_storezSimpleT2Decompiler.op_store  rG  r    c                     t         r?   rE  r$  s     r   op_abszSimpleT2Decompiler.op_abs  rG  r    c                     t         r?   rE  r$  s     r   op_addzSimpleT2Decompiler.op_add  rG  r    c                     t         r?   rE  r$  s     r   op_subzSimpleT2Decompiler.op_sub  rG  r    c                     t         r?   rE  r$  s     r   op_divzSimpleT2Decompiler.op_div  rG  r    c                     t         r?   rE  r$  s     r   op_loadzSimpleT2Decompiler.op_load  rG  r    c                     t         r?   rE  r$  s     r   op_negzSimpleT2Decompiler.op_neg  rG  r    c                     t         r?   rE  r$  s     r   op_eqzSimpleT2Decompiler.op_eq  rG  r    c                     t         r?   rE  r$  s     r   op_dropzSimpleT2Decompiler.op_drop  rG  r    c                     t         r?   rE  r$  s     r   op_putzSimpleT2Decompiler.op_put  rG  r    c                     t         r?   rE  r$  s     r   op_getzSimpleT2Decompiler.op_get  rG  r    c                     t         r?   rE  r$  s     r   	op_ifelsezSimpleT2Decompiler.op_ifelse  rG  r    c                     t         r?   rE  r$  s     r   	op_randomzSimpleT2Decompiler.op_random  rG  r    c                     t         r?   rE  r$  s     r   op_mulzSimpleT2Decompiler.op_mul  rG  r    c                     t         r?   rE  r$  s     r   op_sqrtzSimpleT2Decompiler.op_sqrt  rG  r    c                     t         r?   rE  r$  s     r   op_dupzSimpleT2Decompiler.op_dup  rG  r    c                     t         r?   rE  r$  s     r   op_exchzSimpleT2Decompiler.op_exch  rG  r    c                     t         r?   rE  r$  s     r   op_indexzSimpleT2Decompiler.op_index  rG  r    c                     t         r?   rE  r$  s     r   op_rollzSimpleT2Decompiler.op_roll  rG  r    c                    | j                   dk(  r| j                  j                         | _         | j                         }|| j                   dz   z  }| j                  | j
                  ||z
   d = y t        | j
                        |z
  }||z   x}}||k  r^|| j                   z   }| j
                  || }| j	                  | j                  |      }	| j
                  |xx   |	z  cc<   |}|dz  }||k  r^g | j
                  |d  y Nr   r   )r  r   getNumRegionsr  r   r   rd   r  )
r   r   	numBlendsnumOpsargiend_argstupleinext_tideltasdeltas
             r   op_blendzSimpleT2Decompiler.op_blend  s   ??a"ll88:DOHHJ	doo12<<!!9$%' t(()F2D $y 00Hv/ 4??2**6':T\\6:!!$'50' 	 / ,.Dhi(r    c                 r    | j                         }|| _        | j                  j                  |      | _        y r?   )r  r  r   rt  r  )r   r   vis      r   
op_vsindexzSimpleT2Decompiler.op_vsindex  s*    XXZ,,44R8r    NN)-r   r   r   r   r   r  r  r  r"  r%  r'  r*  r/  r1  r5  r8  r:  r<  r?  op_cntrmaskr4  rF  rI  rK  rM  rO  rQ  rS  rU  rW  rY  r[  r]  r_  ra  rc  re  rg  ri  rk  rm  ro  rq  r}  r  r   r    r   r   r   /  s    ">

(

$ K9
"""""""""""""""""""""".*9r    r   )rl   rn   rq   rs   rv   ry   r|   )r   	closepathr   r   )r   hsbwr   r   r   r   r   )r   
dotsection))r   r   vstem3))r   r.   hstem3))r   rw   seac))r   rz   sbwr   ))r   r:   callothersubr))r      r  ))r   !   setcurrentpointc                   D    e Zd Z	 	 d
dZd ZddZd Zd Zd Zd Z	d	 Z
y)T2WidthExtractorNc                 R    t         j                  | ||||       || _        || _        y r?   )r   r   nominalWidthXdefaultWidthX)r   r   r   r  r  r   r   s          r   r   zT2WidthExtractor.__init__  s*     	##D*k7GT**r    c                 J    t         j                  |        d| _        d| _        y r   )r   r   gotWidthwidthr  s    r   r   zT2WidthExtractor.reset$  s      &
r    c                     | j                         }| j                  sY|t        |      dz  z  r0| j                  J d       | j                  |d   z   | _        |dd  }n| j                  | _        d| _        |S )Nr.   z5CFF2 CharStrings must not have an initial width valuer   r   )r  r  rd   r  r  r  )r   evenOddrC  s      r   popallWidthzT2WidthExtractor.popallWidth)  s~    {{}}}#d)a-( &&2KJK2!//$q'9
ABx!//
DMr    c                 d    | j                         }| j                  t        |      dz  z   | _        y rA  )r  r   rd   rB  s     r   r4  zT2WidthExtractor.countHints8  s(    !#d)q.8r    c                 $    | j                          y r?   r  r$  s     r   
op_rmovetozT2WidthExtractor.op_rmoveto<      r    c                 &    | j                  d       y Nr   r  r$  s     r   
op_hmovetozT2WidthExtractor.op_hmoveto?      r    c                 &    | j                  d       y r  r  r$  s     r   
op_vmovetozT2WidthExtractor.op_vmovetoB  r  r    c                 $    | j                          y r?   r  r$  s     r   r'  zT2WidthExtractor.op_endcharE  r  r    r  r   )r   r   r   r   r   r  r4  r  r  r  r'  r   r    r   r  r    s2     +
9r    r  c                   V    e Zd Z	 	 d5dZd Z fdZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6 xZ7S )6T2OutlineExtractorc           	      V    t         j                  | ||||||       || _        d| _        y r   )r  r   pen	subrLevel)r   r  r   r   r  r  r   r   s           r   r   zT2OutlineExtractor.__init__J  s7     	!!	
 r    c                 X    t         j                  |        d| _        d| _        d| _        y )Nr   r   r   )r  r   currentPoint	sawMoveTor  r  s    r   r   zT2OutlineExtractor.reset`  s&    t$"r    c                     | xj                   dz  c_         t        | 	  |       | xj                   dz  c_         | j                   dk(  r| j                          y y Nr   r   )r  superr  endPath)r   r  	__class__s     r   r  zT2OutlineExtractor.executef  sE    !
#!>>QLLN r    c                 R    | j                   \  }}||d   z   ||d   z   f}|| _         |S rs  )r  )r   pointr  ys       r   
_nextPointzT2OutlineExtractor._nextPointm  s8      1E!Ha%(l*!r    c                 f    | j                   j                  | j                  |             d| _        y r  )r  moveTor  r  r   r  s     r   rMoveTozT2OutlineExtractor.rMoveTos  s"    ./r    c                     | j                   s| j                  d       | j                  j                  | j	                  |             y Nr  )r  r  r  lineTor  r  s     r   rLineTozT2OutlineExtractor.rLineTow  s.    ~~LL ./r    c                     | j                   s| j                  d       | j                  }| j                  j	                   ||       ||       ||             y r  )r  r  r  r  curveTo)r   pt1pt2pt3	nextPoints        r   rCurveTozT2OutlineExtractor.rCurveTo|  s@    ~~LL OO	333Hr    c                 ^    | j                   r| j                  j                          d| _         y r   )r  r  	closePathr  s    r   r  zT2OutlineExtractor.closePath  s     >>HH r    c                 >    | j                   r| j                          y y r?   )r  r  r  s    r   r  zT2OutlineExtractor.endPath  s    
 >>NN r    c                 b    | j                          | j                  | j                                y r?   r  r  r  r$  s     r   r  zT2OutlineExtractor.op_rmoveto  s     T%%'(r    c                 n    | j                          | j                  | j                  d      d   df       y r  r  r$  s     r   r  zT2OutlineExtractor.op_hmoveto  s,    d&&q)!,a01r    c                 n    | j                          | j                  d| j                  d      d   f       y rs  r  r$  s     r   r  zT2OutlineExtractor.op_vmoveto  s,    a))!,Q/01r    c           	          | j                          | j                         }|rVddlm} |\  }}}}||   }| j                  j                  |d       ||   }	| j                  j                  |	dddd||f       y y )Nr   StandardEncodingr   r   r   r   r   r   r   )r  r  $fontTools.encodings.StandardEncodingr  r  addComponent)
r   r   rC  r  adxadybcharachar	baseGlyphaccentGlyphs
             r   r'  zT2OutlineExtractor.op_endchar  s~    !M &*"CeU(/IHH!!)-?@*51KHH!!+1aC/EF r    c                     | j                         }t        dt        |      d      D ]  }|||dz    }| j                  |        y )Nr   r.   )r  r   rd   r  )r   r   rC  r   r  s        r   
op_rlinetozT2OutlineExtractor.op_rlineto  sD    {{}q#d)Q' 	 AQUOELL	 r    c                 &    | j                  d       y r  alternatingLinetor$  s     r   
op_hlinetozT2OutlineExtractor.op_hlineto      q!r    c                 &    | j                  d       y r   r  r$  s     r   
op_vlinetozT2OutlineExtractor.op_vlineto  r  r    c                     | j                         }t        dt        |      d      D ]*  }|||dz    \  }}}}}}	| j                  ||f||f||	f       , y)z${dxa dya dxb dyb dxc dyc}+ rrcurvetor   rw   N)r  r   rd   r  )
r   r   rC  r   dxadyadxbdybdxcdycs
             r   op_rrcurvetozT2OutlineExtractor.op_rrcurveto  sk    {{}q#d)Q' 		>A QQMM3*sCj3*=		>r    c                     | j                         }t        dt        |      dz
  d      D ]*  }|||dz    \  }}}}}}	| j                  ||f||f||	f       , | j	                  |dd        y)z-{dxa dya dxb dyb dxc dyc}+ dxd dyd rcurveliner   r.   rw   N)r  r   rd   r  r  )
r   r   rC  r   r  r  r  r  dxddyds
             r   op_rcurvelinez T2OutlineExtractor.op_rcurveline  sy    {{}q#d)a-+ 	>A+/AE?(Cc3SMM3*sCj3*=	> 	T"#Yr    c                     | j                         }|dd }t        dt        |      d      D ]  }| j                  |||dz            |dd \  }}}}}	}
| j	                  ||f||f|	|
f       y)z-{dxa dya}+ dxb dyb dxc dyc dxd dyd rlinecurveNir   r.   )r  r   rd   r  r  )r   r   rC  lineArgsr   r  r  r  r  r  r  s              r   op_rlinecurvez T2OutlineExtractor.op_rlinecurve  s    {{}9q#h-+ 	.ALL!a!e,-	.'+BCy$S#sCsCj3*sCj9r    c                     | j                         }t        |      dz  r|d   }|dd }nd}t        dt        |      d      D ]*  }|||dz    \  }}}}| j                  ||f||fd|f       d}, y)z!dx1? {dya dxb dyb dyc}+ vvcurvetor.   r   r   Nr7   r  rd   r   r  )	r   r   rC  dx1r   r  r  r  r  s	            r   op_vvcurvetozT2OutlineExtractor.op_vvcurveto  s    {{}t9q=q'C8DCq#d)Q' 	A!%a!a%Cc3MM3*sCj1c(;C	r    c                     | j                         }t        |      dz  r|d   }|dd }nd}t        dt        |      d      D ]*  }|||dz    \  }}}}| j                  ||f||f|df       d}, y)z!dy1? {dxa dxb dyb dxc}+ hhcurvetor.   r   r   Nr7   r  )	r   r   rC  dy1r   r  r  r  r  s	            r   op_hhcurvetozT2OutlineExtractor.op_hhcurveto  s    {{}t9q=q'C8DCq#d)Q' 	A!%a!a%Cc3MM3*sCj3(;C	r    c                 x    | j                         }|r(| j                  |      }|r| j                  |      }|r'yy)zdy1 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   rC  s      r   op_vhcurvetozT2OutlineExtractor.op_vhcurveto  6     {{}==&D}}T* r    c                 x    | j                         }|r(| j                  |      }|r| j                  |      }|r'yy)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  r  r  s      r   op_hvcurvetozT2OutlineExtractor.op_hvcurveto  r  r    c                     | j                         \  }}}}}}}dx}	x}
x}}| }| j                  ||	f||f||
f       | j                  ||f||f||f       y r   r  r  )r   r   r  dx2dy2dx3dx4dx5dx6r  dy3dy4dy6dy5s                 r   op_hflexzT2OutlineExtractor.op_hflex  so    ,0KKM)S#sCc !!!c!C#dsCj3*sCj9sCj3*sCj9r    c                     | j                         \  }}}}}}}}	}
}}}}| j                  ||f||f||f       | j                  ||	f|
|f||f       y r?   r  )r   r   r  r  r  r  r  r
  r  r  r  r  r	  r  fds                  r   op_flexzT2OutlineExtractor.op_flex%  s`    IMFS#sCc3S#sBsCj3*sCj9sCj3*sCj9r    c           	          | j                         \	  }}}}}}}}	}
dx}}||z   |z   |z   |	z    }| j                  ||f||f||f       | j                  ||f||	f|
|f       y r   r  )r   r   r  r  r  r  r  r  r  r  r	  r
  r  r  s                 r   	op_hflex1zT2OutlineExtractor.op_hflex1*  s{    6:kkm3S#sCc3cc	C#%+,sCj3*sCj9sCj3*sCj9r    c                    | j                         \  }}}}}}}}	}
}}||z   |z   |z   |
z   }||z   |z   |	z   |z   }t        |      t        |      kD  r|}| }n| }|}| j                  ||f||f||f       | j                  ||	f|
|f||f       y r?   )r  r   r  )r   r   r  r  r  r  r  r
  r  r  r  r  d6dxdyr	  r  s                    r   op_flex1zT2OutlineExtractor.op_flex12  s    ?C{{}<S#sCc3S"3Y_s"S(3Y_s"S(r7SWC#C#CCsCj3*sCj9sCj3*sCj9r    c                     t         r?   rE  r$  s     r   rF  zT2OutlineExtractor.op_and@  rG  r    c                     t         r?   rE  r$  s     r   rI  zT2OutlineExtractor.op_orC  rG  r    c                     t         r?   rE  r$  s     r   rK  zT2OutlineExtractor.op_notF  rG  r    c                     t         r?   rE  r$  s     r   rM  zT2OutlineExtractor.op_storeI  rG  r    c                     t         r?   rE  r$  s     r   rO  zT2OutlineExtractor.op_absL  rG  r    c                     t         r?   rE  r$  s     r   rQ  zT2OutlineExtractor.op_addO  rG  r    c                     t         r?   rE  r$  s     r   rS  zT2OutlineExtractor.op_subR  rG  r    c                     | j                         }| j                         }||z  }||z  }||k(  r| j                  |       y | j                  |       y r?   )r  r"  )r   r   num2num1d1d2s         r   rU  zT2OutlineExtractor.op_divU  sG    xxzxxzT\D[8IIbMIIbMr    c                     t         r?   rE  r$  s     r   rW  zT2OutlineExtractor.op_load_  rG  r    c                     t         r?   rE  r$  s     r   rY  zT2OutlineExtractor.op_negb  rG  r    c                     t         r?   rE  r$  s     r   r[  zT2OutlineExtractor.op_eqe  rG  r    c                     t         r?   rE  r$  s     r   r]  zT2OutlineExtractor.op_droph  rG  r    c                     t         r?   rE  r$  s     r   r_  zT2OutlineExtractor.op_putk  rG  r    c                     t         r?   rE  r$  s     r   ra  zT2OutlineExtractor.op_getn  rG  r    c                     t         r?   rE  r$  s     r   rc  zT2OutlineExtractor.op_ifelseq  rG  r    c                     t         r?   rE  r$  s     r   re  zT2OutlineExtractor.op_randomt  rG  r    c                     t         r?   rE  r$  s     r   rg  zT2OutlineExtractor.op_mulw  rG  r    c                     t         r?   rE  r$  s     r   ri  zT2OutlineExtractor.op_sqrtz  rG  r    c                     t         r?   rE  r$  s     r   rk  zT2OutlineExtractor.op_dup}  rG  r    c                     t         r?   rE  r$  s     r   rm  zT2OutlineExtractor.op_exch  rG  r    c                     t         r?   rE  r$  s     r   ro  zT2OutlineExtractor.op_index  rG  r    c                     t         r?   rE  r$  s     r   rq  zT2OutlineExtractor.op_roll  rG  r    c                 p    | j                         }|D ]!  }|r|df}nd|f}| j                  |       | }# y r   )r  r  )r   isHorizontalrC  argr  s        r   r  z$T2OutlineExtractor.alternatingLineto  sE    {{} 	,CaCLL++L	,r    c                     |d d \  }}}}|dd  }t        |      dk(  r|d   }g }nd}| j                  d|f||f||f       |S Nr7   r   r   rd   r  )r   rC  r  r  r  r  r  s          r   r  zT2OutlineExtractor.vcurveto  s`    !"1XS#sABxt9>q'CDCq#hc
S#J7r    c                     |d d \  }}}}|dd  }t        |      dk(  r|d   }g }nd}| j                  |df||f||f       |S r7  r8  )r   rC  r  r  r  r  r  s          r   r  zT2OutlineExtractor.hcurveto  s`    !"1XS#sABxt9>q'CDCsAhc
S#J7r    r  )8r   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  rF  rI  rK  rM  rO  rQ  rS  rU  rW  rY  r[  r]  r_  ra  rc  re  rg  ri  rk  rm  ro  rq  r  r  r  __classcell__r  s   @r   r  r  I  s    ,0
I
6)22G" ""> :++::
::""""""""""""""""""""",		r    r  c                       e Zd Zd Zd Zd ZddZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)T1OutlineExtractorc                 @    || _         || _        | j                          y r?   )r  subrsr   )r   r  r?  s      r   r   zT1OutlineExtractor.__init__  s    


r    c                 X    d| _         d| _        d| _        t        j	                  |        y r   )flexingr  sbxr  r   r  s    r   r   zT1OutlineExtractor.reset  s%    
  &r    c                 ^    | j                   r| j                  j                          d| _         y r   )r  r  r  r  s    r   r  zT1OutlineExtractor.endPath  s     >>HHr    c                 "    | j                         S r?   r  )r   r  s     r   r  zT1OutlineExtractor.popallWidth      {{}r    c                 >    | j                   }|d   |d   c|d<   |d<   y )Nr  r	  r  r  s     r   r   zT1OutlineExtractor.exch  s)    !!$Ry%)b	59r    c                 |    | j                   ry | j                          | j                  | j                                y r?   )rA  r  r  r  r$  s     r   r  zT1OutlineExtractor.op_rmoveto  s'    <<T[[]#r    c                     | j                   r| j                  d       y | j                          | j                  | j	                         d   df       y r   )rA  r"  r  r  r  r$  s     r   r  zT1OutlineExtractor.op_hmoveto  s<    <<IIaLdkkmA&*+r    c                     | j                   r"| j                  d       | j                          y | j                          | j	                  d| j                         d   f       y r   )rA  r"  r   r  r  r  r$  s     r   r  zT1OutlineExtractor.op_vmoveto  sE    <<IIaLIIKaq)*+r    c                 $    | j                          y r?   )r  r$  s     r   op_closepathzT1OutlineExtractor.op_closepath  s    r    c                 @    | j                         }|\  }}||f| _        y r?   )r  r  )r   r   rC  r  r  s        r   op_setcurrentpointz%T1OutlineExtractor.op_setcurrentpoint  s"    {{}1qDr    c                 $    | j                          y r?   )r  r$  s     r   r'  zT1OutlineExtractor.op_endchar  s    r    c                 r    | j                         \  }}|| _        || _        || j                  d   f| _        y r  )r  r  rB  r  )r   r   rB  wxs       r   op_hsbwzT1OutlineExtractor.op_hsbw  s7    ++-R
!2!21!55r    c                 $    | j                          y r?   rE  r$  s     r   op_sbwzT1OutlineExtractor.op_sbw      r    c                 d    | j                         }| j                  |   }| j                  |       y r?   )r  r?  r  r,  s       r   r/  zT1OutlineExtractor.op_callsubr  s'    HHJ	zz)$Tr    c                     | j                         }| j                         }|dk(  r|dk(  r| j                          d| _        y |dk(  r|dk(  rd| _        y y y )Nr   ro   r   )r  doFlexrA  )r   r   r-  nArgss       r   op_callothersubrz#T1OutlineExtractor.op_callothersubr  sP    HHJ	
>eqjKKMDL!^
DL !+^r    c                      y r?   r   r$  s     r   op_popzT1OutlineExtractor.op_pop  r(  r    c                 P   | j                         }| j                         }| j                          | j                         }| j                         }| j                         }| j                         }| j                         }| j                         }| j                         }	| j                         }
| j                         }| j                         }| j                         }| j                         }| j                         }| j                         }| j                  ||z          | j                  ||z          | j                  |       | j                  |       | j                  |
       | j                  |	       | j                  d        | j                  |       | j                  |       | j                  |       | j                  |       | j                  |       | j                  |       | j                  d        | j                  |       | j                  |       y r?   )r  r"  r  )r   finalyfinalxp3yp3xbcp4ybcp4xbcp3ybcp3xp2yp2xbcp2ybcp2xbcp1ybcp1xrpyrpxs                    r   rX  zT1OutlineExtractor.doFlex  s   
hhjhhj



hhjhhj



hhjhhj 			%#+		%#+		%		%		#		#$ 			%		%		%		%		#		#$ 			&		&r    c                 $    | j                          y r?   rE  r$  s     r   op_dotsectionz T1OutlineExtractor.op_dotsection1  rU  r    c                 $    | j                          y r?   rE  r$  s     r   	op_hstem3zT1OutlineExtractor.op_hstem34  rU  r    c           	          ddl m} | j                         \  }}}}}||   }| j                  j	                  |d       ||   }	|| j
                  z   |z
  }| j                  j	                  |	dddd||f       y)zasb adx ady bchar achar seacr   r  r  r   N)r  r  r  r  r  rB  )
r   r   r  asbr  r  r  r  r  r  s
             r   op_seaczT1OutlineExtractor.op_seac7  sw    I&*kkm#S#ue$U+	i);<&u-DHHns"kAq!QS+ABr    c                 $    | j                          y r?   rE  r$  s     r   	op_vstem3zT1OutlineExtractor.op_vstem3B  rU  r    Nr  )r   r   r   r   r   r  r  r   r  r  r  rL  rN  r'  rR  rT  r/  rZ  r\  rX  ro  rq  rt  rv  r   r    r   r=  r=    sm    
'
4$,,!
6
(T	Cr    r=  c                       e Zd ZeZ ee      \  ZZe	Z
eZddZddZd Zd Zd Zd ZddZd	 Zdd
Zd Zd Zd ZeeefdZd Zd ZddZd Z y)T2CharStringNc                 Z    |g }|| _         || _        || _        ||ng | _        d | _        y r?   )bytecoder  r   r   _cur_vsindex)r   rz  r  r   r   s        r   r   zT2CharString.__init__L  s8    ?G *5*A;r r    c                     | j                   }|J ||| _        n+| j                  t        |d      r|j                  nd| _        |j	                  | j                        S )Nr   r   )r   r{  hasattrr   rt  )r   r   pds      r   rt  zT2CharString.getNumRegionsU  s]    \\~~ 'D&.5b).D

!D 1 122r    c                     | j                   $d| j                  j                  t        |       fz  S d| j                  j                  t        |       fz  S )Nz<%s (source) at %x>z<%s (bytecode) at %x>)rz  r  r   idr  s    r   __repr__zT2CharString.__repr__^  sH    == (DNN,C,CRX+NNN*dnn.E.Er$x-PPPr    c                     t         S r?   )r   r  s    r   r   zT2CharString.getIntEncoderd      r    c                     t         S r?   )r   r  s    r   getFixedEncoderzT2CharString.getFixedEncoderg  r  r    c                     | j                         sy t        | j                  dg       }| j                  || j                  | j                        }|j                  |        y NSubrs)r
  r  r   decompilerClassr   r  )r   r?  
decompilers      r   	decompilezT2CharString.decompilej  sO    &&(gr2))%1A1A4<<P
4 r    c           	         t        | j                  dg       }| j                  ||| j                  | j                  j                  | j                  j
                  | j                  |      }|j                  |        |j                  | _        y r  )r  r   outlineExtractorr   r  r  r  r  )r   r  r   r?  	extractors        r   drawzT2CharString.drawq  sr    gr2))LL&&LL&&LL
	 	$__
r    c                 R    t        |      }| j                  |       |j                  S r?   )r   r  bounds)r   glyphSet	boundsPens      r   
calcBoundszT2CharString.calcBounds  s$    h'			)r    c                 H   | j                   y | j                  }| j                  }|r|r-|d   dv r&|d d }n |rt        |d   t              st        d      g }| j                         }| j                         }d}t        |      }||k  r||   }	|dz   }t        |	t              r:	 |j                  d ||	   D               |	dv r}|j                  ||          |dz   }nct        |	t              r|j                   ||	             n;t        |	t              r|j                   ||	             nJ d	t        |	      z         ||k  r	 t        |      }| j'                  |       y # t        $ r t        d|	z        w xY w# t         $ r t"        j%                  |        w xY w)
Nr	  )r   r   z@T2CharString or Subr has items on the stack after last operator.r   r   c              3   2   K   | ]  }t        |        y wr?   )r   ).0rJ   s     r   	<genexpr>z'T2CharString.compile.<locals>.<genexpr>  s     #G1GAJ#Gs   zillegal operator: %sr   r   zunsupported type: %s)rz  opcodesr  re   strr   r   r  rd   extendr   r   intrH   typer	   	TypeErrorr   errorsetBytecode)
r   isCFF2r  r  rz  r   r   r   endr  s
             r   compilezT2CharString.compile  s   ==$,,,,72;*??!#2,ZS9(R  &&(	**,'l#gAJEAA%%QOO#G#GG 44OOGAJ/AAE3'	% 01E5)E 23>04;>>q! #g"	 *H 	"!   Q01G%1OPPQ  	IIh	s   &E& 	F &E> F!c                     | j                   d uS r?   )rz  r  s    r   r
  zT2CharString.needsDecompilation  s    }}D((r    c                      || _         d | _        y r?   )r  rz  )r   r  s     r   r  zT2CharString.setProgram  s    r    c                      || _         d | _        y r?   )rz  r  )r   rz  s     r   r  zT2CharString.setBytecode  s     r    c                 B   | j                   X| || j                         k\  ry || j                   |         }|dz   }| j                  |   } || || j                   |      \  }}n*| || j                        k\  ry| j                  |   }|dz   } ||t              }|||fS )N)Nr   r   r   )rz  operandEncodingr  r  )	r   r   rd   r   re   r   r  r  r  s	            r   r  zT2CharString.getToken  s    ==$DMM**!u-.BAIE**2.G"4T]]EBLE5DLL))!LL'EAIEs+
j%''r    c                     | j                   ||z   }| j                   || }|}n| j                  |   }|dz   }t        |      |k(  sJ ||fS r  )rz  r  rd   )r   r   nBytesnewIndexbytess        r   r>  zT2CharString.getBytes  s]    ==$v~HMM%1EELL'EAIE5zV###e|r    c                     |S r?   r   )r   r   s     r   r   zT2CharString.handle_operator  s    r    c                    ddl m} | j                  |j                  | j                         y d}g }	 | j	                  |      \  }}}|n|r|dv ra| j	                  |      \  }}}g }	|D ]#  }
|	j                   |t        |
      d             % t        |	      }dj                  |||gz         }ndj                  ||gz         }|j                  |       |j                          g }n:t        |t              rt        |d      }nt        |      }|j                  |       |r#dj                  |      }|j                  |       y y )Nr   )
num2binaryr  r}    r:   r;   )fontTools.misc.textToolsr  rz  dumphexr  r   r   r
   joinwritenewlinere   rH   r   r  )r   	xmlWriterttFontr  r   rC  r  r  hintMaskbitsbytelines               r   toXMLzT2CharString.toXML  s@   7==$dmm,ED+/==+?(z5= 886:mmE6J3*e!$, FD KK
74=!(DEF#*4="xxx/@(@A"xxw7OOD)%%'D!%/ 1%r J #E
KK&- .  xx~% r    c                    ddl m}m} |j                  d      r| j	                   ||             y t        |      }|j                         }g }t        |      }d}||k  r-||   }	|dz   }	 t        |	      }	|j                  |	       ||k  r-| j                  |       y # t        $ r 	 t        |	d      }	|j                  |	       nv# t        $ rj |j                  |	       |	dv rR||   }
d}t        dt        |
      d	      D ]  }|t         ||
||d	z                z   } |j                  |       |dz   }Y nw xY wY w xY w)
Nr   )
binary2numreadHexrawr   r:   r;   r  r    r}   )r  r  r  r   r  r
   splitrd   r  r   
ValueErrorr   r   r   r  )r   nameattrscontentr  r  r  r  r   r  mask	maskBytesjs                r   fromXMLzT2CharString.fromXML  sT   @99UWW-.'"--/'l#gAJEAA&E
  u%) #g* 	 !  **-e2FE NN5) " "NN5) 88&qz$'	!&q#d)Q!7 YA(1GJtAPQTUPU<W4X(XIYy1E"*s7   ,B   	E*C	7E	A0D<9E;D<<EE)NNNNr?   )F)!r   r   r   t2OperandEncodingr  rk   t2Operatorsr   r  r   r  r  r  r   rt  r  r   r  r  r  r  r  r
  r  r  rd   r   re   r  r>  r   r  r  r   r    r   rx  rx  F  s    'O*;7Iw(O)!3Q!% 
*#X) #&w: ( 	$&L !r    rx  c                   R     e Zd ZeZ ee      \  ZZd fd	Z	d Z
d Zd Zd Z xZS )T1CharStringc                 4    t         |   ||       || _        y r?   )r  r   r?  )r   rz  r  r?  r  s       r   r   zT1CharString.__init__&  s    7+
r    c                     t         S r?   )encodeIntT1r  s    r   r   zT1CharString.getIntEncoder*  r  r    c                 
    d }y )Nc                     t        d      )Nz8Type 1 charstrings don't support floating point operands)r  )r   s    r   r   z1T1CharString.getFixedEncoder.<locals>.encodeFixed.  s    VWWr    r   )r   r   s     r   r  zT1CharString.getFixedEncoder-  s    	Xr    c                     | j                   y g }d}	 | j                  |      \  }}}|n|j                  |       *| j                  |       y r   )rz  r  r   r  )r   r  r   r  r  s        r   r  zT1CharString.decompile1  sX    == '+}}U';$E:u}NN5!	 
 	 r    c                 t    t        || j                        }|j                  |        |j                  | _        y r?   )r=  r?  r  r  )r   r  r  s      r   r  zT1CharString.draw=  s+    &sDJJ7	$__
r    )NNN)r   r   r   t1OperandEncodingr  rk   t1Operatorsr   r  r   r   r  r  r  r:  r;  s   @r   r  r  "  s1    'O*;7IwX
!%r    r  c                   Z    e Zd ZeZddZd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zy)DictDecompilerNc                 <    g | _         || _        i | _        || _        y r?   )r   stringsdictparent)r   r  r  s      r   r   zDictDecompiler.__init__F  s    
	r    c                 X    t        | j                        dk(  sJ d       | j                  S )Nr   znon-empty stack)rd   r   r  r  s    r   getDictzDictDecompiler.getDictL  s(    4::!#6%66#yyr    c                     d}t        |      }| j                  j                  }||k  rAt        ||         }|dz   }| j                  |   } || |||      \  }}| ||       ||k  r@y y rs  )rd   r   r   r   r  )r   r   r   lenDatar"  r   r  r   s           r   r  zDictDecompiler.decompileP  sw    d)zz  goe%BAIE**2.G"4T59LE5 U gor    c                 >    | j                   d   }| j                   d= |S r  r   r  s     r   r  zDictDecompiler.pop\  s    

2JJrNr    c                 B    | j                   d d  }| j                   d d = |S r?   r  rB  s     r   r  zDictDecompiler.popalla  s    zz!}JJqMr    c                 >   |\  }}t        |t              rAd}t        t        |      dz
  dd      D ]"  }||   }t	        | d|z         } ||      f|z   }$ nt	        | d|z         } ||      }|dk(  r| j
                  j                  |       y || j                  |<   y )Nr   r   r	  arg_r   )re   rf   r   rd   r  r   r  r  )r   r   argTyper   r   r5  
arghandlers          r   r   zDictDecompiler.handle_operatorf  s    $'gu%E3w<!+R4 8aj$T6C<8
#H-/%78
 !v'78Jx(EwJJe$"'DIIhr    c                     t        | j                  d   t              r| j                  | j                        }|S | j	                         }|S r   )re   r   listarg_blend_numberr  )r   r  outs      r   
arg_numberzDictDecompiler.arg_numberv  sA    djjmT*''

3C 
 ((*C
r    c                     g }| j                         }t        |      }|j                  |       |j                  d       | j                         }|S )Nr   )r  rd   r   r  )r   r  r  	blendArgs
numMastersdummys         r   r  zDictDecompiler.arg_blend_number}  sD    HHJ	^


9

7r    c                 <    | j                   | j                            S r?   )r  r  r   r  s     r   arg_SIDzDictDecompiler.arg_SID  s    ||DHHJ''r    c                 "    | j                         S r?   rE  r  s     r   	arg_arrayzDictDecompiler.arg_array  rF  r    c                 h   | j                   j                  dd      }| j                  j                  |      dz   }| j	                         }| j                         }t        |      }|||z  k(  sJ dg|z  }|dz
  }d}	d}
|	|k  r.||	   |
z   }|}
||	|z  z   }|g||||z    z   }|||	<   |	dz  }	|	|k  r.|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.
        r   r   r   N)r  r   r  rt  r  r  rd   )r   r  r   r  ru  rC  numArgsr   	numDeltasr   prevValnewValmasterOffset	blendLists                 r   arg_blendListzDictDecompiler.arg_blendList  s     ))--	1-KK%%g.2 	 HHJ	{{}d)*y0000"N	)m!Ww&FG$I6L4|i7O#PPI E!HFA )m r    c                     | j                         }g }|rt        |d   t              r|}|S d}|D ]  }||z   }|j                  |        |S r   )r  re   r  r   )r   r  	valueListr  currentvs         r   	arg_deltazDictDecompiler.arg_delta  s`    KKM	IaL$7C 
	 G $!A+

7#$ 
r    r?   )r   r   r   cffDictOperandEncodingr  r   r  r  r  r  r   r  r  r  r  r  r  r   r    r   r  r  C  sD    ,O


( ( Dr    r  c                 D    t        |       }|dk  rd}|S |dk  rd}|S d}|S )Ni  r   il  r   i   )rd   )r?  nSubrsbiass      r   r   r     s?    ZF}
 K	 
% K Kr    )9__doc__fontTools.misc.fixedToolsr   r   r   r   r  r   r   r	   r
   fontTools.pens.boundsPenr   r0   logging	getLoggerr   r   r   r   r(   r+   r3   r8   r=   rB   rM   r  rd   r  r  rG   	enumerater   
maxOpStackrk   r  r   encodeIntCFFr  r   r   r   r   r   	Exceptionr   objectr   r  r  r  r=  rx  r  r  r   )r   r  s   00r   <module>r     s?    J I .   g!2
3


<
!
   FSL -0 !B %)4 "S 'N+;; #c 'N+;; #c % # 
$ $$%a( % " ' # *1- ) r , r + s " %.k$:;DAq1a4;
8v1h U#D!D!  + gcl*@	Y 	F9 F9R<0) 0fa) aHV+ VrY!6 Y!x%< %BvV vrK* <s   E<