From: timw@county.lmt.mn.org (Timothy Wright)
Subject: Re: listing fonts
Organization: LaserMaster R&D
Date: Fri, 25 Sep 92 20:42:23 GMT

In article <x4vqbjpk@csv.warwick.ac.uk>, esurw@warwick.ac.uk (Stephen Landamore) writes:
> 
> In some article or other, Pete Hartman writes:
> >
> > What is a good way to get a list of fonts available?
> >
> > I've beek poking through both red books, and I can't
> > seem to get anything that works.  level 2 "resourceforall"
> > doesn't work for my copy of ghostview (that I'm using for
> > testing) presumably because level 2 isn't implemented.
> > I'm completely self-taught, so I don't really understand
> > how to read a dictionary.  I've tried the following fragment
> > with no success.  Any pointers to what I'm doing wrong would
> > be greatly appreciated.
> >
> > %!
> > %
> > % icky to get a list of all fonts
> > %
> > /showfont 
> >  {
> > 	dup
> > 	findfont setfont	% display the font name IN the font
> >	127 string cvs show	% convert the font name to a string to show
> >  } def
> >
> > 50 30 moveto
> > /FontDirectory showfont forall
> >
> 
>   Without looking  at the above code for the time being, I should like
> to say that there are several routines floating around (sorry, I don't
> have one) that print lists of fonts known. Works just fine on our HP 3
> Si, but freaks out miserably on ghostscript (presumably also ghostview
> since that is just  a frontend to gs)...  Can  I  suggest you try  eg,
> /Times-Roman  findfont  setfont  before running,  see  if you  get any
> output (ie,  1  font!!!)   ...  gs seems  not to  recognise fonts with
> FontDictionary until they have been loaded  in with  findfont, sort of
> makes  the whole idea of listing available fonts with FontDirectory  a
> bit of a scam! Still, I s'pose there's a good reason for it (Bug! Bug!
> Bug!)
> 
>   Now to your code ;-)
>   You ought to stick a showpage on the end,  (shouldn't matter thought
> for gs / ghostview ? )
>   You  ought to stick an  eg. 12  scalefont  in  before the  setfont -
> unless of course you can read 1 point text =8^)
>   And  after  the  show  you  should  move  down  a  line  -  say,  eg
> currentpoint 3 -1  roll show moveto 0 -12  rmoveto, oh yes, the  point
> 50,30 is too near the bottom left, try 50, 500 ish
>   forall  takes a procedure  as an argument,  eg  { showfont }...  not
> showfont, also need to do a pop before the showfont
>   FontDirectory is supposed to return a list of fonts - /FontDirectory
> will put the name FontDirectory on the stack... remove the `/'
> 
> So your code would become something like:
> 
> ----------
> %!
> 
> % Function to print one font
> 
> /showfont {
>     dup
>     findfont 12 scalefont setfont      % display the font name IN the font
>     127 string cvs                     % convert the font name to a
>                                        % string to show
>     currentpoint 3 -1 roll show moveto % show, but keep currentpoint
>     0 -12 rmoveto                      % Down a line (font size)
> } def
> 
> % Main program
> 
> 100 600 moveto
> FontDirectory { pop showfont } forall
> 
> showpage
> ----------
>   As I said,  on ghostview, you will not  get  any output, try it on a
> laserprinter or similar.
> 
> Regards,
> Stephen
> -- 
> 	      Stephen Landamore, esurw@uk.ac.warwick.csv
> 	       University of Warwick, England, CV4 7AL.
> main(_){static long i=366640679;if(i=(_=i)>>6)main();putchar((_&'?')+62);}
> 
> 

Using the FontDirectory alone is a BAD way to determine what fonts
are available to your system.

As far as I am concerned, the proper way to do a font query that 
works for level 1 and 2 printers is something like:
--------------------------------------------------
%!

/ScratchString 100 string def

% to print over back channel:

/showfont {ScratchString cvs =} bind def
/flushpage /flush load def

%to print on page:

%20 700 moveto
%/ScratchString 100 string def
%/showfont {dup findfont 10 scalefont setfont ScratchString cvs
%          currentpoint 3 -1 roll show 10 sub moveto} bind def
%/flushpage /showpage load def

FontDirectory {pop showfont} bind forall
systemdict /filenameforall known{
(fonts/*) {(fonts/) search pop pop pop showfont} bind 100 string filenameforall
}if
flushpage
---------------------------------------------------
This is basically what the Mac LaserWriter driver does.  If you only look at
the FontDirectory you are missing out on any fonts that are on a hard
drive or CD attached to the printer.  What is the point of being able
to keep gobs of fonts in external storage if the software you are using
ignores them???

Tim W.

Newsgroups: comp.lang.postscript