[comp.text.tex] MF 2.0: poor support for X-windows

rcpt@rw7.urc.tue.nl (Piet Tutelaers) (12/01/90)

I have played with METAFONT (MF 2.0) on my NCD16 X-windows terminal,
but I am not very satified with the result. To encourage other people to
solve my problem I have enclosed two files which can draw a nice chess
board on the screen (if your MF has nice graphical support).

To instruct MF to draw a character on the screen your MF program needs
to do a `showit', as does my chessdiag.mf. With X-windows you also
need to set your DISPLAY environment variable (for example `setenv
DISPLAY rx2.urc:0' if you are using the C-shell). And now you are
ready to draw a `mate in three problem' with:
   mf "\mode=localfont; mag=magstep(2); screenchars; input chessdiag"

But on my NCD16 display there appears a big window covering the
complete screen but only showing a part of the chess board. The other
part flows from the screen or is just not shown. What extra things do
you need to get the board positioned in the middle of the screen?

To test the preview capabilities of your MF you can unshar this
message (saved in a file) in a dirctory and run it. Does it shows the
same problems as I mentioned?

Because MF needs to run on a big number of platforms it was a wise
choice from professor Knuth to restrict the number of graphical
primitives that it will depend on. To get nevertheless nice preview
facilities it would be great to have a separate program, let's call it
XMFview, which can recieve drawing requests from MF in a client server
model, and execute them in a separate window. XMFview should have
facilities to position the picture somewhere within its window, rescale
the height and width, provides backingstore, etc. If such a program still
does not exist for X-windows, who will write one? (AmigaMETAFONT, with
which I developed this chessfont, does have such a facility.)

--Piet

---------------------chessdiagram.shar-------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  chessbase.mf chessdiag.mf
# Wrapped by rcpt@rw3.urc.tue.nl on Fri Nov 30 16:18:04 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f chessbase.mf -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"chessbase.mf\"
else
echo shar: Extracting \"chessbase.mf\" \(10459 characters\)
sed "s/^X//" >chessbase.mf <<'END_OF_chessbase.mf'
X% This is `chessbase.mf' version 1.0 as of 8/90
X% METAfounded by Piet Tutelaers (uucp: rcpt@urc.tue.nl)
X
X% In this file all pieces are defined.
X% The points defining a piece are all in the unitsquare
X%   (0,0)--(0,1)--(1,1)--cycle.
X
Xdef dark_square(expr D) =
X  clearit; L:=min(D/4, 9); delta:=1/L;
X  pickup fine_pen;
X  for i=1 upto min(D/4,9):
X     draw (0,delta*i*D)--(D-delta*i*D,D);
X     draw (delta*i*D,0)--(D,D-delta*i*D);
X     endfor;
X  draw (0,0)--(D,D);
X  enddef;
X  
Xdef erase_square(expr D, col, row) =
X  currentpicture:=board;
X  erase fill (0,0)--(0,1)--(1,1)--(1,0)--cycle scaled D shifted(col*D, row*D);
X  board:=currentpicture;
X  enddef;
X  
Xdef empty_board(expr D) =
X   picture board; path border;
X   border = ((0,0)--(1,0)--(1,1)--(0,1)--cycle);
X   dark_square(D); board:=nullpicture;
X   for i=0 upto M-1:
X   for j=0 upto M-1:
X      if not odd(i+j): addto board also currentpicture shifted (D*i,D*j) fi;
X      endfor
X      endfor;
X   clearit;
X   pickup border_pen;
X   draw  border scaled (M*D);
X   addto board also currentpicture;
X   currentpicture:=board;
X   enddef;
X   
Xdef reflect(text t) =
X   forsuffixes $=t: z$'=z$ reflectedabout (z1,z2); endfor;
X   enddef;
X
Xdef opr(suffix $) = (x$+thick#/d#, y$) enddef; % one point right
Xdef opl(suffix $) = (x$-thick#/d#, y$) enddef; % one point left
Xdef opu(suffix $) = (x$, y$+thick#/d#) enddef; % one point up
Xdef opd(suffix $) = (x$, y$-thick#/d#) enddef; % one point down
X    
Xvardef K(expr D, col, row) =
X  clearxy;
X  path cross_bar, crown, crown_top, crown_left, crown_right, crown_lower,
X      crown_top_inner, crown_left_inner, crown_right_inner;
X  def moved = scaled D shifted (col*D, row*D) enddef;
X
X  pickup thick_pen;
X% draw cross 
X  z1=(.5,.96); z2=(.5,.8); z11=(.42,.9); reflect(11);
X  cutdraw (z1--z2) moved; cutdraw (z11--z11') moved;
X% top part of crown
X  z3=(.5,.38); z21=(.475,.5); z22=(.45,.575); z23=(.45,.775);
X  reflect(21,22,23);
X  crown_top= ((z3..z21..z22..z23..z2..z23'..z22'..z21'..z3) & cycle);
X% left and right part
X  z31=z21; z32=z22; z33=(.32,.67); z34=(.13,.69); z35=(.07,.55);
X  z36=(.13,.45); z37=(.2,.34);
X  reflect(31, 32, 33, 34, 35, 36, 37);
X  crown_left=(z3..z31..z33..z34..z35..z36..z37);
X  crown_right=(z37'..z36'..z35'..z34'..z33'..z31'..z3);
X% lower part of the crown
X  z6=(.5,.095); z61=(.27,.12); z62=(.2,.15); z63=(.21,.23);
X  reflect(61, 62, 63);
X  crown_lower= ((z37--z63) & (z63--z62) & (z62..z61..z6..z61'..z62') &
X   (z62'--z63') & (z63'--z37') & (z37'..z3..z37) & cycle);
X% draw contour of crown
X  pickup thin_pen;
X  crown= crown_left & z37..z3..z37' & crown_right & cycle;
X  if background=dark: erase fill crown moved;
X    erase fill crown_top moved;
X    erase fill crown_lower moved;fi;
X  draw crown moved;  draw crown_top moved;
X  if color=black: 
X     z121=(.5,.5); z123=(.45,.675); z102=(.5,.77);
X     reflect(123);
X     crown_top_inner = (z121{curl 0}..z123..z102..z123'..{curl 0}z121 & cycle);
X     z131=(.45,.5); z133=(.32,.64); z134=(.13,.66); z135=(.10,.55);
X     z136=(.16,.45); z137=(.22,.36); z103=(.475,.4);
X     crown_left_inner= ((z103..z131..z133..z134..z135..z136..z137)
X        & (z137..{right}z103) & cycle);
X     crown_right_inner=crown_left_inner reflectedabout (z1,z2);
X     fill crown_top_inner moved;
X     fill crown_left_inner moved;
X     fill crown_right_inner moved;
X     fill crown_lower moved;
X  else: draw crown_lower moved;
X  fi;
X% draw inner parts
X  z4=(.5,.28); z5=(.5,.21);
X  if color=white:
X     draw (z37..z3..z37') moved;
X     draw (z63..z4..z63') moved;
X     draw (z62..z5..z62') moved;
X  else: pickup thick_pen;
X     erase draw (opr(37)..z3..opl(37')) moved;
X     erase draw (opr(63)..z4..opl(63')) moved;
X     erase draw (opr(62)..z5..opl(62')) moved;
X  fi;
X  enddef;
X  
Xvardef Q(expr D, col, row) =
X  clearxy;
X  path crown_top, crown, crown_lower;
X  def moved = scaled D shifted (col*D, row*D) enddef;
X  
X  pickup thin_pen;
X% top part of crown
X  z1=(.5,.92); z2=(.5,.5); z11=(.42,.46); z12=(.275,.88);
X  z13=(.25,.44); z14=(.075,.8); z15=(.125,.4); 
X  reflect(11,12,13,14,15);
X  crown_top = (z15'--z14'--z13'--z12'--z11'--z1--z11--z12--z13--z14--z15);
X% lower part of the crown
X  z6=(.5,.0775); z61=(.25,.1); z62=(.2,.125); z63=(.24,y62+1/3(y15-y62));
X  z64=(.2,y62+2/3(y15-y62));
X  reflect(61,62,63,64);
X  crown_lower= ((z15--z64) & (z64--z63) & (z63--z62) &
X   (z62..z61..z6..z61'..z62') & (z62'--z63') & (z63'--z64') &
X   (z64'--z15'));
X% draw contour of crown
X  crown= (crown_top & crown_lower & cycle);
X  if background=dark:
X     if color=white: erase fill crown moved; fi; fi;
X  if color=white: draw crown moved;
X     forsuffixes $:=1,12,12',14,14':
X        erase fill (fullcircle scaled .1 shifted z$) moved; 
X        draw (fullcircle scaled .1 shifted z$) moved; endfor;
X  else: fill crown moved;
X     forsuffixes $:=1,12,12',14,14':
X        fill (fullcircle scaled .1 shifted z$) moved; endfor; fi;
X% draw inner parts
X  z3=(.5,y5+(y64-y62)); z4=(.5,y5+(y63-y62)); z5=(.5,.18);
X  if color=white: draw (z64..z3..z64') moved; draw (z63..z4..z63') moved;
X     draw (z62..z5..z62') moved;
X     z21=z11; z22=(.325,.475); z23=z13; z24=(.175,.44); z25=z15;
X     reflect(21,22,23,24,25);
X     draw ((z2..z21..z22) & (z22..z23..z24) & (z24--z25)) moved;
X     draw ((z2..z21'..z22') & (z22'..z23'..z24') & (z24'--z25')) moved;
X  else: pickup thick_pen;
X     erase draw (opr(64)..z3..opl(64')) moved;
X     erase draw (opr(63)..z4..opl(63')) moved;
X     erase draw (opr(62)..z5..opl(62')) moved;
X  fi;
X  enddef;
X  
Xvardef R(expr D, col, row) =
X  clearxy;
X  path rook;
X  def moved = scaled D shifted (col*D, row*D) enddef;
X  
X  pickup thin_pen;
X% top part of rook
X  z1=(.5,.86); y15=y14=y11=y1; x15=x16=.21; x19=x20=.225; y13=y12=.8;
X  y16=.725; y17=.65; y18=.35; y19=.26; y20=y21=.175; y22=.1;
X  x22=x21=.175; x17=x18=.31; x13=x14=.325; x11=x12=.43; z2=(.5,.1);
X  reflect(11,12,13,14,15,16,17,18,19,20,21,22);
X  rook = (z11--z12--z13--z14--z15--z16--z17--z18--z19--z20--z21--z22--z22'
X     --z21'--z20'--z19'--z18'--z17'--z16'--z15'--z14'--z13'--z12'--z11'--cycle);
X% draw contour of rook
X  if background=dark:
X     if color=white: erase fill rook moved; fi; fi;
X  if color=white: draw rook moved; else: fill rook moved; fi;
X% draw inner parts
X  if color=white: draw (z16--z16') moved; draw (z17--z17') moved;
X     draw (z18--z18') moved; draw (z19--z19') moved;
X     draw (z20--z20') moved;
X  else: pickup thick_pen;
X     erase draw (opr(16)--opl(16')) moved;
X     erase draw (opr(17)--opl(17')) moved;
X     erase draw (opr(18)--opl(18')) moved;
X     erase draw (opr(19)--opl(19')) moved;
X     erase draw (opr(20)--opl(20')) moved; fi;
X  enddef;
X  
Xvardef N(expr D, col, row) =
X  clearxy;
X  path knight, ear, eye, nose, mouth, neck;
X  def moved = scaled D shifted (col*D, row*D) enddef;
X  
X  pickup thin_pen;
X% the knight's contour
X  z1=(.5,.82); z2=(.5,.075); z11=(.45,.93); z12=(.375,.85); z13=(.25,.925);
X  z14=(.26,.8); z15=(.22,.75); z16=(.18,.7); z17=(.18,.66); z18=(.07,.42);
X  z19=(.07,.36); z20=(.14,.3); z21=(.17,.3); z22=(.175,.275); z23=(.225,.28);
X  z24=(.29,.38); z25=(.41,.46); z26=(.49,.51); z27=(.435,.295); z28=(.32,.165);
X  z29=(.31,y2); z30=(.93,y2); z31=(.87,.5); z32=(.7,.78);
X  knight = ((z1--z11--z12--z13--z14) &
X     (z14..z15..z16..z17..z18..z19..z20..z21) &
X     (z21..z22..z23..z24..z25..z26) &
X     (z26..z27..z28..z29) & (z29--z30) &
X     (z30..z31..z32..z1) &cycle);
X% draw contour of knight
X  if color=white: erase fill knight moved;
X     draw knight moved;
X  else: fill knight moved; fi;
X% draw inner parts
X  z4=(.22,.62); z41=(.25,.67); z42=(.29,.705); z43=(.31,.7); z44=(.3,.68);
X  eye = (z4..z41..z42..z43 & z43..z44..z4 & cycle);
X  z5=(.1,.36); z51=(.1,.39); z52=(.135,.43); z53=(.15,.4); z54=(.13,.38);
X  nose = (z5..z51..z52..z53..z54..z5 &cycle);
X  if color=white: z21'=(.2,.34); draw (z21'--z21) moved; %mouth
X     z26'=(.54,.63); draw (z26'..z26{z24-z26}) moved; %neck
X     draw (z12--z14) moved; % ear
X     fill eye moved; fill nose moved;
X  else: erase fill eye moved; erase fill nose moved; fi;
X     z30'=z30 + (-thick#/d#,thick#/d#); pickup thick_pen
X     erase draw (opd(1)..opd(32)..opl(31)..z30') moved; % mane 
X  enddef;
X  
Xvardef B(expr D, col, row) =
X  clearxy;
X  path top, hat, brim, mitre, stole;
X  def moved = scaled D shifted (col*D, row*D) enddef;
X  
X  pickup thin_pen;
X% the top circle
X  z1=(.5,.85); z2=(.5,.8);
X  top = (fullcircle scaled .1 shifted z1);
X  if color=white: erase fill top moved; draw top moved;
X  else: fill top moved; fi;
X% the hat
X  z3=(.5,.43); z21=(.27,.57); z31=(.35,.4); reflect(21,31);
X  hat = (z31'..z21'..z2{(-1,1)}) & (z2{(-1,-1)}..z21..z31);
X% the brim
X  z4=(.5,.33); z5=(.5,.23);
X  z41=(.32,.28); reflect(41);
X  brim = ((z31--z41) & (z41..z5..z41') & (z41'--z31'));
X% the stole
X  z6=(.5,.15); z7=(.5,.3); z61=(.44,.12); z62=(.25,.1); z63=(.15,.05);
X  z64=(.09,.11); z65=(.25,.18); z66=(.44,.2);
X  reflect(61,62,63,64,65,66);
X  stole = ((z7..z66..z65..z64) & (z64--z63) & (z63..z62..z61..z6) &
X     (z6..z61'..z62'..z63') & (z63'--z64') & (z64'..z65'..z66'..z7) &cycle);
X% the mitre
X  mitre = (hat & brim & cycle);
X  if background=dark:
X     if color=white: erase fill mitre moved;  
X        erase fill stole moved; fi; fi;
X  if color=black: fill mitre moved; fill stole moved;
X  else: draw mitre moved; draw stole moved;
X     erase fill mitre moved; draw mitre moved; fi; 
X  
X% inner parts of mitre
X  center:=.59; width:=.065;
X  if color=white:  draw (z31..z3..z31') moved;  draw (z41..z4..z41') moved;
X     draw ((.5,center-width)--(.5,center+width)) moved;
X     draw ((.5-width,center)--(.5+width,center)) moved;
X  else: pickup thick_pen;
X     erase cutdraw (opr(31)..z3..opl(31')) moved;
X     erase cutdraw (opr(41)..z4..opl(41')) moved;
X     erase cutdraw ((.5,center-width)--(.5,center+width)) moved;
X     erase cutdraw ((.5-width,center)--(.5+width,center)) moved;
X  fi;
X  enddef;
X  
Xvardef p(expr D, col, row) =
X  clearxy;
X  path pawn;
X  def moved = scaled D shifted (col*D, row*D) enddef;
X  
X  pickup thin_pen;
X% the pawn's contour
X  z1=(.5,.9); z2=(.5,.1); z11=(.41,.85); z12=(.46,.73); z13=(.32,.6);
X  z14=(.41,.46); z15=(.3,.4); z16=(.2,.1);
X  reflect(11,12,13,14,15,16);
X  pawn = ((z12'..z11'..z1..z11..z12) &
X     (z12..z13..z14) &
X     (z14..z15..z16) &
X     (z16--z16') &
X     (z16'..z15'..z14') &
X     (z14'..z13'..z12') & cycle);
X
X% draw contour of pawn
X  if background=dark:
X     if color=white: erase fill pawn moved;  fi; fi;
X  if color=black: fill pawn moved;
X  else: draw pawn moved; fi; 
X  enddef;
END_OF_chessbase.mf
if test 10459 -ne `wc -c <chessbase.mf`; then
    echo shar: \"chessbase.mf\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f chessdiag.mf -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"chessdiag.mf\"
else
echo shar: Extracting \"chessdiag.mf\" \(1702 characters\)
sed "s/^X//" >chessdiag.mf <<'END_OF_chessdiag.mf'
X% This is `chessdiag.mf' version 1.1 as of 11/90
X% METAfounded by Piet Tutelaers (uucp: rcpt@urc.tue.nl)
X
X% file generates a complete chess diagram
X
X% most versions of METAFONT have memorylimits so generating a complete
X% diagram of 160 X 160 points for a 300 DPI printer is not possible
X
Xmode_setup;
Xinput chessbase;
X
Xdef draw_pieces(text piece_list) = 
X   string piece, location;
X   for p=piece_list:
X      l:=length p;
X      exitunless (l=2) or (l=3);
X      if l=2: piece:="p"; i:=0;
X      else: piece:=substring(0,1) of p; i:=1; fi;
X      column:=ASCII substring(i,i+1) of p - ASCII "a";
X      row:=ASCII substring(i+1,i+2) of p - ASCII "1";
X      if not odd(column+row): background:=dark; else: background:=light; fi;
X      scantokens piece(d, column,row);
X      endfor;
X   enddef;
X   
Xdef w(text piece_list) = 
X   color:=white;
X   empty_board(d); draw_pieces(piece_list);
X   enddef;
X   
Xdef b(text piece_list) = 
X   color:=black;
X   draw_pieces(piece_list);
X   enddef;
X   
XM=8; % number of squares
Xd#:=100pt#/M; % size per square
Xfine#:=1/100*d#; thin#:=1/90*d#; thick#:=1/36*d#; border#:=1/20*d#;
Xdefine_blacker_pixels(fine, thin, thick, border);
Xdefine_whole_pixels(d);
Xpickup pencircle scaled fine; fine_pen:=savepen ; % for drawing dark squares
Xpickup pencircle scaled border; border_pen:=savepen ; % for border ofboard
Xpickup pencircle scaled thin; thin_pen:=savepen ; % for drawing pieces
Xpickup pencircle scaled thick; thick_pen:=savepen; % for drawing inside pieces
Xlight=0; dark=1; white=0; black=1;
X
X% put here the wanted diagram (ex.: mate in three problem)
X
Xw("Kc2","Nb4","Bf8","b3","g7");
Xb("Ka3","b6");
Xshowit;
X
Xmessage("White mates in three moves. Do you see how?");
XStopMe;
X
Xend;
END_OF_chessdiag.mf
if test 1702 -ne `wc -c <chessdiag.mf`; then
    echo shar: \"chessdiag.mf\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0

lgy@phys.washington.edu (Laurence G. Yaffe) (12/01/90)

rcpt@rw7.urc.tue.nl (Piet Tutelaers) writes:

-I have played with METAFONT (MF 2.0) on my NCD16 X-windows terminal,
-but I am not very satified with the result. To encourage other people to
-solve my problem I have enclosed two files which can draw a nice chess
-board on the screen (if your MF has nice graphical support).

-But on my NCD16 display there appears a big window covering the
-complete screen but only showing a part of the chess board. The other
-part flows from the screen or is just not shown. What extra things do
-you need to get the board positioned in the middle of the screen?

    Last I knew, a suitable resource specification like:

Metafont*geometry:	500x600+200+200

(in your .xresources or equivalent) would do what you want.
--
--------------------------------------------------------------------------
Laurence G. Yaffe		Internet: lgy@newton.phys.washington.edu
University of Washington	Bitnet:   yaffe@uwaphast.bitnet

rcpt@rw7.urc.tue.nl (Piet Tutelaers) (12/03/90)

lgy@phys.washington.edu (Laurence G. Yaffe) writes:
>    Last I knew, a suitable resource specification like:

>Metafont*geometry:	500x600+200+200

>(in your .xresources or equivalent) would do what you want.
>--
>--------------------------------------------------------------------------
>Laurence G. Yaffe		Internet: lgy@newton.phys.washington.edu
>University of Washington	Bitnet:   yaffe@uwaphast.bitnet

The geometry line in my ~/.Xdefaults (it does not work in ~/.xresources)
puts the Metafont window indeed in the middle of my screen. But the
chessboard is still cut horizontally (at the 5th line) and vertically (at
the 4th row). I have included the METAFONT sources (see my previous
posting) so that you can see what goes wrong! Try it.

--Piet