
    hD1                     (   S r SSKrSSKrSSKJrJrJrJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKrS/r " S S\5      r\R8                  " S5      r\\\R>                  4   r S\S\ S\RB                  4S jr"S\RF                  S\ 4S jr$S\RJ                  S\ S\&4S jr'S\RB                  S\RJ                  4S jr(S\RB                  S\S\4S jr)\4S\RB                  S\\*/\*4   S\RB                  4S jjr+\S.S\RB                  S\S\\*/\*4   S\RB                  4S  jjr,S!\RB                  S"\RB                  S\&4S# jr- S5S\S\ S%\R\                  S&\R^                  S'\&S\&4S( jjr0S)\Rb                  S*\\   S\ S'\&S+\&SS4S, jr2S\S\ S-\	S\&4S. jr3S$S/.S)\Rb                  S*\\   S\ S'\&S+\&S0\&SS4S1 jjr4   S6S$S/.S)\Rb                  S*\\\      S'\&S+\&S0\&SS4S2 jjjr5S7S3 jr6\7S4:X  a  \6" 5         gg)8zySimplify 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                       \ rS rSrSrg)RemoveOverlapsError    N)__name__
__module____qualname____firstlineno____static_attributes__r       P/var/www/html/env/lib/python3.13/site-packages/fontTools/ttLib/removeOverlaps.pyr   r      s    r   r   zfontTools.ttLib.removeOverlaps	glyphNameglyphSetreturnc                 t    [         R                  " 5       nUR                  US9nX   R                  U5        U$ )Nr   )pathopsPathgetPendraw)r   r   pathpathPens       r   skPathFromGlyphr'   "   s3    <<>Dkk8k,GW%Kr   	componentc                 Z    U R                  5       u  p#[        X!5      nUR                  " U6 $ N)getComponentInfor'   	transform)r(   r   baseGlyphNametransformationr%   s        r   skPathFromGlyphComponentr/   )   s.     %.$>$>$@!M=3D>>>**r   glyphc           
      N  ^ ^^^ T R                  5       (       d  [        S5      e[        T R                  5      S:  a  g0 mS[        S[
        R                  4UU U4S jjm[        U4S j[        R                  " [        [        T R                  5      5      S5       5       5      $ )Nz5This method only works with TrueType composite glyphs   Findexr   c                 R   > U T;  a  [        TR                  U    T5      TU '   TU    $ r*   )r/   
components)r3   component_pathsr0   r   s    r   _get_nth_component_path2componentsOverlap.<locals>._get_nth_component_path9   s7    '%=  '&OE" u%%r   c           	   3      >#    U  HC  u  p[         R                  " T" U5      T" U5      [         R                  R                  S S S9v   ME     g7f)F)fix_windingkeep_starting_pointsN)r!   opPathOpINTERSECTION).0ijr7   s      r   	<genexpr>$componentsOverlap.<locals>.<genexpr>@   sL      	 LDA 	

#A&#A&NN''!&	
 Ls   AA)isComposite
ValueErrorlenr5   intr!   r"   any	itertoolscombinationsrange)r0   r   r7   r6   s   ``@@r   componentsOverlaprL   1   s    PQQ
5q O&s &w|| & &  	 **5U5E5E1F+GK	 	 	r   r%   c                     [        S S9nU R                  U5        UR                  5       nUR                  5       (       a   eUR	                  S S9  U$ )Nr    )	glyfTable)r   r$   r0   rD   recalcBounds)r%   ttPenr0   s      r   ttfGlyphFromSkPathrQ   L   sN    %EIIeKKME  """"	&Lr   
charStringc                    UR                   UR                  R                  :X  a  S nO#UR                   UR                  R                  -
  n[	        US S9nU R                  U5        UR                  UR                  UR                  5      $ )N)widthr   )rT   privatedefaultWidthXnominalWidthXr   r$   getCharStringglobalSubrs)r%   rR   rT   t2Pens       r   _charString_from_SkPathr[   W   sv     :--;;;  :#5#5#C#CC%$7EIIez11:3I3IJJr   roundc                    ^ [         R                  " 5       nU  H"  u  p4UR                  " U/U4S jU 5       Q76   M$     U$ )Nc              3   P   >#    U  H  nT" US    5      T" US   5      4v   M     g7f)r      Nr   )r?   pr\   s     r   rB   _round_path.<locals>.<genexpr>h   s&      LV%!+uQqT{!;Vs   #&)r!   r"   add)r%   r\   rounded_pathverbpointss    `   r   _round_pathrf   c   s;     <<>LM LV LM r   r\   debugGlyphNamec                    [         R                  " X R                  S9$ ! [         R                   a     Of = f[	        XS9n  [         R                  " X R                  S9n [
        R                  SU5        U $ ! [         R                   aM  n[
        R                  [        R                  5      (       a  U R                  5         [        SU< 35      UeS nAff = f)N)	clockwiserg   zkskia-pathops failed to simplify '%s' with float coordinates, but succeded using rounded integer coordinatesz%Failed to remove overlaps from glyph )r!   simplifyrj   PathOpsErrorrf   logdebugisEnabledForloggingDEBUGdumpr   AssertionError)r%   rh   r\   es       r   	_simplifyru   l   s    ??  t)D?		=	

  GMM**IIK!3N3EF
	s%     775A: :CACCpath1path2c                     U R                    Vs1 s H  n[        U5      iM     snUR                    Vs1 s H  n[        U5      iM     sn:H  $ s  snf s  snf r*   )contourstuple)rv   rw   cs      r   
_same_pathr|      sA    #nn-nE!Hn-ENN1SNq%(N1SSS-1Ss
   AATrN   	hmtxTableremoveHintingc                 ~   X    nUR                   S:  d%  UR                  5       (       a}  [        XQ5      (       am  [        X5      n[	        X`5      n[        Xg5      (       dG  [        U5      =X '   nUR                  (       a   eX0   u  pXR                  :w  a  XR                  4X0'   gU(       a  UR                  5         g)Nr   TF)
numberOfContoursrD   rL   r'   ru   r|   rQ   programxMinr~   )
r   r   rN   r}   r~   r0   r%   rw   rT   lsbs
             r   removeTTGlyphOverlapsr      s      E 	"e..y3 $* $&&+=e+DDI 5}}$$"-JEjj (-zz':	$r   font
glyphNamesignoreErrorsc                 d  ^ U S   mU S   n[        UU4S jS9n[        5       nU H)  n [        XrTXS5      (       a  UR                  U5        M)  M+     [
        R                  S[        U5      SR                  U5      5        g ! [         a"    U(       d  e [
        R                  SU5         M  f = f)Nglyfhmtxc                 |   > TU    R                  5       (       a   TU    R                  T5      R                  U 4$ SU 4$ )Nr   )rD   getCompositeMaxpValuesmaxComponentDepth)namerN   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 )
sortedsetr   rb   r   rm   errorrn   rF   join)	r   r   r   r~   r   r}   modifiedr   rN   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/
cffFontSetc                     [        X5      n[        X0[        S9n[        X45      (       d   US   R                  n[        XEU    5      XP'   gg)Nrg   r   TF)r'   ru   r   r|   CharStringsr[   )r   r   r   r%   rw   charStringss         r   _remove_charstring_overlapsr      sP     9/D dW5E d"" m//!8I@V!Wr   )removeUnusedSubroutinesr   c                    U S   R                   n[        5       nU H'  n [        UUUS9(       a  UR                  U5        M'  M)     U(       d  [
        R                  S5        g U(       a  UR                  5         U(       a  UR                  5         [
        R                  S[        U5      SR                  U5      5        g ! [         a"    U(       d  e [
        R                  SU5         M  f = f)NCFF )r   r   r   r   z-No overlaps found in the specified CFF glyphsr   r   )cffr   r   rb   r   rm   r   rn   remove_hintsremove_unused_subroutinesrF   r   )	r   r   r   r~   r   r   r   r   r   s	            r   _remove_cff_overlapsr      s     f!!JuH	
	G*#!%
 Y'   		AB!,,.II3S]CHHXDVW # 	GII:IF	Gs   !C(C.-C.c          	          SU ;  a  SU ;  a  [        S5      eUc  U R                  5       nU R                  5       nSU ;   a  [        U UUUUS9  SU ;   a  [	        U UUUUUS9  gg)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   r   zANo outline data found in the font: missing 'glyf' or 'CFF ' tableN)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0!O
 	
 '')
 !H~!'%	
 ~!'%$;	
 r   c           	      ^   SSK nUR                  S[        S9nUR                  SSSS9  UR                  S	S
SS9  UR                  SSSSS9  UR                  SSSS9  UR                  SSSS9  UR                  SSSS9  UR	                  U 5      n [
        R                  " U R                  5       n[        UU R                  =(       d    SU R                  (       + U R                  U R                  (       + S9  UR                  U R                  5        SSS5        g! , (       d  f       g= f)z:Simplify glyphs in TTFont by merging overlapping contours.r   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   TTFontr   r   r   keep_hintingignore_errorskeep_unused_subroutinessaver   )argsr   parserr   s       r   mainr   Y  sF    $$(g % F ;LM
,=OP
C	   M  
 3   #?   T"D	tzz	"d{{*d"///++(,(D(D$D	
 			$++ 
#	"	"s   1A$D
D,__main__)T)NTFr*   )8r   rI   rp   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   	getLoggerrm   str_TTGlyph_TTGlyphMappingr"   r'   GlyphComponentr/   GlyphboolrL   rQ   r[   floatrf   ru   r|   table__g_l_y_ftable__h_m_t_xr   r   r   r   r   r   r   r   r   r   r   <module>r      sF  
   8 8 ' " + + 5 6 0 :  
	) 	 89#v./s o ',, +&&+2A+X^^  4 6W\\ hnn 	K
,,	K$0	K	K ;B
,,'7\\ '.	$(
,,$($( UGUN#	$(
 \\$(NTgll T7<< TD T     &&  &&	 
   
 F%X
--%X %X 	%X
 %X %X 
%XP  	
 
6 %)"X
--"X "X 	"X
 "X "X ""X 
"XN +/	;
 %);

--;
#';
 ;
 	;
 ";
 
;
|,^ zF r   