[subversion-commit] SVN tetex-bin commit + diffs: r1534 - tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir

Frank Küster frank at costa.debian.org
Wed Jul 26 16:32:26 UTC 2006


Author: frank
Date: 2006-07-26 16:32:24 +0000 (Wed, 26 Jul 2006)
New Revision: 1534

Modified:
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ChangeLog
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/Makefile.in
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/NEWS
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/README
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/avlstuff.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/depend.mk
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/epdf.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/epdf.h
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/image.h
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/macnames.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/mapfile.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.ch
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.defines
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.h
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.mk
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftexextra.in
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftoepdf.cc
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pkin.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ptexlib.h
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ptexmac.h
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/tex.ch0
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ttf2afm.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/utils.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/vfpacket.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writeenc.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writefont.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writeimg.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writejpg.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writepng.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writet1.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writet3.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writettf.c
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writettf.h
   tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writezip.c
Log:
commit files modified in new upstream version

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ChangeLog
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ChangeLog	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ChangeLog	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,104 +1,69 @@
-2004-10-29  Jan Nieuwenhuizen  <janneke at gnu.org>
+2004-08-21  Peter Breitenlohner <peb at mppmu.mpg.de>
 
-        * pdftex.mk (pdftex):  Build fix: pdftexextra.c depends on
-        pdftexextra.h.
+	* pdfetex.ch2: Adapted to e-TeX version 2.2.
 
-2004-09-07  The pdfTeX team:
-
-	* README: pdftex version 1.20a.
-
-	* NEWS: pdftex version 1.20a.
-
-	* pdftex.ch: pdftex version 1.20a.
-
 2004-08-26  Olaf Weber  <olaf at infovore.xs4all.nl>
 
-	* pdftexlib.mk (pdftexdir/libpdf.a): Add pdftexdir/pdftexextra.h
-	to the dependencies, so it gets built before we go and try to
-	build the library.
+	* pdfetexextra.in: File was renamed from pdftexextra.h; the
+	current pdfTeX and e-TeX versions are substituted from
+	../pdftexdir/pdftex.version and ../etexdir/etex.version.  Variant
+	of code supplied by Peter Breitenlohner <peb at mppmu.mpg.de>.
 
-	* pdftex.version: Is from now on a generated file.
-
-	* pdftexextra.in: Renamed from pdftexextra.h; the current pdfTeX
-	version is substituted from pdftex.version.  Variant of code
-	supplied by Peter Breitenlohner <peb at mppmu.mpg.de>.
-
-	* pdftex.mk: Added rules to extract current pdfTeX version from
-	pdftex.ch and insert into pdftex.version and pdftexextra.h.
-	Variant of code supplied by Peter Breitenlohner
+	* pdfetex.mk: Added rule to insert pdfTeX and e-TeX versions into
+	pdfetexextra.h.  Variant of code supplied by Peter Breitenlohner
 	<peb at mppmu.mpg.de>.
 
 2004-08-25  Olaf Weber  <olaf at infovore.xs4all.nl>
 
-	* vadjust.ch: Moved here from pdfxtexdir.
+	* pdfetex.mk: vadjust.ch moved from pdfxtexdir to pdftexdir.
 
-	* pdftex.mk: vadjust.ch moved to this directory from pdfxtexdir.
+2004-08-17  Olaf Weber  <olaf at infovore.xs4all.nl>
 
-2004-08-23  Olaf Weber  <olaf at infovore.xs4all.nl>
+	* pdfetex.mk: Resurrected etex.fix, there is again a need to
+	include late-breaking changes.
 
-	* pdftex.mk: Scrap rules for pdftexinfo.  These are obsolete.
-
-	* pdftex.mak: Scrap rules for pdftexinfo.
-
-2004-08-06  Olaf Weber  <olaf at infovore.xs4all.nl>
-
-	* Makefile.in: The .cc.o suffix rule should use ALL_CXXFLAGS (as
-	is done for ALL_CFLAGS).  From Jan Nieuwenhuizen
-	<janneke at gnu.org>.
-
 2004-07-29  Peter Breitenlohner <peb at mppmu.mpg.de>
 
-	* pdftex.ch, hz.ch: Somewhat rearrange handling of kern and
-	math nodes in order to reduce interference between eTeX and
-	pdfTeX change files. Somewhat disentangle margin kerns such
-	that pdftex.web and pdfetex.web can be built with or without
-	hz.ch (not true for pdf*tex.ch).
+	* pdfetex.ch[12]: Somewhat rearrange handling of kern and math
+	nodes in order to reduce interference between eTeX and pdfTeX
+	change files.
 
+	* pdfetex.ch1 (hlist_out): Keep full mixed direction typesetting
+	code.
+
 2004-07-25  Peter Breitenlohner <peb at mppmu.mpg.de>
 
-	* pdftex.ch: Reorganize additional command codes for convert
+	* pdfetex.ch[12]: Reorganize additional command codes for convert
 	and last_item in order to reduce interference between eTeX and
 	pdfTeX change files.
 
-	* change-files.txt: Adjust to current status.
-
 2004-07-23  Peter Breitenlohner <peb at mppmu.mpg.de>
 
-	* pdftex.ch, tex.ch[01], tex.pch: Reorganize handling of banner
+	* pdfetex.ch[12], tex.ch[01]: Reorganize handling of banner
 	string in order to reduce interference between eTeX, pdfTeX,
 	and web2c change files.
 
 2004-07-22  Peter Breitenlohner <peb at mppmu.mpg.de>
 
-	* pdftex.ch: Removed unused token types for pdfTeX's additional
-	token list parameters.
+	* pdfetex.ch[12]: Removed unused token types for pdfTeX's
+	additional token list parameters.
 
 2004-07-19  Peter Breitenlohner <peb at mppmu.mpg.de>
 
-	* hz.ch, pdftex.ch, tex.ch[01], tex.pch: Reorganize handling of
-	additional token list and integer parameters in order to reduce
-	interference between eTeX, pdfTeX, and web2c change files.
+	* pdfetex.ch[12], tex.ch0: Reorganize handling of additional
+	token list and integer parameters and e-TeX's additional
+	penalties in order to reduce interference between eTeX, pdfTeX,
+	and web2c change files.
 
-	* pdftex.ch: Add a note that this file not only defines pdftex.web
-	in terms of changes to be applies to tex.web, but in addition
-	is used to define pdfetex.web.
+	* pdfetex.mk (pdfetex.ch): Remove tex.ch2 from build rules.
 
-	* tex.pch: Add a note that this file is used to construct the
-	web2c change files for both pdfTeX and pfdeTeX.
+	* tex.ch2: Removed.
 
-	* pdftex.mk (pdftex.ch): Remove tex.ch2 from build rules.
-
-	* tex.ch2: Removed
-
 2004-07-17  Peter Breitenlohner <peb at mppmu.mpg.de>
 
-	* pdftex.mk: Rewrite build rules for pdftex.{web,ch}.
+	* pdfetex.mk: Rewrite build rules for pdfetex.{web,ch},
+	remove etex.{ch0,ch1,fix}, tex.ch2, and several non-dependencies.
 
-	* pdftex.ch: Adapt glue and leader box rounding to TeX 3.141592.
-	Remove a few modules that were identical copies of those in TeX.
+	* pdfetex.ch2: Adapt to eTeX changes.
 
-2004-07-16  Peter Breitenlohner <peb at mppmu.mpg.de>
-
-	* ttf2afm.c: Add various const's, to avoid compiler warnings.
-
 	* ChangeLog: New file.

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/Makefile.in
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/Makefile.in	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/Makefile.in	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,9 +1,9 @@
 # Makefile for libpdf - te at dbs.uni-hannover.de
-# $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/Makefile.in#19 $
+# $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/Makefile.in#23 $
 
-ac_include ../make/common.mk
-ac_include ../make/programs.mk
-ac_include ../make/library.mk
+kpse_include ../make/common.mk
+kpse_include ../make/programs.mk
+kpse_include ../make/library.mk
 
 kpathsea_srcdir_parent = $(srcdir)/../..
 kpathsea_dir_parent = ../..
@@ -35,7 +35,7 @@
 
 OBJS = epdf.o mapfile.o utils.o vfpacket.o pkin.o \
 writefont.o writet1.o writet3.o writezip.o writeenc.o writettf.o \
-writejpg.o writepng.o writeimg.o pdftoepdf.o avl.o avlstuff.o
+writejpg.o writepng.o writeimg.o pdftoepdf.o avl.o avlstuff.o subfont.o tounicode.o
 
 all: libpdf.a
 
@@ -46,11 +46,10 @@
 	$(AR) $(ARFLAGS) $@  $(OBJS)
 	$(RANLIB) $@
 
-mostlyclean clean:
-	rm -f *.o libpdf.a ttf2afm pdftosrc
+kpse_include ../make/clean.mk
 
-distclean maintainer-clean extraclean: clean
-	rm -f Makefile config.log config.status
+clean::
+	rm -f libpdf.a ttf2afm pdftosrc
 
 depend:
 	rm -f $(OBJS) ttf2afm.o pdftosrc.o
@@ -58,4 +57,4 @@
 	    grep -v "^$(CC)\|$(CXX)\|$(AR)\|make\|klibtool" | \
 	    sed 's: [^ ]*/\.\./libs/[^ ]*::g' > $(srcdir)/depend.mk
 
-ac_include pdftexdir/depend.mk
+kpse_include pdftexdir/depend.mk

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/NEWS
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/NEWS	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/NEWS	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,3 +1,253 @@
+---------------------------------------------------------------
+pdfTeX 3.141592-1.40.0-beta-20060725 was released on 2006-07-25
+---------------------------------------------------------------
+- added patches by Christian Schenk forwarded by Hartmut
+- added patch 421 (popen) from Taco
+- added lots of (void) to writettf* and ttf2afm to silence the compiler
+- removed some unused variables from tounicode.c
+- add new code by Thanh (patch 580)
+- added security patch for xpdf :-(
+
+---------------------------------------------------------------
+pdfTeX 3.141592-1.40.0-beta-20060213 was released on 2006-02-13
+---------------------------------------------------------------
+- pdftex.web has been improved a bit
+- new patch:
+  - 473 \ifabsnum and \ifabsdim
+- the manual has been updated a bit and is again included
+
+---------------------------------------------------------------
+pdfTeX 3.141592-1.40.0-beta-20060125 was released on 2006-01-25
+---------------------------------------------------------------
+- pdfTeX now includes pdfeTeX, i.e. there is no way to make a binary without
+  eTeX support. Also the sources of TeX, eTeX and pdfTeX have been merged into
+  one file pdftex.web
+- most pdfTeX change files are gone; only one file (pdftex.ch) remains.
+- improved patches:
+  - 393 Ensure newline before endstream
+
+---------------------------------------------------------------
+pdfTeX 3.141592-1.40.0-beta-20060117 was released on 2006-01-17
+---------------------------------------------------------------
+- pdfTeX is now pdfeTeX, i.e. there is no way to make a binary without eTeX
+  support. Also the sources of TeX, eTeX and pdfTeX have been merged into one
+  file pdfetex.web
+- strip trailing zeros in fractions of reals written
+- removed patch 467 \ifindef
+- improved logging of objstreams
+
+----------------------------------------------------------------
+pdfTeX 3.141592-1.40.0-alpha-20060111 was released on 2006-01-11
+----------------------------------------------------------------
+- new patches:
+  - 466 \primitive and \ifprimitive
+  - 467 \ifinedef
+- improved patches:
+  - 393 Ensure newline before endstream
+- pdfTeX now sets /ModDate and /Trapped by default (the values can be
+  overridden with /pdfinfo)
+- more fixes to remove warnings from -Wall
+
+----------------------------------------------------------------
+pdfTeX 3.141592-1.40.0-alpha-20060106 was released on 2006-01-06
+----------------------------------------------------------------
+- many small fixes to remove warnings from -Wall
+- removed some unused variables
+- really fix bug 444
+- add some GCC extensions and use *nprintf instead of *printf where possible
+- fixed a unicode bug in ttf2afm
+  
+----------------------------------------------------------------
+pdfTeX 3.141592-1.40.0-alpha-20051226 was released on 2005-12-26
+----------------------------------------------------------------
+- improved patches:
+  - 453	Object Streams for PDF-1.5
+  - take PK resolution from "pk_dpi" parameter in  texmf.cnf, if it has not
+    been set by the format file or by the user
+  - 432	Rules in a PDF qQ group
+- some fixes for Thanhs patch
+- some improvements from -Wall
+- .indent.pro for indent
+
+----------------------------------------------------------------
+pdfTeX 3.141592-1.40.0-alpha-20051221 was released on 2005-12-21
+----------------------------------------------------------------
+- has a large patch from Thanh
+- pdflastlink has been fixed
+- remove generated pdf in case of fatal error
+
+----------------------------------------------------------------
+pdfTeX 3.141592-1.40.0-alpha-20051208 was released on 2005-12-08
+----------------------------------------------------------------
+- improved patches:
+  - 386	grow obj_tab and dest_names arrays dynamically
+  - 453	Object Streams for PDF-1.5
+  - take PK resolution from "pk_dpi" parameter in  texmf.cnf, if it has not
+    been set by the format file or by the user
+- write out PDF statistics later to make them correct
+- makefile target pdfetex-all.pdf for a huge file
+
+----------------------------------------------------------------
+pdfTeX 3.141592-1.40.0-alpha-20051205 was released on 2005-12-05
+----------------------------------------------------------------
+- has these patches:
+  - 386	grow obj_tab and dest_names arrays dynamically
+  - 416	new primitive pdflastlink
+  - 427	Character positioning patch
+  - 432	Rules in a PDF qQ group
+  - 434	Remove queued map item handling
+  - 438	\pdfsavepos in DVI mode
+  - 443	512 zeros in Type1 fonts not copied anymore
+  - 447	Don't write /Encoding for non-reencoded fonts
+  - 453	Object Streams for PDF-1.5
+  - take PK resolution from "pk_dpi" parameter in  texmf.cnf, if it has not
+    been set by the format file or by the user
+
+-------------------------------------------------
+pdfTeX 3.141592-1.30.6 was released on 2006-02-16
+-------------------------------------------------
+- bugfix: updated xpdf to 3.01pl2
+
+-------------------------------------------------
+pdfTeX 3.141592-1.30.5 was released on 2005-12-04
+-------------------------------------------------
+- bugfix: \pdfximage prints the file name twice (bug 441)
+- bugfix: buffer overflow with \pdfmatch (bug 444)
+- bugfix: updated xpdf to 3.01pl1
+
+-------------------------------------------------
+pdfTeX 3.141592-1.30.4 was released on 2005-10-17
+-------------------------------------------------
+- bugfix: whitespaces in filenames didn't work on Unix anymore (bug 377)
+- bugfix: two \immediates cancel themselves (bug 437)
+- bugfix: wrong file name in error messages of image inclusion (bug 435)
+
+-------------------------------------------------
+pdfTeX 3.141592-1.30.3 was released on 2005-09-04
+-------------------------------------------------
+- bugfix: \write18
+
+-------------------------------------------------
+pdfTeX 3.141592-1.30.2 was released on 2005-08-25
+-------------------------------------------------
+- fixed some build problems and minor bugs introduced in 1.30.1
+
+-------------------------------------------------
+pdfTeX 3.141592-1.30.1 was released on 2005-08-21
+-------------------------------------------------
+- the eTeX extensions can now be enabled with the cmdline switch -etex
+- pdfTeX uses xpdf 3.01
+
+-------------------------------------------------
+pdfTeX 3.141592-1.30.0 was released on 2005-08-01
+-------------------------------------------------
+- pdfxtex (introduced with 1.20a) is gone; all extensions are now in pdf(e)tex.
+- Some primitives have been renamed; the old names will still work, but are
+  deprecated and some give a warning that they are obsolete:
+    \pdfoptionpdfminorversion         -> \pdfminorversion
+    \pdfoptionalwaysusepdfpagebox     -> \pdfforcepagebox
+    \pdfoptionpdfinclusionerrorlevel  -> \pdfinclusionerrorlevel
+- pdftex knows two new units:
+  - new Didot (1nd=0.375mm)
+  - new Cicero (1nc=12nd)
+- New primitives: 
+  - Inclusion of pngs has been greatly improved: It now does
+    - alpha channel and transparency (only if %!PDF >=1.4)
+    - 16-bit colour (only if %!PDF >=1.5); this must be enabled by setting
+      \pdfimagehicolor to 1.
+    - gamma correction; this must be enabled by setting \pdfimageapplygamma to
+      1. The device gamma is taken from \pdfgamma. If no embedded value can be
+      found in the png image, then the value of \pdfimagegamma is used instead.
+    - fast direct embedding of png streams, if their structure allows this; the
+      automatic fall-back is to decompress and re-compress as before.
+  - pdfTeX now has an interface to the precise system time (if available) as an
+    aid in benchmarking TeX macro code. 
+    - \pdfelapsedtime is a read-only integer that (initially) returns the
+      amount of time passed since the start of this run. This amount is given
+      in `scaled seconds': the value 65536 counts as one second. If more time
+      has passed than 32767 seconds, (2^31)-1 will be returned.
+    - \pdfresettimer updates the internal timer, such that subsequent calls to
+      \pdfelapsedtime will restart from 0.
+  - pdfTeX can now generate random numbers:
+    - \pdfuniformdeviate <count> generates a uniformly distributed random
+      integer value between 0 (inclusive) and <count> (exclusive).
+    - \pdfnormaldeviate expands to a random integer value with a mean of 0 and
+      a unit of 65536. 
+    - \pdfrandomseed allows access to the current seed value.
+    - \pdfsetrandomseed <count> sets the random seed to a specific value.
+  - \pdfnoligatures\f disables ligatures for the loaded font \f.
+  - Escaping strings:
+    - \pdfescapestring{<a>} escapes the string <a> so that it can be used as
+      PDF string.
+    - \pdfescapename{<a>} escapes the string <a> so that it can be used as PDF
+      name.
+    - \pdfescapehex{<a>} converts the string <a> to uppercase hexadecimal
+      representation.
+    - \pdfunescapehex{<b>} reverses the effect of \pdfescapehex
+  - \pdfcreationdate expands to the date string that pdfTeX uses in the info
+    dict as default.
+  - \pdffilemoddate{<file>} expands to the modification date of <file> in the
+    same format as \pdfcreationdate (PDF date format).
+  - \pdffilesize{<file>} expands to the size of <file> as string.
+  - \pdfmdfivesum{<abc>} or \pdfmdfivesum file {<file>} calculates the md5
+    sum (of a string or a file) and converts it to uppercase hexadecimal format
+    (same as \pdfescapehex).
+  - \pdffiledump [offset <int>] [length <int>] <general text>
+    Expands to a hex dump of the file given in <general text>, starting at
+    given offset or 0 with given length.
+  - \pdfshellescape is a read-only integer that is 1 if \write18 is enabled, 0
+    otherwise.
+  - \pdfxformname <object number>, which expands to the number in the
+    corresponding form XObject name.
+  - \leftmarginkern <box number> and \rightmarginkern <box number> tell the
+    margin kern at the left and right side of the horizontal list stored in box
+    <box number>.
+  - \pdfpkmode is a token register that sets the MF mode for pixel font
+    generation. The contents of this register is dumped into the format, so one
+    can (optionally) preset it e.g. in part of pdftexconfig.tex.
+  - \pdftracingfonts: An integer variable controlling the tracing of font
+    expansion. It is zero by default; then we get a log (with fontexpansion)
+    like this
+    ...\tenrm t
+    ...\tenrm (+20) e
+    Without font expansion, this default should be compatible with TeX's
+    original log output.
+    If \pdftracingfonts is set to 1 (or greater), we get a more verbose log:
+    ...\xivtt (cmtt10 at 14.0pt) t
+    ...\xivtt (cmtt10+20 at 14.0pt) e
+    See also bug 304.
+- New experimental primitives:
+  - \pdfmatch [icase] [subcount <number>}] {<pattern>}{<string>}
+    Implements pattern matching using the POSIX regex.
+    It returns the same values as \pdfstrcmp, but with the following semantics: 
+      -1: error case (invalid pattern, ...)
+       0: no match
+       1: match found
+    Options:
+    * icase: case insensitive matching
+    * subcount: it sets the table size for found subpatterns.
+      A number "-1" resets the table size to the start default.
+  - \pdflastmatch <number>
+    The result of \pdfmatch is stored in an array. The entry "0" contains the
+    match, the following entries submatches. The positions of the matches are
+    also available. They are encoded:
+      <position> "->" <match string>
+    The position "-1" with an empty string indicates that this entry is not
+    set.
+  - \pdfstrcmp{<a>}{<b>} compares two strings and returns the strings "0" if
+    <a> equals <b>, "-1" if <a> is less than <b>, "1" if <a> is greater than
+    <b>
+- The primitive \pdfmovechars has been removed (bug 294)
+- Bugfixes:
+  - empty strings are not supressed anymore (bug 335)
+  - \unhboxing and character protusion didn't work well together (bug 292)
+  - --jobname didn't work if there was no filename at all (bug 302)
+  - Some problem with fonts on solaris (bug 315)
+  - Dangling font objects with non-replacable fonts (bug 311).
+  - \pdfxform didn't work with box>255 (bug 310)
+  - cmap: unicode ???? is mapped to multiple glyphs (bug 306).
+- pdfTeX uses zlib 1.2.3
+
 ------------------------------------------------
 pdfTeX 3.141592-1.21a was released on 2005-02-04
 ------------------------------------------------
@@ -6,32 +256,24 @@
     - added some more info to the AFM output
     - some minor bug fixes
     - a short documentation available
-
 - pdftex now understand forms 'uniXXXX' in encoding files (only makes sense
   with TrueType fonts)
-
 - added subset tag for TrueType fonts
-
 - PDF strings are now printed as following:
     (This is a string) -> (This is a string)
     This is a string -> (This is a string)
     <a1b245c1a2...> -> <a1b245c1a2...>
-
 - check for double newline char to get rid of empty lines in PDF output
-
-- Fixed a bug in the scanning of map lines introduced in the the fix of bug
-  #242 in 1.20b.
-  
+- Fixed a bug in the scanning of map lines introduced in the fix of bug #242 in
+  1.20b.
 - Fixed three problems in xpdf; xpdf is now 3.00pl3
-
 - \ifeof18 is a simple method to test if \write18 is enabled.
-
 - a few extensions in pdfxtex:
     - \pdflastximagecolordepth returns the last color depth
     - \pdfximage supports a keyword "colorspace" following an object number
       representing a ColorSpace object
     - \pdfstrcmp compares two strings
-    - \pdfescapestring/\pdflastescapedstring provide a mean to escape string
+    - \pdfescapestring/\pdflastescapedstring provide a way to escape string
     - \pdffirstlineheight/\pdflastlinedepth/\pdfeachlineheight/\pdfeachlinedepth
       allow fixing line dimen
     - patches from Taco
@@ -43,47 +285,33 @@
 pdfTeX 3.141592-1.20b was released on 2004-12-22
 ------------------------------------------------
 - Fixed some minor bugs, mostly with hz
-
 - The info line "output format initialized to PDF/DVI" isn't shown anymore, as
   this info wasn't reliable (bug 112).
-
 - Now the PDF-related statistics (PDF objects...) in the .log file is only
   shown in PDF output mode. It start with a line "PDF statistics:".
-
 - \pdfimageresolution is not limited to 2400 [dpi] anymore, can now be between
   0 and 65535 [dpi].
-
 - pdfTeX uses xpdf 3.00pl2
-
 - pdfTeX uses libpng 1.2.8, which fixes some png-related bugs.
 
 ------------------------------------------------
 pdfTeX 3.141592-1.20a was released on 2004-09-06
 ------------------------------------------------
-
-Major changes since 1.11b
--------------------------
 - There is a new program pdfxtex, which contains experimental features which
   might end up in pdftex in the future.
-
 - Most distributions now use eTeX as the default engine, so when you call
   pdftex you will get pdfeTeX. Most distributions now also use pdfTeX as the
   default engine, so when you call latex you will get pdfeTeX running LaTeX.:-)
-
 - We are setting up pdfTeX as a project at sarovar
   (http://sarovar.org/projects/pdftex/). Please report bugs etc. through the
   site.
-
 - Support for the file pdftex.cfg is gone completely. All parameters that had
   previously been set by it can be set through primitives; their values are
   dumped to the format file.
-  
 - The searchpath for encoding and mapfiles has been changed.
   See http://tug.org/pipermail/tex-live/2004-January/004734.html and
   http://tug.org/pipermail/tex-live/2004-January/004791.html
-
 - eTeX is now version 2.2, incorporating the last changes to TeX (3.141592).
-
 - New options for \pdfmapfile:
   General functionality: Map items (map files, new: also single map lines; see
   \pdfmapline) are put in list of pending map items. During the next shipout,
@@ -106,84 +334,59 @@
     foo.map is scanned, matching map entries are deleted from database.
   - \pdfmapfile {} clears the list of pending map items. It does not affect map
     entries already registered into the database. This is the old behaviour.
-
 - New command \pdfmapline {line}. It's like \pdfmapfile but here you can set
   single map lines like in the map files directly. The modifiers (+-=) have the
   same effect as with \pdfmapfile.
-
 - Simplified the handling of the 14 Type 1 "standard fonts" (Times,
   Helvetica...): They are now more or less handled like any other Type 1 font.
   See http://www.ntg.nl/pipermail/ntg-pdftex/2004-July/000648.html
-
 - hz: So far the font expansion feature required that the user must be able to
   create expanded tfms (eg cmr10+10.tfm). Now font expansion can be used
   without creating these tfms.
   See http://www.ntg.nl/pipermail/ntg-pdftex/2004-May/000504.html
-  
 - hz: Changed \pdffontexpand primitive --> the expand factor is now fixed to
   1000 and the argument is ignored. This will lead to spurious texts of "1000"
   in your output if you compile old documents.
-
 - New command \pdftexbanner which returns a string with the full banner of the
   current binary (e.g. "This is pdfTeX, Version 3.141592-1.20a (Web2C 7.5.3)
   kpathsea version 3.5.3")
-
 - The PTEX.FullBanner key is now inserted in the document info dict instead of
   the catalog. Newer versions of Acrobat display it.
-  
 - Now includes support for encTeX.
-
 - Extended \pdfannot to use reserveobjnum/useobjnum 
   See http://www.ntg.nl/pipermail/ntg-pdftex/2004-March/000424.html
-
 - Bugfix: pdfTeX would read an .xpdfrc when including pdfs.
   See http://tug.org/pipermail/pdftex/2004-March/004835.html
-
 - Bugfix: The strings in /ID would sometimes be empty.
-  
 - Bugfix: Even when mapfiles or encodings or PostScript font files were
   missing, pdfTeX still produced a (most often corrupt) pdf. Now it aborts with
   an error in these cases.
-
 - numerous small bugfixes.
-  
 - pdfTeX now uses the GNU libavl from Ben Pfaff for managing of fontmap
   entries.
-  
 - pdfTeX uses zlib 1.2.1
-
 - pdfTeX uses xpdf 3.00
-
 - pdfTeX uses libpng 1.2.7
   
 ------------------------------------------------
 pdfTeX 3.141592-1.11b was released on 2003-10-06
 ------------------------------------------------
-
-Major changes since 1.11a
--------------------------
 - Bugfix: The handling of /Rotate produced displaced images when /Rotate was 90
   or 270.
 
 ------------------------------------------------
 pdfTeX 3.141592-1.11a was released on 2003-08-02
 ------------------------------------------------
-
-Major changes since 1.10b
--------------------------
 - New command \pdftrailer analogue to \pdfcatalog whose argument ends up in the
   trailer dictionary.
-
 - The behaviour when an included pdf has a newer version than the one specified
   with \pdfoptionpdfminorversion can be controlled by the new internal integer
   \pdfoptionpdfinclusionerrorlevel: If it's 0, pdfTeX gives only a warning; if
   it's 1, it raises an error. 
     This can also be set in pdftex.cfg with pdf_inclusion_errorlevel
-
 - The syntax for outlines has been extended to allow attributes:
   <outline spec> --> <attr spec> <action spec> [count <number>] <general text>
   See http://www.ntg.nl/pipermail/ntg-pdftex/2003-June/000165.html
-
 - The syntax of \pdfobj has been extended:
   \pdfobj <object type spec>                              (h, v, m)
   <object type spec> --> reserveobjnum
@@ -193,63 +396,45 @@
   When the optional keyword `reserveobjnum' and `useobjnum' is not given, the
   behaviour is unchanged. 
   See also http://tug.org/mailman/htdig/pdftex/2003-March/003814.html
-
 - Bugfix: /CreationDate didn't care for the timezone and could be fooled.
   See http://www.ntg.nl/pipermail/ntg-pdftex/2003-July/000223.html
-
 - Bugfix: The translation of 8-bit characters in included pdfs that had their
   eighth bit set sometimes got wrong because of a missing typecast.
   See http://www.ntg.nl/pipermail/ntg-pdftex/2003-July/000216.html
-  
 - Bugfix: pdfTeX -ini would crash with a minimal file because it didn't read
   it's config and so didn't know anything about fonts.
   See http://tug.org/pipermail/pdftex/2003-July/004262.html
-  
 - Bugfix: \pdfstartlink would produce spurious /NewWindow entries. Also the
   syntax of <action spec> and <goto-action spec> has been cleaned up.
   See http://www.ntg.nl/pipermail/ntg-pdftex/2003-June/000167.html 
-
 - Bugfix: \pdffontattr was not used for T3 fonts.
   See http://tug.org/pipermail/pdftex/2003-June/004127.html
-
 - Bugfix: The cropbox of an included pdf would sometimes not be used.
   See http://tug.org/pipermail/pdftex/2003-May/004037.html
-
 - pdfTeX uses xpdf 2.02
 
 ------------------------------------------------
 pdfTeX 3.141592-1.10b was released on 2003-02-26
 ------------------------------------------------
-
-Major changes since 1.10a
--------------------------
 - The numbers in transformation matrices are allways written with maximum
   precision (see http://tug.org/pipermail/pdftex/2003-February/003596.html).
-
 - Incorporated the new version of TeX: 3.141592
-
 - Bugfix: Numbers in pdfs would sometimes be just a wee bit of (changed
   implementation of pdftoepdf.convertNumToPDF).
-
 - Bugfix: When setting the /Producer, /Creator or /CreationDate keys with
   /pdfinfo pdfTeX would also insert default values which caused duplicate keys
   in the info dict (see
   http://tug.org/pipermail/pdftex/2003-February/003524.html).
-
 - The reading of mapfiles is much faster (see
   http://tug.org/pipermail/pdftex/2002-July/002843.html).
-  
 - Bugfix: AR5 had problems with the CTM when displaying in "fit visible" mode
   (see http://tug.org/pipermail/pdftex/2002-May/002688.html).
-
 - Bugfix: str_in_str had wrong indices (see
   http://tug.org/pipermail/pdftex/2002-March/002367.html).
-
 - Bugfix: decimal_digits defaulted to 0, which caused problems with included
   images when including pdfs (see
   http://tug.org/pipermail/pdftex/2003-February/003518.html). 
   It now defaults to 4.
-  
 - Bugfix: the type of included images was decided based only on the extensions;
   now pdfTeX looks for magic bytes at the start of files (see
   http://tug.org/pipermail/pdftex/2003-February/003519.html)
@@ -257,9 +442,6 @@
 -----------------------------------------------
 pdfTeX 3.14159-1.10a was released on 2003-01-16
 -----------------------------------------------
-
-Major changes since 1.0
------------------------
 - pdfTeX is now able to produce pdf1.4 (which is also the default) and has
   almost complete support for including pdf1.4 files:
   - Additional attributes like MetaData are copied from included pdfs.
@@ -278,7 +460,6 @@
       See pdftoepdf.cc for preprocessor flags which allow this behaviour to be
     changed (copying the Page Group (most likely producing incorrect pdf) or
     treating Page Groups as errors).
-    
 - The new primitive \pdfoptionpdfminorversion sets the pdf version of the
   generated file and the latest allowed pdf version of included pdfs:
         \pdfoptionpdfminorversion=3
@@ -288,7 +469,6 @@
     This must appear before any data is written to the generated pdf file, so
   you should put it at the very start of your files.
     This can also be set in pdftex.cfg with pdf_minorversion
-
 - It is now possible to specify the pdf page box to use when including pdfs.
   The syntax has been extended:
     \pdfximage [<image attr spec>] <general text>           (h, v, m)
@@ -303,29 +483,22 @@
   and 5 is artbox. This can only be set once per object, i.e. the value used at
   \pdfximage is remembered.
     See the pdf reference for an explanation of the boxes.
-  
 - The support for the inclusion of jpeg images has been extended to allow the
   inclusion of JPEG/Exif files which are produced by digital photo cameras
   (thanks to Hartmut Henkel).
-
 - The support for the inclusion of tif images has been removed as it was of
   limited use (it worked only for gray-scale and rgb images) and produced wrong
   results (all other images types where treated as rgb images). 
   Tif images can be converted on *nix on-the-fly to pngs with the help of
   ImageMagick, epstopdf.sty or pdftex.def v0.4 or newer, and this rule:
     \DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `basename #1 .tif`.png}
-
 - The extensions for pdf encryption have been removed, since they make the
   pdfTeX code overly complex. Those needing pdf encryption are encouraged to
   produce a standalone program for encrypting pdfs.
-
 - pdfTeX now writes a usage statistic about the pdfTeX specific memory to the
   log.
-
 - numerous bugfixes, most of them in the inclusion of pdfs.
-
 - pdfTeX uses xpdf 2.01
-
 - pdfTeX uses libpng 1.2.5
 
 ---------------------------------------------------------------------
@@ -340,5 +513,5 @@
 pdfTeX 3.14159-1.00a-pretest-20010804 was released on 2001-08-04
 ----------------------------------------------------------------
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/NEWS#80 $
+$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/NEWS#86 $
 // vim: tw=79:ts=2:expandtab:autoindent

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/README
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/README	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/README	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,25 +1,18 @@
 pdfTeX
 ======
 
-README for version 3.14159-1.21a of $Date: 2005/02/04 $
-=======================================================
+README for version 3.14159-1.40.0-beta-20060725
+===============================================
 
-This directory contains the version 1.21a of pdfTeX, an extended version of
-TeX that can create PDF directly from TeX source files and enhance the
-result of TeX typesetting with the help of PDF. When PDF output is not
-selected, pdfTeX produces normal DVI output, otherwise it produces PDF
-output that looks identical to the DVI output. An important aspect of this
-project is to investigate alternative justification algorithms, optionally
-making use of multiple master fonts. 
+This directory contains the version 1.40.0-alpha-20060725 of pdfTeX, an
+extended version of eTeX that can create PDF directly from TeX source files
+and enhance the result of TeX typesetting with the help of PDF. When PDF
+output is not selected, pdfTeX produces normal DVI output, otherwise it
+produces PDF output that looks identical to the DVI output. An important
+aspect of this project is to investigate alternative justification
+algorithms, optionally making use of multiple master fonts. 
 
-pdfeTeX is an even more extended version of TeX than pdfTeX because it is
-not based on TeX but on eTeX, an extended version of TeX. 
-
-pdfxTeX is an experimental version of pdfeTeX, which apart from pdfTeX and
-eTeX contains some features for testing purpose. When some feature seems to
-be useful and stable, it can be moved to pdfTeX.
-
-pdfTeX is based on the original TeX sources and Web2c, and has been
+pdfTeX is based on the original eTeX sources and Web2c, and has been
 successfully compiled on Unix, Win32 and DOS systems. It is still under
 development and features may change; it produces reasonable PDF code.
 
@@ -40,7 +33,7 @@
 LEGAL ISSUES
 ============
 
-pdfTeX is copyright (c) 1996-2005 Han The Thanh, <thanh at pdftex.org>
+pdfTeX is copyright (c) 1996-2006 Han The Thanh, <thanh at pdftex.org>
 
 pdfTeX is free software; you can redistribute it and/or modify it under the
 terms of the GNU General Public License as published by the Free Software
@@ -76,10 +69,10 @@
 ============
 
 Peter Breitenlohner, Ricardo Sanchez Carmenes, Otfried Cheong, Thomas
-Esser, Hans Hagen, Hartmut Henkel, Tom Kacvinsky, Akira Kakuto, Reinhard
-Kotucha, Derek B. Noonburg, Heiko Oberdiek, Jiri Osoba, Fabrice Popineau,
-Sebastian Rahtz, Tomas Rokicki, Martin Schröder, Petr Sojka, Olaf Weber,
-Jiri Zlatuska.
+Esser, Hans Hagen, Hartmut Henkel, Taco Hoekwater, Pawel Jackowski, Tom
+Kacvinsky, Akira Kakuto, Reinhard Kotucha, Derek B. Noonburg, Heiko
+Oberdiek, Jiri Osoba, Fabrice Popineau, Sebastian Rahtz, Tomas Rokicki,
+Martin Schröder, Petr Sojka, Ralf Utermann. Olaf Weber, Jiri Zlatuska.
 
 pdfTeX is built on top of TeX, written by Donald Knuth cum suis (Liang and
 so), and eTeX, written by Peter Breitenlohner cum suis; part of the
@@ -88,9 +81,7 @@
 
 ------------------------------------------------------------------------------
 
-See the file TODO for work to be done.
-
 Please send bug reports, offers of help, etc. to martin at pdftex.org
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/README#26 $
+$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/README#30 $
 // vim: tw=75

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/avlstuff.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/avlstuff.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/avlstuff.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2004 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 2004-2005 Han The Thanh, <thanh at pdftex.org>
 
 This file is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by Free
@@ -15,9 +15,8 @@
 with this file; if not, write to the Free Software Foundation, Inc.,
 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/avlstuff.c#5 $
+$Id: avlstuff.c,v 1.12 2005/07/11 20:27:39 hahe Exp hahe $
 
-formatted by indent -kr
 */
 
 #include "ptexlib.h"
@@ -26,7 +25,7 @@
 #include "avl.h"
 
 static const char perforce_id[] =
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/avlstuff.c#5 $";
+    "$Id: avlstuff.c,v 1.12 2005/07/11 20:27:39 hahe Exp hahe $";
 
 /* One AVL tree for each obj_type 0...pdfobjtypemax */
 
@@ -36,16 +35,16 @@
 
 /* memory management functions for avl */
 
-void *avl_xmalloc(struct libavl_allocator *allocator, size_t size)
+void *avl_xmalloc (struct libavl_allocator *allocator, size_t size)
 {
-    assert(allocator != NULL && size > 0);
-    return xmalloc(size);
+    assert (allocator != NULL && size > 0);
+    return xmalloc (size);
 }
 
-void avl_xfree(struct libavl_allocator *allocator, void *block)
+void avl_xfree (struct libavl_allocator *allocator, void *block)
 {
-    assert(allocator != NULL && block != NULL);
-    xfree(block);
+    assert (allocator != NULL && block != NULL);
+    xfree (block);
 }
 
 struct libavl_allocator avl_xallocator = {
@@ -53,67 +52,71 @@
     avl_xfree
 };
 
+typedef struct oentry_ {
+    integer int0;
+    integer objptr;
+} oentry;
 
-/* AVL sort objentry into avl_table[] */
+/* AVL sort oentry into avl_table[] */
 
-int compare_info(const void *pa, const void *pb, void *param)
+int compare_info (const void *pa, const void *pb, void *param)
 {
     integer a, b;
     int as, ae, bs, be, al, bl;
 
-    a = ((const objentry *) pa)->int0;
-    b = ((const objentry *) pb)->int0;
-    if (a < 0 && b < 0) {        /* string comparison */
+    a = ((const oentry *) pa)->int0;
+    b = ((const oentry *) pb)->int0;
+    if (a < 0 && b < 0) {       /* string comparison */
         as = strstart[-a];
-        ae = strstart[-a + 1];        /* start of next string in pool */
+        ae = strstart[-a + 1];  /* start of next string in pool */
         bs = strstart[-b];
         be = strstart[-b + 1];
         al = ae - as;
         bl = be - bs;
-        if (al < bl)                /* compare first by string length */
+        if (al < bl)            /* compare first by string length */
             return -1;
-        else if (al > bl)
+        if (al > bl)
             return 1;
-        else
-            for (; as < ae; as++, bs++) {
-                if (strpool[as] < strpool[bs])
-                    return -1;
-                if (strpool[as] > strpool[bs])
-                    return 1;
-            }
-        return 0;
-    } else {                        /* integer comparison */
+        for (; as < ae; as++, bs++) {
+            if (strpool[as] < strpool[bs])
+                return -1;
+            if (strpool[as] > strpool[bs])
+                return 1;
+        }
+    } else {                    /* integer comparison */
         if (a < b)
             return -1;
-        else if (a > b)
+        if (a > b)
             return 1;
-        else
-            return 0;
     }
+    return 0;
 }
 
-
-void avlputobj(integer objptr, integer t)
+void avlputobj (integer objptr, integer t)
 {
     static void **pp;
+    static oentry *oe;
 
     if (PdfObjTree[t] == NULL) {
-        PdfObjTree[t] = avl_create(compare_info, NULL, &avl_xallocator);
+        PdfObjTree[t] = avl_create (compare_info, NULL, &avl_xallocator);
         if (PdfObjTree[t] == NULL)
-            pdftex_fail("avlstuff.c: avl_create() PdfObjTree failed");
+            pdftex_fail ("avlstuff.c: avl_create() PdfObjTree failed");
     }
-    pp = avl_probe(PdfObjTree[t], &(objtab[objptr]));
+    oe = xtalloc (1, oentry);
+    oe->int0 = objtab[objptr].int0;
+    oe->objptr = objptr;        /* allows to relocate objtab */
+    pp = avl_probe (PdfObjTree[t], oe);
     if (pp == NULL)
-        pdftex_fail("avlstuff.c: avl_probe() out of memory in insertion");
+        pdftex_fail ("avlstuff.c: avl_probe() out of memory in insertion");
 }
 
 
-/* replacement for linear search pascal function "find_obj" */
+/* replacement for linear search pascal function "find_obj()" */
 
-integer avlfindobj(integer t, integer i, integer byname)
+integer avlfindobj (integer t, integer i, integer byname)
 {
-    static objentry *p;
-    static objentry tmp;
+    static oentry *p;
+    static oentry tmp;
 
     if (byname > 0)
         tmp.int0 = -i;
@@ -121,11 +124,29 @@
         tmp.int0 = i;
     if (PdfObjTree[t] == NULL)
         return 0;
-    p = (objentry *) avl_find(PdfObjTree[t], &tmp);
+    p = (oentry *) avl_find (PdfObjTree[t], &tmp);
     if (p == NULL)
         return 0;
-    else
-        return (int) (p - (objentry *) objtab);
+    return p->objptr;
 }
 
-/* end of file avlstuff.c */
+/**********************************************************************/
+/* cleaning up... */
+
+static void destroy_oentry (void *pa, void *pb)
+{
+    oentry *p = (oentry *) pa;
+    xfree (p);
+}
+
+void PdfObjTree_free ()
+{
+    int i;
+
+    for (i = 0; i <= pdfobjtypemax; i++) {
+        if (PdfObjTree[i] != NULL)
+            avl_destroy (PdfObjTree[i], destroy_oentry);
+    }
+}
+
+/**********************************************************************/

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/depend.mk
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/depend.mk	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/depend.mk	2006-07-26 16:32:24 UTC (rev 1534)
@@ -27,7 +27,7 @@
 writeenc.o: writeenc.c ptexlib.h ../pdftexd.h ../texmfmp.h \
  ../cpascal.h ../config.h ../help.h ../texmfmem.h ../pdftexcoerce.h \
  ptexmac.h
-writettf.o: writettf.c ptexlib.h ../pdftexd.h ../texmfmp.h \
+writettf.o: writettf.c ptexlib.h writettf.h ../pdftexd.h ../texmfmp.h \
  ../cpascal.h ../config.h ../help.h ../texmfmem.h ../pdftexcoerce.h \
  ptexmac.h macnames.c
 writejpg.o: writejpg.c ptexlib.h ../pdftexd.h ../texmfmp.h \
@@ -45,7 +45,7 @@
  ../../../libs/xpdf/xpdf/XRef.h ../../../libs/xpdf/xpdf/Catalog.h \
  ../../../libs/xpdf/xpdf/Page.h ../../../libs/xpdf/xpdf/GfxFont.h \
  ../../../libs/xpdf/xpdf/Error.h epdf.h
-ttf2afm.o: ttf2afm.c macnames.c
+ttf2afm.o: ttf2afm.c writettf.h macnames.c
 pdftosrc.o: pdftosrc.cc ../../../libs/xpdf/xpdf/Object.h \
  ../../../libs/xpdf/xpdf/Array.h ../../../libs/xpdf/xpdf/Dict.h \
  ../../../libs/xpdf/xpdf/Stream.h ../../../libs/xpdf/xpdf/XRef.h \

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/epdf.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/epdf.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/epdf.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,61 +17,59 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/epdf.c#7 $
+$Id: epdf.c,v 1.2 2005/12/26 13:21:22 hahe Exp hahe $
 */
 
 #include "ptexlib.h"
 #include <kpathsea/c-vararg.h>
 #include <kpathsea/c-proto.h>
+#include <string.h>
 
-integer pdfbufmax = pdfbufsize;
+extern void epdf_check_mem (void);
 
-extern void epdf_check_mem(void);
-
-int is_subsetable(fm_entry *fm)
+int is_subsetable (fm_entry * fm)
 {
-    return is_included(fm) && is_subsetted(fm);
+    return is_included (fm) && is_subsetted (fm);
 }
 
-int is_type1(fm_entry *fm)
+int is_type1 (fm_entry * fm)
 {
-    return is_t1fontfile(fm);
+    return is_t1fontfile (fm);
 }
 
-void mark_glyphs(fm_entry *fm, char *charset)
+void mark_glyphs (fm_entry * fm, char *charset)
 {
     char *new_charset = fm->charset;
     if (charset == NULL)
         return;
     if (new_charset == NULL)
-        new_charset = xstrdup(charset);
+        new_charset = xstrdup (charset);
     else {
-        new_charset = xretalloc(new_charset, 
-                                strlen(new_charset) + strlen(charset) + 1,
-                                char);
-        strcat(new_charset, charset);
+        xretalloc (new_charset, strlen (new_charset) + strlen (charset) + 1,
+                   char);
+        strcat (new_charset, charset);
     }
     fm->charset = new_charset;
 }
 
-void embed_whole_font(fm_entry *fm)
+void embed_whole_font (fm_entry * fm)
 {
     fm->all_glyphs = true;
 }
 
-integer get_fontfile(fm_entry *fm)
+integer get_fontfile (fm_entry * fm)
 {
     return fm->ff_objnum;
 }
 
-integer get_fontname(fm_entry *fm)
+integer get_fontname (fm_entry * fm)
 {
     if (fm->fn_objnum == 0)
-        fm->fn_objnum = pdfnewobjnum();
+        fm->fn_objnum = pdfnewobjnum ();
     return fm->fn_objnum;
 }
 
-void epdf_free(void)
+void epdf_free (void)
 {
-    epdf_check_mem();
+    epdf_check_mem ();
 }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/epdf.h
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/epdf.h	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/epdf.h	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,87 +17,100 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/epdf.h#15 $
+$Id: epdf.h,v 1.6 2005/11/28 23:29:32 hahe Exp $
 */
 
 extern "C" {
 
 #include <kpathsea/c-auto.h>
 
+    extern char *xstrdup (const char *);
+
 /* the following code is extremly ugly but needed for including web2c/config.h */
 
-#include <kpathsea/c-proto.h>     /* define P?H macros */
+#include <kpathsea/c-proto.h>   /* define P?H macros */
 
-typedef const char *const_string; /* including kpathsea/types.h doesn't work on some systems */
+    typedef const char *const_string;   /* including kpathsea/types.h doesn't work on some systems */
 
-#define KPATHSEA_CONFIG_H         /* avoid including other kpathsea header files */
-                                  /* from web2c/config.h */
+#define KPATHSEA_CONFIG_H       /* avoid including other kpathsea header files */
+    /* from web2c/config.h */
 
-#ifdef CONFIG_H                   /* CONFIG_H has been defined by some xpdf */
-#undef CONFIG_H                   /* header file */
+#ifdef CONFIG_H                 /* CONFIG_H has been defined by some xpdf */
+#  undef CONFIG_H               /* header file */
 #endif
 
-#include <web2c/c-auto.h>         /* define SIZEOF_LONG */
-#include <web2c/config.h>         /* define type integer */
+#include <web2c/c-auto.h>       /* define SIZEOF_LONG */
+#include <web2c/config.h>       /* define type integer */
 
 #include <web2c/pdftexdir/ptexmac.h>
 
-#define pdfbufsize      pdfbufmax
+/* #-define pdfbufsize      pdfbufmax */
 
-extern float epdf_width;
-extern float epdf_height;
-extern float epdf_orig_x;
-extern float epdf_orig_y;
-extern integer epdf_selected_page;
-extern integer epdf_num_pages;
-extern integer epdf_page_box;
-extern integer epdf_always_use_pdf_pagebox;
-extern void *epdf_doc;
-extern void *epdf_xref;
+    extern float epdf_width;
+    extern float epdf_height;
+    extern float epdf_orig_x;
+    extern float epdf_orig_y;
+    extern integer epdf_selected_page;
+    extern integer epdf_num_pages;
+    extern integer epdf_page_box;
+    extern void *epdf_doc;
+    extern void *epdf_xref;
 
-extern integer pdfstreamlength;
-extern integer pdfptr;
-typedef unsigned char eightbits  ;
-extern eightbits pdfbuf[];
-extern integer pdfbufmax;
+    extern integer pdfboxspecmedia;
+    extern integer pdfboxspeccrop;
+    extern integer pdfboxspecbleed;
+    extern integer pdfboxspectrim;
+    extern integer pdfboxspecart;
 
-extern char notdef[];
+    extern integer pdfstreamlength;
+    extern integer pdfptr;
+    extern integer poolptr;
+    typedef unsigned char eightbits;
+    extern eightbits *pdfbuf;
+    extern integer pdfbufsize;
+    extern integer pdfosmode;
+    extern eightbits pdflastbyte;
 
-extern int is_subsetable(struct fm_entry *);
-extern int is_type1(struct fm_entry *);
-extern struct fm_entry * lookup_fontmap(char *);
-extern integer get_fontfile(struct fm_entry *);
-extern integer get_fontname(struct fm_entry *);
-extern integer pdfnewobjnum(void);
-extern integer read_pdf_info(char*, char*, integer, integer, integer, integer);
-extern void embed_whole_font(struct fm_entry *);
-extern void epdf_check_mem(void);
-extern void epdf_delete(void);
-extern void epdf_free(void);
-extern void mark_glyphs(struct fm_entry *, char *);
-extern void pdf_printf(const char *fmt,...);
-extern void pdf_puts(const char *);
-extern void pdfbeginstream(void);
-extern void pdfendobj(void);
-extern void pdfendstream(void);
-extern void pdfflush(void);
-extern void pdftex_fail(const char *fmt,...);
-extern void pdftex_warn(const char *fmt,...);
-extern void tex_printf(const char *, ...);
-extern void write_enc(char **, struct enc_entry *, integer);
-extern void write_epdf(void);
-extern void zpdfbegindict(integer);
-extern void zpdfbeginobj(integer);
-extern void zpdfcreateobj(integer, integer);
-extern void zpdfnewdict(integer, integer);
+    extern char notdef[];
 
+    extern int is_subsetable (struct fm_entry *);
+    extern int is_type1 (struct fm_entry *);
+    extern struct fm_entry *lookup_fontmap (char *);
+    extern integer get_fontfile (struct fm_entry *);
+    extern integer get_fontname (struct fm_entry *);
+    extern integer pdfnewobjnum (void);
+    extern integer read_pdf_info (char *, char *, integer, integer, integer,
+                                  integer);
+    extern void embed_whole_font (struct fm_entry *);
+    extern void epdf_check_mem (void);
+    extern void epdf_delete (void);
+    extern void epdf_free (void);
+    extern void mark_glyphs (struct fm_entry *, char *);
+    extern void pdf_printf (const char *fmt, ...);
+    extern void pdf_puts (const char *);
+    extern void pdfbeginstream (void);
+    extern void pdfendobj (void);
+    extern void pdfendstream (void);
+    extern void pdfflush (void);
+    extern void pdftex_fail (const char *fmt, ...);
+    extern void pdftex_warn (const char *fmt, ...);
+    extern void tex_printf (const char *, ...);
+    extern void write_enc (char **, struct enc_entry *, integer);
+    extern void write_epdf (void);
+    extern void zpdfbegindict (integer, bool);
+    extern void zpdfbeginobj (integer, bool);
+    extern void zpdfcreateobj (integer, integer);
+    extern void zpdfnewdict (integer, integer, bool);
+    extern void zpdfosgetosbuf (integer);
+
 /* utils.c */
-extern char *convertStringToPDFString(char *in);
+    extern char *convertStringToPDFString (char *in, int len);
+    extern char *stripzeros (char *a);
 
 /* config.c */
-extern integer cfgpar(integer);
+    extern integer cfgpar (integer);
 
 /* avlstuff.c */
-extern void avl_put_obj (integer, integer);
-extern integer avl_find_obj (integer, integer, integer);
+    extern void avl_put_obj (integer, integer);
+    extern integer avl_find_obj (integer, integer, integer);
 }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/image.h
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/image.h	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/image.h	2006-07-26 16:32:24 UTC (rev 1534)
@@ -29,10 +29,10 @@
 #define JPG_UINT8       unsigned char
 
 typedef struct {
-    int color_space;    /* used color space. See JPG_ constants */
-    JPG_UINT8  bits_per_component; /* bits per component                         */
-    JPG_UINT32 length;             /* length of file/data                        */
-    FILE *file;                    /* jpg file                                   */
+    int color_space;            /* used color space. See JPG_ constants */
+    JPG_UINT8 bits_per_component;       /* bits per component                         */
+    JPG_UINT32 length;          /* length of file/data                        */
+    FILE *file;                 /* jpg file                                   */
 } JPG_IMAGE_INFO;
 
 typedef struct {
@@ -45,7 +45,6 @@
     integer orig_y;
     integer selected_page;
     integer page_box;
-    integer always_use_pdfpagebox;
     void *doc;
 } pdf_image_struct;
 
@@ -95,10 +94,11 @@
 #define jpg_ptr(N)      (img_ptr(N)->image_struct.jpg)
 #define tif_ptr(N)      (img_ptr(N)->image_struct.tif)
 
-extern integer read_pdf_info(char*, char*, integer, integer, integer, integer);
-extern void write_epdf(void);
-extern void epdf_delete(void);
-extern void read_png_info(integer);
-extern void write_png(integer);
-extern void read_jpg_info(integer);
-extern void write_jpg(integer);
+extern integer read_pdf_info (char *, char *, integer, integer, integer,
+                              integer);
+extern void write_epdf (void);
+extern void epdf_delete (void);
+extern void read_png_info (integer);
+extern void write_png (integer);
+extern void read_jpg_info (integer);
+extern void write_jpg (integer);

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/macnames.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/macnames.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/macnames.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -301,12 +301,12 @@
 };
 
 const char *ambiguous_names[] = {
-    "Delta",            /*   increment   */
-    "Omega",            /*   Ohm         */
-    "Pi",               /*   product     */
-    "Sigma",            /*   summation   */
-    "dmacron",          /*   dslash      */
-    "macron",           /*   overscore   */
-    "periodcentered",   /*   middot      */
+    "Delta",                    /*   increment   */
+    "Omega",                    /*   Ohm         */
+    "Pi",                       /*   product     */
+    "Sigma",                    /*   summation   */
+    "dmacron",                  /*   dslash      */
+    "macron",                   /*   overscore   */
+    "periodcentered",           /*   middot      */
     NULL
 };

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/mapfile.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/mapfile.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/mapfile.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,17 +17,18 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/mapfile.c#28 $
+$Id: mapfile.c,v 1.20 2005/10/16 17:41:51 hahe Exp hahe $
+
 */
 
 #include <math.h>
 #include "ptexlib.h"
 #include <kpathsea/c-auto.h>
 #include <kpathsea/c-memstr.h>
-#include "avlstuff.h"
+#include <string.h>
 
 static const char perforce_id[] =
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/mapfile.c#28 $";
+    "$Id: mapfile.c,v 1.20 2005/10/16 17:41:51 hahe Exp hahe $";
 
 #define FM_BUF_SIZE     1024
 
@@ -41,15 +42,15 @@
 
 enum _mode { FM_DUPIGNORE, FM_REPLACE, FM_DELETE };
 enum _ltype { MAPFILE, MAPLINE };
-enum _tfmavail { TFM_UNCHECKED, TFM_FOUND, TFM_NOTFOUND};
+enum _tfmavail { TFM_UNCHECKED, TFM_FOUND, TFM_NOTFOUND };
 
 typedef struct mitem {
-    int mode;            /* FM_DUPIGNORE or FM_REPLACE or FM_DELETE */
-    int type;            /* mapfile or map line */
-    char *line;            /* pointer to map line */
-    struct mitem *next;        /* pointer to next item, or NULL */
+    int mode;                   /* FM_DUPIGNORE or FM_REPLACE or FM_DELETE */
+    int type;                   /* map file or map line */
+    char *line;                 /* pointer to map file name or map line */
+    int lineno;                 /* line number in map file */
 } mapitem;
-mapitem *miptr, *mapitems = NULL;
+mapitem *mitem = NULL;
 
 fm_entry *fm_cur;
 static const char nontfm[] = "<nontfm>";
@@ -58,48 +59,38 @@
 static fm_entry *non_tfm_found;
 static fm_entry *not_avail_tfm_found;
 
-static const char *basefont_names[] = {
-    "Courier",
-    "Courier-Bold",
-    "Courier-Oblique",
-    "Courier-BoldOblique",
-    "Helvetica",
-    "Helvetica-Bold",
-    "Helvetica-Oblique",
-    "Helvetica-BoldOblique",
-    "Symbol",
-    "Times-Roman",
-    "Times-Bold",
-    "Times-Italic",
-    "Times-BoldItalic",
-    "ZapfDingbats",
-    NULL
-};
-
-#define read_field(r, q, buf) do {                     \
-    for (q = buf; *r != ' ' && *r != 10; *q++ = *r++); \
-    *q = 0;                                            \
-    skip (r, ' ');                                     \
+#define read_field(r, q, buf) do {  \
+    q = buf;                        \
+    while (*r != ' ' && *r != '\0') \
+        *q++ = *r++;                \
+    *q = '\0';                      \
+    skip (r, ' ');                  \
 } while (0)
 
-#define set_field(F) do {                              \
-    if (q > buf)                                       \
-        fm_ptr->F = xstrdup(buf);                      \
-    if (*r == 10)                                      \
-        goto done;                                     \
+#define set_field(F) do {           \
+    if (q > buf)                    \
+        fm->F = xstrdup(buf);       \
+    if (*r == '\0')                 \
+        goto done;                  \
 } while (0)
 
-static fm_entry *new_fm_entry(void)
+#define cmp_return(a, b) \
+    if (a > b)           \
+        return 1;        \
+    if (a < b)           \
+        return -1
+
+fm_entry *new_fm_entry (void)
 {
     fm_entry *fm;
-    fm = xtalloc(1, fm_entry);
+    fm = xtalloc (1, fm_entry);
     fm->tfm_name = NULL;
     fm->ps_name = NULL;
-    fm->flags = 0;
+    fm->flags = 4;
     fm->ff_name = NULL;
     fm->subset_tag = NULL;
     fm->encoding = NULL;
-    fm->tfm_num = getnullfont();
+    fm->tfm_num = getnullfont ();
     fm->tfm_avail = TFM_UNCHECKED;
     fm->type = 0;
     fm->slant = 0;
@@ -110,64 +101,67 @@
     fm->charset = NULL;
     fm->all_glyphs = false;
     fm->links = 0;
+    fm->pid = -1;
+    fm->eid = -1;
+    fm->subfont = NULL;
     return fm;
 }
 
-static void delete_fm_entry(fm_entry * fm)
+void delete_fm_entry (fm_entry * fm)
 {
-    xfree(fm->tfm_name);
-    xfree(fm->ps_name);
-    xfree(fm->ff_name);
-    xfree(fm->subset_tag);
-    xfree(fm->charset);
-    xfree(fm);
+    xfree (fm->tfm_name);
+    xfree (fm->ps_name);
+    xfree (fm->ff_name);
+    xfree (fm->subset_tag);
+    xfree (fm->charset);
+    xfree (fm);
 }
 
-static ff_entry *new_ff_entry(void)
+static ff_entry *new_ff_entry (void)
 {
     ff_entry *ff;
-    ff = xtalloc(1, ff_entry);
+    ff = xtalloc (1, ff_entry);
     ff->ff_name = NULL;
     ff->ff_path = NULL;
     return ff;
 }
 
-static void delete_ff_entry(ff_entry * ff)
+static void delete_ff_entry (ff_entry * ff)
 {
-    xfree(ff->ff_name);
-    xfree(ff->ff_path);
-    xfree(ff);
+    xfree (ff->ff_name);
+    xfree (ff->ff_path);
+    xfree (ff);
 }
 
-static fm_entry *dummy_fm_entry()
+static fm_entry *dummy_fm_entry ()
 {
     static const fm_entry const_fm_entry;
-    return (fm_entry*) &const_fm_entry;
+    return (fm_entry *) & const_fm_entry;
 }
 
-char *mk_base_tfm(char *tfmname, int *i)
+char *mk_base_tfm (char *tfmname, int *i)
 {
     static char buf[SMALL_BUF_SIZE];
-    char *p = tfmname, *r = strend(p) - 1, *q = r;
-    while (q > p && isdigit(*q))
+    char *p = tfmname, *r = strend (p) - 1, *q = r;
+    while (q > p && isdigit (*q))
         --q;
     if (!(q > p) || q == r || (*q != '+' && *q != '-'))
         return NULL;
-    check_buf(q - p + 1, SMALL_BUF_SIZE);
-    strncpy(buf, p, (unsigned) (q - p));
-    buf[q - p] = 0;
-    *i = atoi(q);
+    check_buf (q - p + 1, SMALL_BUF_SIZE);
+    strncpy (buf, p, (unsigned) (q - p));
+    buf[q - p] = '\0';
+    *i = atoi (q);
     return buf;
 }
 
-static fmentryptr fmlookup(internalfontnumber);
+static fmentryptr fmlookup (internalfontnumber);
 
-boolean hasfmentry(internalfontnumber f)
+boolean hasfmentry (internalfontnumber f)
 {
     if (pdffontmap[f] == NULL)
-        pdffontmap[f] = fmlookup(f);
-    assert(pdffontmap[f] != NULL);
-    return pdffontmap[f] != (fmentryptr) dummy_fm_entry();
+        pdffontmap[f] = fmlookup (f);
+    assert (pdffontmap[f] != NULL);
+    return pdffontmap[f] != (fmentryptr) dummy_fm_entry ();
 }
 
 /**********************************************************************/
@@ -178,56 +172,50 @@
 
 /* AVL sort fm_entry into tfm_tree by tfm_name */
 
-static int comp_fm_entry_tfm(const void *pa, const void *pb, void *p)
+static int comp_fm_entry_tfm (const void *pa, const void *pb, void *p)
 {
-    return strcmp(((const fm_entry *) pa)->tfm_name,
-                  ((const fm_entry *) pb)->tfm_name);
+    return strcmp (((const fm_entry *) pa)->tfm_name,
+                   ((const fm_entry *) pb)->tfm_name);
 }
 
-#define cmp_return(a, b)    \
-    if (a > b)              \
-        return 1;           \
-    if (a < b)              \
-        return -1
+/* AVL sort fm_entry into ps_tree by ps_name, slant, and extend */
 
-/* AVL sort fm_entry into ps_tree by ps_name, slant, and extend */
-static int comp_fm_entry_ps(const void *pa, const void *pb, void *p)
+static int comp_fm_entry_ps (const void *pa, const void *pb, void *p)
 {
-    const fm_entry *p1 = (const fm_entry *) pa,
-                   *p2 = (const fm_entry *) pb;
+    const fm_entry *p1 = (const fm_entry *) pa, *p2 = (const fm_entry *) pb;
     int i;
-    assert(p1->ps_name != NULL && p2->ps_name != NULL);
-    if ((i = strcmp(p1->ps_name, p2->ps_name)) != 0)
+    assert (p1->ps_name != NULL && p2->ps_name != NULL);
+    if ((i = strcmp (p1->ps_name, p2->ps_name)) != 0)
         return i;
-    cmp_return(p1->slant, p2->slant);
-    cmp_return(p1->extend, p2->extend);
+    cmp_return (p1->slant, p2->slant);
+    cmp_return (p1->extend, p2->extend);
     if (p1->tfm_name != NULL && p2->tfm_name != NULL &&
-        (i = strcmp(p1->tfm_name, p2->tfm_name)) != 0)
+        (i = strcmp (p1->tfm_name, p2->tfm_name)) != 0)
         return i;
     return 0;
 }
 
 /* AVL sort ff_entry into ff_tree by ff_name */
 
-static int comp_ff_entry(const void *pa, const void *pb, void *p)
+static int comp_ff_entry (const void *pa, const void *pb, void *p)
 {
-    return strcmp(((const ff_entry *) pa)->ff_name,
-                 ((const ff_entry *) pb)->ff_name);
+    return strcmp (((const ff_entry *) pa)->ff_name,
+                   ((const ff_entry *) pb)->ff_name);
 }
 
-static void create_avl_trees()
+static void create_avl_trees ()
 {
     if (tfm_tree == NULL) {
-        tfm_tree = avl_create(comp_fm_entry_tfm, NULL, &avl_xallocator);
-        assert(tfm_tree != NULL);
+        tfm_tree = avl_create (comp_fm_entry_tfm, NULL, &avl_xallocator);
+        assert (tfm_tree != NULL);
     }
     if (ps_tree == NULL) {
-        ps_tree = avl_create(comp_fm_entry_ps, NULL, &avl_xallocator);
-        assert(ps_tree != NULL);
+        ps_tree = avl_create (comp_fm_entry_ps, NULL, &avl_xallocator);
+        assert (ps_tree != NULL);
     }
     if (ff_tree == NULL) {
-        ff_tree = avl_create(comp_ff_entry, NULL, &avl_xallocator);
-        assert(ff_tree != NULL);
+        ff_tree = avl_create (comp_ff_entry, NULL, &avl_xallocator);
+        assert (ff_tree != NULL);
     }
 }
 
@@ -238,199 +226,322 @@
 with the original version.
 */
 
-static int avl_do_entry(fm_entry * fp, int mode)
+int avl_do_entry (fm_entry * fp, int mode)
 {
-    fm_entry *p, *p2;
+    fm_entry *p;
     void *a;
     void **aa;
-    struct avl_traverser trav;
 
     /* handle tfm_name link */
 
-    if (strcmp(fp->tfm_name, nontfm) != 0) {
-        p = (fm_entry *) avl_find(tfm_tree, fp);
+    if (strcmp (fp->tfm_name, nontfm) != 0) {
+        p = (fm_entry *) avl_find (tfm_tree, fp);
         if (p != NULL) {
             if (mode == FM_DUPIGNORE) {
-                pdftex_warn("fontmap entry for `%s' already exists, duplicates ignored",
-                            fp->tfm_name);
+                pdftex_warn
+                    ("fontmap entry for `%s' already exists, duplicates ignored",
+                     fp->tfm_name);
                 goto exit;
-            } else { /* mode == FM_REPLACE / FM_DELETE */
+            } else {            /* mode == FM_REPLACE / FM_DELETE */
                 if (fontused[p->tfm_num]) {
-                    pdftex_warn("fontmap entry for `%s' has been used, replace/delete not allowed",
-                                fp->tfm_name);
-                    goto exit;        
+                    pdftex_warn
+                        ("fontmap entry for `%s' has been used, replace/delete not allowed",
+                         fp->tfm_name);
+                    goto exit;
                 }
-                a = avl_delete(tfm_tree, p);
-                assert(a != NULL);
-                unset_tfmlink(p);
-                if (!has_pslink(p))
-                    delete_fm_entry(p);
+                a = avl_delete (tfm_tree, p);
+                assert (a != NULL);
+                unset_tfmlink (p);
+                if (!has_pslink (p))
+                    delete_fm_entry (p);
             }
         }
         if (mode != FM_DELETE) {
-            aa = avl_probe(tfm_tree, fp);
-            assert(aa != NULL);
-            set_tfmlink(fp);
+            aa = avl_probe (tfm_tree, fp);
+            assert (aa != NULL);
+            set_tfmlink (fp);
         }
     }
 
     /* handle ps_name link */
 
     if (fp->ps_name != NULL) {
-        assert(fp->tfm_name != NULL);
-        p = (fm_entry *) avl_find(ps_tree, fp);
+        assert (fp->tfm_name != NULL);
+        p = (fm_entry *) avl_find (ps_tree, fp);
         if (p != NULL) {
             if (mode == FM_DUPIGNORE) {
-                pdftex_warn("ps_name entry for `%s' already exists, duplicates ignored",
-                            fp->ps_name);
+                pdftex_warn
+                    ("ps_name entry for `%s' already exists, duplicates ignored",
+                     fp->ps_name);
                 goto exit;
-            } else { /* mode == FM_REPLACE / FM_DELETE */
+            } else {            /* mode == FM_REPLACE / FM_DELETE */
                 if (fontused[p->tfm_num]) {
                     /* REPLACE/DELETE not allowed */
-                    pdftex_warn("fontmap entry for `%s' has been used, replace/delete not allowed",
-                                p->tfm_name);
-                    goto exit;        
+                    pdftex_warn
+                        ("fontmap entry for `%s' has been used, replace/delete not allowed",
+                         p->tfm_name);
+                    goto exit;
                 }
-                a = avl_delete(ps_tree, p);
-                assert(a != NULL);
-                unset_pslink(p);
-                if (!has_tfmlink(p))
-                    delete_fm_entry(p);
+                a = avl_delete (ps_tree, p);
+                assert (a != NULL);
+                unset_pslink (p);
+                if (!has_tfmlink (p))
+                    delete_fm_entry (p);
             }
         }
         if (mode != FM_DELETE) {
-            aa = avl_probe(ps_tree, fp);
-            assert(aa != NULL);
-            set_pslink(fp);
+            aa = avl_probe (ps_tree, fp);
+            assert (aa != NULL);
+            set_pslink (fp);
         }
     }
-exit:
-    if (!has_tfmlink(fp) && !has_pslink(fp))        /* e. g. after FM_DELETE */
-        return 1;                /* deallocation of fm_entry structure required */
+  exit:
+    if (!has_tfmlink (fp) && !has_pslink (fp))  /* e. g. after FM_DELETE */
+        return 1;               /* deallocation of fm_entry structure required */
     else
         return 0;
 }
 
 /**********************************************************************/
+/* consistency check for map entry, with warn flag */
 
-static void fm_scan_line(mapitem * mitem)
+int check_fm_entry (fm_entry * fm, boolean warn)
 {
+    int a = 0;
+    assert (fm != NULL);
+    if (fm->ps_name != NULL) {
+        if (is_basefont (fm)) {
+            if (is_fontfile (fm) && !is_included (fm)) {
+                if (warn)
+                    pdftex_warn
+                        ("invalid entry for `%s': font file must be included or omitted for base fonts",
+                         fm->tfm_name);
+                a += 1;
+            }
+        } else {                /* not a base font */
+            /* if no font file given, drop this entry */
+            if (!is_fontfile (fm)) {
+                if (warn)
+                    pdftex_warn
+                        ("invalid entry for `%s': font file missing",
+                         fm->tfm_name);
+                a += 2;
+            }
+        }
+    }
+    if (is_truetype (fm) && is_reencoded (fm) && !is_subsetted (fm)) {
+        if (warn)
+            pdftex_warn
+                ("invalid entry for `%s': only subsetted TrueType font can be reencoded",
+                 fm->tfm_name);
+        a += 4;
+    }
+    if ((fm->slant != 0 || fm->extend != 0) &&
+        (!is_included (fm) || is_truetype (fm))) {
+        if (warn)
+            pdftex_warn
+                ("invalid entry for `%s': SlantFont/ExtendFont can be used only with embedded T1 fonts",
+                 fm->tfm_name);
+        a += 8;
+    }
+    if (abs (fm->slant) > 1000) {
+        if (warn)
+            pdftex_warn
+                ("invalid entry for `%s': too big value of SlantFont (%g)",
+                 fm->tfm_name, fm->slant / 1000.0);
+        a += 16;
+    }
+    if (abs (fm->extend) > 2000) {
+        if (warn)
+            pdftex_warn
+                ("invalid entry for `%s': too big value of ExtendFont (%g)",
+                 fm->tfm_name, fm->extend / 1000.0);
+        a += 32;
+    }
+    if (fm->pid != -1 &&
+        !(is_truetype (fm) && is_included (fm) &&
+          is_subsetted (fm) && !is_reencoded (fm))) {
+        if (warn)
+            pdftex_warn
+                ("invalid entry for `%s': PidEid can be used only with subsetted non-reencoded TrueType fonts",
+                 fm->tfm_name);
+        a += 64;
+    }
+    return a;
+}
+
+/**********************************************************************/
+/* returns true if s is one of the 14 std. font names; speed-trimmed. */
+
+boolean check_basefont (char *s)
+{
+    static const char *basefont_names[] = {
+        "Courier",              /* 0:7 */
+        "Courier-Bold",         /* 1:12 */
+        "Courier-Oblique",      /* 2:15 */
+        "Courier-BoldOblique",  /* 3:19 */
+        "Helvetica",            /* 4:9 */
+        "Helvetica-Bold",       /* 5:14 */
+        "Helvetica-Oblique",    /* 6:17 */
+        "Helvetica-BoldOblique",        /* 7:21 */
+        "Symbol",               /* 8:6 */
+        "Times-Roman",          /* 9:11 */
+        "Times-Bold",           /* 10:10 */
+        "Times-Italic",         /* 11:12 */
+        "Times-BoldItalic",     /* 12:16 */
+        "ZapfDingbats"          /* 13:12 */
+    };
+    static const int index[] =
+        { -1, -1, -1, -1, -1, -1, 8, 0, -1, 4, 10, 9, -1, -1, 5, 2, 12, 6,
+        -1, 3, -1, 7
+    };
+    const size_t n = strlen (s);
+    int k = -1;
+    if (n > 21)
+        return false;
+    if (n == 12) {              /* three names have length 12 */
+        switch (*s) {
+        case 'C':
+            k = 1;              /* Courier-Bold */
+            break;
+        case 'T':
+            k = 11;             /* Times-Italic */
+            break;
+        case 'Z':
+            k = 13;             /* ZapfDingbats */
+            break;
+        default:
+            return false;
+        }
+    } else
+        k = index[n];
+    if (k > -1 && strcmp (basefont_names[k], s) == 0)
+        return true;
+    return false;
+};
+
+/**********************************************************************/
+
+static void fm_scan_line ()
+{
     int a, b, c, j, u = 0, v = 0;
     float d;
+    fm_entry *fm;
     char fm_line[FM_BUF_SIZE], buf[FM_BUF_SIZE];
-    char **pn;
-    fm_entry *fm_ptr = NULL;
-    char *p, *q, *r, *s, *t = NULL;
-    p = fm_line;
+    char *p, *q, *r, *s;
     switch (mitem->type) {
     case MAPFILE:
+        p = fm_line;
         do {
-            c = fm_getchar();
-            append_char_to_buf(c, p, fm_line, FM_BUF_SIZE);
+            c = fm_getchar ();
+            append_char_to_buf (c, p, fm_line, FM_BUF_SIZE);
         }
         while (c != 10);
+        *(--p) = '\0';
+        r = fm_line;
         break;
     case MAPLINE:
-        t = mitem->line;
-        while ((c = *t++) != 0)
-            append_char_to_buf(c, p, fm_line, FM_BUF_SIZE);
+        r = mitem->line;        /* work on string from makecstring() */
         break;
     default:
-        assert(0);
+        assert (0);
     }
-    append_eol(p, fm_line, FM_BUF_SIZE);
-    if (is_cfg_comment(*fm_line))
+    if (*r == '\0' || is_cfg_comment (*r))
         return;
-    r = fm_line;
-    read_field(r, q, buf);
-    fm_ptr = new_fm_entry();
-    set_field(tfm_name);
-    if (*r == 10)
-        goto done;
+    fm = new_fm_entry ();
+    read_field (r, q, buf);
+    set_field (tfm_name);
     p = r;
-    read_field(r, q, buf);
+    read_field (r, q, buf);
     if (*buf != '<' && *buf != '"')
-        set_field(ps_name);
+        set_field (ps_name);
     else
-        r = p;                        /* unget the field */
-    if (isdigit(*r)) {                /* font flags given */
-        fm_ptr->flags = atoi(r);
-        while (isdigit(*r))
+        r = p;                  /* unget the field */
+    if (isdigit (*r)) {         /* font flags given */
+        fm->flags = atoi (r);
+        while (isdigit (*r))
             r++;
-    } else
-        fm_ptr->flags = 4;      /* treat as Symbol font */
-    while (1) {                 /* this was former label reswitch: */
-        skip(r, ' ');
+    }
+    while (1) {                 /* loop through "specials", encoding, font file */
+        skip (r, ' ');
         switch (*r) {
-        case 10:
+        case '\0':
             goto done;
-        case '"':                /* opening quote */
+        case '"':              /* opening quote */
             r++;
             u = v = 0;
             do {
-                skip(r, ' ');
-                if (sscanf(r, "%f %n", &d, &j) > 0) {
-                    s = r + j;        /* jump behind number, eat also blanks, if any */
+                skip (r, ' ');
+                if (sscanf (r, "%f %n", &d, &j) > 0) {
+                    s = r + j;  /* jump behind number, eat also blanks, if any */
                     if (*(s - 1) == 'E' || *(s - 1) == 'e')
-                        s--;        /* e. g. 0.5ExtendFont: %f = 0.5E */
-                    if (strncmp(s, "SlantFont", strlen("SlantFont")) == 0) {
-                        d *= 1000.0;        /* correct rounding also for neg. numbers */
-                        fm_ptr->slant =
-                            (integer) (d > 0 ? d + 0.5 : d - 0.5);
-                        r = s + strlen("SlantFont");
-                    } else if (strncmp(s, "ExtendFont", strlen("ExtendFont")) == 0) {
+                        s--;    /* e. g. 0.5ExtendFont: %f = 0.5E */
+                    if (strncmp (s, "SlantFont", strlen ("SlantFont")) == 0) {
+                        d *= 1000.0;    /* correct rounding also for neg. numbers */
+                        fm->slant = (integer) (d > 0 ? d + 0.5 : d - 0.5);
+                        r = s + strlen ("SlantFont");
+                    } else if (strncmp (s, "ExtendFont", strlen ("ExtendFont"))
+                               == 0) {
                         d *= 1000.0;
-                        fm_ptr->extend =
-                            (integer) (d > 0 ? d + 0.5 : d - 0.5);
-                        if (fm_ptr->extend == 1000)
-                            fm_ptr->extend = 0;
-                        r = s + strlen("ExtendFont");
-                    } else {
+                        fm->extend = (integer) (d > 0 ? d + 0.5 : d - 0.5);
+                        if (fm->extend == 1000)
+                            fm->extend = 0;
+                        r = s + strlen ("ExtendFont");
+                    } else {    /* unknown name */
+                        for (r = s; *r != ' ' && *r != '"' && *r != '\0'; r++); /* jump over name */
+                        c = *r; /* remember char for temporary end of string */
+                        *r = '\0';
                         pdftex_warn
                             ("invalid entry for `%s': unknown name `%s' ignored",
-                             fm_ptr->tfm_name, s);
-                        for (r = s; *r != ' ' && *r != '"' && *r != 10;
-                             r++);
+                             fm->tfm_name, s);
+                        *r = c;
                     }
                 } else
-                    for (; *r != ' ' && *r != '"' && *r != 10; r++);
-            } while (*r == ' ');
-            if (*r == '"')        /* closing quote */
+                    for (; *r != ' ' && *r != '"' && *r != '\0'; r++);
+            }
+            while (*r == ' ');
+            if (*r == '"')      /* closing quote */
                 r++;
             else {
-                pdftex_warn("invalid entry for `%s': unknown line format",
-                            fm_ptr->tfm_name);
+                pdftex_warn
+                    ("invalid entry for `%s': closing quote missing",
+                     fm->tfm_name);
                 goto bad_line;
             }
             break;
-        default: /* encoding or font file specification */
+        case 'P':              /* handle cases for subfonts like 'PidEid=3,1' */
+            if (sscanf (r, "PidEid=%i, %i %n", &a, &b, &c) >= 2) {
+                fm->pid = a;
+                fm->eid = b;
+                r += c;
+                break;
+            }
+        default:               /* encoding or font file specification */
             a = b = 0;
             if (*r == '<') {
                 a = *r++;
                 if (*r == '<' || *r == '[')
                     b = *r++;
             }
-            read_field(r, q, buf);
-                /* encoding, formats: '8r.enc' or '<8r.enc' or '<[8r.enc' */
-            if (strlen(buf) > 4 && strcasecmp(strend(buf) - 4, ".enc") == 0) {
-                fm_ptr->encoding = add_enc(buf);
-                u = 0;                      /* u, v used if intervening blank: "<< foo" */
-                v = 0;
-            } else if (strlen(buf) > 0) {
-                /* fontfile, formats:
-                 * subsetting:    '<cmr10.pfa' 
-                 * no subsetting: '<<cmr10.pfa' 
-                 * no embedding:  'cmr10.pfa' 
+            read_field (r, q, buf);
+            /* encoding, formats: '8r.enc' or '<8r.enc' or '<[8r.enc' */
+            if (strlen (buf) > 4 && strcasecmp (strend (buf) - 4, ".enc") == 0) {
+                fm->encoding = add_enc (buf);
+                u = v = 0;      /* u, v used if intervening blank: "<< foo" */
+            } else if (strlen (buf) > 0) {      /* file name given */
+                /* font file, formats:
+                 * subsetting:    '<cmr10.pfa'
+                 * no subsetting: '<<cmr10.pfa'
+                 * no embedding:  'cmr10.pfa'
                  */
                 if (a == '<' || u == '<') {
-                    set_included(fm_ptr);
+                    set_included (fm);
                     if ((a == '<' && b == 0) || (a == 0 && v == 0))
-                        set_subsetted(fm_ptr);
+                        set_subsetted (fm);
                     /* otherwise b == '<' (or '[') => no subsetting */
                 }
-                set_field(ff_name);
-                u = 0;
-                v = 0;
+                set_field (ff_name);
+                u = v = 0;
             } else {
                 u = a;
                 v = b;
@@ -438,101 +549,60 @@
         }
     }
   done:
-    if (fm_ptr->ps_name != NULL) {
-        /* check whether this is a base font */
-        for (pn = (char**)basefont_names; *pn != NULL; ++pn)
-            if (strcmp(*pn, fm_ptr->ps_name) == 0) {
-                set_basefont(fm_ptr);
-                break;
-            }
-        /* when no font file is given and this is not a base font, drop this entry */
-        if (!is_fontfile(fm_ptr) && !is_basefont(fm_ptr)) {
-            pdftex_warn("invalid entry for `%s': font file missing",
-                    fm_ptr->tfm_name);
-            goto bad_line;
-        }
-        if (is_fontfile(fm_ptr) && is_basefont(fm_ptr) && !is_included(fm_ptr)) {
-            pdftex_warn(
-                "invalid entry for `%s': font file must be included or omitted for base fonts",
-                fm_ptr->tfm_name);
-            goto bad_line;
-        }
-    }
-    if (is_fontfile(fm_ptr) && 
-        strcasecmp(strend(fm_fontfile(fm_ptr)) - 4, ".ttf") == 0)
-        set_truetype(fm_ptr);
-    if ((fm_ptr->slant != 0 || fm_ptr->extend != 0) &&
-        (!is_included(fm_ptr) || is_truetype(fm_ptr))) {
-        pdftex_warn
-            ("invalid entry for `%s': SlantFont/ExtendFont can be used only with embedded T1 fonts",
-             fm_ptr->tfm_name);
+    if (fm->ps_name != NULL && check_basefont (fm->ps_name))
+        set_basefont (fm);
+    if (is_fontfile (fm)
+        && strcasecmp (strend (fm_fontfile (fm)) - 4, ".ttf") == 0)
+        set_truetype (fm);
+    if (check_fm_entry (fm, true) != 0)
         goto bad_line;
-    }
-    if (is_truetype(fm_ptr) && (is_reencoded(fm_ptr)) && !is_subsetted(fm_ptr)) {
-        pdftex_warn
-            ("invalid entry for `%s': only subsetted TrueType font can be reencoded",
-             fm_ptr->tfm_name);
-        goto bad_line;
-    }
-    if (abs(fm_ptr->slant) >= 1000) {
-        pdftex_warn
-            ("invalid entry for `%s': too big value of SlantFont (%g)",
-             fm_ptr->tfm_name, fm_ptr->slant / 1000.0);
-        goto bad_line;
-    }
-    if (abs(fm_ptr->extend) >= 2000) {
-        pdftex_warn
-            ("invalid entry for `%s': too big value of ExtendFont (%g)",
-             fm_ptr->tfm_name, fm_ptr->extend / 1000.0);
-        goto bad_line;
-    }
-
     /*
        Until here the map line has been completely scanned without errors;
-       fm_ptr points to a valid, freshly filled-out fm_entry structure.
+       fm points to a valid, freshly filled-out fm_entry structure.
        Now follows the actual work of registering/deleting.
      */
-
-    if (avl_do_entry(fm_ptr, mitem->mode) == 1) /* if no link to fm_entry */
-        goto bad_line;
-    return;
+    if (handle_subfont_fm (fm, mitem->mode))    /* is this a subfont? */
+        return;
+    if (avl_do_entry (fm, mitem->mode) == 0)    /* if success */
+        return;
   bad_line:
-    delete_fm_entry(fm_ptr);
+    delete_fm_entry (fm);
 }
 
-void fm_read_info()
+/**********************************************************************/
+
+void fm_read_info ()
 {
-    mapitem *tmp;
-    create_avl_trees();
-    while (mapitems != NULL) {
-        assert(mapitems->line != NULL);
-        switch (mapitems->type) {
-        case MAPFILE:
-            set_cur_file_name(mapitems->line);
-            if (!fm_open()) {
-                pdftex_warn("cannot open font map file");
-            } else {
-                cur_file_name = (char *) nameoffile + 1;
-                tex_printf("{%s", cur_file_name);
-                while (!fm_eof())
-                    fm_scan_line(mapitems);
-                fm_close();
-                tex_printf("}");
-                fm_file = NULL;
+    if (tfm_tree == NULL)
+        create_avl_trees ();
+    if (mitem->line == NULL)    /* nothing to do */
+        return;
+    mitem->lineno = 1;
+    switch (mitem->type) {
+    case MAPFILE:
+        set_cur_file_name (mitem->line);
+        if (!fm_open ()) {
+            pdftex_warn ("cannot open font map file");
+        } else {
+            cur_file_name = (char *) nameoffile + 1;
+            tex_printf ("{%s", cur_file_name);
+            while (!fm_eof ()) {
+                fm_scan_line ();
+                mitem->lineno++;
             }
-            break;
-        case MAPLINE:
-            cur_file_name = NULL;        /* makes pdftex_warn() shorter */
-            fm_scan_line(mapitems);
-            break;
-        default:
-            assert(0);
+            fm_close ();
+            tex_printf ("}");
+            fm_file = NULL;
         }
-        tmp = mapitems;
-        mapitems = mapitems->next;
-        xfree(tmp->line);
-        xfree(tmp);
+        break;
+    case MAPLINE:
+        cur_file_name = NULL;   /* makes pdftex_warn() shorter */
+        fm_scan_line ();
+        break;
+    default:
+        assert (0);
     }
+    mitem->line = NULL;         /* done with this line */
     cur_file_name = NULL;
     return;
 }
@@ -554,91 +624,88 @@
 }
 */
 
-internalfontnumber tfmoffm(fmentryptr fm_pt)
+internalfontnumber tfmoffm (fmentryptr fm_pt)
 {
     return ((fm_entry *) fm_pt)->tfm_num;
 }
 
-static fm_entry *mk_ex_fm(internalfontnumber f, fm_entry * basefm, int ex)
+static fm_entry *mk_ex_fm (internalfontnumber f, fm_entry * basefm, int ex)
 {
     fm_entry *fm;
     integer e = basefm->extend;
     if (e == 0)
         e = 1000;
-    fm = new_fm_entry();
+    fm = new_fm_entry ();
     fm->flags = basefm->flags;
     fm->encoding = basefm->encoding;
     fm->type = basefm->type;
     fm->slant = basefm->slant;
-    fm->extend = roundxnoverd(e, 1000 + ex, 1000); /* modify ExtentFont to simulate expansion */
+    fm->extend = roundxnoverd (e, 1000 + ex, 1000);     /* modify ExtentFont to simulate expansion */
     if (fm->extend == 1000)
         fm->extend = 0;
-    fm->tfm_name = xstrdup(makecstring(fontname[f]));
+    fm->tfm_name = xstrdup (makecstring (fontname[f]));
     if (basefm->ps_name != NULL)
-        fm->ps_name = xstrdup(basefm->ps_name);
-    fm->ff_name = xstrdup(basefm->ff_name);
-    fm->ff_objnum = pdfnewobjnum();
+        fm->ps_name = xstrdup (basefm->ps_name);
+    fm->ff_name = xstrdup (basefm->ff_name);
+    fm->ff_objnum = pdfnewobjnum ();
     fm->tfm_num = f;
     fm->tfm_avail = TFM_FOUND;
-    assert(strcmp(fm->tfm_name, nontfm) != 0);
+    assert (strcmp (fm->tfm_name, nontfm) != 0);
     return fm;
 }
 
-static void init_fm(fm_entry * fm, internalfontnumber f)
+static void init_fm (fm_entry * fm, internalfontnumber f)
 {
-    if (fm->fd_objnum == 0)
-        fm->fd_objnum = pdfnewobjnum();
-    if (fm->ff_objnum == 0 && is_included(fm))
-        fm->ff_objnum = pdfnewobjnum();
-    if (fm->tfm_num == getnullfont()) {
+    if (fm->fd_objnum == 0 && !no_font_desc (fm))
+        fm->fd_objnum = pdfnewobjnum ();
+    if (fm->ff_objnum == 0 && is_included (fm))
+        fm->ff_objnum = pdfnewobjnum ();
+    if (fm->tfm_num == getnullfont ()) {
         fm->tfm_num = f;
         fm->tfm_avail = TFM_FOUND;
     }
 }
 
-static fmentryptr fmlookup(internalfontnumber f)
+static fmentryptr fmlookup (internalfontnumber f)
 {
-    char *tfm, *p;
+    char *tfm;
     fm_entry *fm, *exfm;
     fm_entry tmp;
     int ai, e;
-    if (tfm_tree == NULL || mapitems != NULL)
-        fm_read_info();
-    tfm = makecstring(fontname[f]);
-    assert(strcmp(tfm, nontfm) != 0);
+    if (tfm_tree == NULL)
+        fm_read_info ();        /* only to read default map file */
+    tfm = makecstring (fontname[f]);
+    assert (strcmp (tfm, nontfm) != 0);
 
     /* Look up for full <tfmname>[+-]<expand> */
     tmp.tfm_name = tfm;
-    fm = (fm_entry *) avl_find(tfm_tree, &tmp);
+    fm = (fm_entry *) avl_find (tfm_tree, &tmp);
     if (fm != NULL) {
-        init_fm(fm, f);
+        init_fm (fm, f);
         return (fmentryptr) fm;
     }
-    tfm = mk_base_tfm(makecstring(fontname[f]), &e);
-    if (tfm == NULL) /* not an expanded font, nothing to do */
-        return (fmentryptr) dummy_fm_entry();
+    tfm = mk_base_tfm (makecstring (fontname[f]), &e);
+    if (tfm == NULL)            /* not an expanded font, nothing to do */
+        return (fmentryptr) dummy_fm_entry ();
 
     tmp.tfm_name = tfm;
-    fm = (fm_entry *) avl_find(tfm_tree, &tmp);
-    if (fm != NULL) { /* found an entry with the base tfm name, e.g. cmr10 */
-        if (!is_t1fontfile(fm) || !is_included(fm)) {
-            pdftex_warn(
-                "font %s cannot be expanded (not an included Type1 font)",
-                tfm);
-            return (fmentryptr) dummy_fm_entry();
+    fm = (fm_entry *) avl_find (tfm_tree, &tmp);
+    if (fm != NULL) {           /* found an entry with the base tfm name, e.g. cmr10 */
+        if (!is_t1fontfile (fm) || !is_included (fm)) {
+            pdftex_warn
+                ("font %s cannot be expanded (not an included Type1 font)",
+                 tfm);
+            return (fmentryptr) dummy_fm_entry ();
         }
-        exfm = mk_ex_fm(f, fm, e); /* copies all fields from fm except tfm name */
-        init_fm(exfm, f);
-        ai = avl_do_entry(exfm, FM_DUPIGNORE);
-        assert(ai == 0);
+        exfm = mk_ex_fm (f, fm, e);     /* copies all fields from fm except tfm name */
+        init_fm (exfm, f);
+        ai = avl_do_entry (exfm, FM_DUPIGNORE);
+        assert (ai == 0);
         return (fmentryptr) exfm;
     }
-    return (fmentryptr) dummy_fm_entry();
+    return (fmentryptr) dummy_fm_entry ();
 }
 
-
-/**********************************************************************/
-
 /*
    Early check whether a font file exists. Used e. g. for replacing fonts
    of embedded PDF files: Without font file, the font within the embedded
@@ -651,34 +718,31 @@
    so this tree typically is much smaller than the tfm_tree or ps_tree.
 */
 
-ff_entry *check_ff_exist(fm_entry * fm)
+ff_entry *check_ff_exist (fm_entry * fm)
 {
     ff_entry *ff;
     ff_entry tmp;
-    char *ex_ffname;
     void **aa;
 
-    assert(fm->ff_name != NULL);
+    assert (fm->ff_name != NULL);
     tmp.ff_name = fm->ff_name;
-    ff = (ff_entry *) avl_find(ff_tree, &tmp);
-    if (ff == NULL) {                /* not yet in database */
-        ff = new_ff_entry();
-        ff->ff_name = xstrdup(fm->ff_name);
-        if (is_truetype(fm))
-            ff->ff_path =
-                kpse_find_file(fm->ff_name, kpse_truetype_format, 0);
+    ff = (ff_entry *) avl_find (ff_tree, &tmp);
+    if (ff == NULL) {           /* not yet in database */
+        ff = new_ff_entry ();
+        ff->ff_name = xstrdup (fm->ff_name);
+        if (is_truetype (fm))
+            ff->ff_path = kpse_find_file (fm->ff_name, kpse_truetype_format, 0);
         else
-            ff->ff_path =
-                kpse_find_file(fm->ff_name, kpse_type1_format, 0);
-        aa = avl_probe(ff_tree, ff);
-        assert(aa != NULL);
+            ff->ff_path = kpse_find_file (fm->ff_name, kpse_type1_format, 0);
+        aa = avl_probe (ff_tree, ff);
+        assert (aa != NULL);
     }
     return ff;
 }
 
 /**********************************************************************/
 
-static boolean used_tfm(fm_entry *p)
+static boolean used_tfm (fm_entry * p)
 {
     internalfontnumber f;
     strnumber s;
@@ -686,46 +750,44 @@
 
     /* check if the font file is not a TrueType font */
     /* font replacement makes sense only for included Type1 files */
-    if (is_truetype(p) || !is_included(p))
+    if (is_truetype (p) || !is_included (p))
         return false;
 
     /* check if the font file is available */
-    ff = check_ff_exist(p); 
+    ff = check_ff_exist (p);
     if (ff->ff_path == NULL)
         return false;
 
     /* check whether this font has been used */
     if (fontused[p->tfm_num])
         return true;
-    assert(p->tfm_name != NULL);
+    assert (p->tfm_name != NULL);
 
     /* check whether we didn't find a loaded font yet,
      * and this font has been loaded */
-    if (loaded_tfm_found == NULL && strcmp(p->tfm_name, nontfm) != 0) {
-        s = maketexstring(p->tfm_name);
-        if ((f = tfmlookup(s, 0)) != getnullfont()) {
-            loaded_tfm_found = p; 
+    if (loaded_tfm_found == NULL && strcmp (p->tfm_name, nontfm) != 0) {
+        s = maketexstring (p->tfm_name);
+        if ((f = tfmlookup (s, 0)) != getnullfont ()) {
+            loaded_tfm_found = p;
             if (pdffontmap[f] == NULL)
                 pdffontmap[f] = (fmentryptr) p;
-            if (p->tfm_num == getnullfont())
+            if (p->tfm_num == getnullfont ())
                 p->tfm_num = f;
-            assert(p->tfm_num == f);
+            assert (p->tfm_num == f);
             /* don't call flushstr() here as it has been called by tfmlookup() */
-        }
-        else
-            flushstr(s);
+        } else
+            flushstr (s);
     }
 
     /* check whether we didn't find either a loaded or a loadable font yet,
      * and this font is loadable */
     if (avail_tfm_found == NULL && loaded_tfm_found == NULL &&
-        strcmp(p->tfm_name, nontfm) != 0) {
+        strcmp (p->tfm_name, nontfm) != 0) {
         if (p->tfm_avail == TFM_UNCHECKED) {
-            if (kpse_find_file(p->tfm_name, kpse_tfm_format, 0) != NULL) {
+            if (kpse_find_file (p->tfm_name, kpse_tfm_format, 0) != NULL) {
                 avail_tfm_found = p;
                 p->tfm_avail = TFM_FOUND;
-            }
-            else {
+            } else {
                 p->tfm_avail = TFM_NOTFOUND;
                 if (not_avail_tfm_found == NULL)
                     not_avail_tfm_found = p;
@@ -734,13 +796,15 @@
     }
 
     /* check whether the current entry is a <nontfm> entry */
-    if (non_tfm_found == NULL && strcmp(p->tfm_name, nontfm) == 0)
+    if (non_tfm_found == NULL && strcmp (p->tfm_name, nontfm) == 0)
         non_tfm_found = p;
 
     return false;
 }
 
-/* lookup_ps_name looks for an entry with a given ps name + slant + extend.
+/* lookup_ps_name looks for an entry with a given ps name + slant + extend;
+ * return NULL if not found.
+ *
  * As there may exist several such entries, we need to select the `right'
  * one. We do so by checking all such entries and return the first one that
  * fulfils the following criteria (in descending priority):
@@ -751,11 +815,11 @@
  * - the tfm is present in map files, but cannot be loaded. In this case a
  *   dummy tfm can be loaded instead, and a warning should be written out
  */
-static fm_entry *lookup_ps_name(fm_entry *fm)
+
+static fm_entry *lookup_ps_name (fm_entry * fm)
 {
     fm_entry *p, *p2;
     struct avl_traverser t, t2;
-    strnumber s;
     int a;
 
     loaded_tfm_found = NULL;
@@ -763,82 +827,83 @@
     non_tfm_found = NULL;
     not_avail_tfm_found = NULL;
 
-    assert(fm->tfm_name == NULL);
-    p = (fm_entry *) avl_t_find(&t, ps_tree, fm);
+    assert (fm->tfm_name == NULL);
+    p = (fm_entry *) avl_t_find (&t, ps_tree, fm);
     if (p == NULL)
         return NULL;
     t2 = t;
-    p2 = avl_t_prev(&t2);
+    p2 = (fm_entry *) avl_t_prev (&t2);
 
     /* search forward */
     do {
-        if (used_tfm(p))
+        if (used_tfm (p))
             return p;
-        p = avl_t_next(&t);
-    } while (p != NULL && comp_fm_entry_ps(fm, p, NULL) == 0);
+        p = (fm_entry *) avl_t_next (&t);
+    }
+    while (p != NULL && comp_fm_entry_ps (fm, p, NULL) == 0);
 
     /* search backward */
-    while (p2 != NULL && comp_fm_entry_ps(fm, p2, NULL) == 0) {
-        if (used_tfm(p2))
+    while (p2 != NULL && comp_fm_entry_ps (fm, p2, NULL) == 0) {
+        if (used_tfm (p2))
             return p2;
-        p2 = avl_t_prev(&t2);
+        p2 = (fm_entry *) avl_t_prev (&t2);
     }
 
     if (loaded_tfm_found != NULL)
         p = loaded_tfm_found;
     else if (avail_tfm_found != NULL) {
         p = avail_tfm_found;
-        p->tfm_num = readfontinfo(getnullcs(), maketexstring(p->tfm_name), 
-                                  getnullstr(), -1000);
+        p->tfm_num = readfontinfo (getnullcs (), maketexstring (p->tfm_name),
+                                   getnullstr (), -1000);
         p->tfm_avail = TFM_FOUND;
     } else if (non_tfm_found != NULL) {
         p = non_tfm_found;
-        p->tfm_num = newdummyfont();
+        p->tfm_num = newdummyfont ();
         p->tfm_avail = TFM_FOUND;
     } else if (not_avail_tfm_found != NULL) {
         p = not_avail_tfm_found;
-        pdftex_warn("`%s' not loadable, use a dummy tfm instead", p->tfm_name);
-        p2 = new_fm_entry();
+        pdftex_warn ("`%s' not loadable, use a dummy tfm instead", p->tfm_name);
+        p2 = new_fm_entry ();
         p2->flags = p->flags;
         p2->encoding = p->encoding;
         p2->type = p->type;
         p2->slant = p->slant;
         p2->extend = p->extend;
-        p2->tfm_name = xstrdup(nontfm);
-        p2->ps_name = xstrdup(p->ps_name);
+        p2->tfm_name = xstrdup (nontfm);
+        p2->ps_name = xstrdup (p->ps_name);
         if (p->ff_name != NULL)
-            p2->ff_name = xstrdup(p->ff_name);
-        p2->tfm_num = newdummyfont();
+            p2->ff_name = xstrdup (p->ff_name);
+        p2->tfm_num = newdummyfont ();
         p2->tfm_avail = TFM_FOUND;
-        a = avl_do_entry(p2, FM_DUPIGNORE);
-        assert(a == 0);
+        a = avl_do_entry (p2, FM_DUPIGNORE);
+        assert (a == 0);
         p = p2;
     } else
         return NULL;
-    assert(p->tfm_num != getnullfont());
+    assert (p->tfm_num != getnullfont ());
     return p;
 }
 
-/* Lookup fontmap for /BaseFont entries of embedded PDF-files */
+/* Lookup fontmap for /BaseFont entries of embedded PDF-files;
+ * return dummy_fm_entry() if not found */
 
-fm_entry *lookup_fontmap(char *bname)
+fm_entry *lookup_fontmap (char *bname)
 {
     fm_entry *fm, *fmx;
     fm_entry tmp, tmpx;
     ff_entry *ff;
     char buf[SMALL_BUF_SIZE];
     char *a, *b, *c, *d, *e, *s;
-    strnumber str;
     int i, sl, ex, ai;
-    if (tfm_tree == NULL || mapitems != NULL)
-        fm_read_info();
+    if (tfm_tree == NULL)
+        fm_read_info ();        /* only to read default map file */
     if (bname == NULL)
-        return dummy_fm_entry();
-    if (strlen(bname) >= SMALL_BUF_SIZE)
-        pdftex_fail("Font name too long: `%s'", bname);
-    strcpy(buf, bname);         /* keep bname untouched for later */
-    s = buf; 
-    if (strlen(buf) > 7) {        /* check for subsetted name tag */
+        return NULL;
+    if (strlen (bname) >= SMALL_BUF_SIZE)
+        pdftex_fail ("Font name too long: `%s'", bname);
+    strcpy (buf, bname);        /* keep bname untouched for later */
+    s = buf;
+    if (strlen (buf) > 7) {     /* check for subsetted name tag */
         for (i = 0; i < 6; i++, s++)
             if (*s < 'A' || *s > 'Z')
                 break;
@@ -859,47 +924,53 @@
 
     tmp.slant = 0;
     tmp.extend = 0;
-    if ((a = strstr(s, "-Slant_")) != NULL) {
-        b = a + strlen("-Slant_");
-        sl = (int) strtol(b, &e, 10);
-        if ((e != b) && (e == strend(b))) {
+    if ((a = strstr (s, "-Slant_")) != NULL) {
+        b = a + strlen ("-Slant_");
+        sl = (int) strtol (b, &e, 10);
+        if ((e != b) && (e == strend (b))) {
             tmp.slant = sl;
-            *a = 0;                /* bname string ends before "-Slant_" */
+            *a = '\0';          /* bname string ends before "-Slant_" */
         } else {
-            if (e != b) {        /* only if <slant> is valid number */
-                if ((c = strstr(e, "-Extend_")) != NULL) {
-                    d = c + strlen("-Extend_");
-                    ex = (int) strtol(d, &e, 10);
-                    if ((e != d) && (e == strend(d))) {
+            if (e != b) {       /* only if <slant> is valid number */
+                if ((c = strstr (e, "-Extend_")) != NULL) {
+                    d = c + strlen ("-Extend_");
+                    ex = (int) strtol (d, &e, 10);
+                    if ((e != d) && (e == strend (d))) {
                         tmp.slant = sl;
                         tmp.extend = ex;
-                        *a = 0;        /* bname string ends before "-Slant_" */
+                        *a = '\0';      /* bname string ends before "-Slant_" */
                     }
                 }
             }
         }
     } else {
-        if ((a = strstr(s, "-Extend_")) != NULL) {
-            b = a + strlen("-Extend_");
-            ex = (int) strtol(b, &e, 10);
-            if ((e != b) && (e == strend(b))) {
+        if ((a = strstr (s, "-Extend_")) != NULL) {
+            b = a + strlen ("-Extend_");
+            ex = (int) strtol (b, &e, 10);
+            if ((e != b) && (e == strend (b))) {
                 tmp.extend = ex;
-                *a = 0;                /* bname string ends before "-Extend_" */
+                *a = '\0';      /* bname string ends before "-Extend_" */
             }
         }
     }
     tmp.ps_name = s;
     tmp.tfm_name = NULL;
-    fm = lookup_ps_name(&tmp);
+    fm = lookup_ps_name (&tmp);
     if (fm != NULL) {
+        if (!(is_type1 (fm) && is_included (fm))) {
+            pdftex_warn
+                ("PS name '%s' is found but ignored (not an included Type1 font)",
+                 tmp.ps_name);
+            return NULL;
+        }
         i = fm->tfm_num;
-        assert(i != getnullfont());
+        assert (i != getnullfont ());
         if (pdffontmap[i] == NULL)
             pdffontmap[i] = (fmentryptr) fm;
-        if (fm->ff_objnum == 0 && is_included(fm))
-            fm->ff_objnum = pdfnewobjnum();
+        if (fm->ff_objnum == 0 && is_included (fm))
+            fm->ff_objnum = pdfnewobjnum ();
         if (!fontused[i])
-            pdfinitfont(i);
+            pdfinitfont (i);
         return fm;
     }
 /*
@@ -925,163 +996,141 @@
     tmpx.slant = 0;
     tmpx.extend = 0;
 /*     fm = (fm_entry *) avl_find(ps_tree, &tmpx); */
-    fm = lookup_ps_name(&tmpx);
+    fm = lookup_ps_name (&tmpx);
     if (fm != NULL) {
-        if (is_truetype(fm) || !is_included(fm))
-            return dummy_fm_entry();
-        ff = check_ff_exist(fm);
+        if (is_truetype (fm) || !is_included (fm))
+            return NULL;
+        ff = check_ff_exist (fm);
         if (ff->ff_path == NULL)
-            return dummy_fm_entry();
-        fmx = new_fm_entry();
+            return NULL;
+        fmx = new_fm_entry ();
         fmx->flags = fm->flags;
         fmx->encoding = fm->encoding;
         fmx->type = fm->type;
         fmx->slant = tmp.slant;
         fmx->extend = tmp.extend;
-        fmx->tfm_name = xstrdup(nontfm);
-        fmx->ps_name = xstrdup(s);
-        fmx->ff_name = xstrdup(fm->ff_name);
-        ai = avl_do_entry(fmx, FM_DUPIGNORE);
-        assert(ai == 0);
-        fm = lookup_fontmap(bname);        /* new try */
-        assert(fm != NULL);
+        fmx->tfm_name = xstrdup (nontfm);
+        fmx->ps_name = xstrdup (s);
+        fmx->ff_name = xstrdup (fm->ff_name);
+        ai = avl_do_entry (fmx, FM_DUPIGNORE);
+        assert (ai == 0);
+        fm = lookup_fontmap (bname);    /* new try */
+        assert (fm != NULL);
         return fm;
     }
-    return dummy_fm_entry();
+    return NULL;
 }
 
-
 /**********************************************************************/
-/* cleaning up... */
+/*
+Process map file given by its name or map line contents. Items not
+beginning with [+-=] flush default map file, if it has not yet been
+read. Leading blanks and blanks immediately following [+-=] are ignored.
+*/
 
-static void destroy_fm_entry_tfm(void *pa, void *pb)
+void process_map_item (char *s, int type)
 {
-    fm_entry *fm;
-    fm = (fm_entry *) pa;
-    if (!has_pslink(fm))
-        delete_fm_entry(fm);
-    else
-        unset_tfmlink(fm);
+    char *p;
+    int mode;
+    if (*s == ' ')
+        s++;                    /* ignore leading blank */
+    switch (*s) {
+    case '+':                  /* +mapfile.map, +mapline */
+        mode = FM_DUPIGNORE;    /* insert entry, if it is not duplicate */
+        s++;
+        break;
+    case '=':                  /* =mapfile.map, =mapline */
+        mode = FM_REPLACE;      /* try to replace earlier entry */
+        s++;
+        break;
+    case '-':                  /* -mapfile.map, -mapline */
+        mode = FM_DELETE;       /* try to delete entry */
+        s++;
+        break;
+    default:
+        mode = FM_DUPIGNORE;    /* like +, but also: */
+        mitem->line = NULL;     /* flush default map file name */
+    }
+    if (*s == ' ')
+        s++;                    /* ignore blank after [+-=] */
+    p = s;                      /* map item starts here */
+    switch (type) {
+    case MAPFILE:              /* remove blank at end */
+        while (*p != '\0' && *p != ' ')
+            p++;
+        *p = '\0';
+        break;
+    case MAPLINE:              /* blank at end allowed */
+        break;
+    default:
+        assert (0);
+    }
+    if (mitem->line != NULL)    /* read default map file first */
+        fm_read_info ();
+    if (*s != '\0') {           /* only if real item to process */
+        mitem->mode = mode;
+        mitem->type = type;
+        mitem->line = s;
+        fm_read_info ();
+    }
 }
 
-static void destroy_fm_entry_ps(void *pa, void *pb)
+void pdfmapfile (integer t)
 {
-    fm_entry *fm;
-    fm = (fm_entry *) pa;
-    if (!has_tfmlink(fm))
-        delete_fm_entry(fm);
-    else
-        unset_pslink(fm);
+    process_map_item (makecstring (tokenstostring (t)), MAPFILE);
+    flushstr (lasttokensstring);
 }
 
-static void destroy_ff_entry(void *pa, void *pb)
+void pdfmapline (integer t)
 {
-    ff_entry *ff;
-    ff = (ff_entry *) pa;
-    delete_ff_entry(ff);
+    process_map_item (makecstring (tokenstostring (t)), MAPLINE);
+    flushstr (lasttokensstring);
 }
 
-void fm_free(void)
+void pdfinitmapfile (string map_name)
 {
-    if (tfm_tree != NULL)
-        avl_destroy(tfm_tree, destroy_fm_entry_tfm);
-    if (ps_tree != NULL)
-        avl_destroy(ps_tree, destroy_fm_entry_ps);
-    if (ff_tree != NULL)
-        avl_destroy(ff_tree, destroy_ff_entry);
+    assert (mitem == NULL);
+    mitem = xtalloc (1, mapitem);
+    mitem->mode = FM_DUPIGNORE;
+    mitem->type = MAPFILE;
+    mitem->line = xstrdup (map_name);
 }
 
 /**********************************************************************/
+/* cleaning up... */
 
-/*
-Add mapfile name or mapline contents to the linked list "mapitems". Items
-not beginning with [+-=] flush list with pending items. Leading blanks
-and blanks immediately following [+-=] are ignored.
-*/
-
-char *add_map_item(char *s, int type)
+static void destroy_fm_entry_tfm (void *pa, void *pb)
 {
-    char *p;
-    int l;            /* length of map item (without [+-=]) */
-    mapitem *tmp;
-    int mode;
-    for (; *s == ' '; s++);    /* ignore leading blanks */
-    switch (*s) {
-    case '+':            /* +mapfile.map, +mapline */
-    mode = FM_DUPIGNORE;    /* insert entry, if it is not duplicate */
-    s++;
-    break;
-    case '=':            /* =mapfile.map, =mapline */
-    mode = FM_REPLACE;        /* try to replace earlier entry */
-    s++;
-    break;
-    case '-':            /* -mapfile.map, -mapline */
-    mode = FM_DELETE;        /* try to delete entry */
-    s++;
-    break;
-    default:
-    mode = FM_DUPIGNORE;    /* also flush pending list */
-    while (mapitems != NULL) {
-        tmp = mapitems;
-        mapitems = mapitems->next;
-        xfree(tmp->line);
-        xfree(tmp);
-    }
-    }
-    for (; *s == ' '; s++); /* ignore blanks after [+-=] */
-    p = s;                  /* map item starts here */
-    switch (type) {         /* find end of map item */
-    case MAPFILE:
-    for (; *p != 0 && *p != ' ' && *p != 10; p++);
-    break;
-    case MAPLINE:        /* blanks allowed */
-    for (; *p != 0 && *p != 10; p++);
-    break;
-    default:
-    assert(0);
-    }
-    l = p - s;
-    if (l > 0) {        /* only if real item to add */
-    tmp = xtalloc(1, mapitem);
-    if (mapitems == NULL)
-        mapitems = tmp;    /* start new list */
+    fm_entry *fm;
+    fm = (fm_entry *) pa;
+    if (!has_pslink (fm))
+        delete_fm_entry (fm);
     else
-        miptr->next = tmp;
-    miptr = tmp;
-    miptr->mode = mode;
-    miptr->type = type;
-    miptr->line = xtalloc(l + 1, char);
-    *(miptr->line) = 0;
-    strncat(miptr->line, s, l);
-    miptr->next = NULL;
-    }
-    return p;
+        unset_tfmlink (fm);
 }
-
-void pdfmapfile(integer t)
+static void destroy_fm_entry_ps (void *pa, void *pb)
 {
-    add_map_item(makecstring(tokenstostring(t)), MAPFILE);
-    flushstr(lasttokensstring);
+    fm_entry *fm;
+    fm = (fm_entry *) pa;
+    if (!has_tfmlink (fm))
+        delete_fm_entry (fm);
+    else
+        unset_pslink (fm);
 }
-
-void pdfmapline(integer t)
+static void destroy_ff_entry (void *pa, void *pb)
 {
-    add_map_item(makecstring(tokenstostring(t)), MAPLINE);
-    flushstr(lasttokensstring);
-}
-
-void pdfinitmapfile(string map_name)
+    ff_entry *ff;
+    ff = (ff_entry *) pa;
+    delete_ff_entry (ff);
+} void fm_free (void)
 {
-    if (mapitems == NULL) {
-        mapitems = xtalloc(1, mapitem);
-        miptr = mapitems;
-        miptr->mode = FM_DUPIGNORE;
-        miptr->type = MAPFILE;
-        miptr->line = xstrdup(map_name);
-        miptr->next = NULL;
-    }
+    if (tfm_tree != NULL)
+        avl_destroy (tfm_tree, destroy_fm_entry_tfm);
+    if (ps_tree != NULL)
+        avl_destroy (ps_tree, destroy_fm_entry_ps);
+    if (ff_tree != NULL)
+        avl_destroy (ff_tree, destroy_ff_entry);
 }
 
 /**********************************************************************/
-
 /* end of mapfile.c */

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.ch
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.ch	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.ch	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,33 +1,6 @@
-% WEB change file containing code for pdfTeX features extending TeX; % to be applied to tex.web (Version 3.141592) in order to define the
-% pdfTeX program.
 %
-% Note: This file, pdftex.ch, defines pdftex.web in terms of changes to be
-% applied to tex.web; in terms of a program such as TIE (or equivalent),
+% Copyright (c) 1996-2006 Han The Thanh, <thanh at pdftex.org>
 %
-%	tex.web			)
-%	   +			)   =>   tie -m ...   =>   etex.web
-%	pdftexdir/pdftex.ch	)
-%
-% In addition, this file is used to define pdfetex.web, a combination
-% of e-TeX and pdfTeX as follows:
-%
-%	tex.web			)
-%	   +			)
-%	etexdir/etex.ch		)
-%	   +			)
-%	pdfetexdir/pdfetex.ch1	)   =>   tie -m ...   =>   pdfetex.web
-%	   +			)
-%	pdftexdir/pdftex.ch	)
-%	   +			)
-%	pdfetexdir/pdfetex.ch2	)
-%
-% where the two (small) files pdfetexdir/pdfetex.ch[12] take care of
-% interferences between e-Tex changes (etexdir/etex.ch) and pdfTeX changes
-% (pdftexdir/pdftex.ch). Consequently, changes in these files have to be
-% coordinated.
-%
-% Copyright (c) 1996-2005 Han Th\^e\llap{\raise 0.5ex\hbox{\'{}}} Th\`anh, <thanh at pdftex.org>
-%
 % This file is part of pdfTeX.
 %
 % pdfTeX is free software; you can redistribute it and/or modify
@@ -44,528 +17,75 @@
 % along with pdfTeX; if not, write to the Free Software
 % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 %
-% $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftex.ch#163 $
+% $Id: //depot/Build/source.development/TeX/texk/web2c/pdfetexdir/pdfetex.ch2#20 $
 %
-% The TeX program is copyright (C) 1982 by D. E. Knuth.
-% TeX is a trademark of the American Mathematical Society.
-%
-% all pdfTeX new primitives have the prefix "\pdf", apart from:
-%   o  extension of \vadjust 
-%   o  extension of \font
-%   o  \efcode
-%   o  \lpcode, \rpcode
-    
- at x limbo
-\def\PASCAL{Pascal}
- at y
-\def\PASCAL{Pascal}
-\def\pdfTeX{pdf\TeX}
-\def\PDF{PDF}
+ at x [0.0] l.83 - WEAVE: we want the whole file
+  \def\?##1]{\hbox{Changes to \hbox to 1em{\hfil##1}.\ }}
+  }
+\let\maybe=\iffalse
+ at y 83
+  \def\?##1]{\hbox{Changes to \hbox to 1em{\hfil##1}.\ }}
+  }
+\let\maybe=\iftrue
 @z
 
- at x [2] - This change is made for TeX 3.141592
- at d banner=='This is TeX, Version 3.141592' {printed when \TeX\ starts}
- at y
- at d pdftex_version==121 { \.{\\pdftexversion} }
- at d pdftex_revision=="a" { \.{\\pdftexrevision} }
- at d pdftex_version_string=='-1.21a' {current \pdfTeX\ version}
-@#
- at d pdfTeX_banner=='This is pdfTeX, Version 3.141592',pdftex_version_string
-   {printed when \pdfTeX\ starts}
-@#
- at d TeX_banner=='This is TeX, Version 3.141592' {printed when \TeX\ starts}
-@#
- at d banner==pdfTeX_banner
- at z
+% Change file to assist in creating the web2c-specific change file.
+% This one resolves inconsistencies between tex.ch and tex.ech.
+% Public domain.
 
-% Some procedures that need to be declared forward
- at x [173]
-@* \[12] Displaying boxes.
+ at x [1] m.2 l.188 - Web2C: extensions imply we're not e-TeX
+ at d eTeX_banner=='This is e-TeX, Version 3.141592',eTeX_version_string
 @y
-@<Declare procedures that need to be declared forward for pdftex@>@;
-
-@* \[12] Displaying boxes.
+ at d eTeX_banner_k=='This is e-TeXk, Version 3.141592',eTeX_version_string
+ at d eTeX_banner=='This is e-TeX, Version 3.141592',eTeX_version_string
 @z
 
-% Define pdftex token list parameters
- at x [230]
- at d toks_base=local_base+10 {table of 256 token list registers}
+ at x [1] m.2 l.188 - Web2C: extensions imply we're not pdfeTeX
+ at d pdfeTeX_banner=='This is pdfeTeX, Version 3.141592',pdftex_version_string,eTeX_version_string
 @y
- at d tex_toks=local_base+10 {end of \TeX's token list parameters}
-@#
- at d pdftex_first_loc       = tex_toks {base for \pdfTeX's token list parameters}
- at d pdf_pages_attr_loc     = pdftex_first_loc + 0 {points to token list for \.{\\pdfpagesattr}}
- at d pdf_page_attr_loc      = pdftex_first_loc + 1 {points to token list for \.{\\pdfpageattr}}
- at d pdf_page_resources_loc = pdftex_first_loc + 2 {points to token list for \.{\\pdfpageresources}}
- at d pdf_toks=pdftex_first_loc+3 {end of \pdfTeX's token list parameters}
-@#
- at d toks_base=pdf_toks {table of 256 token list registers}
+ at d pdfeTeX_banner_k=='This is pdfeTeXk, Version 3.141592',pdftex_version_string,eTeX_version_string
+ at d pdfeTeX_banner=='This is pdfeTeX, Version 3.141592',pdftex_version_string,eTeX_version_string
 @z
 
- at x [230]
- at d err_help==equiv(err_help_loc)
+ at x [1] m.2 l.188 - Web2C: extensions imply we're not pdfTeX
+ at d pdfTeX_banner=='This is pdfTeX, Version 3.141592',pdftex_version_string
 @y
- at d err_help==equiv(err_help_loc)
- at d pdf_pages_attr==equiv(pdf_pages_attr_loc)
- at d pdf_page_attr==equiv(pdf_page_attr_loc)
- at d pdf_page_resources==equiv(pdf_page_resources_loc)
+ at d pdfTeX_banner_k=='This is pdfTeXk, Version 3.141592',pdftex_version_string
+ at d pdfTeX_banner=='This is pdfTeX, Version 3.141592',pdftex_version_string
 @z
 
- at x [230]
-primitive("errhelp",assign_toks,err_help_loc);
-@!@:err_help_}{\.{\\errhelp} primitive@>
+ at x [1] m.2 l.188 - banner
+ at d banner==TeX_banner
+ at d banner_k==TeX_banner_k
 @y
-primitive("errhelp",assign_toks,err_help_loc);
-@!@:err_help_}{\.{\\errhelp} primitive@>
-primitive("pdfpagesattr",assign_toks,pdf_pages_attr_loc);
-@!@:pdf_pages_attr_}{\.{\\pdfpagesattr} primitive@>
-primitive("pdfpageattr",assign_toks,pdf_page_attr_loc);
-@!@:pdf_page_attr_}{\.{\\pdfpageattr} primitive@>
-primitive("pdfpageresources",assign_toks,pdf_page_resources_loc);
-@!@:pdf_page_resources_}{\.{\\pdfpageresources} primitive@>
+ at d banner==pdfTeX_banner
+ at d banner_k==pdfTeX_banner_k
 @z
 
- at x [231]
-  othercases print_esc("errhelp")
- at y
-  pdf_pages_attr_loc: print_esc("pdfpagesattr");
-  pdf_page_attr_loc: print_esc("pdfpageattr");
-  pdf_page_resources_loc: print_esc("pdfpageresources");
-  othercases print_esc("errhelp")
- at z
-
-% Define pdftex integer parameters
- at x [236]
- at d int_pars=55 {total number of integer parameters}
- at y
- at d tex_int_pars=55 {total number of \TeX's integer parameters}
+ at x [17.236] l.4960 - first web2c, then e-TeX additional integer parameters
+ at d int_pars=web2c_int_pars {total number of integer parameters}
 @#
- at d pdftex_first_integer_code = tex_int_pars {base for \pdfTeX's integer parameters}
- at d pdf_output_code           = pdftex_first_integer_code + 0 {switch on PDF output if positive}
- at d pdf_compress_level_code   = pdftex_first_integer_code + 1 {compress level of streams}
- at d pdf_decimal_digits_code   = pdftex_first_integer_code + 2 {digits after the decimal point of numbers}
- at d pdf_move_chars_code       = pdftex_first_integer_code + 3 {move chars 0..31 to higher area if possible}
- at d pdf_image_resolution_code = pdftex_first_integer_code + 4 {default image resolution}
- at d pdf_pk_resolution_code    = pdftex_first_integer_code + 5 {default resolution of PK font}
- at d pdf_unique_resname_code   = pdftex_first_integer_code + 6 {generate unique names for resouces}
- at d pdf_option_pdf_minor_version_code = pdftex_first_integer_code + 7 {fractional part of the pdf version produced}
- at d pdf_option_always_use_pdfpagebox_code = pdftex_first_integer_code + 8 {if the pdf inclusion should always use a specific pdf page box}
- at d pdf_option_pdf_inclusion_errorlevel_code = pdftex_first_integer_code + 9 {if the pdf inclusion should treat pdfs newer than |pdf_option_pdf_minor_version| as an error}
- at d pdf_int_pars=pdftex_first_integer_code + 10 {total number of \pdfTeX's integer parameters}
-@#
- at d int_pars=pdf_int_pars {total number of integer parameters}
- at z
- 
- at x [236]
- at d error_context_lines==int_par(error_context_lines_code)
+ at d etex_int_base=tex_int_pars {base for \eTeX's integer parameters}
 @y
- at d error_context_lines==int_par(error_context_lines_code)
-@#
- at d pdf_output           == int_par(pdf_output_code)
- at d pdf_compress_level   == int_par(pdf_compress_level_code)
- at d pdf_decimal_digits   == int_par(pdf_decimal_digits_code)
- at d pdf_move_chars       == int_par(pdf_move_chars_code)
- at d pdf_image_resolution == int_par(pdf_image_resolution_code)
- at d pdf_pk_resolution    == int_par(pdf_pk_resolution_code)
- at d pdf_unique_resname   == int_par(pdf_unique_resname_code)
- at d pdf_option_pdf_minor_version == int_par(pdf_option_pdf_minor_version_code)
- at d pdf_option_always_use_pdfpagebox == int_par(pdf_option_always_use_pdfpagebox_code)
- at d pdf_option_pdf_inclusion_errorlevel == int_par(pdf_option_pdf_inclusion_errorlevel_code)
+ at d pdftex_first_integer_code = web2c_int_pars {base for \pdfTeX's integer parameters}
 @z
 
- at x [237]
-error_context_lines_code:print_esc("errorcontextlines");
+% start of tex.pch
+ at x (MLTeX) l. 12945
+      begin i := char_tag(char_info(f)(c));
 @y
-error_context_lines_code:print_esc("errorcontextlines");
-@#
-pdf_output_code:           print_esc("pdfoutput");
-pdf_compress_level_code:   print_esc("pdfcompresslevel");
-pdf_decimal_digits_code:   print_esc("pdfdecimaldigits");
-pdf_move_chars_code:       print_esc("pdfmovechars");
-pdf_image_resolution_code: print_esc("pdfimageresolution");
-pdf_pk_resolution_code:    print_esc("pdfpkresolution");
-pdf_unique_resname_code:   print_esc("pdfuniqueresname");
-pdf_option_pdf_minor_version_code: print_esc("pdfoptionpdfminorversion");
-pdf_option_always_use_pdfpagebox_code: print_esc("pdfoptionalwaysusepdfpagebox");
-pdf_option_pdf_inclusion_errorlevel_code: print_esc("pdfoptionpdfinclusionerrorlevel");
+      begin i := char_tag(orig_char_info(f)(c));
 @z
 
- at x [238]
-primitive("errorcontextlines",assign_int,int_base+error_context_lines_code);@/
-@!@:error_context_lines_}{\.{\\errorcontextlines} primitive@>
+ at x (MLTeX) l. 14640
+ at d is_valid_char(#)==((font_bc[f] <= #) and (# <= font_ec[f]) and 
+                      char_exists(char_info(f)(#)))
 @y
-primitive("errorcontextlines",assign_int,int_base+error_context_lines_code);@/
-@!@:error_context_lines_}{\.{\\errorcontextlines} primitive@>
-primitive("pdfoutput",assign_int,int_base+pdf_output_code);@/
-@!@:pdf_output_}{\.{\\pdfoutput} primitive@>
-primitive("pdfcompresslevel",assign_int,int_base+pdf_compress_level_code);@/
-@!@:pdf_compress_level_}{\.{\\pdfcompresslevel} primitive@>
-primitive("pdfdecimaldigits",assign_int,int_base+pdf_decimal_digits_code);@/
-@!@:pdf_decimal_digits_}{\.{\\pdfdecimaldigits} primitive@>
-primitive("pdfmovechars",assign_int,int_base+pdf_move_chars_code);@/
-@!@:pdf_move_chars_}{\.{\\pdfmovechars} primitive@>
-primitive("pdfimageresolution",assign_int,int_base+pdf_image_resolution_code);@/
-@!@:pdf_image_resolution_}{\.{\\pdfimageresolution} primitive@>
-primitive("pdfpkresolution",assign_int,int_base+pdf_pk_resolution_code);@/
-@!@:pdf_pk_resolution_}{\.{\\pdfpkresolution} primitive@>
-primitive("pdfuniqueresname",assign_int,int_base+pdf_unique_resname_code);@/
-@!@:pdf_unique_resname_}{\.{\\pdfuniqueresname} primitive@>
-primitive("pdfoptionpdfminorversion",assign_int,int_base+pdf_option_pdf_minor_version_code);@/
-@!@:pdf_option_pdf_minor_version_}{\.{\\pdfoptionpdfminorversion} primitive@>
-primitive("pdfoptionalwaysusepdfpagebox",assign_int,int_base+pdf_option_always_use_pdfpagebox_code);@/
-@!@:pdf_option_always_use_pdfpagebox_}{\.{\\pdfoptionalwaysusepdfpagebox} primitive@>
-primitive("pdfoptionpdfinclusionerrorlevel",assign_int,int_base+pdf_option_pdf_inclusion_errorlevel_code);@/
-@!@:pdf_option_pdf_inclusion_errorlevel_}{\.{\\pdfoptionpdfinclusionerrorlevel} primitive@>
+ at d is_valid_char(#)==((font_bc[f] <= #) and (# <= font_ec[f]) and 
+                      char_exists(orig_char_info(f)(#)))
 @z
 
-% Define pdftex dimension parameters
- at x [247]
- at d emergency_stretch_code=20 {reduces badnesses on final pass of line-breaking}
- at y
- at d emergency_stretch_code=20 {reduces badnesses on final pass of line-breaking}
- at d pdftex_first_dimen_code = 21 {first number defined in this section}
- at d pdf_h_origin_code       = pdftex_first_dimen_code + 0 {horigin of the PDF output}
- at d pdf_v_origin_code       = pdftex_first_dimen_code + 1 {vorigin of the PDF output}
- at d pdf_page_width_code     = pdftex_first_dimen_code + 2 {page width of the PDF output}
- at d pdf_page_height_code    = pdftex_first_dimen_code + 3 {page height of the PDF output}
- at d pdf_link_margin_code    = pdftex_first_dimen_code + 4 {link margin in the PDF output}
- at d pdf_dest_margin_code    = pdftex_first_dimen_code + 5 {dest margin in the PDF output}
- at d pdf_thread_margin_code  = pdftex_first_dimen_code + 6 {thread margin in the PDF output}
- at d pdftex_last_dimen_code  = pdftex_first_dimen_code + 6 {last number defined in this section}
- at z
-
- at x
- at d dimen_pars=21 {total number of dimension parameters}
- at y
- at d dimen_pars = pdftex_last_dimen_code + 1 {total number of dimension parameters}
- at z
-
- at x [247]
- at d emergency_stretch==dimen_par(emergency_stretch_code)
- at y
- at d emergency_stretch==dimen_par(emergency_stretch_code)
- at d pdf_h_origin      == dimen_par(pdf_h_origin_code)
- at d pdf_v_origin      == dimen_par(pdf_v_origin_code)
- at d pdf_page_width    == dimen_par(pdf_page_width_code)
- at d pdf_page_height   == dimen_par(pdf_page_height_code)
- at d pdf_link_margin   == dimen_par(pdf_link_margin_code)
- at d pdf_dest_margin   == dimen_par(pdf_dest_margin_code)
- at d pdf_thread_margin == dimen_par(pdf_thread_margin_code)
- at z
-
- at x [247]
-emergency_stretch_code:print_esc("emergencystretch");
- at y
-emergency_stretch_code:print_esc("emergencystretch");
-pdf_h_origin_code:      print_esc("pdfhorigin");
-pdf_v_origin_code:      print_esc("pdfvorigin");
-pdf_page_width_code:    print_esc("pdfpagewidth");
-pdf_page_height_code:   print_esc("pdfpageheight");
-pdf_link_margin_code:   print_esc("pdflinkmargin");
-pdf_dest_margin_code:   print_esc("pdfdestmargin");
-pdf_thread_margin_code: print_esc("pdfthreadmargin");
- at z
-
- at x [248]
-primitive("emergencystretch",assign_dimen,dimen_base+emergency_stretch_code);@/
-@!@:emergency_stretch_}{\.{\\emergencystretch} primitive@>
- at y
-primitive("emergencystretch",assign_dimen,dimen_base+emergency_stretch_code);@/
-@!@:emergency_stretch_}{\.{\\emergencystretch} primitive@>
-primitive("pdfhorigin",assign_dimen,dimen_base+pdf_h_origin_code);@/
-@!@:pdf_h_origin_}{\.{\\pdfhorigin} primitive@>
-primitive("pdfvorigin",assign_dimen,dimen_base+pdf_v_origin_code);@/
-@!@:pdf_v_origin_}{\.{\\pdfvorigin} primitive@>
-primitive("pdfpagewidth",assign_dimen,dimen_base+pdf_page_width_code);@/
-@!@:pdf_page_width_}{\.{\\pdfpagewidth} primitive@>
-primitive("pdfpageheight",assign_dimen,dimen_base+pdf_page_height_code);@/
-@!@:pdf_page_height_}{\.{\\pdfpageheight} primitive@>
-primitive("pdflinkmargin",assign_dimen,dimen_base+pdf_link_margin_code);@/
-@!@:pdf_link_margin_}{\.{\\pdflinkmargin} primitive@>
-primitive("pdfdestmargin",assign_dimen,dimen_base+pdf_dest_margin_code);@/
-@!@:pdf_dest_margin_}{\.{\\pdfdestmargin} primitive@>
-primitive("pdfthreadmargin",assign_dimen,dimen_base+pdf_thread_margin_code);@/
-@!@:pdf_thread_margin_}{\.{\\pdfthreadmargin} primitive@>
- at z
-
-% Define some read-only pdfTeX primitives
- at x [416]
-|glue_val|, |input_line_no_code|, or |badness_code|.
- at y
-|glue_val|, |input_line_no_code|, or |badness_code|.
-\pdfTeX\ adds the codes for its extensions: |pdftex_version_code|, \dots\ .
- at z
-
- at x [416]
- at d badness_code=glue_val+2 {code for \.{\\badness}}
- at y
- at d badness_code=input_line_no_code+1 {code for \.{\\badness}}
-@#
- at d pdftex_first_rint_code     = badness_code + 1 {base for \pdfTeX's command codes}
- at d pdftex_version_code        = pdftex_first_rint_code + 0 {code for \.{\\pdftexversion}}
- at d pdf_last_obj_code          = pdftex_first_rint_code + 1 {code for \.{\\pdflastobj}}
- at d pdf_last_xform_code        = pdftex_first_rint_code + 2 {code for \.{\\pdflastxform}}
- at d pdf_last_ximage_code       = pdftex_first_rint_code + 3 {code for \.{\\pdflastximage}}
- at d pdf_last_ximage_pages_code = pdftex_first_rint_code + 4 {code for \.{\\pdflastximagepages}}
- at d pdf_last_annot_code        = pdftex_first_rint_code + 5 {code for \.{\\pdflastannot}}
- at d pdf_last_x_pos_code        = pdftex_first_rint_code + 6 {code for \.{\\pdflastxpos}}
- at d pdf_last_y_pos_code        = pdftex_first_rint_code + 7 {code for \.{\\pdflastypos}}
- at d pdftex_last_item_codes     = pdftex_first_rint_code + 7 {end of \pdfTeX's command codes}
- at z
-
- at x [416]
-primitive("badness",last_item,badness_code);
-@!@:badness_}{\.{\\badness} primitive@>
- at y
-primitive("badness",last_item,badness_code);
-@!@:badness_}{\.{\\badness} primitive@>
-primitive("pdftexversion",last_item,pdftex_version_code);@/
-@!@:pdftex_version_}{\.{\\pdftexversion} primitive@>
-primitive("pdflastobj",last_item,pdf_last_obj_code);@/
-@!@:pdf_last_obj_}{\.{\\pdflastobj} primitive@>
-primitive("pdflastxform",last_item,pdf_last_xform_code);@/
-@!@:pdf_last_xform_}{\.{\\pdflastxform} primitive@>
-primitive("pdflastximage",last_item,pdf_last_ximage_code);@/
-@!@:pdf_last_ximage_}{\.{\\pdflastximage} primitive@>
-primitive("pdflastximagepages",last_item,pdf_last_ximage_pages_code);@/
-@!@:pdf_last_ximage_pages_}{\.{\\pdflastximagepages} primitive@>
-primitive("pdflastannot",last_item,pdf_last_annot_code);@/
-@!@:pdf_last_annot_}{\.{\\pdflastannot} primitive@>
-primitive("pdflastxpos",last_item,pdf_last_x_pos_code);@/
-@!@:pdf_last_x_pos_}{\.{\\pdflastxpos} primitive@>
-primitive("pdflastypos",last_item,pdf_last_y_pos_code);@/
-@!@:pdf_last_y_pos_}{\.{\\pdflastypos} primitive@>
- at z
-
- at x [417]
-  othercases print_esc("badness")
- at y
-  pdftex_version_code:  print_esc("pdftexversion");
-  pdf_last_obj_code:    print_esc("pdflastobj");
-  pdf_last_xform_code:  print_esc("pdflastxform");
-  pdf_last_ximage_code: print_esc("pdflastximage");
-  pdf_last_ximage_pages_code: print_esc("pdflastximagepages");
-  pdf_last_annot_code:  print_esc("pdflastannot");
-  pdf_last_x_pos_code:  print_esc("pdflastxpos");
-  pdf_last_y_pos_code:  print_esc("pdflastypos");
-  othercases print_esc("badness")
- at z
-
- at x [26.424] l.8506
-if cur_chr>glue_val then
- at y
-if m>=input_line_no_code then
- at z
-
- at x [26.424] l.8507
-  begin if cur_chr=input_line_no_code then cur_val:=line
-  else cur_val:=last_badness; {|cur_chr=badness_code|}
- at y
-  begin case m of
-  input_line_no_code: cur_val:=line;
-  badness_code: cur_val:=last_badness;
-  pdftex_version_code:  cur_val := pdftex_version;
-  pdf_last_obj_code:    cur_val := pdf_last_obj;
-  pdf_last_xform_code:  cur_val := pdf_last_xform;
-  pdf_last_ximage_code: cur_val := pdf_last_ximage;
-  pdf_last_ximage_pages_code: cur_val := pdf_last_ximage_pages;
-  pdf_last_annot_code:  cur_val := pdf_last_annot;
-  pdf_last_x_pos_code:  cur_val := pdf_last_x_pos;
-  pdf_last_y_pos_code:  cur_val := pdf_last_y_pos;
-  end; {there are no other cases}
- at z
-
-% Define some char token producing pdfTeX primitives
- at x [27.468] l.9202
- at d number_code=0 {command code for \.{\\number}}
- at y
-\pdfTeX\ adds \.{\\eTeXrevision}, \.{\\pdftexrevision}, \.{\\pdftexbanner},
-\.{\\pdffontname}, \.{\\pdffontobjnum}, \.{\\pdffontsize}, and \.{\\pdfpageref}
-such that |job_name_code| remains last.
-
- at d number_code=0 {command code for \.{\\number}}
- at z
-
- at x [27.468] l.9207
- at d job_name_code=5 {command code for \.{\\jobname}}
- at y
- at d pdftex_first_expand_code = 5 {base for \pdfTeX's command codes}
- at d pdftex_revision_code     = pdftex_first_expand_code + 0 {command code for \.{\\pdftexrevision}}
- at d pdftex_banner_code       = pdftex_first_expand_code + 1 {command code for \.{\\pdftexbanner}}
- at d pdf_font_name_code       = pdftex_first_expand_code + 2 {command code for \.{\\pdffontname}}
- at d pdf_font_objnum_code     = pdftex_first_expand_code + 3 {command code for \.{\\pdffontobjnum}}
- at d pdf_font_size_code       = pdftex_first_expand_code + 4 {command code for \.{\\pdffontsize}}
- at d pdf_page_ref_code        = pdftex_first_expand_code + 5 {command code for \.{\\pdfpageref}}
- at d pdftex_convert_codes     = pdftex_first_expand_code + 6 {end of \pdfTeX's command codes}
- at d job_name_code=pdftex_convert_codes {command code for \.{\\jobname}}
- at z
-
- at x [27.468] l.9220
-primitive("jobname",convert,job_name_code);@/
- at y
-@#
-primitive("pdftexrevision",convert,pdftex_revision_code);@/
-@!@:pdftex_revision_}{\.{\\pdftexrevision} primitive@>
-primitive("pdftexbanner",convert,pdftex_banner_code);@/
-@!@:pdftex_banner_}{\.{\\pdftexbanner} primitive@>
-primitive("pdffontname",convert,pdf_font_name_code);@/
-@!@:pdf_font_name_}{\.{\\pdffontname} primitive@>
-primitive("pdffontobjnum",convert,pdf_font_objnum_code);@/
-@!@:pdf_font_objnum_}{\.{\\pdffontobjnum} primitive@>
-primitive("pdffontsize",convert,pdf_font_size_code);@/
-@!@:pdf_font_size_}{\.{\\pdffontsize} primitive@>
-primitive("pdfpageref",convert,pdf_page_ref_code);@/
-@!@:pdf_page_ref_}{\.{\\pdfpageref} primitive@>
-@#
-primitive("jobname",convert,job_name_code);@/
- at z
-
- at x [469]
-  othercases print_esc("jobname")
- at y
-  pdftex_revision_code: print_esc("pdftexrevision");
-  pdftex_banner_code:   print_esc("pdftexbanner");
-  pdf_font_name_code:   print_esc("pdffontname");
-  pdf_font_objnum_code: print_esc("pdffontobjnum");
-  pdf_font_size_code:   print_esc("pdffontsize");
-  pdf_page_ref_code:    print_esc("pdfpageref");
-  othercases print_esc("jobname")
- at z
-
- at x [471]
-job_name_code: if job_name=0 then open_log_file;
- at y
-pdftex_revision_code: do_nothing;
-pdftex_banner_code: do_nothing;
-pdf_font_name_code, pdf_font_objnum_code, pdf_font_size_code: begin
-    scan_font_ident;
-    if cur_val = null_font then
-        pdf_error("font", "invalid font identifier");
-    if c <> pdf_font_size_code then begin
-        pdf_check_vf(cur_val);
-        if not font_used[cur_val] then
-            pdf_init_font(cur_val);
-    end;
-end;
-pdf_page_ref_code: begin
-    scan_int;
-    if cur_val <= 0 then
-        pdf_error("pageref", "invalid page number");
-end;
-job_name_code: if job_name=0 then open_log_file;
- at z
-
- at x [472]
-job_name_code: print(job_name);
- at y
-pdftex_revision_code: print(pdftex_revision);
-pdftex_banner_code: print(pdftex_banner);
-pdf_font_name_code, pdf_font_objnum_code: begin
-    set_ff(cur_val);
-    if c = pdf_font_name_code then
-        print_int(obj_info(pdf_font_num[ff]))
-    else
-        print_int(pdf_font_num[ff]);
-end;
-pdf_font_size_code: print_scaled(font_size[cur_val]);
-pdf_page_ref_code: print_int(get_obj(obj_type_page, cur_val, false));
-job_name_code: print(job_name);
- at z
-
-% Shipping out to PDF
- at x [638]
-@ The |hlist_out| and |vlist_out| procedures are now complete, so we are
-ready for the |ship_out| routine that gets them started in the first place.
-
- at p procedure ship_out(@!p:pointer); {output the box |p|}
- at y
-@ The |hlist_out| and |vlist_out| procedures are now complete, so we are
-ready for the |dvi_ship_out| routine that gets them started in the first place.
-
- at p procedure dvi_ship_out(@!p:pointer); {output the box |p|}
- at z
-
- at x [644]
-@* \[33] Packaging.
- at y
-
-@* \[32a] \pdfTeX\ basic.
-
-@<Constants...@>=
-cfg_output_code = pdf_output_code;
-cfg_compress_level_code = pdf_compress_level_code;
-cfg_decimal_digits_code = pdf_decimal_digits_code;
-cfg_move_chars_code = pdf_move_chars_code;
-cfg_image_resolution_code = pdf_image_resolution_code;
-cfg_pk_resolution_code = pdf_pk_resolution_code;
-cfg_unique_resname_code = pdf_unique_resname_code;
-cfg_h_origin_code = pdf_h_origin_code;
-cfg_v_origin_code = pdf_v_origin_code;
-cfg_page_height_code = pdf_page_height_code;
-cfg_page_width_code = pdf_page_width_code;
-cfg_link_margin_code = pdf_link_margin_code;
-cfg_dest_margin_code = pdf_dest_margin_code;
-cfg_thread_margin_code = pdf_thread_margin_code;
-cfg_pdf12_compliant_code = pdf_thread_margin_code + 1;
-cfg_pdf13_compliant_code = cfg_pdf12_compliant_code + 1;
-cfg_pdf_minor_version_code = pdf_option_pdf_minor_version_code;
-cfg_always_use_pdf_pagebox_code = 71; {must be the same as the definition in epdf.h}
-cfg_pdf_option_pdf_inclusion_errorlevel_code = pdf_option_pdf_inclusion_errorlevel_code;
-
-@ Initialize pdftex's parameters to some useful default value.   
-Helpful in case one forgets to set them during initex run.
-
-@<Initialize table entries...@>=
-pdf_h_origin := (one_hundred_inch + 50) div 100;
-pdf_v_origin := (one_hundred_inch + 50) div 100;
-pdf_compress_level := 9;
-pdf_decimal_digits := 4;
-pdf_image_resolution := 72;
-pdf_option_pdf_minor_version := 4;
-
-@ The subroutines define the corresponding macros so we can use them
-in C.
-
- at d flushable(#) == (# = str_ptr - 1)
-
- at d is_valid_char(#)==((font_bc[f] <= #) and (# <= font_ec[f]) and 
-                      char_exists(char_info(f)(#)))
-
- at p function get_int_par(p: integer): integer;
-begin
-    get_int_par := int_par(p);
-end;
-
-function get_nullfont: internal_font_number;
-begin
-    get_nullfont := null_font;
-end;
-
-function get_nullcs: pointer;
-begin
-    get_nullcs := null_cs;
-end;
-
-function get_nullptr: pointer;
-begin
-    get_nullptr := null;
-end;
-
-function get_tex_int(code: integer): integer;
-begin
-    get_tex_int := int_par(code);
-end;
-
-function get_tex_dimen(code: integer): scaled;
-begin
-    get_tex_dimen := dimen_par(code);
-end;
-
-function get_x_height(f: internal_font_number): scaled;
-begin
-    get_x_height := x_height(f);
-end;
-
+ at x (MLTeX) l. 14678
 function get_charwidth(f: internal_font_number; c: eight_bits): scaled;
 begin
     if is_valid_char(c) then
@@ -589,5841 +109,348 @@
     else
         get_chardepth := 0;
 end;
-
-function get_quad(f: internal_font_number): scaled;
+ at y
+function get_charwidth(f: internal_font_number; c: eight_bits): scaled;
 begin
-    get_quad := quad(f);
-end;
-
-function get_slant(f: internal_font_number): scaled;
-begin
-    get_slant := slant(f);
-end;
-
-function new_dummy_font: internal_font_number;
-begin
-    new_dummy_font := read_font_info(null_cs, "dummy", "", -1000);
-end;
-
-@ Helper for debugging purporses
-
- at p procedure short_display_n(@!p, m:integer); {prints highlights of list |p|}
-var n:integer; {for replacement counts}
-    i: integer;
-begin 
-i := 0; 
-font_in_short_display:=null_font;
-if p = null then
-    return;
-while p>mem_min do
-  begin if is_char_node(p) then
-    begin if p<=mem_end then
-      begin if font(p)<>font_in_short_display then
-        begin if (font(p)<font_base)or(font(p)>font_max) then
-          print_char("*")
- at .*\relax@>
-        else @<Print the font identifier for |font(p)|@>;
-        print_char(" "); font_in_short_display:=font(p);
-        end;
-      print_ASCII(qo(character(p)));
-      end;
-    end
-  else begin
-      if (type(p) = glue_node) or 
-         (type(p) = disc_node) or 
-         (type(p) = penalty_node) or
-         ((type(p) = kern_node) and (subtype(p) = explicit)) then 
-         incr(i);
-      if i >= m then
-         return;
-      if (type(p) = disc_node) then begin 
-          print("|");
-          short_display(pre_break(p));
-          print("|");
-          short_display(post_break(p));
-          print("|");
-          n:=replace_count(p);
-          while n>0 do
-              begin if link(p)<>null then p:=link(p);
-          decr(n);
-          end;
-        end
-        else
-            @<Print a short indication of the contents of node |p|@>;
-  end;
-  p:=link(p);
-  if p = null then
-      return;
-  end;
-  update_terminal;
-end;
-
-@ Sometimes it is neccesary to allocate memory for PDF output that cannot
-be deallocated then, so we use |pdf_mem| for this purpose.
-
-@<Constants...@>=
-@!inf_pdf_mem_size = 32000; {min size of the |pdf_mem| array}
-@!sup_pdf_mem_size = 524288; {max size of the |pdf_mem| array}
-
-@ @<Glob...@>=
-@!pdf_mem_size: integer;
-@!pdf_mem: ^integer;
-@!pdf_mem_ptr: integer;
-
-@ @<Set init...@>=
-pdf_mem_ptr := 1; {the first word is not used so we can use zero as a value for testing
-whether a pointer to |pdf_mem| is valid}
-
-@ We use |pdf_get_mem| to allocate memory in |pdf_mem|
-
- at p function pdf_get_mem(s: integer): integer; {allocate |s| words in
-|pdf_mem|}
-begin
-    if pdf_mem_ptr + s > pdf_mem_size then
-        overflow("PDF memory size (pdf_mem_size)", pdf_mem_size);
-    pdf_get_mem := pdf_mem_ptr;
-    pdf_mem_ptr := pdf_mem_ptr + s;
-end;
-
-
-@* \[32b] \pdfTeX\ output low-level subroutines.
-We use the similiar subroutines to handle the output buffer for
-PDF output. When compress is used, the state of writing to buffer
-is held in |zip_write_state|. We must write the header of PDF
-output file in initialization to ensure that it will be the first
-written bytes.
-
-@<Constants...@>=
-@!pdf_buf_size = 16384; {size of the PDF buffer}
-
-@ The following macros are similar as for \.{DVI} buffer handling
-
- at d pdf_offset == (pdf_gone + pdf_ptr) {the file offset of last byte in PDF
-buffer that |pdf_ptr| points to}
-
- at d no_zip == 0 {no \.{ZIP} compression}
- at d zip_writing == 1 {\.{ZIP} compression being used}
- at d zip_finish == 2 {finish \.{ZIP} compression}
-
- at d pdf_quick_out(#) == {output a byte to PDF buffer without checking of
-overflow}
-begin
-    pdf_buf[pdf_ptr] := #;
-    incr(pdf_ptr);
-end
-
- at d pdf_room(#) == {make sure that there are at least |n| bytes free in PDF
-buffer}
-begin
-    if pdf_buf_size < # then
-        overflow("PDF output buffer", pdf_buf_size);
-    if pdf_ptr + # > pdf_buf_size then
-        pdf_flush;
-end
-
- at d pdf_out(#) == {do the same as |pdf_quick_out| and flush the PDF
-buffer if necessary}
-begin
-    if pdf_ptr > pdf_buf_size then
-        pdf_flush;
-    pdf_quick_out(#);
-end
-
-@<Glob...@>=
-@!pdf_file: byte_file; {the PDF output file}
-@!pdf_buf: array[0..pdf_buf_size] of eight_bits; {the PDF buffer}
-@!pdf_ptr: integer; {pointer to the first unused byte in the PDF buffer}
-@!pdf_gone: integer; {number of bytes that were flushed to output}
-@!pdf_save_offset: integer; {to save |pdf_offset|}
-@!zip_write_state: integer; {which state of compression we are in}
-@!fixed_pdf_minor_version: integer; {fixed minor part of the pdf version}
-@!pdf_minor_version_has_been_written: boolean; {flag if the pdf version has been written}
-@!fixed_pdfoutput: integer; {fixed output format}
-@!fixed_pdfoutput_set: boolean; {|fixed_pdfoutput| has been set?}
-
-@ @<Set init...@>=
-pdf_buf[0] := "%";
-pdf_buf[1] := "P";
-pdf_buf[2] := "D";
-pdf_buf[3] := "F";
-pdf_buf[4] := "-";
-pdf_buf[5] := "1";
-pdf_buf[6] := ".";
-pdf_buf[7] := "4";
-pdf_buf[8] := pdf_new_line_char;
-pdf_ptr := 9;
-pdf_gone := 0;
-zip_write_state := no_zip;
-pdf_minor_version_has_been_written := false;
-fixed_pdfoutput_set := false;
-
-@ @p 
-function fix_int(val, min, max: integer): integer;
-begin
-    if val < min then
-        fix_int := min
-    else if val > max then
-        fix_int := max
+    if is_valid_char(c) then
+        get_charwidth := char_width(f)(orig_char_info(f)(c))
     else
-        fix_int := val;
+        get_charwidth := 0;
 end;
 
-@ This checks that |pdfoptionpdfminorversion| can only be set before any
-bytes have been written to the generated pdf file. It should be called
-directly every after |ensure_pdf_open|.
-
- at p procedure check_and_set_pdfoptionpdfminorversion;
+function get_charheight(f: internal_font_number; c: eight_bits): scaled;
 begin
-    if not pdf_minor_version_has_been_written then begin
-        pdf_minor_version_has_been_written := true;
-        if (pdf_option_pdf_minor_version < 0) or (pdf_option_pdf_minor_version > 9) then begin
-        print_err("pdfTeX error (illegal pdfoptionpdfminorversion)");
-        print_ln;
-        help2 ("The pdfoptionpdfminorversion must be between 0 and 9.")@/
-            ("I changed this to 4.");
-        int_error (pdf_option_pdf_minor_version);
-        pdf_option_pdf_minor_version := 4;
-        end;
-        fixed_pdf_minor_version := pdf_option_pdf_minor_version;
-        pdf_buf[7] := chr(ord("0") + fixed_pdf_minor_version);
-    end
-    else begin
-        if fixed_pdf_minor_version <> pdf_option_pdf_minor_version then
-            pdf_error("setup", 
-               "\pdfoptionpdfminorversion cannot be changed after data is written to the pdf file");
-    end;
-end;
-
-@ Checks that we have a name for the generated pdf file and that it's open.
-|check_and_set_pdfoptionpdfminorversion| should be called directly
-hereafter.
-
- at p procedure ensure_pdf_open;
-begin
-    if output_file_name <> 0 then
-        return;
-    if job_name = 0 then
-        open_log_file;
-    pack_job_name(".pdf");
-    while not b_open_out(pdf_file) do
-        prompt_file_name("file name for output",".pdf");
-    output_file_name := b_make_name_string(pdf_file);
-end;
-
-@ The PDF buffer is flushed by calling |pdf_flush|, which checks the
-variable |zip_write_state| and will compress the buffer before flushing if
-neccesary. We call |pdf_begin_stream| to begin a stream  and |pdf_end_stream|
-to finish it. The stream contents will be compressed if compression is turn on.
-
- at p procedure pdf_flush; {flush out the |pdf_buf|}
-begin
-    ensure_pdf_open;
-    check_and_set_pdfoptionpdfminorversion;
-    case zip_write_state of
-        no_zip: if pdf_ptr > 0 then begin
-            write_pdf(0, pdf_ptr - 1);
-            pdf_gone := pdf_gone + pdf_ptr;
-        end;
-        zip_writing:
-            write_zip(false);
-        zip_finish: begin
-            write_zip(true);
-            zip_write_state := no_zip;
-        end;
-    end;
-    pdf_ptr := 0;
-end;
-
-procedure pdf_begin_stream; {begin a stream}
-begin
-    ensure_pdf_open;
-    check_and_set_pdfoptionpdfminorversion;
-    pdf_print_ln("/Length           ");
-    pdf_stream_length_offset := pdf_offset - 11;
-    pdf_stream_length := 0;
-    if pdf_compress_level > 0 then begin
-        pdf_print_ln("/Filter /FlateDecode");
-        pdf_print_ln(">>");
-        pdf_print_ln("stream");
-        pdf_flush;
-        zip_write_state := zip_writing;
-    end
-    else begin
-        pdf_print_ln(">>");
-        pdf_print_ln("stream");
-        pdf_save_offset := pdf_offset;
-    end;
-end;
-
-procedure pdf_end_stream; {end a stream}
-begin
-    if pdf_compress_level > 0 then
-        zip_write_state := zip_finish
+    if is_valid_char(c) then
+        get_charheight := char_height(f)(height_depth(orig_char_info(f)(c)))
     else
-        pdf_stream_length := pdf_offset - pdf_save_offset;
-    pdf_flush;
-    write_stream_length(pdf_stream_length, pdf_stream_length_offset);
-    pdf_print_nl;
-    pdf_print_ln("endstream");
-    pdf_end_obj;
+        get_charheight := 0;
 end;
 
-@ Basic printing procedures for PDF output are very similiar to \TeX\ basic
-printing ones but the output is going to PDF buffer. Subroutines with
-suffix |_ln| append a new-line character to the PDF output.
-
- at d pdf_new_line_char == 10 {new-line character for UNIX platforms}
-
- at d pdf_print_nl == {output a new-line character to PDF buffer}
-if (pdf_ptr > 0) and (pdf_buf[pdf_ptr - 1] <> pdf_new_line_char) then
-    pdf_out(pdf_new_line_char)
-
- at d pdf_print_ln(#) == {print out a string to PDF buffer followed by
-a new-line character}
+function get_chardepth(f: internal_font_number; c: eight_bits): scaled;
 begin
-    pdf_print(#);
-    pdf_print_nl;
-end
-
- at d pdf_print_int_ln(#) == {print out an integer to PDF buffer followed by
-a new-line character}
-begin
-    pdf_print_int(#);
-    pdf_print_nl;
-end
-
-@<Declare procedures that need to be declared forward for pdftex@>=
-procedure pdf_error(t, p: str_number);
-begin
-    normalize_selector;
-    print_err("pdfTeX error");
-    if t <> 0 then begin
-        print(" (");
-        print(t);
-        print(")");
-    end;
-    print(": "); print(p);
-    succumb;
-end;
-
-procedure pdf_warning(t, p: str_number; append_nl: boolean);
-begin
-    print_err("pdfTeX warning");
-    if t <> 0 then begin
-        print(" (");
-        print(t);
-        print(")");
-    end;
-    print(": "); print(p);
-    if append_nl then
-        print_ln;
-end;
-
-procedure remove_last_space;
-begin
-    if (pdf_ptr > 0) and (pdf_buf[pdf_ptr - 1] = 32) then
-        decr(pdf_ptr);
-end;
-
-procedure pdf_print_octal(n: integer); {prints an integer in octal form to
-PDF buffer}
-var k:0..23; {index to current digit; we assume that $|n|<10^{23}$}
-begin
-  k:=0;
-  repeat dig[k]:=n mod 8; n:=n div 8; incr(k);
-  until n=0;
-  if k = 1 then begin
-    pdf_out("0");
-    pdf_out("0");
-  end;
-  if k = 2 then
-    pdf_out("0");
-  while k>0 do begin
-    decr(k);
-    pdf_out("0"+dig[k]);
-  end;
-end;
-
-procedure pdf_print_char(f: internal_font_number; c: integer);
-{ print out a character to PDF buffer; the character will be printed in octal
-  form in the following cases: chars <= 32, backslash (92), left parenthesis
-  (40) and  right parenthesis (41) }
-begin
-    if c <= 32 then
-        c := pdf_char_map[f, c];
-    pdf_mark_char(f, c);
-    if (c <= 32) or (c = 92) or (c = 40) or (c = 41) or (c > 127) then begin
-        pdf_out(92);           {output a backslash}
-        pdf_print_octal(c);
-    end
+    if is_valid_char(c) then
+        get_chardepth := char_depth(f)(height_depth(orig_char_info(f)(c)))
     else
-        pdf_out(c);
+        get_chardepth := 0;
 end;
+ at z
 
-procedure pdf_print(s: str_number); {print out a string to PDF buffer}
-var j: pool_pointer; {current character code position}
-    c: integer;
-begin
-    j := str_start[s];
-    while j < str_start[s + 1] do begin
-       c := str_pool[j];
-       pdf_out(c);
-       incr(j);
-    end;
-end;
 
-function str_in_str(s, r: str_number; i: integer): boolean;
-  {test equality of strings}
-label not_found; {loop exit}
-var j, k: pool_pointer; {running indices}
-@!result: boolean; {result of comparison}
-begin 
-    str_in_str := false;
-    if length(s) < i + length(r) then
-        return;
-    j := i + str_start[s];
-    k := str_start[r];
-    while (j < str_start[s + 1]) and (k < str_start[r + 1]) do begin
-        if str_pool[j] <> str_pool[k] then
-            return;
-        incr(j);
-        incr(k);
-    end;
-    str_in_str := true;
-end;
-
-procedure literal(s: str_number; reset_origin, is_special, warn: boolean);
-var j: pool_pointer; {current character code position}
-begin
-    j:=str_start[s];
-    if is_special then begin
-        if not (str_in_str(s, "PDF:", 0) or str_in_str(s, "pdf:", 0)) then begin
-            if warn and not (str_in_str(s, "SRC:", 0) or str_in_str(s, "src:", 0) or (length(s) = 0)) then
-                print_nl("Non-PDF special ignored!");
-            return;
-        end;
-        j := j + length("PDF:");
-        if str_in_str(s, "direct:", length("PDF:")) then begin
-            j := j + length("direct:");
-            reset_origin := false;
-        end
-        else
-            reset_origin := true;
-    end;
-    if reset_origin then begin
-        pdf_end_text;
-        pdf_set_origin;
-    end
-    else begin
-        pdf_end_string;
-        pdf_print_nl;
-    end;
-    while j<str_start[s+1] do begin
-       pdf_out(str_pool[j]);
-       incr(j);
-    end;
-    pdf_print_nl;
-end;
-
-procedure pdf_print_int(n:integer); {print out a integer to PDF buffer}
-var k:0..23; {index to current digit; we assume that $|n|<10^{23}$}
-m:integer; {used to negate |n| in possibly dangerous cases}
-begin
-  k:=0;
-  if n<0 then
-    begin pdf_out("-");
-    if n>-100000000 then negate(n)
-    else  begin m:=-1-n; n:=m div 10; m:=(m mod 10)+1; k:=1;
-      if m<10 then dig[0]:=m
-      else  begin dig[0]:=0; incr(n);
-        end;
-      end;
-    end;
-  repeat dig[k]:=n mod 10; n:=n div 10; incr(k);
-  until n=0;
-  pdf_room(k);
-  while k>0 do begin
-    decr(k);
-    pdf_quick_out("0"+dig[k]);
-  end;
-end;
-
-procedure pdf_print_two(n:integer); {prints two least significant digits in
-decimal form to PDF buffer}
-begin n:=abs(n) mod 100; pdf_out("0"+(n div 10));
-pdf_out("0"+(n mod 10));
-end;
-
-function tokens_to_string(p: pointer): str_number; {return a string from tokens
-list}
-begin
-    if selector = new_string then
-        pdf_error("tokens", "tokens_to_string() called while selector = new_string");
-    old_setting:=selector; selector:=new_string;
-    show_token_list(link(p),null,pool_size-pool_ptr);
-    selector:=old_setting;
-    last_tokens_string := make_string;
-    tokens_to_string := last_tokens_string;
-end;
-
-
-@ To print |scaled| value to PDF output we need some subroutines to ensure
-accurary.
-
- at d max_integer == @"7FFFFFFF {$2^{31}-1$}
- at d call_func(#) == begin if # <> 0 then do_nothing end
-
-@<Glob...@>=
-@!one_bp: scaled; {scaled value corresponds to 1bp}
-@!one_hundred_bp: scaled; {scaled value corresponds to 100bp}
-@!one_hundred_inch: scaled; {scaled value corresponds to 100in}
-@!ten_pow: array[0..9] of integer; {$10^0..10^9$}
-@!scaled_out: integer; {amount of |scaled| that was taken out in
-|divide_scaled|}
-@!init_pdf_output: boolean;
-
-@ @<Set init...@>=
-one_bp := 65782; {65781.76}
-one_hundred_bp := 6578176;
-one_hundred_inch := 473628672;
-ten_pow[0] := 1;
-for i := 1 to 9 do
-    ten_pow[i] := 10*ten_pow[i - 1];
-init_pdf_output := false;
-
-
-@ The following function divides |s| by |m|. |dd| is number of decimal digits.
-
-@<Declare procedures that need to be declared forward for pdftex@>=
-function divide_scaled(s, m: scaled; dd: integer): scaled;
-var q, r: scaled;
-    sign, i: integer;
-begin
-    sign := 1;
-    if s < 0 then begin
-        sign := -sign;
-        s := -s;
-    end;
-    if m < 0 then begin
-        sign := -sign;
-        m := -m;
-    end;
-    if m = 0 then
-        pdf_error("arithmetic", "divided by zero")
-    else if m >= (max_integer div 10) then
-        pdf_error("arithmetic", "number too big");
-    q := s div m;
-    r := s mod m;
-    for i := 1 to dd do begin
-        q := 10*q + (10*r) div m;
-        r := (10*r) mod m;
-    end;
-    if 2*r >= m then begin
-        incr(q);
-        r := r - m;
-    end;
-    scaled_out := sign*(s - (r div ten_pow[dd]));
-    divide_scaled := sign*q;
-end;
-
-function round_xn_over_d(@!x:scaled; @!n,@!d:integer):scaled;
-var positive:boolean; {was |x>=0|?}
-@!t,@!u,@!v:nonnegative_integer; {intermediate quantities}
-begin if x>=0 then positive:=true
-else  begin negate(x); positive:=false;
-  end;
-t:=(x mod @'100000)*n;
-u:=(x div @'100000)*n+(t div @'100000);
-v:=(u mod d)*@'100000 + (t mod @'100000);
-if u div d>=@'100000 then arith_error:=true
-else u:=@'100000*(u div d) + (v div d);
-v := v mod d;
-if 2*v >= d then
-    incr(u);
-if positive then 
-    round_xn_over_d := u
-else
-    round_xn_over_d := -u;
-end;
-
-
-@ Next subroutines are needed for controling spacing in PDF page description.
-The procedure |adv_char_width| advances |pdf_h| by the amount |w|, which is
-the character width. We cannot simply add |w| to |pdf_h|, but must
-calculate the amount corresponding to |w| in the PDF output. For PK fonts
-things are more complicated, as we have to deal with scaling bitmaps as well.
-
- at p 
-procedure adv_char_width(f: internal_font_number; w: scaled); {update |pdf_h|
-by character width |w| from font |f|} 
-begin
-    if hasfmentry(f) then begin
-        call_func(divide_scaled(w, pdf_font_size[f], 3));
-        pdf_h := pdf_h + scaled_out;
-    end
-    else
-        pdf_h := pdf_h + get_pk_char_width(f, w);
-end;
-
-procedure pdf_print_real(m, d: integer); {print $m/10^d$ as real}
-var n: integer;
-begin
-    if m < 0 then begin
-        pdf_out("-");
-        m := -m;
-    end;
-    n := ten_pow[d];
-    pdf_print_int(m div n);
-    m := m mod n;
-    if m > 0 then begin
-        pdf_out(".");
-        n := n div 10;
-        while m < n do begin
-            pdf_out("0");
-            n := n div 10;
-        end;
-        while m mod 10 = 0 do
-            m := m div 10;
-        pdf_print_int(m);
-    end;
-end;
-
-procedure pdf_print_bp(s: scaled); {print scaled as |bp|}
-begin
-    pdf_print_real(divide_scaled(s, one_hundred_bp, fixed_decimal_digits + 2), 
-                   fixed_decimal_digits);
-end;
-
-procedure pdf_print_mag_bp(s: scaled); {take |mag| into account}
-begin
-    prepare_mag;
-    if mag <> 1000 then
-        s := round_xn_over_d(s, mag, 1000);
-    pdf_print_bp(s);
-end;
-
-@* \[32c] PDF page description.
-
- at d pdf_x(#) == ((#) - pdf_origin_h) {convert $x$-coordinate from \.{DVI} to
-PDF}
- at d pdf_y(#) == (pdf_origin_v - (#)) {convert $y$-coordinate from \.{DVI} to
-PDF}
-
-@<Glob...@>=
-@!pdf_f: internal_font_number; {the current font in PDF output page}
-@!pdf_h: scaled; {current horizontal coordinate in PDF output page}
-@!pdf_v: scaled; {current vertical coordinate in PDF output page}
-@!pdf_last_h: scaled; {last horizontal coordinate in PDF output page}
-@!pdf_last_v: scaled; {last vertical coordinate in PDF output page}
-@!pdf_origin_h: scaled; {current horizontal origin in PDF output page}
-@!pdf_origin_v: scaled; {current vertical origin in PDF output page}
-@!pdf_first_space_corr: integer; {amount of first word spacing while drawing a string;
-for some reason it is not taken into account of the length of the string, so we
-have to save it in order to adjust spacing when string drawing is finished}
-@!pdf_doing_string: boolean; {we are writing string to PDF file?}
-@!pdf_doing_text: boolean; {we are writing text section to PDF file?}
-@!pdf_font_changed: boolean; {current font has been changed?}
-@!min_bp_val: scaled; 
-@!fixed_pk_resolution: integer; 
-@!fixed_decimal_digits: integer;
-@!pk_scale_factor: integer;
-@!pdf_output_option: integer;
-@!pdf_output_value: integer;
-
-@ Following procedures implement low-level subroutines to convert \TeX{}
-internal structures to PDF page description.
-
- at p procedure pdf_set_origin; {set the origin to |cur_h|, |cur_v|}
-begin
-    if (abs(cur_h - pdf_origin_h) >= min_bp_val) or
-        (abs(cur_v - pdf_origin_v) >= min_bp_val) then begin
-        pdf_print("1 0 0 1 ");
-        pdf_print_bp(cur_h - pdf_origin_h);
-        pdf_origin_h := pdf_origin_h + scaled_out;
-        pdf_out(" ");
-        pdf_print_bp(pdf_origin_v - cur_v);
-        pdf_origin_v := pdf_origin_v - scaled_out;
-        pdf_print_ln(" cm");
-    end;
-    pdf_h := pdf_origin_h;
-    pdf_last_h := pdf_origin_h;
-    pdf_v := pdf_origin_v;
-    pdf_last_v := pdf_origin_v;
-end;
-
-procedure pdf_end_string; {end the current string}
-begin
-    if pdf_doing_string then begin
-        pdf_print(")]TJ");
-        if pdf_first_space_corr <> 0 then begin
-            pdf_h := pdf_h - pdf_first_space_corr;
-            pdf_first_space_corr := 0;
-        end;
-        pdf_doing_string := false;
-    end;
-end;
-
-procedure pdf_moveto(v, v_out: scaled); {set the next starting point to |cur_h|, |cur_v|}
-begin
-    pdf_out(" ");
-    pdf_print_bp(cur_h - pdf_last_h);
-    pdf_h := pdf_last_h + scaled_out;
-    pdf_out(" ");
-    pdf_print_real(v, fixed_decimal_digits);
-    pdf_print(" Td");
-    pdf_v := pdf_last_v - v_out;
-    pdf_last_h := pdf_h;
-    pdf_last_v := pdf_v;
-end;
-
-procedure pdf_begin_text; forward;
-
-procedure pdf_print_font_tag(f: internal_font_number);
-begin
-    if pdf_font_expand_ratio[f] = 0 then
-        return;
-    if pdf_font_expand_ratio[f] > 0 then
-        pdf_print("+"); {minus sign will be printed by |pdf_print_int|}
-    pdf_print_int(pdf_font_expand_ratio[f]);
-end;
-
-procedure pdf_set_font(f: internal_font_number);
-label found;
-var p: pointer;
-    k: internal_font_number;
-begin
-    if not font_used[f] then
-        pdf_init_font(f);
-    set_ff(f);
-    k := ff;
-    p := pdf_font_list;
-    while p <> null do begin
-        set_ff(info(p));
-        if ff = k then
-            goto found;
-        p := link(p);
-    end;
-    pdf_append_list(f)(pdf_font_list); {|f| not found in |pdf_font_list|}
-found:
-    pdf_begin_text;
-    pdf_print("/F");
-    pdf_print_int(k);
-    pdf_print_font_tag(f);
-    pdf_print_resname_prefix;
-    pdf_out(" ");
-    pdf_print_bp(font_size[f]);
-    pdf_print(" Tf");
-    pdf_f := f;
-    pdf_font_changed := true;
-end;
-
-procedure pdf_begin_text; {begin a text section}
-var temp_cur_h, temp_cur_v: scaled;
-begin
-    if not pdf_doing_text then begin
-        temp_cur_h := cur_h;
-        temp_cur_v := cur_v;
-        cur_h := 0;
-        cur_v := cur_page_height;
-        pdf_set_origin;
-        cur_h := temp_cur_h;
-        cur_v := temp_cur_v;
-        pdf_print_ln("BT");
-        pdf_doing_text := true;
-        pdf_f := null_font;
-        pdf_first_space_corr := 0;
-        pdf_doing_string := false;
-    end;
-end;
-
-procedure pdf_begin_string(f: internal_font_number); {begin to draw a string}
-var b: boolean; {|b| is true only when we must adjust word spacing
-at the beginning of string}
-    s, s_out, v, v_out: scaled;
-begin
-    pdf_begin_text;
-    if f <> pdf_f then begin
-        pdf_end_string;
-        pdf_set_font(f);
-    end;
-    b := false;
-    s := divide_scaled(cur_h - pdf_h, pdf_font_size[f], 3);
-    s_out := scaled_out;
-    if abs(cur_v - pdf_v) >= min_bp_val then begin
-        v := divide_scaled(pdf_last_v - cur_v, one_hundred_bp, 
-                           fixed_decimal_digits + 2);
-        v_out := scaled_out;
-    end
-    else begin
-        v := 0;
-        v_out := 0;
-    end;
-    if pdf_font_changed or (v <> 0) or (abs(s) >= @'100000) then begin
-        pdf_end_string;
-        pdf_moveto(v, v_out);
-        pdf_font_changed := false;
-        s := 0;
-        s_out := 0;
-    end;
-    if pdf_doing_string then begin
-        if s <> 0 then
-            pdf_out(")");
-    end
-    else begin
-        pdf_out("[");
-        if s <> 0 then
-            b := true
-        else
-            pdf_out("(");
-        pdf_doing_string := true;
-    end;
-    if s <> 0 then begin
-        pdf_print_int(-s);
-        if b then
-            pdf_first_space_corr := s_out;
-        pdf_out("(");
-        pdf_h := pdf_h + s_out;
-    end;
-end;
-
-procedure pdf_end_text; {end a text section}
-begin
-    if pdf_doing_text then begin
-        pdf_end_string;
-        pdf_print_nl;
-        pdf_print_ln("ET");
-        pdf_doing_text := false;
-    end;
-end;
-
-procedure pdf_set_rule(x, y, w, h: scaled); {draw a rule}
-begin                                                                           
-    pdf_end_text;
-    pdf_set_origin;
-    if h <= one_bp then begin
-        pdf_print_ln("q"); 
-        pdf_print_ln("[]0 d");                                                    
-        pdf_print_ln("0 J");                                                        
-        pdf_print_bp(h); pdf_print_ln(" w");
-        pdf_print("0 "); pdf_print_bp((h + 1)/2); pdf_print_ln(" m");
-        pdf_print_bp(w); pdf_print(" "); pdf_print_bp((h + 1)/2);
-        pdf_print_ln(" l");
-        pdf_print_ln("S");
-        pdf_print_ln("Q"); 
-    end
-    else if w <= one_bp then begin
-        pdf_print_ln("q"); 
-        pdf_print_ln("[]0 d");                                                    
-        pdf_print_ln("0 J");                                                        
-        pdf_print_bp(w); pdf_print_ln(" w");
-        pdf_print_bp((w + 1)/2); pdf_print_ln(" 0 m");
-        pdf_print_bp((w + 1)/2); pdf_print(" "); pdf_print_bp(h);
-        pdf_print_ln(" l");
-        pdf_print_ln("S");
-        pdf_print_ln("Q"); 
-    end
-    else begin
-        pdf_print_bp(pdf_x(x)); pdf_out(" "); 
-        pdf_print_bp(pdf_y(y)); pdf_out(" "); 
-        pdf_print_bp(w); pdf_out(" "); 
-        pdf_print_bp(h); pdf_print_ln(" re f");
-    end;
-end;
-
-
-procedure pdf_rectangle(left, top, right, bottom: scaled); {output a
-rectangle specification to PDF file}
-begin
-    prepare_mag;
-    pdf_print("/Rect [");
-    pdf_print_mag_bp(pdf_x(left)); pdf_out(" ");
-    pdf_print_mag_bp(pdf_y(bottom)); pdf_out(" ");
-    pdf_print_mag_bp(pdf_x(right)); pdf_out(" ");
-    pdf_print_mag_bp(pdf_y(top));
-    pdf_print_ln("]");
-end;
-
-@* \[32d] The cross-reference table.
-
-The cross-reference table |obj_tab| is an array of |obj_tab_size| of
-|tab_entry|. Each entry contains four integer fields and represents an object
-in PDF file whose object number is the index of this entry in |obj_tab|.
-Objects in |obj_tab| maybe linked into list; objects in such a linked list have
-the same type.
-
-@<Types...@>=
-@!obj_entry = record@;@/
-    int0, int1, int2, int3: integer;
-end;
-
-@ The first field contains information representing identifier of this object.
-It is usally a number for most of object types, but it may be a string number
-for named destination or named thread.
-
-The second field of |obj_entry| contains link to the next
-object in |obj_tab| if this object in linked in a list.
-
-The third field holds the byte offset of the object in the output PDF file.
-Objects that have been not written yet have this field set to zero. However
-sometimes we have to use this field to store some info before the object is
-written out.
-
-The last field usually represents the pointer to some auxiliary data
-structure depending on the object type; however it may be used as a counter as
-well.
-
- at d obj_info(#) == obj_tab[#].int0 {information representing identifier of this object}
- at d obj_link(#) == obj_tab[#].int1 {link to the next entry in linked list}
- at d obj_offset(#) == obj_tab[#].int2 {byte offset of this object in PDF output file}
- at d obj_aux(#) == obj_tab[#].int3 {auxiliary pointer}
- at d is_obj_written(#) == (obj_offset(#) <> 0)
-
-@# {types of objects}
- at d obj_type_others              == 0 {objects which are not linked in any list}
- at d obj_type_page                == 1 {index of linked list of Page objects}
- at d obj_type_pages               == 2 {index of linked list of Pages objects}
- at d obj_type_font                == 3 {index of linked list of Fonts objects}
- at d obj_type_outline             == 4 {index of linked list of outline objects}
- at d obj_type_dest                == 5 {index of linked list of destination objects}
- at d obj_type_obj                 == 6 {index of linked list of raw objects}
- at d obj_type_xform               == 7 {index of linked list of XObject forms}
- at d obj_type_ximage              == 8 {index of linked list of XObject image}
- at d obj_type_thread              == 9 {index of linked list of num article threads}
- at d head_tab_max                 == obj_type_thread {max index of |head_tab|}
-
-@# {max number of kids for balanced trees}
- at d pages_tree_kids_max     == 6 {max number of kids of Pages tree node}
- at d name_tree_kids_max      == @'100000 {max number of kids of node of name tree for
-name destinations}
-
-@# {when a whatsit node representing annotation is created, words |1..3| are
-width, height and depth of this annotation; after shipping out words |1..4|
-are rectangle specification of annotation. For whatsit node representing
-destination |pdf_left| and |pdf_top| are used for some types of destinations}
-
-@# {coordinates of destinations/threads/annotations (in whatsit node)}
- at d pdf_left(#)             == mem[# + 1].sc
- at d pdf_top(#)              == mem[# + 2].sc
- at d pdf_right(#)            == mem[# + 3].sc
- at d pdf_bottom(#)           == mem[# + 4].sc
-
-@# {dimesion of destinations/threads/annotations (in whatsit node)}
- at d pdf_width(#)            == mem[# + 1].sc
- at d pdf_height(#)           == mem[# + 2].sc
- at d pdf_depth(#)            == mem[# + 3].sc
-
-@# {data struture for \.{\\pdfliteral}}
- at d pdf_literal_data(#)     == link(#+1) {data}
- at d pdf_literal_direct(#)   == info(#+1) {write data directly to the page
-                              contents without resetting text matrix}
-
-@# {data struture for \.{\\pdfobj} and \.{\\pdfrefobj}}
- at d pdf_refobj_node_size    == 2 {size of whatsit node representing the raw object}
- at d pdf_obj_objnum(#)       == info(# + 1) {number of the raw object}
- at d obj_data_ptr            == obj_aux {pointer to |pdf_mem|}
- at d pdfmem_obj_size         == 4 {size of memory in |pdf_mem| which
-                              |obj_data_ptr| holds}
- at d obj_obj_data(#)         == pdf_mem[obj_data_ptr(#) + 0] {object data}
- at d obj_obj_is_stream(#)    == pdf_mem[obj_data_ptr(#) + 1] {will this object
-                              be written as a stream instead of a dictionary?}
- at d obj_obj_stream_attr(#)  == pdf_mem[obj_data_ptr(#) + 2] {additional
-                              object attributes for streams}
- at d obj_obj_is_file(#)      == pdf_mem[obj_data_ptr(#) + 3] {data should be 
-                              read from an external file?}
-
-@# {data struture for \.{\\pdfxform} and \.{\\pdfrefxform}}
- at d pdf_refxform_node_size  == 5 {size of whatsit node for xform; words 1..3 are
-                              form dimensions}
- at d pdf_xform_objnum(#)     == info(# + 4) {object number}
- at d pdfmem_xform_size       == 6 {size of memory in |pdf_mem| which
-                              |obj_data_ptr| holds}
- at d obj_xform_width(#)      == pdf_mem[obj_data_ptr(#) + 0]
- at d obj_xform_height(#)     == pdf_mem[obj_data_ptr(#) + 1]
- at d obj_xform_depth(#)      == pdf_mem[obj_data_ptr(#) + 2]
- at d obj_xform_box(#)        == pdf_mem[obj_data_ptr(#) + 3] {this field holds
-                              pointer to the corresponding box}
- at d obj_xform_attr(#)       == pdf_mem[obj_data_ptr(#) + 4] {additional xform
-                              attributes}
- at d obj_xform_resources(#)  == pdf_mem[obj_data_ptr(#) + 5] {additional xform
-                              Resources}
-
-@# {data struture for \.{\\pdfximage} and \.{\\pdfrefximage}}
- at d pdf_refximage_node_size == 5 {size of whatsit node for ximage; words 1..3
-                               are image dimensions}
- at d pdf_ximage_objnum(#)    == info(# + 4) {object number}
- at d pdfmem_ximage_size      == 5 {size of memory in |pdf_mem| which
-                              |obj_data_ptr| holds}
- at d obj_ximage_width(#)     == pdf_mem[obj_data_ptr(#) + 0]
- at d obj_ximage_height(#)    == pdf_mem[obj_data_ptr(#) + 1]
- at d obj_ximage_depth(#)     == pdf_mem[obj_data_ptr(#) + 2]
- at d obj_ximage_attr(#)      == pdf_mem[obj_data_ptr(#) + 3] {additional ximage attributes}
- at d obj_ximage_data(#)      == pdf_mem[obj_data_ptr(#) + 4] {pointer to image data}
-
-@# {data struture of annotations; words 1..4 represent the coordinates of
-    the annotation}
- at d obj_annot_ptr           == obj_aux {pointer to corresponding whatsit node}
- at d pdf_annot_node_size     == 7 {size of whatsit node representing annotation}
- at d pdf_annot_data(#)       == info(# + 5) {raw data of general annotations}
- at d pdf_link_attr(#)        == info(# + 5) {attributes of link annotations}
- at d pdf_link_action(#)      == link(# + 5) {pointer to action structure}
- at d pdf_annot_objnum(#)     == mem[# + 6].int {object number of corresponding object}
-
-@# {types of actions}
- at d pdf_action_page         == 0 {Goto action}
- at d pdf_action_goto         == 1 {Goto action}
- at d pdf_action_thread       == 2 {Thread action}
- at d pdf_action_user         == 3 {user-defined action}
-
-@# {data structure of actions}
- at d pdf_action_size         == 3 {size of action structure in |mem|}
- at d pdf_action_type         == type {action type}
- at d pdf_action_named_id     == subtype {identifier is type of name}
- at d pdf_action_id           == link {destination/thread name identifier}
- at d pdf_action_file(#)      == info(# + 1) {file name for external action}
- at d pdf_action_new_window(#)== link(# + 1) {open a new window?}
- at d pdf_action_page_tokens(#) == info(# + 2) {specification of goto page action}
- at d pdf_action_user_tokens(#) == info(# + 2) {user-defined action string}
- at d pdf_action_refcount(#)  == link(# + 2) {counter of references to this action}
-
-@# {data structure of outlines; it's not able to write out outline entries
-before all outline entries are defined, so memory allocated for outline
-entries can't not be deallocated and will stay in memory. For this reason we
-will store data of outline entries in |pdf_mem| instead of |mem|}
-
- at d pdfmem_outline_size     == 8 {size of memory in |pdf_mem| which
-|obj_outline_ptr| points to}
- at d obj_outline_count        == obj_info{count of all opened children}
- at d obj_outline_ptr          == obj_aux {pointer to |pdf_mem|}
- at d obj_outline_title(#)     == pdf_mem[obj_outline_ptr(#)]
- at d obj_outline_parent(#)    == pdf_mem[obj_outline_ptr(#) + 1]
- at d obj_outline_prev(#)      == pdf_mem[obj_outline_ptr(#) + 2]
- at d obj_outline_next(#)      == pdf_mem[obj_outline_ptr(#) + 3]
- at d obj_outline_first(#)     == pdf_mem[obj_outline_ptr(#) + 4]
- at d obj_outline_last(#)      == pdf_mem[obj_outline_ptr(#) + 5]
- at d obj_outline_action_objnum(#) == pdf_mem[obj_outline_ptr(#) + 6] {object number of
-action}
- at d obj_outline_attr(#)      == pdf_mem[obj_outline_ptr(#) + 7]
-
-@# {types of destinations}
- at d pdf_dest_xyz             == 0
- at d pdf_dest_fit             == 1
- at d pdf_dest_fith            == 2
- at d pdf_dest_fitv            == 3
- at d pdf_dest_fitb            == 4
- at d pdf_dest_fitbh           == 5
- at d pdf_dest_fitbv           == 6
- at d pdf_dest_fitr            == 7
-
-@# {data structure of destinations}
- at d obj_dest_ptr             == obj_aux {pointer to |pdf_dest_node|}
- at d pdf_dest_node_size       == 7 {size of whatsit node for destination;
-words |1..4| hold dest dimensions, word |6| identifier type, subtype
-and identifier of destination, word |6| the corresponding object number}
- at d pdf_dest_type(#)          == type(# + 5) {type of destination}
- at d pdf_dest_named_id(#)      == subtype(# + 5) {is named identifier?}
- at d pdf_dest_id(#)            == link(# + 5) {destination identifier}
- at d pdf_dest_xyz_zoom(#)      == info(# + 6) {zoom factor for |destxyz| destination}
- at d pdf_dest_objnum(#)        == link(# + 6) {object number of corresponding
-object}
-
-@# {data structure of threads; words 1..4 represent the coordinates of the
-    corners}
- at d pdf_thread_node_size      == 7
- at d pdf_thread_named_id(#)    == subtype(# + 5) {is a named identifier}
- at d pdf_thread_id(#)          == link(# + 5) {thread identifier}
- at d pdf_thread_attr(#)        == info(# + 6) {attributes of thread}
- at d obj_thread_first          == obj_aux {pointer to the first bead}
-
-@# {data structure of beads}
- at d pdfmem_bead_size         == 5 {size of memory in |pdf_mem| which 
-                                  |obj_bead_ptr| points to}
- at d obj_bead_ptr             == obj_aux {pointer to |pdf_mem|}
- at d obj_bead_rect(#)         == pdf_mem[obj_bead_ptr(#)]
- at d obj_bead_page(#)         == pdf_mem[obj_bead_ptr(#) + 1]
- at d obj_bead_next(#)         == pdf_mem[obj_bead_ptr(#) + 2]
- at d obj_bead_prev(#)         == pdf_mem[obj_bead_ptr(#) + 3]
- at d obj_bead_attr(#)         == pdf_mem[obj_bead_ptr(#) + 4]
- at d obj_bead_data            == obj_bead_rect {pointer to the corresponding
-whatsit node; |obj_bead_rect| is needed only when the bead rectangle has
-been written out and after that |obj_bead_data| is not needed any more
-so we can use this field for both}
-
-@<Constants...@>=
-@!inf_obj_tab_size = 32000; {min size of the cross-reference table for PDF output}
-@!sup_obj_tab_size = 8388607; {max size of the cross-reference table for PDF output}
-@!inf_dest_names_size = 10000; {min size of the destination names table for PDF output}
-@!sup_dest_names_size = 131072; {max size of the destination names table for PDF output}
-@!pdf_objtype_max = head_tab_max;
-@!pdf_pdf_box_spec_media  = 0;
-@!pdf_pdf_box_spec_crop   = 1;
-@!pdf_pdf_box_spec_bleed  = 2;
-@!pdf_pdf_box_spec_trim   = 3;
-@!pdf_pdf_box_spec_art    = 4;
-
-@ @<Glob...@>=
-@!obj_tab_size:integer;
-@!obj_tab:^obj_entry;
-@!head_tab: array[1..head_tab_max] of integer;
-@!obj_ptr: integer; {objects counter}
-@!pdf_last_pages: integer; {pointer to most recently generated pages object}
-@!pdf_last_page: integer; {pointer to most recently generated page object}
-@!pdf_last_stream: integer; {pointer to most recently generated stream}
-@!pdf_stream_length: integer; {length of most recently generated stream}
-@!pdf_stream_length_offset: integer; {file offset of the last stream length}
-@!pdf_append_list_arg: integer; {for use with |pdf_append_list|}
-@!ff: integer; {for use with |set_ff|}
-
-@ @<Set init...@>=
-obj_ptr := 0;
-for k := 1 to head_tab_max do
-    head_tab[k] := 0;
-
-@ Here we implement subroutines for work with objects and related things.
-Some of them are used in former parts too, so we need to declare them
-forward.
-
- at d pdf_append_list_end(#) == # := append_ptr(#, pdf_append_list_arg); end
- at d pdf_append_list(#) == begin pdf_append_list_arg := #; pdf_append_list_end
- at d set_ff(#) == begin 
-    if pdf_font_num[#] < 0 then
-        ff := -pdf_font_num[#]
-    else 
-        ff := #;
-end
-
-@<Declare procedures that need to be declared forward for pdftex@>=
-procedure append_dest_name(s: str_number; n: integer);
-begin
-    if pdf_dest_names_ptr = dest_names_size then
-        overflow("number of destination names", dest_names_size);
-    dest_names[pdf_dest_names_ptr].objname := s;
-    dest_names[pdf_dest_names_ptr].objnum := n;
-    incr(pdf_dest_names_ptr);
-end;
-
-procedure pdf_create_obj(t, i: integer); {create an object with type |t| and
-identifier |i|}
-label done;
-var p, q: integer;
-begin
-    if obj_ptr = obj_tab_size then
-        overflow("indirect objects table size", obj_tab_size);
-    incr(obj_ptr);
-    obj_info(obj_ptr) := i;
-    obj_offset(obj_ptr) := 0;
-    obj_aux(obj_ptr) := 0;
-    avl_put_obj(obj_ptr, t);
-    if t = obj_type_page then begin
-        p := head_tab[t];
-        {find the right position to insert newly created object}@/
-        if (p = 0) or (obj_info(p) < i) then begin
-            obj_link(obj_ptr) := p;
-            head_tab[t] := obj_ptr;
-        end
-        else begin
-            while p <> 0 do begin
-                if obj_info(p) < i then
-                    goto done;
-                q := p;
-                p := obj_link(p);
-            end;
-done:
-            obj_link(q) := obj_ptr;
-            obj_link(obj_ptr) := p;
-        end;
-    end
-    else if t <> obj_type_others then begin
-        obj_link(obj_ptr) := head_tab[t];
-        head_tab[t] := obj_ptr;
-        if (t = obj_type_dest) and (i < 0) then
-            append_dest_name(-obj_info(obj_ptr), obj_ptr);
-    end;
-end;
-
-function pdf_new_objnum: integer; {create a new object and return its number}
-begin
-    pdf_create_obj(obj_type_others, 0);
-    pdf_new_objnum := obj_ptr;
-end;
-
-procedure pdf_begin_obj(i: integer); {begin a PDF object}
-begin
-    ensure_pdf_open;
-    check_and_set_pdfoptionpdfminorversion;
-    obj_offset(i) := pdf_offset;
-    pdf_print_int(i);
-    pdf_print_ln(" 0 obj");
-end;
-
-procedure pdf_end_obj;
-begin
-    pdf_print_ln("endobj"); {end a PDF object}
-end;
-
-procedure pdf_begin_dict(i: integer); {begin a PDF dictionary object}
-begin
-    obj_offset(i) := pdf_offset;
-    pdf_print_int(i);
-    pdf_print_ln(" 0 obj <<");
-end;
-
-procedure pdf_end_dict; {end a PDF object of type dictionary}
-begin
-    pdf_print_ln(">> endobj");
-end;
-
-procedure pdf_new_obj(t, i: integer); {begin to a new object}
-begin
-    pdf_create_obj(t, i);
-    pdf_begin_obj(obj_ptr);
-end;
-
-procedure pdf_new_dict(t, i: integer); {begin a new object with type dictionary}
-begin
-    pdf_create_obj(t, i);
-    pdf_begin_dict(obj_ptr);
-end;
-
-function append_ptr(p: pointer; i: integer): pointer; {appends a pointer with
-info |i| to the end of linked list with head |p|}
-var q: pointer;
-begin
-    append_ptr := p;
-    fast_get_avail(q);
-    info(q) := i;
-    link(q) := null;
-    if p = null then begin
-        append_ptr := q;
-        return;
-    end;
-    while link(p) <> null do
-        p := link(p);
-    link(p) := q;
-end;
-
-function pdf_lookup_list(p: pointer; i: integer): pointer; {looks up for pointer
-with info |i| in list |p|}
-begin
-    pdf_lookup_list := null;
-    while p <> null do begin
-        if info(p) = i then begin
-            pdf_lookup_list := p;
-            return;
-        end;
-        p := link(p);
-    end;
-end;
-
-@ @<Glob...@>=
-@!pdf_image_procset: integer; {collection of image types used in current page/form}
-@!pdf_text_procset: boolean; {mask of used ProcSet's in the current page/form}
-
-@ Subroutines to print out various PDF objects
-
- at d is_hex_char(#) == (((# >= '0') and (# <= '9')) or
-                      ((# >= 'A') and (# <= 'F')) or
-                      ((# >= 'a') and (# <= 'f')))
-
- at p procedure pdf_print_fw_int(n, w: integer); {print out an integer with 
-fixed width; used for outputting cross-reference table}
-var k:0..23;
-begin
-  k:=0;
-  repeat dig[k]:=n mod 10; n:=n div 10; incr(k);
-  until k = w;
-  pdf_room(k);
-  while k>0 do begin
-    decr(k);
-    pdf_quick_out("0"+dig[k]);
-  end;
-end;
-
-procedure pdf_int_entry(s: str_number; v: integer); {print out an entry in
-dictionary with integer value to PDF buffer}
-begin
-    pdf_out("/");
-    pdf_print(s);
-    pdf_out(" ");
-    pdf_print_int(v);
-end;
-
-procedure pdf_int_entry_ln(s: str_number; v: integer);
-begin
-    pdf_int_entry(s, v);
-    pdf_print_nl;
-end;
-
-procedure pdf_indirect(s: str_number; o: integer); {print out an indirect
-entry in dictionary}
-begin
-    pdf_out("/");
-    pdf_print(s);
-    pdf_out(" ");
-    pdf_print_int(o);
-    pdf_print(" 0 R");
-end;
-
-procedure pdf_indirect_ln(s: str_number; o: integer);
-begin
-    pdf_indirect(s, o);
-    pdf_print_nl;
-end;
-
-procedure pdf_print_str(s: str_number); {print out |s| as string in PDF
-output}
-label done;
-var i, j, k: pool_pointer;
-    is_hex_string: boolean;
-begin
-    i := str_start[s];
-    j := i + length(s) - 1;
-    if (i > j) then
-        return; {null string}
-    if (str_pool[i] = '(') and (str_pool[j] = ')') then begin
-        pdf_print(s);
-        return;
-    end;
-    is_hex_string := false;
-    if (str_pool[i] <> '<') or (str_pool[j] <> '>') or odd(length(s)) then 
-        goto done;
-    incr(i);
-    decr(j);
-    while i < j do begin
-        if is_hex_char(str_pool[i]) and is_hex_char(str_pool[i + 1]) then
-            i := i + 2
-        else
-            goto done;
-    end;
-    is_hex_string := true;
-done:
-    if is_hex_string then
-        pdf_print(s)
-    else begin
-        pdf_out("(");
-        pdf_print(s);
-        pdf_out(")");
-    end;
-end;
-
-procedure pdf_print_str_ln(s: str_number); {print out |s| as string in PDF
-output}
-begin
-    pdf_print_str(s);
-    pdf_print_nl;
-end;
-
-procedure pdf_str_entry(s, v: str_number); {print out an entry in
-dictionary with string value to PDF buffer}
-begin
-    if v = 0 then
-        return;
-    pdf_out("/");
-    pdf_print(s);
-    pdf_out(" ");
-    pdf_print_str(v);
-end;
-
-procedure pdf_str_entry_ln(s, v: str_number);
-begin
-    if v = 0 then
-        return;
-    pdf_str_entry(s, v);
-    pdf_print_nl;
-end;
-
-@* \[32e] Font processing.
-
-As pdfTeX should also act as a back-end driver, it needs to support virtual
-font too. Information about virtual font can be found in source of some
-\.{DVI}-related programs.
-
-Whenever we want to write out a character in a font to PDF output, we
-should check whether the used font is new font (has not been used yet),
-virtual font or real font. The array |pdf_font_type| holds flag of each used
-font. After initialization flag of each font is set to |new_font_type|.
-The first time when a character of a font is written out, pdfTeX looks for
-the corresponding virtual font. If the corresponding virtual font exists, then
-the font type is set to |virtual_font_type|; otherwise it will be set to
-|real_font_type|. |subst_font_type| indicates fonts that have been substituted
-during adjusting spacing. Such fonts are linked via the |pdf_font_elink| array.
-
- at d new_font_type = 0 {new font (has not been used yet)}
- at d virtual_font_type = 1 {virtual font}
- at d real_font_type = 2 {real font}
- at d subst_font_type = 3 {substituted font}
- at d pdf_init_font(#) == begin tmp_f := #; pdf_create_font_obj; end
- at d pdf_check_vf(#) == begin 
-    tmp_f := #; 
-    do_vf; 
-    if pdf_font_type[#] = virtual_font_type then
-        pdf_error("font", "command cannot be used with virtual font");
-end
-
- at d pdf_check_new_font(#) == 
-    if pdf_font_type[#] = new_font_type then begin
-        tmp_f := #;
-        do_vf;
-    end
-
-@<Declare procedures that need to be declared forward...@>=
-procedure pdf_create_font_obj; forward;
-procedure do_vf; forward;
-procedure scan_pdf_ext_toks; forward;
-
-@ @<Glob...@>=
-@!pdf_font_type: ^eight_bits; {the type of font}
-@!pdf_font_attr: ^str_number; {pointer to additional attributes}
-@!tmp_f: internal_font_number; {for use with |pdf_init_font|}
-
-@ To set PDF font we need to find out fonts with the same name, because \TeX\
-can load the same font several times for various sizes. For such fonts we
-define only one font resource. The array |pdf_font_num| holds the object
-number of font resource. A negative value of an entry of |pdf_font_num|
-indicates that the corresponding font shares the font resource with the font
-whose internal number is the absolute value of the entry. For partial
-downloading we also need to hold flags indicating which characters in particular
-font are used in array |pdf_char_used|.
-
- at d pdf_print_resname_prefix == 
-if pdf_resname_prefix <> 0 then
-    pdf_print(pdf_resname_prefix)
-
- at p procedure pdf_use_font(f: internal_font_number; fontnum: integer);
-begin
-    call_func(divide_scaled(font_size[f], one_hundred_bp, 
-                            fixed_decimal_digits + 2));
-    pdf_font_size[f] := scaled_out;
-    font_used[f] := true;
-    pdf_font_num[f] := fontnum;
-    set_char_map(f);
-end;
-
-procedure pdf_create_font_obj; 
-var f, k: internal_font_number;
-begin
-    f := tmp_f;
-    if not font_used[f] then begin
-        if hasfmentry(f) then begin
-        {this font is scaleable, so different sizes can share a single font object}
-            k := tfm_of_fm(pdf_font_map[f]);
-            if (k <> f) and str_eq_str(font_name[k], font_name[f]) then begin
-                pdf_use_font(f, -k);
-                return;
-            end;
-        end;
-        pdf_create_obj(obj_type_font, f);
-        pdf_use_font(f, obj_ptr);
-    end;
-end;
-
-@ We need to hold information about used characters in each font for partial
-downloading.
-
-@<Types...@>=
-char_used_array = array[0..31] of eight_bits; 
-char_map_array = array[0..32] of eight_bits; {move chars in range 0..32}
-fm_entry_ptr = ^integer;
-
-@ @<Glob...@>=
-@!pdf_char_used: ^char_used_array; {to mark used chars}
-@!pdf_char_map: ^char_map_array; {where to map chars 0..32}
-@!pdf_font_size: ^scaled; {used size of font in PDF file}
-@!pdf_font_num: ^integer; {mapping between internal font number in \TeX\ and
-    font name defined in resources in PDF file}
-@!pdf_font_map: ^fm_entry_ptr; {pointer into AVL tree of font mappings}
-@!pdf_font_list: pointer; {list of used fonts in current page}
-@!pdf_resname_prefix: str_number; {global prefix of resources name}
-@!last_tokens_string: str_number; {the number of the most recently string
-created by |tokens_to_string|}
-
-@ @<Set init...@>=
-pdf_resname_prefix := 0;
-last_tokens_string := 0;
-
-
-@ Here we implement reading information from \.{VF} file.
-
- at d vf_max_packet_length = 10000 {max length of character packet in \.{VF} file}
-
-@#
- at d vf_error = 61 {label to go to when an error occur}
- at d do_char = 70 {label to go to typesetting a character of virtual font}
-@#
- at d long_char = 242 {\.{VF} command for general character packet}
- at d vf_id = 202 {identifies \.{VF} files}
- at d put1=133 {typeset a character}
-
-@#
- at d vf_byte == getc(vf_file) {get a byte from\.{VF} file}
- at d vf_packet(#) == vf_packet_start[vf_packet_base[#] + vf_packet_end
- at d vf_packet_end(#) == #]
-
-@#
- at d bad_vf(#) == begin vf_err_str := #; goto vf_error; end {go out \.{VF}
-processing with an error message}
- at d four_cases(#) == #,#+1,#+2,#+3
-
-@#
- at d tmp_b0 == tmp_w.qqqq.b0
- at d tmp_b1 == tmp_w.qqqq.b1
- at d tmp_b2 == tmp_w.qqqq.b2
- at d tmp_b3 == tmp_w.qqqq.b3
- at d tmp_int == tmp_w.int
-
-@#
- at d scaled3u == {convert |tmp_b1..tmp_b3| to an unsigned scaled dimension}
-(((((tmp_b3*vf_z)div@'400)+(tmp_b2*vf_z))div@'400)+(tmp_b1*vf_z))div vf_beta
- at d scaled4(#) == {convert |tmp_b0..tmp_b3| to a scaled dimension}
-  #:=scaled3u;
-  if tmp_b0>0 then if tmp_b0=255 then # := # - vf_alpha
- at d scaled3(#) == {convert |tmp_b1..tmp_b3| to a scaled dimension}
-  #:=scaled3u; @+ if tmp_b1>127 then # := # - vf_alpha
- at d scaled2 == {convert |tmp_b2..tmp_b3| to a scaled dimension}
-  if tmp_b2>127 then tmp_b1:=255 else tmp_b1:=0;
-  scaled3
- at d scaled1 == {convert |tmp_b3| to a scaled dimension}
-  if tmp_b3>127 then tmp_b1:=255 else tmp_b1:=0;
-  tmp_b2:=tmp_b1; scaled3
-
-@<Glob...@>=
-@!vf_packet_base: ^integer; {base addresses of character packets from virtual fonts}
-@!vf_default_font: ^internal_font_number; {default font in a \.{VF} file}
-@!vf_local_font_num: ^internal_font_number; {number of local fonts in a \.{VF} file}
-@!vf_packet_length: integer; {length of the current packet}
-@!vf_file: byte_file;
-@!vf_nf: internal_font_number; {the local fonts counter}
-@!vf_e_fnts: ^integer; {external font numbers}
-@!vf_i_fnts: ^internal_font_number; {corresponding internal font numbers}
-@!tmp_w: memory_word; {accumulator}
-@!vf_z: integer; {multiplier}
-@!vf_alpha: integer; {correction for negative values}
-@!vf_beta: 1..16; {divisor}
-
-@ @<Set init...@>=
-vf_nf := 0;
-
-@ The |do_vf| procedure attempts to read the \.{VF} file for a font, and sets
-|pdf_font_type| to |real_font_type| if the \.{VF} file could not be found
-or loaded, otherwise sets |pdf_font_type| to |virtual_font_type|.  At this
-time, |tmp_f| is the internal font number of the current \.{TFM} font.  To
-process font definitions in virtual font we call |vf_def_font|.
-
- at p procedure vf_replace_z;
-begin
-    vf_alpha:=16;
-    while vf_z>=@'40000000 do begin
-        vf_z:=vf_z div 2;
-        vf_alpha:=vf_alpha+vf_alpha;
-    end;
-    vf_beta:=256 div vf_alpha;
-    vf_alpha:=vf_alpha*vf_z;
-end;
-
-function vf_read(k: integer): integer; {read |k| bytes as an integer from \.{VF} file}
-var i: integer;
-begin
-    i := 0;
-    while k > 0 do begin
-        i := i*256 + vf_byte;
-        decr(k);
-    end;
-    vf_read := i;
-end;
-
-procedure vf_local_font_warning(f, k: internal_font_number; s: str_number);
-{print a warning message if an error ocurrs during processing local fonts in
-\.{VF} file}
-begin
-    print_nl(s);
-    print(" in local font ");
-    print(font_name[k]);
-    print(" in virtual font ");
-    print(font_name[f]);
-    print(".vf ignored.");
-end;
-
-function vf_def_font(f: internal_font_number): internal_font_number; 
-{process a local font in \.{VF} file}
-var k: internal_font_number;
-    s: str_number;
-    ds, fs: scaled;
-    cs: four_quarters;
-    c: integer;
-begin
-    cs.b0 := vf_byte; cs.b1 := vf_byte; cs.b2 := vf_byte; cs.b3 := vf_byte;
-    tmp_b0 := vf_byte; tmp_b1 := vf_byte; tmp_b2 := vf_byte; tmp_b3 := vf_byte;
-    scaled4(fs);
-    ds := vf_read(4) div @'20;
-    tmp_b0 := vf_byte;
-    tmp_b1 := vf_byte;
-    while tmp_b0 > 0 do begin
-        decr(tmp_b0);
-        if vf_byte > 0 then
-            do_nothing; {skip the font path}
-    end;
-    str_room(tmp_b1);
-    while tmp_b1 > 0 do begin
-        decr(tmp_b1);
-        append_char(vf_byte);
-    end;
-    s := make_string;
-    k := tfm_lookup(s, fs);
-    if k = null_font then
-        k := read_font_info(null_cs, s, "", fs);
-    if k <> null_font then begin
-        if ((cs.b0 <> 0) or (cs.b1 <> 0) or (cs.b2 <> 0) or (cs.b3 <> 0)) and
-           ((font_check[k].b0 <> 0) or (font_check[k].b1 <> 0) or
-            (font_check[k].b2 <> 0) or (font_check[k].b3 <> 0)) and
-           ((cs.b0 <> font_check[k].b0) or (cs.b1 <> font_check[k].b1) or
-            (cs.b2 <> font_check[k].b2) or (cs.b3 <> font_check[k].b3)) then
-            vf_local_font_warning(f, k, "checksum mismatch");
-        if ds <> font_dsize[k] then
-            vf_local_font_warning(f, k, "design size mismatch");
-    end;
-    if pdf_font_expand_ratio[f] <> 0 then
-        set_expand_param(k, f, pdf_font_expand_ratio[f]);
-    vf_def_font := k;
-end;
-
-procedure do_vf; {process \.{VF} file with font internal number |f|}
-label vf_error;
-var cmd, k, n: integer;
-    cc, cmd_length: integer;
-    tfm_width: scaled;
-    vf_err_str, s: str_number;
-    stack_level: vf_stack_index;
-    save_vf_nf: internal_font_number;
-    f: internal_font_number;
-
-begin
-    f := tmp_f;
-    pdf_font_type[f] := real_font_type;
-    if auto_expand_vf(f) then
-        return; {auto-expanded virtual font}
-    stack_level := 0;
-    @<Open |vf_file|, return if not found@>;
-    @<Process the preamble@>;@/
-    @<Process the font definitions@>;@/
-    @<Allocate memory for the new virtual font@>;@/
-    while cmd <= long_char do begin@/
-        @<Build a character packet@>;@/
-    end;
-    if cmd <> post then
-        bad_vf("POST command expected");
-    b_close(vf_file);
-    pdf_font_type[f] := virtual_font_type;
-    return;
-vf_error:
-    print_nl("Error in processing VF font (");
-    print(font_name[f]);
-    print(".vf): ");
-    print(vf_err_str);
-    print(", virtual font will be ignored");
-    print_ln;
-    b_close(vf_file);
-    update_terminal;
-end;
-
-@ @<Open |vf_file|, return if not found@>=
-pack_file_name(font_name[f], "", ".vf");
-if not vf_b_open_in(vf_file) then
-    return
-
-@ @<Process the preamble@>=
-if vf_byte <> pre then
-    bad_vf("PRE command expected");
-if vf_byte <> vf_id then
-    bad_vf("wrong id byte");
-cmd_length := vf_byte;
-for k := 1 to cmd_length do
-    tmp_int := vf_byte;
-tmp_b0 := vf_byte; tmp_b1 := vf_byte; tmp_b2 := vf_byte; tmp_b3 := vf_byte;
-if ((tmp_b0 <> 0) or (tmp_b1 <> 0) or (tmp_b2 <> 0) or (tmp_b3 <> 0)) and
-   ((font_check[f].b0 <> 0) or (font_check[f].b1 <> 0) or
-    (font_check[f].b2 <> 0) or (font_check[f].b3 <> 0)) and
-   ((tmp_b0 <> font_check[f].b0) or (tmp_b1 <> font_check[f].b1) or
-    (tmp_b2 <> font_check[f].b2) or (tmp_b3 <> font_check[f].b3)) then begin
-    print_nl("checksum mismatch in font ");
-    print(font_name[f]);
-    print(".vf ignored");
-end;
-if vf_read(4) div @'20 <> font_dsize[f] then begin
-    print_nl("design size mismatch in font ");
-    print(font_name[f]);
-    print(".vf ignored");
-end;
-update_terminal;
-vf_z := font_size[f];
-vf_replace_z
-
-@ @<Process the font definitions@>=
-cmd := vf_byte;
-save_vf_nf := vf_nf;
-while (cmd >= fnt_def1) and (cmd <= fnt_def1 + 3) do begin
-    vf_e_fnts[vf_nf] := vf_read(cmd - fnt_def1 + 1);
-    vf_i_fnts[vf_nf] := vf_def_font(f);
-    incr(vf_nf);
-    cmd := vf_byte;
-end;
-vf_default_font[f] := save_vf_nf;
-vf_local_font_num[f] := vf_nf - save_vf_nf;
-
-@ @<Allocate memory for the new virtual font@>=
-    vf_packet_base[f] := new_vf_packet(f)
-
-@ @<Build a character packet@>=
-if cmd = long_char then begin
-    vf_packet_length := vf_read(4);
-    cc := vf_read(4);
-    if not is_valid_char(cc) then
-        bad_vf("invalid character code");
-    tmp_b0 := vf_byte; tmp_b1 := vf_byte; tmp_b2 := vf_byte; tmp_b3 := vf_byte;
-    scaled4(tfm_width);
-end
-else begin
-    vf_packet_length := cmd;
-    cc := vf_byte;
-    if not is_valid_char(cc) then
-        bad_vf("invalid character code");
-    tmp_b1 := vf_byte; tmp_b2 := vf_byte; tmp_b3 := vf_byte;
-    scaled3(tfm_width);
-end;
-if vf_packet_length < 0 then
-    bad_vf("negative packet length");
-if vf_packet_length > vf_max_packet_length then
-    bad_vf("packet length too long");
-if (tfm_width <> char_width(f)(char_info(f)(cc))) then begin
-    print_nl("character width mismatch in font ");
-    print(font_name[f]);
-    print(".vf ignored");
-end;
-str_room(vf_packet_length);
-while vf_packet_length > 0 do begin
-    cmd := vf_byte;
-    decr(vf_packet_length);
-    @<Cases of \.{DVI} commands that can appear in character packet@>;
-    if cmd <> nop then
-        append_char(cmd);
-    vf_packet_length := vf_packet_length - cmd_length;
-    while cmd_length > 0 do begin
-        decr(cmd_length);
-        append_char(vf_byte);
-    end;
-end;
-if stack_level <> 0 then
-    bad_vf("more PUSHs than POPs in character packet");
-if vf_packet_length <> 0 then
-    bad_vf("invalid packet length or DVI command in packet");
-@<Store the packet being built@>;
-cmd := vf_byte
-
-@ @<Store the packet being built@>=
-s := make_string;
-storepacket(f, cc, s);
-flush_str(s)
-
-@ @<Cases of \.{DVI} commands that can appear in character packet@>=
-if (cmd >= set_char_0) and (cmd <= set_char_0 + 127) then
-    cmd_length := 0
-else if ((fnt_num_0 <= cmd) and (cmd <= fnt_num_0 + 63)) or
-        ((fnt1 <= cmd) and (cmd <= fnt1 + 3)) then begin
-    if cmd >= fnt1 then begin
-        k := vf_read(cmd - fnt1 + 1);
-        vf_packet_length := vf_packet_length - (cmd - fnt1 + 1);
-    end
-    else
-        k := cmd - fnt_num_0;
-    if k >= 256 then
-        bad_vf("too many local fonts");
-    n := 0;
-    while (n < vf_local_font_num[f]) and
-          (vf_e_fnts[vf_default_font[f] + n] <> k) do
-        incr(n);
-    if n = vf_local_font_num[f] then
-        bad_vf("undefined local font");
-    if k <= 63 then
-        append_char(fnt_num_0 + k)
-    else begin
-        append_char(fnt1);
-        append_char(k);
-    end;
-    cmd_length := 0;
-    cmd := nop;
-end
-else case cmd of
-set_rule, put_rule: cmd_length := 8;
-four_cases(set1):   cmd_length := cmd - set1 + 1;
-four_cases(put1):   cmd_length := cmd - put1 + 1;
-four_cases(right1): cmd_length := cmd - right1 + 1;
-four_cases(w1):     cmd_length := cmd - w1 + 1;
-four_cases(x1):     cmd_length := cmd - x1 + 1;
-four_cases(down1):  cmd_length := cmd - down1 + 1;
-four_cases(y1):     cmd_length := cmd - y1 + 1;
-four_cases(z1):     cmd_length := cmd - z1 + 1;
-four_cases(xxx1):  begin
-    cmd_length := vf_read(cmd - xxx1 + 1);
-    vf_packet_length := vf_packet_length - (cmd - xxx1 + 1);
-    if cmd_length > vf_max_packet_length then
-        bad_vf("packet length too long");
-    if cmd_length < 0 then
-        bad_vf("string of negative length");
-    append_char(xxx1);
-    append_char(cmd_length);
-    cmd := nop; {|cmd| has been already stored above as |xxx1|}
-end;
-w0, x0, y0, z0, nop:
-    cmd_length := 0;
-push, pop:  begin
-    cmd_length := 0;
-    if cmd = push then
-        if stack_level = vf_stack_size then
-            overflow("virtual font stack size", vf_stack_size)
-        else
-            incr(stack_level)
-    else
-        if stack_level = 0 then
-            bad_vf("more POPs than PUSHs in character")
-        else
-            decr(stack_level);
-end;
-othercases
-    bad_vf("improver DVI command");
-endcases
-
-@ The |do_vf_packet| procedure is called in order to interpret the
-character packet for a virtual character. Such a packet may contain the
-instruction to typeset a character from the same or an other virtual
-font; in such cases |do_vf_packet| calls itself recursively. The
-recursion level, i.e., the number of times this has happened, is kept
-in the global variable |vf_cur_s| and should not exceed |vf_max_recursion|.
-
-@<Constants...@>=
-@!vf_max_recursion=10; {\.{VF} files shouldn't recurse beyond this level}
-@!vf_stack_size=100; {\.{DVI} files shouldn't |push| beyond this depth}
-
-@ @<Types...@>=
-@!vf_stack_index=0..vf_stack_size; {an index into the stack}
-@!vf_stack_record=record
-    stack_h, stack_v, stack_w, stack_x, stack_y, stack_z: scaled;
-end;
-
-@ @<Glob...@>=
-@!vf_cur_s: 0..vf_max_recursion; {current recursion level}
-@!vf_stack: array [vf_stack_index] of vf_stack_record;
-@!vf_stack_ptr: vf_stack_index; {pointer into |vf_stack|}
-
-@ @<Set init...@>=
-vf_cur_s := 0;
-vf_stack_ptr := 0;
-
-@ Some functions for processing character packets.
-
- at p function packet_read(k: integer): integer; {read |k| bytes as an integer from
-character packet}
-var i: integer;
-begin
-    i := 0;
-    while k > 0 do begin
-        i := i*256 + packet_byte;
-        decr(k);
-    end;
-    packet_read := i;
-end;
-
-function packet_scaled(k: integer): integer; {get |k| bytes from packet as a
-scaled}
-var s: scaled;
-begin
-    case k of
-    1: begin
-        tmp_b3 := packet_byte;
-        scaled1(s);
-    end;
-    2: begin
-        tmp_b2 := packet_byte;
-        tmp_b3 := packet_byte;
-        scaled2(s);
-    end;
-    3: begin
-        tmp_b1 := packet_byte;
-        tmp_b2 := packet_byte;
-        tmp_b3 := packet_byte;
-        scaled3(s);
-    end;
-    4: begin
-        tmp_b0 := packet_byte;
-        tmp_b1 := packet_byte;
-        tmp_b2 := packet_byte;
-        tmp_b3 := packet_byte;
-        scaled4(s);
-    end;
-    othercases pdf_error("vf", "invalid number size");
-    endcases;
-    packet_scaled := s;
-end;
-
-procedure do_vf_packet(f: internal_font_number; c: eight_bits); {typeset the \.{DVI} commands in the
-character packet for character |c| in current font |f|}
-label do_char, continue;
-var save_packet_ptr, save_packet_length: pool_pointer;
-    save_vf, k, n: internal_font_number;
-    base_line, save_h, save_v: scaled;
-    cmd: integer;
-    char_move: boolean;
-    w, x, y, z: scaled;
-    s: str_number;
-begin
-    incr(vf_cur_s);
-    if vf_cur_s > vf_max_recursion then
-        overflow("max level recursion of virtual fonts", vf_max_recursion);
-    push_packet_state;
-    start_packet(f, c);
-    vf_z := font_size[f];
-    vf_replace_z;
-    save_vf := f;
-    f := vf_i_fnts[vf_default_font[save_vf]];
-    save_v := cur_v;
-    save_h := cur_h;
-    w := 0; x := 0; y := 0; z := 0;
-    while vf_packet_length > 0 do begin
-        cmd := packet_byte;
-        @<Do typesetting the \.{DVI} commands in virtual character packet@>;
-continue:
-    end;
-    cur_h := save_h;
-    cur_v := save_v;
-    pop_packet_state;
-    vf_z := font_size[f];
-    vf_replace_z;
-    decr(vf_cur_s);
-end;
-
-@ The following code typesets a character to PDF output.
-
- at d output_one_char(#)==begin
-    pdf_check_new_font(f);
-    if pdf_font_type[f] = virtual_font_type then
-        do_vf_packet(f, #)
-    else begin
-        pdf_begin_string(f);
-        pdf_print_char(f, #);
-        adv_char_width(f, char_width(f)(char_info(f)(#)));
-    end;
-end
-
-
-@<Do typesetting the \.{DVI} commands in virtual character packet@>=
-if (cmd >= set_char_0) and (cmd <= set_char_0 + 127)  then begin
-    if not is_valid_char(cmd) then begin
-        char_warning(f, cmd);
-        goto continue;
-    end;
-    c := cmd;
-    char_move := true;
-    goto do_char;
-end
-else if ((fnt_num_0 <= cmd) and (cmd <= fnt_num_0 + 63)) or (cmd = fnt1) then begin
-    if cmd = fnt1 then
-        k := packet_byte
-    else
-        k := cmd - fnt_num_0;
-    n := 0;
-    while (n < vf_local_font_num[save_vf]) and
-          (vf_e_fnts[vf_default_font[save_vf] + n] <> k) do
-        incr(n);
-    if (n = vf_local_font_num[save_vf]) then
-        f := null_font
-    else
-        f := vf_i_fnts[vf_default_font[save_vf] + n];
-end
-else case cmd of
-push: begin
-    vf_stack[vf_stack_ptr].stack_h := cur_h;
-    vf_stack[vf_stack_ptr].stack_v := cur_v;
-    vf_stack[vf_stack_ptr].stack_w := w;
-    vf_stack[vf_stack_ptr].stack_x := x;
-    vf_stack[vf_stack_ptr].stack_y := y;
-    vf_stack[vf_stack_ptr].stack_z := z;
-    incr(vf_stack_ptr);
-end;
-pop: begin
-    decr(vf_stack_ptr);
-    cur_h := vf_stack[vf_stack_ptr].stack_h;
-    cur_v := vf_stack[vf_stack_ptr].stack_v;
-    w := vf_stack[vf_stack_ptr].stack_w;
-    x := vf_stack[vf_stack_ptr].stack_x;
-    y := vf_stack[vf_stack_ptr].stack_y;
-    z := vf_stack[vf_stack_ptr].stack_z;
-end;
-four_cases(set1), four_cases(put1): begin
-    if (set1 <= cmd) and (cmd <= set1 + 3) then begin
-        tmp_int := packet_read(cmd - set1 + 1);
-        char_move := true;
-    end
-    else begin
-        tmp_int := packet_read(cmd - put1 + 1);
-        char_move := false;
-    end;
-    if not is_valid_char(tmp_int) then begin
-        char_warning(f, tmp_int);
-        goto continue;
-    end;
-    c := tmp_int;
-    goto do_char;
-end;
-set_rule, put_rule: begin
-    rule_ht := packet_scaled(4);
-    rule_wd := packet_scaled(4);
-    if (rule_wd > 0) and (rule_ht > 0) then begin
-        pdf_set_rule(cur_h, cur_v, rule_wd, rule_ht);
-        if cmd = set_rule then
-            cur_h := cur_h + rule_wd;
-    end;
-end;
-four_cases(right1):
-    cur_h := cur_h + packet_scaled(cmd - right1 + 1);
-w0, four_cases(w1): begin
-    if cmd > w0 then
-        w := packet_scaled(cmd - w0);
-    cur_h := cur_h + w;
-end;
-x0, four_cases(x1): begin
-    if cmd > x0 then
-        x := packet_scaled(cmd - x0);
-    cur_h := cur_h + x;
-end;
-four_cases(down1):
-    cur_v := cur_v + packet_scaled(cmd - down1 + 1);
-y0, four_cases(y1): begin
-    if cmd > y0 then
-        y := packet_scaled(cmd - y0);
-    cur_v := cur_v + y;
-end;
-z0, four_cases(z1): begin
-    if cmd > z0 then
-        z := packet_scaled(cmd - z0);
-    cur_v := cur_v + z;
-end;
-four_cases(xxx1):  begin
-    tmp_int := packet_read(cmd - xxx1 + 1);
-    str_room(tmp_int);
-    while tmp_int > 0 do begin
-        decr(tmp_int);
-        append_char(packet_byte);
-    end;
-    s := make_string;
-    literal(s, true, true, false);
-    flush_str(s);
-end;
-othercases pdf_error("vf", "invalid DVI command");
-endcases;
-goto continue;
-do_char:
-if is_valid_char(c) then 
-    output_one_char(c)
-else
-    char_warning(f, c);
-if char_move then
-    cur_h := cur_h + char_width(f)(char_info(f)(c))
-
-@* \[32f] PDF shipping out.
-To ship out a \TeX\ box to PDF page description we need to implement
-|pdf_hlist_out|, |pdf_vlist_out| and |pdf_ship_out|, which are equivalent to
-the \TeX' original |hlist_out|, |vlist_out| and |ship_out| resp. But first we
-need to declare some procedures needed in |pdf_hlist_out| and |pdf_vlist_out|.
-
-@<Declare procedures needed in |pdf_hlist_out|, |pdf_vlist_out|@>=
-procedure pdf_out_literal(p:pointer);
-var old_setting:0..max_selector; {holds print |selector|}
-    s: str_number;
-begin
-    old_setting:=selector; selector:=new_string;
-    show_token_list(link(pdf_literal_data(p)),null,pool_size-pool_ptr);
-    selector:=old_setting;
-    s := make_string;
-    if pdf_literal_direct(p) = 1 then
-        literal(s, false, false, false)
-    else
-        literal(s, true, false, false);
-    flush_str(s);
-end;
-
-procedure pdf_special(p: pointer);
-var old_setting:0..max_selector; {holds print |selector|}
-    s: str_number;
-begin
-    old_setting:=selector; selector:=new_string;
-    show_token_list(link(write_tokens(p)),null,pool_size-pool_ptr);
-    selector:=old_setting;
-    s := make_string;
-    literal(s, true, true, true);
-    flush_str(s);
-end;
-
-procedure pdf_print_toks(p: pointer); {print tokens list |p|}
-var s: str_number;
-begin
-    s := tokens_to_string(p);
-    if length(s) > 0 then
-        pdf_print(s);
-    flush_str(s);
-end;
-
-procedure pdf_print_toks_ln(p: pointer); {print tokens list |p|}
-var s: str_number;
-begin
-    s := tokens_to_string(p);
-    if length(s) > 0 then begin
-        pdf_print(s);
-        pdf_print_nl;
-    end;
-    flush_str(s);
-end;
-
-@ Similiar to |vlist_out|, |pdf_vlist_out| needs to be declared forward
-
- at p procedure@?pdf_vlist_out; forward;
-
-@ The implementation of procedure |pdf_hlist_out| is similiar to |hlist_out|
-
- at p @t\4@>@<Declare procedures needed in |pdf_hlist_out|, |pdf_vlist_out|@>@t@>@/
-
-procedure pdf_hlist_out; {output an |hlist_node| box}
+ at x (MLTeX) l. 17413
 label reswitch, move_past, fin_rule, next_p;
-var base_line: scaled; {the baseline coordinate for this box}
-@!left_edge: scaled; {the left coordinate for this box}
-@!save_h: scaled; {what |cur_h| should pop to}
-@!this_box: pointer; {pointer to containing box}
-@!g_order: glue_ord; {applicable order of infinity for glue}
-@!g_sign: normal..shrinking; {selects type of glue}
-@!p:pointer; {current position in the hlist}
-@!leader_box:pointer; {the leader box being replicated}
-@!leader_wd:scaled; {width of leader box being replicated}
-@!lx:scaled; {extra space between leader boxes}
-@!outer_doing_leaders:boolean; {were we doing leaders?}
-@!edge:scaled; {left edge of sub-box, or right edge of leader space}
-@!running_link: pointer; {pointer to `running' link if exists}
-@!glue_temp:real; {glue value before rounding}
-@!cur_glue:real; {glue seen so far}
-@!cur_g:scaled; {rounded equivalent of |cur_glue| times the glue ratio}
-begin cur_g:=0; cur_glue:=float_constant(0);
-this_box:=temp_ptr; g_order:=glue_order(this_box);
-g_sign:=glue_sign(this_box); p:=list_ptr(this_box);
-incr(cur_s);
-base_line:=cur_v; left_edge:=cur_h;
-running_link := null;
-@<Create link annotation for the current hbox if needed@>;
-while p<>null do
-    @<Output node |p| for |pdf_hlist_out| and move to the next node,
-    maintaining the condition |cur_v=base_line|@>;
-decr(cur_s);
-end;
+ at y
+label reswitch, move_past, fin_rule, next_p, found, continue;
+ at z
 
-@ @<Create link annotation for the current hbox if needed@>=
-if running_link = null then begin
-    if is_running(pdf_link_wd) and (pdf_link_level = cur_s) then begin
-        append_link(this_box, left_edge, base_line);
-        running_link := last_link;
-    end;
-end
-else
-    last_link := running_link
-
-@ @<Output node |p| for |pdf_hlist_out|...@>=
-reswitch: if is_char_node(p) then
-  begin
-  repeat f:=font(p); c:=character(p);
+ at x (MLTeX) l. 17462
   if is_valid_char(c) then 
       output_one_char(c)
   else
       char_warning(f, c);
   cur_h:=cur_h+char_width(f)(char_info(f)(c));
-  p:=link(p);
-  until not is_char_node(p);
-  end
-else @<Output the non-|char_node| |p| for |pdf_hlist_out|
-    and move to the next node@>
-
-@ @<Output the non-|char_node| |p| for |pdf_hlist_out|...@>=
-begin case type(p) of
-hlist_node,vlist_node:@<(\pdfTeX) Output a box in an hlist@>;
-rule_node: begin rule_ht:=height(p); rule_dp:=depth(p); rule_wd:=width(p);
-  goto fin_rule;
+ at y
+  if is_valid_char(c) then begin
+      output_one_char(c);
+      cur_h:=cur_h+char_width(f)(char_info(f)(c));
+      goto continue;
   end;
-whatsit_node: @<Output the whatsit node |p| in |pdf_hlist_out|@>;
-glue_node: @<(\pdfTeX) Move right or output leaders@>;
-kern_node,math_node:cur_h:=cur_h+width(p);
-ligature_node: @<Make node |p| look like a |char_node| and |goto reswitch|@>;
-othercases do_nothing
-endcases;@/
-goto next_p;
-fin_rule: @<(\pdfTeX) Output a rule in an hlist@>;
-move_past: cur_h:=cur_h+rule_wd;
-next_p:p:=link(p);
-end
+  if mltex_enabled_p then
+    @<(\pdfTeX) Output a substitution, |goto continue| if not possible@>;
+continue:
+ at z
 
-@ @<(\pdfTeX) Output a box in an hlist@>=
-if list_ptr(p)=null then cur_h:=cur_h+width(p)
-else  begin
-  cur_v:=base_line+shift_amount(p); {shift the box down}
-  temp_ptr:=p; edge:=cur_h;
-  if type(p)=vlist_node then pdf_vlist_out at +else pdf_hlist_out;
-  cur_h:=edge+width(p); cur_v:=base_line;
-  end
-
-@ @<(\pdfTeX) Output a rule in an hlist@>=
-if is_running(rule_ht) then rule_ht:=height(this_box);
-if is_running(rule_dp) then rule_dp:=depth(this_box);
-rule_ht:=rule_ht+rule_dp; {this is the rule thickness}
-if (rule_ht>0)and(rule_wd>0) then {we don't output empty rules}
-  begin cur_v:=base_line+rule_dp;
-  pdf_set_rule(cur_h, cur_v, rule_wd, rule_ht);
-  cur_v:=base_line;
-  end
-
-@ @<(\pdfTeX) Move right or output leaders@>=
-begin g:=glue_ptr(p); rule_wd:=width(g)-cur_g;
-if g_sign<>normal then
-  begin if g_sign=stretching then
-    begin if stretch_order(g)=g_order then
-      begin cur_glue:=cur_glue+stretch(g);
-      vet_glue(float(glue_set(this_box))*cur_glue);
-@^real multiplication@>
-      cur_g:=round(glue_temp);
-      end;
-    end
-  else if shrink_order(g)=g_order then
-      begin cur_glue:=cur_glue-shrink(g);
-      vet_glue(float(glue_set(this_box))*cur_glue);
-      cur_g:=round(glue_temp);
-      end;
-  end;
-rule_wd:=rule_wd+cur_g;
-if subtype(p)>=a_leaders then
-  @<(\pdfTeX) Output leaders in an hlist, |goto fin_rule| if a rule
-    or to |next_p| if done@>;
-goto move_past;
-end
-
-@ @<(\pdfTeX) Output leaders in an hlist...@>=
-begin leader_box:=leader_ptr(p);
-if type(leader_box)=rule_node then
-  begin rule_ht:=height(leader_box); rule_dp:=depth(leader_box);
-  goto fin_rule;
-  end;
-leader_wd:=width(leader_box);
-if (leader_wd>0)and(rule_wd>0) then
-  begin rule_wd:=rule_wd+10; {compensate for floating-point rounding}
-  edge:=cur_h+rule_wd; lx:=0;
-  @<Let |cur_h| be the position of the first box, and set |leader_wd+lx|
-    to the spacing between corresponding parts of boxes@>;
-  while cur_h+leader_wd<=edge do
-    @<(\pdfTeX) Output a leader box at |cur_h|,
-      then advance |cur_h| by |leader_wd+lx|@>;
-  cur_h:=edge-10; goto next_p;
-  end;
-end
-
-@ @<(\pdfTeX) Output a leader box at |cur_h|, ...@>=
-begin cur_v:=base_line+shift_amount(leader_box);@/
-save_h:=cur_h; temp_ptr:=leader_box;
-outer_doing_leaders:=doing_leaders; doing_leaders:=true;
-if type(leader_box)=vlist_node then pdf_vlist_out at +else pdf_hlist_out;
-doing_leaders:=outer_doing_leaders;
-cur_v:=base_line;
-cur_h:=save_h+leader_wd+lx;
-end
-
+ at x
 @ The |pdf_vlist_out| routine is similar to |pdf_hlist_out|, but a bit simpler.
- at p procedure pdf_vlist_out; {output a |pdf_vlist_node| box}
-label move_past, fin_rule, next_p;
-var left_edge: scaled; {the left coordinate for this box}
-@!top_edge: scaled; {the top coordinate for this box}
-@!save_v: scaled; {what |cur_v| should pop to}
-@!this_box: pointer; {pointer to containing box}
-@!g_order: glue_ord; {applicable order of infinity for glue}
-@!g_sign: normal..shrinking; {selects type of glue}
-@!p:pointer; {current position in the vlist}
-@!leader_box:pointer; {the leader box being replicated}
-@!leader_ht:scaled; {height of leader box being replicated}
-@!lx:scaled; {extra space between leader boxes}
-@!outer_doing_leaders:boolean; {were we doing leaders?}
-@!edge:scaled; {bottom boundary of leader space}
-@!glue_temp:real; {glue value before rounding}
-@!cur_glue:real; {glue seen so far}
-@!cur_g:scaled; {rounded equivalent of |cur_glue| times the glue ratio}
-begin cur_g:=0; cur_glue:=float_constant(0);
-this_box:=temp_ptr; g_order:=glue_order(this_box);
-g_sign:=glue_sign(this_box); p:=list_ptr(this_box);
-incr(cur_s);
-left_edge:=cur_h; cur_v:=cur_v-height(this_box); top_edge:=cur_v;
-@<Create thread for the current vbox if needed@>;
-while p<>null do
-    @<Output node |p| for |pdf_vlist_out| and move to the next node,
-    maintaining the condition |cur_h=left_edge|@>;
-decr(cur_s);
-end;
-
-@ @<Create thread for the current vbox if needed@>=
-if (last_thread <> null) and is_running(pdf_thread_dp) and 
-    (pdf_thread_level = cur_s) then
-    append_thread(this_box, left_edge, top_edge + height(this_box))
-
-@ @<Output node |p| for |pdf_vlist_out|...@>=
-begin if is_char_node(p) then confusion("pdfvlistout")
-@:this can't happen pdfvlistout}{\quad pdfvlistout@>
-else @<Output the non-|char_node| |p| for |pdf_vlist_out|@>;
-next_p:p:=link(p);
-end
-
-@ @<Output the non-|char_node| |p| for |pdf_vlist_out|@>=
-begin case type(p) of
-hlist_node,vlist_node:@<(\pdfTeX) Output a box in a vlist@>;
-rule_node: begin rule_ht:=height(p); rule_dp:=depth(p); rule_wd:=width(p);
-  goto fin_rule;
-  end;
-whatsit_node: @<Output the whatsit node |p| in |pdf_vlist_out|@>;
-glue_node: @<(\pdfTeX) Move down or output leaders@>;
-kern_node:cur_v:=cur_v+width(p);
-othercases do_nothing
-endcases;@/
-goto next_p;
-fin_rule: @<(\pdfTeX) Output a rule in a vlist, |goto next_p|@>;
-move_past: cur_v:=cur_v+rule_ht;
-end
-
-@ @<(\pdfTeX) Output a box in a vlist@>=
-if list_ptr(p)=null then cur_v:=cur_v+height(p)+depth(p)
-else  begin cur_v:=cur_v+height(p); save_v:=cur_v;
-  cur_h:=left_edge+shift_amount(p); {shift the box right}
-  temp_ptr:=p;
-  if type(p)=vlist_node then pdf_vlist_out at +else pdf_hlist_out;
-  cur_v:=save_v+depth(p); cur_h:=left_edge;
+ at y
+@ @<(\pdfTeX) Output a substitution, |goto continue| if not possible@>=
+  begin
+  @<Get substitution information, check it, goto |found|
+  if all is ok, otherwise goto |continue|@>;
+found: @<Print character substition tracing log@>;
+  @<(\pdfTeX) Rebuild character using substitution information@>;
   end
 
-@ @<(\pdfTeX) Output a rule in a vlist...@>=
-if is_running(rule_wd) then rule_wd:=width(this_box);
-rule_ht:=rule_ht+rule_dp; {this is the rule thickness}
-cur_v:=cur_v+rule_ht;
-if (rule_ht>0)and(rule_wd>0) then {we don't output empty rules}
-  pdf_set_rule(cur_h, cur_v, rule_wd, rule_ht);
-goto next_p
-
-@ @<(\pdfTeX) Move down or output leaders@>=
-begin g:=glue_ptr(p); rule_ht:=width(g)-cur_g;
-if g_sign<>normal then
-  begin if g_sign=stretching then
-    begin if stretch_order(g)=g_order then
-      begin cur_glue:=cur_glue+stretch(g);
-      vet_glue(float(glue_set(this_box))*cur_glue);
+@ @<(\pdfTeX) Rebuild character using substitution information@>=
+  base_x_height:=x_height(f);
+  base_slant:=slant(f)/float_constant(65536);
+@^real division@>
+  accent_slant:=base_slant; {slant of accent character font}
+  base_width:=char_width(f)(ib_c);
+  base_height:=char_height(f)(height_depth(ib_c));
+  accent_width:=char_width(f)(ia_c);
+  accent_height:=char_height(f)(height_depth(ia_c));
+  @/{compute necessary horizontal shift (don't forget slant)}@/
+  delta:=round((base_width-accent_width)/float_constant(2)+
+            base_height*base_slant-base_x_height*accent_slant);
 @^real multiplication@>
-      cur_g:=round(glue_temp);
-      end;
+@^real addition@>
+  @/{1. For centering/horizontal shifting insert a kern node.}@/
+  cur_h:=cur_h+delta;
+  @/{2. Then insert the accent character possibly shifted up or down.}@/
+  if ((base_height<>base_x_height) and (accent_height>0)) then
+    begin {the accent must be shifted up or down}
+    cur_v:=base_line+(base_x_height-base_height);
+    output_one_char(accent_c);
+    cur_v:=base_line;
     end
-  else if shrink_order(g)=g_order then
-      begin cur_glue:=cur_glue-shrink(g);
-      vet_glue(float(glue_set(this_box))*cur_glue);
-      cur_g:=round(glue_temp);
-      end;
-  end;
-rule_ht:=rule_ht+cur_g;
-if subtype(p)>=a_leaders then
-  @<(\pdfTeX) Output leaders in a vlist, |goto fin_rule| if a rule
-    or to |next_p| if done@>;
-goto move_past;
-end
-
-@ @<(\pdfTeX) Output leaders in a vlist...@>=
-begin leader_box:=leader_ptr(p);
-if type(leader_box)=rule_node then
-  begin rule_wd:=width(leader_box); rule_dp:=0;
-  goto fin_rule;
-  end;
-leader_ht:=height(leader_box)+depth(leader_box);
-if (leader_ht>0)and(rule_ht>0) then
-  begin rule_ht:=rule_ht+10; {compensate for floating-point rounding}
-  edge:=cur_v+rule_ht; lx:=0;
-  @<Let |cur_v| be the position of the first box, and set |leader_ht+lx|
-    to the spacing between corresponding parts of boxes@>;
-  while cur_v+leader_ht<=edge do
-    @<(\pdfTeX) Output a leader box at |cur_v|,
-      then advance |cur_v| by |leader_ht+lx|@>;
-  cur_v:=edge-10; goto next_p;
-  end;
-end
-
-@ @<(\pdfTeX) Output a leader box at |cur_v|, ...@>=
-begin cur_h:=left_edge+shift_amount(leader_box);@/
-cur_v:=cur_v+height(leader_box); save_v:=cur_v;
-temp_ptr:=leader_box;
-outer_doing_leaders:=doing_leaders; doing_leaders:=true;
-if type(leader_box)=vlist_node then pdf_vlist_out at +else pdf_hlist_out;
-doing_leaders:=outer_doing_leaders;
-cur_h:=left_edge;
-cur_v:=save_v-height(leader_box)+leader_ht+lx;
-end
-
-@ |fix_pdfoutput| freezes |pdfoutput| when something has been written to
-the output.
-
- at p procedure fix_pdfoutput;
-begin
-    if not fixed_pdfoutput_set then begin
-        fixed_pdfoutput := pdf_output;
-        fixed_pdfoutput_set := true;
-    end
-    else if fixed_pdfoutput <> pdf_output then
-        pdf_error("setup", 
-            "\pdfoutput can only be changed before anything is written to the output");
-end;
-
-
-@ |pdf_ship_out| is used instead of |ship_out| to shipout a box to PDF
-output. If |shipping_page| is not set then the output will be a Form object,
-otherwise it will be a Page object.
-
- at p procedure pdf_ship_out(p: pointer; shipping_page: boolean); {output the box |p|}
-label done, done1;
-var i,j,k:integer; {general purpose accumulators}
-r: integer; {accumulator to copy node for pending link annotation}
-save_font_list: pointer; {to save |pdf_font_list| during flushing pending forms}
-save_obj_list: pointer; {to save |pdf_obj_list|}
-save_ximage_list: pointer; {to save |pdf_ximage_list|}
-save_xform_list: pointer; {to save |pdf_xform_list|}
-save_image_procset: integer;  {to save |pdf_image_procset|}
-save_text_procset: integer;  {to save |pdf_text_procset|}
-pdf_last_resources: integer; {pointer to most recently generated Resources object}
-s:str_number;
-old_setting:0..max_selector; {saved |selector| setting}
-begin if tracing_output>0 then
-  begin print_nl(""); print_ln;
-  print("Completed box being shipped out");
- at .Completed box...@>
-  end;
-if not init_pdf_output then begin
-    @<Initialize variables for \.{PDF} output@>;
-    init_pdf_output := true;
-end;
-is_shipping_page := shipping_page;
-if shipping_page then begin
-    if term_offset>max_print_line-9 then print_ln
-    else if (term_offset>0)or(file_offset>0) then print_char(" ");
-    print_char("["); j:=9;
-    while (count(j)=0)and(j>0) do decr(j);
-    for k:=0 to j do
-      begin print_int(count(k));
-      if k<j then print_char(".");
-      end;
-    update_terminal;
-end;
-if tracing_output>0 then
-  begin if shipping_page then print_char("]");
-  begin_diagnostic; show_box(p); end_diagnostic(true);
-  end;
-@<(\pdfTeX) Ship box |p| out@>;
-if (tracing_output<=0) and shipping_page then print_char("]");
-dead_cycles:=0;
-update_terminal; {progress report}
-@<Flush the box from memory, showing statistics if requested@>;
-end;
-
-@ @<(\pdfTeX) Ship box |p| out@>=
-@<Update the values of |max_h| and |max_v|; but if the page is too large,
-  |goto done|@>;
-@<Initialize variables as |pdf_ship_out| begins@>;
-if type(p)=vlist_node then pdf_vlist_out at +else pdf_hlist_out;
-if shipping_page then
-    incr(total_pages);
-cur_s:=-1;
-@<Finish shipping@>;
-done:
-
-@ @<Initialize variables as |pdf_ship_out| begins@>=
-fix_pdfoutput;
-temp_ptr:=p;
-prepare_mag;
-pdf_last_resources := pdf_new_objnum;
-@<Reset resources lists@>;
-if not shipping_page then begin
-    pdf_xform_width := width(p);
-    pdf_xform_height := height(p);
-    pdf_xform_depth := depth(p);
-    pdf_begin_dict(pdf_cur_form);
-    pdf_last_stream := pdf_cur_form;
-    cur_v := height(p);
-    cur_h := 0;
-    pdf_origin_h := 0;
-    pdf_origin_v := pdf_xform_height + pdf_xform_depth;
-end
-else begin
-    @<Calculate page dimensions and margins@>;
-    pdf_last_page := get_obj(obj_type_page, total_pages + 1, 0);
-    obj_aux(pdf_last_page) := 1; {mark that this page has beed created}
-    pdf_new_dict(obj_type_others, 0);
-    pdf_last_stream := obj_ptr;
-    cur_h := cur_h_offset;
-    cur_v := height(p) + cur_v_offset;
-    pdf_origin_h := 0;
-    pdf_origin_v := cur_page_height;
-    @<Reset PDF mark lists@>;
-end;
-if not shipping_page then begin
-    @<Write out Form stream header@>;
-end;
-@<Start stream of page/form contents@>
-
-@ @<Reset resources lists@>=
-pdf_font_list := null;
-pdf_obj_list := null;
-pdf_xform_list := null;
-pdf_ximage_list := null;
-pdf_text_procset := false;
-pdf_image_procset := 0
-
-@ @<Reset PDF mark lists@>=
-pdf_annot_list := null;
-pdf_link_list := null;
-pdf_dest_list := null;
-pdf_bead_list := null;
-last_link := null;
-last_thread := null
-
-@ @<Calculate page dimensions and margins@>=
-cur_h_offset := pdf_h_origin + h_offset;
-cur_v_offset := pdf_v_origin + v_offset;
-if pdf_page_width <> 0 then
-    cur_page_width := pdf_page_width
-else
-    cur_page_width := width(p) + 2*cur_h_offset;
-if pdf_page_height <> 0 then
-    cur_page_height := pdf_page_height
-else
-    cur_page_height := height(p) + depth(p) + 2*cur_v_offset
-
-@ Here we write out the header for Form.
-
-@<Write out Form stream header@>=
-pdf_print_ln("/Type /XObject");
-pdf_print_ln("/Subtype /Form");
-if obj_xform_attr(pdf_cur_form) <> null then begin
-    pdf_print_toks_ln(obj_xform_attr(pdf_cur_form));
-    delete_toks(obj_xform_attr(pdf_cur_form));
-end;
-pdf_print("/BBox [");
-pdf_print("0 0 ");
-pdf_print_bp(pdf_xform_width); pdf_out(" ");
-pdf_print_bp(pdf_xform_height + pdf_xform_depth); pdf_print_ln("]");
-pdf_print_ln("/FormType 1");
-pdf_print_ln("/Matrix [1 0 0 1 0 0]");
-pdf_indirect_ln("Resources", pdf_last_resources)
-
-@ @<Start stream of page/form contents@>=
-pdf_begin_stream;
-if shipping_page then begin
-    @<Adjust transformation matrix for the magnification ratio@>;
-end
-
-@ @<Adjust transformation matrix for the magnification ratio@>=
-prepare_mag;
-if mag <> 1000 then begin
-    pdf_print_real(mag, 3);
-    pdf_print(" 0 0 ");
-    pdf_print_real(mag, 3);
-    pdf_print_ln(" 0 0 cm");
-end
-
-@ @<Finish shipping@>=
-@<Finish stream of page/form contents@>;
-if shipping_page then begin
-    @<Write out page object@>;
-end;
-@<Flush out pending raw objects@>;
-@<Flush out pending forms@>;
-@<Flush out pending images@>;
-if shipping_page then begin
-    @<Flush out pending PDF marks@>;
-end;
-@<Write out resources dictionary@>;
-@<Flush resources lists@>;
-if shipping_page then begin
-    @<Flush PDF mark lists@>;
-end
-
-@ @<Finish stream of page/form contents@>=
-pdf_end_text;
-pdf_end_stream
-
-@ @<Write out resources dictionary@>=
-pdf_begin_dict(pdf_last_resources);
-@<Print additional resources@>;
-@<Generate font resources@>;
-@<Generate XObject resources@>;
-@<Generate ProcSet@>;
-pdf_end_dict
-
-@ @<Print additional resources@>=
-if shipping_page then begin
-    if pdf_page_resources <> null then
-        pdf_print_toks_ln(pdf_page_resources);
-end
-else begin
-    if obj_xform_resources(pdf_cur_form) <> null then begin
-        pdf_print_toks_ln(obj_xform_resources(pdf_cur_form));
-        delete_toks(obj_xform_resources(pdf_cur_form));
+  else begin
+    output_one_char(accent_c);
     end;
-end
+  cur_h:=cur_h+accent_width;
+  @/{3. For centering/horizontal shifting insert another kern node.}@/
+  cur_h:=cur_h+(-accent_width-delta);
+  @/{4. Output the base character.}@/
+  output_one_char(base_c);
+  cur_h:=cur_h+base_width;
 
-@ In the end of shipping out a page we reset all the lists holding objects
-have been created during the page shipping.
+@ The |pdf_vlist_out| routine is similar to |pdf_hlist_out|, but a bit simpler.
+ at z
 
- at d delete_toks(#) == begin delete_token_ref(#); # := null; end
-
-@<Flush resources lists@>=
-flush_list(pdf_font_list);
-flush_list(pdf_obj_list);
-flush_list(pdf_xform_list);
-flush_list(pdf_ximage_list)
-
-@ @<Flush PDF mark lists@>=
-flush_list(pdf_annot_list);
-flush_list(pdf_link_list);
-flush_list(pdf_dest_list);
-flush_list(pdf_bead_list)
-
-@ @<Generate font resources@>=
-if pdf_font_list <> null then begin
-    pdf_print("/Font << ");
-    k := pdf_font_list;
-    while k <> null do begin
-        pdf_print("/F");
-        set_ff(info(k));
-        pdf_print_int(ff);
-        pdf_print_font_tag(info(k));
-        pdf_print_resname_prefix;
-        pdf_out(" ");
-        pdf_print_int(pdf_font_num[ff]);
-        pdf_print(" 0 R ");
-        k := link(k);
-    end;
-    pdf_print_ln(">>");
-    pdf_text_procset := true;
-end
-
-@ @<Generate XObject resources@>=
-if (pdf_xform_list <> null) or (pdf_ximage_list <> null) then begin
-    pdf_print("/XObject << ");
-    k := pdf_xform_list;
-    while k <> null do begin
-        pdf_print("/Fm");
-        pdf_print_int(obj_info(info(k)));
-        pdf_print_resname_prefix;
-        pdf_out(" ");
-        pdf_print_int(info(k));
-        pdf_print(" 0 R ");
-        k := link(k);
-    end;
-    k := pdf_ximage_list;
-    while k <> null do begin
-        pdf_print("/Im");
-        pdf_print_int(obj_info(info(k)));
-        pdf_print_resname_prefix;
-        pdf_out(" ");
-        pdf_print_int(info(k));
-        pdf_print(" 0 R ");
-        update_image_procset(obj_ximage_data(info(k)));
-        k := link(k);
-    end;
-    pdf_print_ln(">>");
-end
-
-@ @<Generate ProcSet@>=
-pdf_print("/ProcSet [ /PDF");
-if pdf_text_procset then
-    pdf_print(" /Text");
-if check_image_b(pdf_image_procset) then
-    pdf_print(" /ImageB");
-if check_image_c(pdf_image_procset) then
-    pdf_print(" /ImageC");
-if check_image_i(pdf_image_procset) then
-    pdf_print(" /ImageI");
-pdf_print_ln(" ]")
-
-@ @<Write out page object@>=
-pdf_begin_dict(pdf_last_page);
-pdf_print_ln("/Type /Page");
-pdf_indirect_ln("Contents", pdf_last_stream);
-pdf_indirect_ln("Resources", pdf_last_resources);
-pdf_print("/MediaBox [0 0 ");
-pdf_print_mag_bp(cur_page_width); pdf_out(" ");
-pdf_print_mag_bp(cur_page_height);
-pdf_print_ln("]");
-if pdf_page_attr <> null then
-    pdf_print_toks_ln(pdf_page_attr);
-@<Generate parent pages object@>;
-@<Generate array of annotations or beads in page@>;
-pdf_end_dict
-
-@ @<Generate parent pages object@>=
-if total_pages mod pages_tree_kids_max = 1 then begin
-    pdf_create_obj(obj_type_pages, pages_tree_kids_max);
-    pdf_last_pages := obj_ptr;
-end;
-pdf_indirect_ln("Parent", pdf_last_pages)
-
-@ @<Generate array of annotations or beads in page@>=
-if (pdf_annot_list <> null) or (pdf_link_list <> null) then begin
-    pdf_print("/Annots [ ");
-    k := pdf_annot_list;
-    while k <> null do begin
-        pdf_print_int(info(k));
-        pdf_print(" 0 R ");
-        k := link(k);
-    end;
-    k := pdf_link_list;
-    while k <> null do begin
-        pdf_print_int(info(k));
-        pdf_print(" 0 R ");
-        k := link(k);
-    end;
-    pdf_print_ln("]");
-end;
-if pdf_bead_list <> null then begin
-    k := pdf_bead_list;
-    pdf_print("/B [ ");
-    while k <> null do begin
-        pdf_print_int(info(k));
-        pdf_print(" 0 R ");
-        k := link(k);
-    end;
-    pdf_print_ln("]");
-end
-
-@ @<Declare procedures needed in |pdf_hlist_out|, |pdf_vlist_out|@>=
-procedure pdf_write_obj(n: integer); {write a raw PDF object}
-var s: str_number;
-    f: byte_file;
-begin
-    s := tokens_to_string(obj_obj_data(n));
-    delete_toks(obj_obj_data(n));
-    if obj_obj_is_stream(n) > 0 then begin
-        pdf_begin_dict(n);
-        if obj_obj_stream_attr(n) <> null then begin
-            pdf_print_toks_ln(obj_obj_stream_attr(n));
-            delete_toks(obj_obj_stream_attr(n));
-        end;
-        pdf_begin_stream;
+ at x [49.1259] 
+    begin if s>0 then
+      begin if s=font_size[f] then goto common_ending;
+      end
+    else if font_size[f]=xn_over_d(font_dsize[f],-s,1000) then
+      goto common_ending;
     end
-    else
-        pdf_begin_obj(n);
-    if obj_obj_is_file(n) > 0 then begin
-        cur_name := s;
-        cur_area := "";
-        cur_ext := "";
-        pack_cur_name;
-        if not tex_b_openin(f) then
-            pdf_error("ext5", "cannot open file for embedding");
-        print("<<");
-        print(s);
-        while not eof(f) do
-            pdf_out(getc(f));
-        print(">>");
-        b_close(f);
+ at y
+    begin
+    if pdf_font_step[f] = 0 then begin
+       if s>0 then
+         begin if s=font_size[f] then goto common_ending;
+         end
+       else if font_size[f]=xn_over_d(font_dsize[f],-s,1000) then
+         goto common_ending;
+       end
     end
-    else if obj_obj_is_stream(n) > 0 then
-        pdf_print(s)
-    else
-        pdf_print_ln(s);
-    if obj_obj_is_stream(n) > 0 then
-        pdf_end_stream
-    else
-        pdf_end_obj;
-    flush_str(s);
-end;
+ at z
 
-procedure flush_whatsit_node(p: pointer; s: small_number);
-begin
-    type(p) := whatsit_node;
-    subtype(p) := s;
-    if link(p) <> null then
-        pdf_error("flush_whatsit_node", "link(p) is not null");
-    flush_node_list(p);
-end;
+ at x (WEB2C!)
+param_base:=xmalloc_array(integer, font_max);
 
-@ @<Flush out pending raw objects@>=
-if pdf_obj_list <> null then begin
-    k := pdf_obj_list;
-    while k <> null do begin
-        if not is_obj_written(info(k)) then
-            pdf_write_obj(info(k));
-        k := link(k);
-    end;
-end
+undump_things(font_check[null_font], font_ptr+1-null_font);
+ at y
+param_base:=xmalloc_array(integer, font_max);
 
-@ When flushing pending forms we need to save and restore resources lists
-  (|pdf_font_list|, |pdf_obj_list|, |pdf_xform_list| and |pdf_ximage_list|),
-  which are also used by page shipping.
+pdf_char_used:=xmalloc_array(char_used_array, font_max);
+pdf_font_size:=xmalloc_array(scaled, font_max);
+pdf_font_num:=xmalloc_array(integer, font_max);
+pdf_font_map:=xmalloc_array(fm_entry_ptr, font_max);
+pdf_font_type:=xmalloc_array(eight_bits, font_max);
+pdf_font_attr:=xmalloc_array(str_number, font_max);
+pdf_font_blink:=xmalloc_array(internal_font_number, font_max);
+pdf_font_elink:=xmalloc_array(internal_font_number, font_max);
+pdf_font_stretch:=xmalloc_array(integer, font_max);
+pdf_font_shrink:=xmalloc_array(integer, font_max);
+pdf_font_step:=xmalloc_array(integer, font_max);
+pdf_font_expand_ratio:=xmalloc_array(integer, font_max);
+pdf_font_auto_expand:=xmalloc_array(boolean, font_max);
+pdf_font_lp_base:=xmalloc_array(integer, font_max);
+pdf_font_rp_base:=xmalloc_array(integer, font_max);
+pdf_font_ef_base:=xmalloc_array(integer, font_max);
+pdf_font_kn_bs_base:=xmalloc_array(integer, font_max);
+pdf_font_st_bs_base:=xmalloc_array(integer, font_max);
+pdf_font_sh_bs_base:=xmalloc_array(integer, font_max);
+pdf_font_kn_bc_base:=xmalloc_array(integer, font_max);
+pdf_font_kn_ac_base:=xmalloc_array(integer, font_max);
+vf_packet_base:=xmalloc_array(integer, font_max);
+vf_default_font:=xmalloc_array(internal_font_number, font_max);
+vf_local_font_num:=xmalloc_array(internal_font_number, font_max);
+vf_e_fnts:=xmalloc_array(integer, font_max);
+vf_i_fnts:=xmalloc_array(internal_font_number, font_max);
 
-@<Flush out pending forms@>=
-if pdf_xform_list <> null then begin
-    k := pdf_xform_list;
-    while k <> null do begin
-        if not is_obj_written(info(k)) then begin
-            pdf_cur_form := info(k);
-            @<Save resources lists@>;
-            @<Reset resources lists@>;
-            pdf_ship_out(obj_xform_box(pdf_cur_form), false);
-            @<Restore resources lists@>;
-        end;
-        k := link(k);
-    end;
-end
-
-@ @<Save resources lists@>=
-save_font_list := pdf_font_list;
-save_obj_list := pdf_obj_list;
-save_xform_list := pdf_xform_list;
-save_ximage_list := pdf_ximage_list;
-save_text_procset := pdf_text_procset;
-save_image_procset := pdf_image_procset
-
-@ @<Restore resources lists@>=
-pdf_font_list := save_font_list;
-pdf_obj_list := save_obj_list;
-pdf_xform_list := save_xform_list;
-pdf_ximage_list := save_ximage_list;
-pdf_text_procset := save_text_procset;
-pdf_image_procset := save_image_procset
-
-@ @<Declare procedures needed in |pdf_hlist_out|, |pdf_vlist_out|@>=
-procedure pdf_write_image(n: integer); {write an image}
-begin
-    pdf_begin_dict(n);
-    if obj_ximage_attr(n) <> null then begin
-        pdf_print_toks_ln(obj_ximage_attr(n));
-        delete_toks(obj_ximage_attr(n));
-    end;
-    write_image(obj_ximage_data(n));
-    delete_image(obj_ximage_data(n));
+for font_k := font_base to font_max do begin
+    for k := 0 to 31 do
+        pdf_char_used[font_k, k] := 0;
+    pdf_font_size[font_k] := 0;
+    pdf_font_num[font_k] := 0;
+    pdf_font_map[font_k] := 0;
+    pdf_font_type[font_k] := new_font_type;
+    pdf_font_attr[font_k] := "";
+    pdf_font_blink[font_k] := null_font;
+    pdf_font_elink[font_k] := null_font;
+    pdf_font_stretch[font_k] := null_font;
+    pdf_font_shrink[font_k] := null_font;
+    pdf_font_step[font_k] := 0;
+    pdf_font_expand_ratio[font_k] := 0;
+    pdf_font_auto_expand[font_k] := false;
+    pdf_font_lp_base[font_k] := 0;
+    pdf_font_rp_base[font_k] := 0;
+    pdf_font_ef_base[font_k] := 0;
+    pdf_font_kn_bs_base[font_k] := 0;
+    pdf_font_st_bs_base[font_k] := 0;
+    pdf_font_sh_bs_base[font_k] := 0;
+    pdf_font_kn_bc_base[font_k] := 0;
+    pdf_font_kn_ac_base[font_k] := 0;
 end;
 
-@ @<Flush out pending images@>=
-if pdf_ximage_list <> null then begin
-    k := pdf_ximage_list;
-    while k <> null do begin
-        if not is_obj_written(info(k)) then
-            pdf_write_image(info(k));
-        k := link(k);
-    end;
-end
-
-@ @<Flush out pending PDF marks@>=
-pdf_origin_h := 0;
-pdf_origin_v := cur_page_height;
-@<Flush out PDF annotations@>;
-@<Flush out PDF link annotations@>;
-@<Flush out PDF mark destinations@>;
-@<Flush out PDF bead rectangle specifications@>
-
-@ @<Flush out PDF annotations@>=
-if pdf_annot_list <> null then begin
-    k := pdf_annot_list;
-    while k <> null do begin
-        i := obj_annot_ptr(info(k)); {|i| points to |pdf_annot_node|}
-        pdf_begin_dict(info(k));
-        pdf_print_ln("/Type /Annot");
-        pdf_print_toks_ln(pdf_annot_data(i));
-        pdf_rectangle(pdf_left(i), pdf_top(i), pdf_right(i), pdf_bottom(i));
-        pdf_end_dict;
-        k := link(k);
-    end;
-end
-
-@ @<Flush out PDF link annotations@>=
-if pdf_link_list <> null then begin
-    @<Write out PDF link annotations@>;
-    @<Free PDF link annotations@>;
-end
-
-@ @<Write out PDF link annotations@>=
-k := pdf_link_list;
-while k <> null do begin
-    i := obj_annot_ptr(info(k));
-    pdf_begin_dict(info(k));
-    pdf_print_ln("/Type /Annot");
-    if pdf_link_attr(i) <> null then
-        pdf_print_toks_ln(pdf_link_attr(i));
-    pdf_rectangle(pdf_left(i), pdf_top(i), pdf_right(i), pdf_bottom(i));
-    if pdf_action_type(pdf_link_action(i)) <> pdf_action_user
-    then begin
-        pdf_print_ln("/Subtype /Link");
-        pdf_print("/A ");
-    end;
-    write_action(pdf_link_action(i));
-    pdf_end_dict;
-    k := link(k);
-end
-
-@ @<Free PDF link annotations@>=
-k := pdf_link_list;
-while k <> null do begin
-    i := obj_annot_ptr(info(k));
-    {nodes with |info = null| were created by |append_link| and 
-     must be flushed here, as they are not linked in any list}
-    if info(i) = max_halfword then
-        flush_whatsit_node(i, pdf_start_link_node);
-    k := link(k);
-end
-
-@ @<Flush out PDF mark destinations@>=
-if pdf_dest_list <> null then begin
-    k := pdf_dest_list;
-    while k <> null do begin
-        if is_obj_written(info(k)) then
-            pdf_error("ext5", 
-                "destination has been already written (this shouldn't happen)")
-        else begin
-            i := obj_dest_ptr(info(k));
-            if pdf_dest_named_id(i) > 0 then begin
-                pdf_begin_dict(info(k));
-                pdf_print("/D ");
-            end
-            else
-                pdf_begin_obj(info(k));
-            pdf_out("["); pdf_print_int(pdf_last_page); pdf_print(" 0 R ");
-            case pdf_dest_type(i) of
-            pdf_dest_xyz: begin
-                pdf_print("/XYZ ");
-                pdf_print_mag_bp(pdf_x(pdf_left(i))); pdf_out(" ");
-                pdf_print_mag_bp(pdf_y(pdf_top(i))); pdf_out(" ");
-                if pdf_dest_xyz_zoom(i) = null then
-                    pdf_print("null")
-                else begin
-                    pdf_print_int(pdf_dest_xyz_zoom(i) div 1000);
-                    pdf_out(".");
-                    pdf_print_int((pdf_dest_xyz_zoom(i) mod 1000));
-                end;
-            end;
-            pdf_dest_fit:
-                pdf_print("/Fit");
-            pdf_dest_fith: begin
-                pdf_print("/FitH ");
-                pdf_print_mag_bp(pdf_y(pdf_top(i)));
-            end;
-            pdf_dest_fitv: begin
-                pdf_print("/FitV ");
-                pdf_print_mag_bp(pdf_x(pdf_left(i)));
-            end;
-            pdf_dest_fitb:
-                pdf_print("/FitB");
-            pdf_dest_fitbh: begin
-                pdf_print("/FitBH ");
-                pdf_print_mag_bp(pdf_y(pdf_top(i)));
-            end;
-            pdf_dest_fitbv: begin
-                pdf_print("/FitBV ");
-                pdf_print_mag_bp(pdf_x(pdf_left(i)));
-            end;
-            pdf_dest_fitr: begin
-                pdf_print("/FitR ");
-                pdf_print_rect_spec(i);
-            end;
-            othercases pdf_error("ext5", "unknown dest type");
-            endcases;
-            pdf_print_ln("]");
-            if pdf_dest_named_id(i) > 0 then
-                pdf_end_dict
-            else
-                pdf_end_obj;
-        end;
-        k := link(k);
-    end;
-end
-
-@ @<Declare procedures needed in |pdf_hlist_out|, |pdf_vlist_out|@>=
-procedure pdf_print_rect_spec(r: pointer); {prints a rect spec}
-begin
-    pdf_print_mag_bp(pdf_x(pdf_left(r)));
-    pdf_out(" ");
-    pdf_print_mag_bp(pdf_y(pdf_bottom(r)));
-    pdf_out(" ");
-    pdf_print_mag_bp(pdf_x(pdf_right(r)));
-    pdf_out(" ");
-    pdf_print_mag_bp(pdf_y(pdf_top(r)));
-end;
-
-@ @<Flush out PDF bead rectangle specifications@>=
-if pdf_bead_list <> null then begin
-    k := pdf_bead_list;
-    while k <> null do begin
-        pdf_new_obj(obj_type_others, 0);
-        pdf_out("[");
-        i := obj_bead_data(info(k)); {pointer to a whatsit or whatsit-like node}
-        pdf_print_rect_spec(i);
-        if info(i) = max_halfword then {not a whatsit node, so must be destroyed here}
-            flush_whatsit_node(i, pdf_start_thread_node);
-        pdf_print_ln("]");
-        obj_bead_rect(info(k)) := obj_ptr; {rewrite |obj_bead_data|}
-        pdf_end_obj;
-        k := link(k);
-    end;
-end
-
-@ In the end we must flush PDF objects that cannot be written out
-immediately after shipping out pages.
-
-@ @<Output outlines@>=
-if pdf_first_outline <> 0 then begin
-    pdf_new_dict(obj_type_others, 0);
-    outlines := obj_ptr;
-    l := pdf_first_outline; k := 0;
-    repeat
-        incr(k);
-        a := open_subentries(l);
-        if obj_outline_count(l) > 0 then
-            k := k + a;
-        obj_outline_parent(l) := obj_ptr;
-        l := obj_outline_next(l);
-    until l = 0;
-    pdf_print_ln("/Type /Outlines");
-    pdf_indirect_ln("First", pdf_first_outline);
-    pdf_indirect_ln("Last", pdf_last_outline);
-    pdf_int_entry_ln("Count", k);
-    pdf_end_dict;
-    @<Output PDF outline entries@>;
-end
-else
-    outlines := 0
-
-@ @<Output PDF outline entries@>=
-k := head_tab[obj_type_outline];
-while k <> 0 do begin
-    if obj_outline_parent(k) = pdf_parent_outline then begin
-        if obj_outline_prev(k) = 0 then
-            pdf_first_outline := k;
-        if obj_outline_next(k) = 0 then
-            pdf_last_outline := k;
-    end;
-    pdf_begin_dict(k);
-    pdf_indirect_ln("Title", obj_outline_title(k));
-    pdf_indirect_ln("A", obj_outline_action_objnum(k));
-    if obj_outline_parent(k) <> 0 then
-        pdf_indirect_ln("Parent", obj_outline_parent(k));
-    if obj_outline_prev(k) <> 0 then
-        pdf_indirect_ln("Prev", obj_outline_prev(k));
-    if obj_outline_next(k) <> 0 then
-        pdf_indirect_ln("Next", obj_outline_next(k));
-    if obj_outline_first(k) <> 0 then
-        pdf_indirect_ln("First", obj_outline_first(k));
-    if obj_outline_last(k) <> 0 then
-        pdf_indirect_ln("Last", obj_outline_last(k));
-    if obj_outline_count(k) <> 0 then
-        pdf_int_entry_ln("Count", obj_outline_count(k));
-    if obj_outline_attr(k) <> 0 then begin
-        pdf_print_toks_ln(obj_outline_attr(k));
-        delete_toks(obj_outline_attr(k));
-    end;
-    pdf_end_dict;
-    k := obj_link(k);
-end
-
-@ @<Output article threads@>=
-if head_tab[obj_type_thread] <> 0 then begin
-    pdf_new_obj(obj_type_others, 0);
-    threads := obj_ptr;
-    pdf_out("[");
-    k := head_tab[obj_type_thread];
-    while k <> 0 do begin
-        pdf_print_int(k);
-        pdf_print(" 0 R ");
-        k := obj_link(k);
-    end;
-    remove_last_space;
-    pdf_print_ln("]");
-    pdf_end_obj;
-    k := head_tab[obj_type_thread];
-    while k <> 0 do begin
-        out_thread(k);
-        k := obj_link(k);
-    end;
-end
-else
-    threads := 0
-
-@ Now we are ready to declare our new procedure |ship_out|.  It will call
-|pdf_ship_out| if integer parametr |pdf_output| is positive; otherwise it
-will call |dvi_ship_out|, which is the \TeX\ original |ship_out|. 
-
- at p procedure ship_out(p:pointer); {output the box |p|}
-begin
-    fix_pdfoutput;
-    if pdf_output > 0 then
-        pdf_ship_out(p, true)
-    else
-        dvi_ship_out(p);
-end;
-
-@ @<Initialize variables for \.{PDF} output@>=
-ensure_pdf_open;
-check_and_set_pdfoptionpdfminorversion;
-prepare_mag;
-fixed_decimal_digits := fix_int(pdf_decimal_digits, 0, 4);
-min_bp_val := 
-    divide_scaled(one_hundred_bp, ten_pow[fixed_decimal_digits + 2], 0);
-fixed_pk_resolution := fix_int(pdf_pk_resolution, 72, 2400);
-pk_scale_factor := 
-    divide_scaled(72, fixed_pk_resolution, 5 + fixed_decimal_digits);
-kpse_init_prog ('PDFTEX', fixed_pk_resolution, nil, nil);
-if not kpse_var_value('MKTEXPK') then
-    kpse_set_program_enabled (kpse_pk_format, 1, kpse_src_cmdline);
-set_job_id(year, month, day, time, pdftex_version, pdftex_revision); 
-if (pdf_unique_resname > 0) and (pdf_resname_prefix = 0) then
-    pdf_resname_prefix := get_resname_prefix
-
-@ Finishing the PDF output file.
-
-The following procedures sort the table of destination names
- at p function str_less_str(s1, s2: str_number): boolean; {compare two strings}
-var j1, j2: pool_pointer;
-    l, i: integer;
-begin
-    j1 := str_start[s1];
-    j2 := str_start[s2];
-    if length(s1) < length(s2) then
-        l := length(s1)
-    else
-        l := length(s2);
-    i := 0;
-    while (i < l) and (str_pool[j1 + i] = str_pool[j2 + i]) do
-        incr(i);
-    if ((i < l) and (str_pool[j1 + i] < str_pool[j2 + i])) or
-        ((i = l) and (length(s1) < length(s2))) then
-        str_less_str := true
-    else
-        str_less_str := false;
-end;
-
-procedure sort_dest_names(l, r: integer); {sorts |dest_names| by names}
-var i, j: integer;
-    s: str_number;
-    x, y: integer;
-    e: dest_name_entry;
-begin
-    i := l;
-    j := r;
-    s := dest_names[(l + r) div 2].objname;
-    repeat
-        while str_less_str(dest_names[i].objname, s) do
-            incr(i);
-        while str_less_str(s, dest_names[j].objname) do
-            decr(j);
-        if i <= j then begin
-            e := dest_names[i];
-            dest_names[i] := dest_names[j];
-            dest_names[j] := e;
-            incr(i);
-            decr(j);
-        end;
-    until i > j;
-    if l < j then
-        sort_dest_names(l, j);
-    if i < r then
-        sort_dest_names(i, r);
-end;
-
-@  Now the finish of PDF output file. At this moment all Page objects
-are already written completely to PDF output file.
-
-@<Finish the PDF file@>=
-if total_pages=0 then print_nl("No pages of output.")
- at .No pages of output@>
-else begin
-    pdf_flush; {to make sure that the output file name has been already
-    created}
-    if total_pages mod pages_tree_kids_max <> 0 then
-        obj_info(pdf_last_pages) := total_pages mod pages_tree_kids_max;
-    {last pages object may have less than |pages_tree_kids_max| chilrend}
-    @<Check for non-existing pages@>;
-    @<Reverse the linked list of Page and Pages objects@>;
-    @<Check for non-existing destinations@>;
-    @<Output fonts definition@>;
-    @<Output pages tree@>;
-    @<Output outlines@>;
-    @<Output name tree@>;
-    @<Output article threads@>;
-    @<Output the catalog object@>;
-    pdf_print_info;
-    @<Output the |obj_tab|@>;
-    @<Output the trailer@>;
-    pdf_flush;
-    print_nl("Output written on "); slow_print(output_file_name);
-  @.Output written on x@>
-    print(" ("); print_int(total_pages); print(" page");
-    if total_pages<>1 then print_char("s");
-    print(", "); print_int(pdf_offset); print(" bytes).");
-    libpdffinish;
-    b_close(pdf_file);
-end
-
-@ Destinations that have been referenced but don't exists have
-|obj_dest_ptr=null|. Leaving them undefined might cause troubles for
-PDF browsers, so we need to fix them.
-
- at p procedure pdf_fix_dest(k: integer);
-begin
-    if obj_dest_ptr(k) <> null then 
-        return;
-    pdf_warning("dest", "", false);
-    if obj_info(k) < 0 then begin
-        print("name{");
-        print(-obj_info(k));
-        print("}");
-    end
-    else begin
-        print("num");
-        print_int(obj_info(k));
-    end;
-    print(" has been referenced but does not exist, replaced by a fixed one");
-    print_ln; print_ln;
-    pdf_begin_obj(k);
-    pdf_out("[");
-    pdf_print_int(head_tab[obj_type_page]);
-    pdf_print_ln(" 0 R /Fit]");
-    pdf_end_obj;
-end;
-
-@ @<Check for non-existing destinations@>=
-k := head_tab[obj_type_dest];
-while k <> 0 do begin
-    pdf_fix_dest(k);
-    k := obj_link(k);
-end
-
-@ @<Check for non-existing pages@>=
-k := head_tab[obj_type_page];
-while obj_aux(k) = 0 do begin
-    pdf_warning("dest", "Page ", false);
-    print_int(obj_info(k));
-    print(" has been referenced but does not exist!");
-    print_ln; print_ln;
-    k := obj_link(k);
-end;
-head_tab[obj_type_page] := k
-
-@ @<Reverse the linked list of Page and Pages objects@>=
-k := head_tab[obj_type_page];
-l := 0;
-repeat
-    i := obj_link(k);
-    obj_link(k) := l;
-    l := k;
-    k := i;
-until k = 0;
-head_tab[obj_type_page] := l;
-k := head_tab[obj_type_pages];
-l := 0;
-repeat
-    i := obj_link(k);
-    obj_link(k) := l;
-    l := k;
-    k := i;
-until k = 0;
-head_tab[obj_type_pages] := l
-
-@ @<Output fonts definition@>=
-for k := font_base + 1 to font_ptr do
-    if font_used[k] and hasfmentry(k) then begin
-        if pdf_font_num[k] < 0 then
-            i := -pdf_font_num[k]
-        else 
-            i := tfm_of_fm(pdf_font_map[k]);
-        if i <> k then
-            for j := 0 to 255 do
-                if pdf_char_marked(k, j) then
-                    pdf_mark_char(i, j);
-    end;
-k := head_tab[obj_type_font];
-while k <> 0 do begin
-    f := obj_info(k);
-    do_pdf_font(k, f);
-    k := obj_link(k);
-end
-
-@ We will generate in each single step the parents of all Pages/Page objects in
-the previous level. These new generated Pages object will create a new level of
-Pages tree. We will repeat this until search only one Pages object. This one
-will be the Root object.
-
-@<Output pages tree@>=
-a := obj_ptr + 1; {all Pages objects whose children are not Page objects
-should have index greater than |a|}
-l := head_tab[obj_type_pages]; {|l| is the index of current Pages object which is
-being output}
-k := head_tab[obj_type_page]; {|k| is the index of current child of |l|}
-if obj_link(l) = 0 then
-    is_root := true {only Pages object; total pages is not greater than
-    |pages_tree_kids_max|}
-else
-    is_root := false;
-b := obj_ptr + 1; {to init |c| in next step}
-repeat
-    i := 0; {counter of Pages object in current level}
-    c := b; {first Pages object in previous level}
-    b := obj_ptr + 1; {succcesor of last created object}
-    repeat
-        if not is_root then begin
-            if i mod pages_tree_kids_max = 0 then begin {create a new Pages object for next level}
-                pdf_last_pages := pdf_new_objnum;
-                obj_info(pdf_last_pages) := obj_info(l);
-            end
-            else
-                obj_info(pdf_last_pages) := obj_info(pdf_last_pages) +
-                    obj_info(l);
-        end;
-        @<Output the current Pages object in this level@>;
-        incr(i);
-        if l < a  then
-            l := obj_link(l)
-        else
-            incr(l);
-    until (l = 0) or (l = b);
-    if l = 0 then
-        l := a;
-    if b = obj_ptr then
-        is_root := true;
-until false;
-done:
-
-@ @<Output the current Pages object in this level@>=
-pdf_begin_dict(l);
-pdf_print_ln("/Type /Pages");
-pdf_int_entry_ln("Count", obj_info(l));
-if not is_root then
-    pdf_indirect_ln("Parent", pdf_last_pages);
-pdf_print("/Kids [");
-j := 0;
-repeat
-    pdf_print_int(k);
-    pdf_print(" 0 R ");
-    if k < a then {the next Pages/Page object must be |obj_link(k)|}
-        k := obj_link(k)
-    else {|k >= a|, the next Pages object is |k + 1|}
-        incr(k);
-    incr(j);
-until ((l < a) and (j = obj_info(l))) or
-    (k = 0) or (k = c) or
-    (j = pages_tree_kids_max);
-remove_last_space;
-pdf_print_ln("]");
-if k = 0 then begin
-    if head_tab[obj_type_pages] <> 0 then begin {we are in Page objects list}
-        k := head_tab[obj_type_pages];
-        head_tab[obj_type_pages] := 0;
-    end
-    else {we are in Pages objects list}
-        k := a;
-end;
-if is_root and (pdf_pages_attr <> null) then
-    pdf_print_toks_ln(pdf_pages_attr);
-pdf_end_dict;
-if is_root then
-    goto done
-
-@ The name tree is very similiar to Pages tree so its construction should be
-certain from Pages tree construction. For intermediate node |obj_info| will be
-the first name and |obj_link| will be the last name in \.{\\Limits} array.
-Note that |pdf_dest_names_ptr| will be less than |obj_ptr|, so we test if
-|k < pdf_dest_names_ptr| then |k| is index of leaf in |dest_names|; else
-|k| will be index in |obj_tab| of some intermediate node.
-
-@<Output name tree@>=
-if pdf_dest_names_ptr = 0 then begin
-    dests := 0;
-    goto done1;
-end;
-sort_dest_names(0, pdf_dest_names_ptr - 1);
-a := obj_ptr + 1; {first intermediate node of name tree}
-l := a; {index of node being output}
-k := 0; {index of current child of |l|; if |k < pdf_dest_names_ptr| then this is
-pointer to |dest_names| array; otherwise it is the pointer to |obj_tab|
-(object number) }
-repeat
-    c := obj_ptr + 1; {first node in current level}
-    repeat
-        pdf_create_obj(obj_type_others, 0); {create a new node for next level}
-        @<Output the current node in this level@>;
-        incr(l);
-        incr(i);
-    until k = c;
-until false;
-done1:
-if (dests <> 0) or (pdf_names_toks <> null) then begin
-    pdf_new_dict(obj_type_others, 0);
-    if (dests <> 0) then
-        pdf_indirect_ln("Dests", dests);
-    if pdf_names_toks <> null then begin
-        pdf_print_toks_ln(pdf_names_toks);
-        delete_toks(pdf_names_toks);
-    end;
-    pdf_end_dict;
-    names_tree := obj_ptr;
-end
-else
-    names_tree := 0
-
-@ @<Output the current node in this level@>=
-pdf_begin_dict(l);
-j := 0;
-if k < pdf_dest_names_ptr then begin
-    obj_info(l) := dest_names[k].objname;
-    pdf_print("/Names [");
-    repeat
-        pdf_print_str(dest_names[k].objname);
-        pdf_out(" ");
-        pdf_print_int(dest_names[k].objnum);
-        pdf_print(" 0 R ");
-        incr(j);
-        incr(k);
-    until (j = name_tree_kids_max) or (k = pdf_dest_names_ptr);
-    remove_last_space;
-    pdf_print_ln("]");
-    obj_link(l) := dest_names[k - 1].objname;
-    if k = pdf_dest_names_ptr then
-        k := a;
-end
-else begin
-    obj_info(l) := obj_info(k);
-    pdf_print("/Kids [");
-    repeat
-        pdf_print_int(k);
-        pdf_print(" 0 R ");
-        incr(j);
-        incr(k);
-    until (j = name_tree_kids_max) or (k = c);
-    remove_last_space;
-    pdf_print_ln("]");
-    obj_link(l) := obj_link(k - 1);
-end;
-if (l > k) or (l = a) then begin
-    pdf_print("/Limits [");
-    pdf_print_str(obj_info(l));
-    pdf_out(" ");
-    pdf_print_str(obj_link(l));
-    pdf_print_ln("]");
-    pdf_end_dict;
-end
-else begin
-    pdf_end_dict;
-    dests := l;
-    goto done1;
-end
-
-@ @<Output the catalog object@>=
-pdf_new_dict(obj_type_others, 0);
-root := obj_ptr;
-pdf_print_ln("/Type /Catalog");
-pdf_indirect_ln("Pages", pdf_last_pages);
-if threads <> 0 then
-    pdf_indirect_ln("Threads", threads);
-if outlines <> 0 then
-    pdf_indirect_ln("Outlines", outlines);
-if names_tree <> 0 then
-    pdf_indirect_ln("Names", names_tree);
-if pdf_catalog_toks <> null then begin
-    pdf_print_toks_ln(pdf_catalog_toks);
-    delete_toks(pdf_catalog_toks);
-end;
-if pdf_catalog_openaction <> 0 then
-    pdf_indirect_ln("OpenAction", pdf_catalog_openaction);
-pdf_end_dict
-
-@ If the same keys in a dictionary are given several times,
-then it is not defined which value is choosen by an application.
-Therefore the keys |/Producer| and |/Creator| are only set,
-if the token list |pdf_info_toks|, converted to a string does
-not contain these key strings.
-
- at p function substr_of_str(s, t: str_number):boolean;
-label continue,exit;
-var j, k, kk: pool_pointer; {running indices}
-begin
-    k:=str_start[t];
-    while (k < str_start[t+1] - length(s)) do begin
-        j:=str_start[s];
-        kk:=k;
-        while (j < str_start[s+1]) do begin
-            if str_pool[j] <> str_pool[kk] then
-                goto continue;
-            incr(j);
-            incr(kk);
-        end;
-        substr_of_str:=true;
-        return;
-        continue: incr(k);
-    end;
-    substr_of_str:=false;
-end;
-
-procedure pdf_print_info; {print info object}
-var s: str_number;
-    creator_given, producer_given, creationdate_given: boolean;
-begin
-    pdf_new_dict(obj_type_others, 0);
-    creator_given:=false;
-    producer_given:=false;
-    creationdate_given:=false;
-    if pdf_info_toks <> null then begin
-        s:=tokens_to_string(pdf_info_toks);
-        creator_given:=substr_of_str("/Creator", s);
-        producer_given:=substr_of_str("/Producer", s);
-        creationdate_given:=substr_of_str("/CreationDate", s);
-    end;
-    if not producer_given then begin
-        @<Print the Producer key@>;
-    end;
-    if pdf_info_toks <> null then begin
-        if length(s) > 0 then begin
-            pdf_print(s);
-            pdf_print_nl;
-        end;
-        flush_str(s);
-        delete_toks(pdf_info_toks);
-    end;
-    if not creator_given then
-        pdf_str_entry_ln("Creator", "TeX");
-    if not creationdate_given then begin
-        @<Print the CreationDate key@>;
-    end;
-    pdf_str_entry_ln("PTEX.Fullbanner", pdftex_banner);
-    pdf_end_dict;
-end;
-
-@ @<Print the Producer key@>=
-pdf_print("/Producer (pdfTeX-");
-pdf_print_int(pdftex_version div 100);
-pdf_out(".");
-pdf_print_int(pdftex_version mod 100);
-pdf_print(pdftex_revision);
-pdf_print_ln(")")
-
-@ @<Print the CreationDate key@>=
-print_creation_date;
-
-@ @<Glob...@>=
-@!pdftex_banner: str_number;   {the complete banner}
-
-@ @<Output the |obj_tab|@>=
-l := 0;
-for k := 1 to obj_ptr do
-    if obj_offset(k) = 0 then begin
-        obj_link(l) := k;
-        l := k;
-    end;
-obj_link(l) := 0;
-pdf_save_offset := pdf_offset;
-pdf_print_ln("xref");
-pdf_print("0 "); pdf_print_int_ln(obj_ptr + 1);
-pdf_print_fw_int(obj_link(0), 10);
-pdf_print_ln(" 65535 f ");
-for k := 1 to obj_ptr do begin
-    if obj_offset(k) = 0 then begin
-        pdf_print_fw_int(obj_link(k), 10);
-        pdf_print_ln(" 00000 f ");
-    end
-    else begin
-        pdf_print_fw_int(obj_offset(k), 10);
-        pdf_print_ln(" 00000 n ");
-    end;
-end
-
-@ @<Output the trailer@>=
-pdf_print_ln("trailer");
-pdf_print_ln("<<");
-pdf_int_entry_ln("Size", obj_ptr + 1);
-pdf_indirect_ln("Root", root);
-pdf_indirect_ln("Info", obj_ptr);
-if pdf_trailer_toks <> null then begin
-    pdf_print_toks_ln(pdf_trailer_toks);
-    delete_toks(pdf_trailer_toks);
-end;
-print_ID(output_file_name);
-pdf_print_ln(">>");
-pdf_print_ln("startxref");
-pdf_print_int_ln(pdf_save_offset);
-pdf_print_ln("%%EOF")
-
-@* \[33] Packaging.
+make_pdftex_banner;
+undump_things(font_check[null_font], font_ptr+1-null_font);
 @z
 
- at x [33.649] l.12912
-exit: hpack:=r;
- at y
-exit: {|hpack|}
-hpack:=r;
- at z
+ at x [51.1]
+  setup_bound_var (0)('hash_extra')(hash_extra);
 
- at x [33.651] l.12936
-  kern_node,math_node: x:=x+width(p);
 @y
-  kern_node: x:=x+width(p);
-  math_node: x:=x+width(p);
+  setup_bound_var (0)('hash_extra')(hash_extra);
+  setup_bound_var (72)('pk_dpi')(pk_dpi);
 @z
 
- at x [39.889] l.17408
-adjust_tail:=adjust_head; just_box:=hpack(q,cur_width,exactly);
+ at x [51.2]
+  const_chk (hash_extra);
+  if error_line > ssup_error_line then error_line := ssup_error_line;
 @y
-adjust_tail:=adjust_head;
-just_box:=hpack(q,cur_width,exactly);
+  const_chk (hash_extra);
+  const_chk (obj_tab_size);
+  const_chk (pdf_mem_size);
+  const_chk (dest_names_size);
+  const_chk (pk_dpi);
+  if error_line > ssup_error_line then error_line := ssup_error_line;
 @z
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Declare the necessary variables for finishing PDF file
-% Close PDF output if necessary
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- at x [1333]
-procedure close_files_and_terminate;
-var k:integer; {all-purpose index}
-begin @<Finish the extensions@>;
-@!stat if tracing_stats>0 then @<Output statistics about this job@>;@;@+tats@/
-wake_up_terminal; @<Finish the \.{DVI} file@>;
+ at x [51.1332] l.24203 (ca.) texarray
+  line_stack:=xmalloc_array (integer, max_in_open);
 @y
-procedure close_files_and_terminate;
-label done, done1;
-var a, b, c, i, j, k, l: integer; {all-purpose index}
-    is_root: boolean; {|pdf_last_pages| is root of Pages tree?}
-    root, outlines, threads, names_tree, dests, fixed_dest: integer;
-begin @<Finish the extensions@>;
-@!stat if tracing_stats>0 then @<Output statistics about this job@>;@;@+tats@/
-wake_up_terminal;
-if fixed_pdfoutput > 0 then begin
-    if history = fatal_error_stop then
-        print_err(" ==> Fatal error occurred, the output PDF file is not finished!")
-    else begin
-        @<Finish the PDF file@>;
-    end;
-end
-else begin
-    @<Finish the \.{DVI} file@>;
-end;
+  line_stack:=xmalloc_array (integer, max_in_open);
+  eof_seen:=xmalloc_array (boolean, max_in_open);
+  grp_stack:=xmalloc_array (save_pointer, max_in_open);
+  if_stack:=xmalloc_array (pointer, max_in_open);
 @z
 
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Output statistics about the pdftex specific sizes only in PDF mode.
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- at x [1334]
-  wlog_ln(' ',max_in_stack:1,'i,',max_nest_stack:1,'n,',@|
-    max_param_stack:1,'p,',@|
-    max_buf_stack+1:1,'b,',@|
-    max_save_stack+6:1,'s stack positions out of ',@|
-    stack_size:1,'i,',
-    nest_size:1,'n,',
-    param_size:1,'p,',
-    buf_size:1,'b,',
-    save_size:1,'s');
-  end
+ at x [51.3]
+  hyph_link :=xmalloc_array (hyph_pointer, hyph_size);
 @y
-  wlog_ln(' ',max_in_stack:1,'i,',max_nest_stack:1,'n,',@|
-    max_param_stack:1,'p,',@|
-    max_buf_stack+1:1,'b,',@|
-    max_save_stack+6:1,'s stack positions out of ',@|
-    stack_size:1,'i,',
-    nest_size:1,'n,',
-    param_size:1,'p,',
-    buf_size:1,'b,',
-    save_size:1,'s');
-  if (pdf_output > 0) then begin
-    wlog_ln('PDF statistics:');
-    wlog_ln(' ',obj_ptr:1,' PDF objects out of ',obj_tab_size:1);
-    wlog_ln(' ',pdf_dest_names_ptr:1,' named destinations out of ',dest_names_size:1);
-    wlog_ln(' ',pdf_mem_ptr:1,' words of extra memory for PDF output out of ',pdf_mem_size:1);
-  end;
-  end
+  hyph_link :=xmalloc_array (hyph_pointer, hyph_size);
+  obj_tab:=xmalloc_array (obj_entry, inf_obj_tab_size); {will grow dynamically}
+  pdf_mem:=xmalloc_array (integer, inf_pdf_mem_size); {will grow dynamically}
+  dest_names:=xmalloc_array (dest_name_entry, inf_dest_names_size); {will grow dynamically}
+  pdf_op_buf:=xmalloc_array (eight_bits, pdf_op_buf_size);
+  pdf_os_buf:=xmalloc_array (eight_bits, inf_pdf_os_buf_size); {will grow dynamically}
+  pdf_os_objnum:=xmalloc_array (integer, pdf_os_max_objs);
+  pdf_os_objoff:=xmalloc_array (integer, pdf_os_max_objs);
 @z
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Override pdf_output value from format file with command line option
-% and initialize other options
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- at x
-  while (loc<limit)and(buffer[loc]=" ") do incr(loc);
-  end;
+ at x [51.1337] l.24371 (ca.) texarray
+  trie_root:=0; trie_c[0]:=si(0); trie_ptr:=0;
 @y
-  while (loc<limit)and(buffer[loc]=" ") do incr(loc);
-  end;
-if (pdf_output_option <> 0) then pdf_output := pdf_output_value;
-pdf_init_map_file('pdftex.map');
+  trie_root:=0; trie_c[0]:=si(0); trie_ptr:=0;
+  hyph_root:=0; hyph_start:=0;
 @z
 
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% PDF-speficic extensions that don't fall to any previous category
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- at x [1344]
- at d set_language_code=5 {command modifier for \.{\\setlanguage}}
- at y
- at d set_language_code=5 {command modifier for \.{\\setlanguage}}
- at d pdftex_first_extension_code = 6
- at d pdf_literal_node            == pdftex_first_extension_code + 0
- at d pdf_obj_code                == pdftex_first_extension_code + 1
- at d pdf_refobj_node             == pdftex_first_extension_code + 2
- at d pdf_xform_code              == pdftex_first_extension_code + 3
- at d pdf_refxform_node           == pdftex_first_extension_code + 4
- at d pdf_ximage_code             == pdftex_first_extension_code + 5
- at d pdf_refximage_node          == pdftex_first_extension_code + 6
- at d pdf_annot_node              == pdftex_first_extension_code + 7
- at d pdf_start_link_node         == pdftex_first_extension_code + 8
- at d pdf_end_link_node           == pdftex_first_extension_code + 9
- at d pdf_outline_code            == pdftex_first_extension_code + 10
- at d pdf_dest_node               == pdftex_first_extension_code + 11
- at d pdf_thread_node             == pdftex_first_extension_code + 12
- at d pdf_start_thread_node       == pdftex_first_extension_code + 13
- at d pdf_end_thread_node         == pdftex_first_extension_code + 14
- at d pdf_save_pos_node           == pdftex_first_extension_code + 15
- at d pdf_info_code               == pdftex_first_extension_code + 16
- at d pdf_catalog_code            == pdftex_first_extension_code + 17
- at d pdf_names_code              == pdftex_first_extension_code + 18
- at d pdf_font_attr_code          == pdftex_first_extension_code + 19
- at d pdf_include_chars_code      == pdftex_first_extension_code + 20
- at d pdf_map_file_code           == pdftex_first_extension_code + 21
- at d pdf_map_line_code           == pdftex_first_extension_code + 22
- at d pdf_trailer_code            == pdftex_first_extension_code + 23
- at d pdftex_last_extension_code  == pdftex_first_extension_code + 23
- at z
+ at x (WEB2C!)
+  param_base:=xmalloc_array(integer, font_max);
 
- at x [1344]
-primitive("setlanguage",extension,set_language_code);@/
-@!@:set_language_}{\.{\\setlanguage} primitive@>
+  font_ptr:=null_font; fmem_ptr:=7;
 @y
-primitive("setlanguage",extension,set_language_code);@/
-@!@:set_language_}{\.{\\setlanguage} primitive@>
-primitive("pdfliteral",extension,pdf_literal_node);@/
-@!@:pdf_literal_}{\.{\\pdfliteral} primitive@>
-primitive("pdfobj",extension,pdf_obj_code);@/
-@!@:pdf_obj_}{\.{\\pdfobj} primitive@>
-primitive("pdfrefobj",extension,pdf_refobj_node);@/
-@!@:pdf_refobj_}{\.{\\pdfrefobj} primitive@>
-primitive("pdfxform",extension,pdf_xform_code);@/
-@!@:pdf_xform_}{\.{\\pdfxform} primitive@>
-primitive("pdfrefxform",extension,pdf_refxform_node);@/
-@!@:pdf_refxform_}{\.{\\pdfrefxform} primitive@>
-primitive("pdfximage",extension,pdf_ximage_code);@/
-@!@:pdf_ximage_}{\.{\\pdfximage} primitive@>
-primitive("pdfrefximage",extension,pdf_refximage_node);@/
-@!@:pdf_refximage_}{\.{\\pdfrefximage} primitive@>
-primitive("pdfannot",extension,pdf_annot_node);@/
-@!@:pdf_annot_}{\.{\\pdfannot} primitive@>
-primitive("pdfstartlink",extension,pdf_start_link_node);@/
-@!@:pdf_start_link_}{\.{\\pdfstartlink} primitive@>
-primitive("pdfendlink",extension,pdf_end_link_node);@/
-@!@:pdf_end_link_}{\.{\\pdfendlink} primitive@>
-primitive("pdfoutline",extension,pdf_outline_code);@/
-@!@:pdf_outline_}{\.{\\pdfoutline} primitive@>
-primitive("pdfdest",extension,pdf_dest_node);@/
-@!@:pdf_dest_}{\.{\\pdfdest} primitive@>
-primitive("pdfthread",extension,pdf_thread_node);@/
-@!@:pdf_thread_}{\.{\\pdfthread} primitive@>
-primitive("pdfstartthread",extension,pdf_start_thread_node);@/
-@!@:pdf_start_thread_}{\.{\\pdfstartthread} primitive@>
-primitive("pdfendthread",extension,pdf_end_thread_node);@/
-@!@:pdf_end_thread_}{\.{\\pdfendthread} primitive@>
-primitive("pdfsavepos",extension,pdf_save_pos_node);@/
-@!@:pdf_save_pos_}{\.{\\pdfsavepos} primitive@>
-primitive("pdfinfo",extension,pdf_info_code);@/
-@!@:pdf_info_}{\.{\\pdfinfo} primitive@>
-primitive("pdfcatalog",extension,pdf_catalog_code);@/
-@!@:pdf_catalog_}{\.{\\pdfcatalog} primitive@>
-primitive("pdfnames",extension,pdf_names_code);@/
-@!@:pdf_names_}{\.{\\pdfnames} primitive@>
-primitive("pdfincludechars",extension,pdf_include_chars_code);@/
-@!@:pdf_include_chars_}{\.{\\pdfincludechars} primitive@>
-primitive("pdffontattr",extension,pdf_font_attr_code);@/
-@!@:pdf_font_attr_}{\.{\\pdffontattr} primitive@>
-primitive("pdfmapfile",extension,pdf_map_file_code);@/
-@!@:pdf_map_file_}{\.{\\pdfmapfile} primitive@>
-primitive("pdfmapline",extension,pdf_map_line_code);@/
-@!@:pdf_map_line_}{\.{\\pdfmapline} primitive@>
-primitive("pdftrailer",extension,pdf_trailer_code);@/
-@!@:pdf_trailer_}{\.{\\pdftrailer} primitive@>
- at z
+param_base:=xmalloc_array(integer, font_max);
 
- at x [1346]
-  set_language_code:print_esc("setlanguage");
- at y
-  set_language_code:print_esc("setlanguage");
-  pdf_literal_node: print_esc("pdfliteral");
-  pdf_obj_code: print_esc("pdfobj");
-  pdf_refobj_node: print_esc("pdfrefobj");
-  pdf_xform_code: print_esc("pdfxform");
-  pdf_refxform_node: print_esc("pdfrefxform");
-  pdf_ximage_code: print_esc("pdfximage");
-  pdf_refximage_node: print_esc("pdfrefximage");
-  pdf_annot_node: print_esc("pdfannot");
-  pdf_start_link_node: print_esc("pdfstartlink");
-  pdf_end_link_node: print_esc("pdfendlink");
-  pdf_outline_code: print_esc("pdfoutline");
-  pdf_dest_node: print_esc("pdfdest");
-  pdf_thread_node: print_esc("pdfthread");
-  pdf_start_thread_node: print_esc("pdfstartthread");
-  pdf_end_thread_node: print_esc("pdfendthread");
-  pdf_save_pos_node: print_esc("pdfsavepos");
-  pdf_info_code: print_esc("pdfinfo");
-  pdf_catalog_code: print_esc("pdfcatalog");
-  pdf_names_code: print_esc("pdfnames");
-  pdf_include_chars_code: print_esc("pdfincludechars");
-  pdf_font_attr_code: print_esc("pdffontattr");
-  pdf_map_file_code: print_esc("pdfmapfile");
-  pdf_map_line_code: print_esc("pdfmapline");
-  pdf_trailer_code: print_esc("pdftrailer");
- at z
+pdf_char_used:=xmalloc_array(char_used_array,font_max);
+pdf_font_size:=xmalloc_array(scaled,font_max);
+pdf_font_num:=xmalloc_array(integer,font_max);
+pdf_font_map:=xmalloc_array(fm_entry_ptr,font_max);
+pdf_font_type:=xmalloc_array(eight_bits,font_max);
+pdf_font_attr:=xmalloc_array(str_number,font_max);
+pdf_font_blink:=xmalloc_array(internal_font_number,font_max);
+pdf_font_elink:=xmalloc_array(internal_font_number,font_max);
+pdf_font_stretch:=xmalloc_array(integer,font_max);
+pdf_font_shrink:=xmalloc_array(integer,font_max);
+pdf_font_step:=xmalloc_array(integer,font_max);
+pdf_font_expand_ratio:=xmalloc_array(integer,font_max);
+pdf_font_auto_expand:=xmalloc_array(boolean,font_max);
+pdf_font_lp_base:=xmalloc_array(integer,font_max);
+pdf_font_rp_base:=xmalloc_array(integer,font_max);
+pdf_font_ef_base:=xmalloc_array(integer,font_max);
+pdf_font_kn_bs_base:=xmalloc_array(integer, font_max);
+pdf_font_st_bs_base:=xmalloc_array(integer, font_max);
+pdf_font_sh_bs_base:=xmalloc_array(integer, font_max);
+pdf_font_kn_bc_base:=xmalloc_array(integer, font_max);
+pdf_font_kn_ac_base:=xmalloc_array(integer, font_max);
+vf_packet_base:=xmalloc_array(integer,font_max);
+vf_default_font:=xmalloc_array(internal_font_number,font_max);
+vf_local_font_num:=xmalloc_array(internal_font_number,font_max);
+vf_e_fnts:=xmalloc_array(integer,font_max);
+vf_i_fnts:=xmalloc_array(internal_font_number,font_max);
 
- at x [1348]
-immediate_code:@<Implement \.{\\immediate}@>;
-set_language_code:@<Implement \.{\\setlanguage}@>;
- at y
-immediate_code:@<Implement \.{\\immediate}@>;
-set_language_code:@<Implement \.{\\setlanguage}@>;
-pdf_literal_node: @<Implement \.{\\pdfliteral}@>;
-pdf_obj_code: @<Implement \.{\\pdfobj}@>;
-pdf_refobj_node: @<Implement \.{\\pdfrefobj}@>;
-pdf_xform_code: @<Implement \.{\\pdfxform}@>;
-pdf_refxform_node: @<Implement \.{\\pdfrefxform}@>;
-pdf_ximage_code: @<Implement \.{\\pdfximage}@>;
-pdf_refximage_node: @<Implement \.{\\pdfrefximage}@>;
-pdf_annot_node: @<Implement \.{\\pdfannot}@>;
-pdf_start_link_node: @<Implement \.{\\pdfstartlink}@>;
-pdf_end_link_node: @<Implement \.{\\pdfendlink}@>;
-pdf_outline_code: @<Implement \.{\\pdfoutline}@>;
-pdf_dest_node: @<Implement \.{\\pdfdest}@>;
-pdf_thread_node: @<Implement \.{\\pdfthread}@>;
-pdf_start_thread_node: @<Implement \.{\\pdfstartthread}@>;
-pdf_end_thread_node: @<Implement \.{\\pdfendthread}@>;
-pdf_save_pos_node: @<Implement \.{\\pdfsavepos}@>;
-pdf_info_code: @<Implement \.{\\pdfinfo}@>;
-pdf_catalog_code: @<Implement \.{\\pdfcatalog}@>;
-pdf_names_code: @<Implement \.{\\pdfnames}@>;
-pdf_include_chars_code: @<Implement \.{\\pdfincludechars}@>;
-pdf_font_attr_code: @<Implement \.{\\pdffontattr}@>;
-pdf_map_file_code: @<Implement \.{\\pdfmapfile}@>;
-pdf_map_line_code: @<Implement \.{\\pdfmapline}@>;
-pdf_trailer_code: @<Implement \.{\\pdftrailer}@>;
- at z
-
- at x [1354]
-@<Implement \.{\\special}@>=
-begin new_whatsit(special_node,write_node_size); write_stream(tail):=null;
-p:=scan_toks(false,true); write_tokens(tail):=def_ref;
-end
- at y
-@<Implement \.{\\special}@>=
-begin new_whatsit(special_node,write_node_size); write_stream(tail):=null;
-p:=scan_toks(false,true); write_tokens(tail):=def_ref;
-end
-
-@ The following macros are needed for further manipulation with whatsit nodes
-for \pdfTeX{} extensions (copying, destroying etc.)
-
- at d add_action_ref(#) == incr(pdf_action_refcount(#)) {increase count of
-references to this action}
-
- at d delete_action_ref(#) == {decrease count of references to this
-action; free it if there is no reference to this action}
-begin
-    if pdf_action_refcount(#) = null then begin
-        if pdf_action_type(#) = pdf_action_user then
-            delete_token_ref(pdf_action_user_tokens(#))
-        else begin
-            if pdf_action_file(#) <> null then
-                delete_token_ref(pdf_action_file(#));
-            if pdf_action_type(#) = pdf_action_page then
-                delete_token_ref(pdf_action_page_tokens(#))
-            else if pdf_action_named_id(#) > 0 then
-                delete_token_ref(pdf_action_id(#));
-        end;
-        free_node(#, pdf_action_size);
-    end
-    else
-        decr(pdf_action_refcount(#));
-end
-
-@ We have to check whether \.{\\pdfoutput} is set for using \pdfTeX{}
-  extensions.
-
-
-@<Declare procedures needed in |do_ext...@>=
-procedure check_pdfoutput(s: str_number);
-begin
-    if pdf_output <= 0 then begin
-        print_nl("pdfTeX error (ext1): ");
-        print(s); 
-        print(" used while \pdfoutput is not set"); 
-        succumb;
-    end;
+for font_k := font_base to font_max do begin
+    for k := 0 to 31 do
+        pdf_char_used[font_k, k] := 0;
+    pdf_font_size[font_k] := 0;
+    pdf_font_num[font_k] := 0;
+    pdf_font_map[font_k] := 0;
+    pdf_font_type[font_k] := new_font_type;
+    pdf_font_attr[font_k] := "";
+    pdf_font_blink[font_k] := null_font;
+    pdf_font_elink[font_k] := null_font;
+    pdf_font_stretch[font_k] := null_font;
+    pdf_font_shrink[font_k] := null_font;
+    pdf_font_step[font_k] := 0;
+    pdf_font_expand_ratio[font_k] := 0;
+    pdf_font_auto_expand[font_k] := false;
+    pdf_font_lp_base[font_k] := 0;
+    pdf_font_rp_base[font_k] := 0;
+    pdf_font_ef_base[font_k] := 0;
+    pdf_font_kn_bs_base[font_k] := 0;
+    pdf_font_st_bs_base[font_k] := 0;
+    pdf_font_sh_bs_base[font_k] := 0;
+    pdf_font_kn_bc_base[font_k] := 0;
+    pdf_font_kn_ac_base[font_k] := 0;
 end;
 
-procedure scan_pdf_ext_toks;
-begin
-    call_func(scan_toks(false, true)); {like \.{\\special}}
-end;
-
-@ @<Implement \.{\\pdfliteral}@>=
-begin
-    check_pdfoutput("\pdfliteral");
-    new_whatsit(pdf_literal_node, write_node_size);
-    if scan_keyword("direct") then
-        pdf_literal_direct(tail) := 1
-    else
-        pdf_literal_direct(tail) := 0;
-    scan_pdf_ext_toks;
-    pdf_literal_data(tail) := def_ref;
-end
-
-@ The \.{\\pdfobj} primitive is to create a ``raw'' object in PDF
-  output file. The object contents will be hold in memory and will be written
-  out only when the object je referenced by \.{\\pdfrefobj}. When \.{\\pdfobj}
-  is used with \.{\\immediate}, the object contents will be written out
-  immediately. Object referenced in current page are appended into
-  |pdf_obj_list|.
-
-@<Glob...@>=
-@!pdf_last_obj: integer;
-
-@ @<Implement \.{\\pdfobj}@>=
-begin
-    check_pdfoutput("\pdfobj");
-    if scan_keyword("reserveobjnum") then begin
-        incr(pdf_obj_count);
-        pdf_create_obj(obj_type_obj, pdf_obj_count);
-        pdf_last_obj := obj_ptr;
-    end
-    else begin
-        if scan_keyword("useobjnum") then begin
-            scan_int;
-            k := cur_val;
-            if (k <= 0) or (k > obj_ptr) or (obj_data_ptr(k) <> 0) then 
-                pdf_error("ext1", "invalid object number");
-        end
-        else begin
-            incr(pdf_obj_count);
-            pdf_create_obj(obj_type_obj, pdf_obj_count);
-            k := obj_ptr;
-        end;
-        obj_data_ptr(k) := pdf_get_mem(pdfmem_obj_size);
-        if scan_keyword("stream") then begin
-            obj_obj_is_stream(k) := 1;
-            if scan_keyword("attr") then begin
-                scan_pdf_ext_toks;
-                obj_obj_stream_attr(k) := def_ref;
-            end
-            else
-                obj_obj_stream_attr(k) := null;
-        end
-        else
-            obj_obj_is_stream(k) := 0;
-        if scan_keyword("file") then
-            obj_obj_is_file(k) := 1
-        else
-            obj_obj_is_file(k) := 0;
-        scan_pdf_ext_toks;
-        obj_obj_data(k) := def_ref;
-        pdf_last_obj := k;
-    end;
-end
-
-@ We need to check whether the referenced object exists.
-
-@<Declare procedures that need to be declared forward for pdftex@>=
-procedure pdf_check_obj(t, n: integer);
-var k: integer;
-begin
-    k := head_tab[t];
-    while (k <> 0) and (k <> n) do
-        k := obj_link(k);
-    if k = 0 then
-        pdf_error("ext1", "cannot find referenced object");
-end;
-
-@ @<Implement \.{\\pdfrefobj}@>=
-begin
-    check_pdfoutput("\pdfrefobj");
-    scan_int;
-    pdf_check_obj(obj_type_obj, cur_val);
-    new_whatsit(pdf_refobj_node, pdf_refobj_node_size);
-    pdf_obj_objnum(tail) := cur_val;
-end
-
-@ \.{\\pdfxform} and \.{\\pdfrefxform} are similiar to \.{\\pdfobj} and
-  \.{\\pdfrefobj}
-
-@<Glob...@>=
-@!pdf_last_xform: integer;
-
-@ @<Implement \.{\\pdfxform}@>=
-begin
-    check_pdfoutput("\pdfxform");
-    incr(pdf_xform_count);
-    pdf_create_obj(obj_type_xform, pdf_xform_count);
-    k := obj_ptr;
-    obj_data_ptr(k) := pdf_get_mem(pdfmem_xform_size);
-    if scan_keyword("attr") then begin
-        scan_pdf_ext_toks;
-        obj_xform_attr(k) := def_ref;
-    end
-    else
-        obj_xform_attr(k) := null;
-    if scan_keyword("resources") then begin
-        scan_pdf_ext_toks;
-        obj_xform_resources(k) := def_ref;
-    end
-    else
-        obj_xform_resources(k) := null;
-    scan_int;
-    if box(cur_val) = null then
-        pdf_error("ext1", "\pdfxform cannot be used with a void box");
-    obj_xform_width(k) := width(box(cur_val));
-    obj_xform_height(k) := height(box(cur_val));
-    obj_xform_depth(k) := depth(box(cur_val));
-    obj_xform_box(k) := box(cur_val); {save pointer to the box}
-    box(cur_val) := null;
-    pdf_last_xform := k;
-end
-
-@ @<Implement \.{\\pdfrefxform}@>=
-begin
-    check_pdfoutput("\pdfrefxform");
-    scan_int;
-    pdf_check_obj(obj_type_xform, cur_val);
-    new_whatsit(pdf_refxform_node, pdf_refxform_node_size);
-    pdf_xform_objnum(tail) := cur_val;
-    pdf_width(tail) := obj_xform_width(cur_val);
-    pdf_height(tail) := obj_xform_height(cur_val);
-    pdf_depth(tail) := obj_xform_depth(cur_val);
-end
-
-@ \.{\\pdfximage} and \.{\\pdfrefximage} are similiar to \.{\\pdfxform} and
-  \.{\\pdfrefxform}. As we have to scan |<rule spec>| quite often, it is better
-  have a |rule_node| that holds the most recently scanned |<rule spec>|.
-
-@<Glob...@>=
-@!pdf_last_ximage: integer;
-@!pdf_last_ximage_pages: integer;
-@!alt_rule: pointer;
-@!pdf_last_pdf_box_spec: integer;
-
-@ @<Set init...@>=
-alt_rule := null;
-
-@ @<Declare procedures needed in |do_ext...@>=
-procedure scale_image(n: integer);
-var x, y, xr, yr: integer; {size and resolution of image}
-    w, h: scaled; {indeed size corresponds to image resolution}
-    default_res: integer;
-begin
-    x := image_width(obj_ximage_data(n));
-    y := image_height(obj_ximage_data(n));
-    xr := image_x_res(obj_ximage_data(n));
-    yr := image_y_res(obj_ximage_data(n));
-    if (xr > 65535) or (yr > 65535) then begin
-        xr := 0;
-        yr := 0;
-        pdf_warning("ext1", "too large image resolution ignored", true);
-    end;
-    if (x <= 0) or (y <= 0) or (xr < 0) or (yr < 0) then
-        pdf_error("ext1", "invalid image dimensions");
-    if is_pdf_image(obj_ximage_data(n)) then begin
-        w := x;
-        h := y;
-    end
-    else begin
-        default_res := fix_int(pdf_image_resolution, 0, 65535);
-        if (default_res > 0) and ((xr = 0) or (yr = 0)) then begin
-            xr := default_res;
-            yr := default_res;
-        end;
-        if is_running(obj_ximage_width(n)) and 
-           is_running(obj_ximage_height(n)) then
-        begin
-            if (xr > 0) and (yr > 0) then begin
-                w := ext_xn_over_d(one_hundred_inch, x, 100*xr);
-                h := ext_xn_over_d(one_hundred_inch, y, 100*yr);
-            end
-            else begin
-                w := ext_xn_over_d(one_hundred_inch, x, 7200);
-                h := ext_xn_over_d(one_hundred_inch, y, 7200);
-            end;
-        end;
-    end;
-    if is_running(obj_ximage_width(n)) and is_running(obj_ximage_height(n)) and
-        is_running(obj_ximage_depth(n)) then begin
-        obj_ximage_width(n) := w;
-        obj_ximage_height(n) := h;
-        obj_ximage_depth(n) := 0;
-    end
-    else if is_running(obj_ximage_width(n)) then begin
-        {image depth or height is explicitly specified}
-        if is_running(obj_ximage_height(n)) then begin
-            {image depth is explicitly specified}
-            obj_ximage_width(n) := ext_xn_over_d(h, x, y);
-            obj_ximage_height(n) := h - obj_ximage_depth(n);
-        end
-        else if is_running(obj_ximage_depth(n)) then begin
-            {image height is explicitly specified}
-            obj_ximage_width(n) := ext_xn_over_d(obj_ximage_height(n), x, y);
-            obj_ximage_depth(n) := 0;
-        end
-        else begin
-            {both image depth and height are explicitly specified}
-            obj_ximage_width(n) := ext_xn_over_d(obj_ximage_height(n) + 
-                                                 obj_ximage_depth(n), x, y);
-        end;
-    end
-    else begin
-        {image width is explicitly specified}
-        if is_running(obj_ximage_height(n)) and 
-           is_running(obj_ximage_depth(n)) then begin
-            {both image depth and height are not specified}
-            obj_ximage_height(n) := ext_xn_over_d(obj_ximage_width(n), y, x);
-            obj_ximage_depth(n) := 0;
-        end
-        {image depth is explicitly specified}
-        else if is_running(obj_ximage_height(n)) then begin
-            obj_ximage_height(n) := 
-                ext_xn_over_d(obj_ximage_width(n), y, x) - obj_ximage_depth(n);
-        end
-        {image height is explicitly specified}
-        else if is_running(obj_ximage_depth(n)) then begin
-            obj_ximage_depth(n) := 0;
-        end
-        {both image depth and height are explicitly specified}
-        else
-            do_nothing;
-    end;
-end;
-
-procedure scan_pdf_box_spec; {scans pdf-box-spec to |pdf_last_pdf_box_spec|}
-begin 
-    pdf_last_pdf_box_spec := pdf_pdf_box_spec_crop; 
-    
-    if scan_keyword("mediabox") then
-        pdf_last_pdf_box_spec := pdf_pdf_box_spec_media
-    else if scan_keyword("cropbox") then 
-        pdf_last_pdf_box_spec := pdf_pdf_box_spec_crop
-    else if scan_keyword("bleedbox") then 
-        pdf_last_pdf_box_spec := pdf_pdf_box_spec_bleed
-    else if scan_keyword("trimbox") then 
-        pdf_last_pdf_box_spec := pdf_pdf_box_spec_trim
-    else if scan_keyword("artbox") then 
-        pdf_last_pdf_box_spec := pdf_pdf_box_spec_art
-end;
-
-procedure scan_alt_rule; {scans rule spec to |alt_rule|}
-label reswitch;
-begin 
-    if alt_rule = null then
-        alt_rule := new_rule;
-    width(alt_rule) := null_flag;
-    height(alt_rule) := null_flag;
-    depth(alt_rule) := null_flag;
-reswitch: 
-    if scan_keyword("width") then begin
-        scan_normal_dimen;
-        width(alt_rule) := cur_val;
-        goto reswitch;
-    end;
-    if scan_keyword("height") then begin
-        scan_normal_dimen;
-        height(alt_rule) := cur_val;
-        goto reswitch;
-    end;
-    if scan_keyword("depth") then begin
-        scan_normal_dimen;
-        depth(alt_rule) := cur_val;
-        goto reswitch;
-    end;
-end;
-
-procedure scan_image;
-label reswitch;
-var p: pointer;
-    k: integer;
-    named: str_number;
-    s: str_number;
-    page, colorspace: integer;
-begin
-    incr(pdf_ximage_count);
-    pdf_create_obj(obj_type_ximage, pdf_ximage_count);
-    k := obj_ptr;
-    obj_data_ptr(k) := pdf_get_mem(pdfmem_ximage_size);
-    scan_alt_rule; {scans |<rule spec>| to |alt_rule|}
-    obj_ximage_width(k) := width(alt_rule);
-    obj_ximage_height(k) := height(alt_rule);
-    obj_ximage_depth(k) := depth(alt_rule);
-    if scan_keyword("attr") then begin
-        scan_pdf_ext_toks;
-        obj_ximage_attr(k) := def_ref;
-    end
-    else
-        obj_ximage_attr(k) := null;
-    named := 0;
-    if scan_keyword("named") then begin
-        scan_pdf_ext_toks;
-        named := tokens_to_string(def_ref);
-        delete_token_ref(def_ref);
-    end
-    else if scan_keyword("page") then begin
-        scan_int;
-        page := cur_val;
-    end
-    else
-        page := 1;
-    if scan_keyword("colorspace") then begin
-        scan_int;
-        colorspace := cur_val;
-    end
-    else
-        colorspace := 0;
-    scan_pdf_box_spec; {scans pdf-box-spec to |pdf_last_pdf_box_spec|}
-    scan_pdf_ext_toks;
-    s := tokens_to_string(def_ref);
-    delete_token_ref(def_ref);
-    if pdf_option_always_use_pdfpagebox > 0 then begin
-        print_err("pdfTeX warning (image inclusion): ");
-        print ("\pdfoptionalwaysusepdfpagebox is in use ("); 
-        print_int (pdf_option_always_use_pdfpagebox); 
-        print (")");
-        print_ln;
-    end;
-    obj_ximage_data(k) := read_image(s, page, named, colorspace,
-                                     pdf_option_pdf_minor_version, 
-                                     pdf_option_always_use_pdfpagebox,
-                                     pdf_option_pdf_inclusion_errorlevel);
-    if named <> 0 then flush_str(named);
-    flush_str(s);
-    scale_image(k);
-    pdf_last_ximage := k;
-    pdf_last_ximage_pages := image_pages(obj_ximage_data(k));
-end;
-
-@ @<Implement \.{\\pdfximage}@>=
-begin
-    check_pdfoutput("\pdfximage");
-    check_and_set_pdfoptionpdfminorversion;
-    scan_image;
-end
-
-@ @<Implement \.{\\pdfrefximage}@>=
-begin
-    check_pdfoutput("\pdfrefximage");
-    scan_int;
-    pdf_check_obj(obj_type_ximage, cur_val);
-    new_whatsit(pdf_refximage_node, pdf_refximage_node_size);
-    pdf_ximage_objnum(tail) := cur_val;
-    pdf_width(tail) := obj_ximage_width(cur_val);
-    pdf_height(tail) := obj_ximage_height(cur_val);
-    pdf_depth(tail) := obj_ximage_depth(cur_val);
-end
-
-@ The following function finds object with identifier |i| and type |t|. 
-  |i < 0| indicates that |-i| should be treated as a string number. If no
-  such object exists then it will be created. This function is used mainly to
-  find destination for link annotations and outlines; however it is also used
-  in |pdf_ship_out| (to check whether a Page object already exists) so we need
-  to declare it together with subroutines needed in |pdf_hlist_out| and
-  |pdf_vlist_out|.
-
-@<Declare procedures that need to be declared forward for pdftex@>=
-function find_obj(t, i: integer; byname: boolean): integer;
-begin
-    find_obj := avl_find_obj(t, i, byname);
-end;
-
-procedure flush_str(s: str_number); {flush a string if possible}
-begin
-    if flushable(s) then
-        flush_string;
-end;
-
-function get_obj(t, i: integer; byname: boolean): integer; 
-var r: integer;
-    s: str_number;
-begin
-    if byname > 0 then begin
-        s := tokens_to_string(i);
-        r := find_obj(t, s, true);
-    end
-    else begin
-        s := 0;
-        r := find_obj(t, i, false);
-    end;
-    if r = 0 then begin
-        if byname > 0 then begin
-            pdf_create_obj(t, -s);
-            s := 0;
-        end
-        else
-            pdf_create_obj(t, i);
-        r := obj_ptr;
-        if t = obj_type_dest then
-            obj_dest_ptr(r) := null;
-    end;
-    if s <> 0 then
-        flush_str(s);
-    get_obj := r;
-end;
-
-@ @<Declare procedures needed in |do_ext...@>=
-function scan_action: pointer; {read an action specification}
-var p, t: integer;
-    s: str_number;
-begin
-    p := get_node(pdf_action_size);
-    scan_action := p;
-    pdf_action_file(p) := null;
-    pdf_action_refcount(p) := null;
-    if scan_keyword("user") then
-        pdf_action_type(p) := pdf_action_user
-    else if scan_keyword("goto") then
-        pdf_action_type(p) := pdf_action_goto
-    else if scan_keyword("thread") then
-        pdf_action_type(p) := pdf_action_thread
-    else
-        pdf_error("ext1", "action type missing");
-    if pdf_action_type(p) = pdf_action_user then begin
-        scan_pdf_ext_toks;
-        pdf_action_user_tokens(p) := def_ref;
-        return;
-    end;
-    if scan_keyword("file") then begin
-        scan_pdf_ext_toks;
-        pdf_action_file(p) := def_ref;
-    end;
-    if scan_keyword("page") then begin
-        if pdf_action_type(p) <> pdf_action_goto then
-            pdf_error("ext1", "only GoTo action can be used with `page'");
-        pdf_action_type(p) := pdf_action_page;
-        scan_int;
-        if cur_val <= 0 then
-            pdf_error("ext1", "page number must be positive");
-        pdf_action_id(p) := cur_val;
-        pdf_action_named_id(p) := 0;
-        scan_pdf_ext_toks;
-        pdf_action_page_tokens(p) := def_ref;
-    end
-    else if scan_keyword("name") then begin
-        scan_pdf_ext_toks;
-        pdf_action_named_id(p) := 1;
-        pdf_action_id(p) := def_ref;
-    end
-    else if scan_keyword("num") then begin
-        if (pdf_action_type(p) = pdf_action_goto) and
-            (pdf_action_file(p) <> null) then
-            pdf_error("ext1",
-                "`goto' option cannot be used with both `file' and `num'");
-        scan_int;
-        if cur_val <= 0 then
-            pdf_error("ext1", "num identifier must be positive");
-        pdf_action_named_id(p) := 0;
-        pdf_action_id(p) := cur_val;
-    end
-    else
-        pdf_error("ext1", "identifier type missing");
-    if scan_keyword("newwindow") then
-        pdf_action_new_window(p) := 1
-    else if scan_keyword("nonewwindow") then
-        pdf_action_new_window(p) := 2
-    else
-        pdf_action_new_window(p) := 0;
-    if (pdf_action_new_window(p) > 0) and
-        (((pdf_action_type(p) <> pdf_action_goto) and
-          (pdf_action_type(p) <> pdf_action_page)) or
-         (pdf_action_file(p) = null)) then
-            pdf_error("ext1",
-                "`newwindow'/`nonewwindow' must be used with `goto' and `file' option");
-end;
-
-procedure new_annot_whatsit(w, s: small_number); {create a new whatsit node for
-annotation}
-var p: pointer;
-begin
-    new_whatsit(w, s);
-    scan_alt_rule; {scans |<rule spec>| to |alt_rule|}
-    pdf_width(tail) := width(alt_rule);
-    pdf_height(tail) := height(alt_rule);
-    pdf_depth(tail) := depth(alt_rule);
-    if (w = pdf_start_link_node) then begin
-        if scan_keyword("attr") then begin
-            scan_pdf_ext_toks;
-            pdf_link_attr(tail) := def_ref;
-        end
-        else
-            pdf_link_attr(tail) := null;
-    end;
-    if (w = pdf_thread_node) or (w = pdf_start_thread_node) then begin
-        if scan_keyword("attr") then begin
-            scan_pdf_ext_toks;
-            pdf_thread_attr(tail) := def_ref;
-        end
-        else
-            pdf_thread_attr(tail) := null;
-    end;
-end;
-
-@ @<Glob...@>=
-@!pdf_last_annot: integer;
-
-@ @<Implement \.{\\pdfannot}@>=
-begin
-    check_pdfoutput("\pdfannot");
-    if scan_keyword("reserveobjnum") then
-        pdf_last_annot := pdf_new_objnum
-    else begin
-        if scan_keyword("useobjnum") then begin
-            scan_int;
-            k := cur_val;
-            if (k <= 0) or (k > obj_ptr) or (obj_annot_ptr(k) <> 0) then 
-                pdf_error("ext1", "invalid object number");
-        end
-        else
-            k := pdf_new_objnum;
-        new_annot_whatsit(pdf_annot_node, pdf_annot_node_size);
-        pdf_annot_objnum(tail) := k;
-        scan_pdf_ext_toks;
-        pdf_annot_data(tail) := def_ref;
-        pdf_last_annot := k;
-    end
-end
-
-@ @<Implement \.{\\pdfstartlink}@>=
-begin
-    check_pdfoutput("\pdfstartlink");
-    if abs(mode) = vmode then
-        pdf_error("ext1", "\pdfstartlink cannot be used in vertical mode");
-    new_annot_whatsit(pdf_start_link_node, pdf_annot_node_size);
-    pdf_link_action(tail) := scan_action;
-end
-
-@ @<Implement \.{\\pdfendlink}@>=
-begin
-    check_pdfoutput("\pdfendlink");
-    if abs(mode) = vmode then
-        pdf_error("ext1", "\pdfendlink cannot be used in vertical mode");
-    new_whatsit(pdf_end_link_node, small_node_size);
-end
-
-@ @<Declare procedures needed in |do_ext...@>=
-function outline_list_count(p: pointer): integer; {return number of outline
-entries in the same level with |p|}
-var k: integer;
-begin
-    k := 1;
-    while obj_outline_prev(p) <> 0 do begin
-        incr(k);
-        p := obj_outline_prev(p);
-    end;
-    outline_list_count := k;
-end;
-
-@ @<Implement \.{\\pdfoutline}@>=
-begin
-    check_pdfoutput("\pdfoutline");
-    if scan_keyword("attr") then begin
-        scan_pdf_ext_toks;
-        r := def_ref;
-    end
-    else
-        r := 0;
-    p := scan_action;
-    if scan_keyword("count") then begin
-        scan_int;
-        i := cur_val;
-    end
-    else
-        i := 0;
-    scan_pdf_ext_toks;
-    q := def_ref;
-    pdf_new_obj(obj_type_others, 0);
-    j := obj_ptr;
-    write_action(p);
-    pdf_end_obj;
-    delete_action_ref(p);
-    pdf_create_obj(obj_type_outline, 0);
-    k := obj_ptr;
-    obj_outline_ptr(k) := pdf_get_mem(pdfmem_outline_size);
-    obj_outline_action_objnum(k) := j;
-    obj_outline_count(k) := i;
-    pdf_new_obj(obj_type_others, 0);
-    pdf_print_str_ln(tokens_to_string(q));
-    flush_str(last_tokens_string);
-    delete_token_ref(q);
-    pdf_end_obj;
-    obj_outline_title(k) := obj_ptr;
-    obj_outline_prev(k) := 0;
-    obj_outline_next(k) := 0;
-    obj_outline_first(k) := 0;
-    obj_outline_last(k) := 0;
-    obj_outline_parent(k) := pdf_parent_outline;
-    obj_outline_attr(k) := r;
-    if pdf_first_outline = 0 then
-        pdf_first_outline :=  k;
-    if pdf_last_outline = 0 then begin
-        if pdf_parent_outline <> 0 then
-            obj_outline_first(pdf_parent_outline) := k;
-    end
-    else begin
-        obj_outline_next(pdf_last_outline) := k;
-        obj_outline_prev(k) := pdf_last_outline;
-    end;
-    pdf_last_outline := k;
-    if obj_outline_count(k) <> 0 then begin
-        pdf_parent_outline := k;
-        pdf_last_outline := 0;
-    end
-    else if (pdf_parent_outline <> 0) and
-    (outline_list_count(k) = abs(obj_outline_count(pdf_parent_outline))) then
-    begin
-        j := pdf_last_outline;
-        repeat
-            obj_outline_last(pdf_parent_outline) := j;
-            j := pdf_parent_outline;
-            pdf_parent_outline := obj_outline_parent(pdf_parent_outline);
-        until (pdf_parent_outline = 0) or
-        (outline_list_count(j) < abs(obj_outline_count(pdf_parent_outline)));
-        if pdf_parent_outline = 0 then
-            pdf_last_outline := pdf_first_outline
-        else
-            pdf_last_outline := obj_outline_first(pdf_parent_outline);
-        while obj_outline_next(pdf_last_outline) <> 0 do
-            pdf_last_outline := obj_outline_next(pdf_last_outline);
-    end;
-end
-
-@ When a destination is created we need to check whether another destination
-with the same identifier already exists and give a warning if needed.
-
-@<Declare procedures needed in |pdf_hlist_out|, |pdf_vlist_out|@>=
-procedure warn_dest_dup(id: integer; byname: small_number; s1, s2: str_number);
-begin
-    pdf_warning(s1, "destination with the same identifier (", false);
-    if byname > 0 then begin
-        print("name");
-        print_mark(id);
-    end
-    else begin
-        print("num");
-        print_int(id);
-    end;
-    print(") ");
-    print(s2);
-    print_ln;
-    show_context;
-end;
-
-@ Notice that |scan_keyword| doesn't care if two words have same prefix; so
-we should be careful when scan keywords with same prefix. The main rule: if
-there are two or more keywords with the same prefix, then always test in
-order from the longest one to the shortest one. 
-
-@<Implement \.{\\pdfdest}@>=
-begin
-    check_pdfoutput("\pdfdest");
-    q := tail;
-    new_whatsit(pdf_dest_node, pdf_dest_node_size);
-    if scan_keyword("num") then begin
-        scan_int;
-        if cur_val <= 0 then
-            pdf_error("ext1", "num identifier must be positive");
-        if cur_val > max_halfword then
-            pdf_error("ext1", "number too big");
-        pdf_dest_id(tail) := cur_val;
-        pdf_dest_named_id(tail) := 0;
-    end
-    else if scan_keyword("name") then begin
-        scan_pdf_ext_toks;
-        pdf_dest_id(tail) := def_ref;
-        pdf_dest_named_id(tail) := 1;
-    end
-    else
-        pdf_error("ext1", "identifier type missing");
-    if scan_keyword("xyz") then begin
-        pdf_dest_type(tail) := pdf_dest_xyz;
-        if scan_keyword("zoom") then begin
-            scan_int;
-            if cur_val > max_halfword then
-                pdf_error("ext1", "number too big");
-            pdf_dest_xyz_zoom(tail) := cur_val;
-        end
-        else
-            pdf_dest_xyz_zoom(tail) := null;
-    end
-    else if scan_keyword("fitbh") then
-        pdf_dest_type(tail) := pdf_dest_fitbh
-    else if scan_keyword("fitbv") then
-        pdf_dest_type(tail) := pdf_dest_fitbv
-    else if scan_keyword("fitb") then
-        pdf_dest_type(tail) := pdf_dest_fitb
-    else if scan_keyword("fith") then
-        pdf_dest_type(tail) := pdf_dest_fith
-    else if scan_keyword("fitv") then
-        pdf_dest_type(tail) := pdf_dest_fitv
-    else if scan_keyword("fitr") then
-        pdf_dest_type(tail) := pdf_dest_fitr
-    else if scan_keyword("fit") then
-        pdf_dest_type(tail) := pdf_dest_fit
-    else
-        pdf_error("ext1", "destination type missing");
-    if pdf_dest_type(tail) = pdf_dest_fitr then begin
-        scan_alt_rule; {scans |<rule spec>| to |alt_rule|}
-        pdf_width(tail) := width(alt_rule);
-        pdf_height(tail) := height(alt_rule);
-        pdf_depth(tail) := depth(alt_rule);
-    end;
-    if pdf_dest_named_id(tail) <> 0 then begin
-        i := tokens_to_string(pdf_dest_id(tail));
-        k := find_obj(obj_type_dest, i, true);
-        flush_str(i);
-    end
-    else
-        k := find_obj(obj_type_dest, pdf_dest_id(tail), false);
-    if (k <> 0) and (obj_dest_ptr(k) <> null) then begin
-        warn_dest_dup(pdf_dest_id(tail), pdf_dest_named_id(tail),
-                      "ext4", "has been already used, duplicate ignored");
-        flush_node_list(tail);
-        tail := q;
-        link(q) := null;
-    end;
-end
-
-@ @<Declare procedures needed in |do_ext...@>=
-procedure scan_thread_id;
-begin
-    if scan_keyword("num") then begin
-        scan_int;
-        if cur_val <= 0 then
-            pdf_error("ext1", "num identifier must be positive");
-        if cur_val > max_halfword then
-            pdf_error("ext1", "number too big");
-        pdf_thread_id(tail) := cur_val;
-        pdf_thread_named_id(tail) := 0;
-    end
-    else if scan_keyword("name") then begin
-        scan_pdf_ext_toks;
-        pdf_thread_id(tail) := def_ref;
-        pdf_thread_named_id(tail) := 1;
-    end
-    else
-        pdf_error("ext1", "identifier type missing");
-end;
-
-@ @<Implement \.{\\pdfthread}@>=
-begin
-    check_pdfoutput("\pdfthread");
-    new_annot_whatsit(pdf_thread_node, pdf_thread_node_size);
-    scan_thread_id;
-end
-
-@ @<Implement \.{\\pdfstartthread}@>=
-begin
-    check_pdfoutput("\pdfstartthread");
-    new_annot_whatsit(pdf_start_thread_node, pdf_thread_node_size);
-    scan_thread_id;
-end
-
-@ @<Implement \.{\\pdfendthread}@>=
-begin
-    check_pdfoutput("\pdfendthread");
-    new_whatsit(pdf_end_thread_node, small_node_size);
-end
-
-@ @<Glob...@>=
-@!pdf_last_x_pos: integer;
-@!pdf_last_y_pos: integer;
-
-@ @<Implement \.{\\pdfsavepos}@>=
-begin
-    check_pdfoutput("\pdfsavepos");
-    new_whatsit(pdf_save_pos_node, small_node_size);
-end
-
-@ To implement primitives as \.{\\pdfinfo}, \.{\\pdfcatalog} or
-\.{\\pdfnames} we need to concatenate tokens lists.
-
-@<Declare procedures needed in |do_ext...@>=
-function concat_tokens(q, r: pointer): pointer; {concat |q| and |r| and
-returns the result tokens list}
-var p: pointer;
-begin
-    if q = null then begin
-        concat_tokens := r;
-        return;
-    end;
-    p := q;
-    while link(p) <> null do
-        p := link(p);
-    link(p) := link(r);
-    free_avail(r);
-    concat_tokens := q;
-end;
-
-@ @<Implement \.{\\pdfinfo}@>=
-begin
-    check_pdfoutput("\pdfinfo");
-    scan_pdf_ext_toks;
-    pdf_info_toks := concat_tokens(pdf_info_toks, def_ref);
-end
-
-@ @<Implement \.{\\pdfcatalog}@>=
-begin
-    check_pdfoutput("\pdfcatalog");
-    scan_pdf_ext_toks;
-    pdf_catalog_toks := concat_tokens(pdf_catalog_toks, def_ref);
-    if scan_keyword("openaction") then
-        if pdf_catalog_openaction <> 0 then
-            pdf_error("ext1", "duplicate of openaction")
-        else begin
-            p := scan_action;
-            pdf_new_obj(obj_type_others, 0);
-            pdf_catalog_openaction := obj_ptr;
-            write_action(p);
-            pdf_end_obj;
-            delete_action_ref(p);
-        end;
-end
-
-@ @<Implement \.{\\pdfnames}@>=
-begin
-    check_pdfoutput("\pdfnames");
-    scan_pdf_ext_toks;
-    pdf_names_toks := concat_tokens(pdf_names_toks, def_ref);
-end
-
-@ @<Implement \.{\\pdftrailer}@>=
-begin
-    check_pdfoutput("\pdftrailer");
-    scan_pdf_ext_toks;
-    pdf_trailer_toks := concat_tokens(pdf_trailer_toks, def_ref);
-end
-
-
-@ The following subroutines are about PDF-specific font issues.
-
-@<Declare procedures needed in |do_ext...@>=
-procedure pdf_include_chars; 
-var s: str_number;
-    k: pool_pointer; {running indices}
-    f: internal_font_number;
-begin
-    scan_font_ident;
-    f := cur_val;
-    if f = null_font then
-        pdf_error("font", "invalid font identifier");
-    pdf_check_vf(f);
-    if not font_used[f] then
-        pdf_init_font(f);
-    scan_pdf_ext_toks;
-    s := tokens_to_string(def_ref);
-    delete_token_ref(def_ref);
-    k := str_start[s];
-    while k < str_start[s + 1] do begin
-       pdf_mark_char(f, str_pool[k]);
-       incr(k);
-    end;
-    flush_str(s);
-end;
-
-
-@ @<Implement \.{\\pdfincludechars}@>= 
-begin
-    check_pdfoutput("\pdfincludechars");
-    pdf_include_chars;
-end
-
-@ @<Implement \.{\\pdffontattr}@>= 
-begin
-    check_pdfoutput("\pdffontattr");
-    scan_font_ident;
-    k := cur_val;
-    if k = null_font then
-        pdf_error("font", "invalid font identifier");
-    scan_pdf_ext_toks;
-    pdf_font_attr[k] := tokens_to_string(def_ref);
-end
-
-@ @<Implement \.{\\pdfmapfile}@>= 
-begin
-    check_pdfoutput("\pdfmapfile");
-    scan_pdf_ext_toks;
-    pdfmapfile(def_ref);
-    delete_token_ref(def_ref);
-end
-
-@ @<Implement \.{\\pdfmapline}@>=
-begin
-    check_pdfoutput("\pdfmapline");
-    scan_pdf_ext_toks;
-    pdfmapline(def_ref);
-    delete_token_ref(def_ref);
-end
-
-@ The following function are needed for outputing article thread.
-
-@<Declare procedures needed in |do_ext...@>=
-procedure thread_title(thread: integer);
-begin
-    pdf_print("/Title (");
-    if obj_info(thread) < 0 then
-        pdf_print(-obj_info(thread))
-    else
-        pdf_print_int(obj_info(thread));
-    pdf_print_ln(")");
-end;
-
-procedure pdf_fix_thread(thread: integer);
-var a: pointer;
-begin
-    pdf_warning("thread", "destination ", false);
-    if obj_info(thread) < 0 then begin
-        print("name{");
-        print(-obj_info(thread));
-        print("}");
-    end
-    else begin
-        print("num");
-        print_int(obj_info(thread));
-    end;
-    print(" has been referenced but does not exist, replaced by a fixed one");
-    print_ln; print_ln;
-    pdf_new_dict(obj_type_others, 0);
-    a := obj_ptr;
-    pdf_indirect_ln("T", thread);
-    pdf_indirect_ln("V", a);
-    pdf_indirect_ln("N", a);
-    pdf_indirect_ln("P", head_tab[obj_type_page]);
-    pdf_print("/R [0 0 ");
-    pdf_print_bp(pdf_page_width); pdf_out(" ");
-    pdf_print_bp(pdf_page_height);
-    pdf_print_ln("]");
-    pdf_end_dict;
-    pdf_begin_dict(thread);
-    pdf_print_ln("/I << ");
-    thread_title(thread);
-    pdf_print_ln(">>");
-    pdf_indirect_ln("F", a);
-    pdf_end_dict;
-end;
-
-procedure out_thread(thread: integer);
-var a, b, c: pointer;
-    last_attr: integer;
-begin
-    if obj_thread_first(thread) = 0 then begin
-        pdf_fix_thread(thread);
-        return;
-    end;
-    pdf_begin_dict(thread);
-    a := obj_thread_first(thread);
-    b := a;
-    last_attr := 0;
-    repeat
-        if obj_bead_attr(a) <> 0 then
-            last_attr := obj_bead_attr(a);
-        a := obj_bead_next(a);
-    until a = b;
-    if last_attr <> 0 then
-        pdf_print_ln(last_attr)
-    else begin
-        pdf_print_ln("/I << ");
-        thread_title(thread);
-        pdf_print_ln(">>");
-    end;
-    pdf_indirect_ln("F", a);
-    pdf_end_dict;
-    repeat
-        pdf_begin_dict(a);
-        if a = b then
-            pdf_indirect_ln("T", thread);
-        pdf_indirect_ln("V", obj_bead_prev(a));
-        pdf_indirect_ln("N", obj_bead_next(a));
-        pdf_indirect_ln("P", obj_bead_page(a));
-        pdf_indirect_ln("R", obj_bead_rect(a));
-        pdf_end_dict;
-        a := obj_bead_next(a);
-    until a = b;
-end;
-
-@ @<Display <rule spec> for whatsit node created by \pdfTeX@>=
-print("("); 
-print_rule_dimen(pdf_height(p)); 
-print_char("+");
-print_rule_dimen(pdf_depth(p));
-print(")x");
-print_rule_dimen(pdf_width(p))
+font_ptr:=null_font; fmem_ptr:=7;
+make_pdftex_banner;
 @z
 
- at x [1356]
-othercases print("whatsit?")
+ at x [53a.1379] l.??? -etex command line switch
+@!init if (buffer[loc]="*")and(format_ident=" (INITEX)") then
 @y
-pdf_literal_node: begin
-    print_esc("pdfliteral");
-    if pdf_literal_direct(p) > 0 then
-        print(" direct");
-    print_mark(pdf_literal_data(p));
-end;
-pdf_refobj_node: begin
-    print_esc("pdfrefobj");
-    if obj_obj_is_stream(pdf_obj_objnum(p)) > 0 then begin
-        if obj_obj_stream_attr(pdf_obj_objnum(p)) <> null then begin
-            print(" attr");
-            print_mark(obj_obj_stream_attr(pdf_obj_objnum(p)));
-        end;
-        print(" stream");
-    end;
-    if obj_obj_is_file(pdf_obj_objnum(p)) > 0 then
-        print(" file");
-    print_mark(obj_obj_data(pdf_obj_objnum(p)));
-end;
-pdf_refxform_node: begin
-    print_esc("pdfrefxform");
-    print("("); 
-    print_scaled(obj_xform_height(pdf_xform_objnum(p))); 
-    print_char("+");
-    print_scaled(obj_xform_depth(pdf_xform_objnum(p))); 
-    print(")x");
-    print_scaled(obj_xform_width(pdf_xform_objnum(p))); 
-end;
-pdf_refximage_node: begin
-    print_esc("pdfrefximage");
-    print("("); 
-    print_scaled(obj_ximage_height(pdf_ximage_objnum(p))); 
-    print_char("+");
-    print_scaled(obj_ximage_depth(pdf_ximage_objnum(p))); 
-    print(")x");
-    print_scaled(obj_ximage_width(pdf_ximage_objnum(p))); 
-end;
-pdf_annot_node: begin
-    print_esc("pdfannot");
-    @<Display <rule spec> for whatsit node created by \pdfTeX@>;
-    print_mark(pdf_annot_data(p));
-end;
-pdf_start_link_node: begin
-    print_esc("pdflink");
-    @<Display <rule spec> for whatsit node created by \pdfTeX@>;
-    if pdf_link_attr(p) <> null then begin
-        print(" attr");
-        print_mark(pdf_link_attr(p));
-    end;
-    print(" action");
-    if pdf_action_type(pdf_link_action(p)) = pdf_action_user then begin
-        print(" user");
-        print_mark(pdf_action_user_tokens(pdf_link_action(p)));
-        return;
-    end;
-    if pdf_action_file(pdf_link_action(p)) <> null then begin
-        print(" file");
-        print_mark(pdf_action_file(pdf_link_action(p)));
-    end;
-    case pdf_action_type(pdf_link_action(p)) of
-    pdf_action_goto: begin
-        if pdf_action_named_id(pdf_link_action(p)) > 0 then begin
-            print(" goto name");
-            print_mark(pdf_action_id(pdf_link_action(p)));
-        end
-        else begin
-            print(" goto num");
-            print_int(pdf_action_id(pdf_link_action(p)))
-        end;
-    end;
-    pdf_action_page: begin
-        print(" page");
-        print_int(pdf_action_id(pdf_link_action(p)));
-        print_mark(pdf_action_page_tokens(pdf_link_action(p)));
-    end;
-    pdf_action_thread: begin
-        if pdf_action_named_id(pdf_link_action(p)) > 0 then begin
-            print(" thread name");
-            print_mark(pdf_action_id(pdf_link_action(p)));
-        end
-        else begin
-            print(" thread num");
-            print_int(pdf_action_id(pdf_link_action(p)));
-        end;
-    end;
-    othercases pdf_error("displaying", "unknown action type");
-    endcases;
-end;
-pdf_end_link_node: print_esc("pdfendlink");
-pdf_dest_node: begin
-    print_esc("pdfdest");
-    if pdf_dest_named_id(p) > 0 then begin
-        print(" name");
-        print_mark(pdf_dest_id(p));
-    end
-    else begin
-        print(" num");
-        print_int(pdf_dest_id(p));
-    end;
-    print(" ");
-    case pdf_dest_type(p) of
-    pdf_dest_xyz: begin
-        print("xyz");
-        if pdf_dest_xyz_zoom(p) <> null then begin
-            print(" zoom");
-            print_int(pdf_dest_xyz_zoom(p));
-        end;
-    end;
-    pdf_dest_fitbh: print("fitbh");
-    pdf_dest_fitbv: print("fitbv");
-    pdf_dest_fitb: print("fitb");
-    pdf_dest_fith: print("fith");
-    pdf_dest_fitv: print("fitv");
-    pdf_dest_fitr: begin 
-        print("fitr");
-        @<Display <rule spec> for whatsit node created by \pdfTeX@>;
-    end;
-    pdf_dest_fit: print("fit");
-    othercases print("unknown!");
-    endcases;
-end;
-pdf_thread_node,
-pdf_start_thread_node: begin
-    if subtype(p) = pdf_thread_node then
-        print_esc("pdfthread")
-    else
-        print_esc("pdfstartthread");
-    print("("); print_rule_dimen(pdf_height(p)); print_char("+");
-    print_rule_dimen(pdf_depth(p)); print(")x");
-    print_rule_dimen(pdf_width(p));
-    if pdf_thread_attr(p) <> null then begin
-        print(" attr");
-        print_mark(pdf_thread_attr(p));
-    end;
-    if pdf_thread_named_id(p) > 0 then begin
-        print(" name");
-        print_mark(pdf_thread_id(p));
-    end
-    else begin
-        print(" num");
-        print_int(pdf_thread_id(p));
-    end;
-end;
-pdf_end_thread_node: print_esc("pdfendthread");
-pdf_save_pos_node: print_esc("pdfsavepos");
-othercases print("whatsit?")
+@!init if (etex_p or(buffer[loc]="*"))and(format_ident=" (INITEX)") then
 @z
 
- at x [1357]
-othercases confusion("ext2")
+ at x [53a.1379] l.??? -etex command line switch
+  incr(loc); eTeX_mode:=1; {enter extended mode}
 @y
-pdf_literal_node: begin
-    r := get_node(write_node_size);
-    add_token_ref(pdf_literal_data(p));
-    words := write_node_size;
-end;
-pdf_refobj_node: begin
-    r := get_node(pdf_refobj_node_size);
-    words := pdf_refobj_node_size;
-end;
-pdf_refxform_node: begin
-    r := get_node(pdf_refxform_node_size);
-    words := pdf_refxform_node_size;
-end;
-pdf_refximage_node: begin
-    r := get_node(pdf_refximage_node_size);
-    words := pdf_refximage_node_size;
-end;
-pdf_annot_node: begin
-    r := get_node(pdf_annot_node_size);
-    add_token_ref(pdf_annot_data(p));
-    words := pdf_annot_node_size;
-end;
-pdf_start_link_node: begin
-    r := get_node(pdf_annot_node_size);
-    pdf_height(r) := pdf_height(p);
-    pdf_depth(r)  := pdf_depth(p);
-    pdf_width(r)  := pdf_width(p);
-    pdf_link_attr(r) := pdf_link_attr(p);
-    if pdf_link_attr(r) <> null then
-        add_token_ref(pdf_link_attr(r));
-    pdf_link_action(r) := pdf_link_action(p);
-    add_action_ref(pdf_link_action(r));
-end;
-pdf_end_link_node:
-    r := get_node(small_node_size);
-pdf_dest_node: begin
-    r := get_node(pdf_dest_node_size);
-    if pdf_dest_named_id(p) > 0 then
-        add_token_ref(pdf_dest_id(p));
-    words := pdf_dest_node_size;
-end;
-pdf_thread_node,
-pdf_start_thread_node: begin
-    r := get_node(pdf_thread_node_size);
-    if pdf_thread_named_id(p) > 0 then
-        add_token_ref(pdf_thread_id(p));
-    if pdf_thread_attr(p) <> null then
-        add_token_ref(pdf_thread_attr(p));
-    words := pdf_thread_node_size;
-end;
-pdf_end_thread_node:
-    r := get_node(small_node_size);
-pdf_save_pos_node:
-    r := get_node(small_node_size);
-othercases confusion("ext2")
+  if (buffer[loc]="*") then incr(loc);
+  eTeX_mode:=1; {enter extended mode}
 @z
 
- at x [1358]
-othercases confusion("ext3")
+ at x [53a.1383] l.??? -etex command line switch
+@!eTeX_mode: 0..1; {identifies compatibility and extended mode}
 @y
-pdf_literal_node: begin
-    delete_token_ref(pdf_literal_data(p));
-    free_node(p, write_node_size);
-end;
-pdf_refobj_node:
-    free_node(p, pdf_refobj_node_size);
-pdf_refxform_node:
-    free_node(p, pdf_refxform_node_size);
-pdf_refximage_node:
-    free_node(p, pdf_refximage_node_size);
-pdf_annot_node: begin
-    delete_token_ref(pdf_annot_data(p));
-    free_node(p, pdf_annot_node_size);
-end;
-pdf_start_link_node: begin
-    if pdf_link_attr(p) <> null then
-        delete_token_ref(pdf_link_attr(p));
-    delete_action_ref(pdf_link_action(p));
-    free_node(p, pdf_annot_node_size);
-end;
-pdf_end_link_node:
-    free_node(p, small_node_size);
-pdf_dest_node: begin
-    if pdf_dest_named_id(p) > 0 then
-        delete_token_ref(pdf_dest_id(p));
-    free_node(p, pdf_dest_node_size);
-end;
-pdf_thread_node,
-pdf_start_thread_node: begin
-    if pdf_thread_named_id(p) > 0 then
-        delete_token_ref(pdf_thread_id(p));
-    if pdf_thread_attr(p) <> null then
-        delete_token_ref(pdf_thread_attr(p));
-    free_node(p, pdf_thread_node_size);
-end;
-pdf_end_thread_node:
-    free_node(p, small_node_size);
-pdf_save_pos_node:
-    free_node(p, small_node_size);
-othercases confusion("ext3")
+@!eTeX_mode: 0..1; {identifies compatibility and extended mode}
+@!etex_p: boolean; {was the -etex option specified}
 @z
 
- at x [1359]
-@ @<Incorporate a whatsit node into a vbox@>=do_nothing
+ at x [53a.1391] l.??? texarray
+@!eof_seen : array[1..max_in_open] of boolean; {has eof been seen?}
 @y
-@ @<Incorporate a whatsit node into a vbox@>=
-if (subtype(p) = pdf_refxform_node) or (subtype(p) = pdf_refximage_node) then
-begin x:=x+d+pdf_height(p); d:=pdf_depth(p);
-s:=0;
-if pdf_width(p)+s>w then w:=pdf_width(p)+s;
-end
+@!eof_seen : ^boolean; {has eof been seen?}
 @z
 
- at x [1360]
-@ @<Incorporate a whatsit node into an hbox@>=do_nothing
+ at x [53a.1506] l.??? texarray
+@!grp_stack : array[0..max_in_open] of save_pointer; {initial |cur_boundary|}
+@!if_stack : array[0..max_in_open] of pointer; {initial |cond_ptr|}
 @y
-@ @<Incorporate a whatsit node into an hbox@>=
-if (subtype(p) = pdf_refxform_node) or (subtype(p) = pdf_refximage_node) then
-begin x:=x+pdf_width(p);
-s:=0;
-if pdf_height(p)-s>h then h:=pdf_height(p)-s;
-if pdf_depth(p)+s>d then d:=pdf_depth(p)+s;
-end
+@!grp_stack : ^save_pointer; {initial |cur_boundary|}
+@!if_stack : ^pointer; {initial |cond_ptr|}
 @z
 
- at x [1361]
-@ @<Let |d| be the width of the whatsit |p|@>=d:=0
+ at x [53a.1587] l.??? texarray
+hyph_root:=0; hyph_start:=0;
 @y
-@ @<Let |d| be the width of the whatsit |p|@>=
-if (subtype(p) = pdf_refxform_node) or (subtype(p) = pdf_refximage_node) then
-    d := pdf_width(p)
-else
-    d := 0
 @z
 
- at x [1362]
-@<Advance \(p)past a whatsit node in the \(l)|line_break| loop@>=@+
-adv_past(cur_p)
- at y
-@<Advance \(p)past a whatsit node in the \(l)|line_break| loop@>=@+
-begin
-adv_past(cur_p);
-if (subtype(cur_p) = pdf_refxform_node) or (subtype(cur_p) = pdf_refximage_node) then
-    act_width:=act_width+pdf_width(cur_p);
-end
- at z
+ at x [54/web2c.???] l.??? needed earlier
+replacement, but always existing character |font_bc[f]|.
+@^inner loop@>
 
- at x [1364]
-@ @<Prepare to move whatsit |p| to the current page, then |goto contribute|@>=
-goto contribute
+@<Declare additional functions for ML\TeX@>=
+function effective_char(@!err_p:boolean;
 @y
-@ @<Prepare to move whatsit |p| to the current page, then |goto contribute|@>=
-begin
-  if (subtype(p) = pdf_refxform_node) or (subtype(p) = pdf_refximage_node) then
-  begin page_total:=page_total+page_depth+pdf_height(p);
-  page_depth:=pdf_depth(p);
-  end;
-  goto contribute;
-end
- at z
+replacement, but always existing character |font_bc[f]|.
+@^inner loop@>
 
- at x [1365]
-@ @<Process whatsit |p| in |vert_break| loop, |goto not_found|@>=
-goto not_found
- at y
-@ @<Process whatsit |p| in |vert_break| loop, |goto not_found|@>=
-begin
-  if (subtype(p) = pdf_refxform_node) or (subtype(p) = pdf_refximage_node) then
-  begin cur_height:=cur_height+prev_dp+pdf_height(p); prev_dp:=pdf_depth(p);
-  end;
-  goto not_found;
-end
+@<Declare \eTeX\ procedures for sc...@>=
+function effective_char(@!err_p:boolean;
 @z
 
- at x [1375]
-@<Implement \.{\\immediate}@>=
-begin get_x_token;
-if (cur_cmd=extension)and(cur_chr<=close_node) then
-  begin p:=tail; do_extension; {append a whatsit node}
-  out_what(tail); {do the action immediately}
-  flush_node_list(tail); tail:=p; link(p):=null;
-  end
-else back_input;
-end
- at y
-@<Implement \.{\\immediate}@>=
-begin get_x_token;
-if cur_cmd=extension then begin
-    if cur_chr<=close_node then
-      begin p:=tail; do_extension; {append a whatsit node}
-      out_what(tail); {do the action immediately}
-      flush_node_list(tail); tail:=p; link(p):=null;
-      end
-    else case cur_chr of
-        pdf_obj_code: begin
-            do_extension; {scan object and set |pdf_last_obj|}
-            if obj_data_ptr(pdf_last_obj) = 0 then {this object has not been initialized yet}
-                pdf_error("ext1", "`\pdfobj reserveobjnum' cannot be used with \immediate");
-            pdf_write_obj(pdf_last_obj);
-        end;
-        pdf_xform_code: begin
-            do_extension; {scan form and set |pdf_last_xform|}
-            pdf_cur_form := pdf_last_xform;
-            pdf_ship_out(obj_xform_box(pdf_last_xform), false);
-        end;
-        pdf_ximage_code: begin
-            do_extension; {scan image and set |pdf_last_ximage|}
-            pdf_write_image(pdf_last_ximage);
-        end;
-    endcases;
-end
-else
-    back_input;
-end
- at z
-
- at x [1378]
-@ @<Finish the extensions@>=
-for k:=0 to 15 do if write_open[k] then a_close(write_file[k])
- at y
-@ @<Finish the extensions@>=
-for k:=0 to 15 do if write_open[k] then a_close(write_file[k])
-
-@ Shipping out PDF marks.
-
-@<Types...@>=
-dest_name_entry = record
-    objname: str_number; {destination name}
-    objnum: integer; {destination object number}
-end;
-
-@ @<Glob...@>=
-@!cur_page_width: scaled; {width of page being shipped}
-@!cur_page_height: scaled; {height of page being shipped}
-@!cur_h_offset: scaled; {horizontal offset of page being shipped}
-@!cur_v_offset: scaled; {vertical offset of page being shipped}
-@!pdf_obj_list: pointer; {list of objects in the current page}
-@!pdf_xform_list: pointer; {list of forms in the current page}
-@!pdf_ximage_list: pointer; {list of images in the current page}
-@!pdf_link_level: integer; {depth of nesting of box containing link annotation}
-@!last_link: pointer; {pointer to the last link annotation}
-@!pdf_link_ht, pdf_link_dp, pdf_link_wd: scaled; {dimensions of the last link
-annotation}
-@!last_thread: pointer; {pointer to the last thread}
-@!pdf_thread_ht, pdf_thread_dp, pdf_thread_wd: scaled; {dimensions of the last 
-thread}
-@!pdf_last_thread_id: halfword; {identifier of the last thread}
-@!pdf_last_thread_named_id: boolean; {is identifier of the last thread named}
-@!pdf_thread_level: integer; {depth of nesting of box containing the last thread}
-@!pdf_annot_list: pointer; {list of annotations in the current page}
-@!pdf_link_list: pointer; {list of link annotations in the current page}
-@!pdf_dest_list: pointer; {list of destinations in the current page}
-@!pdf_bead_list: pointer; {list of thread beads in the current page}
-@!pdf_obj_count: integer; {counter of objects}
-@!pdf_xform_count: integer; {counter of forms}
-@!pdf_ximage_count: integer; {counter of images}
-@!pdf_cur_form: integer; {the form being output}
-@!pdf_first_outline, pdf_last_outline, pdf_parent_outline: integer;
-@!pdf_xform_width,
-@!pdf_xform_height,
-@!pdf_xform_depth: scaled; {dimension of the current form}
-@!pdf_info_toks: pointer; {additional keys of Info dictionary}
-@!pdf_catalog_toks: pointer; {additional keys of Catalog dictionary}
-@!pdf_catalog_openaction: integer;
-@!pdf_names_toks: pointer; {additional keys of Names dictionary}
-@!pdf_dest_names_ptr: integer; {first unused position in |dest_names|}
-@!dest_names_size: integer; {maximum number of names in name tree of PDF output file}
-@!dest_names: ^dest_name_entry;
-@!image_orig_x, image_orig_y: integer; {origin of cropped pdf images}
-@!link_level_stack: pointer; {stack to save |pdf_link_level|}
-@!pdf_trailer_toks: pointer; {additional keys of Trailer dictionary}
-
-@ @<Set init...@>=
-pdf_link_level := -1;
-link_level_stack := null;
-pdf_first_outline:= 0;
-pdf_last_outline:= 0;
-pdf_parent_outline:= 0;
-pdf_obj_count := 0;
-pdf_xform_count := 0;
-pdf_ximage_count := 0;
-pdf_dest_names_ptr := 0;
-pdf_info_toks := null;
-pdf_catalog_toks := null;
-pdf_names_toks := null;
-pdf_catalog_openaction := 0;
-pdf_trailer_toks := null;
-
-@ The following procedures are needed for outputing whatsit nodes for
-pdfTeX.
-
-@<Declare procedures needed in |pdf_hlist_out|, |pdf_vlist_out|@>=
-procedure write_action(p: pointer); {write an action specification}
-var s: str_number;
-    d: integer;
-begin
-    if pdf_action_type(p) = pdf_action_user then begin
-        pdf_print_toks_ln(pdf_action_user_tokens(p));
-        return;
-    end;
-    pdf_print("<< ");
-    if pdf_action_file(p) <> null then begin
-        pdf_print("/F ");
-        s := tokens_to_string(pdf_action_file(p));
-        if (str_pool[str_start[s]] = 40) and 
-           (str_pool[str_start[s] + length(s) - 1] = 41) then
-            pdf_print(s)
-        else begin
-            pdf_print_str(s);
-        end;
-        flush_str(s);
-        pdf_print(" ");
-        if pdf_action_new_window(p) > 0 then begin
-            pdf_print("/NewWindow ");
-            if pdf_action_new_window(p) = 1 then
-                pdf_print("true ")
-            else
-                pdf_print("false ");
-        end;
-    end;
-    case pdf_action_type(p) of
-    pdf_action_page: begin
-        if pdf_action_file(p) = null then begin
-            pdf_print("/S /GoTo /D [");
-            pdf_print_int(get_obj(obj_type_page, pdf_action_id(p), false));
-            pdf_print(" 0 R");
-        end
-        else begin
-            pdf_print("/S /GoToR /D [");
-            pdf_print_int(pdf_action_id(p) - 1);
-        end;
-        pdf_out(" ");
-        pdf_print(tokens_to_string(pdf_action_page_tokens(p)));
-        flush_str(last_tokens_string);
-        pdf_out("]");
-    end;
-    pdf_action_goto: begin
-        if pdf_action_file(p) = null then begin
-            pdf_print("/S /GoTo ");
-            d := get_obj(obj_type_dest, pdf_action_id(p), 
-                         pdf_action_named_id(p));
-        end
-        else
-            pdf_print("/S /GoToR ");
-        if pdf_action_named_id(p) > 0 then begin
-            pdf_str_entry("D", tokens_to_string(pdf_action_id(p)));
-            flush_str(last_tokens_string);
-        end
-        else if pdf_action_file(p) = null then
-            pdf_indirect("D", d)
-        else
-            pdf_error("ext4", "`goto' option cannot be used with both `file' and `num'");
-    end;
-    pdf_action_thread: begin
-        pdf_print("/S /Thread ");
-        if pdf_action_file(p) = null then
-            d := get_obj(obj_type_thread, pdf_action_id(p), 
-                         pdf_action_named_id(p));
-        if pdf_action_named_id(p) > 0 then begin
-            pdf_str_entry("D", tokens_to_string(pdf_action_id(p)));
-            flush_str(last_tokens_string);
-        end
-        else if pdf_action_file(p) = null then
-            pdf_indirect("D", d)
-        else
-            pdf_int_entry("D", pdf_action_id(p));
-    end;
-    endcases;
-    pdf_print_ln(" >>");
-end;
-
-procedure set_rect_dimens(p, parent_box: pointer; x, y, w, h, d, margin: scaled);
-begin
-    pdf_left(p) := cur_h;
-    if is_running(w) then
-        pdf_right(p) := x + width(parent_box)
-    else
-        pdf_right(p) := cur_h + w;
-    if is_running(h) then
-        pdf_top(p) := y - height(parent_box)
-    else
-        pdf_top(p) := cur_v - h;
-    if is_running(d) then
-        pdf_bottom(p) := y  + depth(parent_box)
-    else
-        pdf_bottom(p) := cur_v + d;
-    pdf_left(p)   := pdf_left(p)   - margin;
-    pdf_top(p)    := pdf_top(p)    - margin;
-    pdf_right(p)  := pdf_right(p)  + margin;
-    pdf_bottom(p) := pdf_bottom(p) + margin;
-end;
-
-procedure do_annot(p, parent_box: pointer; x, y: scaled);
-begin
-    if not is_shipping_page then
-        pdf_error("ext4", "annotations cannot be inside an XForm");
-    if doing_leaders then
-        return;
-    set_rect_dimens(p, parent_box, x, y, 
-                    pdf_width(p), pdf_height(p), pdf_depth(p), 0);
-    obj_annot_ptr(pdf_annot_objnum(p)) := p;
-    pdf_append_list(pdf_annot_objnum(p))(pdf_annot_list);
-end;
-
-@ To implement nesting link annotations, we need a stack to save box testing
-level of each link that has been broken. Each stack entry holds the
-box nesting level and pointer the whatsit node created for
-corresponding \.{\\pdfstartlink}.
-
- at d link_level(#) == info(#)
- at d link_ptr(#) == info(# + 1)
-
-@<Declare procedures needed in |pdf_hlist_out|, |pdf_vlist_out|@>=
-procedure save_link_level(l: pointer);
-var p, r: pointer;
-begin
-    pdf_link_level := cur_s;
-    r := copy_node_list(l);
-    pdf_link_wd := pdf_width(r);
-    pdf_link_ht := pdf_height(r);
-    pdf_link_dp := pdf_depth(r);
-    p := get_node(small_node_size);
-    link_level(p) := pdf_link_level;
-    link_ptr(p) := r;
-    link(p) := link_level_stack;
-    link_level_stack := p;
-end;
-
-procedure do_link(p, parent_box: pointer; x, y: scaled);
-begin
-    if not is_shipping_page then
-        pdf_error("ext4", "link annotations cannot be inside an XForm");
-    if type(parent_box) <> hlist_node then
-        pdf_error("ext4", "link annotations can be inside hbox only");
-    save_link_level(p);
-    set_rect_dimens(p, parent_box, x, y, 
-                    pdf_link_wd, pdf_link_ht, pdf_link_dp, pdf_link_margin);
-    last_link := p;
-    pdf_create_obj(obj_type_others, 0);
-    obj_annot_ptr(obj_ptr) := p;
-    pdf_append_list(obj_ptr)(pdf_link_list);
-end;
-
-procedure restore_link_level;
-var p, r: pointer;
-begin
-    if link_level_stack = null then
-        pdf_error("ext4", "invalid stack of link nesting level");
-    p := link_level_stack;
-    link_level_stack := link(p);
-    r := link_ptr(p);
-    flush_node_list(r);
-    free_node(p, small_node_size);
-    p := link_level_stack;
-    if p = null then
-        pdf_link_level := -1
-    else begin
-        pdf_link_level := link_level(p);
-        r := link_ptr(p);
-        pdf_link_wd := pdf_width(r);
-        pdf_link_ht := pdf_height(r);
-        pdf_link_dp := pdf_depth(r);
-    end;
-end;
-
-procedure end_link;
-begin
-    if pdf_link_level <> cur_s then
-        pdf_error("ext4", "\pdfendlink ended up in different nesting level than \pdfstartlink");
-    if is_running(pdf_link_wd) and (last_link <> null) then
-        pdf_right(last_link) := cur_h + pdf_link_margin;
-    restore_link_level;
-    last_link := null;
-end;
-
-@ For ``running'' annotations we must append a new node when the end of
-annotation is in other box than its start. The new created node is identical to
-corresponding whatsit node representing the start of annotation,  but its
-|info| field is |null|. We set |info| field just before destroying the node, in 
-order to use |flush_node_list| to do the job.
-
-@<Declare procedures needed in |pdf_hlist_out|, |pdf_vlist_out|@>=
-procedure append_link(parent_box: pointer; x, y: scaled); {append a new
-|pdf_start_link_node| to |pdf_link_list| and update |last_link|}
-var p, r: integer;
-begin
-    if type(parent_box) <> hlist_node then
-        pdf_error("ext4", "link annotations can be inside hbox only");
-    r := copy_node_list(link_ptr(link_level_stack)); {copy link node to |r|}
-    info(r) := max_halfword; {mark that this node is not a whatsit node}
-    link(r) := null; {this node will be destroyed separately}
-    set_rect_dimens(r, parent_box, x, y, 
-                    pdf_link_wd, pdf_link_ht, pdf_link_dp, pdf_link_margin);
-    pdf_create_obj(obj_type_others, 0);
-    obj_annot_ptr(obj_ptr) := r;
-    last_link := r;
-    pdf_append_list(obj_ptr)(pdf_link_list);
-end;
-
-@ Threads are handled in similar way as link annotations.
-
-@<Declare procedures needed in |pdf_hlist_out|, |pdf_vlist_out|@>=
-procedure append_bead(p: pointer);
-var a, b, c, t: integer;
-begin
-    if not is_shipping_page then
-        pdf_error("ext4", "threads cannot be inside an XForm");
-    t := get_obj(obj_type_thread, pdf_thread_id(p), pdf_thread_named_id(p));
-    b := pdf_new_objnum;
-    obj_bead_ptr(b) := pdf_get_mem(pdfmem_bead_size);
-    obj_bead_page(b) := pdf_last_page;
-    obj_bead_data(b) := p; 
-    if pdf_thread_attr(p) <> null then
-        obj_bead_attr(b) := tokens_to_string(pdf_thread_attr(p))
-    else
-        obj_bead_attr(b) := 0; 
-    if obj_thread_first(t) = 0 then begin
-        obj_thread_first(t) := b;
-        obj_bead_next(b) := b;
-        obj_bead_prev(b) := b;
-    end
-    else begin
-        a := obj_thread_first(t);
-        c := obj_bead_prev(a);
-        obj_bead_prev(b) := c;
-        obj_bead_next(b) := a;
-        obj_bead_prev(a) := b;
-        obj_bead_next(c) := b;
-    end;
-    pdf_append_list(b)(pdf_bead_list);
-end;
-
-procedure do_thread(p, parent_box: pointer; x, y: scaled);
-begin
-    if doing_leaders then
-        return;
-    if subtype(p) = pdf_start_thread_node then begin
-        pdf_thread_wd := pdf_width(p);
-        pdf_thread_ht := pdf_height(p);
-        pdf_thread_dp := pdf_depth(p);
-        pdf_last_thread_id := pdf_thread_id(p);
-        pdf_last_thread_named_id := (pdf_thread_named_id(p) > 0);
-        if pdf_last_thread_named_id then
-            add_token_ref(pdf_thread_id(p));
-        pdf_thread_level := cur_s;
-    end;
-    set_rect_dimens(p, parent_box, x, y, 
-                    pdf_width(p), pdf_height(p), pdf_depth(p),
-                    pdf_thread_margin);
-    append_bead(p);
-    last_thread := p;
-end;
-
-procedure append_thread(parent_box: pointer; x, y: scaled);
-var p: pointer;
-begin
-    p := get_node(pdf_thread_node_size);
-    info(p) := max_halfword; {this is not a whatsit node}
-    link(p) := null; {this node will be destroyed separately}
-    pdf_width(p) := pdf_thread_wd;
-    pdf_height(p) := pdf_thread_ht;
-    pdf_depth(p) := pdf_thread_dp;
-    pdf_thread_attr(p) := null;
-    pdf_thread_id(p) := pdf_last_thread_id;
-    if pdf_last_thread_named_id then begin
-        add_token_ref(pdf_thread_id(p));
-        pdf_thread_named_id(p) := 1;
-    end
-    else
-        pdf_thread_named_id(p) := 0;
-    set_rect_dimens(p, parent_box, x, y, 
-                    pdf_width(p), pdf_height(p), pdf_depth(p),
-                    pdf_thread_margin);
-    append_bead(p);
-    last_thread := p;
-end;
-
-procedure end_thread;
-begin
-    if pdf_thread_level <> cur_s then
-        pdf_error("ext4", "\pdfendthread ended up in different nesting level than \pdfstartthread");
-    if is_running(pdf_thread_dp) and (last_thread <> null) then
-        pdf_bottom(last_thread) := cur_v + pdf_thread_margin;
-    if pdf_last_thread_named_id then
-        delete_token_ref(pdf_last_thread_id);
-    last_thread := null;
-end;
-
-function open_subentries(p: pointer): integer;
-var k, c: integer;
-    l, r: integer;
-begin
-    k := 0;
-    if obj_outline_first(p) <> 0 then begin
-        l := obj_outline_first(p);
-        repeat
-            incr(k);
-            c := open_subentries(l);
-            if obj_outline_count(l) > 0 then
-                k := k + c;
-            obj_outline_parent(l) := p;
-            r := obj_outline_next(l);
-            if r = 0 then
-                obj_outline_last(p) := l;
-            l := r;
-        until l = 0;
-    end;
-    if obj_outline_count(p) > 0 then
-        obj_outline_count(p) := k
-    else
-        obj_outline_count(p) := -k;
-    open_subentries := k;
-end;
-
-procedure do_dest(p, parent_box: pointer; x, y: scaled);
-var k: integer;
-begin
-    if not is_shipping_page then
-        pdf_error("ext4", "destinations cannot be inside an XForm");
-    if doing_leaders then
-        return;
-    k := get_obj(obj_type_dest, pdf_dest_id(p), pdf_dest_named_id(p));
-    if obj_dest_ptr(k) <> null then begin
-        warn_dest_dup(pdf_dest_id(p), pdf_dest_named_id(p),
-                      "ext4", "has been already used, duplicate ignored");
-        return;
-    end;
-    obj_dest_ptr(k) := p;
-    pdf_append_list(k)(pdf_dest_list);
-    case pdf_dest_type(p) of
-    pdf_dest_xyz: begin
-        pdf_left(p) := cur_h;
-        pdf_top(p) := cur_v;
-    end;
-    pdf_dest_fith,
-    pdf_dest_fitbh:
-        pdf_top(p) := cur_v;
-    pdf_dest_fitv,
-    pdf_dest_fitbv:
-        pdf_left(p) := cur_h;
-    pdf_dest_fit,
-    pdf_dest_fitb:
-        do_nothing;
-    pdf_dest_fitr:
-        set_rect_dimens(p, parent_box, x, y, 
-                        pdf_width(p), pdf_height(p), pdf_depth(p), 
-                        pdf_dest_margin);
-    endcases;
-end;
-
-procedure out_form(p: pointer);
-begin
-    pdf_end_text;
-    pdf_print_ln("q");
-    if pdf_lookup_list(pdf_xform_list, pdf_xform_objnum(p)) = null then
-        pdf_append_list(pdf_xform_objnum(p))(pdf_xform_list);
-    cur_v := cur_v + obj_xform_depth(pdf_xform_objnum(p));
-    pdf_print("1 0 0 1 ");
-    pdf_print_bp(pdf_x(cur_h)); pdf_out(" ");
-    pdf_print_bp(pdf_y(cur_v));
-    pdf_print_ln(" cm");
-    pdf_print("/Fm");
-    pdf_print_int(obj_info(pdf_xform_objnum(p)));
-    pdf_print_resname_prefix;
-    pdf_print_ln(" Do");
-    pdf_print_ln("Q");
-end;
-
-procedure out_image(p: pointer);
-var image: integer;
-begin
-    image := obj_ximage_data(pdf_ximage_objnum(p));
-    pdf_end_text;
-    pdf_print_ln("q");
-    if pdf_lookup_list(pdf_ximage_list, pdf_ximage_objnum(p)) = null then
-        pdf_append_list(pdf_ximage_objnum(p))(pdf_ximage_list);
-    if not is_pdf_image(image) then begin
-        pdf_print_real(ext_xn_over_d(pdf_width(p), 
-                       ten_pow[6], one_hundred_bp), 4);
-        pdf_print(" 0 0 ");
-        pdf_print_real(ext_xn_over_d(pdf_height(p) + pdf_depth(p), 
-                       ten_pow[6], one_hundred_bp), 4);
-        pdf_out(" ");
-        pdf_print_bp(pdf_x(cur_h)); pdf_out(" ");
-        pdf_print_bp(pdf_y(cur_v));
-    end
-    else begin
-        pdf_print_real(ext_xn_over_d(pdf_width(p),
-                       ten_pow[6], image_width(image)), 6);
-        pdf_print(" 0 0 ");
-        pdf_print_real(ext_xn_over_d(pdf_height(p) + pdf_depth(p),
-                       ten_pow[6], image_height(image)), 6);
-        pdf_out(" ");
-        pdf_print_bp(pdf_x(cur_h) -
-                     ext_xn_over_d(pdf_width(p), epdf_orig_x(image), 
-                                   image_width(image)));
-        pdf_out(" ");
-        pdf_print_bp(pdf_y(cur_v) -
-                     ext_xn_over_d(pdf_height(p), epdf_orig_y(image), 
-                                   image_height(image)));
-    end;
-    pdf_print_ln(" cm");
-    pdf_print("/Im");
-    pdf_print_int(obj_info(pdf_ximage_objnum(p)));
-    pdf_print_resname_prefix;
-    pdf_print_ln(" Do");
-    pdf_print_ln("Q");
-end;
-
-
-@ @<Output the whatsit node |p| in |pdf_vlist_out|@>=
-case subtype(p) of
-pdf_literal_node:
-    pdf_out_literal(p);
-pdf_refobj_node:
-    pdf_append_list(pdf_obj_objnum(p))(pdf_obj_list);
-pdf_refxform_node:
-    @<Output a Form node in a vlist@>;
-pdf_refximage_node:
-    @<Output a Image node in a vlist@>;
-pdf_annot_node:
-    do_annot(p, this_box, left_edge, top_edge + height(this_box));
-pdf_start_link_node:
-    pdf_error("ext4", "\pdfstartlink ended up in vlist");
-pdf_end_link_node:
-    pdf_error("ext4", "\pdfendlink ended up in vlist");
-pdf_dest_node:
-    do_dest(p, this_box, left_edge, top_edge + height(this_box));
-pdf_thread_node,
-pdf_start_thread_node:
-    do_thread(p, this_box, left_edge, top_edge + height(this_box));
-pdf_end_thread_node:
-    end_thread;
-pdf_save_pos_node:
-    @<Save current position to |pdf_last_x_pos|, |pdf_last_y_pos|@>;
-special_node:
-    pdf_special(p);
-othercases out_what(p);
-endcases
-
-@ @<Glob...@>=
-@!is_shipping_page: boolean; {set to |shipping_page| when |pdf_ship_out| starts}
-
-@ @<Save current position to |pdf_last_x_pos|, |pdf_last_y_pos|@>=
-begin
-    pdf_last_x_pos := cur_h;
-    if is_shipping_page then
-        pdf_last_y_pos := cur_page_height - cur_v
-    else
-        pdf_last_y_pos := pdf_xform_height + pdf_xform_depth - cur_v;
-end
-
-@ @<Output a Image node in a vlist@>=
-begin cur_v:=cur_v+pdf_height(p)+pdf_depth(p); save_v:=cur_v;
-  cur_h:=left_edge;
-  out_image(p);
-  cur_v:=save_v; cur_h:=left_edge;
-  end
-
-@ @<Output a Form node in a vlist@>=
-begin cur_v:=cur_v+pdf_height(p); save_v:=cur_v;
-  cur_h:=left_edge;
-  out_form(p);
-  cur_v:=save_v+pdf_depth(p); cur_h:=left_edge;
-  end
-
-@ @<Output the whatsit node |p| in |pdf_hlist_out|@>=
-case subtype(p) of
-pdf_literal_node:
-    pdf_out_literal(p);
-pdf_refobj_node:
-    pdf_append_list(pdf_obj_objnum(p))(pdf_obj_list);
-pdf_refxform_node:
-    @<Output a Form node in a hlist@>;
-pdf_refximage_node:
-    @<Output a Image node in a hlist@>;
-pdf_annot_node:
-    do_annot(p, this_box, left_edge, base_line);
-pdf_start_link_node:
-    do_link(p, this_box, left_edge, base_line);
-pdf_end_link_node: begin
-    end_link;
-    @<Create link annotation for the current hbox if needed@>;
-end;
-pdf_dest_node:
-    do_dest(p, this_box, left_edge, base_line);
-pdf_thread_node:
-    do_thread(p, this_box, left_edge, base_line);
-pdf_start_thread_node:
-    pdf_error("ext4", "\pdfstartthread ended up in hlist");
-pdf_end_thread_node:
-    pdf_error("ext4", "\pdfendthread ended up in hlist");
-pdf_save_pos_node:
-    @<Save current position to |pdf_last_x_pos|, |pdf_last_y_pos|@>;
-special_node:
-    pdf_special(p);
-othercases out_what(p);
-endcases
-
-@ @<Output a Image node in a hlist@>=
-begin
-  cur_v:=base_line+pdf_depth(p);
-  edge:=cur_h;
-  out_image(p);
-  cur_h:=edge+pdf_width(p); cur_v:=base_line;
-  end
-
-@ @<Output a Form node in a hlist@>=
-begin
-  cur_v:=base_line;
-  edge:=cur_h;
-  out_form(p);
-  cur_h:=edge+pdf_width(p); cur_v:=base_line;
-  end
- at z

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.defines
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.defines	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.defines	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 {
-Copyright (c) 1996-2002 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2006 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -17,7 +17,7 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftex.defines#13 $
+$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftex.defines#15 $
 }
 
 { pdftex.defines: additions for pdfTeX }
@@ -27,6 +27,11 @@
 @define function getlpcode();
 @define function getrpcode();
 @define function getefcode();
+ at define function getknbscode();
+ at define function getstbscode();
+ at define function getshbscode();
+ at define function getknbccode();
+ at define function getknaccode();
 @define function texbopenin();
 @define function vfbopenin ();
 @define procedure pdfmarkchar();
@@ -41,27 +46,37 @@
 @define procedure pdfinitmapfile();
 
 { functions from utils.c }
+ at define procedure escapehex();
+ at define procedure escapename();
+ at define procedure escapestring();
+ at define function extxnoverd();
+ at define procedure getcreationdate;
+ at define procedure getfiledump();
+ at define procedure getfilemoddate();
+ at define procedure getfilesize();
+ at define procedure getmatch();
+ at define procedure getmd5sum();
 @define function getresnameprefix;
+ at define procedure initstarttime;
+ at define function isquotebad;
+ at define function makecstring();
+ at define procedure matchstrings();
+ at define procedure libpdffinish;
+ at define procedure makepdftexbanner;
+ at define procedure printcreationdate;
+ at define procedure printmoddate;
+ at define procedure printID();
 @define procedure setjobid();
- at define procedure makepdftexbanner;
- at define function extxnoverd();
- at define procedure libpdffinish;
+ at define procedure unescapehex();
 @define procedure writestreamlength();
- at define procedure printID();
- at define procedure printcreationdate;
- at define procedure escapestr();
- at define function  escapedstrlen;
- at define function  getescapedchar();
 
+
 { functions from vfpacket.c }
 @define function newvfpacket();
 @define function packetbyte;
 @define procedure startpacket();
 @define procedure storepacket();
 
-{ functions from writeenc.c }
- at define procedure setcharmap();
-
 { functions from writefont.c }
 @define procedure dopdffont();
 
@@ -93,4 +108,7 @@
 @define procedure avlputobj();
 @define function avlfindobj();
 
+{ functions from tounicode.c }
+ at define procedure deftounicode();
+
 { end of pdftex.defines }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.h
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.h	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.h	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 1996-2002 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2006 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -42,6 +42,21 @@
 #define getefcode(f, c) \
     (pdffontefbase[f] == 0 ? 1000 : pdfmem[pdffontefbase[f] + c])
 
+#define getknbscode(f, c) \
+    (pdffontknbsbase[f] == 0 ? 0 : pdfmem[pdffontknbsbase[f] + c])
+
+#define getstbscode(f, c) \
+    (pdffontstbsbase[f] == 0 ? 0 : pdfmem[pdffontstbsbase[f] + c])
+
+#define getshbscode(f, c) \
+    (pdffontshbsbase[f] == 0 ? 0 : pdfmem[pdffontshbsbase[f] + c])
+
+#define getknbccode(f, c) \
+    (pdffontknbcbase[f] == 0 ? 0 : pdfmem[pdffontknbcbase[f] + c])
+
+#define getknaccode(f, c) \
+    (pdffontknacbase[f] == 0 ? 0 : pdfmem[pdffontknacbase[f] + c])
+
 #define texbopenin(f) \
     open_input (&(f), kpse_tex_format, FOPEN_RBIN_MODE)
 #define vfbopenin(f) \

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.mk
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.mk	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftex.mk	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,103 +1,103 @@
-# Makefile fragment for pdfTeX and web2c. --infovore at xs4all.nl. Public domain.
+# Makefile fragment for pdfeTeX and web2c. --infovore at xs4all.nl. Public domain.
 # This fragment contains the parts of the makefile that are most likely to
-# differ between releases of pdfTeX.
+# differ between releases of pdfeTeX.
 
-# The libraries are not mentioned.  As the matter stands, a change in their
-# number or how they are configured requires changes to the main distribution
-# anyway.
+# We build pdftex
+pdftex = @PETEX@ pdftex
+pdftexdir = pdftexdir
 
-# $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftex.mk#34 $
+Makefile: $(srcdir)/$(pdftexdir)/pdftex.mk
 
-Makefile: pdftexdir/pdftex.mk
-
-pdftex_bin = pdftex pdfetex pdfxtex ttf2afm pdftosrc
+# pdftex_bin = pdftex ttf2afm pdftosrc
+pdftex_bin = pdftex
 linux_build_dir = $(HOME)/pdftex/build/linux/texk/web2c
 
-# We build pdftex
-pdftex = @PTEX@ pdftex
-pdftexdir = pdftexdir
-
 # Extract pdftex version
-pdftexdir/pdftex.version: pdftexdir/pdftex.ch
-	grep '^@d pdftex_version_string==' $(srcdir)/pdftexdir/pdftex.ch \
+$(pdftexdir)/pdftex.version: $(srcdir)/$(pdftexdir)/pdftex.web
+	test -d $(pdftexdir) || mkdir $(pdftexdir)
+	grep '^@d pdftex_version_string==' $(srcdir)/$(pdftexdir)/pdftex.web \
 	  | sed "s/^.*'-//;s/'.*$$//" \
-	  >pdftexdir/pdftex.version
-
+	  >$(pdftexdir)/pdftex.version
+          
 # The C sources.
-pdftex_c = pdftexini.c pdftex0.c pdftex1.c pdftex2.c pdftex3.c
+pdftex_c = pdftexini.c pdftex0.c pdftex1.c pdftex2.c pdftex3.c 
 pdftex_o = pdftexini.o pdftex0.o pdftex1.o pdftex2.o pdftex3.o pdftexextra.o
 
 # Making pdftex
-pdftex: $(pdftex_o) $(pdftexextra_o) $(pdftexlibsdep)
+pdftex: pdftexd.h $(pdftex_o) $(pdftexextra_o) $(pdftexlibsdep)
 	@CXXHACKLINK@ $(pdftex_o) $(pdftexextra_o) $(pdftexlibs) $(socketlibs) @CXXHACKLDLIBS@ @CXXLDEXTRA@
 
 # C file dependencies.
-$(pdftex_c) pdftexcoerce.h pdftexd.h: pdftex.p $(web2c_texmf)
+$(pdftex_c) pdftexcoerce.h pdftexd.h: pdftex.p $(web2c_texmf) $(srcdir)/$(pdftexdir)/pdftex.defines $(srcdir)/$(pdftexdir)/pdftex.h
 	$(web2c) pdftex
-pdftexextra.c: pdftexdir/pdftexextra.h lib/texmfmp.c
+pdftexextra.c: $(pdftexdir)/pdftexextra.h lib/texmfmp.c
+	test -d $(pdftexdir) || mkdir $(pdftexdir)
 	sed s/TEX-OR-MF-OR-MP/pdftex/ $(srcdir)/lib/texmfmp.c >$@
-pdftexdir/pdftexextra.h: pdftexdir/pdftexextra.in pdftexdir/pdftex.version
-	sed s/PDFTEX-VERSION/`cat pdftexdir/pdftex.version`/ \
-	  $(srcdir)/pdftexdir/pdftexextra.in >$@
+$(pdftexdir)/pdftexextra.h: $(pdftexdir)/pdftexextra.in $(pdftexdir)/pdftex.version etexdir/etex.version
+	test -d $(pdftexdir) || mkdir $(pdftexdir)
+	sed -e s/PDFTEX-VERSION/`cat $(pdftexdir)/pdftex.version`/ \
+	    -e s/ETEX-VERSION/`cat etexdir/etex.version`/ \
+	  $(srcdir)/$(pdftexdir)/pdftexextra.in >$@
 
-# Tangling.
-pdftex.p pdftex.pool: tangle pdftex.web pdftex.ch
-	$(TANGLE) pdftex.web pdftex.ch
+# Tangling
+pdftex.p pdftex.pool: tangle $(srcdir)/$(pdftexdir)/pdftex.web pdftex.ch
+	$(TANGLE) $(srcdir)/$(pdftexdir)/pdftex.web pdftex.ch
 
-# Generation of the web and ch files.
-#   Sources for pdftex.web:
-pdftex_web_srcs = $(srcdir)/tex.web \
-  $(srcdir)/pdftexdir/pdftex.ch \
-  $(srcdir)/pdftexdir/hz.ch  \
-  $(srcdir)/pdftexdir/misc.ch \
-  $(srcdir)/pdftexdir/vadjust.ch
-#   Sources for etex.ch:
-pdftex_ch_srcs = pdftex.web \
-  $(srcdir)/pdftexdir/tex.ch0 \
+#   Sources for pdftex.ch:
+pdftex_ch_srcs = $(srcdir)/$(pdftexdir)/pdftex.web \
+  $(srcdir)/$(pdftexdir)/tex.ch0 \
   $(srcdir)/tex.ch \
-  $(srcdir)/pdftexdir/tex.ch1 \
-  $(srcdir)/pdftexdir/tex.pch
+  $(srcdir)/$(pdftexdir)/pdftex.ch 
 #   Rules:
-pdftex.web: tie pdftexdir/pdftex.mk $(pdftex_web_srcs)
-	$(TIE) -m pdftex.web $(pdftex_web_srcs)
-pdftex.ch: $(pdftex_ch_srcs)
+pdftex.ch: $(TIE) $(pdftex_ch_srcs)
 	$(TIE) -c pdftex.ch $(pdftex_ch_srcs)
 
-# Tests...
-check: @PTEX@ pdftex-check
+# pdfetex: (it's just a copy of pdftex)
+pdfetex: pdftex
+	cp -p pdftex pdfetex
+pdfetex.pool: pdftex.pool
+	cp -p pdftex.pool pdfetex.pool
+
+# for developing only
+pdftex-org.web: $(TIE) $(pdftex_ch_srcs_org)
+	$(TIE) -m $@ $(pdftex_ch_srcs_org)
+pdftex-all.web: $(TIE) $(srcdir)/$(pdftexdir)/pdftex.web pdftex.ch
+	$(TIE) -m $@ $(srcdir)/$(pdftexdir)/pdftex.web pdftex.ch
+pdftex-all.tex: pdftex-all.web
+	$(WEAVE) pdftex-all.web
+	echo -e '1s/ webmac/ pdfwebmac/\nw\nq' | ed $@ >/dev/null 2>&1
+pdftex-all.pdf: pdftex-all.tex
+	$(pdftex) pdftex-all.tex
+
+check: @PETEX@ pdftex-check
 pdftex-check: pdftex pdftex.fmt
 
-# Cleaning up.
 clean:: pdftex-clean
 pdftex-clean:
 	$(LIBTOOL) --mode=clean $(RM) pdftex
 	rm -f $(pdftex_o) $(pdftex_c) pdftexextra.c pdftexcoerce.h
-	rm -f pdftexdir/pdftexextra.h pdftexdir/pdftex.version
-	rm -f pdftexd.h pdftex.p pdftex.pool pdftex.web pdftex.ch
+	rm -f $(pdftexdir)/pdftexextra.h
+	rm -f pdftexd.h pdftex.p pdftex.pool pdftex.ch
 	rm -f pdftex.fmt pdftex.log
 
-# Dumps.
-all_pdffmts = @FMU@ pdftex.fmt $(pdffmts)
+# Dumps
+all_pdfefmts = @FMU@ pdfetex.fmt $(pdfefmts)
 
-dumps: @PTEX@ pdffmts
-pdffmts: $(all_pdffmts)
+dumps: @PETEX@ pdfefmts
+pdfefmts: $(all_pdfefmts)
 
-pdffmtdir = $(web2cdir)/pdftex
-$(pdffmtdir)::
-	$(SHELL) $(top_srcdir)/../mkinstalldirs $(pdffmtdir)
+pdfefmtdir = $(web2cdir)/pdfetex
+$(pdfefmtdir)::
+	$(SHELL) $(top_srcdir)/../mkinstalldirs $(pdfefmtdir)
 
-pdftex.fmt: pdftex
-	$(dumpenv) $(MAKE) progname=pdftex files="plain.tex cmr10.tfm" prereq-check
-	$(dumpenv) ./pdftex --progname=pdftex --jobname=pdftex --ini \\pdfoutput=1 \\input plain \\dump </dev/null
+pdfetex.fmt: pdfetex
+	$(dumpenv) $(MAKE) progname=pdfetex files="etex.src plain.tex cmr10.tfm" prereq-check
+	$(dumpenv) ./pdfetex --progname=pdfetex --jobname=pdfetex --ini \*\\pdfoutput=1\\input etex.src \\dump </dev/null
 
-pdfolatex.fmt: pdftex
-	$(dumpenv) $(MAKE) progname=pdfolatex files="latex.ltx" prereq-check
-	$(dumpenv) ./pdftex --progname=pdfolatex --jobname=pdfolatex --ini \\pdfoutput=1 \\input latex.ltx </dev/null
+pdflatex.fmt: pdftex
+	$(dumpenv) $(MAKE) progname=pdflatex files="latex.ltx" prereq-check
+	$(dumpenv) ./pdftex --progname=pdflatex --jobname=pdflatex --ini \*\\pdfoutput=1\\input latex.ltx </dev/null
 
-#pdflatex.fmt: pdftex
-#	$(dumpenv) $(MAKE) progname=pdflatex files="latex.ltx" prereq-check
-#	$(dumpenv) ./pdftex --progname=pdflatex --jobname=pdflatex --ini \\pdfoutput=1 \\input latex.ltx </dev/null
-
 # 
 # Installation.
 install-pdftex: install-pdftex-exec install-pdftex-data
@@ -106,29 +106,28 @@
 install-pdftex-dumps: install-pdftex-fmts
 
 # The actual binary executables and pool files.
-install-programs: @PTEX@ install-pdftex-programs
-install-pdftex-programs: pdftex $(bindir)
+install-programs: @PETEX@ install-pdftex-programs
+install-pdftex-programs: $(pdftex) $(bindir)
 	for p in pdftex; do $(INSTALL_LIBTOOL_PROG) $$p $(bindir); done
 
-install-links: @PTEX@ install-pdftex-links
+install-links: @PETEX@ install-pdftex-links
 install-pdftex-links: install-pdftex-programs
-	#cd $(bindir) && (rm -f pdfinitex pdfinitex; \
-	#  $(LN) pdftex pdfinitex; $(LN) pdftex pdfvirtex)
+	#cd $(bindir) && (rm -f pdfeinitex pdfevirtex; \
+	#  $(LN) pdftex pdfeinitex; $(LN) pdftex pdfevirtex)
 
-install-fmts: @PTEX@ install-pdftex-fmts
-install-pdftex-fmts: pdffmts $(pdffmtdir)
-	pdffmts="$(all_pdffmts)"; \
-	  for f in $$pdffmts; do $(INSTALL_DATA) $$f $(pdffmtdir)/$$f; done
-	pdffmts="$(pdffmts)"; \
-	  for f in $$pdffmts; do base=`basename $$f .fmt`; \
+install-fmts: @PETEX@ install-pdftex-fmts
+install-pdftex-fmts: pdfefmts $(pdfefmtdir)
+	pdfefmts="$(all_pdfefmts)"; \
+	  for f in $$pdfefmts; do $(INSTALL_DATA) $$f $(pdfefmtdir)/$$f; done
+	pdfefmts="$(pdfefmts)"; \
+	  for f in $$pdfefmts; do base=`basename $$f .fmt`; \
 	    (cd $(bindir) && (rm -f $$base; $(LN) pdftex $$base)); done
 
 # Auxiliary files.
-install-data:: @PTEX@ install-pdftex-data
+install-data:: @PETEX@ install-pdftex-data
 install-pdftex-pool: pdftex.pool $(texpooldir)
 	$(INSTALL_DATA) pdftex.pool $(texpooldir)/pdftex.pool
 
-
 # 
 # ttf2afm
 ttf2afm = ttf2afm
@@ -137,10 +136,10 @@
 	$(kpathsea_link) ttf2afm.o $(kpathsea)
 ttf2afm.o: ttf2afm.c macnames.c
 	$(compile) -c $< -o $@
-ttf2afm.c:
-	cp $(srcdir)/pdftexdir/ttf2afm.c .
-macnames.c:
-	cp $(srcdir)/pdftexdir/macnames.c .
+ttf2afm.c: $(srcdir)/$(pdftexdir)/ttf2afm.c
+	cp $(srcdir)/$(pdftexdir)/ttf2afm.c .
+macnames.c: $(srcdir)/$(pdftexdir)/macnames.c
+	cp $(srcdir)/$(pdftexdir)/macnames.c .
 check: ttf2afm-check
 ttf2afm-check: ttf2afm
 clean:: ttf2afm-clean
@@ -152,10 +151,10 @@
 # pdftosrc
 pdftosrc = pdftosrc
 
-pdftosrc: pdftexdir/pdftosrc.o $(LIBXPDFDEP)
-	@CXXHACKLINK@ pdftexdir/pdftosrc.o $(LDLIBXPDF) -lm @CXXLDEXTRA@
-pdftexdir/pdftosrc.o:$(srcdir)/pdftexdir/pdftosrc.cc
-	cd pdftexdir && $(MAKE) pdftosrc.o
+pdftosrc: $(pdftexdir)/pdftosrc.o $(LIBXPDFDEP)
+	@CXXHACKLINK@ $(pdftexdir)/pdftosrc.o $(LDLIBXPDF) -lm @CXXLDEXTRA@
+$(pdftexdir)/pdftosrc.o:$(srcdir)/$(pdftexdir)/pdftosrc.cc
+	cd $(pdftexdir) && $(MAKE) pdftosrc.o
 check: pdftosrc-check
 pdftosrc-check: pdftosrc
 clean:: pdftosrc-clean
@@ -188,4 +187,5 @@
 	$(MAKE) tangle && rm -f tangle && \
 	cp -f $(linux_build_dir)/tangle .  && touch tangle
 
+# vim: set noexpandtab
 # end of pdftex.mk

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftexextra.in
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftexextra.in	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftexextra.in	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,17 +17,17 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: pdftexextra.in,v 1.4 2004/08/26 18:14:18 olaf Exp $
+$Id: pdftexextra.in,v 1.4 2004/08/26 18:19:57 olaf Exp $
 */
 
 /* pdftexextra.in: banner etc. for pdfTeX.
 
-   This is included by pdfTeX, from ../etexextra.c
+   This is included by pdfTeX, from ../pdftexextra.c
    (generated from ../lib/texmfmp.c).
 */
 
-#define BANNER "This is pdfTeX, Version 3.141592-PDFTEX-VERSION"
-#define COPYRIGHT_HOLDER "Han The Thanh"
+#define BANNER "This is pdfTeX, Version 3.141592-PDFTEX-VERSION-ETEX-VERSION"
+#define COPYRIGHT_HOLDER "Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX)"
 #define AUTHOR NULL
 #define PROGRAM_HELP PDFTEXHELP
 #define BUG_ADDRESS "pdftex at tug.org"
@@ -38,3 +38,4 @@
 #define INPUT_FORMAT kpse_tex_format
 #define INI_PROGRAM "pdfinitex"
 #define VIR_PROGRAM "pdfvirtex"
+

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftoepdf.cc
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftoepdf.cc	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pdftoepdf.cc	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,7 +17,7 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftoepdf.cc#51 $
+$Id: pdftoepdf.cc,v 1.6 2006/01/06 22:13:27 hahe Exp hahe $
 */
 
 #include <stdlib.h>
@@ -37,6 +37,7 @@
 #include "Dict.h"
 #include "XRef.h"
 #include "Catalog.h"
+#include "Link.h"
 #include "Page.h"
 #include "GfxFont.h"
 #include "PDFDoc.h"
@@ -46,25 +47,13 @@
 #include "epdf.h"
 
 static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftoepdf.cc#51 $";
+    "$Id: pdftoepdf.cc,v 1.6 2006/01/06 22:13:27 hahe Exp hahe $";
 
-/* we avoid reading all necessary kpathsea headers, but we need xstrdup */
-#ifdef __cplusplus
-extern "C" {
-  extern KPSEDLL char *xstrdup (const char *);
-}
-#else
-  extern KPSEDLL char *xstrdup (const char *);
-#endif
+/* 
+ * this file is mostly C and not very much C++; it's just used to interface the
+ * functions of xpdf, which happens to be written in C++. 
+ */
 
-#ifdef __cplusplus
-extern "C" {
-// FIXME: This definition is a duplicate from ../pdftexcoerce.h, which is
-// not usable here because of different macro definitions.
-extern integer pdflastpdfboxspec ;
-}
-#endif
-
 /*
  * Used flags below:
  * PDFTEX_COPY_PAGEGROUP
@@ -80,18 +69,6 @@
  *      PDFTEX_COPY_PAGEGROUP is set.
  */
 
-// FIXME: These definitions are duplicates from pdftexd.h
-/* #define PDF_PDF_BOX_SPEC_MEDIA 0 */
-/* #define PDF_PDF_BOX_SPEC_CROP  1 */
-/* #define PDF_PDF_BOX_SPEC_BLEED 2 */
-/* #define PDF_PDF_BOX_SPEC_TRIM  3 */
-/* #define PDF_PDF_BOX_SPEC_ART   4 */
-#define pdfpdfboxspecmedia ( 0 ) 
-#define pdfpdfboxspeccrop ( 1 ) 
-#define pdfpdfboxspecbleed ( 2 ) 
-#define pdfpdfboxspectrim ( 3 ) 
-#define pdfpdfboxspecart ( 4 ) 
-
 // The prefix for the PDF keys special to pdfTeX
 // This has been registered with Adobe by Hans Hagen
 #define pdfkeyprefix "PTEX"
@@ -178,7 +155,7 @@
         xref = p->xref;
         (p->occurences)++;
 #ifdef DEBUG
-        fprintf(stderr, "\nIncrementing %s (%d)\n", p->file_name, p->occurences);
+        fprintf(stderr, "\npdfTeX Debug: Incrementing %s (%d)\n", p->file_name, p->occurences);
 #endif
         return p;
     }
@@ -187,7 +164,7 @@
     p->xref = xref = 0;
     p->occurences = 0;
 #ifdef DEBUG
-    fprintf(stderr, "\nCreating %s (%d)\n", p->file_name, p->occurences);
+    fprintf(stderr, "\npdfTeX Debug: Creating %s (%d)\n", p->file_name, p->occurences);
 #endif
     GString *docName = new GString(p->file_name);
     p->doc = new PDFDoc(docName);  // takes ownership of docName
@@ -366,6 +343,7 @@
     str->reset();
     while ((c = str->getChar()) != EOF)
         pdfout(c);
+    pdflastbyte = pdfbuf[pdfptr - 1];
 }
 
 static void copyProcSet(Object *obj)
@@ -389,7 +367,7 @@
 
 static void copyFont(char *tag, Object *fontRef)
 {
-    PdfObject fontdict, subtype, basefont, fontdescRef, fontdesc, charset;
+    PdfObject fontdict, subtype, basefont, fontdescRef, fontdesc, charset, fontfile;
     GfxFont *gfont;
     fm_entry *fontmap;
     // Check whether the font has already been embedded before analysing it.
@@ -402,45 +380,43 @@
             return;
         }
     }
-    fontRef->fetch(xref, &fontdict);
-    if (!fontdict->isDict())
-        pdftex_fail("pdf inclusion: invalid font dict type <%s>", 
-                    fontdict->getTypeName());
-    fontdict->dictLookup("Subtype", &subtype);
-    if (!subtype->isName())
-        pdftex_fail("pdf inclusion: invalid font Subtype entry type <%s>", 
-                    subtype->getTypeName());
-    /* only handle Type1 fonts; others will be copied */
-    if (strcmp(subtype->getName(), "Type1") != 0 ) {
-        copyName(tag);
-        pdf_puts(" ");
-        copyObject(fontRef);
-        return;
+    /* only handle included Type1 fonts; anything else will be copied */
+    if (fontRef->fetch(xref, &fontdict) &&
+        fontdict->isDict() &&
+        fontdict->dictLookup("Subtype", &subtype) &&
+        subtype->isName() &&
+        fontdict->dictLookup("BaseFont", &basefont) &&
+        basefont->isName() &&
+        fontdict->dictLookupNF("FontDescriptor", &fontdescRef) &&
+        fontdescRef->isRef() &&
+        fontdescRef->fetch(xref, &fontdesc) &&
+        fontdesc->isDict() &&
+        fontdesc->dictLookupNF("FontDescriptor", &fontdescRef) &&
+        ((strcmp(subtype->getName(), "Type1") == 0 && 
+          fontdesc->dictLookup("FontFile", &fontfile)) ||
+         (strcmp(subtype->getName(), "Type1C") == 0 && 
+          fontdesc->dictLookup("FontFile3", &fontfile))) &&
+        fontfile->isStream()
+       ) {
+            fontmap = lookup_fontmap(basefont->getName());
+            if (fontmap != NULL) {
+                if (fontdesc->dictLookup("CharSet", &charset) && 
+                    charset->isString() && is_subsetable(fontmap))
+                    mark_glyphs(fontmap, charset->getString()->getCString());
+                else
+                    embed_whole_font(fontmap);
+                addFontDesc(fontdescRef->getRef(), fontmap);
+                copyName(tag);
+                gfont = GfxFont::makeFont(xref, tag, fontRef->getRef(), 
+                                          fontdict->getDict());
+                pdf_printf(" %d 0 R ", addFont(fontRef->getRef(), fontmap,
+                                               addEncoding(gfont)));
+                return;
+            }
     }
-    fontdict->dictLookup("BaseFont", &basefont);
-    if (!basefont->isName())
-        pdftex_fail("pdf inclusion: invalid font BaseFont entry type <%s>", 
-                    basefont->getTypeName());
-    fontmap = lookup_fontmap(basefont->getName());
-    if (fontmap != NULL && is_type1(fontmap) &&
-        fontdict->dictLookupNF("FontDescriptor", &fontdescRef) && 
-        fontdescRef->isRef() && fontdescRef->fetch(xref, &fontdesc) &&
-        fontdesc->isDict()) {
-        if (fontdesc->dictLookup("CharSet", &charset) && 
-                charset->isString() && is_subsetable(fontmap))
-            mark_glyphs(fontmap, charset->getString()->getCString());
-        else
-            embed_whole_font(fontmap);
-        addFontDesc(fontdescRef->getRef(), fontmap);
-    }
     copyName(tag);
-    if (fontdesc->isDict()) {
-        gfont = GfxFont::makeFont(xref, tag, fontRef->getRef(), fontdict->getDict());
-        pdf_printf(" %d 0 R ", addFont(fontRef->getRef(), fontmap, 
-                                       addEncoding(gfont)));
-    }
-    else
-        pdf_printf(" %d 0 R ", addOther(fontRef->getRef()));
+    pdf_puts(" ");
+    copyObject(fontRef);
 }
 
 static void copyFontResources(Object *obj)
@@ -607,7 +583,9 @@
         pdf_puts(">>\n");
         pdf_puts("stream\n");
         copyStream(obj->getStream()->getBaseStream());
-        pdf_puts("endstream");
+        if (pdflastbyte != '\n')
+           pdf_puts("\n");
+        pdf_puts("endstream"); /* can't simply write pdfendstream() */
     }
     else if (obj->isRef()) {
         ref = obj->getRef();
@@ -631,8 +609,11 @@
         if (!r->written) {
             Object obj1;
         r->written = 1;
-        zpdfbeginobj(r->num);
         xref->fetch(r->ref.num, r->ref.gen, &obj1);
+        if (obj1.isStream())
+            zpdfbeginobj(r->num, 0);
+        else
+            zpdfbeginobj(r->num, 2); /* \pdfobjcompresslevel = 2 is for this */
         if (r->type == objFont || r->type == objFontDesc)
             copyFontDict(&obj1, r);
         else
@@ -647,10 +628,10 @@
 static void writeEncodings()
 {
     UsedEncoding *r, *n;
-    char *glyphNames[MAX_CHAR_CODE + 1], *s;
+    char *glyphNames[256], *s;
     int i;
     for (r = encodingList; r != 0; r = r->next) {
-      for (i = 0; i <= MAX_CHAR_CODE; i++) {
+      for (i = 0; i < 256; i++) {
       if (r->font->isCIDFont()) {
         pdftex_warn("pdf inclusion: CID font included, encoding maybe wrong");
       }
@@ -668,6 +649,26 @@
     }
 }
 
+// get the pagebox according to the pagebox_spec
+static PDFRectangle *get_pagebox(Page *page, integer pagebox_spec)
+{
+    if (pagebox_spec == pdfboxspecmedia)
+        return page->getMediaBox();
+    else if (pagebox_spec == pdfboxspeccrop)
+        return page->getCropBox();
+    else if (pagebox_spec == pdfboxspecbleed)
+        return page->getBleedBox();
+    else if (pagebox_spec == pdfboxspectrim)
+        return page->getTrimBox();
+    else if (pagebox_spec == pdfboxspecart)
+        return page->getArtBox();
+    else
+        pdftex_fail("pdf inclusion: unknown value of pagebox spec (%i)", 
+                    pagebox_spec);
+        return page->getMediaBox(); // to make the compiler happy
+}
+
+
 /* Reads various information about the pdf and sets it up for later inclusion.
  * This will fail if the pdf version of the pdf is higher than
  * minor_pdf_version_wanted or page_name is given and can not be found.
@@ -675,9 +676,8 @@
  * Returns the page number.
  */
 integer 
-read_pdf_info(char *image_name, char *page_name, integer page_num,
-              integer minor_pdf_version_wanted, integer always_use_pdf_pagebox,
-              integer pdf_inclusion_errorlevel)
+read_pdf_info(char *image_name, char *page_name, integer page_num, integer pagebox_spec,
+              integer minor_pdf_version_wanted, integer pdf_inclusion_errorlevel)
 {
     PdfDocument *pdf_doc;
     Page *page;
@@ -693,9 +693,7 @@
     // open PDF file
     pdf_doc = find_add_document(image_name);
     epdf_doc = (void *) pdf_doc;
-#ifdef DEBUG
-    fprintf(stderr, "\nReading information on %s\n", pdf_doc->file_name);
-#endif
+
     // check pdf version
     // this works only for pdf 1.x -- but since any versions of pdf newer
     // than 1.x will not be backwards compatible to pdf 1.x, pdfTeX will
@@ -717,74 +715,40 @@
         LinkDest *link = pdf_doc->doc->findDest(&name);
         if (link == 0 || !link->isOk())
             pdftex_fail("pdf inclusion: invalid destination <%s>",
-                page_name);
+                        page_name);
         Ref ref = link->getPageRef();
         page_num = pdf_doc->doc->getCatalog()->findPage(ref.num, ref.gen);
         if (page_num == 0)
             pdftex_fail("pdf inclusion: destination is not a page <%s>",
-                page_name);
+                        page_name);
         delete link;
     } else {
         // get page by number
         if (page_num <= 0 || page_num > epdf_num_pages)
-        pdftex_fail("pdf inclusion: required page does not exist <%i>", 
-            epdf_num_pages);
+            pdftex_fail("pdf inclusion: required page does not exist <%i>", 
+                        epdf_num_pages);
     }
     // get the required page
     page = pdf_doc->doc->getCatalog()->getPage(page_num);
 
     // get the pagebox (media, crop...) to use.
-    // always_use_pdf_pagebox can set in the config file to override the
-    // setting through pdfximage.
-    if (always_use_pdf_pagebox < 1) {
-        switch (pdflastpdfboxspec) {
-        case pdfpdfboxspeccrop:
-            pagebox = page->getCropBox();
-            break;
-        
-        case pdfpdfboxspecbleed:
-            pagebox = page->getBleedBox();
-            break;
-        
-        case pdfpdfboxspectrim:
-            pagebox = page->getTrimBox();
-            break;
-        
-        case pdfpdfboxspecart:
-            pagebox = page->getArtBox();
-            break;
-
-        default:
-            pagebox = page->getMediaBox();
-            }
-        }
+    pagebox = get_pagebox(page, pagebox_spec);
+    if (pagebox->x2 > pagebox->x1) {
+        epdf_orig_x = pagebox->x1;
+        epdf_width = pagebox->x2 - pagebox->x1;
+    }
     else {
-        switch (always_use_pdf_pagebox) {
-        case 1 : 
-            pagebox = page->getMediaBox();
-            break;
-        case 2 : 
-            pagebox = page->getCropBox();
-            break;
-        case 3 : 
-            pagebox = page->getBleedBox();
-            break;
-        case 4 : 
-            pagebox = page->getTrimBox();
-            break;
-        default : // 5 and larger
-            pagebox = page->getArtBox();
-            }
-        }
-#ifdef DEBUG
-    fprintf(stderr, 
-            "\npagebox->x1: %.8f, pagebox->x2: %.8f, pagebox->y1: %.8f, pagebox->y2: %.8f\n", 
-            pagebox->x1, pagebox->x2, pagebox->y1, pagebox->y2);
-#endif
-    epdf_width = pagebox->x2 - pagebox->x1;
-    epdf_height = pagebox->y2 - pagebox->y1;
-    epdf_orig_x = pagebox->x1;
-    epdf_orig_y = pagebox->y1;
+        epdf_orig_x = pagebox->x2;
+        epdf_width = pagebox->x1 - pagebox->x2;
+    }
+    if (pagebox->y2 > pagebox->y1) {
+        epdf_orig_y = pagebox->y1;
+        epdf_height = pagebox->y2 - pagebox->y1;
+    }
+    else {
+        epdf_orig_y = pagebox->y2;
+        epdf_height = pagebox->y1 - pagebox->y2;
+    }
     
     rotate = page->getRotate();
     // handle page rotation and adjust dimens as needed
@@ -817,13 +781,15 @@
     PdfObject group, metadata, pieceinfo, separationInfo;
     Object info;
     char *key;
+    char s[256];
     int i, l;
     int rotate;
     double scale[6] = {0, 0, 0, 0, 0, 0};
+    bool writematrix = false;
     PdfDocument *pdf_doc = (PdfDocument *) epdf_doc;
     (pdf_doc->occurences)--;
 #ifdef DEBUG
-    fprintf(stderr, "\nDecrementing %s (%d)\n", pdf_doc->file_name, pdf_doc->occurences);
+    fprintf(stderr, "\npdfTeX Debug: Decrementing %s (%d)\n", pdf_doc->file_name, pdf_doc->occurences);
 #endif
     xref = pdf_doc->xref;
     inObjList = pdf_doc->inObjList;
@@ -838,7 +804,8 @@
 
     // write additional information
     pdf_printf("/%s.FileName (%s)\n", pdfkeyprefix, 
-               convertStringToPDFString(pdf_doc->file_name));
+               convertStringToPDFString(pdf_doc->file_name,
+                                        strlen(pdf_doc->file_name)));
     pdf_printf("/%s.PageNumber %i\n", pdfkeyprefix, epdf_selected_page);
     pdf_doc->doc->getDocInfoNF(&info);
     if (info.isRef()) {
@@ -846,55 +813,8 @@
         pdf_printf("/%s.InfoDict ", pdfkeyprefix);
         pdf_printf("%d 0 R \n", addOther(info.getRef()));
         }
-  
     // get the pagebox (media, crop...) to use.
-    // epdf_always_use_pdf_pagebox is a copy of always_use_pdf_pagebox which
-    // can set in the config file to override the setting through pdfximage.
-    if (epdf_always_use_pdf_pagebox < 1) {
-        switch (epdf_page_box) {
-        case pdfpdfboxspeccrop:
-            pagebox = page->getCropBox();
-            break;
-      
-        case pdfpdfboxspecbleed:
-            pagebox = page->getBleedBox();
-            break;
-        
-        case pdfpdfboxspectrim:
-            pagebox = page->getTrimBox();
-            break;
-        
-        case pdfpdfboxspecart:
-            pagebox = page->getArtBox();
-            break;
-       
-        default:
-            pagebox = page->getMediaBox();
-            }
-        }
-    else {
-        switch (epdf_always_use_pdf_pagebox) {
-        case 1 : 
-            pagebox = page->getMediaBox();
-            break;
-        case 2 : 
-            pagebox = page->getCropBox();
-            break;
-        case 3 : 
-            pagebox = page->getBleedBox();
-            break;
-        case 4 : 
-            pagebox = page->getTrimBox();
-            break;
-        default : // 5 and larger
-            pagebox = page->getArtBox();
-            }
-        }
-#ifdef DEBUG
-    fprintf(stderr, 
-            "\npagebox->x1: %.8f, pagebox->x2: %.8f, pagebox->y1: %.8f, pagebox->y2: %.8f\n", 
-            pagebox->x1, pagebox->x2, pagebox->y1, pagebox->y2);
-#endif
+    pagebox = get_pagebox(page, epdf_page_box);
 
     // handle page rotation
     if (rotate != 0) {
@@ -907,29 +827,29 @@
             // counterclockwise :-%
             tex_printf (", page is rotated %d degrees", rotate);
             switch (rotate) {
-                case  90: scale[1] = -1; scale[2] = 1; scale[4] = pagebox->x1 - pagebox->y1; scale[5] = pagebox->y1 + pagebox->x2; break;
-                case 180: scale[0] = scale[3] = -1;    scale[4] = pagebox->x1 + pagebox->x2; scale[5] = pagebox->y1 + pagebox->y2; break; // width and height are exchanged
-                case 270: scale[1] = 1; scale[2] = -1; scale[4] = pagebox->x1 + pagebox->y2; scale[5] = pagebox->y1 - pagebox->x1; break;
+                case  90: scale[1] = -1; scale[2] = 1; scale[4] = pagebox->x1 - pagebox->y1; scale[5] = pagebox->y1 + pagebox->x2; writematrix = true; break;
+                case 180: scale[0] = scale[3] = -1;    scale[4] = pagebox->x1 + pagebox->x2; scale[5] = pagebox->y1 + pagebox->y2; writematrix = true; break; // width and height are exchanged
+                case 270: scale[1] = 1; scale[2] = -1; scale[4] = pagebox->x1 + pagebox->y2; scale[5] = pagebox->y1 - pagebox->x1; writematrix = true; break;
                 }
+            if (writematrix) { // The matrix is only written if the image is rotated.
+                sprintf(s, "/Matrix [%.8f %.8f %.8f %.8f %.8f %.8f]\n",
+                    scale[0],
+                    scale[1],
+                    scale[2],
+                    scale[3],
+                    scale[4],
+                    scale[5]);
+                pdf_printf(stripzeros(s));
+                }
             }
         }
-    else {
-        scale[0] = scale[3] = 1;
-        }
 
-    pdf_printf("/Matrix [%.8f %.8f %.8f %.8f %.8f %.8f]\n",
-        scale[0],
-        scale[1],
-        scale[2],
-        scale[3],
-        scale[4],
-        scale[5]);
-
-    pdf_printf("/BBox [%.8f %.8f %.8f %.8f]\n",
+    sprintf(s, "/BBox [%.8f %.8f %.8f %.8f]\n",
                pagebox->x1,
                pagebox->y1,
                pagebox->x2,
                pagebox->y2);
+    pdf_printf(stripzeros(s));
 
     // write the page Group if it's there
     if (page->getGroup() != NULL) {
@@ -985,7 +905,8 @@
         // Resources can be missing (files without them have been spotted
         // in the wild). This violates the pdf spec, which claims they are
         // required, but all RIPs accept them.  
-        // We "replace" them with empty Resources.
+        // We "replace" them with empty /Resources, although in form xobjects
+        // /Resources are not required.
         pdftex_warn("pdf inclusion: no /Resources detected. Replacing with empty /Resources.");
         pdf_puts("/Resources <<>>\n");
         }
@@ -1016,8 +937,7 @@
         copyDict(&obj1);
         pdf_puts(">>\nstream\n");
         copyStream(contents->getStream()->getBaseStream());
-        pdf_puts("endstream\n");
-        pdfendobj();
+        pdfendstream();
     }
     else if (contents->isArray()) {
         pdfbeginstream();
@@ -1050,7 +970,7 @@
     xref = pdf_doc->xref;
     if (pdf_doc->occurences < 0) {
 #ifdef DEBUG
-        fprintf(stderr, "\nDeleting %s\n", pdf_doc->file_name);
+        fprintf(stderr, "\npdfTeX Debug: Deleting %s\n", pdf_doc->file_name);
 #endif
         delete_document(pdf_doc);
     }
@@ -1070,4 +990,3 @@
     delete globalParams;
     }
 }
-// vi:ts=4:tw=79:expandtab:ai:

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pkin.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pkin.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/pkin.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -58,49 +58,49 @@
 extern FILE *t3_file;
 #define pkfile t3_file
 
-static shalfword pkbyte(void)
+static shalfword pkbyte (void)
 {
-   register shalfword i ;
+    register shalfword i;
 
-   if ((i=xgetc(pkfile))==EOF)
-      pdftex_fail("unexpected eof in pk file") ;
-   return(i) ;
+    if ((i = xgetc (pkfile)) == EOF)
+        pdftex_fail ("unexpected eof in pk file");
+    return (i);
 }
 
-static integer pkduo(void)
+static integer pkduo (void)
 {
-    register integer i ;
+    register integer i;
 
-    i = pkbyte() ;
+    i = pkbyte ();
     if (i > 127)
-        i -= 256 ;
-    i = i * 256 + pkbyte() ;
-    return(i) ;
+        i -= 256;
+    i = i * 256 + pkbyte ();
+    return (i);
 }
 
-static integer pktrio(void)
+static integer pktrio (void)
 {
-   register integer i ;
+    register integer i;
 
-   i = pkbyte() ;
-   if (i > 127)
-      i -= 256 ;
-   i = i * 256 + pkbyte() ;
-   i = i * 256 + pkbyte() ;
-   return(i) ;
+    i = pkbyte ();
+    if (i > 127)
+        i -= 256;
+    i = i * 256 + pkbyte ();
+    i = i * 256 + pkbyte ();
+    return (i);
 }
 
-static integer pkquad(void)
+static integer pkquad (void)
 {
-   register integer i ;
+    register integer i;
 
-   i = pkbyte() ;
-   if (i > 127)
-      i -= 256 ;
-   i = i * 256 + pkbyte() ;
-   i = i * 256 + pkbyte() ;
-   i = i * 256 + pkbyte() ;
-   return(i) ;
+    i = pkbyte ();
+    if (i > 127)
+        i -= 256;
+    i = i * 256 + pkbyte ();
+    i = i * 256 + pkbyte ();
+    i = i * 256 + pkbyte ();
+    return (i);
 }
 
 /*
@@ -112,106 +112,111 @@
  *   packed data structure.
  */
 
-static halfword inputbyte, flagbyte ; 
-static halfword bitweight ; 
-static halfword dynf ;
-static halfword repeatcount ;
+static halfword inputbyte, flagbyte;
+static halfword bitweight;
+static halfword dynf;
+static halfword repeatcount;
 
-static shalfword getnyb(void)
-{   halfword temp;
-    if ( bitweight == 0 ) 
-    { bitweight = 16 ; 
-      inputbyte = pkbyte();
-      temp = inputbyte >> 4 ;
+static shalfword getnyb (void)
+{
+    halfword temp;
+    if (bitweight == 0) {
+        bitweight = 16;
+        inputbyte = pkbyte ();
+        temp = inputbyte >> 4;
     } else {
-      bitweight = 0 ;
-      temp = inputbyte & 15 ;
+        bitweight = 0;
+        temp = inputbyte & 15;
     }
-    return(temp);
-} 
+    return (temp);
+}
 
-static boolean getbit(void)
+static boolean getbit (void)
 {
-    bitweight >>= 1 ; 
-    if ( bitweight == 0 ) 
-    { inputbyte = pkbyte();
-      bitweight = 128 ;
-    } 
-    return(inputbyte & bitweight) ;
+    bitweight >>= 1;
+    if (bitweight == 0) {
+        inputbyte = pkbyte ();
+        bitweight = 128;
+    }
+    return (inputbyte & bitweight);
 }
 
-static halfword (*realfunc)(void) ;
-long pk_remainder ;
-static halfword handlehuge(halfword i, halfword  k);
+static halfword (*realfunc) (void);
+long pk_remainder;
+static halfword handlehuge (halfword i, halfword k);
 
-static halfword pkpackednum(void) {
-register halfword i, j ; 
-    i = getnyb () ; 
-    if ( i == 0 ) 
-    { do { j = getnyb () ; 
-        i++ ; 
-        } while ( ! ( j != 0 ) ) ; 
-      if ( i > 3 ) {
+static halfword pkpackednum (void)
+{
+    register halfword i, j;
+    i = getnyb ();
+    if (i == 0) {
+        do {
+            j = getnyb ();
+            i++;
+        } while (!(j != 0));
+        if (i > 3) {
 /*
  *   Damn, we got a huge count!  We *fake* it by giving an artificially
  *   large repeat count.
  */
-         return(handlehuge(i, j)) ;
-      } else {
-         while ( i > 0 ) 
-           { j = j * 16 + getnyb () ; 
-             i-- ; 
-             } 
-           return ( j - 15 + ( 13 - dynf ) * 16 + dynf ) ; 
-         } 
-      }
-    else if ( i <= dynf ) return ( i ) ; 
-    else if ( i < 14 ) return ( ( i - dynf - 1 ) * 16 + getnyb () + dynf + 1 
-    ) ; 
-    else 
-    { if ( i == 14 ) repeatcount = pkpackednum () ; 
-      else repeatcount = 1 ; 
+            return (handlehuge (i, j));
+        } else {
+            while (i > 0) {
+                j = j * 16 + getnyb ();
+                i--;
+            }
+            return (j - 15 + (13 - dynf) * 16 + dynf);
+        }
+    } else if (i <= dynf)
+        return (i);
+    else if (i < 14)
+        return ((i - dynf - 1) * 16 + getnyb () + dynf + 1);
+    else {
+        if (i == 14)
+            repeatcount = pkpackednum ();
+        else
+            repeatcount = 1;
 #ifdef DEBUG
-      printf("[%d]", repeatcount);
+        printf ("[%d]", (int) repeatcount);
 #endif
-      return ( (*realfunc)() ) ;
-      } 
-    } 
+        return ((*realfunc) ());
+    }
+}
 
-static halfword rest(void)
+static halfword rest (void)
 {
-   halfword i ;
+    halfword i;
 
-   if (pk_remainder < 0) {
-      pk_remainder = - pk_remainder ;
-      return ( 0 ) ;
-   } else if (pk_remainder > 0) {
-      if (pk_remainder > 4000) {
-         pk_remainder = 4000 - pk_remainder ;
-         return ( 4000 ) ;
-      } else {
-         i = pk_remainder ;
-         pk_remainder = 0 ;
-         realfunc = pkpackednum ;
-         return ( i ) ;
-      }
-   } else {
-      pdftex_fail("shouldn't happen") ;
-      return 0; /*NOTREACHED*/
-   }
+    if (pk_remainder < 0) {
+        pk_remainder = -pk_remainder;
+        return (0);
+    } else if (pk_remainder > 0) {
+        if (pk_remainder > 4000) {
+            pk_remainder = 4000 - pk_remainder;
+            return (4000);
+        } else {
+            i = pk_remainder;
+            pk_remainder = 0;
+            realfunc = pkpackednum;
+            return (i);
+        }
+    } else {
+        pdftex_fail ("shouldn't happen");
+        return 0;
+    /*NOTREACHED*/}
 }
 
-static halfword handlehuge(halfword i, halfword  k)
+static halfword handlehuge (halfword i, halfword k)
 {
-   register long j = k ;
+    register long j = k;
 
-   while (i) {
-      j = (j << 4L) + getnyb() ;
-      i-- ;
-   }
-   pk_remainder = j - 15 + ( 13 - dynf ) * 16 + dynf ;
-   realfunc = rest ;
-   return ( rest() ) ;
+    while (i) {
+        j = (j << 4L) + getnyb ();
+        i--;
+    }
+    pk_remainder = j - 15 + (13 - dynf) * 16 + dynf;
+    realfunc = rest;
+    return (rest ());
 }
 
 /*
@@ -219,102 +224,104 @@
  */
 
 static halfword gpower[17] = { 0, 1, 3, 7, 15, 31, 63, 127,
-     255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535 } ; 
+    255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535
+};
 
-static void unpack(chardesc *cd)
-{ 
-  register integer i, j ; 
-  register halfword word, wordweight ;
-  halfword *raster;
-  shalfword rowsleft ; 
-  boolean turnon ; 
-  shalfword hbit ; 
-  halfword count ; 
-  shalfword  wordwidth ;
+static void unpack (chardesc * cd)
+{
+    register integer i, j;
+    register halfword word, wordweight;
+    halfword *raster;
+    shalfword rowsleft;
+    boolean turnon;
+    shalfword hbit;
+    halfword count;
+    shalfword wordwidth;
 
-      wordwidth = (cd->cwidth + 15) / 16 ;
-      i = 2 * cd->cheight * (long)wordwidth ;
-      if (i <= 0)
-         i = 2 ;
-      if (i > cd->rastersize) {
-        xfree(cd->raster);
+    wordwidth = (cd->cwidth + 15) / 16;
+    i = 2 * cd->cheight * (long) wordwidth;
+    if (i <= 0)
+        i = 2;
+    if (i > cd->rastersize) {
+        xfree (cd->raster);
         cd->rastersize = i;
-        cd->raster = xtalloc(cd->rastersize, halfword);
-      }
-      raster = cd->raster;
-      realfunc = pkpackednum ;
-      dynf = flagbyte / 16 ; 
-      turnon = flagbyte & 8 ; 
-      if ( dynf == 14 ) 
-      { bitweight = 0 ; 
-        for ( i = 1 ; i <= cd->cheight ; i ++ ) 
-          { word = 0 ; 
-            wordweight = 32768 ; 
-            for ( j = 1 ; j <= cd->cwidth ; j ++ ) 
-              { if ( getbit () ) word += wordweight ; 
-                wordweight >>= 1 ;
-                if ( wordweight == 0 ) 
-                { *raster++ = word ; 
-                  word = 0 ;
-                  wordweight = 32768 ; 
-                  } 
-                } 
-              if ( wordweight != 32768 ) 
-                 *raster++ = word ; 
-            } 
-      } else {
-        rowsleft = cd->cheight ; 
-        hbit = cd->cwidth ; 
-        repeatcount = 0 ; 
-        wordweight = 16 ; 
-        word = 0 ; 
-        bitweight = 0 ;
-        while ( rowsleft > 0 ) 
-          { count = (*realfunc)() ; 
+        cd->raster = xtalloc (cd->rastersize, halfword);
+    }
+    raster = cd->raster;
+    realfunc = pkpackednum;
+    dynf = flagbyte / 16;
+    turnon = flagbyte & 8;
+    if (dynf == 14) {
+        bitweight = 0;
+        for (i = 1; i <= cd->cheight; i++) {
+            word = 0;
+            wordweight = 32768;
+            for (j = 1; j <= cd->cwidth; j++) {
+                if (getbit ())
+                    word += wordweight;
+                wordweight >>= 1;
+                if (wordweight == 0) {
+                    *raster++ = word;
+                    word = 0;
+                    wordweight = 32768;
+                }
+            }
+            if (wordweight != 32768)
+                *raster++ = word;
+        }
+    } else {
+        rowsleft = cd->cheight;
+        hbit = cd->cwidth;
+        repeatcount = 0;
+        wordweight = 16;
+        word = 0;
+        bitweight = 0;
+        while (rowsleft > 0) {
+            count = (*realfunc) ();
 #ifdef DEBUG
-            if (turnon) printf("(%d) ",count);
-            else printf("%d ",count);
+            if (turnon)
+                printf ("(%d) ", (int) count);
+            else
+                printf ("%d ", (int) count);
 #endif
-            while ( count != 0 ) 
-              { if ( ( count < wordweight ) && ( count < hbit ) ) 
-                { if ( turnon ) word += gpower [ wordweight ] - gpower 
-                  [ wordweight - count ] ; 
-                  hbit -= count ; 
-                  wordweight -= count ; 
-                  count = 0 ; 
-                  } 
-                else if ( ( count >= hbit ) && ( hbit <= wordweight ) ) 
-                { if ( turnon )
-                     word += gpower [ wordweight ] - gpower 
-                  [ wordweight - hbit ] ; 
-                  *raster++ = word ; 
-                  for ( i = 1 ; i <= repeatcount ; i ++ ) {
-                    for ( j = 1 ; j <= wordwidth ; j ++ ) {
-                      *raster = *(raster - wordwidth) ;
-                      raster++ ;
+            while (count != 0) {
+                if ((count < wordweight) && (count < hbit)) {
+                    if (turnon)
+                        word += gpower[wordweight] - gpower[wordweight - count];
+                    hbit -= count;
+                    wordweight -= count;
+                    count = 0;
+                } else if ((count >= hbit) && (hbit <= wordweight)) {
+                    if (turnon)
+                        word += gpower[wordweight] - gpower[wordweight - hbit];
+                    *raster++ = word;
+                    for (i = 1; i <= repeatcount; i++) {
+                        for (j = 1; j <= wordwidth; j++) {
+                            *raster = *(raster - wordwidth);
+                            raster++;
+                        }
                     }
-                  }
-                  rowsleft -= repeatcount + 1 ; 
-                  repeatcount = 0 ; 
-                  word = 0 ; 
-                  wordweight = 16 ; 
-                  count -= hbit ; 
-                  hbit = cd->cwidth ; 
-                  } 
-                else 
-                { if ( turnon ) word += gpower [ wordweight ] ; 
-                  *raster++ = word ;
-                  word = 0 ; 
-                  count -= wordweight ; 
-                  hbit -= wordweight ; 
-                  wordweight = 16 ; 
-                  } 
-                } 
-              turnon = ! turnon ; 
-   }
-          if ( ( rowsleft != 0 ) || ( (integer)hbit != cd->cwidth ) ) 
-             pdftex_fail("error while unpacking; more bits than required"); 
-        } 
+                    rowsleft -= repeatcount + 1;
+                    repeatcount = 0;
+                    word = 0;
+                    wordweight = 16;
+                    count -= hbit;
+                    hbit = cd->cwidth;
+                } else {
+                    if (turnon)
+                        word += gpower[wordweight];
+                    *raster++ = word;
+                    word = 0;
+                    count -= wordweight;
+                    hbit -= wordweight;
+                    wordweight = 16;
+                }
+            }
+            turnon = !turnon;
+        }
+        if ((rowsleft != 0) || ((integer) hbit != cd->cwidth))
+            pdftex_fail ("error while unpacking; more bits than required");
+    }
 }
 
 /*
@@ -330,98 +337,103 @@
  *   return EOF if no character definition is available
  */
 
-int readchar(boolean check_preamble, chardesc *cd)
+int readchar (boolean check_preamble, chardesc * cd)
 {
-   register shalfword i ;
-   register integer k ;
-   register integer length=0 ;
+    register shalfword i;
+    register integer k;
+    register integer length = 0;
 
 /*
  *   Check the preamble of the pkfile
  */
-   if (check_preamble) {
-       if (pkbyte()!=247)
-          pdftex_fail("bad pk file, expected pre") ;
-       if (pkbyte()!=89)
-          pdftex_fail("bad version of pk file") ;
-       for(i=pkbyte(); i>0; i--) /* creator of pkfile */
-          (void)pkbyte() ;   
-       (void)pkquad(); /* design size */
-       k = pkquad() ;  /* checksum    */
-       k = pkquad() ;  /* hppp        */
-       k = pkquad() ;  /* vppp   */
-   }
+    if (check_preamble) {
+        if (pkbyte () != 247)
+            pdftex_fail ("bad pk file, expected pre");
+        if (pkbyte () != 89)
+            pdftex_fail ("bad version of pk file");
+        for (i = pkbyte (); i > 0; i--) /* creator of pkfile */
+            (void) pkbyte ();
+        (void) pkquad ();       /* design size */
+        k = pkquad ();          /* checksum    */
+        k = pkquad ();          /* hppp        */
+        k = pkquad ();          /* vppp   */
+    }
 /*
  *   Now we skip to the desired character definition
  */
-   while ((flagbyte=pkbyte())!=245) {
-      if (flagbyte < 240) {
-         switch (flagbyte & 7) {
-case 0: case 1: case 2: case 3:
-            length = (flagbyte & 7) * 256 + pkbyte() - 3;
-            cd->charcode = pkbyte() ;
-            (void) pktrio() ;  /* TFMwidth */
-            cd->xescape = pkbyte() ;      /* pixel width */
-            cd->cwidth = pkbyte() ;
-            cd->cheight = pkbyte() ;
-            cd->xoff = pkbyte() ;
-            cd->yoff = pkbyte() ;
-            if (cd->xoff > 127)
-               cd->xoff -= 256 ;
-            if (cd->yoff > 127)
-               cd->yoff -= 256 ;
-            break ;
-case 4: case 5: case 6:
-            length = (flagbyte & 3) * 65536L + pkbyte() * 256L ;
-            length = length + pkbyte() - 4L ;
-            cd->charcode = pkbyte() ;
-            (void) pktrio() ;           /* TFMwidth */
-            cd->xescape  = pkduo() ;      /* pixelwidth */
-            cd->cwidth = pkduo() ;
-            cd->cheight = pkduo() ;
-            cd->xoff = pkduo() ;
-            cd->yoff = pkduo() ;
-            break ;
-case 7:
-            length = pkquad() - 9L;
-            cd->charcode = pkquad();
-            (void) pkquad() ;  /* TFMwidth */
-            cd->xescape =  pkquad();      /* pixelwidth */
-            k = pkquad() ;
-            cd->cwidth = pkquad();
-            cd->cheight = pkquad();
-            cd->xoff = pkquad();
-            cd->yoff = pkquad();
-         }
-         if (length <= 0)
-            pdftex_fail("packet length (%i) too small", (int)length) ;
-         unpack(cd);
-         return 1;
-      } else {
-         k = 0 ;
-         switch (flagbyte) {
-case 243:
-            k = pkbyte() ;
-            if (k > 127)
-               k -= 256 ;
-case 242:
-            k = k * 256 + pkbyte() ;
-case 241:
-            k = k * 256 + pkbyte() ;
-case 240:
-            k = k * 256 + pkbyte() ;
-            while (k-- > 0)
-               i = pkbyte() ;
-            break ;
-case 244:
-            k = pkquad() ;
-            break ;
-case 246:
-            break ;
-default:
-            pdftex_fail("unexpected command (%i)", (int)flagbyte) ;
-         }
-      }
-   }
-   return 0; /* character not found */
+    while ((flagbyte = pkbyte ()) != 245) {
+        if (flagbyte < 240) {
+            switch (flagbyte & 7) {
+            case 0:
+            case 1:
+            case 2:
+            case 3:
+                length = (flagbyte & 7) * 256 + pkbyte () - 3;
+                cd->charcode = pkbyte ();
+                (void) pktrio ();       /* TFMwidth */
+                cd->xescape = pkbyte ();        /* pixel width */
+                cd->cwidth = pkbyte ();
+                cd->cheight = pkbyte ();
+                cd->xoff = pkbyte ();
+                cd->yoff = pkbyte ();
+                if (cd->xoff > 127)
+                    cd->xoff -= 256;
+                if (cd->yoff > 127)
+                    cd->yoff -= 256;
+                break;
+            case 4:
+            case 5:
+            case 6:
+                length = (flagbyte & 3) * 65536L + pkbyte () * 256L;
+                length = length + pkbyte () - 4L;
+                cd->charcode = pkbyte ();
+                (void) pktrio ();       /* TFMwidth */
+                cd->xescape = pkduo (); /* pixelwidth */
+                cd->cwidth = pkduo ();
+                cd->cheight = pkduo ();
+                cd->xoff = pkduo ();
+                cd->yoff = pkduo ();
+                break;
+            case 7:
+                length = pkquad () - 9L;
+                cd->charcode = pkquad ();
+                (void) pkquad ();       /* TFMwidth */
+                cd->xescape = pkquad ();        /* pixelwidth */
+                k = pkquad ();
+                cd->cwidth = pkquad ();
+                cd->cheight = pkquad ();
+                cd->xoff = pkquad ();
+                cd->yoff = pkquad ();
+            }
+            if (length <= 0)
+                pdftex_fail ("packet length (%i) too small", (int) length);
+            unpack (cd);
+            return 1;
+        } else {
+            k = 0;
+            switch (flagbyte) {
+            case 243:
+                k = pkbyte ();
+                if (k > 127)
+                    k -= 256;
+            case 242:
+                k = k * 256 + pkbyte ();
+            case 241:
+                k = k * 256 + pkbyte ();
+            case 240:
+                k = k * 256 + pkbyte ();
+                while (k-- > 0)
+                    i = pkbyte ();
+                break;
+            case 244:
+                k = pkquad ();
+                break;
+            case 246:
+                break;
+            default:
+                pdftex_fail ("unexpected command (%i)", (int) flagbyte);
+            }
+        }
+    }
+    return 0;                   /* character not found */
 }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ptexlib.h
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ptexlib.h	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ptexlib.h	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 1996-2002 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2006 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -17,24 +17,28 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/ptexlib.h#24 $
+$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/ptexlib.h#26 $
 */
 
 #ifndef PDFTEXLIB
-#define PDFTEXLIB
+#  define PDFTEXLIB
 
 /* WEB2C macros and prototypes */
-#if !defined(PDFTEXCOERCE) && !defined(PDFETEXCOERCE) && !defined(PDFXTEXCOERCE)
-#ifdef pdfTeX
-#undef pdfTeX /* to avoid warning about redefining pdfTeX in pdftexd.h */
-#endif /* pdfTeX */
-#define EXTERN extern
-#include "pdftexd.h"
-#endif
+#  if !defined(PDFTEXCOERCE) && !defined(PDFETEXCOERCE)
+#    ifdef pdfTeX
+#      undef pdfTeX             /* to avoid warning about redefining pdfTeX in pdftexd.h */
+#    endif                      /* pdfTeX */
+#    define EXTERN extern
+#    include "pdftexd.h"
+#  endif
 
 /* pdftexlib macros */
-#include "ptexmac.h"
+#  include "ptexmac.h"
 
+/* avl */
+#  include "avlstuff.h"
+
+
 /* pdftexlib type declarations */
 typedef struct {
     const char *pdfname;
@@ -44,17 +48,35 @@
 } key_entry;
 
 typedef struct {
-    boolean loaded;                 /* the encoding has been loaded? */
-    boolean updated;                /* glyph names have been updated for 0--32 chars? */
-    internalfontnumber firstfont;   /* first font that has accessed to this
-                                       encoding; move chars 0--32 to higher
-                                       area according to this font */
-    char *name;                     /* encoding file name */
-    integer objnum;                 /* object number */
+    boolean loaded;             /* the encoding has been loaded? */
+    char *name;                 /* encoding file name */
+    integer objnum;             /* object number */
     char **glyph_names;
+    integer tounicode;          /* object number of associated ToUnicode entry */
 } enc_entry;
 
+struct _subfont_entry;
+typedef struct _subfont_entry subfont_entry;
+
+struct _subfont_entry {
+    char *infix;                /* infix for this subfont, eg "01" */
+    long charcodes[256];        /* the mapping for this subfont as read from sfd */
+    subfont_entry *next;
+};
+
 typedef struct {
+    char *name;                 /* sfd name, eg "Unicode" */
+    subfont_entry *subfont;     /* linked list of subfonts */
+} sfd_entry;
+
+typedef struct {
+    char *name;                 /* glyph name */
+    long code;                  /* -1 = undefined; -2 = multiple codes, stored
+                                   as string in unicode_seq; otherwise unicode value */
+    char *unicode_seq;          /* multiple unicode sequence */
+} glyph_unicode_entry;
+
+typedef struct {
     char *tfm_name;             /* TFM file name */
     char *ps_name;              /* PostScript name */
     integer flags;              /* font flags */
@@ -72,6 +94,9 @@
     boolean all_glyphs;         /* embed all glyphs? */
     unsigned short links;       /* link flags from tfm_tree and ps_tree */
     short tfm_avail;            /* flags whether a tfm is available */
+    short pid;                  /* Pid for truetype fonts */
+    short eid;                  /* Eid for truetype fonts */
+    subfont_entry *subfont;     /* subfont mapping */
 } fm_entry;
 
 typedef struct {
@@ -79,16 +104,10 @@
     char *ff_path;              /* full path to font file */
 } ff_entry;
 
-typedef short shalfword ;
+typedef short shalfword;
 typedef struct {
-   integer charcode,
-           cwidth, 
-           cheight,
-           xoff, 
-           yoff, 
-           xescape,
-           rastersize;
-   halfword *raster;
+    integer charcode, cwidth, cheight, xoff, yoff, xescape, rastersize;
+    halfword *raster;
 } chardesc;
 
 /* pdftexlib variable declarations */
@@ -111,116 +130,146 @@
 /* pdftexlib function prototypes */
 
 /* epdf.c */
-extern integer get_fontfile_num(int);
-extern integer get_fontname_num(int);
-extern void epdf_free(void);
+extern integer get_fontfile_num (int);
+extern integer get_fontname_num (int);
+extern void epdf_free (void);
+extern int is_type1 (fm_entry *);
 
 /* mapfile.c */
-extern char *mk_basename(char *);
-extern char *mk_exname(char *, int);
-extern fm_entry * lookup_fontmap(char *);
-extern boolean hasfmentry(internalfontnumber);
-extern internalfontnumber tfmoffm(fmentryptr);
-extern void checkextfm(strnumber, integer);
-extern void fm_free(void);
-extern void fm_read_info(void);
-extern ff_entry * check_ff_exist(fm_entry *);
-extern void pdfmapfile(integer);
-extern void pdfmapline(integer);
+extern char *mk_basename (char *);
+extern char *mk_exname (char *, int);
+extern fm_entry *lookup_fontmap (char *);
+extern boolean hasfmentry (internalfontnumber);
+extern internalfontnumber tfmoffm (fmentryptr);
+extern void checkextfm (strnumber, integer);
+extern void fm_free (void);
+extern void fm_read_info (void);
+extern ff_entry *check_ff_exist (fm_entry *);
+extern void pdfmapfile (integer);
+extern void pdfmapline (integer);
+extern void pdfinitmapfile (string map_name);
+extern fm_entry *new_fm_entry (void);
+extern void delete_fm_entry (fm_entry *);
+extern int avl_do_entry (fm_entry *, int);
 
 /* papersiz.c */
-extern integer myatodim(char **);
-extern integer myatol(char **);
+extern integer myatodim (char **);
+extern integer myatol (char **);
 
 /* pkin.c */
-extern int readchar(boolean, chardesc *);
+extern int readchar (boolean, chardesc *);
 
+/* subfont.c */
+extern void sfd_free (void);
+extern boolean handle_subfont_fm (fm_entry *, int);
+
+/* tounicode.c */
+extern void glyph_unicode_free (void);
+extern void deftounicode (strnumber, strnumber);
+extern integer write_tounicode (char **, char *);
+
 /* utils.c */
-extern boolean str_eq_cstr(strnumber, char *);
-extern char *makecstring(integer);
-extern int xfflush(FILE *);
-extern int xgetc(FILE *);
-extern int xputc(int, FILE *);
-extern scaled extxnoverd(scaled, scaled, scaled);
-extern size_t xfwrite(void *, size_t size, size_t nmemb, FILE *);
-extern strnumber getresnameprefix(void);
-extern strnumber maketexstring(const char *);
-extern integer fb_offset(void);
-extern void fb_flush(void);
-extern void fb_putchar(eightbits b);
-extern void fb_seek(integer);
-extern void libpdffinish(void);
-extern void make_subset_tag(fm_entry *, char **);
-extern void pdf_printf(const char *,...);
-extern void pdf_puts(const char *);
-extern void pdftex_fail(const char *,...);
-extern void pdftex_warn(const char *,...);
-extern void setjobid(int, int, int, int, int, int);
-extern void tex_printf(const char *, ...);
-extern void writestreamlength(integer, integer);
-extern char *convertStringToPDFString(char *in);
-extern void printID(strnumber);
+extern boolean str_eq_cstr (strnumber, char *);
+extern char *makecstring (integer);
+extern int xfflush (FILE *);
+extern int xgetc (FILE *);
+extern int xputc (int, FILE *);
+extern scaled extxnoverd (scaled, scaled, scaled);
+extern size_t xfwrite (void *, size_t size, size_t nmemb, FILE *);
+extern strnumber getresnameprefix (void);
+extern strnumber maketexstring (const char *);
+extern integer fb_offset (void);
+extern void fb_flush (void);
+extern void fb_putchar (eightbits b);
+extern void fb_seek (integer);
+extern void libpdffinish (void);
+extern char *makecfilename (strnumber s);
+extern void make_subset_tag (fm_entry *, char **);
+extern void pdf_printf (const char *, ...);
+extern void pdf_puts (const char *);
+extern void pdftex_fail (const char *, ...);
+extern void pdftex_warn (const char *, ...);
+extern void setjobid (int, int, int, int);
+extern void tex_printf (const char *, ...);
+extern void writestreamlength (integer, integer);
+extern char *convertStringToPDFString (const char *in, int len);
+extern void printID (strnumber);
+extern void printcreationdate ();
+extern void printmoddate ();
+extern void escapename (poolpointer in);
+extern void escapestring (poolpointer in);
+extern void escapehex (poolpointer in);
+extern void unescapehex (poolpointer in);
+extern void getcreationdate ();
+extern void getfilemoddate (strnumber s);
+extern void getfilesize (strnumber s);
+extern void getmd5sum (strnumber s, boolean file);
+extern void getfiledump (strnumber s, int offset, int length);
+extern void matchstrings (strnumber s, strnumber t, int subcount,
+                          boolean icase);
+extern void getmatch (int i);
+extern void makepdftexbanner (void);
+extern void initstarttime ();
 
 /* vfpacket.c */
-extern eightbits packetbyte(void);
-extern integer newvfpacket(internalfontnumber);
-extern void poppacketstate(void);
-extern void pushpacketstate(void);
-extern void startpacket(internalfontnumber, integer);
-extern void storepacket(integer, integer, integer);
-extern void vf_free(void);
+extern eightbits packetbyte (void);
+extern integer newvfpacket (internalfontnumber);
+extern void poppacketstate (void);
+extern void pushpacketstate (void);
+extern void startpacket (internalfontnumber, integer);
+extern void storepacket (integer, integer, integer);
+extern void vf_free (void);
 
 /* writeenc.c */
-extern boolean get_enc(fm_entry *);
-extern boolean indexed_enc(fm_entry *);
-extern enc_entry *add_enc(char *);
-extern void enc_free(void);
-extern void read_enc(enc_entry *);
-extern void setcharmap(internalfontnumber);
-extern void write_enc(char **, enc_entry *, integer);
+extern boolean indexed_enc (fm_entry *);
+extern enc_entry *add_enc (char *);
+extern void enc_free (void);
+extern void read_enc (enc_entry *);
+extern void write_enc (char **, enc_entry *, integer);
 
 /* writefont.c */
-extern void dopdffont(integer, internalfontnumber);
-extern void update_enc(internalfontnumber, char **);
+extern void dopdffont (integer, internalfontnumber);
 
 /* writeimg.c */
-extern boolean checkimageb(integer);
-extern boolean checkimagec(integer);
-extern boolean checkimagei(integer);
-extern boolean ispdfimage(integer);
-extern integer epdforigx(integer);
-extern integer epdforigy(integer);
-extern integer imageheight(integer);
-extern integer imagepages(integer);
-extern integer imagewidth(integer);
-extern integer imagexres(integer);
-extern integer imageyres(integer);
-extern integer readimage(strnumber, integer, strnumber, integer, integer, integer, integer);
-extern void deleteimage(integer);
-extern void img_free(void) ;
-extern void updateimageprocset(integer);
-extern void writeimage(integer);
+extern boolean checkimageb (integer);
+extern boolean checkimagec (integer);
+extern boolean checkimagei (integer);
+extern boolean ispdfimage (integer);
+extern integer epdforigx (integer);
+extern integer epdforigy (integer);
+extern integer imageheight (integer);
+extern integer imagepages (integer);
+extern integer imagewidth (integer);
+extern integer imagexres (integer);
+extern integer imageyres (integer);
+extern integer readimage (strnumber, integer, strnumber, integer, integer,
+                          integer, integer);
+extern void deleteimage (integer);
+extern void img_free (void);
+extern void updateimageprocset (integer);
+extern void writeimage (integer);
+extern integer imagecolordepth (integer img);
 
 /* writet1.c */
-extern boolean t1_read_enc(fm_entry *);
-extern boolean t1_subset(char *, char *, unsigned char *);
-extern void load_enc(char *, char **);
-extern void writet1(void);
-extern void t1_free(void);
+extern boolean t1_subset (char *, char *, unsigned char *);
+extern void load_enc (char *, char **);
+extern void writet1 (void);
+extern void t1_free (void);
 
 /* writet3.c */
-extern void writet3(int, internalfontnumber);
-extern scaled getpkcharwidth(internalfontnumber, scaled);
+extern void writet3 (int, internalfontnumber);
+extern scaled getpkcharwidth (internalfontnumber, scaled);
 
 /* writettf.c */
-extern void writettf(void);
-extern void writeotf(void);
+extern void writettf (void);
+extern void writeotf (void);
+extern void ttf_free (void);
 
 /* writezip.c */
-extern void writezip(boolean);
+extern void writezip (boolean);
 
 /* avlstuff.c */
-extern void avlputobj(integer, integer);
-extern integer avlfindobj(integer, integer, integer);
+extern void avlputobj (integer, integer);
+extern integer avlfindobj (integer, integer, integer);
 
-#endif  /* PDFTEXLIB */
+#endif                          /* PDFTEXLIB */

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ptexmac.h
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ptexmac.h	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ptexmac.h	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 1996-2004 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2006 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -17,67 +17,74 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/ptexmac.h#14 $
+$Id: ptexmac.h,v 1.14 2005/11/29 22:05:23 hahe Exp $
 */
 
 #ifndef PDFTEXMAC
-#define PDFTEXMAC
+#  define PDFTEXMAC
 
 /* Not all systems define it. */
-#ifndef M_PI
-#define M_PI           3.14159265358979323846   /* pi */
-#define M_PI_2         1.5707963267948966192E0  /*Hex  2^ 0 * 1.921FB54442D18 */
-#define M_PI_4         7.8539816339744830962E-1 /*Hex  2^-1 * 1.921FB54442D18 */
-#endif
+#  ifndef M_PI
+#    define M_PI           3.14159265358979323846
+                                                /* pi */
+#    define M_PI_2         1.5707963267948966192E0
+                                                /*Hex  2^ 0 * 1.921FB54442D18 */
+#    define M_PI_4         7.8539816339744830962E-1
+                                                /*Hex  2^-1 * 1.921FB54442D18 */
+#  endif
 
-#ifdef WIN32
+#  ifdef WIN32
 // Why relying on gmalloc() ???
-#define gmalloc(n) xmalloc(n)
-#define gfree(p) free(p)
-#define inline __inline
-#define srandom(n) srand(n)
-#define random() rand()
-#endif
+#    define gmalloc(n) xmalloc(n)
+#    define gfree(p) free(p)
+#    define inline __inline
+#    define srandom(n) srand(n)
+#    define random() rand()
+#  endif
 
 /* Pascal WEB macros */
-#define maxinteger 0x7FFFFFFF
-#define maxdimen   0x3FFFFFFF
+#  define maxinteger 0x7FFFFFFF
+#  define maxdimen   0x3FFFFFFF
 
-#define objinfo(n) objtab[n].int0
+#  define objinfo(n) objtab[n].int0
 
-#define pdfroom(n) do {                                 \
-    if (pdfbufsize < n)                                 \
-        pdftex_fail("PDF output buffer overflowed");    \
-    if (pdfptr + n > pdfbufsize)                        \
-        pdfflush();                                     \
+#  define pdfroom(n) do {                                      \
+    if (n + pdfptr > pdfbufsize) {                           \
+        if (pdfosmode)                                       \
+            zpdfosgetosbuf(n);                               \
+        else {                                               \
+            if (n > pdfbufsize)                              \
+                pdftex_fail("PDF output buffer overflowed"); \
+            else                                             \
+                pdfflush();                                  \
+        }                                                    \
+    }                                                        \
 } while (0)
 
-#define pdfout(c)  do {             \
-    if (pdfptr > pdfbufsize)        \
-        pdfflush();                 \
-    pdfbuf[pdfptr++] = c;           \
+#  define pdfout(c)  do {   \
+    pdfroom(1);           \
+    pdfbuf[pdfptr++] = c; \
 } while (0)
 
-#define pdfoffset()     (pdfgone + pdfptr)
-#define pdfinitfont(f)  {tmpf = f; pdfcreatefontobj();}
+#  define pdfoffset()     (pdfgone + pdfptr)
+#  define pdfinitfont(f)  {tmpf = f; pdfcreatefontobj();}
 
-#define pdfmovechars        getintpar(cfgmovecharscode)
+#  define MAX_CHAR_CODE       255
+#  define PRINTF_BUF_SIZE     1024
+#  define MAX_CSTRING_LEN     1024 * 1024
+#  define MAX_PSTRING_LEN     1024
+#  define SMALL_BUF_SIZE      256
+#  define SMALL_ARRAY_SIZE    256
+#  define FONTNAME_BUF_SIZE   128
+                                /* a PDF name can be maximum 127 chars long */
 
-#define MAX_CHAR_CODE       255
-#define MOVE_CHARS_OFFSET   160
+#  define pdftex_debug    tex_printf
 
-#define PRINTF_BUF_SIZE     1024
-#define MAX_CSTRING_LEN     1024
-#define MAX_PSTRING_LEN     1024
-#define SMALL_BUF_SIZE      256
-#define SMALL_ARRAY_SIZE    256
-#define FONTNAME_BUF_SIZE   128 /* a PDF name can be maximum 127 chars long */
-
-#define check_buf(size, buf_size)                          \
+#  define check_buf(size, buf_size)                          \
     if ((size) > (buf_size))                               \
-        pdftex_fail("buffer overflow", (buf_size))
+        pdftex_fail("buffer overflow at file %s, line %d", __FILE__,  __LINE__ )
 
-#define append_char_to_buf(c, p, buf, buf_size) do {       \
+#  define append_char_to_buf(c, p, buf, buf_size) do {       \
     if (c == 9)                                            \
         c = 32;                                            \
     if (c == 13 || c == EOF)                               \
@@ -88,7 +95,7 @@
     }                                                      \
 } while (0)
 
-#define append_eol(p, buf, buf_size) do {                  \
+#  define append_eol(p, buf, buf_size) do {                  \
     check_buf(p - buf + 2, (buf_size));                    \
     if (p - buf > 1 && p[-1] != 10)                        \
         *p++ = 10;                                         \
@@ -99,16 +106,16 @@
     *p = 0;                                                \
 } while (0)
 
-#define remove_eol(p, buf) do {                            \
+#  define remove_eol(p, buf) do {                            \
     p = strend(buf) - 1;                                   \
     if (*p == 10)                                          \
         *p = 0;                                            \
 } while (0)
 
-#define skip(p, c)   if (*p == c)  p++
+#  define skip(p, c)   if (*p == c)  p++
 
-#define alloc_array(T, n, s) do {                           \
-    if (T##_array == NULL) {                                   \
+#  define alloc_array(T, n, s) do {                           \
+    if (T##_array == NULL) {                                \
         T##_limit = (s);                                    \
         if ((n) > T##_limit)                                \
             T##_limit = (n);                                \
@@ -120,79 +127,90 @@
         T##_limit *= 2;                                     \
         if (T##_ptr - T##_array + (n) > T##_limit)          \
             T##_limit = T##_ptr - T##_array + (n);          \
-        T##_array = xretalloc(T##_array, T##_limit, T##_entry); \
+        xretalloc(T##_array, T##_limit, T##_entry);         \
         T##_ptr = T##_array + last_ptr_index;               \
     }                                                       \
 } while (0)
 
-#define is_cfg_comment(c) \
+#  define is_cfg_comment(c) \
     (c == 10 || c == '*' || c == '#' || c == ';' || c == '%')
 
-#define define_array(T)                     \
+#  define define_array(T)                     \
 T##_entry      *T##_ptr, *T##_array = NULL;    \
 size_t          T##_limit
 
-#define xfree(p)            do { if (p != NULL) free(p); p = NULL; } while (0)
-#define strend(s)           strchr(s, 0)
-#define xtalloc             XTALLOC
-#define xretalloc           XRETALLOC
+#  define xfree(p)            do { if (p != NULL) free(p); p = NULL; } while (0)
+#  define strend(s)           strchr(s, 0)
+#  define xtalloc             XTALLOC
+#  define xretalloc           XRETALLOC
 
-#define ASCENT_CODE         0
-#define CAPHEIGHT_CODE      1
-#define DESCENT_CODE        2
-#define FONTNAME_CODE       3
-#define ITALIC_ANGLE_CODE   4
-#define STEMV_CODE          5
-#define XHEIGHT_CODE        6
-#define FONTBBOX1_CODE      7
-#define FONTBBOX2_CODE      8
-#define FONTBBOX3_CODE      9
-#define FONTBBOX4_CODE      10
-#define MAX_KEY_CODE        (FONTBBOX1_CODE + 1)
-#define FONT_KEYS_NUM       (FONTBBOX4_CODE + 1)
+#  define ASCENT_CODE         0
+#  define CAPHEIGHT_CODE      1
+#  define DESCENT_CODE        2
+#  define FONTNAME_CODE       3
+#  define ITALIC_ANGLE_CODE   4
+#  define STEMV_CODE          5
+#  define XHEIGHT_CODE        6
+#  define FONTBBOX1_CODE      7
+#  define FONTBBOX2_CODE      8
+#  define FONTBBOX3_CODE      9
+#  define FONTBBOX4_CODE      10
+#  define MAX_KEY_CODE        (FONTBBOX1_CODE + 1)
+#  define FONT_KEYS_NUM       (FONTBBOX4_CODE + 1)
 
-#define F_INCLUDED          0x01
-#define F_SUBSETTED         0x02
-#define F_TRUETYPE          0x04
-#define F_BASEFONT          0x08
+#  define F_INCLUDED          0x01
+#  define F_SUBSETTED         0x02
+#  define F_TRUETYPE          0x04
+#  define F_BASEFONT          0x08
+#  define F_SUBFONT           0x10
 
-#define set_included(fm)    ((fm)->type |= F_INCLUDED)
-#define set_subsetted(fm)   ((fm)->type |= F_SUBSETTED)
-#define set_truetype(fm)    ((fm)->type |= F_TRUETYPE)
-#define set_basefont(fm)    ((fm)->type |= F_BASEFONT)
+#  define set_included(fm)    ((fm)->type |= F_INCLUDED)
+#  define set_subsetted(fm)   ((fm)->type |= F_SUBSETTED)
+#  define set_truetype(fm)    ((fm)->type |= F_TRUETYPE)
+#  define set_basefont(fm)    ((fm)->type |= F_BASEFONT)
+#  define set_subfont(fm)     ((fm)->type |= F_SUBFONT)
 
-#define unset_included(fm)  ((fm)->type &= ~F_INCLUDED)
-#define unset_subsetted(fm) ((fm)->type &= ~F_SUBSETTED)
-#define unset_truetype(fm)  ((fm)->type &= ~F_TRUETYPE)
-#define unset_basefont(fm)  ((fm)->type &= ~F_BASEFONT)
+#  define unset_included(fm)  ((fm)->type &= ~F_INCLUDED)
+#  define unset_subsetted(fm) ((fm)->type &= ~F_SUBSETTED)
+#  define unset_truetype(fm)  ((fm)->type &= ~F_TRUETYPE)
+#  define unset_basefont(fm)  ((fm)->type &= ~F_BASEFONT)
+#  define unset_subfont(fm)   ((fm)->type &= ~F_SUBFONT)
 
-#define unset_fontfile(fm)  xfree((fm)->ff_name)
+#  define unset_fontfile(fm)  xfree((fm)->ff_name)
 
-#define is_included(fm)     ((fm)->type & F_INCLUDED)
-#define is_subsetted(fm)    ((fm)->type & F_SUBSETTED)
-#define is_truetype(fm)     ((fm)->type & F_TRUETYPE)
-#define is_basefont(fm)     ((fm)->type & F_BASEFONT)
+#  define is_included(fm)     ((fm)->type & F_INCLUDED)
+#  define is_subsetted(fm)    ((fm)->type & F_SUBSETTED)
+#  define is_truetype(fm)     ((fm)->type & F_TRUETYPE)
+#  define is_basefont(fm)     ((fm)->type & F_BASEFONT)
+#  define is_subfont(fm)      ((fm)->type & F_SUBFONT)
+#  define no_font_desc(fm)    (is_basefont(fm) && !is_included(fm))
 
-#define fm_slant(fm)        (fm)->slant
-#define fm_extend(fm)       (fm)->extend
-#define fm_fontfile(fm)     (fm)->ff_name
+#  define fm_slant(fm)        (fm)->slant
+#  define fm_extend(fm)       (fm)->extend
+#  define fm_fontfile(fm)     (fm)->ff_name
 
-#define is_reencoded(fm)    ((fm)->encoding != NULL)
-#define is_fontfile(fm)     (fm_fontfile(fm) != NULL)
-#define is_t1fontfile(fm)   (is_fontfile(fm) && !is_truetype(fm))
+#  define is_reencoded(fm)    ((fm)->encoding != NULL)
+#  define is_fontfile(fm)     (fm_fontfile(fm) != NULL)
+#  define is_t1fontfile(fm)   (is_fontfile(fm) && !is_truetype(fm))
 
-#define LINK_TFM            0x01
-#define LINK_PS             0x02
-#define set_tfmlink(fm)     ((fm)->links |= LINK_TFM)
-#define set_pslink(fm)      ((fm)->links |= LINK_PS)
-#define unset_tfmlink(fm)   ((fm)->links &= ~LINK_TFM)
-#define unset_pslink(fm)    ((fm)->links &= ~LINK_PS)
-#define has_tfmlink(fm)     ((fm)->links & LINK_TFM)
-#define has_pslink(fm)      ((fm)->links & LINK_PS)
+#  define LINK_TFM            0x01
+#  define LINK_PS             0x02
+#  define set_tfmlink(fm)     ((fm)->links |= LINK_TFM)
+#  define set_pslink(fm)      ((fm)->links |= LINK_PS)
+#  define unset_tfmlink(fm)   ((fm)->links &= ~LINK_TFM)
+#  define unset_pslink(fm)    ((fm)->links &= ~LINK_PS)
+#  define has_tfmlink(fm)     ((fm)->links & LINK_TFM)
+#  define has_pslink(fm)      ((fm)->links & LINK_PS)
 
 
-#define set_cur_file_name(s)      \
+#  define set_cur_file_name(s)      \
     cur_file_name = s;      \
     packfilename(maketexstring(cur_file_name), getnullstr(), getnullstr())
 
-#endif  /* PDFTEXMAC */
+#  define cmp_return(a, b) \
+    if (a > b)           \
+        return 1;        \
+    if (a < b)           \
+        return -1
+
+#endif                          /* PDFTEXMAC */

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/tex.ch0
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/tex.ch0	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/tex.ch0	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,26 +17,26 @@
 % along with pdfTeX; if not, write to the Free Software
 % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 %
-% $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/tex.ch0#10 $
+% $Id: //depot/Build/source.development/TeX/texk/web2c/pdfetexdir/tex.ch0#10 $
 %
 % Change file to assist in creating the web2c-specific change file.
 % This one comes first, resolves inconsistencies between the generated
-% pdftex.web and tex.ch
+% pdfetex.web and tex.ch
 
 @x [1.2] l.188
 @d TeX_banner=='This is TeX, Version 3.141592' {printed when \TeX\ starts}
 @#
- at d banner==pdfTeX_banner
+ at d banner==pdfeTeX_banner
 @y
 @d banner=='This is TeX, Version 3.141592' {printed when \TeX\ starts}
 @z
 
- at x [17.236] l.4960 - first web2c, then pdfTeX additional integer parameters
+ at x [17.236] l.4960 - first web2c, then pdfTeX, then e-TeX additional integer parameters
 @d tex_int_pars=55 {total number of \TeX's integer parameters}
 @#
 @d pdftex_first_integer_code = tex_int_pars {base for \pdfTeX's integer parameters}
 @y
 @d int_pars=55 {total number of integer parameters}
 @#
- at d pdftex_first_integer_code = tex_int_pars {base for \pdfTeX's integer parameters}
+ at d etex_int_base=tex_int_pars {base for \eTeX's integer parameters}
 @z

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ttf2afm.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ttf2afm.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/ttf2afm.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 1996-2005 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2006 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -17,7 +17,7 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/ttf2afm.c#15 $
+$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/ttf2afm.c#21 $
 */
 
 /*
@@ -33,19 +33,24 @@
 */
 #include <kpathsea/kpathsea.h>
 #include <time.h>
+#include <libgen.h>
 #include <pdftexdir/ptexmac.h>
 #include <pdftexdir/writettf.h>
+#include <string.h>
 
-static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/ttf2afm.c#15 $";
+static const char perforce_id[] =
+    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/ttf2afm.c#21 $";
 
 /* constants used for print_glyph */
 #define AS_NAME         0
 #define AS_INDEX        1
 #define AS_UNICODE      2
 
-#define VERSION         "1.0"
+#define VERSION         "1.02"
 
+/* FIXME */
+#define NOGLYPH_ASSIGNED_YET USHRT_MAX
+
 #define enc_getchar()   xgetc(encfile)
 #define enc_eof()       feof(encfile)
 #define pdftex_fail     ttf_fail
@@ -102,11 +107,11 @@
 char *bname = NULL;
 FILE *fontfile, *encfile, *outfile = NULL;
 char enc_line[ENC_BUF_SIZE];
-int print_glyph = AS_NAME;    /* print glyph as names by default*/
+int print_glyph = AS_NAME;      /* print glyph as names by default */
 int print_cmap = 0;
-int use_ext_enc = 0;    /* use external encoding? */
-int select_unicode = 1; /* use the first unicode mapping by default */
-int printing_enc = 0; /* set to 1 while printing encodings */
+int use_ext_enc = 0;            /* use external encoding? */
+int select_unicode = 1;         /* use the first unicode mapping by default */
+int printing_enc = 0;           /* set to 1 while printing encodings */
 
 
 TTF_USHORT upem;
@@ -121,7 +126,7 @@
 dirtab_entry *dir_tab;
 mtx_entry *mtx_tab;
 kern_entry *kern_tab;
-char *enc_names[MAX_CHAR_CODE + 1];
+char *enc_names[256];
 
 cmap_entry *cmap_tab;
 TTF_USHORT ncmapsubtabs;
@@ -131,92 +136,92 @@
 
 #include "macnames.c"
 
-void ttf_fail(char *fmt,...)
+void ttf_fail (char *fmt, ...)
 {
     va_list args;
-    va_start(args, fmt);
-    fprintf(stderr, "\nError: ttf2afm");
+    va_start (args, fmt);
+    fprintf (stderr, "\nError: ttf2afm");
     if (cur_file_name)
-        fprintf(stderr, " (file %s)", cur_file_name);
-    fprintf(stderr, ": ");
-    vfprintf(stderr, fmt, args);
-    fprintf(stderr, "\n");
-    va_end(args);
-    exit(-1);
+        fprintf (stderr, " (file %s)", cur_file_name);
+    fprintf (stderr, ": ");
+    vfprintf (stderr, fmt, args);
+    fprintf (stderr, "\n");
+    va_end (args);
+    exit (-1);
 }
 
-void ttf_warn(char *fmt,...)
+void ttf_warn (char *fmt, ...)
 {
     va_list args;
-    va_start(args, fmt);
-    fprintf(stderr, "\nWarning: ttf2afm");
+    va_start (args, fmt);
+    fprintf (stderr, "\nWarning: ttf2afm");
     if (cur_file_name)
-        fprintf(stderr, " (file %s)", cur_file_name);
-    fprintf(stderr, ": ");
-    vfprintf(stderr, fmt, args);
-    fprintf(stderr, "\n");
-    va_end(args);
+        fprintf (stderr, " (file %s)", cur_file_name);
+    fprintf (stderr, ": ");
+    vfprintf (stderr, fmt, args);
+    fprintf (stderr, "\n");
+    va_end (args);
 }
 
-int xgetc(FILE *stream)
+int xgetc (FILE * stream)
 {
-    int c = getc(stream);
+    int c = getc (stream);
     if (c < 0 && c != EOF)
-        ttf_fail("getc() failed");
+        ttf_fail ("getc() failed");
     return c;
 }
 
-long ttf_getnum(int s)
+long ttf_getnum (int s)
 {
     long i = 0;
     int c;
     while (s > 0) {
-        if ((c = xgetc(fontfile)) < 0)
-            ttf_fail("unexpected EOF");
+        if ((c = xgetc (fontfile)) < 0)
+            ttf_fail ("unexpected EOF");
         i = (i << 8) + c;
         s--;
     }
     return i;
 }
 
-dirtab_entry *name_lookup(char *s)
+dirtab_entry *name_lookup (char *s)
 {
     dirtab_entry *p;
     for (p = dir_tab; p - dir_tab < ntabs; p++)
-        if (strncmp(p->tag, s, 4) == 0)
+        if (strncmp (p->tag, s, 4) == 0)
             break;
     if (p - dir_tab == ntabs)
         p = NULL;
     return p;
 }
 
-void ttf_seek_tab(char *name, TTF_LONG offset)
+void ttf_seek_tab (char *name, TTF_LONG offset)
 {
-    dirtab_entry *p = name_lookup(name);
+    dirtab_entry *p = name_lookup (name);
     if (p == NULL)
-        ttf_fail("can't find table `%s'", name);
-    if (fseek(fontfile, p->offset + offset, SEEK_SET) < 0)
-        ttf_fail("fseek() failed while reading `%s' table", name);
+        ttf_fail ("can't find table `%s'", name);
+    if (fseek (fontfile, p->offset + offset, SEEK_SET) < 0)
+        ttf_fail ("fseek() failed while reading `%s' table", name);
 }
 
-void ttf_seek_off(char *name, TTF_LONG offset)
+void ttf_seek_off (char *name, TTF_LONG offset)
 {
-    if (fseek(fontfile, offset, SEEK_SET) < 0)
-        ttf_fail("fseek() failed while reading `%s' table", name);
+    if (fseek (fontfile, offset, SEEK_SET) < 0)
+        ttf_fail ("fseek() failed while reading `%s' table", name);
 }
 
-void store_kern_value(TTF_USHORT i, TTF_USHORT j, TTF_FWORD v)
+void store_kern_value (TTF_USHORT i, TTF_USHORT j, TTF_FWORD v)
 {
     kern_entry *pk;
     for (pk = kern_tab + i; pk->next != NULL; pk = pk->next);
-    pk->next = xtalloc(1, kern_entry);
+    pk->next = xtalloc (1, kern_entry);
     pk = pk->next;
     pk->next = NULL;
     pk->adjacent = j;
     pk->value = v;
 }
 
-TTF_FWORD get_kern_value(TTF_USHORT i, TTF_USHORT j)
+TTF_FWORD get_kern_value (TTF_USHORT i, TTF_USHORT j)
 {
     kern_entry *pk;
     for (pk = kern_tab + i; pk->next != NULL; pk = pk->next)
@@ -225,104 +230,108 @@
     return 0;
 }
 
-void free_tabs()
+void free_tabs ()
 {
     int i;
     kern_entry *p, *q, *r;
     unicode_entry *u, *v;
     mtx_entry *pm;
-    xfree(ps_glyphs_buf);
-    xfree(dir_tab);
-    xfree(cmap_tab);
+    xfree (ps_glyphs_buf);
+    xfree (dir_tab);
+    xfree (cmap_tab);
     for (pm = mtx_tab; pm - mtx_tab < nglyphs; pm++)
         if (pm->unicode_list != NULL) {
             for (u = pm->unicode_list; u != NULL; u = v) {
                 v = u->next;
-                xfree(u);
+                xfree (u);
             }
         }
-    xfree(mtx_tab);
-    for (i = 0; i <= MAX_CHAR_CODE; i++)
+    xfree (mtx_tab);
+    for (i = 0; i < 256; i++)
         if (enc_names[i] != notdef)
-            free(enc_names[i]);
+            free (enc_names[i]);
     if (kern_tab == NULL)
         return;
     for (p = kern_tab; p - kern_tab < nglyphs; p++)
         if (p->next != NULL) {
             for (q = p->next; q != NULL; q = r) {
                 r = q->next;
-                xfree(q);
+                xfree (q);
             }
         }
-    xfree(kern_tab);
+    xfree (kern_tab);
 }
 
-void enc_getline()
+void enc_getline ()
 {
     char *p;
     int c;
-restart:
-    if (enc_eof())
-        ttf_fail("unexpected end of file");
+  restart:
+    if (enc_eof ())
+        ttf_fail ("unexpected end of file");
     p = enc_line;
     do {
-        c = enc_getchar();
-        append_char_to_buf(c, p, enc_line, ENC_BUF_SIZE);
+        c = enc_getchar ();
+        append_char_to_buf (c, p, enc_line, ENC_BUF_SIZE);
     } while (c != 10);
-    append_eol(p, enc_line, ENC_BUF_SIZE);
+    append_eol (p, enc_line, ENC_BUF_SIZE);
     if (p - enc_line <= 2 || *enc_line == '%')
         goto restart;
 }
 
-void read_encoding(char *encname)
+void read_encoding (char *encname)
 {
     char buf[ENC_BUF_SIZE], *q, *r;
     int i;
     cur_file_name = encname;
-    if ((encfile = kpse_open_file(encname, kpse_enc_format)) == NULL)
-        ttf_fail("can't open encoding file for reading");
-    enc_getline();
-    if (*enc_line != '/' || (r = strchr(enc_line, '[')) == 0)
-        ttf_fail("invalid encoding vector: name or `[' missing:\n%s", enc_line);
-    for (i = 0; i <= MAX_CHAR_CODE; i++)
-        enc_names[i] = (char*) notdef;
+    if ((encfile = kpse_open_file (encname, kpse_enc_format)) == NULL)
+        ttf_fail ("can't open encoding file for reading");
+    enc_getline ();
+    if (*enc_line != '/' || (r = strchr (enc_line, '[')) == 0)
+        ttf_fail ("invalid encoding vector: name or `[' missing:\n%s",
+                  enc_line);
+    for (i = 0; i < 256; i++)
+        enc_names[i] = (char *) notdef;
     if (r[1] == 32)
         r += 2;
     else
         r++;
     for (;;) {
         while (*r == '/') {
-            for (q = buf, r++; *r != ' ' && *r != 10 && *r != ']' && *r != '/'; *q++ = *r++);
+            for (q = buf, r++; *r != ' ' && *r != 10 && *r != ']' && *r != '/';
+                 *q++ = *r++);
             *q = 0;
             if (*r == ' ')
                 r++;
-            if (strcmp(buf, notdef) != 0)
-                enc_names[names_count] = xstrdup(buf);
-            if (names_count++ > MAX_CHAR_CODE)
-                ttf_fail("encoding vector contains more than %i names",
-                     (int)(MAX_CHAR_CODE + 1));
+            if (strcmp (buf, notdef) != 0)
+                enc_names[names_count] = xstrdup (buf);
+            if (++names_count > 256)
+                ttf_fail ("encoding vector contains more than 256 names");
         }
-        if (*r != 10 && *r != '%')
-            if (strncmp(r, "] def", strlen("] def")) == 0)
+        if (*r != 10 && *r != '%') {
+            if (strncmp (r, "] def", strlen ("] def")) == 0)
                 goto done;
             else
-                ttf_fail("invalid encoding vector: a name or `] def' expected:\n%s", enc_line);
-        enc_getline();
+                ttf_fail
+                    ("invalid encoding vector: a name or `] def' expected:\n%s",
+                     enc_line);
+        }
+        enc_getline ();
         r = enc_line;
     }
-done:
-    xfclose(encfile, cur_file_name);
-    if (names_count != MAX_CHAR_CODE + 1)
-        ttf_warn("encoding vector contains only %i names (expected %i)", 
-                 names_count, MAX_CHAR_CODE + 1);
+  done:
+    xfclose (encfile, cur_file_name);
+    if (names_count != 256)
+        ttf_warn ("encoding vector contains only %i names (expected %i)",
+                  names_count, 256);
 }
 
-void append_unicode(long glyph_index, TTF_USHORT code)
+void append_unicode (long glyph_index, TTF_USHORT code)
 {
     mtx_entry *m;
     unicode_entry *u, *v;
-    assert(glyph_index >= 0 && glyph_index < nglyphs);
-    u = xtalloc(1, unicode_entry), *v;
+    assert (glyph_index >= 0 && glyph_index < nglyphs);
+    u = xtalloc (1, unicode_entry);
     m = mtx_tab + glyph_index;
     u->next = NULL;
     u->code = code;
@@ -334,55 +343,55 @@
     }
 }
 
-void read_cmap()
+void read_cmap ()
 {
     cmap_entry *e;
     seg_entry *seg_tab, *s;
     TTF_USHORT *glyphId, format, segCount;
-    long int n, i, j, k, first_code, length, last_sep, index;
+    long int n, i, k, length, index;
     int unicode_map_count = 0;
-    ttf_seek_tab("cmap", TTF_USHORT_SIZE); /* skip the table vesrion number (=0) */
-    ncmapsubtabs = get_ushort();
-    cmap_offset = xftell(fontfile, cur_file_name) - 2*TTF_USHORT_SIZE;
-    cmap_tab = xtalloc(ncmapsubtabs, cmap_entry);
+    ttf_seek_tab ("cmap", TTF_USHORT_SIZE);     /* skip the table vesrion number (=0) */
+    ncmapsubtabs = get_ushort ();
+    cmap_offset = xftell (fontfile, cur_file_name) - 2 * TTF_USHORT_SIZE;
+    cmap_tab = xtalloc (ncmapsubtabs, cmap_entry);
     for (e = cmap_tab; e - cmap_tab < ncmapsubtabs; e++) {
-        e->platform_id = get_ushort();
-        e->encoding_id = get_ushort();
-        e->offset = get_ulong();
+        e->platform_id = get_ushort ();
+        e->encoding_id = get_ushort ();
+        e->offset = get_ulong ();
     }
     for (i = 0; i < 0xFFFF; ++i)
         unicode_map[i] = NOGLYPH_ASSIGNED_YET;
     for (e = cmap_tab; e - cmap_tab < ncmapsubtabs; e++) {
-        ttf_seek_off("cmap", cmap_offset + e->offset);
-        format = get_ushort();
-        if (is_unicode_mapping(e) && format == 4) {
+        ttf_seek_off ("cmap", cmap_offset + e->offset);
+        format = get_ushort ();
+        if (is_unicode_mapping (e) && format == 4) {
             ++unicode_map_count;
             if (unicode_map_count == select_unicode)
                 goto read_unicode_mapping;
         }
         continue;
-read_unicode_mapping:
-        length = get_ushort(); /* length of subtable */
-        get_ushort(); /* skip the version number */
-        segCount = get_ushort()/2;
-        get_ushort(); /* skip searchRange */
-        get_ushort(); /* skip entrySelector */
-        get_ushort(); /* skip rangeShift */
-        seg_tab = xtalloc(segCount, seg_entry);
+      read_unicode_mapping:
+        length = get_ushort (); /* length of subtable */
+        (void) get_ushort ();   /* skip the version number */
+        segCount = get_ushort () / 2;
+        (void) get_ushort ();   /* skip searchRange */
+        (void) get_ushort ();   /* skip entrySelector */
+        (void) get_ushort ();   /* skip rangeShift */
+        seg_tab = xtalloc (segCount, seg_entry);
         for (s = seg_tab; s - seg_tab < segCount; s++)
-            s->endCode = get_ushort();
-        get_ushort(); /* skip reversedPad */
+            s->endCode = get_ushort ();
+        (void) get_ushort ();   /* skip reversedPad */
         for (s = seg_tab; s - seg_tab < segCount; s++)
-            s->startCode = get_ushort();
+            s->startCode = get_ushort ();
         for (s = seg_tab; s - seg_tab < segCount; s++)
-            s->idDelta = get_ushort();
+            s->idDelta = get_ushort ();
         for (s = seg_tab; s - seg_tab < segCount; s++)
-            s->idRangeOffset = get_ushort();
-        length -= 8*TTF_USHORT_SIZE + 4*segCount*TTF_USHORT_SIZE;
-        n = length/TTF_USHORT_SIZE; /* number of glyphID's */
-        glyphId = xtalloc(n, TTF_USHORT);
+            s->idRangeOffset = get_ushort ();
+        length -= 8 * TTF_USHORT_SIZE + 4 * segCount * TTF_USHORT_SIZE;
+        n = length / TTF_USHORT_SIZE;   /* number of glyphID's */
+        glyphId = xtalloc (n, TTF_USHORT);
         for (i = 0; i < n; i++)
-            glyphId[i] = get_ushort();
+            glyphId[i] = get_ushort ();
         for (s = seg_tab; s - seg_tab < segCount; s++) {
             for (i = s->startCode; i <= s->endCode; i++) {
                 if (i == 0xFFFF)
@@ -391,34 +400,37 @@
                     if (s->idRangeOffset == 0)
                         index = (s->idDelta + i) & 0xFFFF;
                     else {
-                        k = (i - s->startCode) + s->idRangeOffset/2 + 
-                            (s - seg_tab) - segCount ;
-                        assert(k >= 0 && k < n);
+                        k = (i - s->startCode) + s->idRangeOffset / 2 +
+                            (s - seg_tab) - segCount;
+                        assert (k >= 0 && k < n);
                         index = glyphId[k];
                         if (index != 0)
                             index = (index + s->idDelta) & 0xFFFF;
                     }
                     if (index < 0 || index >= nglyphs)
-                        ttf_fail("cmap: glyph index out of range [0..%i)", nglyphs);
+                        ttf_fail ("cmap: glyph index out of range [0..%i)",
+                                  nglyphs);
                     if (unicode_map[i] != NOGLYPH_ASSIGNED_YET)
-                        ttf_fail("cmap: unicode %.4X is mapped to multiple glyphs", i);
+                        ttf_fail
+                            ("cmap: unicode %.4X is mapped to multiple glyphs",
+                             i);
                     if (unicode_map[i] == 0)
-                        ttf_warn("unicode %.4X is mapped to glyph 0", i);
+                        ttf_warn ("unicode %.4X is mapped to glyph 0", i);
                     unicode_map[i] = index;
-                    append_unicode(index, i);
+                    append_unicode (index, i);
                 }
             }
         }
-        xfree(seg_tab);
-        xfree(glyphId);
+        xfree (seg_tab);
+        xfree (glyphId);
         break;
     }
     if (e - cmap_tab == ncmapsubtabs)
-        ttf_fail("Invalid argument `-m %i': out of range [1..%i]",
-                 select_unicode, unicode_map_count);
+        ttf_fail ("Invalid argument `-m %i': out of range [1..%i]",
+                  select_unicode, unicode_map_count);
 }
 
-void read_font()
+void read_font ()
 {
     long i, j, k, l, n, m, platform_id, encoding_id;
     TTF_FWORD kern_value;
@@ -426,508 +438,554 @@
     dirtab_entry *pd;
     kern_entry *pk;
     mtx_entry *pm;
-    ttf_skip(TTF_FIXED_SIZE);
-    ntabs = get_ushort();
-    ttf_skip(3*TTF_USHORT_SIZE);
-    dir_tab = xtalloc(ntabs, dirtab_entry);
+    ttf_skip (TTF_FIXED_SIZE);
+    ntabs = get_ushort ();
+    ttf_skip (3 * TTF_USHORT_SIZE);
+    dir_tab = xtalloc (ntabs, dirtab_entry);
     for (pd = dir_tab; pd - dir_tab < ntabs; pd++) {
-        pd->tag[0] = get_char();
-        pd->tag[1] = get_char();
-        pd->tag[2] = get_char();
-        pd->tag[3] = get_char();
-        ttf_skip(TTF_ULONG_SIZE);
-        pd->offset = get_ulong();
-        pd->length = get_ulong();
+        pd->tag[0] = get_char ();
+        pd->tag[1] = get_char ();
+        pd->tag[2] = get_char ();
+        pd->tag[3] = get_char ();
+        ttf_skip (TTF_ULONG_SIZE);
+        pd->offset = get_ulong ();
+        pd->length = get_ulong ();
     }
-    ttf_seek_tab("head", 2*TTF_FIXED_SIZE + 2*TTF_ULONG_SIZE + TTF_USHORT_SIZE);
-    upem = get_ushort();
-    ttf_skip(16);
-    FontBBox1 = get_fword();
-    FontBBox2 = get_fword();
-    FontBBox3 = get_fword();
-    FontBBox4 = get_fword();
-    ttf_skip(TTF_USHORT_SIZE);
-    ttf_skip(TTF_USHORT_SIZE + TTF_SHORT_SIZE);
-    loca_format = get_short();
-    ttf_seek_tab("maxp", TTF_FIXED_SIZE);
-    nglyphs = get_ushort();
-    mtx_tab = xtalloc(nglyphs + 1, mtx_entry);
+    ttf_seek_tab ("head",
+                  2 * TTF_FIXED_SIZE + 2 * TTF_ULONG_SIZE + TTF_USHORT_SIZE);
+    upem = get_ushort ();
+    ttf_skip (16);
+    FontBBox1 = get_fword ();
+    FontBBox2 = get_fword ();
+    FontBBox3 = get_fword ();
+    FontBBox4 = get_fword ();
+    ttf_skip (TTF_USHORT_SIZE);
+    ttf_skip (TTF_USHORT_SIZE + TTF_SHORT_SIZE);
+    loca_format = get_short ();
+    ttf_seek_tab ("maxp", TTF_FIXED_SIZE);
+    nglyphs = get_ushort ();
+    mtx_tab = xtalloc (nglyphs + 1, mtx_entry);
     for (pm = mtx_tab; pm - mtx_tab < nglyphs + 1; pm++) {
-        pm->name = NULL; /* notdef */
+        pm->name = NULL;        /* notdef */
         pm->found = 0;
         pm->unicode_list = NULL;
     }
-    ttf_seek_tab("hhea", TTF_FIXED_SIZE);
-    Ascender = get_fword();
-    Descender = get_fword();
-    ttf_skip(TTF_FWORD_SIZE + TTF_UFWORD_SIZE + 3*TTF_FWORD_SIZE + 8*TTF_SHORT_SIZE);
-    nhmtx = get_ushort();
-    ttf_seek_tab("hmtx", 0);
+    ttf_seek_tab ("hhea", TTF_FIXED_SIZE);
+    Ascender = get_fword ();
+    Descender = get_fword ();
+    ttf_skip (TTF_FWORD_SIZE + TTF_UFWORD_SIZE + 3 * TTF_FWORD_SIZE +
+              8 * TTF_SHORT_SIZE);
+    nhmtx = get_ushort ();
+    ttf_seek_tab ("hmtx", 0);
     for (pm = mtx_tab; pm - mtx_tab < nhmtx; pm++) {
-        pm->wx = get_ufword();
-        ttf_skip(TTF_FWORD_SIZE);
+        pm->wx = get_ufword ();
+        ttf_skip (TTF_FWORD_SIZE);
     }
     i = pm[-1].wx;
     for (; pm - mtx_tab < nglyphs; pm++)
         pm->wx = i;
-    ttf_seek_tab("post", 0);
-    post_format = get_fixed();
-    ItalicAngle = get_fixed();
-    UnderlinePosition = get_fword();
-    UnderlineThickness = get_fword();
-    IsFixedPitch = get_ulong();
-    ttf_skip(4*TTF_ULONG_SIZE);
+    ttf_seek_tab ("post", 0);
+    post_format = get_fixed ();
+    ItalicAngle = get_fixed ();
+    UnderlinePosition = get_fword ();
+    UnderlineThickness = get_fword ();
+    IsFixedPitch = get_ulong ();
+    ttf_skip (4 * TTF_ULONG_SIZE);
     switch (post_format) {
     case 0x00010000:
         for (pm = mtx_tab; pm - mtx_tab < NMACGLYPHS; pm++)
-            pm->name = mac_glyph_names[pm - mtx_tab];
+            pm->name = (char *) mac_glyph_names[pm - mtx_tab];
         break;
     case 0x00020000:
-        l = get_ushort(); /* some fonts have this value different from nglyphs */
+        l = get_ushort ();      /* some fonts have this value different from nglyphs */
         for (pm = mtx_tab; pm - mtx_tab < l; pm++)
-            pm->index = get_ushort();
-        if ((pd = name_lookup("post")) == NULL)
-            ttf_fail("can't find table `post'");
-        n = pd->length - (xftell(fontfile, cur_file_name) - pd->offset);
-        ps_glyphs_buf = xtalloc(n + 1, char);
+            pm->index = get_ushort ();
+        if ((pd = name_lookup ("post")) == NULL)
+            ttf_fail ("can't find table `post'");
+        n = pd->length - (xftell (fontfile, cur_file_name) - pd->offset);
+        ps_glyphs_buf = xtalloc (n + 1, char);
         for (m = 0, p = ps_glyphs_buf; p - ps_glyphs_buf < n;) {
-            for (i = get_byte(); i > 0; i--)
-                *p++ = get_char();
+            for (i = get_byte (); i > 0; i--)
+                *p++ = get_char ();
             *p++ = 0;
             m++;
         }
         for (pm = mtx_tab; pm - mtx_tab < l; pm++) {
             if (pm->index < NMACGLYPHS)
-                pm->name = mac_glyph_names[pm->index];
+                pm->name = (char *) mac_glyph_names[pm->index];
             else {
                 k = pm->index - NMACGLYPHS;
                 if (k < m) {
                     for (p = ps_glyphs_buf; k > 0; k--)
-                        p = (char *)strend(p) + 1;
+                        p = (char *) strend (p) + 1;
                     pm->name = p;
+                } else {
+                    pm->name = NULL;    /* index out of valid range, fix name to notdef */
                 }
-                else {
-                    pm->name = NULL; /* index out of valid range, fix name to notdef */
-                }
             }
         }
         break;
     case 0x00030000:
         if (print_glyph == AS_NAME) {
-            ttf_warn("no names available in `post' table, print glyph names as indices");
+            ttf_warn
+                ("no names available in `post' table, print glyph names as indices");
             print_glyph = AS_INDEX;
         }
         break;
     default:
-        ttf_fail("unsupported format (%.8X) of `post' table", post_format);
+        ttf_fail ("unsupported format (%.8X) of `post' table", post_format);
     }
-    ttf_seek_tab("loca", 0);
+    ttf_seek_tab ("loca", 0);
     for (pm = mtx_tab; pm - mtx_tab < nglyphs + 1; pm++)
-        pm->offset = (loca_format == 1 ? get_ulong() : get_ushort() << 1);
-    if ((pd = name_lookup("glyf")) == NULL)
-        ttf_fail("can't find table `glyf'");
+        pm->offset = (loca_format == 1 ? get_ulong () : get_ushort () << 1);
+    if ((pd = name_lookup ("glyf")) == NULL)
+        ttf_fail ("can't find table `glyf'");
     for (n = pd->offset, pm = mtx_tab; pm - mtx_tab < nglyphs; pm++) {
-        ttf_seek_off("glyf", n + pm->offset);
-        ttf_skip(TTF_SHORT_SIZE);
-        pm->bbox[0] = get_fword();
-        pm->bbox[1] = get_fword();
-        pm->bbox[2] = get_fword();
-        pm->bbox[3] = get_fword();
+        ttf_seek_off ("glyf", n + pm->offset);
+        ttf_skip (TTF_SHORT_SIZE);
+        pm->bbox[0] = get_fword ();
+        pm->bbox[1] = get_fword ();
+        pm->bbox[2] = get_fword ();
+        pm->bbox[3] = get_fword ();
     }
 
-    ttf_seek_tab("name", 0);
-    i = ftell(fontfile);
-    get_ushort();           /* skip Format selector (=0) */
-    n = get_ushort();       /* number of name records */
-    j = get_ushort() + i;   /* start of string storage */
-    i += 3*TTF_USHORT_SIZE; /* update the current offset */
+    ttf_seek_tab ("name", 0);
+    i = ftell (fontfile);
+    (void) get_ushort ();       /* skip Format selector (=0) */
+    n = get_ushort ();          /* number of name records */
+    j = get_ushort () + i;      /* start of string storage */
+    i += 3 * TTF_USHORT_SIZE;   /* update the current offset */
     while (n-- > 0) {
-        ttf_seek_off("name", i);
-        platform_id = get_ushort();
-        encoding_id = get_ushort();
-        get_ushort(); /* skip language_id */
-        k = get_ushort(); /* name_id */
-        l = get_ushort(); /* string length */
+        ttf_seek_off ("name", i);
+        platform_id = get_ushort ();
+        encoding_id = get_ushort ();
+        (void) get_ushort ();   /* skip language_id */
+        k = get_ushort ();      /* name_id */
+        l = get_ushort ();      /* string length */
         if ((platform_id == 1 && encoding_id == 0) &&
-            (k == 0 || k == 1 || k == 4 || k == 5 || 
-             k == 6)) {
-            ttf_seek_off("name", j + get_ushort());
+            (k == 0 || k == 1 || k == 4 || k == 5 || k == 6)) {
+            ttf_seek_off ("name", j + get_ushort ());
             for (p = buf; l-- > 0; p++)
-                *p = get_char();
+                *p = get_char ();
             *p++ = 0;
-            p = xstrdup(buf);
+            p = xstrdup (buf);
             switch (k) {
-            case 0:  Notice = p; break;
-            case 1:  FamilyName = p; break;
-            case 4:  FullName = p; break;
-            case 5:  Version = p; break;
-            case 6:  FontName = p; break;
+            case 0:
+                Notice = p;
+                break;
+            case 1:
+                FamilyName = p;
+                break;
+            case 4:
+                FullName = p;
+                break;
+            case 5:
+                Version = p;
+                break;
+            case 6:
+                FontName = p;
+                break;
             }
-            if (Notice != NULL && FamilyName != NULL && 
-                FullName != NULL && FontName != NULL && 
-                Version != NULL)
+            if (Notice != NULL && FamilyName != NULL &&
+                FullName != NULL && FontName != NULL && Version != NULL)
                 break;
         }
-        i += 6*TTF_USHORT_SIZE;
+        i += 6 * TTF_USHORT_SIZE;
     }
-    if ((pd = name_lookup("PCLT")) != NULL) {
-        ttf_seek_off("PCLT", pd->offset + TTF_FIXED_SIZE + TTF_ULONG_SIZE + TTF_USHORT_SIZE);
-        XHeight = get_ushort();
-        if (XHeight > FontBBox3) {
-            ttf_warn("XHeight is too big (%i)\n"
-                     "This is likely a font bug, so I discarded this parameter.", 
-                     (int)get_ttf_funit(XHeight));
+    if ((pd = name_lookup ("PCLT")) != NULL) {
+        ttf_seek_off ("PCLT",
+                      pd->offset + TTF_FIXED_SIZE + TTF_ULONG_SIZE +
+                      TTF_USHORT_SIZE);
+        XHeight = get_ushort ();
+        if (XHeight > FontBBox4) {
+            ttf_warn ("XHeight is too big (%i)\n"
+                      "This is likely a font bug, so I discarded this parameter.",
+                      (int) get_ttf_funit (XHeight));
             XHeight = 0;
         }
-        ttf_skip(2*TTF_USHORT_SIZE);
-        CapHeight = get_ushort();
-        if (CapHeight > FontBBox3) {
-            ttf_warn("CapHeight is too big (%i)\n"
-                     "This is likely a font bug, so I discarded this parameter.", 
-                     (int)get_ttf_funit(CapHeight));
+        ttf_skip (2 * TTF_USHORT_SIZE);
+        CapHeight = get_ushort ();
+        if (CapHeight > FontBBox4) {
+            ttf_warn ("CapHeight is too big (%i)\n"
+                      "This is likely a font bug, so I discarded this parameter.",
+                      (int) get_ttf_funit (CapHeight));
             CapHeight = 0;
         }
     }
-    if ((pd = name_lookup("OS/2")) != NULL) {
-        ttf_seek_off("OS/2", pd->offset + TTF_USHORT_SIZE + TTF_SHORT_SIZE);
-        switch (get_ushort()) {
-        case 100: Weight = xstrdup("Thin"); break;
-        case 200: Weight = xstrdup("ExtraLight"); break;
-        case 300: Weight = xstrdup("Light"); break;
-        case 400: Weight = xstrdup("Normal"); break;
-        case 500: Weight = xstrdup("Medium"); break;
-        case 600: Weight = xstrdup("SemiBold"); break;
-        case 700: Weight = xstrdup("Bold"); break;
-        case 800: Weight = xstrdup("ExtraBold"); break;
-        case 900: Weight = xstrdup("Black"); break;
+    if ((pd = name_lookup ("OS/2")) != NULL) {
+        ttf_seek_off ("OS/2", pd->offset + TTF_USHORT_SIZE + TTF_SHORT_SIZE);
+        switch (get_ushort ()) {
+        case 100:
+            Weight = xstrdup ("Thin");
+            break;
+        case 200:
+            Weight = xstrdup ("ExtraLight");
+            break;
+        case 300:
+            Weight = xstrdup ("Light");
+            break;
+        case 400:
+            Weight = xstrdup ("Normal");
+            break;
+        case 500:
+            Weight = xstrdup ("Medium");
+            break;
+        case 600:
+            Weight = xstrdup ("SemiBold");
+            break;
+        case 700:
+            Weight = xstrdup ("Bold");
+            break;
+        case 800:
+            Weight = xstrdup ("ExtraBold");
+            break;
+        case 900:
+            Weight = xstrdup ("Black");
+            break;
         }
     }
-    read_cmap();
-    if ((pd = name_lookup("kern")) == NULL)
+    read_cmap ();
+    if ((pd = name_lookup ("kern")) == NULL)
         return;
-    kern_tab = xtalloc(nglyphs, kern_entry);
+    kern_tab = xtalloc (nglyphs, kern_entry);
     for (pk = kern_tab; pk - kern_tab < nglyphs; pk++) {
         pk->next = NULL;
         pk->value = 0;
     }
-    ttf_seek_off("kern", pd->offset + TTF_USHORT_SIZE);
-    for (n = get_ushort(); n > 0; n--) {
-        ttf_skip(2*TTF_USHORT_SIZE);
-        k = get_ushort();
+    ttf_seek_off ("kern", pd->offset + TTF_USHORT_SIZE);
+    for (n = get_ushort (); n > 0; n--) {
+        ttf_skip (2 * TTF_USHORT_SIZE);
+        k = get_ushort ();
         if (!(k & 1) || (k & 2) || (k & 4))
             return;
         if (k >> 8 != 0) {
-            ttf_warn("warning: only format 0 supported of `kern' \
+            ttf_warn ("warning: only format 0 supported of `kern' \
                  subtables, others are ignored\n");
             continue;
         }
-        k = get_ushort();
-        ttf_skip(3*TTF_USHORT_SIZE);
+        k = get_ushort ();
+        ttf_skip (3 * TTF_USHORT_SIZE);
         while (k-- > 0) {
-            i = get_ushort();
-            j = get_ushort();
-            kern_value = get_fword();
+            i = get_ushort ();
+            j = get_ushort ();
+            kern_value = get_fword ();
             if (kern_value != 0) {
-                store_kern_value(i, j, kern_value);
+                store_kern_value (i, j, kern_value);
                 nkernpairs++;
             }
         }
     }
 }
 
-int null_glyph(const char *s)
+int null_glyph (const char *s)
 {
     return (s == NULL || s == notdef);
     /*
-        strcmp(s, ".null") == 0 ||
-        strcmp(s, ".notdef") == 0 ||
-        strcmp(s, "CR") == 0 ||
-        strcmp(s, "nonmarkingreturn") == 0
-    */
+       strcmp(s, ".null") == 0 ||
+       strcmp(s, ".notdef") == 0 ||
+       strcmp(s, "CR") == 0 ||
+       strcmp(s, "nonmarkingreturn") == 0
+     */
 }
 
-void print_glyph_name(FILE *f, long glyph_index, int convention)
+void print_glyph_name (FILE * f, long glyph_index, int convention)
 {
     unicode_entry *u;
     static char buf[1024];
     const char *n;
-    assert(glyph_index >= 0 && glyph_index < nglyphs);
+    assert (glyph_index >= 0 && glyph_index < nglyphs);
     n = mtx_tab[glyph_index].name;
     if (printing_enc && (n == notdef || glyph_index == 0)) {
-        fputs(notdef, f);
+        fputs (notdef, f);
         return;
     }
     switch (convention) {
     case AS_NAME:
-        if (!null_glyph(n))
-            fprintf(f, "%s", mtx_tab[glyph_index].name);
+        if (!null_glyph (n))
+            fprintf (f, "%s", mtx_tab[glyph_index].name);
         else if (n == notdef && glyph_index == 0)
-            fputs(notdef, f);
+            fputs (notdef, f);
         else
-            fprintf(f, "%s%i", GLYPH_PREFIX_INDEX, glyph_index);
+            fprintf (f, "%s%li", GLYPH_PREFIX_INDEX, glyph_index);
         break;
     case AS_INDEX:
-        fprintf(f, "%s%i", GLYPH_PREFIX_INDEX, glyph_index);
+        fprintf (f, "%s%li", GLYPH_PREFIX_INDEX, glyph_index);
         break;
     case AS_UNICODE:
         u = mtx_tab[glyph_index].unicode_list;
         if (glyph_index == 0 || u == NULL)
-            fprintf(f, "%s%i", GLYPH_PREFIX_INDEX, glyph_index);
+            fprintf (f, "%s%li", GLYPH_PREFIX_INDEX, glyph_index);
         else {
-            fprintf(f, "%s%.4X", GLYPH_PREFIX_UNICODE, u->code);
+            fprintf (f, "%s%.4X", GLYPH_PREFIX_UNICODE, u->code);
             if (u->next != NULL) {
                 *buf = 0;
                 for (; u != NULL; u = u->next) {
-                    assert(strlen(buf) + strlen(GLYPH_PREFIX_UNICODE) + 4 < sizeof(buf));
-                    sprintf(strend(buf), "%s%.4X ", GLYPH_PREFIX_UNICODE, u->code);
+                    assert (strlen (buf) + strlen (GLYPH_PREFIX_UNICODE) + 4 <
+                            sizeof (buf));
+                    sprintf (strend (buf), "%s%.4X ", GLYPH_PREFIX_UNICODE,
+                             u->code);
                 }
-                ttf_warn("glyph %i have multiple encodings: %s", 
-                         glyph_index, buf);
+                ttf_warn
+                    ("glyph %li have multiple encodings (the first one being used): %s",
+                     glyph_index, buf);
             }
         }
         break;
     }
 }
 
-void print_char_metric(FILE *f, int charcode, long glyph_index)
+void print_char_metric (FILE * f, int charcode, long glyph_index)
 {
-    assert(glyph_index >= 0 && glyph_index < nglyphs);
-    fprintf(f, "C %i ; WX %i ; N ", (int) charcode, 
-            (int)get_ttf_funit(mtx_tab[glyph_index].wx));
-    print_glyph_name(f, glyph_index, print_glyph);
-    fprintf(f, " ; B %i %i %i %i ;\n", 
-            (int)get_ttf_funit(mtx_tab[glyph_index].bbox[0]),
-            (int)get_ttf_funit(mtx_tab[glyph_index].bbox[1]),
-            (int)get_ttf_funit(mtx_tab[glyph_index].bbox[2]),
-            (int)get_ttf_funit(mtx_tab[glyph_index].bbox[3]));
+    assert (glyph_index >= 0 && glyph_index < nglyphs);
+    fprintf (f, "C %i ; WX %i ; N ", (int) charcode,
+             (int) get_ttf_funit (mtx_tab[glyph_index].wx));
+    print_glyph_name (f, glyph_index, print_glyph);
+    fprintf (f, " ; B %i %i %i %i ;\n",
+             (int) get_ttf_funit (mtx_tab[glyph_index].bbox[0]),
+             (int) get_ttf_funit (mtx_tab[glyph_index].bbox[1]),
+             (int) get_ttf_funit (mtx_tab[glyph_index].bbox[2]),
+             (int) get_ttf_funit (mtx_tab[glyph_index].bbox[3]));
 }
 
-void print_afm(char *date, char *fontname)
+void print_afm (char *date, char *fontname)
 {
-    int i, ncharmetrics;
+    int ncharmetrics;
     mtx_entry *pm;
-    short mtx_index[MAX_CHAR_CODE + 1], *idx;
+    short mtx_index[256], *idx;
     unsigned int index;
     char **pe;
     kern_entry *pk, *qk;
-    unicode_entry *u;
-    char buf[20];
-    fputs("StartFontMetrics 2.0\n", outfile);
-    fprintf(outfile, "Comment Converted at %s by ttf2afm from font file `%s'\n", date, fontname);
-    print_str(FontName);
-    print_str(FullName);
-    print_str(FamilyName);
-    print_str(Weight);
-    fprintf(outfile, "ItalicAngle %i", (int)(ItalicAngle/0x10000));
-    if (ItalicAngle%0x10000 > 0)
-        fprintf(outfile, ".%i", (int)((ItalicAngle%0x10000)*1000)/0x10000);
-    fputs("\n", outfile);
-    fprintf(outfile, "IsFixedPitch %s\n", IsFixedPitch ? "true" : "false");
-    fprintf(outfile, "FontBBox %i %i %i %i\n", 
-            (int)get_ttf_funit(FontBBox1),
-            (int)get_ttf_funit(FontBBox2),
-            (int)get_ttf_funit(FontBBox3),
-            (int)get_ttf_funit(FontBBox4));
-    print_dimen(UnderlinePosition);
-    print_dimen(UnderlineThickness);
-    print_str(Version);
-    print_str(Notice);
-    fputs("EncodingScheme FontSpecific\n", outfile);
-    print_dimen(CapHeight);
-    print_dimen(XHeight);
-    print_dimen(Ascender);
-    print_dimen(Descender);
+    fputs ("StartFontMetrics 2.0\n", outfile);
+    fprintf (outfile,
+             "Comment Converted at %s by ttf2afm from font file `%s'\n", date,
+             fontname);
+    print_str (FontName);
+    print_str (FullName);
+    print_str (FamilyName);
+    print_str (Weight);
+    fprintf (outfile, "ItalicAngle %i", (int) (ItalicAngle / 0x10000));
+    if (ItalicAngle % 0x10000 > 0)
+        fprintf (outfile, ".%i",
+                 (int) ((ItalicAngle % 0x10000) * 1000) / 0x10000);
+    fputs ("\n", outfile);
+    fprintf (outfile, "IsFixedPitch %s\n", IsFixedPitch ? "true" : "false");
+    fprintf (outfile, "FontBBox %i %i %i %i\n",
+             (int) get_ttf_funit (FontBBox1),
+             (int) get_ttf_funit (FontBBox2),
+             (int) get_ttf_funit (FontBBox3), (int) get_ttf_funit (FontBBox4));
+    print_dimen (UnderlinePosition);
+    print_dimen (UnderlineThickness);
+    print_str (Version);
+    print_str (Notice);
+    fputs ("EncodingScheme FontSpecific\n", outfile);
+    print_dimen (CapHeight);
+    print_dimen (XHeight);
+    print_dimen (Ascender);
+    print_dimen (Descender);
     ncharmetrics = nglyphs;
-    if (use_ext_enc == 0) { /* external encoding vector not given */
-        fprintf(outfile, "StartCharMetrics %u\n", ncharmetrics);
+    if (use_ext_enc == 0) {     /* external encoding vector not given */
+        fprintf (outfile, "StartCharMetrics %u\n", ncharmetrics);
         for (pm = mtx_tab; pm - mtx_tab < nglyphs; pm++) {
             pm->found = 1;
-            print_char_metric(outfile, -1, pm - mtx_tab);
+            print_char_metric (outfile, -1, pm - mtx_tab);
         }
-    }
-    else { /* external encoding vector given */
-        for (idx = mtx_index; idx - mtx_index <= MAX_CHAR_CODE; *idx++ = 0);
+    } else {                    /* external encoding vector given */
+        for (idx = mtx_index; idx - mtx_index < 256; *idx++ = 0);
         for (pe = enc_names; pe - enc_names < names_count; pe++) {
             if (*pe == notdef)
                 continue;
             /* scan form `uniABCD' */
-            if (sscanf(*pe, GLYPH_PREFIX_UNICODE "%X", &index) == 1) {
+            if (sscanf (*pe, GLYPH_PREFIX_UNICODE "%X", &index) == 1) {
                 if (unicode_map[index] != NOGLYPH_ASSIGNED_YET) {
                     pm = mtx_tab + unicode_map[index];
                     pm->found = 1;
-                }
-                else
-                    ttf_warn("`unicode %s%.4X' is not mapped to any glyph", 
-                             GLYPH_PREFIX_UNICODE, index);
+                } else
+                    ttf_warn ("`unicode %s%.4X' is not mapped to any glyph",
+                              GLYPH_PREFIX_UNICODE, index);
                 continue;
             }
             /* scan form `index123' */
-            if (sscanf(*pe, GLYPH_PREFIX_INDEX "%u", &index) == 1) {
+            if (sscanf (*pe, GLYPH_PREFIX_INDEX "%u", &index) == 1) {
                 if (index >= nglyphs)
-                    ttf_fail("`%s' out of valid range [0..%i)",
-                         *pe, nglyphs);
+                    ttf_fail ("`%s' out of valid range [0..%i)", *pe, nglyphs);
                 pm = mtx_tab + index;
                 pm->found = 1;
                 continue;
             }
             for (pm = mtx_tab; pm - mtx_tab < nglyphs; pm++)
-                if (pm->name != NULL && strcmp(*pe, pm->name) == 0)
-                    break; 
+                if (pm->name != NULL && strcmp (*pe, pm->name) == 0)
+                    break;
             if (pm - mtx_tab < nglyphs) {
                 mtx_index[pe - enc_names] = pm - mtx_tab;
                 pm->found = 1;
                 continue;
-            }
-            else
-                ttf_warn("glyph `%s' not found", *pe);
+            } else
+                ttf_warn ("glyph `%s' not found", *pe);
         }
-        fprintf(outfile, "StartCharMetrics %u\n", ncharmetrics);
-        for (idx = mtx_index; idx - mtx_index <= MAX_CHAR_CODE; idx++) {
+        fprintf (outfile, "StartCharMetrics %u\n", ncharmetrics);
+        for (idx = mtx_index; idx - mtx_index < 256; idx++) {
             if (*idx != 0 && mtx_tab[*idx].found == 1)
-                print_char_metric(outfile, idx - mtx_index, *idx);
+                print_char_metric (outfile, idx - mtx_index, *idx);
         }
         for (pm = mtx_tab; pm - mtx_tab < nglyphs; pm++) {
             if (pm->found == 0)
-                print_char_metric(outfile, -1, pm - mtx_tab);
+                print_char_metric (outfile, -1, pm - mtx_tab);
         }
     }
-end_metrics:
-    fputs("EndCharMetrics\n", outfile);
+    fputs ("EndCharMetrics\n", outfile);
     if (nkernpairs == 0)
         goto end_kerns;
-    fprintf(outfile, "StartKernData\nStartKernPairs %i\n", nkernpairs);
+    fprintf (outfile, "StartKernData\nStartKernPairs %i\n", nkernpairs);
     for (pk = kern_tab; pk - kern_tab < nglyphs; pk++)
         for (qk = pk; qk != NULL; qk = qk->next)
             if (qk->value != 0) {
-                fputs("KPX ", outfile);
-                print_glyph_name(outfile, pk - kern_tab, print_glyph);
-                fputs(" ", outfile);
-                print_glyph_name(outfile, qk->adjacent, print_glyph);
-                fprintf(outfile, " %i\n", get_ttf_funit(qk->value));
+                fputs ("KPX ", outfile);
+                print_glyph_name (outfile, pk - kern_tab, print_glyph);
+                fputs (" ", outfile);
+                print_glyph_name (outfile, qk->adjacent, print_glyph);
+                fprintf (outfile, " %i\n", get_ttf_funit (qk->value));
             }
-    fputs("EndKernPairs\nEndKernData\n", outfile);
-end_kerns:
-    fputs("EndFontMetrics\n", outfile);
+    fputs ("EndKernPairs\nEndKernData\n", outfile);
+  end_kerns:
+    fputs ("EndFontMetrics\n", outfile);
 }
 
-void print_encoding(char *fontname)
+void print_encoding (char *fontname)
 {
-    long int i, k, first_code, length, last_sep;
+    long int i, k, first_code, length;
     FILE *file;
     TTF_USHORT format;
     char *enc_name, *end_enc_name;
     cmap_entry *e;
-    const char *n;
     printing_enc = 1;
-    enc_name = xtalloc(strlen(bname) + 20, char);
-    strcpy(enc_name, bname);
-    end_enc_name = strend(enc_name);
+    enc_name = xtalloc (strlen (bname) + 20, char);
+    strcpy (enc_name, bname);
+    end_enc_name = strend (enc_name);
     for (e = cmap_tab; e - cmap_tab < ncmapsubtabs; e++) {
-        ttf_seek_off("cmap", cmap_offset + e->offset);
-        format = get_ushort();
+        ttf_seek_off ("cmap", cmap_offset + e->offset);
+        format = get_ushort ();
         if (format != 0 && format != 4 && format != 6) {
-            ttf_warn("format %i of encoding subtable unsupported", (int)format);
+            ttf_warn ("format %i of encoding subtable unsupported",
+                      (int) format);
             continue;
         }
-        sprintf(end_enc_name, ".e%i%i", 
-                (int)e->platform_id, (int)e->encoding_id);
-        if ((file = xfopen(enc_name, FOPEN_W_MODE)) == NULL)
-            ttf_fail("cannot open file for writing (%s)\n", enc_name);
-        fprintf(file, "%% Encoding table from font file %s\n", fontname);
-        fprintf(file, "%% Platform ID %i", (int)e->platform_id);
+        sprintf (end_enc_name, ".e%i%i",
+                 (int) e->platform_id, (int) e->encoding_id);
+        if ((file = xfopen (enc_name, FOPEN_W_MODE)) == NULL)
+            ttf_fail ("cannot open file for writing (%s)\n", enc_name);
+        fprintf (file, "%% Encoding table from font file %s\n", fontname);
+        fprintf (file, "%% Platform ID %i", (int) e->platform_id);
         switch (e->platform_id) {
-        case 0:  fprintf(file, " (Apple Unicode)"); break;
-        case 1:  fprintf(file, " (Macintosh)"); break;
-        case 2:  fprintf(file, " (ISO)"); break;
-        case 3:  fprintf(file, " (Microsoft)"); break;
+        case 0:
+            fprintf (file, " (Apple Unicode)");
+            break;
+        case 1:
+            fprintf (file, " (Macintosh)");
+            break;
+        case 2:
+            fprintf (file, " (ISO)");
+            break;
+        case 3:
+            fprintf (file, " (Microsoft)");
+            break;
         }
-        fprintf(file, "\n");
-        fprintf(file, "%% Encoding ID %i", (int)e->encoding_id);
-        if (e->platform_id == 1 &&  e->encoding_id == 0)
-            fprintf(file, " (Roman)");
+        fprintf (file, "\n");
+        fprintf (file, "%% Encoding ID %i", (int) e->encoding_id);
+        if (e->platform_id == 1 && e->encoding_id == 0)
+            fprintf (file, " (Roman)");
         if (e->platform_id == 3)
             switch (e->encoding_id) {
-            case 0:  fprintf(file, " (Symbol)"); break;
-            case 1:  fprintf(file, " (Unicode)"); break;
+            case 0:
+                fprintf (file, " (Symbol)");
+                break;
+            case 1:
+                fprintf (file, " (Unicode)");
+                break;
             }
-        fprintf(file, "\n");
-        fprintf(file, "%% Format %i", (int)(format));
+        fprintf (file, "\n");
+        fprintf (file, "%% Format %i", (int) (format));
         switch (format) {
-        case 0:  fprintf(file, " (byte encoding table)"); break;
-        case 4:  fprintf(file, " (segment mapping to delta values)"); break;
-        case 6:  fprintf(file, " (trimmed table mapping)"); break;
+        case 0:
+            fprintf (file, " (byte encoding table)");
+            break;
+        case 4:
+            fprintf (file, " (segment mapping to delta values)");
+            break;
+        case 6:
+            fprintf (file, " (trimmed table mapping)");
+            break;
         }
-        fprintf(file, "\n");
-        fprintf(file, "/Encoding%i [\n", (int)(e - cmap_tab + 1));
+        fprintf (file, "\n");
+        fprintf (file, "/Encoding%i [\n", (int) (e - cmap_tab + 1));
         switch (format) {
         case 0:
-            get_ushort(); /* skip length */
-            get_ushort(); /* skip version number */
-            for (i = 0; i <= MAX_CHAR_CODE; i++) {
-                fputs("/", file);
-                print_glyph_name(file, get_byte(), print_glyph);
-                fputs("\n", file);
+            (void) get_ushort ();       /* skip length */
+            (void) get_ushort ();       /* skip version number */
+            for (i = 0; i < 256; i++) {
+                fputs ("/", file);
+                print_glyph_name (file, get_byte (), print_glyph);
+                fputs ("\n", file);
             }
             break;
         case 4:
             for (i = 0; i < nglyphs; ++i) {
-                fprintf(file, "%% Glyph %i -> ", i);
-                print_glyph_name(file, i, AS_UNICODE);
-                fputs("\n", file);
+                fprintf (file, "%% Glyph %li -> ", i);
+                print_glyph_name (file, i, AS_UNICODE);
+                fputs ("\n", file);
             }
             break;
         case 6:
-            get_ushort(); /* skip table length */
-            get_ushort(); /* skip version number */
-            first_code = get_ushort(); /* first character code */
+            (void) get_ushort ();       /* skip table length */
+            (void) get_ushort ();       /* skip version number */
+            first_code = get_ushort (); /* first character code */
             for (i = 0; i < first_code; ++i)
-                fprintf(file, "/%s\n", notdef);
-            length = get_ushort(); /* number of character codes */
+                fprintf (file, "/%s\n", notdef);
+            length = get_ushort ();     /* number of character codes */
             for (i = first_code; i < first_code + length; i++) {
-                k = get_ushort();
-                if (i > MAX_CHAR_CODE)
-                    fputs("% ", file);
-                fputs("/", file);
-                print_glyph_name(file, k, print_glyph);
-                fputs("\n", file);
+                k = get_ushort ();
+                if (i > 255)
+                    fputs ("% ", file);
+                fputs ("/", file);
+                print_glyph_name (file, k, print_glyph);
+                fputs ("\n", file);
             }
-            for (i =  first_code + length; i <= MAX_CHAR_CODE; i++)
-                fprintf(file, "/%s\n", notdef);
+            for (i = first_code + length; i < 256; i++)
+                fprintf (file, "/%s\n", notdef);
             break;
         default:
-            ttf_warn("format %i of encoding subtable unsupported", (int)format);
+            ttf_warn ("format %i of encoding subtable unsupported",
+                      (int) format);
         }
-        fprintf(file, "] def\n");
+        fprintf (file, "] def\n");
     }
-    xfree(enc_name);
+    xfree (enc_name);
 }
 
-void usage()
+void usage ()
 {
     cur_file_name = NULL;
-    fprintf(stderr,
-        "Usage: ttf2afm [-i|-u|-c|-v] [-e enc] [-o filename] [-m NUM] fontfile\n"
-        "    -i:          force printing glyph names in form 'index123'\n"
-        "    -u:          force printing glyph names in form 'uniABCD'\n"
-        "    -c:          print encoding tables to `basename.e<platformID><encodingID>'\n"
-        "    -v:          print version\n"
-        "    -e enc:      encode the AFM output using encoding vector from `enc'\n"
-        "    -o filename: write output to file `filename' instead of stdout\n"
-        "    -m NUM:      select unicode mapping (default = 1, ie the first)\n"
-        "    fontfile:    the TrueType fontfile\n"
-        "\nPlease send bug reports or feature requests to <pdftex at tug.org>\n"
-    );
-    _exit(-1);
+    fprintf (stderr,
+             "Usage: ttf2afm [-i|-u|-c|-v] [-e enc] [-o filename] [-m NUM] fontfile\n"
+             "    -i:          force printing glyph names in form 'index123'\n"
+             "    -u:          force printing glyph names in form 'uniABCD'\n"
+             "    -c:          print encoding tables to `basename.e<platformID><encodingID>'\n"
+             "    -v:          print version\n"
+             "    -e enc:      encode the AFM output using encoding vector from `enc'\n"
+             "    -o filename: write output to file `filename' instead of stdout\n"
+             "    -m NUM:      select unicode mapping (default = 1, ie the first)\n"
+             "    fontfile:    the TrueType fontfile\n"
+             "\nPlease send bug reports or feature requests to <pdftex at tug.org>\n");
+    _exit (-1);
 }
 
-int main(int argc, char **argv)
+int main (int argc, char **argv)
 {
-    char date[128], *s, *buf = NULL;
-    time_t t = time(&t);
+    char date[128], *s;
+    time_t t = time (&t);
     int c;
-    kpse_set_progname(argv[0]);
-    kpse_init_prog("ttf2afm", 0, 0, 0) ;
-    while ((c = getopt(argc, argv, "iucve:o:m:")) != -1)
+    kpse_set_progname (argv[0]);
+    kpse_init_prog ("ttf2afm", 0, 0, 0);
+    while ((c = getopt (argc, argv, "iucve:o:m:")) != -1)
         switch (c) {
         case 'i':
             print_glyph = AS_INDEX;
@@ -940,60 +998,58 @@
             break;
         case 'e':
             cur_file_name = optarg;
-            read_encoding(cur_file_name);
+            read_encoding (cur_file_name);
             use_ext_enc = 1;
             break;
         case 'o':
             cur_file_name = optarg;
-            outfile = xfopen(cur_file_name, FOPEN_W_MODE);
+            outfile = xfopen (cur_file_name, FOPEN_W_MODE);
             if (outfile == NULL)
-                ttf_fail("cannot open file for writing");
+                ttf_fail ("cannot open file for writing");
             break;
         case 'm':
-            select_unicode = atoi(optarg);
+            select_unicode = atoi (optarg);
             break;
         case 'v':
-            fprintf(stderr, 
-                    "ttf2afm version " VERSION "\n"
-                    "Copyright (C) 1997-2005 Han The Thanh.\n"
-                    "There is NO warranty.  Redistribution of this software is\n"
-                    "covered by the terms of both the pdfTeX copyright and\n"
-                    "the GNU General Public License.\n"
-                    "For more information about these matters, see the files\n"
-                    "named COPYING and the pdfTeX source.\n"
-                    "Primary author of ttf2afm: Han The Thanh.\n"
-                   );
-            _exit(0);
+            fprintf (stderr,
+                     "ttf2afm version " VERSION "\n"
+                     "Copyright (C) 1997-2005 Han The Thanh.\n"
+                     "There is NO warranty.  Redistribution of this software is\n"
+                     "covered by the terms of both the pdfTeX copyright and\n"
+                     "the GNU General Public License.\n"
+                     "For more information about these matters, see the files\n"
+                     "named COPYING and the pdfTeX source.\n"
+                     "Primary author of ttf2afm: Han The Thanh.\n");
+            _exit (0);
         default:
-            usage();
+            usage ();
         }
     if (argc - optind != 1)
-        usage();
-    sprintf(date, "%s\n", ctime(&t));
-    *(char *)strchr(date, '\n') = 0;
+        usage ();
+    sprintf (date, "%s\n", ctime (&t));
+    *(char *) strchr (date, '\n') = 0;
     cur_file_name = argv[optind];
     if (print_cmap) {
-        buf = xstrdup(cur_file_name);
-        bname = xbasename(buf);
-        if ((s = rindex(bname, '.')) != NULL)
+        bname = strdup (xbasename (cur_file_name));
+        if ((s = rindex (bname, '.')) != NULL)
             *s = 0;
     }
-    if ((fontfile = kpse_open_file(cur_file_name, kpse_truetype_format)) == NULL)
-        ttf_fail("can't open font file for reading");
-    read_font();
+    if ((fontfile =
+         kpse_open_file (cur_file_name, kpse_truetype_format)) == NULL)
+        ttf_fail ("can't open font file for reading");
+    read_font ();
     if (outfile == NULL)
         outfile = stdout;
-    print_afm(date, cur_file_name);
+    print_afm (date, cur_file_name);
     if (print_cmap)
-        print_encoding(cur_file_name);
-    xfree(FontName);
-    xfree(FullName);
-    xfree(FamilyName);
-    xfree(Notice);
-    xfree(Version);
-    xfree(Weight);
-    xfree(buf);
-    free_tabs();
-    xfclose(fontfile, cur_file_name);
+        print_encoding (cur_file_name);
+    xfree (FontName);
+    xfree (FullName);
+    xfree (FamilyName);
+    xfree (Notice);
+    xfree (Version);
+    xfree (Weight);
+    free_tabs ();
+    xfclose (fontfile, cur_file_name);
     return 0;
 }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/utils.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/utils.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/utils.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 1996-2003 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2006 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -17,56 +17,63 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/utils.c#21 $
+$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/utils.c#24 $
 */
 
+#include "sys/types.h"
+#include "sysexits.h"
+#include "regex.h"
 #include "ptexlib.h"
 #include "zlib.h"
 #include "md5.h"
 #include <kpathsea/c-vararg.h>
 #include <kpathsea/c-proto.h>
+#include <kpathsea/c-stat.h>
+#include <kpathsea/c-fopen.h>
+#include <string.h>
 #include <time.h>
+#include <float.h>              /* for DBL_EPSILON */
 
-static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/utils.c#21 $";
+/*@unused@*/
+static const char perforce_id[] =
+    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/utils.c#24 $";
 
 char *cur_file_name = NULL;
 strnumber last_tex_string;
 static char print_buf[PRINTF_BUF_SIZE];
 static char *jobname_cstr = NULL;
 static char *job_id_string = NULL;
-static char *escaped_string = NULL;
-extern string ptexbanner; /* from web2c/lib/texmfmp.c */
-extern string versionstring; /* from web2c/lib/version.c */         
-extern KPSEDLL string kpathsea_version_string; /* from kpathsea/version.c */
+extern string ptexbanner;       /* from web2c/lib/texmfmp.c */
+extern string versionstring;    /* from web2c/lib/version.c */
+extern KPSEDLL string kpathsea_version_string;  /* from kpathsea/version.c */
 
-size_t last_ptr_index; /* for use with alloc_array */
+size_t last_ptr_index;          /* for use with alloc_array */
 
 /* define fb_ptr, fb_array & fb_limit */
 typedef char fb_entry;
-define_array(fb);   
+define_array (fb);
 
 /* define char_ptr, char_array & char_limit */
 typedef char char_entry;
-define_array(char);   
+define_array (char);
 
-integer fb_offset(void)
+integer fb_offset (void)
 {
     return fb_ptr - fb_array;
 }
 
-void fb_seek(integer offset)
+void fb_seek (integer offset)
 {
-     fb_ptr = fb_array + offset;
+    fb_ptr = fb_array + offset;
 }
 
-void fb_putchar(eightbits b)
+void fb_putchar (eightbits b)
 {
-    alloc_array(fb, 1, SMALL_ARRAY_SIZE);
+    alloc_array (fb, 1, SMALL_ARRAY_SIZE);
     *fb_ptr++ = b;
 }
 
-void fb_flush(void)
+void fb_flush (void)
 {
     fb_entry *p;
     integer n;
@@ -74,58 +81,59 @@
         n = pdfbufsize - pdfptr;
         if (fb_ptr - p < n)
             n = fb_ptr - p;
-        memcpy(pdfbuf + pdfptr, p, (unsigned)n);
+        memcpy (pdfbuf + pdfptr, p, (unsigned) n);
         pdfptr += n;
         if (pdfptr == pdfbufsize)
-            pdfflush();
+            pdfflush ();
         p += n;
     }
     fb_ptr = fb_array;
 }
 
-static void fnstr_append(const char *s)
+static void fnstr_append (const char *s)
 {
-    int l = strlen(s) + 1;
-    alloc_array(char, l, SMALL_ARRAY_SIZE);
-    strcat(char_ptr, s);
-    char_ptr = strend(char_ptr);
+    size_t l = strlen (s) + 1;
+    alloc_array (char, l, SMALL_ARRAY_SIZE);
+    strcat (char_ptr, s);
+    char_ptr = strend (char_ptr);
 }
 
-void make_subset_tag(fm_entry *fm_cur, char **glyph_names)
+void make_subset_tag (fm_entry * fm_cur, char **glyph_names)
 {
     char tag[7];
     unsigned long crc;
-    int i, l = strlen(job_id_string) + 1;
-    alloc_array(char, l, SMALL_ARRAY_SIZE);
-    strcpy(char_array, job_id_string);
-    char_ptr = strend(char_array);
+    int i;
+    size_t l = strlen (job_id_string) + 1;
+    alloc_array (char, l, SMALL_ARRAY_SIZE);
+    strcpy (char_array, job_id_string);
+    char_ptr = strend (char_array);
     if (fm_cur->tfm_name != NULL) {
-        fnstr_append(" TFM name: ");
-        fnstr_append(fm_cur->tfm_name);
+        fnstr_append (" TFM name: ");
+        fnstr_append (fm_cur->tfm_name);
     }
-    fnstr_append(" PS name: ");
+    fnstr_append (" PS name: ");
     if (font_keys[FONTNAME_CODE].valid)
-        fnstr_append(fontname_buf);
+        fnstr_append (fontname_buf);
     else if (fm_cur->ps_name != NULL)
-        fnstr_append(fm_cur->ps_name);
-    fnstr_append(" Encoding: ");
+        fnstr_append (fm_cur->ps_name);
+    fnstr_append (" Encoding: ");
     if (fm_cur->encoding != NULL && (fm_cur->encoding)->name != NULL)
-        fnstr_append((fm_cur->encoding)->name);
+        fnstr_append ((fm_cur->encoding)->name);
     else
-        fnstr_append("built-in");
-    fnstr_append(" CharSet: ");
-    assert(glyph_names != NULL);
-    for (i = 0; i <= MAX_CHAR_CODE; i++)
-        if (pdfcharmarked(tex_font, i) && glyph_names[i] != notdef) {
-            fnstr_append(" /");
-            fnstr_append(glyph_names[i]);
+        fnstr_append ("built-in");
+    fnstr_append (" CharSet: ");
+    assert (glyph_names != NULL);
+    for (i = 0; i < 256; i++)
+        if (pdfcharmarked (tex_font, i) && glyph_names[i] != notdef) {
+            fnstr_append ("/");
+            fnstr_append (glyph_names[i]);
         }
     if (fm_cur->charset != NULL) {
-        fnstr_append(" Extra CharSet: ");
-        fnstr_append(fm_cur->charset);
+        fnstr_append (" Extra CharSet: ");
+        fnstr_append (fm_cur->charset);
     }
-    crc = crc32(0L, Z_NULL, 0);
-    crc = crc32(crc, (Bytef*)char_array, strlen(char_array));
+    crc = crc32 (0L, Z_NULL, 0);
+    crc = crc32 (crc, (Bytef *) char_array, strlen (char_array));
     /* we need to fit a 32-bit number into a string of 6 uppercase chars long;
      * there are 26 uppercase chars ==> each char represents a number in range
      * 0..25. The maximal number that can be represented by the tag is
@@ -137,311 +145,597 @@
         crc /= 26;
     }
     tag[6] = 0;
-    fm_cur->subset_tag = xstrdup(tag);
+    fm_cur->subset_tag = xstrdup (tag);
 }
 
-void pdf_puts(const char *s)
+void pdf_puts (const char *s)
 {
-    pdfroom(strlen(s) + 1);
+    pdfroom (strlen (s) + 1);
     while (*s)
         pdfbuf[pdfptr++] = *s++;
 }
 
-void pdf_printf(const char *fmt,...)
+#ifdef __GNUC__
+void pdf_printf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
+#endif
+void pdf_printf (const char *fmt, ...)
 {
     va_list args;
-    va_start(args, fmt);
-    vsprintf(print_buf, fmt, args);
-    pdf_puts(print_buf);                                    
-    va_end(args);
+    va_start (args, fmt);
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+    vsnprintf (print_buf, PRINTF_BUF_SIZE,
+#else
+    vsprintf (print_buf,
+#endif
+              fmt, args);
+    pdf_puts (print_buf);
+    va_end (args);
 }
 
-strnumber maketexstring(const char *s)
+strnumber maketexstring (const char *s)
 {
-    int l;
+    size_t l;
     if (s == NULL || *s == 0)
-        return getnullstr();
-    l = strlen(s);
-    check_buf(poolptr + l, poolsize);
+        return getnullstr ();
+    l = strlen (s);
+    check_buf (poolptr + l, poolsize);
     while (l-- > 0)
         strpool[poolptr++] = *s++;
-    last_tex_string = makestring();
+    last_tex_string = makestring ();
     return last_tex_string;
 }
 
-void tex_printf(const char *fmt, ...)
+#ifdef __GNUC__
+void tex_printf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
+#endif
+void tex_printf (const char *fmt, ...)
 {
     va_list args;
-    va_start(args, fmt);
-    vsprintf(print_buf, fmt, args);
-    print(maketexstring(print_buf));
-    flushstr(last_tex_string);
-    xfflush(stdout);
-    va_end(args);
+    va_start (args, fmt);
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+    vsnprintf (print_buf, PRINTF_BUF_SIZE,
+#else
+    vsprintf (print_buf,
+#endif
+              fmt, args);
+    print (maketexstring (print_buf));
+    flushstr (last_tex_string);
+    xfflush (stdout);
+    va_end (args);
 }
 
 /* Helper for pdftex_fail. */
-static void safe_print(const char *str)
+static void safe_print (const char *str)
 {
     const char *c;
     for (c = str; *c; ++c)
-        print(*c);
+        print (*c);
 }
 
 /* pdftex_fail may be called when a buffer overflow has happened/is
    happening, therefore may not call mktexstring.  However, with the
    current implementation it appears that error messages are misleading,
    possibly because pool overflows are detected too late. */
-void pdftex_fail(const char *fmt,...)
+#ifdef __GNUC__
+void pdftex_fail (const char *fmt, ...)
+    __attribute__ ((noreturn, format (printf, 1, 2)));
+#endif
+void pdftex_fail (const char *fmt, ...)
 {
     va_list args;
-    va_start(args, fmt);
-    println();
-    safe_print("Error: ");
-    safe_print(program_invocation_name);
+    va_start (args, fmt);
+    println ();
+    safe_print ("Error: ");
+    safe_print (program_invocation_name);
     if (cur_file_name) {
-        safe_print(" (file ");
-        safe_print(cur_file_name);
-        safe_print(")");
+        safe_print (" (file ");
+        safe_print (cur_file_name);
+        safe_print (")");
     }
-    safe_print(": ");
-    vsprintf(print_buf, fmt, args);
-    safe_print(print_buf);
-    va_end(args);
-    println();
-    safe_print(" ==> Fatal error occurred, the output PDF file is not finished!");
-    println();
-    exit(-1);
+    safe_print (": ");
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+    vsnprintf (print_buf, PRINTF_BUF_SIZE,
+#else
+    vsprintf (print_buf,
+#endif
+              fmt, args);
+    safe_print (print_buf);
+    va_end (args);
+    println ();
+    if (!kpathsea_debug && outputfilename) {
+        xfclose (pdffile, makecstring (outputfilename));
+        remove (makecstring (outputfilename));
+    }
+    safe_print (" ==> Fatal error occurred, no output PDF file produced!");
+    println ();
+    if (kpathsea_debug) {
+        abort ();
+    } else {
+        exit (EX_SOFTWARE);
+    }
 }
 
-void pdftex_warn(const char *fmt,...)
+#ifdef __GNUC__
+void pdftex_warn (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
+#endif
+void pdftex_warn (const char *fmt, ...)
 {
     va_list args;
-    va_start(args, fmt);
-    println();
-    tex_printf("Warning: %s", program_invocation_name);
+    va_start (args, fmt);
+    println ();
+    tex_printf ("Warning: %s", program_invocation_name);
     if (cur_file_name)
-        tex_printf(" (file %s)", cur_file_name);
-    tex_printf(": ");
-    vsprintf(print_buf, fmt, args);
-    print(maketexstring(print_buf));
-    flushstr(last_tex_string);
-    va_end(args);
-    println();
+        tex_printf (" (file %s)", cur_file_name);
+    tex_printf (": ");
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+    vsnprintf (print_buf, PRINTF_BUF_SIZE,
+#else
+    vsprintf (print_buf,
+#endif
+              fmt, args);
+    print (maketexstring (print_buf));
+    flushstr (last_tex_string);
+    va_end (args);
+    println ();
 }
 
-char *makecstring(integer s)
+char *makecstring (integer s)
 {
-    static char cstrbuf[MAX_CSTRING_LEN];
-    char *p = cstrbuf;
-    int i, l = strstart[s + 1] - strstart[s];
-    check_buf(l + 1, MAX_CSTRING_LEN);
+    static char *cstrbuf = NULL;
+    char *p;
+    static int allocsize;
+    int allocgrow, i, l = strstart[s + 1] - strstart[s];
+    check_buf (l + 1, MAX_CSTRING_LEN);
+    if (cstrbuf == NULL) {
+        allocsize = l + 1;
+        cstrbuf = xmallocarray (char, allocsize);
+    } else if (l + 1 > allocsize) {
+        allocgrow = allocsize * 0.2;
+        if (l + 1 - allocgrow > allocsize)
+            allocsize = l + 1;
+        else if (allocsize < MAX_CSTRING_LEN - allocgrow)
+            allocsize += allocgrow;
+        else
+            allocsize = MAX_CSTRING_LEN;
+        cstrbuf = xreallocarray (cstrbuf, char, allocsize);
+    }
+    p = cstrbuf;
     for (i = 0; i < l; i++)
         *p++ = strpool[i + strstart[s]];
     *p = 0;
     return cstrbuf;
 }
 
-/*
-boolean str_eq_cstr(strnumber n, char *s)
+void setjobid (int year, int month, int day, int time)
 {
-    int l;
-    if (s == NULL || n == 0)
-        return false;
-    l = strstart[n];
-    while (*s && l < strstart[n + 1] && *s == strpool[l])
-        l++, s++;
-    return !*s && l == strstart[n + 1];
-}
-*/
-
-void setjobid(int year, int month, int day, int time, int pdftexversion, int pdftexrevision)
-{
     char *name_string, *format_string, *s;
+    size_t slen;
 
     if (job_id_string != NULL)
         return;
 
-    name_string = xstrdup(makecstring(jobname));
-    format_string = xstrdup(makecstring(formatident));
-    s = xtalloc(SMALL_BUF_SIZE + 
-                strlen(name_string) + 
-                strlen(format_string) + 
-                strlen(ptexbanner) + 
-                strlen(versionstring) + 
-                strlen(kpathsea_version_string), char);
+    name_string = xstrdup (makecstring (jobname));
+    format_string = xstrdup (makecstring (formatident));
+    slen = SMALL_BUF_SIZE +
+        strlen (name_string) +
+        strlen (format_string) +
+        strlen (ptexbanner) +
+        strlen (versionstring) + strlen (kpathsea_version_string);
+    s = xtalloc (slen, char);
     /* The Web2c version string starts with a space.  */
-    sprintf(s, "%.4d/%.2d/%.2d %.2d:%.2d %s %s %s%s %s",
-            year, month, day, time/60, time%60, 
-            name_string, format_string, ptexbanner, 
-            versionstring, kpathsea_version_string);
-    job_id_string = xstrdup(s);
-    xfree(s);
-    xfree(name_string);
-    xfree(format_string);
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+    snprintf (s, slen,
+#else
+    sprintf (s,
+#endif
+             "%.4d/%.2d/%.2d %.2d:%.2d %s %s %s%s %s",
+             year, month, day, time / 60, time % 60,
+             name_string, format_string, ptexbanner,
+             versionstring, kpathsea_version_string);
+    job_id_string = xstrdup (s);
+    xfree (s);
+    xfree (name_string);
+    xfree (format_string);
 }
 
-void makepdftexbanner(void)
+void makepdftexbanner (void)
 {
     static boolean pdftexbanner_init = false;
     char *s;
+    size_t slen;
 
     if (pdftexbanner_init)
         return;
 
-    s = xtalloc(SMALL_BUF_SIZE + 
-                strlen(ptexbanner) + 
-                strlen(versionstring) + 
-                strlen(kpathsea_version_string), char);
+    slen = SMALL_BUF_SIZE +
+        strlen (ptexbanner) +
+        strlen (versionstring) + strlen (kpathsea_version_string);
+    s = xtalloc (slen, char);
     /* The Web2c version string starts with a space.  */
-    sprintf(s, "%s%s %s", ptexbanner, versionstring, kpathsea_version_string);
-    pdftexbanner = maketexstring(s);
-    xfree(s);
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+    snprintf (s, slen,
+#else
+    sprintf (s,
+#endif
+             "%s%s %s", ptexbanner, versionstring, kpathsea_version_string);
+    pdftexbanner = maketexstring (s);
+    xfree (s);
     pdftexbanner_init = true;
 }
 
-strnumber getresnameprefix(void)
+strnumber getresnameprefix (void)
 {
 /*     static char name_str[] = */
 /* "!\"$&'*+,-.0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\" */
 /* "^_`abcdefghijklmnopqrstuvwxyz|~"; */
     static char name_str[] =
-"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-    char prefix[7]; /* make a tag of 6 chars long */
+        "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+    char prefix[7];             /* make a tag of 6 chars long */
     unsigned long crc;
-    int i, base = strlen(name_str);
-    crc = crc32(0L, Z_NULL, 0);
-    crc = crc32(crc, (Bytef*)job_id_string, strlen(job_id_string));
+    int i;
+    size_t base = strlen (name_str);
+    crc = crc32 (0L, Z_NULL, 0);
+    crc = crc32 (crc, (Bytef *) job_id_string, strlen (job_id_string));
     for (i = 0; i < 6; i++) {
         prefix[i] = name_str[crc % base];
         crc /= base;
     }
     prefix[6] = 0;
-    return maketexstring(prefix);
+    return maketexstring (prefix);
 }
 
-size_t xfwrite(void *ptr, size_t size, size_t nmemb, FILE *stream)
+size_t xfwrite (void *ptr, size_t size, size_t nmemb, FILE * stream)
 {
-    if (fwrite(ptr, size, nmemb, stream) != nmemb)
-        pdftex_fail("fwrite() failed");
+    if (fwrite (ptr, size, nmemb, stream) != nmemb)
+        pdftex_fail ("fwrite() failed");
     return nmemb;
 }
 
-int xfflush(FILE *stream)
+int xfflush (FILE * stream)
 {
-    if (fflush(stream) != 0)
-        pdftex_fail("fflush() failed");
+    if (fflush (stream) != 0)
+        pdftex_fail ("fflush() failed");
     return 0;
 }
 
-int xgetc(FILE *stream)
+int xgetc (FILE * stream)
 {
-    int c = getc(stream);
+    int c = getc (stream);
     if (c < 0 && c != EOF)
-        pdftex_fail("getc() failed");
+        pdftex_fail ("getc() failed");
     return c;
 }
 
-int xputc(int c, FILE *stream)
+int xputc (int c, FILE * stream)
 {
-    int i = putc(c, stream);
+    int i = putc (c, stream);
     if (i < 0)
-        pdftex_fail("putc() failed");
+        pdftex_fail ("putc() failed");
     return i;
 }
 
-void writestreamlength(integer length, integer offset)
+void writestreamlength (integer length, integer offset)
 {
     integer save_offset;
     if (jobname_cstr == NULL)
-        jobname_cstr = xstrdup(makecstring(jobname));
-    save_offset = xftell(pdffile, jobname_cstr);
-    xfseek(pdffile, offset, SEEK_SET, jobname_cstr);
-    fprintf(pdffile, "%li", (long int)length);
-    xfseek(pdffile, pdfoffset(), SEEK_SET, jobname_cstr);
+        jobname_cstr = xstrdup (makecstring (jobname));
+    save_offset = xftell (pdffile, jobname_cstr);
+    xfseek (pdffile, offset, SEEK_SET, jobname_cstr);
+    fprintf (pdffile, "%li", (long int) length);
+    xfseek (pdffile, pdfoffset (), SEEK_SET, jobname_cstr);
 }
 
-scaled extxnoverd(scaled x, scaled n, scaled d)
+scaled extxnoverd (scaled x, scaled n, scaled d)
 {
-    double r = (((double)x)*((double)n))/((double)d);
-    if (r > 0)
+    double r = (((double) x) * ((double) n)) / ((double) d);
+    if (r > DBL_EPSILON)
         r += 0.5;
     else
         r -= 0.5;
-    if (r >= (double)maxinteger || r <= -(double)maxinteger)
-        pdftex_warn("arithmetic: number too big");
-    return r;
+    if (r >= (double) maxinteger || r <= -(double) maxinteger)
+        pdftex_warn ("arithmetic: number too big");
+    return (scaled) r;
 }
 
-void libpdffinish()
+void libpdffinish ()
 {
-    xfree(fb_array);
-    xfree(char_array);
-    xfree(job_id_string);
-    fm_free();
-    t1_free();
-    enc_free();
-    img_free();
-    vf_free();
-    epdf_free();
+    xfree (fb_array);
+    xfree (char_array);
+    xfree (job_id_string);
+    fm_free ();
+    t1_free ();
+    enc_free ();
+    img_free ();
+    vf_free ();
+    epdf_free ();
+    ttf_free ();
+    sfd_free ();
+    glyph_unicode_free ();
 }
 
 /* Converts any string given in in in an allowed PDF string which can be
- * handled by printf et.al.: \ is escaped to \\, paranthesis are escaped and
- * control characters are hexadecimal encoded.
+ * handled by printf et.al.: \ is escaped to \\, parenthesis are escaped and
+ * control characters are octal encoded.
+ * This assumes that the string does not contain any already escaped
+ * characters!
  */
-char *convertStringToPDFString (char *in)
+char *convertStringToPDFString (const char *in, int len)
 {
     static char pstrbuf[MAX_PSTRING_LEN];
     char *out = pstrbuf;
-    int lin = strlen (in);
     int i, j;
-    char buf[4];
+    char buf[5];
     j = 0;
-    for (i = 0; i < lin; i++) {
-        check_buf(j + sizeof(buf), MAX_PSTRING_LEN);
-        if ((unsigned char)in[i] < ' ') {
-            /* convert control characters into hex */
-            sprintf (buf, "#%02x", (unsigned int)(unsigned char)in[i]);
+    for (i = 0; i < len; i++) {
+        check_buf (j + sizeof (buf), MAX_PSTRING_LEN);
+        if (((unsigned char) in[i] < '!') || ((unsigned char) in[i] > '~')) {
+            /* convert control characters into oct */
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+            snprintf (buf, sizeof (buf),
+#else
+            sprintf (buf,
+#endif
+                     "\\%03o", (unsigned int) (unsigned char) in[i]);
             out[j++] = buf[0];
             out[j++] = buf[1];
             out[j++] = buf[2];
-            }
-        else if ((in[i] == '(') || (in[i] == ')')) {
+            out[j++] = buf[3];
+        } else if ((in[i] == '(') || (in[i] == ')')) {
             /* escape paranthesis */
             out[j++] = '\\';
             out[j++] = in[i];
-            }
-        else if (in[i] == '\\') {
+        } else if (in[i] == '\\') {
             /* escape backslash */
             out[j++] = '\\';
             out[j++] = '\\';
-            }
-        else {
+        } else {
             /* copy char :-) */
             out[j++] = in[i];
-            }
         }
+    }
     out[j] = '\0';
     return pstrbuf;
 }
 
+
+/* Converts any string given in in in an allowed PDF string which can be
+ * handled by printf et.al.: \ is escaped to \\, parenthesis are escaped and
+ * control characters are octal encoded.
+ * This assumes that the string does not contain any already escaped
+ * characters!
+ *
+ * See escapename for parameter description.
+ */
+void escapestring (poolpointer in)
+{
+    const poolpointer out = poolptr;
+    unsigned char ch;
+    while (in < out) {
+        if (poolptr + 4 >= poolsize) {
+            poolptr = poolsize;
+            /* error by str_toks that calls str_room(1) */
+            return;
+        }
+
+        ch = (unsigned char) strpool[in++];
+
+        if ((ch < '!') || (ch > '~')) {
+            /* convert control characters into oct */
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+            snprintf ((char *) &strpool[poolptr], 4,
+#else
+            sprintf ((char *) &strpool[poolptr],
+#endif
+                     "\\%.3o", (unsigned int) ch);
+            poolptr += 4;
+            continue;
+        }
+        if ((ch == '(') || (ch == ')') || (ch == '\\')) {
+            /* escape parenthesis and backslash */
+            strpool[poolptr++] = '\\';
+        }
+        /* copy char :-) */
+        strpool[poolptr++] = ch;
+    }
+}
+
+
+/* Convert any given string in a PDF name using escaping mechanism
+   of PDF 1.2. The result does not include the leading slash.
+   
+   PDF specification 1.6, section 3.2.6 "Name Objects" explains:
+   <blockquote>
+    Beginning with PDF 1.2, any character except null (character code 0) may
+    be included in a name by writing its 2-digit hexadecimal code, preceded
+    by the number sign character (#); see implementation notes 3 and 4 in
+    Appendix H. This syntax is required to represent any of the delimiter or
+    white-space characters or the number sign character itself; it is
+    recommended but not required for characters whose codes are outside the
+    range 33 (!) to 126 (~).
+   </blockquote>
+   The following table shows the conversion that are done by this
+   function:
+     code      result   reason
+     -----------------------------------
+     0         ignored  not allowed
+     1..32     escaped  must for white-space:
+                          9 (tab), 10 (lf), 12 (ff), 13 (cr), 32 (space)
+                        recommended for the other control characters
+     35        escaped  escape char "#"
+     37        escaped  delimiter "%"
+     40..41    escaped  delimiters "(" and ")"
+     47        escaped  delimiter "/"
+     60        escaped  delimiter "<"
+     62        escaped  delimiter ">"
+     91        escaped  delimiter "["
+     93        escaped  delimiter "]"
+     123       escaped  delimiter "{"
+     125       escaped  delimiter "}"
+     127..255  escaped  recommended
+     else      copy     regular characters
+     
+   Parameter "in" is a pointer into the string pool where
+   the input string is located. The output string is written
+   as temporary string right after the input string.
+   Thus at the begin of the procedure the global variable
+   "poolptr" points to the start of the output string and
+   after the end when the procedure returns.
+*/
+void escapename (poolpointer in)
+{
+    const poolpointer out = poolptr;
+    unsigned char ch;
+
+    while (in < out) {
+        if (poolptr + 3 >= poolsize) {
+            poolptr = poolsize;
+            /* error by str_toks that calls str_room(1) */
+            return;
+        }
+
+        ch = (unsigned char) strpool[in++];
+
+        if ((ch >= 1 && ch <= 32) || ch >= 127) {
+            /* escape */
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+            snprintf ((char *) &strpool[poolptr], 3,
+#else
+            sprintf ((char *) &strpool[poolptr],
+#endif
+                     "#%.2X", (unsigned int) ch);
+            poolptr += 3;
+            continue;
+        }
+        switch (ch) {
+        case 0:
+            /* ignore */
+            break;
+        case 35:
+        case 37:
+        case 40:
+        case 41:
+        case 47:
+        case 60:
+        case 62:
+        case 91:
+        case 93:
+        case 123:
+        case 125:
+            /* escape */
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+            snprintf ((char *) &strpool[poolptr], 3,
+#else
+            sprintf ((char *) &strpool[poolptr],
+#endif
+                     "#%.2X", (unsigned int) ch);
+            poolptr += 3;
+            break;
+        default:
+            /* copy */
+            strpool[poolptr++] = ch;
+        }
+    }
+}
+
+/* Convert any given string in a PDF hexadecimal string. The
+   result does not include the angle brackets.
+   
+   This procedure uses uppercase hexadecimal letters.
+   
+   See escapename for description of parameters.
+*/
+void escapehex (poolpointer in)
+{
+    const poolpointer out = poolptr;
+    unsigned char ch;
+
+    while (in < out) {
+        if (poolptr + 2 >= poolsize) {
+            poolptr = poolsize;
+            /* error by str_toks that calls str_room(1) */
+            return;
+        }
+
+        ch = (unsigned char) strpool[in++];
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+        snprintf ((char *) &strpool[poolptr], 3,
+#else
+        sprintf ((char *) &strpool[poolptr],
+#endif
+                 "%.2X", (unsigned int) ch);
+        poolptr += 2;
+    }
+}
+
+/* Unescape any given hexadecimal string.
+
+   Last hex digit can be omitted, it is replaced by zero, see
+   PDF specification.
+   
+   Invalid digits are silently ignored.
+
+   See escapename for description of parameters.
+*/
+void unescapehex (poolpointer in)
+{
+    const poolpointer out = poolptr;
+    unsigned char ch, a;
+    boolean first = true;
+
+    while (in < out) {
+        if (poolptr + 1 >= poolsize) {
+            poolptr = poolsize;
+            /* error by str_toks that calls str_room(1) */
+            return;
+        }
+
+        ch = (unsigned char) strpool[in++];
+
+        if ((ch >= '0') && (ch <= '9')) {
+            ch -= '0';
+        } else if ((ch >= 'A') && (ch <= 'F')) {
+            ch -= 'A' - 10;
+        } else if ((ch >= 'a') && (ch <= 'f')) {
+            ch -= 'a' - 10;
+        } else {
+            continue;           /* ignore wrong character */
+        }
+
+        if (first) {
+            a = ch << 4;
+            first = false;
+            continue;
+        }
+
+        strpool[poolptr++] = a + ch;
+        first = true;
+    }
+    if (!first) {               /* last hex digit is omitted */
+        strpool[poolptr++] = ch << 4;
+    }
+}
+
+
 /* Converts any string given in in in an allowed PDF string which is 
- * hexadecimal encoded and enclosed in '<' and '>'.
- * sizeof(out) should be at least lin*2+3.
+ * hexadecimal encoded;
+ * sizeof(out) should be at least lin*2+1.
  */
-void convertStringToHexString (char *in, char *out, int lin)
+static void convertStringToHexString (const char *in, char *out, int lin)
 {
     int i, j;
     char buf[3];
-    out[0] = '<';
-    j = 1;
+    j = 0;
     for (i = 0; i < lin; i++) {
-        sprintf (buf, "%02X", (unsigned int)(unsigned char)in[i]);
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+        snprintf (buf, sizeof (buf),
+#else
+        sprintf (buf,
+#endif
+                 "%02X", (unsigned int) (unsigned char) in[i]);
         out[j++] = buf[0];
         out[j++] = buf[1];
-        }
-    out[j++] = '>';
+    }
     out[j] = '\0';
 }
 
@@ -487,23 +781,24 @@
     char *file_name;
     char pwd[4096];
     /* start md5 */
-    md5_init(&state);
+    md5_init (&state);
     /* get the time */
-    t = time(NULL);
-    size = strftime (time_str, sizeof(time_str), "%Y%m%dT%H%M%SZ", gmtime(&t));
-    md5_append(&state, (const md5_byte_t *)time_str, size);
+    t = time (NULL);
+    size =
+        strftime (time_str, sizeof (time_str), "%Y%m%dT%H%M%SZ", gmtime (&t));
+    md5_append (&state, (const md5_byte_t *) time_str, size);
     /* get the file name */
-    if (getcwd(pwd, sizeof(pwd)) == NULL)
-        pdftex_fail("getcwd() failed (path too long?)");
-    file_name = makecstring(filename);
-    md5_append(&state, (const md5_byte_t *)pwd, strlen(pwd));
-    md5_append(&state, (const md5_byte_t *)"/", 1);
-    md5_append(&state, (const md5_byte_t *)file_name, strlen(file_name));
+    if (getcwd (pwd, sizeof (pwd)) == NULL)
+        pdftex_fail ("getcwd() failed (path too long?)");
+    file_name = makecstring (filename);
+    md5_append (&state, (const md5_byte_t *) pwd, strlen (pwd));
+    md5_append (&state, (const md5_byte_t *) "/", 1);
+    md5_append (&state, (const md5_byte_t *) file_name, strlen (file_name));
     /* finish md5 */
-    md5_finish(&state, digest);
+    md5_finish (&state, digest);
     /* write the IDs */
-    convertStringToHexString ((char*)digest, id, 16);
-    pdf_printf("/ID [%s %s]\n", id, id);
+    convertStringToHexString ((char *) digest, id, 16);
+    pdf_printf ("/ID [<%s> <%s>]", id, id);
 }
 
 /* Print the /CreationDate entry.
@@ -555,76 +850,453 @@
   C99 (e.g. newer glibc) with %z, but we have to work with other systems (e.g.
   Solaris 2.5). 
 */
-void printcreationdate()
+
+static time_t start_time = 0;
+#define TIME_STR_SIZE 30
+static char start_time_str[TIME_STR_SIZE];
+static char time_str[TIME_STR_SIZE];
+    /* minimum size for time_str is 24: "D:YYYYmmddHHMMSS+HH'MM'" */
+
+static void makepdftime (time_t t, char *time_str)
 {
-            
-    time_t t;
+
     struct tm lt, gmt;
     size_t size;
-    /* minimum size for time_str is 22: "YYYYmmddHHMMSS+HH'MM'" */
-    char time_str[40]; /* larger value for safety */
     int off, off_hours, off_mins;
- 
+
     /* get the time */
-    t = time(NULL);
-    lt = *localtime(&t);
-    size = strftime(time_str, sizeof(time_str), "%Y%m%d%H%M%S", &lt);
+    lt = *localtime (&t);
+    size = strftime (time_str, TIME_STR_SIZE, "D:%Y%m%d%H%M%S", &lt);
     /* expected format: "YYYYmmddHHMMSS" */
-    if (size != 14) {
-        /* An unexpected result of strftime */
-        pdftex_warn("/CreationDate dropped because of "
-                    "unexpected result of strftime()");
+    if (size == 0) {
+        /* unexpected, contents of time_str is undefined */
+        time_str[0] = '\0';
         return;
     }
 
     /* correction for seconds: %S can be in range 00..61,
        the PDF reference expects 00..59,   
        therefore we map "60" and "61" to "59" */
-    if (time_str[12] == '6') {
-        time_str[12] = '5';
-        time_str[13] = '9'; /* we have checked for size above */
+    if (time_str[14] == '6') {
+        time_str[14] = '5';
+        time_str[15] = '9';
+        time_str[16] = '\0';    /* for safety */
     }
 
     /* get the time zone offset */
-    gmt = *gmtime(&t);
+    gmt = *gmtime (&t);
 
     /* this calculation method was found in exim's tod.c */
-    off = 60*(lt.tm_hour - gmt.tm_hour) + lt.tm_min - gmt.tm_min;
+    off = 60 * (lt.tm_hour - gmt.tm_hour) + lt.tm_min - gmt.tm_min;
     if (lt.tm_year != gmt.tm_year) {
         off += (lt.tm_year > gmt.tm_year) ? 1440 : -1440;
-    }
-    else if (lt.tm_yday != gmt.tm_yday) {
+    } else if (lt.tm_yday != gmt.tm_yday) {
         off += (lt.tm_yday > gmt.tm_yday) ? 1440 : -1440;
     }
 
     if (off == 0) {
         time_str[size++] = 'Z';
         time_str[size] = 0;
+    } else {
+        off_hours = off / 60;
+        off_mins = abs (off - off_hours * 60);
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+        snprintf (&time_str[size], 9,
+#else
+        sprintf (&time_str[size],
+#endif
+                 "%+03d'%02d'", off_hours, off_mins);
     }
-    else {
-        off_hours = off/60;
-        off_mins = abs(off - off_hours*60);
-        sprintf(&time_str[size], "%+03i'%02d'", off_hours, off_mins);
+}
+
+void initstarttime ()
+{
+    if (start_time == 0) {
+        start_time = time ((time_t *) NULL);
+        makepdftime (start_time, start_time_str);
     }
+}
 
-    /* print result */
-    pdf_printf("/CreationDate (D:%s)\n", time_str);
+void printcreationdate ()
+{
+    initstarttime ();
+    pdf_printf ("/CreationDate (%s)\n", start_time_str);
 }
 
-void escapestr(strnumber s)
+void printmoddate ()
 {
-    escaped_string = convertStringToPDFString(makecstring(s));
+    initstarttime ();
+    pdf_printf ("/ModDate (%s)\n", start_time_str);
 }
 
-integer escapedstrlen()
+void getcreationdate ()
 {
-    assert(escaped_string != NULL);
-    return strlen(escaped_string);
+    /* put creation date on top of string pool and update poolptr */
+    size_t len = strlen (start_time_str);
+
+    initstarttime ();
+
+    if (poolptr + len >= poolsize) {
+        poolptr = poolsize;
+        /* error by str_toks that calls str_room(1) */
+        return;
+    }
+
+    memcpy (&strpool[poolptr], start_time_str, len);
+    poolptr += len;
 }
 
-ASCIIcode getescapedchar(integer index)
+void getfilemoddate (strnumber s)
 {
-    if (index < 0 || index >= strlen(escaped_string))
-        pdftex_fail("getescapedchar(): index out of range");
-    return escaped_string[index];
+    struct stat file_data;
+
+    char *file_name = kpse_find_tex (makecfilename (s));
+    if (file_name == NULL) {
+        return;                 /* empty string */
+    }
+
+    /* get file status */
+    if (stat (file_name, &file_data) == 0) {
+        size_t len;
+
+        makepdftime (file_data.st_mtime, time_str);
+        len = strlen (time_str);
+        if (poolptr + len >= poolsize) {
+            poolptr = poolsize;
+            /* error by str_toks that calls str_room(1) */
+        } else {
+            memcpy (&strpool[poolptr], time_str, len);
+            poolptr += len;
+        }
+    }
+    /* else { errno contains error code } */
+
+    xfree (file_name);
 }
+
+void getfilesize (strnumber s)
+{
+    struct stat file_data;
+
+    char *file_name = kpse_find_tex (makecfilename (s));
+    if (file_name == NULL) {
+        return;                 /* empty string */
+    }
+
+    /* get file status */
+    if (stat (file_name, &file_data) == 0) {
+        size_t len;
+        char buf[20];
+
+        /* st_size has type off_t */
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+        snprintf (buf, sizeof (buf),
+#else
+        sprintf (buf,
+#endif
+                 "%lu", (long unsigned int) file_data.st_size);
+        len = strlen (buf);
+        if (poolptr + len >= poolsize) {
+            poolptr = poolsize;
+            /* error by str_toks that calls str_room(1) */
+        } else {
+            memcpy (&strpool[poolptr], buf, len);
+            poolptr += len;
+        }
+    }
+    /* else { errno contains error code } */
+
+    xfree (file_name);
+}
+
+#define DIGEST_SIZE 16
+#define FILE_BUF_SIZE 1024
+
+void getmd5sum (strnumber s, boolean file)
+{
+    md5_state_t state;
+    md5_byte_t digest[DIGEST_SIZE];
+    char outbuf[2 * DIGEST_SIZE + 1];
+    int len = 2 * DIGEST_SIZE;
+
+    if (file) {
+        char file_buf[FILE_BUF_SIZE];
+        int read = 0;
+        FILE *f;
+
+        char *file_name = kpse_find_tex (makecfilename (s));
+        if (file_name == NULL) {
+            return;             /* empty string */
+        }
+        /* in case of error the empty string is returned,
+           no need for xfopen that aborts on error.
+         */
+        f = fopen (file_name, FOPEN_RBIN_MODE);
+        if (f == NULL) {
+            xfree (file_name);
+            return;
+        }
+        md5_init (&state);
+        while ((read = fread (&file_buf, sizeof (char), FILE_BUF_SIZE, f)) > 0) {
+            md5_append (&state, (const md5_byte_t *) file_buf, read);
+        }
+        md5_finish (&state, digest);
+        fclose (f);
+
+        xfree (file_name);
+    } else {
+        /* s contains the data */
+        md5_init (&state);
+        md5_append (&state,
+                    (const md5_byte_t *) &strpool[strstart[s]],
+                    strstart[s + 1] - strstart[s]);
+        md5_finish (&state, digest);
+    }
+
+    if (poolptr + len >= poolsize) {
+        /* error by str_toks that calls str_room(1) */
+        return;
+    }
+    convertStringToHexString ((char *) digest, outbuf, DIGEST_SIZE);
+    memcpy (&strpool[poolptr], outbuf, len);
+    poolptr += len;
+}
+
+void getfiledump (strnumber s, int offset, int length)
+{
+    FILE *f;
+    int read;
+    poolpointer data_ptr;
+    poolpointer data_end;
+    char *file_name;
+
+    if (length == 0) {
+        /* empty result string */
+        return;
+    }
+
+    if (poolptr + 2 * length + 1 >= poolsize) {
+        /* no place for result */
+        poolptr = poolsize;
+        /* error by str_toks that calls str_room(1) */
+        return;
+    }
+
+    file_name = kpse_find_tex (makecfilename (s));
+    if (file_name == NULL) {
+        return;                 /* empty string */
+    }
+
+    /* read file data */
+    f = fopen (file_name, FOPEN_RBIN_MODE);
+    if (f == NULL) {
+        xfree (file_name);
+        return;
+    }
+    if (fseek (f, (long) offset, SEEK_SET) != 0) {
+        xfree (file_name);
+        return;
+    }
+    /* there is enough space in the string pool, the read
+       data are put in the upper half of the result, thus
+       the conversion to hex can be done without overwriting
+       unconverted bytes. Be aware that sprintf also appends
+       a nul byte at the end. */
+    data_ptr = poolptr + length;
+    read = fread (&strpool[data_ptr], sizeof (char), length, f);
+    fclose (f);
+
+    /* convert to hex */
+    data_end = data_ptr + read;
+    for (; data_ptr < data_end; data_ptr++) {
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+        snprintf ((char *) &strpool[poolptr], 3,
+#else
+        sprintf ((char *) &strpool[poolptr],
+#endif
+                 "%.2X", (unsigned int) strpool[data_ptr]);
+        poolptr += 2;
+    }
+    xfree (file_name);
+}
+
+#define DEFAULT_SUB_MATCH_COUNT 10
+static int sub_match_count = DEFAULT_SUB_MATCH_COUNT;
+static regmatch_t *pmatch = NULL;
+static char *match_string = NULL;
+
+void matchstrings (strnumber s, strnumber t, int subcount, boolean icase)
+{
+    regex_t preg;
+    int cflags = REG_EXTENDED;
+    int eflags = 0;
+    int ret;
+    char *str;
+
+    if (icase) {
+        cflags |= REG_ICASE;
+    }
+
+    if (poolptr + 10 >= poolsize) {
+        poolptr = poolsize;
+        return;
+    }
+
+    str = makecstring (s);
+    ret = regcomp (&preg, str, cflags);
+    if (ret != 0) {
+        size_t size = regerror (ret, &preg, NULL, 0);
+        str = xtalloc (size, char);
+        regerror (ret, &preg, str, size);
+        pdftex_warn ("%s%s", "\\pdfmatch: ", str);
+        xfree (str);
+        strpool[poolptr++] = '-';
+        strpool[poolptr++] = '1';
+    } else {
+        str = makecstring (t);
+        sub_match_count = ((subcount < 0) ? DEFAULT_SUB_MATCH_COUNT : subcount);
+        xfree (pmatch);
+        if (sub_match_count > 0) {
+            pmatch = xtalloc (sub_match_count, regmatch_t);
+        }
+        ret = regexec (&preg, str, sub_match_count, pmatch, eflags);
+        xfree (match_string);
+        match_string = xstrdup (str);
+        strpool[poolptr++] = ((ret == 0) ? '1' : '0');
+    }
+
+    regfree (&preg);
+}
+
+void getmatch (int i)
+{
+    int size = 0;
+    int len = 0;
+
+    boolean found = i < sub_match_count
+        && match_string != NULL && pmatch[i].rm_so >= 0 && i >= 0;
+
+    if (found) {
+        len = pmatch[i].rm_eo - pmatch[i].rm_so;
+        size = 20 + len;
+        /* 20: place for integer number and '->' */
+    } else {
+        size = 4;
+    }
+
+    if (poolptr + size >= poolsize) {
+        poolptr = poolsize;
+        return;
+    }
+
+    if (found) {
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >=199901L
+        snprintf ((char *) &strpool[poolptr], 20,
+#else
+        sprintf ((char *) &strpool[poolptr],
+#endif
+                 "%d", pmatch[i].rm_so);
+        poolptr += strlen (&strpool[poolptr]);
+        strpool[poolptr++] = '-';
+        strpool[poolptr++] = '>';
+        memcpy (&strpool[poolptr], &match_string[pmatch[i].rm_so], len);
+        poolptr += len;
+        return;
+    }
+
+    strpool[poolptr++] = '-';
+    strpool[poolptr++] = '1';
+    strpool[poolptr++] = '-';
+    strpool[poolptr++] = '>';
+}
+
+
+/* makecfilename
+  input/ouput same as makecstring:
+    input: string number
+    output: C string with quotes removed.
+    That means, file names that are legal on some operation systems
+    cannot any more be used since pdfTeX version 1.30.4.
+*/
+char *makecfilename (strnumber s)
+{
+    char *name = makecstring (s);
+    char *p = name;
+    char *q = name;
+
+    while (*p) {
+        if (*p != '"')
+            *q++ = *p;
+        p++;
+    }
+    *q = '\0';
+    return name;
+}
+
+/* function strips trailing zeros in string with numbers; */
+/* leading zeros are not stripped (as in real life) */
+char *stripzeros (char *a)
+{
+    enum { NONUM, DOTNONUM, INT, DOT, LEADDOT, FRAC } s = NONUM, t = NONUM;
+    char *p, *q, *r;
+    for (p = q = r = a; *q != '\0';) {
+        switch (s) {
+        case NONUM:
+            if (*p >= '0' && *p <= '9')
+                s = INT;
+            else if (*p == '.')
+                s = LEADDOT;
+            break;
+        case DOTNONUM:
+            if (*p != '.' && (*p < '0' || *p > '9'))
+                s = NONUM;
+            break;
+        case INT:
+            if (*p == '.')
+                s = DOT;
+            else if (*p < '0' || *p > '9')
+                s = NONUM;
+            break;
+        case DOT:
+        case LEADDOT:
+            if (*p >= '0' && *p <= '9')
+                s = FRAC;
+            else if (*p == '.')
+                s = DOTNONUM;
+            else
+                s = NONUM;
+            break;
+        case FRAC:
+            if (*p == '.')
+                s = DOTNONUM;
+            else if (*p < '0' || *p > '9')
+                s = NONUM;
+            break;
+        default:;
+        }
+        switch (s) {
+        case DOT:
+            r = q;
+            break;
+        case LEADDOT:
+            r = q + 1;
+            break;
+        case FRAC:
+            if (*p > '0')
+                r = q + 1;
+            break;
+        case NONUM:
+            if ((t == FRAC || t == DOT) && r != a) {
+                q = r--;
+                if (*r == '.')  /* was a LEADDOT */
+                    *r = '0';
+                r = a;
+            }
+            break;
+        default:;
+        }
+        *q++ = *p++;
+        t = s;
+    }
+    return a;
+}

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/vfpacket.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/vfpacket.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/vfpacket.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -25,30 +25,29 @@
 typedef struct {
     internalfontnumber font;
     char *dataptr;
-    int  len;
+    int len;
 } packet_entry;
 
 /* define packet_ptr, packet_array & packet_limit */
-define_array(packet);   
+define_array (packet);
 
 typedef struct {
     char **data;
     int *len;
     internalfontnumber font;
-}  vf_entry;
+} vf_entry;
 
 /* define vf_ptr, vf_array & vf_limit */
-define_array(vf);   
+define_array (vf);
 
 static char *packet_data_ptr;
 
-integer newvfpacket(internalfontnumber f)
+integer newvfpacket (internalfontnumber f)
 {
-    int i,
-        n = fontec[f] - fontbc[f] + 1;
-    alloc_array(vf, 1, SMALL_ARRAY_SIZE);
-    vf_ptr->len = xtalloc(n, int);
-    vf_ptr->data = xtalloc(n, char *);
+    int i, n = fontec[f] - fontbc[f] + 1;
+    alloc_array (vf, 1, SMALL_ARRAY_SIZE);
+    vf_ptr->len = xtalloc (n, int);
+    vf_ptr->data = xtalloc (n, char *);
     for (i = 0; i < n; i++) {
         vf_ptr->data[i] = NULL;
         vf_ptr->len[i] = 0;
@@ -57,60 +56,60 @@
     return vf_ptr++ - vf_array;
 }
 
-void storepacket(integer f, integer c, integer s)
+void storepacket (integer f, integer c, integer s)
 {
     int l = strstart[s + 1] - strstart[s];
     vf_array[vfpacketbase[f]].len[c - fontbc[f]] = l;
-    vf_array[vfpacketbase[f]].data[c - fontbc[f]] = xtalloc(l, char);
-    memcpy((void *)vf_array[vfpacketbase[f]].data[c - fontbc[f]], 
-           (void *)(strpool + strstart[s]), (unsigned)l);
+    vf_array[vfpacketbase[f]].data[c - fontbc[f]] = xtalloc (l, char);
+    memcpy ((void *) vf_array[vfpacketbase[f]].data[c - fontbc[f]],
+            (void *) (strpool + strstart[s]), (unsigned) l);
 }
 
-void pushpacketstate()
+void pushpacketstate ()
 {
-    alloc_array(packet, 1, SMALL_ARRAY_SIZE);
+    alloc_array (packet, 1, SMALL_ARRAY_SIZE);
     packet_ptr->font = f;
     packet_ptr->dataptr = packet_data_ptr;
     packet_ptr->len = vfpacketlength;
     packet_ptr++;
 }
 
-void poppacketstate()
+void poppacketstate ()
 {
     if (packet_ptr == packet_array)
-        pdftex_fail("packet stack empty, impossible to pop");
+        pdftex_fail ("packet stack empty, impossible to pop");
     packet_ptr--;
     f = packet_ptr->font;
     packet_data_ptr = packet_ptr->dataptr;
     vfpacketlength = packet_ptr->len;
 }
 
-void startpacket(internalfontnumber f, integer c)
+void startpacket (internalfontnumber f, integer c)
 {
     packet_data_ptr = vf_array[vfpacketbase[f]].data[c - fontbc[f]];
     vfpacketlength = vf_array[vfpacketbase[f]].len[c - fontbc[f]];
 }
 
-eightbits packetbyte()
+eightbits packetbyte ()
 {
     vfpacketlength--;
     return *packet_data_ptr++;
 }
 
-void vf_free(void)
+void vf_free (void)
 {
     vf_entry *v;
     int n;
     char **p;
     if (vf_array != NULL) {
         for (v = vf_array; v < vf_ptr; v++) {
-            xfree(v->len);
+            xfree (v->len);
             n = fontec[v->font] - fontec[v->font] + 1;
-            for (p = v->data; p - v->data < n ; p++)
-                xfree(*p);
-            xfree(v->data);
+            for (p = v->data; p - v->data < n; p++)
+                xfree (*p);
+            xfree (v->data);
         }
-        xfree(vf_array);
+        xfree (vf_array);
     }
-    xfree(packet_array);
+    xfree (packet_array);
 }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writeenc.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writeenc.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writeenc.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 1996-2002 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2005 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -17,21 +17,22 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeenc.c#10 $
+$Id: writeenc.c,v 1.3 2005/12/26 14:20:13 hahe Exp hahe $
+
 */
 
 #include "ptexlib.h"
-#include "avlstuff.h"
 
-static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeenc.c#10 $";
+/*@unused@*/
+static const char perforce_id[] =
+    "$Id: writeenc.c,v 1.3 2005/12/26 14:20:13 hahe Exp hahe $";
 
-void read_enc(enc_entry *e)
+void read_enc (enc_entry * e)
 {
-    assert(e != NULL);
+    assert (e != NULL);
     if (e->loaded)
         return;
-    load_enc(e->name, e->glyph_names);
+    load_enc (e->name, e->glyph_names);
     e->loaded = true;
 }
 
@@ -40,209 +41,105 @@
  * the 2nd argument is a pointer to the encoding entry; otherwise the 3rd is 
  * the object number of the Encoding object
  */
-void write_enc(char **glyph_names, enc_entry *e, integer eobjnum)
+void write_enc (char **glyph_names, enc_entry * e, integer eobjnum)
 {
     boolean is_notdef;
     int i;
     char **g;
     if (glyph_names == NULL) {
-        assert(e != NULL);
-        if (e->objnum != 0) /* the encoding has been written already */
+        assert (e != NULL);
+        if (e->objnum != 0)     /* the encoding has been written already */
             return;
-        pdfnewdict(0, 0);
+        pdfnewdict (0, 0, 1);
         e->objnum = objptr;
         g = e->glyph_names;
-    }
-    else {
-        pdfbegindict(eobjnum);
+    } else {
+        pdfbegindict (eobjnum, 1);
         g = glyph_names;
     }
-    pdf_printf("/Type /Encoding\n/Differences [ 0 /%s", g[0]);
+    pdf_printf ("/Type /Encoding\n/Differences [ 0 /%s", g[0]);
     is_notdef = (g[0] == notdef);
-    for (i = 1; i <= MAX_CHAR_CODE; i++) {
+    for (i = 1; i < 256; i++) {
         if (g[i] == notdef) {
             if (!is_notdef) {
-                pdf_printf(" %i/%s", i, notdef);
+                pdf_printf (" %i/%s", i, notdef);
                 is_notdef = true;
             }
-        }
-        else {
+        } else {
             if (is_notdef) {
-                pdf_printf(" %i", i);
+                pdf_printf (" %i", i);
                 is_notdef = false;
             }
-            pdf_printf("/%s", g[i]);
+            pdf_printf ("/%s", g[i]);
         }
     }
-    pdf_puts("]\n");
-    pdfenddict();
+    pdf_puts ("]\n");
+    pdfenddict ();
 }
 
 /**********************************************************************/
-/* All encoding entries go into linked list. The named ones (s != NULL)
-are also registered into AVL tree for quicker search. */
+/* All encoding entries go into AVL tree for fast search by name. */
 
-typedef struct encstruct_ {
-    enc_entry entry;
-    struct encstruct_ *next;
-} encstruct;
-
-static encstruct *epstart = NULL;	/* start of linked list */
-
-/* handle named encodings through AVL tree */
-
 struct avl_table *enc_tree = NULL;
 
 /* AVL sort enc_entry into enc_tree by name */
 
-static int comp_enc_entry(const void *pa, const void *pb, void *p)
+static int comp_enc_entry (const void *pa, const void *pb, void *p)
 {
-    return strcmp(((const enc_entry *) pa)->name,
-		  ((const enc_entry *) pb)->name);
+    return strcmp (((const enc_entry *) pa)->name,
+                   ((const enc_entry *) pb)->name);
 }
 
-enc_entry *add_enc(char *s)
-{				/* built-in encodings have s == NULL */
+enc_entry *add_enc (char *s)
+{
     int i;
-    enc_entry *enc_ptr, etmp;
-    static encstruct *ep;	/* pointer into linked list of encodings */
+    enc_entry tmp, *p;
     void **aa;
 
+    assert (s != NULL);
     if (enc_tree == NULL) {
-	enc_tree = avl_create(comp_enc_entry, NULL, &avl_xallocator);
-	assert(enc_tree != NULL);
+        enc_tree = avl_create (comp_enc_entry, NULL, &avl_xallocator);
+        assert (enc_tree != NULL);
     }
-    if (s != NULL) {
-	etmp.name = s;
-	enc_ptr = (enc_entry *) avl_find(enc_tree, &etmp);
-	if (enc_ptr != NULL)	/* encoding already registered */
-	    return enc_ptr;
-    }
-    if (epstart == NULL) {
-	epstart = xtalloc(1, encstruct);
-	ep = epstart;
-    } else {
-	ep->next = xtalloc(1, encstruct);
-	ep = ep->next;
-    }
-    ep->next = NULL;
-    enc_ptr = &(ep->entry);
-    if (s != NULL) {
-	enc_ptr->name = xstrdup(s);
-	aa = avl_probe(enc_tree, enc_ptr);
-	assert(aa != NULL);
-    } else
-	enc_ptr->name = NULL;
-    enc_ptr->loaded = false;
-    enc_ptr->updated = false;
-    enc_ptr->firstfont = getnullfont();
-    enc_ptr->objnum = 0;
-    enc_ptr->glyph_names = xtalloc(MAX_CHAR_CODE + 1, char *);
-    for (i = 0; i <= MAX_CHAR_CODE; i++)
-	enc_ptr->glyph_names[i] = (char *) notdef;
-
-    return enc_ptr;
+    tmp.name = s;
+    p = (enc_entry *) avl_find (enc_tree, &tmp);
+    if (p != NULL)              /* encoding already registered */
+        return p;
+    p = xtalloc (1, enc_entry);
+    p->loaded = false;
+    p->name = xstrdup (s);
+    p->objnum = 0;
+    p->tounicode = 0;
+    p->glyph_names = xtalloc (256, char *);
+    for (i = 0; i < 256; i++)
+        p->glyph_names[i] = (char *) notdef;
+    aa = avl_probe (enc_tree, p);
+    assert (aa != NULL);
+    return p;
 }
 
 /**********************************************************************/
+/* cleaning up... */
 
-/* get encoding for map entry fm. When encoding vector is not given, try to
- * get it from T1 font file, in this case t1_read_enc sets the font being
- * reencoded, so next calls for the same entry doesn't cause reading the font
- * again
- */
-boolean get_enc(fm_entry *fm)
+static void destroy_enc_entry (void *pa, void *pb)
 {
+    enc_entry *p;
     int i;
-    char **glyph_names;
-    if (is_reencoded(fm)) { /* external encoding vector available */
-        read_enc(fm->encoding);
-        return true;
-    }
-    if (!is_t1fontfile(fm)) /* get built-in encoding for T1 fonts only */
-        return false;
-    if (t1_read_enc(fm)) { /* encoding read into t1_builtin_glyph_names */
-        fm->encoding = add_enc(NULL);
-        glyph_names = (fm->encoding)->glyph_names;
-        for (i = 0; i <= MAX_CHAR_CODE; i++)
-            glyph_names[i] = t1_builtin_glyph_names[i];
-        (fm->encoding)->loaded = true;
-        return true;
-    }
-    return false;
-}
 
-/* check whether an encoding contains indexed glyph in form "/index123" */
-/* boolean indexed_enc(fm_entry *fm) */
-/* { */
-/*     char **s = enc_array[fm->encoding].glyph_names; */
-/*     int i, n; */
-/*     for (i = 0; i <= MAX_CHAR_CODE; i++, s++) */
-/*         if (*s != NULL && *s != notdef &&  */
-/*             sscanf(*s,  INDEXED_GLYPH_PREFIX "%i", &n) == 1) */
-/*                 return true; */
-/*     return false; */
-/* } */
-
-void setcharmap(internalfontnumber f)
-{
-    fm_entry *fm;
-    enc_entry *e;
-    char **glyph_names;
-    int i, k;
-    if (pdfmovechars == 0 || fontbc[f] > 32 || !hasfmentry(f))
-        return;
-    if (fontec[f] < 128) {
-        for (i = fontbc[f]; i <= 32; i++)
-            pdfcharmap[f][i] = i + MOVE_CHARS_OFFSET;
-        return;
-    }
-    fm = (fm_entry *) pdffontmap[f];
-    if (pdfmovechars == 1 || !get_enc(fm))
-        return;
-    e = fm->encoding;
-    if (e->firstfont != getnullfont()) {
-        for (i = fontbc[f]; i <= 32; i++)
-            pdfcharmap[f][i] = pdfcharmap[e->firstfont][i];
-        return;
-    }
-    e->firstfont = f;
-    glyph_names = e->glyph_names;
-    for (i = 32, k = MAX_CHAR_CODE; i >= fontbc[f] && k > 127; i--) {
-        if (glyph_names[i] == notdef)
-            continue;
-        while (glyph_names[k] != notdef && k > 127)
-            k--;
-        if (k < 128)
-            return;
-        glyph_names[k] = glyph_names[i];
-        glyph_names[i] = (char*) notdef;
-        pdfcharmap[f][i] = k;
-    }
+    p = (enc_entry *) pa;
+    xfree (p->name);
+    if (p->glyph_names != NULL)
+        for (i = 0; i < 256; i++)
+            if (p->glyph_names[i] != notdef)
+                xfree (p->glyph_names[i]);
+    xfree (p->glyph_names);
+    xfree (p);
 }
 
-/**********************************************************************/
-/* cleaning up... */
-
-void enc_free()
+void enc_free ()
 {
-    int k;
-    encstruct *p, *pn;
-    enc_entry *e;
-
-    for (p = epstart; p != NULL; p = pn) {
-	e = &(p->entry);
-	pn = p->next;
-	xfree(e->name);
-	if (e->loaded)		/* encoding has been loaded */
-	    for (k = 0; k <= MAX_CHAR_CODE; k++)
-		if (e->glyph_names[k] != notdef)
-		    xfree(e->glyph_names[k]);
-	xfree(e->glyph_names);
-	xfree(p);
-    }
     if (enc_tree != NULL)
-	avl_destroy(enc_tree, NULL);
+        avl_destroy (enc_tree, destroy_enc_entry);
 }
 
 /**********************************************************************/

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writefont.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writefont.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writefont.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,26 +17,26 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writefont.c#13 $
+$Id: writefont.c,v 1.3 2005/12/27 19:04:42 hahe Exp $
 */
 
 #include "ptexlib.h"
 
-static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writefont.c#13 $";
+static const char perforce_id[] =
+    "$Id: writefont.c,v 1.3 2005/12/27 19:04:42 hahe Exp $";
 
 key_entry font_keys[FONT_KEYS_NUM] = {
-    {"Ascent",       "Ascender",     0, false},
-    {"CapHeight",    "CapHeight",    0, false},
-    {"Descent",      "Descender",    0, false},
-    {"FontName",     "FontName",     0, false},
-    {"ItalicAngle",  "ItalicAngle",  0, false},
-    {"StemV",        "StdVW",        0, false},
-    {"XHeight",      "XHeight",      0, false},
-    {"FontBBox",     "FontBBox",     0, false},
-    {"",             "",             0, false},
-    {"",             "",             0, false},
-    {"",             "",             0, false}
+    {"Ascent", "Ascender", 0, false},
+    {"CapHeight", "CapHeight", 0, false},
+    {"Descent", "Descender", 0, false},
+    {"FontName", "FontName", 0, false},
+    {"ItalicAngle", "ItalicAngle", 0, false},
+    {"StemV", "StdVW", 0, false},
+    {"XHeight", "XHeight", 0, false},
+    {"FontBBox", "FontBBox", 0, false},
+    {"", "", 0, false},
+    {"", "", 0, false},
+    {"", "", 0, false}
 };
 
 internalfontnumber tex_font;
@@ -46,301 +46,278 @@
 char fontname_buf[FONTNAME_BUF_SIZE];
 
 static int first_char, last_char;
-static integer char_widths[MAX_CHAR_CODE + 1];
+static integer char_widths[256];
 static boolean write_fontfile_only;
-static int char_widths_objnum,
-           encoding_objnum;
-static char **cur_glyph_names;
+static int char_widths_objnum, encoding_objnum, tounicode_objnum;
 
-static void print_key(integer code, integer v)
+static void print_key (integer code, integer v)
 {
-    pdf_printf("/%s ", font_keys[code].pdfname);
+    pdf_printf ("/%s ", font_keys[code].pdfname);
     if (font_keys[code].valid)
-        pdf_printf("%i", (int)font_keys[code].value);
+        pdf_printf ("%i", (int) font_keys[code].value);
     else
-        pdf_printf("%i", (int)dividescaled(v, pdffontsize[tex_font], 3));
-    pdf_puts("\n");
+        pdf_printf ("%i", (int) dividescaled (v, pdffontsize[tex_font], 3));
+    pdf_puts ("\n");
 }
 
-static void print_italic_angle()
+static void print_italic_angle ()
 {
-    pdf_printf("/%s ", font_keys[ITALIC_ANGLE_CODE].pdfname);
+    pdf_printf ("/%s ", font_keys[ITALIC_ANGLE_CODE].pdfname);
     if (font_keys[ITALIC_ANGLE_CODE].valid)
-        pdf_printf("%g", font_keys[ITALIC_ANGLE_CODE].value);
+        pdf_printf ("%g", font_keys[ITALIC_ANGLE_CODE].value);
     else
-        pdf_printf("%g", -atan(getslant(tex_font)/65536.0)*(180/M_PI));
-    pdf_puts("\n");
+        pdf_printf ("%g", -atan (getslant (tex_font) / 65536.0) * (180 / M_PI));
+    pdf_puts ("\n");
 }
 
-static integer getstemv(void)
+static integer getstemv (void)
 {
-    return getcharwidth(tex_font, '.')/3;
+    return getcharwidth (tex_font, '.') / 3;
 }
 
-static void getbbox(void)
+static void getbbox (void)
 {
     font_keys[FONTBBOX1_CODE].value = 0;
-    font_keys[FONTBBOX2_CODE].value = 
-        dividescaled(-getchardepth(tex_font, 'y'), pdffontsize[tex_font], 3);
+    font_keys[FONTBBOX2_CODE].value =
+        dividescaled (-getchardepth (tex_font, 'y'), pdffontsize[tex_font], 3);
     font_keys[FONTBBOX3_CODE].value =
-        dividescaled(getquad(tex_font), pdffontsize[tex_font], 3);
+        dividescaled (getquad (tex_font), pdffontsize[tex_font], 3);
     font_keys[FONTBBOX4_CODE].value =
-        dividescaled(getcharheight(tex_font, 'H'), pdffontsize[tex_font], 3);
+        dividescaled (getcharheight (tex_font, 'H'), pdffontsize[tex_font], 3);
 }
 
-/*
- * update glyph names of an encoding (either external or internal) 
- * when fontec[f] < 128 
- */
-void update_enc(internalfontnumber f, char **glyph_names)
+static void get_char_widths (void)
 {
     int i;
-    fm_entry *fm = (fm_entry *) pdffontmap[f];
-    if (fontec[f] > 127 || (hasfmentry(f) &&
-         (is_reencoded(fm) && (fm->encoding)->updated)))
-        return;
-    for (i = fontbc[f]; i <= 32; i++)
-        if (pdfcharmap[f][i] != i) {
-            if (glyph_names[i + MOVE_CHARS_OFFSET] != notdef)
-                xfree(glyph_names[i + MOVE_CHARS_OFFSET]);
-            if (glyph_names[i] != notdef)
-                glyph_names[i + MOVE_CHARS_OFFSET] = xstrdup(glyph_names[i]);
-            else
-                glyph_names[i + MOVE_CHARS_OFFSET] = (char*) notdef;
-        }
-    if (is_reencoded(fm))
-        (fm->encoding)->updated = true;
-}
-
-static void get_char_widths(void)
-{
-    int i;
-    for (i = 0; i <= MAX_CHAR_CODE; i++) {
+    for (i = 0; i < 256; i++) {
         if (i < fontbc[tex_font] || i > fontec[tex_font])
             char_widths[i] = 0;
         else
-            char_widths[i] = getcharwidth(tex_font, i);
+            char_widths[i] = getcharwidth (tex_font, i);
     }
-    for (i = fontbc[tex_font]; i <= 32; i++)
-        char_widths[pdfcharmap[tex_font][i]] = char_widths[i];
-    for (i = fontbc[tex_font]; i <= MAX_CHAR_CODE; i++)
-        if (pdfcharmarked(tex_font, i))
+    for (i = fontbc[tex_font]; i < 256; i++)
+        if (pdfcharmarked (tex_font, i))
             break;
     first_char = i;
-    for (i = MAX_CHAR_CODE; i > first_char;  i--)
-        if (pdfcharmarked(tex_font, i))
+    for (i = 255; i > first_char; i--)
+        if (pdfcharmarked (tex_font, i))
             break;
     last_char = i;
     if ((first_char > last_char) ||
-        (first_char == last_char && !pdfcharmarked(tex_font, first_char))) { 
-        write_fontfile_only = true; /* the font is used in PDF images only */
+        (first_char == last_char && !pdfcharmarked (tex_font, first_char))) {
+        write_fontfile_only = true;     /* the font is used in PDF images only */
         return;
     }
     for (i = first_char; i <= last_char; i++)
-        if (pdfcharmarked(tex_font, i))
-            char_widths[i] = dividescaled(char_widths[i], 
-                                          pdffontsize[tex_font], 3);
+        if (pdfcharmarked (tex_font, i))
+            char_widths[i] = dividescaled (char_widths[i],
+                                           pdffontsize[tex_font], 4);
         else
             char_widths[i] = 0;
-    if (is_reencoded(fm_cur) && pdfmovechars > 0) {
-        read_enc(fm_cur->encoding);
-        update_enc(f, (fm_cur->encoding)->glyph_names);
-    }
 }
 
-static void write_char_widths(void)
+static void write_char_widths (void)
 {
-    int i;
-    pdfbeginobj(char_widths_objnum); 
-    pdf_puts("[");
-    for (i = first_char; i <= last_char; i++)
-        pdf_printf("%i ", char_widths[i]);
-    pdf_puts("]\n");
-    pdfendobj();
+    int i, j;
+    pdfbeginobj (char_widths_objnum, 1);
+    pdf_puts ("[");
+    for (i = first_char; i <= last_char; i++) {
+        pdf_printf ("%i", char_widths[i] / 10);
+        if ((j = char_widths[i] % 10) != 0)
+            pdf_printf (".%i", j);
+        pdf_printf (" ");
+    }
+    pdf_puts ("]\n");
+    pdfendobj ();
 }
 
-static void write_fontname(boolean as_reference)
+static void write_fontname (boolean as_reference)
 {
     if (as_reference && fm_cur->fn_objnum != 0) {
-        pdf_printf("%i 0 R\n", (int)fm_cur->fn_objnum);
+        pdf_printf ("%i 0 R\n", (int) fm_cur->fn_objnum);
         return;
     }
-    pdf_puts("/");
+    pdf_puts ("/");
     if (fm_cur->subset_tag != NULL)
-        pdf_printf("%s+", fm_cur->subset_tag);
+        pdf_printf ("%s+", fm_cur->subset_tag);
     if (font_keys[FONTNAME_CODE].valid)
-        pdf_printf("%s", fontname_buf);
+        pdf_printf ("%s", fontname_buf);
     else if (fm_cur->ps_name != NULL)
-        pdf_printf("%s", fm_cur->ps_name);
+        pdf_printf ("%s", fm_cur->ps_name);
     else
-        pdf_printf("%s", fm_cur->tfm_name);
-    pdf_puts("\n");
+        pdf_printf ("%s", fm_cur->tfm_name);
+    pdf_puts ("\n");
 }
 
-static void write_fontobj(integer font_objnum)
+static void write_fontobj (integer font_objnum)
 {
-    pdfbegindict(font_objnum);
-    pdf_puts("/Type /Font\n");
-    pdf_printf("/Subtype /%s\n", is_truetype(fm_cur) ? "TrueType" : "Type1");
+    pdfbegindict (font_objnum, 1);
+    pdf_puts ("/Type /Font\n");
+    pdf_printf ("/Subtype /%s\n", is_truetype (fm_cur) ? "TrueType" : "Type1");
     if (encoding_objnum != 0)
-        pdf_printf("/Encoding %i 0 R\n", (int)encoding_objnum);
-    if (pdffontattr[tex_font] != getnullstr()) {
-        pdfprint(pdffontattr[tex_font]);
-        pdf_puts("\n");
+        pdf_printf ("/Encoding %i 0 R\n", (int) encoding_objnum);
+    if (tounicode_objnum != 0)
+        pdf_printf ("/ToUnicode %i 0 R\n", (int) tounicode_objnum);
+    if (pdffontattr[tex_font] != getnullstr ()) {
+        pdfprint (pdffontattr[tex_font]);
+        pdf_puts ("\n");
     }
-    if (is_basefont(fm_cur) && !is_included(fm_cur)) {
-        pdf_printf("/BaseFont /%s\n", fm_cur->ps_name);
-        pdfenddict();
+    if (no_font_desc (fm_cur)) {
+        pdf_printf ("/BaseFont /%s\n", fm_cur->ps_name);
+        pdfenddict ();
         return;
     }
-    char_widths_objnum = pdfnewobjnum();
-    pdf_printf("/FirstChar %i\n/LastChar %i\n/Widths %i 0 R\n",
-               first_char, last_char, char_widths_objnum);
-    pdf_printf("/BaseFont ");
-    write_fontname(true);
+    char_widths_objnum = pdfnewobjnum ();
+    pdf_printf ("/FirstChar %i\n/LastChar %i\n/Widths %i 0 R\n",
+                first_char, last_char, char_widths_objnum);
+    pdf_printf ("/BaseFont ");
+    write_fontname (true);
     if (fm_cur->fd_objnum == 0)
-        fm_cur->fd_objnum = pdfnewobjnum();
-    pdf_printf("/FontDescriptor %i 0 R\n", fm_cur->fd_objnum);
-    pdfenddict();
+        fm_cur->fd_objnum = pdfnewobjnum ();
+    pdf_printf ("/FontDescriptor %i 0 R\n", fm_cur->fd_objnum);
+    pdfenddict ();
 }
 
-static void write_fontfile(void)
+static void write_fontfile (void)
 {
     int i;
-    for (i = 0; i < FONT_KEYS_NUM; i++)
-        font_keys[i].valid = false;
     fontfile_found = false;
     is_otf_font = false;
-    if (is_truetype(fm_cur))
-        writettf();
+    if (is_truetype (fm_cur))
+        writettf ();
     else
-        writet1();
-    if (!fontfile_found || !is_included(fm_cur))
+        writet1 ();
+    if (!fontfile_found || !is_included (fm_cur))
         return;
     if (fm_cur->ff_objnum == 0)
-        pdftex_fail("font file object number for `%s' not initialized",
-                    fm_cur->tfm_name);
-    pdfbegindict(fm_cur->ff_objnum); /* font file stream */
-    if (is_truetype(fm_cur))
-        pdf_printf("/Length1 %i\n", (int)ttf_length);
-    else if (is_otf_font) 
-        pdf_printf("/Subtype /Type1C\n");
+        pdftex_fail ("font file object number for `%s' not initialized",
+                     fm_cur->tfm_name);
+    pdfbegindict (fm_cur->ff_objnum, 0);        /* font file stream */
+    if (is_truetype (fm_cur))
+        pdf_printf ("/Length1 %i\n", (int) ttf_length);
+    else if (is_otf_font)
+        pdf_printf ("/Subtype /Type1C\n");
     else
-        pdf_printf("/Length1 %i\n/Length2 %i\n/Length3 %i\n",
-                   (int)t1_length1, (int)t1_length2, (int)t1_length3);
-    pdfbeginstream();
-    fb_flush();
-    pdfendstream();
+        pdf_printf ("/Length1 %i\n/Length2 %i\n/Length3 %i\n",
+                    (int) t1_length1, (int) t1_length2, (int) t1_length3);
+    pdfbeginstream ();
+    fb_flush ();
+    pdfendstream ();
 }
 
-static void write_fontdescriptor(void)
+static void write_fontdescriptor (void)
 {
     int i;
-    pdfbegindict(fm_cur->fd_objnum); /* font descriptor */
-    print_key(ASCENT_CODE, getcharheight(tex_font, 'h'));
-    print_key(CAPHEIGHT_CODE, getcharheight(tex_font, 'H'));
-    print_key(DESCENT_CODE, -getchardepth(tex_font, 'y'));
-    pdf_printf("/FontName ");
-    write_fontname(true);
-    print_italic_angle();
-    print_key(STEMV_CODE, getstemv());
-    print_key(XHEIGHT_CODE, getxheight(tex_font));
+    pdfbegindict (fm_cur->fd_objnum, 1);        /* font descriptor */
+    print_key (ASCENT_CODE, getcharheight (tex_font, 'h'));
+    print_key (CAPHEIGHT_CODE, getcharheight (tex_font, 'H'));
+    print_key (DESCENT_CODE, -getchardepth (tex_font, 'y'));
+    pdf_printf ("/FontName ");
+    write_fontname (true);
+    print_italic_angle ();
+    print_key (STEMV_CODE, getstemv ());
+    print_key (XHEIGHT_CODE, getxheight (tex_font));
     if (!font_keys[FONTBBOX1_CODE].valid) {
-        getbbox();
+        getbbox ();
     }
-    pdf_printf("/%s [%i %i %i %i]\n",
-               font_keys[FONTBBOX1_CODE].pdfname,
-               (int)font_keys[FONTBBOX1_CODE].value,
-               (int)font_keys[FONTBBOX2_CODE].value,
-               (int)font_keys[FONTBBOX3_CODE].value,
-               (int)font_keys[FONTBBOX4_CODE].value);
+    pdf_printf ("/%s [%i %i %i %i]\n",
+                font_keys[FONTBBOX1_CODE].pdfname,
+                (int) font_keys[FONTBBOX1_CODE].value,
+                (int) font_keys[FONTBBOX2_CODE].value,
+                (int) font_keys[FONTBBOX3_CODE].value,
+                (int) font_keys[FONTBBOX4_CODE].value);
     if (!fontfile_found && fm_cur->flags == 4)
-        pdf_puts("/Flags 34\n"); /* assumes a roman sans serif font */
+        pdf_puts ("/Flags 34\n");       /* assumes a roman sans serif font */
     else
-        pdf_printf("/Flags %i\n", (int)fm_cur->flags);
-    if (is_included(fm_cur) && fontfile_found) {
-        if (is_subsetted(fm_cur) && !is_truetype(fm_cur)) {
-            cur_glyph_names = t1_glyph_names;
-            pdf_puts("/CharSet (");
-            for (i = 0; i <= MAX_CHAR_CODE; i++)
-                if (pdfcharmarked(tex_font, i) && cur_glyph_names[i] != notdef)
-                    pdf_printf("/%s", cur_glyph_names[i]);
-            pdf_puts(")\n");
+        pdf_printf ("/Flags %i\n", (int) fm_cur->flags);
+    if (is_included (fm_cur) && fontfile_found) {
+        if (is_subsetted (fm_cur) && !is_truetype (fm_cur)) {
+            pdf_puts ("/CharSet (");
+            for (i = 0; i < 256; i++)
+                if (pdfcharmarked (tex_font, i) && t1_glyph_names[i] != notdef)
+                    pdf_printf ("/%s", t1_glyph_names[i]);
+            pdf_puts (")\n");
         }
-        if (is_truetype(fm_cur))
-            pdf_printf("/FontFile2 %i 0 R\n", fm_cur->ff_objnum);
+        if (is_truetype (fm_cur))
+            pdf_printf ("/FontFile2 %i 0 R\n", fm_cur->ff_objnum);
         else if (is_otf_font)
-            pdf_printf("/FontFile3 %i 0 R\n", fm_cur->ff_objnum);
+            pdf_printf ("/FontFile3 %i 0 R\n", fm_cur->ff_objnum);
         else
-            pdf_printf("/FontFile %i 0 R\n", fm_cur->ff_objnum);
+            pdf_printf ("/FontFile %i 0 R\n", fm_cur->ff_objnum);
     }
-    pdfenddict();
+    pdfenddict ();
 }
 
-void dopdffont(integer font_objnum, internalfontnumber f)
+void dopdffont (integer font_objnum, internalfontnumber f)
 {
     int i;
+    enc_entry *e;
+
     tex_font = f;
-    cur_glyph_names = NULL;
     encoding_objnum = 0;
+    tounicode_objnum = 0;
     write_ttf_glyph_names = false;
     write_fontfile_only = false;
+    t1_glyph_names = NULL;
+    for (i = 0; i < FONT_KEYS_NUM; i++)
+        font_keys[i].valid = false;
+
     if (pdffontmap[tex_font] == NULL)
-        pdftex_fail("pdffontmap not initialized for font %s", 
-                    makecstring(fontname[tex_font]));
-    if (hasfmentry(tex_font))
+        pdftex_fail ("pdffontmap not initialized for font %s",
+                     makecstring (fontname[tex_font]));
+    if (hasfmentry (tex_font))
         fm_cur = (fm_entry *) pdffontmap[tex_font];
     else
         fm_cur = NULL;
     if (fm_cur == NULL || (fm_cur->ps_name == NULL && fm_cur->ff_name == NULL)) {
-        writet3(font_objnum, tex_font);
+        writet3 (font_objnum, tex_font);
         return;
     }
 
-    get_char_widths(); /* update char widths; also check whether this font is
-                          used in embedded PDF only; if so then set
-                          write_fontfile_only to true */
+    get_char_widths ();         /* update char widths; also check whether this font is
+                                   used in embedded PDF only; if so then set
+                                   write_fontfile_only to true */
 
-    if (!write_fontfile_only) { /* encoding vector needed */
-        if ((is_reencoded(fm_cur))) {
-            read_enc(fm_cur->encoding);
-            if (!is_truetype(fm_cur)) {
-                write_enc(NULL, fm_cur->encoding, 0);
-                encoding_objnum = (fm_cur->encoding)->objnum;
-            }
-            else
+    if (!write_fontfile_only) { /* handle Encoding + ToUnicode as well */
+        if (is_reencoded (fm_cur)) {
+            e = fm_cur->encoding;
+            read_enc (e);
+            if (!is_truetype (fm_cur)) {
+                write_enc (NULL, e, 0);
+                encoding_objnum = e->objnum;
+                if (fixedgentounicode > 0) {
+                    if (e->tounicode == 0)
+                        e->tounicode =
+                            write_tounicode (e->glyph_names, e->name);
+                    tounicode_objnum = e->tounicode;
+                }
+            } else
                 write_ttf_glyph_names = true;
         }
-        else if (is_fontfile(fm_cur) && !is_truetype(fm_cur)) {
-            encoding_objnum = pdfnewobjnum();
-        }
     }
-    if (is_included(fm_cur))
-        write_fontfile();
+    if (is_included (fm_cur))
+        write_fontfile ();
+    if (!write_fontfile_only && !is_reencoded (fm_cur) &&
+        fixedgentounicode > 0 && t1_glyph_names == t1_builtin_glyph_names) {
+        /* write ToUnicode entry for built-in encoding of Type1 font */
+        tounicode_objnum = write_tounicode (t1_glyph_names, fm_cur->tfm_name);
+    }
     if (fm_cur->fn_objnum != 0) {
-        pdfbeginobj(fm_cur->fn_objnum);
-        write_fontname(false);
-        pdfendobj();
+        pdfbeginobj (fm_cur->fn_objnum, 1);
+        write_fontname (false);
+        pdfendobj ();
     }
     if (!write_fontfile_only)
-        write_fontobj(font_objnum);
-    if (is_basefont(fm_cur) && !is_included(fm_cur))
+        write_fontobj (font_objnum);
+    if (no_font_desc (fm_cur))
         return;
     if (!write_fontfile_only) {
-        write_fontdescriptor();
-        write_char_widths();
+        write_fontdescriptor ();
+        write_char_widths ();
     }
-    if (cur_glyph_names == t1_builtin_glyph_names) {
-        if (!write_fontfile_only) {
-            for (i = 0; i <= MAX_CHAR_CODE; i++)
-                if (!pdfcharmarked(tex_font, i) && cur_glyph_names[i] != notdef) {
-                    xfree(cur_glyph_names[i]);
-                    cur_glyph_names[i] = (char*) notdef;
-                }
-            write_enc(cur_glyph_names, NULL, encoding_objnum);
-        }
-        for (i = 0; i <= MAX_CHAR_CODE; i++)
-            if (cur_glyph_names[i] != notdef)
-                xfree(cur_glyph_names[i]);
+    if (t1_glyph_names == t1_builtin_glyph_names) {
+        for (i = 0; i < 256; i++)
+            if (t1_glyph_names[i] != notdef)
+                xfree (t1_glyph_names[i]);
     }
 }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writeimg.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writeimg.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writeimg.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 1996-2002 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2002, 2005 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -17,7 +17,7 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeimg.c#15 $
+$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeimg.c#17 $
 */
 
 #include "ptexlib.h"
@@ -25,13 +25,13 @@
 #include <kpathsea/c-auto.h>
 #include <kpathsea/c-memstr.h>
 
-static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeimg.c#15 $";
-    
+static const char perforce_id[] =
+    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeimg.c#17 $";
+
 #define bp2int(p)    round(p*(onehundredbp/100.0))
 
 /* define image_ptr, image_array & image_limit */
-define_array(image);   
+define_array (image);
 
 float epdf_width;
 float epdf_height;
@@ -40,12 +40,11 @@
 integer epdf_selected_page;
 integer epdf_num_pages;
 integer epdf_page_box;
-integer epdf_always_use_pdf_pagebox;
 void *epdf_doc;
 
-static integer new_image_entry(void)
+static integer new_image_entry (void)
 {
-    alloc_array(image, 1, SMALL_BUF_SIZE);
+    alloc_array (image, 1, SMALL_BUF_SIZE);
     image_ptr->image_type = IMAGE_TYPE_NONE;
     image_ptr->color_type = 0;
     image_ptr->num_pages = 0;
@@ -57,82 +56,83 @@
     return image_ptr++ - image_array;
 }
 
-integer imagecolor(integer img)
+integer imagecolor (integer img)
 {
-    return img_color(img);
+    return img_color (img);
 }
 
-integer imagewidth(integer img)
+integer imagewidth (integer img)
 {
-    return img_width(img);
+    return img_width (img);
 }
 
-integer imageheight(integer img)
+integer imageheight (integer img)
 {
-    return img_height(img);
+    return img_height (img);
 }
 
-integer imagexres(integer img)
+integer imagexres (integer img)
 {
-    return img_xres(img);
+    return img_xres (img);
 }
 
-integer imageyres(integer img)
+integer imageyres (integer img)
 {
-    return img_yres(img);
+    return img_yres (img);
 }
 
-boolean ispdfimage(integer img)
+boolean ispdfimage (integer img)
 {
-    return img_type(img) == IMAGE_TYPE_PDF;
+    return img_type (img) == IMAGE_TYPE_PDF;
 }
 
-boolean checkimageb(integer procset)
+boolean checkimageb (integer procset)
 {
     return procset & IMAGE_COLOR_B;
 }
 
-boolean checkimagec(integer procset)
+boolean checkimagec (integer procset)
 {
     return procset & IMAGE_COLOR_C;
 }
 
-boolean checkimagei(integer procset)
+boolean checkimagei (integer procset)
 {
     return procset & IMAGE_COLOR_I;
 }
 
-void updateimageprocset(integer img)
+void updateimageprocset (integer img)
 {
-    pdfimageprocset |= img_color(img);
+    pdfimageprocset |= img_color (img);
 }
 
-integer epdforigx(integer img)
+integer epdforigx (integer img)
 {
-    return pdf_ptr(img)->orig_x;
+    return pdf_ptr (img)->orig_x;
 }
 
-integer epdforigy(integer img)
+integer epdforigy (integer img)
 {
-    return pdf_ptr(img)->orig_y;
+    return pdf_ptr (img)->orig_y;
 }
 
-integer imagepages(integer img)
+integer imagepages (integer img)
 {
-    return img_pages(img);
+    return img_pages (img);
 }
 
-integer imagecolordepth(integer img)
+integer imagecolordepth (integer img)
 {
-    switch (img_type(img)) {
+    switch (img_type (img)) {
     case IMAGE_TYPE_PNG:
-        return png_info(img)->bit_depth;
+        return png_info (img)->bit_depth;
     case IMAGE_TYPE_JPG:
-        return jpg_ptr(img)->bits_per_component;
+        return jpg_ptr (img)->bits_per_component;
     case IMAGE_TYPE_PDF:
         return 0;
     default:
-        pdftex_fail("unknown type of image");
+        pdftex_fail ("unknown type of image");
+        return -1;              /* to make the compiler happy */
     }
 }
 
@@ -202,164 +202,150 @@
 #define HEADER_PNG "\x89PNG\r\n\x1A\n"
 #define HEADER_PDF "%PDF-1."
 #define MAX_HEADER (sizeof(HEADER_PNG)-1)
-static void checktypebyheader(integer img)
+static void checktypebyheader (integer img)
 {
     int i;
     FILE *file = NULL;
     char header[MAX_HEADER];
 
-    if (img_type(img) != IMAGE_TYPE_NONE) /* nothing to do */
+    if (img_type (img) != IMAGE_TYPE_NONE)      /* nothing to do */
         return;
 
     /* read the header */
-    file = xfopen(img_name(img), FOPEN_RBIN_MODE);
-    for (i=0; i<MAX_HEADER; i++) {
-        header[i] = xgetc(file);
-        if (feof(file))
-            pdftex_fail("reading image file failed");
+    file = xfopen (img_name (img), FOPEN_RBIN_MODE);
+    for (i = 0; i < MAX_HEADER; i++) {
+        header[i] = xgetc (file);
+        if (feof (file))
+            pdftex_fail ("reading image file failed");
     }
-    xfclose(file, img_name(img));
+    xfclose (file, img_name (img));
 
     /* tests */
-    if (strncmp(header, HEADER_JPG, sizeof(HEADER_JPG)-1) == 0)
-        img_type(img) = IMAGE_TYPE_JPG;
-    else if (strncmp(header, HEADER_PNG, sizeof(HEADER_PNG)-1) == 0)
-        img_type(img) = IMAGE_TYPE_PNG;
-    else if (strncmp(header, HEADER_PDF, sizeof(HEADER_PDF)-1) == 0)
-        img_type(img) = IMAGE_TYPE_PDF;
+    if (strncmp (header, HEADER_JPG, sizeof (HEADER_JPG) - 1) == 0)
+        img_type (img) = IMAGE_TYPE_JPG;
+    else if (strncmp (header, HEADER_PNG, sizeof (HEADER_PNG) - 1) == 0)
+        img_type (img) = IMAGE_TYPE_PNG;
+    else if (strncmp (header, HEADER_PDF, sizeof (HEADER_PDF) - 1) == 0)
+        img_type (img) = IMAGE_TYPE_PDF;
 }
 
-static void checktypebyextension(integer img)
+static void checktypebyextension (integer img)
 {
     char *image_suffix;
 
-    if (img_type(img) != IMAGE_TYPE_NONE) /* nothing to do */
+    if (img_type (img) != IMAGE_TYPE_NONE)      /* nothing to do */
         return;
     /* tests */
-    if ((image_suffix = strrchr(cur_file_name, '.')) == 0)
-        img_type(img) = IMAGE_TYPE_NONE;
-    else if (strcasecmp(image_suffix, ".pdf") == 0)
-        img_type(img) = IMAGE_TYPE_PDF;
-    else if (strcasecmp(image_suffix, ".png") == 0)
-        img_type(img) = IMAGE_TYPE_PNG;
-    else if (strcasecmp(image_suffix, ".jpg") == 0 ||
-             strcasecmp(image_suffix, ".jpeg") == 0)
-        img_type(img) = IMAGE_TYPE_JPG;
+    if ((image_suffix = strrchr (cur_file_name, '.')) == 0)
+        img_type (img) = IMAGE_TYPE_NONE;
+    else if (strcasecmp (image_suffix, ".pdf") == 0)
+        img_type (img) = IMAGE_TYPE_PDF;
+    else if (strcasecmp (image_suffix, ".png") == 0)
+        img_type (img) = IMAGE_TYPE_PNG;
+    else if (strcasecmp (image_suffix, ".jpg") == 0 ||
+             strcasecmp (image_suffix, ".jpeg") == 0)
+        img_type (img) = IMAGE_TYPE_JPG;
 }
 
-integer readimage(strnumber s, integer page_num, strnumber page_name, integer colorspace,
-                  integer pdfversion, integer pdfoptionalwaysusepdfpagebox,
-                  integer pdf_option_pdf_inclusion_errorlevel)
+integer readimage (strnumber s, integer page_num, strnumber page_name,
+                   integer colorspace, integer pagebox,
+                   integer pdfversion, integer pdfinclusionerrorlevel)
 {
     char *dest = NULL;
-    integer img = new_image_entry();
-    img_colorspace_ref(img) = colorspace;
+    integer img = new_image_entry ();
+    img_colorspace_ref (img) = colorspace;
 
     /* need to allocate new string as makecstring's buffer is 
        already used by cur_file_name */
     if (page_name != 0)
-      dest = xstrdup(makecstring(page_name));
-    cur_file_name = makecstring(s);
-#ifdef WIN32
-    /* unquote file name */
-    if (*cur_file_name == '"') {
-      char *p = cur_file_name;
-      char *q = cur_file_name;
-      while (p && *p) {
-    *q = (*p == '"' ? *(++p) : *p);
-    p++, q++;
-      }
-      *q = '\0';
-    }
-    fprintf(stderr, " %s\n", cur_file_name);
-#endif
-    img_name(img) = kpse_find_file(cur_file_name, kpse_tex_format, true);
-    if (img_name(img) == NULL)
-        pdftex_fail("cannot find image file");
+        dest = xstrdup (makecstring (page_name));
+    cur_file_name = makecfilename (s);
+    img_name (img) = kpse_find_file (cur_file_name, kpse_tex_format, true);
+    if (img_name (img) == NULL)
+        pdftex_fail ("cannot find image file");
+    /* kpse_find_file perhaps changed the file name */
+    cur_file_name = img_name (img);
     /* type checks */
-    checktypebyheader(img);
-    checktypebyextension(img);
+    checktypebyheader (img);
+    checktypebyextension (img);
     /* read image */
-    switch (img_type(img)) {
+    switch (img_type (img)) {
     case IMAGE_TYPE_PDF:
-        pdf_ptr(img) = xtalloc(1, pdf_image_struct);
-        pdf_ptr(img)->page_box = pdflastpdfboxspec;
-        pdf_ptr(img)->always_use_pdfpagebox = pdfoptionalwaysusepdfpagebox;
-        page_num = read_pdf_info(img_name(img), dest, page_num, 
-                                     pdfversion, pdfoptionalwaysusepdfpagebox,
-                                     pdf_option_pdf_inclusion_errorlevel);
-        img_width(img) = bp2int(epdf_width);
-        img_height(img) = bp2int(epdf_height);
-        img_pages(img) = epdf_num_pages;
-        pdf_ptr(img)->orig_x = bp2int(epdf_orig_x);
-        pdf_ptr(img)->orig_y = bp2int(epdf_orig_y);
-        pdf_ptr(img)->selected_page = page_num;
-        pdf_ptr(img)->doc = epdf_doc;
+        pdf_ptr (img) = xtalloc (1, pdf_image_struct);
+        pdf_ptr (img)->page_box = pagebox;
+        page_num = read_pdf_info (img_name (img), dest, page_num, pagebox,
+                                  pdfversion, pdfinclusionerrorlevel);
+        img_width (img) = bp2int (epdf_width);
+        img_height (img) = bp2int (epdf_height);
+        img_pages (img) = epdf_num_pages;
+        pdf_ptr (img)->orig_x = bp2int (epdf_orig_x);
+        pdf_ptr (img)->orig_y = bp2int (epdf_orig_y);
+        pdf_ptr (img)->selected_page = page_num;
+        pdf_ptr (img)->doc = epdf_doc;
         break;
     case IMAGE_TYPE_PNG:
-        img_pages(img) = 1;
-        read_png_info(img);
+        img_pages (img) = 1;
+        read_png_info (img);
         break;
     case IMAGE_TYPE_JPG:
-        jpg_ptr(img) = xtalloc(1, JPG_IMAGE_INFO);
-        img_pages(img) = 1;
-        read_jpg_info(img);
+        jpg_ptr (img) = xtalloc (1, JPG_IMAGE_INFO);
+        img_pages (img) = 1;
+        read_jpg_info (img);
         break;
     default:
-        pdftex_fail("unknown type of image");
+        pdftex_fail ("unknown type of image");
     }
-    xfree(dest);
+    xfree (dest);
     cur_file_name = NULL;
     return img;
 }
 
-void writeimage(integer img)
+void writeimage (integer img)
 {
-    cur_file_name = img_name(img);
-    tex_printf(" <%s", img_name(img));
-    switch (img_type(img)) {
+    cur_file_name = img_name (img);
+    tex_printf (" <%s", img_name (img));
+    switch (img_type (img)) {
     case IMAGE_TYPE_PNG:
-        write_png(img);
+        write_png (img);
         break;
     case IMAGE_TYPE_JPG:
-        write_jpg(img);
+        write_jpg (img);
         break;
     case IMAGE_TYPE_PDF:
-        epdf_doc = pdf_ptr(img)->doc;
-        epdf_selected_page = pdf_ptr(img)->selected_page;
-        epdf_page_box = pdf_ptr(img)->page_box;
-        epdf_always_use_pdf_pagebox = pdf_ptr(img)->always_use_pdfpagebox;
-        write_epdf();
+        epdf_doc = pdf_ptr (img)->doc;
+        epdf_selected_page = pdf_ptr (img)->selected_page;
+        epdf_page_box = pdf_ptr (img)->page_box;
+        write_epdf ();
         break;
     default:
-        pdftex_fail("unknown type of image");
+        pdftex_fail ("unknown type of image");
     }
-    tex_printf(">");
+    tex_printf (">");
     cur_file_name = NULL;
 }
 
-void deleteimage(integer img)
+void deleteimage (integer img)
 {
-    switch (img_type(img)) {
+    switch (img_type (img)) {
     case IMAGE_TYPE_PDF:
-        epdf_doc = pdf_ptr(img)->doc;
-        epdf_delete();
+        epdf_doc = pdf_ptr (img)->doc;
+        epdf_delete ();
         break;
     case IMAGE_TYPE_PNG:
-        xfclose(png_ptr(img)->io_ptr, cur_file_name);
-        png_destroy_read_struct(&(png_ptr(img)), &(png_info(img)), NULL);
+        xfclose ((FILE *) png_ptr (img)->io_ptr, cur_file_name);
+        png_destroy_read_struct (&(png_ptr (img)), &(png_info (img)), NULL);
         break;
     case IMAGE_TYPE_JPG:
-        xfclose(jpg_ptr(img)->file, cur_file_name);
+        xfclose (jpg_ptr (img)->file, cur_file_name);
         break;
     default:
-        pdftex_fail("unknown type of image");
+        pdftex_fail ("unknown type of image");
     }
-    xfree(img_name(img));
+    xfree (img_name (img));
     return;
 }
 
-void img_free() 
+void img_free ()
 {
-    xfree(image_array);
+    xfree (image_array);
 }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writejpg.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writejpg.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writejpg.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,123 +17,132 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writejpg.c#8 $
+$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writejpg.c#10 $
 */
 
 #include "ptexlib.h"
 #include "image.h"
 
-#define JPG_GRAY  1     /* Gray color space, use /DeviceGray  */
-#define JPG_RGB   3     /* RGB color space, use /DeviceRGB    */
-#define JPG_CMYK  4     /* CMYK color space, use /DeviceCMYK  */
+#define JPG_GRAY  1             /* Gray color space, use /DeviceGray  */
+#define JPG_RGB   3             /* RGB color space, use /DeviceRGB    */
+#define JPG_CMYK  4             /* CMYK color space, use /DeviceCMYK  */
 
-typedef enum {          /* JPEG marker codes                    */
-  M_SOF0  = 0xc0,       /* baseline DCT                         */
-  M_SOF1  = 0xc1,       /* extended sequential DCT              */
-  M_SOF2  = 0xc2,       /* progressive DCT                      */
-  M_SOF3  = 0xc3,       /* lossless (sequential)                */
+typedef enum {                  /* JPEG marker codes                    */
+    M_SOF0 = 0xc0,              /* baseline DCT                         */
+    M_SOF1 = 0xc1,              /* extended sequential DCT              */
+    M_SOF2 = 0xc2,              /* progressive DCT                      */
+    M_SOF3 = 0xc3,              /* lossless (sequential)                */
 
-  M_SOF5  = 0xc5,       /* differential sequential DCT          */
-  M_SOF6  = 0xc6,       /* differential progressive DCT         */
-  M_SOF7  = 0xc7,       /* differential lossless                */
+    M_SOF5 = 0xc5,              /* differential sequential DCT          */
+    M_SOF6 = 0xc6,              /* differential progressive DCT         */
+    M_SOF7 = 0xc7,              /* differential lossless                */
 
-  M_JPG   = 0xc8,       /* JPEG extensions                      */
-  M_SOF9  = 0xc9,       /* extended sequential DCT              */
-  M_SOF10 = 0xca,       /* progressive DCT                      */
-  M_SOF11 = 0xcb,       /* lossless (sequential)                */
+    M_JPG = 0xc8,               /* JPEG extensions                      */
+    M_SOF9 = 0xc9,              /* extended sequential DCT              */
+    M_SOF10 = 0xca,             /* progressive DCT                      */
+    M_SOF11 = 0xcb,             /* lossless (sequential)                */
 
-  M_SOF13 = 0xcd,       /* differential sequential DCT          */
-  M_SOF14 = 0xce,       /* differential progressive DCT         */
-  M_SOF15 = 0xcf,       /* differential lossless                */
+    M_SOF13 = 0xcd,             /* differential sequential DCT          */
+    M_SOF14 = 0xce,             /* differential progressive DCT         */
+    M_SOF15 = 0xcf,             /* differential lossless                */
 
-  M_DHT   = 0xc4,       /* define Huffman tables                */
+    M_DHT = 0xc4,               /* define Huffman tables                */
 
-  M_DAC   = 0xcc,       /* define arithmetic conditioning table */
+    M_DAC = 0xcc,               /* define arithmetic conditioning table */
 
-  M_RST0  = 0xd0,       /* restart                              */
-  M_RST1  = 0xd1,       /* restart                              */
-  M_RST2  = 0xd2,       /* restart                              */
-  M_RST3  = 0xd3,       /* restart                              */
-  M_RST4  = 0xd4,       /* restart                              */
-  M_RST5  = 0xd5,       /* restart                              */
-  M_RST6  = 0xd6,       /* restart                              */
-  M_RST7  = 0xd7,       /* restart                              */
+    M_RST0 = 0xd0,              /* restart                              */
+    M_RST1 = 0xd1,              /* restart                              */
+    M_RST2 = 0xd2,              /* restart                              */
+    M_RST3 = 0xd3,              /* restart                              */
+    M_RST4 = 0xd4,              /* restart                              */
+    M_RST5 = 0xd5,              /* restart                              */
+    M_RST6 = 0xd6,              /* restart                              */
+    M_RST7 = 0xd7,              /* restart                              */
 
-  M_SOI   = 0xd8,       /* start of image                       */
-  M_EOI   = 0xd9,       /* end of image                         */
-  M_SOS   = 0xda,       /* start of scan                        */
-  M_DQT   = 0xdb,       /* define quantization tables           */
-  M_DNL   = 0xdc,       /* define number of lines               */
-  M_DRI   = 0xdd,       /* define restart interval              */
-  M_DHP   = 0xde,       /* define hierarchical progression      */
-  M_EXP   = 0xdf,       /* expand reference image(s)            */
+    M_SOI = 0xd8,               /* start of image                       */
+    M_EOI = 0xd9,               /* end of image                         */
+    M_SOS = 0xda,               /* start of scan                        */
+    M_DQT = 0xdb,               /* define quantization tables           */
+    M_DNL = 0xdc,               /* define number of lines               */
+    M_DRI = 0xdd,               /* define restart interval              */
+    M_DHP = 0xde,               /* define hierarchical progression      */
+    M_EXP = 0xdf,               /* expand reference image(s)            */
 
-  M_APP0  = 0xe0,       /* application marker, used for JFIF    */
-  M_APP1  = 0xe1,       /* application marker                   */
-  M_APP2  = 0xe2,       /* application marker                   */
-  M_APP3  = 0xe3,       /* application marker                   */
-  M_APP4  = 0xe4,       /* application marker                   */
-  M_APP5  = 0xe5,       /* application marker                   */
-  M_APP6  = 0xe6,       /* application marker                   */
-  M_APP7  = 0xe7,       /* application marker                   */
-  M_APP8  = 0xe8,       /* application marker                   */
-  M_APP9  = 0xe9,       /* application marker                   */
-  M_APP10 = 0xea,       /* application marker                   */
-  M_APP11 = 0xeb,       /* application marker                   */
-  M_APP12 = 0xec,       /* application marker                   */
-  M_APP13 = 0xed,       /* application marker                   */
-  M_APP14 = 0xee,       /* application marker, used by Adobe    */
-  M_APP15 = 0xef,       /* application marker                   */
+    M_APP0 = 0xe0,              /* application marker, used for JFIF    */
+    M_APP1 = 0xe1,              /* application marker                   */
+    M_APP2 = 0xe2,              /* application marker                   */
+    M_APP3 = 0xe3,              /* application marker                   */
+    M_APP4 = 0xe4,              /* application marker                   */
+    M_APP5 = 0xe5,              /* application marker                   */
+    M_APP6 = 0xe6,              /* application marker                   */
+    M_APP7 = 0xe7,              /* application marker                   */
+    M_APP8 = 0xe8,              /* application marker                   */
+    M_APP9 = 0xe9,              /* application marker                   */
+    M_APP10 = 0xea,             /* application marker                   */
+    M_APP11 = 0xeb,             /* application marker                   */
+    M_APP12 = 0xec,             /* application marker                   */
+    M_APP13 = 0xed,             /* application marker                   */
+    M_APP14 = 0xee,             /* application marker, used by Adobe    */
+    M_APP15 = 0xef,             /* application marker                   */
 
-  M_JPG0  = 0xf0,       /* reserved for JPEG extensions         */
-  M_JPG13 = 0xfd,       /* reserved for JPEG extensions         */
-  M_COM   = 0xfe,       /* comment                              */
+    M_JPG0 = 0xf0,              /* reserved for JPEG extensions         */
+    M_JPG13 = 0xfd,             /* reserved for JPEG extensions         */
+    M_COM = 0xfe,               /* comment                              */
 
-  M_TEM   = 0x01,       /* temporary use                        */
+    M_TEM = 0x01,               /* temporary use                        */
 
-  M_ERROR = 0x100       /* dummy marker, internal use only      */
+    M_ERROR = 0x100             /* dummy marker, internal use only      */
 } JPEG_MARKER;
 
-static JPG_UINT16 read2bytes(FILE *f)
+static JPG_UINT16 read2bytes (FILE * f)
 {
-    int c = xgetc(f);
-    return (c << 8) + xgetc(f);
+    int c = xgetc (f);
+    return (c << 8) + xgetc (f);
 }
 
-void read_jpg_info(integer img)
+void read_jpg_info (integer img)
 {
-    int i;
-    char jpg_id[]="JFIF";
-    int units=0;
-    img_xres(img)=img_yres(img)=0;
-    jpg_ptr(img)->file = xfopen(img_name(img), FOPEN_RBIN_MODE);
-    xfseek(jpg_ptr(img)->file,0,SEEK_END,cur_file_name);
-    jpg_ptr(img)->length=xftell(jpg_ptr(img)->file,cur_file_name);
-    xfseek(jpg_ptr(img)->file,0,SEEK_SET,cur_file_name);
-    if(read2bytes(jpg_ptr(img)->file)!=0xFFD8)
-        pdftex_fail("reading JPEG image failed");
-
-    if(read2bytes(jpg_ptr(img)->file)==0xFFE0) { /* JFIF APP0 */
-      (void)read2bytes(jpg_ptr(img)->file);
-      for(i=0;i<5;i++) if(xgetc(jpg_ptr(img)->file)!=jpg_id[i])
-        pdftex_fail("reading JPEG image failed");
-      (void)read2bytes(jpg_ptr(img)->file);
-      units=xgetc(jpg_ptr(img)->file);
-      img_xres(img)=read2bytes(jpg_ptr(img)->file);
-      img_yres(img)=read2bytes(jpg_ptr(img)->file);
-      switch(units) {
-          case 1: break; /* pixels per inch */
-          case 2: img_xres(img)*=2.54; img_yres(img)*=2.54;
-                  break; /* pixels per cm */
-          default:img_xres(img)=img_yres(img)=0; break;
-      }
+    int i, units = 0;
+    unsigned char jpg_id[] = "JFIF";
+    img_xres (img) = img_yres (img) = 0;
+    jpg_ptr (img)->file = xfopen (img_name (img), FOPEN_RBIN_MODE);
+    xfseek (jpg_ptr (img)->file, 0, SEEK_END, cur_file_name);
+    jpg_ptr (img)->length = xftell (jpg_ptr (img)->file, cur_file_name);
+    xfseek (jpg_ptr (img)->file, 0, SEEK_SET, cur_file_name);
+    if (read2bytes (jpg_ptr (img)->file) != 0xFFD8)
+        pdftex_fail ("reading JPEG image failed (no JPEG header found)");
+    /* currently only true JFIF files allow extracting img_xres and img_yres */
+    if (read2bytes (jpg_ptr (img)->file) == 0xFFE0) {   /* check for JFIF */
+        (void) read2bytes (jpg_ptr (img)->file);
+        for (i = 0; i < 5; i++) {
+            if (xgetc (jpg_ptr (img)->file) != jpg_id[i])
+                break;
+        }
+        if (i == 5) {           /* it's JFIF */
+            read2bytes (jpg_ptr (img)->file);
+            units = xgetc (jpg_ptr (img)->file);
+            img_xres (img) = read2bytes (jpg_ptr (img)->file);
+            img_yres (img) = read2bytes (jpg_ptr (img)->file);
+            switch (units) {
+            case 1:
+                break;          /* pixels per inch */
+            case 2:
+                img_xres (img) *= 2.54;
+                img_yres (img) *= 2.54;
+                break;          /* pixels per cm */
+            default:
+                img_xres (img) = img_yres (img) = 0;
+                break;
+            }
+        }
     }
-
-    xfseek(jpg_ptr(img)->file,0,SEEK_SET,cur_file_name);
-    while(1) {
-        if(feof(jpg_ptr(img)->file) || fgetc(jpg_ptr(img)->file)!=0xFF)
-            pdftex_fail("reading JPEG image failed");
-        switch(xgetc(jpg_ptr(img)->file)) {
+    xfseek (jpg_ptr (img)->file, 0, SEEK_SET, cur_file_name);
+    while (1) {
+        if (feof (jpg_ptr (img)->file))
+            pdftex_fail ("reading JPEG image failed (premature file end)");
+        if (fgetc (jpg_ptr (img)->file) != 0xFF)
+            pdftex_fail ("reading JPEG image failed (no marker found)");
+        switch (xgetc (jpg_ptr (img)->file)) {
         case M_SOF5:
         case M_SOF6:
         case M_SOF7:
@@ -143,35 +152,35 @@
         case M_SOF13:
         case M_SOF14:
         case M_SOF15:
-            pdftex_fail("unsupported type of compression");
+            pdftex_fail ("unsupported type of compression");
         case M_SOF2:
-         if (getintpar(cfgpdfminorversioncode) <= 2)
-                 pdftex_fail("cannot use progressive DCT with PDF-1.2");
+            if (fixedpdfminorversion <= 2)
+                pdftex_fail ("cannot use progressive DCT with PDF-1.2");
         case M_SOF0:
         case M_SOF1:
         case M_SOF3:
-             (void)read2bytes(jpg_ptr(img)->file);    /* read segment length  */
-             jpg_ptr(img)->bits_per_component = xgetc(jpg_ptr(img)->file);
-             img_height(img)       = read2bytes(jpg_ptr(img)->file);
-             img_width(img)        = read2bytes(jpg_ptr(img)->file);
-             jpg_ptr(img)->color_space  = xgetc(jpg_ptr(img)->file);
-             xfseek(jpg_ptr(img)->file,0,SEEK_SET,cur_file_name); 
-             switch (jpg_ptr(img)->color_space) {
-                 case JPG_GRAY:
-                     img_color(img) = IMAGE_COLOR_B;
-                     break;
-                 case JPG_RGB:
-                     img_color(img) = IMAGE_COLOR_C;
-                     break;
-                 case JPG_CMYK:
-                     img_color(img) = IMAGE_COLOR_C;
-                     break;
-                 default:
-                     pdftex_fail("Unsupported color space %i", 
-                             (int)jpg_ptr(img)->color_space);
-             }
-             return;
-        case M_SOI:             /* ignore markers without parameters */
+            (void) read2bytes (jpg_ptr (img)->file);    /* read segment length  */
+            jpg_ptr (img)->bits_per_component = xgetc (jpg_ptr (img)->file);
+            img_height (img) = read2bytes (jpg_ptr (img)->file);
+            img_width (img) = read2bytes (jpg_ptr (img)->file);
+            jpg_ptr (img)->color_space = xgetc (jpg_ptr (img)->file);
+            xfseek (jpg_ptr (img)->file, 0, SEEK_SET, cur_file_name);
+            switch (jpg_ptr (img)->color_space) {
+            case JPG_GRAY:
+                img_color (img) = IMAGE_COLOR_B;
+                break;
+            case JPG_RGB:
+                img_color (img) = IMAGE_COLOR_C;
+                break;
+            case JPG_CMYK:
+                img_color (img) = IMAGE_COLOR_C;
+                break;
+            default:
+                pdftex_fail ("Unsupported color space %i",
+                             (int) jpg_ptr (img)->color_space);
+            }
+            return;
+        case M_SOI:            /* ignore markers without parameters */
         case M_EOI:
         case M_TEM:
         case M_RST0:
@@ -183,45 +192,45 @@
         case M_RST6:
         case M_RST7:
             break;
-        default:                        /* skip variable length markers */
-            xfseek(jpg_ptr(img)->file,read2bytes(jpg_ptr(img)->file)-2,SEEK_CUR,cur_file_name);
+        default:               /* skip variable length markers */
+            xfseek (jpg_ptr (img)->file, read2bytes (jpg_ptr (img)->file) - 2,
+                    SEEK_CUR, cur_file_name);
             break;
         }
     }
 }
 
-void write_jpg(integer img)
+void write_jpg (integer img)
 {
     long unsigned l;
     FILE *f;
-    pdf_puts("/Type /XObject\n/Subtype /Image\n");
-    pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n/Length %i\n",
-               img_width(img),
-               img_height(img),
-               (int)jpg_ptr(img)->bits_per_component,
-               (int)jpg_ptr(img)->length);
-    pdf_puts("/ColorSpace ");
-    if (img_colorspace_ref(img) != 0) {
-        pdf_printf("%i 0 R\n", (int)img_colorspace_ref(img));
-    }
-    else {
-        switch (jpg_ptr(img)->color_space) {
+    pdf_puts ("/Type /XObject\n/Subtype /Image\n");
+    pdf_printf ("/Width %i\n/Height %i\n/BitsPerComponent %i\n/Length %i\n",
+                img_width (img),
+                img_height (img),
+                (int) jpg_ptr (img)->bits_per_component,
+                (int) jpg_ptr (img)->length);
+    pdf_puts ("/ColorSpace ");
+    if (img_colorspace_ref (img) != 0) {
+        pdf_printf ("%i 0 R\n", (int) img_colorspace_ref (img));
+    } else {
+        switch (jpg_ptr (img)->color_space) {
         case JPG_GRAY:
-            pdf_puts("/DeviceGray\n");
+            pdf_puts ("/DeviceGray\n");
             break;
         case JPG_RGB:
-            pdf_puts("/DeviceRGB\n");
+            pdf_puts ("/DeviceRGB\n");
             break;
         case JPG_CMYK:
-            pdf_puts("/DeviceCMYK\n/Decode [1 0 1 0 1 0 1 0]\n");
+            pdf_puts ("/DeviceCMYK\n/Decode [1 0 1 0 1 0 1 0]\n");
             break;
         default:
-            pdftex_fail("Unsupported color space %i", 
-                 (int)jpg_ptr(img)->color_space);
+            pdftex_fail ("Unsupported color space %i",
+                         (int) jpg_ptr (img)->color_space);
         }
     }
-    pdf_puts("/Filter /DCTDecode\n>>\nstream\n");
-    for (l = jpg_ptr(img)->length, f = jpg_ptr(img)->file; l > 0; l--)
-        pdfout(xgetc(f));
-    pdf_puts("endstream\nendobj\n");
+    pdf_puts ("/Filter /DCTDecode\n>>\nstream\n");
+    for (l = jpg_ptr (img)->length, f = jpg_ptr (img)->file; l > 0; l--)
+        pdfout (xgetc (f));
+    pdfendstream ();
 }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writepng.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writepng.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writepng.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,141 +17,571 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writepng.c#5 $
+$Id: writepng.c,v 1.2 2006/01/06 22:35:43 hahe Exp hahe $
 */
 
 #include "ptexlib.h"
 #include "image.h"
 
-static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writepng.c#5 $";
+/*@unused@*/
+static const char perforce_id[] =
+    "$Id: writepng.c,v 1.2 2006/01/06 22:35:43 hahe Exp hahe $";
 
-void read_png_info(integer img)
+void read_png_info (integer img)
 {
-    FILE *png_file = xfopen(img_name(img), FOPEN_RBIN_MODE);
-    if ((png_ptr(img) = png_create_read_struct(PNG_LIBPNG_VER_STRING, 
-        NULL, NULL, NULL)) == NULL)
-        pdftex_fail("libpng: png_create_read_struct() failed");
-    if ((png_info(img) = png_create_info_struct(png_ptr(img))) == NULL)
-        pdftex_fail("libpng: png_create_info_struct() failed");
-    if (setjmp(png_ptr(img)->jmpbuf))
-        pdftex_fail("libpng: internal error");
-    png_init_io(png_ptr(img), png_file);
-    png_read_info(png_ptr(img), png_info(img));
-    if (png_info(img)->color_type & PNG_COLOR_MASK_ALPHA)
-        png_set_strip_alpha(png_ptr(img));
-    if (png_info(img)->bit_depth == 16)
-        png_set_strip_16(png_ptr(img));
-    png_read_update_info(png_ptr(img), png_info(img));
-    img_width(img) =  png_info(img)->width;
-    img_height(img) =  png_info(img)->height;
-    if (png_info(img)->valid & PNG_INFO_pHYs) {
-        img_xres(img) = 
-            round(0.0254*png_get_x_pixels_per_meter(png_ptr(img), png_info(img)));
-        img_yres(img) =
-            round(0.0254*png_get_y_pixels_per_meter(png_ptr(img), png_info(img)));
+    double gamma;
+    FILE *png_file = xfopen (img_name (img), FOPEN_RBIN_MODE);
+
+    if ((png_ptr (img) = png_create_read_struct (PNG_LIBPNG_VER_STRING,
+                                                 NULL, NULL, NULL)) == NULL)
+        pdftex_fail ("libpng: png_create_read_struct() failed");
+    if ((png_info (img) = png_create_info_struct (png_ptr (img))) == NULL)
+        pdftex_fail ("libpng: png_create_info_struct() failed");
+    if (setjmp (png_ptr (img)->jmpbuf))
+        pdftex_fail ("libpng: internal error");
+    png_init_io (png_ptr (img), png_file);
+    png_read_info (png_ptr (img), png_info (img));
+    /* simple transparency support */
+    if (png_get_valid (png_ptr (img), png_info (img), PNG_INFO_tRNS)) {
+        png_set_tRNS_to_alpha (png_ptr (img));
     }
-    switch (png_info(img)->color_type) {
+    /* alpha channel support  */
+    if (fixedpdfminorversion < 4
+        && png_ptr (img)->color_type | PNG_COLOR_MASK_ALPHA)
+        png_set_strip_alpha (png_ptr (img));
+    /* 16bit depth support */
+    if (fixedpdfminorversion < 5)
+        fixedimagehicolor = 0;
+    if (png_info (img)->bit_depth == 16 && !fixedimagehicolor)
+        png_set_strip_16 (png_ptr (img));
+    /* gamma support */
+    if (fixedimageapplygamma) {
+        if (png_get_gAMA (png_ptr (img), png_info (img), &gamma))
+            png_set_gamma (png_ptr (img), (fixedgamma / 1000.0), gamma);
+        else
+            png_set_gamma (png_ptr (img), (fixedgamma / 1000.0),
+                           (1000.0 / fixedimagegamma));
+    }
+    /* reset structure */
+    png_read_update_info (png_ptr (img), png_info (img));
+    /* resolution support */
+    img_width (img) = png_info (img)->width;
+    img_height (img) = png_info (img)->height;
+    if (png_info (img)->valid & PNG_INFO_pHYs) {
+        img_xres (img) =
+            round (0.0254 *
+                   png_get_x_pixels_per_meter (png_ptr (img), png_info (img)));
+        img_yres (img) =
+            round (0.0254 *
+                   png_get_y_pixels_per_meter (png_ptr (img), png_info (img)));
+    }
+    switch (png_info (img)->color_type) {
     case PNG_COLOR_TYPE_PALETTE:
-        img_color(img) = IMAGE_COLOR_C | IMAGE_COLOR_I;
+        img_color (img) = IMAGE_COLOR_C | IMAGE_COLOR_I;
         break;
     case PNG_COLOR_TYPE_GRAY:
     case PNG_COLOR_TYPE_GRAY_ALPHA:
-        img_color(img) = IMAGE_COLOR_B;
+        img_color (img) = IMAGE_COLOR_B;
         break;
     case PNG_COLOR_TYPE_RGB:
     case PNG_COLOR_TYPE_RGB_ALPHA:
-        img_color(img) = IMAGE_COLOR_C;
+        img_color (img) = IMAGE_COLOR_C;
         break;
     default:
-        pdftex_fail("unsupported type of color_type <%i>", png_info(img)->color_type);
+        pdftex_fail ("unsupported type of color_type <%i>",
+                     png_info (img)->color_type);
     }
 }
 
-void write_png(integer img)
+
+#define write_gray_pixel_16(r)                           \
+  if (j % 4 == 0||j % 4 == 1)  pdfbuf[pdfptr++]  = *r++; \
+  else                        smask[smask_ptr++] = *r++
+
+#define write_gray_pixel_8(r)                   \
+    if (j % 2 == 0)  pdfbuf[pdfptr++]   = *r++; \
+    else  	     smask[smask_ptr++] = *r++
+
+
+#define write_rgb_pixel_16(r)                                 \
+    if (!(j % 8 == 6||j % 8 == 7)) pdfbuf[pdfptr++]  = *r++;  \
+    else                           smask[smask_ptr++] = *r++
+
+#define write_rgb_pixel_8(r)                                 \
+    if (j % 4 != 3)      pdfbuf[pdfptr++]  = *r++;           \
+    else                 smask[smask_ptr++] = *r++
+
+#define write_simple_pixel(r)    pdfbuf[pdfptr++] = *r++
+
+
+#define write_noninterlaced(outmac)                    \
+  for (i = 0; i < (int)png_info(img)->height; i++) {   \
+    png_read_row(png_ptr(img), row, NULL);             \
+    r = row;                                           \
+    k = png_info(img)->rowbytes;                       \
+    while(k > 0) {                                     \
+	l = (k > pdfbufsize)? pdfbufsize : k;          \
+		pdfroom(l);                            \
+		for (j = 0; j < l; j++) {              \
+		  outmac;	                       \
+		}                                      \
+		k -= l;                                \
+	    }                                          \
+        }
+
+#define write_interlaced(outmac)                       \
+  for (i = 0; i < (int)png_info(img)->height; i++) {   \
+            row = rows[i];                             \
+	    k = png_info(img)->rowbytes;               \
+	    while(k > 0) {                             \
+		l = (k > pdfbufsize)? pdfbufsize : k;  \
+		pdfroom(l);                            \
+		for (j = 0; j < l; j++) {              \
+		  outmac;           	               \
+		}                                      \
+		k -= l;                                \
+	    }                                          \
+            xfree(rows[i]);                            \
+        }
+
+
+void write_png_palette (integer img)
 {
     int i, j, k, l;
+    png_bytep row, r, *rows;
     integer palette_objnum = 0;
+    pdfcreateobj (0, 0);
+    palette_objnum = objptr;
+    if (img_colorspace_ref (img) != 0) {
+        pdf_printf ("%i 0 R\n", (int) img_colorspace_ref (img));
+    } else {
+        pdf_printf ("[/Indexed /DeviceRGB %i %i 0 R]\n",
+                    (int) (png_info (img)->num_palette - 1),
+                    (int) palette_objnum);
+    }
+    pdfbeginstream ();
+    if (png_info (img)->interlace_type == PNG_INTERLACE_NONE) {
+        row = xtalloc (png_info (img)->rowbytes, png_byte);
+        write_noninterlaced (write_simple_pixel (r));
+        xfree (row);
+    } else {
+        if (png_info (img)->height * png_info (img)->rowbytes >= 10240000L)
+            pdftex_warn
+                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
+        rows = xtalloc (png_info (img)->height, png_bytep);
+        for (i = 0; i < png_info (img)->height; i++)
+            rows[i] = xtalloc (png_info (img)->rowbytes, png_byte);
+        png_read_image (png_ptr (img), rows);
+        write_interlaced (write_simple_pixel (row));
+        xfree (rows);
+    }
+    pdfendstream ();
+    if (palette_objnum > 0) {
+        pdfbegindict (palette_objnum, 0);
+        pdfbeginstream ();
+        for (i = 0; i < png_info (img)->num_palette; i++) {
+            pdfroom (3);
+            pdfbuf[pdfptr++] = png_info (img)->palette[i].red;
+            pdfbuf[pdfptr++] = png_info (img)->palette[i].green;
+            pdfbuf[pdfptr++] = png_info (img)->palette[i].blue;
+        }
+        pdfendstream ();
+    }
+}
+
+void write_png_gray (integer img)
+{
+    int i, j, k, l;
     png_bytep row, r, *rows;
-    pdf_puts("/Type /XObject\n/Subtype /Image\n");
-    pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
-               (int)png_info(img)->width,
-               (int)png_info(img)->height,
-               (int)png_info(img)->bit_depth);
-    pdf_puts("/ColorSpace ");
-    if (img_colorspace_ref(img) != 0) {
-        pdf_printf("%i 0 R\n", (int)img_colorspace_ref(img));
+    if (img_colorspace_ref (img) != 0) {
+        pdf_printf ("%i 0 R\n", (int) img_colorspace_ref (img));
+    } else {
+        pdf_puts ("/DeviceGray\n");
     }
-    else {
-        switch (png_info(img)->color_type) {
+    pdfbeginstream ();
+    if (png_info (img)->interlace_type == PNG_INTERLACE_NONE) {
+        row = xtalloc (png_info (img)->rowbytes, png_byte);
+        write_noninterlaced (write_simple_pixel (r));
+        xfree (row);
+    } else {
+        if (png_info (img)->height * png_info (img)->rowbytes >= 10240000L)
+            pdftex_warn
+                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
+        rows = xtalloc (png_info (img)->height, png_bytep);
+        for (i = 0; i < png_info (img)->height; i++)
+            rows[i] = xtalloc (png_info (img)->rowbytes, png_byte);
+        png_read_image (png_ptr (img), rows);
+        write_interlaced (write_simple_pixel (row));
+        xfree (rows);
+    }
+    pdfendstream ();
+}
+
+
+
+void write_png_gray_alpha (integer img)
+{
+    int i, j, k, l;
+    png_bytep row, r, *rows;
+    integer smask_objnum = 0;
+    png_bytep smask;
+    integer smask_ptr = 0;
+    integer smask_size = 0;
+    int bitdepth;
+    if (img_colorspace_ref (img) != 0) {
+        pdf_printf ("%i 0 R\n", (int) img_colorspace_ref (img));
+    } else {
+        pdf_puts ("/DeviceGray\n");
+    }
+    pdfcreateobj (0, 0);
+    smask_objnum = objptr;
+    pdf_printf ("/SMask %i 0 R\n", (int) smask_objnum);
+    smask_size = (png_info (img)->rowbytes / 2) * png_info (img)->height;
+    smask = xtalloc (smask_size, png_byte);
+    pdfbeginstream ();
+    if (png_info (img)->interlace_type == PNG_INTERLACE_NONE) {
+        row = xtalloc (png_info (img)->rowbytes, png_byte);
+        if ((png_info (img)->bit_depth == 16) && fixedimagehicolor) {
+            write_noninterlaced (write_gray_pixel_16 (r));
+        } else {
+            write_noninterlaced (write_gray_pixel_8 (r));
+        }
+        xfree (row);
+    } else {
+        if (png_info (img)->height * png_info (img)->rowbytes >= 10240000L)
+            pdftex_warn
+                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
+        rows = xtalloc (png_info (img)->height, png_bytep);
+        for (i = 0; i < png_info (img)->height; i++)
+            rows[i] = xtalloc (png_info (img)->rowbytes, png_byte);
+        png_read_image (png_ptr (img), rows);
+        if ((png_info (img)->bit_depth == 16) && fixedimagehicolor) {
+            write_interlaced (write_gray_pixel_16 (row));
+        } else {
+            write_interlaced (write_gray_pixel_8 (row));
+        }
+        xfree (rows);
+    }
+    pdfendstream ();
+    pdfflush ();
+    /* now write the Smask object */
+    if (smask_objnum > 0) {
+        bitdepth = (int) png_info (img)->bit_depth;
+        pdfbegindict (smask_objnum, 0);
+        pdf_puts ("/Type /XObject\n/Subtype /Image\n");
+        pdf_printf ("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
+                    (int) png_info (img)->width,
+                    (int) png_info (img)->height,
+                    (bitdepth == 16 ? 8 : bitdepth));
+        pdf_puts ("/ColorSpace /DeviceGray\n");
+        pdfbeginstream ();
+        for (i = 0; i < smask_size; i++) {
+            if (i % 8 == 0)
+                pdfroom (8);
+            pdfbuf[pdfptr++] = smask[i];
+            if (bitdepth == 16)
+                i++;
+        }
+        xfree (smask);
+        pdfendstream ();
+    }
+}
+
+void write_png_rgb (integer img)
+{
+    int i, j, k, l;
+    png_bytep row, r, *rows;
+    if (img_colorspace_ref (img) != 0) {
+        pdf_printf ("%i 0 R\n", (int) img_colorspace_ref (img));
+    } else {
+        pdf_puts ("/DeviceRGB\n");
+    }
+    pdfbeginstream ();
+    if (png_info (img)->interlace_type == PNG_INTERLACE_NONE) {
+        row = xtalloc (png_info (img)->rowbytes, png_byte);
+        write_noninterlaced (write_simple_pixel (r));
+        xfree (row);
+    } else {
+        if (png_info (img)->height * png_info (img)->rowbytes >= 10240000L)
+            pdftex_warn
+                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
+        rows = xtalloc (png_info (img)->height, png_bytep);
+        for (i = 0; i < png_info (img)->height; i++)
+            rows[i] = xtalloc (png_info (img)->rowbytes, png_byte);
+        png_read_image (png_ptr (img), rows);
+        write_interlaced (write_simple_pixel (row));
+        xfree (rows);
+    }
+    pdfendstream ();
+}
+
+void write_png_rgb_alpha (integer img)
+{
+    int i, j, k, l;
+    png_bytep row, r, *rows;
+    integer smask_objnum = 0;
+    png_bytep smask;
+    integer smask_ptr = 0;
+    integer smask_size = 0;
+    int bitdepth;
+    if (img_colorspace_ref (img) != 0) {
+        pdf_printf ("%i 0 R\n", (int) img_colorspace_ref (img));
+    } else {
+        pdf_puts ("/DeviceRGB\n");
+    }
+    pdfcreateobj (0, 0);
+    smask_objnum = objptr;
+    pdf_printf ("/SMask %i 0 R\n", (int) smask_objnum);
+    smask_size = (png_info (img)->rowbytes / 2) * png_info (img)->height;
+    smask = xtalloc (smask_size, png_byte);
+    pdfbeginstream ();
+    if (png_info (img)->interlace_type == PNG_INTERLACE_NONE) {
+        row = xtalloc (png_info (img)->rowbytes, png_byte);
+        if ((png_info (img)->bit_depth == 16) && fixedimagehicolor) {
+            write_noninterlaced (write_rgb_pixel_16 (r));
+        } else {
+            write_noninterlaced (write_rgb_pixel_8 (r));
+        }
+        xfree (row);
+    } else {
+        if (png_info (img)->height * png_info (img)->rowbytes >= 10240000L)
+            pdftex_warn
+                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
+        rows = xtalloc (png_info (img)->height, png_bytep);
+        for (i = 0; i < png_info (img)->height; i++)
+            rows[i] = xtalloc (png_info (img)->rowbytes, png_byte);
+        png_read_image (png_ptr (img), rows);
+        if ((png_info (img)->bit_depth == 16) && fixedimagehicolor) {
+            write_interlaced (write_rgb_pixel_16 (row));
+        } else {
+            write_interlaced (write_rgb_pixel_8 (row));
+        }
+        xfree (rows);
+    }
+    pdfendstream ();
+    pdfflush ();
+    /* now write the Smask object */
+    if (smask_objnum > 0) {
+        bitdepth = (int) png_info (img)->bit_depth;
+        pdfbegindict (smask_objnum, 0);
+        pdf_puts ("/Type /XObject\n/Subtype /Image\n");
+        pdf_printf ("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
+                    (int) png_info (img)->width,
+                    (int) png_info (img)->height,
+                    (bitdepth == 16 ? 8 : bitdepth));
+        pdf_puts ("/ColorSpace /DeviceGray\n");
+        pdfbeginstream ();
+        for (i = 0; i < smask_size; i++) {
+            if (i % 8 == 0)
+                pdfroom (8);
+            pdfbuf[pdfptr++] = smask[i];
+            if (bitdepth == 16)
+                i++;
+        }
+        xfree (smask);
+        pdfendstream ();
+    }
+}
+
+
+/**********************************************************************/
+/*
+ *
+ * The |copy_png| function is from Hartmut Henkel. The goal is to use 
+ * pdf's native FlateDecode support if that is possible.
+ *
+ * Only a subset of the png files allows this, but when possible it
+ * greatly improves inclusion speed. 
+ *
+ */
+
+/* Code cheerfully gleaned from Thomas Merz' PDFlib, file p_png.c "SPNG - Simple PNG" */
+
+static int spng_getint (FILE * fp)
+{
+    unsigned char buf[4];
+    if (fread (buf, 1, 4, fp) != 4)
+        pdftex_fail ("writepng: reading chunk type failed");
+    return ((((((int) buf[0] << 8) + buf[1]) << 8) + buf[2]) << 8) + buf[3];
+}
+
+#define SPNG_CHUNK_IDAT 0x49444154
+#define SPNG_CHUNK_IEND 0x49454E44
+
+void copy_png (integer img)
+{
+    FILE *fp = (FILE *) png_ptr (img)->io_ptr;
+    int i, len, type, streamlength = 0;
+    boolean endflag = false;
+    int idat = 0;               /* flag to check continuous IDAT chunks sequence */
+    /* 1st pass to find overall stream /Length */
+    if (fseek (fp, 8, SEEK_SET) != 0)
+        pdftex_fail ("writepng: fseek in PNG file failed");
+    do {
+        len = spng_getint (fp);
+        type = spng_getint (fp);
+        switch (type) {
+        case SPNG_CHUNK_IEND:
+            endflag = true;
+            break;
+        case SPNG_CHUNK_IDAT:
+            streamlength += len;
+        default:
+            if (fseek (fp, len + 4, SEEK_CUR) != 0)
+                pdftex_fail ("writepng: fseek in PNG file failed");
+        }
+    } while (endflag == false);
+    pdf_printf ("/Length %d\n", streamlength);
+    pdf_printf ("/Filter /FlateDecode\n");
+    pdf_printf ("/DecodeParms << ");
+    pdf_printf ("/Colors %d ", png_info (img)->color_type == 2 ? 3 : 1);
+    pdf_printf ("/Columns %d ", (int) png_info (img)->width);
+    pdf_printf ("/BitsPerComponent %i ", (int) png_info (img)->bit_depth);
+    pdf_printf ("/Predictor %d ", 10);  /* actual predictor defined on line basis */
+    pdf_printf (">>\n>>\nstream\n");
+    /* 2nd pass to copy data */
+    endflag = false;
+    if (fseek (fp, 8, SEEK_SET) != 0)
+        pdftex_fail ("writepng: fseek in PNG file failed");
+    do {
+        len = spng_getint (fp);
+        type = spng_getint (fp);
+        switch (type) {
+        case SPNG_CHUNK_IDAT:  /* do copy */
+            if (idat == 2)
+                pdftex_fail ("writepng: IDAT chunk sequence broken");
+            idat = 1;
+            while (len > 0) {
+                i = (len > pdfbufsize) ? pdfbufsize : len;
+                pdfroom (i);
+                fread (&pdfbuf[pdfptr], 1, i, fp);
+                pdfptr += i;
+                len -= i;
+            }
+            if (fseek (fp, 4, SEEK_CUR) != 0)
+                pdftex_fail ("writepng: fseek in PNG file failed");
+            break;
+        case SPNG_CHUNK_IEND:  /* done */
+            pdfendstream ();
+            endflag = true;
+            break;
+        default:
+            if (idat == 1)
+                idat = 2;
+            if (fseek (fp, len + 4, SEEK_CUR) != 0)
+                pdftex_fail ("writepng: fseek in PNG file failed");
+        }
+    } while (endflag == false);
+}
+
+void write_png (integer img)
+{
+
+    double gamma, checked_gamma;
+    int i;
+    integer palette_objnum = 0;
+    if (fixedpdfminorversion < 5)
+        fixedimagehicolor = 0;
+
+    pdf_puts ("/Type /XObject\n/Subtype /Image\n");
+    pdf_printf ("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
+                (int) png_info (img)->width,
+                (int) png_info (img)->height, (int) png_info (img)->bit_depth);
+    pdf_puts ("/ColorSpace ");
+    checked_gamma = 1.0;
+    if (fixedimageapplygamma) {
+        if (png_get_gAMA (png_ptr (img), png_info (img), &gamma)) {
+            checked_gamma = (fixedgamma / 1000.0) * gamma;
+        } else {
+            checked_gamma = (fixedgamma / 1000.0) * (1000.0 / fixedimagegamma);
+        }
+    }
+    /* the switching between |png_info| and |png_ptr| queries has been trial and error. 
+     */
+    if (fixedpdfminorversion > 1 && png_info (img)->interlace_type == PNG_INTERLACE_NONE && (png_ptr (img)->transformations == 0 || png_ptr (img)->transformations == 0x2000)   /* gamma */
+        &&!(png_ptr (img)->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
+            png_ptr (img)->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+        && (fixedimagehicolor || (png_ptr (img)->bit_depth <= 8))
+        && (checked_gamma <= 1.01 && checked_gamma > 0.99)
+        ) {
+        if (img_colorspace_ref (img) != 0) {
+            pdf_printf ("%i 0 R\n", (int) img_colorspace_ref (img));
+        } else {
+            switch (png_info (img)->color_type) {
             case PNG_COLOR_TYPE_PALETTE:
-                pdfcreateobj(0, 0);
+                pdfcreateobj (0, 0);
                 palette_objnum = objptr;
-                pdf_printf("[/Indexed /DeviceRGB %i %i 0 R]\n",
-                        (int)(png_info(img)->num_palette - 1),
-                        (int)palette_objnum);
+                pdf_printf ("[/Indexed /DeviceRGB %i %i 0 R]\n",
+                            (int) (png_info (img)->num_palette - 1),
+                            (int) palette_objnum);
                 break;
             case PNG_COLOR_TYPE_GRAY:
-            case PNG_COLOR_TYPE_GRAY_ALPHA:
-                pdf_puts("/DeviceGray\n");
+                pdf_puts ("/DeviceGray\n");
                 break;
-            case PNG_COLOR_TYPE_RGB:
-            case PNG_COLOR_TYPE_RGB_ALPHA:
-                pdf_puts("/DeviceRGB\n");
-                break;
-            default:
-                pdftex_fail("unsupported type of color_type <%i>", png_info(img)->color_type);
+            default:           /* RGB */
+                pdf_puts ("/DeviceRGB\n");
+            };
         }
-    }
-    pdfbeginstream();
-    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
-        row = xtalloc(png_info(img)->rowbytes, png_byte);
-        for (i = 0; i < (int)png_info(img)->height; i++) {
-            png_read_row(png_ptr(img), row, NULL);
-	    r = row;
-	    k = png_info(img)->rowbytes;
-	    while(k > 0) {
-		l = (k > pdfbufsize)? pdfbufsize : k;
-		pdfroom(l);
-		for (j = 0; j < l; j++)
-		    pdfbuf[pdfptr++] = *r++;
-		k -= l;
-	    }
+        tex_printf (" (PNG copy)");
+        copy_png (img);
+        if (palette_objnum > 0) {
+            pdfbegindict (palette_objnum, 0);
+            pdfbeginstream ();
+            for (i = 0; i < png_info (img)->num_palette; i++) {
+                pdfroom (3);
+                pdfbuf[pdfptr++] = png_info (img)->palette[i].red;
+                pdfbuf[pdfptr++] = png_info (img)->palette[i].green;
+                pdfbuf[pdfptr++] = png_info (img)->palette[i].blue;
+            }
+            pdfendstream ();
         }
-        xfree(row);
-    }
-    else {
-        if (png_info(img)->height*png_info(img)->rowbytes >= 10240000L)
-            pdftex_warn("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
-        rows = xtalloc(png_info(img)->height, png_bytep);
-        for (i = 0; i < png_info(img)->height; i++)
-            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
-        png_read_image(png_ptr(img), rows);
-        for (i = 0; i < (int)png_info(img)->height; i++) {
-            row = rows[i];
-	    k = png_info(img)->rowbytes;
-	    while(k > 0) {
-		l = (k > pdfbufsize)? pdfbufsize : k;
-		pdfroom(l);
-		for (j = 0; j < l; j++)
-		    pdfbuf[pdfptr++] = *row++;
-		k -= l;
-	    }
-            xfree(rows[i]);
+    } else {
+        if (0) {
+            tex_printf (" PNG copy skipped because: ");
+            if (fixedimageapplygamma &&
+                (checked_gamma > 1.01 || checked_gamma < 0.99))
+                tex_printf ("gamma delta=%lf ", checked_gamma);
+            if (png_ptr (img)->transformations != PNG_TRANSFORM_IDENTITY)
+                tex_printf ("transform=%d", png_ptr (img)->transformations);
+            if ((png_info (img)->color_type != PNG_COLOR_TYPE_GRAY) &&
+                (png_info (img)->color_type != PNG_COLOR_TYPE_RGB) &&
+                (png_info (img)->color_type != PNG_COLOR_TYPE_PALETTE))
+                tex_printf ("colortype ");
+            if (fixedpdfminorversion <= 1)
+                tex_printf ("version=%d ", fixedpdfminorversion);
+            if (png_info (img)->interlace_type != PNG_INTERLACE_NONE)
+                tex_printf ("interlaced ");
+            if (png_info (img)->bit_depth > 8)
+                tex_printf ("bitdepth=%d ", png_info (img)->bit_depth);
+            if (png_get_valid (png_ptr (img), png_info (img), PNG_INFO_tRNS))
+                tex_printf ("simple transparancy ");
         }
-        xfree(rows);
-    }
-    pdfendstream();
-    if (palette_objnum > 0) {
-        pdfbegindict(palette_objnum);
-        pdfbeginstream();
-        for (i = 0; i < png_info(img)->num_palette; i++) {
-            pdfroom(3);
-            pdfbuf[pdfptr++] = png_info(img)->palette[i].red;
-            pdfbuf[pdfptr++] = png_info(img)->palette[i].green;
-            pdfbuf[pdfptr++] = png_info(img)->palette[i].blue;
+        switch (png_info (img)->color_type) {
+        case PNG_COLOR_TYPE_PALETTE:
+            write_png_palette (img);
+            break;
+        case PNG_COLOR_TYPE_GRAY:
+            write_png_gray (img);
+            break;
+        case PNG_COLOR_TYPE_GRAY_ALPHA:
+            if (fixedpdfminorversion >= 4)
+                write_png_gray_alpha (img);
+            else
+                write_png_gray (img);
+            break;
+        case PNG_COLOR_TYPE_RGB:
+            write_png_rgb (img);
+            break;
+        case PNG_COLOR_TYPE_RGB_ALPHA:
+            if (fixedpdfminorversion >= 4)
+                write_png_rgb_alpha (img);
+            else
+                write_png_rgb (img);
+            break;
+        default:
+            pdftex_fail ("unsupported type of color_type <%i>",
+                         png_info (img)->color_type);
         }
-        pdfendstream();
     }
-    pdfflush();
+    pdfflush ();
 }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writet1.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writet1.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writet1.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 1996-2004 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2005 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -17,109 +17,113 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writet1.c#23 $
+$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writet1.c#25 $
+
 */
 
-static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writet1.c#23 $";
+static const char perforce_id[] =
+    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writet1.c#25 $";
 
-#ifdef pdfTeX /* writet1 used with pdfTeX */
-#include "ptexlib.h"           
-#define t1_log(s)           tex_printf(s)
-#define t1_open()           \
+#ifdef pdfTeX                   /* writet1 used with pdfeTeX */
+#  include "ptexlib.h"
+#  define t1_log(s)           tex_printf(s)
+#  define t1_open()           \
     open_input(&t1_file, kpse_type1_format, FOPEN_RBIN_MODE)
-#define enc_open()      \
+#  define enc_open()          \
     open_input(&enc_file, kpse_enc_format, FOPEN_RBIN_MODE)
-#define external_enc()      (fm_cur->encoding)->glyph_names
-#define full_file_name()    (char*)nameoffile + 1
-#define get_length1()       t1_length1 = t1_offset() - t1_save_offset
-#define get_length2()       t1_length2 = t1_offset() - t1_save_offset
-#define get_length3()       t1_length3 = t1_offset() - t1_save_offset
-#define is_used_char(c)     pdfcharmarked(tex_font, c)
-#define t1_putchar          fb_putchar
-#define t1_offset           fb_offset  
-#define out_eexec_char      t1_putchar
-#define save_offset()       t1_save_offset = t1_offset()
-#define end_last_eexec_line()   \
+#  define external_enc()      (fm_cur->encoding)->glyph_names
+#  define full_file_name()    (char*)nameoffile + 1
+#  define get_length1()       t1_length1 = t1_offset() - t1_save_offset
+#  define get_length2()       t1_length2 = t1_offset() - t1_save_offset
+#  define get_length3()       t1_length3 = fixedcontent? t1_offset() - t1_save_offset : 0
+#  define is_used_char(c)     pdfcharmarked(tex_font, c)
+#  define t1_putchar          fb_putchar
+#  define t1_offset           fb_offset
+#  define out_eexec_char      t1_putchar
+#  define save_offset()       t1_save_offset = t1_offset()
+#  define end_last_eexec_line() \
     t1_eexec_encrypt = false
-#define update_builtin_enc(font, glyph_names)    update_enc(font, glyph_names) 
-#define t1_char(c)          c
-#define embed_all_glyphs(tex_font)  fm_cur->all_glyphs
-#define extra_charset()     fm_cur->charset
-#define update_subset_tag() \
+#  define t1_char(c)          c
+#  define embed_all_glyphs(tex_font)  fm_cur->all_glyphs
+#  define extra_charset()     fm_cur->charset
+#  define update_subset_tag() \
     strncpy(fb_array + t1_fontname_offset, fm_cur->subset_tag, 6)
+#  define fixedcontent        false
 
 integer t1_length1, t1_length2, t1_length3;
 static integer t1_save_offset;
 static integer t1_fontname_offset;
 extern char *fb_array;
 
-#else /* writet1 used with dvips */
-#include "dvips.h"
-#include "ptexmac.h"
-#undef  fm_extend
-#define fm_extend(f)        0
-#undef  fm_slant
-#define fm_slant(f)         0
-#undef  is_reencoded
-#define is_reencoded(f)     (cur_enc_name != NULL)
-#undef  is_subsetted
-#define is_subsetted(f)     true
-#undef  is_included
-#define is_included(f)      true
-#undef  set_cur_file_name
-#define set_cur_file_name(s)    cur_file_name = s
-#define t1_open()           \
+#else                           /* writet1 used with dvips */
+#  include "sysexits.h"
+#  include "dvips.h"
+#  include "ptexmac.h"
+#  undef  fm_extend
+#  define fm_extend(f)        0
+#  undef  fm_slant
+#  define fm_slant(f)         0
+#  undef  is_reencoded
+#  define is_reencoded(f)     (cur_enc_name != NULL)
+#  undef  is_subsetted
+#  define is_subsetted(f)     true
+#  undef  is_included
+#  define is_included(f)      true
+#  undef  set_cur_file_name
+#  define set_cur_file_name(s)    cur_file_name = s
+#  define t1_open()           \
     ((t1_file = search(headerpath, cur_file_name, FOPEN_RBIN_MODE)) != NULL)
-#define enc_open()           \
+#  define enc_open()          \
     ((enc_file = search(encpath, cur_file_name, FOPEN_RBIN_MODE)) != NULL)
-#define external_enc()      ext_glyph_names
-#define full_file_name()    cur_file_name
-#define get_length1()
-#define get_length2()
-#define get_length3()
-#define is_used_char(c)     (grid[c] == 1)
-#define out_eexec_char      t1_outhex
-#define save_offset()
-#define end_last_eexec_line()       \
+#  define external_enc()      ext_glyph_names
+#  define full_file_name()    cur_file_name
+#  define get_length1()
+#  define get_length2()
+#  define get_length3()
+#  define is_used_char(c)     (grid[c] == 1)
+#  define out_eexec_char      t1_outhex
+#  define save_offset()
+#  define end_last_eexec_line()       \
     hexline_length = HEXLINE_WIDTH; \
     end_hexline();                  \
     t1_eexec_encrypt = false
-#define t1_log(s)
-#define t1_scan_only()
-#define t1_include()
-#define t1_putchar(c)       fputc(c, bitfile)
-#define t1_scan_keys()
-#define update_builtin_enc(font, glyph_names) 
-#define embed_all_glyphs(tex_font)  false
-#undef pdfmovechars
-#ifdef SHIFTLOWCHARS
+#  define t1_log(s)
+#  define t1_scan_only()
+#  define t1_include()
+#  define t1_putchar(c)       fputc(c, bitfile)
+#  define t1_scan_keys()
+#  define embed_all_glyphs(tex_font)  false
+#  undef pdfmovechars
+#  ifdef SHIFTLOWCHARS
+extern char errbuf[];
 extern Boolean shiftlowchars;
-#define pdfmovechars shiftlowchars
-#define t1_char(c)          T1Char(c)
-#else /* SHIFTLOWCHARS */
-#define t1_char(c)          c
-#define pdfmovechars 0
-#endif /* SHIFTLOWCHARS */
-#define extra_charset()     dvips_extra_charset
-#define make_subset_tag(a, b)
-#define update_subset_tag()
+#    define pdfmovechars shiftlowchars
+#    define t1_char(c)          T1Char(c)
+#  else                         /* SHIFTLOWCHARS */
+#    define t1_char(c)          c
+#    define pdfmovechars 0
+#  endif                        /* SHIFTLOWCHARS */
+#  define extra_charset()     dvips_extra_charset
+#  define make_subset_tag(a, b)
+#  define update_subset_tag()
+#  define fixedcontent        true
 
-static char *dvips_extra_charset ;
-extern FILE *bitfile ;
-extern FILE *search();
+static char *dvips_extra_charset;
+extern FILE *bitfile;
+extern FILE *search ();
 static char *cur_file_name;
 static char *cur_enc_name;
 static unsigned char *grid;
-static char *ext_glyph_names[MAX_CHAR_CODE + 1];                                        
+static char *ext_glyph_names[256];
 static char print_buf[PRINTF_BUF_SIZE];
-static int  hexline_length;
-static char notdef[] = ".notdef";
+static int hexline_length;
+static const char notdef[] = ".notdef";
 static size_t last_ptr_index;
-#endif /* pdfTeX */
+#endif                          /* pdfTeX */
 
 #include <kpathsea/c-vararg.h>
 #include <kpathsea/c-proto.h>
+#include <string.h>
 
 #define t1_getchar()    getc(t1_file)
 #define t1_ungetchar(c) ungetc(c, t1_file)
@@ -130,46 +134,53 @@
 #define enc_eof()       feof(enc_file)
 #define enc_close()     xfclose(enc_file, cur_file_name)
 
-#define valid_code(c)   (c >= 0 && c <= MAX_CHAR_CODE)
+#define valid_code(c)   (c >= 0 && c < 256)
 
-static const char *standard_glyph_names[MAX_CHAR_CODE + 1] = {
-notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
-notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
-notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
-notdef, notdef, notdef, notdef, notdef, "space", "exclam", "quotedbl",
-"numbersign", "dollar", "percent", "ampersand", "quoteright", "parenleft",
-"parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
-"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
-"nine", "colon", "semicolon", "less", "equal", "greater", "question", "at",
-"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
-"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft",
-"backslash", "bracketright", "asciicircum", "underscore", "quoteleft", "a",
-"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
-"q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar",
-"braceright", "asciitilde", notdef, notdef, notdef, notdef, notdef, notdef,
-notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
-notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
-notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
-notdef, "exclamdown", "cent", "sterling", "fraction", "yen", "florin",
-"section", "currency", "quotesingle", "quotedblleft", "guillemotleft",
-"guilsinglleft", "guilsinglright", "fi", "fl", notdef, "endash", "dagger",
-"daggerdbl", "periodcentered", notdef, "paragraph", "bullet",
-"quotesinglbase", "quotedblbase", "quotedblright", "guillemotright",
-"ellipsis", "perthousand", notdef, "questiondown", notdef, "grave", "acute",
-"circumflex", "tilde", "macron", "breve", "dotaccent", "dieresis", notdef,
-"ring", "cedilla", notdef, "hungarumlaut", "ogonek", "caron", "emdash",
-notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
-notdef, notdef, notdef, notdef, notdef, notdef, notdef, "AE", notdef,
-"ordfeminine", notdef, notdef, notdef, notdef, "Lslash", "Oslash", "OE",
-"ordmasculine", notdef, notdef, notdef, notdef, notdef, "ae", notdef, notdef,
-notdef, "dotlessi", notdef, notdef, "lslash", "oslash", "oe", "germandbls",
-notdef, notdef, notdef, notdef
+static const char *standard_glyph_names[256] =
+    { notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
+    notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
+    notdef, notdef, notdef, notdef, notdef, notdef,
+    notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
+    "space", "exclam", "quotedbl", "numbersign",
+    "dollar", "percent", "ampersand", "quoteright", "parenleft",
+    "parenright", "asterisk", "plus", "comma", "hyphen", "period",
+    "slash", "zero", "one", "two", "three", "four", "five", "six", "seven",
+    "eight", "nine", "colon", "semicolon", "less",
+    "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F",
+    "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
+    "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft",
+    "backslash", "bracketright", "asciicircum", "underscore",
+    "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
+    "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
+    "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde",
+    notdef, notdef, notdef, notdef, notdef, notdef, notdef,
+    notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
+    notdef, notdef, notdef, notdef, notdef, notdef,
+    notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
+    notdef, notdef, notdef, "exclamdown", "cent",
+    "sterling", "fraction", "yen", "florin", "section", "currency",
+    "quotesingle", "quotedblleft", "guillemotleft",
+    "guilsinglleft", "guilsinglright", "fi", "fl", notdef, "endash",
+    "dagger", "daggerdbl", "periodcentered", notdef,
+    "paragraph", "bullet", "quotesinglbase", "quotedblbase",
+    "quotedblright", "guillemotright", "ellipsis", "perthousand",
+    notdef, "questiondown", notdef, "grave", "acute", "circumflex",
+    "tilde", "macron", "breve", "dotaccent", "dieresis", notdef,
+    "ring", "cedilla", notdef, "hungarumlaut", "ogonek", "caron", "emdash",
+    notdef, notdef, notdef, notdef, notdef, notdef,
+    notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef, notdef,
+    notdef, "AE", notdef, "ordfeminine", notdef, notdef,
+    notdef, notdef, "Lslash", "Oslash", "OE", "ordmasculine", notdef,
+    notdef, notdef, notdef, notdef, "ae", notdef, notdef,
+    notdef, "dotlessi", notdef, notdef, "lslash", "oslash", "oe",
+    "germandbls", notdef, notdef, notdef, notdef
 };
 
 static char charstringname[] = "/CharStrings";
 
 char **t1_glyph_names;
-char *t1_builtin_glyph_names[MAX_CHAR_CODE + 1];                                        
+char *t1_builtin_glyph_names[256];
+char charsetstr[0x4000];
 static boolean read_encoding_only;
 static int t1_encoding;
 
@@ -213,17 +224,17 @@
 typedef unsigned char byte;
 
 typedef struct {
-    byte nargs;     /* number of arguments */
-    boolean bottom; /* take arguments from bottom of stack? */
-    boolean clear;  /* clear stack? */
+    byte nargs;                 /* number of arguments */
+    boolean bottom;             /* take arguments from bottom of stack? */
+    boolean clear;              /* clear stack? */
     boolean valid;
-} cc_entry; /* CharString Command */
+} cc_entry;                     /* CharString Command */
 
 typedef struct {
-    char *name;             /* glyph name (or notdef for Subrs entry) */
+    char *name;                 /* glyph name (or notdef for Subrs entry) */
     byte *data;
-    unsigned short len;     /* length of the whole string */
-    unsigned short cslen;   /* length of the encoded part of the string */
+    unsigned short len;         /* length of the whole string */
+    unsigned short cslen;       /* length of the encoded part of the string */
     boolean used;
     boolean valid;
 } cs_entry;
@@ -236,11 +247,11 @@
 
 /* define t1_line_ptr, t1_line_array & t1_line_limit */
 typedef char t1_line_entry;
-define_array(t1_line);   
+define_array (t1_line);
 
 /* define t1_buf_ptr, t1_buf_array & t1_buf_limit */
 typedef char t1_buf_entry;
-define_array(t1_buf);   
+define_array (t1_buf);
 
 static int cs_start;
 
@@ -255,18 +266,18 @@
 /* This list contains the begin/end tokens commonly used in the */
 /* /Subrs array of a Type 1 font.                                */
 static const char *cs_token_pairs_list[][2] = {
-  {" RD", "NP"},
-  {" -|", "|"},
-  {" RD", "noaccess put"},
-  {" -|", "noaccess put"},
-  {NULL, NULL}
+    {" RD", "NP"},
+    {" -|", "|"},
+    {" RD", "noaccess put"},
+    {" -|", "noaccess put"},
+    {NULL, NULL}
 };
 static const char **cs_token_pair;
 
 static boolean t1_pfa, t1_cs, t1_scan, t1_eexec_encrypt, t1_synthetic;
-static int  t1_in_eexec; /* 0 before eexec-encrypted, 1 during, 2 after */
+static int t1_in_eexec;         /* 0 before eexec-encrypted, 1 during, 2 after */
 static long t1_block_length;
-static int  last_hexbyte;
+static int last_hexbyte;
 static FILE *t1_file;
 static FILE *enc_file;
 
@@ -281,157 +292,160 @@
 #define t1_cleartomark()    t1_prefix("cleartomark")
 
 #ifndef pdfTeX
-static void pdftex_fail(char *fmt,...)
+static void pdftex_fail (char *fmt, ...)
 {
     va_list args;
-    va_start(args, fmt);
-    fputs("\nError: module writet1", stderr);
+    va_start (args, fmt);
+    fputs ("\nError: module writet1", stderr);
     if (cur_file_name)
-        fprintf(stderr, " (file %s)", cur_file_name);
-    fputs(": ", stderr);
-    vsprintf(print_buf, fmt, args);
-    fputs(print_buf, stderr);
-    fputs("\n ==> Fatal error occurred, the output PS file is not finished!\n", stderr);
-    va_end(args);
-    exit(-1);
+        fprintf (stderr, " (file %s)", cur_file_name);
+    fputs (": ", stderr);
+    vsprintf (print_buf, fmt, args);
+    fputs (print_buf, stderr);
+    fputs
+        ("\n ==> Fatal error occurred, the output PS file is not finished!\n",
+         stderr);
+    va_end (args);
+    exit (EX_SOFTWARE);
 }
 
-static void pdftex_warn(char *fmt,...)
+static void pdftex_warn (char *fmt, ...)
 {
     va_list args;
-    va_start(args, fmt);
-    fputs("\nWarning: module writet1 of dvips", stderr);
+    va_start (args, fmt);
+    fputs ("\nWarning: module writet1 of dvips", stderr);
     if (cur_file_name)
-        fprintf(stderr, " (file %s)", cur_file_name);
-    fputs(": ", stderr);
-    vsprintf(print_buf, fmt, args);
-    fputs(print_buf, stderr);
-    fputs("\n", stderr);
-    va_end(args);
+        fprintf (stderr, " (file %s)", cur_file_name);
+    fputs (": ", stderr);
+    vsprintf (print_buf, fmt, args);
+    fputs (print_buf, stderr);
+    fputs ("\n", stderr);
+    va_end (args);
 }
 
-#define HEXLINE_WIDTH 64
+#  define HEXLINE_WIDTH 64
 
-static void end_hexline()
+static void end_hexline ()
 {
     if (hexline_length == HEXLINE_WIDTH) {
-        fputs("\n", bitfile);
+        fputs ("\n", bitfile);
         hexline_length = 0;
     }
 }
 
-static void t1_outhex(byte b)
+static void t1_outhex (byte b)
 {
     static char *hexdigits = "0123456789ABCDEF";
-    t1_putchar(hexdigits[b/16]);
-    t1_putchar(hexdigits[b%16]);
+    t1_putchar (hexdigits[b / 16]);
+    t1_putchar (hexdigits[b % 16]);
     hexline_length += 2;
-    end_hexline();
+    end_hexline ();
 }
-#endif /* pdfTeX */
+#endif                          /* pdfTeX */
 
 
-static void enc_getline(void)
+static void enc_getline (void)
 {
     char *p;
     int c;
-restart:
-    if (enc_eof())
-        pdftex_fail("unexpected end of file");
+  restart:
+    if (enc_eof ())
+        pdftex_fail ("unexpected end of file");
     p = enc_line;
     do {
-        c = enc_getchar();
-        append_char_to_buf(c, p, enc_line, ENC_BUF_SIZE);
-    } while (c != 10);
-    append_eol(p, enc_line, ENC_BUF_SIZE);
+        c = enc_getchar ();
+        append_char_to_buf (c, p, enc_line, ENC_BUF_SIZE);
+    }
+    while (c != 10);
+    append_eol (p, enc_line, ENC_BUF_SIZE);
     if (p - enc_line < 2 || *enc_line == '%')
         goto restart;
 }
 
-void load_enc(char *enc_name, char **glyph_names)
+void load_enc (char *enc_name, char **glyph_names)
 {
     char buf[ENC_BUF_SIZE], *p, *r;
     int names_count;
-    set_cur_file_name(enc_name);
-    if (!enc_open()) {
-        pdftex_warn("cannot open encoding file for reading");
+    set_cur_file_name (enc_name);
+    if (!enc_open ()) {
+        pdftex_warn ("cannot open encoding file for reading");
         cur_file_name = NULL;
         return;
     }
-    t1_log("{");
-    t1_log(cur_file_name = full_file_name());
-    enc_getline();
-    if (*enc_line != '/' || (r = strchr(enc_line, '[')) == NULL) {
-        remove_eol(r, enc_line);
-        pdftex_fail("invalid encoding vector (a name or `[' missing): `%s'", enc_line);
+    t1_log ("{");
+    t1_log (cur_file_name = full_file_name ());
+    enc_getline ();
+    if (*enc_line != '/' || (r = strchr (enc_line, '[')) == NULL) {
+        remove_eol (r, enc_line);
+        pdftex_fail
+            ("invalid encoding vector (a name or `[' missing): `%s'", enc_line);
     }
     names_count = 0;
-    r++; /* skip '[' */
-    skip(r, ' ');
+    r++;                        /* skip '[' */
+    skip (r, ' ');
     for (;;) {
         while (*r == '/') {
-            for (p = buf, r++; *r != ' ' && *r != 10 && *r != ']' && *r != '/'; *p++ = *r++);
+            for (p = buf, r++;
+                 *r != ' ' && *r != 10 && *r != ']' && *r != '/'; *p++ = *r++);
             *p = 0;
-            skip(r, ' ');
-            if (names_count > MAX_CHAR_CODE)
-                pdftex_fail("encoding vector contains more than %i names",
-                            (int)(MAX_CHAR_CODE + 1));
-            if (strcmp(buf, notdef) != 0)
-                glyph_names[names_count] = xstrdup(buf);
+            skip (r, ' ');
+            if (names_count > 256)
+                pdftex_fail ("encoding vector contains more than 256 names");
+            if (strcmp (buf, notdef) != 0)
+                glyph_names[names_count] = xstrdup (buf);
             names_count++;
         }
         if (*r != 10 && *r != '%') {
-            if (strncmp(r, "] def", strlen("] def")) == 0) 
+            if (strncmp (r, "] def", strlen ("] def")) == 0)
                 goto done;
             else {
-                remove_eol(r, enc_line);
-                pdftex_fail("invalid encoding vector: a name or `] def' expected: `%s'", enc_line);
+                remove_eol (r, enc_line);
+                pdftex_fail
+                    ("invalid encoding vector: a name or `] def' expected: `%s'",
+                     enc_line);
             }
         }
-        enc_getline();
+        enc_getline ();
         r = enc_line;
     }
-done:
-    enc_close();
-    t1_log("}");
+  done:
+    enc_close ();
+    t1_log ("}");
     cur_file_name = NULL;
 }
 
-static void t1_check_pfa(void)
+static void t1_check_pfa (void)
 {
-    int c = t1_getchar();
-    if (c != 128)
-        t1_pfa = true;
-    else 
-        t1_pfa = false;
-    t1_ungetchar(c);
+    const int c = t1_getchar ();
+    t1_pfa = (c != 128) ? true : false;
+    t1_ungetchar (c);
 }
 
-static int t1_getbyte(void)
+static int t1_getbyte (void)
 {
-    int c = t1_getchar();
+    int c = t1_getchar ();
     if (t1_pfa)
         return c;
     if (t1_block_length == 0) {
         if (c != 128)
-            pdftex_fail("invalid marker");
-        c = t1_getchar();
+            pdftex_fail ("invalid marker");
+        c = t1_getchar ();
         if (c == 3) {
-            while (!t1_eof())
-                t1_getchar();
+            while (!t1_eof ())
+                t1_getchar ();
             return EOF;
         }
-        t1_block_length = t1_getchar() & 0xff;
-        t1_block_length |= (t1_getchar() & 0xff) << 8;
-        t1_block_length |= (t1_getchar() & 0xff) << 16;
-        t1_block_length |= (t1_getchar() & 0xff) << 24;
-        c = t1_getchar();
+        t1_block_length = t1_getchar () & 0xff;
+        t1_block_length |= (t1_getchar () & 0xff) << 8;
+        t1_block_length |= (t1_getchar () & 0xff) << 16;
+        t1_block_length |= (t1_getchar () & 0xff) << 24;
+        c = t1_getchar ();
     }
     t1_block_length--;
     return c;
 }
 
-static int hexval(int c)
+static int hexval (int c)
 {
     if (c >= 'A' && c <= 'F')
         return c - 'A' + 10;
@@ -443,43 +457,43 @@
         return -1;
 }
 
-static byte edecrypt(byte cipher)
+static byte edecrypt (byte cipher)
 {
     byte plain;
     if (t1_pfa) {
         while (cipher == 10 || cipher == 13)
-            cipher = t1_getbyte();
-        last_hexbyte = cipher = (hexval(cipher) << 4) + hexval(t1_getbyte());
+            cipher = t1_getbyte ();
+        last_hexbyte = cipher = (hexval (cipher) << 4) + hexval (t1_getbyte ());
     }
-    plain = (cipher^(t1_dr >> 8));
-    t1_dr = (cipher + t1_dr)*t1_c1 + t1_c2;
+    plain = (cipher ^ (t1_dr >> 8));
+    t1_dr = (cipher + t1_dr) * t1_c1 + t1_c2;
     return plain;
 }
 
-static byte cdecrypt(byte cipher, unsigned short *cr)
+static byte cdecrypt (byte cipher, unsigned short *cr)
 {
-    byte plain = (cipher^(*cr >> 8));
-    *cr = (cipher + *cr)*t1_c1 + t1_c2;
+    const byte plain = (cipher ^ (*cr >> 8));
+    *cr = (cipher + *cr) * t1_c1 + t1_c2;
     return plain;
 }
 
-static byte eencrypt(byte plain)
+static byte eencrypt (byte plain)
 {
-    byte cipher = (plain^(t1_er >> 8));
-    t1_er = (cipher + t1_er)*t1_c1 + t1_c2;
+    const byte cipher = (plain ^ (t1_er >> 8));
+    t1_er = (cipher + t1_er) * t1_c1 + t1_c2;
     return cipher;
 }
 
-static byte cencrypt(byte plain, unsigned short *cr)
+static byte cencrypt (byte plain, unsigned short *cr)
 {
-    byte cipher = (plain^(*cr >> 8));
-    *cr = (cipher + *cr)*t1_c1 + t1_c2;
+    const byte cipher = (plain ^ (*cr >> 8));
+    *cr = (cipher + *cr) * t1_c1 + t1_c2;
     return cipher;
 }
 
-static char *eol(char *s)
+static char *eol (char *s)
 {
-    char *p = strend(s);
+    char *p = strend (s);
     if (p - s > 1 && p[-1] != 10) {
         *p++ = 10;
         *p = 0;
@@ -487,27 +501,26 @@
     return p;
 }
 
-static float t1_scan_num(char *p, char **r)
+static float t1_scan_num (char *p, char **r)
 {
     float f;
-    skip(p, ' ');
-    if (sscanf(p, "%g", &f) != 1) {
-        remove_eol(p, t1_line_array);
-        pdftex_fail("a number expected: `%s'", t1_line_array);
+    skip (p, ' ');
+    if (sscanf (p, "%g", &f) != 1) {
+        remove_eol (p, t1_line_array);
+        pdftex_fail ("a number expected: `%s'", t1_line_array);
     }
     if (r != NULL) {
-        for (; isdigit(*p) || *p == '.' || 
-               *p == 'e' || *p == 'E' || *p == '+' || *p == '-'; p++);
+        for (; isdigit (*p) || *p == '.' ||
+             *p == 'e' || *p == 'E' || *p == '+' || *p == '-'; p++);
         *r = p;
     }
     return f;
 }
 
-static boolean str_suffix(const char *begin_buf, const char *end_buf, 
-                          const char *s) 
+static boolean str_suffix (const char *begin_buf, const char *end_buf,
+                           const char *s)
 {
-    const char *s1 = end_buf - 1, 
-               *s2 = strend(s) - 1;
+    const char *s1 = end_buf - 1, *s2 = strend (s) - 1;
     if (*s1 == 10)
         s1--;
     while (s1 >= begin_buf && s2 >= s) {
@@ -517,27 +530,27 @@
     return s2 < s;
 }
 
-static void t1_getline(void) 
+static void t1_getline (void)
 {
     int c, l, eexec_scan;
     char *p;
     static const char eexec_str[] = "currentfile eexec";
-    static int eexec_len = 17; /* strlen(eexec_str) */
-restart:
-    if (t1_eof())
-        pdftex_fail("unexpected end of file");
+    static int eexec_len = 17;  /* strlen(eexec_str) */
+  restart:
+    if (t1_eof ())
+        pdftex_fail ("unexpected end of file");
     t1_line_ptr = t1_line_array;
-    alloc_array(t1_line, 1, T1_BUF_SIZE);
+    alloc_array (t1_line, 1, T1_BUF_SIZE);
     t1_cslen = 0;
     eexec_scan = 0;
-    c = t1_getbyte();
+    c = t1_getbyte ();
     if (c == EOF)
         goto exit;
-    while (!t1_eof()) {
-        if (t1_in_eexec == 1) 
-            c = edecrypt(c);
-        alloc_array(t1_line, 1, T1_BUF_SIZE);
-        append_char_to_buf(c, t1_line_ptr, t1_line_array, t1_line_limit);
+    while (!t1_eof ()) {
+        if (t1_in_eexec == 1)
+            c = edecrypt (c);
+        alloc_array (t1_line, 1, T1_BUF_SIZE);
+        append_char_to_buf (c, t1_line_ptr, t1_line_array, t1_line_limit);
         if (t1_in_eexec == 0 && eexec_scan >= 0 && eexec_scan < eexec_len) {
             if (t1_line_array[eexec_scan] == eexec_str[eexec_scan])
                 eexec_scan++;
@@ -546,66 +559,69 @@
         }
         if (c == 10 || (t1_pfa && eexec_scan == eexec_len && c == 32))
             break;
-        if (t1_cs && t1_cslen == 0 && (t1_line_ptr - t1_line_array > 4) && 
-           (t1_suffix(" RD ") || t1_suffix(" -| "))) {
+        if (t1_cs && t1_cslen == 0 && (t1_line_ptr - t1_line_array > 4) &&
+            (t1_suffix (" RD ") || t1_suffix (" -| "))) {
             p = t1_line_ptr - 5;
             while (*p != ' ')
                 p--;
-            t1_cslen = l = t1_scan_num(p + 1, 0);
-            cs_start = t1_line_ptr - t1_line_array; /* cs_start is an index now */
-            alloc_array(t1_line, l, T1_BUF_SIZE);
+            t1_cslen = l = t1_scan_num (p + 1, 0);
+            cs_start = t1_line_ptr - t1_line_array;     /* cs_start is an index now */
+            alloc_array (t1_line, l, T1_BUF_SIZE);
             while (l-- > 0)
-                *t1_line_ptr++ = edecrypt(t1_getbyte());
+                *t1_line_ptr++ = edecrypt (t1_getbyte ());
         }
-        c = t1_getbyte();
+        c = t1_getbyte ();
     }
-    alloc_array(t1_line, 2, T1_BUF_SIZE); /* append_eol can append 2 chars */
-    append_eol(t1_line_ptr, t1_line_array, t1_line_limit);
+    alloc_array (t1_line, 2, T1_BUF_SIZE);      /* append_eol can append 2 chars */
+    append_eol (t1_line_ptr, t1_line_array, t1_line_limit);
     if (t1_line_ptr - t1_line_array < 2)
         goto restart;
     if (eexec_scan == eexec_len)
         t1_in_eexec = 1;
-exit:
+  exit:
     /* ensure that t1_buf_array has as much room as t1_line_array */
     t1_buf_ptr = t1_buf_array;
-    alloc_array(t1_buf, t1_line_limit, t1_line_limit);
+    alloc_array (t1_buf, t1_line_limit, t1_line_limit);
 }
 
-static void t1_putline(void) 
+static void t1_putline (void)
 {
     char *p = t1_line_array;
     if (t1_line_ptr - t1_line_array <= 1)
         return;
-    if (t1_eexec_encrypt)  {
+    if (t1_eexec_encrypt) {
         while (p < t1_line_ptr)
-            out_eexec_char(eencrypt(*p++));
-    }
-    else 
+            out_eexec_char (eencrypt (*p++));
+    } else
         while (p < t1_line_ptr)
-            t1_putchar(*p++);
+            t1_putchar (*p++);
 }
 
-static void t1_puts(const char *s)
+static void t1_puts (const char *s)
 {
     if (s != t1_line_array)
-        strcpy(t1_line_array, s);
-    t1_line_ptr = strend(t1_line_array);
-    t1_putline();
+        strcpy (t1_line_array, s);
+    t1_line_ptr = strend (t1_line_array);
+    t1_putline ();
 }
 
-static void t1_printf(const char *fmt,...)
+#ifdef __GNUC__
+static void t1_printf (const char *fmt, ...)
+    __attribute__ ((format (printf, 1, 2)));
+#endif
+static void t1_printf (const char *fmt, ...)
 {
     va_list args;
-    va_start(args, fmt);
-    vsprintf(t1_line_array, fmt, args);
-    t1_puts(t1_line_array);                                    
-    va_end(args);
+    va_start (args, fmt);
+    vsprintf (t1_line_array, fmt, args);
+    t1_puts (t1_line_array);
+    va_end (args);
 }
 
-static void t1_init_params(const char *open_name_prefix) 
+static void t1_init_params (const char *open_name_prefix)
 {
-    t1_log(open_name_prefix);
-    t1_log(cur_file_name);
+    t1_log (open_name_prefix);
+    t1_log (cur_file_name);
     t1_lenIV = 4;
     t1_dr = 55665;
     t1_er = 55665;
@@ -615,67 +631,67 @@
     t1_synthetic = false;
     t1_eexec_encrypt = false;
     t1_block_length = 0;
-    t1_check_pfa();
+    t1_check_pfa ();
 }
 
-static void t1_close_font_file(const char *close_name_suffix)
+static void t1_close_font_file (const char *close_name_suffix)
 {
-    t1_log(close_name_suffix);
-    t1_close();
+    t1_log (close_name_suffix);
+    t1_close ();
     cur_file_name = NULL;
 }
 
-static void t1_check_block_len(boolean decrypt)
+static void t1_check_block_len (boolean decrypt)
 {
     int l, c;
     if (t1_block_length == 0)
-       return;
-    c = t1_getbyte();
-    if (decrypt) 
-        c = edecrypt(c);
+        return;
+    c = t1_getbyte ();
+    if (decrypt)
+        c = edecrypt (c);
     l = t1_block_length;
     if (!(l == 0 && (c == 10 || c == 13))) {
-        pdftex_warn("%i bytes more than expected were ignored", l + 1);
+        pdftex_warn ("%i bytes more than expected were ignored", l + 1);
         while (l-- > 0)
-            t1_getbyte();
+            t1_getbyte ();
     }
 }
 
-static void t1_start_eexec(void)
+static void t1_start_eexec (void)
 {
     int i;
-    if (is_included(fm_cur)) {
-        get_length1();
-        save_offset();
+    if (is_included (fm_cur)) {
+        get_length1 ();
+        save_offset ();
     }
     if (!t1_pfa)
-        t1_check_block_len(false);
+        t1_check_block_len (false);
     for (t1_line_ptr = t1_line_array, i = 0; i < 4; i++) {
-        edecrypt(t1_getbyte());
+        edecrypt (t1_getbyte ());
         *t1_line_ptr++ = 0;
     }
     t1_eexec_encrypt = true;
-    if (is_included(fm_cur))
-        t1_putline(); /* to put the first four bytes */
+    if (is_included (fm_cur))
+        t1_putline ();          /* to put the first four bytes */
 }
 
-static void t1_stop_eexec(void)
+static void t1_stop_eexec (void)
 {
     int c;
-    if (is_included(fm_cur)) {
-        get_length2();
-        save_offset();
+    if (is_included (fm_cur)) {
+        get_length2 ();
+        save_offset ();
     }
-    end_last_eexec_line();
+    end_last_eexec_line ();
     if (!t1_pfa)
-        t1_check_block_len(true);
+        t1_check_block_len (true);
     else {
-        c = edecrypt(t1_getbyte());
+        c = edecrypt (t1_getbyte ());
         if (!(c == 10 || c == 13)) {
             if (last_hexbyte == 0)
-                t1_puts("00");
+                t1_puts ("00");
             else
-                pdftex_warn("unexpected data after eexec");
+                pdftex_warn ("unexpected data after eexec");
         }
     }
     t1_cs = false;
@@ -683,455 +699,464 @@
 }
 
 #ifdef pdfTeX
-static void t1_modify_fm(void)
+/* macros for various transforms; currently only slant and extend are used */
+#  define do_xshift(x,a) {x[4]+=a;}
+#  define do_yshift(x,a) {x[5]+=a;}
+#  define do_xscale(x,a) {x[0]*=a; x[2]*=a; x[4]*=a;}
+#  define do_yscale(x,a) {x[1]*=a; x[3]*=a; x[5]*=a;}
+#  define do_extend(x,a) {do_xscale(x,a);}
+#  define do_scale(x,a)  {do_xscale(x,a); do_yscale(x,a);}
+#  define do_slant(x,a)  {x[0]+=x[1]*(a); x[2]+=x[3]*(a); x[4]+=x[5]*(a);}
+#  define do_shear(x,a)  {x[1]+=x[0]*(a); x[3]+=x[2]*(a); x[5]+=x[4]*(a);}
+#  define do_rotate(x,a)          \
+  {float t, u=cos(a), v=sin(a); \
+  t    =x[0]*u+x[1]*-v;         \
+  x[1] =x[0]*v+x[1]* u; x[0]=t; \
+  t    =x[2]*u+x[3]*-v;         \
+  x[3] =x[2]*v+x[3]* u; x[2]=t; \
+  t    =x[4]*u+x[5]*-v;         \
+  x[5] =x[4]*v+x[5]* u; x[4]=t;}
+
+static void t1_modify_fm (void)
 {
- /*
-  * font matrix is given as six numbers a0..a5, which stands for the matrix
-  * 
-  *           a0 a1 0
-  *     M =   a2 a3 0
-  *           a4 a5 1
-  * 
-  * ExtendFont is given as
-  * 
-  *           e 0 0
-  *     E =   0 1 0
-  *           0 0 1
-  * 
-  * SlantFont is given as
-  * 
-  *           1 0 0
-  *     S =   s 1 0
-  *           0 0 1
-  * 
-  * and the final transformation is
-  * 
-  *                    e*a0        e*a1       0
-  *     F =  E.S.M  =  s*e*a0+a2   s*e*a1+a3  0
-  *                    a4          a5         1
-  */
-    float e, s, a[6], b[6];
+    /*
+     * font matrix is given as six numbers a0..a5, which stands for the matrix
+     *
+     *           a0 a1 0
+     *     M =   a2 a3 0
+     *           a4 a5 1
+     *
+     * ExtendFont is given as
+     *
+     *           e 0 0
+     *     E =   0 1 0
+     *           0 0 1
+     *
+     * SlantFont is given as
+     *
+     *           1 0 0
+     *     S =   s 1 0
+     *           0 0 1
+     *
+     * The slant transform must be done _before_ the extend transform
+     * for compatibility!
+     */
+    float a[6];
     int i, c;
     char *p, *q, *r;
-    if ((p = strchr(t1_line_array, '[')) == 0)
-        if ((p = strchr(t1_line_array, '{')) == 0) {
-            remove_eol(p, t1_line_array);
-            pdftex_fail("FontMatrix: an array expected: `%s'", t1_line_array);
+    if ((p = strchr (t1_line_array, '[')) == 0)
+        if ((p = strchr (t1_line_array, '{')) == 0) {
+            remove_eol (p, t1_line_array);
+            pdftex_fail ("FontMatrix: an array expected: `%s'", t1_line_array);
         }
-    c = *p++; /* save the character '[' resp. '{' */
-    strncpy(t1_buf_array, t1_line_array, (unsigned)(p - t1_line_array));
+    c = *p++;                   /* save the character '[' resp. '{' */
+    strncpy (t1_buf_array, t1_line_array, (unsigned) (p - t1_line_array));
     r = t1_buf_array + (p - t1_line_array);
     for (i = 0; i < 6; i++) {
-        a[i] = t1_scan_num(p, &q);
+        a[i] = t1_scan_num (p, &q);
         p = q;
     }
-    if (fm_extend(fm_cur) != 0)
-        e = fm_extend(fm_cur)*1E-3;
-    else
-        e = 1;
-    s = fm_slant(fm_cur)*1E-3;
-    b[0] = e*a[0];
-    b[1] = e*a[1];
-    b[2] = s*e*a[0] + a[2];
-    b[3] = s*e*a[1] + a[3];
-    b[4] = a[4];
-    b[5] = a[5];
+    if (fm_slant (fm_cur) != 0)
+        do_slant (a, fm_slant (fm_cur) * 1E-3);
+    if (fm_extend (fm_cur) != 0)
+        do_extend (a, fm_extend (fm_cur) * 1E-3);
     for (i = 0; i < 6; i++) {
-        sprintf(r, "%g ", b[i]);
-        r = strend(r);
+        sprintf (r, "%g ", a[i]);
+        r = strend (r);
     }
     if (c == '[') {
         while (*p != ']' && *p != 0)
             p++;
-    }
-    else {
+    } else {
         while (*p != '}' && *p != 0)
             p++;
     }
     if (*p == 0) {
-        remove_eol(p, t1_line_array);
-        pdftex_fail("FontMatrix: cannot find the corresponding character to '%c': `%s'",  c, t1_line_array);
+        remove_eol (p, t1_line_array);
+        pdftex_fail
+            ("FontMatrix: cannot find the corresponding character to '%c': `%s'",
+             c, t1_line_array);
     }
-    strcpy(r, p);
-    strcpy(t1_line_array, t1_buf_array);
-    t1_line_ptr = eol(t1_line_array);
+    strcpy (r, p);
+    strcpy (t1_line_array, t1_buf_array);
+    t1_line_ptr = eol (t1_line_array);
 }
 
-static void t1_modify_italic(void)
+static void t1_modify_italic (void)
 {
     float a;
     char *p, *r;
-    if (fm_slant(fm_cur) == 0)
+    if (fm_slant (fm_cur) == 0)
         return;
-    p = strchr(t1_line_array, ' ');
-    strncpy(t1_buf_array, t1_line_array, (unsigned)(p - t1_line_array + 1));
-    a = t1_scan_num(p + 1, &r);
-    a -= atan(fm_slant(fm_cur)*1E-3)*(180/M_PI);
-    sprintf(t1_buf_array + (p - t1_line_array + 1), "%g", a);
-    strcpy(strend(t1_buf_array), r);
-    strcpy(t1_line_array, t1_buf_array);
-    t1_line_ptr = eol(t1_line_array);
-    font_keys[ITALIC_ANGLE_CODE].value = round(a);
+    p = strchr (t1_line_array, ' ');
+    strncpy (t1_buf_array, t1_line_array, (unsigned) (p - t1_line_array + 1));
+    a = t1_scan_num (p + 1, &r);
+    a -= atan (fm_slant (fm_cur) * 1E-3) * (180 / M_PI);
+    sprintf (t1_buf_array + (p - t1_line_array + 1), "%g", a);
+    strcpy (strend (t1_buf_array), r);
+    strcpy (t1_line_array, t1_buf_array);
+    t1_line_ptr = eol (t1_line_array);
+    font_keys[ITALIC_ANGLE_CODE].value = round (a);
     font_keys[ITALIC_ANGLE_CODE].valid = true;
 }
 
-static void t1_scan_keys(void)
+static void t1_scan_keys (void)
 {
     int i, k;
     char *p, *q, *r;
     key_entry *key;
-    if (fm_extend(fm_cur) != 0 || fm_slant(fm_cur) != 0) {
-        if (t1_prefix("/FontMatrix")) {
-            t1_modify_fm();
+    if (fm_extend (fm_cur) != 0 || fm_slant (fm_cur) != 0) {
+        if (t1_prefix ("/FontMatrix")) {
+            t1_modify_fm ();
             return;
         }
-        if (t1_prefix("/ItalicAngle")) {
-            t1_modify_italic();
+        if (t1_prefix ("/ItalicAngle")) {
+            t1_modify_italic ();
             return;
         }
     }
-    if (t1_prefix("/FontType")) {
-        p = t1_line_array + strlen("FontType") + 1;
-        if ((i = t1_scan_num(p, 0)) != 1)
-            pdftex_fail("Type%d fonts unsupported by pdfTeX", i);
+    if (t1_prefix ("/FontType")) {
+        p = t1_line_array + strlen ("FontType") + 1;
+        if ((i = t1_scan_num (p, 0)) != 1)
+            pdftex_fail ("Type%d fonts unsupported by pdfTeX", i);
         return;
     }
-    for (key = font_keys; key - font_keys  < MAX_KEY_CODE; key++)
-        if (strncmp(t1_line_array + 1, key->t1name, strlen(key->t1name)) == 0)
-          break;
+    for (key = font_keys; key - font_keys < MAX_KEY_CODE; key++)
+        if (strncmp (t1_line_array + 1, key->t1name, strlen (key->t1name)) == 0)
+            break;
     if (key - font_keys == MAX_KEY_CODE)
         return;
     key->valid = true;
-    p = t1_line_array + strlen(key->t1name) + 1;
-    skip(p, ' ');
+    p = t1_line_array + strlen (key->t1name) + 1;
+    skip (p, ' ');
     if ((k = key - font_keys) == FONTNAME_CODE) {
         if (*p != '/') {
-            remove_eol(p, t1_line_array);
-            pdftex_fail("a name expected: `%s'", t1_line_array);
+            remove_eol (p, t1_line_array);
+            pdftex_fail ("a name expected: `%s'", t1_line_array);
         }
-        r = ++p; /* skip the slash */
+        r = ++p;                /* skip the slash */
         for (q = t1_buf_array; *p != ' ' && *p != 10; *q++ = *p++);
         *q = 0;
-        if (fm_slant(fm_cur) != 0) {
-            sprintf(q, "-Slant_%i", (int)fm_slant(fm_cur));
-            q = strend(q);
+        if (fm_slant (fm_cur) != 0) {
+            sprintf (q, "-Slant_%i", (int) fm_slant (fm_cur));
+            q = strend (q);
         }
-        if (fm_extend(fm_cur) != 0) {
-            sprintf(q, "-Extend_%i", (int)fm_extend(fm_cur));
+        if (fm_extend (fm_cur) != 0) {
+            sprintf (q, "-Extend_%i", (int) fm_extend (fm_cur));
         }
-        strncpy(fontname_buf, t1_buf_array, FONTNAME_BUF_SIZE);
-        /* at this moment we cannot call make_subset_tag() yet, as the encoding 
+        strncpy (fontname_buf, t1_buf_array, FONTNAME_BUF_SIZE);
+        /* at this moment we cannot call make_subset_tag() yet, as the encoding
          * is not read; thus we mark the offset of the subset tag and write it
          * later */
-        if (is_included(fm_cur) && is_subsetted(fm_cur)) {
-            t1_fontname_offset = fb_offset() + (r - t1_line_array);
-            strcpy(t1_buf_array, p);
-            sprintf(r, "ABCDEF+%s%s", fontname_buf, t1_buf_array);
-            t1_line_ptr = eol(r);
+        if (is_included (fm_cur) && is_subsetted (fm_cur)) {
+            t1_fontname_offset = t1_offset () + (r - t1_line_array);
+            strcpy (t1_buf_array, p);
+            sprintf (r, "ABCDEF+%s%s", fontname_buf, t1_buf_array);
+            t1_line_ptr = eol (r);
         }
         return;
     }
-    if ((k == STEMV_CODE ||  k == FONTBBOX1_CODE) &&
-        (*p == '[' || *p == '{'))
+    if ((k == STEMV_CODE || k == FONTBBOX1_CODE)
+        && (*p == '[' || *p == '{'))
         p++;
     if (k == FONTBBOX1_CODE) {
         for (i = 0; i < 4; i++) {
-            key[i].value = t1_scan_num(p, &r);
+            key[i].value = t1_scan_num (p, &r);
             p = r;
         }
         return;
     }
-    key->value = t1_scan_num(p, 0);
+    key->value = t1_scan_num (p, 0);
 }
 
-#endif /* pdfTeX */
+#endif                          /* pdfTeX */
 
-static void t1_scan_param(void) 
+static void t1_scan_param (void)
 {
     static const char *lenIV = "/lenIV";
     if (!t1_scan || *t1_line_array != '/')
         return;
-    if (t1_prefix(lenIV)) {
-        t1_lenIV = t1_scan_num(t1_line_array + strlen(lenIV), 0);
+    if (t1_prefix (lenIV)) {
+        t1_lenIV = t1_scan_num (t1_line_array + strlen (lenIV), 0);
         return;
     }
-    t1_scan_keys();
+    t1_scan_keys ();
 }
 
-static void copy_glyph_names(char **glyph_names, int a, int b)
+static void copy_glyph_names (char **glyph_names, int a, int b)
 {
     if (glyph_names[b] != notdef) {
-        free(glyph_names[b]);
-        glyph_names[b] = (char*) notdef;
+        free (glyph_names[b]);
+        glyph_names[b] = (char *) notdef;
     }
     if (glyph_names[a] != notdef) {
-        glyph_names[b] = xstrdup(glyph_names[a]);
+        glyph_names[b] = xstrdup (glyph_names[a]);
     }
 }
 
-static void t1_builtin_enc(void)
+static void t1_builtin_enc (void)
 {
     int i, a, b, c, counter = 0;
     char *r, *p;
-   /*
-    * At this moment "/Encoding" is the prefix of t1_line_array
-    */
-    if (t1_suffix("def")) { /* predefined encoding */
-        sscanf(t1_line_array + strlen("/Encoding"), "%256s", t1_buf_array);
-        if (strcmp(t1_buf_array, "StandardEncoding") == 0) {
-            for (i = 0; i <= MAX_CHAR_CODE; i++)
+    /*
+     * At this moment "/Encoding" is the prefix of t1_line_array
+     */
+    if (t1_suffix ("def")) {    /* predefined encoding */
+        sscanf (t1_line_array + strlen ("/Encoding"), "%256s", t1_buf_array);
+        if (strcmp (t1_buf_array, "StandardEncoding") == 0) {
+            for (i = 0; i < 256; i++)
                 if (standard_glyph_names[i] == notdef)
-                    t1_builtin_glyph_names[i] = (char*) notdef;
+                    t1_builtin_glyph_names[i] = (char *) notdef;
                 else
-                    t1_builtin_glyph_names[i] = xstrdup(standard_glyph_names[i]);
+                    t1_builtin_glyph_names[i] =
+                        xstrdup (standard_glyph_names[i]);
             t1_encoding = ENC_STANDARD;
-        }
-        else 
-            pdftex_fail("cannot subset font (unknown predefined encoding `%s')", 
-                        t1_buf_array);
+        } else
+            pdftex_fail
+                ("cannot subset font (unknown predefined encoding `%s')",
+                 t1_buf_array);
         return;
     } else
         t1_encoding = ENC_BUILTIN;
-   /*
-    * At this moment "/Encoding" is the prefix of t1_line_array, and the encoding is
-    * not a predefined encoding
-    * 
-    * We have two possible forms of Encoding vector. The first case is
-    * 
-    *     /Encoding [/a /b /c...] readonly def
-    * 
-    * and the second case can look like
-    * 
-    *     /Encoding 256 array 0 1 255 {1 index exch /.notdef put} for
-    *     dup 0 /x put
-    *     dup 1 /y put
-    *     ...
-    *     readonly def
-    */
-    for (i = 0; i <= MAX_CHAR_CODE; i++)
-        t1_builtin_glyph_names[i] = (char*) notdef;
-    if (t1_prefix("/Encoding [") || t1_prefix("/Encoding[")) { /* the first case */
-        r = strchr(t1_line_array, '[') + 1;
-        skip(r, ' ');
-        for(;;) {
+    /*
+     * At this moment "/Encoding" is the prefix of t1_line_array, and the encoding is
+     * not a predefined encoding
+     *
+     * We have two possible forms of Encoding vector. The first case is
+     *
+     *     /Encoding [/a /b /c...] readonly def
+     *
+     * and the second case can look like
+     *
+     *     /Encoding 256 array 0 1 255 {1 index exch /.notdef put} for
+     *     dup 0 /x put
+     *     dup 1 /y put
+     *     ...
+     *     readonly def
+     */
+    for (i = 0; i < 256; i++)
+        t1_builtin_glyph_names[i] = (char *) notdef;
+    if (t1_prefix ("/Encoding [") || t1_prefix ("/Encoding[")) {        /* the first case */
+        r = strchr (t1_line_array, '[') + 1;
+        skip (r, ' ');
+        for (;;) {
             while (*r == '/') {
                 for (p = t1_buf_array, r++;
                      *r != 32 && *r != 10 && *r != ']' && *r != '/';
                      *p++ = *r++);
                 *p = 0;
-                skip(r, ' ');
-                if (counter > MAX_CHAR_CODE)
-                    pdftex_fail("encoding vector contains more than %i names",
-                            (int)(MAX_CHAR_CODE + 1));
-                if (strcmp(t1_buf_array, notdef) != 0)
-                    t1_builtin_glyph_names[counter] = xstrdup(t1_buf_array);
+                skip (r, ' ');
+                if (counter > 255)
+                    pdftex_fail
+                        ("encoding vector contains more than 256 names");
+                if (strcmp (t1_buf_array, notdef) != 0)
+                    t1_builtin_glyph_names[counter] = xstrdup (t1_buf_array);
                 counter++;
             }
             if (*r != 10 && *r != '%') {
-                if (str_prefix(r, "] def") || str_prefix(r, "] readonly def"))
+                if (str_prefix (r, "] def")
+                    || str_prefix (r, "] readonly def"))
                     break;
                 else {
-                    remove_eol(r, t1_line_array);
-                    pdftex_fail("a name or `] def' or `] readonly def' expected: `%s'",
-                                t1_line_array);
+                    remove_eol (r, t1_line_array);
+                    pdftex_fail
+                        ("a name or `] def' or `] readonly def' expected: `%s'",
+                         t1_line_array);
                 }
             }
-            t1_getline();
+            t1_getline ();
             r = t1_line_array;
         }
-    }
-    else { /* the second case */
-        p = strchr(t1_line_array, 10); 
+    } else {                    /* the second case */
+        p = strchr (t1_line_array, 10);
         for (;;) {
             if (*p == 10) {
-                t1_getline();
+                t1_getline ();
                 p = t1_line_array;
             }
             /*
-             check for `dup <index> <glyph> put'
+               check for `dup <index> <glyph> put'
              */
-            if (sscanf(p, "dup %i%256s put", &i, t1_buf_array) == 2 && 
-                *t1_buf_array == '/' && valid_code(i)) {
-                if (strcmp(t1_buf_array + 1, notdef) != 0)
-                    t1_builtin_glyph_names[i] = xstrdup(t1_buf_array + 1);
-                p = strstr(p, " put") + strlen(" put");
-                skip(p, ' ');
+            if (sscanf (p, "dup %i%256s put", &i, t1_buf_array) == 2 &&
+                *t1_buf_array == '/' && valid_code (i)) {
+                if (strcmp (t1_buf_array + 1, notdef) != 0)
+                    t1_builtin_glyph_names[i] = xstrdup (t1_buf_array + 1);
+                p = strstr (p, " put") + strlen (" put");
+                skip (p, ' ');
             }
             /*
-             check for `dup dup <to> exch <from> get put'
+               check for `dup dup <to> exch <from> get put'
              */
-            else if (sscanf(p, "dup dup %i exch %i get put", &b, &a) == 2 &&
-                     valid_code(a) && valid_code(b)) {
-                copy_glyph_names(t1_builtin_glyph_names, a, b);
-                p = strstr(p, " get put") + strlen(" get put");
-                skip(p, ' ');
+            else if (sscanf (p, "dup dup %i exch %i get put", &b, &a) == 2
+                     && valid_code (a) && valid_code (b)) {
+                copy_glyph_names (t1_builtin_glyph_names, a, b);
+                p = strstr (p, " get put") + strlen (" get put");
+                skip (p, ' ');
             }
             /*
-             check for `dup dup <from> <size> getinterval <to> exch putinterval'
+               check for `dup dup <from> <size> getinterval <to> exch putinterval'
              */
-            else if (sscanf(p, "dup dup %i %i getinterval %i exch putinterval", 
-                            &a, &c, &b) == 3 && 
-                     valid_code(a) && valid_code(b) && valid_code(c)) {
+            else if (sscanf
+                     (p, "dup dup %i %i getinterval %i exch putinterval",
+                      &a, &c, &b) == 3 && valid_code (a) && valid_code (b)
+                     && valid_code (c)) {
                 for (i = 0; i < c; i++)
-                    copy_glyph_names(t1_builtin_glyph_names, a + i, b + i);
-                p = strstr(p, " putinterval") + strlen(" putinterval");
-                skip(p, ' ');
+                    copy_glyph_names (t1_builtin_glyph_names, a + i, b + i);
+                p = strstr (p, " putinterval") + strlen (" putinterval");
+                skip (p, ' ');
             }
             /*
-             check for `def' or `readonly def'
+               check for `def' or `readonly def'
              */
-            else if ((p == t1_line_array || (p > t1_line_array && p[-1] == ' ')) &&
-                     strcmp(p, "def\n") == 0)
+            else if ((p == t1_line_array || (p > t1_line_array && p[-1] == ' '))
+                     && strcmp (p, "def\n") == 0)
                 return;
-            /* 
-             skip an unrecognizable word 
+            /*
+               skip an unrecognizable word
              */
             else {
                 while (*p != ' ' && *p != 10)
-                    p++;    
-                skip(p, ' ');
+                    p++;
+                skip (p, ' ');
             }
         }
     }
 }
 
-static void t1_check_end(void)
+static void t1_check_end (void)
 {
-    if (t1_eof())
+    if (t1_eof ())
         return;
-    t1_getline();
-    if (t1_prefix("{restore}"))
-        t1_putline();
+    t1_getline ();
+    if (t1_prefix ("{restore}"))
+        t1_putline ();
 }
 
 #ifdef pdfTeX
-static boolean t1_open_fontfile(const char *open_name_prefix)
+static boolean t1_open_fontfile (const char *open_name_prefix)
 {
-    char *ex_ffname = NULL;
     ff_entry *ff;
-    ff = check_ff_exist(fm_cur);
+    ff = check_ff_exist (fm_cur);
     if (ff->ff_path != NULL)
-        t1_file = xfopen(cur_file_name = ff->ff_path, FOPEN_RBIN_MODE);
+        t1_file = xfopen (cur_file_name = ff->ff_path, FOPEN_RBIN_MODE);
     else {
-        set_cur_file_name(fm_cur->ff_name);
-        pdftex_warn("cannot open Type 1 font file for reading");
+        set_cur_file_name (fm_cur->ff_name);
+        pdftex_warn ("cannot open Type 1 font file for reading");
         return false;
     }
-    t1_init_params(open_name_prefix);
+    t1_init_params (open_name_prefix);
     fontfile_found = true;
     return true;
 }
 
-boolean t1_read_enc(fm_entry *fm)
+static void t1_scan_only (void)
 {
-    read_encoding_only = true;
-    fm_cur = fm;
-    if (!t1_open_fontfile("{"))
-        return false;
-    while (!t1_prefix("/Encoding"))
-        t1_getline();
-    t1_builtin_enc(); 
-    t1_close_font_file("}");
-    return true;
-}
-
-static void t1_scan_only(void)
-{
     do {
-        t1_getline();
-        t1_scan_param(); 
-    } while (t1_in_eexec == 0);
-    t1_start_eexec();
+        t1_getline ();
+        t1_scan_param ();
+    }
+    while (t1_in_eexec == 0);
+    t1_start_eexec ();
     do {
-        t1_getline();
-        t1_scan_param();
-    } while (!(t1_charstrings() || t1_subrs()));
+        t1_getline ();
+        t1_scan_param ();
+    }
+    while (!(t1_charstrings () || t1_subrs ()));
 }
 
-static void t1_include(void)
+static void t1_include (void)
 {
-    save_offset();
     do {
-        t1_getline();
-        t1_scan_param();
-        t1_putline();
-    } while (t1_in_eexec == 0);
-    t1_start_eexec();
+        t1_getline ();
+        t1_scan_param ();
+        t1_putline ();
+    }
+    while (t1_in_eexec == 0);
+    t1_start_eexec ();
     do {
-        t1_getline();
-        t1_scan_param();
-        t1_putline();
-    } while (!(t1_charstrings() || t1_subrs()));
+        t1_getline ();
+        t1_scan_param ();
+        t1_putline ();
+    }
+    while (!(t1_charstrings () || t1_subrs ()));
     t1_cs = true;
     do {
-        t1_getline();
-        t1_putline();
-    } while (!t1_end_eexec());
-    t1_stop_eexec();
-    do {
-        t1_getline();
-        t1_putline();
-    } while (!t1_cleartomark());
-    t1_check_end(); /* write "{restore}if" if found */
-    get_length3();
+        t1_getline ();
+        t1_putline ();
+    }
+    while (!t1_end_eexec ());
+    t1_stop_eexec ();
+    if (fixedcontent) {         /* copy 512 zeros (not needed for PDF) */
+        do {
+            t1_getline ();
+            t1_putline ();
+        }
+        while (!t1_cleartomark ());
+        t1_check_end ();        /* write "{restore}if" if found */
+    }
+    get_length3 ();
 }
 
-#else /* not pdfTeX */
-static boolean t1_open_fontfile(char *open_name_prefix)
+#else                           /* not pdfTeX */
+static boolean t1_open_fontfile (char *open_name_prefix)
 {
-    if (!t1_open())
-        return false;
-    t1_init_params(open_name_prefix);
+    if (!t1_open ()) {
+        (void) sprintf (errbuf, "! Couldn't find font file %s", cur_file_name);
+        error (errbuf);
+    }
+    t1_init_params (open_name_prefix);
     return true;
 }
-#endif /* pdfTeX */
+#endif                          /* pdfTeX */
 
 #define check_subr(subr) \
     if (subr >= subr_size || subr < 0) \
         pdftex_fail("Subrs array: entry index out of range (%i)",  subr);
 
-static const char **check_cs_token_pair()
+static const char **check_cs_token_pair ()
 {
-    const char **p = (const char**) cs_token_pairs_list;
-    for (; p[0] != NULL; ++p) 
-        if (t1_buf_prefix(p[0]) && t1_buf_suffix(p[1]))
+    const char **p = (const char **) cs_token_pairs_list;
+    for (; p[0] != NULL; ++p)
+        if (t1_buf_prefix (p[0]) && t1_buf_suffix (p[1]))
             return p;
     return NULL;
 }
 
-static void cs_store(boolean is_subr)
+static void cs_store (boolean is_subr)
 {
     char *p;
     cs_entry *ptr;
     int subr;
-    for (p = t1_line_array, t1_buf_ptr = t1_buf_array; *p != ' '; *t1_buf_ptr++ = *p++);
+    for (p = t1_line_array, t1_buf_ptr = t1_buf_array; *p != ' ';
+         *t1_buf_ptr++ = *p++);
     *t1_buf_ptr = 0;
     if (is_subr) {
-        subr = t1_scan_num(p + 1, 0);
-        check_subr(subr);
+        subr = t1_scan_num (p + 1, 0);
+        check_subr (subr);
         ptr = subr_tab + subr;
-    }
-    else {
+    } else {
         ptr = cs_ptr++;
         if (cs_ptr - cs_tab > cs_size)
-            pdftex_fail("CharStrings dict: more entries than dict size (%i)", cs_size);
-        if (strcmp(t1_buf_array + 1, notdef) == 0) /* skip the slash */
-            ptr->name = (char*) notdef;
+            pdftex_fail
+                ("CharStrings dict: more entries than dict size (%i)", cs_size);
+        if (strcmp (t1_buf_array + 1, notdef) == 0)     /* skip the slash */
+            ptr->name = (char *) notdef;
         else
-            ptr->name = xstrdup(t1_buf_array + 1); 
+            ptr->name = xstrdup (t1_buf_array + 1);
     }
     /* copy " RD " + cs data to t1_buf_array */
-    memcpy(t1_buf_array, t1_line_array + cs_start - 4, (unsigned)(t1_cslen + 4));
+    memcpy (t1_buf_array, t1_line_array + cs_start - 4,
+            (unsigned) (t1_cslen + 4));
     /* copy the end of cs data to t1_buf_array */
-    for (p = t1_line_array + cs_start + t1_cslen, t1_buf_ptr = t1_buf_array + t1_cslen + 4; 
-         *p != 10; *t1_buf_ptr++ = *p++);
+    for (p = t1_line_array + cs_start + t1_cslen, t1_buf_ptr =
+         t1_buf_array + t1_cslen + 4; *p != 10; *t1_buf_ptr++ = *p++);
     *t1_buf_ptr++ = 10;
     if (is_subr && cs_token_pair == NULL)
-        cs_token_pair = check_cs_token_pair();
+        cs_token_pair = check_cs_token_pair ();
     ptr->len = t1_buf_ptr - t1_buf_array;
     ptr->cslen = t1_cslen;
-    ptr->data = xtalloc(ptr->len, byte);
-    memcpy(ptr->data, t1_buf_array, ptr->len);
+    ptr->data = xtalloc (ptr->len, byte);
+    memcpy (ptr->data, t1_buf_array, ptr->len);
     ptr->valid = true;
 }
 
@@ -1157,7 +1182,7 @@
 }
 
 /*
-static integer cc_get(integer index) 
+static integer cc_get(integer index)
 {
     if (index <  0) {
         if (stack_ptr + index < cc_stack )
@@ -1176,48 +1201,48 @@
 
 #define cc_push(V)  *stack_ptr++ = V
 #define cc_clear()  stack_ptr = cc_stack
-    
+
 #define set_cc(N, B, A, C) \
     cc_tab[N].nargs = A;   \
     cc_tab[N].bottom = B;  \
     cc_tab[N].clear = C;   \
     cc_tab[N].valid = true
-    
-static void cc_init(void)
+
+static void cc_init (void)
 {
     int i;
     if (is_cc_init)
         return;
     for (i = 0; i < CS_MAX; i++)
         cc_tab[i].valid = false;
-    set_cc(CS_HSTEM,           true,   2, true);
-    set_cc(CS_VSTEM,           true,   2, true);
-    set_cc(CS_VMOVETO,         true,   1, true);
-    set_cc(CS_RLINETO,         true,   2, true);
-    set_cc(CS_HLINETO,         true,   1, true);
-    set_cc(CS_VLINETO,         true,   1, true);
-    set_cc(CS_RRCURVETO,       true,   6, true);
-    set_cc(CS_CLOSEPATH,       false,  0, true);
-    set_cc(CS_CALLSUBR,        false,  1, false);
-    set_cc(CS_RETURN,          false,  0, false);
+    set_cc (CS_HSTEM, true, 2, true);
+    set_cc (CS_VSTEM, true, 2, true);
+    set_cc (CS_VMOVETO, true, 1, true);
+    set_cc (CS_RLINETO, true, 2, true);
+    set_cc (CS_HLINETO, true, 1, true);
+    set_cc (CS_VLINETO, true, 1, true);
+    set_cc (CS_RRCURVETO, true, 6, true);
+    set_cc (CS_CLOSEPATH, false, 0, true);
+    set_cc (CS_CALLSUBR, false, 1, false);
+    set_cc (CS_RETURN, false, 0, false);
     /*
-    set_cc(CS_ESCAPE,          false,  0, false);
-    */
-    set_cc(CS_HSBW,            true,   2, true);
-    set_cc(CS_ENDCHAR,         false,  0, true);
-    set_cc(CS_RMOVETO,         true,   2, true);
-    set_cc(CS_HMOVETO,         true,   1, true);
-    set_cc(CS_VHCURVETO,       true,   4, true);
-    set_cc(CS_HVCURVETO,       true,   4, true);
-    set_cc(CS_DOTSECTION,      false,  0, true);
-    set_cc(CS_VSTEM3,          true,   6, true);
-    set_cc(CS_HSTEM3,          true,   6, true);
-    set_cc(CS_SEAC,            true,   5, true);
-    set_cc(CS_SBW,             true,   4, true);
-    set_cc(CS_DIV,             false,  2, false);
-    set_cc(CS_CALLOTHERSUBR,   false,  0, false);
-    set_cc(CS_POP,             false,  0, false);
-    set_cc(CS_SETCURRENTPOINT, true,   2, true);
+       set_cc(CS_ESCAPE,          false,  0, false);
+     */
+    set_cc (CS_HSBW, true, 2, true);
+    set_cc (CS_ENDCHAR, false, 0, true);
+    set_cc (CS_RMOVETO, true, 2, true);
+    set_cc (CS_HMOVETO, true, 1, true);
+    set_cc (CS_VHCURVETO, true, 4, true);
+    set_cc (CS_HVCURVETO, true, 4, true);
+    set_cc (CS_DOTSECTION, false, 0, true);
+    set_cc (CS_VSTEM3, true, 6, true);
+    set_cc (CS_HSTEM3, true, 6, true);
+    set_cc (CS_SEAC, true, 5, true);
+    set_cc (CS_SBW, true, 4, true);
+    set_cc (CS_DIV, false, 2, false);
+    set_cc (CS_CALLOTHERSUBR, false, 0, false);
+    set_cc (CS_POP, false, 0, false);
+    set_cc (CS_SETCURRENTPOINT, true, 2, true);
     is_cc_init = true;
 }
 
@@ -1226,45 +1251,48 @@
 #define mark_subr(n)    cs_mark(0, n)
 #define mark_cs(s)      cs_mark(s, 0)
 
-static void cs_warn(const char *cs_name, int subr, const char *fmt,...)
+#ifdef __GNUC__
+static void cs_warn (const char *cs_name, int subr, const char *fmt, ...)
+    __attribute__ ((format (printf, 3, 4)));
+#endif
+static void cs_warn (const char *cs_name, int subr, const char *fmt, ...)
 {
     char buf[SMALL_BUF_SIZE];
     va_list args;
-    va_start(args, fmt);
-    vsprintf(buf, fmt, args);
-    va_end(args);
+    va_start (args, fmt);
+    vsprintf (buf, fmt, args);
+    va_end (args);
     if (cs_name == NULL)
-        pdftex_warn("Subr (%i): %s", (int)subr, buf);
+        pdftex_warn ("Subr (%i): %s", (int) subr, buf);
     else
-        pdftex_warn("CharString (/%s): %s", cs_name, buf);
+        pdftex_warn ("CharString (/%s): %s", cs_name, buf);
 }
 
-static void cs_mark(const char *cs_name, int subr)
+static void cs_mark (const char *cs_name, int subr)
 {
     byte *data;
     int i, b, cs_len;
     integer a, a1, a2;
     unsigned short cr;
-    static integer lastargOtherSubr3 = 3; /* the argument of last call to 
-                                             OtherSubrs[3] */
+    static integer lastargOtherSubr3 = 3;       /* the argument of last call to
+                                                   OtherSubrs[3] */
     cs_entry *ptr;
     cc_entry *cc;
     if (cs_name == NULL) {
-        check_subr(subr);
+        check_subr (subr);
         ptr = subr_tab + subr;
         if (!ptr->valid)
             return;
-    }
-    else {
-        if (cs_notdef != NULL && 
-            (cs_name == notdef || strcmp(cs_name, notdef) == 0))
+    } else {
+        if (cs_notdef != NULL &&
+            (cs_name == notdef || strcmp (cs_name, notdef) == 0))
             ptr = cs_notdef;
         else {
             for (ptr = cs_tab; ptr < cs_ptr; ptr++)
-                if (strcmp(ptr->name, cs_name) == 0)
+                if (strcmp (ptr->name, cs_name) == 0)
                     break;
             if (ptr == cs_ptr) {
-                pdftex_warn("glyph `%s' undefined", cs_name);
+                pdftex_warn ("glyph `%s' undefined", cs_name);
                 return;
             }
             if (ptr->name == notdef)
@@ -1274,165 +1302,162 @@
     /* only marked CharString entries and invalid entries can be skipped;
        valid marked subrs must be parsed to keep the stack in sync */
     if (!ptr->valid || (ptr->used && cs_name != NULL))
-        return; 
+        return;
     ptr->used = true;
-    cr = 4330; 
+    cr = 4330;
     cs_len = ptr->cslen;
     data = ptr->data + 4;
     for (i = 0; i < t1_lenIV; i++, cs_len--)
-        cs_getchar();
+        cs_getchar ();
     while (cs_len > 0) {
         --cs_len;
-        b = cs_getchar();
+        b = cs_getchar ();
         if (b >= 32) {
             if (b <= 246)
                 a = b - 139;
             else if (b <= 250) {
                 --cs_len;
-                a = ((b - 247) << 8) + 108 + cs_getchar();
-            } 
-            else if (b <= 254) {
+                a = ((b - 247) << 8) + 108 + cs_getchar ();
+            } else if (b <= 254) {
                 --cs_len;
-                a = -((b - 251) << 8) - 108 - cs_getchar();
-            } 
-            else {
+                a = -((b - 251) << 8) - 108 - cs_getchar ();
+            } else {
                 cs_len -= 4;
-                a =  (cs_getchar() & 0xff) << 24;
-                a |= (cs_getchar() & 0xff) << 16;
-                a |= (cs_getchar() & 0xff) <<  8;
-                a |= (cs_getchar() & 0xff) <<  0;
-                if (sizeof(integer) > 4 && (a & 0x80000000))
+                a = (cs_getchar () & 0xff) << 24;
+                a |= (cs_getchar () & 0xff) << 16;
+                a |= (cs_getchar () & 0xff) << 8;
+                a |= (cs_getchar () & 0xff) << 0;
+                if (sizeof (integer) > 4 && (a & 0x80000000))
                     a |= ~0x7FFFFFFF;
             }
-            cc_push(a);
-        }
-        else {
+            cc_push (a);
+        } else {
             if (b == CS_ESCAPE) {
-                b = cs_getchar() + CS_1BYTE_MAX;
+                b = cs_getchar () + CS_1BYTE_MAX;
                 cs_len--;
             }
             if (b >= CS_MAX) {
-                cs_warn(cs_name, subr, "command value out of range: %i", (int)b);
+                cs_warn (cs_name, subr, "command value out of range: %i",
+                         (int) b);
                 goto cs_error;
             }
             cc = cc_tab + b;
             if (!cc->valid) {
-                cs_warn(cs_name, subr, "command not valid: %i", (int)b);
+                cs_warn (cs_name, subr, "command not valid: %i", (int) b);
                 goto cs_error;
             }
             if (cc->bottom) {
                 if (stack_ptr - cc_stack < cc->nargs)
-                    cs_warn(cs_name, subr, 
-                            "less arguments on stack (%i) than required (%i)",
-                            (int)(stack_ptr - cc_stack), (int)cc->nargs);
+                    cs_warn (cs_name, subr,
+                             "less arguments on stack (%i) than required (%i)",
+                             (int) (stack_ptr - cc_stack), (int) cc->nargs);
                 else if (stack_ptr - cc_stack > cc->nargs)
-                    cs_warn(cs_name, subr, 
-                            "more arguments on stack (%i) than required (%i)",
-                            (int)(stack_ptr - cc_stack), (int)cc->nargs);
+                    cs_warn (cs_name, subr,
+                             "more arguments on stack (%i) than required (%i)",
+                             (int) (stack_ptr - cc_stack), (int) cc->nargs);
             }
             switch (cc - cc_tab) {
             case CS_CALLSUBR:
-                a1 = cc_get(-1);
-                cc_pop(1);
-                mark_subr(a1);
+                a1 = cc_get (-1);
+                cc_pop (1);
+                mark_subr (a1);
                 if (!subr_tab[a1].valid) {
-                    cs_warn(cs_name, subr, 
-                            "cannot call subr (%i)", (int)a1);
+                    cs_warn (cs_name, subr, "cannot call subr (%i)", (int) a1);
                     goto cs_error;
                 }
                 break;
             case CS_DIV:
-                cc_pop(2);
-                cc_push(0);
+                cc_pop (2);
+                cc_push (0);
                 break;
             case CS_CALLOTHERSUBR:
-                if (cc_get(-1) == 3)
-                    lastargOtherSubr3 = cc_get(-3);
-                a1 = cc_get(-2) + 2;
-                cc_pop(a1);
+                if (cc_get (-1) == 3)
+                    lastargOtherSubr3 = cc_get (-3);
+                a1 = cc_get (-2) + 2;
+                cc_pop (a1);
                 break;
             case CS_POP:
-                cc_push(lastargOtherSubr3);
+                cc_push (lastargOtherSubr3);
                 /* the only case when we care about the value being pushed onto
                    stack is when POP follows CALLOTHERSUBR (changing hints by
-                   OtherSubrs[3]) 
+                   OtherSubrs[3])
                  */
                 break;
             case CS_SEAC:
-                a1 = cc_get(3);
-                a2 = cc_get(4);
-                cc_clear();
-                mark_cs(standard_glyph_names[a1]);
-                mark_cs(standard_glyph_names[a2]);
+                a1 = cc_get (3);
+                a2 = cc_get (4);
+                cc_clear ();
+                mark_cs (standard_glyph_names[a1]);
+                mark_cs (standard_glyph_names[a2]);
                 break;
             default:
                 if (cc->clear)
-                    cc_clear();
+                    cc_clear ();
             }
         }
     }
     return;
-cs_error: /* an error occured during parsing */
-    cc_clear();
+  cs_error:                    /* an error occured during parsing */
+    cc_clear ();
     ptr->valid = false;
     ptr->used = false;
 }
 
-static void t1_subset_ascii_part(void)
+static void t1_subset_ascii_part (void)
 {
     int i, j;
-    save_offset();
-    t1_getline();
-    while (!t1_prefix("/Encoding")) {
-        t1_scan_param();
-        t1_putline();
-        t1_getline();
+    t1_getline ();
+    while (!t1_prefix ("/Encoding")) {
+        t1_scan_param ();
+        t1_putline ();
+        t1_getline ();
     }
-    t1_builtin_enc(); 
-    if (is_reencoded(fm_cur))
-        t1_glyph_names = external_enc();
-    else {
+    t1_builtin_enc ();
+    if (is_reencoded (fm_cur))
+        t1_glyph_names = external_enc ();
+    else
         t1_glyph_names = t1_builtin_glyph_names;
-        update_builtin_enc(tex_font, t1_glyph_names); 
+    if (is_included (fm_cur) && is_subsetted (fm_cur)) {
+        make_subset_tag (fm_cur, t1_glyph_names);
+        update_subset_tag ();
     }
-    if (is_included(fm_cur) && is_subsetted(fm_cur)) {
-        make_subset_tag(fm_cur, t1_glyph_names);
-        update_subset_tag();
-    }
-    if (pdfmovechars == 0 && t1_encoding == ENC_STANDARD)
-        t1_puts("/Encoding StandardEncoding def\n");
+    if (t1_encoding == ENC_STANDARD)
+        t1_puts ("/Encoding StandardEncoding def\n");
     else {
-        t1_puts("/Encoding 256 array\n0 1 255 {1 index exch /.notdef put} for\n");
-        for (i = 0, j = 0; i <= MAX_CHAR_CODE; i++) {
-            if (is_used_char(i) && t1_glyph_names[i] != notdef) {
+        t1_puts
+            ("/Encoding 256 array\n0 1 255 {1 index exch /.notdef put} for\n");
+        for (i = 0, j = 0; i < 256; i++) {
+            if (is_used_char (i) && t1_glyph_names[i] != notdef) {
                 j++;
-                t1_printf("dup %i /%s put\n", (int)t1_char(i), t1_glyph_names[i]);
+                t1_printf ("dup %i /%s put\n", (int) t1_char (i),
+                           t1_glyph_names[i]);
             }
         }
         /* We didn't mark anything for the Encoding array. */
         /* We add "dup 0 /.notdef put" for compatibility   */
         /* with Acrobat 5.0.                               */
         if (j == 0)
-            t1_puts("dup 0 /.notdef put\n");
-        t1_puts("readonly def\n");
+            t1_puts ("dup 0 /.notdef put\n");
+        t1_puts ("readonly def\n");
     }
     do {
-        t1_getline();
-        t1_scan_param();
-        if (!t1_prefix("/UniqueID")) /* ignore UniqueID for subsetted fonts */
-            t1_putline();
-    } while (t1_in_eexec == 0);
+        t1_getline ();
+        t1_scan_param ();
+        if (!t1_prefix ("/UniqueID"))   /* ignore UniqueID for subsetted fonts */
+            t1_putline ();
+    }
+    while (t1_in_eexec == 0);
 }
 
 #define t1_subr_flush()  t1_flush_cs(true)
 #define t1_cs_flush()    t1_flush_cs(false)
 
-static void t1_flush_cs(boolean);
+static void t1_flush_cs (boolean);
 
-static void cs_init(void)
+static void cs_init (void)
 {
     cs_ptr = cs_tab = NULL;
-    cs_dict_start =  cs_dict_end = NULL;
+    cs_dict_start = cs_dict_end = NULL;
     cs_count = cs_size = cs_size_pos = 0;
     cs_token_pair = NULL;
     subr_tab = NULL;
@@ -1440,7 +1465,7 @@
     subr_max = subr_size = subr_size_pos = 0;
 }
 
-static void init_cs_entry(cs_entry *cs)
+static void init_cs_entry (cs_entry * cs)
 {
     cs->data = NULL;
     cs->name = NULL;
@@ -1450,39 +1475,39 @@
     cs->valid = false;
 }
 
-static void t1_mark_glyphs(void);
+static void t1_mark_glyphs (void);
 
-static void t1_read_subrs(void)
+static void t1_read_subrs (void)
 {
     int i, s;
     cs_entry *ptr;
-    t1_getline();
-    while (!(t1_charstrings() || t1_subrs())) {
-        t1_scan_param(); 
-        t1_putline();
-        t1_getline();
+    t1_getline ();
+    while (!(t1_charstrings () || t1_subrs ())) {
+        t1_scan_param ();
+        t1_putline ();
+        t1_getline ();
     }
-found:
+  found:
     t1_cs = true;
     t1_scan = false;
-    if (!t1_subrs())
-       return;
-    subr_size_pos = strlen("/Subrs") + 1; 
+    if (!t1_subrs ())
+        return;
+    subr_size_pos = strlen ("/Subrs") + 1;
     /* subr_size_pos points to the number indicating dict size after "/Subrs" */
-    subr_size = t1_scan_num(t1_line_array + subr_size_pos, 0);
+    subr_size = t1_scan_num (t1_line_array + subr_size_pos, 0);
     if (subr_size == 0) {
-        while (!t1_charstrings())
-            t1_getline();
+        while (!t1_charstrings ())
+            t1_getline ();
         return;
     }
-    subr_tab = xtalloc(subr_size, cs_entry);
+    subr_tab = xtalloc (subr_size, cs_entry);
     for (ptr = subr_tab; ptr - subr_tab < subr_size; ptr++)
-        init_cs_entry(ptr);
-    subr_array_start = xstrdup(t1_line_array);
-    t1_getline();
+        init_cs_entry (ptr);
+    subr_array_start = xstrdup (t1_line_array);
+    t1_getline ();
     while (t1_cslen) {
-        store_subr();
-        t1_getline();
+        store_subr ();
+        t1_getline ();
     }
     /* mark the first four entries without parsing */
     for (i = 0; i < subr_size && i < 4; i++)
@@ -1498,32 +1523,32 @@
     s = 0;
     *t1_buf_array = 0;
     for (i = 0; i < POST_SUBRS_SCAN; i++) {
-        if (t1_charstrings())
-               break;
+        if (t1_charstrings ())
+            break;
         s += t1_line_ptr - t1_line_array;
-        alloc_array(t1_buf, s, T1_BUF_SIZE);
-        strcat(t1_buf_array, t1_line_array);
-        t1_getline();
+        alloc_array (t1_buf, s, T1_BUF_SIZE);
+        strcat (t1_buf_array, t1_line_array);
+        t1_getline ();
     }
-    subr_array_end = xstrdup(t1_buf_array);
-    if (i == POST_SUBRS_SCAN) { /* CharStrings not found; 
+    subr_array_end = xstrdup (t1_buf_array);
+    if (i == POST_SUBRS_SCAN) { /* CharStrings not found;
                                    suppose synthetic font */
         for (ptr = subr_tab; ptr - subr_tab < subr_size; ptr++)
             if (ptr->valid)
-                xfree(ptr->data);
-        xfree(subr_tab);
-        xfree(subr_array_start);
-        xfree(subr_array_end);
-        cs_init();
+                xfree (ptr->data);
+        xfree (subr_tab);
+        xfree (subr_array_start);
+        xfree (subr_array_end);
+        cs_init ();
         t1_cs = false;
         t1_synthetic = true;
-        while (!(t1_charstrings() || t1_subrs()))
-            t1_getline();
+        while (!(t1_charstrings () || t1_subrs ()))
+            t1_getline ();
         goto found;
     }
 }
 
-static void t1_flush_cs(boolean is_subr)
+static void t1_flush_cs (boolean is_subr)
 {
     char *p;
     byte *r, *return_cs = NULL;
@@ -1538,36 +1563,34 @@
         tab = subr_tab;
         count = subr_max + 1;
         end_tab = subr_tab + count;
-    }
-    else {
+    } else {
         start_line = cs_dict_start;
         line_end = cs_dict_end;
         size_pos = cs_size_pos;
-        tab =  cs_tab;
+        tab = cs_tab;
         end_tab = cs_ptr;
         count = cs_count;
     }
     t1_line_ptr = t1_line_array;
     for (p = start_line; p - start_line < size_pos;)
         *t1_line_ptr++ = *p++;
-    while (isdigit(*p))
+    while (isdigit (*p))
         p++;
-    sprintf(t1_line_ptr, "%u", count);
-    strcat(t1_line_ptr, p);
-    t1_line_ptr = eol(t1_line_array);
-    t1_putline();
+    sprintf (t1_line_ptr, "%u", count);
+    strcat (t1_line_ptr, p);
+    t1_line_ptr = eol (t1_line_array);
+    t1_putline ();
 
     /* create return_cs to replace unsused subr's */
     if (is_subr) {
         cr = 4330;
         cs_len = 0;
-        return_cs = xtalloc(t1_lenIV + 1, byte);
+        return_cs = xtalloc (t1_lenIV + 1, byte);
         if (t1_lenIV > 0) {
             for (cs_len = 0, r = return_cs; cs_len < t1_lenIV; cs_len++, r++)
-                *r = cencrypt(0x00, &cr);
-            *r = cencrypt(CS_RETURN, &cr);
-        }
-        else {
+                *r = cencrypt (0x00, &cr);
+            *r = cencrypt (CS_RETURN, &cr);
+        } else {
             *return_cs = CS_RETURN;
         }
         cs_len++;
@@ -1576,49 +1599,48 @@
     for (ptr = tab; ptr < end_tab; ptr++) {
         if (ptr->used) {
             if (is_subr)
-                sprintf(t1_line_array, "dup %u %u", ptr - tab, ptr->cslen);
+                sprintf (t1_line_array, "dup %u %u", ptr - tab, ptr->cslen);
             else
-                sprintf(t1_line_array, "/%s %u", ptr->name, ptr->cslen);
-            p = strend(t1_line_array);
-            memcpy(p, ptr->data, ptr->len);
+                sprintf (t1_line_array, "/%s %u", ptr->name, ptr->cslen);
+            p = strend (t1_line_array);
+            memcpy (p, ptr->data, ptr->len);
             t1_line_ptr = p + ptr->len;
-            t1_putline();
-        }
-        else {
+            t1_putline ();
+        } else {
             /* replace unsused subr's by return_cs */
             if (is_subr) {
-                sprintf(t1_line_array, "dup %u %u%s ", ptr - tab, cs_len,
-                        cs_token_pair[0]);
-                p = strend(t1_line_array);
-                memcpy(p, return_cs, cs_len);
+                sprintf (t1_line_array, "dup %u %u%s ", ptr - tab, cs_len,
+                         cs_token_pair[0]);
+                p = strend (t1_line_array);
+                memcpy (p, return_cs, cs_len);
                 t1_line_ptr = p + cs_len;
-                t1_putline();
-                sprintf(t1_line_array, " %s", cs_token_pair[1]);
-                t1_line_ptr = eol(t1_line_array);
-                t1_putline();
+                t1_putline ();
+                sprintf (t1_line_array, " %s", cs_token_pair[1]);
+                t1_line_ptr = eol (t1_line_array);
+                t1_putline ();
             }
         }
-        xfree(ptr->data);
+        xfree (ptr->data);
         if (ptr->name != notdef)
-            xfree(ptr->name);
+            xfree (ptr->name);
     }
-    sprintf(t1_line_array, "%s", line_end);
-    t1_line_ptr = eol(t1_line_array);
-    t1_putline();
+    sprintf (t1_line_array, "%s", line_end);
+    t1_line_ptr = eol (t1_line_array);
+    t1_putline ();
     if (is_subr)
-        xfree(return_cs);
-    xfree(tab);
-    xfree(start_line);
-    xfree(line_end);
+        xfree (return_cs);
+    xfree (tab);
+    xfree (start_line);
+    xfree (line_end);
 }
 
-static void t1_mark_glyphs(void)
+static void t1_mark_glyphs (void)
 {
     int i;
-    char *charset = extra_charset();
+    char *charset = extra_charset ();
     char *g, *s, *r;
     cs_entry *ptr;
-    if (t1_synthetic || embed_all_glyphs(tex_font)) { /* mark everything */
+    if (t1_synthetic || embed_all_glyphs (tex_font)) {  /* mark everything */
         if (cs_tab != NULL)
             for (ptr = cs_tab; ptr < cs_ptr; ptr++)
                 if (ptr->valid)
@@ -1631,165 +1653,170 @@
         }
         return;
     }
-    mark_cs(notdef);
-    for (i = 0; i <= MAX_CHAR_CODE; i++)
-        if (is_used_char(i)) {
+    mark_cs (notdef);
+    for (i = 0; i < 256; i++)
+        if (is_used_char (i)) {
             if (t1_glyph_names[i] == notdef)
-                pdftex_warn("character %i is mapped to %s", i, notdef);
+                pdftex_warn ("character %i is mapped to %s", i, notdef);
             else
-                mark_cs(t1_glyph_names[i]);
+                mark_cs (t1_glyph_names[i]);
         }
     if (charset == NULL)
         goto set_subr_max;
-    g = s = charset + 1; /* skip the first '/' */
-    r = strend(g);
+    g = s = charset + 1;        /* skip the first '/' */
+    r = strend (g);
     while (g < r) {
         while (*s != '/' && s < r)
             s++;
-        *s = 0; /* terminate g by rewriting '/' to 0 */
-        mark_cs(g);
+        *s = 0;                 /* terminate g by rewriting '/' to 0 */
+        mark_cs (g);
         g = s + 1;
     }
-set_subr_max:
+  set_subr_max:
     if (subr_tab != NULL)
         for (subr_max = -1, ptr = subr_tab; ptr - subr_tab < subr_size; ptr++)
             if (ptr->used && ptr - subr_tab > subr_max)
                 subr_max = ptr - subr_tab;
 }
 
-static void t1_subset_charstrings(void)
+static void t1_subset_charstrings (void)
 {
     cs_entry *ptr;
-    cs_size_pos = strstr(t1_line_array, charstringname) + strlen(charstringname)
-                  - t1_line_array + 1; 
+    cs_size_pos =
+        strstr (t1_line_array, charstringname) + strlen (charstringname)
+        - t1_line_array + 1;
     /* cs_size_pos points to the number indicating
        dict size after "/CharStrings" */
-    cs_size = t1_scan_num(t1_line_array + cs_size_pos, 0);
-    cs_ptr = cs_tab = xtalloc(cs_size, cs_entry);
+    cs_size = t1_scan_num (t1_line_array + cs_size_pos, 0);
+    cs_ptr = cs_tab = xtalloc (cs_size, cs_entry);
     for (ptr = cs_tab; ptr - cs_tab < cs_size; ptr++)
-        init_cs_entry(ptr);
+        init_cs_entry (ptr);
     cs_notdef = NULL;
-    cs_dict_start = xstrdup(t1_line_array);
-    t1_getline();
+    cs_dict_start = xstrdup (t1_line_array);
+    t1_getline ();
     while (t1_cslen) {
-        store_cs();
-        t1_getline();
+        store_cs ();
+        t1_getline ();
     }
-    cs_dict_end = xstrdup(t1_line_array);
-    t1_mark_glyphs();
+    cs_dict_end = xstrdup (t1_line_array);
+    t1_mark_glyphs ();
     if (subr_tab != NULL) {
         if (cs_token_pair == NULL)
-            pdftex_fail("This Type 1 font uses mismatched subroutine begin/end token pairs.");
-        t1_subr_flush();
+            pdftex_fail
+                ("This Type 1 font uses mismatched subroutine begin/end token pairs.");
+        t1_subr_flush ();
     }
     for (cs_count = 0, ptr = cs_tab; ptr < cs_ptr; ptr++)
         if (ptr->used)
             cs_count++;
-    t1_cs_flush();
+    t1_cs_flush ();
 }
 
-static void t1_subset_end(void)
+static void t1_subset_end (void)
 {
-    if (t1_synthetic) { /* copy to "dup /FontName get exch definefont pop" */
-        while (!strstr(t1_line_array, "definefont")) {
-            t1_getline();
-            t1_putline();
+    if (t1_synthetic) {         /* copy to "dup /FontName get exch definefont pop" */
+        while (!strstr (t1_line_array, "definefont")) {
+            t1_getline ();
+            t1_putline ();
         }
-        while (!t1_end_eexec())
-            t1_getline();   /* ignore the rest */
-        t1_putline();       /* write "mark currentfile closefile" */
+        while (!t1_end_eexec ())
+            t1_getline ();      /* ignore the rest */
+        t1_putline ();          /* write "mark currentfile closefile" */
+    } else
+        while (!t1_end_eexec ()) {      /* copy to "mark currentfile closefile" */
+            t1_getline ();
+            t1_putline ();
+        }
+    t1_stop_eexec ();
+    if (fixedcontent) {         /* copy 512 zeros (not needed for PDF) */
+        while (!t1_cleartomark ()) {
+            t1_getline ();
+            t1_putline ();
+        }
+        if (!t1_synthetic)      /* don't check "{restore}if" for synthetic fonts */
+            t1_check_end ();    /* write "{restore}if" if found */
     }
-    else while (!t1_end_eexec()) { /* copy to "mark currentfile closefile" */
-        t1_getline();
-        t1_putline();
-    }
-    t1_stop_eexec();
-    while (!t1_cleartomark()) {
-        t1_getline();
-        t1_putline();
-    }
-    if (!t1_synthetic)  /* don't check "{restore}if" for synthetic fonts */
-        t1_check_end(); /* write "{restore}if" if found */
-    get_length3();
+    get_length3 ();
 }
 
-void writet1(void)
+void writet1 (void)
 {
     read_encoding_only = false;
 #ifdef pdfTeX
-    if (strcasecmp(strend(fm_fontfile(fm_cur)) - 4, ".otf") == 0) {
-        if (!is_included(fm_cur) || is_subsetted(fm_cur))
-            pdftex_fail("OTF fonts must be included entirely");
-        writeotf();
+    t1_save_offset = 0;
+    if (strcasecmp (strend (fm_fontfile (fm_cur)) - 4, ".otf") == 0) {
+        if (!is_included (fm_cur) || is_subsetted (fm_cur))
+            pdftex_fail ("OTF fonts must be included entirely");
+        writeotf ();
         is_otf_font = true;
         return;
     }
 #endif
-    if (!is_included(fm_cur)) { /* scan parameters from font file */
-        if (!t1_open_fontfile("{"))
+    if (!is_included (fm_cur)) {        /* scan parameters from font file */
+        if (!t1_open_fontfile ("{"))
             return;
-        t1_scan_only();
-        t1_close_font_file("}");
+        t1_scan_only ();
+        t1_close_font_file ("}");
         return;
     }
-    if (!is_subsetted(fm_cur)) { /* include entire font */
-        if (!t1_open_fontfile("<<"))
+    if (!is_subsetted (fm_cur)) {       /* include entire font */
+        if (!t1_open_fontfile ("<<"))
             return;
-        t1_include();
-        t1_close_font_file(">>");
+        t1_include ();
+        t1_close_font_file (">>");
         return;
-    } 
+    }
     /* partial downloading */
-    if (!t1_open_fontfile("<"))
+    if (!t1_open_fontfile ("<"))
         return;
-    t1_subset_ascii_part();
-    t1_start_eexec();
-    cc_init();
-    cs_init();
-    t1_read_subrs();
-    t1_subset_charstrings();
-    t1_subset_end();
-    t1_close_font_file(">");
+    t1_subset_ascii_part ();
+    t1_start_eexec ();
+    cc_init ();
+    cs_init ();
+    t1_read_subrs ();
+    t1_subset_charstrings ();
+    t1_subset_end ();
+    t1_close_font_file (">");
 }
 
-void t1_free()
+void t1_free ()
 {
-    xfree(t1_line_array);
-    xfree(t1_buf_array);
+    xfree (t1_line_array);
+    xfree (t1_buf_array);
 }
 
 #ifndef pdfTeX
-boolean t1_subset(char *fontfile, char *encfile, unsigned char *g)
+boolean t1_subset (char *fontfile, char *encfile, unsigned char *g)
 {
     int i;
     cur_enc_name = encfile;
-    for (i = 0; i <= MAX_CHAR_CODE; i++)
-        ext_glyph_names[i] = (char*) notdef;
+    for (i = 0; i < 256; i++)
+        ext_glyph_names[i] = (char *) notdef;
     if (cur_enc_name != NULL)
-        load_enc(cur_enc_name, ext_glyph_names);
+        load_enc (cur_enc_name, ext_glyph_names);
     grid = g;
     cur_file_name = fontfile;
     hexline_length = 0;
-    writet1();
-    for (i = 0; i <= MAX_CHAR_CODE; i++)
+    writet1 ();
+    for (i = 0; i < 256; i++)
         if (ext_glyph_names[i] != notdef)
-            free(ext_glyph_names[i]);
-    return 1 ; /* note:  there *is* no unsuccessful return */
+            free (ext_glyph_names[i]);
+    return 1;                   /* note:  there *is* no unsuccessful return */
 }
 
-boolean t1_subset_2(char *fontfile, unsigned char *g, char *extraGlyphs)
+boolean t1_subset_2 (char *fontfile, unsigned char *g, char *extraGlyphs)
 {
     int i;
-    for (i = 0; i <= MAX_CHAR_CODE; i++)
-        ext_glyph_names[i] = (char*) notdef;
+    for (i = 0; i < 256; i++)
+        ext_glyph_names[i] = (char *) notdef;
     grid = g;
     cur_file_name = fontfile;
     hexline_length = 0;
-    dvips_extra_charset = extraGlyphs ;
-    writet1();
-    for (i = 0; i <= MAX_CHAR_CODE; i++)
+    dvips_extra_charset = extraGlyphs;
+    writet1 ();
+    for (i = 0; i < 256; i++)
         if (ext_glyph_names[i] != notdef)
-            free(ext_glyph_names[i]);
-    return 1 ; /* note:  there *is* no unsuccessful return */
+            free (ext_glyph_names[i]);
+    return 1;                   /* note:  there *is* no unsuccessful return */
 }
-#endif /* not pdfTeX */
+#endif                          /* not pdfTeX */

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writet3.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writet3.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writet3.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,27 +17,28 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writet3.c#9 $
+$Id: writet3.c,v 1.10 2005/12/26 14:26:18 hahe Exp hahe $
 */
 
 #include "ptexlib.h"
 #include <kpathsea/tex-glyph.h>
 #include <kpathsea/magstep.h>
+#include <string.h>
 
 #define T3_BUF_SIZE   1024
 
-static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writet3.c#9 $";
+static const char perforce_id[] =
+    "$Id: writet3.c,v 1.10 2005/12/26 14:26:18 hahe Exp hahe $";
 
 /* define t3_line_ptr, t3_line_array & t3_line_limit */
 typedef char t3_line_entry;
-define_array(t3_line);   
+define_array (t3_line);
 
 FILE *t3_file;
 static boolean t3_image_used;
 
-static integer t3_char_procs[MAX_CHAR_CODE + 1];
-static float t3_char_widths[MAX_CHAR_CODE + 1];
+static integer t3_char_procs[256];
+static float t3_char_widths[256];
 static int t3_glyph_num;
 static float t3_font_scale;
 static integer t3_b0, t3_b1, t3_b2, t3_b3;
@@ -55,43 +56,43 @@
     if (t3_eof())                                          \
         pdftex_fail("unexpected end of file");
 
-static void t3_getline(void) 
+static void t3_getline (void)
 {
     int c;
-restart:
+  restart:
     t3_line_ptr = t3_line_array;
-    c = t3_getchar();
-    while (!t3_eof()) {
-        alloc_array(t3_line, 1, T3_BUF_SIZE);
-        append_char_to_buf(c, t3_line_ptr, t3_line_array, t3_line_limit);
+    c = t3_getchar ();
+    while (!t3_eof ()) {
+        alloc_array (t3_line, 1, T3_BUF_SIZE);
+        append_char_to_buf (c, t3_line_ptr, t3_line_array, t3_line_limit);
         if (c == 10)
             break;
-        c = t3_getchar();
+        c = t3_getchar ();
     }
-    alloc_array(t3_line, 2, T3_BUF_SIZE);
-    append_eol(t3_line_ptr, t3_line_array, T3_BUF_SIZE);
+    alloc_array (t3_line, 2, T3_BUF_SIZE);
+    append_eol (t3_line_ptr, t3_line_array, T3_BUF_SIZE);
     if (t3_line_ptr - t3_line_array < 2 || *t3_line_array == '%') {
-        if (!t3_eof())
+        if (!t3_eof ())
             goto restart;
     }
 }
 
-static void t3_putline(void)
+static void t3_putline (void)
 {
     char *p = t3_line_array;
     while (p < t3_line_ptr)
-        t3_putchar(*p++);
+        t3_putchar (*p++);
 }
 
-static void update_bbox(integer llx, integer lly, integer urx, integer ury, boolean is_first_glyph)
+static void update_bbox (integer llx, integer lly, integer urx, integer ury,
+                         boolean is_first_glyph)
 {
     if (is_first_glyph) {
         t3_b0 = llx;
         t3_b1 = lly;
         t3_b2 = urx;
         t3_b3 = ury;
-    }
-    else {
+    } else {
         if (llx < t3_b0)
             t3_b0 = llx;
         if (lly < t3_b1)
@@ -103,82 +104,80 @@
     }
 }
 
-static void t3_write_glyph(internalfontnumber f)
+static void t3_write_glyph (internalfontnumber f)
 {
     static char t3_begin_glyph_str[] = "\\pdfglyph";
     static char t3_end_glyph_str[] = "\\endglyph";
     int glyph_index;
     int width, height, depth, llx, lly, urx, ury;
     char *p;
-    t3_getline();
-    if (t3_prefix(t3_begin_glyph_str)) {
-        if (sscanf(t3_line_array + strlen(t3_begin_glyph_str) + 1,
-                   "%i %i %i %i %i %i %i %i =", &glyph_index,
-                   &width, &height, &depth, &llx, &lly, &urx, &ury) != 8) {
-            remove_eol(p, t3_line_array);
-            pdftex_warn("invalid glyph preamble: `%s'", t3_line_array);
+    t3_getline ();
+    if (t3_prefix (t3_begin_glyph_str)) {
+        if (sscanf (t3_line_array + strlen (t3_begin_glyph_str) + 1,
+                    "%i %i %i %i %i %i %i %i =", &glyph_index,
+                    &width, &height, &depth, &llx, &lly, &urx, &ury) != 8) {
+            remove_eol (p, t3_line_array);
+            pdftex_warn ("invalid glyph preamble: `%s'", t3_line_array);
             return;
         }
         if (glyph_index < fontbc[f] || glyph_index > fontec[f])
             return;
-    }
-    else
+    } else
         return;
-    if (!pdfcharmarked(f, glyph_index)) {
-        while (!t3_prefix(t3_end_glyph_str)) {
-            t3_check_eof();
-            t3_getline();
+    if (!pdfcharmarked (f, glyph_index)) {
+        while (!t3_prefix (t3_end_glyph_str)) {
+            t3_check_eof ();
+            t3_getline ();
         }
         return;
     }
-    update_bbox(llx, lly, urx, ury, t3_glyph_num == 0);
+    update_bbox (llx, lly, urx, ury, t3_glyph_num == 0);
     t3_glyph_num++;
-    pdfnewdict(0, 0);
+    pdfnewdict (0, 0, 0);
     t3_char_procs[glyph_index] = objptr;
-    if (width == 0) 
-        t3_char_widths[glyph_index] = 
-            (getcharwidth(f, glyph_index)/t3_font_scale) / pdffontsize[f];
+    if (width == 0)
+        t3_char_widths[glyph_index] =
+            (getcharwidth (f, glyph_index) / t3_font_scale) / pdffontsize[f];
     else
         t3_char_widths[glyph_index] = width;
-    pdfbeginstream();
-    t3_getline();
-    pdf_printf("%i 0 %i %i %i %i d1\nq\n", 
-               (int)t3_char_widths[glyph_index], (int)llx,
-               (int)lly, (int)urx, (int)ury);
-    while (!t3_prefix(t3_end_glyph_str)) {
-        t3_check_eof();
-        if (t3_prefix("BI"))
+    pdfbeginstream ();
+    t3_getline ();
+    pdf_printf ("%i 0 %i %i %i %i d1\nq\n",
+                (int) t3_char_widths[glyph_index], (int) llx,
+                (int) lly, (int) urx, (int) ury);
+    while (!t3_prefix (t3_end_glyph_str)) {
+        t3_check_eof ();
+        if (t3_prefix ("BI"))
             t3_image_used = true;
-        t3_putline();
-        t3_getline();
+        t3_putline ();
+        t3_getline ();
     }
-    pdf_puts("Q\n");
-    pdfendstream();
+    pdf_puts ("Q\n");
+    pdfendstream ();
 }
 
-static integer get_pk_font_scale(internalfontnumber f)
+static integer get_pk_font_scale (internalfontnumber f)
 {
-    return 
-        dividescaled(pkscalefactor, 
-            dividescaled(pdffontsize[f], onehundredbp, fixeddecimaldigits + 2),
-            0);
+    return
+        dividescaled (pkscalefactor,
+                      dividescaled (pdffontsize[f], onehundredbp,
+                                    fixeddecimaldigits + 2), 0);
 }
 
-static integer pk_char_width(internalfontnumber f, scaled w)
+static integer pk_char_width (internalfontnumber f, scaled w)
 {
-    return 
-        dividescaled(dividescaled(w, pdffontsize[f], 7),
-                     get_pk_font_scale(f), 0);
+    return
+        dividescaled (dividescaled (w, pdffontsize[f], 7),
+                      get_pk_font_scale (f), 0);
 }
 
-scaled getpkcharwidth(internalfontnumber f, scaled w)
+scaled getpkcharwidth (internalfontnumber f, scaled w)
 {
-    return (get_pk_font_scale(f)/100000.0)*
-           (pk_char_width(f, w)/100.0)*
-           pdffontsize[f];
+    return (get_pk_font_scale (f) / 100000.0) *
+        (pk_char_width (f, w) / 100.0) * pdffontsize[f];
 }
 
-static boolean writepk(internalfontnumber f)
+static boolean writepk (internalfontnumber f)
 {
     kpse_glyph_file_type font_ret;
     integer llx, lly, urx, ury;
@@ -188,202 +187,201 @@
     chardesc cd;
     boolean is_null_glyph, check_preamble;
     integer dpi;
-    int e;
-    dpi = kpse_magstep_fix(
-             round(fixedpkresolution*(((float)pdffontsize[f])/fontdsize[f])),
-             fixedpkresolution, NULL);
-    cur_file_name = makecstring(fontname[f]);
-    name = kpse_find_pk(cur_file_name, (unsigned)dpi, &font_ret);
+    dpi =
+        kpse_magstep_fix (round
+                          (fixedpkresolution *
+                           (((float) pdffontsize[f]) / fontdsize[f])),
+                          fixedpkresolution, NULL);
+    cur_file_name = makecstring (fontname[f]);
+    name = kpse_find_pk (cur_file_name, (unsigned) dpi, &font_ret);
     if (name == NULL ||
-        !FILESTRCASEEQ(cur_file_name, font_ret.name) ||
-        !kpse_bitmap_tolerance((float)font_ret.dpi, (float)dpi)) {
-        pdftex_warn("Font %s at %i not found", cur_file_name, (int)dpi);
+        !FILESTRCASEEQ (cur_file_name, font_ret.name) ||
+        !kpse_bitmap_tolerance ((float) font_ret.dpi, (float) dpi)) {
+        pdftex_warn ("Font %s at %i not found", cur_file_name, (int) dpi);
         cur_file_name = NULL;
         return false;
     }
-    t3_file = xfopen(name, FOPEN_RBIN_MODE);
+    t3_file = xfopen (name, FOPEN_RBIN_MODE);
     t3_image_used = true;
     is_pk_font = true;
-    tex_printf(" <%s", (char *)name);
+    tex_printf (" <%s", (char *) name);
     cd.rastersize = 256;
-    cd.raster = xtalloc(cd.rastersize, halfword);
+    cd.raster = xtalloc (cd.rastersize, halfword);
     check_preamble = true;
-    while (readchar(check_preamble, &cd) != 0) {
+    while (readchar (check_preamble, &cd) != 0) {
         check_preamble = false;
-        if (!pdfcharmarked(f, cd.charcode))
+        if (!pdfcharmarked (f, cd.charcode))
             continue;
-        t3_char_widths[cd.charcode] = 
-            pk_char_width(f, getcharwidth(f, cd.charcode));
+        t3_char_widths[cd.charcode] =
+            pk_char_width (f, getcharwidth (f, cd.charcode));
         if (cd.cwidth < 1 || cd.cheight < 1) {
-            cd.xescape = cd.cwidth = round(t3_char_widths[cd.charcode]/100.0);
+            cd.xescape = cd.cwidth =
+                round (t3_char_widths[cd.charcode] / 100.0);
             cd.cheight = 1;
             cd.xoff = 0;
             cd.yoff = 0;
             is_null_glyph = true;
-        }
-        else
+        } else
             is_null_glyph = false;
         llx = -cd.xoff;
         lly = cd.yoff - cd.cheight + 1;
         urx = cd.cwidth + llx + 1;
         ury = cd.cheight + lly;
-        update_bbox(llx, lly, urx, ury, t3_glyph_num == 0);
+        update_bbox (llx, lly, urx, ury, t3_glyph_num == 0);
         t3_glyph_num++;
-        pdfnewdict(0, 0);
+        pdfnewdict (0, 0, 0);
         t3_char_procs[cd.charcode] = objptr;
-        pdfbeginstream();
-        pdfprintreal(t3_char_widths[cd.charcode], 2);
-        pdf_printf(" 0 %i %i %i %i d1\n", 
-                    (int)llx, (int)lly, (int)urx, (int)ury);
+        pdfbeginstream ();
+        pdfprintreal (t3_char_widths[cd.charcode], 2);
+        pdf_printf (" 0 %i %i %i %i d1\n",
+                    (int) llx, (int) lly, (int) urx, (int) ury);
         if (is_null_glyph)
             goto end_stream;
-        pdf_printf("q\n%i 0 0 %i %i %i cm\nBI\n", (int)cd.cwidth,
-                   (int)cd.cheight, (int)llx, (int)lly);
-        pdf_printf("/W %i\n/H %i\n", 
-                   (int)cd.cwidth, (int)cd.cheight);
-        pdf_puts("/IM true\n/BPC 1\n/D [1 0]\nID ");
-        cw = (cd.cwidth + 7)/8;
-        rw = (cd.cwidth + 15)/16;
+        pdf_printf ("q\n%i 0 0 %i %i %i cm\nBI\n", (int) cd.cwidth,
+                    (int) cd.cheight, (int) llx, (int) lly);
+        pdf_printf ("/W %i\n/H %i\n", (int) cd.cwidth, (int) cd.cheight);
+        pdf_puts ("/IM true\n/BPC 1\n/D [1 0]\nID ");
+        cw = (cd.cwidth + 7) / 8;
+        rw = (cd.cwidth + 15) / 16;
         row = cd.raster;
         for (i = 0; i < cd.cheight; i++) {
             for (j = 0; j < rw - 1; j++) {
-                pdfout(*row/256);
-                pdfout(*row%256);
+                pdfout (*row / 256);
+                pdfout (*row % 256);
                 row++;
             }
-            pdfout(*row/256);
-            if (2*rw == cw)
-                pdfout(*row%256);
+            pdfout (*row / 256);
+            if (2 * rw == cw)
+                pdfout (*row % 256);
             row++;
         }
-        pdf_puts("\nEI\nQ\n");
-end_stream:
-        pdfendstream();
+        pdf_puts ("\nEI\nQ\n");
+      end_stream:
+        pdfendstream ();
     }
-    xfree(cd.raster);
+    xfree (cd.raster);
     cur_file_name = NULL;
     return true;
 }
 
-void writet3(int objnum, internalfontnumber f)
+void writet3 (int objnum, internalfontnumber f)
 {
     static char t3_font_scale_str[] = "\\pdffontscale";
-    int i, e;
+    int i;
+    integer wptr, eptr, cptr;
     int first_char, last_char;
     integer pk_font_scale;
     boolean is_notdef;
     t3_glyph_num = 0;
     t3_image_used = false;
-    for (i = 0; i <= MAX_CHAR_CODE; i++) {
+    for (i = 0; i < 256; i++) {
         t3_char_procs[i] = 0;
         t3_char_widths[i] = 0;
     }
-    packfilename(fontname[f], getnullstr(), maketexstring(".pgc"));
-    cur_file_name = makecstring(makenamestring());
+    packfilename (fontname[f], getnullstr (), maketexstring (".pgc"));
+    cur_file_name = makecstring (makenamestring ());
     is_pk_font = false;
-    if (!t3_open()) {
-        if (writepk(f))
+    if (!t3_open ()) {
+        if (writepk (f))
             goto write_font_dict;
         else {
             cur_file_name = NULL;
             return;
         }
     }
-    tex_printf("<%s", nameoffile + 1);
-    t3_getline();
-    if (!t3_prefix(t3_font_scale_str) ||
-        sscanf(t3_line_array + strlen(t3_font_scale_str) + 1, "%g", &t3_font_scale) < 1 ||
-        t3_font_scale <= 0 || t3_font_scale > 1000 ) {
-        pdftex_warn("missing or invalid font scale");
-        t3_close();
+    tex_printf ("<%s", nameoffile + 1);
+    t3_getline ();
+    if (!t3_prefix (t3_font_scale_str) ||
+        sscanf (t3_line_array + strlen (t3_font_scale_str) + 1, "%g",
+                &t3_font_scale) < 1 || t3_font_scale <= 0
+        || t3_font_scale > 1000) {
+        pdftex_warn ("missing or invalid font scale");
+        t3_close ();
         cur_file_name = NULL;
         return;
     }
-    while (!t3_eof())
-        t3_write_glyph(f);
-write_font_dict:
+    while (!t3_eof ())
+        t3_write_glyph (f);
+  write_font_dict:
     for (i = fontbc[f]; i <= fontec[f]; i++)
-        if (pdfcharmarked(f, i))
+        if (pdfcharmarked (f, i))
             break;
     first_char = i;
     for (i = fontec[f]; i > first_char; i--)
-        if (pdfcharmarked(f, i))
+        if (pdfcharmarked (f, i))
             break;
     last_char = i;
-    pdfbegindict(objnum); /* Type 3 font dictionary */
-    pdf_puts("/Type /Font\n/Subtype /Type3\n");
-    pdf_printf("/Name /F%i\n", (int)f);
-    if (pdffontattr[f] != getnullstr()) {
-        pdfprint(pdffontattr[f]);
-        pdf_puts("\n");
+    pdfbegindict (objnum, 1);   /* Type 3 font dictionary */
+    pdf_puts ("/Type /Font\n/Subtype /Type3\n");
+    pdf_printf ("/Name /F%i\n", (int) f);
+    if (pdffontattr[f] != getnullstr ()) {
+        pdfprint (pdffontattr[f]);
+        pdf_puts ("\n");
     }
     if (is_pk_font) {
-        pk_font_scale = get_pk_font_scale(f);
-        pdf_puts("/FontMatrix [");
-        pdfprintreal(pk_font_scale, 5);
-        pdf_puts(" 0 0 ");
-        pdfprintreal(pk_font_scale, 5);
-        pdf_puts(" 0 0]\n") ;
-    }
-    else
-        pdf_printf("/FontMatrix [%g 0 0 %g 0 0]\n", 
-                   (double)t3_font_scale, (double)t3_font_scale);
-    pdf_printf("/%s [ %i %i %i %i ]\n", 
-               font_keys[FONTBBOX1_CODE].pdfname, 
-               (int)t3_b0, (int)t3_b1, 
-               (int)t3_b2, (int)t3_b3);
-    pdf_printf("/Resources << /ProcSet [ /PDF %s] >>\n", 
-               t3_image_used ? "/ImageB " : "");
-    pdf_printf("/FirstChar %i\n/LastChar %i\n", first_char, last_char);
-    pdf_printf("/Widths %i 0 R\n/Encoding %i 0 R\n/CharProcs %i 0 R\n", 
-               (int)(objptr + 1), (int)(objptr + 2),
-               (int)(objptr + 3));
-    pdfenddict();
-    pdfnewobj(0, 0); /* chars width array */
-    pdf_puts("[");
+        pk_font_scale = get_pk_font_scale (f);
+        pdf_puts ("/FontMatrix [");
+        pdfprintreal (pk_font_scale, 5);
+        pdf_puts (" 0 0 ");
+        pdfprintreal (pk_font_scale, 5);
+        pdf_puts (" 0 0]\n");
+    } else
+        pdf_printf ("/FontMatrix [%g 0 0 %g 0 0]\n",
+                    (double) t3_font_scale, (double) t3_font_scale);
+    pdf_printf ("/%s [ %i %i %i %i ]\n",
+                font_keys[FONTBBOX1_CODE].pdfname,
+                (int) t3_b0, (int) t3_b1, (int) t3_b2, (int) t3_b3);
+    pdf_printf ("/Resources << /ProcSet [ /PDF %s] >>\n",
+                t3_image_used ? "/ImageB " : "");
+    pdf_printf ("/FirstChar %i\n/LastChar %i\n", first_char, last_char);
+    wptr = pdfnewobjnum ();
+    eptr = pdfnewobjnum ();
+    cptr = pdfnewobjnum ();
+    pdf_printf ("/Widths %i 0 R\n/Encoding %i 0 R\n/CharProcs %i 0 R\n",
+                wptr, eptr, cptr);
+    pdfenddict ();
+    pdfbeginobj (wptr, 1);      /* chars width array */
+    pdf_puts ("[");
     if (is_pk_font)
         for (i = first_char; i <= last_char; i++) {
-            pdfprintreal(t3_char_widths[i], 2);
-            pdf_puts(" ");
-        }
-    else
+            pdfprintreal (t3_char_widths[i], 2);
+            pdf_puts (" ");
+    } else
         for (i = first_char; i <= last_char; i++)
-            pdf_printf("%i ", (int)t3_char_widths[i]);
-    pdf_puts("]\n");
-    pdfendobj();
-    pdfnewdict(0, 0); /* encoding dictionary */
-    pdf_printf("/Type /Encoding\n/Differences [%i", first_char);
+            pdf_printf ("%i ", (int) t3_char_widths[i]);
+    pdf_puts ("]\n");
+    pdfendobj ();
+    pdfbegindict (eptr, 1);     /* encoding dictionary */
+    pdf_printf ("/Type /Encoding\n/Differences [%i", first_char);
     if (t3_char_procs[first_char] == 0) {
-        pdf_printf("/%s", notdef);
+        pdf_printf ("/%s", notdef);
         is_notdef = true;
-    }
-    else {
-        pdf_printf("/a%i", first_char);
+    } else {
+        pdf_printf ("/a%i", first_char);
         is_notdef = false;
     }
     for (i = first_char + 1; i <= last_char; i++) {
         if (t3_char_procs[i] == 0) {
             if (!is_notdef) {
-                pdf_printf(" %i/%s", i, notdef);
+                pdf_printf (" %i/%s", i, notdef);
                 is_notdef = true;
             }
-        }
-        else {
+        } else {
             if (is_notdef) {
-                pdf_printf(" %i", i);
+                pdf_printf (" %i", i);
                 is_notdef = false;
             }
-            pdf_printf("/a%i", i);
+            pdf_printf ("/a%i", i);
         }
     }
-    pdf_puts("]\n");
-    pdfenddict();
-    pdfnewdict(0, 0); /* CharProcs dictionary */
+    pdf_puts ("]\n");
+    pdfenddict ();
+    pdfbegindict (cptr, 1);     /* CharProcs dictionary */
     for (i = first_char; i <= last_char; i++)
         if (t3_char_procs[i] != 0)
-            pdf_printf("/a%i %i 0 R\n", (int)i, (int)t3_char_procs[i]);
-    pdfenddict();
-    t3_close();
-    tex_printf(">");
+            pdf_printf ("/a%i %i 0 R\n", (int) i, (int) t3_char_procs[i]);
+    pdfenddict ();
+    t3_close ();
+    tex_printf (">");
     cur_file_name = NULL;
 }

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writettf.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writettf.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writettf.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 1996-2002 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2006 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -17,14 +17,15 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writettf.c#14 $
+$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writettf.c#16 $
 */
 
 #include "ptexlib.h"
 #include "writettf.h"
+#include <string.h>
 
-static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writettf.c#14 $";
+static const char perforce_id[] =
+    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writettf.c#16 $";
 
 #define DEFAULT_NTABS       14
 #define NEW_CMAP_SIZE       2
@@ -46,14 +47,16 @@
     TTF_LONG newoffset;
     TTF_UFWORD advWidth;
     TTF_FWORD lsb;
-    char *name;              /* name of glyph */
-    TTF_SHORT newindex;      /* new index of glyph in output file */
-    TTF_USHORT name_index;   /* index of name as read from font file */
+    char *name;                 /* name of glyph */
+    TTF_SHORT newindex;         /* new index of glyph in output file */
+    TTF_USHORT name_index;      /* index of name as read from font file */
 } glyph_entry;
 
 typedef struct {
-    char *name;             /* name of glyph */
-    short newindex;         /* new index of glyph in output file */
+    char *name;                 /* name of glyph */
+    long code;                  /* charcode in case of subfonts */
+    short newindex;             /* new index of glyph in output file */
+
 } ttfenc_entry;
 
 typedef struct {
@@ -67,6 +70,13 @@
     TTF_USHORT new_length;
 } name_record;
 
+typedef struct {
+    char *ttf_name;
+    TTF_USHORT pid;
+    TTF_USHORT eid;
+    short *table;
+} ttf_cmap_entry;
+
 static TTF_USHORT ntabs;
 static TTF_USHORT upem;
 static TTF_FIXED post_format;
@@ -91,16 +101,16 @@
 static TTF_ULONG tmp_ulong;
 static TTF_ULONG checkSumAdjustment_offset;
 static FILE *ttf_file;
-static ttfenc_entry ttfenc_tab[MAX_CHAR_CODE + 1];
+static ttfenc_entry ttfenc_tab[256];
 
-static TTF_USHORT unicode_map[0xFFFF];
+static struct avl_table *ttf_cmap_tree = NULL;
 
-
 integer ttf_length;
 
 #include "macnames.c"
 
 extern char *fb_array;
+extern char charsetstr[];
 
 static const char *newtabnames[] = {
     "OS/2",
@@ -119,8 +129,45 @@
     "prep"
 };
 
-static unsigned char ttf_addchksm(unsigned char b)
+ttf_cmap_entry *new_ttf_cmap_entry (void)
 {
+    ttf_cmap_entry *e;
+    e = xtalloc (1, ttf_cmap_entry);
+    e->ttf_name = NULL;
+    e->table = NULL;
+    return e;
+}
+
+static void destroy_ttf_cmap_entry (void *pa, void *pb)
+{
+    ttf_cmap_entry *p;
+    p = (ttf_cmap_entry *) pa;
+    xfree (p->ttf_name);
+    xfree (p->table);
+    xfree (p);
+}
+
+void ttf_free (void)
+{
+    if (ttf_cmap_tree != NULL)
+        avl_destroy (ttf_cmap_tree, destroy_ttf_cmap_entry);
+}
+
+static int comp_ttf_cmap_entry (const void *pa, const void *pb, void *p)
+{
+    const ttf_cmap_entry *p1 = (const ttf_cmap_entry *) pa,
+        *p2 = (const ttf_cmap_entry *) pb;
+    int i;
+    assert (p1->ttf_name != NULL && p2->ttf_name != NULL);
+    if ((i = strcmp (p1->ttf_name, p2->ttf_name)) != 0)
+        return i;
+    cmp_return (p1->pid, p2->pid);
+    cmp_return (p1->eid, p2->eid);
+    return 0;
+}
+
+static unsigned char ttf_addchksm (unsigned char b)
+{
     tmp_ulong = (tmp_ulong << 8) + b;
     tab_length++;
     if (tab_length % 4 == 0) {
@@ -130,14 +177,14 @@
     return b;
 }
 
-static TTF_ULONG ttf_getchksm(void)
+static TTF_ULONG ttf_getchksm (void)
 {
     while (tab_length % 4 != 0)
-        ttf_putchar(ttf_addchksm(0)); /* ttf_addchksm updates tab_length */
+        ttf_putchar (ttf_addchksm (0)); /* ttf_addchksm updates tab_length */
     return checksum;
 }
 
-static long ttf_putnum(int s, long n)
+static long ttf_putnum (int s, long n)
 {
     long i = n;
     char buf[TTF_LONG_SIZE + 1], *p = buf;
@@ -147,76 +194,107 @@
     }
     p--;
     while (p >= buf)
-        ttf_putchar(ttf_addchksm(*p--));
+        ttf_putchar (ttf_addchksm (*p--));
     return n;
 }
 
-static long ttf_getnum(int s)
+static long ttf_getnum (int s)
 {
     long i = 0;
     int c;
     while (s > 0) {
-        if ((c = ttf_getchar()) < 0)
-            pdftex_fail("unexpected EOF");
+        if ((c = ttf_getchar ()) < 0)
+            pdftex_fail ("unexpected EOF");
         i = (i << 8) + c;
         s--;
     }
     return i;
 }
 
-static long ttf_funit(long n)
+static long ttf_funit (long n)
 {
     if (n < 0)
-        return -((-n/upem)*1000 + ((-n%upem)*1000)/upem);
+        return -((-n / upem) * 1000 + ((-n % upem) * 1000) / upem);
     else
-        return (n/upem)*1000 + ((n%upem)*1000)/upem;
+        return (n / upem) * 1000 + ((n % upem) * 1000) / upem;
 }
 
-static void ttf_ncopy(int n)
+static void ttf_ncopy (int n)
 {
     while (n-- > 0)
-        copy_byte();
+        copy_byte ();
 }
 
-static dirtab_entry *ttf_name_lookup(const char *s, boolean required)
+static dirtab_entry *ttf_name_lookup (const char *s, boolean required)
 {
     dirtab_entry *tab;
     for (tab = dir_tab; tab - dir_tab < ntabs; tab++)
-        if (strncmp(tab->tag, s, 4) == 0)
+        if (strncmp (tab->tag, s, 4) == 0)
             break;
     if (tab - dir_tab == ntabs) {
         if (required)
-            pdftex_fail("can't find table `%s'", s);
+            pdftex_fail ("can't find table `%s'", s);
         else
             tab = NULL;
     }
     return tab;
 }
 
-static dirtab_entry *ttf_seek_tab(const char *name, TTF_LONG offset)
+static dirtab_entry *ttf_seek_tab (const char *name, TTF_LONG offset)
 {
-    dirtab_entry *tab = ttf_name_lookup(name, true);
-    xfseek(INFILE, tab->offset + offset, SEEK_SET, cur_file_name);
+    dirtab_entry *tab = ttf_name_lookup (name, true);
+    xfseek (INFILE, tab->offset + offset, SEEK_SET, cur_file_name);
     return tab;
 }
 
-static void ttf_seek_off(TTF_LONG offset)
+static void ttf_seek_off (TTF_LONG offset)
 {
-    xfseek(INFILE, offset, SEEK_SET, cur_file_name);
+    xfseek (INFILE, offset, SEEK_SET, cur_file_name);
 }
 
-static void ttf_copy_encoding(void)
+static void ttf_copy_encoding (void)
 {
     int i;
-    char **glyph_names = (fm_cur->encoding)->glyph_names;
+    char **glyph_names, *p;
+    long *charcodes;
+    static char *charcode_names[256], buf[2048];
+
     ttfenc_entry *e = ttfenc_tab;
-    pdfmarkchar(tex_font, 'a'); /* workaround for a bug of AcroReader 4.0 */
-    for (i = 0; i <= MAX_CHAR_CODE; i++, e++) {
-        if (pdfcharmarked(tex_font, i))
-            e->name = glyph_names[i];
-        else
-            e->name = (char*) notdef;
-    }
+    pdfmarkchar (tex_font, 'a');        /* workaround for a bug of AcroReader 4.0 */
+
+    if (is_reencoded (fm_cur)) {
+        glyph_names = (fm_cur->encoding)->glyph_names;
+        for (i = 0; i < 256; i++, e++) {
+            if (pdfcharmarked (tex_font, i))
+                e->name = glyph_names[i];
+            else
+                e->name = (char *) notdef;
+        }
+        make_subset_tag (fm_cur, glyph_names);
+    } else if (is_subfont (fm_cur)) {
+        charcodes = fm_cur->subfont->charcodes;
+        assert (charcodes != NULL);
+        p = buf;
+        for (i = 0; i < 256; i++, e++) {
+            if (pdfcharmarked (tex_font, i)) {
+                e->code = charcodes[i];
+                if (e->code == -1)
+                    pdftex_warn ("character %i is not mapped to any charcode",
+                                 i);
+            } else
+                e->code = -1;
+            if (e->code != -1) {
+                assert (e->code < 0x10000);
+                // FIXME: e->code is long. Do we want multibyte instead of a char?
+                sprintf (p, "/hc%4.4X", (short) e->code);
+                charcode_names[i] = p;
+                p = strend (p) + 1;
+            } else
+                charcode_names[i] = (char *) notdef;
+        }
+        make_subset_tag (fm_cur, charcode_names);
+    } else
+        assert (0);
 }
 
 #define ttf_append_byte(B)\
@@ -226,33 +304,33 @@
     *q++ = B;\
 } while (0)
 
-static void ttf_read_name(void)
+static void ttf_read_name (void)
 {
     int i, j;
-    dirtab_entry *tab = ttf_seek_tab("name", TTF_USHORT_SIZE);
+    dirtab_entry *tab = ttf_seek_tab ("name", TTF_USHORT_SIZE);
     char *p;
-    name_record_num = get_ushort();
-    name_tab = xtalloc(name_record_num, name_record);
-    name_buf_size = tab->length - 
-         (3*TTF_USHORT_SIZE + name_record_num*6*TTF_USHORT_SIZE);
-    name_buf = xtalloc(name_buf_size, char);
-    ttf_skip(TTF_USHORT_SIZE);
+    name_record_num = get_ushort ();
+    name_tab = xtalloc (name_record_num, name_record);
+    name_buf_size = tab->length -
+        (3 * TTF_USHORT_SIZE + name_record_num * 6 * TTF_USHORT_SIZE);
+    name_buf = xtalloc (name_buf_size, char);
+    ttf_skip (TTF_USHORT_SIZE);
     for (i = 0; i < name_record_num; i++) {
-        name_tab[i].platform_id = get_ushort();
-        name_tab[i].encoding_id = get_ushort();
-        name_tab[i].language_id = get_ushort();
-        name_tab[i].name_id = get_ushort();
-        name_tab[i].length = get_ushort();
-        name_tab[i].offset = get_ushort();
+        name_tab[i].platform_id = get_ushort ();
+        name_tab[i].encoding_id = get_ushort ();
+        name_tab[i].language_id = get_ushort ();
+        name_tab[i].name_id = get_ushort ();
+        name_tab[i].length = get_ushort ();
+        name_tab[i].offset = get_ushort ();
     }
     for (p = name_buf; p - name_buf < name_buf_size; p++)
-         *p = get_char();
+        *p = get_char ();
     /* look for PS font name */
     for (i = 0; i < name_record_num; i++) {
-        if (name_tab[i].platform_id == 1 && 
-            name_tab[i].encoding_id == 0 &&
-            name_tab[i].name_id == 6) {
-            strncpy(fontname_buf, name_buf + name_tab[i].offset, name_tab[i].length);
+        if (name_tab[i].platform_id == 1 &&
+            name_tab[i].encoding_id == 0 && name_tab[i].name_id == 6) {
+            strncpy (fontname_buf, name_buf + name_tab[i].offset,
+                     name_tab[i].length);
             fontname_buf[name_tab[i].length] = 0;
             font_keys[FONTNAME_CODE].valid = true;
             break;
@@ -260,10 +338,9 @@
     }
     if (!font_keys[FONTNAME_CODE].valid) {
         for (i = 0; i < name_record_num; i++) {
-            if (name_tab[i].platform_id == 3 && 
-                (name_tab[i].encoding_id == 0 || 
-                 name_tab[i].encoding_id == 1) &&
-                name_tab[i].name_id == 6) {
+            if (name_tab[i].platform_id == 3 &&
+                (name_tab[i].encoding_id == 0 ||
+                 name_tab[i].encoding_id == 1) && name_tab[i].name_id == 6) {
                 for (j = 0, p = fontname_buf; j < name_tab[i].length; j += 2)
                     *p++ = name_buf[name_tab[i].offset + j + 1];
                 *p = 0;
@@ -274,82 +351,83 @@
     }
 }
 
-static void ttf_read_mapx(void)
+static void ttf_read_mapx (void)
 {
-    int i;
     glyph_entry *glyph;
-    ttf_seek_tab("maxp", TTF_FIXED_SIZE);
-    glyph_tab = xtalloc(1 + (glyphs_count = get_ushort()), glyph_entry);
+    ttf_seek_tab ("maxp", TTF_FIXED_SIZE);
+    glyph_tab = xtalloc (1 + (glyphs_count = get_ushort ()), glyph_entry);
     for (glyph = glyph_tab; glyph - glyph_tab < glyphs_count; glyph++) {
         glyph->newindex = -1;
         glyph->newoffset = 0;
         glyph->name_index = 0;
-        glyph->name = (char*) notdef;
+        glyph->name = (char *) notdef;
     }
-    glyph_index = xtalloc(glyphs_count, short);
-    glyph_index[0] = 0; /* index of ".notdef" glyph */
-    glyph_index[1] = 1; /* index of ".null" glyph */
+    glyph_index = xtalloc (glyphs_count, short);
+    glyph_index[0] = 0;         /* index of ".notdef" glyph */
+    glyph_index[1] = 1;         /* index of ".null" glyph */
 }
 
-static void ttf_read_head(void)
+static void ttf_read_head (void)
 {
-    ttf_seek_tab("head", 2*TTF_FIXED_SIZE + 2*TTF_ULONG_SIZE + TTF_USHORT_SIZE);
-    upem = get_ushort();
-    ttf_skip(16);
-    font_keys[FONTBBOX1_CODE].value = ttf_funit(get_fword());
-    font_keys[FONTBBOX2_CODE].value = ttf_funit(get_fword());
-    font_keys[FONTBBOX3_CODE].value = ttf_funit(get_fword());
-    font_keys[FONTBBOX4_CODE].value = ttf_funit(get_fword());
+    ttf_seek_tab ("head",
+                  2 * TTF_FIXED_SIZE + 2 * TTF_ULONG_SIZE + TTF_USHORT_SIZE);
+    upem = get_ushort ();
+    ttf_skip (16);
+    font_keys[FONTBBOX1_CODE].value = ttf_funit (get_fword ());
+    font_keys[FONTBBOX2_CODE].value = ttf_funit (get_fword ());
+    font_keys[FONTBBOX3_CODE].value = ttf_funit (get_fword ());
+    font_keys[FONTBBOX4_CODE].value = ttf_funit (get_fword ());
     font_keys[FONTBBOX1_CODE].valid = true;
     font_keys[FONTBBOX2_CODE].valid = true;
     font_keys[FONTBBOX3_CODE].valid = true;
     font_keys[FONTBBOX4_CODE].valid = true;
-    ttf_skip(2*TTF_USHORT_SIZE + TTF_SHORT_SIZE);
-    loca_format = get_short();
+    ttf_skip (2 * TTF_USHORT_SIZE + TTF_SHORT_SIZE);
+    loca_format = get_short ();
 }
 
-static void ttf_read_hhea(void)
+static void ttf_read_hhea (void)
 {
-    ttf_seek_tab("hhea", TTF_FIXED_SIZE);
-    font_keys[ASCENT_CODE].value = ttf_funit(get_fword());
-    font_keys[DESCENT_CODE].value = ttf_funit(get_fword());
+    ttf_seek_tab ("hhea", TTF_FIXED_SIZE);
+    font_keys[ASCENT_CODE].value = ttf_funit (get_fword ());
+    font_keys[DESCENT_CODE].value = ttf_funit (get_fword ());
     font_keys[ASCENT_CODE].valid = true;
     font_keys[DESCENT_CODE].valid = true;
-    ttf_skip(TTF_FWORD_SIZE + TTF_UFWORD_SIZE + 3*TTF_FWORD_SIZE + 8*TTF_SHORT_SIZE);
-    nhmtxs = get_ushort();
+    ttf_skip (TTF_FWORD_SIZE + TTF_UFWORD_SIZE + 3 * TTF_FWORD_SIZE +
+              8 * TTF_SHORT_SIZE);
+    nhmtxs = get_ushort ();
 }
 
-static void ttf_read_pclt(void)
+static void ttf_read_pclt (void)
 {
-    if (ttf_name_lookup("PCLT", false) == NULL)
+    if (ttf_name_lookup ("PCLT", false) == NULL)
         return;
-    ttf_seek_tab("PCLT", TTF_FIXED_SIZE + TTF_ULONG_SIZE + TTF_USHORT_SIZE);
-    font_keys[XHEIGHT_CODE].value = ttf_funit(get_ushort());
-    ttf_skip(2*TTF_USHORT_SIZE);
-    font_keys[CAPHEIGHT_CODE].value = ttf_funit(get_ushort());
+    ttf_seek_tab ("PCLT", TTF_FIXED_SIZE + TTF_ULONG_SIZE + TTF_USHORT_SIZE);
+    font_keys[XHEIGHT_CODE].value = ttf_funit (get_ushort ());
+    ttf_skip (2 * TTF_USHORT_SIZE);
+    font_keys[CAPHEIGHT_CODE].value = ttf_funit (get_ushort ());
     font_keys[XHEIGHT_CODE].valid = true;
     font_keys[CAPHEIGHT_CODE].valid = true;
 }
 
-static void ttf_read_hmtx(void)
+static void ttf_read_hmtx (void)
 {
     glyph_entry *glyph;
     TTF_UFWORD last_advWidth;
-    ttf_seek_tab("hmtx", 0);
+    ttf_seek_tab ("hmtx", 0);
     for (glyph = glyph_tab; glyph - glyph_tab < nhmtxs; glyph++) {
-        glyph->advWidth = get_ufword();
-        glyph->lsb = get_ufword();
+        glyph->advWidth = get_ufword ();
+        glyph->lsb = get_ufword ();
     }
     if (nhmtxs < glyphs_count) {
         last_advWidth = glyph[-1].advWidth;
-        for (;glyph - glyph_tab <  glyphs_count; glyph++) {
+        for (; glyph - glyph_tab < glyphs_count; glyph++) {
             glyph->advWidth = last_advWidth;
-            glyph->lsb = get_ufword();
+            glyph->lsb = get_ufword ();
         }
     }
 }
 
-static void ttf_read_post(void)
+static void ttf_read_post (void)
 {
     int k, nnames;
     long length;
@@ -358,46 +436,47 @@
     TTF_FIXED italic_angle;
     char *p;
     glyph_entry *glyph;
-    dirtab_entry *tab = ttf_seek_tab("post", 0);
-    post_format = get_fixed();
-    italic_angle = get_fixed();
+    const dirtab_entry *tab = ttf_seek_tab ("post", 0);
+    post_format = get_fixed ();
+    italic_angle = get_fixed ();
     int_part = italic_angle >> 16;
-    if (int_part > 0x7FFF) { /* a negative number */
+    if (int_part > 0x7FFF) {    /* a negative number */
         int_part = 0x10000 - int_part;
         sign = -1;
     }
     frac_part = italic_angle % 0x10000;
-    font_keys[ITALIC_ANGLE_CODE].value = sign*(int_part + frac_part*1.0/0x10000);
+    font_keys[ITALIC_ANGLE_CODE].value =
+        sign * (int_part + frac_part * 1.0 / 0x10000);
     font_keys[ITALIC_ANGLE_CODE].valid = true;
     if (glyph_tab == NULL)
-        return; /* being called from writeotf() */
-    ttf_skip(2*TTF_FWORD_SIZE + 5*TTF_ULONG_SIZE);
+        return;                 /* being called from writeotf() */
+    ttf_skip (2 * TTF_FWORD_SIZE + 5 * TTF_ULONG_SIZE);
     switch (post_format) {
     case 0x10000:
         for (glyph = glyph_tab; glyph - glyph_tab < NMACGLYPHS; glyph++) {
-            glyph->name = (char*)mac_glyph_names[glyph - glyph_tab];
+            glyph->name = (char *) mac_glyph_names[glyph - glyph_tab];
             glyph->name_index = glyph - glyph_tab;
         }
         break;
     case 0x20000:
-        nnames = get_ushort(); /* some fonts have this value different from nglyphs */
+        nnames = get_ushort (); /* some fonts have this value different from nglyphs */
         for (glyph = glyph_tab; glyph - glyph_tab < nnames; glyph++)
-            glyph->name_index = get_ushort();
-        length = tab->length - (xftell(INFILE, cur_file_name) - tab->offset);
-        glyph_name_buf = xtalloc(length, char);
+            glyph->name_index = get_ushort ();
+        length = tab->length - (xftell (INFILE, cur_file_name) - tab->offset);
+        glyph_name_buf = xtalloc (length, char);
         for (p = glyph_name_buf; p - glyph_name_buf < length;) {
-            for (k = get_byte(); k > 0; k--)
-                *p++ = get_char();
+            for (k = get_byte (); k > 0; k--)
+                *p++ = get_char ();
             *p++ = 0;
         }
         for (glyph = glyph_tab; glyph - glyph_tab < nnames; glyph++) {
             if (glyph->name_index < NMACGLYPHS)
-                glyph->name = (char*)mac_glyph_names[glyph->name_index];
+                glyph->name = (char *) mac_glyph_names[glyph->name_index];
             else {
                 p = glyph_name_buf;
                 k = glyph->name_index - NMACGLYPHS;
                 for (; k > 0; k--)
-                    p = strend(p) + 1;
+                    p = strend (p) + 1;
                 glyph->name = p;
             }
         }
@@ -408,298 +487,326 @@
         }
         break;
     default:
-        pdftex_fail("unsupported format (%.8X) of `post' table", (unsigned int) post_format);
+        pdftex_fail ("unsupported format (%.8X) of `post' table",
+                     (unsigned int) post_format);
     }
 }
 
-static void ttf_read_loca(void)
+static void ttf_read_loca (void)
 {
     glyph_entry *glyph;
-    ttf_seek_tab("loca", 0);
+    ttf_seek_tab ("loca", 0);
     if (loca_format != 0)
         for (glyph = glyph_tab; glyph - glyph_tab < glyphs_count + 1; glyph++)
-            glyph->offset = get_ulong();
+            glyph->offset = get_ulong ();
     else
         for (glyph = glyph_tab; glyph - glyph_tab < glyphs_count + 1; glyph++)
-            glyph->offset = get_ushort() << 1;
+            glyph->offset = get_ushort () << 1;
 }
 
-static void ttf_read_tabdir()
+static void ttf_read_tabdir ()
 {
     int i;
     dirtab_entry *tab;
-/*     if ((version= get_fixed()) != 0x00010000) */
-/*         pdftex_fail("unsupport version 0x%.8X; can handle only version 1.0", (int)version); */
-    ttf_skip(TTF_FIXED_SIZE); /* ignore the sfnt number */
-    dir_tab = xtalloc(ntabs = get_ushort(), dirtab_entry);
-    ttf_skip(3*TTF_USHORT_SIZE);
+    ttf_skip (TTF_FIXED_SIZE);  /* ignore the sfnt number */
+    dir_tab = xtalloc (ntabs = get_ushort (), dirtab_entry);
+    ttf_skip (3 * TTF_USHORT_SIZE);
     for (tab = dir_tab; tab - dir_tab < ntabs; tab++) {
         for (i = 0; i < 4; i++)
-            tab->tag[i] = get_char();
-        tab->checksum = get_ulong();
-        tab->offset = get_ulong();
-        tab->length = get_ulong();
+            tab->tag[i] = get_char ();
+        tab->checksum = get_ulong ();
+        tab->offset = get_ulong ();
+        tab->length = get_ulong ();
     }
 }
 
-static void ttf_read_cmap(void)
+static ttf_cmap_entry *ttf_read_cmap (char *ttf_name, int pid, int eid,
+                                      boolean warn)
 {
-    cmap_entry *e;
     seg_entry *seg_tab, *s;
     TTF_USHORT *glyphId, format, segCount;
-    TTF_USHORT ncmapsubtabs;
-    long cmap_offset;
-    long int n, i, j, k, first_code, length, last_sep, index;
-    int unicode_map_count = 0;
-    int select_unicode = 1; /* may be changed later if needed */
-    ttf_seek_tab("cmap", TTF_USHORT_SIZE); /* skip the table vesrion number (=0) */
-    ncmapsubtabs = get_ushort();
-    cmap_offset = xftell(INFILE, cur_file_name) - 2*TTF_USHORT_SIZE;
-    cmap_tab = xtalloc(ncmapsubtabs, cmap_entry);
-    for (e = cmap_tab; e - cmap_tab < ncmapsubtabs; e++) {
-        e->platform_id = get_ushort();
-        e->encoding_id = get_ushort();
-        e->offset = get_ulong();
+    TTF_USHORT ncmapsubtabs, tmp_pid, tmp_eid;
+    TTF_ULONG cmap_offset, tmp_offset;
+    long n, i, k, length, index;
+    ttf_cmap_entry tmp_e, *p;
+    void **aa;
+
+    /* loop up in ttf_cmap_tree first, return if found */
+    tmp_e.ttf_name = ttf_name;
+    tmp_e.pid = pid;
+    tmp_e.eid = eid;
+    if (ttf_cmap_tree == NULL) {
+        ttf_cmap_tree = avl_create (comp_ttf_cmap_entry, NULL, &avl_xallocator);
+        assert (ttf_cmap_tree != NULL);
     }
-    for (i = 0; i < 0xFFFF; ++i)
-        unicode_map[i] = NOGLYPH_ASSIGNED_YET;
-    for (e = cmap_tab; e - cmap_tab < ncmapsubtabs; e++) {
-        ttf_seek_off(cmap_offset + e->offset);
-        format = get_ushort();
-        if (is_unicode_mapping(e) && format == 4) {
-            ++unicode_map_count;
-            if (unicode_map_count == select_unicode)
-                goto read_unicode_mapping;
+    p = (ttf_cmap_entry *) avl_find (ttf_cmap_tree, &tmp_e);
+    if (p != NULL)
+        return p;
+
+    /* not found, have to read it */
+    ttf_seek_tab ("cmap", TTF_USHORT_SIZE);     /* skip the table vesrion number (=0) */
+    ncmapsubtabs = get_ushort ();
+    cmap_offset = xftell (INFILE, cur_file_name) - 2 * TTF_USHORT_SIZE;
+    cmap_tab = xtalloc (ncmapsubtabs, cmap_entry);
+    for (i = 0; i < ncmapsubtabs; ++i) {
+        tmp_pid = get_ushort ();
+        tmp_eid = get_ushort ();
+        tmp_offset = get_ulong ();
+        if (tmp_pid == pid && tmp_eid == eid) {
+            ttf_seek_off (cmap_offset + tmp_offset);
+            format = get_ushort ();
+            if (format == 4)
+                goto read_cmap_format_4;
+            else {
+                if (warn)
+                    pdftex_warn ("cmap format %i unsupported");
+                return NULL;
+            }
         }
-        continue;
-read_unicode_mapping:
-        length = get_ushort(); /* length of subtable */
-        get_ushort(); /* skip the version number */
-        segCount = get_ushort()/2;
-        get_ushort(); /* skip searchRange */
-        get_ushort(); /* skip entrySelector */
-        get_ushort(); /* skip rangeShift */
-        seg_tab = xtalloc(segCount, seg_entry);
-        for (s = seg_tab; s - seg_tab < segCount; s++)
-            s->endCode = get_ushort();
-        get_ushort(); /* skip reversedPad */
-        for (s = seg_tab; s - seg_tab < segCount; s++)
-            s->startCode = get_ushort();
-        for (s = seg_tab; s - seg_tab < segCount; s++)
-            s->idDelta = get_ushort();
-        for (s = seg_tab; s - seg_tab < segCount; s++)
-            s->idRangeOffset = get_ushort();
-        length -= 8*TTF_USHORT_SIZE + 4*segCount*TTF_USHORT_SIZE;
-        n = length/TTF_USHORT_SIZE; /* number of glyphID's */
-        glyphId = xtalloc(n, TTF_USHORT);
-        for (i = 0; i < n; i++)
-            glyphId[i] = get_ushort();
-        for (s = seg_tab; s - seg_tab < segCount; s++) {
-            for (i = s->startCode; i <= s->endCode; i++) {
-                if (i == 0xFFFF)
-                    break;
-                if (s->idRangeOffset != 0xFFFF) {
-                    if (s->idRangeOffset == 0)
-                        index = (s->idDelta + i) & 0xFFFF;
-                    else {
-                        k = (i - s->startCode) + s->idRangeOffset/2 + 
-                            (s - seg_tab) - segCount ;
-                        assert(k >= 0 && k < n);
-                        index = glyphId[k];
-                        if (index != 0)
-                            index = (index + s->idDelta) & 0xFFFF;
-                    }
-                    if (index >= glyphs_count)
-                        pdftex_fail("cmap: glyph index out of range [0..%i)", glyphs_count);
-                    if (unicode_map[i] != NOGLYPH_ASSIGNED_YET)
-                        pdftex_fail("cmap: unicode %.4X is mapped to multiple glyphs", i);
-                    unicode_map[i] = index;
+    }
+    if (warn)
+        pdftex_warn ("cannot find cmap subtable for (pid,eid) = (%i, %i)",
+                     pid, eid);
+    return NULL;
+  read_cmap_format_4:
+    /* initialize the new entry */
+    p = new_ttf_cmap_entry ();
+    p->ttf_name = xstrdup (ttf_name);
+    p->pid = pid;
+    p->eid = eid;
+    p->table = xtalloc (0x10000, short);
+    for (i = 0; i < 0x10000; ++i)
+        p->table[i] = -1;       /* unassigned yet */
+
+    /* read the subtable */
+    length = get_ushort ();     /* length of subtable */
+    (void) get_ushort ();       /* skip the version number */
+    segCount = get_ushort () / 2;
+    (void) get_ushort ();       /* skip searchRange */
+    (void) get_ushort ();       /* skip entrySelector */
+    (void) get_ushort ();       /* skip rangeShift */
+    seg_tab = xtalloc (segCount, seg_entry);
+    for (s = seg_tab; s - seg_tab < segCount; s++)
+        s->endCode = get_ushort ();
+    (void) get_ushort ();       /* skip reversedPad */
+    for (s = seg_tab; s - seg_tab < segCount; s++)
+        s->startCode = get_ushort ();
+    for (s = seg_tab; s - seg_tab < segCount; s++)
+        s->idDelta = get_ushort ();
+    for (s = seg_tab; s - seg_tab < segCount; s++)
+        s->idRangeOffset = get_ushort ();
+    length -= 8 * TTF_USHORT_SIZE + 4 * segCount * TTF_USHORT_SIZE;
+    n = length / TTF_USHORT_SIZE;       /* number of glyphID's */
+    glyphId = xtalloc (n, TTF_USHORT);
+    for (i = 0; i < n; i++)
+        glyphId[i] = get_ushort ();
+    for (s = seg_tab; s - seg_tab < segCount; s++) {
+        for (i = s->startCode; i <= s->endCode; i++) {
+            if (i == 0xFFFF)
+                break;
+            if (s->idRangeOffset != 0xFFFF) {
+                if (s->idRangeOffset == 0)
+                    index = (s->idDelta + i) & 0xFFFF;
+                else {
+                    k = (i - s->startCode) + s->idRangeOffset / 2 +
+                        (s - seg_tab) - segCount;
+                    assert (k >= 0 && k < n);
+                    index = glyphId[k];
+                    if (index != 0)
+                        index = (index + s->idDelta) & 0xFFFF;
                 }
+                if (index >= glyphs_count)
+                    pdftex_fail ("cmap: glyph index %i out of range [0..%i)",
+                                 index, glyphs_count);
+                if (p->table[i] != -1)
+                    pdftex_warn
+                        ("cmap: multiple glyphs are mapped to unicode %.4X, "
+                         "only %i will be used (glyph %i being ignored)", i,
+                         p->table[i], index);
+                else
+                    p->table[i] = index;
             }
         }
-        xfree(seg_tab);
-        xfree(glyphId);
-        break;
     }
-    if (e - cmap_tab == ncmapsubtabs)
-        pdftex_fail("Invalid argument `-m %i': out of range [1..%i]",
-                 select_unicode, unicode_map_count);
-    xfree(cmap_tab);
+    xfree (seg_tab);
+    xfree (glyphId);
+    aa = avl_probe (ttf_cmap_tree, p);
+    assert (aa != NULL);
+    return p;
 }
 
-static void ttf_read_font(void)
+static void ttf_read_font (void)
 {
-    ttf_read_tabdir();
-    if (ttf_name_lookup("PCLT", false) == NULL)
+    ttf_read_tabdir ();
+    if (ttf_name_lookup ("PCLT", false) == NULL)
         new_ntabs--;
-    if (ttf_name_lookup("fpgm", false) == NULL)
+    if (ttf_name_lookup ("fpgm", false) == NULL)
         new_ntabs--;
-    if (ttf_name_lookup("cvt ", false) == NULL)
+    if (ttf_name_lookup ("cvt ", false) == NULL)
         new_ntabs--;
-    if (ttf_name_lookup("prep", false) == NULL)
+    if (ttf_name_lookup ("prep", false) == NULL)
         new_ntabs--;
-    ttf_read_mapx();
-    ttf_read_head();
-    ttf_read_hhea();
-    ttf_read_pclt();
-    ttf_read_hmtx();
-    ttf_read_post();
-    ttf_read_loca();
-    ttf_read_name();
-    ttf_read_cmap();
+    ttf_read_mapx ();
+    ttf_read_head ();
+    ttf_read_hhea ();
+    ttf_read_pclt ();
+    ttf_read_hmtx ();
+    ttf_read_post ();
+    ttf_read_loca ();
+    ttf_read_name ();
 }
 
-static void ttf_reset_chksm(dirtab_entry *tab)
+static void ttf_reset_chksm (dirtab_entry * tab)
 {
     checksum = 0;
     tab_length = 0;
     tmp_ulong = 0;
-    tab->offset = ttf_offset();
+    tab->offset = ttf_offset ();
     if (tab->offset % 4 != 0)
-        pdftex_warn("offset of `%4.4s' is not a multiple of 4", tab->tag);
+        pdftex_warn ("offset of `%4.4s' is not a multiple of 4", tab->tag);
 }
 
 
-static void ttf_set_chksm(dirtab_entry *tab)
+static void ttf_set_chksm (dirtab_entry * tab)
 {
-    tab->length = ttf_offset() - tab->offset;
-    tab->checksum = ttf_getchksm();
+    tab->length = ttf_offset () - tab->offset;
+    tab->checksum = ttf_getchksm ();
 }
 
-static void ttf_copytab(const char *name)
+static void ttf_copytab (const char *name)
 {
     long i;
-    dirtab_entry *tab = ttf_seek_tab(name, 0);
-    ttf_reset_chksm(tab);
+    dirtab_entry *tab = ttf_seek_tab (name, 0);
+    ttf_reset_chksm (tab);
     for (i = tab->length; i > 0; i--)
-        copy_char();
-    ttf_set_chksm(tab);
+        copy_char ();
+    ttf_set_chksm (tab);
 }
 
 #define BYTE_ENCODING_LENGTH  \
-    ((MAX_CHAR_CODE + 1)*TTF_BYTE_SIZE + 3*TTF_USHORT_SIZE)
+    ((256)*TTF_BYTE_SIZE + 3*TTF_USHORT_SIZE)
 
-static void ttf_byte_encoding(void)
+static void ttf_byte_encoding (void)
 {
     ttfenc_entry *e;
-    put_ushort(0);  /* format number (0: byte encoding table) */
-    put_ushort(BYTE_ENCODING_LENGTH); /* length of table */
-    put_ushort(0);  /* version number */
-    for (e = ttfenc_tab; e - ttfenc_tab <= MAX_CHAR_CODE; e++)
+    (void) put_ushort (0);      /* format number (0: byte encoding table) */
+    (void) put_ushort (BYTE_ENCODING_LENGTH);   /* length of table */
+    (void) put_ushort (0);      /* version number */
+    for (e = ttfenc_tab; e - ttfenc_tab < 256; e++)
         if (e->newindex < 256) {
-            put_byte(e->newindex);
-        }
-        else {
+            put_byte (e->newindex);
+        } else {
             if (e->name != notdef)
-                pdftex_warn("glyph `%s' has been mapped to `%s' in `ttf_byte_encoding' cmap table",
-                            e->name, notdef);
-            put_byte(0); /* notdef */
+                pdftex_warn
+                    ("glyph `%s' has been mapped to `%s' in `ttf_byte_encoding' cmap table",
+                     e->name, notdef);
+            put_byte (0);       /* notdef */
         }
 }
 
-#define TRIMMED_TABLE_MAP_LENGTH (TTF_USHORT_SIZE*(5 + (MAX_CHAR_CODE + 1)))
+#define TRIMMED_TABLE_MAP_LENGTH (TTF_USHORT_SIZE*(5 + (256)))
 
-static void ttf_trimmed_table_map(void)
+static void ttf_trimmed_table_map (void)
 {
     ttfenc_entry *e;
-    put_ushort(6);  /* format number (6): trimmed table mapping */
-    put_ushort(TRIMMED_TABLE_MAP_LENGTH);
-    put_ushort(0);  /* version number (0) */
-    put_ushort(0);  /* first character code */
-    put_ushort(MAX_CHAR_CODE + 1);  /* number of character code in table */
-    for (e = ttfenc_tab; e - ttfenc_tab <= MAX_CHAR_CODE; e++)
-        put_ushort(e->newindex);
+    (void) put_ushort (6);      /* format number (6): trimmed table mapping */
+    (void) put_ushort (TRIMMED_TABLE_MAP_LENGTH);
+    (void) put_ushort (0);      /* version number (0) */
+    (void) put_ushort (0);      /* first character code */
+    (void) put_ushort (256);    /* number of character code in table */
+    for (e = ttfenc_tab; e - ttfenc_tab < 256; e++)
+        (void) put_ushort (e->newindex);
 }
 
-#define SEG_MAP_DELTA_LENGTH ((16 + (MAX_CHAR_CODE + 1))*TTF_USHORT_SIZE)
+#define SEG_MAP_DELTA_LENGTH ((16 + (256))*TTF_USHORT_SIZE)
 
-static void ttf_seg_map_delta(void)
+static void ttf_seg_map_delta (void)
 {
     ttfenc_entry *e;
-    put_ushort(4);  /* format number (4: segment mapping to delta values) */
-    put_ushort(SEG_MAP_DELTA_LENGTH);
-    put_ushort(0);  /* version number */
-    put_ushort(4);  /* 2*segCount */
-    put_ushort(4);  /* searchRange */
-    put_ushort(1);  /* entrySelector */
-    put_ushort(0);  /* rangeShift */
-    put_ushort(0xF0FF); /* endCount[0] */
-    put_ushort(0xFFFF); /* endCount[1] */
-    put_ushort(0); /* reversedPad */
-    put_ushort(0xF000); /* startCount[0] */
-    put_ushort(0xFFFF); /* startCount[1] */
-    put_ushort(0); /* idDelta[0] */
-    put_ushort(1); /* idDelta[1] */
-    put_ushort(2*TTF_USHORT_SIZE); /* idRangeOffset[0] */
-    put_ushort(0); /* idRangeOffset[1] */
-    for (e = ttfenc_tab; e - ttfenc_tab <= MAX_CHAR_CODE; e++)
-        put_ushort(e->newindex);
+    (void) put_ushort (4);      /* format number (4: segment mapping to delta values) */
+    (void) put_ushort (SEG_MAP_DELTA_LENGTH);
+    (void) put_ushort (0);      /* version number */
+    (void) put_ushort (4);      /* 2*segCount */
+    (void) put_ushort (4);      /* searchRange */
+    (void) put_ushort (1);      /* entrySelector */
+    (void) put_ushort (0);      /* rangeShift */
+    (void) put_ushort (0xF0FF); /* endCount[0] */
+    (void) put_ushort (0xFFFF); /* endCount[1] */
+    (void) put_ushort (0);      /* reversedPad */
+    (void) put_ushort (0xF000); /* startCount[0] */
+    (void) put_ushort (0xFFFF); /* startCount[1] */
+    (void) put_ushort (0);      /* idDelta[0] */
+    (void) put_ushort (1);      /* idDelta[1] */
+    (void) put_ushort (2 * TTF_USHORT_SIZE);    /* idRangeOffset[0] */
+    (void) put_ushort (0);      /* idRangeOffset[1] */
+    for (e = ttfenc_tab; e - ttfenc_tab < 256; e++)
+        (void) put_ushort (e->newindex);
 }
 
 #define CMAP_ENTRY_LENGTH (2*TTF_USHORT_SIZE + TTF_ULONG_SIZE)
 
-static void ttf_select_cmap(void)
+static void ttf_select_cmap (void)
 {
-    assert(sizeof(new_cmap_tab) <= NEW_CMAP_SIZE*sizeof(cmap_entry));
-    new_cmap_tab[0].platform_id  = 1; /* Macintosh */
-    new_cmap_tab[0].encoding_id  = 0; /* Symbol; ignore code page */
-    new_cmap_tab[0].format = new_glyphs_count < 256 ? 0  /* byte encoding */
-                                                : 6; /* trimmed table mapping */
-    new_cmap_tab[1].platform_id  = 3; /* Microsoft */
-    new_cmap_tab[1].encoding_id  = 0; /* Symbol; ignore code page */
-    new_cmap_tab[1].format       = 4; /* segment mapping to delta */
+    assert (sizeof (new_cmap_tab) <= NEW_CMAP_SIZE * sizeof (cmap_entry));
+    new_cmap_tab[0].platform_id = 1;    /* Macintosh */
+    new_cmap_tab[0].encoding_id = 0;    /* Symbol; ignore code page */
+    new_cmap_tab[0].format = new_glyphs_count < 256 ? 0 /* byte encoding */
+        : 6;                    /* trimmed table mapping */
+    new_cmap_tab[1].platform_id = 3;    /* Microsoft */
+    new_cmap_tab[1].encoding_id = 0;    /* Symbol; ignore code page */
+    new_cmap_tab[1].format = 4; /* segment mapping to delta */
 }
 
-static void ttf_write_cmap(void)
+static void ttf_write_cmap (void)
 {
     cmap_entry *ce;
     long offset;
-    dirtab_entry *tab = ttf_name_lookup("cmap", true);
-    ttf_select_cmap();
-    ttf_reset_chksm(tab);
-    put_ushort(0);  /* table version number (0) */
-    put_ushort(NEW_CMAP_SIZE);  /* number of encoding tables */
-    offset = 2*TTF_USHORT_SIZE + NEW_CMAP_SIZE*CMAP_ENTRY_LENGTH;
+    dirtab_entry *tab = ttf_name_lookup ("cmap", true);
+    ttf_select_cmap ();
+    ttf_reset_chksm (tab);
+    (void) put_ushort (0);      /* table version number (0) */
+    (void) put_ushort (NEW_CMAP_SIZE);  /* number of encoding tables */
+    offset = 2 * TTF_USHORT_SIZE + NEW_CMAP_SIZE * CMAP_ENTRY_LENGTH;
     for (ce = new_cmap_tab; ce - new_cmap_tab < NEW_CMAP_SIZE; ce++) {
         ce->offset = offset;
         switch (ce->format) {
-        case 0: 
-            offset +=  BYTE_ENCODING_LENGTH;
+        case 0:
+            offset += BYTE_ENCODING_LENGTH;
             break;
-        case 4: 
-            offset +=  SEG_MAP_DELTA_LENGTH;
+        case 4:
+            offset += SEG_MAP_DELTA_LENGTH;
             break;
-        case 6: 
-            offset +=  TRIMMED_TABLE_MAP_LENGTH;
+        case 6:
+            offset += TRIMMED_TABLE_MAP_LENGTH;
             break;
         default:
-            pdftex_fail("invalid format (it should not have happened)");
+            pdftex_fail ("invalid format (it should not have happened)");
         }
-        put_ushort(ce->platform_id);
-        put_ushort(ce->encoding_id);
-        put_ulong(ce->offset);
+        (void) put_ushort (ce->platform_id);
+        (void) put_ushort (ce->encoding_id);
+        put_ulong (ce->offset);
     }
     for (ce = new_cmap_tab; ce - new_cmap_tab < NEW_CMAP_SIZE; ce++) {
         switch (ce->format) {
-        case 0: 
-            ttf_byte_encoding();
+        case 0:
+            ttf_byte_encoding ();
             break;
-        case 4: 
-            ttf_seg_map_delta();
+        case 4:
+            ttf_seg_map_delta ();
             break;
-        case 6: 
-            ttf_trimmed_table_map();
+        case 6:
+            ttf_trimmed_table_map ();
             break;
         }
     }
-    ttf_set_chksm(tab);
+    ttf_set_chksm (tab);
 }
 
-static int prepend_subset_tags(int index, char *p)
+static int prepend_subset_tags (int index, char *p)
 {
-    boolean is_unicode = (name_tab[index].platform_id == 3);
+    const boolean is_unicode = (name_tab[index].platform_id == 3);
     int i;
-    assert(index > 0 && index < name_record_num && fm_cur->subset_tag != NULL);
+    assert (index > 0 && index < name_record_num && fm_cur->subset_tag != NULL);
     if (is_unicode) {
         for (i = 0; i < 6; ++i) {
             *p++ = 0;
@@ -709,7 +816,7 @@
         *p++ = '+';
         return 14;
     } else {
-        strncpy(p, fm_cur->subset_tag, 6);
+        strncpy (p, fm_cur->subset_tag, 6);
         p += 6;
         *p++ = '+';
         return 7;
@@ -717,19 +824,19 @@
 }
 
 
-static void ttf_write_name(void)
+static void ttf_write_name (void)
 {
     int i, l;
     char *p;
     int new_name_buf_size;
     char *new_name_buf;
     name_record *n;
-    dirtab_entry *tab = ttf_name_lookup("name", true);
-    if (is_subsetted(fm_cur)) {
+    dirtab_entry *tab = ttf_name_lookup ("name", true);
+    if (is_subsetted (fm_cur)) {
         l = 0;
         for (i = 0; i < name_record_num; i++)
-            l += name_tab[i].length + 14; /* maximum lengh of new stogare area */
-        new_name_buf = xtalloc(l, char);
+            l += name_tab[i].length + 14;       /* maximum lengh of new stogare area */
+        new_name_buf = xtalloc (l, char);
         /* additional space for subset tags */
         p = new_name_buf;
         for (i = 0; i < name_record_num; i++) {
@@ -739,68 +846,65 @@
                  n->name_id == 4 || n->name_id == 6) &&
                 ((n->platform_id == 1 && n->encoding_id == 0) ||
                  (n->platform_id == 3 && n->encoding_id == 0) ||
-                 (n->platform_id == 3 && n->encoding_id == 1)))
-            {
-                l = prepend_subset_tags(i, p);
+                 (n->platform_id == 3 && n->encoding_id == 1))) {
+                l = prepend_subset_tags (i, p);
                 p += l;
-            }
-            else 
+            } else
                 l = 0;
-            memcpy(p, name_buf + n->offset, n->length);
+            memcpy (p, name_buf + n->offset, n->length);
             p += n->length;
             n->new_length = n->length + l;
         }
         new_name_buf_size = p - new_name_buf;
-    }
-    else {
+    } else {
         new_name_buf = name_buf;
         new_name_buf_size = name_buf_size;
     }
-    ttf_reset_chksm(tab);
-    put_ushort(0); /* Format selector */
-    put_ushort(name_record_num);
-    put_ushort(3*TTF_USHORT_SIZE + name_record_num*6*TTF_USHORT_SIZE);
+    ttf_reset_chksm (tab);
+    (void) put_ushort (0);      /* Format selector */
+    (void) put_ushort (name_record_num);
+    (void) put_ushort (3 * TTF_USHORT_SIZE +
+                       name_record_num * 6 * TTF_USHORT_SIZE);
     for (i = 0; i < name_record_num; i++) {
-        put_ushort(name_tab[i].platform_id);
-        put_ushort(name_tab[i].encoding_id);
-        put_ushort(name_tab[i].language_id);
-        put_ushort(name_tab[i].name_id);
-        put_ushort(name_tab[i].new_length);
-        put_ushort(name_tab[i].new_offset);
+        (void) put_ushort (name_tab[i].platform_id);
+        (void) put_ushort (name_tab[i].encoding_id);
+        (void) put_ushort (name_tab[i].language_id);
+        (void) put_ushort (name_tab[i].name_id);
+        (void) put_ushort (name_tab[i].new_length);
+        (void) put_ushort (name_tab[i].new_offset);
     }
     for (p = new_name_buf; p - new_name_buf < new_name_buf_size; p++)
-         put_char(*p);
-    ttf_set_chksm(tab);
+        put_char (*p);
+    ttf_set_chksm (tab);
     if (new_name_buf != name_buf)
-        xfree(new_name_buf);
+        xfree (new_name_buf);
 }
 
-static void ttf_write_dirtab(void)
+static void ttf_write_dirtab (void)
 {
     dirtab_entry *tab;
     TTF_ULONG i, k;
     char *p;
-    integer save_offset = ttf_offset();
-    ttf_seek_outbuf(TABDIR_OFF);
-    if (is_subsetted(fm_cur)) {
+    const integer save_offset = ttf_offset ();
+    ttf_seek_outbuf (TABDIR_OFF);
+    if (is_subsetted (fm_cur)) {
         for (i = 0; i < DEFAULT_NTABS; i++) {
-            tab = ttf_name_lookup(newtabnames[i], false);
+            tab = ttf_name_lookup (newtabnames[i], false);
             if (tab == NULL)
                 continue;
             for (k = 0; k < 4; k++)
-               put_char(tab->tag[k]);
-            put_ulong(tab->checksum);
-            put_ulong(tab->offset);
-            put_ulong(tab->length);
+                put_char (tab->tag[k]);
+            put_ulong (tab->checksum);
+            put_ulong (tab->offset);
+            put_ulong (tab->length);
         }
-    }
-    else {
+    } else {
         for (tab = dir_tab; tab - dir_tab < ntabs; tab++) {
             for (k = 0; k < 4; k++)
-               put_char(tab->tag[k]);
-            put_ulong(tab->checksum);
-            put_ulong(tab->offset);
-            put_ulong(tab->length);
+                put_char (tab->tag[k]);
+            put_ulong (tab->checksum);
+            put_ulong (tab->offset);
+            put_ulong (tab->length);
         }
     }
     /* adjust checkSumAdjustment */
@@ -815,120 +919,158 @@
         }
     }
     if (i % 4 != 0) {
-        pdftex_warn("font length is not a multiple of 4 (%li)", i);
-        checksum <<= 8*(4 - i % 4);
+        pdftex_warn ("font length is not a multiple of 4 (%li)", i);
+        checksum <<= 8 * (4 - i % 4);
     }
     k = 0xB1B0AFBA - checksum;
-    ttf_seek_outbuf(checkSumAdjustment_offset);
-    put_ulong(k);
-    ttf_seek_outbuf(save_offset);
+    ttf_seek_outbuf (checkSumAdjustment_offset);
+    put_ulong (k);
+    ttf_seek_outbuf (save_offset);
 }
 
-static void ttf_write_glyf(void)
+static void ttf_write_glyf (void)
 {
     short *id, k;
     TTF_USHORT idx;
     TTF_USHORT flags;
-    dirtab_entry *tab = ttf_name_lookup("glyf", true);
-    long glyf_offset = tab->offset;
-    long new_glyf_offset = ttf_offset();
-    ttf_reset_chksm(tab);
+    dirtab_entry *tab = ttf_name_lookup ("glyf", true);
+    const long glyf_offset = tab->offset;
+    const long new_glyf_offset = ttf_offset ();
+    ttf_reset_chksm (tab);
     for (id = glyph_index; id - glyph_index < new_glyphs_count; id++) {
-        glyph_tab[*id].newoffset = ttf_offset() - new_glyf_offset;
+        glyph_tab[*id].newoffset = ttf_offset () - new_glyf_offset;
         if (glyph_tab[*id].offset != glyph_tab[*id + 1].offset) {
-            ttf_seek_off(glyf_offset + glyph_tab[*id].offset);
-            k = copy_short();
-            ttf_ncopy(4*TTF_FWORD_SIZE);
+            ttf_seek_off (glyf_offset + glyph_tab[*id].offset);
+            k = copy_short ();
+            ttf_ncopy (4 * TTF_FWORD_SIZE);
             if (k < 0) {
                 do {
-                    flags = copy_ushort();
-                    idx = get_ushort();
+                    flags = copy_ushort ();
+                    idx = get_ushort ();
                     if (glyph_tab[idx].newindex < 0) {
                         glyph_tab[idx].newindex = new_glyphs_count;
                         glyph_index[new_glyphs_count++] = idx;
                         /* 
-                            N.B.: Here we change `new_glyphs_count',
-                            which appears in the condition of the `for' loop
-                        */
+                           N.B.: Here we change `new_glyphs_count',
+                           which appears in the condition of the `for' loop
+                         */
                     }
-                    put_ushort(glyph_tab[idx].newindex);
+                    (void) put_ushort (glyph_tab[idx].newindex);
                     if (flags & ARG_1_AND_2_ARE_WORDS)
-                        ttf_ncopy(2*TTF_SHORT_SIZE);
+                        ttf_ncopy (2 * TTF_SHORT_SIZE);
                     else
-                        ttf_ncopy(TTF_USHORT_SIZE);
+                        ttf_ncopy (TTF_USHORT_SIZE);
                     if (flags & WE_HAVE_A_SCALE)
-                        ttf_ncopy(TTF_F2DOT14_SIZE);
+                        ttf_ncopy (TTF_F2DOT14_SIZE);
                     else if (flags & WE_HAVE_AN_X_AND_Y_SCALE)
-                        ttf_ncopy(2*TTF_F2DOT14_SIZE);
+                        ttf_ncopy (2 * TTF_F2DOT14_SIZE);
                     else if (flags & WE_HAVE_A_TWO_BY_TWO)
-                        ttf_ncopy(4*TTF_F2DOT14_SIZE);
+                        ttf_ncopy (4 * TTF_F2DOT14_SIZE);
                 } while (flags & MORE_COMPONENTS);
                 if (flags & WE_HAVE_INSTRUCTIONS)
-                    ttf_ncopy(copy_ushort());
-            }
-            else
-                ttf_ncopy(glyph_tab[*id + 1].offset - glyph_tab[*id].offset - 
-                    TTF_USHORT_SIZE - 4*TTF_FWORD_SIZE);
+                    ttf_ncopy (copy_ushort ());
+            } else
+                ttf_ncopy (glyph_tab[*id + 1].offset - glyph_tab[*id].offset -
+                           TTF_USHORT_SIZE - 4 * TTF_FWORD_SIZE);
         }
     }
-    last_glyf_offset = ttf_offset() - new_glyf_offset;
-    ttf_set_chksm(tab);
+    last_glyf_offset = ttf_offset () - new_glyf_offset;
+    ttf_set_chksm (tab);
 }
 
-static void ttf_reindex_glyphs(void)
+static void ttf_reindex_glyphs (void)
 {
     ttfenc_entry *e;
     glyph_entry *glyph;
-    unsigned int index;
+    int index;
+    short *t;
+    ttf_cmap_entry *cmap = NULL;
+    boolean cmap_not_found = false;
+
     /* 
      * reindexing glyphs: we append index of used glyphs to `glyph_index'
      * while going through `ttfenc_tab'. After appending a new entry to
      * `glyph_index' we set field `newindex' of corresponding entries in both
      * `glyph_tab' and `ttfenc_tab' to the newly created index
-     * 
      */
-    for (e = ttfenc_tab; e - ttfenc_tab <= MAX_CHAR_CODE; e++) {
-        e->newindex = 0; /* index of ".notdef" glyph */
+    for (e = ttfenc_tab; e - ttfenc_tab < 256; e++) {
+        e->newindex = 0;        /* index of ".notdef" glyph */
+
+        /* handle case of subfonts first */
+        if (is_subfont (fm_cur)) {
+            if (e->code == -1)
+                continue;
+            assert (fm_cur->pid != -1 && fm_cur->eid != -1);
+            if (cmap == NULL && !cmap_not_found) {
+                cmap = ttf_read_cmap (fm_cur->ff_name, fm_cur->pid, fm_cur->eid,
+                                      true);
+                if (cmap == NULL)
+                    cmap_not_found = true;
+            }
+            if (cmap == NULL)
+                continue;
+            t = cmap->table;
+            assert (t != NULL && e->code < 0x10000);
+            assert (t[e->code] < glyphs_count); /* t has been read from ttf */
+            glyph = glyph_tab + t[e->code];
+            goto append_new_glyph;
+        }
+
+        /* handle case of reencoded fonts */
         if (e->name == notdef)
             continue;
         /* scan form `index123' */
-        if (sscanf(e->name,  GLYPH_PREFIX_INDEX "%i", &index) == 1) {
+        if (sscanf (e->name, GLYPH_PREFIX_INDEX "%i", &index) == 1) {
             if (index >= glyphs_count) {
-                pdftex_warn("`%s' out of valid range [0..%i)",
-                            e->name, glyphs_count);
+                pdftex_warn ("`%s' out of valid range [0..%i)",
+                             e->name, glyphs_count);
                 continue;
             }
             glyph = glyph_tab + index;
             goto append_new_glyph;
         }
         /* scan form `uniABCD' */
-        if (sscanf(e->name, GLYPH_PREFIX_UNICODE "%X", &index) == 1) {
-            assert(index <= 0xFFFF);
-            if (unicode_map[index] != NOGLYPH_ASSIGNED_YET) {
-                if (unicode_map[index] >= glyphs_count) {
-                    pdftex_warn("`%s' is mapped to index %i which is out of valid range [0..%i)",
-                                e->name, unicode_map[index], glyphs_count);
+        if (sscanf (e->name, GLYPH_PREFIX_UNICODE "%X", &index) == 1) {
+            if (cmap == NULL && !cmap_not_found) {
+                /* need to read the unicode mapping, ie (pid,eid) = (3,1) or (0,3) */
+                cmap = ttf_read_cmap (fm_cur->ff_name, 3, 1, false);
+                if (cmap == NULL)
+                    cmap = ttf_read_cmap (fm_cur->ff_name, 0, 3, false);
+                if (cmap == NULL) {
+                    pdftex_warn
+                        ("no unicode mapping found, all `uniXXXX' names will be ignored");
+                    cmap_not_found = true;      /* once only */
+                }
+            }
+            if (cmap == NULL)
+                continue;
+            t = cmap->table;
+            assert (t != NULL);
+            if (t[index] != -1) {
+                if (t[index] >= glyphs_count) {
+                    pdftex_warn
+                        ("`%s' is mapped to index %i which is out of valid range [0..%i)",
+                         e->name, t[index], glyphs_count);
                     continue;
                 }
-                glyph = glyph_tab + unicode_map[index];
+                glyph = glyph_tab + t[index];
                 goto append_new_glyph;
-            }
-            else {
-                pdftex_warn("`unicode %s%.4X' is not mapped to any glyph", 
-                            GLYPH_PREFIX_UNICODE, index);
+            } else {
+                pdftex_warn ("`unicode %s%.4X' is not mapped to any glyph",
+                             GLYPH_PREFIX_UNICODE, index);
                 continue;
             }
         }
         /* look up by name */
         for (glyph = glyph_tab; glyph - glyph_tab < glyphs_count; glyph++)
-            if (glyph->name != notdef && strcmp(glyph->name, e->name) == 0)
+            if (glyph->name != notdef && strcmp (glyph->name, e->name) == 0)
                 break;
         if (!(glyph - glyph_tab < glyphs_count)) {
-            pdftex_warn("glyph `%s' not found", e->name);
+            pdftex_warn ("glyph `%s' not found", e->name);
             continue;
         }
-append_new_glyph:
-        assert(glyph - glyph_tab < glyphs_count);
+      append_new_glyph:
+        assert (glyph - glyph_tab < glyphs_count);
         if (glyph->newindex < 0) {
             glyph_index[new_glyphs_count] = glyph - glyph_tab;
             glyph->newindex = new_glyphs_count;
@@ -937,54 +1079,54 @@
         e->newindex = glyph->newindex;
     }
 }
- 
-static void ttf_write_head()
+
+static void ttf_write_head ()
 {
     dirtab_entry *tab;
-    tab = ttf_seek_tab("head", 0);
-    ttf_reset_chksm(tab);
-    ttf_ncopy(2*TTF_FIXED_SIZE);
-    checkSumAdjustment_offset = ttf_offset();
-    put_ulong(0);
-    ttf_skip(TTF_ULONG_SIZE); /* skip checkSumAdjustment */
-    ttf_ncopy(TTF_ULONG_SIZE + 2*TTF_USHORT_SIZE + 16 + 
-        4*TTF_FWORD_SIZE + 2*TTF_USHORT_SIZE + TTF_SHORT_SIZE);
-    if (is_subsetted(fm_cur))  {
-        put_short(loca_format);
-        put_short(0);
-    }
-    else
-        ttf_ncopy(2*TTF_SHORT_SIZE);
-    ttf_set_chksm(tab);
+    tab = ttf_seek_tab ("head", 0);
+    ttf_reset_chksm (tab);
+    ttf_ncopy (2 * TTF_FIXED_SIZE);
+    checkSumAdjustment_offset = ttf_offset ();
+    put_ulong (0);
+    ttf_skip (TTF_ULONG_SIZE);  /* skip checkSumAdjustment */
+    ttf_ncopy (TTF_ULONG_SIZE + 2 * TTF_USHORT_SIZE + 16 +
+               4 * TTF_FWORD_SIZE + 2 * TTF_USHORT_SIZE + TTF_SHORT_SIZE);
+    if (is_subsetted (fm_cur)) {
+        (void) put_short (loca_format);
+        (void) put_short (0);
+    } else
+        ttf_ncopy (2 * TTF_SHORT_SIZE);
+    ttf_set_chksm (tab);
 }
- 
-static void ttf_write_hhea(void)
+
+static void ttf_write_hhea (void)
 {
     dirtab_entry *tab;
-    tab = ttf_seek_tab("hhea", 0);
-    ttf_reset_chksm(tab);
-    ttf_ncopy(TTF_FIXED_SIZE + 3*TTF_FWORD_SIZE + TTF_UFWORD_SIZE + 3*TTF_FWORD_SIZE + 8*TTF_SHORT_SIZE);
-    put_ushort(new_glyphs_count);
-    ttf_set_chksm(tab);
+    tab = ttf_seek_tab ("hhea", 0);
+    ttf_reset_chksm (tab);
+    ttf_ncopy (TTF_FIXED_SIZE + 3 * TTF_FWORD_SIZE + TTF_UFWORD_SIZE +
+               3 * TTF_FWORD_SIZE + 8 * TTF_SHORT_SIZE);
+    (void) put_ushort (new_glyphs_count);
+    ttf_set_chksm (tab);
 }
 
-static void ttf_write_htmx(void)
+static void ttf_write_htmx (void)
 {
     short *id;
-    dirtab_entry *tab = ttf_seek_tab("hmtx", 0);
-    ttf_reset_chksm(tab);
+    dirtab_entry *tab = ttf_seek_tab ("hmtx", 0);
+    ttf_reset_chksm (tab);
     for (id = glyph_index; id - glyph_index < new_glyphs_count; id++) {
-        put_ufword(glyph_tab[*id].advWidth);
-        put_ufword(glyph_tab[*id].lsb);
+        put_ufword (glyph_tab[*id].advWidth);
+        put_ufword (glyph_tab[*id].lsb);
     }
-    ttf_set_chksm(tab);
+    ttf_set_chksm (tab);
 }
 
-static void ttf_write_loca(void)
+static void ttf_write_loca (void)
 {
     short *id;
-    dirtab_entry *tab = ttf_seek_tab("loca", 0);
-    ttf_reset_chksm(tab);
+    dirtab_entry *tab = ttf_seek_tab ("loca", 0);
+    ttf_reset_chksm (tab);
     loca_format = 0;
     if (last_glyf_offset >= 0x00020000 || (last_glyf_offset & 1))
         loca_format = 1;
@@ -996,167 +1138,165 @@
             }
     if (loca_format != 0) {
         for (id = glyph_index; id - glyph_index < new_glyphs_count; id++)
-            put_ulong(glyph_tab[*id].newoffset);
-        put_ulong(last_glyf_offset);
-    }
-    else {
+            put_ulong (glyph_tab[*id].newoffset);
+        put_ulong (last_glyf_offset);
+    } else {
         for (id = glyph_index; id - glyph_index < new_glyphs_count; id++)
-            put_ushort(glyph_tab[*id].newoffset/2);
-        put_ushort(last_glyf_offset/2);
+            (void) put_ushort (glyph_tab[*id].newoffset / 2);
+        (void) put_ushort (last_glyf_offset / 2);
     }
-    ttf_set_chksm(tab);
+    ttf_set_chksm (tab);
 }
 
-static void ttf_write_mapx(void)
+static void ttf_write_mapx (void)
 {
-    dirtab_entry *tab = ttf_seek_tab("maxp", TTF_FIXED_SIZE + TTF_USHORT_SIZE);
-    ttf_reset_chksm(tab);
-    put_fixed(0x00010000);
-    put_ushort(new_glyphs_count);
-    ttf_ncopy(13*TTF_USHORT_SIZE);
-    ttf_set_chksm(tab);
+    dirtab_entry *tab = ttf_seek_tab ("maxp", TTF_FIXED_SIZE + TTF_USHORT_SIZE);
+    ttf_reset_chksm (tab);
+    put_fixed (0x00010000);
+    (void) put_ushort (new_glyphs_count);
+    ttf_ncopy (13 * TTF_USHORT_SIZE);
+    ttf_set_chksm (tab);
 }
 
-static void ttf_write_OS2(void)
+static void ttf_write_OS2 (void)
 {
-    dirtab_entry *tab = ttf_seek_tab("OS/2", 0);
+    dirtab_entry *tab = ttf_seek_tab ("OS/2", 0);
     TTF_USHORT version;
-    ttf_reset_chksm(tab);
-    version = get_ushort();
+    ttf_reset_chksm (tab);
+    version = get_ushort ();
     if (version != 0x0000 && version != 0x0001 && version != 0x0002)
-        pdftex_fail("unknown verssion of OS/2 table (%.4X)", version);
-    put_ushort(0x0001); /* fix version to 1*/
-    ttf_ncopy(2*TTF_USHORT_SIZE + 13*TTF_SHORT_SIZE + 10*TTF_BYTE_SIZE);
-    ttf_skip(4*TTF_ULONG_SIZE); /* ulUnicodeRange 1--4 */
-    put_ulong(0x00000003); /* Basic Latin + Latin-1 Supplement (0x0000--0x00FF) */
-    put_ulong(0x10000000); /* Private Use (0xE000--0xF8FF) */
-    put_ulong(0x00000000);
-    put_ulong(0x00000000);
-    ttf_ncopy(4*TTF_CHAR_SIZE + TTF_USHORT_SIZE); /* achVendID + fsSelection */
-    ttf_skip(2*TTF_USHORT_SIZE);
-    put_ushort(0x0000); /* usFirstCharIndex */
-    put_ushort(0xF0FF); /* usLastCharIndex */
-    ttf_ncopy(5*TTF_USHORT_SIZE);
-    /* for version 0 the OS/2 table ends here, the rest is for version 1 */ 
-    put_ulong(0x80000000); /* Symbol Character Set---don't use any code page */
-    put_ulong(0x00000000);
-    ttf_set_chksm(tab);
+        pdftex_fail ("unknown version of OS/2 table (%.4X)", version);
+    (void) put_ushort (0x0001); /* fix version to 1 */
+    ttf_ncopy (2 * TTF_USHORT_SIZE + 13 * TTF_SHORT_SIZE + 10 * TTF_BYTE_SIZE);
+    ttf_skip (4 * TTF_ULONG_SIZE);      /* ulUnicodeRange 1--4 */
+    put_ulong (0x00000003);     /* Basic Latin + Latin-1 Supplement (0x0000--0x00FF) */
+    put_ulong (0x10000000);     /* Private Use (0xE000--0xF8FF) */
+    put_ulong (0x00000000);
+    put_ulong (0x00000000);
+    ttf_ncopy (4 * TTF_CHAR_SIZE + TTF_USHORT_SIZE);    /* achVendID + fsSelection */
+    ttf_skip (2 * TTF_USHORT_SIZE);
+    (void) put_ushort (0x0000); /* usFirstCharIndex */
+    (void) put_ushort (0xF0FF); /* usLastCharIndex */
+    ttf_ncopy (5 * TTF_USHORT_SIZE);
+    /* for version 0 the OS/2 table ends here, the rest is for version 1 */
+    put_ulong (0x80000000);     /* Symbol Character Set---don't use any code page */
+    put_ulong (0x00000000);
+    ttf_set_chksm (tab);
 }
 
-static boolean unsafe_name(char *s)
+static boolean unsafe_name (char *s)
 {
     const char **p;
     for (p = ambiguous_names; *p != NULL; p++)
-        if (strcmp(s, *p) == 0)
+        if (strcmp (s, *p) == 0)
             return true;
     return false;
 }
 
-static void ttf_write_post(void)
+static void ttf_write_post (void)
 {
-    dirtab_entry *tab = ttf_seek_tab("post", TTF_FIXED_SIZE);
+    dirtab_entry *tab = ttf_seek_tab ("post", TTF_FIXED_SIZE);
     glyph_entry *glyph;
     char *s;
     short *id;
     int l;
-    ttf_reset_chksm(tab);
+    ttf_reset_chksm (tab);
     if (!write_ttf_glyph_names || post_format == 0x00030000) {
-        put_fixed(0x00030000);
-        ttf_ncopy(TTF_FIXED_SIZE + 2*TTF_FWORD_SIZE + 5*TTF_ULONG_SIZE);
-    }
-    else {
-        put_fixed(0x00020000);
-        ttf_ncopy(TTF_FIXED_SIZE + 2*TTF_FWORD_SIZE + 5*TTF_ULONG_SIZE);
-        put_ushort(new_glyphs_count);
+        put_fixed (0x00030000);
+        ttf_ncopy (TTF_FIXED_SIZE + 2 * TTF_FWORD_SIZE + 5 * TTF_ULONG_SIZE);
+    } else {
+        put_fixed (0x00020000);
+        ttf_ncopy (TTF_FIXED_SIZE + 2 * TTF_FWORD_SIZE + 5 * TTF_ULONG_SIZE);
+        (void) put_ushort (new_glyphs_count);
         k = 0;
         for (id = glyph_index; id - glyph_index < new_glyphs_count; id++) {
             glyph = glyph_tab + *id;
-            if (glyph->name_index >= NMACGLYPHS || unsafe_name(glyph->name))
+            if (glyph->name_index >= NMACGLYPHS || unsafe_name (glyph->name))
                 glyph->name_index = NMACGLYPHS + k++;
-            put_ushort(glyph->name_index);
+            (void) put_ushort (glyph->name_index);
         }
         for (id = glyph_index; id - glyph_index < new_glyphs_count; id++) {
             glyph = glyph_tab + *id;
             if (glyph->name_index >= NMACGLYPHS) {
                 s = glyph->name;
-                l = strlen(s);
-                put_byte(l);
+                l = strlen (s);
+                put_byte (l);
                 while (l-- > 0)
-                    put_char(*s++);
+                    put_char (*s++);
             }
         }
     }
-    ttf_set_chksm(tab);
+    ttf_set_chksm (tab);
 }
 
-static void ttf_init_font(int n)
+static void ttf_init_font (int n)
 {
     int i, k;
     for (i = 1, k = 0; i <= n; i <<= 1, k++);
-    put_fixed(0x00010000); /* font version */
-    put_ushort(n); /* number of tables */
-    put_ushort(i << 3); /* search range */
-    put_ushort(k - 1); /* entry selector */
-    put_ushort((n<<4) - (i<<3)); /* range shift */
-    ttf_seek_outbuf(TABDIR_OFF + n*4*TTF_ULONG_SIZE);
+    put_fixed (0x00010000);     /* font version */
+    (void) put_ushort (n);      /* number of tables */
+    (void) put_ushort (i << 3); /* search range */
+    (void) put_ushort (k - 1);  /* entry selector */
+    (void) put_ushort ((n << 4) - (i << 3));    /* range shift */
+    ttf_seek_outbuf (TABDIR_OFF + n * 4 * TTF_ULONG_SIZE);
 }
 
-static void ttf_subset_font(void)
+static void ttf_subset_font (void)
 {
-    ttf_init_font(new_ntabs);
-    if (ttf_name_lookup("PCLT", false) != NULL)
-        ttf_copytab("PCLT");
-    if (ttf_name_lookup("fpgm", false) != NULL)
-        ttf_copytab("fpgm");
-    if (ttf_name_lookup("cvt ", false) != NULL)
-        ttf_copytab("cvt ");
-    if (ttf_name_lookup("prep", false) != NULL)
-        ttf_copytab("prep");
-    ttf_reindex_glyphs();
-    ttf_write_glyf();
-    ttf_write_loca();
-    ttf_write_OS2();
-    ttf_write_head();
-    ttf_write_hhea();
-    ttf_write_htmx();
-    ttf_write_mapx();
-    ttf_write_name();
-    ttf_write_post();
-    ttf_write_cmap();
-    ttf_write_dirtab();
+    ttf_init_font (new_ntabs);
+    if (ttf_name_lookup ("PCLT", false) != NULL)
+        ttf_copytab ("PCLT");
+    if (ttf_name_lookup ("fpgm", false) != NULL)
+        ttf_copytab ("fpgm");
+    if (ttf_name_lookup ("cvt ", false) != NULL)
+        ttf_copytab ("cvt ");
+    if (ttf_name_lookup ("prep", false) != NULL)
+        ttf_copytab ("prep");
+    ttf_reindex_glyphs ();
+    ttf_write_glyf ();
+    ttf_write_loca ();
+    ttf_write_OS2 ();
+    ttf_write_head ();
+    ttf_write_hhea ();
+    ttf_write_htmx ();
+    ttf_write_mapx ();
+    ttf_write_name ();
+    ttf_write_post ();
+    ttf_write_cmap ();
+    ttf_write_dirtab ();
 }
 
-static void ttf_copy_font(void)
+static void ttf_copy_font (void)
 {
     dirtab_entry *tab;
-    ttf_init_font(ntabs);
+    ttf_init_font (ntabs);
     for (tab = dir_tab; tab - dir_tab < ntabs; tab++) {
-        if (strncmp(tab->tag, "head", 4) == 0)
-            ttf_write_head();
+        if (strncmp (tab->tag, "head", 4) == 0)
+            ttf_write_head ();
         else
-            ttf_copytab(tab->tag);
+            ttf_copytab (tab->tag);
     }
-    ttf_write_dirtab();
+    ttf_write_dirtab ();
 }
 
-void writettf()
+void writettf ()
 {
-    set_cur_file_name(fm_cur->ff_name);
-    if (is_subsetted(fm_cur) && !(is_reencoded(fm_cur))) {
-        pdftex_warn("encoding vector required for TrueType font subsetting");
+    set_cur_file_name (fm_cur->ff_name);
+    if (is_subsetted (fm_cur) && !is_reencoded (fm_cur) && !is_subfont (fm_cur)) {
+        pdftex_warn ("Subset TrueType must be a reencoded or a subfont");
         cur_file_name = NULL;
         return;
     }
-    if (!ttf_open()) {
-        pdftex_fail("cannot open TrueType font file for reading");
+    if (!ttf_open ()) {
+        pdftex_fail ("cannot open TrueType font file for reading");
     }
-    cur_file_name = (char*)nameoffile + 1;
-    if (!is_included(fm_cur))
-        tex_printf("{%s", cur_file_name);
-    else if (is_subsetted(fm_cur))
-        tex_printf("<%s", cur_file_name);
+    cur_file_name = (char *) nameoffile + 1;
+    if (!is_included (fm_cur))
+        tex_printf ("{%s", cur_file_name);
+    else if (is_subsetted (fm_cur))
+        tex_printf ("<%s", cur_file_name);
     else
-        tex_printf("<<%s", cur_file_name);
+        tex_printf ("<<%s", cur_file_name);
     fontfile_found = true;
     new_glyphs_count = 2;
     new_ntabs = DEFAULT_NTABS;
@@ -1166,65 +1306,63 @@
     glyph_name_buf = NULL;
     name_tab = NULL;
     name_buf = NULL;
-    ttf_read_font();
-    if (is_included(fm_cur)) {
-        pdfsaveoffset = pdfoffset();
-        pdfflush();
-        if (is_subsetted(fm_cur)) {
-            ttf_copy_encoding();
-            make_subset_tag(fm_cur, fm_cur->encoding->glyph_names);
-            ttf_subset_font();
-        }
-        else
-            ttf_copy_font();
-        ttf_length = ttf_offset();
+    ttf_read_font ();
+    if (is_included (fm_cur)) {
+        pdfsaveoffset = pdfoffset ();
+        pdfflush ();
+        if (is_subsetted (fm_cur)) {
+            ttf_copy_encoding ();
+            ttf_subset_font ();
+        } else
+            ttf_copy_font ();
+        ttf_length = ttf_offset ();
     }
-    xfree(dir_tab);
-    xfree(glyph_tab);
-    xfree(glyph_index);
-    xfree(glyph_name_buf);
-    xfree(name_tab);
-    xfree(name_buf);
-    ttf_close();
-    if (!is_included(fm_cur))
-        tex_printf("}");
-    else if (is_subsetted(fm_cur))
-        tex_printf(">");
+    xfree (dir_tab);
+    xfree (glyph_tab);
+    xfree (glyph_index);
+    xfree (glyph_name_buf);
+    xfree (name_tab);
+    xfree (name_buf);
+    ttf_close ();
+    if (!is_included (fm_cur))
+        tex_printf ("}");
+    else if (is_subsetted (fm_cur))
+        tex_printf (">");
     else
-        tex_printf(">>");
+        tex_printf (">>");
     cur_file_name = NULL;
 }
 
-void writeotf()
+void writeotf ()
 {
     dirtab_entry *tab;
     long i;
-    set_cur_file_name(fm_cur->ff_name);
-    if (!open_input(&ttf_file, kpse_type1_format, FOPEN_RBIN_MODE)) {
-        pdftex_fail("cannot open OpenType font file for reading");
+    set_cur_file_name (fm_cur->ff_name);
+    if (!open_input (&ttf_file, kpse_type1_format, FOPEN_RBIN_MODE)) {
+        pdftex_fail ("cannot open OpenType font file for reading");
     }
-    cur_file_name = (char*)nameoffile + 1;
-    tex_printf("<<%s", cur_file_name);
+    cur_file_name = (char *) nameoffile + 1;
+    tex_printf ("<<%s", cur_file_name);
     fontfile_found = true;
     dir_tab = NULL;
     glyph_tab = NULL;
-    ttf_read_tabdir();
+    ttf_read_tabdir ();
     /* read font parameters */
-    if (ttf_name_lookup("head", false) != NULL)
-        ttf_read_head();
-    if (ttf_name_lookup("hhea", false) != NULL)
-        ttf_read_hhea();
-    if (ttf_name_lookup("PCLT", false) != NULL)
-        ttf_read_pclt();
-    if (ttf_name_lookup("post", false) != NULL)
-        ttf_read_post();
+    if (ttf_name_lookup ("head", false) != NULL)
+        ttf_read_head ();
+    if (ttf_name_lookup ("hhea", false) != NULL)
+        ttf_read_hhea ();
+    if (ttf_name_lookup ("PCLT", false) != NULL)
+        ttf_read_pclt ();
+    if (ttf_name_lookup ("post", false) != NULL)
+        ttf_read_post ();
     /* copy font file */
-    tab = ttf_seek_tab("CFF ", 0);
+    tab = ttf_seek_tab ("CFF ", 0);
     for (i = tab->length; i > 0; i--)
-        copy_char();
-    xfree(dir_tab);
-    ttf_close();
-    tex_printf(">>");
+        copy_char ();
+    xfree (dir_tab);
+    ttf_close ();
+    tex_printf (">>");
     cur_file_name = NULL;
 }
 
@@ -1248,6 +1386,4 @@
 
    The table directory also includes the offset of the associated tagged
    table from the beginning of the font file and the length of that table.
-
-
  */

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writettf.h
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writettf.h	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writettf.h	2006-07-26 16:32:24 UTC (rev 1534)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 1996-2002 Han The Thanh, <thanh at pdftex.org>
+Copyright (c) 1996-2006 Han The Thanh, <thanh at pdftex.org>
 
 This file is part of pdfTeX.
 
@@ -20,17 +20,17 @@
 $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writettf.h#1 $
 */
 
-typedef signed char     TTF_CHAR;
-typedef unsigned char   TTF_BYTE;
-typedef signed short    TTF_SHORT;
-typedef unsigned short  TTF_USHORT;
-typedef signed long     TTF_LONG;
-typedef unsigned long   TTF_ULONG;
-typedef unsigned long   TTF_FIXED;
-typedef unsigned short  TTF_FUNIT;
-typedef signed short    TTF_FWORD;
-typedef unsigned short  TTF_UFWORD;
-typedef unsigned short  TTF_F2DOT14;
+typedef signed char TTF_CHAR;
+typedef unsigned char TTF_BYTE;
+typedef signed short TTF_SHORT;
+typedef unsigned short TTF_USHORT;
+typedef signed long TTF_LONG;
+typedef unsigned long TTF_ULONG;
+typedef unsigned long TTF_FIXED;
+typedef unsigned short TTF_FUNIT;
+typedef signed short TTF_FWORD;
+typedef unsigned short TTF_UFWORD;
+typedef unsigned short TTF_F2DOT14;
 
 #define TTF_CHAR_SIZE    1
 #define TTF_BYTE_SIZE    1
@@ -71,16 +71,16 @@
 
 #define put_num(t,n)    ((t)ttf_putnum(t##_SIZE, n))
 
-#define put_char(n)     put_num(TTF_CHAR, n)
-#define put_byte(n)     put_num(TTF_BYTE, n)
+#define put_char(n)     (void)put_num(TTF_CHAR, n)
+#define put_byte(n)     (void)put_num(TTF_BYTE, n)
 #define put_short(n)    put_num(TTF_SHORT, n)
 #define put_ushort(n)   put_num(TTF_USHORT, n)
 #define put_long(n)     put_num(TTF_LONG, n)
-#define put_ulong(n)    put_num(TTF_ULONG, n)
-#define put_fixed(n)    put_num(TTF_FIXED, n)
+#define put_ulong(n)    (void)put_num(TTF_ULONG, n)
+#define put_fixed(n)    (void)put_num(TTF_FIXED, n)
 #define put_funit(n)    put_num(TTF_FUNIT, n)
 #define put_fword(n)    put_num(TTF_FWORD, n)
-#define put_ufword(n)   put_num(TTF_UFWORD, n)
+#define put_ufword(n)   (void)put_num(TTF_UFWORD, n)
 #define put_f2dot14(n)  put_num(TTF_F2DOT14, n)
 
 #define copy_byte()     put_byte(get_byte())
@@ -106,8 +106,6 @@
 #define GLYPH_PREFIX_INDEX    "index"
 #define GLYPH_PREFIX_UNICODE  "uni"
 
-#define NOGLYPH_ASSIGNED_YET 0xFFFF /* indicating that no glyph is assigned to
-                                       an unicode */
 typedef struct {
     char tag[4];
     TTF_ULONG checksum;
@@ -118,7 +116,7 @@
 typedef struct {
     TTF_USHORT platform_id;
     TTF_USHORT encoding_id;
-    TTF_ULONG  offset;
+    TTF_ULONG offset;
     TTF_USHORT format;
 } cmap_entry;
 

Modified: tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writezip.c
===================================================================
--- tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writezip.c	2006-07-26 16:32:01 UTC (rev 1533)
+++ tetex-bin/branches/pdftex-1.4/texk/web2c/pdftexdir/writezip.c	2006-07-26 16:32:24 UTC (rev 1534)
@@ -17,14 +17,15 @@
 along with pdfTeX; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writezip.c#5 $
+$Id: writezip.c,v 1.2 2006/01/14 20:35:43 hahe Exp $
 */
 
 #include "ptexlib.h"
 #include "zlib.h"
+#include <assert.h>
 
-static const char perforce_id[] = 
-    "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writezip.c#5 $";
+static const char perforce_id[] =
+    "$Id: writezip.c,v 1.2 2006/01/14 20:35:43 hahe Exp $";
 
 #define ZIP_BUF_SIZE  32768
 
@@ -32,52 +33,47 @@
     if (f != Z_OK)                                         \
         pdftex_fail("zlib: %s() failed", fn)
 
-#define fixedcompresslevel  fixint(getintpar(cfgcompresslevelcode), 0, 9)
-
 static char zipbuf[ZIP_BUF_SIZE];
-static z_stream c_stream; /* compression stream */
+static z_stream c_stream;       /* compression stream */
 
-void writezip(boolean finish)
+void writezip (boolean finish)
 {
     int err;
-
-    if (!fixedcompresslevel) {
-        if (pdfptr) {
-            pdfgone += xfwrite(pdfbuf, 1, pdfptr, pdffile);
-            pdfstreamlength += pdfptr;
-            }
-        return;
-    }
-
+    assert (getpdfcompresslevel () > 0);
     cur_file_name = NULL;
     if (pdfstreamlength == 0) {
-        c_stream.zalloc = (alloc_func)0;
-        c_stream.zfree = (free_func)0;
-        c_stream.opaque = (voidpf)0;
-        check_err(deflateInit(&c_stream, fixedcompresslevel), "deflateInit");
-        c_stream.next_out = (Bytef*)zipbuf;
+        c_stream.zalloc = (alloc_func) 0;
+        c_stream.zfree = (free_func) 0;
+        c_stream.opaque = (voidpf) 0;
+        check_err (deflateInit (&c_stream, getpdfcompresslevel ()),
+                   "deflateInit");
+        c_stream.next_out = (Bytef *) zipbuf;
         c_stream.avail_out = ZIP_BUF_SIZE;
     }
     c_stream.next_in = pdfbuf;
     c_stream.avail_in = pdfptr;
-    for(;;) {
+    for (;;) {
         if (c_stream.avail_out == 0) {
-            pdfgone += xfwrite(zipbuf, 1, ZIP_BUF_SIZE, pdffile);
-            c_stream.next_out = (Bytef*)zipbuf;
+            pdfgone += xfwrite (zipbuf, 1, ZIP_BUF_SIZE, pdffile);
+            pdflastbyte = zipbuf[ZIP_BUF_SIZE - 1];     /* not needed */
+            c_stream.next_out = (Bytef *) zipbuf;
             c_stream.avail_out = ZIP_BUF_SIZE;
         }
-        err = deflate(&c_stream, finish ? Z_FINISH : Z_NO_FLUSH);
+        err = deflate (&c_stream, finish ? Z_FINISH : Z_NO_FLUSH);
         if (finish && err == Z_STREAM_END)
             break;
-        check_err(err, "deflate");
+        check_err (err, "deflate");
         if (!finish && c_stream.avail_in == 0)
             break;
     }
     if (finish) {
-        if (c_stream.avail_out < ZIP_BUF_SIZE) /* at least one byte has been output */
-            pdfgone += xfwrite(zipbuf, 1, ZIP_BUF_SIZE - c_stream.avail_out, pdffile);
-        check_err(deflateEnd(&c_stream), "deflateEnd");
-        xfflush(pdffile);
+        if (c_stream.avail_out < ZIP_BUF_SIZE) {        /* at least one byte has been output */
+            pdfgone +=
+                xfwrite (zipbuf, 1, ZIP_BUF_SIZE - c_stream.avail_out, pdffile);
+            pdflastbyte = zipbuf[ZIP_BUF_SIZE - c_stream.avail_out - 1];
+        }
+        check_err (deflateEnd (&c_stream), "deflateEnd");
+        xfflush (pdffile);
     }
     pdfstreamlength = c_stream.total_out;
 }




More information about the Pkg-tetex-commits mailing list