§
    ¢”j„4  ã                  ó–   — d dl mZ d dlmZmZ d dlmZ d dlmZ 	 	 ddd„Z	dd„Z
dd d„Zd„ Zedk    rd dlZ ej        ¦   «          dS dS )!é    )Úannotations)ÚMappingÚAny)Ú	Container)ÚKerningNested© Úkerningr   Úgroupsúdict[str, list[str]]ÚglyphSetúContainer[str]ÚreturnúEtuple[KerningNested, dict[str, list[str]], dict[str, dict[str, str]]]c                ór  — t          |¦  «        \  }}t          |                      ¦   «         ¦  «        D ]�\  }}||v r.||vr*|                     d¦  «        s|                     |¦  «         t          |                     ¦   «         ¦  «        D ]4}||v r.||vr*|                     d¦  «        s|                     |¦  «         Œ5ŒŽi }|D ]u}t          |                     ¦   «         ¦  «        t          |                     ¦   «         ¦  «        z   }	|                     dd¦  «        }
d|
z   }
t          |
|	¦  «        }
|
||<   Œvi }|D ]u}t          |                     ¦   «         ¦  «        t          |                     ¦   «         ¦  «        z   }	|                     dd¦  «        }
d|
z   }
t          |
|	¦  «        }
|
||<   Œvi }t          |                      ¦   «         ¦  «        D ]d\  }}|                     ||¦  «        }i }t          |                     ¦   «         ¦  «        D ] \  }}|                     ||¦  «        }|||<   Œ!|||<   Œet          |                     ¦   «         ¦  «        }|t          |                     ¦   «         ¦  «        z  }|D ]\  }}
t          ||         ¦  «        }|||
<   Œ ||t          ||¬¦  «        fS )a§  Convert 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_)Úside1Úside2)
ÚfindKnownKerningGroupsÚlistÚitemsÚ
startswithÚaddÚkeysÚreplaceÚmakeUniqueGroupNameÚgetÚdict)r	   r
   r   ÚfirstReferencedGroupsÚsecondReferencedGroupsÚfirstÚsecondsÚsecondÚfirstRenamedGroupsÚexistingGroupNamesÚnewNameÚsecondRenamedGroupsÚ
newKerningÚ
newSecondsÚvalueÚallRenamedGroupsÚoldNameÚgroups                     új/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/fontTools/ufoLib/converters.pyÚ%convertUFO1OrUFO2KerningToUFO3Kerningr0      sü  € õ, 5KÈ6Ñ4RÔ4RÑ1ÐÐ1å˜wŸ}š}™œÑ/Ô/ð 7ð 7‰ˆˆwØ�Fˆ?ˆ?˜u¨HÐ4Ð4Ø×#Ò# OÑ4Ô4ð 1Ø%×)Ò)¨%Ñ0Ô0Ð0Ý˜7Ÿ<š<™>œ>Ñ*Ô*ð 	7ð 	7ˆFØ˜ÐÐ F°(Ð$:Ð$:Ø×(Ò(¨Ñ9Ô9ð 7Ø*×.Ò.¨vÑ6Ô6Ð6øð	7ð
 *,ÐØ&ð 
,ð 
,ˆå! &§+¢+¡-¤-Ñ0Ô0µ4Ð8J×8OÒ8OÑ8QÔ8QÑ3RÔ3RÑRÐà—-’- 	¨2Ñ.Ô.ˆà! GÑ+ˆå% gÐ/AÑBÔBˆà$+Ð˜5Ñ!Ð!Ø*,ÐØ(ð 
.ð 
.ˆå! &§+¢+¡-¤-Ñ0Ô0µ4Ð8K×8PÒ8PÑ8RÔ8RÑ3SÔ3SÑSÐà—.’. ¨BÑ/Ô/ˆà! GÑ+ˆå% gÐ/AÑBÔBˆà&-Ð˜FÑ#Ð#à€JÝ˜wŸ}š}™œÑ/Ô/ð 'ð '‰ˆˆwØ"×&Ò& u¨eÑ4Ô4ˆØˆ
Ý! '§-¢-¡/¤/Ñ2Ô2ð 	'ð 	'‰MˆF�EØ(×,Ò,¨V°VÑ<Ô<ˆFØ!&ˆJ�vÑÐØ&ˆ
�5ÑÐõ Ð.×4Ò4Ñ6Ô6Ñ7Ô7ÐØ�Ð0×6Ò6Ñ8Ô8Ñ9Ô9Ñ9ÐØ,ð  ð  Ñˆ�Ý�V˜G”_Ñ%Ô%ˆØˆˆw‰ˆà�v�tÐ*<ÐDWÐXÑXÔXÐXÐXó    úMapping[str, Any]útuple[set[str], set[str]]c                óZ  — dg}dg}t          ¦   «         }t          ¦   «         }t          |                      ¦   «         ¦  «        D ]d}|D ].}|                     |¦  «        r|                     |¦  «          nŒ/|D ].}|                     |¦  «        r|                     |¦  «          nŒ/Œe||fS )a‹  Find all kerning groups in a UFO1 or UFO2 font that use known prefixes.

    In some cases, not all kerning groups will be referenced
    by the kerning pairs in a UFO. The algorithm for locating
    groups in :func:`convertUFO1OrUFO2KerningToUFO3Kerning` will
    miss these unreferenced groups. By scanning for known prefixes,
    this function will catch all of the prefixed groups.

    The prefixes and sides by this function are:

    @MMK_L_ - side 1
    @MMK_R_ - side 2

    as defined in the UFO1 specification.

    Args:
        groups:
          A dictionary containing the groups defined in the UFO
          font, as read by :class:`.UFOReader`.

    Returns:
        Two sets; the first containing the names of all
        first-side kerning groups identified in the ``groups``
        dictionary, and the second containing the names of all
        second-side kerning groups identified.

        "First-side" and "second-side" are with respect to the
        writing direction of the script.

        Example::

          >>> 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
    r   r   )Úsetr   r   r   r   )r
   ÚknownFirstGroupPrefixesÚknownSecondGroupPrefixesÚfirstGroupsÚsecondGroupsÚ	groupNameÚfirstPrefixÚsecondPrefixs           r/   r   r   `   sÚ   € ðd  )˜kÐØ )˜{ÐÝ‘%”%€KÝ‘5”5€LÝ˜&Ÿ+š+™-œ-Ñ(Ô(ð ð ˆ	Ø2ð 	ð 	ˆKØ×#Ò# KÑ0Ô0ð Ø—’ 	Ñ*Ô*Ð*Ø�ðð 5ð 	ð 	ˆLØ×#Ò# LÑ1Ô1ð Ø× Ò  Ñ+Ô+Ð+Ø�ðøð ˜Ð$Ð$r1   ÚnameÚstrÚ
groupNamesú	list[str]ÚcounterÚintc                óT   — | }|dk    rd||fz  }||v rt          | ||dz   ¦  «        S |S )aT  Make 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.
    r   z%s%dé   )r   )r=   r?   rA   r'   s       r/   r   r   ¢   sG   € ð. €GØ�‚{€{Ø˜G WÐ-Ñ-ˆà�*ÐÐÝ" 4¨°W¸q±[ÑAÔAÐAà€Nr1   c                 ó   — dS )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
    Nr   r   r1   r/   ÚtestrF   Ã   s   € € € r1   Ú__main__N)r   )r	   r   r
   r   r   r   r   r   )r
   r2   r   r3   )r   )r=   r>   r?   r@   rA   rB   r   r>   )Ú
__future__r   Útypingr   r   Úcollections.abcr   ÚfontTools.annotationsr   r0   r   r   rF   Ú__name__ÚdoctestÚtestmodr   r1   r/   ú<module>rO      sù   ðØ "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à /Ð /Ð /Ð /Ð /Ð /ðð VXðJYð JYð JYð JYð JYðZ?%ð ?%ð ?%ð ?%ðDð ð ð ð ðBNð Nð Nðb ˆzÒÐØ€N€N€Nà€G„OÑÔÐÐÐð Ðr1   