% mathematical symbols by Anthony Phan.
% file: mathadrv.mf (driver file for matha serie,
% U stands for Unsupported)
% last modification: May 16, 2005.

mode_setup;
math_setup;
%
% This file calls calu.mf and then extends
% the superb work of N. N. Billawala into
% a whole OT1 font.
%

%
% First thing to do is to copy Computer Modern's
% control sequences and setup.
%
%slant := 0;
newinternal l, r, shrink_fit; % adjustments to spacing
boolean math_fitting;

flare := dtsz;
flare# := dtsz#;

def cal_setup = 
  let adjust_fit = normal_adjust_fit;
  pickup pencircle xscaled cap_curve yscaled cap_hair rotated 30;
  cal.nib := savepen;
  pair cal.extension; cal.extension := (.75cap_curve, 0) rotated 30;
  pickup pencircle xscaled cap_curve yscaled cap_hair rotated 70;
  tilted.nib := savepen;
  pickup pencircle xscaled curve yscaled cap_hair rotated 70;
  med_tilted.nib := savepen;
  pickup pencircle xscaled cap_stem yscaled cap_hair rotated 30;
  med_cal.nib := savepen;
  pickup pencircle xscaled stem yscaled cap_hair rotated 30;
  light_cal.nib := savepen;
  % 
  % lowercase and punctuation
  %
  pickup pencircle xscaled curve yscaled hair rotated 30;
  lower_cal.nib := savepen;
  lower_cal_width# := curve#*cosd 30+hair#*sind 30;
  pickup pencircle xscaled 0.5[hair, curve] yscaled hair rotated 30;
  fine_cal.nib := savepen;
  %
  pickup pencircle xscaled(cap_curve+dw) yscaled cap_hair rotated 30;
  heavy_cal.nib := savepen;
  bot_flourish_line := -0.5u-o;
  pair bend; bend = (.5u, 0);
  pair flourish_change; flourish_change = (4u, .2asc_height);
  join_radius := u;
  shrink_fit := 1+hround(2letter_fit#*hppp)-2letter_fit;
enddef;

let cmchar = \;
def .... = .. tension atleast .9 .. enddef;
vardef w# = charwd enddef;
vardef d# = chardp enddef;
vardef h# = charht enddef;
vardef ic# = charic enddef;

def do_expansion(expr expansion_factor) = 
  forsuffixes $ = u, jut, cap_jut, beak_jut, apex_corr:
    $ := $.#*expansion_factor*hppp; endfor
enddef;

def normal_adjust_fit(expr left_adjustment, right_adjustment) = 
  numeric charwd_in; charwd_in = charwd;
  l := -hround(left_adjustment*hppp)-letter_fit;
  interim xoffset := -l;
  charwd := charwd+2letter_fit#+left_adjustment+right_adjustment;
  r := l+hround(charwd*hppp)-shrink_fit;
  w := r-hround(right_adjustment*hppp)-letter_fit;
  do_expansion(w/(charwd_in*hppp));
enddef;

def mono_adjust_fit(expr left_adjustment, right_adjustment) = 
  numeric charwd_in; charwd_in = charwd;
  numeric expansion_factor;
  mono_charwd# = 2letter_fit#
  +expansion_factor*(charwd+left_adjustment+right_adjustment);
  l := -hround(left_adjustment*expansion_factor*hppp)-letter_fit;
  interim xoffset := -l;
  r := l+mono_charwd-shrink_fit;
  w := r-hround(right_adjustment*expansion_factor*hppp)-letter_fit;
  charwd := mono_charwd#; charic := mono_charic#;
  do_expansion(w/(charwd_in*hppp));
enddef;

extra_endchar := extra_endchar&"r := r+shrink_fit; w := r-l;";

def ignore_math_fit(expr left_adjustment, right_adjustment) = enddef;

def do_math_fit(expr left_adjustment, right_adjustment) = 
  l := l-hround(left_adjustment*hppp); interim xoffset := -l;
  charwd := charwd+left_adjustment+right_adjustment;
  r := l+hround(charwd*hppp)-shrink_fit;
  charic := charic-right_adjustment;
  if charic<0: charic := 0; fi
enddef;

currenttransform := identity slanted slant
yscaled aspect_ratio scaled granularity;
def t_ = transformed currenttransform enddef;

cal_setup;
autorounding := hair;

%
% UPPERCASE
%

let math_fit = do_math_fit;
math_fitting := true;
input calu.mf;

%
% OTHER CASES
%

let math_fit = ignore_math_fit;
math_fitting := false;

vardef hook_in(suffix $, $$, $$$) = 
  x$ := good.x x$;
  x$$ = max(x$$$-1.25u, 0.5[x$, x$$$]);
  top y$$ = x_height+oo; y$ = good.y 7/8[0, y$$];
  y$$$ = 3/4x_height;
  z$...z$$ right_to_down z$$$
enddef;

vardef hook_out(suffix $, $$, $$$) = 
  x$$$ := good.x x$$$;
  x$$ = min(x$+1.25u, 0.5[x$, x$$$]);
  bot y$$ = -oo; y$ = 1/4x_height; y$$$ = good.y 7/8[x_height, y$$];
  z$ down_to_right z$$...z$$$ % super_arc
enddef;

vardef ital_arch(suffix $, $$, $$$) = 
  x$$ = 0.6[x$, x$$$];
  top y$$ = x_height+oo; y$$$ = 0.65x_height;
  z${up}...z$$ right_to_down z$$$ % super_arc
enddef;

vardef desc_curve(suffix $, $$, $$$) = 
  x$$$ := good.x x$$$; x$$ = 0.6[x$, x$$$];
  y$ = 0; bot y$$ = -d-oo; y$$$ = good.y 1/3[y$$, y$];
  z${down}...z$$ left_to_up z$$$...z$$$+round(1.1u*dir 60)
enddef;

vardef cal_dot@#(expr $, $$, dotsize) = 
  rt x@#a-lft x@#c = top y@#b-bot y@#d = dotsize+2eps;
  rt x@#a = hround($+0.5dotsize)+eps;
  top y@#b = vround($$+0.5dotsize)+eps;
  y@#a = y@#c = 0.5[y@#b, y@#d];
  x@#b = x@#d = 0.5[x@#c, x@#a];
  filldraw superellipse(z@#a, z@#b, z@#c, z@#d, superness);
  labels(@#a, @#b, @#c, @#d);
enddef;

comma_depth# := 0.75desc_depth#;
comma_depth := vround 0.75desc_depth;

vardef cal_comma@#(expr $, $$, deviation, prof) = 
  pickup fine_cal.nib;
  cal_dot@#($, $$, dtsz);
  if $$>prof: bot else: top fi y@#f = prof;
  y@#e = 0.25[$$, y@#f];
  if deviation>0:
    x@#f = x@#c; rt x@#e = hround($+dtsz)+eps;
    draw if $$>prof: z@#b else: z@#d fi right_to_down z@#e
    ...{x@#f-x@#e, (1-superness)*(y@#f-y@#e)}z@#f;
  else:
    x@#f = x@#a; lft x@#e = hround($-dtsz)-eps;
    draw if $$<prof: z@#d else: z@#b fi right_to_up z@#e
    ...{x@#f-x@#e, (1-superness)*(y@#f-y@#e)}z@#f;
  fi
  labels(@#e, @#f);
enddef;

%
% LOWERCASE, DIGITS, PUNCTUATION
%

input mathcall;

%
% GREEK
%

input mathcallgreek;

currenttransform := identity
yscaled aspect_ratio scaled granularity;
autorounding := 0;
extra_endchar := "";
standard_proofing;

extra_endchar := extra_endchar & "; charcode := charcode+code_offset;";
dagesh := false; code_offset := 128;

%
% HEBREW
%

input mathhbrw;

dagesh := true; code_offset := 160;

%
% HEBREAW WITH DAGESH
%

input mathhbrw;

code_offset := 0;

% parameters for TFM files.

font_slant = 0;
font_x_height = x_height#;
font_normal_stretch = 3u#;
font_normal_shrink = 2u#;
font_quad = 18u#+4letter_fit#;
font_extra_space = 2u#;
font_normal_space = 6u#+2letter_fit#;

end.
