U
    mdm                     @   sb   d dl mZ 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normalizeValue)deepcopyNzfontTools.varLib.instancerc                 C   sh   g }| j jD ]*}|jdkr  dS ||j|j|jf qt| jj	g| }||krVdS |
| dS d S )N   TF)ConditionSetConditionTableFormatappend	AxisIndexFilterRangeMinValueFilterRangeMaxValue	frozensetFeatureTableSubstitutionVersionadd)recseenZconditionSetZcondZ	recordKey r   _/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/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   | ]}t | V  qd S )Nr   ).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   sf  d}d}g }ddl m} |ddd}	t| jjD ]\}
}|jdkr|j}|| j}|j}|j	}|
||	}||j  kr|ksn d}|j|ks|j|k rd } q.||kr,|| |_t||}|r|\}}||_||_	d}|dks|dkr|| n
d } q.q0td|
||j d}|| q0|d k	rL|rL|| j_d}nd}|oZ| }|||fS )NTFr   )NormalizedAxisTripler   zWCondition table {0} of FeatureVariationRecord {1} has unsupported format ({2}); ignored)ZfontTools.varLib.instancerr#   	enumerater   r   r	   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   "_instantiateFeatureVariationRecord/   sX    



  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>r   s     
 z1_instantiateFeatureVariations.<locals>.<listcomp>c                    s   i | ]}|  |qS r   )index)r   r&   )	axisOrderr   r   
<dictcomp>s   s      z1_instantiateFeatureVariations.<locals>.<dictcomp>Fi   Tr   )setZpinnedLocationr%   FeatureVariationsZFeatureVariationRecordr4   r   r
   r   r   AssertionErrorr   zipZSubstitutionRecordZFeatureListZFeatureRecordZFeatureIndexZFeatureotr   r   ZConditionCountlenZFeatureVariationCount)tabler.   r-   r/   ZfeatureVariationAppliedZuniqueRecordsZ
newRecordsZdefaultsSubstsr2   r,   r0   r1   r3   r(   r   ZdefaultRecordr   )r8   r5   r   _instantiateFeatureVariationsp   sZ        




rA   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)   inforA   ZaxesZprune_lookups)Zvarfontr-   ZtableTagr   r   r   instantiateFeatureVariations   s    
    rD   )ZfontTools.ttLib.tablesr   r>   ZfontTools.varLib.modelsr   copyr   logging	getLoggerr)   r   r"   r4   rA   rD   r   r   r   r   <module>   s   
A9