% This is  UPPERXYZ.MF
% Version 1.0d 
% Date 12-MAR-2004
% 
% (c) 1991--2004 by J"org Knappen. See fc.rme for copying conditions
% This file is part of the fc-package 
% See fc.rme for more information
%
% Contents:
%
% The following characters are generated without condition:
%
% X,Y,Z
%
% And the following on demand, i. e. if their code is known:
%
% hooktop_Y, Zhe (Ezh)
%
% Higher versions of this file might include more characters.

cmchar "The letter X";
beginchar("X",13u#,cap_height#,0);
italcorr cap_height#*slant-.25u#;
adjust_fit(cap_serif_fit#,cap_serif_fit#);
numeric stem[],outer_jut,xjut,alpha[];
stem1=cap_stem-2stem_corr; stem2=min(cap_hair,stem1);
outer_jut=.75cap_jut; xjut= if serifs: (stem1-stem2)/4 else: 0 fi;
x1l=l+letter_fit+.5u+outer_jut; x2r=r-letter_fit-u-outer_jut-xjut;
x3l=l+letter_fit+.25u+outer_jut+xjut; x4r=r-letter_fit-.25u-outer_jut;
y1=y2=h; y3=y4=0;
alpha1=diag_ratio(1,stem1,h,x4r-x1l);
alpha2=diag_ratio(1,stem2,h,x2r-x3l);
penpos1(alpha1*stem1,0); penpos2(alpha2*stem2,0);
penpos3(alpha2*stem2,0); penpos4(alpha1*stem1,0);
if hefty: z0=whatever[z1,z4]=whatever[z2,z3];
 x12=x34=x0; y13=y24=y0;
 z12=whatever[z2l,z3l]; z13=whatever[z2l,z3l];
 z24=whatever[z2r,z3r]; z34=whatever[z2r,z3r];
 forsuffixes $=13,24,34: z$'=.1[z$,z0]; endfor
 fill diag_end(12,1r,.5,1,1l,13')--z13'--diag_end(13',3l,1,.5,3r,34')--z34'
  --diag_end(34',4l,.5,1,4r,24')--z24'
  --diag_end(24',2r,1,.5,2l,12)--z12--cycle; % diagonals
else: fill diag_end(4r,1r,.5,1,1l,4l)
  --diag_end(1l,4l,.5,1,4r,1r)--cycle; % left diagonal
 fill diag_end(2l,3l,.5,1,3r,2r)
  --diag_end(3r,2r,.5,1,2l,3l)--cycle; 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
math_fit(0,.5ic#); penlabels(0,1,2,3,4,12,13,24,34); endchar;

cmchar "The letter Y";
beginchar("Y",13u#,cap_height#,0);
italcorr cap_height#*slant+.45u#;
adjust_fit(cap_serif_fit#,cap_serif_fit#);
numeric left_stem,right_stem,outer_jut,dy,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+.05u;
x2l=x5l=hround(.5w-.5left_stem); x3r=x5r; y1=y4=h; y2=y3=y5=.4h;
dy=y1-y2; alpha=((x2l-x1l)++dy)/dy;
penpos1(alpha*left_stem,0); penpos2(alpha*left_stem,0);
penpos3(alpha*right_stem,0); penpos4(alpha*right_stem,0);
penpos5(left_stem,0); penpos6(left_stem,0); x5=x6; y6=0;
z0=whatever[z1r,z2r]=whatever[z3l,z4l];
if y0>y2+cap_notch_cut: y0:=y2+cap_notch_cut;
  fill z0+.5right{up}...{z4-z3}diag_end(3l,4l,1,1,4r,3r)--z5r
    --diag_end(5r,6r,1,1,6l,5l)--z5l--diag_end(2l,1l,1,1,1r,2r){z2-z1}
    ...{down}z0+.5left--cycle; % diagonals and stem
else: fill z0--diag_end(0,4l,1,1,4r,3r)--z5r
    --diag_end(5r,6r,1,1,6l,5l)--z5l
    --diag_end(2l,1l,1,1,1r,0)--cycle; fi  % diagonals and stem
if serifs: numeric inner_jut; pickup tiny.nib;
 prime_points_inside(1,2); prime_points_inside(4,3); prime_points_inside(6,5);
 if rt x1'r+cap_jut+.5u+1<=lft x4'l-cap_jut: inner_jut=cap_jut;
 else: rt x1'r+inner_jut+.5u+1=lft x4'l-inner_jut; fi
 dish_serif(1',2,a,1/3,outer_jut,b,1/2,inner_jut);  % upper left serif
 dish_serif(4',3,c,.6,inner_jut,d,1/2,outer_jut)(dark);  % upper right serif
 dish_serif(6',5,e,1/3,cap_jut,f,1/3,cap_jut); fi  % lower serif
math_fit(.5u#-cap_height#*slant,ic#-4u#);
penlabels(0,1,2,3,4,5,6); endchar;

iff known hooktop_Y:
cmchar "Capital letter hooktop Y";
beginchar(hooktop_Y,15u#,cap_height#,0);
italcorr cap_height#*slant+.45u#;
adjust_fit(cap_serif_fit#,cap_serif_fit#);
numeric left_stem,right_stem,outer_jut,dy,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-3u-x4r=l+letter_fit+outer_jut+.05u;
x2l=x5l=hround(.5w-u-.5left_stem); x3r=x5r; y1=y4=h; y2=y3=y5=.4h;
dy=y1-y2; alpha=((x2l-x1l)++dy)/dy;
penpos1(alpha*left_stem,0); penpos2(alpha*left_stem,0);
penpos3(alpha*right_stem,0); penpos4(alpha*right_stem,0);
penpos5(left_stem,0); penpos6(left_stem,0); x5=x6; y6=0;
z0=whatever[z1r,z2r]=whatever[z3l,z4l];
penpos7(alpha*right_stem,0); z7=whatever[z3,z4]; y7=h-.21h;
if y0>y2+cap_notch_cut: y0:=y2+cap_notch_cut;
  fill z0+.5right{up}...{z4-z3}diag_end(3l,7l,1,1,7r,3r)--z5r
    --diag_end(5r,6r,1,1,6l,5l)--z5l--diag_end(2l,1l,1,1,1r,2r){z2-z1}
    ...{down}z0+.5left--cycle; % diagonals and stem
else: fill z0--diag_end(0,7l,1,1,7r,3r)--z5r
    --diag_end(5r,6r,1,1,6l,5l)--z5l
    --diag_end(2l,1l,1,1,1r,0)--cycle; fi  % diagonals and stem
if serifs:
  z7'=z7; penpos7'(alpha*right_stem,180);
  penpos8(cap_band,90); penpos9(cap_hair,0);
  penpos10(flare+(cap_stem-stem),0);
  top y8=h+o; x8=.5[x7,x9]; y10=5/6h; rt x10r=hround(w-.5u);
  z9r=z10r;
  filldraw stroke z7'e{z4-z3}...{right}z8e; % link
  bulb(8,9,10); % bulb
else:
%  pickup fine.nib; 
  pos8(cap_band,0); z8=z7;      
  pos9(flare,angle(6.5u,-h)); pos10(flare,-100);
  top y9l=h+o; x9l=.5[x8l,x10l]; rt x10l=hround(w-.5u);
  top y10l=vround.94h+o;
  filldraw stroke z7e{z4-z3}....term.e(9,10,right,1,10);
fi
if serifs: numeric inner_jut; pickup tiny.nib;
 prime_points_inside(1,2); prime_points_inside(4,3); prime_points_inside(6,5);
 if rt x1'r+cap_jut+.5u+1<=lft x4'l-cap_jut: inner_jut=cap_jut;
 else: rt x1'r+inner_jut+.5u+1=lft x4'l-inner_jut; fi
 dish_serif(1',2,a,1/3,outer_jut,b,1/2,inner_jut);  % upper left serif
% dish_serif(4',3,c,.6,inner_jut,d,1/2,outer_jut)(dark);  % upper right serif
 dish_serif(6',5,e,1/3,cap_jut,f,1/3,cap_jut); fi  % lower serif
math_fit(.5u#-cap_height#*slant,ic#-4u#);
penlabels(0,1,2,3,4,5,6); endchar;

cmchar "The letter Z";
beginchar("Z",11u#,cap_height#,0);
italcorr cap_height#*slant-.5u#;
adjust_fit(0,0);
numeric arm_thickness[],z_stem;
if hefty: arm_thickness1=Vround(slab-vair_corr); arm_thickness2=slab;
 z_stem=.8[vair,cap_stem];
else: arm_thickness1=slab; arm_thickness2=vround(slab+vair_corr);
 z_stem=.9[vair,cap_stem]; fi
pickup tiny.nib; x3l=x4l=w-x1r=w-x2r; lft x3l=hround u;
top y1=h; y2=min(y1,h-2/3arm_thickness1);
bot y4=0; y3=max(y4,2/3arm_thickness2);
numeric alpha; alpha=diag_ratio(1,z_stem-tiny,y2-y3,x2r-x3l);
penpos1(alpha*(z_stem-tiny),0); penpos2(alpha*(z_stem-tiny),0);
penpos3(alpha*(z_stem-tiny),0); penpos4(alpha*(z_stem-tiny),0);
pair delta; delta=penoffset z3-z2 of currentpen;
fill top lft z1l--z2l+delta---z3l+delta..lft z3l---lft z4l..bot z4l
 ---bot rt z4r--z3r-delta---z2r-delta..rt z2r---rt z1r..top z1r
 ---cycle;  % diagonal
pickup crisp.nib; pos5(arm_thickness1,90); pos6(hair,180);
top y5r=h; x5=x1; lft x6r=hround 1.25u; y6=good.y(y5l-beak)-eps;
arm(5,6,a,beak_darkness**.8,-.4beak_jut);  % upper arm and beak
pos7(arm_thickness2,-90); pos8(hair,0);
bot y7r=0; x7=x4; rt x8r=hround(w-.9u); y8=good.y(y7l+1.2beak)+eps;
arm(7,8,b,beak_darkness**.9,.6beak_jut);  % lower arm and beak
math_fit(0,.5ic#); penlabels(1,2,3,4,5,6,7,8); endchar;

iff known Zhe:
cmchar "Capital letter EZH";   % jk, adapted from cmoe Yogh by J. Bradfield
beginchar(Zhe,10u#,cap_height#,0);
italcorr cap_height#*slant-.5serif_fit#-.3u#;
adjust_fit(0,0);
numeric arm_thickness,z_stem;
% The following two lines are from greeku.mf (Xi)
arm_thickness=hround .9[vair,.85cap_stem];  
if arm_thickness<crisp.breadth: arm_thickness:=crisp.breadth; fi
z_stem = .1[vair,cap_stem] ;
pickup tiny.nib; rt x1r=rt x2r=hround(w-1.2u);
top y1=h; y2=min(y1,h-2/3arm_thickness);
lft x3l = hround .33w ; bot y3 = vround(.52h-.5arm_thickness);
numeric alpha; alpha=diag_ratio(1,z_stem-tiny,y2-y3,x2r-x3l-slant*(y2-y3));
penpos1(alpha*(z_stem-tiny),0); penpos2(alpha*(z_stem-tiny),0);
penpos3(alpha*(z_stem-tiny),0);
pair delta; delta=penoffset z3-z1 of currentpen;
fill top lft z1l--z1l+delta---z3l+delta..lft z3l
 ..bot z3r--z3r-delta---rt z1r..top z1r
 ---cycle;  % diagonal
z99 = rt z1r ; z98 = z99 + (u,0) ;   % for cutting away
z97 = z99 + 10*(z3-z1) ; z96 = z97 + (u,0) ;
pickup crisp.nib; pos5(arm_thickness,90); pos6(cap_hair,180);
top y5r=h; x5=x1; lft x6r=hround .75u; y6=good.y(y5l-beak/1.6)-eps;
arm(5,6,a,beak_darkness**.8,-.4beak_jut);  % upper arm and beak
% now cut away the excess arm
erase fill z99 --- z98 --- z96 --- z97 --- cycle ;
pickup fine.nib ;
pos10'(vair,90) ; pos11(cap_curve,0) ;
pos12(.1[vair,cap_curve],-90) ;
z10' - z3 = whatever*dir 30 ;
x10' = x3 + u ; x10 = x10' ; y10r = good.y y10'r ; pos10(vair,90) ;
bot y12r = -o ; x12 = .5w ;
y11 = .5[y10,y12] ; rt x11r = hround(w-.9u) ;
z3' = z3 ; z3'l = z3r ; z3'r = z3l ;
filldraw stroke z3'e .. z10e{right} ;
filldraw stroke pulled_arc.e(10,11) & pulled_arc.e(11,12) ;
if serifs: pos13(hair,-180) ; y13=.8bar_height ; lft x13r = hround .8u ;
   pos14(flare,-180) ; bulb(12,13,14) ;
else: pos13(5/7[vair,flare],angle(-3u,-h)) ;
lft x13r = hround .9u ; y13 = .8bar_height ;
x13l := good.x x13l ; y13l := good.y y13l ;
filldraw stroke term.e(12,13,left,1,4) ; fi
penlabels(1,2,3,4,5,6,7,8,10,11,12,13,14); endchar;
 
endinput;
