)EjS3dZddlZddlZddlmZmZmZmZddlm Z ddl m Z ddl m Z ddl mZddlmZdd lmZmZdd lmZdd lmZddlZd gZGd deZejdZeee jfZ dede dej!fdZ"de j#de fdZ$de j%de de&fdZ'dej!de j%fdZ(dej!dedefdZ)efdej!dee*ge*fdej!fdZ+eddej!dedee*ge*fdej!fd Z,d!ej!d"ej!de&fd#Z- d7dede d%e j.d&ej/d'e&de&f d(Z0d)e j1d*eede d'e&d+e&ddf d,Z2dede d-e de&fd.Z3d$d/d)e j1d*eede d'e&d+e&d0ed1e&ddfd2Z4 d8d$d/d)e j1d*eeed'e&d+e&d1e&ddf d4Z5d9d5Z6e7d6kr e6dSdS):zySimplify 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)T2CharStringPenremoveOverlapsceZdZdS)RemoveOverlapsErrorN)__name__ __module__ __qualname__PC:\PYTHON\MyICR_Suite\python\Lib\site-packages\fontTools/ttLib/removeOverlaps.pyrrsDrrzfontTools.ttLib.removeOverlaps glyphNameglyphSetreturnctj}||}||||S)Nr)pathopsPathgetPendraw)rrpathpathPens rskPathFromGlyphr$"s> <>>Dkk8k,,G YW%%% Kr componentcd|\}}t||}|j|SN)getComponentInfor$ transform)r%r baseGlyphNametransformationr"s rskPathFromGlyphComponentr,)s8%.$>$>$@$@!M> =( 3 3D 4>> **rglyphc XstdtjdkrdSidtdt jffd tfdtj ttjdDS)Nz5This method only works with TrueType composite glyphsFindexrcX|vrtj||<|Sr')r, components)r0component_pathsr-rs r_get_nth_component_pathz2componentsOverlap.._get_nth_component_path9s<  ' '%= '&&OE "u%%rc3K|]A\}}tj||tjjddVBdS)F) fix_windingkeep_starting_pointsN)ropPathOp INTERSECTION).0ijr4s r z$componentsOverlap..@sx   Aq  # #A & & # #A & & N '!&          r) isComposite ValueErrorlenr2intrrany itertools combinationsrange)r-rr4r3s``@@rcomponentsOverlaprG1s     RPQQQ 5 q  uO&s&w|&&&&&&&&     *5U5E1F1F+G+GKK      rr"ctd}|||}|rJ|d|S)Nr) glyfTable)rr!r-r? recalcBounds)r"ttPenr-s rttfGlyphFromSkPathrLLse  % % %EIIe KKMME  """" " &&& Lr charStringc|j|jjkrd}n|j|jjz }t |d}||||j|jS)N)widthr)rOprivate defaultWidthX nominalWidthXrr! getCharString globalSubrs)r"rMrOt2Pens r_charString_from_SkPathrVWsr:-;;; :#5#CC %$ 7 7 7EIIe   z1:3I J JJrroundcrtj}|D]\}}|j|gfd|DR |S)Nc3\K|]&}|d|dfV'dS)rNr)r;prWs rr>z_round_path..hs@ L L%%!++uuQqT{{!; L L L L L Lr)rradd)r"rW rounded_pathverbpointss ` r _round_pathr`cs^<>>LNN f M L L L LV L L LMMMMM rrWdebugGlyphNamec tj||jS#tj$rYnwxYwt ||} tj||j}t d||S#tj$rP}t tj r| td||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 ???  =         GM * *  IIKKK! FN F F   s%//7A<<C A CCpath1path2cJd|jDd|jDkS)Nc,h|]}t|Srtupler;cs r z_same_path..s - - -E!HH - - -rc,h|]}t|Srrtrvs rrxz_same_path..s1S1S1Sq%((1S1S1Sr)contours)rprqs r _same_pathr{s. - -en - - -1S1SEN1S1S1S SSrTrI hmtxTable removeHintingc||}|jdks$|rt||rqt||}t ||}t ||sAt |x||<}|jrJ||\}} | |jkr ||jf||<dS|r| dS)NrTF) numberOfContoursr?rGr$ror{rLprogramxMinr}) rrrIr|r}r-r"rqrOlsbs rremoveTTGlyphOverlapsrs i E ""      # eX . . #y(33$ **$&& +=e+D+D DIi 5} $ $$"9-JE3ej  (-uz': )$4  5rfont glyphNames ignoreErrorsc|d|d}t|fd}t}|D]Y} t||||r||,#t$r!|st d|YVwxYwt dt|d |dS)Nglyfhmtxc|r |jnd|fS)Nr)r?getCompositeMaxpValuesmaxComponentDepth)namerIs rz'_remove_glyf_overlaps..sDT?..00 $66yAASS   r)key"Failed to remove overlaps for '%s'"Removed overlaps for %s glyphs: %s ) sortedsetrr\rrgerrorrhrAjoin) rrrr}rr|modifiedrrIs @r_remove_glyf_overlapsrsV IV I        JuuH G G  G$8Y = ( Y'''" G G G  II:I F F F F F G II3S]]CHHXDVDVWWWWWs(A""(B  B  cffFontSetct||}t||t}t||s(|dj}t |||||<dSdS)NrarTF)r$ror r{ CharStringsrV)rrrr"rq charStringss r_remove_charstring_overlapsrsl 9h / /D dIW 5 5 5E dE " " m/ !8 I@V!W!W It 5r)removeUnusedSubroutines table_tagrc||j}t}|D]X} t| ||r|| +#t$r!|st d| YUwxYw|st ddS|r||r| t dt|d |dS)N)rrrrz-No overlaps found in the specified CFF glyphsrr) cffrrr\rrgrrh remove_hintsremove_unused_subroutinesrAr) rrrr}rrrrrrs r_remove_cff_overlapsrs/i$JuuH G G  G*#!% (  Y'''" G G G  II:I F F F F F G  ABBB"!!!/,,...II3S]]CHHXDVDVWWWWWs'A  (A43A4Fc  d|vrd|vrd|vrtd||}|}d|vrt|||||d|vsd|vrt |||||d|vrdnd|dSdS)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. rzCFF CFF2zJNo outline data found in the font: missing 'glyf', 'CFF ', or 'CFF2' tableN)rrrr}r)rrrr}rrr)NotImplementedError getGlyphOrder getGlyphSetrr)rrr}rrrs rrrs>TfD00V45G5G! X   '')) !!H ~~!'%     ~~4!'% &$ffF$;      (rcddl}|dt}|ddd|d d d |d d dd|ddd|ddd|ddd||}t j|j5}t||j pd|j |j |j | |jddddS#1swxYwYdS)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)rrr}rr)argparseArgumentParser__doc__ add_argument parse_argsrTTFontrrr keep_hinting ignore_errorskeep_unused_subroutinessaver)argsrparserrs rmainr[sOOO  $ $(g%F ;LMMM ,=OPPP  C    M  3  #?   T " "D tz " "d{*d"//+(,(D$D      $+s AD44D8;D8__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`ror{table__g_l_y_ftable__h_m_t_xrrrrrrrrrrrrs 888888888888''''''""""""++++++++++++55555566666666000000::::::       )   g899#v./so',+&+2A++++X^46W\hn K , K$0 K K K K K;B ,'7 \'. $($($( ,$($( UGUN # $(  \ $($($($(NTglT7<TDTTTT    & &        F%X -%X %X %X  %X  %X %X%X%X%XP   8%)#X#X#X -#X #X #X  #X  #X#X"#X #X#X#X#XP+/ < %) < < < -< #'< <  < " <  < < < < ~,,,,^ zDFFFFFr