% mathematical symbols by Anthony Phan.
% file: mathgrey.mf (grey symbols)
% last modification: May 16, 2005.

def horizontal_rules_list=
  0.5[-d,h]-math_axis,0.5[-d,h]-math_axis+x_height,
  0.25[-d,h],0.5[-d,h],0.75[-d,h] enddef;

% basic pieces and parameters

grey_ppi=1200;% maximum resolution
grey_sc:=round max(1,pixels_per_inch/grey_ppi);
grey_ht:=4grey_sc; grey_wd:=4grey_sc;
picture grey.light,grey.medium,grey.dark;
grey.light=nullpicture;
grey.medium=nullpicture;
grey.dark=nullpicture;
for z=(0,2),(1,0),(2,3),(3,1):
  addto grey.light contour
  (unitsquare scaled grey_sc) shifted (z scaled grey_sc);
endfor
for z=(0,1),(0,3),(1,0),(1,2),(2,1),(2,3),(3,0),(3,2):
  addto grey.medium contour
  (unitsquare scaled grey_sc) shifted (z scaled grey_sc);
endfor
addto grey.dark contour
(0,0)--(grey_wd,0)--(grey_wd,grey_ht)--(0,grey_ht)--cycle;
for z=(0,2),(1,0),(2,3),(3,1):
  addto grey.dark contour
  (unitsquare scaled grey_sc) shifted (z scaled grey_sc) withweight -1;
endfor

% The whole bounding box is shaded (tmp_light not currentpicture).

vardef grey_background@#(expr x_min,x_max,y_min,y_max)=
  for j=floor(y_min/grey_ht) upto ceiling(y_max/grey_ht):
    for i=floor(x_min/grey_wd) upto ceiling(x_max/grey_wd):
      addto tmp_picture also (grey.@# shifted (i*grey_wd,j*grey_ht));
    endfor endfor
enddef;

% The path p must lies within the character bounding box.

vardef grey_fill(expr p,x_min,x_max,y_min,y_max)(suffix @#)=
  tmp_picture:=nullpicture;
  grey_background@#(x_min,x_max,y_min,y_max);
  addto tmp_picture contour p;
  cull tmp_picture keeping (2,infinity);
  addto tmp_picture also currentpicture;
  currentpicture:=tmp_picture;
enddef;

def tmp_program(expr circle,radius)(suffix @#)=
  x0=good.x 0.5w; y0=good.y 0.5[-d,h];
  if circle:
    for i=1 upto 8:
      z[i]=z0+round(radius-0.5rth)*right rotated(45*(i-1));
    endfor; labels(0,1,2,3,4,5,6,7,8);
    tmp_path:=z1{up}...z2{z3-z1}
    ...z3{left}...z4{z5-z3}...z5{down}...z6{z7-z5}
    ...z7{right}...z8{z1-z7}...cycle;
  else:
    for i=1 step 2 until 7:
      z[i]=z0+round(6.75u-0.5rth)*right rotated(45*(i-1));
    endfor;
    x1=x2=x8; x5=x4=x6; y2=y3=y4; y6=y7=y8;
    labels(0,1,2,3,4,5,6,7,8);
    tmp_path:=z1--z2--z3--z4--z5--z6--z7--z8--cycle;
  fi
  grey_fill(tmp_path,x5,x1,y7,y3,@#);
enddef;

beginchar(hex"DD",arithmetic_bounds);
  tmp_program(true,6.75u,light);
endchar;

beginchar(hex"FD",arithmetic_bounds);
  tmp_program(false,6.75u,light);
endchar;

beginchar(hex"DE",arithmetic_bounds);
  tmp_program(true,6.75u,medium);
endchar;

beginchar(hex"FE",arithmetic_bounds);
  tmp_program(false,6.75u,medium);
endchar;

beginchar(hex"DF",arithmetic_bounds);
  tmp_program(true,6.75u,dark);
endchar;

beginchar(hex"FF",arithmetic_bounds);
  tmp_program(false,6.75u,dark);
endchar;


