DVIDOC for Pyramid OSx (Part 1 of 2)

Scott Simpson simpson at trwrb.UUCP
Thu Sep 11 05:12:32 AEST 1986


    Here is a copy of the DVIDOC program posted by Clayton Elwell 
(elwell at osu-eddie) of Ohio State University.  This version runs on
Pyramid OSx using the Pyramid pascal compiler.  The previous
posted version did not run under OSx (it did not even weave
or compile).  Also, the old doc.pl file was outdated.  I have also
created a Makefile and man page for the program.  I do not expect
this version to run under the 4.2 pc compiler although I have not
tried it.
    The file seek algorithm is horrible and causes the program to run
very slow on large DVI files.  In fact, if you looked up horrible in the
dictionary you would probably see a picture of my seek code there.
    You will need to modify the pathnames in the files appropriately.
Also, this file is one big shar file posted in two parts so you will
have to cat them together and then unshar them.  The dvidoc.web file
was over 66K bytes so posting it individually still could have caused
problems.
		Scott Simpson
		TRW Electronics and Defense Sector
		...{decvax,ihnp4,ucbvax}!trwrb!simpson
#! /bin/sh
# To extract, remove mail header lines and type "sh filename"
if [ ! -d dvidoc ]
then
	mkdir dvidoc
	echo mkdir dvidoc
fi
echo x - dvidoc/Makefile
sed -e 's/^X//' > dvidoc/Makefile << '!FaR!OuT!'
XDEST=/usr/local/bin
XLIB=/usr/local/lib/tex/fonts
XMACROS=/usr/local/lib/tex/macros
XPC=pascal
XPFLAGS=-O
XLDFLAGS=-s
X
X.SUFFIXES: .web .o .dvi .pl .tfm
X.web.o:
X	tangle $<
X	$(PC) -c $(PFLAGS) $*.p
X	rm $*.p
X.web.dvi:
X	weave $<
X	tex $*.tex
X	rm $*.tex
X.pl.tfm:
X	pltotf $< $*.tfm
X
Xall: dvidoc doc.tfm dvidoc.dvi
X
Xdvidoc: dvidoc.o dvityext.o
X	$(PC) -o $@ $(LDFLAGS) dvidoc.o dvityext.o
X
Xinstall: all
X	install -m 644 doc.tfm $(LIB)
X	install -m 755 dvidoc $(DEST)
X	install -m 644 -c docmac.tex $(MACROS)
X
Xclean:
X	-rm -f *.o dvidoc.p dvidoc dvidoc.log dvidoc.tex dvidoc.pool \
X	CONTENTS.tex dvidoc.dvi doc.tfm
X
!FaR!OuT!
if [ ! -d dvidoc ]
then
	mkdir dvidoc
	echo mkdir dvidoc
fi
echo x - dvidoc/doc.pl
sed -e 's/^X//' > dvidoc/doc.pl << '!FaR!OuT!'
X(COMMENT OSU DOC file font)
X(COMMENT Derived from amtt)
X(CODINGSCHEME TEX TYPEWRITER TEXT)
X(DESIGNSIZE R 13.76574)
X(COMMENT DESIGNSIZE IS IN POINTS)
X(COMMENT OTHER SIZES ARE MULTIPLES OF DESIGNSIZE)
X(CHECKSUM O 10653670734)
X(SEVENBITSAFEFLAG TRUE)
X(FONTDIMEN
X   (SLANT R 0.0)
X   (SPACE R 0.5249996)
X   (STRETCH R 1.049999)
X   (SHRINK R 0.0)
X   (XHEIGHT R 0.4305553)
X   (QUAD R 0.5249996)
X   (EXTRASPACE R 0.5249996)
X   )
X(LIGTABLE
X   (LABEL O 47)
X   (LIG O 47 O 42)
X   (STOP)
X   (LABEL O 140)
X   (LIG O 140 O 42)
X   (STOP)
X   )
X(CHARACTER O 41
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER O 42
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER O 43
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER O 44
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER O 45
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER O 46
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER O 47
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER O 50
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER O 51
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER O 52
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.5208330)
X   )
X(CHARACTER O 53
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.5097217)
X   )
X(CHARACTER O 54
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.1000003)
X   (CHARDP R 0.1111106)
X   )
X(CHARACTER O 55
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.5097217)
X   )
X(CHARACTER O 56
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.1000003)
X   )
X(CHARACTER O 57
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER C 0
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C 1
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C 2
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C 3
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C 4
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C 5
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C 6
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C 7
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C 8
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C 9
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER O 72
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER O 73
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   (CHARDP R 0.1111106)
X   )
X(CHARACTER O 74
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.5555553)
X   )
X(CHARACTER O 75
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4156246)
X   )
X(CHARACTER O 76
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.5555553)
X   )
X(CHARACTER O 77
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER O 100
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C A
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C B
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C C
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C D
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C E
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C F
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C G
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C H
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C I
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C J
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C K
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C L
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C M
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C N
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C O
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C P
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C Q
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   (CHARDP R 0.1111106)
X   )
X(CHARACTER C R
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C S
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C T
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C U
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C V
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C W
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C X
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C Y
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C Z
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER O 133
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER O 134
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER O 135
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER O 136
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER O 137
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.5381946)
X   )
X(CHARACTER O 140
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C a
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C b
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C c
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C d
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C e
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C f
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C g
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   (CHARDP R 0.2222223)
X   )
X(CHARACTER C h
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C i
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C j
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   (CHARDP R 0.2222223)
X   )
X(CHARACTER C k
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C l
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
X(CHARACTER C m
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C n
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C o
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C p
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   (CHARDP R 0.2222223)
X   )
X(CHARACTER C q
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   (CHARDP R 0.2222223)
X   )
X(CHARACTER C r
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C s
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C t
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.5659723)
X   )
X(CHARACTER C u
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C v
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C w
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C x
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER C y
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   (CHARDP R 0.2222223)
X   )
X(CHARACTER C z
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.4305553)
X   )
X(CHARACTER O 173
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER O 174
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER O 175
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6944446)
X   (CHARDP R 0.0833330)
X   )
X(CHARACTER O 176
X   (CHARWD R 0.5249996)
X   (CHARHT R 0.6111106)
X   )
!FaR!OuT!
if [ ! -d dvidoc ]
then
	mkdir dvidoc
	echo mkdir dvidoc
fi
echo x - dvidoc/docmac.tex
sed -e 's/^X//' > dvidoc/docmac.tex << '!FaR!OuT!'
X\baselineskip=12bp
X\font\docfont=doc
X\textfont0=\docfont \scriptfont0=\docfont \scriptscriptfont0=\docfont
X\def\rm{\fam0\docfont}
X\textfont1=\docfont \scriptfont1=\docfont \scriptscriptfont1=\docfont
X\def\mit{\fam1} \def\oldstyle{\fam1\docfont}
X\def\it{\fam\itfam\docfont} % \it is family 4
X\textfont\itfam=\docfont
X\def\sl{\fam\slfam\docfont} % \sl is family 5
X\textfont\slfam=\docfont
X\def\bf{\fam\bffam\docfont} % \bf is family 6
X\textfont\bffam=\docfont \scriptfont\bffam=\docfont
X\scriptscriptfont\bffam=\docfont
X\def\tt{\fam\ttfam\docfont} % \tt is family 7
X\textfont\ttfam=\docfont
X\def\TeX{TeX}
X\def\LaTeX{LaTeX}
X\def\SliTeX{SliTeX}
X\def\BibTeX{BibTeX}
X\rm
!FaR!OuT!
if [ ! -d dvidoc ]
then
	mkdir dvidoc
	echo mkdir dvidoc
fi
echo x - dvidoc/dvidoc.1
sed -e 's/^X//' > dvidoc/dvidoc.1 << '!FaR!OuT!'
X.\" $Header
X.if t .ds TX T\h'-.1667m'\v'.22m'E\h'-.125m'\v'-.22m'X
X.if n .ds TX TeX
X.if t .ds LX L\v'-.22m'a\v'.22m'T\h'-.1667m'\v'.22m'E\h'-.125m'\v'-.22m'X
X.if n .ds LX LaTeX
X.TH DVIDOC 1
X.UC
X.SH NAME
Xdvidoc \- print TeX DVI files out on a file
X.SH SYNOPSIS
Xdvidoc
X.I dvifile
X.I outputfile
X.SH DESCRIPTION
X.IR Dvidoc (1)
Xattempts to print the contents of a DVI file on a regular ASCII file.
XThe output file will not be an exact representation of the DVI file
Xsince \*(TX output is designed for a high-resolution device.
XThe output will be an approximate representation of paragraph breaks
Xand it provides a simple quick means to preview output at your terminal.
XMath mode and tables are not handled well.
XAlso, page breaks will be different when output to a high-resolution device.
X.PP
XTo use 
X.I dvidoc
Xyou must 
X.I \input
Xthe macro file
X.I docmac.tex
Xin the beginning of your \*(TX or \*(LX document.
XThis file redefines the width of the roman, italic, boldface and typewriter
Xfonts.
XWhen you wish to output the final document to the laser printer or other
Xhigh resolution device you should remove the include file
X.I docmac.tex
Xand re\*(TX your document.
X.SH FILES
X.nf
X.ta \w'/usr/local/lib/tex/macros/docmac.tex   'u
X/usr/local/lib/tex/macros/docmac.tex	Input macro package
X.fi
X.SH SEE ALSO
Xtex(1)
X.SH BUGS
XThe DVI seek algorithm is horrible so it runs forever on large DVI files.
!FaR!OuT!
if [ ! -d dvidoc ]
then
	mkdir dvidoc
	echo mkdir dvidoc
fi
echo x - dvidoc/dvidoc.web
sed -e 's/^X//' > dvidoc/dvidoc.web << '!FaR!OuT!'
X% This is DVIDOC, a TeX device driver for text files.  It was written
X% at OSU in April, 1983, by modifying the TeX utility DVItype.
X
X% Here is TeX material that gets inserted after \input webhdr
X\def\hang{\hangindent 3em\indent\ignorespace}
X\def\TeX{T\hbox{\hskip-.1667em\lower.424ex\hbox{E}\hskip-.125em X}}
X\font\ninerm=cmr9
X\let\mc=\ninerm % medium caps for names like PASCAL
X\def\PASCAL{{\mc PASCAL}}
X
X\def\(#1){} % this is used to make module names sort themselves better
X\def\9#1{} % this is used for sort keys in the index
X
X\def\title{DVIDOC}
X\def\contentspagenumber{1}
X\def\topofcontents{\null
X  \def\titlepage{F} % include headline on the contents page
X  \def\rheader{\mainfont\hfil \contentspagenumber}
X  \vfill
X  \centerline{\titlefont The {\ttitlefont DVIDOC} processor}
X  \vskip 15pt
X  \centerline{(Version 1, April 1983)}
X  \vfill}
X\def\botofcontents{\vfill
X  \centerline{\hsize 5in\baselineskip9pt
X    \vbox{\ninerm\noindent
X   `\TeX' is a
X    trademark of the American Mathematical Society.}}}
X\pageno=\contentspagenumber \advance\pageno by 1
X
X@* Introduction.
XThe \.{DVIDOC} utility program reads binary device-independent (``\.{DVI}'')
Xfiles that are produced by document compilers such as \TeX, and 
Xapproximates the intended document as a text file suitable for typing at
Xa terminal or on a line printer.
X
XThis program is based on the program \.{DVItype}, which was written by
XDonald Knuth and David Fuchs.
XIt contained a great deal of code checking for malformed \.{DVI}
Xfiles.  Most of that code remains in \.{DVIDOC}, not because it is
Ximportant (we trust \TeX) to produce correct \.{DVI} files), but
Xbecause is was easier not to disturb the logic in modifying
X\.{DVItype} to produce \.{DVIDOC}.
X
XThe |banner| string defined here should be changed whenever \.{DVIDOC}
Xgets modified.
X
X at d banner=='This is DVIDOC, Version 1 for Pyramid OSx' {printed when the program starts}
X
X@ Unlike the programs distributed with \TeX, which are written in a
Xleast-common-denominator Pascal that runs on no machine, this program
Xis written to run on OSx using Pyramid Pascal.  
X
X at d othercases == otherwise: {default for cases not listed explicitly}
X at d endcases == @+end {follows the default case in an extended |case| statement}
X at f othercases == else
X at f endcases == end
X
X@ The binary input comes from |dvi_file|, and the document is written
Xon the file |doc_file|
X|term_in| and |term_out| are used throughout this program as files for
Xdialog with the user.  
X
X at d term_in==input
X at d term_out==output
X at d error(#)==message(' ',#)
X
X at p program DVIDOC(@!dvi_file,@!doc_file);
Xlabel @<Labels in the outer block@>@/
Xconst @<Constants in the outer block@>@/
Xtype @<Types in the outer block@>@/
Xvar@?@<Globals in the outer block@>@/
X@\@=#include "dvityext.h"@>@\ {declarations for external C procedures}
Xprocedure initialize; {this procedure gets things started properly}
Xvar i:integer;
X  begin @/
X  setpaths;
X  @<Set initial values@>@/
X  end;
X
X@ If the program has to stop prematurely, it goes to the
X`|final_end|'. Another label, |done|, is used when stopping normally.
X
X at d final_end=9999 {label for the end of it all}
X at d done=30 {go here when finished with a subtask}
X
X@<Labels...@>=final_end,done;
X
X@ The following parameters can be changed at compile time to extend or
Xreduce \.{DVIDOC}'s capacity.
X
X@<Constants...@>=
X@!max_fonts=100; {maximum number of distinct fonts per \.{DVI} file}
X@!max_widths=10000; {maximum number of different characters among all fonts}
X@!terminal_line_length=150; {maximum number of characters input in a single
X  line of input from the terminal}
X@!stack_size=100; {\.{DVI} files shouldn't |push| beyond this depth}
X@!name_size=1000; {total length of all font file names}
X@!name_length=100; {a file name shouldn't be longer than this}
X@!page_width_max=132; {maximum number of characters per line in the document}
X@!page_length_max=88; {maximum number of lines per page in the document}
X
X@ Here are some macros for common programming idioms.
X
X at d incr(#) == #:=#+1 {increase a variable by unity}
X at d decr(#) == #:=#-1 {decrease a variable by unity}
X at d do_nothing == {empty statement}
X
X@ If the \.{DVI} file is badly malformed, the whole process must be aborted;
X\.{DVIDOC} will give up, after issuing an error message about the symptoms
Xthat were noticed.
X
XSuch errors might be discovered inside of subroutines inside of subroutines,
Xso a procedure called |jump_out| has been introduced. This procedure, which
Xsimply transfers control to the label |final_end| at the end of the program,
Xcontains the only non-local |goto| statement in \.{DVIDOC}.
X
X at d abort(#)==begin message(' ',#); jump_out;
X    end
X at d bad_dvi(#)==abort('Bad DVI file: ',#,'!')
X at .Bad DVI file@>
X
X at p procedure jump_out;
Xbegin goto final_end;
Xend;
X
X@* The character set.
XLike all programs written with the  \.{WEB} system, \.{DVIDOC} can be
Xused with any character set. But it uses ascii code internally, because
Xthe programming for portable input-output is easier when a fixed internal
Xcode is used, and because \.{DVI} files use ascii code for file names
Xand certain other strings.
X
XThe next few modules of \.{DVIDOC} have therefore been copied from the
Xanalogous ones in the \.{WEB} system routines. They have been considerably
Xsimplified, since \.{DVIDOC} need not deal with the controversial
Xascii codes less than @'40. If such codes appear in the \.{DVI} file,
Xthey will be printed as question marks.
X
X@<Types...@>=
X@!ascii_code=" ".."~"; {a subrange of the integers}
X
X@ The original \PASCAL\ compiler was designed in the late 60s, when six-bit
Xcharacter sets were common, so it did not make provision for lower case
Xletters. Nowadays, of course, we need to deal with both upper and lower case
Xalphabets in a convenient way, especially in a program like \.{DVIDOC}.
XSo we shall assume that the \PASCAL\ system being used for \.{DVIDOC}
Xhas a character set containing at least the standard visible characters
Xof ascii code (|"!"| through |"~"|).
X
XSome \PASCAL\ compilers use the original name |char| for the data type
Xassociated with the characters in text files, while other \PASCAL s
Xconsider |char| to be a 64-element subrange of a larger data type that has
Xsome other name.  In order to accommodate this difference, we shall use
Xthe name |text_char| to stand for the data type of the characters in the
Xoutput file.  We shall also assume that |text_char| consists of
Xthe elements |chr(first_text_char)| through |chr(last_text_char)|,
Xinclusive. The following definitions should be adjusted if necessary.
X at d text_char == char {the data type of characters in text files}
X at d first_text_char=0 {ordinal number of the smallest element of |text_char|}
X at d last_text_char=127 {ordinal number of the largest element of |text_char|}
X
X@<Types...@>=
X@!text_file=packed file of text_char;
X
X@ The \.{DVIDOC} processor converts between ascii code and
Xthe user's external character set by means of arrays |xord| and |xchr|
Xthat are analogous to \PASCAL's |ord| and |chr| functions.
X
X@<Globals...@>=
X@!xord: array [text_char] of ascii_code;
X  {specifies conversion of input characters}
X@!xchr: array [0..255] of text_char;
X  {specifies conversion of output characters}
X
X@ Under our assumption that the visible characters of standard ascii are
Xall present, the following assignment statements initialize the
X|xchr| array properly, without needing any system-dependent changes.
X
X@<Set init...@>=
Xfor i:=0 to @'37 do xchr[i]:='?';
Xxchr[@'40]:=' ';
Xxchr[@'41]:='!';
Xxchr[@'42]:='"';
Xxchr[@'43]:='#';
Xxchr[@'44]:='$';
Xxchr[@'45]:='%';
Xxchr[@'46]:='&';
Xxchr[@'47]:='''';@/
Xxchr[@'50]:='(';
Xxchr[@'51]:=')';
Xxchr[@'52]:='*';
Xxchr[@'53]:='+';
Xxchr[@'54]:=',';
Xxchr[@'55]:='-';
Xxchr[@'56]:='.';
Xxchr[@'57]:='/';@/
Xxchr[@'60]:='0';
Xxchr[@'61]:='1';
Xxchr[@'62]:='2';
Xxchr[@'63]:='3';
Xxchr[@'64]:='4';
Xxchr[@'65]:='5';
Xxchr[@'66]:='6';
Xxchr[@'67]:='7';@/
Xxchr[@'70]:='8';
Xxchr[@'71]:='9';
Xxchr[@'72]:=':';
Xxchr[@'73]:=';';
Xxchr[@'74]:='<';
Xxchr[@'75]:='=';
Xxchr[@'76]:='>';
Xxchr[@'77]:='?';@/
Xxchr[@'100]:='@@';
Xxchr[@'101]:='A';
Xxchr[@'102]:='B';
Xxchr[@'103]:='C';
Xxchr[@'104]:='D';
Xxchr[@'105]:='E';
Xxchr[@'106]:='F';
Xxchr[@'107]:='G';@/
Xxchr[@'110]:='H';
Xxchr[@'111]:='I';
Xxchr[@'112]:='J';
Xxchr[@'113]:='K';
Xxchr[@'114]:='L';
Xxchr[@'115]:='M';
Xxchr[@'116]:='N';
Xxchr[@'117]:='O';@/
Xxchr[@'120]:='P';
Xxchr[@'121]:='Q';
Xxchr[@'122]:='R';
Xxchr[@'123]:='S';
Xxchr[@'124]:='T';
Xxchr[@'125]:='U';
Xxchr[@'126]:='V';
Xxchr[@'127]:='W';@/
Xxchr[@'130]:='X';
Xxchr[@'131]:='Y';
Xxchr[@'132]:='Z';
Xxchr[@'133]:='[';
Xxchr[@'134]:='\';
Xxchr[@'135]:=']';
Xxchr[@'136]:='^';
Xxchr[@'137]:='_';@/
Xxchr[@'140]:='`';
Xxchr[@'141]:='a';
Xxchr[@'142]:='b';
Xxchr[@'143]:='c';
Xxchr[@'144]:='d';
Xxchr[@'145]:='e';
Xxchr[@'146]:='f';
Xxchr[@'147]:='g';@/
Xxchr[@'150]:='h';
Xxchr[@'151]:='i';
Xxchr[@'152]:='j';
Xxchr[@'153]:='k';
Xxchr[@'154]:='l';
Xxchr[@'155]:='m';
Xxchr[@'156]:='n';
Xxchr[@'157]:='o';@/
Xxchr[@'160]:='p';
Xxchr[@'161]:='q';
Xxchr[@'162]:='r';
Xxchr[@'163]:='s';
Xxchr[@'164]:='t';
Xxchr[@'165]:='u';
Xxchr[@'166]:='v';
Xxchr[@'167]:='w';@/
Xxchr[@'170]:='x';
Xxchr[@'171]:='y';
Xxchr[@'172]:='z';
Xxchr[@'173]:='{';
Xxchr[@'174]:='|';
Xxchr[@'175]:='}';
Xxchr[@'176]:='~';
Xfor i:=@'177 to 255 do xchr[i]:='?';
X
X@ The following system-independent code makes the |xord| array contain a
Xsuitable inverse to the information in |xchr|.
X
X@<Set init...@>=
Xfor i:=first_text_char to last_text_char do xord[chr(i)]:=@'40;
Xfor i:=" " to "~" do xord[xchr[i]]:=i;
X
X@* Device-independent file format.
XThe device-independent file format is described in the \.{DVItype} 
Xdocumentation.
X
XWhen \.{DVIDOC} "typesets" a character, it simply puts its ascii code
Xinto the document file in the proper place according to the rounding of
X|h| and |v| to whole character positions.  It may, of course, obliterate
Xa character previously stored in the same position.  Especially if a
Xsymbol font is being used, the ascii code may print ultimately as an
Xentirely different character than the one the document designer originally
Xintended.  For \.{DVIDOC} to produce more than a rough approximation to 
Xthe intended document, fonts need to be chosen very carefully.
X
X@ @d set_char_0=0 {typeset character 0 and move right}
X at d set1=128 {typeset a character and move right}
X at d set_rule=132 {typeset a rule and move right}
X at d put1=133 {typeset a character}
X at d put_rule=137 {typeset a rule}
X at d nop=138 {no operation}
X at d bop=139 {beginning of page}
X at d eop=140 {ending of page}
X at d push=141 {save the current positions}
X at d pop=142 {restore previous positions}
X at d right1=143 {move right}
X at d w0=147 {move right by |w|}
X at d w1=148 {move right and set |w|}
X at d x0=152 {move right by |x|}
X at d x1=153 {move right and set |x|}
X at d down1=157 {move down}
X at d y0=161 {move down by |y|}
X at d y1=162 {move down and set |y|}
X at d z0=166 {move down by |z|}
X at d z1=167 {move down and set |z|}
X at d fnt_num_0=171 {set current font to 0}
X at d fnt1=235 {set current font}
X at d xxx1=239 {extension to \.{DVI} primitives}
X at d xxx4=242 {potentially long extension to \.{DVI} primitives}
X at d fnt_def1=243 {define the meaning of a font number}
X at d pre=247 {preamble}
X at d post=248 {postamble beginning}
X at d post_post=249 {postamble ending}
X at d undefined_commands==250,251,252,253,254,255
X at d id_byte=2 {identifies the kind of \.{DVI} files described here}
X
X@* Input from binary files.
XWe have seen that a \.{DVI} file is a sequence of 8-bit bytes. The bytes
Xappear physically in what is called a `|packed file of 0..255|'
Xin \PASCAL\ lingo.
X
XPacking is system dependent, and many \PASCAL\ systems fail to implement
Xsuch files in a sensible way (at least, from the viewpoint of producing
Xgood production software).  For example, some systems treat all
Xbyte-oriented files as text, looking for end-of-line marks and such
Xthings. Therefore some system-dependent code is often needed to deal with
Xbinary files, even though most of the program in this section of
X\.{DVIDOC} is written in standard \PASCAL.
X
XWe shall stick to simple \PASCAL\ in this program, for reasons of clarity,
Xeven if such simplicity is sometimes unrealistic.
X
X@<Types...@>=
X@!eight_bits=0..255; {unsigned one-byte quantity}
X@!byte_file=packed file of char; {files that contain binary data}
X
X@ The program deals with two binary file variables: |dvi_file| is the main
Xinput file that we are translating into symbolic form, and |tfm_file| is
Xthe current font metric file from which character-width information is
Xbeing read.
X
X@<Glob...@>=
X@!dvi_file:byte_file; {the stuff we are \.{DVI}typing}
X@!tfm_file:byte_file; {a font metric file}
X
X@ To prepare these files for input, we |reset| them. An extension of
X\PASCAL\ is needed in the case of |tfm_file|, since we want to associate
Xit with external files whose names are specified dynamically (i.e., not
Xknown at compile time). The following code assumes that `|reset(f,s)|'
Xdoes this, when |f| is a file variable and |s| is a string variable that
Xspecifies the file name. If |eof(f)| is true immediately after
X|reset(f,s)| has acted, we assume that no file named |s| is accessible.
X
X at d read_access_mode=4  {``read'' mode for |test_access|}
X at d write_access_mode=2 {``write'' mode for |test_access|}
X
X at d no_file_path=0    {no path searching should be done}
X at d font_file_path=3  {path specifier for \.{TFM} files}
X at p procedure open_dvi_file; {prepares to read packed bytes in |dvi_file|}
Xbegin
Xargv(1, cur_name);
Xif test_access(read_access_mode, no_file_path) then 
Xreset(dvi_file, real_name_of_file) else
Xbegin
Xerror('DVI file not found');
Xgoto done;
Xend;
Xcur_loc:=0;
Xend;
X@#
Xprocedure open_tfm_file; {prepares to read packed bytes in |tfm_file|}
Xbegin 
Xif test_access(read_access_mode, font_file_path) then 
Xreset(tfm_file, real_name_of_file) 
Xelse
Xbegin
Xerror('TFM file not found');
Xgoto done;
Xend;
Xend;
X
X@ If you looked carefully at the preceding code, you probably asked,
X``What are |cur_loc| and |cur_name|?'' Good question. They're global
Xvariables: |cur_loc| is the number of the byte about to be read next from
X|dvi_file|, and |cur_name| is a string variable that will be set to the
Xcurrent font metric file name before |open_tfm_file| is called.
X
X@<Glob...@>=
X@!cur_loc:integer; {where we are about to look, in |dvi_file|}
X@!cur_name,real_name_of_file:
Xpacked array[1..name_length] of char; {external name,
X  with no lower case letters}
X
X@ It turns out to be convenient to read four bytes at a time, when we are
Xinputting from \.{TFM} files. The input goes into global variables
X|b0|, |b1|, |b2|, and |b3|, with |b0| getting the first byte and |b3|
Xthe fourth.
X
X@<Glob...@>=
X@!b0,@!b1,@!b2,@!b3: eight_bits; {four bytes input at once}
X
X@ The |read_tfm_word| procedure sets |b0| through |b3| to the next
Xfour bytes in the current \.{TFM} file.
X at d get_tfm_byte(#) ==
X    read(tfm_file,byte); # := ord(byte);
X
X at p procedure read_tfm_word;
Xvar byte:char;
Xbegin
Xget_tfm_byte(b0);
Xget_tfm_byte(b1);
Xget_tfm_byte(b2);
Xget_tfm_byte(b3);
Xend;
X
X@ We shall use another set of simple functions to read the next byte or
Xbytes from |dvi_file|. There are seven possibilities, each of which is
Xtreated as a separate function in order to minimize the overhead for
Xsubroutine calls.
X
X at p function get_byte:integer; {returns the next byte, unsigned}
Xvar b:char;
Xbegin if eof(dvi_file) then get_byte:=0
Xelse  begin read(dvi_file,b); incr(cur_loc); get_byte:=ord(b);
X  end;
Xend;
X@#
Xfunction signed_byte:integer; {returns the next byte, signed}
Xvar b:char;
Xbegin read(dvi_file,b); incr(cur_loc);
Xif ord(b)<128 then signed_byte:=ord(b) @+ else signed_byte:=ord(b)-256;
Xend;
X@#
Xfunction get_two_bytes:integer; {returns the next two bytes, unsigned}
Xvar a,@!b:char;
Xbegin read(dvi_file,a); read(dvi_file,b);
Xcur_loc:=cur_loc+2;
Xget_two_bytes:=ord(a)*256+ord(b);
Xend;
X@#
Xfunction signed_pair:integer; {returns the next two bytes, signed}
Xvar a,@!b:char;
Xbegin read(dvi_file,a); read(dvi_file,b);
Xcur_loc:=cur_loc+2;
Xif ord(a)<128 then signed_pair:=ord(a)*256+ord(b)
Xelse signed_pair:=(ord(a)-256)*256+ord(b);
Xend;
X@#
Xfunction get_three_bytes:integer; {returns the next three bytes, unsigned}
Xvar a,@!b,@!c:char;
Xbegin read(dvi_file,a); read(dvi_file,b); read(dvi_file,c);
Xcur_loc:=cur_loc+3;
Xget_three_bytes:=(ord(a)*256+ord(b))*256+ord(c);
Xend;
X@#
Xfunction signed_trio:integer; {returns the next three bytes, signed}
Xvar a,@!b,@!c:char;
Xbegin read(dvi_file,a); read(dvi_file,b); read(dvi_file,c);
Xcur_loc:=cur_loc+3;
Xif ord(a)<128 then signed_trio:=(ord(a)*256+ord(b))*256+ord(c)
Xelse signed_trio:=((ord(a)-256)*256+ord(b))*256+ord(c);
Xend;
X@#
Xfunction signed_quad:integer; {returns the next four bytes, signed}
Xvar a,@!b,@!c,@!d:char;
Xbegin read(dvi_file,a); read(dvi_file,b); read(dvi_file,c); read(dvi_file,d);
Xcur_loc:=cur_loc+4;
Xif ord(a)<128 then signed_quad:=((ord(a)*256+ord(b))*256+ord(c))*256+ord(d)
Xelse signed_quad:=(((ord(a)-256)*256+ord(b))*256+ord(c))*256+ord(d);
Xend;
X
X@ Finally we come to the routines that do random file access.
XThe driver program below needs two such routines: |dvi_length| should
Xcompute the total number of bytes in |dvi_file|, possibly also
Xcausing |eof(dvi_file)| to be true; and |move_to_byte(n)|
Xshould position |dvi_file| so that the next |get_byte| will read byte |n|,
Xstarting with |n=0| for the first byte in the file.
X
X at p function dvi_length:integer;
Xvar i:integer;
X    j:char;
Xbegin 
Xreset(dvi_file);
Xi := 0;
Xwhile not eof(dvi_file) do
Xbegin
X    read(dvifile, j);
X    incr(i);
Xend;
Xcur_loc := i;
Xdvi_length := i;
Xend;
X@#
Xprocedure move_to_byte(n:integer);
Xvar i:integer;
X    j:char;
Xbegin 
Xreset(dvi_file);
Xi := 0;
Xwhile i < n do
Xbegin
X    read(dvi_file, j);
X    incr(i);
Xend;
Xcur_loc := n;
Xend;
X
X@* Reading the font information.
X\.{DVI} file format does not include information about character widths, since
Xthat would tend to make the files a lot longer. But a program that reads
Xa \.{DVI} file is supposed to know the widths of the characters that appear
Xin \\{set\_char} commands. Therefore \.{DVIDOC} looks at the font metric
X(\.{TFM}) files for the fonts that are involved.
X at .TFM {\rm files}@>
X
X@ For purposes of this program, we need to know only two things about a
Xgiven character |c| in a given font |f|: (1)@@Is |c| a legal character
Xin@@|f|? (2)@@If so, what is the width of |c|? We also need to know the
Xsymbolic name of each font, so it can be printed out, and we need to know
Xthe approximate size of inter-word spaces in each font.
X
XThe answers to these questions appear implicitly in the following data
Xstructures. The current number of known fonts is |nf|. Each known font has
Xan internal number |f|, where |0<=f<nf|; the external number of this font,
Xi.e., its font identification number in the \.{DVI} file, is
X|font_num[f]|, and the external name of this font is the string that
Xoccupies positions |font_name[f]| through |font_name[f+1]-1| of the array
X|names|. The latter array consists of |ascii_code| characters, and
X|font_name[nf]| is its first unoccupied position.  A horizontal motion
Xless than |font_space[f]| will be treated as a `kern'.
XThe
Xlegal characters run from |font_bc[f]| to |font_ec[f]|, inclusive; more
Xprecisely, a given character |c| is valid in font |f| if and only if
X|font_bc[f]<=c<=font_ec[f]| and |char_width(f)(c)<>invalid_width|.
X(Exception: If |font_ec[f]=256|, all characters |c>=256| are valid and have
Xthe same width |char_width(f)(256)|.)
X@^oriental characters@>@^Chinese characters@>@^Japanese characters@>
XFinally, |char_width(f)(c)=width[width_base[f]+c]|, and |width_ptr| is the
Xfirst unused position of the |width| array.
X
X at d char_width_end(#)==#]
X at d char_width(#)==width[width_base[#]+char_width_end
X at d invalid_width==@'17777777777
X
X@<Glob...@>=
X@!font_num:array [0..max_fonts] of integer; {external font numbers}
X@!font_name:array [0..max_fonts] of 0..name_size; {starting positions
X  of external font names}
X@!names:array [0..name_size] of ascii_code; {characters of names}
X@!font_check_sum:array [0..max_fonts] of integer; {check sums}
X@!font_scaled_size:array [0..max_fonts] of integer; {scale factors}
X@!font_design_size:array [0..max_fonts] of integer; {design sizes}
X@!font_space:array [0..max_fonts] of integer; {boundary between ``small''
X  and ``large'' spaces}
X@!font_bc:array [0..max_fonts] of integer; {beginning characters in fonts}
X@!font_ec:array [0..max_fonts] of integer; {ending characters in fonts}
X@!width_base:array [0..max_fonts] of integer; {index into |width| table}
X@!width:array [0..max_widths] of integer; {character widths, in \.{DVI} units}
X@!nf:0..max_fonts; {the number of known fonts}
X@!width_ptr:0..max_widths; {the number of known character widths}
X
X@ @<Set init...@>=
Xnf:=0; width_ptr:=0; font_name[0]:=0;
X
X@ It is, of course, a simple matter to print the name of a given font.
X
X at p procedure print_font(@!f:integer); {|f| is an internal font number}
Xvar k:0..name_size; {index into |names|}
Xbegin if f=nf then write(term_out,'UNDEFINED!')
X at .UNDEFINED@>
Xelse  begin for k:=font_name[f] to font_name[f+1]-1 do
X    write(term_out,xchr[names[k]]);
X  end;
Xend;
X
X@ An auxiliary array |in_width| is used to hold the widths as they are
Xinput. The global variable |tfm_check_sum| is set to the check sum that
Xappears in the current \.{TFM} file.
X
X@<Glob...@>=
X@!in_width:array[0..255] of integer; {\.{TFM} width data in \.{DVI} units}
X@!tfm_check_sum:integer; {check sum found in |tfm_file|}
X
X@ Here is a procedure that absorbs the necessary information from a
X\.{TFM} file, assuming that the file has just been successfully reset
Xso that we are ready to read its first byte. (A complete description of
X\.{TFM} file format appears in the documentation of \.{TFtoPL} and will
Xnot be repeated here.) The procedure does not check the \.{TFM} file
Xfor validity, nor does it give explicit information about what is
Xwrong with a \.{TFM} file that proves to be invalid; \.{DVI}-reading
Xprograms need not do this, since \.{TFM} files are almost always valid,
Xand since the \.{TFtoPL} utility program has been specifically designed
Xto diagnose \.{TFM} errors. The procedure simply returns |false| if it
Xdetects anything amiss in the \.{TFM} data.
X
XThere is a parameter, |z|, which represents the scaling factor being
Xused to compute the font dimensions; it must be in the range $0<z<2^{27}$.
X
X at p function in_TFM(@!z:integer):boolean; {input \.{TFM} data or return |false|}
Xlabel 9997, {go here when the format is bad}
X  9998,  {go here when the information cannot be loaded}
X  9999;  {go here to exit}
Xvar k:integer; {index for loops}
X@!lh:integer; {length of the header data, in four-byte words}
X@!nw:integer; {number of words in the width table}
X@!wp:0..max_widths; {new value of |width_ptr| after successful input}
X@!alpha,@!beta:integer; {quantities used in the scaling computation}
Xbegin @<Read past the header data; |goto 9997| if there is a problem@>;
X@<Store character-width indices at the end of the |width| table@>;
X@<Read and convert the width values, setting up the |in_width| table@>;
X@<Move the widths from |in_width| to |width|, and append |pixel_width| values@>;
Xwidth_ptr:=wp; in_TFM:=true; goto 9999;
X9997: write_ln(term_out,'---not loaded, TFM file is bad');
X at .TFM file is bad@>
X9998: in_TFM:=false;
X9999: end;
X
X@ @<Read past the header...@>=
Xread_tfm_word; lh:=b2*256+b3;
Xread_tfm_word; font_bc[nf]:=b0*256+b1; font_ec[nf]:=b2*256+b3;
Xif font_ec[nf]<font_bc[nf] then font_bc[nf]:=font_ec[nf]+1;
Xif width_ptr+font_ec[nf]-font_bc[nf]+1>max_widths then
X  begin write_ln(term_out,'---not loaded, DVIDOC needs larger width table');
X at .DVIDOC needs larger...@>
X    goto 9998;
X  end;
Xwp:=width_ptr+font_ec[nf]-font_bc[nf]+1;
Xread_tfm_word; nw:=b0*256+b1;
Xif (nw=0)or(nw>256) then goto 9997;
Xfor k:=1 to 3+lh do
X  begin if eof(tfm_file) then goto 9997;
X  read_tfm_word;
X  if k=4 then
X    if b0<128 then tfm_check_sum:=((b0*256+b1)*256+b2)*256+b3
X    else tfm_check_sum:=(((b0-256)*256+b1)*256+b2)*256+b3;
X  end;
X
X@ @<Store character-width indices...@>=
Xif wp>0 then for k:=width_ptr to wp-1 do
X  begin read_tfm_word;
X  if b0>nw then goto 9997;
X  width[k]:=b0;
X  end;
X
X@ The most important part of |in_TFM| is the width computation, which
Xinvolves multiplying the relative widths in the \.{TFM} file by the
Xscaling factor in the \.{DVI} file. This fixed-point multiplication
Xmust be done with precisely the same accuracy by all \.{DVI}-reading programs,
Xin order to validate the assumptions made by \.{DVI}-writing programs
Xlike \TeX82.
X
XLet us therefore summarize what needs to be done. Each width in a \.{TFM}
Xfile appears as a four-byte quantity called a |fix_word|.  A |fix_word|
Xwhose respective bytes are $(a,b,c,d)$ represents the number
X$$x=\left\{\vcenter{\halign{$#$,\hfil\qquad&if $#$\hfil\cr
Xb\cdot2^{-4}+c\cdot2^{-12}+d\cdot2^{-20}&a=0;\cr
X-16+b\cdot2^{-4}+c\cdot2^{-12}+d\cdot2^{-20}&a=255.\cr}}\right.$$
X(No other choices of $a$ are allowed, since the magnitude of a \.{TFM}
Xdimension must be less than 16.)  We want to multiply this quantity by the
Xinteger@@|z|, which is known to be less then $2^{27}$. Let $\alpha=16z$.
XIf $|z|<2^{23}$, the individual multiplications $b\cdot z$, $c\cdot z$,
X$d\cdot z$ cannot overflow; otherwise we will divide |z| by 2, 4, 8, or
X16, to obtain a multiplier less than $2^{23}$, and we can compensate for
Xthis later. If |z| has thereby been replaced by $|z|^\prime=|z|/2^e$, let
X$\beta=2^{4-e}$; we shall compute
X$$\lfloor(b+c\cdot2^{-8}+d\cdot2^{-16})\,z^\prime/\beta\rfloor$$ if $a=0$,
Xor the same quantity minus $\alpha$ if $a=255$.  This calculation must be
Xdone exactly, for the reasons stated above; the following program does the
Xjob in a system-independent way, assuming that arithmetic is exact on
Xnumbers less than $2^{31}$ in magnitude.
X
X@<Read and convert the width values...@>=
X@<Replace |z| by $|z|^\prime$ and compute $\alpha,\beta$@>;
Xfor k:=0 to nw-1 do
X  begin read_tfm_word;
X  in_width[k]:=(((((b3*z)div@'400)+(b2*z))div@'400)+(b1*z))div beta;
X  if b0>0 then if b0<255 then goto 9997
X    else in_width[k]:=in_width[k]-alpha;
X  end
X
X@ @<Replace |z|...@>=
Xbegin alpha:=16*z; beta:=16;
Xwhile z>=@'40000000 do
X  begin z:=z div 2; beta:=beta div 2;
X  end;
Xend
X
X@ A \.{DVI}-reading program usually works with font files instead of
X\.{TFM} files, so \.{DVIDOC} is atypical in that respect. Font files
Xshould, however, contain exactly the same character width data that is
Xfound in the corresponding \.{TFM}s. In addition, font files usually
Xalso contain the widths of characters in pixels, since the device-independent
Xcharacter widths of \.{TFM} files are generally not perfect multiples of
Xpixels.
X
XThe |pixel_width| array contains this information; when |width[k]| is the
Xdevice-independent width of some character in \.{DVI} units, |pixel_width[k]|
Xis the corresponding width of that character in an actual font.
XThe macro |char_pixel_width| is set up to be analogous to |char_width|.
X
X at d char_pixel_width(#)==pixel_width[width_base[#]+char_width_end
X
X@<Glob...@>=
X@!pixel_width:array[0..max_widths] of integer; {actual character widths,
X  in pixels}
X@!horiz_conv:real; {converts \.{DVI} units to horizontal pixels}
X@!vert_conv:real; {converts \.{DVI} units to vertical pixels}
X@!true_horiz_conv:real; {converts unmagnified \.{DVI} units to pixels}
X@!true_vert_conv:real; {converts unmagnified \.{DVI} units to pixels}
X@!numerator,@!denominator:integer; {stated conversion ratio}
X@!mag:integer; {magnification factor times 1000}
X
X@ The following code computes pixel widths by simply rounding the \.{TFM}
Xwidths to the nearest integer number of pixels, based on the conversion factor
X|horiz_conv| that converts \.{DVI} units to pixels. 
X
X at d horiz_pixel_round(#)==trunc(horiz_conv*(#)+0.5)
X at d vert_pixel_round(#)==trunc(vert_conv*(#)+0.5)
X
X@<Move the widths from |in_width| to |width|, and append |pixel_width| values@>=
Xwidth_base[nf]:=width_ptr-font_bc[nf];
Xif wp>0 then for k:=width_ptr to wp-1 do
X  begin width[k]:=in_width[width[k]];
X  pixel_width[k]:=horiz_pixel_round(width[k]);
X  end
X
X@* Optional modes of output.

-- 
		Scott Simpson
		TRW Electronics and Defense Sector
		...{decvax,ihnp4,ucbvax}!trwrb!simpson



More information about the Comp.sources.unix mailing list