%% filename: cyrilu.mf
%% version: 2.2
%% date: 1995/01/04
%%
%% American Mathematical Society
%% Technical Support
%% Publications Technical Group
%% 201 Charles Street
%% Providence, RI 02904
%% USA
%% tel: (401) 455-4080
%%      (800) 321-4267 (USA and Canada only)
%% fax: (401) 331-3842
%% email: tech-support@ams.org
%%
%% Copyright 1995 Humanities and Arts Computing Center, University of
%% Washington.
%%
%% Unlimited copying and redistribution of this file are permitted as
%% long as this file is not modified.  Modifications, and distribution
%% of modified versions, are permitted, but only if the resulting file
%% is renamed.
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  This file contains definitions of letters that have the same shapes in
%  both upper and lower case.

cmchar "The Russian letter TSE";
beginchar("C",13u#+width_adj#,cap_height#,0);
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
pos3(cap_stem,0); pos4(cap_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5cap_stem); 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
if serifs: numeric inner_jut;
  if rt x1r+cap_jut+.5u+1<=lft x3l-cap_jut: inner_jut=cap_jut;
  else: rt x1r+inner_jut+.5u+1=lft x3l-inner_jut; fi
  dish_serif(1,2,a,1/3,cap_jut,b,1/3,inner_jut);  % upper left serif
  dish_serif(3,4,e,1/3,inner_jut,f,1/3,cap_jut);  % upper left serif
  inner_jut:=.5(x3l-x1r);
  nodish_serif(2,1,c,1/3,cap_jut,d,1/3,inner_jut); % lower left serif
  r_cyr_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut);   % lower left serif
else: 
  lcyrsanserif(4); lft x2'= lft x2l; bot y2'l=0; pos2'(slab,90);
  rt x4'=rt x4r; y4'=y2'; pos4'(slab,90); filldraw stroke z2'e--z4'e;
fi
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6); endchar;

cmchar "The Russian letter DE";
beginchar("D",13u#,cap_height#,0);
adjust_fit(.25u#,.75u#);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
lft x1l=lft x2l=hround(w-3u); top y1=h; bot y2=0;
x3=u+.75cap_jut; bot y3l=0; pos3(cap_hair,90); lft x3'l=x3l; bot y3'=0; 
if serifs: pos3'(1.5cap_hair,0); else: pos3'(cap_hair,0); fi
x5=.42[x3,x1]; top y5=h; 
if serifs: pos5(1.5cap_hair,0); else: pos5(cap_hair,0);  fi
filldraw stroke z1e--z2e;
filldraw stroke z3'e{z1-z3}...{up}z5e;
bot y4l=0; x4=x2r; pos4(cap_hair,90);
%filldraw stroke z3e--z4e;
pickup crisp.nib; 
top y6=h;  x6-.75cap_jut=rt x1r; pos6(slab,90);
x9=x5; y9r=0; pos9(cap_hair,90);
if serifs:
  numeric inner_jut;
  inner_jut=.5(x1-x5);
  nodish_serif(5,9,aa,1/3,cap_jut,b,1/3,inner_jut);  % upper left serif
  nodish_serif(1,2,ae,1/3,inner_jut,f,1/3,cap_jut);  % upper right serif
  inner_jut:=.5(x2-x3);
  l_cyr_serif(3',1,ac,1/3,cap_jut,d,1/3,inner_jut); % lower left serif
  r_cyr_serif(2,1,ag,1/3,inner_jut,h,1/3,cap_jut);   % lower right serif
else:
  cyrsanserif(3'); lcyrsanserif(2);
  x5'=lft x5l; top y5'=h; pos5'(slab,90);
  filldraw stroke z3e--z4e; filldraw stroke z5'e--z6e;
fi
endchar;

cmchar "The Russian letter GHE (looks like Gamma)";
beginchar("G",11.5u#-width_adj#,cap_height#,0);
italcorr cap_height#*slant-beak_jut#-.25u#;
adjust_fit(cap_serif_fit#,0);
h:=vround(h-stem_corr);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5cap_stem); 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-beak)-eps;
arm(3,4,e,beak_darkness,beak_jut);  % upper arm and beak
pos5(cap_bar,-90); pos6(hair,0);
top y5l=vround(.5[y2,y1]+.5cap_bar); x5=x1;
pos0(cap_bar,90); pos7(hair,0);
z0=z5; x6=x7; y6-y5l=y0l-y7;
if serifs: rt x6r=hround(w-4u+.5hair); y6=good.y(y5l+.6beak)+eps;
  rt x9r=hround(w-.5u);
else: rt x6r=hround(w-1.5u); y6=y5l+eps; rt x9r=hround(w-.75u);
fi
%arm(5,6,f,beak_darkness,0); arm(0,7,g,beak_darkness,0);  % middle arm and serif
if serifs: nodish_serif(1,2,a,1/3,cap_jut,b,1/3,.5cap_jut);  % upper serif
  dish_serif(2,1,c,1/3,cap_jut,d,1/3,1.25cap_jut);  % lower serif
fi
math_fit(0,ic#-2.5u#); penlabels(0,1,2,3,4,5,6,7,8,9); endchar;

cmchar "The Russian letter KHA (looks like X)";
beginchar("H",13u#,cap_height#,0);
italcorr cap_height#*slant-.25u#;
adjust_fit(cap_serif_fit#,cap_serif_fit#);
numeric stem[],outer_jut,xjut,alpha[];
stem1=cap_stem-2stem_corr; stem2=min(cap_hair,stem1);
outer_jut=.75cap_jut; xjut= if serifs: (stem1-stem2)/4 else: 0 fi;
x1l=l+letter_fit+.5u+outer_jut; x2r=r-letter_fit-u-outer_jut-xjut;
x3l=l+letter_fit+.25u+outer_jut+xjut; x4r=r-letter_fit-.25u-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$'=.1[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;  % right diagonal
fi
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+cap_jut+.5u+1<=lft x2'l-cap_jut-xjut: inner_jut1=cap_jut;
  else: rt x1'r+inner_jut1+.5u+1=lft x2'l-inner_jut1-xjut; fi
  if rt x3'r+cap_jut+.5u+1<=lft x4'l-cap_jut-xjut: inner_jut2=cap_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);  % lower left serif
fi
math_fit(0,.5ic#); penlabels(0,1,2,3,4,12,13,24,34); endchar;

cmchar "The Russian letter I (looks like backwards N)";
beginchar("I",14u#+width_adj#,cap_height#,0);
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
pos3(cap_stem,0); pos4(cap_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5cap_stem); 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
if serifs: penpos5(.85cap_stem,90); penpos6(.85cap_stem,90);
else: penpos5(cap_stem,90); penpos6(cap_stem,90);
fi
x5=x1r; x6=x3l; if serifs: y5=.1h; y6=.9h; else: bot y5l=0; top y6r=h; fi
fill stroke z5e--z6e;  % bar
if serifs: numeric inner_jut;
  if rt x1r+cap_jut+.5u+1<=lft x3l-cap_jut: inner_jut=cap_jut;
  else: rt x1r+inner_jut+.5u+1=lft x3l-inner_jut; fi
  dish_serif(1,2,a,1/3,cap_jut,b,1/3,inner_jut);  % upper left serif
  dish_serif(2,1,c,1/3,cap_jut,d,1/3,inner_jut); % lower left serif
  dish_serif(3,4,e,1/3,inner_jut,f,1/3,cap_jut);  % upper left serif
  dish_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut);  % lower left serif
fi
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6); endchar;

%  The letter "K" is the last character defined in this file.
%  See below for comments.

cmchar "The Russian letter EL";
beginchar("L",13u#,cap_height#,0);
adjust_fit(0,1.5u#);
numeric ldot_size; ldot_size=1.15flare;
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
lft x1l=lft x2l=hround(w-3u); top y1=h; bot y2=0;
filldraw stroke z1e--z2e;
if serifs:
  numeric inner_jut; inner_jut=.5(x1-x5);
  x4=u+.5ldot_size; x3=x4+.5ldot_size; bot y3r=0; pos3(1.5cap_hair,-90); 
  x5=.42[x4,x1]; top y5=h; pos5(1.5cap_hair,0); pos4(ldot_size,-180);
  pos10(hair,-180);
  filldraw stroke z3e{right}...{up}z5e;
  y4=ldot_size; bulb(3,10,4);
  dish_serif(2,1,a,1/3,cap_jut,b,1/3,cap_jut);
  nodish_serif(1,2,c,1/3,inner_jut,d,1/3,cap_jut);
  top y6=h;  x6-.75cap_jut=rt x1r; pos6(slab,90);
  x5'+.5cap_jut=lft x5l; top y5'=h; pos5'(slab,90);
  x9=x5; y9=0; pos9(cap_hair,0);
  nodish_serif(5,9,aa,1/3,cap_jut,ab,1/3,inner_jut);  % upper left serif
else:
  x5r=hround u; bot y5r=vround(.06h-o); bot y4r=-o; x4r=.35[x5,x3r];
  x3=x5+3flare; top y3=h; lft x3'=lft x3l; top y3'r=h; rt x1'r=rt x1r;
  top y1'r=h; pos3'(slab,90); pos1'(slab,90); pos5(flare,-120); pos4(vair,-90);
  pos3(hair,0);
  filldraw stroke z5e...{right}z4e...{up}z3e;
  filldraw stroke z3'e--z1'e;
fi
endchar;

cmchar "The Russian letter EM";
beginchar("M",16u#+width_adj#,cap_height#,0);
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
numeric stem[]; % thicknesses of the four strokes
stem1=hround(fudged.hair+stem_corr);
stem2=hround(fudged.cap_stem-4stem_corr);
stem3=hround(fudged.hair-stem_corr);
stem4=hround(fudged.cap_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 min(w-2u,w-3u+.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;
if hefty: y6=if monospace: vround 1/3h else: o fi;
 numeric upper_notch,lower_notch;
 upper_notch=h-cap_notch_cut; lower_notch=y6+cap_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,-cap_jut);  % upper left serif
 dish_serif(2,1,b,1/2,cap_jut,c,1/2,cap_jut)(dark); % lower left serif
 serif(3,4,d,1/3,cap_jut); %  upper right serif
 dish_serif(4,3,e,1/3,cap_jut,f,1/3,cap_jut); fi  % lower right serif
math_fit(0,max(.5ic#-.5u#,0));
penlabels(0,1,1',2,3,3',4,5,6,7,8); endchar;

cmchar "The Russian letter EN (looks like H)";
beginchar("N",13u#+width_adj#,cap_height#,0);
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
pos3(cap_stem,0); pos4(cap_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5cap_stem); 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(cap_bar,90); penpos6(cap_bar,90);
x5=x1; x6=x3; y5=y6=.52h;
fill stroke z5e--z6e;  % bar
if serifs: numeric inner_jut;
 if rt x1r+cap_jut+.5u+1<=lft x3l-cap_jut: inner_jut=cap_jut;
 else: rt x1r+inner_jut+.5u+1=lft x3l-inner_jut; fi
 dish_serif(1,2,a,1/3,cap_jut,b,1/3,inner_jut);  % upper left serif
 dish_serif(2,1,c,1/3,cap_jut,d,1/3,inner_jut); % lower left serif
 dish_serif(3,4,e,1/3,inner_jut,f,1/3,cap_jut);  % upper left serif
 dish_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut); fi  % lower left serif
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6); endchar;

cmchar "The Russian letter PE (looks like PI)";
beginchar("P",13u#+width_adj#,cap_height#,0);
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
pos3(cap_stem,0); pos4(cap_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5cap_stem); 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
if serifs: numeric inner_jut;
 if rt x1r+cap_jut+.5u+1<=lft x3l-cap_jut: inner_jut=cap_jut;
 else: rt x1r+inner_jut+.5u+1=lft x3l-inner_jut; fi
 dish_serif(2,1,c,1/3,cap_jut,d,1/3,inner_jut); % lower left serif
 dish_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut);   % lower left serif
 inner_jut:=.5(x3l-x1r);
 nodish_serif(1,2,a,1/3,cap_jut,b,1/3,inner_jut);  % upper left serif
 nodish_serif(3,4,e,1/3,inner_jut,f,1/3,cap_jut);  % upper left serif
else:
 lft x1'= lft x1l; top y1'r=h; pos1'(slab,90);
 rt x3'=rt x3r; y3'=y1'; pos3'(slab,90); filldraw stroke z1'e--z3'e;
fi
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6); endchar;

cmchar "The Russian letter CHE";
beginchar("Q",14u#+width_adj#,cap_height#,0);
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
pos3(cap_stem,0); pos4(cap_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5cap_stem); x3=x4=w-x1;
top y1=top y3=h; %bot y2=x_height; 
bot y4=0;
x22=x3; y22=.65h; %x_height-.25bar_height; 
pos22(cap_bar,90); y2=y22;
filldraw stroke z1e--z2e{down}...{1,2}z22e; % left stem and bowl
filldraw stroke z3e--z4e; % right stem
if serifs: numeric inner_jut;
 if rt x1r+cap_jut+.5u+1<=lft x3l-cap_jut: inner_jut=cap_jut;
 else: rt x1r+inner_jut+.5u+1=lft x3l-inner_jut; fi
 dish_serif(1,2,a,1/3,cap_jut,b,1/3,inner_jut);  % upper left serif
% dish_serif(2,1,c,1/3,cap_jut,d,1/3,inner_jut); % lower left serif
 dish_serif(3,4,e,1/3,inner_jut,f,1/3,cap_jut);  % upper left serif
 dish_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut); fi  % lower left serif
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6); endchar;

cmchar "The Russian letter TE";
beginchar("T",13u#-width_adj#,cap_height#,0);
italcorr cap_height#*slant-beak_jut#-.25u#;
adjust_fit(0,0);
h:=vround(h-2stem_corr);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
lft x1l=lft x2l=hround(.5w-.5cap_stem); 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-beak)-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.414cap_jut,d,1/3,1.414cap_jut);  % lower serif
 nodish_serif(1,2,a,1/3,.5cap_jut,b,1/3,.5cap_jut); fi  % upper bracketing
math_fit(-.75cap_height#*slant,ic#-2.5u#); penlabels(1,2,3,4,5,6); endchar;

cmchar "The Russian letter VE (looks like B)";
beginchar("V",12.5u#,cap_height#,0);
italcorr .75cap_height#*slant-.5u#;
adjust_fit(cap_serif_fit#,0);
numeric left_stem,right_curve,middle_weight;
left_stem=cap_stem-hround 2stem_corr; middle_weight=.6vair+.5;
pickup tiny.nib; pos1(left_stem,0); pos2(left_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5left_stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
penpos3(cap_band,90); penpos4(cap_band,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(cap_band,-90); penpos12(cap_band,-90);
z3r=top z1; y4=y3; y5=.5[y4,y6]; y6=y7; y7l-y8l=vair;
z12r=bot z2; y11=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-1.5u); x10r=hround(w-u);
if serifs: right_curve=cap_curve-stem_corr; x4=.5[x1,w-1.5u];
else: right_curve=cap_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,cap_jut,b,1/3,.5cap_jut);  % upper serif
 nodish_serif(2,1,c,1/3,cap_jut,d,1/3,.5cap_jut); fi  % lower serif
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6,7,8,9,10,11,12); endchar;

cmchar "The Russian letter SHCHA";
beginchar("W",19u#+width_adj#,cap_height#,0);
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
pos3(cap_stem,0); pos4(cap_stem,0); pos5(cap_stem,0); pos6(cap_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5cap_stem); x3=x4=w-x1;
top y1=top y3=h; bot y2=bot y4=0;
z5=.5[z1,z3]; z6=.5[z2,z4];
filldraw stroke z1e--z2e; % left stem
filldraw stroke z3e--z4e; % right stem
filldraw stroke z5e--z6e; % center stem
if serifs: numeric inner_jut;
 if rt x1r+cap_jut+.5u+1<=lft x5l-cap_jut: inner_jut=cap_jut;
 else: rt x1r+inner_jut+.5u+1=lft x5l-inner_jut; fi
 dish_serif(1,2,a,1/3,cap_jut,b,1/3,inner_jut);  % upper left serif
 dish_serif(3,4,e,1/3,inner_jut,f,1/3,cap_jut);  % upper right serif
 dish_serif(5,6,i,1/3,inner_jut,j,1/3,inner_jut); % upper center serif
 inner_jut:=.5(x3l-x5r);
 nodish_serif(2,1,c,1/3,cap_jut,d,1/3,inner_jut); % lower left serif
 nodish_serif(6,5,k,1/3,inner_jut,m,1/3,inner_jut); % lower center serif
 r_cyr_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut);   % lower right serif
else:
 lcyrsanserif(4); lft x2'= lft x2l; bot y2'l=0; pos2'(slab,90);
 rt x4'=rt x4r; y4'=y2'; pos4'(slab,90); filldraw stroke z2'e--z4'e;
fi
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6); endchar;

cmchar "The Russian letter SHA";
beginchar("X",19u#+width_adj#,cap_height#,0);
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
pos3(cap_stem,0); pos4(cap_stem,0); pos5(cap_stem,0); pos6(cap_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5cap_stem); x3=x4=w-x1;
top y1=top y3=h; bot y2=bot y4=0;
z5=.5[z1,z3]; z6=.5[z2,z4];
filldraw stroke z1e--z2e; % left stem
filldraw stroke z3e--z4e; % right stem
filldraw stroke z5e--z6e; % center stem
if serifs: numeric inner_jut;
 if rt x1r+cap_jut+.5u+1<=lft x5l-cap_jut: inner_jut=cap_jut;
 else: rt x1r+inner_jut+.5u+1=lft x5l-inner_jut; fi
 dish_serif(1,2,a,1/3,cap_jut,b,1/3,inner_jut);  % upper left serif
 dish_serif(3,4,e,1/3,inner_jut,f,1/3,cap_jut);  % upper right serif
 dish_serif(5,6,i,1/3,inner_jut,j,1/3,inner_jut); % upper center serif
 inner_jut:=.5(x3l-x5r);
 nodish_serif(2,1,c,1/3,cap_jut,d,1/3,inner_jut); % lower left serif
 nodish_serif(6,5,k,1/3,inner_jut,m,1/3,inner_jut); % lower center serif
 nodish_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut);   % lower right serif
else:
 lft x2'= lft x2l; bot y2'l=0; pos2'(slab,90);
 rt x4'=rt x4r; y4'=y2'; pos4'(slab,90); filldraw stroke z2'e--z4'e;
fi
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6); endchar;

cmchar "The Russian letter ERY";
beginchar("Y",12.5u#,cap_height#,0);
italcorr .75cap_height#*slant-.5u#;
adjust_fit(cap_serif_fit#,if serifs: 5u# else: 4.25u# fi);
numeric left_stem,right_curve,middle_weight;
left_stem=cap_stem-hround 2stem_corr; middle_weight=.6vair+.5;
pickup tiny.nib; pos1(left_stem,0); pos2(left_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5left_stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
penpos3(cap_band,90); penpos4(cap_band,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(cap_band,-90); penpos12(cap_band,-90);
z3r=top z1; y4=y3; y5=.5[y4,y6]; y6=y7; y7l-y8l=vair;
z12r=bot z2; y11=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-1.5u); x10r=hround(w-u);
if serifs: right_curve=cap_curve-stem_corr; x4=.5[x1,w-1.5u];
else: right_curve=cap_curve-3stem_corr; x4=.5[x1,w-2.5u];
 x4l:=x4l-.5u; x9l:=x9l-.5u; fi
x6l:=x6l-.5u; x11l:=x11l-.5u;
fill stroke z8e..super_arc.e(9,10) & super_arc.e(10,11)..z12e;  % lower lobe
if serifs: dish_serif(1,2,a,1/3,cap_jut,b,1/3,cap_jut);  % upper serif
 nodish_serif(2,1,c,1/3,cap_jut,d,1/3,.5cap_jut); fi  % lower serif
pickup tiny.nib;
x80=x81=w if serifs: +2u else: +1.25u fi; top y80=h; bot y81=0; pos80(cap_stem,0); pos81(cap_stem,0);
filldraw stroke z80e--z81e;
if serifs: 
  dish_serif(80,81,e,1/3,cap_jut,f,1/3,cap_jut);
  dish_serif(81,80,g,1/3,cap_jut,h,1/3,cap_jut); 
fi  
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6,7,8,9,10,11,12); endchar;

cmchar "The Russian letter ZE (looks like numeral 3)";
beginchar("Z",11u#,cap_height#,0);
italcorr cap_height#*slant-.5u#;
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)-eps;
pos8(bot_thickness,-90); bot y8r=-o;
y3=.6[top y4l,bot y2l]; y7=.5[bot y6l,top y8l];
top y5l=vround(.54h+.5vair); y5r=y6l;
x4=1/3[x5,x3l]; z4=z5+whatever*(150u,h);
lft x1r=hround 1.25u; y1=.8h;
if serifs: pos1(cap_hair,180); pos9(cap_hair,-180); else: pos1(1.5cap_hair,135); pos9(1.5cap_hair,-135); fi
 lft x9r=hround .75u; y9=.2h;
filldraw stroke z1e{x2-x1,10(y2-y1)}...{right}z2e & 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)
 & z8e{left}....{up}z9e;  % lower bowl %this line added for changing bulb to barb
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(.9h-.5bulb_diam1,.75h+.5bulb_diam1);
 % bulb(2,1,0);  % upper bulb
 %pos10(bulb_diam2,-180); 
 % bulb(8,9,10);  % lower bulb
% barbs on end of strokes
 path upper_arc; upper_arc=z1{x2-x1,10(y2-y1)}..{right}z2;
 path lower_arc; lower_arc=z8{left}....{up}z9;
 pos20(hair,0); x20r=x1l; top y20=top y2r; x1'-x1l=1.6cap_curve; y1'=y1;
 numeric t; t=xpart(upper_arc intersectiontimes (z20r--z1'));
 filldraw z1r--z20l--z20r--subpath(t,0) of upper_arc--cycle;
 pos30(hair,0); x30r=x9l; bot y30=bot y8r; x9'-x9l=1.6cap_curve; y9'=y9;
 t:=xpart(lower_arc intersectiontimes (z30r--z9'));
 filldraw z9r--z30l--z30r--subpath(t,1) of lower_arc--cycle;
%else: %pos1(.5[vair,flare],angle(-8u,h));
 %lft x1r=hround u; bot y1l=vround .75h+o;
 %y1r:=good.y y1r+eps; x1l:=good.x x1l;
 %pos9(bot_thickness,angle(-2u,-h));
 %lft x9r=hround .75u; top y9l=vround .25h-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 "The Russian letter Soft Sign";
beginchar(oct"136",12.5u#,cap_height#,0);
italcorr .75cap_height#*slant-.5u#;
adjust_fit(cap_serif_fit#,0);
numeric left_stem,right_curve,middle_weight;
left_stem=cap_stem-hround 2stem_corr; middle_weight=.6vair+.5;
pickup tiny.nib; pos1(left_stem,0); pos2(left_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5left_stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
penpos3(cap_band,90); penpos4(cap_band,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(cap_band,-90); penpos12(cap_band,-90);
z3r=top z1; y4=y3; y5=.5[y4,y6]; y6=y7; y7l-y8l=vair;
z12r=bot z2; y11=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-1.5u); x10r=hround(w-u);
if serifs: right_curve=cap_curve-stem_corr; x4=.5[x1,w-1.5u];
else: right_curve=cap_curve-3stem_corr; x4=.5[x1,w-2.5u];
 x4l:=x4l-.5u; x9l:=x9l-.5u; fi
x6l:=x6l-.5u; x11l:=x11l-.5u;
fill stroke z8e..super_arc.e(9,10) & super_arc.e(10,11)..z12e;  % lower lobe
if serifs: dish_serif(1,2,a,1/3,cap_jut,b,1/3,cap_jut);  % upper serif
 nodish_serif(2,1,c,1/3,cap_jut,d,1/3,.5cap_jut); fi  % lower serif
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6,7,8,9,10,11,12); endchar;

cmchar "The Russian letter Hard Sign";
beginchar(oct"137",12.5u#,cap_height#,0);
italcorr .75cap_height#*slant-.5u#;
adjust_fit(if serifs: 4 else: 2 fi u#+cap_serif_fit#,0);
numeric left_stem,right_curve,middle_weight;
left_stem=cap_stem-hround 2stem_corr; middle_weight=.6vair+.5;
pickup tiny.nib; pos1(left_stem,0); pos2(left_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5left_stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
penpos3(cap_band,90); penpos4(cap_band,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(cap_band,-90); penpos12(cap_band,-90);
z3r=top z1; y4=y3; y5=.5[y4,y6]; y6=y7; y7l-y8l=vair;
z12r=bot z2; y11=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-1.5u); x10r=hround(w-u);
if serifs: right_curve=cap_curve-stem_corr; x4=.5[x1,w-1.5u];
else: right_curve=cap_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,.5cap_jut,b,1/3,.5cap_jut);  % upper serif
 nodish_serif(2,1,c,1/3,cap_jut,d,1/3,.5cap_jut); fi  % lower serif
pickup crisp.nib;
top y55r=h; x55=x1; pos55(slab,90); pos56(hair,180); x56=x1-if serifs: 6 else: 3 fi u; 
y56=good.y(y55l-beak)-eps;
arm(55,56,q,beak_darkness**.8,-.4beak_jut);
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6,7,8,9,10,11,12); endchar;

%  The shape "K" is saved as a picture, to be used by the next file input.
%  It is defined here to minimize storage time.
cmchar "The Russian letter KA";
beginchar("K",12u#,cap_height#,0);
italcorr cap_height#*slant-.5u#;
adjust_fit(0,.25u#);
pickup tiny.nib; pos1(fudged.cap_stem,0); pos2(fudged.cap_stem,0);
lft x1l=lft x2l=hround max(2u,3u-.5fudged.cap_stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
if serifs:  dish_serif(1,2,a,1/3,cap_jut,b,1/3,cap_jut); % upper stem serif
 dish_serif(2,1,c,1/3,cap_jut,d,1/3,cap_jut);  % lower stem serif
% pickup fine.nib; pos3(vair,90); x3=x1; y3=.55h; x3'=x3; y3'=y3+1; pos3'(slab,90);
 pickup fine.nib; pos3(vair,90); x3=x1; y3=.55h; z3'=z3; pos3'(varwid,90);
% pos4(vair,90); x4=w-2u; top y4r=h+oo;
 pos4(varwid,90); x4=w-.75flare-.125u; top y4r=h+oo; %original x4=w-2u
% filldraw stroke z3'e{right}..{right}z4e;  % upper diagonal
 x41=x4; y41=y3'; x42=x4-2u; y42=y4;
 filldraw stroke z3'e..controls z41 and z42..z4e;  % upper diagonal
 pos5(hair,0); pos6(flare,0);
 rt x5r=hround(w-.125u); y5+.5flare=vround(top y4r-hair)+1; %original bot y4l-.03h
 top y4'r=top y4r; x4'=x4; pos4'(hair,90);
 bulb(4',5,6); % bulb
% pos7(stem,0); pos8(vair,90); pos9(hair,180);
 pos7(stem,0); pos8(varwid,90); pos9(hair,180);
 x9+.5hair=hround(w+.5hair-eps); y9=1/3x_height;
 lft x7l=hround(w-2.75u-.5stem); y7=1/2y3; x8=w-1.2u; bot y8l=-oo;
 filldraw stroke z3e{right}...z7e{down}
 ...z8e{right}...{up}z9e;  % lower diagonal
else:
 numeric right_jut,stem[],alpha[];
 right_jut=.4tiny; 
 pickup tiny.nib; 
 stem2=max(tiny.breadth,fudged.cap_stem-3stem_corr);
 stem1=max(tiny.breadth,fudged.hair if hefty:-3stem_corr fi);
 top y3=h; rt x3r=hround(r-letter_fit-u-right_jut);
 bot y6=0; rt x6r=hround(r-letter_fit-.75u-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
%forsuffixes $=l,r: x5$:=x5$+.5u; y5$:=y5$-.5u; 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{right}..diag_end(4r,3'r,1,.5,3'l,4l)..{left}z4l--cycle;  % upper diagonal
 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
fi
picture K_pic; K_pic=currentpicture;
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6); endchar;
