!--------------------------------------------------------------------------
! Plot the glyphs (characters and symbols) available in a hershey-font.dat
! file (typically the one in gildas-src/kernel/etc/hershey-font.dat).
!
! Usage:
!   @ plot-hershey-font <filename>
!
! The plot shows several glyphs per plot page. Type C to show next page.
! For each glyph, its baseline and its bounding box is also displayed
! in light grey.
!
! Not all symbols are available from Greg by using DRAW TEXT (symbols needs
! to be mapped by an ASCII character and a dedicated font). See detailed
! comments in file gildas-src/kernel/lib/gchar/hershey2gag.f90, in
! particular about the baseline and bounding box definition.
!--------------------------------------------------------------------------

begin procedure accept1
  define integer f
  let f 'pro%arg[2]'
  accept hershey%xx['f+1'] hershey%yy['f+1'] -
         /column 'hershey%file' /format "1(2X,2F4.0)" /line 'pro%arg[1]'
end procedure accept1

begin procedure accept2
  define integer f
  let f 'pro%arg[2]'
  accept hershey%xx['f+1'] hershey%yy['f+1'] hershey%xx['f+2'] hershey%yy['f+2'] -
         /column 'hershey%file' /format "2(2X,2F4.0)" /line 'pro%arg[1]'
end procedure accept2

begin procedure accept3
  define integer f
  let f 'pro%arg[2]'
  accept hershey%xx['f+1'] hershey%yy['f+1'] hershey%xx['f+2'] hershey%yy['f+2'] -
         hershey%xx['f+3'] hershey%yy['f+3'] -
         /column 'hershey%file' /format "3(2X,2F4.0)" /line 'pro%arg[1]'
end procedure accept3

begin procedure accept4
  define integer f
  let f 'pro%arg[2]'
  accept hershey%xx['f+1'] hershey%yy['f+1'] hershey%xx['f+2'] hershey%yy['f+2'] -
         hershey%xx['f+3'] hershey%yy['f+3'] hershey%xx['f+4'] hershey%yy['f+4'] -
         /column 'hershey%file' /format "4(2X,2F4.0)" /line 'pro%arg[1]'
end procedure accept4

begin procedure accept5
  define integer f
  let f 'pro%arg[2]'
  accept hershey%xx['f+1'] hershey%yy['f+1'] hershey%xx['f+2'] hershey%yy['f+2'] -
         hershey%xx['f+3'] hershey%yy['f+3'] hershey%xx['f+4'] hershey%yy['f+4'] -
         hershey%xx['f+5'] hershey%yy['f+5'] -
         /column 'hershey%file' /format "5(2X,2F4.0)" /line 'pro%arg[1]'
end procedure accept5

begin procedure accept6
  define integer f
  let f 'pro%arg[2]'
  accept hershey%xx['f+1'] hershey%yy['f+1'] hershey%xx['f+2'] hershey%yy['f+2'] -
         hershey%xx['f+3'] hershey%yy['f+3'] hershey%xx['f+4'] hershey%yy['f+4'] -
         hershey%xx['f+5'] hershey%yy['f+5'] hershey%xx['f+6'] hershey%yy['f+6'] -
         /column 'hershey%file' /format "6(2X,2F4.0)" /line 'pro%arg[1]'
end procedure accept6

begin procedure accept7
  define integer f
  let f 'pro%arg[2]'
  accept hershey%xx['f+1'] hershey%yy['f+1'] hershey%xx['f+2'] hershey%yy['f+2'] -
         hershey%xx['f+3'] hershey%yy['f+3'] hershey%xx['f+4'] hershey%yy['f+4'] -
         hershey%xx['f+5'] hershey%yy['f+5'] hershey%xx['f+6'] hershey%yy['f+6'] -
         hershey%xx['f+7'] hershey%yy['f+7'] -
         /column 'hershey%file' /format "7(2X,2F4.0)" /line 'pro%arg[1]'
end procedure accept7

begin procedure plot-character
  define logical penup
  !
  g\limits -40 40 -40 40
  g\box n n n
  !
  ! Draw the baseline and bounding box
  g\pen /col gainsboro
  g\draw relo user_xmin hershey%base /user
  g\draw line user_xmax hershey%base /user
  g\draw relo hershey%minx hershey%miny /user
  g\draw line hershey%minx hershey%maxy /user
  g\draw line hershey%maxx hershey%maxy /user
  g\draw line hershey%maxx hershey%miny /user
  g\draw line hershey%minx hershey%miny /user
  g\pen /col foreground
  !
  ! Draw the symbol identifier
  g\draw text 0.1 0.1 hershey%id 9 /box 1
  g\draw relo hershey%xx[1] hershey%yy[1] /user
  !
  ! Draw the polyline
  let penup no
  for i 1 to size(hershey%xx)
    if hershey%xx[i].eq.-64 then
      let penup yes
    else if penup then
      g\draw relo hershey%xx[i] hershey%yy[i] /user
      let penup no
    else
      g\draw line hershey%xx[i] hershey%yy[i] /user
    endif
  next i
  !
end procedure plot-character

if .not.exist(hershey) then
  define structure hershey        /global
  define char*256  hershey%file   /global
  define integer   hershey%nline  /global
  define integer   hershey%id     /global
  define integer   hershey%length /global
  define integer   hershey%miny   /global
  define integer   hershey%base   /global
  define integer   hershey%maxy   /global
  define integer   hershey%minx   /global
  define integer   hershey%maxx   /global
endif

let hershey%file 'pro%arg[1]'
compute hershey%nline lines 'hershey%file'

define integer iline nv remain stored ibox
let iline 0
let ibox 0
@ window_tools
@ window_init
let position 0.01 1.40 0.01 0.99
clear
g\set char 0.4

for /while iline.lt.hershey%nline

  let iline iline+1
  accept hershey%id hershey%length hershey%miny hershey%base -
         hershey%maxy hershey%minx hershey%maxx -
         /column 'hershey%file' /format "7(2X,2F4.0)" /line 'iline'
  ! exa hershey%id hershey%length
  ! exa hershey%miny hershey%base hershey%maxy hershey%minx hershey%maxx

  let nv (hershey%length-5)/2
  if exist(hershey%xx)  del /var hershey%xx hershey%yy
  define integer hershey%xx[nv] hershey%yy[nv] /global

  let remain nv
  let stored 0
  for /while remain.gt.0
    let iline iline+1
    let nv min(7,remain)
    @ "accept"'nv' 'iline' 'stored'
    let remain remain-nv
    let stored stored+nv
  next
  ! exa hershey%xx hershey%yy

  let ibox ibox+1
  @ window_xy 7 5 'ibox'
  @ plot-character
  if ibox.eq.35 then
    pause 'iline'"/"'hershey%nline'" lines from Hershey font table"
    clear
    let ibox 0
  endif

next
