View | Details | Raw Unified | Return to bug 57180
Collapse All | Expand All

(-)ttfm/Makefile (-14 / +6 lines)
Lines 6-25 Link Here
6
#
6
#
7
7
8
PORTNAME=	ttfm
8
PORTNAME=	ttfm
9
PORTVERSION=	0.9.3
9
PORTVERSION=	0.9.4
10
PORTREVISION=	3
11
CATEGORIES=	chinese print
10
CATEGORIES=	chinese print
12
MASTER_SITES=	ftp://freebsd.sinica.edu.tw/pub/keith/ttfm/
11
MASTER_SITES=	ftp://freebsd.sinica.edu.tw/pub/statue/ttfm/
13
12
14
MAINTAINER=	keith@FreeBSD.org
13
MAINTAINER=	statue@freebsd.sinica.edu.tw
15
COMMENT=	A Big5/GB enhanced TrueType Font Manager
14
COMMENT=	A Big5/GB enhanced TrueType Font Manager
16
15
17
.include <bsd.port.pre.mk>
18
.if ${XFREE86_VERSION} == 4
19
RUN_DEPENDS=	mkfontdir:${PORTSDIR}/x11/XFree86-4-clients
16
RUN_DEPENDS=	mkfontdir:${PORTSDIR}/x11/XFree86-4-clients
20
.endif
17
LIB_DEPENDS=	freetype.9:${PORTSDIR}/print/freetype2
21
22
USE_FREETYPE=	yes
23
18
24
FONTSDIR=	${PREFIX}/share/fonts/TrueType/
19
FONTSDIR=	${PREFIX}/share/fonts/TrueType/
25
MODULESDIR=	${PREFIX}/share/ttfm/
20
MODULESDIR=	${PREFIX}/share/ttfm/
Lines 33-46 Link Here
33
.endfor
28
.endfor
34
	@${INSTALL_MAN} ${WRKSRC}/ttfm.sh.1 ${PREFIX}/man/man1
29
	@${INSTALL_MAN} ${WRKSRC}/ttfm.sh.1 ${PREFIX}/man/man1
35
	@${MKDIR} ${MODULESDIR}
30
	@${MKDIR} ${MODULESDIR}
36
.for module in abiword.ttfm gscjk.ttfm xfreetype.ttfm xttfm.ttfm
31
.for module in gscjk.ttfm xttfm.ttfm
37
	@${INSTALL_SCRIPT} ${WRKSRC}/modules/${module} ${MODULESDIR}
32
	@${INSTALL_SCRIPT} ${WRKSRC}/modules/${module} ${MODULESDIR}
38
.endfor
33
.endfor
39
.for module in chitex.ttfm ghostscript6.ttfm ttf2pk.ttfm xttfm-tcl.ttfm
40
	@${INSTALL_SCRIPT} ${WRKSRC}/modules/${module} ${MODULESDIR}/${module}.nop
41
.endfor
42
	@${MKDIR} ${FONTSDIR}
34
	@${MKDIR} ${FONTSDIR}
43
35
44
MAN1=	ttfm.sh.1
36
MAN1=	ttfm.sh.1
45
37
46
.include <bsd.port.post.mk>
38
.include <bsd.port.mk>
(-)ttfm/distinfo (-1 / +1 lines)
Line 1 Link Here
1
MD5 (ttfm-0.9.3.tar.gz) = fb9fb633adafa3523b5d4c222c848417
1
MD5 (ttfm-0.9.4.tar.gz) = 53c67a9d7ef5379ee7ddaec033ca5244
(-)ttfm/files/patch-Makefile (-12 lines)
Lines 1-12 Link Here
1
2
$FreeBSD: ports/chinese/ttfm/files/patch-Makefile,v 1.1 2002/03/14 11:16:37 sobomax Exp $
3
4
--- Makefile	2002/03/14 07:35:10	1.1
5
+++ Makefile	2002/03/14 07:35:23
6
@@ -1,5 +1,5 @@
7
 FREETYPE_BASE=/usr/local
8
-FREETYPE_INCL=$(FREETYPE_BASE)/include
9
+FREETYPE_INCL=$(FREETYPE_BASE)/include/freetype1
10
 FREETYPE_LIB=$(FREETYPE_BASE)/lib
11
 prefix=/usr
12
 
(-)ttfm/files/patch-modules::abiword.ttfm (-681 lines)
Lines 1-681 Link Here
1
--- modules/abiword.ttfm.orig	Sun Jun  2 14:22:27 2002
2
+++ modules/abiword.ttfm	Sun Jun  2 14:22:57 2002
3
@@ -1,82 +1,56 @@
4
 #!/bin/sh
5
-#
6
-# TTFM's module for AbiWord 0.7.12.
7
-#
8
-# This script is distributed under the revised BSD license.
9
-#
10
-# For any problem reports or suggestions, please contact
11
-# Jing-Tang Keith Jang <keith@FreeBSD.org>.
12
-#
13
-
14
-#
15
-# AbiWord searches the following subdirectories under fonts/ for fonts.dir:
16
-# $country, $country-$region, $encoding, $country-$region.$encoding.  For
17
-# example, fonts/{zh, zh-TW, Big5, zh-TW.Big5} are all valid directories.
18
-# However, this module will only generate fonts/$encoding/fonts.dir for the
19
-# sake of simplicity.
20
-#
21
-# Here are the sample lines of a font in AbiWord's fonts.dir:
22
-#
23
-# Kai-Medium, -default-kai-medium-r-normal--0-0-0-0-c-0-big5-0, 880, 120, 1000
24
-# Kai-Medium, -default-kai-bold-r-normal--0-0-0-0-c-0-big5-0, 880, 120, 1000
25
-# Kai-Medium, -default-kai-medium-i-normal--0-0-0-0-c-0-big5-0, 880, 120, 1000
26
-# Kai-Medium, -default-kai-bold-i-normal--0-0-0-0-c-0-big5-0, 880, 120, 1000
27
-#
28
-# AbiWord uses the first field for printing, second field for displaying.
29
-# The last three fields are font's ascent, descent, and width, used when
30
-# printing.
31
-#
32
-# Because AbiWord follows normal X convention, there's no need that the font
33
-# must be TTF.  But we'll only accept TTF here, since it's better in scaling.
34
-# CID fonts may be supported in the future, depending on the demanding.
35
-#
36
-
37
-# Name & version
38
-export NAME; NAME="AbiWord Font Manager"
39
-export VERSION; VERSION=0.9.3
40
+#/*
41
+# * Copyrighy (c) 2001 CLE Project. All rights reserved.
42
+# * Copyright (c) 2001 Chung-Yen Chang. All rights reserved.
43
+# *    with Big5-HKSCS font support added by Anthony Fok
44
+# *    thanks to ThizLinux Laboratory Ltd., Thiz Technology Group
45
+# *
46
+# * Redistribution and use in source and binary forms, with or without
47
+# * modification, are permitted provided that the following conditions
48
+# * are met:
49
+# * 1. Redistributions of source code must retain the above copyright
50
+# *    notice, this list of conditions and the following disclaimer.
51
+# * 2. Redistributions in binary form must reproduce the above copyright
52
+# *    notice, this list of conditions and the following disclaimer in the
53
+# *    documentation and/or other materials provided with the distribution.
54
+# * 3. All advertising materials mentioning features or use of this software
55
+# *    must display the following acknowledgement:
56
+# *      This product includes software developed by
57
+# *      Chih-Wei Huang and contributors for CLE Project
58
+# * 4. Neither the name of the Author nor the names of contributors
59
+# *    may be used to endorse or promote products derived from this software
60
+# *    without specific prior written permission.
61
+# *
62
+# *
63
+# * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
64
+# * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65
+# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66
+# * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
67
+# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68
+# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69
+# * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70
+# * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71
+# * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72
+# * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73
+# * SUCH DAMAGE.
74
+# */
75
 
76
 # Global constants
77
+export TWABIFONTPATH; TWABIFONTPATH="/usr/X11R6/share/AbiSuite/fonts/zh-TW"
78
+export CNABIFONTPATH; CNABIFONTPATH="/usr/X11R6/share/AbiSuite/fonts/zh-CN"
79
+export HKABIFONTPATH; HKABIFONTPATH="/usr/X11R6/share/AbiSuite/fonts/zh-HK"
80
+export TEMPFILE; TEMPFILE="`mktemp /tmp/ttfm.tmpXXXXXX`"
81
+export DEFAULTPATH; DEFAULTPATH="/usr/local/share/fonts/TrueType"
82
+
83
+for i in $TWABIFONTPATH $CNABIFONTPATH $CNABIFONTPATH.GBK $HKABIFONTPATH; do
84
+    test -d $i || mkdir $i
85
+    test -f $i/fonts.dir || mkfontdir $i
86
+    touch $i/.already-in-fp
87
+done
88
 
89
-export PREFIX; PREFIX=/usr/local
90
-export X11BASE; X11BASE=/usr/X11R6
91
-export PATH; PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PREFIX/bin:$PREFIX/sbin:$X11BASE/bin
92
-export TEMPFILE; TEMPFILE="`mktemp /tmp/ttfm.tmpXXX`"
93
-export ABIFontPath; ABIFontPath=$PREFIX/AbiSuite/fonts
94
-export DefaultFontPath; DefaultFontPath=$PREFIX/share/fonts/TrueType
95
-export TTFM; TTFM=$PREFIX/bin/ttfm.sh
96
-export XTTFFONTPATH; XTTFFONTPATH="$X11BASE/lib/X11/fonts/TrueType"
97
-export GSMODULE; GSMODULE="ghostscript6"
98
-export XMODULE; XMODULE="xttfm"
99
-export TTFINFOPATH; TTFINFOPATH="$PREFIX/bin/ttfinfo"
100
-export DEFAULTMING_NAME; DEFAULTMING_NAME="default_ming"
101
-export DEFAULTKAI_NAME; DEFAULTKAI_NAME="default_kai"
102
-export PRINTPARAM; PRINTPARAM="880, 120, 1000"
103
-
104
-
105
-#
106
-# Encoding/Directory table, used to convert the XLFD of a font to AbiWord's
107
-# charset directories, and vice versa.  Used by add_fonts().
108
-#
109
-export ed_table; ed_table=\
110
-"Big5,big5-0\n
111
-GB2312,gb2312.1980-0\n
112
-KSC5601,ksc5601.1987-0\n
113
-JISX0208,jisx0208.1983-0\n
114
-JISX0212,jisx0212.1990-0\n"
115
-
116
-
117
-#
118
-# Encoding/Postscript name table, used to convert a font's XLFD encoding
119
-# to its frequently used Postscript name.  I'm not sure if the entries
120
-# are correct, except Big5.
121
-#
122
-export ep_table; ep_table=\
123
-"big5-0,B5pc-H\n
124
-gb2312.1980-0,GBpc-EUC-H\n
125
-ksc5601.1987-0,KSCpc-EUC-H\n
126
-jisx0208.1983-0,EUC-H\n
127
-jisx0212.1990-0,Hojo-EUC-H\n"
128
-
129
+# Name & version
130
+export NAME; NAME="AbiWord 1.0.1 TrueType Font Manager"
131
+export VERSION; VERSION=1.0
132
 
133
 # Who am I?
134
 print_name()
135
@@ -84,7 +58,6 @@
136
     echo "$NAME $VERSION"
137
 }
138
 
139
-
140
 # Usage
141
 Usage()
142
 {
143
@@ -96,204 +69,275 @@
144
     echo "       --add <file>...    install ttf font"
145
     echo "       --remove <file>... remove ttf font from the system"
146
     echo "       --list             list all ttf fonts on the system"
147
-    echo "       --setdefault <file> "
148
-    echo "                          set default font to file"
149
-    echo "       --setdefault_kai <file> "
150
-    echo "                          set default \kai font to file"
151
-    echo "       --setdefault_ming <file> "
152
-    echo "                          set default \ming font to file"
153
     echo "       --help             show this info"
154
     echo
155
 }
156
 
157
 
158
-check_abiword()
159
-{
160
-	 if [ ! -d $ABIFontPath ]; then
161
-		  mkdir -p $ABIFontPath
162
-	 fi
163
-	 fontsdirlist=`find $ABIFontPath -name fonts.dir`
164
-}
165
-
166
-
167
-#
168
-# List all fonts installed under $AbiFontPath
169
-#
170
-# I'm not sure if font filenames should also be displayed, since the XLFD
171
-# may be provided from xfs.
172
-#
173
+# List all ttf fonts installed in $ABIFONTPATH
174
 list_fonts()
175
 {
176
-    if [ "X$fontsdirlist" = "X" ]; then
177
-        echo "No fonts installed."
178
+    if [ -f ${TWABIFONTPATH}/fonts.dir -o -f ${CNABIFONTPATH}/fonts.dir \
179
+	 -o -f ${HKABIFONTPATH}/fonts.dir ]; then
180
+        echo "Installed TTF fonts:"
181
+	if [ -f ${TWABIFONTPATH}/fonts.dir ]; then
182
+          awk -F, 'FNR>1 {print $1,$2}' ${TWABIFONTPATH}/fonts.dir
183
+	fi
184
+	if [ -f ${CNABIFONTPATH}/fonts.dir ]; then
185
+          awk -F, 'FNR>1 {print $1,$2}' ${CNABIFONTPATH}/fonts.dir
186
+	fi
187
+	if [ -f ${CNABIFONTPATH}.GBK/fonts.dir ]; then
188
+          awk -F, 'FNR>1 {print $1,$2}' ${CNABIFONTPATH}.GBK/fonts.dir
189
+	fi
190
+	if [ -f ${HKABIFONTPATH}/fonts.dir ]; then
191
+          awk -F, 'FNR>1 {print $1,$2}' ${HKABIFONTPATH}/fonts.dir
192
+	fi
193
+        echo
194
     else
195
-        for f in $fontsdirlist; do
196
-            echo "In `dirname $f`:"
197
-            sed -e '1d' $f |cut -d ',' -f 1 |sort |uniq
198
-				echo
199
-        done
200
+        echo "No TTF fonts installed!"
201
     fi
202
 }
203
 
204
+# Get ttfinfo
205
+get_ttfinfo()
206
+{
207
+    TTFINFO="/usr/local/bin/ttfinfo"
208
+    if [ "z$TTFINFO" = "z" ]; then
209
+        echo "ttfinfo not found, aborted!"
210
+        exit 3
211
+    fi
212
+    eval `$TTFINFO $1`
213
+}
214
 
215
-#
216
-# Remove ttf fonts.  It accepts PS or TTF arguments, eg.
217
-# remove_fonts DefaultMingB5-Regular(series), or
218
-# remove_fonts /usr/local/share/fonts/TrueType/bsmi00lp.ttf.
219
-#
220
-# We won't delete font files, since the AbiWord module solely
221
-# depends on other modules like xttfm or ghostscript6, font
222
-# files should be managed by them, not here.
223
-#
224
-remove_fonts()
225
+# Get Unicode fontmap
226
+get_unicode_fontmap()
227
 {
228
-    for f in $@; do
229
-		  case $f in
230
-		  *.[Tt][Tt][CcFf])
231
-				i=`basename $f`
232
-				psnamelist=`$TTFM --list $GSMODULE |grep $i |cut -d '(' -f 1`
233
-				if [ -z "$psnamelist" ]; then
234
-					 echo "$f is not installed"
235
-					 continue
236
-				else
237
-				for psname in $psnamelist; do
238
-					 for fontsdir in $fontsdirlist; do
239
-						  sed -e "/^$psname/d" $fontsdir > $TEMPFILE
240
-						  num=`cat $TEMPFILE |wc -l`
241
-						  num=`expr $num - 1`
242
-						  sed -e "1s/.*/$num/g" $TEMPFILE > $fontsdir
243
-					 done
244
-				done
245
-				fi
246
-		  ;;
247
-		  *)
248
-				for fontsdir in $fontsdirlist; do
249
-					 sed -e "/$f/d" $fontsdir > $TEMPFILE
250
-					 num=`cat $TEMPFILE |wc -l`
251
-					 num=`expr $num - 1`
252
-					 sed -e "1s/.*/$num/g" $TEMPFILE > $fontsdir
253
-				done
254
-		  ;;
255
-		  esac
256
+    j=1; n=0
257
+    while [ $j -le $TTFINFO_MAPNUM ]; do
258
+        eval "fontmap=\$TTFINFO_FONTMAP$j"
259
+        if (echo $fontmap | grep -q big5); then
260
+            eval "NAMEEXT$n=_big5; TBL$n=UBig5"; n=$(($n+1))
261
+        elif (echo $fontmap | grep -q gb); then
262
+            eval "NAMEEXT$n=_gb; TBL$n=UGB"; n=$(($n+1))
263
+        elif (echo $fontmap | grep -q jisx0208); then
264
+            eval "NAMEEXT$n=_jis; TBL$n=UJIS"; n=$(($n+1))
265
+        elif (echo $fontmap | grep -q ksc5601); then
266
+            eval "NAMEEXT$n=_ksc; TBL$n=UKS"; n=$(($n+1))
267
+        fi
268
+        j=$(($j+1))
269
+    done
270
+  # do not append ext if only one fontmap found
271
+    [ $n -eq 1 ] && NAMEEXT0=""
272
+
273
+    j=0
274
+    while [ $j -lt $n ]; do
275
+        eval "NAME$j=$font\$NAMEEXT$j"
276
+        j=$(($j+1))
277
     done
278
 }
279
 
280
 
281
-#
282
 # Add ttf fonts
283
-#
284
-# This script won't do the low-level work for both X Window or Ghostscript,
285
-# such as adding fonts.dir or ps font entries.  It just calls $TTFM with
286
-# appropriate modules.  All file handlings will be managed by those modules.
287
-#
288
 add_fonts()
289
 {
290
-	 for addfile in $@; do
291
-		  # Some sanity checking
292
-		  if [ ! -r "$addfile" ]; then
293
-				echo "$addfile does not exist, skipped."
294
-				continue
295
-		  fi
296
-		  if [ -z "`echo $addfile |grep -i -e ".*tt[cf]$"`" ]; then
297
-				echo "$addfile is not a TTF, skipped."
298
-				continue
299
-		  fi
300
-		  # Those modules will manage if fonts are already installed.
301
-		  $TTFM --add $XMODULE $addfile
302
-		  $TTFM --add $GSMODULE $addfile
303
-
304
-		  f="`basename "$addfile"`"
305
-		  xlfd="`$TTFM --list $XMODULE |grep $f |sed -e "/iso/d" -e "s/$f //g" |sort |uniq`"
306
-		  encoding=`echo $xlfd |cut -d '-' -f 14-15`
307
-		  subdir="`printf "$ed_table" |awk -F "," -v i=$encoding '{dir[$2]=$1} END {print dir[i]}'`"
308
-		  cidname="`$TTFM --list $GSMODULE |grep $f |cut -d '(' -f 1 |sed -e "/^Default/d"`"
309
-		  psname="$cidname"-"`printf "$ep_table" |awk -F "," -v i=$encoding '{ps[$1]=$2} END {print ps[i]}'`"
310
-
311
-		  if [ ! -d $ABIFontPath/$subdir ]; then
312
-				mkdir -p $ABIFontPath/$subdir
313
-		  fi
314
-		  touch $ABIFontPath/$subdir/.already-in-fp
315
-		  if [ ! -r $ABIFontPath/$subdir/fonts.dir ]; then
316
-				echo 0 > $ABIFontPath/$subdir/fonts.dir
317
-		  fi
318
-		  num=`head -1 $ABIFontPath/$subdir/fonts.dir`
319
-		  cp $ABIFontPath/$subdir/fonts.dir $TEMPFILE
320
-		  # There may be spaces in $xlfd, quote it.
321
-		  abifont="$psname, $xlfd, $PRINTPARAM"
322
-		  echo $abifont >> $TEMPFILE
323
-		  echo $abifont |sed -e "s/-medium-r-/-bold-r-/g" >> $TEMPFILE
324
-		  echo $abifont |sed -e "s/-medium-r-/-medium-i-/g" >> $TEMPFILE
325
-		  echo $abifont |sed -e "s/-medium-r-/-bold-i-/g" >> $TEMPFILE
326
-		  num=`cat $TEMPFILE |wc -l`
327
-		  num=`expr $num - 1`
328
-		  sed -e "1s/.*/$num/g" $TEMPFILE > $ABIFontPath/$subdir/fonts.dir
329
+    error=0
330
+    for f in "$@"; do
331
+        if [ ! -e "$f" ]; then
332
+            if [ -e "$DEFAULTPATH/$f" ]; then
333
+                f="$DEFAULTPATH/$f"
334
+            else
335
+                echo "Cannot find font $f, ignored!"
336
+                error=$(($error+1))
337
+                continue
338
+            fi
339
+        fi
340
+
341
+        fontfile=`basename $f`
342
+        eval `echo $fontfile | awk -F. '{ printf "font=%s;ext=%s",\$1,\$2 }'`
343
+
344
+        get_ttfinfo $f
345
+        i=1
346
+        while [ $i -le $TTFINFO_MAPNUM ]; do
347
+          eval I1=\$TTFINFO_FONTMAP${i}
348
+	  I2=`echo $I1|sed -e s/medium-r/bold-r/`
349
+	  I3=`echo $I1|sed -e s/medium-r/medium-i/`
350
+	  I4=`echo $I1|sed -e s/medium-r/bold-i/`
351
+	  J1=`echo $I1|cut -c2-`
352
+	  J2=`echo $I2|cut -c2-`
353
+	  J3=`echo $I3|cut -c2-`
354
+	  J4=`echo $I4|cut -c2-`
355
+	  MYENC=`echo $I1 | awk -F- '{print $14}'`
356
+	  case $MYENC in
357
+	    big5)
358
+	      # zh-TW
359
+              grep -v "$J1" $TWABIFONTPATH/fonts.dir |grep -v "$J2" |grep -v "$J3" |grep -v "$J4" |sed -e "1d" > $TEMPFILE.1
360
+	      echo "${TTFINFO_FONT_PSNAME}-ETen-B5-H, $I1, 880, 120, 1000" > $TEMPFILE.2
361
+	      echo "${TTFINFO_FONT_PSNAME}-Bold-ETen-B5-H, $I2, 880, 120, 1000" >> $TEMPFILE.2
362
+	      echo "${TTFINFO_FONT_PSNAME}-Italic-ETen-B5-H, $I3, 880, 120, 1000" >> $TEMPFILE.2
363
+	      echo "${TTFINFO_FONT_PSNAME}-BoldItalic-ETen-B5-H, $I4, 880, 120, 1000" >> $TEMPFILE.2
364
+	      if [ "$TTFINFO_FONT_PSNAME" = "ShanHeiSun-Light" ]; then
365
+		cat $TEMPFILE.2 $TEMPFILE.1 > $TEMPFILE
366
+	      else
367
+		cat $TEMPFILE.1 $TEMPFILE.2 > $TEMPFILE
368
+	      fi
369
+	      LINE=`wc -l < $TEMPFILE`
370
+              echo $LINE > $TWABIFONTPATH/fonts.dir
371
+	      cat $TEMPFILE >> $TWABIFONTPATH/fonts.dir
372
+	      # zh-HK
373
+	      I1=`echo $I1 | sed -e 's/-big5-0$/-big5hkscs-0/'`
374
+	      I2=`echo $I2 | sed -e 's/-big5-0$/-big5hkscs-0/'`
375
+	      I3=`echo $I3 | sed -e 's/-big5-0$/-big5hkscs-0/'`
376
+	      I4=`echo $I4 | sed -e 's/-big5-0$/-big5hkscs-0/'`
377
+	      J1=`echo $I1|cut -c2-`
378
+	      J2=`echo $I2|cut -c2-`
379
+	      J3=`echo $I3|cut -c2-`
380
+	      J4=`echo $I4|cut -c2-`
381
+              grep -v "$J1" $HKABIFONTPATH/fonts.dir |grep -v "$J2" |grep -v "$J3" |grep -v "$J4" |sed -e "1d" > $TEMPFILE
382
+	      grep -i '[[:space:]]\+-[^-]\+-[^-]\+HKSCS-' $TEMPFILE > $TEMPFILE.1
383
+	      grep -vi '[[:space:]]\+-[^-]\+-[^-]\+HKSCS-' $TEMPFILE > $TEMPFILE.2
384
+	      echo "${TTFINFO_FONT_PSNAME}-HKscs-B5-H, $I1, 880, 120, 1000" > $TEMPFILE.3
385
+	      echo "${TTFINFO_FONT_PSNAME}-Bold-HKscs-B5-H, $I2, 880, 120, 1000" >> $TEMPFILE.3
386
+	      echo "${TTFINFO_FONT_PSNAME}-Italic-HKscs-B5-H, $I3, 880, 120, 1000" >> $TEMPFILE.3
387
+	      echo "${TTFINFO_FONT_PSNAME}-BoldItalic-HKscs-B5-H, $I4, 880, 120, 1000" >> $TEMPFILE.3
388
+	      if ( echo $I1 | grep -qi '^-[^-]\+-[^-]*HKSCS-' ); then
389
+		if [ "$TTFINFO_FONT_PSNAME" = "InnMing-Light" ]; then
390
+		  cat $TEMPFILE.3 $TEMPFILE.1 $TEMPFILE.2 > $TEMPFILE
391
+		else
392
+		  cat $TEMPFILE.1 $TEMPFILE.3 $TEMPFILE.2 > $TEMPFILE
393
+		fi
394
+	      elif [ "$TTFINFO_FONT_PSNAME" = "ShanHeiSun-Light" ]; then
395
+		cat $TEMPFILE.1 $TEMPFILE.3 $TEMPFILE.2 > $TEMPFILE
396
+	      else
397
+		cat $TEMPFILE.1 $TEMPFILE.2 $TEMPFILE.3 > $TEMPFILE
398
+	      fi
399
+	      LINE=`wc -l < $TEMPFILE`
400
+              echo $LINE > $HKABIFONTPATH/fonts.dir
401
+	      cat $TEMPFILE >> $HKABIFONTPATH/fonts.dir
402
+	    ;;
403
+	    gb2312.1980)
404
+	      # zh-CN
405
+              grep -v "$J1" $CNABIFONTPATH/fonts.dir|grep -v "$J2"|grep -v "$J3"|grep -v "$J4"|sed -e "1d" > $TEMPFILE
406
+	      echo "${TTFINFO_FONT_PSNAME}-GB-EUC-H, $I1, 880, 120, 1000" >> $TEMPFILE
407
+	      echo "${TTFINFO_FONT_PSNAME}-Bold-GB-EUC-H, $I2, 880, 120, 1000" >> $TEMPFILE
408
+	      echo "${TTFINFO_FONT_PSNAME}-Italic-GB-EUC-H, $I3, 880, 120, 1000" >> $TEMPFILE
409
+	      echo "${TTFINFO_FONT_PSNAME}-BoldItalic-GB-EUC-H, $I4, 880, 120, 1000" >> $TEMPFILE
410
+	      LINE=`wc -l < $TEMPFILE`
411
+              echo $LINE > $CNABIFONTPATH/fonts.dir
412
+	      cat $TEMPFILE >> $CNABIFONTPATH/fonts.dir
413
+	      # zh-CN.GBK
414
+	      I1=`echo $I1 | sed -e 's/-gb2312.1980-0$/-gbk-0/'`
415
+	      I2=`echo $I2 | sed -e 's/-gb2312.1980-0$/-gbk-0/'`
416
+	      I3=`echo $I3 | sed -e 's/-gb2312.1980-0$/-gbk-0/'`
417
+	      I4=`echo $I4 | sed -e 's/-gb2312.1980-0$/-gbk-0/'`
418
+	      J1=`echo $I1|cut -c2-`
419
+	      J2=`echo $I2|cut -c2-`
420
+	      J3=`echo $I3|cut -c2-`
421
+	      J4=`echo $I4|cut -c2-`
422
+              grep -v "$J1" $CNABIFONTPATH.GBK/fonts.dir |grep -v "$J2" |grep -v "$J3" |grep -v "$J4" |sed -e "1d" > $TEMPFILE
423
+	      echo "${TTFINFO_FONT_PSNAME}-GBK-EUC-H, $I1, 880, 120, 1000" >> $TEMPFILE
424
+	      echo "${TTFINFO_FONT_PSNAME}-Bold-GBK-EUC-H, $I2, 880, 120, 1000" >> $TEMPFILE
425
+	      echo "${TTFINFO_FONT_PSNAME}-Italic-GBK-EUC-H, $I3, 880, 120, 1000" >> $TEMPFILE
426
+	      echo "${TTFINFO_FONT_PSNAME}-BoldItalic-GBK-EUC-H, $I4, 880, 120, 1000" >> $TEMPFILE
427
+	      LINE=`wc -l < $TEMPFILE`
428
+              echo $LINE > $CNABIFONTPATH.GBK/fonts.dir
429
+	      cat $TEMPFILE >> $CNABIFONTPATH.GBK/fonts.dir
430
+            ;;
431
+#	    ksc5601.1987)
432
+#	      echo
433
+#	    ;;
434
+#	    jisx0208.1983|jisx0201.1976)
435
+#	      echoC "todo"
436
+#	    ;;
437
+	  esac
438
+          i=$(($i+1))     # Linux should use bash...:)
439
+        done
440
     done
441
+    return $error
442
 }
443
 
444
 
445
-#
446
-# Set default font, accept kai or ming(default) only, all others will be
447
-# treated as ming, eg.
448
-# "setdefault kai /usr/local/share/fonts/TrueType/bkai00mp.ttf".
449
-#
450
-# setdefault() causes chain effects, ie. setdefault() in AbiWord WILL
451
-# make that font default both in X Window or Ghostscript.  While we can
452
-# make AbiWord's default font an ordinary TTF in X Window, it's hard
453
-# to do so do so with Ghostscript.
454
-#
455
-# One implication of this behaviour is that the default fonts of Abiword,
456
-# Ghostscript, and X Window have to be the same.  If they're not in sync,
457
-# strange problems may arise.
458
-#
459
-setdefault()
460
+# Remove ttf fonts
461
+remove_fonts()
462
 {
463
-	 face=$1
464
-	 addfile=$2
465
-	 # Some sanity checking
466
-	 if [ ! -r "$addfile" ]; then
467
-		  echo "$addfile does not exist, skipped."
468
-		  continue
469
-	 fi
470
-	 if [ -z "`echo $addfile |grep -i -e ".*tt[cf]$"`" ]; then
471
-		  echo "$addfile is not a TTF, skipped."
472
-		  continue
473
-	 fi
474
-	 # Those modules will manage if fonts are already installed.
475
-	 $TTFM --add $XMODULE $addfile
476
-	 $TTFM --add $GSMODULE $addfile
477
-	 if [ "$face" = "kai" ]; then
478
-		  $TTFM --setdefault_kai $XMODULE $addfile
479
-		  $TTFM --setdefault_kai $GSMODULE $addfile
480
-	 else
481
-		  $TTFM --setdefault $XMODULE $addfile
482
-		  $TTFM --setdefault $GSMODULE $addfile
483
-	 fi
484
-
485
-	 f="`basename "$addfile"`"
486
-	 # We know it's default, but which encoding is unknown.
487
-	 xlfd="`$TTFM --list $XMODULE |grep $f |sed -e "/iso/d" -e "s/$f //g" |sort |uniq`"
488
-	 encoding=`echo $xlfd |cut -d '-' -f 14-15`
489
-	 subdir="`printf "$ed_table" |awk -F "," -v i=$encoding '{dir[$2]=$1} END {print dir[i]}'`"
490
-	 cidname="`$TTFM --list $GSMODULE |grep -e "^Default.*$f" |cut -d '(' -f 1`"
491
-	 psname="$cidname"-"`printf "$ep_table" |awk -F "," -v i=$encoding '{ps[$1]=$2} END {print ps[i]}'`"
492
-
493
-	 if [ ! -d $ABIFontPath/$subdir ]; then
494
-		  mkdir -p $ABIFontPath/$subdir
495
-	 fi
496
-	 touch $ABIFontPath/$subdir/.already-in-fp
497
-	 if [ ! -r $ABIFontPath/$subdir/fonts.dir ]; then
498
-		  echo 0 > $ABIFontPath/$subdir/fonts.dir
499
-	 fi
500
-	 cp $ABIFontPath/$subdir/fonts.dir $TEMPFILE
501
-	 # There may be spaces in $xlfd, quote it.
502
-	 abifont="$psname, $xlfd, $PRINTPARAM"
503
-	 echo $abifont >> $TEMPFILE
504
-	 echo $abifont |sed -e "s/-medium-r-/-bold-r-/g" >> $TEMPFILE
505
-	 echo $abifont |sed -e "s/-medium-r-/-medium-i-/g" >> $TEMPFILE
506
-	 echo $abifont |sed -e "s/-medium-r-/-bold-i-/g" >> $TEMPFILE
507
-	 num=`cat $TEMPFILE |wc -l`
508
-	 num=`expr $num - 1`
509
-	 sed -e "1s/.*/$num/g" $TEMPFILE > $ABIFontPath/$subdir/fonts.dir
510
+    error=0
511
+    for f in "$@"; do
512
+        if [ ! -e "$f" ]; then
513
+            if [ -e "$DEFAULTPATH/$f" ]; then
514
+                f="$DEFAULTPATH/$f"
515
+            else
516
+                echo "Cannot find font $f, ignored!"
517
+                error=$(($error+1))
518
+                continue
519
+            fi
520
+        fi
521
+
522
+        fontfile=`basename $f`
523
+        eval `echo $fontfile | awk -F. '{ printf "font=%s;ext=%s",\$1,\$2 }'`
524
+
525
+        get_ttfinfo $f
526
+        i=1
527
+        while [ $i -le $TTFINFO_MAPNUM ]; do
528
+          eval I1=\$TTFINFO_FONTMAP${i}
529
+	  I2=`echo $I1|sed -e s/medium-r/bold-r/`
530
+	  I3=`echo $I1|sed -e s/medium-r/medium-i/`
531
+	  I4=`echo $I1|sed -e s/medium-r/bold-i/`
532
+	  J1=`echo $I1|cut -c2-`
533
+	  J2=`echo $I2|cut -c2-`
534
+	  J3=`echo $I3|cut -c2-`
535
+	  J4=`echo $I4|cut -c2-`
536
+	  MYENC=`echo $I1 | awk -F- '{print $14}'`
537
+	  case $MYENC in
538
+	    big5)
539
+	      # zh-TW
540
+              grep -v "$J1" $TWABIFONTPATH/fonts.dir |grep -v "$J2" |grep -v "$J3" |grep -v "$J4" |sed -e "1d" > $TEMPFILE
541
+	      LINE=`wc -l < $TEMPFILE`
542
+              echo $LINE > $TWABIFONTPATH/fonts.dir
543
+	      cat $TEMPFILE >> $TWABIFONTPATH/fonts.dir
544
+	      # zh-HK
545
+	      I1=`echo $I1 | sed -e 's/-big5-0$/-big5hkscs-0/'`
546
+	      I2=`echo $I2 | sed -e 's/-big5-0$/-big5hkscs-0/'`
547
+	      I3=`echo $I3 | sed -e 's/-big5-0$/-big5hkscs-0/'`
548
+	      I4=`echo $I4 | sed -e 's/-big5-0$/-big5hkscs-0/'`
549
+	      J1=`echo $I1|cut -c2-`
550
+	      J2=`echo $I2|cut -c2-`
551
+	      J3=`echo $I3|cut -c2-`
552
+	      J4=`echo $I4|cut -c2-`
553
+              grep -v "$J1" $HKABIFONTPATH/fonts.dir |grep -v "$J2" |grep -v "$J3" |grep -v "$J4" |sed -e "1d" > $TEMPFILE
554
+	      LINE=`wc -l < $TEMPFILE`
555
+              echo $LINE > $HKABIFONTPATH/fonts.dir
556
+	      cat $TEMPFILE >> $HKABIFONTPATH/fonts.dir
557
+	    ;;
558
+	    gb2312.1980)
559
+	      # zh-CN
560
+              grep -v "$J1" $CNABIFONTPATH/fonts.dir|grep -v "$J2"|grep -v "$J3"|grep -v "$J4"|sed -e "1d" > $TEMPFILE
561
+	      LINE=`wc -l < $TEMPFILE`
562
+              echo $LINE > $CNABIFONTPATH/fonts.dir
563
+	      cat $TEMPFILE >> $CNABIFONTPATH/fonts.dir
564
+	      # zh-CN.GBK
565
+	      I1=`echo $I1 | sed -e 's/-gb2312.1980-0$/-gbk-0/'`
566
+	      I2=`echo $I2 | sed -e 's/-gb2312.1980-0$/-gbk-0/'`
567
+	      I3=`echo $I3 | sed -e 's/-gb2312.1980-0$/-gbk-0/'`
568
+	      I4=`echo $I4 | sed -e 's/-gb2312.1980-0$/-gbk-0/'`
569
+	      J1=`echo $I1|cut -c2-`
570
+	      J2=`echo $I2|cut -c2-`
571
+	      J3=`echo $I3|cut -c2-`
572
+	      J4=`echo $I4|cut -c2-`
573
+              grep -v "$J1" $CNABIFONTPATH.GBK/fonts.dir |grep -v "$J2" |grep -v "$J3" |grep -v "$J4" |sed -e "1d" > $TEMPFILE
574
+	      LINE=`wc -l < $TEMPFILE`
575
+              echo $LINE > $CNABIFONTPATH.GBK/fonts.dir
576
+	      cat $TEMPFILE >> $CNABIFONTPATH.GBK/fonts.dir
577
+            ;;
578
+#	    ksc5601.1987)
579
+#	      echo
580
+#	    ;;
581
+#	    jisx0208.1983|jisx0201.1976)
582
+#	      echoC "todo"
583
+#	    ;;
584
+	  esac
585
+          i=$(($i+1))     # Linux should use bash...:)
586
+        done
587
+    done
588
+    return $error
589
 }
590
 
591
 
592
@@ -306,8 +350,6 @@
593
     exit 1
594
 fi
595
 
596
-check_abiword
597
-
598
 ARG=$1
599
 shift 1
600
 
601
@@ -316,52 +358,36 @@
602
     Usage
603
     ;;
604
 --name)
605
+    echo
606
     echo "$NAME $VERSION"
607
+    echo
608
     ;;
609
 --list)
610
     list_fonts
611
     ;;
612
 --add)
613
     if [ $# -lt 1 ]; then
614
-        echo "Missing font filename argument."
615
+        echo "Missing font filename argument!"
616
         Usage
617
         exit 1
618
     fi
619
     add_fonts $@
620
-    echo "Adding $@."
621
+    echo "Done!"
622
     ;;
623
 --remove)
624
     if [ $# -lt 1 ]; then
625
-        echo "Missing font filename argument."
626
+        echo "Missing font filename argument!"
627
         Usage
628
         exit 1
629
     fi
630
     remove_fonts $@
631
-    echo "Removing $@."
632
+    echo "Done!"
633
     ;;
634
 --setdefault|--setdefault_ming)
635
-    if [ $# -lt 1 ]; then
636
-        echo "Missing font filename arguments."
637
-        Usage
638
-        exit 1
639
-    elif [ $# -gt 1 ]; then
640
-        echo "Only need one font filename."
641
-        Usage
642
-        exit 1
643
-    fi
644
-    setdefault ming $1
645
+    echo "No need to set default fonts"
646
     ;;
647
 --setdefault_kai)
648
-    if [ $# -lt 1 ]; then
649
-        echo "Missing font filename arguments."
650
-        Usage
651
-        exit 1
652
-    elif [ $# -gt 1 ]; then
653
-        echo "Only need one font filename."
654
-        Usage
655
-        exit 1
656
-    fi
657
-    setdefault kai $1
658
+    echo "No need to set default fonts"
659
     ;;
660
 *)
661
     Usage
662
@@ -369,7 +395,18 @@
663
     ;;
664
 esac
665
 
666
-rm -f $TEMPFILE
667
+rm -f $TEMPFILE $TEMPFILE.1 $TEMPFILE.2 $TEMPFILE.3
668
 exit 0
669
 
670
 
671
+# ChangeLog
672
+#
673
+# * Fri Jan  12 2001 Chung-Yen Chang <candyz@cle.linux.org.tw>
674
+# - first release
675
+#
676
+# * Tue Sep  4 2001 Anthony Fok <anthony@thizlinux.com>
677
+# - Added Big5-HKSCS font support thanks to ThizLinux Laboratory Ltd., Thiz
678
+#   Technology Group.  Also added preliminary GBK support
679
+# - Use the _real_ PostScript font names, and with Bold, Italic and BoldItalic
680
+# - List InnMing-Light / HKSCS (zh_HK) or ShanHeiSun-Light (zh_TW) first
681
+#
(-)ttfm/files/patch-modules::gscjk.ttfm (-763 lines)
Lines 1-763 Link Here
1
--- modules/gscjk.ttfm.orig	Sun Jun  2 03:40:13 2002
2
+++ modules/gscjk.ttfm	Sun Jun  2 03:39:59 2002
3
@@ -0,0 +1,760 @@
4
+#!/bin/sh
5
+#
6
+# TTFM module for Ghostscript 6.51 with GS-CJK
7
+#
8
+# This script is distributed under the revised BSD license.
9
+#
10
+# For any problem reports or suggestions, please contact
11
+# Chung-Yen Chang <candyz@linux.org.tw>,
12
+# Anthony Fok <anthony@thizlinux.org>
13
+# or the original author Jing-Tang Keith Jang <keith@FreeBSD.org>.
14
+#
15
+
16
+# This script can handle both CID and TrueType fonts.
17
+
18
+# Name & version
19
+export NAME; NAME="Ghostscript 7.06 TTF Font Manager"
20
+export VERSION; VERSION=1.0
21
+
22
+# Global constants
23
+
24
+export PREFIX; PREFIX=/usr/local
25
+export TTFINFOPath; TTFINFOPath="${PREFIX}/bin/ttfinfo"
26
+export GS6Path; GS6Path="${PREFIX}/share/ghostscript"
27
+export GS6CJKPath; GS6CJKPath="${GS6Path}/Resource"
28
+export CJKCMapPath; CJKCMapPath="${GS6CJKPath}/CMap"
29
+export CJKFontPath; CJKFontPath="${GS6CJKPath}/Font"
30
+export CJKCIDPath; CJKCIDPath="${GS6CJKPath}/CIDFont"
31
+# Not used
32
+# export CJKTTFPath; CJKTTFPath="${GS6CJKPath}/TrueType"
33
+export GS6LibPath; GS6LibPath="${GS6Path}/7.06/lib"
34
+export DefaultMing_Name; DefaultMing_Name="DEFAULT-MING"
35
+export DefaultKai_Name; DefaultKai_Name="DEFAULT-KAI"
36
+export TEMPFILE; TEMPFILE="`mktemp /tmp/ttfm.tmpXXXXXX`"
37
+
38
+# Encoding/Ordering table, used to convert the output of ttfinfo(encoding)
39
+# to CID font's ordering property, and vice versa.  See guess_ttf_info()
40
+# below.
41
+#
42
+export eo_table; eo_table=\
43
+"Adobe CNS1,big5-0\n
44
+Adobe GB1,gb2312.1980-0\n
45
+Adobe Korea1,ksc5601.1987-0\n
46
+Adobe Japan1,jisx0208.1983-0\n
47
+Adobe Japan2,jisx0212.1990-0\n"
48
+
49
+# Postscript command to open TTFs, defined in gs_ttf.ps.
50
+# It needs gs_ttf.ps-cjkv-*.patch of http://www.aihara.co.jp/~taiji/tops/.
51
+export OpenTTFont; OpenTTFont=.openttcidfont
52
+
53
+# Who am I?
54
+print_name()
55
+{
56
+    echo "$NAME $VERSION"
57
+}
58
+
59
+
60
+# Usage
61
+Usage()
62
+{
63
+    echo
64
+    echo "$NAME $VERSION"
65
+    echo
66
+    echo "Usage: $NAME [option]"
67
+    echo
68
+    echo "       --check            check Ghostscript 7.06 settings"
69
+    echo "       --add <file>...                install CID font"
70
+    echo "       --add [alias=]<file>...        install TTF font"
71
+    echo "       --remove <file>... remove font from the system"
72
+    echo "       --list             list all fonts on the system"
73
+    echo "       --setdefault <file>"
74
+    echo "                          set default font to file"
75
+    echo "       --setdefault_kai <file>"
76
+    echo "                          set default \kai font to file"
77
+    echo "       --setdefault_ming <file>"
78
+    echo "                          set default \ming font to file"
79
+    echo "       --help             show this info"
80
+    echo
81
+}
82
+
83
+
84
+#
85
+# Check if CJK CMap files are correctly installed with Ghostscript 6.
86
+# Give a warning if Adobe CNS1/GB1/Identity/Japan1/Japan2/Korea1 is not found.
87
+#
88
+# We'll also check gs_res.ps & gs_ttf.ps.
89
+#
90
+check_gs6()
91
+{
92
+    if [ ! -x $TTFINFOPath ]; then
93
+        echo "ttfinfo not installed!"
94
+        exit 1
95
+    fi
96
+
97
+    if [ ! -d "${CJKCMapPath}" ]; then
98
+        echo "Error: You have no CMap files installed!"
99
+        exit 1
100
+    fi
101
+
102
+    # ac1
103
+    if [ -z "`grep -l "Adobe CNS1" ${CJKCMapPath}/*`" ]; then
104
+        echo "Warning: Adobe-CNS1-3 CMap files not installed!"
105
+    # ag1
106
+    elif [ -z "`grep -l "Adobe GB1" ${CJKCMapPath}/*`" ]; then
107
+        echo "Warning: Adobe-GB1-3 CMap files not installed!"
108
+    # aj1
109
+    elif [ -z "`grep -l "Adobe Japan1" ${CJKCMapPath}/*`" ]; then
110
+        echo "Warning: Adobe-Japan1-4 CMap files not installed!"
111
+    # aj2
112
+    elif [ -z "`grep -l "Adobe Japan2" ${CJKCMapPath}/*`" ]; then
113
+        echo "Warning: Adobe-Japan2-0 CMap files not installed!"
114
+    # ak1
115
+    elif [ -z "`grep -l "Adobe Korea1" ${CJKCMapPath}/*`" ]; then
116
+        echo "Warning: Adobe-Korea1-2 CMap files not installed!"
117
+    # I'm not sure if it's needed, so just a warning if not found.
118
+    elif [ -z "`grep -l "Adobe Identity" ${CJKCMapPath}/*`" ]; then
119
+        echo "Warning: Adobe Identity CMap files not installed!"
120
+    fi
121
+
122
+    # These two conditions are pretty weak. :-)
123
+    if [ -z "`grep -l "Taiji Yamada" ${GS6LibPath}/gs_ttf.ps`" ]; then
124
+        echo "Error: Your gs_ttf.ps is not patched."
125
+        echo "See http://www.aihara.co.jp/~taiji/tops/ for details."
126
+        exit 1
127
+    elif [ -n "`grep -l -e "/FontResourceDir (/Resource/Font/)\|/FontResourceDir (/Resource/Font/)" ${GS6LibPath}/gs_res.ps`" ]; then
128
+        echo "Error: Please modify FontResourceDir or FontResourceDir in gs_res.ps."
129
+        echo "See http://www.aihara.co.jp/~taiji/tops/ for details."
130
+        exit 1
131
+    fi
132
+
133
+    echo "No errors found."
134
+}
135
+
136
+
137
+# List all fonts installed in ${CJKFontPath}, cross-referenced with those
138
+# fonts installed in ${CJKCIDPath}.
139
+list_fonts()
140
+{
141
+    echo "Installed TTF fonts:"
142
+    for CIDFont in `ls ${CJKCIDPath}`; do
143
+        echo "${CIDFont}:"
144
+        cd ${CJKFontPath}; ls ${CIDFont}* 2>/dev/null
145
+        echo
146
+    done
147
+}
148
+
149
+
150
+# Remove fonts
151
+remove_fonts()
152
+{
153
+    for f in "$@"; do
154
+        targetname=`basename $f`
155
+
156
+        rm -f ${CJKCIDPath}/${targetname} ${CJKFontPath}/${targetname}*
157
+    done
158
+}
159
+
160
+
161
+#
162
+# guess_ttf_info <fontfile>, eg. guess_ttf_info bsmi00lp.ttf.
163
+#
164
+# Guess the alias of a ttf, and put it in $TTF_ALIAS.
165
+# Guess which index to use, and put it in $TTF_INDEX.
166
+# Guess which ordering a ttf should use, eg. "Adobe CNS1" for bsmi00lp.ttf.
167
+#    Then put the ordering in $TTF_ORDERING.
168
+#
169
+# Simply put, we guess everything. :-)
170
+#
171
+guess_ttf_info()
172
+{
173
+    targetname=$1
174
+
175
+    eval `$TTFINFOPath -c ${targetname}`
176
+    # Set fontname from the filename if it's unknown.
177
+    # I assume there's no ttf filename like "-----.ttf".
178
+    unset HKSCS
179
+    ( echo $TTFINFO_FONT_NAME | grep -qi HKSCS ) && export HKSCS=1
180
+    if [ "$TTFINFO_FONT_NAME" = "unknown" ]; then
181
+        TTFINFO_FONT_NAME=`basename $targetname |cut -d "." -f 1 |sed -e "s/-//g"`
182
+    fi
183
+
184
+    # Extract slant/property/encoding, then install.
185
+    MAPNUM=1
186
+    while [ $MAPNUM -le $TTFINFO_MAPNUM ]; do
187
+        eval TTFINFO_FONTMAP=\$TTFINFO_FONTMAP${MAPNUM}
188
+        fontweight=`echo $TTFINFO_FONTMAP |cut -d "-" -f 4`
189
+        fontslant=`echo $TTFINFO_FONTMAP |cut -d "-" -f 5`
190
+        encoding1=`echo $TTFINFO_FONTMAP |cut -d "-" -f 14`
191
+        encoding2=`echo $TTFINFO_FONTMAP |cut -d "-" -f 15`
192
+        fontencoding=${encoding1}-${encoding2}
193
+
194
+        if [ -n "`echo ${fontencoding} |grep -i -e "big5\|cns\|gb\|ksc\|jis"`" ]; then
195
+            break
196
+        fi
197
+
198
+        MAPNUM=`expr $MAPNUM + 1`
199
+    done
200
+
201
+    if [ -z "`echo ${fontencoding} |grep -i -e "big5\|cns\|gb\|ksc\|jis"`" ]; then
202
+        echo "${targetname}" is not a CJK TTF!
203
+        exit 1
204
+    fi
205
+
206
+    # The first characters of foundry & font names should be uppercase.
207
+    i=`echo "$TTFINFO_FOUNDRY_NAME" |cut -b 1`
208
+    j=`echo $i |tr [:lower:] [:upper:]`
209
+    TTFINFO_FOUNDRY_NAME=`echo $TTFINFO_FOUNDRY_NAME |sed -e "s/^$i/$j/"`
210
+    i=`echo "$TTFINFO_FONT_NAME" |cut -b 1`
211
+    j=`echo $i |tr [:lower:] [:upper:]`
212
+    TTFINFO_FONT_NAME=`echo $TTFINFO_FONT_NAME |sed -e "s/^$i/$j/"`
213
+
214
+    # Alias property.  The first two are in favor of Chinese TTFs.
215
+    # We'll also strip any spaces in foundry and font names.
216
+    TTFINFO_FOUNDRY_NAME="`echo $TTFINFO_FOUNDRY_NAME |sed -e "s/ //g"`"
217
+#    if [ -n "`echo ${fontencoding} |grep -i "big5"`" ]; then
218
+#        if [ -z "`echo $TTFINFO_FONT_NAME |grep " "`" ]; then
219
+#            TTF_ALIAS="${TTFINFO_FOUNDRY_NAME}${TTFINFO_FONT_NAME}B5"
220
+#        # The following two are hacks, in favor of Arphic TTF.
221
+#        elif [ -n "`echo $TTFINFO_FONT_NAME |grep -i -e "kai"`" ]; then
222
+#            TTF_ALIAS="${TTFINFO_FOUNDRY_NAME}KaiB5"
223
+#        elif [ -n "`echo $TTFINFO_FONT_NAME |grep -i -e "ming"`" ]; then
224
+#            TTF_ALIAS="${TTFINFO_FOUNDRY_NAME}MingB5"
225
+#        else
226
+#            TTF_ALIAS="${TTFINFO_FOUNDRY_NAME}`echo $TTFINFO_FONT_NAME |sed -e "s/ //g"`B5"
227
+#        fi
228
+#    elif [ -n "`echo ${fontencoding} |grep -i "gb"`" ]; then
229
+#        if [ -z "`echo $TTFINFO_FONT_NAME |grep " "`" ]; then
230
+#            TTF_ALIAS="${TTFINFO_FOUNDRY_NAME}${TTFINFO_FONT_NAME}GB"
231
+#        # The following two are hacks, in favor of Arphic TTF.
232
+#        elif [ -n "`echo $TTFINFO_FONT_NAME |grep -i -e "kai"`" ]; then
233
+#            TTF_ALIAS="${TTFINFO_FOUNDRY_NAME}KaiGB"
234
+#        elif [ -n "`echo $TTFINFO_FONT_NAME |grep -i -e "ming"`" ]; then
235
+#            TTF_ALIAS="${TTFINFO_FOUNDRY_NAME}MingGB"
236
+#        else
237
+#            TTF_ALIAS="${TTFINFO_FOUNDRY_NAME}`echo $TTFINFO_FONT_NAME |sed -e "s/ //g"`GB"
238
+#        fi
239
+#    else
240
+#        TTF_ALIAS=${TTFINFO_FOUNDRY_NAME}"`echo $TTFINFO_FONT_NAME |sed -e "s/ //g"`"
241
+#    fi
242
+    TTF_ALIAS=$TTFINFO_FONT_PSNAME
243
+
244
+#    case "$fontweight" in
245
+#    'bold')
246
+#        TTF_ALIAS="${TTF_ALIAS}-Bold"
247
+#    ;;
248
+#    *)
249
+#        TTF_ALIAS="${TTF_ALIAS}-Regular"
250
+#    ;;
251
+#    esac
252
+
253
+    # Index
254
+    TTF_INDEX=$MAPNUM
255
+    # Ordering property
256
+    TTF_ORDERING="`printf "$eo_table" |awk -F "," -v i=$fontencoding '{encoding[$2]=$1} END {print encoding[i]}'`"
257
+}
258
+
259
+
260
+#
261
+# install_ttf <alias> <filename>[,ttf_index] eg.
262
+# install_ttf Arphic-MingB5 /usr/share/fonts/ttf/bsmi00lp.ttf,1.
263
+#
264
+# Write CID info file of a TTF, so it can be used as a CID font afterwards.
265
+# Currently we'll always call install_ttf() with ttf_index.
266
+#
267
+install_ttf()
268
+{
269
+    alias=$1
270
+    filename=$2
271
+
272
+    TTE=""
273
+    case "$alias" in
274
+    *-Adobe-*[0-9])
275
+        TTE=' /'`echo "$alias" |sed -n -e "s/^.*-\(Adobe-.*[0-9]\)$/\1/p"`"-Unicode"
276
+    ;;
277
+    *,Adobe-*[0-9]-*)
278
+        TTE=' /'`echo "$alias" |sed -n -e "s/^\(.*\),\(Adobe-.*[0-9]-.*\)$/\2/p"`
279
+        alias=`echo "$alias" |sed -n -e "s/^\(.*\),\(Adobe-.*[0-9]-.*\)$/\1/p"`
280
+    ;;
281
+    esac
282
+
283
+    case "$filename" in
284
+    *.[Tt][Tt][CcFf],[0-9])
285
+        TTF=`echo "$filename" |sed -n -e "s/^\(.*\),\([0-9]\)$/\1/p"`
286
+        TTI=`echo "$filename" |sed -n -e "s/^\(.*\),\([0-9]\)$/\2/p"`
287
+	# Regular font
288
+        [ "$HKSCS" = "1" -o ! -f "$CJKCIDPath/$alias" ] && cat <<EOF > "$CJKCIDPath/$alias" && echo "+$alias=$TTF"
289
+%!PS-Adobe-3.0 Resource-CIDFont
290
+%%BeginResource: CIDFont ($FNN)
291
+/$alias
292
+($TTF) $TTI$TTE $OpenTTFont
293
+dup length dict begin {def} forall currentdict end
294
+/CIDFont defineresource pop
295
+%%EndResource
296
+%%EOF
297
+EOF
298
+	# Bold font
299
+        [ "$HKSCS" = "1" -o ! -f "$CJKCIDPath/$alias-Bold" ] && cat <<EOF > "$CJKCIDPath/$alias-Bold" && echo "+$alias=$TTF-Bold"
300
+%!PS-Adobe-3.0 Resource-CIDFont
301
+%%BeginResource: CIDFont ($FNN-Bold)
302
+/$alias-Bold
303
+/$alias /CIDFont findresource
304
+16 dict begin
305
+  /basecidfont exch def
306
+  /basefont-H /.basefont-H /Identity-H [ basecidfont ] composefont def
307
+  /basefont-V /.basefont-V /Identity-V [ basecidfont ] composefont def
308
+  /CIDFontName dup basecidfont exch get def
309
+  /CIDFontType 1 def
310
+  /CIDSystemInfo dup basecidfont exch get def
311
+  /FontInfo dup basecidfont exch get def
312
+  /FontMatrix [ 1 0 0 1 0 0 ] def
313
+  /FontBBox [
314
+    basecidfont /FontBBox get cvx exec
315
+    4 2 roll basecidfont /FontMatrix get transform
316
+    4 2 roll basecidfont /FontMatrix get transform
317
+  ] def
318
+  /cid 2 string def
319
+  /BuildGlyph {
320
+    gsave
321
+    exch begin
322
+      dup 256 idiv cid exch 0 exch put
323
+      256 mod cid exch 1 exch put
324
+      rootfont /WMode known { rootfont /WMode get 1 eq } { false } ifelse
325
+      { basefont-V } { basefont-H } ifelse setfont
326
+      .03 setlinewidth 1 setlinejoin
327
+      newpath
328
+      0 0 moveto cid false charpath stroke
329
+      0 0 moveto cid show
330
+      currentpoint setcharwidth
331
+    end
332
+    grestore
333
+  } bind def
334
+  currentdict
335
+end
336
+/CIDFont defineresource pop
337
+%%EndResource
338
+%%EOF
339
+EOF
340
+	# Italic font
341
+        [ "$HKSCS" = "1" -o ! -f "$CJKCIDPath/$alias-Italic" ] && cat <<EOF > "$CJKCIDPath/$alias-Italic" && echo "+$alias=$TTF-Italic"
342
+%!PS-Adobe-3.0 Resource-CIDFont
343
+%%BeginResource: CIDFont ($FNN-Italic)
344
+/$alias-Italic
345
+/$alias /CIDFont findresource
346
+dup length dict begin { 1 index /FontMatrix eq { [1 0 .3 1 0 0] matrix concatmatrix def } { def } ifelse } forall currentdict end
347
+/CIDFont defineresource pop
348
+%%EndResource
349
+%%EOF
350
+EOF
351
+	# BoldItalic font
352
+        [ "$HKSCS" = "1" -o ! -f "$CJKCIDPath/$alias-BoldItalic" ] && cat <<EOF > "$CJKCIDPath/$alias-BoldItalic" && echo "+$alias=$TTF-BoldItalic"
353
+%!PS-Adobe-3.0 Resource-CIDFont
354
+%%BeginResource: CIDFont ($FNN-BoldItalic)
355
+/$alias-BoldItalic
356
+/$alias /CIDFont findresource
357
+16 dict begin
358
+  /basecidfont exch def
359
+  /basefont-H /.basefont-H /Identity-H [ basecidfont ] composefont def
360
+  /basefont-V /.basefont-V /Identity-V [ basecidfont ] composefont def
361
+  /CIDFontName dup basecidfont exch get def
362
+  /CIDFontType 1 def
363
+  /CIDSystemInfo dup basecidfont exch get def
364
+  /FontInfo dup basecidfont exch get def
365
+  /FontMatrix [ 1 0 0 1 0 0 ] def
366
+  /FontBBox [
367
+    basecidfont /FontBBox get cvx exec
368
+    4 2 roll basecidfont /FontMatrix get transform
369
+    4 2 roll basecidfont /FontMatrix get transform
370
+  ] def
371
+  /cid 2 string def
372
+  /BuildGlyph {
373
+    gsave
374
+    exch begin
375
+      dup 256 idiv cid exch 0 exch put
376
+      256 mod cid exch 1 exch put
377
+      rootfont /WMode known { rootfont /WMode get 1 eq } { false } ifelse
378
+      { basefont-V } { basefont-H } ifelse setfont
379
+      .03 setlinewidth 1 setlinejoin
380
+      newpath
381
+      0 0 moveto cid false charpath stroke
382
+      0 0 moveto cid show
383
+      currentpoint setcharwidth
384
+    end
385
+    grestore
386
+  } bind def
387
+  currentdict
388
+end
389
+dup length dict begin { 1 index /FontMatrix eq { [1 0 .3 1 0 0] matrix concatmatrix def } { def } ifelse } forall currentdict end
390
+/CIDFont defineresource pop
391
+%%EndResource
392
+%%EOF
393
+EOF
394
+    ;;
395
+    *.[Tt][Tt][CcFf])
396
+        TTF="$filename"
397
+	# Regular Font
398
+        [ "$HKSCS" = "1" -o ! -f "$CJKCIDPath/$alias" ] && cat <<EOF > "$CJKCIDPath/$alias" && echo "+$alias=$TTF"
399
+%!PS-Adobe-3.0 Resource-CIDFont
400
+%%BeginResource: CIDFont ($FNN)
401
+/$alias
402
+($TTF)$TTE $OpenTTFont
403
+dup length dict begin {def} forall currentdict end
404
+/CIDFont defineresource pop
405
+%%EndResource
406
+%%EOF
407
+EOF
408
+	# Bold Font
409
+        [ "$HKSCS" = "1" -o ! -f "$CJKCIDPath/$alias-Bold" ] && cat <<EOF > "$CJKCIDPath/$alias-Bold" && echo "+$alias=$TTF-Bold"
410
+%!PS-Adobe-3.0 Resource-CIDFont
411
+%%BeginResource: CIDFont ($FNN-Bold)
412
+/$alias-Bold
413
+/$alias /CIDFont findresource
414
+16 dict begin
415
+  /basecidfont exch def
416
+  /basefont-H /.basefont-H /Identity-H [ basecidfont ] composefont def
417
+  /basefont-V /.basefont-V /Identity-V [ basecidfont ] composefont def
418
+  /CIDFontName dup basecidfont exch get def
419
+  /CIDFontType 1 def
420
+  /CIDSystemInfo dup basecidfont exch get def
421
+  /FontInfo dup basecidfont exch get def
422
+  /FontMatrix [ 1 0 0 1 0 0 ] def
423
+  /FontBBox [
424
+    basecidfont /FontBBox get cvx exec
425
+    4 2 roll basecidfont /FontMatrix get transform
426
+    4 2 roll basecidfont /FontMatrix get transform
427
+  ] def
428
+  /cid 2 string def
429
+  /BuildGlyph {
430
+    gsave
431
+    exch begin
432
+      dup 256 idiv cid exch 0 exch put
433
+      256 mod cid exch 1 exch put
434
+      rootfont /WMode known { rootfont /WMode get 1 eq } { false } ifelse
435
+      { basefont-V } { basefont-H } ifelse setfont
436
+      .03 setlinewidth 1 setlinejoin
437
+      newpath
438
+      0 0 moveto cid false charpath stroke
439
+      0 0 moveto cid show
440
+      currentpoint setcharwidth
441
+    end
442
+    grestore
443
+  } bind def
444
+  currentdict
445
+end
446
+/CIDFont defineresource pop
447
+%%EndResource
448
+%%EOF
449
+EOF
450
+	# Italic Font
451
+        [ "$HKSCS" = "1" -o ! -f "$CJKCIDPath/$alias-Italic" ] && cat <<EOF > "$CJKCIDPath/$alias-Italic" && echo "+$alias=$TTF-Italic"
452
+%!PS-Adobe-3.0 Resource-CIDFont
453
+%%BeginResource: CIDFont ($FNN-Italic)
454
+/$alias-Italic
455
+/$alias /CIDFont findresource
456
+dup length dict begin { 1 index /FontMatrix eq { [1 0 .3 1 0 0] matrix concatmat
457
+rix def } { def } ifelse } forall currentdict end
458
+/CIDFont defineresource pop
459
+%%EndResource
460
+%%EOF
461
+EOF
462
+	# BoldItalic Font
463
+        [ "$HKSCS" = "1" -o ! -f "$CJKCIDPath/$alias-BoldItalic" ] && cat <<EOF > "$CJKCIDPath/$alias-BoldItalic" && echo "+$alias=$TTF-BoldItalic"
464
+%!PS-Adobe-3.0 Resource-CIDFont
465
+%%BeginResource: CIDFont ($FNN-BoldItalic)
466
+/$alias-BoldItalic
467
+/$alias /CIDFont findresource
468
+16 dict begin
469
+  /basecidfont exch def
470
+  /basefont-H /.basefont-H /Identity-H [ basecidfont ] composefont def
471
+  /basefont-V /.basefont-V /Identity-V [ basecidfont ] composefont def
472
+  /CIDFontName dup basecidfont exch get def
473
+  /CIDFontType 1 def
474
+  /CIDSystemInfo dup basecidfont exch get def
475
+  /FontInfo dup basecidfont exch get def
476
+  /FontMatrix [ 1 0 0 1 0 0 ] def
477
+  /FontBBox [
478
+    basecidfont /FontBBox get cvx exec
479
+    4 2 roll basecidfont /FontMatrix get transform
480
+    4 2 roll basecidfont /FontMatrix get transform
481
+  ] def
482
+  /cid 2 string def
483
+  /BuildGlyph {
484
+    gsave
485
+    exch begin
486
+      dup 256 idiv cid exch 0 exch put
487
+      256 mod cid exch 1 exch put
488
+      rootfont /WMode known { rootfont /WMode get 1 eq } { false } ifelse
489
+      { basefont-V } { basefont-H } ifelse setfont
490
+      .03 setlinewidth 1 setlinejoin
491
+      newpath
492
+      0 0 moveto cid false charpath stroke
493
+      0 0 moveto cid show
494
+      currentpoint setcharwidth
495
+    end
496
+    grestore
497
+  } bind def
498
+  currentdict
499
+end
500
+dup length dict begin { 1 index /FontMatrix eq { [1 0 .3 1 0 0] matrix concatmat
501
+rix def } { def } ifelse } forall currentdict end
502
+/CIDFont defineresource pop
503
+%%EndResource
504
+%%EOF
505
+EOF
506
+    ;;
507
+    *)
508
+        [ "$HKSCS" = "1" -o ! -f "$CJKCIDPath/$alias" ] && cat <<EOF > "$CJKCIDPath/$alias" && echo "+$alias=$filename"
509
+%!PS-Adobe-3.0 Resource-CIDFont
510
+%%BeginResource: CIDFont ($FNN)
511
+/$alias
512
+/$filename /CIDFont findresource
513
+dup length dict begin {def} forall currentdict end
514
+/CIDFont defineresource pop
515
+%%EndResource
516
+%%EOF
517
+EOF
518
+    ;;
519
+    esac
520
+}
521
+
522
+
523
+#
524
+# install_cid <ordering> <fontname>, eg.
525
+# install_cid "Adobe CNS1" MOESung-Regular.
526
+#
527
+# Write all CID-related font files.  It can be used to install TTF once
528
+# the CID info file of TTF is available.
529
+#
530
+install_cid()
531
+{
532
+    CID_ordering=$1
533
+    fontname=$2
534
+    CMaps=`cd $CJKCMapPath; grep -l -e "$CID_ordering\|Adobe Identity" *`
535
+
536
+    for cmap in $CMaps; do
537
+        if [ $cmap = 'Roman' -o $cmap = 'Katakana' -o $cmap = 'Hiragana' -o $cmap = 'Hankaku' ]; then
538
+            to='.'
539
+        else
540
+            to='-'
541
+        fi
542
+	for style in '' '-Bold' '-Italic' '-BoldItalic'; do
543
+	  [ "$HKSCS" = "1" -o ! -f "$CJKFontPath/$fontname$style$to$cmap" ] && cat <<EOF > "$CJKFontPath/$fontname$style$to$cmap" && echo "+$fontname$style$to$cmap"
544
+%!PS-Adobe-3.0 Resource-Font
545
+%%DocumentNeededResources: $cmap (CMap)
546
+%%IncludeResource: $cmap (CMap)
547
+%%BeginResource: Font ($fontname$style$to$cmap)
548
+/$fontname$style$to$cmap
549
+/$cmap /CMap findresource
550
+[/$fontname$style /CIDFont findresource]
551
+composefont pop
552
+%%EndResource
553
+%%EOF
554
+EOF
555
+	done
556
+    done
557
+}
558
+
559
+
560
+#
561
+# Add fonts
562
+#
563
+add_fonts()
564
+{
565
+    ALIASES=$*
566
+    for alias in $ALIASES; do
567
+        case "$alias" in
568
+        ?*=?*)    # We have alias & font filename.
569
+            FNN="`echo "$alias" |sed -n -e 's/^\(.*\)=\(.*\)$/\1/p'`"
570
+            fnn="`echo "$alias" |sed -n -e 's/^\(.*\)=\(.*\)$/\2/p'`"
571
+            if [ ! -f "$fnn" ]; then
572
+                echo "$fnn not found!"
573
+            fi
574
+            guess_ttf_info "$fnn"
575
+            TTF_ALIAS="$FNN"
576
+            install_ttf "$FNN" "$fnn",$TTF_INDEX
577
+            install_cid "$TTF_ORDERING" "$fnn"
578
+        ;;
579
+        ?*.[Tt][Tt][CcFf])    # We have to make up an alias.
580
+            if [ ! -f "$alias" ]; then
581
+                echo "$alias not found!"
582
+            fi
583
+            guess_ttf_info "$alias"
584
+	    FNN=$TTF_ALIAS
585
+            install_ttf $TTF_ALIAS "$alias",$TTF_INDEX
586
+            install_cid "$TTF_ORDERING" $TTF_ALIAS
587
+        ;;
588
+        *)    # CID font
589
+            if [ ! -f "$alias" ]; then
590
+                echo "$alias not found!"
591
+            fi
592
+            if [ ! -f "$CJKCIDPath/`basename $alias`" ]; then
593
+                ln -s "$alias" "$CJKCIDPath"
594
+            fi
595
+            cid_registry=`head -10 "$alias" |grep ^%%Title |cut -d " " -f 3`
596
+            cid_ordering=`head -10 "$alias" |grep ^%%Title |cut -d " " -f 4`
597
+            install_cid "$cid_registry $cid_ordering" "`basename "$alias"`"
598
+        ;;
599
+        esac
600
+    done
601
+}
602
+
603
+
604
+#
605
+# setdefault <face> <fontfile>, eg.
606
+# setdefault ming /usr/share/fonts/ttf/bsmi00lp.ttf.
607
+#
608
+# Set default font, accept kai or ming(default) only, all others will be
609
+# treated as ming.
610
+#
611
+# All aliases will be set to "Default<face><encoding>-<weight>", like
612
+# DefaultMingB5-Regular, or DefaultKaiGB-Regular.
613
+#
614
+# Currently we can't assign a CID font as default Kai/Ming.  This is
615
+# because CID font has "/FontName" hard-coded.  I'm not sure if there
616
+# are any safe ways to substitute this.
617
+#
618
+setdefault()
619
+{
620
+    face=$1
621
+    if [ "$face" != "Ming" -a "$face" != "Kai" ]; then
622
+        face="Ming"
623
+    fi
624
+    fontfile=$2
625
+    if [ -n "`echo "$fontfile" |grep '='`" ]; then    # Ignore alias
626
+        fontfile="`echo "$fontfile" |sed -n -e 's/^\(.*\)=\(.*\)$/\2/p'`"
627
+    fi
628
+    if [ ! -f "$fontfile" ]; then
629
+        echo "$fontfile not found!"
630
+    fi
631
+
632
+    case "$fontfile" in
633
+    *.[Tt][Tt][CcFf])
634
+        guess_ttf_info "$fontfile"
635
+
636
+        case "$TTF_ORDERING" in
637
+        "Adobe CNS1")
638
+            TTF_ALIAS="Default${face}B5-`echo $TTF_ALIAS |cut -d '-' -f 2`"
639
+        ;;
640
+        "Adobe GB1")
641
+            TTF_ALIAS="Default${face}GB-`echo $TTF_ALIAS |cut -d '-' -f 2`"
642
+        ;;
643
+        *)
644
+            TTF_ALIAS="Default${face}-`echo $TTF_ALIAS |cut -d '-' -f 2`"
645
+        ;;
646
+        esac
647
+
648
+        install_ttf "$TTF_ALIAS" "$fontfile",$TTF_INDEX
649
+        install_cid "$TTF_ORDERING" "$TTF_ALIAS"
650
+    ;;
651
+    *)    # CID font.  Give a message and exit.
652
+        echo "CID fonts can't be used as default fonts."
653
+        echo "Please use TTF instead."
654
+        exit 1
655
+    ;;
656
+    esac
657
+}
658
+
659
+
660
+#
661
+# main program
662
+#
663
+
664
+if [ $# -lt 1 ]; then
665
+    Usage
666
+    exit 1
667
+fi
668
+
669
+ARG=$1
670
+shift 1
671
+
672
+case $ARG in
673
+--help)
674
+    Usage
675
+    ;;
676
+--name)
677
+    echo
678
+    echo "$NAME $VERSION"
679
+    echo
680
+    ;;
681
+--list)
682
+    list_fonts
683
+    ;;
684
+--check)
685
+    check_gs6
686
+    ;;
687
+--add)
688
+    if [ $# -lt 1 ]; then
689
+        echo "Missing font filename argument!"
690
+        Usage
691
+        exit 1
692
+    fi
693
+    add_fonts $@
694
+    echo "Done!"
695
+    ;;
696
+--remove)
697
+    if [ $# -lt 1 ]; then
698
+        echo "Missing font filename argument!"
699
+        Usage
700
+        exit 1
701
+    fi
702
+    remove_fonts $@
703
+    echo "Done!"
704
+    ;;
705
+--setdefault|--setdefault_ming)
706
+    if [ $# -lt 1 ]; then
707
+        echo "Missing font filename arguments!"
708
+        Usage
709
+        exit 1
710
+    elif [ $# -gt 1 ]; then
711
+        echo "Only need one font filename!"
712
+        Usage
713
+        exit 1
714
+    fi
715
+    setdefault "Ming" $1
716
+    echo "Done!"
717
+    ;;
718
+--setdefault_kai)
719
+    if [ $# -lt 1 ]; then
720
+        echo "Missing font filename arguments!"
721
+        Usage
722
+        exit 1
723
+    elif [ $# -gt 1 ]; then
724
+        echo "Only need one font filename!"
725
+        Usage
726
+        exit 1
727
+    fi
728
+    setdefault "Kai" $1
729
+    echo "Done!"
730
+    ;;
731
+*)
732
+    Usage
733
+    exit 1
734
+    ;;
735
+esac
736
+
737
+rm -f $TEMPFILE
738
+exit 0
739
+
740
+
741
+# ChangeLog
742
+#
743
+# * Sat Oct 18 2001 Chung-Yen Chang <candyz@linux.org.tw>
744
+# - add Italic fonts support
745
+#
746
+# * Tue Sep  4 2001 Anthony Fok <anthony@thizlinux.com>
747
+# - Use original PostScript font names instead of making them up  :-)
748
+# - Added poorman's Bold font.  Still needs to work on Italic.
749
+# - Gives HKSCS priority, e.g. kai00m.ttf (Big5&HKSCS) and bkai00mp.ttf
750
+#   are both ZenKai-Medium; kai00m.ttf takes precedence.
751
+#
752
+# * Sat Dec 9 2000 Chung-Yen Chang <candyz@cle.linux.org.tw>
753
+# - Modified for Red Hat Linux 
754
+#
755
+# $Log: gscjk.ttfm,v $
756
+# Revision 1.1  2001/12/14 15:21:26  candyz
757
+# add ttfm.sh.1 gscjk.ttfm
758
+#
759
+# Revision 1.1  2000/11/23 04:32:57  Keith
760
+# Log entry was added.
761
+#
762
+# * Thu Nov 23 2000 Jing-Tang Keith Jang <keith@FreeBSD.org>
763
+# - Initial version.
(-)ttfm/files/patch-modules::xttfm.ttfm (-32 lines)
Lines 1-32 Link Here
1
--- modules/xttfm.ttfm.orig	Sat Dec 21 22:56:45 2002
2
+++ modules/xttfm.ttfm	Sat Dec 21 23:01:09 2002
3
@@ -129,18 +129,25 @@
4
     fontproperties=$7
5
     fontencoding=$8
6
 
7
+    if [ "$fontproperties" = "m" ] ; then
8
+       fontproperties="p"   
9
+       FONTFACE="fn=1:"
10
+    else
11
+       FONTFACE=""
12
+    fi
13
+
14
     # Create and update fonts.scale
15
     touch $XTTFFONTPATH/fonts.scale
16
     # Delete the first line, and duplicate entries if exist.
17
     # We can't use uniq(1) here, since filenames may start with numbers.
18
     sed -e "1d" $XTTFFONTPATH/fonts.scale |grep -iv "$fontfoundry-$fontfamily.*-$fontencoding$" > $TEMPFILE
19
 
20
-    echo "$targetname -$fontfoundry-$fontfamily-$fontweight-$fontslant-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" >> $TEMPFILE
21
+    echo "${FONTFACE}$targetname -$fontfoundry-$fontfamily-$fontweight-$fontslant-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" >> $TEMPFILE
22
     # If it's medium-r, make a {medium,bold}-{i,r} full suite
23
     if [ "X$fontweight" = "Xmedium" ] && [ "X$fontslant" = "Xr" ]; then
24
-        echo "ai=0.3:$targetname -$fontfoundry-$fontfamily-medium-i-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" >> $TEMPFILE
25
-        echo "ds=y:$targetname -$fontfoundry-$fontfamily-bold-r-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" >> $TEMPFILE
26
-        echo "ds=y:ai=0.3:$targetname -$fontfoundry-$fontfamily-bold-i-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" >> $TEMPFILE
27
+        echo "${FONTFACE}ai=0.3:$targetname -$fontfoundry-$fontfamily-medium-i-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" >> $TEMPFILE
28
+        echo "${FONTFACE}ds=y:$targetname -$fontfoundry-$fontfamily-bold-r-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" >> $TEMPFILE
29
+        echo "${FONTFACE}ds=y:ai=0.3:$targetname -$fontfoundry-$fontfamily-bold-i-$fontwidth--0-0-0-0-$fontproperties-0-$fontencoding" >> $TEMPFILE
30
     fi
31
     echo `cat $TEMPFILE |wc -l` > $XTTFFONTPATH/fonts.scale
32
     cat $TEMPFILE >> $XTTFFONTPATH/fonts.scale
(-)ttfm/files/patch-ttfinfo.c (-143 lines)
Lines 1-143 Link Here
1
--- ttfinfo.c.orig	Sun Dec 17 02:56:41 2000
2
+++ ttfinfo.c	Tue Jul 30 10:48:21 2002
3
@@ -112,6 +112,7 @@
4
 static void  usage             (const char *name);
5
 static const char *get_foundry (const TT_Char orig_code[4]);
6
 static const char *get_name    (TT_Face face);
7
+static const char *get_psname  (TT_Face face);
8
 static void  add_mapping (struct xlfdmapping **listhead,
9
 			  char *file_name,
10
 			  const char *foundry_name,
11
@@ -684,6 +685,7 @@
12
     TT_Face face;
13
     TT_Face_Properties  properties;
14
     const char *font_name;
15
+    const char *font_psname;
16
     const char *foundry_name;
17
     const char *weight_name;
18
     const char *width_name;
19
@@ -722,6 +724,7 @@
20
     }
21
 
22
     font_name    = get_name (face);
23
+    font_psname  = get_psname (face);
24
     foundry_name = get_foundry (properties.os2->achVendID);
25
     weight_name  = get_weight (path, &properties);
26
     width_name   = get_width_name (path, &properties);
27
@@ -729,6 +732,7 @@
28
     /* basic fone information */
29
     fprintf(outstream,"TTFINFO_FONT_FILE=\"%s\"\n",path);
30
     fprintf(outstream,"TTFINFO_FONT_NAME=\"%s\"\n",font_name);
31
+    fprintf(outstream,"TTFINFO_FONT_PSNAME=\"%s\"\n",font_psname);
32
     fprintf(outstream,"TTFINFO_FOUNDRY_NAME=\"%s\"\n",foundry_name);
33
     fprintf(outstream,"TTFINFO_WEIGHT_NAME=\"%s\"\n",weight_name);
34
     fprintf(outstream,"TTFINFO_WIDTH=\"%s\"\n",width_name);
35
@@ -1206,7 +1210,7 @@
36
        function returns as soon as an english name for the font is found,
37
        so most of the time one loop is enough; however some fonts have only
38
        non-english names in their font faminly entry, so the second loop
39
-       to try the Postscript name as last ressort
40
+       to try the Postscript name as last resort
41
     */
42
     for (k = 0; k < 2; k++) {
43
 
44
@@ -1276,6 +1280,99 @@
45
 		    }
46
 	    }
47
 	}
48
+    }
49
+ 
50
+    /* Not found */
51
+    return "unknown";
52
+}
53
+
54
+/* This get_psname() function is copied from get_name().  I probably should
55
+   try to merge the two functions somehow, but unfortunately, I do not have
56
+   the time right now.  :-)  Anthony Fok <anthony@thizlinux.com>
57
+*/
58
+
59
+const char *
60
+get_psname (TT_Face face)
61
+{
62
+    int i, j, k, n;
63
+
64
+    TT_UShort  platform;
65
+    TT_UShort  encoding;
66
+    TT_UShort  language;
67
+    TT_UShort  NameId;
68
+
69
+    /* get the number of name strings in this font */
70
+    if ((n = TT_Get_Name_Count (face)) < 0) {
71
+	return NULL;
72
+    }
73
+    /* printf("\nn=%d\n",n); */
74
+
75
+    /* for (k = 0; k < 2; k++) { */
76
+
77
+    k = 1;
78
+	/* now look at every entry */
79
+	for (i = 0; i < n; i++) {
80
+	    TT_Get_Name_ID (face, i, &platform, &encoding, &language, &NameId);
81
+	    /*	    printf("k=%d, face=%d, i=%d, platform=%d, encoding=%d, lang=%d, Id=%d\n",k ,face, i, platform, encoding, language, NameId); */
82
+
83
+	    if (NameId == TT_NAME_ID_PS_NAME) {
84
+
85
+		/* Try a Macintosh english name */
86
+		if ((platform == TT_PLATFORM_MACINTOSH) && 
87
+		    (language == TT_MAC_LANGID_ENGLISH))
88
+		    {
89
+			char*  string;
90
+			TT_UShort string_len;
91
+			static char  name_buffer[257];
92
+			int   name_len;
93
+			int   english=1;
94
+
95
+			TT_Get_Name_String (face, i, &string, &string_len);
96
+			string_len =  string_len < 257 ? string_len : 257;
97
+			name_len = 0;
98
+
99
+			for (j = 0; j < string_len; j++) {
100
+			    /* some font names claim to be in english but aren't */
101
+			    if ((string[j] & 0xff) > 0x7f) english=0;
102
+			    name_buffer[name_len++] = string[j];
103
+			}
104
+
105
+			name_buffer[name_len] = '\0';
106
+			if (english) return name_buffer;
107
+		    }
108
+		/* Try to find an Apple Unicode or Microsoft English name */
109
+		if ((platform == TT_PLATFORM_APPLE_UNICODE) ||
110
+		    ((platform == TT_PLATFORM_MICROSOFT) &&
111
+		     ((language & 0x00FF) ==
112
+		      (TT_MS_LANGID_ENGLISH_UNITED_STATES & 0x00FF))) ||
113
+		    (((platform == TT_PLATFORM_MICROSOFT) &&
114
+		      (encoding == TT_MS_ID_UNICODE_CS)) &&
115
+		     (NameId == TT_NAME_ID_PS_NAME)))
116
+		    {
117
+			/* The following code was inspired from Mark Leisher's */
118
+			/* ttf2bdf package                                     */
119
+			char*  string;
120
+			TT_UShort string_len;
121
+			static char  name_buffer[513];
122
+			int   name_len;
123
+			int   english=1;
124
+
125
+			TT_Get_Name_String (face, i, &string, &string_len);
126
+			string_len =  string_len < 512 ? string_len : 512;
127
+			name_len = 0;
128
+			/* convert from unicode to ASCII */
129
+			for (j = 0; j < string_len; j ++) {
130
+			  /* drop the NULL part, dont't use j+=2 to avoid
131
+			     endian problem. */
132
+			  if (string[j] != '\0'){
133
+			    if ((string[j] & 0xff) > 0x7f) english=0;
134
+			    name_buffer[name_len++] = string[j];
135
+			  }
136
+			}
137
+			name_buffer[name_len] = '\0';
138
+			if (english) return name_buffer;
139
+		    }
140
+	    }
141
     }
142
  
143
     /* Not found */
(-)ttfm/pkg-plist (-6 lines)
Lines 2-14 Link Here
2
bin/ttfm.sh
2
bin/ttfm.sh
3
share/doc/ttfm/README
3
share/doc/ttfm/README
4
share/doc/ttfm/USAGE
4
share/doc/ttfm/USAGE
5
share/ttfm/abiword.ttfm
6
share/ttfm/chitex.ttfm.nop
7
share/ttfm/ghostscript6.ttfm.nop
8
share/ttfm/gscjk.ttfm
5
share/ttfm/gscjk.ttfm
9
share/ttfm/ttf2pk.ttfm.nop
10
share/ttfm/xttfm-tcl.ttfm.nop
11
share/ttfm/xfreetype.ttfm
12
share/ttfm/xttfm.ttfm
6
share/ttfm/xttfm.ttfm
13
@dirrm share/ttfm
7
@dirrm share/ttfm
14
@dirrm share/doc/ttfm
8
@dirrm share/doc/ttfm

Return to bug 57180