]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
textFmt patch - Robert Colquhoun(rjc@trump.net.au)
authorRobert Colquhoun <rjc@trump.net.au>
Sat, 2 Jan 1999 04:25:04 +0000 (04:25 +0000)
committerRobert Colquhoun <rjc@trump.net.au>
Sat, 2 Jan 1999 04:25:04 +0000 (04:25 +0000)
TextFmt patch allows hylafax's textfmt(and faxmail) to directly
read ghostscript Fontmap files, removing the need for the afm files.

Also adds two config params 'Fontmap' and 'Fontpath'

12 files changed:
afm/Makefile.in
config.h.in
config.site
configure
defs.in
etc/faxsetup.sh.in
man/Makefile.in
man/faxmail.1
man/textfmt.1
util/TextFmt.c++
util/TextFmt.h
util/textfmt.c++

index a0ac353bc2d254b8f9c5417ec7bccd47ee628dc8..3bff532d4ac266784eb608bd56ea5648dcefc0d8 100644 (file)
@@ -99,8 +99,8 @@ targets: ${TARGETS}
 
 install: default ${AFMFILES}
        ${INSTALL} -u ${SYSUSER} -g ${SYSGROUP} -m ${DIRMODE}           \
-           -idb hylafax.sw.afm -dir ${AFMDIR}
+           -idb hylafax.sw.afm -dir ${FONTPATH}
        for i in ${AFMFILES}; do \
-           ${INSTALL} -F ${AFMDIR} -m 444 -idb ${PRODUCT}.sw.afm \
+           ${INSTALL} -F ${FONTPATH} -m 444 -idb ${PRODUCT}.sw.afm \
                -src ${SRCDIR}/$$i -O `echo $$i | ${SED} s/\.afm//`; \
        done
index cb681f8446f1602f63cc8fcce0a085b57151c536..85fcdb56ae65803954273fcd520bca893e8bb2f5 100644 (file)
 #endif
 
 /*
- * The default pathname for the Adobe Font Metric files
+ * The default pathname for the Fontmap(s) file
  * is compiled into util/TextFmt.o but can be overridden
  * through configuration files.
  */
-#ifndef _PATH_AFMDIR
-#define        _PATH_AFMDIR    "@AFMDIR@"      /* directory with AFM files */
+#ifndef _PATH_FONTMAP
+#define        _PATH_FONTMAP   "@FONTMAP@"     /* location of Fontmap(s) */
+#endif
+
+/*
+ * The default pathname for the location of the fonts
+ * is compiled into util/TextFmt.o but can be overridden
+ * through configuration files.
+ */
+#ifndef _PATH_AFM
+#define        _PATH_AFM       "@FONTPATH@"    /* location of Fonts */
 #endif
 
 /*
index 368c0651e206a246ae2a3cff1030d5906995ed1a..5e5d0652eaf481412553813b6f7d18e1aa155ee2 100644 (file)
@@ -59,7 +59,6 @@
 #
 # Directory parameters.
 #
-#DIR_AFM="/usr/lib/DPS/AFM"            # directory for AFM files
 #DIR_BIN="/usr/local/bin"              # directory for client apps
 #DIR_LIBDATA="/usr/lib/fax"            # directory for client data
 #DIR_LIBEXEC="/usr/lib/fax"            # directory for libraries&hidden apps
@@ -67,6 +66,8 @@
 #DIR_SPOOL="/var/spool/fax"            # directory for spooling area
 #DIR_SBIN="/var/spool/fax/bin"         # directory for system apps
 #DIR_LOCKS="/usr/spool/locks"          # directory for UUCP lock files
+#FONTMAP="/usr/share/ghostscript/3.33" # directorys containing Fontmap files
+#PATH_AFM="/usr/lib/DPS/AFM"           # directorys for AFM files
 
 #
 # HTML-specific parameters; only used when the
index 01e88686a841dd9a1761d914de6093841e87289c..92c23ed540dfada9b33991363092c549293e9729 100755 (executable)
--- a/configure
+++ b/configure
@@ -124,7 +124,6 @@ WARNING
 ZLIBINC"
 
 VAR2="AFM
-AFMDIR         DIR_AFM
 AWK
 BIN            DIR_BIN
 CAT
@@ -151,6 +150,8 @@ ECHO
 FAXGID
 FAXUID
 FILLORDER
+FONTMAP
+FONTPATH       PATH_AFM
 GETTY
 GREP
 GSRIP          PATH_GSRIP
@@ -3430,39 +3431,6 @@ else
     Note "Looks like UUCP lock files go in $DIR_LOCKS."
 fi
 
-#
-# Location of Adobe Font Metric files.
-#
-if [ -z "$DIR_AFM" ]; then
-    DIR_AFMS="
-       /usr/lib/afm
-       /usr/local/lib/afm
-       /usr/local/share/ghostscript/fonts
-       /usr/local/lib/ghostscript/fonts
-       /usr/gnu/lib/ghostscript/fonts
-       /opt/gnu/lib/ghostscript/fonts
-       /usr/lib/ghostscript/fonts
-       /usr/lib/gnu/ghostscript/fonts
-    "
-    case $TARGET in
-    *-irix*)   DIR_AFMS="/usr/lib/DPS/AFM $DIR_AFMS";;
-    *-bsdi*)   DIR_AFMS="/usr/contrib/lib/flexfax/afm $DIR_AFMS";;
-    *-sunos*)  DIR_AFMS="/usr/openwin/lib/fonts/afm $DIR_AFMS";;
-    esac
-    DIR_AFM=
-    for i in $DIR_AFMS; do
-       test -d $i && { DIR_AFM=$i; break; }
-    done
-fi
-if [ -z "$DIR_AFM" ]; then
-    # put it where ghostscript normally puts things
-    DIR_AFM=/usr/local/lib/ghostscript/fonts
-    Note "WARNING, could not locate a directory with font metric information,"
-    Note "guessing that font metric information goes in $DIR_AFM."
-else
-    Note "Looks like font metric information goes in $DIR_AFM."
-fi
-
 bitchExecutable()
 {
     echo ""
@@ -3546,6 +3514,79 @@ PickRIP
 Note "Looks like $PATH_PSRIP is the PostScript RIP to use."
 CheckRIP
 
+#
+# Ghostscript Fontmap File
+#
+
+getGSFonts()
+{
+       if [ ! "$PS" = gs -a -n $PATH_PSRIP ];then
+               return 1
+       fi
+       $PATH_PSRIP -h | awk -F '[ ]' '
+               BEGIN { start = 0; }
+               /Search path:/ { start = 1 }
+               {
+                       if (start == 1) {
+                               if ($1 == "") {
+                                       gsub(" ","")
+                                       gsub("^[.]","")
+                                       gsub("^:","")
+                                       printf "%s", $0
+                               } else if ($1 != "Search") start = 0
+                       }
+               }       
+       '
+       return 0
+}
+
+if [ -z "$FONTMAP" ]; then
+       FONTMAP=`getGSFonts`
+       if [ -n "$FONTMAP" ]; then
+               AFM="no"
+       fi
+fi
+Note "Setting the Fontmap path to $FONTMAP"
+
+#
+# Location of Adobe Font Metric files.
+#
+if [ -z "$PATH_AFM" ]; then
+    # if the fontmap path is available use that
+    # else just guess
+    if [ -n "$FONTMAP" ]; then
+       PATH_AFM=$FONTMAP
+    else
+        DIR_AFMS="
+           /usr/lib/afm
+           /usr/local/lib/afm
+           /usr/local/share/ghostscript/fonts
+           /usr/local/lib/ghostscript/fonts
+           /usr/gnu/lib/ghostscript/fonts
+           /opt/gnu/lib/ghostscript/fonts
+           /usr/lib/ghostscript/fonts
+           /usr/lib/gnu/ghostscript/fonts
+        "
+        case $TARGET in
+        *-irix*)       DIR_AFMS="/usr/lib/DPS/AFM $DIR_AFMS";;
+        *-bsdi*)       DIR_AFMS="/usr/contrib/lib/flexfax/afm $DIR_AFMS";;
+        *-sunos*)      DIR_AFMS="/usr/openwin/lib/fonts/afm $DIR_AFMS";;
+        esac
+        PATH_AFM=
+        for i in $DIR_AFMS; do
+           test -d $i && { PATH_AFM=$i; break; }
+        done
+    fi
+fi
+if [ -z "$PATH_AFM" ]; then
+    # put it where ghostscript normally puts things
+    PATH_AFM=/usr/local/lib/ghostscript/fonts
+    Note "WARNING, could not locate a directory with font metric information,"
+    Note "guessing that font metric information goes in $PATH_AFM."
+else
+    Note "Looks like font metric information goes in $PATH_AFM."
+fi
+
 #
 # Setup manual page-related stuff.
 #
@@ -3877,18 +3918,19 @@ HylaFAX configuration parameters are:
 [ 5] Directory for manual pages:        $DIR_MAN
 [ 6] Directory for HTML documentation:  $DIR_HTML
 [ 7] Directory for spooling:            $DIR_SPOOL
-[ 8] Directory for font metrics:        $DIR_AFM
-[ 9] Directory for uucp lock files:     $DIR_LOCKS
-[10] Uucp lock file scheme:             $LOCKS
-[11] PostScript imager package:         $PS
-[12] PostScript imager program:         $PATH_PSRIP
-[13] Manual page installation scheme:   $MANSCHEME
-[14] Default page size:                 $PAGESIZE
-[15] Default vertical res (lpi):        $DEFVRES
-[16] Location of getty program:         $PATH_GETTY
-[17] Location of voice getty program:   $PATH_VGETTY
-[18] Location of sendmail program:      $PATH_SENDMAIL
-[19] Location of TIFF tools:            $TIFFBIN
+[ 8] Path for fontmap files:            $FONTMAP
+[ 9] Path for font metrics:             $PATH_AFM
+[10] Directory for uucp lock files:     $DIR_LOCKS
+[11] Uucp lock file scheme:             $LOCKS
+[12] PostScript imager package:         $PS
+[13] PostScript imager program:         $PATH_PSRIP
+[14] Manual page installation scheme:   $MANSCHEME
+[15] Default page size:                 $PAGESIZE
+[16] Default vertical res (lpi):        $DEFVRES
+[17] Location of getty program:         $PATH_GETTY
+[18] Location of voice getty program:   $PATH_VGETTY
+[19] Location of sendmail program:      $PATH_SENDMAIL
+[20] Location of TIFF tools:            $TIFFBIN
 
 EOF
 }
@@ -3917,15 +3959,18 @@ promptForParameter()
     7) promptForNonNullStringParameter "$DIR_SPOOL" \
            "Directory to setup server spooling area";  DIR_SPOOL="$param"
        ;;
-    8) promptForNonNullStringParameter "$DIR_AFM" \
-           "Directory to find Adobe font metrics";     DIR_AFM="$param"
+    8) promptForNonNullStringParameter "$FONTMAP" \
+           "Path for gs Fontmap files";        FONTMAP="$param"
+       ;;
+    9) promptForNonNullStringParameter "$PATH_AFM" \
+           "Path for font metric files";       PATH_AFM="$param"
        ;;
-    9) promptForNonNullStringParameter "$DIR_LOCKS" \
+    10)        promptForNonNullStringParameter "$DIR_LOCKS" \
            "Directory for uucp lock files";            DIR_LOCKS="$param"
        ;;
-    10)        promptForUUCPLockScheme;;
-    11)        promptForImagerPackage; PickRIP; CheckRIP;;
-    12)        promptForNonNullStringParameter "$PATH_PSRIP" \
+    11)        promptForUUCPLockScheme;;
+    12)        promptForImagerPackage; PickRIP; CheckRIP;;
+    13)        promptForNonNullStringParameter "$PATH_PSRIP" \
            "PostScript imager program";                PATH_PSRIP="$param"
        case "$PS" in
        dps)    PATH_DPSRIP=$PATH_PSRIP;;
@@ -3933,19 +3978,19 @@ promptForParameter()
        gs)     PATH_GSRIP=$PATH_PSRIP;;
        esac
        ;;
-    13)        promptForManPageScheme;;
-    14)        promptForPageSize $SRCDIR/util/pagesizes.in;;
-    15)        promptForVRes;;
-    16)        promptForNonNullStringParameter "$PATH_GETTY" \
+    14)        promptForManPageScheme;;
+    15)        promptForPageSize $SRCDIR/util/pagesizes.in;;
+    16)        promptForVRes;;
+    17)        promptForNonNullStringParameter "$PATH_GETTY" \
            "Location of getty program";                PATH_GETTY="$param"
        ;;
-    17) promptForNonNullStringParameter "$PATH_VGETTY" \
+    18) promptForNonNullStringParameter "$PATH_VGETTY" \
            "Location of vgetty program";               PATH_VGETTY="$param"
        ;;
-    18)        promptForNonNullStringParameter "$PATH_SENDMAIL" \
+    19)        promptForNonNullStringParameter "$PATH_SENDMAIL" \
            "Location of sendmail program";             PATH_SENDMAIL="$param"
        ;;
-    19) promptForNonNullStringParameter "$TIFFBIN" \
+    20) promptForNonNullStringParameter "$TIFFBIN" \
            "Location of TIFF tools";                   TIFFBIN="$param"
     esac
 }
@@ -3959,7 +4004,7 @@ if [ $QUIET = no ]; then
     ok=skip
     while [ "$ok" != y ] && [ "$ok" != yes ]; do
        if [ "$ok" != skip ]; then
-           for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
+           for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
                promptForParameter $i;
            done
        fi
@@ -3969,7 +4014,7 @@ if [ $QUIET = no ]; then
        prompt "Are these ok [yes]?"; read ok
        test -z "$ok" && ok=yes
        case "$ok" in
-       [1-9]|1[0-9])   promptForParameter $ok;;
+       [1-9]|1[0-9]|20)        promptForParameter $ok;;
        [yY]*|[nN]*)    continue;;
        ?*)
            echo ""
@@ -4065,7 +4110,7 @@ if [ $IMP = yes ]; then
     }
 fi
 if [ "$AFM" = auto ]; then
-    if [ ! -f $DIR_AFM/Courier -a ! -f $DIR_AFM/Courier.afm ]; then
+    if [ ! -f $PATH_AFM/Courier -a ! -f $PATH_AFM/Courier.afm ]; then
        Note ""
        Note "WARNING, no font metric files appear to be installed on your system, enabling"
        Note "installation of the default set of metric files included with this software."
diff --git a/defs.in b/defs.in
index 1b5cfb68751e3d0d555e89733888decb4263d78c..0d9834d97884d71695b53e3e40f0c15503ccf521 100644 (file)
--- a/defs.in
+++ b/defs.in
@@ -50,7 +50,8 @@ BIN           = @BIN@
 LIBDATA                = @LIBDATA@
 LIBEXEC                = @LIBEXEC@
 HTMLDIR                = @HTMLDIR@
-AFMDIR         = @AFMDIR@
+FONTMAP                = @FONTMAP@
+FONTPATH       = @FONTPATH@
 #
 TOPSRCDIR      = @SRCDIR@
 PORT           = ${DEPTH}/port
index 9e42608e92a4f17963372061b849e914b40bb146..15942246ae5e966d425b74a4271e90975e58a4f4 100644 (file)
@@ -79,7 +79,7 @@ VERSION="@VERSION@"           # configured version
 DATE="@DATE@"                  # data software was configured
 TARGET="@TARGET@"              # configured target
 
-DIR_AFM=@AFMDIR@               # directory for Adobe Font Metric files
+PATH_AFM=@FONTPATH@            # directory for Adobe Font Metric files
 DIR_BIN=@BIN@                  # directory for client applications
 DIR_LIBDATA=@LIBDATA@          # directory for client data files
 DIR_LIBEXEC=@LIBEXEC@          # directory where servers are located
@@ -111,7 +111,7 @@ POSIXLY_CORRECT=1; export POSIXLY_CORRECT           # disable GNU extensions
 # (but some confusion within this script).
 #
 VARS="SCRIPT_SH
-AFMDIR         DIR_AFM
+FONTPATH               PATH_AFM
 AWK
 BIN            DIR_BIN
 CAT
@@ -1081,54 +1081,53 @@ fi
 # Installation of Adobe Font Metric files
 #
 if onClient; then
-    if [ -d $DIR_AFM ]; then
-       if [ ! -f $DIR_AFM/Courier ] && [ ! -f $DIR_AFM/Courier.afm ]; then
-           cat >&4 <<EOF
-
-
-Warning: Font metric information files were not found!
-
-The font metric information file for the Courier font was not found in
-the $DIR_AFM directory.  This means that client HylaFAX applications 
-that use this information to format ASCII text for submission as fax will
-use incorrect information and generate potentially illegible facsimile.
-
-If font metric information is present on your system in a directory other
-than $DIR_AFM then you can setup a symbolic link to the appropriate
-directory or you can specify the appropriate pathname in the configuration
-file $DIR_LIBDATA/hyla.conf with a line of the form:
-
-FontDir:       someplace_unexpected
-
-If you do not have the font metric information files loaded on your system
-system you can obtain them by public FTP from the place where you obtained
-the HylaFAX software or from the master FTP site at ftp.sgi.com.
-EOF
+    FDIRS=`echo $PATH_AFM | sed "s/:/ /g"`
+    MATCH=
+    for FDIR in $FDIRS; do
+    if [ -d $FDIR ]; then
+       cd $FDIR
+       if [ -n "`ls | grep '.afm'`" ] || [ -f Courier ]; then
+               MATCH=$FDIR
+               break
        fi
     else
        cat >&4 <<EOF
 
 
-Warning: $DIR_AFM does not exist or is not a directory!
+Warning: $FDIR does not exist or is not a directory!
 
-The directory $DIR_AFM does not exist or this file is not a directory.
+The directory $FDIR does not exist or this file is not a directory.
 This is the directory where the HylaFAX client applications expect to
 locate font metric information to use in formatting ASCII text for
 submission as facsimile.  Without this information HylaFAX may generate
 illegible facsimile from ASCII text.
 
+EOF
+    fi
+    done
+    if [ -z "$MATCH" ];then
+           cat >&4 <<EOF
+
+
+Warning: Font metric information files were not found!
+
+The font metric information file for the Courier font was not found in
+the $PATH_AFM path.  This means that client HylaFAX applications 
+that use this information to format ASCII text for submission as fax will
+use incorrect information and generate potentially illegible facsimile.
+
 If font metric information is present on your system in a directory other
-than $DIR_AFM then you can setup a symbolic link to the appropriate
+than $PATH_AFM then you can setup a symbolic link to the appropriate
 directory or you can specify the appropriate pathname in the configuration
 file $DIR_LIBDATA/hyla.conf with a line of the form:
 
-FontDir:       someplace_unexpected
+FontPath:      someplace_unexpected
 
 If you do not have the font metric information files loaded on your system
 system you can obtain them by public FTP from the place where you obtained
 the HylaFAX software or from the master FTP site at ftp.sgi.com.
 EOF
-    fi
+     fi
 fi
 
 #
index ee0b8c3f0f46c30b33d4820d576fa89c1992a9c4..2a58b4a81e1af40d949671be51cc7b4ed9d3e7a5 100644 (file)
@@ -123,7 +123,7 @@ MANSED=${SED}\
        -e 's;\$${SBIN};${SBIN};g' \
        -e 's;\$${LIBDATA};${LIBDATA};g' \
        -e 's;\$${LIBEXEC};${LIBEXEC};g' \
-       -e 's;\$${AFMDIR};${AFMDIR};g' ${MANSEDLOCAL}
+       -e 's;\$${FONTPATH};${FONTPATH};g' ${MANSEDLOCAL}
 
 default all targets:: ${TARGETS}
 
index 042ab7fd4c0650ea5f0877c7666682b5c755a4ec..76ecad61aa509a11d97da8a6240dcab3423fe49d 100644 (file)
@@ -438,7 +438,7 @@ AutoCoverPage       boolean \s-1Yes\s+1     automatically generate cover page
 BoldFont       string  \s-1Helvetica-Bold\s+1  font for setting header tags
 Columns        integer \s-11\s+1       number of columns in formatted output
 DigestDivider  string  \-      multipart/digest divider \*(Ps command
-FontDir        string  \s-1\fIsee below\fP\s+1 directory for font metric files
+FontPath       string  \s-1\fIsee below\fP\s+1 directory for font metric files
 GaudyHeaders   boolean \s-1No\s+1      enable/disable gaudy page headers
 Headers        string  \s-1\fIsee below\fP\s+1 headers to retain in envelope
 ISO8859        boolean \s-1Yes\s+1     use ISO 8859-1 character encoding
@@ -516,9 +516,9 @@ mark of some sort.
 Dividers are expected to use no more vertical space on the
 output page than a line of text.
 .TP 15
-.B FontDir
-The directory where Adobe Font Metric (\s-1AFM\s+1) files are
-located; by default ${AFMDIR}.
+.B FontPath
+The path where Adobe Font Metric (\s-1AFM\s+1) files are
+located; by default ${FONTPATH}.
 .TP 15
 .B GaudyHeaders
 Control whether or not to use a gaudy-style page header.
@@ -675,7 +675,7 @@ ${LIBDATA}/hyla.conf        system-wide configuration file
 ${LIBDATA}/faxmail.conf        system-wide configuration file
 ${LIBDATA}/sendfax.conf        system-wide configuration file for direct delivery
 ${LIBEXEC}/faxmail     hierarchy for external \s-1MIME\s+1 converters
-${AFMDIR}      for font metrics
+${FONTPATH}    for font metrics
 /usr/tmp/faxmailXXXXXX temporary files
 .fi
 .SH "SEE ALSO"
index 48e940ddb2eb81c89b0949f8a4f46ffce008d94f..2849a7591f7fdb1ce71677bb4ad381c2c425eb33 100644 (file)
@@ -54,7 +54,7 @@ will read from standard input.
 .PP
 By default,
 .I textfmt
-will generate an output document that is formtted with a single
+will generate an output document that is formatted with a single
 vertical column of text, set in a 10 point fixed width font, and
 with a simple page header that consists of the file name, last
 modification date, and the page number.
@@ -92,6 +92,10 @@ encoding in the generated \*(Ps.
 Set text using the \*(Ps font named
 .IR font .
 .TP
+.BI \-F " fontdir(s)"
+.IR Path(s)
+to \s-1afm\s+1 font files.
+.TP
 .B \-G
 Use a gaudy-style page header.
 .TP
@@ -172,11 +176,11 @@ Configuration files follow the conventions described in
 The following configuration parameters are recognized:
 .sp .5
 .nf
-.ta \w'TextLineHeight    'u +\w'boolean    'u +\w'\s-1\fIsee below\fP\s+1    'u
 \fBTag Type    Default Description\fP
 Columns        integer \s-11\s+1       number of columns in formatted output
-FontDir        string  \s-1\fIsee below\fP\s+1 directory for font metric files
 GaudyHeaders   boolean \s-1No\s+1      enable/disable guady page headers
+FontMap       string  \s-1\fIsee below\fP\s+1 location of ghostscript Fontmap file
+FontPath      string  \s-1\fIsee below\fP\s+1 directory for font metric files
 ISO8859        boolean \s-1Yes\s+1     use ISO 8859-1 character encoding
 LineWrap       boolean \s-1Yes\s+1     wrap/truncate text lines
 Orientation    string  \s-1portrait\s+1        orientation of text on page
@@ -225,9 +229,21 @@ The number of columns to set text in.
 .B \-m
 option.)
 .TP 15
-.B FontDir
-The directory where Adobe Font Metric (\s-1AFM\s+1) files are
-located; by default ${AFMDIR}.
+.B FontMap
+The directory or directories where the ghostscript Fontmap file(s)
+are located; multiple paths are seperated by a colon (":"). The
+Fontmap table allows the translation of the descriptive name of the
+font (as used by the
+.IR TextFont
+parameter) to the ghostscript font filenames. Setting the value to ""
+(zero length string) disables this translation and provides functionality
+with RIPs other than ghostscript.
+.TP 15
+.B FontPath
+The path where Adobe Font Metric (\s-1AFM\s+1) files are
+located; by default ${FONTPATH}. (Equivalent to the
+.B \-F
+option.)
 .TP 15
 .B GaudyHeaders
 Control whether or not to use a gaudy-style page header.
@@ -315,7 +331,7 @@ Set the output page width in inches (in inches).
 Set the tab stop distance; in characters.
 .TP 15
 .B TextFont
-Set the name of font to use for setting text.
+Set the descriptive name of font to use for setting text.
 (Equivalent to the
 .B \-f
 option.)
@@ -349,7 +365,7 @@ program written by Don Beebe.
 ${LIBDATA}/hyla.conf   system-wide configuration file
 ~/.hylarc      per-user configuration file
 ${LIBDATA}/pagesizes   page size database
-${AFMDIR}      font metric files
+${FONTPATH}   font metric files
 .fi
 .SH "SEE ALSO"
 .IR hylafax (1),
index f45151a12caf07160607ee099f2ad059f04eb47f..710a6fe53ee6d5ebfc3b34b7e0ac790b75eb5175 100644 (file)
@@ -141,6 +141,7 @@ TextFmt::getFont(const char* name) const
 
 void TextFmt::setFont(TextFont* f)             { curFont = f; }
 void TextFmt::setFont(const char* name)                { curFont = (*fonts)[name]; }   
+void TextFmt::setFontPath(const char* path)    { TextFont::fontPath = path; }  
 
 void TextFmt::setOutputFile(FILE* f)           { output = f; }
 void TextFmt::setNumberOfColumns(u_int n)      { numcol = n; }
@@ -1117,8 +1118,10 @@ TextFmt::setConfigItem(const char* tag, const char* value)
        setTextLineHeight(inch(value));
     else if (streq(tag, "tabstop"))
        tabStop = getNumber(value);
-    else if (streq(tag, "fontdir"))            // XXX
-       TextFont::fontDir = value;
+    else if (streq(tag, "fontmap"))            // XXX
+       TextFont::fontMap = value;
+    else if (streq(tag, "fontpath"))
+       setFontPath(value);
     else
        return (FALSE);
     return (TRUE);
@@ -1126,7 +1129,8 @@ TextFmt::setConfigItem(const char* tag, const char* value)
 
 #define        NCHARS  (sizeof (widths) / sizeof (widths[0]))
 
-fxStr TextFont::fontDir = _PATH_AFMDIR;
+fxStr TextFont::fontMap = _PATH_FONTMAP;
+fxStr TextFont::fontPath = _PATH_AFM;
 u_int TextFont::fontID = 0;
 
 TextFont::TextFont(const char* cp) : family(cp)
@@ -1138,32 +1142,113 @@ TextFont::TextFont(const char* cp) : family(cp)
 TextFont::~TextFont() {}
 
 fxBool
-TextFont::findFont(const char* name)
+TextFont::decodeFontName(const char* name, fxStr& filename, fxStr& emsg)
 {
-    fxBool ok = FALSE;
-    DIR* dir = Sys::opendir(fontDir);
-    if (dir) {
-       int len = strlen(name);
-       dirent* dp;
-       while ((dp = readdir(dir)) != NULL) {
-           int l = strlen(dp->d_name);         // XXX should d_namlen
-           if (l < len)
-               continue;
-           if (strcasecmp(name, dp->d_name) == 0) {
-               ok = TRUE;
-               break;
-           }
-           // check for .afm suffix
-           if (l-4 != len || strcmp(&dp->d_name[len], ".afm"))
-               continue;
-           if (strncasecmp(name, dp->d_name, len) == 0) {
-               ok = TRUE;
-               break;
-           }
-       }
-       closedir(dir);
+    struct stat junk;
+    fxStr path = fontMap;
+    u_int index = path.next(0, ':');
+    while (index > 0) {
+        fxStr fontMapFile = path.head(index) | "/" | "Fontmap";
+        path.remove(0, index);
+        if (path.length() > 0) path.remove(0, 1);
+        FILE* fd = Sys::fopen(fontMapFile, "r");
+        if (fd != NULL && fontMapFile[0] == '/') {
+            fxStr key = name;
+            char buf[1024];
+           int aliascount = maxaliases;
+            while (fgets(buf, sizeof(buf), fd) != NULL &&
+               aliascount > 0) {
+                int len = strcspn(buf, "%\n");
+                if (len == strlen(buf)) {
+                   emsg = fxStr::format(
+                       "Warning:%s - line too long.", (const char*)fontMapFile);
+                       break;
+                }
+               if (len == 0) continue;
+                *(buf + len) = '\0';
+                char* tmp = buf + strcspn(buf, ") \t");
+                *tmp++ = '\0';
+                tmp += strspn(tmp, " \t");
+                if (strcmp(key, buf + 1) == 0) {
+                    //match - now ensure it is the last one in the file
+                   // for gs compatibility
+                    *(tmp + strcspn(tmp, ") \t;")) = '\0';
+                    fxStr val = tmp;
+                    while (fgets(buf, sizeof(buf), fd) != NULL) {
+                        len = strcspn(buf, "%\n");
+                        *(buf + len) = '\0';
+                        if (len == strlen(buf)) {
+                           emsg = fxStr::format(
+                               "Warning: %s - line too long.", (const char*) fontMapFile);
+                           break;
+                        }
+                       if (len == 0) continue;
+                       tmp = buf + strcspn(buf, ") \t");
+                       *tmp++ = '\0';
+                        tmp += strspn(tmp, " \t");
+                        if (strcmp(key, buf + 1) == 0) {
+                            *(tmp + strcspn(tmp, ") \t;")) = '\0';
+                            val = tmp;
+                       }
+                   }
+                    if (val[0] == '/') {
+                       //alias
+                       aliascount--;
+                       val.remove(0);
+                       key = val;
+                       fseek(fd, 0L, SEEK_SET);
+                    } else {
+                        //real file
+                        fclose(fd);
+                       val.remove(0);
+                       int pos = val.next(0, '.');
+                       val.remove(pos, val.length() - pos);
+                       val.append(".afm");
+                       //move through dirs looking for font
+                       fxStr fpath = fontPath;
+                        int index2 = fpath.next(0, ':');
+                        filename = fpath.head(index2) | "/" | val;
+                        fpath.remove(0, index2);
+                       if (fpath.length() > 0) fpath.remove(0, 1);
+                       while (stat(filename, &junk) != 0 && index2 > 0) {
+                            index2 = fpath.next(0, ':');
+                            filename = fpath.head(index2) | "/" | val;
+                            fpath.remove(0, index2);
+                           if (fpath.length() > 0) fpath.remove(0, 1);
+                       }
+                       fxBool result = stat(filename, &junk) ? FALSE : TRUE;
+                       if (!result)
+                           emsg = fxStr::format(
+                               "Warning: %s invalid Fontmap entry - no filename present", (const char*)val);
+                        return result;
+                    }
+                }
+            }
+            fclose(fd);
+        }
+        index = path.next(0, ':');
+    }
+    //decoding using fontmap has failed
+    //now try plain filename with/without afm extension
+    path = fontPath;
+    index = path.next(0, ':');
+    while (index > 0) {
+        filename = path.head(index) | "/" | name | ".afm";
+        path.remove(0, index);
+        if (path.length() > 0) path.remove(0, 1);
+        if (stat(filename, &junk) == 0) return TRUE;
+       filename.resize(filename.length()-4);   // strip ``.afm''
+        if (stat(filename, &junk) == 0) return TRUE;
+        index = path.next(0, ':');
     }
-    return (ok);
+    return FALSE;
+}
+
+fxBool
+TextFont::findFont(const char* name)
+{
+    fxStr myname, emsg;
+    return decodeFontName(name, myname, emsg);
 }
 
 static const char* defISOFont = "\
@@ -1257,15 +1342,14 @@ TextFont::getAFMLine(FILE* fp, char* buf, int bsize)
 }
 
 FILE*
-TextFont::openAFMFile(fxStr& fontPath)
+TextFont::openAFMFile(fxStr& fontpath)
 {
-    fontPath = fontDir | "/" | family | ".afm";
-    FILE* fd = Sys::fopen(fontPath, "r");
-    if (fd == NULL && errno == ENOENT) {
-       fontPath.resize(fontPath.length()-4);   // strip ``.afm''
-       fd = Sys::fopen(fontPath, "r");
-    }
-    return (fd);
+    fxStr emsg;
+    if (!decodeFontName(family, fontpath, emsg)) {
+       fprintf(stderr,emsg);
+        return NULL;
+    } 
+    return Sys::fopen(fontpath, "r");
 }
 
 fxBool
index c07bec2b65a8d71dbc47d546cf597d9c47ae4745..545627192e4a60363a9dad9e0114999c522df83e 100644 (file)
@@ -35,12 +35,14 @@ typedef long TextCoord;             // local coordinates
 
 class TextFont {
 private:
+    enum { maxaliases = 10 };          // max no of aliases to find a font
     fxStr      family;                 // font family name
     fxStr      setproc;                // PostScript setfont procedure
     fxStr      showproc;               // PostScript show procedure
     TextCoord  widths[256];            // width table
 
-    static fxStr fontDir;              // directory for metric files
+    static fxStr fontMap;              // location of Fontmap file
+    static fxStr fontPath;             // path for afm files
     static u_int fontID;               // font identifier number
 
     friend class TextFmt;
@@ -48,6 +50,7 @@ private:
     void loadFixedMetrics(TextCoord w);
     FILE* openAFMFile(fxStr& pathname);
     fxBool getAFMLine(FILE* fp, char* buf, int bsize);
+    static fxBool decodeFontName(const char*, fxStr&, fxStr&);
 public:
     TextFont(const char*);
     ~TextFont();
@@ -211,6 +214,7 @@ public:
     const TextFont* getFont(const char* name) const;
     void setFont(TextFont*);
     void setFont(const char*);
+    void setFontPath(const char*);
 
     void hrMove(TextCoord);
     TextCoord getXOff(void) const;
index 5fc7fdf8032aa7566fde37b136385a64fb4488c0..99214d9ac49648ee45799beb73d0716de77de831 100644 (file)
@@ -49,6 +49,7 @@ usage()
        " [-c]"
        " [-D]"
        " [-f fontname]"
+       " [-F fontdir(s)]"
        " [-m N]"
        " [-o #]"
        " [-p #]"
@@ -87,7 +88,7 @@ main(int argc, char* argv[])
     fmt.readConfig(FAX_USERCONF);
 
     prog = argv[0];
-    while ((c = getopt(argc, argv, "f:m:M:o:p:s:V:12BcDGrRU")) != -1)
+    while ((c = getopt(argc, argv, "f:F:m:M:o:p:s:V:12BcDGrRU")) != -1)
        switch(c) {
        case '1':               // 1-column output
        case '2':               // 2-column output
@@ -110,6 +111,9 @@ main(int argc, char* argv[])
                usage();
            }
            break;
+       case 'F':               // set Font path
+           fmt.setFontPath(optarg);
+           break;
        case 'G':               // gaudy mode
            fmt.setGaudyHeaders(TRUE);
            break;