% mathematical symbols by Anthony Phan.
% file: mathacnt.mf (accents)
% last modification: May 16, 2005.
% Only known charcodes will be generated.

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

% ACCENTS (nullissime)

diacritics_proofing;% changes extra_endchar for proof mode.
hat_w:=hex"70";
check_w:=hex"71";
tilde_w:=hex"72";
bar_w:=hex"73";
arrow_w:=hex"74";
paren_w:=hex"75";

hat_ww:=hex"78"; hat_www:=hex"79";
hat_wwww:=hex"7A"; hat_wwwww:=hex"7B";
check_ww:=hex"7C"; check_www:=hex"7D";
check_wwww:=hex"7E"; check_wwwww:=hex"7F";
tilde_ww:=hex"80"; tilde_www:=hex"81";
tilde_wwww:=hex"82"; tilde_wwwww:=hex"83";
bar_ww:=hex"84"; bar_www:=hex"85";
bar_wwww:=hex"86"; bar_wwwww:=hex"87";
arrow_ww:=hex"88"; arrow_www:=hex"89";
arrow_wwww:=hex"8A"; arrow_wwwww:=hex"8B";
paren_ww:=hex"8C"; paren_www:=hex"8D";
paren_wwww:=hex"8E"; paren_wwwww:=hex"8F";

charlist hat_w: hat_ww: hat_www: hat_wwww: hat_wwwww;
charlist check_w: check_ww: check_www: check_wwww: check_wwwww;
charlist tilde_w: tilde_ww: tilde_www: tilde_wwww: tilde_wwwww;
charlist bar_w: bar_ww: bar_www: bar_wwww: bar_wwwww;
charlist arrow_w: arrow_ww: arrow_www: arrow_wwww: arrow_wwwww;
charlist paren_w: paren_ww: paren_www: paren_wwww: paren_wwwww;

vardef tmp_program(expr orientation,overshot,appr,coef)=
  save a,b,c;
  pickup crisp.nib;
  b=coef[0.8[vair,stem],stem];
  b'=coef[min(vair,hair),max(vair,hair)];
  if orientation=up:
    top y2r=top y3r=h+overshot;
    bot y1r=bot y4r=vround 0.5[x_height,h];
  else:
    bot y2r=bot y3r=vround 0.5[x_height,h]-overshot;
    top y1r=top y4r=h; fi
  lft x2r=hround 0.5(w-b);
  rt x3r-lft x2r=hround b;
  lft x1r=appr; x4r-x3r=x2r-x1r;
  x=0.5(b-b')/length(z2r-z1r);
  a=if orientation=up: 180+ fi (angle(z2r-z1r)-angle(x,1+-+x));
  pos1(b',a); pos2(b,a); pos3(b,180-a); pos4(b',180-a);
  z0=whatever[z1l,z2l]; z0=whatever[z3l,z4l];
  filldraw z1r--z2r--z3r--z4r--z4l--z0--z1l--cycle;
  penlabels(0,1,2,3,4)
enddef;

use_rule1;

beginchar(hat_accent,7u#+2appr#,min(asc_height#,2x_height#),0);
  "Circumflex accent";
  tmp_program(up,0,appr+u,0);
endchar;

beginchar(hat_w,8u#+2appr#,0.5[asc_height#,body_height#],0);
  "Wide circumflex accent 1";
  tmp_program(up,o,appr-0.5u,0.2);
endchar;

beginchar(hat_ww,16u#+2appr#,body_height#,0);
  "Wide circumflex accent 2";
  tmp_program(up,o,appr-0.5u,0.4);
endchar;

beginchar(hat_www,24u#+2appr#,body_height#,0);
  "Wide circumflex accent 3";
  tmp_program(up,o,appr-0.5u,0.6);
endchar;

beginchar(hat_wwww,32u#+2appr#,body_height#,0);
  "Wide circumflex accent 4";
  tmp_program(up,o,appr-0.5u,0.8);
endchar;

beginchar(hat_wwwww,40u#+2appr#,body_height#,0);
  "Wide circumflex accent 5";
  tmp_program(up,o,appr-0.5u,1);
endchar;

beginchar(check_accent,7u#+2appr#,min(asc_height#,2x_height#),0);
  "Check accent";
  tmp_program(down,0,appr-0.5u,0);
endchar;

beginchar(check_w,8u#+2appr#,0.5[asc_height#,body_height#],0);
  "Wide check accent 1";
  tmp_program(down,o,appr-0.5u,0.2);
endchar;

beginchar(check_ww,16u#+2appr#,body_height#,0);
  "Wide check accent 2";
  tmp_program(down,o,appr-0.5u,0.4);
endchar;

beginchar(check_www,24u#+2appr#,body_height#,0);
  "Wide check accent 3";
  tmp_program(down,o,appr-0.5u,0.6);
endchar;

beginchar(check_wwww,32u#+2appr#,body_height#,0);
  "Wide check accent 4";
  tmp_program(down,o,appr-0.5u,0.8);
endchar;

beginchar(check_wwwww,40u#+2appr#,body_height#,0);
  "Wide check accent 5";
  tmp_program(down,o,appr-0.5u,1);
endchar;

vardef tmp_program(expr height,depth,approach,coef)=
  pickup tiny.nib;
  save a,b,c;
  a=angle(w-2approach,9(height-depth));
  b=angle(w-2approach,-3(height-depth));
  b'=coef[0.5[vair,hair],max(vair,hair)];
  c=coef[0.8[vair,stem],stem];
  pos1(b',a+90); pos9(b',a+90); pos5(c,b+90);
  bot y7l=depth-eps; top y3r=height+eps;
  y1l=good.y 1/6[y7l,y3r]; y3r-y9r=y1l-y7l;
  top y3r-bot y3l=top y7r-bot y7l=vround 0.5[b',c];
  lft x1r=w-rt x9l=approach;
  z5=0.5[z1,z9];
  forsuffixes $=r,l: y2$=y3$=y4$; y6$=y7$=y8$;
    z2$-z1$=whatever*dir a; z8$-z9$=whatever*dir a;
    z4$-z5$=whatever*dir b; z6$-z5$=whatever*dir b;
    x3$=0.666[x2$,x4$]; x7$=0.666[x8$,x6$];
  endfor
  filldraw stroke z1e..controls .666[z1e,z2e] and .666[z3e,z2e]
  ..z3e..controls .666[z3e,z4e] and .666[z5e,z4e]
  ..z5e..controls .666[z5e,z6e] and .666[z7e,z6e]
  ..z7e..controls .666[z7e,z8e] and .666[z9e,z8e]..z9e;
%penlabels(1,2,3,4,5,6,7,8,9);
enddef;

beginchar(tilde_accent,7u#+2appr#,min(asc_height#,2x_height#),0);
  "Tilde accent";
  tmp_program(h,vround 0.5[x_height,asc_height],appr,0);
endchar;

beginchar(tilde_w,8u#+2appr#,0.5[asc_height#,body_height#],0);
  "Wide tilde accent 1";
  tmp_program(h,vround 0.5[x_height,asc_height],appr-0.5u,0.2);
endchar;

beginchar(tilde_ww,16u#+2appr#,body_height#,0);
  "Wide tilde accent 2";
  tmp_program(h,vround 0.5[x_height,asc_height],appr-0.5u,0.4);
endchar;

beginchar(tilde_www,24u#+2appr#,body_height#,0);
  "Wide tilde accent 3";
  tmp_program(h,vround 0.5[x_height,asc_height],appr-0.5u,0.6);
endchar;

beginchar(tilde_wwww,32u#+2appr#,body_height#,0);
  "Wide tilde accent 4";
  tmp_program(h,vround 0.5[x_height,asc_height],appr-0.5u,0.8);
endchar;

beginchar(tilde_wwwww,40u#+2appr#,body_height#,0);
  "Wide tilde accent 5";
  tmp_program(h,vround 0.5[x_height,asc_height],appr-0.5u,1);
endchar;

% changes august 23, 2004.

beginchar(bar_accent,7u#+2appr#,
    %x_height#+body_height#-cap_height#,0);
    0.5[x_height#,asc_height#],0);
  "Bar accent";
  pickup crisp.nib;
  a:=vround 0.0[min(0.2[vair,stem],rth0),rth1];
  pos1(a,90); pos2(a,90); lft x1-appr=w-appr-rt x2=hround 0.25u;
  top y1r=top y2r=vround(h+0.5a);
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(bar_w,8u#+2appr#,
    %x_height#+body_height#-cap_height#,0);
    0.5[x_height#,body_height#],0);
  "Wide bar accent 1";
  pickup crisp.nib;
  a:=vround 0.0[min(0.2[vair,stem],rth0),rth1];
  pos1(a,90); pos2(a,90); lft x1-appr=w-appr-rt x2=hround 0.0u;
  top y1r=top y2r=vround(h+0.5a);
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(bar_ww,16u#+2appr#,
    %x_height#+body_height#-cap_height#,0);
    0.5[x_height#,body_height#],0);
  "Wide bar accent 2";
  pickup crisp.nib;
  a:=vround 0.0[min(0.2[vair,stem],rth0),rth1];
  pos1(a,90); pos2(a,90); lft x1-appr=w-appr-rt x2=hround 0.0u;
  top y1r=top y2r=vround(h+0.5a);
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(bar_www,24u#+2appr#,
    %x_height#+body_height#-cap_height#,0);
    0.5[x_height#,body_height#],0);
  "Wide bar accent 3";
  pickup crisp.nib;
  a:=vround 0.0[min(0.2[vair,stem],rth0),rth1];
  pos1(a,90); pos2(a,90); lft x1-appr=w-appr-rt x2=hround 0.0u;
  top y1r=top y2r=vround(h+0.5a);
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(bar_wwww,32u#+2appr#,
    %x_height#+body_height#-cap_height#,0);
    0.5[x_height#,body_height#],0);
  "Wide bar accent 4";
  pickup crisp.nib;
  a:=vround 0.0[min(0.2[vair,stem],rth0),rth1];
  pos1(a,90); pos2(a,90); lft x1-appr=w-appr-rt x2=hround 0.0u;
  top y1r=top y2r=vround(h+0.5a);
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(bar_wwwww,40u#+2appr#,
    %x_height#+body_height#-cap_height#,0);
    0.5[x_height#,body_height#],0);
  "Wide bar accent 5";
  pickup crisp.nib;
  a:=vround 0.0[min(0.2[vair,stem],rth0),rth1];
  pos1(a,90); pos2(a,90); lft x1-appr=w-appr-rt x2=hround 0.0u;
  top y1r=top y2r=vround(h+0.5a);
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

arrow_stress  := 0.52;
arrow_tense1  := 0.75;
arrow_tense2  := 0.875;

beginchar(arrow_accent,7u#+2appr#,min(asc_height#,2x_height#),0);
  "Arrow accent";
  pickup tiny.nib;
  arrow_width   := 2ceiling 0.3(h-x_height)+rth;
  arrow_height  := hround 3.25u;
  arrow_breadth := rth;
  y2=y3=vround(0.7[x_height,h]-0.5rth)+0.5rth;
  lft x2=w-rt x3=appr-hround 0.5u;
  arrow_head1(z2..z3,both); x2r=x2l=x2; y1r=y2r; y1l=y2l;
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(arrow_w,8u#+2appr#,0.5[asc_height#,body_height#],0);
  "Wide arrow accent 1";
  pickup tiny.nib;
  arrow_width   := 2ceiling 0.3(h-x_height)+rth;
  arrow_height  := hround 3.3u;
  arrow_breadth := rth;
  y2=y3=vround(0.7[x_height,h]-0.5rth)+0.5rth;
  lft x2=w-rt x3=appr-hround 0.5u;
  arrow_head1(z2..z3,both); x2r=x2l=x2; y1r=y2r; y1l=y2l;
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(arrow_ww,16u#+2appr#,body_height#,0);
  "Wide arrow accent 2";
  pickup tiny.nib;
  arrow_width   := 2ceiling 0.3(h-x_height)+rth;
  arrow_height  := hround 3.35u;
  arrow_breadth := rth;
  y2=y3=vround(0.7[x_height,h]-0.5rth)+0.5rth;
  lft x2=w-rt x3=appr-hround 0.5u;
  arrow_head1(z2..z3,both); x2r=x2l=x2; y1r=y2r; y1l=y2l;
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(arrow_www,24u#+2appr#,body_height#,0);
  "Wide arrow accent 3";
  pickup tiny.nib;
  arrow_width   := 2ceiling 0.3(h-x_height)+rth;
  arrow_height  := hround 3.4u;
  arrow_breadth := rth;
  y2=y3=vround(0.7[x_height,h]-0.5rth)+0.5rth;
  lft x2=w-rt x3=appr-hround 0.5u;
  arrow_head1(z2..z3,both); x2r=x2l=x2; y1r=y2r; y1l=y2l;
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(arrow_wwww,32u#+2appr#,body_height#,0);
  "Wide arrow accent 4";
  pickup tiny.nib;
  arrow_width   := 2ceiling 0.3(h-x_height)+rth;
  arrow_height  := hround 3.45u;
  arrow_breadth := rth;
  y2=y3=vround(0.7[x_height,h]-0.5rth)+0.5rth;
  lft x2=w-rt x3=appr-hround 0.5u;
  arrow_head1(z2..z3,both); x2r=x2l=x2; y1r=y2r; y1l=y2l;
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(arrow_wwwww,40u#+2appr#,body_height#,0);
  "Wide arrow accent 5";
  pickup tiny.nib;
  arrow_width   := 2ceiling 0.3(h-x_height)+rth;
  arrow_height  := hround 3.5u;
  arrow_breadth := rth;
  y2=y3=vround(0.7[x_height,h]-0.5rth)+0.5rth;
  lft x2=w-rt x3=appr-hround 0.5u;
  arrow_head1(z2..z3,both); x2r=x2l=x2; y1r=y2r; y1l=y2l;
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

def tmp_program(expr orientation,overshot,approach,coef)=
  pickup tiny.nib;
  a:=vround 0.5[vair,stem]; pos2(a,90);
  y2+0.5a=vround(h+0.5a+overshot); y1r=y3r=good.y 1/3[x_height,h];
  lft x1r=w-rt x3r=hround approach; x2=0.5[x1r,x3r];
  z1'-z1r=(z2r-z1r) xscaled 1/3;
  z3'-z3r=(z2r-z3r) xscaled 1/3;
  pos1(hair,angle(z1'-z1r)+90);
  pos3(hair,angle(z3'-z3r)-90);
  filldraw stroke z1e{z1'-z1r}...z2e{right}...z3e{z3r-z3'};
  penlabels(1,2,3); labels(1',3');
enddef;

beginchar(paren_accent,7u#+2appr#,0.5[x_height#,asc_height#],0);
  "Parenthesis accent";
  tmp_program(up,0,appr+0.25u,0);
endchar;

beginchar(paren_w,8u#+2appr#,0.5[x_height#,body_height#],0);
  "Wide parenthesis accent 1";
  tmp_program(up,o,appr,0.2);
endchar;

beginchar(paren_ww,16u#+2appr#,0.5[x_height#,body_height#],0);
  "Wide parenthesis accent 2";
  tmp_program(up,o,appr-0.25u,0.4);
endchar;

beginchar(paren_www,24u#+2appr#,0.5[x_height#,body_height#],0);
  "Wide parenthesis accent 3";
  tmp_program(up,o,appr-0.5u,0.6);
endchar;

beginchar(paren_wwww,32u#+2appr#,0.5[x_height#,body_height#],0);
  "Wide parenthesis accent 4";
  tmp_program(up,o,appr-0.5u,0.8);
endchar;

beginchar(paren_wwwww,40u#+2appr#,0.5[x_height#,body_height#],0);
  "Wide parenthesis accent 5";
  tmp_program(up,o,appr-0.5u,1);
endchar;

standard_proofing;% restore extra_endchar.

