+
    i1                        R t ^ RIt^ RIt^ RIHtHtHtHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt ^ RItR.t ! R R]4      t]P8                  ! R4      t]]]P>                  3,          t R R lt!R R lt"R R lt#R R lt$R R lt%]3R R llt&R]/R R llt'R R lt(R.R! R" llt)R# R$ lt*R% R& lt+R'R /R( R) llt,R/R'R /R* R+ lllt-R0R, lt.]/R-8X  d
   ].! 4        R# R# )1zySimplify TrueType glyphs by merging overlapping contours/components.

Requires https://github.com/fonttools/skia-pathops
N)CallableIterableOptionalMapping)
CFFFontSet)ttFont)_g_l_y_f)_h_m_t_x)T2CharString)otRoundnoRound)
TTGlyphPen)T2CharStringPenremoveOverlapsc                       ] tR t^tRtR# )RemoveOverlapsError N)__name__
__module____qualname____firstlineno____static_attributes__r       ~/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/fontTools/ttLib/removeOverlaps.pyr   r      s    r   r   zfontTools.ttLib.removeOverlapsc                P    V ^8  d   QhR\         R\        R\        P                  /# )   	glyphNameglyphSetreturn)str_TTGlyphMappingpathopsPath)formats   "r   __annotate__r$   "   s%      s o ',, r   c                     \         P                  ! 4       pVP                  VR 7      pW,          P                  V4       V# )r   )r!   r"   getPendraw)r   r   pathpathPens   &&  r   skPathFromGlyphr+   "   s3    <<>Dkk8k,GW%Kr   c                D    V ^8  d   QhR\         P                  R\        /# )r   	componentr   )r   GlyphComponentr    )r#   s   "r   r$   r$   )   s"     + +&&+2A+r   c                 \    V P                  4       w  r#\        W!4      pVP                  ! V!  # N)getComponentInfor+   	transform)r-   r   baseGlyphNametransformationr)   s   &&   r   skPathFromGlyphComponentr5   )   s.     %.$>$>$@!M=3D>>>**r   c                P    V ^8  d   QhR\         P                  R\        R\        /# )r   glyphr   r   )r   Glyphr    bool)r#   s   "r   r$   r$   1   s%      X^^  4 r   c           
        a aaa S P                  4       '       g   \        R 4      h\        S P                  4      ^8  d   R# / oR VV V3R llo\        ;QJ dP    V3R l\
        P                  ! \        \        S P                  4      4      ^4       4       F  '       g   K   R# 	  R# ! V3R l\
        P                  ! \        \        S P                  4      4      ^4       4       4      # )z5This method only works with TrueType composite glyphsFc                D    V ^8  d   QhR\         R\        P                  /# )r   indexr   )intr!   r"   )r#   s   "r   r$   'componentsOverlap.<locals>.__annotate__9   s     & &s &w|| &r   c                 d   < V S9  d!   \        SP                  V ,          S4      SV &   SV ,          # r0   )r5   
components)r<   component_pathsr7   r   s   &r   _get_nth_component_path2componentsOverlap.<locals>._get_nth_component_path9   s7    '%=  '&OE" u%%r   c           	   3      <"   T FF  w  r\         P                  ! S! V4      S! V4      \         P                  P                  R R R7      x  KH  	  R# 5i)F)fix_windingkeep_starting_pointsN)r!   opPathOpINTERSECTION).0ijrB   s   &  r   	<genexpr>$componentsOverlap.<locals>.<genexpr>@   sQ      	 LDA 	

#A&#A&NN''!&	
 	
 Ls   AAT)isComposite
ValueErrorlenr@   any	itertoolscombinationsrange)r7   r   rB   rA   s   ff@@r   componentsOverlaprV   1   s    PQQ
5q O& & 3 	 **5U5E5E1F+GK	33 	3 	3 	 **5U5E5E1F+GK	 	 	r   c                X    V ^8  d   QhR\         P                  R\        P                  /# )r   r)   r   )r!   r"   r   r8   )r#   s   "r   r$   r$   L   s"      W\\ hnn r   c                     \        R R7      pV P                  V4       VP                  4       pVP                  4       '       d   Q hVP	                  R R7       V# )Nr&   )	glyfTable)r   r(   r7   rO   recalcBounds)r)   ttPenr7   s   &  r   ttfGlyphFromSkPathr\   L   sN    %EIIeKKME  """"	&Lr   c                P    V ^8  d   QhR\         P                  R\        R\        /# )r   r)   
charStringr   )r!   r"   r
   )r#   s   "r   r$   r$   W   s-     	K 	K
,,	K$0	K	Kr   c                 (   VP                   VP                  P                  8X  d   R pM'VP                   VP                  P                  ,
          p\	        VR R7      pV P                  V4       VP                  VP                  VP                  4      # )N)widthr   )r`   privatedefaultWidthXnominalWidthXr   r(   getCharStringglobalSubrs)r)   r^   r`   t2Pens   &&  r   _charString_from_SkPathrg   W   sv     :--;;;  :#5#5#C#CC%$7EIIez11:3I3IJJr   c                    V ^8  d   QhR\         P                  R\        \        .\        3,          R\         P                  /# )r   r)   roundr   )r!   r"   r   float)r#   s   "r   r$   r$   c   s7      
,,'7\\r   c                    a \         P                  ! 4       pV  F#  w  r4VP                  ! V.V3R  lV 4       O5!   K%  	  V# )c              3   `   <"   T F#  pS! V^ ,          4      S! V^,          4      3x  K%  	  R# 5i)    Nr   )rJ   pri   s   & r   rM   _round_path.<locals>.<genexpr>h   s&      LV%!+uQqT{!;Vs   +.)r!   r"   add)r)   ri   rounded_pathverbpointss   &f   r   _round_pathrt   c   s;     <<>LM LV LM r   ri   c                    V ^8  d   QhR\         P                  R\        R\        \        .\        3,          R\         P                  /# )r   r)   debugGlyphNameri   r   )r!   r"   r   r   rj   )r#   s   "r   r$   r$   l   sC     $( $(
,,$($( UGUN#	$(
 \\$(r   c                    \         P                  ! W P                  R 7      #   \         P                   d     Mi ; i\	        YR7      p  \         P                  ! Y P                  R 7      p \
        P                  RT4       T #   \         P                   dO   p\
        P                  \        P                  4      '       d   T P                  4        \        RT: 24      ThRp?ii ; i))	clockwiseri   zkskia-pathops failed to simplify '%s' with float coordinates, but succeded using rounded integer coordinatesz%Failed to remove overlaps from glyph N)r!   simplifyrx   PathOpsErrorrt   logdebugisEnabledForloggingDEBUGdumpr   AssertionError)r)   rv   ri   es   &&$ r   	_simplifyr   l   s    ??  t)D?		=	

  GMM**IIK!3N3EF
	s%    # ;;8B C'A	C""C'c                d    V ^8  d   QhR\         P                  R\         P                  R\        /# )r   path1path2r   )r!   r"   r9   )r#   s   "r   r$   r$      s.     T Tgll T7<< TD Tr   c                     V P                    Uu0 uF  p\        V4      kK  	  upVP                    Uu0 uF  p\        V4      kK  	  up8H  # u upi u upi r0   )contourstuple)r   r   cs   && r   
_same_pathr      sA    #nn-nE!Hn-ENN1SNq%(N1SSS-1Ss
   AATc                    V ^8  d   QhR\         R\        R\        P                  R\        P
                  R\        R\        /# )r   r   r   rY   	hmtxTableremoveHintingr   )r   r    r   table__g_l_y_fr	   table__h_m_t_xr9   )r#   s   "r   r$   r$      sP           &&  &&	 
   
 r   c                    W ,          pVP                   ^ 8  g(   VP                  4       '       d   \        WQ4      '       dv   \        W4      p\	        W`4      p\        Wg4      '       gO   \        V4      ;W &   pVP                  '       d   Q hW0,          w  rWP                  8w  d   WP                  3W0&   R# V'       d   VP                  4        R# )rm   TF)
numberOfContoursrO   rV   r+   r   r   r\   programxMinr   )
r   r   rY   r   r   r7   r)   r   r`   lsbs
   &&&&&     r   removeTTGlyphOverlapsr      s      E 	"e..y3 $* $&&+=e+DDI 5}}}$$"-JEjj (-zz':	$r   c                    V ^8  d   QhR\         P                  R\        \        ,          R\        R\
        R\
        RR/# )r   font
glyphNamesr   r   ignoreErrorsr   Nr   TTFontr   r   r    r9   )r#   s   "r   r$   r$      sV     %X %X
--%X %X 	%X
 %X %X 
%Xr   c                   a V R ,          oV R,          p\        VV3R lR7      p\        4       pV F*  p \        WrSWS4      '       d   VP                  V4       K*  K,  	  \
        P                  R\        V4      RP                  V4      4       R#   \         d$    T'       g   h \
        P                  RT4        K  i ; i)glyfhmtxc                    < SV ,          P                  4       '       d%   SV ,          P                  S4      P                  V 3# ^ V 3# )rm   )rO   getCompositeMaxpValuesmaxComponentDepth)namerY   s   &r   <lambda>'_remove_glyf_overlaps.<locals>.<lambda>   sI     T?..00 $66yASS 
 
r   )key"Failed to remove overlaps for '%s'"Removed overlaps for %s glyphs:
%s N)
sortedsetr   rp   r   r|   errorr}   rQ   join)	r   r   r   r   r   r   modifiedr   rY   s	   $$$$$   @r   _remove_glyf_overlapsr      s     VIVI
 

J uH		G$Y	  Y'   II3S]CHHXDVW # 	GII:IF	Gs   $BB>#B>=B>c                H    V ^8  d   QhR\         R\        R\        R\        /# )r   r   r   
cffFontSetr   )r   r    r   r9   )r#   s   "r   r$   r$      s2        	
 
r   c                     \        W4      p\        W0\        R 7      p\        W44      '       g*   V^ ,          P                  p\        WEV ,          4      WP&   R# R# )ry   TF)r+   r   r   r   CharStringsrg   )r   r   r   r)   r   charStringss   $$$   r   _remove_charstring_overlapsr      sP     9/D dW5E d"" m//!8I@V!Wr   removeUnusedSubroutinesc                    V ^8  d   QhR\         P                  R\        \        ,          R\        R\
        R\
        R\        R\
        RR	/# )
r   r   r   r   r   r   	table_tagr   r   Nr   )r#   s   "r   r$   r$      sl     #X #X
--#X #X 	#X
 #X #X #X "#X 
#Xr   c                    W,          P                   p\        4       pV F+  p	 \        V	VVR 7      '       d   VP                  V	4       K+  K-  	  V'       g   \
        P                  R4       R# V'       d   VP                  4        V'       d   VP                  4        \
        P                  R\        V4      RP                  V4      4       R#   \         d$    T'       g   h \
        P                  RT	4        K  i ; i))r   r   r   r   z-No overlaps found in the specified CFF glyphsNr   r   )cffr   r   rp   r   r|   r   r}   remove_hintsremove_unused_subroutinesrQ   r   )
r   r   r   r   r   r   r   r   r   r   s
   $$$$$$$   r   _remove_cff_overlapsr      s     $$JuH	
	G*#!% 
 Y'   		AB!,,.II3S]CHHXDVW # 	GII:IF	Gs   %CC<!C<;C<c                    V ^8  d   QhR\         P                  R\        \        \        ,          ,          R\
        R\
        R\
        RR/# )r   r   r   r   r   r   r   N)r   r   r   r   r   r9   )r#   s   "r   r$   r$     sQ     <
 <

--<
#'<
 <
 	<
 "<
 
<
r   c          
        RV 9  d   RV 9  d   RV 9  d   \        R4      hVf   V P                  4       pV P                  4       pRV 9   d   \        V VVVVR7       RV 9   g   RV 9   d   \	        T TTTTRV 9   d   RMRVR7       R# R# )aJ  Simplify glyphs in TTFont by merging overlapping contours.

Overlapping components are first decomposed to simple contours, then merged.

Currently this only works for fonts with 'glyf' or 'CFF ' tables.
Raises NotImplementedError if 'glyf' or 'CFF ' tables are absent.

Note that removing overlaps invalidates the hinting. By default we drop hinting
from all glyphs whether or not overlaps are removed from a given one, as it would
look weird if only some glyphs are left (un)hinted.

Args:
    font: input TTFont object, modified in place.
    glyphNames: optional iterable of glyph names (str) to remove overlaps from.
        By default, all glyphs in the font are processed.
    removeHinting (bool): set to False to keep hinting for unmodified glyphs.
    ignoreErrors (bool): set to True to ignore errors while removing overlaps,
        thus keeping the tricky glyphs unchanged (fonttools/fonttools#2363).
    removeUnusedSubroutines (bool): set to False to keep unused subroutines
        in CFF table after removing overlaps. Default is to remove them if
        any glyphs are modified.
r   zCFF CFF2zJNo outline data found in the font: missing 'glyf', 'CFF ', or 'CFF2' tableN)r   r   r   r   r   )r   r   r   r   r   r   r   )NotImplementedErrorgetGlyphOrdergetGlyphSetr   r   )r   r   r   r   r   r   s   &&&&$ r   r   r     s    > TfD0V45G!X
 	
 '')
 !H~!'%	
 ~4!'% &$fF$;	
 (r   c           
        ^ RI pVP                  R\        R7      pVP                  RRRR7       VP                  RR	R
R7       VP                  RRRRR7       VP                  RRRR7       VP                  RRRR7       VP                  RRRR7       VP	                  V 4      p \
        P                  ! V P                  4      ;_uu_ 4       p\        TV P                  ;'       g    RV P                  '       * V P                  V P                  '       * R7       VP                  V P                  4       RRR4       R#   + '       g   i     R# ; i)z:Simplify glyphs in TTFont by merging overlapping contours.Nzfonttools ttLib.removeOverlaps)descriptioninputz	INPUT.ttfzInput font file)metavarhelpoutputz
OUTPUT.ttfzOutput font fileglyphsGLYPHS*z4Optional list of glyph names to remove overlaps from)r   nargsr   z--keep-hinting
store_truez>Keep hinting for unmodified glyphs, default is to drop hinting)actionr   z--ignore-errorszOignore errors while removing overlaps, thus keeping the tricky glyphs unchangedz--keep-unused-subroutineszrKeep unused subroutines in CFF table after removing overlaps, default is to remove them if any glyphs are modified)r   r   r   r   r   )argparseArgumentParser__doc__add_argument
parse_argsr   r   r   r   r   keep_hintingignore_errorskeep_unused_subroutinessaver   )argsr   parserr   s   &   r   mainr   [  sO    $$(g % F ;LM
,=OP
C	   M  
 3   #?   T"D	tzz	"	"d{{**d"///++(,(D(D$D	
 			$++ 
#	"	"	"s   A(E  E	__main__)T)NTFr0   )0r   rS   r   typingr   r   r   r   fontTools.cffLibr   fontTools.ttLibr   fontTools.ttLib.tablesr   r	   fontTools.misc.psCharStringsr
   fontTools.misc.roundToolsr   r   fontTools.pens.ttGlyphPenr   fontTools.pens.t2CharStringPenr   r!   __all__	Exceptionr   	getLoggerr|   r   _TTGlyphr    r+   r5   rV   r\   rg   rt   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s   
   8 8 ' " + + 5 6 0 :  
	) 	 89#v./+6	K ;B$( '.	$(NT F%XP(#X %)#XL<
 %)<
 <
~,^ zF r   