
    Ngm#                        d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
Z
ddlmZmZmZmZmZmZmZ  e
j        e          ZeZddd	d
dZe G d d                      ZddZddZddZd dZdS )!a-  Compute name information for a given location in user-space coordinates
using STAT data. This can be used to fill-in automatically the names of an
instance:

.. code:: python

    instance = doc.instances[0]
    names = getStatNames(doc, instance.getFullUserLocation(doc))
    print(names.styleNames)
    )annotations)	dataclass)DictOptionalTupleUnionN)AxisDescriptorAxisLabelDescriptorDesignSpaceDocumentDesignSpaceDocumentErrorDiscreteAxisDescriptorSimpleLocationDictSourceDescriptorregularitalicboldzbold italic))FF)FT)TF)TTc                  F    e Zd ZU dZded<   ded<   ded<   ded<   ded	<   d
S )	StatNamesz4Name data generated from the STAT table information.zDict[str, str]familyNames
styleNameszOptional[str]postScriptFontNamestyleMapFamilyNameszOptional[RibbiStyle]styleMapStyleNameN)__name__
__module____qualname____doc____annotations__     ^/var/www/html/ai-engine/env/lib/python3.11/site-packages/fontTools/designspaceLib/statNames.pyr   r   )   sT         >>%%%%''''++++++r    r   docr   userLocationr   returnc                P   i }|                                  }|t                              d           n2|j        t                              d           nd|j        i|j        }i }|                     |          }|d|j        i|j        }nt          | j	        |          }|rit          d |D                       }|                    d           |D ]8d                    fd|D                       }|s| j        | j        }||<   9d|vsd|vrt          ||di d          S |d          d	|d                              dd
          }	t!          | |          \  }
}|}||k    rt#          | |          }|j        }i }t          |                              |                                          D ]W|                    |d                   }|                    |d                   }|dz   |z                                   |<   Xt          |||	||
          S )aq  Compute the family, style, PostScript names of the given ``userLocation``
    using the document's STAT information.

    Also computes localizations.

    If not enough STAT data is available for a given name, either its dict of
    localized names will be empty (family and style names), or the name will be
    None (PostScript name).

    .. versionadded:: 5.0
    Nz7Cannot determine default source to look up family name.zTCannot look up family name, assign the 'familyname' attribute to the default source.enc              3  .   K   | ]}|j         D ]}|V  d S N)
labelNames.0labellanguages      r!   	<genexpr>zgetStatNames.<locals>.<genexpr>\   sJ        "U=M 19      r     c              3  f   K   | ]+}|j         	|j                            |j                  V  ,d S r(   )elidabler)   getdefaultNamer*   s     r!   r.   zgetStatNames.<locals>.<genexpr>a   sU       % % >%$((53DEE% % % % % %r    )r   r   r   r   r   - )findDefaultLOGGERwarning
familyNamelocalisedFamilyNamelabelForUserLocationnamer)   _getAxisLabelsForUserLocationaxessetaddjoinelidedFallbackNamer   replace_getRibbiStylegetStatNamesr   unionkeysr2   strip)r"   r#   r   defaultSourcer   r,   labels	languages	styleNamer   r   regularUserLocationstyleNamesForStyleMapregularStatNamesr   r9   r-   s                   @r!   rE   rE   4   s    #%K030A0AMPQQQQ		!	)b	
 	
 	
 	

 -*
/

 "$J$$\22EEJ;%*:;

 /sxFF 	1  &,    I MM$% 1 1HH % % % %!'% % %  	
 ! 7S%;%G # 6I'0
8$$;$j"8"8#!# ""
 
 
 	
 (-BB
40@BBJJ3PRSS-;C-N-N**&l**'-@AA 0 ;$$**:??+<+<== O O __X{4/@AA
)--h8Md8STT	)3c)9I)E(L(L(N(NH%%-/+   r    r>   3list[Union[AxisDescriptor, DiscreteAxisDescriptor]]$Dict[str, list[AxisLabelDescriptor]]c                    t          d | D             d           }d |D             }| D ]}|j        |j        ||j        <   |S )zbReturns axis labels sorted by their ordering, with unordered ones appended as
    they are listed.c              3  (   K   | ]}|j         	|V  d S r(   axisOrderingr+   axiss     r!   r.   z'_getSortedAxisLabels.<locals>.<genexpr>   s*      @@$$"3"?"?"?"?"?@@r    c                    | j         S r(   rT   )as    r!   <lambda>z&_getSortedAxisLabels.<locals>.<lambda>   s    an r    )keyc                (    i | ]}|j         |j        S r   )r<   
axisLabelsrV   s     r!   
<dictcomp>z(_getSortedAxisLabels.<locals>.<dictcomp>   s+     : : :'+	4?: : :r    )sortedrU   r]   r<   )r>   
sortedAxessortedLabelsrW   s       r!   _getSortedAxisLabelsrb      s|     @@$@@@$$  J: :/9: : :L  6 6$&*oL#r    list[AxisLabelDescriptor]c                   g }t          |           }|                                |                                k    rEt                              d|                                 d|                                 d           |                                D ]b\  }}||         t          fd|D             d           }|"t                              d| d d           M|                    |           c|S )Nz Mismatch between user location 'z' and available labels for 'z'.c              3     K   | ]9}|j         k    s(|j        %|j        |j        cxk    r|j        k    2n n|V  :d S r(   )	userValueuserMinimumuserMaximum)r+   lrf   s     r!   r.   z0_getAxisLabelsForUserLocation.<locals>.<genexpr>   su       	 	;)++M-1CCCCamCCCCC  DCCC	 	r    z!Document needs a label for axis 'z', user value ')rb   rG   r7   r8   itemsnextdebugappend)r>   r#   rJ   allAxisLabelsaxisNamer]   r,   rf   s          @r!   r=   r=      sE    )+F(..M|0022224|/@/@/B/B 4 4(--//4 4 4	
 	
 	

 !. 3 3 5 5 ! !* *	/3	 	 	 	#	 	 	 0
 0
 =LLZHZZYZZZ    MM%    Mr    self%Tuple[RibbiStyle, SimpleLocationDict]c                    i }d | j         D             }d}d}|                    d          }|C|j        D ];}|j        ||j                 k    r#|j        |j        k     r|j        ||j        <   d} n<|                    d          p|                    d          }|]|j        D ]U}|j        ||j                 k    r=t          |j                  t          |j                  k     r|j        ||j        <   d} nVt          ||f         i ||fS )zCompute the RIBBI style name of the given user location,
    return the location of the matching Regular in the RIBBI group.

    .. versionadded:: 5.0
    c                    i | ]
}|j         |S r   )tagrV   s     r!   r^   z"_getRibbiStyle.<locals>.<dictcomp>   s    888d48T888r    FwghtNTitalslnt)r>   r2   r]   linkedUserValuer<   rf   absBOLD_ITALIC_TO_RIBBI_STYLE)	rp   r#   rM   axes_by_tagr   r   rW   regular_labelupright_labels	            r!   rD   rD      sK    88di888KDF??6""D!_ 	 	M-di1HHH "+m.KKK1>1H#DI.??6""=koof&=&=D!_ 	 	M-di1HHH /003}7T3U3UUU1>1H#DI.%dFl3 6
6
6  r    )r"   r   r#   r   r$   r   )r>   rP   r$   rQ   )r>   rP   r#   r   r$   rc   )rp   r   r#   r   r$   rq   )r   
__future__r   dataclassesr   typingr   r   r   r   loggingfontTools.designspaceLibr	   r
   r   r   r   r   r   	getLoggerr   r7   str
RibbiStylerz   r   rE   rb   r=   rD   r   r    r!   <module>r      s  	 	 # " " " " " ! ! ! ! ! ! / / / / / / / / / / / /                   
	8	$	$ 
	   , , , , , , , ,U U U Up   0# # # #L3 3 3 3 3 3r    