+
    f7i1  c                   s   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                   s    ] tR t^tRtR# )RemoveOverlapsError N)__name__Z
__module__Z__qualname__Z__firstlineno__Z__static_attributes__r       E/usr/lib64/python3.14/site-packages/fontTools/ttLib/removeOverlaps.pyr   r      s    r   r   zfontTools.ttLib.removeOverlapsc                sP    V ^8  d   QhR\         R\        R\        P                  /# )   	glyphNameglyphSetreturn)str_TTGlyphMappingpathopsPathZformat   "r   __annotate__r   "   s%      s o ',, r   c                 s    \         P                  ! 4       pVP                  VR 7      pW,          P                  V4       V# )r   )r   r   ZgetPendraw)r   r   pathZpathPen   &&  r   skPathFromGlyphr"   "   s3    <<>Dkk8k,GW%Kr   c                sD    V ^8  d   QhR\         P                  R\        /# )r   	componentr   )r   ZGlyphComponentr   r   r   r   r   r   )   s"     + +&&+2A+r   c                 s\    V P                  4       w  r#\        W!4      pVP                  ! V!  # N)ZgetComponentInfor"   Z	transform)r#   r   ZbaseGlyphNameZtransformationr    s   &&   r   skPathFromGlyphComponentr%   )   s.     %.$>$>$@!M=3D>>>**r   c                sP    V ^8  d   QhR\         P                  R\        R\        /# )r   glyphr   r   )r   Glyphr   boolr   r   r   r   r   1   s%      X^^  4 r   c           
      s  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                sD    V ^8  d   QhR\         R\        P                  /# )r   indexr   )Zintr   r   r   r   r   r   Z'componentsOverlap.<locals>.__annotate__9   s     & &s &w|| &r   c                 sd   < V S9  d!   \        SP                  V ,          S4      SV &   SV ,          # r$   )r%   
components)r)   component_pathsr&   r   s   &r   _get_nth_component_pathZ2componentsOverlap.<locals>._get_nth_component_path9   s7    '%=  '&OE" u%%r   c           	   3   s   <"   T FF  w  r\         P                  ! S! V4      S! V4      \         P                  P                  R R R7      x  KH  	  R# 5i)F)Zfix_windingZkeep_starting_pointsN)r   ZopZPathOpZINTERSECTION).0ZiZjr,   s   &  r   	<genexpr>Z$componentsOverlap.<locals>.<genexpr>@   sQ      	 LDA 	

#A&#A&NN''!&	
 	
 Ls   AAT)isCompositeZ
ValueErrorlenr*   Zany	itertoolsZcombinationsZrange)r&   r   r,   r+   s   ff@@r   componentsOverlapr2   1   s    PQQ
5q O& & 3 	 **5U5E5E1F+GK	33 	3 	3 	 **5U5E5E1F+GK	 	 	r   c                sX    V ^8  d   QhR\         P                  R\        P                  /# )r   r    r   )r   r   r   r'   r   r   r   r   r   L   s"      W\\ hnn r   c                 s    \        R R7      pV P                  V4       VP                  4       pVP                  R R7       V# )Nr   )	glyfTable)r   r   r&   ZrecalcBounds)r    ZttPenr&   s   &  r   ttfGlyphFromSkPathr4   L   s;    %EIIeKKME 
&Lr   c                sP    V ^8  d   QhR\         P                  R\        R\        /# )r   r    
charStringr   )r   r   r   r   r   r   r   r   W   s-     	K 	K
,,	K$0	K	Kr   c                 s(   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   )r6   ZprivateZdefaultWidthXZnominalWidthXr   r   ZgetCharStringZglobalSubrs)r    r5   r6   Zt2Penr!   r   _charString_from_SkPathr7   W   sv     :--;;;  :#5#5#C#CC%$7EIIez11:3I3IJJr   c                s    V ^8  d   QhR\         P                  R\        \        .\        3,          R\         P                  /# )r   r    roundr   )r   r   r    floatr   r   r   r   r   c   s7      
,,'7\\r   c                 s   a \         P                  ! 4       pV  F#  w  r4VP                  ! V.V3R  lV 4       O5!   K%  	  V# )c              3   s`   <"   T F#  pS! V^ ,          4      S! V^,          4      3x  K%  	  R# 5i)    Nr   )r-   Zpr8   s   & r   r.   Z_round_path.<locals>.<genexpr>h   s&      LV%!+uQqT{!;Vs   +.)r   r   add)r    r8   Zrounded_pathZverbZpointss   &f   r   _round_pathr<   c   s;     <<>LM LV LM r   r8   c                s    V ^8  d   QhR\         P                  R\        R\        \        .\        3,          R\         P                  /# )r   r    debugGlyphNamer8   r   )r   r   r   r    r9   r   r   r   r   r   l   sC     $( $(
,,$($( UGUN#	$(
 \\$(r   c                s    \         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r8   zkskia-pathops failed to simplify '%s' with float coordinates, but succeded using rounded integer coordinatesz%Failed to remove overlaps from glyph N)r   Zsimplifyr>   ZPathOpsErrorr<   logdebugZisEnabledForloggingZDEBUGZdumpr   ZAssertionError)r    r=   r8   Zes   &&$ r   	_simplifyrC   l   s    ??  t)D?		=	

  GMM**IIK!3N3EF
	s%    # ;;8B C'A	C""C'c                sd    V ^8  d   QhR\         P                  R\         P                  R\        /# )r   path1path2r   )r   r   r(   r   r   r   r   r      s.     T Tgll T7<< TD Tr   c                 s    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 r$   )ZcontoursZtuple)rD   rE   Zcs   && r   
_same_pathrF      sA    #nn-nE!Hn-ENN1SNq%(N1SSS-1Ss
   AATc                s    V ^8  d   QhR\         R\        R\        P                  R\        P
                  R\        R\        /# )r   r   r   r3   	hmtxTableremoveHintingr   )r   r   r   Ztable__g_l_y_fr   Ztable__h_m_t_xr(   r   r   r   r   r      sP           &&  &&	 
   
 r   c                 sx   W ,          pVP                   ^ 8  g(   VP                  4       '       ds   \        WQ4      '       db   \        W4      p\	        W`4      p\        Wg4      '       g;   \        V4      ;W &   pW0,          w  rWP                  8w  d   WP                  3W0&   R# V'       d   VP                  4        R# )r:   TF)	ZnumberOfContoursr/   r2   r"   rC   rF   r4   ZxMinrH   )
r   r   r3   rG   rH   r&   r    rE   r6   Zlsbs
   &&&&&     r   removeTTGlyphOverlapsrI      s      E 	"e..y3 $* $&&+=e+DDI 5 #-JEjj (-zz':	$r   c                s    V ^8  d   QhR\         P                  R\        \        ,          R\        R\
        R\
        RR/# )r   font
glyphNamesr   rH   ignoreErrorsr   Nr   TTFontr   r   r   r(   r   r   r   r   r      sV     %X %X
--%X %X 	%X
 %X %X 
%Xr   c                 s  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)glyfZhmtxc                 s   < SV ,          P                  4       '       d%   SV ,          P                  S4      P                  V 3# ^ V 3# )r:   )r/   ZgetCompositeMaxpValuesZmaxComponentDepth)Znamer3   s   &r   Z<lambda>Z'_remove_glyf_overlaps.<locals>.<lambda>   sI     T?..00 $66yASS 
 
r   )Zkey"Failed to remove overlaps for '%s'"Removed overlaps for %s glyphs:
%s N)
ZsortedsetrI   r;   r   r@   errorrA   r0   join)	rJ   rK   r   rH   rL   rG   modifiedr   r3   s	   $$$$$   @r   _remove_glyf_overlapsrW      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                sH    V ^8  d   QhR\         R\        R\        R\        /# )r   r   r   
cffFontSetr   )r   r   r   r(   r   r   r   r   r      s2        	
 
r   c                 s    \        W4      p\        W0\        R 7      p\        W44      '       g*   V^ ,          P                  p\        WEV ,          4      WP&   R# R# )r?   TF)r"   rC   r
   rF   ZCharStringsr7   )r   r   rX   r    rE   ZcharStringss   $$$   r   _remove_charstring_overlapsrY      sP     9/D dW5E d"" m//!8I@V!Wr   removeUnusedSubroutinesc                s    V ^8  d   QhR\         P                  R\        \        ,          R\        R\
        R\
        R\        R\
        RR	/# )
r   rJ   rK   r   rH   rL   	table_tagrZ   r   NrM   r   r   r   r   r      sl     #X #X
--#X #X 	#X
 #X #X #X "#X 
#Xr   c                 s   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   rX   rP   z-No overlaps found in the specified CFF glyphsNrQ   rR   )ZcffrS   rY   r;   r   r@   rT   rA   Zremove_hintsZremove_unused_subroutinesr0   rU   )
rJ   rK   r   rH   rL   r[   rZ   rX   rV   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                s    V ^8  d   QhR\         P                  R\        \        \        ,          ,          R\
        R\
        R\
        RR/# )r   rJ   rK   rH   rL   rZ   r   N)r   rN   r   r   r   r(   r   r   r   r   r     sQ     <
 <

--<
#'<
 <
 	<
 "<
 
<
r   c          
     s   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.
rO   zCFF ZCFF2zJNo outline data found in the font: missing 'glyf', 'CFF ', or 'CFF2' tableN)rJ   rK   r   rH   rL   )rJ   rK   r   rH   rL   r[   rZ   )ZNotImplementedErrorZgetGlyphOrderZgetGlyphSetrW   r\   )rJ   rK   rH   rL   rZ   r   s   &&&&$ r   r   r     s    > TfD0V45G!X
 	
 '')
 !H~!'%	
 ~4!'% &$fF$;	
 (r   c           
     s   ^ 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)Zdescriptioninputz	INPUT.ttfzInput font file)metavarhelpoutputz
OUTPUT.ttfzOutput font fileglyphsZGLYPHSZ*z4Optional list of glyph names to remove overlaps from)r^   Znargsr_   z--keep-hintingZ
store_truez>Keep hinting for unmodified glyphs, default is to drop hinting)Z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)rJ   rK   rH   rL   rZ   )argparseZArgumentParser__doc__Zadd_argumentZ
parse_argsr   rN   r]   r   ra   Zkeep_hintingZignore_errorsZkeep_unused_subroutinesZsaver`   )Zargsrb   ZparserrJ   s   &   r   mainrd   [  sO    $$(g % F ;LM
,=OP
C	   M  
 3   #?   T"D	tzz	"	"d{{**d"///++(,(D(D$D	
 			$++ 
#	"	"	"s   A(E  E	Z__main__)T)NTFr$   )0rc   r1   rB   Ztypingr    r   r   r   ZfontTools.cffLibr   ZfontTools.ttLibr   ZfontTools.ttLib.tablesr   r   ZfontTools.misc.psCharStringsr   ZfontTools.misc.roundToolsr	   r
   ZfontTools.pens.ttGlyphPenr   ZfontTools.pens.t2CharStringPenr   r   Z__all__Z	Exceptionr   Z	getLoggerr@   r   Z_TTGlyphr   r"   r%   r2   r4   r7   r<   rC   rF   rI   rW   rY   r\   r   rd   r   r   r   r   <module>re      s   
   8 8 ' " + + 5 6 0 :  
	) 	 89#v./+6	K ;B$( '.	$(NT F%XP(#X %)#XL<
 %)<
 <
~,^ zF r   