L iD1dZddlZddlZddlmZmZmZmZddlm Z ddl m Z ddl m Z ddl mZddlmZdd lmZmZdd lmZdd lmZddlZd gZGd deZej8dZeee j>fZ dede dejBfdZ"de jFde fdZ$de jJde de&fdZ'dejBde jJfdZ(dejBdedefdZ)efdejBdee*ge*fdejBfdZ+eddejBdedee*ge*fdejBfd Z,d!ejBd"ejBde&fd#Z- d5dede d%e j\d&ej^d'e&de&f d(Z0d)e jbd*eede d'e&d+e&ddf d,Z2dede d-e de&fd.Z3d$d/d)e jbd*eede d'e&d+e&d0e&ddfd1Z4 d6d$d/d)e jbd*eeed'e&d+e&d0e&ddf d2Z5d7d3Z6e7d4k(re6yy)8zz Simplify TrueType glyphs by merging overlapping contours/components. Requires https://github.com/fonttools/skia-pathops N)CallableIterableOptionalMapping) CFFFontSet)ttFont)_g_l_y_f)_h_m_t_x) T2CharString)otRoundnoRound) TTGlyphPen)T2CharStringPenremoveOverlapsc eZdZy)RemoveOverlapsErrorN)__name__ __module__ __qualname__d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fontTools/ttLib/removeOverlaps.pyrrsrrzfontTools.ttLib.removeOverlaps glyphNameglyphSetreturncztj}|j|}||j||S)Nr)pathopsPathgetPendraw)rrpathpathPens rskPathFromGlyphr$"s5 <<>Dkk8k,G YW% Kr componentc^|j\}}t||}|j|SN)getComponentInfor$ transform)r%r baseGlyphNametransformationr"s rskPathFromGlyphComponentr,)s4%.$>$>$@!M> =( 3D 4>>> **rglyphc :js tdtjdkryidtdt j ffd tfdtjttjdDS)Nz5This method only works with TrueType composite glyphsFindexrcN|vrtj||<|Sr')r, components)r0component_pathsr-rs r_get_nth_component_pathz2componentsOverlap.._get_nth_component_path9s7  '%=  '&OE "u%%rc3K|]E\}}tj||tjjddGyw)F) fix_windingkeep_starting_pointsN)ropPathOp INTERSECTION).0ijr4s r z$componentsOverlap..@sP  Aq  #A & #A & NN ' '!&    sA A) isComposite ValueErrorlenr2intrrany itertools combinationsrange)r-rr4r3s``@@rcomponentsOverlaprG1s    PQQ 5  q O&s&w||&  **5U5E5E1F+GK   rr"ctd}|j||j}|jrJ|j d|S)Nr) glyfTable)rr!r-r? recalcBounds)r"ttPenr-s rttfGlyphFromSkPathrLLsK  %EIIe KKME  "" " & Lr charStringc|j|jjk(rd}n#|j|jjz }t |d}|j ||j |j|jS)N)widthr)rOprivate defaultWidthX nominalWidthXrr! getCharString globalSubrs)r"rMrOt2Pens r_charString_from_SkPathrVWsv:--;;;  :#5#5#C#CC %$ 7EIIe   z11:3I3I JJrroundc|tj}|D]!\}}|j|gfd|D#|S)Nc3JK|]}|d|dfyw)rNr)r;prWs rr>z_round_path..hs& L%!+uQqT{!; Ls #)rradd)r"rW rounded_pathverbpointss ` r _round_pathr`csF<<>LN f M LV LMN rrWdebugGlyphNamec tj||jS#tj$rYnwxYwt ||} tj||j}t j d||S#tj$rG}t jtjr|jtd||d}~wwxYw)N) clockwiserazkskia-pathops failed to simplify '%s' with float coordinates, but succeded using rounded integer coordinatesz%Failed to remove overlaps from glyph ) rsimplifyrd PathOpsErrorr`logdebug isEnabledForloggingDEBUGdumprAssertionError)r"rbrWes r _simplifyrols ??       t5 )D ?  =        GMM * IIK!3N3E F  s% #99 8BCACCpath1path2c|jDchc] }t|c}|jDchc] }t|c}k(Scc}wcc}wr')contourstuple)rprqcs r _same_pathrvs9#nn -E!H -ENN1Sq%(1S SS -1Ss AA TrI hmtxTable removeHintingc^||}|jdkDs|jrwt||rkt||}t ||}t ||sGt |x||<}|jrJ||\}} | |jk7r||jf||<y|r|jy)NrTF) numberOfContoursr?rGr$rorvrLprogramxMinrx) rrrIrwrxr-r"rqrOlsbs rremoveTTGlyphOverlapsr~s i E "     eX .y(3$ *$&+=e+D DIi 5}} $$"9-JE3ejj (-uzz': )$  rfont glyphNames ignoreErrorscL|d|d}t|fd}t}|D]#} t||||r|j|%t jdt|dj|y#t$r|st j d|YzwxYw)Nglyfhmtxcr|jr |jj|fSd|fS)Nr)r?getCompositeMaxpValuesmaxComponentDepth)namerIs rz'_remove_glyf_overlaps..sJT?..0$66yASS      r)key"Failed to remove overlaps for '%s'"Removed overlaps for %s glyphs: %s ) sortedsetr~r\rrgerrorrhrAjoin) rrrrxrrwmodifiedrrIs @r_remove_glyf_overlapsrsV IV I   JuH G  G$8Y = Y' GII3S]CHHXDVW # G II:I F Gs A>>"B#"B# cffFontSetct||}t||t}t||s"|dj}t |||||<yy)NrarTF)r$ror rv CharStringsrV)rrrr"rq charStringss r_remove_charstring_overlapsrsW 9h /D dIW 5E dE " m// !8 I@V!W I r)removeUnusedSubroutinesrc|dj}t}|D]"} t|||r|j|$|st jdy|r|j|r|jt jdt|dj|y#t$r|st j d|YwxYw)NCFF )rrrrz-No overlaps found in the specified CFF glyphsrr) cffrrr\rrgrrh remove_hintsremove_unused_subroutinesrAr) rrrrxrrrrrs r_remove_cff_overlapsrsf!!JuH G  G*#!%  Y' G  AB!,,.II3S]CHHXDVW# G II:I F GsB--"CCcd|vrd|vr td||j}|j}d|vrt|||||d|vrt ||||||yy)aSimplify 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. rrzANo outline data found in the font: missing 'glyf' or 'CFF ' tableN)rrrrxr)rrrrxrr)NotImplementedError getGlyphOrder getGlyphSetrr)rrrxrrrs rrrs>TfD0! O  '') !H ~!'%  ~!'%$;  rchddl}|jdt}|jddd|jd d d |jd d dd|jddd|jddd|jddd|j |}t j |j5}t||jxsd|j |j|j |j|jdddy#1swYyxYw)z:Simplify glyphs in TTFont by merging overlapping contours.rNzfonttools ttLib.removeOverlaps) descriptioninputz INPUT.ttfzInput font file)metavarhelpoutputz OUTPUT.ttfzOutput font fileglyphsGLYPHS*z4Optional list of glyph names to remove overlaps from)rnargsrz--keep-hinting store_truez>Keep hinting for unmodified glyphs, default is to drop hinting)actionrz--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)rrrxrr)argparseArgumentParser__doc__ add_argument parse_argsrTTFontrrr keep_hinting ignore_errorskeep_unused_subroutinessaver)argsrparserrs rmainrYsO  $ $(g%F ;LM ,=OP  C    M  3  #?   T "D tzz "d{{*d"///++(,(D(D$D   $++s AD((D1__main__)T)NTFr')8rrDrjtypingrrrrfontTools.cffLibrfontTools.ttLibrfontTools.ttLib.tablesr r fontTools.misc.psCharStringsr fontTools.misc.roundToolsr r fontTools.pens.ttGlyphPenrfontTools.pens.t2CharStringPenrr__all__ Exceptionr getLoggerrgstr_TTGlyph_TTGlyphMappingrr$GlyphComponentr,GlyphboolrGrLrVfloatr`rorvtable__g_l_y_ftable__h_m_t_xr~rrrrrrrrrrrsH 88'"++560:   ) g89#v./so',,+&&+2A+X^^46W\\hnn K ,, K$0 K K;B ,,'7 \\'. $( ,,$($( UGUN # $(  \\ $(NTgllT7<<TDT   && &&     F%X --%X %X %X  %X  %X %XP   6%)"X --"X "X "X  "X  "X""X "XN+/ ; %) ; --; #'; ;  ; " ;  ; |,^ zFr