)Ej6ddlmZddlmZmZddlmZddlmZ dddZ ddZ dd dZ dZ e dkrddlZejdSdS)!) annotations)MappingAny) Container) KerningNestedkerningrgroupsdict[str, list[str]]glyphSetContainer[str]returnEtuple[KerningNested, dict[str, list[str]], dict[str, dict[str, str]]]crt|\}}t|D]\}}||vr.||vr*|ds||t|D]4}||vr.||vr*|ds||5i}|D]u}t|t|z} |dd} d| z} t| | } | ||<vi} |D]u}t|t| z} |dd} d| z} t| | } | | |<vi} t|D]d\}}|||}i} t|D] \}}| ||}|| |<!| | |<et|}|t| z }|D]\}} t||}||| < | |t|| fS)aConvert kerning data in UFO1 or UFO2 syntax into UFO3 syntax. Args: kerning: A dictionary containing the kerning rules defined in the UFO font, as used in :class:`.UFOReader` objects. groups: A dictionary containing the groups defined in the UFO font, as used in :class:`.UFOReader` objects. glyphSet: Optional; a set of glyph objects to skip (default: None). Returns: 1. A dictionary representing the converted kerning data. 2. A copy of the groups dictionary, with all groups renamed to UFO3 syntax. 3. A dictionary containing the mapping of old group names to new group names. z public.kern1.z public.kern2.@MMK_L_@MMK_R_)side1side2) findKnownKerningGroupslistitems startswithaddkeysreplacemakeUniqueGroupNamegetdict)r r r firstReferencedGroupssecondReferencedGroupsfirstsecondssecondfirstRenamedGroupsexistingGroupNamesnewNamesecondRenamedGroups newKerning newSecondsvalueallRenamedGroupsoldNamegroups MC:\PYTHON\MyICR_Suite\python\Lib\site-packages\fontTools/ufoLib/converters.py%convertUFO1OrUFO2KerningToUFO3Kerningr0s,5K64R4R11w}}//77w F??uH44##O44 1%))%0007<<>>** 7 7FF($:$:((997*..v666 7 *,& , ,!&++--0048J8O8O8Q8Q3R3RR-- 2..!G+%g/ABB$+5!!*,( . .!&++--0048K8P8P8R8R3S3SS..B//!G+%g/ABB&-F##Jw}}//''w"&&ue44 !'--//22 ' 'MFE(,,VV<>> testGroups = { ... "@MMK_L_1" : None, ... "@MMK_L_2" : None, ... "@MMK_L_3" : None, ... "@MMK_R_1" : None, ... "@MMK_R_2" : None, ... "@MMK_R_3" : None, ... "@MMK_l_1" : None, ... "@MMK_r_1" : None, ... "@MMK_X_1" : None, ... "foo" : None, ... } >>> first, second = findKnownKerningGroups(testGroups) >>> sorted(first) == ['@MMK_L_1', '@MMK_L_2', '@MMK_L_3'] True >>> sorted(second) == ['@MMK_R_1', '@MMK_R_2', '@MMK_R_3'] True rr)setrrrr)r knownFirstGroupPrefixesknownSecondGroupPrefixes firstGroups secondGroups groupName firstPrefix secondPrefixs r/rr`sd )k ){%%K55L&++--(( 2  K##K00  *** 5  L##L11   +++   $$r1namestr groupNames list[str]counterintcT|}|dkrd||fz}||vrt|||dzS|S)aTMake a kerning group name that will be unique within the set of group names. If the requested kerning group name already exists within the set, this will return a new name by adding an incremented counter to the end of the requested name. Args: name: The requested kerning group name. groupNames: A list of the existing kerning group names. counter: Optional; a counter of group names already seen (default: 0). If :attr:`.counter` is not provided, the function will recurse, incrementing the value of :attr:`.counter` until it finds the first unused ``name+counter`` combination, and return that result. Returns: A unique kerning group name composed of the requested name suffixed by the smallest available integer counter. rz%s%d)r)r=r?rAr's r/rrsG.G{{GW--*"4Wq[AAA Nr1cdS)aJ Tests for :func:`.convertUFO1OrUFO2KerningToUFO3Kerning`. No known prefixes. >>> testKerning = { ... "A" : { ... "A" : 1, ... "B" : 2, ... "CGroup" : 3, ... "DGroup" : 4 ... }, ... "BGroup" : { ... "A" : 5, ... "B" : 6, ... "CGroup" : 7, ... "DGroup" : 8 ... }, ... "CGroup" : { ... "A" : 9, ... "B" : 10, ... "CGroup" : 11, ... "DGroup" : 12 ... }, ... } >>> testGroups = { ... "BGroup" : ["B"], ... "CGroup" : ["C"], ... "DGroup" : ["D"], ... } >>> kerning, groups, maps = convertUFO1OrUFO2KerningToUFO3Kerning( ... testKerning, testGroups, []) >>> expected = { ... "A" : { ... "A": 1, ... "B": 2, ... "public.kern2.CGroup": 3, ... "public.kern2.DGroup": 4 ... }, ... "public.kern1.BGroup": { ... "A": 5, ... "B": 6, ... "public.kern2.CGroup": 7, ... "public.kern2.DGroup": 8 ... }, ... "public.kern1.CGroup": { ... "A": 9, ... "B": 10, ... "public.kern2.CGroup": 11, ... "public.kern2.DGroup": 12 ... } ... } >>> kerning == expected True >>> expected = { ... "BGroup": ["B"], ... "CGroup": ["C"], ... "DGroup": ["D"], ... "public.kern1.BGroup": ["B"], ... "public.kern1.CGroup": ["C"], ... "public.kern2.CGroup": ["C"], ... "public.kern2.DGroup": ["D"], ... } >>> groups == expected True Known prefixes. >>> testKerning = { ... "A" : { ... "A" : 1, ... "B" : 2, ... "@MMK_R_CGroup" : 3, ... "@MMK_R_DGroup" : 4 ... }, ... "@MMK_L_BGroup" : { ... "A" : 5, ... "B" : 6, ... "@MMK_R_CGroup" : 7, ... "@MMK_R_DGroup" : 8 ... }, ... "@MMK_L_CGroup" : { ... "A" : 9, ... "B" : 10, ... "@MMK_R_CGroup" : 11, ... "@MMK_R_DGroup" : 12 ... }, ... } >>> testGroups = { ... "@MMK_L_BGroup" : ["B"], ... "@MMK_L_CGroup" : ["C"], ... "@MMK_L_XGroup" : ["X"], ... "@MMK_R_CGroup" : ["C"], ... "@MMK_R_DGroup" : ["D"], ... "@MMK_R_XGroup" : ["X"], ... } >>> kerning, groups, maps = convertUFO1OrUFO2KerningToUFO3Kerning( ... testKerning, testGroups, []) >>> expected = { ... "A" : { ... "A": 1, ... "B": 2, ... "public.kern2.CGroup": 3, ... "public.kern2.DGroup": 4 ... }, ... "public.kern1.BGroup": { ... "A": 5, ... "B": 6, ... "public.kern2.CGroup": 7, ... "public.kern2.DGroup": 8 ... }, ... "public.kern1.CGroup": { ... "A": 9, ... "B": 10, ... "public.kern2.CGroup": 11, ... "public.kern2.DGroup": 12 ... } ... } >>> kerning == expected True >>> expected = { ... "@MMK_L_BGroup": ["B"], ... "@MMK_L_CGroup": ["C"], ... "@MMK_L_XGroup": ["X"], ... "@MMK_R_CGroup": ["C"], ... "@MMK_R_DGroup": ["D"], ... "@MMK_R_XGroup": ["X"], ... "public.kern1.BGroup": ["B"], ... "public.kern1.CGroup": ["C"], ... "public.kern1.XGroup": ["X"], ... "public.kern2.CGroup": ["C"], ... "public.kern2.DGroup": ["D"], ... "public.kern2.XGroup": ["X"], ... } >>> groups == expected True >>> from .validators import kerningValidator >>> kerningValidator(kerning) (True, None) Mixture of known prefixes and groups without prefixes. >>> testKerning = { ... "A" : { ... "A" : 1, ... "B" : 2, ... "@MMK_R_CGroup" : 3, ... "DGroup" : 4 ... }, ... "BGroup" : { ... "A" : 5, ... "B" : 6, ... "@MMK_R_CGroup" : 7, ... "DGroup" : 8 ... }, ... "@MMK_L_CGroup" : { ... "A" : 9, ... "B" : 10, ... "@MMK_R_CGroup" : 11, ... "DGroup" : 12 ... }, ... } >>> testGroups = { ... "BGroup" : ["B"], ... "@MMK_L_CGroup" : ["C"], ... "@MMK_R_CGroup" : ["C"], ... "DGroup" : ["D"], ... } >>> kerning, groups, maps = convertUFO1OrUFO2KerningToUFO3Kerning( ... testKerning, testGroups, []) >>> expected = { ... "A" : { ... "A": 1, ... "B": 2, ... "public.kern2.CGroup": 3, ... "public.kern2.DGroup": 4 ... }, ... "public.kern1.BGroup": { ... "A": 5, ... "B": 6, ... "public.kern2.CGroup": 7, ... "public.kern2.DGroup": 8 ... }, ... "public.kern1.CGroup": { ... "A": 9, ... "B": 10, ... "public.kern2.CGroup": 11, ... "public.kern2.DGroup": 12 ... } ... } >>> kerning == expected True >>> expected = { ... "BGroup": ["B"], ... "@MMK_L_CGroup": ["C"], ... "@MMK_R_CGroup": ["C"], ... "DGroup": ["D"], ... "public.kern1.BGroup": ["B"], ... "public.kern1.CGroup": ["C"], ... "public.kern2.CGroup": ["C"], ... "public.kern2.DGroup": ["D"], ... } >>> groups == expected True Nrrr1r/testrFsr1__main__N)r)r rr r r r rr)r r2rr3)r)r=r>r?r@rArBrr>) __future__rtypingrrcollections.abcrfontTools.annotationsrr0rrrF__name__doctesttestmodrr1r/rOs""""""%%%%%%//////VXJYJYJYJYJYZ?%?%?%?%DBNNNb zNNNGOr1