
     i%                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZmZmZ d dlZd dlZej        rd dlmZ eeeef         d	f         Z	 ddZ G d d          Ze G d d                      ZdS )    )annotations)Mapping)	dataclass)DesignSpaceDocument)TTFont)VariationModelnoRoundnormalizeValuepiecewiseLinearMapN)Self.locationMapping[str, float]returnLocationTuplec                ^    t          t          |                                                     S )z;Create a hashable location from a dictionary-like location.)tuplesorteditems)r   s    i/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/fontTools/feaLib/variableScalar.pyLocationr      s"    (())***    c                  V    e Zd ZU dZded<   	 ddZd Zedd	            ZddZ	ddZ
dS )VariableScalarzFA scalar with different values at different points in the designspace.zdict[LocationTuple, int]valuesNc                ^    d |pi                                  D             | _        g | _        d S )Nc                4    i | ]\  }}t          |          |S  )r   ).0r   values      r   
<dictcomp>z+VariableScalar.__init__.<locals>.<dictcomp>&   s6     
 
 
% X
 
 
r   )r   r   axes)selflocation_values     r   __init__zVariableScalar.__init__%   s@    
 
$2$8b#?#?#A#A
 
 
 			r   c                    g }| j                                         D ]>\  }}d                    d |D                       }|                    d||fz             ?dd                    |          z   dz   S )N,c                    g | ]<\  }}| d t          |                                          rt          |          n| =S )=)float
is_integerint)r   axcoords      r   
<listcomp>z+VariableScalar.__repr__.<locals>.<listcomp>2   s[       !E PP%,,*A*A*C*CNCJJJPP  r   z%s:%i( ))r   r   joinappend)r"   r   r   r   locs        r   __repr__zVariableScalar.__repr__.   s    #{0022 	1 	1OHe(( %-   C LLC</0000chhuoo&,,r   r   boolc                    t          | j                                                  t          fddd          D                       S )Nc              3  0   K   | ]}|d          k    V  dS )r   Nr   )r   vr   s     r   	<genexpr>z+VariableScalar.does_vary.<locals>.<genexpr>=   s+      66a1q	>666666r      )listr   any)r"   r   s    @r   	does_varyzVariableScalar.does_vary:   sI    dk((**++66666!"":666666r   r   r   r   r+   c                4    || j         t          |          <   d S N)r   r   )r"   r   r   s      r   	add_valuezVariableScalar.add_value?   s    */HX&&'''r   c                   t          j        dt          d           | j        st	          d          t          d | j        D             |i nt          |j                  ||ni           }|                    | |          S )zGDeprecated: use VariableScalarBuilder.add_to_variation_store() instead.zrVariableScalar.add_to_variation_store() is deprecated. Use VariableScalarBuilder.add_to_variation_store() instead.   )
stacklevelzP.axes must be defined on variable scalar before calling add_to_variation_store()c                B    i | ]}|j         |j        |j        |j        fS r   axisTagminValuedefaultValuemaxValue)r   r,   s     r   r    z9VariableScalar.add_to_variation_store.<locals>.<dictcomp>P   s9        
R["/2;G  r   Naxis_triplesaxis_mappingsmodel_cache)	warningswarnDeprecationWarningr!   
ValueErrorVariableScalarBuilderdictsegmentsadd_to_variation_store)r"   store_builderrN   avarbuilders        r   rV   z%VariableScalar.add_to_variation_storeB   s    J		
 	
 	
 	
 y 	+   ( )   "&2243F3F'2'>B
 
 
 --dMBBBr   r@   )r   r6   )r   r   r   r+   )NN)__name__
__module____qualname____doc____annotations__r$   r5   propertyr>   rA   rV   r   r   r   r   r      s         PP$$$$%   
- 
- 
- 7 7 7 X70 0 0 0C C C C C Cr   r   c                      e Zd ZU dZded<   	 ded<   	 ded<   	 ed#d            Zed$d            Zd%dZd&dZ	d'dZ
d(dZd)dZd*dZd+dZd,d!Zd"S )-rS   zA helper class for building variable scalars, or otherwise interrogating
    their variation model for interpolation or similar.z%dict[str, tuple[float, float, float]]rL   z dict[str, Mapping[float, float]]rM   z/dict[tuple[LocationTuple, ...], VariationModel]rN   ttfr   r   r   c                     | d |d         j         D             |                    d          x}i n"d |j                                        D             i           S )Nc                B    i | ]}|j         |j        |j        |j        fS r   rF   r   axiss     r   r    z2VariableScalarBuilder.from_ttf.<locals>.<dictcomp>m   s:        t}d.?O  r   fvarrX   c                    i | ]\  }}||	S r   r   )r   re   rU   s      r   r    z2VariableScalarBuilder.from_ttf.<locals>.<dictcomp>t   s    QQQxdHQQQr   rK   )r!   getrU   r   )clsra   rX   s      r   from_ttfzVariableScalarBuilder.from_ttfj   s~    s K,    GGFOO+D4 QQ4=;N;N;P;PQQQ
 
 
 	
r   docr   c                Z     | d |j         D             d |j         D             i           S )Nc                B    i | ]}|j         |j        |j        |j        fS r   )tagminimumdefaultmaximumrd   s     r   r    z:VariableScalarBuilder.from_designspace.<locals>.<dictcomp>|   s9        4<t|D  r   c                P    i | ]"j         	j        fd j         D             #S )c                   i | ]\  }}t          |j        j        j        f          t          |                    j                                      j                                      j                  f          S r   )r
   ro   rp   rq   map_forward)r   userdesignre   s      r   r    zEVariableScalarBuilder.from_designspace.<locals>.<dictcomp>.<dictcomp>   s        %f #t|T\4<H % ,,T\:: ,,T\:: ,,T\::   r   )maprn   rd   s    @r   r    z:VariableScalarBuilder.from_designspace.<locals>.<dictcomp>   s_        8     )-    r   rK   )r!   )ri   rk   s     r   from_designspacez&VariableScalarBuilder.from_designspacey   s^    s H     H  " -
 
 
 	
r   r   r   c                    i }|D ](\  }}|| j         vrt          d|d|          |||<   )| j                                         D ]\  }\  }}}||vr|||<   t          |          S )zsValidate and fully-specify a user-space location by filling in
        missing axes with their user-space defaults.zUnknown axis z in )rL   rR   r   r   )r"   r   fullaxtagr   _axis_defaults          r   _fully_specify_locationz-VariableScalarBuilder._fully_specify_location   s     $ 	  	 LE5D--- jEEE88!LMMMDKK+/+<+B+B+D+D 	+ 	+'E'A|QD  *U~~r   dict[str, float]c                    i }|D ]Z\  }}| j         |         \  }}}t          ||||f          }| j                            |          }	|	t	          ||	          }|||<   [|S )zNormalize a user-space location, applying avar mappings if present.

        TODO: This only handles avar1 (per-axis piecewise linear mappings),
        not avar2 (multi-dimensional mappings).
        )rL   r
   rM   rh   r   )
r"   r   resultr{   r   axis_minr}   axis_max
normalizedmappings
             r   _normalize_locationz)VariableScalarBuilder._normalize_location   s     $ 	' 	'LE5/3/@/G,HlH',/QRRJ(,,U33G"/
GDD
&F5MMr   scalarr   list[tuple[LocationTuple, int]]c                N      fd|j                                         D             S )zzReturn a list of (fully-specified user-space location, value) pairs,
        preserving order and length of scalar.values.c                D    g | ]\  }}                     |          |fS r   )r~   )r   r4   valr"   s      r   r.   zDVariableScalarBuilder._full_locations_and_values.<locals>.<listcomp>   s@     
 
 
S ))#..4
 
 
r   )r   r   )r"   r   s   ` r   _full_locations_and_valuesz0VariableScalarBuilder._full_locations_and_values   s<    
 
 
 
"M//11
 
 
 	
r   r+   c                    t          d | j                                        D                       }|                     |          D ]\  }}||k    r|c S t	          d          )z+Get the default value of a variable scalar.c                "    i | ]\  }\  }}}||S r   r   )r   rn   r|   rp   s       r   r    z7VariableScalarBuilder.default_value.<locals>.<dictcomp>   s%    PPP2c?AwS'PPPr   z Default value could not be found)r   rL   r   r   rR   )r"   r   default_locr   r   s        r   default_valuez#VariableScalarBuilder.default_value   s     PPd6G6M6M6O6OPPP
 
  $>>vFF 	 	OHe;&& ' ;<<<r   r)   c                4   |                      |          }|                     |          }|D ]\  }}||k    r|c S d |D             }|                     |          }|                     |                              ||          }|t          d          |S )z7Interpolate the value of a scalar from a user-location.c                    g | ]\  }}|S r   r   )r   r|   r   s      r   r.   z;VariableScalarBuilder.value_at_location.<locals>.<listcomp>   s    ***&!S#***r   Nz,Insufficient number of values to interpolate)r~   r   r   modelinterpolateFromMastersrR   )	r"   r   r   pairsr4   r   r   normalized_locationr   s	            r   value_at_locationz'VariableScalarBuilder.value_at_location   s    
 //99//77  	 	HCh


  +*E***"66x@@

6""99:MvVV=KLLLr   r   c                >                          |          }t          d |D                       } j                            |          }||S  fd|D             }t	           j                                                  }t          ||          x} j        |<   |S )zReturn a variation model based on a scalar's values.

        Variable scalars with the same fully-specified user-locations will use
        the same cached variation model.c              3      K   | ]	\  }}|V  
d S r@   r   )r   r4   r|   s      r   r:   z.VariableScalarBuilder.model.<locals>.<genexpr>   s&      22&#q#222222r   Nc                @    g | ]\  }}                     |          S r   )r   )r   r4   r|   r"   s      r   r.   z/VariableScalarBuilder.model.<locals>.<listcomp>   s+    RRR&#q 8 8 = =RRRr   )	axisOrder)r   r   rN   rh   r<   rL   keysr   )r"   r   r   	cache_keycached_modelnormalized_locationsr   r   s   `       r   r   zVariableScalarBuilder.model   s     //7722E22222	'++I66#RRRRERRR*//1122	.< I/
 /
 /
 	
 + r   c                    t          |j                                                  }|                     |                              |t                    S )zACalculate deltas and supports from this scalar's variation model.round)r<   r   r   getDeltasAndSupportsr   )r"   r   r   s      r   get_deltas_and_supportsz-VariableScalarBuilder.get_deltas_and_supports   sB    fm**,,--zz&!!66vU6KKKr   tuple[int, int]c                    |                      |          \  }}|                    |           |                    |t                    }t	          |                     |                    |fS )zlSerialize this scalar's variation model to a store, returning the
        default value and variation index.r   )r   setSupportsstoreDeltasr	   r+   r   )r"   r   rW   deltassupportsindexs         r   rV   z,VariableScalarBuilder.add_to_variation_store   sk      77??!!(+++))&)@@ 4%%f--..55r   N)ra   r   r   r   )rk   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r+   )r   r   r   r   r   r)   )r   r   r   r   )r   r   )r   r   r   r   )rZ   r[   r\   r]   r^   classmethodrj   rx   r~   r   r   r   r   r   r   rV   r   r   r   rS   rS   Z   s;        ; ; 8777J3333 A@@@L 
 
 
 [
 
 
 
 [
4       $	
 	
 	
 	

= 
= 
= 
=   ,   *L L L L
6 6 6 6 6 6r   rS   )r   r   r   r   )
__future__r   collections.abcr   dataclassesr   fontTools.designspaceLibr   fontTools.ttLib.ttFontr   fontTools.varLib.modelsr   r	   r
   r   typingrO   TYPE_CHECKINGr   r   strr)   r   r   r   rS   r   r   r   <module>r      st   " " " " " " # # # # # # ! ! ! ! ! ! 8 8 8 8 8 8 ) ) ) ) ) )             	 eCJ',- + + + +
9C 9C 9C 9C 9C 9C 9C 9Cx n6 n6 n6 n6 n6 n6 n6 n6 n6 n6r   