
    hj                        S SK Jr  S SKJr  S SKJr  S SKJr  S SK	J
r
  S SKJrJr  S SKJr  S SKrS SKrS S	KJr  / S
Qr\R*                  " S5      r/ SQr/ SQr\" S \" SS5       5       5      r/ SQrSrS rS rS r S r!S r"S(S jr#S(S jr$S(S jr%S r&S r'S r(     S)S jr)      S*S jr*      S*S  jr+      S*S! jr,      S*S" jr-S# r.S$ r/      S+S% jr0S(S& jr1\2S':X  a  S SK3r3\3Rh                  " \1" 5       5        gg),    )newTable)Axis)AreaPen)NullPen)StatisticsPen)piecewiseLinearMapnormalizeValue)makeOutputFileNameN)pformat)planWeightAxisplanWidthAxisplanSlantAxisplanOpticalSizeAxisplanAxissanitizeWeightsanitizeWidthsanitizeSlantmeasureWeightmeasureWidthmeasureSlantnormalizeLinearnormalizeLognormalizeDegreesinterpolateLinearinterpolateLogprocessAxismakeDesignspaceSnippetaddEmptyAvarmainzfontTools.varLib.avarPlanner)2   d            i,  i^  i  i  i  i&  iX  i  i  i  i   iR  i  i  )g      9@g     B@g      I@g     @O@g     R@g     U@g      Y@g      \@g     @_@g     0a@g     b@g     Pd@g     e@g     pg@g      i@c              #   |   #    U  H2  n[         R                  " [         R                  " US -  5      5      v   M4     g7f)g      4@N)mathdegreesatan).0ds     N/var/www/html/env/lib/python3.13/site-packages/fontTools/varLib/avarPlanner.py	<genexpr>r,   M   s)     HAdll499QX.//s   :<i   )            	   
                     $   0   <   H   `   x            i   r1   c                     X-
  X!-
  -  $ )zOLinearly normalize value in [rangeMin, rangeMax] to [0, 1], with extrapolation. )valuerangeMinrangeMaxs      r+   r   r   l   s    !455    c                     XX!-
  -  -   $ )zALinear interpolation between a and b, with t typically in [0, 1].rD   )tabs      r+   r   r   q   s    AE{?rH   c                     [         R                  " U5      n[         R                  " U5      n[         R                  " U 5      U-
  XC-
  -  $ )zVLogarithmically normalize value in [rangeMin, rangeMax] to [0, 1], with extrapolation.)r&   log)rE   rF   rG   logMinlogMaxs        r+   r   r   v   s8    XXhFXXhFHHUOf$99rH   c                     [         R                  " U5      n[         R                  " U5      n[         R                  " X0XC-
  -  -   5      $ )zFLogarithmic interpolation between a and b, with t typically in [0, 1].)r&   rN   exp)rJ   rK   rL   logAlogBs        r+   r   r   }   s5    88A;D88A;D88D,,--rH   c                    [         R                  " [         R                  " U5      5      n[         R                  " [         R                  " U5      5      n[         R                  " [         R                  " U 5      5      U-
  XC-
  -  $ )zPAngularly normalize value in [rangeMin, rangeMax] to [0, 1], with extrapolation.)r&   tanradians)rE   rF   rG   tanMintanMaxs        r+   r   r      sT    XXdll8,-FXXdll8,-FHHT\\%()F2vGGrH   c                 V   [        U[        5      (       a  UnOU Vs0 s H  o3S_M     nnS=pEU Hn  nUb  UR                  US5      nUS:X  a  M   OSnX   n[        U S9n	UR	                  U	5        UR
                  U-  n
XJ[        U	R                  5      -  -  nXZ-  nMp     XE-  $ s  snf )z:Measure the perceptual average weight of the given glyphs.   r   glyphset)
isinstancedictgetr   drawwidthabsrE   )r]   glyphsfrequenciesgwght_sumwdth_sum
glyph_name	frequencyglyphpenmults              r+   r   r      s    &$%+,V!tV,H
"#
A6IA~  I$x(

3{{Y&3syy>)) " ) -s   B&c                 *   [        U[        5      (       a  UnOU Vs0 s H  o3S_M     nnSnSnU HW  nUb  UR                  US5      nUS:X  a  M   OSnX   n[        5       n	UR	                  U	5        XHR
                  U-  -  nXW-  nMY     XE-  $ s  snf )z.Measure the average width of the given glyphs.r[   r   )r^   r_   r`   r   ra   rb   )
r]   rd   re   rf   rh   freq_sumri   rj   rk   rl   s
             r+   r   r      s    &$%+,V!tV,HH
"#
A6IA~  I$i

3KK)++   ) -s   Bc                    [        U[        5      (       a  UnOU Vs0 s H  o3S_M     nnSnSnU He  nUb  UR                  US5      nUS:X  a  M   OSnX   n[        U S9n	UR	                  U	5        UR
                  U-  n
XJU	R                  -  -  nXZ-  nMg     [        R                  " [        R                  " XE-  5      5      * $ s  snf )z?Measure the perceptual average slant angle of the given glyphs.r[   r   r\   )
r^   r_   r`   r   ra   rb   slantr&   r'   r(   )r]   rd   re   rf   slnt_sumro   ri   rj   rk   rl   rm   s              r+   r   r      s    &$%+,V!tV,HH
"#
A6IA~  I$X.

3{{Y&399$$ " LL8#67888+ -s   Cc                    X1S      X1S      X1S      penU S   XE-  -  nU S   Xe-  -  n[         R                  " S/U Q76   [         R                  SUU S   U5        [        XpS   -
  5      U S   -  S:  d  [        XS   -
  5      U S   -  S:  aH  [         R                  S5        [         R                  " S/U Q76   [         R                  S	UU S   U5        g
g)zSanitize the width axis limits.r   r[      z$Original width axis limits: %g:%g:%gz&Calculated width axis limits: %g:%g:%g皙?z6Calculated width axis min/max do not match user input.z%  Current width axis limits: %g:%g:%gz'  Suggested width axis limits: %g:%g:%gFTrN   inforc   warning)	
userTripledesignTriplepinsmeasurementsminVal
defaultValmaxValcalculatedMinValcalculatedMaxVals	            r+   r   r      s    	!_%!_%!_% F "!}(;<!!}(;<HH3AjAHH01	 	!},-
1=DQ-/0:a=@4GLM3	
	
 	5qM		
 rH   c                 p   [        [        U 5      5      S:  a  gX1S      X1S      X1S      pen[        R                  " U5      n[        R                  " U5      n[        R                  " U5      n	U S   U S   -
  U S   U S   -
  -  n
[        R                  " XzX-
  -  -   5      nX-
  Xd-
  -  n
U S   XS   U S   -
  -  -   n[        R
                  " S/U Q76   [        R                  SU S   UU S   5        [        XS   -
  5      U S   -  S:  Ga'  [        R                  S	5        [        R                  " S
/U Q76   [        R                  SU S   UU S   5        U S   U S   -
  U S   U S   -
  -  n
[        R                  " XzX-
  -  -   5      nX-
  XT-
  -  n
U S   XS   U S   -
  -  -   n[        R                  SU S   U S   U5        U S   U S   -
  U S   U S   -
  -  n
[        R                  " XX-
  -  -   5      nX-
  XV-
  -  n
U S   XS   U S   -
  -  -   n[        R                  SUU S   U S   5        gg)z Sanitize the weight axis limits.   Tr   r[   rt   z%Original weight axis limits: %g:%g:%gz'Calculated weight axis limits: %g:%g:%gru   z9Calculated weight axis default does not match user input.z&  Current weight axis limits: %g:%g:%gz:  Suggested weight axis limits, changing default: %g:%g:%gz:  Suggested weight axis limits, changing maximum: %g:%g:%gz:  Suggested weight axis limits, changing minimum: %g:%g:%gF)lensetr&   rN   rR   rw   rc   rx   )ry   rz   r{   r|   r}   r~   r   rO   
logDefaultrP   rJ   ycalculatedDefaultValr   r   s                  r+   r   r   	  s    3z?a 	!_%!_%!_% F XXfF*%JXXfF	AA	&:a=:a=+HIAv//0A	
(A%a=11
10M+NNHH4BzBHH111	 Q-/0:a=@4GOP4	
	

 	HqM qM		
 ]Z]*z!}z!}/LMHHV:#6778ZJ/0%a=11
10M+NNHqMqM		
 ]Z]*z!}z!}/LMHHV:#6778ZJ/0%a=11
10M+NNHqMqM		
 rH   c                    [         R                  " S/U Q76   [         R                  SX1S      X1S      X1S      5        [        X1S      U S   -
  5      S:  d4  [        X1S      U S   -
  5      S:  d  [        X1S      U S   -
  5      S:  aT  [         R                  S5        [         R                  " S/U Q76   [         R                  SX1S      X1S      X1S      5        g	g
)zSanitize the slant axis limits.z$Original slant axis limits: %g:%g:%gz&Calculated slant axis limits: %g:%g:%gr   r[   rt   z>Calculated slant axis min/default/max do not match user input.z%  Current slant axis limits: %g:%g:%gz'  Suggested slant axis limits: %g:%g:%gFTrv   )ry   rz   r{   r|   s       r+   r   r   P  s     HH3AjAHH0!_%!_%!_%	 	La)JqM9:Q>|O,z!}<=A|O,z!}<=ATU3	
	
 	5a)a)a)		
 rH   c           	         [        U[        5      (       a#  UR                  UR                  UR                  4nUu  pnUc  [
        nUc  U" 0 5      R                  5       nU
c  0 n
OU
R                  5       n
[        R                  SXU5        XU4nU	b  [        R                  " S/U	Q76   OUn	U
(       a-  [        R                  S[        U
R                  5       5      5        U
R                  XS   XS   XS   05        0 n0 n0 n[        XU1[        U
R                  5       5      -  5       H  nU" UU0S9nU
U   nU " UU5      UU'   M     Ub   [        R                  S	U5        U" XU
U5        [        R                  S
[        U5      5        [!        [#        [        U
R                  5       5      5      SS [#        [        U
R                  5       5      5      SS 5       GH  u  u  nnu  nnU Vs1 s H  nUUs=:  a  U:  d  M  O  M  UiM     nnU(       d  M;  [%        UU5      n[%        UU5      n[%        UU	5      n[%        UU	5      n[        R                  S[        U5      5        [        R                  SUUU5        UR                  5       n ['        SUS-   5       HJ  n!UUU-
  U!-  US-   -  -   n[        R                  SU5        U" UU0S9n[)        UU
5      nU " UU5      U U'   ML     [        R                  S[        U 5      5        0 n"[        U 5       H  nUU"U U   '   M     UUU'   UUU'   [        U5       Hs  nU" UUU5      n#U" U#U U   U U   5      n$[)        U$U"5      n%[        R                  SUU%4-  5        U%UU'   UUU-
  UU-
  -  UU-
  -  -   n&UU%U-
  UU-
  -  UU-
  -  -   UU&'   Mu     UUU'   UUU'   GM     [        R                  SU[        U5      5        [        R                  SU[        U5      5        [+        S UR                  5        5       5      (       a  [        R                  SU5        0 n0 nUU4$ s  snf )a  Plan an axis.

measureFunc: callable that takes a glyphset and an optional
list of glyphnames, and returns the glyphset-wide measurement
to be used for the axis.

normalizeFunc: callable that takes a measurement and a minimum
and maximum, and normalizes the measurement into the range 0..1,
possibly extrapolating too.

interpolateFunc: callable that takes a normalized t value, and a
minimum and maximum, and returns the interpolated value,
possibly extrapolating too.

glyphSetFunc: callable that takes a variations "location" dictionary,
and returns a glyphset.

axisTag: the axis tag string.

axisLimits: a triple of minimum, default, and maximum values for
the axis. Or an `fvar` Axis object.

values: a list of output values to map for this axis.

samples: the number of samples to use when sampling. Default 8.

glyphs: a list of glyph names to use when sampling. Defaults to None,
which will process all glyphs.

designLimits: an optional triple of minimum, default, and maximum values
represenging the "design" limits for the axis. If not provided, the
axisLimits will be used.

pins: an optional dictionary of before/after mapping entries to pin in
the output.

sanitizeFunc: an optional callable to call to sanitize the axis limits.
Nz(Axis limits min %g / default %g / max %gz/Axis design-limits min %g / default %g / max %gzPins %sr   r[   rt   )locationz/Sanitizing axis limit values for the `%s` axis.zCalculated average value:
%szPlanning target values %s.z"Sampling %u points in range %g,%g.zSampling value %g.zSampled average value:
%szPlanned mapping value %g to %g.z%Planned mapping for the `%s` axis:
%sz0Planned normalized mapping for the `%s` axis:
%sc              3   F   #    U  H  u  p[        X-
  5      S :  v   M     g7f)g{Gz?N)rc   )r)   kvs      r+   r,   planAxis.<locals>.<genexpr>  s     
?)>3qu:)>s   !z6Detected identity mapping for the `%s` axis. Dropping.)r^   fvarAxisminValuedefaultValuemaxValueSAMPLESkeyscopyrN   rw   sorteditemsupdater   debugr   ziplistr	   ranger   all)'measureFuncnormalizeFuncinterpolateFuncglyphSetFuncaxisTag
axisLimitsvaluessamplesrd   designLimitsr{   sanitizeFuncr   r   r   tripleoutoutNormalizedaxisMeasurementsrE   r]   designValuerF   	targetMinrG   	targetMaxwtargetValuesnormalizedMinnormalizedMaxnormalizedTargetMinnormalizedTargetMaxvalueMeasurementssamplemeasurementValuerJ   targetMeasurementtargetValuevalueNormalizeds'                                          r+   r   r   q  s   j *h'' )):+B+BJDWDWX
'1$HH~b!&&(|yy{HH2HH h/FBR\RF4::<01KK1oq/1o	
 CM:S=MMN'5)9:5k(3Hf(E% O
 BGLV41ABII-w7G/HI8;VDJJL!"3B'VDJJL!"12&9494) $*E6aX-DH-D-D6E&x8&x8,YE,YE-vl/CD5w(S,113Aw{+F8 3v=1MMEII*E2#gu-=>H,UD9K-86-Jk* , 			.8I0JK-.E9>.u56 / "H':m$L)EeXx8A /$Y/1B91M! -->@PQKII75+:NNO$CJ+ux/?8#/./0 0O .Ai'Y&D(+>AT+TDV .VM/* * "H':m$[9^ HH5wMHH; 
?)<)<)>
???I7So Fs   1QQ
Qc                 r    Uc  [         n[        [        [        [        U SUUUUUUU(       a  [
        S9$ SS9$ )zPlan a weight (`wght`) axis.

weights: A list of weight values to plan for. If None, the default
values are used.

This function simply calls planAxis with values=weights, and the appropriate
arguments. See documenation for planAxis for more information.
Nwghtr   r   rd   r   r{   r   )WEIGHTSr   r   r   r   r   )r   r   weightsr   rd   r   r{   sanitizes           r+   r   r     sP    & !'/^  6: rH   c                 r    Uc  [         n[        [        [        [        U SUUUUUUU(       a  [
        S9$ SS9$ )a	  Plan a width (`wdth`) axis.

widths: A list of width values (percentages) to plan for. If None, the default
values are used.

This function simply calls planAxis with values=widths, and the appropriate
arguments. See documenation for planAxis for more information.
Nwdthr   )WIDTHSr   r   r   r   r   )r   r   widthsr   rd   r   r{   r   s           r+   r   r   :  sP    & ~!&.]  59 rH   c                 r    Uc  [         n[        [        [        [        U SUUUUUUU(       a  [
        S9$ SS9$ )zPlan a slant (`slnt`) axis.

slants: A list slant angles to plan for. If None, the default
values are used.

This function simply calls planAxis with values=slants, and the appropriate
arguments. See documenation for planAxis for more information.
Nslntr   )SLANTSr   r   r   r   r   )r   r   slantsr   rd   r   r{   r   s           r+   r   r   `  sP    & ~!&.]  59 rH   c                 R    Uc  [         n[        [        [        [        U SUUUUUUS9$ )a  Plan a optical-size (`opsz`) axis.

sizes: A list of optical size values to plan for. If None, the default
values are used.

This function simply calls planAxis with values=sizes, and the appropriate
arguments. See documenation for planAxis for more information.
opsz)r   r   rd   r   r{   )SIZESr   r   r   r   )r   r   sizesr   rd   r   r{   r   s           r+   r   r     s<    & }! rH   c                     SX4U-   -  nU(       a  US-  nOUS-  nUR                  5        H  u  pVUSXV4-  -  nM     U(       a  US-  nU$ )z-Make a designspace snippet for a single axis.zC    <axis tag="%s" name="%s" minimum="%g" default="%g" maximum="%g"z>
z/>z$      <map input="%g" output="%g"/>
z    </axis>)r   )r   axisName	axisLimitmappingdesignspaceSnippetkeyrE   s          r+   r   r     ss     	N*	,  e#d"mmo
ETT & m+rH   c                     [        S5      =U S'   n[        R                   H  n0 UR                  UR                  '   M     g)z&Add an empty `avar` table to the font.avarN)r   fvaraxessegmentsr   )fontr   axiss      r+   r   r     s5    "6**DL4		&(dll# rH   c                 R   SnU S   R                    H  nUR                  U:X  d  M  Un  O   Uc  gUR                  UR                  UR                  4n[
        R                  SU5        SU ;   a%  U S   R                  U   n0 U S   R                  U'   OSnUb>  [        U[        5      (       a)  UR                  5        Vs/ s H  n[        U5      PM     nnUby  [        U[        5      (       ad  [        R                  R                  S5       Vs/ s H  n[        U5      PM     nn[        U5      S:X  a  US   US	   s=::  a  US
   ::  d    e   eOSnUb\  [        U[        5      (       aG  0 nUR                  5        H.  nUR                  S5      u  nn[        U5      U[        U5      '   M0     UnAU" U R                  UUUUUUU	S9u  nnU
(       aN  SSKJn  UR%                  ['        U5      ['        U5       Vs/ s H  nUU   PM
     sn5        UR)                  5         Ub   [
        R                  SU[+        U5      5        U(       a$  SU ;  a  [-        U 5        UU S   R                  U'   OSU ;   a  0 U S   R                  U'   [/        UUUU5      nU$ s  snf s  snf s  snf )zProcess a single axis.Nr    zPlanning %s axis.r   :r   r   r[   rt   )r   rd   r   r{   r   )pyplotzExisting %s mapping:
%s)r   r   r   r   r   rN   rw   r   r^   strsplitfloatoptionsr   r   getGlyphSet
matplotlibr   plotr   showr   r   r   )r   planFuncr   r   r   r   rd   r   r{   r   r   r   r   existingMappingr   r*   newPinspinbeforeafterr   mappingNormalizedr   r   r   s                            r+   r   r     s    JV!!<<7"J " %%z'>'>
@S@STJHH (+~v,//8)+Vg&j55$*LLN3Nq%(N3J|S$A$A*1*>*>*D*DS*IJ*IQa*IJ"Q<?El1oE	
FE	
FE JtS11::<CIIcNMFE%*5\GE&M"   !)!	"G %$%+12C+DE+Daq!+DE	
 	"+Xw7OP):Vg&T>-/DL!!'*/	 q 4 K@ Fs   JJ>J$
c                 	   U c  SSK nUR                  SS n SSKJn  SSKJn  SSKnUR                  SSS9nUR                  S	S
SS9  UR                  SS[        SS9  UR                  S[        SS9  UR                  S[        SS9  UR                  S[        SS9  UR                  S[        SS9  UR                  S[        SS9  UR                  SSSSS9  UR                  S S![        S"S9  UR                  S#[        S$S9  UR                  S%[        S&S9  UR                  S'[        S(S9  UR                  S)[        S*S9  UR                  S+[        S,S9  UR                  S-[        S.S9  UR                  S/[        S0S9  UR                  S1[        S2S9  UR                  S3S4SS5S9  UR                  S6S79nUR                  S8S9SS:S9  UR                  S;S<SS=S9  UR                  U 5      nU" UR                  (       a  S>OUR                  (       a  S?OS@SA9  U" UR                  5      nSBU;  a  [         R#                  SC5        gUR$                  bz  UR$                  R'                  5       n	SDUR$                  ;   aO  0 n	UR$                  R'                  5        H/  n
SDU
;   a"  U
R'                  SD5      u  p[)        U5      X'   M+  SEX'   M1     OSn	/ nUR+                  [-        U[.        SFSGUR0                  UR2                  U	UR4                  UR6                  UR8                  UR:                  SH95        UR+                  [-        U[<        SISJUR>                  UR2                  U	UR@                  URB                  UR8                  UR:                  SH95        UR+                  [-        U[D        SKSLURF                  UR2                  U	URH                  URJ                  UR8                  UR:                  SH95        UR+                  [-        U[L        SMSNURN                  UR2                  U	URP                  URR                  UR8                  UR:                  SH95        [         RU                  SO5        U H  nU(       d  M  [W        U5        M     URX                  c  [[        UR                  SPSQSR9nOURX                  nU(       a(  [         RU                  SSU5        UR]                  U5        gg)Tz3Plan the standard axis mappings for a variable fontNr   r[   )configLogger)TTFontzfonttools varLib.avarPlannerz#Plan `avar` table for variable font)descriptionr   zvarfont.ttfzVariable-font file.)metavarhelpz-oz--output-filezOutput font file name.)typer   z	--weightsz+Space-separate list of weights to generate.z--widthsz*Space-separate list of widths to generate.z--slantsz*Space-separate list of slants to generate.z--sizesz1Space-separate list of optical-sizes to generate.z	--sampleszNumber of samples.z-sz
--sanitize
store_truezSanitize axis limits)actionr   z-gz--glyphsz2Space-separate list of glyphs to use for sampling.z--weight-design-limitsz4min:default:max in design units for the `wght` axis.z--width-design-limitsz4min:default:max in design units for the `wdth` axis.z--slant-design-limitsz4min:default:max in design units for the `slnt` axis.z--optical-size-design-limitsz4min:default:max in design units for the `opsz` axis.z--weight-pinsz=Space-separate list of before:after pins for the `wght` axis.z--width-pinsz=Space-separate list of before:after pins for the `wdth` axis.z--slant-pinsz=Space-separate list of before:after pins for the `slnt` axis.z--optical-size-pinsz=Space-separate list of before:after pins for the `opsz` axis.z-pz--plotzPlot the resulting mapping.F)requiredz-vz	--verbosezRun more verbosely.z-qz--quietzTurn verbosity off.DEBUGWARNINGINFO)levelr   zNot a variable font.r   g      ?r   Weight)r   r   rd   r   r{   r   r   r   Widthr   Slantr   OpticalSizezDesignspace snippet:Tz.avar)	overWritesuffixz	Saving %s)/sysargv	fontToolsr   fontTools.ttLibr   argparseArgumentParseradd_argumentr   intadd_mutually_exclusive_group
parse_argsverbosequietr   rN   errorrd   r   r   appendr   r   r   r   weight_design_limitsweight_pinsr   r   r   r   width_design_limits
width_pinsr   r   slant_design_limits
slant_pinsr   r   optical_size_design_limitsoptical_size_pinsrw   printoutput_filer
   save)argsr  r   r   r  parserlogging_groupr   r   rd   rf   rk   rj   designspaceSnippetssnippetoutfiles                   r+   r   r   #  s<    |xx|&&$$&9 % F <QR
%	   #$Q   #O   #O   "U   #4HI
l<6L   A	    C  
 C  
 C  
 &C  
 L  
 L  
 L  
 L  
 h|2O   777GMk,5J   i3H   %G!//wGMMyv ',,DT>		()~~!%%''.. F^^))+!8'(wws|$E$))$4FM #FI , ??OO 55$$%%	
 >>OO 44##%%	
 >>OO 44##%%	
 ==OO ;;**%%	
  HH#$&7'N ' "$W\\T'R%%g&		' rH   __main__)N)NNNNN)NNNNNF)NNNNFF)5r  r   fontTools.ttLib.tables._f_v_a_rr   r   fontTools.pens.areaPenr   fontTools.pens.basePenr   fontTools.pens.statisticsPenr   fontTools.varLib.modelsr   r	   fontTools.misc.cliToolsr
   r&   loggingpprintr   __all__	getLoggerrN   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   __name__r  exitrD   rH   r+   <module>r/     sy   $ < * * 6 F 6   . 67,
$ 
HsBH	H	4 6

:.H889:&RDNR 	`L 	#R 	#R 	#R 	"J*) 		YxCL zHHTV rH   