summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/fonts/source/public/cb/cbspline.mf
blob: 8bdeff88bfbc50bce012f43848fe8b5b2f79e9c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
% Copyright (C) 1997, 1999 Claudio Beccari
% The copyright holds only for the file that enucleates the spline macros,
% not for the macros themselves that are copyright of J"orge Knappen.
%
% This file includes the spline macros for computing font paramenters
% from a table. It includes all the macros written by J"orge Knappen for the
% ec fonts.  Thanks to J"orge for the good things these macros do, blame to me
% for their misuse.


vardef simple_gendef@#(text aa)(text t)=
 string s[];
 s1:="";
 s2:=str @#;
 index:=1;
 forsuffixes $=t: ydata[index]:=$ if s1<>s2: *@# fi;
                 index:=index+1;
 endfor;
 if numpoints>(index-1): errmessage "Missing parameter"; message str aa; fi;
 if numpoints<(index-1): errmessage "Too many parameters"; message str aa; fi;
 aa:=ydata[merke];
 if gencheck: message str aa fi;
enddef;

vardef extended_gendef@#(text aa)(text t)=
 string s[];
 s1:="";
 s2:=str @#;
 index:=1;
 forsuffixes $=t: ydata[index]:=$ if s1<>s2: *@# fi;
                 index:=index+1;
 endfor;
 if numpoints>(index-1): errmessage "Missing parameter"; message str aa; fi;
 if numpoints<(index-1): errmessage "Too many parameters"; message str aa; fi;
 if gensize>basedata[numpoints]:
   numeric hilf [];
   hilf[1]:=(ydata[numpoints]-ydata[numpoints-1])/(basedata[numpoints]-basedata[numpoints-1]);
   hilf[2]:=(ydata[numpoints]-ydata[numpoints-2])/(basedata[numpoints]-basedata[numpoints-2]);
   hilf[3]:=ydata[numpoints]-hilf1*basedata[numpoints];
   hilf[4]:=ydata[numpoints]-hilf2*basedata[numpoints];
   spy:=(hilf[1]*gensize+hilf[3])/2+(hilf[2]*gensize+hilf[4])/2;
   aa:=spy;
 else:
 for index = 1 upto numpoints-1:
    interval[index]:=basedata[index+1]-basedata[index];
 endfor;
 for index=1 upto numpoints:
    spline[1][index]:=ydata[index];
 endfor;
 for index=2 upto numpoints-1:
    alpha[index]:=3*((spline[1][index+1]*interval[index-1])%
                   -(spline[1][index]*(basedata[index+1]-basedata[index-1]))%
                   +(spline[1][index-1]*interval[index]))%
                   /(interval[index-1]*interval[index]);
 endfor;
 spl[1]:=0;
 spmu[1]:=0;
 spz[1]:=0;
 for index=2 upto numpoints-1:
    spl[index]:=2*(basedata[index+1]-basedata[index-1])%
                 -interval[index-1]*spmu[index-1];
    spmu[index]:=interval[index]/spl[index];
    spz[index]:=(alpha[index]-interval[index-1]*spz[index-1])/spl[index];
 endfor;
 spline[3][numpoints]:=0;
 for index=numpoints-1 downto 1:
    spline[3][index]:=spz[index]-spmu[index]*spline[3][index+1];
 endfor;
 for index=numpoints -1 downto 1:
    spline[2][index]:=(spline[1][index+1]-spline[1][index])/interval[index]%
             -interval[index]*(spline[3][index+1]*spline[3][index])/3;
    spline[4][index]:=(spline[3][index+1]-spline[3][index])/(3*interval[index]);
 endfor;
 location:=1;
 for term=1 upto numpoints-1:
    if gensize > basedata[term]: location:=term; fi
 endfor;
 spx:=gensize-basedata[location];
 spy:=((spline[4][location]*spx+spline[3][location])*spx+spline[2][location])*spx+spline[1][location];
 aa:=spy; fi;
 if gencheck: message str aa fi;
enddef;

vardef basedef(text t)=
 boolean basevalue; boolean gencheck;
 numeric index; numeric ergbnis; numeric location; numeric term;
 numeric numpoints; numeric spx; numeric spy;
 numeric basedata[]; numeric interval[]; numeric alpha[];
 numeric spl[]; numeric spmu[]; numeric spz[];
 numeric ydata[]; numeric spline[][];
 basevalue:=false; gencheck:=false;
 index:=1;
 forsuffixes $=t: basedata[index]:=$;
                 if $=gensize: basevalue:=true; merke:=index; fi;
                 index:=index+1;
 endfor;
 numpoints:=index-1;
 if numpoints<3: errmessage "Not enough reference points"; fi
 if basevalue: def gendef=simple_gendef enddef; else:
               def gendef=extended_gendef enddef; fi
enddef;

def clear_extra_memory= % Release ressources hold by the extrapolation routine
 numeric index; numeric ergbnis; numeric location; numeric term;
 numeric numpoints; numeric spx; numeric spy;
 numeric basedata[]; numeric interval[]; numeric alpha[];
 numeric spl[]; numeric spmu[]; numeric spz[];
 numeric ydata[]; numeric spline[][];
 numeric hilf []; string s[];
enddef;

endinput;