a
    w=icl#                     @  s   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
eZeZddd	d
dZeG dd dZddddddZdddddZddddddZdddd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SourceDescriptorZregularitalicboldzbold italic))FF)FT)TF)TTc                   @  s:   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__ r   r   s/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/fontTools/designspaceLib/statNames.pyr   (   s   
r   r
   r   )docuserLocationreturnc                   s  i }|   }|du r td n&|jdu r6td nd|ji|j}i }| |}|durnd|ji|j}njt| j	|}|rt
dd |D }|d |D ]8 d fdd|D }|s| jdur| j}|| < qd|vsd|vrt||di dd	S |d  d
|d  dd}	t| |\}
}|}||krDt| |}|j}i }t
|| D ]: | |d }| |d }|d |  | < qZt|||	||
d	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                 s  s   | ]}|j D ]
}|V  qqd S N)
labelNames).0labellanguager   r   r   	<genexpr>[   s   zgetStatNames.<locals>.<genexpr> c                 3  s$   | ]}|j s|j |jV  qd S r"   )Zelidabler#   getdefaultName)r$   r%   r&   r   r   r'   `   s   )r   r   r   r   r   - )ZfindDefaultLOGGERwarning
familyNameZlocalisedFamilyNameZlabelForUserLocationnamer#   _getAxisLabelsForUserLocationaxessetaddjoinZelidedFallbackNamer   replace_getRibbiStylegetStatNamesr   unionkeysr)   strip)r   r   r   ZdefaultSourcer   r%   labels	languagesZ	styleNamer   r   regularUserLocationZstyleNamesForStyleMapZregularStatNamesr   r0   r   r+   r   r9   3   sn    





r9   z3list[Union[AxisDescriptor, DiscreteAxisDescriptor]]z$Dict[str, list[AxisLabelDescriptor]])r3   r    c                 C  sL   t dd | D dd d}dd |D }| D ]}|jdu r,|j||j< q,|S )	zbReturns axis labels sorted by their ordering, with unordered ones appended as
    they are listed.c                 s  s   | ]}|j d ur|V  qd S r"   axisOrderingr$   axisr   r   r   r'          z'_getSortedAxisLabels.<locals>.<genexpr>c                 S  s   | j S r"   r@   )ar   r   r   <lambda>   rD   z&_getSortedAxisLabels.<locals>.<lambda>)keyc                 S  s   i | ]}|j |jqS r   )r1   
axisLabelsrB   r   r   r   
<dictcomp>   s   z(_getSortedAxisLabels.<locals>.<dictcomp>N)sortedrA   rH   r1   )r3   Z
sortedAxesZsortedLabelsrC   r   r   r   _getSortedAxisLabels   s    
rK   zlist[AxisLabelDescriptor])r3   r   r    c                   s   g }t | }| | kr<td|  d|  d | D ]T\}}||  t fdd|D d }|d u rtd| d  d qD|| qD|S )Nz Mismatch between user location 'z' and available labels for 'z'.c                 3  sL   | ]D}|j  ks@|jd ur|jd ur|j   kr<|jkrn q|V  qd S r"   )	userValueZuserMinimumZuserMaximum)r$   lrL   r   r   r'      s   


z0_getAxisLabelsForUserLocation.<locals>.<genexpr>z!Document needs a label for axis 'z', user value ')rK   r;   r.   r/   itemsnextdebugappend)r3   r   r=   ZallAxisLabelsZaxisNamerH   r%   r   rN   r   r2      s,    

r2   z%Tuple[RibbiStyle, SimpleLocationDict])selfr   r    c           	      C  s   i }dd | j D }d}d}|d}|durj|jD ]4}|j||j kr4|j|jk r4|j||j< d} qjq4|dp||d}|dur|jD ]<}|j||j krt|jt|jk r|j||j< d} qqt||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                 S  s   i | ]}|j |qS r   )tagrB   r   r   r   rI      rD   z"_getRibbiStyle.<locals>.<dictcomp>FZwghtNTZitalZslnt)r3   r)   rH   ZlinkedUserValuer1   rL   absBOLD_ITALIC_TO_RIBBI_STYLE)	rS   r   r?   Zaxes_by_tagr   r   rC   Zregular_labelZupright_labelr   r   r   r8      s:    


	
	r8   )r   
__future__r   dataclassesr   typingr   r   r   r   loggingZfontTools.designspaceLibr   r	   r
   r   r   r   r   	getLoggerr   r.   strZ
RibbiStylerV   r   r9   rK   r2   r8   r   r   r   r   <module>   s$   
$


X&