% blackboard typefaces by Anthony Phan.
% file: mbbromlg.mf (truly ligatured letters)
% last modification: 25.10.2001.

def horizontal_rules_list=
  -body_depth,-desc_depth,0.5x_height,x_height,cap_height,
  asc_height,body_height
enddef;

use_rule1;

% Special rules govern `f'-ligatures. First `f'-width is
% hthick#+thin#+u#+2appr#, the middle bar is 2u# large.
% For `ff' or `fi' or `fl', the two vertical stems should
% be as distant as in `n'. Furthermore, those stems should
% be as distant as two adjacent `i', so the letter_fit#
% as to be taken into account. Then, I take the maximum.
% Alas, those rules are not very stable at low resolution. 

beginchar(bblig_ff,max(9u#+2appr#,2hthick#+2thin#+u#+4appr#),
    asc_height#,if variant_f: desc_depth# else: 0 fi);
  "The ligature ff";
  italcorr asc_height#*slant+1.5u#;
  pickup circle.nib; lft x1=apprl; rt x4=w-apprr-hround u;
  x2-x1=x4-x3=hthick; x5=x2; x6=x3; x7=x4; x8-x7=hround 2u;
  top y5=x_height; y5=y6=y7=y8; draw z5..z6; draw z7..z8;
  complete_f_stroke(1,2,hround 3u,true);
  complete_f_stroke(3,4,hround 3u,true);
  square_end8(right);
  labels(5,6,7,8);
endchar;

beginchar(bblig_fi,max(8u#+2appr#,2hthick#+2thin#+4appr#),
    asc_height#,if variant_f: desc_depth# else: 0 fi);
  "The ligature f_i";
  if square_dots: italcorr asc_height#*slant-.5u#;
  else: italcorr (asc_height#-0.4dot_size#)*slant-.5u#; fi
  pickup circle.nib;
  lft x1=apprl; rt x4=w-apprr; x2-x1=x4-x6=hthick;
  x3=x2; x4=x5=x8; x6=x7=x9;
  top y3=x_height; y3=y4=y7; bot y5=bot y6=0;
  top y8=h; top y8-bot y9=dot_size;
  draw z3..z4; draw z6..z7;
  complete_f_stroke(1,2,x9-x2,false);
  pickup square.nib; draw z4--z5--z6--z7;
  if square_dots: z8.a=(x8,y9);
    draw z1.a--z8--z8.a--z9--cycle;
  else: pickup circle.nib; x8.a=x9.a=0.5[x8,x9];
    y8.b=y9.b=0.5[y9,y8]; y8=y8.a; x8=x8.b; y9=y9.a; x9=x9.b;
    draw z1.a..z8.a right_to_down z8.b down_to_left z9.a
    left_to_up z9.b..z1.a; labels(8.b,9.a,9.b);
  fi
  labels(3,4,5,6,7,8,8.a,9);
endchar;

beginchar(bblig_fl,max(8u#+2appr#,2hthick#+2thin#+4appr#),
    asc_height#,if variant_f: desc_depth# else: 0 fi);
  "The ligature fl";
  italcorr asc_height#*slant-0.5u#;
  pickup circle.nib; lft x1=apprl; rt x3=rt x4=w-apprr;
  x2-x1=x4-x5=hthick; x6=x2; x7=x5;
  top y6=top y7=x_height; top y3=h; bot y4=bot y5=0;
  draw (x5,y3)..z3; draw z6..z7;
  complete_f_stroke(1,2,x5-x2,false);
  pickup square.nib; draw z3--z4--z5--z1.a; 
  labels(3,4,5,6,7);
endchar;

beginchar(bblig_ffl,max(16u#-hthick#-thin#+2appr#,
      3hthick#+3thin#+6appr#),
    asc_height#,if variant_f: desc_depth# else: 0 fi);
  "The ligature ffl";
  italcorr asc_height#*slant-0.5u#;
  center_bar(3,4); lft x1=apprl; rt x5=rt x6=w-apprr;
  x2-x1=x6-x7=hthick; x8=x2; x9=x3; x10=x4; x11=x7;
  top y8=x_height; y8=y9=y10=y11; top y5=h; bot y6=bot y7=0;
  draw (x7,y5)..z5; draw z8..z9; draw z10..z11;
  complete_f_stroke(1,2,hround 3u,true);
  complete_f_stroke(3,4,x7-x4,false);
  pickup square.nib; draw z5--z6--z7--z3.a; 
  labels(5,6,7,6,7,8,9,10,11);
endchar;

beginchar(bblig_ffi,max(16u#-hthick#-thin#+2appr#,
      3hthick#+3thin#+6appr#),
    asc_height#,if variant_f: desc_depth# else: 0 fi);
  "The ligature ffi";
  if square_dots: italcorr asc_height#*slant-.5u#;
  else: italcorr (asc_height#-0.4dot_size#)*slant-.5u#; fi
  center_bar(3,4);
  lft x1=apprl; rt x8=w-apprr; x2-x1=x8-x10=hthick;
  x5=x2; x6=x3; x7=x4; x8=x9=x12; x10=x11=x13;
  top y5=x_height; y5=y6=y7=y8=y11; bot y9=bot y10=0;
  top y12=h; top y12-bot y13=dot_size;
  draw z5..z6; draw z7..z8;
  complete_f_stroke(1,2,hround 3u,true);
  complete_f_stroke(3,4,x13-x4,false);
  pickup square.nib; draw z8--z9--z10--z11;
  if square_dots: z12.a=(x12,y13);
    draw z3.a--z12--z12.a--z13--cycle;
  else: pickup circle.nib; x12.a=x13.a=0.5[x12,x13];
    y12.b=y13.b=0.5[y13,y12]; y12=y12.a;
    x12=x12.b; y13=y13.a; x13=x13.b;
    draw z3.a..z12.a right_to_down z12.b down_to_left z13.a
    left_to_up z13.b..z3.a; labels(12.b,13.a,13.b);
  fi
  labels(5,6,7,8,9,10,11,12,12.a,13);
endchar;

iff known bblig_ct:
beginchar(bblig_ct,13u#+4appr#,min(asc_height#,10/7x_height#),0);
  "The ligature ct";
  italcorr x_height#*slant-0.5thin#-0.5u#;
  pickup circle.nib;
  numeric t_w; t_w=hround((2appr#+6u#)*hppp);  
% the "t" part
  rt x1=rt x2=w-apprr; x3=0.5[x2,x4];
  lft x4=lft x5=w-t_w+apprl; rt x8=floor x1;
  top y7=top y8=x_height; bot y3=-oo;
  top y5=h; y2=y4=0.3[y3,y8];
  top y1=max(vround 0.42x_height,top y2); 
  tmp_path:=z1..z2 down_to_left z3 left_to_up z4..z5;
  % the "c" part
  x11=x15=w-apprr-t_w; lft x13=apprl-ho;
  top y12=x_height+uo; bot y14=-oo; y13=0.5[y14,y12];
  y11=0.707[y13,y12]; y15=0.707[y13,y14];
  tmpp_path:=reverse elliptic_arc(13,12,11)&elliptic_arc(13,14,15);
  % the ligature part
  top y20=top y23=h; z20=whatever[z11',z11];
  z22=0.5[z20,0.5[z11,z5]];
  z21=0.25[z11,z20]; z23=0.25[z5,z20];
  draw z11---z21...z22{z5-z11}...z23---z5;
  draw tmp_path; draw tmpp_path;
  bbbowl(z12,z13,z14,hThick) tmpp_path;
  hbbowl(z3,z4,z5,hthick) tmp_path;
  x7=rt x.bowl.mid;
  pickup square.nib;
  draw z7..z8; draw z5..z.bowl.bot;
  square_end1(up);
  square_end11(z11-z11');
  square_end15(z15-z15');
  labels(range 0 thru 23,11',15');
endchar;

iff known bblig_st:
beginchar(bblig_st,13u#+4appr#,min(asc_height#,10/7x_height#),0);
  "The ligature st";
  italcorr x_height#*slant-0.5thin#-0.5u#;
  numeric t_w; t_w=hround((2appr#+6u#)*hppp);  
  pickup circle.nib;
% the "s" part
  slope:=-x_height/24u; y5=0.52[y8,y2];
  top y2=x_height+uo; bot y8=-oo;
  y2-y1=vround 0.12x_height; y9-y8=vround 0.175x_height;
  lft x3l=lft x9-(0.5thin*(sqrt2-1))=apprl-ho;
  rt x7r=hround((7u#+2appr#)*hppp)-apprr+ho;
  x7r-x1=hround 0.6u+(0.5thin*(sqrt2-1));
  x2=x5=x8=0.5[x3l,x7r];
  x3r-x3l=x7r-x7l=hround 0.5[thin,ess];
  ortho_penpos5(ess,(-1,-slope));
  forsuffixes $=r,l:
    ellipse_set(2,3.$,4.$,5.$); ellipse_set(8,7.$,6.$,5.$);
  endfor
  z1'-z1=(z2-z1)xscaled 1/3; z9-z9'=(z9-z8)xscaled 0.3;
  draw z1{z1'-z1}...z2 left_to_down z3l...z4l
  ---z6l...z7l down_to_left z8;
  draw z2 left_to_down z3r...z4r
  ---z6r...z7r down_to_left z8...{z9-z9'}z9;
  square_end1(z1-z1'); square_end9(z9-z9');
  labels(1,1',2,8,9,9'); penlabels(3,4,5,6,7);
% the "t" part
  rt x10=rt x11=w-apprr; x12=0.5[x11,x13];
  lft x13=lft x14=w-t_w+apprl; rt x16=floor x10;
  top y15=top y16=x_height; bot y12=-oo;
  top y14=h; y11=y13=0.3[y12,y16];
  top y10=max(vround 0.42x_height,top y11); 
  tmp_path:=z10..z11 down_to_left z12 left_to_up z13..z14;
% the ligature part
  top y17=top y20=h; z17=whatever[z1,z1'];
  z19=0.5[z17,0.5[z1,z14]];
  z18=0.25[z1,z17]; z20=0.25[z14,z17];
  draw tmp_path;
  draw z1---z18...z19{z14-z1}...z20---z14;
  hbbowl(z12,z13,z14,hthick) tmp_path;
  x15=rt x.bowl.mid;
  pickup square.nib; draw z14..z.bowl.bot;
  draw z15..z16; square_end10(up);
  labels(10,11,12,13,14,15,16,17,18,19,20);
endchar;