o
    h'K                     @  s,  d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZmZ ddlmZmZmZmZm Z m!Z!m"Z" e#e$Z%eeeege&f Z'd5ddZ(dde(fd6ddZ)dde(fd7ddZ*d8d d!Z+d9d%d&Z,d:d*d+Z-d;d/d0Z.d<d3d4Z/dS )=zAllows building all the variable fonts of a DesignSpace version 5 by
splitting the document into interpolable sub-space, then into each VF.
    )annotationsN)AnyCallableDictIteratorListTuplecast)	AxisDescriptorAxisMappingDescriptorDesignSpaceDocumentDiscreteAxisDescriptorInstanceDescriptorRuleDescriptorSimpleLocationDictSourceDescriptorVariableFontDescriptor)	StatNamesgetStatNames)ConditionSetRangeRegiongetVFUserRegionlocationInRegionregionInRegionuserRegionToDesignRegiondocr   instancer   	statNamesr   returnstrc                 C  s4   |j p|jd}|jp|jd}| d| dS )zDefault callable to synthesize an instance filename
    when makeNames=True, for instances that don't specify an instance name
    in the designspace. This part of the name generation can be overriden
    because it's not specified by the STAT table.
    en-z.ttf)
familyNamefamilyNamesget	styleName
styleNames)r   r   r   r#   r&    r(   r/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fontTools/designspaceLib/split.pydefaultMakeInstanceFilename)   s   r*   T	makeNamesboolexpandLocationsmakeInstanceFilenameMakeInstanceFilenameCallable8Iterator[Tuple[SimpleLocationDict, DesignSpaceDocument]]c              	   c  s    g }i }| j D ]#}t|drtt|}|| qtt|}t|j|j|j	||j
< qtjdd |D  }|D ]}dd t||D }	t| i ||	d|||d}
|	|
fV  q8dS )	a  Split the given DS5 into several interpolable sub-designspaces.
    There are as many interpolable sub-spaces as there are combinations of
    discrete axis values.

    E.g. with axes:
        - italic (discrete) Upright or Italic
        - style (discrete) Sans or Serif
        - weight (continuous) 100 to 900

    There are 4 sub-spaces in which the Weight axis should interpolate:
    (Upright, Sans), (Upright, Serif), (Italic, Sans) and (Italic, Serif).

    The sub-designspaces still include the full axis definitions and STAT data,
    but the rules, sources, variable fonts, instances are trimmed down to only
    keep what falls within the interpolable sub-space.

    Args:
      - ``makeNames``: Whether to compute the instance family and style
        names using the STAT data.
      - ``expandLocations``: Whether to turn all locations into "full"
        locations, including implicit default axis values where missing.
      - ``makeInstanceFilename``: Callable to synthesize an instance filename
        when makeNames=True, for instances that don't specify an instance name
        in the designspace. This part of the name generation can be overridden
        because it's not specified by the STAT table.

    .. versionadded:: 5.0
    valuesc                 S  s   g | ]}|j qS r(   )r1   .0axisr(   r(   r)   
<listcomp>h       z%splitInterpolable.<locals>.<listcomp>c                 S  s   i | ]\}}|j |qS r(   name)r3   discreteAxisvaluer(   r(   r)   
<dictcomp>j   s    z%splitInterpolable.<locals>.<dictcomp>TkeepVFsr+   r-   r.   N)axeshasattrr	   r   appendr
   r   minimummaximumdefaultr8   	itertoolsproductzip_extractSubSpace)r   r+   r-   r.   discreteAxesinterpolableUserRegionr4   valueCombinationsr1   discreteUserLocationsubDocr(   r(   r)   splitInterpolable6   s8   "




rM   F)Iterator[Tuple[str, DesignSpaceDocument]]c              	   c  sP    |   D ] }t| |}t| |d|||d}i |j|j|_|j|fV  qdS )a$  Convert each variable font listed in this document into a standalone
    designspace. This can be used to compile all the variable fonts from a
    format 5 designspace using tools that can only deal with 1 VF at a time.

    Args:
      - ``makeNames``: Whether to compute the instance family and style
        names using the STAT data.
      - ``expandLocations``: Whether to turn all locations into "full"
        locations, including implicit default axis values where missing.
      - ``makeInstanceFilename``: Callable to synthesize an instance filename
        when makeNames=True, for instances that don't specify an instance name
        in the designspace. This part of the name generation can be overridden
        because it's not specified by the STAT table.

    .. versionadded:: 5.0
    Fr<   N)getVariableFontsr   rG   libr8   )r   r+   r-   r.   vfvfUserRegionvfDocr(   r(   r)   splitVariableFontsy   s   
rT   Dict[str, DesignSpaceDocument]c                 C  s:   i }t | D ]\}}t|D ]\}}d|_|||< qq|S )zConvert each variable font listed in this document into a standalone
    format 4 designspace. This can be used to compile all the variable fonts
    from a format 5 designspace using tools that only know about format 4.

    .. versionadded:: 5.0
    z4.1)rM   rT   formatVersion)r   vfs	_locationrL   vfNamerS   r(   r(   r)   convert5to4   s   	
rZ   
userRegionr   r=   c                  s  t  } fdd} jD ]A}|j ttrNt|drNtt|}|t|j	|j|j
|jtj|jjp9|jtj|jfdd|jD d d d
 qg  |_}	dd |jD  jD ]w}
tfd	d
|
j D spq_tfdd
|
j D std|
j|
j q_t }||
j  ||
j   jD ],}|j|vrq|j j|jksjd urj|jksj|jkrtd|j qq|	t|
j|
jd q_t }t j||_ j |_  j!D ]-}t" #|j$sq|%t&|j'|j(|j)|jt*|||j+|j,|j-|j.|j/|j0d q|1 } 1 }|d ur.|d ur.|j2|_2|rZ 3 D ]$}t4 |}t5|rX|6t7|j|j'fdd|j8D |j9d q5 j:D ]}t"|; sjq]|rt< |; }|j,p~|j=>d}|j-p|j?>d}|@tAd$i d|j'p| ||d|j(d|j)d|jp| d| dri n|jBdt*||d|d|d|jCp|jCd|jDp|jE>dd|jFp|jFd|j2p|j=d |jGp|j?d!|jHp|jEd"|jIpi d#|j9 q]|@tAd$i d|j'd|j(d|j)d|jdr"i n|jBdt*||d|j,d|j-d|jCd|jDd|jFd|j2d |jGd!|jHd"|jId#|j9 q] j9|_9|S )%Nc                   s   r|   S | jS N)getFullDesignLocationdesignLocation)object)r   r-   r(   r)   maybeExpandDesignLocation   s   
z3_extractSubSpace.<locals>.maybeExpandDesignLocationrA   c                   s4   g | ]\}} j |  kr jkrn n||fqS r(   )rA   rB   )r3   userdesign)ranger(   r)   r5      s
    z$_extractSubSpace.<locals>.<listcomp>)
tagr8   
labelNameshiddenrA   rC   rB   mapaxisOrdering
axisLabelsc                 S  s   h | ]}|j qS r(   r7   r2   r(   r(   r)   	<setcomp>   r6   z#_extractSubSpace.<locals>.<setcomp>c                 3      | ]}| v V  qd S r\   r(   r2   
subDocAxesr(   r)   	<genexpr>       z#_extractSubSpace.<locals>.<genexpr>c                 3  rk   r\   r(   r2   rl   r(   r)   rn      ro   zPIn axis mapping from input %s, some output axes are not in the variable-font: %szALimiting axis ranges used in <mapping> elements not supported: %s)inputLocationoutputLocation)filenamepathfontr8   r^   	layerNamer#   r&   muteKerningmuteInfomutedGlyphNamesc                   s    g | ]}t  |j tr|qS r(   )
isinstancer8   r   )r3   
axisSubsetr[   r(   r)   r5   :  s    )r8   rr   axisSubsetsrP   r!   rr   rs   rt   r8    userLocationr^   r#   r&   postScriptFontNamestyleMapFamilyNamestyleMapStyleNamelocalisedFamilyNamelocalisedStyleNamelocalisedStyleMapFamilyNamelocalisedStyleMapStyleNamerP   r(   )Jr   r>   r8   ry   r   r?   r	   r
   addAxisrd   re   rf   maxrA   rC   minrB   rg   axisMappingsallrp   keysrq   LOGGERerrorsetupdater@   r   r   _subsetRulesBasedOnConditionsrulesrulesProcessingLastsourcesr   map_backwardr^   	addSourcer   rr   rs   rt   _filterLocationru   r#   r&   rv   rw   rx   findDefaultr   rO   r   r   addVariableFontr   r|   rP   	instancesgetFullUserLocationr   r$   r%   r'   addInstancer   r~   r   r   styleMapFamilyNamesr   r   r   r   )r   r[   r=   r+   r-   r.   rL   r`   r4   mappingsmappingmappingAxesdesignRegionsource	vfDefault
oldDefaultrQ   rR   r   r   r#   r&   r(   )r   r-   rc   rm   r[   r)   rG      s  	


















	
rG   conditionSetList[Dict[str, Any]]r   c                 C  sX   i }| D ]%}| d| d}}t|d ur|ntj |d ur!|ntj||d < q|S )NrA   rB   r8   )r%   r   mathinf)r   c	conditionrA   rB   r(   r(   r)   _conditionSetFrom  s   r   r   List[RuleDescriptor]r   c              	   C  s   g }| D ]h}t |jg |jd}|jD ]Q}t|}g }d}| D ]:\}	}
|	|vr)q t|
ttfr:|
||	 v r7q d}q |
||	 v rAq ||	 	|
}|d urX|
|	|j|jd q d}q |sc|j
| q|jrl|
| q|S )N)r8   conditionSetssubsFT)r8   rA   rB   )r   r8   r   r   r   itemsry   floatintintersectionr@   rA   rB   )r   r   newRulesrulenewRuleconditionsetcsnewConditionsetdiscardConditionsetselectionNameselectionValuer   r(   r(   r)   r     sD   

	
r   locationDict[str, float]c                   s    fdd|  D S )Nc                   s,   i | ]\}}| v rt  | tr||qS r(   )ry   r   )r3   r8   r:   r{   r(   r)   r;     s
    z#_filterLocation.<locals>.<dictcomp>)r   )r[   r   r(   r{   r)   r     s   
r   )r   r   r   r   r   r   r   r    )
r   r   r+   r,   r-   r,   r.   r/   r   r0   )
r   r   r+   r,   r-   r,   r.   r/   r   rN   )r   r   r   rU   )r   r   r[   r   r=   r,   r+   r,   r-   r,   r.   r/   r   r   )r   r   r   r   )r   r   r   r   r   r   )r[   r   r   r   r   r   )0__doc__
__future__r   rD   loggingr   typingr   r   r   r   r   r   r	   fontTools.designspaceLibr
   r   r   r   r   r   r   r   r   "fontTools.designspaceLib.statNamesr   r   fontTools.designspaceLib.typesr   r   r   r   r   r   r   	getLogger__name__r   r    r/   r*   rM   rT   rZ   rG   r   r   r   r(   r(   r(   r)   <module>   s8    $,$


E
%
 
Y
A