! display_table.MBS
! Display a table composed of several "ranges" of the Hershey glyphs.
! The table is an 8x8 grid of 64 possible ranges.
!
! The divisions into ranges are made in the text file 
! "list_tables_occidental.txt", but this file is not accessed here.

! To process plot file of entire table to print longways (11" "wide")
! on a sheet (because the whole table won't fit in 8.5" direction), 
! generate it with box_visibility=0 (no boxes) and then:
!
! postscript -s0.0867 -v90 -x-175 -y-10 < bigtable.PLT > bigtable.ps
!    overall width = 375 * 8 = 3000, scaled to 260mm to fit; 260/3000 = 0.0867
!    -v90 rotates to landscape mode, but moves image off page
!    -x-175 moves it back on the page (175mm to the right), roughly centering it
!    -y-10  moves it 10mm up roughly to center it

global drawing module display_table(
int table_number;
int toplevel;         ! 0 = false = not top level; 1 = true = top level
int box_visibility;   ! 0 = plain = invisible (no boxes); 1 = boxed = visible
int verbosity);

int    range_number;
int    rc;
int    start;
int    stop;
int    radius;
string range_name*132;

float  gw;  ! width and height of a range display
float  gh;
float  x;   ! position of range
float  y;
int    first_range;
int    current_range;
int    row;
int    col;
float  c;   ! offset for crop marks
string prefix*132;

constant int toplevel_false = 0;
constant int toplevel_true  = 1;

string homedir*132;

beginmodule

   first_range := table_number * 64;

   ! If box isn't visible, the glyphs will be displayed closer together,
   ! so display the ranges in a page closer together.
   ! The values here are empirical.
   if box_visibility = 1 then
      gw := 750;
      gh := 450;
   else
      gw := 375;
      gh := 200;
   endif;

   ! display the grid of ranges of glyphs
   y := 0;
   for row := first_range to (first_range + 56) step 8 do
      x := 0;
      for col := 0 to 7 do
         current_range := row + col;
         if verbosity >= 9 then
            lst_lin("display_table: row, col, row + col" + 
                    str(row) + str(col) + str(current_range));
         endif;
         csys_1p(#20,"range", vec(x,y): blank=1);
         part(#21,check_range (current_range,rc,start,stop,radius,range_name,
                               verbosity));
         if rc = 0 then
            part(#22,show_one_range(current_range, 
                                    toplevel_false, box_visibility, 
                                    verbosity), 
                     refc(20,current_range - first_range + 1));
         endif;
         x := x + gw;
      endfor;
      y := y - gh;
   endfor;

   if toplevel = toplevel_true then  ! redundant, as we're always top level here
      ! put four crop marks, one at each corner, so that when the resultant
      ! image is autocropped in The GIMP it will crop always to the same size
      c := 50;
      poi_free(#30,vec(-c,              c)); ! upper left
      poi_free(#31,vec((8*gw)+c,        c)); ! upper right
      poi_free(#32,vec((8*gw)+c,-(8*gh)-c)); ! lower right
      poi_free(#33,vec(-c,      -(8*gh)-c)); ! lower left
   endif;

   ! plot it 
   if toplevel = toplevel_true then
      homedir := get_environment("HOME");
      if box_visibility = 0 then
         prefix := "table-";
      else
         prefix := "tableboxed-";
      endif;
      plot_win(vec(-c-1,      -(8*gh)-c-1),
               vec((8*gw)+c+1,        c+1),
          homedir + "/hershey_plots/" + prefix + str(table_number,1,0) +".PLT");
   endif;

endmodule


! Copyright 2003-2004 by David M. MacMillan

! This work is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 2 of the License, or
! (at your option) any later version.

! NOTICE OF DISCLAIMER OF WARRANTY AND LIABILITY:

! This work is distributed WITHOUT ANY WARRANTY;
! without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
! See the GNU General Public License for more details.

! In no event will the author(s), editor(s), or publisher(s) of this work
! be liable to you or to any other party for damages,
! including but not limited to any general, special, incidental
! or consequential damages arising out of your use of or inability to use this
! work or the information contained in it, even if you have been advised
! of the possibility of such damages.

! In no event will the author(s), editor(s), or publisher(s) of this work
! be liable to you or to any other party for any injury, death,
! disfigurement, or other personal damage arising out of your use of
! or inability to use this work or the information
! contained in it, even if you have been advised of the
! possibility of such injury, death, disfigurement, or other
! personal damage.

! You should have received a copy of the GNU General Public License
! along with this work; if not, write to the
! Free Software Foundation, Inc., 59 Temple Place - Suite 330,
! Boston, MA  02111-1307, USA.

