%
% lgt2lou.mf
%
%% Cyrillic font container with T2 encoding beta-support
%
% This file is future part of lxfonts package
% Version 3.5 // Patchlevel=1
% (c) O.Lapko
%
% This package is freeware product under conditions similar to
% those of D. E. Knuth specified for the Computer Modern family of fonts.
% In particular, only the authors are entitled to modify this file
% (and all this package as well) and to save it under the same name.
%
% Content:
%
% Uppercase Cyrillic letters 0--127 for T2 encoding
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% List of letternames and their codes in T2
%
%                X2      T2A  T2B  T2C
%
% AE            "41  A   "8c   -    -    Ligature AE
% ABH_CH        "44  D    -    -   "91   Abkhasian che (same as lower e with hook)
% ABH_CH_dsc    "45  E    -    -   "92   Abkhasian che descender
% K_vcrs        "46  F   "8b   -    -    Ka vertically crossed
% K_hcrs        "47  G    -    -   "8b   Ka horisontally crossed
% L_dsc         "48  H    -   "8a  "8a   El with descender
% M_dsc         "4c  L    -    -   "88   Em with descender
% ABH_HA        "4e  N    -    -   "97   Abkhasian kha
% P_tl          "4f  O    -    -   "80   Pe with tail
%
% R_dsc         "50  P    -    -   "85   Er with descender
% LAT_Q         "51  Q    -    -    -    Latin letter Q
% T_dsc         "52  R    -    -   "82   Te with descender
% TETSE         "54  T    -    -   "81   Ligature Te-Tse
% CH_vcrs       "56  V   "97   -    -    Che vertically crossed
% LAT_W         "57  W    -    -    -    Latin letter W
%
% N_ltl         "1c       -    -   "99   En with left tail
% DELTA         "1e       -    "86  -    Delta
% M_tl           -        -    -   "8e   Em with tail
% R_gcrs         -        -    -   "86   Er grave crossed
% S_acrs         -        -    -   "91   Es acute crossed
% G_crsdsc       -        -   "80   -    Ghe crossed with descender
% H_hcrs         -        -   "94   -    Kha horisontally crossed
%
% SEMISN         -        -    -   "93   Semi Soft Sign
% I_shdsc        -        -    -   "94   I Short with descender
% R_tl           -        -    -   "9b   Er with tail
%

LHver_check(3,5); % like |version_check| in ec

lhchar "Uppercase Cyrillic letter AE - ligature AE";
cyrchar(AE,16u#,cap_height#,0);
if is_small_cap: getcharcode(ae); fi
italcorr cap_height#*slant-beak_jut#-.5u#;
adjust_fit(cap_serif_fit#,0);
numeric left_stem,amid_stem,outer_jut,alpha;
amid_stem=max(tiny.breadth,hround .9[mfudged.hair,mfudged.cap_stem]);
pickup tiny.nib; pos1(amid_stem,0); pos2(amid_stem,0);
lft x1l=lft x2l=hround(if monospace or hefty:.55 else:.5 fi\\w-.75u);
top y1=h; bot y2=0;
filldraw stroke z1e--z2e; % stem
pickup crisp.nib; pos3(slab,90); pos4(mfudged.hair,0);
top y3r=h; x3=x1; rt x4r=hround(w-u); y4=good.y(y3l-beak)-eps;
arm(3,4,e,beak_darkness,beak_jut);  % upper arm and beak
pos5(cap_bar,-90); pos6(mfudged.hair,0); x5=x1;
top y5l=vround(if hefty:.52 else:.48 fi\\[y2,y1]+.5cap_bar);
pos0(cap_bar,90); pos7(mfudged.hair,0);
z0=z5; x6=x7; y6-y5l=y0l-y7;
if serifs and not(monospace and hefty):
 rt x6r=hround(w-3.65u+.5mfudged.hair);
 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
pos8(slab if not serifs:+2stem_corr fi,-90);
pos9(mfudged.hair,0); bot y8r=0; x8=x2; y9=good.y(y8l+7/6beak)+eps;
arm(8,9,h,beak_darkness,1.5beak_jut);  % lower arm and beak
left_stem=if monospace:fudged.hair else: cap_hair fi if hefty: -3stem_corr fi;
outer_jut=.8cap_jut; x11l=l+letter_fit+outer_jut+.5u; y11=0;
x12=x1l-apex_corr-if monospace:2 fi\\u; y12=h;
alpha=diag_ratio(1,.5left_stem,y12-y11,x12-x11l);
penpos11(alpha*left_stem,0); penpos12(alpha*left_stem,0);
fill diag_end(12l,11l,1,1,11r,12r)
 --diag_end(11r,12r,1,1,12l,11l)--cycle; % diagonal
y10=h-slab; z10=whatever[z11,z12];
fill z10--(x1,y10)--(x1,h)--z12--cycle;  % link
penpos13(whatever,angle(z2-z1)); z13=whatever[z11,z12];
penpos14(cap_band,90); x14=x0; y13l=y14l; y13r=y14r;
if hefty: y14r=.4h; else: y14=y0; fi
penstroke z13e--z14e; % bar line
if serifs:
 numeric inner_jut;
 pickup tiny.nib;
 prime_points_inside(11,12);
 if rt x11'r+cap_jut+.5u+1<=lft x2l-.75cap_jut: inner_jut=cap_jut;
  else: rt x11'r+inner_jut+.5u+1=lft x2l-.75inner_jut; fi
 dish_serif(11',12,i,1/2,outer_jut,j,.6,inner_jut)(dark);  % lower left serif
 nodish_serif(1,2,a,1/3,cap_jut+x1l-x12,b,1/3,.5cap_jut);  % upper serif
 nodish_serif(2,1,c,1/3,.75inner_jut,d,1/3,.5cap_jut); fi  % lower middle serif
penlabels(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14); endchar;

lhchar "Uppercase Cyrillic letter ABH_CH - lower e hook";
cyrchar(ABH_CH,(11.25u#+max(.75u#,.5cap_curve#)),
 cap_height#,0);
if is_small_cap: getcharcode(abh_ch); fi
italcorr .7cap_height#*slant-.4u#; %O+.1u
adjust_fit(1.5dot_size#-tiny# %if serifs:max(1.5u,u#+.5flare#)
 if monospace: +\\1.25u#,-.25u#+ else:,fi\\ 0);
%large_e;`large e' shape (ecfonts)
numeric left_curve,right_curve;
left_curve=right_curve+3stem_corr=cap_curve if not serifs: -1.5stem_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 .52h; top y2r=h+o; y0l=bot y1; x2=.5w+.25u;
rt x1r=hround min(w-.5u,w-u+.5right_curve);
lft x3r=hround max(.75u,1.5u-.5left_curve); %lower_e+.25u
{{interim superness:=more_super;
 filldraw stroke super_arc.e(1,2)}};  % right bowl
y3=.5[y2,y4]; bot y4r=-o; 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+7/8[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
% bulb
if serifs: pickup crisp.nib; fi
pos6(max(currentbreadth+eps,7/8[thin_join,vair']),-90);
x6=x3; bot y6r=y0l;
lft x7r=min(l+letter_fit+hround(.5u-.5),lft x0l-flare-1); y7=.5[y1,y2];
if serifs:
 pos7(hair,-180); pos8(flare+(cap_stem-stem),-180); z8r=z7r;
 {{less_tense; cyrbulb(6,7,8)}};
else:
 pos7(hair,-150);
 filldraw stroke z6e{left}...{dir60}z7e; fi
%%%%%
penlabels(0,1,2,3,4,5,6,7,8, 9,10,11,12,13); endchar;

lhchar "Uppercase Cyrillic letter ABH_CH_dsc - lower e hook ogonek";
cyrchar(ABH_CH_dsc,(11.25u#+max(.75u#,.5cap_curve#)),
 cap_height#,desc_depth#);
if is_small_cap: getcharcode(abh_ch_dsc); fi
italcorr .7cap_height#*slant-.4u#; %O+.1u
adjust_fit(1.5dot_size#-tiny# %if serifs:max(1.5u,u#+.5flare#)
 if monospace: +\\1.25u#,-.25u#+ else:,fi\\ 0);
%large_e;`large e' shape (ecfonts)
numeric left_curve,right_curve;
left_curve=right_curve+3stem_corr=cap_curve if not serifs: -1.5stem_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 .52h; top y2r=h+o; y0l=bot y1; x2=.5w+.25u;
rt x1r=hround min(w-.5u,w-u+.5right_curve);
lft x3r=hround max(.75u,1.5u-.5left_curve); %lower_e+.25u
{{interim superness:=more_super;
 filldraw stroke super_arc.e(1,2)}};  % right bowl
y3=.5[y2,y4]; bot y4r=-o; 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+7/8[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
% bulb
if serifs:
 pickup crisp.nib; fi
pos6(max(currentbreadth+eps,7/8[thin_join,vair']),-90);
x6=x3; bot y6r=y0l;
lft x7r=min(l+letter_fit+hround(.5u-.5),lft x0l-flare-1); y7=.5[y1,y2];
if serifs:
 pos7(hair,-180); pos8(flare+(cap_stem-stem),-180); z8r=z7r;
 {{less_tense; cyrbulb(6,7,8)}};
else:
 pos7(hair,-150);
 filldraw stroke z6e{left}...{dir60}z7e; fi
%%%%%
% descender-ogonek
 path p.r;
 p.r=if serifs: pulled_arc.r(3,4)...{x5-x4,5(y5-y4)}z5r
  else: term.r(4',5,right,1,4) fi;
 def the_pen=if known ogonek_pen: ogonek_pen
  elseif serifs: tiny elseif is_bold: fisp else: fine fi
 enddef;
 numeric tt; % the time...
 tt=if serifs: if hefty: 2.3 else: 2.15 fi else: % sansserif
  if is_bold: .3 else: .2 fi\\ fi;
 join_angle=angle((direction tt of p.r) rotated 180);
 ogonek_move=-o;
 ogonek_pos=(point tt of p.r)+.5(the_pen-if serifs: tiny else: fine fi)*
     unitvector((direction tt of p.r) rotated 90)-(ogonek_breadth-the_pen,0);
easy_ogonek(the_pen,9,10,11); % ogonek
penlabels(0,1,2,3,4,5,6,7,8, 9,10,11); endchar;

iff not concrete:%
iff not specific:%
lhchar "Uppercase Cyrillic letter K_vcrs - KA vcrossed (`roman')";
cyrchar(K_vcrs,15u# if not serifs:+.5width_adj# fi, % N_width+1.5u
 cap_height#,0);
if is_small_cap: getcharcode(k_vcrs); fi
italcorr cap_height#*slant-.5u#; %K
adjust_fit(cap_serif_fit#,cap_serif_fit#);
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); fi % lower stem serif
% Kv_rbowl;
 pos10(fudged.cap_stem,0);
 numeric right_jut,stem[],alpha[];
 right_jut=if serifs:.6cap_jut else:.4tiny fi; pickup tiny.nib;
%
 stem1=max(tiny.breadth,fudged.hair if hefty:-3stem_corr fi);
 stem2=max(tiny.breadth,fudged.cap_stem-3stem_corr);
 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=x10; y4=1/3h; y10=y1; x10=hround max(w-11.5u,w-10.5u-.5fudged.cap_stem);
 penpos3(alpha1*(stem1-tiny),0); penpos4(whatever,-90);
 alpha1=diag_ratio(1,.5(stem1-tiny),y3-y4,x3r-x4);
 penpos6(alpha2*(stem2-tiny),0);
 alpha2=diag_ratio(1,.5(stem2-tiny),y10-y6,x6r-x10);
 forsuffixes $=l,r: y3'$=h; y6'$=0; z4$=z3'$+whatever*(z3-z4);
  z5$=z6'$+whatever*(z10-z6)=z3'$+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 z10-z6 of currentpen+whatever*(z10-z6);
 z6'l=z6l+penoffset z6-z10 of currentpen+whatever*(z10-z6);
 fill z5r--diag_end(5r,3'r,1,.5,3'l,5l)--z5l--
 diag_end(5l,6'l,.5,1,6'r,5r)--cycle;  % diagonals
 pickup fine.nib; pos7(vair,90); pos8(vair,90);
 y7=y8=y5l; x7=x1; rt x8=x5r; filldraw stroke z7e--z8e; % middle cross
%%%
if serifs:
 numeric inner_jut,up_inner_jut;
 if rt x2r+cap_jut+.5u+1<=lft x6l-cap_jut: inner_jut=cap_jut;
  else: rt x2r+cap_jut+.5u+1=lft x6l-inner_jut; fi
 if rt x1r+cap_jut+.5u+1<=lft x3l-1.2cap_jut: up_inner_jut=1.2cap_jut;
  else: rt x1r+cap_jut+.5u+1=lft x3l-up_inner_jut; fi
 dish_serif(3,4,e,2/3,up_inner_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
%%%
% vcross
pickup crisp.nib; pos9(bar,0); pos11(bar,0);
lft x9l=lft x11l=hround max(rt x1r+1,max(x5l-bar+eps,.5[rt x1r,x5l]));
top y11-bot y9=.5cap_height; .52[y9,y11]=y7;
filldraw stroke z9e--z11e; % cross bar
penlabels(1,2,3,4,5,6,7,8,9,10,11); endchar;

iff not concrete:%
iff not specific:%
lhchar "Uppercase Cyrillic letter K_hcrs - KA hcrossed (`roman')";
cyrchar(K_hcrs,13.5u#,cap_height#,0); % N_width
if is_small_cap: getcharcode(k_hcrs); fi
italcorr cap_height#*slant-.5u#;
adjust_fit(cap_serif_fit#,cap_serif_fit#);
% upperr_k;
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); fi % lower stem serif
% K_rbowl;
numeric right_jut,stem[],alpha[]; pickup tiny.nib;
right_jut=if serifs:.6cap_jut else:.4tiny fi;
stem1=max(tiny.breadth,fudged.hair if hefty:-3stem_corr fi);
stem2=max(tiny.breadth,fudged.cap_stem-3stem_corr);
rt x3r=hround(r-letter_fit-u-right_jut);
rt x6r=hround(r-letter_fit-.75u-right_jut);
y4=1/3h; top y3=h; bot y6=0; x4=x1;
penpos3(alpha1*(stem1-tiny),0); penpos4(whatever,-90);
alpha1=diag_ratio(1,.5(stem1-tiny),y3-y4,x3r-x4);
penpos6(alpha2*(stem2-tiny),0);
alpha2=diag_ratio(1,.5(stem2-tiny),y1-y6,x6r-x1);
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
numeric inner_jut,up_inner_jut;
%%
if serifs:
 if rt x2r+cap_jut+.5u+1<=lft x6l-cap_jut: inner_jut=cap_jut;
  else: rt x2r+cap_jut+.5u+1=lft x6l-inner_jut; fi
 if rt x1r+cap_jut+.5u+1<=lft x3l-1.2cap_jut: up_inner_jut=1.2cap_jut;
  else: rt x1r+cap_jut+.5u+1=lft x3l-up_inner_jut; fi
 dish_serif(3,4,e,2/3,up_inner_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
%%%
%%%%%
% hcross
pickup crisp.nib; numeric outer_jut;
outer_jut=if serifs: max(limit_dist,1.1cap_jut) else: 1.8u fi;
pos7(bar,90); pos8(bar,90);
top y7r=top y8r=vround (min(1/3[x_height,h]+.5bar,h-max(bracket,1.2slab))-eps);
x7=x1r+1.15outer_jut; x8=hround 1/3u-cap_serif_fit;
filldraw stroke z7e--z8e; % cross bar
penlabels(1,2,3,4,5,6, 7,8); endchar;

iff not concrete:%
lhchar "Uppercase Cyrillic letter L_dsc - EL descender";
cyrchar(L_dsc,13.5u#,cap_height#, % DL_width:N_width
 if is_ogonek: desc_depth# else: cap_sbeak# fi); %udesc/og_depth
if is_small_cap: getcharcode(l_dsc); fi
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit# if not serifs:
    +\\.5(cap_stem#-u#),.5(cap_stem#-u#)+ else:,fi\\ cap_serif_fit#); %D_adj
% upper_l;
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
rt x1r=rt x2r=w-hround max(2u,3u-.5cap_stem); top y1=h; bot y2=0;
filldraw stroke z1e--z2e; %stem
numeric bulb_diam; bulb_diam=flare+(cap_stem-stem);
numeric light_hair,bot_vair,left_jut;
light_hair=max(tiny.breadth,fudged.hair if hefty:-4stem_corr fi);
left_jut=
   if serifs: max(limit_dist,1.1cap_jut)
   else:      hround (w+cap_serif_fit-rt x2r-.65u) fi;
bot_vair=Vround(.5[vair,light_hair]);
x3=1/3[w-rt x1r-(1/6left_jut),rt x1r] if not serifs:-.5(cap_stem-u) fi+eps;
if serifs:
 pos3(light_hair,0); pos4(light_hair,-90);
 pos6(bulb_diam,-180); pos5(cap_hair,-180);
 top y3=h; y6=1/6h-max(0,flare-stem-2vair_corr-.5); z6r=z5r;
 lft x6r=l+letter_fit+hround(.5u-.5);
 x4=max(lft x5r+.5bulb_diam,.4[lft x5r,rt x3r]); bot y4r=-o;
 filldraw stroke z4e{right}..
  controls (min(15/16[x4,x3],max(x4,lft x6r+2flare))+(x3e-x3)+eps,y4e)
  and (x3e,good.y(min(y6-.5,1/3h)+1/3(y4e-y4))-eps)..z3e; % left tail
 {{less_tense; bulb(4,5,6)}};
else:
 pos3'(slab,90); pos1'(slab,90);
 lft x3'=x3-.5light_hair; rt x1'=x1r; top y3'r=top y1'r=h;
 filldraw stroke z3'e--z1'e;
 pickup fine.nib; pos3(max(fine.breadth,light_hair),0); pos4(bot_vair,-90); pos5(bot_vair,-90);
 bot y5r=0; x4=2/3[x3l,x5r]; lft x5=l+letter_fit+hround(.35u-.5);
 bot y4r=bot y5r; y3=y3'; x4l:=.25[x4,x5];
 path p;
 p=stroke z3{down}
   ..controls (x3,y5+.35h-eps) and (min(7/8[x4,x3],x5+2.5light_hair+.5u),y4)
   ..{left}z4--z5;
 z6=point .35 of p;
 pos6(max(fine.breadth,7/8[bot_vair,light_hair]),angle(direction .35 of p)+90);
 filldraw stroke z3e{down}...z6e{direction .35 of p}...{left}z4e--z5e; fi % arc
%%%
if serifs:
 x0=x3; y0=0;
 numeric inner_jut; inner_jut=min(.5(lft x1l-rt x3r)-eps,.5cap_jut);
 if is_ogonek:
    dish_serif(2,1,a,1/3,cap_jut,b,1/3,cap_jut); %!!!  % lower right serif
 fi
 nodish_serif(1,2,c,1/3,inner_jut,d,1/3,cap_jut);     % upper right serif
 nodish_serif(3,0,e,1/3,1.05cap_jut,f,1/3,inner_jut); % upper left serif
 filldraw z.c0--z.c1--z.f1--z.f0--cycle; fi % upper inter_serif bar
%%%%%
% uppercase descender/saam tail
numeric right_jut;
right_jut=
      if serifs: max(limit_dist,cap_jut) else: hround (r-rt x2r-.65u) fi;
if unic:
   %saam tail
    serif(2,1,v,1/3,-cap_jut);
    siam_serif(2,1,w,1/3,right_jut);
else:
   r_serif(2,1,x,1/3,cap_jut,y,1/3,beak_darkness,right_jut,beak_jut); % lower right descender
fi
penlabels(1,2,3,4,5,6, 7,8,9); endchar;

lhchar "Uppercase Cyrillic letter M_dsc - M descender";
cyrchar(M_dsc,16u#+width_adj#,cap_height#,
 if is_ogonek: desc_depth# else: cap_sbeak# fi); %udesc/og_depth
if is_small_cap: getcharcode(m_dsc); fi
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,
 cap_serif_fit# if not serifs:+.5(cap_stem#-u#) fi); %DL_adj
% upper_m;
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
 if is_ogonek:
    dish_serif(4,3,e,1/3,cap_jut,f,1/3,cap_jut); fi %!!! % lower right serif
fi
%%%%%
% uppercase descender/saam tail
numeric right_jut;
right_jut=if serifs: max(limit_dist,1.1cap_jut) else: hround (r-rt x4r-.65u) fi;
if unic:
   %saam tail
    serif(4,3,v,1/3,-cap_jut);
    siam_serif(4,3,w,1/3,right_jut);
else:
   r_serif(4,3,x,1/3,cap_jut,y,1/3,beak_darkness,right_jut,beak_jut); % lower right descender
fi
penlabels(0,1,1',2,3,3',4,5,6,7,8, 9,10,11); endchar;

lhchar "Uppercase Cyrillic letter ABH_HA - Abkhasian KHA";
cyrchar(ABH_HA,14u#,cap_height#,desc_depth#);
if is_small_cap: getcharcode(abh_ha); fi
italcorr .7cap_height#*slant-.5u#;
adjust_fit(0,0);
pickup fine.nib; numeric right_curve,mid_curve;
right_curve=max(fine.breadth,.8[vair,curve] if hefty:-stem_corr fi);
mid_curve=max(fine.breadth,.65[vair,curve] if hefty:-2stem_corr fi);
pos1(vair',90); pos3(vround(vair+1.5vair_corr),-90);
pos2(cap_curve,180); pos4(right_curve,0);
if monospace:
 lft x2r=hround 1.5u;
 interim superness:=sqrt superness;  % make |"O"|, not |"0"|
else:
 interim superness:=hein_super; lft x2r=hround u; fi
x4r=w-x2r; x1=x3=x6=.5w; top y1r=h+o; bot y3r=-o;
y2=y4=.5h-vair_corr; y2l:=.52h;
y7=-1/3d; rt x7=hround(w-.5u);
pos7(vair,270);
y6=.5y5r; pos6(mid_curve,180);
forsuffixes e=l,r: path p.e; p.e=pulled_super_arc.e(1,4)(.5superpull); endfor
x5=if serifs:.5[x6,x4]else:.5[x6,x4]fi; top y5r=.5[y4,y1]; pos5(vair,90);
filldraw stroke pulled_super_arc.e(1,2)(.5superpull)
 & pulled_super_arc.e(2,3)(.5superpull)
 & pulled_super_arc.e(3,4)(.5superpull) % 3/4 bowl
 & pulled_super_arc.e(4,5)(.25superpull)
 & pulled_super_arc.e(5,6)(.75superpull)
 & pulled_super_arc.e(6,7)(.5superpull); %6/4 bowl
numeric t;
t=min(ypart(p.l intersectiontimes ((0,top y5r+vair)--(w,top y5r+vair))),
      ypart(p.r intersectiontimes ((lft x5,0)--(lft x5,h))));
filldraw stroke subpath (0,.75) of p.e; %quart
penlabels(1,2,3,4,5,6,7); endchar;

lhchar "Uppercase Cyrillic letter P_tl - PE tail";
cyrchar(P_tl,13.5u#,cap_height#,desc_depth#);
if is_small_cap: getcharcode(p_tl); fi
italcorr .45cap_height#*slant-.35u#; %O*.52
adjust_fit(if monospace:-.5u# else:cap_serif_fit# fi,
 if monospace: 5.35u# else:5.75u# fi);
% upper_p;
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_jut1=cap_jut;
  else: rt x1r+inner_jut1+.5u+1=lft x3l-inner_jut1; fi
 dish_serif(2,1,c,1/3,cap_jut,d,1/3,inner_jut1); % lower left serif
 %dish_serif(4,3,g,1/3,inner_jut1,h,1/3,cap_jut);   % lower right serif
 inner_jut2=min(.5(lft x3l-rt x1r)-eps,.5cap_jut);
 nodish_serif(1,2,a,1/3,cap_jut,b,1/3,inner_jut2);  % upper left serif
 nodish_serif(3,4,e,1/3,inner_jut2,f,1/3,cap_jut);  % upper right serif
 filldraw z.b0--z.b1--z.e1--z.e0--cycle; % upper inter_serif bar
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 % upper_bar
%%%%%
w:=w+6.25u;
% Tail_part(4);
_zero:=4;
_one:=5; _two:=6; _three:=7;
_four:=8; _five:=9; _six:=10; _seven:=11; _eight:=12;
%
pickup tiny.nib;
numeric bulb_diam;
bulb_diam=max(currentbreadth+eps,min(.82d-1-eps,flare+(cap_stem-stem)));
penpos[_one](vair,90); penpos[_two](vair,90);
penpos[_three](cap_curve if hefty:-3stem_corr fi,0);
y[_three]=.5[y[_one],-d]; x[_two]=max(.5w-.25u,w-7u);
x[_one]=x[_zero]; x[_three]r=hround(w-u);
x[_two]l:=x[_two]-.25cap_curve; y[_one]=y[_two]=.52h;
{{interim superness:=more_super;
 fill stroke super_arc.e([_three],[_two])..z[_one]e}};  % lobe
if serifs:
 z[_four]=z[_three];
 pos[_four](cap_curve if hefty:-3stem_corr fi,0);
 pos[_five](vair',-90); bot y[_five]r=-d-oo; y[_six]-.5flare=-.85d;
 pos[_six](cap_hair,-180); pos[_seven](bulb_diam,-180);
 rt x[_seven]l=max(lft x[_zero]l-jut+bulb_diam,
  floor x[_three]-3.5u if monospace: / expansion_factor fi);
 z[_six]r=z[_seven]r;
 x[_five]=max(rt x[_seven]l,.6[x[_four],x[_seven]r]);
 (x,y[_five]r)=whatever[z[_five]l,z[_four]l];
 x[_five]r:=max(x,.5[x[_six]r,x[_five]]);
 filldraw stroke super_arc.e([_four],[_five]);
 bulb([_five],[_six],[_seven]); % bulb
else:
 pickup fine.nib; z[_four]=z[_three];
 pos[_four](max(fine.breadth,cap_curve if hefty:-3stem_corr fi),0);
 pos[_eight](vair,-90); pos[_five](flare,-105);
 rt x[_five]r=x[_three]-6u; bot y[_five]r=-d;
 y[_five]l:=good.y y[_five]l; x[_five]l:=good.y x[_five]l;
 bot y[_eight]r=-d-o; x[_eight]=.35[lft x[_five]r,x[_three]r];
 filldraw stroke super_arc.e([_four],[_eight])
  & term.e([_eight],[_five],left,.75,4); fi
%%%
if serifs:
 if rt x2r+cap_jut+.5u+1<=x[_three]r: inner_jut3=cap_jut;
  else: rt x2r+inner_jut3+.5u=x[_three]r; fi
 dish_serif(4,3,g,1/3,inner_jut1,h,1/3,inner_jut3); fi % lower right serif
penlabels(1,2,3,4, 5,6,7,8,9,10,11,12); endchar;

lhchar "Uppercase Cyrillic letter R_dsc (looks like P)";
cyrchar(R_dsc,12u#,cap_height#,
 if is_ogonek: desc_depth# else: cap_sbeak# fi); %udesc/og_depth
if is_small_cap: getcharcode(r_dsc); fi
italcorr .75cap_height#*slant-.5u#;
adjust_fit(cap_serif_fit#,0);
% upper_r;
pickup tiny.nib; penpos1(cap_stem'-tiny,0); penpos2(cap_stem-tiny,0);
pos0(cap_stem',0); pos0'(cap_stem,0);
lft x1l=hround max(2u,3u-.5cap_stem'); top y1=h; bot y2=0;
x1l=x2l=x0l=x0'l; y0=y0'=y7;
penpos3(cap_band,90); penpos4(cap_band,90);
penpos5(cap_curve if hefty:-3stem_corr fi,0);
penpos6(.5[vair,cap_band],-90); penpos7(.5[vair,cap_band],-90);
z3r=top z1; y4=y3; y5=.5[y4l,y6l]; y6=y7;
x7=x2; y7l=vround .5h; x4=x6=.5w+.75u; x5r=hround(w-u);
x4l:=x6l:=x4-.25cap_curve;
filldraw stroke z1e--z0e--z0'e--z2e; % stem
fill stroke z3e..pulled_arc.e(4,5) & pulled_arc.e(5,6)..z7e;  % lobe
%%%
if serifs: nodish_serif(1,0,a,1/3,cap_jut,b,1/3,.5cap_jut);  % upper serif
 if is_ogonek:
    dish_serif(2,0',c,1/3,cap_jut,d,1/3,cap_jut); fi %!!! % lower serif
fi
%%%%%
% uppercase descender/ogonek
if is_ogonek:
   def the_pen=if known ogonek_pen: ogonek_pen
       elseif serifs: tiny elseif is_bold: fisp else: fine fi
   enddef;
   % |diag_end| refers to |tiny| pen, hence |tiny| in the following equation:
   ogonek_pos=(x2 if not serifs: l if is_bold: +.75tiny fi\\ fi,.5the_pen)
       if serifs and not is_egyptian: +(.5xvair,0) fi;
   easy_ogonek(the_pen,8,9,10); % ogonek
else:
   numeric right_jut;
   right_jut=if serifs: 1.414cap_jut else: .5cap_stem+.5u fi;
   r_serif(2,0',x,1/3,cap_jut,y,1/3,beak_darkness,right_jut,beak_jut); % lower right descender
fi
penlabels(0,1,2,3,4,5,6,7, 8,9,10); endchar;

lhchar "Uppercase Cyrillic letter LAT_Q";
cyrchar(LAT_Q,14u#-width_adj#,cap_height#,comma_depth#);
if is_small_cap: getcharcode(lat_q); fi
italcorr .7cap_height#*slant-.5u#;
adjust_fit(0,0);
numeric light_curve; light_curve=cap_curve-hround stem_corr;
penpos1(vair',90); penpos3(vair',-90);
penpos2(light_curve,180); penpos4(light_curve,0);
if monospace: x2r=hround 1.5u;
 interim superness:=sqrt superness;  % make |"Q"| like |"O"|
else: x2r=hround u; fi
x4r=w-x2r; x1=x3=.5w; y1r=h+o; y2=y4=.5h-vair_corr; y3r=-o;
penstroke pulled_super_arc.e(1,2)(.5superpull)
 & pulled_super_arc.e(2,3)(.5superpull)
 & pulled_super_arc.e(3,4)(.5superpull)
 & pulled_super_arc.e(4,1)(.5superpull) & cycle;  % bowl
pickup tiny.nib;
if hefty:
 penpos5(1.2(.5[cap_bar,light_curve]),0); penpos6(1.2light_curve,0);
 x5=.5w; x6r=hround(w-1.5u);
 y5=vround .28h; y6=-d;
 fill diag_end(6r,5r,.25,1,5l,6l)--diag_end(5l,6l,.5,1,6r,5r)--cycle;  % tail
else:
 pos3'(vair,270); pos5(vair,180); pos6(vair,90);
 pos7(cap_curve,85); penpos8(eps,180);
 z3'=z3; x6=x3; top y6r=vround(.2h+.5vair);
 lft x5r=hround(.5w-1.25u-.5vair); y5=.5[y3,y6];
 bot y7l=-d; x7l=2/3[x6,x8]; y8=0; rt x8=hround(x4r+.1u);
 filldraw stroke z3'e{left}...z5e{up}...z6e{right}
  ..z7e{right}...z8e{up}; fi % tail
penlabels(1,2,3,4,5,6,7,8); endchar;

lhchar "Uppercase Cyrillic letter T_dsc - TE descender";
cyrchar(T_dsc,13u#-width_adj#,cap_height#,
 if is_ogonek: desc_depth# else: cap_sbeak# fi); %udesc/og_depth
if is_small_cap: getcharcode(t_dsc); fi
italcorr cap_height#*slant-beak_jut#-.25u#;
adjust_fit(0,0);
% upper_t;
if odd(cap_stem-w): change_width; fi % symmetric & all three equal
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:
 if is_ogonek:
    dish_serif(2,1,c,1/3,1.414cap_jut,d,1/3,1.414cap_jut); %!!! % lower serif
 fi
 nodish_serif(1,2,a,1/3,.5cap_jut,b,1/3,.5cap_jut); fi  % upper bracketing
%%%%%
% uppercase descender/ogonek
if is_ogonek:
   def the_pen=if known ogonek_pen: ogonek_pen
       elseif serifs: tiny elseif is_bold: fisp else: fine fi
   enddef;
   % |diag_end| refers to |tiny| pen, hence |tiny| in the following equation:
   ogonek_pos=(x2 if not serifs: l if is_bold: +.75tiny fi\\ fi,.5the_pen)
       if serifs and not is_egyptian: +(.5xvair,0) fi;
   easy_ogonek(the_pen,6,7,8); % ogonek
else:
   numeric right_jut;
   right_jut=if serifs: 1.414cap_jut else: .5cap_stem+.5u fi;
   r_serif(2,1,x,1/3,1.414cap_jut,y,1/3,beak_darkness,right_jut,beak_jut); % lower right descender
fi
penlabels(1,2,3,4,5, 6,7,8); endchar;

lhchar "Uppercase Cyrillic letter TETSE - ligature TETSE";
cyrchar(TETSE,if serifs:14u#+width_adj#else:13.5u#fi,cap_height#,cap_sbeak#);
if is_small_cap: getcharcode(tetse); fi
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(min(4.5u#-.5stem#,3.5u#)-.5width_adj#, % Beak_adj
 cap_serif_fit# if not serifs:+.5(cap_stem#-u#) fi); %DL_adj
% upper_c;tetse
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(1u,2u-.5cap_stem) if monospace:-.5u fi;
rt x3r=rt x4r=w-hround max(2u,3u-.5cap_stem);
top y1=top y3=h; bot y2=bot y4=0;
filldraw stroke z1e--z2e; % left stem
filldraw stroke z3e--z4e; % right stem
% T part
pickup crisp.nib; pos5(slab,90); pos6(hair,180); pos7(hair,0);
x5=x1; x5-x6=x7-x5;
lft x6r=l+letter_fit+hround if monospace:.65u else: .1u fi;
top y5r=h; y6=good.y(y5l-beak)-eps; y7=y6;
arm(5,6,q,beak_darkness,-.5beak_jut); % arm and beak
arm(5,7,r,beak_darkness,.5beak_jut); % arm and beak
%%%
numeric inner_jut,arm_thickness;
arm_thickness=vround(slab+vair_corr);
if serifs:
 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
 nodish_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
 inner_jut:=min(.5(lft x3l-rt x1r)-eps,.5cap_jut);
 save slab; slab:=arm_thickness; % bottom.bar.slab
 nodish_serif(2,1,c,1/3,cap_jut,d,1/3,inner_jut); % lower left serif
else:
 save slab; slab:=arm_thickness; % bottom.bar.slab
 pos2'(slab,90); lft x2'= lft x2l; bot y2'l=0;
 rt x4'= rt x4r; y4'=y2'; pos4'(slab,90);
 filldraw stroke z2'e--z4'e; fi % lower bar
% uppercase descender
inner_jut:=min(.5(lft x3l-rt x1r)-eps,.5cap_jut);
numeric right_jut;
right_jut=
   if serifs: max(limit_dist,1.1cap_jut) else: hround (r-rt x4r-.65u) fi;
r_serif(4,3,g,1/3,inner_jut,h,1/3,beak_darkness,right_jut,beak_jut); % lower right descender
if serifs:
 filldraw z.d0--z.d1--z.g1--z.g0--cycle; fi % lower inter_serif bar
penlabels(1,2,3,4,5,6,7); endchar;

lhchar "Uppercase Cyrillic letter CH_vcrs - CHE vcrossed";
cyrchar(CH_vcrs,13.5u#,cap_height#,0);
if is_small_cap: getcharcode(ch_vcrs); fi
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
% upper_ch;
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=.3[y6,h]; bot y4=0;
x5l=1/3[x1,x3]; y5=y6; if serifs: y6'=y6-cap_hair+1.05cap_stem; fi
x6=x6'=x3; y6=good.y (h-.52h if serifs: -.35(.5[cap_hair,.7cap_stem]) fi);
filldraw stroke z1e--z2e; % left stem
filldraw stroke z3e--z4e; % right stem
clearpen; penpos2'(cap_stem,0); z2'=z2;
numeric middle_weight; middle_weight=.5[vair,cap_band];
penpos5(middle_weight,90); penpos6(middle_weight,90); penpos6'(middle_weight,90);
if serifs:
 if((y6'-y6)>=middle_weight+1+eps):
  fill stroke  pulled_arc.e(2',5) & z5e{right}...{.75(z5-z6)+z6'}z6'e;
 else: fill stroke  pulled_arc.e(2',5) & z5e--z6e; fi % arc
 numeric inner_jut; pickup tiny.nib;
 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 right serif
 dish_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut);  % lower right serif
else: filldraw stroke  pulled_arc.e(2',5) & z5e--z6e; fi % arc
%%%%%
% vcross
pickup crisp.nib; pos7(bar,0); pos8(bar,0);
lft x7l=lft x8l=hround(.5[x1r,x3l]-.5bar);
top y8-bot y7=.5cap_height; .5[y7,y8]=y6;
filldraw stroke z7e--z8e;
penlabels(1,2,3,4,5,6); endchar;

lhchar "Uppercase Cyrillic letter W";
cyrchar(LAT_W,18u#,cap_height#,0);
if is_small_cap: getcharcode(lat_w); fi
italcorr cap_height#*slant+.25u#;
adjust_fit(cap_serif_fit#,cap_serif_fit#);
numeric stem[],outer_jut,upper_notch,alpha,mid_corr;
outer_jut=.7cap_jut; x1l=w-x8r=l+letter_fit+outer_jut+.25u;
stem1=fudged.cap_stem-stem_corr;
stem4=min(fudged.hair if hefty:-2stem_corr fi,stem1);
stem2=stem4 if hefty:-2stem_corr fi;
stem3=stem1 if hefty:-2stem_corr fi;
x2-x1=x4-x3=x6-x5=x8-x7; x2l+apex_corr=x3l; x6l+apex_corr=x7l;
y1=y8=h; y2=y3=y6=y7=-apex_o; y4=y5=if monospace: vround .6 fi\\ h;
mid_corr=if monospace or hefty:-apex_corr else: 1/3jut fi;
alpha=diag_ratio(4,stem2-stem3+stem4,y1-y2,x8r-x1l+mid_corr-2apex_corr);
penpos1(alpha*stem1,0); penpos2(alpha*stem1,0);
penpos3(alpha*stem2,0); penpos4(alpha*stem2,0);
penpos5(alpha*stem3,0); penpos6(alpha*stem3,0);
penpos7(alpha*stem4,0); penpos8(alpha*stem4,0);
x4l-x1l=floor(x4l-x1l+.5(x5r+mid_corr-x4r)); % |x5r+mid_corr| $\approx$ |x4r|
z23=whatever[z1r,z2r]=whatever[z3l,z4l];
z45=whatever[z3r,z4r]=whatever[z5l,z6l];
z67=whatever[z5r,z6r]=whatever[z7l,z8l]; upper_notch=y4-cap_notch_cut;
fill diag_end(1l,2l,1,1,3r,4r){z4-z3}
 ...if y45<upper_notch:(x45,upper_notch)+.5left{up}
   --(x45,upper_notch)+.5right{down} else: z45&z45 fi
 ...{z6-z5}diag_end(5l,6l,1,1,7r,8r)--diag_end(7r,8r,1,1,8l,7l){z7-z8}
 ...if y67>cap_notch_cut:(x67,cap_notch_cut)+.5right{down}
   --(x67,cap_notch_cut)+.5left{up} else: z67&z67 fi
 ...{z5-z6}special_diag_end(6,5,4,3){z3-z4}
 ...if y23>cap_notch_cut:(x23,cap_notch_cut)+.5right{down}
   --(x23,cap_notch_cut)+.5left{up} else: z23&z23 fi
 ...{z1-z2}diag_end(2r,1r,1,1,1l,2l)--cycle;  % diagonals
if serifs:
 numeric inner_jut[]; pickup tiny.nib;
 prime_points_inside(1,2); prime_points_inside(5,6); prime_points_inside(8,7);
 if monospace:
  inner_jut1=inner_jut4=1.5cap_jut;
 elseif hefty:
  inner_jut1=inner_jut4=cap_jut;
 else:
  fill diag_end(6r,5r,1,1,5l,6l)--.9[z5l,z6l]
   ..{z5-z6}.1[z5r,z6r]--cycle;  % middle stem
  inner_jut2=.7inner_jut1; inner_jut4=1.1inner_jut3;
  if rt x1'r+cap_jut+.5u+1<=lft x5'l-.7cap_jut: inner_jut1=cap_jut;
   else: rt x1'r+inner_jut1+.5u+1=lft x5'l-inner_jut2; fi
  if rt x5'r+cap_jut+.5u+1<=lft x8'l-1.1cap_jut: inner_jut3=cap_jut;
   else: rt x5'r+inner_jut3+.5u+1=lft x8'l-inner_jut4; fi
  dish_serif(5',6,e,1/3,inner_jut2,f,1/2,inner_jut3); fi  % middle serif
 dish_serif(1',2,a,1/3,outer_jut,b,1/2,inner_jut1);  % left serif
 dish_serif(8',7,c,.6,inner_jut4,d,1/2,outer_jut)(dark); fi  % right serif
penlabels(0,1,2,3,4,5,6,7,8,23,45,67); endchar;

lhchar "Uppercase Cyrillic letter N_ltl -  EN with left tail";
cyrchar(N_ltl,13.5u#,cap_height#,desc_depth#);
if is_small_cap: getcharcode(n_ltl); fi
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
% upper_n;
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 right serif
 dish_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut); fi  % lower right serif
%%%%%
% L_tail(2)x;
_zero:=2;
_one:=7; _two:=8; _three:=9; _four:=10; _five:=11;
%
pickup fine.nib;
pos[_five](tiny.rt x[_zero]r-tiny.lft x[_zero]l,0);
pos[_one](tiny.rt x[_zero]r-tiny.lft x[_zero]l,0);
z[_five]=z[_zero]; x[_one]r=x[_five]r;
bot y[_one]=max(-1/3d,-d+if serifs: vair' else: slab fi+eps);
if serifs:
 numeric bulb_diam;
 bulb_diam=max(currentbreadth+eps,min(.82d-1-eps,flare+(cap_stem-stem)));
 pos[_two](vair',-90); pos[_three](hair,-180);
 pos[_four](bulb_diam,-180);
 x[_two]=.5[x[_one],x[_three]r];
 bot y[_two]r=-d-oo; y[_three]-.5bulb_diam=vround max(-.85d,y[_two]r+eps)+eps;
 z[_three]r=z[_four]r;
 %rt x[_four]l=floor x[_zero]-2u if monospace: / expansion_factor fi;%2.5u
 lft x[_four]r=-1/3u if monospace: / expansion_factor fi;%2.5u
 %filldraw stroke z[_five]e--pulled_arc.e([_one],[_two]);
 forsuffixes e=l,r:
 z[_one]'e=((0,y[_four])--(w,y[_four])) intersectionpoint
    (z[_five]e--pulled_arc.e([_one],[_two])); endfor
 if lft x[_one]'l>rt x[_four]l+max(1,.5vair+.5):
    filldraw stroke z[_five]e--pulled_arc.e([_one],[_two]);
 else:
    x[_one]'l:=min(rt x[_four]l+max(1,hround(.5vair+.5)),rt x[_one]'r-vair)+.5fine-eps;
    filldraw z[_five]r--pulled_arc.r([_one],[_two])--z[_two]l{right}
             ..z[_one]'l{up}..{up}z[_five]l--cycle;
 fi
 bulb([_two],[_three],[_four]); % bulb
else:
 pos[_two](slab,-90); pos[_three](flare,-105);
 rt x[_three]r=x[_zero]-2.5u; bot y[_three]r=-d;%4u
 bot y[_two]r=-d-o; x[_two]=.4[x[_three]r,x[_zero]r];
 filldraw stroke z[_five]e--super_arc.e([_one],[_two])
  & term.e([_two],[_three],left,.8,4); fi
%%%
penlabels(1,2,3,4,5,6, 7,8,9,10,11); endchar;

iff serifs:
lhchar "Uppercase Cyrillic letter DELTA - Lowercase Greek delta";
cyrchar(DELTA,10u#-width_adj#,asc_height#,0);
if is_small_cap: getcharcode(delta); fi
italcorr .9asc_height#*slant+.5hair#-1.5u#;
adjust_fit(0,0); pickup fine.nib;
x0=-u; y0=1.1h;
numeric light_flare; light_flare=3/4[vair,flare];
x1=w-2u-.5light_flare; y1=h-.5light_flare;
numeric theta; theta=angle (z1-z0);
pos1(light_flare,theta-90); pos2(.2[vair,light_flare],-90);
x2=x3+2u; y2=h;
x4=.5w+.5u; x6=.55[x7,x5]; top y8r=1/4[x_height,cap_height]+o; z4=z8;
pos6(vround(vair+1.5vair_corr),-90); pos7(cap_stem,-180); pos8(vair',-270);
pos3(1/3[hair,cap_stem],angle(z4-z0)+60); pos4(cap_stem,angle(z4-z0)+45);
pos5(cap_stem,15);
z3=1/3[z4,(x0,.5[y0,h])];
y5+.05x_height=y7=.5[y6,y8]; bot y6=-o;
lft x7r=hround(1.4u-.5cap_stem); rt x5r=hround(w-u);
z35=point 1.5 of (z1{z0-z1}...z2....z3{z4-z0});%{(z0-z1)rotated 90});
pos35(hair,angle(.5[z4,z1]-z0));
filldraw stroke z1e{z0-z1e}....z2e...z35e..z3e{z4e-z0}%{(z0-z1)rotated 90}
 ...z4e{z4e-.8[z4,z0]}
 ....z5e{down}...pulled_arc.e(6,7) & pulled_arc.e(7,8);  % hook and bowl
filldraw z1r{z1r-z0}...z1l{z0-z1l}--cycle; % bulb
math_fit(-.3x_height#*slant+.5curve#-u#,.7x_height#*slant-.5u#);
penlabels(0,1,2,3,35,4,5,6,7,8); endchar;

iff not serifs:
lhchar "Uppercase Cyrillic letter delta - Lowercase Greek delta";
cyrchar(DELTA,11u#-2width_adj#,asc_height#,0);
italcorr .9asc_height#*slant+.5hair#-1.5u#;
adjust_fit(0,0); pickup fine.nib;
x0=-u; y0=1.1h;
numeric light_flare; light_flare=3/4[vair,flare];
x1=w-2u-.5light_flare; y1=h-.5light_flare;
numeric theta; theta=angle (z1-z0);
pos1(light_flare,theta-90); pos2(.2[vair,light_flare],-90);
x2=x3+2u; y2=h;
x4=.5w+.5u; x6=.5[x7,x5]; top y8r=1/4[x_height,cap_height]+o; z4=z8;
pos6(vround(vair+1.5vair_corr),-90); pos7(cap_stem,-180); pos8(vair',-270);
pos3(vair,angle(z4-z0)+90); pos4(.5[vair,cap_stem],angle(z4-z0)+90);
pos5(fudged.stem,0);
z3=1/3[z4,(x0,.5[y0,h])]; y5=y7=.5[y6,y8]; bot y6=-o;
lft x7r=hround(1.4u-.5stem); rt x5r=hround(w-1.4u+.5stem);
z35=point 1.5 of (z1{z0-z1}...z2....z3{z4-z0});
pos35(vair,angle(.5[z4,z1]-z0));
filldraw stroke z1e{z0-z1e}...z2e..z35e..z3e{z4e-z0}
 ...z4e{z4-.8[z4,(x0,h)]}
 ...
{{interim superness:=more_super;
pulled_arc.e(5,6) &
pulled_arc.e(6,7) & pulled_arc.e(7,8)}};  % hook and bowl
math_fit(-.3x_height#*slant+.5curve#-u#,.7x_height#*slant-.5u#);
penlabels(0,1,2,3,35,4,5,6,7,8); endchar;

lhchar "Uppercase Cyrillic letter M_tl - M tail";
cyrchar(M_tl,16u#+width_adj#,cap_height#,desc_depth#);
if is_small_cap: getcharcode(m_tl); fi
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
% upper_m;
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); fi % upper right serif
 %dish_serif(4,3,e,1/3,cap_jut,f,1/3,cap_jut); fi % lower right serif
%%%%%
% L_tail(4);
_zero:=4;
_one:=9; _two:=10; _three:=11; _four:=12; _five:=13;
%
pickup fine.nib;
pos[_five](tiny.rt x[_zero]r-tiny.lft x[_zero]l,0);
pos[_one](tiny.rt x[_zero]r-tiny.lft x[_zero]l,0);
z[_five]=z[_zero]; x[_one]r=x[_five]r;
bot y[_one]=max(-1/3d,-d+if serifs: vair' else: slab fi+eps);
if serifs:
 numeric bulb_diam;
 bulb_diam=max(currentbreadth+eps,min(.82d-1-eps,flare+(cap_stem-stem)));
 pos[_two](vair',-90); pos[_three](hair,-180);
 pos[_four](bulb_diam,-180);
 x[_two]=.5[x[_one],x[_three]r];
 bot y[_two]r=-d-oo; y[_three]-.5bulb_diam=vround max(-.85d,y[_two]r+eps)+eps;
 z[_three]r=z[_four]r;
 rt x[_four]l=floor x[_zero]-2.5u if monospace: / expansion_factor fi;
 filldraw stroke z[_five]e--pulled_arc.e([_one],[_two]);
 bulb([_two],[_three],[_four]); % bulb
else:
 pos[_two](slab,-90); pos[_three](flare,-105);
 rt x[_three]r=x[_zero]-4u; bot y[_three]r=-d;
 bot y[_two]r=-d-o; x[_two]=.4[x[_three]r,x[_zero]r];
 filldraw stroke z[_five]e--super_arc.e([_one],[_two])
  & term.e([_two],[_three],left,.8,4); fi
%%%
penlabels(0,1,1',2,3,3',4,5,6,7,8,9, 10,11,12,13,14); endchar;

lhchar "Uppercase Cyrillic letter R_gcrs - R grave crossed";
cyrchar(R_gcrs,12u#,cap_height#,0);
if is_small_cap: getcharcode(r_gcrs); fi
italcorr .75cap_height#*slant-.5u#;
adjust_fit(cap_serif_fit#,0); full_h:=h; h:=cap_height;
% upper_r;
pickup tiny.nib; penpos1(cap_stem'-tiny,0); penpos2(cap_stem-tiny,0);
pos0(cap_stem',0); pos0'(cap_stem,0);
lft x1l=hround max(2u,3u-.5cap_stem'); top y1=h; bot y2=0;
x1l=x2l=x0l=x0'l; y0=y0'=y7;
penpos3(cap_band,90); penpos4(cap_band,90);
penpos5(cap_curve if hefty:-3stem_corr fi,0);
penpos6(.5[vair,cap_band],-90); penpos7(.5[vair,cap_band],-90);
z3r=top z1; y4=y3; y5=.5[y4l,y6l]; y6=y7;
x7=x2; y7l=vround .5h; x4=x6=.5w+.75u; x5r=hround(w-u);
x4l:=x6l:=x4-.25cap_curve;
filldraw stroke z1e--z0e--z0'e--z2e; % stem
fill stroke z3e..pulled_arc.e(4,5) & pulled_arc.e(5,6)..z7e;  % lobe
%%%
if serifs: nodish_serif(1,0,a,1/3,cap_jut,b,1/3,.5cap_jut);  % upper serif
 dish_serif(2,0',c,1/3,cap_jut,d,1/3,cap_jut); fi  % lower serif
%%%%%
numeric unbalance,outer_jut;
unbalance=if monospace: 1 else: 1.1 fi;
z8=(.5[x5,x6],y6);
% some funny fonts have an extremally small |jut|:
outer_jut=.5cap_stem+if serifs: max(limit_dist,cap_jut) else: 1.8u fi;
put_cyrcross(x8,y8-.52cap_height,-outer_jut,-unbalance*outer_jut)(cyrcaph);
%%%
penlabels(0,1,2,3,4,5,6,7, 8); endchar;

iff serifs:%
lhchar "Uppercase Cyrillic letter S_acrs - S acute crossed";
cyrchar(S_acrs,13u#,cap_height#,0);
if is_small_cap: getcharcode(s_acrs); fi
italcorr cap_height#*slant-.5u#;
adjust_fit(0,0);
% upper_s;
pickup fine.nib; pos1(cap_hair,0); pos2(cap_band,90);
pos3(cap_curve,180); pos4(cap_band,270); pos5(hair,360);
rt x1r=rt x5r=hround(w-u); lft x3r=hround u; x2=x4=.55[x3,x1];
top y2r=h+o; bot y4r=-o; y3=.5[y2,y4];
bot y1=min(vround max(.6h,x_height-.5vair),bot y2l-eps);
y5=max(good.y .95(h-y1),y4l+eps);
(x2l',y2l)=whatever[z2r,z1l]; x2l:=min(x2l',x2l+.5u);
(x4l',y4l)=whatever[z4r,z5l]; x4l:=min(x4l',x4l+.5u);
filldraw stroke z1e{x2-x1,10(y2-y1)}
 ...pulled_arc.e(2,3) & pulled_arc.e(3,4)...{up}z5e; % arc
pos6(.3[fine.breadth,cap_hair],0); x6r=x1r; top y6=h+o;
x1r-x1'=2cap_curve-fine; y1'=y1;
path upper_arc; upper_arc=z1{x2-x1,10(y2-y1)}..z2{left};
numeric t; t=xpart(upper_arc intersectiontimes (z6l--z1'));
filldraw z1r--z6r--z6l--subpath(t,0) of upper_arc--cycle; % barb
%%%%%
pair outer_point; path p; numeric unbalance,outer_jut;
outer_point=superness[(x4r,y3r),(x3r,y4r)];
p=z3{(x3,y4)-z3}
 ...superpull[superness[(x4,y3),(x3,y4)],outer_point]{z4-z3}...{z4-(x3,y4)}z4;
z7=point.8 of p;
unbalance=if monospace: 1 else: 1.1 fi;
% some funny fonts have an extremally small |jut|:
outer_jut=.5cap_stem+if serifs: max(limit_dist,cap_jut) else: 1.8u fi;
put_cyrcross(x7,y7-.52cap_height,unbalance*outer_jut,outer_jut)(cyrcaph);
penlabels(1,1',2,3,4,5,6, 7); endchar;

iff not serifs:%
lhchar "Uppercase Cyrillic letter S_acrs - es acute crossed";
cyrchar(S_acrs,11.5u#,cap_height#,0);
if is_small_cap: getcharcode(s_acrs); fi
italcorr cap_height#*slant-.5u#;
adjust_fit(0,0);
% uppers_s;
pickup fine.nib; pos1(1.2flare,80); pos2(slab,90);
pos3(cap_curve,180); pos4(slab,270); pos5(flare,275);
rt x1r=hround(w-1.1u); x2=x4=.5w+1.25u;
lft x3r=hround max(u,2u-.5cap_curve); rt x5r=hround(w-.9u);
top y1r=vround .95h+o; top y2r=h+o; y3=.5h;
bot y4r=-o; bot y5r=vround .08h-o; y5l:=good.y y5l; x5l:=good.x x5l;
filldraw stroke rterm.e(2,1,right,.9,4) & super_arc.e(2,3)
 & super_arc.e(3,4) & term.e(4,5,right,.8,4); % arc and terminals
%%%%%
path p; numeric unbalance,outer_jut;
p=z3{(x3,y4)-z3}...superness[(x4,y3),(x3,y4)]{z4-z3}...{z4-(x3,y4)}z4;
z6=point.8 of p;
unbalance=if monospace: 1 else: 1.1 fi;
% some funny fonts have an extremally small |jut|:
outer_jut=.5cap_stem+if serifs: max(limit_dist,cap_jut) else: 1.8u fi;
put_cyrcross(x6,y6-.52cap_height,unbalance*outer_jut,outer_jut)(cyrcaph);
penlabels(1,2,3,4,5, 6); endchar;

lhchar "Uppercase Cyrillic letter G_crsdsc - GHE hcrossed descender";
cyrchar(G_crsdsc,if monospace: 9u# else: 11u# fi-width_adj#, %G_width
 cap_height#,cap_sbeak#);
if is_small_cap: getcharcode(g_crsdsc); fi
italcorr cap_height#*slant-beak_jut#-.25u#;
adjust_fit(cap_serif_fit#,0);
% upper_g;
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
%%%
if serifs: nodish_serif(1,2,a,1/3,cap_jut,b,1/3,.5cap_jut); % upper serif
   if is_ogonek:
      dish_serif(2,1,c,1/3,cap_jut,d,1/3,1.25cap_jut); fi %!!! % lower serif
fi
%%%%%
% uppercase descender/ogonek
if is_ogonek:
   def the_pen=if known ogonek_pen: ogonek_pen
       elseif serifs: tiny elseif is_bold: fisp else: fine fi
   enddef;
   % |stem| is drawn by |tiny| pen, hence |tiny| in the following equation:
   ogonek_pos=(x2 if not serifs: l if is_bold: +.75tiny fi\\ fi,.5the_pen)
       if serifs and not is_egyptian: +(.5xvair,0) fi;
   easy_ogonek(the_pen,5,6,7); % ogonek
else:
   numeric right_jut;
   right_jut=if serifs: 1.414cap_jut else: .5cap_stem+.5u fi;
   if not serifs:
      numeric arm_thickness; arm_thickness=vround(slab-vair_corr);
      save slab; slab:=arm_thickness; fi %bottom.desc.slab
   r_serif(2,1,x,1/3,cap_jut,y,1/3,beak_darkness,right_jut,beak_jut); % lower right descender
fi
% hcross
pickup crisp.nib; numeric outer_jut;
outer_jut=if serifs: max(limit_dist,1.1cap_jut) else: 1.8u fi;
pos5(bar,90); pos6(bar,90);
top y6r=top y5r=vround (.52h+.5bar)+eps;
x6=x1r+1.15outer_jut; x5=hround 1/3u-cap_serif_fit;
filldraw stroke z5e--z6e;
penlabels(1,2,3,4 ,5,6,7); endchar;

lhchar "Uppercase Cyrillic letter H_hcrs (looks like X)";
cyrchar(H_hcrs,13u#,cap_height#,0);
if is_small_cap: getcharcode(h_hcrs); fi
italcorr cap_height#*slant-.25u#;
adjust_fit(cap_serif_fit#,cap_serif_fit#);
% upper_h;
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; 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+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); fi % lower left serif
%%%%%
% cross
pickup fine.nib; numeric middle_weight;
middle_weight=max(fine.breadth,.6[thin_join,vair]);
if hefty: y6=y5=y0; else:
 z0'=whatever[z1,z4]=whatever[z2,z3]; y6r=y5r=y0'; fi
x6=w-u; x5=u; pos5(middle_weight,90); pos6(middle_weight,90);
filldraw stroke z5e--z6e;
penlabels(0,1,2,3,4,12,13,24,34, 5,6); endchar;

lhchar "Uppercase Cyrillic letter SEMISN - SEMI SOFT SIGN";
cyrchar(SEMISN,12.5u#,cap_height#,0);
if is_small_cap: getcharcode(semisn); fi
italcorr .75cap_height#*slant-.5u#;
adjust_fit(2u#+cap_serif_fit#,0);
numeric left_stem,right_curve,middle_weight;
left_stem=cap_stem-hround 2stem_corr; middle_weight=.5[vair,cap_band];
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
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
% usftsn_bowl(2);
_zero:=2;
_one:=3; _two:=4; _three:=5; _four:=6; _five:=7;
%
pickup tiny.nib;
penpos[_one](cap_bar,90);
penpos[_three](cap_curve if hefty:-3stem_corr fi,0);
penpos[_four](cap_band,-90); penpos[_five](cap_band,-90);
z[_five]r=bot z[_zero]; y[_four]=y[_five];
y[_three]=.5[y[_four],y[_two]];
x[_one]=x[_zero]r; x[_three]r=hround(w-u);
if (serifs=false) or (cap_bar#>.5cap_curve#) or (cap_bar<3):
 penpos[_two](cap_bar,90);
 x[_four]=.5[x[_zero],w-if serifs:1.5u else:2.5u fi]+.5u;
 y[_one]=y[_two]=.52h; x[_two]=x[_four];
else: penpos[_two](1/18[cap_bar,cap_curve],90);
 x[_four]=.5[x[_zero],w-1.5u]+.5u;
 y[_one]l=y[_two]l-.35cap_bar=.52h-.5cap_bar;
 x[_two]=x[_four]-.35u; fi
x[_two]l:=x[_two]l-.5u; x[_four]l:=x[_four]l-.5u;
fill stroke z[_five]e..super_arc.e([_four],[_three])
 & super_arc.e([_three],[_two])..z[_one]e; % lobe
%%%
% hcross
pickup crisp.nib; pos8(bar,90); pos9(bar,90);
lft x8=w-x9-4u; %hround 1/3u if serifs:-serif_fit fi;
x9=hround(w-2.65u); %x4; %1r+2.5u;
top y8r=top y9r=vround .85h;%vround x_height+eps;
filldraw stroke z8e--z9e; % cross bar
%%%%%
penlabels(1,2,3,4,5,6,7,8,9,10); endchar;

lhchar "Uppercase Cyrillic letter I_shdsc - SHORT I WITH DESCENDER";
cyrchar(I_shdsc,13.5u#,cap_height#+acc_height#, % N_width
 if is_ogonek: desc_depth# else: cap_sbeak# fi); %udesc/og_depth
if is_small_cap: getcharcode(i_shdsc); fi
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#); full_h:=h; h:=cap_height;
% upper_i;
pickup tiny.nib; pos1(fudged.cap_stem,0); pos2(fudged.cap_stem,0);
pos3(fudged.cap_stem,0); pos4(fudged.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
numeric stem[],alpha[];
if hefty: numeric upper_notch,lower_notch;
 stem1=fudged.hair-stem_corr;
 upper_notch=y6-cap_notch_cut-eps; lower_notch=y5+cap_notch_cut+eps;
 if monospace:
  x5r =rt x1r; x6l =lft x3l; y5=vround(slab+eps); y6=vround(h-slab-eps);
  alpha1=diag_ratio(1,stem1,y5-y6,x5r-x6l);
  penpos5(min(2fudged.cap_stem,alpha1*stem1),0);
  penpos6(min(2fudged.cap_stem,alpha1*stem1),0);
  x5'=lft x1l; z5'=whatever[z5l,z6l]; x6'=rt x4r; z6'=whatever[z5r,z6r];
  x5l:=x5'; x6r:=x6'; y5l:=y5'; y6r:=y6';
 else:
  y5l=0; y6r=h; x5=x1r; x6=x3l; penpos5(stem1,0); penpos6(stem1,0);
 fi
 x2'=rt x1r; z2'=whatever[z5l,z6l]; x3'=lft x4l; z3'=whatever[z5r,z6r];
 fill z5l..
  if y2'>lower_notch: {right}(x2'+1,lower_notch){up}... fi
  {z6-z5}diag_in(5l,6l,1,6r)--z6r..
  if y3'<upper_notch: {left}(x3'-1,upper_notch){down}... fi
  {z5-z6}diag_in(6r,5r,1,5l)--cycle;  % diagonal
else: y5l=y2+bracket+eps; y6r=y3-bracket-eps;
 x5=hround (rt x1r-.5)-eps; x6=hround (lft x3l+.5)+eps;
 stem1=max(tiny.breadth,fudged.hair);
 alpha1=diag_ratio(1,stem1,x6-x5,top y6r-bot y5l);
 penpos5(alpha1*stem1,90); penpos6(alpha1*stem1,90);
 fill stroke z5e--z6e; fi % diagonal
%%%
numeric inner_jut;
if serifs:
 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 right serif
 if is_ogonek:
    dish_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut); fi % lower right serif
fi
%%%
% uppercase descender/saam tail
if not serifs: inner_jut:=0; fi
numeric right_jut;
right_jut=if serifs: max(limit_dist,1.1cap_jut) else: hround (r-rt x4r-.65u) fi;
if unic:
   %saam tail
    serif(4,3,v,1/3,-inner_jut);
    siam_serif(4,3,w,1/3,right_jut);
else:
   r_serif(4,3,g,1/3,inner_jut,h,1/3,beak_darkness,right_jut,beak_jut); % lower right descender
fi
%%%%%
% the accent
h:=cap_height+acc_height;
cbreve(.5w,0, 7,8,9,10,11,12,13)(cyrcaph);
penlabels(1,2,3,4,5,6, 7,8,9,10,11,12,13); endchar;

lhchar "Uppercase Cyrillic letter R_tl (looks like P)";
cyrchar(R_tl,12u#,cap_height#,desc_depth#); %udesc/og_depth
if is_small_cap: getcharcode(r_tl); fi
italcorr .75cap_height#*slant-.5u#;
adjust_fit(cap_serif_fit#,0);
% upper_r;
pickup tiny.nib; penpos1(cap_stem'-tiny,0); penpos2(cap_stem-tiny,0);
pos0(cap_stem',0); pos0'(cap_stem,0);
lft x1l=hround max(2u,3u-.5cap_stem'); top y1=h; bot y2=0;
x1l=x2l=x0l=x0'l; y0=y0'=y7;
penpos3(cap_band,90); penpos4(cap_band,90);
penpos5(cap_curve if hefty:-3stem_corr fi,0);
penpos6(.5[vair,cap_band],-90); penpos7(.5[vair,cap_band],-90);
z3r=top z1; y4=y3; y5=.5[y4l,y6l]; y6=y7;
x7=x2; y7l=vround .5h; x4=x6=.5w+.75u; x5r=hround(w-u);
x4l:=x6l:=x4-.25cap_curve;
filldraw stroke z1e--z0e--z0'e--z2e; % stem
fill stroke z3e..pulled_arc.e(4,5) & pulled_arc.e(5,6)..z7e;  % lobe
%%%
if serifs: nodish_serif(1,0,a,1/3,cap_jut,b,1/3,.5cap_jut);  % upper serif
 dish_serif(2,0',c,1/3,cap_jut,d,1/3,cap_jut); fi %!!! % lower serif
%%%%%
% Tail_part(2);%!!!
_zero:=2;
_one:=8; _two:=9; _three:=10;
_four:=11; _five:=12; _six:=13; _seven:=14; _eight:=15;
%
pickup tiny.nib;
numeric bulb_diam;
bulb_diam=max(currentbreadth+eps,min(.82d-1-eps,flare+(cap_stem-stem)));
penpos[_one](vair,90); penpos[_two](vair,90);
penpos[_three](cap_curve if hefty:-3stem_corr fi,0);
y[_three]=.5[y[_one],-d]; x[_two]=max(.5w-.25u,w-7u);
x[_one]=x[_zero]; x[_three]r=hround(w-2u);%!!!
x[_two]l:=x[_two]-.25cap_curve; y[_one]=y[_two]=.5y7l;%!!!
{{interim superness:=more_super;
 fill stroke super_arc.e([_three],[_two])..z[_one]e}};  % lobe
if serifs:
 z[_four]=z[_three];
 pos[_four](cap_curve if hefty:-3stem_corr fi,0);
 pos[_five](vair',-90); bot y[_five]r=-d-oo; y[_six]-.5flare=-.85d;
 pos[_six](cap_hair,-180); pos[_seven](bulb_diam,-180);
 rt x[_seven]l=max(lft x[_zero]l-jut+bulb_diam,
  floor x[_three]-3.5u if monospace: / expansion_factor fi);%!!!
 z[_six]r=z[_seven]r;
 x[_five]=max(rt x[_seven]l,.6[x[_four],x[_seven]r]);
 (x,y[_five]r)=whatever[z[_five]l,z[_four]l];
 x[_five]r:=max(x,.5[x[_six]r,x[_five]]);
 filldraw stroke super_arc.e([_four],[_five]);
 bulb([_five],[_six],[_seven]); % bulb
else:
 pickup fine.nib; z[_four]=z[_three];
 pos[_four](max(fine.breadth,cap_curve if hefty:-3stem_corr fi),0);
 pos[_eight](vair,-90); pos[_five](flare,-105);
 rt x[_five]r=x[_three]-6u; bot y[_five]r=-d;
 y[_five]l:=good.y y[_five]l; x[_five]l:=good.y x[_five]l;
 bot y[_eight]r=-d-o; x[_eight]=.35[lft x[_five]r,x[_three]r];
 filldraw stroke super_arc.e([_four],[_eight])
  & term.e([_eight],[_five],left,.75,4); fi
penlabels(0,1,2,3,4,5,6,7, 8,9,10); endchar;

endinput;
%end of file
