HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Revision of fontmap perl script




Hi,

The mailing list is aware that ghostscript now has dos compatible 
filenames for its fonts with the relation between the old and new names
kept in the 'Fontmap' text file. Eric Leibovitch kindly submitted a perl
script which would use the Fontmap file to create links between the 
names so that HylaFAX's textfmt program could still use them.

Setting up my new Redhat Linux 5.0 system and re-installing HylaFAX gave
me the opportunity for giving the script a whirl, and found that my
Fontmap file was in a different location, and that the script would
place the links in with the font files, and I wanted them in a seperate
directory. More importantly, the script only created links for 'real'
fonts and not the 'alias' fontnames (please see the Fontmap file for an
explanation of these terms); and it is the aliases such as Courier.afm
and Courier-Bold.afm that textfmt ( and faxsetup ) are looking for.

So I changed it.

The script is now twice as long as the original, but is easier for the
user to configure for the particulars of her system, and will link the
alias names as well as the real font names ( in fact, the default is to
do the alias names only ).

WARNING! This is my first perl script! Altho' I have a nice, warm feeling
about it, I realize that it is probably a load of clobbers. Please watch
carefully if you decide to run it and check afterwards that it's worked.

If there is some positive feedback, I will then submit a patch to Matthias
( and I'm wearing my asbestos suit just in case ).

Phil Watkinson,
Boston, UK.

-----%<-----------%<---------cut here------%<--------------%<---------------

#!/usr/bin/perl -w
#
#     /usr/src/hylafax-v4.0pl0/afm/fontmap.pl 
#     Written by: Evan Leibovitch, 3 Oct 1997
#     Amended by: Phil Watkinson,  8 Feb 1998
#
# -----------------------User Configurable Variables------------------------
# ----------------Please change the following for your system---------------

$fontdir = "../fonts";		# directory where font files are,
					# either full path or relative to linkdir
$fmapdir = "/usr/share/ghostscript/5.10";     # dir where the Fontmap lives
$linkdir = "/usr/share/ghostscript/afm";      # where links are to be created
$aliases_only = "yes";		# link only alias font entries,
					# change to "no" for real fonts as well
# -------------------------end of user configuration------------------------ 

#
# sub-routine to create link from source and destination arguments
#
sub createlink {
    if ( -r $fname) {
	system ("ln","-s",$_[0],$_[1]);
	print "Linking " . $_[0] . " to " . $_[1] . "\n";
    }	else   {
	print "Skipping " . $_[0] . ": no such file\n";
    }
}

#
# main code
#	
chdir $linkdir || die "$linkdir does not exist. Cannot proceed.\n";
	
open(FONTLIST, "$fmapdir/Fontmap") || die "Cannot open Fontmap: $!\n";
while (<FONTLIST>)
	{
	chop;
	next if (/^$/);				# skip blank lines
	@f=split(/\s+/);				# split line into words
	next unless substr($f[0],0,1) eq "/";	# skip comment lines, etc
	if ( substr( $f[1],0,1 ) ne "/" )		# now we have a real font
	    {
	    @l=split(/\./,$f[1]);	          # seperate filename extension
	    chop($l[1]);

	    if (( $l[1] eq "pfb" ) || ( $l[1] eq "pfa" ))
		# ignore gsf fonts which are not compatible
		{
		# save info in a hash table
		$fname = substr($l[0],1,40);
		$font = substr($f[0],1,40);
		$fonttable{ $font } = $fname;
		if ( $aliases_only ne "yes" )
		    # build up path and filenames and create link
		    {
		    $fname = $fontdir . "/" . $fname . ".afm";
		    $font = $font . ".afm";
		    createlink( $fname, $font );
		    }
		}
	    }
	    else					# then we have an alias
	    {
	    $alias = substr( $f[1],1,40);		# try to find alias font..
	    while (( $akey, $afile ) = each( %fonttable ))
		{
		if ( $akey eq $alias )		# ...found it in table
		    {
		    # build up path and filenames and create link
		    $fname = $fontdir . "/" . $afile . ".afm";
		    $font = substr( $f[0],1,40 ) . ".afm";
		    createlink( $fname, $font );
		    }
		}
	    }
	}

-----%<-----------%<----------cut here-------------%<-------------------




Project hosted by iFAX Solutions