a
    ¥Q•h'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 )/zŒAllows 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 )zÿDefault 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(   úW/var/www/sistema_ama/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/   ÚdiscreteAxesZinterpolableUserRegionr3   ÚvalueCombinationsr0   ZdiscreteUserLocationÚsubDocr(   r(   r)   ÚsplitInterpolable6   s4    "



ýþ
úrI   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    
úrO   zDict[str, DesignSpaceDocument])r   r    c                 C  s:   i }t | ƒD ](\}}t|ƒD ]\}}d|_|||< qq|S )züConvert 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)rI   rO   ÚformatVersion)r   ÚvfsÚ	_locationrH   ZvfNamerN   r(   r(   r)   Úconvert5to4ž   s    	rS   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 ƒƒsâq¾t‡fdd
„|
j ¡ D ƒƒ�st d|
j|
j¡ q¾tƒ }| |
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�¡ q¾tˆ ˆƒ}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Ô|�ræt<ˆ | ;ˆ ¡ƒ}|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�pØi |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)Ú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@   ÚmapÚaxisOrderingÚ
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 rU   r(   r1   ©Ú
subDocAxesr(   r)   Ú	<genexpr>è   r5   z#_extractSubSpace.<locals>.<genexpr>c                 3  s   | ]}|ˆ v V  qd S rU   r(   r1   rc   r(   r)   re   ê   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   rW   Ú	layerNamer#   r&   ÚmuteKerningÚmuteInfoÚmutedGlyphNamesc                   s    g | ]}t ˆ |j tƒr|‘qS r(   )Ú
isinstancer7   r   )r2   Ú
axisSubset©rT   r(   r)   r4   :  s   þ)r7   rh   ÚaxisSubsetsrK   r!   ú )rh   ri   rj   r7   ÚuserLocationrW   r#   r&   ÚpostScriptFontNameÚstyleMapFamilyNameÚstyleMapStyleNameÚlocalisedFamilyNameÚlocalisedStyleNameÚlocalisedStyleMapFamilyNameÚlocalisedStyleMapStyleNamerK   )Jr   r<   r7   ro   r   r=   r	   r
   ÚaddAxisr\   r]   r^   Úmaxr?   rA   Úminr@   r_   ÚaxisMappingsÚallrf   Úkeysrg   ÚLOGGERÚerrorÚsetÚupdater>   r   r   Ú_subsetRulesBasedOnConditionsÚrulesÚrulesProcessingLastÚsourcesr   Úmap_backwardrW   Ú	addSourcer   rh   ri   rj   Ú_filterLocationrk   r#   r&   rl   rm   rn   ÚfindDefaultrx   rJ   r   r   ÚaddVariableFontr   rr   rK   Ú	instancesÚgetFullUserLocationr   r$   r%   r'   ÚaddInstancer   rt   ru   rv   ZstyleMapFamilyNamesrw   ry   rz   r{   )r   rT   r;   r-   r.   r/   rH   rY   r3   ÚmappingsÚmappingZmappingAxesÚdesignRegionÚsourceZ	vfDefaultZ
oldDefaultrL   rM   r   r   r#   r&   r(   )r   r.   r[   rd   rT   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 rnq´d}q@|
||	 v r‚q@||	  	|
¡}|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›   Úitemsro   ÚfloatÚintÚintersectionr>   r?   r@   )r‡   r”   ZnewRulesÚruleZnewRuleÚconditionsetÚcsZnewConditionsetZdiscardConditionsetZselectionNameZselectionValuer¡   r(   r(   r)   r†   ’  s@    
ÿ
ýÿ	r†   zDict[str, float])rT   Úlocationr    c                   s   ‡ fdd„|  ¡ D ƒS )Nc                   s,   i | ]$\}}|ˆ v rt ˆ | tƒr||“qS r(   )ro   r   )r2   r7   r8   rq   r(   r)   r9   ×  s   þz#_filterLocation.<locals>.<dictcomp>)rž   )rT   r¥   r(   rq   r)   rŒ   Ó  s    
þrŒ   )0Ú__doc__Ú
__future__r   rB   Úloggingr—   Útypingr   r   r   r   r   r   r	   Ú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__r‚   r   r,   r*   rI   rO   rS   rE   r›   r†   rŒ   r(   r(   r(   r)   Ú<module>   s6   $,$

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