aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/postscript/printfont
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/postscript/printfont')
-rw-r--r--src/cmd/postscript/printfont/mkfile22
-rw-r--r--src/cmd/postscript/printfont/printfont.ps321
-rw-r--r--src/cmd/postscript/printfont/printfont.rc105
3 files changed, 448 insertions, 0 deletions
diff --git a/src/cmd/postscript/printfont/mkfile b/src/cmd/postscript/printfont/mkfile
new file mode 100644
index 00000000..8ddadb25
--- /dev/null
+++ b/src/cmd/postscript/printfont/mkfile
@@ -0,0 +1,22 @@
+</$objtype/mkfile
+
+<../config
+
+POSTBIN=/rc/bin
+
+all:V: printfont
+
+install installall:V: $POSTBIN/printfont $POSTLIB/printfont.ps
+
+clean nuke:V:
+ rm -f printfont
+
+$POSTBIN/printfont: printfont
+ cp $prereq $target
+
+$POSTLIB/printfont.ps: printfont.ps
+ cp $prereq $target
+
+printfont: printfont.rc
+ sed 's?^POSTLIB=.*?POSTLIB='$POSTLIB'?' printfont.rc >printfont
+ chmod 775 printfont
diff --git a/src/cmd/postscript/printfont/printfont.ps b/src/cmd/postscript/printfont/printfont.ps
new file mode 100644
index 00000000..7a881a4d
--- /dev/null
+++ b/src/cmd/postscript/printfont/printfont.ps
@@ -0,0 +1,321 @@
+%
+% Formatted font dump. Assumes all fonts include valid FontBBox arrays.
+%
+
+/#copies 1 store
+/aspectratio 1 def
+/landscape false def
+/magnification 1 def
+/margin 10 def
+/orientation 0 def
+/rotation 1 def
+/xoffset 0 def
+/yoffset 0 def
+
+/axescount 0 def
+/charwidth false def
+/graynotdef 0.85 def
+/hireslinewidth 0.2 def
+/longnames false def
+/maxsize 6.0 def
+/minsize 4.5 def
+/numbercell true def
+/radix 16 def
+/labelfont /Helvetica def
+/labelspace 36 def
+/zerocell 0 def
+
+/roundpage true def
+/useclippath true def
+/pagebbox [0 0 612 792] def
+
+/inch {72 mul} def
+/min {2 copy gt {exch} if pop} def
+/max {2 copy lt {exch} if pop} def
+
+/LLx {0 get} bind def
+/LLy {1 get} bind def
+/URx {2 get} bind def
+/URy {3 get} bind def
+/BBoxHeight {dup URy exch LLy sub} bind def
+/BBoxWidth {dup URx exch LLx sub} bind def
+
+/setup {
+ /graylevels [1 0 0] def
+ /scratchstring 512 string def
+ /Product statusdict begin /product where {pop product}{(Unknown)} ifelse end def
+ /Resolution 0 72 dtransform dup mul exch dup mul add sqrt cvi def
+ /Version /version where {pop version}{(???)} ifelse def
+
+ landscape {/orientation 90 orientation add def} if
+
+ pagedimensions
+ xcenter ycenter translate
+ orientation rotation mul rotate
+ width 2 div neg height 2 div translate
+ xoffset inch yoffset inch neg translate
+ margin dup neg translate
+ 0 labelspace .75 mul neg translate
+ magnification dup aspectratio mul scale
+ 0 0 transform round exch round exch itransform translate
+
+ currentdict /linewidth known not {
+ /linewidth Resolution 400 le {0}{hireslinewidth} ifelse def
+ } if
+} def
+
+/pagedimensions {
+ useclippath {
+ /pagebbox [clippath pathbbox newpath] def
+ roundpage currentdict /roundpagebbox known and {roundpagebbox} if
+ } if
+ pagebbox aload pop
+ 4 -1 roll exch 4 1 roll 4 copy
+ landscape {4 2 roll} if
+ sub /width exch def
+ sub /height exch def
+ add 2 div /xcenter exch def
+ add 2 div /ycenter exch def
+} def
+
+/CharSetup {
+ /chcode exch def
+ /chname Encoding chcode get def
+ /chstring ( ) dup 0 chcode put def
+ /chknown true def
+
+ graylevels 0 1 put % initial cell fill
+ graylevels 1 0 put % cell text
+ graylevels 2 0 put % cell border
+
+ FontDict /CharStrings known {
+ FontDict /CharStrings get chname known not {
+ /chknown false def
+ graylevels 0 0 put
+ graylevels 1 1 put
+ } if
+ } if
+
+ chname /.notdef eq {
+ /chknown false def
+ graylevels 0 graynotdef put
+ graylevels 1 graynotdef put
+ } if
+
+ /chwid chknown
+ {FontDict 1 scalefont setfont chstring stringwidth pop}
+ {0}
+ ifelse def
+} bind def
+
+/CellSetup {
+ /gridwidth width margin 2 mul sub def
+ /gridheight height labelspace sub margin 2 mul sub def
+ /cellwidth gridwidth radix div def
+ /cellheight gridheight Entries radix div ceiling div def
+
+ cellwidth cellheight dtransform truncate exch truncate exch idtransform
+ /cellheight exch def
+ /cellwidth exch def
+
+ labelfont findfont 1 scalefont setfont
+ /LabelBBox currentfont /FontBBox get TransformBBox def
+
+ LabelBBox 2 0 Encoding {
+ scratchstring cvs stringwidth pop
+ 2 copy lt {exch} if
+ pop
+ } forall put
+
+ /CellLabelSize
+ cellheight .20 mul cellwidth .90 mul LabelBBox BestFit
+ minsize max
+ maxsize min
+ def
+ zerocell CellOrigin cellheight add neg exch neg exch translate
+} bind def
+
+/FontSetup {
+ FontName findfont 1 scalefont setfont
+ /BBox currentfont /FontBBox get TransformBBox def
+ /PointSize cellheight .5 mul cellwidth .8 mul BBox BestFit def
+ BBox {PointSize mul} forall BBox astore pop
+
+ /xorigin cellwidth BBox BBoxWidth sub 2 div BBox LLx sub def
+ /yorigin cellheight BBox BBoxHeight sub 2 div BBox LLy sub def
+} bind def
+
+/BestFit {
+ /bbox exch def
+ bbox BBoxWidth div exch
+ bbox BBoxHeight div min
+} bind def
+
+/TransformBBox { % font bbox to user space
+ aload pop
+ currentfont /FontMatrix get dtransform 4 2 roll
+ currentfont /FontMatrix get dtransform 4 2 roll
+ 4 array astore % should build user space bbox if all zeros
+} bind def
+
+/CellOrigin {
+ dup
+ exch radix mod cellwidth mul
+ exch radix idiv 1 add neg cellheight mul
+} bind def
+
+/CellOutline {
+ newpath
+ CellOrigin moveto
+ cellwidth 0 rlineto
+ 0 cellheight rlineto
+ cellwidth neg 0 rlineto
+ closepath
+} bind def
+
+/LabelCell {
+ gsave
+ chcode CellOrigin translate
+ linewidth .5 mul setlinewidth
+ labelfont findfont CellLabelSize scalefont setfont
+
+ numbercell {
+ cellwidth .025 mul cellheight .05 mul moveto
+ chcode radix scratchstring cvrs show
+ } if
+
+ charwidth chknown and {
+ /wid chwid 0.0005 add scratchstring cvs 0 5 getinterval def
+ cellwidth wid stringwidth pop 1.10 mul sub cellheight .05 mul moveto
+ wid show
+ } if
+
+ longnames chknown not or {
+ cellwidth .025 mul
+ cellheight LabelBBox URy CellLabelSize mul sub .05 sub moveto
+ Encoding chcode get scratchstring cvs show
+ } if
+
+ axescount 1 ge chknown and { % gsave/grestore if not last
+ newpath
+ xorigin yorigin translate
+
+ BBox LLx 0 moveto % baseline
+ BBox URx 0 lineto stroke
+
+ axescount 2 ge { % vertical through current origin
+ 0 BBox LLy moveto
+ 0 BBox URy lineto stroke
+ } if
+
+ axescount 3 ge { % vertical through next origin
+ chwid PointSize mul BBox LLy
+ dtransform round exch round exch idtransform moveto
+ 0 BBox BBoxHeight rlineto stroke
+ %chwid PointSize mul BBox URy lineto stroke
+ } if
+ } if
+ grestore
+} bind def
+
+/PlaceChar {
+ FontName findfont PointSize scalefont setfont
+ chcode CellOrigin moveto
+ xorigin yorigin rmoveto
+ ( ) dup 0 chcode put show
+} bind def
+
+/LabelPage {
+ labelfont findfont labelspace .75 mul .75 mul 18 min scalefont setfont
+ 0 labelspace .75 mul .25 mul moveto
+ FontName scratchstring cvs show
+
+ labelfont findfont labelspace .25 mul .75 mul 9 min scalefont setfont
+ 0 gridheight neg moveto
+ 0 labelspace .25 mul .75 mul neg rmoveto
+ Product show ( Version ) show Version show
+ ( \() show Resolution scratchstring cvs show (dpi\)) show
+
+ gridwidth gridheight neg moveto
+ 0 labelspace .25 mul .75 mul neg rmoveto
+ (size=, ) stringwidth pop neg 0 rmoveto
+ PointSize cvi scratchstring cvs stringwidth pop neg 0 rmoveto
+ (gray=, ) stringwidth pop neg 0 rmoveto
+ graynotdef scratchstring cvs stringwidth pop neg 0 rmoveto
+ (linewidth=) stringwidth pop neg 0 rmoveto
+ linewidth scratchstring cvs stringwidth pop neg 0 rmoveto
+ (size=) show PointSize cvi scratchstring cvs show (, ) show
+ (gray=) show graynotdef scratchstring cvs show (, ) show
+ (linewidth=) show linewidth scratchstring cvs show
+} bind def
+
+%
+% Formatted dump of the encoded characters in a single font.
+%
+
+/PrintFont {
+ /saveobj save def
+ /FontName exch def
+ /FontDict FontName findfont def
+ /Encoding FontDict /Encoding get def
+ /Entries Encoding length def
+
+ CellSetup
+ FontSetup
+ LabelPage
+ zerocell 1 Entries 1 sub {
+ CharSetup
+ graylevels 0 get setgray
+ chcode CellOutline fill
+ graylevels 1 get setgray
+ LabelCell
+ PlaceChar
+ graylevels 2 get setgray
+ linewidth setlinewidth
+ chcode CellOutline stroke
+ } for
+ showpage
+ saveobj restore
+} bind def
+
+%
+% Dump of all ROM and disk fonts - in alphabetical order.
+%
+
+/AllFonts {
+ /AllFontNames FontDirectory maxlength array def
+ AllFontNames 0 0 put
+
+ FontDirectory {pop AllFontNames Insert} forall
+
+ /filenameforall where {
+ pop
+ (fonts/*)
+ {(fonts/) search pop pop pop AllFontNames Insert}
+ 200 string
+ filenameforall
+ } if
+
+ 1 1 AllFontNames 0 get {
+ AllFontNames exch get cvn PrintFont
+ } for
+} bind def
+
+/Insert { % name in a sorted list
+ /List exch def
+ /Name exch 128 string cvs def
+
+ /Slot 1 def
+ List 0 get {
+ Name List Slot get le {exit} if
+ /Slot Slot 1 add def
+ } repeat
+
+ List 0 get -1 Slot {
+ dup List exch get
+ List 3 1 roll exch 1 add exch put
+ } for
+ List Slot Name put
+ List 0 List 0 get 1 add put
+} bind def
+
diff --git a/src/cmd/postscript/printfont/printfont.rc b/src/cmd/postscript/printfont/printfont.rc
new file mode 100644
index 00000000..266102f9
--- /dev/null
+++ b/src/cmd/postscript/printfont/printfont.rc
@@ -0,0 +1,105 @@
+#!/bin/rc
+# Formatted dump of encoded characters in one or more PostScript fonts.
+# Arguments should be PostScript font names or the word all, which dumps
+# all ROM and disk based fonts.
+#
+
+POSTLIB=/sys/lib/postscript/prologues
+PROLOGUE=$POSTLIB/printfont.ps
+
+OPTIONS=''
+COPYFILE=''
+MODE=portrait
+FONTENCODING=Default
+
+NONCONFORMING='%!PS'
+ENDPROLOG='%%EndProlog'
+BEGINSETUP='%%BeginSetup'
+ENDSETUP='%%EndSetup'
+TRAILER='%%Trailer'
+
+SETUP=setup
+
+while (! ~ $#* 0 && ~ $1 -*) {
+ switch ($1) {
+ case -a; shift; OPTIONS=$OPTIONS' /axescount $1 def'
+ case -a*; OPTIONS=$OPTIONS' /axescount '`{echo $1 | sed s/-a//}' def'
+
+ case -b; shift; OPTIONS=$OPTIONS' /radix '$1' def'
+ case -b*; OPTIONS=$OPTIONS' /radix '`{echo $1 | sed s/-b//}' def'
+
+ case -c; shift; OPTIONS=$OPTIONS' /#copies '$1' store'
+ case -c*; OPTIONS=$OPTIONS' /#copies '`{echo $1 | sed s/-c//}' store'
+
+ case -f; shift; OPTIONS=$OPTIONS' /labelfont /'$1' def'
+ case -f*; OPTIONS=$OPTIONS' /labelfont /'`{echo $1 | sed s/-f//}' def'
+
+ case -g; shift; OPTIONS=$OPTIONS' /graynotdef '$1' def'
+ case -g*; OPTIONS=$OPTIONS' /graynotdef '`{echo $1 | sed s/-g//}' def'
+
+ case -p; shift; MODE=$1
+ case -p*; MODE=`{echo $1 | sed s/-p//}
+
+ case -q; OPTIONS=$OPTIONS' /longnames false def /charwidth false def'
+
+ case -m; shift; OPTIONS=$OPTIONS' /magnification '$1' def'
+ case -m*; OPTIONS=$OPTIONS' /magnification '`{echo $1 | sed s/-m//}' def'
+
+ case -v; OPTIONS=$OPTIONS' /longnames true def /charwidth true def'
+
+ case -w; shift; OPTIONS=$OPTIONS' /linewidth '$1' def'
+ case -w*; OPTIONS=$OPTIONS' /linewidth '`{echo $1 | sed s/-w//}' def'
+
+ case -x; shift; OPTIONS=$OPTIONS' /xoffset '$1' def'
+ case -x*; OPTIONS=$OPTIONS' /xoffset '`{echo $1 | sed s/-x//}' def'
+
+ case -y; shift; OPTIONS=$OPTIONS' /yoffset '$1' def'
+ case -y*; OPTIONS=$OPTIONS' /yoffset '`{echo $1 | sed s/-y//}' def'
+
+ case -z; shift; OPTIONS=$OPTIONS' /zerocell '$1' def'
+ case -z*; OPTIONS=$OPTIONS' /zerocell '`{echo $1 | sed s/-z//}' def'
+
+ case -C; shift; COPYFILE=$COPYFILE' '$1
+ case -C*; COPYFILE=$COPYFILE' '`{echo $1 | sed s/-C//}
+
+ case -E; shift; FONTENCODING=$1
+ case -E*; FONTENCODING=`{echo $1 | sed s/-E//}
+
+ case -L; shift; PROLOGUE=$1
+ case -L*; PROLOGUE=`{echo $1 | sed s/-L//}
+
+ case -*; echo $0:' illegal option '$1 >[1=2]; exit 1
+ }
+ shift
+}
+
+switch ($MODE) {
+case l*; OPTIONS=$OPTIONS' /landscape true def'
+case *; OPTIONS=$OPTIONS' /landscape false def'
+}
+
+echo $NONCONFORMING
+cat $PROLOGUE
+echo $ENDPROLOG
+echo $BEGINSETUP
+if (~ $#COPYFILE 0 || ~ $COPYFILE '') COPYFILE=/dev/null
+cat $COPYFILE
+echo $OPTIONS
+
+switch ($FONTENCODING) {
+case /*; cat $FONTENCODING
+case ?*; cat $POSTLIB^/$FONTENCODING^.enc >[2]/dev/null
+}
+
+echo $SETUP
+echo $ENDSETUP
+
+for (i) {
+ switch ($i) {
+ case all; echo AllFonts
+ case /*; echo $i' PrintFont'
+ case ?*; echo /$i' PrintFont'
+ }
+}
+
+echo $TRAILER