a
    ZXh'K                     @  sz  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'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AxisMappingDescriptor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(   c/var/www/viveiro_mudafortebrasil/venv/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(   )r0   .0axisr(   r(   r)   
<listcomp>h       z%splitInterpolable.<locals>.<listcomp>c                 S  s   i | ]\}}|j |qS r(   name)r2   ZdiscreteAxisvaluer(   r(   r)   
<dictcomp>j   s   z%splitInterpolable.<locals>.<dictcomp>TkeepVFsr-   r.   r/   N)axeshasattrr	   r   appendr
   r   minimummaximumdefaultr7   	itertoolsproductzip_extractSubSpace)r   r-   r.   r/   ZdiscreteAxesZinterpolableUserRegionr3   ZvalueCombinationsr0   ZdiscreteUserLocationsubDocr(   r(   r)   splitInterpolable6   s4    "




rG   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
    Fr:   N)getVariableFontsr   rE   libr7   )r   r-   r.   r/   vfvfUserRegionvfDocr(   r(   r)   splitVariableFontsy   s    
rM   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)rG   rM   ZformatVersion)r   ZvfsZ	_locationrF   ZvfNamerL   r(   r(   r)   convert5to4   s    	rN   r   )r   
userRegionr;   r-   r.   r/   r    c                  sV  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g  |_}	dd |jD  jD ] }
tfd	d
|
j D sqtfdd
|
j D std|
j|
j qt }||
j  ||
j   jD ]h}|j|vrTq@|j j|jksjd urj|jksj|jkr@td|j q@q@|	t|
j|
jd qt }t j||_ j |_  j!D ]`}t" #|j$sq|%t&|j'|j(|j)|jt*|||j+|j,|j-|j.|j/|j0d q|1 } 1 }|d urv|d urv|j2|_2|rΈ 3 D ]H}t4 |}t5|r|6t7|j|j'fdd|j8D |j9d q j:D ]r}t"|; sq|rt< |; }|j,p|j=>d}|j-p,|j?>d}|@tA|j'pF| |||j(|j)|jpb| d| rli n|jBt*|||||jCp|jC|jDp|jE>d|jFp|jF|j2p|j=|jGp|j?|jHp|jE|jIpi |j9d n`|@tA|j'|j(|j)|jri n|jBt*|||j,|j-|jC|jD|jF|j2|jG|jH|jI|j9d qԈ j9|_9|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@   )r2   userZdesign)ranger(   r)   r4      s   z$_extractSubSpace.<locals>.<listcomp>)
tagr7   
labelNameshiddenr?   rA   r@   mapZaxisOrderingZ
axisLabelsc                 S  s   h | ]
}|j qS r(   r6   r1   r(   r(   r)   	<setcomp>   r5   z#_extractSubSpace.<locals>.<setcomp>c                 3  s   | ]}| v V  qd S rP   r(   r1   
subDocAxesr(   r)   	<genexpr>   r5   z#_extractSubSpace.<locals>.<genexpr>c                 3  s   | ]}| v V  qd S rP   r(   r1   r[   r(   r)   r]      r5   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fontr7   rQ   	layerNamer#   r&   muteKerningmuteInfomutedGlyphNamesc                   s    g | ]}t  |j tr|qS r(   )
isinstancer7   r   )r2   Z
axisSubsetrO   r(   r)   r4   :  s   )r7   r`   axisSubsetsrI   r!    )r`   ra   rb   r7   userLocationrQ   r#   r&   postScriptFontNamestyleMapFamilyNamestyleMapStyleNamelocalisedFamilyNamelocalisedStyleNamelocalisedStyleMapFamilyNamelocalisedStyleMapStyleNamerI   )Jr   r<   r7   rg   r   r=   r	   r
   ZaddAxisrV   rW   rX   maxr?   rA   minr@   rY   ZaxisMappingsallr^   keysr_   LOGGERerrorsetupdater>   r   r   _subsetRulesBasedOnConditionsrulesZrulesProcessingLastsourcesr   Zmap_backwardrQ   Z	addSourcer   r`   ra   rb   _filterLocationrc   r#   r&   rd   re   rf   ZfindDefaultro   rH   r   r   ZaddVariableFontr   ri   rI   Z	instancesZgetFullUserLocationr   r$   r%   r'   ZaddInstancer   rk   rl   rm   ZstyleMapFamilyNamesrn   rp   rq   rr   )r   rO   r;   r-   r.   r/   rF   rS   r3   ZmappingsmappingZmappingAxesdesignRegionsourceZ	vfDefaultZ
oldDefaultrJ   rK   r   r   r#   r&   r(   )r   r.   rU   r\   rO   r)   rE      sD   	

















rE   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@   r7   )r%   r   mathinf)r   c	conditionr?   r@   r(   r(   r)   _conditionSetFrom  s    r   zList[RuleDescriptor])r|   r   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)r7   conditionSetssubsFT)r7   r?   r@   )r   r7   r   r   r   itemsrg   floatintintersectionr>   r?   r@   )r|   r   ZnewRulesZruleZnewRuleZconditionsetcsZnewConditionsetZdiscardConditionsetZselectionNameZselectionValuer   r(   r(   r)   r{     s@    

	r{   zDict[str, float])rO   locationr    c                   s    fdd|  D S )Nc                   s,   i | ]$\}}| v rt  | tr||qS r(   )rg   r   )r2   r7   r8   rh   r(   r)   r9     s   z#_filterLocation.<locals>.<dictcomp>)r   )rO   r   r(   rh   r)   r~     s    
r~   )0__doc__
__future__r   rB   loggingr   typingr   r   r   r   r   r   r	   ZfontTools.designspaceLibr
   r   r   r   r   r   r   r   r   Z"fontTools.designspaceLib.statNamesr   r   ZfontTools.designspaceLib.typesr   r   r   r   r   r   r   	getLogger__name__rw   r   r,   r*   rG   rM   rN   rE   r   r{   r~   r(   r(   r(   r)   <module>   s6   $,$

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