o
    hm#                     @  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Zd"ddZd#ddZ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SourceDescriptor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   v/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fontTools/designspaceLib/statNames.pyr   )   s   
 r   docr
   userLocationr   returnc                   s  i }|   }|du rtd n|jdu rtd nd|ji|j}i }| |}|dur7d|ji|j}n5t| j	|}|rlt
dd |D }|d |D ] d fdd|D }|sg| jdurg| j}|| < qOd|vstd|vr}t||di dd	S |d  d
|d  dd}	t| |\}
}|}||krt| |}|j}i }t
|| D ] | |d }| |d }|d |  | < qt|||	||
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#   )elidabler$   getdefaultName)r%   r&   r'   r   r   r(   a   s    
)r   r   r   r   r   - )findDefaultLOGGERwarning
familyNamelocalisedFamilyNamelabelForUserLocationnamer$   _getAxisLabelsForUserLocationaxessetaddjoinelidedFallbackNamer   replace_getRibbiStylegetStatNamesr   unionkeysr+   strip)r   r    r   defaultSourcer   r&   labels	languages	styleNamer   r   regularUserLocationstyleNamesForStyleMapregularStatNamesr   r3   r   r-   r   r?   4   sn   




r?   r8   3list[Union[AxisDescriptor, DiscreteAxisDescriptor]]$Dict[str, list[AxisLabelDescriptor]]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(      s    z'_getSortedAxisLabels.<locals>.<genexpr>c                 S  s   | j S r#   rL   )ar   r   r   <lambda>   s    z&_getSortedAxisLabels.<locals>.<lambda>)keyc                 S  s   i | ]}|j |jqS r   )r6   
axisLabelsrN   r   r   r   
<dictcomp>   s    
z(_getSortedAxisLabels.<locals>.<dictcomp>N)sortedrM   rS   r6   )r8   
sortedAxessortedLabelsrO   r   r   r   _getSortedAxisLabels   s   
rX   list[AxisLabelDescriptor]c                   s   g }t | }| | krtd|  d|  d | D ]*\}}||  t fdd|D d }|d u rGtd| d  d q"|| q"|S )Nz Mismatch between user location 'z' and available labels for 'z'.c                 3  sN    | ]"}|j  ks!|jd ur$|jd ur$|j   kr|jkrn n|V  qd S r#   )	userValueuserMinimumuserMaximum)r%   lrZ   r   r   r(      s    


z0_getAxisLabelsForUserLocation.<locals>.<genexpr>z!Document needs a label for axis 'z', user value ')rX   rA   r1   r2   itemsnextdebugappend)r8   r    rD   allAxisLabelsaxisNamerS   r&   r   r^   r   r7      s,   

r7   self%Tuple[RibbiStyle, SimpleLocationDict]c           	      C  s   i }dd | j D }d}d}|d}|dur5|jD ]}|j||j kr4|j|jk r4|j||j< d} nq|dp>|d}|dure|jD ]}|j||j krdt|jt|jk rd|j||j< d} nqFt||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   )tagrN   r   r   r   rT      s    z"_getRibbiStyle.<locals>.<dictcomp>FwghtNTitalslnt)r8   r+   rS   linkedUserValuer6   rZ   absBOLD_ITALIC_TO_RIBBI_STYLE)	re   r    rG   axes_by_tagr   r   rO   regular_labelupright_labelr   r   r   r>      s6   


r>   )r   r
   r    r   r!   r   )r8   rJ   r!   rK   )r8   rJ   r    r   r!   rY   )re   r
   r    r   r!   rf   )r   
__future__r   dataclassesr   typingr   r   r   r   loggingfontTools.designspaceLibr   r	   r
   r   r   r   r   	getLoggerr   r1   str
RibbiStylerm   r   r?   rX   r7   r>   r   r   r   r   <module>   s&    $




X
&