)EjqddlmZddlmZddlmZmZmZmZe e e fZ dddZ e dkrddlZejdSdS)) annotations)Optional) KerningPair KerningDict KerningGroupsIntFloatNpairrkerningrgroupsrfallbackrglyphToFirstGroupOptional[StrDict]glyphToSecondGroupreturnc@||vr||S|du|dukrtd|]i}i}|D]D\}}|dr |D]}|||<%|dr |D]}|||<E|J|J|\} } dx} | dr| } d} n|| } | } | dr| dn|| | fd| | fD} | D]}||vr ||cS|S)a Retrieve the kerning value (if any) between a pair of elements. The elments can be either individual glyphs (by name) or kerning groups (by name), or any combination of the two. Args: pair: A tuple, in logical order (first, second) with respect to the reading direction, to query the font for kerning information on. Each element in the tuple can be either a glyph name or a kerning group name. kerning: A dictionary of kerning pairs. groups: A set of kerning groups. fallback: The fallback value to return if no kern is found between the elements in ``pair``. Defaults to 0. glyphToFirstGroup: A dictionary mapping glyph names to the first-glyph kerning groups to which they belong. Defaults to ``None``. glyphToSecondGroup: A dictionary mapping glyph names to the second-glyph kerning groups to which they belong. Defaults to ``None``. Returns: The kerning value between the element pair. If no kerning for the pair is found, the fallback value is returned. Note: This function expects the ``kerning`` argument to be a flat dictionary of kerning pairs, not the nested structure used in a kerning.plist file. Examples:: >>> groups = { ... "public.kern1.O" : ["O", "D", "Q"], ... "public.kern2.E" : ["E", "F"] ... } >>> kerning = { ... ("public.kern1.O", "public.kern2.E") : -100, ... ("public.kern1.O", "F") : -200, ... ("D", "F") : -300 ... } >>> lookupKerningValue(("D", "F"), kerning, groups) -300 >>> lookupKerningValue(("O", "F"), kerning, groups) -200 >>> lookupKerningValue(("O", "E"), kerning, groups) -100 >>> lookupKerningValue(("O", "O"), kerning, groups) 0 >>> lookupKerningValue(("E", "E"), kerning, groups) 0 >>> lookupKerningValue(("E", "O"), kerning, groups) 0 >>> lookupKerningValue(("X", "X"), kerning, groups) 0 >>> lookupKerningValue(("public.kern1.O", "public.kern2.E"), ... kerning, groups) -100 >>> lookupKerningValue(("public.kern1.O", "F"), kerning, groups) -200 >>> lookupKerningValue(("O", "public.kern2.E"), kerning, groups) -100 >>> lookupKerningValue(("public.kern1.X", "public.kern2.X"), kerning, groups) 0 NzKMust provide both 'glyphToFirstGroup' and 'glyphToSecondGroup', or neither.z public.kern1.z public.kern2.c.g|]}fD] }||||f S)N).0ab secondGlyph secondGroups JC:\PYTHON\MyICR_Suite\python\Lib\site-packages\fontTools/ufoLib/kerning.py z&lookupKerningValue..|sI    {+    =Q] A+]]]) ValueErroritems startswithget)r r r r r rgroup groupMembersglyphfirstsecond firstGroup firstGlyphpairsrrs @@rlookupKerningValuer( sZ wt}T!'9T'ABB Y    #)<<>> 6 6 E<00 6)55E/4%e,,5!!/22 6)66E05&u--  ( ( (  ) ) )ME6##J ((  &**511   ))  (,,V44       j)   E!! 7??4=   Or__main__)rNN)r rr rr rr rr rrrrr) __future__rtypingrfontTools.annotationsrrrrdictstrStrDictr(__name__doctesttestmodrrrr3s""""""SSSSSSSSSSSS sCx.+/,0 }}}}}@ zNNNGOr