%
% lgt2lou.mf
%
%% Cyrillic font container with T2 encoding beta-support
%
% This file is future part of lxfonts package
% Version 3.2 // Patchlevel=0
% (c) O.Lapko
%
% This package belongs to the public domain under conditions similar to
% those of D. E. Knuth specified for the Computer Modern family of fonts.
% In particular, only the author is entitled to modify this file
% 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
% TSHE          "42  B   "82   -    -    Tshe
% DJE           "43  C   "83   -    -    Dje
% 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
% LAT_I         "49  I    -    -    -    Latin letter I (goes first for LH font)
% LAT_J         "4a  J    -    -    -    Je - Latin letter J
% LJE           "4b  K  !"87  "88   -    Lje
% M_dsc         "4c  L    -    -   "88   Em with descender
% NJE           "4d  M  !"9b  "99   -    Nje
% 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
% LAT_S         "53  S   "8f   -    -    Dze - Latin letter S
% TETSE         "54  T    -    -   "81   Ligature Te-Tse
% DZHE          "55  U   "96   -   "96   Dzhe
% CH_vcrs       "56  V   "97   -    -    Che vertically crossed
% LAT_W         "57  W    -    -    -    Latin letter W
% YAT           "58  X    -    -   "93   Yat
% B_YUS         "59  Y    -    -   "9b   Big Yus
% IZH           "5a  Z    -    -   "94   Izhitsa
%
% N_ltl         "1c       -    -   "99   En with left tail
% DELTA         "1e       -   "86   -    Delta
% M_tl           -        -    -   "8e   Em with tail
% R_gcrs         -        -    -   "86   Er crossed
% S_acrs         -        -    -   "91   Es crossed
% G_crsdsc       -        -   "80   -    Ghe crossed with descender
% H_hcrs         -        -   "94   -    Kha horisontally crossed
%

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

% Latin I goes first for LH font
lhchar "Uppercase Cyrillic letter LAT_I - Latin I (as latin I)";
cyrchar(LAT_I,max(6u#,4u#+cap_stem#),cap_height#,0);
if is_small_cap: getcharcode(lat_i); fi
italcorr cap_height#*slant-.25u#;
adjust_fit(cap_serif_fit#,cap_serif_fit#);
% upper_ukri; - borrowed from ec
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
lft x1l=lft x2l=hround(.5w-.5cap_stem); top y1=cap_height; bot y2=0;
filldraw stroke z1e--z2e; % stem
if serifs or monospace:
 dish_serif(1,2,a,1/3,1.05cap_jut,b,1/3,1.05cap_jut);  % upper serif
 dish_serif(2,1,c,1/3,1.05cap_jut,d,1/3,1.05cap_jut);  fi % lower serif
if slitex:
 pickup crisp.nib;           % arms based on proportions of uppercase E
 pos3(slab,90); pos4(slab if not serifs:+2stem_corr fi,-90);
 x3=x4=x1; top y3r=h; bot y4r=0;
 pos5(hair,0); pos6(hair,0); % top and bottom right arms
 rt x5r=rt x6r=hround(w-u);
 pos7(hair,180); pos8(hair,180); % top and bottom left arms
 lft x7r=lft x8r=hround(u);
 y5=y7=good.y(y3l-beak)-eps; % beak in case we ever want a beaked serif!
 y6=y8=good.y(y4l+beak)+eps; % watch that this doesn't get too heavy
 arm(3,5,a,darkness,jut); arm(3,7,b,darkness,jut); % top left and right arms
 arm(4,6,c,darkness,jut); arm(4,8,d,darkness,jut); % bottom left and right
fi
%%%%%
penlabels(1,2,3,4,5,6,7,8); endchar;

if not more_letters: endinput \\; fi

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 TSHE (Soft T - like Th)";
cyrchar(TSHE,13u#,cap_height#,0);
if is_small_cap: getcharcode(tshe); fi
italcorr cap_height#*slant-beak_jut#-u#; %Gamma-.75u#
adjust_fit(0,.75u#);
pickup tiny.nib; pos1(cap_stem,0); pos2(cap_stem,0);
lft x1l=lft x2l=hround(.5w-.5cap_stem-u)-eps; 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-1.65u); y4=good.y(y3l-.7beak)-eps;
arm(3,4,e,beak_darkness,.7beak_jut); % right arm and beak
pos5(hair,180); x5=w-x4-u; y5=good.y(y3l-beak)-eps;
arm(3,5,f,beak_darkness,-beak_jut);  % left arm and beak
% h_part;
pickup tiny.nib; pos6(stem,0); x6=hround(w-2.5u+.5stem);
h_stroke(2,q,6,7);
dish_serif(7,6,g,1/3,.75cap_jut,h,1/3,.75cap_jut);
if serifs:
 dish_serif(2,1,c,1/3,cap_jut,d,1/3,.75cap_jut);  % lower serif
 nodish_serif(1,2,a,1/3,.5cap_jut,b,1/3,.5cap_jut); fi  % upper bracketing
penlabels(1,2,3,4,5,6,7); endchar;

lhchar "Uppercase Cyrillic letter DJE (Soft DJ - Th with a tail)";
cyrchar(DJE,13u#-width_adj#,cap_height#,0);
if is_small_cap: getcharcode(dje); fi
italcorr cap_height#*slant-beak_jut#-.25u#;
adjust_fit(0,2.5u#);
if odd(cap_stem-w): change_width; fi % symmetric
% upper_dje;
full_h:=h; h:=x_height;
% h_stroke_part+bulb
pickup tiny.nib; lft x1l=lft x2l=hround(.5w-.5cap_stem)-eps;
bot y2=0; pos2(cap_stem,0);
% upperh_stroke
penpos2''(min(rt x2r-lft x2l,thin_join)-fine,180);
pickup fine.nib; pos3(curve,0); pos4(vair,90);
y3=1/3[bar_height,x_height];
if serifs:
 x3=r-letter_fit-hround max(1.5u,2.5u-.5curve)+eps; %.5u right
 else: rt x3r=r-letter_fit-hround.65u+eps; fi
rt x2''l=tiny.rt x2r; y2''=1/8[bar_height,x_height];
x4=.5[rt x2''l,rt x3r]; top y4r=x_height+o;
(x,y4l)=whatever[z4r,z2''l]; x4l:=x;
filldraw stroke z2''e{up}...{right}z4e
 & {{interim superness:=hein_super; super_arc.e(4,3)}};  % arch
%%%%%
% tail
pos5(curve,0); pos6(vair,-90);
x5=x3; y5=2/3[bot y6r,y3]; bot y6r=-o;
if serifs:
 numeric bulb_diam; bulb_diam=flare+(cap_stem-stem);
 pos7(hair,-180); pos7'(bulb_diam,-180);
 lft x7r=min(rt x2r+1.5u,lft x3r-bulb_diam-eps);
 x6=max(lft x7r+.5bulb_diam,.4[lft x7r,rt x5r]);
 y7=1/6cap_height-max(0,flare-stem-2vair_corr-.5); z7r=z7'r;
 cyrbulb(6,7,7'); % bulb
else:
 pos7(flare,-105);
 x6=.4[lft x7r,rt x5r];
 lft x7r=rt x2r+1.25u+eps; bot y7r=0;
 filldraw stroke term.e(6,7,left,.8,4); fi
filldraw stroke z3e--z5e{down}...pulled_arc.e(5,6);
% T part
h:=full_h; pickup tiny.nib; pos1(cap_stem,0); top y1=h;
filldraw stroke z1e--z2e; % stem
pickup crisp.nib; pos8(slab,90); pos9(hair,0);
top y8r=h; x8=x1; rt x9r=hround(w-.65u); y9=good.y(y8l-.7beak)-eps;
arm(8,9,e,beak_darkness,.7beak_jut);  % right arm and beak
pos10(hair,180); x10=w-x9; y10=good.y(y8l-beak)-eps;
arm(8,10,f,beak_darkness,-beak_jut);  % left arm and beak
if serifs:
 dish_serif(2,1,c,1/3,1.414cap_jut,d,1/3,.5cap_jut);  % lower serif
 nodish_serif(1,2,aa,1/3,.5cap_jut,b,1/3,.5cap_jut); fi  % upper bracketing
penlabels(1,2,3,4,5,6,7,8,9,10); 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 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 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(.5[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;

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-eps))+(x3e-x3),y4e)
  and (x3e,good.y(min(y6-.5,1/3h-eps)+1/3(y4e-y4)))..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=.5(x1l-x3r)+.5crisp+eps;
 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); fi % upper left serif
%%%%%
% 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,7,8,9); % ogonek
else:
   numeric right_jut;
   right_jut=
      if serifs: max(limit_dist,1.1cap_jut) else: hround (r-rt x2r-.65u) fi;
   r_serif(2,1,x,1/3,cap_jut,y,1/3,beak_darkness,right_jut,beak_jut); % lower rt descender
fi
penlabels(1,2,3,4,5,6, 7,8,9); endchar;

% Latin I goes first for LH font

lhchar "Uppercase Cyrillic letter LAT_J (as Latin J)";
cyrchar(LAT_J,9u#,cap_height#,0);
if is_small_cap: getcharcode(lat_j); fi
italcorr cap_height#*slant-cap_serif_fit#
 +.75cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(0,cap_serif_fit#);
pickup tiny.nib; pos1(cap_stem',0); pos2(cap_stem',0);
top y1=h; rt x1r=hround(w-2u); x2=x1; y2=.21h;
if serifs: pos3(vair,-90); pos4(cap_hair,-180);
 pos5(flare+(cap_stem-stem),-180);
 bot y3r=-o; x3=.5[x4,x2]; y5=1/6h; rt x5l=hround 2.75u; z5r=z4r;
 filldraw stroke z1e--z2e & super_arc.e(2,3);  % stem and arc
 dish_serif(1,2,a,1/3,1.3cap_jut,b,1/3,.75cap_jut);  % serif
 bulb(3,4,5);  % bulb
else: filldraw stroke z1e--z2e;  % stem
 pickup fine.nib; pos3(cap_stem',0); z3=z2;
 pos4(flare,angle(6.5u,-h)); pos5(1.1flare,-100);
 bot y4r=-o; x4r=.5[x5r,x3r]; lft x5r=hround.75u; bot y5r=vround.06h-o;
 filldraw stroke z3e{down}....term.e(4,5,left,1,4); fi % arc and terminal
penlabels(1,2,3,4,5); endchar;

lhchar "Uppercase Cyrillic letter LJE (Soft L)";
cyrchar(LJE,13.5u#,cap_height#,0); % DL_width:N_width
if is_small_cap: getcharcode(lje); fi;
italcorr .52*.7cap_height#*slant-.5u#; % D*.52h
adjust_fit(cap_serif_fit# if not serifs:+.5(cap_stem#-u#) fi, %DL_adj
 5.75u#-.5width_adj#);% usftsn_adj;usftsnwd-.25u-.5width_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-eps))+(x3e-x3),y4e)
  and (x3e,good.y(min(y6-.5,1/3h-eps)+1/3(y4e-y4)))..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=.5(x1l-x3r)+.5crisp+eps;
 nodish_serif(2,1,a,1/3,cap_jut,b,1/3,.5cap_jut); %!!! % lower right serif
 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); fi %upper left serif
%%%%%
% now the b part
w:=w+5.75u-.5width_adj;%usftsnwd-.5u-.5width_adj
% usftsn_bowl(2);
_zero:=2;
_one:=7; _two:=8; _three:=9; _four:=10; _five:=11;
%
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-1.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-2.5u];
 y[_one]l=y[_two]l-.35cap_bar=.52h-.5cap_bar;
 x[_two]=x[_four]-.35u; fi
x[_two]l:=x[_four]l:=x[_two]-.25cap_curve;
fill stroke z[_five]e..pulled_arc.e([_four],[_three])
 & pulled_arc.e([_three],[_two])..z[_one]e; % lobe
%%%
%%%%%
penlabels(1,2,3,4,5,6,7,8,9,10,11); 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/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=(x4 if not serifs: l if is_bold: +.4tiny fi\\ fi,.5the_pen)
       if serifs and not is_egyptian: +(.5xvair,0) fi;
   easy_ogonek(the_pen,9,10,11); % ogonek
else:
   numeric right_jut;
   right_jut=if serifs: max(limit_dist,1.1cap_jut) else: hround (r-rt x4r-.65u) fi;
   r_serif(4,3,x,1/3,cap_jut,y,1/3,beak_darkness,right_jut,beak_jut); % lower rt descender
fi
penlabels(0,1,1',2,3,3',4,5,6,7,8, 9,10,11); endchar;

lhchar "Uppercase Cyrillic letter NJE (Soft N - looks like Hb)";
cyrchar(NJE,13.5u#,cap_height#,0);
if is_small_cap: getcharcode(nje); fi;
italcorr .52*.7cap_height#*slant-.5u#; % D*.52h
adjust_fit(cap_serif_fit#,5.75u#-.5width_adj#);% usftsn_adj;usftsnwd-.25u-.5width_adj
% 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 rt serif
 nodish_serif(4,3,g,1/3,inner_jut,h,1/3,.5cap_jut); fi  %!!!% lower rt serif
%%%%%
% now the b part
w:=w+5.75u-.5width_adj;%usftsnwd-.25u-.5width_adj
% usftsn_bowl(4);
_zero:=4;
_one:=7; _two:=8; _three:=9; _four:=10; _five:=11;
%
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-1.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-2.5u];
 y[_one]l=y[_two]l-.35cap_bar=.52h-.5cap_bar;
 x[_two]=x[_four]-.35u; fi
x[_two]l:=x[_four]l:=x[_two]-.25cap_curve;
fill stroke z[_five]e..pulled_arc.e([_four],[_three])
 & pulled_arc.e([_three],[_two])..z[_one]e; % lobe
%%%
penlabels(1,2,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=.5(x3l-x1r)+eps;
 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
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 rt 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 rt descender
fi
penlabels(1,2,3,4,5, 6,7,8); endchar;

lhchar "Uppercase Cyrillic letter LAT_S - DZE";
cyrchar(LAT_S,10u#,cap_height#,0);
if is_small_cap: getcharcode(lat_s); fi
italcorr cap_height#*slant-u#;
adjust_fit(0,0);
numeric theta; theta=90-angle(50u,h); slope:=-h/50u;  % angle at middle
numeric s_slab; s_slab=if serifs:slab else:vround .2[slab,cap_stem] fi;
numeric ess'; ess'=max(fine.breadth,cap_ess);
pickup fine.nib; pos2(max(fine.breadth,s_slab-vround vair_corr),-90);
pos0(ess',theta); pos7(s_slab,-90);
x2+x7=2x0=w; x7-x2=if serifs: u else: 0 fi; top y2l=h+o; bot y7r=-o;
y0=.52h; lft x3l=hround u; rt x6r=hround(w-u);
x3r-x3l=x6r-x6l=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;
filldraw stroke super_arc.e(2,3) & z3e{down}
 ..z4e---z5e..z6e{down} & super_arc.e(6,7);  % main stroke
if serifs:
 pos1(hair,180); pos8(hair,180);
 rt x1l=hround(w-1.5u); lft x8r=hround u;
 bot y1=vround 2/3h+1; top y8=vround 1/3h-1;
 %bot y1=good.y(vround 2/3h+1-eps); top y8=vround 1/3h-1;
 filldraw stroke z1e{x2-x1,10(y2-y1)}....{left}z2e;  % upper arc
 filldraw stroke z7e{left}....{up}z8e;  % lower arc
 path upper_arc, lower_arc;
 upper_arc=z1{x2-x1,10(y2-y1)}....{left}z2;
 lower_arc=z7{left}....{up}z8;
 pos10(.3[fine.breadth,cap_hair],0); pos9(.3[fine.breadth,cap_hair],0);
 x10r=x1l; top y10=top y2l; x9l=x8r; bot y9=bot y7r;
 x1l-x1'=x8'-x8r=1.6cap_curve-fine; y1'=y1; y8'=y8;
 numeric t; t=xpart(upper_arc intersectiontimes(z10l--z1'));
 filldraw z1l--z10r--z10l--subpath(t,0) of upper_arc--cycle;  % upper barb
 t:=xpart(lower_arc intersectiontimes(z9r--z8'));
 filldraw z8r--z9l--z9r--subpath(t,1) of lower_arc--cycle;  % lower barb
else:
 pos1(1.2flare,-100); pos8(1.2flare,-100);
 x1l=good.x(x1l+w-1.75u-rt x1); lft x8r=hround .8u;
 top y1l=vround .93h+o; bot y8r=vround .1h-o;
 filldraw stroke term.e(2,1,right,.9,4);   % upper arc and terminal
 filldraw stroke term.e(7,8,left,1,4); fi  % lower arc and terminal
penlabels(0,1,1',2,3,4,5,6,7,8,8',9,10); 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
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:=.5(x3l-x1r)+.5crisp+eps;
 save slab; slab:=arm_thickness; % bottom.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.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:=.5(x3l-x1r)+.5crisp+eps;
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 rt descender
penlabels(1,2,3,4,5,6,7); endchar;

lhchar "Uppercase Cyrillic letter DZHE (Hard DJ)";
cyrchar(DZHE,13.5u#,cap_height#,cap_sbeak#); % N_width;TSE
if is_small_cap: getcharcode(dzhe); fi;
italcorr cap_height#*slant-cap_serif_fit#+cap_jut#-2.5u#+min(.5cap_stem#,u#);
adjust_fit(cap_serif_fit#,cap_serif_fit#);
% Tse_part;
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
numeric inner_jut,arm_thickness;
arm_thickness=vround(slab+vair_corr);
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,c,1/3,cap_jut,d,1/3,inner_jut); % upper left serif
 dish_serif(3,4,g,1/3,inner_jut,h,1/3,cap_jut);   % upper rt serif
 inner_jut:=.5(x3l-x1r)+.5crisp+eps;
 save slab; slab:=arm_thickness; % bottom.slab
 nodish_serif(2,1,a,1/3,cap_jut,b,1/3,inner_jut);  % lower left serif
 nodish_serif(4,3,e,1/3,inner_jut,f,1/3,cap_jut);  % lower rt serif
else:
 save slab; slab:=arm_thickness; % bottom.slab
 lft x1'= lft x1l; bot y1'l=0; pos1'(slab,90);
 rt x3'=rt x3r; y3'=y1'; pos3'(slab,90);
 filldraw stroke z1'e--z3'e; fi % lower bar
% uppercase middle descender
x5=.5[x2,x4]; bot y5=0; x6=x5; bot y6=-d;
if hefty:
   pos5(max(tiny.breadth,fudged.cap_stem if hefty:-4stem_corr fi),0);
   pos6(max(tiny.breadth,fudged.cap_stem if hefty:-4stem_corr fi),0);
   filldraw stroke z5e--z6e;
else:
   numeric light_hair;
   light_hair=min(fudged.stem,fudged.hair if hefty:-4stem_corr fi);
   pos5(light_hair+cap_jut,0); pos6(light_hair,0);
   filldraw z5l{right}... 1/3[.5[z5l,z6l],(x6l,y5l)]{z6l-z5l}...{down}z6l
       --z6r{up}...1/3[.5[z6r,z5r],(x6r,y5r)]{z5r-z6r}...{right}z5r
       --cycle; % miggle stem
fi
penlabels(1,2,3,4,5,6); 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 YAT";
cyrchar(YAT,12.5u#,body_height#,0);
if is_small_cap: getcharcode(yat); fi
italcorr .75cap_height#*slant-.5u#;
adjust_fit(2u#+cap_serif_fit#,0);
% upper_yat;
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
full_h:=h; h:=cap_height;
% 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-1.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-2.5u];
 y[_one]l=y[_two]l-.35cap_bar=.52h-.5cap_bar;
 x[_two]=x[_four]-.35u; fi
x[_two]l:=x[_four]l:=x[_two]-.25cap_curve;
fill stroke z[_five]e..pulled_arc.e([_four],[_three])
 & pulled_arc.e([_three],[_two])..z[_one]e; % lobe
%%%
h:=full_h;
% yat beaks
pickup crisp.nib; pos8(slab,90); pos9(hair,0);
top y8r=vround .85h; x8=x1; rt x9r=hround(w-2.65u); y9=good.y(y8l-2/3beak)-eps;
arm(8,9,m,beak_darkness,2/3beak_jut);  % right arm and beak
pos10(hair,180); x10=w-x9-4u; y10=y9;
arm(8,10,p,beak_darkness,-2/3beak_jut);  % left arm and beak
%%%%%
penlabels(1,2,3,4,5,6,7,8,9,10); endchar;

iff not specific:%
lhchar "Uppercase Cyrillic letter B_YUS - BIG YUS (`roman')";
cyrchar(B_YUS,18u#,cap_height#,0);
if is_small_cap: getcharcode(b_yus); fi
adjust_fit(cap_serif_fit#,cap_serif_fit#);
if odd(fudged.cap_stem-w): change_width; fi % symmetric & all three equal
% upperr_yus;
% top_Yus;
numeric stem[];
stem1=fudged.cap_stem if hefty:-3stem_corr fi;
stem2=min(stem1,cap_hair if hefty:-2stem_corr fi);
penpos1(stem1,0); penpos2(stem2,0); penpos3(stem1,0); penpos4(stem2,0);
x1l=w-x2r=.2w; y1=h; y2=y1; y3=y4=.52h;
x3l=hround(.5w-.5stem1); x3r=x4r;
z0'=whatever[z4l,z2l]=whatever[z1r,z3r];
if hefty:
 numeric lower_notch; lower_notch=y3+cap_notch_cut;
 fill z3l--diag_end(3l,1l,1,1,1r,3r){z3r-z1r}
 if y0'<=lower_notch: ..{z3r-z1r}z0'{z2l-z4l}..
  else: ...{down}(x0'+.5,lower_notch)--(x0'-.5,lower_notch){up}... fi
 {z2l-z4l}diag_end(4l,2l,1,1,2r,4r)--z4r--cycle; %v
else:
 fill z3l--diag_end(3l,1l,1,1,1r,3r)--z0'--
  diag_end(4l,2l,1,1,2r,4r)--z4r--cycle; fi %v
penpos5(stem1,0); x5=x3; y5=0;
fill z3l--diag_end(3l,5l,1,1,5r,3r)--z3r--cycle; %middle stem
z6=whatever[z4,z2]; z7=whatever[z1,z3]; y6=y7=good.y(y1-slab);
fill z1--z7--z6--z2--cycle; % upper bar
% Yus_rbowl;
pickup tiny.nib; numeric stem[],alpha[],right_jut,middle_weight;
right_jut=.6cap_jut; middle_weight=cap_bar;
penpos10(middle_weight,90);
y10r=y3+.5min(cap_bar,cap_notch_cut); x10=x3; y9=y12=.8y10;
rt x8r=w-lft x11l=hround(r-letter_fit-.3u-right_jut); bot y8=bot y11=y5;
stem2=max(tiny.breadth,fudged.cap_stem-3stem_corr);
alpha2=diag_ratio(1,.5(stem2-tiny),h-y8,x8r-x3);
penpos8(alpha2*(stem2-tiny),0); penpos11(alpha2*(stem2-tiny),0);
forsuffixes $=l,r: y8'$=0; y11'$=0; endfor
z8'r=z8r+penoffset (x3,h)-z8 of currentpen+whatever*((x3,h)-z8);
z8'l=z8l+penoffset z8-(x3,h) of currentpen+whatever*((x3,h)-z8);
z11'r=z11r+penoffset (x3,h)-z11 of currentpen+whatever*((x3,h)-z11);
z11'l=z11l+penoffset z11-(x3,h) of currentpen+whatever*((x3,h)-z11);
z8'=.5[z8'l,z8'r]; z11'=.5[z11'l,z11'r];
z9=z8'+whatever*((x3,h)-z8);  z12=z11'+whatever*((x3,h)-z11);
penpos9(cap_stem-2stem_corr,0); penpos12(cap_stem-2stem_corr,0);
fill z10l{right}...{z8'l-z9l}z9l--diag_end(9l,8'l,.5,1,8'r,9r)
 --z9r{z9r-z8'r}...{left}z10r--cycle; % right diagonal
 fill z10r{left}...{z11'l-z12l}z12l--diag_end(12l,11'l,1,.5,11'r,12r)
  --z12r{z12r-z11'r}...{right}z10l--cycle; % left diagonal
if serifs:
 numeric inner_jut; prime_points_inside(5,3);
 if rt x5r+cap_jut+.5u+1<=lft x8l-cap_jut: inner_jut=cap_jut;
  else: rt x5r+cap_jut+.5u+1=lft x8l-inner_jut; fi
 dish_serif(11,12,a,1/3,right_jut,b,1/2,inner_jut)(dark); % lower diagonal serif
 dish_serif(8,9,e,1/2,inner_jut,f,1/3,right_jut)(dark); % lower diagonal serif
 dish_serif(5',3,c,1/3,.75jut,d,1/3,.75jut); fi % middle serif
%%%%%
penlabels(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); endchar;

lhchar "Uppercase Cyrillic letter IZH - IZHITSA (looks like V)";
cyrchar(IZH,13u#,cap_height#,0);
if is_small_cap: getcharcode(izh); fi
italcorr cap_height#*slant+.25u#;
adjust_fit(cap_serif_fit#,
 if serifs: min(1.5u#,.5u#+(flare#+(cap_stem#-stem#))) %ccL_adj
 else:.5u#fi);
% upper_izh;
numeric left_stem,right_stem,outer_jut,alpha;
left_stem=cap_stem-stem_corr;
right_stem=min(cap_hair if hefty:-2stem_corr fi,left_stem);
outer_jut=.75cap_jut; x1l=w-x4r=l+letter_fit+outer_jut+.25u; y1=y4=h;
x2-x1=x4-x3; x2l+apex_corr=x3l; y2=y3=-apex_o;
alpha=diag_ratio(2,right_stem,y1-y2,x4r-x1l-apex_corr);
penpos1(alpha*left_stem,0); penpos2(alpha*left_stem,0);
penpos3(alpha*right_stem,0); penpos4(alpha*right_stem,0);
z0=whatever[z1r,z2r]=whatever[z3l,z4l];
x6=if serifs:.5[x5,x7r] else: x7r fi;
penpos6(vair,90); y6r=h if serifs:+o fi;
penpos5(alpha*right_stem,0);
y5=min(.9cap_height,bot y6l-.5vair); z5=whatever[z3,z4];
x7r=hround(r-.5u); penpos7(hair,0);
y7=h-vround max(.05fig_height+.5flare,.1fig_height-.5flare)+o; z8r=z7r;
penpos8(flare,0); if serifs: cyrbulb(6,7,8); fi
if y0>cap_notch_cut:
 y0:=cap_notch_cut;
 fill z0+.5right{up}...{z4-z3}z5l...{right}
      if serifs: z6r--z6l
      else:
         (.5[x4,x4r],y6r)--(fine.lft x6r,y6r)..(x6r,fine.bot y6r)--
         (x6l,fine.top y6l)..(fine.lft x6l,y6l) fi
  {left}
  ....z5r{z3-z4}--diag_end(4r,3r,1,1,2l,1l)--diag_end(2l,1l,1,1,1r,2r){z2-z1}
  ...{down}z0+.5left--cycle; % left and right diagonals
else:
 fill z0--z5l{z4-z3}...{right}z6r--z6l{left}...{z3-z4}z5r
  --diag_end(4r,3r,1,1,2l,1l)
  --diag_end(2l,1l,1,1,1r,0)--cycle; fi % left and right diagonals
if serifs:
 numeric inner_jut; pickup tiny.nib;
 prime_points_inside(1,2);
 if rt x1'r+cap_jut+.5u+1<=x4l-cap_jut: inner_jut=cap_jut;
  else: rt x1'r+inner_jut+.5u+1=x4l-inner_jut; fi
 dish_serif(1',2,a,1/3,outer_jut,b,1/2,inner_jut); fi % left serif
%%%%%
penlabels(0,1,2,3,4,5,6,7,8); 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 rt serif
 dish_serif(4,3,g,1/3,inner_jut,h,1/3,cap_jut); fi  % lower rt 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=-.85d;
 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
	(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);
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=-.85d;
 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 crossed (looks like P)";
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 - S crossed (looks like C)";
cyrchar(S_acrs,13u#,cap_height#,0);
if is_small_cap: getcharcode(s); 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 crossed";
cyrchar(S_acrs,11.5u#,cap_height#,0);
if is_small_cap: getcharcode(s); 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 %bot.slab
   r_serif(2,1,x,1/3,cap_jut,y,1/3,beak_darkness,right_jut,beak_jut); % lower rt 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;

endinput;
% end of file
