o
    tBhB                     @  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 ddl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)AxisDescriptorDesignSpaceDocumentDiscreteAxisDescriptorInstanceDescriptorRuleDescriptorSimpleLocationDictSourceDescriptorVariableFontDescriptor)	StatNamesgetStatNames)RangeRegionConditionSet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&   u/var/www/html/riverr-enterprise-integrations-main/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|tr|| qt|j|j|j||j< qt	j
dd |D  }|D ]}dd t||D }	t| i ||	d|||d}
|	|
fV  q.d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
    c                 S  s   g | ]}|j qS r&   )values).0axisr&   r&   r'   
<listcomp>`   s    z%splitInterpolable.<locals>.<listcomp>c                 S  s   i | ]\}}|j |qS r&   )name)r0   discreteAxisvaluer&   r&   r'   
<dictcomp>b   s    z%splitInterpolable.<locals>.<dictcomp>TkeepVFsr)   r+   r,   N)axes
isinstancer   appendr   minimummaximumdefaultr3   	itertoolsproductzip_extractSubSpace)r   r)   r+   r,   discreteAxesinterpolableUserRegionr1   valueCombinationsr/   discreteUserLocationsubDocr&   r&   r'   splitInterpolable5   s0   "


rH   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
    Fr7   N)getVariableFontsr   rB   libr3   )r   r)   r+   r,   vfvfUserRegionvfDocr&   r&   r'   splitVariableFontsq   s   
rO   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)rH   rO   formatVersion)r   vfs	_locationrG   vfNamerN   r&   r&   r'   convert5to4   s   	
rU   
userRegionr   r8   c                  s  t  } fdd} jD ]<}|j ttrIt|trI|t|j|j|j|j	t
j|jjp4|jtj|jfdd|jD d d d
 qt }	t j|	|_ j|_ jD ]-}
t |
jsiq]|t|
j|
j|
j|
jt||
|
j|
j|
j |
j!|
j"|
j#d q]|$ } $ }|d ur|d ur|j%|_%|rȈ & D ]"}t' |}t(|r|)t*|j|jfdd|j+D |j,d q j-D ]}t|. sq|rpt/ |. }|jp|j01d	}|j p|j21d	}|3t4di d
|jp| ||d|jd|jd|jp| d| dri n|j5dt||d|d|d|j6p5|j6d|j7p@|j81d	d|j9pH|j9d|j%pP|j0d|j:pX|j2d|j;p`|j8d|j<pgi d|j, q|3t4di d
|jd|jd|jd|jdri n|j5dt||d|jd|j d|j6d|j7d|j9d|j%d|j:d|j;d|j<d|j, qˈ j,|_,|S )Nc                   s   r|   S | jS )N)getFullDesignLocationdesignLocation)object)r   r+   r&   r'   maybeExpandDesignLocation   s   
z3_extractSubSpace.<locals>.maybeExpandDesignLocationc                   s4   g | ]\}} j |  kr jkrn n||fqS r&   )r<   r=   )r0   userdesign)ranger&   r'   r2      s
    z$_extractSubSpace.<locals>.<listcomp>)
tagr3   
labelNameshiddenr<   r>   r=   mapaxisOrdering
axisLabels)filenamepathfontr3   rX   	layerNamer!   r$   muteKerningmuteInfomutedGlyphNamesc                   s    g | ]}t  |j tr|qS r&   )r:   r3   r   )r0   
axisSubsetrV   r&   r'   r2     s    )r3   rd   axisSubsetsrK   r   rd   re   rf   r3    userLocationrX   r!   r$   postScriptFontNamestyleMapFamilyNamestyleMapStyleNamelocalisedFamilyNamelocalisedStyleNamelocalisedStyleMapFamilyNamelocalisedStyleMapStyleNamerK   r&   )=r
   r9   r3   r:   r   r	   addAxisr^   r_   r`   maxr<   r>   minr=   ra   r   _subsetRulesBasedOnConditionsrulesrulesProcessingLastsourcesr   map_backwardrX   	addSourcer   rd   re   rf   _filterLocationrg   r!   r$   rh   ri   rj   findDefaultrs   rJ   r   r   addVariableFontr   rm   rK   	instancesgetFullUserLocationr   r"   r#   r%   addInstancer   ro   rp   rq   styleMapFamilyNamesrr   rt   ru   rv   )r   rV   r8   r)   r+   r,   rG   rZ   r1   designRegionsource	vfDefault
oldDefaultrL   rM   r   r   r!   r$   r&   )r   r+   r]   rV   r'   rB      sL  	













	
rB   conditionSetList[Dict[str, Any]]r   c                 C  s:   i }| D ]}t |dtj |dtj||d < q|S )Nr<   r=   r3   )r   r#   mathinf)r   c	conditionr&   r&   r'   _conditionSetFromU  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)r3   conditionSetssubsFT)r3   r<   r=   )r   r3   r   r   r   itemsr:   floatintintersectionr;   r<   r=   )r{   r   newRulesrulenewRuleconditionsetcsnewConditionsetdiscardConditionsetselectionNameselectionValuer   r&   r&   r'   rz   _  sD   

	
rz   locationDict[str, float]c                   s    fdd|  D S )Nc                   s,   i | ]\}}| v rt  | tr||qS r&   )r:   r   )r0   r3   r5   rl   r&   r'   r6     s
    z#_filterLocation.<locals>.<dictcomp>)r   )rV   r   r&   rl   r'   r     s   
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   rI   )r   r
   r   rP   )r   r
   rV   r   r8   r*   r)   r*   r+   r*   r,   r-   r   r
   )r   r   r   r   )r{   r   r   r   r   r   )rV   r   r   r   r   r   ).__doc__
__future__r   r?   loggingr   typingr   r   r   r   r   r   fontTools.designspaceLibr	   r
   r   r   r   r   r   r   "fontTools.designspaceLib.statNamesr   r   fontTools.designspaceLib.typesr   r   r   r   r   r   r   	getLogger__name__LOGGERr   r-   r(   rH   rO   rU   rB   r   rz   r   r&   r&   r&   r'   <module>   s8     (
$


>
%
 
/

A