diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/cmd/postscript/trofftable |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/postscript/trofftable')
-rwxr-xr-x | sys/src/cmd/postscript/trofftable/mkfile | 42 | ||||
-rwxr-xr-x | sys/src/cmd/postscript/trofftable/trofftable.1 | 164 | ||||
-rwxr-xr-x | sys/src/cmd/postscript/trofftable/trofftable.mk | 74 | ||||
-rwxr-xr-x | sys/src/cmd/postscript/trofftable/trofftable.ps | 189 | ||||
-rwxr-xr-x | sys/src/cmd/postscript/trofftable/trofftable.rc | 123 | ||||
-rwxr-xr-x | sys/src/cmd/postscript/trofftable/trofftable.sh | 129 |
6 files changed, 721 insertions, 0 deletions
diff --git a/sys/src/cmd/postscript/trofftable/mkfile b/sys/src/cmd/postscript/trofftable/mkfile new file mode 100755 index 000000000..38f0720d0 --- /dev/null +++ b/sys/src/cmd/postscript/trofftable/mkfile @@ -0,0 +1,42 @@ +</$objtype/mkfile + +MAKE=mk +MAKEFILE=postscript.mk + +SYSTEM=plan9 +VERSION=3.3.1 + +ROOT= +FONTDIR=$ROOT/sys/lib/troff/font +MAN1DIR=$ROOT/tmp +POSTBIN=$ROOT/sys/lib/postscript/bin +POSTLIB=$ROOT/sys/lib/postscript/prologues + + +all :V: trofftable + +install :V: $POSTBIN/rc/trofftable $POSTLIB/trofftable.ps $MAN1DIR/trofftable.1 + +installall :V: install + +clean :V: + rm -f trofftable + +clobber :V: clean + +$POSTBIN/rc/trofftable : trofftable + cp $prereq $target + +$POSTLIB/trofftable.ps : trofftable.ps + cp $prereq $target + +$MAN1DIR/trofftable.1 : trofftable.1 + cp $prereq $target + +trofftable : trofftable.rc + sed \ + -e 's?^FONTDIR=.*?FONTDIR='$FONTDIR'?' \ + -e 's?^POSTBIN=.*?POSTBIN='$POSTBIN'?' \ + -e 's?^POSTLIB=.*?POSTLIB='$POSTLIB'?' \ + trofftable.rc >trofftable + chmod 775 trofftable diff --git a/sys/src/cmd/postscript/trofftable/trofftable.1 b/sys/src/cmd/postscript/trofftable/trofftable.1 new file mode 100755 index 000000000..031e2ed04 --- /dev/null +++ b/sys/src/cmd/postscript/trofftable/trofftable.1 @@ -0,0 +1,164 @@ +.ds dF /usr/lib/font +.ds dQ /usr/lib/postscript +.TH TROFFTABLE 1 "DWB 3.2" +.SH NAME +.B trofftable +\- output a PostScript program that builds a font width table +.SH SYNOPSIS +\*(mBtrofftable\f1 +.OP "" options [] +.OP "" shortname +.OP "" longname [] +.SH DESCRIPTION +.B trofftable +writes a PostScript program on the standard output that builds a +font width table or typesetter description file. +The following +.I options +are understood: +.TP 1.0i +.OP \-t name +Use +.I name +as the template for fonts not in the default set. +Choose +.MW R +for proportionally spaced fonts and +.MW CW +for fixed width fonts. +Try +.MW ZD +(ZapfDingbats) if the font has a non-standard +character set. +The default is +.MR R . +.TP 1.0i +.OP \-C file +Copy +.I file +into each PostScript table program; +.I file +must contain legitimate PostScript. +.TP 1.0i +.OP \-H hostdir +Use +.I hostdir +as the host resident font directory. +A file in +.I hostdir +that matches the name of the troff font is assumed to be a host +resident font program and is included in the PostScript width +table program. +There is no default. +.TP 1.0i +.OP \-L file +Use +.I file +as the PostScript prologue. +.br +The default is +.MW \*(dQ/trofftable.ps +.TP 1.0i +.OP \-S file +Use +.I file +as the shell library file. +Overrides the choice made with the +.OP \-T +option. +.TP 1.0i +.OP \-T name +Set the target device to +.IR name . +Device +.I name +means +.br +.MI \*(dF/dev name /shell.lib +is the shell library file. +There is no default. +.PP +One of +.OP \-T +or +.OP \-S +is required. +If both are given +.OP \-S +wins. +Either +.OP \-H +or +.OP \-C +can be used to include a host resident font. +.PP +The shell library file defines a collection of functions used to +build troff tables. +The default set of tables is the list of names returned by the +.MW AllTables +function. +Changes to the default list can be made by updating the +.MW BuiltinTables +function. +.PP +.I Shortname +is the name of the +.B troff +font and +.I longname +is the name of the PostScript font; +.I longname +can be omitted only if +.I shortname +is a default table name. +PostScript table programs created by +.B trofftable +return data to the host computer using PostScript's +.MW print +operator. +See +.BR hardcopy (1) +if you don't have access to the printer's serial port. +.SH EXAMPLES +Get the PostScript program that builds a width table for font +.MR R : +.EX +trofftable -Tpost R >R.ps +.EE +If a font is not in the default set include the +.B troff +and PostScript font names: +.EX +trofftable -TLatin1 GL Garamond-Light >GL.ps +.EE +A font must be available on the printer when the table is built. +Use +.OP \-H +or +.OP \-C +to include host resident fonts. +.SH WARNINGS +A width table will not build properly if the printer cannot access +the PostScript font. +.PP +The +.OP -TLatin1 +option only works on PostScript printers that support the full +.SM ISO +Latin-1 character set. +The error message from older printers will likely indicate a missing +.MW ISOLatin1Encoding +array. +.SH FILES +.MW \*(dF/dev*/shell.lib +.br +.MW \*(dQ/dpost.ps +.br +.MW \*(dQ/trofftable.ps +.SH SEE ALSO +.BR dpost (1), +.BR hardcopy (1), +.BR postio (1), +.BR troff (1), +.BR buildtables (1), +.BR font (5) diff --git a/sys/src/cmd/postscript/trofftable/trofftable.mk b/sys/src/cmd/postscript/trofftable/trofftable.mk new file mode 100755 index 000000000..d12b1fea5 --- /dev/null +++ b/sys/src/cmd/postscript/trofftable/trofftable.mk @@ -0,0 +1,74 @@ +MAKE=/bin/make +MAKEFILE=trofftable.mk + +SYSTEM=V9 +VERSION=3.3.2 + +GROUP=bin +OWNER=bin + +FONTDIR=/usr/lib/font +POSTBIN=/usr/bin/postscript +POSTLIB=/usr/lib/postscript +MAN1DIR=/tmp + +all : trofftable + +install : all + @if [ ! -d $(POSTBIN) ]; then \ + mkdir $(POSTBIN); \ + chmod 755 $(POSTBIN); \ + chgrp $(GROUP) $(POSTBIN); \ + chown $(OWNER) $(POSTBIN); \ + fi + @if [ ! -d "$(POSTLIB)" ]; then \ + mkdir $(POSTLIB); \ + chmod 755 $(POSTLIB); \ + chgrp $(GROUP) $(POSTLIB); \ + chown $(OWNER) $(POSTLIB); \ + fi + cp trofftable $(POSTBIN)/trofftable + @chmod 755 $(POSTBIN)/trofftable + @chgrp $(GROUP) $(POSTBIN)/trofftable + @chown $(OWNER) $(POSTBIN)/trofftable + cp trofftable.ps $(POSTLIB)/trofftable.ps + @chmod 644 $(POSTLIB)/trofftable.ps + @chgrp $(GROUP) $(POSTLIB)/trofftable.ps + @chown $(OWNER) $(POSTLIB)/trofftable.ps + cp trofftable.1 $(MAN1DIR)/trofftable.1 + @chmod 644 $(MAN1DIR)/trofftable.1 + @chgrp $(GROUP) $(MAN1DIR)/trofftable.1 + @chown $(OWNER) $(MAN1DIR)/trofftable.1 + +clean : + +clobber : clean + rm -f trofftable + +trofftable : trofftable.sh + sed \ + -e "s'^FONTDIR=.*'FONTDIR=$(FONTDIR)'" \ + -e "s'^POSTBIN=.*'POSTBIN=$(POSTBIN)'" \ + -e "s'^POSTLIB=.*'POSTLIB=$(POSTLIB)'" \ + trofftable.sh >trofftable + @chmod 755 trofftable + +changes : + @trap "" 1 2 3 15; \ + sed \ + -e "s'^SYSTEM=.*'SYSTEM=$(SYSTEM)'" \ + -e "s'^VERSION=.*'VERSION=$(VERSION)'" \ + -e "s'^GROUP=.*'GROUP=$(GROUP)'" \ + -e "s'^OWNER=.*'OWNER=$(OWNER)'" \ + -e "s'^FONTDIR=.*'FONTDIR=$(FONTDIR)'" \ + -e "s'^POSTBIN=.*'POSTBIN=$(POSTBIN)'" \ + -e "s'^POSTLIB=.*'POSTLIB=$(POSTLIB)'" \ + -e "s'^MAN1DIR=.*'MAN1DIR=$(MAN1DIR)'" \ + $(MAKEFILE) >XXX.mk; \ + mv XXX.mk $(MAKEFILE); \ + sed \ + -e "s'^.ds dF.*'.ds dF $(FONTDIR)'" \ + -e "s'^.ds dQ.*'.ds dQ $(POSTLIB)'" \ + trofftable.1 >XXX.1; \ + mv XXX.1 trofftable.1 + diff --git a/sys/src/cmd/postscript/trofftable/trofftable.ps b/sys/src/cmd/postscript/trofftable/trofftable.ps new file mode 100755 index 000000000..dcc23200c --- /dev/null +++ b/sys/src/cmd/postscript/trofftable/trofftable.ps @@ -0,0 +1,189 @@ +% +% Prologue for building troff width tables. The gsave/grestore pairs are +% for hardcopy. +% + +/slowdown 25 def +/flagduplicates false def + +/ascenderheight -1 def +/descenderdepth 0 def +/octalescapes 256 def +/startcomments 256 def +/currentfontdict null def +/scratchstring 512 string def + +/Print { + scratchstring cvs print flush + slowdown {1 pop} repeat +} def + +/ReEncode { % vector fontname ReEncode - + dup + findfont dup length dict begin + {1 index /FID ne {def}{pop pop} ifelse} forall + /Encoding 3 -1 roll def + currentdict + end + definefont pop +} bind def + +/SelectFont { % fontname SelectFont - + findfont + dup /PaintType get 0 eq { + /scaling 1 def + unitwidth resolution 72.0 div mul + }{ + /scaling resolution 72 div def + unitwidth + } ifelse + scalefont + /currentfontdict exch def +} def + +/ChangeMetrics {DpostPrologue begin addmetrics end} def + +/NamedInPrologue { + dup + DpostPrologue exch known { + DpostPrologue exch get type /nametype eq { + (named in prologue\n) Print + } if + }{pop} ifelse +} def + +/SetAscender { + /str exch def + + gsave + currentfontdict setfont + newpath + 0 0 moveto + str false charpath flattenpath pathbbox + /descenderdepth 4 -1 roll .5 mul def + exch pop exch pop + + newpath + 0 0 moveto + str 0 1 getinterval false charpath flattenpath pathbbox + 4 1 roll pop pop pop + dup 3 1 roll sub .25 mul add + /ascenderheight exch def + grestore +} def + +/GetAscender { + ascenderheight descenderdepth ge { + gsave + currentfontdict setfont + newpath + 0 0 moveto + ( ) dup 0 4 -1 roll put + false charpath flattenpath pathbbox + exch pop 3 -1 roll pop + ascenderheight gt {2}{0} ifelse + exch descenderdepth lt {1}{0} ifelse + or + grestore + }{0} ifelse +} def + +/GetWidth { + gsave + currentfontdict setfont + ( ) dup 0 4 -1 roll put + stringwidth pop scaling mul round cvi + grestore +} def + +/GetCode { + 256 3 1 roll % last unprintable match + 0 3 -1 roll { + 2 index eq { + dup 127 and 32 ge {exit} if + 3 -1 roll pop + dup 3 1 roll + } if + 1 add + } forall + exch pop + dup 255 gt {pop}{exch pop} ifelse +} def + +/BuildFontCharset { + 0 2 charset length 2 sub { + /i exch def + /chcode -1 def + /chname null def + /key charset i get def + /val charset i 1 add get def + + val type /integertype eq { + /chcode val def + /chname currentfontdict /Encoding get chcode get def + } if + + val type /nametype eq { + /chname val def + /chcode currentfontdict /Encoding get chname GetCode def + } if + + val type /stringtype eq {/chcode 0 def} if + + chcode 0 lt chcode 255 gt or { + chcode 0 lt {(syntaxerror: )}{(undefinedname: )} ifelse + Print key Print (\t) Print val Print (\n) Print + quit + } if + + val type /stringtype eq { + key Print + (\t) Print val Print + (\n) Print + }{ + chcode octalescapes ge key (---) eq and { + (\\0) Print chcode 8 ( ) cvrs Print + }{key Print} ifelse + (\t) Print chcode GetWidth Print + (\t) Print chcode GetAscender Print + (\t) Print chcode Print + chcode startcomments ge { + (\t# ) Print chname Print + } if + (\n) Print + chcode octalescapes ge (---) key ne and { + key (\\0) anchorsearch not { + pop + (\\0) Print chcode 8 ( ) cvrs Print + (\t"\n) Print + }{pop pop} ifelse + } if + } ifelse + } for +} def + +/BuildDescCharset { + /DescDict 512 dict def + /Characters 0 def + + 0 1 charset length 1 sub { + /i exch def + /key charset i get def + + key length 2 eq { + DescDict key cvn known { + flagduplicates { % for debugging + (<<<duplicated character: ) Print + key Print + (>>>\n) Print + } if + }{ + DescDict key cvn 1 put + key Print + /Characters Characters 1 add def + Characters 20 mod 0 eq {(\n)}{( )} ifelse Print + } ifelse + } if + } for +} def + diff --git a/sys/src/cmd/postscript/trofftable/trofftable.rc b/sys/src/cmd/postscript/trofftable/trofftable.rc new file mode 100755 index 000000000..47c56b5bd --- /dev/null +++ b/sys/src/cmd/postscript/trofftable/trofftable.rc @@ -0,0 +1,123 @@ +#!/bin/rc +# Writes a PostScript program on standard output that builds a width +# table or typesetter description file. The program uses PostScript's +# print procedure, which means the table comes back on the printer's +# serial port. Try hardcopy if you don't have access to the port. +# + +POSTLIB=/sys/lib/postscript/prologues +FONTDIR=/sys/lib/troff/font + +PROLOGUE=$POSTLIB/trofftable.ps +DPOSTPROLOGUE=$POSTLIB/dpost.ps + +COPYFILE=() +HOSTFONTDIR=() +DEVICE=() +LIBRARY=() +TEMPLATE=-R + +SLOWDOWN=25 +STARTCOMMENTS=256 + +NONCONFORMING='%!PS' +ENDPROLOG='%%EndProlog' +BEGINSETUP='%%BeginSetup' +ENDSETUP='%%EndSetup' +TRAILER='%%Trailer' + +while (! ~ $#* 0 && ~ $1 -*) { + switch ($1) { + case -C; shift; COPYFILE=$COPYFILE' '$1 + case -C*; COPYFILE=$COPYFILE' '`{echo $1 | sed s/-C//} + + case -F; shift; FONTDIR=$1 + case -F*; FONTDIR=`{echo $1 | sed s/-F//} + + case -H; shift; HOSTFONTDIR=$1 + case -H*; HOSTFONTDIR=`{echo $1 | sed s/-H//} + + case -L; shift; PROLOGUE=$1 + case -L*; PROLOGUE=`{echo $1 | sed s/-L//} + + case -S; shift; LIBRARY=$1 + case -S*; LIBRARY=`{echo $1 | sed s/-S//} + + case -T; shift; DEVICE=$1 + case -T*; DEVICE=`{echo $1 | sed s/-T//} + + case -c; shift; STARTCOMMENTS=$1 + case -c*; STARTCOMMENTS=`{echo $1 | sed s/-c//} + + case -o; shift; OCTALESCAPES=$1 # only for Latin1 tables + case -o*; OCTALESCAPES=`{echo $1 | sed s/-o//} + + case -s; shift; SLOWDOWN=$1 + case -s*; SLOWDOWN=`{echo $1 | sed s/-s//} + + case -t; shift; TEMPLATE=$1 + case -t*; TEMPLATE=`{echo $1 | sed s/-t//} + + case -*; echo $0: illegal option $1 >[1=2]; exit 1 + } + shift +} + +if (! ~ $#DEVICE 0 && ! ~ $#LIBRARY 0) { + echo $0: no device or shell library >[1=2] + exit 1 +} + +if (! ~ $#* 1 2) { + echo $0: bad argument count >[1=2] + exit 1 +} + +if (test -d $HOSTFONTDIR -a -f $HOSTFONTDIR/$1) { + COPYFILE=$COPYFILE' '$HOSTFONTDIR/$1 +} + +# +# Include the shell library and get the command used to build the table. +# Make awk call a separate library function?? +# +if (~ $#LIBRARY 0 || ~ $LIBRARY '') LIBRARY=$FONTDIR/dev$DEVICE/shell.lib + +. $LIBRARY + +if (~ $#* 1) TEMPLATE=$1 + +CMD=`{BuiltinTables | awk '$2 == template"" { + if ( pname == "" ) + pname = $3 + printf "%s %s %s", $1, tname, pname + exit 0 +}' template=$TEMPLATE tname=$1 pname=$2} + +if (! $CMD) { + echo $0: $TEMPLATE not found >[1=2] + exit 1 +} + +# +# Build the PostScript font table program. +# + +echo $NONCONFORMING +cat $PROLOGUE +echo /DpostPrologue 100 dict dup begin +cat $DPOSTPROLOGUE +echo end def +echo $ENDPROLOG + +echo $BEGINSETUP +if (~ $COPYFILE '') COPYFILE=/dev/null +cat $COPYFILE +echo /slowdown $SLOWDOWN def +echo /startcomments $STARTCOMMENTS def +echo $ENDSETUP + +$CMD + +echo $TRAILER + diff --git a/sys/src/cmd/postscript/trofftable/trofftable.sh b/sys/src/cmd/postscript/trofftable/trofftable.sh new file mode 100755 index 000000000..528bb8f84 --- /dev/null +++ b/sys/src/cmd/postscript/trofftable/trofftable.sh @@ -0,0 +1,129 @@ +#!/bin/sh + +# +# Writes a PostScript program on standard output that builds a width +# table or typesetter description file. The program uses PostScript's +# print procedure, which means the table comes back on the printer's +# serial port. Try hardcopy if you don't have access to the port. +# + +POSTBIN=/usr/lbin/postscript +POSTLIB=/usr/lib/postscript +FONTDIR=/usr/lib/font + +PROLOGUE=$POSTLIB/trofftable.ps +DPOSTPROLOGUE=$POSTLIB/dpost.ps + +COPYFILE= +HOSTFONTDIR= +DEVICE= +LIBRARY= +TEMPLATE= + +SLOWDOWN=25 +STARTCOMMENTS=256 + +NONCONFORMING="%!PS" +ENDPROLOG="%%EndProlog" +BEGINSETUP="%%BeginSetup" +ENDSETUP="%%EndSetup" +TRAILER="%%Trailer" + +while [ -n "$1" ]; do + case $1 in + -C) shift; COPYFILE="$COPYFILE $1";; + -C*) COPYFILE="$COPYFILE `echo $1 | sed s/-C//`";; + + -F) shift; FONTDIR=$1;; + -F*) FONTDIR=`echo $1 | sed s/-F//`;; + + -H) shift; HOSTFONTDIR=$1;; + -H*) HOSTFONTDIR=`echo $1 | sed s/-H//`;; + + -L) shift; PROLOGUE=$1;; + -L*) PROLOGUE=`echo $1 | sed s/-L//`;; + + -S) shift; LIBRARY=$1;; + -S*) LIBRARY=`echo $1 | sed s/-S//`;; + + -T) shift; DEVICE=$1;; + -T*) DEVICE=`echo $1 | sed s/-T//`;; + + -c) shift; STARTCOMMENTS=$1;; + -c*) STARTCOMMENTS=`echo $1 | sed s/-c//`;; + + -o) shift; OCTALESCAPES=$1;; # only for Latin1 tables + -o*) OCTALESCAPES=`echo $1 | sed s/-o//`;; + + -s) shift; SLOWDOWN=$1;; + -s*) SLOWDOWN=`echo $1 | sed s/-s//`;; + + -t) shift; TEMPLATE=$1;; + -t*) TEMPLATE=`echo $1 | sed s/-t//`;; + + -*) echo "$0: illegal option $1" >&2; exit 1;; + + *) break;; + esac + shift +done + +if [ ! "$DEVICE" -a ! "$LIBRARY" ]; then + echo "$0: no device or shell library" >&2 + exit 1 +fi + +if [ $# -ne 1 -a $# -ne 2 ]; then + echo "$0: bad argument count" >&2 + exit 1 +fi + +if [ -d "$HOSTFONTDIR" -a -f "$HOSTFONTDIR/$1" ]; then + COPYFILE="$COPYFILE $HOSTFONTDIR/$1" +fi + +# +# Include the shell library and get the command used to build the table. +# Make awk call a separate library function?? +# + +. ${LIBRARY:-${FONTDIR}/dev${DEVICE}/shell.lib} + +if [ $# -eq 1 ] + then TEMPLATE=$1 + else TEMPLATE=${TEMPLATE:-R} +fi + +CMD=`BuiltinTables | awk '$2 == template"" { + if ( pname == "" ) + pname = $3 + printf "%s %s %s", $1, tname, pname + exit 0 +}' template="$TEMPLATE" tname="$1" pname="$2"` + +if [ ! "$CMD" ]; then + echo "$0: $TEMPLATE not found" >&2 + exit 1 +fi + +# +# Build the PostScript font table program. +# + +echo $NONCONFORMING +cat $PROLOGUE +echo "/DpostPrologue 100 dict dup begin" +cat $DPOSTPROLOGUE +echo "end def" +echo $ENDPROLOG + +echo $BEGINSETUP +cat ${COPYFILE:-/dev/null} +echo "/slowdown $SLOWDOWN def" +echo "/startcomments $STARTCOMMENTS def" +echo $ENDSETUP + +$CMD + +echo $TRAILER + |