! display_glyph.MBS
! Display a single Hershey glyph at (0,0) in a local coordinate system.

local drawing module display_glyph(
int    glyph_number;
string glyph_short_name*132;
int    glyph_radius;
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    number_of_data_pairs;
int    data_pair_array(300);
float  crop_x, crop_y, crop_y_below;
int    rc;

string homedir*132;
string prefix*132;

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

beginmodule

   ! Create a coordinate system identical to our own
   ! (which is itself a local coordinate system created by the module
   ! which called us) so that it can be passed as the local coordinate system 
   ! to draw_glyph().  This leaves draw_glyph() relative in its coordinates.
   csys_1p(#1,"local",vec(0,0):blank=1);
   
   ! If at top level, draw four crop marks so that the image generated from
   ! this will crop to a known size.
   ! The multiplier numbers here are empirical.
   ! Calculate the crop positions in any event, as they'll be used in plotting.
   crop_x       := glyph_radius * 1.5;
   crop_y       := glyph_radius * 1.5;
   crop_y_below := glyph_radius * 2.2; ! adjust for label
   if toplevel = toplevel_true then
      poi_free(#11,vec(-crop_x, -crop_y_below));  ! lower left
      poi_free(#12,vec( crop_x, -crop_y_below));  ! lower right
      poi_free(#13,vec( crop_x,  crop_y));        ! upper right
      poi_free(#14,vec(-crop_x,  crop_y));        ! upper left
   endif;
   
   ! read the glyph data
   part(#20, read_glyph(glyph_number, number_of_data_pairs, data_pair_array, rc,
                        verbosity));
   if rc <> 0 then 
      goto fail;
   endif;
   
   ! draw the glyph in the local coordinate system established above
   part(#22,draw_glyph(glyph_number, 
                       0, 0,
                       glyph_short_name, glyph_radius, 
                       box_visibility, 
                       number_of_data_pairs, data_pair_array,
                       verbosity),
            #1);
   
   ! plot it
   if toplevel = toplevel_true then
      homedir := get_environment("HOME");
      if box_visibility = 0 then
         prefix := "glyph-";
      else
         prefix := "glyphboxed-";
      endif;
      plot_win(vec(-crop_x,-crop_y_below),
               vec( crop_x, crop_y),
         homedir + "/hershey_plots/" + prefix + str(glyph_number,1,0) + ".PLT");
   endif;

fail:;

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.

