o
    h                     @  s   d Z ddlmZ ddlmZmZmZ ddlZddl	m
Z
mZmZmZ ddlmZmZmZ ddlmZ d"ddZd#ddZd#ddZd$ddZd%d d!ZdS )&zFExtra methods for DesignSpaceDocument to generate its STAT table data.    )annotations)DictListUnionN)AxisLabelDescriptorDesignSpaceDocumentDesignSpaceDocumentErrorLocationLabelDescriptor)RegiongetVFUserRegionlocationInRegion)TTFontttFontr   docr   vfNamestrreturnNonec                 C  s   |  D ]	}|j|kr nqtd| t||}tdd t| dddD }tjj	j
| t||t|||jdurB|j|d	S d|d	S )
a  Build the STAT table for the variable font identified by its name in
    the given document.

    Knowing which variable we're building STAT data for is needed to subset
    the STAT locations to only include what the variable font actually ships.

    .. versionadded:: 5.0

    .. seealso::
        - :func:`getStatAxes()`
        - :func:`getStatLocations()`
        - :func:`fontTools.otlLib.builder.buildStatTable()`
    z&Cannot find the variable font by name c                 s  s    | ]}|j d kV  qdS )   N)
platformID).0nr r   i/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fontTools/varLib/stat.py	<genexpr>,   s    

z#buildVFStatTable.<locals>.<genexpr>namenamesr   N   )macNames)getVariableFontsr   r   r   anygetattrget	fontToolsotlLibbuilderbuildStatTablegetStatAxesgetStatLocationselidedFallbackName)r   r   r   vfregionr   r   r   r   buildVFStatTable   s*   

r,   
userRegionr
   
List[Dict]c                   sl   t dd | jD dd}g }| jD ]}|jdur||j q|d7 }|| q fddt| j|D S )	zReturn a list of axis dicts suitable for use as the ``axes``
    argument to :func:`fontTools.otlLib.builder.buildStatTable()`.

    .. versionadded:: 5.0
    c                 s  s     | ]}|j d ur|j V  qd S )N)axisOrderingr   axisr   r   r   r   B   s    zgetStatAxes.<locals>.<genexpr>)defaultNr   c              	     s@   g | ]\ }t  jd  ji j| fdd jD dqS )enc                   s&   g | ]}t  j|jirt|qS r   )r   r   	userValue_axisLabelToStatLocationr   label)r1   r-   r   r   
<listcomp>Q   s    z*getStatAxes.<locals>.<listcomp>.<listcomp>)tagr   orderingvalues)dictr:   r   
labelNames
axisLabels)r   r;   r-   )r1   r   r9   L   s    zgetStatAxes.<locals>.<listcomp>)maxaxesr/   appendzip)r   r-   maxOrderingaxisOrderingsr1   r   r@   r   r'   9   s   



r'   c                   s(   dd j D   fddjD S )zReturn a list of location dicts suitable for use as the ``locations``
    argument to :func:`fontTools.otlLib.builder.buildStatTable()`.

    .. versionadded:: 5.0
    c                 S  s   i | ]}|j |qS r   )r   r0   r   r   r   
<dictcomp>a   s    z$getStatLocations.<locals>.<dictcomp>c                   sR   g | ]%}t |rtd |ji|j fdd| D t|dqS )r4   c                   s   i | ]
\}} | j |qS r   )r:   )r   r   value)
axesByNamer   r   rG   g   s    
z/getStatLocations.<locals>.<listcomp>.<dictcomp>)r   locationflags)r   getFullUserLocationr=   r   r>   items_labelToFlagsr7   rI   r   r-   r   r   r9   b   s    
z$getStatLocations.<locals>.<listcomp>)rB   locationLabels)r   r-   r   rO   r   r(   [   s   r(   r8   3Union[AxisLabelDescriptor, LocationLabelDescriptor]intc                 C  s$   d}| j r	|dO }| jr|dO }|S )Nr   r   r   )olderSiblingelidable)r8   rK   r   r   r   rN   r   s   rN   r   r   c                 C  s   |   }d| ji| j}t| }|dkrt|| j|dS |dkr*t|| j| j|dS |dkrLt|| j|d}| jd ur@| j|d< | jd urJ| j|d	< |S t	d
)Nr4   r   )r   rH   rK      )r   rH   linkedValuerK   r   )r   nominalValuerK   rangeMinValuerangeMaxValuezUnknown STAT label format)
	getFormatr   r>   rN   r=   r5   linkedUserValueuserMinimumuserMaximumNotImplementedError)r8   label_formatr   rK   resr   r   r   r6   {   s0   



r6   )r   r   r   r   r   r   r   r   )r   r   r-   r
   r   r.   )r8   rQ   r   rR   )r8   r   r   r   )__doc__
__future__r   typingr   r   r   fontTools.otlLib.builderr#   fontTools.designspaceLibr   r   r   r	   fontTools.designspaceLib.typesr
   r   r   fontTools.ttLibr   r,   r'   r(   rN   r6   r   r   r   r   <module>   s    

'
"
	