1 | #!/bin/sh |
---|
2 | # |
---|
3 | # Copyright (c) 1998-2000 |
---|
4 | # Sergey A. Babkin. All rights reserved. |
---|
5 | # |
---|
6 | # Redistribution and use in source and binary forms, with or without |
---|
7 | # modification, are permitted provided that the following conditions |
---|
8 | # are met: |
---|
9 | # 1. Redistributions of source code must retain the above copyright |
---|
10 | # notice, this list of conditions and the following disclaimer. |
---|
11 | # 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | # notice, this list of conditions and the following disclaimer in the |
---|
13 | # documentation and/or other materials provided with the distribution. |
---|
14 | # |
---|
15 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
---|
16 | # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
---|
17 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
18 | # |
---|
19 | # Sergey A. Babkin (sab123@hotmail.com, babkin@bellatlantic.net) |
---|
20 | # |
---|
21 | |
---|
22 | # Use : convert [cfgfile] |
---|
23 | |
---|
24 | # Convert TTF fonts from source directory to Type1 fonts in the destination |
---|
25 | # directory, converted to the specified encodings. Also generate the |
---|
26 | # fonts.scale, fonts.dir and fonts.alias files in the destination directory. |
---|
27 | |
---|
28 | # clean some variables so that they won't be inherited from environment |
---|
29 | |
---|
30 | ENCDIR= |
---|
31 | MAPDIR= |
---|
32 | |
---|
33 | # path to the configuration file |
---|
34 | |
---|
35 | if [ $# -eq 1 ] |
---|
36 | then |
---|
37 | CFGFILE=$1 |
---|
38 | else |
---|
39 | CFGFILE=`pwd`/convert.cfg |
---|
40 | fi |
---|
41 | |
---|
42 | # these setting would be edited during installation |
---|
43 | |
---|
44 | TTF2PT1_BINDIR= |
---|
45 | TTF2PT1_LIBXDIR= |
---|
46 | TTF2PT1_SHAREDIR= |
---|
47 | |
---|
48 | [ -z "$TTF2PT1_BINDIR" ] && { |
---|
49 | TTF2PT1_BINDIR=`pwd`/.. |
---|
50 | } |
---|
51 | [ -z "$TTF2PT1_LIBXDIR" ] && { |
---|
52 | TTF2PT1_LIBXDIR=`pwd`/.. |
---|
53 | } |
---|
54 | [ -z "$TTF2PT1_SHAREDIR" ] && { |
---|
55 | TTF2PT1_SHAREDIR=`pwd`/.. |
---|
56 | } |
---|
57 | |
---|
58 | # directory from where we are started |
---|
59 | |
---|
60 | RUNDIR=`pwd` |
---|
61 | |
---|
62 | # paths to various utilities |
---|
63 | |
---|
64 | T1ASM=$TTF2PT1_LIBXDIR/t1asm |
---|
65 | [ -f $T1ASM -a -x $T1ASM ] || { |
---|
66 | # if it's not in libxdir, use whatever t1asm the system provides |
---|
67 | T1ASM=t1asm |
---|
68 | } |
---|
69 | TTF2PT1=$TTF2PT1_BINDIR/ttf2pt1 |
---|
70 | TRANS=$TTF2PT1_SHAREDIR/scripts/trans |
---|
71 | T1FDIR=$TTF2PT1_SHAREDIR/scripts/t1fdir |
---|
72 | FORCEISO=$TTF2PT1_SHAREDIR/scripts/forceiso |
---|
73 | X2GS=$TTF2PT1_SHAREDIR/scripts/x2gs |
---|
74 | SUFFIX="pfa" |
---|
75 | |
---|
76 | MYSELF=convert |
---|
77 | |
---|
78 | # include the configuration |
---|
79 | |
---|
80 | if [ -r $CFGFILE ] |
---|
81 | then { |
---|
82 | . $CFGFILE |
---|
83 | } else { |
---|
84 | echo " |
---|
85 | Can't find the configuration file |
---|
86 | $CFGFILE |
---|
87 | Please look at the sample file convert.cfg.sample, |
---|
88 | copy it to convert.cfg and modify for |
---|
89 | you actual configuration." >&2 |
---|
90 | exit 1 |
---|
91 | } fi |
---|
92 | |
---|
93 | # path to the directory with descriptions of encodings |
---|
94 | [ -z "$ENCDIR" ] && { |
---|
95 | ENCDIR=$TTF2PT1_SHAREDIR/encodings |
---|
96 | } |
---|
97 | |
---|
98 | # directory with the external Unicode maps |
---|
99 | [ -z "$MAPDIR" ] && { |
---|
100 | MAPDIR=$TTF2PT1_SHAREDIR/maps |
---|
101 | } |
---|
102 | |
---|
103 | LOG=$DSTDIR/convert.log |
---|
104 | |
---|
105 | # configure the ttf2pt1 options from our options |
---|
106 | |
---|
107 | # artefact of backwards-compatibility with .cfg |
---|
108 | [ -z "$CORRECTWIDTH" -a YES != "$DONTCORRECTWIDTH" ] && { |
---|
109 | TTF2PT1="$TTF2PT1 -OW" |
---|
110 | } |
---|
111 | [ YES = "$CORRECTWIDTH" ] && { |
---|
112 | TTF2PT1="$TTF2PT1 -OW" |
---|
113 | } |
---|
114 | |
---|
115 | [ YES != "$HINTSUBST" ] && { |
---|
116 | TTF2PT1="$TTF2PT1 -Ou" # meaning changed past 3.22 |
---|
117 | } |
---|
118 | |
---|
119 | [ YES = "$ALLGLYPHS" -a YES = "$ENFORCEISO" ] && { |
---|
120 | echo "$MYSELF: options ALLGLYPHS and ENFORCEISO are mutually exclusive" >&2 |
---|
121 | exit 1 |
---|
122 | } |
---|
123 | |
---|
124 | [ YES = "$ALLGLYPHS" ] && { |
---|
125 | TTF2PT1="$TTF2PT1 -a" |
---|
126 | } |
---|
127 | |
---|
128 | [ YES = "$GENUID" ] && { |
---|
129 | TTF2PT1="$TTF2PT1 -uA" |
---|
130 | } |
---|
131 | |
---|
132 | [ YES != "$ENFORCEISO" ] && { |
---|
133 | FORCEISO=cat |
---|
134 | } |
---|
135 | |
---|
136 | [ YES = "$CREATEPFB" ] && { |
---|
137 | T1ASM="$T1ASM -b" |
---|
138 | SUFFIX="pfb" |
---|
139 | } |
---|
140 | |
---|
141 | # parse the information about the source files |
---|
142 | |
---|
143 | eval "`echo \"$SRCDIRS\" | awk ' |
---|
144 | BEGIN { n=0; } |
---|
145 | /^ *$/ { next; } |
---|
146 | { |
---|
147 | if(n>9) { |
---|
148 | printf(\"echo \\\"Only 9 encodings are supported at once!\\\" >&2\n\"); |
---|
149 | printf(\"exit 1\\n\"); |
---|
150 | } else { |
---|
151 | printf(\"SRCDIR%d=%s\n\",n,$1); |
---|
152 | printf(\"SRCLANG%d=%s\n\",n,$2); |
---|
153 | printf(\"SRCENC%d=%s\n\",n,$3); |
---|
154 | printf(\"SRCMAP%d=%s\n\",n,$4); |
---|
155 | n++; |
---|
156 | } |
---|
157 | }'`" |
---|
158 | |
---|
159 | # check whether we have the directories |
---|
160 | |
---|
161 | mkdir $DSTDIR 2>/dev/null >/dev/null |
---|
162 | [ -d $DSTDIR -a -r $DSTDIR -a -w $DSTDIR -a -x $DSTDIR ] || { |
---|
163 | echo "$MYSELF: can't access the directory $DSTDIR" >&2 |
---|
164 | exit 1 |
---|
165 | } |
---|
166 | |
---|
167 | # go to our destination directory |
---|
168 | |
---|
169 | cd $DSTDIR || { |
---|
170 | echo "$MYSELF: can't chdir to $DSTDIR" >&2 |
---|
171 | exit 1 |
---|
172 | } |
---|
173 | |
---|
174 | rm -f ./* 2>/dev/null |
---|
175 | >$LOG |
---|
176 | |
---|
177 | for dirno in 0 1 2 3 4 5 6 7 8 9 |
---|
178 | do { |
---|
179 | |
---|
180 | SRCDIR=`eval "echo \\\$SRCDIR$dirno"` |
---|
181 | SRCLANG=`eval "echo \\\$SRCLANG$dirno"` |
---|
182 | SRCENC=`eval "echo \\\$SRCENC$dirno"` |
---|
183 | SRCMAP=`eval "echo \\\$SRCMAP$dirno"` |
---|
184 | DSTENC=`eval "echo \\\$DSTENC$SRCLANG"` |
---|
185 | |
---|
186 | echo $SRCDIR |
---|
187 | echo $SRCENC |
---|
188 | |
---|
189 | [ -z "$SRCDIR" ] && break; |
---|
190 | |
---|
191 | [ "`ls $SRCDIR/*.[tT][tT][fF] 2>/dev/null |wc -l`" -gt 0 ] || { |
---|
192 | echo "$MYSELF: no TTF files in $SRCDIR" >&2 |
---|
193 | exit 1 |
---|
194 | } |
---|
195 | |
---|
196 | # check whether we have the encoding tables |
---|
197 | |
---|
198 | [ -n "$SRCENC" ] || { |
---|
199 | echo "$MYSELF: you must specify some source encoding" >&2 |
---|
200 | exit 1 |
---|
201 | } |
---|
202 | |
---|
203 | [ unknown = "$SRCLANG" -o -n "$DSTENC" ] || { |
---|
204 | echo "$MYSELF: you must specify some destination encodings" >&2 |
---|
205 | exit 1 |
---|
206 | } |
---|
207 | |
---|
208 | # handle aliases of the destination encodings |
---|
209 | |
---|
210 | XDSTENC= |
---|
211 | DSTALIAS= |
---|
212 | |
---|
213 | [ -r $ENCDIR/$SRCLANG/encodings.alias ] && { |
---|
214 | for i in $DSTENC |
---|
215 | do { |
---|
216 | TO=`awk '$1=="'$i'" { print $2; }' <$ENCDIR/$SRCLANG/encodings.alias` |
---|
217 | if [ -n "$TO" ] |
---|
218 | then { |
---|
219 | [ -f $ENCDIR/$SRCLANG/$i.tbl -a -r $ENCDIR/$SRCLANG/$i.tbl ] && { |
---|
220 | echo "WARNING: $SRCLANG encoding $i found as both table and alias" >&2 |
---|
221 | echo "WARNING: The alias takes precedence" >&2 |
---|
222 | } |
---|
223 | DSTALIAS="$TO $i |
---|
224 | $DSTALIAS" |
---|
225 | XDSTENC="$TO |
---|
226 | $XDSTENC" |
---|
227 | } else { |
---|
228 | XDSTENC="$i |
---|
229 | $XDSTENC" |
---|
230 | } fi |
---|
231 | } done |
---|
232 | DSTENC=`echo "$XDSTENC" | sort -u | tr ' |
---|
233 | ' ' '` |
---|
234 | } |
---|
235 | |
---|
236 | [ unknown != "$SRCLANG" ] && { |
---|
237 | for i in $SRCENC $DSTENC |
---|
238 | do { |
---|
239 | [ -f $ENCDIR/$SRCLANG/$i.tbl -a -r $ENCDIR/$SRCLANG/$i.tbl ] || { |
---|
240 | echo "$MYSELF: can't read $ENCDIR/$SRCLANG/$i.tbl" >&2 |
---|
241 | exit 1 |
---|
242 | } |
---|
243 | } done |
---|
244 | } |
---|
245 | |
---|
246 | # OK convert the files |
---|
247 | |
---|
248 | for file in $SRCDIR/*.[tT][tT][fF] |
---|
249 | do { |
---|
250 | name=`echo $file | tr A-Z a-z` |
---|
251 | name=`basename $name .ttf` |
---|
252 | |
---|
253 | echo "Converting $name" |
---|
254 | |
---|
255 | # generate the assembler code |
---|
256 | |
---|
257 | echo "******* $name -> t1a ************" >>$LOG |
---|
258 | |
---|
259 | if [ -n "$SRCMAP" ] |
---|
260 | then { |
---|
261 | $TTF2PT1 -L $MAPDIR/$SRCMAP $file ./$name.$SRCENC 2>>$LOG |
---|
262 | } else { |
---|
263 | $TTF2PT1 -l $SRCLANG $file ./$name.$SRCENC 2>>$LOG |
---|
264 | } fi |
---|
265 | |
---|
266 | [ -s ./$name.$SRCENC.t1a ] || { |
---|
267 | echo "$MYSELF: can't generate Type1 assembler code for $name" >&2 |
---|
268 | continue; |
---|
269 | } |
---|
270 | |
---|
271 | [ -s ./$name.$SRCENC.afm ] || { |
---|
272 | echo "$MYSELF: can't generate AFM metrics file for $name" >&2 |
---|
273 | continue; |
---|
274 | } |
---|
275 | |
---|
276 | mv ./$name.$SRCENC.afm ./$name.$SRCENC.xafm |
---|
277 | |
---|
278 | psname=`$T1FDIR -g $FOUNDRY " " -f ./$name.$SRCENC.t1a \ |
---|
279 | | awk '{print substr($1,2);}'` |
---|
280 | |
---|
281 | # now for each destination encoding generate a .pfa/b file |
---|
282 | # and record for fonts.scale |
---|
283 | |
---|
284 | if [ unknown != "$SRCLANG" ] |
---|
285 | then { |
---|
286 | for enc in $DSTENC |
---|
287 | do { |
---|
288 | echo "******* $name -> $enc ************" >>$LOG |
---|
289 | |
---|
290 | sed 's|^\/FontName.*$|/FontName /'$psname$enc' def|' <./$name.$SRCENC.t1a \ |
---|
291 | | $TRANS $ENCDIR/$SRCLANG/$SRCENC.tbl $ENCDIR/$SRCLANG/$enc.tbl \ |
---|
292 | | $FORCEISO | $T1ASM >./$name.$enc.$SUFFIX |
---|
293 | [ -s ./$name.$enc.$SUFFIX ] || { |
---|
294 | echo "$MYSELF: can't convert/assemble Type1 file for $name.$enc" >&2 |
---|
295 | continue; |
---|
296 | } |
---|
297 | |
---|
298 | sed 's|^FontName.*$|FontName '$psname$enc'|' <./$name.$SRCENC.xafm \ |
---|
299 | | $TRANS $ENCDIR/$SRCLANG/$SRCENC.tbl $ENCDIR/$SRCLANG/$enc.tbl \ |
---|
300 | | uniq | $FORCEISO >./$name.$enc.afm |
---|
301 | [ -s ./$name.$enc.afm ] || { |
---|
302 | echo "$MYSELF: can't convert AFM file for $name.$enc" >&2 |
---|
303 | } |
---|
304 | |
---|
305 | aliases=`echo "$DSTALIAS" | grep "^$enc" | cut -d\ -f2` |
---|
306 | echo "******* aliases: $aliases" >>$LOG |
---|
307 | |
---|
308 | $T1FDIR -d fonts.ttf fonts.alias $FOUNDRY $enc $aliases -f ./$name.$enc.$SUFFIX |
---|
309 | echo "/$psname$enc ($name.$enc.$SUFFIX) ;" >>Fontmap.ttf |
---|
310 | } done |
---|
311 | } else { |
---|
312 | enc="$SRCENC" |
---|
313 | echo "******* $name -> $enc ************" >>$LOG |
---|
314 | |
---|
315 | sed 's|^\/FontName.*$|/FontName /'$psname$enc' def|' <./$name.$SRCENC.t1a \ |
---|
316 | | $FORCEISO | $T1ASM >./$name.$enc.$SUFFIX |
---|
317 | [ -s ./$name.$enc.$SUFFIX ] || { |
---|
318 | echo "$MYSELF: can't convert/assemble Type1 file for $name.$enc" >&2 |
---|
319 | continue; |
---|
320 | } |
---|
321 | |
---|
322 | sed 's|^FontName.*$|FontName '$psname$enc'|' <./$name.$SRCENC.xafm \ |
---|
323 | | uniq | $FORCEISO >./$name.$enc.afm |
---|
324 | [ -s ./$name.$enc.afm ] || { |
---|
325 | echo "$MYSELF: can't convert AFM file for $name.$enc" >&2 |
---|
326 | } |
---|
327 | |
---|
328 | $T1FDIR -d fonts.ttf fonts.alias $FOUNDRY $enc -f ./$name.$enc.$SUFFIX |
---|
329 | echo "/$psname$enc ($name.$enc.$SUFFIX) ;" >>Fontmap.ttf |
---|
330 | } fi |
---|
331 | |
---|
332 | [ YES = "$REMOVET1A" ] && { |
---|
333 | rm -f ./$name.$SRCENC.t1a |
---|
334 | rm -f ./$name.$SRCENC.xafm |
---|
335 | } |
---|
336 | |
---|
337 | } done |
---|
338 | } done |
---|
339 | |
---|
340 | wc -l <fonts.ttf >fonts.scale |
---|
341 | cat fonts.ttf >>fonts.scale |
---|
342 | mkfontdir |
---|
343 | |
---|
344 | [ YES = "$GENUID" ] && { |
---|
345 | echo "Checking for duplicate UniqueIDs..." |
---|
346 | for id in `find . -name "*.$SUFFIX" -exec grep UniqueID {} \; \ |
---|
347 | | cut -d" " -f2 | sort | uniq -d` |
---|
348 | do { |
---|
349 | echo "Warning: duplicate UniqueID $id in files:" | tee -a $LOG |
---|
350 | find . -name "*.$SUFFIX" -exec grep -l "UniqueID $id " {} \; 2>&1 | tee -a $LOG |
---|
351 | } done |
---|
352 | } |
---|
353 | |
---|
354 | [ -n "$GSDIR" ] || { |
---|
355 | echo "$MYSELF: The Ghostscript base directory is not specified.\n" >&2 |
---|
356 | echo "$MYSELF: Installation of the Ghostscript fonts is deferred.\n" >&2 |
---|
357 | echo "$MYSELF: You can do it later by running x2gs\n" >&2 |
---|
358 | exit 0 |
---|
359 | } |
---|
360 | |
---|
361 | echo "Installing the Ghostscript fonts" |
---|
362 | cd $RUNDIR |
---|
363 | $X2GS $CFGFILE || { |
---|
364 | echo "$MYSELF: Installation of the Ghostscript fonts has failed.\n" >&2 |
---|
365 | echo "$MYSELF: You can correct the problem and run x2gs to repeat\n" >&2 |
---|
366 | exit 0 |
---|
367 | } |
---|