U
    Dvf                     @   sV   d dl mZ d dlmZ d dlZedZdd Zdd Z	d	d
 Z
dd Zdd ZdS )    )otTables)deepcopyNzfontTools.varLib.instancerc                 C   sz   g }| j d k	r| j jng }|D ]*}|jdkr2 dS ||j|j|jf qt| jj	g| }||krhdS |
| dS d S )N   TF)ConditionSetConditionTableFormatappend	AxisIndexFilterRangeMinValueFilterRangeMaxValue	frozensetFeatureTableSubstitutionVersionadd)recseenZconditionSetZconditionSetsZcondZ	recordKey r   J/tmp/pip-unpacked-wheel-qlge9rch/fontTools/varLib/instancer/featureVars.py_featureVariationRecordIsUnique	   s    

r   c                    sF   | j }| j}||ks(| jks(| jk r,d S t fdd||fD S )Nc                 3   s   | ]} j |d dV  qdS )F)ZextrapolateN)ZrenormalizeValue).0v	axisLimitr   r   	<genexpr>.   s    z7_limitFeatureVariationConditionRange.<locals>.<genexpr>)r
   r   maximumminimumtuple)	conditionr   minValuemaxValuer   r   r   $_limitFeatureVariationConditionRange"   s    r    c                 C   s  d}d}g }ddl m} |ddd}	| jd krHt | _g | j_d| j_t| jjD ]\}
}|jdkr4|j}|| j	}|j
}|j}|||	}||j  kr|ksn d}|j|ks|j|k rd } qZ||krX|| |_t||}|r(|\}}||_
||_d}|dks|dkr2|| n
d } qZqTtd|
||j d}|| qT|d k	r|r|| j_|s~d | _d}nd}|o| }|||fS )NTFr   ) NormalizedAxisTripleAndDistancesr   zWCondition table {0} of FeatureVariationRecord {1} has unsupported format ({2}); ignored)ZfontTools.varLib.instancerr!   r   otr   ConditionCount	enumerater   r	   axisTagr
   r   getdefaultr   r   r    r   logwarningformat)recordZrecIdx
axisLimitsfvarAxesaxisIndexMapapplies
shouldKeepZnewConditionsr!   Zdefault_tripleir   ZaxisIdxr&   r   r   ZtripleZnewRanger   r   	universalr   r   r   "_instantiateFeatureVariationRecord3   sd    





  r4   c                    sh  t | fdd|D   fdd D }d}t  }g }d }t| jjD ]\}}	t|	||||\}
}}|rt|	|r||	 |
r|s|	jj	dkst
t|	j}t|j|	jjD ]4\}}t| jj|j j|_t|j| jj|j _qd}|rN qqN|r>|r>|s>t }t |_g |j_d|j_||_|| |rZ|| j_t|| j_n
| `d| _	d S )	Nc                    s   g | ]}|j  kr|j qS r   )r&   )r   Zaxis)
pinnedAxesr   r   
<listcomp>|   s     
 z1_instantiateFeatureVariations.<locals>.<listcomp>c                    s   i | ]}|  |qS r   )index)r   r&   )	axisOrderr   r   
<dictcomp>}   s      z1_instantiateFeatureVariations.<locals>.<dictcomp>Fi   Tr   )setZpinnedLocationr%   FeatureVariationsZFeatureVariationRecordr4   r   r   r   r   AssertionErrorr   zipZSubstitutionRecordZFeatureListZFeatureRecordZFeatureIndexZFeaturer#   r   r   r$   lenZFeatureVariationCount)tabler.   r-   r/   ZfeatureVariationAppliedZuniqueRecordsZ
newRecordsZdefaultsSubstsr2   r,   r0   r1   r3   r(   r   ZdefaultRecordr   )r8   r5   r   _instantiateFeatureVariationsz   sZ        




r@   c                 C   sZ   dD ]P}|| kst | | jdd s$qtd| t| | j| d j| | |   qd S )N)ZGPOSZGSUBr;   z+Instantiating FeatureVariations of %s tableZfvar)getattrr?   r)   infor@   ZaxesZprune_lookups)Zvarfontr-   ZtableTagr   r   r   instantiateFeatureVariations   s    
    rC   )ZfontTools.ttLib.tablesr   r#   copyr   logging	getLoggerr)   r   r    r4   r@   rC   r   r   r   r   <module>   s   
G9