% blackboard typefaces by Anthony Phan.
% file: maydigit.mf (Maya digits)
% last modification: May 16, 2005.

numeric fig_width#;
fig_width#=max(dtsz#,stem#*(1++slant));

use_rule1;

beginchar("0",20u#+2appr#,fig_height#,0);
  "Maya numeral 0";
%  italcorr fig_height#*slant-0.5u#;
  numeric a; a=vround 0.2(h+d);
  pickup rule.nib; x2r=x4r=good.x 0.5w;
  pickup fine.nib; y1r=y3r=good.y 0.5[-d,h];
  top y2r=h+o; y2r-y1r=y1r-y4r; y1'=y2r; y3'=y4r;
  lft x1r=appr; x3r-x2r=x2r-x1r;
  x1'=1/3[x1r,x2r]; x3'=1/3[x3r,x4r];
  pos2(rth,90); pos4(rth,-90);
  penpos1(diag_width(rth-fine,z1'-z1r),180);
  penpos3(diag_width(rth-fine,z3'-z3r),0);
  path tmp_path[],tmp_path[]r,tmp_path[]l;
  numeric t[],t[]r,t[]l;
  forsuffixes $=,r,l:
    z[5]$=z[1]$ shifted(0,a); z[7]$=z[4]$ shifted(0,a);
    z[9]$=z[3]$ shifted(0,a);
    tmp_path[1]$=z[1]${z1'-z1r}...z[2]${right}
    ...z[3]${(z3'-z3r) xscaled -1};
    tmp_path[2]$=z[9]${z3'-z3r}...z[7]${left}
    ...z[5]${(z1r-z1') yscaled -1};
    t[1]$=xpart(tmp_path[2]$
      intersectiontimes subpath (1,2) of tmp_path[1]);
    t[2]$=xpart(tmp_path[2]$
      intersectiontimes subpath (0,1) of tmp_path[1]);
    tmp_path[3]$=subpath (t[1]$,t[2]$) of tmp_path[2]$;
    z[6]$=point t[1]$ of tmp_path[2]$;
    z[8]$=point t[2]$ of tmp_path[2]$;
  endfor
  pickup rule.nib; x12=good.x 1/3[x2,x6];
  x14=x2; x18-x16=x16-x14=x14-x12=x12-x10;
  pickup fine.nib;
  for i=10 step 2 until 18:
    rt x[i]r-lft x[i]l=rth; 0.5[x[i]r,x[i]l]=x[i];
    forsuffixes $=,r,l:
      z[i]$=tmp_path[1] intersectionpoint ((x[i]$,y2r)..(x[i]$,y7r));
      z[i+1]$=tmp_path[3] intersectionpoint ((x[i]$,y2r)..(x[i]$,y7r));
    endfor
    filldraw stroke z[i]e..z[i+1]e;
  endfor
  filldraw stroke tmp_path[1]e; filldraw stroke tmp_path[3]e;
  filldraw stroke z3e{z3'-z3r}...z4e{left}...z1e{(z1r-z1') yscaled -1};
  penlabels(range 1 thru 19); labels(1',3');
endchar;

beginchar("1",fig_width#+2appr#,fig_height#,0);
  "Maya numeral 1 (hun)";
%  italcorr fig_height#*slant-0.5u#;
  pickup fine.nib;
  adjust_dot1((0.5w,0.5h),dtsz,false,false);
  dot(1,1');
endchar;

beginchar("2",fig_width#+2appr#,fig_height#,0);
  "Maya numeral 2 (ca)";
%  italcorr fig_height#*slant-0.5u#;
  pickup fine.nib;
  adjust_dot1((0.5w,0.25h),dtsz,false,false);
  dot(1,1');
  adjust_dot2((0.5w,0.75h),dtsz,false,false);
  dot(2,2');
endchar;

beginchar("3",fig_width#+2appr#,fig_height#,0);
  "Maya numeral 3 (ox)";
%  italcorr fig_height#*slant-0.5u#;
  pickup fine.nib;
  adjust_dot1((0.5w,h/6),dtsz,false,false);
  dot(1,1');
  adjust_dot2((0.5w,0.5h),dtsz,false,false);
  dot(2,2');
  x3=x1; x3'=x1'; y2-y1=y3-y2; y2'-y1'=y3'-y2'; dot(3,3');
endchar;

beginchar("4",fig_width#+2appr#,fig_height#,0);
  "Maya numeral 4 (can)";
%  italcorr fig_height#*slant-0.5u#;
  pickup fine.nib;
  adjust_dot1((0.5w,0.5dtsz),dtsz,false,false);
  dot(1,1');
  adjust_dot2((0.5w,1/3(h-dtsz)+0.5dtsz),dtsz,false,false);
  dot(2,2');
  x3=x1; x3'=x1'; y2-y1=y3-y2; y2'-y1'=y3'-y2'; dot(3,3');
  x4=x1; x4'=x1'; y2-y1=y4-y3; y2'-y1'=y4'-y3'; dot(4,4');
endchar;

beginchar("5",fig_width#+2appr#,fig_height#,0);
  "Maya numeral 5 (ho)";
%  italcorr fig_height#*slant-0.5u#;
  pickup fine.nib; top y1=h; bot y2=0;
  lft x1l=lft x2l=hround(0.5w-0.5stem);
  pos1(stem,0); pos2(stem,0); filldraw stroke z1e..z2e;
  penlabels(1,2);
endchar;

% 6=uac, 7=uc, 8=vaxac, 9=bolon, 10=lahun
% 11=hun lahun, 12=ca lahun, 13=ox lahun.

