% Routines for the METAFONT logo, as found in The METAFONTbook
% Extended to characters P and S for John Hobby's METAPOST
% (logo10.mf is a typical parameter file)

mode_setup;
if unknown slant: slant:=0 else: currenttransform:=
 identity slanted slant yscaled aspect_ratio fi;

ygap#:=(ht#/13.5u#)*xgap#;              % vertical adjustment
ho#:=o#;                                % horizontal overshoot
leftstemloc#:=2.5u#+s#;                 % position of left stem
barheight#:=.45ht#;                     % height of bar lines
py#:=.9px#;                             % vertical pen thickness

define_pixels(s,u);
define_whole_pixels(xgap);
define_whole_vertical_pixels(ygap);
define_blacker_pixels(px,py);
pickup pencircle xscaled px yscaled py;
logo_pen:=savepen;
define_good_x_pixels(leftstemloc);
define_good_y_pixels(barheight);
define_corrected_pixels(o);
define_horizontal_corrected_pixels(ho);

def beginlogochar(expr code, unit_width) =
 beginchar(code,unit_width*u#+2s#,ht#,0);
 pickup logo_pen enddef;

def super_half(suffix i,j,k) =
 draw z.i{0,y.j-y.i}
 ... (.8[x.j,x.i],.8[y.i,y.j]){z.j-z.i}
 ... z.j{x.k-x.i,0}
 ... (.8[x.j,x.k],.8[y.k,y.j]){z.k-z.j}
 ... z.k{0,y.k-y.j} enddef;

def super_crescent(suffix i,j,k) =
 draw z.i{x.j-x.i,0}
 ... (.8[x.i,x.j],.8[y.j,y.i]){z.j-z.i}
 ... z.j{0,y.k-y.i}
 ... (.8[x.k,x.j],.8[y.j,y.k]){z.k-z.j}
 ... z.k{x.k-x.j,0} enddef;

beginlogochar("M",18);
x1=x2=leftstemloc; x4=x5=w-x1; x3=w-x3;
y1=y5; y2=y4; bot y1=-o;
top y2=h+o; y3=y1+ygap;
draw z1--z2--z3--z4--z5;
labels(1,2,3,4,5); endchar;

beginlogochar("E",14);
x1=x2=x3=leftstemloc;
x4=x6=w-x1+ho; x5=x4-xgap;
y1=y6; y2=y5; y3=y4;
bot y1=0; top y3=h; y2=barheight;
draw z6--z1--z3--z4; draw z2--z5;
labels(1,2,3,4,5,6); endchar;

beginlogochar("T",13);
italcorr ht#*slant + .5u#;
if .5w<>good.x .5w: change_width; fi
lft x1=-eps; x2=w-x1; x3=x4=.5w;
y1=y2=y3; top y1=h; bot y4=-o;
draw z1--z2; draw z3--z4;
labels(1,2,3,4); endchar;

beginlogochar("A",15);
x1=.5w; x2=x4=leftstemloc; x3=x5=w-x2;
top y1=h+o; y2=y3=barheight;
bot y4=bot y5=-o;
draw z4--z2--z3--z5; super_half(2,1,3);
labels(1,2,3,4,5); endchar;

beginlogochar("F",14);
x1=x2=x3=leftstemloc;
x4=w-x1+ho; x5=x4-xgap;
y2=y5; y3=y4; bot y1=-o;
top y3=h; y2=barheight;
draw z1--z3--z4; draw z2--z5;
labels(1,2,3,4,5); endchar;

beginlogochar("P",14);
x1=x2=x3=leftstemloc;
x4=x5=.618[x1,w-x1];
y2=y5; y3=y4; bot y1=-o;
top y3=h; y2=barheight;
draw z1--z3--z4; draw z2--z5;
x6=.5[w-x1,lft w]; y6=.5[y4,y5];
super_crescent(4,6,5);
labels(1,2,3,4,5,6); endchar;

beginlogochar("S",14);
x3=x8=leftstemloc;
x1=w-x3;
x2=x4=.382[x3,x1];
x5=x7=.9[x3,x1];
x6=.5[x1,w];
top y1=h; y4=barheight; bot y8=0;
y1=y2; y3=.6[y2,y4]; y4=y5; y6=.3[y5,y7]; y7=y8;
draw z1--z2; draw z4--z5; draw z7--z8;
super_crescent(2,3,4);
super_crescent(5,6,7);
labels(1,2,3,4,5,6,7,8); endchar;

beginlogochar("O",15);
x1=x4=.5w; top y1=h+o; bot y4=-o;
x2=w-x3=good.x(1.5u+s); y2=y3=barheight;
super_half(2,1,3); super_half(2,4,3);
labels(1,2,3,4); endchar;

beginlogochar("N",15);
x1=x2=leftstemloc; x3=x4=x5=w-x1;
bot y1=bot y4=-o;
top y2=top y5=h+o; y3=y4+ygap;
draw z1--z2--z3; draw z4--z5;
labels(1,2,3,4,5); endchar;

ligtable "T": "A" kern -.5u#;
ligtable "F": "O" kern -u#;
ligtable "P": "O" kern u#;

font_quad:=18u#+2s#;
font_normal_space:=6u#+2s#;
font_normal_stretch:=3u#;
font_normal_shrink:=2u#;
font_identifier:="MFLOGO" if slant<>0: & "SL" fi;
font_coding_scheme:="AEFMNOPST only";
