-
Notifications
You must be signed in to change notification settings - Fork 1
/
fontbase.mf
722 lines (704 loc) · 14.4 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% MF Adjuster v1.36 %
% © 2014 by Marco Mueller and Simon Egli %
% thanks to Christian Vetter, Linus Roemer, Alexis Reigel %
% www.metaflop.com %
% licensed under gpl v3: www.gnu.org/licenses/ %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% additional parameters / hidden parameter list for metrics %
s#:=0u#; % extra space
leftstemloc#:=0u#; % position of left stem
letter_fit#:=0u#; % ad-hoc dimension that adds to all sidebearings
shrink_fit:=1u#; % amount subtracted from w before each character in the font has been drawn
space:=3; % letterspacing (0 = compress)
% sidebearings %
def normal_adjust_fit(expr left_adjustment,right_adjustment) =
l := -hround(left_adjustment*hppp)-letter_fit#;
interim xoffset := -l;
charwd := charwd+2letter_fit#+left_adjustment+right_adjustment;
r := l+hround(charwd*hppp)-shrink_fit;
w := r-hround(right_adjustment*hppp)-letter_fit#;
enddef;
mode=luxo;
mode_setup;
% font infos %
font_quad:=10u#+0s#;
font_normal_space:=3u#+0s#;
font_normal_stretch:=0u#;
font_normal_shrink:=0u#;
font_coding_scheme:="T1";
% pixel conversions %
define_pixels(s,u);
define_blacker_pixels(px,py);
define_good_x_pixels(leftstemloc,letter_fit);
define_good_y_pixels(bar1,bar2,bar3,bar4,bar5,cap);
% enc numbers %
def enc(expr name)=
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="softhyphen":
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
enddef;
% composite glyphs %
numeric charwidths_[]; % will store the width of every char at the index of the encoding number
numeric charheights_[]; % as above for heights
numeric chardepths_[]; % as above for depths
picture charpictures_[]; % as above for the pictures (the glyphs themselves)
numeric charitalcorrs_[];% as above for italic corrections
numeric charxoffsets_[]; % as above for the xoffsets
pair charanchortops_[]; % choose some sensible anchors (top, bot ...)
pair charanchorbots_[];
% begin character macros %
def beginadjchar(expr code, unit_width, h, d) =
beginchar(code,unit_width*u#+s#,h,d);
pickup adj_pen;
enddef;
% end character macros %
extra_endchar := extra_endchar&"charpictures_[charcode]:=currentpicture;"
&"charwidths_[charcode]=charwd;"
&"charheights_[charcode]=charht;"
&"chardepths_[charcode]=chardp;"
&"charitalcorrs_[charcode]=charic;"
&"charxoffsets_[charcode]=xoffset;";
% composite glyphs %
def composite(expr codea,codeb,codec,anchor,height,depth) =
widthb:=charwidths_[codeb];
charicb:=charitalcorrs_[codeb];
beginchar(codea,widthb,height,depth);
charic:=charicb;
interim xoffset:=charxoffsets_[codeb];
addto currentpicture also charpictures_[codeb];
if anchor="top":
addto currentpicture also charpictures_[codec] shifted
(charanchortops_[codeb]-charanchortops_[codec]);
elseif anchor="bot":
addto currentpicture also charpictures_[codec] shifted
(charanchorbots_[codeb]-charanchorbots_[codec]);
else:
errmessage "Wrong anchor name";
fi
endchar;
enddef;
% pen settings %
if penshape=1:
pickup pencircle xscaled px yscaled py rotated penang;
elseif penshape=2:
pickup pensquare xscaled px yscaled py rotated penang;
elseif penshape=3:
pickup penrazor xscaled px rotated penang;
fi
adj_pen:=savepen;
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],
else:
ligmatrix_[i][j][0] kern ligmatrix_[i][j][1],
fi
endfor
%last entry needs a semicolon:
if ligmatrix_[i][n][0]<0: % the minus is a flag for "ligature"
-ligmatrix_[i][n][0]=:ligmatrix_[i][n][1];
else:
ligmatrix_[i][n][0] kern ligmatrix_[i][n][1];
fi
fi
endfor
endgroup
enddef;