### -*-awk-*- ### /usr/local/src/ghostscript/make-Fontmap.awk, Mon May 20 14:38:01 2002 ### Edit by Nelson H. F. Beebe ### /usr/local/src/ghostscript/make-Fontmap.awk, Mon Sep 3 15:03:19 2001 ### Edit by Nelson H. F. Beebe ### /usr/local/lib/ghostscript/make-Fontmap.awk, Tue Jun 4 10:56:36 1996 ### Edit by Nelson H. F. Beebe ### ======================================================================== ### Create a new ghostscript font map file, Fontmap, to reflect ### additional fonts available locally. ### ### We assume that the base ghostscript font map file (Fontmap) is ### available (and provided as the first argument), plus a local ### customization in the same format (here called Fontmap.utah, but it ### can have any name, and can be empty), plus, optionally, one or more ### Adobe Distiller PSres.upr font map files (produced by Adobe's ### makepsres: ### ### Apple MacOSX /usr/X11R6/bin/makepsres ### GNU/Linux /usr/X11R6/bin/makepsres ### SGI IRIX /usr/bin/X11/makepsres ### Sun Solaris /usr/openwin/bin/makepsres ### ### or Piet Tutelaers' mkpsres, available in his ps2pk distribution at ### ### ftp://ftp.tue.nl/pub/tex/ps2pk16beta1.tgz ### ) ### ### PSres.upr files sometimes contain font filenames with relative ### paths; we provide no special handling of such names. If yours look ### that way, consider regenerating them with absolute paths before ### running this program. ### ### Since PSres.upr files have a fixed name, we simply pattern match on ### the input filename to determine whether we are processing a file in ### that format. ### ### The output file intentionally avoids listing font names more than ### once. Since font name duplications are likely when data is merged ### from multiple font maps, the additional data is recorded as a normal ### Fontmap line, but turned into a comment with the special prefix ### "%%% NO:". If you don't want such lines in your new Fontmap, filter ### them out with grep as shown below. ### ### Usage: ### awk -f make-Fontmap.awk Fontmap Fontmap.utah [PSres.upr] ... >Fontmap.new ### awk -f make-Fontmap.awk Fontmap Fontmap.utah [PSres.upr] ... | grep -v '^%+ NO:' >Fontmap.new ### ### The ghostscript Fontmap file must be first, but the remaining files ### can occur in any desired order: entries from earlier files are used ### in preference to ones from later files, so that file order may be ### important at some sites. ### ### WARNING: recent releases of ghostscript have a very short Fontmap ### file that contains an indirect reference to another file, typically ### a line like this: ### ### (Fontmap.GS) .runlibfile ### ### In such a case, supply THAT file in place of Fontmap: ### ### awk -f make-Fontmap.awk Fontmap.gs Fontmap.utah [PSres.upr] ... >Fontmap.new ### ### Install the output map file, Fontmap.new, as ### ### /usr/local/share/ghostscript/fonts/Fontmap ### ### or in a version-specific ghostscript directory, such as ### ### /usr/local/share/ghostscript/7.20/lib/Fontmap ### ### The installation location may be different on your system: run "gs ### --help" to see what search path has been compiled into your version ### of ghostscript. ### ### [20-May-2002] -- Handle Adobe PSres.upr files as well. ### [03-Sep-2001] -- Add comment header to start of contents of each ### input file, and close pipe in BEGIN action. ### [26-Oct-1996] -- Update install version number message, add check for ### duplications in Fontmap.utah, and add an extra comment ### line to output ### [04-Jun-1996] -- Original version. ### ======================================================================== BEGIN { "date" | getline Current_Date_and_Time close("date") Arg_Sep = " \\\n%%%\t\t" First_Filename = "" Second_Filename = "" Other_Filenames = "" In_FontOutline = 0 } /^[ \t]*$/ { print ""; next } # copy empty lines (FILENAME ~ /PSres.upr/) \ { do_PSres_upr_file($0); next } # expect PSres.upr file { do_Fontmap_file($1,$0) } # expect Fontmap file END { print "" >"/dev/stderr" print "========================================================================" >"/dev/stderr" print "Now install the output file as" >"/dev/stderr" print "\t/usr/local/share/ghostscript/fonts/Fontmap" >"/dev/stderr" print "or" >"/dev/stderr" print "\t/usr/local/share/ghostscript/x.yz/lib/Fontmap" >"/dev/stderr" print "where x.yz is the ghostscript version number." >"/dev/stderr" print "========================================================================" >"/dev/stderr" } ### ======================================================================== function do_check_filename() { if (First_Filename == "") { First_Filename = FILENAME for (k = 1; k < ARGC; ++k) { if (First_Filename == ARGV[k]) break; } Other_Filenames = "" for (k++; k < ARGC; ++k) Other_Filenames = Other_Filenames ((Other_Filenames == "") ? "" : Arg_Sep) ARGV[k] print "%%%=====================================================================" print "%%% WARNING: Do NOT edit this file: it was created automatically" print "%%%" print "%%% by awk -f make-Fontmap.awk " Arg_Sep First_Filename Arg_Sep Other_Filenames print "%%%" print "%%% by " ENVIRON["USER"] "@" (("INDOMAIN" in ENVIRON) ? ENVIRON["INDOMAIN"] : ENVIRON["HOST"]) print "%%% on " Current_Date_and_Time print "%%% in file://" ENVIRON["HOST"] ENVIRON["PWD"] print "%%%=====================================================================" } } function do_Fontmap_file(fontname,line, k,Other_Filenames) { do_check_filename() fontname = trim(fontname) line = trim(line) if (First_Filename == FILENAME) { # just remember this font and print its line if (fontname ~ "^/") Font_Used[fontname] = line print line } else # no longer in master Fontmap { if (Second_Filename == "") Second_Filename = FILENAME if (FNR == 1) print_header(FILENAME) if (fontname ~ "^/") # should look like "/fontname (filename) ;" { print ((fontname in Font_Used) ? "%%% NO:\t" : "") line if (!(fontname in Font_Used)) Font_Used[fontname] = line } else # probably a comment line print line } } function do_PSres_upr_file(line, fontfile,fontname,parts) { ## PSres.upr files contain several sections. We want only the ## ones that look like this: ## ## FontOutline ## AGaramond-Bold=/usr/local/sys/fonts/postscript/AGaramond-Bold.pfa ## AGaramond-BoldItalic=/usr/local/sys/fonts/postscript/AGaramond-BoldItalic.pfa ## ...more such entries ... ## . ## print "%%% DEBUG: do_PSres_upr_file(" line ")" line = trim(line) if (line ~ "^FontOutline") { In_FontOutline = 1 NeedHeader = 1 } if (In_FontOutline) { if (line ~ "^[.] *$") In_FontOutline = 0 else { ## Typical line: ## AGaramond-Bold=/usr/local/sys/fonts/postscript/AGaramond-Bold.pfa if (split(line, parts, "=") == 2) { if (NeedHeader) { print_header(FILENAME) NeedHeader = 0 } fontname = ("/" trim(parts[1])) fontfile = trim(parts[2]) printf("%s%-39s\t(%s) ;\n", ((fontname in Font_Used) ? "%%% NO:\t" : ""), fontname, fontfile) if (!(fontfile in Font_Used)) Font_Used[fontname] = line } } } } function print_header(filename) { print "\f" print "%%% ====================================================================" print "%%%" print "%%% Additional fonts available at local site from " filename print "%%%" print "%%% Fonts which are already defined above are commented out with the" print "%%% prefix \"%%% NO:\"" print "%%%" } function trim(s) { gsub(/^[ \t]+/,"",s) gsub(/[ \t]+$/,"",s) return (s) }