% This file contains the ten digits in so-called old style.
% Character codes \0060 through \0071 are generated.

cmchar "Oldstyle numeral 0";
beginchar("0",9u#,x←height#,0);
italcorr .7x←height#*slant-max(.2u#,.95u#-.5curve#);
adjust←fit(0,0);
penpos1(vair,90); penpos3(vair,-90); penpos2(curve,180); penpos4(curve,0);
if not monospace: interim superness:=sqrt(more←super*hein←super); fi
x2r=hround max(.7u,1.45u-.5curve);
x4r=w-x2r; x1=x3=.5w; y1r=h+o; y3r=-o;
y2=y4=.5h-vair←corr; y2l:=y4l:=.52h;
penstroke pulled←arc.e(1,2) & pulled←arc.e(2,3)
 & pulled←arc.e(3,4) & pulled←arc.e(4,1) & cycle;  % bowl
penlabels(1,2,3,4); endchar;

cmchar "Oldstyle numeral 1";
beginchar("1",9u#,x←height#,0);
italcorr x←height#*slant+.5cap←stem#-4.25u#;
adjust←fit(0,0);
numeric light←stem; light←stem=hround .4[stem',cap←stem'];
pickup tiny.nib;
pos1(light←stem,0); pos2(light←stem,0);
lft x1l=lft x2l=hround(.5(w+.5u)-.5cap←stem'); top y1=h+apex←o; bot y2=0;
filldraw stroke z1e--z2e;  % stem
if not serifs: save slab; slab=bar; fi
dish←serif(2,1,a,1/3,min(2.25u,lft x2l-1.5u),
  b,1/3,min(2.25u,w-1.25u-rt x2r)); % serif
pickup crisp.nib; pos3(slab,-90); pos4(bar,-90);
top y3l=h+apex←o; top y4l=if monospace: .8 else: .9 fi\\ h+apex←o;
lft x4=max(1.25u,tiny.lft x1l-2.35u);
tiny.rt x1r=lft x3+.25[tiny,hair];
erase fill z3l{x4l-x3l,3(y4l-y3l)}...z4l{left}
 --(x4l,h+apex←o+1)--(x3l,h+apex←o+1)--cycle; % erase excess at top
filldraw stroke z3e{x4e-x3e,3(y4e-y3e)}..z4e{left};  % point
penlabels(1,2,3,4); endchar;

cmchar "Oldstyle numeral 2";
beginchar("2",9u#,x←height#,0);
italcorr .8x←height#*slant-.4u#;
adjust←fit(0,0);
numeric arm←thickness, hair←vair; hair←vair=.25[vair,hair];
arm←thickness=Vround(if hefty:slab+2stem←corr else:.75[vair,cap←stem] fi);
pickup crisp.nib; pos7(arm←thickness,-90); pos8(hair,0);
bot y7r=0; lft x7=hround .8u; rt x8r=hround(w-.9u); y8=good.y(y7l+beak/3)+eps;
arm(7,8,a,.3beak←darkness,beak←jut);  % arm and beak
pickup fine.nib; pos2(slab,90); pos3(.4[curve,cap←curve],0);
top y2r=h+o; x2=.5(w-.5u); rt x3r=hround(w-.9u); y3+.5vair=.75h;
if serifs: numeric bulb←diam; bulb←diam=hround .8[hair,flare];
 pos0(bulb←diam,180); pos1(cap←hair,180);
 lft x1r=hround u; y1-.5bulb←diam=2/3h;
 (x,y2l)=whatever[z1l,z2r]; x2l:=x; bulb(2,1,0);  % bulb and arc
else: x2l:=x2l-.25u; pos1(flare,angle(-9u,h));
 lft x1r=hround .75u; bot y1l=vround .7h; y1r:=good.y y1r; x1l:=good.x x1l;
 filldraw stroke term.e(2,1,left,.9,4); fi  % terminal and arc
pos4(.25[hair←vair,cap←stem],0);
pos5(hair←vair,0); pos6(hair←vair,0);
y5=arm←thickness; y4=.3[y5,y3]; top y6=min(y5,slab,top y7l);
lft x6l=crisp.lft x7; z4l=whatever[z6l,(x3l,bot .58h)]; z5l=whatever[z6l,z4l];
erase fill z4l--z6l--lft z6l--(lft x6l,y4l)--cycle;  % erase excess at left
filldraw stroke z2e{right}..tension atleast .9 and atleast 1
 ..z3e{down}.. z4e---z5e--z6e;  % stroke
penlabels(0,1,2,3,4,5,6,7,8); endchar;

cmchar "Oldstyle numeral 3";
beginchar("3",9u#,x←height#,desc←depth#);
italcorr .8x←height#*slant-.4u#;
adjust←fit(0,0);
numeric top←thickness,mid←thickness,bot←thickness;
top←thickness=max(fine.breadth,vround(slab-2vair←corr));
mid←thickness=max(fine.breadth,vround 2/3vair);
bot←thickness=max(fine.breadth,vround(slab-vair←corr));
pickup fine.nib; pos2(top←thickness,90); top y2r=h+o;
pos3(max(fine.breadth,.6[curve,cap←curve]-stem←corr),0);
rt x3r=hround(w-1.25u);
pos4(vair,-90); pos5(vair,-90);
pos6(mid←thickness,90); x2=x6=x8=.5[1.5u,x7];
pos7(cap←curve,0); rt x7r=hround(w-.75u); lft x5=min(hround 3u,lft x6);
pos8(bot←thickness,-90); bot y8r=-d-o;
y3=.6[top y4l,bot y2l]; y7=.5[bot y6l,top y8l];
top y5l=vround(.54[-d,h]+.5vair); y5r=y6l;
x4=1/3[x5,x3l]; z4=z5+whatever*(150u,h+d);
filldraw stroke pulled←super←arc.e(2,3)(.5superpull)
 & z3e{down}...z4e---z5e;  % upper bowl
filldraw z5r--z6l--z6r--z5l---cycle;  % middle tip
filldraw stroke pulled←super←arc.e(6,7)(.5superpull)
 & pulled←super←arc.e(7,8)(.5superpull);  % lower bowl
if serifs: numeric bulb←diam[];
 bulb←diam1=flare+.5(cap←stem-stem); bulb←diam2=flare+cap←stem-stem;
 pos0(bulb←diam1,180); pos1(hair,180);
 lft x0r=hround 1.25u; y0=min(.9[-d,h]-.5bulb←diam1,.75[-d,h]+.5bulb←diam1);
 bulb(2,1,0);  % upper bulb
 pos10(bulb←diam2,-180); pos9(cap←hair,-180);
 lft x10r=hround .75u; y10=max(.1[-d,h]+.5bulb←diam2,.3[-d,h]-.5bulb←diam2);
 bulb(8,9,10);  % lower bulb
else: pos1(.5[vair,flare],angle(-8u,h+d)); lft x1r=hround u;
 bot y1l=(vround .75[-d,h])+o; y1r:=good.y y1r+eps; x1l:=good.x x1l;
 pos9(bot←thickness,angle(-2u,-h-d));
 lft x9r=hround .75u; top y9l=(vround .25[-d,h])-o;
 y9r:=good.y y9r-eps; x9l:=good.x x9l;
 filldraw stroke term.e(2,1,left,1,4);  % upper terminal
 filldraw stroke term.e(8,9,left,1,4); fi  % lower terminal
penlabels(0,1,2,3,4,5,6,7,8,9,10); endchar;

cmchar "Oldstyle numeral 4";
beginchar("4",9u#,x←height#,desc←depth#);
italcorr x←height#*slant+.5stem#-2.5u#;
adjust←fit(0,0);
numeric light←stem, light←stem', diag←stem, alpha, cut; cut=.75notch←cut;
light←stem=hround .4[fudged.stem,fudged.cap←stem];
light←stem'=hround max(tiny.breadth,light←stem-2stem←corr);
diag←stem=max(tiny.breadth,.4[vair,fudged.hair]);
pickup crisp.nib; pos5(cap←bar,90); pos6(cap←bar,90);
lft x5=hround .5u; rt x6=hround(w-.5u); bot y5l=0;
z4l=top lft z5r; y2=y2'=y5=y6; x1r=x2r=hround(w-3u+.5light←stem);
penpos1(light←stem',0); penpos2(light←stem',0); y1=y3=h+apex←o+apex←oo;
x3r+apex←corr=x1r; alpha=diag←ratio(1,diag←stem,y3-y4l,x3r-x4l);
penpos3(alpha*diag←stem,0); penpos4(alpha*diag←stem,0);
x0=x1l; z0=whatever[z3r,z4r];
x5'=x5; z5''=z5'+penoffset z4-z3 of currentpen=whatever[z4l,z3l];
fill diag←end(2r,1r,1,.5,3l,4l)---z5''...lft z5'
 ---lft z5l -- (x4r,y5l) -- z4r
 if y0<h-cut:{z3r-z4r}...{up}(x1l-1,h-cut)
  --(x1l,h-cut) else: -- z0 fi
 --z2l--z2r--cycle;  % diagonal and upper stem
filldraw stroke z5e--z6e;  % bar
pickup tiny.nib; pos7(light←stem,0); pos2'(light←stem,0); x2'=x7;
rt x7r=x1r; bot y7=-d if not serifs:-o fi;
filldraw stroke z2'e--z7e;  % lower stem
if serifs: dish←serif(7,2',a,1/3,1.75u,
  b,1/3,min(1.75u,w-.5u-rt x7r)); fi  % serif
penlabels(0,1,2,3,4,5,6,7); endchar;

cmchar "Oldstyle numeral 5";
beginchar("5",9u#,x←height#,desc←depth#);
italcorr x←height#*slant-u#;
adjust←fit(0,0);
numeric bot←thickness,light←hair;
bot←thickness=max(fine.breadth,vround(slab-vair←corr));
light←hair=hround(cap←hair if hefty: -2stem←corr fi);
pickup tiny.nib; pos5(vair,180); pos6(vair,90);
bot y5=vround(.53[-d,h]-vair); top y6r=(vround .61803[-d,h])+o;
pos3(light←hair,0); pos4(light←hair,0);
lft x3l=max(1.35u,2.1u-.5light←hair); x3=x4=x5; y4=y5;
top y3=h if not hefty: +o fi;
filldraw stroke z3e--z4e;  % thin stem
penpos7(cap←stem-fine,0); penpos8(bot←thickness-fine,-90);
fine.rt x7r=hround(w-.9u); x8=.5[u,x7]; x6=.5[x5,x7];
erase fill z5--bot z5--(x6,bot y5)--z6{left}
 ..tension .9 and 1..{x5-x6,3(y5-y6)}cycle; % erase excess in middle
filldraw stroke z6e{left}..tension .9 and 1..{x5-x6,3(y5-y6)}z5e;  % link
pickup fine.nib; pos6'(vair,90); z6'=z6;
y7=.5[y6,y8]; bot y8r=-d-o;
filldraw stroke pulled←arc.e(6',7) & pulled←arc.e(7,8);  % bowl
if serifs: pos9(hair,-180); y9=.5[-d,y5]; lft x9r=hround .9u;
 pos10(flare+1/3(cap←stem-stem),-180); bulb(8,9,10);  % bulb
else: pos9(3/7[bot←thickness,flare],angle(-7u,-h-d));
 lft x9r=hround .9u; bot y9r=(vround .15[-d,h])-o;
 x9l:=good.x x9l; y9l:=good.y y9l;
 filldraw stroke term.e(8,9,left,1,4); fi  % terminal
if hefty: pickup crisp.nib; pos1(slab,90); pos2(hair,0);
 top y1r=h; x1=x4; rt x2r=hround(w-1.5u);
 y2=y1l-eps; arm(1,2,a,0,0);  % arm
else: numeric flag←breadth; flag←breadth=7/8[vair,cap←curve];
 pos1(flag←breadth,90); pos2(flag←breadth,60);
 pos0(vair,90); top y1r=tiny.top y3; top y2r=(vround .95[-d,h])+o; y0r=y1r;
 lft x1=tiny.lft x3l; x2r=.5[x1,x0]; rt x0=hround(w-1.6u);
 erase fill top z1r--z1r...{right}z2r
  --(x2r,top y1r)--cycle; % erase excess at top
 filldraw stroke z1e...{right}z2e...z0e; fi  % flag
penlabels(0,1,2,3,4,5,6,7,8,9,10); endchar;

cmchar "Oldstyle numeral 6";
beginchar("6",9u#,fig←height#,0);
italcorr fig←height#*slant-u#;
adjust←fit(0,0);
numeric top←thickness,bot←thickness,side←thickness,pull;
top←thickness=max(fine.breadth,vround(slab-2vair←corr));
bot←thickness=max(fine.breadth,vround(slab-vair←corr));
side←thickness=max(fine.breadth,hround 1/3[curve,cap←curve]);
pull=min(.25,1.5superpull);
pickup fine.nib; pos2(top←thickness,-270);
pos3(side←thickness,-180); pos4(bot←thickness,-90);
pos5(side←thickness,0); pos6(vair,90);
lft x3r=w-rt x5r=hround max(.75u,1.5u-.5side←thickness);
x4=x6-.1u=x2-u=.5w;
top y2r=h+o; y3=.5[y2,y4]; bot y4r=-o;
y5=.5[y4,y6]; top y6=vround 5/8h+o;
path p; p=pulled←super←arc.l(3,4)(pull);
numeric t; t=xpart(p intersectiontimes((x3r,y5)--(x4,y5)));
pos7(thin←join,180); z7l=point t of p;
(x,y6r)=whatever[z7l,z6l]; x6r:=min(x,.5[x5r,x6]);
filldraw stroke pulled←super←arc.e(2,3)(pull)
 & {{interim superness:=more←super; pulled←super←arc.e(3,4)(pull)}}
 & {{less←tense; pulled←super←arc.e(4,5)(pull) & pulled←super←arc.e(5,6)(pull)}}
 & z6e{left}...{direction t of p}z7e;  % arc and bowl
if serifs: pos1(hair,-360); pos0(flare,-360);
 rt x0r=max(rt x2+eps,hround(w-1.2u));
 y0=vround min(.9h-.5flare,.85h+.5flare)+o;
 {{less←tense; bulb(2,1,0)}};  % arc and bulb
else: pos1(vround .1[top←thickness,flare],90);
 top y1r=vround .97h+o; rt x1=hround(x5-.5);
 filldraw stroke term.e(2,1,right,.9,4); fi  % terminal
penlabels(0,1,2,3,4,5,6,7); endchar;

cmchar "Oldstyle numeral 7";
beginchar("7",9u#,x←height#,desc←depth#);
italcorr x←height#*slant;
adjust←fit(0,0);
numeric arm←thickness, bot←width, top←shift, top←hair;
if hefty: arm←thickness=Vround(slab+2stem←corr); top←shift=0;
 bot←width=hround .51[curve,cap←curve]; top←hair=.4[thin←join,bot←width];
else: arm←thickness=Vround .4[stem,cap←stem]; top←shift=.5u;
 bot←width=flare; top←hair=cap←hair; fi
if top←hair<tiny.breadth: top←hair:=tiny.breadth; fi
pickup crisp.nib; pos2(arm←thickness,90); pos1(hair,180);
top y2r=h; rt x2=hround(w-.75u+top←shift);
lft x1r=hround(.75u+.5top←shift); y1=good.y(y2l-beak/2)-eps;
arm(2,1,a,.3beak←darkness,-beak←jut);  % arm and beak
pos3(hair,180); y3=good.y(y2r+beak/6)+eps; z3r=whatever[z1r,z.a0];
penpos2'(2epsilon,-90); z2'=z2r;
arm(2',3,b,beak←darkness,x3r-x.a0);  % upward extension of beak
pickup tiny.nib; pos4(top←hair,0); pos6(bot←width,0);
bot y4=max(h-arm←thickness,h-slab,bot y2l); rt x4r=crisp.rt x2;
lft x6l=hround(3.5u+top←shift-.5bot←width);
if serifs: y6-.5bot←width=-d-o; filldraw z6l{down}..{up}z6r--cycle;  % bulb
else: bot y6=-d-oo; fi
if hefty: erase fill rt z4r--z4r...{down}z6r
  --(rt x4r,y6)--cycle;  % erase excess at top
 filldraw stroke z4e...{down}z6e;  % stroke
else: pos5(top←hair,0); y5=2/3[-d,h]; z5=whatever[z4,(.75u,y6)];
 erase fill rt z4r--z4r--z5r--(rt x4r,y5)--cycle;  % erase excess at top
 filldraw stroke z4e---z5e...{down}z6e; fi  % stroke
penlabels(1,2,3,4,5,6); endchar;

cmchar "Oldstyle numeral 8";
beginchar("8",9u#,fig←height#,0);
italcorr fig←height#*slant-u#;
adjust←fit(0,0);
numeric top←thickness,mid←thickness,bot←thickness,upper←side,lower←side,theta;
top←thickness=max(fine.breadth,vround(slab-2vair←corr));
bot←thickness=max(fine.breadth,vround(slab-vair←corr));
x0=.5w; y0=.54h;
if hefty: mid←thickness=vround 2/3vair; upper←side=hround(stem-3stem←corr);
 lower←side=hround min(.5[curve,cap←curve]-stem←corr,upper←side+.25u);
 penpos1(top←thickness,90); penpos2(upper←side,180);
 penpos3(mid←thickness,270); penpos8(upper←side,360);
 penpos4(mid←thickness,90); penpos7(lower←side,180);
 penpos6(bot←thickness,270); penpos5(lower←side,360);
 penpos0(vair,90); z3l=z0r; z4l=z0l;
 x1=x6=.5w; x2r=w-x8r=hround u; x7r=w-x5r=hround .75u;
 top y1r=h+o; bot y6r=-o; y2=y8=.5[y1l,y3l]; y7=y5=.5[y4l,y6l];
 filldraw stroke pulled←arc.e(1,2)
  & pulled←arc.e(2,3);  % left half of upper bowl
 filldraw stroke pulled←arc.e(4,5)
  & pulled←arc.e(5,6);  % right half of lower bowl
 filldraw stroke pulled←arc.e(6,7)
  & pulled←arc.e(7,4);  % left half of lower bowl
 filldraw stroke pulled←arc.e(3,8)
  & pulled←arc.e(8,1);  % right half of upper bowl
else: pickup fine.nib; theta=90-angle(18u,h); slope:=-h/18u;
 upper←side=max(fine.breadth,hround(.5[hair,stem]-stem←corr));
 lower←side=hround(.5[hair,stem]+stem←corr);
 pos1(top←thickness,-90); pos6(bot←thickness,-90);
 x1=x6=.5w; top y1l=h+o; bot y6r=-o; pos0(cap←stem,theta);
 lft x2l=w-rt x8l=hround 1.25u; lft x7r=w-rt x5r=hround .75u;
 x2r-x2l=upper←side-fine; x5r-x5l=lower←side-fine;
 ellipse←set(1l,2l,3l,0l); ellipse←set(1r,2r,3r,0r);
 ellipse←set(6l,5l,4l,0l); ellipse←set(6r,5r,4r,0r);
 numeric tau; tau=max(.8,.20710678/(superness-.5));
 filldraw stroke z1e{left}..tension atleast tau..z2e{down}
  ..z3e---z4e..z5e{down}..tension atleast tau..z6e{left};  % S stroke
 pos7(lower←side,180); pos8(upper←side,180);
 y7=.5[y5l,y5r]; y8=.5[y2l,y2r]; pos9(vair,90); z9=z0;
 filldraw stroke z1e{right}..tension atleast tau..z8e{down}
  ..tension atleast tau and atleast 1..{-18u,-.618h}z9e; % upper right stroke
 filldraw stroke z6e{left}..tension atleast tau..z7e{up}
  ..tension atleast tau and atleast 1..{18u,.5h}z9e; fi % lower left stroke
penlabels(0,1,2,3,4,5,6,7,8,9); endchar;

cmchar "Oldstyle numeral 9";
beginchar("9",9u#,x←height#,desc←depth#);
italcorr x←height#*slant-u#;
adjust←fit(0,0);
numeric top←thickness,bot←thickness,side←thickness,pull;
top←thickness=max(fine.breadth,vround(slab-2vair←corr));
bot←thickness=max(fine.breadth,vround(slab-vair←corr));
side←thickness=max(fine.breadth,hround 1/3[curve,cap←curve]);
pull=min(.25,1.5superpull);
pickup fine.nib; pos2(bot←thickness,-90);
pos3(side←thickness,0); pos4(top←thickness,90);
pos5(side←thickness,180); pos6(vair,270);
w-rt x3r=lft x5r=hround max(.75u,1.5u-.5side←thickness);
x4-.1u=x6+.1u=x2+.75u=.5w;
bot y2r=-d-o; y3=.5[y2,y4]; top y4r=h+o;
y5=.5[y4,y6]; bot y6=(vround 3/8[-d,h])-o;
path p; p=pulled←super←arc.l(3,4)(pull);
numeric t; t=xpart(p intersectiontimes((x3r,y5)--(x4,y5)));
pos7(thin←join,360); z7l=point t of p;
(x,y6r)=whatever[z7l,z6l]; x6r:=max(x,.5[x5r,x6]);
filldraw stroke pulled←super←arc.e(2,3)(pull)
 & {{interim superness:=more←super; pulled←super←arc.e(3,4)(pull)}}
 & {{less←tense; pulled←super←arc.e(4,5)(pull) & pulled←super←arc.e(5,6)(pull)}}
 & z6e{right}...{direction t of p}z7e;  % arc and bowl
if serifs: pos1(hair,-180); pos0(flare,-180);
 lft x0r=min(lft x2-eps,hround 1.2u);
 y0=vround max(.1[-d,h]+.5flare,.15[-d,h]-.5flare)-o;
 {{less←tense; bulb(2,1,0)}};  % arc and bulb
else: pos1(.1[bot←thickness,flare],-120);
 bot y1r=(vround .07[-d,h])-o; lft x1r=hround 1.3u;
 filldraw stroke term.e(2,1,left,.9,4); fi  % terminal
penlabels(0,1,2,3,4,5,6,7); endchar;