summaryrefslogtreecommitdiff
path: root/afm/make_fonts_map.sh
blob: 4526d12c45458cbf00d3b37b13ad087e59d0d7ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#! /bin/sh
#
# This file is part of a2ps.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#

#
# This shell script is ment to ease the writing of the fonts.map
# file.  Once a2ps is installed, just run this script.
#

# Exit whenever there is a problem
set -e

/bin/rm -rf fonts.map.new fonts.map.tmp
LC_ALL=C
export LC_ALL

files=
A2PS=${A2PS:-a2ps}

# The width of the first columns
many_spaces="                              "
many_dots=`echo "$many_spaces" | sed -e 's/ /./g'`

# First we want to get all the AFM files
echo "Looking for the afm files read by ${A2PS}..." 1>&2
for directory in `$A2PS --list-options | grep '^	/'`
do
  echo "  $directory..." 1>&2
  newfiles=`echo $directory/*.afm 2> /dev/null`
  case "$newfiles" in
    */\*.afm) # nothing found here
       ;;
    *) # echo "     $newfiles" | sed -e "s!$directory/!!g" 1>&2
       files=`echo $newfiles $files`
       ;;
  esac
done

# Extract there names
echo "Extracting font names..." 1>&2
for file in $files
do
  # Extract the font name.
  name=`sed -n -e '/^FontName/{
s/FontName[ ]*\([-a-zA-Z]*\).*/\1/p
q
}' $file`
  shortname=`basename $file | sed -e 's/\.[^\.]*$//g'`
  if test x$name = x; then :; else
    # This is probably not a correct AFM file.
    # (For instance Ogonkify's pseudo AFMs that define the encodings)
    # Forget it.
    col1=`echo "$name$many_spaces" | sed -e 's/^\('$many_dots'\).*$/\1/g'`
    # Make sure the name has not been cut
    case "$col1" in
      $name*) ;;
      *) echo "A name has been cut ($name -> $col1)." 1>&2
	 exit 1 ;;
    esac
    col2="$shortname"
    echo "$col1$col2" >> fonts.map.new
  fi
done

# Sort them by name, and keep a unique file for each font
echo "Sorting entries..." 1>&2
sort -u -t' ' +0 -1 fonts.map.new > fonts.map.tmp

echo "Finishing." 1>&2
cat > fonts.map.new <<EOF
# -*- ksh -*-
#
# This file is part of a2ps.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#

#
# This file defines the rules used by a2ps to recognize the file
# name of a font given the font name.
#
# The format of each line is:
#
# <font name> <font file key>
#	In which case whenever <font name> is requested, a2ps uses the
#	files <font file key>.afm to get the font information, and the
#	files <font file key>.pfa or pfb when it needs to download it
#	to the printer.
#
# *** <path>
#	In which case a encoding.map is included at this point.
#	This may be the case if you define a personal extension
#	of the system's fonts.map
#
# A shell script has been provided with a2ps, and should be able to
# write this file for you.
# Just hit: \`make_fonts_map.sh'
#
EOF

cat fonts.map.tmp >> fonts.map.new
chmod 644 fonts.map.new
rm fonts.map.tmp

# Make a message for the user
cat <<EOF
*******************************************************************
* A new fonts.map has been created: \`fonts.map.new'               *
* Please check that it is correct, and rename it as \`fonts.map':  *
*     mv fonts.map.new fonts.map                                  *
*******************************************************************
EOF

# Local Variables:
# mode:ksh
# sh-indentation:2
# End: