#!/usr/local/bin/perl
#
# MakeTeXPK.pl version 1.0, Copyright (C) 1993,94 by Norman Walsh.
# NO WARRANTY. Distribute freely under the GNU GPL.
#
# This script attempts to make a new TeX PK font, because one wasn't
# found. Parameters are:
#
# name dpi bdpi [[[magnification] mode] subdir]
#
# `name' is the name of the font, such as `cmr10' (*NOT* cmr10.mf).
# `dpi' is the resolution the font is needed at.
# `bdpi' is the base resolution, useful for figuring out the mode to
# make the font in.
# `magnification' is a string to pass to MF as the magnification.
# `mode' if supplied, is the mode to use.
#
# This script was designed with two goals in mind: to support recursive
# subdirectory searching for fonts and to provide support for PK files
# built from both MF fonts and PS fonts. It also supports the Sauter
# and DC fonts which can be built at any design size.
#
# This script was designed and tested with the following directory structure
# in mind: each typeface is stored in its own directory with appropriate
# subdirectories for font sources, metrics, and glyphs. The script may not
# work exactly right if you use a different directory structure (the font
# installation, in particular, will probably be incorrect). However,
# several other versions of MakeTeXPK exist which will handle simpler
# directory structures, so you need not feel compelled to use the one
# described here.
#
# For MF fonts: (... is usually something like /usr/local/lib/tex/fonts)
#
# .../typeface/src holds the sources
# /tfm holds the TFM files
# /glyphs root for glyphs
# /glyphs/mode holds the PK files for "mode".
#
# For PS fonts: (... is usually something like /usr/local/lib/tex/fonts)
#
# .../typeface/afm holds the AFM files
# /tfm holds the TFM files
# /vf holds the VF files
# /vpl holds the VPL files
# /glyphs root for glyphs
# /glyphs/pk/999dpi holds the PK files at 999 dpi created by ps2pk
# /glpyhs/type1 holds the type1 PFA/PFB sources for the fonts
#
require "getopts.pl";
$rc = &Getopts ('v'); # Get options from the user...
$USE_MODE_IN_DEST = 1; # Does the destination directory name include
# the name of the mode?
chop($CWD = `pwd`); # Where are we?
$TEMPDIR = "/tmp/mkPK.$$"; # Where do temp files go?
$MFBASE = "&plain"; # What MF base do we use by default?
# Where are fonts stored?
$TEXFONTS = $ENV{"TEXFONTS"} || ".:/usr/local/lib/fonts//";
# Define modes that should be used for base resolutions...
$DPI_MODES{300} = "laserwriter";
$DPI_MODES{200} = "FAX";
$DPI_MODES{360} = "lqhires";
$DPI_MODES{400} = "nexthi";
$DPI_MODES{600} = "QMSmoa";
$DPI_MODES{100} = "nextscreen";
# Where are the DC fonts stored and what base names can be used?
$DCR_DIR = '/usr/local/lib/fonts/free/dc/src';
@DCR_GEN = ('dcb','dcbom','dcbx','dcbxsl','dcbxti','dccsc','dcdunh','dcff',
'dcfi','dcfib','dcitt','dcr','dcsl','dcsltt','dcss','dcssbx',
'dcssi','dctcsc','dcti','dctt','dcu','dcvtt' );
# Where are the Sauter fonts stored and what base names can be used?
$SAUTER_DIR = '/usr/local/lib/fonts/free/sauter/src';
@SAUTER_GEN = ('cmb','cmbizx','cmbozx','cmbsy','cmbszx','cmbx','cmbxsl',
'cmbxti', 'cmbz', 'cmbzx', 'cmcsc', 'cmdszc', 'cmdunh',
'cmex', 'cmff', 'cmfi', 'cmfib', 'cminch', 'cmitt', 'cmmi',
'cmmib', 'cmr', 'cmrcz', 'cmrisz', 'cmritz', 'cmriz',
'cmrotz', 'cmroz', 'cmrsz', 'cmrtz', 'cmruz', 'cmrz',
'cmsl', 'cmsltt', 'cmss', 'cmssbx', 'cmssdc', 'cmssi',
'cmssq', 'cmssqi', 'cmsy', 'cmtcsc', 'cmtex', 'cmti',
'cmtt', 'cmu', 'cmvtt', 'czinch', 'czssq', 'czssqi',
'lasy', 'lasyb');
# Get the command line arguments...
($NAME, $DPI, $BDPI, $MAG, $MODE, $FORCEDEST, $EXTRA) = @ARGV;
open (TTY, ">/dev/tty"); # Open the TTY (so we can print messages
select (TTY); $| = 1; select(STDOUT); # even if STDERR and STDOUT are both
# redirected)
if ($VERBOSE) {
print TTY "$0: font name: $NAME\n";
print TTY "$0: dpi: $DPI\n";
print TTY "$0: base dpi: $BDPI\n";
print TTY "$0: magnification: $MAG\n" if $MAG;
print TTY "$0: mode: $MODE\n" if $MODE;
print TTY "$0: force destination directory: $FORCEDEST\n" if $FORCEDEST;
print TTY "$0: extra: $EXTRA\n" if $EXTRA;
}
# Make sure we got enough arguments, but not too many...
die "$0: Invalid arguments.\n" if ($BDPI eq "" || $EXTRA ne "");
# Calculate the magnification from the requested resolutions if no
# magnification string was provided.
if (!$MAG) {
$MAG = "$DPI/$BDPI";
print TTY "$0: magnification: $MAG\n" if $VERBOSE;
}
# Calculate the mode if the mode was not given. Die if we don't know
# what mode to use for the requested base resolution.
if ($MODE eq "") {
$MODE = $DPI_MODES{$BDPI};
die "$0: No mode for ${BDPI}dpi base resolution.\n" if $MODE eq "";
print TTY "$0: mode: $MODE\n" if $VERBOSE;
}
# Presumably, we got here because the PK file doesn't exist. Let's look
# for the MF file or the PFA or PFB file...
# ... it's more complicated than that...
# If the font is from a PFA/B file, it may have the name "rxxx" or
# "xxx0" because virtual fonts extract glyphs from the "raw" font.
# We need to find the PFA/B file and install the font with the right name.
# I'm not sure what the best solution would really be, but this will work.
# Luckily, it gets installed with the right name 'cause we already
# figured that out...
#
# A better solution on Unix machines might be to make "xxx0.pfa" or
# "rxxx.pfa" a symbolic link to "xxx.pfa". But that won't work for other
# architectures...
open (SAVEOUT, ">&STDOUT");
open (SAVEERR, ">&STDERR");
close (STDOUT);
open (STDOUT, ">&TTY");
close (STDERR);
open (STDERR, ">&TTY");
# Chdir seems to return a funny exit code. So do it internally...
# (this is a hack)
if (@cmd[0] eq "chdir") {
$rc = chdir(@cmd[1]);
$rc = !$rc;
} else {
$rc = system(@cmd);
}
close (STDOUT);
open (STDOUT, ">&SAVEOUT");
close (SAVEOUT);
close (STDERR);
open (STDERR, ">&SAVEERR");
close (SAVEERR);
if ($rc) {
printf TTY "%s\n", "*" x 72;
print TTY "$0 error : system return code: $rc\n";
print TTY "$0 failed: @cmd\n";
printf TTY "%s\n", "*" x 72;
}
$rc;
}
sub make_and_cd_tempdir {
&run ("mkdir", "$TEMPDIR");
&run ("chdir", "$TEMPDIR");
}
# what a minute, suppose we just made a font in the current
# directory...let's put the PK file there too...
if (! -d "$target" && ($source_path eq $CWD)) {
$target = $source_path;
$USE_MODE_IN_DEST = 0;
}
}
while (!$target && ($ptarget = shift @paths)) {
$target = $ptarget if ($ptarget ne "." && $ptarget ne ".."
&& -d $ptarget && -w $ptarget);
}
if ($target) {
if (! -d $target) {
&run ("mkdir", "$target");
&run ("chmod", "777", "$target");
}
if ($USE_MODE_IN_DEST) {
$target .= "/$mode";
if (! -d $target) {
&run ("mkdir", "$target");
&run ("chmod", "777", "$target");
}
}
print TTY "Installing $font in $target.\n";
&run ("cp", "$font", "$target/fonttmp.$$");
&run ("chdir", "$target");
&run ("mv", "fonttmp.$$", "$font");
&run ("chmod", "a+r", "$font");
&run ("chdir", "$TEMPDIR");
print STDOUT "$target/$font\n";
} else {
print TTY "$0: Install failed: no where to put $font.\n";
}
}
sub make_from_mf {
local ($source_path, $source_file) = @_;
local ($mfsource, $mfinputs, $cmd);
local ($gfname, $pkname, $realdpi, $testdpi);
local ($cmpath);
print "source_path: $source_path\n" if $VERBOSE;
print "source_file: $source_file\n" if $VERBOSE;
sub find_fonts {
# This subroutine searches for font sources. It looks in all the directories
# in the path specified. Recursive searches are preformed on directories
# that end in //, !, or !!. The emTeX directive "!", which should search
# only one level deep, is treated exactly like "!!".
#
local($path, @fonts) = @_;
local(@dirs, $dir, $font);
local(@matches) = ();
local(@recursive_matches);
# Note: this perl script has to scan them all, the mask is meaningless.
# Especially since I'm looking for the font *source* not the TFM or
# PK file...