
    Li%                        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y)    )annotations)Mapping)	dataclass)DesignSpaceDocument)TTFont)VariationModelnoRoundnormalizeValuepiecewiseLinearMapN)Self.c                F    t        t        | j                                     S )z;Create a hashable location from a dictionary-like location.)tuplesorteditems)locations    e/home/ubuntu/crypto_trading_bot/.venv/lib/python3.12/site-packages/fontTools/feaLib/variableScalar.pyLocationr      s    ()**    c                  N    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
y)VariableScalarzFA scalar with different values at different points in the designspace.zdict[LocationTuple, int]valuesNc                    |xs i j                         D ci c]  \  }}t        |      | c}}| _        g | _        y c c}}w N)r   r   r   axes)selflocation_valuer   values       r   __init__zVariableScalar.__init__%   sH     %3$8b#?#?#A
% X%
 	
s   ?c                J   g }| j                   j                         D ]h  \  }}dj                  |D cg c]0  \  }}| dt        |      j	                         rt        |      n| 2 c}}      }|j                  d||fz         j ddj                  |      z   dz   S c c}}w )N,=z%s:%i( ))r   r   joinfloat
is_integerintappend)r   r   r   r   axcoordlocs          r   __repr__zVariableScalar.__repr__.   s    #{{002 	1OHe(( &.!E d!%,*A*A*CCJOPC LLC</0	1 chhuo&,,s   5Bc                x    t        | j                  j                               t        fddd  D              S )Nc              3  .   K   | ]  }|d    k7    yw)r   N ).0vr   s     r   	<genexpr>z+VariableScalar.does_vary.<locals>.<genexpr>=   s     6a1q	>6s      )listr   any)r   r   s    @r   	does_varyzVariableScalar.does_vary:   s1    dkk((*+66!":666r   c                4    || j                   t        |      <   y r   )r   r   )r   r   r   s      r   	add_valuezVariableScalar.add_value?   s    */HX&'r   c           	     p   t        j                  dt        d       | j                  st	        d      t        | j                  D ci c]0  }|j                  |j                  |j                  |j                  f2 c}|i nt        |j                        ||ni       }|j                  | |      S c c}w )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()axis_triplesaxis_mappingsmodel_cache)warningswarnDeprecationWarningr   
ValueErrorVariableScalarBuilderaxisTagminValuedefaultValuemaxValuedictsegmentsadd_to_variation_store)r   store_builderr@   avarr*   builders         r   rL   z%VariableScalar.add_to_variation_storeB   s    J		
 yy+  ( )) 

R[["//2;;GG "&243F'2'>B
 --dMBBs   5B3r   )returnbool)r   Mapping[str, float]r   r(   )NN)__name__
__module____qualname____doc____annotations__r   r-   propertyr7   r9   rL   r0   r   r   r   r      s9    P$$%
- 7 70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y)rE   zA helper class for building variable scalars, or otherwise interrogating
    their variation model for interpolation or similar.z%dict[str, tuple[float, float, float]]r>   z dict[str, Mapping[float, float]]r?   z/dict[tuple[LocationTuple, ...], VariationModel]r@   c           	     J    | |d   j                   D ci c]0  }|j                  |j                  |j                  |j                  f2 c}|j                  d      x}i i       S |j                  j                         D ci c]  \  }}||
 c}}i       S c c}w c c}}w )NfvarrN   r=   )r   rF   rG   rH   rI   getrK   r   )clsttfaxisrN   rK   s        r   from_ttfzVariableScalarBuilder.from_ttfj   s      K,, t}}d.?.?OO  GGFO+D4  
 	
 <@==;N;N;PQxdHnQ
 	
 Rs   5BBc                l    | |j                   D ci c]0  }|j                  |j                  |j                  |j                  f2 c}|j                   D ci c]  }|j
                  r|j                  |j
                  D ci c]  \  }}t        ||j                  |j                  |j                  f      t        ||j                  |j                        |j                  |j                        |j                  |j                        f       c}} c}}}i       S c c}w c c}}w c c}}}w )Nr=   )r   tagminimumdefaultmaximummapr
   map_forward)r]   docr_   userdesigns        r   from_designspacez&VariableScalarBuilder.from_designspacey   s     HH 4<<t||DD$  HH  88  )- %f #t||T\\4<<H% ,,T\\: ,,T\\: ,,T\\:	 " -
 	

s   5D$+D/BD)D/)D/c                    i }|D ])  \  }}|| j                   vrt        d|d|      |||<   + | j                   j                         D ]  \  }\  }}}||vs|||<    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 )r>   rD   r   r   )r   r   fullaxtagr   _axis_defaults          r   _fully_specify_locationz-VariableScalarBuilder._fully_specify_location   s     $ 	 LE5D--- E8!LMMDK	 
 ,0+<+<+B+B+D 	+'E'A|QD *U	+ ~r   c                    i }|D ]U  \  }}| j                   |   \  }}}t        ||||f      }| j                  j                  |      }	|	t	        ||	      }|||<   W |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).
        )r>   r
   r?   r\   r   )
r   r   resultrn   r   axis_minrp   axis_max
normalizedmappings
             r   _normalize_locationz)VariableScalarBuilder._normalize_location   s~     $ 	'LE5/3/@/@/G,HlH',/QRJ((,,U3G"/
GD
&F5M	' r   c                    |j                   j                         D cg c]  \  }}| j                  |      |f c}}S c c}}w )zzReturn a list of (fully-specified user-space location, value) pairs,
        preserving order and length of scalar.values.)r   r   rq   )r   scalarr,   vals       r   _full_locations_and_valuesz0VariableScalarBuilder._full_locations_and_values   sE     #MM//1
S ))#.4
 	
 
s   ?c           
         t        | j                  j                         D ci c]  \  }\  }}}|| c}}}      }| j                  |      D ]  \  }}||k(  s|c S  t	        d      c c}}}w )z+Get the default value of a variable scalar.z Default value could not be found)r   r>   r   r|   rD   )r   rz   rb   ro   rd   default_locr   r   s           r   default_valuez#VariableScalarBuilder.default_value   s~     6:6G6G6M6M6OPP2c?AwS'\P
  $>>vF 	OHe;&	 ;<< Qs   A+c                "   | j                  |      }| j                  |      }|D ]  \  }}||k(  s|c S  |D cg c]  \  }}|	 }}}| j                  |      }| j                  |      j	                  ||      }	|	t        d      |	S c c}}w )z7Interpolate the value of a scalar from a user-location.z,Insufficient number of values to interpolate)rq   r|   rx   modelinterpolateFromMastersrD   )
r   rz   r   pairsr,   r{   ro   r   normalized_locationr   s
             r   value_at_locationz'VariableScalarBuilder.value_at_location   s    
 //9//7  	HCh
	 %**&!S#**"66x@

6"99:MvV=KLL +s   Bc                Z   | j                  |      }t        d |D              }| j                  j                  |      }||S |D cg c]  \  }}| j	                  |       }}}t        | j                  j                               }t        ||      x}	| j                  |<   |	S c c}}w )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   | ]	  \  }}|  y wr   r0   )r1   r,   ro   s      r   r3   z.VariableScalarBuilder.model.<locals>.<genexpr>   s     2&#q#2s   )	axisOrder)	r|   r   r@   r\   rx   r5   r>   keysr   )
r   rz   r   	cache_keycached_modelr,   ro   normalized_locationsr   r   s
             r   r   zVariableScalarBuilder.model   s     //72E22	''++I6#LQR&#q 8 8 =RR**//12	.< I/
 	
  +   Ss   B'c                    t        |j                  j                               }| j                  |      j                  |t              S )zACalculate deltas and supports from this scalar's variation model.round)r5   r   r   getDeltasAndSupportsr   )r   rz   r   s      r   get_deltas_and_supportsz-VariableScalarBuilder.get_deltas_and_supports   s8    fmm**,-zz&!66vU6KKr   c                    | j                  |      \  }}|j                  |       |j                  |t              }t	        | j                  |            |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   rz   rM   deltassupportsindexs         r   rL   z,VariableScalarBuilder.add_to_variation_store   sY      77?!!(+))&)@ 4%%f-.55r   N)r^   r   rP   r   )rh   r   rP   r   )r   LocationTuplerP   r   )r   r   rP   zdict[str, float])rz   r   rP   zlist[tuple[LocationTuple, int]])rz   r   rP   r(   )rz   r   r   r   rP   r&   )rz   r   rP   r   )rz   r   )rz   r   rP   ztuple[int, int])rS   rT   rU   rV   rW   classmethodr`   rk   rq   rx   r|   r   r   r   r   rL   r0   r   r   rE   rE   Z   s    ; 87J33 A@L 
 
 
 
4 $	
$	
	(	

=$0=	,*L
6$6	6r   rE   )r   rR   rP   r   )
__future__r   collections.abcr   dataclassesr   fontTools.designspaceLibr   fontTools.ttLib.ttFontr   fontTools.varLib.modelsr   r	   r
   r   typingrA   TYPE_CHECKINGr   r   strr&   r   r   r   rE   r0   r   r   <module>r      s{    " # ! 8 )   	eCJ',- +
9C 9Cx n6 n6 n6r   