summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/fonts/source/vntex/vnr/vnbase.mf
blob: a87e32ce6c8505f18879cfdfe2f2d39c3a20a2fd (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
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
% Copyright 2003-2005 Han The Thanh <hanthethanh@gmx.net>.
% This file is part of vntex.  License: LPPL, version 1.3 or newer,
% according to http://www.latex-project.org/lppl.txt

% basic macros for all vnr fonts

% get_acc_pos := 1;
% gen_t5_supp := 1;

if known get_acc_pos or known gen_t5_supp:
    mag := 100.375;
fi

% define which letters should be generated when testing > 0
def testchars =
% a.acute_,
% a.dot_,
% a.grave_,
% a.hook_,
% a.tilde_,
% a.breve_,
% a.breve_.acute_,
% a.breve_.dot_,
% a.breve_.grave_,
% a.breve_.hook_,
% a.breve_.tilde_,
% a.circumflex_,
% a.circumflex_.acute_,
% a.circumflex_.dot_,
% a.circumflex_.grave_,
% a.circumflex_.hook_,
% a.circumflex_.tilde_,
% d.bar_,
% e.acute_,
% e.dot_,
% e.grave_,
% e.hook_,
% e.tilde_,
% e.circumflex_,
% e.circumflex_.acute_,
% e.circumflex_.dot_,
% e.circumflex_.grave_,
% e.circumflex_.hook_,
% e.circumflex_.tilde_,
% i.acute_,
% i.dot_,
% i.grave_,
% i.hook_,
% i.tilde_,
% o.acute_,
% o.dot_,
% o.grave_,
% o.hook_,
% o.tilde_,
% o.circumflex_,
% o.circumflex_.acute_,
% o.circumflex_.dot_,
% o.circumflex_.grave_,
% o.circumflex_.hook_,
% o.circumflex_.tilde_,
o.horn_,
o.horn_.acute_,
o.horn_.dot_,
o.horn_.grave_,
o.horn_.hook_,
o.horn_.tilde_,
% u.acute_,
% u.dot_,
% u.grave_,
% u.hook_,
% u.tilde_,
u.horn_,
u.horn_.acute_,
u.horn_.dot_,
u.horn_.grave_,
u.horn_.hook_,
u.horn_.tilde_,
% y.acute_,
% y.dot_,
% y.grave_,
% y.hook_,
% y.tilde_,
last
enddef;

C.l.last := 256;
C.u.last := 256;

% copied from plain.mf to make metapost run with ec sources, as mfplain.mp is not
% up-to-date with plain.mf
vardef whatever = save ?; ? enddef;
def killtext text t = enddef;


if known testing: % turn testing on
%     proofcolor := .4[white, black];
    defaultfont := "Times-Roman";
    defaultscale := 1;
    prologues := 1;
    show_labels := 1;
    if known gensize:
        mag := 20/gensize;
    else:
        mag := 2;
    fi
fi

if unknown exbase:
    input exbase;
fi

if unknown displaying:
    displaying := 0;
fi

let vnchar = ecchar;
let cmchar = ecchar;

input vncode;   % character encoding

if known testing:
string inputstr;
forsuffixes _u =
    A_fam_used, D_fam_used, E_fam_used, I_fam_used, O_fam_used, U_fam_used, Y_fam_used,
    a_fam_used, d_fam_used, e_fam_used, i_fam_used, o_fam_used, u_fam_used, y_fam_used:
    boolean _u;
    _u := false;
endfor;

def test_fam(text _f, _u, _c) =
    n_ := 0;
    if not _u:
        forsuffixes $ = _f(,) 257:
            n_ := n_ + 1;
            if (($ < 32) or ($ > 127)) % check for vn chars only
               and ($ = C.u._c) or ($ = C.l._c):
                _u := true;
            fi
        endfor
    fi
enddef;

forsuffixes _c = testchars:
    test_fam(A_fam)(A_fam_used)(_c);
    test_fam(D_fam)(D_fam_used)(_c);
    test_fam(E_fam)(E_fam_used)(_c);
    test_fam(I_fam)(I_fam_used)(_c);
    test_fam(O_fam)(O_fam_used)(_c);
    test_fam(U_fam)(U_fam_used)(_c);
    test_fam(Y_fam)(Y_fam_used)(_c);

    test_fam(a_fam)(a_fam_used)(_c);
    test_fam(d_fam)(d_fam_used)(_c);
    test_fam(e_fam)(e_fam_used)(_c);
    test_fam(i_fam)(i_fam_used)(_c);
    test_fam(o_fam)(o_fam_used)(_c);
    test_fam(u_fam)(u_fam_used)(_c);
    test_fam(y_fam)(y_fam_used)(_c);

    test_fam(U_horn_fam)(U_fam_used)(_c);
    test_fam(u_horn_fam)(u_fam_used)(_c);
endfor

def input_ur_fam =
    inputstr := "";
    if A_fam_used: inputstr := inputstr & "input vnuar; "; fi
    if D_fam_used: inputstr := inputstr & "input vnudr; "; fi
    if E_fam_used: inputstr := inputstr & "input vnuer; "; fi
    if I_fam_used: inputstr := inputstr & "input vnuir; "; fi
    if O_fam_used: inputstr := inputstr & "input vnuor; "; fi
    if U_fam_used: inputstr := inputstr & "input vnuur; "; fi
    if Y_fam_used: inputstr := inputstr & "input vnuyr; "; fi
    scantokens(inputstr);
enddef;

def input_lr_fam =
    inputstr := "";
    if a_fam_used: inputstr := inputstr & "input vnlar; "; fi
    if d_fam_used: inputstr := inputstr & "input vnldr; "; fi
    if e_fam_used: inputstr := inputstr & "input vnler; "; fi
    if i_fam_used: inputstr := inputstr & "input vnlir; "; fi
    if o_fam_used: inputstr := inputstr & "input vnlor; "; fi
    if u_fam_used: inputstr := inputstr & "input vnlur; "; fi
    if y_fam_used: inputstr := inputstr & "input vnlyr; "; fi
    scantokens(inputstr);
enddef;

def input_sc_fam =
    inputstr := "";
    if a_fam_used: inputstr := inputstr & "input vnuar; "; fi
    if d_fam_used: inputstr := inputstr & "input vnudr; "; fi
    if e_fam_used: inputstr := inputstr & "input vnuer; "; fi
    if i_fam_used: inputstr := inputstr & "input vnuir; "; fi
    if o_fam_used: inputstr := inputstr & "input vnuor; "; fi
    if u_fam_used: inputstr := inputstr & "input vnuur; "; fi
    if y_fam_used: inputstr := inputstr & "input vnuyr; "; fi
    scantokens(inputstr);
enddef;

def input_li_fam =
    inputstr := "";
    if a_fam_used: inputstr := inputstr & "input vnlai; "; fi
    if d_fam_used: inputstr := inputstr & "input vnldi; "; fi
    if e_fam_used: inputstr := inputstr & "input vnlei; "; fi
    if i_fam_used: inputstr := inputstr & "input vnlii; "; fi
    if o_fam_used: inputstr := inputstr & "input vnloi; "; fi
    if u_fam_used: inputstr := inputstr & "input vnlui; "; fi
    if y_fam_used: inputstr := inputstr & "input vnlyi; "; fi
    scantokens(inputstr);
enddef;

% def endchar =
%  scantokens extra_endchar;
%  if proofing>0: makebox(proofrule); fi
%  chardx:=w;     % desired width of the character in pixels
%  shipit;
%  endgroup enddef;

% def makebox(text rule) =
%  for y=0,asc_height,body_height,x_height,bar_height,-desc_depth,-body_depth:
%   rule((l,y)t_,(r,y)t_); endfor % horizontals
%  for x=l,r:   rule((x,-body_depth)t_,(x,body_height)t_); endfor % verticals
%  for x=u*(1+floor(l/u)) step u until r-1:
%   rule((x,-body_depth)t_,(x,body_height)t_); endfor % more verticals
%  if charic<>0:
%   rule((r+charic*pt,h.o_),(r+charic*pt,.5h.o_)); fi % italic correction
%  enddef;

def bboxcolor = red enddef;
def bboxrule(expr w,z) =
  begingroup interim linecap:=squared;
  draw w..z withpen pencircle scaled (.4/bp_per_pixel) withcolor bboxcolor;
  endgroup
enddef;

def makebox(text rule) =
 for y=0,(cap_height+acc_height),
       asc_height,body_height,x_height,bar_height,-desc_depth,-body_depth:
  rule((l,y),(r,y)); endfor % horizontals

 for y=-3.5pt,8.5pt,(x_height+acc_height):
   rule((l-4pt,y),(l-2pt,y)); endfor
 for x=l,r:   rule((x,-body_depth),(x,body_height)); endfor % verticals
 for x=u*(1+floor(l/u)) step u until r-1:
  rule((x,-body_depth),(x,body_height)); endfor % more verticals

 for x=0.5w:
   rule((x,-body_depth-1pt),(x,-body_depth-1.5pt));
   rule((x,cap_height+acc_height+1pt),(x,cap_height+acc_height+1.5pt));
 endfor
 if charic<>0:
  rule((r+charic*pt,h.o_),(r+charic*pt,.5h.o_)); fi % italic correction
 enddef;

def makebbox(text rule) =
 for x=0,w:   bboxrule((x,-d),(x,h)); endfor % verticals
 for y = 0,h,-d: bboxrule((0, y), (w, y)); endfor
enddef;

def endchar =
    scantokens extra_endchar;
    if proofing>0: 
%         makebox(proofrule);
        makebbox(proofrule);
    fi
    shipit;
endgroup
enddef;

fi % known testing

% if (known show_labels) and (known testing):
% if (known show_labels):
%     def makebox(text r) =
%         for y = 0, h, -d:
%             r((0, y), (w, y));
%         endfor % horizontals
%         for x = 0, w:
%             r((x, -d), (x, h));
%         endfor % verticals
%     enddef;
%     def draw_box(expr x, y, w, h, p) =
%         pickup pencircle scaled p;
%         draw (x, y) -- (x, y + h) -- (x + w, y + h) -- (x + w, y) -- (x, y);
%     enddef;
% else:
%     def makebox(text r) = enddef;
%     def draw_box(expr x, y, w, h) = enddef;
%     def penlabels(text r) = enddef;
%     proofcolor := black;
% fi;

numeric case_;
small     := 0;
capital   := 1;
smallcap  := 2;

def set_lowercase =
    case_ := small;
    def vncase = l enddef;
enddef;

def set_uppercase =
    case_ := capital;
    def vncase = u enddef;
enddef;

def set_smallcap =
    case_ := smallcap;
    def vncase = l enddef;
enddef;

def casename expr _name =
if not known testing:
    "The " &
    if case_ = capital:
        "capital"
    elseif case_ = small:
        "small"
    else:
        "smallcap"
    fi &
    " letter " & _name
fi
enddef;

def ifknown(suffix _a)(expr _b) =
    if known _a: _a
    else: _b
    fi
enddef;

def tand(expr _d) =
    (sind(_d)/cosd(_d))
enddef;

def vn_code(suffix _n) =
    C.vncase._n
enddef;

def vn_pic(suffix _n) =
    vn.vncase._n.pic
enddef;

def vn_width(suffix _n) =
    vn.vncase._n.w#
enddef;

def vn_height(suffix _n) =
    vn.vncase._n.h#
enddef;

def vn_top(suffix _n) =
    vn.vncase._n.top#
enddef;

def vn_depth(suffix _n) =
    vn.vncase._n.d#
enddef;

def vn_bot(suffix _n) =
    vn.vncase._n.bot#
enddef;

def vn_ic(suffix _n) =
    vn.vncase._n.ic#
enddef;

def vn_left_adj(suffix _n) =
    vn.vncase._n.left_adj#
enddef;

def vn_right_adj(suffix _n) =
    vn.vncase._n.right_adj#
enddef;

def vn_gap(suffix _n) =
    vn.vncase._n.gap#
enddef;

def vn_join_xp(suffix _n) =
    vn.vncase._n.join.x
enddef;

def vn_join_x(suffix _n) =
    vn.vncase._n.join.x#
enddef;

def vn_rt(suffix _n) =
    vn.vncase._n.rt#
enddef;

def vn_dot_shift_y(suffix _n) =
    vn.vncase._n.dot_shift.y#
enddef;

def vn_ac_top =
    vn.vncase.accent_top#
enddef;

def vn_double_ac_top =
    vn.vncase.double_accent_top#
enddef;

let vn_left_side = vn_join_x;

def vn_right_side(suffix _a) =
    (vn_width(_a) - vn_left_side(_a))
enddef;

def align_left(suffix _a, _b) =
    0
enddef;

def vn_align_join(suffix _a, _b) =
    (vn_join_x(_a) - vn_join_x(_b))
enddef;

def vn_align_right(suffix _a, _b) =
    (vn_width(_a) - vn_width(_b))
enddef;

def define_accent_dimens(suffix _a)(expr _w, _h) =
    vn_width(_a) := _w;
    vn_height(_a) := _h;
    vn_top(_a) := vn_height(_a) + vn_letter_height# + vn_accent_gap#;
    vn_max_ac_top# := max(vn_max_ac_top#, vn_top(_a));
enddef;

def vn_set_ac_join(suffix _a)(expr _xp, _x, _rt) =
    vn_join_xp(_a) := _xp;
    vn_join_x(_a) := _x;
    vn_rt(_a) := _rt;
    if known show_labels:
        makelabel("j", (vn_join_xp(_a), 0));
        makelabel("J", (hp(vn_join_x(_a)), 0));
        makelabel("r", (hp(vn_width(_a)), vp(vn_rt(_a))));
        makelabel("o", (0,0));
    fi
enddef;

def set_letter_join(suffix _l)(expr _xp, _x) =
    vn_join_xp(_l) := _xp;
    vn_join_x(_l) := _x;
    if known show_labels:
        makelabel("j", (vn_join_xp(_l), vp(vn_height(_l))));
        makelabel("J", (hp(vn_join_x(_l)), vp(vn_height(_l))));
    fi
enddef;

def set_adj_gap(suffix _l, _a) =
    adj_gap# := ifknown(vn_gap(_l._a), ifknown(vn_gap(_a), 0));
enddef;

def get_join_xp(suffix _l, _a) =
    ifknown(vn_join_xp(_l._a), vn_join_xp(_l))
enddef;

def get_join_x(suffix _l, _a) =
    ifknown(vn_join_x(_l._a), vn_join_x(_l))
enddef;

def get_top(suffix _a) =
    max(vn_top(_a) + adj_gap#,
        if vn_top(_a) <= vn_ac_top:
            vn_ac_top
        else:
            vn_double_ac_top
        fi)
enddef;

def set_shift(suffix _l, _a) =
    shift.y  := vp(vn_top(_a) - vn_height(_a));
    shift.x  := get_join_xp(_l, _a) - vn_join_xp(_a) + slant*shift.y;
    shift.y# := vn_top(_a) - vn_height(_a);
    shift.x# := get_join_x(_l, _a) - vn_join_x(_a) + slant*shift.y#;
enddef;

def set_ic(suffix _l, _a) =
    italcorr max(vn_ic(_l), 
                 vn_width(_a) + shift.x#
                 + slant*(vn_rt(_a) + shift.y#) 
                 - w# + .5u#);
enddef;

def set_lic(suffix _l) =
    italcorr vn_ic(_l);
enddef;

def set_fit(suffix _l) =
    adjust_fit(vn_left_adj(_l), vn_right_adj(_l));
enddef;

C.l.idot.dot_ = 256;
C.u.idot.dot_ = 256;    % to avoid error when calling set_dot_shift(idot)

def set_dot_shift(suffix _l) =
    shift.y := - vp(ifknown(vn_dot_shift_y(_l), vn_bot(dot_)));
    shift.x := get_join_xp(_l, dot_) - vn_join_xp(dot_) + slant*shift.y;
enddef;

% vardef xpos@#(expr b ,d) =
%     pos@#(max(currentbreadth + eps, b), d)
% enddef;
vardef pos@#(expr b,d) =
    if known b: if b<=currentbreadth:
        (x@#r-x@#l,y@#r-y@#l)=(eps,0) rotated d;
    else: (x@#r-x@#l,y@#r-y@#l)=(b-currentbreadth,0) rotated d; fi
    else: (x@#r-x@#l,y@#r-y@#l)=(b-currentbreadth,0) rotated d; fi
    x@#=.5(x@#l+x@#r); y@#=.5(y@#l+y@#r)
enddef;

def hp(expr _x) =
    hround(_x*hppp)
enddef;

def vp(expr _y) =
    vround(_y*vppp)
enddef;

def begin_pic(suffix _n) =
    begingroup
        clearxy;
        clearit;
        clearpen;
        picture vn.vncase._n.pic;
        vn.vncase._n.pic :=
        begingroup
enddef;

def end_pic =
        if known testing: 
%             makebox(proofrule); 
            makebbox(proofrule); 
        fi
            currentpicture  % continuation of `vn_pic(_n) :='
        endgroup;
    endgroup
enddef;

def set_letter_dimens(suffix _l)(expr _w, _h, _d, _ic, _lft, _rt) =
    set_char_dimens(_w, _h, _d);
    vn_width(_l) := _w;
    vn_height(_l) := _h;
    vn_depth(_l) := _d;
    vn_ic(_l) := _ic;
    vn_left_adj(_l) := _lft;
    vn_right_adj(_l) := _rt;
    adjust_fit(_lft, _rt);
enddef;

def begin_accent(suffix _a) =
    begin_pic(_a);
    set_char_dimens(vn_width(_a), vn_height(_a), 0)
enddef;
let end_accent = end_pic;

let begin_letter = begin_pic;
let end_letter = end_pic;

def vn_sl_shift(suffix _a) =
%     .5slant*(adj_y# + vn_height(_a))
    0
enddef;

def set_char_dimens(expr _w, _h, _d) =
    charwd := _w;
    charht := _h;
    chardp := _d;
    w := hp(charwd);
    h := vp(charht);
    d := vp(chardp);
    charic := 0;
enddef;

def abs_round(expr _e) =
    if _e < 0:
        ceiling(_e - .5)
    else:
        floor(_e + .5)
    fi
enddef;

def write_shift_xy(suffix _l, _a)(expr _sx, _sy) =
    if known get_acc_pos and known bp_per_pixel:
        message "CC " & 
                if case_ = capital:
                    "capital"
                elseif case_ = small:
                    "small"
                else:
                    "smallcap"
                fi & " " &
                str _l & " " & 
                str _a & " " & 
                decimal(abs_round(_sx*bp_per_pixel*10/designsize)) &  " " & 
                decimal(abs_round(_sy*bp_per_pixel*10/designsize));
    fi
enddef;


def define_double_accent(suffix _a, _b)(expr _adj_x, _adj_y) =
    shift.y# := _adj_y + vn_height(_a);
    shift.x# := _adj_x + slant*shift.y#;
    define_accent_dimens(_a._b, vn_width(_a), vn_height(_b) + shift.y#);
    begin_accent(_a._b);
    currentpicture := vn_pic(_a);
    addto currentpicture also vn_pic(_b)
                         shifted (hp(shift.x#), vp(shift.y#));
    write_shift_xy(_a, _b)(hp(shift.x#), vp(shift.y#));
    vn_set_ac_join(_a._b, vn_join_xp(_a), vn_join_x(_a),
                if vn_width(_a) + slant*vn_rt(_a) >                                         
                    vn_width(_b) + shift.x# + slant*(vn_rt(_b) + shift.y#):            
                    vn_rt(_a)
                else:                                                                       
                    vn_rt(_b) + shift.y#
                fi);                                
    end_accent;
enddef;

if not known testing:
vardef used_char(expr _code) = true enddef;
else:
vardef used_char(expr _code) =
    boolean _is_used;
    _is_used := false;
    forsuffixes $ = testchars:
        if _code = vn_code($):
            _is_used := true;
        fi;
    endfor;
    _is_used
enddef;
fi

def define_vnaccent(expr _c)(suffix _a) =
    beginchar(_c, vn_width(_a), vn_height(_a), 0);
        currentpicture := vn_pic(_a);
    endchar
enddef;

def define_vnchar(suffix _l, _a) =
if used_char(vn_code(_l._a)):
    set_adj_gap(_l, _a);    % set adj_gap#
    beginchar(vn_code(_l._a), 
              vn_width(_l), 
              get_top(_a), 
              vn_depth(_l));
        set_shift(_l, _a);  % set shift.x, shift.y, shift.x# and shift.y#
        set_ic(_l, _a);     % call italcorr
        set_fit(_l);        % call adjust_fit
        currentpicture := vn_pic(_l);
        addto currentpicture also vn_pic(_a) 
            shifted (shift.x, shift.y + vp(adj_gap#));
        write_shift_xy(_l, _a)
            (shift.x + hp(vn_left_adj(_l)) + letter_fit, shift.y + vp(adj_gap#));
%         message "vn_left_adj: " & decimal hp(vn_left_adj(_l));
%         message "letter_fit: " & decimal letter_fit;
    endchar
fi
enddef;

def define_vnchar_dot(suffix _l) =
if used_char(vn_code(_l.dot_)):
    % test for the small i letter with dot
    if (case_ = small) and (vn_code(_l.dot_) = vn_code(i.dot_)):
        beginchar(vn_code(i.dot_), 
                  vn_width(idot), 
                  vn_height(idot), 
                  vn_bot(dot_));
            set_dot_shift(idot);    % set shift.x and shift.y
            set_lic(idot);          % call italcorr
            set_fit(idot);          % call adjust_fit
            currentpicture := vn_pic(idot);
    else:
        beginchar(vn_code(_l.dot_), 
                  vn_width(_l), 
                  vn_height(_l),
                  ifknown(vn_depth(_l.dot_), max(vn_bot(dot_), vn_depth(_l))));
            set_dot_shift(_l);
            set_lic(_l);
            set_fit(_l);
            currentpicture := vn_pic(_l);
    fi
            addto currentpicture also vn_pic(dot_)
                                 shifted (shift.x, shift.y);
        write_shift_xy(_l, dot_)
            (shift.x + hp(vn_left_adj(_l)) + letter_fit,  shift.y);
        endchar
fi
enddef;

def define_vnchar_dot_ac(suffix _l, _a) =
if used_char(vn_code(_l._a.dot_)):
    set_adj_gap(_l, _a);
    beginchar(vn_code(_l._a.dot_), 
              vn_width(_l), 
              get_top(_a), 
              max(vn_bot(dot_), vn_depth(_l)));
        set_shift(_l, _a);
        set_ic(_l, _a);
        set_fit(_l);
        currentpicture := vn_pic(_l);
        addto currentpicture also vn_pic(_a)
                             shifted (shift.x, shift.y + vp(adj_gap#));
        set_dot_shift(_l);
        addto currentpicture also vn_pic(dot_)
                             shifted (shift.x, shift.y);
        write_shift_xy(_l._a, dot_)
            (shift.x + hp(vn_left_adj(_l)) + letter_fit, shift.y);
    endchar
fi
enddef;

def define_vnchar_horn(suffix _l) =
if used_char(vn_code(_l.horn_)):
    select_horn(_l);
    set_shift_horn(_l);
    update_horn_width(_l);
    beginchar(vn_code(_l.horn_), 
              updated_width#,
              vn_top(cur_horn_), 
              vn_depth(_l));
        set_ic(_l, cur_horn_);
        set_fit(_l);
        select_letter_u(_l);
        addto currentpicture also vn_pic(cur_horn_)
                             shifted (shift.x, shift.y);
    endchar
fi
enddef;

def select_horn(suffix _l) = % set cur_horn_ to uhorn_ or ohorn_ according to _l
    if vn_code(_l.horn_) = vn_code(u.horn_):
        def cur_horn_ = uhorn_ enddef;
    else:
        def cur_horn_ = ohorn_ enddef;
    fi
enddef;

def update_horn_width(suffix _l) =
    _du := (shift.x + hp(vn_width(cur_horn_))) -
           (hp(vn_width(_l) + vn_left_adj(_l) + vn_right_adj(_l)) + 2letter_fit) -
           slant*(shift.y + vp(vn_height(cur_horn_)));
    updated_width# := vn_width(_l)
        if _du > .5u:
            + .5u#*floor(_du/.5u)
        fi
enddef;

def set_shift_horn(suffix _l) =
    shift.y  := vp(vn_bot(cur_horn_));
    shift.x  := vn_join_xp(_l.horn_join) - vn_join_xp(cur_horn_) +
                slant*(shift.y);
enddef;

def select_letter_u(suffix _l) =
    % test for the serif capital u letter with horn
    if serifs and (case_ <> small) and (vn_code(_l.horn_) = vn_code(u.horn_)):
        % use the modified "U" (without right part of the right serif)
        currentpicture := vn_pic(Uhorn)
    else:
        currentpicture := vn_pic(_l)
    fi
enddef;

def define_vnchar_horn_ac(suffix _l, _a) =
if used_char(vn_code(_l.horn_._a)):
    select_horn(_l); % set cur_horn_ to uhorn_ or ohorn_ according to _l
    set_adj_gap(_l, _a);
    set_shift_horn(_l);
    update_horn_width(_l);
    beginchar(vn_code(_l.horn_._a), 
              updated_width#,
              get_top(_a), 
              vn_depth(_l));
        set_ic(_l, cur_horn_);
        set_fit(_l);
        select_letter_u(_l);
        addto currentpicture also vn_pic(cur_horn_)
                             shifted (shift.x, shift.y);
        set_shift(_l.horn_, _a);
%         if serifs and (vn_code(_l.horn_._a) = vn_code(o.horn_.grave_)):
%             shift.x := shift.x + max(0, u - .3stem);
%         fi
        set_ic(_l, _a);
        addto currentpicture also vn_pic(_a)
                             shifted (shift.x, shift.y + vp(adj_gap#));
        write_shift_xy(_l.horn_, _a)
            (shift.x + hp(vn_left_adj(_l)) + letter_fit, shift.y + vp(adj_gap#));
    endchar
fi
enddef;

def define_vnchar_horn_dot(suffix _l) =
if used_char(vn_code(_l.horn_.dot_)):
    select_horn(_l); % set cur_horn_ to uhorn_ or ohorn_ according to _l
    set_shift_horn(_l);
    update_horn_width(_l);
    beginchar(vn_code(_l.horn_.dot_), 
              updated_width#,
              vn_top(cur_horn_),
              max(vn_bot(dot_), vn_depth(_l)));
        set_ic(_l, cur_horn_);
        set_fit(_l);
        select_letter_u(_l);
        addto currentpicture also vn_pic(cur_horn_)
                             shifted (shift.x, shift.y);
        set_dot_shift(_l);
%         if serifs and (vn_tt_corr = 0) and (vn_code(_l.horn_) = vn_code(o.horn_)):
%             shift.x := shift.x + .1dot_size;
%         fi
        addto currentpicture also vn_pic(dot_)
                             shifted (shift.x, shift.y);
        write_shift_xy(_l.horn_, dot_)
            (shift.x + hp(vn_left_adj(_l)) + letter_fit, shift.y);
    endchar
fi
enddef;

% hook_arc is based on super_arc from exbase.mf
vardef hook_arc.r(suffix $, $$)(expr _superness, _swap) =
    pair center, corner;
    if (y$ = y$r) or _swap:
        center = (x$$r, y$r);
        corner = (x$r, y$$r);
    else:
        center = (x$r, y$$r);
        corner = (x$$r, y$r);
    fi
    z$.r{corner - z$.r} ... _superness[center, corner]{z$$.r - z$.r} ...
        {z$$.r - corner}z$$.r
enddef;

vardef hook_arc.l(suffix $, $$)(expr _superness, _swap) =
    pair center, corner;
    if (y$ = y$r) or _swap:
        center = (x$$l, y$l);
        corner = (x$l, y$$l);
    else:
        center = (x$l, y$$l);
        corner = (x$$l, y$l);
    fi
    z$l{corner - z$l} ... _superness[center, corner]{z$$l - z$l} ...
        {z$$l - corner}z$$l
enddef;

% vn_hook_bulb is based on bulb from exbase.mf
def vn_hook_bulb(suffix $, $$, $$$) =
    z$$$r = z$$r;
    path_.l := z$l{x$$r - x$r, 0} ... {0, y$$r - y$r}z$$l;
    filldraw path_.l -- z$$r{0, y$r - y$$r} ... {x$r - x$$r, 0}z$r -- cycle; % link
    path_.r := z$$$l{0, y$r - y$$r} .. z$$$r{0, y$$r - y$r}; % near - circle
    filldraw subpath(0, xpart(path_.r intersectiontimes path_.l)) of path_.r
    -- z$$r{0, y$$r - y$r} .. cycle; % bulb
enddef;

def vn_draw_horn(suffix _a)(expr _dotsize, _horn_stem, _horn_bot_theta) =
    cur_dotsize# := _dotsize;
    cur_stem# := _horn_stem;
    define_blacker_pixels(cur_dotsize, cur_stem);
    if not square_dots:
        pickup crisp.nib;
        pos4(cur_dotsize, 90);
        top y4r = h;
        x4 = w - .5cur_dotsize;
        pos1(cur_stem, 90);
        pos2(cur_stem, 0);
        pos3(cur_stem, _horn_bot_theta - 90);
        z1r = z4r;
        rt x2r = hround(x4 + .5cur_dotsize) + 2eps;
        lft x3l = 0;
        bot y3r = 0;
        y2 = 1/3[y1, y3];
        y_ := ypart((z1{right} ... z2{down} ... z3)
                    intersectiontimes (z4l{right} .. {left}z4r));
        if y_ < 0:
            y_ := 1;
        fi
        filldraw z4r{left} .. subpath (0, y_) of (z4l{right} .. {left}z4r)
            -- cycle; % dot
        filldraw stroke z1e{right} ... z2e{down} ... {left}z3e;
        filldraw z1r--z2r--z4l--cycle;
        penlabels(0, 1, 2, 3, 4);
        vn_set_ac_join(_a, x3, .5cur_stem*sind(_horn_bot_theta),  
                    h# - .5cur_dotsize#);
    else:
        pickup fine.nib;
        pos4(cur_dotsize, 90);
        top y4r = h;
        x4 = w - .5cur_dotsize;
        pos4'(cur_dotsize, 0);
        z4' = z4;
        dot(4', 4);  % squarish dot
        horn_join := max(fine.breadth, floor cur_stem);
        horn_bot := max(fine.breadth, floor .8cur_stem);
        pos0(horn_join, 0);
        pos1(horn_join, 0);
        pos2(horn_bot, 0);
        y0 = y4;
        y1 = y4l;
        x0r = x1r = x4'r;
        lft x2l = 0;
        bot y2r = 0;
        z2' = whatever[z1, z2];
        numeric _vn_bot_width;
        pos2'(_vn_bot_width, -90 + _horn_bot_theta);
        z2l = z2'l;
        filldraw stroke z0e -- z1e .. z2'e; % tail
        penlabels(0, 1, 2', 3, 4);
        vn_set_ac_join(_a, x2', 0, h#);
    fi
    vn_bot(_a) := vn_top(_a) - vn_height(_a);
enddef;

def set_horn_join(suffix _l)(expr _pl, _pr) =
    select_horn(_l); % set cur_horn_ to uhorn_ or ohorn_ according to _l
    path bot_line;
    pair L, R;
    bot_line := (.5w, vp(vn_bot(cur_horn_))) -- (w, vp(vn_bot(cur_horn_)));
    L := point xpart(bot_line intersectiontimes _pl) of bot_line;
    R := point xpart(bot_line intersectiontimes _pr) of bot_line;
    vn_set_ac_join(_l.horn_join, xpart .5[L, R], 0, 0);
enddef;

def lig_CGQ_table(expr k) =
    "C" kern k, "G" kern k, "Q" kern k
enddef;

def end_ligtable = 0 kern 0 enddef;

% define input_lig to generate only char oct"031" from excspl.mf
def input_lig suffix @# = 
    let save_endchar = endchar;
    let endchar = lig_endchar;
    scantokens("input " & str @#);
    relax;
    let endchar = save_endchar;
enddef;

def lig_endchar = 
    if charcode = oct"031":
        save_endchar
    else:
        endgroup
    fi
enddef;

def generate suffix @# = 
    scantokens("input null"); % can't figure out why it's needed
    scantokens("input vn" & substring(2, length(str @#)) of str @#);
enddef;

endinput;