
    jkel#                       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y)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                  D    e Zd ZU dZded<   ded<   ded<   ded<   ded	<   y
)	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__     D/usr/lib/python3/dist-packages/fontTools/designspaceLib/statNames.pyr   r   (   s#    >%%''++r    r   c                   i }| j                         }|t        j                  d       n<|j                  t        j                  d       nd|j                  i|j                  }i }| j                  |      }|d|j                  i|j                  }n{t        | j                  |      }|rct        d |D              }|j                  d       |D ];  dj                  fd|D              }|s| j                  | j                  }||<   = d|vsd|vrt        ||di d      S |d    d	|d    j                  dd
      }	t!        | |      \  }
}|}||k7  rt#        | |      }|j$                  }i }t        |      j'                  |j)                               D ]E  |j+                  |d         }|j+                  |d         }|dz   |z   j-                         |<   G t        |||	||
      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  B   K   | ]  }|j                   D ]  }|   y wN)
labelNames.0labellanguages      r!   	<genexpr>zgetStatNames.<locals>.<genexpr>[   s-      "U=M=M19s    c              3     K   | ]6  }|j                   s(|j                  j                  |j                         8 y wr%   )elidabler&   getdefaultNamer'   s     r!   r+   zgetStatNames.<locals>.<genexpr>`   s9      % >> $$((53D3DE%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)docuserLocationr   defaultSourcer   r)   labels	languages	styleNamer   r   regularUserLocationstyleNamesForStyleMapregularStatNamesr   r6   r*   s                   @r!   rB   rB   3   sQ    #%K030AMPQ		!	!	)b	

 -**
//

 "$J$$\2EEJJ;%*:*:;
 /sxxF &, I MM$% 1HH %!'% 	
 !S%;%;%G # 6 6I'0
8$1 ;$j"8#!# ""
 	
 (-.a
40@/ABJJ3PRS-;C-N**&l*'-@A 0 ; ;$**:??+<= O __X{4/@A
)--h8Md8ST	)3c)9I)E(L(L(NH%O
 -/+ r    c                    t        d | D        d       }|D ci c]  }|j                  |j                   }}| D ](  }|j                  |j                  ||j                  <   * |S c c}w )zbReturns axis labels sorted by their ordering, with unordered ones appended as
    they are listed.c              3  :   K   | ]  }|j                   |  y wr%   axisOrdering)r(   axiss     r!   r+   z'_getSortedAxisLabels.<locals>.<genexpr>   s     @$$"3"3"?@s   c                    | j                   S r%   rQ   )as    r!   <lambda>z&_getSortedAxisLabels.<locals>.<lambda>   s
    ann r    )key)sortedr9   
axisLabelsrR   )r;   
sortedAxesrS   sortedLabelss       r!   _getSortedAxisLabelsr\      s~     @$@$J
 0::'+		4??":L :  6$&*ooL#6 :s   A)c                   g }t        |       }|j                         |j                         k7  r8t        j                  d|j                          d|j                          d       |j	                         D ]O  \  }}||   t        fd|D        d       }|t        j                  d| d d       ?|j                  |       Q |S )Nz Mismatch between user location 'z' and available labels for 'z'.c              3     K   | ]O  }|j                   k(  s:|j                  2|j                  &|j                  cxk  r|j                  k  rn n| Q y wr%   )	userValueuserMinimumuserMaximum)r(   lr_   s     r!   r+   z0_getAxisLabelsForUserLocation.<locals>.<genexpr>   sN      	;;)+MM-1CammC 	s   AAz!Document needs a label for axis 'z', user value ')r\   rD   r4   r5   itemsnextdebugappend)r;   rG   rI   allAxisLabelsaxisNamerY   r)   r_   s          @r!   r:   r:      s     )+F(.M|0022.|/@/@/B.C D(--/04	

 !. 3 3 5 !* *	/3	#	 0
 =LL3H:_YKWYZ MM% )!, Mr    c                   i }| j                   D ci c]  }|j                  | }}d}d}|j                  d      }|d|j                  D ]U  }|j                  ||j
                     k(  s |j                  |j                  k  s:|j                  ||j
                  <   d} n |j                  d      xs |j                  d      }|v|j                  D ]g  }|j                  ||j
                     k(  s t        |j                        t        |j                        k  sL|j                  ||j
                  <   d} n t        ||f   i ||fS c c}w )zCompute the RIBBI style name of the given user location,
    return the location of the matching Regular in the RIBBI group.

    .. versionadded:: 5.0
    FwghtTitalslnt)	r;   tagr/   rY   linkedUserValuer9   r_   absBOLD_ITALIC_TO_RIBBI_STYLE)	selfrG   rL   rS   axes_by_tagr   r   regular_labelupright_labels	            r!   rA   rA      sb    .2ii8d488T>8K8DF??6"D!__ 	M--dii1HH "++m.K.KK1>1H1H#DII.	 ??6"=koof&=D!__ 	M--dii1HH //03}7T7T3UU1>1H1H#DII.	  &dFl3 6
6
6  O 9s   E)rF   r   rG   r   returnr   )r;   3list[Union[AxisDescriptor, DiscreteAxisDescriptor]]ru   z$Dict[str, list[AxisLabelDescriptor]])r;   rv   rG   r   ru   zlist[AxisLabelDescriptor])rq   r   rG   r   ru   z%Tuple[RibbiStyle, SimpleLocationDict])r   
__future__r   dataclassesr   typingr   r   r   r   loggingfontTools.designspaceLibr	   r
   r   r   r   r   r   	getLoggerr   r4   str
RibbiStylerp   r   rB   r\   r:   rA   r   r    r!   <module>r      s   	 # ! / /    
		8	$ 
	  , , ,U	U,>UUp
=)0#
=#$# #L3
3-?3*3r    