a
    w=icqE                     @  sv  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 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&dd	d
ddddZ'dde'fddddddddZ(dde'fddddddddZ)dddddZ*ddddddddd d!Z+d"d#d$d%d&Z,d'dd'd(d)d*Z-dd+d+d,d-d.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DesignSpaceDocumentDiscreteAxisDescriptorInstanceDescriptorRuleDescriptorSimpleLocationDictSourceDescriptorVariableFontDescriptor)	StatNamesgetStatNames)ConditionSetRangeRegiongetVFUserRegionlocationInRegionregionInRegionuserRegionToDesignRegionr   r   r   str)docinstance	statNamesreturnc                 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'   o/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/fontTools/designspaceLib/split.pydefaultMakeInstanceFilename(   s    r)   TboolMakeInstanceFilenameCallablez8Iterator[Tuple[SimpleLocationDict, DesignSpaceDocument]])r   	makeNamesexpandLocationsmakeInstanceFilenamer   c              	   c  s   g }i }| j D ]F}t|dr2t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  qnd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'   )r/   ).0axisr'   r'   r(   
<listcomp>g       z%splitInterpolable.<locals>.<listcomp>c                 S  s   i | ]\}}|j |qS r'   )name)r0   ZdiscreteAxisvaluer'   r'   r(   
<dictcomp>i   s   z%splitInterpolable.<locals>.<dictcomp>TkeepVFsr,   r-   r.   N)axeshasattrr	   r   appendr
   r   minimummaximumdefaultr4   	itertoolsproductzip_extractSubSpace)r   r,   r-   r.   ZdiscreteAxesZinterpolableUserRegionr1   ZvalueCombinationsr/   ZdiscreteUserLocationsubDocr'   r'   r(   splitInterpolable5   s4    "




rD   Fz)Iterator[Tuple[str, DesignSpaceDocument]]c              	   c  sN   |   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   libr4   )r   r,   r-   r.   vfvfUserRegionvfDocr'   r'   r(   splitVariableFontsx   s    
rJ   zDict[str, DesignSpaceDocument])r   r   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)rD   rJ   ZformatVersion)r   ZvfsZ	_locationrC   ZvfNamerI   r'   r'   r(   convert5to4   s    	rK   r   )r   
userRegionr8   r,   r-   r.   r   c                  s,  t  } fdd} jD ]}|j ttrt|drtt|}|t|j	|j|j
|jtj|jjpr|jtj|jfdd|jD d d d
 qt }	t j|	|_ j|_ jD ]Z}
t |
jsq|t|
j|
j|
j|
jt||
|
j |
j!|
j"|
j#|
j$|
j%d q|& } & }|d urL|d urL|j'|_'|r ( D ]H}t) |}t*|rZ|+t,|j|jfdd|j-D |j.d	 qZ j/D ]r}t|0 sƐq|rt1 |0 }|j!p|j23d
}|j"p|j43d
}|5t6|jp| |||j|j|jp8| d| rBi n|j7t|||||j8pb|j8|j9pt|j:3d
|j;p|j;|j'p|j2|j<p|j4|j=p|j:|j>pi |j.d n`|5t6|j|j|j|jri n|j7t|||j!|j"|j8|j9|j;|j'|j<|j=|j>|j.d q j.|_.|S )Nc                   s   r|   S | jS d S )N)ZgetFullDesignLocationdesignLocation)object)r   r-   r'   r(   maybeExpandDesignLocation   s    
z3_extractSubSpace.<locals>.maybeExpandDesignLocationr<   c                   s4   g | ],\}} j |  kr$ jkrn q||fqS r'   )r<   r=   )r0   userZdesign)ranger'   r(   r2      s   z$_extractSubSpace.<locals>.<listcomp>)
tagr4   
labelNameshiddenr<   r>   r=   mapZaxisOrderingZ
axisLabels)filenamepathfontr4   rM   	layerNamer"   r%   muteKerningmuteInfomutedGlyphNamesc                   s    g | ]}t  |j tr|qS r'   )
isinstancer4   r   )r0   Z
axisSubsetrL   r'   r(   r2     s   )r4   rV   axisSubsetsrF   r     )rV   rW   rX   r4   userLocationrM   r"   r%   postScriptFontNamestyleMapFamilyNamestyleMapStyleNamelocalisedFamilyNamelocalisedStyleNamelocalisedStyleMapFamilyNamelocalisedStyleMapStyleNamerF   )?r   r9   r4   r]   r   r:   r	   r
   ZaddAxisrR   rS   rT   maxr<   r>   minr=   rU   r   _subsetRulesBasedOnConditionsrulesZrulesProcessingLastsourcesr   Zmap_backwardrM   Z	addSourcer   rV   rW   rX   _filterLocationrY   r"   r%   rZ   r[   r\   ZfindDefaultre   rE   r   r   ZaddVariableFontr   r_   rF   Z	instancesZgetFullUserLocationr   r#   r$   r&   ZaddInstancer   ra   rb   rc   ZstyleMapFamilyNamesrd   rf   rg   rh   )r   rL   r8   r,   r-   r.   rC   rO   r1   designRegionsourceZ	vfDefaultZ
oldDefaultrG   rH   r   r   r"   r%   r'   )r   r-   rQ   rL   r(   rB      s    	











rB   zList[Dict[str, Any]]r   )conditionSetr   c                 C  sX   i }| D ]J}| d| d }}t|d ur0|ntj |d urB|ntj||d < q|S )Nr<   r=   r4   )r$   r   mathinf)rq   c	conditionr<   r=   r'   r'   r(   _conditionSetFrom`  s    rv   zList[RuleDescriptor])rl   ro   r   c              	   C  s   g }| D ]}t |jg |jd}|jD ]}t|}g }d}| D ]t\}	}
|	|vrRq@t|
ttfrt|
||	 v rnqd}q@|
||	 v rq@||	 	|
}|d ur|
|	|j|jd q@d}q@|s$|j
| q$|jr|
| q|S )N)r4   conditionSetssubsFT)r4   r<   r=   )r   r4   rx   rw   rv   itemsr]   floatintintersectionr;   r<   r=   )rl   ro   ZnewRulesruleZnewRuleZconditionsetcsZnewConditionsetZdiscardConditionsetZselectionNameZselectionValuer|   r'   r'   r(   rk   k  s@    

	rk   zDict[str, float])rL   locationr   c                   s    fdd|  D S )Nc                   s,   i | ]$\}}| v rt  | tr||qS r'   )r]   r   )r0   r4   r5   r^   r'   r(   r6     s   z#_filterLocation.<locals>.<dictcomp>)ry   )rL   r   r'   r^   r(   rn     s    
rn   )/__doc__
__future__r   r?   loggingrr   typingr   r   r   r   r   r   r	   ZfontTools.designspaceLibr
   r   r   r   r   r   r   r   Z"fontTools.designspaceLib.statNamesr   r   ZfontTools.designspaceLib.typesr   r   r   r   r   r   r   	getLogger__name__LOGGERr   r+   r)   rD   rJ   rK   rB   rv   rk   rn   r'   r'   r'   r(   <module>   s6   $(
$

E% 3A