cmchar "The cyrillic letter a";
beginchar(CYR_a,9u#,x_height#,0);
bh#:=min(bar_height#,1.14x_height#-bar_height#); define_pixels(bh);
italcorr 1/3[bh#,x_height#]*slant+.5stem#-serif_fit#-2u#;
adjust_fit(0,serif_fit# if serifs: if hair#+.5stem#>1.5u#:-.25u# fi\\fi);
pickup fine.nib; top y3r=h+vround 1.5oo;
if serifs: pos1(flare,180); pos2(hair,180);
 pos3(vair,90);  lft x1r=hround max(u,2.1u-.5flare); x3=.5w-.5u;
 y1=min(bh+.5flare+2vair+2,.9[bh,h]-.5flare);
 bulb(3,2,1);  % bulb
else: pos1(5/7[vair,flare],95); x1l=good.x 1.5u; x1r:=good.x x1r;
 pos3(1/8[vair,thin_join],90);
 x3=.5w-.2u; top y1r=vround .82[bh,top y3r];
 filldraw stroke term.e(3,1,left,.9,4); fi  % terminal
pos4(stem,0); rt x4r=hround(w-2.5u+.5stem); y4=1/3[bh,h];
pos5(stem,0); x5=x4; y5=max(.55bh,2vair);
filldraw stroke super_arc.e(3,4)&z4e..z5e;  % arc and stem
pos6(.3[thin_join,vair],90); x6=x4; bot y6=bh;
pos7(hround(curve-2stem_corr),180);
lft x7r=hround max(.5u,1.5u-.5curve); y7=1/3[top y8l,top y6r];
pos8(vair,270); x8l=.5w-.75u; bot y8r=-oo;
pos9(thin_join,360); z9l=z5l;
(x,y8r)=whatever[z8l,z9l]; x8r:=max(x,x8-u);
{{interim superness:=more_super;
 filldraw stroke z9e{down}...z8e{left}...{up}z7e&super_arc.e(7,6)}}; % bowl
if serifs: numeric shaved_stem; shaved_stem=hround(stem-3stem_corr);
 if hair#+.5stem#>1.5u#: pickup tiny.nib;
  pos5'(shaved_stem,0); rt x5'r=fine.rt x5r; y5'=y5;
  pos10(shaved_stem,0); x10=x5'; y10=.2[.5tiny,bh];
  pos11(shaved_stem,0); rt x11r=hround(w-.25u); bot y11=0;
  pos12(shaved_stem,0); x11=x12; top y12=slab+eps;
  filldraw z5'l---z10l...z11l{right}--z11r
   --z12r{left}...z10r+.75(z12-z11)---z5'r--cycle;  % foot
 else: pickup crisp.nib; pos5'(shaved_stem,0); rt x5'r=fine.rt x5r; y5'=y5;
  pos10(shaved_stem,0); x10=x5'; y10=1/3bh;
  pos11(.2[vair,stem],90); x11r=.5[x10r,x12r]; bot y11l=-vround .5oo;
  pos12(hair,180); rt x12l=hround(w-.1u); y12=max(y10,y11+vair);
  pos13(hair,180); x13=x12; top y13=max(vround .6bh,top y12);
  (x',y11l)=whatever[z11r,z12r]; x11l:=max(x',x10);
  filldraw stroke z5'e---z10e...z11e{right}...z12e---z13e; fi  % hook
else: numeric shaved_stem; shaved_stem=hround(stem-stem_corr);
 pickup tiny.nib; pos5'(shaved_stem,0); rt x5'r=fine.rt x5r; y5'=y5;
 pos10(shaved_stem,0); x10=x5'; bot y10=0;
 filldraw stroke z5'e--z10e; fi  % base of stem
penlabels(1,2,3,4,5,6,7,8,9,10,11,12,13); endchar;

cmchar "The cyrillic letter be";
beginchar(CYR_be,9u#,fig_height#,0);
italcorr .7x_height#*slant;
adjust_fit(if monospace: .5u#,.5u# else: 0,0 fi);
penpos1(vair,90); penpos3(vair',-90);
penpos2(curve,180); penpos4(curve,0);
x2r=hround max(.5u,1.25u-.5curve);
x4r=w-x2r; x1=x3=.5w; y1r=x_height+vround 1.5oo; y3r=-oo;
y2=y4=.5x_height-vair_corr; y2l:=y4l:=.52x_height;
penstroke pulled_arc.e(1,2) & pulled_arc.e(2,3)
 & pulled_arc.e(3,4) & pulled_arc.e(4,1) & cycle;  % bowl
penpos2'(vair,180); lft x2'r=x2r; y2'=y2r;
penpos5(.8curve,90); penpos6(.8curve,90); 
penpos6'(.8curve,-90); x6=.5[x5,x7]; y6=y5; z6'=z6;
penpos7(thin_join,0); rt x7r=rt x4r;
top y7=h; top y5r=.97h; x5=x1;
fill stroke z2'e{up}...{right}z5e..z6e;
fill circ_stroke pulled_arc.e(7,6');
penlabels(1,2,2',3,4,5,6',6,7); endchar;

cmchar "The cyrillic letter ve";
beginchar(CYR_ve,9u#,x_height#,0);
italcorr .5x_height#*slant+min(.5curve#-u#,-.25u#);
adjust_fit(serif_fit#,0);
numeric left_stem,right_curve,middle_weight;
left_stem=stem-hround 2stem_corr; middle_weight=.75vair;
pickup tiny.nib; pos1(left_stem,0); pos2(left_stem,0);
lft x1l=lft x2l=hround(2.5u-.5left_stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
penpos3(.75vair,90); penpos4(.75vair,90);
penpos6(middle_weight,-90); penpos7(middle_weight,-90);
penpos8(middle_weight,90); penpos9(middle_weight,90);
penpos5(right_curve-stem_corr,0); penpos10(right_curve,0);
penpos11(.75vair,-90); penpos12(.75vair,-90);
z3r=top z1; y4=y3; y5=.5[y4,y6]; y6=y7; y7l-y8l=vair;
z12r=bot z2; bot y11=bot y12; y10=.5[y11,y9]; y8=y9; .5[y7l,y8l]=.52h;
x4=x6; x9=x11=x4+.5u; x7=x8=x1; x9l:=x4+.25u;
x5r=hround(w-u); x10r=hround(w-.5u);
if serifs: right_curve=curve-stem_corr; x4=.5[x1,w-1.5u];
else: right_curve=curve-3stem_corr; x4=.5[x1,w-2.5u];
 x4l:=x4l-.5u; x9l:=x9l-.5u; fi
x6l:=x6l-.5u; x11l:=x11l-.5u;
fill stroke z3e..super_arc.e(4,5) & super_arc.e(5,6)..z7e;  % upper lobe
fill stroke z8e..super_arc.e(9,10) & super_arc.e(10,11)..z12e;  % lower lobe
if serifs: nodish_serif(1,2,a,1/3,jut,b,1/3,.5jut);  % upper serif
 nodish_serif(2,1,c,1/3,jut,d,1/3,.5jut); fi  % lower serif
penlabels(1,2,3,4,5,6,7,8,9,10,11,12); endchar;

cmchar "The cyrillic letter ghe";
beginchar(CYR_ghe,8.5u#,x_height#,0);
italcorr x_height#*slant;
adjust_fit(serif_fit#,0);
h:=vround(h-stem_corr);
pickup tiny.nib; pos1(stem,0); pos2(stem,0);
lft x1l=lft x2l=hround(2.5u-.5stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
pickup crisp.nib; pos3(slab,90); pos4(hair,0);
top y3r=h; x3=x1; rt x4r=hround(w-.75u); y4=good.y(y3l-.6beak)-eps;
arm(3,4,e,beak_darkness,beak_jut);  % upper arm and beak
nodish_serif(1,2,a,1/3,jut,b,1/3,.5jut);  % upper serif
dish_serif(2,1,c,1/3,jut,d,1/3,1.25jut);  % lower serif
penlabels(1,2,3,4); endchar;

def ellipse_set(suffix $,@,@@,$$) = % given |z$,x@,z$$|, find |y@| and |z@@|
% such that the path |z${x@-x$,0}..z@{0,y@-y$}..{z$$-z@@}z@@|
% is consistent with an ellipse
% and such that the line |z@@--z$$| has a given |slope|
 alpha_:=slope*(x$-x@); beta_:=y$$-y$-slope*(x$-x$$);
 gamma_:=alpha_/beta_;
 y@-y$=.5(beta_-alpha_*gamma_);
 x$-x@@=-2gamma_*(x$-x@)/(1+gamma_*gamma_);
 y@@-y$$=slope*(x$$-x@@) enddef;

cmchar "The cyrillic letter ghe";
beginchar(CYR_ghe,7.1u#,x_height#,0);
italcorr x_height#*slant-.3u#;
adjust_fit(if monospace: .5u#,.4u# else: 0,-.2u# fi);
numeric theta; theta=90+angle(40u,h); slope:=-h/40u;  % angle at middle
numeric s_slab; s_slab=if serifs:vair else:Vround .1[vair,stem] fi;
numeric ess'; ess'=max(fine.breadth,ess);
pickup fine.nib; pos2(max(fine.breadth,s_slab-vround vair_corr),-80);
pos0(ess',theta); pos7(s_slab,-90); x2l=x0=x7=.5w;
top y2l=h+vround 1.5oo; bot y7r=-oo;
y0-.5ess'=y7l+.52(y2r-y7l-ess');
rt x3l=hround(w-.6u); lft x6r=hround .6u;
x3l-x3r=x6l-x6r=hround .5[s_slab,ess']-fine;
ellipse_set(2l,3l,4l,0l); ellipse_set(2r,3r,4r,0r); y3=y3r;
ellipse_set(7l,6l,5l,0l); ellipse_set(7r,6r,5r,0r); y6=y6r;
interim superness:=more_super;
filldraw stroke super_arc.e(2,3) & z3e{down}
 ..z4e---z5e..z6e{down} & super_arc.e(6,7);  % main stroke
pos1(4/7[s_slab,flare],-80); pos8(flare,-80);
x1l=good.x(x1l+u-lft x1); rt x8r=hround(w-.5u);
top y1l=vround(.93h+1.5oo); bot y8r=vround .1h-oo;
filldraw stroke term.e(2,1,left,.9,4);  % upper arc and terminal
filldraw stroke term.e(7,8,right,1,4);  % lower arc and terminal
penlabels(0,1,1',2,3,4,5,6,7,8,8',9,10); endchar;

cmchar "The cyrillic letter de";
beginchar(CYR_de,10u#+serif_fit#,x_height#,desc_depth#);
italcorr x_height#*slant-serif_fit#+.5stem#-2u# if serifs:+.5u# fi;
adjust_fit(0,serif_fit# if serifs: -.5u# fi);
pickup tiny.nib; pos1(stem',0); pos2(stem,0);
pos0'(stem',0); pos0(stem,0); z0r=z0'r; x0'=x1; x0=x2;
rt x1r=hround(w-2.5u+.5stem');
numeric edge; edge=lft x2l;
path edge_path; edge_path=(edge,h)--(edge,0);
pickup fine.nib; pos3(if hefty:thin_join else: hair fi,0);
pos4(vair,90); pos5(curve,180); pos6(vair,270); penpos7(x3r-x3l,360);
lft x3l=min(lft x3l-(rt x3r-tiny.rt x2r),2/3[lft x2,edge]); y3=bar_height;
x4l=.5(w-serif_fit)-.3u; top y4r=x_height+oo;
lft x5r=hround max(1.35u-.5curve,.6u); y5=.5x_height;
x6l=x4l-.2u; bot y6r=vround 1/3vair;
lft x7l=edge; y7=min(y3,y6+y4-y3+.6vair);
(x,y4r)=whatever[z3l,z4l]; x4r:=max(x,.5[x5r,x4]);
(x',y6r)=whatever[z7l,z6l]; x6r:=max(x',.5[x5r,x6]);
filldraw stroke z3e{up}...{left}z4e&super_arc.e(4,5)
 &super_arc.e(5,6)&z6e{right}...{up}z7e;  % bowl
y1=ypart(edge_path intersectionpoint(z3l{up}...{left}z4l));
y0=ypart(edge_path intersectionpoint(z7l{down}...{left}z6l));
pickup tiny.nib; bot y2=if serifs: -.25d else: 0 fi;
filldraw stroke z1e--z0'e--z0e--z2e;  % stem
pickup crisp.nib;
pos8(hround(hair-stem_corr),0); pos7'(stem',0);
z7'=z1; x8r=x7'r; top y8=h+oo;
filldraw stroke z7'e--z8e;  % point
if serifs: pickup tiny.nib;
 pos9(vair,-90); x9=.5[x2,x10]; bot y9r=-d-o-1;
 pos10(hair,-180); lft x10r=hround u; y10=-.75d+.5flare;
 pos11(flare,-180); z11r=z10r;
 bulb(9,10,11); filldraw stroke super_arc.e(2,9);  % tail
else: pickup fine.nib; pos2'(stem,0); z2'=z2;
 z2''r=z2'r; z2''=z2'; z2''l=(x2'l,0);
 pos9(vair,-90); x9=4.5u; bot y9r=-d-o-1;
 pos10(.5[vair,flare],-90); lft x10=hround 1.25u;
 y10r=good.y -5/6d; y10l:=good.y y10l;
 filldraw stroke z2'e..z2''e&super_arc.e(2'',9)
  & term.e(9,10,left,.9,4); fi  % tail
penlabels(0,1,2,3,4,5,6,7,8,9,10,11); endchar;

cmchar "The cyrillic letter ie";
beginchar(CYR_ie,7.25u#+max(.75u#,.5curve#),x_height#,0);
italcorr .5[bar_height#,x_height#]*slant+.5min(curve#-1.5u#,0);
adjust_fit(if monospace: .25u#,.5u# else: 0,0 fi);
numeric left_curve,right_curve;
left_curve=right_curve+6stem_corr=curve if not serifs: -3stem_corr fi;
if right_curve<tiny.breadth: right_curve:=tiny.breadth; fi
if left_curve<tiny.breadth: left_curve:=tiny.breadth; fi
pickup tiny.nib; pos1(right_curve,0);
pos2(vair,90); pos3(left_curve,180);
y1=good.y bar_height; top y2r=h+vround 1.5oo; y0l=bot y1;
rt x1r=hround min(w-.5u,w-u+.5right_curve);
lft x3r=hround max(.5u,1.25u-.5left_curve); x2=.5w+.25u;
{{interim superness:=more_super;
 filldraw stroke super_arc.e(1,2)}};  % right bowl
y3=.5[y2,y4]; bot y4r=-oo; x4=x2+.25u;
if serifs: pos4(vair',270); pos5(hair,360);
 y5=max(good.y(.5bar_height-.9),y4l+vair); x5r=x1r;
 (x,y4l)=whatever[z4r,z5]; x4l:=min(x,x4l+.5u);
 filldraw stroke pulled_arc.e(2,3) & pulled_arc.e(3,4)
  ...{x5-x4,5(y5-y4)}z5e; % left bowl, arc, and terminal
else: pos4(vair,270);
 filldraw stroke super_arc.e(2,3) & super_arc.e(3,4);  % left bowl and arc
 pickup fine.nib; pos4'(vair,270); z4=z4';
 pos5(.5[vair,flare],275); rt x5r=hround(w-.6u);
 y5r=good.y(y5r+1/3bar_height-y5); y5l:=good.y y5l; x5l:=good.x x5l;
 filldraw stroke term.e(4',5,right,1,4); fi  % terminal
path testpath; testpath=super_arc.r(2,3) & super_arc.r(3,4);
y1'r=y0r=y0l+.6[thin_join,vair]; y1'l=y0l; x1'l=x1'r=x1;
forsuffixes $=l,r:
 x0$=xpart(((0,y0$)--(x1,y0$)) intersectionpoint testpath); endfor
fill stroke z0e--z1'e;  % crossbar
penlabels(0,1,2,3,4,5); endchar;

cmchar "The cyrillic letter ye";
numeric dot_diam#,dot_diam;
dot_diam#=max(dot_size#,cap_curve#);
beginchar(CYR_ye,7.25u#+max(.75u#,.5curve#),1.4x_height#,0);
dot_diam=max(tiny.breadth,hround(max(dot_size,cap_curve)-2stem_corr));
italcorr .5[bar_height#,x_height#]*slant+.5min(curve#-1.5u#,0);
adjust_fit(if monospace: .25u#,.5u# else: 0,0 fi);
numeric left_curve,right_curve,letter_h; letter_h=x_height;
left_curve=right_curve+6stem_corr=curve if not serifs: -3stem_corr fi;
if right_curve<tiny.breadth: right_curve:=tiny.breadth; fi
if left_curve<tiny.breadth: left_curve:=tiny.breadth; fi
pickup tiny.nib; pos1(right_curve,0);
pos2(vair,90); pos3(left_curve,180);
y1=good.y bar_height; top y2r=letter_h+vround 1.5oo; y0l=bot y1;
rt x1r=hround min(w-.5u,w-u+.5right_curve);
lft x3r=hround max(.5u,1.25u-.5left_curve); x2=.5w+.25u;
{{interim superness:=more_super;
 filldraw stroke super_arc.e(1,2)}};  % right bowl
y3=.5[y2,y4]; bot y4r=-oo; x4=x2+.25u;
if serifs: pos4(vair',270); pos5(hair,360);
 y5=max(good.y(.5bar_height-.9),y4l+vair); x5r=x1r;
 (x,y4l)=whatever[z4r,z5]; x4l:=min(x,x4l+.5u);
 filldraw stroke pulled_arc.e(2,3) & pulled_arc.e(3,4)
  ...{x5-x4,5(y5-y4)}z5e; % left bowl, arc, and terminal
else: pos4(vair,270);
 filldraw stroke super_arc.e(2,3) & super_arc.e(3,4);  % left bowl and arc
 pickup fine.nib; pos4'(vair,270); z4=z4';
 pos5(.5[vair,flare],275); rt x5r=hround(w-.6u);
 y5r=good.y(y5r+1/3bar_height-y5); y5l:=good.y y5l; x5l:=good.x x5l;
 filldraw stroke term.e(4',5,right,1,4); fi  % terminal
path testpath; testpath=super_arc.r(2,3) & super_arc.r(3,4);
y1'r=y0r=y0l+.6[thin_join,vair]; y1'l=y0l; x1'l=x1'r=x1;
forsuffixes $=l,r:
 x0$=xpart(((0,y0$)--(x1,y0$)) intersectionpoint testpath); endfor
fill stroke z0e--z1'e;  % crossbar
pos6(dot_diam,0); pos7(dot_diam,90);
x6=x7=2.5u; top y7r=h+1;
if bot y7l<letter_h+o+slab: y7l:=min(y7r-eps,letter_h+o+slab+.5tiny); fi
y6=.5[y7l,y7r]; dot(6,7);  % left dot
pos8(dot_diam,0); penpos9(y7r-y7l,90); y8=y9=y6; x8=x9=w-x6;
dot(8,9);  % right dot
penlabels(0,1,2,3,4,5,6,7,8,9); endchar;

cmchar "The cyrillic letter zhe";
beginchar(CYR_zhe,15.5u#,x_height#,0);
italcorr if math_fitting:1/3x_height#*slant else:x_height#*slant-u# fi;
adjust_fit(0,0); pickup fine.nib;
numeric arc_width; arc_width=7u;
pos2(vair,-90); pos3(.8curve,0); pos4(vair,90);  % NG 
pos9(vair,90); pos10(.8curve,180); pos11(vair,270);   % NG
x2=x4=w-x9=.5(arc_width-2u); x11=x9;
rt x3r=w-lft x10r=hround(arc_width-2.5u+.5curve);  % NG
x6=x5; bot y2r=-oo; top y9r=h+oo;
top y4r=h+oo; bot y11r=-oo; y3=h-y10=.5[y2,y4];
pos5(4/7[vair',flare],110); pos8(4/7[vair',flare],80); 
rt x8r=w-lft x5r=hround(w-.6u); top y8r=top y5r=vround .82[bar_height,top y9r];
filldraw stroke term.e(4,5,left,.8,4);  % left upper terminal
filldraw stroke term.e(9,8,right,.8,-4);  % right upper terminal
pos1(.6[vair',flare],265); pos12(.6[vair',flare],275); 
rt x12r=w-lft x1r=hround(w-.5u);
y1r=good.y(y1r+1/3bar_height-y1); y1l:=good.y y1l; x1l:=good.x x1l; 
y12r=good.y(y12r+1/3bar_height-y12); y12l:=good.y y12l; x12l:=good.x x12l; 
forsuffixes e=l,r: path p.e,q.e; 
p.e=z2e{left}..tension .9 and 1..z1e;
q.e=z11e{right}..tension .9 and 1..z12e;
if angle direction 1 of p.e>75:
  p.e:=z2e{left}..tension atleast.9 and 1..{dir 115}z1e; 
  q.e:=z11e{right}..tension atleast.9 and 1..{dir 75}z12e; fi endfor
filldraw stroke pulled_super_arc.e(4,3)(.7superpull)
 & pulled_super_arc.e(3,2)(.5superpull) & p.e;  % left arc and lower terminal
filldraw stroke pulled_super_arc.e(9,10)(.7superpull)
 & pulled_super_arc.e(10,11)(.5superpull) & q.e;  % right arc and terminal
pos14(.9stem,0); pos15(.9stem,0);   % NG
x14=x15=.5w; top y14=h; bot y15=0;
filldraw stroke z14e--z15e;   % stem
penpos3'(bar,90); penpos10'(bar,90); z3'=z3; z10'=z10;
fill stroke z3'e--z10'e;  % bar
math_fit(-.3x_height#*slant+.5curve#-u#,ic#);
penlabels(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); endchar;

cmchar "The cyrillic letter ze";
beginchar(CYR_ze,7.5u#,x_height#,0);
italcorr x_height#*slant-.5u#;
adjust_fit(0,0);
pickup fine.nib;
pos1(1.2flare,100); pos2(slab,90);
pos3(flare,0); pos4(slab,-90); pos5(flare,-95);
rt x1r=hround(1.1u); x2=.5w; x4=.45[x1,x10]; x9=.5w-u;
rt x3r=hround w-max(u,2u-.5curve); rt x5r=hround(.9u);
top y1r=vround .9h+oo; top y2r=h+oo; y3=.5[y7,y2];
bot y4r=-oo; bot y5r=vround .15h-oo; y5l:=good.y y5l; x5l:=good.x x5l;
pos7(vair,-90); pos8(vair,-90);
pos9(max(fine.breadth,vround 2/3vair),90); pos10(flare,0);
rt x10r=hround(w-.75u); lft x8=min(hround 5u,lft x9)-eps;
y10=.5[y9,y4]; top y8l=vround(.54h+.5vair); y8r=y9l;
x7=1/3[x8,x3l]; z7=z8+whatever*(150u,h);
filldraw stroke rterm.e(2,1,left,.9,4) & super_arc.e(2,3)
& pulled_arc.e(3,8);  % upper bowl
filldraw stroke pulled_arc.e(9,10)
 & super_arc.e(10,4) & term.e(4,5,left,.8,4);  % lower bowl
penlabels(1,1',2,3,4,5,6,7,8,9,10); endchar;

cmchar "The cyrillic letter i";
beginchar(CYR_i,10u#,x_height#,0);
italcorr x_height#*slant-serif_fit#+.5stem#-2u#;
adjust_fit(serif_fit#+stem_shift#,serif_fit#-stem_shift#);
numeric light_vair; light_vair=vair if hefty: -vround 2vair_corr fi;
if light_vair<fine.breadth: light_vair:=fine.breadth; fi
pickup tiny.nib; pos1(stem,0); pos2(stem,0);
pos3(stem,0); pos4(stem',0);
lft x1l=hround(2.5u-.5stem); x1=x2; x3=w-x1; x3r=x4r;
if serifs: top y1=h+min(oo,serif_drop); bot y4=-min(oo,serif_drop);
else: top y1=h; bot y4=0; fi
pos0(stem,0); pos0'(stem',0); x0=x3; x0'=x4; y0=y0';
penpos2'(stem-fine,-180); z2'=z2; y3=y1; y2=.5bar_height;
penpos5(max(eps,light_vair-fine),-90); penpos6(thin_join-fine,0);
y6=y0=2/3bar_height;
filldraw stroke z1e--z2e;  % left stem
filldraw stroke z3e..z0e--z0'e..z4e;  % right stem
pickup fine.nib; bot y5r=-oo; x5l=.5w-.25u; lft x6l=tiny.lft x0l;
(x,y5r)=whatever[z5l,z6l]; x5r:=max(x,.5[x5,x2'r]);
filldraw stroke {{interim superness:=hein_super;
  pulled_arc.e(2',5)}} & z5e{right}...{up}z6e;  % arc
if serifs: sloped_serif.l(1,2,a,1/3,jut,serif_drop); % upper left serif
 sloped_serif.l(3,0,b,1/3,jut,serif_drop); % upper right serif
 sloped_serif.r(4,0',c,1/3,jut,min(oo,serif_drop)); fi % lower right serif
penlabels(1,2,3,4,5); labels(6); endchar;

cmchar "The cyrillic letter short_i";
beginchar(CYR_short_i,10u#,if serifs: 1.5x_height# 
 else: 1.4x_height# fi,0);
italcorr 1.5x_height#*slant-serif_fit#+jut#-2.5u#+min(.5stem#,u#);
adjust_fit(serif_fit#,serif_fit#);
numeric light_vair; light_vair=vair if hefty: -vround 2vair_corr fi;
pickup tiny.nib; pos1(stem,0); pos2(stem,0);
pos3(stem,0); pos4(stem',0);
lft x1l=hround(2.5u-.5stem); x1=x2; x3=w-x1; x3r=x4r;
if serifs: top y1=x_height+min(oo,serif_drop); bot y4=-min(oo,serif_drop);
else: top y1=x_height; bot y4=0; fi
pos0(stem,0); pos0'(stem',0); x0=x3; x0'=x4; y0=y0';
penpos2'(stem-fine,-180); z2'=z2; y3=y1; y2=.5bar_height;
penpos5(max(eps,light_vair-fine),-90); penpos6(thin_join-fine,0);
y6=y0=2/3bar_height;
filldraw stroke z1e--z2e;  % left stem
filldraw stroke z3e..z0e--z0'e..z4e;  % right stem
pickup fine.nib; bot y5r=-oo; x5l=.5w-.25u; lft x6l=tiny.lft x0l;
(x,y5r)=whatever[z5l,z6l]; x5r:=max(x,.5[x5,x2'r]);
filldraw stroke {{interim superness:=hein_super;
  pulled_arc.e(2',5)}} & z5e{right}...{up}z6e;  % arc
if serifs: sloped_serif.l(1,2,a,1/3,jut,serif_drop); % upper left serif
 sloped_serif.l(3,0,b,1/3,jut,serif_drop); % upper right serif
 sloped_serif.r(4,0',c,1/3,jut,min(oo,serif_drop)); fi % lower right serif
pickup fine.nib; penpos7(.75vair,-90);
penpos8(.75vair,-180); penpos10(.75vair,0);
x7=.5[x8,x10]; y7=.85h;
x8r=x1r; x10r=x3l; top y8=top y10=h;
filldraw stroke z8e...z7e...z10e; 
penlabels(1,2,2',3,3',4,5,6,7,8,9,10,11);  endchar;

cmchar "The cyrillic letter ka";
beginchar(CYR_ka,9.5u#,x_height#,0);
italcorr x_height#*slant-.5u#;
adjust_fit(serif_fit#,serif_fit#);
numeric right_jut,stem[],alpha[];
if serifs: right_jut=.6jut;
else: right_jut=.4tiny; fi
pickup tiny.nib; pos1(fudged.stem,0); pos2(fudged.stem,0);
lft x1l=lft x2l=hround(2.5u-.5fudged.stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
stem2=max(tiny.breadth,fudged.stem-3stem_corr);
stem1=max(tiny.breadth,fudged.hair if hefty:-3stem_corr fi);
top y3=h; rt x3r=hround(r-letter_fit-.75u-right_jut);
bot y6=0; rt x6r=hround(r-letter_fit-.5u-right_jut);
x4=x1; y4=1/3h;
alpha1=diag_ratio(1,.5(stem1-tiny),y3-y4,x3r-x4);
penpos3(alpha1*(stem1-tiny),0); penpos4(whatever,-90);
alpha2=diag_ratio(1,.5(stem2-tiny),y1-y6,x6r-x1);
penpos6(alpha2*(stem2-tiny),0);
forsuffixes $=l,r: y3'$=h; y6'$=0; z4$=z3'$+whatever*(z3-z4);
 z5$=z6'$+whatever*(z1-z6)=whatever[z3,z4]; endfor
z5=.5[z5l,z5r];
z3'r=z3r+penoffset z3-z4 of currentpen+whatever*(z3-z4);
% we have also |z3'l=z3l+penoffset z4-z3 of currentpen+whatever*(z3-z4)|;\]
z6'r=z6r+penoffset z1-z6 of currentpen+whatever*(z1-z6);
z6'l=z6l+penoffset z6-z1 of currentpen+whatever*(z1-z6);
fill z4r--diag_end(4r,3'r,1,.5,3'l,4l)--z4l--cycle;  % upper diagonal
fill z5l--diag_end(5l,6'l,.5,1,6'r,5r)--z5r--cycle;  % lower diagonal
if serifs:  numeric inner_jut;
 if rt x2r+jut+.5u+1<=lft x6l-jut: inner_jut=jut;
 else: rt x2r+jut+.5u+1=lft x6l-inner_jut; fi
 dish_serif(1,2,a,1/3,jut,b,1/3,jut); % upper stem serif
 dish_serif(2,1,c,1/3,jut,d,1/3,jut);  % lower stem serif
 dish_serif(3,4,e,2/3,right_jut,f,1/2,right_jut)(dark); % upper diagonal serif
 dish_serif(6,5,g,1/2,inner_jut,h,1/3,right_jut)(dark);fi % lower diagonal serif
penlabels(1,2,3,4,5,6); endchar;

cmchar "The cyrillic letter el";
beginchar(CYR_el,9.5u#,x_height#,0);
italcorr x_height#*slant-.5u;
adjust_fit(0,serif_fit#);
pickup tiny.nib; 
numeric light_stem; light_stem=.9stem;
pos1(light_stem,0); pos2(light_stem,0); pos3(light_stem,0);
lft x1l=.5u; rt x3r=w-.5u; bot y1=bot y3=0;
x2=.5[x1,x3]; top y2=h;
filldraw stroke z1e--z2e;  % left stem
filldraw stroke z2e--z3e;  % right stem
penlabels(1,2,3); endchar;

%cmchar "The cyrillic letter el";
%beginchar(CYR_el,10u#,x_height#,0);
%italcorr x_height#*slant-serif_fit#
% +.75jut#-2.5u#+min(.5stem#,u#);
%adjust_fit(0,serif_fit#);
%pickup tiny.nib;
%pos1(hair,90); pos2(hair,90); pos3(hair,180); 
%pos4(stem,0); pos4'(slab,90); pos5(stem,0);
%x3=.33w; rt x4r=rt x5r=hround(w-2.5u+.5stem); 
%top y4=h; bot y5=0; y3=.52h; 
%filldraw stroke z4e--z5e;  % right stem
%x1=u; x2=x1+.75u; bot y1l=0; bot y2l=0;
%rt x4'=rt x4r; top y4'r=h;
%filldraw stroke z1e..z2e{right}...{up}z3e{up}..{right}z4'e;  % stem and arc
%penlabels(1,2,3,4,5,6); endchar;

cmchar "The cyrillic letter em";
beginchar(CYR_em,12u#,x_height#,0);
italcorr x_height#*slant-serif_fit#+jut#-2.5u#+min(.5stem#,u#);
adjust_fit(serif_fit#,serif_fit#);
numeric stem[]; % thicknesses of the four strokes
stem1=hround(fudged.hair+stem_corr);
stem2=hround(fudged.stem-4stem_corr);
stem3=hround(fudged.hair-stem_corr);
stem4=hround(fudged.stem-3stem_corr);
if stem4<stem1: stem4:=stem1; fi
pickup tiny.nib; pos1(stem1,0); pos2(stem1,0);
pos3(stem4,0); pos4(stem4,0);
x1=x2; x3=x4; x1l=w-x3r; rt x3r=hround(w-2.5u+.5stem4);
top y1=top y3=h; bot y2=bot y4=0;
filldraw stroke z1e--z2e; % left stem
filldraw stroke z3e--z4e; % right stem
penpos5(stem2,0); penpos6(stem2,0); penpos7(stem3,0); penpos8(stem3,0);
x5l=x1; x6l=x7l; x8=lft x3l; x6-x5=x8-x7; y5=y8=h; y6=y7;
y6=1/3h;
if hefty: 
%y6=if monospace: vround 1/3h else: o fi;
 numeric upper_notch,lower_notch;
 upper_notch=h-notch_cut; lower_notch=y6+notch_cut;
 x1'=rt x1r; z1'=whatever[z5l,z6l]; x3'=lft x3l; z3'=whatever[z7r,z8r];
 z0=whatever[z5r,z6r]=whatever[z7l,z8l];
 fill z5l..
  if y1'<upper_notch: {right}(x1'+1,upper_notch){down}... fi
  {z6-z5}diag_in(5l,6l,1,6r)..diag_out(7l,1,7r,8r){z8-z7}
  if y3'<upper_notch: ...{up}(x3'-1,upper_notch){right} fi
  ..z8r--diag_out(8r,1,8l,7l){z7-z8}
  if y0<=lower_notch: ..{z7-z8}z0{z5-z6}..
  else: ...{down}(x0+.5,lower_notch)--(x0-.5,lower_notch){up}... fi
  {z5-z6}diag_in(6r,5r,1,5l)--cycle;  % diagonals
else: 
%y6=0; 
 z0=whatever[z5r,z6r]=whatever[z7l,z8l];
 fill z5l..{z6-z5}diag_in(5l,6l,1,6r)..diag_out(7l,1,7r,8r){z8-z7}
  ..z8r--diag_out(8r,1,8l,7l){z7-z8}..{z7-z8}z0{z5-z6}
  ..{z5-z6}diag_in(6r,5r,1,5l)--cycle; fi  % diagonals
if serifs: serif(1,2,a,1/3,-jut);  % upper left serif
 dish_serif(2,1,b,1/2,jut,c,1/2,jut)(dark); % lower left serif
 serif(3,4,d,1/3,jut); %  upper right serif
 dish_serif(4,3,e,1/3,jut,f,1/3,jut); fi  % lower right serif
penlabels(0,1,1',2,3,3',4,5,6,7,8); endchar;

cmchar "The cyrillic letter en";
beginchar(CYR_en,10u#,x_height#,0);
italcorr x_height#*slant-serif_fit#+jut#-2.5u#+min(.5stem#,u#);
adjust_fit(serif_fit#,serif_fit#);
pickup tiny.nib; pos1(stem,0); pos2(stem,0);
pos3(stem,0); pos4(stem,0);
lft x1l=lft x2l=hround(2.5u-.5stem); x3=x4=w-x1;
top y1=top y3=h; bot y2=bot y4=0;
filldraw stroke z1e--z2e; % left stem
filldraw stroke z3e--z4e; % right stem
penpos5(bar,90); penpos6(bar,90);
x5=x1; x6=x3; y5=y6=.52h;
fill stroke z5e--z6e;  % bar
if serifs:  numeric inner_jut;
 if rt x1r+jut+.5u+1<=lft x3l-jut: inner_jut=jut;
 else: rt x1r+inner_jut+.5u+1=lft x3l-inner_jut; fi
 dish_serif(1,2,a,1/3,jut,b,1/3,inner_jut);  % upper left serif
 dish_serif(2,1,c,1/3,jut,d,1/3,inner_jut); % lower left serif
 dish_serif(3,4,e,1/3,inner_jut,f,1/3,jut);  % upper left serif
 dish_serif(4,3,g,1/3,inner_jut,h,1/3,jut); fi  % lower left serif
penlabels(1,2,3,4,5,6); endchar;

cmchar "The cyrillic letter o";
beginchar(CYR_o,9u#,x_height#,0);
italcorr .7x_height#*slant;
adjust_fit(if monospace: .5u#,.5u# else: 0,0 fi);
penpos1(vair,90); penpos3(vair',-90);
penpos2(curve,180); penpos4(curve,0);
x2r=hround max(.5u,1.25u-.5curve);
x4r=w-x2r; x1=x3=.5w; y1r=h+vround 1.5oo; y3r=-oo;
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 "The cyrillic letter pe";
beginchar(CYR_pe,10u#,x_height#,0);
italcorr .5[bar_height#,x_height#]*slant-serif_fit#+.5stem#-2u#;
adjust_fit(serif_fit#+stem_shift#,serif_fit#-stem_shift#);
pickup tiny.nib; pos1(stem,0); pos2(stem,0);
numeric shaved_stem; shaved_stem=hround(stem-2stem_corr);
pos1'(shaved_stem,0); pos2'(shaved_stem,0); pos3(stem,0);
lft x1l=hround(2.5u-.5stem); x1l=x1'l=x2l=x2'l; x3=w-x1;
top y1=h+min(oo,serif_drop); bot y2=0; y1=y1'; y2=y2';
filldraw stroke z1'e--z2'e;  % left stem
h_stroke(2,a,3,4);  % arch and right stem
if serifs: sloped_serif.l(1',2',b,1/3,jut,serif_drop); % upper left serif
 numeric inner_jut; pickup tiny.nib;
 if rt x2r+jut+.5u+1<=lft x4l-jut: inner_jut=jut;
 else: rt x2r+jut+.5u+1=lft x4l-inner_jut; fi
 dish_serif(2,1,c,1/3,jut,d,1/3,jut); % lower left serif
 dish_serif(4,3,e,1/3,inner_jut,f,1/3,jut); fi % lower right serif
penlabels(1,2,3,4); endchar;

cmchar "The cyrillic letter er";
beginchar(CYR_er,10u#+serif_fit#,x_height#,desc_depth#);
italcorr .5x_height#*slant+min(.5curve#-.85u#,-.1u#);
adjust_fit(serif_fit#,0);
pickup tiny.nib; pos1(stem',0); pos2(stem,0);
pos0'(stem',0); pos0(stem,0); z0l=z0'l; x0'=x1; x0=x2;
lft x1l=hround(2.5u-.5stem'); top y1=h if serifs: +min(oo,serif_drop) fi;
numeric edge; edge=rt x2r;
pickup fine.nib; pos3(if hefty:thin_join else: hair fi,180);
pos4(vair',90); pos5(curve,0); pos6(vair,-90); penpos7(x3l-x3r,-180);
rt x3l=max(rt x3l-(lft x3r-tiny.lft x2l), 1/3[rt x2,edge]);
y3=1/8[bar_height,x_height];
x4l=w-.5(w-serif_fit)+.5u; top y4r=x_height+oo;
rt x5r=hround min(w-1.35u+.5curve,w-.6u); y5=.5x_height;
x6l=x4l-.2u; bot y6r=-oo;
x7=x3; y7=min(y3,y6+y4-y3+.6vair);
(x,y4r)=whatever[z3l,z4l]; x4r:=min(x,.5[x5r,x4]);
(x',y6r)=whatever[z7l,z6l]; x6r:=min(x',.5[x5r,x6]);
filldraw stroke z3e{up}...{right}z4e&super_arc.e(4,5)
 &super_arc.e(5,6)&z6e{left}...{up}z7e;  % bowl
y0=ypart(((edge,h)--(edge,0))intersectionpoint(z3l{up}...{right}z4l));
pickup tiny.nib; bot y2=-d;
filldraw stroke z1e--z0'e--z0e--z2e;  % stem
pickup crisp.nib; pos8(hair,0); pos7'(stem,0);
z7'=z2; x8l=x7'l; bot y8=0;
filldraw stroke z7'e--z8e;  % point
if serifs: sloped_serif.l(1,0',a,1/3,jut,serif_drop);  % upper serif
 dish_serif(2,0,b,1/3,jut,c,1/3,jut); fi  % lower serif
penlabels(0,1,2,3,4,5,6,7,8); endchar;

cmchar "The cyrillic letter es";
beginchar(CYR_es,8u#,x_height#,0);
italcorr x_height#*slant-.2u#;
adjust_fit(if monospace: .5u#,.5u# else: 0,0 fi);
pickup fine.nib; pos2(vair',90); pos4(vair',270);
x2=x4=.5(w+u); top y2r=vround(h+1.5oo); bot y4r=-oo;
pos3(curve,180); lft x3r=hround max(.6u,1.35u-.5curve); y3=.5h;
if serifs: pos1(hair,0); pos0(flare,0);
 y1=min(bar_height+.5flare+2vair'+2,.9[bar_height,h]-.5flare);
 rt x1r=hround(w-.7u); bulb(2,1,0);  % bulb
 pos5(hair,0); rt x5r=hround(w-.5u);
 y5=max(good.y(.5bar_height-.9),y4l+vair');
 (x,y4l)=whatever[z4r,z5l]; x4l:=min(x,x4l+.5u);
 filldraw stroke pulled_super_arc.e(2,3)(.7superpull)
  & pulled_super_arc.e(3,4)(.5superpull)
  ..tension .9 and 1..{x5-x4,5(y5-y4)}z5e;  % arc and lower terminal
else: pos1(4/7[vair',flare],80);
 rt x1r=hround(w-.6u); top y1r=vround .82[bar_height,top y2r];
 filldraw stroke term.e(2,1,right,.8,4);  % upper terminal
 pos5(.6[vair',flare],275); rt x5r=hround(w-.5u);
 y5r=good.y(y5r+1/3bar_height-y5); y5l:=good.y y5l; x5l:=good.x x5l;
 forsuffixes e=l,r: path p.e; p.e=z4e{right}..tension .9 and 1..z5e;
  if angle direction 1 of p.e>75:
   p.e:=z4e{right}..tension atleast.9 and 1..{dir 75}z5e; fi endfor
 filldraw stroke pulled_super_arc.e(2,3)(.7superpull)
  & pulled_super_arc.e(3,4)(.5superpull) & p.e; fi  % arc and lower terminal
penlabels(0,1,2,3,4,5); endchar;

cmchar "The cyrillic letter te";
beginchar(CYR_te,10u#,x_height#,0);
italcorr x_height#*slant-beak_jut#-.25u#;
adjust_fit(0,0);
h:=vround(h-2stem_corr);
pickup tiny.nib; pos1(stem,0); pos2(stem,0);
if odd(w-stem): change_width; fi
lft x1l=lft x2l=hround(.5w-.5stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
pickup crisp.nib; pos3(slab,90); pos4(hair,0);
top y3r=h; x3=x1; rt x4r=hround(w-.65u); y4=good.y(y3l-.6beak)-eps;
arm(3,4,e,beak_darkness,.7beak_jut);  % right arm and beak
pos5(hair,180); x5=w-x4; y5=y4;
arm(3,5,f,beak_darkness,-.7beak_jut);  % left arm and beak
if serifs: dish_serif(2,1,c,1/3,1.414jut,d,1/3,1.414jut);  % lower serif
 nodish_serif(1,2,a,1/3,.5jut,b,1/3,.5jut); fi  % upper bracketing
penlabels(1,2,3,4,5); endchar;

cmchar "The cyrillic letter te";
beginchar(oct"040",15u#,x_height#,0);
italcorr .5[bar_height#,x_height#]*slant-serif_fit#+.5stem#-2u#;
adjust_fit(serif_fit#+stem_shift#,serif_fit#-stem_shift#);
numeric shaved_stem; shaved_stem=hround(mfudged.stem-2stem_corr);
pickup tiny.nib; pos1(mfudged.stem,0); pos2(mfudged.stem,0);
pos1'(shaved_stem,0); pos2'(shaved_stem,0);
pos3(mfudged.stem,0); pos5(mfudged.stem,0);
lft x1l=hround(2.5u-.5stem); x1l=x1'l=x2l=x2'l;
lft x3l=hround(.5w-.5stem); x5-x3=x3-x1;
if not monospace: r:=hround(x5+x1)-l; fi  % change width for better fit
top y1=h+min(oo,serif_drop); bot y2=0; y1=y1'; y2=y2';
filldraw stroke z1'e--z2'e;  % left stem
h_stroke(2,a,3,4);  % left arch and middle stem
h_stroke(4,b,5,6);  % right arch and right stem
if serifs: sloped_serif.l(1',2',c,1/3,jut,serif_drop); % upper left serif
 numeric inner_jut; pickup tiny.nib;
 if rt x2r+jut+.5u+1<=lft x4l-jut: inner_jut=jut;
 else: rt x2r+jut+.5u+1=lft x4l-inner_jut; fi
 dish_serif(2,1,d,1/3,jut,e,1/3,jut); % lower left serif
 dish_serif(4,3,f,1/3,inner_jut,g,1/3,jut); % lower middle serif
 dish_serif(6,5,h,1/3,inner_jut,i,1/3,jut); fi % lower right serif
penlabels(1,2,3,4,5,6); endchar;

cmchar "The cyrillic letter u";
beginchar(CYR_u,if serifs:9.5u# else:9u# fi,x_height#,desc_depth#);
italcorr x_height#*slant+.25u#;
adjust_fit(serif_fit# if monospace:+\\.5u#,.5u#+ else:,fi\\ serif_fit#);
numeric left_stem,right_stem,bot_stem,bot_vair,outer_jut;
left_stem=fudged.stem-stem_corr;
right_stem=fudged.hair if hefty:-2stem_corr fi;
bot_stem=fudged.hair if hefty:-8stem_corr fi;
bot_vair=Vround(if serifs: vair else:.5[vair,bot_stem] fi);
outer_jut=.75jut;
x1l=w-x4r=l+letter_fit+outer_jut+.25u; y1=y4r=h; y2=y3=0; x2l=x3l;
numeric alpha,alpha[]; x9=3u; y9=bot_vair-d-oo;
alpha1=diag_ratio(2,bot_stem,y1-y3,x4r-x1l-apex_corr);
alpha2=diag_ratio(1,bot_stem,y1-y9,x4r-x9);
if alpha1<alpha2: x2l-x1l=x4r-x3r+apex_corr; alpha=alpha1;
else: alpha=alpha2; z3l=whatever[z9,z4r-(alpha*bot_stem,0)]; fi
penpos3(alpha*bot_stem,0); penpos4(alpha*right_stem,0);
alpha3=(y1++(x2l-x1l))/y1;
penpos1(alpha3*left_stem,0); penpos2(alpha3*left_stem,0);
z0=whatever[z1r,z2r]=z4l+whatever*(z3r-z4r);
if y0>notch_cut: y0:=notch_cut;
  fill z0+.5right{up}...{z4r-z3r}diag_end(0,4l,1,1,4r,3r)
    --z3r--z2l--diag_end(2l,1l,1,1,1r,2r){z2-z1}
    ...{down}z0+.5left--cycle; % left and right diagonals
else: fill z0--diag_end(0,4l,1,1,4r,3r)--z3r--z2l
    --diag_end(2l,1l,1,1,1r,0)--cycle; fi % left and right diagonals
penpos5(alpha*bot_stem,0); z5r=whatever[z3r,z4r]; y5-.5vair=-.5d;
if serifs: numeric light_bulb; light_bulb=hround 7/8[hair,flare]; clearpen;
 penpos6(vair,-90); penpos7(hair,-180); penpos8(light_bulb,-180);
 x6=2u; y6r=-d-oo; y8-.5light_bulb=-.85d; x8r=hround .35u;
 fill stroke z3e---z5e...{left}z6e; bulb(6,7,8);  % arc and bulb
 numeric inner_jut; pickup tiny.nib;
 prime_points_inside(1,2); prime_points_inside(4,3);
 if rt x1'r+jut+.5u+1<=lft x4'l-jut: inner_jut=jut;
 else: rt x1'r+inner_jut+.5u+1=lft x4'l-inner_jut; fi
 dish_serif(1',2,a,1/3,outer_jut,b,1/2,inner_jut);  % left serif
 dish_serif(4',3,c,.6,inner_jut,d,1/2,outer_jut)(dark);  % right serif
else: penpos6(bot_vair,-90); x6=2.5u; y6r=-d-oo;
 fill stroke z3e---z5e...{left}z6e;  % arc
 pickup fine.nib; pos6'(bot_vair,-90); z6'=z6;
 pos7(2/3[bot_vair,flare],-85);
 lft x7l=hround u; bot y7r=vround-.96d-oo; y7l:=good.y y7l;
 filldraw stroke term.e(6',7,left,1,4); fi % arc and terminal
penlabels(0,1,2,3,4,5,6,7,8,9); endchar;

cmchar "The cyrillic letter ef";
beginchar(CYR_ef,12u#,x_height#+desc_depth#,desc_depth#);
italcorr .75x_height#*slant-.5u#;
adjust_fit(serif_fit#,0);
pickup tiny.nib; pos1(stem,0); pos2(stem,0);
if odd(w-stem): change_width; fi
top y1=h if serifs: +min(oo,serif_drop) fi; 
x1=x2=.5w; bot y2=-d; 
penpos3(.75vair,180);penpos3'(.75vair,0); 
penpos4(.75vair,90); penpos5(curve,0);
penpos6(.5[vair,.75vair],-90); 
penpos7(.75vair,180); penpos7'(.75vair,0);
penpos8(.75vair,90); penpos9(curve,180);
penpos10(.75vair,270);
x3l=x7l=rt x1r; x3'l=x7'l=lft x1l; 
y4r=y8r=x_height+oo; y5=y9=.5[y4l,y6l];
x4r=x6r=.5[x1,x5]; x8r=x10r=.5[x9,x1];
x5r=w-x9r=w-.5u; 
y7=y7'=.25x_height; y3=y3'=x_height-y7; y6r=y10r=-oo;
filldraw stroke z1e--z2e; % stem
fill stroke z3e{up}..pulled_arc.e(4,5) & pulled_arc.e(5,6)..{up}z7e;
fill stroke z3'e{up}..pulled_arc.e(8,9) & pulled_arc.e(9,10)..{up}z7'e;  % lobe
if serifs:
 sloped_serif.l(1,2,a,1/3,jut,.1h);  % upper serif
 dish_serif(2,1,b,1/3,jut,c,1/3,jut); fi  % lower serif
penlabels(0,1,2,3,3',4,5,6,7,7',8,9,10); endchar;

cmchar "The cyrillic letter ha";
beginchar(CYR_ha,if serifs:9.5u# else:9u# fi,x_height#,0);
italcorr x_height#*slant-.05u#;
adjust_fit(serif_fit# if monospace:+\\.5u#,.5u#+ else:,fi\\ serif_fit#);
numeric stem[],outer_jut,xjut,alpha[];
stem1=fudged.stem-4stem_corr; stem2=min(fudged.hair,stem1);
outer_jut=.75jut; xjut= if serifs: (stem1-stem2)/4 else: 0 fi;
x1l=l+letter_fit+.1u+outer_jut; x2r=r-letter_fit-.3u-outer_jut-xjut;
x3l=l+letter_fit+outer_jut+xjut; x4r=r-letter_fit-outer_jut;
y1=y2=h; y3=y4=0;
alpha1=diag_ratio(1,stem1,h,x4r-x1l);
alpha2=diag_ratio(1,stem2,h,x2r-x3l);
penpos1(alpha1*stem1,0); penpos2(alpha2*stem2,0);
penpos3(alpha2*stem2,0); penpos4(alpha1*stem1,0);
if hefty: z0=whatever[z1,z4]=whatever[z2,z3];
 x12=x34=x0; y13=y24=y0;
 z12=whatever[z2l,z3l]; z13=whatever[z2l,z3l];
 z24=whatever[z2r,z3r]; z34=whatever[z2r,z3r];
 forsuffixes $=13,24,34: z$'=.2[z$,z0]; endfor
 fill diag_end(12,1r,.5,1,1l,13')--z13'--diag_end(13',3l,1,.5,3r,34')--z34'
  --diag_end(34',4l,.5,1,4r,24')--z24'
  --diag_end(24',2r,1,.5,2l,12)--z12--cycle; % diagonals
else: fill diag_end(4r,1r,.5,1,1l,4l)
  --diag_end(1l,4l,.5,1,4r,1r)--cycle; % left diagonal
 fill diag_end(2l,3l,.5,1,3r,2r)
  --diag_end(3r,2r,.5,1,2l,3l)--cycle; fi  % right diagonal
if serifs: numeric inner_jut[]; pickup tiny.nib;
 prime_points_inside(1,4); prime_points_inside(2,3);
 prime_points_inside(3,2); prime_points_inside(4,1);
 if rt x1'r+jut+.5u+1<=lft x2'l-jut-xjut: inner_jut1=jut;
 else: rt x1'r+inner_jut1+.5u+1=lft x2'l-inner_jut1-xjut; fi
 if rt x3'r+jut+.5u+1<=lft x4'l-jut-xjut: inner_jut2=jut;
 else: rt x3'r+inner_jut2+.5u+1=lft x4'l-inner_jut2-xjut; fi
 dish_serif(1',4,a,1/3,outer_jut,b,2/3,inner_jut1);  % upper left serif
 dish_serif(4',1,c,2/3,inner_jut2,d,1/3,outer_jut);  % lower right serif
 dish_serif(2',3,e,2/3,inner_jut1+xjut,
  f,1/2,outer_jut+xjut)(dark);  % upper right serif
 dish_serif(3',2,g,1/2,outer_jut+xjut,
  h,2/3,inner_jut2+xjut)(dark); fi  % lower left serif
penlabels(0,1,2,3,4,12,13,24,34); endchar;

cmchar "The cyrillic letter tse";
beginchar(CYR_tse,11u#,x_height#,comma_depth#);
italcorr x_height#*slant-serif_fit#+.5stem#-2u#;
adjust_fit(serif_fit#+stem_shift#,serif_fit#-stem_shift#);
numeric light_vair,letter_w; letter_w=10u;
light_vair=vair if hefty: -vround 2vair_corr fi;
if light_vair<fine.breadth: light_vair:=fine.breadth; fi
pickup tiny.nib; pos1(stem,0); pos2(stem,0);
pos3(stem,0); pos4(stem',0);
lft x1l=hround(2.5u-.5stem); x1=x2; x3=letter_w-x1; x3r=x4r;
top y1=h; bot y4=.12h;
pos0(stem,0); pos0'(stem',0); x0=x3; x0'=x4; y0=y0';
penpos2'(stem-fine,-180); z2'=z2; y3=y1; y2=.5bar_height;
penpos5(max(eps,light_vair-fine),-90); penpos6(thin_join-fine,0);
y6=y0=2/3bar_height;
filldraw stroke z1e--z2e;  % left stem
filldraw stroke z3e..z0e--z0'e..z4e;  % right stem 
z4'l=lft z4l; z4'r=rt z4r;
penpos7(stem,40); penpos8(stem,-35);
rt x7r=w-.5u; y7=0; x8l=x4l; y8=-d;
(z8l-z9)=whatever*(z8r-z7r); y9=.5[y7l,y7r];
fill stroke z4'e{down}..z7e;  % lower arc
fill z8l--z8r--z7r--z9--cycle; % appendix
pickup fine.nib; bot y5r=-oo; x5l=.5letter_w-.25u; lft x6l=tiny.lft x0l;
(x,y5r)=whatever[z5l,z6l]; x5r:=max(x,.5[x5,x2'r]);
filldraw stroke {{interim superness:=hein_super;
  pulled_arc.e(2',5)}} & z5e{right}...{up}z6e;  % arc
penlabels(1,2,3,4,5,7,8,9); labels(6); endchar;

cmchar "The cyrillic letter che";
beginchar(CYR_che,10u#,x_height#,0);
italcorr x_height#*slant-serif_fit#+.5stem#-2u#;
adjust_fit(serif_fit#+stem_shift#,serif_fit#-stem_shift#);
pickup tiny.nib; pos1(stem,0); pos2(stem,0);
pos3(stem,0); pos4(stem,0);
numeric light_vair; light_vair=vair-fine;
lft x1l=hround(2.5u-.5stem); x1=x2; x3l=w-x1r; x3r=x4r;
top y1=h; bot y4=0;
penpos2'(stem-fine,-180); z2'=z2; y3=y1; y2=.65h;
penpos5(light_vair,-90); penpos6(light_vair,0);
y6=.5h; lft x6l=lft x3l; if rt x6r>rt x3r: x6r:=x3r; fi
filldraw stroke z1e--z2e;  % left stem
filldraw stroke z3e--z4e;  % right stem
pickup fine.nib; bot y5r=y6-vair-.05h; x5=.5w; 
filldraw stroke {{interim superness:=hein_super; 
 pulled_super_arc.e(2',5)(.01superpull)}}
 & z5e{right}...z6e;  % arc
if serifs: numeric inner_jut;  
 if rt x1r+jut+.5u+1<=lft x3l-jut: inner_jut=jut;
 else: rt x1r+inner_jut+.5u+1=lft x3l-inner_jut; fi
 dish_serif(1,2,a,1/3,jut,b,1/3,inner_jut);  % upper left serif
 dish_serif(3,4,e,1/3,inner_jut,f,1/3,jut);  % upper right serif
 dish_serif(4,3,g,1/3,jut,h,1/3,jut); fi  % lower right serif
penlabels(1,2,3,4,5,6); endchar;

 def i_stroke(suffix $,@,@@,$$) =                                   
 penpos$$(x@@l-x@@r,180); x$$=x@@; top y$$=h;                        
 y@@=h-1/3[bar_height,x_height];                                     
 penpos$''(x$l-x$r,180); x$''=x$; y$''=h-1/8[bar_height,x_height];     
 filldraw stroke z$''e--z$e;  % thicken the lower left stem        
 penpos@0(min(rt x$l-lft x$r,thin_join)-fine,0); pickup fine.nib;
 lft x@0l=tiny.lft x$r; y@0=y$'';                                    
 pos@1(vair,-90); pos@@'(x@@l-x@@r+tiny,180); z@@'=z@@;               
 x@1=.5[lft x@@'r,lft x@0l]; bot y@1r=-oo;                   
 (x@,y@1l)=whatever[z@0l,z@1r]; x@1l:=x@;                          
 filldraw stroke z@0e{down}...{left}z@1e
  &{{interim superness:=hein_super; super_arc.e(@1,@@')}};  % arch 
 pickup tiny.nib; filldraw stroke z@@e--z$$e;  % right stem        
 labels(@0); penlabels(@0,@1); enddef;                                

cmchar "The cyrillic letter sha";
beginchar(CYR_sha,15u#,x_height#,0);
italcorr .5[bar_height#,x_height#]*slant-serif_fit#+.5stem#-2u#;
adjust_fit(serif_fit#+stem_shift#,serif_fit#-stem_shift#);
numeric shaved_stem; shaved_stem=hround(mfudged.stem-2stem_corr);
pickup tiny.nib; pos1(mfudged.stem,180); pos2(mfudged.stem,180);
pos1'(shaved_stem,180); pos2'(shaved_stem,180);
pos3(mfudged.stem,180); pos5(mfudged.stem,180);
rt x1l=hround(w-2.5u+.5stem); x1l=x1'l=x2l=x2'l;
rt x3l=hround(.5w+.5stem); x5-x3=x3-x1;
if not monospace: r:=hround(x1+x5)-l; fi  % change width for better fit
bot y1=-min(oo,serif_drop); top y2=h; y1=y1'; y2=y2';
filldraw stroke z1'e--z2'e;  % left stem
i_stroke(2,a,3,4);  % left arch and middle stem
i_stroke(4,b,5,6);  % right arch and right stem
penlabels(1,2,3,4,5,6); endchar;

cmchar "The cyrillic letter shcha";
beginchar(CYR_shcha,16u#,x_height#,comma_depth#);
italcorr .5[bar_height#,x_height#]*slant-serif_fit#+.5stem#-2u#;
adjust_fit(serif_fit#+stem_shift#,serif_fit#-stem_shift#);
numeric shaved_stem,letter_w; letter_w=15u; 
shaved_stem=hround(mfudged.stem-2stem_corr);
pickup tiny.nib; pos1(mfudged.stem,180); pos2(mfudged.stem,180);
pos1'(shaved_stem,180); pos2'(shaved_stem,180);
pos3(mfudged.stem,180); pos5(mfudged.stem,180);
rt x1l=hround(letter_w-2.5u+.5stem); x1l=x1'l=x2l=x2'l;
rt x3l=hround(.5letter_w+.5stem); x5-x3=x3-x1;
if not monospace: r:=hround(x1+x5+u)-l; fi  % change width for better fit
bot y1=.12h; top y2=h; y1=y1'; y2=y2';
filldraw stroke z1'e--z2'e;  % left stem
i_stroke(2,a,3,4);  % left arch and middle stem
i_stroke(4,b,5,6);  % right arch and right stem
z6'l=lft z1r; z6'r=rt z1l;
penpos7(stem,40); penpos8(stem,-35);
rt x7r=w-.5u; y7=0; x8l=x1r; y8=-d;
(z8l-z9)=whatever*(z8r-z7r); y9=.5[y7l,y7r];
fill stroke z6'e{down}..z7e;  % lower arc
fill z8l--z8r--z7r--z9--cycle; % appendix
penlabels(1,2,3,4,5,6,6',7,8,9); endchar;

cmchar "The cyrillic letter hard_sign";
beginchar(CYR_hard_sign,10.5u#,x_height#,0);
italcorr .75x_height#*slant-.5u#;
adjust_fit(serif_fit#,0);
numeric left_stem,right_curve,middle_weight;
left_stem=stem-hround 2stem_corr; middle_weight=.6vair+.5;
pickup tiny.nib; pos1(left_stem,0); pos2(left_stem,0);
lft x1l=lft x2l=hround(4u-.5left_stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
penpos5(.75vair,90); penpos6(.75vair,90); penpos7(right_curve,0);
penpos8(.75vair,-90); penpos9(.75vair,-90);
z9r=bot z2; y8=y9; y7=.5[y8,y6]; y5=y6=.52h;
x6=x8; x5=x1; x6l:=x6-.25u; x7r=hround(w-.5u); x8l:=x8l-.5u;
if serifs: right_curve=curve-stem_corr; x6=.5[x1,w-u];
else: right_curve=curve-3stem_corr; x6=.5[x1,w-1.2u];
x6l:=x6l-.5u; fi
fill stroke z5e..super_arc.e(6,7) & super_arc.e(7,8)..z9e;  % lower lobe
pickup crisp.nib; pos3(slab,90); pos4(hair,180);
top y3r=h; x3=x1; lft x4r=hround(.5u); y4=good.y(y3l-.6beak)-eps;
arm(3,4,e,beak_darkness,-.7beak_jut);  % upper arm and beak
if serifs: nodish_serif(1,2,a,0,jut,b,1/3,jut);  % upper serif
nodish_serif(2,1,c,1/3,jut,d,1/3,.5jut); fi  % lower serif
penlabels(1,2,3,4,5,6,7,8,9); endchar;

cmchar "The cyrillic letter yeru";
beginchar(CYR_yeru,13u#,x_height#,0);
italcorr .75x_height#*slant-.5u#;
adjust_fit(serif_fit#,0);
numeric left_stem,right_curve,middle_weight;
left_stem=stem-hround 2stem_corr; middle_weight=.6vair+.5;
pickup tiny.nib; pos1(left_stem,0); pos2(left_stem,0);
lft x1l=lft x2l=hround(2.5u-.5left_stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % left stem
pos3(stem,0); pos4(stem,0); x3=x4=w-x1; top y3=h; bot y4=0;
penpos5(.75vair,90); penpos6(.75vair,90); penpos7(right_curve,0);
penpos8(.75vair,-90); penpos9(.75vair,-90);
z9r=bot z2; y8=y9; y7=.5[y8,y6]; y5=y6=.52h;
x6=x8; x5=x1; x6ltop:=x6-.25u; x8l:=x8l-.5u;
x7r=if serifs: tiny.lft x3l-jut; else: 8.5u; fi
if serifs: right_curve=curve-stem_corr; x6=.5[x1,w-4.5u];
else: right_curve=curve-3stem_corr; x6=.5[x1,w-5.2u]; 
x6l:=x6l-.5u; fi
fill stroke z5e..super_arc.e(6,7) & super_arc.e(7,8)..z9e;  % lower lobe
filldraw stroke z3e--z4e; % right stem
if serifs: dish_serif(1,2,a,1/3,jut,b,1/3,jut);  % upper left serif
nodish_serif(2,1,c,1/3,jut,d,1/3,.5jut);  % lower left serif
dish_serif(3,4,e,1/3,1.05jut,f,1/3,1.05jut);  % upper right serif
dish_serif(4,3,g,1/3,1.05jut,h,1/3,1.05jut); fi   % lower right serif
penlabels(1,2,3,4,5,6,7,8,9); endchar;

cmchar "The cyrillic letter soft_sign";
beginchar(CYR_soft_sign,9u#,x_height#,0);
italcorr .75x_height#*slant-.5u#;
adjust_fit(serif_fit#,0);
numeric left_stem,right_curve,middle_weight;
left_stem=stem-hround 2stem_corr; middle_weight=.6vair+.5;
pickup tiny.nib; pos1(left_stem,0); pos2(left_stem,0);
lft x1l=lft x2l=hround(2.5u-.5left_stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
penpos5(.75vair,90); penpos6(.75vair,90); penpos7(right_curve,0);
penpos8(.75vair,-90); penpos9(.75vair,-90);
z9r=bot z2; y8=y9; y7=.5[y8,y6]; y5=y6=.52h;
x6=x8; x5=x1; x6l:=x6-.25u; x7r=hround(w-.5u); x8l:=x8l-.5u;
if serifs: right_curve=curve-stem_corr; x6=.5[x1,w-u];
else: right_curve=curve-3stem_corr; x6=.5[x1,w-1.2u];
x6l:=x6l-.5u; fi
fill stroke z5e..super_arc.e(6,7) & super_arc.e(7,8)..z9e;  % lower lobe
if serifs: dish_serif(1,2,a,1/3,jut,b,1/3,jut);  % upper serif
nodish_serif(2,1,c,1/3,jut,d,1/3,.5jut); fi  % lower serif
penlabels(1,2,3,4,5,6,7,8,9); endchar;

cmchar "The cyrillic letter e";
beginchar(CYR_e,8u#,x_height#,0);
italcorr x_height#*slant-.2u#;
adjust_fit(if monospace: .5u#,.5u# else: 0,0 fi);
pickup fine.nib;
pos2(cap_band,90); pos4(vair',270); pos3(curve,0); 
x2=x4=.5(w-u); top y2r=h+oo; bot y4r=-oo;
rt x3r=w-hround min(.6u,1.35u-.5curve); y3=.5h;
if serifs: pos1(hair,180);  
 lft x1r=u;  bot y1=min(vround .7h,bot y2l-eps); 
 pos5(hair,180); lft x5r=hround(.5u);
 y5=max(good.y(.5bar_height-.9),y4l+vair');
 (x,y4l)=whatever[z4r,z5l]; x4l:=max(x,x4l-.5u);
 filldraw stroke z1e{up}
  ..pulled_super_arc.e(2,3)(superpull)%(.7superpull)
  & pulled_super_arc.e(3,4)(superpull)%(.5superpull)
  ..tension .9 and 1..{x5-x4,5(y5-y4)}z5e;  % arc and lower terminal
 pos6(.3[fine.breadth,hair],180); x6r=x1r; top y6=h+o;
 x1'-x1r=1.5curve-fine; y1'=y1;
 path upper_arc; upper_arc=z1{x1-x2,10(y2-y1)}..z2{right};
 numeric t; t=xpart(upper_arc intersectiontimes (z6l--z1'));
 filldraw z1r--z6r--z6l--subpath(t,0) of upper_arc--cycle; % barb
else: pos1(4/7[vair',flare],110);
 lft x1r=hround(.6u); 
 top y1r=vround .82[bar_height,top y2r];
 filldraw stroke term.e(2,1,left,.8,4);  % upper terminal
 pos5(.6[vair',flare],265); lft x5r=hround(.5u);
 y5r=good.y(y5r+1/3bar_height-y5); y5l:=good.y y5l; x5l:=good.x x5l;
 forsuffixes e=l,r: path p.e; p.e=z4e{left}..tension .9 and 1..z5e;
  if angle direction 1 of p.e<105:
   p.e:=z4e{left}..tension atleast.9 and 1..{dir 105}z5e; fi endfor
 filldraw stroke pulled_super_arc.e(2,3)(.5superpull)
  & pulled_super_arc.e(3,4)(.7superpull) & p.e; fi  % arc and lower terminal
penpos7(bar,90); penpos8(bar,90);
x7=lft x3l; x8=.5w-1.5u;
y7=y8=.5h;
fill stroke z7e--z8e;  % bar
penlabels(0,1,2,3,4,5); endchar;

cmchar "The cyrillic letter yu";
beginchar(CYR_yu,13.5u#,x_height#,0);
italcorr x_height#*slant-serif_fit#+jut#-2.5u#+min(.5stem#,u#);
adjust_fit(serif_fit#,if monospace: .5u# else: 0 fi);
pickup tiny.nib; pos1(stem,0); pos2(stem,0);
lft x1l=lft x2l=hround(2.5u-.5stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % left stem
penpos5(vair,90); penpos7(vair',-90);
penpos6(curve,180); penpos8(curve,0);
x5=x7=.5[x6,x8]; y5r=h+oo; y7r=-oo; 
x8r=hround(w-.5u); x6r=hround(w-8.5u);
y6=y8=.5h-vair_corr; y6l:=y8l:=.52h;
penstroke pulled_arc.e(5,6) & pulled_arc.e(6,7)
 & pulled_arc.e(7,8) & pulled_arc.e(8,5) & cycle;  % bowl
penpos3(bar,90); penpos4(bar,90); x3=x1; x4=x6; y3=y4=.52h;
fill stroke z3e--z4e;  % bar
if serifs: numeric inner_jut; inner_jut=jut;
 dish_serif(1,2,a,1/3,jut,b,1/3,inner_jut);  % upper left serif
 dish_serif(2,1,c,1/3,jut,d,1/3,inner_jut); fi  % lower left serif
penlabels(1,2,3,4,5,6,7,8); endchar;

cmchar "The cyrillic letter ya";
beginchar(CYR_ya,8u#+.5max(2u#,curve#),x_height#,0);
italcorr .75cap_height#*slant- if serifs: 1.75 else: .5 fi\\ u#;
adjust_fit(0,serif_fit#);
pickup tiny.nib; pos1(stem',0); pos2(stem',0);
rt x1r=rt x2r=w-hround(2.5u-.5stem'); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
penpos3(.75vair,90); penpos4(.75vair,90);
penpos5(curve if hefty:-3stem_corr fi,180);
penpos6(vair,-90); penpos7(vair,-90);
z3r=top z1; y4=y3; y5=.5[y4l,y6l]; y6=y7; x7=x2; y7=.5h; x4=x6;
if serifs: x4=.5w+.5u; x5r=hround(1.5u);
else: x4=.5w; x5r=hround(.75u); fi
x4l:=x6l:=x4+.125curve;
fill stroke z3e..pulled_arc.e(4,5) & pulled_arc.e(5,6)..z7e;  % lobe
pos6'(curve,0); pos8(curve,0); x6'r=x6l; y6'=y6;
tiny.lft x8l=.5u+.5jut; bot y8=0;
filldraw stroke z6'e--z8e; % diagonal stem
if serifs: numeric inner_jut;
 if rt x8r+u+1<=lft x2l-jut: inner_jut=jut;
 else: lft x2l-u-1=rt x8r+inner_jut; fi
 nodish_serif(1,2,a,1/3,.5jut,b,1/3,jut);  % upper serif
 dish_serif(2,1,c,1/3,inner_jut,d,1/3,jut);  % lower serif
 serif(8,6',e,1/3,-.5jut); fi  % lower diagonal serif
penlabels(1,2,3,4,5,6,7,8); endchar;
