o
    i'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(   m/var/www/html/eduruby.in/lip-sync/lip-sync-env/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   Z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.   ZdiscreteAxesZinterpolableUserRegionr4   ZvalueCombinationsr1   ZdiscreteUserLocationsubDocr(   r(   r)   splitInterpolable6   s8   "




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
    Fr;   N)getVariableFontsr   rF   libr8   )r   r+   r-   r.   vfvfUserRegionvfDocr(   r(   r)   splitVariableFontsy   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   ZformatVersion)r   ZvfsZ	_locationrG   ZvfNamerN   r(   r(   r)   convert5to4   s   	
rQ   
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)ZgetFullDesignLocationdesignLocation)object)r   r-   r(   r)   maybeExpandDesignLocation   s   
z3_extractSubSpace.<locals>.maybeExpandDesignLocationr@   c                   s4   g | ]\}} j |  kr jkrn n||fqS r(   )r@   rA   )r3   userZdesign)ranger(   r)   r5      s
    z$_extractSubSpace.<locals>.<listcomp>)
tagr8   
labelNameshiddenr@   rB   rA   mapZaxisOrderingZ
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 rS   r(   r2   
subDocAxesr(   r)   	<genexpr>       z#_extractSubSpace.<locals>.<genexpr>c                 3  r^   rS   r(   r2   r_   r(   r)   ra      rb   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   rT   	layerNamer#   r&   muteKerningmuteInfomutedGlyphNamesc                   s    g | ]}t  |j tr|qS r(   )
isinstancer8   r   )r3   Z
axisSubsetrR   r(   r)   r5   :  s    )r8   re   axisSubsetsrK   r!   re   rf   rg   r8    userLocationrT   r#   r&   postScriptFontNamestyleMapFamilyNamestyleMapStyleNamelocalisedFamilyNamelocalisedStyleNamelocalisedStyleMapFamilyNamelocalisedStyleMapStyleNamerK   r(   )Jr   r=   r8   rl   r   r>   r	   r
   ZaddAxisrY   rZ   r[   maxr@   rB   minrA   r\   ZaxisMappingsallrc   keysrd   LOGGERerrorsetupdater?   r   r   _subsetRulesBasedOnConditionsrulesZrulesProcessingLastsourcesr   Zmap_backwardrT   Z	addSourcer   re   rf   rg   _filterLocationrh   r#   r&   ri   rj   rk   ZfindDefaultrt   rJ   r   r   ZaddVariableFontr   rn   rK   Z	instancesZgetFullUserLocationr   r$   r%   r'   ZaddInstancer   rp   rq   rr   ZstyleMapFamilyNamesrs   ru   rv   rw   )r   rR   r<   r+   r-   r.   rG   rV   r4   ZmappingsmappingZmappingAxesdesignRegionsourceZ	vfDefaultZ
oldDefaultrL   rM   r   r   r#   r&   r(   )r   r-   rX   r`   rR   r)   rF      s  	


















	
rF   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 )Nr@   rA   r8   )r%   r   mathinf)r   c	conditionr@   rA   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   r@   rA   )r   r8   r   r   r   itemsrl   floatintintersectionr?   r@   rA   )r   r   ZnewRulesruleZnewRuleZconditionsetcsZnewConditionsetZdiscardConditionsetZselectionNameZ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(   )rl   r   )r3   r8   r9   rm   r(   r)   r:     s
    z#_filterLocation.<locals>.<dictcomp>)r   )rR   r   r(   rm   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   rI   )r   r   r   rP   )r   r   rR   r   r<   r,   r+   r,   r-   r,   r.   r/   r   r   )r   r   r   r   )r   r   r   r   r   r   )rR   r   r   r   r   r   )0__doc__
__future__r   rC   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__r|   r    r/   r*   rH   rO   rQ   rF   r   r   r   r(   r(   r(   r)   <module>   s8    $,$

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