
    <`2                     X   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d  e e          D             Z!dZ"d Z#g dZ$d Z% e%d          Z& e%d           Z' e%d!          Z(ej)        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 d0 d1e/          Z5 G d2 d3e5          Z6 G d4 d5e/          Z7d6 Z8dS )7zwpsCharStrings.py -- module implementing various kinds of CharStrings:
CFF dictionary data and Type1/Type2 CharStrings.
    )bytechrbyteord	bytesjoinstrjoin)fixedToFloatfloatToFixedfloatToFixedToStrstrToFixedToFloat)	BoundsPenNc                     |dk    r|t          ||                   f}|dz   }n|}	 | j        |         }n# t          $ r d |fcY S w xY w|                     |          }||fS )N      )r   	operatorsKeyErrorhandle_operator)selfb0dataindexopoperatorvalues          <lib/python3.11/site-packages/fontTools/misc/psCharStrings.pyread_operatorr      s    "HH
GDK  !"
'%%	"^B((   	u			h	'	'us   5 AAc                     |dz
  |fS )N    r   r   r   r   s       r   	read_byter      s    
S%    c                 R    t          ||                   }|dz
  dz  |z   dz   |dz   fS )N      l   r   r   r   r   r   r   b1s        r   read_smallInt1r(   !   s4    d5k	CrCq((r    c                 T    t          ||                   }|dz
   dz  |z
  dz
  |dz   fS )N   r#   r$   r   r%   r&   s        r   read_smallInt2r+   %   s6    d5k
S&	#S %'))r    c                 T    t          j        d|||dz                      \  }||dz   fS )N>h   structunpackr   r   r   r   r   s        r   read_shortIntr3   )   0    
-d5q=1
2
2uQwr    c                 T    t          j        d|||dz                      \  }||dz   fS )N>l   r/   r2   s        r   read_longIntr8   -   r4   r    c                 r    t          j        d|||dz                      \  }t          |d          |dz   fS )Nr6   r7      precisionBits)r0   r1   r   r2   s        r   read_fixed1616r=   1   s>    
-d5q=1
2
2U"---uQw66r    c                 &    t           sJ t          |fS N)NotImplementedErrorNotImplementedr   s       r   read_reservedrB   5   s    r    c                     d}	 t          ||                   }|dz   }|dz  dz	  }|dz  }|dk    rn(|t          |         z   }|dk    rn|t          |         z   }Vt          |          |fS )N Tr      r7      )r   realNibblesfloat)r   r   r   r   numberbnibble0nibble1s           r   read_realNumberrM   9   s    

)d5k!
!)%X!O'H'^^K((&^^K((&
) 	fur    r#          r"   r7   r*               )0123456789.EE-N-c                     i | ]\  }}||	S r   r   ).0ivs      r   
<dictcomp>rf   ]   s    99931Q1Q999r       c                 
   i }i }| D ]y}t          |          dk    r|d         ||d         <   n|dd          ||d         <   t          |d         t                    r|d         ||d         <   g|d         f||d         <   z||fS )Nr.   r   r   )len
isinstancetuple)operatorListoperopcitems       r   buildOperatorDictrp   b   s    
	  TYY!^^74Q==84Q=Q q'3tAw<<7*3tAw<<c	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   rt   and))r   r7   or))r   ry   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          }n | dk    rt          d          }n
| dk    sJ d }|t           t          j        t          j        fd}|S )NcffrR   t1rP   t2c                    d| cxk    rdk    rn n || dz             }nd| cxk    rdk    r)n n&| dz
  }  || dz	  dz              || dz            z   }nd	| cxk    rd
k    r*n n'|  dz
  }  || dz	  dz              || dz            z   }nm|\d| cxk    rdk    rn n |d           |d|           z   }nBt                               d            |d           |d|           z   }n| |d|           z   }|S )Nik   r   r$   k  r   r"   rP   iir*   i i  rQ   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   codes         r   	encodeIntz getIntEncoder.<locals>.encodeInt   s   	Uc
'%#+

44
et3;5
'5A:$
%
%(=(=
=446C<5
'5A:$
%
%(=(=
=4472;;dE***DD KK     73<<$$tU+++DD
ttD%((
(4	+r    )r   r0   r   r1   )formatr   r   s      r   getIntEncoderr      sj    
eOOr{{**nns||**	4*!+WFM   > 	r    r   r   r   c                 x    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      sL    	ar	*	*	*	FNa	Ub[	!	!!	44e$$	$$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 }|rg|d	         }|dd          }|d
k    r-|d d         }|dk    r|dd          }d}n|dk    r
|dd          }|                    t          |                    |g|                    d           t          |          dz  r|                    d           t	          d          }t          d	t          |          d          D ])}|t	          ||         dz  ||dz            z            z   }*|S )Ng        z%.8Gr.   z0.r   rt   z-0.ra   r   r_   r`   +rF   rS   r7   )realZeroBytesappendrealNibblesDictri   r   range)r   snibblescc2drd   s          r   encodeFloatr      s~   HH	 aZbqbETMMe!!eunn	AabbEk! 
%d!e!#XX	"1"2Cii	!""AAA
c			!""A	..#$$$ 	 
% 	LL1 	..R[[
3w<<
#
# 2 2Q''!*/GAaCL0
1
11!!	r    c                       e Zd ZdS )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,dS ),SimpleT2DecompilerNc                     || _         t          |          | _        || _        t          |          | _        || _        |                                  d S r?   )
localSubrscalcSubrBias	localBiasglobalSubrs
globalBiasprivatereset)r   r   r   r   s       r   __init__zSimpleT2Decompiler.__init__
  sG    $/
++$. $ --$/$,**,,,,,r    c                 L    g | _         g | _        d| _        d| _        d| _        d S Nr   )callingStackoperandStack	hintCounthintMaskBytes
numRegionsr   s    r   r   zSimpleT2Decompiler.reset  s,    $$$.$$///r    c                    | j                             |           |                                }|r
g }|j        }nd }| j        j        }d}	 |                    |          \  }}}|nd ||           |rKd|z   }	t          | |	d           }
|
 |
|          }|r|\  }} ||           n |                                  n ||           |r|                    |           | j         d= d S )Nc                     d S r?   r   )xs    r   <lambda>z,SimpleT2Decompiler.execute.<locals>.<lambda>   s    T r    r   Top_)r   r   needsDecompilationr   getTokengetattrpopall
setProgram)r   
charStringr  programpushToProgrampushToStackr   token
isOperatorhandlerNamehandlerrvr  s                r   executezSimpleT2Decompiler.execute  s:   :&&&!4466 "7>==!>=!(+
%(11%885*em	= %-KdK..G
'%..R
 #mUmM"""	[[]]]]K!"  "!!!
r    c                 0    | j         d         }| j         d= |S Nr
  r   r   r   s     r   popzSimpleT2Decompiler.pop8  s    

B
%
	,r    c                 <    | j         d d          }g | j         d d <   |S r?   r  r   stacks     r   r  zSimpleT2Decompiler.popall=  s)    

AAA
%$AAA	,r    c                 :    | j                             |           d S r?   )r   r   r  s     r   pushzSimpleT2Decompiler.pushB  s    5!!!!!r    c                     | j         rd S d S r?   r  r   r   s     r   	op_returnzSimpleT2Decompiler.op_returnE  s    	 4 r    c                     d S r?   r   r%  s     r   
op_endcharzSimpleT2Decompiler.op_endcharI      $r    c                     d S r?   r   r%  s     r   	op_ignorezSimpleT2Decompiler.op_ignoreL  r)  r    c                     |                                  }| j        || j        z            }|                     |           d S r?   )r  r   r   r  r   r   	subrIndexsubrs       r   op_callsubrzSimpleT2Decompiler.op_callsubrO  s:    hhjj)	4>1	2$,,tr    c                     |                                  }| j        || j        z            }|                     |           d S r?   )r  r   r   r  r-  s       r   op_callgsubrzSimpleT2Decompiler.op_callgsubrT  s;    hhjj)		)DO3	4$,,tr    c                 .    |                                   d S r?   
countHintsr%  s     r   op_hstemzSimpleT2Decompiler.op_hstemY      //r    c                 .    |                                   d S r?   r4  r%  s     r   op_vstemzSimpleT2Decompiler.op_vstem[  r7  r    c                 .    |                                   d S r?   r4  r%  s     r   
op_hstemhmzSimpleT2Decompiler.op_hstemhm]  r7  r    c                 .    |                                   d S r?   r4  r%  s     r   
op_vstemhmzSimpleT2Decompiler.op_vstemhm_  r7  r    c                     | j         s&|                                  | j        dz   dz  | _         | j        d                             || j                   \  }}||fS )Nr   r   r
  )r  r5  r  r   getBytes)r   r   r  s      r   op_hintmaskzSimpleT2Decompiler.op_hintmaskb  sa    		 2??!+14*2.77t?QRR-		r    c                 l    |                                  }| j        t          |          dz  z   | _        d S Nr.   )r  r  ri   r   argss     r   r5  zSimpleT2Decompiler.countHintsk  s+    	$>CIIN2$...r    c                     t           r?   r@   r%  s     r   op_andzSimpleT2Decompiler.op_andp      r    c                     t           r?   rF  r%  s     r   op_orzSimpleT2Decompiler.op_orr  rH  r    c                     t           r?   rF  r%  s     r   op_notzSimpleT2Decompiler.op_nott  rH  r    c                     t           r?   rF  r%  s     r   op_storezSimpleT2Decompiler.op_storev  rH  r    c                     t           r?   rF  r%  s     r   op_abszSimpleT2Decompiler.op_absx  rH  r    c                     t           r?   rF  r%  s     r   op_addzSimpleT2Decompiler.op_addz  rH  r    c                     t           r?   rF  r%  s     r   op_subzSimpleT2Decompiler.op_sub|  rH  r    c                     t           r?   rF  r%  s     r   op_divzSimpleT2Decompiler.op_div~  rH  r    c                     t           r?   rF  r%  s     r   op_loadzSimpleT2Decompiler.op_load  rH  r    c                     t           r?   rF  r%  s     r   op_negzSimpleT2Decompiler.op_neg  rH  r    c                     t           r?   rF  r%  s     r   op_eqzSimpleT2Decompiler.op_eq  rH  r    c                     t           r?   rF  r%  s     r   op_dropzSimpleT2Decompiler.op_drop  rH  r    c                     t           r?   rF  r%  s     r   op_putzSimpleT2Decompiler.op_put  rH  r    c                     t           r?   rF  r%  s     r   op_getzSimpleT2Decompiler.op_get  rH  r    c                     t           r?   rF  r%  s     r   	op_ifelsezSimpleT2Decompiler.op_ifelse  rH  r    c                     t           r?   rF  r%  s     r   	op_randomzSimpleT2Decompiler.op_random  rH  r    c                     t           r?   rF  r%  s     r   op_mulzSimpleT2Decompiler.op_mul  rH  r    c                     t           r?   rF  r%  s     r   op_sqrtzSimpleT2Decompiler.op_sqrt  rH  r    c                     t           r?   rF  r%  s     r   op_dupzSimpleT2Decompiler.op_dup  rH  r    c                     t           r?   rF  r%  s     r   op_exchzSimpleT2Decompiler.op_exch  rH  r    c                     t           r?   rF  r%  s     r   op_indexzSimpleT2Decompiler.op_index  rH  r    c                     t           r?   rF  r%  s     r   op_rollzSimpleT2Decompiler.op_roll  rH  r    c                     | j         dk    r| j                                        | _         |                                 }|| j         dz   z  }| j        ||z
   d = d S Nr   r   )r  r   getNumRegionsr  r   )r   r   	numBlendsnumOpss       r   op_blendzSimpleT2Decompiler.op_blend  sa    	_\//114?hhjj)!+,&
&*+,,---r    c                 l    |                                  }| j                            |          | _        d S r?   )r  r   ru  r  )r   r   vis      r   
op_vsindexzSimpleT2Decompiler.op_vsindex  s*    xxzz"L..r22$///r    r?   )-r   r   r   r   r   r  r  r  r#  r&  r(  r+  r0  r2  r6  r9  r;  r=  r@  op_cntrmaskr5  rG  rJ  rL  rN  rP  rR  rT  rV  rX  rZ  r\  r^  r`  rb  rd  rf  rh  rj  rl  rn  rp  rr  rx  r{  r   r    r   r   r     s              >  
  
" " "        
  
           3 3 3
                                            
. . .3 3 3 3 3r    r   )rq   rs   rv   rx   r{   r~   r   )r   	closepathr   r   )r   hsbwr   r   r   r   r   )r   
dotsection))r   r   vstem3))r   r.   hstem3))r   r|   seac))r   r   sbwr   ))r   r:   callothersubr))r      r  ))r   !   setcurrentpointc                   B    e Zd ZddZd ZddZd Zd Zd Zd	 Z	d
 Z
dS )T2WidthExtractorNc                 \    t                               | |||           || _        || _        d S r?   )r   r   nominalWidthXdefaultWidthX)r   r   r   r  r  r   s         r   r   zT2WidthExtractor.__init__  s2    dJWEEE$$$$r    c                 V    t                               |            d| _        d| _        d S r   )r   r   gotWidthwidthr  s    r   r   zT2WidthExtractor.reset  s(    4   $-$***r    r   c                     |                                  }| j        sY|t          |          dz  z  r1| 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  ri   r  r  r  )r   evenOddrD  s      r   popallWidthzT2WidthExtractor.popallWidth  s    	$	 TQ $))+b)))#d1g-DJ8DD#DJ4=	+r    c                 l    |                                  }| j        t          |          dz  z   | _        d S rB  )r  r  ri   rC  s     r   r5  zT2WidthExtractor.countHints  s/    					$>CIIN2$...r    c                 .    |                                   d S r?   r  r%  s     r   
op_rmovetozT2WidthExtractor.op_rmoveto      r    c                 0    |                      d           d S Nr   r  r%  s     r   
op_hmovetozT2WidthExtractor.op_hmoveto      1r    c                 0    |                      d           d S r  r  r%  s     r   
op_vmovetozT2WidthExtractor.op_vmoveto  r  r    c                 .    |                                   d S r?   r  r%  s     r   r(  zT2WidthExtractor.op_endchar  r  r    r?   r   )r   r   r   r   r   r  r5  r  r  r  r(  r   r    r   r  r    s        % % % %
  
   3 3 3          r    r  c                   B   e Zd Zd5d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- Z.d. Z/d/ Z0d0 Z1d1 Z2d2 Z3d3 Z4d4 Z5dS )6T2OutlineExtractorNc                 R    t                               | |||||           || _        d S r?   )r  r   pen)r   r  r   r   r  r  r   s          r   r   zT2OutlineExtractor.__init__  s5    [-I I I$(((r    c                 V    t                               |            d| _        d| _        d S )Nr   r   r   )r  r   currentPoint	sawMoveTor  s    r   r   zT2OutlineExtractor.reset  s)    $$...r    c                 T    | j         \  }}||d         z   ||d         z   f}|| _         |S rt  )r  )r   pointr  ys       r   
_nextPointzT2OutlineExtractor._nextPoint  s5    		$!Q
eAh,E!H
$%$	,r    c                 n    | j                             |                     |                     d| _        d S r  )r  moveTor  r  r   r  s     r   rMoveTozT2OutlineExtractor.rMoveTo  s-    (//$//%(()))$...r    c                     | j         s|                     d           | j                            |                     |                     d S Nr  )r  r  r  lineTor  r  s     r   rLineTozT2OutlineExtractor.rLineTo	  sD    	 <<(//$//%(()))))r    c                     | j         s|                     d           | j        }| j                             ||           ||           ||                     d S r  )r  r  r  r  curveTo)r   pt1pt2pt3	nextPoints        r   rCurveTozT2OutlineExtractor.rCurveTo  s]    	 <<o)(99S>>99S>>99S>>BBBBBr    c                 T    | j         r| j                                         d| _         d S r   )r  r  	closePathr  s    r   r  zT2OutlineExtractor.closePath  s+    	^ 8$...r    c                 .    |                                   d S r?   r  r  s    r   endPathzT2OutlineExtractor.endPath  s     ..r    c                 |    |                                   |                     |                                            d S r?   r  r  r  r%  s     r   r  zT2OutlineExtractor.op_rmoveto1  s3    ,,...,,t!!"""""r    c                     |                                   |                     |                     d          d         df           d S )Nr   r   r  r%  s     r   r  zT2OutlineExtractor.op_hmoveto4  s?    ,,...,,  ##A&*+++++r    c                     |                                   |                     d|                     d          d         f           d S rt  r  r%  s     r   r  zT2OutlineExtractor.op_vmoveto7  s?    ,,...,,4##A&&q)*+++++r    c           	         |                                   |                                 }|r[ddlm} |\  }}}}||         }| j                            |d           ||         }	| j                            |	dddd||f           d S d S )Nr   StandardEncodingr   r   r   r   r   r   r   )r  r  $fontTools.encodings.StandardEncodingr  r  addComponent)
r   r   rD  r  adxadybcharachar	baseGlyphaccentGlyphs
             r   r(  zT2OutlineExtractor.op_endchar:  s    ,,...					$	 >DDDDDD !3UE&98$6777!%(;8q!Q3&<=====> >r    c                     |                                  }t          dt          |          d          D ]$}|||dz            }|                     |           %d S )Nr   r.   )r  r   ri   r  )r   r   rD  rd   r  s        r   
op_rlinetozT2OutlineExtractor.op_rlinetoJ  s`    	$CIIq!!  a!A#;5<< r    c                 0    |                      d           d S r  alternatingLinetor%  s     r   
op_hlinetozT2OutlineExtractor.op_hlinetoP      r    c                 0    |                      d           d S r   r  r%  s     r   
op_vlinetozT2OutlineExtractor.op_vlinetoR  r  r    c                     |                                  }t          dt          |          d          D ]3}|||dz            \  }}}}}}	|                     ||f||f||	f           4dS )z${dxa dya dxb dyb dxc dyc}+ rrcurvetor   r|   N)r  r   ri   r  )
r   r   rD  rd   dxadyadxbdybdxcdycs
             r   op_rrcurvetozT2OutlineExtractor.op_rrcurvetoX  s}    	$CIIq!! 5 5a#'!A#; 3S#sC==#sc3Z#s44445 5r    c                    |                                  }t          dt          |          dz
  d          D ]3}|||dz            \  }}}}}}	|                     ||f||f||	f           4|                     |dd                    dS )z-{dxa dya dxb dyb dxc dyc}+ dxd dyd rcurveliner   r.   r|   N)r  r   ri   r  r  )
r   r   rD  rd   r  r  r  r  dxddyds
             r   op_rcurvelinez T2OutlineExtractor.op_rcurveline_  s    	$CIIaK## 5 5a"&q1u+3S#sC==#sc3Z#s4444,,tBCCyr    c                     |                                  }|dd         }t          dt          |          d          D ]"}|                     |||dz                       #|dd         \  }}}}}	}
|                     ||f||f|	|
f           dS )z-{dxa dya}+ dxb dyb dxc dyc dxd dyd rlinecurveNir   r.   )r  r   ri   r  r  )r   r   rD  lineArgsrd   r  r  r  r  r  r  s              r   op_rlinecurvez T2OutlineExtractor.op_rlinecurveg  s    	$#2#Y(CMM1%% ! !a<<1Q3    !%bcc#sCc3--c
S#Jc
33333r    c                     |                                  }t          |          dz  r|d         }|dd         }nd}t          dt          |          d          D ]3}|||dz            \  }}}}|                     ||f||fd|f           d}4dS )z!dx1? {dya dxb dyb dyc}+ vvcurvetor.   r   r   Nr7   r  ri   r   r  )	r   r   rD  dx1rd   r  r  r  r  s	            r   op_vvcurvetozT2OutlineExtractor.op_vvcurvetop  s    	$YY] 	a3
qrr(44	
3CIIq!!  aQqsU3S#==#sc3Z!S222	
33 r    c                     |                                  }t          |          dz  r|d         }|dd         }nd}t          dt          |          d          D ]3}|||dz            \  }}}}|                     ||f||f|df           d}4dS )z!dy1? {dxa dxb dyb dxc}+ hhcurvetor.   r   r   Nr7   r  )	r   r   rD  dy1rd   r  r  r  r  s	            r   op_hhcurvetozT2OutlineExtractor.op_hhcurveto}  s    	$YY] 	a3
qrr(44	
3CIIq!!  aQqsU3S#==#sc3Z#q222	
33 r    c                     |                                  }|r0|                     |          }|r|                     |          }|.dS 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   rD  s      r   op_vhcurvetozT2OutlineExtractor.op_vhcurveto  a     
$ 
--

4
 ==D 	     r    c                     |                                  }|r0|                     |          }|r|                     |          }|.dS dS )zddx1 dx2 dy2 dy3 {dya dxb dyb dxc dxd dxe dye dyf}* dxf?
		{dxa dxb dyb dyc dyd dxe dye dxf}+ dyf?
		N)r  r  r  r  s      r   op_hvcurvetozT2OutlineExtractor.op_hvcurveto  r  r    c                     |                                  \  }}}}}}}dx}	x}
x}}| }|                     ||	f||f||
f           |                     ||f||f||f           d S r   r  r  )r   r   r  dx2dy2dx3dx4dx5dx6r  dy3dy4dy6dy5s                 r   op_hflexzT2OutlineExtractor.op_hflex  s    &*kkmm##sCc3#cC	#--c
S#Jc
333--c
S#Jc
33333r    c                     |                                  \  }}}}}}}}	}
}}}}|                     ||f||f||f           |                     ||	f|
|f||f           d S r?   r  )r   r   r  r  r  r  r  r   r  r  r  r  r  r  fds                  r   op_flexzT2OutlineExtractor.op_flex  st    CG;;==@#sCc3S#sCb--c
S#Jc
333--c
S#Jc
33333r    c           	          |                                  \	  }}}}}}}}	}
dx}}||z   |z   |z   |	z    }|                     ||f||f||f           |                     ||f||	f|
|f           d S r   r  )r   r   r  r  r  r  r  r  r  r  r  r   r  r  s                 r   	op_hflex1zT2OutlineExtractor.op_hflex1  s    04-#sCc3S#-#
)c/C
#
%&#--c
S#Jc
333--c
S#Jc
33333r    c                 H   |                                  \  }}}}}}}}	}
}}||z   |z   |z   |
z   }||z   |z   |	z   |z   }t          |          t          |          k    r|}| }n| }|}|                     ||f||f||f           |                     ||	f|
|f||f           d S 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_flex1  s    9=6#sCc3S#sB
Sy3s""
Sy3s""WWs2ww	3
33
3	3--c
S#Jc
333--c
S#Jc
33333r    c                     t           r?   rF  r%  s     r   rG  zT2OutlineExtractor.op_and  rH  r    c                     t           r?   rF  r%  s     r   rJ  zT2OutlineExtractor.op_or  rH  r    c                     t           r?   rF  r%  s     r   rL  zT2OutlineExtractor.op_not  rH  r    c                     t           r?   rF  r%  s     r   rN  zT2OutlineExtractor.op_store  rH  r    c                     t           r?   rF  r%  s     r   rP  zT2OutlineExtractor.op_abs  rH  r    c                     t           r?   rF  r%  s     r   rR  zT2OutlineExtractor.op_add  rH  r    c                     t           r?   rF  r%  s     r   rT  zT2OutlineExtractor.op_sub  rH  r    c                     |                                  }|                                  }||z  }||z  }||k    r|                     |           d S |                     |           d S r?   )r  r#  )r   r   num2num1d1d2s         r   rV  zT2OutlineExtractor.op_div  s]    	$	$Tz"Dy"2XX99R=====99R=====r    c                     t           r?   rF  r%  s     r   rX  zT2OutlineExtractor.op_load  rH  r    c                     t           r?   rF  r%  s     r   rZ  zT2OutlineExtractor.op_neg  rH  r    c                     t           r?   rF  r%  s     r   r\  zT2OutlineExtractor.op_eq  rH  r    c                     t           r?   rF  r%  s     r   r^  zT2OutlineExtractor.op_drop  rH  r    c                     t           r?   rF  r%  s     r   r`  zT2OutlineExtractor.op_put  rH  r    c                     t           r?   rF  r%  s     r   rb  zT2OutlineExtractor.op_get  rH  r    c                     t           r?   rF  r%  s     r   rd  zT2OutlineExtractor.op_ifelse  rH  r    c                     t           r?   rF  r%  s     r   rf  zT2OutlineExtractor.op_random  rH  r    c                     t           r?   rF  r%  s     r   rh  zT2OutlineExtractor.op_mul  rH  r    c                     t           r?   rF  r%  s     r   rj  zT2OutlineExtractor.op_sqrt  rH  r    c                     t           r?   rF  r%  s     r   rl  zT2OutlineExtractor.op_dup  rH  r    c                     t           r?   rF  r%  s     r   rn  zT2OutlineExtractor.op_exch  rH  r    c                     t           r?   rF  r%  s     r   rp  zT2OutlineExtractor.op_index  rH  r    c                     t           r?   rF  r%  s     r   rr  zT2OutlineExtractor.op_roll  rH  r    c                 ~    |                                  }|D ]%}|r|df}nd|f}|                     |           | }&d S r   )r  r  )r   isHorizontalrD  argr  s        r   r  z$T2OutlineExtractor.alternatingLineto  s`    	$ # #c !HEEHE<<""<<# #r    c                     |d d         \  }}}}|dd          }t          |          dk    r|d         }g }nd}|                     d|f||f||f           |S Nr7   r   r   ri   r  )r   rD  r  r  r  r  r  s          r   r  zT2OutlineExtractor.vcurveto  sp    BQBx#sC	abb$YY!^^	a3
44	
3--C3*sCj111	+r    c                     |d d         \  }}}}|dd          }t          |          dk    r|d         }g }nd}|                     |df||f||f           |S r-  r.  )r   rD  r  r  r  r  r  s          r   r  zT2OutlineExtractor.hcurveto  sp    BQBx#sC	abb$YY!^^	a3
44	
3--a3*sCj111	+r    r?   )6r   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  rG  rJ  rL  rN  rP  rR  rT  rV  rX  rZ  r\  r^  r`  rb  rd  rf  rh  rj  rl  rn  rp  rr  r  r  r  r   r    r   r  r    s          
  
    * * *
C C C  
  0# # #, , ,, , ,> > >       5 5 5  4 4 4        4 4 44 4 44 4 44 4 4                                            # # #	 	 		 	 	 	 	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dS )T1OutlineExtractorc                 J    || _         || _        |                                  d S r?   )r  subrsr   )r   r  r3  s      r   r   zT1OutlineExtractor.__init__  s!    $($***,,,,,r    c                 d    d| _         d| _        d| _        t                              |            d S r   )flexingr  sbxr  r   r  s    r   r   zT1OutlineExtractor.reset  s1    $,$*$(4     r    c                 T    | j         r| j                                         d| _         d S r   )r  r  r  r  s    r   r  zT1OutlineExtractor.endPath$  s+    	^ 8$...r    r   c                 *    |                                  S r?   r  )r   r  s     r   r  zT1OutlineExtractor.popallWidth)      	r    c                 B    | j         }|d         |d         c|d<   |d<   d S )Nr  r
  r  r   s     r   r   zT1OutlineExtractor.exch,  s*    

%rE"I%)U2YYYr    c                     | j         rd S |                                  |                     |                                            d S r?   )r5  r  r  r  r%  s     r   r  zT1OutlineExtractor.op_rmoveto3  s>    	\ 
	6,,...,,t{{}}r    c                     | j         r|                     d           d S |                                  |                     |                                 d         df           d S r   )r5  r#  r  r  r  r%  s     r   r  zT1OutlineExtractor.op_hmoveto8  sW    	\ 
99Q<<<	6,,...,,a !$%%%%%r    c                     | j         r+|                     d           |                                  d S |                                  |                     d|                                 d         f           d S r   )r5  r#  r   r  r  r  r%  s     r   r  zT1OutlineExtractor.op_vmoveto?  sd    	\ 
99Q<<<99;;;	6,,...,,4;;==#$%%%%%r    c                 .    |                                   d S r?   r  r%  s     r   op_closepathzT1OutlineExtractor.op_closepathG  s    ..r    c                 J    |                                  }|\  }}||f| _        d S r?   )r  r  )r   r   rD  r  r  s        r   op_setcurrentpointz%T1OutlineExtractor.op_setcurrentpointI  s*    	$	$!Qd$r    c                 .    |                                   d S r?   )r  r%  s     r   r(  zT1OutlineExtractor.op_endcharN  s    ,,.....r    c                 x    |                                  \  }}|| _        || _        || j        d         f| _        d S r  )r  r  r6  r  )r   r   r6  wxs       r   op_hsbwzT1OutlineExtractor.op_hsbwQ  s<    KKMM'#r$*$(4,Q//$r    c                 .    |                                   d S r?   r9  r%  s     r   op_sbwzT1OutlineExtractor.op_sbwV      ++-----r    c                 r    |                                  }| j        |         }|                     |           d S r?   )r  r3  r  r-  s       r   r0  zT1OutlineExtractor.op_callsubrZ  s3    hhjj)	I	$,,tr    c                     |                                  }|                                  }|dk    r#|dk    r|                                  d| _        d S |dk    r|dk    rd| _        d S d S d S )Nr   rt   r   )r  doFlexr5  )r   r   r.  nArgss       r   op_callothersubrz#T1OutlineExtractor.op_callothersubr^  sl    hhjj)
((**%!^^

;;===4<<<A~~%1**4<<< ~**r    c                     d S r?   r   r%  s     r   op_popzT1OutlineExtractor.op_poph  r)  r    c                 Z   |                                  }|                                  }|                                   |                                  }|                                  }|                                  }|                                  }|                                  }|                                  }|                                  }	|                                  }
|                                  }|                                  }|                                  }|                                  }|                                  }|                                  }|                     ||z              |                     ||z              |                     |           |                     |           |                     |
           |                     |	           |                     d            |                     |           |                     |           |                     |           |                     |           |                     |           |                     |           |                     d            |                     |           |                     |           d S r?   )r  r#  r  )r   finalyfinalxp3yp3xbcp4ybcp4xbcp3ybcp3xp2yp2xbcp2ybcp2xbcp1ybcp1xrpyrpxs                    r   rL  zT1OutlineExtractor.doFlexk  s   88::&88::&((***

#

#
((**%
((**%
((**%
((**%

#

#
((**%
((**%
((**%
((**%

#

# ))E#I))E#I))E))E))C...))C...D ))E))E))E))E))C...))C...D ))F))Fr    c                 .    |                                   d S r?   r9  r%  s     r   op_dotsectionz T1OutlineExtractor.op_dotsection  rI  r    c                 .    |                                   d S r?   r9  r%  s     r   	op_hstem3zT1OutlineExtractor.op_hstem3  rI  r    c           	          ddl m} |                                 \  }}}}}||         }| j                            |d           ||         }	|| j        z   |z
  }| j                            |	dddd||f           dS )zasb adx ady bchar achar seacr   r  r  r   N)r  r  r  r  r  r6  )
r   r   r  asbr  r  r  r  r  r  s
             r   op_seaczT1OutlineExtractor.op_seac  s    CCCCCC $#sCu%)(	#5666 '+dh#(aAq#s%;<<<<<r    c                 .    |                                   d S r?   r9  r%  s     r   	op_vstem3zT1OutlineExtractor.op_vstem3  rI  r    Nr  )r   r   r   r   r   r  r  r   r  r  r  r@  rB  r(  rF  rH  r0  rN  rP  rL  rc  re  rh  rj  r   r    r   r1  r1    sU         
! ! !  
   . . .  
& & && & &    
  0 0 0
        ( ( (T    = = =    r    r1  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 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 dS )T2CharStringNc                 \    |g }|| _         || _        || _        ||ng | _        d | _        d S r?   )bytecoder  r   r   _cur_vsindex)r   rn  r  r   r   s        r   r   zT2CharString.__init__  s@    _7$-$,$,$/$;[[$$r    c                     | j         }|J ||| _        n%| j        t          |d          r|j        nd| _        |                    | j                  S )Nr   r   )r   ro  hasattrr   ru  )r   r   pds      r   ru  zT2CharString.getNumRegions  s`    |"	4 %,R%;%;Brzz4			$+	,	,,r    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>)rn  	__class__r   idr  s    r   __repr__zT2CharString.__repr__  s@    	]
4>#:BtHH"E
EE
!T^%<bhh$G
GGr    c                     t           S r?   )r   r  s    r   r   zT2CharString.getIntEncoder      	r    c                     t           S r?   )r   r  s    r   getFixedEncoderzT2CharString.getFixedEncoder  rx  r    c                     |                                  sd S t          | j        dg           }|                     || j        | j                  }|                    |            d S NSubrs)r  r  r   decompilerClassr   r  )r   r3  
decompilers      r   	decompilezT2CharString.decompile  sd    		 	 	"	" 
	6
$,
,
,%##E4+;T\JJ*Tr    c                     t          | j        dg           }|                     ||| j        | j        j        | j        j        | j                  }|                    |            |j        | _        d S r|  )r  r   outlineExtractorr   r  r  r  r  )r   r  r3  	extractors       r   drawzT2CharString.draw  sj    
$,
,
,%##C0@L :L ) D$***r    c                 X    t          |          }|                     |           |j        S r?   )r   r  bounds)r   glyphSet	boundsPens      r   
calcBoundszT2CharString.calcBounds  s*    !!)))I		r    Fc                    | j         d S | j        }| j        }|r|r|d         dv r
|d d         }n,|r*t          |d         t                    st          d          g }|                                 }|                                 }d}t          |          }||k     r||         }	|dz   }t          |	t                    rl	 |	                    d ||	         D                        n # t          $ r t          d|	z            w xY w|	dv r |                    ||                    |dz   }nt          |	t                    r|                     ||	                     nNt          |	t                    r|                     ||	                     nJ d	t          |	          z              ||k     	 t          |          }n)# t           $ r t"                              |            w xY w|                     |           d S )
Nr
  )r   r   z@T2CharString or Subr has items on the stack after last operator.r   r   c              3   4   K   | ]}t          |          V  d S r?   )r   )rc   rJ   s     r   	<genexpr>z'T2CharString.compile.<locals>.<genexpr>  s(      88AWQZZ888888r    zillegal operator: %sr   r   zunsupported type: %s)rn  opcodesr  rj   strr   r   rz  ri   extendr   r   intrH   typer   	TypeErrorr   errorsetBytecode)
r   isCFF2r  r  rn  r   r   rd   endr  s
             r   compilezT2CharString.compile  sV   	]	6L'L'  '"+!666crclG z'"+s33 	F
 
  (  "")$$&&+!G#	C1:51u1 3B__888888888 B B B!"85"@AAAB(((__WQZ   	
QQ5# 3OOIIe$$%%%%5%   3OOKK&&''''2$tE{{2222! 	
C"	!!88	 	 	 	99X	 8s   %C( (D7G &G-c                     | j         d uS r?   )rn  r  s    r   r  zT2CharString.needsDecompilation
  s    	d	""r    c                 "    || _         d | _        d S r?   )r  rn  )r   r  s     r   r  zT2CharString.setProgram  s    $,$---r    c                 "    || _         d | _        d S r?   )rn  r  )r   rn  s     r   r  zT2CharString.setBytecode  s    $-$,,,r    c                 6   | j         U| || j                   k    rdS  || j         |                   }|dz   }| j        |         } || || j         |          \  }}n(| || j                  k    rdS | j        |         }|dz   } ||t                    }|||fS )N)Nr   r   r   )rn  operandEncodingr  r  )	r   r   ri   r   rj   r   r  r  r  s	            r   r  zT2CharString.getToken  s    	]ss4=!!!!:e$%%2195!"%7'$DM599<5%%ss4<    :<5195z%%%*	
E	!!r    c                     | j         ||z   }| j         ||         }|}n| j        |         }|dz   }t          |          |k    sJ ||fS r  )rn  r  ri   )r   r   nBytesnewIndexbytess        r   r?  zT2CharString.getBytes&  s`    	]fn8=x(555<5195	Uv					r    c                     |S r?   r   )r   r   s     r   r   zT2CharString.handle_operator1  s    	/r    c                    ddl m} | j        |                    | j                   d S d}g }	 |                     |          \  }}}|n|r|dv rv|                     |          \  }}}g }	|D ].}
|	                     |t          |
          d                     /t          |	          }d                    |||gz             }nd                    ||gz             }|	                    |           |
                                 g }nKt          |t                    rt          |d          }nt          |          }|                    |           +|r,d                    |          }|	                    |           d S d S )	Nr   )
num2binaryTr  r    r:   r;   )fontTools.misc.textToolsr  rn  dumphexr  r   r   r   joinwritenewlinerj   rH   r	   r  )r   	xmlWriterttFontr  r   rD  r  r  hintMaskbitsbytelines               r   toXMLzT2CharString.toXML4  s   111111	]T]#####5
4#}}U33E:u}
 )))$(MM%$8$8!h
Ed 1 1${{::gdmmQ//0000hXXdeX..//ddXXdeWn%%d__TTT5%   R888ee%jje	[[-.   88D>>DOOD r    c                 0   ddl m}m} |                    d          r |                      ||                     d S t          |          }|                                }g }t          |          }d}||k     r||         }	|dz   }	 t          |	          }	|	                    |	           n# t          $ r 	 t          |	d          }	|	                    |	           n# t          $ r |	                    |	           |	dv rk||         }
d}t          dt          |
          d	          D ](}|t           ||
||d	z                                z   })|	                    |           |dz   }Y nw xY wY nw xY w||k     |                     |           d S )
Nr   )
binary2numreadHexrawr   r:   r;   r  r    r   )r  r  r  r   r  r   splitri   r  r   
ValueErrorr
   r   r   r  )r   nameattrscontentr  r  r  r  rd   r  mask	maskBytesjs                r   fromXMLzT2CharString.fromXMLY  s   ::::::::
YYu 
GGG$$%%%	6G'MMOO''G#!	C1:51u1JJE  NN5    uB777U ^^E    ^^E)))QZdiQD		1%% @ @!wzz$q1u+'>'>???yynnY
a%a 	
C* //'s7   	B. .
E79C 
E7 BE1.E70E11E76E7)NNNNr?   )F)!r   r   r   t2OperandEncodingr  rp   t2Operatorsr   r  r   r~  r  r  r   ru  rv  r   rz  r  r  r  r  r  r  r  ri   r   rj   r  r?  r   r  r  r   r    r   rl  rl    s_       $''44G%&   - - - -H H H          
* * * *X# # #    
 G
" " " ""	 	 	  # # # #J    r    rl  c                   X     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 )T1CharStringNc                 Z    t                                          ||           || _        d S r?   )superr   r3  )r   rn  r  r3  rt  s       r   r   zT1CharString.__init__  s(    ''8W%%%$***r    c                     t           S r?   )encodeIntT1r  s    r   r   zT1CharString.getIntEncoder  rx  r    c                     d }d S )Nc                      t          d          )Nz8Type 1 charstrings don't support floating point operands)r  )r   s    r   r   z1T1CharString.getFixedEncoder.<locals>.encodeFixed  s    	M	N	NNr    r   )r   r   s     r   rz  zT1CharString.getFixedEncoder  s     O O O O Or    c                     | j         d S g }d}	 |                     |          \  }}}|n|                    |           2|                     |           d S r   )rn  r  r   r  )r   r  r   r  r  s        r   r  zT1CharString.decompile  so    	]	6'
%"mmE225*em	
>>%	
 //'r    c                 r    t          || j                  }|                    |            |j        | _        d S r?   )r1  r3  r  r  )r   r  r  s      r   r  zT1CharString.draw  s4     dj11)D$***r    )NNN)r   r   r   t1OperandEncodingr  rp   t1Operatorsr   r  r   r   rz  r  r  __classcell__)rt  s   @r   r  r  z  s        $''44G       O O O
 
 
      r    r  c                   \    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dS )DictDecompilerNc                 >    g | _         || _        i | _        || _        d S r?   )r!  stringsdictparent)r   r  r  s      r   r   zDictDecompiler.__init__  s"    $*$,$)$+++r    c                 T    t          | j                  dk    s
J d            | j        S )Nr   znon-empty stack)ri   r!  r  r  s    r   getDictzDictDecompiler.getDict  s,    	TZA			0				r    c                     d}t          |          }| j        j        }||k     rMt          ||                   }|dz   }| j        |         } || |||          \  }}| ||           ||k     Kd S d S rt  )ri   r!  r   r   r  )r   r   r   lenDatar#  r   r  r   s           r   r  zDictDecompiler.decompile  s    
%II'		$U2195!"%7'$D%00<5%DKKK 	r    c                 0    | j         d         }| j         d= |S r  r!  r  s     r   r  zDictDecompiler.pop  s    
*R.%
jn	,r    c                 8    | j         d d          }| j         d d = |S r?   r  rC  s     r   r  zDictDecompiler.popall  s#    	AAA$
jm	+r    c                 p   |\  }}t          |t                    rQd}t          t          |          dz
  dd          D ],}||         }t	          | d|z             } ||          f|z   }-nt	          | d|z             } ||          }|dk    r| j                            |           d S || j        |<   d S )Nr   r   r
  arg_r   )rj   rk   r   ri   r  r!  r  r  )r   r   argTyper   rd   r+  
arghandlers          r   r   zDictDecompiler.handle_operator  s    (G  5#g,,q."b)) , ,q
!*Cv|,,JZ!!#e+EE,
 fw.//::h5:U49Xr    c                     t          | j        d         t                    r|                     | j                  }n|                                 }|S r   )rj   r!  listarg_blend_numberr  )r   r  outs      r   
arg_numberzDictDecompiler.arg_number  sC    
1t$$ 			tz	*	*33	3	*r    c                     g }|                                  }t          |          }|                    |           |                    d           |                                 }|S )Nr   )r  ri   r   r  )r   r  r  	blendArgs
numMastersdummys         r   r  zDictDecompiler.arg_blend_number  sV    
#hhjj)9~~***Y**W
++--%	r    c                 @    | j         |                                          S r?   )r  r  r   r  s     r   arg_SIDzDictDecompiler.arg_SID  s    	dhhjj	!!r    c                 *    |                                  S r?   r9  r  s     r   	arg_arrayzDictDecompiler.arg_array  r:  r    c                    | j                             dd          }| j                            |          dz   }|                                 }|                                 }t          |          }|||z  k    sJ dg|z  }|dz
  }d}	d}
|	|k     r6||	         |
z   }|}
||	|z  z   }|g||||z            z   }|||	<   |	dz  }	|	|k     6|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  ru  r  r  ri   )r   r  r   r  rv  rD  numArgsr   	numDeltasrd   prevValnewValmasterOffset	blendLists                 r   arg_blendListzDictDecompiler.arg_blendList  s     IMM)Q'''{((11A5*hhjj)	$II'	J*	*	*	*	*&
%l)!'	IGg67q)|,<x$|L,BBCC95861 	
I 
,r    c                     |                                  }g }|rt          |d         t                    r|}n!d}|D ]}||z   }|                    |           |S r   )r  rj   r  r   )r   r  	valueListr  currentre   s         r   	arg_deltazDictDecompiler.arg_delta  so    kkmm)
# :ilD11 	337  qkGJJw	*r    r?   )r   r   r   cffDictOperandEncodingr  r   r  r  r  r  r   r  r  r  r  r  r  r   r    r   r  r    s        )     
 
 
  
  
       " " "    @    r    r  c                 L    t          |           }|dk     rd}n|dk     rd}nd}|S )Ni  r   il  r   i   )ri   )r3  nSubrsbiass      r   r   r     s7    
e**
TMM	$$unn	$$	$r    )9__doc__fontTools.misc.py23r   r   r   r   fontTools.misc.fixedToolsr   r   r	   r
   fontTools.pens.boundsPenr   r0   logging	getLoggerr   r   r   r   r(   r+   r3   r8   r=   rB   rM   r  ri   r  r  rG   	enumerater   
maxOpStackrp   r  r   encodeIntCFFr  r   r   r   r   r   	Exceptionr   objectr   r  r  r  r1  rl  r  r  r   r   r    r   <module>r     s    E D D D D D D D D D D D            / . . . . .   g!!    ) ) )* * *    7 7 7      FSL -0 !B$ %)4 "S& 'N+;; #c' 'N+;; #c' % # 
s$$$$%aaa( % " ' # *111- ) r , r + s   99))K"8"8999
  8 8 8t( ( (V }U##mD!!mD!! % % % % ggcll*
 
 
@ . - - - -Y - - -`3 `3 `3 `3 `3 `3 `3 `3F  <' ' ' ' ') ' ' 'Tb b b b b) b b bH	L L L L L+ L L L\S S S S S6 S S Sj    <   Br r r r rV r r rj    r    