-
Notifications
You must be signed in to change notification settings - Fork 1
/
fontbase.mf
1014 lines (983 loc) · 22.6 KB
/
fontbase.mf
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% MF Calport v1.45 %
% © 2021 by Marco Mueller %
% thanks to Linus Roemer, Alexis Reigel, Jeremy Gibbons %
% <http://www.metaflop.com> %
% licensed under gpl v3: www.gnu.org/licenses/ %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% general %
define_pixels(s,u,xgap,px,py,ptiny,x_ht,ht,o,desc_depth);
if unknown slant: slant:=0 else: currenttransform:=
identity slanted slant yscaled aspect_ratio fi;
ho#:=o#; % horizontal overshoot
leftstemloc#:=2.5u#+s#; % position of left stem
letter_fit#:=0.0u#; % ad-hoc dimension that adds to all sidebearings
shrink_fit:=0.0u#; % amount subtracted from w before each character in the font has been drawn
mode=luxo;
mode_setup;
% slant %
if unknown slant: slant:=0 else: currenttransform:=
identity slanted slant yscaled aspect_ratio
fi;
% font infos %
font_coding_scheme "T1";
font_normal_stretch 3u#;
font_normal_shrink 2u#;
font_x_height x_ht#;
font_quad 18u#+2s#;
font_extra_space 2u#;
font_slant slant;
% enc encodes names to numbers, so enc("A")=65
% altough defining an array first seems to be
% a good idea, it turns out that this variant
% is significantly faster!
def enc(expr name)=
if (font_coding_scheme_="T1"):
if name="grave":
0
elseif name="acute":
1
elseif name="circumflex":
2
elseif name="tilde":
3
elseif name="dieresis":
4
elseif name="hungarumlaut":
5
elseif name="ring":
6
elseif name="caron":
7
elseif name="breve":
8
elseif name="macron":
9
elseif name="dotaccent":
10
elseif name="cedilla":
11
elseif name="ogonek":
12
elseif name="quotesinglbase":
13
elseif name="guilsinglleft":
14
elseif name="guilsinglright":
15
elseif name="quotedblleft":
16
elseif name="quotedblright":
17
elseif name="quotedblbase":
18
elseif name="guillemotleft":
19
elseif name="guillemotright":
20
elseif name="endash":
21
elseif name="emdash":
22
elseif name="cwm":
23
elseif name="perthousandzero":
24
elseif name="dotlessi":
25
elseif name="dotlessj":
26
elseif name="ff":
27
elseif name="fi":
28
elseif name="fl":
29
elseif name="ffi":
30
elseif name="ffl":
31
elseif name="visiblespace":
32
elseif name="exclam":
33
elseif name="quotedbl":
34
elseif name="numbersign":
35
elseif name="dollar":
36
elseif name="percent":
37
elseif name="ampersand":
38
elseif name="quoteright":
39
elseif name="parenleft":
40
elseif name="parenright":
41
elseif name="asterisk":
42
elseif name="plus":
43
elseif name="comma":
44
elseif name="hyphen":
45
elseif name="period":
46
elseif name="slash":
47
elseif name="zero":
48
elseif name="one":
49
elseif name="two":
50
elseif name="three":
51
elseif name="four":
52
elseif name="five":
53
elseif name="six":
54
elseif name="seven":
55
elseif name="eight":
56
elseif name="nine":
57
elseif name="colon":
58
elseif name="semicolon":
59
elseif name="less":
60
elseif name="equal":
61
elseif name="greater":
62
elseif name="question":
63
elseif name="at":
64
elseif name="A":
65
elseif name="B":
66
elseif name="C":
67
elseif name="D":
68
elseif name="E":
69
elseif name="F":
70
elseif name="G":
71
elseif name="H":
72
elseif name="I":
73
elseif name="J":
74
elseif name="K":
75
elseif name="L":
76
elseif name="M":
77
elseif name="N":
78
elseif name="O":
79
elseif name="P":
80
elseif name="Q":
81
elseif name="R":
82
elseif name="S":
83
elseif name="T":
84
elseif name="U":
85
elseif name="V":
86
elseif name="W":
87
elseif name="X":
88
elseif name="Y":
89
elseif name="Z":
90
elseif name="bracketleft":
91
elseif name="backslash":
92
elseif name="bracketright":
93
elseif name="asciicircum":
94
elseif name="underscore":
95
elseif name="quoteleft":
96
elseif name="a":
97
elseif name="b":
98
elseif name="c":
99
elseif name="d":
100
elseif name="e":
101
elseif name="f":
102
elseif name="g":
103
elseif name="h":
104
elseif name="i":
105
elseif name="j":
106
elseif name="k":
107
elseif name="l":
108
elseif name="m":
109
elseif name="n":
110
elseif name="o":
111
elseif name="p":
112
elseif name="q":
113
elseif name="r":
114
elseif name="s":
115
elseif name="t":
116
elseif name="u":
117
elseif name="v":
118
elseif name="w":
119
elseif name="x":
120
elseif name="y":
121
elseif name="z":
122
elseif name="braceleft":
123
elseif name="bar":
124
elseif name="braceright":
125
elseif name="asciitilde":
126
elseif name="dash":
127
elseif name="Abreve":
128
elseif name="Aogonek":
129
elseif name="Cacute":
130
elseif name="Ccaron":
131
elseif name="Dcaron":
132
elseif name="Ecaron":
133
elseif name="Eogonek":
134
elseif name="Gbreve":
135
elseif name="Lacute":
136
elseif name="Lcaron":
137
elseif name="Lslash":
138
elseif name="Nacute":
139
elseif name="Ncaron":
140
elseif name="Eng":
141
elseif name="Ohungarumlaut":
142
elseif name="Racute":
143
elseif name="Rcaron":
144
elseif name="Sacute":
145
elseif name="Scaron":
146
elseif name="Scedilla":
147
elseif name="Tcaron":
148
elseif name="Tcedilla":
149
elseif name="Uhungarumlaut":
150
elseif name="Uring":
151
elseif name="Ydieresis":
152
elseif name="Zacute":
153
elseif name="Zcaron":
154
elseif name="Zdotaccent":
155
elseif name="IJ":
156
elseif name="Idotaccent":
157
elseif name="dcroat":
158
elseif name="section":
159
elseif name="abreve":
160
elseif name="aogonek":
161
elseif name="cacute":
162
elseif name="ccaron":
163
elseif name="dcaron":
164
elseif name="ecaron":
165
elseif name="eogonek":
166
elseif name="gbreve":
167
elseif name="lacute":
168
elseif name="lcaron":
169
elseif name="lslash":
170
elseif name="nacute":
171
elseif name="ncaron":
172
elseif name="eng":
173
elseif name="ohungarumlaut":
174
elseif name="racute":
175
elseif name="rcaron":
176
elseif name="sacute":
177
elseif name="scaron":
178
elseif name="scedilla":
179
elseif name="tcaron":
180
elseif name="tcedilla":
181
elseif name="uhungarumlaut":
182
elseif name="uring":
183
elseif name="ydieresis":
184
elseif name="zacute":
185
elseif name="zcaron":
186
elseif name="zdotaccent":
187
elseif name="ij":
188
elseif name="exclamdown":
189
elseif name="questiondown":
190
elseif name="sterling":
191
elseif name="Agrave":
192
elseif name="Aacute":
193
elseif name="Acircumflex":
194
elseif name="Atilde":
195
elseif name="Adieresis":
196
elseif name="Aring":
197
elseif name="AE":
198
elseif name="Ccedilla":
199
elseif name="Egrave":
200
elseif name="Eacute":
201
elseif name="Ecircumflex":
202
elseif name="Edieresis":
203
elseif name="Igrave":
204
elseif name="Iacute":
205
elseif name="Icircumflex":
206
elseif name="Idieresis":
207
elseif name="Eth":
208
elseif name="Ntilde":
209
elseif name="Ograve":
210
elseif name="Oacute":
211
elseif name="Ocircumflex":
212
elseif name="Otilde":
213
elseif name="Odieresis":
214
elseif name="OE":
215
elseif name="Oslash":
216
elseif name="Ugrave":
217
elseif name="Uacute":
218
elseif name="Ucircumflex":
219
elseif name="Udieresis":
220
elseif name="Yacute":
221
elseif name="Thorn":
222
elseif name="Germandbls":
223
elseif name="agrave":
224
elseif name="aacute":
225
elseif name="acircumflex":
226
elseif name="atilde":
227
elseif name="adieresis":
228
elseif name="aring":
229
elseif name="ae":
230
elseif name="ccedilla":
231
elseif name="egrave":
232
elseif name="eacute":
233
elseif name="ecircumflex":
234
elseif name="edieresis":
235
elseif name="igrave":
236
elseif name="iacute":
237
elseif name="icircumflex":
238
elseif name="idieresis":
239
elseif name="eth":
240
elseif name="ntilde":
241
elseif name="ograve":
242
elseif name="oacute":
243
elseif name="ocircumflex":
244
elseif name="otilde":
245
elseif name="odieresis":
246
elseif name="oe":
247
elseif name="oslash":
248
elseif name="ugrave":
249
elseif name="uacute":
250
elseif name="ucircumflex":
251
elseif name="udieresis":
252
elseif name="yacute":
253
elseif name="thorn":
254
elseif name="germandbls":
255
else:
errmessage("unknown name to encode");
fi
else:
errmessage("tell me somewhere that the font_coding_scheme is T1");
fi
enddef;
% pen settings %
path penpath;
if penshape=1:
penpath=fullcircle xscaled px yscaled py rotated prot;
pickup pencircle xscaled px yscaled py rotated prot;
elseif penshape=2:
penpath=unitsquare shifted -(.5,.5) xscaled px yscaled py rotated prot;
pickup pensquare xscaled px yscaled py rotated prot;
elseif penshape=3:
penpath=((dir(-30)--dir(90)--dir(210)--cycle) xscaled .5px yscaled .5py rotated prot);
capsule_def(pentriangle) makepen(penpath);
pickup pentriangle;
elseif penshape=4:
penpath=((dir(-54)--dir(18)--dir(90)--dir(162)--dir(234)--cycle) xscaled .5px yscaled .5py rotated prot);
capsule_def(penpentagon) makepen(penpath);
pickup penpentagon;
fi
cornerpen:=savepen;
% sidebearings %
def adjustwidth(expr left_adjustment,right_adjustment) =
l:=-hround(left_adjustment*hppp);
interim xoffset:=-l;
charwd:=charwd+left_adjustment+right_adjustment;
r:=l+hround(charwd*hppp);
w:=r-hround(right_adjustment*hppp);
enddef;
def overdraw expr c = erase fill c; draw c enddef;
def overdrawsupreme expr c = begingroup
picture region; region := nullpicture;
interim turningcheck := 0; addto region contour c;
cull region dropping (0,0);
cullit; addto currentpicture also -region ; cullit;
draw c endgroup enddef;
% returns true iff the curve c has length 1 (no points
% inbetween) and is straight (curvature 0)
def isstraight(expr c) =
if (length(c)=1) and (angle(direction 1 of c)=angle(direction 0 of c))
and (angle((point 1 of c)-(point 0 of c))=angle(direction 0 of c)):
true
else:
false
fi
enddef;
% returns 1 if point p is right of the line
% going through point q heading in direction d
% returns -1 for left
% returns 0 for being on the line
def sideof(expr p,q,d) =
if xpart(d)*(ypart(q)-ypart(p))>ypart(d)*(xpart(q)-xpart(p)):
1
elseif xpart(d)*(ypart(q)-ypart(p))=ypart(d)*(xpart(q)-xpart(p)):
0
else:
-1
fi
enddef;
% returns true iff point p is inside the curve c
% the idea is to check for a bunch of points on c
% if p is always on the same side of the tangent
def isinside(expr p,c) =
if (point length(c) of c = point 0 of c):
begingroup
save inside,side;
boolean inside;
inside=true;
side:=sideof(p,point 0 of c,direction 0 of c);
for k=0 upto length(c)-1:
for i=1 upto 5:
if sideof(p,point (k+i/5) of c,direction (k+i/5) of c)*side<=0:
inside:=false;
fi
exitif not inside;
endfor
endfor
inside
endgroup
else:
false
fi
enddef;
% draw white carpet
%
% draws a point on curve c with time t
% with respect to the future point with time s
def moondraw(expr c,t,s) =
begingroup
save curvea,curveb,firsttimea,secondtimea;
path curvea,curveb;
curvea = penpath shifted point t of c;
curveb = penpath shifted point s of c;
% we know that there will be most probably only two
% intersection points, hence: using reverse curve!
firsttimea:=xpart(curvea intersectiontimes curveb);
secondtimea:=length(curvea)-xpart((reverse curvea) intersectiontimes curveb);
if not(point s of c = point t of c): % avoid a complete overlapping
if isinside(point .5[firsttimea,secondtimea] of curvea,curveb):
draw (subpath(secondtimea,length(curvea)) of curvea).. (subpath(0,firsttimea) of curvea)
else:
draw subpath(firsttimea,secondtimea) of curvea
fi
fi
endgroup
enddef;
% generalization of arclength (also for MF)
def arcl(expr c) =
if known color Wolfgang Amadeus Mozart:
arclength(c)
else:
begingroup
save arc,alpha;
arc:=0;
for k=0 upto length(c)-1:
if isstraight(subpath(k,k+1) of c):
arc:=arc+length((point (k+1) of c)-(point k of c));
else:
for i=1 upto 100:
arc:=arc+length((point (k+i/100) of c)-(point (k+(i-1)/100) of c));
endfor
fi
endfor
arc
endgroup
fi
enddef;
% generalization of arctime (also for MF)
def arct(expr l,c) =
if known color Wolfgang Amadeus Mozart:
arctime l of c
else:
begingroup
save old,arc,i;
arc:=0;
i:=0;
forever:
old:=arc;
arc:=arc+length((point i/100 of c)-(point (i-1)/100 of c));
exitif arc>l;
i:=i+1;
exitif i>=length(c)*100;
endfor
(i-(arc-l)/(arc-old))/100
endgroup
fi
enddef;
% interdotdraw marks a path with equally spaced dots
% the vertices inbetween the starting and end vertices
% are generally not hit exactly (in contrast to dotdraw)
def interdotdraw expr c =
if drawingstyle=1:
pickup cornerpen;
draw c;
elseif (drawingstyle=2) or (drawingstyle=3):
begingroup
pickup pencircle scaled ptiny;
% measure the length of the arc:
save divnumber,divlength;
divnumber:=floor(.5+dnum/(max(px,py))*arcl(c)); % number of points on one subpath
divlength:=1/divnumber*arcl(c);
% draw a white carpet anyway
if drawingstyle=3:
for i=0 upto divnumber:
erase fill penpath shifted point arct(divlength*i,c) of c;
endfor
fi
for i=0 upto divnumber:
if drawingstyle=3:
if not (((point length(c) of c)=(point 0 of c))
and (i>max(divnumber/2,divnumber-3))): % this is just an
% approximation to avoid the comma problem, so the last points
% won't get a white carpet, if the path is cyclic
erase fill penpath shifted point arct(divlength*i,c) of c;
fi
moondraw(c,arct(divlength*i,c),arct(divlength*(i+1),c));
else:
fill penpath shifted point arct(divlength*i,c) of c;
fi
endfor
% draw last point
if drawingstyle=3:
if (point length(c) of c) = (point 0 of c): % if c is cyclic
moondraw(c,length(c),0);
else:
erase fill penpath shifted point length(c) of c;
draw penpath shifted point length(c) of c
fi
else:
fill penpath shifted point length(c) of c;
fi
endgroup
fi
enddef;
% dotdraw marks a path with approximately equally spaced dots
% the vertices inbetween the starting and end vertices
% are hit exactly (in contrast to interdotdraw)
def dotdraw expr c =
if drawingstyle=1:
pickup cornerpen;
draw c;
elseif (drawingstyle=2) or (drawingstyle=3):
pickup pencircle scaled ptiny;
% if the path is a single point:
if pair c:
if drawingstyle=3:
erase fill penpath shifted c;
draw penpath shifted c
else:
fill penpath shifted c;
fi
else:
begingroup
% measure the length of the arc:
save divnumber,divlength,cc;
path cc;
% draw a white carpet anyway
if drawingstyle=3:
for k=0 upto length(c)-1:
cc:=subpath(k,k+1) of c;
divnumber:=floor(.5+dnum/(max(px,py))*arcl(cc)); % number of points on one subpath
divlength:=1/divnumber*arcl(cc);
for i=0 upto divnumber-1:
erase fill penpath shifted point arct(divlength*i,cc) of cc;
endfor
endfor
fi
% draw actual points
for k=0 upto length(c)-1:
cc:=subpath(k,k+1) of c;
divnumber:=floor(.5+dnum/(max(px,py))*arcl(cc)); % number of points on one subpath
divlength:=1/divnumber*arcl(cc);
for i=0 upto divnumber-1:
if drawingstyle=3:
if not (((point length(c) of c)=(point 0 of c))
and (k=length(c)-1)): % this is just an
% approximation to avoid the comma problem, so the last points
% won't get a white carpet, if the path is cyclic
erase fill penpath shifted point arct(divlength*i,cc) of cc;
fi
moondraw(cc,arct(divlength*i,cc),arct(divlength*(i+1),cc));
else:
fill penpath shifted point arct(divlength*i,cc) of cc;
fi
endfor
endfor
% draw last point
if drawingstyle=3:
if (point length(c) of c)=(point 0 of c): % if c is cyclic
moondraw(c,length(c),0);
else:
erase fill penpath shifted point length(c) of c;
draw penpath shifted point length(c) of c
fi
else:
fill penpath shifted point length(c) of c;
fi
endgroup
fi
fi
enddef;
code_offset:=0; % may later used for small caps
% composite glyphs %
numeric charwidths_[];
numeric charheights_[];
numeric chardepths_[];
numeric charitalcorrs_[];
picture charpictures_[];
pair charanchortops_[];
pair charanchorbots_[];
pair charanchortoprights_[];
% begin and end character macros %
def clpchar(expr name, width, height, depth) =
beginchar(enc(name)+code_offset,width,height,depth)
enddef;
extra_endchar := extra_endchar&"charpictures_[charcode]:=currentpicture;"
&"charwidths_[charcode]=charwd;"
&"charheights_[charcode]=charht;"
&"chardepths_[charcode]=chardp;"
&"charitalcorrs_[charcode]=charic;";
% composite glyphs %
def clpcombinedchar(expr namea,nameb,namec,anchor,height,depth) =
beginchar(enc(namea)+code_offset,charwidths_[enc(nameb)+code_offset],height,depth);
charic:=charitalcorrs_[enc(nameb)+code_offset];
addto currentpicture also charpictures_[enc(nameb)+code_offset];
if anchor="top":
addto currentpicture also charpictures_[enc(namec)] shifted
((charanchortops_[enc(nameb)+code_offset]-charanchortops_[enc(namec)]) slanted slant);
elseif anchor="bot":
addto currentpicture also charpictures_[enc(namec)] shifted
((charanchorbots_[enc(nameb)+code_offset]-charanchorbots_[enc(namec)]) slanted slant);
elseif anchor="topright":
addto currentpicture also charpictures_[enc(namec)] shifted
((charanchortoprights_[enc(nameb)+code_offset]-charanchortoprights_[enc(namec)]) slanted slant);
else:
errmessage "Wrong anchor name";
fi
endchar;
enddef;
% chain two chars like "f" and "l" to "fl"
def clpchainedchar(expr namea,nameb,namec) =
beginchar(
enc(namea)+code_offset,
charwidths_[enc(nameb)+code_offset]
+charwidths_[enc(namec)+code_offset],
max(charheights_[enc(nameb)+code_offset],
+charheights_[enc(namec)+code_offset]),
max(chardepths_[enc(nameb)+code_offset],
+chardepths_[enc(namec)]+code_offset)
);
charic:=charitalcorrs_[enc(nameb)+code_offset];
addto currentpicture also charpictures_[enc(nameb)+code_offset];
addto currentpicture also charpictures_[enc(namec)+code_offset]
shifted (charwidths_[enc(nameb)+code_offset]*hppp,0);
endchar;
enddef;
% copy a letter nameb to namea
def clpcopiedchar(expr namea,nameb) =
beginchar(
enc(namea),
charwidths_[enc(nameb)],
charheights_[enc(nameb)],
chardepths_[enc(nameb)]
);
charic:=charitalcorrs_[enc(nameb)];
addto currentpicture also charpictures_[enc(nameb)];
endchar;
enddef;
% kernings
numeric kernclassesf_[][], % list of kerning classes (first position)
kernclassess_[][], % list of kerning classes (second position)
ligmatrix_[][][]; % matrix with kern and ligature entries: 255 times X times 2
kernclassesf_[0][0]=0; % number of kernclassesf (will be increased)
kernclassess_[0][0]=0; % number of kernclassess (will be increased)
for i=0 upto 255:
ligmatrix_[i][0][0]:=0; % every char i begins with no kernings (will be increased)
endfor
def addkernclassf(text a) = % add a kerning class to kernclassesf
kernclassesf_[0][0]:=kernclassesf_[0][0]+1; % number of kernclassesf
begingroup
save i;
i:=0; % number of chars in current class
for b=a:
i:=i+1;
kernclassesf_[kernclassesf_[0][0]][i]:=enc(b);
endfor
% number of chars in current class is stored at 0th position
kernclassesf_[kernclassesf_[0][0]][0]:=i;
endgroup
enddef;
def addkernclasss(text a) = % add a kerning class to kernclassess
kernclassess_[0][0]:=kernclassess_[0][0]+1; % number of kernclassess
begingroup
save i,n;
n:=kernclassess_[0][0]; % current last class (being written)
i:=0; % number of chars in current class
for b=a:
i:=i+1;
kernclassess_[n][i]:=enc(b);
endfor
% number of chars in current class is stored at 0th position
kernclassess_[n][0]:=i;
endgroup
enddef;
def addlig(expr first,second,third) = % replace first and second to the ligature third
begingroup
save i,n;
i:=enc(first); % encoding number of first
ligmatrix_[i][0][0]:=ligmatrix_[i][0][0]+1;
n:=ligmatrix_[i][0][0]; % current last ligature entry index of i (being written)
ligmatrix_[i][0][0]:=n;
ligmatrix_[i][n][0]:=-enc(second); % the minus is a flag for "ligature" instead of "kern"
ligmatrix_[i][n][1]:=enc(third);
endgroup
enddef;
def addclasskern(expr first,second,kvalue) = % kern all chars of first class and second class by kvalue
begingroup
save i,j,m,n;
% get the indices i and j of the two classes:
i:=0; % default value (cannot be true)
j:=0; % default value (cannot be true)
forever:
i:=i+1;
exitif kernclassesf_[i][1]=enc(first);
if i>255:
errmessage("unknown first kerning class");
fi
endfor
forever:
j:=j+1;
exitif kernclassess_[j][1]=enc(second);
if j>255:
errmessage("unknown first kerning class");
fi
endfor
for k=1 upto kernclassesf_[i][0]:
m:=kernclassesf_[i][k]; % current first glyph
for l=1 upto kernclassess_[j][0]:
ligmatrix_[m][0][0]:=ligmatrix_[m][0][0]+1;
n:=ligmatrix_[m][0][0]; % current last entry index (being written)
ligmatrix_[m][n][0]:=kernclassess_[j][l];
ligmatrix_[m][n][1]:=kvalue;
endfor
endfor
endgroup
enddef;
def writeligtable = % write all kernings/ligatures at once
begingroup
save n;
for i=0 upto 255: % current glyph i
n:=ligmatrix_[i][0][0]; % number n of entries for glyph i
if n<>0: % skip empty entries
ligtable i:
for j=1 upto n-1: %last entry needs a semicolon
if ligmatrix_[i][j][0]<0: % the minus is a flag for "ligature"
-ligmatrix_[i][j][0]=:ligmatrix_[i][j][1],