%gnuchars.mf
%%\medskip
if unknown cmbase: input cmbase fi;
mode=localfont; picture r[];
mode_setup;

%%First, the function to print a string:

def put_text(expr ts,xstart,ystart,rot,justification) =

%%\noindent The {\tt rot}, rotation, should be a multiple of 90.
%%Justification is 
%%1,2, or 3 for left, center, and right justified text with respect to
%%the {\tt (xstart,ystart)} position. \smallskip
begingroup
 text_width:=0;text_height:=0;

%%Compute the width of the text string (ts):

 for ind:=0 step 1 until length(ts)-1:
  dec_num:=ASCII substring (ind,ind+1) of ts;
  if unknown r[dec_num]: dec_num:=32; fi

%%r is a picture array to be filled later. The space character is used
%%for missing characters.

  if dec_num=32: 
   text_width:=text_width+wd[65];
   text_height:=max(text_height,ht[65]+dp[65]);
  elseif dec_num>=0: 
   text_width:=text_width+wd[dec_num];
   text_height:=max(text_height,ht[dec_num]+dp[dec_num]);
  fi
 endfor

%%Now that we have the text width (and height), we can compute the x and y
%%coordinates for the starting position, given the specified
%%justification (1=left, 2=centered, 3=right)

 if rot=90:
  if justification=1: ynext:=ystart;
  elseif justification=2: ynext:=round(ystart-text_width/2);
  else: ynext:=round(ystart-text_width);
  fi
  xnext:=xstart+text_height/2;
 else:
  if justification=1: xnext:=xstart;
  elseif justification=2: xnext:=round(xstart-text_width/2);
  else: xnext:=round(xstart-text_width);
  fi
  ynext:=ystart-text_height/2;
 fi

%%All of that was just to get the starting position. Now we again step
%%through the string character by character, adding the characters'
%%picture to the current picture. The {\tt wd} array contains the
%%characters' lengths.

 for ind:=0 step 1 until length(ts)-1:
  dec_num:=ASCII substring (ind,ind+1) of ts;
  if unknown r[dec_num]: dec_num:=32; fi
  if dec_num=32: 
   xnext:=xnext+wd[65]*cosd rot;
   ynext:=ynext+wd[65]*sind rot;
  elseif dec_num>=0: 
%  We add the text character by character to the current picture.
   currentpicture:=currentpicture+r[dec_num] shifted(xnext,ynext)
    rotatedaround ((xnext,ynext),rot); 
   xnext:=xnext+wd[dec_num]*cosd rot;
   ynext:=ynext+wd[dec_num]*sind rot;
  fi
 endfor
endgroup 
enddef;

%%In order to save the character pictures and widths, we redefine the
%%{\tt endchar} macro:

def endchar =
 r[charcode]:=currentpicture;
 wd[charcode]:=w;ht[charcode]:=h;dp[charcode]:=d;
 message "Picture of charcode no." & decimal charcode;
 endgroup;
enddef;

%%The plain base adds a \_ to the end of all its private tokens. This
%%reduces the likelehood of users redefining those tokens. However,
%%that's precisely whate we want to do here:

let endchar_ := endchar;

%%Negate the commands that would normally generate a font:

let o_generate := generate; let o_roman := roman;
let generate := relax;
let roman = relax; 

%%The let macro, like the def macro, can use either an = or a :=
%%symbol. The code generated by gnuplot uses a = which I change to :=
%%which seems less confusing.

%%Rather than cmr10, I use a sans serif font. The {\tt
%%cmssb10.mf} parameter file is just {\tt cmssdc10} with sharp
%%corners: {\tt crisp:= tiny:= fine:= 0}.

input cmbx5.mf
if ligs>1: font_coding_scheme:="TeX text";
 spanish_shriek=oct"074"; spanish_query=oct"076";
else: font_coding_scheme:=
 if ligs=0: "TeX typewriter text"
 else: "TeX text without f-ligatures" fi;
 spanish_shriek=oct"016"; spanish_query=oct"017"; 
fi;
font_setup;
input romanu.mf %Roman uppercase.
input romanl.mf %Roman lowerrcase.
input romand.mf %Numerals.
input punct.mf %Punctuation symbols.

%%\noindent You can, of course, include other characters if needed;
%%in fact, you can include characters from several fonts (parameters 
%%and font\_setup may need redoing).

%%Next we add some extra characters:
 
minus=ASCII"-"; cmchar "Minus sign";
beginarithchar(minus); 
 pickup rule.nib;
 lft x1=hround 1.5u-eps;
 x2=w-x1; y1=y2=math_axis;
 draw z1--z2; % bar
 labels(1,2); 
endchar;

cmchar "Period";
 numeric dot_diam#; dot_diam#:=if monospace: 5/4 fi\ dot_size#;
 define_whole_blacker_pixels(dot_diam);
 beginchar(".",5u#,dot_diam#,0);
 adjust_fit(0,0); pickup fine.nib;
 pos1(dot_diam,0); pos2(dot_diam,90);
 lft x1l=hround(.5w-.5dot_diam); bot y2l=0; z1=z2; dot(1,2); % dot
 penlabels(1,2);
endchar;

%% Now we reset endchar back to normal; there isn't really any need to
%% do this.

def endchar =
 l:=0; r:=w;
%Include the next two lines if you want to rotate
%the picture 90 deg.(Portrait to Landscape)
%currentpicture:=currentpicture rotated 90 shifted (h,0);
%tmp:=charht; charht:=charwd; charwd:=tmp;
 scantokens extra_endchar;
 if proofing>0: makebox(proofrule); fi
 chardx:=w;
 shipit;
 if displaying>0: makebox(screenrule); showit; fi
 endgroup 
enddef;
let endchar_ := endchar;
 
let generate := o_generate;
let roman := o_roman;

font_identifier:="GNUPLOT";
font_size 72pt#;
th#=0.4pt#; define_whole_pixels(th);

path arrowhead;
arrowhead = (-7pt,-2pt){dir30}..(-6pt,0pt)..{dir150}(-7pt,2pt) &
  (-7pt,2pt)--(0pt,0pt)--(-7pt,-2pt) & cycle;

%%Save this in a base file for future use (the mode=localfont at the 
%%beginning was needed since the pictures are for paper; and even for
%%on-screen use, proof mode characters are too big).
