Ë
    ÚÍ:jÇ%  ã                  óà   — 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    út/home/mcse/projects/srt_converter/srt-converter-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Ò$8°b×#?Ñ#?Ó#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ò 	1‰OˆH�eØ—(‘(ð &.÷á!˜˜Eð �d˜!¬%°«,×*AÑ*AÔ*CœC œJÈÐOÒPóóˆCð �L‰L˜ C¨ <Ñ/Õ0ð	1ð �c—h‘h˜u“oÑ&¨Ñ,Ð,ùó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   øè ø€ Ò6 a�1˜˜q™	•>Ñ6ùs   ƒé   )Úlistr   Úany)r   r   s    @r   Ú	does_varyzVariableScalar.does_vary:   s1   ø€ ä�d—k‘k×(Ñ(Ó*Ó+ˆÜÓ6¨6°!°"¨:Ô6Ó6Ð6r   c                ó4   — || j                   t        |«      <   y r   )r   r   )r   r   r   s      r   Ú	add_valuezVariableScalar.add_value?   s   € Ø*/ˆ�‰”H˜XÓ&Ò'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äØõ		
ð �yŠyÜð+óð ô (ð Ÿ)™)öàð —
‘
˜RŸ[™[¨"¯/©/¸2¿;¹;ÐGÑGòð "& ™2´4¸¿¹Ó3FØ'2Ð'>™ÀBô
ˆð ×-Ñ-¨d°MÓ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   z€A 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òð  ŸG™G F›OÐ+�DÐ4ð ð ô
ð 	
ð <@¿=¹=×;NÑ;NÓ;P×Q©¨¨x�d˜H‘nÓ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  € áð  ŸH™Höàð —‘˜4Ÿ<™<¨¯©°t·|±|ÐDÑDòð$  ŸH™H÷ð ð Ø—8’8ð —‘ð )-¯©÷ñ %˜˜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Œ   € ð ˆØ$ò 	 ‰LˆE�5Ø˜D×-Ñ-Ñ-Ý ºEÁ8Ð!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 )zÉNormalize 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~   € ð ˆØ$ò 	'‰LˆE�5Ø/3×/@Ñ/@ÀÑ/GÑ,ˆH�l HÜ'¨°¸,ÈÐ/QÓRˆJØ×(Ñ(×,Ñ,¨UÓ3ˆGØÐ"Ü/°
¸GÓD�
Ø&ˆF�5ŠMð	'ð ˆ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   € ð #ŸM™M×/Ñ/Ó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:×6GÑ6G×6MÑ6MÓ6O×PÐPÑ2˜c¡? A w°ˆS�'‰\ÔPó
ˆð  $×>Ñ>¸vÓFò 	‰OˆH�eØ˜;Ó&Ø’ð	ô Ð;Ó<Ð<ùô 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ˆð ò 	‰HˆC�Ø�h‹Ø’
ð	ð %*×*™&˜!˜S’#Ð*ˆÑ*Ø"×6Ñ6°xÓ@Ðà—
‘
˜6Ó"×9Ñ9Ð:MÈvÓ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 )z­Return 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œ#Ñ2ùs   ‚)Ú	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ˆÜÑ2¨EÔ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   € ä�f—m‘m×*Ñ*Ó,Ó-ˆØ�z‰z˜&Ó!×6Ñ6°vÄUÐ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Ý )÷ó ó Û à	×ÒÝà�e˜C ˜JÑ'¨Ð,Ñ-€Ø ó+÷
9Cñ 9Cðx ÷n6ð n6ó ñn6r   