§
    ÛóÉj   ã                  ó˜   — d dl mZ d dlmZ d dlmZmZmZmZ e	e
e
f         Z	 	 	 ddd„Zdd„Zedk    rd dlZ ej        ¦   «          dS dS )é    )Úannotations)ÚOptional)ÚKerningPairÚKerningDictÚKerningGroupsÚIntFloatNÚpairr   Úkerningr   Úgroupsr   Úfallbackr   ÚglyphToFirstGroupúOptional[StrDict]ÚglyphToSecondGroupÚreturnc                óž  ‡‡— | |v r||          S |du |du k    rt          d¦  «        ‚|�|€t          |¦  «        \  }}| \  }}dx}Š|                     d¦  «        r|}d}	n|                     |¦  «        }|}	|                     d¦  «        r|ŠdŠn|                     |¦  «        Š|Šˆˆfd„|	|fD ¦   «         }
|
D ]} | |v r
||          c S Œ|S )a*  Retrieve the kerning value (if any) between a pair of elements.

    The elements can be either individual glyphs (by name) or kerning
    groups (by name), or any combination of the two.

    Providing the two glyph-to-group mappings accelerates group-lookups.
    These can be built manually, or with :py:func:`glyphsToGroups`.

    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 dictionary mapping each group name to its glyph names.
      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
      >>> glyphToFirstGroup, glyphToSecondGroup = glyphsToGroups(groups)
      >>> lookupKerningValue(("O", "E"), kerning, groups, glyphToFirstGroup=glyphToFirstGroup, glyphToSecondGroup=glyphToSecondGroup)
      -100
    NzKMust provide both 'glyphToFirstGroup' and 'glyphToSecondGroup', or neither.úpublic.kern1.úpublic.kern2.c                ó.   •— g | ]}‰‰fD ]
}|®|®||f‘ŒŒS )N© )Ú.0ÚaÚbÚsecondGlyphÚsecondGroups      €€ú}/home/lighthouse/badge-speaker-benchmark/.benchmark-venv-community/lib64/python3.11/site-packages/fontTools/ufoLib/kerning.pyú
<listcomp>z&lookupKerningValue.<locals>.<listcomp>w   sI   ø€ ð ð ð àØ˜{Ð+ðð ð Øˆ=˜Q˜]ð 
ˆAˆð +˜]˜]˜]ó    )Ú
ValueErrorÚglyphsToGroupsÚ
startswithÚget)r	   r
   r   r   r   r   ÚfirstÚsecondÚ
firstGroupÚ
firstGlyphÚpairsr   r   s              @@r   ÚlookupKerningValuer'   
   sV  øø€ ðf ˆw€€Ø�tŒ}Ðà˜TÐ!Ð'9¸TÐ'AÒBÐBÝØYñ
ô 
ð 	
ð Ð Ð$6Ð$>Ý0>¸vÑ0FÔ0FÑ-ÐÐ-à�M€Eˆ6Ø#Ð#€J�Ø×Ò˜Ñ(Ô(ð Øˆ
Øˆ
ˆ
à&×*Ò*¨5Ñ1Ô1ˆ
Øˆ
Ø×Ò˜Ñ)Ô)ð ØˆØˆˆà(×,Ò,¨VÑ4Ô4ˆØˆðð ð ð ð à˜jÐ)ðñ ô €Eð ð !ð !ˆØ�7ˆ?ˆ?Ø˜4”=Ð Ð Ð ð ð €Or   útuple[StrDict, StrDict]c                óÄ   — i }i }|                       ¦   «         D ]D\  }}|                     d¦  «        r|D ]}|||<   ŒŒ%|                     d¦  «        r
|D ]}|||<   ŒŒE||fS )ae  Build dictionaries mapping glyph names to their kerning groups.

    This is a reverse-mapping of the UFO kerning groups data structure.
    Groups are assumed to be compliant with the UFO specification; with
    the current implementation, if glyphs appear in more than one group
    anyway, the last group wins.

    Args:
      groups:
          A dictionary mapping each group name to its glyph names.

    Returns:
      A tuple of two dictionaries, respectively mapping glyph names to
      the first- and second-glyph kerning groups to which they belong.

    Examples::

      >>> groups = {
      ...     "public.kern1.O" : ["O", "D", "Q"],
      ...     "public.kern2.E" : ["E", "F"]
      ... }
      >>> glyphsToGroups(groups)
      ({'O': 'public.kern1.O', 'D': 'public.kern1.O', 'Q': 'public.kern1.O'}, {'E': 'public.kern2.E', 'F': 'public.kern2.E'})
    r   r   )Úitemsr    )r   r   r   ÚgroupÚgroupMembersÚglyphs         r   r   r   …   s¤   € ð2 ÐØÐØ%Ÿ|š|™~œ~ð 2ð 2Ñˆˆ|Ø×Ò˜OÑ,Ô,ð 	2Ø%ð 1ð 1�Ø+0Ð! %Ñ(Ð(ð1à×Ò˜oÑ.Ô.ð 	2Ø%ð 2ð 2�Ø,1Ð" 5Ñ)Ð)øØÐ1Ð2Ð2r   Ú__main__)r   NN)r	   r   r
   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r(   )Ú
__future__r   Útypingr   ÚfontTools.annotationsr   r   r   r   ÚdictÚstrÚStrDictr'   r   Ú__name__ÚdoctestÚtestmodr   r   r   ú<module>r8      sÍ   ðØ "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ Sà
ˆs�CˆxŒ.€ð Ø+/Ø,0ðxð xð xð xð xðv"3ð "3ð "3ð "3ðJ ˆzÒÐØ€N€N€Nà€G„OÑÔÐÐÐð Ðr   